@morozinc/opencode-clockify-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 +21 -0
- package/README.md +58 -2
- package/dist/gui-experimental.cjs +60 -0
- package/docs/screenshots/add-account.png +0 -0
- package/package.json +44 -4
- package/src/clockify.svg +3 -0
- package/src/clockify.ts +29 -0
- package/src/gui.tsx +403 -0
- package/src/index.ts +188 -0
- package/src/rpc.ts +39 -0
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,59 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OpenCode Clockify Plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use Clockify reports and timers from OpenCode Desktop. Each account has its
|
|
4
|
+
own alias, API key, region, and tool namespace. The plugin connects to
|
|
5
|
+
[Clockify’s official hosted MCP server](https://clockify.me/help/integrations-and-add-ons/use-clockify-mcp-server-to-connect-to-ai-agent)
|
|
6
|
+
at `https://api.clockify.me/mcp-server/mcp`.
|
|
7
|
+
|
|
8
|
+
## Install from npm
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
opencode plugin add @morozinc/opencode-clockify-plugin@0.1.0
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Build from source
|
|
15
|
+
|
|
16
|
+
Requires OpenCode Desktop V2 and Node.js 20.19+ or 22.12+. The plugin was
|
|
17
|
+
built against OpenCode 2.4.3 and uses its experimental Desktop plugin API.
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
cd opencode-clockify-plugin
|
|
21
|
+
npm ci
|
|
22
|
+
npm run build
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Append this directory’s absolute path to `plugins` in your global OpenCode
|
|
26
|
+
config (`~/.config/opencode/opencode.json(c)` or its XDG equivalent):
|
|
27
|
+
|
|
28
|
+
```jsonc
|
|
29
|
+
{
|
|
30
|
+
"$schema": "https://opencode.ai/config.json",
|
|
31
|
+
"plugins": ["/absolute/path/to/opencode-clockify-plugin"],
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
1. Select OpenCode Desktop’s own server. Open **Settings > Clockify** or choose
|
|
38
|
+
**Clockify** from the command palette.
|
|
39
|
+
2. Enter an alias and pick the account’s Clockify data region. Get the API key
|
|
40
|
+
from **Clockify > Preferences > Advanced > Manage API keys**. The plugin
|
|
41
|
+
checks the key against the regional profile API before saving it.
|
|
42
|
+
3. Use the alias in chat: “Using Clockify work, summarize my time last week.”
|
|
43
|
+
|
|
44
|
+

|
|
45
|
+
|
|
46
|
+
OpenCode keeps the API key in its credential store. **Disable** hides the tools
|
|
47
|
+
and keeps the key. **Sign out** clears the key. **Remove** also deletes the alias.
|
|
48
|
+
You can revoke keys in Clockify.
|
|
49
|
+
|
|
50
|
+
The plugin asks for approval before write tools run. If a timer or other write
|
|
51
|
+
times out, check Clockify before retrying.
|
|
52
|
+
|
|
53
|
+
## License and credits
|
|
54
|
+
|
|
55
|
+
[MIT License](LICENSE). Developed by [Moroz Inc.](https://moroz.cc).
|
|
56
|
+
|
|
57
|
+
Logo from [Simple Icons](https://simpleicons.org/).
|
|
58
|
+
|
|
59
|
+
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 z=require("solid-js/web"),se=require("@opencode/plugin/gui"),j=require("solid-js"),Mn=require("@opencode/plugin/rpc");function De(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 at(e,t="|"){return e.map(n=>Wt(n)).join(t)}function Ne(e,t){return typeof t=="bigint"?t.toString():t}class Jn{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 We(e){return new Jn(e)}function Bn(e){return e==null}function qe(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 Mt(e){const t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function F(e){return Mt(e._zod.def)??e._zod.def.shape}function Jt(e,t,n){Object.defineProperty(e,t,{get(){const r=n();return X(this,t,r),r},enumerable:!0,configurable:!0})}function Bt(e,t,n){t in e?X(e,t,n):e[t]=n}function G(e,t,n,r){const o=F(t);for(const i of n){const s=Object.getOwnPropertyDescriptor(o,i);s.enumerable&&(s.get?Jt(e,i,()=>{const c=t._zod.def.shape[i];return r?r(c,i):c}):Bt(e,i,r?r(s.value,i):s.value))}}function Kn(e,t){for(const n of Reflect.ownKeys(t)){const r=Object.getOwnPropertyDescriptor(t,n);r.enumerable&&(r.get?Jt(e,n,()=>t[n]):Bt(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 Vn(e){return JSON.stringify(e)}function Wn(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const Kt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function we(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const qn=We(()=>{if(D.jitless||typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function fe(e){if(we(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(we(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Vt(e){return fe(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const Gn=new Set(["string","number","symbol"]);function Se(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function B(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function y(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 Wt(e){return typeof e=="bigint"?e.toString()+"n":typeof e=="string"?`"${e}"`:`${e}`}function Xn(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}const Hn={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]},Yn={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function Qn(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,Ze(e,t)),B(e,T(n,{shape:i,checks:[]}))}function Ze(e,t){const n=F(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 er(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(Ze(e,t)),s={};return G(s,e,Reflect.ownKeys(F(e)).filter(c=>!i.has(c))),B(e,T(n,{shape:s,checks:[]}))}function tr(e,t){if(!fe(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=F(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 B(e,T(e._zod.def,{shape:qt(e,t)}))}function qt(e,t){const n={};return G(n,e,Reflect.ownKeys(F(e))),Kn(n,t),n}function nr(e,t){if(!fe(t))throw new Error("Invalid input to safeExtend: expected a plain object");return B(e,T(e._zod.def,{shape:qt(e,t)}))}function rr(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(F(e))),G(n,t,Reflect.ownKeys(F(t)));const r=T(e._zod.def,{shape:n,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return B(e,r)}function ut(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(Ze(t,n)):void 0,a={};return G(a,t,Reflect.ownKeys(F(t)),e&&((u,f)=>c&&!c.has(f)?u:new e({type:"optional",innerType:u}))),B(t,T(t._zod.def,{shape:a,checks:[]}))}function or(e,t,n){const r=n?new Set(Ze(t,n)):void 0,o={};return G(o,t,Reflect.ownKeys(F(t)),(i,s)=>r&&!r.has(s)?i:new e({type:"nonoptional",innerType:i})),B(t,T(t._zod.def,{shape:o}))}function U(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 ir(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 Gt(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function re(e){return typeof e=="string"?e:e?.message}function ft(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 Ue(e,t,n){var r;for(let o=t;o<e.length;o++)(r=e[o]).schema??(r.schema=n)}function te(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:re(e.inst?._zod.def?.error?.(e))??re(i?.(e))??re(t?.error?.(e))??re(n.customError?.(e))??re(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 sr=/[\uD800-\uDBFF]/;function Ge(e){const t=e.length;if(!sr.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 Xe(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function cr(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 le(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}function ar(e,t){for(const n in t){const r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):fr(e,n,r.value)}}function J(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function Xt(e,t,n){return J(e,t,n,!1)}function ur(e,t){for(const n in e){const r=e[n];Object.defineProperty(t,n,{configurable:!0,enumerable:!0,get(){return J(this,n,r(this))},set(o){J(this,n,o)}})}return t}function fr(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:J(this,t,n.bind(this))},set(r){J(this,t,r)}})}function lr(e,t){const n=Object.getPrototypeOf(e);return t in n?void 0:n}let Ae,M=!1;const dr={configurable:!0,get(){M=!0}};function w(e,t,n){const r=Object.getPrototypeOf(e._zod);if(t in r&&Ae!==e._zod){Ae=void 0;return}Ae=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,dr);const o=M;M=!1;try{const i=n(this);return M?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:i}),M=M||o,i}catch(i){throw delete this[t],M=M||o,i}},set(o){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:o})}})}function pr(e,t,n,r){const o=lr(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 hr="~constantCatch";function mr(e){const t=()=>e;return t[hr]=!0,t}var lt;const Ce={value:void 0,enumerable:!1};let dt="captureStackTrace"in Error?Error:null;function gr(e){const t=dt;if(t){const n=t.stackTraceLimit;if(typeof n=="number"){try{t.stackTraceLimit=0}catch{return dt=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{Ce.value=new i(h);try{Object.defineProperty(p,"_zod",Ce)}finally{Ce.value=void 0}}if(p._zod.traits.add(e),t(p,h),c){const g=Object.getPrototypeOf(p),v=p._zod.constr.prototype;let k=g;for(;k&&k!==v;)k=Object.getPrototypeOf(k);const I=k??g;c.has(I)||(c.add(I),ar(I,s))}const m=d.prototype;for(const g in m)Object.prototype.hasOwnProperty.call(m,g)&&(g in p||(p[g]=m[g].bind(p)))}const u=r?.Parent??Object;class f extends u{}Object.defineProperty(f,"name",{value:e});function d(p){const h=r?.Parent?gr(f):this;a(h,p);const m=h._zod.deferred;if(m){for(const v of m)v();h._zod.deferred=void 0}const g=globalThis.__zod_globalConfig?.postProcessor;return g&&g(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 Ht extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}(lt=globalThis).__zod_globalConfig??(lt.__zod_globalConfig={});const D=globalThis.__zod_globalConfig;function K(e){return e&&Object.assign(D,e),D}function _r(){const e=this._zod;return e.message??(e.message=JSON.stringify(e.def,Ne,2)),e.message}function yr(e){this._zod.message=e}const vr={get:_r,set:yr,enumerable:!0,configurable:!0},je={value:void 0,enumerable:!1},pt=new WeakSet([Object.prototype,Error.prototype]),br=(e,t)=>{e.name="$ZodError",je.value=t,Object.defineProperty(e,"issues",je),je.value=void 0,Object.defineProperty(e,"message",vr);const n=Object.getPrototypeOf(e);pt.has(n)||(pt.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})}}))},wr=l("$ZodError",br);function zr(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 kr(e,t=n=>n.message){const n={},r=[];for(const o of e.issues)o.path.length>0?zr(n,o.path[0],()=>[]).push(t(o)):r.push(t(o));return{formErrors:r,fieldErrors:n}}function $r(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 Pe(e,t){return{callee:t?.callee??e,Err:t?.Err}}const He=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=>te(u,s,K())));throw Kt(a,i?.callee??t),a}return c.value};return t},Ye=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=>te(u,s,K())));throw Kt(a,i?.callee??t),a}return c.value};return t},Qe=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?Yt(e,i.issues,o):{success:!0,data:i.value}};function Yt(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(o=>te(o,n,K()))),t=void 0,n=void 0),r},set error(o){r=o,t=void 0,n=void 0}}}const et=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?Yt(e,i.issues,o):{success:!0,data:i.value}},Or=Symbol.for("zod.compile.invalid"),Sr=Symbol.for("zod.compile.fallback"),Zr=((e,t,n)=>{const r=e._zod.bag.validator;if(r!==void 0){if(r(t)!==Or)return!0;if(r.definite===!0&&n===void 0)return!1}return Pr(e,t,n)});function Pr(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[Sr]=!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 Er=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},Ir=e=>{const t=He(e),n=(r,o,i,s)=>{const c=i?{...i,direction:"backward"}:{direction:"backward"};return t(r,o,c,Pe(n,s))};return n},Ar=e=>{const t=He(e),n=(r,o,i,s)=>t(r,o,i,Pe(n,s));return n},Cr=e=>{const t=Ye(e),n=async(r,o,i,s)=>{const c=i?{...i,direction:"backward"}:{direction:"backward"};return await t(r,o,c,Pe(n,s))};return n},jr=e=>{const t=Ye(e),n=async(r,o,i,s)=>await t(r,o,i,Pe(n,s));return n},Tr=e=>(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return Qe(e)(t,n,o)},Rr=e=>(t,n,r)=>Qe(e)(t,n,r),Dr=e=>async(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return et(e)(t,n,o)},Nr=e=>async(t,n,r)=>et(e)(t,n,r),Ur=/^[cC][0-9a-z]{6,}$/,Fr=/^[0-9a-z]+$/,xr=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,Lr=/^[0-9a-vA-V]{20}$/,Mr=/^[A-Za-z0-9]{27}$/,Jr=/^[a-zA-Z0-9_-]{21}$/;function Br(e){return new RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}const Kr=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Vr=/^([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})$/,ht=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)$/,Wr=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,qr="^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$";function Gr(){return new RegExp(qr,"u")}const Xr=/^(?:(?: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])$/,Hr=/^(([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}|:))$/,Yr=/^((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])$/,Qr=/^(([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])$/,eo=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,to=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/,no=/^https?$/,ro=/^\+[1-9]\d{6,14}$/,Qt="(?:(?:\\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 oo(e){return new RegExp(`^${e}$`)}const io=oo(Qt);function Fe(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 so(e){return new RegExp(`^${Fe(e)}$`)}function co(e){const t=["Z"];e.offset&&t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const n=`${Fe({precision:e.precision,seconds:!0})}(?:${t.join("|")})`,r=e.local?`${n}|${Fe({precision:e.precision})}`:n;return new RegExp(`^${Qt}T(?:${r})$`)}const ao=/^[\s\S]{0,}$/,uo=/^(?:true|false)$/i,fo=/^[^A-Z]*$/,lo=/^[^a-z]*$/,N=l("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),tt=e=>{const t=e.value;return!Bn(t)&&t.length!==void 0},po=l("$ZodCheckMaxLength",(e,t)=>{var n;N.init(e,t),(n=e._zod.def).when??(n.when=tt),e._zod.check=r=>{const o=r.value,i=o.length;if((typeof o=="string"&&i>t.maximum?Ge(o):i)<=t.maximum)return;const c=Xe(o);r.issues.push({origin:c,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),ho=l("$ZodCheckMinLength",(e,t)=>{var n;N.init(e,t),(n=e._zod.def).when??(n.when=tt),e._zod.check=r=>{const o=r.value,i=o.length;if((typeof o=="string"&&i>=t.minimum&&i<t.minimum*2?Ge(o):i)>=t.minimum)return;const c=Xe(o);r.issues.push({origin:c,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),mo=l("$ZodCheckLengthEquals",(e,t)=>{var n;N.init(e,t),(n=e._zod.def).when??(n.when=tt),e._zod.check=r=>{const o=r.value,i=o.length,s=typeof o=="string"&&i>=t.length&&i<=t.length*2?Ge(o):i;if(s===t.length)return;const c=Xe(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})}}),Ee=l("$ZodCheckStringFormat",(e,t)=>{var n,r;N.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=()=>{})}),go=l("$ZodCheckRegex",(e,t)=>{Ee.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})}}),_o=l("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=fo),Ee.init(e,t)}),yo=l("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=lo),Ee.init(e,t)}),vo=l("$ZodCheckIncludes",(e,t)=>{N.init(e,t);const n=Se(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})}}),bo=l("$ZodCheckStartsWith",(e,t)=>{N.init(e,t);const n=new RegExp(`^${Se(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})}}),wo=l("$ZodCheckEndsWith",(e,t)=>{N.init(e,t);const n=new RegExp(`.*${Se(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})}}),zo=l("$ZodCheckOverwrite",(e,t)=>{N.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class ko{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 $o={major:4,minor:6,patch:7},Z=l("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=$o;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=U(c),d;for(const p of a){if(p._zod.def.when){if(ir(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&&(Ue(c.issues,h,e),f||(f=U(c,h)))});else{if(c.issues.length===h)continue;Ue(c.issues,h,e),f||(f=U(c,h))}}return d?d.then(()=>c):c},s=(c,a,u)=>{if(U(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 Xt(this,"~standard",tn(this))},set"~standard"(e){J(this,"~standard",e)}}),en=(e,t)=>e.issues.length?{issues:e.issues.map(n=>te(n,t,K()))}:{value:e.value};async function Oo(e,t){const n={async:!0};return en(await e._zod.run({value:t,issues:[]},n),n)}function tn(e){return{validate:t=>{const n={async:!1};try{const r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return en(r,n)}catch{}return Oo(e,t)},vendor:"zod",version:1}}const nt=l("$ZodString",(e,t)=>{Z.init(e,t),e._zod.pattern=t.pattern??ao,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}}),$=l("$ZodStringFormat",(e,t)=>{Ee.init(e,t),nt.init(e,t)}),So=l("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Vr),$.init(e,t)}),Zo=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=ht(r))}else t.pattern??(t.pattern=ht());$.init(e,t)}),Po=l("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Wr),$.init(e,t)}),nn=1,ze=2;function rn(e){try{return typeof URL<"u"&&typeof URL.canParse=="function"?URL.canParse(e):(new URL(e),!0)}catch{return!1}}function Eo(e,t){return!("normalize"in t)&&!("hostname"in t)&&!("protocol"in t)?rn(e)||ze:Io(e,t)}function Io(e,t){if(!t.normalize&&t.protocol?.source===no.source&&!/^https?:\/\//i.test(e))return nn;try{if(typeof URL<"u"){const n=URL;if(typeof n.parse=="function")return n.parse(e)??ze}return new URL(e)}catch{return ze}}const Ao=/[\t\n\r]/g;function mt(e){return e.replace(Ao,"")}function Co(e,t){return t.lastIndex=0,t.test(e.hostname)}function jo(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(":")?e.protocol.slice(0,-1):e.protocol)}const To=l("$ZodURL",(e,t)=>{$.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),o=Eo(r,t);if(o===nn){n.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:n.value,inst:e,continue:!t.abort});return}if(o===ze){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort});return}if(o===!0){n.value=mt(r);return}t.hostname&&!Co(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&&!jo(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:mt(r);return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Ro=l("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Gr()),$.init(e,t)}),Do=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?Jr:Br(t.length)),$.init(e,t)}),No=l("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Ur),$.init(e,t)}),Uo=l("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Fr),$.init(e,t)}),Fo=l("$ZodULID",(e,t)=>{t.pattern??(t.pattern=xr),$.init(e,t)}),xo=l("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Lr),$.init(e,t)}),Lo=l("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Mr),$.init(e,t)}),Mo=l("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=co(t)),$.init(e,t)}),Jo=l("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=io),$.init(e,t)}),Bo=l("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=so(t)),$.init(e,t)}),Ko=l("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Kr),$.init(e,t)}),Vo=l("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Xr),$.init(e,t)}),Wo=/^[0-9a-fA-F:.]+$/;function on(e){return Wo.test(e)?rn(`http://[${e}]`):!1}const qo=l("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Hr),$.init(e,t),e._zod.check=n=>{on(n.value)||n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}),Go=l("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Yr),$.init(e,t)});function Xo(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:on(n)}const Ho=l("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Qr),$.init(e,t),e._zod.check=n=>{Xo(n.value)||n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}});function sn(e){if(e==="")return!0;if(/\s/.test(e)||e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const cn=/^[0-9a-zA-Z+/]*={0,2}$/,Yo=l("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=cn),$.init(e,t),e._zod.check=n=>{sn(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}}),rt=/^[A-Za-z0-9_-]*$/;function Qo(e){if(!rt.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return sn(n)}const ei=l("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=rt),$.init(e,t),e._zod.check=n=>{Qo(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),ti=l("$ZodE164",(e,t)=>{t.pattern??(t.pattern=ro),$.init(e,t)});function ni(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 ri=l("$ZodJWT",(e,t)=>{$.init(e,t),e._zod.check=n=>{ni(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),oi=l("$ZodBoolean",(e,t)=>{Z.init(e,t),e._zod.pattern=uo,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}}),ii=l("$ZodUnknown",(e,t)=>{Z.init(e,t),e._zod.parse=n=>n}),si=l("$ZodNever",(e,t)=>{Z.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function ci(e,t){const n=ft(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 ft(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,Ue(i.issues,f,e),i}}return o(i,s)}}const ai=e=>Array.isArray(e)?e.length:-1;function gt(e,t,n){e.issues.length&&t.issues.push(...Gt(n,e.issues)),t.value[n]=e.value}const ui=l("$ZodArray",(e,t)=>{Z.init(e,t);const n=D.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=>gt(d,r,a)));else if(gt(f,r,a),c&&f.issues.length!==0&&U(f))break}return s.length?Promise.all(s).then(()=>r):r},ci(e,ai)});function ke(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(...Gt(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 fi=[];function an(e){const t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:fi,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=Xn(e.shape);return{...e,allKeys:o,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(i)}}function un(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(U(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 g=u.run({value:t[m],issues:[]},r);g instanceof Promise?e.push(g.then(v=>ke(v,n,m,t,d,p))):ke(g,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 li=l("$ZodObject",(e,t)=>{Z.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=We(()=>an(t));w(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=we,s=t.catchall;let c;const a=D.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 g=u.issues.length;for(const v of c.allKeys){if(m&&u.issues.length!==g){if(U(u,g))break;g=u.issues.length}if(v==="__proto__")continue;const k=h[v],I=k._zod.optin,x=k._zod.optout,L=k._zod.run({value:d[v],issues:[]},f);L instanceof Promise?p.push(L.then(S=>ke(S,u,v,d,I,x))):ke(L,u,v,d,I,x)}return s?un(p,d,u,f,o.value,e,m===!0):p.length?Promise.all(p).then(()=>u):u}}),di=l("$ZodObjectJIT",(e,t)=>{li.init(e,t);const n=e._zod.parse,r=We(()=>an(t)),o=D.memoizer,i=h=>{const m=r.value,g=m.symbolKeys,v=new ko(["payload","ctx"],{shape:h,inst:e,memo:o,syms:g}),k=S=>`shape[${S}]._zod.run({ value: input[${S}], issues: [] }, ctx)`,I=(S,_)=>`
|
|
6
|
+
let ${S}_ab = false;
|
|
7
|
+
for (let i = 0; i < ${S}.issues.length; i++) {
|
|
8
|
+
const iss = ${S}.issues[i];
|
|
9
|
+
iss.path = iss.path ? [${_}, ...iss.path] : [${_}];
|
|
10
|
+
payload.issues.push(iss);
|
|
11
|
+
if (iss.continue !== true) ${S}_ab = true;
|
|
12
|
+
}
|
|
13
|
+
if (${S}_ab && ctx && ctx.abortEarly) {
|
|
14
|
+
payload.value = newResult;
|
|
15
|
+
return payload;
|
|
16
|
+
}`;v.write("const input = payload.value;");const x=Object.create(null);let L=0;for(const S of m.allKeys)x[S]=`key_${L++}`;v.write(o?"const newResult = memo.alloc(inst, payload, {}, ctx);":"const newResult = {};");for(const S of m.allKeys){if(S==="__proto__")continue;const _=x[S],b=typeof S=="symbol"?`syms[${g.indexOf(S)}]`:Vn(S),A=`${b} in input`,V=h[S],Ie=V?._zod?.optin,ct=Ie!==void 0,xn=V?._zod?.optout==="optional";if(v.write(`const ${_} = ${k(b)};`),ct&&xn){const Ln=Ie==="optional"?`${_}_present`:`${_}.value !== undefined || ${_}_present`;v.write(`
|
|
17
|
+
const ${_}_present = ${A};
|
|
18
|
+
if (!${_}.issues.length || ${_}_present) {
|
|
19
|
+
if (${_}.issues.length) {${I(_,b)}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (${Ln}) {
|
|
23
|
+
newResult[${b}] = ${_}.value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
`)}else ct?(v.write(`
|
|
28
|
+
if (${_}.issues.length) {${I(_,b)}
|
|
29
|
+
}
|
|
30
|
+
`),Ie==="defaulted"?v.write(`newResult[${b}] = ${_}.value;`):v.write(`
|
|
31
|
+
if (${_}.value !== undefined || ${A}) {
|
|
32
|
+
newResult[${b}] = ${_}.value;
|
|
33
|
+
}
|
|
34
|
+
`)):v.write(`
|
|
35
|
+
const ${_}_present = ${A};
|
|
36
|
+
if (${_}.issues.length) {${I(_,b)}
|
|
37
|
+
}
|
|
38
|
+
if (!${_}_present && !${_}.issues.length) {
|
|
39
|
+
payload.issues.push({
|
|
40
|
+
code: "invalid_type",
|
|
41
|
+
expected: "nonoptional",
|
|
42
|
+
input: undefined,
|
|
43
|
+
path: [${b}]
|
|
44
|
+
});
|
|
45
|
+
if (ctx && ctx.abortEarly) {
|
|
46
|
+
payload.value = newResult;
|
|
47
|
+
return payload;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (${_}_present) {
|
|
52
|
+
newResult[${b}] = ${_}.value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
`)}return v.write("payload.value = newResult;"),v.write("return payload;"),v.compile()};let s;const c=we,a=!D.jitless,f=a&&qn.value,d=t.catchall;let p;e._zod.parse=(h,m)=>{p??(p=r.value);const g=h.value;return c(g)?a&&f&&m?.async===!1&&m.jitless!==!0?(s||(s=i(t.shape)),h=s(h,m),d?un([],g,h,m,p,e,m?.abortEarly===!0):h):n(h,m):(h.issues.push({expected:"object",code:"invalid_type",input:g,inst:e}),h)}});function _t(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=>!U(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=>te(s,r,K())))}),t)}const pi=l("$ZodUnion",(e,t)=>{Z.init(e,t),w(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),w(e,"optout",r=>r.def.options.some(o=>o._zod.optout==="optional")?"optional":void 0),w(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)))}),w(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=>qe(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=>_t(c,r,e,o)):_t(s,r,e,o)}}),hi=l("$ZodIntersection",(e,t)=>{Z.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])=>yt(n,a,u)):yt(n,i,s)}});function xe(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(fe(e)&&fe(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=xe(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=xe(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 yt(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=xe(t.value,n.value);if(!a.valid){if(U(e))return e;throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`)}return e.value=a.data,e}const mi=l("$ZodEnum",(e,t)=>{Z.init(e,t);const n=De(t.entries),r=new Set(n);e._zod.values=r,w(e,"pattern",o=>{const i=De(o.def.entries).filter(s=>Gn.has(typeof s));return new RegExp(i.length?`^(${i.map(s=>Se(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}}),gi=l("$ZodTransform",(e,t)=>{Z.init(e,t),e._zod.optin="optional",D.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Ht(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 vt(e,t){return e.value=t.issues.length?void 0:t.value,e}const fn=l("$ZodOptional",(e,t)=>{Z.init(e,t),w(e,"optin",n=>n.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),e._zod.optout="optional",w(e,"values",n=>{const r=n.def.innerType._zod.values;return r?new Set([...r,void 0]):void 0}),w(e,"pattern",n=>{const r=n.def.innerType._zod.pattern;return r?new RegExp(`^(${qe(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=>vt(n,i)):vt(n,o)}return t.innerType._zod.run(n,r)}}),_i=l("$ZodExactOptional",(e,t)=>{fn.init(e,t),w(e,"values",n=>n.def.innerType._zod.values),w(e,"pattern",n=>n.def.innerType._zod.pattern),e._zod.parse=(n,r)=>t.innerType._zod.run(n,r)}),yi=l("$ZodNullable",(e,t)=>{Z.init(e,t),w(e,"optin",n=>n.def.innerType._zod.optin),w(e,"optout",n=>n.def.innerType._zod.optout),w(e,"pattern",n=>{const r=n.def.innerType._zod.pattern;return r?new RegExp(`^(${qe(r.source)}|null)$`):void 0}),w(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)}),vi=l("$ZodDefault",(e,t)=>{Z.init(e,t),e._zod.optin="defaulted",w(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=>bt(i,t)):bt(o,t)}});function bt(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const bi=l("$ZodPrefault",(e,t)=>{Z.init(e,t),e._zod.optin="defaulted",w(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))}),wi=l("$ZodNonOptional",(e,t)=>{Z.init(e,t),w(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=>wt(i,e)):wt(o,e)}});function wt(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 zt(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(o=>te(o,r,K()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}const zi=l("$ZodCatch",(e,t)=>{Z.init(e,t),w(e,"optin",n=>n.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),w(e,"optout",n=>n.def.innerType._zod.optout),w(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=>zt(n,i,t,r)):zt(n,o,t,r)}}),ki=l("$ZodPipe",(e,t)=>{Z.init(e,t),w(e,"values",n=>n.def.in._zod.values),w(e,"optin",n=>n.def.in._zod.optin),w(e,"optout",n=>n.def.out._zod.optout),w(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=>pe(s,t.in,r)):pe(i,t.in,r)}const o=t.in._zod.run(n,r);return o instanceof Promise?o.then(i=>pe(i,t.out,r)):pe(o,t.out,r)}});function pe(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 $i=l("$ZodReadonly",(e,t)=>{Z.init(e,t),w(e,"propValues",n=>n.def.innerType._zod.propValues),w(e,"values",n=>n.def.innerType._zod.values),w(e,"optin",n=>n.def.innerType?._zod?.optin),w(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(kt):kt(o)}});function kt(e){return e.memo||(e.value=Object.freeze(e.value)),e}const Oi=l("$ZodCustom",(e,t)=>{N.init(e,t),Z.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=>$t(i,n,r,e));$t(o,n,r,e)}});function $t(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(le(o))}}class Si extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}const Le="~memo",Ot=[];function ln(e){return e!==null&&typeof e=="object"}function Te(e){return e.map(t=>t.path?{...t,path:t.path.slice()}:{...t})}const dn=new WeakMap,oe=0,ve=1,ce=2;function be(e,t,n){const r=dn.get(e);if(r!==void 0)return r?ce:oe;if(t.has(e))return ce;t.add(e);let o=oe;const i=f=>{if(o!==ce&&f?._zod){const d=be(f,t);d>o&&(o=d)}},s=(f,d)=>{let p=oe;for(const h of Reflect.ownKeys(f)){const m=Object.getOwnPropertyDescriptor(f,h);if(!m.enumerable)continue;const g=m.get?ve:m.value?._zod?be(m.value,t):oe;g>p&&(p=g)}return p},c=f=>{f>o&&(o=f)},a=e._zod.def;switch(a.type){case"object":{const f=Mt(a);c(f?s(f):ve),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?be(f,t):ve);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),Zi(e,o)}function Zi(e,t){return t!==ve&&dn.set(e,t===ce),t}function Pi(e,t){let n=e.buckets.get(t);return n||(n=new WeakMap,e.buckets.set(t,n)),n}let he;const me=[],Ei={alloc(e,t,n){const r=he;if(!r)return n;he=void 0;const o={value:n,issues:null};return r.set(t.value,o),me.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"&&Ai(i,o.value))throw new Si;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 k=be(e,new Set);if(k===oe)return e._zod.parse=s,e._zod.run===c&&(e._zod.run=s),s(a,u);k===ce||r?n=!0:r=!0}const f=a.value;if(!ln(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=Pi(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(...Te(h.issues)):(a.memo=!0,d.backEdges??(d.backEdges=new WeakSet),d.backEdges.add(h.value)),a;he=p;const m=me.length,g=s(a,u);he=void 0;const v=me.length>m?me.pop():void 0;return g instanceof Promise?g.then(k=>(v&&(v.issues=k.issues.length?Te(k.issues):Ot),k)):(v&&(v.issues=g.issues.length?Te(g.issues):Ot),g)};e._zod.parse=c,e._zod.run===s&&(e._zod.run=c)})}};function Ii(){return Ei}function Ai(e,t){const n=e[Le]?.backEdges;return n!==void 0&&ln(t)&&n.has(t)}const Ci=()=>{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=cr(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 ${Wt(i.values[0])}`:`Invalid option: expected one of ${at(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":""}: ${at(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 ji(){return{localeError:Ci()}}var St;class Ti{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 Ri(){return new Ti}(St=globalThis).__zod_globalRegistry??(St.__zod_globalRegistry=Ri());const ie=globalThis.__zod_globalRegistry;function Di(e){return e.checks&&(e.checks=[...e.checks]),e}function Ni(e,t){return new e(Di({type:"string",...y(t)}))}function Ui(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...y(t)})}function Fi(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...y(t)})}function xi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...y(t)})}function Li(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...y(t)})}function Mi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...y(t)})}function Ji(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...y(t)})}function Bi(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...y(t)})}function Ki(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...y(t)})}function Vi(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...y(t)})}function Wi(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...y(t)})}function qi(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...y(t)})}function Gi(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...y(t)})}function Xi(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...y(t)})}function Hi(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...y(t)})}function Yi(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...y(t)})}function Qi(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...y(t)})}function es(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...y(t)})}function ts(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...y(t)})}function ns(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...y(t)})}function rs(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...y(t)})}function os(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...y(t)})}function is(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...y(t)})}function ss(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...y(t)})}function cs(e,t){return new e({type:"string",format:"date",check:"string_format",...y(t)})}function as(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...y(t)})}function us(e,t){return new e({type:"string",format:"duration",check:"string_format",...y(t)})}function fs(e,t){return new e({type:"boolean",...y(t)})}function ls(e){return new e({type:"unknown"})}function ds(e,t){return new e({type:"never",...y(t)})}function pn(e,t){return new po({check:"max_length",...y(t),maximum:e})}function $e(e,t){return new ho({check:"min_length",...y(t),minimum:e})}function hn(e,t){return new mo({check:"length_equals",...y(t),length:e})}function ps(e,t){return new go({check:"string_format",format:"regex",...y(t),pattern:e})}function hs(e){return new _o({check:"string_format",format:"lowercase",...y(e)})}function ms(e){return new yo({check:"string_format",format:"uppercase",...y(e)})}function gs(e,t){return new vo({check:"string_format",format:"includes",...y(t),includes:e})}function _s(e,t){return new bo({check:"string_format",format:"starts_with",...y(t),prefix:e})}function ys(e,t){return new wo({check:"string_format",format:"ends_with",...y(t),suffix:e})}function ne(e){return new zo({check:"overwrite",tx:e})}function vs(e){return ne(t=>t.normalize(e))}function bs(){return ne(e=>e.trim())}function ws(){return ne(e=>e.toLowerCase())}function zs(){return ne(e=>e.toUpperCase())}function ks(){return ne(e=>Wn(e))}function $s(e,t,n){return new e({type:"array",element:t,...y(n)})}function Os(e,t,n){return new e({type:"custom",check:"custom",fn:t,...y(n)})}function Ss(e,t){const n=Zs(r=>(r.addIssue=o=>{if(typeof o=="string")r.issues.push(le(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(le(i))}},e(r.value,r)),t);return n}function Zs(e,t){const n=new N({check:"custom",...y(t)});return n._zod.check=e,n}function ae(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 mn(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??ie,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 de(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 E(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),E(d,t,f),t.seen.get(d).isParent=!0)}const a=t.metadataRegistry.get(e);return a&&ae(s.schema,a),t.io==="input"&&C(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 Zt(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function gn(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}/${Zt(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+Zt(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 _n(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;_n(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 yn=new Set(["type","properties","required","additionalProperties"]),Pt=["oneOf","anyOf"];function Et(e){const t=e.additionalProperties;return t===void 0||t===!1||typeof t!="object"||t===null?null:Object.keys(t).length?t:null}function Me(e){const t=[];for(const i of e){if(typeof i!="object"||i.type!=="object")return null;for(const s in i)if(!yn.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]??Et(u);f!=null&&(c.some(d=>JSON.stringify(d)===JSON.stringify(f))||c.push(f))}const a=c.length===1?c[0]:Me(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=Et(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 Ps(e){const t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(const o of yn)if(o in e)return;const n=t.filter(o=>Pt.some(i=>Array.isArray(o[i])));let r=null;if(!n.length)r=Me(t);else{const o=n[0],i=Pt.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=>Me([...s,a]));if(c.some(a=>!a))return;r={[i]:c}}r&&(delete e.allOf,ae(e,r))}function vn(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)):ae(u,m),ae(u,f),c._zod.parent===d)for(const v in u)v==="$ref"||v==="allOf"||v in f||delete u[v];if(m.$ref&&h.def)for(const v in u)v==="$ref"||v==="allOf"||v in h.def&&JSON.stringify(u[v])===JSON.stringify(h.def[v])&&delete u[v]}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())_n(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)??[])Ps(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)}ae(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:Oe(t,"input",e.processors),output:Oe(t,"output",e.processors)}},enumerable:!1,writable:!1}),c}catch{throw new Error("Error converting schema to JSON.")}}function C(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 C(r.element,n);if(r.type==="set")return C(r.valueType,n);if(r.type==="lazy")return C(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 C(r.innerType,n);if(r.type==="intersection")return C(r.left,n)||C(r.right,n);if(r.type==="record"||r.type==="map")return C(r.keyType,n)||C(r.valueType,n);if(r.type==="pipe")return e._zod.traits.has("$ZodCodec")?!0:C(r.in,n)||C(r.out,n);if(r.type==="object"){for(const o in r.shape)if(C(r.shape[o],n))return!0;return!1}if(r.type==="union"){for(const o of r.options)if(C(o,n))return!0;return!1}if(r.type==="tuple"){for(const o of r.items)if(C(o,n))return!0;return!!(r.rest&&C(r.rest,n))}return!1}const Es=(e,t={})=>n=>{const r=mn({...n,processors:t});return E(e,r),gn(r,e),vn(r,e)},Oe=(e,t,n={})=>r=>{const{libraryOptions:o,target:i}=r??{},s=mn({...o??{},target:i,io:t,processors:n});return E(e,s),gn(s,e),vn(s,e)},Q=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},ee=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},It=(e,t)=>{Q(e,"minimum",t),ee(e,"maximum",t)},bn=(e,t)=>{e.multipleOf??(e.multipleOf=[]),e.multipleOf.includes(t)||e.multipleOf.push(t)},wn=(e,t)=>{e.patterns??(e.patterns=new Set),e.patterns.add(t)},zn=(e,t)=>{e.mime=e.mime?e.mime.filter(n=>t.includes(n)):[...t]},kn=(e,t)=>{e.format=t,t.includes("int")&&(e.isInt=!0)},At=(e,t)=>Q(e,"minimum",t.minimum),Ct=(e,t)=>ee(e,"maximum",t.maximum),jt=e=>(t,n)=>{kn(t,n.format);const[r,o]=e[n.format];Q(t,"minimum",r),ee(t,"maximum",o)},Is={greater_than:(e,t)=>Q(e,t.inclusive?"minimum":"exclusiveMinimum",t.value),less_than:(e,t)=>ee(e,t.inclusive?"maximum":"exclusiveMaximum",t.value),multiple_of:(e,t)=>bn(e,t.value),number_format:jt(Hn),bigint_format:jt(Yn),min_length:At,max_length:Ct,length_equals:(e,t)=>It(e,t.length),min_size:At,max_size:Ct,size_equals:(e,t)=>It(e,t.size),string_format:(e,t)=>{kn(e,t.format),t.pattern&&wn(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)=>zn(e,t.mime)};function ue(e){const t={},n=e._zod.def,r=e._zod.traits.has("$ZodCheck")?[e,...n.checks??[]]:n.checks??[];for(const i of r)Is[i._zod.def.check]?.(t,i._zod.def);const o=e._zod.bag;o.minimum!==void 0&&Q(t,"minimum",o.minimum),o.exclusiveMinimum!==void 0&&Q(t,"exclusiveMinimum",o.exclusiveMinimum),o.maximum!==void 0&&ee(t,"maximum",o.maximum),o.exclusiveMaximum!==void 0&&ee(t,"exclusiveMaximum",o.exclusiveMaximum),o.multipleOf!==void 0&&bn(t,o.multipleOf),o.format!==void 0&&(t.format??(t.format=o.format),o.format.includes("int")&&(t.isInt=!0)),o.mime&&zn(t,o.mime);for(const i of o.patterns??[])wn(t,i);return t}const As={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Cs=new Map([[cn,eo],[rt,to]]),js=e=>Cs.get(e)??e,Ts=(e,t,n,r)=>{const o=n;o.type="string";const{minimum:i,maximum:s,format:c,patterns:a,contentEncoding:u,laxFormat:f}=ue(e);if(typeof i=="number"&&(o.minLength=i),typeof s=="number"&&(o.maxLength=s),c&&(o.format=As[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(js);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}))])}},Rs=(e,t,n,r)=>{n.type="boolean"},Ds=(e,t,n,r)=>{n.not={}},Ns=(e,t,n,r)=>{},Us=(e,t,n,r)=>{const o=e._zod.def,i=De(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},Fs=(e,t,n,r)=>{de(e,t,n,r,"Custom types cannot be represented in JSON Schema")},xs=(e,t,n,r)=>{de(e,t,n,r,"Transforms cannot be represented in JSON Schema")},Ls=(e,t,n,r)=>{const o=n,i=e._zod.def,{minimum:s,maximum:c}=ue(e);typeof s=="number"&&(o.minItems=s),typeof c=="number"&&(o.maxItems=c),o.type="array",o.items=E(i.element,t,{...r,path:[...r.path,"items"]})};function Je(e){const t=e._zod.def;return t.type==="pipe"&&t.in._zod.traits.has("$ZodTransform")?Je(t.out):t.type==="catch"?Je(t.innerType):e._zod.optin}const Ms=(e,t,n,r)=>{const o=n,i=e._zod.def,s=i.shape;if(Object.getOwnPropertySymbols(s).length&&de(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,E(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"?Je(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=E(i.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):t.io==="output"&&(o.additionalProperties=!1)},Js=(e,t,n,r)=>{const o=e._zod.def,i=o.inclusive===!1,s=o.options.map((c,a)=>E(c,t,{...r,path:[...r.path,i?"oneOf":"anyOf",a]}));i?n.oneOf=s:n.anyOf=s},Bs=(e,t,n,r)=>{const o=e._zod.def,i=E(o.left,t,{...r,path:[...r.path,"allOf",0]}),s=E(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)},Ks=(e,t,n,r)=>{const o=e._zod.def,i=E(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"}]},Vs=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType},ot=Symbol();function $n(e,t,n,r,o){let i=!1;const s=JSON.stringify(e,(c,a)=>typeof a!="bigint"?a:(i=!0,null));return i?(de(t,n,r,o,"BigInt defaults cannot be represented in JSON Schema"),ot):JSON.parse(s)}const Ws=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType;const s=$n(o.defaultValue,e,t,n,r);s!==ot&&(n.default=s)},qs=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const i=t.seen.get(e);if(i.ref=o.innerType,t.io!=="input")return;const s=$n(o.defaultValue,e,t,n,r);s!==ot&&(n._prefault=s)},Gs=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType;let s;try{s=o.catchValue(void 0)}catch{de(e,t,n,r,"Dynamic catch values are not supported in JSON Schema");return}n.default=s},Xs=(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;E(s,t,r);const c=t.seen.get(e);c.ref=s},Hs=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType,n.readOnly=!0},On=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const i=t.seen.get(e);i.ref=o.innerType},Tt=new WeakSet([Object.prototype,Error.prototype]);function ge(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 Ys=(e,t)=>{wr.init(e,t),e.name="ZodError";const n=Object.getPrototypeOf(e);Tt.has(n)||(Tt.add(n),ge(n,"format",r=>o=>$r(r,o)),ge(n,"flatten",r=>o=>kr(r,o)),ge(n,"addIssue",r=>o=>{r.issues.push(o),r.message=JSON.stringify(r.issues,Ne,2)}),ge(n,"addIssues",r=>o=>{r.issues.push(...o),r.message=JSON.stringify(r.issues,Ne,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},R=l("ZodError",Ys,void 0,{Parent:Error}),Qs=He(R),ec=Ye(R),tc=Qe(R),nc=et(R),rc=Ir(R),oc=Ar(R),ic=Cr(R),sc=jr(R),cc=Tr(R),ac=Rr(R),uc=Dr(R),fc=Nr(R);function lc(){D.localeError||K(ji())}function it(){D.memoizer||K({memoizer:Ii()})}const P=l("ZodType",(e,t)=>(lc(),Z.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 B(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(ia(e,t))},superRefine(e,t){return this.check(sa(e,t))},overwrite(e){return this.check(ne(e))},optional(){return Dt(this)},exactOptional(){return Vc(this)},nullable(){return Nt(this)},nullish(){return Dt(Nt(this))},nonoptional(e){return Yc(this,e)},array(){return En(this)},or(e){return Lc([this,e])},and(e){return Jc(this,e)},transform(e){return Ut(this,Kc(e))},default(e){return Gc(this,e)},prefault(e){return Hc(this,e)},catch(e){return ea(this,e)},pipe(e){return Ut(this,e)},readonly(){return ra(this)},describe(e){const t=this.clone();return ie.add(t,{description:e}),t},meta(...e){if(e.length===0)return ie.get(this);const t=this.clone();return ie.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 Xt(this,"~standard",{...tn(this),jsonSchema:{input:Oe(this,"input"),output:Oe(this,"output")}})},set"~standard"(e){J(this,"~standard",e)},parse:function e(t,n){return Qs(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await ec(this,t,n,{callee:e})},safeParse(e,t){return tc(this,e,t)},async safeParseAsync(e,t){return nc(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){J(this,"spa",e)},validate(e,t){return Zr(this,e,t)},validateAsync(e,t){return Er(this,e,t)},encode:function e(t,n){return rc(this,t,n,{callee:e})},decode:function e(t,n){return oc(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await ic(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await sc(this,t,n,{callee:e})},safeEncode(e,t){return cc(this,e,t)},safeDecode(e,t){return ac(this,e,t)},async safeEncodeAsync(e,t){return uc(this,e,t)},async safeDecodeAsync(e,t){return fc(this,e,t)},toJSONSchema(e){return Es(this,{})(e)},get description(){return ie.get(this)?.description},get _def(){return this._zod.def}}),Sn=l("_ZodString",(e,t)=>{nt.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ts(e,n,r)},ur({format:e=>ue(e).format??null,minLength:e=>ue(e).minimum??null,maxLength:e=>ue(e).maximum??null},{regex(...e){return this.check(ps(...e))},includes(...e){return this.check(gs(...e))},startsWith(...e){return this.check(_s(...e))},endsWith(...e){return this.check(ys(...e))},min(...e){return this.check($e(...e))},max(...e){return this.check(pn(...e))},length(...e){return this.check(hn(...e))},nonempty(...e){return this.check($e(1,...e))},lowercase(e){return this.check(hs(e))},uppercase(e){return this.check(ms(e))},trim(){return this.check(bs())},normalize(...e){return this.check(vs(...e))},toLowerCase(){return this.check(ws())},toUpperCase(){return this.check(zs())},slugify(){return this.check(ks())}})),dc=l("ZodString",(e,t)=>{nt.init(e,t),Sn.init(e,t)},{email(e){return this.check(Ui(_c,e))},url(e){return this.check(Bi(vc,e))},jwt(e){return this.check(is(Tc,e))},emoji(e){return this.check(Ki(bc,e))},guid(e){return this.check(Fi(yc,e))},uuid(e){return this.check(xi(_e,e))},uuidv4(e){return this.check(Li(_e,e))},uuidv6(e){return this.check(Mi(_e,e))},uuidv7(e){return this.check(Ji(_e,e))},nanoid(e){return this.check(Vi(wc,e))},cuid(e){return this.check(Wi(zc,e))},cuid2(e){return this.check(qi(kc,e))},ulid(e){return this.check(Gi($c,e))},base64(e){return this.check(ns(Ac,e))},base64url(e){return this.check(rs(Cc,e))},xid(e){return this.check(Xi(Oc,e))},ksuid(e){return this.check(Hi(Sc,e))},ipv4(e){return this.check(Yi(Zc,e))},ipv6(e){return this.check(Qi(Pc,e))},cidrv4(e){return this.check(es(Ec,e))},cidrv6(e){return this.check(ts(Ic,e))},e164(e){return this.check(os(jc,e))},datetime(e){return this.check(ss(pc,e))},date(e){return this.check(cs(hc,e))},time(e){return this.check(as(mc,e))},duration(e){return this.check(us(gc,e))}});function H(e){return Ni(dc,e)}const O=l("ZodStringFormat",(e,t)=>{$.init(e,t),Sn.init(e,t)}),pc=l("ZodISODateTime",(e,t)=>{Mo.init(e,t),O.init(e,t)}),hc=l("ZodISODate",(e,t)=>{Jo.init(e,t),O.init(e,t)}),mc=l("ZodISOTime",(e,t)=>{Bo.init(e,t),O.init(e,t)}),gc=l("ZodISODuration",(e,t)=>{Ko.init(e,t),O.init(e,t)}),_c=l("ZodEmail",(e,t)=>{Po.init(e,t),O.init(e,t)}),yc=l("ZodGUID",(e,t)=>{So.init(e,t),O.init(e,t)}),_e=l("ZodUUID",(e,t)=>{Zo.init(e,t),O.init(e,t)}),vc=l("ZodURL",(e,t)=>{To.init(e,t),O.init(e,t)}),bc=l("ZodEmoji",(e,t)=>{Ro.init(e,t),O.init(e,t)}),wc=l("ZodNanoID",(e,t)=>{Do.init(e,t),O.init(e,t)}),zc=l("ZodCUID",(e,t)=>{No.init(e,t),O.init(e,t)}),kc=l("ZodCUID2",(e,t)=>{Uo.init(e,t),O.init(e,t)}),$c=l("ZodULID",(e,t)=>{Fo.init(e,t),O.init(e,t)}),Oc=l("ZodXID",(e,t)=>{xo.init(e,t),O.init(e,t)}),Sc=l("ZodKSUID",(e,t)=>{Lo.init(e,t),O.init(e,t)}),Zc=l("ZodIPv4",(e,t)=>{Vo.init(e,t),O.init(e,t)}),Pc=l("ZodIPv6",(e,t)=>{qo.init(e,t),O.init(e,t)}),Ec=l("ZodCIDRv4",(e,t)=>{Go.init(e,t),O.init(e,t)}),Ic=l("ZodCIDRv6",(e,t)=>{Ho.init(e,t),O.init(e,t)}),Ac=l("ZodBase64",(e,t)=>{Yo.init(e,t),O.init(e,t)}),Cc=l("ZodBase64URL",(e,t)=>{ei.init(e,t),O.init(e,t)}),jc=l("ZodE164",(e,t)=>{ti.init(e,t),O.init(e,t)}),Tc=l("ZodJWT",(e,t)=>{ri.init(e,t),O.init(e,t)}),Rc=l("ZodBoolean",(e,t)=>{oi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Rs(e,n,r)});function Zn(e){return fs(Rc,e)}const Dc=l("ZodUnknown",(e,t)=>{ii.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ns()});function Rt(){return ls(Dc)}const Nc=l("ZodNever",(e,t)=>{si.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ds(e,n,r)});function Pn(e){return ds(Nc,e)}const Uc=l("ZodArray",(e,t)=>{it(),ui.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ls(e,n,r,o),e.element=t.element},{min(e,t){return this.check($e(e,t))},nonempty(e){return this.check($e(1,e))},max(e,t){return this.check(pn(e,t))},length(e,t){return this.check(hn(e,t))},unwrap(){return this.element}});function En(e,t){return $s(Uc,e,t)}const Fc=l("ZodObject",(e,t)=>{it(),di.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ms(e,n,r,o),pr(e,"shape",n=>n._zod.def.shape,!1)},{keyof(){return In(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:Rt()}))},loose(){return this.clone(T(this._zod.def,{catchall:Rt()}))},strict(){return this.clone(T(this._zod.def,{catchall:Pn()}))},strip(){return this.clone(T(this._zod.def,{catchall:void 0}))},extend(e){return tr(this,e)},safeExtend(e){return nr(this,e)},merge(e){return rr(this,e)},pick(e){return Qn(this,e)},omit(e){return er(this,e)},partial(...e){return ut(An,this,e[0])},exactPartial(...e){return ut(Cn,this,e[0],"exactPartial")},required(...e){return or(jn,this,e[0])}});function Y(e,t){return new Fc({type:"object",shape:e,catchall:Pn(),...y(t)})}const xc=l("ZodUnion",(e,t)=>{pi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Js(e,n,r,o),e.options=t.options});function Lc(e,t){return new xc({type:"union",options:e,...y(t)})}const Mc=l("ZodIntersection",(e,t)=>{hi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Bs(e,n,r,o)});function Jc(e,t){return new Mc({type:"intersection",left:e,right:t})}const Be=l("ZodEnum",(e,t)=>{mi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(r,o,i)=>Us(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 Be({...t,checks:[],...y(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 Be({...t,checks:[],...y(o),entries:i})}});function In(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new Be({type:"enum",entries:n,...y(t)})}const Bc=l("ZodTransform",(e,t)=>{it(),gi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>xs(e,n,r,o),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Ht(e.constructor.name);n.addIssue=i=>{if(typeof i=="string")n.issues.push(le(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(le(s))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(i=>(n.value=i,n)):(n.value=o,n)}});function Kc(e){return new Bc({type:"transform",transform:e})}const An=l("ZodOptional",(e,t)=>{fn.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>On(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Dt(e){return new An({type:"optional",innerType:e})}const Cn=l("ZodExactOptional",(e,t)=>{_i.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>On(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Vc(e){return new Cn({type:"optional",innerType:e})}const Wc=l("ZodNullable",(e,t)=>{yi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ks(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Nt(e){return new Wc({type:"nullable",innerType:e})}const qc=l("ZodDefault",(e,t)=>{vi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ws(e,n,r,o),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Gc(e,t){return new qc({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Vt(t)}})}const Xc=l("ZodPrefault",(e,t)=>{bi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>qs(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Hc(e,t){return new Xc({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():Vt(t)}})}const jn=l("ZodNonOptional",(e,t)=>{wi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Vs(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Yc(e,t){return new jn({type:"nonoptional",innerType:e,...y(t)})}const Qc=l("ZodCatch",(e,t)=>{zi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Gs(e,n,r,o),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function ea(e,t){return new Qc({type:"catch",innerType:e,catchValue:typeof t=="function"?t:mr(t)})}const ta=l("ZodPipe",(e,t)=>{ki.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Xs(e,n,r,o),e.in=t.in,e.out=t.out});function Ut(e,t){return new ta({type:"pipe",in:e,out:t})}const na=l("ZodReadonly",(e,t)=>{$i.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Hs(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function ra(e){return new na({type:"readonly",innerType:e})}const oa=l("ZodCustom",(e,t)=>{Oi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Fs(e,n,r,o)});function ia(e,t={}){return Os(oa,e,t)}function sa(e,t){return Ss(e,t)}const ca="opencode-clockify-plugin",Tn=/^[a-z][a-z0-9-]{1,23}$/,Ke="Use 2–24 lowercase letters, numbers, or hyphens, starting with a letter.",Rn=["global","EU","USA","UK","AU"],Dn=H().regex(Tn,Ke),Nn=H().regex(/^clockify_[a-z][a-z0-9-]{1,23}_[a-f0-9]{12}$/),Un=In(Rn),Ft=Y({alias:Dn,name:Nn,region:Un,enabled:Zn()}),W=Y({}),Re=Y({name:Nn}),ye={account_error:W},st=Mn.Rpc.define({id:ca,methods:{list:{input:W,output:Y({accounts:En(Ft.extend({identity:H().optional()}))})},add:{input:Y({alias:Dn,region:Un}),output:Ft,errors:ye},enable:{input:Re.extend({enabled:Zn()}),output:W,errors:ye},remove:{input:Re,output:W,errors:ye},verify:{input:Re.extend({key:H().min(1).max(512).regex(/^[\x21-\x7e]+$/)}),output:Y({id:H(),label:H()}),errors:ye},refresh:{input:W,output:W}},events:{changed:{schema:W}}}),aa=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
|
58
|
+
<path d="M13.3512 20.4035c1.1108 0 2.169-.2217 3.139-.6157l2.6913 2.6944C17.4555 23.4458 15.4688 24 13.3512 24 6.729 24 1.3594 18.627 1.3594 12.0006 1.3594 5.3729 6.7289 0 13.3512 0c2.0964 0 4.0652.5406 5.7789 1.4865L16.4834 4.136c-.9687-.3918-2.0236-.6134-3.1322-.6134-4.6379 0-8.3976 3.779-8.3976 8.441 0 4.6609 3.7597 8.4399 8.3976 8.4399zm2.176-12.1544l5.5104-5.5139 1.5773 1.5772-5.5104 5.514zm-2.2328 5.6348c-1.0784 0-1.952-.8775-1.952-1.961 0-1.0825.8736-1.9611 1.952-1.9611 1.0784 0 1.952.8786 1.952 1.961 0 1.0836-.8736 1.9611-1.952 1.9611zm9.3462 5.6953l-1.5772 1.5783-5.5105-5.514 1.5774-1.5783z"/>
|
|
59
|
+
</svg>
|
|
60
|
+
`;var Fn=z.template("<p role=alert>"),ua=z.template("<p>No Clockify accounts added yet.");const Ve="Clockify",xt="clockify-accounts",fa=Rn.map(e=>({value:e,label:e==="global"?"Global":e})),la={connected:"Connected",disabled:"Disabled",failed:"Connection failed",needs_auth:"API key required",pending:"Connecting…"};async function da(e){const[{accounts:t},{data:n}]=await Promise.all([e.client.rpc(st).list({}),e.client.mcp.list()]);return{accounts:t,statuses:new Map(n.map(({name:r,status:o})=>[r,o.status]))}}const Lt=new WeakMap;function pa(){const e=se.usePlugin(),t=e.ui,n=()=>e.client.rpc(st),[r,o]=j.createSignal(""),[i,s]=j.createSignal("global"),[c,a]=j.createSignal(!1),[u,f]=j.createSignal(""),[d,{refetch:p}]=j.createResource(async()=>{const _=await da(e);return Lt.set(e,_),_},{initialValue:Lt.get(e)}),h=new AbortController;let m;const g=()=>{m&&clearTimeout(m),m=setTimeout(()=>{m=void 0,p()},250)},v=n().events.on("changed",g);j.onCleanup(()=>{v(),h.abort(),m&&clearTimeout(m)}),(async()=>{for await(const _ of e.client.event.subscribe({types:["mcp.status.changed"],signal:h.signal}))_.type==="mcp.status.changed"&&g()})().catch(()=>{});async function k(_,b){if(!c()){a(!0),f("");try{await _()}catch(A){const V=A&&typeof A=="object"&&"type"in A&&A.type==="account_error"&&"message"in A&&typeof A.message=="string"?` ${A.message}`:"";f(`${b}${V}`)}finally{p(),a(!1)}}}function I(){const _=r().trim().toLowerCase();if(!Tn.test(_)){f(Ke);return}k(async()=>{const b=await n().add({alias:_,region:i()});o(""),x(b)},"Could not add the Clockify account.")}function x(_){e.dialogs.open(b=>z.createComponent(ha,{account:_,onDone:()=>{b.close(),p()}}))}async function L(_){const b=e.client,{data:A}=await b.integration.get({integrationID:_.name});await Promise.all(A.connections.flatMap(V=>V.type==="credential"?[b.credential.remove({credentialID:V.id})]:[])),await n().refresh({})}async function S(_){await e.dialogs.confirm({title:`Remove ${_.alias}?`,description:"Remove this connection and its saved key from OpenCode.",confirm:"Remove",danger:!0})&&await k(async()=>{await L(_),await n().remove({name:_.name})},"Could not remove the Clockify account.")}return z.createComponent(t.SettingsLayout,{title:Ve,description:"Connect each Clockify account with its own API key and data region.",get actions(){return z.createComponent(t.Button,{onClick:()=>{p()},children:"Refresh"})},get children(){return[z.createComponent(t.SettingsSection,{title:"Add an account",get children(){return[z.createComponent(t.SettingsRow,{id:"add",title:"Account alias",description:Ke,get children(){return z.createComponent(t.TextInput,{label:"Account alias",placeholder:"e.g. work",get value(){return r()},onInput:o,onSubmit:I,get disabled(){return c()}})}}),z.createComponent(t.SettingsRow,{title:"Data region",description:"Select the region that issued your API key.",get children(){return z.createComponent(t.Select,{label:"Data region",options:fa,get value(){return i()},onChange:s,get disabled(){return c()}})}}),z.createComponent(t.SettingsRow,{title:"Save connection",description:"You’ll be prompted for your API key.",get children(){return z.createComponent(t.Button,{variant:"contrast",onClick:I,get disabled(){return c()||!r().trim()},children:"Add account"})}})]}}),z.createComponent(j.Show,{get when(){return u()||d.error},get children(){var _=Fn();return z.insert(_,()=>u()||"Could not load Clockify accounts. Refresh to try again."),_}}),z.createComponent(j.Show,{get when(){return z.memo(()=>!d.error)()&&d()},children:_=>z.createComponent(t.SettingsSection,{title:"Connections",footer:"For example: “Using Clockify work, summarize my time last week.”",get children(){return[z.createComponent(j.Show,{get when(){return!_().accounts.length},get children(){return ua()}}),z.createComponent(j.For,{get each(){return _().accounts},children:b=>{const A=()=>b.enabled?b.identity?_().statuses.get(b.name)??"pending":"needs_auth":"disabled";return z.createComponent(t.SettingsRow,{get title(){return`${b.alias} · ${la[A()]}`},get description(){return[b.identity,b.region==="global"?"Global":b.region,b.name].filter(Boolean).join(" · ")},get children(){return z.createComponent(t.Menu,{get label(){return`Manage ${b.alias}`},get disabled(){return c()},get items(){return[{label:"Enter API key…",disabled:!!b.identity,onSelect:()=>x(b)},{label:"Sign out",disabled:!b.identity,onSelect:()=>{k(()=>L(b),"Could not sign out of Clockify.")}},{label:b.enabled?"Disable":"Enable",onSelect:()=>{k(async()=>{await n().enable({name:b.name,enabled:!b.enabled})},"Could not change the account’s availability.")}},{label:"Remove…",onSelect:()=>{S(b)}}]}})}})}})]}})})]}})}function ha(e){const t=se.usePlugin(),n=t.ui,[r,o]=j.createSignal(""),[i,s]=j.createSignal(!1),[c,a]=j.createSignal(""),u=new AbortController;j.onCleanup(()=>u.abort());async function f(){const d=r().trim();if(!d||i())return;s(!0),a("");const p=t.client,h=p.rpc(st),m=e.account.name;try{const g=await h.verify({name:m,key:d},{signal:u.signal});if(u.signal.aborted)return;const v=await p.credential.create({integrationID:m,label:g.label,value:{type:"key",key:d,metadata:{clockifyUserID:g.id}},activate:!0}),{accounts:k}=await h.list({});if(!k.some(I=>I.name===m)){await p.credential.remove({credentialID:v.id}),a("This account was removed in another window.");return}await h.refresh({}),o(""),e.onDone()}catch(g){if(u.signal.aborted)return;g&&typeof g=="object"&&"type"in g&&g.type==="account_error"&&"message"in g&&typeof g.message=="string"?a(g.message):a("Could not save or activate the Clockify key. Close this dialog and refresh to check the connection.")}finally{s(!1)}}return z.createComponent(n.Dialog,{get title(){return`Connect Clockify: ${e.account.alias}`},description:"Generate a key in Clockify under Preferences → Advanced → Manage API keys.",get children(){return[z.createComponent(n.TextInput,{label:"API key",type:"password",get value(){return r()},onInput:o,onSubmit:()=>{f()},get disabled(){return i()},autofocus:!0}),z.createComponent(n.Button,{variant:"contrast",onClick:()=>{f()},get busy(){return i()},get disabled(){return!r().trim()},children:"Verify and connect"}),z.createComponent(j.Show,{get when(){return c()},get children(){var d=Fn();return z.insert(d,c),d}})]}})}const ma=se.Plugin.define({icons:{logo:aa},setup(e){e.add(se.SettingsPage,{id:xt,icon:e.icons.logo,title:Ve,entries:[{id:"add",title:"Add a Clockify account",keywords:"clockify accounts api key time tracking"}],render:()=>z.createComponent(pa,{})}),e.add(se.Command,{id:"accounts",title:Ve,keywords:"manage clockify accounts workspace time tracking mcp",run:()=>e.layout.settings(xt)})}});exports.default=ma;
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morozinc/opencode-clockify-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": "git+https://github.com/ShiftHackZ/opencode-clockify-plugin.git",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"opencode",
|
|
8
|
+
"opencode-plugin",
|
|
9
|
+
"clockify"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"registry": "https://registry.npmjs.org/"
|
|
14
|
+
},
|
|
15
|
+
"description": "Manage multiple Clockify accounts with the official Clockify MCP server in OpenCode Desktop.",
|
|
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/clockify.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="M13.3512 20.4035c1.1108 0 2.169-.2217 3.139-.6157l2.6913 2.6944C17.4555 23.4458 15.4688 24 13.3512 24 6.729 24 1.3594 18.627 1.3594 12.0006 1.3594 5.3729 6.7289 0 13.3512 0c2.0964 0 4.0652.5406 5.7789 1.4865L16.4834 4.136c-.9687-.3918-2.0236-.6134-3.1322-.6134-4.6379 0-8.3976 3.779-8.3976 8.441 0 4.6609 3.7597 8.4399 8.3976 8.4399zm2.176-12.1544l5.5104-5.5139 1.5773 1.5772-5.5104 5.514zm-2.2328 5.6348c-1.0784 0-1.952-.8775-1.952-1.961 0-1.0825.8736-1.9611 1.952-1.9611 1.0784 0 1.952.8786 1.952 1.961 0 1.0836-.8736 1.9611-1.952 1.9611zm9.3462 5.6953l-1.5772 1.5783-5.5105-5.514 1.5774-1.5783z"/>
|
|
3
|
+
</svg>
|
package/src/clockify.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
import type { Region } from "./rpc.js"
|
|
3
|
+
|
|
4
|
+
export const endpoint = "https://api.clockify.me/mcp-server/mcp"
|
|
5
|
+
const apiHosts: Record<Region, string> = {
|
|
6
|
+
global: "api.clockify.me",
|
|
7
|
+
EU: "euc1.clockify.me",
|
|
8
|
+
USA: "use2.clockify.me",
|
|
9
|
+
UK: "euw2.clockify.me",
|
|
10
|
+
AU: "apse2.clockify.me",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const profile = z.object({
|
|
14
|
+
id: z.string().min(1),
|
|
15
|
+
email: z.string().nullish(),
|
|
16
|
+
name: z.string().nullish(),
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export async function verifyKey(region: Region, key: string, signal: AbortSignal) {
|
|
20
|
+
const response = await fetch(`https://${apiHosts[region]}/api/v1/user`, {
|
|
21
|
+
headers: { "x-api-key": key, accept: "application/json" },
|
|
22
|
+
redirect: "error",
|
|
23
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(10_000)]),
|
|
24
|
+
})
|
|
25
|
+
if (response.status === 401 || response.status === 403) return undefined
|
|
26
|
+
if (!response.ok) throw new Error("Clockify profile unavailable")
|
|
27
|
+
const user = profile.parse(await response.json())
|
|
28
|
+
return { id: user.id, label: user.email || user.name || user.id }
|
|
29
|
+
}
|
package/src/gui.tsx
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
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
|
+
ClockifyAccounts,
|
|
13
|
+
regions,
|
|
14
|
+
type Account,
|
|
15
|
+
type Region,
|
|
16
|
+
} from "./rpc.js";
|
|
17
|
+
import logo from "./clockify.svg?raw";
|
|
18
|
+
|
|
19
|
+
const title = "Clockify";
|
|
20
|
+
const settingsID = "clockify-accounts";
|
|
21
|
+
const regionOptions = regions.map((value) => ({
|
|
22
|
+
value,
|
|
23
|
+
label: value === "global" ? "Global" : value,
|
|
24
|
+
}));
|
|
25
|
+
const statusLabels = {
|
|
26
|
+
connected: "Connected",
|
|
27
|
+
disabled: "Disabled",
|
|
28
|
+
failed: "Connection failed",
|
|
29
|
+
needs_auth: "API key required",
|
|
30
|
+
pending: "Connecting…",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
async function loadView(ctx: Context) {
|
|
34
|
+
const [{ accounts }, { data }] = await Promise.all([
|
|
35
|
+
ctx.client.rpc(ClockifyAccounts).list({}),
|
|
36
|
+
ctx.client.mcp.list(),
|
|
37
|
+
]);
|
|
38
|
+
return {
|
|
39
|
+
accounts,
|
|
40
|
+
statuses: new Map(data.map(({ name, status }) => [name, status.status])),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const viewCache = new WeakMap<Context, Awaited<ReturnType<typeof loadView>>>();
|
|
45
|
+
|
|
46
|
+
function ClockifySettings() {
|
|
47
|
+
const ctx = usePlugin();
|
|
48
|
+
const ui = ctx.ui;
|
|
49
|
+
const rpc = () => ctx.client.rpc(ClockifyAccounts);
|
|
50
|
+
const [alias, setAlias] = createSignal("");
|
|
51
|
+
const [region, setRegion] = createSignal<Region>("global");
|
|
52
|
+
const [busy, setBusy] = createSignal(false);
|
|
53
|
+
const [error, setError] = createSignal("");
|
|
54
|
+
const [view, { refetch }] = createResource(
|
|
55
|
+
async () => {
|
|
56
|
+
const result = await loadView(ctx);
|
|
57
|
+
viewCache.set(ctx, result);
|
|
58
|
+
return result;
|
|
59
|
+
},
|
|
60
|
+
{ initialValue: viewCache.get(ctx) },
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const events = new AbortController();
|
|
64
|
+
let refreshTimer: ReturnType<typeof setTimeout> | undefined;
|
|
65
|
+
const scheduleRefresh = () => {
|
|
66
|
+
if (refreshTimer) clearTimeout(refreshTimer);
|
|
67
|
+
refreshTimer = setTimeout(() => {
|
|
68
|
+
refreshTimer = undefined;
|
|
69
|
+
void refetch();
|
|
70
|
+
}, 250);
|
|
71
|
+
};
|
|
72
|
+
const unsubscribe = rpc().events.on("changed", scheduleRefresh);
|
|
73
|
+
onCleanup(() => {
|
|
74
|
+
unsubscribe();
|
|
75
|
+
events.abort();
|
|
76
|
+
if (refreshTimer) clearTimeout(refreshTimer);
|
|
77
|
+
});
|
|
78
|
+
void (async () => {
|
|
79
|
+
for await (const event of ctx.client.event.subscribe({
|
|
80
|
+
types: ["mcp.status.changed"],
|
|
81
|
+
signal: events.signal,
|
|
82
|
+
})) {
|
|
83
|
+
if (event.type === "mcp.status.changed") scheduleRefresh();
|
|
84
|
+
}
|
|
85
|
+
})().catch(() => {
|
|
86
|
+
/* Manual refresh remains available. */
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
async function run(action: () => Promise<void>, failure: string) {
|
|
90
|
+
if (busy()) return;
|
|
91
|
+
setBusy(true);
|
|
92
|
+
setError("");
|
|
93
|
+
try {
|
|
94
|
+
await action();
|
|
95
|
+
} catch (cause) {
|
|
96
|
+
const detail =
|
|
97
|
+
cause &&
|
|
98
|
+
typeof cause === "object" &&
|
|
99
|
+
"type" in cause &&
|
|
100
|
+
cause.type === "account_error" &&
|
|
101
|
+
"message" in cause &&
|
|
102
|
+
typeof cause.message === "string"
|
|
103
|
+
? ` ${cause.message}`
|
|
104
|
+
: "";
|
|
105
|
+
setError(`${failure}${detail}`);
|
|
106
|
+
} finally {
|
|
107
|
+
void refetch();
|
|
108
|
+
setBusy(false);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function add() {
|
|
113
|
+
const value = alias().trim().toLowerCase();
|
|
114
|
+
if (!aliasPattern.test(value)) {
|
|
115
|
+
setError(aliasHint);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
void run(async () => {
|
|
119
|
+
const account = await rpc().add({ alias: value, region: region() });
|
|
120
|
+
setAlias("");
|
|
121
|
+
signIn(account);
|
|
122
|
+
}, "Could not add the Clockify account.");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function signIn(account: Account) {
|
|
126
|
+
ctx.dialogs.open((dialog) => (
|
|
127
|
+
<KeyDialog
|
|
128
|
+
account={account}
|
|
129
|
+
onDone={() => {
|
|
130
|
+
dialog.close();
|
|
131
|
+
void refetch();
|
|
132
|
+
}}
|
|
133
|
+
/>
|
|
134
|
+
));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function signOut(account: Account) {
|
|
138
|
+
const client = ctx.client;
|
|
139
|
+
const { data } = await client.integration.get({
|
|
140
|
+
integrationID: account.name,
|
|
141
|
+
});
|
|
142
|
+
await Promise.all(
|
|
143
|
+
data.connections.flatMap((connection) =>
|
|
144
|
+
connection.type === "credential"
|
|
145
|
+
? [client.credential.remove({ credentialID: connection.id })]
|
|
146
|
+
: [],
|
|
147
|
+
),
|
|
148
|
+
);
|
|
149
|
+
await rpc().refresh({});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function remove(account: Account) {
|
|
153
|
+
if (
|
|
154
|
+
!(await ctx.dialogs.confirm({
|
|
155
|
+
title: `Remove ${account.alias}?`,
|
|
156
|
+
description: "Remove this connection and its saved key from OpenCode.",
|
|
157
|
+
confirm: "Remove",
|
|
158
|
+
danger: true,
|
|
159
|
+
}))
|
|
160
|
+
)
|
|
161
|
+
return;
|
|
162
|
+
await run(async () => {
|
|
163
|
+
await signOut(account);
|
|
164
|
+
await rpc().remove({ name: account.name });
|
|
165
|
+
}, "Could not remove the Clockify account.");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<ui.SettingsLayout
|
|
170
|
+
title={title}
|
|
171
|
+
description="Connect each Clockify account with its own API key and data region."
|
|
172
|
+
actions={<ui.Button onClick={() => void refetch()}>Refresh</ui.Button>}
|
|
173
|
+
>
|
|
174
|
+
<ui.SettingsSection title="Add an account">
|
|
175
|
+
<ui.SettingsRow id="add" title="Account alias" description={aliasHint}>
|
|
176
|
+
<ui.TextInput
|
|
177
|
+
label="Account alias"
|
|
178
|
+
placeholder="e.g. work"
|
|
179
|
+
value={alias()}
|
|
180
|
+
onInput={setAlias}
|
|
181
|
+
onSubmit={add}
|
|
182
|
+
disabled={busy()}
|
|
183
|
+
/>
|
|
184
|
+
</ui.SettingsRow>
|
|
185
|
+
<ui.SettingsRow
|
|
186
|
+
title="Data region"
|
|
187
|
+
description="Select the region that issued your API key."
|
|
188
|
+
>
|
|
189
|
+
<ui.Select
|
|
190
|
+
label="Data region"
|
|
191
|
+
options={regionOptions}
|
|
192
|
+
value={region()}
|
|
193
|
+
onChange={setRegion}
|
|
194
|
+
disabled={busy()}
|
|
195
|
+
/>
|
|
196
|
+
</ui.SettingsRow>
|
|
197
|
+
<ui.SettingsRow
|
|
198
|
+
title="Save connection"
|
|
199
|
+
description="You’ll be prompted for your API key."
|
|
200
|
+
>
|
|
201
|
+
<ui.Button
|
|
202
|
+
variant="contrast"
|
|
203
|
+
onClick={add}
|
|
204
|
+
disabled={busy() || !alias().trim()}
|
|
205
|
+
>
|
|
206
|
+
Add account
|
|
207
|
+
</ui.Button>
|
|
208
|
+
</ui.SettingsRow>
|
|
209
|
+
</ui.SettingsSection>
|
|
210
|
+
<Show when={error() || view.error}>
|
|
211
|
+
<p role="alert">
|
|
212
|
+
{error() || "Could not load Clockify accounts. Refresh to try again."}
|
|
213
|
+
</p>
|
|
214
|
+
</Show>
|
|
215
|
+
<Show when={!view.error && view()}>
|
|
216
|
+
{(data) => (
|
|
217
|
+
<ui.SettingsSection
|
|
218
|
+
title="Connections"
|
|
219
|
+
footer="For example: “Using Clockify work, summarize my time last week.”"
|
|
220
|
+
>
|
|
221
|
+
<Show when={!data().accounts.length}>
|
|
222
|
+
<p>No Clockify accounts added yet.</p>
|
|
223
|
+
</Show>
|
|
224
|
+
<For each={data().accounts}>
|
|
225
|
+
{(account) => {
|
|
226
|
+
const status = () =>
|
|
227
|
+
!account.enabled
|
|
228
|
+
? "disabled"
|
|
229
|
+
: !account.identity
|
|
230
|
+
? "needs_auth"
|
|
231
|
+
: (data().statuses.get(account.name) ?? "pending");
|
|
232
|
+
return (
|
|
233
|
+
<ui.SettingsRow
|
|
234
|
+
title={`${account.alias} · ${statusLabels[status()]}`}
|
|
235
|
+
description={[
|
|
236
|
+
account.identity,
|
|
237
|
+
account.region === "global" ? "Global" : account.region,
|
|
238
|
+
account.name,
|
|
239
|
+
]
|
|
240
|
+
.filter(Boolean)
|
|
241
|
+
.join(" · ")}
|
|
242
|
+
>
|
|
243
|
+
<ui.Menu
|
|
244
|
+
label={`Manage ${account.alias}`}
|
|
245
|
+
disabled={busy()}
|
|
246
|
+
items={[
|
|
247
|
+
{
|
|
248
|
+
label: "Enter API key…",
|
|
249
|
+
disabled: !!account.identity,
|
|
250
|
+
onSelect: () => signIn(account),
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
label: "Sign out",
|
|
254
|
+
disabled: !account.identity,
|
|
255
|
+
onSelect: () =>
|
|
256
|
+
void run(
|
|
257
|
+
() => signOut(account),
|
|
258
|
+
"Could not sign out of Clockify.",
|
|
259
|
+
),
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
label: account.enabled ? "Disable" : "Enable",
|
|
263
|
+
onSelect: () =>
|
|
264
|
+
void run(async () => {
|
|
265
|
+
await rpc().enable({
|
|
266
|
+
name: account.name,
|
|
267
|
+
enabled: !account.enabled,
|
|
268
|
+
});
|
|
269
|
+
}, "Could not change the account’s availability."),
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
label: "Remove…",
|
|
273
|
+
onSelect: () => void remove(account),
|
|
274
|
+
},
|
|
275
|
+
]}
|
|
276
|
+
/>
|
|
277
|
+
</ui.SettingsRow>
|
|
278
|
+
);
|
|
279
|
+
}}
|
|
280
|
+
</For>
|
|
281
|
+
</ui.SettingsSection>
|
|
282
|
+
)}
|
|
283
|
+
</Show>
|
|
284
|
+
</ui.SettingsLayout>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function KeyDialog(props: { account: Account; onDone: () => void }) {
|
|
289
|
+
const ctx = usePlugin();
|
|
290
|
+
const ui = ctx.ui;
|
|
291
|
+
const [key, setKey] = createSignal("");
|
|
292
|
+
const [busy, setBusy] = createSignal(false);
|
|
293
|
+
const [error, setError] = createSignal("");
|
|
294
|
+
const controller = new AbortController();
|
|
295
|
+
onCleanup(() => controller.abort());
|
|
296
|
+
|
|
297
|
+
async function submit() {
|
|
298
|
+
const value = key().trim();
|
|
299
|
+
if (!value || busy()) return;
|
|
300
|
+
setBusy(true);
|
|
301
|
+
setError("");
|
|
302
|
+
const client = ctx.client;
|
|
303
|
+
const rpc = client.rpc(ClockifyAccounts);
|
|
304
|
+
const name = props.account.name;
|
|
305
|
+
try {
|
|
306
|
+
const identity = await rpc.verify(
|
|
307
|
+
{ name, key: value },
|
|
308
|
+
{ signal: controller.signal },
|
|
309
|
+
);
|
|
310
|
+
if (controller.signal.aborted) return;
|
|
311
|
+
const credential = await client.credential.create({
|
|
312
|
+
integrationID: name,
|
|
313
|
+
label: identity.label,
|
|
314
|
+
value: {
|
|
315
|
+
type: "key",
|
|
316
|
+
key: value,
|
|
317
|
+
metadata: { clockifyUserID: identity.id },
|
|
318
|
+
},
|
|
319
|
+
activate: true,
|
|
320
|
+
});
|
|
321
|
+
const { accounts } = await rpc.list({});
|
|
322
|
+
if (!accounts.some((account) => account.name === name)) {
|
|
323
|
+
await client.credential.remove({ credentialID: credential.id });
|
|
324
|
+
setError("This account was removed in another window.");
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
await rpc.refresh({});
|
|
328
|
+
setKey("");
|
|
329
|
+
props.onDone();
|
|
330
|
+
} catch (cause) {
|
|
331
|
+
if (controller.signal.aborted) return;
|
|
332
|
+
if (
|
|
333
|
+
cause &&
|
|
334
|
+
typeof cause === "object" &&
|
|
335
|
+
"type" in cause &&
|
|
336
|
+
cause.type === "account_error" &&
|
|
337
|
+
"message" in cause &&
|
|
338
|
+
typeof cause.message === "string"
|
|
339
|
+
) {
|
|
340
|
+
setError(cause.message);
|
|
341
|
+
} else {
|
|
342
|
+
setError(
|
|
343
|
+
"Could not save or activate the Clockify key. Close this dialog and refresh to check the connection.",
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
} finally {
|
|
347
|
+
setBusy(false);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return (
|
|
352
|
+
<ui.Dialog
|
|
353
|
+
title={`Connect Clockify: ${props.account.alias}`}
|
|
354
|
+
description="Generate a key in Clockify under Preferences → Advanced → Manage API keys."
|
|
355
|
+
>
|
|
356
|
+
<ui.TextInput
|
|
357
|
+
label="API key"
|
|
358
|
+
type="password"
|
|
359
|
+
value={key()}
|
|
360
|
+
onInput={setKey}
|
|
361
|
+
onSubmit={() => void submit()}
|
|
362
|
+
disabled={busy()}
|
|
363
|
+
autofocus
|
|
364
|
+
/>
|
|
365
|
+
<ui.Button
|
|
366
|
+
variant="contrast"
|
|
367
|
+
onClick={() => void submit()}
|
|
368
|
+
busy={busy()}
|
|
369
|
+
disabled={!key().trim()}
|
|
370
|
+
>
|
|
371
|
+
Verify and connect
|
|
372
|
+
</ui.Button>
|
|
373
|
+
<Show when={error()}>
|
|
374
|
+
<p role="alert">{error()}</p>
|
|
375
|
+
</Show>
|
|
376
|
+
</ui.Dialog>
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export default Plugin.define({
|
|
381
|
+
icons: { logo },
|
|
382
|
+
setup(ctx) {
|
|
383
|
+
ctx.add(SettingsPage, {
|
|
384
|
+
id: settingsID,
|
|
385
|
+
icon: ctx.icons.logo,
|
|
386
|
+
title,
|
|
387
|
+
entries: [
|
|
388
|
+
{
|
|
389
|
+
id: "add",
|
|
390
|
+
title: "Add a Clockify account",
|
|
391
|
+
keywords: "clockify accounts api key time tracking",
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
render: () => <ClockifySettings />,
|
|
395
|
+
});
|
|
396
|
+
ctx.add(Command, {
|
|
397
|
+
id: "accounts",
|
|
398
|
+
title,
|
|
399
|
+
keywords: "manage clockify accounts workspace time tracking mcp",
|
|
400
|
+
run: () => ctx.layout.settings(settingsID),
|
|
401
|
+
});
|
|
402
|
+
},
|
|
403
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto"
|
|
2
|
+
import { Plugin } from "@opencode/plugin"
|
|
3
|
+
import { endpoint, verifyKey } from "./clockify.js"
|
|
4
|
+
import { accountList, ClockifyAccounts, pluginID, type Account } from "./rpc.js"
|
|
5
|
+
|
|
6
|
+
const storageKey = "accounts"
|
|
7
|
+
const readTools = new Set([
|
|
8
|
+
"get_current_user_profile", "get_current_time", "get_current_timer",
|
|
9
|
+
"get_summary_report", "get_detailed_report", "list_clients", "list_users",
|
|
10
|
+
"list_projects", "list_tasks", "list_tags",
|
|
11
|
+
])
|
|
12
|
+
|
|
13
|
+
type AccountState = {
|
|
14
|
+
accounts: Account[]
|
|
15
|
+
queue: Promise<void>
|
|
16
|
+
registries: Set<(inventoryChanged: boolean) => Promise<void>>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const stateKey = Symbol.for(`${pluginID}.accounts.v1`)
|
|
20
|
+
const host = globalThis as typeof globalThis & { [stateKey]?: AccountState }
|
|
21
|
+
const state = host[stateKey] ??= { accounts: [], queue: Promise.resolve(), registries: new Set() }
|
|
22
|
+
|
|
23
|
+
function serialize<T>(work: () => Promise<T>): Promise<T> {
|
|
24
|
+
const result = state.queue.then(work)
|
|
25
|
+
state.queue = result.then(() => undefined, () => undefined)
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function reconcile(inventoryChanged: boolean) {
|
|
30
|
+
const active = [...state.registries]
|
|
31
|
+
const results = await Promise.allSettled(active.map((reload) => reload(inventoryChanged)))
|
|
32
|
+
if (results.some((result, index) => result.status === "rejected" && state.registries.has(active[index]))) {
|
|
33
|
+
throw new Error("Could not refresh all Clockify connections. Use /reload to retry.")
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default Plugin.define({
|
|
38
|
+
id: pluginID,
|
|
39
|
+
setup(ctx) {
|
|
40
|
+
return serialize(async () => {
|
|
41
|
+
state.accounts = accountList.parse((await ctx.storage.get(storageKey)) ?? [])
|
|
42
|
+
let credentials = new Map<string, { key: string; label: string }>()
|
|
43
|
+
|
|
44
|
+
await ctx.integration.transform((editor) => {
|
|
45
|
+
for (const { name, alias } of state.accounts) {
|
|
46
|
+
editor.update(name, (integration) => { integration.name = `Clockify: ${alias}` })
|
|
47
|
+
editor.method.update({ integrationID: name, method: { type: "key", label: "Clockify API key" } })
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
async function loadCredentials() {
|
|
52
|
+
const next = new Map<string, { key: string; label: string }>()
|
|
53
|
+
await Promise.all(state.accounts.map(async ({ name }) => {
|
|
54
|
+
const connection = await ctx.integration.connection.active(name)
|
|
55
|
+
if (connection?.type !== "credential") return
|
|
56
|
+
const value = await ctx.integration.connection.resolve(connection)
|
|
57
|
+
if (value?.type === "key" && typeof value.metadata?.clockifyUserID === "string") {
|
|
58
|
+
next.set(name, { key: value.key, label: connection.label })
|
|
59
|
+
}
|
|
60
|
+
}))
|
|
61
|
+
credentials = next
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await loadCredentials()
|
|
65
|
+
await ctx.mcp.transform((editor) => {
|
|
66
|
+
for (const { name, region, enabled } of state.accounts) {
|
|
67
|
+
const credential = credentials.get(name)
|
|
68
|
+
if (!credential) continue
|
|
69
|
+
editor.set(name, {
|
|
70
|
+
type: "remote",
|
|
71
|
+
url: endpoint,
|
|
72
|
+
protocol: "legacy",
|
|
73
|
+
oauth: false,
|
|
74
|
+
headers: {
|
|
75
|
+
"x-api-key": credential.key,
|
|
76
|
+
...(region === "global" ? {} : { region }),
|
|
77
|
+
},
|
|
78
|
+
disabled: !enabled,
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
await ctx.permission.hook("evaluate", (event) => {
|
|
84
|
+
const account = state.accounts.find(({ name }) => event.action.startsWith(`${name}_`))
|
|
85
|
+
if (!account || readTools.has(event.action.slice(account.name.length + 1))) return
|
|
86
|
+
event.effect = "ask"
|
|
87
|
+
event.message = `Approve this Clockify action for ${account.alias}.`
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
await ctx.session.hook("context", (event) => {
|
|
91
|
+
const accounts = state.accounts.filter(({ enabled, name }) => enabled && credentials.has(name))
|
|
92
|
+
if (!accounts.length) return
|
|
93
|
+
event.system.push({
|
|
94
|
+
type: "text",
|
|
95
|
+
text: [
|
|
96
|
+
"Clockify accounts are independent. Select the named account and workspace for each operation.",
|
|
97
|
+
...accounts.map(({ alias, name, region }) => `- ${alias} (${region}): ${name}`),
|
|
98
|
+
"If more than one Clockify account is available and the intended account is ambiguous, ask before calling a tool. Report an unavailable account instead of falling back to another.",
|
|
99
|
+
"Keep report date ranges bounded. Change Clockify data only when the user explicitly requests the change. If a write times out, check whether it took effect before retrying.",
|
|
100
|
+
].join("\n"),
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
async function reload(inventoryChanged: boolean) {
|
|
105
|
+
if (inventoryChanged) await ctx.integration.reload()
|
|
106
|
+
await loadCredentials()
|
|
107
|
+
await ctx.mcp.reload()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const registration = await ctx.rpc.register(ClockifyAccounts, {
|
|
111
|
+
list: async () => ({
|
|
112
|
+
accounts: state.accounts.map((account) => {
|
|
113
|
+
const credential = credentials.get(account.name)
|
|
114
|
+
return credential ? { ...account, identity: credential.label } : account
|
|
115
|
+
}),
|
|
116
|
+
}),
|
|
117
|
+
add: ({ alias, region }, rpc) => serialize(async () => {
|
|
118
|
+
if (state.accounts.some((account) => account.alias === alias)) {
|
|
119
|
+
return rpc.error("account_error", `The alias "${alias}" already exists.`, {})
|
|
120
|
+
}
|
|
121
|
+
const account = { alias, region, name: `clockify_${alias}_${randomBytes(6).toString("hex")}`, enabled: true }
|
|
122
|
+
await save([...state.accounts, account], true)
|
|
123
|
+
return account
|
|
124
|
+
}),
|
|
125
|
+
enable: ({ name, enabled }, rpc) => serialize(async () => {
|
|
126
|
+
if (!state.accounts.some((account) => account.name === name)) {
|
|
127
|
+
return rpc.error("account_error", "This account was removed in another window.", {})
|
|
128
|
+
}
|
|
129
|
+
await save(state.accounts.map((account) => account.name === name ? { ...account, enabled } : account), false)
|
|
130
|
+
return {}
|
|
131
|
+
}),
|
|
132
|
+
remove: ({ name }, rpc) => serialize(async () => {
|
|
133
|
+
if (await ctx.integration.connection.active(name)) {
|
|
134
|
+
return rpc.error("account_error", "Sign out before removing this account.", {})
|
|
135
|
+
}
|
|
136
|
+
await save(state.accounts.filter((account) => account.name !== name), true)
|
|
137
|
+
return {}
|
|
138
|
+
}),
|
|
139
|
+
verify: async ({ name, key }, rpc) => {
|
|
140
|
+
const account = state.accounts.find((account) => account.name === name)
|
|
141
|
+
if (!account) return rpc.error("account_error", "This account no longer exists.", {})
|
|
142
|
+
try {
|
|
143
|
+
const identity = await verifyKey(account.region, key, rpc.signal)
|
|
144
|
+
return identity ?? rpc.error("account_error", "Clockify rejected the API key. Check the key and data region.", {})
|
|
145
|
+
} catch {
|
|
146
|
+
return rpc.error("account_error", "Could not verify the API key with Clockify. Try again.", {})
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
refresh: () => serialize(async () => {
|
|
150
|
+
await reconcile(false)
|
|
151
|
+
await notify()
|
|
152
|
+
return {}
|
|
153
|
+
}),
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
async function notify() {
|
|
157
|
+
await registration.events.emit("changed", {}).catch(() => undefined)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function save(next: Account[], inventoryChanged: boolean) {
|
|
161
|
+
await ctx.storage.set(storageKey, next)
|
|
162
|
+
state.accounts = next
|
|
163
|
+
try {
|
|
164
|
+
await reconcile(inventoryChanged)
|
|
165
|
+
} finally {
|
|
166
|
+
await notify()
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const events = new AbortController()
|
|
171
|
+
state.registries.add(reload)
|
|
172
|
+
// Each location updates its own credential snapshot after external changes.
|
|
173
|
+
void (async () => {
|
|
174
|
+
for await (const event of ctx.event.subscribe({ types: ["credential.updated", "credential.switched"], signal: events.signal })) {
|
|
175
|
+
if (!state.accounts.some(({ name }) => name === event.data.integrationID)) continue
|
|
176
|
+
await serialize(async () => {
|
|
177
|
+
if (!events.signal.aborted) await reload(false)
|
|
178
|
+
}).catch(() => undefined)
|
|
179
|
+
}
|
|
180
|
+
})().catch(() => undefined)
|
|
181
|
+
|
|
182
|
+
return () => {
|
|
183
|
+
events.abort()
|
|
184
|
+
state.registries.delete(reload)
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
},
|
|
188
|
+
})
|
package/src/rpc.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Rpc } from "@opencode/plugin/rpc"
|
|
2
|
+
import { z } from "zod"
|
|
3
|
+
|
|
4
|
+
export const pluginID = "opencode-clockify-plugin"
|
|
5
|
+
export const aliasPattern = /^[a-z][a-z0-9-]{1,23}$/
|
|
6
|
+
export const aliasHint = "Use 2–24 lowercase letters, numbers, or hyphens, starting with a letter."
|
|
7
|
+
export const regions = ["global", "EU", "USA", "UK", "AU"] as const
|
|
8
|
+
export type Region = (typeof regions)[number]
|
|
9
|
+
|
|
10
|
+
const alias = z.string().regex(aliasPattern, aliasHint)
|
|
11
|
+
const name = z.string().regex(/^clockify_[a-z][a-z0-9-]{1,23}_[a-f0-9]{12}$/)
|
|
12
|
+
const region = z.enum(regions)
|
|
13
|
+
const account = z.strictObject({ alias, name, region, enabled: z.boolean() })
|
|
14
|
+
export type Account = z.infer<typeof account>
|
|
15
|
+
export const accountList = z.array(account)
|
|
16
|
+
|
|
17
|
+
const empty = z.strictObject({})
|
|
18
|
+
const accountName = z.strictObject({ name })
|
|
19
|
+
const errors = { account_error: empty }
|
|
20
|
+
|
|
21
|
+
export const ClockifyAccounts = Rpc.define({
|
|
22
|
+
id: pluginID,
|
|
23
|
+
methods: {
|
|
24
|
+
list: {
|
|
25
|
+
input: empty,
|
|
26
|
+
output: z.strictObject({ accounts: z.array(account.extend({ identity: z.string().optional() })) }),
|
|
27
|
+
},
|
|
28
|
+
add: { input: z.strictObject({ alias, region }), output: account, errors },
|
|
29
|
+
enable: { input: accountName.extend({ enabled: z.boolean() }), output: empty, errors },
|
|
30
|
+
remove: { input: accountName, output: empty, errors },
|
|
31
|
+
verify: {
|
|
32
|
+
input: accountName.extend({ key: z.string().min(1).max(512).regex(/^[\x21-\x7e]+$/) }),
|
|
33
|
+
output: z.strictObject({ id: z.string(), label: z.string() }),
|
|
34
|
+
errors,
|
|
35
|
+
},
|
|
36
|
+
refresh: { input: empty, output: empty },
|
|
37
|
+
},
|
|
38
|
+
events: { changed: { schema: empty } },
|
|
39
|
+
})
|