@morozinc/opencode-tencentdb-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.
Files changed (38) hide show
  1. package/LICENSE +661 -0
  2. package/LICENSE-MIT +24 -0
  3. package/NOTICE.md +14 -0
  4. package/README.md +207 -2
  5. package/dist/gui-experimental.cjs +64 -0
  6. package/dist/integration.mjs +1986 -0
  7. package/docs/screenshots/code-indexes.png +0 -0
  8. package/package.json +61 -4
  9. package/scripts/prepare-runtime.mjs +298 -0
  10. package/src/binding.ts +33 -0
  11. package/src/bmad-artifact-preview.tsx +111 -0
  12. package/src/embedding-settings.tsx +191 -0
  13. package/src/gui.tsx +388 -0
  14. package/src/index.ts +484 -0
  15. package/src/integration.d.ts +75 -0
  16. package/src/rpc.ts +195 -0
  17. package/src/rule-document.ts +44 -0
  18. package/src/rules-contract.ts +77 -0
  19. package/src/rules.ts +237 -0
  20. package/src/runtime.ts +436 -0
  21. package/vendor/TENCENT-LICENSE +27 -0
  22. package/vendor/integration/native/config.ts +253 -0
  23. package/vendor/integration/native/embedding.ts +270 -0
  24. package/vendor/integration/native/index.ts +265 -0
  25. package/vendor/integration/project/index.ts +151 -0
  26. package/vendor/integration/project/knowledge.ts +283 -0
  27. package/vendor/integration/server.ts +154 -0
  28. package/vendor/integration/tencentChatRules.ts +84 -0
  29. package/vendor/integration/tencentGenerationContext.ts +4 -0
  30. package/vendor/integration/tencentKnowledgeClient.ts +512 -0
  31. package/vendor/integration/tencentMemoryClient.ts +391 -0
  32. package/vendor/integration/tencentUserQuestion.ts +51 -0
  33. package/vendor/locks/MemoryCore.json +4776 -0
  34. package/vendor/locks/MemoryKnowledge.json +3761 -0
  35. package/vendor/locks/MemoryPanel.json +467 -0
  36. package/vendor/locks/web.json +6418 -0
  37. package/vendor/provenance.json +21 -0
  38. package/vendor/runner.mjs +12 -0
