bluma-cli 0.1.0 → 0.2.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 (3) hide show
  1. package/README.md +12 -1
  2. package/dist/bluma.js +46 -86
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -43,7 +43,18 @@ bluma today
43
43
  bluma done <id>
44
44
  ```
45
45
 
46
- For scripts and agents, use an API token instead: `bluma login --token blm_...`, or set `BLUMA_TOKEN`. `BLUMA_URL` points the CLI at your own server. Run `bluma --help` for every command.
46
+ For scripts and agents, use an API token instead: `bluma login --token blm_...`, or set `BLUMA_TOKEN`. Make one while signed in with your email: `bluma token add "claude code"`, with `--read-only` for a token that cannot change anything and `--expires 30d` (or `90d`, or any number of days up to 365) for one that stops working by itself. An API token cannot make another token. `BLUMA_URL` points the CLI at your own server. Run `bluma --help` for every command.
47
+
48
+ ## Files on to-dos
49
+
50
+ ```sh
51
+ bluma attach <task> screenshot.png build.log # up to 25 MB each, 20 per to-do
52
+ bluma attachments <task> # the files and their ids
53
+ bluma attachment get <id> # saved here under its own name; -o <path>, --force to overwrite
54
+ bluma attachment rm <id>
55
+ ```
56
+
57
+ An agent connected over MCP reads these with `read_attachment` and can attach its own output with `attach_file`. `attachment get` never writes outside the current folder unless you pass `-o`, and never overwrites a file without `--force`.
47
58
 
48
59
  ## Importing from Things
49
60
 
package/dist/bluma.js CHANGED
@@ -1,87 +1,35 @@
1
1
  #!/usr/bin/env node
2
- var Oa=Object.defineProperty;var Ca=(e)=>e;function Aa(e,t){this[e]=Ca.bind(null,t)}var Ea=(e,t)=>{for(var r in t)Oa(e,r,{get:t[r],enumerable:!0,configurable:!0,set:Aa.bind(t,r)})};var Dr={};Ea(Dr,{bigint:()=>Bl,boolean:()=>Fl,date:()=>Jl,number:()=>Ul,string:()=>Ml});import{parseArgs as Mp}from"node:util";function Te(e){let t=Object.values(e).filter((n)=>typeof n==="number");return Object.entries(e).filter(([n,o])=>t.indexOf(+n)===-1).map(([n,o])=>o)}function Ft(e,t="|"){return e.map((r)=>Kt(r)).join(t)}function Ze(e,t){if(typeof t==="bigint")return t.toString();return t}class Xr{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;if(e!==void 0)this._value=e(),this._getter=void 0;return this._value}}function Ie(e){return new Xr(e)}function Qr(e){return e===null||e===void 0}function We(e){let t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}function en(e,t){let r=e/t,n=Math.round(r),o=4*Number.EPSILON*Math.max(Math.abs(r),1);if(Math.abs(r-n)<o)return 0;return r-n}function V(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function Oe(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function te(e){return Oe(e._zod.def)??e._zod.def.shape}function tn(e,t,r){Object.defineProperty(e,t,{get(){let n=r();return V(this,t,n),n},enumerable:!0,configurable:!0})}function rn(e,t,r){if(t in e)V(e,t,r);else e[t]=r}function pe(e,t,r,n){let o=te(t);for(let i of r){let s=Object.getOwnPropertyDescriptor(o,i);if(!s.enumerable)continue;if(s.get)tn(e,i,()=>{let c=t._zod.def.shape[i];return n?n(c,i):c});else rn(e,i,n?n(s.value,i):s.value)}}function ja(e,t){for(let r of Reflect.ownKeys(t)){let n=Object.getOwnPropertyDescriptor(t,r);if(!n.enumerable)continue;if(n.get)tn(e,r,()=>t[r]);else rn(e,r,n.value)}}function M(...e){let t={};for(let r of e){let n=Object.getOwnPropertyDescriptors(r);Object.assign(t,n)}return Object.defineProperties({},t)}function nn(e){return JSON.stringify(e)}function on(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var Bt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function me(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var sn=Ie(()=>{if(U.jitless)return!1;if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function he(e){if(me(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;if(typeof t!=="function")return!0;let r=t.prototype;if(me(r)===!1)return!1;if(Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)return!1;return!0}function Jt(e){if(he(e))return{...e};if(Array.isArray(e))return[...e];if(e instanceof Map)return new Map(e);if(e instanceof Set)return new Set(e);return e}var cn=new Set(["string","number","symbol"]);function ce(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function q(e,t,r){let n=new e._zod.constr(t??e._zod.def);if(!t||r?.parent)n._zod.parent=e;return n}function g(e){let t=e;if(!t)return{};if(typeof t==="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function Kt(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function an(e){return Object.keys(e).filter((t)=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}var Ge=(()=>({safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]}))(),Vt={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function Na(e,t){let r=e._zod.def,n=r.checks;if(n&&n.length>0)throw Error(".pick() cannot be used on object schemas containing refinements");let i={};return pe(i,e,He(e,t)),q(e,M(r,{shape:i,checks:[]}))}function He(e,t){let r=te(e),n=[];for(let o of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(r,o)?.enumerable)throw Error(`Unrecognized key: "${String(o)}"`);if(t[o])n.push(o)}return n}function Ra(e,t){let r=e._zod.def,n=r.checks;if(n&&n.length>0)throw Error(".omit() cannot be used on object schemas containing refinements");let i=new Set(He(e,t)),s={};return pe(s,e,Reflect.ownKeys(te(e)).filter((c)=>!i.has(c))),q(e,M(r,{shape:s,checks:[]}))}function Da(e,t){if(!he(t))throw Error("Invalid input to extend: expected a plain object");let r=e._zod.def.checks;if(r&&r.length>0){let o=te(e);for(let i of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(o,i)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return q(e,M(e._zod.def,{shape:un(e,t)}))}function un(e,t){let r={};return pe(r,e,Reflect.ownKeys(te(e))),ja(r,t),r}function La(e,t){if(!he(t))throw Error("Invalid input to safeExtend: expected a plain object");return q(e,M(e._zod.def,{shape:un(e,t)}))}function Ma(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");let r={};pe(r,e,Reflect.ownKeys(te(e))),pe(r,t,Reflect.ownKeys(te(t)));let n=M(e._zod.def,{shape:r,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return q(e,n)}function ln(e,t,r,n="partial"){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${n}() cannot be used on object schemas containing refinements`);let c=r?new Set(He(t,r)):void 0,a={};return pe(a,t,Reflect.ownKeys(te(t)),e&&((u,l)=>c&&!c.has(l)?u:new e({type:"optional",innerType:u}))),q(t,M(t._zod.def,{shape:a,checks:[]}))}function Ua(e,t,r){let n=r?new Set(He(t,r)):void 0,o={};return pe(o,t,Reflect.ownKeys(te(t)),(i,s)=>n&&!n.has(s)?i:new e({type:"nonoptional",innerType:i})),q(t,M(t._zod.def,{shape:o}))}function X(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function pn(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}function Ye(e,t){return t.map((r)=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(e),r})}function Se(e){return typeof e==="string"?e:e?.message}function Wt(e){let t=[];for(let r of e??[]){let n=r._zod.def;if(!/_(length|size)$|_equals$/.test(n.check))break;let o=n.maximum??n.length??n.size;if(o>=0)t.push([o,r])}return t}function qe(e,t,r){var n;for(let o=t;o<e.length;o++)(n=e[o]).schema??(n.schema=r)}function ae(e,t,r){var n;let o=e.inst?._zod?.traits;if(o?.has("$ZodType"))if(o.has("$ZodCheck"))(n=e).schema??(n.schema=e.inst);else e.schema=e.inst;let i=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,s=e.message?e.message:Se(e.inst?._zod.def?.error?.(e))??Se(i?.(e))??Se(t?.error?.(e))??Se(r.customError?.(e))??Se(r.localeError?.(e))??"Invalid input",c={};for(let a of Object.keys(e)){if(a==="inst"||a==="schema"||a==="continue"||a==="input"||a==="__proto__")continue;c[a]=e[a]}if(c.path??(c.path=[]),c.message=s,t?.reportInput)c.input=e.input;return c}var Fa=/[\uD800-\uDBFF]/;function Xe(e){let t=e.length;if(!Fa.test(e))return t;let r=t;for(let n=0;n<t-1;n++)if((e.charCodeAt(n)&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320)r--,n++;return r}function Qe(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function dn(e){let t=typeof e;switch(t){case"number":return Number.isNaN(e)?"nan":"number";case"object":{if(e===null)return"null";if(Array.isArray(e))return"array";let r=e;if(r&&Object.getPrototypeOf(r)!==Object.prototype&&"constructor"in r&&r.constructor)return r.constructor.name}}return t}function de(...e){let[t,r,n]=e;if(typeof t==="string")return{message:t,code:"custom",input:r,inst:n};return{...t}}function fn(e,t){for(let r in t){let n=Object.getOwnPropertyDescriptor(t,r);if(n.get)Object.defineProperty(e,r,{...n,enumerable:!1});else Ba(e,r,n.value)}}function re(e,t,r,n=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:n,value:r}),r}function et(e,t,r){return re(e,t,r,!1)}function tt(e,t){for(let r in e){let n=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return re(this,r,n(this))},set(o){re(this,r,o)}})}return t}function Ba(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:re(this,t,r.bind(this))},set(n){re(this,t,n)}})}function Ja(e,t){let r=Object.getPrototypeOf(e);return t in r?void 0:r}var Ut,se=!1,Ka={configurable:!0,get(){se=!0;return}};function v(e,t,r){let n=Object.getPrototypeOf(e._zod);if(t in n&&Ut!==e._zod){Ut=void 0;return}Ut=e._zod,Object.defineProperty(n,t,{configurable:!0,get(){Object.defineProperty(this,t,Ka);let o=se;se=!1;try{let i=r(this);if(se)delete this[t];else Object.defineProperty(this,t,{configurable:!0,writable:!0,value:i});return se=se||o,i}catch(i){throw delete this[t],se=se||o,i}},set(o){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:o})}})}function Va(e,t,r,n){let o=Ja(e,t);if(!o)return;Object.defineProperty(o,t,{configurable:!0,get(){let i={configurable:!0,writable:!0,enumerable:n,value:void 0};return Object.defineProperty(this,t,i),i.value=r(this),Object.defineProperty(this,t,i),i.value},set(i){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:n,value:i})}})}var Wa="~constantCatch";function mn(e){let t=()=>e;return t[Wa]=!0,t}var hn;var Gt={value:void 0,enumerable:!1},gn="captureStackTrace"in Error?Error:null;function Ga(e){let t=gn;if(t){let r=t.stackTraceLimit;if(typeof r==="number"){try{t.stackTraceLimit=0}catch{return gn=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}function p(e,t,r,n){let o={};function i(f){this.def=f,this.constr=d,this.traits=new Set}i.prototype=o;let s=r,c=s&&new WeakSet;function a(f,m){if(!f._zod){Gt.value=new i(m);try{Object.defineProperty(f,"_zod",Gt)}finally{Gt.value=void 0}}else if(f._zod.traits.has(e))return;if(f._zod.traits.add(e),t(f,m),c){let b=Object.getPrototypeOf(f),_=f._zod.constr.prototype,k=b;while(k&&k!==_)k=Object.getPrototypeOf(k);let R=k??b;if(!c.has(R))c.add(R),fn(R,s)}let h=d.prototype;for(let b in h){if(!Object.prototype.hasOwnProperty.call(h,b))continue;if(!(b in f))f[b]=h[b].bind(f)}}let u=n?.Parent??Object;class l extends u{}Object.defineProperty(l,"name",{value:e});function d(f){let m=n?.Parent?Ga(l):this;a(m,f);let h=m._zod.deferred;if(h){for(let _ of h)_();m._zod.deferred=void 0}let b=globalThis.__zod_globalConfig?.postProcessor;if(b)b(m);return m}return Object.defineProperty(d,"init",{value:a}),Object.defineProperty(d,Symbol.hasInstance,{value:(f)=>{if(n?.Parent&&f instanceof n.Parent)return!0;return f?._zod?.traits?.has(e)}}),Object.defineProperty(d,"name",{value:e}),d}class Q extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Ce extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}(hn=globalThis).__zod_globalConfig??(hn.__zod_globalConfig={});var U=globalThis.__zod_globalConfig;function G(e){if(e)Object.assign(U,e);return U}function Ha(){let e=this._zod;return e.message??(e.message=JSON.stringify(e.def,Ze,2)),e.message}function Ya(e){this._zod.message=e}var qa={get:Ha,set:Ya,enumerable:!0,configurable:!0},Yt={value:void 0,enumerable:!1},yn=new WeakSet([Object.prototype,Error.prototype]),_n=(e,t)=>{e.name="$ZodError",Yt.value=t,Object.defineProperty(e,"issues",Yt),Yt.value=void 0,Object.defineProperty(e,"message",qa);let r=Object.getPrototypeOf(e);if(!yn.has(r))yn.add(r),Object.defineProperty(r,"toString",{configurable:!0,enumerable:!1,get(){let n=()=>this.message;return Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0})}})},bn=p("$ZodError",_n),Gp=p("$ZodError",_n,void 0,{Parent:Error});function Xa(e,t,r){if(!Object.prototype.hasOwnProperty.call(e,t))if(t==="__proto__")Object.defineProperty(e,t,{value:r(),writable:!0,enumerable:!0,configurable:!0});else e[t]=r();return e[t]}function xn(e,t=(r)=>r.message){let r={},n=[];for(let o of e.issues)if(o.path.length>0)Xa(r,o.path[0],()=>[]).push(t(o));else n.push(t(o));return{formErrors:n,fieldErrors:r}}function vn(e,t=(r)=>r.message){let r={_errors:[]},n=(o,i=[])=>{for(let s of o.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map((c)=>n({issues:c},[...i,...s.path]));else if(s.code==="invalid_key")n({issues:s.issues},[...i,...s.path]);else if(s.code==="invalid_element")n({issues:s.issues},[...i,...s.path]);else{let c=[...i,...s.path];if(c.length===0)r._errors.push(t(s));else{let a=r,u=0;while(u<c.length){let l=c[u],d=u===c.length-1;if(l==="_errors"){if(d)a._errors.push(t(s));u++;continue}if(!Object.prototype.hasOwnProperty.call(a,l))Object.defineProperty(a,l,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let f=a[l];if(d)f._errors.push(t(s));a=f,u++}}}};return n(e),r}function rt(e,t){return{callee:t?.callee??e,Err:t?.Err}}var nt=(e)=>{let t=(r,n,o,i)=>{let s=o?{...o,async:!1}:{async:!1},c=r._zod.run({value:n,issues:[]},s);if(c instanceof Promise)throw new Q;if(c.issues.length){let a=new(i?.Err??e)(c.issues.map((u)=>ae(u,s,G())));throw Bt(a,i?.callee??t),a}return c.value};return t};var ot=(e)=>{let t=async(r,n,o,i)=>{let s=o?{...o,async:!0}:{async:!0},c=r._zod.run({value:n,issues:[]},s);if(c instanceof Promise)c=await c;if(c.issues.length){let a=new(i?.Err??e)(c.issues.map((u)=>ae(u,s,G())));throw Bt(a,i?.callee??t),a}return c.value};return t};var it=(e)=>(t,r,n)=>{let o=n?{...n,async:!1}:{async:!1},i=t._zod.run({value:r,issues:[]},o);if(i instanceof Promise)throw new Q;return i.issues.length?wn(e,i.issues,o):{success:!0,data:i.value}};function wn(e,t,r){let n;return{success:!1,get error(){if(!n)n=new e(t.map((o)=>ae(o,r,G()))),t=void 0,r=void 0;return n},set error(o){n=o,t=void 0,r=void 0}}}var st=(e)=>async(t,r,n)=>{let o=n?{...n,async:!0}:{async:!0},i=t._zod.run({value:r,issues:[]},o);if(i instanceof Promise)i=await i;return i.issues.length?wn(e,i.issues,o):{success:!0,data:i.value}};var Qa=Symbol.for("zod.compile.invalid"),eu=Symbol.for("zod.compile.fallback"),qt=(e,t,r)=>{let n=e._zod.bag.validator;if(n!==void 0){if(n(t)!==Qa)return!0;if(n.definite===!0&&r===void 0)return!1}return tu(e,t,r)};function tu(e,t,r){let n=r?{...r,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},o=e._zod.bag.fallbackRun,i;if(o)n[eu]=!0,i=o({value:t,issues:[]},n);else i=e._zod.run({value:t,issues:[]},n);if(i instanceof Promise)throw new Q;return i.issues.length===0}var Xt=async(e,t,r)=>{let n=r?{...r,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},o=e._zod.run({value:t,issues:[]},n);if(o instanceof Promise)o=await o;return o.issues.length===0},kn=(e)=>{let t=nt(e),r=(n,o,i,s)=>{let c=i?{...i,direction:"backward"}:{direction:"backward"};return t(n,o,c,rt(r,s))};return r};var $n=(e)=>{let t=nt(e),r=(n,o,i,s)=>t(n,o,i,rt(r,s));return r};var zn=(e)=>{let t=ot(e),r=async(n,o,i,s)=>{let c=i?{...i,direction:"backward"}:{direction:"backward"};return await t(n,o,c,rt(r,s))};return r};var Pn=(e)=>{let t=ot(e),r=async(n,o,i,s)=>await t(n,o,i,rt(r,s));return r};var Sn=(e)=>(t,r,n)=>{let o=n?{...n,direction:"backward"}:{direction:"backward"};return it(e)(t,r,o)};var Tn=(e)=>(t,r,n)=>it(e)(t,r,n);var Zn=(e)=>async(t,r,n)=>{let o=n?{...n,direction:"backward"}:{direction:"backward"};return st(e)(t,r,o)};var In=(e)=>async(t,r,n)=>st(e)(t,r,n);var On=/^[cC][0-9a-z]{6,}$/,Cn=/^[0-9a-z]+$/,An=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,En=/^[0-9a-vA-V]{20}$/,jn=/^[A-Za-z0-9]{27}$/,Nn=/^[a-zA-Z0-9_-]{21}$/;function Rn(e){return new RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}var Dn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Ln=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,er=(e)=>{if(!e)return/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`)};var Mn=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var ru="^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$";function Un(){return new RegExp(ru,"u")}var Fn=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Bn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;var Jn=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Kn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Vn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Wn=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;var Gn=/^https?$/,Hn=/^\+[1-9]\d{6,14}$/;var Yn="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))";function nu(e){return new RegExp(`^${e}$`)}var qn=nu(Yn);function Qt(e){return typeof e.precision==="number"?e.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":e.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?":"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function Xn(e){return new RegExp(`^${Qt(e)}$`)}function Qn(e){let t=["Z"];if(e.offset)t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let r=`${Qt({precision:e.precision,seconds:!0})}(?:${t.join("|")})`,n=e.local?`${r}|${Qt({precision:e.precision})}`:r;return new RegExp(`^${Yn}T(?:${n})$`)}var eo=/^[\s\S]{0,}$/;var to=/^-?\d+n?$/;var tr=/^-?\d+(?:\.\d+)?$/,ro=/^(?:true|false)$/i;var no=/^[^A-Z]*$/,oo=/^[^a-z]*$/;var A=p("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])});var rr=(e)=>{let t=e.value;return!Qr(t)&&t.length!==void 0},ct={number:"number",bigint:"bigint",object:"date"},nr=p("$ZodCheckLessThan",(e,t)=>{A.init(e,t);let r=ct[typeof t.value];e._zod.check=(n)=>{if(t.inclusive?n.value<=t.value:n.value<t.value)return;n.issues.push({origin:ct[typeof n.value]??r,code:"too_big",maximum:typeof t.value==="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),or=p("$ZodCheckGreaterThan",(e,t)=>{A.init(e,t);let r=ct[typeof t.value];e._zod.check=(n)=>{if(t.inclusive?n.value>=t.value:n.value>t.value)return;n.issues.push({origin:ct[typeof n.value]??r,code:"too_small",minimum:typeof t.value==="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),io=p("$ZodCheckMultipleOf",(e,t)=>{A.init(e,t),e._zod.check=(r)=>{if(typeof r.value!==typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");if(typeof r.value==="bigint"?t.value!==BigInt(0)&&r.value%t.value===BigInt(0):en(r.value,t.value)===0)return;r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),so=p("$ZodCheckNumberFormat",(e,t)=>{A.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),n=r?"int":"number",[o,i]=Ge[t.format];e._zod.check=(s)=>{let c=s.value;if(r){if(!Number.isInteger(c)){s.issues.push({expected:n,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){if(c>0)s.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort});else s.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort});return}}if(c<o)s.issues.push({origin:"number",input:c,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort});if(c>i)s.issues.push({origin:"number",input:c,code:"too_big",maximum:i,inclusive:!0,inst:e,continue:!t.abort})}});var co=p("$ZodCheckMaxLength",(e,t)=>{var r;A.init(e,t),(r=e._zod.def).when??(r.when=rr),e._zod.check=(n)=>{let o=n.value,i=o.length;if((typeof o==="string"&&i>t.maximum?Xe(o):i)<=t.maximum)return;let c=Qe(o);n.issues.push({origin:c,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),ao=p("$ZodCheckMinLength",(e,t)=>{var r;A.init(e,t),(r=e._zod.def).when??(r.when=rr),e._zod.check=(n)=>{let o=n.value,i=o.length;if((typeof o==="string"&&i>=t.minimum&&i<t.minimum*2?Xe(o):i)>=t.minimum)return;let c=Qe(o);n.issues.push({origin:c,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),uo=p("$ZodCheckLengthEquals",(e,t)=>{var r;A.init(e,t),(r=e._zod.def).when??(r.when=rr),e._zod.check=(n)=>{let o=n.value,i=o.length,s=typeof o==="string"&&i>=t.length&&i<=t.length*2?Xe(o):i;if(s===t.length)return;let c=Qe(o),a=s>t.length;n.issues.push({origin:c,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Ee=p("$ZodCheckStringFormat",(e,t)=>{var r,n;if(A.init(e,t),t.pattern)(r=e._zod).check??(r.check=(o)=>{if(t.pattern.lastIndex=0,t.pattern.test(o.value))return;o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})});else(n=e._zod).check??(n.check=()=>{})}),lo=p("$ZodCheckRegex",(e,t)=>{Ee.init(e,t),e._zod.check=(r)=>{if(t.pattern.lastIndex=0,t.pattern.test(r.value))return;r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),po=p("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=no),Ee.init(e,t)}),fo=p("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=oo),Ee.init(e,t)}),mo=p("$ZodCheckIncludes",(e,t)=>{A.init(e,t);let r=ce(t.includes),n=new RegExp(typeof t.position==="number"?`^.{${t.position},}${r}`:r);t.pattern=n,e._zod.check=(o)=>{if(o.value.includes(t.includes,t.position))return;o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),ho=p("$ZodCheckStartsWith",(e,t)=>{A.init(e,t);let r=new RegExp(`^${ce(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.check=(n)=>{if(n.value.startsWith(t.prefix))return;n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),go=p("$ZodCheckEndsWith",(e,t)=>{A.init(e,t);let r=new RegExp(`.*${ce(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.check=(n)=>{if(n.value.endsWith(t.suffix))return;n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}});var yo=p("$ZodCheckOverwrite",(e,t)=>{A.init(e,t),e._zod.check=(r)=>{r.value=t.tx(r.value)}});class ir{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{this.indent-=1}}write(e){if(typeof e==="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let r=e.split(`
3
- `).filter((i)=>i),n=Math.min(...r.map((i)=>i.length-i.trimStart().length)),o=r.map((i)=>i.slice(n)).map((i)=>" ".repeat(this.indent*2)+i);for(let i of o)this.content.push(i)}compile(){let e=Function,t=this?.content??[""];return new e(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
4
- ${t.join(`
5
- `)}
6
- };`)(...Object.values(this.closed))}}var bo={major:4,minor:6,patch:7};var P=p("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=bo;let n=e._zod.def.checks,o=e._zod.traits.has("$ZodCheck")?[e,...n??[]]:n?.length?[...n]:[];for(let i of o)for(let s of i._zod.onattach)s(e);if(o.length===0)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let i=(c,a,u)=>{if(c.memo)return c;let l=X(c),d;for(let f of a){if(f._zod.def.when){if(pn(c))continue;if(!f._zod.def.when(c))continue}else if(l)continue;let m=c.issues.length,h=f._zod.check(c);if(h instanceof Promise&&u?.async===!1)throw new Q;if(d||h instanceof Promise)d=(d??Promise.resolve()).then(async()=>{if(await h,c.issues.length===m)return;if(qe(c.issues,m,e),!l)l=X(c,m)});else{if(c.issues.length===m)continue;if(qe(c.issues,m,e),!l)l=X(c,m)}}if(d)return d.then(()=>c);return c},s=(c,a,u)=>{if(X(c))return c.aborted=!0,c;let l=i(a,o,u);if(l instanceof Promise){if(u.async===!1)throw new Q;return l.then((d)=>e._zod.parse(d,u))}return e._zod.parse(l,u)};e._zod.run=(c,a)=>{if(a.skipChecks)return e._zod.parse(c,a);if(a.direction==="backward"){let l=e._zod.parse({value:c.value,issues:[]},{...a,skipChecks:!0});if(l instanceof Promise)return l.then((d)=>s(d,c,a));return s(l,c,a)}let u=e._zod.parse(c,a);if(u instanceof Promise){if(a.async===!1)throw new Q;return u.then((l)=>i(l,o,a))}return i(u,o,a)}}},{get "~standard"(){return et(this,"~standard",cr(this))},set "~standard"(e){re(this,"~standard",e)}}),Io=(e,t)=>e.issues.length?{issues:e.issues.map((r)=>ae(r,t,G()))}:{value:e.value};async function iu(e,t){let r={async:!0};return Io(await e._zod.run({value:t,issues:[]},r),r)}function cr(e){return{validate:(t)=>{let r={async:!1};try{let n=e._zod.run({value:t,issues:[]},r);if(!(n instanceof Promise))return Io(n,r)}catch(n){}return iu(e,t)},vendor:"zod",version:1}}var pt=p("$ZodString",(e,t)=>{P.init(e,t),e._zod.pattern=t.pattern??eo,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=String(r.value)}catch(o){}if(typeof r.value==="string")return r;return r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}}),S=p("$ZodStringFormat",(e,t)=>{Ee.init(e,t),pt.init(e,t)}),Oo=p("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Ln),S.init(e,t)}),Co=p("$ZodUUID",(e,t)=>{if(t.version){let n={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(n===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=er(n))}else t.pattern??(t.pattern=er());S.init(e,t)}),Ao=p("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Mn),S.init(e,t)}),Eo=1,ut=2;function jo(e){try{if(typeof URL<"u"&&typeof URL.canParse==="function")return URL.canParse(e);return new URL(e),!0}catch{return!1}}function su(e,t){if(!("normalize"in t)&&!("hostname"in t)&&!("protocol"in t))return jo(e)||ut;return cu(e,t)}function cu(e,t){if(!t.normalize&&t.protocol?.source===Gn.source&&!/^https?:\/\//i.test(e))return Eo;try{if(typeof URL<"u"){let r=URL;if(typeof r.parse==="function")return r.parse(e)??ut}return new URL(e)}catch{return ut}}var au=/[\t\n\r]/g;function xo(e){return e.replace(au,"")}function uu(e,t){return t.lastIndex=0,t.test(e.hostname)}function lu(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(":")?e.protocol.slice(0,-1):e.protocol)}var No=p("$ZodURL",(e,t)=>{S.init(e,t),e._zod.check=(r)=>{try{let n=r.value.trim(),o=su(n,t);if(o===Eo){r.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:r.value,inst:e,continue:!t.abort});return}if(o===ut){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort});return}if(o===!0){r.value=xo(n);return}if(t.hostname&&!uu(o,t.hostname))r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:r.value,inst:e,continue:!t.abort});if(t.protocol&&!lu(o,t.protocol))r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:r.value,inst:e,continue:!t.abort});r.value=t.normalize?o.href:xo(n);return}catch(n){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort})}}}),Ro=p("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Un()),S.init(e,t)}),Do=p("$ZodNanoID",(e,t)=>{if(t.length!==void 0&&(!Number.isInteger(t.length)||t.length<1))throw Error(`Invalid nanoid length: ${t.length}`);t.pattern??(t.pattern=t.length===void 0?Nn:Rn(t.length)),S.init(e,t)}),Lo=p("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=On),S.init(e,t)}),Mo=p("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Cn),S.init(e,t)}),Uo=p("$ZodULID",(e,t)=>{t.pattern??(t.pattern=An),S.init(e,t)}),Fo=p("$ZodXID",(e,t)=>{t.pattern??(t.pattern=En),S.init(e,t)}),Bo=p("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=jn),S.init(e,t)}),Jo=p("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=Qn(t)),S.init(e,t)}),Ko=p("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=qn),S.init(e,t)}),Vo=p("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=Xn(t)),S.init(e,t)}),Wo=p("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Dn),S.init(e,t)}),Go=p("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Fn),S.init(e,t)}),pu=/^[0-9a-fA-F:.]+$/;function Ho(e){if(!pu.test(e))return!1;return jo(`http://[${e}]`)}var Yo=p("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Bn),S.init(e,t),e._zod.check=(r)=>{if(!Ho(r.value))r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:e,continue:!t.abort})}});var qo=p("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Jn),S.init(e,t)});function du(e){let t=e.split("/");if(t.length!==2)return!1;let[r,n]=t;if(!n)return!1;let o=Number(n);if(`${o}`!==n)return!1;if(o<0||o>128)return!1;return Ho(r)}var Xo=p("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Kn),S.init(e,t),e._zod.check=(r)=>{if(!du(r.value))r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:e,continue:!t.abort})}});function Qo(e){if(e==="")return!0;if(/\s/.test(e))return!1;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var ar=/^[0-9a-zA-Z+/]*={0,2}$/,ei=p("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=ar),S.init(e,t),e._zod.check=(r)=>{if(Qo(r.value))return;r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:e,continue:!t.abort})}}),dt=/^[A-Za-z0-9_-]*$/;function fu(e){if(!dt.test(e))return!1;let t=e.replace(/[-_]/g,(n)=>n==="-"?"+":"/"),r=t.padEnd(Math.ceil(t.length/4)*4,"=");return Qo(r)}var ti=p("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=dt),S.init(e,t),e._zod.check=(r)=>{if(fu(r.value))return;r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:e,continue:!t.abort})}}),ri=p("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Hn),S.init(e,t)});function mu(e,t=null){try{let r=e.split(".");if(r.length!==3)return!1;let[n]=r;if(!n)return!1;let o=JSON.parse(atob(n));if("typ"in o&&o?.typ!=="JWT")return!1;if(!o.alg)return!1;if(t&&(!("alg"in o)||o.alg!==t))return!1;return!0}catch{return!1}}var ni=p("$ZodJWT",(e,t)=>{S.init(e,t),e._zod.check=(r)=>{if(mu(r.value,t.alg))return;r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:e,continue:!t.abort})}});var ur=p("$ZodNumber",(e,t)=>{P.init(e,t),e._zod.pattern=tr,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=Number(r.value)}catch(s){}let o=r.value;if(typeof o==="number"&&!Number.isNaN(o)&&Number.isFinite(o))return r;let i=typeof o==="number"?Number.isNaN(o)?"NaN":!Number.isFinite(o)?String(o):void 0:void 0;return r.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...i?{received:i}:{}}),r}}),oi=p("$ZodNumberFormat",(e,t)=>{so.init(e,t),ur.init(e,t)}),ii=p("$ZodBoolean",(e,t)=>{P.init(e,t),e._zod.pattern=ro,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=Boolean(r.value)}catch(i){}let o=r.value;if(typeof o==="boolean")return r;return r.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),r}}),si=p("$ZodBigInt",(e,t)=>{P.init(e,t),e._zod.pattern=to,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=BigInt(r.value)}catch(o){}if(typeof r.value==="bigint")return r;return r.issues.push({expected:"bigint",code:"invalid_type",input:r.value,inst:e}),r}});var ci=p("$ZodUnknown",(e,t)=>{P.init(e,t),e._zod.parse=(r)=>r}),ai=p("$ZodNever",(e,t)=>{P.init(e,t),e._zod.parse=(r,n)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:e}),r)});var ui=p("$ZodDate",(e,t)=>{P.init(e,t),e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=new Date(r.value)}catch(c){}let o=r.value,i=o instanceof Date;if(i&&!Number.isNaN(o.getTime()))return r;return r.issues.push({expected:"date",code:"invalid_type",input:o,...i?{received:"Invalid Date"}:{},inst:e}),r}});function hu(e,t){let r=Wt(e._zod.def.checks);if(!r.length)return;let n=Math.min(...r.map((i)=>i[0])),o=e._zod.parse;e._zod.parse=(i,s)=>{let c=t(i.value);if(c>n&&!s?.skipChecks&&s?.direction!=="backward"){for(let[a,u]of Wt(e._zod.def.checks))if(c>a&&u._zod.def.when(i)){let l=i.issues.length;return u._zod.check(i),i.issues[l].continue=!1,qe(i.issues,l,e),i}}return o(i,s)}}var gu=(e)=>Array.isArray(e)?e.length:-1;function vo(e,t,r){if(e.issues.length)t.issues.push(...Ye(r,e.issues));t.value[r]=e.value}var li=p("$ZodArray",(e,t)=>{P.init(e,t);let r=U.memoizer;r?.attach(e),e._zod.parse=(n,o)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=r?r.alloc(e,n,Array(i.length),o):Array(i.length);let s=[],c=o?.abortEarly;for(let a=0;a<i.length;a++){let u=i[a],l=t.element._zod.run({value:u,issues:[]},o);if(l instanceof Promise)s.push(l.then((d)=>vo(d,n,a)));else if(vo(l,n,a),c&&l.issues.length!==0&&X(l))break}if(s.length)return Promise.all(s).then(()=>n);return n},hu(e,gu)});function lt(e,t,r,n,o,i){let s=r in n,c=i==="optional";if(!s&&c&&o==="optional")return;if(e.issues.length){if(o!==void 0&&c&&!s)return;t.issues.push(...Ye(r,e.issues))}if(!s&&o===void 0){if(!e.issues.length)t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[r]});return}if(e.value===void 0){if(s||o==="defaulted"&&!c)t.value[r]=void 0}else t.value[r]=e.value}var yu=[];function pi(e){let t=Object.keys(e.shape),r=Object.getOwnPropertySymbols(e.shape),n=r.length?r:yu,o=n.length?[...t,...n]:t;for(let s of o)if(!e.shape?.[s]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${String(s)}": expected a Zod schema`);let i=an(e.shape);return{...e,allKeys:o,symbolKeys:n,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(i)}}function di(e,t,r,n,o,i,s){let c=[],a=o.keySet,u=o.catchall._zod,l=u.def.type,{optin:d,optout:f}=u,m=0;for(let h in t){if(s&&r.issues.length!==m){if(X(r,m))break;m=r.issues.length}if(a.has(h))continue;if(h==="__proto__"){if(l==="never")c.push(h);continue}if(l==="never"){c.push(h);continue}let b=u.run({value:t[h],issues:[]},n);if(b instanceof Promise)e.push(b.then((_)=>lt(_,r,h,t,d,f)));else lt(b,r,h,t,d,f)}if(c.length)r.issues.push({code:"unrecognized_keys",keys:c,input:t,inst:i,continue:!0});if(!e.length)return r;return Promise.all(e).then(()=>r)}var _u=p("$ZodObject",(e,t)=>{P.init(e,t);let r=Object.getOwnPropertyDescriptor(t,"shape"),n=r?.get?r.get.raw:t.shape??{};if(n){let u=()=>{let l={...n};return Object.defineProperty(t,"shape",{value:l}),u.raw=l,l};u.raw=n,Object.defineProperty(t,"shape",{get:u})}let o=Ie(()=>pi(t));v(e,"propValues",(u)=>{let l=u.def.shape,d={};for(let f in l){let m=l[f]._zod;if(m.values){if(!Object.prototype.hasOwnProperty.call(d,f))V(d,f,new Set);for(let h of m.values)d[f].add(h);if(m.optin!==void 0)d[f].add(void 0)}}return d});let i=me,s=t.catchall,c,a=U.memoizer;a?.attach(e),e._zod.parse=(u,l)=>{c??(c=o.value);let d=u.value;if(!i(d))return u.issues.push({expected:"object",code:"invalid_type",input:d,inst:e}),u;u.value=a?a.alloc(e,u,{},l):{};let f=[],m=c.shape,h=l?.abortEarly,b=u.issues.length;for(let _ of c.allKeys){if(h&&u.issues.length!==b){if(X(u,b))break;b=u.issues.length}if(_==="__proto__")continue;let k=m[_],R=k._zod.optin,ie=k._zod.optout,le=k._zod.run({value:d[_],issues:[]},l);if(le instanceof Promise)f.push(le.then((O)=>lt(O,u,_,d,R,ie)));else lt(le,u,_,d,R,ie)}if(!s)return f.length?Promise.all(f).then(()=>u):u;return di(f,d,u,l,o.value,e,h===!0)}}),fi=p("$ZodObjectJIT",(e,t)=>{_u.init(e,t);let r=e._zod.parse,n=Ie(()=>pi(t)),o=U.memoizer,i=(m)=>{let h=n.value,b=h.symbolKeys,_=new ir(["payload","ctx"],{shape:m,inst:e,memo:o,syms:b}),k=(O)=>`shape[${O}]._zod.run({ value: input[${O}], issues: [] }, ctx)`,R=(O,z)=>`
7
- let ${O}_ab = false;
8
- for (let i = 0; i < ${O}.issues.length; i++) {
9
- const iss = ${O}.issues[i];
10
- iss.path = iss.path ? [${z}, ...iss.path] : [${z}];
11
- payload.issues.push(iss);
12
- if (iss.continue !== true) ${O}_ab = true;
13
- }
14
- if (${O}_ab && ctx && ctx.abortEarly) {
15
- payload.value = newResult;
16
- return payload;
17
- }`;_.write("const input = payload.value;");let ie=Object.create(null),le=0;for(let O of h.allKeys)ie[O]=`key_${le++}`;_.write(o?"const newResult = memo.alloc(inst, payload, {}, ctx);":"const newResult = {};");for(let O of h.allKeys){if(O==="__proto__")continue;let z=ie[O],Y=typeof O==="symbol"?`syms[${b.indexOf(O)}]`:nn(O),Lt=`${Y} in input`,Yr=m[O],Mt=Yr?._zod?.optin,qr=Mt!==void 0,Za=Yr?._zod?.optout==="optional";if(_.write(`const ${z} = ${k(Y)};`),qr&&Za){let Ia=Mt==="optional"?`${z}_present`:`${z}.value !== undefined || ${z}_present`;_.write(`
18
- const ${z}_present = ${Lt};
19
- if (!${z}.issues.length || ${z}_present) {
20
- if (${z}.issues.length) {${R(z,Y)}
21
- }
22
-
23
- if (${Ia}) {
24
- newResult[${Y}] = ${z}.value;
25
- }
26
- }
27
-
28
- `)}else if(!qr)_.write(`
29
- const ${z}_present = ${Lt};
30
- if (${z}.issues.length) {${R(z,Y)}
31
- }
32
- if (!${z}_present && !${z}.issues.length) {
33
- payload.issues.push({
34
- code: "invalid_type",
35
- expected: "nonoptional",
36
- input: undefined,
37
- path: [${Y}]
38
- });
39
- if (ctx && ctx.abortEarly) {
40
- payload.value = newResult;
41
- return payload;
42
- }
43
- }
44
-
45
- if (${z}_present) {
46
- newResult[${Y}] = ${z}.value;
47
- }
48
-
49
- `);else if(_.write(`
50
- if (${z}.issues.length) {${R(z,Y)}
51
- }
52
- `),Mt==="defaulted")_.write(`newResult[${Y}] = ${z}.value;`);else _.write(`
53
- if (${z}.value !== undefined || ${Lt}) {
54
- newResult[${Y}] = ${z}.value;
55
- }
56
- `)}return _.write("payload.value = newResult;"),_.write("return payload;"),_.compile()},s,c=me,a=!U.jitless,l=a&&sn.value,d=t.catchall,f;e._zod.parse=(m,h)=>{f??(f=n.value);let b=m.value;if(!c(b))return m.issues.push({expected:"object",code:"invalid_type",input:b,inst:e}),m;if(a&&l&&h?.async===!1&&h.jitless!==!0){if(!s)s=i(t.shape);if(m=s(m,h),!d)return m;return di([],b,m,h,f,e,h?.abortEarly===!0)}return r(m,h)}});function wo(e,t,r,n){for(let i of e)if(i.issues.length===0)return t.value=i.value,t;let o=e.filter((i)=>!X(i));if(o.length===1)return t.value=o[0].value,o[0];return t.issues.push({code:"invalid_union",input:t.value,inst:r,errors:e.map((i)=>i.issues.map((s)=>ae(s,n,G())))}),t}var lr=p("$ZodUnion",(e,t)=>{P.init(e,t),v(e,"optin",(n)=>n.def.options.some((o)=>o._zod.optin==="defaulted")?"defaulted":n.def.options.some((o)=>o._zod.optin!==void 0)?"optional":void 0),v(e,"optout",(n)=>n.def.options.some((o)=>o._zod.optout==="optional")?"optional":void 0),v(e,"values",(n)=>{if(n.def.options.every((o)=>o._zod.values))return new Set(n.def.options.flatMap((o)=>Array.from(o._zod.values)));return}),v(e,"pattern",(n)=>{if(n.def.options.every((o)=>o._zod.pattern)){let o=n.def.options.map((i)=>i._zod.pattern);return new RegExp(`^(${o.map((i)=>We(i.source)).join("|")})$`)}return});let r=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(n,o)=>{if(r)return r(n,o);let i=!1,s=[];for(let c of t.options){let a=c._zod.run({value:n.value,issues:[]},o);if(a instanceof Promise)s.push(a),i=!0;else{if(a.issues.length===0)return a;s.push(a)}}if(!i)return wo(s,n,e,o);return Promise.all(s).then((c)=>wo(c,n,e,o))}});function bu(e){let t=new Map;for(let r of e.options){let n=r._zod.propValues?.[e.discriminator];if(!n||n.size===0)throw Error(`Invalid discriminated union option at index "${e.options.indexOf(r)}"`);for(let o of n)if(t.has(o)){if(o!==void 0)throw Error(`Duplicate discriminator value "${String(o)}"`);t.set(o,null)}else t.set(o,r)}return t}var mi=p("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,lr.init(e,t);let r=e._zod.parse;v(e,"propValues",(o)=>{let i={},s=0;for(let c of o.def.options){let a=c._zod.propValues;if(!a||Object.keys(a).length===0)throw Error(`Invalid discriminated union option at index "${o.def.options.indexOf(c)}"`);if(a[o.def.discriminator]?.has(void 0))s++;for(let[u,l]of Object.entries(a)){if(!Object.prototype.hasOwnProperty.call(i,u))V(i,u,new Set);for(let d of l)i[u].add(d)}}if(!o.def.unionFallback&&s>1)i[o.def.discriminator]?.delete(void 0);return i}),t.options.forEach((o,i)=>{let s=Oe(o._zod.def);if(s&&!Object.prototype.hasOwnProperty.call(s,t.discriminator))throw Error(`Invalid discriminated union option at index "${i}"`)});let n=Ie(()=>bu(t));e._zod.parse=(o,i)=>{let s=o.value;if(!me(s))return o.issues.push({code:"invalid_type",expected:"object",input:s,inst:e}),o;let c=s?.[t.discriminator],a=n.value.get(c);if(a&&(c!==void 0||i.direction!=="backward"))return a._zod.run(o,i);if(t.unionFallback||i.direction==="backward")return r(o,i);return o.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,options:Array.from(n.value.keys()).filter((u)=>n.value.get(u)!==null),input:s,path:[t.discriminator],inst:e}),o}}),hi=p("$ZodIntersection",(e,t)=>{P.init(e,t),e._zod.parse=(r,n)=>{let o=r.value,i=t.left._zod.run({value:o,issues:[]},n),s=t.right._zod.run({value:o,issues:[]},n);if(i instanceof Promise||s instanceof Promise)return Promise.all([i,s]).then(([a,u])=>ko(r,a,u));return ko(r,i,s)}});function sr(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(he(e)&&he(t)){let r=Object.keys(t),n=Object.keys(e).filter((i)=>r.indexOf(i)!==-1),o={...e,...t};if(Object.prototype.hasOwnProperty.call(o,"__proto__"))delete o.__proto__;for(let i of n){if(i==="__proto__")continue;let s=sr(e[i],t[i]);if(!s.valid)return{valid:!1,mergeErrorPath:[i,...s.mergeErrorPath]};o[i]=s.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let r=[];for(let n=0;n<e.length;n++){let o=e[n],i=t[n],s=sr(o,i);if(!s.valid)return{valid:!1,mergeErrorPath:[n,...s.mergeErrorPath]};r.push(s.data)}return{valid:!0,data:r}}return{valid:!1,mergeErrorPath:[]}}function ko(e,t,r){let n=new Map,o,i=new Map,s=(u,l)=>{let d;if(u.code==="unrecognized_keys"&&!u.path?.length)o??(o=u),d=u.keys;else if(u.code==="invalid_key"&&u.origin==="record"&&u.path?.length===1){let f=String(u.path[0]);if(!i.has(f))i.set(f,u);d=[f]}else return!1;for(let f of d){if(!n.has(f))n.set(f,{});n.get(f)[l]=!0}return!0};for(let u of t.issues)if(!s(u,"l"))e.issues.push(u);for(let u of r.issues)if(!s(u,"r"))e.issues.push(u);let c=[...n].filter(([,u])=>u.l&&u.r).map(([u])=>u);if(c.length){let u=o?c.filter((l)=>o.keys.includes(l)):[];if(u.length)e.issues.push({...o,keys:u});for(let l of c)if(!u.includes(l)&&i.has(l))e.issues.push(i.get(l))}let a=sr(t.value,r.value);if(!a.valid){if(X(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`)}return e.value=a.data,e}var gi=p("$ZodEnum",(e,t)=>{P.init(e,t);let r=Te(t.entries),n=new Set(r);e._zod.values=n,v(e,"pattern",(o)=>{let i=Te(o.def.entries).filter((s)=>cn.has(typeof s));return new RegExp(i.length?`^(${i.map((s)=>ce(s.toString())).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(o,i)=>{let s=o.value;if(n.has(s))return o;return o.issues.push({code:"invalid_value",values:r,input:s,inst:e}),o}}),yi=p("$ZodLiteral",(e,t)=>{P.init(e,t);let r=new Set(t.values);e._zod.values=r,v(e,"pattern",(n)=>{let o=n.def.values;return new RegExp(o.length?`^(${o.map((i)=>typeof i==="string"?ce(i):i?ce(i.toString()):String(i)).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(n,o)=>{let i=n.value;if(r.has(i))return n;return n.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),n}});var _i=p("$ZodTransform",(e,t)=>{P.init(e,t),e._zod.optin="optional",U.memoizer?.guard(e),e._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Ce(e.constructor.name);let o=t.transform(r.value,r);if(n.async)return(o instanceof Promise?o:Promise.resolve(o)).then((s)=>(r.value=s,r));if(o instanceof Promise)throw new Q;return r.value=o,r}});function $o(e,t){return e.value=t.issues.length?void 0:t.value,e}var pr=p("$ZodOptional",(e,t)=>{P.init(e,t),v(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),e._zod.optout="optional",v(e,"values",(r)=>{let n=r.def.innerType._zod.values;return n?new Set([...n,void 0]):void 0}),v(e,"pattern",(r)=>{let n=r.def.innerType._zod.pattern;return n?new RegExp(`^(${We(n.source)})?$`):void 0}),e._zod.parse=(r,n)=>{if(r.value===void 0){if(t.innerType._zod.optin!=="defaulted")return r;let o=t.innerType._zod.run({value:r.value,issues:[]},n);if(o instanceof Promise)return o.then((i)=>$o(r,i));return $o(r,o)}return t.innerType._zod.run(r,n)}}),bi=p("$ZodExactOptional",(e,t)=>{pr.init(e,t),v(e,"values",(r)=>r.def.innerType._zod.values),v(e,"pattern",(r)=>r.def.innerType._zod.pattern),e._zod.parse=(r,n)=>t.innerType._zod.run(r,n)}),xi=p("$ZodNullable",(e,t)=>{P.init(e,t),v(e,"optin",(r)=>r.def.innerType._zod.optin),v(e,"optout",(r)=>r.def.innerType._zod.optout),v(e,"pattern",(r)=>{let n=r.def.innerType._zod.pattern;return n?new RegExp(`^(${We(n.source)}|null)$`):void 0}),v(e,"values",(r)=>r.def.innerType._zod.values?new Set([...r.def.innerType._zod.values,null]):void 0),e._zod.parse=(r,n)=>{if(r.value===null)return r;return t.innerType._zod.run(r,n)}}),vi=p("$ZodDefault",(e,t)=>{P.init(e,t),e._zod.optin="defaulted",v(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);if(r.value===void 0)return r.value=t.defaultValue,r;let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then((i)=>zo(i,t));return zo(o,t)}});function zo(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var wi=p("$ZodPrefault",(e,t)=>{P.init(e,t),e._zod.optin="defaulted",v(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);if(r.value===void 0)r.value=t.defaultValue;return t.innerType._zod.run(r,n)}}),ki=p("$ZodNonOptional",(e,t)=>{P.init(e,t),v(e,"values",(r)=>{let n=r.def.innerType._zod.values;return n?new Set([...n].filter((o)=>o!==void 0)):void 0}),e._zod.parse=(r,n)=>{let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then((i)=>Po(i,e));return Po(o,e)}});function Po(e,t){if(!e.issues.length&&e.value===void 0)e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t});return e}function So(e,t,r,n){if(!t.issues.length){if(e.value=t.value,t.memo)e.memo=!0;return e}return e.value=r.catchValue({...t,value:e.value,error:{issues:t.issues.map((o)=>ae(o,n,G()))},input:e.value}),e}var $i=p("$ZodCatch",(e,t)=>{P.init(e,t),v(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),v(e,"optout",(r)=>r.def.innerType._zod.optout),v(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);let o=t.innerType._zod.run({value:r.value,issues:[]},n);if(o instanceof Promise)return o.then((i)=>So(r,i,t,n));return So(r,o,t,n)}});var zi=p("$ZodPipe",(e,t)=>{P.init(e,t),v(e,"values",(r)=>r.def.in._zod.values),v(e,"optin",(r)=>r.def.in._zod.optin),v(e,"optout",(r)=>r.def.out._zod.optout),v(e,"propValues",(r)=>r.def.in._zod.propValues),e._zod.parse=(r,n)=>{if(n.direction==="backward"){let i=t.out._zod.run(r,n);if(i instanceof Promise)return i.then((s)=>at(s,t.in,n));return at(i,t.in,n)}let o=t.in._zod.run(r,n);if(o instanceof Promise)return o.then((i)=>at(i,t.out,n));return at(o,t.out,n)}});function at(e,t,r){if(e.issues.some((n)=>n.code!=="unrecognized_keys"))return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},r)}var Pi=p("$ZodReadonly",(e,t)=>{P.init(e,t),v(e,"propValues",(r)=>r.def.innerType._zod.propValues),v(e,"values",(r)=>r.def.innerType._zod.values),v(e,"optin",(r)=>r.def.innerType?._zod?.optin),v(e,"optout",(r)=>r.def.innerType?._zod?.optout),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then(To);return To(o)}});function To(e){if(!e.memo)e.value=Object.freeze(e.value);return e}var Si=p("$ZodCustom",(e,t)=>{A.init(e,t),P.init(e,t),e._zod.parse=(r,n)=>r,e._zod.check=(r)=>{let n=r.value,o=t.fn(n);if(o instanceof Promise)return o.then((i)=>Zo(i,r,n,e));Zo(o,r,n,e);return}});function Zo(e,t,r,n){if(!e){let o={code:"custom",input:r,inst:n,path:[...n._zod.def.path??[]],continue:!n._zod.def.abort};if(n._zod.def.params)o.params=n._zod.def.params;t.issues.push(de(o))}}class Zi extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform");this.name="ZodCyclicError"}}var fr="~memo",Ti=[];function Ii(e){return e!==null&&typeof e==="object"}function dr(e){return e.map((t)=>t.path?{...t,path:t.path.slice()}:{...t})}var Oi=new WeakMap,je=0,ht=1,Ne=2;function gt(e,t,r){let n=Oi.get(e);if(n!==void 0)return n?Ne:je;if(t.has(e))return Ne;t.add(e);let o=je,i=(l)=>{if(o!==Ne&&l?._zod){let d=gt(l,t,r);if(d>o)o=d}},s=(l,d)=>{let f=je;for(let m of Reflect.ownKeys(l)){let h=Object.getOwnPropertyDescriptor(l,m);if(d&&!h.enumerable)continue;let b=h.get?ht:h.value?._zod?gt(h.value,t,r):je;if(b>f)f=b}return f},c=(l)=>{if(l>o)o=l},a=e._zod.def,u=a.type;switch(u){case"object":{let l=Oe(a);c(l?s(l,!0):ht),i(a.catchall);break}case"array":i(a.element);break;case"tuple":for(let l of a.items)i(l);i(a.rest);break;case"record":case"map":i(a.keyType),i(a.valueType);break;case"set":i(a.valueType);break;case"union":for(let l of a.options)i(l);break;case"intersection":i(a.left),i(a.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":i(a.innerType);break;case"pipe":i(a.in),i(a.out);break;case"function":i(a.input),i(a.output);break;case"lazy":{let l=a._cachedInner??(r?e._zod.innerType:void 0);c(l?gt(l,t,!1):ht);break}case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":break;default:for(let l in a){let d=Object.getOwnPropertyDescriptor(a,l);if(!d||d.get)continue;let f=d.value;if(!f||typeof f!=="object")continue;if(f._zod)i(f);else if(Array.isArray(f))for(let m of f)i(m)}}return t.delete(e),xu(e,o)}function xu(e,t){if(t!==ht)Oi.set(e,t===Ne);return t}function vu(e,t){let r=e.buckets.get(t);if(!r)r=new WeakMap,e.buckets.set(t,r);return r}var ft,mt=[],wu={alloc(e,t,r){let n=ft;if(!n)return r;ft=void 0;let o={value:r,issues:null};return n.set(t.value,o),mt.push(o),r},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let r=e._zod.parse,n=(o,i)=>{if(i.direction!=="backward"&&ku(i,o.value))throw new Zi;return r(o,i)};if(e._zod.parse=n,e._zod.run===r)e._zod.run=n})},attach(e){var t;let r,n=!1,o,i;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let s=e._zod.parse,c=(a,u)=>{if(r===void 0){let k=gt(e,new Set,!1);if(k===je){if(e._zod.parse=s,e._zod.run===c)e._zod.run=s;return s(a,u)}if(k===Ne||n)r=!0;else n=!0}let l=a.value;if(!Ii(l))return s(a,u);let d=u[fr];if(!d)d={buckets:new WeakMap,backEdges:void 0},u[fr]=d;let f;if(o===u)f=i;else f=vu(d,e),o=u,i=f;let m=f.get(l);if(m){if(a.value=m.value,m.issues){if(m.issues.length)a.issues.push(...dr(m.issues))}else a.memo=!0,d.backEdges??(d.backEdges=new WeakSet),d.backEdges.add(m.value);return a}ft=f;let h=mt.length,b=s(a,u);ft=void 0;let _=mt.length>h?mt.pop():void 0;if(b instanceof Promise)return b.then((k)=>{if(_)_.issues=k.issues.length?dr(k.issues):Ti;return k});if(_)_.issues=b.issues.length?dr(b.issues):Ti;return b};if(e._zod.parse=c,e._zod.run===s)e._zod.run=c})}};function Ci(){return wu}function ku(e,t){let r=e[fr]?.backEdges;return r!==void 0&&Ii(t)&&r.has(t)}var $u=()=>{let e={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"},map:{unit:"entries",verb:"to have"}};function t(i){return e[i]??null}let r={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",mac:"MAC address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",currency_code:"currency code",credit_card:"credit card number",iban:"IBAN",jwt:"JWT",template_literal:"input"},n={nan:"NaN"};function o(i,s){if(i==="number"&&typeof s==="number"&&!Number.isFinite(s))return String(s);return n[i]??i}return(i)=>{switch(i.code){case"invalid_type":{let s=o(i.expected),c=dn(i.input),a=o(c,i.input);return`Invalid input: expected ${s}, received ${a}`}case"invalid_value":if(i.values.length===1)return`Invalid input: expected ${Kt(i.values[0])}`;return`Invalid option: expected one of ${Ft(i.values,"|")}`;case"too_big":{let s=i.exact?"exactly ":i.inclusive?"<=":"<",c=t(i.origin);if(c)return`Too big: expected ${i.origin??"value"} to have ${s}${i.maximum.toString()} ${c.unit??"elements"}`;return`Too big: expected ${i.origin??"value"} to be ${s}${i.maximum.toString()}`}case"too_small":{let s=i.exact?"exactly ":i.inclusive?">=":">",c=t(i.origin);if(c)return`Too small: expected ${i.origin} to have ${s}${i.minimum.toString()} ${c.unit}`;return`Too small: expected ${i.origin} to be ${s}${i.minimum.toString()}`}case"invalid_format":{let s=i;if(s.format==="starts_with")return`Invalid string: must start with "${s.prefix}"`;if(s.format==="ends_with")return`Invalid string: must end with "${s.suffix}"`;if(s.format==="includes")return`Invalid string: must include "${s.includes}"`;if(s.format==="regex")return`Invalid string: must match pattern ${s.pattern}`;return`Invalid ${r[s.format]??i.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${i.divisor}`;case"unrecognized_keys":return`Unrecognized key${i.keys.length>1?"s":""}: ${Ft(i.keys,", ")}`;case"invalid_key":return`Invalid key in ${i.origin}`;case"invalid_union":if(i.options&&Array.isArray(i.options)&&i.options.length>0)return`Invalid discriminator value. Expected ${i.options.map((c)=>`'${c}'`).join(" | ")}`;if(i.inclusive===!1)return"Invalid input: more than one option matched";return"Invalid input";case"invalid_element":return`Invalid value in ${i.origin}`;default:return"Invalid input"}}};function mr(){return{localeError:$u()}}var Ai;class Ei{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let r=t[0];if(this._map.set(e,r),r&&typeof r==="object"&&"id"in r)this._idmap.set(r.id,e);return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);if(t&&typeof t==="object"&&"id"in t)this._idmap.delete(t.id);return this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let r={...this.get(t)??{}};delete r.id;let n={...r,...this._map.get(e)};return Object.keys(n).length?n:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function zu(){return new Ei}(Ai=globalThis).__zod_globalRegistry??(Ai.__zod_globalRegistry=zu());var fe=globalThis.__zod_globalRegistry;function yt(e){if(e.checks)e.checks=[...e.checks];return e}function ji(e,t){return new e(yt({type:"string",...g(t)}))}function Ni(e,t){return new e(yt({type:"string",coerce:!0,...g(t)}))}function Ri(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...g(t)})}function Di(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...g(t)})}function Li(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...g(t)})}function Mi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...g(t)})}function Ui(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...g(t)})}function Fi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...g(t)})}function hr(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...g(t)})}function Bi(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...g(t)})}function Ji(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...g(t)})}function Ki(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...g(t)})}function Vi(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...g(t)})}function Wi(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...g(t)})}function Gi(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...g(t)})}function Hi(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...g(t)})}function Yi(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...g(t)})}function qi(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...g(t)})}function Xi(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...g(t)})}function Qi(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...g(t)})}function es(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...g(t)})}function ts(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...g(t)})}function rs(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...g(t)})}function ns(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...g(t)})}function os(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...g(t)})}function is(e,t){return new e({type:"string",format:"date",check:"string_format",...g(t)})}function ss(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...g(t)})}function cs(e,t){return new e({type:"string",format:"duration",check:"string_format",...g(t)})}function as(e,t){return new e(yt({type:"number",checks:[],...g(t)}))}function us(e,t){return new e(yt({type:"number",coerce:!0,checks:[],...g(t)}))}function ls(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...g(t)})}function ps(e,t){return new e({type:"boolean",...g(t)})}function ds(e,t){return new e({type:"boolean",coerce:!0,...g(t)})}function fs(e,t){return new e({type:"bigint",coerce:!0,...g(t)})}function ms(e){return new e({type:"unknown"})}function hs(e,t){return new e({type:"never",...g(t)})}function gs(e,t){return new e({type:"date",coerce:!0,...g(t)})}function ge(e,t){return new nr({check:"less_than",...g(t),value:e,inclusive:!1})}function ne(e,t){return new nr({check:"less_than",...g(t),value:e,inclusive:!0})}function ye(e,t){return new or({check:"greater_than",...g(t),value:e,inclusive:!1})}function oe(e,t){return new or({check:"greater_than",...g(t),value:e,inclusive:!0})}function Re(e,t){return new io({check:"multiple_of",...g(t),value:e})}function _t(e,t){return new co({check:"max_length",...g(t),maximum:e})}function _e(e,t){return new ao({check:"min_length",...g(t),minimum:e})}function bt(e,t){return new uo({check:"length_equals",...g(t),length:e})}function gr(e,t){return new lo({check:"string_format",format:"regex",...g(t),pattern:e})}function yr(e){return new po({check:"string_format",format:"lowercase",...g(e)})}function _r(e){return new fo({check:"string_format",format:"uppercase",...g(e)})}function br(e,t){return new mo({check:"string_format",format:"includes",...g(t),includes:e})}function xr(e,t){return new ho({check:"string_format",format:"starts_with",...g(t),prefix:e})}function vr(e,t){return new go({check:"string_format",format:"ends_with",...g(t),suffix:e})}function ue(e){return new yo({check:"overwrite",tx:e})}function wr(e){return ue((t)=>t.normalize(e))}function kr(){return ue((e)=>e.trim())}function $r(){return ue((e)=>e.toLowerCase())}function zr(){return ue((e)=>e.toUpperCase())}function Pr(){return ue((e)=>on(e))}function ys(e,t,r){return new e({type:"array",element:t,...g(r)})}function _s(e,t,r){return new e({type:"custom",check:"custom",fn:t,...g(r)})}function bs(e,t){let r=Pu((n)=>(n.addIssue=(o)=>{if(typeof o==="string")n.issues.push(de(o,n.value,r._zod.def));else{let i=o;if(i.fatal)i.continue=!1;if(i.code??(i.code="custom"),!("input"in i))i.input=n.value;i.inst??(i.inst=r),i.continue??(i.continue=!r._zod.def.abort),n.issues.push(de(i))}},e(n.value,n)),t);return r}function Pu(e,t){let r=new A({check:"custom",...g(t)});return r._zod.check=e,r}function De(e,...t){for(let r of t)for(let n of Reflect.ownKeys(r))if(Object.prototype.propertyIsEnumerable.call(r,n))V(e,n,r[n]);return e}function Tr(e){let t=e?.target??"draft-2020-12";if(t==="draft-4")t="draft-04";if(t==="draft-7")t="draft-07";return{processors:e.processors??{},metadataRegistry:e?.metadata??fe,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??"ref",reused:e?.reused??"inline",intersections:[],deferred:[],external:e?.external??void 0}}function H(e,t,r,n,o){let i=typeof t.unrepresentable==="function"?t.unrepresentable({zodSchema:e,path:n.path,message:o}):t.unrepresentable;if(i==="any")return!1;if(i===void 0||i==="throw")throw Error(o);return Object.assign(r,i),!0}function C(e,t,r={path:[],schemaPath:[]}){var n;let o=e._zod.def,i=t.seen.get(e);if(i){if(i.count++,r.schemaPath.includes(e))i.cycle=r.path;return i.schema}let s={schema:{},count:1,cycle:void 0,path:r.path};t.seen.set(e,s),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let c=e._zod.toJSONSchema?.();if(c)s.schema=c;else{let l={...r,schemaPath:[...r.schemaPath,e],path:r.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,s.schema,l);else{let f=s.schema,m=t.processors[o.type];if(!m)throw Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);m(e,t,f,l)}let d=e._zod.parent;if(d){if(!s.ref)s.ref=d;C(d,t,l),t.seen.get(d).isParent=!0}}let a=t.metadataRegistry.get(e);if(a)De(s.schema,a);if(t.io==="input"&&j(e))delete s.schema.examples,delete s.schema.default;if(t.io==="input"&&"_prefault"in s.schema)(n=s.schema).default??(n.default=s.schema._prefault);return delete s.schema._prefault,t.seen.get(e).schema}function xs(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function Zr(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");if(e.external&&e.sharedDefsExtractedFor===e.external)return;let n=new Map;for(let s of e.seen.entries()){let c=e.metadataRegistry.get(s[0])?.id;if(c){let a=n.get(c);if(a&&a!==s[0])throw Error(`Duplicate schema id "${c}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);n.set(c,s[0])}}let o=(s)=>{let c=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){let d=e.external.registry.get(s[0])?.id,f=e.external.uri??((h)=>h);if(d)return{ref:f(d)};let m=s[1].defId??s[1].schema.id??`schema${e.counter++}`;return s[1].defId=m,{defId:m,ref:`${f("__shared")}#/${c}/${xs(m)}`}}let a="#",u=`${a}/${c}/`;if(s[1]===r&&!s[1].schema.id)return{ref:a};let l=s[1].schema.id??`__schema${e.counter++}`;return{defId:l,ref:u+xs(l)}},i=(s)=>{if(s[1].schema.$ref)return;let c=s[1],{ref:a,defId:u}=o(s);if(c.def={...c.schema},u)c.defId=u;let l=c.schema;for(let d in l)delete l[d];l.$ref=a};if(e.cycles==="throw")for(let s of e.seen.entries()){let c=s[1];if(c.cycle)throw Error(`Cycle detected: #/${c.cycle?.join("/")}/<root>
57
-
58
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let s of e.seen.entries()){let c=s[1];if(t===s[0]){i(s);continue}if(e.external){let u=e.external.registry.get(s[0])?.id;if(t!==s[0]&&u){i(s);continue}}if(e.metadataRegistry.get(s[0])?.id){i(s);continue}if(c.cycle){i(s);continue}if(c.count>1){if(e.reused==="ref")i(s)}}if(e.external)e.sharedDefsExtractedFor=e.external}function ks(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let r=[];for(let n of t){if(!n||typeof n!=="object")return;ks(n);let o=Object.keys(n);if(o.length!==1||o[0]!=="type")return;let i=n.type;for(let s of Array.isArray(i)?i:[i]){if(typeof s!=="string")return;if(!r.includes(s))r.push(s)}}delete e.anyOf,e.type=r.length===1?r[0]:r}var $s=new Set(["type","properties","required","additionalProperties"]),vs=["oneOf","anyOf"];function ws(e){let t=e.additionalProperties;if(t===void 0||t===!1||typeof t!=="object"||t===null)return null;return Object.keys(t).length?t:null}function Sr(e){let t=[];for(let i of e){if(typeof i!=="object"||i.type!=="object")return null;for(let s in i)if(!$s.has(s))return null;t.push(i)}let r={},n=new Set;for(let i of t){for(let s in i.properties){if(Object.prototype.hasOwnProperty.call(r,s))continue;let c=[];for(let u of t){let l=u.properties?.[s]??ws(u);if(l===null||l===void 0)continue;if(!c.some((d)=>JSON.stringify(d)===JSON.stringify(l)))c.push(l)}let a=c.length===1?c[0]:Sr(c)??{allOf:c};V(r,s,a)}for(let s of i.required??[])n.add(s)}let o={type:"object",properties:r};if(n.size)o.required=[...n];if(t.every((i)=>i.additionalProperties===!1))o.additionalProperties=!1;else{let i=[];for(let s of t){let c=ws(s);if(c&&!i.some((a)=>JSON.stringify(a)===JSON.stringify(c)))i.push(c)}if(i.length===1)o.additionalProperties=i[0];else if(i.length>1)o.additionalProperties={allOf:i}}return o}function Su(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let o of $s)if(o in e)return;let r=t.filter((o)=>vs.some((i)=>Array.isArray(o[i]))),n=null;if(!r.length)n=Sr(t);else{let o=r[0],i=vs.find((a)=>Array.isArray(o[a]));if(Object.keys(o).length!==1)return;let s=t.filter((a)=>a!==o),c=o[i].map((a)=>Sr([...s,a]));if(c.some((a)=>!a))return;n={[i]:c}}if(!n)return;delete e.allOf,De(e,n)}function Ir(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");let n=(c)=>{let a=e.seen.get(c);if(a.ref===null)return;let u=a.def??a.schema,l={...u},d=a.ref;if(a.ref=null,d){n(d);let m=e.seen.get(d),h=m.schema;if(h.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))u.allOf=u.allOf??[],u.allOf.push(h);else De(u,h);if(De(u,l),c._zod.parent===d)for(let _ in u){if(_==="$ref"||_==="allOf")continue;if(!(_ in l))delete u[_]}if(h.$ref&&m.def)for(let _ in u){if(_==="$ref"||_==="allOf")continue;if(_ in m.def&&JSON.stringify(u[_])===JSON.stringify(m.def[_]))delete u[_]}}let f=c._zod.parent;if(f&&f!==d){n(f);let m=e.seen.get(f);if(m?.schema.$ref){if(u.$ref=m.schema.$ref,m.def)for(let h in u){if(h==="$ref"||h==="allOf")continue;if(h in m.def&&JSON.stringify(u[h])===JSON.stringify(m.def[h]))delete u[h]}}}e.override({zodSchema:c,jsonSchema:u,path:a.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let c of[...e.seen.entries()].reverse())n(c[0]);if(e.target!=="openapi-3.0")for(let c of e.seen.entries())ks(c[1].def??c[1].schema);for(let c of e.deferred)c();if(e.intersections.length){let c=new Map;for(let a of e.seen.values())for(let u of[a.schema,a.def]){let l=u?.allOf;if(!Array.isArray(l))continue;let d=c.get(l);if(d)d.push(u);else c.set(l,[u])}for(let a of e.intersections)for(let u of c.get(a)??[])Su(u)}}let o={};if(e.target==="draft-2020-12")o.$schema="https://json-schema.org/draft/2020-12/schema";else if(e.target==="draft-07")o.$schema="http://json-schema.org/draft-07/schema#";else if(e.target==="draft-04")o.$schema="http://json-schema.org/draft-04/schema#";else if(e.target==="openapi-3.0");if(e.external?.uri){let c=e.external.registry.get(t)?.id;if(!c)throw Error("Schema is missing an `id` property");o.$id=e.external.uri(c)}De(o,r.defId?r.schema:r.def??r.schema);let i=e.metadataRegistry.get(t)?.id;if(i!==void 0&&o.id===i)delete o.id;let s=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let c of e.seen.entries()){let a=c[1];if(a.def&&a.defId){if(a.def.id===a.defId)delete a.def.id;V(s,a.defId,a.def)}}if(e.external)e.sharedEmitDoneFor=e.external;if(e.external);else if(Object.keys(s).length>0)if(e.target==="draft-2020-12")o.$defs=s;else o.definitions=s;try{let c=JSON.parse(JSON.stringify(o));return Object.defineProperty(c,"~standard",{value:{...t["~standard"],jsonSchema:{input:Le(t,"input",e.processors),output:Le(t,"output",e.processors)}},enumerable:!1,writable:!1}),c}catch(c){throw Error("Error converting schema to JSON.")}}function j(e,t){let r=t??{seen:new Set};if(r.seen.has(e))return!1;r.seen.add(e);let n=e._zod.def;if(n.type==="transform")return!0;if(n.type==="array")return j(n.element,r);if(n.type==="set")return j(n.valueType,r);if(n.type==="lazy")return j(n.getter(),r);if(n.type==="promise"||n.type==="optional"||n.type==="nonoptional"||n.type==="nullable"||n.type==="readonly"||n.type==="default"||n.type==="prefault"||n.type==="catch")return j(n.innerType,r);if(n.type==="intersection")return j(n.left,r)||j(n.right,r);if(n.type==="record"||n.type==="map")return j(n.keyType,r)||j(n.valueType,r);if(n.type==="pipe"){if(e._zod.traits.has("$ZodCodec"))return!0;return j(n.in,r)||j(n.out,r)}if(n.type==="object"){for(let o in n.shape)if(j(n.shape[o],r))return!0;return!1}if(n.type==="union"){for(let o of n.options)if(j(o,r))return!0;return!1}if(n.type==="tuple"){for(let o of n.items)if(j(o,r))return!0;if(n.rest&&j(n.rest,r))return!0;return!1}return!1}var zs=(e,t={})=>(r)=>{let n=Tr({...r,processors:t});return C(e,n),Zr(n,e),Ir(n,e)},Le=(e,t,r={})=>(n)=>{let{libraryOptions:o,target:i}=n??{},s=Tr({...o??{},target:i,io:t,processors:r});return C(e,s),Zr(s,e),Ir(s,e)};var be=(e,t,r)=>{if(e[t]===void 0||r>e[t])e[t]=r},xe=(e,t,r)=>{if(e[t]===void 0||r<e[t])e[t]=r},Ps=(e,t)=>{be(e,"minimum",t),xe(e,"maximum",t)},Is=(e,t)=>{if(e.multipleOf??(e.multipleOf=[]),!e.multipleOf.includes(t))e.multipleOf.push(t)},Os=(e,t)=>{e.patterns??(e.patterns=new Set),e.patterns.add(t)},Cs=(e,t)=>{e.mime=e.mime?e.mime.filter((r)=>t.includes(r)):[...t]},As=(e,t)=>{if(e.format=t,t.includes("int"))e.isInt=!0},Ss=(e,t)=>be(e,"minimum",t.minimum),Ts=(e,t)=>xe(e,"maximum",t.maximum),Zs=(e)=>(t,r)=>{As(t,r.format);let[n,o]=e[r.format];be(t,"minimum",n),xe(t,"maximum",o)},Tu={greater_than:(e,t)=>be(e,t.inclusive?"minimum":"exclusiveMinimum",t.value),less_than:(e,t)=>xe(e,t.inclusive?"maximum":"exclusiveMaximum",t.value),multiple_of:(e,t)=>Is(e,t.value),number_format:Zs(Ge),bigint_format:Zs(Vt),min_length:Ss,max_length:Ts,length_equals:(e,t)=>Ps(e,t.length),min_size:Ss,max_size:Ts,size_equals:(e,t)=>Ps(e,t.size),string_format:(e,t)=>{if(As(e,t.format),t.pattern)Os(e,t.pattern);if(t.format==="base64"||t.format==="base64url")e.contentEncoding=t.format;if(t.local||t.precision===-1)e.laxFormat=!0},mime_type:(e,t)=>Cs(e,t.mime)};function E(e){let t={},r=e._zod.def,n=e._zod.traits.has("$ZodCheck")?[e,...r.checks??[]]:r.checks??[];for(let i of n)Tu[i._zod.def.check]?.(t,i._zod.def);let o=e._zod.bag;if(o.minimum!==void 0)be(t,"minimum",o.minimum);if(o.exclusiveMinimum!==void 0)be(t,"exclusiveMinimum",o.exclusiveMinimum);if(o.maximum!==void 0)xe(t,"maximum",o.maximum);if(o.exclusiveMaximum!==void 0)xe(t,"exclusiveMaximum",o.exclusiveMaximum);if(o.multipleOf!==void 0)Is(t,o.multipleOf);if(o.format!==void 0){if(t.format??(t.format=o.format),o.format.includes("int"))t.isInt=!0}if(o.mime)Cs(t,o.mime);for(let i of o.patterns??[])Os(t,i);return t}var Zu={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Iu=new Map([[ar,Vn],[dt,Wn]]),Ou=(e)=>Iu.get(e)??e,Es=(e,t,r,n)=>{let o=r;o.type="string";let{minimum:i,maximum:s,format:c,patterns:a,contentEncoding:u,laxFormat:l}=E(e);if(typeof i==="number")o.minLength=i;if(typeof s==="number")o.maxLength=s;if(c){if(o.format=Zu[c]??c,o.format==="")delete o.format;if(c==="time"||l)delete o.format}if(u)o.contentEncoding=u;if(a&&a.size>0){let d=[...a].map(Ou);if(d.length===1)o.pattern=d[0].source;else if(d.length>1)o.allOf=[...d.map((f)=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))]}},js=(e,t,r,n)=>{let o=r,{minimum:i,maximum:s,multipleOf:c,exclusiveMaximum:a,exclusiveMinimum:u,isInt:l}=E(e);o.type=l?"integer":"number";let d=typeof u==="number"&&u>=(i??Number.NEGATIVE_INFINITY),f=typeof a==="number"&&a<=(s??Number.POSITIVE_INFINITY),m=t.target==="draft-04"||t.target==="openapi-3.0";if(d)if(m)o.minimum=u,o.exclusiveMinimum=!0;else o.exclusiveMinimum=u;else if(typeof i==="number")o.minimum=i;if(f)if(m)o.maximum=a,o.exclusiveMaximum=!0;else o.exclusiveMaximum=a;else if(typeof s==="number")o.maximum=s;if(c){let h=new Set;for(let k of c)if(Number.isFinite(k)&&k!==0)h.add(Math.abs(k));else H(e,t,o,n,`A multipleOf divisor of ${k} cannot be represented in JSON Schema`);let[b,..._]=h;if(b!==void 0)o.multipleOf=b;if(_.length)o.allOf=[...o.allOf??[],..._.map((k)=>({multipleOf:k}))]}},Ns=(e,t,r,n)=>{r.type="boolean"},Rs=(e,t,r,n)=>{H(e,t,r,n,"BigInt cannot be represented in JSON Schema")};var Ds=(e,t,r,n)=>{r.not={}};var Ls=(e,t,r,n)=>{},Ms=(e,t,r,n)=>{H(e,t,r,n,"Date cannot be represented in JSON Schema")},Us=(e,t,r,n)=>{let o=e._zod.def,i=Te(o.entries);if(i.length===0){r.not={};return}if(i.every((s)=>typeof s==="number"))r.type="number";if(i.every((s)=>typeof s==="string"))r.type="string";r.enum=i},Fs=(e,t,r,n)=>{let o=e._zod.def;if(o.values.length===0){r.not={};return}let i=[];for(let s of o.values)if(s===void 0){if(H(e,t,r,n,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof s==="bigint"){if(H(e,t,r,n,"BigInt literals cannot be represented in JSON Schema"))return;i.push(Number(s))}else i.push(s);if(i.length===0);else if(i.length===1){let s=i[0];if(r.type=s===null?"null":typeof s,t.target==="draft-04"||t.target==="openapi-3.0")r.enum=[s];else r.const=s}else{if(i.every((s)=>typeof s==="number"))r.type="number";if(i.every((s)=>typeof s==="string"))r.type="string";if(i.every((s)=>typeof s==="boolean"))r.type="boolean";if(i.every((s)=>s===null))r.type="null";r.enum=i}};var Bs=(e,t,r,n)=>{H(e,t,r,n,"Custom types cannot be represented in JSON Schema")};var Js=(e,t,r,n)=>{H(e,t,r,n,"Transforms cannot be represented in JSON Schema")};var Ks=(e,t,r,n)=>{let o=r,i=e._zod.def,{minimum:s,maximum:c}=E(e);if(typeof s==="number")o.minItems=s;if(typeof c==="number")o.maxItems=c;o.type="array",o.items=C(i.element,t,{...n,path:[...n.path,"items"]})};function Or(e){let t=e._zod.def;if(t.type==="pipe"&&t.in._zod.traits.has("$ZodTransform"))return Or(t.out);if(t.type==="catch")return Or(t.innerType);return e._zod.optin}var Vs=(e,t,r,n)=>{let o=r,i=e._zod.def,s=i.shape;if(Object.getOwnPropertySymbols(s).length&&H(e,t,o,n,"Symbol keys cannot be represented in JSON Schema"))return;o.type="object",o.properties={};for(let u in s)V(o.properties,u,C(s[u],t,{...n,path:[...n.path,"properties",u]}));let a=[];for(let u of Object.keys(s)){let l=i.shape[u];if(t.io==="input"?Or(l)===void 0:l._zod.optout===void 0)a.push(u)}if(a.length>0)o.required=a;if(i.catchall?._zod.def.type==="never")o.additionalProperties=!1;else if(!i.catchall){if(t.io==="output")o.additionalProperties=!1}else if(i.catchall)o.additionalProperties=C(i.catchall,t,{...n,path:[...n.path,"additionalProperties"]})},Ws=(e,t,r,n)=>{let o=e._zod.def,i=o.inclusive===!1,s=o.options.map((c,a)=>C(c,t,{...n,path:[...n.path,i?"oneOf":"anyOf",a]}));if(i)r.oneOf=s;else r.anyOf=s},Gs=(e,t,r,n)=>{let o=e._zod.def,i=C(o.left,t,{...n,path:[...n.path,"allOf",0]}),s=C(o.right,t,{...n,path:[...n.path,"allOf",1]}),c=(u)=>("allOf"in u)&&Object.keys(u).length===1,a=[...c(i)?i.allOf:[i],...c(s)?s.allOf:[s]];r.allOf=a,t.intersections.push(a)};var Hs=(e,t,r,n)=>{let o=e._zod.def,i=C(o.innerType,t,n),s=t.seen.get(e);if(t.target==="openapi-3.0")s.ref=o.innerType,r.nullable=!0;else r.anyOf=[i,{type:"null"}]},Ys=(e,t,r,n)=>{let o=e._zod.def;C(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType},Cr=Symbol();function qs(e,t,r,n,o){let i=!1,s=JSON.stringify(e,(c,a)=>{if(typeof a!=="bigint")return a;return i=!0,null});if(!i)return JSON.parse(s);return H(t,r,n,o,"BigInt defaults cannot be represented in JSON Schema"),Cr}var Xs=(e,t,r,n)=>{let o=e._zod.def;C(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType;let s=qs(o.defaultValue,e,t,r,n);if(s!==Cr)r.default=s},Qs=(e,t,r,n)=>{let o=e._zod.def;C(o.innerType,t,n);let i=t.seen.get(e);if(i.ref=o.innerType,t.io!=="input")return;let s=qs(o.defaultValue,e,t,r,n);if(s!==Cr)r._prefault=s},ec=(e,t,r,n)=>{let o=e._zod.def;C(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType;let s;try{s=o.catchValue(void 0)}catch{H(e,t,r,n,"Dynamic catch values are not supported in JSON Schema");return}r.default=s},tc=(e,t,r,n)=>{let o=e._zod.def,i=o.in._zod.traits.has("$ZodTransform"),s=t.io==="input"?i?o.out:o.in:o.out;C(s,t,n);let c=t.seen.get(e);c.ref=s},rc=(e,t,r,n)=>{let o=e._zod.def;C(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType,r.readOnly=!0};var Ar=(e,t,r,n)=>{let o=e._zod.def;C(o.innerType,t,n);let i=t.seen.get(e);i.ref=o.innerType};var nc=new WeakSet([Object.prototype,Error.prototype]);function xt(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let n=r(this);return Object.defineProperty(this,t,{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,t,{value:n,configurable:!0,writable:!0})}})}var Mu=(e,t)=>{bn.init(e,t),e.name="ZodError";let r=Object.getPrototypeOf(e);if(nc.has(r))return;nc.add(r),xt(r,"format",(n)=>(o)=>vn(n,o)),xt(r,"flatten",(n)=>(o)=>xn(n,o)),xt(r,"addIssue",(n)=>(o)=>{n.issues.push(o),n.message=JSON.stringify(n.issues,Ze,2)}),xt(r,"addIssues",(n)=>(o)=>{n.issues.push(...o),n.message=JSON.stringify(n.issues,Ze,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}})};var F=p("ZodError",Mu,void 0,{Parent:Error});var oc=nt(F),ic=ot(F),sc=it(F),cc=st(F),ac=kn(F),uc=$n(F),lc=zn(F),pc=Pn(F),dc=Sn(F),fc=Tn(F),mc=Zn(F),hc=In(F);function Fu(){if(!U.localeError)G(mr())}function jr(){if(!U.memoizer)G({memoizer:Ci()})}var Z=p("ZodType",(e,t)=>(Fu(),P.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(M(t,{checks:[...t.checks??[],...e.map((r)=>typeof r==="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return q(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Rl(e,t))},superRefine(e,t){return this.check(Dl(e,t))},overwrite(e){return this.check(ue(e))},optional(){return _c(this)},exactOptional(){return $l(this)},nullable(){return bc(this)},nullish(){return _c(bc(this))},nonoptional(e){return Il(this,e)},array(){return N(this)},or(e){return kt([this,e])},and(e){return xl(this,e)},transform(e){return xc(this,kl(e))},default(e){return Sl(this,e)},prefault(e){return Zl(this,e)},catch(e){return Cl(this,e)},pipe(e){return xc(this,e)},readonly(){return jl(this)},describe(e){let t=this.clone();return fe.add(t,{description:e}),t},meta(...e){if(e.length===0)return fe.get(this);let t=this.clone();return fe.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 et(this,"~standard",{...cr(this),jsonSchema:{input:Le(this,"input"),output:Le(this,"output")}})},set "~standard"(e){re(this,"~standard",e)},parse:function e(t,r){return oc(this,t,r,{callee:e})},parseAsync:async function e(t,r){return await ic(this,t,r,{callee:e})},safeParse(e,t){return sc(this,e,t)},async safeParseAsync(e,t){return cc(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){re(this,"spa",e)},validate(e,t){return qt(this,e,t)},validateAsync(e,t){return Xt(this,e,t)},encode:function e(t,r){return ac(this,t,r,{callee:e})},decode:function e(t,r){return uc(this,t,r,{callee:e})},encodeAsync:async function e(t,r){return await lc(this,t,r,{callee:e})},decodeAsync:async function e(t,r){return await pc(this,t,r,{callee:e})},safeEncode(e,t){return dc(this,e,t)},safeDecode(e,t){return fc(this,e,t)},async safeEncodeAsync(e,t){return mc(this,e,t)},async safeDecodeAsync(e,t){return hc(this,e,t)},toJSONSchema(e){return zs(this,{})(e)},get description(){return fe.get(this)?.description},get _def(){return this._zod.def}}),vc=p("_ZodString",(e,t)=>{pt.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Es(e,r,n,o)},tt({format:(e)=>E(e).format??null,minLength:(e)=>E(e).minimum??null,maxLength:(e)=>E(e).maximum??null},{regex(...e){return this.check(gr(...e))},includes(...e){return this.check(br(...e))},startsWith(...e){return this.check(xr(...e))},endsWith(...e){return this.check(vr(...e))},min(...e){return this.check(_e(...e))},max(...e){return this.check(_t(...e))},length(...e){return this.check(bt(...e))},nonempty(...e){return this.check(_e(1,...e))},lowercase(e){return this.check(yr(e))},uppercase(e){return this.check(_r(e))},trim(){return this.check(kr())},normalize(...e){return this.check(wr(...e))},toLowerCase(){return this.check($r())},toUpperCase(){return this.check(zr())},slugify(){return this.check(Pr())}})),Nr=p("ZodString",(e,t)=>{pt.init(e,t),vc.init(e,t)},{email(e){return this.check(Ri(Wu,e))},url(e){return this.check(hr(wc,e))},jwt(e){return this.check(ns(ll,e))},emoji(e){return this.check(Bi(Yu,e))},guid(e){return this.check(Di(Gu,e))},uuid(e){return this.check(Li(vt,e))},uuidv4(e){return this.check(Mi(vt,e))},uuidv6(e){return this.check(Ui(vt,e))},uuidv7(e){return this.check(Fi(vt,e))},nanoid(e){return this.check(Ji(qu,e))},cuid(e){return this.check(Ki(Xu,e))},cuid2(e){return this.check(Vi(Qu,e))},ulid(e){return this.check(Wi(el,e))},base64(e){return this.check(es(cl,e))},base64url(e){return this.check(ts(al,e))},xid(e){return this.check(Gi(tl,e))},ksuid(e){return this.check(Hi(rl,e))},ipv4(e){return this.check(Yi(nl,e))},ipv6(e){return this.check(qi(ol,e))},cidrv4(e){return this.check(Xi(il,e))},cidrv6(e){return this.check(Qi(sl,e))},e164(e){return this.check(rs(ul,e))},datetime(e){return this.check(os(Bu,e))},date(e){return this.check(is(Ju,e))},time(e){return this.check(ss(Ku,e))},duration(e){return this.check(cs(Vu,e))}});function y(e){return ji(Nr,e)}var I=p("ZodStringFormat",(e,t)=>{S.init(e,t),vc.init(e,t)}),Bu=p("ZodISODateTime",(e,t)=>{Jo.init(e,t),I.init(e,t)}),Ju=p("ZodISODate",(e,t)=>{Ko.init(e,t),I.init(e,t)}),Ku=p("ZodISOTime",(e,t)=>{Vo.init(e,t),I.init(e,t)}),Vu=p("ZodISODuration",(e,t)=>{Wo.init(e,t),I.init(e,t)}),Wu=p("ZodEmail",(e,t)=>{Ao.init(e,t),I.init(e,t)});var Gu=p("ZodGUID",(e,t)=>{Oo.init(e,t),I.init(e,t)});var vt=p("ZodUUID",(e,t)=>{Co.init(e,t),I.init(e,t)});var wc=p("ZodURL",(e,t)=>{No.init(e,t),I.init(e,t)});function Hu(e){return hr(wc,e)}var Yu=p("ZodEmoji",(e,t)=>{Ro.init(e,t),I.init(e,t)});var qu=p("ZodNanoID",(e,t)=>{Do.init(e,t),I.init(e,t)});var Xu=p("ZodCUID",(e,t)=>{Lo.init(e,t),I.init(e,t)});var Qu=p("ZodCUID2",(e,t)=>{Mo.init(e,t),I.init(e,t)});var el=p("ZodULID",(e,t)=>{Uo.init(e,t),I.init(e,t)});var tl=p("ZodXID",(e,t)=>{Fo.init(e,t),I.init(e,t)});var rl=p("ZodKSUID",(e,t)=>{Bo.init(e,t),I.init(e,t)});var nl=p("ZodIPv4",(e,t)=>{Go.init(e,t),I.init(e,t)});var ol=p("ZodIPv6",(e,t)=>{Yo.init(e,t),I.init(e,t)});var il=p("ZodCIDRv4",(e,t)=>{qo.init(e,t),I.init(e,t)});var sl=p("ZodCIDRv6",(e,t)=>{Xo.init(e,t),I.init(e,t)});var cl=p("ZodBase64",(e,t)=>{ei.init(e,t),I.init(e,t)});var al=p("ZodBase64URL",(e,t)=>{ti.init(e,t),I.init(e,t)});var ul=p("ZodE164",(e,t)=>{ri.init(e,t),I.init(e,t)});var ll=p("ZodJWT",(e,t)=>{ni.init(e,t),I.init(e,t)});var wt=p("ZodNumber",(e,t)=>{ur.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>js(e,r,n,o),e.isFinite=!0},tt({minValue:(e)=>{let{minimum:t,exclusiveMinimum:r}=E(e);return Math.max(t??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:(e)=>{let{maximum:t,exclusiveMaximum:r}=E(e);return Math.min(t??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:(e)=>{let{isInt:t,multipleOf:r}=E(e);return!!t||!!r?.some(Number.isSafeInteger)},format:(e)=>E(e).format??null},{gt(e,t){return this.check(ye(e,t))},gte(e,t){return this.check(oe(e,t))},min(e,t){return this.check(oe(e,t))},lt(e,t){return this.check(ge(e,t))},lte(e,t){return this.check(ne(e,t))},max(e,t){return this.check(ne(e,t))},int(e){return this.check(gc(e))},safe(e){return this.check(gc(e))},positive(e){return this.check(ye(0,e))},nonnegative(e){return this.check(oe(0,e))},negative(e){return this.check(ge(0,e))},nonpositive(e){return this.check(ne(0,e))},multipleOf(e,t){return this.check(Re(e,t))},step(e,t){return this.check(Re(e,t))},finite(){return this}}));function K(e){return as(wt,e)}var pl=p("ZodNumberFormat",(e,t)=>{oi.init(e,t),wt.init(e,t)});function gc(e){return ls(pl,e)}var Rr=p("ZodBoolean",(e,t)=>{ii.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ns(e,r,n,o)});function B(e){return ps(Rr,e)}var kc=p("ZodBigInt",(e,t)=>{si.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Rs(e,r,n,o)},tt({minValue:(e)=>E(e).minimum??null,maxValue:(e)=>E(e).maximum??null,format:(e)=>E(e).format??null},{gte(e,t){return this.check(oe(e,t))},min(e,t){return this.check(oe(e,t))},gt(e,t){return this.check(ye(e,t))},lt(e,t){return this.check(ge(e,t))},lte(e,t){return this.check(ne(e,t))},max(e,t){return this.check(ne(e,t))},positive(e){return this.check(ye(BigInt(0),e))},negative(e){return this.check(ge(BigInt(0),e))},nonpositive(e){return this.check(ne(BigInt(0),e))},nonnegative(e){return this.check(oe(BigInt(0),e))},multipleOf(e,t){return this.check(Re(e,t))}}));var dl=p("ZodUnknown",(e,t)=>{ci.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ls(e,r,n,o)});function yc(){return ms(dl)}var fl=p("ZodNever",(e,t)=>{ai.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ds(e,r,n,o)});function ml(e){return hs(fl,e)}var $c=p("ZodDate",(e,t)=>{ui.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ms(e,r,n,o),e.min=(r,n)=>e.check(oe(r,n)),e.max=(r,n)=>e.check(ne(r,n))},tt({minDate:(e)=>{let{minimum:t}=E(e);return t?new Date(t):null},maxDate:(e)=>{let{maximum:t}=E(e);return t?new Date(t):null}},{}));var hl=p("ZodArray",(e,t)=>{jr(),li.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ks(e,r,n,o),e.element=t.element},{min(e,t){return this.check(_e(e,t))},nonempty(e){return this.check(_e(1,e))},max(e,t){return this.check(_t(e,t))},length(e,t){return this.check(bt(e,t))},unwrap(){return this.element}});function N(e,t){return ys(hl,e,t)}var gl=p("ZodObject",(e,t)=>{jr(),fi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Vs(e,r,n,o),Va(e,"shape",(r)=>r._zod.def.shape,!1)},{keyof(){return J(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(M(this._zod.def,{catchall:e}))},passthrough(){return this.clone(M(this._zod.def,{catchall:yc()}))},loose(){return this.clone(M(this._zod.def,{catchall:yc()}))},strict(){return this.clone(M(this._zod.def,{catchall:ml()}))},strip(){return this.clone(M(this._zod.def,{catchall:void 0}))},extend(e){return Da(this,e)},safeExtend(e){return La(this,e)},merge(e){return Ma(this,e)},pick(e){return Na(this,e)},omit(e){return Ra(this,e)},partial(...e){return ln(Sc,this,e[0])},exactPartial(...e){return ln(Tc,this,e[0],"exactPartial")},required(...e){return Ua(Zc,this,e[0])}});function w(e,t){let r={type:"object",shape:e??{},...g(t)};return new gl(r)}var zc=p("ZodUnion",(e,t)=>{lr.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ws(e,r,n,o),e.options=t.options});function kt(e,t){return new zc({type:"union",options:e,...g(t)})}var yl=p("ZodDiscriminatedUnion",(e,t)=>{zc.init(e,t),mi.init(e,t)});function _l(e,t,r){return new yl({type:"union",options:t,discriminator:e,...g(r)})}var bl=p("ZodIntersection",(e,t)=>{hi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Gs(e,r,n,o)});function xl(e,t){return new bl({type:"intersection",left:e,right:t})}var Er=p("ZodEnum",(e,t)=>{gi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(n,o,i)=>Us(e,n,o,i),e.enum=t.entries,e.options=[...e._zod.values];let r=new Set(Object.keys(t.entries));e.extract=(n,o)=>{let i={};for(let s of n)if(r.has(s))i[s]=t.entries[s];else throw Error(`Key ${s} not found in enum`);return new Er({...t,checks:[],...g(o),entries:i})},e.exclude=(n,o)=>{let i={...t.entries};for(let s of n)if(r.has(s))delete i[s];else throw Error(`Key ${s} not found in enum`);return new Er({...t,checks:[],...g(o),entries:i})}});function J(e,t){let r=Array.isArray(e)?Object.fromEntries(e.map((n)=>[n,n])):e;return new Er({type:"enum",entries:r,...g(t)})}var vl=p("ZodLiteral",(e,t)=>{yi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Fs(e,r,n,o),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 Pc(e,t){return new vl({type:"literal",values:Array.isArray(e)?e:[e],...g(t)})}var wl=p("ZodTransform",(e,t)=>{jr(),_i.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Js(e,r,n,o),e._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Ce(e.constructor.name);r.addIssue=(i)=>{if(typeof i==="string")r.issues.push(de(i,r.value,t));else{let s=i;if(s.fatal)s.continue=!1;if(s.code??(s.code="custom"),!("input"in s))s.input=r.value;s.inst??(s.inst=e),r.issues.push(de(s))}};let o=t.transform(r.value,r);if(o instanceof Promise)return o.then((i)=>(r.value=i,r));return r.value=o,r}});function kl(e){return new wl({type:"transform",transform:e})}var Sc=p("ZodOptional",(e,t)=>{pr.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ar(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function _c(e){return new Sc({type:"optional",innerType:e})}var Tc=p("ZodExactOptional",(e,t)=>{bi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ar(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function $l(e){return new Tc({type:"optional",innerType:e})}var zl=p("ZodNullable",(e,t)=>{xi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Hs(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function bc(e){return new zl({type:"nullable",innerType:e})}var Pl=p("ZodDefault",(e,t)=>{vi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Xs(e,r,n,o),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Sl(e,t){return new Pl({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():Jt(t)}})}var Tl=p("ZodPrefault",(e,t)=>{wi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Qs(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Zl(e,t){return new Tl({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():Jt(t)}})}var Zc=p("ZodNonOptional",(e,t)=>{ki.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ys(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Il(e,t){return new Zc({type:"nonoptional",innerType:e,...g(t)})}var Ol=p("ZodCatch",(e,t)=>{$i.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ec(e,r,n,o),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Cl(e,t){return new Ol({type:"catch",innerType:e,catchValue:typeof t==="function"?t:mn(t)})}var Al=p("ZodPipe",(e,t)=>{zi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>tc(e,r,n,o),e.in=t.in,e.out=t.out});function xc(e,t){return new Al({type:"pipe",in:e,out:t})}var El=p("ZodReadonly",(e,t)=>{Pi.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>rc(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function jl(e){return new El({type:"readonly",innerType:e})}var Nl=p("ZodCustom",(e,t)=>{Si.init(e,t),Z.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Bs(e,r,n,o)});function Rl(e,t={}){return _s(Nl,e,t)}function Dl(e,t){return bs(e,t)}function Ml(e){return Ni(Nr,e)}function Ul(e){return us(wt,e)}function Fl(e){return ds(Rr,e)}function Bl(e){return fs(kc,e)}function Jl(e){return gs($c,e)}var D=y().regex(/^\d{4}-\d{2}-\d{2}$/,"expected a date like 2026-11-16").describe("Calendar date, YYYY-MM-DD"),Ic=y().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/,"expected a local time like 2026-11-16T09:00").describe("Local date and time, YYYY-MM-DDTHH:mm, with no time zone"),T=y().min(1).max(64),zt=J(["open","completed","canceled"]),Kl=J(["inbox","anytime","someday"]),ve=["inbox","today","upcoming","anytime","someday","logbook","trash"],Vl=J(ve),Oc=w({id:T,title:y(),done:B()}),Cc=w({every:K().int().min(1).max(365),unit:J(["day","week","month","year"]),after:J(["schedule","completion"]).describe('"schedule" counts from the date it was due; "completion" counts from the day it was finished')}),Pt={createdAt:y(),updatedAt:y(),deletedAt:y().nullable(),rev:K().int()},Wl=w({id:T,title:y(),notes:y(),status:zt,when:Kl,scheduledFor:D.nullable(),deadline:D.nullable(),projectId:T.nullable(),areaId:T.nullable(),headingId:T.nullable(),tags:N(y()),checklist:N(Oc),remindAt:Ic.nullable().describe("When to send a reminder, in the person's local time."),evening:B().describe("Shown under This Evening when the to-do is in Today."),repeat:Cc.nullable().describe("Set on a to-do that comes back after it is completed."),position:K(),completedAt:y().nullable(),purged:B().describe("True once emptied from the trash. Clients drop these rows."),...Pt}),Gl=w({id:T,title:y(),notes:y(),status:zt,when:J(["anytime","someday"]),scheduledFor:D.nullable(),deadline:D.nullable(),areaId:T.nullable(),tags:N(y()),position:K(),completedAt:y().nullable(),purged:B().describe("True once emptied from the trash. Clients drop these rows."),...Pt}),Hl=w({id:T,title:y(),position:K(),...Pt}),Yl=w({id:T,projectId:T,title:y(),position:K(),...Pt}),ql=kt([J(["inbox","today","tomorrow","anytime","someday"]),D]).describe('"inbox", "today", "tomorrow", "anytime", "someday", or a date like 2026-12-01'),Xl=N(kt([y(),Oc.partial({id:!0,done:!0})])).describe("Sub-steps. Plain strings are fine."),Ql=w({id:T.optional().describe("Client-generated id, for offline creation. Omit to let the server pick."),title:y().min(1),notes:y().optional(),when:ql.optional().describe('"inbox", "today", "tomorrow", "anytime", "someday", or a date like 2026-12-01. Defaults to inbox, or to anytime when a project or area is given.'),deadline:D.nullable().optional(),projectId:T.nullable().optional(),areaId:T.nullable().optional(),headingId:T.nullable().optional(),tags:N(y()).optional(),checklist:Xl.optional(),remindAt:Ic.nullable().optional().describe("Local time for a reminder, like 2026-12-01T09:00."),evening:B().optional().describe("Put it under This Evening in Today."),repeat:Cc.nullable().optional().describe("Make it come back after it is completed."),position:K().optional()}),xm=Ql.omit({id:!0}).partial().extend({status:zt.optional()}),ep=w({id:T.optional(),title:y().min(1),notes:y().optional(),when:kt([J(["today","tomorrow","anytime","someday"]),D]).optional(),deadline:D.nullable().optional(),areaId:T.nullable().optional(),tags:N(y()).optional(),position:K().optional()}),vm=ep.omit({id:!0}).partial().extend({status:zt.optional()}),tp=w({id:T.optional(),title:y().min(1),position:K().optional()}),wm=tp.omit({id:!0}).partial(),km=w({id:T.optional(),projectId:T,title:y().min(1),position:K().optional()}),$m=w({title:y().min(1),position:K()}).partial(),zm=w({view:Vl.optional(),projectId:T.optional(),areaId:T.optional(),tag:y().optional(),q:y().optional().describe("Case-insensitive match on title and notes"),today:D.optional().describe("Override the server's idea of today (defaults to the account time zone)"),limit:Dr.number().int().min(1).max(500).optional()}),Ac=J(["bug","missing_capability","confusing","idea"]),Pm=w({kind:Ac.describe('"bug": it did the wrong thing. "missing_capability": a tool, field or filter that is not there. "confusing": a description or error that misled. "idea": anything else worth changing.'),summary:y().trim().min(5).max(200).describe("One line naming the problem."),intent:y().trim().max(2000).optional().describe("What you were trying to get done."),happened:y().trim().max(4000).optional().describe("What happened instead, with the error text if any."),tools:N(w({name:y().max(80),arguments:y().max(500).optional().describe('The shape of what was passed, not the values: "{view, tag, limit}"')})).max(20).optional().describe("The calls involved, in order."),proposedFix:y().trim().max(4000).optional().describe("The change that would have made this work.")}),Sm=J(["new","accepted","done","dismissed"]),Tm=w({id:T,kind:Ac,summary:y(),createdAt:y()}),Zm=w({id:T,email:y().nullable(),name:y().nullable(),timezone:y(),emailVerified:B(),today:D}),Im=w({rev:K().int(),full:B(),tasks:N(Wl),projects:N(Gl),areas:N(Hl),headings:N(Yl)}),Om=w({error:w({code:y(),message:y(),issues:N(w({path:y(),message:y()})).optional()})});var rp=w({id:y(),name:y(),color:y().nullable(),selected:B(),primary:B()}),jm=w({configured:B(),connected:B(),email:y().nullable(),calendars:N(rp)}),Nm=w({calendarIds:N(y().min(1).max(256)).max(100)}),Ec=y().regex(/^\d{2}:\d{2}$/),Rm=w({id:y(),calendarId:y(),title:y(),day:D,allDay:B(),start:Ec.nullable(),end:Ec.nullable(),color:y().nullable()}),Dm=w({from:D,to:D});class ee extends Error{status;code;issues;constructor(e,t,r,n){super(r);this.status=e;this.code=t;this.issues=n;this.name="BlumaError"}}async function Lr(e,t,r){let n=await(e.fetch??fetch)(`${e.baseUrl.replace(/\/+$/,"")}${t}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(r)}),o=await n.json().catch(()=>{});if(!n.ok)throw new ee(n.status,o?.error?.code??"http_error",o?.error?.message??`Request failed with HTTP ${n.status}`,o?.error?.issues);return o}var jc=(e,t,r)=>Lr(e,t,r),Nc=(e,t)=>Lr(e,"/v1/password/forgot",{email:t}),Rc=(e,t)=>Lr(e,"/v1/password/reset",t);var Dc=(e,t)=>jc(e,"/v1/signup",t);var Lc=(e,t)=>jc(e,"/v1/enter",t);function St(e){let t=e.baseUrl.replace(/\/+$/,""),r=e.fetch??fetch;async function n(o,i,s,c){let a=new URL(t+i);for(let[f,m]of Object.entries(c??{}))if(m!==void 0)a.searchParams.set(f,String(m));let u=await r(a,{method:o,headers:{authorization:`Bearer ${e.token}`,...e.client?{"x-bluma-client":e.client}:{},...s===void 0?{}:{"content-type":"application/json"}},body:s===void 0?void 0:JSON.stringify(s)}),l=await u.text(),d;try{d=l?JSON.parse(l):void 0}catch{d=void 0}if(!u.ok){let f=d?.error;throw new ee(u.status,f?.code??"http_error",f?.message??`Request failed with HTTP ${u.status}`,f?.issues)}return d}return{me:()=>n("GET","/v1/me"),updateMe:(o)=>n("PATCH","/v1/me",o),logout:()=>n("POST","/v1/logout"),setPassword:(o)=>n("POST","/v1/me/password",o),resendVerification:()=>n("POST","/v1/me/verify-email"),export:()=>n("GET","/v1/export"),deleteAccount:()=>n("DELETE","/v1/me"),sync:(o)=>n("GET","/v1/sync",void 0,{since:o}),tasks:{list:(o={})=>n("GET","/v1/tasks",void 0,o).then((i)=>i.tasks),get:(o)=>n("GET",`/v1/tasks/${o}`),create:(o)=>n("POST","/v1/tasks",o),update:(o,i)=>n("PATCH",`/v1/tasks/${o}`,i),complete:(o)=>n("PATCH",`/v1/tasks/${o}`,{status:"completed"}),cancel:(o)=>n("PATCH",`/v1/tasks/${o}`,{status:"canceled"}),reopen:(o)=>n("PATCH",`/v1/tasks/${o}`,{status:"open"}),trash:(o)=>n("DELETE",`/v1/tasks/${o}`),restore:(o)=>n("POST",`/v1/tasks/${o}/restore`)},projects:{list:(o={})=>n("GET","/v1/projects",void 0,o).then((i)=>i.projects),get:(o)=>n("GET",`/v1/projects/${o}`),create:(o)=>n("POST","/v1/projects",o),update:(o,i)=>n("PATCH",`/v1/projects/${o}`,i),trash:(o)=>n("DELETE",`/v1/projects/${o}`),restore:(o)=>n("POST",`/v1/projects/${o}/restore`)},areas:{list:()=>n("GET","/v1/areas").then((o)=>o.areas),create:(o)=>n("POST","/v1/areas",o),update:(o,i)=>n("PATCH",`/v1/areas/${o}`,i),trash:(o)=>n("DELETE",`/v1/areas/${o}`),restore:(o)=>n("POST",`/v1/areas/${o}/restore`)},headings:{list:(o)=>n("GET","/v1/headings",void 0,{projectId:o}).then((i)=>i.headings),create:(o)=>n("POST","/v1/headings",o),update:(o,i)=>n("PATCH",`/v1/headings/${o}`,i),trash:(o)=>n("DELETE",`/v1/headings/${o}`),restore:(o)=>n("POST",`/v1/headings/${o}/restore`)},tokens:{list:()=>n("GET","/v1/tokens").then((o)=>o.tokens),create:(o)=>n("POST","/v1/tokens",{name:o}),revoke:(o)=>n("DELETE",`/v1/tokens/${o}`)},calendar:{status:()=>n("GET","/v1/calendar"),select:(o)=>n("PUT","/v1/calendar",{calendarIds:o}),start:()=>n("GET","/v1/calendar/google/start"),finish:(o)=>n("POST","/v1/calendar/google/connect",{handoff:o}),disconnect:()=>n("DELETE","/v1/calendar/google"),events:(o,i)=>n("GET","/v1/calendar/events",void 0,{from:o,to:i}).then((s)=>s.events)},push:{config:()=>n("GET","/v1/push/config"),subscribe:(o)=>n("POST","/v1/push/subscriptions",o),unsubscribe:(o)=>n("DELETE",`/v1/push/subscriptions/${o}`)},sendFeedback:(o)=>n("POST","/v1/feedback",o),emptyTrash:()=>n("POST","/v1/trash/empty"),tags:()=>n("GET","/v1/tags").then((o)=>o.tags)}}function Mr(e){return`every ${e.every===1?e.unit:`${e.every} ${e.unit}s`}${e.after==="completion"?" after completion":""}`}var Jm=_l("kind",[w({kind:Pc("webpush"),endpoint:Hu().max(2048),p256dh:y().min(1).max(200),auth:y().min(1).max(100)}),w({kind:Pc("apns"),deviceToken:y().regex(/^[0-9a-fA-F]{32,200}$/,"expected the device token as hex"),bundleId:y().regex(/^[A-Za-z0-9.-]{1,155}$/),environment:J(["sandbox","production"])})]),Km=w({id:T,kind:J(["webpush","apns"])}),Vm=w({webpush:w({publicKey:y()}).nullable(),apns:B()});import{chmodSync as Kc,existsSync as Vc,mkdirSync as Wc,readFileSync as Gc,writeFileSync as Hc}from"node:fs";import{homedir as ap}from"node:os";import{dirname as Fr,join as Ur}from"node:path";var Mc={name:"@bluma/cli",version:"0.1.0",private:!0,type:"module",bin:{bluma:"./src/main.ts"},scripts:{build:"bun build src/main.ts --compile --outfile dist/bluma",typecheck:"tsc -p tsconfig.json",test:"bun test"},dependencies:{"@bluma/core":"workspace:*"}};var we=(e)=>String(e).padStart(2,"0"),Uc=(e)=>`${e.getFullYear()}-${we(e.getMonth()+1)}-${we(e.getDate())}`;function Fc(e){let t=/^(\d{1,2})(?::(\d{2}))?\s*(am|pm)?$/i.exec(e.trim());if(!t)return null;let r=Number(t[1]),n=Number(t[2]??0),o=t[3]?.toLowerCase();if(!o&&t[2]===void 0)return null;if(o&&(r<1||r>12))return null;if(o==="pm"&&r<12)r+=12;if(o==="am"&&r===12)r=0;if(r>23||n>59)return null;return`${we(r)}:${we(n)}`}function Bc(e,t){let r=e.trim().toLowerCase();if(r==="today")return Uc(t);if(r==="tomorrow"){let n=new Date(t);return n.setDate(n.getDate()+1),Uc(n)}return/^\d{4}-\d{2}-\d{2}$/.test(r)?r:null}var op='a time like "2026-12-01 09:00", "tomorrow 9am", "today 18:30" or "9am", or "none" to clear';function Jc(e,t=new Date){let r=e.trim();if(r.toLowerCase()==="none")return null;let n=()=>Error(`Could not read the reminder "${e}". Use ${op}.`),[o="",...i]=r.split(/[\sT]+/),s=i.join("").replace(/^at/i,""),c=Bc(o,t);if(c){if(s==="")return`${c}T09:00`;let l=Fc(s);if(!l)throw n();return`${c}T${l}`}let a=Fc(r.replace(/^at\s+/i,"").replace(/\s+/g,""));if(!a)throw n();let u=`${we(t.getHours())}:${we(t.getMinutes())}`;return`${Bc(a>u?"today":"tomorrow",t)}T${a}`}var ip={day:"day",week:"week",month:"month",year:"year"},sp={daily:"day",weekly:"week",monthly:"month",yearly:"year"},cp='"daily", "weekly", "monthly", "yearly", "every 2 weeks" or "every 3 days after completion", or "none" to clear';function Tt(e){let t=e.trim().toLowerCase().replace(/\s+/g," ");if(t==="none")return null;let r=/\bafter (completion|done|finishing)$/.test(t)?"completion":"schedule";t=t.replace(/ ?\bafter (completion|done|finishing)$/,"");let n=sp[t];if(n)return{every:1,unit:n,after:r};let o=/^every (?:(\d+|other) )?(day|week|month|year)s?$/.exec(t),i=o?.[2]?ip[o[2]]:void 0,s=o?.[1]==="other"?2:Number(o?.[1]??1);if(!i||s<1||s>365)throw Error(`Could not read the repeat "${e}". Use ${cp}.`);return{every:s,unit:i,after:r}}var It=Mc.version,Ue="https://api.bluma.sh",Yc={when:{type:"string",short:"w"},deadline:{type:"string",short:"d"},project:{type:"string",short:"p"},area:{type:"string",short:"a"},tag:{type:"string",short:"t",multiple:!0},notes:{type:"string",short:"n"},check:{type:"string",short:"c",multiple:!0},remind:{type:"string",short:"r"},evening:{type:"boolean"},"no-evening":{type:"boolean"},repeat:{type:"string"},"dry-run":{type:"boolean"},force:{type:"boolean"},db:{type:"string"},title:{type:"string"},query:{type:"string",short:"q"},kind:{type:"string"},details:{type:"string"},url:{type:"string"},token:{type:"string"},email:{type:"string"},"admin-secret":{type:"string"},timezone:{type:"string"},json:{type:"boolean"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}};class x extends Error{}function Br(e){return e.BLUMA_CONFIG??Ur(e.XDG_CONFIG_HOME??Ur(ap(),".config"),"bluma","config.json")}function Ot(e){let t=Br(e);if(!Vc(t))return{};try{return JSON.parse(Gc(t,"utf8"))}catch{throw new x(`Could not read ${t}. Fix or delete it, then run "bluma login" again.`)}}function $e(e,t){let r=Br(e);return Wc(Fr(r),{recursive:!0}),Hc(r,`${JSON.stringify(t,null,2)}
59
- `),Kc(r,384),r}function ze(e,t){let r=Ot(e.env),n=t.url??e.env.BLUMA_URL??r.url??Ue,o=t.token??e.env.BLUMA_TOKEN??r.token;if(!o)throw new x('Not signed in. Run "bluma login --email you@example.com" (or "bluma signup --email you@example.com" for a new account). For a script, set BLUMA_TOKEN or use "bluma login --token <token>".');return{url:n,token:o}}async function Pe(e,t,r="BLUMA_PASSWORD"){let n=e.env[r]??await e.askSecret?.(t);if(n===void 0)throw new x(`No terminal to ask on. Set ${r} instead.`);return n}var Ct=(e)=>Ur(Fr(Br(e)),"imports.json");function qc(e){let t=Ct(e);if(!Vc(t))return{};try{return JSON.parse(Gc(t,"utf8"))}catch{throw new x(`Could not read ${t}. Fix or delete it, then import again.`)}}function Xc(e,t){let r=Ct(e);Wc(Fr(r),{recursive:!0}),Hc(r,`${JSON.stringify(t)}
60
- `),Kc(r,384)}var Zt=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function Jr(e){return[Zt(e.areas,"area"),Zt(e.projects,"project"),Zt(e.headings,"heading"),Zt(e.tasks,"to-do")].join(", ")}var Kr=(e)=>Object.entries(e.skipped).map(([t,r])=>` left out ${r}: ${t}`);function ke(e,t,r){let n=r.toLowerCase(),o=t.filter((a)=>a.id===r||a.title.toLowerCase()===n),i=o.length>0?o:t.filter((a)=>a.id.startsWith(r)),s=i.length>0?i:t.filter((a)=>a.title.toLowerCase().includes(n));if(s.length===1&&s[0])return s[0];if(s.length===0)throw new x(`No ${e} matches "${r}".`);let c=s.map((a)=>` ${L(a.id)} ${a.title}`).join(`
61
- `);throw new x(`"${r}" matches more than one ${e}:
62
- ${c}`)}async function At(e,t){let r=(o)=>o.filter((i)=>i.id.startsWith(t)),n=r(await e.tasks.list({}));if(n.length===0){let[o,i]=await Promise.all([e.tasks.list({view:"logbook",limit:500}),e.tasks.list({view:"trash",limit:500})]);n=r([...i,...o.filter((s)=>s.deletedAt===null)])}if(n.length===1&&n[0])return n[0];if(n.length>1){let o=n.map((i)=>` ${L(i.id)} ${i.title}`).join(`
63
- `);throw new x(`"${t}" matches more than one task:
64
- ${o}`)}try{return await e.tasks.get(t)}catch(o){if(o instanceof ee&&o.status===404)throw new x(`No task matches "${t}".`);throw o}}async function Fe(e,t){let r={};if(t.project!==void 0)r.projectId=t.project==="none"?null:ke("project",await e.projects.list({status:"all"}),t.project).id;if(t.area!==void 0)r.areaId=t.area==="none"?null:ke("area",await e.areas.list(),t.area).id;return r}function Vr(e){let t={};if(e.title!==void 0)t.title=e.title;if(e.when!==void 0)t.when=e.when;if(e.deadline!==void 0)t.deadline=e.deadline==="none"?null:e.deadline;if(e.notes!==void 0)t.notes=e.notes;if(e.tag!==void 0)t.tags=e.tag;if(e.check!==void 0)t.checklist=e.check;try{if(e.remind!==void 0)t.remindAt=Jc(e.remind);if(e.repeat!==void 0)t.repeat=Tt(e.repeat)}catch(r){throw new x(r instanceof Error?r.message:String(r))}if(e.evening&&e["no-evening"])throw new x("Pass --evening or --no-evening, not both.");if(e.evening)t.evening=!0;if(e["no-evening"])t.evening=!1;return t}var L=(e)=>e.slice(0,6),up={open:"[ ]",completed:"[x]",canceled:"[-]"};function Qc(e,t){let r=[up[e.status],L(e.id),e.title];if(e.scheduledFor)r.push(`@${e.scheduledFor}`);if(e.deadline)r.push(`due ${e.deadline}`);if(e.evening)r.push("evening");if(e.remindAt)r.push(`remind ${e.remindAt.slice(5).replace("T"," ")}`);if(e.repeat)r.push(Mr(e.repeat));let n=e.projectId?t.get(e.projectId):void 0;if(n)r.push(`(${n})`);for(let o of e.tags)r.push(`#${o}`);if(e.checklist.length>0)r.push(`${e.checklist.filter((o)=>o.done).length}/${e.checklist.length}`);return r.join(" ")}function ea(e,t,r){let n=[["id",e.id],["status",e.status],["when",e.scheduledFor??e.when],["deadline",e.deadline],["evening",e.evening?"yes":null],["reminder",e.remindAt?.replace("T"," ")],["repeats",e.repeat&&Mr(e.repeat)],["project",e.projectId&&(t.get(e.projectId)??e.projectId)],["area",e.areaId&&(r.get(e.areaId)??e.areaId)],["tags",e.tags.join(", ")],["completed",e.completedAt],["trashed",e.deletedAt]],o=[e.title,...n.filter(([,i])=>i).map(([i,s])=>` ${i.padEnd(10)}${s}`)];if(e.notes)o.push("",...e.notes.split(`
65
- `).map((i)=>` ${i}`));if(e.checklist.length>0)o.push("",...e.checklist.map((i)=>` ${i.done?"[x]":"[ ]"} ${i.title}`));return o.join(`
66
- `)}var Be=(e)=>new Map(e.map((t)=>[t.id,t.title]));function ta(e,t,r,n){return{io:e,flags:t,command:r,rest:n,print:(o,i)=>e.out(t.json?JSON.stringify(o,null,2):i()),connect(){let{url:o,token:i}=ze(e,t);return St({baseUrl:o,token:i,fetch:e.fetch,client:`cli/${It}`})},need(o){if(n.length===0)throw new x(`Missing ${o}. Run "bluma --help" for usage.`);return n}}}function Je(e,t,r){return(n)=>{let o=n.connect(),[i,...s]=n.rest;if(i===void 0)return r(n,o,s);let c=Object.hasOwn(t,i)?t[i]:void 0;if(!c)throw new x(`Unknown ${e} command "${i}". Try: ${Object.keys(t).join(", ")}.`);return c(n,o,s)}}var Wr=({io:e,flags:t})=>t.url??e.env.BLUMA_URL??Ot(e.env).url??Ue;var oa=()=>Intl.DateTimeFormat().resolvedOptions().timeZone,ra=Je("token",{async add({print:e},t,r){if(r.length===0)throw new x("Missing a name for the token, such as the agent it is for.");let n=await t.tokens.create(r.join(" "));return e(n,()=>`${n.token}
67
- Save it now; it is not shown again. Revoke with: bluma token rm ${n.id}`),0},async rm({print:e},t,r){let n=await t.tokens.list(),o=ke("token",n.map((i)=>({...i,title:i.name})),r.join(" "));return await t.tokens.revoke(o.id),e({revoked:o.id},()=>`Revoked ${o.name}`),0}},async({print:e},t)=>{let r=await t.tokens.list();return e(r,()=>r.map((n)=>[L(n.id),n.kind==="session"?"device":"api ",n.name+(n.current?" (this one)":""),`made ${n.createdAt.slice(0,10)}`,n.lastUsedAt?`used ${n.lastUsedAt.slice(0,10)}`:"never used"].join(" ")).join(`
68
- `)),0}),lp=async(e)=>{let t=await e.connect().me();return e.print(t,()=>`${t.email??t.id} ${t.timezone} today is ${t.today}`),0};async function pp({io:e,flags:t,print:r},n){let{token:o}=ze(e,t),i=await St({baseUrl:n,token:o,fetch:e.fetch}).me(),s=$e(e.env,{url:n,token:o});return r({...i,config:s},()=>`Signed in as ${i.email??i.id}. Saved to ${s}`),0}var na=async(e)=>{let{io:t,flags:r,command:n,print:o}=e,i=Wr(e);if(n==="login"&&(r.token||!r.email))return pp(e,i);let{email:s}=r;if(!s)throw new x("signup needs --email.");let c=await Pe(t,"Password: "),a={email:s,password:c,device:"bluma cli"},u={baseUrl:i,fetch:t.fetch},l=n==="signup"?await Dc(u,{...a,timezone:r.timezone??oa()}):await Lc(u,a).catch((m)=>{if(m instanceof ee&&m.code==="no_account")throw new x(`No account for ${s} yet. Create one with: bluma signup --email ${s}`);throw m}),d=$e(t.env,{url:i,token:l.token.token}),f=n==="signup"?"Welcome to Bluma,":"Signed in as";return o({user:l.user,config:d},()=>`${f} ${l.user.email}. Saved to ${d}`),0},dp=async(e)=>{let{io:t,print:r}=e;await e.connect().logout().catch(()=>{});let n=$e(t.env,{url:Ot(t.env).url??Ue});return r({config:n},()=>"Signed out."),0};async function fp(e){let{io:t,flags:r,print:n}=e,o=Wr(e);if(!r.email)throw new x("password reset needs --email.");let i={baseUrl:o,fetch:t.fetch};if(!t.env.BLUMA_RESET_CODE)await Nc(i,r.email),t.err(`If ${r.email} has an account, a reset email is on its way. It works for 30 minutes.`);let s=await Pe(t,"Code from the email: ","BLUMA_RESET_CODE"),c=await Pe(t,"New password: ");return await Rc(i,{token:s.trim(),password:c}),$e(t.env,{url:o}),n({ok:!0},()=>`Password saved. Every device was signed out. Sign in with: bluma login --email ${r.email}`),0}var mp=async(e)=>{if(e.rest[0]==="reset")return fp(e);let{io:t,print:r}=e,n=await Pe(t,"Current password (empty if you never set one): ","BLUMA_CURRENT_PASSWORD"),o=await Pe(t,"New password: ");return await e.connect().setPassword({current:n||void 0,password:o}),r({ok:!0},()=>"Password saved."),0},hp=async({io:e,flags:t,print:r})=>{let n=t.url??e.env.BLUMA_URL??Ue,o=t["admin-secret"]??e.env.BLUMA_ADMIN_SECRET;if(!o||!t.email)throw new x("init needs --email and --admin-secret (or BLUMA_ADMIN_SECRET).");let i=await(e.fetch??fetch)(`${n.replace(/\/+$/,"")}/v1/bootstrap`,{method:"POST",headers:{authorization:`Bearer ${o}`,"content-type":"application/json"},body:JSON.stringify({email:t.email,timezone:t.timezone??oa(),tokenName:"cli"})}),s=await i.json();if(!i.ok||!s.token){let{code:a="http_error",message:u="Bootstrap failed"}=s.error??{};throw new ee(i.status,a,u)}let c=$e(e.env,{url:n,token:s.token.token});return r({url:n,config:c},()=>`Account ready for ${t.email}. Token saved to ${c}`),0},gp=async({io:e,flags:t,print:r})=>{let{url:n,token:o}=ze(e,t),i=`${n.replace(/\/+$/,"")}/mcp`,s={mcpServers:{bluma:{type:"http",url:i,headers:{Authorization:`Bearer ${o}`}}}};return r(s,()=>["Claude Code:",` claude mcp add --transport http bluma ${i} --header "Authorization: Bearer ${o}"`,"","Any other MCP client (Streamable HTTP):",JSON.stringify(s,null,2)].join(`
69
- `)),0},ia={tokens:ra,token:ra,whoami:lp,signup:na,login:na,logout:dp,password:mp,init:hp,mcp:gp};async function Gr(e,t){let{flags:r,print:n}=e,o=e.connect(),{projectId:i,areaId:s}=await Fe(o,r),[c,a]=await Promise.all([o.tasks.list({view:t,tag:r.tag?.[0],q:r.query,projectId:i??void 0,areaId:s??void 0}),o.projects.list({status:"all"})]),u=Be(a);return n(c,()=>c.length>0?c.map((l)=>Qc(l,u)).join(`
70
- `):"Nothing here."),0}var sa=(e)=>{let t=e.rest[0];if(t!==void 0&&!ve.includes(t))throw new x(`Unknown view "${t}". Choose one of: ${ve.join(", ")}.`);return Gr(e,t)};function Ke(e,t){return async(r)=>{let n=r.connect(),o=[];for(let i of r.need("a task id"))o.push(await t(n,await At(n,i)));return r.print(o.length===1?o[0]:o,()=>o.map((i)=>`${e} ${L(i.id)} ${i.title}`).join(`
71
- `)),0}}var yp=async(e)=>{let{flags:t,print:r}=e,n=e.connect(),o=e.need("a title").join(" "),i=await n.tasks.create({...Vr(t),...await Fe(n,t),title:o});return r(i,()=>`Added ${L(i.id)} ${i.title}`),0},_p=async(e)=>{let t=e.connect(),[r,n,o]=await Promise.all([At(t,e.need("a task id")[0]??""),t.projects.list({status:"all"}),t.areas.list()]);return e.print(r,()=>ea(r,Be(n),Be(o))),0},bp=async(e)=>{let{flags:t,print:r}=e,n=e.connect(),o=await At(n,e.need("a task id")[0]??""),i={...Vr(t),...await Fe(n,t)};if(Object.keys(i).length===0)throw new x("Nothing to change. Pass at least one option.");let s=await n.tasks.update(o.id,i);return r(s,()=>`Updated ${L(s.id)} ${s.title}`),0},xp=async(e)=>{let t=await e.connect().emptyTrash();return e.print(t,()=>t.tasks+t.projects===0?"The trash is already empty.":`Permanently deleted ${t.tasks} task(s) and ${t.projects} project(s).`),0},ca=Je("project",{async add({flags:e,print:t},r,n){if(n.length===0)throw new x("Missing a project title.");let{areaId:o}=await Fe(r,e),i=await r.projects.create({title:n.join(" "),notes:e.notes,when:e.when,deadline:e.deadline,areaId:o,tags:e.tag});return t(i,()=>`Added project ${L(i.id)} ${i.title}`),0},async done({print:e},t,r){let n=ke("project",await t.projects.list(),r.join(" ")),o=await t.projects.update(n.id,{status:"completed"});return e(o,()=>`Completed project ${L(o.id)} ${o.title}`),0}},async({print:e},t)=>{let[r,n,o]=await Promise.all([t.projects.list(),t.areas.list(),t.tasks.list({})]),i=Be(n),s=(c)=>{let a=o.filter((d)=>d.projectId===c.id).length,u=c.areaId?` (${i.get(c.areaId)??"?"})`:"",l=c.deadline?` due ${c.deadline}`:"";return`${L(c.id)} ${c.title} ${a} open${l}${u}`};return e(r,()=>r.length===0?"No projects yet.":r.map(s).join(`
72
- `)),0}),aa=Je("area",{async add({print:e},t,r){if(r.length===0)throw new x("Missing an area title.");let n=await t.areas.create({title:r.join(" ")});return e(n,()=>`Added area ${L(n.id)} ${n.title}`),0}},async({print:e},t)=>{let r=await t.areas.list();return e(r,()=>r.length===0?"No areas yet.":r.map((n)=>`${L(n.id)} ${n.title}`).join(`
73
- `)),0}),ua={bug:"bug",missing:"missing_capability",confusing:"confusing",idea:"idea"},vp=async(e)=>{let{flags:t,rest:r,print:n}=e,o=r.join(" ").trim();if(!o)throw new x('Say what it is about: bluma feedback "Upcoming skips repeating to-dos"');let i=ua[t.kind??"idea"];if(!i)throw new x(`--kind is one of: ${Object.keys(ua).join(", ")}`);let s=await e.connect().sendFeedback({kind:i,summary:o,happened:t.details});return n(s,()=>`Sent. Thank you. (report ${s.id.slice(0,6)})`),0},wp=async(e)=>(e.io.out(JSON.stringify(await e.connect().export(),null,2)),0),la={list:sa,ls:sa,add:yp,show:_p,edit:bp,done:Ke("Completed",(e,t)=>e.tasks.complete(t.id)),cancel:Ke("Canceled",(e,t)=>e.tasks.cancel(t.id)),reopen:Ke("Reopened",(e,t)=>e.tasks.reopen(t.id)),rm:Ke("Trashed",(e,t)=>e.tasks.trash(t.id)),restore:Ke("Restored",(e,t)=>e.tasks.restore(t.id)),"empty-trash":xp,projects:ca,project:ca,areas:aa,area:aa,export:wp,feedback:vp};import{existsSync as za,readFileSync as Rp}from"node:fs";import{copyFileSync as fa,existsSync as Hr,mkdtempSync as $p,readdirSync as zp,rmSync as Pp}from"node:fs";import{homedir as Sp,tmpdir as Tp}from"node:os";import{basename as Zp,join as Ve}from"node:path";class Et extends Error{}var kp="Reading the Things database needs the bluma binary, Bun, or Node 22.13 or newer";function pa(e){let{getBuiltinModule:t}=process;if(typeof t!=="function")return;let{emitWarning:r}=process;process.emitWarning=()=>{};try{return t.call(process,e)}catch{return}finally{process.emitWarning=r}}function da(e){if(process.versions.bun){let n=pa("bun:sqlite");if(n){let o=new n.Database(e);return{all:(i)=>o.query(i).all(),close:()=>o.close()}}}let t=pa("node:sqlite");if(!t)throw new Et(`${kp}. This is Node ${process.versions.node}.`);let r=new t.DatabaseSync(e);return{all:(n)=>r.prepare(n).all(),close:()=>r.close()}}var ga=()=>({areas:[],projects:[],headings:[],tasks:[],skipped:{}}),jt=(e,t,r=1)=>{if(r>0)e.skipped[t]=(e.skipped[t]??0)+r},Nt=(e)=>String(e).padStart(2,"0");function Rt(e){if(!e)return null;return`${e>>16&2047}-${Nt(e>>12&15)}-${Nt(e>>7&31)}`}function Ip(e){if(e===null)return null;return`${Nt(e>>26&31)}:${Nt(e>>20&63)}`}function ya(e=Sp()){let t=Ve(e,"Library","Group Containers","JLMPQHK86H.com.culturedcode.ThingsMac");if(!Hr(t))return null;return[...zp(t).filter((n)=>n.startsWith("ThingsData-")).map((n)=>Ve(t,n,"Things Database.thingsdatabase","main.sqlite")),Ve(t,"Things Database.thingsdatabase","main.sqlite")].find((n)=>Hr(n))??null}function _a(e){let t=$p(Ve(Tp(),"bluma-things-"));try{let r=Ve(t,"main.sqlite");fa(e,r);for(let o of["-wal","-shm"])if(Hr(e+o))fa(e+o,r+o);let n=da(r);try{let o=new Set(n.all("SELECT name FROM pragma_table_info('TMTask')").map((c)=>c.name)),i=o.has("heading")?"heading":"actionGroup",s=o.has("reminderTime")?"reminderTime":"NULL";return{areas:n.all('SELECT uuid, title FROM TMArea ORDER BY "index"'),tasks:n.all(`SELECT uuid, type, status, trashed, title, notes, start, startDate, startBucket, deadline,
74
- ${s} AS reminderTime, area, project, ${i} AS heading,
2
+ var x=["inbox","today","upcoming","anytime","someday","logbook","trash"];function N(e){let t="";for(let n of e){let r=n.codePointAt(0)??0,a=r<32&&r!==9&&r!==10||r>=127&&r<=159,s=r>=8234&&r<=8238||r>=8294&&r<=8297;if(!a&&!s)t+=n}return t}var fe={fileBytes:26214400,perTask:20,accountBytes:1073741824,name:255},ht=16;function ye(e){let t=N(e).replace(/[\t\n]/g," ").replace(/[/\\]/g,"").trim(),n=[...t],r=t;if(n.length>fe.name){let a=t.lastIndexOf("."),s=a>0?Array.from(t.slice(a)):[],o=s.length<=ht?s:[];r=[...n.slice(0,fe.name-o.length),...o].join("")}return r===""||r==="."||r===".."?"file":r}class w extends Error{status;code;issues;constructor(e,t,n,r){super(n);this.status=e;this.code=t;this.issues=r;this.name="BlumaError"}}class I extends Error{constructor(e){super(e instanceof Error?e.message:String(e),{cause:e});this.name="NetworkError"}}async function D(e,t,n){try{return await e(t,n)}catch(r){throw new I(r)}}async function we(e){try{return await e}catch(t){throw new I(t)}}async function L(e){let t=await we(e.text());try{return t?JSON.parse(t):void 0}catch{return}}async function B(e){let n=(await L(e))?.error;return new w(e.status,n?.code??"http_error",n?.message??`Request failed with HTTP ${e.status}`,n?.issues)}async function A(e,t,n,r={}){let a=await D(e.fetch??fetch,`${e.baseUrl.replace(/\/+$/,"")}${t}`,{method:"POST",headers:{...r,"content-type":"application/json"},body:JSON.stringify(n)});if(!a.ok)throw await B(a);return await L(a)}var ft=(e,t,n)=>A(e,t,n),ke=(e,t)=>A(e,"/v1/password/forgot",{email:t}),Te=(e,t)=>A(e,"/v1/password/reset",t);var be=(e,t)=>ft(e,"/v1/signup",t);var ve=(e,t)=>A(e,"/v1/enter",t);var Ce=(e,t,n)=>A(e,"/v1/bootstrap",n,{authorization:`Bearer ${t}`});function yt(e){let t=/filename\*=UTF-8''([^;\s]+)/i.exec(e??"")?.[1];if(!t)return null;try{return decodeURIComponent(t)}catch{return null}}var wt=1e4;async function kt(e){let t=await e(),n={rev:t.rev,full:t.full,tasks:[],projects:[],areas:[],headings:[]},r=t;for(let a=1;;a++){if(n.tasks.push(...r.tasks),n.projects.push(...r.projects),n.areas.push(...r.areas),n.headings.push(...r.headings),r.next===void 0||a>=wt)return n;r=await e(r.next)}}async function Tt(e,t,n){let r=await D(e.fetch,new URL(`${e.base}/v1/tasks/${encodeURIComponent(t)}/attachments`),{method:"POST",headers:{...e.identity,"content-type":n.contentType??"application/octet-stream","content-length":String(n.bytes.byteLength),"x-bluma-filename":encodeURIComponent(n.name)},body:n.bytes});if(!r.ok)throw await B(r);return await L(r)}async function bt(e,t){let n=await D(e.fetch,new URL(`${e.base}/v1/attachments/${encodeURIComponent(t)}`),{headers:e.identity});if(!n.ok)throw await B(n);return{name:yt(n.headers.get("content-disposition"))??t,contentType:n.headers.get("content-type")??"application/octet-stream",bytes:new Uint8Array(await we(n.arrayBuffer()))}}function F(e){let t=e.baseUrl.replace(/\/+$/,""),n=e.fetch??fetch,r={authorization:`Bearer ${e.token}`,...e.client?{"x-bluma-client":e.client}:{}},a={base:t,fetch:n,identity:r};async function s(o,i,c,l){let u=new URL(t+i);for(let[m,h]of Object.entries(l??{}))if(h!==void 0)u.searchParams.set(m,String(h));let p=await D(n,u,{method:o,headers:{...r,...c===void 0?{}:{"content-type":"application/json"}},body:c===void 0?void 0:JSON.stringify(c)});if(!p.ok)throw await B(p);return await L(p)}return{me:()=>s("GET","/v1/me"),updateMe:(o)=>s("PATCH","/v1/me",o),logout:()=>s("POST","/v1/logout"),setPassword:(o)=>s("POST","/v1/me/password",o),resendVerification:()=>s("POST","/v1/me/verify-email"),export:()=>s("GET","/v1/export"),deleteAccount:()=>s("DELETE","/v1/me"),sync:(o)=>s("GET","/v1/sync",void 0,{since:o}),syncPaged:(o,i)=>kt((c)=>s("GET","/v1/sync",void 0,{since:o,limit:i,after:c})),tasks:{list:(o={})=>s("GET","/v1/tasks",void 0,o).then((i)=>i.tasks),get:(o)=>s("GET",`/v1/tasks/${o}`),create:(o)=>s("POST","/v1/tasks",o),createMany:(o)=>s("POST","/v1/tasks/batch",{tasks:o}),update:(o,i)=>s("PATCH",`/v1/tasks/${o}`,i),complete:(o)=>s("PATCH",`/v1/tasks/${o}`,{status:"completed"}),cancel:(o)=>s("PATCH",`/v1/tasks/${o}`,{status:"canceled"}),reopen:(o)=>s("PATCH",`/v1/tasks/${o}`,{status:"open"}),trash:(o)=>s("DELETE",`/v1/tasks/${o}`),restore:(o)=>s("POST",`/v1/tasks/${o}/restore`)},attachments:{list:(o)=>s("GET",`/v1/tasks/${o}/attachments`).then((i)=>i.attachments),upload:(o,i)=>Tt(a,o,i),download:(o)=>bt(a,o),remove:(o)=>s("DELETE",`/v1/attachments/${o}`)},projects:{list:(o={})=>s("GET","/v1/projects",void 0,o).then((i)=>i.projects),get:(o)=>s("GET",`/v1/projects/${o}`),create:(o)=>s("POST","/v1/projects",o),update:(o,i)=>s("PATCH",`/v1/projects/${o}`,i),trash:(o)=>s("DELETE",`/v1/projects/${o}`),restore:(o)=>s("POST",`/v1/projects/${o}/restore`)},areas:{list:()=>s("GET","/v1/areas").then((o)=>o.areas),create:(o)=>s("POST","/v1/areas",o),update:(o,i)=>s("PATCH",`/v1/areas/${o}`,i),trash:(o)=>s("DELETE",`/v1/areas/${o}`),restore:(o)=>s("POST",`/v1/areas/${o}/restore`)},headings:{list:(o)=>s("GET","/v1/headings",void 0,{projectId:o}).then((i)=>i.headings),create:(o)=>s("POST","/v1/headings",o),update:(o,i)=>s("PATCH",`/v1/headings/${o}`,i),trash:(o)=>s("DELETE",`/v1/headings/${o}`),restore:(o)=>s("POST",`/v1/headings/${o}/restore`)},tokens:{list:()=>s("GET","/v1/tokens").then((o)=>o.tokens),create:(o,i={})=>s("POST","/v1/tokens",{name:o,...i}),revoke:(o)=>s("DELETE",`/v1/tokens/${o}`),revokeOthers:()=>s("POST","/v1/tokens/revoke-others")},calendar:{status:()=>s("GET","/v1/calendar"),select:(o)=>s("PUT","/v1/calendar",{calendarIds:o}),start:()=>s("GET","/v1/calendar/google/start"),finish:(o)=>s("POST","/v1/calendar/google/connect",{handoff:o}),disconnect:()=>s("DELETE","/v1/calendar/google"),events:(o,i)=>s("GET","/v1/calendar/events",void 0,{from:o,to:i}).then((c)=>c.events)},push:{config:()=>s("GET","/v1/push/config"),subscribe:(o)=>s("POST","/v1/push/subscriptions",o),unsubscribe:(o)=>s("DELETE",`/v1/push/subscriptions/${o}`)},sendFeedback:(o)=>s("POST","/v1/feedback",o),emptyTrash:()=>s("POST","/v1/trash/empty"),tags:()=>s("GET","/v1/tags").then((o)=>o.tags)}}function ee(e){return`every ${e.every===1?e.unit:`${e.every} ${e.unit}s`}${e.after==="completion"?" after completion":""}`}var te=()=>Intl.DateTimeFormat().resolvedOptions().timeZone;import{parseArgs as Pn}from"node:util";import{chmodSync as Ie,existsSync as Pt,mkdirSync as Ae,readFileSync as xt,writeFileSync as Re}from"node:fs";import{homedir as It}from"node:os";import{dirname as se,join as ne}from"node:path";var Se={name:"@bluma/cli",version:"0.2.0",private:!0,type:"module",bin:{bluma:"./src/main.ts"},scripts:{build:"bun build src/main.ts --compile --outfile dist/bluma",typecheck:"tsc -p tsconfig.json",test:"bun test"},dependencies:{"@bluma/core":"workspace:*"}};var C=(e)=>String(e).padStart(2,"0"),$e=(e)=>`${e.getFullYear()}-${C(e.getMonth()+1)}-${C(e.getDate())}`;function je(e){let t=/^(\d{1,2})(?::(\d{2}))?\s*(am|pm)?$/i.exec(e.trim());if(!t)return null;let n=Number(t[1]),r=Number(t[2]??0),a=t[3]?.toLowerCase();if(!a&&t[2]===void 0)return null;if(a&&(n<1||n>12))return null;if(a==="pm"&&n<12)n+=12;if(a==="am"&&n===12)n=0;if(n>23||r>59)return null;return`${C(n)}:${C(r)}`}function Pe(e,t){let n=e.trim().toLowerCase();if(n==="today")return $e(t);if(n==="tomorrow"){let r=new Date(t);return r.setDate(r.getDate()+1),$e(r)}return/^\d{4}-\d{2}-\d{2}$/.test(n)?n:null}var Ct='a time like "2026-12-01 09:00", "tomorrow 9am", "today 18:30" or "9am", or "none" to clear';function xe(e,t=new Date){let n=e.trim();if(n.toLowerCase()==="none")return null;let r=()=>Error(`Could not read the reminder "${e}". Use ${Ct}.`),[a="",...s]=n.split(/[\sT]+/),o=s.join("").replace(/^at/i,""),i=Pe(a,t);if(i){if(o==="")return`${i}T09:00`;let u=je(o);if(!u)throw r();return`${i}T${u}`}let c=je(n.replace(/^at\s+/i,"").replace(/\s+/g,""));if(!c)throw r();let l=`${C(t.getHours())}:${C(t.getMinutes())}`;return`${Pe(c>l?"today":"tomorrow",t)}T${c}`}var St={day:"day",week:"week",month:"month",year:"year"},$t={daily:"day",weekly:"week",monthly:"month",yearly:"year"},jt='"daily", "weekly", "monthly", "yearly", "every 2 weeks" or "every 3 days after completion", or "none" to clear';function _(e){let t=e.trim().toLowerCase().replace(/\s+/g," ");if(t==="none")return null;let n=/\bafter (completion|done|finishing)$/.test(t)?"completion":"schedule";t=t.replace(/ ?\bafter (completion|done|finishing)$/,"");let r=$t[t];if(r)return{every:1,unit:r,after:n};let a=/^every (?:(\d+|other) )?(day|week|month|year)s?$/.exec(t),s=a?.[2]?St[a[2]]:void 0,o=a?.[1]==="other"?2:Number(a?.[1]??1);if(!s||o<1||o>365)throw Error(`Could not read the repeat "${e}". Use ${jt}.`);return{every:o,unit:s,after:n}}var H=Se.version,R="https://api.bluma.sh",Ee={when:{type:"string",short:"w"},deadline:{type:"string",short:"d"},project:{type:"string",short:"p"},area:{type:"string",short:"a"},tag:{type:"string",short:"t",multiple:!0},notes:{type:"string",short:"n"},check:{type:"string",short:"c",multiple:!0},remind:{type:"string",short:"r"},evening:{type:"boolean"},"no-evening":{type:"boolean"},repeat:{type:"string"},"dry-run":{type:"boolean"},output:{type:"string",short:"o"},force:{type:"boolean"},db:{type:"string"},title:{type:"string"},query:{type:"string",short:"q"},kind:{type:"string"},details:{type:"string"},url:{type:"string"},token:{type:"string"},"read-only":{type:"boolean"},expires:{type:"string"},email:{type:"string"},"admin-secret":{type:"string"},timezone:{type:"string"},json:{type:"boolean"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}};class d extends Error{}var re=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e);function Oe(e,t,n){if(!Pt(e))return;let r;try{r=JSON.parse(xt(e,"utf8"))}catch{r=void 0}if(!t(r))throw new d(`Could not read ${e}. Fix or delete it, then ${n}.`);return r}var At=(e)=>re(e)&&["url","token"].every((t)=>e[t]===void 0||typeof e[t]==="string");function oe(e){return e.BLUMA_CONFIG??ne(e.XDG_CONFIG_HOME??ne(It(),".config"),"bluma","config.json")}var q=(e)=>Oe(oe(e),At,'run "bluma login" again')??{};function j(e,t){let n=oe(e);return Ae(se(n),{recursive:!0,mode:448}),Re(n,`${JSON.stringify(t,null,2)}
3
+ `,{mode:384}),Ie(n,384),n}function P(e,t){let n=q(e.env),r=t.url??e.env.BLUMA_URL??n.url??R,a=t.token??e.env.BLUMA_TOKEN??n.token;if(!a)throw new d('Not signed in. Run "bluma login --email you@example.com" (or "bluma signup --email you@example.com" for a new account). For a script, set BLUMA_TOKEN or use "bluma login --token <token>".');return{url:r,token:a}}async function T(e,t,n="BLUMA_PASSWORD"){let r=e.env[n]??await e.askSecret?.(t);if(r===void 0)throw new d(`No terminal to ask on. Set ${n} instead.`);return r}var Rt=(e)=>re(e)&&Object.values(e).every((t)=>re(t)&&Object.values(t).every((n)=>typeof n==="string")),z=(e)=>ne(se(oe(e)),"imports.json"),Me=(e)=>Oe(z(e),Rt,"import again")??{};function Ue(e,t){let n=z(e);Ae(se(n),{recursive:!0,mode:448}),Re(n,`${JSON.stringify(t)}
4
+ `,{mode:384}),Ie(n,384)}var K=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function ae(e){return[K(e.areas,"area"),K(e.projects,"project"),K(e.headings,"heading"),K(e.tasks,"to-do")].join(", ")}var ie=(e)=>Object.entries(e.skipped).map(([t,n])=>` left out ${n}: ${t}`);function S(e,t,n){let r=n.toLowerCase(),a=t.filter((c)=>c.id===n||c.title.toLowerCase()===r),s=a.length>0?a:t.filter((c)=>c.id.startsWith(n)),o=s.length>0?s:t.filter((c)=>c.title.toLowerCase().includes(r));if(o.length===1&&o[0])return o[0];if(o.length===0)throw new d(`No ${e} matches "${n}".`);let i=o.map((c)=>` ${g(c.id)} ${c.title}`).join(`
5
+ `);throw new d(`"${n}" matches more than one ${e}:
6
+ ${i}`)}async function b(e,t){try{return await e.tasks.get(t)}catch(l){if(!(l instanceof w&&l.status===404))throw l}let n=(l)=>l.filter((u)=>u.id.startsWith(t)),r=(l)=>e.tasks.list({view:l,idPrefix:t,limit:500}).then(n),[a,s,o]=await Promise.all([r(),r("logbook"),r("trash")]),i=a.length>0?a:[...o,...s.filter((l)=>l.deletedAt===null)];if(i.length===1&&i[0])return i[0];if(i.length===0)throw new d(`No task matches "${t}".`);let c=i.map((l)=>` ${g(l.id)} ${l.title}`).join(`
7
+ `);throw new d(`"${t}" matches more than one task:
8
+ ${c}`)}async function E(e,t){let n={};if(t.project!==void 0)n.projectId=t.project==="none"?null:S("project",await e.projects.list({status:"all"}),t.project).id;if(t.area!==void 0)n.areaId=t.area==="none"?null:S("area",await e.areas.list(),t.area).id;return n}function ce(e){let t={};if(e.title!==void 0)t.title=e.title;if(e.when!==void 0)t.when=e.when;if(e.deadline!==void 0)t.deadline=e.deadline==="none"?null:e.deadline;if(e.notes!==void 0)t.notes=e.notes;if(e.tag!==void 0)t.tags=e.tag;if(e.check!==void 0)t.checklist=e.check;try{if(e.remind!==void 0)t.remindAt=xe(e.remind);if(e.repeat!==void 0)t.repeat=_(e.repeat)}catch(n){throw new d(n instanceof Error?n.message:String(n))}if(e.evening&&e["no-evening"])throw new d("Pass --evening or --no-evening, not both.");if(e.evening)t.evening=!0;if(e["no-evening"])t.evening=!1;return t}var g=(e)=>e.slice(0,6),Et={open:"[ ]",completed:"[x]",canceled:"[-]"};function Ne(e,t){let n=[Et[e.status],g(e.id),e.title];if(e.scheduledFor)n.push(`@${e.scheduledFor}`);if(e.deadline)n.push(`due ${e.deadline}`);if(e.evening)n.push("evening");if(e.remindAt)n.push(`remind ${e.remindAt.slice(5).replace("T"," ")}`);if(e.repeat)n.push(ee(e.repeat));let r=e.projectId?t.get(e.projectId):void 0;if(r)n.push(`(${r})`);for(let a of e.tags)n.push(`#${a}`);if(e.checklist.length>0)n.push(`${e.checklist.filter((a)=>a.done).length}/${e.checklist.length}`);return n.join(" ")}function De(e,t,n){let r=[["id",e.id],["status",e.status],["when",e.scheduledFor??e.when],["deadline",e.deadline],["evening",e.evening?"yes":null],["reminder",e.remindAt?.replace("T"," ")],["repeats",e.repeat&&ee(e.repeat)],["project",e.projectId&&(t.get(e.projectId)??e.projectId)],["area",e.areaId&&(n.get(e.areaId)??e.areaId)],["tags",e.tags.join(", ")],["completed",e.completedAt],["trashed",e.deletedAt]],a=[e.title,...r.filter(([,s])=>s).map(([s,o])=>` ${s.padEnd(10)}${o}`)];if(e.notes)a.push("",...e.notes.split(`
9
+ `).map((s)=>` ${s}`));if(e.checklist.length>0)a.push("",...e.checklist.map((s)=>` ${s.done?"[x]":"[ ]"} ${s.title}`));return a.join(`
10
+ `)}var O=(e)=>new Map(e.map((t)=>[t.id,t.title]));function Le(e,t,n){return{io:e,flags:t,rest:n,print:(r,a)=>e.out(t.json?JSON.stringify(r,null,2):a()),connect(){let{url:r,token:a}=P(e,t);return F({baseUrl:r,token:a,fetch:e.fetch,client:`cli/${H}`})},need(r){if(n.length===0)throw new d(`Missing ${r}. Run "bluma --help" for usage.`);return n}}}function v(e,t,n){return(r)=>{let a=r.connect(),[s,...o]=r.rest;if(s===void 0)return n(r,a,o);let i=Object.hasOwn(t,s)?t[s]:void 0;if(!i)throw new d(`Unknown ${e} command "${s}". Try: ${Object.keys(t).join(", ")}.`);return i(r,a,o)}}var W=({io:e,flags:t})=>t.url??e.env.BLUMA_URL??q(e.env).url??R;function Ot(e){if(e===void 0||e==="never")return;let t=/^(\d+)d?$/.exec(e.trim()),n=t?Number(t[1]):0;if(n<1||n>365)throw new d("--expires takes a number of days from 1 to 365, such as 30d.");return n}function Be(e){return`${e.scope==="read"?"read only":"can change"}, ${e.expiresAt?`expires ${e.expiresAt.slice(0,10)}`:"no expiry"}`}var Fe=v("token",{async add({print:e,flags:t},n,r){if(r.length===0)throw new d("Missing a name for the token, such as the agent it is for.");let a=Ot(t.expires),s=await n.tokens.create(r.join(" "),{scope:t["read-only"]?"read":"full",...a?{expiresInDays:a}:{}});return e(s,()=>`${s.token}
11
+ ${s.name}: ${Be(s)}.
12
+ Save it now; it is not shown again. Revoke with: bluma token rm ${s.id}`),0},async rm({print:e},t,n){let r=await t.tokens.list(),a=S("token",r.map((s)=>({...s,title:s.name})),n.join(" "));return await t.tokens.revoke(a.id),e({revoked:a.id},()=>`Revoked ${a.name}`),0}},async({print:e},t)=>{let n=await t.tokens.list();return e(n,()=>n.map((r)=>[g(r.id),r.kind==="session"?"device":"api ",r.name+(r.current?" (this one)":""),...r.kind==="api"?[Be(r)]:[],`made ${r.createdAt.slice(0,10)}`,r.lastUsedAt?`used ${r.lastUsedAt.slice(0,10)}`:"never used"].join(" ")).join(`
13
+ `)),0}),Mt=async(e)=>{let t=await e.connect().me();return e.print(t,()=>`${t.email??t.id} ${t.timezone} today is ${t.today}`),0};async function Ut({io:e,flags:t,print:n},r){let{token:a}=P(e,t),s=await F({baseUrl:r,token:a,fetch:e.fetch}).me(),o=j(e.env,{url:r,token:a});return n({...s,config:o},()=>`Signed in as ${s.email??s.id}. Saved to ${o}`),0}var _e="bluma cli";function Ke({io:e,print:t},n,r,a){let s=j(e.env,{url:n,token:r.token.token});return t({user:r.user,config:s},()=>`${a} ${r.user.email}. Saved to ${s}`),0}var Nt=async(e)=>{let{io:t,flags:n}=e,r=W(e);if(!n.email)throw new d("signup needs --email.");let a=await T(t,"Password: "),s={email:n.email,password:a,device:_e,timezone:n.timezone??te()};return Ke(e,r,await be({baseUrl:r,fetch:t.fetch},s),"Welcome to Bluma,")},Dt=async(e)=>{let{io:t,flags:n}=e,r=W(e),{email:a}=n;if(n.token||!a)return Ut(e,r);let s=await T(t,"Password: "),o=await ve({baseUrl:r,fetch:t.fetch},{email:a,password:s,device:_e}).catch((i)=>{if(i instanceof w&&i.code==="no_account")throw new d(`No account for ${a} yet. Create one with: bluma signup --email ${a}`);throw i});return Ke(e,r,o,"Signed in as")},Lt=async(e)=>{let{io:t,print:n}=e;await e.connect().logout().catch(()=>{});let r=j(t.env,{url:q(t.env).url??R});return n({config:r},()=>"Signed out."),0};async function Bt(e){let{io:t,flags:n,print:r}=e,a=W(e);if(!n.email)throw new d("password reset needs --email.");let s={baseUrl:a,fetch:t.fetch};if(!t.env.BLUMA_RESET_CODE)await ke(s,n.email),t.err(`If ${n.email} has an account, a reset email is on its way. It works for 30 minutes.`);let o=await T(t,"Code from the email: ","BLUMA_RESET_CODE"),i=await T(t,"New password: ");return await Te(s,{token:o.trim(),password:i}),j(t.env,{url:a}),r({ok:!0},()=>`Password saved. Every device was signed out. Sign in with: bluma login --email ${n.email}`),0}var Ft=async(e)=>{if(e.rest[0]==="reset")return Bt(e);let{io:t,print:n}=e,r=await T(t,"Current password (empty if you never set one): ","BLUMA_CURRENT_PASSWORD"),a=await T(t,"New password: ");return await e.connect().setPassword({current:r||void 0,password:a}),n({ok:!0},()=>"Password saved."),0},_t=async({io:e,flags:t,print:n})=>{let r=t.url??e.env.BLUMA_URL??R,a=t["admin-secret"]??e.env.BLUMA_ADMIN_SECRET;if(!a||!t.email)throw new d("init needs --email and --admin-secret (or BLUMA_ADMIN_SECRET).");let s=await Ce({baseUrl:r,fetch:e.fetch},a,{email:t.email,timezone:t.timezone??te(),tokenName:"cli"}),o=j(e.env,{url:r,token:s.token.token});return n({url:r,config:o},()=>`Account ready for ${t.email}. Token saved to ${o}`),0},Kt=async({io:e,flags:t,print:n})=>{let{url:r,token:a}=P(e,t),s=`${r.replace(/\/+$/,"")}/mcp`,o={mcpServers:{bluma:{type:"http",url:s,headers:{Authorization:`Bearer ${a}`}}}};return n(o,()=>["Claude Code:",` claude mcp add --transport http bluma ${s} --header "Authorization: Bearer ${a}"`,"","Any other MCP client (Streamable HTTP):",JSON.stringify(o,null,2)].join(`
14
+ `)),0},He={tokens:Fe,token:Fe,whoami:Mt,signup:Nt,login:Dt,logout:Lt,password:Ft,init:_t,mcp:Kt};async function le(e,t){let{flags:n,print:r}=e,a=e.connect(),{projectId:s,areaId:o}=await E(a,n),[i,c]=await Promise.all([a.tasks.list({view:t,tag:n.tag?.[0],q:n.query,projectId:s??void 0,areaId:o??void 0}),a.projects.list({status:"all"})]),l=O(c);return r(i,()=>i.length>0?i.map((u)=>Ne(u,l)).join(`
15
+ `):"Nothing here."),0}var qe=(e)=>{let t=e.rest[0];if(t!==void 0&&!x.includes(t))throw new d(`Unknown view "${t}". Choose one of: ${x.join(", ")}.`);return le(e,t)};function M(e,t){return async(n)=>{let r=n.connect(),a=[];for(let s of n.need("a task id"))a.push(await t(r,await b(r,s)));return n.print(a.length===1?a[0]:a,()=>a.map((s)=>`${e} ${g(s.id)} ${s.title}`).join(`
16
+ `)),0}}var Ht=async(e)=>{let{flags:t,print:n}=e,r=e.connect(),a=e.need("a title").join(" "),s=await r.tasks.create({...ce(t),...await E(r,t),title:a});return n(s,()=>`Added ${g(s.id)} ${s.title}`),0},qt=async(e)=>{let t=e.connect(),[n,r,a]=await Promise.all([b(t,e.need("a task id")[0]??""),t.projects.list({status:"all"}),t.areas.list()]);return e.print(n,()=>De(n,O(r),O(a))),0},zt=async(e)=>{let{flags:t,print:n}=e,r=e.connect(),a=await b(r,e.need("a task id")[0]??""),s={...ce(t),...await E(r,t)};if(Object.keys(s).length===0)throw new d("Nothing to change. Pass at least one option.");let o=await r.tasks.update(a.id,s);return n(o,()=>`Updated ${g(o.id)} ${o.title}`),0},Wt=async(e)=>{let t=await e.connect().emptyTrash();return e.print(t,()=>t.tasks+t.projects===0?"The trash is already empty.":`Permanently deleted ${t.tasks} task(s) and ${t.projects} project(s).`),0},ze=v("project",{async add({flags:e,print:t},n,r){if(r.length===0)throw new d("Missing a project title.");let{areaId:a}=await E(n,e),s=await n.projects.create({title:r.join(" "),notes:e.notes,when:e.when,deadline:e.deadline,areaId:a,tags:e.tag});return t(s,()=>`Added project ${g(s.id)} ${s.title}`),0},async done({print:e},t,n){let r=S("project",await t.projects.list(),n.join(" ")),a=await t.projects.update(r.id,{status:"completed"});return e(a,()=>`Completed project ${g(a.id)} ${a.title}`),0}},async({print:e},t)=>{let[n,r,a]=await Promise.all([t.projects.list(),t.areas.list(),t.tasks.list({})]),s=O(r),o=(i)=>{let c=a.filter((p)=>p.projectId===i.id).length,l=i.areaId?` (${s.get(i.areaId)??"?"})`:"",u=i.deadline?` due ${i.deadline}`:"";return`${g(i.id)} ${i.title} ${c} open${u}${l}`};return e(n,()=>n.length===0?"No projects yet.":n.map(o).join(`
17
+ `)),0}),We=v("area",{async add({print:e},t,n){if(n.length===0)throw new d("Missing an area title.");let r=await t.areas.create({title:n.join(" ")});return e(r,()=>`Added area ${g(r.id)} ${r.title}`),0}},async({print:e},t)=>{let n=await t.areas.list();return e(n,()=>n.length===0?"No areas yet.":n.map((r)=>`${g(r.id)} ${r.title}`).join(`
18
+ `)),0}),de={bug:"bug",missing:"missing_capability",confusing:"confusing",idea:"idea"},Gt=async(e)=>{let{flags:t,rest:n,print:r}=e,a=n.join(" ").trim();if(!a)throw new d('Say what it is about: bluma feedback "Upcoming skips repeating to-dos"');let s=t.kind??"idea",o=Object.hasOwn(de,s)?de[s]:null;if(!o)throw new d(`--kind is one of: ${Object.keys(de).join(", ")}`);let i=await e.connect().sendFeedback({kind:o,summary:a,happened:t.details});return r(i,()=>`Sent. Thank you. (report ${i.id.slice(0,6)})`),0},Yt=async(e)=>(e.io.out(JSON.stringify(await e.connect().export(),null,2)),0),Ge={list:qe,ls:qe,add:Ht,show:qt,edit:zt,done:M("Completed",(e,t)=>e.tasks.complete(t.id)),cancel:M("Canceled",(e,t)=>e.tasks.cancel(t.id)),reopen:M("Reopened",(e,t)=>e.tasks.reopen(t.id)),rm:M("Trashed",(e,t)=>e.tasks.trash(t.id)),restore:M("Restored",(e,t)=>e.tasks.restore(t.id)),"empty-trash":Wt,projects:ze,project:ze,areas:We,area:We,export:Yt,feedback:Gt};import{existsSync as ue,readFileSync as Vt,statSync as Ye,writeFileSync as Jt}from"node:fs";import{basename as Qt,dirname as Xt,extname as Zt,resolve as G}from"node:path";var en={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".pdf":"application/pdf",".txt":"text/plain",".log":"text/plain",".md":"text/markdown",".csv":"text/csv",".json":"application/json",".html":"text/html",".svg":"image/svg+xml",".zip":"application/zip"};function pe(e){if(e<1024)return`${e} B`;if(e<1048576)return`${Math.round(e/1024)} KB`;return`${(e/1024/1024).toFixed(1)} MB`}var tn=(e)=>`${e.id} ${e.name} ${pe(e.size)} ${e.contentType}`,nn=async(e)=>{let[t,...n]=e.need("a task id and a file");if(!t||n.length===0)throw new d("Missing a file. Usage: bluma attach <task> <file…>");let r=e.connect(),a=await b(r,t),s=[];for(let o of n){if(!ue(o)||!Ye(o).isFile())throw new d(`No file at ${o}.`);let i=new Uint8Array(Vt(o)),c=en[Zt(o).toLowerCase()]??"application/octet-stream";s.push(await r.attachments.upload(a.id,{name:Qt(o),contentType:c,bytes:i}))}return e.print(s.length===1?s[0]:s,()=>s.map((o)=>`Attached ${o.name} (${pe(o.size)}) to ${g(a.id)} ${a.title}`).join(`
19
+ `)),0},rn=async(e)=>{let t=e.connect(),n=await b(t,e.need("a task id")[0]??""),r=await t.attachments.list(n.id);return e.print(r,()=>r.length===0?"No files on this to-do.":r.map(tn).join(`
20
+ `)),0};function sn(e,t){let n=G(e.io.cwd??process.cwd()),r=ye(t),a=e.flags.output;if(a!==void 0&&!(ue(a)&&Ye(a).isDirectory()))return G(n,a);let s=G(n,a??"."),o=G(s,r);if(Xt(o)!==s)throw new d(`Refusing to save "${r}" outside ${s}. Pass -o <path>.`);return o}var on=v("attachment",{async get(e,t,[n]){if(!n)throw new d("Missing an attachment id. Usage: bluma attachment get <id> [-o path]");let r=await t.attachments.download(n),a=sn(e,r.name);if(ue(a)&&!e.flags.force)throw new d(`${a} already exists. Pass --force to overwrite it.`);return Jt(a,r.bytes,{flag:e.flags.force?"w":"wx"}),e.print({path:a,name:r.name,size:r.bytes.byteLength},()=>`Saved ${a} (${pe(r.bytes.byteLength)})`),0},async rm({print:e},t,n){if(n.length===0)throw new d("Missing an attachment id. Usage: bluma attachment rm <id…>");for(let r of n)await t.attachments.remove(r);return e({removed:n},()=>n.map((r)=>`Removed ${r}`).join(`
21
+ `)),0}},()=>{throw new d("Try: bluma attachment get <id> [-o path], or bluma attachment rm <id>.")}),Ve={attach:nn,attachments:rn,attachment:on};import{existsSync as lt,readFileSync as Sn}from"node:fs";import{copyFileSync as Xe,existsSync as me,mkdtempSync as cn,readdirSync as dn,rmSync as ln}from"node:fs";import{homedir as un,tmpdir as pn}from"node:os";import{basename as mn,join as U}from"node:path";class Y extends Error{}var an="Reading the Things database needs the bluma binary, Bun, or Node 22.13 or newer";function Je(e){let t=Reflect.get(process,"getBuiltinModule");if(typeof t!=="function")return;let{emitWarning:n}=process;process.emitWarning=()=>{};try{return t.call(process,e)}catch{return}finally{process.emitWarning=n}}function Qe(e){if(process.versions.bun){let r=Je("bun:sqlite");if(r){let a=new r.Database(e);return{all:(s)=>a.query(s).all(),close:()=>a.close()}}}let t=Je("node:sqlite");if(!t)throw new Y(`${an}. This is Node ${process.versions.node}.`);let n=new t.DatabaseSync(e);return{all:(r)=>n.prepare(r).all(),close:()=>n.close()}}var tt=()=>({areas:[],projects:[],headings:[],tasks:[],skipped:{}}),V=(e,t,n=1)=>{if(n>0)e.skipped[t]=(e.skipped[t]??0)+n},J=(e)=>String(e).padStart(2,"0");function Q(e){if(!e)return null;return`${e>>16&2047}-${J(e>>12&15)}-${J(e>>7&31)}`}function gn(e){if(e===null)return null;return`${J(e>>26&31)}:${J(e>>20&63)}`}function nt(e=un()){let t=U(e,"Library","Group Containers","JLMPQHK86H.com.culturedcode.ThingsMac");if(!me(t))return null;return[...dn(t).filter((r)=>r.startsWith("ThingsData-")).map((r)=>U(t,r,"Things Database.thingsdatabase","main.sqlite")),U(t,"Things Database.thingsdatabase","main.sqlite")].find((r)=>me(r))??null}function rt(e){let t=cn(U(pn(),"bluma-things-"));try{let n=U(t,"main.sqlite");Xe(e,n);for(let a of["-wal","-shm"])if(me(e+a))Xe(e+a,n+a);let r=Qe(n);try{let a=new Set(r.all("SELECT name FROM pragma_table_info('TMTask')").map((i)=>i.name)),s=a.has("heading")?"heading":"actionGroup",o=a.has("reminderTime")?"reminderTime":"NULL";return{areas:r.all('SELECT uuid, title FROM TMArea ORDER BY "index"'),tasks:r.all(`SELECT uuid, type, status, trashed, title, notes, start, startDate, startBucket, deadline,
22
+ ${o} AS reminderTime, area, project, ${s} AS heading,
75
23
  rt1_recurrenceRule IS NOT NULL AS repeats
76
- FROM TMTask ORDER BY "index"`),tags:n.all("SELECT TMTaskTag.tasks AS task, TMTag.title AS title FROM TMTaskTag JOIN TMTag ON TMTag.uuid = TMTaskTag.tags"),checklist:n.all('SELECT task, title, status FROM TMChecklistItem ORDER BY "index"')}}finally{n.close()}}finally{Pp(t,{recursive:!0,force:!0})}}var ma=(e)=>e.status===0&&e.trashed===0;function ba(e,t){if(e.start===0)return"inbox";if(e.start===2)return"someday";let r=Rt(e.startDate);if(!r)return"anytime";return r<=t?"today":r}function ha(e){let t=new Map;for(let{task:r,title:n}of e)t.set(r,[...t.get(r)??[],n]);return t}function Op(e,t){let r=e.heading&&t.everyHeading.has(e.heading)&&!t.headings.has(e.heading),n=e.project&&t.everyProject.has(e.project)&&!t.projects.has(e.project);return Boolean(r||n)}function Cp(e,t){if(e.trashed!==0)return"in the trash";if(e.status!==0)return"completed or canceled";if(e.repeats)return"repeating templates (set the repeat again in Bluma)";if(!e.title?.trim())return"without a title";return Op(e,t)?"inside a finished or trashed project":null}function Ap(e,t){let r=ba(e,t.today);return{key:e.uuid,title:e.title?.trim()||"Untitled project",notes:e.notes??"",areaKey:e.area&&t.areas.has(e.area)?e.area:null,when:r==="inbox"?null:r,deadline:Rt(e.deadline),tags:t.tags.get(e.uuid)??[]}}function Ep(e,t){let r=e.heading&&t.headings.has(e.heading)?e.heading:null,n=r?t.headings.get(r)??null:e.project,o=Rt(e.startDate),i=Ip(e.reminderTime);return{key:e.uuid,title:(e.title??"").trim(),notes:e.notes??"",when:ba(e,t.today),evening:e.startBucket===1,deadline:Rt(e.deadline),remindAt:o&&i?`${o}T${i}`:null,repeat:null,projectKey:n&&t.projects.has(n)?n:null,areaKey:!n&&e.area&&t.areas.has(e.area)?e.area:null,headingKey:r,tags:t.tags.get(e.uuid)??[],checklist:t.steps.get(e.uuid)??[]}}function xa(e,t){let r=ga(),n=(c)=>e.tasks.filter((a)=>a.type===c),o=e.checklist.flatMap((c)=>c.status===0&&c.title?[{task:c.task,title:c.title}]:[]),i={today:t,areas:new Set(e.areas.map((c)=>c.uuid)),projects:new Set,headings:new Map,everyProject:new Set(n(1).map((c)=>c.uuid)),everyHeading:new Set(n(2).map((c)=>c.uuid)),tags:ha(e.tags),steps:ha(o)};r.areas=e.areas.map((c)=>({key:c.uuid,title:c.title?.trim()||"Untitled area"}));for(let c of n(1).filter(ma))i.projects.add(c.uuid),r.projects.push(Ap(c,i));for(let c of n(2).filter(ma)){if(!c.project||!i.projects.has(c.project))continue;i.headings.set(c.uuid,c.project),r.headings.push({key:c.uuid,projectKey:c.project,title:c.title?.trim()||"Untitled heading"})}for(let c of n(0)){let a=Cp(c,i);if(a)jt(r,a);else r.tasks.push(Ep(c,i))}let s=new Set([...r.projects.map((c)=>c.areaKey),...r.tasks.map((c)=>c.areaKey)]);return jt(r,"empty areas",r.areas.filter((c)=>!s.has(c.key)).length),r.areas=r.areas.filter((c)=>s.has(c.key)),r}function jp(e){let t=[],r=[],n="",o=!1,i=e.replace(/^/,"");for(let s=0;s<i.length;s++){let c=i[s];if(o)if(c==='"'&&i[s+1]==='"')n+='"',s++;else if(c==='"')o=!1;else n+=c;else if(c==='"')o=!0;else if(c===",")r.push(n),n="";else if(c===`
77
- `||c==="\r"){if(c==="\r"&&i[s+1]===`
78
- `)s++;r.push(n),t.push(r),r=[],n=""}else n+=c}if(n!==""||r.length>0)t.push([...r,n]);return t}function Np(e){let t=5381;for(let r of e.join("\x00"))t=(t<<5)+t+r.charCodeAt(0)>>>0;return t.toString(36)}function va(e,t,r){let n=ga(),[o=[],...i]=jp(e),s=(m)=>o.findIndex((h)=>h.trim().toUpperCase()===m),c={type:s("TYPE"),content:s("CONTENT"),notes:s("DESCRIPTION")},a={priority:s("PRIORITY"),date:s("DATE")};if(c.type<0||c.content<0)throw Error("That does not look like a Todoist CSV export: it has no TYPE and CONTENT columns.");let u=(m,h)=>h<0?"":(m[h]??"").trim(),l=`todoist:${t}`;n.projects.push({key:l,title:t,notes:"",areaKey:null,when:null,deadline:null,tags:[]});let d=null,f;for(let m of i){let h=u(m,c.type).toLowerCase(),b=u(m,c.content);if(h==="section"&&b)d=`${l}:section:${b}`,n.headings.push({key:d,projectKey:l,title:b}),f=void 0;else if(h==="note"&&b&&f)f.notes=[f.notes,b].filter(Boolean).join(`
24
+ FROM TMTask ORDER BY "index"`),tags:r.all("SELECT TMTaskTag.tasks AS task, TMTag.title AS title FROM TMTaskTag JOIN TMTag ON TMTag.uuid = TMTaskTag.tags"),checklist:r.all('SELECT task, title, status FROM TMChecklistItem ORDER BY "index"')}}finally{r.close()}}finally{ln(t,{recursive:!0,force:!0})}}var Ze=(e)=>e.status===0&&e.trashed===0;function st(e,t){if(e.start===0)return"inbox";if(e.start===2)return"someday";let n=Q(e.startDate);if(!n)return"anytime";return n<=t?"today":n}function et(e){let t=new Map;for(let{task:n,title:r}of e)t.set(n,[...t.get(n)??[],r]);return t}function hn(e,t){let n=e.heading&&t.everyHeading.has(e.heading)&&!t.headings.has(e.heading),r=e.project&&t.everyProject.has(e.project)&&!t.projects.has(e.project);return Boolean(n||r)}function fn(e,t){if(e.trashed!==0)return"in the trash";if(e.status!==0)return"completed or canceled";if(e.repeats)return"repeating templates (set the repeat again in Bluma)";if(!e.title?.trim())return"without a title";return hn(e,t)?"inside a finished or trashed project":null}function yn(e,t){let n=st(e,t.today);return{key:e.uuid,title:e.title?.trim()||"Untitled project",notes:e.notes??"",areaKey:e.area&&t.areas.has(e.area)?e.area:null,when:n==="inbox"?null:n,deadline:Q(e.deadline),tags:t.tags.get(e.uuid)??[]}}function wn(e,t){let n=e.heading&&t.headings.has(e.heading)?e.heading:null,r=n?t.headings.get(n)??null:e.project,a=Q(e.startDate),s=gn(e.reminderTime);return{key:e.uuid,title:(e.title??"").trim(),notes:e.notes??"",when:st(e,t.today),evening:e.startBucket===1,deadline:Q(e.deadline),remindAt:a&&s?`${a}T${s}`:null,repeat:null,projectKey:r&&t.projects.has(r)?r:null,areaKey:!r&&e.area&&t.areas.has(e.area)?e.area:null,headingKey:n,tags:t.tags.get(e.uuid)??[],checklist:t.steps.get(e.uuid)??[]}}function ot(e,t){let n=tt(),r=(i)=>e.tasks.filter((c)=>c.type===i),a=e.checklist.flatMap((i)=>i.status===0&&i.title?[{task:i.task,title:i.title}]:[]),s={today:t,areas:new Set(e.areas.map((i)=>i.uuid)),projects:new Set,headings:new Map,everyProject:new Set(r(1).map((i)=>i.uuid)),everyHeading:new Set(r(2).map((i)=>i.uuid)),tags:et(e.tags),steps:et(a)};n.areas=e.areas.map((i)=>({key:i.uuid,title:i.title?.trim()||"Untitled area"}));for(let i of r(1).filter(Ze))s.projects.add(i.uuid),n.projects.push(yn(i,s));for(let i of r(2).filter(Ze)){if(!i.project||!s.projects.has(i.project))continue;s.headings.set(i.uuid,i.project),n.headings.push({key:i.uuid,projectKey:i.project,title:i.title?.trim()||"Untitled heading"})}for(let i of r(0)){let c=fn(i,s);if(c)V(n,c);else n.tasks.push(wn(i,s))}let o=new Set([...n.projects.map((i)=>i.areaKey),...n.tasks.map((i)=>i.areaKey)]);return V(n,"empty areas",n.areas.filter((i)=>!o.has(i.key)).length),n.areas=n.areas.filter((i)=>o.has(i.key)),n}function kn(e){let t=[],n=[],r="",a=!1,s=e.replace(/^/,"");for(let o=0;o<s.length;o++){let i=s[o];if(a)if(i==='"'&&s[o+1]==='"')r+='"',o++;else if(i==='"')a=!1;else r+=i;else if(i==='"')a=!0;else if(i===",")n.push(r),r="";else if(i===`
25
+ `||i==="\r"){if(i==="\r"&&s[o+1]===`
26
+ `)o++;n.push(r),t.push(n),n=[],r=""}else r+=i}if(r!==""||n.length>0)t.push([...n,r]);return t}function Tn(e){let t=5381;for(let n of e.join("\x00"))t=(t<<5)+t+n.charCodeAt(0)>>>0;return t.toString(36)}function at(e,t,n){let r=tt(),[a=[],...s]=kn(e),o=(h)=>a.findIndex((f)=>f.trim().toUpperCase()===h),i={type:o("TYPE"),content:o("CONTENT"),notes:o("DESCRIPTION")},c={priority:o("PRIORITY"),date:o("DATE")};if(i.type<0||i.content<0)throw Error("That does not look like a Todoist CSV export: it has no TYPE and CONTENT columns.");let l=(h,f)=>f<0?"":(h[f]??"").trim(),u=`todoist:${t}`;r.projects.push({key:u,title:t,notes:"",areaKey:null,when:null,deadline:null,tags:[]});let p=null,m;for(let h of s){let f=l(h,i.type).toLowerCase(),k=l(h,i.content);if(f==="section"&&k)p=`${u}:section:${k}`,r.headings.push({key:p,projectKey:u,title:k}),m=void 0;else if(f==="note"&&k&&m)m.notes=[m.notes,k].filter(Boolean).join(`
79
27
 
80
- `);else if(h==="task"&&b){let _=u(m,a.date),k=[u(m,c.notes)],R="anytime",ie=null;if(/^\d{4}-\d{2}-\d{2}$/.test(_))R=_<=r?"today":_;else if(_.toLowerCase()==="today"||_.toLowerCase()==="tomorrow")R=_.toLowerCase();else if(_)try{ie=Tt(_.replace(/^every day$/i,"daily"))}catch{k.push(`Date in Todoist: ${_}`),jt(n,"dates kept as a note")}let le=u(m,a.priority);f={key:`${l}:${Np([d??"",b,_])}`,title:b,notes:k.filter(Boolean).join(`
28
+ `);else if(f==="task"&&k){let y=l(h,c.date),ge=[l(h,i.notes)],Z="anytime",he=null;if(/^\d{4}-\d{2}-\d{2}$/.test(y))Z=y<=n?"today":y;else if(y.toLowerCase()==="today"||y.toLowerCase()==="tomorrow")Z=y.toLowerCase();else if(y)try{he=_(y.replace(/^every day$/i,"daily"))}catch{ge.push(`Date in Todoist: ${y}`),V(r,"dates kept as a note")}let gt=l(h,c.priority);m={key:`${u}:${Tn([p??"",k,y])}`,title:k,notes:ge.filter(Boolean).join(`
81
29
 
82
- `),when:R,evening:!1,deadline:null,remindAt:null,repeat:ie,projectKey:l,areaKey:null,headingKey:d,tags:le==="1"?["p1"]:[],checklist:[]},n.tasks.push(f)}}return n}var wa=(e)=>Zp(e).replace(/\.csv$/i,""),Dt=(e)=>({areas:e.areas.length,projects:e.projects.length,headings:e.headings.length,tasks:e.tasks.length});function ka(e,t){let r=(c)=>c.filter((a)=>!(a.key in t)),n=Dt(e),o={...e,areas:r(e.areas),projects:r(e.projects),headings:r(e.headings),tasks:r(e.tasks),skipped:{...e.skipped}},i=Dt(o),s=Object.values(n).reduce((c,a)=>c+a,0);return jt(o,"already imported",s-Object.values(i).reduce((c,a)=>c+a,0)),o}async function $a(e,t,r,n){let o=(s)=>s?r[s]??null:null,i={areas:0,projects:0,headings:0,tasks:0};try{for(let s of t.areas)r[s.key]=(await e.areas.create({title:s.title})).id,i.areas++;for(let s of t.projects){let c=await e.projects.create({title:s.title,notes:s.notes,areaId:o(s.areaKey),when:s.when??void 0,deadline:s.deadline,tags:s.tags});r[s.key]=c.id,i.projects++}for(let s of t.headings){let c=o(s.projectKey);if(!c)continue;r[s.key]=(await e.headings.create({projectId:c,title:s.title})).id,i.headings++}for(let s of t.tasks){let c=await e.tasks.create({title:s.title,notes:s.notes,when:s.when,evening:s.evening,deadline:s.deadline,remindAt:s.remindAt,repeat:s.repeat,headingId:o(s.headingKey),projectId:s.headingKey?void 0:o(s.projectKey),areaId:s.projectKey?void 0:o(s.areaKey),tags:s.tags,checklist:s.checklist});if(r[s.key]=c.id,i.tasks++,i.tasks%25===0)n()}}finally{n()}return i}function Dp(e,t){let r=e??ya();if(!r||!za(r))throw new x("Could not find the Things database on this Mac. Pass its path with --db.");try{return xa(_a(r),t)}catch(n){if(n instanceof Et)throw new x(n.message);throw n}}function Lp(e,t){if(e.length===0)throw new x("Which file? Pass one or more Todoist CSV exports.");let r={areas:[],projects:[],headings:[],tasks:[],skipped:{}};for(let n of e){if(!za(n))throw new x(`No file at ${n}.`);let o;try{o=va(Rp(n,"utf8"),wa(n),t)}catch(i){throw new x(`${n}: ${i instanceof Error?i.message:String(i)}`)}r.projects.push(...o.projects),r.headings.push(...o.headings),r.tasks.push(...o.tasks);for(let[i,s]of Object.entries(o.skipped))r.skipped[i]=(r.skipped[i]??0)+s}return r}var Pa=async(e)=>{let{io:t,flags:r,print:n}=e,[o,...i]=e.rest;if(o!=="things"&&o!=="todoist")throw new x('Import from where? Use "bluma import things" or "bluma import todoist <file.csv>".');let s=e.connect(),c=await s.me(),a=o==="things"?Dp(r.db,c.today):Lp(i,c.today),u=qc(t.env),l=`${ze(t,r).url}#${c.id}#${o}`,d=r.force?{}:u[l]??{},f=ka(a,d),m=Dt(f);if(r["dry-run"])return n({dryRun:!0,wouldCreate:m,skipped:f.skipped},()=>[`Would create ${Jr(m)}.`,...Kr(f),"Nothing was changed."].join(`
83
- `)),0;u[l]=d;let h=await $a(s,f,d,()=>Xc(t.env,u));return n({created:h,skipped:f.skipped},()=>[`Imported ${Jr(h)}.`,...Kr(f),`What was imported is noted in ${Ct(t.env)}, so running this again adds only what is new.`].join(`
84
- `)),0};var Up=`bluma ${It} — tasks from the terminal
30
+ `),when:Z,evening:!1,deadline:null,remindAt:null,repeat:he,projectKey:u,areaKey:null,headingKey:p,tags:gt==="1"?["p1"]:[],checklist:[]},r.tasks.push(m)}}return r}var it=(e)=>mn(e).replace(/\.csv$/i,""),X=(e)=>({areas:e.areas.length,projects:e.projects.length,headings:e.headings.length,tasks:e.tasks.length});function ct(e,t){let n=(i)=>i.filter((c)=>!(c.key in t)),r=X(e),a={...e,areas:n(e.areas),projects:n(e.projects),headings:n(e.headings),tasks:n(e.tasks),skipped:{...e.skipped}},s=X(a),o=Object.values(r).reduce((i,c)=>i+c,0);return V(a,"already imported",o-Object.values(s).reduce((i,c)=>i+c,0)),a}var bn=100,vn=393216;function Cn(e,t){let n=[],r=[],a=0;for(let s of e){let o=JSON.stringify(t(s)).length;if(r.length>0&&(r.length>=bn||a+o>vn))n.push(r),r=[],a=0;r.push(s),a+=o}if(r.length>0)n.push(r);return n}async function dt(e,t,n,r){let a=(o)=>o?n[o]??null:null,s={areas:0,projects:0,headings:0,tasks:0};try{for(let i of t.areas)n[i.key]=(await e.areas.create({title:i.title})).id,s.areas++;for(let i of t.projects){let c=await e.projects.create({title:i.title,notes:i.notes,areaId:a(i.areaKey),when:i.when??void 0,deadline:i.deadline,tags:i.tags});n[i.key]=c.id,s.projects++}for(let i of t.headings){let c=a(i.projectKey);if(!c)continue;n[i.key]=(await e.headings.create({projectId:c,title:i.title})).id,s.headings++}let o=t.tasks.map((i)=>({key:i.key,input:{title:i.title,notes:i.notes,when:i.when,evening:i.evening,deadline:i.deadline,remindAt:i.remindAt,repeat:i.repeat,headingId:a(i.headingKey),projectId:i.headingKey?void 0:a(i.projectKey),areaId:i.projectKey?void 0:a(i.areaKey),tags:i.tags,checklist:i.checklist}}));for(let i of Cn(o,(c)=>c.input)){let{results:c}=await e.tasks.createMany(i.map((u)=>u.input)),l;for(let[u,p]of c.entries()){let m=i[u]?.key;if(!("task"in p))l??=new w(p.status,p.error.code,p.error.message);else if(m)n[m]=p.task.id,s.tasks++}if(r(),l)throw l}}finally{r()}return s}function $n(e,t){let n=e??nt();if(!n||!lt(n))throw new d("Could not find the Things database on this Mac. Pass its path with --db.");try{return ot(rt(n),t)}catch(r){if(r instanceof Y)throw new d(r.message);throw r}}function jn(e,t){if(e.length===0)throw new d("Which file? Pass one or more Todoist CSV exports.");let n={areas:[],projects:[],headings:[],tasks:[],skipped:{}};for(let r of e){if(!lt(r))throw new d(`No file at ${r}.`);let a;try{a=at(Sn(r,"utf8"),it(r),t)}catch(s){throw new d(`${r}: ${s instanceof Error?s.message:String(s)}`)}n.projects.push(...a.projects),n.headings.push(...a.headings),n.tasks.push(...a.tasks);for(let[s,o]of Object.entries(a.skipped))n.skipped[s]=(n.skipped[s]??0)+o}return n}var ut=async(e)=>{let{io:t,flags:n,print:r}=e,[a,...s]=e.rest;if(a!=="things"&&a!=="todoist")throw new d('Import from where? Use "bluma import things" or "bluma import todoist <file.csv>".');let o=e.connect(),i=await o.me(),c=a==="things"?$n(n.db,i.today):jn(s,i.today),l=Me(t.env),u=`${P(t,n).url}#${i.id}#${a}`,p=n.force?{}:l[u]??{},m=ct(c,p),h=X(m);if(n["dry-run"])return r({dryRun:!0,wouldCreate:h,skipped:m.skipped},()=>[`Would create ${ae(h)}.`,...ie(m),"Nothing was changed."].join(`
31
+ `)),0;l[u]=p;let f=await dt(o,m,p,()=>Ue(t.env,l));return r({created:f,skipped:m.skipped},()=>[`Imported ${ae(f)}.`,...ie(m),`What was imported is noted in ${z(t.env)}, so running this again adds only what is new.`].join(`
32
+ `)),0};var xn=`bluma ${H} — tasks from the terminal
85
33
 
86
34
  Usage: bluma <command> [options]
87
35
 
@@ -100,6 +48,13 @@ Change
100
48
  rm <task…> Move to the trash restore <task…>
101
49
  empty-trash Permanently delete everything in the trash
102
50
 
51
+ Files on to-dos (up to 25 MB each, 20 per to-do; an agent reads them over MCP)
52
+ attach <task> <file…> Attach files to a to-do
53
+ attachments <task> List a to-do's files, with their ids
54
+ attachment get <id> Download a file into this folder under its own name: -o <path or folder>, --force
55
+ to overwrite. A name is never allowed to point outside the folder
56
+ attachment rm <id…> Delete files for good
57
+
103
58
  Organise
104
59
  projects List projects project add <title…> [-a area] [-w when] [-d date]
105
60
  areas List areas area add <title…>
@@ -121,7 +76,10 @@ Setup
121
76
  feedback <summary…> Tell us about a bug, a gap or an idea: --kind bug|missing|confusing|idea, --details "…"
122
77
  whoami Show the signed-in account
123
78
  mcp Print the config for connecting an agent over MCP
124
- tokens List API tokens token add <name…> token rm <token>
79
+ tokens List devices and API tokens, with what each can do and when it expires
80
+ token add <name…> Make an API token for an agent or script (needs an email sign-in, not a token):
81
+ --read-only so it cannot change anything, --expires 30d|90d|<n>d (default: never)
82
+ token rm <token> Revoke a token
125
83
 
126
84
  Options
127
85
  -w, --when <when> today, tomorrow, anytime, someday, inbox, or YYYY-MM-DD
@@ -138,12 +96,14 @@ Options
138
96
  --title <text> New title (edit)
139
97
  -q, --query <text> Search title and notes (list)
140
98
  --dry-run Import: show what would be created and create nothing
141
- --force Import: bring over again what an earlier import already made
99
+ --force Import: bring over again what an earlier import already made. attachment get:
100
+ overwrite an existing file
101
+ -o, --output <path> attachment get: where to save the file
142
102
  --db <path> Import things: the Things database, if it is not in the usual place
143
103
  --json Print JSON instead of text
144
104
  -h, --help -v, --version
145
105
 
146
- Tasks, projects and areas can be named by id or any unique id prefix.`,Sa={...Object.fromEntries(ve.map((e)=>[e,(t)=>Gr(t,e)])),...la,...ia,import:Pa};async function Ta(e,t){try{return await Fp(e,t)}catch(r){if(r instanceof x)return t.err(r.message),2;if(r instanceof ee)return t.err(`${r.message} (${r.code})`),1;if(r instanceof TypeError&&/option|argument/i.test(r.message))return t.err(`${r.message}
147
- Run "bluma --help" for usage.`),2;return t.err(r instanceof Error?`Could not reach the server: ${r.message}`:String(r)),1}}async function Fp(e,t){let{values:r,positionals:n}=Mp({args:e,options:Yc,allowPositionals:!0}),[o,...i]=n;if(r.version)return t.out(It),0;if(r.help||!o||o==="help")return t.out(Up),0;let s=Object.hasOwn(Sa,o)?Sa[o]:void 0;if(!s)throw new x(`Unknown command "${o}". Run "bluma --help" for usage.`);return s(ta(t,r,o,i))}function Bp(e){let{stdin:t,stderr:r}=process;if(!t.isTTY)return Promise.reject(Error("Not a terminal. Set BLUMA_PASSWORD instead."));return r.write(e),t.setRawMode(!0),t.resume(),new Promise((n,o)=>{let i="",s=(a)=>{t.setRawMode(!1),t.pause(),t.off("data",c),r.write(`
148
- `),a()},c=(a)=>{for(let u of a.toString("utf8")){if(u==="\r"||u===`
149
- `)return s(()=>n(i));if(u==="\x03")return s(()=>o(Error("Cancelled.")));if(u==="\x7F"||u==="\b")i=i.slice(0,-1);else i+=u}};t.on("data",c)})}process.exitCode=await Ta(process.argv.slice(2),{out:(e)=>console.log(e),err:(e)=>console.error(e),env:process.env,askSecret:process.stdin.isTTY?Bp:void 0});
106
+ Tasks, projects and areas can be named by id or any unique id prefix.`,pt={...Object.fromEntries(x.map((e)=>[e,(t)=>le(t,e)])),...Ge,...Ve,...He,import:ut};function In(e){switch(e.code){case"session_required":return"An API token cannot do this. Sign in with `bluma login --email you@example.com`, then run this again.";case"read_only_token":return"This token is read only, so it cannot change anything. Use a token that can change, or sign in with `bluma login --email you@example.com`.";default:return`${e.message} (${e.code})`}}async function mt(e,t){try{return await An(e,t)}catch(n){if(n instanceof d)return t.err(n.message),2;if(n instanceof w)return t.err(In(n)),1;if(n instanceof I)return t.err(`Could not reach the server: ${n.message}`),1;if(n instanceof TypeError&&/option|argument/i.test(n.message))return t.err(`${n.message}
107
+ Run "bluma --help" for usage.`),2;return t.err(n instanceof Error?n.message:String(n)),1}}async function An(e,t){let{values:n,positionals:r}=Pn({args:e,options:Ee,allowPositionals:!0}),[a,...s]=r;if(n.version)return t.out(H),0;if(n.help||!a||a==="help")return t.out(xn),0;let o=Object.hasOwn(pt,a)?pt[a]:void 0;if(!o)throw new d(`Unknown command "${a}". Run "bluma --help" for usage.`);return o(Le(t,n,s))}function Rn(e){let{stdin:t,stderr:n}=process;if(!t.isTTY)return Promise.reject(Error("Not a terminal. Set BLUMA_PASSWORD instead."));return n.write(e),t.setRawMode(!0),t.resume(),new Promise((r,a)=>{let s="",o=(c)=>{t.setRawMode(!1),t.pause(),t.off("data",i),n.write(`
108
+ `),c()},i=(c)=>{for(let l of c.toString("utf8")){if(l==="\r"||l===`
109
+ `)return o(()=>r(s));if(l==="\x03")return o(()=>a(Error("Cancelled.")));if(l==="\x7F"||l==="\b")s=s.slice(0,-1);else s+=l}};t.on("data",i)})}process.exitCode=await mt(process.argv.slice(2),{out:(e)=>console.log(N(e)),err:(e)=>console.error(N(e)),env:process.env,askSecret:process.stdin.isTTY?Rn:void 0});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bluma-cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Bluma from the terminal: capture, list and finish tasks, import from Things or Todoist, connect an agent over MCP.",
5
5
  "keywords": [
6
6
  "tasks",