kiki-agent 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/dist/docs/en/configuration/config-files.md +32 -19
  2. package/dist/docs/en/configuration/data-locations.md +23 -1
  3. package/dist/docs/en/configuration/env-vars.md +6 -8
  4. package/dist/docs/en/configuration/overrides.md +19 -8
  5. package/dist/docs/en/configuration/providers.md +75 -4
  6. package/dist/docs/en/customization/agents-and-subagents.md +6 -2
  7. package/dist/docs/en/customization/personas.md +36 -2
  8. package/dist/docs/en/customization/plugins.md +41 -1
  9. package/dist/docs/en/customization/prompt-fields.md +4 -0
  10. package/dist/docs/en/features/agent-workflows.md +8 -8
  11. package/dist/docs/en/features/browser-and-computer.md +40 -0
  12. package/dist/docs/en/features/daily.md +10 -10
  13. package/dist/docs/en/features/ecosystem.md +5 -5
  14. package/dist/docs/en/features/extend.md +9 -8
  15. package/dist/docs/en/features/freedom.md +8 -8
  16. package/dist/docs/en/features/index.md +44 -28
  17. package/dist/docs/en/features/long-work.md +9 -9
  18. package/dist/docs/en/features/look.md +5 -5
  19. package/dist/docs/en/features/people.md +6 -6
  20. package/dist/docs/en/features/phone.md +5 -3
  21. package/dist/docs/en/features/spaces.md +7 -7
  22. package/dist/docs/en/features/workbench.md +8 -8
  23. package/dist/docs/en/guides/interface.md +16 -4
  24. package/dist/docs/en/guides/sessions.md +6 -2
  25. package/dist/docs/en/guides/settings.md +15 -2
  26. package/dist/docs/en/reference/command.md +58 -1
  27. package/dist/docs/en/reference/tools.md +25 -5
  28. package/dist/docs/en/server/acp.md +3 -1
  29. package/dist/docs/en/server/mcp.md +5 -1
  30. package/dist/docs/en/server/rest-api.md +115 -4
  31. package/dist/docs/zh/configuration/config-files.md +32 -19
  32. package/dist/docs/zh/configuration/data-locations.md +23 -1
  33. package/dist/docs/zh/configuration/env-vars.md +6 -8
  34. package/dist/docs/zh/configuration/overrides.md +19 -8
  35. package/dist/docs/zh/configuration/providers.md +75 -4
  36. package/dist/docs/zh/customization/agents-and-subagents.md +6 -2
  37. package/dist/docs/zh/customization/personas.md +36 -2
  38. package/dist/docs/zh/customization/plugins.md +41 -1
  39. package/dist/docs/zh/customization/prompt-fields.md +4 -0
  40. package/dist/docs/zh/features/agent-workflows.md +10 -10
  41. package/dist/docs/zh/features/browser-and-computer.md +40 -0
  42. package/dist/docs/zh/features/daily.md +10 -10
  43. package/dist/docs/zh/features/ecosystem.md +5 -5
  44. package/dist/docs/zh/features/extend.md +8 -7
  45. package/dist/docs/zh/features/freedom.md +8 -8
  46. package/dist/docs/zh/features/index.md +44 -28
  47. package/dist/docs/zh/features/long-work.md +8 -8
  48. package/dist/docs/zh/features/look.md +5 -5
  49. package/dist/docs/zh/features/people.md +5 -5
  50. package/dist/docs/zh/features/phone.md +5 -3
  51. package/dist/docs/zh/features/spaces.md +7 -7
  52. package/dist/docs/zh/features/workbench.md +8 -8
  53. package/dist/docs/zh/guides/interface.md +16 -4
  54. package/dist/docs/zh/guides/sessions.md +6 -2
  55. package/dist/docs/zh/guides/settings.md +15 -2
  56. package/dist/docs/zh/reference/command.md +58 -1
  57. package/dist/docs/zh/reference/tools.md +25 -5
  58. package/dist/docs/zh/server/acp.md +3 -1
  59. package/dist/docs/zh/server/mcp.md +5 -1
  60. package/dist/docs/zh/server/rest-api.md +114 -3
  61. package/dist/hostRunner.mjs +92 -1
  62. package/dist/mailbox-worker.mjs +297 -0
  63. package/dist/main.mjs +2 -2
  64. package/dist/native/windows-process-helper.exe +0 -0
  65. package/dist/query-store-worker.mjs +446 -0
  66. package/dist/sqlite-indexer.mjs +223 -401
  67. package/dist/sqlite-query-worker.mjs +226 -249
  68. package/dist/usage-parser-worker.mjs +24 -5
  69. package/dist/web/assets/AppErrorBoundary-BN6IDdP1.js +1 -0
  70. package/dist/web/assets/{LifeMark-CL6-HWDu.js → LifeMark-UBMVaTWr.js} +1 -1
  71. package/dist/web/assets/{NavScopeBoundary-CFCnvZR0.js → NavScopeBoundary-BCryw-UG.js} +1 -1
  72. package/dist/web/assets/{arc-DYDCMlOS.js → arc-C7IAvCCJ.js} +1 -1
  73. package/dist/web/assets/{architectureDiagram-3BPJPVTR-C9Y7T0O2.js → architectureDiagram-3BPJPVTR-CbwFBxn7.js} +1 -1
  74. package/dist/web/assets/{blockDiagram-GPEHLZMM-CdUrp-tD.js → blockDiagram-GPEHLZMM-B20N4t8r.js} +1 -1
  75. package/dist/web/assets/{c4Diagram-AAUBKEIU-PrwvB9IJ.js → c4Diagram-AAUBKEIU-3BYtlcP-.js} +1 -1
  76. package/dist/web/assets/channel-BJs5vJuh.js +1 -0
  77. package/dist/web/assets/{chunk-2J33WTMH-BL56g_Es.js → chunk-2J33WTMH-CpjgczxM.js} +1 -1
  78. package/dist/web/assets/{chunk-4BX2VUAB-DvJD5M9M.js → chunk-4BX2VUAB-BScxUF5G.js} +1 -1
  79. package/dist/web/assets/{chunk-55IACEB6-C8f-nzvx.js → chunk-55IACEB6-CrcLYJXd.js} +1 -1
  80. package/dist/web/assets/{chunk-727SXJPM-DOGkWKkV.js → chunk-727SXJPM-BwlyIOjw.js} +1 -1
  81. package/dist/web/assets/{chunk-AQP2D5EJ-fFOuz7g6.js → chunk-AQP2D5EJ-DKKIRkRv.js} +1 -1
  82. package/dist/web/assets/{chunk-FMBD7UC4-BpeXZ9LM.js → chunk-FMBD7UC4-CVDMj2kX.js} +1 -1
  83. package/dist/web/assets/{chunk-ND2GUHAM-CRUh76fb.js → chunk-ND2GUHAM-CL-PM6r8.js} +1 -1
  84. package/dist/web/assets/{chunk-QZHKN3VN-uNfxaPk0.js → chunk-QZHKN3VN-DPV2KbKZ.js} +1 -1
  85. package/dist/web/assets/classDiagram-4FO5ZUOK-BookeACB.js +1 -0
  86. package/dist/web/assets/classDiagram-v2-Q7XG4LA2-BookeACB.js +1 -0
  87. package/dist/web/assets/client-CXcrCawx.js +3 -0
  88. package/dist/web/assets/connection-C8nwzwXB.js +1 -0
  89. package/dist/web/assets/{cose-bilkent-S5V4N54A-BNkxG-qX.js → cose-bilkent-S5V4N54A-D1CEiQM6.js} +1 -1
  90. package/dist/web/assets/{dagre-BM42HDAG-BerioUei.js → dagre-BM42HDAG-BlFV941E.js} +1 -1
  91. package/dist/web/assets/{diagram-2AECGRRQ-Czv2SR07.js → diagram-2AECGRRQ-BC0ldkFY.js} +1 -1
  92. package/dist/web/assets/{diagram-5GNKFQAL-Uzi1weGK.js → diagram-5GNKFQAL-B22Iej6G.js} +1 -1
  93. package/dist/web/assets/{diagram-KO2AKTUF-W36h_ff3.js → diagram-KO2AKTUF-B75UNw6D.js} +1 -1
  94. package/dist/web/assets/{diagram-LMA3HP47-FG4dDk52.js → diagram-LMA3HP47-CypI7IJM.js} +1 -1
  95. package/dist/web/assets/{diagram-OG6HWLK6-CQoEjIAY.js → diagram-OG6HWLK6-OsXumvcD.js} +1 -1
  96. package/dist/web/assets/{erDiagram-TEJ5UH35-Ck06KVyZ.js → erDiagram-TEJ5UH35-3756GOvS.js} +1 -1
  97. package/dist/web/assets/{export-T_izwEkQ.js → export-Bn8PqPg4.js} +1 -1
  98. package/dist/web/assets/{flowDiagram-I6XJVG4X-C5hgxdFZ.js → flowDiagram-I6XJVG4X-DB6Y_UDg.js} +1 -1
  99. package/dist/web/assets/{ganttDiagram-6RSMTGT7-BS52Pw5_.js → ganttDiagram-6RSMTGT7-CHJeuoAY.js} +1 -1
  100. package/dist/web/assets/{gitGraphDiagram-PVQCEYII-DLlQKZHs.js → gitGraphDiagram-PVQCEYII-Dj85554Y.js} +1 -1
  101. package/dist/web/assets/{highlighted-body-OFNGDK62-Btm6MuZ4.js → highlighted-body-OFNGDK62-DMgPHetp.js} +1 -1
  102. package/dist/web/assets/{index-CZX3qUe2.js → index-0tHq8zh2.js} +1 -1
  103. package/dist/web/assets/index-7ySDqvaN.css +1 -0
  104. package/dist/web/assets/index-B0KPRi1U.js +166 -0
  105. package/dist/web/assets/{index-CRDDqofN.js → index-B599VnpP.js} +1 -1
  106. package/dist/web/assets/{index-Cd62y0wD.js → index-BFK-GypQ.js} +1 -1
  107. package/dist/web/assets/{index-BMWid2q9.js → index-BPX8gmpB.js} +1 -1
  108. package/dist/web/assets/{index-5_yzg61S.js → index-BSGYc1tb.js} +1 -1
  109. package/dist/web/assets/{index-CJ92kLtO.js → index-BTt9Q5iv.js} +1 -1
  110. package/dist/web/assets/{index-B4iu4SJW.js → index-BWzUsoY_.js} +1 -1
  111. package/dist/web/assets/{index-CgcJPsK6.js → index-BYlSV3FO.js} +1 -1
  112. package/dist/web/assets/{index-BkPV0psm.js → index-BpXQ1q-u.js} +1 -1
  113. package/dist/web/assets/{index-Dceu0bqY.js → index-BqPxpGUh.js} +1 -1
  114. package/dist/web/assets/{index-CM-nNfuV.js → index-C6qeLCPw.js} +4 -4
  115. package/dist/web/assets/{index-ByiwExpV.js → index-C7mOS2T4.js} +1 -1
  116. package/dist/web/assets/{index-CG8uIlD7.js → index-C8OFfbEs.js} +1 -1
  117. package/dist/web/assets/{index-B-6LiYTY.js → index-CI7yuMGZ.js} +1 -1
  118. package/dist/web/assets/{index-B2Pu0Iuu.js → index-CJqIcuAl.js} +1 -1
  119. package/dist/web/assets/{index-BECSk4If.js → index-CTRJmDep.js} +1 -1
  120. package/dist/web/assets/{index-Bezli3SF.js → index-CXGCKoId.js} +1 -1
  121. package/dist/web/assets/{index-hG2s2Spn.js → index-CsY571EL.js} +1 -1
  122. package/dist/web/assets/{index-BFcyN2Zw.js → index-CwQG_9rB.js} +1 -1
  123. package/dist/web/assets/{index-BLU8_Um7.js → index-D--cw39y.js} +1 -1
  124. package/dist/web/assets/{index-B9MlqF7J.js → index-D260jsUJ.js} +1 -1
  125. package/dist/web/assets/{index-D_oPSlBL.js → index-DJjmEXx4.js} +1 -1
  126. package/dist/web/assets/{index-BNch_a4L.js → index-DRMjjql1.js} +1 -1
  127. package/dist/web/assets/{index-BeMvPEXs.js → index-DUxOVxHS.js} +1 -1
  128. package/dist/web/assets/{index-Ca607_hK.js → index-DZMkZKhW.js} +1 -1
  129. package/dist/web/assets/{index-BwcG86o3.js → index-DqK8MfQN.js} +1 -1
  130. package/dist/web/assets/{index-DKIysLbI.js → index-DxUmR9aV.js} +1 -1
  131. package/dist/web/assets/{index-Cy8C_eFR.js → index-GK8aa9pT.js} +1 -1
  132. package/dist/web/assets/{index-Bg99yVX_.js → index-bYtKyBMB.js} +1 -1
  133. package/dist/web/assets/{index-eUyF-8Sq.js → index-wxHFHTgD.js} +1 -1
  134. package/dist/web/assets/{infoDiagram-5YYISTIA-CD4XJGFm.js → infoDiagram-5YYISTIA-DeDPIdEH.js} +1 -1
  135. package/dist/web/assets/{ishikawaDiagram-YF4QCWOH-fu5E3_CT.js → ishikawaDiagram-YF4QCWOH-ButuBiBW.js} +1 -1
  136. package/dist/web/assets/{journeyDiagram-JHISSGLW-CXcnKBfJ.js → journeyDiagram-JHISSGLW-Dlbmqm-j.js} +1 -1
  137. package/dist/web/assets/{kanban-definition-UN3LZRKU-BawKH6Pl.js → kanban-definition-UN3LZRKU-tlQK1cOz.js} +1 -1
  138. package/dist/web/assets/{linear-BplJuXph.js → linear-iXuNfUWp.js} +1 -1
  139. package/dist/web/assets/mermaid-GHXKKRXX-sDJax95P.js +624 -0
  140. package/dist/web/assets/{mindmap-definition-RKZ34NQL-DA1SE2uy.js → mindmap-definition-RKZ34NQL-2qPv-mwT.js} +1 -1
  141. package/dist/web/assets/{pieDiagram-4H26LBE5-6i021QeX.js → pieDiagram-4H26LBE5-CrLe1C-O.js} +1 -1
  142. package/dist/web/assets/{quadrantDiagram-W4KKPZXB-CcKSZDMT.js → quadrantDiagram-W4KKPZXB-DfeIFxc0.js} +1 -1
  143. package/dist/web/assets/{requirementDiagram-4Y6WPE33-lYVuWRuD.js → requirementDiagram-4Y6WPE33-BWtjdxie.js} +1 -1
  144. package/dist/web/assets/{sankeyDiagram-5OEKKPKP-4Zfb4_h4.js → sankeyDiagram-5OEKKPKP-B5TxJ6mb.js} +1 -1
  145. package/dist/web/assets/{sequenceDiagram-3UESZ5HK-DqltKmlY.js → sequenceDiagram-3UESZ5HK-Cf92ZCl1.js} +1 -1
  146. package/dist/web/assets/{spaces-CjuXbmxF.js → spaces-DqMTtCXX.js} +1 -1
  147. package/dist/web/assets/{stateDiagram-AJRCARHV-HFdhqxzx.js → stateDiagram-AJRCARHV-NR9I-Q4d.js} +1 -1
  148. package/dist/web/assets/stateDiagram-v2-BHNVJYJU-BiegFWxE.js +1 -0
  149. package/dist/web/assets/{theme-beWE_6f8.js → theme-6OL1RXgY.js} +1 -1
  150. package/dist/web/assets/{timeline-definition-PNZ67QCA-HNRxaB3t.js → timeline-definition-PNZ67QCA-CBAOVMfm.js} +1 -1
  151. package/dist/web/assets/{vennDiagram-CIIHVFJN-DwsCTyaD.js → vennDiagram-CIIHVFJN-C68x6TdS.js} +1 -1
  152. package/dist/web/assets/{wardley-L42UT6IY-BWW2wtVO.js → wardley-L42UT6IY-DuZZr5jm.js} +1 -1
  153. package/dist/web/assets/{wardleyDiagram-YWT4CUSO-C-ktKm7v.js → wardleyDiagram-YWT4CUSO-D6dVGtHd.js} +1 -1
  154. package/dist/web/assets/{xychartDiagram-2RQKCTM6-48AxNW9k.js → xychartDiagram-2RQKCTM6-DYLUhZX4.js} +1 -1
  155. package/dist/web/index.html +2 -2
  156. package/native/auth-native/prebuilds/linux-arm64/auth-native.node +0 -0
  157. package/native/auth-native/prebuilds/linux-x64/auth-native.node +0 -0
  158. package/native/auth-native/prebuilds/win32-arm64/auth-native.node +0 -0
  159. package/native/auth-native/prebuilds/win32-x64/auth-native.node +0 -0
  160. package/package.json +2 -2
  161. package/dist/search-worker.mjs +0 -14177
  162. package/dist/web/assets/AppErrorBoundary-DiGMUg4r.js +0 -1
  163. package/dist/web/assets/channel-Bj_gZ_Lv.js +0 -1
  164. package/dist/web/assets/classDiagram-4FO5ZUOK-ssCwe2R4.js +0 -1
  165. package/dist/web/assets/classDiagram-v2-Q7XG4LA2-ssCwe2R4.js +0 -1
  166. package/dist/web/assets/client-DGj93bGT.js +0 -3
  167. package/dist/web/assets/connection-Bpf-EjrL.js +0 -1
  168. package/dist/web/assets/index-BIebkSEI.css +0 -1
  169. package/dist/web/assets/index-D8z7lcQn.js +0 -166
  170. package/dist/web/assets/mermaid-GHXKKRXX-BO9hkP3Z.js +0 -621
  171. package/dist/web/assets/stateDiagram-v2-BHNVJYJU-Dx28QuZF.js +0 -1
