@vercel/board 0.27.0 → 0.29.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 (98) hide show
  1. package/dist/{a2-B8P8hjOT.mjs → a2-HUbQJ0RD.mjs} +16 -192
  2. package/dist/access.d.mts +1 -1
  3. package/dist/access.mjs +3 -3
  4. package/dist/{actors-BLXVp4oZ.mjs → actors-DcJhFbwJ.mjs} +2 -2
  5. package/dist/{auth-lTkOgvcE.mjs → auth-JO22iIwr.mjs} +1 -1
  6. package/dist/{backend-ZKYTe3xa.d.mts → backend-CPC_vyOo.d.mts} +5 -5
  7. package/dist/backend-a2/blob-vercel.d.mts +1 -1
  8. package/dist/backend-a2/contract.d.mts +1 -1
  9. package/dist/backend-a2/contract.mjs +3 -3
  10. package/dist/backend-a2/store-memory.d.mts +1 -1
  11. package/dist/backend-a2/store-memory.mjs +2 -2
  12. package/dist/backend-a2/store-postgres.d.mts +1 -1
  13. package/dist/backend-a2/store-postgres.mjs +1 -1
  14. package/dist/backend-a2/store-redis-http.d.mts +1 -1
  15. package/dist/backend-a2/store-redis-http.mjs +1 -1
  16. package/dist/backend-a2/store-redis.d.mts +1 -1
  17. package/dist/backend-a2/store-redis.mjs +1 -1
  18. package/dist/backend-a2/store-sqlite.d.mts +1 -1
  19. package/dist/backend-a2/store-sqlite.mjs +2 -2
  20. package/dist/backend-a2.d.mts +8 -5
  21. package/dist/backend-a2.mjs +2 -1
  22. package/dist/{backend-http-nppEk8gC.mjs → backend-http-Bmp0IgD3.mjs} +2 -2
  23. package/dist/{backend-http-E7YU0qhn.d.mts → backend-http-CqfKhrnn.d.mts} +5 -3
  24. package/dist/{backend-http-DEMvX2ht.mjs → backend-http-CzIJMm58.mjs} +3 -3
  25. package/dist/backend-http.d.mts +1 -1
  26. package/dist/backend-http.mjs +1 -1
  27. package/dist/backend-http.node.d.mts +1 -1
  28. package/dist/backend-http.node.mjs +1 -1
  29. package/dist/{backend-vercel-CIRObA0t.d.mts → backend-vercel-4tvcPKqX.d.mts} +7 -3
  30. package/dist/{backend-vercel-K5rDrMxZ.mjs → backend-vercel-BNauAs7w.mjs} +68 -10
  31. package/dist/{backend-vercel-CnViBZYT.mjs → backend-vercel-DQc_TaHp.mjs} +5 -3
  32. package/dist/backend-vercel.d.mts +1 -1
  33. package/dist/backend-vercel.mjs +1 -1
  34. package/dist/backend-vercel.node.d.mts +1 -1
  35. package/dist/backend-vercel.node.mjs +1 -1
  36. package/dist/blob-DdbpJqN1.mjs +182 -0
  37. package/dist/{blob-B-9AvYis.d.mts → blob-DmiQjrYy.d.mts} +2 -2
  38. package/dist/{chat-provider-DsNEBQiA.d.mts → chat-provider-BWHbChcQ.d.mts} +5 -3
  39. package/dist/{chat-provider-DnHibqnM.mjs → chat-provider-COtsU5jB.mjs} +2 -2
  40. package/dist/cli-commands.mjs +1 -1
  41. package/dist/cli-embedded.d.mts +5 -3
  42. package/dist/cli-embedded.mjs +6 -4
  43. package/dist/cli.mjs +5 -5
  44. package/dist/{client-xLxeDz0f.d.mts → client-BqAjk0Q4.d.mts} +8 -1
  45. package/dist/{commands-BFookFtn.mjs → commands-C3R1AWgm.mjs} +4 -1
  46. package/dist/conformance.d.mts +1 -1
  47. package/dist/{engine-Bfe6pcXb.mjs → engine-DQxXk7dX.mjs} +20 -12
  48. package/dist/{errors-CB4tnZGz.d.mts → errors-DDktVeUa.d.mts} +1 -1
  49. package/dist/{events-CewD4kw7.mjs → events-qf5XG5VQ.mjs} +2 -2
  50. package/dist/{exports-uiRQD2-i.mjs → exports-BG-0Wyn-.mjs} +9 -9
  51. package/dist/exports-mhAYiU4i.d.mts +5 -0
  52. package/dist/{external-BV_cUncs.mjs → external-D3p5T57R.mjs} +4 -2
  53. package/dist/{folds-Dyjput8M.mjs → folds-BDMSxBUf.mjs} +2 -2
  54. package/dist/{folds-jS9wlh9_.d.mts → folds-ZkHM4M-v.d.mts} +2 -0
  55. package/dist/{index-C05it0mC.d.mts → index-D3VvNfh_.d.mts} +2 -2
  56. package/dist/index.d.mts +5 -5
  57. package/dist/{index.default-RaGMBzNu.mjs → index.default-rB8sJ9RX.mjs} +1 -1
  58. package/dist/index.mjs +4 -4
  59. package/dist/index.node.d.mts +5 -5
  60. package/dist/index.node.mjs +2 -2
  61. package/dist/inspect/app.js +3 -3
  62. package/dist/inspect/engine.js +5 -5
  63. package/dist/{main-CRHQQFgN.mjs → main-CVBqe3VO.mjs} +14 -9
  64. package/dist/{middleware-ChKM1zuu.mjs → middleware-CXjEeef4.mjs} +1 -1
  65. package/dist/{node-Ybi9E6bO.mjs → node-Zd_C-gxP.mjs} +34 -17
  66. package/dist/{project-DMDST9kl.mjs → project-CBXlLftU.mjs} +1 -1
  67. package/dist/{provider-poIkXapd.mjs → provider-BaVmi4Hi.mjs} +3 -1
  68. package/dist/{provider-Cdg1qadh.d.mts → provider-DmSTp9lI.d.mts} +9 -2
  69. package/dist/{redis-tables-DN9PfIDi.mjs → redis-tables-BJQVUspu.mjs} +2 -2
  70. package/dist/{reducers-BcmSs4qf.mjs → reducers-DJzVpXwM.mjs} +3 -3
  71. package/dist/{schemas-Be08nyfW.mjs → schemas-DBmUO6pr.mjs} +2 -1
  72. package/dist/{serve-BsbHOJFN.mjs → serve-G9RuaDSr.mjs} +5 -4
  73. package/dist/{server-C0DVYiHm.mjs → server-BixV_byP.mjs} +4 -4
  74. package/dist/{serving-CvOWEym2.mjs → serving-B75Y4BF-.mjs} +1 -1
  75. package/dist/{sql-U9WTxrwJ.mjs → sql-D4Z_efJX.mjs} +2 -2
  76. package/dist/{sqlite-db-Ds4majtT.mjs → sqlite-db-Bz2JkfCU.mjs} +1 -1
  77. package/dist/sync-github.d.mts +4 -2
  78. package/dist/sync-github.mjs +4 -14
  79. package/dist/sync-kapso.d.mts +3 -2
  80. package/dist/sync-kapso.mjs +3 -3
  81. package/dist/sync-linear.d.mts +12 -2
  82. package/dist/sync-linear.mjs +189 -9
  83. package/dist/sync-slack.d.mts +41 -5
  84. package/dist/sync-slack.mjs +70 -11
  85. package/dist/sync.chat.d.mts +1 -1
  86. package/dist/sync.chat.mjs +1 -1
  87. package/dist/sync.d.mts +2 -2
  88. package/dist/sync.mjs +3 -3
  89. package/dist/tags-BpFo6q0_.mjs +14 -0
  90. package/dist/{targets-C-wdR5wP.mjs → targets-Cgjs29T0.mjs} +1 -1
  91. package/dist/{tokens-BuCU-61R.mjs → tokens-CC3izSNr.mjs} +1 -1
  92. package/dist/{types-aCAf6lGU.d.mts → types-No0WdhE5.d.mts} +1 -1
  93. package/dist/{watchers-hash-qSMYlljN.mjs → watchers-hash-BDhLVkV5.mjs} +7 -5
  94. package/docs/02-sync/03-slack.md +6 -2
  95. package/docs/02-sync/07-linear.md +28 -6
  96. package/docs/04-reference/01-cli.md +7 -2
  97. package/package.json +1 -1
  98. package/dist/exports-D22M68rk.d.mts +0 -5
@@ -341,13 +341,13 @@ function Ao(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...U(n)})}//
341
341
  function jo(e,t){let n=/* @__PURE__ */ Mo(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(jt(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(jt(r))}},e(t.value,t)),t);return n}// @__NO_SIDE_EFFECTS__
