@tbox.cn/tboxcode-dsh-sdk 0.1.0-rc.15 → 0.1.0-rc.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/embedded.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SharedAcpCore, SharedConnection, createSharedAcpCore } from "@tbox.cn/dsh-acp-full";
1
+ import { IMAGE_PAYLOAD_BUDGET, ImageRenderOptions, ImageRenderState, RenderImageBytes, SharedAcpCore, SharedConnection, createSharedAcpCore } from "@tbox.cn/dsh-acp-full";
2
2
  import { AskUserQuestionItemLike, SubagentCatalogState, ToolJournal, agentCapabilities, buildElicitationSchema, projectRecord, stopReasonFromTurnEnd } from "@tbox.cn/dsh-acp-bridge-core";
3
3
  import { LlmConfigSchema, TboxcodeDshModelTraits } from "@tbox.cn/tboxcode-dsh-llm";
4
- export { type AskUserQuestionItemLike, LlmConfigSchema, type SharedAcpCore, type SharedConnection, SubagentCatalogState, type TboxcodeDshModelTraits, ToolJournal, agentCapabilities, buildElicitationSchema, createSharedAcpCore, projectRecord, stopReasonFromTurnEnd };
4
+ export { type AskUserQuestionItemLike, IMAGE_PAYLOAD_BUDGET, type ImageRenderOptions, ImageRenderState, LlmConfigSchema, type RenderImageBytes, type SharedAcpCore, type SharedConnection, SubagentCatalogState, type TboxcodeDshModelTraits, ToolJournal, agentCapabilities, buildElicitationSchema, createSharedAcpCore, projectRecord, stopReasonFromTurnEnd };
package/lib/embedded.js CHANGED
@@ -1 +1 @@
1
- import{createSharedAcpCore as e}from"@tbox.cn/dsh-acp-full";import{SubagentCatalogState as t,ToolJournal as n,agentCapabilities as r,buildElicitationSchema as i,projectRecord as a,stopReasonFromTurnEnd as o}from"@tbox.cn/dsh-acp-bridge-core";import{LlmConfigSchema as s}from"@tbox.cn/tboxcode-dsh-llm";export{s as LlmConfigSchema,t as SubagentCatalogState,n as ToolJournal,r as agentCapabilities,i as buildElicitationSchema,e as createSharedAcpCore,a as projectRecord,o as stopReasonFromTurnEnd};
1
+ import{IMAGE_PAYLOAD_BUDGET as e,ImageRenderState as t,createSharedAcpCore as n}from"@tbox.cn/dsh-acp-full";import{SubagentCatalogState as r,ToolJournal as i,agentCapabilities as a,buildElicitationSchema as o,projectRecord as s,stopReasonFromTurnEnd as c}from"@tbox.cn/dsh-acp-bridge-core";import{LlmConfigSchema as l}from"@tbox.cn/tboxcode-dsh-llm";export{e as IMAGE_PAYLOAD_BUDGET,t as ImageRenderState,l as LlmConfigSchema,r as SubagentCatalogState,i as ToolJournal,a as agentCapabilities,o as buildElicitationSchema,n as createSharedAcpCore,s as projectRecord,c as stopReasonFromTurnEnd};
package/lib/index.d.ts CHANGED
@@ -81,7 +81,7 @@ declare class Supervisor {
81
81
  //#endregion
82
82
  //#region src/wire.d.ts
83
83
  /**
84
- * wire 契约(手写恰两处之二——sdk 对外面;规格真源 = dsh 0.2.2-rc.1 源码形状(wire 形状较 0.2.1 未变),
84
+ * wire 契约(手写恰两处之二——sdk 对外面;规格真源 = dsh 0.2.2-rc.5 源码形状(wire 形状较 0.2.2-rc.1 未变),
85
85
  * 逐字段锚点见各类型注释;verify:upgrade 第五项帧比对守护漂移)。
86
86
  *
87
87
  * 编译域 / wire 域二分(bridge-typing-boundary-hardening):本文件是 wire 域——
@@ -503,6 +503,16 @@ declare class RpcSessionDeps implements SessionDeps {
503
503
  pool: FollowPool;
504
504
  logger: GatewayLogger;
505
505
  });
506
+ /**
507
+ * Stop 级联(`session/cancel`):请 server 软停该会话的全部后代。
508
+ * 失败只记日志——cancel 是 notification,不因树清理失败拒绝;旧 server 降级。
509
+ */
510
+ readonly stopSubagents: (agent: AgentLike) => Promise<void>;
511
+ /**
512
+ * Close 级联(`session/close`):请 server 释放该会话的全部后代。
513
+ * 旧 server 降级;其余失败上抛,由 close 聚合与 dispose 一并收敛。
514
+ */
515
+ readonly drainSubagents: (agent: AgentLike) => Promise<void>;
506
516
  createAgent(options: Parameters<SessionDeps['createAgent']>[0]): Promise<HostAgentHandle>;
507
517
  resumeAgent(options: Parameters<SessionDeps['resumeAgent']>[0]): Promise<HostAgentHandle>;
508
518
  readonly persistence: {
@@ -529,6 +539,23 @@ declare class RpcSessionDeps implements SessionDeps {
529
539
  };
530
540
  readonly llm: LlmCatalogDeps;
531
541
  admitPromptContent(parts: Parameters<NonNullable<SessionDeps['admitPromptContent']>>[0]): Promise<Awaited<ReturnType<NonNullable<SessionDeps['admitPromptContent']>>>>;
542
+ /**
543
+ * 图片 URL 准入(载体二):RPC 抵达 dsh 侧同一服务(抓取 + 归一化 + 出处记录),
544
+ * 回传归一化字节与内容寻址 id;桥把字节放进 session/prompt,dsh 二次准入因
545
+ * 直通谓词而 digest 相同(同一次 prompt 内归一化策略一致)。
546
+ *
547
+ * 错误面:RemoteError 一律归一化为 invalidParams——bridge 的 prompt 捕获只
548
+ * 透传 RequestError,其余会变成 internal(对用户不可诊断)。
549
+ */
550
+ admitImageUrls(sessionId: string, urls: readonly string[], opts?: {
551
+ readonly signal?: AbortSignal;
552
+ readonly names?: readonly (string | undefined)[];
553
+ }): Promise<Awaited<ReturnType<NonNullable<SessionDeps['admitImageUrls']>>>>;
554
+ /** 历史回显读字节(载体二):失败一律 undefined(降级占位,不中断回放)。 */
555
+ readImage(_sessionId: string, attachment: unknown): Promise<{
556
+ mediaType: string;
557
+ data: string;
558
+ } | undefined>;
532
559
  applyModeKnobs(session: SessionLike, _agent: AgentLike, knobs: ModeKnobs): void | Promise<void>;
533
560
  defaultSelection(): ConfigModelSelection | undefined;
534
561
  executeCommand(agent: AgentLike, line: string, _signal?: AbortSignal): Promise<{
package/lib/index.js CHANGED
@@ -1,5 +1,59 @@
1
1
  import{MODE_TABLE as e,classify as t,isIgnorable as n}from"@tbox.cn/dsh-acp-bridge-core";import{spawn as r}from"node:child_process";import{randomUUID as i}from"node:crypto";import a,{WebSocketServer as o}from"ws";var s=class extends Error{kind;report;constructor(e,t,n){super(t),this.name=`SupervisorDeploymentError`,this.kind=e,this.report=n}};function c(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!=`object`||!t||Array.isArray(t))return null;let n=t;return n.v===1&&(n.event===`standby`||n.event===`ready`&&typeof n.port==`number`&&typeof n.token==`string`)?t:null}async function l(e,t){let n=await fetch(`http://127.0.0.1:${e}/connect?token=${encodeURIComponent(t)}&interactions=answer`,{redirect:`manual`});if(n.status!==302)throw Error(`/connect 凭据交换期待 302,实得 ${n.status}(port ${e})`);let r=n.headers.get(`set-cookie`);if(r===null)throw Error(`/connect 凭据交换缺 Set-Cookie`);let i=r.split(`;`)[0]??``;if(i===``)throw Error(`/connect 凭据交换缺 Set-Cookie`);return i}function u(e){return e.replace(/((?:token|access_token|refresh_token|cookie|authorization)=)[^&\s]+/gi,`$1[REDACTED]`).replace(/((?:authorization|cookie):\s*)[^\n]+/gi,`$1[REDACTED]`)}var d=class{#e;#t;#n;#r;#i=`idle`;#a=[];#o;#s=!1;#c=!1;#l=0;#u=[];#d=[];#f=[];#p=[];#m;#h=0;#g=[];#_=!1;#v;constructor(e={},t,n){this.#e={startMode:`immediate`,readyTimeoutMs:12e4,backoffBaseMs:1e3,backoffMaxMs:5e3,maxRestartAttempts:3,ringBufferLines:1e3,...e},this.#t=t??f(e),this.#n=n??l,this.#r=e.log??(()=>{})}phase(){return this.#i}onPhaseChange(e){return this.#a.push(e),()=>{this.#a=this.#a.filter(t=>t!==e)}}onStderrLine(e){return this.#p.push(e),()=>{this.#p=this.#p.filter(t=>t!==e)}}async start(){if(this.#i!==`idle`)throw Error(`Supervisor.start 仅 idle 态可调(当前 ${this.#i})`);this.#T(),await this.#S()}async connect(){this.#b(),this.#s=!0,this.#i===`standby`&&!this.#c&&this.#e.startMode===`on-first-connection`&&this.#O(),this.#i!==`ready`&&await this.#S();let e=this.#m;if(e!==void 0&&e.generation===this.#h)return e;let t=this.#y;if(t===void 0)throw Error(`ready 凭据缺席(状态机时序违例)`);let n=await this.#n(t.port,t.token),r={baseUrl:`http://127.0.0.1:${t.port}`,cookie:n,port:t.port,generation:this.#h};return this.#m=r,this.#r(`凭据交换完成(generation ${this.#h},port ${t.port})`),r}async reconnect(){this.#b(),this.#i!==`ready`&&await this.#S();let e=this.#y;if(e===void 0)throw Error(`ready 凭据缺席(状态机时序违例)`);let t=await this.#n(e.port,e.token),n={baseUrl:`http://127.0.0.1:${e.port}`,cookie:t,port:e.port,generation:this.#h};return this.#m=n,this.#r(`凭据再交换完成(generation ${this.#h},port ${e.port})`),n}crashReport(){return[`phase=${this.#i} restarts=${this.#l} generation=${this.#h}`,`exitCodes=${JSON.stringify(this.#u)}`,`phaseHistory=${this.#d.join(` → `)}`,`stderr(环形缓冲尾部 ${this.#f.length} 行):`,...this.#f.map(e=>` ${e}`)].join(`
2
2
  `)}async dispose(){if(this.#_)return;this.#_=!0,this.#v=void 0;let e=this.#o;e!==void 0&&(e.kill(`SIGTERM`),await new Promise(t=>{let n=setTimeout(()=>{e.kill(`SIGKILL`),t()},3e3);e.onExit(()=>{clearTimeout(n),t()})})),this.#w(Error(`Supervisor 已停机`)),this.#x(`disposed`)}#y;#b(){if(this.#_)throw Error(`Supervisor 已停机`);if(this.#i===`idle`)throw Error(`先调用 start()(connect 挂靠 spawn 生命周期)`);if(this.#v!==void 0)throw this.#v.error;if(this.#i===`failed-permanent`||this.#i===`failed-protocol`)throw new s(this.#i===`failed-permanent`?`permanent`:`protocol`,`Supervisor 终态 ${this.#i}`,this.crashReport())}#x(e){this.#i=e,this.#d.push(`${e}@${Date.now()}`),this.#a.forEach(t=>t(e))}#S(){return this.#i===`ready`?Promise.resolve():new Promise((e,t)=>{this.#g.push({generation:this.#h,resolve:e,reject:t})})}#C(){this.#g.splice(0).forEach(e=>e.resolve())}#w(e){this.#g.splice(0).forEach(t=>t.reject(e))}async#T(){for(;;){if(this.#_)return;if(await this.#D(),this.#v!==void 0){this.#x(this.#v.kind===`protocol`?`failed-protocol`:`failed-permanent`);return}return}}#E(e){if(this.#_)return;if(this.#l+=1,this.#l>this.#e.maxRestartAttempts){this.#v={kind:`permanent`,error:new s(`exhausted`,`崩溃退避序列耗尽(${this.#e.maxRestartAttempts} 次)——最后原因:${e}`,this.crashReport())},this.#x(`failed-permanent`),this.#w(this.#v.error);return}let t=Math.min(this.#e.backoffBaseMs*2**(this.#l-1),this.#e.backoffMaxMs);this.#x(`restarting`),this.#r(`瞬时失败(${e})——${t}ms 后第 ${this.#l} 次重启`),setTimeout(()=>{this.#_||this.#D().then(()=>{this.#v!==void 0&&(this.#x(this.#v.kind===`protocol`?`failed-protocol`:`failed-permanent`),this.#w(this.#v.error))})},t)}async#D(){this.#h+=1,this.#m=void 0,this.#c=!1,this.#y=void 0;let e=this.#h;this.#x(`booting`);let t=this.#e.command??[`tboxcode-dsh`],n=this.#t([...t,`server`]);this.#o=n;let r=!1,i;clearTimeout(i),i=setTimeout(()=>{this.#h!==e||this.#i===`ready`||(this.#r(`就绪确认超时——kill 子进程(瞬时面)`),n.kill(`SIGKILL`))},this.#e.readyTimeoutMs),n.onStdoutLine(t=>{if(this.#h!==e)return;let a=c(t);if(!r){if(a===null||a.event!==`standby`){this.#v={kind:`protocol`,error:new s(`protocol`,`首行校验失败(期待 standby 信封,实得 "${t.slice(0,80)}")`,this.crashReport())},this.#x(`failed-protocol`),this.#w(this.#v.error),n.kill(`SIGKILL`);return}r=!0,this.#x(`standby`),(this.#e.startMode===`immediate`||this.#s)&&this.#O();return}if(a===null){this.#i===`ready`&&this.#r(`stdout 违约(ready 后非静默): ${t.slice(0,120)}`),this.#k(`[stdout] ${t}`);return}a.event!==`standby`&&this.#i!==`ready`&&(this.#y=a,this.#x(`ready`),clearTimeout(i),this.#C())}),n.onStderrLine(t=>{if(this.#h!==e)return;let n=u(t);this.#k(n);for(let e of this.#p)try{e(n)}catch{}}),n.onExit(t=>{if(this.#h===e&&(clearTimeout(i),this.#u.push(t),!this.#_&&this.#v===void 0)){if(t===2){this.#v={kind:`permanent`,error:new s(`permanent`,`server 永久失败(退出码 2——config 非法 / 未设 model / profile 损坏)`,this.crashReport())},this.#x(`failed-permanent`),this.#w(this.#v.error);return}if(t===3){this.#v={kind:`protocol`,error:new s(`protocol`,`server 协议版本偏斜(退出码 3——部署错误最显眼信号)`,this.crashReport())},this.#x(`failed-protocol`),this.#w(this.#v.error);return}this.#E(`退出码 ${t??`signal`}`)}})}#O(){this.#c||this.#o===void 0||(this.#c=!0,this.#x(`starting`),this.#o.writeStdin(`${JSON.stringify({v:1,cmd:`start`})}\n`),this.#r(`start 已释放`))}#k(e){this.#f.push(`${Date.now()} ${e}`),this.#f.length>this.#e.ringBufferLines&&this.#f.splice(0,this.#f.length-this.#e.ringBufferLines)}};function f(e){return t=>{let n=r(t[0],t.slice(1),{stdio:[`pipe`,`pipe`,`pipe`],env:{...process.env,...e.env??{}}}),i=``,a=``,o=[],s=[],c=[],l=(e,t,n)=>{for(e+=t.toString();;){let t=e.indexOf(`
3
- `);if(t<0)break;let r=e.slice(0,t);e=e.slice(t+1),n.forEach(e=>e(r))}return e};return n.stdout?.on(`data`,e=>{i=l(i,e.toString(),o)}),n.stderr?.on(`data`,e=>{a=l(a,e.toString(),s)}),n.on(`close`,e=>{i!==``&&o.forEach(e=>e(i)),a!==``&&s.forEach(e=>e(a)),c.forEach(t=>t(e))}),{writeStdin:e=>n.stdin?.write(e),onStdoutLine:e=>o.push(e),onStderrLine:e=>s.push(e),onExit:e=>c.push(e),kill:e=>n.kill(e??`SIGTERM`)}}}function p(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function m(e){return!p(e)||typeof e.type!=`string`||e.type===``||typeof e.seq!=`number`||!Number.isInteger(e.seq)||typeof e.time!=`number`||!(`data`in e)?null:e}function h(e){if(!p(e)||e.type!==`event`)return null;let t=m(e.event);return t===null?null:{type:`event`,event:t}}function g(e){if(!p(e))return null;if(e.type===`snapshot`){let t=p(e.header)?e.header:null;if(t===null||typeof e.cursor!=`number`||typeof e.hasMore!=`boolean`)return null;let n=[];if(Array.isArray(e.records))for(let t of e.records){let e=h(t);if(e===null)return null;n.push(e)}else return null;return{type:`snapshot`,header:t,cursor:e.cursor,records:n,hasMore:e.hasMore,projections:e.projections,...p(e.assistantStream)?{assistantStream:e.assistantStream}:{}}}return e.type===`assistant-stream`?p(e.frame)?{type:`assistant-stream`,frame:e.frame}:null:h(e)}function _(e){if(!p(e)||typeof e.hasMore!=`boolean`||!Array.isArray(e.records))return null;let t=[];for(let n of e.records){let e=h(n);if(e===null)return null;t.push(e)}return{records:t,hasMore:e.hasMore}}function v(e){return p(e)&&(e.type===`ready`&&typeof e.clientId==`string`&&p(e.host)||e.type===`emit`&&typeof e.event==`string`&&Array.isArray(e.args)||e.type===`waterfall`&&typeof e.eventId==`string`&&typeof e.agentId==`string`&&typeof e.event==`string`&&p(e.request)||e.type===`cancel`&&typeof e.eventId==`string`)?e:null}var y=class extends Error{code;details;constructor(e){super(e.message),this.name=`CarrierRpcError`,this.code=e.code,this.details=e.details}},b=class extends Error{constructor(e){super(e),this.name=`CarrierTransportError`}},x=class{#e;#t;#n;#r;#i;#a;#o=!1;#s=!1;constructor(e){this.#e=e.baseUrl.replace(/\/$/,``),this.#t=e.cookie,this.#n=e.refreshCredentials}async unary(e,t){this.#p();try{return await this.#c(e,t)}catch(n){if(!(n instanceof b&&n.message.endsWith(`HTTP 401`))||this.#n===void 0)throw n;return await this.#f(),this.#c(e,t)}}async#c(e,t){let n=i(),r;try{r=await fetch(`${this.#e}/api/${e}`,{method:`POST`,headers:{"content-type":`application/json`,cookie:this.#t},body:JSON.stringify({type:`client-request`,rpcId:n,method:e,payload:{args:t}}),signal:AbortSignal.timeout(6e4)})}catch(t){throw t instanceof Error&&t.name===`TimeoutError`?new b(`unary ${e} 超时(上游 60s 无响应)`):t}if(r.status!==200)throw new b(`unary ${e} HTTP ${r.status}`);let a=await r.json();if(a.type!==`server-response`||a.rpcId!==n)throw new b(`unary ${e} envelope 畸形(type/rpcId 失配)`);if(a.result.ok)return a.result.value;throw new y(a.result.error)}openStream(e,t,n){this.#p();let r=i(),o=!1,s={canceled:!1,onFrame:e=>{e.type===`item`?n.onItem(e.value):e.type===`end`?(s.canceled=!0,n.onEnd?.()):e.type===`error`&&(s.canceled=!0,n.onError?.(e.error??{code:`gateway/internal`,message:`stream error 帧缺 error 字段`}))},onDown:e=>{s.canceled||(s.canceled=!0,e&&n.onError?.({code:`carrier/mux-closed`,message:`mux 插座意外关闭`}),n.onClose?.(e))}};return this.#l().then(n=>{if(o||s.canceled){process.stderr.write(`[carrier] open ABORTED (canceled=${String(o)} entry=${String(s.canceled)}) ${e}\n`);return}n.streams.set(r,s),n.socket.readyState===a.OPEN?(n.socket.send(JSON.stringify({type:`open`,streamId:r,endpoint:e,payload:{args:t}})),process.env.CARRIER_WIRE_DEBUG===`1`&&process.stderr.write(`[carrier] open sent ${e} streamId=${r.slice(0,8)}\n`)):process.stderr.write(`[carrier] open SKIPPED (readyState ${n.socket.readyState}) ${e}\n`)}).catch(e=>{o||s.canceled||(s.canceled=!0,n.onError?.({code:`carrier/mux-open`,message:e.message}),n.onClose?.(!0))}),{cancel:()=>{o=!0,s.canceled=!0;let e=this.#r;e!==void 0&&e.streams.delete(r)&&e.socket.readyState===a.OPEN&&e.socket.send(JSON.stringify({type:`cancel`,streamId:r}))}}}async#l(){let e=this.#r;if(e!==void 0&&e.socket.readyState===a.OPEN)return e;if(this.#i!==void 0)return this.#i;let t=this.#u().finally(()=>{this.#i===t&&(this.#i=void 0)});return this.#i=t,t}async#u(){this.#p(),this.#o&&this.#n!==void 0&&await this.#f();let e=new a(`${S(this.#e)}/api/remote.mux`,{headers:{cookie:this.#t}});await new Promise((t,n)=>{let r=setTimeout(()=>n(new b(`mux 插座打开超时`)),15e3);r.unref(),e.once(`open`,()=>{clearTimeout(r),t()}),e.once(`error`,e=>{clearTimeout(r),n(new b(`mux 插座打开失败: ${e.message}`))}),e.once(`unexpected-response`,(e,t)=>{clearTimeout(r),n(new b(`mux 升级被拒 HTTP ${t.statusCode??`?`}`))})});let t={socket:e,streams:new Map};e.on(`message`,e=>{let n;try{n=JSON.parse(String(e))}catch{return}typeof n.streamId==`string`&&t.streams.get(n.streamId)?.onFrame(n)});let n=!1;return e.on(`close`,()=>this.#d(t,n)),e.on(`error`,()=>{n=!0}),this.#r=t,this.#o=!0,t}#d(e,t){if(this.#r===e){this.#r=void 0;for(let n of e.streams.values())n.onDown(t);e.streams.clear()}}#f(){if(this.#a!==void 0)return this.#a;let e=(async()=>{let e=this.#n;if(e===void 0)return;let t=await e();this.#t=t.cookie,this.#e=t.baseUrl.replace(/\/$/,``)})().finally(()=>{this.#a===e&&(this.#a=void 0)});return this.#a=e,e}openEvents(e){let t,n=n=>{switch(n.type){case`ready`:t=n.clientId,e.onReady(n);return;case`emit`:e.onEmit(n);return;case`waterfall`:e.onWaterfall(n);return;case`cancel`:e.onCancel(n);return}},r=this.openStream(`$events`,{},{onItem:t=>{let i=v(t);if(i===null){e.onClose?.(!1),r.cancel();return}n(i)},onClose:t=>e.onClose?.(t)});return{respond:async(e,n)=>{if(t===void 0)throw new b(`waterfall 应答先于 ready 帧(clientId 缺席)`);await this.unary(`$events/result`,{clientId:t,eventId:e,outcome:n})},close:()=>r.cancel()}}dispose(){this.#s=!0,this.#r?.socket.close(),this.#r=void 0}#p(){if(this.#s)throw new b(`carrier 已释放`)}};function S(e){if(e.startsWith(`https://`))return`wss://${e.slice(8)}`;if(e.startsWith(`http://`))return`ws://${e.slice(7)}`;throw new b(`baseUrl 非法(期待 http(s)://,实得 ${e})`)}function C(e,r){let i=m(e);if(i===null)return r!==void 0&&(r.invalid+=1),null;if(t(i.type)===`project`)return typeof i.data!=`object`||i.data===null||Array.isArray(i.data)?(r!==void 0&&(r.opaqueWarn+=1),{kind:`opaque`,event:i,level:`warn`}):(r!==void 0&&(r.consumable+=1),{kind:`consumable`,event:i});let a=n(i)?`debug`:`warn`;return a===`debug`?r!==void 0&&(r.opaqueDebug+=1):r!==void 0&&(r.opaqueWarn+=1),{kind:`opaque`,event:i,level:a}}var w=class{#e;#t;#n={invalid:0,opaqueDebug:0,opaqueWarn:0,consumable:0};#r=new Map;#i=0;constructor(e,t){this.#e=e,this.#t=t?.reopenBaseMs??1e3}open(e,t){let n=this.#r.get(e);if(n!==void 0&&!n.closed)return n.handlers=t,{close:()=>this.close(e)};let r={sessionId:e,handlers:t,handle:void 0,cursor:void 0,baseline:void 0,streamSeenRevision:!1,reopening:!1,backoffMs:this.#t,closed:!1,pending:[]};return this.#r.set(e,r),this.#a(r),{close:()=>this.close(e)}}close(e){let t=this.#r.get(e);t!==void 0&&(t.closed=!0,t.handle?.cancel(),this.#r.delete(e))}stats(){let e=0,t=0;for(let n of this.#r.values())n.closed||(n.reopening||n.cursor===void 0?t++:e++);return{live:e,reopening:t,decoded:{...this.#n},gapsRepaired:this.#i}}#a(e){e.closed||(e.reopening=e.cursor!==void 0,e.handle=this.#e.openStream(`session/follow`,{request:{address:{kind:`session`,sessionId:e.sessionId},assistantStream:!0}},{onItem:t=>this.#s(e,t),onEnd:()=>this.#o(e,`stream end`),onError:t=>this.#o(e,`${t.code}: ${t.message}`),onClose:t=>{t&&this.#o(e,`socket error`)}}))}#o(e,t){if(e.closed)return;e.handle=void 0,e.handlers.onDown(t);let n=e.backoffMs;e.backoffMs=Math.min(e.backoffMs*2,3e4),e.baseline=void 0,e.streamSeenRevision=!1,e.reopening=!0,setTimeout(()=>{e.closed||this.#a(e)},n)}#s(e,t){if(t.type===`snapshot`){this.#c(e,t);return}if(e.cursor!==void 0){if(e.reopening){e.pending.push(t);return}this.#d(e,t)}}#c(e,t){let n=e.cursor;if(n!==void 0&&t.cursor<n){e.handlers.onDown(`cursor 回退:${String(t.cursor)} < ${String(n)}`);return}e.baseline=t.assistantStream,e.streamSeenRevision=!1,e.reopening=!0,e.handlers.onSnapshot(t.header,t.cursor,t.projections,t.assistantStream),this.#l(e,t,n)}async#l(e,t,n){try{let r=[];if(n!==void 0&&t.records.length>0){let i=t.records[0]?.event.seq??t.cursor;i>n+1&&(r.push(...await this.#u(e,n+1,i)),this.#i+=r.length)}for(let e of t.records)r.push(e.event);for(let t of r)this.#f(e,t);let i=e.pending;e.pending=[],e.reopening=!1,e.cursor=t.cursor,e.backoffMs=this.#t;for(let t of i)this.#d(e,t)}catch(t){e.handlers.onDown(`backlog 补齐失败:${String(t)}`)}}async#u(e,t,n){let r=[],i=n;for(;i>t;){let n=_(await this.#e.unary(`session/page`,{request:{address:{kind:`session`,sessionId:e.sessionId},throughSeq:i-1,beforeSeq:t,maxMessages:200}}));if(n===null)throw new b(`session/page 帧畸形(records/hasMore 缺失)`);for(let e of n.records)r.push(e.event);let a=n.records[0]?.event.seq;if(a===void 0||a<=t||(i=a,!n.hasMore))break}return r.sort((e,t)=>e.seq-t.seq),r}#d(e,t){if(t.type===`assistant-stream`){if(!e.streamSeenRevision){e.streamSeenRevision=!0;let n=(e.baseline?.revision??-1)+1;if(e.baseline!==void 0&&t.frame.revision!==n){e.handlers.onDown(`assistant-stream 衔接断裂:revision ${String(t.frame.revision)} ≠ ${String(n)}`);return}}e.handlers.onAssistantStream(t.frame);return}t.type===`event`&&this.#f(e,t.event)}#f(e,t){let n=C(t,this.#n);n!==null&&n.kind===`consumable`&&e.handlers.onEvent(n.event)}async readAll(e){return await new Promise((t,n)=>{let r=new Map,i,a,o=!1,s=this.#e.openStream(`session/follow`,{request:{address:{kind:`session`,sessionId:e}}},{onItem:c=>{o||c.type===`snapshot`&&(o=!0,i=c.header,a=c.projections,s.cancel(),this.#p(e,c,r).then(e=>t({header:i,events:e,projections:a}),e=>n(e)))},onEnd:()=>{o||(o=!0,n(new b(`session/follow 在 snapshot 前关闭`)))},onError:e=>{o||(o=!0,n(new y(e)))}})})}async#p(e,t,n){let r=[];for(let e of t.records)r.push(e.event);let i=t.records.length>0?t.records[0]?.event.seq:void 0;for(;t.hasMore===!0;){let n=_(await this.#e.unary(`session/page`,{request:{address:{kind:`session`,sessionId:e},throughSeq:t.cursor,...i===void 0?{}:{beforeSeq:i},maxMessages:200}}));if(n===null)throw new b(`session/page 帧畸形(records/hasMore 缺失)`);for(let e of n.records)r.push(e.event);if(!n.hasMore||n.records.length===0)break;let a=n.records[0]?.event.seq;if(a===void 0||a===0)break;i=a}let a=new Map;for(let e of r)a.set(e.seq,e);let o=[...a.values()].sort((e,t)=>e.seq-t.seq);for(let e=0;e<o.length;e++){let t=o[e];if(t?.seq!==e)throw new y({code:`gateway/internal`,message:`journal 连续性断裂:位置 ${String(e)} 实得 seq ${String(t?.seq)}`});let r=C(t,this.#n);r?.kind===`consumable`&&n.set(t.seq,r.event)}return[...n.values()]}},T=class{#e=new Map;#t=new Map;#n=new Map;#r=new Map;#i;#a;#o=0;#s=0;constructor(e,t){this.#i=e,this.#a=t}attachConnection(e,t,n){this.#e.set(e,{connId:e,send:t,ctx:n})}detachConnection(e){this.#e.delete(e);for(let[t,n]of this.#t)n.delete(e),n.size===0&&this.#t.delete(t),this.#a?.onSessionUnbind?.(e,t);for(let[t,n]of this.#n)n===e&&this.#n.delete(t)}bind(e,t){let n=this.#t.get(t);n===void 0&&(n=new Set,this.#t.set(t,n));let r=n.has(e);n.add(e),r||this.#a?.onSessionBind?.(e,t)}unbind(e,t){this.#t.get(t)?.delete(e),this.#a?.onSessionUnbind?.(e,t)}boundConnIds(e){return[...this.#t.get(e)??[]]}ctxOf(e){return this.#e.get(e)?.ctx}routeResolved(e,t,n){this.routeExt({method:e,payload:t},n===void 0?void 0:{excludeConnId:n})}beginReplayCount(e){this.#r.set(e,0)}takeReplayCount(e){let t=this.#r.get(e);return this.#r.delete(e),t}setTurnOrigin(e,t){this.#n.set(e,t)}clearTurnOrigin(e){this.#n.delete(e)}route(e){let t=e.sessionId;if(t!==void 0&&this.#a?.onSessionUpdate!==void 0){let n=e.update??e;E(this.#i,`onSessionUpdate`,()=>this.#a?.onSessionUpdate?.(t,n))}let n;if(t===void 0)n=[...this.#e.keys()];else{let r=this.#n.get(t),i=e.update?.sessionUpdate===`user_message_chunk`;n=[...this.#t.get(t)??[]],r!==void 0&&i&&(n=n.filter(e=>e!==r),this.#s++);let a=this.#a?.fanout===void 0?void 0:E(this.#i,`fanout`,()=>this.#a?.fanout?.(e,n));if(a!==void 0&&(n=[...a]),n.length===0){this.#o++;return}}for(let t of n){let n=this.#e.get(t);if(n===void 0)continue;let r=e;if(this.#a?.transformOutbound!==void 0){let t=E(this.#i,`transformOutbound`,()=>this.#a?.transformOutbound?.(e,n.ctx));if(t===null)continue;t!==void 0&&(r=t)}n.send({jsonrpc:`2.0`,method:`session/update`,params:r});let i=this.#r.get(t);i!==void 0&&this.#r.set(t,i+1)}}routeExt(e,t){let n=typeof e.payload.sessionId==`string`?e.payload.sessionId:void 0,r=n===void 0?[...this.#e.keys()]:[...this.#t.get(n)??[]];t?.excludeConnId!==void 0&&(r=r.filter(e=>e!==t.excludeConnId));for(let t of r)this.#e.get(t)?.send({jsonrpc:`2.0`,method:e.method,params:e.payload})}stats(){return{connections:this.#e.size,dropped:this.#o,suppressed:this.#s}}};function E(e,t,n){try{return n()}catch(n){e.warn(`gateway hook ${t} failed (fail-open): ${String(n)}`);return}}function D(e){if(typeof e!=`object`||!e)return e;let t=e;if(t.type!==`image`)return e;let n=t.attachment;if(typeof n!=`object`||!n)return e;let r=n;return typeof r.mediaType!=`string`||typeof r.data!=`string`?e:{type:`image`,mediaType:r.mediaType,data:r.data,...typeof r.name==`string`?{name:r.name}:{}}}const O=1e3,k=3e4;function A(e){let t=e,n=t?.values?.modelSelection?.next??t?.values?.modelSelection?.lastUsed;if(!(n==null||typeof n.provider!=`string`||typeof n.model!=`string`))return{provider:n.provider,model:n.model,...typeof n.reasoningEffort==`string`?{reasoningEffort:n.reasoningEffort}:{}}}function j(e,t){return e===void 0||t===void 0?e===t:e.provider===t.provider&&e.model===t.model&&e.reasoningEffort===t.reasoningEffort}function M(e){if(typeof e!=`object`||!e)return-1;let t=e.asOfSeq;return typeof t==`number`?t:-1}function N(e){return e.pendingSelection??A(e.projections)??e.fallbackSelection}function P(e){return{id:e.id,get header(){let t=e.header;return{...t?.cwd===void 0?{}:{cwd:t.cwd},...t?.origin===void 0?{}:{origin:t.origin},...t?.parentSession===void 0?{}:{parentSession:t.parentSession},...t?.createdAt===void 0?{}:{createdAt:t.createdAt}}},requestHeader(){let t=N(e);if(t!==void 0)return{config:{provider:t.provider,model:t.model,...t.reasoningEffort===void 0?{}:{reasoningEffort:t.reasoningEffort}}}}}}function F(e,t,n){return{id:e.id,session:e.session,model:{current:()=>N(e),select:async n=>{j(e.pendingSelection??A(e.projections),n)||(e.pendingSelection=(await t.unary(`session/selectModel`,{request:{sessionId:e.id,...n}}))?.selected??n,e.pendingAtSeq=M(e.projections))}},cancel:async n=>{await t.unary(`session/cancel`,{request:{sessionId:e.id}})},followup:t=>{n(e,t)}}}var I=class{logger;#e;#t;#n;#r=new Map;#i=new Map;#a=new Set;#o=new Set;#s=new Set;#c=new Set;#l=new Set;#u;#d=O;#f;#p=O;#m;#h={groups:[],failures:[]};#g=0;#_;#v=!1;#y;constructor(e){this.#e=e.carrier,this.#t=e.pool,this.#n=e.logger,this.logger=e.logger,this.#y=this.#E(),this.#O(),this.#A()}async createAgent(e){return await this.#b(e)}async resumeAgent(e){return await this.#b(e)}async#b(e){let t=(await this.#e.unary(`session/create`,{request:{sessionId:e.sessionId,cwd:e.cwd}})).sessionId,n=this.#r.get(t);if(n!==void 0)return await this.#i.get(t)?.catch(()=>{}),n.fallbackSelection=this.#_,await e.configureScope?.(this.#C(n),n.agent),{agent:n.agent,dispose:async()=>this.#S(t)};let r={id:t,header:{version:1,id:t,createdAt:0,cwd:e.cwd,isSeeded:!1},projections:{},promptInflight:!1};r.session=P(r),r.agent=F(r,this.#e,(e,t)=>this.#w(e,t));let i=r;this.#r.set(t,i);try{let n=this.#x(t).then(e=>{e!==void 0&&(i.projections=e)});this.#i.set(t,n),await n,this.#i.delete(t),this.#_===void 0&&(await this.#y,this.#_===void 0&&!this.#v&&(this.#v=!0,await this.#E())),i.fallbackSelection=this.#_,await e.configureScope?.(this.#C(i),i.agent),this.#t.open(t,this.#D(i))}catch(e){throw await this.#S(t).catch(()=>{}),e}return{agent:i.agent,dispose:async()=>this.#S(t)}}async#x(e){try{let t=await this.#e.unary(`session/projections`,{request:{sessionId:e}});if(typeof t!=`object`||!t||Array.isArray(t))return;let n=t,r=n.values;return typeof r!=`object`||!r||Array.isArray(r)?void 0:{asOfSeq:typeof n.asOfSeq==`number`?n.asOfSeq:-1,values:r}}catch(t){this.#n.debug(`projection prime failed (${e}): ${String(t)}`);return}}#S(e){return this.#t.close(e),this.#r.delete(e),this.#i.delete(e),Promise.resolve()}#C(e){return{on:(e,t)=>()=>{},tools:{restrict:e=>void 0}}}async#w(e,t){e.promptInflight=!0;let n=t.content.map(D);await this.#e.unary(`session/prompt`,{request:{requestId:t.id,sessionId:e.id,mode:`steer`,content:n}})}persistence={stat:async(e,t)=>{let n=await this.#e.unary(`tboxcode/sessions.stat`,{request:{sessionId:e}});if(n!==null)return{header:n.header}},list:async e=>(await this.#e.unary(`session/list`,{_request:{}})).items.map(e=>({header:{id:e.sessionId,...e.cwd===void 0?{}:{cwd:e.cwd},...e.origin===void 0?{}:{origin:e.origin},...e.parentSessionId===void 0?{}:{parentSession:e.parentSessionId},createdAt:e.updatedAt}})),openHistoryRead:async(e,t)=>{let n=await this.#t.readAll(e);return{read:async()=>({events:n.events}),close:async()=>{}}}};sessionStore={get:e=>this.#r.get(e)?.session,flush:async e=>{await this.#e.unary(`tboxcode/sessions.flush`,{request:{sessionId:e.id}})}};llm={listProviders:()=>this.#T().groups.map(e=>({id:e.id,name:e.name})),listModels:async e=>(this.#T().groups.find(t=>t.id===e)?.models??[]).map(e=>({id:String(e.id),name:String(e.name),...e.description===void 0?{}:{description:String(e.description)}})),resolveModelInfo:async(e,t)=>{let n=this.#T().groups.find(t=>t.id===e)?.models.find(e=>e.id===t)?.reasoning;return{reasoning:{defaultEffort:n?.defaultEffort,efforts:n?.efforts??[]}}},resolveCallConfig:async e=>e};#T(){return Date.now()-this.#g>3e4&&this.#E(),this.#h}async#E(){try{this.#h=await this.#e.unary(`session/modelCatalog`,{}),this.#g=Date.now();let e=await this.#e.unary(`tboxcode/selection.default`,{});this.#_=typeof e.provider==`string`&&typeof e.model==`string`?{provider:e.provider,model:e.model,...e.reasoningEffort===void 0?{}:{reasoningEffort:e.reasoningEffort}}:void 0}catch(e){this.#n.warn(`catalog warm failed: ${String(e)}`)}}async admitPromptContent(e){return e.map(e=>e.type===`text`?e:{type:`image`,attachment:{mediaType:e.mediaType,data:e.data,...e.name===void 0?{}:{name:e.name}}})}applyModeKnobs(t,n,r){let i=Object.entries(e).find(([,e])=>e.sandbox===r.sandbox&&e.approval===r.approval)?.[0];if(i===void 0)throw Error(`tboxcode: mode knobs 无对位(${String(r.sandbox)}/${String(r.approval)}——MODE_TABLE 外组合)`);return this.#e.unary(`tboxcode/mode`,{request:{agentId:t.id,mode:i}}).then(()=>void 0)}defaultSelection(){return this.#_}async executeCommand(e,t,n){let r=await this.#e.unary(`tboxcode/commands.execute`,{request:{agentId:e.id,line:t}});return r?.commandId===void 0?void 0:{commandId:r.commandId}}async listCommands(e){return await this.#e.unary(`tboxcode/commands.list`,{request:{agentId:e.id}})}async listUserInvocableSkills(e){return await this.#e.unary(`tboxcode/skills.userInvocable`,{request:{agentId:e.id}})}onSessionEvent(e){let t=e;return this.#a.add(t),()=>this.#a.delete(t)}onAssistantStream(e){return this.#o.add(e),()=>this.#o.delete(e)}onInboxClaimed(e){return this.#s.add(e),()=>this.#s.delete(e)}onAgentError(e){return this.#c.add(e),()=>this.#c.delete(e)}sessionToolDenies(){return[]}onCommandSurfaceChanged(e){return this.#l.add(e),()=>this.#l.delete(e)}sessionIds(){return[...this.#r.keys()]}hasInflightPrompt(e){return this.#r.get(e)?.promptInflight===!0}poolLive(){return this.#t.stats().live>0}poolEntries(){return this.#r.size}settlePrompt(e,t){let n=this.#r.get(e);if(!(n===void 0||!n.promptInflight)){n.promptInflight=!1;for(let e of this.#c)e({agent:n.agent,turn:0,error:t})}}#D(e){return{onSnapshot:(t,n,r)=>{e.header=t;let i=M(r);e.pendingSelection!==void 0&&i>(e.pendingAtSeq??-1)&&A(r)!==void 0&&(e.pendingSelection=void 0,e.pendingAtSeq=void 0),e.projections=r},onEvent:t=>{t.type===`turn/end`&&(e.promptInflight=!1);for(let n of this.#a)n(e.session,t)},onAssistantStream:t=>{let n={type:t.type??(t.finish===void 0?t.index===0?`start`:`chunk`:`end`),attemptId:t.attemptId,...t.turn===void 0?{}:{turn:t.turn},...t.step===void 0?{}:{step:t.step},...t.chunk===void 0?{}:{chunk:t.chunk}};for(let t of this.#o)t({agent:e.agent,frame:n})},onDown:t=>this.#n.warn(`follow pool down (${e.id}): ${t}`)}}#O(){this.#u=this.#e.openStream(`tboxcode/agent.watch`,{},{onItem:e=>{this.#n.debug(`agent.watch item: ${JSON.stringify(e).slice(0,160)} states=${[...this.#r.keys()].join(`,`)}`);let t=this.#r.get(e.sessionId);if(t!==void 0){if(e.kind===`inboxClaimed`)for(let n of this.#s)n({agent:t.agent,message:{...e.messageId===void 0?{}:{id:e.messageId}},turn:e.turn??0});else if(e.kind===`error`)for(let n of this.#c)n({agent:t.agent,turn:0,error:e.error??`unknown agent error`})}},onError:e=>{this.#n.warn(`agent.watch stream error: ${JSON.stringify(e).slice(0,200)}`),this.#k()},onClose:e=>{e&&(this.#n.warn(`agent.watch stream closed`),this.#k())}})}#k(){let e=this.#d;this.#d=Math.min(this.#d*2,k),setTimeout(()=>{this.#O(),this.#d=O},e)}#A(){let e=()=>{for(let e of this.#l)e()};this.#f=L(this.#e,e,this.#n),this.#m=this.#e.openStream(`tboxcode/skills.watch`,{},{onItem:()=>e(),onError:()=>this.#j(),onClose:e=>{e&&this.#j()}})}#j(){let e=this.#p;this.#p=Math.min(this.#p*2,k),setTimeout(()=>{this.#A(),this.#p=O},e)}dispose(){this.#u?.cancel(),this.#f?.close(),this.#m?.cancel()}};function L(e,t,n){return e.openEvents({onReady:()=>n.debug(`commands/change $events ready`),onEmit:e=>{e.event===`commands/change`&&t()},onWaterfall:()=>{},onCancel:()=>{},onClose:e=>{e&&n.warn(`commands/change $events closed with error`)}})}var R=class{#e;#t;#n;#r;#i;#a;#o=!1;#s;constructor(e,t){this.#e=e,this.#t=t?.timeoutMs??12e4,this.#n=t?.tickMs??1e3,this.#r=t?.now??Date.now,this.#i=t?.logger??{warn:()=>{},info:()=>{},debug:()=>{}}}start(){this.#s=setInterval(()=>this.tick(),this.#n)}stop(){this.#s!==void 0&&clearInterval(this.#s),this.#s=void 0}tick(){if(!(this.#e.poolEntries()>0&&!this.#e.poolLive())){this.#a=void 0,this.#o=!1;return}if(this.#a===void 0){this.#a=this.#r();return}if(this.#o||this.#r()-this.#a<this.#t)return;this.#o=!0;let e=this.#r()-this.#a;for(let t of this.#e.sessionIds())this.#e.hasInflightPrompt(t)&&(this.#i.warn(`carrier timeout settle (${t}): downMs=${String(e)}`),this.#e.settle(t,Error(`tboxcode carrier-timeout (downMs=${String(e)})`)))}snapshot(){return{down:this.#a!==void 0,downSince:this.#a,settled:this.#o}}};const z=6e4,B=36e5,V=3e4,H=-32001;var U=class{#e=new Map;#t;constructor(e){this.#t=e}get size(){return this.#e.size}pendingOf(e){for(let t of this.#e.values())if(t.sessionId===e)return t}begin(e){let t=e.event===`user-questions/request`?`elicitation`:e.event===`approval/request`?`permission`:void 0;if(t===void 0||this.#e.has(e.eventId))return;let n=this.#t.sessionIdOfAgent(e.agentId);if(n===void 0){this.#l(e.eventId,{kind:`rejected`,error:{code:`gateway/agent-not-found`,message:`agent ${e.agentId} not managed by gateway`}});return}let r={kind:t,sessionId:n,eventId:e.eventId,frame:e,asked:new Map,state:`active`,budgetStartedAt:this.#t.now()};this.#e.set(e.eventId,r),this.#n(r),this.#s(r)}cancel(e){let t=this.#e.get(e.eventId);t===void 0||t.state===`settled`||this.#c(t,{kind:`result`,value:`cancelled`},`turn`)}attach(e,t){for(let n of this.#e.values()){if(n.sessionId!==t||n.state!==`grace`)continue;let r=n.graceTimer;n.graceTimer=void 0,r!==void 0&&this.#t.timers.clear(r),n.state=`active`,this.#t.logger.info(`answerer: grace broken by attach (${n.eventId} conn=${e})`),this.#n(n)}}switchBack(e,t){this.attach(e,t)}disconnect(e){for(let t of this.#e.values())t.asked.delete(e)&&t.state===`active`&&t.asked.size===0&&this.#o(t,`member disconnected`)}dispose(){for(let e of[...this.#e.values()])e.state!==`settled`&&this.#c(e,{kind:`result`,value:`cancelled`},`dispose`);this.#e.clear()}#n(e){let t=this.#t.eligibleConns(e.sessionId).filter(t=>!e.asked.has(t)).filter(t=>e.kind===`permission`||this.#t.capsOf(t));if(t.length===0){this.#o(e,`no eligible connections`);return}for(let n of t){let t={connId:n};e.kind===`permission`&&(t.timer=this.#t.timers.set(()=>{e.state!==`active`||!e.asked.has(n)||(e.asked.delete(n),this.#t.logger.info(`answerer: member timeout (${e.eventId} conn=${n})`),e.asked.size===0&&this.#o(e,`all members timed out`))},V)),e.asked.set(n,t),this.#r(e,n)}}async#r(e,t){let n=e.kind===`elicitation`?this.#t.buildQuestionParams(e.sessionId,e.frame):{callId:e.frame.request.callId};try{let r=await this.#t.dispatch(t,e.kind,n);if(e.state===`settled`||!e.asked.has(t))return;let i=this.#i(e,r);if(i.abstain){this.#a(e,t,`abstained`);return}this.#c(e,i.outcome,t)}catch(n){if(e.state===`settled`||!e.asked.has(t))return;if(n.code===H){this.#a(e,t,`abstained`);return}this.#t.logger.warn(`answerer: dispatch failed (${e.eventId} conn=${t}): ${n instanceof Error?n.message:String(n)}`),this.#a(e,t,`dispatch failed`)}}#i(e,t){if(e.kind===`permission`){let e=t?.outcome;return e?.outcome===`cancelled`?{abstain:!1,outcome:{kind:`result`,value:`cancelled`}}:{abstain:!1,outcome:{kind:`result`,value:e?.optionId===`allow-once`?`allowed-once`:`rejected`}}}let n=t;return n?.action===`accept`?{abstain:!1,outcome:{kind:`result`,value:n.content??{}}}:{abstain:!1,outcome:{kind:`rejected`,error:{code:n?.action===`decline`?`ASK_DECLINED`:`ASK_ABORTED`,message:`ask_user_question ${n?.action===`decline`?`declined`:`cancelled`} by client`}}}}#a(e,t,n){let r=e.asked.get(t);r?.timer!==void 0&&this.#t.timers.clear(r.timer),e.asked.delete(t),this.#t.logger.debug(`answerer: member dropped (${e.eventId} conn=${t} ${n})`),e.state===`active`&&e.asked.size===0&&this.#o(e,`all members out (${n})`)}#o(e,t){e.state===`active`&&(e.state=`grace`,e.graceTimer=this.#t.timers.set(()=>{this.#c(e,e.kind===`elicitation`?{kind:`rejected`,error:{code:`ASK_ABORTED`,message:`ask_user_question grace window expired`}}:{kind:`result`,value:`cancelled`},`grace`)},z),this.#t.logger.info(`answerer: grace entered (${e.eventId} ${t})`))}#s(e){let t=B-(this.#t.now()-e.budgetStartedAt);if(t<=0){this.#c(e,e.kind===`elicitation`?{kind:`rejected`,error:{code:`ASK_ABORTED`,message:`ask_user_question form budget exhausted`}}:{kind:`result`,value:`cancelled`},`budget`);return}this.#t.timers.set(()=>{e.state!==`settled`&&(this.#t.logger.warn(`answerer: form budget exhausted (${e.eventId})`),this.#c(e,e.kind===`elicitation`?{kind:`rejected`,error:{code:`ASK_ABORTED`,message:`ask_user_question form budget exhausted`}}:{kind:`result`,value:`cancelled`},`budget`))},t)}#c(e,t,n){if(e.state!==`settled`){e.state=`settled`,e.settledOutcome=t,e.respondedBy=n,e.graceTimer!==void 0&&(this.#t.timers.clear(e.graceTimer),e.graceTimer=void 0);for(let t of e.asked.values())t.timer!==void 0&&this.#t.timers.clear(t.timer);e.asked.clear(),this.#l(e.eventId,t),this.#t.resolvedNotify(e.kind,{sessionId:e.sessionId,eventId:e.eventId,outcome:t,respondedBy:n},typeof n==`string`&&n!==`grace`&&n!==`turn`&&n!==`dispose`&&n!==`budget`?n:void 0),this.#t.logger.info(`answerer: settled (${e.eventId} by=${n} kind=${t.kind})`)}}async#l(e,t){try{await this.#t.respond(e,t)}catch(t){this.#t.logger.warn(`answerer: respond failed (${e}): ${t instanceof Error?t.message:String(t)}`)}}};function W(e,t){e.gate.active||(e.gate.active=!0,e.gate.timer=setTimeout(()=>{e.gate.active&&(t.warn(`gateway load gate timeout (${e.connId})——释放缓存帧`),G(e,!0))},3e4),e.gate.timer.unref?.())}function G(e,t){if(!e.gate.active)return[];e.gate.active=!1,e.gate.timer!==void 0&&clearTimeout(e.gate.timer),e.gate.timer=void 0;let n=t?e.gate.frames.splice(0):[];return e.gate.frames.length=0,n}function K(e,t){e.socket.readyState===e.socket.OPEN&&e.socket.send(JSON.stringify(t))}function q(e,t,n){let{core:r,hooks:i,authenticate:a,logger:s}=n,c=new T(s,i),l=new o({noServer:!0}),u=new Set;r.io.notify=async e=>{c.route(e)},r.io.extNotify=async e=>{c.routeExt(e)};let d=(e,n,o)=>{new URL(e.url??`/`,`http://localhost`).pathname===t&&(async()=>{if(!(a===void 0||await J(a,e,s))){n.write(`HTTP/1.1 401 Unauthorized\r
3
+ `);if(t<0)break;let r=e.slice(0,t);e=e.slice(t+1),n.forEach(e=>e(r))}return e};return n.stdout?.on(`data`,e=>{i=l(i,e.toString(),o)}),n.stderr?.on(`data`,e=>{a=l(a,e.toString(),s)}),n.on(`close`,e=>{i!==``&&o.forEach(e=>e(i)),a!==``&&s.forEach(e=>e(a)),c.forEach(t=>t(e))}),{writeStdin:e=>n.stdin?.write(e),onStdoutLine:e=>o.push(e),onStderrLine:e=>s.push(e),onExit:e=>c.push(e),kill:e=>n.kill(e??`SIGTERM`)}}}function p(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function m(e){return!p(e)||typeof e.type!=`string`||e.type===``||typeof e.seq!=`number`||!Number.isInteger(e.seq)||typeof e.time!=`number`||!(`data`in e)?null:e}function h(e){if(!p(e)||e.type!==`event`)return null;let t=m(e.event);return t===null?null:{type:`event`,event:t}}function ee(e){if(!p(e))return null;if(e.type===`snapshot`){let t=p(e.header)?e.header:null;if(t===null||typeof e.cursor!=`number`||typeof e.hasMore!=`boolean`)return null;let n=[];if(Array.isArray(e.records))for(let t of e.records){let e=h(t);if(e===null)return null;n.push(e)}else return null;return{type:`snapshot`,header:t,cursor:e.cursor,records:n,hasMore:e.hasMore,projections:e.projections,...p(e.assistantStream)?{assistantStream:e.assistantStream}:{}}}return e.type===`assistant-stream`?p(e.frame)?{type:`assistant-stream`,frame:e.frame}:null:h(e)}function te(e){if(!p(e)||typeof e.hasMore!=`boolean`||!Array.isArray(e.records))return null;let t=[];for(let n of e.records){let e=h(n);if(e===null)return null;t.push(e)}return{records:t,hasMore:e.hasMore}}function ne(e){return p(e)&&(e.type===`ready`&&typeof e.clientId==`string`&&p(e.host)||e.type===`emit`&&typeof e.event==`string`&&Array.isArray(e.args)||e.type===`waterfall`&&typeof e.eventId==`string`&&typeof e.agentId==`string`&&typeof e.event==`string`&&p(e.request)||e.type===`cancel`&&typeof e.eventId==`string`)?e:null}var re=class extends Error{code;details;constructor(e){super(e.message),this.name=`CarrierRpcError`,this.code=e.code,this.details=e.details}},g=class extends Error{constructor(e){super(e),this.name=`CarrierTransportError`}},ie=class{#e;#t;#n;#r;#i;#a;#o=!1;#s=!1;constructor(e){this.#e=e.baseUrl.replace(/\/$/,``),this.#t=e.cookie,this.#n=e.refreshCredentials}async unary(e,t){this.#p();try{return await this.#c(e,t)}catch(n){if(!(n instanceof g&&n.message.endsWith(`HTTP 401`))||this.#n===void 0)throw n;return await this.#f(),this.#c(e,t)}}async#c(e,t){let n=i(),r;try{r=await fetch(`${this.#e}/api/${e}`,{method:`POST`,headers:{"content-type":`application/json`,cookie:this.#t},body:JSON.stringify({type:`client-request`,rpcId:n,method:e,payload:{args:t}}),signal:AbortSignal.timeout(6e4)})}catch(t){throw t instanceof Error&&t.name===`TimeoutError`?new g(`unary ${e} 超时(上游 60s 无响应)`):t}if(r.status!==200)throw new g(`unary ${e} HTTP ${r.status}`);let a=await r.json();if(a.type!==`server-response`||a.rpcId!==n)throw new g(`unary ${e} envelope 畸形(type/rpcId 失配)`);if(a.result.ok)return a.result.value;throw new re(a.result.error)}openStream(e,t,n){this.#p();let r=i(),o=!1,s={canceled:!1,onFrame:e=>{e.type===`item`?n.onItem(e.value):e.type===`end`?(s.canceled=!0,n.onEnd?.()):e.type===`error`&&(s.canceled=!0,n.onError?.(e.error??{code:`gateway/internal`,message:`stream error 帧缺 error 字段`}))},onDown:e=>{s.canceled||(s.canceled=!0,e&&n.onError?.({code:`carrier/mux-closed`,message:`mux 插座意外关闭`}),n.onClose?.(e))}};return this.#l().then(n=>{if(o||s.canceled){process.stderr.write(`[carrier] open ABORTED (canceled=${String(o)} entry=${String(s.canceled)}) ${e}\n`);return}n.streams.set(r,s),n.socket.readyState===a.OPEN?(n.socket.send(JSON.stringify({type:`open`,streamId:r,endpoint:e,payload:{args:t}})),process.env.CARRIER_WIRE_DEBUG===`1`&&process.stderr.write(`[carrier] open sent ${e} streamId=${r.slice(0,8)}\n`)):process.stderr.write(`[carrier] open SKIPPED (readyState ${n.socket.readyState}) ${e}\n`)}).catch(e=>{o||s.canceled||(s.canceled=!0,n.onError?.({code:`carrier/mux-open`,message:e.message}),n.onClose?.(!0))}),{cancel:()=>{o=!0,s.canceled=!0;let e=this.#r;e!==void 0&&e.streams.delete(r)&&e.socket.readyState===a.OPEN&&e.socket.send(JSON.stringify({type:`cancel`,streamId:r}))}}}async#l(){let e=this.#r;if(e!==void 0&&e.socket.readyState===a.OPEN)return e;if(this.#i!==void 0)return this.#i;let t=this.#u().finally(()=>{this.#i===t&&(this.#i=void 0)});return this.#i=t,t}async#u(){this.#p(),this.#o&&this.#n!==void 0&&await this.#f();let e=new a(`${ae(this.#e)}/api/remote.mux`,{headers:{cookie:this.#t}});await new Promise((t,n)=>{let r=setTimeout(()=>n(new g(`mux 插座打开超时`)),15e3);r.unref(),e.once(`open`,()=>{clearTimeout(r),t()}),e.once(`error`,e=>{clearTimeout(r),n(new g(`mux 插座打开失败: ${e.message}`))}),e.once(`unexpected-response`,(e,t)=>{clearTimeout(r),n(new g(`mux 升级被拒 HTTP ${t.statusCode??`?`}`))})});let t={socket:e,streams:new Map};e.on(`message`,e=>{let n;try{n=JSON.parse(String(e))}catch{return}typeof n.streamId==`string`&&t.streams.get(n.streamId)?.onFrame(n)});let n=!1;return e.on(`close`,()=>this.#d(t,n)),e.on(`error`,()=>{n=!0}),this.#r=t,this.#o=!0,t}#d(e,t){if(this.#r===e){this.#r=void 0;for(let n of e.streams.values())n.onDown(t);e.streams.clear()}}#f(){if(this.#a!==void 0)return this.#a;let e=(async()=>{let e=this.#n;if(e===void 0)return;let t=await e();this.#t=t.cookie,this.#e=t.baseUrl.replace(/\/$/,``)})().finally(()=>{this.#a===e&&(this.#a=void 0)});return this.#a=e,e}openEvents(e){let t,n=n=>{switch(n.type){case`ready`:t=n.clientId,e.onReady(n);return;case`emit`:e.onEmit(n);return;case`waterfall`:e.onWaterfall(n);return;case`cancel`:e.onCancel(n);return}},r=this.openStream(`$events`,{},{onItem:t=>{let i=ne(t);if(i===null){e.onClose?.(!1),r.cancel();return}n(i)},onClose:t=>e.onClose?.(t)});return{respond:async(e,n)=>{if(t===void 0)throw new g(`waterfall 应答先于 ready 帧(clientId 缺席)`);await this.unary(`$events/result`,{clientId:t,eventId:e,outcome:n})},close:()=>r.cancel()}}dispose(){this.#s=!0,this.#r?.socket.close(),this.#r=void 0}#p(){if(this.#s)throw new g(`carrier 已释放`)}};function ae(e){if(e.startsWith(`https://`))return`wss://${e.slice(8)}`;if(e.startsWith(`http://`))return`ws://${e.slice(7)}`;throw new g(`baseUrl 非法(期待 http(s)://,实得 ${e})`)}function oe(e,r){let i=m(e);if(i===null)return r!==void 0&&(r.invalid+=1),null;if(t(i.type)===`project`)return typeof i.data!=`object`||i.data===null||Array.isArray(i.data)?(r!==void 0&&(r.opaqueWarn+=1),{kind:`opaque`,event:i,level:`warn`}):(r!==void 0&&(r.consumable+=1),{kind:`consumable`,event:i});let a=n(i)?`debug`:`warn`;return a===`debug`?r!==void 0&&(r.opaqueDebug+=1):r!==void 0&&(r.opaqueWarn+=1),{kind:`opaque`,event:i,level:a}}var se=class{#e;#t;#n={invalid:0,opaqueDebug:0,opaqueWarn:0,consumable:0};#r=new Map;#i=0;constructor(e,t){this.#e=e,this.#t=t?.reopenBaseMs??1e3}open(e,t){let n=this.#r.get(e);if(n!==void 0&&!n.closed)return n.handlers=t,{close:()=>this.close(e)};let r={sessionId:e,handlers:t,handle:void 0,cursor:void 0,baseline:void 0,streamSeenRevision:!1,reopening:!1,backoffMs:this.#t,closed:!1,pending:[]};return this.#r.set(e,r),this.#a(r),{close:()=>this.close(e)}}close(e){let t=this.#r.get(e);t!==void 0&&(t.closed=!0,t.handle?.cancel(),this.#r.delete(e))}stats(){let e=0,t=0;for(let n of this.#r.values())n.closed||(n.reopening||n.cursor===void 0?t++:e++);return{live:e,reopening:t,decoded:{...this.#n},gapsRepaired:this.#i}}#a(e){e.closed||(e.reopening=e.cursor!==void 0,e.handle=this.#e.openStream(`session/follow`,{request:{address:{kind:`session`,sessionId:e.sessionId},assistantStream:!0}},{onItem:t=>this.#s(e,t),onEnd:()=>this.#o(e,`stream end`),onError:t=>this.#o(e,`${t.code}: ${t.message}`),onClose:t=>{t&&this.#o(e,`socket error`)}}))}#o(e,t){if(e.closed)return;e.handle=void 0,e.handlers.onDown(t);let n=e.backoffMs;e.backoffMs=Math.min(e.backoffMs*2,3e4),e.baseline=void 0,e.streamSeenRevision=!1,e.reopening=!0,setTimeout(()=>{e.closed||this.#a(e)},n)}#s(e,t){if(t.type===`snapshot`){this.#c(e,t);return}if(e.cursor!==void 0){if(e.reopening){e.pending.push(t);return}this.#d(e,t)}}#c(e,t){let n=e.cursor;if(n!==void 0&&t.cursor<n){e.handlers.onDown(`cursor 回退:${String(t.cursor)} < ${String(n)}`);return}e.baseline=t.assistantStream,e.streamSeenRevision=!1,e.reopening=!0,e.handlers.onSnapshot(t.header,t.cursor,t.projections,t.assistantStream),this.#l(e,t,n)}async#l(e,t,n){try{let r=[];if(n!==void 0&&t.records.length>0){let i=t.records[0]?.event.seq??t.cursor;i>n+1&&(r.push(...await this.#u(e,n+1,i)),this.#i+=r.length)}for(let e of t.records)r.push(e.event);for(let t of r)this.#f(e,t);let i=e.pending;e.pending=[],e.reopening=!1,e.cursor=t.cursor,e.backoffMs=this.#t;for(let t of i)this.#d(e,t)}catch(t){e.handlers.onDown(`backlog 补齐失败:${String(t)}`)}}async#u(e,t,n){let r=[],i=n;for(;i>t;){let n=te(await this.#e.unary(`session/page`,{request:{address:{kind:`session`,sessionId:e.sessionId},throughSeq:i-1,beforeSeq:t,maxMessages:200}}));if(n===null)throw new g(`session/page 帧畸形(records/hasMore 缺失)`);for(let e of n.records)r.push(e.event);let a=n.records[0]?.event.seq;if(a===void 0||a<=t||(i=a,!n.hasMore))break}return r.sort((e,t)=>e.seq-t.seq),r}#d(e,t){if(t.type===`assistant-stream`){if(!e.streamSeenRevision){e.streamSeenRevision=!0;let n=(e.baseline?.revision??-1)+1;if(e.baseline!==void 0&&t.frame.revision!==n){e.handlers.onDown(`assistant-stream 衔接断裂:revision ${String(t.frame.revision)} ≠ ${String(n)}`);return}}e.handlers.onAssistantStream(t.frame);return}t.type===`event`&&this.#f(e,t.event)}#f(e,t){let n=oe(t,this.#n);n!==null&&n.kind===`consumable`&&e.handlers.onEvent(n.event)}async readAll(e){return await new Promise((t,n)=>{let r=new Map,i,a,o=!1,s=this.#e.openStream(`session/follow`,{request:{address:{kind:`session`,sessionId:e}}},{onItem:c=>{o||c.type===`snapshot`&&(o=!0,i=c.header,a=c.projections,s.cancel(),this.#p(e,c,r).then(e=>t({header:i,events:e,projections:a}),e=>n(e)))},onEnd:()=>{o||(o=!0,n(new g(`session/follow 在 snapshot 前关闭`)))},onError:e=>{o||(o=!0,n(new re(e)))}})})}async#p(e,t,n){let r=[];for(let e of t.records)r.push(e.event);let i=t.records.length>0?t.records[0]?.event.seq:void 0;for(;t.hasMore===!0;){let n=te(await this.#e.unary(`session/page`,{request:{address:{kind:`session`,sessionId:e},throughSeq:t.cursor,...i===void 0?{}:{beforeSeq:i},maxMessages:200}}));if(n===null)throw new g(`session/page 帧畸形(records/hasMore 缺失)`);for(let e of n.records)r.push(e.event);if(!n.hasMore||n.records.length===0)break;let a=n.records[0]?.event.seq;if(a===void 0||a===0)break;i=a}let a=new Map;for(let e of r)a.set(e.seq,e);let o=[...a.values()].sort((e,t)=>e.seq-t.seq);for(let e=0;e<o.length;e++){let t=o[e];if(t?.seq!==e)throw new re({code:`gateway/internal`,message:`journal 连续性断裂:位置 ${String(e)} 实得 seq ${String(t?.seq)}`});let r=oe(t,this.#n);r?.kind===`consumable`&&n.set(t.seq,r.event)}return[...n.values()]}},ce=class{#e=new Map;#t=new Map;#n=new Map;#r=new Map;#i;#a;#o=0;#s=0;constructor(e,t){this.#i=e,this.#a=t}attachConnection(e,t,n){this.#e.set(e,{connId:e,send:t,ctx:n})}detachConnection(e){this.#e.delete(e);for(let[t,n]of this.#t)n.delete(e),n.size===0&&this.#t.delete(t),this.#a?.onSessionUnbind?.(e,t);for(let[t,n]of this.#n)n===e&&this.#n.delete(t)}bind(e,t){let n=this.#t.get(t);n===void 0&&(n=new Set,this.#t.set(t,n));let r=n.has(e);n.add(e),r||this.#a?.onSessionBind?.(e,t)}unbind(e,t){this.#t.get(t)?.delete(e),this.#a?.onSessionUnbind?.(e,t)}boundConnIds(e){return[...this.#t.get(e)??[]]}ctxOf(e){return this.#e.get(e)?.ctx}routeResolved(e,t,n){this.routeExt({method:e,payload:t},n===void 0?void 0:{excludeConnId:n})}beginReplayCount(e){this.#r.set(e,0)}takeReplayCount(e){let t=this.#r.get(e);return this.#r.delete(e),t}setTurnOrigin(e,t){this.#n.set(e,t)}clearTurnOrigin(e){this.#n.delete(e)}route(e){let t=e.sessionId;if(t!==void 0&&this.#a?.onSessionUpdate!==void 0){let n=e.update??e;le(this.#i,`onSessionUpdate`,()=>this.#a?.onSessionUpdate?.(t,n))}let n;if(t===void 0)n=[...this.#e.keys()];else{let r=this.#n.get(t),i=e.update?.sessionUpdate===`user_message_chunk`;n=[...this.#t.get(t)??[]],r!==void 0&&i&&(n=n.filter(e=>e!==r),this.#s++);let a=this.#a?.fanout===void 0?void 0:le(this.#i,`fanout`,()=>this.#a?.fanout?.(e,n));if(a!==void 0&&(n=[...a]),n.length===0){this.#o++;return}}for(let t of n){let n=this.#e.get(t);if(n===void 0)continue;let r=e;if(this.#a?.transformOutbound!==void 0){let t=le(this.#i,`transformOutbound`,()=>this.#a?.transformOutbound?.(e,n.ctx));if(t===null)continue;t!==void 0&&(r=t)}n.send({jsonrpc:`2.0`,method:`session/update`,params:r});let i=this.#r.get(t);i!==void 0&&this.#r.set(t,i+1)}}routeExt(e,t){let n=typeof e.payload.sessionId==`string`?e.payload.sessionId:void 0,r=n===void 0?[...this.#e.keys()]:[...this.#t.get(n)??[]];t?.excludeConnId!==void 0&&(r=r.filter(e=>e!==t.excludeConnId));for(let t of r)this.#e.get(t)?.send({jsonrpc:`2.0`,method:e.method,params:e.payload})}stats(){return{connections:this.#e.size,dropped:this.#o,suppressed:this.#s}}};function le(e,t,n){try{return n()}catch(n){e.warn(`gateway hook ${t} failed (fail-open): ${String(n)}`);return}}const _={initialize:`initialize`,authenticate:`authenticate`,providers_list:`providers/list`,providers_set:`providers/set`,providers_disable:`providers/disable`,session_new:`session/new`,session_load:`session/load`,session_set_mode:`session/set_mode`,session_set_config_option:`session/set_config_option`,session_prompt:`session/prompt`,session_cancel:`session/cancel`,mcp_message:`mcp/message`,session_list:`session/list`,session_delete:`session/delete`,session_fork:`session/fork`,session_resume:`session/resume`,session_close:`session/close`,logout:`logout`,nes_start:`nes/start`,nes_suggest:`nes/suggest`,nes_accept:`nes/accept`,nes_reject:`nes/reject`,nes_close:`nes/close`,document_did_open:`document/didOpen`,document_did_change:`document/didChange`,document_did_close:`document/didClose`,document_did_save:`document/didSave`,document_did_focus:`document/didFocus`},v={session_request_permission:`session/request_permission`,session_update:`session/update`,fs_write_text_file:`fs/write_text_file`,fs_read_text_file:`fs/read_text_file`,terminal_create:`terminal/create`,terminal_output:`terminal/output`,terminal_release:`terminal/release`,terminal_wait_for_exit:`terminal/wait_for_exit`,terminal_kill:`terminal/kill`,mcp_message:`mcp/message`,elicitation_create:`elicitation/create`,elicitation_complete:`elicitation/complete`},ue={cancel_request:`$/cancel_request`};function de(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function fe(e,t=`|`){return e.map(e=>Fe(e)).join(t)}function pe(e,t){return typeof t==`bigint`?t.toString():t}var me=class{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return e!==void 0&&(this._value=e(),this._getter=void 0),this._value}};function he(e){return new me(e)}function ge(e){return e==null}function _e(e){let t=e.startsWith(`^`)?1:0,n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function ve(e,t){let n=e/t,r=Math.round(n),i=4*2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}function ye(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function be(e){let t=Object.getOwnPropertyDescriptor(e,`shape`);return t?.get?t.get.raw:t?.value}function y(e){return be(e._zod.def)??e._zod.def.shape}function xe(e,t,n){Object.defineProperty(e,t,{get(){let e=n();return ye(this,t,e),e},enumerable:!0,configurable:!0})}function Se(e,t,n){t in e?ye(e,t,n):e[t]=n}function Ce(e,t,n,r){let i=y(t);for(let a of n){let n=Object.getOwnPropertyDescriptor(i,a);n.enumerable&&(n.get?xe(e,a,()=>{let e=t._zod.def.shape[a];return r?r(e,a):e}):Se(e,a,r?r(n.value,a):n.value))}}function we(e,t){for(let n of Reflect.ownKeys(t)){let r=Object.getOwnPropertyDescriptor(t,n);r.enumerable&&(r.get?xe(e,n,()=>t[n]):Se(e,n,r.value))}}function b(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Te(e){return JSON.stringify(e)}function Ee(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const De=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function Oe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const ke=he(()=>{if(T.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function Ae(e){if(Oe(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return!(Oe(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}function je(e){return Ae(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const Me=new Set([`string`,`number`,`symbol`]);function Ne(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Pe(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function x(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function Fe(e){return typeof e==`bigint`?e.toString()+`n`:typeof e==`string`?`"${e}"`:`${e}`}function Ie(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}const Le=(()=>({safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]}))(),Re={int64:[BigInt(`-9223372036854775808`),BigInt(`9223372036854775807`)],uint64:[BigInt(0),BigInt(`18446744073709551615`)]};function ze(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);let i={};return Ce(i,e,Be(e,t)),Pe(e,b(n,{shape:i,checks:[]}))}function Be(e,t){let n=y(e),r=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(n,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&r.push(e)}return r}function Ve(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);let i=new Set(Be(e,t)),a={};return Ce(a,e,Reflect.ownKeys(y(e)).filter(e=>!i.has(e))),Pe(e,b(n,{shape:a,checks:[]}))}function He(e,t){if(!Ae(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=y(e);for(let e of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return Pe(e,b(e._zod.def,{shape:Ue(e,t)}))}function Ue(e,t){let n={};return Ce(n,e,Reflect.ownKeys(y(e))),we(n,t),n}function We(e,t){if(!Ae(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return Pe(e,b(e._zod.def,{shape:Ue(e,t)}))}function Ge(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);let n={};return Ce(n,e,Reflect.ownKeys(y(e))),Ce(n,t,Reflect.ownKeys(y(t))),Pe(e,b(e._zod.def,{shape:n,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function Ke(e,t,n,r=`partial`){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${r}() cannot be used on object schemas containing refinements`);let a=n?new Set(Be(t,n)):void 0,o={};return Ce(o,t,Reflect.ownKeys(y(t)),e&&((t,n)=>a&&!a.has(n)?t:new e({type:`optional`,innerType:t}))),Pe(t,b(t._zod.def,{shape:o,checks:[]}))}function qe(e,t,n){let r=n?new Set(Be(t,n)):void 0,i={};return Ce(i,t,Reflect.ownKeys(y(t)),(t,n)=>r&&!r.has(n)?t:new e({type:`nonoptional`,innerType:t})),Pe(t,b(t._zod.def,{shape:i}))}function S(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 Je(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 Ye(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Xe(e){return typeof e==`string`?e:e?.message}function Ze(e){let t=[];for(let n of e??[]){let e=n._zod.def;if(!/_(length|size)$|_equals$/.test(e.check))break;let r=e.maximum??e.length??e.size;r>=0&&t.push([r,n])}return t}function Qe(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function $e(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:Xe(e.inst?._zod.def?.error?.(e))??Xe(a?.(e))??Xe(t?.error?.(e))??Xe(n.customError?.(e))??Xe(n.localeError?.(e))??`Invalid input`,s={};for(let t of Object.keys(e))t===`inst`||t===`schema`||t===`continue`||t===`input`||t===`__proto__`||(s[t]=e[t]);return s.path??=[],s.message=o,t?.reportInput&&(s.input=e.input),s}const et=/[\uD800-\uDBFF]/;function tt(e){let t=e.length;if(!et.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function nt(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function rt(e){let t=typeof e;switch(t){case`number`:return Number.isNaN(e)?`nan`:`number`;case`object`:{if(e===null)return`null`;if(Array.isArray(e))return`array`;let t=e;if(t&&Object.getPrototypeOf(t)!==Object.prototype&&`constructor`in t&&t.constructor)return t.constructor.name}}return t}function it(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function at(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):lt(e,n,r.value)}}function ot(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function st(e,t,n){return ot(e,t,n,!1)}function ct(e,t){for(let n in e){let r=e[n];Object.defineProperty(t,n,{configurable:!0,enumerable:!0,get(){return ot(this,n,r(this))},set(e){ot(this,n,e)}})}return t}function lt(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:ot(this,t,n.bind(this))},set(e){ot(this,t,e)}})}function ut(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}let dt,ft=!1;const pt={configurable:!0,get(){ft=!0}};function C(e,t,n){let r=Object.getPrototypeOf(e._zod);if(t in r&&dt!==e._zod){dt=void 0;return}dt=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,pt);let e=ft;ft=!1;try{let r=n(this);return ft?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),ft||=e,r}catch(n){throw delete this[t],ft||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}})}function mt(e,t,n,r){let i=ut(e,t);i&&Object.defineProperty(i,t,{configurable:!0,get(){let e={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,t,e),e.value=n(this),Object.defineProperty(this,t,e),e.value},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:r,value:e})}})}function ht(e){let t=()=>e;return t[`~constantCatch`]=!0,t}var gt;const _t=Object.freeze({status:`aborted`}),vt={value:void 0,enumerable:!1};let yt=`captureStackTrace`in Error?Error:null;function bt(e){let t=yt;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return yt=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function w(e,t,n,r){let i={};function a(e){this.def=e,this.constr=d,this.traits=new Set}a.prototype=i;let o=n,s=o&&new WeakSet;function c(n,r){if(n._zod){if(n._zod.traits.has(e))return}else{vt.value=new a(r);try{Object.defineProperty(n,`_zod`,vt)}finally{vt.value=void 0}}if(n._zod.traits.add(e),t(n,r),s){let e=Object.getPrototypeOf(n),t=n._zod.constr.prototype,r=e;for(;r&&r!==t;)r=Object.getPrototypeOf(r);let i=r??e;s.has(i)||(s.add(i),at(i,o))}let i=d.prototype;for(let e in i)Object.prototype.hasOwnProperty.call(i,e)&&(e in n||(n[e]=i[e].bind(n)))}let l=r?.Parent??Object;class u extends l{}Object.defineProperty(u,`name`,{value:e});function d(e){let t=r?.Parent?bt(u):this;c(t,e);let n=t._zod.deferred;if(n){for(let e of n)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(d,`init`,{value:c}),Object.defineProperty(d,Symbol.hasInstance,{value:t=>r?.Parent&&t instanceof r.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(d,`name`,{value:e}),d}var xt=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},St=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(gt=globalThis).__zod_globalConfig??(gt.__zod_globalConfig={});const T=globalThis.__zod_globalConfig;function E(e){return e&&Object.assign(T,e),T}function Ct(){let e=this._zod;return e.message??=JSON.stringify(e.def,pe,2),e.message}function wt(e){this._zod.message=e}const Tt={get:Ct,set:wt,enumerable:!0,configurable:!0},Et={value:void 0,enumerable:!1},Dt=new WeakSet([Object.prototype,Error.prototype]),Ot=(e,t)=>{e.name=`$ZodError`,Et.value=t,Object.defineProperty(e,`issues`,Et),Et.value=void 0,Object.defineProperty(e,`message`,Tt);let n=Object.getPrototypeOf(e);Dt.has(n)||(Dt.add(n),Object.defineProperty(n,`toString`,{configurable:!0,enumerable:!1,get(){let e=()=>this.message;return Object.defineProperty(this,`toString`,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,`toString`,{value:e,configurable:!0,writable:!0})}}))},kt=w(`$ZodError`,Ot);w(`$ZodError`,Ot,void 0,{Parent:Error});function At(e,t,n){return Object.prototype.hasOwnProperty.call(e,t)||(t===`__proto__`?Object.defineProperty(e,t,{value:n(),writable:!0,enumerable:!0,configurable:!0}):e[t]=n()),e[t]}function jt(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?At(n,i.path[0],()=>[]).push(t(i)):r.push(t(i));return{formErrors:r,fieldErrors:n}}function Mt(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i],o=i===e.length-1;if(n===`_errors`){o&&r._errors.push(t(a)),i++;continue}Object.prototype.hasOwnProperty.call(r,n)||Object.defineProperty(r,n,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let s=r[n];o&&s._errors.push(t(a)),r=s,i++}}}};return r(e),n}function Nt(e,t){return{callee:t?.callee??e,Err:t?.Err}}const Pt=e=>{let t=(n,r,i,a)=>{let o=i?{...i,async:!1}:{async:!1},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new xt;if(s.issues.length){let n=new(a?.Err??e)(s.issues.map(e=>$e(e,o,E())));throw De(n,a?.callee??t),n}return s.value};return t},Ft=e=>{let t=async(n,r,i,a)=>{let o=i?{...i,async:!0}:{async:!0},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let n=new(a?.Err??e)(s.issues.map(e=>$e(e,o,E())));throw De(n,a?.callee??t),n}return s.value};return t},It=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new xt;return a.issues.length?Lt(e,a.issues,i):{success:!0,data:a.value}};function Lt(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(e=>$e(e,n,E()))),t=void 0,n=void 0),r},set error(e){r=e,t=void 0,n=void 0}}}const Rt=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?Lt(e,a.issues,i):{success:!0,data:a.value}},zt=Symbol.for(`zod.compile.invalid`),Bt=Symbol.for(`zod.compile.fallback`),Vt=((e,t,n)=>{let r=e._zod.bag.validator;if(r!==void 0){if(r(t)!==zt)return!0;if(r.definite===!0&&n===void 0)return!1}return Ht(e,t,n)});function Ht(e,t,n){let r=n?{...n,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},i=e._zod.bag.fallbackRun,a;if(i?(r[Bt]=!0,a=i({value:t,issues:[]},r)):a=e._zod.run({value:t,issues:[]},r),a instanceof Promise)throw new xt;return a.issues.length===0}const Ut=async(e,t,n)=>{let r=n?{...n,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},i=e._zod.run({value:t,issues:[]},r);return i instanceof Promise&&(i=await i),i.issues.length===0},Wt=e=>{let t=Pt(e),n=(e,r,i,a)=>t(e,r,i?{...i,direction:`backward`}:{direction:`backward`},Nt(n,a));return n},Gt=e=>{let t=Pt(e),n=(e,r,i,a)=>t(e,r,i,Nt(n,a));return n},Kt=e=>{let t=Ft(e),n=async(e,r,i,a)=>await t(e,r,i?{...i,direction:`backward`}:{direction:`backward`},Nt(n,a));return n},qt=e=>{let t=Ft(e),n=async(e,r,i,a)=>await t(e,r,i,Nt(n,a));return n},Jt=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return It(e)(t,n,i)},Yt=e=>(t,n,r)=>It(e)(t,n,r),Xt=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return Rt(e)(t,n,i)},Zt=e=>async(t,n,r)=>Rt(e)(t,n,r),Qt=/^[cC][0-9a-z]{6,}$/,$t=/^[0-9a-z]+$/,en=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,tn=/^[0-9a-vA-V]{20}$/,nn=/^[A-Za-z0-9]{27}$/,rn=/^[a-zA-Z0-9_-]{21}$/;function an(e){return RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}const on=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,sn=/^([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})$/,cn=e=>e?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)$/,ln=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;function un(){return RegExp(`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,`u`)}const dn=/^(?:(?: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}|:))$/,pn=/^((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])$/,mn=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,hn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,gn=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/,_n=/^https?$/,vn=/^\+[1-9]\d{6,14}$/,yn=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;function bn(e){return RegExp(`^${e}$`)}const xn=bn(yn);function Sn(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?`${t}:[0-5]\\d(?:\\.\\d+)?`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Cn(e){return RegExp(`^${Sn(e)}$`)}function wn(e){let t=[`Z`];e.offset&&t.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let n=`${Sn({precision:e.precision,seconds:!0})}(?:${t.join(`|`)})`,r=e.local?`${n}|${Sn({precision:e.precision})}`:n;return RegExp(`^${yn}T(?:${r})$`)}const Tn=/^[\s\S]{0,}$/,En=/^-?\d+$/,Dn=/^-?\d+(?:\.\d+)?$/,On=/^(?:true|false)$/i,kn=/^null$/i,An=/^[^A-Z]*$/,jn=/^[^a-z]*$/,D=w(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Mn=e=>{let t=e.value;return!ge(t)&&t.length!==void 0},Nn={number:`number`,bigint:`bigint`,object:`date`},Pn=w(`$ZodCheckLessThan`,(e,t)=>{D.init(e,t);let n=Nn[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:Nn[typeof r.value]??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})}}),Fn=w(`$ZodCheckGreaterThan`,(e,t)=>{D.init(e,t);let n=Nn[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:Nn[typeof r.value]??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})}}),In=w(`$ZodCheckMultipleOf`,(e,t)=>{D.init(e,t),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?t.value!==BigInt(0)&&n.value%t.value===BigInt(0):ve(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})}}),Ln=w(`$ZodCheckNumberFormat`,(e,t)=>{D.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=Le[t.format];e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),Rn=w(`$ZodCheckMaxLength`,(e,t)=>{var n;D.init(e,t),(n=e._zod.def).when??(n.when=Mn),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>t.maximum?tt(r):i)<=t.maximum)return;let a=nt(r);n.issues.push({origin:a,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),zn=w(`$ZodCheckMinLength`,(e,t)=>{var n;D.init(e,t),(n=e._zod.def).when??(n.when=Mn),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?tt(r):i)>=t.minimum)return;let a=nt(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Bn=w(`$ZodCheckLengthEquals`,(e,t)=>{var n;D.init(e,t),(n=e._zod.def).when??(n.when=Mn),e._zod.check=n=>{let r=n.value,i=r.length,a=typeof r==`string`&&i>=t.length&&i<=t.length*2?tt(r):i;if(a===t.length)return;let o=nt(r),s=a>t.length;n.issues.push({origin:o,...s?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Vn=w(`$ZodCheckStringFormat`,(e,t)=>{var n,r;D.init(e,t),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Hn=w(`$ZodCheckRegex`,(e,t)=>{Vn.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})}}),Un=w(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=An,Vn.init(e,t)}),Wn=w(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=jn,Vn.init(e,t)}),Gn=w(`$ZodCheckIncludes`,(e,t)=>{D.init(e,t);let n=Ne(t.includes);t.pattern=new RegExp(typeof t.position==`number`?`^.{${t.position},}${n}`:n),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Kn=w(`$ZodCheckStartsWith`,(e,t)=>{D.init(e,t);let n=RegExp(`^${Ne(t.prefix)}.*`);t.pattern??=n,e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),qn=w(`$ZodCheckEndsWith`,(e,t)=>{D.init(e,t);let n=RegExp(`.*${Ne(t.suffix)}$`);t.pattern??=n,e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Jn=w(`$ZodCheckOverwrite`,(e,t)=>{D.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var Yn=class{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{--this.indent}}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
4
+ `).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.content??[``];return new e(...Object.keys(this.closed),`return function (${this.args.join(`, `)}) {\n${t.join(`
5
+ `)}\n};`)(...Object.values(this.closed))}};const Xn={major:4,minor:6,patch:7},O=w(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Xn;let r=e._zod.def.checks,i=e._zod.traits.has(`$ZodCheck`)?[e,...r??[]]:r?.length?[...r]:[];for(let t of i)for(let n of t._zod.onattach)n(e);if(i.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,n,r)=>{if(t.memo)return t;let i=S(t),a;for(let o of n){if(o._zod.def.when){if(Je(t)||!o._zod.def.when(t))continue}else if(i)continue;let n=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&r?.async===!1)throw new xt;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,t.issues.length!==n&&(Qe(t.issues,n,e),i||=S(t,n))});else{if(t.issues.length===n)continue;Qe(t.issues,n,e),i||=S(t,n)}}return a?a.then(()=>t):t},n=(n,r,a)=>{if(S(n))return n.aborted=!0,n;let o=t(r,i,a);if(o instanceof Promise){if(a.async===!1)throw new xt;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(r,a)=>{if(a.skipChecks)return e._zod.parse(r,a);if(a.direction===`backward`){let t=e._zod.parse({value:r.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,r,a)):n(t,r,a)}let o=e._zod.parse(r,a);if(o instanceof Promise){if(a.async===!1)throw new xt;return o.then(e=>t(e,i,a))}return t(o,i,a)}}},{get"~standard"(){return st(this,`~standard`,$n(this))},set"~standard"(e){ot(this,`~standard`,e)}}),Zn=(e,t)=>e.issues.length?{issues:e.issues.map(e=>$e(e,t,E()))}:{value:e.value};async function Qn(e,t){let n={async:!0};return Zn(await e._zod.run({value:t,issues:[]},n),n)}function $n(e){return{validate:t=>{let n={async:!1};try{let r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return Zn(r,n)}catch{}return Qn(e,t)},vendor:`zod`,version:1}}const er=w(`$ZodString`,(e,t)=>{O.init(e,t),e._zod.pattern=t.pattern??Tn,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=w(`$ZodStringFormat`,(e,t)=>{Vn.init(e,t),er.init(e,t)}),tr=w(`$ZodGUID`,(e,t)=>{t.pattern??=sn,k.init(e,t)}),nr=w(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=cn(e)}else t.pattern??=cn();k.init(e,t)}),rr=w(`$ZodEmail`,(e,t)=>{t.pattern??=ln,k.init(e,t)});function ir(e){try{return typeof URL<`u`&&typeof URL.canParse==`function`?URL.canParse(e):(new URL(e),!0)}catch{return!1}}function ar(e,t){return!(`normalize`in t)&&!(`hostname`in t)&&!(`protocol`in t)?ir(e)||2:or(e,t)}function or(e,t){if(!t.normalize&&t.protocol?.source===_n.source&&!/^https?:\/\//i.test(e))return 1;try{if(typeof URL<`u`){let t=URL;if(typeof t.parse==`function`)return t.parse(e)??2}return new URL(e)}catch{return 2}}const sr=/[\t\n\r]/g;function cr(e){return e.replace(sr,``)}function lr(e,t){return t.lastIndex=0,t.test(e.hostname)}function ur(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(`:`)?e.protocol.slice(0,-1):e.protocol)}const dr=w(`$ZodURL`,(e,t)=>{k.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=ar(r,t);if(i===1){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}if(i===2){n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort});return}if(i===!0){n.value=cr(r);return}t.hostname&&!lr(i,t.hostname)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort}),t.protocol&&!ur(i,t.protocol)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort}),n.value=t.normalize?i.href:cr(r);return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),fr=w(`$ZodEmoji`,(e,t)=>{t.pattern??=un(),k.init(e,t)}),pr=w(`$ZodNanoID`,(e,t)=>{if(t.length!==void 0&&(!Number.isInteger(t.length)||t.length<1))throw Error(`Invalid nanoid length: ${t.length}`);t.pattern??=t.length===void 0?rn:an(t.length),k.init(e,t)}),mr=w(`$ZodCUID`,(e,t)=>{t.pattern??=Qt,k.init(e,t)}),hr=w(`$ZodCUID2`,(e,t)=>{t.pattern??=$t,k.init(e,t)}),gr=w(`$ZodULID`,(e,t)=>{t.pattern??=en,k.init(e,t)}),_r=w(`$ZodXID`,(e,t)=>{t.pattern??=tn,k.init(e,t)}),vr=w(`$ZodKSUID`,(e,t)=>{t.pattern??=nn,k.init(e,t)}),yr=w(`$ZodISODateTime`,(e,t)=>{t.pattern??=wn(t),k.init(e,t)}),br=w(`$ZodISODate`,(e,t)=>{t.pattern??=xn,k.init(e,t)}),xr=w(`$ZodISOTime`,(e,t)=>{t.pattern??=Cn(t),k.init(e,t)}),Sr=w(`$ZodISODuration`,(e,t)=>{t.pattern??=on,k.init(e,t)}),Cr=w(`$ZodIPv4`,(e,t)=>{t.pattern??=dn,k.init(e,t)}),wr=/^[0-9a-fA-F:.]+$/;function Tr(e){return wr.test(e)?ir(`http://[${e}]`):!1}const Er=w(`$ZodIPv6`,(e,t)=>{t.pattern??=fn,k.init(e,t),e._zod.check=n=>{Tr(n.value)||n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}),Dr=w(`$ZodCIDRv4`,(e,t)=>{t.pattern??=pn,k.init(e,t)});function Or(e){let t=e.split(`/`);if(t.length!==2)return!1;let[n,r]=t;if(!r)return!1;let i=Number(r);return`${i}`!==r||i<0||i>128?!1:Tr(n)}const kr=w(`$ZodCIDRv6`,(e,t)=>{t.pattern??=mn,k.init(e,t),e._zod.check=n=>{Or(n.value)||n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}});function Ar(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const jr=/^[0-9a-zA-Z+/]*={0,2}$/,Mr=w(`$ZodBase64`,(e,t)=>{t.pattern??=jr,k.init(e,t),e._zod.check=n=>{Ar(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}}),Nr=/^[A-Za-z0-9_-]*$/;function Pr(e){if(!Nr.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return Ar(t.padEnd(Math.ceil(t.length/4)*4,`=`))}const Fr=w(`$ZodBase64URL`,(e,t)=>{t.pattern??=Nr,k.init(e,t),e._zod.check=n=>{Pr(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Ir=w(`$ZodE164`,(e,t)=>{t.pattern??=vn,k.init(e,t)});function Lr(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const Rr=w(`$ZodJWT`,(e,t)=>{k.init(e,t),e._zod.check=n=>{Lr(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),zr=w(`$ZodNumber`,(e,t)=>{O.init(e,t),e._zod.pattern=Dn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:String(i):void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),Br=w(`$ZodNumberFormat`,(e,t)=>{Ln.init(e,t),zr.init(e,t)}),Vr=w(`$ZodBoolean`,(e,t)=>{O.init(e,t),e._zod.pattern=On,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),Hr=w(`$ZodNull`,(e,t)=>{O.init(e,t),e._zod.pattern=kn,e._zod.values=new Set([null]),e._zod.parse=(t,n)=>{let r=t.value;return r===null||t.issues.push({expected:`null`,code:`invalid_type`,input:r,inst:e}),t}}),Ur=w(`$ZodUnknown`,(e,t)=>{O.init(e,t),e._zod.parse=e=>e}),Wr=w(`$ZodNever`,(e,t)=>{O.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function Gr(e,t){let n=Ze(e._zod.def.checks);if(!n.length)return;let r=Math.min(...n.map(e=>e[0])),i=e._zod.parse;e._zod.parse=(n,a)=>{let o=t(n.value);if(o>r&&!a?.skipChecks&&a?.direction!==`backward`){for(let[t,r]of Ze(e._zod.def.checks))if(o>t&&r._zod.def.when(n)){let t=n.issues.length;return r._zod.check(n),n.issues[t].continue=!1,Qe(n.issues,t,e),n}}return i(n,a)}}const Kr=e=>Array.isArray(e)?e.length:-1;function qr(e,t,n){e.issues.length&&t.issues.push(...Ye(n,e.issues)),t.value[n]=e.value}const Jr=w(`$ZodArray`,(e,t)=>{O.init(e,t);let n=T.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({expected:`array`,code:`invalid_type`,input:a,inst:e}),r;r.value=n?n.alloc(e,r,Array(a.length),i):Array(a.length);let o=[],s=i?.abortEarly;for(let e=0;e<a.length;e++){let n=a[e],c=t.element._zod.run({value:n,issues:[]},i);if(c instanceof Promise)o.push(c.then(t=>qr(t,r,e)));else if(qr(c,r,e),s&&c.issues.length!==0&&S(c))break}return o.length?Promise.all(o).then(()=>r):r},Gr(e,Kr)});function Yr(e,t,n,r,i,a){let o=n in r,s=a===`optional`;if(!(!o&&s&&i===`optional`)){if(e.issues.length){if(i!==void 0&&s&&!o)return;t.issues.push(...Ye(n,e.issues))}if(!o&&i===void 0){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?(o||i===`defaulted`&&!s)&&(t.value[n]=void 0):t.value[n]=e.value}}const Xr=[];function Zr(e){let t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:Xr,i=r.length?[...t,...r]:t;for(let t of i)if(!e.shape?.[t]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${String(t)}": expected a Zod schema`);let a=Ie(e.shape);return{...e,allKeys:i,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(a)}}function Qr(e,t,n,r,i,a,o){let s=[],c=i.keySet,l=i.catchall._zod,u=l.def.type,d=l.optin,f=l.optout,p=0;for(let i in t){if(o&&n.issues.length!==p){if(S(n,p))break;p=n.issues.length}if(c.has(i))continue;if(i===`__proto__`){u===`never`&&s.push(i);continue}if(u===`never`){s.push(i);continue}let a=l.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>Yr(e,n,i,t,d,f))):Yr(a,n,i,t,d,f)}return s.length&&n.issues.push({code:`unrecognized_keys`,keys:s,input:t,inst:a,continue:!0}),e.length?Promise.all(e).then(()=>n):n}const $r=w(`$ZodObject`,(e,t)=>{O.init(e,t);let n=Object.getOwnPropertyDescriptor(t,`shape`),r=n?.get?n.get.raw:t.shape??{};if(r){let e=()=>{let n={...r};return Object.defineProperty(t,`shape`,{value:n}),e.raw=n,n};e.raw=r,Object.defineProperty(t,`shape`,{get:e})}let i=he(()=>Zr(t));C(e,`propValues`,e=>{let t=e.def.shape,n={};for(let e in t){let r=t[e]._zod;if(r.values){Object.prototype.hasOwnProperty.call(n,e)||ye(n,e,new Set);for(let t of r.values)n[e].add(t);r.optin!==void 0&&n[e].add(void 0)}}return n});let a=Oe,o=t.catchall,s,c=T.memoizer;c?.attach(e),e._zod.parse=(t,n)=>{s??=i.value;let r=t.value;if(!a(r))return t.issues.push({expected:`object`,code:`invalid_type`,input:r,inst:e}),t;t.value=c?c.alloc(e,t,{},n):{};let l=[],u=s.shape,d=n?.abortEarly,f=t.issues.length;for(let e of s.allKeys){if(d&&t.issues.length!==f){if(S(t,f))break;f=t.issues.length}if(e===`__proto__`)continue;let i=u[e],a=i._zod.optin,o=i._zod.optout,s=i._zod.run({value:r[e],issues:[]},n);s instanceof Promise?l.push(s.then(n=>Yr(n,t,e,r,a,o))):Yr(s,t,e,r,a,o)}return o?Qr(l,r,t,n,i.value,e,d===!0):l.length?Promise.all(l).then(()=>t):t}}),ei=w(`$ZodObjectJIT`,(e,t)=>{$r.init(e,t);let n=e._zod.parse,r=he(()=>Zr(t)),i=T.memoizer,a=t=>{let n=r.value,a=n.symbolKeys,o=new Yn([`payload`,`ctx`],{shape:t,inst:e,memo:i,syms:a}),s=e=>`shape[${e}]._zod.run({ value: input[${e}], issues: [] }, ctx)`,c=(e,t)=>`
6
+ let ${e}_ab = false;
7
+ for (let i = 0; i < ${e}.issues.length; i++) {
8
+ const iss = ${e}.issues[i];
9
+ iss.path = iss.path ? [${t}, ...iss.path] : [${t}];
10
+ payload.issues.push(iss);
11
+ if (iss.continue !== true) ${e}_ab = true;
12
+ }
13
+ if (${e}_ab && ctx && ctx.abortEarly) {
14
+ payload.value = newResult;
15
+ return payload;
16
+ }`;o.write(`const input = payload.value;`);let l=Object.create(null),u=0;for(let e of n.allKeys)l[e]=`key_${u++}`;o.write(i?`const newResult = memo.alloc(inst, payload, {}, ctx);`:`const newResult = {};`);for(let e of n.allKeys){if(e===`__proto__`)continue;let n=l[e],r=typeof e==`symbol`?`syms[${a.indexOf(e)}]`:Te(e),i=`${r} in input`,u=t[e],d=u?._zod?.optin,f=d!==void 0,p=u?._zod?.optout===`optional`;if(o.write(`const ${n} = ${s(r)};`),f&&p){let e=d===`optional`?`${n}_present`:`${n}.value !== undefined || ${n}_present`;o.write(`
17
+ const ${n}_present = ${i};
18
+ if (!${n}.issues.length || ${n}_present) {
19
+ if (${n}.issues.length) {${c(n,r)}
20
+ }
21
+
22
+ if (${e}) {
23
+ newResult[${r}] = ${n}.value;
24
+ }
25
+ }
26
+
27
+ `)}else f?(o.write(`
28
+ if (${n}.issues.length) {${c(n,r)}
29
+ }
30
+ `),d===`defaulted`?o.write(`newResult[${r}] = ${n}.value;`):o.write(`
31
+ if (${n}.value !== undefined || ${i}) {
32
+ newResult[${r}] = ${n}.value;
33
+ }
34
+ `)):o.write(`
35
+ const ${n}_present = ${i};
36
+ if (${n}.issues.length) {${c(n,r)}
37
+ }
38
+ if (!${n}_present && !${n}.issues.length) {
39
+ payload.issues.push({
40
+ code: "invalid_type",
41
+ expected: "nonoptional",
42
+ input: undefined,
43
+ path: [${r}]
44
+ });
45
+ if (ctx && ctx.abortEarly) {
46
+ payload.value = newResult;
47
+ return payload;
48
+ }
49
+ }
50
+
51
+ if (${n}_present) {
52
+ newResult[${r}] = ${n}.value;
53
+ }
54
+
55
+ `)}return o.write(`payload.value = newResult;`),o.write(`return payload;`),o.compile()},o,s=Oe,c=!T.jitless,l=c&&ke.value,u=t.catchall,d;e._zod.parse=(i,f)=>{d??=r.value;let p=i.value;return s(p)?c&&l&&f?.async===!1&&f.jitless!==!0?(o||=a(t.shape),i=o(i,f),u?Qr([],p,i,f,d,e,f?.abortEarly===!0):i):n(i,f):(i.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),i)}});function ti(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!S(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>$e(e,r,E())))}),t)}const ni=w(`$ZodUnion`,(e,t)=>{O.init(e,t),C(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),C(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),C(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),C(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>_e(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>ti(t,r,e,i)):ti(o,r,e,i)}}),ri=w(`$ZodIntersection`,(e,t)=>{O.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>ai(e,t,n)):ai(e,i,a)}});function ii(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Ae(e)&&Ae(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};Object.prototype.hasOwnProperty.call(i,`__proto__`)&&delete i.__proto__;for(let n of r){if(n===`__proto__`)continue;let r=ii(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=ii(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function ai(e,t,n){let r=new Map,i,a=new Map,o=(e,t)=>{let n;if(e.code===`unrecognized_keys`&&!e.path?.length)i??=e,n=e.keys;else if(e.code===`invalid_key`&&e.origin===`record`&&e.path?.length===1){let t=String(e.path[0]);a.has(t)||a.set(t,e),n=[t]}else return!1;for(let e of n)r.has(e)||r.set(e,{}),r.get(e)[t]=!0;return!0};for(let n of t.issues)o(n,`l`)||e.issues.push(n);for(let t of n.issues)o(t,`r`)||e.issues.push(t);let s=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(s.length){let t=i?s.filter(e=>i.keys.includes(e)):[];t.length&&e.issues.push({...i,keys:t});for(let n of s)!t.includes(n)&&a.has(n)&&e.issues.push(a.get(n))}let c=ii(t.value,n.value);if(!c.valid){if(S(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}const oi=w(`$ZodRecord`,(e,t)=>{O.init(e,t);let n=T.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Ae(a))return r.issues.push({expected:`record`,code:`invalid_type`,input:a,inst:e}),r;let o=[],s=t.keyType._zod.values;if(s&&!t.partial){r.value=n?n.alloc(e,r,{},i):{};let c=new Set;for(let n of s)if(typeof n==`string`||typeof n==`number`||typeof n==`symbol`){if(c.add(typeof n==`number`?n.toString():n),n===`__proto__`)continue;let s=t.keyType._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){r.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>$e(e,i,E())),input:n,path:[n],inst:e});continue}let l=s.value;if(l===`__proto__`)continue;let u=t.valueType._zod.run({value:a[n],issues:[]},i);u instanceof Promise?o.push(u.then(e=>{e.issues.length&&r.issues.push(...Ye(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...Ye(n,u.issues)),r.value[l]=u.value)}let l;for(let e in a)if(!c.has(e))if(t.mode===`loose`){if(e===`__proto__`)continue;r.value[e]=a[e]}else l??=[],l.push(e);l&&l.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:l,continue:!0})}else{r.value=n?n.alloc(e,r,{},i):{};let c;for(let n of Reflect.ownKeys(a)){if(n===`__proto__`||!Object.prototype.propertyIsEnumerable.call(a,n))continue;let l=t.keyType._zod.run({value:n,issues:[]},i);if(l instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof n==`string`&&Dn.test(n)&&l.issues.length){let e=t.keyType._zod.run({value:Number(n),issues:[]},i);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(l=e)}if(l.issues.length){t.mode===`loose`?r.value[n]=a[n]:s?(c??=[],c.push(n)):r.issues.push({code:`invalid_key`,origin:`record`,issues:l.issues.map(e=>$e(e,i,E())),input:n,path:[n],inst:e});continue}let u=l.value;if(u===`__proto__`)continue;let d=t.valueType._zod.run({value:a[n],issues:[]},i);d instanceof Promise?o.push(d.then(e=>{e.issues.length&&r.issues.push(...Ye(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...Ye(n,d.issues)),r.value[u]=d.value)}c&&c.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:c,continue:!0})}return o.length?Promise.all(o).then(()=>r):r}}),si=w(`$ZodEnum`,(e,t)=>{O.init(e,t);let n=de(t.entries),r=new Set(n);e._zod.values=r,C(e,`pattern`,e=>{let t=de(e.def.entries).filter(e=>Me.has(typeof e));return RegExp(t.length?`^(${t.map(e=>Ne(e.toString())).join(`|`)})$`:`^[^\\s\\S]$`)}),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),ci=w(`$ZodLiteral`,(e,t)=>{O.init(e,t);let n=new Set(t.values);e._zod.values=n,C(e,`pattern`,e=>{let t=e.def.values;return RegExp(t.length?`^(${t.map(e=>typeof e==`string`?Ne(e):e?Ne(e.toString()):String(e)).join(`|`)})$`:`^[^\\s\\S]$`)}),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),li=w(`$ZodTransform`,(e,t)=>{O.init(e,t),e._zod.optin=`optional`,T.memoizer.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new St(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new xt;return n.value=i,n}});function ui(e,t){return e.value=t.issues.length?void 0:t.value,e}const di=w(`$ZodOptional`,(e,t)=>{O.init(e,t),C(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,C(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),C(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${_e(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>ui(e,t)):ui(e,r)}return t.innerType._zod.run(e,n)}}),fi=w(`$ZodExactOptional`,(e,t)=>{di.init(e,t),C(e,`values`,e=>e.def.innerType._zod.values),C(e,`pattern`,e=>e.def.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),pi=w(`$ZodNullable`,(e,t)=>{O.init(e,t),C(e,`optin`,e=>e.def.innerType._zod.optin),C(e,`optout`,e=>e.def.innerType._zod.optout),C(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${_e(t.source)}|null)$`):void 0}),C(e,`values`,e=>e.def.innerType._zod.values?new Set([...e.def.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),mi=w(`$ZodDefault`,(e,t)=>{O.init(e,t),e._zod.optin=`defaulted`,C(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>hi(e,t)):hi(r,t)}});function hi(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const gi=w(`$ZodPrefault`,(e,t)=>{O.init(e,t),e._zod.optin=`defaulted`,C(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),_i=w(`$ZodNonOptional`,(e,t)=>{O.init(e,t),C(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>vi(t,e)):vi(i,e)}});function vi(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}function yi(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(e=>$e(e,r,E()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}const bi=w(`$ZodCatch`,(e,t)=>{O.init(e,t),C(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),C(e,`optout`,e=>e.def.innerType._zod.optout),C(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(r=>yi(e,r,t,n)):yi(e,r,t,n)}}),xi=w(`$ZodPipe`,(e,t)=>{O.init(e,t),C(e,`values`,e=>e.def.in._zod.values),C(e,`optin`,e=>e.def.in._zod.optin),C(e,`optout`,e=>e.def.out._zod.optout),C(e,`propValues`,e=>e.def.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Si(e,t.in,n)):Si(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Si(e,t.out,n)):Si(r,t.out,n)}});function Si(e,t,n){return e.issues.some(e=>e.code!==`unrecognized_keys`)?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Ci=w(`$ZodPreprocess`,(e,t)=>{xi.init(e,t)}),wi=w(`$ZodReadonly`,(e,t)=>{O.init(e,t),C(e,`propValues`,e=>e.def.innerType._zod.propValues),C(e,`values`,e=>e.def.innerType._zod.values),C(e,`optin`,e=>e.def.innerType?._zod?.optin),C(e,`optout`,e=>e.def.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Ti):Ti(r)}});function Ti(e){return e.memo||(e.value=Object.freeze(e.value)),e}const Ei=w(`$ZodCustom`,(e,t)=>{D.init(e,t),O.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Di(t,n,r,e));Di(i,n,r,e)}});function Di(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(it(e))}}var Oi=class extends Error{constructor(){super(`Cannot parse a reference cycle that closes through a transform`),this.name=`ZodCyclicError`}};const ki=`~memo`,Ai=[];function ji(e){return typeof e==`object`&&!!e}function Mi(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}const Ni=new WeakMap;function Pi(e,t,n){let r=Ni.get(e);if(r!==void 0)return r?2:0;if(t.has(e))return 2;t.add(e);let i=0,a=e=>{if(i!==2&&e?._zod){let r=Pi(e,t,n);r>i&&(i=r)}},o=(e,r)=>{let i=0;for(let a of Reflect.ownKeys(e)){let o=Object.getOwnPropertyDescriptor(e,a);if(r&&!o.enumerable)continue;let s=o.get?1:o.value?._zod?Pi(o.value,t,n):0;s>i&&(i=s)}return i},s=e=>{e>i&&(i=e)},c=e._zod.def;switch(c.type){case`object`:{let e=be(c);s(e?o(e,!0):1),a(c.catchall);break}case`array`:a(c.element);break;case`tuple`:for(let e of c.items)a(e);a(c.rest);break;case`record`:case`map`:a(c.keyType),a(c.valueType);break;case`set`:a(c.valueType);break;case`union`:for(let e of c.options)a(e);break;case`intersection`:a(c.left),a(c.right);break;case`optional`:case`nullable`:case`default`:case`prefault`:case`catch`:case`readonly`:case`nonoptional`:case`promise`:case`success`:a(c.innerType);break;case`pipe`:a(c.in),a(c.out);break;case`function`:a(c.input),a(c.output);break;case`lazy`:{let r=c._cachedInner??(n?e._zod.innerType:void 0);s(r?Pi(r,t,!1):1);break}case`template_literal`:case`string`:case`number`:case`int`:case`boolean`:case`bigint`:case`symbol`:case`undefined`:case`null`:case`void`:case`never`:case`any`:case`unknown`:case`date`:case`nan`:case`enum`:case`literal`:case`file`:case`transform`:case`custom`:break;default:for(let e in c){let t=Object.getOwnPropertyDescriptor(c,e);if(!t||t.get)continue;let n=t.value;if(!(!n||typeof n!=`object`)){if(n._zod)a(n);else if(Array.isArray(n))for(let e of n)a(e)}}}return t.delete(e),Fi(e,i)}function Fi(e,t){return t!==1&&Ni.set(e,t===2),t}function Ii(e,t){let n=e.buckets.get(t);return n||(n=new WeakMap,e.buckets.set(t,n)),n}let Li;const Ri=[],zi={alloc(e,t,n){let r=Li;if(!r)return n;Li=void 0;let i={value:n,issues:null};return r.set(t.value,i),Ri.push(i),n},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,n=(e,n)=>{if(n.direction!==`backward`&&Vi(n,e.value))throw new Oi;return t(e,n)};e._zod.parse=n,e._zod.run===t&&(e._zod.run=n)})},attach(e){var t;let n,r=!1,i,a;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,o=(s,c)=>{if(n===void 0){let i=Pi(e,new Set,!1);if(i===0)return e._zod.parse=t,e._zod.run===o&&(e._zod.run=t),t(s,c);i===2||r?n=!0:r=!0}let l=s.value;if(!ji(l))return t(s,c);let u=c[ki];u||(u={buckets:new WeakMap,backEdges:void 0},c[ki]=u);let d;i===c?d=a:(d=Ii(u,e),i=c,a=d);let f=d.get(l);if(f)return s.value=f.value,f.issues?f.issues.length&&s.issues.push(...Mi(f.issues)):(s.memo=!0,u.backEdges??=new WeakSet,u.backEdges.add(f.value)),s;Li=d;let p=Ri.length,m=t(s,c);Li=void 0;let h=Ri.length>p?Ri.pop():void 0;return m instanceof Promise?m.then(e=>(h&&(h.issues=e.issues.length?Mi(e.issues):Ai),e)):(h&&(h.issues=m.issues.length?Mi(m.issues):Ai),m)};e._zod.parse=o,e._zod.run===t&&(e._zod.run=o)})}};function Bi(){return zi}function Vi(e,t){let n=e[ki]?.backEdges;return n!==void 0&&ji(t)&&n.has(t)}const Hi=()=>{let e={string:{unit:`characters`,verb:`to have`},file:{unit:`bytes`,verb:`to have`},array:{unit:`items`,verb:`to have`},set:{unit:`items`,verb:`to have`},map:{unit:`entries`,verb:`to have`}};function t(t){return e[t]??null}let n={regex:`input`,email:`email address`,url:`URL`,emoji:`emoji`,uuid:`UUID`,uuidv4:`UUIDv4`,uuidv6:`UUIDv6`,nanoid:`nanoid`,guid:`GUID`,cuid:`cuid`,cuid2:`cuid2`,ulid:`ULID`,xid:`XID`,ksuid:`KSUID`,datetime:`ISO datetime`,date:`ISO date`,time:`ISO time`,duration:`ISO duration`,ipv4:`IPv4 address`,ipv6:`IPv6 address`,mac:`MAC address`,cidrv4:`IPv4 range`,cidrv6:`IPv6 range`,base64:`base64-encoded string`,base64url:`base64url-encoded string`,json_string:`JSON string`,e164:`E.164 number`,currency_code:`currency code`,credit_card:`credit card number`,iban:`IBAN`,jwt:`JWT`,template_literal:`input`},r={nan:`NaN`};function i(e,t){return e===`number`&&typeof t==`number`&&!Number.isFinite(t)?String(t):r[e]??e}return e=>{switch(e.code){case`invalid_type`:return`Invalid input: expected ${i(e.expected)}, received ${i(rt(e.input),e.input)}`;case`invalid_value`:return e.values.length===1?`Invalid input: expected ${Fe(e.values[0])}`:`Invalid option: expected one of ${fe(e.values,`|`)}`;case`too_big`:{let n=e.exact?`exactly `:e.inclusive?`<=`:`<`,r=t(e.origin);return r?`Too big: expected ${e.origin??`value`} to have ${n}${e.maximum.toString()} ${r.unit??`elements`}`:`Too big: expected ${e.origin??`value`} to be ${n}${e.maximum.toString()}`}case`too_small`:{let n=e.exact?`exactly `:e.inclusive?`>=`:`>`,r=t(e.origin);return r?`Too small: expected ${e.origin} to have ${n}${e.minimum.toString()} ${r.unit}`:`Too small: expected ${e.origin} to be ${n}${e.minimum.toString()}`}case`invalid_format`:{let t=e;return t.format===`starts_with`?`Invalid string: must start with "${t.prefix}"`:t.format===`ends_with`?`Invalid string: must end with "${t.suffix}"`:t.format===`includes`?`Invalid string: must include "${t.includes}"`:t.format===`regex`?`Invalid string: must match pattern ${t.pattern}`:`Invalid ${n[t.format]??e.format}`}case`not_multiple_of`:return`Invalid number: must be a multiple of ${e.divisor}`;case`unrecognized_keys`:return`Unrecognized key${e.keys.length>1?`s`:``}: ${fe(e.keys,`, `)}`;case`invalid_key`:return`Invalid key in ${e.origin}`;case`invalid_union`:return e.options&&Array.isArray(e.options)&&e.options.length>0?`Invalid discriminator value. Expected ${e.options.map(e=>`'${e}'`).join(` | `)}`:e.inclusive===!1?`Invalid input: more than one option matched`:`Invalid input`;case`invalid_element`:return`Invalid value in ${e.origin}`;default:return`Invalid input`}}};function Ui(){return{localeError:Hi()}}var Wi,Gi=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Ki(){return new Gi}(Wi=globalThis).__zod_globalRegistry??(Wi.__zod_globalRegistry=Ki());const qi=globalThis.__zod_globalRegistry;function Ji(e){return e.checks&&=[...e.checks],e}function Yi(e,t){return new e(Ji({type:`string`,...x(t)}))}function Xi(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...x(t)})}function Zi(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...x(t)})}function Qi(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...x(t)})}function $i(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...x(t)})}function ea(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...x(t)})}function ta(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...x(t)})}function na(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...x(t)})}function ra(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...x(t)})}function ia(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...x(t)})}function aa(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...x(t)})}function oa(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...x(t)})}function sa(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...x(t)})}function ca(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...x(t)})}function la(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...x(t)})}function ua(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...x(t)})}function da(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...x(t)})}function fa(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...x(t)})}function pa(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...x(t)})}function ma(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...x(t)})}function ha(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...x(t)})}function ga(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...x(t)})}function _a(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...x(t)})}function va(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...x(t)})}function ya(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...x(t)})}function ba(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...x(t)})}function xa(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...x(t)})}function Sa(e,t){return new e(Ji({type:`number`,checks:[],...x(t)}))}function Ca(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...x(t)})}function wa(e,t){return new e({type:`boolean`,...x(t)})}function Ta(e,t){return new e({type:`null`,...x(t)})}function Ea(e){return new e({type:`unknown`})}function Da(e,t){return new e({type:`never`,...x(t)})}function Oa(e,t){return new Pn({check:`less_than`,...x(t),value:e,inclusive:!1})}function ka(e,t){return new Pn({check:`less_than`,...x(t),value:e,inclusive:!0})}function Aa(e,t){return new Fn({check:`greater_than`,...x(t),value:e,inclusive:!1})}function ja(e,t){return new Fn({check:`greater_than`,...x(t),value:e,inclusive:!0})}function Ma(e,t){return new In({check:`multiple_of`,...x(t),value:e})}function Na(e,t){return new Rn({check:`max_length`,...x(t),maximum:e})}function Pa(e,t){return new zn({check:`min_length`,...x(t),minimum:e})}function Fa(e,t){return new Bn({check:`length_equals`,...x(t),length:e})}function Ia(e,t){return new Hn({check:`string_format`,format:`regex`,...x(t),pattern:e})}function La(e){return new Un({check:`string_format`,format:`lowercase`,...x(e)})}function Ra(e){return new Wn({check:`string_format`,format:`uppercase`,...x(e)})}function za(e,t){return new Gn({check:`string_format`,format:`includes`,...x(t),includes:e})}function Ba(e,t){return new Kn({check:`string_format`,format:`starts_with`,...x(t),prefix:e})}function Va(e,t){return new qn({check:`string_format`,format:`ends_with`,...x(t),suffix:e})}function Ha(e){return new Jn({check:`overwrite`,tx:e})}function Ua(e){return Ha(t=>t.normalize(e))}function Wa(){return Ha(e=>e.trim())}function Ga(){return Ha(e=>e.toLowerCase())}function Ka(){return Ha(e=>e.toUpperCase())}function qa(){return Ha(e=>Ee(e))}function Ja(e,t,n){return new e({type:`array`,element:t,...x(n)})}function Ya(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...x(n)})}function Xa(e,t){let n=Za(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(it(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(it(r))}},e(t.value,t)),t);return n}function Za(e,t){let n=new D({check:`custom`,...x(t)});return n._zod.check=e,n}function Qa(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&ye(e,t,n[t]);return e}function $a(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??qi,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function eo(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function A(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,A(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Qa(o.schema,c),t.io===`input`&&j(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function to(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function no(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${to(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+to(a)}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
56
+
57
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}r.count>1&&e.reused===`ref`&&a(n)}e.external&&(e.sharedDefsExtractedFor=e.external)}function ro(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;ro(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}const io=new Set([`type`,`properties`,`required`,`additionalProperties`]),ao=[`oneOf`,`anyOf`];function oo(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function so(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!io.has(e))return null;t.push(n)}let n={},r=new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??oo(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}ye(n,r,e.length===1?e[0]:so(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=oo(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function co(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of io)if(t in e)return;let n=t.filter(e=>ao.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=so(t);else{let e=n[0],i=ao.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>so([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,Qa(e,r))}function lo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Qa(i,s),Qa(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())ro(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])co(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Qa(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,ye(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,`~standard`,{value:{...t[`~standard`],jsonSchema:{input:fo(t,`input`,e.processors),output:fo(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function j(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return j(r.element,n);if(r.type===`set`)return j(r.valueType,n);if(r.type===`lazy`)return j(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type===`default`||r.type===`prefault`||r.type===`catch`)return j(r.innerType,n);if(r.type===`intersection`)return j(r.left,n)||j(r.right,n);if(r.type===`record`||r.type===`map`)return j(r.keyType,n)||j(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:j(r.in,n)||j(r.out,n);if(r.type===`object`){for(let e in r.shape)if(j(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(j(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(j(e,n))return!0;return!!(r.rest&&j(r.rest,n))}return!1}const uo=(e,t={})=>n=>{let r=$a({...n,processors:t});return A(e,r),no(r,e),lo(r,e)},fo=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=$a({...i??{},target:a,io:t,processors:n});return A(e,o),no(o,e),lo(o,e)},po=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},mo=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},ho=(e,t)=>{po(e,`minimum`,t),mo(e,`maximum`,t)},go=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},_o=(e,t)=>{e.patterns??=new Set,e.patterns.add(t)},vo=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},yo=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},bo=(e,t)=>po(e,`minimum`,t.minimum),xo=(e,t)=>mo(e,`maximum`,t.maximum),So=e=>(t,n)=>{yo(t,n.format);let[r,i]=e[n.format];po(t,`minimum`,r),mo(t,`maximum`,i)},Co={greater_than:(e,t)=>po(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>mo(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>go(e,t.value),number_format:So(Le),bigint_format:So(Re),min_length:bo,max_length:xo,length_equals:(e,t)=>ho(e,t.length),min_size:bo,max_size:xo,size_equals:(e,t)=>ho(e,t.size),string_format:(e,t)=>{yo(e,t.format),t.pattern&&_o(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>vo(e,t.mime)};function M(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)Co[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&po(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&po(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&mo(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&mo(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&go(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&vo(t,i.mime);for(let e of i.patterns??[])_o(t,e);return t}const wo={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},To=new Map([[jr,hn],[Nr,gn]]),Eo=e=>To.get(e)??e,Do=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=M(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=wo[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(Eo);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Oo=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=M(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):eo(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},ko=(e,t,n,r)=>{n.type=`boolean`},Ao=(e,t,n,r)=>{t.target===`openapi-3.0`?(n.type=`string`,n.nullable=!0,n.enum=[null]):n.type=`null`},jo=(e,t,n,r)=>{n.not={}},Mo=(e,t,n,r)=>{let i=e._zod.def,a=de(i.entries);if(a.length===0){n.not={};return}a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},No=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(eo(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(eo(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);if(a.length!==0)if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a},Po=(e,t,n,r)=>{eo(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},Fo=(e,t,n,r)=>{eo(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Io=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=M(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=A(a.element,t,{...r,path:[...r.path,`items`]})};function Lo(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?Lo(t.out):t.type===`catch`?Lo(t.innerType):e._zod.optin}const Ro=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&eo(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;for(let e in i.type=`object`,i.properties={},o)ye(i.properties,e,A(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?Lo(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=A(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},zo=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>A(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Bo=(e,t,n,r)=>{let i=e._zod.def,a=A(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=A(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)};function Vo(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=Vo(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>Vo(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i?(p.type=`string`,a||(p.pattern=(r.includes(`number`)?Dn:En).source),p):p}const Ho=new WeakMap;function Uo(e){let t=new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=new Map;for(let r of Ho.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=Vo(t,a,new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}const Wo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=M(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=A(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)ye(i.patternProperties,Eo(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=A(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=Ho.get(t);n||(n=[],Ho.set(t,n),t.deferred.push(()=>Uo(t))),n.push(e)}i.additionalProperties=A(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&Lo(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},Go=(e,t,n,r)=>{let i=e._zod.def,a=A(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Ko=(e,t,n,r)=>{let i=e._zod.def;A(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},qo=Symbol();function Jo(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(eo(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),qo):JSON.parse(o)}const Yo=(e,t,n,r)=>{let i=e._zod.def;A(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=Jo(i.defaultValue,e,t,n,r);o!==qo&&(n.default=o)},Xo=(e,t,n,r)=>{let i=e._zod.def;A(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=Jo(i.defaultValue,e,t,n,r);o!==qo&&(n._prefault=o)},Zo=(e,t,n,r)=>{let i=e._zod.def;A(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{eo(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},Qo=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;A(o,t,r);let s=t.seen.get(e);s.ref=o},$o=(e,t,n,r)=>{let i=e._zod.def;A(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},es=(e,t,n,r)=>{let i=e._zod.def;A(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ts=new WeakSet([Object.prototype,Error.prototype]);function ns(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}const N=w(`ZodError`,(e,t)=>{kt.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);ts.has(n)||(ts.add(n),ns(n,`format`,e=>t=>Mt(e,t)),ns(n,`flatten`,e=>t=>jt(e,t)),ns(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,pe,2)}),ns(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,pe,2)}),Object.defineProperty(n,`isEmpty`,{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),rs=Pt(N),is=Ft(N),as=It(N),os=Rt(N),ss=Wt(N),cs=Gt(N),ls=Kt(N),us=qt(N),ds=Jt(N),fs=Yt(N),ps=Xt(N),ms=Zt(N);function hs(){T.localeError||E(Ui())}function gs(){T.memoizer||E({memoizer:Bi()})}const P=w(`ZodType`,(e,t)=>(hs(),O.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(b(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return Pe(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Oc(e,t))},superRefine(e,t){return this.check(kc(e,t))},overwrite(e){return this.check(Ha(e))},optional(){return lc(this)},exactOptional(){return dc(this)},nullable(){return pc(this)},nullish(){return lc(pc(this))},nonoptional(e){return yc(this,e)},array(){return V(this)},or(e){return U([this,e])},and(e){return W(this,e)},transform(e){return Cc(this,sc(e))},default(e){return hc(this,e)},prefault(e){return _c(this,e)},catch(e){return xc(this,e)},pipe(e){return Cc(this,e)},readonly(){return Ec(this)},describe(e){let t=this.clone();return qi.add(t,{description:e}),t},meta(...e){if(e.length===0)return qi.get(this);let t=this.clone();return qi.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return st(this,`~standard`,{...$n(this),jsonSchema:{input:fo(this,`input`),output:fo(this,`output`)}})},set"~standard"(e){ot(this,`~standard`,e)},parse:function e(t,n){return rs(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await is(this,t,n,{callee:e})},safeParse(e,t){return as(this,e,t)},async safeParseAsync(e,t){return os(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){ot(this,`spa`,e)},validate(e,t){return Vt(this,e,t)},validateAsync(e,t){return Ut(this,e,t)},encode:function e(t,n){return ss(this,t,n,{callee:e})},decode:function e(t,n){return cs(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await ls(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await us(this,t,n,{callee:e})},safeEncode(e,t){return ds(this,e,t)},safeDecode(e,t){return fs(this,e,t)},async safeEncodeAsync(e,t){return ps(this,e,t)},async safeDecodeAsync(e,t){return ms(this,e,t)},toJSONSchema(e){return uo(this,{})(e)},get description(){return qi.get(this)?.description},get _def(){return this._zod.def}}),_s=w(`_ZodString`,(e,t)=>{er.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Do(e,t,n,r)},ct({format:e=>M(e).format??null,minLength:e=>M(e).minimum??null,maxLength:e=>M(e).maximum??null},{regex(...e){return this.check(Ia(...e))},includes(...e){return this.check(za(...e))},startsWith(...e){return this.check(Ba(...e))},endsWith(...e){return this.check(Va(...e))},min(...e){return this.check(Pa(...e))},max(...e){return this.check(Na(...e))},length(...e){return this.check(Fa(...e))},nonempty(...e){return this.check(Pa(1,...e))},lowercase(e){return this.check(La(e))},uppercase(e){return this.check(Ra(e))},trim(){return this.check(Wa())},normalize(...e){return this.check(Ua(...e))},toLowerCase(){return this.check(Ga())},toUpperCase(){return this.check(Ka())},slugify(){return this.check(qa())}})),vs=w(`ZodString`,(e,t)=>{er.init(e,t),_s.init(e,t)},{email(e){return this.check(Xi(Cs,e))},url(e){return this.check(na(Es,e))},jwt(e){return this.check(_a(Hs,e))},emoji(e){return this.check(ra(Os,e))},guid(e){return this.check(Zi(ws,e))},uuid(e){return this.check(Qi(Ts,e))},uuidv4(e){return this.check($i(Ts,e))},uuidv6(e){return this.check(ea(Ts,e))},uuidv7(e){return this.check(ta(Ts,e))},nanoid(e){return this.check(ia(ks,e))},cuid(e){return this.check(aa(As,e))},cuid2(e){return this.check(oa(js,e))},ulid(e){return this.check(sa(Ms,e))},base64(e){return this.check(ma(zs,e))},base64url(e){return this.check(ha(Bs,e))},xid(e){return this.check(ca(Ns,e))},ksuid(e){return this.check(la(Ps,e))},ipv4(e){return this.check(ua(Fs,e))},ipv6(e){return this.check(da(Is,e))},cidrv4(e){return this.check(fa(Ls,e))},cidrv6(e){return this.check(pa(Rs,e))},e164(e){return this.check(ga(Vs,e))},datetime(e){return this.check(va(ys,e))},date(e){return this.check(ya(bs,e))},time(e){return this.check(ba(xs,e))},duration(e){return this.check(xa(Ss,e))}});function F(e){return Yi(vs,e)}const I=w(`ZodStringFormat`,(e,t)=>{k.init(e,t),_s.init(e,t)}),ys=w(`ZodISODateTime`,(e,t)=>{yr.init(e,t),I.init(e,t)}),bs=w(`ZodISODate`,(e,t)=>{br.init(e,t),I.init(e,t)}),xs=w(`ZodISOTime`,(e,t)=>{xr.init(e,t),I.init(e,t)}),Ss=w(`ZodISODuration`,(e,t)=>{Sr.init(e,t),I.init(e,t)}),Cs=w(`ZodEmail`,(e,t)=>{rr.init(e,t),I.init(e,t)}),ws=w(`ZodGUID`,(e,t)=>{tr.init(e,t),I.init(e,t)}),Ts=w(`ZodUUID`,(e,t)=>{nr.init(e,t),I.init(e,t)}),Es=w(`ZodURL`,(e,t)=>{dr.init(e,t),I.init(e,t)});function Ds(e){return na(Es,e)}const Os=w(`ZodEmoji`,(e,t)=>{fr.init(e,t),I.init(e,t)}),ks=w(`ZodNanoID`,(e,t)=>{pr.init(e,t),I.init(e,t)}),As=w(`ZodCUID`,(e,t)=>{mr.init(e,t),I.init(e,t)}),js=w(`ZodCUID2`,(e,t)=>{hr.init(e,t),I.init(e,t)}),Ms=w(`ZodULID`,(e,t)=>{gr.init(e,t),I.init(e,t)}),Ns=w(`ZodXID`,(e,t)=>{_r.init(e,t),I.init(e,t)}),Ps=w(`ZodKSUID`,(e,t)=>{vr.init(e,t),I.init(e,t)}),Fs=w(`ZodIPv4`,(e,t)=>{Cr.init(e,t),I.init(e,t)}),Is=w(`ZodIPv6`,(e,t)=>{Er.init(e,t),I.init(e,t)}),Ls=w(`ZodCIDRv4`,(e,t)=>{Dr.init(e,t),I.init(e,t)}),Rs=w(`ZodCIDRv6`,(e,t)=>{kr.init(e,t),I.init(e,t)}),zs=w(`ZodBase64`,(e,t)=>{Mr.init(e,t),I.init(e,t)}),Bs=w(`ZodBase64URL`,(e,t)=>{Fr.init(e,t),I.init(e,t)}),Vs=w(`ZodE164`,(e,t)=>{Ir.init(e,t),I.init(e,t)}),Hs=w(`ZodJWT`,(e,t)=>{Rr.init(e,t),I.init(e,t)}),Us=w(`ZodNumber`,(e,t)=>{zr.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oo(e,t,n,r),e.isFinite=!0},ct({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=M(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=M(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=M(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>M(e).format??null},{gt(e,t){return this.check(Aa(e,t))},gte(e,t){return this.check(ja(e,t))},min(e,t){return this.check(ja(e,t))},lt(e,t){return this.check(Oa(e,t))},lte(e,t){return this.check(ka(e,t))},max(e,t){return this.check(ka(e,t))},int(e){return this.check(R(e))},safe(e){return this.check(R(e))},positive(e){return this.check(Aa(0,e))},nonnegative(e){return this.check(ja(0,e))},negative(e){return this.check(Oa(0,e))},nonpositive(e){return this.check(ka(0,e))},multipleOf(e,t){return this.check(Ma(e,t))},step(e,t){return this.check(Ma(e,t))},finite(){return this}}));function L(e){return Sa(Us,e)}const Ws=w(`ZodNumberFormat`,(e,t)=>{Br.init(e,t),Us.init(e,t)});function R(e){return Ca(Ws,e)}const Gs=w(`ZodBoolean`,(e,t)=>{Vr.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ko(e,t,n,r)});function z(e){return wa(Gs,e)}const Ks=w(`ZodNull`,(e,t)=>{Hr.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ao(e,t,n,r)});function qs(e){return Ta(Ks,e)}const Js=w(`ZodUnknown`,(e,t)=>{Ur.init(e,t),P.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function B(){return Ea(Js)}const Ys=w(`ZodNever`,(e,t)=>{Wr.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>jo(e,t,n,r)});function Xs(e){return Da(Ys,e)}const Zs=w(`ZodArray`,(e,t)=>{gs(),Jr.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Io(e,t,n,r),e.element=t.element},{min(e,t){return this.check(Pa(e,t))},nonempty(e){return this.check(Pa(1,e))},max(e,t){return this.check(Na(e,t))},length(e,t){return this.check(Fa(e,t))},unwrap(){return this.element}});function V(e,t){return Ja(Zs,e,t)}const Qs=w(`ZodObject`,(e,t)=>{gs(),ei.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ro(e,t,n,r),mt(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return ic(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(b(this._zod.def,{catchall:e}))},passthrough(){return this.clone(b(this._zod.def,{catchall:B()}))},loose(){return this.clone(b(this._zod.def,{catchall:B()}))},strict(){return this.clone(b(this._zod.def,{catchall:Xs()}))},strip(){return this.clone(b(this._zod.def,{catchall:void 0}))},extend(e){return He(this,e)},safeExtend(e){return We(this,e)},merge(e){return Ge(this,e)},pick(e){return ze(this,e)},omit(e){return Ve(this,e)},partial(...e){return Ke(cc,this,e[0])},exactPartial(...e){return Ke(uc,this,e[0],`exactPartial`)},required(...e){return qe(vc,this,e[0])}});function H(e,t){return new Qs({type:`object`,shape:e??{},...x(t)})}function $s(e,t){return new Qs({type:`object`,shape:e,catchall:B(),...x(t)})}const ec=w(`ZodUnion`,(e,t)=>{ni.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zo(e,t,n,r),e.options=t.options});function U(e,t){return new ec({type:`union`,options:e,...x(t)})}const tc=w(`ZodIntersection`,(e,t)=>{ri.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bo(e,t,n,r)});function W(e,t){return new tc({type:`intersection`,left:e,right:t})}const nc=w(`ZodRecord`,(e,t)=>{gs(),oi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wo(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function G(e,t,n){return!t||!t._zod?new nc({type:`record`,keyType:F(),valueType:e,...x(t)}):new nc({type:`record`,keyType:e,valueType:t,...x(n)})}const rc=w(`ZodEnum`,(e,t)=>{si.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mo(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new rc({...t,checks:[],...x(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new rc({...t,checks:[],...x(r),entries:i})}});function ic(e,t){return new rc({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...x(t)})}const ac=w(`ZodLiteral`,(e,t)=>{ci.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>No(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function K(e,t){return new ac({type:`literal`,values:Array.isArray(e)?e:[e],...x(t)})}const oc=w(`ZodTransform`,(e,t)=>{gs(),li.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fo(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new St(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(it(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(it(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function sc(e){return new oc({type:`transform`,transform:e})}const cc=w(`ZodOptional`,(e,t)=>{di.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>es(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function lc(e){return new cc({type:`optional`,innerType:e})}const uc=w(`ZodExactOptional`,(e,t)=>{fi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>es(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function dc(e){return new uc({type:`optional`,innerType:e})}const fc=w(`ZodNullable`,(e,t)=>{pi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Go(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function pc(e){return new fc({type:`nullable`,innerType:e})}const mc=w(`ZodDefault`,(e,t)=>{mi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function hc(e,t){return new mc({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():je(t)}})}const gc=w(`ZodPrefault`,(e,t)=>{gi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function _c(e,t){return new gc({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():je(t)}})}const vc=w(`ZodNonOptional`,(e,t)=>{_i.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ko(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function yc(e,t){return new vc({type:`nonoptional`,innerType:e,...x(t)})}const bc=w(`ZodCatch`,(e,t)=>{bi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function xc(e,t){return new bc({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:ht(t)})}const Sc=w(`ZodPipe`,(e,t)=>{xi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qo(e,t,n,r),e.in=t.in,e.out=t.out});function Cc(e,t){return new Sc({type:`pipe`,in:e,out:t})}const wc=w(`ZodPreprocess`,(e,t)=>{Sc.init(e,t),Ci.init(e,t)}),Tc=w(`ZodReadonly`,(e,t)=>{wi.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$o(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ec(e){return new Tc({type:`readonly`,innerType:e})}const Dc=w(`ZodCustom`,(e,t)=>{Ei.init(e,t),P.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Po(e,t,n,r)});function Oc(e,t={}){return Ya(Dc,e,t)}function kc(e,t){return Xa(e,t)}function Ac(e,t){return new wc({type:`pipe`,in:sc(e),out:t})}const jc=Symbol(`skippedItem`);function q(e,t){return e.catch(t)}function Mc(e,t){let n=e.catch(t);return B().transform((e,t)=>e===void 0?(t.addIssue({code:`custom`,message:`Required value is missing`}),_t):n.parse(e))}function Nc(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return;let n=e[t];return typeof n==`string`?n:void 0}function Pc(e,t,n){return e.superRefine((e,r)=>{let i=Nc(e,t);i!==void 0&&n.includes(i)&&r.addIssue({code:`custom`,path:[t],message:`${t} ${JSON.stringify(i)} is reserved by a known variant, but the value does not match that variant's schema`})})}function Fc(e,t,n){return B().transform((r,i)=>{let a=e.safeParse(r);if(!a.success){for(let e of a.error.issues)i.addIssue({...e,input:r});return _t}let o=a.data,s=Nc(r,t);if(s!==void 0&&!n.includes(s)){let e=r;for(let[t,n]of Object.entries(e))t!==`__proto__`&&(Object.hasOwn(o,t)||(o[t]=n))}return o})}function Ic(e,t){return Ac(e=>{if(typeof e!=`object`||!e||Array.isArray(e))return e;let n=e,r=n[t];if(r==null||typeof r==`string`)return e;let i={...n};return delete i[t],i},e)}function J(e){return V(e.catch(jc)).transform(e=>e.filter(e=>e!==jc))}const Lc=U([L(),F()]).nullable(),Y=F(),Rc=H({sessionId:Y,path:F(),content:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),zc=H({sessionId:Y,path:F(),line:R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}).nullish(),limit:R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}).nullish(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Bc=F(),Vc=U([K(`read`),K(`edit`),K(`delete`),K(`move`),K(`search`),K(`execute`),K(`think`),K(`fetch`),K(`switch_mode`),K(`other`)]),Hc=U([K(`pending`),K(`in_progress`),K(`completed`),K(`failed`)]),Uc=H({audience:q(J(U([K(`assistant`),K(`user`)])).nullish(),()=>void 0),lastModified:q(F().nullish(),()=>void 0),priority:q(L().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Wc=H({annotations:q(Uc.nullish(),()=>void 0),text:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Gc=H({annotations:q(Uc.nullish(),()=>void 0),data:F(),mimeType:F(),uri:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Kc=H({annotations:q(Uc.nullish(),()=>void 0),data:F(),mimeType:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),qc=H({annotations:q(Uc.nullish(),()=>void 0),description:q(F().nullish(),()=>void 0),mimeType:q(F().nullish(),()=>void 0),name:F(),size:q(L().nullish(),()=>void 0),title:q(F().nullish(),()=>void 0),uri:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Jc=U([H({mimeType:q(F().nullish(),()=>void 0),text:F(),uri:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),H({blob:F(),mimeType:q(F().nullish(),()=>void 0),uri:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)})]),Yc=H({annotations:q(Uc.nullish(),()=>void 0),resource:Jc,_meta:q(G(F(),B()).nullish(),()=>void 0)}),Xc=U([Wc.and(H({type:K(`text`)})),Gc.and(H({type:K(`image`)})),Kc.and(H({type:K(`audio`)})),qc.and(H({type:K(`resource_link`)})),Yc.and(H({type:K(`resource`)}))]),Zc=H({content:Xc,_meta:q(G(F(),B()).nullish(),()=>void 0)}),Qc=H({path:F(),oldText:q(F().nullish(),()=>void 0),newText:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),$c=F(),el=H({terminalId:$c,_meta:q(G(F(),B()).nullish(),()=>void 0)}),tl=U([Zc.and(H({type:K(`content`)})),Qc.and(H({type:K(`diff`)})),el.and(H({type:K(`terminal`)}))]),nl=H({path:F(),line:q(R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),rl=H({toolCallId:Bc,kind:q(Vc.nullish(),()=>void 0),status:q(Hc.nullish(),()=>void 0),title:q(F().nullish(),()=>void 0),name:q(F().nullish(),()=>void 0),content:q(J(tl).nullish(),()=>void 0),locations:q(J(nl).nullish(),()=>void 0),rawInput:q(B().optional(),()=>void 0),rawOutput:q(B().optional(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),il=F(),al=U([K(`allow_once`),K(`allow_always`),K(`reject_once`),K(`reject_always`)]),ol=H({sessionId:Y,toolCall:rl,options:V(H({optionId:il,name:F(),kind:al,_meta:q(G(F(),B()).nullish(),()=>void 0)})),_meta:q(G(F(),B()).nullish(),()=>void 0)}),sl=H({name:F(),value:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),cl=H({sessionId:Y,command:F(),args:V(F()).optional(),env:V(sl).optional(),cwd:F().nullish(),outputByteLimit:L().nullish(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),ll=H({sessionId:Y,terminalId:$c,_meta:q(G(F(),B()).nullish(),()=>void 0)}),ul=H({sessionId:Y,terminalId:$c,_meta:q(G(F(),B()).nullish(),()=>void 0)}),dl=H({sessionId:Y,terminalId:$c,_meta:q(G(F(),B()).nullish(),()=>void 0)}),fl=H({sessionId:Y,terminalId:$c,_meta:q(G(F(),B()).nullish(),()=>void 0)}),pl=H({sessionId:Y,toolCallId:q(Bc.nullish(),()=>void 0)}),ml=H({requestId:Lc}),hl=K(`object`),gl=U([K(`email`),K(`uri`),K(`date`),K(`date-time`)]),_l=H({const:F(),title:F(),description:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),vl=H({title:q(F().nullish(),()=>void 0),description:q(F().nullish(),()=>void 0),minLength:R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}).nullish(),maxLength:R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}).nullish(),pattern:F().nullish(),format:gl.nullish(),default:q(F().nullish(),()=>void 0),enum:V(F()).nullish(),oneOf:V(_l).nullish(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),yl=H({title:q(F().nullish(),()=>void 0),description:q(F().nullish(),()=>void 0),minimum:L().nullish(),maximum:L().nullish(),default:q(L().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),bl=H({title:q(F().nullish(),()=>void 0),description:q(F().nullish(),()=>void 0),minimum:L().nullish(),maximum:L().nullish(),default:q(L().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),xl=H({title:q(F().nullish(),()=>void 0),description:q(F().nullish(),()=>void 0),default:q(z().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Sl=H({enum:V(F()),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Cl=H({anyOf:V(_l),_meta:q(G(F(),B()).nullish(),()=>void 0)}),wl=Fc(U([Sl.and(H({type:K(`string`)})),Pc(H({type:F()}),`type`,[`string`]),Cl]),`type`,[`string`]),Tl=H({title:q(F().nullish(),()=>void 0),description:q(F().nullish(),()=>void 0),minItems:L().nullish(),maxItems:L().nullish(),items:wl,default:q(J(F()).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),El=Fc(U([vl.and(H({type:K(`string`)})),yl.and(H({type:K(`number`)})),bl.and(H({type:K(`integer`)})),xl.and(H({type:K(`boolean`)})),Tl.and(H({type:K(`array`)})),Pc(H({type:F()}),`type`,[`array`,`boolean`,`integer`,`number`,`string`])]),`type`,[`array`,`boolean`,`integer`,`number`,`string`]),Dl=H({type:q(hl.optional().default(`object`),()=>`object`),title:q(F().nullish(),()=>void 0),properties:G(F(),El).optional().default({}),required:V(F()).nullish(),description:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Ol=W(U([pl,ml]),H({requestedSchema:Dl})),kl=F(),Al=W(U([pl,ml]),H({elicitationId:kl,url:Ds()})),jl=Fc(W(U([Ol.and(H({mode:K(`form`)})),Al.and(H({mode:K(`url`)})),Pc(W(U([pl,ml]),H({mode:F()})),`mode`,[`form`,`url`])]),H({message:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)})),`mode`,[`form`,`url`]),Ml=F(),Nl=F(),Pl=H({serverId:Ml,requestId:Nl,method:F(),params:G(F(),B()).nullish(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Fl=B();H({id:Lc,method:F(),params:U([Rc,zc,ol,cl,ll,ul,dl,fl,jl,Pl,Fl]).nullish()});const Il=R().gte(0).lte(65535),Ll=H({image:q(z().optional().default(!1),()=>!1),audio:q(z().optional().default(!1),()=>!1),embeddedContext:q(z().optional().default(!1),()=>!1),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Rl=H({http:q(z().optional().default(!1),()=>!1),sse:q(z().optional().default(!1),()=>!1),acp:q(z().optional().default(!1),()=>!1),_meta:q(G(F(),B()).nullish(),()=>void 0)}),zl=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Bl=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Vl=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Hl=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Ul=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Wl=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Gl=H({list:q(zl.nullish(),()=>void 0),delete:q(Bl.nullish(),()=>void 0),additionalDirectories:q(Vl.nullish(),()=>void 0),fork:q(Hl.nullish(),()=>void 0),resume:q(Ul.nullish(),()=>void 0),close:q(Wl.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Kl=H({logout:q(H({_meta:q(G(F(),B()).nullish(),()=>void 0)}).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),ql=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Jl=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Yl=H({syncKind:U([K(`full`),K(`incremental`)]),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Xl=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Zl=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Ql=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),$l=H({document:q(H({didOpen:q(Jl.nullish(),()=>void 0),didChange:q(Yl.nullish(),()=>void 0),didClose:q(Xl.nullish(),()=>void 0),didSave:q(Zl.nullish(),()=>void 0),didFocus:q(Ql.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),eu=H({maxCount:q(R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),tu=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),nu=H({maxCount:q(R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),ru=H({maxCount:q(R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),iu=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),au=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),ou=H({recentFiles:q(eu.nullish(),()=>void 0),relatedSnippets:q(tu.nullish(),()=>void 0),editHistory:q(nu.nullish(),()=>void 0),userActions:q(ru.nullish(),()=>void 0),openFiles:q(iu.nullish(),()=>void 0),diagnostics:q(au.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),su=H({events:q($l.nullish(),()=>void 0),context:q(ou.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),cu=U([K(`utf-16`),K(`utf-32`),K(`utf-8`)]),lu=H({loadSession:q(z().optional().default(!1),()=>!1),promptCapabilities:q(Ll.optional().default({image:!1,audio:!1,embeddedContext:!1}),()=>({image:!1,audio:!1,embeddedContext:!1})),mcpCapabilities:q(Rl.optional().default({http:!1,sse:!1,acp:!1}),()=>({http:!1,sse:!1,acp:!1})),sessionCapabilities:q(Gl.optional().default({}),()=>({})),auth:q(Kl.optional().default({}),()=>({})),providers:q(ql.nullish(),()=>void 0),nes:q(su.nullish(),()=>void 0),positionEncoding:q(cu.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),uu=F(),du=H({id:uu,name:F(),description:q(F().nullish(),()=>void 0),args:V(F()).optional(),env:G(F(),F()).optional(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),fu=H({id:uu,name:F(),description:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),pu=U([du.and(H({type:K(`terminal`)})),fu]),mu=H({name:F(),title:q(F().nullish(),()=>void 0),version:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),hu=H({protocolVersion:Il,agentCapabilities:q(lu.optional().default({loadSession:!1,promptCapabilities:{image:!1,audio:!1,embeddedContext:!1},mcpCapabilities:{http:!1,sse:!1,acp:!1},sessionCapabilities:{},auth:{}}),()=>({loadSession:!1,promptCapabilities:{image:!1,audio:!1,embeddedContext:!1},mcpCapabilities:{http:!1,sse:!1,acp:!1},sessionCapabilities:{},auth:{}})),authMethods:q(J(pu).optional().default([]),()=>[]),agentInfo:q(mu.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),gu=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),_u=F(),vu=U([K(`anthropic`),K(`openai`),K(`azure`),K(`vertex`),K(`bedrock`),F()]),yu=H({apiType:vu,baseUrl:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),bu=H({providers:V(H({providerId:_u,supported:Mc(J(vu),()=>[]),required:z(),current:yu.nullish(),_meta:q(G(F(),B()).nullish(),()=>void 0)})),_meta:q(G(F(),B()).nullish(),()=>void 0)}),xu=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Su=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Cu=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),wu=F(),Tu=H({currentModeId:wu,availableModes:Mc(J(H({id:wu,name:F(),description:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)})),()=>[]),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Eu=F(),Du=U([K(`mode`),K(`model`),K(`model_config`),K(`thought_level`),F()]),Ou=F(),ku=H({value:Ou,name:F(),description:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Au=H({group:F(),name:F(),options:Mc(J(ku),()=>[]),_meta:q(G(F(),B()).nullish(),()=>void 0)}),ju=H({currentValue:Ou,options:U([V(ku),V(Au)])}),Mu=H({currentValue:z()}),Nu=W(U([ju.and(H({type:K(`select`)})),Mu.and(H({type:K(`boolean`)}))]),H({id:Eu,name:F(),description:q(F().nullish(),()=>void 0),category:q(Du.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)})),Pu=H({sessionId:Y,modes:q(Tu.nullish(),()=>void 0),configOptions:q(J(Nu).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Fu=H({modes:q(Tu.nullish(),()=>void 0),configOptions:q(J(Nu).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Iu=H({sessions:Mc(J(H({sessionId:Y,cwd:F(),additionalDirectories:q(J(F()).optional(),()=>[]),title:q(F().nullish(),()=>void 0),updatedAt:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)})),()=>[]),nextCursor:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Lu=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Ru=H({sessionId:Y,modes:q(Tu.nullish(),()=>void 0),configOptions:q(J(Nu).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),zu=H({modes:q(Tu.nullish(),()=>void 0),configOptions:q(J(Nu).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Bu=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Vu=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Hu=H({configOptions:Mc(J(Nu),()=>[]),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Uu=U([K(`end_turn`),K(`max_tokens`),K(`max_turn_requests`),K(`refusal`),K(`cancelled`)]),Wu=H({totalTokens:L(),inputTokens:L(),outputTokens:L(),thoughtTokens:q(L().nullish(),()=>void 0),cachedReadTokens:q(L().nullish(),()=>void 0),cachedWriteTokens:q(L().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Gu=H({stopReason:Uu,usage:q(Wu.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Ku=H({sessionId:Y,_meta:q(G(F(),B()).nullish(),()=>void 0)}),qu=F(),Ju=H({line:R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}),character:R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Yu=H({start:Ju,end:Ju,_meta:q(G(F(),B()).nullish(),()=>void 0)}),Xu=H({range:Yu,newText:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Zu=H({id:qu,uri:F(),edits:V(Xu),cursorPosition:q(Ju.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Qu=H({id:qu,uri:F(),position:Ju,_meta:q(G(F(),B()).nullish(),()=>void 0)}),$u=H({id:qu,uri:F(),position:Ju,newName:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),ed=H({id:qu,uri:F(),search:F(),replace:F(),isRegex:z().nullish(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),td=H({suggestions:V(U([Zu.and(H({kind:K(`edit`)})),Qu.and(H({kind:K(`jump`)})),$u.and(H({kind:K(`rename`)})),ed.and(H({kind:K(`searchAndReplace`)}))])),_meta:q(G(F(),B()).nullish(),()=>void 0)}),nd=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),rd=B(),id=H({code:U([K(-32700),K(-32600),K(-32601),K(-32602),K(-32603),K(-32800),K(-32e3),K(-32002),R().min(-2147483648,{error:`Invalid value: Expected int32 to be >= -2147483648`}).max(2147483647,{error:`Invalid value: Expected int32 to be <= 2147483647`})]),message:F(),data:q(B().optional(),()=>void 0)});U([H({id:Lc,result:U([hu,gu,bu,xu,Su,Cu,Pu,Fu,Iu,Lu,Ru,zu,Bu,Vu,Hu,Gu,Ku,td,nd,rd])}),H({id:Lc,error:id})]);const ad=F(),od=H({content:Xc,messageId:q(ad.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),sd=H({toolCallId:Bc,title:F(),name:q(F().nullish(),()=>void 0),kind:q(Vc.optional(),()=>void 0),status:q(Hc.optional(),()=>void 0),content:q(J(tl).optional(),()=>[]),locations:q(J(nl).optional(),()=>[]),rawInput:q(B().optional(),()=>void 0),rawOutput:q(B().optional(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),cd=U([K(`high`),K(`medium`),K(`low`)]),ld=U([K(`pending`),K(`in_progress`),K(`completed`)]),ud=H({content:F(),priority:cd,status:ld,_meta:q(G(F(),B()).nullish(),()=>void 0)}),dd=H({entries:Mc(J(ud),()=>[]),_meta:q(G(F(),B()).nullish(),()=>void 0)}),fd=F(),pd=H({planId:fd,entries:Mc(J(ud),()=>[]),_meta:q(G(F(),B()).nullish(),()=>void 0)}),md=H({planId:fd,uri:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),hd=H({planId:fd,content:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),gd=H({plan:U([pd.and(H({type:K(`items`)})),md.and(H({type:K(`file`)})),hd.and(H({type:K(`markdown`)}))]),_meta:q(G(F(),B()).nullish(),()=>void 0)}),_d=H({planId:fd,_meta:q(G(F(),B()).nullish(),()=>void 0)}),vd=H({hint:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),yd=H({availableCommands:Mc(J(H({name:F(),description:F(),input:q(vd.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)})),()=>[]),_meta:q(G(F(),B()).nullish(),()=>void 0)}),bd=H({currentModeId:wu,_meta:q(G(F(),B()).nullish(),()=>void 0)}),xd=H({configOptions:Mc(J(Nu),()=>[]),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Sd=H({title:q(F().nullish(),()=>void 0),updatedAt:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Cd=H({amount:L(),currency:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),wd=H({used:L(),size:L(),cost:q(Cd.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Td=H({severity:U([K(`info`),K(`warning`),K(`error`),F()]),title:F().min(1),description:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Ed=F(),Dd=H({compactionId:Ed,status:U([K(`in_progress`),K(`completed`),K(`failed`),K(`cancelled`),F()]),summary:q(J(Xc).nullish(),()=>void 0),error:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Od=H({compactionId:Ed,content:Xc,_meta:q(G(F(),B()).nullish(),()=>void 0)}),kd=H({cancel:q(H({_meta:q(G(F(),B()).nullish(),()=>void 0)}).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Ad=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),jd=H({error:q(id.nullish(),()=>void 0)}),Md=Ic(Fc(W(U([H({stopReason:K(`end_turn`)}),H({stopReason:K(`max_tokens`)}),H({stopReason:K(`max_turn_requests`)}),H({stopReason:K(`refusal`)}),H({stopReason:K(`cancelled`)}),jd.and(H({stopReason:K(`error`)})),Pc(H({stopReason:F()}),`stopReason`,[`cancelled`,`end_turn`,`error`,`max_tokens`,`max_turn_requests`,`refusal`]),H({stopReason:qs().optional()})]),H({usage:q(Wu.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0),stopReason:q(F().nullish(),()=>void 0)})),`stopReason`,[`cancelled`,`end_turn`,`error`,`max_tokens`,`max_turn_requests`,`refusal`]),`stopReason`),Nd=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Pd=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Fd=Fc(U([Ad.and(H({state:K(`running`)})),Md.and(H({state:K(`idle`)})),Nd.and(H({state:K(`requires_action`)})),Pd.and(H({state:K(`unknown`)})),Pc(H({state:F()}),`state`,[`idle`,`requires_action`,`running`,`unknown`])]),`state`,[`idle`,`requires_action`,`running`,`unknown`]),Id=H({sessionId:Y,title:q(F().nullish(),()=>void 0),description:q(F().nullish(),()=>void 0),capabilities:q(kd.nullish(),()=>void 0),state:q(Fd.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Ld=H({messageId:ad,senderSessionId:q(Y.nullish(),()=>void 0),recipientSessionId:q(Y.nullish(),()=>void 0),content:q(J(Xc).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Rd=H({messageId:ad,senderSessionId:q(Y.nullish(),()=>void 0),recipientSessionId:q(Y.nullish(),()=>void 0),content:Xc,_meta:q(G(F(),B()).nullish(),()=>void 0)}),zd=H({sessionId:Y,update:U([od.and(H({sessionUpdate:K(`user_message_chunk`)})),od.and(H({sessionUpdate:K(`agent_message_chunk`)})),od.and(H({sessionUpdate:K(`agent_thought_chunk`)})),sd.and(H({sessionUpdate:K(`tool_call`)})),rl.and(H({sessionUpdate:K(`tool_call_update`)})),dd.and(H({sessionUpdate:K(`plan`)})),gd.and(H({sessionUpdate:K(`plan_update`)})),_d.and(H({sessionUpdate:K(`plan_removed`)})),yd.and(H({sessionUpdate:K(`available_commands_update`)})),bd.and(H({sessionUpdate:K(`current_mode_update`)})),xd.and(H({sessionUpdate:K(`config_option_update`)})),Sd.and(H({sessionUpdate:K(`session_info_update`)})),wd.and(H({sessionUpdate:K(`usage_update`)})),Td.and(H({sessionUpdate:K(`notice`)})),Dd.and(H({sessionUpdate:K(`compaction_update`)})),Od.and(H({sessionUpdate:K(`compaction_summary_chunk`)})),Id.and(H({sessionUpdate:K(`subagent_update`)})),Ld.and(H({sessionUpdate:K(`session_message`)})),Rd.and(H({sessionUpdate:K(`session_message_chunk`)}))]),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Bd=H({elicitationId:kl,_meta:q(G(F(),B()).nullish(),()=>void 0)}),Vd=B();H({method:F(),params:U([zd,Bd,Vd]).nullish()});const Hd=H({readTextFile:q(z().optional().default(!1),()=>!1),writeTextFile:q(z().optional().default(!1),()=>!1),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Ud=G(F(),B()),Wd=H({boolean:q(H({_meta:q(G(F(),B()).nullish(),()=>void 0)}).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Gd=G(F(),B()),Kd=H({compaction:q(Ud.nullish(),()=>void 0),configOptions:q(Wd.nullish(),()=>void 0),notices:q(Gd.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),qd=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Jd=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Yd=H({terminal:q(z().optional().default(!1),()=>!1),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Xd=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Zd=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Qd=H({form:q(Xd.nullish(),()=>void 0),url:q(Zd.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),$d=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),ef=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),tf=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),nf=H({jump:q($d.nullish(),()=>void 0),rename:q(ef.nullish(),()=>void 0),searchAndReplace:q(tf.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),rf=H({protocolVersion:Il,clientCapabilities:q(H({fs:q(Hd.optional().default({readTextFile:!1,writeTextFile:!1}),()=>({readTextFile:!1,writeTextFile:!1})),terminal:q(z().optional().default(!1),()=>!1),session:q(Kd.nullish(),()=>void 0),subagents:q(qd.nullish(),()=>void 0),plan:q(Jd.nullish(),()=>void 0),auth:q(Yd.optional().default({terminal:!1}),()=>({terminal:!1})),elicitation:q(Qd.nullish(),()=>void 0),nes:q(nf.nullish(),()=>void 0),positionEncodings:q(J(cu).optional(),()=>[]),_meta:q(G(F(),B()).nullish(),()=>void 0)}).optional().default({fs:{readTextFile:!1,writeTextFile:!1},terminal:!1,auth:{terminal:!1}}),()=>({fs:{readTextFile:!1,writeTextFile:!1},terminal:!1,auth:{terminal:!1}})),clientInfo:q(mu.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),af=H({methodId:uu,_meta:q(G(F(),B()).nullish(),()=>void 0)}),of=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),sf=H({providerId:_u,apiType:vu,baseUrl:F(),headers:G(F(),F()).optional(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),cf=H({providerId:_u,_meta:q(G(F(),B()).nullish(),()=>void 0)}),lf=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),uf=H({name:F(),value:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),df=H({name:F(),url:F(),headers:V(uf),_meta:q(G(F(),B()).nullish(),()=>void 0)}),ff=H({name:F(),url:F(),headers:V(uf),_meta:q(G(F(),B()).nullish(),()=>void 0)}),pf=H({name:F(),serverId:Ml,_meta:q(G(F(),B()).nullish(),()=>void 0)}),mf=H({name:F(),command:F(),args:V(F()),env:V(sl),_meta:q(G(F(),B()).nullish(),()=>void 0)}),hf=U([df.and(H({type:K(`http`)})),ff.and(H({type:K(`sse`)})),pf.and(H({type:K(`acp`)})),mf]),gf=H({cwd:F(),additionalDirectories:V(F()).optional(),mcpServers:V(hf),_meta:q(G(F(),B()).nullish(),()=>void 0)}),_f=H({mcpServers:V(hf),cwd:F(),additionalDirectories:V(F()).optional(),sessionId:Y,_meta:q(G(F(),B()).nullish(),()=>void 0)}),vf=H({cwd:F().nullish(),cursor:F().nullish(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),yf=H({sessionId:Y,_meta:q(G(F(),B()).nullish(),()=>void 0)}),bf=H({sessionId:Y,cwd:F(),additionalDirectories:V(F()).optional(),mcpServers:V(hf).optional(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),xf=H({sessionId:Y,cwd:F(),additionalDirectories:V(F()).optional(),mcpServers:V(hf).optional(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Sf=H({sessionId:Y,_meta:q(G(F(),B()).nullish(),()=>void 0)}),Cf=H({sessionId:Y,modeId:wu,_meta:q(G(F(),B()).nullish(),()=>void 0)}),wf=W(U([H({value:z(),type:K(`boolean`)}),H({value:Ou})]),H({sessionId:Y,configId:Eu,_meta:q(G(F(),B()).nullish(),()=>void 0)})),Tf=H({sessionId:Y,prompt:V(Xc),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Ef=H({uri:F(),name:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Df=H({name:F(),owner:F(),remoteUrl:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Of=H({workspaceUri:q(F().nullish(),()=>void 0),workspaceFolders:V(Ef).nullish(),repository:q(Df.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),kf=U([K(`automatic`),K(`diagnostic`),K(`manual`)]),Af=H({uri:F(),languageId:F(),text:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),jf=H({startLine:R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}),endLine:R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}),text:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Mf=H({uri:F(),excerpts:V(jf),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Nf=H({uri:F(),diff:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Pf=H({action:F(),uri:F(),position:Ju,timestampMs:L(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Ff=H({uri:F(),languageId:F(),visibleRange:q(Yu.nullish(),()=>void 0),lastFocusedMs:q(L().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),If=U([K(`error`),K(`warning`),K(`information`),K(`hint`)]),Lf=H({uri:F(),range:Yu,severity:If,message:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Rf=H({recentFiles:V(Af).nullish(),relatedSnippets:V(Mf).nullish(),editHistory:V(Nf).nullish(),userActions:V(Pf).nullish(),openFiles:V(Ff).nullish(),diagnostics:V(Lf).nullish(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),zf=H({sessionId:Y,uri:F(),version:L(),position:Ju,selection:Yu.nullish(),triggerKind:kf,context:Rf.nullish(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Bf=H({sessionId:Y,_meta:q(G(F(),B()).nullish(),()=>void 0)});H({id:Lc,method:F(),params:U([rf,af,of,sf,cf,lf,gf,_f,vf,yf,bf,xf,Sf,Cf,wf,Tf,Of,zf,Bf,Fl]).nullish()});const Vf=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Hf=H({content:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Uf=H({optionId:il,_meta:q(G(F(),B()).nullish(),()=>void 0)}),Wf=H({outcome:U([H({outcome:K(`cancelled`)}),Uf.and(H({outcome:K(`selected`)}))]),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Gf=H({terminalId:$c,_meta:q(G(F(),B()).nullish(),()=>void 0)}),Kf=H({exitCode:q(R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}).nullish(),()=>void 0),signal:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),qf=H({output:F(),truncated:z(),exitStatus:q(Kf.nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Jf=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Yf=H({exitCode:q(R().gte(0).max(4294967295,{error:`Invalid value: Expected uint32 to be <= 4294967295`}).nullish(),()=>void 0),signal:q(F().nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),Xf=H({_meta:q(G(F(),B()).nullish(),()=>void 0)}),Zf=U([F(),L(),L(),z(),V(F())]),Qf=H({content:G(F(),Zf).nullish()}),$f=Fc(W(U([Qf.and(H({action:K(`accept`)})),H({action:K(`decline`)}),H({action:K(`cancel`)}),Pc(H({action:F()}),`action`,[`accept`,`cancel`,`decline`])]),H({_meta:q(G(F(),B()).nullish(),()=>void 0)})),`action`,[`accept`,`cancel`,`decline`]),ep=$s({code:R().min(-2147483648,{error:`Invalid value: Expected int32 to be >= -2147483648`}).max(2147483647,{error:`Invalid value: Expected int32 to be <= 2147483647`}),message:F(),data:B().optional()});U([H({id:Lc,result:U([Vf,Hf,Wf,Gf,qf,Jf,Yf,Xf,$f,U([H({result:B(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),H({error:ep,_meta:q(G(F(),B()).nullish(),()=>void 0)})]),rd])}),H({id:Lc,error:id})]);const tp=H({sessionId:Y,_meta:q(G(F(),B()).nullish(),()=>void 0)}),np=H({sessionId:Y,uri:F(),languageId:F(),version:L(),text:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),rp=H({range:Yu.nullish(),text:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),ip=H({sessionId:Y,uri:F(),version:L(),contentChanges:V(rp),_meta:q(G(F(),B()).nullish(),()=>void 0)}),ap=H({sessionId:Y,uri:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),op=H({sessionId:Y,uri:F(),_meta:q(G(F(),B()).nullish(),()=>void 0)}),sp=H({sessionId:Y,uri:F(),version:L(),position:Ju,visibleRange:Yu,_meta:q(G(F(),B()).nullish(),()=>void 0)}),cp=H({sessionId:Y,id:qu,_meta:q(G(F(),B()).nullish(),()=>void 0)}),lp=H({sessionId:Y,id:qu,reason:q(U([K(`rejected`),K(`ignored`),K(`replaced`),K(`cancelled`)]).nullish(),()=>void 0),_meta:q(G(F(),B()).nullish(),()=>void 0)}),up=H({serverId:Ml,requestId:Nl,method:F(),params:G(F(),B()).nullish(),_meta:q(G(F(),B()).nullish(),()=>void 0)});H({method:F(),params:U([tp,np,ip,ap,op,sp,cp,lp,up,Vd]).nullish()}),H({requestId:Lc,_meta:q(G(F(),B()).nullish(),()=>void 0)});const dp=`$/cancel_request`;function fp(e){return gp(e)&&`id`in e&&typeof e.method==`string`&&_p(e.id)}function pp(e){if(!gp(e)||`method`in e||!(`id`in e)||!_p(e.id))return!1;let t=Object.hasOwn(e,`result`),n=Object.hasOwn(e,`error`);return t===n?!1:!n||xp(e.error)}function mp(e){return gp(e)&&!(`id`in e)&&typeof e.method==`string`}function hp(e){return typeof e==`object`&&!!e}function gp(e){return hp(e)&&e.jsonrpc===`2.0`}function _p(e){return e===null||typeof e==`string`||typeof e==`number`&&Number.isFinite(e)}function vp(e){return hp(e)&&!(`method`in e)&&(`id`in e||`result`in e||`error`in e)}function yp(e){let t=!1,n=!1,r=!1,i=!1;for(let a of e)t||=fp(a)||mp(a),n||=pp(a),hp(a)&&(r||=`method`in a,i||=`result`in a||`error`in a);return t?!1:n?!0:i&&!r}function bp(e){if(!(!hp(e)||!_p(e.requestId)))return e.requestId}function xp(e){return hp(e)&&typeof e.code==`number`&&Number.isInteger(e.code)&&typeof e.message==`string`}const Sp={yes(){return{handled:!0}},no(e,t=!1){return{handled:!1,message:e,retry:t}}};function Cp(e){let t=Promise.reject(e);return t.catch(()=>{}),t}function wp(e){if(e instanceof Error||typeof e==`object`&&e&&`message`in e&&typeof e.message==`string`)return e.message}function Tp(e){return typeof e==`object`&&!!e&&`name`in e&&e.name===`ZodError`&&`issues`in e&&Array.isArray(e.issues)&&`format`in e&&typeof e.format==`function`}function Ep(e){if(e instanceof X)return e.toResult();if(Tp(e))return X.invalidParams(e.format()).toResult();let t=wp(e);try{return X.internalError(t?JSON.parse(t):{}).toResult()}catch{return X.internalError({details:t}).toResult()}}function Dp(e){return e instanceof X&&e.code===-32800?e:X.requestCancelled(e)}function Op(e,t){let n=kp(e,t);return n?n.toResult():Ep(e)}function kp(e,t){if(!(!t.aborted||!Ap(e)))return Dp(t.reason)}function Ap(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.name===`AbortError`||t.code===`ABORT_ERR`}var jp=class{id;sendResult;signal;finishRequest;didRespond=!1;constructor(e,t,n=new AbortController().signal,r){this.id=e,this.sendResult=t,this.signal=n,this.finishRequest=r}get responded(){return this.didRespond}respond(e){return this.respondWithResult({result:e??null})}respondWithError(e){let t=e instanceof X?e.toErrorResponse():e;return this.respondWithResult({error:t})}respondWithResult(e){return this.didRespond?Cp(Error(`JSON-RPC request already responded`)):(this.didRespond=!0,this.sendResult(e).finally(()=>{this.finishRequest?.()}))}};const Mp=new WeakMap;var Np=class{disposeHandler;active=!0;constructor(e){this.disposeHandler=e}dispose(){this.active&&(this.active=!1,this.disposeHandler())}[Symbol.dispose](){this.dispose()}runIndefinitely(){return this}},Pp=class{connection;constructor(e){this.connection=e}sendRequest(e,t,n,r){return this.connection.sendRequest(e,t,n,r)}sendNotification(e,t){return this.connection.sendNotification(e,t)}sendBatch(e){return this.connection.sendBatch(e)}sendCancelRequest(e){return this.connection.sendCancelRequest(e)}addDynamicHandler(e){return this.connection.addDynamicHandler(e)}get signal(){return this.connection.signal}get closed(){return this.connection.closed}},Fp=class{pendingResponses=new Map;incomingRequests=new Map;nextRequestId=0;staticHandlers=[];dynamicHandlers=new Set;stream;writeQueue=Promise.resolve();abortController=new AbortController;closedPromise;retryQueue=[];context=new Pp(this);receiveReader;allowBatches=!0;constructor(e,t,n,r){if(typeof e==`function`){let i=e,a=t,o=n;this.initialize(o,[...r?.handlers??[],this.legacyHandler(i,a)],r);return}let i=e,a=t,o=n;this.initialize(i,[...o?.handlers??[],...a],o)}static builder(){return new Ip}runUntil(e){let t=!1,n=Promise.resolve().then(()=>e(this.context)).finally(()=>{t=!0}),r=this.closed.then(()=>{if(t)return new Promise(()=>{});throw this.closedReason()});return Promise.race([n,r]).finally(()=>{t=!0,this.close()})}addDynamicHandler(e){if(this.dynamicHandlers.add(e),this.retryQueue.length>0)for(let e of this.retryQueue.splice(0))this.processIncomingMessage(e).catch(e=>this.close(e));return new Np(()=>{this.dynamicHandlers.delete(e)})}get signal(){return this.abortController.signal}get closed(){return this.closedPromise}getContext(){return this.context}sendRequest(e,t,n,r={}){if(this.abortController.signal.aborted)return Cp(this.closedReason());let i=this.prepareRequest(e,t,n,r);return this.sendWireMessage(i.message).catch(()=>{}),r.cancellationSignal?.aborted&&i.cancel(),i.response}sendBatch(e){if(this.abortController.signal.aborted)return Cp(this.closedReason());if(!this.allowBatches)return Cp(TypeError(`JSON-RPC batches are not supported on this connection`));if(e.length===0)return Cp(TypeError(`JSON-RPC batch must contain at least one entry`));let t=[],n=[],r=[];for(let i of e){if(i.kind===`notification`){t.push({jsonrpc:`2.0`,method:i.method,params:i.params}),r.push(Promise.resolve(void 0));continue}let e=this.prepareRequest(i.method,i.params,i.mapResponse,i.options);t.push(e.message),r.push(e.response),n.push({signal:i.options?.cancellationSignal,cancel:e.cancel})}let i=t,a=this.sendWireMessage(i);for(let e of n)e.signal?.aborted&&e.cancel();let o=Promise.all([a,...r]).then(([,...e])=>e);return o.catch(()=>{}),o}sendCancelRequest(e){return this.sendNotification(dp,{requestId:e})}sendNotification(e,t){return this.abortController.signal.aborted?Cp(this.closedReason()):this.sendWireMessage({jsonrpc:`2.0`,method:e,params:t})}prepareRequest(e,t,n,r={}){let i=this.nextRequestId++,a=()=>{},o=new Promise((e,t)=>{let o={resolve:r=>{try{e(n?n(r):r)}catch(e){t(e)}},reject:t};a=()=>{o.cancellationSent||(o.cancellationSent=!0,o.cleanup?.(),this.sendCancelRequest(i).catch(()=>{}))},r.cancellationSignal?.addEventListener(`abort`,a,{once:!0}),o.cleanup=()=>{r.cancellationSignal?.removeEventListener(`abort`,a)},this.pendingResponses.set(i,o)});return o.catch(()=>{}),{message:{jsonrpc:`2.0`,id:i,method:e,params:t},response:o,cancel:()=>a()}}close(e){if(this.abortController.signal.aborted)return;let t=e??Error(`ACP connection closed`);this.abortController.abort(t);for(let e of this.pendingResponses.values())e.cleanup?.(),e.reject(t);this.pendingResponses.clear();for(let e of this.incomingRequests.values())e.abort(t);this.incomingRequests.clear(),this.receiveReader?.cancel(t).catch(()=>{})}initialize(e,t,n){this.stream=e,this.staticHandlers=t,this.allowBatches=n?.allowBatches??!0,this.closedPromise=new Promise(e=>{this.abortController.signal.addEventListener(`abort`,()=>e())}),this.receive()}legacyHandler(e,t){return{handleMessage:async(n,r)=>{if(n.kind===`request`){let t=await e(n.method,n.params,r);await n.responder.respond(t)}else await t(n.method,n.params,r);return Sp.yes()}}}async receive(){let e;try{let e=this.stream.readable.getReader();this.receiveReader=e;try{for(;!this.abortController.signal.aborted;){let{value:t,done:n}=await e.read();if(this.abortController.signal.aborted||n)break;this.receiveWireMessage(t)}}finally{this.receiveReader===e&&(this.receiveReader=void 0),e.releaseLock()}}catch(t){e=t}finally{this.close(e)}}receiveWireMessage(e){if(Array.isArray(e)){if(!this.allowBatches){this.close(TypeError(`JSON-RPC batches are not supported on this connection`));return}this.receiveBatch(e);return}if(!fp(e)&&!mp(e)&&!vp(e)){this.sendWireMessage(Lp(X.invalidRequest(e))).catch(()=>{});return}this.receiveMessage(e)}receiveBatch(e){if(e.length===0){this.sendWireMessage(Lp(X.invalidRequest(e))).catch(()=>{});return}let t=yp(e),n=t?0:e.reduce((e,t)=>e+(mp(t)?0:1),0),r=e.reduce((e,t)=>e+(mp(t)?1:0),0),i=!1,a=[],o=async()=>{i||n!==0||r!==0||a.length===0||(i=!0,await this.sendWireMessage(a))},s=async e=>{a.push(e),--n,await o()};for(let n of e){if(t){vp(n)&&this.receiveMessage(n);continue}if(!fp(n)&&!mp(n)){s(Lp(X.invalidRequest(n))).catch(()=>{});continue}let i=this.receiveMessage(n,fp(n)?s:void 0,e.length);mp(n)&&i.finally(()=>{--r,o().catch(e=>this.close(e))})}}receiveMessage(e,t,n){return this.abortController.signal.aborted?Promise.resolve():hp(e)?`method`in e?(`id`in e||this.handleProtocolNotification(e),this.processIncomingMessage(this.toIncomingMessage(e,t,n)).catch(e=>this.close(e))):(`id`in e?this.handleResponse(e):console.error(`Invalid message`,{message:e}),Promise.resolve()):(console.error(`Invalid message`,{message:e}),Promise.resolve())}async processIncomingMessage(e){if(this.abortController.signal.aborted)return;let t=e,n=!1;try{for(let e of[...this.staticHandlers,...this.dynamicHandlers.values()]){if(this.abortController.signal.aborted)return;let r=await e.handleMessage(t,this.context)??{handled:!0};if(r.handled)return;t=r.message??t,n||=!!r.retry}n?this.retryQueue.push(t):t.kind===`request`&&await t.responder.respondWithError(X.methodNotFound(t.method))}catch(n){if(this.abortController.signal.aborted)return;if(t.kind===`request`&&!t.responder.responded)await t.responder.respondWithResult(Op(n,t.responder.signal));else{let t=Ep(n);`error`in t&&console.error(`Error handling notification`,e.raw,t.error)}}}toIncomingMessage(e,t,n){if(`id`in e){let r=new AbortController;this.incomingRequests.set(e.id,r);let i=new jp(e.id,n=>{let r={jsonrpc:`2.0`,id:e.id,...n};return t?t(r):this.sendWireMessage(r)},r.signal,()=>{this.incomingRequests.get(e.id)===r&&this.incomingRequests.delete(e.id)});return n!==void 0&&Mp.set(i,n),{kind:`request`,method:e.method,params:e.params,raw:e,signal:r.signal,responder:i}}return{kind:`notification`,method:e.method,params:e.params,raw:e}}handleResponse(e){let t=this.pendingResponses.get(e.id);if(t)if(this.pendingResponses.delete(e.id),t.cleanup?.(),!pp(e))t.reject(X.invalidRequest(e));else if(`result`in e)t.resolve(e.result);else{let{code:n,message:r,data:i}=e.error;t.reject(new X(n,r,i))}else console.error(`Got response to unknown request`,e.id)}handleProtocolNotification(e){if(e.method!==dp)return;let t=bp(e.params);if(t===void 0)return;let n=this.incomingRequests.get(t);!n||n.signal.aborted||n.abort(X.requestCancelled({requestId:t}))}closedReason(){return this.abortController.signal.reason??Error(`ACP connection closed`)}async sendWireMessage(e){return this.abortController.signal.aborted?Cp(this.closedReason()):(this.writeQueue=this.writeQueue.then(async()=>{if(this.abortController.signal.aborted)throw this.closedReason();let t=this.stream.writable.getWriter();try{await t.write(e)}finally{t.releaseLock()}}).catch(e=>{throw this.close(e),e}),this.writeQueue)}},Ip=class{handlers=[];connectionName;name(e){return this.connectionName=e,this}withHandler(e){return this.handlers.push(e),this}onReceiveMessage(e){return this.withHandler({handleMessage:async(t,n)=>await e(t,n)??Sp.no(t),describe:()=>this.connectionName??`onReceiveMessage`})}onReceiveRequest(e,t,n){return this.withHandler({handleMessage:async(r,i)=>r.kind!==`request`||r.method!==e?Sp.no(r):await n(t(r.params),r.responder,i)??Sp.yes(),describe:()=>`${this.connectionName??`request`}:${e}`})}onReceiveNotification(e,t,n){return this.withHandler({handleMessage:async(r,i)=>r.kind!==`notification`||r.method!==e?Sp.no(r):await n(t(r.params),i)??Sp.yes(),describe:()=>`${this.connectionName??`notification`}:${e}`})}connect(e,t){return new Fp(e,this.handlers,t)}connectWith(e,t,n){return this.connect(e,n).runUntil(t)}},X=class e extends Error{code;data;constructor(e,t,n){super(t),this.code=e,this.name=`RequestError`,this.data=n}static parseError(t,n){return new e(-32700,`Parse error${n?`: ${n}`:``}`,t)}static invalidRequest(t,n){return new e(-32600,`Invalid request${n?`: ${n}`:``}`,t)}static methodNotFound(t){return new e(-32601,`"Method not found": ${t}`,{method:t})}static invalidParams(t,n){return new e(-32602,`Invalid params${n?`: ${n}`:``}`,t)}static internalError(t,n){return new e(-32603,`Internal error${n?`: ${n}`:``}`,t)}static requestCancelled(t,n){return new e(-32800,`Request cancelled${n?`: ${n}`:``}`,t)}static authRequired(t,n){return new e(-32e3,`Authentication required${n?`: ${n}`:``}`,t)}static resourceNotFound(t){return new e(-32002,`Resource not found${t?`: ${t}`:``}`,t&&{uri:t})}toResult(){return{error:{code:this.code,message:this.message,data:this.data}}}toErrorResponse(){return{code:this.code,message:this.message,data:this.data}}};function Lp(e){return{jsonrpc:`2.0`,id:null,error:e.toErrorResponse()}}Ol.and(H({mode:K(`form`)})).and(H({message:F()})),Al.and(H({mode:K(`url`)})).and(H({message:F()})),U([pl,ml]).and(H({message:F()})),vl.and(H({type:K(`string`)})),yl.and(H({type:K(`number`)})),bl.and(H({type:K(`integer`)})),xl.and(H({type:K(`boolean`)})),Tl.and(H({type:K(`array`)})),Sl.and(H({type:K(`string`)})),Ad.and(H({state:K(`running`)})),Md.and(H({usage:Wu.nullish()})).and(H({state:K(`idle`)})),Nd.and(H({state:K(`requires_action`)})),Pd.and(H({state:K(`unknown`)})),H({stopReason:K(`end_turn`)}),H({stopReason:K(`max_tokens`)}),H({stopReason:K(`max_turn_requests`)}),H({stopReason:K(`refusal`)}),H({stopReason:K(`cancelled`)}),jd.and(H({error:id.nullish()})).and(H({stopReason:K(`error`)})),H({stopReason:qs().optional()}),Qf.and(H({action:K(`accept`)})),H({action:K(`decline`)}),H({action:K(`cancel`)});function Z(e){return e??{}}_.initialize,_.authenticate,_.logout,_.providers_list,_.providers_set,_.providers_disable,_.session_new,_.session_load,_.session_list,_.session_delete,_.session_fork,_.session_resume,_.session_close,_.session_set_mode,_.session_set_config_option,_.session_prompt,_.session_cancel,_.nes_start,_.nes_suggest,_.nes_accept,_.nes_reject,_.nes_close,_.document_did_open,_.document_did_change,_.document_did_close,_.document_did_save,_.document_did_focus,v.session_request_permission,v.session_update,v.fs_write_text_file,v.fs_read_text_file,v.terminal_create,v.terminal_output,v.terminal_release,v.terminal_wait_for_exit,v.terminal_kill,v.elicitation_create,v.elicitation_complete,ue.cancel_request,Symbol.dispose;function Q(e,t,n){return{method:e,params:t,mapResponse:n}}function $(e,t){return{method:e,params:t}}function Rp(e){let t={};for(let n of Object.values(e))t[n.method]=n;return t}const zp={initialize:Q(_.initialize,rf),newSession:Q(_.session_new,gf),loadSession:Q(_.session_load,_f,Z),unstable_forkSession:Q(_.session_fork,bf),listSessions:Q(_.session_list,vf),deleteSession:Q(_.session_delete,yf,Z),resumeSession:Q(_.session_resume,xf),closeSession:Q(_.session_close,Sf,Z),setSessionMode:Q(_.session_set_mode,Cf,Z),setSessionConfigOption:Q(_.session_set_config_option,wf),authenticate:Q(_.authenticate,af,Z),unstable_listProviders:Q(_.providers_list,of),unstable_setProvider:Q(_.providers_set,sf,Z),unstable_disableProvider:Q(_.providers_disable,cf,Z),logout:Q(_.logout,lf,Z),prompt:Q(_.session_prompt,Tf),unstable_startNes:Q(_.nes_start,Of),unstable_suggestNes:Q(_.nes_suggest,zf),unstable_closeNes:Q(_.nes_close,Bf,Z)},Bp={cancel:$(_.session_cancel,tp),unstable_didOpenDocument:$(_.document_did_open,np),unstable_didChangeDocument:$(_.document_did_change,ip),unstable_didCloseDocument:$(_.document_did_close,ap),unstable_didSaveDocument:$(_.document_did_save,op),unstable_didFocusDocument:$(_.document_did_focus,sp),unstable_acceptNes:$(_.nes_accept,cp),unstable_rejectNes:$(_.nes_reject,lp)},Vp={requestPermission:Q(v.session_request_permission,ol),writeTextFile:Q(v.fs_write_text_file,Rc,Z),readTextFile:Q(v.fs_read_text_file,zc),createTerminal:Q(v.terminal_create,cl),terminalOutput:Q(v.terminal_output,ll),releaseTerminal:Q(v.terminal_release,ul,Z),waitForTerminalExit:Q(v.terminal_wait_for_exit,dl),killTerminal:Q(v.terminal_kill,fl,Z),createElicitation:Q(v.elicitation_create,jl)},Hp={sessionUpdate:$(v.session_update,zd),completeElicitation:$(v.elicitation_complete,Bd)};Rp(zp),Rp(Bp),Rp(Vp),Rp(Hp),new Set([_.initialize,_.authenticate,_.providers_list,_.providers_set,_.providers_disable,_.session_new,_.session_load,_.session_set_mode,_.session_set_config_option,_.session_prompt,_.session_list,_.session_delete,_.session_fork,_.session_resume,_.session_close,_.logout,_.nes_start,_.nes_suggest,_.nes_close]),new Set([_.session_cancel,_.nes_accept,_.nes_reject,_.document_did_open,_.document_did_change,_.document_did_close,_.document_did_save,_.document_did_focus]),new Set([v.session_request_permission,v.fs_write_text_file,v.fs_read_text_file,v.terminal_create,v.terminal_output,v.terminal_release,v.terminal_wait_for_exit,v.terminal_kill,v.elicitation_create]),new Set([v.session_update,v.elicitation_complete]),Symbol.asyncDispose;function Up(e){if(typeof e!=`object`||!e)return e;let t=e;if(t.type!==`image`)return e;let n=t.attachment;if(typeof n!=`object`||!n)return e;let r=n;if(typeof r.mediaType!=`string`||typeof r.data!=`string`)return e;let i=typeof t.name==`string`?t.name:typeof r.name==`string`?r.name:void 0;return{type:`image`,mediaType:r.mediaType,data:r.data,...i===void 0?{}:{name:i}}}const Wp=1e3,Gp=3e4,Kp=new Set([`gateway/invocation-unavailable`,`gateway/method-unavailable`,`gateway/definition-unavailable`]);function qp(e){return e instanceof re&&Kp.has(e.code)}function Jp(e){let t=e,n=t?.values?.modelSelection?.next??t?.values?.modelSelection?.lastUsed;if(!(n==null||typeof n.provider!=`string`||typeof n.model!=`string`))return{provider:n.provider,model:n.model,...typeof n.reasoningEffort==`string`?{reasoningEffort:n.reasoningEffort}:{}}}function Yp(e,t){return e===void 0||t===void 0?e===t:e.provider===t.provider&&e.model===t.model&&e.reasoningEffort===t.reasoningEffort}function Xp(e){if(typeof e!=`object`||!e)return-1;let t=e.asOfSeq;return typeof t==`number`?t:-1}function Zp(e){return e.pendingSelection??Jp(e.projections)??e.fallbackSelection}function Qp(e){return{id:e.id,get header(){let t=e.header;return{...t?.cwd===void 0?{}:{cwd:t.cwd},...t?.origin===void 0?{}:{origin:t.origin},...t?.parentSession===void 0?{}:{parentSession:t.parentSession},...t?.createdAt===void 0?{}:{createdAt:t.createdAt}}},requestHeader(){let t=Zp(e);if(t!==void 0)return{config:{provider:t.provider,model:t.model,...t.reasoningEffort===void 0?{}:{reasoningEffort:t.reasoningEffort}}}}}}function $p(e,t,n){return{id:e.id,session:e.session,model:{current:()=>Zp(e),select:async n=>{Yp(e.pendingSelection??Jp(e.projections),n)||(e.pendingSelection=(await t.unary(`session/selectModel`,{request:{sessionId:e.id,...n}}))?.selected??n,e.pendingAtSeq=Xp(e.projections))}},cancel:async n=>{await t.unary(`session/cancel`,{request:{sessionId:e.id}})},followup:t=>{n(e,t)}}}var em=class{logger;#e;#t;#n;#r=new Map;#i=new Map;#a=new Set;#o=new Set;#s=new Set;#c=new Set;#l=new Set;#u;#d=Wp;#f;#p=Wp;#m;#h={groups:[],failures:[]};#g=0;#_;#v=!1;#y;constructor(e){this.#e=e.carrier,this.#t=e.pool,this.#n=e.logger,this.logger=e.logger,this.#y=this.#E(),this.#O(),this.#A()}stopSubagents=async e=>{try{await this.#e.unary(`tboxcode/sessions.stopSubagents`,{request:{sessionId:e.id}})}catch(t){if(qp(t)){this.#n.debug(`stopSubagents unavailable on server: ${String(t)}`);return}this.#n.warn(`stopSubagents failed for ${e.id}: ${String(t)}`)}};drainSubagents=async e=>{try{await this.#e.unary(`tboxcode/sessions.drainSubagents`,{request:{sessionId:e.id}})}catch(e){if(qp(e)){this.#n.debug(`drainSubagents unavailable on server: ${String(e)}`);return}throw e}};async createAgent(e){return await this.#b(e)}async resumeAgent(e){return await this.#b(e)}async#b(e){let t=(await this.#e.unary(`session/create`,{request:{sessionId:e.sessionId,cwd:e.cwd}})).sessionId,n=this.#r.get(t);if(n!==void 0)return await this.#i.get(t)?.catch(()=>{}),n.fallbackSelection=this.#_,await e.configureScope?.(this.#C(n),n.agent),{agent:n.agent,dispose:async()=>this.#S(t)};let r={id:t,header:{version:1,id:t,createdAt:0,cwd:e.cwd,isSeeded:!1},projections:{},promptInflight:!1};r.session=Qp(r),r.agent=$p(r,this.#e,(e,t)=>this.#w(e,t));let i=r;this.#r.set(t,i);try{let n=this.#x(t).then(e=>{e!==void 0&&(i.projections=e)});this.#i.set(t,n),await n,this.#i.delete(t),this.#_===void 0&&(await this.#y,this.#_===void 0&&!this.#v&&(this.#v=!0,await this.#E())),i.fallbackSelection=this.#_,await e.configureScope?.(this.#C(i),i.agent),this.#t.open(t,this.#D(i))}catch(e){throw await this.#S(t).catch(()=>{}),e}return{agent:i.agent,dispose:async()=>this.#S(t)}}async#x(e){try{let t=await this.#e.unary(`session/projections`,{request:{sessionId:e}});if(typeof t!=`object`||!t||Array.isArray(t))return;let n=t,r=n.values;return typeof r!=`object`||!r||Array.isArray(r)?void 0:{asOfSeq:typeof n.asOfSeq==`number`?n.asOfSeq:-1,values:r}}catch(t){this.#n.debug(`projection prime failed (${e}): ${String(t)}`);return}}#S(e){return this.#t.close(e),this.#r.delete(e),this.#i.delete(e),Promise.resolve()}#C(e){return{on:(e,t)=>()=>{},tools:{restrict:e=>void 0}}}async#w(e,t){e.promptInflight=!0;let n=t.content.map(Up);await this.#e.unary(`session/prompt`,{request:{requestId:t.id,sessionId:e.id,mode:`steer`,content:n}})}persistence={stat:async(e,t)=>{let n=await this.#e.unary(`tboxcode/sessions.stat`,{request:{sessionId:e}});if(n!==null)return{header:n.header}},list:async e=>(await this.#e.unary(`session/list`,{_request:{}})).items.map(e=>({header:{id:e.sessionId,...e.cwd===void 0?{}:{cwd:e.cwd},...e.origin===void 0?{}:{origin:e.origin},...e.parentSessionId===void 0?{}:{parentSession:e.parentSessionId},createdAt:e.updatedAt}})),openHistoryRead:async(e,t)=>{let n=await this.#t.readAll(e);return{read:async()=>({events:n.events}),close:async()=>{}}}};sessionStore={get:e=>this.#r.get(e)?.session,flush:async e=>{await this.#e.unary(`tboxcode/sessions.flush`,{request:{sessionId:e.id}})}};llm={listProviders:()=>this.#T().groups.map(e=>({id:e.id,name:e.name})),listModels:async e=>(this.#T().groups.find(t=>t.id===e)?.models??[]).map(e=>({id:String(e.id),name:String(e.name),...e.description===void 0?{}:{description:String(e.description)}})),resolveModelInfo:async(e,t)=>{let n=this.#T().groups.find(t=>t.id===e)?.models.find(e=>e.id===t)?.reasoning;return{reasoning:{defaultEffort:n?.defaultEffort,efforts:n?.efforts??[]}}},resolveCallConfig:async e=>e};#T(){return Date.now()-this.#g>3e4&&this.#E(),this.#h}async#E(){try{this.#h=await this.#e.unary(`session/modelCatalog`,{}),this.#g=Date.now();let e=await this.#e.unary(`tboxcode/selection.default`,{});this.#_=typeof e.provider==`string`&&typeof e.model==`string`?{provider:e.provider,model:e.model,...e.reasoningEffort===void 0?{}:{reasoningEffort:e.reasoningEffort}}:void 0}catch(e){this.#n.warn(`catalog warm failed: ${String(e)}`)}}async admitPromptContent(e){return e.map(e=>e.type===`text`?e:{type:`image`,attachment:{mediaType:e.mediaType,data:e.data,...e.name===void 0?{}:{name:e.name}}})}async admitImageUrls(e,t,n){try{return(await this.#e.unary(`tboxcode/images.admit`,{request:{sessionId:e,urls:t,...n?.names===void 0?{}:{names:n.names}}})).images.map(e=>({attachment:{mediaType:e.attachment.mediaType,data:e.attachment.data},attachmentId:e.attachmentId,...e.name===void 0?{}:{name:e.name}}))}catch(e){throw X.invalidParams(void 0,e instanceof Error?e.message:String(e))}}async readImage(e,t){try{return(await this.#e.unary(`tboxcode/images.read`,{request:{attachment:t}})).image??void 0}catch{return}}applyModeKnobs(t,n,r){let i=Object.entries(e).find(([,e])=>e.sandbox===r.sandbox&&e.approval===r.approval)?.[0];if(i===void 0)throw Error(`tboxcode: mode knobs 无对位(${String(r.sandbox)}/${String(r.approval)}——MODE_TABLE 外组合)`);return this.#e.unary(`tboxcode/mode`,{request:{agentId:t.id,mode:i}}).then(()=>void 0)}defaultSelection(){return this.#_}async executeCommand(e,t,n){let r=await this.#e.unary(`tboxcode/commands.execute`,{request:{agentId:e.id,line:t}});return r?.commandId===void 0?void 0:{commandId:r.commandId}}async listCommands(e){return await this.#e.unary(`tboxcode/commands.list`,{request:{agentId:e.id}})}async listUserInvocableSkills(e){return await this.#e.unary(`tboxcode/skills.userInvocable`,{request:{agentId:e.id}})}onSessionEvent(e){let t=e;return this.#a.add(t),()=>this.#a.delete(t)}onAssistantStream(e){return this.#o.add(e),()=>this.#o.delete(e)}onInboxClaimed(e){return this.#s.add(e),()=>this.#s.delete(e)}onAgentError(e){return this.#c.add(e),()=>this.#c.delete(e)}sessionToolDenies(){return[]}onCommandSurfaceChanged(e){return this.#l.add(e),()=>this.#l.delete(e)}sessionIds(){return[...this.#r.keys()]}hasInflightPrompt(e){return this.#r.get(e)?.promptInflight===!0}poolLive(){return this.#t.stats().live>0}poolEntries(){return this.#r.size}settlePrompt(e,t){let n=this.#r.get(e);if(!(n===void 0||!n.promptInflight)){n.promptInflight=!1;for(let e of this.#c)e({agent:n.agent,turn:0,error:t})}}#D(e){return{onSnapshot:(t,n,r)=>{e.header=t;let i=Xp(r);e.pendingSelection!==void 0&&i>(e.pendingAtSeq??-1)&&Jp(r)!==void 0&&(e.pendingSelection=void 0,e.pendingAtSeq=void 0),e.projections=r},onEvent:t=>{t.type===`turn/end`&&(e.promptInflight=!1);for(let n of this.#a)n(e.session,t)},onAssistantStream:t=>{let n={type:t.type??(t.finish===void 0?t.index===0?`start`:`chunk`:`end`),attemptId:t.attemptId,...t.turn===void 0?{}:{turn:t.turn},...t.step===void 0?{}:{step:t.step},...t.chunk===void 0?{}:{chunk:t.chunk}};for(let t of this.#o)t({agent:e.agent,frame:n})},onDown:t=>this.#n.warn(`follow pool down (${e.id}): ${t}`)}}#O(){this.#u=this.#e.openStream(`tboxcode/agent.watch`,{},{onItem:e=>{this.#n.debug(`agent.watch item: ${JSON.stringify(e).slice(0,160)} states=${[...this.#r.keys()].join(`,`)}`);let t=this.#r.get(e.sessionId);if(t!==void 0){if(e.kind===`inboxClaimed`)for(let n of this.#s)n({agent:t.agent,message:{...e.messageId===void 0?{}:{id:e.messageId}},turn:e.turn??0});else if(e.kind===`error`)for(let n of this.#c)n({agent:t.agent,turn:0,error:e.error??`unknown agent error`})}},onError:e=>{this.#n.warn(`agent.watch stream error: ${JSON.stringify(e).slice(0,200)}`),this.#k()},onClose:e=>{e&&(this.#n.warn(`agent.watch stream closed`),this.#k())}})}#k(){let e=this.#d;this.#d=Math.min(this.#d*2,Gp),setTimeout(()=>{this.#O(),this.#d=Wp},e)}#A(){let e=()=>{for(let e of this.#l)e()};this.#f=tm(this.#e,e,this.#n),this.#m=this.#e.openStream(`tboxcode/skills.watch`,{},{onItem:()=>e(),onError:()=>this.#j(),onClose:e=>{e&&this.#j()}})}#j(){let e=this.#p;this.#p=Math.min(this.#p*2,Gp),setTimeout(()=>{this.#A(),this.#p=Wp},e)}dispose(){this.#u?.cancel(),this.#f?.close(),this.#m?.cancel()}};function tm(e,t,n){return e.openEvents({onReady:()=>n.debug(`commands/change $events ready`),onEmit:e=>{e.event===`commands/change`&&t()},onWaterfall:()=>{},onCancel:()=>{},onClose:e=>{e&&n.warn(`commands/change $events closed with error`)}})}var nm=class{#e;#t;#n;#r;#i;#a;#o=!1;#s;constructor(e,t){this.#e=e,this.#t=t?.timeoutMs??12e4,this.#n=t?.tickMs??1e3,this.#r=t?.now??Date.now,this.#i=t?.logger??{warn:()=>{},info:()=>{},debug:()=>{}}}start(){this.#s=setInterval(()=>this.tick(),this.#n)}stop(){this.#s!==void 0&&clearInterval(this.#s),this.#s=void 0}tick(){if(!(this.#e.poolEntries()>0&&!this.#e.poolLive())){this.#a=void 0,this.#o=!1;return}if(this.#a===void 0){this.#a=this.#r();return}if(this.#o||this.#r()-this.#a<this.#t)return;this.#o=!0;let e=this.#r()-this.#a;for(let t of this.#e.sessionIds())this.#e.hasInflightPrompt(t)&&(this.#i.warn(`carrier timeout settle (${t}): downMs=${String(e)}`),this.#e.settle(t,Error(`tboxcode carrier-timeout (downMs=${String(e)})`)))}snapshot(){return{down:this.#a!==void 0,downSince:this.#a,settled:this.#o}}};const rm=6e4,im=36e5,am=3e4,om=-32001;var sm=class{#e=new Map;#t;constructor(e){this.#t=e}get size(){return this.#e.size}pendingOf(e){for(let t of this.#e.values())if(t.sessionId===e)return t}begin(e){let t=e.event===`user-questions/request`?`elicitation`:e.event===`approval/request`?`permission`:void 0;if(t===void 0||this.#e.has(e.eventId))return;let n=this.#t.sessionIdOfAgent(e.agentId);if(n===void 0){this.#l(e.eventId,{kind:`rejected`,error:{code:`gateway/agent-not-found`,message:`agent ${e.agentId} not managed by gateway`}});return}let r={kind:t,sessionId:n,eventId:e.eventId,frame:e,asked:new Map,state:`active`,budgetStartedAt:this.#t.now()};this.#e.set(e.eventId,r),this.#n(r),this.#s(r)}cancel(e){let t=this.#e.get(e.eventId);t===void 0||t.state===`settled`||this.#c(t,{kind:`result`,value:`cancelled`},`turn`)}attach(e,t){for(let n of this.#e.values()){if(n.sessionId!==t||n.state!==`grace`)continue;let r=n.graceTimer;n.graceTimer=void 0,r!==void 0&&this.#t.timers.clear(r),n.state=`active`,this.#t.logger.info(`answerer: grace broken by attach (${n.eventId} conn=${e})`),this.#n(n)}}switchBack(e,t){this.attach(e,t)}disconnect(e){for(let t of this.#e.values())t.asked.delete(e)&&t.state===`active`&&t.asked.size===0&&this.#o(t,`member disconnected`)}dispose(){for(let e of[...this.#e.values()])e.state!==`settled`&&this.#c(e,{kind:`result`,value:`cancelled`},`dispose`);this.#e.clear()}#n(e){let t=this.#t.eligibleConns(e.sessionId).filter(t=>!e.asked.has(t)).filter(t=>e.kind===`permission`||this.#t.capsOf(t));if(t.length===0){this.#o(e,`no eligible connections`);return}for(let n of t){let t={connId:n};e.kind===`permission`&&(t.timer=this.#t.timers.set(()=>{e.state!==`active`||!e.asked.has(n)||(e.asked.delete(n),this.#t.logger.info(`answerer: member timeout (${e.eventId} conn=${n})`),e.asked.size===0&&this.#o(e,`all members timed out`))},am)),e.asked.set(n,t),this.#r(e,n)}}async#r(e,t){let n=e.kind===`elicitation`?this.#t.buildQuestionParams(e.sessionId,e.frame):{callId:e.frame.request.callId};try{let r=await this.#t.dispatch(t,e.kind,n);if(e.state===`settled`||!e.asked.has(t))return;let i=this.#i(e,r);if(i.abstain){this.#a(e,t,`abstained`);return}this.#c(e,i.outcome,t)}catch(n){if(e.state===`settled`||!e.asked.has(t))return;if(n.code===om){this.#a(e,t,`abstained`);return}this.#t.logger.warn(`answerer: dispatch failed (${e.eventId} conn=${t}): ${n instanceof Error?n.message:String(n)}`),this.#a(e,t,`dispatch failed`)}}#i(e,t){if(e.kind===`permission`){let e=t?.outcome;return e?.outcome===`cancelled`?{abstain:!1,outcome:{kind:`result`,value:`cancelled`}}:{abstain:!1,outcome:{kind:`result`,value:e?.optionId===`allow-once`?`allowed-once`:`rejected`}}}let n=t;return n?.action===`accept`?{abstain:!1,outcome:{kind:`result`,value:n.content??{}}}:{abstain:!1,outcome:{kind:`rejected`,error:{code:n?.action===`decline`?`ASK_DECLINED`:`ASK_ABORTED`,message:`ask_user_question ${n?.action===`decline`?`declined`:`cancelled`} by client`}}}}#a(e,t,n){let r=e.asked.get(t);r?.timer!==void 0&&this.#t.timers.clear(r.timer),e.asked.delete(t),this.#t.logger.debug(`answerer: member dropped (${e.eventId} conn=${t} ${n})`),e.state===`active`&&e.asked.size===0&&this.#o(e,`all members out (${n})`)}#o(e,t){e.state===`active`&&(e.state=`grace`,e.graceTimer=this.#t.timers.set(()=>{this.#c(e,e.kind===`elicitation`?{kind:`rejected`,error:{code:`ASK_ABORTED`,message:`ask_user_question grace window expired`}}:{kind:`result`,value:`cancelled`},`grace`)},rm),this.#t.logger.info(`answerer: grace entered (${e.eventId} ${t})`))}#s(e){let t=im-(this.#t.now()-e.budgetStartedAt);if(t<=0){this.#c(e,e.kind===`elicitation`?{kind:`rejected`,error:{code:`ASK_ABORTED`,message:`ask_user_question form budget exhausted`}}:{kind:`result`,value:`cancelled`},`budget`);return}this.#t.timers.set(()=>{e.state!==`settled`&&(this.#t.logger.warn(`answerer: form budget exhausted (${e.eventId})`),this.#c(e,e.kind===`elicitation`?{kind:`rejected`,error:{code:`ASK_ABORTED`,message:`ask_user_question form budget exhausted`}}:{kind:`result`,value:`cancelled`},`budget`))},t)}#c(e,t,n){if(e.state!==`settled`){e.state=`settled`,e.settledOutcome=t,e.respondedBy=n,e.graceTimer!==void 0&&(this.#t.timers.clear(e.graceTimer),e.graceTimer=void 0);for(let t of e.asked.values())t.timer!==void 0&&this.#t.timers.clear(t.timer);e.asked.clear(),this.#l(e.eventId,t),this.#t.resolvedNotify(e.kind,{sessionId:e.sessionId,eventId:e.eventId,outcome:t,respondedBy:n},typeof n==`string`&&n!==`grace`&&n!==`turn`&&n!==`dispose`&&n!==`budget`?n:void 0),this.#t.logger.info(`answerer: settled (${e.eventId} by=${n} kind=${t.kind})`)}}async#l(e,t){try{await this.#t.respond(e,t)}catch(t){this.#t.logger.warn(`answerer: respond failed (${e}): ${t instanceof Error?t.message:String(t)}`)}}};function cm(e,t){e.gate.active||(e.gate.active=!0,e.gate.timer=setTimeout(()=>{e.gate.active&&(t.warn(`gateway load gate timeout (${e.connId})——释放缓存帧`),lm(e,!0))},3e4),e.gate.timer.unref?.())}function lm(e,t){if(!e.gate.active)return[];e.gate.active=!1,e.gate.timer!==void 0&&clearTimeout(e.gate.timer),e.gate.timer=void 0;let n=t?e.gate.frames.splice(0):[];return e.gate.frames.length=0,n}function um(e,t){e.socket.readyState===e.socket.OPEN&&e.socket.send(JSON.stringify(t))}function dm(e,t,n){let{core:r,hooks:i,authenticate:a,logger:s}=n,c=new ce(s,i),l=new o({noServer:!0}),u=new Set;r.io.notify=async e=>{c.route(e)},r.io.extNotify=async e=>{c.routeExt(e)};let d=(e,n,o)=>{new URL(e.url??`/`,`http://localhost`).pathname===t&&(async()=>{if(!(a===void 0||await fm(a,e,s))){n.write(`HTTP/1.1 401 Unauthorized\r
4
58
  \r
5
- `),n.destroy();return}l.handleUpgrade(e,n,o,e=>{Y(e,r,i,c,s,u)})})().catch(e=>{s.warn(`gateway upgrade failed: ${String(e)}`),n.destroy()})};return e.on(`upgrade`,d),{close:()=>{e.off(`upgrade`,d);for(let e of u)e.socket.close();l.close()},boundConnIds:e=>c.boundConnIds(e),ctxOf:e=>c.ctxOf(e),routeResolved:(e,t,n)=>c.routeResolved(e,t,n)}}async function J(e,t,n){try{return await e(t)}catch(e){return n.warn(`gateway authenticate failed: ${String(e)}`),!1}}function Y(e,t,n,r,a,o){let s=i(),c={elicitation:!1},l={active:!1,frames:[],timer:void 0},u=t=>{if(l.active){l.frames.push(t);return}e.readyState===e.OPEN&&e.send(JSON.stringify(t))},d={connId:s,get caps(){return c},request:async(e,t)=>{throw Error(`tboxcode: server→client request 面直通由 attach 后覆写(answerer 切片消费)`)},notify:async(e,t)=>{u({jsonrpc:`2.0`,method:e,params:t})}};if(r.attachConnection(s,u,d),n?.onConnection!==void 0)try{n.onConnection(d)}catch(e){a.warn(`gateway hook onConnection failed (fail-open): ${String(e)}`)}let f=new TransformStream,p=f.writable.getWriter(),m={writable:new WritableStream({write:e=>{X(e,g,r,u)}}),readable:f.readable},h=t.attachConnection(m,{beforePrompt:e=>r.setTurnOrigin(e,s),afterPrompt:e=>r.clearTurnOrigin(e)}),g={connId:s,socket:e,conn:h,ctx:d,pending:new Map,get caps(){return c},gate:l};d.request=(e,t)=>h.client.request(e,t),o.add(g),e.on(`message`,e=>{let i=typeof e==`string`?e:Buffer.isBuffer(e)?e.toString(`utf8`):void 0;if(i===void 0)return;let o;try{o=JSON.parse(i)}catch{u({jsonrpc:`2.0`,id:null,error:{code:-32700,message:`Parse error`}});return}Z(o,g,p,t,n,r,a)}),e.on(`close`,()=>{if(o.delete(g),r.detachConnection(s),n?.onConnectionClose!==void 0)try{n.onConnectionClose(s)}catch(e){a.warn(`gateway hook onConnectionClose failed (fail-open): ${String(e)}`)}p.close().catch(()=>{}),a.debug(`gateway connection detached (${s})`)}),e.on(`error`,e=>{a.warn(`gateway socket error (${s}): ${String(e)}`)})}function X(e,t,n,r){if(e.method===void 0&&e.id!==void 0){let r=t.pending.get(String(e.id));if(r!==void 0){t.pending.delete(String(e.id));let i=r.method===`session/load`,a=e.error===void 0;if(a){let i=e.result?.sessionId??r.params?.sessionId;r.method===`session/close`?i!==void 0&&n.unbind(t.connId,i):i!==void 0&&n.bind(t.connId,i)}else if(r.prebound){let e=r.params?.sessionId;e!==void 0&&n.unbind(t.connId,e)}if(i){let n=G(t,a);if(K(t,e),a)for(let e of n)K(t,e);return}}}r(e)}async function Z(e,t,n,r,i,a,o){let s=e.method;if(s===void 0){await n.write(e);return}if(s===`initialize`){let n=e.params?.clientCapabilities;t.caps.elicitation=n?.elicitation!=null}if(s.startsWith(`_tbox.cn/`)){if(e.id===void 0){let n=i?.notifications?.[s];if(n===void 0)return;try{await n(e.params,t.ctx)}catch(e){o.warn(`gateway notification ${s} failed (fail-open): ${String(e)}`)}return}let n=i?.methods?.[s];if(n===void 0){t.socket.send(JSON.stringify({jsonrpc:`2.0`,id:e.id,error:{code:-32601,message:`Method not found: ${s}`}}));return}try{let r=await n(e.params,t.ctx);t.socket.send(JSON.stringify({jsonrpc:`2.0`,id:e.id,result:r??{}}))}catch(n){t.socket.send(JSON.stringify({jsonrpc:`2.0`,id:e.id,error:{code:-32603,message:n instanceof Error?n.message:String(n)}}))}return}if(i?.transformInbound!==void 0&&e.id!==void 0){let n;try{n=await i.transformInbound(s,e.params,t.ctx)}catch(t){o.warn(`gateway hook transformInbound failed (fail-open): ${String(t)}`),n=e.params}if(n===null){t.socket.send(JSON.stringify({jsonrpc:`2.0`,id:e.id,error:{code:-32602,message:`Invalid params: ${s} rejected by gateway`}}));return}e.params=n}if(s===`session/load`&&e.id!==void 0){let n=e.params?.sessionId,s=e.params?.cwd;if(n!==void 0&&s!==void 0&&r.hasSession(n)){a.bind(t.connId,n),W(t,o);try{let a=await r.joinSession({sessionId:n,cwd:s});K(t,{jsonrpc:`2.0`,id:e.id,result:{configOptions:a.configOptions}});for(let e of a.updates){let r=e;if(i?.transformOutbound!==void 0){let n;try{n=i.transformOutbound(e,t.ctx)}catch(t){o.warn(`gateway hook transformOutbound failed (fail-open): ${String(t)}`),n=e}if(n===null)continue;r=n}K(t,{jsonrpc:`2.0`,method:`session/update`,params:{sessionId:n,update:r}})}K(t,{jsonrpc:`2.0`,method:`_tbox.cn/acp_replay_complete`,params:{sessionId:n,notificationCount:a.updates.length}});for(let e of G(t,!0))K(t,e)}catch(r){G(t,!1),a.unbind(t.connId,n),K(t,{jsonrpc:`2.0`,id:e.id,error:{code:-32603,message:r instanceof Error?r.message:String(r)}})}return}}if((s===`session/new`||s===`session/load`||s===`session/resume`||s===`session/close`)&&e.id!==void 0){let n=!1;if(s===`session/load`){let r=e.params?.sessionId;r!==void 0&&!a.boundConnIds(r).includes(t.connId)&&(a.bind(t.connId,r),n=!0),W(t,o),a.beginReplayCount(t.connId)}if(t.pending.set(String(e.id),{method:s,params:e.params,prebound:n}),s===`session/close`){let n=e.params?.sessionId;n!==void 0&&a.unbind(t.connId,n)}}if(await n.write(e),s===`session/close`&&e.id===void 0){let n=e.params?.sessionId;n!==void 0&&a.unbind(t.connId,n)}}async function Q(e,t,n,r){try{return await n()}catch(n){return e.warn(`gateway hook ${t} failed (fail-open): ${String(n)}`),r}}const $=`@tbox.cn/tboxcode-dsh-sdk`;export{H as ABSTAIN_RPC_ERROR,y as CarrierRpcError,b as CarrierTransportError,x as DshCarrier,B as FORM_BUDGET_MS,T as FanoutRouter,w as FollowPool,z as GRACE_WINDOW_MS,U as InteractionRegistry,R as InterruptionMonitor,$ as PACKAGE_NAME,V as PERMISSION_MEMBER_TIMEOUT_MS,I as RpcSessionDeps,d as Supervisor,s as SupervisorDeploymentError,q as attachAcpGateway,C as decodeWireEvent,l as exchangeCredentialsViaConnect,p as isRecord,L as openCommandsChangeEventStream,v as parseWireEventFrame,g as parseWireFollowFrame,h as parseWireHistoryRecord,_ as parseWirePage,m as parseWireSessionEvent,Q as runHookOpen};
59
+ `),n.destroy();return}l.handleUpgrade(e,n,o,e=>{pm(e,r,i,c,s,u)})})().catch(e=>{s.warn(`gateway upgrade failed: ${String(e)}`),n.destroy()})};return e.on(`upgrade`,d),{close:()=>{e.off(`upgrade`,d);for(let e of u)e.socket.close();l.close()},boundConnIds:e=>c.boundConnIds(e),ctxOf:e=>c.ctxOf(e),routeResolved:(e,t,n)=>c.routeResolved(e,t,n)}}async function fm(e,t,n){try{return await e(t)}catch(e){return n.warn(`gateway authenticate failed: ${String(e)}`),!1}}function pm(e,t,n,r,a,o){let s=i(),c={elicitation:!1},l={active:!1,frames:[],timer:void 0},u=t=>{if(l.active){l.frames.push(t);return}e.readyState===e.OPEN&&e.send(JSON.stringify(t))},d={connId:s,get caps(){return c},request:async(e,t)=>{throw Error(`tboxcode: server→client request 面直通由 attach 后覆写(answerer 切片消费)`)},notify:async(e,t)=>{u({jsonrpc:`2.0`,method:e,params:t})}};if(r.attachConnection(s,u,d),n?.onConnection!==void 0)try{n.onConnection(d)}catch(e){a.warn(`gateway hook onConnection failed (fail-open): ${String(e)}`)}let f=new TransformStream,p=f.writable.getWriter(),m={writable:new WritableStream({write:e=>{mm(e,ee,r,u)}}),readable:f.readable},h=t.attachConnection(m,{beforePrompt:e=>r.setTurnOrigin(e,s),afterPrompt:e=>r.clearTurnOrigin(e)}),ee={connId:s,socket:e,conn:h,ctx:d,pending:new Map,get caps(){return c},gate:l};d.request=(e,t)=>h.client.request(e,t),o.add(ee),e.on(`message`,e=>{let i=typeof e==`string`?e:Buffer.isBuffer(e)?e.toString(`utf8`):void 0;if(i===void 0)return;let o;try{o=JSON.parse(i)}catch{u({jsonrpc:`2.0`,id:null,error:{code:-32700,message:`Parse error`}});return}hm(o,ee,p,t,n,r,a)}),e.on(`close`,()=>{if(o.delete(ee),r.detachConnection(s),n?.onConnectionClose!==void 0)try{n.onConnectionClose(s)}catch(e){a.warn(`gateway hook onConnectionClose failed (fail-open): ${String(e)}`)}p.close().catch(()=>{}),a.debug(`gateway connection detached (${s})`)}),e.on(`error`,e=>{a.warn(`gateway socket error (${s}): ${String(e)}`)})}function mm(e,t,n,r){if(e.method===void 0&&e.id!==void 0){let r=t.pending.get(String(e.id));if(r!==void 0){t.pending.delete(String(e.id));let i=r.method===`session/load`,a=e.error===void 0;if(a){let i=e.result?.sessionId??r.params?.sessionId;r.method===`session/close`?i!==void 0&&n.unbind(t.connId,i):i!==void 0&&n.bind(t.connId,i)}else if(r.prebound){let e=r.params?.sessionId;e!==void 0&&n.unbind(t.connId,e)}if(i){let n=lm(t,a);if(um(t,e),a)for(let e of n)um(t,e);return}}}r(e)}async function hm(e,t,n,r,i,a,o){let s=e.method;if(s===void 0){await n.write(e);return}if(s===`initialize`){let n=e.params?.clientCapabilities;t.caps.elicitation=n?.elicitation!=null}if(s.startsWith(`_tbox.cn/`)){if(e.id===void 0){let n=i?.notifications?.[s];if(n===void 0)return;try{await n(e.params,t.ctx)}catch(e){o.warn(`gateway notification ${s} failed (fail-open): ${String(e)}`)}return}let n=i?.methods?.[s];if(n===void 0){t.socket.send(JSON.stringify({jsonrpc:`2.0`,id:e.id,error:{code:-32601,message:`Method not found: ${s}`}}));return}try{let r=await n(e.params,t.ctx);t.socket.send(JSON.stringify({jsonrpc:`2.0`,id:e.id,result:r??{}}))}catch(n){t.socket.send(JSON.stringify({jsonrpc:`2.0`,id:e.id,error:{code:-32603,message:n instanceof Error?n.message:String(n)}}))}return}if(i?.transformInbound!==void 0&&e.id!==void 0){let n;try{n=await i.transformInbound(s,e.params,t.ctx)}catch(t){o.warn(`gateway hook transformInbound failed (fail-open): ${String(t)}`),n=e.params}if(n===null){t.socket.send(JSON.stringify({jsonrpc:`2.0`,id:e.id,error:{code:-32602,message:`Invalid params: ${s} rejected by gateway`}}));return}e.params=n}if(s===`session/load`&&e.id!==void 0){let n=e.params?.sessionId,s=e.params?.cwd;if(n!==void 0&&s!==void 0&&r.hasSession(n)){a.bind(t.connId,n),cm(t,o);try{let a=await r.joinSession({sessionId:n,cwd:s});um(t,{jsonrpc:`2.0`,id:e.id,result:{configOptions:a.configOptions}});for(let e of a.updates){let r=e;if(i?.transformOutbound!==void 0){let n;try{n=i.transformOutbound(e,t.ctx)}catch(t){o.warn(`gateway hook transformOutbound failed (fail-open): ${String(t)}`),n=e}if(n===null)continue;r=n}um(t,{jsonrpc:`2.0`,method:`session/update`,params:{sessionId:n,update:r}})}um(t,{jsonrpc:`2.0`,method:`_tbox.cn/acp_replay_complete`,params:{sessionId:n,notificationCount:a.updates.length}});for(let e of lm(t,!0))um(t,e)}catch(r){lm(t,!1),a.unbind(t.connId,n),um(t,{jsonrpc:`2.0`,id:e.id,error:{code:-32603,message:r instanceof Error?r.message:String(r)}})}return}}if((s===`session/new`||s===`session/load`||s===`session/resume`||s===`session/close`)&&e.id!==void 0){let n=!1;if(s===`session/load`){let r=e.params?.sessionId;r!==void 0&&!a.boundConnIds(r).includes(t.connId)&&(a.bind(t.connId,r),n=!0),cm(t,o),a.beginReplayCount(t.connId)}if(t.pending.set(String(e.id),{method:s,params:e.params,prebound:n}),s===`session/close`){let n=e.params?.sessionId;n!==void 0&&a.unbind(t.connId,n)}}if(await n.write(e),s===`session/close`&&e.id===void 0){let n=e.params?.sessionId;n!==void 0&&a.unbind(t.connId,n)}}async function gm(e,t,n,r){try{return await n()}catch(n){return e.warn(`gateway hook ${t} failed (fail-open): ${String(n)}`),r}}const _m=`@tbox.cn/tboxcode-dsh-sdk`;export{om as ABSTAIN_RPC_ERROR,re as CarrierRpcError,g as CarrierTransportError,ie as DshCarrier,im as FORM_BUDGET_MS,ce as FanoutRouter,se as FollowPool,rm as GRACE_WINDOW_MS,sm as InteractionRegistry,nm as InterruptionMonitor,_m as PACKAGE_NAME,am as PERMISSION_MEMBER_TIMEOUT_MS,em as RpcSessionDeps,d as Supervisor,s as SupervisorDeploymentError,dm as attachAcpGateway,oe as decodeWireEvent,l as exchangeCredentialsViaConnect,p as isRecord,tm as openCommandsChangeEventStream,ne as parseWireEventFrame,ee as parseWireFollowFrame,h as parseWireHistoryRecord,te as parseWirePage,m as parseWireSessionEvent,gm as runHookOpen};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/tboxcode-dsh-sdk",
3
- "version": "0.1.0-rc.15",
3
+ "version": "0.1.0-rc.17",
4
4
  "type": "module",
5
5
  "description": "AcpGateway 扩展点 + Supervisor + 直连 RPC 面(主入口薄 carrier,运行时零 dsh 包依赖;/embedded 子路径提供 in-process ACP core、bridge 投影与 model schema,并携带 dsh peer 闭包)+ 上链 ACP server 面 + wire 契约与 decodeWireEvent;agtcodingbox 唯一依赖面",
6
6
  "main": "lib/index.js",
@@ -23,23 +23,23 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@deepseek-ai/cordis": "4.1.0",
26
- "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
27
- "@deepseek-ai/dsh-agent-default-model": "0.2.2-rc.1",
28
- "@deepseek-ai/dsh-attachment": "0.2.2-rc.1",
29
- "@deepseek-ai/dsh-commands": "0.2.2-rc.1",
30
- "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
31
- "@deepseek-ai/dsh-mcp-client": "0.2.2-rc.1",
32
- "@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.1",
33
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
34
- "@deepseek-ai/dsh-session-persistence": "0.2.2-rc.1",
35
- "@deepseek-ai/dsh-skill": "0.2.2-rc.1",
36
- "@deepseek-ai/dsh-typert-registry": "0.2.2-rc.1",
37
- "@deepseek-ai/dsh-user-approval": "0.2.2-rc.1",
38
- "@deepseek-ai/dsh-user-questions": "0.2.2-rc.1",
26
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.5",
27
+ "@deepseek-ai/dsh-agent-default-model": "0.2.2-rc.5",
28
+ "@deepseek-ai/dsh-attachment": "0.2.2-rc.5",
29
+ "@deepseek-ai/dsh-commands": "0.2.2-rc.5",
30
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.5",
31
+ "@deepseek-ai/dsh-mcp-client": "0.2.2-rc.5",
32
+ "@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.5",
33
+ "@deepseek-ai/dsh-session": "0.2.2-rc.5",
34
+ "@deepseek-ai/dsh-session-persistence": "0.2.2-rc.5",
35
+ "@deepseek-ai/dsh-skill": "0.2.2-rc.5",
36
+ "@deepseek-ai/dsh-typert-registry": "0.2.2-rc.5",
37
+ "@deepseek-ai/dsh-user-approval": "0.2.2-rc.5",
38
+ "@deepseek-ai/dsh-user-questions": "0.2.2-rc.5",
39
39
  "ws": "^8.19.0",
40
- "@tbox.cn/dsh-acp-bridge-core": "0.1.0-rc.15",
41
- "@tbox.cn/tboxcode-dsh-llm": "0.1.0-rc.15",
42
- "@tbox.cn/dsh-acp-full": "0.1.0-rc.15"
40
+ "@tbox.cn/tboxcode-dsh-llm": "0.1.0-rc.17",
41
+ "@tbox.cn/dsh-acp-bridge-core": "0.1.0-rc.17",
42
+ "@tbox.cn/dsh-acp-full": "0.1.0-rc.17"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/ws": "^8.18.1",