@@ -1 +0,0 @@
1
- import{Y as an,Z as ln,_ as un,$ as dn,a0 as hn,a1 as fn,a2 as B,a3 as Dt,a4 as St,a5 as re,a6 as Qt,a7 as pn,a8 as Mt,a9 as mn,aa as Ct,ab as Pt,ac as xn,ad as Rt,ae as Nt,af as gn,j as n,r as c,d as dt,S as b,ag as vn,ah as ct,ai as bn,s as wn,aj as yn,ak as kn,al as jn,am as In,an as Sn,b as nt,c as rt,B as Mn,ao as Cn,ap as Pn,aq as Rn}from"./index-D8z7lcQn.js";import{u as fe}from"./index-B2Pu0Iuu.js";import{A as Ne,R as Fe,a as Oe,c as at,K as Le,i as Nn,w as En}from"./client-DGj93bGT.js";function Et(t){return{onFetch:(e,r)=>{const s=e.options,a=e.fetchOptions?.meta?.fetchMore?.direction,l=e.state.data?.pages||[],o=e.state.data?.pageParams||[];let g={pages:[],pageParams:[]},S=0;const F=async()=>{let E=!1;const L=v=>{dn(v,()=>e.signal,()=>E=!0)},U=an(e.options,e.fetchOptions),O=async(v,u,f)=>{if(E)return Promise.reject();if(u==null&&v.pages.length)return Promise.resolve(v);const C=(()=>{const w={client:e.client,queryKey:e.queryKey,pageParam:u,direction:f?"backward":"forward",meta:e.options.meta};return L(w),w})(),M=await U(C),{maxPages:P}=e.options,p=f?ln:un;return{pages:p(v.pages,M,P),pageParams:p(v.pageParams,u,P)}};if(a&&l.length){const v=a==="backward",u=v?qt:lt,f={pages:l,pageParams:o},k=u(s,f);g=await O(f,k,v)}else{const v=t??l.length;do{const u=S===0?o[0]??s.initialPageParam:lt(s,g);if(S>0&&u==null)break;g=await O(g,u),S++}while(S<v)}return g};e.options.persister?e.fetchFn=()=>e.options.persister?.(F,{client:e.client,queryKey:e.queryKey,meta:e.options.meta,signal:e.signal},r):e.fetchFn=F}}}function lt(t,{pages:e,pageParams:r}){const s=e.length-1;return e.length>0?t.getNextPageParam(e[s],e,r[s],r):void 0}function qt(t,{pages:e,pageParams:r}){return e.length>0?t.getPreviousPageParam?.(e[0],e,r[0],r):void 0}function br(t,e){return e?lt(t,e)!=null:!1}function wr(t,e){return!e||!t.getPreviousPageParam?!1:qt(t,e)!=null}var _n=class extends hn{#e;#t;#n;#s;constructor(t){super(),this.#e=t.client,this.mutationId=t.mutationId,this.#n=t.mutationCache,this.#t=[],this.state=t.state||An(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){this.#t.includes(t)||(this.#t.push(t),this.clearGcTimeout(),this.#n.notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){this.#t=this.#t.filter(e=>e!==t),this.scheduleGc(),this.#n.notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){this.#t.length||(this.state.status==="pending"?this.scheduleGc():this.#n.remove(this))}continue(){return this.#s?.continue()??this.execute(this.state.variables)}async execute(t){const e=()=>{this.#r({type:"continue"})},r={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#s=fn({fn:()=>this.options.mutationFn?this.options.mutationFn(t,r):Promise.reject(new Error("No mutationFn found")),onFail:(l,o)=>{this.#r({type:"failed",failureCount:l,error:o})},onPause:()=>{this.#r({type:"pause"})},onContinue:e,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)});const s=this.state.status==="pending",a=!this.#s.canStart();try{if(s)e();else{this.#r({type:"pending",variables:t,isPaused:a}),this.#n.config.onMutate&&await this.#n.config.onMutate(t,this,r);const o=await this.options.onMutate?.(t,r);o!==this.state.context&&this.#r({type:"pending",context:o,variables:t,isPaused:a})}const l=await this.#s.start();return await this.#n.config.onSuccess?.(l,t,this.state.context,this,r),await this.options.onSuccess?.(l,t,this.state.context,r),await this.#n.config.onSettled?.(l,null,this.state.variables,this.state.context,this,r),await this.options.onSettled?.(l,null,t,this.state.context,r),this.#r({type:"success",data:l}),l}catch(l){try{await this.#n.config.onError?.(l,t,this.state.context,this,r)}catch(o){Promise.reject(o)}try{await this.options.onError?.(l,t,this.state.context,r)}catch(o){Promise.reject(o)}try{await this.#n.config.onSettled?.(void 0,l,this.state.variables,this.state.context,this,r)}catch(o){Promise.reject(o)}try{await this.options.onSettled?.(void 0,l,t,this.state.context,r)}catch(o){Promise.reject(o)}throw this.#r({type:"error",error:l}),l}finally{this.#n.runNext(this)}}#r(t){const e=r=>{switch(t.type){case"failed":return{...r,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...r,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:t.error,failureCount:r.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=e(this.state),B.batch(()=>{this.#t.forEach(r=>{r.onMutationUpdate(t)}),this.#n.notify({mutation:this,type:"updated",action:t})})}};function An(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var Ln=class extends Dt{constructor(t={}){super(),this.config=t,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(t,e,r){const s=new _n({client:t,mutationCache:this,mutationId:++this.#n,options:t.defaultMutationOptions(e),state:r});return this.add(s),s}add(t){this.#e.add(t);const e=Ae(t);if(typeof e=="string"){const r=this.#t.get(e);r?r.push(t):this.#t.set(e,[t])}this.notify({type:"added",mutation:t})}remove(t){if(this.#e.delete(t)){const e=Ae(t);if(typeof e=="string"){const r=this.#t.get(e);if(r)if(r.length>1){const s=r.indexOf(t);s!==-1&&r.splice(s,1)}else r[0]===t&&this.#t.delete(e)}}this.notify({type:"removed",mutation:t})}canRun(t){const e=Ae(t);if(typeof e=="string"){const s=this.#t.get(e)?.find(a=>a.state.status==="pending");return!s||s===t}else return!0}runNext(t){const e=Ae(t);return typeof e=="string"?this.#t.get(e)?.find(s=>s!==t&&s.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){B.batch(()=>{this.#e.forEach(t=>{this.notify({type:"removed",mutation:t})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(t){const e={exact:!0,...t};return this.getAll().find(r=>St(e,r))}findAll(t={}){return this.getAll().filter(e=>St(t,e))}notify(t){B.batch(()=>{this.listeners.forEach(e=>{e(t)})})}resumePausedMutations(){const t=this.getAll().filter(e=>e.state.isPaused);return B.batch(()=>Promise.all(t.map(e=>e.continue().catch(re))))}};function Ae(t){return t.options.scope?.id}var Hn=class extends Dt{constructor(t={}){super(),this.config=t,this.#e=new Map}#e;build(t,e,r){const s=e.queryKey,a=e.queryHash??Qt(s,e);let l=this.get(a);return l||(l=new pn({client:t,queryKey:s,queryHash:a,options:t.defaultQueryOptions(e),state:r,defaultOptions:t.getQueryDefaults(s)}),this.add(l)),l}add(t){this.#e.has(t.queryHash)||(this.#e.set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const e=this.#e.get(t.queryHash);e&&(t.destroy(),e===t&&this.#e.delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){B.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return this.#e.get(t)}getAll(){return[...this.#e.values()]}find(t){const e={exact:!0,...t};return this.getAll().find(r=>Mt(e,r))}findAll(t={}){const e=this.getAll();return Object.keys(t).length>0?e.filter(r=>Mt(t,r)):e}notify(t){B.batch(()=>{this.listeners.forEach(e=>{e(t)})})}onFocus(){B.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){B.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},Tn=class{#e;#t;#n;#s;#r;#o;#i;#c;constructor(t={}){this.#e=t.queryCache||new Hn,this.#t=t.mutationCache||new Ln,this.#n=t.defaultOptions||{},this.#s=new Map,this.#r=new Map,this.#o=0}mount(){this.#o++,this.#o===1&&(this.#i=mn.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#c=Ct.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#o--,this.#o===0&&(this.#i?.(),this.#i=void 0,this.#c?.(),this.#c=void 0)}isFetching(t){return this.#e.findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return this.#t.findAll({...t,status:"pending"}).length}getQueryData(t){const e=this.defaultQueryOptions({queryKey:t});return this.#e.get(e.queryHash)?.state.data}ensureQueryData(t){const e=this.defaultQueryOptions(t),r=this.#e.build(this,e),s=r.state.data;return s===void 0?this.fetchQuery(t):(t.revalidateIfStale&&r.isStaleByTime(Pt(e.staleTime,r))&&this.prefetchQuery(e),Promise.resolve(s))}getQueriesData(t){return this.#e.findAll(t).map(({queryKey:e,state:r})=>{const s=r.data;return[e,s]})}setQueryData(t,e,r){const s=this.defaultQueryOptions({queryKey:t}),l=this.#e.get(s.queryHash)?.state.data,o=xn(e,l);if(o!==void 0)return this.#e.build(this,s).setData(o,{...r,manual:!0})}setQueriesData(t,e,r){return B.batch(()=>this.#e.findAll(t).map(({queryKey:s})=>[s,this.setQueryData(s,e,r)]))}getQueryState(t){const e=this.defaultQueryOptions({queryKey:t});return this.#e.get(e.queryHash)?.state}removeQueries(t){const e=this.#e;B.batch(()=>{e.findAll(t).forEach(r=>{e.remove(r)})})}resetQueries(t,e){const r=this.#e;return B.batch(()=>(r.findAll(t).forEach(s=>{s.reset()}),this.refetchQueries({type:"active",...t},e)))}cancelQueries(t,e={}){const r={revert:!0,...e},s=B.batch(()=>this.#e.findAll(t).map(a=>a.cancel(r)));return Promise.all(s).then(re).catch(re)}invalidateQueries(t,e={}){return B.batch(()=>(this.#e.findAll(t).forEach(r=>{r.invalidate()}),t?.refetchType==="none"?Promise.resolve():this.refetchQueries({...t,type:t?.refetchType??t?.type??"active"},e)))}refetchQueries(t,e={}){const r={...e,cancelRefetch:e.cancelRefetch??!0},s=B.batch(()=>this.#e.findAll(t).filter(a=>!a.isDisabled()&&!a.isStatic()).map(a=>{let l=a.fetch(void 0,r);return r.throwOnError||(l=l.catch(re)),a.state.fetchStatus==="paused"?Promise.resolve():l}));return Promise.all(s).then(re)}fetchQuery(t){const e=this.defaultQueryOptions(t);e.retry===void 0&&(e.retry=!1);const r=this.#e.build(this,e);return r.isStaleByTime(Pt(e.staleTime,r))?r.fetch(e):Promise.resolve(r.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(re).catch(re)}fetchInfiniteQuery(t){return t.behavior=Et(t.pages),this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(re).catch(re)}ensureInfiniteQueryData(t){return t.behavior=Et(t.pages),this.ensureQueryData(t)}resumePausedMutations(){return Ct.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(t){this.#n=t}setQueryDefaults(t,e){this.#s.set(Rt(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#s.values()],r={};return e.forEach(s=>{Nt(t,s.queryKey)&&Object.assign(r,s.defaultOptions)}),r}setMutationDefaults(t,e){this.#r.set(Rt(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#r.values()],r={};return e.forEach(s=>{Nt(t,s.mutationKey)&&Object.assign(r,s.defaultOptions)}),r}defaultQueryOptions(t){if(t._defaulted)return t;const e={...this.#n.queries,...this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=Qt(e.queryKey,e)),e.refetchOnReconnect===void 0&&(e.refetchOnReconnect=e.networkMode!=="always"),e.throwOnError===void 0&&(e.throwOnError=!!e.suspense),!e.networkMode&&e.persister&&(e.networkMode="offlineFirst"),e.queryFn===gn&&(e.enabled=!1),e}defaultMutationOptions(t){return t?._defaulted?t:{...this.#n.mutations,...t?.mutationKey&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}};const $t={12:"h-3 w-3",14:"h-3.5 w-3.5",16:"h-4 w-4"},Fn={read:n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M4 2.5h5.2L12 5.3v8.2H4z"}),n.jsx("path",{d:"M9 2.5v3h3"})]}),search:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7",cy:"7",r:"4.2"}),n.jsx("path",{d:"m10.2 10.2 3.3 3.3"})]}),edit:n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M10.4 2.9 13.1 5.6 6 12.7l-3.2.5.5-3.2z"}),n.jsx("path",{d:"m9.2 4.1 2.7 2.7"})]}),terminal:n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2",y:"3",width:"12",height:"10",rx:"1.8"}),n.jsx("path",{d:"m5 6.5 2 1.5-2 1.5M8.5 10H11"})]}),web:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),n.jsx("path",{d:"M2.4 8h11.2M8 2.2c1.7 1.6 2.5 3.6 2.5 5.8s-.8 4.2-2.5 5.8C6.3 12.2 5.5 10.2 5.5 8S6.3 3.8 8 2.2z"})]}),agent:n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.5",y:"2.5",width:"7.5",height:"7.5",rx:"1.6"}),n.jsx("path",{d:"M6 13.5h5.9a1.6 1.6 0 0 0 1.6-1.6V6"})]}),skill:n.jsx("path",{d:"M8 2.3 9.4 6.6l4.3 1.4-4.3 1.4L8 13.7 6.6 9.4 2.3 8l4.3-1.4z"}),plan:n.jsx("path",{d:"M5.5 4.5h8M5.5 8h8M5.5 11.5h8M2.5 4.5h.01M2.5 8h.01M2.5 11.5h.01"}),task:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),n.jsx("path",{d:"M6.8 5.6v4.8L10.4 8z"})]}),goal:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),n.jsx("circle",{cx:"8",cy:"8",r:"2.4"})]}),memory:n.jsx("path",{d:"M8 2.5c.5 3 2.5 5 5.5 5.5-3 .5-5 2.5-5.5 5.5-.5-3-2.5-5-5.5-5.5 3-.5 5-2.5 5.5-5.5z"}),think:n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M5.2 11.3a4.3 4.3 0 1 1 5.6 0v1.2H5.2z"}),n.jsx("path",{d:"M6.3 14h3.4"})]}),system:n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.5",y:"2.5",width:"11",height:"11",rx:"2"}),n.jsx("path",{d:"M5.5 6.5h5M5.5 9.5h3"})]}),clock:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),n.jsx("path",{d:"M8 4.8V8l2.2 1.4"})]}),gate:n.jsx("path",{d:"M8 2.2 13 4v3.6c0 3-2.1 5.2-5 6.2-2.9-1-5-3.2-5-6.2V4z"}),ask:n.jsx("path",{d:"M3 3.5h10c.6 0 1 .4 1 1v6c0 .6-.4 1-1 1H8.2L5 13.8v-2.3H3c-.6 0-1-.4-1-1v-6c0-.6.4-1 1-1z"}),file:n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M4 2.5h5.2L12 5.3v8.2H4z"}),n.jsx("path",{d:"M6.2 8.2h3.6M6.2 10.6h2.4"})]}),tool:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"2.2"}),n.jsx("path",{d:"M8 2.3v1.9M8 11.8v1.9M2.3 8h1.9M11.8 8h1.9M4 4l1.3 1.3M10.7 10.7 12 12M4 12l1.3-1.3M10.7 5.3 12 4"})]}),check:n.jsx("path",{d:"m3.5 8.4 2.9 2.9 6.1-6.6"}),cross:n.jsx("path",{d:"m4.3 4.3 7.4 7.4m0-7.4-7.4 7.4"}),dash:n.jsx("path",{d:"M4 8h8"}),warning:n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M8 2.6 13.8 13H2.2z"}),n.jsx("path",{d:"M8 6.6v2.8M8 11.3h.01"})]}),info:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"5.9"}),n.jsx("path",{d:"M6.5 6.4a1.6 1.6 0 1 1 2.2 1.5c-.5.2-.7.5-.7 1v.4M8 11.4h.01"})]}),hold:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),n.jsx("path",{d:"M6.6 5.8v4.4M9.4 5.8v4.4"})]}),chevron:n.jsx("path",{d:"m6 3.8 4.2 4.2L6 12.2"}),close:n.jsx("path",{d:"m4.5 4.5 7 7m0-7-7 7"}),menu:n.jsx("path",{d:"M2.8 4.5h10.4M2.8 8h10.4M2.8 11.5h10.4"}),more:n.jsx("path",{d:"M3.5 8h.01M8 8h.01M12.5 8h.01",strokeWidth:2.2}),plus:n.jsx("path",{d:"M8 3v10M3 8h10"}),arrowRight:n.jsx("path",{d:"M3 8h10m-3.8-3.8L13 8l-3.8 3.8"}),arrowDown:n.jsx("path",{d:"M8 3v10m-3.8-3.8L8 13l3.8-3.8"}),external:n.jsx("path",{d:"M6.5 3H3.5a1 1 0 0 0-1 1v8.5a1 1 0 0 0 1 1H12a1 1 0 0 0 1-1V9.5M9.5 2.5h4v4M13.5 2.5 7.5 8.5"}),folder:n.jsx("path",{d:"M13.5 11.3a1.2 1.2 0 0 1-1.2 1.2H3.7a1.2 1.2 0 0 1-1.2-1.2V3.9a1.2 1.2 0 0 1 1.2-1.2h2.7l1.3 1.9h4.6a1.2 1.2 0 0 1 1.2 1.2z"}),panel:n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2",y:"3",width:"12",height:"10",rx:"1.6"}),n.jsx("path",{d:"M10 3v10"})]}),filter:n.jsx("path",{d:"M2.5 3.5h11l-4.2 5v4l-2.6 1v-5z"}),sliders:n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.5 4.5h7M13.5 4.5h0M2.5 8h2M7.5 8h6M2.5 11.5h6M12 11.5h1.5"}),n.jsx("circle",{cx:"11",cy:"4.5",r:"1.5"}),n.jsx("circle",{cx:"6",cy:"8",r:"1.5"}),n.jsx("circle",{cx:"10.5",cy:"11.5",r:"1.5"})]}),pin:n.jsx("path",{d:"M9.6 2.2 13.8 6.4l-1.5 1.5-1-.3-2.8 2.8.4 3.1-1 1-2.4-3.4-3 2.2 4.7-5.3-.3-1 2.8-2.8-.3-1z"}),board:n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2",y:"2.5",width:"12",height:"11",rx:"1.8"}),n.jsx("path",{d:"M6 2.5v11M10 2.5v7"})]}),usage:n.jsx("path",{d:"M2.5 13.5h11M4.5 11V8M8 11V4.5M11.5 11V6.5"}),notes:n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M3.4 2.5h7.3l2 2v9a1 1 0 0 1-1 1H3.4a1 1 0 0 1-1-1v-10a1 1 0 0 1 1-1z"}),n.jsx("path",{d:"M5.2 6.4h4.4M5.2 9h3"})]}),settings:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"2.1"}),n.jsx("path",{d:"M8 1.8v1.6M8 12.6v1.6M1.8 8h1.6M12.6 8h1.6M3.6 3.6l1.1 1.1M11.3 11.3l1.1 1.1M3.6 12.4l1.1-1.1M11.3 4.7l1.1-1.1"})]}),arrowLeft:n.jsx("path",{d:"M13 8H3m3.8-3.8L3 8l3.8 3.8"}),arrowUp:n.jsx("path",{d:"M8 13V3M4.2 6.8 8 3l3.8 3.8"}),arrowUpRight:n.jsx("path",{d:"M4.5 11.5 11.5 4.5M5.5 4.5h6v6"}),expand:n.jsx("path",{d:"M9.5 2.5h4v4M6.5 13.5h-4v-4M13.5 2.5 9.3 6.7M2.5 13.5l4.2-4.2"}),collapse:n.jsx("path",{d:"M13.5 6.5h-4v-4M2.5 9.5h4v4M9.5 6.5l4-4M6.5 9.5l-4 4"}),grip:n.jsx("path",{d:"M6 4h.01M10 4h.01M6 8h.01M10 8h.01M6 12h.01M10 12h.01",strokeWidth:2.2}),stop:n.jsx("rect",{x:"4.5",y:"4.5",width:"7",height:"7",rx:"1.2",fill:"currentColor"}),quote:n.jsx("path",{d:"M3 11.5c0-3 1-5 3.5-6M9 11.5c0-3 1-5 3.5-6M3 11.5h2.6V9H3zM9 11.5h2.6V9H9z"}),star:n.jsx("path",{d:"M8 2l1.6 3.4 3.7.5-2.7 2.6.7 3.7L8 10.4l-3.3 1.8.7-3.7L2.7 5.9l3.7-.5z"}),starFilled:n.jsx("path",{d:"M8 2l1.6 3.4 3.7.5-2.7 2.6.7 3.7L8 10.4l-3.3 1.8.7-3.7L2.7 5.9l3.7-.5z",fill:"currentColor"}),dot:n.jsx("circle",{cx:"8",cy:"8",r:"3",fill:"currentColor",stroke:"none"}),ring:n.jsx("circle",{cx:"8",cy:"8",r:"4.5"}),partial:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),n.jsx("path",{d:"M8 8V2.2A5.8 5.8 0 0 1 13.8 8z",fill:"currentColor"})]}),bell:n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M4.2 7a3.8 3.8 0 0 1 7.6 0v2.4l1 1.6H3.2l1-1.6z"}),n.jsx("path",{d:"M6.6 12.4a1.5 1.5 0 0 0 2.8 0"})]}),branch:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"4.5",cy:"3.8",r:"1.3"}),n.jsx("circle",{cx:"4.5",cy:"12.2",r:"1.3"}),n.jsx("circle",{cx:"11.5",cy:"6.2",r:"1.3"}),n.jsx("path",{d:"M4.5 5.1v5.8M11.5 7.5c0 2.2-2 2.9-7 3.4"})]}),eye:n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M1.8 8S4.2 3.6 8 3.6 14.2 8 14.2 8 11.8 12.4 8 12.4 1.8 8 1.8 8z"}),n.jsx("circle",{cx:"8",cy:"8",r:"2"})]}),eyeOff:n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6.3 4c.5-.2 1.1-.4 1.7-.4 3.8 0 6.2 4.4 6.2 4.4a11 11 0 0 1-1.6 2.1M10 11.8a4.8 4.8 0 0 1-2 .6C4.2 12.4 1.8 8 1.8 8a11 11 0 0 1 2.3-2.8"}),n.jsx("path",{d:"M6.6 6.6a2 2 0 0 0 2.8 2.8M2.5 2.5l11 11"})]}),copy:n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"5.5",y:"5.5",width:"8",height:"8",rx:"1.6"}),n.jsx("path",{d:"M10.5 5.5V4.1a1.6 1.6 0 0 0-1.6-1.6H4.1a1.6 1.6 0 0 0-1.6 1.6v4.8a1.6 1.6 0 0 0 1.6 1.6h1.4"})]}),refresh:n.jsx("path",{d:"M13 5V2.5m0 2.5h-2.5M13 5a5.2 5.2 0 1 0 .1 5.8"}),thread:n.jsx("path",{d:"M4 2.8v5.4c0 1.4 1.1 2.5 2.5 2.5H12m-2.6-2.6 2.6 2.6-2.6 2.6"}),room:n.jsx("path",{d:"M6.3 2.6 5.2 13.4M10.9 2.6 9.8 13.4M3 5.6h10.4M2.6 10.4H13"}),persona:n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.5",y:"2.5",width:"11",height:"11",rx:"3"}),n.jsx("circle",{cx:"8",cy:"6.8",r:"1.8"}),n.jsx("path",{d:"M4.9 11.6c.6-1.4 1.7-2.1 3.1-2.1s2.5.7 3.1 2.1"})]}),compass:n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),n.jsx("polygon",{points:"10.8,5.2 6.8,7.2 5.2,10.8 9.2,8.8"})]})};function ut({name:t,size:e=14,className:r=""}){const s=/(^|\s)h-/.test(r)?"":$t[e];return n.jsx("svg",{"aria-hidden":!0,"data-icon":t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.35,strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 ${s} ${r}`.trim(),children:Fn[t]})}function On({open:t,size:e=12,className:r="text-ink-faint"}){return n.jsx(ut,{name:"chevron",size:e,className:`transition-transform duration-[var(--kiki-motion-quick)] ease-out motion-reduce:transition-none ${t?"rotate-90":""} ${r}`})}function Dn({label:t,size:e=14}){return n.jsxs("svg",{role:"img","aria-label":t,viewBox:"0 0 16 16",fill:"none",className:`spinner shrink-0 text-ink-soft ${$t[e]}`,children:[n.jsx("circle",{cx:"8",cy:"8",r:"5.8",stroke:"currentColor",strokeOpacity:"0.22",strokeWidth:1.35}),n.jsx("path",{d:"M13.8 8A5.8 5.8 0 0 0 8 2.2",stroke:"currentColor",strokeWidth:1.35,strokeLinecap:"round"})]})}function yr({state:t,labels:e,title:r}){switch(t){case"running":return n.jsx(Dn,{label:e.running});case"failed":return n.jsx("span",{role:"img","aria-label":e.failed,title:r,"data-outcome":"failed",className:"text-danger",children:n.jsx(ut,{name:"cross"})});case"stopped":return n.jsx("span",{role:"img","aria-label":e.stopped,title:r,"data-outcome":"stopped",className:"text-amber-rule",children:n.jsx(ut,{name:"dash"})});case"done":return n.jsx("span",{className:"sr-only",children:e.done})}}const Qn=10*6e4;function kr(t,e=Date.now()){if(t.pending_interaction==="approval"||t.pending_interaction==="question")return"waiting";if(t.busy)return"working";if(t.last_turn_reason==="failed"||t.last_turn_reason==="cancelled")return"failed";if(t.last_turn_reason==="completed"&&t.updated_at!==void 0){const r=Date.parse(t.updated_at);if(Number.isFinite(r)&&e-r<Qn)return"done"}return"idle"}function jr(t,e=8){return{"--kiki-i":Math.min(t,e)}}function qn(){if(typeof document>"u")return"system";const t=document.documentElement.dataset.kikiMotion;return t==="reduce"||t==="full"?t:"system"}function Ir(){const t=qn();return t!=="system"?t==="reduce":typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}const _t=new Map;function $n(t,e){const r=c.useRef(null);if(r.current===null||r.current.life!==e){const s=_t.get(t);r.current={life:e,changed:e!==void 0&&s!==void 0&&s!==e}}return c.useEffect(()=>{e!==void 0&&_t.set(t,e)},[t,e]),r.current.changed}function Ee({size:t="md",life:e,echo:r}){const s=$n("wordmark",e),a=e==="idle"?void 0:e,l=t==="xl"?"text-[44px] sm:text-[56px]":t==="lg"?"text-4xl":"text-[22px]",o=t==="xl"?"h-2.5 w-2.5 sm:h-3 sm:w-3":t==="lg"?"h-2 w-2":"h-1.5 w-1.5";return n.jsxs("span",{className:"inline-flex items-baseline select-none","aria-label":"kiki",children:[n.jsx("span",{className:`font-display ${l} leading-none font-semibold tracking-tight text-ink`,style:{fontVariationSettings:t==="xl"?'"opsz" 60':'"opsz" 40'},children:"kiki"}),n.jsx("span",{className:`kiki-wordmark-echo inline-block ${t==="xl"?"ml-1":"ml-[3px]"}`,"data-echo":r===void 0?void 0:r===0?"arrive":r%2===0?"a":"b",children:n.jsx("span",{"data-life":a,"data-life-changed":s?"":void 0,className:`kiki-wordmark-dot block ${o} translate-y-[-1px] rounded-full bg-accent`})})]})}function Sr({className:t=""}){return n.jsx("span",{"aria-hidden":!0,className:`inline-block h-2.5 w-2.5 rounded-[3px] bg-accent ${t}`})}function At({onConnect:t,selectedProfile:e}){const{t:r}=fe(),s=dt(),[a,l]=c.useState([]),[o,g]=c.useState(""),[S,F]=c.useState(""),[E,L]=c.useState(""),[U,O]=c.useState("58627"),[v,u]=c.useState(""),[f,k]=c.useState("stable"),[C,M]=c.useState(null),[P,p]=c.useState(null),[w,D]=c.useState(null),[A,Q]=c.useState(null),[H,ke]=c.useState(!1);c.useEffect(()=>{if(!s.connection.listSshProfiles)return;let h=!0;return s.connection.listSshProfiles().then(_=>{h&&l(_)},_=>{h&&(ke(!0),Q(String(_)))}),()=>{h=!1}},[s]);const Y=()=>{D("list"),Q(null),s.connection.listSshProfiles().then(h=>{l(h),ke(!1)},h=>Q(String(h))).finally(()=>D(null))};if(!s.connection.listSshProfiles||!s.connection.saveSshProfile||!s.connection.removeSshProfile)return null;const Qe=h=>{h.preventDefault();const _=Number(U);if(!Number.isInteger(_)||_<1||_>65535||!/^[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$/.test(v.trim())){Q(r("connect.sshNeedSetup"));return}const X=a.find(oe=>oe.id===C),pe={id:X?.id??crypto.randomUUID(),label:o.trim(),target:X?.target.kind==="host"?{...X.target,hostname:S.trim()}:{kind:"alias",alias:S.trim()},identityFile:E.trim()||null,releaseChannel:f,remotePort:_,serverHomeId:v.trim().toLowerCase()};D("save"),Q(null),s.connection.saveSshProfile(pe).then(oe=>{l(oe),g(""),F(""),L(""),O("58627"),u(""),k("stable"),M(null)},oe=>Q(String(oe))).finally(()=>D(null))},se=h=>{const _=a.find(X=>X.id===h)??(e?.id===h?e:void 0);if(!_?.remotePort||!_.serverHomeId||P?.id!==h||!/^[A-Za-z0-9_-]{43}$/.test(P.value)){Q(r("connect.sshNeedSetup"));return}D(h),Q(null),t(h,P.value).then(()=>p(null),X=>Q(String(X))).finally(()=>D(null))},qe=h=>{D(h),Q(null),s.connection.removeSshProfile(h).then(_=>l(_),_=>Q(String(_))).finally(()=>D(null))};return n.jsxs("section",{className:"mt-5 border-t border-hairline pt-4","aria-label":r("connect.sshTitle"),children:[n.jsx("h2",{className:"text-[13px] font-semibold text-ink",children:r("connect.sshTitle")}),n.jsx("p",{className:"mt-1 text-[11px] leading-relaxed text-ink-soft",children:r("connect.sshHint")}),H?n.jsx("button",{type:"button",disabled:w!==null,onClick:Y,className:"mt-2 rounded-md border border-hairline-strong px-2 py-1 text-[11px] text-ink disabled:opacity-50",children:r("common.retry")}):null,(e&&!a.some(h=>h.id===e.id)?[e,...a]:a).map(h=>n.jsxs("div",{className:"mt-2 rounded-lg border border-hairline px-3 py-2",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{className:"truncate text-[12px] font-medium text-ink",children:h.label}),n.jsxs("p",{className:"truncate font-mono text-[10px] text-ink-soft",children:[h.target.kind==="alias"?h.target.alias:h.target.hostname,h.remotePort?` · 127.0.0.1:${h.remotePort}`:""," · ",r(h.releaseChannel==="beta"?"st.about.beta":"st.about.stable")]})]}),n.jsx("button",{type:"button",disabled:w!==null,onClick:()=>{M(h.id),g(h.label),F(h.target.kind==="alias"?h.target.alias:h.target.hostname),L(h.identityFile??""),O(String(h.remotePort??58627)),u(h.serverHomeId??""),k(h.releaseChannel),Q(null)},className:"rounded-md border border-hairline px-2 py-1 text-[11px] text-ink-soft disabled:opacity-50",children:r("goal.edit")}),n.jsx("button",{type:"button",disabled:w!==null,onClick:()=>qe(h.id),className:"rounded-md border border-hairline px-2 py-1 text-[11px] text-ink-soft disabled:opacity-50",children:r("connect.sshRemove")})]}),n.jsxs("label",{className:"mt-2 block text-[11px] text-ink-soft",children:[r("connect.sshToken"),n.jsx("input",{type:"password",value:P?.id===h.id?P.value:"",onChange:_=>p({id:h.id,value:_.target.value}),autoComplete:"off",spellCheck:!1,maxLength:43,className:"mt-1 w-full rounded-md border border-hairline bg-paper px-2 py-1.5 font-mono text-[12px] text-ink"})]}),n.jsx("button",{type:"button",disabled:w!==null,onClick:()=>se(h.id),className:"mt-2 rounded-md border border-hairline-strong px-2 py-1 text-[11px] text-ink disabled:opacity-50",children:r("connect.sshConnect")})]},h.id)),n.jsxs("form",{onSubmit:Qe,className:"mt-3 grid gap-2",children:[n.jsxs("label",{className:"text-[11px] text-ink-soft",children:[r("connect.sshLabel"),n.jsx("input",{value:o,onChange:h=>g(h.target.value),required:!0,maxLength:100,className:"mt-1 w-full rounded-md border border-hairline bg-paper px-2 py-1.5 text-[12px] text-ink"})]}),n.jsxs("label",{className:"text-[11px] text-ink-soft",children:[r("connect.sshAlias"),n.jsx("input",{value:S,onChange:h=>F(h.target.value),required:!0,maxLength:255,autoComplete:"off",spellCheck:!1,placeholder:"dev-linux",className:"mt-1 w-full rounded-md border border-hairline bg-paper px-2 py-1.5 font-mono text-[12px] text-ink"}),n.jsx("span",{className:"mt-1 block leading-relaxed",children:r("connect.sshAliasHint")})]}),n.jsxs("label",{className:"text-[11px] text-ink-soft",children:[r("connect.sshIdentity"),n.jsx("input",{value:E,onChange:h=>L(h.target.value),autoComplete:"off",spellCheck:!1,placeholder:"~/.ssh/id_ed25519",className:"mt-1 w-full rounded-md border border-hairline bg-paper px-2 py-1.5 font-mono text-[12px] text-ink"})]}),n.jsxs("label",{className:"text-[11px] text-ink-soft",children:[r("connect.sshPort"),n.jsx("input",{type:"number",min:1,max:65535,required:!0,value:U,onChange:h=>O(h.target.value),className:"mt-1 w-full rounded-md border border-hairline bg-paper px-2 py-1.5 font-mono text-[12px] text-ink"})]}),n.jsxs("label",{className:"text-[11px] text-ink-soft",children:[r("connect.sshHomeId"),n.jsx("input",{value:v,onChange:h=>u(h.target.value),required:!0,maxLength:36,autoComplete:"off",spellCheck:!1,placeholder:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",className:"mt-1 w-full rounded-md border border-hairline bg-paper px-2 py-1.5 font-mono text-[12px] text-ink"})]}),n.jsxs("label",{className:"text-[11px] text-ink-soft",children:[r("st.about.channel"),n.jsxs("select",{value:f,onChange:h=>k(h.target.value),className:"mt-1 w-full rounded-md border border-hairline bg-paper px-2 py-1.5 text-[12px] text-ink",children:[n.jsx("option",{value:"stable",children:r("st.about.stable")}),n.jsx("option",{value:"beta",children:r("st.about.beta")})]}),n.jsx("span",{className:"mt-1 block leading-relaxed",children:r("connect.sshChannelHint")})]}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{type:"submit",disabled:w!==null,className:"rounded-md border border-hairline-strong px-2 py-1.5 text-[12px] text-ink disabled:opacity-50",children:r("connect.sshAdd")}),C!==null?n.jsx("button",{type:"button",disabled:w!==null,onClick:()=>{M(null),g(""),F(""),L(""),O("58627"),u(""),k("stable")},className:"rounded-md border border-hairline px-2 py-1.5 text-[12px] text-ink-soft disabled:opacity-50",children:r("common.cancel")}):null]})]}),A!==null?n.jsx("p",{role:"alert",className:"mt-2 whitespace-pre-wrap text-[11px] text-danger",children:A}):null]})}function Wn({problem:t,onRetry:e}){const{t:r}=fe(),[s,a]=c.useState(!1);return n.jsxs("div",{className:"px-7 pt-6 pb-7","data-web-link-problem":t,children:[n.jsx(Ee,{size:"lg"}),n.jsx("p",{className:"mt-3 text-[14px] font-medium text-ink",children:r(t==="retargeted"?"connect.webLinkRetargeted":"connect.webLinkRefused")}),n.jsx("p",{className:"mt-1.5 max-w-[46ch] text-[13px] leading-relaxed text-ink-soft",children:r(t==="retargeted"?"connect.webLinkRetargetedBody":"connect.webLinkRefusedBody")}),e!==void 0?n.jsx("button",{type:"button","data-web-link-retry":!0,onClick:e,className:"mt-5 w-full rounded-md bg-accent px-3 py-2 text-[14px] font-medium text-on-accent transition-colors hover:bg-accent-deep focus-visible:ring-2 focus-visible:ring-selected-ink/50 focus-visible:outline-none",children:r("connect.webLinkRetry")}):null,n.jsx("button",{type:"button","data-web-link-connect":!0,"aria-expanded":s,onClick:()=>{a(l=>!l)},className:"mt-3 w-full rounded-md px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:text-ink",children:r(s?"connect.webLinkHideConnect":"connect.webLinkUseConnect")})]})}function Un({initial:t,connecting:e,error:r,onConnect:s,onBack:a,desktopBoot:l,desktopFailure:o,onRetryDesktop:g,onCancelDesktopBoot:S,onConnectSsh:F,onSwitchLocal:E,sshProfile:L,webLink:U,onRetryWebLink:O}){return E!==void 0?n.jsx(Re,{children:o!==null?n.jsxs(n.Fragment,{children:[n.jsx(Lt,{failure:o,onRetry:g,onSwitchLocal:E}),n.jsx("div",{className:"px-7 pb-7",children:n.jsx(At,{onConnect:F,selectedProfile:L})})]}):n.jsx(Vn,{onSwitchLocal:E})}):l!==null?n.jsx(Re,{children:n.jsx(Bn,{boot:l,onCancel:S})}):o!==null?n.jsxs(Re,{children:[n.jsx(Lt,{failure:o,onRetry:g}),n.jsx("div",{className:"px-7 pb-7",children:n.jsx(At,{onConnect:F})})]}):U!==void 0?n.jsx(Re,{children:n.jsx(Wn,{problem:U,onRetry:O})}):n.jsx(Re,{children:n.jsx(zn,{initial:t,connecting:e,error:r,onConnect:s,onBack:a})})}function Re({children:t}){return n.jsx("div",{className:"flex h-full items-center justify-center overflow-y-auto bg-paper px-4 py-4",children:n.jsx("div",{className:"anim-enter w-full max-w-[420px]",children:n.jsx("div",{className:"rounded-2xl border border-hairline bg-panel shadow-[0_1px_2px_rgba(28,25,23,0.04),0_12px_32px_-16px_rgba(28,25,23,0.12)]",children:t})})})}function Kn(t){const[e,r]=c.useState(()=>Date.now());return c.useEffect(()=>{r(Date.now());const s=window.setInterval(()=>{r(Date.now())},1e3);return()=>{window.clearInterval(s)}},[t]),Math.max(0,Math.floor((e-t)/1e3))}function Vn({onSwitchLocal:t}){const{t:e}=fe();return n.jsxs("div",{className:"px-7 pt-6 pb-7",children:[n.jsx(Ee,{size:"lg"}),n.jsx("p",{className:"mt-2 text-[13px] text-ink-soft",children:e("connect.sshChecking")}),n.jsx("button",{type:"button",onClick:t,className:"mt-5 w-full rounded-lg border border-hairline-strong bg-paper px-3 py-2 text-[13px] font-medium text-ink transition-colors hover:border-accent hover:text-ink",children:e("connect.switchLocal")})]})}function Bn({boot:t,onCancel:e}){const{t:r}=fe(),s=Kn(t.startedAtMs);return n.jsxs("div",{className:"px-7 pt-6 pb-7",children:[n.jsx(Ee,{size:"lg"}),n.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-soft",children:t.stage==="spawning"?r("connect.desktopBootingSpawning"):r("connect.desktopBootingWaiting")}),n.jsx("p",{className:"mt-1 font-mono text-[12px] text-ink-faint","aria-live":"polite",children:r("connect.desktopElapsed",{seconds:s})}),n.jsx("button",{type:"button",onClick:e,className:"mt-5 w-full rounded-lg border border-hairline-strong bg-paper px-3 py-2 text-[13px] font-medium text-ink transition-colors hover:border-accent hover:text-ink",children:r("connect.desktopCancel")})]})}function Lt({failure:t,onRetry:e,onSwitchLocal:r}){const{t:s}=fe(),[a,l]=c.useState(!1);c.useEffect(()=>{if(!a)return;const g=window.setTimeout(()=>{l(!1)},1500);return()=>{window.clearTimeout(g)}},[a]);const o=async()=>{try{await navigator.clipboard.writeText(t.message),l(!0)}catch{}};return n.jsxs("div",{className:"px-7 pt-6 pb-7",children:[n.jsx(Ee,{size:"lg"}),n.jsx("p",{className:"mt-2 text-[13px] font-semibold text-danger",children:s(r===void 0?"connect.desktopFailedTitle":"connect.sshFailedTitle")}),n.jsx("pre",{className:"mt-3 max-h-56 overflow-auto whitespace-pre-wrap rounded-lg border border-danger/30 bg-danger/5 px-3 py-2 font-mono text-[12px] leading-relaxed text-danger",children:t.message}),t.logPath!==null?n.jsxs("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-soft",children:[s("connect.desktopLogPathLabel")," ",n.jsx("span",{className:"font-mono",children:t.logPath})]}):null,n.jsxs("div",{className:"mt-4 flex gap-2",children:[n.jsx("button",{type:"button",onClick:r??e,className:"flex-1 rounded-lg bg-accent px-3 py-2 text-[13px] font-semibold text-on-accent transition-colors hover:bg-accent-deep",children:s(r===void 0?"connect.desktopRetry":"connect.switchLocal")}),n.jsx("button",{type:"button",onClick:()=>{o()},className:"flex-1 rounded-lg border border-hairline-strong bg-paper px-3 py-2 text-[13px] font-medium text-ink transition-colors hover:border-accent hover:text-ink",children:s(a?"connect.desktopCopied":"connect.desktopCopyDiagnostics")})]})]})}function zn({initial:t,connecting:e,error:r,onConnect:s,onBack:a}){const l=dt(),{t:o}=fe(),[g,S]=c.useState(t.url),[F,E]=c.useState(t.token),[L,U]=c.useState(!1),[O,v]=c.useState(t.url!==""||t.token!==""||r!==null);c.useEffect(()=>{r!==null&&v(!0)},[r]);const[u,f]=c.useState(!1),[k,C]=c.useState(null),M=p=>{p.preventDefault(),s({url:g.trim(),token:F.trim()})},P=async()=>{f(!0),C(null);try{const p=await l.connection.discover();if(p===null){C(o("connect.noneFound"));return}s(p.config,p.persist)}catch(p){C(l.kind==="tauri"?o("connect.desktopStartFailed",{detail:p instanceof Error?p.message:String(p)}):o("connect.detectNeedsDev"))}finally{f(!1)}};return n.jsxs("div",{className:"px-7 pt-6 pb-7",children:[n.jsx(Ee,{size:"lg"}),n.jsx("p",{className:"mt-3 font-display text-[18px] leading-snug text-ink-soft",children:o("connect.tagline")}),n.jsxs("form",{onSubmit:M,className:"mt-6",children:[n.jsx("button",{type:"button",onClick:()=>{P()},disabled:u||e,className:"w-full rounded-md bg-accent px-3 py-2 text-[14px] font-medium text-on-accent transition-colors hover:bg-accent-deep focus-visible:ring-2 focus-visible:ring-selected-ink/50 focus-visible:outline-none disabled:opacity-60",children:o(u?"connect.detecting":"connect.detect")}),k!==null?n.jsx("p",{role:"status",className:"mt-2 text-[13px] leading-relaxed text-ink-soft",children:k}):null,n.jsxs("button",{type:"button","aria-expanded":O,"aria-controls":"connect-manual",onClick:()=>{v(p=>!p)},className:"mt-5 flex items-center gap-1.5 rounded-md py-1 text-[13px] text-ink-soft transition-colors hover:text-ink focus-visible:ring-2 focus-visible:ring-selected-ink/40 focus-visible:outline-none",children:[n.jsx(On,{open:O,className:"text-current"}),o("connect.otherMachine")]}),n.jsxs("div",{id:"connect-manual",hidden:!O,className:"mt-3",children:[n.jsx("label",{htmlFor:"connect-server-url",className:"mb-1 block text-[12px] font-medium text-ink-soft",children:o("connect.serverUrl")}),n.jsx("input",{id:"connect-server-url",className:"mb-4 w-full rounded-lg border border-hairline bg-paper px-3 py-2 font-mono text-[13px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent",placeholder:o("connect.urlPlaceholder",{target:"http://127.0.0.1:58627"}),value:g,onChange:p=>{S(p.target.value)},spellCheck:!1}),n.jsxs("label",{htmlFor:"connect-token",className:"mb-1 flex items-baseline justify-between gap-2 text-[12px] font-medium text-ink-soft",children:[o("connect.accessToken"),n.jsx("span",{title:o("connect.accessTokenHelp"),className:"cursor-help text-[12px] font-normal text-ink-faint underline decoration-dotted underline-offset-2",children:o("connect.accessTokenWhere")})]}),n.jsxs("div",{className:"mb-5 flex gap-2",children:[n.jsx("input",{id:"connect-token",className:"min-w-0 flex-1 rounded-lg border border-hairline bg-paper px-3 py-2 font-mono text-[13px] text-ink outline-none transition-colors placeholder:text-ink-faint focus:border-accent","aria-describedby":"connect-token-help",value:F,onChange:p=>{E(p.target.value)},spellCheck:!1,type:L?"text":"password"}),n.jsx("button",{type:"button",className:"rounded-lg border border-hairline px-3 text-[12px] text-ink-soft transition-colors hover:border-accent hover:text-ink","aria-label":`${o(L?"st.providers.hideKey":"st.providers.showKey")} ${o("connect.token")}`,onClick:()=>{U(p=>!p)},children:o(L?"st.providers.hideKey":"st.providers.showKey")})]}),n.jsx("p",{id:"connect-token-help",className:"sr-only",children:o("connect.accessTokenHelp")}),r!==null?n.jsx("div",{role:"alert",className:"mb-4 rounded-md border-l-2 border-danger bg-danger/5 px-3 py-2 text-[13px] text-danger",children:r}):null,n.jsx("button",{type:"submit",disabled:e,className:"w-full rounded-md border border-hairline-strong bg-paper px-3 py-2 text-[13px] font-medium text-ink transition-colors hover:border-ink-faint focus-visible:ring-2 focus-visible:ring-selected-ink/40 focus-visible:outline-none disabled:opacity-60",children:o(e?"connect.connecting":"connect.connect")})]}),a!==void 0?n.jsx("button",{type:"button",onClick:a,className:"mt-2 w-full rounded-lg px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:text-ink",children:o("connect.back")}):null]})]})}function Gn(t,e){const[r,s]=t.queryKey;return r==="usage-v2"||r==="usage-v2-strip"||r==="usage-v2-strip-session"||r==="sessions"?!0:r==="session"?e===void 0||s===e:r!=="agentCapabilities"?!1:e===void 0||typeof s=="object"&&s!==null&&"session_id"in s&&s.session_id===e}function Ht(t,e){let r=!0;const s=l=>{const o={predicate:g=>Gn(g,l)};e.cancelQueries(o).then(()=>{if(r)return e.invalidateQueries(o)})},a=t.events.on("usage.settled",({sessionId:l})=>{r&&s(l)});return a.ready.then(()=>{r&&s()}).catch(()=>{}),()=>{r=!1,a.dispose()}}const Zn=[["plugin"],["plugin-usage"],["plugin-panels"],["plugin-commands"],["plugin-panel-document"],["plugin-marketplace"],["plugin-recommendations"],["plugins"],["skins"],["agentCapabilities"],["workspace-skills"],["mcp-servers"],["mcp-managed-servers"]];async function Yn(t){await Promise.all(Zn.map(e=>t.invalidateQueries({queryKey:[...e]})))}function Tt(t,e){let r=!0;const s=()=>{Yn(e).catch(()=>{})},a=t.events.on("plugins.changed",()=>{r&&s()});return a.ready.then(()=>{r&&s()}).catch(()=>{}),()=>{r=!1,a.dispose()}}const ht="kiki.connection",Xn=["server","url","token"];function Jn(t){const e=new URLSearchParams(t.search);for(const o of Xn)e.delete(o);const r=e.toString(),s=t.hash.startsWith("#")?t.hash.slice(1).split("&"):[],a=s.filter(o=>!o.startsWith("token=")&&!o.startsWith("access=")),l=a.length===s.length?t.hash:a.length===0?"":`#${a.join("&")}`;return`${t.pathname}${r===""?"":`?${r}`}${l}`}function er(t=window.location){const e=new URLSearchParams(t.search),r=e.get("server")??e.get("url"),s=e.get("token");if(r!==null||s!==null)return{url:r??"",token:s??""};const a=/(?:^|#|&)token=([^&]+)/.exec(t.hash);return a!==null?{url:"",token:decodeURIComponent(a[1]??"")}:null}function tr(t){try{const e=(t??localStorage).getItem(ht);if(e===null)return null;const r=JSON.parse(e);return typeof r.url!="string"||typeof r.token!="string"?null:{url:r.url,token:r.token}}catch{return null}}function nr(t,e){try{return(e??localStorage).setItem(ht,JSON.stringify(t)),!0}catch{return!1}}function rr(t){try{return(t??localStorage).removeItem(ht),!0}catch{return!1}}function sr(t){return t.desktop!==void 0?{config:t.desktop,persist:!1,source:"desktop"}:t.deepLink!==void 0&&t.deepLink!==null?{config:t.deepLink,persist:or(t.deepLink.url),source:"deep-link"}:t.stored!==void 0&&t.stored!==null?{config:t.stored,persist:!0,source:"stored"}:null}function or(t){if(t==="")return!0;try{const e=new URL(t);if(e.protocol!=="http:"&&e.protocol!=="https:")return!1;const r=e.hostname.toLowerCase();return r==="localhost"||r.endsWith(".localhost")||r==="[::1]"||r==="::1"?!0:/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(r)}catch{return!1}}function st(t){if(t!==null&&typeof t=="object"&&"message"in t){const e=t;if(typeof e.message=="string")return{message:e.message,stderrTail:Array.isArray(e.stderrTail)?e.stderrTail.filter(r=>typeof r=="string"):[],logPath:typeof e.logPath=="string"?e.logPath:null}}return{message:t instanceof Error?t.message:String(t),stderrTail:[],logPath:null}}async function Mr(t,e,r){r.throwIfAborted();const s=e.scopeId.slice(7);if(e.homeId!==e.scopeId||!e.scopeId.startsWith("remote:")||!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(s))throw new b("scope-invalid");if(t.openRemoteSpace===void 0)throw new b("scope-invalid");await t.openRemoteSpace(s),r.throwIfAborted()}async function ot(t,e,r){r.throwIfAborted();const s=new URL(e,"http://example.test").pathname,a=/^\/s\/([^/]+)/.exec(s)?.[1],l=/^\/(?:rooms|r)\/([^/]+)$/.exec(s)?.[1];try{if(a!==void 0){await t.getSession(decodeURIComponent(a)),r.throwIfAborted();const o=/^\/s\/[^/]+\/agent\/([^/]+)$/.exec(s)?.[1];if(o!==void 0&&decodeURIComponent(o)!=="main"){const g=await t.klient.session(decodeURIComponent(a)).agents();if(!Object.hasOwn(g,decodeURIComponent(o)))throw new b("target-missing")}}if(l!==void 0){const o=t.klient.rest;if(o===void 0)throw new b("offline");if(await o.rooms.get(decodeURIComponent(l))===void 0)throw new b("target-missing")}}catch(o){throw a!==void 0&&o instanceof Ne&&Nn(o.message)?new b("target-missing"):l!==void 0&&o instanceof Fe&&o.code===Oe.REQUEST_INVALID&&o.message===`Room '${decodeURIComponent(l)}' does not exist.`?new b("target-missing"):(o instanceof Ne||o instanceof Fe)&&o.code===Oe.UNAUTHORIZED?new b("auth-required"):o}r.throwIfAborted()}function ir(t){return{async prepare(e,r,s){r.throwIfAborted();const a=t.active(),l=a.scope.homeId!==e.homeId;if(!l&&e.scopeId===a.scope.scopeId&&s===void 0){let v;try{v=await a.client.meta()}catch(f){throw(f instanceof Ne||f instanceof Fe)&&f.code===Oe.UNAUTHORIZED?new b("auth-required"):f}r.throwIfAborted();const u=e.serverHomeId??a.scope.serverHomeId;if(u!==void 0&&u!==v.server_home_id||e.connectionRef!==void 0&&e.connectionRef!==a.scope.connectionRef)throw new b("identity-mismatch");return{scope:{...a.scope,serverHomeId:v.server_home_id},validate:(f,k)=>ot(a.client,f,k),commit:()=>{r.throwIfAborted()},dispose:()=>{}}}let o,g,S=!1,F=!1,E=a.scope.homeId,L=!1,U;t.preparing?.(!0);const O=async()=>{try{if(S&&g!==void 0&&(S=!1,await g.klient.close()),U!==void 0){const v=U;U=void 0,await t.host.connection.disconnectSshProfile?.(v.id,v.tunnelId)}F&&(F=!1,await t.host.prepareSpace?.(E))}finally{t.preparing?.(!1)}};try{if(e.scopeId.startsWith("remote:")||e.homeId.startsWith("remote:")){const f=e.scopeId.slice(7);if(e.homeId!==e.scopeId||!e.scopeId.startsWith("remote:")||!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(f))throw new b("scope-invalid");const k=t.control?.()??t.local();if(k===null||k.selection.source==="remote"||k.selection.source==="ssh")throw new b("offline");const C=k.client.klient.rest?.connections;if(C===void 0)throw new b("offline");const M=await C.list();r.throwIfAborted();const P=M.find(D=>D.id===f);if(P===void 0)throw new b("scope-invalid");if(P.enabled!==!0||P.state==="disabled"||P.target.protocol!==vn)throw new b("identity-mismatch");o={config:k.selection.config,persist:!1,source:"remote",scopeId:e.scopeId,connectionId:P.id,serverHomeId:P.target.homeId},g=t.createClient?.(o)??at({endpoint:o.config.url,token:o.config.token,connectionId:P.id}),S=!0;const p=await g.meta();if(r.throwIfAborted(),p.server_home_id!==P.target.homeId||e.serverHomeId!==void 0&&e.serverHomeId!==p.server_home_id||e.connectionRef!==void 0&&e.connectionRef!==P.id)throw new b("identity-mismatch");const w=g;return{scope:{...e,serverHomeId:p.server_home_id,connectionRef:P.id},validate:(D,A)=>ot(w,D,A),commit:()=>{r.throwIfAborted(),t.commit(o,w,p),t.reload(),S=!1,t.preparing?.(!1)},dispose:O}}if(e.scopeId.startsWith("ssh:")&&!s&&!e.connectionRef)throw new b("auth-required");if(l&&a.selection.source==="remote"&&(E=t.host.activeSpace===void 0?"main":ct(await t.host.activeSpace())?.homeId??"main",r.throwIfAborted(),L=e.homeId===E&&(e.scopeId==="local"||e.scopeId.startsWith("direct:"))),l&&!L){if(!t.host.prepareSpace)throw new b("scope-invalid");const f=await t.host.prepareSpace(e.homeId);if(F=!0,r.throwIfAborted(),f.homeId!==e.homeId)throw new b("identity-mismatch")}if(e.scopeId.startsWith("ssh:")){const f=e.scopeId.slice(4),k=await t.host.connection.listSshProfiles?.();r.throwIfAborted();const C=k?.find(p=>p.id===f);if(C===void 0)throw new b("scope-invalid");if(!C.serverHomeId||!C.remotePort)throw new b("scope-invalid");let M;if(s!==void 0){if(!/^[A-Za-z0-9_-]{43}$/.test(s))throw new b("auth-required");if(!t.host.connection.prepareSshProfile)throw new b("scope-invalid");try{M=await t.host.connection.prepareSshProfile(f,s)}catch(p){if(p instanceof b)throw p;const w=p instanceof Error?p.message:String(p);throw w.includes("rejected the bearer token")?new b("auth-required"):w.includes("home identity")||w.includes("authentication; SSH connection blocked")||w.includes("build identity")||w.includes("release channel")?new b("identity-mismatch"):p}M.tunnelId&&(U={id:f,tunnelId:M.tunnelId})}else{if(!e.connectionRef||!t.host.connection.resumeScopeConnection)throw new b("auth-required");try{M=(await t.host.connection.resumeScopeConnection(e.homeId,f,e.connectionRef)).connection}catch(p){const w=p instanceof Error?p.message:String(p);throw new b(w.includes("offline")?"offline":w.includes("identity changed")?"identity-mismatch":"auth-required")}if(M.tunnelId!==e.connectionRef)throw new b("identity-mismatch")}r.throwIfAborted();let P;try{P=new URL(M.config.url)}catch{throw new b("identity-mismatch")}if(P.protocol!=="http:"||P.hostname!=="127.0.0.1"||P.username||P.password||!P.port||!M.tunnelId||s!==void 0&&M.config.token!==s||M.serverHomeId!==C.serverHomeId)throw new b("identity-mismatch");o={config:M.config,persist:!1,source:"ssh",scopeId:e.scopeId,profile:C,tunnelId:M.tunnelId,serverHomeId:M.serverHomeId,serverInstanceId:M.serverInstanceId,serverVersion:M.serverVersion,buildId:M.buildId,buildChannel:M.buildChannel}}else if(e.scopeId==="local"||L&&e.scopeId.startsWith("direct:"))if(l&&!L){const f=await t.host.connection.discover();if(f===null)throw new b("offline");o={config:f.config,persist:!1,source:"desktop",scopeId:"local"}}else{const f=L?t.control?.()??t.local():t.local();if(f===null)throw new b("offline");if(e.scopeId.startsWith("direct:")&&e.scopeId!==(f.selection.scopeId??`direct:${f.selection.config.url.trim().replace(/\/+$/,"")}`))throw new b("scope-invalid");o=f.selection,g=f.client}else if(e.homeId===a.scope.homeId&&e.scopeId===a.scope.scopeId)o=a.selection,g=a.client;else throw new b("scope-invalid");r.throwIfAborted(),g===void 0&&(g=t.createClient?.(o)??new Le({baseUrl:o.config.url,token:o.config.token}),S=!0);const v=await g.meta();if(r.throwIfAborted(),e.serverHomeId!==void 0&&v.server_home_id!==e.serverHomeId)throw new b("identity-mismatch");if(o.source==="ssh"&&(v.server_home_id!==o.serverHomeId||v.server_id!==o.serverInstanceId||v.server_version!==o.serverVersion||v.dangerous_bypass_auth!==!1||(v.build_id??null)!==o.buildId||(v.build_channel??null)!==o.buildChannel))throw new b("identity-mismatch");const u=g;return{scope:{...e,serverHomeId:v.server_home_id,connectionRef:o.source==="ssh"?o.tunnelId:void 0},validate:(f,k)=>ot(u,f,k),commit:async()=>{if(r.throwIfAborted(),o.source==="ssh"&&o.profile&&o.tunnelId){if(!t.host.connection.commitScopeConnection)throw new b("scope-invalid");await t.host.connection.commitScopeConnection(e.homeId,o.profile.id,o.tunnelId,l),r.throwIfAborted()}l?(S&&await u.klient.close(),r.throwIfAborted(),t.reload()):t.commit(o,u,v),S=!1,F=!1,U=void 0,t.preparing?.(!1)},dispose:O}}catch(v){throw await O(),(v instanceof Ne||v instanceof Fe)&&v.code===Oe.UNAUTHORIZED?new b("auth-required"):v}}}}function it(){const t=`${window.location.pathname}${window.location.search}${window.location.hash}`,e=Jn(window.location);if(e!==t)try{window.history.replaceState(window.history.state,"",e)}catch{}}function Wt(t,e){return t.type!=="event.model_catalog.changed"?!1:(e.invalidateQueries({queryKey:["models"]}),e.invalidateQueries({queryKey:["providers"]}),e.invalidateQueries({queryKey:["model-entity"]}),e.invalidateQueries({queryKey:["provider-entity"]}),e.invalidateQueries({queryKey:["discovered-models"]}),!0)}function He(t,e){t.invalidateQueries({queryKey:["sessions"]}),t.invalidateQueries({queryKey:["rooms"]}),t.invalidateQueries({queryKey:["activity-prompts",e]}),t.invalidateQueries({queryKey:["activity-tasks",e]})}const Ut=3,ft=64*1024*1024,Kt=ft/2,Vt=5*6e4,Bt=4;function Te(t){const e=t.getState();return e.busy||e.pendingInteraction!=="none"||e.tasks.some(r=>r.status==="running")}function cr(t){const e=t.getState();return e.loaded&&e.loadError===void 0&&!(e.resyncFailed&&e.resyncError?.retryable===!1)}class zt{controllers=new Set;retained=new WeakMap;parked=new Map;listeners=new Set;generation=0;limits;now;setTimer;clearTimer;ttlTimer=null;constructor(e={}){this.limits={maxParked:e.maxParked??Ut,maxBytes:e.maxBytes??ft,maxEntryBytes:e.maxEntryBytes??Kt,ttlMs:e.ttlMs??Vt,maxLiveParked:e.maxLiveParked??Bt},this.now=e.now??Date.now,this.setTimer=e.setTimer??((r,s)=>setTimeout(r,s)),this.clearTimer=e.clearTimer??(r=>{clearTimeout(r)})}acquire(e,r,s){let a=this.retained.get(r);a===void 0&&(a=new Map,this.retained.set(r,a));let l=a.get(e);if(l===void 0){const S=s();if(S.sessionId!==e||this.controllers.has(S))throw new Error("Controller factory must return a fresh controller for the requested session");l={controller:S,ready:S.open(),references:1,sessions:a,sessionId:e},a.set(e,l),this.add(S)}else l.parked!==void 0?(this.unpark(l),l.references=1,l.ready=l.controller.resume(),this.add(l.controller)):l.references+=1;const o=l;let g=!1;return{controller:o.controller,ready:o.ready,release:()=>{g||(g=!0,o.references-=1,!(o.references>0)&&(this.park(o,r)||this.dispose(o)))}}}get parkedCount(){return this.parked.size}hasRetained(e,r){return e===""?!1:this.retained.get(r)?.has(e)===!0}evictScope(e){for(const[r,s]of Array.from(this.parked))s===e&&this.dispose(r)}clearParked(){for(const e of Array.from(this.parked.keys()))this.dispose(e)}park(e,r){const{controller:s}=e;if(typeof s.getState!="function"||typeof s.suspend!="function"||!cr(s))return!1;const a=s.residentBytes();if(a>this.limits.maxEntryBytes)return!1;const l=s.subscribe(()=>{this.onParkedChange(e)});return e.parked={at:this.now(),bytes:a,unsubscribe:l},this.parked.set(e,r),Te(s)||s.suspend(),this.delete(s),this.enforceLimits(),!0}unpark(e){e.parked?.unsubscribe(),e.parked=void 0,this.parked.delete(e),this.scheduleTtl()}dispose(e){e.parked!==void 0&&this.unpark(e),e.sessions.get(e.sessionId)===e&&e.sessions.delete(e.sessionId),e.controller.close(),this.delete(e.controller)}onParkedChange(e){const r=e.parked;if(r===void 0||e.controller.suspended||Te(e.controller))return;const s=this.parked.get(e)??{};e.parked={...r,at:this.now()},this.parked.delete(e),this.parked.set(e,s),e.controller.suspend(),this.enforceLimits()}isLiveProtected(e){return!e.controller.suspended&&Te(e.controller)}enforceLimits(){const e=this.now(),r=Array.from(this.parked.keys()).filter(o=>this.isLiveProtected(o));for(const o of r.slice(0,Math.max(0,r.length-this.limits.maxLiveParked)))o.controller.suspend();for(const o of Array.from(this.parked.keys()))!this.isLiveProtected(o)&&e-(o.parked?.at??e)>=this.limits.ttlMs&&this.dispose(o);const s=()=>Array.from(this.parked.keys()).filter(o=>!this.isLiveProtected(o));let a=s(),l=a.reduce((o,g)=>o+(g.parked?.bytes??0),0);for(;a.length>0&&(a.length>this.limits.maxParked||l>this.limits.maxBytes);){const o=a[0];l-=o.parked?.bytes??0,this.dispose(o),a=s()}this.scheduleTtl()}scheduleTtl(){this.ttlTimer!==null&&(this.clearTimer(this.ttlTimer),this.ttlTimer=null);let e=1/0;for(const r of this.parked.keys())this.isLiveProtected(r)||(e=Math.min(e,(r.parked?.at??0)+this.limits.ttlMs));e!==1/0&&(this.ttlTimer=this.setTimer(()=>{this.ttlTimer=null,this.enforceLimits()},Math.max(0,e-this.now())))}add(e){this.controllers.add(e),this.emit()}delete(e){this.controllers.delete(e)&&this.emit()}[Symbol.iterator](){return this.controllers.values()}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}snapshot(){return this.generation}emit(){this.generation+=1;for(const e of this.listeners)e()}}const De=c.createContext(null),ar=15e3;let Ft=0;function Gt(t=Date.now()){return Ft+=1,`gui-${t.toString(36)}-${Ft.toString(36)}`}function he(t){return t?.source==="desktop"}function Ot(t,e){return t.url.trim().replace(/\/+$/,"")===e.url.trim().replace(/\/+$/,"")&&t.token.trim()===e.token.trim()}function lr(t,e){for(const r of["server_id","server_home_id","current_space_id","dangerous_bypass_auth"])if(t[r]!==void 0&&e[r]!==void 0&&t[r]!==e[r])return"changed";return!t.server_id||!e.server_id||!t.server_home_id||!e.server_home_id||typeof t.dangerous_bypass_auth!="boolean"||typeof e.dangerous_bypass_auth!="boolean"||t.current_space_id!==e.current_space_id?"unknown":"same"}function ur({children:t}){const e=dt(),r=e.kind==="tauri",s=Pn(),{locale:a,t:l}=fe(),o=c.useRef(new Map),g=bn(),S=c.useRef(g?.scopeId.startsWith("remote:")?g:null),E=c.useSyncExternalStore(wn,yn,kn).requestTimeoutSeconds*1e3,[L,U]=c.useState(()=>jn()),[O,v]=c.useState(L.kind==="failed"?In(L.reason):void 0),[u,f]=c.useState(()=>r||s?null:L.kind==="signed-in"?{config:{url:"",token:""},persist:!1,source:"web-cookie"}:(Sn(i=>{!i||j.current!==null||(q.current+=1,f({config:{url:"",token:""},persist:!1,source:"web-cookie"}))}),sr({deepLink:er(),stored:tr()}))),k=u?.config??null,C=u?.scopeId??(r?"local":`direct:${k?.url.trim().replace(/\/+$/,"")??""}`),M=u?.source==="remote"?u.connectionId??null:null,P=u?.source??null,p=M===null?nt()?.homeId??"main":`remote:${M}`;let w=o.current.get(C);w===void 0&&(w=new Tn({defaultOptions:{queries:{retry:1,staleTime:0,refetchOnWindowFocus:!1}}}),o.current.set(C,w));const[D,A]=c.useState(null),[Q,H]=c.useState(null),[ke,Y]=c.useState(()=>r?{stage:"spawning",startedAtMs:Date.now()}:null),[Qe,se]=c.useState(null),[qe,h]=c.useState(0),_=c.useRef(!1),[X,pe]=c.useState("closed"),oe=c.useRef("closed"),ee=c.useRef(null),G=c.useRef(null),$e=c.useRef(new zt),q=c.useRef(0),me=c.useRef(0),ie=c.useRef(null),[de,Zt]=c.useState(null),te=c.useCallback(i=>{ie.current=i,Zt(i)},[]),We=c.useRef(null),mt=c.useRef(new Map),je=c.useRef(null),Ue=c.useRef(!1),Yt=c.useRef({promise:null,consumed:!1}),j=c.useRef(u);j.current=u;const Xt=c.useRef(Gt()),ce=c.useRef(void 0);c.useEffect(()=>(e.connection.setWorkspaceScope?.(u?.source==="ssh"?"ssh":"local"),()=>e.connection.setWorkspaceScope?.("local")),[e,u?.source]),c.useEffect(()=>{if(!s)return;let i=!1;return e.connection.discover().then(d=>{i||d!==null&&(q.current+=1,f({config:d.config,persist:d.persist,source:"local-detection"}))},d=>{i||H({kind:"raw",text:d instanceof Error?d.message:String(d)})}),()=>{i=!0}},[e,s]),c.useEffect(()=>{if(e.kind!=="tauri")return;let i=!1,d=0;_.current=!1;let m;const x=()=>{const y=ee.current;return y!==null&&y.selection===j.current&&y.client===le.current&&y.homeId===(nt()?.homeId??"main")&&y.scopeId===(j.current?.scopeId??"local")?y:null},R=y=>{const W=x();return W===null?!1:(G.current={client:W.client,phase:"failed"},pe("closed"),Y(null),se(st(y)),!0)};let I=!1;const T=y=>{if(i||I&&y===void 0||_.current)return;I=!0;const W=++d,Je=x(),J=Je!==null&&(y===void 0||Ot(Je.selection.config,y))?Je:null;if(J===null){if(he(j.current)){const K=ee.current;K!==null&&K.selection===j.current&&o.current.get(K.scopeId)?.clear(),q.current+=1,j.current=null,f(null),A(null),ee.current=null,G.current=null}te(null)}else G.current={client:J.client,phase:"checking"},pe("connecting");j.current===null&&Y(K=>({stage:"waiting",startedAtMs:K?.startedAtMs??Date.now()}));const sn=j.current,on=q.current,_e=()=>!i&&!_.current&&W===d&&j.current===sn&&q.current===on,ye=Yt.current;y===void 0&&(ye.promise??=(e.connection.takeScopeConnection?.()??Promise.resolve(null)).then(K=>{if(K===null)return null;const V=K.connection;return{config:V.config,persist:!1,source:"ssh",scopeId:`ssh:${K.profile.id}`,profile:K.profile,tunnelId:V.tunnelId,serverHomeId:V.serverHomeId,serverInstanceId:V.serverInstanceId,serverVersion:V.serverVersion,buildId:V.buildId,buildChannel:V.buildChannel}}).catch(()=>null));const cn=y===void 0?e.connection.discover():Promise.resolve({config:y,persist:!1});Promise.all([cn,ye.consumed||y!==void 0?Promise.resolve(null):ye.promise]).then(async([K,V])=>{if(i||_.current||W!==d||V===null&&!_e())return;Y(null),se(null);const jt=!he(j.current)&&j.current!==null;if(K===null){if(R(new Error("Desktop connection discovery returned no verified endpoint."))||(te(null),jt))return;H({kind:"key",key:"conn.desktopNoServer"});return}if(J!==null&&V===null&&Ot(J.selection.config,K.config)){const tt=await J.client.meta();if(!_e()||x()!==J)return;const It=lr(J.meta,tt);if(It==="unknown"){R(new Error("The desktop backend identity could not be verified."));return}if(It==="same"){ee.current={...J,meta:tt},G.current=null,A(tt),H(null),pe(oe.current);return}}const et={config:K.config,persist:!1,source:"desktop",scopeId:"local"};if(te(et),V!==null&&!ye.consumed){ye.consumed=!0,ye.promise=Promise.resolve(null),j.current=V,V.profile&&V.tunnelId&&(je.current={id:V.profile.id,tunnelId:V.tunnelId}),q.current+=1,f(V);return}jt||!_e()||(J!==null&&o.current.get(J.scopeId)?.clear(),ee.current=null,G.current=null,A(null),H(null),q.current+=1,j.current=et,f(et))}).catch(K=>{!_e()||R(K)||(te(null),!(!he(j.current)&&j.current!==null)&&(q.current+=1,Y(null),A(null),j.current=null,f(null),se(st(K))))}).finally(()=>{W===d&&(I=!1)})};let $;ce.current=void 0;const ue=()=>{$===void 0&&($=setTimeout(()=>{if($=void 0,i)return;const y=j.current?.source;!he(j.current)&&y!=="ssh"&&y!=="remote"||Ue.current||T()},250))};ce.current=ue;const kt=()=>j.current?.source==="ssh"||j.current?.source==="remote",Xe=()=>j.current===null||he(j.current);return e.connection.onBackendStage(y=>{if(!(i||_.current||Ue.current)){if(y==="waiting"){if(!I||!Xe())return;Y(W=>({stage:"waiting",startedAtMs:W?.startedAtMs??Date.now()}));return}if(y!==null&&typeof y=="object"&&"stage"in y&&y.stage==="ready"&&"connection"in y){if(!Xe()&&!kt()||I&&x()===null)return;const W=y.connection;if(W===null||typeof W!="object"||!("url"in W)||typeof W.url!="string"||!("token"in W)||typeof W.token!="string")return;kt()?te({config:{url:W.url,token:W.token},persist:!1,source:"desktop",scopeId:"local"}):T({url:W.url,token:W.token});return}y===null||typeof y!="object"||!("stage"in y)||y.stage!=="failed"||!("failure"in y)||Xe()&&(d+=1,I=!1,!R(y.failure)&&(te(null),q.current+=1,A(null),f(null),H(null),Y(null),se(st(y.failure))))}}).then(y=>{i?y():(m=y,T())},()=>{T()}),()=>{i=!0,d+=1,$!==void 0&&clearTimeout($),ce.current===ue&&(ce.current=void 0),m?.()}},[e,qe,te]);const Ke=c.useCallback(()=>{se(null),H(null),Y({stage:"spawning",startedAtMs:Date.now()}),h(i=>i+1)},[]),Jt=c.useCallback(()=>{_.current=!0,Y(null),se({message:l("connect.desktopCancelled"),stderrTail:[],logPath:null}),e.connection.cancelStartup?.().catch(()=>{})},[e,l]),Ve=de?.config.url.trim().replace(/\/+$/,"")??null,Be=de?.config.token.trim()??null,[xt,en]=c.useState(null),ae=de!==null&&xt?.selection===de?xt.client:null,le=c.useRef(ae);le.current=ae;const ze=c.useRef(null);c.useEffect(()=>{if(de===null||Ve===null||Be===null)return;const i=new Le({baseUrl:Ve,token:Be,timeoutMs:E,onSessionMutation:d=>{const m=o.current.get("local");m!==void 0&&He(m,d)}});return en({selection:de,client:i}),()=>{i.klient.close()}},[de,Ve,Be,E]),c.useEffect(()=>{if(!(e.kind!=="tauri"||ae===null||u?.source!=="ssh"&&u?.source!=="remote"))return ae.klient.terminal.onStatus(i=>{i==="closed"&&ce.current?.()})},[e,ae,u?.source]);const xe=k?.url.trim().replace(/\/+$/,"")??null,ge=k?.token.trim()??null,[Ie,gt]=c.useState(null),ve=u?.source==="desktop",Se=We.current?.selection===u?We.current:null,Me=ve?ae:null,N=Se?.client??(Ie?.endpoint===xe&&Ie.token===ge&&Ie.scopeId===C&&(!ve||Ie.client===Me)?Ie.client:null),z=N?.klient??null;c.useEffect(()=>{if(xe===null||ge===null||ve&&Me===null)return;const i=x=>{He(w,x)},d=Se?.client??Me??(u?.source==="remote"?at({endpoint:xe,token:ge,connectionId:u.connectionId,timeoutMs:E,onSessionMutation:i}):new Le({baseUrl:xe,token:ge,timeoutMs:E,onSessionMutation:i}));gt({endpoint:xe,token:ge,scopeId:C,client:d});const m=$e.current;return()=>{ee.current?.client===d&&(ee.current=null),G.current?.client===d&&(G.current=null),m.evictScope(d),d!==Me&&d.klient.close()}},[xe,ge,C,E,w,ve,Me,Se?.client]),c.useEffect(()=>{if(N===null||S.current!==null&&u?.source!=="remote")return;let i=!1;const d=q.current;H(null);const m=Se?.client===N?Se:ze.current?.client===N?ze.current:null;return m!==null&&(ze.current=null),(m!==null?Promise.resolve(m.meta):N.meta()).then(x=>{if(!(i||d!==q.current)){if(it(),u?.source==="ssh"){const R=u.serverHomeId,I=mt.current.get(C);if(!R||!u.serverInstanceId||!u.serverVersion||x.server_home_id!==R||x.server_id!==u.serverInstanceId||x.server_version!==u.serverVersion||x.dangerous_bypass_auth!==!1||(x.build_id??null)!==u.buildId||(x.build_channel??null)!==u.buildChannel||I!==void 0&&I!==R){A(null),H({kind:"raw",text:"SSH server identity changed or could not be verified. This connection is blocked."});return}mt.current.set(C,R)}if(u?.source==="remote"&&(!u.serverHomeId||x.server_home_id!==u.serverHomeId)){A(null),H({kind:"raw",text:"identity-mismatch"});return}u?.source!=="remote"&&u?.persist===!0&&k!==null&&nr(k),u?.source==="desktop"&&u===j.current&&(ee.current={selection:u,client:N,meta:x,homeId:p,scopeId:C},G.current=null),A(x)}},x=>{i||d!==q.current||(A(null),H({kind:"raw",text:x instanceof Ne||x instanceof Error?x.message:String(x)}),it())}),()=>{i=!0}},[N,k,u?.persist]);const be=k!==null&&D!==null&&N!==null;c.useEffect(()=>{if(!be||N===null)return;const i=()=>{N.renewLease({clientId:Xt.current,kind:"gui"}).catch(()=>{})};i();const d=window.setInterval(i,ar);return()=>{window.clearInterval(d)}},[N,be]),c.useEffect(()=>{if(!be||u?.source!=="ssh"||!e.connection.sshTunnelRunning)return;const i=u.profile?.id,d=u.tunnelId;if(!i||!d)return;let m=!0,x=!1;const R=()=>{x||(x=!0,e.connection.sshTunnelRunning(i,d).then(T=>{!m||T||(q.current+=1,A(null),H({kind:"raw",text:"SSH tunnel disconnected. Check the remote service and connect again."}))},T=>{m&&(q.current+=1,A(null),H({kind:"raw",text:`Cannot check the SSH tunnel: ${String(T)}`}))}).finally(()=>{x=!1}))};R();const I=window.setInterval(R,2e3);return()=>{m=!1,window.clearInterval(I)}},[be,u?.source,u?.profile?.id,u?.tunnelId,e]);const Z=c.useMemo(()=>{const i=be?z?.terminal??null:null;return i===null||!ve?i:{...i,nudge:()=>{i.nudge(),G.current?.client===N&&ce.current?.()}}},[be,z,N,ve]);c.useEffect(()=>{if(Z===null||z===null)return;let i=!0;const d=()=>{const $=z.events.on("search.indexStateChanged",ue=>{w.cancelQueries({queryKey:["search-index-state"]}).then(()=>{i&&m===$&&w.setQueryData(["search-index-state"],ue)})});return $.ready.then(()=>{if(i&&m===$)return w.invalidateQueries({queryKey:["search-index-state"]})}).catch(()=>{}),$};let m=d(),x=Ht(z,w),R=Tt(z,w);const I=Z.onStatus($=>{if(!i)return;oe.current=$,$==="closed"&&e.kind==="tauri"&&he(j.current)&&(N!==null&&ee.current?.client===N&&(G.current={client:N,phase:"checking"}),ce.current?.());const ue=G.current?.client===N?G.current:null;pe(ue?.phase==="failed"?"closed":ue!==null&&$==="open"?"connecting":$),$==="open"&&ue?.phase==="failed"&&ce.current?.(),$==="open"&&(m.dispose(),m=d(),x(),x=Ht(z,w),R(),R=Tt(z,w))}),T=z.events.on("kosong.changed",()=>{Wt({type:"event.model_catalog.changed"},w)});return()=>{i=!1,I(),T.dispose(),m.dispose(),x(),R()}},[Z,z,w]),c.useEffect(()=>{if(Z!==null)return En()},[Z]),c.useEffect(()=>{if(Z===null)return;const i=()=>{Z.nudge();for(const m of $e.current)m.nudge()},d=()=>{document.visibilityState==="visible"&&i()};return window.addEventListener("online",i),window.addEventListener("focus",i),window.addEventListener("pageshow",i),document.addEventListener("visibilitychange",d),()=>{window.removeEventListener("online",i),window.removeEventListener("focus",i),window.removeEventListener("pageshow",i),document.removeEventListener("visibilitychange",d)}},[Z]);const[vt,tn]=c.useState(!1),ne=c.useRef({scope:{homeId:p,scopeId:C},selection:u,client:N});ne.current={scope:{homeId:p,scopeId:C},selection:u,client:N};const we=c.useMemo(()=>ir({host:e,active:()=>{const i=ne.current;if(i.selection===null||i.client===null)throw new Error("No active connection");return{scope:i.scope,selection:i.selection,client:i.client}},local:()=>ie.current!==null&&le.current!==null?{selection:ie.current,client:le.current}:null,control:()=>{if(ie.current!==null&&le.current!==null)return{selection:ie.current,client:le.current};const i=ne.current;return i.selection!==null&&i.client!==null&&i.selection.source!=="remote"&&i.selection.source!=="ssh"?{selection:i.selection,client:i.client}:null},createClient:i=>i.source==="remote"?at({endpoint:i.config.url,token:i.config.token,connectionId:i.connectionId,timeoutMs:E,onSessionMutation:d=>{const m=o.current.get(i.scopeId);m!==void 0&&He(m,d)}}):new Le({baseUrl:i.config.url,token:i.config.token,timeoutMs:E}),reload:()=>{S.current===null&&tn(!0)},preparing:i=>{Ue.current=i},commit:(i,d,m)=>{if(me.current+=1,q.current+=1,i===ne.current.selection&&d===ne.current.client){A(m);return}const x=ne.current.selection;i.source==="remote"&&!r&&x!==null&&x.source!=="remote"&&x.source!=="ssh"&&te({...x,scopeId:ne.current.scope.scopeId});const R=i.source==="ssh"&&i.profile&&i.tunnelId?{id:i.profile.id,tunnelId:i.tunnelId}:null;je.current=R,We.current={selection:i,client:d,meta:m},j.current=i,f(i),gt({endpoint:i.config.url.trim().replace(/\/+$/,""),token:i.config.token.trim(),scopeId:i.scopeId??"local",client:d}),H(null),A(m)}}),[e,E,r,te]);c.useEffect(()=>{const i=S.current;if(i===null||N===null||u?.source==="remote")return;const d=new AbortController;return(async()=>{const m=await we.prepare(i,d.signal);try{await m.validate(`${window.location.pathname}${window.location.search}${window.location.hash}`,d.signal),d.signal.throwIfAborted(),await m.commit(),S.current=null}catch(x){throw await m.dispose(),x}})().catch(m=>{d.signal.aborted||(A(null),H({kind:"raw",text:m instanceof Error?m.message:String(m)}))}),()=>{d.abort()}},[N,u?.source,we]);const bt=c.useCallback(async(i=new AbortController().signal)=>{const d=le.current,m=j.current,x=me.current,R=m?.source==="remote"?e.activeSpace===void 0?"main":ct(await e.activeSpace())?.homeId??"main":nt()?.homeId??"main",I=await we.prepare({homeId:R,scopeId:"local"},i);try{if(i.throwIfAborted(),d!==le.current||m!==j.current||x!==me.current)throw new DOMException("Local connection restoration was superseded.","AbortError");await I.commit()}catch(T){throw await I.dispose(),T}},[we,e]),Ce=c.useCallback(()=>{if(D!==null&&N!==null){j.current?.source==="remote"?(async()=>{const d=e.activeSpace===void 0?"main":ct(await e.activeSpace())?.homeId??"main";await rt({homeId:d,scopeId:ie.current?.scopeId??"local"})})().catch(()=>{}):rt({scopeId:"local"}).catch(()=>{});return}me.current+=1,q.current+=1;const i=je.current;je.current=null,i!==null&&e.connection.disconnectSshProfile?.(i.id,i.tunnelId).catch(()=>{}),A(null),H(null),f(ie.current),ie.current===null&&r&&Ke()},[D,N,e,r,Ke]),Ge=c.useCallback(async(i,d)=>{if(ne.current.client!==null&&ne.current.selection!==null){await rt({scopeId:`ssh:${i}`,token:d});return}if(!e.connection.connectSshProfile||!e.connection.listSshProfiles)throw new Error("SSH connections are available only in the desktop application.");const m=++me.current,R=(await e.connection.listSshProfiles()).find($=>$.id===i);if(!R)throw new Error("SSH profile no longer exists.");if(!R.serverHomeId||!R.remotePort||!/^[A-Za-z0-9_-]{43}$/.test(d))throw new Error("Set the remote Kiki port, expected home ID and bearer token first.");const I=await e.connection.connectSshProfile(i,d);if(m!==me.current){I.tunnelId&&e.connection.disconnectSshProfile?.(i,I.tunnelId).catch(()=>{});return}let T;try{T=new URL(I.config.url)}catch{T=null}if(T?.protocol!=="http:"||T.hostname!=="127.0.0.1"||T.username||T.password||!T.port||!I.tunnelId||I.config.token!==d||I.serverHomeId!==R.serverHomeId)throw I.tunnelId&&e.connection.disconnectSshProfile?.(i,I.tunnelId).catch(()=>{}),new Error("SSH tunnel endpoint or server home ID could not be verified.");je.current={id:i,tunnelId:I.tunnelId},q.current+=1,A(null),H(null),f({config:I.config,persist:!1,source:"ssh",scopeId:`ssh:${i}`,profile:R,tunnelId:I.tunnelId,serverHomeId:I.serverHomeId,serverInstanceId:I.serverInstanceId,serverVersion:I.serverVersion,buildId:I.buildId,buildChannel:I.buildChannel})},[e]),Ze=c.useCallback(()=>{if(j.current?.source==="ssh"){Ce();return}q.current+=1,rr(),A(null),f(null),H(null),it()},[Ce]),nn=c.useCallback(()=>{Rn(),U({kind:"none"}),v(void 0)},[]),Ye=c.useCallback((i,d=!0)=>{const m=++q.current,x=j.current,R=x!==null&&x.config.url.trim().replace(/\/+$/,"")===i.url.trim().replace(/\/+$/,"")&&x.config.token.trim()===i.token.trim();H(null),A(null),f({config:i,persist:d,source:d?"manual":"local-detection",scopeId:R?x.scopeId:`direct:${i.url.trim().replace(/\/+$/,"")}:${m}`})},[]),wt=c.useCallback(i=>{j.current?.source==="ssh"||j.current?.source==="remote"||Ye(i,!0)},[Ye]),yt=c.useMemo(()=>k===null||N===null||z===null||Z===null||D===null?null:{connectionId:M,connectionSource:u?.source??null,spaceKey:p,scopeId:C,connectionRef:u?.source==="remote"?u.connectionId:u?.source==="ssh"?u.tunnelId:void 0,sshLabel:u?.profile?.label??null,activateSshProfile:Ge,activateLocal:Ce,restoreLocal:bt,scopeAdapter:we,needsScopeReload:vt,config:k,client:N,localClient:ae,klient:z,socket:Z,meta:D,wsStatus:X,disconnect:Ze,applyConnection:wt},[M,P,p,C,u?.tunnelId,u?.profile?.label,Ge,Ce,bt,we,vt,k,N,ae,z,Z,D,X,Ze,wt]),Pe=Q===null?null:Q.kind==="key"?Mn(a,Q.key,Q.params):Q.text,rn=u?.source==="ssh"?Pe===null?null:{message:Pe,stderrTail:[],logPath:null}:Qe??(r&&Pe!==null?{message:Pe,stderrTail:[],logPath:null}:null);return n.jsx(De.Provider,{value:yt,children:yt!==null?n.jsx(Cn,{client:w,children:n.jsx(pt.Provider,{value:$e.current,children:t})}):n.jsx(Un,{initial:k??{url:"",token:""},connecting:ke!==null||k!==null&&Q===null,error:r?null:Pe,onConnect:Ye,onBack:r?void 0:k!==null?Ze:void 0,desktopBoot:ke,desktopFailure:rn,onRetryDesktop:Ke,onCancelDesktopBoot:Jt,onConnectSsh:Ge,onSwitchLocal:u?.source==="ssh"?Ce:void 0,sshProfile:u?.source==="ssh"?u.profile:void 0,webLink:O,onRetryWebLink:nn})})}const pt=c.createContext(null);function dr(){const t=c.useContext(pt);if(t===null)throw new Error("useControllerRegistry outside provider");return t}function hr(){return c.useContext(pt)}function fr({value:t,children:e}){return n.jsx(De.Provider,{value:t,children:e})}function pr(){const t=c.useContext(De);if(t===null)throw new Error("useConnection used before connecting");return t}function mr(){return c.useContext(De)}const Cr=Object.freeze(Object.defineProperty({__proto__:null,ConnectionProvider:ur,ConnectionScope:fr,LiveControllerRegistry:zt,VIEW_CACHE_MAX_BYTES:ft,VIEW_CACHE_MAX_ENTRY_BYTES:Kt,VIEW_CACHE_MAX_LIVE_PARKED:Bt,VIEW_CACHE_MAX_PARKED:Ut,VIEW_CACHE_TTL_MS:Vt,handleGlobalConnectionFrame:Wt,isDesktopSelection:he,isProtectedView:Te,nextGuiLeaseClientId:Gt,refreshSessionAttention:He,useConnection:pr,useControllerRegistry:dr,useOptionalConnection:mr,useOptionalControllerRegistry:hr},Symbol.toStringTag,{value:"Module"}));export{On as D,ut as I,Sr as K,yr as O,Dn as S,Ee as W,br as a,mr as b,Yn as c,hr as d,dr as e,At as f,An as g,wr as h,Et as i,Cr as j,kr as l,Mr as o,Ir as p,jr as s,pr as u};