@morozinc/opencode-linear-plugin 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Moroz Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # OpenCode Linear Plugin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Use more than one Linear account or workspace from OpenCode Desktop. Each
4
+ connection has its own alias, OAuth sign-in, and tools from
5
+ [Linear’s official MCP server](https://linear.app/docs/mcp).
6
+
7
+ ## Install from npm
8
+
9
+ ```sh
10
+ opencode plugin add @morozinc/opencode-linear-plugin@0.1.0
11
+ ```
12
+
13
+ ## Build from source
14
+
15
+ Requires OpenCode Desktop V2 and Node.js 20.19+ or 22.12+. The plugin was
16
+ built against OpenCode 2.4.3 and uses its experimental Desktop plugin API.
17
+
18
+ ```sh
19
+ cd opencode-linear-plugin
20
+ npm ci
21
+ npm run build
22
+ ```
23
+
24
+ Add the **absolute path to this directory** to `plugins` in your global
25
+ `~/.config/opencode/opencode.json(c)` (or `$XDG_CONFIG_HOME/opencode/opencode.json(c)`).
26
+ Keep your other plugin entries and settings.
27
+
28
+ ```jsonc
29
+ {
30
+ "$schema": "https://opencode.ai/config.json",
31
+ "plugins": ["/absolute/path/to/opencode-linear-plugin"],
32
+ }
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ 1. Select OpenCode Desktop’s own server. Open **Settings > Linear** or choose
38
+ **Linear** from the command palette.
39
+ 2. Add an alias such as `work`. Enable **Read-only access** if you only need to
40
+ look up issues.
41
+ 3. Choose **Sign in** from the connection’s menu. Check the Linear account and
42
+ workspace on the consent screen. Switch accounts or use a separate browser
43
+ profile if needed. The alias is just a local label.
44
+ 4. Name the alias in chat: “Using Linear work, show my open issues.” If more
45
+ than one connection fits a request, OpenCode asks which one to use.
46
+
47
+ ![Linear settings with the account alias and read-only access option](docs/screenshots/add-account.png)
48
+
49
+ The settings page shows each connection’s status and MCP namespace. You can
50
+ also find the connections under `/mcps`. **Disable** hides the tools and keeps
51
+ the sign-in. **Sign out** clears the credential and keeps the alias. **Remove**
52
+ deletes both.
53
+
54
+ OpenCode stores and refreshes OAuth credentials. The plugin keeps the alias,
55
+ server name, and connection settings.
56
+
57
+ ## License and credits
58
+
59
+ [MIT License](LICENSE). Developed by [Moroz Inc.](https://moroz.cc).
60
+
61
+ Logo from [Simple Icons](https://simpleicons.org/).
62
+
63
+ This project is not affiliated with OpenCode or Anomaly.
@@ -0,0 +1,60 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const w=require("solid-js/web"),ie=require("@opencode/plugin/gui"),Z=require("solid-js"),Ln=require("@opencode/plugin/rpc");function je(e){const t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,o])=>t.indexOf(+r)===-1).map(([r,o])=>o)}function it(e,t="|"){return e.map(n=>Vt(n)).join(t)}function Te(e,t){return typeof t=="bigint"?t.toString():t}class Un{constructor(t){this._getter=t,this._value=void 0}get value(){const t=this._getter;return t!==void 0&&(this._value=t(),this._getter=void 0),this._value}}function Ke(e){return new Un(e)}function Fn(e){return e==null}function Ve(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function X(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function xt(e){const t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function J(e){return xt(e._zod.def)??e._zod.def.shape}function Mt(e,t,n){Object.defineProperty(e,t,{get(){const r=n();return X(this,t,r),r},enumerable:!0,configurable:!0})}function Jt(e,t,n){t in e?X(e,t,n):e[t]=n}function G(e,t,n,r){const o=J(t);for(const i of n){const s=Object.getOwnPropertyDescriptor(o,i);s.enumerable&&(s.get?Mt(e,i,()=>{const c=t._zod.def.shape[i];return r?r(c,i):c}):Jt(e,i,r?r(s.value,i):s.value))}}function xn(e,t){for(const n of Reflect.ownKeys(t)){const r=Object.getOwnPropertyDescriptor(t,n);r.enumerable&&(r.get?Mt(e,n,()=>t[n]):Jt(e,n,r.value))}}function T(...e){const t={};for(const n of e){const r=Object.getOwnPropertyDescriptors(n);Object.assign(t,r)}return Object.defineProperties({},t)}function Mn(e){return JSON.stringify(e)}function Jn(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const Bt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ve(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Bn=Ke(()=>{if(L.jitless||typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function ue(e){if(ve(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(ve(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Kt(e){return ue(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const Kn=new Set(["string","number","symbol"]);function Oe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function V(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function v(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Vt(e){return typeof e=="bigint"?e.toString()+"n":typeof e=="string"?`"${e}"`:`${e}`}function Vn(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}const Wn={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},qn={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function Gn(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const i={};return G(i,e,Se(e,t)),V(e,T(n,{shape:i,checks:[]}))}function Se(e,t){const n=J(e),r=[];for(const o of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(n,o)?.enumerable)throw new Error(`Unrecognized key: "${String(o)}"`);t[o]&&r.push(o)}return r}function Xn(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const i=new Set(Se(e,t)),s={};return G(s,e,Reflect.ownKeys(J(e)).filter(c=>!i.has(c))),V(e,T(n,{shape:s,checks:[]}))}function Hn(e,t){if(!ue(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const o=J(e);for(const i of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(o,i)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return V(e,T(e._zod.def,{shape:Wt(e,t)}))}function Wt(e,t){const n={};return G(n,e,Reflect.ownKeys(J(e))),xn(n,t),n}function Yn(e,t){if(!ue(t))throw new Error("Invalid input to safeExtend: expected a plain object");return V(e,T(e._zod.def,{shape:Wt(e,t)}))}function Qn(e,t){if(!t?._zod?.def)throw new Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");const n={};G(n,e,Reflect.ownKeys(J(e))),G(n,t,Reflect.ownKeys(J(t)));const r=T(e._zod.def,{shape:n,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return V(e,r)}function st(e,t,n,r="partial"){const i=t._zod.def.checks;if(i&&i.length>0)throw new Error(`.${r}() cannot be used on object schemas containing refinements`);const c=n?new Set(Se(t,n)):void 0,a={};return G(a,t,Reflect.ownKeys(J(t)),e&&((u,f)=>c&&!c.has(f)?u:new e({type:"optional",innerType:u}))),V(t,T(t._zod.def,{shape:a,checks:[]}))}function er(e,t,n){const r=n?new Set(Se(t,n)):void 0,o={};return G(o,t,Reflect.ownKeys(J(t)),(i,s)=>r&&!r.has(s)?i:new e({type:"nonoptional",innerType:i})),V(t,T(t._zod.def,{shape:o}))}function M(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function tr(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function qt(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function ne(e){return typeof e=="string"?e:e?.message}function ct(e){const t=[];for(const n of e??[]){const r=n._zod.def;if(!/_(length|size)$|_equals$/.test(r.check))break;const o=r.maximum??r.length??r.size;o>=0&&t.push([o,n])}return t}function Re(e,t,n){var r;for(let o=t;o<e.length;o++)(r=e[o]).schema??(r.schema=n)}function ee(e,t,n){var r;const o=e.inst?._zod?.traits;o?.has("$ZodType")&&(o.has("$ZodCheck")?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);const i=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,s=e.message?e.message:ne(e.inst?._zod.def?.error?.(e))??ne(i?.(e))??ne(t?.error?.(e))??ne(n.customError?.(e))??ne(n.localeError?.(e))??"Invalid input",c={};for(const a of Object.keys(e))a==="inst"||a==="schema"||a==="continue"||a==="input"||a==="__proto__"||(c[a]=e[a]);return c.path??(c.path=[]),c.message=s,t?.reportInput&&(c.input=e.input),c}const nr=/[\uD800-\uDBFF]/;function We(e){const t=e.length;if(!nr.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)===55296&&(e.charCodeAt(r+1)&64512)===56320&&(n--,r++);return n}function qe(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function rr(e){const 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";const n=e;if(n&&Object.getPrototypeOf(n)!==Object.prototype&&"constructor"in n&&n.constructor)return n.constructor.name}}return t}function fe(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}function or(e,t){for(const n in t){const r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):sr(e,n,r.value)}}function K(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function Gt(e,t,n){return K(e,t,n,!1)}function ir(e,t){for(const n in e){const r=e[n];Object.defineProperty(t,n,{configurable:!0,enumerable:!0,get(){return K(this,n,r(this))},set(o){K(this,n,o)}})}return t}function sr(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:K(this,t,n.bind(this))},set(r){K(this,t,r)}})}function cr(e,t){const n=Object.getPrototypeOf(e);return t in n?void 0:n}let Ee,B=!1;const ar={configurable:!0,get(){B=!0}};function k(e,t,n){const r=Object.getPrototypeOf(e._zod);if(t in r&&Ee!==e._zod){Ee=void 0;return}Ee=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,ar);const o=B;B=!1;try{const i=n(this);return B?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:i}),B=B||o,i}catch(i){throw delete this[t],B=B||o,i}},set(o){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:o})}})}function ur(e,t,n,r){const o=cr(e,t);o&&Object.defineProperty(o,t,{configurable:!0,get(){const i={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,t,i),i.value=n(this),Object.defineProperty(this,t,i),i.value},set(i){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:r,value:i})}})}const fr="~constantCatch";function lr(e){const t=()=>e;return t[fr]=!0,t}var at;const Ie={value:void 0,enumerable:!1};let ut="captureStackTrace"in Error?Error:null;function dr(e){const t=ut;if(t){const n=t.stackTraceLimit;if(typeof n=="number"){try{t.stackTraceLimit=0}catch{return ut=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function l(e,t,n,r){const o={};function i(p){this.def=p,this.constr=d,this.traits=new Set}i.prototype=o;const s=n,c=s&&new WeakSet;function a(p,h){if(p._zod){if(p._zod.traits.has(e))return}else{Ie.value=new i(h);try{Object.defineProperty(p,"_zod",Ie)}finally{Ie.value=void 0}}if(p._zod.traits.add(e),t(p,h),c){const b=Object.getPrototypeOf(p),g=p._zod.constr.prototype;let $=b;for(;$&&$!==g;)$=Object.getPrototypeOf($);const A=$??b;c.has(A)||(c.add(A),or(A,s))}const m=d.prototype;for(const b in m)Object.prototype.hasOwnProperty.call(m,b)&&(b in p||(p[b]=m[b].bind(p)))}const u=r?.Parent??Object;class f extends u{}Object.defineProperty(f,"name",{value:e});function d(p){const h=r?.Parent?dr(f):this;a(h,p);const m=h._zod.deferred;if(m){for(const g of m)g();h._zod.deferred=void 0}const b=globalThis.__zod_globalConfig?.postProcessor;return b&&b(h),h}return Object.defineProperty(d,"init",{value:a}),Object.defineProperty(d,Symbol.hasInstance,{value:p=>r?.Parent&&p instanceof r.Parent?!0:p?._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 Xt extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(at=globalThis).__zod_globalConfig??(at.__zod_globalConfig={});const L=globalThis.__zod_globalConfig;function W(e){return e&&Object.assign(L,e),L}function pr(){const e=this._zod;return e.message??(e.message=JSON.stringify(e.def,Te,2)),e.message}function hr(e){this._zod.message=e}const mr={get:pr,set:hr,enumerable:!0,configurable:!0},Ae={value:void 0,enumerable:!1},ft=new WeakSet([Object.prototype,Error.prototype]),gr=(e,t)=>{e.name="$ZodError",Ae.value=t,Object.defineProperty(e,"issues",Ae),Ae.value=void 0,Object.defineProperty(e,"message",mr);const n=Object.getPrototypeOf(e);ft.has(n)||(ft.add(n),Object.defineProperty(n,"toString",{configurable:!0,enumerable:!1,get(){const r=()=>this.message;return Object.defineProperty(this,"toString",{value:r,configurable:!0,writable:!0}),r},set(r){Object.defineProperty(this,"toString",{value:r,configurable:!0,writable:!0})}}))},_r=l("$ZodError",gr);function yr(e,t,n){return Object.prototype.hasOwnProperty.call(e,t)||(t==="__proto__"?Object.defineProperty(e,t,{value:n(),writable:!0,enumerable:!0,configurable:!0}):e[t]=n()),e[t]}function vr(e,t=n=>n.message){const n={},r=[];for(const o of e.issues)o.path.length>0?yr(n,o.path[0],()=>[]).push(t(o)):r.push(t(o));return{formErrors:r,fieldErrors:n}}function br(e,t=n=>n.message){const n={_errors:[]},r=(o,i=[])=>{for(const s of o.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(c=>r({issues:c},[...i,...s.path]));else if(s.code==="invalid_key")r({issues:s.issues},[...i,...s.path]);else if(s.code==="invalid_element")r({issues:s.issues},[...i,...s.path]);else{const c=[...i,...s.path];if(c.length===0)n._errors.push(t(s));else{let a=n,u=0;for(;u<c.length;){const f=c[u],d=u===c.length-1;if(f==="_errors"){d&&a._errors.push(t(s)),u++;continue}Object.prototype.hasOwnProperty.call(a,f)||Object.defineProperty(a,f,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});const p=a[f];d&&p._errors.push(t(s)),a=p,u++}}}};return r(e),n}function Ze(e,t){return{callee:t?.callee??e,Err:t?.Err}}const Ge=e=>{const t=(n,r,o,i)=>{const s=o?{...o,async:!1}:{async:!1},c=n._zod.run({value:r,issues:[]},s);if(c instanceof Promise)throw new q;if(c.issues.length){const a=new(i?.Err??e)(c.issues.map(u=>ee(u,s,W())));throw Bt(a,i?.callee??t),a}return c.value};return t},Xe=e=>{const t=async(n,r,o,i)=>{const s=o?{...o,async:!0}:{async:!0};let c=n._zod.run({value:r,issues:[]},s);if(c instanceof Promise&&(c=await c),c.issues.length){const a=new(i?.Err??e)(c.issues.map(u=>ee(u,s,W())));throw Bt(a,i?.callee??t),a}return c.value};return t},He=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},o);if(i instanceof Promise)throw new q;return i.issues.length?Ht(e,i.issues,o):{success:!0,data:i.value}};function Ht(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(o=>ee(o,n,W()))),t=void 0,n=void 0),r},set error(o){r=o,t=void 0,n=void 0}}}const Ye=e=>async(t,n,r)=>{const o=r?{...r,async:!0}:{async:!0};let i=t._zod.run({value:n,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?Ht(e,i.issues,o):{success:!0,data:i.value}},wr=Symbol.for("zod.compile.invalid"),zr=Symbol.for("zod.compile.fallback"),kr=((e,t,n)=>{const r=e._zod.bag.validator;if(r!==void 0){if(r(t)!==wr)return!0;if(r.definite===!0&&n===void 0)return!1}return $r(e,t,n)});function $r(e,t,n){const r=n?{...n,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},o=e._zod.bag.fallbackRun;let i;if(o?(r[zr]=!0,i=o({value:t,issues:[]},r)):i=e._zod.run({value:t,issues:[]},r),i instanceof Promise)throw new q;return i.issues.length===0}const Or=async(e,t,n)=>{const r=n?{...n,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0};let o=e._zod.run({value:t,issues:[]},r);return o instanceof Promise&&(o=await o),o.issues.length===0},Sr=e=>{const t=Ge(e),n=(r,o,i,s)=>{const c=i?{...i,direction:"backward"}:{direction:"backward"};return t(r,o,c,Ze(n,s))};return n},Zr=e=>{const t=Ge(e),n=(r,o,i,s)=>t(r,o,i,Ze(n,s));return n},Pr=e=>{const t=Xe(e),n=async(r,o,i,s)=>{const c=i?{...i,direction:"backward"}:{direction:"backward"};return await t(r,o,c,Ze(n,s))};return n},Er=e=>{const t=Xe(e),n=async(r,o,i,s)=>await t(r,o,i,Ze(n,s));return n},Ir=e=>(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return He(e)(t,n,o)},Ar=e=>(t,n,r)=>He(e)(t,n,r),Cr=e=>async(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return Ye(e)(t,n,o)},jr=e=>async(t,n,r)=>Ye(e)(t,n,r),Tr=/^[cC][0-9a-z]{6,}$/,Rr=/^[0-9a-z]+$/,Dr=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,Nr=/^[0-9a-vA-V]{20}$/,Lr=/^[A-Za-z0-9]{27}$/,Ur=/^[a-zA-Z0-9_-]{21}$/;function Fr(e){return new RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}const xr=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Mr=/^([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})$/,lt=e=>e?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})$`):/^([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)$/,Jr=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Br="^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$";function Kr(){return new RegExp(Br,"u")}const Vr=/^(?:(?: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])$/,Wr=/^(([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}|:))$/,qr=/^((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])$/,Gr=/^(([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])$/,Xr=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Hr=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/,Yr=/^https?$/,Qr=/^\+[1-9]\d{6,14}$/,Yt="(?:(?:\\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 eo(e){return new RegExp(`^${e}$`)}const to=eo(Yt);function De(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?`${t}:[0-5]\\d(?:\\.\\d+)?`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function no(e){return new RegExp(`^${De(e)}$`)}function ro(e){const t=["Z"];e.offset&&t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const n=`${De({precision:e.precision,seconds:!0})}(?:${t.join("|")})`,r=e.local?`${n}|${De({precision:e.precision})}`:n;return new RegExp(`^${Yt}T(?:${r})$`)}const oo=/^[\s\S]{0,}$/,io=/^(?:true|false)$/i,so=/^[^A-Z]*$/,co=/^[^a-z]*$/,U=l("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Qe=e=>{const t=e.value;return!Fn(t)&&t.length!==void 0},ao=l("$ZodCheckMaxLength",(e,t)=>{var n;U.init(e,t),(n=e._zod.def).when??(n.when=Qe),e._zod.check=r=>{const o=r.value,i=o.length;if((typeof o=="string"&&i>t.maximum?We(o):i)<=t.maximum)return;const c=qe(o);r.issues.push({origin:c,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),uo=l("$ZodCheckMinLength",(e,t)=>{var n;U.init(e,t),(n=e._zod.def).when??(n.when=Qe),e._zod.check=r=>{const o=r.value,i=o.length;if((typeof o=="string"&&i>=t.minimum&&i<t.minimum*2?We(o):i)>=t.minimum)return;const c=qe(o);r.issues.push({origin:c,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),fo=l("$ZodCheckLengthEquals",(e,t)=>{var n;U.init(e,t),(n=e._zod.def).when??(n.when=Qe),e._zod.check=r=>{const o=r.value,i=o.length,s=typeof o=="string"&&i>=t.length&&i<=t.length*2?We(o):i;if(s===t.length)return;const c=qe(o),a=s>t.length;r.issues.push({origin:c,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),Pe=l("$ZodCheckStringFormat",(e,t)=>{var n,r;U.init(e,t),t.pattern?(n=e._zod).check??(n.check=o=>{t.pattern.lastIndex=0,!t.pattern.test(o.value)&&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})}):(r=e._zod).check??(r.check=()=>{})}),lo=l("$ZodCheckRegex",(e,t)=>{Pe.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),po=l("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=so),Pe.init(e,t)}),ho=l("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=co),Pe.init(e,t)}),mo=l("$ZodCheckIncludes",(e,t)=>{U.init(e,t);const n=Oe(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position},}${n}`:n);t.pattern=r,e._zod.check=o=>{o.value.includes(t.includes,t.position)||o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),go=l("$ZodCheckStartsWith",(e,t)=>{U.init(e,t);const n=new RegExp(`^${Oe(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),_o=l("$ZodCheckEndsWith",(e,t)=>{U.init(e,t);const n=new RegExp(`.*${Oe(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),yo=l("$ZodCheckOverwrite",(e,t)=>{U.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class vo{constructor(t=[],n={}){this.content=[],this.indent=0,this.args=t,this.closed=n}indented(t){this.indent+=1;try{t(this)}finally{this.indent-=1}}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const r=t.split(`
2
+ `).filter(s=>s),o=Math.min(...r.map(s=>s.length-s.trimStart().length)),i=r.map(s=>s.slice(o)).map(s=>" ".repeat(this.indent*2)+s);for(const s of i)this.content.push(s)}compile(){const t=Function,n=this?.content??[""];return new t(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
3
+ ${n.join(`
4
+ `)}
5
+ };`)(...Object.values(this.closed))}}const bo={major:4,minor:6,patch:7},P=l("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=bo;const r=e._zod.def.checks,o=e._zod.traits.has("$ZodCheck")?[e,...r??[]]:r?.length?[...r]:[];for(const i of o)for(const s of i._zod.onattach)s(e);if(o.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const i=(c,a,u)=>{if(c.memo)return c;let f=M(c),d;for(const p of a){if(p._zod.def.when){if(tr(c)||!p._zod.def.when(c))continue}else if(f)continue;const h=c.issues.length,m=p._zod.check(c);if(m instanceof Promise&&u?.async===!1)throw new q;if(d||m instanceof Promise)d=(d??Promise.resolve()).then(async()=>{await m,c.issues.length!==h&&(Re(c.issues,h,e),f||(f=M(c,h)))});else{if(c.issues.length===h)continue;Re(c.issues,h,e),f||(f=M(c,h))}}return d?d.then(()=>c):c},s=(c,a,u)=>{if(M(c))return c.aborted=!0,c;const f=i(a,o,u);if(f instanceof Promise){if(u.async===!1)throw new q;return f.then(d=>e._zod.parse(d,u))}return e._zod.parse(f,u)};e._zod.run=(c,a)=>{if(a.skipChecks)return e._zod.parse(c,a);if(a.direction==="backward"){const f=e._zod.parse({value:c.value,issues:[]},{...a,skipChecks:!0});return f instanceof Promise?f.then(d=>s(d,c,a)):s(f,c,a)}const u=e._zod.parse(c,a);if(u instanceof Promise){if(a.async===!1)throw new q;return u.then(f=>i(f,o,a))}return i(u,o,a)}}},{get"~standard"(){return Gt(this,"~standard",en(this))},set"~standard"(e){K(this,"~standard",e)}}),Qt=(e,t)=>e.issues.length?{issues:e.issues.map(n=>ee(n,t,W()))}:{value:e.value};async function wo(e,t){const n={async:!0};return Qt(await e._zod.run({value:t,issues:[]},n),n)}function en(e){return{validate:t=>{const n={async:!1};try{const r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return Qt(r,n)}catch{}return wo(e,t)},vendor:"zod",version:1}}const et=l("$ZodString",(e,t)=>{P.init(e,t),e._zod.pattern=t.pattern??oo,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),O=l("$ZodStringFormat",(e,t)=>{Pe.init(e,t),et.init(e,t)}),zo=l("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Mr),O.init(e,t)}),ko=l("$ZodUUID",(e,t)=>{if(t.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(r===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=lt(r))}else t.pattern??(t.pattern=lt());O.init(e,t)}),$o=l("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Jr),O.init(e,t)}),tn=1,be=2;function nn(e){try{return typeof URL<"u"&&typeof URL.canParse=="function"?URL.canParse(e):(new URL(e),!0)}catch{return!1}}function Oo(e,t){return!("normalize"in t)&&!("hostname"in t)&&!("protocol"in t)?nn(e)||be:So(e,t)}function So(e,t){if(!t.normalize&&t.protocol?.source===Yr.source&&!/^https?:\/\//i.test(e))return tn;try{if(typeof URL<"u"){const n=URL;if(typeof n.parse=="function")return n.parse(e)??be}return new URL(e)}catch{return be}}const Zo=/[\t\n\r]/g;function dt(e){return e.replace(Zo,"")}function Po(e,t){return t.lastIndex=0,t.test(e.hostname)}function Eo(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(":")?e.protocol.slice(0,-1):e.protocol)}const Io=l("$ZodURL",(e,t)=>{O.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),o=Oo(r,t);if(o===tn){n.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:n.value,inst:e,continue:!t.abort});return}if(o===be){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort});return}if(o===!0){n.value=dt(r);return}t.hostname&&!Po(o,t.hostname)&&n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort}),t.protocol&&!Eo(o,t.protocol)&&n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort}),n.value=t.normalize?o.href:dt(r);return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Ao=l("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Kr()),O.init(e,t)}),Co=l("$ZodNanoID",(e,t)=>{if(t.length!==void 0&&(!Number.isInteger(t.length)||t.length<1))throw new Error(`Invalid nanoid length: ${t.length}`);t.pattern??(t.pattern=t.length===void 0?Ur:Fr(t.length)),O.init(e,t)}),jo=l("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Tr),O.init(e,t)}),To=l("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Rr),O.init(e,t)}),Ro=l("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Dr),O.init(e,t)}),Do=l("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Nr),O.init(e,t)}),No=l("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Lr),O.init(e,t)}),Lo=l("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=ro(t)),O.init(e,t)}),Uo=l("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=to),O.init(e,t)}),Fo=l("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=no(t)),O.init(e,t)}),xo=l("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=xr),O.init(e,t)}),Mo=l("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Vr),O.init(e,t)}),Jo=/^[0-9a-fA-F:.]+$/;function rn(e){return Jo.test(e)?nn(`http://[${e}]`):!1}const Bo=l("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Wr),O.init(e,t),e._zod.check=n=>{rn(n.value)||n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}),Ko=l("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=qr),O.init(e,t)});function Vo(e){const t=e.split("/");if(t.length!==2)return!1;const[n,r]=t;if(!r)return!1;const o=Number(r);return`${o}`!==r||o<0||o>128?!1:rn(n)}const Wo=l("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Gr),O.init(e,t),e._zod.check=n=>{Vo(n.value)||n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}});function on(e){if(e==="")return!0;if(/\s/.test(e)||e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const sn=/^[0-9a-zA-Z+/]*={0,2}$/,qo=l("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=sn),O.init(e,t),e._zod.check=n=>{on(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}}),tt=/^[A-Za-z0-9_-]*$/;function Go(e){if(!tt.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return on(n)}const Xo=l("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=tt),O.init(e,t),e._zod.check=n=>{Go(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),Ho=l("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Qr),O.init(e,t)});function Yo(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const o=JSON.parse(atob(r));return!("typ"in o&&o?.typ!=="JWT"||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}}const Qo=l("$ZodJWT",(e,t)=>{O.init(e,t),e._zod.check=n=>{Yo(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),ei=l("$ZodBoolean",(e,t)=>{P.init(e,t),e._zod.pattern=io,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}const o=n.value;return typeof o=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),n}}),ti=l("$ZodUnknown",(e,t)=>{P.init(e,t),e._zod.parse=n=>n}),ni=l("$ZodNever",(e,t)=>{P.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function ri(e,t){const n=ct(e._zod.def.checks);if(!n.length)return;const r=Math.min(...n.map(i=>i[0])),o=e._zod.parse;e._zod.parse=(i,s)=>{const c=t(i.value);if(c>r&&!s?.skipChecks&&s?.direction!=="backward"){for(const[a,u]of ct(e._zod.def.checks))if(c>a&&u._zod.def.when(i)){const f=i.issues.length;return u._zod.check(i),i.issues[f].continue=!1,Re(i.issues,f,e),i}}return o(i,s)}}const oi=e=>Array.isArray(e)?e.length:-1;function pt(e,t,n){e.issues.length&&t.issues.push(...qt(n,e.issues)),t.value[n]=e.value}const ii=l("$ZodArray",(e,t)=>{P.init(e,t);const n=L.memoizer;n?.attach(e),e._zod.parse=(r,o)=>{const i=r.value;if(!Array.isArray(i))return r.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),r;r.value=n?n.alloc(e,r,Array(i.length),o):Array(i.length);const s=[],c=o?.abortEarly;for(let a=0;a<i.length;a++){const u=i[a],f=t.element._zod.run({value:u,issues:[]},o);if(f instanceof Promise)s.push(f.then(d=>pt(d,r,a)));else if(pt(f,r,a),c&&f.issues.length!==0&&M(f))break}return s.length?Promise.all(s).then(()=>r):r},ri(e,oi)});function we(e,t,n,r,o,i){const s=n in r,c=i==="optional";if(!(!s&&c&&o==="optional")){if(e.issues.length){if(o!==void 0&&c&&!s)return;t.issues.push(...qt(n,e.issues))}if(!s&&o===void 0){e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[n]});return}e.value===void 0?(s||o==="defaulted"&&!c)&&(t.value[n]=void 0):t.value[n]=e.value}}const si=[];function cn(e){const t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:si,o=r.length?[...t,...r]:t;for(const s of o)if(!e.shape?.[s]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${String(s)}": expected a Zod schema`);const i=Vn(e.shape);return{...e,allKeys:o,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(i)}}function an(e,t,n,r,o,i,s){const c=[],a=o.keySet,u=o.catchall._zod,f=u.def.type,d=u.optin,p=u.optout;let h=0;for(const m in t){if(s&&n.issues.length!==h){if(M(n,h))break;h=n.issues.length}if(a.has(m))continue;if(m==="__proto__"){f==="never"&&c.push(m);continue}if(f==="never"){c.push(m);continue}const b=u.run({value:t[m],issues:[]},r);b instanceof Promise?e.push(b.then(g=>we(g,n,m,t,d,p))):we(b,n,m,t,d,p)}return c.length&&n.issues.push({code:"unrecognized_keys",keys:c,input:t,inst:i,continue:!0}),e.length?Promise.all(e).then(()=>n):n}const ci=l("$ZodObject",(e,t)=>{P.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape"),r=n?.get?n.get.raw:t.shape??{};if(r){const u=()=>{const f={...r};return Object.defineProperty(t,"shape",{value:f}),u.raw=f,f};u.raw=r,Object.defineProperty(t,"shape",{get:u})}const o=Ke(()=>cn(t));k(e,"propValues",u=>{const f=u.def.shape,d={};for(const p in f){const h=f[p]._zod;if(h.values){Object.prototype.hasOwnProperty.call(d,p)||X(d,p,new Set);for(const m of h.values)d[p].add(m);h.optin!==void 0&&d[p].add(void 0)}}return d});const i=ve,s=t.catchall;let c;const a=L.memoizer;a?.attach(e),e._zod.parse=(u,f)=>{c??(c=o.value);const 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,{},f):{};const p=[],h=c.shape,m=f?.abortEarly;let b=u.issues.length;for(const g of c.allKeys){if(m&&u.issues.length!==b){if(M(u,b))break;b=u.issues.length}if(g==="__proto__")continue;const $=h[g],A=$._zod.optin,F=$._zod.optout,N=$._zod.run({value:d[g],issues:[]},f);N instanceof Promise?p.push(N.then(_=>we(_,u,g,d,A,F))):we(N,u,g,d,A,F)}return s?an(p,d,u,f,o.value,e,m===!0):p.length?Promise.all(p).then(()=>u):u}}),ai=l("$ZodObjectJIT",(e,t)=>{ci.init(e,t);const n=e._zod.parse,r=Ke(()=>cn(t)),o=L.memoizer,i=h=>{const m=r.value,b=m.symbolKeys,g=new vo(["payload","ctx"],{shape:h,inst:e,memo:o,syms:b}),$=_=>`shape[${_}]._zod.run({ value: input[${_}], issues: [] }, ctx)`,A=(_,y)=>`
6
+ let ${_}_ab = false;
7
+ for (let i = 0; i < ${_}.issues.length; i++) {
8
+ const iss = ${_}.issues[i];
9
+ iss.path = iss.path ? [${y}, ...iss.path] : [${y}];
10
+ payload.issues.push(iss);
11
+ if (iss.continue !== true) ${_}_ab = true;
12
+ }
13
+ if (${_}_ab && ctx && ctx.abortEarly) {
14
+ payload.value = newResult;
15
+ return payload;
16
+ }`;g.write("const input = payload.value;");const F=Object.create(null);let N=0;for(const _ of m.allKeys)F[_]=`key_${N++}`;g.write(o?"const newResult = memo.alloc(inst, payload, {}, ctx);":"const newResult = {};");for(const _ of m.allKeys){if(_==="__proto__")continue;const y=F[_],z=typeof _=="symbol"?`syms[${b.indexOf(_)}]`:Mn(_),I=`${z} in input`,D=h[_],x=D?._zod?.optin,ot=x!==void 0,Dn=D?._zod?.optout==="optional";if(g.write(`const ${y} = ${$(z)};`),ot&&Dn){const Nn=x==="optional"?`${y}_present`:`${y}.value !== undefined || ${y}_present`;g.write(`
17
+ const ${y}_present = ${I};
18
+ if (!${y}.issues.length || ${y}_present) {
19
+ if (${y}.issues.length) {${A(y,z)}
20
+ }
21
+
22
+ if (${Nn}) {
23
+ newResult[${z}] = ${y}.value;
24
+ }
25
+ }
26
+
27
+ `)}else ot?(g.write(`
28
+ if (${y}.issues.length) {${A(y,z)}
29
+ }
30
+ `),x==="defaulted"?g.write(`newResult[${z}] = ${y}.value;`):g.write(`
31
+ if (${y}.value !== undefined || ${I}) {
32
+ newResult[${z}] = ${y}.value;
33
+ }
34
+ `)):g.write(`
35
+ const ${y}_present = ${I};
36
+ if (${y}.issues.length) {${A(y,z)}
37
+ }
38
+ if (!${y}_present && !${y}.issues.length) {
39
+ payload.issues.push({
40
+ code: "invalid_type",
41
+ expected: "nonoptional",
42
+ input: undefined,
43
+ path: [${z}]
44
+ });
45
+ if (ctx && ctx.abortEarly) {
46
+ payload.value = newResult;
47
+ return payload;
48
+ }
49
+ }
50
+
51
+ if (${y}_present) {
52
+ newResult[${z}] = ${y}.value;
53
+ }
54
+
55
+ `)}return g.write("payload.value = newResult;"),g.write("return payload;"),g.compile()};let s;const c=ve,a=!L.jitless,f=a&&Bn.value,d=t.catchall;let p;e._zod.parse=(h,m)=>{p??(p=r.value);const b=h.value;return c(b)?a&&f&&m?.async===!1&&m.jitless!==!0?(s||(s=i(t.shape)),h=s(h,m),d?an([],b,h,m,p,e,m?.abortEarly===!0):h):n(h,m):(h.issues.push({expected:"object",code:"invalid_type",input:b,inst:e}),h)}});function ht(e,t,n,r){for(const i of e)if(i.issues.length===0)return t.value=i.value,t;const o=e.filter(i=>!M(i));return o.length===1?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(i=>i.issues.map(s=>ee(s,r,W())))}),t)}const ui=l("$ZodUnion",(e,t)=>{P.init(e,t),k(e,"optin",r=>r.def.options.some(o=>o._zod.optin==="defaulted")?"defaulted":r.def.options.some(o=>o._zod.optin!==void 0)?"optional":void 0),k(e,"optout",r=>r.def.options.some(o=>o._zod.optout==="optional")?"optional":void 0),k(e,"values",r=>{if(r.def.options.every(o=>o._zod.values))return new Set(r.def.options.flatMap(o=>Array.from(o._zod.values)))}),k(e,"pattern",r=>{if(r.def.options.every(o=>o._zod.pattern)){const o=r.def.options.map(i=>i._zod.pattern);return new RegExp(`^(${o.map(i=>Ve(i.source)).join("|")})$`)}});const n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,o)=>{if(n)return n(r,o);let i=!1;const s=[];for(const c of t.options){const a=c._zod.run({value:r.value,issues:[]},o);if(a instanceof Promise)s.push(a),i=!0;else{if(a.issues.length===0)return a;s.push(a)}}return i?Promise.all(s).then(c=>ht(c,r,e,o)):ht(s,r,e,o)}}),fi=l("$ZodIntersection",(e,t)=>{P.init(e,t),e._zod.parse=(n,r)=>{const o=n.value,i=t.left._zod.run({value:o,issues:[]},r),s=t.right._zod.run({value:o,issues:[]},r);return i instanceof Promise||s instanceof Promise?Promise.all([i,s]).then(([a,u])=>mt(n,a,u)):mt(n,i,s)}});function Ne(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(ue(e)&&ue(t)){const n=Object.keys(t),r=Object.keys(e).filter(i=>n.indexOf(i)!==-1),o={...e,...t};Object.prototype.hasOwnProperty.call(o,"__proto__")&&delete o.__proto__;for(const i of r){if(i==="__proto__")continue;const s=Ne(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:[]};const n=[];for(let r=0;r<e.length;r++){const o=e[r],i=t[r],s=Ne(o,i);if(!s.valid)return{valid:!1,mergeErrorPath:[r,...s.mergeErrorPath]};n.push(s.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function mt(e,t,n){const r=new Map;let o;const i=new Map,s=(u,f)=>{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){const p=String(u.path[0]);i.has(p)||i.set(p,u),d=[p]}else return!1;for(const p of d)r.has(p)||r.set(p,{}),r.get(p)[f]=!0;return!0};for(const u of t.issues)s(u,"l")||e.issues.push(u);for(const u of n.issues)s(u,"r")||e.issues.push(u);const c=[...r].filter(([,u])=>u.l&&u.r).map(([u])=>u);if(c.length){const u=o?c.filter(f=>o.keys.includes(f)):[];u.length&&e.issues.push({...o,keys:u});for(const f of c)!u.includes(f)&&i.has(f)&&e.issues.push(i.get(f))}const a=Ne(t.value,n.value);if(!a.valid){if(M(e))return e;throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`)}return e.value=a.data,e}const li=l("$ZodEnum",(e,t)=>{P.init(e,t);const n=je(t.entries),r=new Set(n);e._zod.values=r,k(e,"pattern",o=>{const i=je(o.def.entries).filter(s=>Kn.has(typeof s));return new RegExp(i.length?`^(${i.map(s=>Oe(s.toString())).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(o,i)=>{const s=o.value;return r.has(s)||o.issues.push({code:"invalid_value",values:n,input:s,inst:e}),o}}),di=l("$ZodTransform",(e,t)=>{P.init(e,t),e._zod.optin="optional",L.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Xt(e.constructor.name);const o=t.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(s=>(n.value=s,n));if(o instanceof Promise)throw new q;return n.value=o,n}});function gt(e,t){return e.value=t.issues.length?void 0:t.value,e}const un=l("$ZodOptional",(e,t)=>{P.init(e,t),k(e,"optin",n=>n.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),e._zod.optout="optional",k(e,"values",n=>{const r=n.def.innerType._zod.values;return r?new Set([...r,void 0]):void 0}),k(e,"pattern",n=>{const r=n.def.innerType._zod.pattern;return r?new RegExp(`^(${Ve(r.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(n.value===void 0){if(t.innerType._zod.optin!=="defaulted")return n;const o=t.innerType._zod.run({value:n.value,issues:[]},r);return o instanceof Promise?o.then(i=>gt(n,i)):gt(n,o)}return t.innerType._zod.run(n,r)}}),pi=l("$ZodExactOptional",(e,t)=>{un.init(e,t),k(e,"values",n=>n.def.innerType._zod.values),k(e,"pattern",n=>n.def.innerType._zod.pattern),e._zod.parse=(n,r)=>t.innerType._zod.run(n,r)}),hi=l("$ZodNullable",(e,t)=>{P.init(e,t),k(e,"optin",n=>n.def.innerType._zod.optin),k(e,"optout",n=>n.def.innerType._zod.optout),k(e,"pattern",n=>{const r=n.def.innerType._zod.pattern;return r?new RegExp(`^(${Ve(r.source)}|null)$`):void 0}),k(e,"values",n=>n.def.innerType._zod.values?new Set([...n.def.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),mi=l("$ZodDefault",(e,t)=>{P.init(e,t),e._zod.optin="defaulted",k(e,"values",n=>n.def.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);if(n.value===void 0)return n.value=t.defaultValue,n;const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>_t(i,t)):_t(o,t)}});function _t(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const gi=l("$ZodPrefault",(e,t)=>{P.init(e,t),e._zod.optin="defaulted",k(e,"values",n=>n.def.innerType._zod.values),e._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),_i=l("$ZodNonOptional",(e,t)=>{P.init(e,t),k(e,"values",n=>{const r=n.def.innerType._zod.values;return r?new Set([...r].filter(o=>o!==void 0)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>yt(i,e)):yt(o,e)}});function yt(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}function vt(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(o=>ee(o,r,W()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}const yi=l("$ZodCatch",(e,t)=>{P.init(e,t),k(e,"optin",n=>n.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),k(e,"optout",n=>n.def.innerType._zod.optout),k(e,"values",n=>n.def.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const o=t.innerType._zod.run({value:n.value,issues:[]},r);return o instanceof Promise?o.then(i=>vt(n,i,t,r)):vt(n,o,t,r)}}),vi=l("$ZodPipe",(e,t)=>{P.init(e,t),k(e,"values",n=>n.def.in._zod.values),k(e,"optin",n=>n.def.in._zod.optin),k(e,"optout",n=>n.def.out._zod.optout),k(e,"propValues",n=>n.def.in._zod.propValues),e._zod.parse=(n,r)=>{if(r.direction==="backward"){const i=t.out._zod.run(n,r);return i instanceof Promise?i.then(s=>de(s,t.in,r)):de(i,t.in,r)}const o=t.in._zod.run(n,r);return o instanceof Promise?o.then(i=>de(i,t.out,r)):de(o,t.out,r)}});function de(e,t,n){return e.issues.some(r=>r.code!=="unrecognized_keys")?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const bi=l("$ZodReadonly",(e,t)=>{P.init(e,t),k(e,"propValues",n=>n.def.innerType._zod.propValues),k(e,"values",n=>n.def.innerType._zod.values),k(e,"optin",n=>n.def.innerType?._zod?.optin),k(e,"optout",n=>n.def.innerType?._zod?.optout),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(bt):bt(o)}});function bt(e){return e.memo||(e.value=Object.freeze(e.value)),e}const wi=l("$ZodCustom",(e,t)=>{U.init(e,t),P.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(i=>wt(i,n,r,e));wt(o,n,r,e)}});function wt(e,t,n,r){if(!e){const o={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),t.issues.push(fe(o))}}class zi extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}const Le="~memo",zt=[];function fn(e){return e!==null&&typeof e=="object"}function Ce(e){return e.map(t=>t.path?{...t,path:t.path.slice()}:{...t})}const ln=new WeakMap,re=0,_e=1,se=2;function ye(e,t,n){const r=ln.get(e);if(r!==void 0)return r?se:re;if(t.has(e))return se;t.add(e);let o=re;const i=f=>{if(o!==se&&f?._zod){const d=ye(f,t);d>o&&(o=d)}},s=(f,d)=>{let p=re;for(const h of Reflect.ownKeys(f)){const m=Object.getOwnPropertyDescriptor(f,h);if(!m.enumerable)continue;const b=m.get?_e:m.value?._zod?ye(m.value,t):re;b>p&&(p=b)}return p},c=f=>{f>o&&(o=f)},a=e._zod.def;switch(a.type){case"object":{const f=xt(a);c(f?s(f):_e),i(a.catchall);break}case"array":i(a.element);break;case"tuple":for(const f of a.items)i(f);i(a.rest);break;case"record":case"map":i(a.keyType),i(a.valueType);break;case"set":i(a.valueType);break;case"union":for(const f of a.options)i(f);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":{const f=a._cachedInner??void 0;c(f?ye(f,t):_e);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(const f in a){const d=Object.getOwnPropertyDescriptor(a,f);if(!d||d.get)continue;const p=d.value;if(!(!p||typeof p!="object")){if(p._zod)i(p);else if(Array.isArray(p))for(const h of p)i(h)}}}return t.delete(e),ki(e,o)}function ki(e,t){return t!==_e&&ln.set(e,t===se),t}function $i(e,t){let n=e.buckets.get(t);return n||(n=new WeakMap,e.buckets.set(t,n)),n}let pe;const he=[],Oi={alloc(e,t,n){const r=pe;if(!r)return n;pe=void 0;const o={value:n,issues:null};return r.set(t.value,o),he.push(o),n},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{const n=e._zod.parse,r=(o,i)=>{if(i.direction!=="backward"&&Zi(i,o.value))throw new zi;return n(o,i)};e._zod.parse=r,e._zod.run===n&&(e._zod.run=r)})},attach(e){var t;let n,r=!1,o,i;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{const s=e._zod.parse,c=(a,u)=>{if(n===void 0){const $=ye(e,new Set);if($===re)return e._zod.parse=s,e._zod.run===c&&(e._zod.run=s),s(a,u);$===se||r?n=!0:r=!0}const f=a.value;if(!fn(f))return s(a,u);let d=u[Le];d||(d={buckets:new WeakMap,backEdges:void 0},u[Le]=d);let p;o===u?p=i:(p=$i(d,e),o=u,i=p);const h=p.get(f);if(h)return a.value=h.value,h.issues?h.issues.length&&a.issues.push(...Ce(h.issues)):(a.memo=!0,d.backEdges??(d.backEdges=new WeakSet),d.backEdges.add(h.value)),a;pe=p;const m=he.length,b=s(a,u);pe=void 0;const g=he.length>m?he.pop():void 0;return b instanceof Promise?b.then($=>(g&&(g.issues=$.issues.length?Ce($.issues):zt),$)):(g&&(g.issues=b.issues.length?Ce(b.issues):zt),b)};e._zod.parse=c,e._zod.run===s&&(e._zod.run=c)})}};function Si(){return Oi}function Zi(e,t){const n=e[Le]?.backEdges;return n!==void 0&&fn(t)&&n.has(t)}const Pi=()=>{const 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}const n={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"},r={nan:"NaN"};function o(i,s){return i==="number"&&typeof s=="number"&&!Number.isFinite(s)?String(s):r[i]??i}return i=>{switch(i.code){case"invalid_type":{const s=o(i.expected),c=rr(i.input),a=o(c,i.input);return`Invalid input: expected ${s}, received ${a}`}case"invalid_value":return i.values.length===1?`Invalid input: expected ${Vt(i.values[0])}`:`Invalid option: expected one of ${it(i.values,"|")}`;case"too_big":{const s=i.exact?"exactly ":i.inclusive?"<=":"<",c=t(i.origin);return c?`Too big: expected ${i.origin??"value"} to have ${s}${i.maximum.toString()} ${c.unit??"elements"}`:`Too big: expected ${i.origin??"value"} to be ${s}${i.maximum.toString()}`}case"too_small":{const s=i.exact?"exactly ":i.inclusive?">=":">",c=t(i.origin);return c?`Too small: expected ${i.origin} to have ${s}${i.minimum.toString()} ${c.unit}`:`Too small: expected ${i.origin} to be ${s}${i.minimum.toString()}`}case"invalid_format":{const s=i;return s.format==="starts_with"?`Invalid string: must start with "${s.prefix}"`:s.format==="ends_with"?`Invalid string: must end with "${s.suffix}"`:s.format==="includes"?`Invalid string: must include "${s.includes}"`:s.format==="regex"?`Invalid string: must match pattern ${s.pattern}`:`Invalid ${n[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":""}: ${it(i.keys,", ")}`;case"invalid_key":return`Invalid key in ${i.origin}`;case"invalid_union":return i.options&&Array.isArray(i.options)&&i.options.length>0?`Invalid discriminator value. Expected ${i.options.map(c=>`'${c}'`).join(" | ")}`:i.inclusive===!1?"Invalid input: more than one option matched":"Invalid input";case"invalid_element":return`Invalid value in ${i.origin}`;default:return"Invalid input"}}};function Ei(){return{localeError:Pi()}}var kt;class Ii{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const r=n[0];return this._map.set(t,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const o={...r,...this._map.get(t)};return Object.keys(o).length?o:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function Ai(){return new Ii}(kt=globalThis).__zod_globalRegistry??(kt.__zod_globalRegistry=Ai());const oe=globalThis.__zod_globalRegistry;function Ci(e){return e.checks&&(e.checks=[...e.checks]),e}function ji(e,t){return new e(Ci({type:"string",...v(t)}))}function Ti(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...v(t)})}function Ri(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...v(t)})}function Di(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...v(t)})}function Ni(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...v(t)})}function Li(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...v(t)})}function Ui(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...v(t)})}function Fi(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...v(t)})}function xi(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...v(t)})}function Mi(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...v(t)})}function Ji(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...v(t)})}function Bi(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...v(t)})}function Ki(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...v(t)})}function Vi(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...v(t)})}function Wi(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...v(t)})}function qi(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...v(t)})}function Gi(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...v(t)})}function Xi(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...v(t)})}function Hi(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...v(t)})}function Yi(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...v(t)})}function Qi(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...v(t)})}function es(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...v(t)})}function ts(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...v(t)})}function ns(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...v(t)})}function rs(e,t){return new e({type:"string",format:"date",check:"string_format",...v(t)})}function os(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...v(t)})}function is(e,t){return new e({type:"string",format:"duration",check:"string_format",...v(t)})}function ss(e,t){return new e({type:"boolean",...v(t)})}function cs(e){return new e({type:"unknown"})}function as(e,t){return new e({type:"never",...v(t)})}function dn(e,t){return new ao({check:"max_length",...v(t),maximum:e})}function ze(e,t){return new uo({check:"min_length",...v(t),minimum:e})}function pn(e,t){return new fo({check:"length_equals",...v(t),length:e})}function us(e,t){return new lo({check:"string_format",format:"regex",...v(t),pattern:e})}function fs(e){return new po({check:"string_format",format:"lowercase",...v(e)})}function ls(e){return new ho({check:"string_format",format:"uppercase",...v(e)})}function ds(e,t){return new mo({check:"string_format",format:"includes",...v(t),includes:e})}function ps(e,t){return new go({check:"string_format",format:"starts_with",...v(t),prefix:e})}function hs(e,t){return new _o({check:"string_format",format:"ends_with",...v(t),suffix:e})}function te(e){return new yo({check:"overwrite",tx:e})}function ms(e){return te(t=>t.normalize(e))}function gs(){return te(e=>e.trim())}function _s(){return te(e=>e.toLowerCase())}function ys(){return te(e=>e.toUpperCase())}function vs(){return te(e=>Jn(e))}function bs(e,t,n){return new e({type:"array",element:t,...v(n)})}function ws(e,t,n){return new e({type:"custom",check:"custom",fn:t,...v(n)})}function zs(e,t){const n=ks(r=>(r.addIssue=o=>{if(typeof o=="string")r.issues.push(fe(o,r.value,n._zod.def));else{const i=o;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),"input"in i||(i.input=r.value),i.inst??(i.inst=n),i.continue??(i.continue=!n._zod.def.abort),r.issues.push(fe(i))}},e(r.value,r)),t);return n}function ks(e,t){const n=new U({check:"custom",...v(t)});return n._zod.check=e,n}function ce(e,...t){for(const n of t)for(const r of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,r)&&X(e,r,n[r]);return e}function hn(e){let t=e?.target??"draft-2020-12";return t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??oe,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 le(e,t,n,r,o){const i=typeof t.unrepresentable=="function"?t.unrepresentable({zodSchema:e,path:r.path,message:o}):t.unrepresentable;if(i==="any")return!1;if(i===void 0||i==="throw")throw new Error(o);return Object.assign(n,i),!0}function C(e,t,n={path:[],schemaPath:[]}){var r;const o=e._zod.def,i=t.seen.get(e);if(i)return i.count++,n.schemaPath.includes(e)&&(i.cycle=n.path),i.schema;const s={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,s),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;const c=e._zod.toJSONSchema?.();if(c)s.schema=c;else{const f={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,s.schema,f);else{const p=s.schema,h=t.processors[o.type];if(!h)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);h(e,t,p,f)}const d=e._zod.parent;d&&(s.ref||(s.ref=d),C(d,t,f),t.seen.get(d).isParent=!0)}const a=t.metadataRegistry.get(e);return a&&ce(s.schema,a),t.io==="input"&&j(e)&&(delete s.schema.examples,delete s.schema.default),t.io==="input"&&"_prefault"in s.schema&&((r=s.schema).default??(r.default=s.schema._prefault)),delete s.schema._prefault,t.seen.get(e).schema}function $t(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function mn(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");if(e.external&&e.sharedDefsExtractedFor===e.external)return;const r=new Map;for(const s of e.seen.entries()){const c=e.metadataRegistry.get(s[0])?.id;if(c){const a=r.get(c);if(a&&a!==s[0])throw new Error(`Duplicate schema id "${c}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(c,s[0])}}const o=s=>{const c=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const d=e.external.registry.get(s[0])?.id,p=e.external.uri??(m=>m);if(d)return{ref:p(d)};const h=s[1].defId??s[1].schema.id??`schema${e.counter++}`;return s[1].defId=h,{defId:h,ref:`${p("__shared")}#/${c}/${$t(h)}`}}const a="#",u=`${a}/${c}/`;if(s[1]===n&&!s[1].schema.id)return{ref:a};const f=s[1].schema.id??`__schema${e.counter++}`;return{defId:f,ref:u+$t(f)}},i=s=>{if(s[1].schema.$ref)return;const c=s[1],{ref:a,defId:u}=o(s);c.def={...c.schema},u&&(c.defId=u);const f=c.schema;for(const d in f)delete f[d];f.$ref=a};if(e.cycles==="throw")for(const s of e.seen.entries()){const c=s[1];if(c.cycle)throw new Error(`Cycle detected: #/${c.cycle?.join("/")}/<root>
56
+
57
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const s of e.seen.entries()){const c=s[1];if(t===s[0]){i(s);continue}if(e.external){const 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}c.count>1&&e.reused==="ref"&&i(s)}e.external&&(e.sharedDefsExtractedFor=e.external)}function gn(e){const t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;const n=[];for(const r of t){if(!r||typeof r!="object")return;gn(r);const o=Object.keys(r);if(o.length!==1||o[0]!=="type")return;const i=r.type;for(const s of Array.isArray(i)?i:[i]){if(typeof s!="string")return;n.includes(s)||n.push(s)}}delete e.anyOf,e.type=n.length===1?n[0]:n}const _n=new Set(["type","properties","required","additionalProperties"]),Ot=["oneOf","anyOf"];function St(e){const t=e.additionalProperties;return t===void 0||t===!1||typeof t!="object"||t===null?null:Object.keys(t).length?t:null}function Ue(e){const t=[];for(const i of e){if(typeof i!="object"||i.type!=="object")return null;for(const s in i)if(!_n.has(s))return null;t.push(i)}const n={},r=new Set;for(const i of t){for(const s in i.properties){if(Object.prototype.hasOwnProperty.call(n,s))continue;const c=[];for(const u of t){const f=u.properties?.[s]??St(u);f!=null&&(c.some(d=>JSON.stringify(d)===JSON.stringify(f))||c.push(f))}const a=c.length===1?c[0]:Ue(c)??{allOf:c};X(n,s,a)}for(const s of i.required??[])r.add(s)}const o={type:"object",properties:n};if(r.size&&(o.required=[...r]),t.every(i=>i.additionalProperties===!1))o.additionalProperties=!1;else{const i=[];for(const s of t){const c=St(s);c&&!i.some(a=>JSON.stringify(a)===JSON.stringify(c))&&i.push(c)}i.length===1?o.additionalProperties=i[0]:i.length>1&&(o.additionalProperties={allOf:i})}return o}function $s(e){const t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(const o of _n)if(o in e)return;const n=t.filter(o=>Ot.some(i=>Array.isArray(o[i])));let r=null;if(!n.length)r=Ue(t);else{const o=n[0],i=Ot.find(a=>Array.isArray(o[a]));if(Object.keys(o).length!==1)return;const s=t.filter(a=>a!==o),c=o[i].map(a=>Ue([...s,a]));if(c.some(a=>!a))return;r={[i]:c}}r&&(delete e.allOf,ce(e,r))}function yn(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=c=>{const a=e.seen.get(c);if(a.ref===null)return;const u=a.def??a.schema,f={...u},d=a.ref;if(a.ref=null,d){r(d);const h=e.seen.get(d),m=h.schema;if(m.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(u.allOf=u.allOf??[],u.allOf.push(m)):ce(u,m),ce(u,f),c._zod.parent===d)for(const g in u)g==="$ref"||g==="allOf"||g in f||delete u[g];if(m.$ref&&h.def)for(const g in u)g==="$ref"||g==="allOf"||g in h.def&&JSON.stringify(u[g])===JSON.stringify(h.def[g])&&delete u[g]}const p=c._zod.parent;if(p&&p!==d){r(p);const h=e.seen.get(p);if(h?.schema.$ref&&(u.$ref=h.schema.$ref,h.def))for(const m in u)m==="$ref"||m==="allOf"||m in h.def&&JSON.stringify(u[m])===JSON.stringify(h.def[m])&&delete u[m]}e.override({zodSchema:c,jsonSchema:u,path:a.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(const c of[...e.seen.entries()].reverse())r(c[0]);if(e.target!=="openapi-3.0")for(const c of e.seen.entries())gn(c[1].def??c[1].schema);for(const c of e.deferred)c();if(e.intersections.length){const c=new Map;for(const a of e.seen.values())for(const u of[a.schema,a.def]){const f=u?.allOf;if(!Array.isArray(f))continue;const d=c.get(f);d?d.push(u):c.set(f,[u])}for(const a of e.intersections)for(const u of c.get(a)??[])$s(u)}}const o={};if(e.target==="draft-2020-12"?o.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?o.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?o.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const c=e.external.registry.get(t)?.id;if(!c)throw new Error("Schema is missing an `id` property");o.$id=e.external.uri(c)}ce(o,n.defId?n.schema:n.def??n.schema);const i=e.metadataRegistry.get(t)?.id;i!==void 0&&o.id===i&&delete o.id;const s=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(const c of e.seen.entries()){const a=c[1];a.def&&a.defId&&(a.def.id===a.defId&&delete a.def.id,X(s,a.defId,a.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(s).length>0&&(e.target==="draft-2020-12"?o.$defs=s:o.definitions=s);try{const c=JSON.parse(JSON.stringify(o));return Object.defineProperty(c,"~standard",{value:{...t["~standard"],jsonSchema:{input:ke(t,"input",e.processors),output:ke(t,"output",e.processors)}},enumerable:!1,writable:!1}),c}catch{throw new Error("Error converting schema to JSON.")}}function j(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return j(r.element,n);if(r.type==="set")return j(r.valueType,n);if(r.type==="lazy")return j(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault"||r.type==="catch")return j(r.innerType,n);if(r.type==="intersection")return j(r.left,n)||j(r.right,n);if(r.type==="record"||r.type==="map")return j(r.keyType,n)||j(r.valueType,n);if(r.type==="pipe")return e._zod.traits.has("$ZodCodec")?!0:j(r.in,n)||j(r.out,n);if(r.type==="object"){for(const o in r.shape)if(j(r.shape[o],n))return!0;return!1}if(r.type==="union"){for(const o of r.options)if(j(o,n))return!0;return!1}if(r.type==="tuple"){for(const o of r.items)if(j(o,n))return!0;return!!(r.rest&&j(r.rest,n))}return!1}const Os=(e,t={})=>n=>{const r=hn({...n,processors:t});return C(e,r),mn(r,e),yn(r,e)},ke=(e,t,n={})=>r=>{const{libraryOptions:o,target:i}=r??{},s=hn({...o??{},target:i,io:t,processors:n});return C(e,s),mn(s,e),yn(s,e)},H=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},Y=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},Zt=(e,t)=>{H(e,"minimum",t),Y(e,"maximum",t)},vn=(e,t)=>{e.multipleOf??(e.multipleOf=[]),e.multipleOf.includes(t)||e.multipleOf.push(t)},bn=(e,t)=>{e.patterns??(e.patterns=new Set),e.patterns.add(t)},wn=(e,t)=>{e.mime=e.mime?e.mime.filter(n=>t.includes(n)):[...t]},zn=(e,t)=>{e.format=t,t.includes("int")&&(e.isInt=!0)},Pt=(e,t)=>H(e,"minimum",t.minimum),Et=(e,t)=>Y(e,"maximum",t.maximum),It=e=>(t,n)=>{zn(t,n.format);const[r,o]=e[n.format];H(t,"minimum",r),Y(t,"maximum",o)},Ss={greater_than:(e,t)=>H(e,t.inclusive?"minimum":"exclusiveMinimum",t.value),less_than:(e,t)=>Y(e,t.inclusive?"maximum":"exclusiveMaximum",t.value),multiple_of:(e,t)=>vn(e,t.value),number_format:It(Wn),bigint_format:It(qn),min_length:Pt,max_length:Et,length_equals:(e,t)=>Zt(e,t.length),min_size:Pt,max_size:Et,size_equals:(e,t)=>Zt(e,t.size),string_format:(e,t)=>{zn(e,t.format),t.pattern&&bn(e,t.pattern),(t.format==="base64"||t.format==="base64url")&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>wn(e,t.mime)};function ae(e){const t={},n=e._zod.def,r=e._zod.traits.has("$ZodCheck")?[e,...n.checks??[]]:n.checks??[];for(const i of r)Ss[i._zod.def.check]?.(t,i._zod.def);const o=e._zod.bag;o.minimum!==void 0&&H(t,"minimum",o.minimum),o.exclusiveMinimum!==void 0&&H(t,"exclusiveMinimum",o.exclusiveMinimum),o.maximum!==void 0&&Y(t,"maximum",o.maximum),o.exclusiveMaximum!==void 0&&Y(t,"exclusiveMaximum",o.exclusiveMaximum),o.multipleOf!==void 0&&vn(t,o.multipleOf),o.format!==void 0&&(t.format??(t.format=o.format),o.format.includes("int")&&(t.isInt=!0)),o.mime&&wn(t,o.mime);for(const i of o.patterns??[])bn(t,i);return t}const Zs={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Ps=new Map([[sn,Xr],[tt,Hr]]),Es=e=>Ps.get(e)??e,Is=(e,t,n,r)=>{const o=n;o.type="string";const{minimum:i,maximum:s,format:c,patterns:a,contentEncoding:u,laxFormat:f}=ae(e);if(typeof i=="number"&&(o.minLength=i),typeof s=="number"&&(o.maxLength=s),c&&(o.format=Zs[c]??c,o.format===""&&delete o.format,(c==="time"||f)&&delete o.format),u&&(o.contentEncoding=u),a&&a.size>0){const d=[...a].map(Es);d.length===1?o.pattern=d[0].source:d.length>1&&(o.allOf=[...d.map(p=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:p.source}))])}},As=(e,t,n,r)=>{n.type="boolean"},Cs=(e,t,n,r)=>{n.not={}},js=(e,t,n,r)=>{},Ts=(e,t,n,r)=>{const o=e._zod.def,i=je(o.entries);if(i.length===0){n.not={};return}i.every(s=>typeof s=="number")&&(n.type="number"),i.every(s=>typeof s=="string")&&(n.type="string"),n.enum=i},Rs=(e,t,n,r)=>{le(e,t,n,r,"Custom types cannot be represented in JSON Schema")},Ds=(e,t,n,r)=>{le(e,t,n,r,"Transforms cannot be represented in JSON Schema")},Ns=(e,t,n,r)=>{const o=n,i=e._zod.def,{minimum:s,maximum:c}=ae(e);typeof s=="number"&&(o.minItems=s),typeof c=="number"&&(o.maxItems=c),o.type="array",o.items=C(i.element,t,{...r,path:[...r.path,"items"]})};function Fe(e){const t=e._zod.def;return t.type==="pipe"&&t.in._zod.traits.has("$ZodTransform")?Fe(t.out):t.type==="catch"?Fe(t.innerType):e._zod.optin}const Ls=(e,t,n,r)=>{const o=n,i=e._zod.def,s=i.shape;if(Object.getOwnPropertySymbols(s).length&&le(e,t,o,r,"Symbol keys cannot be represented in JSON Schema"))return;o.type="object",o.properties={};for(const u in s)X(o.properties,u,C(s[u],t,{...r,path:[...r.path,"properties",u]}));const a=[];for(const u of Object.keys(s)){const f=i.shape[u];(t.io==="input"?Fe(f)===void 0:f._zod.optout===void 0)&&a.push(u)}a.length>0&&(o.required=a),i.catchall?._zod.def.type==="never"?o.additionalProperties=!1:i.catchall?i.catchall&&(o.additionalProperties=C(i.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):t.io==="output"&&(o.additionalProperties=!1)},Us=(e,t,n,r)=>{const o=e._zod.def,i=o.inclusive===!1,s=o.options.map((c,a)=>C(c,t,{...r,path:[...r.path,i?"oneOf":"anyOf",a]}));i?n.oneOf=s:n.anyOf=s},Fs=(e,t,n,r)=>{const o=e._zod.def,i=C(o.left,t,{...r,path:[...r.path,"allOf",0]}),s=C(o.right,t,{...r,path:[...r.path,"allOf",1]}),c=u=>"allOf"in u&&Object.keys(u).length===1,a=[...c(i)?i.allOf:[i],...c(s)?s.allOf:[s]];n.allOf=a,t.intersections.push(a)},xs=(e,t,n,r)=>{const o=e._zod.def,i=C(o.innerType,t,r),s=t.seen.get(e);t.target==="openapi-3.0"?(s.ref=o.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]},Ms=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType},nt=Symbol();function kn(e,t,n,r,o){let i=!1;const s=JSON.stringify(e,(c,a)=>typeof a!="bigint"?a:(i=!0,null));return i?(le(t,n,r,o,"BigInt defaults cannot be represented in JSON Schema"),nt):JSON.parse(s)}const Js=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType;const s=kn(o.defaultValue,e,t,n,r);s!==nt&&(n.default=s)},Bs=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const i=t.seen.get(e);if(i.ref=o.innerType,t.io!=="input")return;const s=kn(o.defaultValue,e,t,n,r);s!==nt&&(n._prefault=s)},Ks=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType;let s;try{s=o.catchValue(void 0)}catch{le(e,t,n,r,"Dynamic catch values are not supported in JSON Schema");return}n.default=s},Vs=(e,t,n,r)=>{const 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,r);const c=t.seen.get(e);c.ref=s},Ws=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType,n.readOnly=!0},$n=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType},At=new WeakSet([Object.prototype,Error.prototype]);function me(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){const r=n(this);return Object.defineProperty(this,t,{value:r,configurable:!0,writable:!0}),r},set(r){Object.defineProperty(this,t,{value:r,configurable:!0,writable:!0})}})}const qs=(e,t)=>{_r.init(e,t),e.name="ZodError";const n=Object.getPrototypeOf(e);At.has(n)||(At.add(n),me(n,"format",r=>o=>br(r,o)),me(n,"flatten",r=>o=>vr(r,o)),me(n,"addIssue",r=>o=>{r.issues.push(o),r.message=JSON.stringify(r.issues,Te,2)}),me(n,"addIssues",r=>o=>{r.issues.push(...o),r.message=JSON.stringify(r.issues,Te,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},R=l("ZodError",qs,void 0,{Parent:Error}),Gs=Ge(R),Xs=Xe(R),Hs=He(R),Ys=Ye(R),Qs=Sr(R),ec=Zr(R),tc=Pr(R),nc=Er(R),rc=Ir(R),oc=Ar(R),ic=Cr(R),sc=jr(R);function cc(){L.localeError||W(Ei())}function rt(){L.memoizer||W({memoizer:Si()})}const E=l("ZodType",(e,t)=>(cc(),P.init(e,t),e.def=t,e.type=t.type,e),{check(...e){const t=this.def;return this.clone(T(t,{checks:[...t.checks??[],...e.map(n=>typeof n=="function"?{_zod:{check:n,def:{check:"custom"},onattach:[]}}:n)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return V(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(na(e,t))},superRefine(e,t){return this.check(ra(e,t))},overwrite(e){return this.check(te(e))},optional(){return jt(this)},exactOptional(){return Jc(this)},nullable(){return Tt(this)},nullish(){return jt(Tt(this))},nonoptional(e){return Gc(this,e)},array(){return Pn(this)},or(e){return Nc([this,e])},and(e){return Uc(this,e)},transform(e){return Rt(this,Mc(e))},default(e){return Vc(this,e)},prefault(e){return qc(this,e)},catch(e){return Hc(this,e)},pipe(e){return Rt(this,e)},readonly(){return ea(this)},describe(e){const t=this.clone();return oe.add(t,{description:e}),t},meta(...e){if(e.length===0)return oe.get(this);const t=this.clone();return oe.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 Gt(this,"~standard",{...en(this),jsonSchema:{input:ke(this,"input"),output:ke(this,"output")}})},set"~standard"(e){K(this,"~standard",e)},parse:function e(t,n){return Gs(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await Xs(this,t,n,{callee:e})},safeParse(e,t){return Hs(this,e,t)},async safeParseAsync(e,t){return Ys(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){K(this,"spa",e)},validate(e,t){return kr(this,e,t)},validateAsync(e,t){return Or(this,e,t)},encode:function e(t,n){return Qs(this,t,n,{callee:e})},decode:function e(t,n){return ec(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await tc(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await nc(this,t,n,{callee:e})},safeEncode(e,t){return rc(this,e,t)},safeDecode(e,t){return oc(this,e,t)},async safeEncodeAsync(e,t){return ic(this,e,t)},async safeDecodeAsync(e,t){return sc(this,e,t)},toJSONSchema(e){return Os(this,{})(e)},get description(){return oe.get(this)?.description},get _def(){return this._zod.def}}),On=l("_ZodString",(e,t)=>{et.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Is(e,n,r)},ir({format:e=>ae(e).format??null,minLength:e=>ae(e).minimum??null,maxLength:e=>ae(e).maximum??null},{regex(...e){return this.check(us(...e))},includes(...e){return this.check(ds(...e))},startsWith(...e){return this.check(ps(...e))},endsWith(...e){return this.check(hs(...e))},min(...e){return this.check(ze(...e))},max(...e){return this.check(dn(...e))},length(...e){return this.check(pn(...e))},nonempty(...e){return this.check(ze(1,...e))},lowercase(e){return this.check(fs(e))},uppercase(e){return this.check(ls(e))},trim(){return this.check(gs())},normalize(...e){return this.check(ms(...e))},toLowerCase(){return this.check(_s())},toUpperCase(){return this.check(ys())},slugify(){return this.check(vs())}})),ac=l("ZodString",(e,t)=>{et.init(e,t),On.init(e,t)},{email(e){return this.check(Ti(pc,e))},url(e){return this.check(Fi(mc,e))},jwt(e){return this.check(ts(Ic,e))},emoji(e){return this.check(xi(gc,e))},guid(e){return this.check(Ri(hc,e))},uuid(e){return this.check(Di(ge,e))},uuidv4(e){return this.check(Ni(ge,e))},uuidv6(e){return this.check(Li(ge,e))},uuidv7(e){return this.check(Ui(ge,e))},nanoid(e){return this.check(Mi(_c,e))},cuid(e){return this.check(Ji(yc,e))},cuid2(e){return this.check(Bi(vc,e))},ulid(e){return this.check(Ki(bc,e))},base64(e){return this.check(Yi(Zc,e))},base64url(e){return this.check(Qi(Pc,e))},xid(e){return this.check(Vi(wc,e))},ksuid(e){return this.check(Wi(zc,e))},ipv4(e){return this.check(qi(kc,e))},ipv6(e){return this.check(Gi($c,e))},cidrv4(e){return this.check(Xi(Oc,e))},cidrv6(e){return this.check(Hi(Sc,e))},e164(e){return this.check(es(Ec,e))},datetime(e){return this.check(ns(uc,e))},date(e){return this.check(rs(fc,e))},time(e){return this.check(os(lc,e))},duration(e){return this.check(is(dc,e))}});function Sn(e){return ji(ac,e)}const S=l("ZodStringFormat",(e,t)=>{O.init(e,t),On.init(e,t)}),uc=l("ZodISODateTime",(e,t)=>{Lo.init(e,t),S.init(e,t)}),fc=l("ZodISODate",(e,t)=>{Uo.init(e,t),S.init(e,t)}),lc=l("ZodISOTime",(e,t)=>{Fo.init(e,t),S.init(e,t)}),dc=l("ZodISODuration",(e,t)=>{xo.init(e,t),S.init(e,t)}),pc=l("ZodEmail",(e,t)=>{$o.init(e,t),S.init(e,t)}),hc=l("ZodGUID",(e,t)=>{zo.init(e,t),S.init(e,t)}),ge=l("ZodUUID",(e,t)=>{ko.init(e,t),S.init(e,t)}),mc=l("ZodURL",(e,t)=>{Io.init(e,t),S.init(e,t)}),gc=l("ZodEmoji",(e,t)=>{Ao.init(e,t),S.init(e,t)}),_c=l("ZodNanoID",(e,t)=>{Co.init(e,t),S.init(e,t)}),yc=l("ZodCUID",(e,t)=>{jo.init(e,t),S.init(e,t)}),vc=l("ZodCUID2",(e,t)=>{To.init(e,t),S.init(e,t)}),bc=l("ZodULID",(e,t)=>{Ro.init(e,t),S.init(e,t)}),wc=l("ZodXID",(e,t)=>{Do.init(e,t),S.init(e,t)}),zc=l("ZodKSUID",(e,t)=>{No.init(e,t),S.init(e,t)}),kc=l("ZodIPv4",(e,t)=>{Mo.init(e,t),S.init(e,t)}),$c=l("ZodIPv6",(e,t)=>{Bo.init(e,t),S.init(e,t)}),Oc=l("ZodCIDRv4",(e,t)=>{Ko.init(e,t),S.init(e,t)}),Sc=l("ZodCIDRv6",(e,t)=>{Wo.init(e,t),S.init(e,t)}),Zc=l("ZodBase64",(e,t)=>{qo.init(e,t),S.init(e,t)}),Pc=l("ZodBase64URL",(e,t)=>{Xo.init(e,t),S.init(e,t)}),Ec=l("ZodE164",(e,t)=>{Ho.init(e,t),S.init(e,t)}),Ic=l("ZodJWT",(e,t)=>{Qo.init(e,t),S.init(e,t)}),Ac=l("ZodBoolean",(e,t)=>{ei.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>As(e,n,r)});function $e(e){return ss(Ac,e)}const Cc=l("ZodUnknown",(e,t)=>{ti.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>js()});function Ct(){return cs(Cc)}const jc=l("ZodNever",(e,t)=>{ni.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Cs(e,n,r)});function Zn(e){return as(jc,e)}const Tc=l("ZodArray",(e,t)=>{rt(),ii.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ns(e,n,r,o),e.element=t.element},{min(e,t){return this.check(ze(e,t))},nonempty(e){return this.check(ze(1,e))},max(e,t){return this.check(dn(e,t))},length(e,t){return this.check(pn(e,t))},unwrap(){return this.element}});function Pn(e,t){return bs(Tc,e,t)}const Rc=l("ZodObject",(e,t)=>{rt(),ai.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ls(e,n,r,o),ur(e,"shape",n=>n._zod.def.shape,!1)},{keyof(){return Fc(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(T(this._zod.def,{catchall:e}))},passthrough(){return this.clone(T(this._zod.def,{catchall:Ct()}))},loose(){return this.clone(T(this._zod.def,{catchall:Ct()}))},strict(){return this.clone(T(this._zod.def,{catchall:Zn()}))},strip(){return this.clone(T(this._zod.def,{catchall:void 0}))},extend(e){return Hn(this,e)},safeExtend(e){return Yn(this,e)},merge(e){return Qn(this,e)},pick(e){return Gn(this,e)},omit(e){return Xn(this,e)},partial(...e){return st(En,this,e[0])},exactPartial(...e){return st(In,this,e[0],"exactPartial")},required(...e){return er(An,this,e[0])}});function Q(e,t){return new Rc({type:"object",shape:e,catchall:Zn(),...v(t)})}const Dc=l("ZodUnion",(e,t)=>{ui.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Us(e,n,r,o),e.options=t.options});function Nc(e,t){return new Dc({type:"union",options:e,...v(t)})}const Lc=l("ZodIntersection",(e,t)=>{fi.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Fs(e,n,r,o)});function Uc(e,t){return new Lc({type:"intersection",left:e,right:t})}const xe=l("ZodEnum",(e,t)=>{li.init(e,t),E.init(e,t),e._zod.processJSONSchema=(r,o,i)=>Ts(e,r,o),e.enum=t.entries,e.options=[...e._zod.values];const n=new Set(Object.keys(t.entries));e.extract=(r,o)=>{const i={};for(const s of r)if(n.has(s))i[s]=t.entries[s];else throw new Error(`Key ${s} not found in enum`);return new xe({...t,checks:[],...v(o),entries:i})},e.exclude=(r,o)=>{const i={...t.entries};for(const s of r)if(n.has(s))delete i[s];else throw new Error(`Key ${s} not found in enum`);return new xe({...t,checks:[],...v(o),entries:i})}});function Fc(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new xe({type:"enum",entries:n,...v(t)})}const xc=l("ZodTransform",(e,t)=>{rt(),di.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ds(e,n,r,o),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Xt(e.constructor.name);n.addIssue=i=>{if(typeof i=="string")n.issues.push(fe(i,n.value,t));else{const s=i;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),"input"in s||(s.input=n.value),s.inst??(s.inst=e),n.issues.push(fe(s))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(i=>(n.value=i,n)):(n.value=o,n)}});function Mc(e){return new xc({type:"transform",transform:e})}const En=l("ZodOptional",(e,t)=>{un.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>$n(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function jt(e){return new En({type:"optional",innerType:e})}const In=l("ZodExactOptional",(e,t)=>{pi.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>$n(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Jc(e){return new In({type:"optional",innerType:e})}const Bc=l("ZodNullable",(e,t)=>{hi.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>xs(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Tt(e){return new Bc({type:"nullable",innerType:e})}const Kc=l("ZodDefault",(e,t)=>{mi.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Js(e,n,r,o),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Vc(e,t){return new Kc({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Kt(t)}})}const Wc=l("ZodPrefault",(e,t)=>{gi.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Bs(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function qc(e,t){return new Wc({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():Kt(t)}})}const An=l("ZodNonOptional",(e,t)=>{_i.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ms(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Gc(e,t){return new An({type:"nonoptional",innerType:e,...v(t)})}const Xc=l("ZodCatch",(e,t)=>{yi.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ks(e,n,r,o),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Hc(e,t){return new Xc({type:"catch",innerType:e,catchValue:typeof t=="function"?t:lr(t)})}const Yc=l("ZodPipe",(e,t)=>{vi.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Vs(e,n,r,o),e.in=t.in,e.out=t.out});function Rt(e,t){return new Yc({type:"pipe",in:e,out:t})}const Qc=l("ZodReadonly",(e,t)=>{bi.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ws(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function ea(e){return new Qc({type:"readonly",innerType:e})}const ta=l("ZodCustom",(e,t)=>{wi.init(e,t),E.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Rs(e,n,r,o)});function na(e,t={}){return ws(ta,e,t)}function ra(e,t){return zs(e,t)}const oa="opencode-linear-plugin",Cn=/^[a-z][a-z0-9-]{1,23}$/,Me="Use 2–24 lowercase letters, numbers, or hyphens, starting with a letter.",jn=Sn().regex(Cn,Me),Tn=Sn().regex(/^linear_[a-z][a-z0-9-]{1,23}_[a-f0-9]{12}$/),Je=Q({alias:jn,name:Tn,readOnly:$e(),enabled:$e()}),ia=Pn(Je),Dt=Q({}),Nt=Q({name:Tn}),Lt={conflict:Q({})},Rn=Ln.Rpc.define({id:oa,methods:{list:{input:Dt,output:Q({accounts:ia})},add:{input:Q({alias:jn,readOnly:$e()}),output:Je,errors:Lt},enable:{input:Nt.extend({enabled:$e()}),output:Je,errors:Lt},remove:{input:Nt,output:Dt}},events:{}});var sa=w.template("<p>If the callback page doesn’t load after you authorize, paste its full URL here."),ca=w.template("<p role=alert>"),aa=w.template("<p role=status>Preparing sign-in…");function ua(e){const t=ie.usePlugin(),n=t.ui,[r,o]=Z.createSignal(""),[i,s]=Z.createSignal(!1),[c,a]=Z.createSignal(""),[u,f]=Z.createSignal(!1),[d,p]=Z.createSignal(""),h=new AbortController,m={signal:h.signal},b=e.integrationID;let g,$=!1;function A(){g&&!$&&t.client.integration.oauth.cancel({integrationID:b,attemptID:g}).catch(()=>{})}Z.onCleanup(()=>{h.abort(),A()}),Z.onMount(()=>{F()});async function F(){try{const{data:_}=await t.client.integration.get({integrationID:b},m),y=_.methods.find(I=>I.type==="oauth");if(!y)throw new Error("OpenCode did not find a Linear OAuth method.");if(h.signal.aborted)return;const{data:z}=await t.client.integration.oauth.connect({integrationID:b,methodID:y.id});if(g=z.attemptID,h.signal.aborted){A();return}if(new URL(z.url).origin!=="https://mcp.linear.app")throw A(),new Error("Unexpected Linear sign-in address.");for(s(z.paste===!0||z.mode==="code"),o(z.url);!h.signal.aborted;){const{data:I}=await t.client.integration.oauth.status({integrationID:b,attemptID:g},m);if(I.status==="complete"){$=!0,e.onDone();return}if(I.status!=="pending"){$=!0,o(""),s(!1),p(`Linear sign-in ${I.status}. Close this dialog and try again.`);return}await new Promise(D=>setTimeout(D,1e3))}}catch{h.signal.aborted||p("Could not start or check Linear sign-in. Close this dialog and try again.")}}async function N(){if(!(!g||u()||!c().trim())){f(!0),p("");try{await t.client.integration.oauth.complete({integrationID:b,attemptID:g,code:c().trim()},m),a("")}catch{h.signal.aborted||p("Could not complete sign-in. Check the callback URL or code and try again.")}finally{f(!1)}}}return w.createComponent(n.Dialog,{get title(){return`Sign in to Linear: ${e.alias}`},description:"Open Linear in your browser, then verify the account and workspace on the consent screen.",get children(){return[w.createComponent(Z.Show,{get when(){return r()},get fallback(){return w.createComponent(Z.Show,{get when(){return!d()},get children(){return aa()}})},children:_=>w.createComponent(n.Button,{variant:"contrast",onClick:()=>t.system.openExternal(_()),children:"Open Linear in browser"})}),w.createComponent(Z.Show,{get when(){return i()},get children(){return[sa(),w.createComponent(n.TextInput,{label:"Callback URL or code",get value(){return c()},onInput:a,onSubmit:()=>{N()}}),w.createComponent(n.Button,{onClick:()=>{N()},get disabled(){return!c().trim()},get busy(){return u()},children:"Complete sign-in"})]}}),w.createComponent(Z.Show,{get when(){return d()},get children(){var _=ca();return w.insert(_,d),_}})]}})}const fa=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
58
+ <path d="M2.886 4.18A11.982 11.982 0 0 1 11.99 0C18.624 0 24 5.376 24 12.009c0 3.64-1.62 6.903-4.18 9.105L2.887 4.18ZM1.817 5.626l16.556 16.556c-.524.33-1.075.62-1.65.866L.951 7.277c.247-.575.537-1.126.866-1.65ZM.322 9.163l14.515 14.515c-.71.172-1.443.282-2.195.322L0 11.358a12 12 0 0 1 .322-2.195Zm-.17 4.862 9.823 9.824a12.02 12.02 0 0 1-9.824-9.824Z"/>
59
+ </svg>
60
+ `;var la=w.template("<p role=alert>"),da=w.template("<p>No Linear accounts added yet.");const Ut="linear-accounts",Be="Linear",pa={connected:"Connected",disabled:"Disabled",failed:"Connection failed",needs_auth:"Sign-in required",pending:"Connecting…"};async function ha(e){const[{accounts:t},{data:n}]=await Promise.all([e.client.rpc(Rn).list({}),e.client.mcp.list()]);return{accounts:t,servers:new Map(n.map(r=>[r.name,r]))}}const Ft=new WeakMap;function ma(){const e=ie.usePlugin(),t=e.ui,n=()=>e.client.rpc(Rn),[r,o]=Z.createSignal(""),[i,s]=Z.createSignal(!1),[c,a]=Z.createSignal(!1),[u,f]=Z.createSignal(""),[d,{refetch:p}]=Z.createResource(async()=>{const _=await ha(e);return Ft.set(e,_),_},{initialValue:Ft.get(e)}),h=new AbortController;let m;const b=()=>{m&&clearTimeout(m),m=setTimeout(()=>{m=void 0,p()},250)};Z.onCleanup(()=>{h.abort(),m&&clearTimeout(m)}),(async()=>{for await(const _ of e.client.event.subscribe({types:["mcp.status.changed","credential.updated"],signal:h.signal}))(_.type==="mcp.status.changed"||_.type==="credential.updated")&&b()})().catch(()=>{});async function g(_,y){if(!c()){a(!0),f("");try{await _()}catch(z){const I=z&&typeof z=="object"&&"message"in z?z.message:void 0;f(typeof I=="string"?`${y} ${I}`:y)}finally{p(),a(!1)}}}function $(){const _=r().trim().toLowerCase();if(!Cn.test(_)){f(Me);return}g(async()=>{await n().add({alias:_,readOnly:i()}),o(""),s(!1)},"Could not add the Linear account.")}async function A(_){const{data:y}=await e.client.integration.get({integrationID:_});for(const z of y.connections)z.type==="credential"&&await e.client.credential.remove({credentialID:z.id})}async function F(_){await e.dialogs.confirm({title:`Remove ${_.alias}?`,description:"This removes the connection and its saved sign-in from OpenCode.",confirm:"Remove",danger:!0})&&await g(async()=>{const{data:z}=await e.client.mcp.list(),I=z.find(D=>D.name===_.name)?.integrationID;I&&await A(I),await n().remove({name:_.name})},"Could not remove the Linear account.")}function N(_,y){e.dialogs.open(z=>w.createComponent(ua,{get alias(){return _.alias},integrationID:y,onDone:()=>{p(),z.close()}}))}return w.createComponent(t.SettingsLayout,{title:Be,description:"Connect each Linear workspace or account separately. The alias helps you select it in a conversation.",get actions(){return w.createComponent(t.Button,{onClick:()=>{p()},children:"Refresh"})},get children(){return[w.createComponent(t.SettingsSection,{title:"Add an account",get children(){return[w.createComponent(t.SettingsRow,{id:"add",title:"Account alias",description:Me,get children(){return w.createComponent(t.TextInput,{label:"Account alias",placeholder:"e.g. work",get value(){return r()},onInput:o,onSubmit:$,get disabled(){return c()}})}}),w.createComponent(t.SettingsRow,{title:"Read-only access",description:"Use Linear’s read-only endpoint for this connection.",get children(){return w.createComponent(t.Switch,{label:"Read-only access",hideLabel:!0,get checked(){return i()},onChange:s,get disabled(){return c()}})}}),w.createComponent(t.SettingsRow,{title:"Save connection",description:"Choose the matching account and workspace on Linear’s consent screen.",get children(){return w.createComponent(t.Button,{variant:"contrast",onClick:$,get disabled(){return c()||!r().trim()},children:"Add account"})}})]}}),w.createComponent(Z.Show,{get when(){return u()||d.error},get children(){var _=la();return w.insert(_,()=>u()||"Could not load Linear accounts. Refresh to try again."),_}}),w.createComponent(Z.Show,{get when(){return w.memo(()=>!d.error)()&&d()},children:_=>w.createComponent(t.SettingsSection,{title:"Connections",footer:"In chat, name the alias you want to use, for example: “Using Linear work, show my open issues.”",get children(){return[w.createComponent(Z.Show,{get when(){return _().accounts.length===0},get children(){return da()}}),w.createComponent(Z.For,{get each(){return _().accounts},children:y=>{const z=()=>_().servers.get(y.name),I=()=>z()?.status.status??(y.enabled?"pending":"disabled"),D=()=>z()?.integrationID;return w.createComponent(t.SettingsRow,{get title(){return`${y.alias} · ${pa[I()]}`},get description(){return`${y.readOnly?"Read-only":"Read-write"} · MCP: ${y.name}`},get children(){return w.createComponent(t.Menu,{get label(){return`Manage ${y.alias}`},get disabled(){return c()},get items(){return[{label:"Sign in",disabled:!D()||!y.enabled||I()==="connected",onSelect:()=>{const x=D();x&&N(y,x)}},{label:"Sign out",disabled:!D(),onSelect:()=>{const x=D();x&&g(()=>A(x),"Could not sign out of Linear.")}},{label:y.enabled?"Disable":"Enable",onSelect:()=>{g(()=>n().enable({name:y.name,enabled:!y.enabled}),"Could not change the account’s availability.")}},{label:"Remove…",onSelect:()=>{F(y)}}]}})}})}})]}})})]}})}const ga=ie.Plugin.define({icons:{logo:fa},setup(e){e.add(ie.SettingsPage,{id:Ut,icon:e.icons.logo,title:Be,entries:[{id:"add",title:"Add a Linear account",keywords:"linear workspace oauth mcp"}],render:()=>w.createComponent(ma,{})}),e.add(ie.Command,{id:"accounts",title:Be,keywords:"manage linear accounts workspace oauth mcp",run:()=>e.layout.settings(Ut)})}});exports.default=ga;
Binary file
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@morozinc/opencode-linear-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "repository": "git+https://github.com/ShiftHackZ/opencode-linear-plugin.git",
6
+ "keywords": [
7
+ "opencode",
8
+ "opencode-plugin",
9
+ "linear"
10
+ ],
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "registry": "https://registry.npmjs.org/"
14
+ },
15
+ "description": "Manage multiple Linear OAuth accounts in OpenCode Desktop using the official Linear MCP server.",
16
+ "type": "module",
17
+ "exports": {
18
+ ".": "./src/index.ts",
19
+ "./gui-experimental": "./dist/gui-experimental.cjs",
20
+ "./rpc": "./src/rpc.ts"
21
+ },
22
+ "files": [
23
+ "src",
24
+ "dist",
25
+ "docs/screenshots"
26
+ ],
27
+ "scripts": {
28
+ "build": "vite build",
29
+ "check": "tsc --noEmit",
30
+ "prepack": "npm run check && npm run build"
31
+ },
32
+ "dependencies": {
33
+ "@opencode/plugin": "2.4.3",
34
+ "zod": "^4.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^22.0.0",
38
+ "solid-js": "^1.9.0",
39
+ "typescript": "^5.9.0",
40
+ "vite": "^7.0.0",
41
+ "vite-plugin-solid": "^2.11.0"
42
+ },
43
+ "engines": {
44
+ "node": "^20.19.0 || >=22.12.0"
45
+ }
46
+ }
package/src/gui.tsx ADDED
@@ -0,0 +1,306 @@
1
+ import {
2
+ Command,
3
+ Plugin,
4
+ SettingsPage,
5
+ usePlugin,
6
+ type Context,
7
+ } from "@opencode/plugin/gui";
8
+ import { createResource, createSignal, For, onCleanup, Show } from "solid-js";
9
+ import {
10
+ aliasHint,
11
+ aliasPattern,
12
+ LinearAccounts,
13
+ type Account,
14
+ } from "./rpc.js";
15
+ import { LinearSignIn } from "./sign-in.js";
16
+ import logo from "./linear.svg?raw";
17
+
18
+ const settingsID = "linear-accounts";
19
+ const title = "Linear";
20
+ const statusLabels = {
21
+ connected: "Connected",
22
+ disabled: "Disabled",
23
+ failed: "Connection failed",
24
+ needs_auth: "Sign-in required",
25
+ pending: "Connecting…",
26
+ };
27
+
28
+ async function loadView(ctx: Context) {
29
+ const [{ accounts }, { data }] = await Promise.all([
30
+ ctx.client.rpc(LinearAccounts).list({}),
31
+ ctx.client.mcp.list(),
32
+ ]);
33
+ return {
34
+ accounts,
35
+ servers: new Map(data.map((server) => [server.name, server])),
36
+ };
37
+ }
38
+
39
+ const viewCache = new WeakMap<Context, Awaited<ReturnType<typeof loadView>>>();
40
+
41
+ function LinearSettings() {
42
+ const ctx = usePlugin();
43
+ const ui = ctx.ui;
44
+ const rpc = () => ctx.client.rpc(LinearAccounts);
45
+ const [alias, setAlias] = createSignal("");
46
+ const [readOnly, setReadOnly] = createSignal(false);
47
+ const [busy, setBusy] = createSignal(false);
48
+ const [error, setError] = createSignal("");
49
+ const [view, { refetch }] = createResource(
50
+ async () => {
51
+ const result = await loadView(ctx);
52
+ viewCache.set(ctx, result);
53
+ return result;
54
+ },
55
+ { initialValue: viewCache.get(ctx) },
56
+ );
57
+
58
+ const events = new AbortController();
59
+ let refreshTimer: ReturnType<typeof setTimeout> | undefined;
60
+ const scheduleRefresh = () => {
61
+ if (refreshTimer) clearTimeout(refreshTimer);
62
+ refreshTimer = setTimeout(() => {
63
+ refreshTimer = undefined;
64
+ void refetch();
65
+ }, 250);
66
+ };
67
+ onCleanup(() => {
68
+ events.abort();
69
+ if (refreshTimer) clearTimeout(refreshTimer);
70
+ });
71
+ void (async () => {
72
+ for await (const event of ctx.client.event.subscribe({
73
+ types: ["mcp.status.changed", "credential.updated"],
74
+ signal: events.signal,
75
+ })) {
76
+ if (
77
+ event.type === "mcp.status.changed" ||
78
+ event.type === "credential.updated"
79
+ )
80
+ scheduleRefresh();
81
+ }
82
+ })().catch(() => {
83
+ /* Refresh remains available if the event stream ends. */
84
+ });
85
+
86
+ async function run(action: () => Promise<unknown>, failure: string) {
87
+ if (busy()) return;
88
+ setBusy(true);
89
+ setError("");
90
+ try {
91
+ await action();
92
+ } catch (cause) {
93
+ const message =
94
+ cause && typeof cause === "object" && "message" in cause
95
+ ? cause.message
96
+ : undefined;
97
+ setError(typeof message === "string" ? `${failure} ${message}` : failure);
98
+ } finally {
99
+ void refetch();
100
+ setBusy(false);
101
+ }
102
+ }
103
+
104
+ function add() {
105
+ const value = alias().trim().toLowerCase();
106
+ if (!aliasPattern.test(value)) {
107
+ setError(aliasHint);
108
+ return;
109
+ }
110
+ void run(async () => {
111
+ await rpc().add({ alias: value, readOnly: readOnly() });
112
+ setAlias("");
113
+ setReadOnly(false);
114
+ }, "Could not add the Linear account.");
115
+ }
116
+
117
+ async function clearCredentials(integrationID: string) {
118
+ const { data } = await ctx.client.integration.get({ integrationID });
119
+ for (const connection of data.connections) {
120
+ if (connection.type === "credential") {
121
+ await ctx.client.credential.remove({ credentialID: connection.id });
122
+ }
123
+ }
124
+ }
125
+
126
+ async function remove(account: Account) {
127
+ const confirmed = await ctx.dialogs.confirm({
128
+ title: `Remove ${account.alias}?`,
129
+ description:
130
+ "This removes the connection and its saved sign-in from OpenCode.",
131
+ confirm: "Remove",
132
+ danger: true,
133
+ });
134
+ if (!confirmed) return;
135
+ await run(async () => {
136
+ const { data } = await ctx.client.mcp.list();
137
+ const integrationID = data.find(
138
+ (server) => server.name === account.name,
139
+ )?.integrationID;
140
+ if (integrationID) await clearCredentials(integrationID);
141
+ await rpc().remove({ name: account.name });
142
+ }, "Could not remove the Linear account.");
143
+ }
144
+
145
+ function signIn(account: Account, integrationID: string) {
146
+ ctx.dialogs.open((dialog) => (
147
+ <LinearSignIn
148
+ alias={account.alias}
149
+ integrationID={integrationID}
150
+ onDone={() => {
151
+ void refetch();
152
+ dialog.close();
153
+ }}
154
+ />
155
+ ));
156
+ }
157
+
158
+ return (
159
+ <ui.SettingsLayout
160
+ title={title}
161
+ description="Connect each Linear workspace or account separately. The alias helps you select it in a conversation."
162
+ actions={<ui.Button onClick={() => void refetch()}>Refresh</ui.Button>}
163
+ >
164
+ <ui.SettingsSection title="Add an account">
165
+ <ui.SettingsRow id="add" title="Account alias" description={aliasHint}>
166
+ <ui.TextInput
167
+ label="Account alias"
168
+ placeholder="e.g. work"
169
+ value={alias()}
170
+ onInput={setAlias}
171
+ onSubmit={add}
172
+ disabled={busy()}
173
+ />
174
+ </ui.SettingsRow>
175
+ <ui.SettingsRow
176
+ title="Read-only access"
177
+ description="Use Linear’s read-only endpoint for this connection."
178
+ >
179
+ <ui.Switch
180
+ label="Read-only access"
181
+ hideLabel
182
+ checked={readOnly()}
183
+ onChange={setReadOnly}
184
+ disabled={busy()}
185
+ />
186
+ </ui.SettingsRow>
187
+ <ui.SettingsRow
188
+ title="Save connection"
189
+ description="Choose the matching account and workspace on Linear’s consent screen."
190
+ >
191
+ <ui.Button
192
+ variant="contrast"
193
+ onClick={add}
194
+ disabled={busy() || !alias().trim()}
195
+ >
196
+ Add account
197
+ </ui.Button>
198
+ </ui.SettingsRow>
199
+ </ui.SettingsSection>
200
+
201
+ <Show when={error() || view.error}>
202
+ <p role="alert">
203
+ {error() || "Could not load Linear accounts. Refresh to try again."}
204
+ </p>
205
+ </Show>
206
+ <Show when={!view.error && view()}>
207
+ {(data) => (
208
+ <ui.SettingsSection
209
+ title="Connections"
210
+ footer="In chat, name the alias you want to use, for example: “Using Linear work, show my open issues.”"
211
+ >
212
+ <Show when={data().accounts.length === 0}>
213
+ <p>No Linear accounts added yet.</p>
214
+ </Show>
215
+ <For each={data().accounts}>
216
+ {(account) => {
217
+ const server = () => data().servers.get(account.name);
218
+ const state = () =>
219
+ server()?.status.status ??
220
+ (account.enabled ? "pending" : "disabled");
221
+ const integrationID = () => server()?.integrationID;
222
+ return (
223
+ <ui.SettingsRow
224
+ title={`${account.alias} · ${statusLabels[state()]}`}
225
+ description={`${account.readOnly ? "Read-only" : "Read-write"} · MCP: ${account.name}`}
226
+ >
227
+ <ui.Menu
228
+ label={`Manage ${account.alias}`}
229
+ disabled={busy()}
230
+ items={[
231
+ {
232
+ label: "Sign in",
233
+ disabled:
234
+ !integrationID() ||
235
+ !account.enabled ||
236
+ state() === "connected",
237
+ onSelect: () => {
238
+ const id = integrationID();
239
+ if (id) signIn(account, id);
240
+ },
241
+ },
242
+ {
243
+ label: "Sign out",
244
+ disabled: !integrationID(),
245
+ onSelect: () => {
246
+ const id = integrationID();
247
+ if (id)
248
+ void run(
249
+ () => clearCredentials(id),
250
+ "Could not sign out of Linear.",
251
+ );
252
+ },
253
+ },
254
+ {
255
+ label: account.enabled ? "Disable" : "Enable",
256
+ onSelect: () =>
257
+ void run(
258
+ () =>
259
+ rpc().enable({
260
+ name: account.name,
261
+ enabled: !account.enabled,
262
+ }),
263
+ "Could not change the account’s availability.",
264
+ ),
265
+ },
266
+ {
267
+ label: "Remove…",
268
+ onSelect: () => void remove(account),
269
+ },
270
+ ]}
271
+ />
272
+ </ui.SettingsRow>
273
+ );
274
+ }}
275
+ </For>
276
+ </ui.SettingsSection>
277
+ )}
278
+ </Show>
279
+ </ui.SettingsLayout>
280
+ );
281
+ }
282
+
283
+ export default Plugin.define({
284
+ icons: { logo },
285
+ setup(ctx) {
286
+ ctx.add(SettingsPage, {
287
+ id: settingsID,
288
+ icon: ctx.icons.logo,
289
+ title,
290
+ entries: [
291
+ {
292
+ id: "add",
293
+ title: "Add a Linear account",
294
+ keywords: "linear workspace oauth mcp",
295
+ },
296
+ ],
297
+ render: () => <LinearSettings />,
298
+ });
299
+ ctx.add(Command, {
300
+ id: "accounts",
301
+ title,
302
+ keywords: "manage linear accounts workspace oauth mcp",
303
+ run: () => ctx.layout.settings(settingsID),
304
+ });
305
+ },
306
+ });
package/src/index.ts ADDED
@@ -0,0 +1,102 @@
1
+ import { randomBytes } from "node:crypto"
2
+ import { Plugin } from "@opencode/plugin"
3
+ import { accountList, LinearAccounts, pluginID, type Account } from "./rpc.js"
4
+
5
+ const endpoint = "https://mcp.linear.app/mcp"
6
+ const storageKey = "accounts"
7
+
8
+ type AccountState = {
9
+ accounts: Account[]
10
+ queue: Promise<void>
11
+ registries: Set<() => Promise<void>>
12
+ }
13
+
14
+ // OpenCode evaluates local plugins separately at each location. Share the
15
+ // write queue and registry callbacks across those evaluations in the server.
16
+ const stateKey = Symbol.for("opencode-linear-plugin.accounts.v1")
17
+ const host = globalThis as typeof globalThis & { [stateKey]?: AccountState }
18
+ const state = host[stateKey] ??= { accounts: [], queue: Promise.resolve(), registries: new Set() }
19
+
20
+ function serialize<T>(work: () => Promise<T>): Promise<T> {
21
+ const result = state.queue.then(work)
22
+ state.queue = result.then(() => undefined, () => undefined)
23
+ return result
24
+ }
25
+
26
+ export default Plugin.define({
27
+ id: pluginID,
28
+ async setup(ctx) {
29
+ const reload = () => ctx.mcp.reload()
30
+
31
+ async function save(next: Account[]) {
32
+ await ctx.storage.set(storageKey, next)
33
+ state.accounts = next
34
+ const active = [...state.registries]
35
+ const results = await Promise.allSettled(active.map((reconcile) => reconcile()))
36
+ if (results.some((result, index) => result.status === "rejected" && state.registries.has(active[index]))) {
37
+ throw new Error("The change was saved, but OpenCode could not refresh all MCP connections. Use /reload to retry.")
38
+ }
39
+ }
40
+
41
+ return serialize(async () => {
42
+ state.accounts = accountList.parse((await ctx.storage.get(storageKey)) ?? [])
43
+
44
+ await ctx.mcp.transform((editor) => {
45
+ for (const account of state.accounts) {
46
+ editor.set(account.name, {
47
+ type: "remote",
48
+ url: account.readOnly ? `${endpoint}/readonly` : endpoint,
49
+ ...(account.readOnly ? { oauth: { scope: "read" } } : {}),
50
+ disabled: !account.enabled,
51
+ })
52
+ }
53
+ })
54
+
55
+ await ctx.session.hook("context", (event) => {
56
+ const enabled = state.accounts.filter((account) => account.enabled)
57
+ if (!enabled.length) return
58
+
59
+ event.system.push({
60
+ type: "text",
61
+ text: [
62
+ "Linear connections are independent. Configured aliases and their MCP namespaces:",
63
+ ...enabled.map(({ alias, name, readOnly }) => `- ${alias}: ${name}${readOnly ? " (read-only)" : ""}`),
64
+ "When more than one Linear connection is available and the request does not identify a workspace or account, ask which to use before calling a Linear tool. If the requested account cannot be used, report that instead of falling back to another account.",
65
+ ].join("\n"),
66
+ })
67
+ })
68
+
69
+ await ctx.rpc.register(LinearAccounts, {
70
+ list: async () => ({ accounts: state.accounts }),
71
+ add: (input, rpc) => serialize(async () => {
72
+ if (state.accounts.some((account) => account.alias === input.alias)) {
73
+ return rpc.error("conflict", `The alias "${input.alias}" already exists.`, {})
74
+ }
75
+
76
+ const account = {
77
+ ...input,
78
+ name: `linear_${input.alias}_${randomBytes(6).toString("hex")}`,
79
+ enabled: true,
80
+ }
81
+ await save([...state.accounts, account])
82
+ return account
83
+ }),
84
+ enable: (input, rpc) => serialize(async () => {
85
+ const current = state.accounts.find((account) => account.name === input.name)
86
+ if (!current) return rpc.error("conflict", "This account was removed in another window.", {})
87
+
88
+ const updated = { ...current, enabled: input.enabled }
89
+ await save(state.accounts.map((account) => account.name === updated.name ? updated : account))
90
+ return updated
91
+ }),
92
+ remove: ({ name }) => serialize(async () => {
93
+ await save(state.accounts.filter((account) => account.name !== name))
94
+ return {}
95
+ }),
96
+ })
97
+
98
+ state.registries.add(reload)
99
+ return () => { state.registries.delete(reload) }
100
+ })
101
+ },
102
+ })
package/src/linear.svg ADDED
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
2
+ <path d="M2.886 4.18A11.982 11.982 0 0 1 11.99 0C18.624 0 24 5.376 24 12.009c0 3.64-1.62 6.903-4.18 9.105L2.887 4.18ZM1.817 5.626l16.556 16.556c-.524.33-1.075.62-1.65.866L.951 7.277c.247-.575.537-1.126.866-1.65ZM.322 9.163l14.515 14.515c-.71.172-1.443.282-2.195.322L0 11.358a12 12 0 0 1 .322-2.195Zm-.17 4.862 9.823 9.824a12.02 12.02 0 0 1-9.824-9.824Z"/>
3
+ </svg>
package/src/rpc.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { Rpc } from "@opencode/plugin/rpc"
2
+ import { z } from "zod"
3
+
4
+ export const pluginID = "opencode-linear-plugin"
5
+
6
+ export const aliasPattern = /^[a-z][a-z0-9-]{1,23}$/
7
+ export const aliasHint = "Use 2–24 lowercase letters, numbers, or hyphens, starting with a letter."
8
+
9
+ const alias = z.string().regex(aliasPattern, aliasHint)
10
+ const name = z.string().regex(/^linear_[a-z][a-z0-9-]{1,23}_[a-f0-9]{12}$/)
11
+ const account = z.strictObject({
12
+ alias,
13
+ name,
14
+ readOnly: z.boolean(),
15
+ enabled: z.boolean(),
16
+ })
17
+
18
+ export type Account = z.infer<typeof account>
19
+ export const accountList = z.array(account)
20
+
21
+ const empty = z.strictObject({})
22
+ const accountName = z.strictObject({ name })
23
+ const errors = { conflict: z.strictObject({}) }
24
+
25
+ export const LinearAccounts = Rpc.define({
26
+ id: pluginID,
27
+ methods: {
28
+ list: { input: empty, output: z.strictObject({ accounts: accountList }) },
29
+ add: {
30
+ input: z.strictObject({ alias, readOnly: z.boolean() }),
31
+ output: account,
32
+ errors,
33
+ },
34
+ enable: {
35
+ input: accountName.extend({ enabled: z.boolean() }),
36
+ output: account,
37
+ errors,
38
+ },
39
+ remove: { input: accountName, output: empty },
40
+ },
41
+ events: {},
42
+ })
@@ -0,0 +1,102 @@
1
+ import { usePlugin } from "@opencode/plugin/gui"
2
+ import { createSignal, onCleanup, onMount, Show } from "solid-js"
3
+
4
+ export function LinearSignIn(props: { alias: string; integrationID: string; onDone: () => void }) {
5
+ const ctx = usePlugin()
6
+ const ui = ctx.ui
7
+ const [url, setUrl] = createSignal("")
8
+ const [paste, setPaste] = createSignal(false)
9
+ const [code, setCode] = createSignal("")
10
+ const [submitting, setSubmitting] = createSignal(false)
11
+ const [error, setError] = createSignal("")
12
+ const controller = new AbortController()
13
+ const request = { signal: controller.signal }
14
+ const integrationID = props.integrationID
15
+ let attemptID: string | undefined
16
+ let finished = false
17
+
18
+ function cancel() {
19
+ if (attemptID && !finished) {
20
+ void ctx.client.integration.oauth.cancel({ integrationID, attemptID }).catch(() => undefined)
21
+ }
22
+ }
23
+
24
+ onCleanup(() => {
25
+ controller.abort()
26
+ cancel()
27
+ })
28
+
29
+ onMount(() => void start())
30
+
31
+ async function start() {
32
+ try {
33
+ const { data } = await ctx.client.integration.get({ integrationID }, request)
34
+ const method = data.methods.find((item) => item.type === "oauth")
35
+ if (!method) throw new Error("OpenCode did not find a Linear OAuth method.")
36
+ if (controller.signal.aborted) return
37
+
38
+ const { data: attempt } = await ctx.client.integration.oauth.connect({ integrationID, methodID: method.id })
39
+ attemptID = attempt.attemptID
40
+ if (controller.signal.aborted) {
41
+ cancel()
42
+ return
43
+ }
44
+ if (new URL(attempt.url).origin !== "https://mcp.linear.app") {
45
+ cancel()
46
+ throw new Error("Unexpected Linear sign-in address.")
47
+ }
48
+
49
+ setPaste(attempt.paste === true || attempt.mode === "code")
50
+ setUrl(attempt.url)
51
+ while (!controller.signal.aborted) {
52
+ const { data: status } = await ctx.client.integration.oauth.status({ integrationID, attemptID }, request)
53
+ if (status.status === "complete") {
54
+ finished = true
55
+ props.onDone()
56
+ return
57
+ }
58
+ if (status.status !== "pending") {
59
+ finished = true
60
+ setUrl("")
61
+ setPaste(false)
62
+ setError(`Linear sign-in ${status.status}. Close this dialog and try again.`)
63
+ return
64
+ }
65
+ await new Promise<void>((resolve) => setTimeout(resolve, 1000))
66
+ }
67
+ } catch {
68
+ if (!controller.signal.aborted) setError("Could not start or check Linear sign-in. Close this dialog and try again.")
69
+ }
70
+ }
71
+
72
+ async function submit() {
73
+ if (!attemptID || submitting() || !code().trim()) return
74
+ setSubmitting(true)
75
+ setError("")
76
+ try {
77
+ await ctx.client.integration.oauth.complete({ integrationID, attemptID, code: code().trim() }, request)
78
+ setCode("")
79
+ } catch {
80
+ if (!controller.signal.aborted) setError("Could not complete sign-in. Check the callback URL or code and try again.")
81
+ } finally {
82
+ setSubmitting(false)
83
+ }
84
+ }
85
+
86
+ return (
87
+ <ui.Dialog
88
+ title={`Sign in to Linear: ${props.alias}`}
89
+ description="Open Linear in your browser, then verify the account and workspace on the consent screen."
90
+ >
91
+ <Show when={url()} fallback={<Show when={!error()}><p role="status">Preparing sign-in…</p></Show>}>
92
+ {(address) => <ui.Button variant="contrast" onClick={() => ctx.system.openExternal(address())}>Open Linear in browser</ui.Button>}
93
+ </Show>
94
+ <Show when={paste()}>
95
+ <p>If the callback page doesn’t load after you authorize, paste its full URL here.</p>
96
+ <ui.TextInput label="Callback URL or code" value={code()} onInput={setCode} onSubmit={() => void submit()} />
97
+ <ui.Button onClick={() => void submit()} disabled={!code().trim()} busy={submitting()}>Complete sign-in</ui.Button>
98
+ </Show>
99
+ <Show when={error()}><p role="alert">{error()}</p></Show>
100
+ </ui.Dialog>
101
+ )
102
+ }