342
342
  function Mo(e,t){let n=new sr({check:`custom`,...U(t)});return n._zod.check=e,n}function No(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&Ge(e,t,n[t]);return e}function Po(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??wa,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:/* @__PURE__ */ new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function Fo(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function Io(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,Io(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&No(o.schema,c),t.io===`input`&&Ko(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Lo(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function Ro(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;let r=/* @__PURE__ */ new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${Lo(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+Lo(a)}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
343
343
 
344
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}r.count>1&&e.reused===`ref`&&a(n)}e.external&&(e.sharedDefsExtractedFor=e.external)}function zo(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;zo(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}const Bo=/* @__PURE__ */ new Set([`type`,`properties`,`required`,`additionalProperties`]),Vo=[`oneOf`,`anyOf`];function Ho(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function Uo(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!Bo.has(e))return null;t.push(n)}let n={},r=/* @__PURE__ */ new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??Ho(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}Ge(n,r,e.length===1?e[0]:Uo(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=Ho(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function Wo(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of Bo)if(t in e)return;let n=t.filter(e=>Vo.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=Uo(t);else{let e=n[0],i=Vo.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>Uo([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,No(e,r))}function Go(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):No(i,s),No(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())zo(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])Wo(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}No(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,Ge(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Jo(t,`input`,e.processors),output:Jo(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function Ko(e,t){let n=t??{seen:/* @__PURE__ */ new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return Ko(r.element,n);if(r.type===`set`)return Ko(r.valueType,n);if(r.type===`lazy`)return Ko(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return Ko(r.innerType,n);if(r.type===`intersection`)return Ko(r.left,n)||Ko(r.right,n);if(r.type===`record`||r.type===`map`)return Ko(r.keyType,n)||Ko(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:Ko(r.in,n)||Ko(r.out,n);if(r.type===`object`){for(let e in r.shape)if(Ko(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(Ko(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(Ko(e,n))return!0;return!!(r.rest&&Ko(r.rest,n))}return!1}const qo=(e,t={})=>n=>{let r=Po({...n,processors:t});return Io(e,r),Ro(r,e),Go(r,e)},Jo=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Po({...i??{},target:a,io:t,processors:n});return Io(e,o),Ro(o,e),Go(o,e)},Yo=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},Xo=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},Zo=(e,t)=>{Yo(e,`minimum`,t),Xo(e,`maximum`,t)},Qo=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},$o=(e,t)=>{e.patterns??=/* @__PURE__ */ new Set,e.patterns.add(t)},es=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},ts=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},ns=(e,t)=>Yo(e,`minimum`,t.minimum),rs=(e,t)=>Xo(e,`maximum`,t.maximum),is=e=>(t,n)=>{ts(t,n.format);let[r,i]=e[n.format];Yo(t,`minimum`,r),Xo(t,`maximum`,i)},as={greater_than:(e,t)=>Yo(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>Xo(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Qo(e,t.value),number_format:is(ut),bigint_format:is(dt),min_length:ns,max_length:rs,length_equals:(e,t)=>Zo(e,t.length),min_size:ns,max_size:rs,size_equals:(e,t)=>Zo(e,t.size),string_format:(e,t)=>{ts(e,t.format),t.pattern&&$o(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>es(e,t.mime)};function os(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)as[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&Yo(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&Yo(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&Xo(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&Xo(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Qo(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&es(t,i.mime);for(let e of i.patterns??[])$o(t,e);return t}const ss={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},cs=/* @__PURE__ */ new Map([[li,Wn],[di,Gn]]),ls=e=>cs.get(e)??e,us=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=os(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=ss[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(ls);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},ds=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=os(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=/* @__PURE__ */ new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):Fo(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},fs=(e,t,n,r)=>{n.type=`boolean`},ps=(e,t,n,r)=>{Fo(e,t,n,r,`BigInt cannot be represented in JSON Schema`)},ms=(e,t,n,r)=>{Fo(e,t,n,r,`Symbols cannot be represented in JSON Schema`)},hs=(e,t,n,r)=>{t.target===`openapi-3.0`?(n.type=`string`,n.nullable=!0,n.enum=[null]):n.type=`null`},gs=(e,t,n,r)=>{Fo(e,t,n,r,`Undefined cannot be represented in JSON Schema`)},_s=(e,t,n,r)=>{Fo(e,t,n,r,`Void cannot be represented in JSON Schema`)},vs=(e,t,n,r)=>{n.not={}},ys=(e,t,n,r)=>{},bs=(e,t,n,r)=>{},xs=(e,t,n,r)=>{Fo(e,t,n,r,`Date cannot be represented in JSON Schema`)},Ss=(e,t,n,r)=>{let i=e._zod.def,a=Le(i.entries);if(a.length===0){n.not={};return}a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Cs=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(Fo(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(Fo(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},ws=(e,t,n,r)=>{Fo(e,t,n,r,`NaN cannot be represented in JSON Schema`)},Ts=(e,t,n,r)=>{let i=n,a=e._zod.pattern;if(!a)throw Error(`Pattern not found in template literal`);i.type=`string`,i.pattern=a.source},Es=(e,t,n,r)=>{let i=n;i.type=`string`,i.format=`binary`,i.contentEncoding=`binary`;let{minimum:a,maximum:o,mime:s}=os(e);a!==void 0&&(i.minLength=a),o!==void 0&&(i.maxLength=o),s&&(s.length===0?i.not={}:s.length===1?i.contentMediaType=s[0]:i.anyOf=s.map(e=>({contentMediaType:e})))},Ds=(e,t,n,r)=>{n.type=`boolean`},Os=(e,t,n,r)=>{Fo(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},ks=(e,t,n,r)=>{Fo(e,t,n,r,`Function types cannot be represented in JSON Schema`)},As=(e,t,n,r)=>{Fo(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},js=(e,t,n,r)=>{Fo(e,t,n,r,`Map cannot be represented in JSON Schema`)},Ms=(e,t,n,r)=>{Fo(e,t,n,r,`Set cannot be represented in JSON Schema`)},Ns=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=os(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=Io(a.element,t,{...r,path:[...r.path,`items`]})};function Ps(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?Ps(t.out):t.type===`catch`?Ps(t.innerType):e._zod.optin}const Fs=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&Fo(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)Ge(i.properties,e,Io(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?Ps(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=Io(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Is=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>Io(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Ls=(e,t,n,r)=>{let i=e._zod.def,a=Io(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=Io(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)},Rs=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`array`;let o=t.target===`draft-2020-12`?`prefixItems`:`items`,s=t.target===`draft-2020-12`||t.target===`openapi-3.0`?`items`:`additionalItems`,c=a.items.map((e,n)=>Io(e,t,{...r,path:[...r.path,o,n]})),l=a.rest?Io(a.rest,t,{...r,path:[...r.path,s,...t.target===`openapi-3.0`?[a.items.length]:[]]}):null,u=a.items.length;for(;u>0;){let e=a.items[u-1];if(!(t.io===`input`?Ps(e)!==void 0:e._zod.optout===`optional`))break;u--}let d=a.items.length,f=!a.rest;t.target===`draft-2020-12`?(i.prefixItems=c,f?i.items=!1:l&&(i.items=l),u>0&&(i.minItems=u),f&&(i.maxItems=d)):t.target===`openapi-3.0`?(i.items={anyOf:c},l&&i.items.anyOf.push(l),u>0&&(i.minItems=u),f&&(i.maxItems=d)):(i.items=c,f?i.additionalItems=!1:l&&(i.additionalItems=l),u>0&&(i.minItems=u),f&&(i.maxItems=d));let{minimum:p,maximum:m}=os(e);typeof p==`number`&&(i.minItems=p),typeof m==`number`&&(i.maxItems=m)};function zs(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=zs(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>zs(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i?(p.type=`string`,a||(p.pattern=(r.includes(`number`)?nr:tr).source),p):p}const Bs=/* @__PURE__ */ new WeakMap;function Vs(e){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=/* @__PURE__ */ new Map;for(let r of Bs.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=zs(t,a,/* @__PURE__ */ new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}const Hs=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=os(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=Io(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)Ge(i.patternProperties,ls(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=Io(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=Bs.get(t);n||(n=[],Bs.set(t,n),t.deferred.push(()=>Vs(t))),n.push(e)}i.additionalProperties=Io(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&Ps(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},Us=(e,t,n,r)=>{let i=e._zod.def,a=Io(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Ws=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Gs=Symbol();function Ks(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(Fo(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),Gs):JSON.parse(o)}const qs=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=Ks(i.defaultValue,e,t,n,r);o!==Gs&&(n.default=o)},Js=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=Ks(i.defaultValue,e,t,n,r);o!==Gs&&(n._prefault=o)},Ys=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{Fo(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},Xs=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;Io(o,t,r);let s=t.seen.get(e);s.ref=o},Zs=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Qs=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},$s=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ec={string:us,number:ds,boolean:fs,bigint:ps,symbol:ms,null:hs,undefined:gs,void:_s,never:vs,any:ys,unknown:bs,date:xs,enum:Ss,literal:Cs,nan:ws,template_literal:Ts,file:Es,success:Ds,custom:Os,function:ks,transform:As,map:js,set:Ms,array:Ns,object:Fs,union:Is,intersection:Ls,tuple:Rs,record:Hs,nullable:Us,nonoptional:Ws,default:qs,prefault:Js,catch:Ys,pipe:Xs,readonly:Zs,promise:Qs,optional:$s,lazy:(e,t,n,r)=>{let i=e._zod.innerType;Io(i,t,r);let a=t.seen.get(e);a.ref=i}};function tc(e,t){if(`_idmap`in e){let n=e,r=Po({...t,processors:ec}),i={};for(let e of n._idmap.entries()){let[t,n]=e;Io(n,r)}let a={};r.external={registry:n,uri:t?.uri,defs:i};for(let e of n._idmap.entries()){let[t,n]=e;Ro(r,n),Ge(a,t,Go(r,n))}return Object.keys(i).length>0&&(a.__shared={[r.target===`draft-2020-12`?`$defs`:`definitions`]:i}),{schemas:a}}let n=Po({...t,processors:ec});return Io(e,n),Ro(n,e),Go(n,e)}const nc=/* @__PURE__ */ new WeakSet([Object.prototype,Error.prototype]);function rc(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}const ic=(e,t)=>{an.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);nc.has(n)||(nc.add(n),rc(n,`format`,e=>t=>cn(e,t)),rc(n,`flatten`,e=>t=>sn(e,t)),rc(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ze,2)}),rc(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ze,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},ac=/*@__PURE__*/ G(`ZodError`,ic),oc=/*@__PURE__*/ G(`ZodError`,ic,void 0,{Parent:Error}),sc=/* @__PURE__ */ un(oc),cc=/* @__PURE__ */ dn(oc),lc=/* @__PURE__ */ fn(oc),uc=/* @__PURE__ */ mn(oc),dc=/* @__PURE__ */ bn(oc),fc=/* @__PURE__ */ xn(oc),pc=/* @__PURE__ */ Sn(oc),mc=/* @__PURE__ */ Cn(oc),hc=/* @__PURE__ */ wn(oc),gc=/* @__PURE__ */ Tn(oc),_c=/* @__PURE__ */ En(oc),vc=/* @__PURE__ */ Dn(oc);function yc(){Xt.localeError||Zt(ba())}function bc(){Xt.memoizer||Zt({memoizer:_a()})}const xc=/*@__PURE__*/ G(`ZodType`,(e,t)=>(yc(),Dr.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(Qe(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return ct(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Ul(e,t))},superRefine(e,t){return this.check(Wl(e,t))},overwrite(e){return this.check(/* @__PURE__ */ So(e))},optional(){return wl(this)},exactOptional(){return El(this)},nullable(){return Ol(this)},nullish(){return wl(Ol(this))},nonoptional(e){return Pl(this,e)},array(){return sl(this)},or(e){return ul([this,e])},and(e){return ml(this,e)},transform(e){return Rl(this,Sl(e))},default(e){return Al(this,e)},prefault(e){return Ml(this,e)},catch(e){return Il(this,e)},pipe(e){return Rl(this,e)},readonly(){return Bl(this)},describe(e){let t=this.clone();return wa.add(t,{description:e}),t},meta(...e){if(e.length===0)return wa.get(this);let t=this.clone();return wa.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return Pt(this,`~standard`,{...Ar(this),jsonSchema:{input:Jo(this,`input`),output:Jo(this,`output`)}})},set"~standard"(e){Nt(this,`~standard`,e)},parse:function e(t,n){return sc(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await cc(this,t,n,{callee:e})},safeParse(e,t){return lc(this,e,t)},async safeParseAsync(e,t){return uc(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){Nt(this,`spa`,e)},validate(e,t){return _n(this,e,t)},validateAsync(e,t){return yn(this,e,t)},encode:function e(t,n){return dc(this,t,n,{callee:e})},decode:function e(t,n){return fc(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await pc(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await mc(this,t,n,{callee:e})},safeEncode(e,t){return hc(this,e,t)},safeDecode(e,t){return gc(this,e,t)},async safeEncodeAsync(e,t){return _c(this,e,t)},async safeDecodeAsync(e,t){return vc(this,e,t)},toJSONSchema(e){return qo(this,{})(e)},get description(){return wa.get(this)?.description},get _def(){return this._zod.def}}),Sc=/*@__PURE__*/ G(`_ZodString`,(e,t)=>{jr.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>us(e,t,n,r)},/*@__PURE__*/ Ft({format:e=>os(e).format??null,minLength:e=>os(e).minimum??null,maxLength:e=>os(e).maximum??null},{regex(...e){return this.check(/* @__PURE__ */ go(...e))},includes(...e){return this.check(/* @__PURE__ */ yo(...e))},startsWith(...e){return this.check(/* @__PURE__ */ bo(...e))},endsWith(...e){return this.check(/* @__PURE__ */ xo(...e))},min(...e){return this.check(/* @__PURE__ */ mo(...e))},max(...e){return this.check(/* @__PURE__ */ po(...e))},length(...e){return this.check(/* @__PURE__ */ ho(...e))},nonempty(...e){return this.check(/* @__PURE__ */ mo(1,...e))},lowercase(e){return this.check(/* @__PURE__ */ _o(e))},uppercase(e){return this.check(/* @__PURE__ */ vo(e))},trim(){return this.check(/* @__PURE__ */ wo())},normalize(...e){return this.check(/* @__PURE__ */ Co(...e))},toLowerCase(){return this.check(/* @__PURE__ */ To())},toUpperCase(){return this.check(/* @__PURE__ */ Eo())},slugify(){return this.check(/* @__PURE__ */ Do())}})),Cc=/*@__PURE__*/ G(`ZodString`,(e,t)=>{jr.init(e,t),Sc.init(e,t)},{email(e){return this.check(/* @__PURE__ */ Da(kc,e))},url(e){return this.check(/* @__PURE__ */ Na(Mc,e))},jwt(e){return this.check(/* @__PURE__ */ Ja(qc,e))},emoji(e){return this.check(/* @__PURE__ */ Pa(Nc,e))},guid(e){return this.check(/* @__PURE__ */ Oa(Ac,e))},uuid(e){return this.check(/* @__PURE__ */ ka(jc,e))},uuidv4(e){return this.check(/* @__PURE__ */ Aa(jc,e))},uuidv6(e){return this.check(/* @__PURE__ */ ja(jc,e))},uuidv7(e){return this.check(/* @__PURE__ */ Ma(jc,e))},nanoid(e){return this.check(/* @__PURE__ */ Fa(Pc,e))},cuid(e){return this.check(/* @__PURE__ */ Ia(Fc,e))},cuid2(e){return this.check(/* @__PURE__ */ La(Ic,e))},ulid(e){return this.check(/* @__PURE__ */ Ra(Lc,e))},base64(e){return this.check(/* @__PURE__ */ Ga(Wc,e))},base64url(e){return this.check(/* @__PURE__ */ Ka(Gc,e))},xid(e){return this.check(/* @__PURE__ */ za(Rc,e))},ksuid(e){return this.check(/* @__PURE__ */ Ba(zc,e))},ipv4(e){return this.check(/* @__PURE__ */ Va(Bc,e))},ipv6(e){return this.check(/* @__PURE__ */ Ha(Vc,e))},cidrv4(e){return this.check(/* @__PURE__ */ Ua(Hc,e))},cidrv6(e){return this.check(/* @__PURE__ */ Wa(Uc,e))},e164(e){return this.check(/* @__PURE__ */ qa(Kc,e))},datetime(e){return this.check(/* @__PURE__ */ Ya(Tc,e))},date(e){return this.check(/* @__PURE__ */ Xa(Ec,e))},time(e){return this.check(/* @__PURE__ */ Za(Dc,e))},duration(e){return this.check(/* @__PURE__ */ Qa(Oc,e))}});function K(e){return/* @__PURE__ */ Ea(Cc,e)}const wc=/*@__PURE__*/ G(`ZodStringFormat`,(e,t)=>{Mr.init(e,t),Sc.init(e,t)}),Tc=/*@__PURE__*/ G(`ZodISODateTime`,(e,t)=>{Zr.init(e,t),wc.init(e,t)}),Ec=/*@__PURE__*/ G(`ZodISODate`,(e,t)=>{Qr.init(e,t),wc.init(e,t)}),Dc=/*@__PURE__*/ G(`ZodISOTime`,(e,t)=>{$r.init(e,t),wc.init(e,t)}),Oc=/*@__PURE__*/ G(`ZodISODuration`,(e,t)=>{ei.init(e,t),wc.init(e,t)}),kc=/*@__PURE__*/ G(`ZodEmail`,(e,t)=>{Fr.init(e,t),wc.init(e,t)}),Ac=/*@__PURE__*/ G(`ZodGUID`,(e,t)=>{Nr.init(e,t),wc.init(e,t)}),jc=/*@__PURE__*/ G(`ZodUUID`,(e,t)=>{Pr.init(e,t),wc.init(e,t)}),Mc=/*@__PURE__*/ G(`ZodURL`,(e,t)=>{Ur.init(e,t),wc.init(e,t)}),Nc=/*@__PURE__*/ G(`ZodEmoji`,(e,t)=>{Wr.init(e,t),wc.init(e,t)}),Pc=/*@__PURE__*/ G(`ZodNanoID`,(e,t)=>{Gr.init(e,t),wc.init(e,t)}),Fc=/*@__PURE__*/ G(`ZodCUID`,(e,t)=>{Kr.init(e,t),wc.init(e,t)}),Ic=/*@__PURE__*/ G(`ZodCUID2`,(e,t)=>{qr.init(e,t),wc.init(e,t)}),Lc=/*@__PURE__*/ G(`ZodULID`,(e,t)=>{Jr.init(e,t),wc.init(e,t)}),Rc=/*@__PURE__*/ G(`ZodXID`,(e,t)=>{Yr.init(e,t),wc.init(e,t)}),zc=/*@__PURE__*/ G(`ZodKSUID`,(e,t)=>{Xr.init(e,t),wc.init(e,t)}),Bc=/*@__PURE__*/ G(`ZodIPv4`,(e,t)=>{ti.init(e,t),wc.init(e,t)}),Vc=/*@__PURE__*/ G(`ZodIPv6`,(e,t)=>{ii.init(e,t),wc.init(e,t)}),Hc=/*@__PURE__*/ G(`ZodCIDRv4`,(e,t)=>{ai.init(e,t),wc.init(e,t)}),Uc=/*@__PURE__*/ G(`ZodCIDRv6`,(e,t)=>{si.init(e,t),wc.init(e,t)}),Wc=/*@__PURE__*/ G(`ZodBase64`,(e,t)=>{ui.init(e,t),wc.init(e,t)}),Gc=/*@__PURE__*/ G(`ZodBase64URL`,(e,t)=>{pi.init(e,t),wc.init(e,t)}),Kc=/*@__PURE__*/ G(`ZodE164`,(e,t)=>{mi.init(e,t),wc.init(e,t)}),qc=/*@__PURE__*/ G(`ZodJWT`,(e,t)=>{gi.init(e,t),wc.init(e,t)}),Jc=/*@__PURE__*/ G(`ZodNumber`,(e,t)=>{_i.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ds(e,t,n,r),e.isFinite=!0},/*@__PURE__*/ Ft({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=os(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=os(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=os(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>os(e).format??null},{gt(e,t){return this.check(/* @__PURE__ */ lo(e,t))},gte(e,t){return this.check(/* @__PURE__ */ uo(e,t))},min(e,t){return this.check(/* @__PURE__ */ uo(e,t))},lt(e,t){return this.check(/* @__PURE__ */ so(e,t))},lte(e,t){return this.check(/* @__PURE__ */ co(e,t))},max(e,t){return this.check(/* @__PURE__ */ co(e,t))},int(e){return this.check(Zc(e))},safe(e){return this.check(Zc(e))},positive(e){return this.check(/* @__PURE__ */ lo(0,e))},nonnegative(e){return this.check(/* @__PURE__ */ uo(0,e))},negative(e){return this.check(/* @__PURE__ */ so(0,e))},nonpositive(e){return this.check(/* @__PURE__ */ co(0,e))},multipleOf(e,t){return this.check(/* @__PURE__ */ fo(e,t))},step(e,t){return this.check(/* @__PURE__ */ fo(e,t))},finite(){return this}}));function Yc(e){return/* @__PURE__ */ $a(Jc,e)}const Xc=/*@__PURE__*/ G(`ZodNumberFormat`,(e,t)=>{vi.init(e,t),Jc.init(e,t)});function Zc(e){return/* @__PURE__ */ to(Xc,e)}const Qc=/*@__PURE__*/ G(`ZodBoolean`,(e,t)=>{yi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fs(e,t,n,r)});function $c(e){return/* @__PURE__ */ no(Qc,e)}const el=/*@__PURE__*/ G(`ZodNull`,(e,t)=>{bi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hs(e,t,n,r)});function tl(e){return/* @__PURE__ */ io(el,e)}const nl=/*@__PURE__*/ G(`ZodUnknown`,(e,t)=>{xi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function rl(){return/* @__PURE__ */ ao(nl)}const il=/*@__PURE__*/ G(`ZodNever`,(e,t)=>{Si.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vs(e,t,n,r)});function al(e){return/* @__PURE__ */ oo(il,e)}const ol=/*@__PURE__*/ G(`ZodArray`,(e,t)=>{bc(),wi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ns(e,t,n,r),e.element=t.element},{min(e,t){return this.check(/* @__PURE__ */ mo(e,t))},nonempty(e){return this.check(/* @__PURE__ */ mo(1,e))},max(e,t){return this.check(/* @__PURE__ */ po(e,t))},length(e,t){return this.check(/* @__PURE__ */ ho(e,t))},unwrap(){return this.element}});function sl(e,t){return/* @__PURE__ */ Oo(ol,e,t)}const cl=/*@__PURE__*/ G(`ZodObject`,(e,t)=>{bc(),Ai.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fs(e,t,n,r),Ht(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return vl(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(Qe(this._zod.def,{catchall:e}))},passthrough(){return this.clone(Qe(this._zod.def,{catchall:rl()}))},loose(){return this.clone(Qe(this._zod.def,{catchall:rl()}))},strict(){return this.clone(Qe(this._zod.def,{catchall:al()}))},strip(){return this.clone(Qe(this._zod.def,{catchall:void 0}))},extend(e){return ht(this,e)},safeExtend(e){return _t(this,e)},merge(e){return vt(this,e)},pick(e){return ft(this,e)},omit(e){return mt(this,e)},partial(...e){return yt(Cl,this,e[0])},exactPartial(...e){return yt(Tl,this,e[0],`exactPartial`)},required(...e){return bt(Nl,this,e[0])}});function q(e,t){let n={type:`object`,shape:e??{},...U(t)};return new cl(n)}const ll=/*@__PURE__*/ G(`ZodUnion`,(e,t)=>{Mi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Is(e,t,n,r),e.options=t.options});function ul(e,t){return new ll({type:`union`,options:e,...U(t)})}const dl=/*@__PURE__*/ G(`ZodDiscriminatedUnion`,(e,t)=>{ll.init(e,t),Pi.init(e,t)});function fl(e,t,n){return new dl({type:`union`,options:t,discriminator:e,...U(n)})}const pl=/*@__PURE__*/ G(`ZodIntersection`,(e,t)=>{Fi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ls(e,t,n,r)});function ml(e,t){return new pl({type:`intersection`,left:e,right:t})}const hl=/*@__PURE__*/ G(`ZodRecord`,(e,t)=>{bc(),Ri.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hs(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function gl(e,t,n){return!t||!t._zod?new hl({type:`record`,keyType:K(),valueType:e,...U(t)}):new hl({type:`record`,keyType:e,valueType:t,...U(n)})}const _l=/*@__PURE__*/ G(`ZodEnum`,(e,t)=>{zi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ss(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new _l({...t,checks:[],...U(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new _l({...t,checks:[],...U(r),entries:i})}});function vl(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new _l({type:`enum`,entries:n,...U(t)})}const yl=/*@__PURE__*/ G(`ZodLiteral`,(e,t)=>{Bi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Cs(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function bl(e,t){return new yl({type:`literal`,values:Array.isArray(e)?e:[e],...U(t)})}const xl=/*@__PURE__*/ G(`ZodTransform`,(e,t)=>{bc(),Vi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>As(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Yt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(jt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(jt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Sl(e){return new xl({type:`transform`,transform:e})}const Cl=/*@__PURE__*/ G(`ZodOptional`,(e,t)=>{Ui.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$s(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function wl(e){return new Cl({type:`optional`,innerType:e})}const Tl=/*@__PURE__*/ G(`ZodExactOptional`,(e,t)=>{Wi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$s(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function El(e){return new Tl({type:`optional`,innerType:e})}const Dl=/*@__PURE__*/ G(`ZodNullable`,(e,t)=>{Gi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Us(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ol(e){return new Dl({type:`nullable`,innerType:e})}const kl=/*@__PURE__*/ G(`ZodDefault`,(e,t)=>{Ki.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Al(e,t){return new kl({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():at(t)}})}const jl=/*@__PURE__*/ G(`ZodPrefault`,(e,t)=>{Ji.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Js(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ml(e,t){return new jl({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():at(t)}})}const Nl=/*@__PURE__*/ G(`ZodNonOptional`,(e,t)=>{Yi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ws(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Pl(e,t){return new Nl({type:`nonoptional`,innerType:e,...U(t)})}const Fl=/*@__PURE__*/ G(`ZodCatch`,(e,t)=>{Qi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ys(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Il(e,t){return new Fl({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Ut(t)})}const Ll=/*@__PURE__*/ G(`ZodPipe`,(e,t)=>{$i.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xs(e,t,n,r),e.in=t.in,e.out=t.out});function Rl(e,t){return new Ll({type:`pipe`,in:e,out:t})}const zl=/*@__PURE__*/ G(`ZodReadonly`,(e,t)=>{ta.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Bl(e){return new zl({type:`readonly`,innerType:e})}const Vl=/*@__PURE__*/ G(`ZodCustom`,(e,t)=>{ra.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Os(e,t,n,r)});function Hl(e,t){return/* @__PURE__ */ ko(Vl,e??(()=>!0),t)}function Ul(e,t={}){return/* @__PURE__ */ Ao(Vl,e,t)}function Wl(e,t){return/* @__PURE__ */ jo(e,t)}function Gl(e){return/* @__PURE__ */ eo(Jc,e)}function Kl(e){return/* @__PURE__ */ ro(Qc,e)}const ql=1e4,Jl=`[a-z0-9][a-z0-9_-]*`,Yl=K().max(80).regex(RegExp(`^${Jl}(?:/${Jl})*$`),`invalid channel path`),Xl=e=>!e.includes(`\0`)&&e.isWellFormed(),Zl=e=>e.replaceAll(`\0`,``).toWellFormed(),Ql=K().max(ql).refine(e=>e.trim().length>0,`message text is empty`).refine(Xl,`message text has a NUL character or a lone surrogate`),$l=Yc().int().positive(),eu=/* @__PURE__ */ new Set([...Object.getOwnPropertyNames(Object.prototype),`prototype`]),tu=e=>!eu.has(e),nu=K().max(64).regex(/^[a-z0-9][a-z0-9_.-]*$/,`invalid label key`).refine(tu,`label key is a reserved name`),ru=gl(nu,K().max(256).refine(Xl,`label value has a NUL character or a lone surrogate`)),iu=K().max(64).regex(/^[a-z0-9_+-]+$/,`invalid emoji name`).refine(tu,`emoji name is a reserved name`),au=K().min(1).max(256);ul([vl([`person`,`agent`,`deployment`,`workflow`,`external`]),bl(`profile`)]);const ou=e=>e===`profile`?`agent`:e;K().min(1).max(128).refine(Xl,`handle has a NUL character or a lone surrogate`);function su(e){if(e===null)return null;try{return new URL(e).protocol===`https:`?e:null}catch{return null}}q({actor:au,principal:K().min(1),profile:K().nullable(),session:K().nullable()});const cu=K().regex(/^[A-Za-z0-9_-]{22}$/,`invalid attachment id`);q({id:cu,name:K().min(1).max(255),type:K().min(1).max(255),size:Yc().int().nonnegative()}),K().regex(/^[A-Za-z][A-Za-z0-9-]{0,31}$/,`ids start with a letter and use up to 32 letters, numbers, and hyphens`);const lu=K().min(3).max(300),uu=q({channel:lu.optional(),thread:lu,subthread:lu.nullable(),message:K().min(1).max(300),context:K().max(300).nullable()}),du=q({author:K().min(1).max(256),text:K().max(ql),createdAt:K().max(64).nullable(),files:sl(q({name:K().min(1).max(1e3),url:K().max(4e3).nullable()})).max(20)}),fu=q({url:K().min(1).max(4e3),message:$l.nullable(),snapshot:du.nullable(),unavailable:K().max(300).nullable()}),pu=q({id:K().min(1),handle:K().min(1),name:K().min(1),avatar:K().nullable(),isBot:$c()}),mu=q({type:vl([`image`,`file`,`video`,`audio`]),name:K().max(1e3).optional(),mimeType:K().max(255).optional(),size:Yc().int().nonnegative().optional(),url:K().max(4e3).optional(),fetchMetadata:gl(K(),K().max(4e3)).optional()}),hu=q({url:K().min(1).max(4e3),thread:lu,message:K().min(1).max(300),snapshot:du.nullable()}),gu=q({channel:lu,thread:lu,subthread:lu.nullable()}),_u=fl(`kind`,[q({kind:bl(`message`),...gu.shape,message:K(),isRoot:$c(),text:K(),context:K().nullable(),author:pu,files:sl(mu).max(20).optional(),links:sl(hu).max(10).optional()}),q({kind:bl(`edited`),...gu.shape,message:K(),text:K(),author:pu,links:sl(hu).max(10).optional(),linksOnly:$c().optional()}),q({kind:bl(`deleted`),...gu.shape,message:K()}),q({kind:bl(`reaction`),...gu.shape,message:K(),emoji:K(),added:$c(),author:pu}),q({kind:bl(`lifecycle`),...gu.omit({subthread:!0}).shape,type:K(),title:K(),url:K().nullable(),labels:gl(K(),K()),unset:sl(K()),owns:sl(K()).optional(),reply:K().nullable(),createRoot:$c(),retitled:$c().optional(),author:pu})]),vu=e=>e.slice(e.indexOf(`:`)+1).includes(`:`),yu=e=>{let t=e.indexOf(`:`),n=e.slice(t+1).indexOf(`:`);return n===-1?e:e.slice(0,t+1+n)},bu=(e,t)=>`${e}|${t}`,xu=K().min(1).max(128),Su=xu,Cu=ul([K(),sl(K())]).transform(e=>Array.isArray(e)?e:[e]),wu=K().regex(/^[a-z0-9][a-z0-9_.-]*(=.*)?$/,`label filters look like key, key=value, or key=a|b`).transform(e=>{let t=e.indexOf(`=`);return t===-1?[e,null]:[e.slice(0,t),e.slice(t+1).split(`|`)]}),Tu=q({target:lu,kind:vl([`channel`,`thread`])}),Eu=q({channel:K().optional(),re:Su.optional(),by:K().optional(),mentions:K().optional(),label:Cu.pipe(sl(wu)).optional(),from:K().min(1).max(64).optional(),text:K().min(1).max(200).optional()}),Du=Eu.extend({after:xu.optional(),before:Su.optional(),limit:Gl().int().min(1).max(500).optional()}),Ou=Eu.extend({after:xu.optional(),limit:Gl().int().min(1).max(500).optional()}),ku=Eu.extend({after:xu.optional(),wait:Gl().min(0).max(300).optional(),all:Kl().optional()}),Au=q({channel:Yl.optional(),re:xu.optional(),text:K().max(ql).default(``),labels:ru.optional(),noSync:$c().optional(),sync:sl(ul([K().min(3).max(300),Tu])).max(10).optional(),id:K().min(1).max(200).refine(Xl,`id has a NUL character or a lone surrogate`).optional(),attachments:sl(cu).max(10).optional()}).refine(e=>e.text.trim().length>0||(e.attachments?.length??0)>0,{message:`message text is empty`,path:[`text`]}).refine(e=>e.channel===void 0!=(e.re===void 0),{message:"a post needs `channel`; a reply needs `re`"}).refine(e=>!(e.noSync&&e.sync?.length),{message:"`noSync` and `sync` contradict each other"}),ju=K().regex(/^\d+(\.\d+)?(s|m|h|d)$/,`durations look like 30s, 30m, 12h, or 1d`),Mu=K().datetime({offset:!0}),Nu=q({channel:Yl.optional(),re:xu.optional(),text:K().max(ql).default(``),labels:ru.optional(),noSync:$c().optional(),attachments:sl(cu).max(10).optional(),in:ju.optional(),at:Mu.optional(),every:ju.optional(),until:Mu.optional(),for:ju.optional(),times:Yc().int().positive().optional()}).refine(e=>e.text.trim().length>0||(e.attachments?.length??0)>0,{message:`message text is empty`,path:[`text`]}).refine(e=>e.channel===void 0!=(e.re===void 0),{message:"a schedule needs `channel` for a new thread, or `re` for a reply"}).refine(e=>e.in!==void 0||e.at!==void 0||e.every!==void 0,{message:"say when: `in`, `at`, or `every`"}).refine(e=>e.in===void 0||e.at===void 0,{message:"`in` and `at` contradict each other"}).refine(e=>[e.until,e.for,e.times].filter(e=>e!==void 0).length<=1,{message:"pick one stop: `until`, `for`, or `times`"}).refine(e=>e.every!==void 0||e.until===void 0&&e.for===void 0&&e.times===void 0,{message:"`until`, `for`, and `times` stop a repeat: add `every`"}),Pu=q({re:Su.optional(),channel:K().optional(),by:K().optional(),all:Kl().optional()}),Fu=q({target:K().min(3).max(300)}),Iu=q({channel:K().optional(),limit:Gl().int().min(1).max(500).optional()}),Lu=q({watch:gl(K().max(100),q({tail:K().max(1e3),when:vl([`matches`,`enters`]).default(`matches`)})).refine(e=>Object.keys(e).length<=32,`a board registers at most 32 watchers`),sync:sl(q({key:K().min(1).max(64),platform:K().min(1).max(64),signIn:$c().default(!1)})).max(32).optional()}),Ru=ul([Lu.extend({url:K().url().max(500).refine(e=>/^https:\/\//.test(e),`wake-ups go over https`).transform(e=>e.replace(/\/+$/,``)).nullable().optional(),path:tl({error:`register a url or a path, not both`}).optional(),branch:tl({error:`a branch goes with a path`}).optional()}),Lu.extend({url:tl({error:`register a url or a path, not both`}).optional(),path:K().max(300).regex(/^\/[^?#]*$/,`a path starts with / and has no query or fragment`).transform(e=>e.replace(/(.)\/+$/,`$1`)),branch:K().min(1).max(255).nullable().optional()})]),zu=q({limit:Gl().int().min(1).max(50).optional(),wait:Gl().min(0).max(25).optional()}),Bu=q({lease:K().min(1).max(64),error:K().min(1).max(500).optional(),skip:$c().optional()}),Vu=q({target:K().min(1).max(4e3),limit:Gl().int().min(1).max(200).optional()}),Hu=q({target:K().min(1).max(4e3)}),Uu=q({url:K().url().max(4e3)}),Wu=q({actor:K().min(1).max(256)}),Gu=K().min(1).max(64),Ku=q({thread:lu,message:K().min(1).max(300).optional()}),qu=fu.extend({message:xu.nullable()}),Ju=pu.extend({avatar:K().nullable().transform(su)}),Yu={author:Ju,from:Gu.nullable()},Xu=q({key:Gu,channel:lu,thread:lu}),Zu={origin:Ku.optional(),message:xu.optional()},Qu=fl(`op`,[q({op:bl(`post`),...Yu,origin:uu.nullable().default(null),source:Xu.optional(),channel:Yl.optional(),re:xu.optional(),text:K().max(ql).default(``),labels:ru.optional(),noSync:$c().optional(),attachments:sl(cu).max(10).optional(),links:sl(qu).max(10).optional(),id:K().min(1).max(200).refine(Xl,`id has a NUL character or a lone surrogate`).optional()}),q({op:bl(`edit`),...Yu,...Zu,text:Ql,source:Xu.optional()}),q({op:bl(`delete`),...Yu,...Zu}),q({op:bl(`react`),...Yu,...Zu,emoji:iu,remove:$c().optional()}),q({op:bl(`labels`),...Yu,...Zu,set:ru.optional(),unset:sl(nu).optional()}),q({op:bl(`links`),...Yu,...Zu,links:sl(qu).max(10)}),q({op:bl(`seen`),author:Ju})]),$u=sl(K().min(1).max(300)).max(10).nullable(),ed=fl(`kind`,[q({kind:bl(`message`),message:xu,target:lu,external:q({thread:lu,message:K().min(1).max(300),asUser:bl(!0).optional()}),files:$u.optional()}),q({kind:bl(`files`),message:xu,target:lu,files:$u}),q({kind:bl(`failed`),message:xu,target:lu,error:K().min(1).max(500)}),q({kind:bl(`thread`),message:xu,target:lu,targetKind:vl([`channel`,`thread`]),cause:vl([`config`,`request`])})]),td=q({code:K().min(1).max(64).optional(),post:K().min(1).max(200).optional(),thread:lu.optional(),message:K().min(1).max(300).optional(),account:au.optional(),person:au.optional()}),nd=q({message:Cu.pipe(sl(xu).min(1).max(100))}),rd=q({by:au,since:Gl().int().nonnegative()}),id=q({events:sl(q({id:K().min(1).max(300),event:_u,raw:rl()})).min(1).max(50)}),ad=q({limit:Gl().int().min(1).max(50).optional()}),od=q({lease:K().min(1).max(64),error:K().min(1).max(500).optional()}),sd=q({sync:Gu}),cd=q({sync:Gu,account:Ju,code:K().min(1).max(64),message:K().max(1024).optional(),method:vl([`code`,`consent`]).optional()}),ld=q({sync:Gu,code:K().min(1).max(64)}),ud=q({account:au}),dd=q({name:K().max(1024).nullable().optional(),type:K().max(1024).nullable().optional(),size:Yc().int().positive().max(Ae,`direct uploads are at most ${Ae/1024/1024} MB`)}),fd=q({text:Ql}),pd=q({}).optional(),md=q({status:K().trim().min(1).max(100).optional()}).optional(),hd=q({emoji:iu,remove:$c().optional()}),gd=q({set:ru.optional(),unset:sl(nu).optional()}).refine(e=>e.set!==void 0||e.unset!==void 0,{message:"nothing to change: pass `set` or `unset`"}),_d={discovery:{method:`GET`,path:`/`},me:{method:`GET`,path:`/me`},channels:{method:`GET`,path:`/channels`},actors:{method:`GET`,path:`/actors`},messages:{method:`GET`,path:`/messages`,query:Du},message:{method:`GET`,path:`/messages/:id`},threads:{method:`GET`,path:`/threads`,query:Ou},post:{method:`POST`,path:`/messages`,body:Au},edit:{method:`POST`,path:`/messages/:id/edit`,body:fd},delete:{method:`POST`,path:`/messages/:id/delete`,body:pd},react:{method:`POST`,path:`/messages/:id/reactions`,body:hd},label:{method:`POST`,path:`/messages/:id/labels`,body:gd},sync:{method:`POST`,path:`/messages/:id/sync`,body:Fu},synced:{method:`GET`,path:`/messages/:id/sync`},linked:{method:`GET`,path:`/links`,query:Uu},typing:{method:`POST`,path:`/messages/:id/typing`,body:md},schedule:{method:`POST`,path:`/schedules`,body:Nu},schedules:{method:`GET`,path:`/schedules`,query:Pu},cancelSchedule:{method:`POST`,path:`/schedules/:id/cancel`},posted:{method:`GET`,path:`/posts/:id`},inbox:{method:`GET`,path:`/inbox/:key`,query:Iu},inboxPush:{method:`POST`,path:`/inbox/:key`,body:id},inboxNext:{method:`GET`,path:`/inbox/:key/next`,query:ad},inboxAck:{method:`POST`,path:`/inbox/:key/:id/ack`,body:od},syncImport:{method:`POST`,path:`/sync/imports`,body:Qu},syncReceipt:{method:`POST`,path:`/sync/receipts`,body:ed},syncThread:{method:`GET`,path:`/sync/threads/:thread`},syncFind:{method:`GET`,path:`/sync/find`,query:td},syncCopies:{method:`GET`,path:`/sync/copies`,query:nd},syncRoots:{method:`GET`,path:`/sync/roots`,query:rd},syncCode:{method:`POST`,path:`/sync/codes`,body:sd},syncAccount:{method:`POST`,path:`/sync/accounts`,body:cd},syncUnlink:{method:`POST`,path:`/sync/accounts/unlink`,body:ud},readSource:{method:`GET`,path:`/sources/:key/read`,query:Vu},joinSource:{method:`POST`,path:`/sources/:key/join`,body:Hu},webhook:{method:`POST`,path:`/webhooks/:key`},events:{method:`GET`,path:`/events`,query:ku},avatar:{method:`GET`,path:`/avatars/:name`},upload:{method:`POST`,path:`/attachments`},attachment:{method:`GET`,path:`/attachments/:id`},uploadStart:{method:`POST`,path:`/attachments/uploads`,body:dd},uploadFinish:{method:`POST`,path:`/attachments/uploads/:id`},openapi:{method:`GET`,path:`/openapi.json`},identity:{method:`GET`,path:`/identity`},signIn:{method:`GET`,path:`/identity/sign-in`,query:ld},signedIn:{method:`GET`,path:`/identity/signed-in`,query:ld},identityUnlink:{method:`POST`,path:`/identity/unlink`,body:Wu},watchers:{method:`GET`,path:`/watchers`},register:{method:`POST`,path:`/watchers`,body:Ru},matches:{method:`GET`,path:`/watchers/matches`,query:zu},ack:{method:`POST`,path:`/watchers/matches/:id/ack`,body:Bu},wake:{method:`POST`,path:`/wake`}};async function*vd(e,t){let n=e.getReader(),r=new TextDecoder,i=``,a=()=>void n.cancel().catch(()=>{});t?.addEventListener(`abort`,a,{once:!0});try{for(;;){let{value:e,done:t}=await n.read();if(t)return;i+=r.decode(e,{stream:!0});let a;for(;(a=i.search(/\r?\n\r?\n/))!==-1;){let e=i.slice(0,a);i=i.slice(a).replace(/^\r?\n\r?\n/,``);let t={},n=[];for(let r of e.split(/\r?\n/)){if(r===``||r.startsWith(`:`))continue;let e=r.indexOf(`:`),i=e===-1?r:r.slice(0,e),a=e===-1?``:r.slice(e+1).replace(/^ /,``);i===`data`?n.push(a):i===`id`?t.id=a:i===`event`&&(t.event=a)}n.length>0&&(t.data=n.join(`
345
- `)),(t.id!==void 0||t.data!==void 0)&&(yield t)}}}finally{t?.removeEventListener(`abort`,a),n.releaseLock()}}var yd=class extends Error{code;status;hint;origin;constructor(e,t,n,r={}){super(t),this.name=`BoardError`,this.code=e,this.status=n,this.hint=r.hint,this.origin=r.origin??`handle`}};const bd=/* @__PURE__ */ new WeakSet,xd=async e=>typeof e==`function`?await e():e,Sd=e=>{let{at:t,until:n,...r}=Cd(e);return{...r,...t===void 0?{}:{at:t instanceof Date?t.toISOString():t},...n===void 0?{}:{until:n instanceof Date?n.toISOString():n}}},Cd=e=>{if(typeof e==`string`)return{text:e};let{attachments:t,...n}=e;return t?.length?{...n,attachments:t.map(e=>typeof e==`string`?e:e.id)}:n},wd={ms:1,s:1e3,m:6e4,h:36e5,d:864e5};function Td(e){if(typeof e==`number`)return e;let t=e.trim().match(/^(\d+(?:\.\d+)?)(ms|s|m|h|d)?$/);if(!t)throw new yd(`invalid_duration`,`${e} isn't a duration like 30s, 10m, or 1h.`,0);return Number(t[1])*wd[t[2]??`ms`]}const Ed=e=>encodeURIComponent(e);function Dd(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!=null){if(n===`label`){let e=Array.isArray(r)?r:typeof r==`object`?Object.entries(r).map(([e,t])=>`${e}=${String(t)}`):[r];for(let n of e)t.append(`label`,String(n))}else t.set(n,String(r))}let n=t.toString();return n?`?${n}`:``}const Od=(e,t)=>t?.length?{...e,unknownMentions:t}:e;function kd(e){let t=e.url.replace(/\/+$/,``),n=e.fetch??((e,t)=>globalThis.fetch(e,t)),r=e.storeFetch??((e,t)=>globalThis.fetch(e,t));async function i(t,n){let r={...e.headers?await xd(e.headers):{}};if(!t)return r;e.token!==void 0&&(r.authorization=`Bearer ${await xd(e.token)}`);let i=n===void 0?e.profile===void 0?null:await xd(e.profile):n;if(i!==null){let{name:e,avatar:t}=typeof i==`string`?{name:i,avatar:void 0}:i;r[`x-board-profile`]=e,t&&(r[`x-board-avatar`]=t)}else{let t=e.person===void 0?null:await xd(e.person);t?.name&&(r[`x-board-name`]=encodeURIComponent(t.name)),t?.avatar&&(r[`x-board-avatar`]=t.avatar)}let a=n===void 0?e.session===void 0?null:await xd(e.session):null;a&&(r[`x-board-session`]=a);let o=e.handle===void 0?null:await xd(e.handle);return o&&(r[`x-board-handle`]=o),r}async function a(e,r,a={}){let o=await n(`${t}${r}`,{method:e,headers:{...await i(a.auth??!0),...a.body===void 0?{}:{"content-type":`application/json`},...a.headers},...a.body===void 0?{}:{body:JSON.stringify(a.body)},...a.signal?{signal:a.signal}:{}});if(!o.ok)throw await Ad(o);return o}async function o(e,t,n){return await(await a(e,t,n)).json()}let s=(e={})=>e;async function c(e={},t){return o(`GET`,`/events${Dd(e)}`,t?{signal:t}:{})}return{url:t,request:async(e,r={})=>n(`${t}${e}`,{method:r.method??`GET`,headers:{...r.headers,...await i(!0,r.as)},...r.body?{body:r.body}:{},...r.signal?{signal:r.signal}:{}}),discovery:()=>o(`GET`,`/`,{auth:!1}),me:()=>o(`GET`,`/me`),channels:async()=>(await o(`GET`,`/channels`)).channels,actors:async()=>(await o(`GET`,`/actors`)).actors,identity:()=>o(`GET`,`/identity`),unlinkAccount:e=>o(`POST`,`/identity/unlink`,{body:{actor:e}}),messages:(e={})=>o(`GET`,`/messages${Dd(e)}`),thread:e=>o(`GET`,`/messages/${Ed(e)}`),posted:async e=>(await o(`GET`,`/posts/${Ed(e)}`)).message,threads:(e={})=>o(`GET`,`/threads${Dd(e)}`),async post(e,t){let{message:n,unknownMentions:r}=await o(`POST`,`/messages`,{body:{channel:e,...Cd(t)}});return Od(n,r)},async reply(e,t){let{message:n,unknownMentions:r}=await o(`POST`,`/messages`,{body:{re:e,...Cd(t)}});return Od(n,r)},async schedule(e,t){let{schedule:n,unknownMentions:r}=await o(`POST`,`/schedules`,{body:{...typeof e==`string`?{channel:e}:{re:e.re},...Sd(t)}});return Od(n,r)},schedules:async(e={})=>(await o(`GET`,`/schedules${Dd(e)}`)).schedules,cancelSchedule:e=>o(`POST`,`/schedules/${Ed(e)}/cancel`,{body:{}}),async upload(e){let a=e.type||(e.data instanceof Blob?e.data.type:``)||Ne(e.name),s=e.data instanceof Blob?e.data.size:e.data.byteLength;if(s>4194304){if(s>104857600)throw new yd(`too_large`,`Attachments are at most ${Ae/1024/1024} MB.`,413);let t=await o(`POST`,`/attachments/uploads`,{body:{name:e.name,type:a,size:s}}).catch(e=>{throw e instanceof yd&&e.status===404&&e.code===`not_found`?new yd(`too_large`,`This board takes files of at most ${Oe/1024/1024} MB.`,413):e}),n=await r(t.url,{method:`PUT`,headers:t.headers,body:e.data});if(!n.ok)throw new yd(`upload_failed`,`The blob store refused the file: ${n.status} ${(await n.text().catch(()=>``)).slice(0,300)||n.statusText}`,n.status);return(await o(`POST`,`/attachments/uploads/${encodeURIComponent(t.id)}`,{body:{}})).attachment}let c=await n(`${t}/attachments`,{method:`POST`,headers:{...await i(!0),"content-type":a,"x-board-filename":encodeURIComponent(e.name)},body:e.data});if(!c.ok)throw await Ad(c);return(await c.json()).attachment},download:(e,t={})=>a(`GET`,`/attachments/${encodeURIComponent(e)}`,t.signal?{signal:t.signal}:{}),edit:(e,t)=>o(`POST`,`/messages/${Ed(e)}/edit`,{body:{text:t}}),delete:e=>o(`POST`,`/messages/${Ed(e)}/delete`,{body:{}}),react:(e,t,n={})=>o(`POST`,`/messages/${Ed(e)}/reactions`,{body:{emoji:Ee(t),...n}}),label:(e,t)=>o(`POST`,`/messages/${Ed(e)}/labels`,{body:t}),typing:async(e,t)=>(await o(`POST`,`/messages/${Ed(e)}/typing`,{body:t?{status:t}:{}})).targets,sync:((e,t)=>t===void 0?o(`GET`,`/messages/${Ed(e)}/sync`):o(`POST`,`/messages/${Ed(e)}/sync`,{body:{target:t}})),linked:e=>o(`GET`,`/links${Dd({url:e})}`),inbox:async(e,t={})=>(await o(`GET`,`/inbox/${e}${Dd(t)}`)).events,register:e=>o(`POST`,`/watchers`,{body:e}),watchers:async()=>(await o(`GET`,`/watchers`)).watchers,matches:async(e={})=>{let{signal:t,...n}=e;return(await o(`GET`,`/watchers/matches${Dd(n)}`,t?{signal:t}:{})).matches},ack:(e,t)=>o(`POST`,`/watchers/matches/${encodeURIComponent(e)}/ack`,{body:t}),readSource:(e,t,n={})=>o(`GET`,`/sources/${e}/read${Dd({target:t,...n})}`),joinSource:(e,t)=>o(`POST`,`/sources/${e}/join`,{body:{target:t}}),poll:c,syncImport:e=>o(`POST`,`/sync/imports`,{body:e}),syncReceipt:e=>o(`POST`,`/sync/receipts`,{body:e}),syncThread:e=>o(`GET`,`/sync/threads/${Ed(e)}`),syncFind:(e,t={})=>o(`GET`,`/sync/find${Dd(e)}`,t.signal?{signal:t.signal}:{}),syncCopies:async e=>(await o(`GET`,`/sync/copies?${e.map(e=>`message=${encodeURIComponent(e)}`).join(`&`)}`)).copies,syncRoots:async(e,t)=>(await o(`GET`,`/sync/roots${Dd({by:e,since:t instanceof Date?t.getTime():t})}`)).roots,inboxPush:(e,t)=>o(`POST`,`/inbox/${Ed(e)}`,{body:{events:t}}),inboxNext:async(e,t={})=>(await o(`GET`,`/inbox/${Ed(e)}/next${Dd(t)}`)).items,inboxAck:(e,t,n)=>o(`POST`,`/inbox/${Ed(e)}/${Ed(t)}/ack`,{body:n}),syncCode:e=>o(`POST`,`/sync/codes`,{body:{sync:e}}),syncAccount:e=>o(`POST`,`/sync/accounts`,{body:e}),syncUnlink:e=>o(`POST`,`/sync/accounts/unlink`,{body:{account:e}}),async*events(e={},t={}){let n=e.after,r=0;for(;!t.signal?.aborted;){let i;try{i=await a(`GET`,`/events${Dd({...s(e),after:n})}`,{headers:{accept:`text/event-stream`},...t.signal?{signal:t.signal}:{}})}catch(e){if(t.signal?.aborted)return;if(e instanceof yd&&e.status>=400&&e.status<500)throw e;await new Promise(e=>setTimeout(e,Math.min(3e4,500*2**r++)));continue}r=0;try{for await(let e of vd(i.body,t.signal))e.id!==void 0&&(n=e.id),e.event===`board`&&e.data&&(yield JSON.parse(e.data))}catch{if(t.signal?.aborted)return;await new Promise(e=>setTimeout(e,Math.min(3e4,500*2**r++)))}}},async wait(e={},t={}){let n=Date.now()+Td(t.timeout??`30m`),r=e.after??(await c({...e,after:void 0,wait:0},t.signal)).cursor;for(;Date.now()<n&&!t.signal?.aborted;){let i=Math.max(0,Math.min(25,Math.ceil((n-Date.now())/1e3))),a=await c({...e,after:r,wait:i},t.signal);if(a.events.length>0)return a.events[0];r=a.cursor}return null}}}async function Ad(e){try{let t=await e.json();if(t.error?.message)return new yd(t.error.code??`error`,t.error.message,e.status,{...typeof t.error.hint==`string`?{hint:t.error.hint}:{},origin:bd.has(e)?`handle`:`board`})}catch{}return new yd(`http_error`,`The board answered ${`${e.status} ${e.statusText}`.trim()}.`,e.status)}const jd=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);async function Md(e){return jd(new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))))}async function Nd(...e){let t=new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(JSON.stringify(e)))).slice(0,16);t[6]=t[6]&15|128,t[8]=t[8]&63|128;let n=jd(t);return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20,32)}`}const Pd=/^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,Fd=async(e,t)=>`key:${e}:${(await Md(`board-key\u001f${t}`)).slice(0,32)}`;var Id=class extends Error{status;code;hint;origin;constructor(e,t,n,r={}){super(n),this.status=e,this.code=t,this.hint=r.hint,this.origin=r.origin??`board`}},Ld=class extends Id{response;constructor(e){super(e.status,`rejected`,`rejected with ${e.status}`),this.response=e}};const Rd=(e,t=`invalid_request`)=>new Id(400,t,e),zd=e=>new Id(401,`unauthorized`,e),Bd=e=>new Id(403,`forbidden`,e),Vd=(e,t=`not_found`)=>new Id(404,t,e),Hd=()=>new Id(409,`duplicate_id`,`that id was already used for a different write`),Ud=(e,t=200,n)=>new Response(JSON.stringify(e),{status:t,headers:{"content-type":`application/json`,...n}});function Wd(e){if(e.code!==`invalid_union`||e.errors.length===0)return e;let t=e.errors.reduce((e,t)=>t.length<e.length?t:e)[0];return t?Wd({...t,path:[...e.path,...t.path]}):e}function Gd(e){if(e instanceof Ld)return e.response;if(e instanceof Id){let t=Ud({error:{code:e.code,message:e.message,...e.hint===void 0?{}:{hint:e.hint}}},e.status);return e.origin===`handle`&&bd.add(t),t}if(e instanceof ac){let t=e.issues[0]&&Wd(e.issues[0]),n=t?.path.length?`${t.path.join(`.`)}: `:``;return Ud({error:{code:`invalid_request`,message:`${n}${t?.message??`invalid request`}`}},400)}let t=e?.code;return t===`INVALID_PAYLOAD`?Ud({error:{code:`invalid_request`,message:e.message}},400):t===`PARTIAL_DUPLICATE_BATCH`||t===`DUPLICATE_EVENT_ID`?Gd(Hd()):t===`STORE_UNAVAILABLE`||t===`STORE_NOT_CONFIGURED`?Ud({error:{code:`unavailable`,message:e.message}},503):(console.error(`[board]`,e),Ud({error:{code:`internal`,message:`internal error`}},500))}const Kd=`0.27.0`,qd=[`avatar`,`openapi`,`webhook`,`signIn`,`signedIn`,`identityUnlink`,`sync`],Jd=/* @__PURE__ */ `discovery.me.channels.actors.identity.messages.threads.message.post.posted.edit.delete.react.label.schedule.schedules.cancelSchedule.upload.attachment.uploadStart.uploadFinish.watchers.register.matches.ack.events.syncImport.syncReceipt.syncThread.syncFind.syncCopies.syncRoots.inboxPush.inboxNext.inboxAck.inbox.syncCode.syncAccount.syncUnlink.typing.readSource.joinSource.synced.linked`.split(`.`),Yd=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);function Xd(e,t,n,r){let i=t.split(`/`).filter(Boolean),a=i.map(e=>e.startsWith(`:`)?`/([^/]+)`:`/${Yd(e)}`).join(``);return{method:e,pattern:RegExp(`${a}$`),names:i.filter(e=>e.startsWith(`:`)).map(e=>e.slice(1)),target:n,segments:i.length,literals:i.filter(e=>!e.startsWith(`:`)).length,own:r}}function Zd(e,t){let n=[...qd.map(e=>Xd(_d[e].method,_d[e].path,{kind:`board`,name:e},!1)),...Jd.filter(e=>e!==`discovery`).map(e=>Xd(_d[e].method,_d[e].path,{kind:`protocol`,name:e},!1)),...e.map(e=>Xd(e.method,e.path,{kind:`backend`,route:e},!0))].sort((e,t)=>t.segments-e.segments||t.literals-e.literals||Number(t.own)-Number(e.own)),r=(e,t,n)=>{let r={};try{e.names.forEach((e,t)=>r[e]=decodeURIComponent(n[t]))}catch{return null}let i=e.names[0];return{target:e.target,base:t,param:i===void 0?null:r[i],params:r}},i=e=>({target:{kind:`protocol`,name:`discovery`},base:e,param:null,params:{},root:!0});return function(e,a){let o=a.length>1?a.replace(/\/+$/,``):a;if(t!==void 0){let a=t.replace(/\/+$/,``);if(o!==a&&!o.startsWith(`${a}/`))return null;let s=o.slice(a.length)||`/`;if(s===`/`)return e===`GET`?i(a):null;for(let t of n){let n=t.method===e?s.match(RegExp(`^${t.pattern.source}`)):null;if(n)return r(t,a,n.slice(1))}return null}for(let t of n){if(t.method!==e)continue;let n=o.match(t.pattern);if(n)return r(t,o.slice(0,n.index),n.slice(1))}return e===`GET`?i(o===`/`?``:o):null}}function Qd(e){let t={};for(let n of new Set(e.searchParams.keys())){let r=e.searchParams.getAll(n);t[n]=r.length>1?r:r[0]}return t}async function $d(e){let t=await e.text();if(t.trim()!==``)try{return JSON.parse(t)}catch{throw Rd(`request body is not valid JSON`)}}const ef=()=>new Id(413,`too_large`,`attachments are at most ${Oe/1024/1024} MB`);async function tf(e,t){if(Number(e.headers.get(`content-length`)??0)>t)throw ef();let n=[],r=0;for await(let i of e.body??[]){if(r+=i.byteLength,r>t)throw ef();n.push(i)}let i=new Uint8Array(r),a=0;for(let e of n)i.set(e,a),a+=e.byteLength;return i}function nf(){let e={};for(let[t,n]of Object.entries(_d)){let r=n.path.replace(/:(\w+)/g,`{$1}`),i={operationId:t};`query`in n&&(i[`x-query-schema`]=tc(n.query,{io:`input`})),`body`in n&&(i.requestBody={content:{"application/json":{schema:tc(n.body,{io:`input`})}}}),(e[r]??={})[n.method.toLowerCase()]=i}return{openapi:`3.1.0`,info:{title:`board`,version:Kd},paths:e}}const rf={re:{type:`string`,value:`id`,description:`in a thread: its root's ID`},by:{type:`string`,value:`handle`,description:`by an author: a handle, me, or an actor ID`},mentions:{type:`string`,value:`@handle`,optionalValue:!0,description:`mentioning a handle, or you without one`},label:{type:`string`,multiple:!0,value:`k[=v|w]`,description:`with a label on the message or its thread's root`},source:{type:`string`,value:`source`,description:`from a source: a sync key such as slack, or board`},text:{type:`string`,value:`words`,description:`containing these words`},after:{type:`string`,value:`id`,description:`after a message or a cursor`},url:{type:`string`,value:`url`,description:`the board at this URL, not the one the environment points at`},scope:{type:`string`,value:`team`,description:`a team's board in Vercel's API, by its slug or ID`},team:{type:`string`,value:`team`,description:`the same as --scope`,hidden:!0},as:{type:`string`,value:`profile`,description:`write as a profile, such as an agent's name`},avatar:{type:`string`,value:`url`,description:`the profile's avatar, with --as`},human:{type:`boolean`,description:`write as yourself, with no profile or session`},handle:{type:`string`,value:`h`,description:`your handle (default: your Vercel username)`},json:{type:`boolean`,description:`JSON, for programs`},help:{type:`boolean`,short:`h`,description:`this help, or a command's`},version:{type:`boolean`,short:`v`,description:`the CLI's version`},limit:{type:`string`,short:`n`,value:`N`,description:`how many`},"idempotency-key":{type:`string`,value:`key`,description:`sending the same one again posts once`},sync:{type:`string`,multiple:!0,value:`target`,description:`sync the new thread to a target too, e.g. slack:#incidents`},"no-sync":{type:`boolean`,description:`keep it on the board: sync it nowhere`},attach:{type:`string`,multiple:!0,value:`file`,description:`attach a file`},unset:{type:`string`,multiple:!0,value:`k`,description:`remove a label`},channel:{type:`string`,value:`c`,description:`in a channel`},remove:{type:`boolean`,description:`take the reaction back`},all:{type:`boolean`,short:`a`,description:`everything, not only what most want`},timeout:{type:`string`,value:`duration`,description:`how long to wait (default: 30m)`},code:{type:`boolean`,description:`post a code from your account instead of signing in`},"no-wait":{type:`boolean`,description:`start linking, and don't wait for it to finish`},"no-open":{type:`boolean`,description:`don't open the browser`},in:{type:`string`,value:`duration`,description:`once, this long from now, e.g. 1d`},at:{type:`string`,value:`time`,description:`at a time: once, or with --every, the first`},every:{type:`string`,value:`duration`,description:`repeating at this interval, e.g. 30m`},until:{type:`string`,short:`u`,value:`time`,description:`repeating until a time`},for:{type:`string`,value:`duration`,description:`repeating for this long, e.g. 24h`},times:{type:`string`,value:`N`,description:`repeating this many times`},port:{type:`string`,value:`N`,description:`the port to listen on`},dir:{type:`string`,value:`dir`,description:`where the board keeps its log (default: .board/)`},"no-inspect":{type:`boolean`,description:`don't start the inspector`},agent:{type:`string`,value:`name`,description:`the agent whose turn ended`,hidden:!0}},af=(e,t,n)=>({name:e,...rf[e],...t?{description:t}:{},...n?{value:n}:{}});[`re`,`by`,`source`,`label`,`text`,`mentions`,`after`].map(e=>af(e)),[`url`,`scope`,`team`,`as`,`avatar`,`human`,`handle`,`json`,`help`,`version`].map(e=>af(e)),af(`code`),af(`no-wait`),af(`no-open`),af(`limit`,`threads to list (default: 50)`),af(`label`,`label it`,`k=v`),af(`attach`),af(`sync`),af(`no-sync`),af(`idempotency-key`),af(`attach`),af(`idempotency-key`),af(`no-sync`),af(`in`),af(`at`),af(`every`),af(`until`),af(`for`),af(`times`),af(`label`,`label it`,`k=v`),af(`attach`),af(`no-sync`),af(`by`,`scheduled by a handle`),af(`channel`,`posting in a channel`),af(`all`,`done and canceled ones too`),af(`remove`),af(`unset`),af(`limit`,`events to list`),af(`limit`,`messages to read`),af(`channel`,`the channel to check in (default: conformance)`),af(`agent`),af(`all`,`delivery receipts too`),af(`timeout`);const of={re:rf.re,by:rf.by,mentions:rf.mentions,label:rf.label,source:rf.source,text:rf.text};function sf(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];r===`--mentions`?e[n+1]?.startsWith(`@`)?t.push(`--mentions=${e[++n]}`):t.push(`--mentions=me`):t.push(r)}return t}function cf(e){let t=[],n=null,r=null;for(let i=0;i<e.length;i++){let a=e[i];r?a===r?r=null:a===`\\`&&r===`"`&&i+1<e.length?n+=e[++i]:n+=a:/\s/.test(a)?(n!==null&&t.push(n),n=null):a===`"`||a===`'`?(r=a,n??=``):n=a===`\\`&&i+1<e.length?(n??``)+e[++i]:(n??``)+a}if(r)throw Error(`unterminated ${r}`);return n!==null&&t.push(n),t}const lf={...of,all:{type:`boolean`}};function uf(e){let t={},n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i===`--`){n.push(...e.slice(r+1));break}if(!i.startsWith(`-`)||i===`-`){n.push(i);continue}let a=i.indexOf(`=`),o=i.startsWith(`--`)?i.slice(2,a===-1?void 0:a):null,s=o!==null&&Object.hasOwn(lf,o)?lf[o]:null;if(!s)throw Error(`${o===null?i.slice(0,2):`--${o}`} isn't a filter`);if(s.type===`boolean`){if(a!==-1)throw Error(`--${o} takes no value`);t[o]=!0;continue}let c;if(a!==-1)c=i.slice(a+1);else{let t=e[r+1];if(t===void 0||t.length>1&&t.startsWith(`-`))throw Error(`--${o} needs a value`);c=t,r++}t[o]=`multiple`in s?[...t[o]??[],c]:c}return{values:t,positionals:n}}function df(e){let{values:t,positionals:n}=uf(sf(cf(e)));if(n.length>1)throw Error(`expected one channel, got: ${n.join(` `)}`);let r=n[0],i=Eu.safeParse({...r?{channel:r}:{},...t.re?{re:t.re.replace(/^#/,``)}:{},...t.by?{by:t.by.replace(/^@/,``)}:{},...t.mentions?{mentions:t.mentions.replace(/^@/,``)}:{},...t.label?.length?{label:t.label}:{},...t.source?{from:t.source}:{},...t.text?{text:t.text}:{}});if(!i.success){let e=i.error.issues[0];throw Error(`${e?.path.length?`--${String(e.path[0])}: `:``}${e?.message??`invalid filters`}`)}return{filters:i.data,all:t.all===!0}}const ff=e=>e.channel!==void 0||e.re!==void 0||e.by!==void 0||e.mentions!==void 0||e.from!==void 0||e.text!==void 0||(e.label?.length??0)>0;function pf(e,t){let n,r;try{({filters:n,all:r}=df(t.tail))}catch(t){throw Error(`watch ${e}: ${t.message}`)}if(n.mentions===`me`)throw Error(`watch ${e}: a watcher has no "me": use --mentions @handle`);let i=ff(n);if(t.when===`enters`&&!i)throw Error(`watch ${e}: \`when: enters\` needs a filter to enter`);return{filters:n,criteria:i,enters:t.when===`enters`,all:r}}function mf(e){try{Reflect.get(globalThis,Symbol.for(`@vercel/request-context`))?.get?.()?.waitUntil?.(e)}catch{}}const hf=1e4,gf=e=>((e instanceof Error?e.message:String(e))||`unknown error`).slice(0,500),_f=e=>e?.startsWith(`https://`)?e:null;function vf(e){let t=typeof process<`u`&&process.env.VERCEL===`1`?process.env:null,n=t?.VERCEL_TARGET_ENV||t?.VERCEL_ENV,r=n===`preview`&&t?.VERCEL_GIT_COMMIT_REF||null;return!e||n!==`production`&&!r?null:{path:new URL(e).pathname,...r?{branch:r}:{}}}function yf(e){let{registry:t,rethrow:n}=e,r=e.binding,i=null,a=null;async function o(n){let r=await e.hash();return i&&i.url===n&&i.result.hash===r&&Date.now()-i.at<hf?i.result:(a??=e.wakeAt(n).then(e=>t.register(e)).then(e=>(i={url:n,at:Date.now(),result:e},e)).finally(()=>{a=null}),a)}async function s(e){let n={};if(!r().subscriptions[e.watcher])n={skip:!0};else try{await r().run(e.watcher,e.event,{trigger:`watch:${e.watcher}:${e.id}`,attempt:e.attempt+1})}catch(t){console.error(`[board] watcher ${e.watcher} failed:`,t),n={error:gf(t)}}await t.ack(e.id,{lease:e.lease,...n}).catch(e=>console.error(`[board] couldn't ack a match:`,gf(e)))}async function c(){let e=0,n=Date.now()+24e4;for(;Date.now()<n;){let n=await t.matches({limit:10});if(n.length===0)break;await Promise.all(n.map(s)),e+=n.length}return e+await r().pull()}let l=null;function u(){if(l)return;let n=l=new AbortController;(async()=>{for(let i=1e3;!n.signal.aborted;)try{await o(null);let e=await t.matches({limit:10,wait:25,signal:n.signal});await Promise.all(e.map(s)),await r().pull(),i=1e3}catch(t){if(n.signal.aborted)break;console.error(`[board] couldn't pull matches from ${e.remote}:`,gf(t)),await new Promise(e=>setTimeout(e,i)),i=Math.min(i*2,6e4)}})()}let d=null,f=0;function p(){if(d)return d;if(!e.hasWork()||Date.now()-f<hf)return Promise.resolve();let t=_f(r().url());return!t&&typeof process<`u`&&process.env.VERCEL===`1`?Promise.resolve():(d=o(t).then(()=>{},t=>{d=null,f=Date.now(),console.error(`[board] couldn't register with ${e.remote}:`,gf(t))}),t||u(),d)}return{start:p,routes:[{method:`POST`,path:`/wake`,async handle(t){d??=Promise.resolve();let i=t.headers.get(`x-board-watchers`)!==await e.hash(),a=(async()=>(i&&await o(_f(r().url())),c()))();mf(a.catch(e=>console.error(`[board] couldn't run what woke it:`,gf(e))));let s,l=new Promise(e=>s=setTimeout(()=>e(null),2e3));try{let e=await Promise.race([a.catch(n),l]);return e===null?new Response(null,{status:202}):Ud({ran:e})}finally{clearTimeout(s)}}},{method:`POST`,path:`/watchers`,async handle(t,{caller:i}){if(i)return e.registerFor(i,t);d??=Promise.resolve();let a=_f(r().url()),s=await o(a).catch(n);return a||u(),Ud(s)}}],registerNow:()=>o(_f(r().url())),close:()=>{l?.abort(),l=null}}}const bf=(e,t)=>e<t?-1:+(e>t);function xf(e,t=[]){let n=Object.keys(e).sort(bf).map(t=>[t,e[t].tail,e[t].when]);return t.length>0&&n.push([`sync`,[...t].sort((e,t)=>bf(e.key,t.key)).map(e=>[e.key,e.platform,e.signIn])]),JSON.stringify(n)}const Sf=/^[A-Za-z][A-Za-z0-9-]{0,31}$/,Cf=/* @__PURE__ */ new Set([`identity`,`edit`,`delete`,`schedule`,`cancelSchedule`,`upload`,`uploadStart`,`uploadFinish`,`watchers`,`register`,`matches`,`ack`,`syncImport`,`syncReceipt`,`syncThread`,`syncFind`,`syncCopies`,`syncRoots`,`inboxPush`,`inboxNext`,`inboxAck`,`inbox`,`syncCode`,`syncAccount`,`syncUnlink`]);function wf(e){let t=e.replace(/[^A-Za-z0-9-]+/g,`-`).replace(/^-+|-+$/g,``);return/^[A-Za-z]/.test(t)||(t=`u-${t}`),t.slice(0,32).replace(/-+$/,``)}function Tf(e,t){let n=new Set([...t,`middleware`,`client`].map(e=>e.toLowerCase())),r=wf(e),i=r;for(let e=2;n.has(i.toLowerCase());e++)i=`${r.slice(0,31-String(e).length)}-${e}`;return i}function Ef(e){let{access:t}=e.principal;if(t.everywhere(`manage`))return null;let n=Object.entries(t.summary()).map(([e,t])=>`${e}=${t.join(`,`)}`);return n.length>0?n.join(`;`):`*=`}const Df=e=>((e instanceof Error?e.message:String(e))||`unknown error`).slice(0,500),Of=e=>{throw e instanceof yd?new Id(e.status>=400?e.status:502,e.code,e.message,{...e.hint===void 0?{}:{hint:e.hint},origin:e.origin}):e instanceof Id||e instanceof Error&&e.name===`AbortError`?e:new Id(502,`unreachable`,`the board didn't answer: ${Df(e)}`)};function kf(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!=null&&r!==!1){if(n===`label`&&Array.isArray(r))for(let[e,n]of r)t.append(`label`,n===null?e:`${e}=${n.join(`|`)}`);else if(Array.isArray(r))for(let e of r)t.append(n,String(e));else t.set(n,String(r))}let n=t.toString();return n?`?${n}`:``}function Af(e,t){let n=(t.headers.get(`content-disposition`)??``).match(/filename\*=UTF-8''([^;]+)/)?.[1],r=`file`;try{n&&(r=decodeURIComponent(n))}catch{}return{attachment:{id:e,name:r,type:t.headers.get(`content-type`)??`application/octet-stream`,size:Number(t.headers.get(`content-length`)??0)},data:t.body??/* @__PURE__ */ new Uint8Array}}function jf(e,t,n){if(e!==void 0&&!/^https?:\/\/[^/]/.test(e))throw Error(`http: ${e} isn't a URL: pass the board's, like https://board.example.com/api/board`);if(e===void 0&&!n)throw Error(`http: pass the board's URL: outside Node there's no environment to find it in`);let r=(e??n.url()).replace(/\/+$/,``),i=t.fetch??n?.fetch(r)??((e,t)=>globalThis.fetch(e,t)),a=null,o={},s=[],c=null,l=()=>c??=Md(xf(o,s)).then(e=>e.slice(0,32)),u=()=>{if(!a)throw Error(`http: this backend isn't serving a board yet: pass it to board({ backend })`);return a},d=(e,t)=>kd({url:r,fetch:i,profile:e===void 0?()=>n?.profile().profile??null:e,session:t||e===null?null:()=>n?.profile().session??null}),f=d(null,!0),p=/* @__PURE__ */ new Map;function m(e){if(!Sf.test(e))throw new Id(400,`invalid_request`,`as: ${e}: profiles start with a letter and use up to 32 letters, numbers, and hyphens`);let t=p.get(e);return t||p.set(e,t=d(e,!0)),t}let h=/* @__PURE__ */ new Map;function g(e){let t=JSON.stringify(e??(e===null?null:`\0`)),n=h.get(t);return n||h.set(t,n=d(e,!1)),n}function _(e){return e.origin.via?.kind===`engine`?f:e.origin.via?.kind===`client`?(e.self!==null&&m(e.self),g(`profile`in e?e.profile:e.self??void 0)):m(e.self??`client`)}let v=null,y=()=>(v??=i(r).then(async e=>{if(!e.ok)throw new Id(e.status>=400?e.status:502,`no_board`,`There's no board at ${r}: it answered ${e.status}.`,{origin:`handle`});return await e.json()},Of)).catch(e=>{throw v=null,e}),b=null,x=()=>b??=f.me().then(e=>e.principal).catch(e=>{throw b=null,e}),S=async e=>Fd(await x(),e);async function C(e,t,n,i){let a=_d[t],o={...n},s=a.path.replace(/:(\w+)/g,(e,t)=>{let n=o[t];return delete o[t],encodeURIComponent(String(n))}),c;if(t===`upload`){let{data:t,name:r,type:a}=n;if(t.byteLength>4194304){let n=await e.upload({data:t,name:r??`file`,...a?{type:a}:{}}).catch(Of);return Response.json({attachment:n})}c=await e.request(s,{method:`POST`,body:t,headers:{...a?{"content-type":a}:{},...r===null?{}:{"x-board-filename":encodeURIComponent(r)}},signal:i}).catch(Of)}else c=a.method===`GET`?await e.request(`${s}${kf(o)}`,{signal:i}).catch(Of):await e.request(s,{method:`POST`,body:new TextEncoder().encode(JSON.stringify(o)),headers:{"content-type":`application/json`},signal:i}).catch(Of);if(c.ok)return c;try{let e=await c.json();if(e.error?.message)throw new Id(c.status,e.error.code??`error`,e.error.message,typeof e.error.hint==`string`?{hint:e.error.hint}:{})}catch(e){if(e instanceof Id)throw e}throw new Id(502,`remote_error`,`${r} answered ${c.status}`)}async function w(e,t,n,a){if(e===`me`){let{principal:e,author:n,actor:r}=t;return{actor:r.id,principal:e.id,kind:r.kind,handle:r.handle,name:r.name,avatar:r.avatar,profile:n.profile,session:n.session,expiresAt:e.expiresAt?.toISOString()??null,can:e.access.summary()}}if(Cf.has(e))throw Bd(`this board's callers act as its project on ${r}, which can't tell them apart: ${e} is the project's own to do there`);let s=Ef(t),c=t.actor.avatar?.startsWith(`https://`)?t.actor.avatar:void 0,l=kd({url:r,fetch:i,profile:{name:Tf(t.actor.handle,Object.keys(o)),...c?{avatar:c}:{}},session:null,...s===null?{}:{headers:{"x-board-scope":s}}});(e===`post`||e===`posted`)&&typeof n.id==`string`&&(n={...n,id:await S(await Nd(`board-gateway`,t.principal.id,n.id)).catch(Of)});let u=await C(l,e,n,a);return e===`attachment`?Af(String(n.id),u):u.json()}async function T(e,t,n,r){let i=k();if(`identity`in t)return w(e,t.identity,n,r);let a=_(t);`self`in t&&t.origin.via?.kind===`engine`&&await i,(e===`post`||e===`posted`)&&`self`in t&&typeof n.id==`string`&&Pd.test(n.id)&&(n={...n,id:await S(n.id).catch(Of)});let o=await C(a,e,n,r);return e===`attachment`?Af(String(n.id),o):o.json()}let E={...Object.fromEntries(Jd.map(e=>[e,(t,n,r)=>T(e,t,n,r)])),async discovery(){return y()},async readSource(e,t,n){return`self`in e&&u().sync.some(e=>e.key===t.key)?u().readSource(t.key,t.target,t.limit??50):T(`readSource`,e,t,n)},async joinSource(e,t,n){return`self`in e&&u().sync.some(e=>e.key===t.key)?u().joinSource(t.key,t.target):T(`joinSource`,e,t,n)},async synced(e,t,n){let{targets:r}=await T(`synced`,e,t,n);return{targets:await Promise.all(r.map(async e=>({...e,url:e.url??(e.thread!==null&&e.message!==null?await u().linkOf(e.key,e.thread,e.message):null)})))}},async linked(e,t,n){let r=()=>new Id(404,`message_not_found`,`no message on this board for that link`),i=await(async()=>{for(let{platform:e,thread:r,message:i}of u().locate(t.url))for(let t of u().sync.filter(t=>t.platform===e)){let e=await f.syncFind({thread:`${t.key}:${r}`,...i===null?{}:{message:i}},{signal:n}).catch(Of),a=i===null?e.thread===null?null:(await f.syncThread(e.thread).catch(Of)).root:e.message;if(a!==null)return a}return null})();if(i===null)return T(`linked`,e,t,n);try{return await E.message(e,{id:i},n)}catch(e){throw e instanceof Id&&e.status===404?r():e}},async typing(e,t,n){let{targets:r}=await T(`typing`,e,t,n);if(!(`self`in e)||u().sync.length===0)return{targets:r};let{message:i,replies:a}=await E.message(e,{id:t.id},n),o=await u().typing([i,...a],t.status).catch(e=>(console.warn(`[board] skipped typing where this board syncs:`,Df(e)),[]));return{targets:[...r,...o]}}};async function D(e){let t=vf(e);return t&&(await y()).wake_by_path?t:{url:e}}let O=yf({remote:r,registry:{register:e=>f.register({...e,watch:o,...s.length>0?{sync:s}:{}}),matches:e=>f.matches(e),ack:(e,t)=>f.ack(e,t)},wakeAt:D,binding:u,hash:l,hasWork:()=>Object.keys(o).length>0||s.length>0,rethrow:Of,registerFor:async(e,t)=>Ud(await E.register(e,Ru.parse(await t.json()),t.signal))}),k=O.start;return{...E,routes:O.routes,keeps:!1,bind(e){if(a)throw Error(`http: this backend already serves a board: create one http() per board()`);for(let[t,n]of Object.entries(e.subscriptions)){if(n.kind===`sync`){t===`@sync`&&(s=e.sync.map(e=>({...e})));continue}if(!Sf.test(t))throw Error(`watch ${t}: ids start with a letter and use up to 32 letters, numbers, and hyphens`);pf(t,n),o[t]={tail:n.tail,when:n.when}}c=null,a=e},registerWatchers:O.registerNow,close:O.close}}function Mf(e,t={}){return jf(e,t,null)}const Nf=/```[\s\S]*?```/g,Pf=/`[^`\n]*`/g,Ff=`[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?`,If=RegExp(`(?<![\\w@.-])@(${Ff}(?:/${Ff})?)(?!:|[a-z0-9_/-]|\\.(?=[a-z0-9]))`,`gi`),Lf=/(?<![\w@.-])@\[([^\]\s]+)\]/g,Rf=e=>e.replace(Nf,e=>` `.repeat(e.length)).replace(Pf,e=>` `.repeat(e.length));function zf(e){let t=Rf(e),n=[];for(let e of t.matchAll(Lf)){let t=e[1];t!==void 0&&n.push({index:e.index,token:{kind:`actor`,actor:t},key:`actor:${t}`})}for(let e of t.replace(Lf,e=>` `.repeat(e.length)).matchAll(If)){let t=e[1]?.toLowerCase();t!==void 0&&n.push({index:e.index,token:{kind:`handle`,handle:t},key:`handle:${t}`})}let r=/* @__PURE__ */ new Set;return n.sort((e,t)=>e.index-t.index).filter(({key:e})=>!r.has(e)&&r.add(e)).map(({token:e})=>e)}function Bf(e,t){let n=Rf(e),r=[];for(let e of n.matchAll(Lf))r.push({index:e.index,length:e[0].length,token:{kind:`actor`,actor:e[1]}});for(let e of n.replace(Lf,e=>` `.repeat(e.length)).matchAll(If))r.push({index:e.index,length:e[0].length,token:{kind:`handle`,handle:e[1].toLowerCase()}});let i=``,a=0;for(let{index:n,length:o,token:s}of r.sort((e,t)=>e.index-t.index)){let r=e.slice(n,n+o);i+=e.slice(a,n)+(t(s,r)??r),a=n+o}return i+e.slice(a)}const Vf=[`read`,`post`,`react`,`label`,`sync`,`manage`],Hf={read:[],post:[],react:[`read`],label:[`read`],sync:[`read`],manage:[`read`,`post`,`react`,`label`,`sync`]},Uf=new Map(Vf.map((e,t)=>[e,t])),Wf=`write *, a channel, or a channel and its subtree (feedback/)`;function Gf(e){if(e===`*`)return{kind:`all`};if(e.includes(`*`)){let t=e.slice(0,e.indexOf(`*`)).replace(/\/+$/,``),n=t===``?`write * for every channel`:Yl.safeParse(t).success?`write ${t}/ for ${t} and its subtree`:Wf;throw Error(`invalid channel pattern ${e}: ${n}`)}let t=e.endsWith(`/`),n=t?e.slice(0,-1):e;if(!Yl.safeParse(n).success)throw Error(`invalid channel pattern ${e||`(empty)`}: ${Wf}`);return t?{kind:`subtree`,path:n}:{kind:`exact`,path:n}}const Kf=e=>e.kind===`all`?`*`:e.kind===`subtree`?`${e.path}/`:e.path;function qf(e){let t=/* @__PURE__ */ new Set,n=e=>{if(!Uf.has(e))throw Error(`unknown permission ${String(e)}: use ${Vf.join(`, `)}`);if(!t.has(e)){t.add(e);for(let t of Hf[e])n(t)}};for(let t of e===`all`?Vf:e)n(t);return t}const Jf=/* @__PURE__ */ new Set;function Yf(e){let t=null,n=/* @__PURE__ */ new Map,r=[];for(let[i,a]of e)i.kind===`all`?t=a:i.kind===`exact`?n.set(i.path,a):r.push([i.path,a]);return r.sort((e,t)=>t[0].length-e[0].length),{all:t,exact:n,subtrees:r}}const Xf=(e,t)=>e===t||e.startsWith(`${t}/`);function Zf(e,t,n=!1){if(!n){let n=e.exact.get(t);if(n)return n}for(let[n,r]of e.subtrees)if(Xf(t,n))return r;return e.all??Jf}const Qf=(e,t)=>t.kind===`all`?e.all??Jf:Zf(e,t.path,t.kind===`subtree`),$f=(e,t)=>e.size===t.size&&[...e].every(e=>t.has(e));function ep(e,t){if(t.kind===`exact`)return Zf(e,t.path,!0);if(t.kind===`subtree`){for(let[n,r]of e.subtrees)if(n!==t.path&&Xf(t.path,n))return r}return e.all??Jf}function tp(e){let t=Yf(e);return Yf(e.filter(([e,n])=>e.kind===`all`?n.size>0:!$f(n,ep(t,e))))}function np(e){return e===`all`||Array.isArray(e)?[[{kind:`all`},qf(e)]]:Object.entries(e).map(([e,t])=>[Gf(e),qf(t)])}const rp=e=>[...e.all?[[{kind:`all`},e.all]]:[],...e.subtrees.map(([e,t])=>[{kind:`subtree`,path:e},t]),...[...e.exact].map(([e,t])=>[{kind:`exact`,path:e},t])],ip=Symbol(`board.access`),ap=e=>typeof e==`object`&&ip in e;function op(e){let t=rp(e),n=n=>(e.all?.has(n)??!1)&&t.every(([,e])=>e.has(n)),r=/* @__PURE__ */ new Map;return{[ip]:e,can:(t,n)=>Zf(e,n).has(t),readable(t){let n=r.get(t);return n===void 0&&r.set(t,n=Zf(e,t).has(`read`)),n},readsAll:n(`read`),everywhere:n,anywhere:e=>t.some(([,t])=>t.has(e)),narrow(n){let r=ap(n)?n[ip]:tp(np(n)),i=/* @__PURE__ */ new Map([[`*`,{kind:`all`}]]);for(let[e]of[...t,...rp(r)])i.set(Kf(e),e);return op(tp([...i.values()].map(t=>{let n=Qf(r,t);return[t,new Set([...Qf(e,t)].filter(e=>n.has(e)))]})))},summary(){let e=t.map(([e,t])=>[Kf(e),t]);e.sort(([e],[t])=>e===`*`?-1:t===`*`?1:e.localeCompare(t));let n={};for(let[t,r]of e)n[t]=[...r].sort((e,t)=>Uf.get(e)-Uf.get(t));return n}}}function sp(e){return op(tp(np(e)))}const cp=sp(`all`);function lp(e){if(e.length>4e3)throw Error(`x-board-scope is longer than 4000 characters`);let t={},n=e.split(`;`).map(e=>e.trim());if(n.every(e=>e===``))throw Error(`x-board-scope is empty: write pattern=permissions, like dev/=read,post`);for(let e of n){if(e===``)continue;let n=e.indexOf(`=`);if(n<0)throw Error(`x-board-scope entry ${e} needs =: write pattern=permissions, like dev/=read,post`);let r=e.slice(0,n).trim(),i=e.slice(n+1).trim();if(Object.hasOwn(t,r))throw Error(`x-board-scope lists ${r} twice`);Gf(r);let a=i===``?[]:i.split(`,`).map(e=>e.trim());if(a.length===1&&a[0]===`all`){t[r]=`all`;continue}for(let e of a)if(!Uf.has(e))throw Error(`x-board-scope: unknown permission ${e||`(empty)`}: use ${Vf.join(`, `)}, or all`);t[r]=a}return t}const up=[`claude`,`codex`,`grok`,`pi`],dp=/^[A-Za-z][A-Za-z0-9-]{0,31}$/,fp=/^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$/;function pp(e){let t=e.get(`x-board-profile`)?.trim()||null;if(t!==null&&!dp.test(t))throw Rd(`profile names start with a letter and use up to 32 letters, numbers, and hyphens`);let n=e.get(`x-board-avatar`)?.trim()||null;if(n!==null&&!hp(n))throw Rd(`avatars must be https URLs (http only on localhost)`);let r=e.get(`x-board-session`)?.trim().slice(0,200)||null,i=e.get(`x-board-handle`)?.trim().toLowerCase()||null;if(i!==null&&!fp.test(i))throw Rd(`invalid handle: ${i}`);let a=e.get(`x-board-name`),o=null;if(a)try{o=decodeURIComponent(a).replace(/[\u0000-\u001f\u007f]/g,``).trim().slice(0,128)||null}catch{throw Rd(`x-board-name must be URI-encoded`)}let s=e.get(`x-board-scope`);if(s!==null)try{lp(s)}catch(e){throw Rd(e.message,`invalid_scope`)}return{profile:t,avatar:n,session:r,handle:i,name:o,scope:s}}function mp(e,t,n){let r=e.kind===`person`&&e.facts?.issuer!==`host`&&t.handle?t.handle:e.handle,i=e.kind===`person`?t.name:null,a=t.profile?.toLowerCase()??null,o=a===null?e.id:`${e.id}+${a}`,s=a!==null&&up.includes(a),c={id:o,kind:a===null?e.kind:`agent`,handle:a===null?r:`${r}/${a}`,name:t.profile??i??r,avatar:t.avatar??(s?`${n}/avatars/${a}`:null)};return{author:{actor:o,principal:e.id,profile:a,session:t.session},actor:c}}function hp(e){try{let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`&&[`localhost`,`127.0.0.1`].includes(t.hostname)}catch{return!1}}const gp=e=>Bd(`this token can't use this board: add ${e} to access`),_p=e=>{let t=new URL(e);return`${t.host}${t.pathname.replace(/\/+$/,``)}`.replace(/[%:]/g,e=>e===`%`?`%25`:`%3A`)};function vp(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=_p(n),r=t.get(e);if(r!==void 0&&r!==n)throw Error(`access: oidc issuers ${r} and ${n} name the same principals, oidc:${e}:<sub>: pin one of them`);t.set(e,n)}return new Set(e)}const yp=e=>[...new Set(e.flatMap(e=>typeof e!=`function`&&e.issuer===`oidc`?[e.url]:[]))];function bp(e){let t=typeof e.access==`function`?[]:e.access,n=typeof e.access==`function`?e.access:null,r=vp(yp(t));async function i(n,i){if(i?.issuer===`host`)throw Bd(`this token can't use this board: its board no longer takes a host's principals`);if(i?.issuer===`oidc`&&!r.has(i.iss))throw zd(`untrusted issuer: ${i.iss}`);let a=i?.claims??{},o=i?.issuer===`vercel`?await e.project():null,s=o?{teamId:i.team??o.teamId,projectId:o.id}:{teamId:null,projectId:null},c=String(a.environment??``),l=xp(),u=o!==null&&o.id!==null&&a.project_id===o.id,d=u&&l!==null&&c===l;for(let e of t){if(typeof e==`function`){if(d)continue;let t=await e(n);if(t===void 0)continue;if(t===null)throw Bd(`this token can't use this board`);return sp(t)}if(i&&e.issuer===i.issuer&&(e.issuer!==`oidc`||e.url===i.iss)&&e.matches(a,s))return e.access}if(d)return cp;throw i?i.issuer===`oidc`?gp(`oidc({ issuer: '${i.iss}', claims, can })`):i.issuer===`github`?gp(`githubActions({ repository: '${String(a.repository)}', can })`):u?Bd(`this token can't use this board: it runs in ${l??`no Vercel environment`}, so its ${c||`unnamed`} deployments need vercelProject({ project: 'self', environments: ['${c}'], can })`):gp(`vercelProject({ project: '${String(a.project??``)||String(a.project_id)}', can })`):Bd(`this token can't use this board`)}async function a(t){let r=cp,a=t.facts?.issuer===`host`;if(t.id.startsWith(`board:`)||t.kind===`external`&&!a)r=cp;else{if(a){if(!e.hosts)throw Bd(`this token can't use this board: its board no longer takes a host's principals`);let{exp:n}=t.facts.claims;if(typeof n==`number`&&n*1e3<=Date.now())throw zd(`token expired`)}if(n){let e=await n(t);if(e==null)throw Bd(`this token can't use this board`);r=sp(e)}else t.kind!==`person`&&(r=await i(t,(a?void 0:t.facts)??Sp(t.id)))}return t.scope===void 0?r:r.narrow(lp(t.scope))}async function o(e){try{return await a(e)}catch(e){let t=e.status;if(t===401||t===403)return null;throw e}}return{grant:a,accessNow:o}}const xp=()=>process.env.VERCEL_TARGET_ENV||process.env.VERCEL_ENV||null;function Sp(e){let t=e.match(/^vercel:project:([^:]+):([^:]+)$/);return t?{issuer:`vercel`,iss:``,claims:{project_id:t[1],environment:t[2]}}:null}const Cp=Symbol(`board.oidcTokens`),wp=/* @__PURE__ */ new WeakSet,Tp=e=>Cp in e,Ep=e=>wp.has(e),Dp=/^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*:[^\s+\]]{1,200}$/,Op=[`person`,`deployment`,`workflow`,`external`];function kp(e){let t=e=>{throw TypeError(`authenticate returned an invalid principal: ${e}`)};(typeof e!=`object`||!e)&&t(`not an object`),(typeof e.id!=`string`||!Dp.test(e.id)||e.id.startsWith(`board:`))&&t(`id must look like \`vercel:user:<id>\`, got ${JSON.stringify(e.id)}`),Op.includes(e.kind)||t(`kind must be one of ${Op.join(`, `)}`),(typeof e.handle!=`string`||!/^\S{1,64}$/.test(e.handle))&&t(`handle must be 1-64 characters, no spaces`);let n=e.expiresAt??null;if(n!==null&&(!(n instanceof Date)||Number.isNaN(n.getTime()))&&t(`expiresAt must be a Date or null`),n!==null&&n.getTime()<=Date.now())throw zd(`token expired`);let r=n===null?{}:{exp:Math.floor(n.getTime()/1e3)};return{id:e.id,kind:e.kind,handle:e.handle,expiresAt:n,facts:{issuer:`host`,iss:``,claims:r}}}function Ap(e,t,n){let r=t||e.access!==void 0,i=e.access??[],a=null,o=()=>(a??=(async()=>{if(!n)return{id:e.project?.id??null,teamId:e.project?.teamId??null};let t=await n(),[r,i]=await Promise.all([t.ownProjectId(e.project),t.ownTeamId(e.project)]);return{id:r,teamId:i}})()).catch(e=>{throw a=null,e});async function s(t){return n?(await n()).discoveryIdentity(t,e.project):{projectId:e.project?.id??null,teamId:e.project?.teamId??null}}let c=null,l=()=>e.authenticate?Promise.resolve(e.authenticate):c??=n?n().then(e=>e.oidcTokens()):Promise.reject(new Id(501,`no_verifier`,`this build of board verifies no tokens: pass board({ authenticate })`)),u=bp({access:i,project:o,hosts:e.authenticate!==void 0&&!Tp(e.authenticate)}),d={project:o,issuers:typeof i==`function`?[]:yp(i)},f=/* @__PURE__ */ new Map,p=/* @__PURE__ */ new WeakMap;async function m(e){let t=e=>e.expiresAt===null||e.expiresAt.getTime()>Date.now(),n=p.get(e);if(n){let e=await n;if(t(e))return e}let r=e.credential===null?null:[e.audience,e.credential,e.headers.get(`x-vercel-oidc-token`)??``].join(``),i=r===null?void 0:f.get(r);if(i&&i.until>Date.now())return p.set(e,i.principal),i.principal;let a=h(e);return p.set(e,a),r!==null&&a.then(e=>{e.facts?.issuer!==`host`&&e.expiresAt!==null&&(f.size>=1e3&&f.delete(f.keys().next().value),f.set(r,{principal:a,until:e.expiresAt.getTime()}))},()=>p.delete(e)),a}async function h(e){let t=await l(),n;try{n=await t({...e,board:d})}catch(e){throw e instanceof Response?new Ld(e):e}if(n instanceof Response)throw new Ld(n);if(n==null)throw zd(`missing bearer token`);return Ep(n)?n:kp(n)}return{open:r,project:o,discoveryIdentity:s,async identify(e){let t=await m(e),n=e.claims.scope===null?t:{...t,scope:e.claims.scope},{author:r,actor:i}=mp(n,e.claims,e.audience);return{principal:{...n,access:await u.grant(n)},author:r,actor:i}},accessNow:e=>u.accessNow(e)}}const jp={claude:`m4.7144 15.9555 4.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608 1.5179.1032 2.2767.1578 1.6514.0972 2.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973 9.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686 1.9064 1.4754 2.4893 1.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335 6.6997 0l.9957.1336.419.3642.6192 1.4147 1.0018 2.2282 1.5543 3.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853 1.8517-.5586 2.9021-.3643 1.9429h.2125l.2429-.2429.9835-1.3053 1.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759 1.1293-.34 1.1657-1.0625 1.3478-.8804 1.1414-1.2628 1.7-.7893 1.36.0729.1093.1882-.0183 2.8535-.607 1.5421-.2794 1.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607 1.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929 1.0686 2.0035 1.8092 2.5075 2.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496 2.3436 3.5214.1214 1.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38 17.959l-1.1414-1.9428-.1397.079-.674 7.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328 1.9672-2.1796 2.9446-1.7243 1.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889 2.386-3.0357 1.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385 4.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429 1.9064-1.3114Z`,openai:`M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z`,x:`M14.234 10.162 22.977 0h-2.072l-7.591 8.824L7.251 0H.258l9.168 13.343L.258 24H2.33l8.016-9.318L16.749 24h6.993zm-2.837 3.299-.929-1.329L3.076 1.56h3.182l5.965 8.532.929 1.329 7.754 11.09h-3.182z`,slack:`M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52v2.52zM6.313 15.165a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313zM8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.528 2.528 0 0 1 2.521 2.522v2.52H8.834zM8.834 6.313a2.528 2.528 0 0 1 2.521 2.521 2.528 2.528 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312zM18.956 8.834a2.528 2.528 0 0 1 2.522-2.521A2.528 2.528 0 0 1 24 8.834a2.528 2.528 0 0 1-2.522 2.521h-2.522V8.834zM17.688 8.834a2.528 2.528 0 0 1-2.523 2.521 2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.528 2.528 0 0 1 2.523 2.522v6.312zM15.165 18.956a2.528 2.528 0 0 1 2.523 2.522A2.528 2.528 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.522v-2.522h2.52zM15.165 17.688a2.527 2.527 0 0 1-2.52-2.523 2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.523h-6.313z`,github:`M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12`,whatsapp:`M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z`},Mp={claude:{background:`#D97757`,mark:{path:jp.claude}},codex:{background:`#000000`,mark:{path:jp.openai}},grok:{background:`#000000`,mark:{path:jp.x}},pi:{background:`#1f1f1f`,mark:{glyph:`π`}}};function Np(e){let t=Mp[e]??{background:`#666666`,mark:{glyph:e.slice(0,1).toUpperCase()}},n=`path`in t.mark?`<path transform="translate(30 30) scale(2.8333)" fill="#ffffff" d="${t.mark.path}"/>`:`<text x="64" y="86" font-family="ui-sans-serif,system-ui,sans-serif" font-size="66" font-weight="600" text-anchor="middle" fill="#ffffff">${t.mark.glyph}</text>`;return`<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><rect width="128" height="128" rx="28" fill="${t.background}"/>${n}</svg>`}var Pp=class extends Id{responses;constructor(e){super(422,`dropped`,e.join(`
344
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}r.count>1&&e.reused===`ref`&&a(n)}e.external&&(e.sharedDefsExtractedFor=e.external)}function zo(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;zo(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}const Bo=/* @__PURE__ */ new Set([`type`,`properties`,`required`,`additionalProperties`]),Vo=[`oneOf`,`anyOf`];function Ho(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function Uo(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!Bo.has(e))return null;t.push(n)}let n={},r=/* @__PURE__ */ new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??Ho(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}Ge(n,r,e.length===1?e[0]:Uo(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=Ho(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function Wo(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of Bo)if(t in e)return;let n=t.filter(e=>Vo.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=Uo(t);else{let e=n[0],i=Vo.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>Uo([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,No(e,r))}function Go(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):No(i,s),No(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())zo(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])Wo(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}No(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,Ge(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Jo(t,`input`,e.processors),output:Jo(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function Ko(e,t){let n=t??{seen:/* @__PURE__ */ new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return Ko(r.element,n);if(r.type===`set`)return Ko(r.valueType,n);if(r.type===`lazy`)return Ko(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return Ko(r.innerType,n);if(r.type===`intersection`)return Ko(r.left,n)||Ko(r.right,n);if(r.type===`record`||r.type===`map`)return Ko(r.keyType,n)||Ko(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:Ko(r.in,n)||Ko(r.out,n);if(r.type===`object`){for(let e in r.shape)if(Ko(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(Ko(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(Ko(e,n))return!0;return!!(r.rest&&Ko(r.rest,n))}return!1}const qo=(e,t={})=>n=>{let r=Po({...n,processors:t});return Io(e,r),Ro(r,e),Go(r,e)},Jo=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Po({...i??{},target:a,io:t,processors:n});return Io(e,o),Ro(o,e),Go(o,e)},Yo=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},Xo=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},Zo=(e,t)=>{Yo(e,`minimum`,t),Xo(e,`maximum`,t)},Qo=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},$o=(e,t)=>{e.patterns??=/* @__PURE__ */ new Set,e.patterns.add(t)},es=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},ts=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},ns=(e,t)=>Yo(e,`minimum`,t.minimum),rs=(e,t)=>Xo(e,`maximum`,t.maximum),is=e=>(t,n)=>{ts(t,n.format);let[r,i]=e[n.format];Yo(t,`minimum`,r),Xo(t,`maximum`,i)},as={greater_than:(e,t)=>Yo(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>Xo(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Qo(e,t.value),number_format:is(ut),bigint_format:is(dt),min_length:ns,max_length:rs,length_equals:(e,t)=>Zo(e,t.length),min_size:ns,max_size:rs,size_equals:(e,t)=>Zo(e,t.size),string_format:(e,t)=>{ts(e,t.format),t.pattern&&$o(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>es(e,t.mime)};function os(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)as[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&Yo(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&Yo(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&Xo(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&Xo(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Qo(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&es(t,i.mime);for(let e of i.patterns??[])$o(t,e);return t}const ss={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},cs=/* @__PURE__ */ new Map([[li,Wn],[di,Gn]]),ls=e=>cs.get(e)??e,us=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=os(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=ss[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(ls);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},ds=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=os(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=/* @__PURE__ */ new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):Fo(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},fs=(e,t,n,r)=>{n.type=`boolean`},ps=(e,t,n,r)=>{Fo(e,t,n,r,`BigInt cannot be represented in JSON Schema`)},ms=(e,t,n,r)=>{Fo(e,t,n,r,`Symbols cannot be represented in JSON Schema`)},hs=(e,t,n,r)=>{t.target===`openapi-3.0`?(n.type=`string`,n.nullable=!0,n.enum=[null]):n.type=`null`},gs=(e,t,n,r)=>{Fo(e,t,n,r,`Undefined cannot be represented in JSON Schema`)},_s=(e,t,n,r)=>{Fo(e,t,n,r,`Void cannot be represented in JSON Schema`)},vs=(e,t,n,r)=>{n.not={}},ys=(e,t,n,r)=>{},bs=(e,t,n,r)=>{},xs=(e,t,n,r)=>{Fo(e,t,n,r,`Date cannot be represented in JSON Schema`)},Ss=(e,t,n,r)=>{let i=e._zod.def,a=Le(i.entries);if(a.length===0){n.not={};return}a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Cs=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(Fo(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(Fo(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},ws=(e,t,n,r)=>{Fo(e,t,n,r,`NaN cannot be represented in JSON Schema`)},Ts=(e,t,n,r)=>{let i=n,a=e._zod.pattern;if(!a)throw Error(`Pattern not found in template literal`);i.type=`string`,i.pattern=a.source},Es=(e,t,n,r)=>{let i=n;i.type=`string`,i.format=`binary`,i.contentEncoding=`binary`;let{minimum:a,maximum:o,mime:s}=os(e);a!==void 0&&(i.minLength=a),o!==void 0&&(i.maxLength=o),s&&(s.length===0?i.not={}:s.length===1?i.contentMediaType=s[0]:i.anyOf=s.map(e=>({contentMediaType:e})))},Ds=(e,t,n,r)=>{n.type=`boolean`},Os=(e,t,n,r)=>{Fo(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},ks=(e,t,n,r)=>{Fo(e,t,n,r,`Function types cannot be represented in JSON Schema`)},As=(e,t,n,r)=>{Fo(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},js=(e,t,n,r)=>{Fo(e,t,n,r,`Map cannot be represented in JSON Schema`)},Ms=(e,t,n,r)=>{Fo(e,t,n,r,`Set cannot be represented in JSON Schema`)},Ns=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=os(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=Io(a.element,t,{...r,path:[...r.path,`items`]})};function Ps(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?Ps(t.out):t.type===`catch`?Ps(t.innerType):e._zod.optin}const Fs=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&Fo(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)Ge(i.properties,e,Io(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?Ps(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=Io(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Is=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>Io(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Ls=(e,t,n,r)=>{let i=e._zod.def,a=Io(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=Io(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)},Rs=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`array`;let o=t.target===`draft-2020-12`?`prefixItems`:`items`,s=t.target===`draft-2020-12`||t.target===`openapi-3.0`?`items`:`additionalItems`,c=a.items.map((e,n)=>Io(e,t,{...r,path:[...r.path,o,n]})),l=a.rest?Io(a.rest,t,{...r,path:[...r.path,s,...t.target===`openapi-3.0`?[a.items.length]:[]]}):null,u=a.items.length;for(;u>0;){let e=a.items[u-1];if(!(t.io===`input`?Ps(e)!==void 0:e._zod.optout===`optional`))break;u--}let d=a.items.length,f=!a.rest;t.target===`draft-2020-12`?(i.prefixItems=c,f?i.items=!1:l&&(i.items=l),u>0&&(i.minItems=u),f&&(i.maxItems=d)):t.target===`openapi-3.0`?(i.items={anyOf:c},l&&i.items.anyOf.push(l),u>0&&(i.minItems=u),f&&(i.maxItems=d)):(i.items=c,f?i.additionalItems=!1:l&&(i.additionalItems=l),u>0&&(i.minItems=u),f&&(i.maxItems=d));let{minimum:p,maximum:m}=os(e);typeof p==`number`&&(i.minItems=p),typeof m==`number`&&(i.maxItems=m)};function zs(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=zs(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>zs(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i?(p.type=`string`,a||(p.pattern=(r.includes(`number`)?nr:tr).source),p):p}const Bs=/* @__PURE__ */ new WeakMap;function Vs(e){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=/* @__PURE__ */ new Map;for(let r of Bs.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=zs(t,a,/* @__PURE__ */ new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}const Hs=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=os(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=Io(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)Ge(i.patternProperties,ls(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=Io(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=Bs.get(t);n||(n=[],Bs.set(t,n),t.deferred.push(()=>Vs(t))),n.push(e)}i.additionalProperties=Io(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&Ps(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},Us=(e,t,n,r)=>{let i=e._zod.def,a=Io(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Ws=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Gs=Symbol();function Ks(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(Fo(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),Gs):JSON.parse(o)}const qs=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=Ks(i.defaultValue,e,t,n,r);o!==Gs&&(n.default=o)},Js=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=Ks(i.defaultValue,e,t,n,r);o!==Gs&&(n._prefault=o)},Ys=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{Fo(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},Xs=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;Io(o,t,r);let s=t.seen.get(e);s.ref=o},Zs=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Qs=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},$s=(e,t,n,r)=>{let i=e._zod.def;Io(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ec={string:us,number:ds,boolean:fs,bigint:ps,symbol:ms,null:hs,undefined:gs,void:_s,never:vs,any:ys,unknown:bs,date:xs,enum:Ss,literal:Cs,nan:ws,template_literal:Ts,file:Es,success:Ds,custom:Os,function:ks,transform:As,map:js,set:Ms,array:Ns,object:Fs,union:Is,intersection:Ls,tuple:Rs,record:Hs,nullable:Us,nonoptional:Ws,default:qs,prefault:Js,catch:Ys,pipe:Xs,readonly:Zs,promise:Qs,optional:$s,lazy:(e,t,n,r)=>{let i=e._zod.innerType;Io(i,t,r);let a=t.seen.get(e);a.ref=i}};function tc(e,t){if(`_idmap`in e){let n=e,r=Po({...t,processors:ec}),i={};for(let e of n._idmap.entries()){let[t,n]=e;Io(n,r)}let a={};r.external={registry:n,uri:t?.uri,defs:i};for(let e of n._idmap.entries()){let[t,n]=e;Ro(r,n),Ge(a,t,Go(r,n))}return Object.keys(i).length>0&&(a.__shared={[r.target===`draft-2020-12`?`$defs`:`definitions`]:i}),{schemas:a}}let n=Po({...t,processors:ec});return Io(e,n),Ro(n,e),Go(n,e)}const nc=/* @__PURE__ */ new WeakSet([Object.prototype,Error.prototype]);function rc(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}const ic=(e,t)=>{an.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);nc.has(n)||(nc.add(n),rc(n,`format`,e=>t=>cn(e,t)),rc(n,`flatten`,e=>t=>sn(e,t)),rc(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ze,2)}),rc(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ze,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},ac=/*@__PURE__*/ G(`ZodError`,ic),oc=/*@__PURE__*/ G(`ZodError`,ic,void 0,{Parent:Error}),sc=/* @__PURE__ */ un(oc),cc=/* @__PURE__ */ dn(oc),lc=/* @__PURE__ */ fn(oc),uc=/* @__PURE__ */ mn(oc),dc=/* @__PURE__ */ bn(oc),fc=/* @__PURE__ */ xn(oc),pc=/* @__PURE__ */ Sn(oc),mc=/* @__PURE__ */ Cn(oc),hc=/* @__PURE__ */ wn(oc),gc=/* @__PURE__ */ Tn(oc),_c=/* @__PURE__ */ En(oc),vc=/* @__PURE__ */ Dn(oc);function yc(){Xt.localeError||Zt(ba())}function bc(){Xt.memoizer||Zt({memoizer:_a()})}const xc=/*@__PURE__*/ G(`ZodType`,(e,t)=>(yc(),Dr.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(Qe(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return ct(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Ul(e,t))},superRefine(e,t){return this.check(Wl(e,t))},overwrite(e){return this.check(/* @__PURE__ */ So(e))},optional(){return wl(this)},exactOptional(){return El(this)},nullable(){return Ol(this)},nullish(){return wl(Ol(this))},nonoptional(e){return Pl(this,e)},array(){return sl(this)},or(e){return ul([this,e])},and(e){return ml(this,e)},transform(e){return Rl(this,Sl(e))},default(e){return Al(this,e)},prefault(e){return Ml(this,e)},catch(e){return Il(this,e)},pipe(e){return Rl(this,e)},readonly(){return Bl(this)},describe(e){let t=this.clone();return wa.add(t,{description:e}),t},meta(...e){if(e.length===0)return wa.get(this);let t=this.clone();return wa.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return Pt(this,`~standard`,{...Ar(this),jsonSchema:{input:Jo(this,`input`),output:Jo(this,`output`)}})},set"~standard"(e){Nt(this,`~standard`,e)},parse:function e(t,n){return sc(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await cc(this,t,n,{callee:e})},safeParse(e,t){return lc(this,e,t)},async safeParseAsync(e,t){return uc(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){Nt(this,`spa`,e)},validate(e,t){return _n(this,e,t)},validateAsync(e,t){return yn(this,e,t)},encode:function e(t,n){return dc(this,t,n,{callee:e})},decode:function e(t,n){return fc(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await pc(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await mc(this,t,n,{callee:e})},safeEncode(e,t){return hc(this,e,t)},safeDecode(e,t){return gc(this,e,t)},async safeEncodeAsync(e,t){return _c(this,e,t)},async safeDecodeAsync(e,t){return vc(this,e,t)},toJSONSchema(e){return qo(this,{})(e)},get description(){return wa.get(this)?.description},get _def(){return this._zod.def}}),Sc=/*@__PURE__*/ G(`_ZodString`,(e,t)=>{jr.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>us(e,t,n,r)},/*@__PURE__*/ Ft({format:e=>os(e).format??null,minLength:e=>os(e).minimum??null,maxLength:e=>os(e).maximum??null},{regex(...e){return this.check(/* @__PURE__ */ go(...e))},includes(...e){return this.check(/* @__PURE__ */ yo(...e))},startsWith(...e){return this.check(/* @__PURE__ */ bo(...e))},endsWith(...e){return this.check(/* @__PURE__ */ xo(...e))},min(...e){return this.check(/* @__PURE__ */ mo(...e))},max(...e){return this.check(/* @__PURE__ */ po(...e))},length(...e){return this.check(/* @__PURE__ */ ho(...e))},nonempty(...e){return this.check(/* @__PURE__ */ mo(1,...e))},lowercase(e){return this.check(/* @__PURE__ */ _o(e))},uppercase(e){return this.check(/* @__PURE__ */ vo(e))},trim(){return this.check(/* @__PURE__ */ wo())},normalize(...e){return this.check(/* @__PURE__ */ Co(...e))},toLowerCase(){return this.check(/* @__PURE__ */ To())},toUpperCase(){return this.check(/* @__PURE__ */ Eo())},slugify(){return this.check(/* @__PURE__ */ Do())}})),Cc=/*@__PURE__*/ G(`ZodString`,(e,t)=>{jr.init(e,t),Sc.init(e,t)},{email(e){return this.check(/* @__PURE__ */ Da(kc,e))},url(e){return this.check(/* @__PURE__ */ Na(Mc,e))},jwt(e){return this.check(/* @__PURE__ */ Ja(qc,e))},emoji(e){return this.check(/* @__PURE__ */ Pa(Nc,e))},guid(e){return this.check(/* @__PURE__ */ Oa(Ac,e))},uuid(e){return this.check(/* @__PURE__ */ ka(jc,e))},uuidv4(e){return this.check(/* @__PURE__ */ Aa(jc,e))},uuidv6(e){return this.check(/* @__PURE__ */ ja(jc,e))},uuidv7(e){return this.check(/* @__PURE__ */ Ma(jc,e))},nanoid(e){return this.check(/* @__PURE__ */ Fa(Pc,e))},cuid(e){return this.check(/* @__PURE__ */ Ia(Fc,e))},cuid2(e){return this.check(/* @__PURE__ */ La(Ic,e))},ulid(e){return this.check(/* @__PURE__ */ Ra(Lc,e))},base64(e){return this.check(/* @__PURE__ */ Ga(Wc,e))},base64url(e){return this.check(/* @__PURE__ */ Ka(Gc,e))},xid(e){return this.check(/* @__PURE__ */ za(Rc,e))},ksuid(e){return this.check(/* @__PURE__ */ Ba(zc,e))},ipv4(e){return this.check(/* @__PURE__ */ Va(Bc,e))},ipv6(e){return this.check(/* @__PURE__ */ Ha(Vc,e))},cidrv4(e){return this.check(/* @__PURE__ */ Ua(Hc,e))},cidrv6(e){return this.check(/* @__PURE__ */ Wa(Uc,e))},e164(e){return this.check(/* @__PURE__ */ qa(Kc,e))},datetime(e){return this.check(/* @__PURE__ */ Ya(Tc,e))},date(e){return this.check(/* @__PURE__ */ Xa(Ec,e))},time(e){return this.check(/* @__PURE__ */ Za(Dc,e))},duration(e){return this.check(/* @__PURE__ */ Qa(Oc,e))}});function K(e){return/* @__PURE__ */ Ea(Cc,e)}const wc=/*@__PURE__*/ G(`ZodStringFormat`,(e,t)=>{Mr.init(e,t),Sc.init(e,t)}),Tc=/*@__PURE__*/ G(`ZodISODateTime`,(e,t)=>{Zr.init(e,t),wc.init(e,t)}),Ec=/*@__PURE__*/ G(`ZodISODate`,(e,t)=>{Qr.init(e,t),wc.init(e,t)}),Dc=/*@__PURE__*/ G(`ZodISOTime`,(e,t)=>{$r.init(e,t),wc.init(e,t)}),Oc=/*@__PURE__*/ G(`ZodISODuration`,(e,t)=>{ei.init(e,t),wc.init(e,t)}),kc=/*@__PURE__*/ G(`ZodEmail`,(e,t)=>{Fr.init(e,t),wc.init(e,t)}),Ac=/*@__PURE__*/ G(`ZodGUID`,(e,t)=>{Nr.init(e,t),wc.init(e,t)}),jc=/*@__PURE__*/ G(`ZodUUID`,(e,t)=>{Pr.init(e,t),wc.init(e,t)}),Mc=/*@__PURE__*/ G(`ZodURL`,(e,t)=>{Ur.init(e,t),wc.init(e,t)}),Nc=/*@__PURE__*/ G(`ZodEmoji`,(e,t)=>{Wr.init(e,t),wc.init(e,t)}),Pc=/*@__PURE__*/ G(`ZodNanoID`,(e,t)=>{Gr.init(e,t),wc.init(e,t)}),Fc=/*@__PURE__*/ G(`ZodCUID`,(e,t)=>{Kr.init(e,t),wc.init(e,t)}),Ic=/*@__PURE__*/ G(`ZodCUID2`,(e,t)=>{qr.init(e,t),wc.init(e,t)}),Lc=/*@__PURE__*/ G(`ZodULID`,(e,t)=>{Jr.init(e,t),wc.init(e,t)}),Rc=/*@__PURE__*/ G(`ZodXID`,(e,t)=>{Yr.init(e,t),wc.init(e,t)}),zc=/*@__PURE__*/ G(`ZodKSUID`,(e,t)=>{Xr.init(e,t),wc.init(e,t)}),Bc=/*@__PURE__*/ G(`ZodIPv4`,(e,t)=>{ti.init(e,t),wc.init(e,t)}),Vc=/*@__PURE__*/ G(`ZodIPv6`,(e,t)=>{ii.init(e,t),wc.init(e,t)}),Hc=/*@__PURE__*/ G(`ZodCIDRv4`,(e,t)=>{ai.init(e,t),wc.init(e,t)}),Uc=/*@__PURE__*/ G(`ZodCIDRv6`,(e,t)=>{si.init(e,t),wc.init(e,t)}),Wc=/*@__PURE__*/ G(`ZodBase64`,(e,t)=>{ui.init(e,t),wc.init(e,t)}),Gc=/*@__PURE__*/ G(`ZodBase64URL`,(e,t)=>{pi.init(e,t),wc.init(e,t)}),Kc=/*@__PURE__*/ G(`ZodE164`,(e,t)=>{mi.init(e,t),wc.init(e,t)}),qc=/*@__PURE__*/ G(`ZodJWT`,(e,t)=>{gi.init(e,t),wc.init(e,t)}),Jc=/*@__PURE__*/ G(`ZodNumber`,(e,t)=>{_i.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ds(e,t,n,r),e.isFinite=!0},/*@__PURE__*/ Ft({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=os(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=os(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=os(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>os(e).format??null},{gt(e,t){return this.check(/* @__PURE__ */ lo(e,t))},gte(e,t){return this.check(/* @__PURE__ */ uo(e,t))},min(e,t){return this.check(/* @__PURE__ */ uo(e,t))},lt(e,t){return this.check(/* @__PURE__ */ so(e,t))},lte(e,t){return this.check(/* @__PURE__ */ co(e,t))},max(e,t){return this.check(/* @__PURE__ */ co(e,t))},int(e){return this.check(Zc(e))},safe(e){return this.check(Zc(e))},positive(e){return this.check(/* @__PURE__ */ lo(0,e))},nonnegative(e){return this.check(/* @__PURE__ */ uo(0,e))},negative(e){return this.check(/* @__PURE__ */ so(0,e))},nonpositive(e){return this.check(/* @__PURE__ */ co(0,e))},multipleOf(e,t){return this.check(/* @__PURE__ */ fo(e,t))},step(e,t){return this.check(/* @__PURE__ */ fo(e,t))},finite(){return this}}));function Yc(e){return/* @__PURE__ */ $a(Jc,e)}const Xc=/*@__PURE__*/ G(`ZodNumberFormat`,(e,t)=>{vi.init(e,t),Jc.init(e,t)});function Zc(e){return/* @__PURE__ */ to(Xc,e)}const Qc=/*@__PURE__*/ G(`ZodBoolean`,(e,t)=>{yi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fs(e,t,n,r)});function $c(e){return/* @__PURE__ */ no(Qc,e)}const el=/*@__PURE__*/ G(`ZodNull`,(e,t)=>{bi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hs(e,t,n,r)});function tl(e){return/* @__PURE__ */ io(el,e)}const nl=/*@__PURE__*/ G(`ZodUnknown`,(e,t)=>{xi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function rl(){return/* @__PURE__ */ ao(nl)}const il=/*@__PURE__*/ G(`ZodNever`,(e,t)=>{Si.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>vs(e,t,n,r)});function al(e){return/* @__PURE__ */ oo(il,e)}const ol=/*@__PURE__*/ G(`ZodArray`,(e,t)=>{bc(),wi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ns(e,t,n,r),e.element=t.element},{min(e,t){return this.check(/* @__PURE__ */ mo(e,t))},nonempty(e){return this.check(/* @__PURE__ */ mo(1,e))},max(e,t){return this.check(/* @__PURE__ */ po(e,t))},length(e,t){return this.check(/* @__PURE__ */ ho(e,t))},unwrap(){return this.element}});function sl(e,t){return/* @__PURE__ */ Oo(ol,e,t)}const cl=/*@__PURE__*/ G(`ZodObject`,(e,t)=>{bc(),Ai.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fs(e,t,n,r),Ht(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return vl(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(Qe(this._zod.def,{catchall:e}))},passthrough(){return this.clone(Qe(this._zod.def,{catchall:rl()}))},loose(){return this.clone(Qe(this._zod.def,{catchall:rl()}))},strict(){return this.clone(Qe(this._zod.def,{catchall:al()}))},strip(){return this.clone(Qe(this._zod.def,{catchall:void 0}))},extend(e){return ht(this,e)},safeExtend(e){return _t(this,e)},merge(e){return vt(this,e)},pick(e){return ft(this,e)},omit(e){return mt(this,e)},partial(...e){return yt(Cl,this,e[0])},exactPartial(...e){return yt(Tl,this,e[0],`exactPartial`)},required(...e){return bt(Nl,this,e[0])}});function q(e,t){let n={type:`object`,shape:e??{},...U(t)};return new cl(n)}const ll=/*@__PURE__*/ G(`ZodUnion`,(e,t)=>{Mi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Is(e,t,n,r),e.options=t.options});function ul(e,t){return new ll({type:`union`,options:e,...U(t)})}const dl=/*@__PURE__*/ G(`ZodDiscriminatedUnion`,(e,t)=>{ll.init(e,t),Pi.init(e,t)});function fl(e,t,n){return new dl({type:`union`,options:t,discriminator:e,...U(n)})}const pl=/*@__PURE__*/ G(`ZodIntersection`,(e,t)=>{Fi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ls(e,t,n,r)});function ml(e,t){return new pl({type:`intersection`,left:e,right:t})}const hl=/*@__PURE__*/ G(`ZodRecord`,(e,t)=>{bc(),Ri.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hs(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function gl(e,t,n){return!t||!t._zod?new hl({type:`record`,keyType:K(),valueType:e,...U(t)}):new hl({type:`record`,keyType:e,valueType:t,...U(n)})}const _l=/*@__PURE__*/ G(`ZodEnum`,(e,t)=>{zi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ss(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new _l({...t,checks:[],...U(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new _l({...t,checks:[],...U(r),entries:i})}});function vl(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new _l({type:`enum`,entries:n,...U(t)})}const yl=/*@__PURE__*/ G(`ZodLiteral`,(e,t)=>{Bi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Cs(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function bl(e,t){return new yl({type:`literal`,values:Array.isArray(e)?e:[e],...U(t)})}const xl=/*@__PURE__*/ G(`ZodTransform`,(e,t)=>{bc(),Vi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>As(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Yt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(jt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(jt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Sl(e){return new xl({type:`transform`,transform:e})}const Cl=/*@__PURE__*/ G(`ZodOptional`,(e,t)=>{Ui.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$s(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function wl(e){return new Cl({type:`optional`,innerType:e})}const Tl=/*@__PURE__*/ G(`ZodExactOptional`,(e,t)=>{Wi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$s(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function El(e){return new Tl({type:`optional`,innerType:e})}const Dl=/*@__PURE__*/ G(`ZodNullable`,(e,t)=>{Gi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Us(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ol(e){return new Dl({type:`nullable`,innerType:e})}const kl=/*@__PURE__*/ G(`ZodDefault`,(e,t)=>{Ki.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Al(e,t){return new kl({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():at(t)}})}const jl=/*@__PURE__*/ G(`ZodPrefault`,(e,t)=>{Ji.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Js(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ml(e,t){return new jl({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():at(t)}})}const Nl=/*@__PURE__*/ G(`ZodNonOptional`,(e,t)=>{Yi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ws(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Pl(e,t){return new Nl({type:`nonoptional`,innerType:e,...U(t)})}const Fl=/*@__PURE__*/ G(`ZodCatch`,(e,t)=>{Qi.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ys(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Il(e,t){return new Fl({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Ut(t)})}const Ll=/*@__PURE__*/ G(`ZodPipe`,(e,t)=>{$i.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xs(e,t,n,r),e.in=t.in,e.out=t.out});function Rl(e,t){return new Ll({type:`pipe`,in:e,out:t})}const zl=/*@__PURE__*/ G(`ZodReadonly`,(e,t)=>{ta.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Bl(e){return new zl({type:`readonly`,innerType:e})}const Vl=/*@__PURE__*/ G(`ZodCustom`,(e,t)=>{ra.init(e,t),xc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Os(e,t,n,r)});function Hl(e,t){return/* @__PURE__ */ ko(Vl,e??(()=>!0),t)}function Ul(e,t={}){return/* @__PURE__ */ Ao(Vl,e,t)}function Wl(e,t){return/* @__PURE__ */ jo(e,t)}function Gl(e){return/* @__PURE__ */ eo(Jc,e)}function Kl(e){return/* @__PURE__ */ ro(Qc,e)}const ql=1e4,Jl=`[a-z0-9][a-z0-9_-]*`,Yl=K().max(80).regex(RegExp(`^${Jl}(?:/${Jl})*$`),`invalid channel path`),Xl=e=>!e.includes(`\0`)&&e.isWellFormed(),Zl=e=>e.replaceAll(`\0`,``).toWellFormed(),Ql=K().max(ql).refine(e=>e.trim().length>0,`message text is empty`).refine(Xl,`message text has a NUL character or a lone surrogate`),$l=Yc().int().positive(),eu=/* @__PURE__ */ new Set([...Object.getOwnPropertyNames(Object.prototype),`prototype`]),tu=e=>!eu.has(e),nu=K().max(64).regex(/^[a-z0-9][a-z0-9_.-]*$/,`invalid label key`).refine(tu,`label key is a reserved name`),ru=gl(nu,K().max(256).refine(Xl,`label value has a NUL character or a lone surrogate`)),iu=K().max(64).regex(/^[a-z0-9_+-]+$/,`invalid emoji name`).refine(tu,`emoji name is a reserved name`),au=K().min(1).max(256);ul([vl([`person`,`agent`,`deployment`,`workflow`,`external`]),bl(`profile`)]);const ou=e=>e===`profile`?`agent`:e;K().min(1).max(128).refine(Xl,`handle has a NUL character or a lone surrogate`);function su(e){if(e===null)return null;try{return new URL(e).protocol===`https:`?e:null}catch{return null}}q({actor:au,principal:K().min(1),profile:K().nullable(),session:K().nullable()});const cu=K().regex(/^(?:[A-Za-z0-9_-]{22}|att_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/,`invalid attachment id`);q({id:cu,name:K().min(1).max(255),type:K().min(1).max(255),size:Yc().int().nonnegative()}),K().regex(/^[A-Za-z][A-Za-z0-9-]{0,31}$/,`ids start with a letter and use up to 32 letters, numbers, and hyphens`);const lu=K().min(3).max(300),uu=q({channel:lu.optional(),thread:lu,subthread:lu.nullable(),message:K().min(1).max(300),context:K().max(300).nullable()}),du=q({author:K().min(1).max(256),text:K().max(ql),createdAt:K().max(64).nullable(),files:sl(q({name:K().min(1).max(1e3),url:K().max(4e3).nullable()})).max(20)}),fu=q({url:K().min(1).max(4e3),message:$l.nullable(),snapshot:du.nullable(),unavailable:K().max(300).nullable()}),pu=q({id:K().min(1),handle:K().min(1),name:K().min(1),avatar:K().nullable(),isBot:$c()}),mu=q({type:vl([`image`,`file`,`video`,`audio`]),name:K().max(1e3).optional(),mimeType:K().max(255).optional(),size:Yc().int().nonnegative().optional(),url:K().max(4e3).optional(),fetchMetadata:gl(K(),K().max(4e3)).optional()}),hu=q({url:K().min(1).max(4e3),thread:lu,message:K().min(1).max(300),snapshot:du.nullable()}),gu=q({channel:lu,thread:lu,subthread:lu.nullable()}),_u=fl(`kind`,[q({kind:bl(`message`),...gu.shape,message:K(),isRoot:$c(),text:K(),context:K().nullable(),author:pu,files:sl(mu).max(20).optional(),links:sl(hu).max(10).optional()}),q({kind:bl(`edited`),...gu.shape,message:K(),text:K(),author:pu,links:sl(hu).max(10).optional(),linksOnly:$c().optional()}),q({kind:bl(`deleted`),...gu.shape,message:K()}),q({kind:bl(`reaction`),...gu.shape,message:K(),emoji:K(),added:$c(),author:pu}),q({kind:bl(`lifecycle`),...gu.omit({subthread:!0}).shape,type:K(),title:K(),url:K().nullable(),body:K().nullable().optional(),labels:gl(K(),K()),unset:sl(K()),owns:sl(K()).optional(),reply:K().nullable(),createRoot:$c(),retitled:$c().optional(),author:pu})]),vu=e=>e.slice(e.indexOf(`:`)+1).includes(`:`),yu=e=>{let t=e.indexOf(`:`),n=e.slice(t+1).indexOf(`:`);return n===-1?e:e.slice(0,t+1+n)},bu=(e,t)=>`${e}|${t}`,xu=K().min(1).max(128),Su=xu,Cu=ul([K(),sl(K())]).transform(e=>Array.isArray(e)?e:[e]),wu=K().regex(/^[a-z0-9][a-z0-9_.-]*(=.*)?$/,`label filters look like key, key=value, or key=a|b`).transform(e=>{let t=e.indexOf(`=`);return t===-1?[e,null]:[e.slice(0,t),e.slice(t+1).split(`|`)]}),Tu=q({target:lu,kind:vl([`channel`,`thread`])}),Eu=q({channel:K().optional(),re:Su.optional(),by:K().optional(),mentions:K().optional(),label:Cu.pipe(sl(wu)).optional(),from:K().min(1).max(64).optional(),text:K().min(1).max(200).optional()}),Du=Eu.extend({after:xu.optional(),before:Su.optional(),limit:Gl().int().min(1).max(500).optional()}),Ou=Eu.extend({after:xu.optional(),limit:Gl().int().min(1).max(500).optional()}),ku=Eu.extend({after:xu.optional(),wait:Gl().min(0).max(300).optional(),all:Kl().optional()}),Au=q({channel:Yl.optional(),re:xu.optional(),text:K().max(ql).default(``),labels:ru.optional(),noSync:$c().optional(),sync:sl(ul([K().min(3).max(300),Tu])).max(10).optional(),id:K().min(1).max(200).refine(Xl,`id has a NUL character or a lone surrogate`).optional(),attachments:sl(cu).max(10).optional()}).refine(e=>e.text.trim().length>0||(e.attachments?.length??0)>0,{message:`message text is empty`,path:[`text`]}).refine(e=>e.channel===void 0!=(e.re===void 0),{message:"a post needs `channel`; a reply needs `re`"}).refine(e=>!(e.noSync&&e.sync?.length),{message:"`noSync` and `sync` contradict each other"}),ju=K().regex(/^\d+(\.\d+)?(s|m|h|d)$/,`durations look like 30s, 30m, 12h, or 1d`),Mu=K().datetime({offset:!0}),Nu=q({channel:Yl.optional(),re:xu.optional(),text:K().max(ql).default(``),labels:ru.optional(),noSync:$c().optional(),attachments:sl(cu).max(10).optional(),in:ju.optional(),at:Mu.optional(),every:ju.optional(),until:Mu.optional(),for:ju.optional(),times:Yc().int().positive().optional()}).refine(e=>e.text.trim().length>0||(e.attachments?.length??0)>0,{message:`message text is empty`,path:[`text`]}).refine(e=>e.channel===void 0!=(e.re===void 0),{message:"a schedule needs `channel` for a new thread, or `re` for a reply"}).refine(e=>e.in!==void 0||e.at!==void 0||e.every!==void 0,{message:"say when: `in`, `at`, or `every`"}).refine(e=>e.in===void 0||e.at===void 0,{message:"`in` and `at` contradict each other"}).refine(e=>[e.until,e.for,e.times].filter(e=>e!==void 0).length<=1,{message:"pick one stop: `until`, `for`, or `times`"}).refine(e=>e.every!==void 0||e.until===void 0&&e.for===void 0&&e.times===void 0,{message:"`until`, `for`, and `times` stop a repeat: add `every`"}),Pu=q({re:Su.optional(),channel:K().optional(),by:K().optional(),all:Kl().optional()}),Fu=q({target:K().min(3).max(300)}),Iu=q({channel:K().optional(),limit:Gl().int().min(1).max(500).optional()}),Lu=q({watch:gl(K().max(100),q({tail:K().max(1e3),when:vl([`matches`,`enters`]).default(`matches`)})).refine(e=>Object.keys(e).length<=32,`a board registers at most 32 watchers`),sync:sl(q({key:K().min(1).max(64),platform:K().min(1).max(64),signIn:$c().default(!1)})).max(32).optional()}),Ru=ul([Lu.extend({url:K().url().max(500).refine(e=>/^https:\/\//.test(e),`wake-ups go over https`).transform(e=>e.replace(/\/+$/,``)).nullable().optional(),path:tl({error:`register a url or a path, not both`}).optional(),branch:tl({error:`a branch goes with a path`}).optional()}),Lu.extend({url:tl({error:`register a url or a path, not both`}).optional(),path:K().max(300).regex(/^\/[^?#]*$/,`a path starts with / and has no query or fragment`).transform(e=>e.replace(/(.)\/+$/,`$1`)),branch:K().min(1).max(255).nullable().optional()})]),zu=q({limit:Gl().int().min(1).max(50).optional(),wait:Gl().min(0).max(25).optional()}),Bu=q({lease:K().min(1).max(64),error:K().min(1).max(500).optional(),skip:$c().optional()}),Vu=q({target:K().min(1).max(4e3),limit:Gl().int().min(1).max(200).optional(),after:K().min(1).max(400).optional()}),Hu=q({target:K().min(1).max(4e3)}),Uu=q({url:K().url().max(4e3)}),Wu=q({actor:K().min(1).max(256)}),Gu=K().min(1).max(64),Ku=q({thread:lu,message:K().min(1).max(300).optional()}),qu=fu.extend({message:xu.nullable()}),Ju=pu.extend({avatar:K().nullable().transform(su)}),Yu={author:Ju,from:Gu.nullable()},Xu=q({key:Gu,channel:lu,thread:lu}),Zu={origin:Ku.optional(),message:xu.optional()},Qu=fl(`op`,[q({op:bl(`post`),...Yu,origin:uu.nullable().default(null),source:Xu.optional(),channel:Yl.optional(),re:xu.optional(),text:K().max(ql).default(``),labels:ru.optional(),noSync:$c().optional(),attachments:sl(cu).max(10).optional(),links:sl(qu).max(10).optional(),id:K().min(1).max(200).refine(Xl,`id has a NUL character or a lone surrogate`).optional()}),q({op:bl(`edit`),...Yu,...Zu,text:Ql,source:Xu.optional()}),q({op:bl(`delete`),...Yu,...Zu}),q({op:bl(`react`),...Yu,...Zu,emoji:iu,remove:$c().optional()}),q({op:bl(`labels`),...Yu,...Zu,set:ru.optional(),unset:sl(nu).optional()}),q({op:bl(`links`),...Yu,...Zu,links:sl(qu).max(10)}),q({op:bl(`seen`),author:Ju})]),$u=sl(K().min(1).max(300)).max(10).nullable(),ed=fl(`kind`,[q({kind:bl(`message`),message:xu,target:lu,external:q({thread:lu,message:K().min(1).max(300),asUser:bl(!0).optional()}),files:$u.optional()}),q({kind:bl(`files`),message:xu,target:lu,files:$u}),q({kind:bl(`failed`),message:xu,target:lu,error:K().min(1).max(500)}),q({kind:bl(`thread`),message:xu,target:lu,targetKind:vl([`channel`,`thread`]),cause:vl([`config`,`request`])})]),td=q({code:K().min(1).max(64).optional(),post:K().min(1).max(200).optional(),thread:lu.optional(),message:K().min(1).max(300).optional(),account:au.optional(),person:au.optional()}),nd=q({message:Cu.pipe(sl(xu).min(1).max(100))}),rd=q({by:au,since:Gl().int().nonnegative()}),id=q({events:sl(q({id:K().min(1).max(300),event:_u,raw:rl()})).min(1).max(50)}),ad=q({limit:Gl().int().min(1).max(50).optional()}),od=q({lease:K().min(1).max(64),error:K().min(1).max(500).optional()}),sd=q({sync:Gu}),cd=q({sync:Gu,account:Ju,code:K().min(1).max(64),message:K().max(1024).optional(),method:vl([`code`,`consent`]).optional()}),ld=q({sync:Gu,code:K().min(1).max(64)}),ud=q({account:au}),dd=q({name:K().max(1024).nullable().optional(),type:K().max(1024).nullable().optional(),size:Yc().int().positive().max(Ae,`direct uploads are at most ${Ae/1024/1024} MB`)}),fd=q({text:Ql}),pd=q({}).optional(),md=q({status:K().trim().min(1).max(100).optional()}).optional(),hd=q({emoji:iu,remove:$c().optional()}),gd=q({set:ru.optional(),unset:sl(nu).optional()}).refine(e=>e.set!==void 0||e.unset!==void 0,{message:"nothing to change: pass `set` or `unset`"}),_d={discovery:{method:`GET`,path:`/`},me:{method:`GET`,path:`/me`},channels:{method:`GET`,path:`/channels`},actors:{method:`GET`,path:`/actors`},messages:{method:`GET`,path:`/messages`,query:Du},message:{method:`GET`,path:`/messages/:id`},threads:{method:`GET`,path:`/threads`,query:Ou},post:{method:`POST`,path:`/messages`,body:Au},edit:{method:`POST`,path:`/messages/:id/edit`,body:fd},delete:{method:`POST`,path:`/messages/:id/delete`,body:pd},react:{method:`POST`,path:`/messages/:id/reactions`,body:hd},label:{method:`POST`,path:`/messages/:id/labels`,body:gd},sync:{method:`POST`,path:`/messages/:id/sync`,body:Fu},synced:{method:`GET`,path:`/messages/:id/sync`},linked:{method:`GET`,path:`/links`,query:Uu},typing:{method:`POST`,path:`/messages/:id/typing`,body:md},schedule:{method:`POST`,path:`/schedules`,body:Nu},schedules:{method:`GET`,path:`/schedules`,query:Pu},cancelSchedule:{method:`POST`,path:`/schedules/:id/cancel`},posted:{method:`GET`,path:`/posts/:id`},inbox:{method:`GET`,path:`/inbox/:key`,query:Iu},inboxPush:{method:`POST`,path:`/inbox/:key`,body:id},inboxNext:{method:`GET`,path:`/inbox/:key/next`,query:ad},inboxAck:{method:`POST`,path:`/inbox/:key/:id/ack`,body:od},syncImport:{method:`POST`,path:`/sync/imports`,body:Qu},syncReceipt:{method:`POST`,path:`/sync/receipts`,body:ed},syncThread:{method:`GET`,path:`/sync/threads/:thread`},syncFind:{method:`GET`,path:`/sync/find`,query:td},syncCopies:{method:`GET`,path:`/sync/copies`,query:nd},syncRoots:{method:`GET`,path:`/sync/roots`,query:rd},syncCode:{method:`POST`,path:`/sync/codes`,body:sd},syncAccount:{method:`POST`,path:`/sync/accounts`,body:cd},syncUnlink:{method:`POST`,path:`/sync/accounts/unlink`,body:ud},readSource:{method:`GET`,path:`/sources/:key/read`,query:Vu},joinSource:{method:`POST`,path:`/sources/:key/join`,body:Hu},webhook:{method:`POST`,path:`/webhooks/:key`},events:{method:`GET`,path:`/events`,query:ku},avatar:{method:`GET`,path:`/avatars/:name`},upload:{method:`POST`,path:`/attachments`},attachment:{method:`GET`,path:`/attachments/:id`},uploadStart:{method:`POST`,path:`/attachments/uploads`,body:dd},uploadFinish:{method:`POST`,path:`/attachments/uploads/:id`},openapi:{method:`GET`,path:`/openapi.json`},identity:{method:`GET`,path:`/identity`},signIn:{method:`GET`,path:`/identity/sign-in`,query:ld},signedIn:{method:`GET`,path:`/identity/signed-in`,query:ld},identityUnlink:{method:`POST`,path:`/identity/unlink`,body:Wu},watchers:{method:`GET`,path:`/watchers`},register:{method:`POST`,path:`/watchers`,body:Ru},matches:{method:`GET`,path:`/watchers/matches`,query:zu},ack:{method:`POST`,path:`/watchers/matches/:id/ack`,body:Bu},wake:{method:`POST`,path:`/wake`}};async function*vd(e,t){let n=e.getReader(),r=new TextDecoder,i=``,a=()=>void n.cancel().catch(()=>{});t?.addEventListener(`abort`,a,{once:!0});try{for(;;){let{value:e,done:t}=await n.read();if(t)return;i+=r.decode(e,{stream:!0});let a;for(;(a=i.search(/\r?\n\r?\n/))!==-1;){let e=i.slice(0,a);i=i.slice(a).replace(/^\r?\n\r?\n/,``);let t={},n=[];for(let r of e.split(/\r?\n/)){if(r===``||r.startsWith(`:`))continue;let e=r.indexOf(`:`),i=e===-1?r:r.slice(0,e),a=e===-1?``:r.slice(e+1).replace(/^ /,``);i===`data`?n.push(a):i===`id`?t.id=a:i===`event`&&(t.event=a)}n.length>0&&(t.data=n.join(`
345
+ `)),(t.id!==void 0||t.data!==void 0)&&(yield t)}}}finally{t?.removeEventListener(`abort`,a),n.releaseLock()}}var yd=class extends Error{code;status;hint;origin;constructor(e,t,n,r={}){super(t),this.name=`BoardError`,this.code=e,this.status=n,this.hint=r.hint,this.origin=r.origin??`handle`}};const bd=/* @__PURE__ */ new WeakSet,xd=async e=>typeof e==`function`?await e():e,Sd=e=>{let{at:t,until:n,...r}=Cd(e);return{...r,...t===void 0?{}:{at:t instanceof Date?t.toISOString():t},...n===void 0?{}:{until:n instanceof Date?n.toISOString():n}}},Cd=e=>{if(typeof e==`string`)return{text:e};let{attachments:t,...n}=e;return t?.length?{...n,attachments:t.map(e=>typeof e==`string`?e:e.id)}:n},wd={ms:1,s:1e3,m:6e4,h:36e5,d:864e5};function Td(e){if(typeof e==`number`)return e;let t=e.trim().match(/^(\d+(?:\.\d+)?)(ms|s|m|h|d)?$/);if(!t)throw new yd(`invalid_duration`,`${e} isn't a duration like 30s, 10m, or 1h.`,0);return Number(t[1])*wd[t[2]??`ms`]}const Ed=e=>encodeURIComponent(e);function Dd(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!=null){if(n===`label`){let e=Array.isArray(r)?r:typeof r==`object`?Object.entries(r).map(([e,t])=>`${e}=${String(t)}`):[r];for(let n of e)t.append(`label`,String(n))}else t.set(n,String(r))}let n=t.toString();return n?`?${n}`:``}const Od=(e,t)=>t?.length?{...e,unknownMentions:t}:e;function kd(e){let t=e.url.replace(/\/+$/,``),n=e.fetch??((e,t)=>globalThis.fetch(e,t)),r=e.storeFetch??((e,t)=>globalThis.fetch(e,t));async function i(t,n){let r={...e.headers?await xd(e.headers):{}};if(!t)return r;e.token!==void 0&&(r.authorization=`Bearer ${await xd(e.token)}`);let i=n===void 0?e.profile===void 0?null:await xd(e.profile):n;if(i!==null){let{name:e,avatar:t}=typeof i==`string`?{name:i,avatar:void 0}:i;r[`x-board-profile`]=e,t&&(r[`x-board-avatar`]=t)}else{let t=e.person===void 0?null:await xd(e.person);t?.name&&(r[`x-board-name`]=encodeURIComponent(t.name)),t?.avatar&&(r[`x-board-avatar`]=t.avatar)}let a=n===void 0?e.session===void 0?null:await xd(e.session):null;a&&(r[`x-board-session`]=a);let o=e.handle===void 0?null:await xd(e.handle);return o&&(r[`x-board-handle`]=o),r}async function a(e,r,a={}){let o=await n(`${t}${r}`,{method:e,headers:{...await i(a.auth??!0),...a.body===void 0?{}:{"content-type":`application/json`},...a.headers},...a.body===void 0?{}:{body:JSON.stringify(a.body)},...a.signal?{signal:a.signal}:{}});if(!o.ok)throw await Ad(o);return o}async function o(e,t,n){return await(await a(e,t,n)).json()}let s=(e={})=>e;async function c(e={},t){return o(`GET`,`/events${Dd(e)}`,t?{signal:t}:{})}return{url:t,request:async(e,r={})=>n(`${t}${e}`,{method:r.method??`GET`,headers:{...r.headers,...await i(!0,r.as)},...r.body?{body:r.body}:{},...r.signal?{signal:r.signal}:{}}),discovery:()=>o(`GET`,`/`,{auth:!1}),me:()=>o(`GET`,`/me`),channels:async()=>(await o(`GET`,`/channels`)).channels,actors:async()=>(await o(`GET`,`/actors`)).actors,identity:()=>o(`GET`,`/identity`),unlinkAccount:e=>o(`POST`,`/identity/unlink`,{body:{actor:e}}),messages:(e={})=>o(`GET`,`/messages${Dd(e)}`),thread:e=>o(`GET`,`/messages/${Ed(e)}`),posted:async e=>(await o(`GET`,`/posts/${Ed(e)}`)).message,threads:(e={})=>o(`GET`,`/threads${Dd(e)}`),async post(e,t){let{message:n,unknownMentions:r}=await o(`POST`,`/messages`,{body:{channel:e,...Cd(t)}});return Od(n,r)},async reply(e,t){let{message:n,unknownMentions:r}=await o(`POST`,`/messages`,{body:{re:e,...Cd(t)}});return Od(n,r)},async schedule(e,t){let{schedule:n,unknownMentions:r}=await o(`POST`,`/schedules`,{body:{...typeof e==`string`?{channel:e}:{re:e.re},...Sd(t)}});return Od(n,r)},schedules:async(e={})=>(await o(`GET`,`/schedules${Dd(e)}`)).schedules,cancelSchedule:e=>o(`POST`,`/schedules/${Ed(e)}/cancel`,{body:{}}),async upload(e){let a=e.type||(e.data instanceof Blob?e.data.type:``)||Ne(e.name),s=e.data instanceof Blob?e.data.size:e.data.byteLength;if(s>4194304){if(s>104857600)throw new yd(`too_large`,`Attachments are at most ${Ae/1024/1024} MB.`,413);let t=await o(`POST`,`/attachments/uploads`,{body:{name:e.name,type:a,size:s}}).catch(e=>{throw e instanceof yd&&e.status===404&&e.code===`not_found`?new yd(`too_large`,`This board takes files of at most ${Oe/1024/1024} MB.`,413):e}),n=await r(t.url,{method:`PUT`,headers:t.headers,body:e.data});if(!n.ok)throw new yd(`upload_failed`,`The blob store refused the file: ${n.status} ${(await n.text().catch(()=>``)).slice(0,300)||n.statusText}`,n.status);return(await o(`POST`,`/attachments/uploads/${encodeURIComponent(t.id)}`,{body:{}})).attachment}let c=await n(`${t}/attachments`,{method:`POST`,headers:{...await i(!0),"content-type":a,"x-board-filename":encodeURIComponent(e.name)},body:e.data});if(!c.ok)throw await Ad(c);return(await c.json()).attachment},download:(e,t={})=>a(`GET`,`/attachments/${encodeURIComponent(e)}`,t.signal?{signal:t.signal}:{}),edit:(e,t)=>o(`POST`,`/messages/${Ed(e)}/edit`,{body:{text:t}}),delete:e=>o(`POST`,`/messages/${Ed(e)}/delete`,{body:{}}),react:(e,t,n={})=>o(`POST`,`/messages/${Ed(e)}/reactions`,{body:{emoji:Ee(t),...n}}),label:(e,t)=>o(`POST`,`/messages/${Ed(e)}/labels`,{body:t}),typing:async(e,t)=>(await o(`POST`,`/messages/${Ed(e)}/typing`,{body:t?{status:t}:{}})).targets,sync:((e,t)=>t===void 0?o(`GET`,`/messages/${Ed(e)}/sync`):o(`POST`,`/messages/${Ed(e)}/sync`,{body:{target:t}})),linked:e=>o(`GET`,`/links${Dd({url:e})}`),inbox:async(e,t={})=>(await o(`GET`,`/inbox/${e}${Dd(t)}`)).events,register:e=>o(`POST`,`/watchers`,{body:e}),watchers:async()=>(await o(`GET`,`/watchers`)).watchers,matches:async(e={})=>{let{signal:t,...n}=e;return(await o(`GET`,`/watchers/matches${Dd(n)}`,t?{signal:t}:{})).matches},ack:(e,t)=>o(`POST`,`/watchers/matches/${encodeURIComponent(e)}/ack`,{body:t}),readSource:(e,t,n={})=>o(`GET`,`/sources/${e}/read${Dd({target:t,...n})}`),joinSource:(e,t)=>o(`POST`,`/sources/${e}/join`,{body:{target:t}}),poll:c,syncImport:e=>o(`POST`,`/sync/imports`,{body:e}),syncReceipt:e=>o(`POST`,`/sync/receipts`,{body:e}),syncThread:e=>o(`GET`,`/sync/threads/${Ed(e)}`),syncFind:(e,t={})=>o(`GET`,`/sync/find${Dd(e)}`,t.signal?{signal:t.signal}:{}),syncCopies:async e=>(await o(`GET`,`/sync/copies?${e.map(e=>`message=${encodeURIComponent(e)}`).join(`&`)}`)).copies,syncRoots:async(e,t)=>(await o(`GET`,`/sync/roots${Dd({by:e,since:t instanceof Date?t.getTime():t})}`)).roots,inboxPush:(e,t)=>o(`POST`,`/inbox/${Ed(e)}`,{body:{events:t}}),inboxNext:async(e,t={})=>(await o(`GET`,`/inbox/${Ed(e)}/next${Dd(t)}`)).items,inboxAck:(e,t,n)=>o(`POST`,`/inbox/${Ed(e)}/${Ed(t)}/ack`,{body:n}),syncCode:e=>o(`POST`,`/sync/codes`,{body:{sync:e}}),syncAccount:e=>o(`POST`,`/sync/accounts`,{body:e}),syncUnlink:e=>o(`POST`,`/sync/accounts/unlink`,{body:{account:e}}),async*events(e={},t={}){let n=e.after,r=0;for(;!t.signal?.aborted;){let i;try{i=await a(`GET`,`/events${Dd({...s(e),after:n})}`,{headers:{accept:`text/event-stream`},...t.signal?{signal:t.signal}:{}})}catch(e){if(t.signal?.aborted)return;if(e instanceof yd&&e.status>=400&&e.status<500)throw e;await new Promise(e=>setTimeout(e,Math.min(3e4,500*2**r++)));continue}r=0;try{for await(let e of vd(i.body,t.signal))e.id!==void 0&&(n=e.id),e.event===`board`&&e.data&&(yield JSON.parse(e.data))}catch{if(t.signal?.aborted)return;await new Promise(e=>setTimeout(e,Math.min(3e4,500*2**r++)))}}},async wait(e={},t={}){let n=Date.now()+Td(t.timeout??`30m`),r=e.after??(await c({...e,after:void 0,wait:0},t.signal)).cursor;for(;Date.now()<n&&!t.signal?.aborted;){let i=Math.max(0,Math.min(25,Math.ceil((n-Date.now())/1e3))),a=await c({...e,after:r,wait:i},t.signal);if(a.events.length>0)return a.events[0];r=a.cursor}return null}}}async function Ad(e){try{let t=await e.json();if(t.error?.message)return new yd(t.error.code??`error`,t.error.message,e.status,{...typeof t.error.hint==`string`?{hint:t.error.hint}:{},origin:bd.has(e)?`handle`:`board`})}catch{}return new yd(`http_error`,`The board answered ${`${e.status} ${e.statusText}`.trim()}.`,e.status)}const jd=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);async function Md(e){return jd(new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))))}async function Nd(...e){let t=new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(JSON.stringify(e)))).slice(0,16);t[6]=t[6]&15|128,t[8]=t[8]&63|128;let n=jd(t);return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20,32)}`}const Pd=/^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,Fd=async(e,t)=>`key:${e}:${(await Md(`board-key\u001f${t}`)).slice(0,32)}`;var Id=class extends Error{status;code;hint;origin;constructor(e,t,n,r={}){super(n),this.status=e,this.code=t,this.hint=r.hint,this.origin=r.origin??`board`}},Ld=class extends Id{response;constructor(e){super(e.status,`rejected`,`rejected with ${e.status}`),this.response=e}};const Rd=(e,t=`invalid_request`)=>new Id(400,t,e),zd=e=>new Id(401,`unauthorized`,e),Bd=e=>new Id(403,`forbidden`,e),Vd=(e,t=`not_found`)=>new Id(404,t,e),Hd=()=>new Id(409,`duplicate_id`,`that id was already used for a different write`),Ud=(e,t=200,n)=>new Response(JSON.stringify(e),{status:t,headers:{"content-type":`application/json`,...n}});function Wd(e){if(e.code!==`invalid_union`||e.errors.length===0)return e;let t=e.errors.reduce((e,t)=>t.length<e.length?t:e)[0];return t?Wd({...t,path:[...e.path,...t.path]}):e}function Gd(e){if(e instanceof Ld)return e.response;if(e instanceof Id){let t=Ud({error:{code:e.code,message:e.message,...e.hint===void 0?{}:{hint:e.hint}}},e.status);return e.origin===`handle`&&bd.add(t),t}if(e instanceof ac){let t=e.issues[0]&&Wd(e.issues[0]),n=t?.path.length?`${t.path.join(`.`)}: `:``;return Ud({error:{code:`invalid_request`,message:`${n}${t?.message??`invalid request`}`}},400)}let t=e?.code;return t===`INVALID_PAYLOAD`?Ud({error:{code:`invalid_request`,message:e.message}},400):t===`PARTIAL_DUPLICATE_BATCH`||t===`DUPLICATE_EVENT_ID`?Gd(Hd()):t===`STORE_UNAVAILABLE`||t===`STORE_NOT_CONFIGURED`?Ud({error:{code:`unavailable`,message:e.message}},503):(console.error(`[board]`,e),Ud({error:{code:`internal`,message:`internal error`}},500))}const Kd=`0.29.0`,qd=[`avatar`,`openapi`,`webhook`,`signIn`,`signedIn`,`identityUnlink`,`sync`],Jd=/* @__PURE__ */ `discovery.me.channels.actors.identity.messages.threads.message.post.posted.edit.delete.react.label.schedule.schedules.cancelSchedule.upload.attachment.uploadStart.uploadFinish.watchers.register.matches.ack.events.syncImport.syncReceipt.syncThread.syncFind.syncCopies.syncRoots.inboxPush.inboxNext.inboxAck.inbox.syncCode.syncAccount.syncUnlink.typing.readSource.joinSource.synced.linked`.split(`.`),Yd=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);function Xd(e,t,n,r){let i=t.split(`/`).filter(Boolean),a=i.map(e=>e.startsWith(`:`)?`/([^/]+)`:`/${Yd(e)}`).join(``);return{method:e,pattern:RegExp(`${a}$`),names:i.filter(e=>e.startsWith(`:`)).map(e=>e.slice(1)),target:n,segments:i.length,literals:i.filter(e=>!e.startsWith(`:`)).length,own:r}}function Zd(e,t){let n=[...qd.map(e=>Xd(_d[e].method,_d[e].path,{kind:`board`,name:e},!1)),...Jd.filter(e=>e!==`discovery`).map(e=>Xd(_d[e].method,_d[e].path,{kind:`protocol`,name:e},!1)),...e.map(e=>Xd(e.method,e.path,{kind:`backend`,route:e},!0))].sort((e,t)=>t.segments-e.segments||t.literals-e.literals||Number(t.own)-Number(e.own)),r=(e,t,n)=>{let r={};try{e.names.forEach((e,t)=>r[e]=decodeURIComponent(n[t]))}catch{return null}let i=e.names[0];return{target:e.target,base:t,param:i===void 0?null:r[i],params:r}},i=e=>({target:{kind:`protocol`,name:`discovery`},base:e,param:null,params:{},root:!0});return function(e,a){let o=a.length>1?a.replace(/\/+$/,``):a;if(t!==void 0){let a=t.replace(/\/+$/,``);if(o!==a&&!o.startsWith(`${a}/`))return null;let s=o.slice(a.length)||`/`;if(s===`/`)return e===`GET`?i(a):null;for(let t of n){let n=t.method===e?s.match(RegExp(`^${t.pattern.source}`)):null;if(n)return r(t,a,n.slice(1))}return null}for(let t of n){if(t.method!==e)continue;let n=o.match(t.pattern);if(n)return r(t,o.slice(0,n.index),n.slice(1))}return e===`GET`?i(o===`/`?``:o):null}}function Qd(e){let t={};for(let n of new Set(e.searchParams.keys())){let r=e.searchParams.getAll(n);t[n]=r.length>1?r:r[0]}return t}async function $d(e){let t=await e.text();if(t.trim()!==``)try{return JSON.parse(t)}catch{throw Rd(`request body is not valid JSON`)}}const ef=()=>new Id(413,`too_large`,`attachments are at most ${Oe/1024/1024} MB`);async function tf(e,t){if(Number(e.headers.get(`content-length`)??0)>t)throw ef();let n=[],r=0;for await(let i of e.body??[]){if(r+=i.byteLength,r>t)throw ef();n.push(i)}let i=new Uint8Array(r),a=0;for(let e of n)i.set(e,a),a+=e.byteLength;return i}function nf(){let e={};for(let[t,n]of Object.entries(_d)){let r=n.path.replace(/:(\w+)/g,`{$1}`),i={operationId:t};`query`in n&&(i[`x-query-schema`]=tc(n.query,{io:`input`})),`body`in n&&(i.requestBody={content:{"application/json":{schema:tc(n.body,{io:`input`})}}}),(e[r]??={})[n.method.toLowerCase()]=i}return{openapi:`3.1.0`,info:{title:`board`,version:Kd},paths:e}}const rf={re:{type:`string`,value:`id`,description:`in a thread: its root's ID`},by:{type:`string`,value:`handle`,description:`by an author: a handle, me, or an actor ID`},mentions:{type:`string`,value:`@handle`,optionalValue:!0,description:`mentioning a handle, or you without one`},label:{type:`string`,multiple:!0,value:`k[=v|w]`,description:`with a label on the message or its thread's root`},source:{type:`string`,value:`source`,description:`from a source: a sync key such as slack, or board`},text:{type:`string`,value:`words`,description:`containing these words`},after:{type:`string`,value:`id`,description:`after a message or a cursor`},url:{type:`string`,value:`url`,description:`the board at this URL, not the one the environment points at`},scope:{type:`string`,value:`team`,description:`a team's board in Vercel's API, by its slug or ID`},team:{type:`string`,value:`team`,description:`the same as --scope`,hidden:!0},as:{type:`string`,value:`profile`,description:`write as a profile, such as an agent's name`},avatar:{type:`string`,value:`url`,description:`the profile's avatar, with --as`},human:{type:`boolean`,description:`write as yourself, with no profile or session`},handle:{type:`string`,value:`h`,description:`your handle (default: your Vercel username)`},json:{type:`boolean`,description:`JSON, for programs`},help:{type:`boolean`,short:`h`,description:`this help, or a command's`},version:{type:`boolean`,short:`v`,description:`the CLI's version`},limit:{type:`string`,short:`n`,value:`N`,description:`how many`},"idempotency-key":{type:`string`,value:`key`,description:`sending the same one again posts once`},sync:{type:`string`,multiple:!0,value:`target`,description:`sync the new thread to a target too, e.g. slack:#incidents`},"no-sync":{type:`boolean`,description:`keep it on the board: sync it nowhere`},attach:{type:`string`,multiple:!0,value:`file`,description:`attach a file`},unset:{type:`string`,multiple:!0,value:`k`,description:`remove a label`},channel:{type:`string`,value:`c`,description:`in a channel`},remove:{type:`boolean`,description:`take the reaction back`},all:{type:`boolean`,short:`a`,description:`everything, not only what most want`},timeout:{type:`string`,value:`duration`,description:`how long to wait (default: 30m)`},code:{type:`boolean`,description:`post a code from your account instead of signing in`},"no-wait":{type:`boolean`,description:`start linking, and don't wait for it to finish`},"no-open":{type:`boolean`,description:`don't open the browser`},in:{type:`string`,value:`duration`,description:`once, this long from now, e.g. 1d`},at:{type:`string`,value:`time`,description:`at a time: once, or with --every, the first`},every:{type:`string`,value:`duration`,description:`repeating at this interval, e.g. 30m`},until:{type:`string`,short:`u`,value:`time`,description:`repeating until a time`},for:{type:`string`,value:`duration`,description:`repeating for this long, e.g. 24h`},times:{type:`string`,value:`N`,description:`repeating this many times`},port:{type:`string`,value:`N`,description:`the port to listen on`},dir:{type:`string`,value:`dir`,description:`where the board keeps its log (default: .board/)`},"no-inspect":{type:`boolean`,description:`don't start the inspector`},agent:{type:`string`,value:`name`,description:`the agent whose turn ended`,hidden:!0}},af=(e,t,n)=>({name:e,...rf[e],...t?{description:t}:{},...n?{value:n}:{}});[`re`,`by`,`source`,`label`,`text`,`mentions`,`after`].map(e=>af(e)),[`url`,`scope`,`team`,`as`,`avatar`,`human`,`handle`,`json`,`help`,`version`].map(e=>af(e)),af(`code`),af(`no-wait`),af(`no-open`),af(`limit`,`threads to list (default: 50)`),af(`label`,`label it`,`k=v`),af(`attach`),af(`sync`),af(`no-sync`),af(`idempotency-key`),af(`attach`),af(`idempotency-key`),af(`no-sync`),af(`in`),af(`at`),af(`every`),af(`until`),af(`for`),af(`times`),af(`label`,`label it`,`k=v`),af(`attach`),af(`no-sync`),af(`by`,`scheduled by a handle`),af(`channel`,`posting in a channel`),af(`all`,`done and canceled ones too`),af(`remove`),af(`unset`),af(`limit`,`events to list`),af(`limit`,`messages to read`),af(`after`,`where the last read left off: the cursor it printed`),af(`channel`,`the channel to check in (default: conformance)`),af(`agent`),af(`all`,`delivery receipts too`),af(`timeout`);const of={re:rf.re,by:rf.by,mentions:rf.mentions,label:rf.label,source:rf.source,text:rf.text};function sf(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];r===`--mentions`?e[n+1]?.startsWith(`@`)?t.push(`--mentions=${e[++n]}`):t.push(`--mentions=me`):t.push(r)}return t}function cf(e){let t=[],n=null,r=null;for(let i=0;i<e.length;i++){let a=e[i];r?a===r?r=null:a===`\\`&&r===`"`&&i+1<e.length?n+=e[++i]:n+=a:/\s/.test(a)?(n!==null&&t.push(n),n=null):a===`"`||a===`'`?(r=a,n??=``):n=a===`\\`&&i+1<e.length?(n??``)+e[++i]:(n??``)+a}if(r)throw Error(`unterminated ${r}`);return n!==null&&t.push(n),t}const lf={...of,all:{type:`boolean`}};function uf(e){let t={},n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i===`--`){n.push(...e.slice(r+1));break}if(!i.startsWith(`-`)||i===`-`){n.push(i);continue}let a=i.indexOf(`=`),o=i.startsWith(`--`)?i.slice(2,a===-1?void 0:a):null,s=o!==null&&Object.hasOwn(lf,o)?lf[o]:null;if(!s)throw Error(`${o===null?i.slice(0,2):`--${o}`} isn't a filter`);if(s.type===`boolean`){if(a!==-1)throw Error(`--${o} takes no value`);t[o]=!0;continue}let c;if(a!==-1)c=i.slice(a+1);else{let t=e[r+1];if(t===void 0||t.length>1&&t.startsWith(`-`))throw Error(`--${o} needs a value`);c=t,r++}t[o]=`multiple`in s?[...t[o]??[],c]:c}return{values:t,positionals:n}}function df(e){let{values:t,positionals:n}=uf(sf(cf(e)));if(n.length>1)throw Error(`expected one channel, got: ${n.join(` `)}`);let r=n[0],i=Eu.safeParse({...r?{channel:r}:{},...t.re?{re:t.re.replace(/^#/,``)}:{},...t.by?{by:t.by.replace(/^@/,``)}:{},...t.mentions?{mentions:t.mentions.replace(/^@/,``)}:{},...t.label?.length?{label:t.label}:{},...t.source?{from:t.source}:{},...t.text?{text:t.text}:{}});if(!i.success){let e=i.error.issues[0];throw Error(`${e?.path.length?`--${String(e.path[0])}: `:``}${e?.message??`invalid filters`}`)}return{filters:i.data,all:t.all===!0}}const ff=e=>e.channel!==void 0||e.re!==void 0||e.by!==void 0||e.mentions!==void 0||e.from!==void 0||e.text!==void 0||(e.label?.length??0)>0;function pf(e,t){let n,r;try{({filters:n,all:r}=df(t.tail))}catch(t){throw Error(`watch ${e}: ${t.message}`)}if(n.mentions===`me`)throw Error(`watch ${e}: a watcher has no "me": use --mentions @handle`);let i=ff(n);if(t.when===`enters`&&!i)throw Error(`watch ${e}: \`when: enters\` needs a filter to enter`);return{filters:n,criteria:i,enters:t.when===`enters`,all:r}}function mf(e){try{Reflect.get(globalThis,Symbol.for(`@vercel/request-context`))?.get?.()?.waitUntil?.(e)}catch{}}const hf=1e4,gf=e=>((e instanceof Error?e.message:String(e))||`unknown error`).slice(0,500),_f=e=>e?.startsWith(`https://`)?e:null;function vf(e){let t=typeof process<`u`&&process.env.VERCEL===`1`?process.env:null,n=t?.VERCEL_TARGET_ENV||t?.VERCEL_ENV,r=n===`preview`&&t?.VERCEL_GIT_COMMIT_REF||null;return!e||n!==`production`&&!r?null:{path:new URL(e).pathname,...r?{branch:r}:{}}}function yf(e){let{registry:t,rethrow:n}=e,r=e.binding,i=null,a=null;async function o(n){let r=await e.hash();return i&&i.url===n&&i.result.hash===r&&Date.now()-i.at<hf?i.result:(a??=e.wakeAt(n).then(e=>t.register(e)).then(e=>(i={url:n,at:Date.now(),result:e},e)).finally(()=>{a=null}),a)}async function s(e){let n={};if(!r().subscriptions[e.watcher])n={skip:!0};else try{await r().run(e.watcher,e.event,{trigger:`watch:${e.watcher}:${e.id}`,attempt:e.attempt+1})}catch(t){console.error(`[board] watcher ${e.watcher} failed:`,t),n={error:gf(t)}}await t.ack(e.id,{lease:e.lease,...n}).catch(e=>console.error(`[board] couldn't ack a match:`,gf(e)))}async function c(){let e=0,n=Date.now()+24e4;for(;Date.now()<n;){let n=await t.matches({limit:10});if(n.length===0)break;await Promise.all(n.map(s)),e+=n.length}return e+await r().pull()}let l=null;function u(){if(l)return;let n=l=new AbortController;(async()=>{for(let i=1e3;!n.signal.aborted;)try{await o(null);let e=await t.matches({limit:10,wait:25,signal:n.signal});await Promise.all(e.map(s)),await r().pull(),i=1e3}catch(t){if(n.signal.aborted)break;console.error(`[board] couldn't pull matches from ${e.remote}:`,gf(t)),await new Promise(e=>setTimeout(e,i)),i=Math.min(i*2,6e4)}})()}let d=null,f=0;function p(){if(d)return d;if(!e.hasWork()||Date.now()-f<hf)return Promise.resolve();let t=_f(r().url());return!t&&typeof process<`u`&&process.env.VERCEL===`1`?Promise.resolve():(d=o(t).then(()=>{},t=>{d=null,f=Date.now(),console.error(`[board] couldn't register with ${e.remote}:`,gf(t))}),t||u(),d)}return{start:p,routes:[{method:`POST`,path:`/wake`,async handle(t){d??=Promise.resolve();let i=t.headers.get(`x-board-watchers`)!==await e.hash(),a=(async()=>(i&&await o(_f(r().url())),c()))();mf(a.catch(e=>console.error(`[board] couldn't run what woke it:`,gf(e))));let s,l=new Promise(e=>s=setTimeout(()=>e(null),2e3));try{let e=await Promise.race([a.catch(n),l]);return e===null?new Response(null,{status:202}):Ud({ran:e})}finally{clearTimeout(s)}}},{method:`POST`,path:`/watchers`,async handle(t,{caller:i}){if(i)return e.registerFor(i,t);d??=Promise.resolve();let a=_f(r().url()),s=await o(a).catch(n);return a||u(),Ud(s)}}],registerNow:()=>o(_f(r().url())),close:()=>{l?.abort(),l=null}}}const bf=(e,t)=>e<t?-1:+(e>t);function xf(e,t=[]){let n=Object.keys(e).sort(bf).map(t=>[t,e[t].tail,e[t].when]);return t.length>0&&n.push([`sync`,[...t].sort((e,t)=>bf(e.key,t.key)).map(e=>[e.key,e.platform,e.signIn])]),JSON.stringify(n)}const Sf=/^[A-Za-z][A-Za-z0-9-]{0,31}$/,Cf=/* @__PURE__ */ new Set([`identity`,`edit`,`delete`,`schedule`,`cancelSchedule`,`upload`,`uploadStart`,`uploadFinish`,`watchers`,`register`,`matches`,`ack`,`syncImport`,`syncReceipt`,`syncThread`,`syncFind`,`syncCopies`,`syncRoots`,`inboxPush`,`inboxNext`,`inboxAck`,`inbox`,`syncCode`,`syncAccount`,`syncUnlink`]);function wf(e){let t=e.replace(/[^A-Za-z0-9-]+/g,`-`).replace(/^-+|-+$/g,``);return/^[A-Za-z]/.test(t)||(t=`u-${t}`),t.slice(0,32).replace(/-+$/,``)}function Tf(e,t){let n=new Set([...t,`middleware`,`client`].map(e=>e.toLowerCase())),r=wf(e),i=r;for(let e=2;n.has(i.toLowerCase());e++)i=`${r.slice(0,31-String(e).length)}-${e}`;return i}function Ef(e){let{access:t}=e.principal;if(t.everywhere(`manage`))return null;let n=Object.entries(t.summary()).map(([e,t])=>`${e}=${t.join(`,`)}`);return n.length>0?n.join(`;`):`*=`}const Df=e=>((e instanceof Error?e.message:String(e))||`unknown error`).slice(0,500),Of=e=>{throw e instanceof yd?new Id(e.status>=400?e.status:502,e.code,e.message,{...e.hint===void 0?{}:{hint:e.hint},origin:e.origin}):e instanceof Id||e instanceof Error&&e.name===`AbortError`?e:new Id(502,`unreachable`,`the board didn't answer: ${Df(e)}`)};function kf(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!=null&&r!==!1){if(n===`label`&&Array.isArray(r))for(let[e,n]of r)t.append(`label`,n===null?e:`${e}=${n.join(`|`)}`);else if(Array.isArray(r))for(let e of r)t.append(n,String(e));else t.set(n,String(r))}let n=t.toString();return n?`?${n}`:``}function Af(e,t){let n=(t.headers.get(`content-disposition`)??``).match(/filename\*=UTF-8''([^;]+)/)?.[1],r=`file`;try{n&&(r=decodeURIComponent(n))}catch{}return{attachment:{id:e,name:r,type:t.headers.get(`content-type`)??`application/octet-stream`,size:Number(t.headers.get(`content-length`)??0)},data:t.body??/* @__PURE__ */ new Uint8Array}}function jf(e,t,n){if(e!==void 0&&!/^https?:\/\/[^/]/.test(e))throw Error(`http: ${e} isn't a URL: pass the board's, like https://board.example.com/api/board`);if(e===void 0&&!n)throw Error(`http: pass the board's URL: outside Node there's no environment to find it in`);let r=(e??n.url()).replace(/\/+$/,``),i=t.fetch??n?.fetch(r)??((e,t)=>globalThis.fetch(e,t)),a=null,o={},s=[],c=null,l=()=>c??=Md(xf(o,s)).then(e=>e.slice(0,32)),u=()=>{if(!a)throw Error(`http: this backend isn't serving a board yet: pass it to board({ backend })`);return a},d=(e,t)=>kd({url:r,fetch:i,profile:e===void 0?()=>n?.profile().profile??null:e,session:t||e===null?null:()=>n?.profile().session??null}),f=d(null,!0),p=/* @__PURE__ */ new Map;function m(e){if(!Sf.test(e))throw new Id(400,`invalid_request`,`as: ${e}: profiles start with a letter and use up to 32 letters, numbers, and hyphens`);let t=p.get(e);return t||p.set(e,t=d(e,!0)),t}let h=/* @__PURE__ */ new Map;function g(e){let t=JSON.stringify(e??(e===null?null:`\0`)),n=h.get(t);return n||h.set(t,n=d(e,!1)),n}function _(e){return e.origin.via?.kind===`engine`?f:e.origin.via?.kind===`client`?(e.self!==null&&m(e.self),g(`profile`in e?e.profile:e.self??void 0)):m(e.self??`client`)}let v=null,y=()=>(v??=i(r).then(async e=>{if(!e.ok)throw new Id(e.status>=400?e.status:502,`no_board`,`There's no board at ${r}: it answered ${e.status}.`,{origin:`handle`});return await e.json()},Of)).catch(e=>{throw v=null,e}),b=null,x=()=>b??=f.me().then(e=>e.principal).catch(e=>{throw b=null,e}),S=async e=>Fd(await x(),e);async function C(e,t,n,i){let a=_d[t],o={...n},s=a.path.replace(/:(\w+)/g,(e,t)=>{let n=o[t];return delete o[t],encodeURIComponent(String(n))}),c;if(t===`upload`){let{data:t,name:r,type:a}=n;if(t.byteLength>4194304){let n=await e.upload({data:t,name:r??`file`,...a?{type:a}:{}}).catch(Of);return Response.json({attachment:n})}c=await e.request(s,{method:`POST`,body:t,headers:{...a?{"content-type":a}:{},...r===null?{}:{"x-board-filename":encodeURIComponent(r)}},signal:i}).catch(Of)}else c=a.method===`GET`?await e.request(`${s}${kf(o)}`,{signal:i}).catch(Of):await e.request(s,{method:`POST`,body:new TextEncoder().encode(JSON.stringify(o)),headers:{"content-type":`application/json`},signal:i}).catch(Of);if(c.ok)return c;try{let e=await c.json();if(e.error?.message)throw new Id(c.status,e.error.code??`error`,e.error.message,typeof e.error.hint==`string`?{hint:e.error.hint}:{})}catch(e){if(e instanceof Id)throw e}throw new Id(502,`remote_error`,`${r} answered ${c.status}`)}async function w(e,t,n,a){if(e===`me`){let{principal:e,author:n,actor:r}=t;return{actor:r.id,principal:e.id,kind:r.kind,handle:r.handle,name:r.name,avatar:r.avatar,profile:n.profile,session:n.session,expiresAt:e.expiresAt?.toISOString()??null,can:e.access.summary()}}if(Cf.has(e))throw Bd(`this board's callers act as its project on ${r}, which can't tell them apart: ${e} is the project's own to do there`);let s=Ef(t),c=t.actor.avatar?.startsWith(`https://`)?t.actor.avatar:void 0,l=kd({url:r,fetch:i,profile:{name:Tf(t.actor.handle,Object.keys(o)),...c?{avatar:c}:{}},session:null,...s===null?{}:{headers:{"x-board-scope":s}}});(e===`post`||e===`posted`)&&typeof n.id==`string`&&(n={...n,id:await S(await Nd(`board-gateway`,t.principal.id,n.id)).catch(Of)});let u=await C(l,e,n,a);return e===`attachment`?Af(String(n.id),u):u.json()}async function T(e,t,n,r){let i=k();if(`identity`in t)return w(e,t.identity,n,r);let a=_(t);`self`in t&&t.origin.via?.kind===`engine`&&await i,(e===`post`||e===`posted`)&&`self`in t&&typeof n.id==`string`&&Pd.test(n.id)&&(n={...n,id:await S(n.id).catch(Of)});let o=await C(a,e,n,r);return e===`attachment`?Af(String(n.id),o):o.json()}let E={...Object.fromEntries(Jd.map(e=>[e,(t,n,r)=>T(e,t,n,r)])),async discovery(){return y()},async readSource(e,t,n){return`self`in e&&u().sync.some(e=>e.key===t.key)?u().readSource(t.key,t.target,t.limit??50,t.after??null):T(`readSource`,e,t,n)},async joinSource(e,t,n){return`self`in e&&u().sync.some(e=>e.key===t.key)?u().joinSource(t.key,t.target):T(`joinSource`,e,t,n)},async synced(e,t,n){let{targets:r}=await T(`synced`,e,t,n);return{targets:await Promise.all(r.map(async e=>({...e,url:e.url??(e.thread!==null&&e.message!==null?await u().linkOf(e.key,e.thread,e.message):null)})))}},async linked(e,t,n){let r=()=>new Id(404,`message_not_found`,`no message on this board for that link`),i=await(async()=>{for(let{platform:e,thread:r,message:i}of u().locate(t.url))for(let t of u().sync.filter(t=>t.platform===e)){let e=await f.syncFind({thread:`${t.key}:${r}`,...i===null?{}:{message:i}},{signal:n}).catch(Of),a=i===null?e.thread===null?null:(await f.syncThread(e.thread).catch(Of)).root:e.message;if(a!==null)return a}return null})();if(i===null)return T(`linked`,e,t,n);try{return await E.message(e,{id:i},n)}catch(e){throw e instanceof Id&&e.status===404?r():e}},async typing(e,t,n){let{targets:r}=await T(`typing`,e,t,n);if(!(`self`in e)||u().sync.length===0)return{targets:r};let{message:i,replies:a}=await E.message(e,{id:t.id},n),o=await u().typing([i,...a],t.status).catch(e=>(console.warn(`[board] skipped typing where this board syncs:`,Df(e)),[]));return{targets:[...r,...o]}}};async function D(e){let t=vf(e);return t&&(await y()).wake_by_path?t:{url:e}}let O=yf({remote:r,registry:{register:e=>f.register({...e,watch:o,...s.length>0?{sync:s}:{}}),matches:e=>f.matches(e),ack:(e,t)=>f.ack(e,t)},wakeAt:D,binding:u,hash:l,hasWork:()=>Object.keys(o).length>0||s.length>0,rethrow:Of,registerFor:async(e,t)=>Ud(await E.register(e,Ru.parse(await t.json()),t.signal))}),k=O.start;return{...E,routes:O.routes,keeps:!1,bind(e){if(a)throw Error(`http: this backend already serves a board: create one http() per board()`);for(let[t,n]of Object.entries(e.subscriptions)){if(n.kind===`sync`){t===`@sync`&&(s=e.sync.map(e=>({...e})));continue}if(!Sf.test(t))throw Error(`watch ${t}: ids start with a letter and use up to 32 letters, numbers, and hyphens`);pf(t,n),o[t]={tail:n.tail,when:n.when}}c=null,a=e},registerWatchers:O.registerNow,close:O.close}}function Mf(e,t={}){return jf(e,t,null)}const Nf=/```[\s\S]*?```/g,Pf=/`[^`\n]*`/g,Ff=`[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?`,If=RegExp(`(?<![\\w@.-])@(${Ff}(?:/${Ff})?)(?!:|[a-z0-9_/-]|\\.(?=[a-z0-9]))`,`gi`),Lf=/(?<![\w@.-])@\[([^\]\s]+)\]/g,Rf=e=>e.replace(Nf,e=>` `.repeat(e.length)).replace(Pf,e=>` `.repeat(e.length));function zf(e){let t=Rf(e),n=[];for(let e of t.matchAll(Lf)){let t=e[1];t!==void 0&&n.push({index:e.index,token:{kind:`actor`,actor:t},key:`actor:${t}`})}for(let e of t.replace(Lf,e=>` `.repeat(e.length)).matchAll(If)){let t=e[1]?.toLowerCase();t!==void 0&&n.push({index:e.index,token:{kind:`handle`,handle:t},key:`handle:${t}`})}let r=/* @__PURE__ */ new Set;return n.sort((e,t)=>e.index-t.index).filter(({key:e})=>!r.has(e)&&r.add(e)).map(({token:e})=>e)}function Bf(e,t){let n=Rf(e),r=[];for(let e of n.matchAll(Lf))r.push({index:e.index,length:e[0].length,token:{kind:`actor`,actor:e[1]}});for(let e of n.replace(Lf,e=>` `.repeat(e.length)).matchAll(If))r.push({index:e.index,length:e[0].length,token:{kind:`handle`,handle:e[1].toLowerCase()}});let i=``,a=0;for(let{index:n,length:o,token:s}of r.sort((e,t)=>e.index-t.index)){let r=e.slice(n,n+o);i+=e.slice(a,n)+(t(s,r)??r),a=n+o}return i+e.slice(a)}const Vf=[`read`,`post`,`react`,`label`,`sync`,`manage`],Hf={read:[],post:[],react:[`read`],label:[`read`],sync:[`read`],manage:[`read`,`post`,`react`,`label`,`sync`]},Uf=new Map(Vf.map((e,t)=>[e,t])),Wf=`write *, a channel, or a channel and its subtree (feedback/)`;function Gf(e){if(e===`*`)return{kind:`all`};if(e.includes(`*`)){let t=e.slice(0,e.indexOf(`*`)).replace(/\/+$/,``),n=t===``?`write * for every channel`:Yl.safeParse(t).success?`write ${t}/ for ${t} and its subtree`:Wf;throw Error(`invalid channel pattern ${e}: ${n}`)}let t=e.endsWith(`/`),n=t?e.slice(0,-1):e;if(!Yl.safeParse(n).success)throw Error(`invalid channel pattern ${e||`(empty)`}: ${Wf}`);return t?{kind:`subtree`,path:n}:{kind:`exact`,path:n}}const Kf=e=>e.kind===`all`?`*`:e.kind===`subtree`?`${e.path}/`:e.path;function qf(e){let t=/* @__PURE__ */ new Set,n=e=>{if(!Uf.has(e))throw Error(`unknown permission ${String(e)}: use ${Vf.join(`, `)}`);if(!t.has(e)){t.add(e);for(let t of Hf[e])n(t)}};for(let t of e===`all`?Vf:e)n(t);return t}const Jf=/* @__PURE__ */ new Set;function Yf(e){let t=null,n=/* @__PURE__ */ new Map,r=[];for(let[i,a]of e)i.kind===`all`?t=a:i.kind===`exact`?n.set(i.path,a):r.push([i.path,a]);return r.sort((e,t)=>t[0].length-e[0].length),{all:t,exact:n,subtrees:r}}const Xf=(e,t)=>e===t||e.startsWith(`${t}/`);function Zf(e,t,n=!1){if(!n){let n=e.exact.get(t);if(n)return n}for(let[n,r]of e.subtrees)if(Xf(t,n))return r;return e.all??Jf}const Qf=(e,t)=>t.kind===`all`?e.all??Jf:Zf(e,t.path,t.kind===`subtree`),$f=(e,t)=>e.size===t.size&&[...e].every(e=>t.has(e));function ep(e,t){if(t.kind===`exact`)return Zf(e,t.path,!0);if(t.kind===`subtree`){for(let[n,r]of e.subtrees)if(n!==t.path&&Xf(t.path,n))return r}return e.all??Jf}function tp(e){let t=Yf(e);return Yf(e.filter(([e,n])=>e.kind===`all`?n.size>0:!$f(n,ep(t,e))))}function np(e){return e===`all`||Array.isArray(e)?[[{kind:`all`},qf(e)]]:Object.entries(e).map(([e,t])=>[Gf(e),qf(t)])}const rp=e=>[...e.all?[[{kind:`all`},e.all]]:[],...e.subtrees.map(([e,t])=>[{kind:`subtree`,path:e},t]),...[...e.exact].map(([e,t])=>[{kind:`exact`,path:e},t])],ip=Symbol(`board.access`),ap=e=>typeof e==`object`&&ip in e;function op(e){let t=rp(e),n=n=>(e.all?.has(n)??!1)&&t.every(([,e])=>e.has(n)),r=/* @__PURE__ */ new Map;return{[ip]:e,can:(t,n)=>Zf(e,n).has(t),readable(t){let n=r.get(t);return n===void 0&&r.set(t,n=Zf(e,t).has(`read`)),n},readsAll:n(`read`),everywhere:n,anywhere:e=>t.some(([,t])=>t.has(e)),narrow(n){let r=ap(n)?n[ip]:tp(np(n)),i=/* @__PURE__ */ new Map([[`*`,{kind:`all`}]]);for(let[e]of[...t,...rp(r)])i.set(Kf(e),e);return op(tp([...i.values()].map(t=>{let n=Qf(r,t);return[t,new Set([...Qf(e,t)].filter(e=>n.has(e)))]})))},summary(){let e=t.map(([e,t])=>[Kf(e),t]);e.sort(([e],[t])=>e===`*`?-1:t===`*`?1:e.localeCompare(t));let n={};for(let[t,r]of e)n[t]=[...r].sort((e,t)=>Uf.get(e)-Uf.get(t));return n}}}function sp(e){return op(tp(np(e)))}const cp=sp(`all`);function lp(e){if(e.length>4e3)throw Error(`x-board-scope is longer than 4000 characters`);let t={},n=e.split(`;`).map(e=>e.trim());if(n.every(e=>e===``))throw Error(`x-board-scope is empty: write pattern=permissions, like dev/=read,post`);for(let e of n){if(e===``)continue;let n=e.indexOf(`=`);if(n<0)throw Error(`x-board-scope entry ${e} needs =: write pattern=permissions, like dev/=read,post`);let r=e.slice(0,n).trim(),i=e.slice(n+1).trim();if(Object.hasOwn(t,r))throw Error(`x-board-scope lists ${r} twice`);Gf(r);let a=i===``?[]:i.split(`,`).map(e=>e.trim());if(a.length===1&&a[0]===`all`){t[r]=`all`;continue}for(let e of a)if(!Uf.has(e))throw Error(`x-board-scope: unknown permission ${e||`(empty)`}: use ${Vf.join(`, `)}, or all`);t[r]=a}return t}const up=[`claude`,`codex`,`grok`,`pi`],dp=/^[A-Za-z][A-Za-z0-9-]{0,31}$/,fp=/^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$/;function pp(e){let t=e.get(`x-board-profile`)?.trim()||null;if(t!==null&&!dp.test(t))throw Rd(`profile names start with a letter and use up to 32 letters, numbers, and hyphens`);let n=e.get(`x-board-avatar`)?.trim()||null;if(n!==null&&!hp(n))throw Rd(`avatars must be https URLs (http only on localhost)`);let r=e.get(`x-board-session`)?.trim().slice(0,200)||null,i=e.get(`x-board-handle`)?.trim().toLowerCase()||null;if(i!==null&&!fp.test(i))throw Rd(`invalid handle: ${i}`);let a=e.get(`x-board-name`),o=null;if(a)try{o=decodeURIComponent(a).replace(/[\u0000-\u001f\u007f]/g,``).trim().slice(0,128)||null}catch{throw Rd(`x-board-name must be URI-encoded`)}let s=e.get(`x-board-scope`);if(s!==null)try{lp(s)}catch(e){throw Rd(e.message,`invalid_scope`)}return{profile:t,avatar:n,session:r,handle:i,name:o,scope:s}}function mp(e,t,n){let r=e.kind===`person`&&e.facts?.issuer!==`host`&&t.handle?t.handle:e.handle,i=e.kind===`person`?t.name:null,a=t.profile?.toLowerCase()??null,o=a===null?e.id:`${e.id}+${a}`,s=a!==null&&up.includes(a),c={id:o,kind:a===null?e.kind:`agent`,handle:a===null?r:`${r}/${a}`,name:t.profile??i??r,avatar:t.avatar??(s?`${n}/avatars/${a}`:null)};return{author:{actor:o,principal:e.id,profile:a,session:t.session},actor:c}}function hp(e){try{let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`&&[`localhost`,`127.0.0.1`].includes(t.hostname)}catch{return!1}}const gp=e=>Bd(`this token can't use this board: add ${e} to access`),_p=e=>{let t=new URL(e);return`${t.host}${t.pathname.replace(/\/+$/,``)}`.replace(/[%:]/g,e=>e===`%`?`%25`:`%3A`)};function vp(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=_p(n),r=t.get(e);if(r!==void 0&&r!==n)throw Error(`access: oidc issuers ${r} and ${n} name the same principals, oidc:${e}:<sub>: pin one of them`);t.set(e,n)}return new Set(e)}const yp=e=>[...new Set(e.flatMap(e=>typeof e!=`function`&&e.issuer===`oidc`?[e.url]:[]))];function bp(e){let t=typeof e.access==`function`?[]:e.access,n=typeof e.access==`function`?e.access:null,r=vp(yp(t));async function i(n,i){if(i?.issuer===`host`)throw Bd(`this token can't use this board: its board no longer takes a host's principals`);if(i?.issuer===`oidc`&&!r.has(i.iss))throw zd(`untrusted issuer: ${i.iss}`);let a=i?.claims??{},o=i?.issuer===`vercel`?await e.project():null,s=o?{teamId:i.team??o.teamId,projectId:o.id}:{teamId:null,projectId:null},c=String(a.environment??``),l=xp(),u=o!==null&&o.id!==null&&a.project_id===o.id,d=u&&l!==null&&c===l;for(let e of t){if(typeof e==`function`){if(d)continue;let t=await e(n);if(t===void 0)continue;if(t===null)throw Bd(`this token can't use this board`);return sp(t)}if(i&&e.issuer===i.issuer&&(e.issuer!==`oidc`||e.url===i.iss)&&e.matches(a,s))return e.access}if(d)return cp;throw i?i.issuer===`oidc`?gp(`oidc({ issuer: '${i.iss}', claims, can })`):i.issuer===`github`?gp(`githubActions({ repository: '${String(a.repository)}', can })`):u?Bd(`this token can't use this board: it runs in ${l??`no Vercel environment`}, so its ${c||`unnamed`} deployments need vercelProject({ project: 'self', environments: ['${c}'], can })`):gp(`vercelProject({ project: '${String(a.project??``)||String(a.project_id)}', can })`):Bd(`this token can't use this board`)}async function a(t){let r=cp,a=t.facts?.issuer===`host`;if(t.id.startsWith(`board:`)||t.kind===`external`&&!a)r=cp;else{if(a){if(!e.hosts)throw Bd(`this token can't use this board: its board no longer takes a host's principals`);let{exp:n}=t.facts.claims;if(typeof n==`number`&&n*1e3<=Date.now())throw zd(`token expired`)}if(n){let e=await n(t);if(e==null)throw Bd(`this token can't use this board`);r=sp(e)}else t.kind!==`person`&&(r=await i(t,(a?void 0:t.facts)??Sp(t.id)))}return t.scope===void 0?r:r.narrow(lp(t.scope))}async function o(e){try{return await a(e)}catch(e){let t=e.status;if(t===401||t===403)return null;throw e}}return{grant:a,accessNow:o}}const xp=()=>process.env.VERCEL_TARGET_ENV||process.env.VERCEL_ENV||null;function Sp(e){let t=e.match(/^vercel:project:([^:]+):([^:]+)$/);return t?{issuer:`vercel`,iss:``,claims:{project_id:t[1],environment:t[2]}}:null}const Cp=Symbol(`board.oidcTokens`),wp=/* @__PURE__ */ new WeakSet,Tp=e=>Cp in e,Ep=e=>wp.has(e),Dp=/^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*:[^\s+\]]{1,200}$/,Op=[`person`,`deployment`,`workflow`,`external`];function kp(e){let t=e=>{throw TypeError(`authenticate returned an invalid principal: ${e}`)};(typeof e!=`object`||!e)&&t(`not an object`),(typeof e.id!=`string`||!Dp.test(e.id)||e.id.startsWith(`board:`))&&t(`id must look like \`vercel:user:<id>\`, got ${JSON.stringify(e.id)}`),Op.includes(e.kind)||t(`kind must be one of ${Op.join(`, `)}`),(typeof e.handle!=`string`||!/^\S{1,64}$/.test(e.handle))&&t(`handle must be 1-64 characters, no spaces`);let n=e.expiresAt??null;if(n!==null&&(!(n instanceof Date)||Number.isNaN(n.getTime()))&&t(`expiresAt must be a Date or null`),n!==null&&n.getTime()<=Date.now())throw zd(`token expired`);let r=n===null?{}:{exp:Math.floor(n.getTime()/1e3)};return{id:e.id,kind:e.kind,handle:e.handle,expiresAt:n,facts:{issuer:`host`,iss:``,claims:r}}}function Ap(e,t,n){let r=t||e.access!==void 0,i=e.access??[],a=null,o=()=>(a??=(async()=>{if(!n)return{id:e.project?.id??null,teamId:e.project?.teamId??null};let t=await n(),[r,i]=await Promise.all([t.ownProjectId(e.project),t.ownTeamId(e.project)]);return{id:r,teamId:i}})()).catch(e=>{throw a=null,e});async function s(t){return n?(await n()).discoveryIdentity(t,e.project):{projectId:e.project?.id??null,teamId:e.project?.teamId??null}}let c=null,l=()=>e.authenticate?Promise.resolve(e.authenticate):c??=n?n().then(e=>e.oidcTokens()):Promise.reject(new Id(501,`no_verifier`,`this build of board verifies no tokens: pass board({ authenticate })`)),u=bp({access:i,project:o,hosts:e.authenticate!==void 0&&!Tp(e.authenticate)}),d={project:o,issuers:typeof i==`function`?[]:yp(i)},f=/* @__PURE__ */ new Map,p=/* @__PURE__ */ new WeakMap;async function m(e){let t=e=>e.expiresAt===null||e.expiresAt.getTime()>Date.now(),n=p.get(e);if(n){let e=await n;if(t(e))return e}let r=e.credential===null?null:[e.audience,e.credential,e.headers.get(`x-vercel-oidc-token`)??``].join(``),i=r===null?void 0:f.get(r);if(i&&i.until>Date.now())return p.set(e,i.principal),i.principal;let a=h(e);return p.set(e,a),r!==null&&a.then(e=>{e.facts?.issuer!==`host`&&e.expiresAt!==null&&(f.size>=1e3&&f.delete(f.keys().next().value),f.set(r,{principal:a,until:e.expiresAt.getTime()}))},()=>p.delete(e)),a}async function h(e){let t=await l(),n;try{n=await t({...e,board:d})}catch(e){throw e instanceof Response?new Ld(e):e}if(n instanceof Response)throw new Ld(n);if(n==null)throw zd(`missing bearer token`);return Ep(n)?n:kp(n)}return{open:r,project:o,discoveryIdentity:s,async identify(e){let t=await m(e),n=e.claims.scope===null?t:{...t,scope:e.claims.scope},{author:r,actor:i}=mp(n,e.claims,e.audience);return{principal:{...n,access:await u.grant(n)},author:r,actor:i}},accessNow:e=>u.accessNow(e)}}const jp={claude:`m4.7144 15.9555 4.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608 1.5179.1032 2.2767.1578 1.6514.0972 2.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973 9.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686 1.9064 1.4754 2.4893 1.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335 6.6997 0l.9957.1336.419.3642.6192 1.4147 1.0018 2.2282 1.5543 3.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853 1.8517-.5586 2.9021-.3643 1.9429h.2125l.2429-.2429.9835-1.3053 1.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759 1.1293-.34 1.1657-1.0625 1.3478-.8804 1.1414-1.2628 1.7-.7893 1.36.0729.1093.1882-.0183 2.8535-.607 1.5421-.2794 1.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607 1.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929 1.0686 2.0035 1.8092 2.5075 2.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496 2.3436 3.5214.1214 1.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38 17.959l-1.1414-1.9428-.1397.079-.674 7.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328 1.9672-2.1796 2.9446-1.7243 1.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889 2.386-3.0357 1.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385 4.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429 1.9064-1.3114Z`,openai:`M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z`,x:`M14.234 10.162 22.977 0h-2.072l-7.591 8.824L7.251 0H.258l9.168 13.343L.258 24H2.33l8.016-9.318L16.749 24h6.993zm-2.837 3.299-.929-1.329L3.076 1.56h3.182l5.965 8.532.929 1.329 7.754 11.09h-3.182z`,slack:`M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52v2.52zM6.313 15.165a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313zM8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.528 2.528 0 0 1 2.521 2.522v2.52H8.834zM8.834 6.313a2.528 2.528 0 0 1 2.521 2.521 2.528 2.528 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312zM18.956 8.834a2.528 2.528 0 0 1 2.522-2.521A2.528 2.528 0 0 1 24 8.834a2.528 2.528 0 0 1-2.522 2.521h-2.522V8.834zM17.688 8.834a2.528 2.528 0 0 1-2.523 2.521 2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.528 2.528 0 0 1 2.523 2.522v6.312zM15.165 18.956a2.528 2.528 0 0 1 2.523 2.522A2.528 2.528 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.522v-2.522h2.52zM15.165 17.688a2.527 2.527 0 0 1-2.52-2.523 2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.523h-6.313z`,github:`M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12`,whatsapp:`M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z`},Mp={claude:{background:`#D97757`,mark:{path:jp.claude}},codex:{background:`#000000`,mark:{path:jp.openai}},grok:{background:`#000000`,mark:{path:jp.x}},pi:{background:`#1f1f1f`,mark:{glyph:`π`}}};function Np(e){let t=Mp[e]??{background:`#666666`,mark:{glyph:e.slice(0,1).toUpperCase()}},n=`path`in t.mark?`<path transform="translate(30 30) scale(2.8333)" fill="#ffffff" d="${t.mark.path}"/>`:`<text x="64" y="86" font-family="ui-sans-serif,system-ui,sans-serif" font-size="66" font-weight="600" text-anchor="middle" fill="#ffffff">${t.mark.glyph}</text>`;return`<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><rect width="128" height="128" rx="28" fill="${t.background}"/>${n}</svg>`}var Pp=class extends Id{responses;constructor(e){super(422,`dropped`,e.join(`
346
346
  `)||`the board dropped this message`),this.responses=e}};const Fp=q({text:K().max(ql).optional(),labels:ru.optional()}).strict();async function Ip(e,t,n){let r=[],i=null,a=async(o,s)=>{if(o===e.length){if(s.text.trim()===``&&(s.kind===`edit`||s.attachments.length===0))return;i={value:await n(s)};return}let c=null;await e[o]({write:Object.freeze({...s}),author:Object.freeze({...t.author}),source:Object.freeze({...t.source}),board:t.board(),respond:async e=>{r.push(e)},next:(e={})=>{if(c)throw Error(`next() was already called`);let{text:t,labels:n}=Fp.parse(e);return c=a(o+1,{...s,...t===void 0?{}:{text:t},...s.kind===`post`&&n?{labels:{...s.labels,...n}}:{}}),c}}),c&&await c};if(await a(0,t.write),!i)throw new Pp(r);return i.value}const Lp=e=>typeof e==`string`?{target:e,kind:vu(e)?`thread`:`channel`}:e,Rp=e=>zf(e).some(e=>e.kind===`actor`&&e.actor.includes(`@`));async function zp(e,t){let n=zf(e).flatMap(e=>e.kind===`actor`&&e.actor.includes(`@`)?[e.actor]:[]);if(n.length===0)return{text:e,found:[]};let r=/* @__PURE__ */ new Map;for(let e of n)r.set(e,await t?.(e).catch(()=>null)??null);return{text:Bf(e,e=>{if(e.kind!==`actor`||!r.has(e.actor))return null;let t=r.get(e.actor);return t?`@[${t.id}]`:e.actor}),found:[...r.values()].filter(e=>e!==null)}}const Bp=/* @__PURE__ */ new Set([`post`,`schedule`,`upload`,`uploadFinish`]),Vp=/^(image\/(png|jpeg|gif|webp|avif)|video\/(mp4|webm)|text\/plain)$/;function Hp({attachment:e,data:t}){let n=Vp.test(e.type)?`inline`:`attachment`,r=t instanceof Uint8Array?new Blob([t]):t;return new Response(r,{headers:{"content-type":e.type,"content-length":String(e.size),"content-disposition":`${n}; filename*=UTF-8''${encodeURIComponent(e.name)}`,"content-security-policy":`sandbox; default-src 'none'`,"x-content-type-options":`nosniff`,"cache-control":`private, max-age=31536000, immutable`}})}async function Up(e,t,n,r){let i=r.id??``,a=r.key??``,o=()=>$d(t);switch(e){case`discovery`:case`me`:case`channels`:case`actors`:case`identity`:case`watchers`:return{};case`message`:case`posted`:case`synced`:case`delete`:case`cancelSchedule`:case`attachment`:case`uploadFinish`:return{id:i};case`messages`:return Du.parse(Qd(n));case`threads`:return Ou.parse(Qd(n));case`schedules`:return Pu.parse(Qd(n));case`matches`:return zu.parse(Qd(n));case`events`:{let e=ku.parse(Qd(n)),r=t.headers.get(`last-event-id`);return e.after===void 0&&r&&xu.safeParse(r).success&&(e.after=r),e}case`post`:return Au.parse(await o());case`schedule`:return Nu.parse(await o());case`register`:return Ru.parse(await o());case`edit`:return{id:i,...fd.parse(await o())};case`react`:return{id:i,...hd.parse(await o())};case`label`:return{id:i,...gd.parse(await o())};case`ack`:return{id:i,...Bu.parse(await o())};case`upload`:{let e=t.headers.get(`x-board-filename`),n=null;try{n=e===null?null:decodeURIComponent(e)}catch{throw Rd("`x-board-filename` is not URI-encoded")}return{data:await tf(t,Oe),name:n,type:t.headers.get(`content-type`)}}case`uploadStart`:return dd.parse(await o());case`syncImport`:return Qu.parse(await o());case`syncReceipt`:return ed.parse(await o());case`syncThread`:return{thread:r.thread??``};case`syncFind`:return td.parse(Qd(n));case`syncCopies`:return nd.parse(Qd(n));case`syncRoots`:return rd.parse(Qd(n));case`inboxPush`:return{key:a,...id.parse(await o())};case`inboxNext`:return{key:a,...ad.parse(Qd(n))};case`inboxAck`:return{key:a,id:i,...od.parse(await o())};case`inbox`:return{key:a,...Iu.parse(Qd(n))};case`syncCode`:return sd.parse(await o());case`syncAccount`:return cd.parse(await o());case`syncUnlink`:return ud.parse(await o());case`typing`:return{id:i,...md.parse(await o())??{}};case`readSource`:return{key:a,...Vu.parse(Qd(n))};case`joinSource`:return{key:a,...Hu.parse(await o())};case`linked`:return Uu.parse(Qd(n))}}const Wp=e=>({id:e.id,kind:`external`,handle:e.handle,name:e.name,avatar:e.avatar});function Gp(e){let t=e.origin.via;return t?.kind===`middleware`||t?.kind===`engine`?null:t??{kind:`api`}}const Kp={self:`middleware`,origin:{via:{kind:`middleware`}}},qp={self:null,origin:{via:{kind:`client`,name:null}}};async function Jp(e){let{options:t,backend:n,runtime:r,policy:i}=e,a=t.sync??{},o=Object.keys(a).length>0?(await r.sync()).createSyncEngine(a):null,s=t.streamMaxMs??28e4,c=Zd(n.routes,t.basePath),{state:l,ownUrl:u,clientAs:d,handleOf:f}=e,p=t.watch??{},m=t.middleware??[];function h(e,t){return{credential:(e.headers.get(`authorization`)??``).match(/^Bearer\s+(.+)$/i)?.[1]??null,claims:pp(e.headers),audience:t,headers:e.headers}}async function g(e){return{identity:await i.identify(e),origin:{via:{kind:`api`}}}}let _=()=>new Id(404,`not_found`,`${u()??`this board`} answers only wake-ups and webhooks`);async function v(e){return(await zp(e,o?async e=>{let t=await o.findByEmail(e);return t&&await n.syncImport(o.caller,{op:`seen`,author:{...t,isBot:!1}},new AbortController().signal),t}:void 0)).text}async function y(e){if(typeof e!=`string`)return e;let t=e.indexOf(`:`);if(t<=0)throw Rd(`sync targets look like <key>:<channel or thread>, got: ${e}`);let n=e.slice(0,t);if(o&&a[n])return o.normalizeTarget(e);if(o)throw Rd(`no sync entry named ${n}`);return Lp(e)}let b=e=>`identity`in e?e.identity.principal.access:null;async function x(e,t,n){let r=b(e);if(r===null)return{access:null,channel:t.channel??``};let i=t.channel??(t.re===void 0?void 0:(await P(e,t.re,n))?.channel);return i===void 0?null:r.can(`post`,i)?{access:r,channel:i}:null}let S=/* @__PURE__ */ new Map;async function C(e,t){if(`identity`in e)return{principal:e.identity.principal.id,actor:e.identity.actor};let r=JSON.stringify([e.origin.via?.kind??``,e.self,e.profile??null]),i=S.get(r);return i||(S.set(r,i=n.me(e,{},t).then(e=>({principal:e.principal,actor:{id:e.actor,kind:e.kind,handle:e.handle,name:e.name,avatar:e.avatar}}))),i.catch(()=>S.delete(r))),i}let w=null,T=(e,t,n,r)=>Ip(m,{write:e,author:t,source:n,board:()=>w??=f(Kp,null)},r);async function E(e){try{return await e(),!0}catch(e){if(e instanceof Id&&e.status===404)return!1;throw e}}async function D(e,t,r){let i=[];for(let a of new Set(t??[])){let{attachment:t,data:o}=await n.attachment(e,{id:a},r);o instanceof ReadableStream&&await o.cancel().catch(()=>{}),i.push(t)}return i}async function O(e,t,r,i){let a=Gp(e);if(m.length===0||a===null||t.id!==void 0&&await E(()=>n.posted(e,{id:t.id},r)))return i(t);let o=t.channel,s=null;if(t.re!==void 0){let n=await P(e,t.re,r);if(!n)return i(t);o=n.channel,s=n.re??n.id}let c=b(e),l=Object.keys(t.labels??{}).length>0,u=t.re===void 0&&(t.sync?.length??0)>0;if(o===void 0||c&&(!c.can(`post`,o)||l&&!c.can(`label`,o)||u&&!c.can(`sync`,o)))return i(t);let d=await D(e,t.attachments,r),{actor:f}=await C(e,r);return T({kind:`post`,channel:o,re:s,text:t.text,labels:t.labels??{},attachments:d},f,a,e=>i({...t,text:e.text,labels:e.labels}))}async function k(e,t,n){let r=b(e),i=await P(e,t,n),a=i??(r===null?null:await P(qp,t,n));return!a||a.deleted||r&&!r.can(`post`,a.channel)||!i&&!a.blind?null:a.by.principal===(await C(e,n)).principal?a:null}async function A(e,t,n,r){let i=Gp(e);if(m.length===0||i===null)return r(t);let a=await k(e,t.id,n);if(!a)return r(t);let{actor:o}=await C(e,n);return T({kind:`edit`,id:a.id,channel:a.channel,re:a.re,text:t.text},o,i,e=>r({...t,text:e.text}))}async function j(e,t,r,i){let o=t.source?.key??t.from;if(t.source&&!(`identity`in e?(await n.watchers(e,{},i)).watchers.some(t=>t.owner===e.identity.principal.id&&t.sync.some(e=>e.key===o)):a[t.source.key]!==void 0))return null;let s=(t.op===`post`?t.origin:null)??r?.origin??null;return{kind:`sync`,key:o??``,platform:t.author.id.slice(0,Math.max(0,t.author.id.indexOf(`:`))),channel:t.source?.channel??r?.origin?.channel??s?.channel??``,thread:t.source?.thread??(s?s.subthread??s.thread:``)}}async function M(e,t,r){let i=t.message??null;if(t.origin!==void 0){let{thread:a,message:o}=await n.syncFind(e,{thread:t.origin.thread,...t.origin.message===void 0?{}:{message:t.origin.message}},r);i=t.origin.message===void 0?a===null?null:(await n.syncThread(e,{thread:a},r)).root:o}return i===null?null:P(e,i,r)}async function N(e,t,r){let i=t=>n.syncImport(e,t,r);if(m.length===0||e.origin.via?.kind===`middleware`||t.op!==`post`&&t.op!==`edit`)return i(t);let a=b(e);if(a&&(!a.anywhere(`sync`)||`identity`in e&&e.identity.principal.scope!==void 0))return i(t);let o=async e=>{try{return await e()}catch(e){if(!(e instanceof Pp))throw e;return{message:null,dropped:[...e.responses]}}};if(t.op===`post`){if(t.id!==void 0&&(await n.syncFind(e,{post:t.id},r)).message!==null)return i(t);let s=t.channel,c=null;if(t.re!==void 0){let n=await P(e,t.re,r);if(!n)return i(t);s=n.channel,c=n.re??n.id}if(s===void 0||a&&!a.can(`sync`,s))return i(t);let l=await j(e,t,null,r);if(!l)return i(t);let u=await D(e,t.attachments,r);return o(async()=>T({kind:`post`,channel:s,re:c,text:t.text,labels:t.labels??{},attachments:u},Wp(t.author),l,async e=>i({...t,text:e.text,labels:e.labels})))}if(t.origin===void 0==(t.message===void 0))return i(t);let s=await M(e,t,r);if(!s||s.deleted||a&&!a.can(`sync`,s.channel)||t.message!==void 0&&s.by.principal!==t.author.id)return i(t);let c=await j(e,t,s,r);return c?o(async()=>T({kind:`edit`,id:s.id,channel:s.channel,re:s.re,text:t.text},Wp(t.author),c,async e=>i({...t,text:e.text}))):i(t)}async function P(e,t,r){try{let{message:i,replies:a}=await n.message(e,{id:t},r);return[i,...a].find(e=>e.id===t)??null}catch(e){if(e instanceof Id&&e.status===404)return null;throw e}}async function F(e,t,r){let i=(e,t)=>O(e,t,r,t=>n.post(e,t,r));if(!o)return i(e,t.sync?.length?{...t,sync:await Promise.all(t.sync.map(y))}:t);let a=(t.sync?.length??0)>0||Rp(t.text)?await x(e,t,r):null;if(!a)return i(e,t);let{access:s,channel:c}=a,l=t.re===void 0&&(t.sync?.length??0)>0&&(s===null||s.can(`sync`,c))?{...t,sync:await Promise.all(t.sync.map(y))}:t,u=await v(l.text),d=await i(e,{...l,text:u});return u!==t.text&&s!==null&&!s.readable(d.message.channel)?{...d,message:{...d.message,text:t.text}}:d}async function I(e,t){if(!t.dropped)return t.message;for(let n of t.dropped)await e.platform.respond(n);throw new Pp(t.dropped)}async function L(e,t,n,r){let i=o.caller,{author:a,key:s}=t.platform,{via:c}=t.origin,l={key:s,channel:c.channel,thread:c.thread},u=async e=>{if(await I(t,await N(i,e,r))===null)throw Vd(`message not found: #${e.message}`,`message_not_found`);return{ok:!0}};switch(e){case`post`:return R(t,n,r);case`edit`:{let{id:e,text:t}=n;return u({op:`edit`,author:a,from:null,message:e,text:await v(t),source:l})}case`delete`:return u({op:`delete`,author:a,from:null,message:n.id});case`react`:{let{id:e,emoji:t,remove:r}=n;return u({op:`react`,author:a,from:null,message:e,emoji:t,...r===void 0?{}:{remove:r}})}case`label`:{let{id:e,set:t,unset:r}=n;return u({op:`labels`,author:a,from:null,message:e,...t?{set:t}:{},...r?{unset:r}:{}})}default:return z(e,i,n,r)}}async function R(e,t,r){let i=o.caller,{author:a,key:s}=e.platform,{via:c}=e.origin,l=async e=>{let t=await P(i,e,r);if(!t)throw Vd(`message not found: #${e}`,`message_not_found`);return t};if(t.id!==void 0){let e=(await n.syncFind(i,{post:t.id},r)).message;if(e!==null)return{message:await l(e)}}let u=await Promise.all((t.sync??[]).map(y)),d=await I(e,await N(i,{op:`post`,author:a,from:null,origin:null,source:{key:s,channel:c.channel,thread:c.thread},...t.channel===void 0?{re:t.re}:{channel:t.channel},text:await v(t.text),...t.labels?{labels:t.labels}:{},...t.noSync?{noSync:!0}:{},...t.attachments?.length?{attachments:t.attachments}:{},...t.id===void 0?{}:{id:t.id}},r));for(let e of u)await n.syncReceipt(i,{kind:`thread`,message:d,target:e.target,targetKind:e.kind,cause:`request`},r);return{message:await l(d)}}async function z(e,t,r,i){switch(e){case`post`:return F(t,r,i);case`edit`:{let{id:e,text:a}=r,s=e=>A(t,e,i,e=>n.edit(t,e,i));return!o||!Rp(a)||!await x(t,{re:e},i)?s({id:e,text:a}):s({id:e,text:await v(a)})}case`syncImport`:return N(t,r,i);case`schedule`:{let e=r,a=o&&Rp(e.text)?await x(t,e,i):null;if(!a)return n.schedule(t,e,i);let s=await v(e.text),c=await n.schedule(t,{...e,text:s},i),{access:l}=a;return s!==e.text&&l!==null&&!l.readable(c.schedule.channel)?{...c,schedule:{...c.schedule,text:e.text}}:c}case`inbox`:{let e=r;if(o&&a[e.key]&&e.channel!==void 0){let r=b(t);if(r===null||r.anywhere(`sync`))return n.inbox(t,{...e,channel:await o.inboxChannel(e.key,e.channel)},i)}return n.inbox(t,e,i)}default:{let a=n[e];if(typeof a!=`function`)throw Vd(`no route: ${e}`);return a.call(n,t,r,i)}}}async function ee(e,t,r){let{sync:i,code:s}=ld.parse(Qd(t));if(!o||!a[i])throw Vd(`no sync entry named ${i}`);let c=(e,t)=>new Response(`${t}\n`,{status:e,headers:{"content-type":`text/plain; charset=utf-8`}}),{holder:l}=await n.syncFind(o.caller,{code:s},r);if(l===null)return c(404,"That link has expired or been used. Run `vb identity link` again for a new one.");if(e===`signIn`){let e=u(),t=await o.signIn(i,l,e?`${e}/identity/signed-in?${new URLSearchParams({sync:i,code:s})}`:void 0);return new Response(null,{status:302,headers:{location:t}})}let d=await o.redeemSignIn(i,l,s);return d?c(200,`Linked ${d.handle?`@${d.handle}`:d.actor}. You can close this tab.`):c(409,`${a[i].platform} hasn't said you approved yet: finish signing in, then open this page again.`)}async function te(e,t,r,i,a){let s=r.signal;switch(e){case`sync`:{let e=Fu.parse(await $d(r)),i=a.id??``,c=b(t);if(c&&o){let e=await P(t,i,s);if(!e)throw Vd(`message not found: #${i}`,`message_not_found`);if(!c.can(`sync`,e.channel))throw Bd(`this token can't sync in ${e.channel}`)}let l=await y(e.target),{attached:u}=await n.syncReceipt(t,{kind:`thread`,message:i,target:l.target,targetKind:l.kind,cause:`request`},s);return Ud({target:l.target,attached:u??!0})}case`identityUnlink`:{let e=Wu.parse(await $d(r)),{links:i}=await n.identity(t,{},s),a=e.actor.replace(/^@/,``).toLowerCase(),o=i.filter(t=>t.actor===e.actor||t.handle?.toLowerCase()===a).map(e=>e.actor);if(o.length===0)throw Vd(`${e.actor} isn't linked to you`,`not_linked`);if(o.length>1)throw Rd(`${e.actor} names several of your accounts: use ${o.join(` or `)}`,`ambiguous_actor`);return await n.syncUnlink(t,{account:o[0]},s),Ud({ok:!0,actor:o[0]})}default:throw Vd(`no route: ${r.method} ${i.pathname}`)}}let ne=Object.fromEntries(Jd.map(e=>[e,e===`syncImport`?N:(t,r,i)=>n[e].call(n,t,r,i)]));o?.bind({backend:ne,client:(e,t)=>d({platform:{author:e.author,key:e.key,respond:e.respond},origin:{via:e.via}},t)});async function re(e,t,r,i){let a=await n.events(e,{...t,wait:0},r.signal),o=new TextEncoder,c=new AbortController,l=Date.now()+s,u=AbortSignal.any([r.signal,c.signal,AbortSignal.timeout(s)]),d=new ReadableStream({async start(r){let s=e=>{try{r.enqueue(o.encode(e))}catch{}},c=setInterval(()=>s(`: ping
347
347
 
348
348
  `),15e3);try{s(`: connected
349
349
 
350
- `);let r=a,o;for(;;){for(let e of r.events)s(`id: ${e.cursor}\nevent: board\ndata: ${JSON.stringify(e)}\n\n`);r.cursor!==(r.events.at(-1)?.cursor??o)&&s(`id: ${r.cursor}\n\n`),o=r.cursor;let a=l-Date.now();if(u.aborted||a<=0)break;r=await n.events(i?await i():e,{...t,after:o,wait:Math.min(300,a/1e3)},u)}}catch(e){u.aborted||console.error(`[board] feed failed`,e)}finally{clearInterval(c);try{r.close()}catch{}}},cancel(){c.abort()}});return new Response(d,{headers:{"content-type":`text/event-stream`,"cache-control":`no-cache, no-transform`,connection:`keep-alive`}})}async function ie(e,t,r){let{projectId:o,teamId:s}=await i.discoveryIdentity(e.headers),c=n.keeps?(await n.discovery(qp,{},r)).sync:Object.entries(a).map(([e,t])=>({key:e,platform:t.platform}));return{version:Kd,url:t,audience:t,team_id:s,project_id:o,sync:c}}async function B(e,r){try{let s=new URL(e.url),u=c(e.method,s.pathname);if(!u)throw Vd(`no route: ${e.method} ${s.pathname}`);let{target:d}=u;!r&&!u.root&&(l.learned===null||l.learned.startsWith(`${u.base}/`))&&(l.learned=u.base);let f=(t.url??`${s.origin}${u.base}`).replace(/\/+$/,``);if(d.kind===`board`&&d.name===`webhook`){if(!o||!a[u.params.key??``])throw Vd(`no sync entry named ${u.params.key}`);return await o.handleWebhook(u.params.key,e)}if(d.kind===`board`&&(d.name===`signIn`||d.name===`signedIn`))return await ee(d.name,s,e.signal);if(d.kind===`board`&&d.name===`avatar`){let e=u.param??``;if(!up.includes(e))throw Vd(`no avatar: ${e}`);return new Response(Np(e),{headers:{"content-type":`image/svg+xml`,"cache-control":`public, max-age=86400`}})}if(d.kind===`board`&&d.name===`openapi`)return Ud(nf());if(d.kind===`backend`)return await d.route.handle(e,{caller:r&&`platform`in r?o.caller:r,param:u.param});if(!r&&!i.open)throw _();if(!r&&d.kind===`protocol`&&d.name===`discovery`)return Ud(await ie(e,f,e.signal));if(d.kind===`protocol`&&typeof n[d.name]!=`function`)throw Vd(`no route: ${e.method} ${s.pathname}`);let p=r&&`platform`in r?o.caller:r,m=p?null:h(e,f),v=p??await g(m);if(d.kind===`board`)return await te(d.name,v,e,s,u.params);let y=await Up(d.name,e,s,u.params);if(d.name===`events`&&(e.headers.get(`accept`)??``).includes(`text/event-stream`))return await re(v,y,e,m?()=>g(m):null);let b=r&&`platform`in r?await L(d.name,r,y,e.signal):await z(d.name,v,y,e.signal);return d.name===`attachment`?Hp(b):Ud(b,Bp.has(d.name)?201:200)}catch(e){return Gd(e)}}return{dispatch:B,async inject(e,t,n,r){if(n!==null&&e.method===`POST`&&new URL(e.url).pathname.endsWith(`/messages`)){let t=await e.json()??{};t.id??=await Nd(`board-inbound`,n,`client`,String(r.made++)),e=new Request(e.url,{method:`POST`,headers:e.headers,body:JSON.stringify(t)})}return B(e,t)},async run(e,t,{trigger:n,attempt:r}){if(e===`@sync`&&o)return o.deliver(t,{attempt:r});let i=p[e];if(!i)throw Error(`this board has no watcher ${e}`);await i.run({event:t,board:f({self:e,origin:{via:{kind:`watcher`,id:e}}},n)})},async receive(e,t,{id:n,attempt:r}){if(!o)throw Error(`this board has no sync, so nothing reads ${e}'s inbox`);await o.receive(e,t,{id:n,attempt:r})},pull:()=>o?o.pull():Promise.resolve(0),async readSource(e,t,n){if(!o||!a[e])throw Vd(`this board doesn't run sync entry ${e}: read it where its sync runs`,`not_synced_here`);return o.readSource(e,t,n)},async joinSource(e,t){if(!o||!a[e])throw Vd(`this board doesn't run sync entry ${e}: join it where its sync runs`,`not_synced_here`);return o.joinSource(e,t)},typing:async(e,t)=>o?o.typing(e,t):[]}}function Yp(e,t){let n=e.backend??t.http(),r=Ap(e,n.keeps,t.serving),i=e.watch??{},a=e.sync??{},o={learned:null},s=`http://in-process.board${(e.basePath??``).replace(/\/+$/,``)}`;function c(){if(e.url)return e.url.replace(/\/+$/,``);let t=typeof process>`u`?void 0:process.env,n=t?.VERCEL_ENV===`production`?t.VERCEL_PROJECT_PRODUCTION_URL:t?.VERCEL_URL,r=e.basePath??o.learned;return n&&r!==null?`https://${n}${r}`.replace(/\/+$/,``):null}let l=null;function u(){return l??=Jp(_),l.catch(()=>l=null),l}function d(e,t){let n={made:0};return kd({url:s,token:`in-process`,fetch:(async(r,i)=>(await u()).inject(new Request(r,i),e,t,n))})}let f=async e=>(await u()).dispatch(e,null);function p(e,t){let n={...e,fetch:f,as:g};return t&&Object.defineProperty(n,"url",{get:t,enumerable:!0}),n}function m(e,t){let n=d(e,t);if(`identity`in e)return p({...n,events:(e,t)=>Xp(n,e,t)},()=>c()??s);let r=e.origin.via?.kind??`client`,i=t=>Nd(`board-${r===`watcher`?`watch`:r}`,e.self??``,t),a=async e=>typeof e==`string`||e.id===void 0?e:{...e,id:await i(e.id)};return p({...n,post:async(e,t)=>n.post(e,await a(t)),reply:async(e,t)=>n.reply(e,await a(t)),posted:async e=>n.posted(await i(e)),request:(e,t={})=>{let{as:r,...i}=t;return r===void 0?n.request(e,i):g(r).request(e,i)},events:(e,t)=>Xp(n,e,t)},()=>c()??s)}let h=e=>{let t=e===null?null:typeof e==`string`?e:e.name;return{self:t,profile:e,origin:{via:{kind:`client`,name:t}}}};function g(e){return m(h(e),null)}let _={options:e,backend:n,runtime:t,policy:r,state:o,ownUrl:c,clientAs:d,handleOf:m},v=Object.fromEntries(Object.entries(i).map(([e,t])=>[e,{kind:`tail`,tail:t.tail,when:t.when??`matches`}]));Object.keys(a).length>0&&(v[`@sync`]={kind:`sync`});let y=Object.entries(a).map(([e,t])=>({key:e,platform:t.platform,signIn:t.users!==null})),b={subscriptions:v,run:async(e,t,n)=>(await u()).run(e,t,n),receive:async(e,t,n)=>(await u()).receive(e,t,n),pull:async()=>y.length>0?(await u()).pull():0,sync:y,readSource:async(e,t,n)=>(await u()).readSource(e,t,n),joinSource:async(e,t)=>(await u()).joinSource(e,t),locate:e=>{let t=/* @__PURE__ */ new Map;for(let n of Object.values(a)){let r=n.locate(e);r&&t.set(JSON.stringify([n.platform,r.thread,r.message]),{platform:n.platform,...r})}return[...t.values()]},linkOf:async(e,t,n)=>{let r=Object.hasOwn(a,e)?a[e]:void 0;return!r||!t.startsWith(`${e}:`)?null:r.url(t.slice(e.length+1),n).catch(()=>null)},typing:async(e,t)=>(await u()).typing(e,t),accessNow:e=>r.accessNow(e),project:()=>r.project(),handle:e=>m(e,null),url:c};return n.bind(b),m({self:null,origin:{via:{kind:`client`,name:null}}},null)}async function*Xp(e,t={},n={}){let r=t.after,i=0;for(;!n.signal?.aborted;){let a;try{a=await e.poll({...t,...r===void 0?{}:{after:r},wait:25},n.signal)}catch(e){if(n.signal?.aborted)return;if(e instanceof yd&&e.status>=400&&e.status<500)throw e;await new Promise(e=>setTimeout(e,Math.min(3e4,500*2**i++)));continue}i=0;for(let e of a.events)if(yield e,n.signal?.aborted)return;r=a.cursor}}function Zp(e={}){return Yp(e,{http:()=>Mf(),sync:()=>import(`./engine.js`),serving:null})}const Qp={me:null,discovery:null,channels:{},messages:{},ops:{},pending:[],actors:{},cursor:null,live:`connecting`};function $p(e,t,n){switch(t.kind){case`react`:{let r=(e.reactions[Te(t.emoji)]??[]).includes(n);return t.remove?!r:r||e.deleted}case`edit`:return e.text===t.text||e.deleted;case`delete`:return e.deleted;case`label`:return e.deleted||Object.entries(t.set).every(([t,n])=>e.labels[t]===n)&&t.unset.every(t=>!(t in e.labels))}}function em(e,t,n,r){switch(t.kind){case`react`:{let r=Te(t.emoji),i=(e.reactions[r]??[]).filter(e=>e!==n),a={...e.reactions,[r]:t.remove?i:[...i,n]};return a[r].length===0&&delete a[r],{...e,reactions:a}}case`edit`:return{...e,text:t.text,editedAt:r};case`delete`:return{...e,deleted:!0,text:``,reactions:{},mentions:[]};case`label`:{let n={...e.labels,...t.set};for(let e of t.unset)delete n[e];return{...e,labels:n}}}}function tm(e,t){let n=e.messages,r=e.ops;for(let i of t){if((n[i.id]?.version??-1)>i.version)continue;n===e.messages&&(n={...n}),n[i.id]=i;let t=r[i.id];if(t&&e.me){let n=t.filter(({op:t})=>!$p(i,t,e.me.actor));n.length!==t.length&&(r={...r},n.length>0?r[i.id]=n:delete r[i.id])}}return n===e.messages&&r===e.ops?e:{...e,messages:n,ops:r}}function nm(e,t){if(t.by.actor===e.me?.actor)return e.pending.find(e=>e.error===null&&e.channel===t.channel&&e.re===t.re&&e.text===t.text)}function rm(e,t){let n=t.message?tm(e,[t.message]):e;if(t.type===`message.posted`&&t.message){let e=nm(n,t.message);e&&(n={...n,pending:n.pending.filter(t=>t!==e)});let{channel:r,re:i}=t.message,a=n.channels[r];(!a||a.lastIndex<t.message.version)&&(n={...n,channels:{...n.channels,[r]:{path:r,lastIndex:t.message.version,messages:(a?.messages??0)+1,threads:(a?.threads??0)+ +(i===null)}}})}if(t.type===`actor.seen`){let{actor:e,kind:r,handle:i,name:a,avatar:o}=t.payload;n={...n,actors:{...n.actors,[e]:{kind:ou(r),handle:i,name:a,avatar:o}}}}return{...n,cursor:t.cursor}}function im(e,t,n,r){return{...e,ops:{...e.ops,[t]:[...e.ops[t]??[],{id:n,op:r}]}}}function am(e,t,n){let r=(e.ops[t]??[]).filter(e=>e.id!==n),i={...e.ops};return r.length>0?i[t]=r:delete i[t],{...e,ops:i}}function om(e,t,n=(/* @__PURE__ */ new Date()).toISOString()){let r=e.messages[t];if(!r)return;let i=r;for(let{op:r}of e.ops[t]??[])i=em(i,r,e.me?.actor??``,n);let a=e.actors[r.by.actor];return a?{...i,author:a}:i}const sm=(e,t)=>e.createdAt<t.createdAt?-1:e.createdAt>t.createdAt?1:e.id.localeCompare(t.id,void 0,{numeric:!0});function cm(e,t){let n=[],r=/* @__PURE__ */ new Map;for(let i of Object.values(e.messages)){if(i.channel!==t)continue;let a=om(e,i.id);i.re===null?n.push(a):r.set(i.re,[...r.get(i.re)??[],a])}return n.sort(sm),{threads:n.map(t=>({root:t,replies:(r.get(t.id)??[]).sort(sm),pending:e.pending.filter(e=>e.re===t.id)})),pending:e.pending.filter(e=>e.channel===t&&e.re===null)}}function lm(e,t){let n=om(e,t);return n?{root:n,replies:Object.values(e.messages).filter(e=>e.re===t).sort(sm).map(t=>om(e,t.id)),pending:e.pending.filter(e=>e.re===t)}:null}function um(e,t=200,n=()=>!0){return Object.values(e.messages).filter(n).sort((e,t)=>sm(t,e)).slice(0,t).reverse().map(t=>om(e,t.id))}const dm=e=>!!(e.from||e.text||e.label.length);function fm(e,t){let n=t.indexOf(`=`);if(n===-1)return t in e;let r=t.slice(0,n);return r in e&&t.slice(n+1).split(`|`).includes(e[r])}function pm(e,t,n){if(n.from&&(t.from??`board`)!==n.from||n.text&&!t.text.toLowerCase().includes(n.text.toLowerCase()))return!1;let r=t.re===null?void 0:e.messages[t.re];return n.label.every(e=>fm(t.labels,e)||r!==void 0&&fm(r.labels,e))}function mm(e){let t=/* @__PURE__ */ new Map;for(let n of Object.values(e.messages))for(let[e,r]of Object.entries(n.labels)){let n=t.get(e);n||t.set(e,n=/* @__PURE__ */ new Set),n.add(r)}return t}const hm=(e,t)=>new Date(e).toDateString()===new Date(t).toDateString();function gm(e,t,n=!1){return!!e&&!n&&!e.deleted&&e.by.actor===t.by.actor&&e.channel===t.channel&&e.re===t.re&&hm(e.createdAt,t.createdAt)&&Date.parse(t.createdAt)-Date.parse(e.createdAt)<3e5}const _m=document.querySelector(`meta[name="inspect-token"]`)?.content??``;let vm=Qp;const ym=/* @__PURE__ */ new Set;function bm(e){let t=e(vm);if(t!==vm){vm=t;for(let e of ym)e()}}function xm(){return(0,O.useSyncExternalStore)(e=>(ym.add(e),()=>ym.delete(e)),()=>vm)}const Sm=()=>vm,Cm=`board.profile`;let wm=(()=>{try{let e=localStorage.getItem(Cm);return e===null?void 0:JSON.parse(e)}catch{return}})();const Tm=()=>wm,Em=Zp({backend:Mf(`${location.origin}/board`,{fetch:async(e,t)=>{let n=new Headers(t?.headers);n.set(`x-inspect-token`,_m),wm!==void 0&&n.set(`x-inspect-profile`,wm??``);let r=String(e).includes(`/board/events`);r&&bm(e=>e.live===`reconnecting`?e:{...e,live:`live`});try{let i=await fetch(e,{...t,headers:n});return r&&bm(e=>({...e,live:i.ok?`live`:`reconnecting`})),i}catch(e){throw r&&!t?.signal?.aborted&&bm(e=>({...e,live:`reconnecting`})),e}}})});async function Dm(e){let t=wm;wm=e;try{e===void 0?localStorage.removeItem(Cm):localStorage.setItem(Cm,JSON.stringify(e))}catch{}try{let e=await Em.me();bm(t=>({...t,me:e}))}catch(e){wm=t,Fm(`couldn't switch: ${Lm(e)}`)}}let Om=null;const km=/* @__PURE__ */ new Set;function Am(e){Om=e,km.forEach(e=>e())}function jm(){return(0,O.useSyncExternalStore)(e=>(km.add(e),()=>km.delete(e)),()=>Om)}let Mm=[];const Nm=/* @__PURE__ */ new Set;let Pm=0;function Fm(e){let t=++Pm;Mm=[...Mm,{id:t,text:e}],Nm.forEach(e=>e()),setTimeout(()=>{Mm=Mm.filter(e=>e.id!==t),Nm.forEach(e=>e())},6e3)}function Im(){return(0,O.useSyncExternalStore)(e=>(Nm.add(e),()=>Nm.delete(e)),()=>Mm)}const Lm=e=>e instanceof Error?e.message:String(e),Rm=/* @__PURE__ */ new Map;function zm(e,t){let n=Rm.get(e);return n||(n=t().catch(t=>{Rm.delete(e),Fm(Lm(t))}),Rm.set(e,n)),n}async function Bm(){let[e,t,n,r]=await Promise.all([Em.me(),Em.discovery().catch(()=>null),Em.channels(),Em.messages({limit:200})]);bm(i=>tm({...i,me:e,discovery:t,channels:Object.fromEntries(n.map(e=>[e.path,e])),cursor:r.cursor},r.messages)),Vm(r.cursor)}async function Vm(e){let t=[],n=!1,r=()=>{n=!1;let e=t;t=[],bm(t=>e.reduce(rm,t))};try{for await(let i of Em.events({all:!0,after:e}))t.push(i),n||(n=!0,requestAnimationFrame(r))}catch(e){bm(e=>({...e,live:`reconnecting`})),Fm(`live updates stopped: ${Lm(e)}`)}}const Hm=/* @__PURE__ */ new Set,Um=e=>zm(`channel:${e}`,async()=>{let t=await Em.messages({channel:e,limit:200});t.messages.length<200&&Hm.add(e),bm(e=>tm(e,t.messages))});async function Wm(e){let t=Object.values(vm.messages).filter(t=>t.channel===e).sort(sm)[0];if(Hm.has(e)||!t)return!1;try{let n=await Em.messages({channel:e,before:t.id,limit:200});return n.messages.length<200&&Hm.add(e),bm(e=>tm(e,n.messages)),!Hm.has(e)}catch(e){return Fm(Lm(e)),!0}}const Gm=e=>zm(`thread:${e}`,async()=>{let{message:t,replies:n}=await Em.thread(e);bm(e=>tm(e,[t,...n]))}),Km=e=>Em.inbox(e,{limit:100}),qm=(e,t)=>zm(`filtered:${e??`*`}:${JSON.stringify(t)}`,async()=>{let n=await Em.messages({...e?{channel:e}:{},...t.from?{from:t.from}:{},...t.text?{text:t.text}:{},...t.label.length>0?{label:t.label}:{},limit:200});bm(e=>tm(e,n.messages));let r=[...new Set(n.messages.flatMap(e=>e.re!==null&&!vm.messages[e.re]?[e.re]:[]))].slice(0,30);await Promise.all(r.map(e=>Gm(e)))}),Jm=/* @__PURE__ */ new Map;async function Ym(e,t=crypto.randomUUID()){let n=e.files??Jm.get(t)??[];Jm.set(t,n);let r={channel:e.channel,re:e.re,text:e.text,noSync:e.noSync,labels:e.labels,...n.length?{files:n.map(e=>({name:e.name,size:e.size}))}:{},key:t,createdAt:(/* @__PURE__ */ new Date()).toISOString(),error:null};bm(e=>({...e,pending:[...e.pending.filter(e=>e.key!==t),r]}));try{let r=await Promise.all(n.map(e=>Em.upload({data:e,name:e.name}))),i={text:e.text,id:t,...r.length?{attachments:r}:{},...e.noSync?{noSync:!0}:{},...Object.keys(e.labels).length>0?{labels:e.labels}:{}},a=e.re===null?await Em.post(e.channel,i):await Em.reply(e.re,i);Jm.delete(t),bm(e=>tm({...e,pending:e.pending.filter(e=>e.key!==t)},[a]))}catch(e){bm(n=>({...n,pending:n.pending.map(n=>n.key===t?{...n,error:Lm(e)}:n)}))}}const Xm=({files:e,...t})=>Ym(t,t.key),Zm=/* @__PURE__ */ new Map;function Qm(e){let t=Zm.get(e);return t||(t=Em.download(e).then(async e=>URL.createObjectURL(await e.blob())),t.catch(()=>Zm.delete(e)),Zm.set(e,t)),t}async function $m(e){try{let t=document.createElement(`a`);t.href=await Qm(e.id),t.download=e.name,t.click()}catch(t){Fm(`couldn't download ${e.name}: ${Lm(t)}`)}}const eh=e=>{Jm.delete(e),bm(t=>({...t,pending:t.pending.filter(t=>t.key!==e)}))};async function th(e,t,n){let r=crypto.randomUUID();bm(n=>im(n,e,r,t));try{await n(),setTimeout(()=>bm(t=>am(t,e,r)),8e3)}catch(t){bm(t=>am(t,e,r)),Fm(Lm(t))}}const nh=(e,t,n)=>th(e,{kind:`react`,emoji:t,remove:n},()=>Em.react(e,t,{remove:n})),rh=(e,t)=>th(e,{kind:`edit`,text:t},()=>Em.edit(e,t)),ih=e=>th(e,{kind:`delete`},()=>Em.delete(e)),ah=(e,t,n)=>th(e,{kind:`label`,set:t,unset:n},()=>Em.label(e,{set:t,unset:n}));function oh(e,t){return function(n,...r){let i=new URL(e);return i.searchParams.set(`code`,n.toString()),r.forEach(e=>i.searchParams.append(`args[]`,e)),`${t} error #${n}; visit ${i} for the full message.`}}const sh=oh(`https://base-ui.com/production-error`,`Base UI`);function ch({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=O.useRef(e!==void 0),[a,o]=O.useState(t);return[i&&e!==void 0?e:a,O.useCallback(e=>{i||o(e)},[])]}const J=typeof document<`u`?O.useLayoutEffect:()=>{};function lh(e){let t=O.useRef(!0);t.current&&(t.current=!1,e())}const uh={...O},dh={};function fh(e,t){let n=O.useRef(dh);return n.current===dh&&(n.current=e(t)),n}const ph=uh.useInsertionEffect,mh=ph&&ph!==uh.useLayoutEffect?ph:e=>e();function Y(e){let t=fh(hh).current;return t.next=e,mh(t.effect),t.trampoline}function hh(){let e={next:void 0,callback:gh,trampoline:(...t)=>e.callback?.(...t),effect:()=>{e.callback=e.next}};return e}function gh(){}function _h(e,t,n,r){let i=fh(yh).current;return bh(i,e,t,n,r)&&Sh(i,[e,t,n,r]),i.callback}function vh(e){let t=fh(yh).current;return xh(t,e)&&Sh(t,e),t.callback}function yh(){return{callback:null,cleanup:null,refs:[]}}function bh(e,t,n,r,i){return e.refs[0]!==t||e.refs[1]!==n||e.refs[2]!==r||e.refs[3]!==i}function xh(e,t){return e.refs.length!==t.length||e.refs.some((e,n)=>e!==t[n])}function Sh(e,t){if(e.refs=t,t.every(e=>e==null)){e.callback=null;return}e.callback=n=>{if(e.cleanup&&=(e.cleanup(),null),n!=null){let r=Array(t.length).fill(null);for(let e=0;e<t.length;e+=1){let i=t[e];if(i!=null)switch(typeof i){case`function`:{let t=i(n);typeof t==`function`&&(r[e]=t);break}case`object`:i.current=n}}e.cleanup=()=>{for(let e=0;e<t.length;e+=1){let n=t[e];if(n!=null)switch(typeof n){case`function`:{let t=r[e];typeof t==`function`?t():n(null);break}case`object`:n.current=null}}}}}}function Ch(e){let t=fh(wh,e).current;return t.next=e,J(t.effect),t}function wh(e){let t={current:e,next:e,effect:()=>{t.current=t.next}};return t}const Th={clipPath:`inset(50%)`,overflow:`hidden`,whiteSpace:`nowrap`,border:0,padding:0,width:1,height:1,margin:-1},Eh={...Th,position:`fixed`,top:0,left:0},Dh={...Th,position:`absolute`};
350
+ `);let r=a,o;for(;;){for(let e of r.events)s(`id: ${e.cursor}\nevent: board\ndata: ${JSON.stringify(e)}\n\n`);r.cursor!==(r.events.at(-1)?.cursor??o)&&s(`id: ${r.cursor}\n\n`),o=r.cursor;let a=l-Date.now();if(u.aborted||a<=0)break;r=await n.events(i?await i():e,{...t,after:o,wait:Math.min(300,a/1e3)},u)}}catch(e){u.aborted||console.error(`[board] feed failed`,e)}finally{clearInterval(c);try{r.close()}catch{}}},cancel(){c.abort()}});return new Response(d,{headers:{"content-type":`text/event-stream`,"cache-control":`no-cache, no-transform`,connection:`keep-alive`}})}async function ie(e,t,r){let{projectId:o,teamId:s}=await i.discoveryIdentity(e.headers),c=n.keeps?(await n.discovery(qp,{},r)).sync:Object.entries(a).map(([e,t])=>({key:e,platform:t.platform}));return{version:Kd,url:t,audience:t,team_id:s,project_id:o,sync:c}}async function B(e,r){try{let s=new URL(e.url),u=c(e.method,s.pathname);if(!u)throw Vd(`no route: ${e.method} ${s.pathname}`);let{target:d}=u;!r&&!u.root&&(l.learned===null||l.learned.startsWith(`${u.base}/`))&&(l.learned=u.base);let f=(t.url??`${s.origin}${u.base}`).replace(/\/+$/,``);if(d.kind===`board`&&d.name===`webhook`){if(!o||!a[u.params.key??``])throw Vd(`no sync entry named ${u.params.key}`);return await o.handleWebhook(u.params.key,e)}if(d.kind===`board`&&(d.name===`signIn`||d.name===`signedIn`))return await ee(d.name,s,e.signal);if(d.kind===`board`&&d.name===`avatar`){let e=u.param??``;if(!up.includes(e))throw Vd(`no avatar: ${e}`);return new Response(Np(e),{headers:{"content-type":`image/svg+xml`,"cache-control":`public, max-age=86400`}})}if(d.kind===`board`&&d.name===`openapi`)return Ud(nf());if(d.kind===`backend`)return await d.route.handle(e,{caller:r&&`platform`in r?o.caller:r,param:u.param});if(!r&&!i.open)throw _();if(!r&&d.kind===`protocol`&&d.name===`discovery`)return Ud(await ie(e,f,e.signal));if(d.kind===`protocol`&&typeof n[d.name]!=`function`)throw Vd(`no route: ${e.method} ${s.pathname}`);let p=r&&`platform`in r?o.caller:r,m=p?null:h(e,f),v=p??await g(m);if(d.kind===`board`)return await te(d.name,v,e,s,u.params);let y=await Up(d.name,e,s,u.params);if(d.name===`events`&&(e.headers.get(`accept`)??``).includes(`text/event-stream`))return await re(v,y,e,m?()=>g(m):null);let b=r&&`platform`in r?await L(d.name,r,y,e.signal):await z(d.name,v,y,e.signal);return d.name===`attachment`?Hp(b):Ud(b,Bp.has(d.name)?201:200)}catch(e){return Gd(e)}}return{dispatch:B,async inject(e,t,n,r){if(n!==null&&e.method===`POST`&&new URL(e.url).pathname.endsWith(`/messages`)){let t=await e.json()??{};t.id??=await Nd(`board-inbound`,n,`client`,String(r.made++)),e=new Request(e.url,{method:`POST`,headers:e.headers,body:JSON.stringify(t)})}return B(e,t)},async run(e,t,{trigger:n,attempt:r}){if(e===`@sync`&&o)return o.deliver(t,{attempt:r});let i=p[e];if(!i)throw Error(`this board has no watcher ${e}`);await i.run({event:t,board:f({self:e,origin:{via:{kind:`watcher`,id:e}}},n)})},async receive(e,t,{id:n,attempt:r}){if(!o)throw Error(`this board has no sync, so nothing reads ${e}'s inbox`);await o.receive(e,t,{id:n,attempt:r})},pull:()=>o?o.pull():Promise.resolve(0),async readSource(e,t,n,r){if(!o||!a[e])throw Vd(`this board doesn't run sync entry ${e}: read it where its sync runs`,`not_synced_here`);return o.readSource(e,t,n,r)},async joinSource(e,t){if(!o||!a[e])throw Vd(`this board doesn't run sync entry ${e}: join it where its sync runs`,`not_synced_here`);return o.joinSource(e,t)},typing:async(e,t)=>o?o.typing(e,t):[]}}function Yp(e,t){let n=e.backend??t.http(),r=Ap(e,n.keeps,t.serving),i=e.watch??{},a=e.sync??{},o={learned:null},s=`http://in-process.board${(e.basePath??``).replace(/\/+$/,``)}`;function c(){if(e.url)return e.url.replace(/\/+$/,``);let t=typeof process>`u`?void 0:process.env,n=t?.VERCEL_ENV===`production`?t.VERCEL_PROJECT_PRODUCTION_URL:t?.VERCEL_URL,r=e.basePath??o.learned;return n&&r!==null?`https://${n}${r}`.replace(/\/+$/,``):null}let l=null;function u(){return l??=Jp(_),l.catch(()=>l=null),l}function d(e,t){let n={made:0};return kd({url:s,token:`in-process`,fetch:(async(r,i)=>(await u()).inject(new Request(r,i),e,t,n))})}let f=async e=>(await u()).dispatch(e,null);function p(e,t){let n={...e,fetch:f,as:g};return t&&Object.defineProperty(n,"url",{get:t,enumerable:!0}),n}function m(e,t){let n=d(e,t);if(`identity`in e)return p({...n,events:(e,t)=>Xp(n,e,t)},()=>c()??s);let r=e.origin.via?.kind??`client`,i=t=>Nd(`board-${r===`watcher`?`watch`:r}`,e.self??``,t),a=async e=>typeof e==`string`||e.id===void 0?e:{...e,id:await i(e.id)};return p({...n,post:async(e,t)=>n.post(e,await a(t)),reply:async(e,t)=>n.reply(e,await a(t)),posted:async e=>n.posted(await i(e)),request:(e,t={})=>{let{as:r,...i}=t;return r===void 0?n.request(e,i):g(r).request(e,i)},events:(e,t)=>Xp(n,e,t)},()=>c()??s)}let h=e=>{let t=e===null?null:typeof e==`string`?e:e.name;return{self:t,profile:e,origin:{via:{kind:`client`,name:t}}}};function g(e){return m(h(e),null)}let _={options:e,backend:n,runtime:t,policy:r,state:o,ownUrl:c,clientAs:d,handleOf:m},v=Object.fromEntries(Object.entries(i).map(([e,t])=>[e,{kind:`tail`,tail:t.tail,when:t.when??`matches`}]));Object.keys(a).length>0&&(v[`@sync`]={kind:`sync`});let y=Object.entries(a).map(([e,t])=>({key:e,platform:t.platform,signIn:t.users!==null})),b={subscriptions:v,run:async(e,t,n)=>(await u()).run(e,t,n),receive:async(e,t,n)=>(await u()).receive(e,t,n),pull:async()=>y.length>0?(await u()).pull():0,sync:y,readSource:async(e,t,n,r)=>(await u()).readSource(e,t,n,r),joinSource:async(e,t)=>(await u()).joinSource(e,t),locate:e=>{let t=/* @__PURE__ */ new Map;for(let n of Object.values(a)){let r=n.locate(e);r&&t.set(JSON.stringify([n.platform,r.thread,r.message]),{platform:n.platform,...r})}return[...t.values()]},linkOf:async(e,t,n)=>{let r=Object.hasOwn(a,e)?a[e]:void 0;return!r||!t.startsWith(`${e}:`)?null:r.url(t.slice(e.length+1),n).catch(()=>null)},typing:async(e,t)=>(await u()).typing(e,t),accessNow:e=>r.accessNow(e),project:()=>r.project(),handle:e=>m(e,null),url:c};return n.bind(b),m({self:null,origin:{via:{kind:`client`,name:null}}},null)}async function*Xp(e,t={},n={}){let r=t.after,i=0;for(;!n.signal?.aborted;){let a;try{a=await e.poll({...t,...r===void 0?{}:{after:r},wait:25},n.signal)}catch(e){if(n.signal?.aborted)return;if(e instanceof yd&&e.status>=400&&e.status<500)throw e;await new Promise(e=>setTimeout(e,Math.min(3e4,500*2**i++)));continue}i=0;for(let e of a.events)if(yield e,n.signal?.aborted)return;r=a.cursor}}function Zp(e={}){return Yp(e,{http:()=>Mf(),sync:()=>import(`./engine.js`),serving:null})}const Qp={me:null,discovery:null,channels:{},messages:{},ops:{},pending:[],actors:{},cursor:null,live:`connecting`};function $p(e,t,n){switch(t.kind){case`react`:{let r=(e.reactions[Te(t.emoji)]??[]).includes(n);return t.remove?!r:r||e.deleted}case`edit`:return e.text===t.text||e.deleted;case`delete`:return e.deleted;case`label`:return e.deleted||Object.entries(t.set).every(([t,n])=>e.labels[t]===n)&&t.unset.every(t=>!(t in e.labels))}}function em(e,t,n,r){switch(t.kind){case`react`:{let r=Te(t.emoji),i=(e.reactions[r]??[]).filter(e=>e!==n),a={...e.reactions,[r]:t.remove?i:[...i,n]};return a[r].length===0&&delete a[r],{...e,reactions:a}}case`edit`:return{...e,text:t.text,editedAt:r};case`delete`:return{...e,deleted:!0,text:``,reactions:{},mentions:[]};case`label`:{let n={...e.labels,...t.set};for(let e of t.unset)delete n[e];return{...e,labels:n}}}}function tm(e,t){let n=e.messages,r=e.ops;for(let i of t){if((n[i.id]?.version??-1)>i.version)continue;n===e.messages&&(n={...n}),n[i.id]=i;let t=r[i.id];if(t&&e.me){let n=t.filter(({op:t})=>!$p(i,t,e.me.actor));n.length!==t.length&&(r={...r},n.length>0?r[i.id]=n:delete r[i.id])}}return n===e.messages&&r===e.ops?e:{...e,messages:n,ops:r}}function nm(e,t){if(t.by.actor===e.me?.actor)return e.pending.find(e=>e.error===null&&e.channel===t.channel&&e.re===t.re&&e.text===t.text)}function rm(e,t){let n=t.message?tm(e,[t.message]):e;if(t.type===`message.posted`&&t.message){let e=nm(n,t.message);e&&(n={...n,pending:n.pending.filter(t=>t!==e)});let{channel:r,re:i}=t.message,a=n.channels[r];(!a||a.lastIndex<t.message.version)&&(n={...n,channels:{...n.channels,[r]:{path:r,lastIndex:t.message.version,messages:(a?.messages??0)+1,threads:(a?.threads??0)+ +(i===null)}}})}if(t.type===`actor.seen`){let{actor:e,kind:r,handle:i,name:a,avatar:o}=t.payload;n={...n,actors:{...n.actors,[e]:{kind:ou(r),handle:i,name:a,avatar:o}}}}return{...n,cursor:t.cursor}}function im(e,t,n,r){return{...e,ops:{...e.ops,[t]:[...e.ops[t]??[],{id:n,op:r}]}}}function am(e,t,n){let r=(e.ops[t]??[]).filter(e=>e.id!==n),i={...e.ops};return r.length>0?i[t]=r:delete i[t],{...e,ops:i}}function om(e,t,n=(/* @__PURE__ */ new Date()).toISOString()){let r=e.messages[t];if(!r)return;let i=r;for(let{op:r}of e.ops[t]??[])i=em(i,r,e.me?.actor??``,n);let a=e.actors[r.by.actor];return a?{...i,author:a}:i}const sm=(e,t)=>e.createdAt<t.createdAt?-1:e.createdAt>t.createdAt?1:e.id.localeCompare(t.id,void 0,{numeric:!0});function cm(e,t){let n=[],r=/* @__PURE__ */ new Map;for(let i of Object.values(e.messages)){if(i.channel!==t)continue;let a=om(e,i.id);i.re===null?n.push(a):r.set(i.re,[...r.get(i.re)??[],a])}return n.sort(sm),{threads:n.map(t=>({root:t,replies:(r.get(t.id)??[]).sort(sm),pending:e.pending.filter(e=>e.re===t.id)})),pending:e.pending.filter(e=>e.channel===t&&e.re===null)}}function lm(e,t){let n=om(e,t);return n?{root:n,replies:Object.values(e.messages).filter(e=>e.re===t).sort(sm).map(t=>om(e,t.id)),pending:e.pending.filter(e=>e.re===t)}:null}function um(e,t=200,n=()=>!0){return Object.values(e.messages).filter(n).sort((e,t)=>sm(t,e)).slice(0,t).reverse().map(t=>om(e,t.id))}const dm=e=>!!(e.from||e.text||e.label.length);function fm(e,t){let n=t.indexOf(`=`);if(n===-1)return t in e;let r=t.slice(0,n);return r in e&&t.slice(n+1).split(`|`).includes(e[r])}function pm(e,t,n){if(n.from&&(t.from??`board`)!==n.from||n.text&&!t.text.toLowerCase().includes(n.text.toLowerCase()))return!1;let r=t.re===null?void 0:e.messages[t.re];return n.label.every(e=>fm(t.labels,e)||r!==void 0&&fm(r.labels,e))}function mm(e){let t=/* @__PURE__ */ new Map;for(let n of Object.values(e.messages))for(let[e,r]of Object.entries(n.labels)){let n=t.get(e);n||t.set(e,n=/* @__PURE__ */ new Set),n.add(r)}return t}const hm=(e,t)=>new Date(e).toDateString()===new Date(t).toDateString();function gm(e,t,n=!1){return!!e&&!n&&!e.deleted&&e.by.actor===t.by.actor&&e.channel===t.channel&&e.re===t.re&&hm(e.createdAt,t.createdAt)&&Date.parse(t.createdAt)-Date.parse(e.createdAt)<3e5}const _m=document.querySelector(`meta[name="inspect-token"]`)?.content??``;let vm=Qp;const ym=/* @__PURE__ */ new Set;function bm(e){let t=e(vm);if(t!==vm){vm=t;for(let e of ym)e()}}function xm(){return(0,O.useSyncExternalStore)(e=>(ym.add(e),()=>ym.delete(e)),()=>vm)}const Sm=()=>vm,Cm=`board.profile`;let wm=(()=>{try{let e=localStorage.getItem(Cm);return e===null?void 0:JSON.parse(e)}catch{return}})();const Tm=()=>wm,Em=Zp({backend:Mf(`${location.origin}/board`,{fetch:async(e,t)=>{let n=new Headers(t?.headers);n.set(`x-inspect-token`,_m),wm!==void 0&&n.set(`x-inspect-profile`,wm??``);let r=String(e).includes(`/board/events`);r&&bm(e=>e.live===`reconnecting`?e:{...e,live:`live`});try{let i=await fetch(e,{...t,headers:n});return r&&bm(e=>({...e,live:i.ok?`live`:`reconnecting`})),i}catch(e){throw r&&!t?.signal?.aborted&&bm(e=>({...e,live:`reconnecting`})),e}}})});async function Dm(e){let t=wm;wm=e;try{e===void 0?localStorage.removeItem(Cm):localStorage.setItem(Cm,JSON.stringify(e))}catch{}try{let e=await Em.me();bm(t=>({...t,me:e}))}catch(e){wm=t,Fm(`couldn't switch: ${Lm(e)}`)}}let Om=null;const km=/* @__PURE__ */ new Set;function Am(e){Om=e,km.forEach(e=>e())}function jm(){return(0,O.useSyncExternalStore)(e=>(km.add(e),()=>km.delete(e)),()=>Om)}let Mm=[];const Nm=/* @__PURE__ */ new Set;let Pm=0;function Fm(e){let t=++Pm;Mm=[...Mm,{id:t,text:e}],Nm.forEach(e=>e()),setTimeout(()=>{Mm=Mm.filter(e=>e.id!==t),Nm.forEach(e=>e())},6e3)}function Im(){return(0,O.useSyncExternalStore)(e=>(Nm.add(e),()=>Nm.delete(e)),()=>Mm)}const Lm=e=>e instanceof Error?e.message:String(e),Rm=/* @__PURE__ */ new Map;function zm(e,t){let n=Rm.get(e);return n||(n=t().catch(t=>{Rm.delete(e),Fm(Lm(t))}),Rm.set(e,n)),n}async function Bm(){let[e,t,n,r]=await Promise.all([Em.me(),Em.discovery().catch(()=>null),Em.channels(),Em.messages({limit:200})]);bm(i=>tm({...i,me:e,discovery:t,channels:Object.fromEntries(n.map(e=>[e.path,e])),cursor:r.cursor},r.messages)),Vm(r.cursor)}async function Vm(e){let t=[],n=!1,r=()=>{n=!1;let e=t;t=[],bm(t=>e.reduce(rm,t))};try{for await(let i of Em.events({all:!0,after:e}))t.push(i),n||(n=!0,requestAnimationFrame(r))}catch(e){bm(e=>({...e,live:`reconnecting`})),Fm(`live updates stopped: ${Lm(e)}`)}}const Hm=/* @__PURE__ */ new Set,Um=e=>zm(`channel:${e}`,async()=>{let t=await Em.messages({channel:e,limit:200});t.messages.length<200&&Hm.add(e),bm(e=>tm(e,t.messages))});async function Wm(e){let t=Object.values(vm.messages).filter(t=>t.channel===e).sort(sm)[0];if(Hm.has(e)||!t)return!1;try{let n=await Em.messages({channel:e,before:t.id,limit:200});return n.messages.length<200&&Hm.add(e),bm(e=>tm(e,n.messages)),!Hm.has(e)}catch(e){return Fm(Lm(e)),!0}}const Gm=e=>zm(`thread:${e}`,async()=>{let{message:t,replies:n}=await Em.thread(e);bm(e=>tm(e,[t,...n]))}),Km=e=>Em.inbox(e,{limit:100}),qm=(e,t)=>zm(`filtered:${e??`*`}:${JSON.stringify(t)}`,async()=>{let n=await Em.messages({...e?{channel:e}:{},...t.from?{from:t.from}:{},...t.text?{text:t.text}:{},...t.label.length>0?{label:t.label}:{},limit:200});bm(e=>tm(e,n.messages));let r=[...new Set(n.messages.flatMap(e=>e.re!==null&&!vm.messages[e.re]?[e.re]:[]))].slice(0,30);await Promise.all(r.map(e=>Gm(e)))}),Jm=/* @__PURE__ */ new Map;async function Ym(e,t=crypto.randomUUID()){let n=e.files??Jm.get(t)??[];Jm.set(t,n);let r={channel:e.channel,re:e.re,text:e.text,noSync:e.noSync,labels:e.labels,...n.length?{files:n.map(e=>({name:e.name,size:e.size}))}:{},key:t,createdAt:(/* @__PURE__ */ new Date()).toISOString(),error:null};bm(e=>({...e,pending:[...e.pending.filter(e=>e.key!==t),r]}));try{let r=await Promise.all(n.map(e=>Em.upload({data:e,name:e.name}))),i={text:e.text,id:t,...r.length?{attachments:r}:{},...e.noSync?{noSync:!0}:{},...Object.keys(e.labels).length>0?{labels:e.labels}:{}},a=e.re===null?await Em.post(e.channel,i):await Em.reply(e.re,i);Jm.delete(t),bm(e=>tm({...e,pending:e.pending.filter(e=>e.key!==t)},[a]))}catch(e){bm(n=>({...n,pending:n.pending.map(n=>n.key===t?{...n,error:Lm(e)}:n)}))}}const Xm=({files:e,...t})=>Ym(t,t.key),Zm=/* @__PURE__ */ new Map;function Qm(e){let t=Zm.get(e);return t||(t=Em.download(e).then(async e=>URL.createObjectURL(await e.blob())),t.catch(()=>Zm.delete(e)),Zm.set(e,t)),t}async function $m(e){try{let t=document.createElement(`a`);t.href=await Qm(e.id),t.download=e.name,t.click()}catch(t){Fm(`couldn't download ${e.name}: ${Lm(t)}`)}}const eh=e=>{Jm.delete(e),bm(t=>({...t,pending:t.pending.filter(t=>t.key!==e)}))};async function th(e,t,n){let r=crypto.randomUUID();bm(n=>im(n,e,r,t));try{await n(),setTimeout(()=>bm(t=>am(t,e,r)),8e3)}catch(t){bm(t=>am(t,e,r)),Fm(Lm(t))}}const nh=(e,t,n)=>th(e,{kind:`react`,emoji:t,remove:n},()=>Em.react(e,t,{remove:n})),rh=(e,t)=>th(e,{kind:`edit`,text:t},()=>Em.edit(e,t)),ih=e=>th(e,{kind:`delete`},()=>Em.delete(e)),ah=(e,t,n)=>th(e,{kind:`label`,set:t,unset:n},()=>Em.label(e,{set:t,unset:n}));function oh(e,t){return function(n,...r){let i=new URL(e);return i.searchParams.set(`code`,n.toString()),r.forEach(e=>i.searchParams.append(`args[]`,e)),`${t} error #${n}; visit ${i} for the full message.`}}const sh=oh(`https://base-ui.com/production-error`,`Base UI`);function ch({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=O.useRef(e!==void 0),[a,o]=O.useState(t);return[i&&e!==void 0?e:a,O.useCallback(e=>{i||o(e)},[])]}const J=typeof document<`u`?O.useLayoutEffect:()=>{};function lh(e){let t=O.useRef(!0);t.current&&(t.current=!1,e())}const uh={...O},dh={};function fh(e,t){let n=O.useRef(dh);return n.current===dh&&(n.current=e(t)),n}const ph=uh.useInsertionEffect,mh=ph&&ph!==uh.useLayoutEffect?ph:e=>e();function Y(e){let t=fh(hh).current;return t.next=e,mh(t.effect),t.trampoline}function hh(){let e={next:void 0,callback:gh,trampoline:(...t)=>e.callback?.(...t),effect:()=>{e.callback=e.next}};return e}function gh(){}function _h(e,t,n,r){let i=fh(yh).current;return bh(i,e,t,n,r)&&Sh(i,[e,t,n,r]),i.callback}function vh(e){let t=fh(yh).current;return xh(t,e)&&Sh(t,e),t.callback}function yh(){return{callback:null,cleanup:null,refs:[]}}function bh(e,t,n,r,i){return e.refs[0]!==t||e.refs[1]!==n||e.refs[2]!==r||e.refs[3]!==i}function xh(e,t){return e.refs.length!==t.length||e.refs.some((e,n)=>e!==t[n])}function Sh(e,t){if(e.refs=t,t.every(e=>e==null)){e.callback=null;return}e.callback=n=>{if(e.cleanup&&=(e.cleanup(),null),n!=null){let r=Array(t.length).fill(null);for(let e=0;e<t.length;e+=1){let i=t[e];if(i!=null)switch(typeof i){case`function`:{let t=i(n);typeof t==`function`&&(r[e]=t);break}case`object`:i.current=n}}e.cleanup=()=>{for(let e=0;e<t.length;e+=1){let n=t[e];if(n!=null)switch(typeof n){case`function`:{let t=r[e];typeof t==`function`?t():n(null);break}case`object`:n.current=null}}}}}}function Ch(e){let t=fh(wh,e).current;return t.next=e,J(t.effect),t}function wh(e){let t={current:e,next:e,effect:()=>{t.current=t.next}};return t}const Th={clipPath:`inset(50%)`,overflow:`hidden`,whiteSpace:`nowrap`,border:0,padding:0,width:1,height:1,margin:-1},Eh={...Th,position:`fixed`,top:0,left:0},Dh={...Th,position:`absolute`};
351
351
  /**
352
352
  * @license React
353
353
  * use-sync-external-store-shim.production.js