package/LICENSE-MIT ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Moroz Inc.
4
+
5
+ This license applies to original plugin code owned by Moroz Inc. See LICENSE
6
+ and NOTICE.md for the terms of the combined plugin and reused upstream code.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
package/NOTICE.md ADDED
@@ -0,0 +1,14 @@
1
+ # Reused integration code
2
+
3
+ This independent OpenCode plugin reuses the Tencent memory clients, MCP schemas,
4
+ project indexing helpers, and native service lifecycle from ShiftHackZ/ellmsha-AionUi.
5
+ They are included as source under `vendor/integration`, with adaptations at the host
6
+ boundary. Source revisions and original file hashes are in `vendor/provenance.json`.
7
+ Original eLLMsha material is AGPL-3.0-only. See `LICENSE`.
8
+
9
+ TencentDB Agent Memory is separately MIT licensed. Its notice is retained in
10
+ `vendor/TENCENT-LICENSE`. The pinned Tencent fork includes the existing memory
11
+ retrieval, rule mutation, and model callback changes. The plugin adds no dependency
12
+ on the eLLMsha application, its backend, or its user profile.
13
+
14
+ Node and runtime package dependencies retain their upstream licenses.
package/README.md CHANGED
@@ -1,3 +1,208 @@
1
- # Temporary Holding Version
1
+ # TencentDB Memory for OpenCode
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TencentDB Memory adds local project memory, standing rules, and code search to
4
+ OpenCode V2. OpenCode runs the pinned TencentDB Agent Memory services locally
5
+ using the bundled adapters.
6
+
7
+ ## Install from npm
8
+
9
+ Requires OpenCode V2, Node.js 22.20+, npm, Git, and Ollama with `bge-m3`
10
+ for local vector search. Prepare the runtime on the machine running the
11
+ OpenCode server. It lives outside the installed package.
12
+
13
+ ```sh
14
+ ollama pull bge-m3
15
+ npm exec --package=@morozinc/opencode-tencentdb-plugin@0.1.0 -- \
16
+ opencode-tencentdb-prepare --runtime-root "$HOME/.local/share/opencode/tencentdb-runtime/0.1.0"
17
+ ```
18
+
19
+ Add this entry to `plugins` in your global OpenCode `opencode.json(c)`.
20
+ Replace `runtimeDir` with the absolute path printed by the command.
21
+
22
+ ```jsonc
23
+ {
24
+ "plugins": [
25
+ {
26
+ "package": "@morozinc/opencode-tencentdb-plugin@0.1.0",
27
+ "options": {
28
+ "runtimeDir": "/absolute/path/to/tencentdb-runtime/0.1.0/darwin-arm64",
29
+ },
30
+ },
31
+ ],
32
+ }
33
+ ```
34
+
35
+ Run the preparation command again with a new runtime directory when upgrading
36
+ to a release that changes the pinned runtime. Reload OpenCode after switching
37
+ the configured package or runtime path.
38
+
39
+ ## Build from source
40
+
41
+ Requires OpenCode **2.4.3**, Node **22.20+**, npm, and Git. The Desktop UI uses
42
+ OpenCode’s experimental GUI plugin API. For local vector search, run Ollama
43
+ with `bge-m3` (1024 dimensions):
44
+
45
+ ```sh
46
+ ollama pull bge-m3
47
+ npm ci
48
+ npm run build
49
+ npm run prepare:runtime
50
+ ```
51
+
52
+ `prepare:runtime` downloads the pinned Tencent source, verifies the bundled Node
53
+ distribution against its official checksum, installs locked dependencies, and
54
+ builds the panel. Run it once for each target OS and architecture. The prepared
55
+ macOS arm64 runtime takes about 1.2 GiB.
56
+
57
+ Add this directory to `plugins` in your **global** `~/.config/opencode/opencode.json(c)`, keeping your other entries:
58
+
59
+ ```jsonc
60
+ {
61
+ "plugins": ["/absolute/path/to/opencode-tencentdb-plugin"],
62
+ }
63
+ ```
64
+
65
+ Or choose an independent data directory (use identical settings in every project):
66
+
67
+ ```jsonc
68
+ {
69
+ "plugins": [
70
+ {
71
+ "package": "/absolute/path/to/opencode-tencentdb-plugin",
72
+ "options": { "dataDir": "/absolute/path/to/private-opencode-memory" },
73
+ },
74
+ ],
75
+ }
76
+ ```
77
+
78
+ Use `runtimeDir` to point to a prepared runtime. Set `projectless: true` to
79
+ limit a location to global memory. Git projects use their canonical root.
80
+ Folders that OpenCode assigns to its global project only get global memory.
81
+
82
+ ## Usage
83
+
84
+ Open **Settings > Tencent Memory** or run **Open Tencent Memory**. From a local
85
+ project session, you can also open **Tencent Memory** in the side panel.
86
+
87
+ - **Memory Hub** opens Tencent’s Chat Memory, Wiki, Skills, and Code Graph in
88
+ OpenCode. The embedded hub can see the whole local database. Agent tools
89
+ still follow their scope rules. Skills in the hub are separate from OpenCode
90
+ skills and slash commands.
91
+ - **Code Indexes** finds Git repositories within three folder levels of the
92
+ current workspace. Index one repository or choose **Index all**. Use
93
+ **Refresh** to check progress and errors.
94
+ - **Settings** shows the local runtime and lets you change the embedding
95
+ endpoint, model, and dimensions.
96
+
97
+ ![Tencent Memory Code Indexes tab showing the discovered weather widget demo repository](docs/screenshots/code-indexes.png)
98
+
99
+ ### Change the embedding model
100
+
101
+ The default is Ollama’s OpenAI-compatible `http://127.0.0.1:11434/v1` with
102
+ `bge-m3` and 1024 dimensions. Enter the endpoint, model, and optional API key,
103
+ check the connection, then choose **Rebuild index**. The plugin pauses the
104
+ services while it builds a new index. It switches over after success and keeps
105
+ the previous index and settings as a backup. If the rebuild fails, it restores
106
+ the previous configuration.
107
+
108
+ ## Runtime and storage
109
+
110
+ The OpenCode server starts Core, Knowledge, and Panel. Its locations share the
111
+ same runtime, and the services stop when the last location unloads or the
112
+ server exits. Closing a Desktop window leaves the services running if the
113
+ server is still up. Use standalone mode to give a terminal session its own
114
+ server. Setup leaves no separate daemon or system service.
115
+
116
+ Services listen on loopback. Memory lives under
117
+ `$XDG_DATA_HOME/opencode/tencentdb-plugin` or
118
+ `~/.local/share/opencode/tencentdb-plugin`. A lock keeps two OpenCode servers
119
+ from opening the same database. A restart can reclaim a dead server’s lock.
120
+ The source files and SQLite database are the local source of truth. Keep the
121
+ data directory private. It does not provide encrypted credential storage.
122
+
123
+ When TencentDB needs a model for synthesis, OpenCode uses the provider and
124
+ model selected in the originating chat. The request runs without tools or a
125
+ fallback model. TencentDB receives a short-lived loopback callback, so the
126
+ job ends if its OpenCode server exits.
127
+
128
+ ## Agent behavior and tools
129
+
130
+ OpenCode loads all active global and current-project rules before accepting a
131
+ prompt and sending model requests. It checks the source and revision of each
132
+ rule, then sends them as one section. If loading fails or the rules are too
133
+ large, the request stops. The agent gets the rules in context and can skip
134
+ calling `tdai_rules_read` again for that request. Normal OpenCode permissions
135
+ still govern actions.
136
+
137
+ [TencentDB Rules](https://github.com/ShiftHackZ/opencode-tencentdb-rules-plugin) edits the same
138
+ rules through `rulesList`, `rulesChange`, and `rulesHistory`. Its load history
139
+ shows the last ten changes to the exact rules sent to the session, along with
140
+ the request type. Update both plugins together. OpenCode continues to manage
141
+ repository skills, `AGENTS.md`, and `CLAUDE.md`.
142
+
143
+ TencentDB also searches for a limited amount of relevant history for primary
144
+ requests. If that search fails, the agent is told. The agent saves durable
145
+ memory through explicit tool calls. Chat transcripts aren’t archived
146
+ automatically.
147
+
148
+ The tools are available under OpenCode’s `tencentdb` Code Mode namespace:
149
+
150
+ - Memory: `tdai_context`, `tdai_memory_search`, `tdai_memory_write`, `tdai_core_read`.
151
+ - Documents: `tdai_scenario_list`, `tdai_scenario_read`, `tdai_scenario_write`.
152
+ - Standing rules: `tdai_rules_read`, `tdai_global_rule_write`, `tdai_global_rule_delete`, `tdai_project_rule_write`, `tdai_project_rule_delete`.
153
+ - Wiki: `tdai_knowledge_catalog`, `tdai_wiki_ingest`, `tdai_wiki_search`, `tdai_wiki_read`.
154
+ - Code: `tdai_code_index`, `tdai_code_search`, `tdai_code_explore`, `tdai_code_impact`, `tdai_project_repositories`, `tdai_project_index`, `tdai_project_code_search`, `tdai_code_runtime`.
155
+ - Questions use OpenCode’s native question tool.
156
+
157
+ ### Scopes and permissions
158
+
159
+ - Memory search defaults to the current project plus global memory. Use
160
+ `scope: "all"` to search across projects and check `source_scope` and
161
+ `source_project` before using a result. You can list and read documents
162
+ from other projects. Memory and document writes target the current project
163
+ or global scope. Code graphs stay scoped to the project.
164
+ - Project IDs depend on the canonical path. Copying a repository to a new
165
+ folder gives it a new scope. Wikis are shared globally, so keep private
166
+ project material in project memory or documents.
167
+ - In TencentDB storage mode, BMAD saves documents under `bmad/<project-scope>/`
168
+ through the document tools. Use the rule tools for standing instructions.
169
+ Rule edits and deletions check the saved revision.
170
+ - Writes go through OpenCode’s permission system. The upstream
171
+ `tdai_conversation_add/search` tools are unavailable because the upstream
172
+ archive lacks a reliable project boundary.
173
+
174
+ Runtime preparation supports Node platforms, but process and vector checks
175
+ have only run on macOS arm64. Live vendor inference and interactive runtime
176
+ checks on Windows and Linux are unverified.
177
+
178
+ ## Checks and provenance
179
+
180
+ ```sh
181
+ npm run check
182
+ npm run build
183
+ npm test # real local Tencent + Ollama bge-m3
184
+ node --import tsx tests/opencode-smoke.mjs # owned private OpenCode 2.4.3
185
+ TENCENT_QA_CRASH=1 node --import tsx tests/opencode-smoke.mjs
186
+ ```
187
+
188
+ The tests create disposable profiles under `.test-data` without using your
189
+ OpenCode profile or provider credentials. Set `OPENCODE_QA_BINARY` to use a
190
+ different executable for the smoke test.
191
+
192
+ The Tencent revision and adapter hashes are in
193
+ [`vendor/provenance.json`](vendor/provenance.json). Dependency locks are in
194
+ [`vendor/locks`](vendor/locks). To reuse a clean source checkout, pass
195
+ `prepare:runtime -- --source /clean/pinned/tencent-checkout`. Add
196
+ `--dependency-cache /prepared/platform/runtime` to reuse dependencies with
197
+ matching locks. Git ignores the runtime, cache, `node_modules`, and test
198
+ profiles.
199
+
200
+ ## License and credits
201
+
202
+ Developed by [Moroz Inc.](https://moroz.cc). The original Moroz Inc. plugin code
203
+ is available under the [MIT License](LICENSE-MIT). The combined plugin and reused
204
+ adapters remain [AGPL-3.0-only](LICENSE). TencentDB Agent Memory retains
205
+ its [own MIT license](vendor/TENCENT-LICENSE). See [NOTICE.md](NOTICE.md) for
206
+ upstream credits.
207
+
208
+ This project is not affiliated with OpenCode or Anomaly.
@@ -0,0 +1,64 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("solid-js/web"),N=require("@opencode/plugin/gui"),b=require("solid-js"),tn=require("@opencode/plugin/rpc");var Ue;function l(e,t,n){function r(c,a){if(c._zod||Object.defineProperty(c,"_zod",{value:{def:a,constr:i,traits:new Set},enumerable:!1}),c._zod.traits.has(e))return;c._zod.traits.add(e),t(c,a);const d=i.prototype,p=Object.keys(d);for(let _=0;_<p.length;_++){const g=p[_];g in c||(c[g]=d[g].bind(c))}}const o=n?.Parent??Object;class s extends o{}Object.defineProperty(s,"name",{value:e});function i(c){var a;const d=n?.Parent?new s:this;r(d,c),(a=d._zod).deferred??(a.deferred=[]);for(const p of d._zod.deferred)p();return d}return Object.defineProperty(i,"init",{value:r}),Object.defineProperty(i,Symbol.hasInstance,{value:c=>n?.Parent&&c instanceof n.Parent?!0:c?._zod?.traits?.has(e)}),Object.defineProperty(i,"name",{value:e}),i}class K 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"}}(Ue=globalThis).__zod_globalConfig??(Ue.__zod_globalConfig={});const Ee=globalThis.__zod_globalConfig;function L(e){return Ee}function mt(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 ke(e,t){return typeof t=="bigint"?t.toString():t}function ge(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function Ce(e){return e==null}function Pe(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function nn(e,t){const n=e/t,r=Math.round(n),o=Number.EPSILON*Math.max(Math.abs(n),1);return Math.abs(n-r)<o?0:n-r}const Fe=Symbol("evaluating");function w(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Fe)return r===void 0&&(r=Fe,r=n()),r},set(o){Object.defineProperty(e,t,{value:o})},configurable:!0})}function V(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function M(...e){const t={};for(const n of e){const r=Object.getOwnPropertyDescriptors(n);Object.assign(t,r)}return Object.defineProperties({},t)}function Le(e){return JSON.stringify(e)}function rn(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const gt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ee(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const on=ge(()=>{if(Ee.jitless||typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function te(e){if(ee(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(ee(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function _t(e){return te(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const sn=new Set(["string","number","symbol"]);function q(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function U(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function m(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 cn(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const an={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]};function un(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 s=M(e._zod.def,{get shape(){const i={};for(const c in t){if(!(c in n.shape))throw new Error(`Unrecognized key: "${c}"`);t[c]&&(i[c]=n.shape[c])}return V(this,"shape",i),i},checks:[]});return U(e,s)}function ln(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 s=M(e._zod.def,{get shape(){const i={...e._zod.def.shape};for(const c in t){if(!(c in n.shape))throw new Error(`Unrecognized key: "${c}"`);t[c]&&delete i[c]}return V(this,"shape",i),i},checks:[]});return U(e,s)}function dn(e,t){if(!te(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const s=e._zod.def.shape;for(const i in t)if(Object.getOwnPropertyDescriptor(s,i)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const o=M(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return V(this,"shape",s),s}});return U(e,o)}function pn(e,t){if(!te(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=M(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t};return V(this,"shape",r),r}});return U(e,n)}function fn(e,t){if(e._zod.def.checks?.length)throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");const n=M(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t._zod.def.shape};return V(this,"shape",r),r},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return U(e,n)}function hn(e,t,n){const o=t._zod.def.checks;if(o&&o.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const i=M(t._zod.def,{get shape(){const c=t._zod.def.shape,a={...c};if(n)for(const d in n){if(!(d in c))throw new Error(`Unrecognized key: "${d}"`);n[d]&&(a[d]=e?new e({type:"optional",innerType:c[d]}):c[d])}else for(const d in c)a[d]=e?new e({type:"optional",innerType:c[d]}):c[d];return V(this,"shape",a),a},checks:[]});return U(t,i)}function mn(e,t,n){const r=M(t._zod.def,{get shape(){const o=t._zod.def.shape,s={...o};if(n)for(const i in n){if(!(i in s))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(s[i]=new e({type:"nonoptional",innerType:o[i]}))}else for(const i in o)s[i]=new e({type:"nonoptional",innerType:o[i]});return V(this,"shape",s),s}});return U(t,r)}function G(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 gn(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 vt(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function ae(e){return typeof e=="string"?e:e?.message}function J(e,t,n){const r=e.message?e.message:ae(e.inst?._zod.def?.error?.(e))??ae(t?.error?.(e))??ae(n.customError?.(e))??ae(n.localeError?.(e))??"Invalid input",{inst:o,continue:s,input:i,...c}=e;return c.path??(c.path=[]),c.message=r,t?.reportInput&&(c.input=i),c}function Te(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function ne(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}const bt=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,ke,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},yt=l("$ZodError",bt),wt=l("$ZodError",bt,{Parent:Error});function _n(e,t=n=>n.message){const n={},r=[];for(const o of e.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(t(o))):r.push(t(o));return{formErrors:r,fieldErrors:n}}function vn(e,t=n=>n.message){const n={_errors:[]},r=(o,s=[])=>{for(const i of o.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(c=>r({issues:c},[...s,...i.path]));else if(i.code==="invalid_key")r({issues:i.issues},[...s,...i.path]);else if(i.code==="invalid_element")r({issues:i.issues},[...s,...i.path]);else{const c=[...s,...i.path];if(c.length===0)n._errors.push(t(i));else{let a=n,d=0;for(;d<c.length;){const p=c[d];d===c.length-1?(a[p]=a[p]||{_errors:[]},a[p]._errors.push(t(i))):a[p]=a[p]||{_errors:[]},a=a[p],d++}}}};return r(e),n}const xe=e=>(t,n,r,o)=>{const s=r?{...r,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new K;if(i.issues.length){const c=new(o?.Err??e)(i.issues.map(a=>J(a,s,L())));throw gt(c,o?.callee),c}return i.value},Ae=e=>async(t,n,r,o)=>{const s=r?{...r,async:!0}:{async:!0};let i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise&&(i=await i),i.issues.length){const c=new(o?.Err??e)(i.issues.map(a=>J(a,s,L())));throw gt(c,o?.callee),c}return i.value},_e=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new K;return s.issues.length?{success:!1,error:new(e??yt)(s.issues.map(i=>J(i,o,L())))}:{success:!0,data:s.value}},bn=_e(wt),ve=e=>async(t,n,r)=>{const o=r?{...r,async:!0}:{async:!0};let s=t._zod.run({value:n,issues:[]},o);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new e(s.issues.map(i=>J(i,o,L())))}:{success:!0,data:s.value}},yn=ve(wt),wn=e=>(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return xe(e)(t,n,o)},zn=e=>(t,n,r)=>xe(e)(t,n,r),$n=e=>async(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return Ae(e)(t,n,o)},kn=e=>async(t,n,r)=>Ae(e)(t,n,r),Sn=e=>(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return _e(e)(t,n,o)},Zn=e=>(t,n,r)=>_e(e)(t,n,r),On=e=>async(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return ve(e)(t,n,o)},In=e=>async(t,n,r)=>ve(e)(t,n,r),En=/^[cC][0-9a-z]{6,}$/,Cn=/^[0-9a-z]+$/,Pn=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Tn=/^[0-9a-vA-V]{20}$/,xn=/^[A-Za-z0-9]{27}$/,An=/^[a-zA-Z0-9_-]{21}$/,Nn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,jn=/^([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})$/,Je=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)$/,Rn=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Dn="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Mn(){return new RegExp(Dn,"u")}const Un=/^(?:(?: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])$/,Fn=/^(([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}|:))$/,Ln=/^((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])$/,Jn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Bn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,zt=/^[A-Za-z0-9_-]*$/,Vn=/^https?$/,Wn=/^\+[1-9]\d{6,14}$/,$t="(?:(?:\\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])))",Gn=new RegExp(`^${$t}$`);function kt(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}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Kn(e){return new RegExp(`^${kt(e)}$`)}function qn(e){const t=kt({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${$t}T(?:${r})$`)}const Hn=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},Yn=/^-?\d+$/,Xn=/^-?\d+(?:\.\d+)?$/,Qn=/^(?:true|false)$/i,er=/^[^A-Z]*$/,tr=/^[^a-z]*$/,x=l("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),St={number:"number",bigint:"bigint",object:"date"},Zt=l("$ZodCheckLessThan",(e,t)=>{x.init(e,t);const n=St[typeof t.value];e._zod.onattach.push(r=>{const o=r._zod.bag,s=(t.inclusive?o.maximum:o.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<s&&(t.inclusive?o.maximum=t.value:o.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ot=l("$ZodCheckGreaterThan",(e,t)=>{x.init(e,t);const n=St[typeof t.value];e._zod.onattach.push(r=>{const o=r._zod.bag,s=(t.inclusive?o.minimum:o.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>s&&(t.inclusive?o.minimum=t.value:o.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),nr=l("$ZodCheckMultipleOf",(e,t)=>{x.init(e,t),e._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):nn(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),rr=l("$ZodCheckNumberFormat",(e,t)=>{x.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[o,s]=an[t.format];e._zod.onattach.push(i=>{const c=i._zod.bag;c.format=t.format,c.minimum=o,c.maximum=s,n&&(c.pattern=Yn)}),e._zod.check=i=>{const c=i.value;if(n){if(!Number.isInteger(c)){i.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){c>0?i.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}):i.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}c<o&&i.issues.push({origin:"number",input:c,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort}),c>s&&i.issues.push({origin:"number",input:c,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}}),or=l("$ZodCheckMaxLength",(e,t)=>{var n;x.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!Ce(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<o&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{const o=r.value;if(o.length<=t.maximum)return;const i=Te(o);r.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),ir=l("$ZodCheckMinLength",(e,t)=>{var n;x.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!Ce(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>o&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{const o=r.value;if(o.length>=t.minimum)return;const i=Te(o);r.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),sr=l("$ZodCheckLengthEquals",(e,t)=>{var n;x.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!Ce(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag;o.minimum=t.length,o.maximum=t.length,o.length=t.length}),e._zod.check=r=>{const o=r.value,s=o.length;if(s===t.length)return;const i=Te(o),c=s>t.length;r.issues.push({origin:i,...c?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),be=l("$ZodCheckStringFormat",(e,t)=>{var n,r;x.init(e,t),e._zod.onattach.push(o=>{const s=o._zod.bag;s.format=t.format,t.pattern&&(s.patterns??(s.patterns=new Set),s.patterns.add(t.pattern))}),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=()=>{})}),cr=l("$ZodCheckRegex",(e,t)=>{be.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})}}),ar=l("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=er),be.init(e,t)}),ur=l("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=tr),be.init(e,t)}),lr=l("$ZodCheckIncludes",(e,t)=>{x.init(e,t);const n=q(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(o=>{const s=o._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(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})}}),dr=l("$ZodCheckStartsWith",(e,t)=>{x.init(e,t);const n=new RegExp(`^${q(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(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})}}),pr=l("$ZodCheckEndsWith",(e,t)=>{x.init(e,t);const n=new RegExp(`.*${q(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(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})}}),fr=l("$ZodCheckOverwrite",(e,t)=>{x.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class hr{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const r=t.split(`
2
+ `).filter(i=>i),o=Math.min(...r.map(i=>i.length-i.trimStart().length)),s=r.map(i=>i.slice(o)).map(i=>" ".repeat(this.indent*2)+i);for(const i of s)this.content.push(i)}compile(){const t=Function,n=this?.args,o=[...(this?.content??[""]).map(s=>` ${s}`)];return new t(...n,o.join(`
3
+ `))}}const mr={major:4,minor:4,patch:0},Z=l("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=mr;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const o of r)for(const s of o._zod.onattach)s(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const o=(i,c,a)=>{let d=G(i),p;for(const _ of c){if(_._zod.def.when){if(gn(i)||!_._zod.def.when(i))continue}else if(d)continue;const g=i.issues.length,f=_._zod.check(i);if(f instanceof Promise&&a?.async===!1)throw new K;if(p||f instanceof Promise)p=(p??Promise.resolve()).then(async()=>{await f,i.issues.length!==g&&(d||(d=G(i,g)))});else{if(i.issues.length===g)continue;d||(d=G(i,g))}}return p?p.then(()=>i):i},s=(i,c,a)=>{if(G(i))return i.aborted=!0,i;const d=o(c,r,a);if(d instanceof Promise){if(a.async===!1)throw new K;return d.then(p=>e._zod.parse(p,a))}return e._zod.parse(d,a)};e._zod.run=(i,c)=>{if(c.skipChecks)return e._zod.parse(i,c);if(c.direction==="backward"){const d=e._zod.parse({value:i.value,issues:[]},{...c,skipChecks:!0});return d instanceof Promise?d.then(p=>s(p,i,c)):s(d,i,c)}const a=e._zod.parse(i,c);if(a instanceof Promise){if(c.async===!1)throw new K;return a.then(d=>o(d,r,c))}return o(a,r,c)}}w(e,"~standard",()=>({validate:o=>{try{const s=bn(e,o);return s.success?{value:s.data}:{issues:s.error?.issues}}catch{return yn(e,o).then(i=>i.success?{value:i.data}:{issues:i.error?.issues})}},vendor:"zod",version:1}))}),Ne=l("$ZodString",(e,t)=>{Z.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Hn(e._zod.bag),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}}),k=l("$ZodStringFormat",(e,t)=>{be.init(e,t),Ne.init(e,t)}),gr=l("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=jn),k.init(e,t)}),_r=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=Je(r))}else t.pattern??(t.pattern=Je());k.init(e,t)}),vr=l("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Rn),k.init(e,t)}),br=l("$ZodURL",(e,t)=>{k.init(e,t),e._zod.check=n=>{try{const r=n.value.trim();if(!t.normalize&&t.protocol?.source===Vn.source&&!/^https?:\/\//i.test(r)){n.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:n.value,inst:e,continue:!t.abort});return}const o=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(o.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&&(t.protocol.lastIndex=0,t.protocol.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=o.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),yr=l("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Mn()),k.init(e,t)}),wr=l("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=An),k.init(e,t)}),zr=l("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=En),k.init(e,t)}),$r=l("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Cn),k.init(e,t)}),kr=l("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Pn),k.init(e,t)}),Sr=l("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Tn),k.init(e,t)}),Zr=l("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=xn),k.init(e,t)}),Or=l("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=qn(t)),k.init(e,t)}),Ir=l("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Gn),k.init(e,t)}),Er=l("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=Kn(t)),k.init(e,t)}),Cr=l("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Nn),k.init(e,t)}),Pr=l("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Un),k.init(e,t),e._zod.bag.format="ipv4"}),Tr=l("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Fn),k.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),xr=l("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Ln),k.init(e,t)}),Ar=l("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Jn),k.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[o,s]=r;if(!s)throw new Error;const i=Number(s);if(`${i}`!==s)throw new Error;if(i<0||i>128)throw new Error;new URL(`http://[${o}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function It(e){if(e==="")return!0;if(/\s/.test(e)||e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const Nr=l("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Bn),k.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{It(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function jr(e){if(!zt.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return It(n)}const Rr=l("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=zt),k.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{jr(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),Dr=l("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Wn),k.init(e,t)});function Mr(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 Ur=l("$ZodJWT",(e,t)=>{k.init(e,t),e._zod.check=n=>{Mr(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Et=l("$ZodNumber",(e,t)=>{Z.init(e,t),e._zod.pattern=e._zod.bag.pattern??Xn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const o=n.value;if(typeof o=="number"&&!Number.isNaN(o)&&Number.isFinite(o))return n;const s=typeof o=="number"?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...s?{received:s}:{}}),n}}),Fr=l("$ZodNumberFormat",(e,t)=>{rr.init(e,t),Et.init(e,t)}),Lr=l("$ZodBoolean",(e,t)=>{Z.init(e,t),e._zod.pattern=Qn,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}}),Jr=l("$ZodUnknown",(e,t)=>{Z.init(e,t),e._zod.parse=n=>n}),Br=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 Be(e,t,n){e.issues.length&&t.issues.push(...vt(n,e.issues)),t.value[n]=e.value}const Vr=l("$ZodArray",(e,t)=>{Z.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),n;n.value=Array(o.length);const s=[];for(let i=0;i<o.length;i++){const c=o[i],a=t.element._zod.run({value:c,issues:[]},r);a instanceof Promise?s.push(a.then(d=>Be(d,n,i))):Be(a,n,i)}return s.length?Promise.all(s).then(()=>n):n}});function fe(e,t,n,r,o,s){const i=n in r;if(e.issues.length){if(o&&s&&!i)return;t.issues.push(...vt(n,e.issues))}if(!i&&!o){e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[n]});return}e.value===void 0?i&&(t.value[n]=void 0):t.value[n]=e.value}function Ct(e){const t=Object.keys(e.shape);for(const r of t)if(!e.shape?.[r]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);const n=cn(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Pt(e,t,n,r,o,s){const i=[],c=o.keySet,a=o.catchall._zod,d=a.def.type,p=a.optin==="optional",_=a.optout==="optional";for(const g in t){if(g==="__proto__"||c.has(g))continue;if(d==="never"){i.push(g);continue}const f=a.run({value:t[g],issues:[]},r);f instanceof Promise?e.push(f.then(h=>fe(h,n,g,t,p,_))):fe(f,n,g,t,p,_)}return i.length&&n.issues.push({code:"unrecognized_keys",keys:i,input:t,inst:s}),e.length?Promise.all(e).then(()=>n):n}const Wr=l("$ZodObject",(e,t)=>{if(Z.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const c=t.shape;Object.defineProperty(t,"shape",{get:()=>{const a={...c};return Object.defineProperty(t,"shape",{value:a}),a}})}const r=ge(()=>Ct(t));w(e._zod,"propValues",()=>{const c=t.shape,a={};for(const d in c){const p=c[d]._zod;if(p.values){a[d]??(a[d]=new Set);for(const _ of p.values)a[d].add(_)}}return a});const o=ee,s=t.catchall;let i;e._zod.parse=(c,a)=>{i??(i=r.value);const d=c.value;if(!o(d))return c.issues.push({expected:"object",code:"invalid_type",input:d,inst:e}),c;c.value={};const p=[],_=i.shape;for(const g of i.keys){const f=_[g],h=f._zod.optin==="optional",P=f._zod.optout==="optional",$=f._zod.run({value:d[g],issues:[]},a);$ instanceof Promise?p.push($.then(W=>fe(W,c,g,d,h,P))):fe($,c,g,d,h,P)}return s?Pt(p,d,c,a,r.value,e):p.length?Promise.all(p).then(()=>c):c}}),Gr=l("$ZodObjectJIT",(e,t)=>{Wr.init(e,t);const n=e._zod.parse,r=ge(()=>Ct(t)),o=g=>{const f=new hr(["shape","payload","ctx"]),h=r.value,P=A=>{const z=Le(A);return`shape[${z}]._zod.run({ value: input[${z}], issues: [] }, ctx)`};f.write("const input = payload.value;");const $=Object.create(null);let W=0;for(const A of h.keys)$[A]=`key_${W++}`;f.write("const newResult = {};");for(const A of h.keys){const z=$[A],I=Le(A),se=g[A],ce=se?._zod?.optin==="optional",y=se?._zod?.optout==="optional";f.write(`const ${z} = ${P(A)};`),ce&&y?f.write(`
4
+ if (${z}.issues.length) {
5
+ if (${I} in input) {
6
+ payload.issues = payload.issues.concat(${z}.issues.map(iss => ({
7
+ ...iss,
8
+ path: iss.path ? [${I}, ...iss.path] : [${I}]
9
+ })));
10
+ }
11
+ }
12
+
13
+ if (${z}.value === undefined) {
14
+ if (${I} in input) {
15
+ newResult[${I}] = undefined;
16
+ }
17
+ } else {
18
+ newResult[${I}] = ${z}.value;
19
+ }
20
+
21
+ `):ce?f.write(`
22
+ if (${z}.issues.length) {
23
+ payload.issues = payload.issues.concat(${z}.issues.map(iss => ({
24
+ ...iss,
25
+ path: iss.path ? [${I}, ...iss.path] : [${I}]
26
+ })));
27
+ }
28
+
29
+ if (${z}.value === undefined) {
30
+ if (${I} in input) {
31
+ newResult[${I}] = undefined;
32
+ }
33
+ } else {
34
+ newResult[${I}] = ${z}.value;
35
+ }
36
+
37
+ `):f.write(`
38
+ const ${z}_present = ${I} in input;
39
+ if (${z}.issues.length) {
40
+ payload.issues = payload.issues.concat(${z}.issues.map(iss => ({
41
+ ...iss,
42
+ path: iss.path ? [${I}, ...iss.path] : [${I}]
43
+ })));
44
+ }
45
+ if (!${z}_present && !${z}.issues.length) {
46
+ payload.issues.push({
47
+ code: "invalid_type",
48
+ expected: "nonoptional",
49
+ input: undefined,
50
+ path: [${I}]
51
+ });
52
+ }
53
+
54
+ if (${z}_present) {
55
+ if (${z}.value === undefined) {
56
+ newResult[${I}] = undefined;
57
+ } else {
58
+ newResult[${I}] = ${z}.value;
59
+ }
60
+ }
61
+
62
+ `)}f.write("payload.value = newResult;"),f.write("return payload;");const Y=f.compile();return(A,z)=>Y(g,A,z)};let s;const i=ee,c=!Ee.jitless,d=c&&on.value,p=t.catchall;let _;e._zod.parse=(g,f)=>{_??(_=r.value);const h=g.value;return i(h)?c&&d&&f?.async===!1&&f.jitless!==!0?(s||(s=o(t.shape)),g=s(g,f),p?Pt([],h,g,f,_,e):g):n(g,f):(g.issues.push({expected:"object",code:"invalid_type",input:h,inst:e}),g)}});function Ve(e,t,n,r){for(const s of e)if(s.issues.length===0)return t.value=s.value,t;const o=e.filter(s=>!G(s));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(s=>s.issues.map(i=>J(i,r,L())))}),t)}const Tt=l("$ZodUnion",(e,t)=>{Z.init(e,t),w(e._zod,"optin",()=>t.options.some(r=>r._zod.optin==="optional")?"optional":void 0),w(e._zod,"optout",()=>t.options.some(r=>r._zod.optout==="optional")?"optional":void 0),w(e._zod,"values",()=>{if(t.options.every(r=>r._zod.values))return new Set(t.options.flatMap(r=>Array.from(r._zod.values)))}),w(e._zod,"pattern",()=>{if(t.options.every(r=>r._zod.pattern)){const r=t.options.map(o=>o._zod.pattern);return new RegExp(`^(${r.map(o=>Pe(o.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 s=!1;const i=[];for(const c of t.options){const a=c._zod.run({value:r.value,issues:[]},o);if(a instanceof Promise)i.push(a),s=!0;else{if(a.issues.length===0)return a;i.push(a)}}return s?Promise.all(i).then(c=>Ve(c,r,e,o)):Ve(i,r,e,o)}}),Kr=l("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,Tt.init(e,t);const n=e._zod.parse;w(e._zod,"propValues",()=>{const o={};for(const s of t.options){const i=s._zod.propValues;if(!i||Object.keys(i).length===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(s)}"`);for(const[c,a]of Object.entries(i)){o[c]||(o[c]=new Set);for(const d of a)o[c].add(d)}}return o});const r=ge(()=>{const o=t.options,s=new Map;for(const i of o){const c=i._zod.propValues?.[t.discriminator];if(!c||c.size===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(i)}"`);for(const a of c){if(s.has(a))throw new Error(`Duplicate discriminator value "${String(a)}"`);s.set(a,i)}}return s});e._zod.parse=(o,s)=>{const i=o.value;if(!ee(i))return o.issues.push({code:"invalid_type",expected:"object",input:i,inst:e}),o;const c=r.value.get(i?.[t.discriminator]);return c?c._zod.run(o,s):t.unionFallback||s.direction==="backward"?n(o,s):(o.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,options:Array.from(r.value.keys()),input:i,path:[t.discriminator],inst:e}),o)}}),qr=l("$ZodIntersection",(e,t)=>{Z.init(e,t),e._zod.parse=(n,r)=>{const o=n.value,s=t.left._zod.run({value:o,issues:[]},r),i=t.right._zod.run({value:o,issues:[]},r);return s instanceof Promise||i instanceof Promise?Promise.all([s,i]).then(([a,d])=>We(n,a,d)):We(n,s,i)}});function Se(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(te(e)&&te(t)){const n=Object.keys(t),r=Object.keys(e).filter(s=>n.indexOf(s)!==-1),o={...e,...t};for(const s of r){const i=Se(e[s],t[s]);if(!i.valid)return{valid:!1,mergeErrorPath:[s,...i.mergeErrorPath]};o[s]=i.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],s=t[r],i=Se(o,s);if(!i.valid)return{valid:!1,mergeErrorPath:[r,...i.mergeErrorPath]};n.push(i.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function We(e,t,n){const r=new Map;let o;for(const c of t.issues)if(c.code==="unrecognized_keys"){o??(o=c);for(const a of c.keys)r.has(a)||r.set(a,{}),r.get(a).l=!0}else e.issues.push(c);for(const c of n.issues)if(c.code==="unrecognized_keys")for(const a of c.keys)r.has(a)||r.set(a,{}),r.get(a).r=!0;else e.issues.push(c);const s=[...r].filter(([,c])=>c.l&&c.r).map(([c])=>c);if(s.length&&o&&e.issues.push({...o,keys:s}),G(e))return e;const i=Se(t.value,n.value);if(!i.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(i.mergeErrorPath)}`);return e.value=i.data,e}const Hr=l("$ZodEnum",(e,t)=>{Z.init(e,t);const n=mt(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(o=>sn.has(typeof o)).map(o=>typeof o=="string"?q(o):o.toString()).join("|")})$`),e._zod.parse=(o,s)=>{const i=o.value;return r.has(i)||o.issues.push({code:"invalid_value",values:n,input:i,inst:e}),o}}),Yr=l("$ZodLiteral",(e,t)=>{if(Z.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(r=>typeof r=="string"?q(r):r?q(r.toString()):String(r)).join("|")})$`),e._zod.parse=(r,o)=>{const s=r.value;return n.has(s)||r.issues.push({code:"invalid_value",values:t.values,input:s,inst:e}),r}}),Xr=l("$ZodTransform",(e,t)=>{Z.init(e,t),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(i=>(n.value=i,n));if(o instanceof Promise)throw new K;return n.value=o,n}});function Ge(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const xt=l("$ZodOptional",(e,t)=>{Z.init(e,t),e._zod.optin="optional",e._zod.optout="optional",w(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),w(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Pe(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(t.innerType._zod.optin==="optional"){const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>Ge(s,n.value)):Ge(o,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,r)}}),Qr=l("$ZodExactOptional",(e,t)=>{xt.init(e,t),w(e._zod,"values",()=>t.innerType._zod.values),w(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,r)=>t.innerType._zod.run(n,r)}),eo=l("$ZodNullable",(e,t)=>{Z.init(e,t),w(e._zod,"optin",()=>t.innerType._zod.optin),w(e._zod,"optout",()=>t.innerType._zod.optout),w(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Pe(n.source)}|null)$`):void 0}),w(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),to=l("$ZodDefault",(e,t)=>{Z.init(e,t),e._zod.optin="optional",w(e._zod,"values",()=>t.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(s=>Ke(s,t)):Ke(o,t)}});function Ke(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const no=l("$ZodPrefault",(e,t)=>{Z.init(e,t),e._zod.optin="optional",w(e._zod,"values",()=>t.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))}),ro=l("$ZodNonOptional",(e,t)=>{Z.init(e,t),w(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>qe(s,e)):qe(o,e)}});function qe(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const oo=l("$ZodCatch",(e,t)=>{Z.init(e,t),w(e._zod,"optin",()=>t.innerType._zod.optin),w(e._zod,"optout",()=>t.innerType._zod.optout),w(e._zod,"values",()=>t.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(n,r);return o instanceof Promise?o.then(s=>(n.value=s.value,s.issues.length&&(n.value=t.catchValue({...n,error:{issues:s.issues.map(i=>J(i,r,L()))},input:n.value}),n.issues=[]),n)):(n.value=o.value,o.issues.length&&(n.value=t.catchValue({...n,error:{issues:o.issues.map(s=>J(s,r,L()))},input:n.value}),n.issues=[]),n)}}),io=l("$ZodPipe",(e,t)=>{Z.init(e,t),w(e._zod,"values",()=>t.in._zod.values),w(e._zod,"optin",()=>t.in._zod.optin),w(e._zod,"optout",()=>t.out._zod.optout),w(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,r)=>{if(r.direction==="backward"){const s=t.out._zod.run(n,r);return s instanceof Promise?s.then(i=>ue(i,t.in,r)):ue(s,t.in,r)}const o=t.in._zod.run(n,r);return o instanceof Promise?o.then(s=>ue(s,t.out,r)):ue(o,t.out,r)}});function ue(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const so=l("$ZodReadonly",(e,t)=>{Z.init(e,t),w(e._zod,"propValues",()=>t.innerType._zod.propValues),w(e._zod,"values",()=>t.innerType._zod.values),w(e._zod,"optin",()=>t.innerType?._zod?.optin),w(e._zod,"optout",()=>t.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(He):He(o)}});function He(e){return e.value=Object.freeze(e.value),e}const co=l("$ZodCustom",(e,t)=>{x.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(s=>Ye(s,n,r,e));Ye(o,n,r,e)}});function Ye(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(ne(o))}}var Xe;class ao{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 uo(){return new ao}(Xe=globalThis).__zod_globalRegistry??(Xe.__zod_globalRegistry=uo());const Q=globalThis.__zod_globalRegistry;function lo(e,t){return new e({type:"string",...m(t)})}function po(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...m(t)})}function Qe(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...m(t)})}function fo(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...m(t)})}function ho(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...m(t)})}function mo(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...m(t)})}function go(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...m(t)})}function At(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...m(t)})}function _o(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...m(t)})}function vo(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...m(t)})}function bo(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...m(t)})}function yo(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...m(t)})}function wo(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...m(t)})}function zo(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...m(t)})}function $o(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...m(t)})}function ko(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...m(t)})}function So(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...m(t)})}function Zo(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...m(t)})}function Oo(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...m(t)})}function Io(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...m(t)})}function Eo(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...m(t)})}function Co(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...m(t)})}function Po(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...m(t)})}function To(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...m(t)})}function xo(e,t){return new e({type:"string",format:"date",check:"string_format",...m(t)})}function Ao(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...m(t)})}function No(e,t){return new e({type:"string",format:"duration",check:"string_format",...m(t)})}function jo(e,t){return new e({type:"number",checks:[],...m(t)})}function Ro(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...m(t)})}function Do(e,t){return new e({type:"boolean",...m(t)})}function Mo(e){return new e({type:"unknown"})}function Uo(e,t){return new e({type:"never",...m(t)})}function et(e,t){return new Zt({check:"less_than",...m(t),value:e,inclusive:!1})}function ye(e,t){return new Zt({check:"less_than",...m(t),value:e,inclusive:!0})}function tt(e,t){return new Ot({check:"greater_than",...m(t),value:e,inclusive:!1})}function we(e,t){return new Ot({check:"greater_than",...m(t),value:e,inclusive:!0})}function nt(e,t){return new nr({check:"multiple_of",...m(t),value:e})}function Nt(e,t){return new or({check:"max_length",...m(t),maximum:e})}function he(e,t){return new ir({check:"min_length",...m(t),minimum:e})}function jt(e,t){return new sr({check:"length_equals",...m(t),length:e})}function Fo(e,t){return new cr({check:"string_format",format:"regex",...m(t),pattern:e})}function Lo(e){return new ar({check:"string_format",format:"lowercase",...m(e)})}function Jo(e){return new ur({check:"string_format",format:"uppercase",...m(e)})}function Bo(e,t){return new lr({check:"string_format",format:"includes",...m(t),includes:e})}function Vo(e,t){return new dr({check:"string_format",format:"starts_with",...m(t),prefix:e})}function Wo(e,t){return new pr({check:"string_format",format:"ends_with",...m(t),suffix:e})}function H(e){return new fr({check:"overwrite",tx:e})}function Go(e){return H(t=>t.normalize(e))}function Ko(){return H(e=>e.trim())}function qo(){return H(e=>e.toLowerCase())}function Ho(){return H(e=>e.toUpperCase())}function Yo(){return H(e=>rn(e))}function Xo(e,t,n){return new e({type:"array",element:t,...m(n)})}function Qo(e,t,n){return new e({type:"custom",check:"custom",fn:t,...m(n)})}function ei(e,t){const n=ti(r=>(r.addIssue=o=>{if(typeof o=="string")r.issues.push(ne(o,r.value,n._zod.def));else{const s=o;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=r.value),s.inst??(s.inst=n),s.continue??(s.continue=!n._zod.def.abort),r.issues.push(ne(s))}},e(r.value,r)),t);return n}function ti(e,t){const n=new x({check:"custom",...m(t)});return n._zod.check=e,n}function Rt(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??Q,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function C(e,t,n={path:[],schemaPath:[]}){var r;const o=e._zod.def,s=t.seen.get(e);if(s)return s.count++,n.schemaPath.includes(e)&&(s.cycle=n.path),s.schema;const i={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,i);const c=e._zod.toJSONSchema?.();if(c)i.schema=c;else{const p={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,i.schema,p);else{const g=i.schema,f=t.processors[o.type];if(!f)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);f(e,t,g,p)}const _=e._zod.parent;_&&(i.ref||(i.ref=_),C(_,t,p),t.seen.get(_).isParent=!0)}const a=t.metadataRegistry.get(e);return a&&Object.assign(i.schema,a),t.io==="input"&&T(e)&&(delete i.schema.examples,delete i.schema.default),t.io==="input"&&"_prefault"in i.schema&&((r=i.schema).default??(r.default=i.schema._prefault)),delete i.schema._prefault,t.seen.get(e).schema}function Dt(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const i of e.seen.entries()){const c=e.metadataRegistry.get(i[0])?.id;if(c){const a=r.get(c);if(a&&a!==i[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,i[0])}}const o=i=>{const c=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const _=e.external.registry.get(i[0])?.id,g=e.external.uri??(h=>h);if(_)return{ref:g(_)};const f=i[1].defId??i[1].schema.id??`schema${e.counter++}`;return i[1].defId=f,{defId:f,ref:`${g("__shared")}#/${c}/${f}`}}if(i[1]===n)return{ref:"#"};const d=`#/${c}/`,p=i[1].schema.id??`__schema${e.counter++}`;return{defId:p,ref:d+p}},s=i=>{if(i[1].schema.$ref)return;const c=i[1],{ref:a,defId:d}=o(i);c.def={...c.schema},d&&(c.defId=d);const p=c.schema;for(const _ in p)delete p[_];p.$ref=a};if(e.cycles==="throw")for(const i of e.seen.entries()){const c=i[1];if(c.cycle)throw new Error(`Cycle detected: #/${c.cycle?.join("/")}/<root>
63
+
64
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const i of e.seen.entries()){const c=i[1];if(t===i[0]){s(i);continue}if(e.external){const d=e.external.registry.get(i[0])?.id;if(t!==i[0]&&d){s(i);continue}}if(e.metadataRegistry.get(i[0])?.id){s(i);continue}if(c.cycle){s(i);continue}if(c.count>1&&e.reused==="ref"){s(i);continue}}}function Mt(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 d=a.def??a.schema,p={...d},_=a.ref;if(a.ref=null,_){r(_);const f=e.seen.get(_),h=f.schema;if(h.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(d.allOf=d.allOf??[],d.allOf.push(h)):Object.assign(d,h),Object.assign(d,p),c._zod.parent===_)for(const $ in d)$==="$ref"||$==="allOf"||$ in p||delete d[$];if(h.$ref&&f.def)for(const $ in d)$==="$ref"||$==="allOf"||$ in f.def&&JSON.stringify(d[$])===JSON.stringify(f.def[$])&&delete d[$]}const g=c._zod.parent;if(g&&g!==_){r(g);const f=e.seen.get(g);if(f?.schema.$ref&&(d.$ref=f.schema.$ref,f.def))for(const h in d)h==="$ref"||h==="allOf"||h in f.def&&JSON.stringify(d[h])===JSON.stringify(f.def[h])&&delete d[h]}e.override({zodSchema:c,jsonSchema:d,path:a.path??[]})};for(const c of[...e.seen.entries()].reverse())r(c[0]);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)}Object.assign(o,n.def??n.schema);const s=e.metadataRegistry.get(t)?.id;s!==void 0&&o.id===s&&delete o.id;const i=e.external?.defs??{};for(const c of e.seen.entries()){const a=c[1];a.def&&a.defId&&(a.def.id===a.defId&&delete a.def.id,i[a.defId]=a.def)}e.external||Object.keys(i).length>0&&(e.target==="draft-2020-12"?o.$defs=i:o.definitions=i);try{const c=JSON.parse(JSON.stringify(o));return Object.defineProperty(c,"~standard",{value:{...t["~standard"],jsonSchema:{input:me(t,"input",e.processors),output:me(t,"output",e.processors)}},enumerable:!1,writable:!1}),c}catch{throw new Error("Error converting schema to JSON.")}}function T(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 T(r.element,n);if(r.type==="set")return T(r.valueType,n);if(r.type==="lazy")return T(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")return T(r.innerType,n);if(r.type==="intersection")return T(r.left,n)||T(r.right,n);if(r.type==="record"||r.type==="map")return T(r.keyType,n)||T(r.valueType,n);if(r.type==="pipe")return T(r.in,n)||T(r.out,n);if(r.type==="object"){for(const o in r.shape)if(T(r.shape[o],n))return!0;return!1}if(r.type==="union"){for(const o of r.options)if(T(o,n))return!0;return!1}if(r.type==="tuple"){for(const o of r.items)if(T(o,n))return!0;return!!(r.rest&&T(r.rest,n))}return!1}const ni=(e,t={})=>n=>{const r=Rt({...n,processors:t});return C(e,r),Dt(r,e),Mt(r,e)},me=(e,t,n={})=>r=>{const{libraryOptions:o,target:s}=r??{},i=Rt({...o??{},target:s,io:t,processors:n});return C(e,i),Dt(i,e),Mt(i,e)},ri={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},oi=(e,t,n,r)=>{const o=n;o.type="string";const{minimum:s,maximum:i,format:c,patterns:a,contentEncoding:d}=e._zod.bag;if(typeof s=="number"&&(o.minLength=s),typeof i=="number"&&(o.maxLength=i),c&&(o.format=ri[c]??c,o.format===""&&delete o.format,c==="time"&&delete o.format),d&&(o.contentEncoding=d),a&&a.size>0){const p=[...a];p.length===1?o.pattern=p[0].source:p.length>1&&(o.allOf=[...p.map(_=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:_.source}))])}},ii=(e,t,n,r)=>{const o=n,{minimum:s,maximum:i,format:c,multipleOf:a,exclusiveMaximum:d,exclusiveMinimum:p}=e._zod.bag;typeof c=="string"&&c.includes("int")?o.type="integer":o.type="number";const _=typeof p=="number"&&p>=(s??Number.NEGATIVE_INFINITY),g=typeof d=="number"&&d<=(i??Number.POSITIVE_INFINITY),f=t.target==="draft-04"||t.target==="openapi-3.0";_?f?(o.minimum=p,o.exclusiveMinimum=!0):o.exclusiveMinimum=p:typeof s=="number"&&(o.minimum=s),g?f?(o.maximum=d,o.exclusiveMaximum=!0):o.exclusiveMaximum=d:typeof i=="number"&&(o.maximum=i),typeof a=="number"&&(o.multipleOf=a)},si=(e,t,n,r)=>{n.type="boolean"},ci=(e,t,n,r)=>{n.not={}},ai=(e,t,n,r)=>{},ui=(e,t,n,r)=>{const o=e._zod.def,s=mt(o.entries);s.every(i=>typeof i=="number")&&(n.type="number"),s.every(i=>typeof i=="string")&&(n.type="string"),n.enum=s},li=(e,t,n,r)=>{const o=e._zod.def,s=[];for(const i of o.values)if(i===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof i=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");s.push(Number(i))}else s.push(i);if(s.length!==0)if(s.length===1){const i=s[0];n.type=i===null?"null":typeof i,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[i]:n.const=i}else s.every(i=>typeof i=="number")&&(n.type="number"),s.every(i=>typeof i=="string")&&(n.type="string"),s.every(i=>typeof i=="boolean")&&(n.type="boolean"),s.every(i=>i===null)&&(n.type="null"),n.enum=s},di=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},pi=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},fi=(e,t,n,r)=>{const o=n,s=e._zod.def,{minimum:i,maximum:c}=e._zod.bag;typeof i=="number"&&(o.minItems=i),typeof c=="number"&&(o.maxItems=c),o.type="array",o.items=C(s.element,t,{...r,path:[...r.path,"items"]})},hi=(e,t,n,r)=>{const o=n,s=e._zod.def;o.type="object",o.properties={};const i=s.shape;for(const d in i)o.properties[d]=C(i[d],t,{...r,path:[...r.path,"properties",d]});const c=new Set(Object.keys(i)),a=new Set([...c].filter(d=>{const p=s.shape[d]._zod;return t.io==="input"?p.optin===void 0:p.optout===void 0}));a.size>0&&(o.required=Array.from(a)),s.catchall?._zod.def.type==="never"?o.additionalProperties=!1:s.catchall?s.catchall&&(o.additionalProperties=C(s.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):t.io==="output"&&(o.additionalProperties=!1)},mi=(e,t,n,r)=>{const o=e._zod.def,s=o.inclusive===!1,i=o.options.map((c,a)=>C(c,t,{...r,path:[...r.path,s?"oneOf":"anyOf",a]}));s?n.oneOf=i:n.anyOf=i},gi=(e,t,n,r)=>{const o=e._zod.def,s=C(o.left,t,{...r,path:[...r.path,"allOf",0]}),i=C(o.right,t,{...r,path:[...r.path,"allOf",1]}),c=d=>"allOf"in d&&Object.keys(d).length===1,a=[...c(s)?s.allOf:[s],...c(i)?i.allOf:[i]];n.allOf=a},_i=(e,t,n,r)=>{const o=e._zod.def,s=C(o.innerType,t,r),i=t.seen.get(e);t.target==="openapi-3.0"?(i.ref=o.innerType,n.nullable=!0):n.anyOf=[s,{type:"null"}]},vi=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType},bi=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType,n.default=JSON.parse(JSON.stringify(o.defaultValue))},yi=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(o.defaultValue)))},wi=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType;let i;try{i=o.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=i},zi=(e,t,n,r)=>{const o=e._zod.def,s=t.io==="input"?o.in._zod.def.type==="transform"?o.out:o.in:o.out;C(s,t,r);const i=t.seen.get(e);i.ref=s},$i=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType,n.readOnly=!0},Ut=(e,t,n,r)=>{const o=e._zod.def;C(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType},ki=l("ZodISODateTime",(e,t)=>{Or.init(e,t),S.init(e,t)});function Si(e){return To(ki,e)}const Zi=l("ZodISODate",(e,t)=>{Ir.init(e,t),S.init(e,t)});function Oi(e){return xo(Zi,e)}const Ii=l("ZodISOTime",(e,t)=>{Er.init(e,t),S.init(e,t)});function Ei(e){return Ao(Ii,e)}const Ci=l("ZodISODuration",(e,t)=>{Cr.init(e,t),S.init(e,t)});function Pi(e){return No(Ci,e)}const Ti=(e,t)=>{yt.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>vn(e,n)},flatten:{value:n=>_n(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,ke,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,ke,2)}},isEmpty:{get(){return e.issues.length===0}}})},j=l("ZodError",Ti,{Parent:Error}),xi=xe(j),Ai=Ae(j),Ni=_e(j),ji=ve(j),Ri=wn(j),Di=zn(j),Mi=$n(j),Ui=kn(j),Fi=Sn(j),Li=Zn(j),Ji=On(j),Bi=In(j),rt=new WeakMap;function oe(e,t,n){const r=Object.getPrototypeOf(e);let o=rt.get(r);if(o||(o=new Set,rt.set(r,o)),!o.has(t)){o.add(t);for(const s in n){const i=n[s];Object.defineProperty(r,s,{configurable:!0,enumerable:!1,get(){const c=i.bind(this);return Object.defineProperty(this,s,{configurable:!0,writable:!0,enumerable:!0,value:c}),c},set(c){Object.defineProperty(this,s,{configurable:!0,writable:!0,enumerable:!0,value:c})}})}}}const O=l("ZodType",(e,t)=>(Z.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:me(e,"input"),output:me(e,"output")}}),e.toJSONSchema=ni(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(n,r)=>xi(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>Ni(e,n,r),e.parseAsync=async(n,r)=>Ai(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>ji(e,n,r),e.spa=e.safeParseAsync,e.encode=(n,r)=>Ri(e,n,r),e.decode=(n,r)=>Di(e,n,r),e.encodeAsync=async(n,r)=>Mi(e,n,r),e.decodeAsync=async(n,r)=>Ui(e,n,r),e.safeEncode=(n,r)=>Fi(e,n,r),e.safeDecode=(n,r)=>Li(e,n,r),e.safeEncodeAsync=async(n,r)=>Ji(e,n,r),e.safeDecodeAsync=async(n,r)=>Bi(e,n,r),oe(e,"ZodType",{check(...n){const r=this.def;return this.clone(M(r,{checks:[...r.checks??[],...n.map(o=>typeof o=="function"?{_zod:{check:o,def:{check:"custom"},onattach:[]}}:o)]}),{parent:!0})},with(...n){return this.check(...n)},clone(n,r){return U(this,n,r)},brand(){return this},register(n,r){return n.add(this,r),this},refine(n,r){return this.check(Ns(n,r))},superRefine(n,r){return this.check(js(n,r))},overwrite(n){return this.check(H(n))},optional(){return ct(this)},exactOptional(){return zs(this)},nullable(){return at(this)},nullish(){return ct(at(this))},nonoptional(n){return Is(this,n)},array(){return B(this)},or(n){return fs([this,n])},and(n){return _s(this,n)},transform(n){return ut(this,ys(n))},default(n){return Ss(this,n)},prefault(n){return Os(this,n)},catch(n){return Cs(this,n)},pipe(n){return ut(this,n)},readonly(){return xs(this)},describe(n){const r=this.clone();return Q.add(r,{description:n}),r},meta(...n){if(n.length===0)return Q.get(this);const r=this.clone();return Q.add(r,n[0]),r},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(n){return n(this)}}),Object.defineProperty(e,"description",{get(){return Q.get(e)?.description},configurable:!0}),e)),Ft=l("_ZodString",(e,t)=>{Ne.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,s)=>oi(e,r,o);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,oe(e,"_ZodString",{regex(...r){return this.check(Fo(...r))},includes(...r){return this.check(Bo(...r))},startsWith(...r){return this.check(Vo(...r))},endsWith(...r){return this.check(Wo(...r))},min(...r){return this.check(he(...r))},max(...r){return this.check(Nt(...r))},length(...r){return this.check(jt(...r))},nonempty(...r){return this.check(he(1,...r))},lowercase(r){return this.check(Lo(r))},uppercase(r){return this.check(Jo(r))},trim(){return this.check(Ko())},normalize(...r){return this.check(Go(...r))},toLowerCase(){return this.check(qo())},toUpperCase(){return this.check(Ho())},slugify(){return this.check(Yo())}})}),Vi=l("ZodString",(e,t)=>{Ne.init(e,t),Ft.init(e,t),e.email=n=>e.check(po(Wi,n)),e.url=n=>e.check(At(Lt,n)),e.jwt=n=>e.check(Po(cs,n)),e.emoji=n=>e.check(_o(Gi,n)),e.guid=n=>e.check(Qe(ot,n)),e.uuid=n=>e.check(fo(le,n)),e.uuidv4=n=>e.check(ho(le,n)),e.uuidv6=n=>e.check(mo(le,n)),e.uuidv7=n=>e.check(go(le,n)),e.nanoid=n=>e.check(vo(Ki,n)),e.guid=n=>e.check(Qe(ot,n)),e.cuid=n=>e.check(bo(qi,n)),e.cuid2=n=>e.check(yo(Hi,n)),e.ulid=n=>e.check(wo(Yi,n)),e.base64=n=>e.check(Io(os,n)),e.base64url=n=>e.check(Eo(is,n)),e.xid=n=>e.check(zo(Xi,n)),e.ksuid=n=>e.check($o(Qi,n)),e.ipv4=n=>e.check(ko(es,n)),e.ipv6=n=>e.check(So(ts,n)),e.cidrv4=n=>e.check(Zo(ns,n)),e.cidrv6=n=>e.check(Oo(rs,n)),e.e164=n=>e.check(Co(ss,n)),e.datetime=n=>e.check(Si(n)),e.date=n=>e.check(Oi(n)),e.time=n=>e.check(Ei(n)),e.duration=n=>e.check(Pi(n))});function v(e){return lo(Vi,e)}const S=l("ZodStringFormat",(e,t)=>{k.init(e,t),Ft.init(e,t)}),Wi=l("ZodEmail",(e,t)=>{vr.init(e,t),S.init(e,t)}),ot=l("ZodGUID",(e,t)=>{gr.init(e,t),S.init(e,t)}),le=l("ZodUUID",(e,t)=>{_r.init(e,t),S.init(e,t)}),Lt=l("ZodURL",(e,t)=>{br.init(e,t),S.init(e,t)});function Jt(e){return At(Lt,e)}const Gi=l("ZodEmoji",(e,t)=>{yr.init(e,t),S.init(e,t)}),Ki=l("ZodNanoID",(e,t)=>{wr.init(e,t),S.init(e,t)}),qi=l("ZodCUID",(e,t)=>{zr.init(e,t),S.init(e,t)}),Hi=l("ZodCUID2",(e,t)=>{$r.init(e,t),S.init(e,t)}),Yi=l("ZodULID",(e,t)=>{kr.init(e,t),S.init(e,t)}),Xi=l("ZodXID",(e,t)=>{Sr.init(e,t),S.init(e,t)}),Qi=l("ZodKSUID",(e,t)=>{Zr.init(e,t),S.init(e,t)}),es=l("ZodIPv4",(e,t)=>{Pr.init(e,t),S.init(e,t)}),ts=l("ZodIPv6",(e,t)=>{Tr.init(e,t),S.init(e,t)}),ns=l("ZodCIDRv4",(e,t)=>{xr.init(e,t),S.init(e,t)}),rs=l("ZodCIDRv6",(e,t)=>{Ar.init(e,t),S.init(e,t)}),os=l("ZodBase64",(e,t)=>{Nr.init(e,t),S.init(e,t)}),is=l("ZodBase64URL",(e,t)=>{Rr.init(e,t),S.init(e,t)}),ss=l("ZodE164",(e,t)=>{Dr.init(e,t),S.init(e,t)}),cs=l("ZodJWT",(e,t)=>{Ur.init(e,t),S.init(e,t)}),Bt=l("ZodNumber",(e,t)=>{Et.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,s)=>ii(e,r,o),oe(e,"ZodNumber",{gt(r,o){return this.check(tt(r,o))},gte(r,o){return this.check(we(r,o))},min(r,o){return this.check(we(r,o))},lt(r,o){return this.check(et(r,o))},lte(r,o){return this.check(ye(r,o))},max(r,o){return this.check(ye(r,o))},int(r){return this.check(it(r))},safe(r){return this.check(it(r))},positive(r){return this.check(tt(0,r))},nonnegative(r){return this.check(we(0,r))},negative(r){return this.check(et(0,r))},nonpositive(r){return this.check(ye(0,r))},multipleOf(r,o){return this.check(nt(r,o))},step(r,o){return this.check(nt(r,o))},finite(){return this}});const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function R(e){return jo(Bt,e)}const as=l("ZodNumberFormat",(e,t)=>{Fr.init(e,t),Bt.init(e,t)});function it(e){return Ro(as,e)}const us=l("ZodBoolean",(e,t)=>{Lr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>si(e,n,r)});function re(e){return Do(us,e)}const ls=l("ZodUnknown",(e,t)=>{Jr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ai()});function st(){return Mo(ls)}const ds=l("ZodNever",(e,t)=>{Br.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ci(e,n,r)});function Vt(e){return Uo(ds,e)}const ps=l("ZodArray",(e,t)=>{Vr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>fi(e,n,r,o),e.element=t.element,oe(e,"ZodArray",{min(n,r){return this.check(he(n,r))},nonempty(n){return this.check(he(1,n))},max(n,r){return this.check(Nt(n,r))},length(n,r){return this.check(jt(n,r))},unwrap(){return this.element}})});function B(e,t){return Xo(ps,e,t)}const Wt=l("ZodObject",(e,t)=>{Gr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>hi(e,n,r,o),w(e,"shape",()=>t.shape),oe(e,"ZodObject",{keyof(){return je(Object.keys(this._zod.def.shape))},catchall(n){return this.clone({...this._zod.def,catchall:n})},passthrough(){return this.clone({...this._zod.def,catchall:st()})},loose(){return this.clone({...this._zod.def,catchall:st()})},strict(){return this.clone({...this._zod.def,catchall:Vt()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(n){return dn(this,n)},safeExtend(n){return pn(this,n)},merge(n){return fn(this,n)},pick(n){return un(this,n)},omit(n){return ln(this,n)},partial(...n){return hn(Kt,this,n[0])},required(...n){return mn(qt,this,n[0])}})});function E(e,t){const n={type:"object",shape:e??{},...m(t)};return new Wt(n)}function D(e,t){return new Wt({type:"object",shape:e,catchall:Vt(),...m(t)})}const Gt=l("ZodUnion",(e,t)=>{Tt.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>mi(e,n,r,o),e.options=t.options});function fs(e,t){return new Gt({type:"union",options:e,...m(t)})}const hs=l("ZodDiscriminatedUnion",(e,t)=>{Gt.init(e,t),Kr.init(e,t)});function ms(e,t,n){return new hs({type:"union",options:t,discriminator:e,...m(n)})}const gs=l("ZodIntersection",(e,t)=>{qr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>gi(e,n,r,o)});function _s(e,t){return new gs({type:"intersection",left:e,right:t})}const Ze=l("ZodEnum",(e,t)=>{Hr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(r,o,s)=>ui(e,r,o),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(r,o)=>{const s={};for(const i of r)if(n.has(i))s[i]=t.entries[i];else throw new Error(`Key ${i} not found in enum`);return new Ze({...t,checks:[],...m(o),entries:s})},e.exclude=(r,o)=>{const s={...t.entries};for(const i of r)if(n.has(i))delete s[i];else throw new Error(`Key ${i} not found in enum`);return new Ze({...t,checks:[],...m(o),entries:s})}});function je(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new Ze({type:"enum",entries:n,...m(t)})}const vs=l("ZodLiteral",(e,t)=>{Yr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>li(e,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function ze(e,t){return new vs({type:"literal",values:Array.isArray(e)?e:[e],...m(t)})}const bs=l("ZodTransform",(e,t)=>{Xr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>pi(e,n),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new ht(e.constructor.name);n.addIssue=s=>{if(typeof s=="string")n.issues.push(ne(s,n.value,t));else{const i=s;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=n.value),i.inst??(i.inst=e),n.issues.push(ne(i))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(s=>(n.value=s,n)):(n.value=o,n)}});function ys(e){return new bs({type:"transform",transform:e})}const Kt=l("ZodOptional",(e,t)=>{xt.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ut(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function ct(e){return new Kt({type:"optional",innerType:e})}const ws=l("ZodExactOptional",(e,t)=>{Qr.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ut(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function zs(e){return new ws({type:"optional",innerType:e})}const $s=l("ZodNullable",(e,t)=>{eo.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>_i(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function at(e){return new $s({type:"nullable",innerType:e})}const ks=l("ZodDefault",(e,t)=>{to.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>bi(e,n,r,o),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Ss(e,t){return new ks({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():_t(t)}})}const Zs=l("ZodPrefault",(e,t)=>{no.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>yi(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Os(e,t){return new Zs({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():_t(t)}})}const qt=l("ZodNonOptional",(e,t)=>{ro.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>vi(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Is(e,t){return new qt({type:"nonoptional",innerType:e,...m(t)})}const Es=l("ZodCatch",(e,t)=>{oo.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>wi(e,n,r,o),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Cs(e,t){return new Es({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const Ps=l("ZodPipe",(e,t)=>{io.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>zi(e,n,r,o),e.in=t.in,e.out=t.out});function ut(e,t){return new Ps({type:"pipe",in:e,out:t})}const Ts=l("ZodReadonly",(e,t)=>{so.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>$i(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function xs(e){return new Ts({type:"readonly",innerType:e})}const As=l("ZodCustom",(e,t)=>{co.init(e,t),O.init(e,t),e._zod.processJSONSchema=(n,r,o)=>di(e,n)});function Ns(e,t={}){return Qo(As,e,t)}function js(e,t){return ei(e,t)}const pe=je(["global","project"]).describe("Rule scope."),lt=D({title:v().trim().min(1).max(160).regex(/^[^\r\n]+$/).describe("Single-line rule title."),body:v().trim().min(1).max(16384).describe("Editable Markdown instructions, without storage metadata.")}).describe("Editable standing rule."),Oe=D({id:v().min(1).describe("Canonical TencentDB source path."),revision:v().regex(/^[a-f0-9]{64}$/).describe("SHA-256 of the complete source read by the editor.")}).describe("Optimistic concurrency identity for a standing rule."),Rs=D({...Oe.shape,title:v().describe("Rule title extracted from its source."),body:v().describe("Editable Markdown body."),source:v().describe("Canonical TencentDB source path.")}).describe("Standing rule as displayed in the editor."),dt=D({project:v().nullable().describe("Canonical project directory, or null for global rules."),rules:B(Rs).describe("Complete rules in the selected scope.")}).describe("Current TencentDB rules for one scope."),Ds=ms("action",[lt.extend({action:ze("add").describe("Create a rule."),scope:pe}),lt.extend({...Oe.shape,action:ze("edit").describe("Replace a rule's editable body."),scope:pe}),Oe.extend({action:ze("delete").describe("Delete a rule."),scope:pe})]).describe("A revision-checked change to a TencentDB standing rule."),Ms=B(D({time:R().describe("Snapshot timestamp in Unix milliseconds."),project:v().describe("Canonical project directory."),kind:je(["context","compaction","title","generate"]).describe("OpenCode request hook that supplied these rules."),text:v().describe("Exact TencentDB standing-rules section.")}).describe("Rules supplied to an outgoing model request.")).describe("Up to ten changes to the rules supplied in this session."),Us="opencode-tencentdb-plugin",de=D({}),$e={rules_error:D({}).describe("No additional rule error data.")},Ie=v().regex(/^bmad\/[a-z0-9]+(?:-[a-z0-9]+)*-[a-f0-9]{10}\/.+\.md$/u).refine(e=>!/[\\:\p{Cc}]/u.test(e)&&!e.split("/").some(t=>["",".",".."].includes(t))).describe("TencentDB-relative Markdown path in a BMAD project namespace."),Fs=E({content:v().describe("The stored artifact's Markdown body.")}).describe("A read-only BMAD artifact preview from TencentDB."),pt=E({baseUrl:Jt().describe("OpenAI compatible embedding API base URL."),model:v().trim().min(1).max(200).describe("Model identifier at the endpoint."),apiKey:v().optional().describe("New key, or omit to reuse the current key at the same endpoint.")}).describe("Candidate embedding connection for verification or rebuild."),Ls=E({available:re().describe("Whether the native runtime is configured."),phase:v().describe("Current rebuild phase: idle, checking, reindexing, complete, failed, or unavailable."),done:R().int().describe("Memory records processed."),total:R().int().describe("Total memory records to process."),layer:v().optional().describe("Current memory layer reported by the worker."),error:v().optional().describe("Last rebuild failure detail."),current:E({baseUrl:v().describe("Active embedding API base URL."),model:v().describe("Active model identifier."),dimensions:R().int().describe("Active vector dimensions."),hasApiKey:re().describe("Whether a key is configured, without exposing it.")}).optional().describe("Active embedding configuration, if available.")}).describe("Embedding configuration and rebuild progress."),Js=E({name:v(),path:v(),code_graph_id:v().optional(),status:v(),indexed_at:v().nullable().optional(),error:v().optional(),stats:E({files:R(),nodes:R(),edges:R()}).nullable().optional()}),Bs=E({project_id:v().nullable(),name:v(),workspace:v(),repositories:B(Js),errors:B(E({path:v(),error:v()}))}),Vs=E({results:B(E({repository:v(),name:v().optional(),accepted:re(),error:v().optional()})),errors:B(E({path:v(),error:v()}))}),ie=tn.Rpc.define({id:Us,methods:{rulesList:{input:D({scope:pe}).describe("Select the global or current project rule inventory."),output:dt,errors:$e},rulesChange:{input:Ds,output:dt,errors:$e},rulesHistory:{input:D({sessionID:v().min(1).max(128).describe("Session whose injected rules to inspect.")}).describe("Select a session's rule-load history."),output:Ms,errors:$e},status:{input:de,output:E({ready:re(),dataDir:v(),tools:R().int(),error:v().optional(),embedding:E({baseUrl:v(),model:v(),dimensions:R().int()}).optional()})},panel:{input:de,output:E({url:Jt()})},readBmadArtifact:{input:D({path:Ie}).describe("Identifies the BMAD artifact to open in OpenCode."),output:Fs},embeddingStatus:{input:de,output:Ls},probeEmbedding:{input:pt,output:E({dimensions:R().int().describe("Dimensions returned by the candidate model.")}).describe("Live connection check result.")},applyEmbedding:{input:pt,output:E({started:re().describe("Whether an offline rebuild was started.")}).describe("Rebuild acceptance.")},repositories:{input:de,output:Bs},index:{input:E({repository:v().optional()}),output:Vs}},events:{}});var Ws=u.template("<p role=alert>Could not load embedding settings."),Gs=u.template("<div style=display:flex;gap:8px;flex-wrap:wrap>"),Ks=u.template('<p role=status style="padding:0 16px">Rebuilding embeddings: <!> · <!>/<!> '),qs=u.template('<p role=status style="padding:0 16px">Embedding index rebuilt.'),Hs=u.template('<p style="padding:0 16px">');function Ys(){const e=N.usePlugin(),t=e.ui,n=()=>e.client.rpc(ie),[r,{refetch:o}]=b.createResource(()=>n().embeddingStatus({})),[s,i]=b.createSignal(""),[c,a]=b.createSignal(""),[d,p]=b.createSignal(""),[_,g]=b.createSignal(""),[f,h]=b.createSignal(""),[P,$]=b.createSignal(!1);let W=!1;b.createEffect(()=>{const y=r()?.current;y&&!W&&(i(y.baseUrl),a(y.model),W=!0)}),b.createEffect(()=>{if(!["checking","reindexing"].includes(r()?.phase??""))return;const y=setInterval(()=>{o()},1e3);b.onCleanup(()=>clearInterval(y))}),b.createEffect(()=>{if(r()?.phase==="complete"){const y=r()?.current;y&&(i(y.baseUrl),a(y.model))}});const Y=()=>JSON.stringify([s(),c(),d()]),A=()=>({baseUrl:s().trim(),model:c().trim(),apiKey:d().trim()||void 0}),z=()=>["checking","reindexing"].includes(r()?.phase??""),I=()=>!!s().trim()&&!!c().trim()&&!P()&&!z();async function se(){$(!0),h(""),g("");try{const y=await n().probeEmbedding(A());g(Y()),h(`Connection works · ${y.dimensions} dimensions.`)}catch(y){h(y instanceof Error?y.message:String(y))}finally{$(!1)}}async function ce(){if(!(_()!==Y()||!await e.dialogs.confirm({title:"Change embedding model?",description:"Tencent Memory will pause while it rebuilds the vector index. A backup of the previous index and settings is kept for recovery.",confirm:"Rebuild index"}))){$(!0),h("");try{await n().applyEmbedding(A()),p(""),g(""),await o()}catch(X){h(X instanceof Error?X.message:String(X))}finally{$(!1)}}}return u.createComponent(t.SettingsSection,{title:"Embedding",footer:"Changing the model rebuilds the vector index. Existing memory stays in place and the previous index is backed up.",get children(){return[u.createComponent(b.Show,{get when(){return r.error},get children(){return Ws()}}),u.createComponent(b.Show,{get when(){return r()?.current},children:y=>u.createComponent(t.SettingsRow,{title:"Current model",get description(){return`${y().model} · ${y().dimensions} dimensions`}})}),u.createComponent(t.SettingsRow,{title:"Endpoint",description:"OpenAI compatible /v1 endpoint",get children(){return u.createComponent(t.TextInput,{label:"Embedding endpoint",get value(){return s()},onInput:i,get disabled(){return z()}})}}),u.createComponent(t.SettingsRow,{title:"Model",get children(){return u.createComponent(t.TextInput,{label:"Embedding model",get value(){return c()},onInput:a,get disabled(){return z()}})}}),u.createComponent(t.SettingsRow,{title:"API key",description:"Leave blank to keep the current key for the same endpoint.",get children(){return u.createComponent(t.TextInput,{label:"Embedding API key",type:"password",get value(){return d()},onInput:p,get disabled(){return z()}})}}),u.createComponent(t.SettingsRow,{title:"Verify and apply",get children(){var y=Gs();return u.insert(y,u.createComponent(t.Button,{onClick:()=>{i("http://127.0.0.1:11434/v1"),p("")},get disabled(){return z()},children:"Ollama endpoint"}),null),u.insert(y,u.createComponent(t.Button,{onClick:()=>{se()},get disabled(){return!I()},get busy(){return P()},children:"Check connection"}),null),u.insert(y,u.createComponent(t.Button,{variant:"contrast",onClick:()=>{ce()},get disabled(){return!I()||_()!==Y()},children:"Rebuild index"}),null),y}}),u.createComponent(b.Show,{get when(){return z()},get children(){var y=Ks(),X=y.firstChild,Re=X.nextSibling,Qt=Re.nextSibling,De=Qt.nextSibling,en=De.nextSibling,Me=en.nextSibling;return Me.nextSibling,u.insert(y,()=>r()?.phase,Re),u.insert(y,()=>r()?.done,De),u.insert(y,()=>r()?.total,Me),u.insert(y,()=>r()?.layer??"",null),y}}),u.createComponent(b.Show,{get when(){return r()?.phase==="complete"},get children(){return qs()}}),u.createComponent(b.Show,{get when(){return r()?.error||f()},get children(){var y=Hs();return u.insert(y,()=>r()?.error||f()),u.effect(()=>u.setAttribute(y,"role",r()?.error?"alert":"status")),y}})]}})}var Xs=u.template("<p role=status>Loading artifact…"),Qs=u.template("<p role=alert>Could not load this BMAD artifact from TencentDB."),ec=u.template("<div style=height:100%;overflow:auto;padding:16px><header style=display:flex;justify-content:space-between;gap:8px><p>TencentDB · BMAD artifact");function Ht(e,t){return e.server.client.rpc(ie).readBmadArtifact({path:t},{location:{directory:e.location?.directory}})}function tc(e){const{ui:t}=N.usePlugin(),[n,{refetch:r}]=b.createResource(()=>({session:e.session,path:e.tab.id}),({session:o,path:s})=>Ht(o,s).catch(()=>null));return(()=>{var o=ec(),s=o.firstChild;return s.firstChild,u.insert(s,u.createComponent(t.Button,{get disabled(){return n.loading},onClick:()=>{r()},children:"Refresh"}),null),u.insert(o,u.createComponent(b.Show,{get when(){return n.loading},get children(){return Xs()}}),null),u.insert(o,u.createComponent(b.Show,{get when(){return n()===null},get children(){return Qs()}}),null),u.insert(o,u.createComponent(b.Show,{get when(){return n()},children:i=>u.createComponent(t.Markdown,{get text(){return i().content}})}),null),o})()}function nc(e){const t=new Map;e.add(N.LinkHandler,{priority:10,match:n=>n.session?.server.local===!0&&!n.exact&&Ie.safeParse(n.href).success,exists:async({href:n,session:r})=>r?Ht(r,n).then(()=>!0,()=>!1):!1,open:({href:n,session:r,background:o})=>{r&&e.layout.open(`${e.id}:${n}`,r,{background:o})}}),e.add(N.Panel,{id:"bmad-artifacts",region:"side",mobile:{title:"BMAD Artifact",kind:"menu",order:50,icon:"file-document"},list:({session:n,open:r})=>n.server.local?r.filter(o=>Ie.safeParse(o).success).map(o=>{const s=t.get(o);if(s)return s;const i={id:o,title:o.slice(o.lastIndexOf("/")+1),closable:"compact"};return t.set(o,i),i}):[],render:n=>u.createComponent(tc,{get session(){return n.session},get tab(){return n.tab},get screen(){return n.screen}})})}var rc=u.template('<div role=tablist style="display:flex;gap:16px;padding:0 16px">'),oc=u.template('<button type=button role=tab style="padding:12px 4px;border:0;background:transparent;color:inherit;cursor:pointer;font:inherit">'),ic=u.template("<p role=alert>Tencent Memory is unavailable. Reload OpenCode."),sc=u.template("<div style=display:flex;flex:1;min-height:0>"),cc=u.template('<iframe title="Tencent Memory Hub"style=flex:1;width:100%;height:100%;border:0>'),ac=u.template("<p role=alert>Could not load Tencent Memory settings."),uc=u.template('<div style=display:flex;flex-direction:column;height:100dvh;min-height:650px><h2 style="margin:16px 20px 4px">Tencent Memory</h2><div role=tabpanel aria-label="Memory Hub"style=flex:1;min-height:0></div><div role=tabpanel aria-label=Settings style=flex:1;min-height:0;overflow:auto>'),lc=u.template("<p role=alert>"),dc=u.template("<p role=status>"),pc=u.template('<div role=tabpanel aria-label="Code Indexes"style=flex:1;min-height:0;overflow:auto>'),fc=u.template("<div style=display:flex;gap:8px>"),hc=u.template("<p>No Git repositories found within three folder levels of this project."),mc=u.template("<p role=alert>: "),gc=u.template('<div style=display:flex;flex-direction:column;width:100%;height:100%;min-height:0><div role=tabpanel aria-label="Memory Hub"style=flex:1;min-height:0></div><div style=flex:1;min-height:0>');const F={id:"memory",title:"Tencent Memory",closable:"compact"};async function _c(e){return e.client.rpc(ie).status({})}const ft=new WeakMap;function Yt(e){return(()=>{var t=rc();return u.insert(t,u.createComponent(b.For,{get each(){return e.items},children:n=>(()=>{var r=oc();return r.$$click=()=>e.select(n.id),u.insert(r,()=>n.title),u.effect(o=>{var s=e.active===n.id,i=e.active===n.id?"2px solid currentColor":"2px solid transparent";return s!==o.e&&u.setAttribute(r,"aria-selected",o.e=s),i!==o.t&&u.setStyleProperty(r,"border-bottom",o.t=i),o},{e:void 0,t:void 0}),r})()})),t})()}function Xt(e){const t=N.usePlugin(),[n]=b.createResource(()=>e.session?.directory??"global",()=>(e.session?.server.client??t.client).rpc(ie).panel({},e.session?{location:{directory:e.session.directory}}:void 0));return(()=>{var r=sc();return u.insert(r,u.createComponent(b.Show,{get when(){return n.error},get children(){return ic()}}),null),u.insert(r,u.createComponent(b.Show,{get when(){return n()},children:o=>(()=>{var s=cc();return u.effect(()=>u.setAttribute(s,"src",o().url)),s})()}),null),r})()}function vc(){const e=N.usePlugin(),t=e.ui,[n,r]=b.createSignal("hub"),[o,{refetch:s}]=b.createResource(async()=>{const i=await _c(e);return ft.set(e,i),i},{initialValue:ft.get(e)});return(()=>{var i=uc(),c=i.firstChild,a=c.nextSibling,d=a.nextSibling;return u.insert(i,u.createComponent(Yt,{get active(){return n()},select:r,items:[{id:"hub",title:"Memory Hub"},{id:"settings",title:"Settings"}]}),a),u.insert(a,u.createComponent(Xt,{})),u.insert(d,u.createComponent(t.SettingsLayout,{title:"Runtime Settings",description:"The local TencentDB service and its embedding configuration.",get actions(){return u.createComponent(t.Button,{onClick:()=>{s()},children:"Refresh"})},get children(){return[u.createComponent(b.Show,{get when(){return o.error},get children(){return ac()}}),u.createComponent(b.Show,{get when(){return o()},children:p=>u.createComponent(t.SettingsSection,{title:"Runtime",get children(){return[u.createComponent(t.SettingsRow,{title:"Status",get description(){return u.memo(()=>!!p().ready)()?"Running":p().error??"Unavailable"}}),u.createComponent(t.SettingsRow,{title:"Memory tools",get description(){return String(p().tools)}}),u.createComponent(t.SettingsRow,{title:"Data directory",get description(){return p().dataDir}})]}})}),u.createComponent(Ys,{})]}})),u.effect(p=>{var _=n()!=="hub",g=n()==="hub"?"flex":"none",f=n()!=="settings",h=n()==="settings"?"block":"none";return _!==p.e&&u.setAttribute(a,"aria-hidden",p.e=_),g!==p.t&&u.setStyleProperty(a,"display",p.t=g),f!==p.a&&u.setAttribute(d,"aria-hidden",p.a=f),h!==p.o&&u.setStyleProperty(d,"display",p.o=h),p},{e:void 0,t:void 0,a:void 0,o:void 0}),i})()}function bc(e){const n=N.usePlugin().ui,r=()=>e.session.server.client.rpc(ie),o=()=>({location:{directory:e.session.directory}}),[s,{refetch:i}]=b.createResource(()=>e.session.directory,()=>r().repositories({},o())),[c,a]=b.createSignal(!1),[d,p]=b.createSignal("");async function _(g){a(!0),p("");try{const f=await r().index({repository:g},o()),h=f.results.filter($=>$.accepted).length,P=f.results.length-h;p(`${h} index job${h===1?"":"s"} started${P?`, ${P} failed`:""}. Refresh to check completion.`),await i()}catch(f){p(f instanceof Error?f.message:String(f))}finally{a(!1)}}return(()=>{var g=pc();return u.insert(g,u.createComponent(n.SettingsLayout,{title:"Code Indexes",description:"Git repositories are discovered automatically under this project. Index each repository separately.",get actions(){return(()=>{var f=fc();return u.insert(f,u.createComponent(n.Button,{onClick:()=>{i()},get disabled(){return c()},get busy(){return s.loading},children:"Refresh"}),null),u.insert(f,u.createComponent(n.Button,{variant:"contrast",onClick:()=>{_()},get disabled(){return c()||!s()?.repositories.length},children:"Index all"}),null),f})()},get children(){return[u.createComponent(b.Show,{get when(){return s.error},get children(){var f=lc();return u.insert(f,()=>String(s.error)),f}}),u.createComponent(b.Show,{get when(){return d()},get children(){var f=dc();return u.insert(f,d),f}}),u.createComponent(b.Show,{get when(){return s()},children:f=>u.createComponent(n.SettingsSection,{get title(){return`${f().repositories.length} discovered ${f().repositories.length===1?"repository":"repositories"}`},get footer(){return f().workspace},get children(){return[u.createComponent(b.Show,{get when(){return!f().repositories.length},get children(){return hc()}}),u.createComponent(b.For,{get each(){return f().repositories},children:h=>u.createComponent(n.SettingsRow,{get title(){return`${h.name} · ${h.status}`},get description(){return`${h.path}${h.indexed_at?` · indexed ${h.indexed_at}`:""}${h.stats?` · ${h.stats.files} files`:""}${h.error?` · ${h.error}`:""}`},get children(){return u.createComponent(n.Button,{onClick:()=>{_(h.path)},get disabled(){return c()||h.status==="pending"||h.status==="processing"||h.status==="unavailable"},get children(){return h.status==="ready"?"Refresh index":"Index"}})}})}),u.createComponent(b.For,{get each(){return f().errors},children:h=>(()=>{var P=mc(),$=P.firstChild;return u.insert(P,()=>h.path,$),u.insert(P,()=>h.error,null),P})()})]}})})]}})),g})()}function yc(e){const[t,n]=b.createSignal("hub");return(()=>{var r=gc(),o=r.firstChild,s=o.nextSibling;return u.insert(r,u.createComponent(Yt,{get active(){return t()},select:n,items:[{id:"hub",title:"Memory Hub"},{id:"indexes",title:"Code Indexes"}]}),o),u.insert(o,u.createComponent(Xt,{get session(){return e.session}})),u.insert(s,u.createComponent(bc,{get session(){return e.session}})),u.effect(i=>{var c=t()!=="hub",a=t()==="hub"?"flex":"none",d=t()==="indexes"?"flex":"none",p=t()!=="indexes";return c!==i.e&&u.setAttribute(o,"aria-hidden",i.e=c),a!==i.t&&u.setStyleProperty(o,"display",i.t=a),d!==i.a&&u.setStyleProperty(s,"display",i.a=d),p!==i.o&&u.setAttribute(s,"aria-hidden",i.o=p),i},{e:void 0,t:void 0,a:void 0,o:void 0}),r})()}const wc=N.Plugin.define({setup(e){nc(e);const t=()=>{const n=e.sessions.current();n?.server.local&&e.layout.open(`${e.id}:${F.id}`,n)};e.add(N.SettingsPage,{id:"memory",title:"Tencent Memory",icon:"brain",render:()=>u.createComponent(vc,{})}),e.add(N.Command,{id:"settings",title:"Open Tencent Memory",run:()=>e.layout.settings("memory")}),e.add(N.MenuItem,()=>{const n=e.sessions.current();if(n?.server.local)return{menu:"session.panel",id:F.id,title:F.title,icon:"brain",run:t,opened:e.layout.state(`${e.id}:${F.id}`,n)!=="closed"}}),e.add(N.Panel,{id:F.id,region:"side",width:700,list:({open:n,session:r})=>r.server.local&&n.includes(F.id)?[F]:[],render:n=>u.createComponent(yc,{get session(){return n.session}})})}});u.delegateEvents(["click"]);exports.default=wc;