kiki-agent 0.5.0 → 0.5.1

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 (230) hide show
  1. package/README.md +3 -3
  2. package/dist/cpu-worker.mjs +52744 -0
  3. package/dist/docs/en/configuration/config-files.md +92 -30
  4. package/dist/docs/en/configuration/data-locations.md +14 -9
  5. package/dist/docs/en/configuration/env-vars.md +32 -2
  6. package/dist/docs/en/configuration/overrides.md +1 -1
  7. package/dist/docs/en/configuration/providers.md +44 -10
  8. package/dist/docs/en/customization/agent-profiles.md +1 -1
  9. package/dist/docs/en/customization/agents-and-subagents.md +49 -10
  10. package/dist/docs/en/customization/hooks.md +3 -3
  11. package/dist/docs/en/customization/personas.md +1 -1
  12. package/dist/docs/en/customization/plugins.md +16 -3
  13. package/dist/docs/en/customization/prompt-fields.md +62 -6
  14. package/dist/docs/en/customization/recipes.md +77 -0
  15. package/dist/docs/en/customization/skins.md +2 -2
  16. package/dist/docs/en/customization/themes.md +1 -1
  17. package/dist/docs/en/features/browser-and-computer.md +5 -5
  18. package/dist/docs/en/features/daily.md +3 -3
  19. package/dist/docs/en/features/ecosystem.md +1 -1
  20. package/dist/docs/en/features/extend.md +2 -2
  21. package/dist/docs/en/features/freedom.md +1 -1
  22. package/dist/docs/en/features/index.md +15 -1
  23. package/dist/docs/en/features/long-work.md +9 -5
  24. package/dist/docs/en/features/look.md +1 -1
  25. package/dist/docs/en/features/phone.md +11 -3
  26. package/dist/docs/en/features/spaces.md +5 -5
  27. package/dist/docs/en/getting-started/desktop-app.md +4 -8
  28. package/dist/docs/en/getting-started/first-launch.md +1 -1
  29. package/dist/docs/en/guides/goals.md +4 -2
  30. package/dist/docs/en/guides/interface.md +18 -8
  31. package/dist/docs/en/guides/memory.md +64 -10
  32. package/dist/docs/en/guides/sessions.md +15 -7
  33. package/dist/docs/en/guides/settings.md +49 -38
  34. package/dist/docs/en/index.md +3 -1
  35. package/dist/docs/en/reference/command.md +35 -33
  36. package/dist/docs/en/reference/model-vocabulary.md +2 -2
  37. package/dist/docs/en/reference/slash-commands.md +1 -1
  38. package/dist/docs/en/reference/tools.md +40 -15
  39. package/dist/docs/en/server/acp.md +6 -2
  40. package/dist/docs/en/server/local-server.md +19 -27
  41. package/dist/docs/en/server/mcp.md +4 -4
  42. package/dist/docs/en/server/rest-api.md +240 -23
  43. package/dist/docs/en/server/script-tools.md +268 -0
  44. package/dist/docs/zh/configuration/config-files.md +92 -30
  45. package/dist/docs/zh/configuration/data-locations.md +14 -9
  46. package/dist/docs/zh/configuration/env-vars.md +32 -2
  47. package/dist/docs/zh/configuration/overrides.md +1 -1
  48. package/dist/docs/zh/configuration/providers.md +44 -10
  49. package/dist/docs/zh/customization/agent-profiles.md +1 -1
  50. package/dist/docs/zh/customization/agents-and-subagents.md +49 -10
  51. package/dist/docs/zh/customization/hooks.md +3 -3
  52. package/dist/docs/zh/customization/personas.md +1 -1
  53. package/dist/docs/zh/customization/plugins.md +16 -3
  54. package/dist/docs/zh/customization/prompt-fields.md +62 -6
  55. package/dist/docs/zh/customization/recipes.md +77 -0
  56. package/dist/docs/zh/customization/skins.md +2 -2
  57. package/dist/docs/zh/customization/themes.md +1 -1
  58. package/dist/docs/zh/features/browser-and-computer.md +5 -5
  59. package/dist/docs/zh/features/daily.md +3 -3
  60. package/dist/docs/zh/features/ecosystem.md +1 -1
  61. package/dist/docs/zh/features/extend.md +2 -2
  62. package/dist/docs/zh/features/freedom.md +1 -1
  63. package/dist/docs/zh/features/index.md +16 -2
  64. package/dist/docs/zh/features/long-work.md +9 -5
  65. package/dist/docs/zh/features/look.md +1 -1
  66. package/dist/docs/zh/features/phone.md +11 -3
  67. package/dist/docs/zh/features/spaces.md +5 -5
  68. package/dist/docs/zh/getting-started/desktop-app.md +4 -8
  69. package/dist/docs/zh/getting-started/first-launch.md +1 -1
  70. package/dist/docs/zh/guides/goals.md +4 -2
  71. package/dist/docs/zh/guides/interface.md +18 -8
  72. package/dist/docs/zh/guides/memory.md +64 -10
  73. package/dist/docs/zh/guides/sessions.md +15 -7
  74. package/dist/docs/zh/guides/settings.md +49 -38
  75. package/dist/docs/zh/index.md +4 -2
  76. package/dist/docs/zh/reference/command.md +35 -33
  77. package/dist/docs/zh/reference/model-vocabulary.md +2 -2
  78. package/dist/docs/zh/reference/slash-commands.md +1 -1
  79. package/dist/docs/zh/reference/tools.md +40 -15
  80. package/dist/docs/zh/server/acp.md +6 -2
  81. package/dist/docs/zh/server/local-server.md +19 -27
  82. package/dist/docs/zh/server/mcp.md +4 -4
  83. package/dist/docs/zh/server/rest-api.md +229 -23
  84. package/dist/docs/zh/server/script-tools.md +268 -0
  85. package/dist/external-harness/agy-cli-acp.mjs +168 -162
  86. package/dist/external-harness/agy-hook-registration.mjs +69 -30
  87. package/dist/external-harness/agy-mcp-plugin.mjs +19 -0
  88. package/dist/external-harness/agy-permission-hook.mjs +29 -2
  89. package/dist/hostRunner.mjs +24 -6
  90. package/dist/mailbox-worker.mjs +111 -5
  91. package/dist/main.mjs +2 -2
  92. package/dist/memory-worker.mjs +1008 -0
  93. package/dist/native/windows-process-helper.exe +0 -0
  94. package/dist/query-store-worker.mjs +52 -11
  95. package/dist/sqlite-indexer.mjs +32 -2
  96. package/dist/sqlite-query-worker.mjs +35 -0
  97. package/dist/usage-parser-worker.mjs +3953 -4
  98. package/dist/usage-read-model-worker.mjs +761 -0
  99. package/dist/web/assets/{AppErrorBoundary-BN6IDdP1.js → AppErrorBoundary-B5Fc4f6-.js} +1 -1
  100. package/dist/web/assets/NavScopeBoundary-C7MnGQio.js +1 -0
  101. package/dist/web/assets/{arc-C7IAvCCJ.js → arc-DGB9OVgQ.js} +1 -1
  102. package/dist/web/assets/{architectureDiagram-3BPJPVTR-CbwFBxn7.js → architectureDiagram-3BPJPVTR-glnQCMub.js} +1 -1
  103. package/dist/web/assets/{blockDiagram-GPEHLZMM-B20N4t8r.js → blockDiagram-GPEHLZMM-bM0tnGby.js} +1 -1
  104. package/dist/web/assets/{c4Diagram-AAUBKEIU-3BYtlcP-.js → c4Diagram-AAUBKEIU-DMf_rTtt.js} +1 -1
  105. package/dist/web/assets/channel-Cj8SKJ38.js +1 -0
  106. package/dist/web/assets/{chunk-2J33WTMH-CpjgczxM.js → chunk-2J33WTMH-mTccJ3tW.js} +1 -1
  107. package/dist/web/assets/{chunk-4BX2VUAB-BScxUF5G.js → chunk-4BX2VUAB-DhqPYMjY.js} +1 -1
  108. package/dist/web/assets/{chunk-55IACEB6-CrcLYJXd.js → chunk-55IACEB6-BujrYRoO.js} +1 -1
  109. package/dist/web/assets/{chunk-727SXJPM-BwlyIOjw.js → chunk-727SXJPM-ciMmSI4G.js} +1 -1
  110. package/dist/web/assets/{chunk-AQP2D5EJ-DKKIRkRv.js → chunk-AQP2D5EJ-CZW9pKTc.js} +1 -1
  111. package/dist/web/assets/{chunk-FMBD7UC4-CVDMj2kX.js → chunk-FMBD7UC4-hdALNnnU.js} +1 -1
  112. package/dist/web/assets/{chunk-ND2GUHAM-CL-PM6r8.js → chunk-ND2GUHAM-CgKyqUdb.js} +1 -1
  113. package/dist/web/assets/{chunk-QZHKN3VN-DPV2KbKZ.js → chunk-QZHKN3VN-B2mmUz_E.js} +1 -1
  114. package/dist/web/assets/classDiagram-4FO5ZUOK-f8V9p-dD.js +1 -0
  115. package/dist/web/assets/classDiagram-v2-Q7XG4LA2-f8V9p-dD.js +1 -0
  116. package/dist/web/assets/client-ClWQBErG.js +3 -0
  117. package/dist/web/assets/connection-C0J3BPgk.js +1 -0
  118. package/dist/web/assets/{cose-bilkent-S5V4N54A-D1CEiQM6.js → cose-bilkent-S5V4N54A-UV3uPjkK.js} +1 -1
  119. package/dist/web/assets/{dagre-BM42HDAG-BlFV941E.js → dagre-BM42HDAG-Zjy-gQ6C.js} +1 -1
  120. package/dist/web/assets/{diagram-2AECGRRQ-BC0ldkFY.js → diagram-2AECGRRQ-DL-kilIf.js} +1 -1
  121. package/dist/web/assets/{diagram-5GNKFQAL-B22Iej6G.js → diagram-5GNKFQAL-CjB_xR5B.js} +1 -1
  122. package/dist/web/assets/{diagram-KO2AKTUF-B75UNw6D.js → diagram-KO2AKTUF-CjN4i3b9.js} +1 -1
  123. package/dist/web/assets/{diagram-LMA3HP47-CypI7IJM.js → diagram-LMA3HP47-CPCAMndo.js} +1 -1
  124. package/dist/web/assets/{diagram-OG6HWLK6-OsXumvcD.js → diagram-OG6HWLK6-DVeBWBKd.js} +1 -1
  125. package/dist/web/assets/{erDiagram-TEJ5UH35-3756GOvS.js → erDiagram-TEJ5UH35-CHKzBHrr.js} +1 -1
  126. package/dist/web/assets/export-CXoWon32.js +2 -0
  127. package/dist/web/assets/{flowDiagram-I6XJVG4X-DB6Y_UDg.js → flowDiagram-I6XJVG4X-C5rQa2pq.js} +1 -1
  128. package/dist/web/assets/{ganttDiagram-6RSMTGT7-CHJeuoAY.js → ganttDiagram-6RSMTGT7-BrLjEsNJ.js} +1 -1
  129. package/dist/web/assets/{gitGraphDiagram-PVQCEYII-Dj85554Y.js → gitGraphDiagram-PVQCEYII-3DRR5VZj.js} +1 -1
  130. package/dist/web/assets/highlighted-body-OFNGDK62-Bdj5SJfv.js +1 -0
  131. package/dist/web/assets/index-2Vx5mHRn.js +1 -0
  132. package/dist/web/assets/index-B1UXw2C9.js +1 -0
  133. package/dist/web/assets/{index-C6qeLCPw.js → index-BJxtlf4P.js} +4 -4
  134. package/dist/web/assets/{index-DxUmR9aV.js → index-BY7jPurv.js} +1 -1
  135. package/dist/web/assets/index-Bq79v-Sa.js +1 -0
  136. package/dist/web/assets/index-BqD3iTIl.js +1 -0
  137. package/dist/web/assets/index-Br3AlBrQ.js +1 -0
  138. package/dist/web/assets/{index-DZMkZKhW.js → index-BvRBCpc6.js} +2 -2
  139. package/dist/web/assets/index-BxYCSNg_.js +3 -0
  140. package/dist/web/assets/{index-CJqIcuAl.js → index-C62wjCF_.js} +1 -1
  141. package/dist/web/assets/index-CBvwNH_H.js +1 -0
  142. package/dist/web/assets/{index-DRMjjql1.js → index-CG9e6lgq.js} +1 -1
  143. package/dist/web/assets/{index-C7mOS2T4.js → index-CPSWYh_R.js} +2 -2
  144. package/dist/web/assets/index-CS4xJLZV.js +1 -0
  145. package/dist/web/assets/index-CjvqtF2I.js +1 -0
  146. package/dist/web/assets/index-CprdjRRk.js +13 -0
  147. package/dist/web/assets/{index-bYtKyBMB.js → index-CypTtrCB.js} +1 -1
  148. package/dist/web/assets/{index-DqK8MfQN.js → index-DDJQGcUL.js} +1 -1
  149. package/dist/web/assets/index-DLWzxUOO.js +1 -0
  150. package/dist/web/assets/index-DQxkxZmn.js +7 -0
  151. package/dist/web/assets/index-DRo5Y_9p.js +1 -0
  152. package/dist/web/assets/index-De_LkTZx.js +1 -0
  153. package/dist/web/assets/{index-0tHq8zh2.js → index-DfUpwUTM.js} +2 -2
  154. package/dist/web/assets/{index-D--cw39y.js → index-Dkbz748K.js} +2 -2
  155. package/dist/web/assets/index-DmwFFSkV.js +1 -0
  156. package/dist/web/assets/index-DpcWEDhW.js +1 -0
  157. package/dist/web/assets/index-Dqq1RDP4.js +1 -0
  158. package/dist/web/assets/index-H1uMvIoa.css +1 -0
  159. package/dist/web/assets/index-ICHWJ2SM.js +1 -0
  160. package/dist/web/assets/index-O5fSd569.js +229 -0
  161. package/dist/web/assets/index-odjtqLLS.js +1 -0
  162. package/dist/web/assets/index-v_yAQ0Am.js +1 -0
  163. package/dist/web/assets/{infoDiagram-5YYISTIA-DeDPIdEH.js → infoDiagram-5YYISTIA-CCwV4Z0v.js} +1 -1
  164. package/dist/web/assets/{ishikawaDiagram-YF4QCWOH-ButuBiBW.js → ishikawaDiagram-YF4QCWOH-BwwZcGyZ.js} +1 -1
  165. package/dist/web/assets/{journeyDiagram-JHISSGLW-Dlbmqm-j.js → journeyDiagram-JHISSGLW-Dc6WqniQ.js} +1 -1
  166. package/dist/web/assets/{kanban-definition-UN3LZRKU-tlQK1cOz.js → kanban-definition-UN3LZRKU-DVUqULOS.js} +1 -1
  167. package/dist/web/assets/{linear-iXuNfUWp.js → linear-d6rWsNOU.js} +1 -1
  168. package/dist/web/assets/memoryAdvisor-DBQXJB1o.js +1 -0
  169. package/dist/web/assets/mermaid-GHXKKRXX-Ik6SkVDT.js +642 -0
  170. package/dist/web/assets/{mindmap-definition-RKZ34NQL-2qPv-mwT.js → mindmap-definition-RKZ34NQL-_JHAkhHL.js} +1 -1
  171. package/dist/web/assets/navViewState-DaCMIYWA.js +1 -0
  172. package/dist/web/assets/{pieDiagram-4H26LBE5-CrLe1C-O.js → pieDiagram-4H26LBE5-BlhlygGy.js} +1 -1
  173. package/dist/web/assets/{quadrantDiagram-W4KKPZXB-DfeIFxc0.js → quadrantDiagram-W4KKPZXB-jn6R_C0S.js} +1 -1
  174. package/dist/web/assets/{requirementDiagram-4Y6WPE33-BWtjdxie.js → requirementDiagram-4Y6WPE33-B9fXCHBr.js} +1 -1
  175. package/dist/web/assets/{sankeyDiagram-5OEKKPKP-B5TxJ6mb.js → sankeyDiagram-5OEKKPKP-fPJwIxkl.js} +1 -1
  176. package/dist/web/assets/{sequenceDiagram-3UESZ5HK-Cf92ZCl1.js → sequenceDiagram-3UESZ5HK-1v1DTNGt.js} +1 -1
  177. package/dist/web/assets/{spaces-DqMTtCXX.js → spaces-CvL2DRZM.js} +1 -1
  178. package/dist/web/assets/{stateDiagram-AJRCARHV-NR9I-Q4d.js → stateDiagram-AJRCARHV-CEc_PLov.js} +1 -1
  179. package/dist/web/assets/stateDiagram-v2-BHNVJYJU-iAMctzaT.js +1 -0
  180. package/dist/web/assets/theme-LRSmy8mD.js +1 -0
  181. package/dist/web/assets/{timeline-definition-PNZ67QCA-CBAOVMfm.js → timeline-definition-PNZ67QCA-CEjhuitj.js} +1 -1
  182. package/dist/web/assets/{vennDiagram-CIIHVFJN-C68x6TdS.js → vennDiagram-CIIHVFJN-CActt9h9.js} +1 -1
  183. package/dist/web/assets/{wardley-L42UT6IY-DuZZr5jm.js → wardley-L42UT6IY-Bp3q2izt.js} +1 -1
  184. package/dist/web/assets/{wardleyDiagram-YWT4CUSO-D6dVGtHd.js → wardleyDiagram-YWT4CUSO-C_zutiQ2.js} +1 -1
  185. package/dist/web/assets/{xychartDiagram-2RQKCTM6-DYLUhZX4.js → xychartDiagram-2RQKCTM6-CRafvv33.js} +1 -1
  186. package/dist/web/icons/apple-touch-icon.png +0 -0
  187. package/dist/web/icons/icon-192.png +0 -0
  188. package/dist/web/icons/icon-512.png +0 -0
  189. package/dist/web/icons/maskable-512.png +0 -0
  190. package/dist/web/index.html +12 -2
  191. package/dist/web/manifest.webmanifest +16 -0
  192. package/native/auth-native/prebuilds/linux-arm64/auth-native.node +0 -0
  193. package/native/auth-native/prebuilds/linux-x64/auth-native.node +0 -0
  194. package/native/auth-native/prebuilds/win32-arm64/auth-native.node +0 -0
  195. package/native/auth-native/prebuilds/win32-x64/auth-native.node +0 -0
  196. package/package.json +22 -3
  197. package/dist/web/assets/LifeMark-UBMVaTWr.js +0 -1
  198. package/dist/web/assets/NavScopeBoundary-BCryw-UG.js +0 -1
  199. package/dist/web/assets/channel-BJs5vJuh.js +0 -1
  200. package/dist/web/assets/classDiagram-4FO5ZUOK-BookeACB.js +0 -1
  201. package/dist/web/assets/classDiagram-v2-Q7XG4LA2-BookeACB.js +0 -1
  202. package/dist/web/assets/client-CXcrCawx.js +0 -3
  203. package/dist/web/assets/connection-C8nwzwXB.js +0 -1
  204. package/dist/web/assets/export-Bn8PqPg4.js +0 -2
  205. package/dist/web/assets/highlighted-body-OFNGDK62-DMgPHetp.js +0 -1
  206. package/dist/web/assets/index-7ySDqvaN.css +0 -1
  207. package/dist/web/assets/index-B0KPRi1U.js +0 -166
  208. package/dist/web/assets/index-B599VnpP.js +0 -1
  209. package/dist/web/assets/index-BFK-GypQ.js +0 -1
  210. package/dist/web/assets/index-BPX8gmpB.js +0 -1
  211. package/dist/web/assets/index-BSGYc1tb.js +0 -1
  212. package/dist/web/assets/index-BTt9Q5iv.js +0 -1
  213. package/dist/web/assets/index-BWzUsoY_.js +0 -1
  214. package/dist/web/assets/index-BYlSV3FO.js +0 -3
  215. package/dist/web/assets/index-BpXQ1q-u.js +0 -1
  216. package/dist/web/assets/index-BqPxpGUh.js +0 -1
  217. package/dist/web/assets/index-C8OFfbEs.js +0 -1
  218. package/dist/web/assets/index-CI7yuMGZ.js +0 -1
  219. package/dist/web/assets/index-CTRJmDep.js +0 -1
  220. package/dist/web/assets/index-CXGCKoId.js +0 -1
  221. package/dist/web/assets/index-CsY571EL.js +0 -13
  222. package/dist/web/assets/index-CwQG_9rB.js +0 -1
  223. package/dist/web/assets/index-D260jsUJ.js +0 -1
  224. package/dist/web/assets/index-DJjmEXx4.js +0 -1
  225. package/dist/web/assets/index-DUxOVxHS.js +0 -1
  226. package/dist/web/assets/index-GK8aa9pT.js +0 -7
  227. package/dist/web/assets/index-wxHFHTgD.js +0 -1
  228. package/dist/web/assets/mermaid-GHXKKRXX-sDJax95P.js +0 -624
  229. package/dist/web/assets/stateDiagram-v2-BHNVJYJU-BiegFWxE.js +0 -1
  230. package/dist/web/assets/theme-6OL1RXgY.js +0 -1
@@ -1 +0,0 @@
1
- import{Y as mn,Z as xn,_ as gn,$ as vn,a0 as wn,a1 as yn,a2 as B,a3 as Kt,a4 as Rt,a5 as ie,a6 as Vt,a7 as bn,a8 as Et,a9 as kn,aa as Nt,ab as At,ac as In,ad as Lt,ae as Ht,af as jn,j as s,r as u,d as gt,S as b,ag as Sn,ah as ht,ai as Mn,s as Cn,aj as Pn,ak as _n,al as Rn,am as En,an as Nn,b as ot,c as ct,B as An,ao as Ln,ap as Hn,aq as Fn}from"./index-B0KPRi1U.js";import{u as pe}from"./index-CJqIcuAl.js";import{A as Ee,R as Qe,a as qe,c as ft,K as Te,i as Tn,w as Dn}from"./client-CXcrCawx.js";function Ft(t){return{onFetch:(e,n)=>{const r=e.options,a=e.fetchOptions?.meta?.fetchMore?.direction,c=e.state.data?.pages||[],i=e.state.data?.pageParams||[];let m={pages:[],pageParams:[]},k=0;const L=async()=>{let C=!1;const _=p=>{vn(p,()=>e.signal,()=>C=!0)},T=mn(e.options,e.fetchOptions),y=async(p,l,d)=>{if(C)return Promise.reject();if(l==null&&p.pages.length)return Promise.resolve(p);const R=(()=>{const I={client:e.client,queryKey:e.queryKey,pageParam:l,direction:d?"backward":"forward",meta:e.options.meta};return _(I),I})(),P=await T(R),{maxPages:E}=e.options,x=d?xn:gn;return{pages:x(p.pages,P,E),pageParams:x(p.pageParams,l,E)}};if(a&&c.length){const p=a==="backward",l=p?zt:pt,d={pages:c,pageParams:i},w=l(r,d);m=await y(d,w,p)}else{const p=t??c.length;do{const l=k===0?i[0]??r.initialPageParam:pt(r,m);if(k>0&&l==null)break;m=await y(m,l),k++}while(k<p)}return m};e.options.persister?e.fetchFn=()=>e.options.persister?.(L,{client:e.client,queryKey:e.queryKey,meta:e.options.meta,signal:e.signal},n):e.fetchFn=L}}}function pt(t,{pages:e,pageParams:n}){const r=e.length-1;return e.length>0?t.getNextPageParam(e[r],e,n[r],n):void 0}function zt(t,{pages:e,pageParams:n}){return e.length>0?t.getPreviousPageParam?.(e[0],e,n[0],n):void 0}function Ns(t,e){return e?pt(t,e)!=null:!1}function As(t,e){return!e||!t.getPreviousPageParam?!1:zt(t,e)!=null}var On=class extends wn{#e;#t;#n;#r;constructor(t){super(),this.#e=t.client,this.mutationId=t.mutationId,this.#n=t.mutationCache,this.#t=[],this.state=t.state||Qn(),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.#r?.continue()??this.execute(this.state.variables)}async execute(t){const e=()=>{this.#s({type:"continue"})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#r=yn({fn:()=>this.options.mutationFn?this.options.mutationFn(t,n):Promise.reject(new Error("No mutationFn found")),onFail:(c,i)=>{this.#s({type:"failed",failureCount:c,error:i})},onPause:()=>{this.#s({type:"pause"})},onContinue:e,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)});const r=this.state.status==="pending",a=!this.#r.canStart();try{if(r)e();else{this.#s({type:"pending",variables:t,isPaused:a}),this.#n.config.onMutate&&await this.#n.config.onMutate(t,this,n);const i=await this.options.onMutate?.(t,n);i!==this.state.context&&this.#s({type:"pending",context:i,variables:t,isPaused:a})}const c=await this.#r.start();return await this.#n.config.onSuccess?.(c,t,this.state.context,this,n),await this.options.onSuccess?.(c,t,this.state.context,n),await this.#n.config.onSettled?.(c,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(c,null,t,this.state.context,n),this.#s({type:"success",data:c}),c}catch(c){try{await this.#n.config.onError?.(c,t,this.state.context,this,n)}catch(i){Promise.reject(i)}try{await this.options.onError?.(c,t,this.state.context,n)}catch(i){Promise.reject(i)}try{await this.#n.config.onSettled?.(void 0,c,this.state.variables,this.state.context,this,n)}catch(i){Promise.reject(i)}try{await this.options.onSettled?.(void 0,c,t,this.state.context,n)}catch(i){Promise.reject(i)}throw this.#s({type:"error",error:c}),c}finally{this.#n.runNext(this)}}#s(t){const e=n=>{switch(t.type){case"failed":return{...n,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...n,isPaused:!0};case"continue":return{...n,isPaused:!1};case"pending":return{...n,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{...n,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...n,data:void 0,error:t.error,failureCount:n.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=e(this.state),B.batch(()=>{this.#t.forEach(n=>{n.onMutationUpdate(t)}),this.#n.notify({mutation:this,type:"updated",action:t})})}};function Qn(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var qn=class extends Kt{constructor(t={}){super(),this.config=t,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(t,e,n){const r=new On({client:t,mutationCache:this,mutationId:++this.#n,options:t.defaultMutationOptions(e),state:n});return this.add(r),r}add(t){this.#e.add(t);const e=Fe(t);if(typeof e=="string"){const n=this.#t.get(e);n?n.push(t):this.#t.set(e,[t])}this.notify({type:"added",mutation:t})}remove(t){if(this.#e.delete(t)){const e=Fe(t);if(typeof e=="string"){const n=this.#t.get(e);if(n)if(n.length>1){const r=n.indexOf(t);r!==-1&&n.splice(r,1)}else n[0]===t&&this.#t.delete(e)}}this.notify({type:"removed",mutation:t})}canRun(t){const e=Fe(t);if(typeof e=="string"){const r=this.#t.get(e)?.find(a=>a.state.status==="pending");return!r||r===t}else return!0}runNext(t){const e=Fe(t);return typeof e=="string"?this.#t.get(e)?.find(r=>r!==t&&r.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(n=>Rt(e,n))}findAll(t={}){return this.getAll().filter(e=>Rt(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(ie))))}};function Fe(t){return t.options.scope?.id}var $n=class extends Kt{constructor(t={}){super(),this.config=t,this.#e=new Map}#e;build(t,e,n){const r=e.queryKey,a=e.queryHash??Vt(r,e);let c=this.get(a);return c||(c=new bn({client:t,queryKey:r,queryHash:a,options:t.defaultQueryOptions(e),state:n,defaultOptions:t.getQueryDefaults(r)}),this.add(c)),c}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(n=>Et(e,n))}findAll(t={}){const e=this.getAll();return Object.keys(t).length>0?e.filter(n=>Et(t,n)):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()})})}},Wn=class{#e;#t;#n;#r;#s;#i;#o;#c;constructor(t={}){this.#e=t.queryCache||new $n,this.#t=t.mutationCache||new qn,this.#n=t.defaultOptions||{},this.#r=new Map,this.#s=new Map,this.#i=0}mount(){this.#i++,this.#i===1&&(this.#o=kn.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#c=Nt.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#i--,this.#i===0&&(this.#o?.(),this.#o=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),n=this.#e.build(this,e),r=n.state.data;return r===void 0?this.fetchQuery(t):(t.revalidateIfStale&&n.isStaleByTime(At(e.staleTime,n))&&this.prefetchQuery(e),Promise.resolve(r))}getQueriesData(t){return this.#e.findAll(t).map(({queryKey:e,state:n})=>{const r=n.data;return[e,r]})}setQueryData(t,e,n){const r=this.defaultQueryOptions({queryKey:t}),c=this.#e.get(r.queryHash)?.state.data,i=In(e,c);if(i!==void 0)return this.#e.build(this,r).setData(i,{...n,manual:!0})}setQueriesData(t,e,n){return B.batch(()=>this.#e.findAll(t).map(({queryKey:r})=>[r,this.setQueryData(r,e,n)]))}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(n=>{e.remove(n)})})}resetQueries(t,e){const n=this.#e;return B.batch(()=>(n.findAll(t).forEach(r=>{r.reset()}),this.refetchQueries({type:"active",...t},e)))}cancelQueries(t,e={}){const n={revert:!0,...e},r=B.batch(()=>this.#e.findAll(t).map(a=>a.cancel(n)));return Promise.all(r).then(ie).catch(ie)}invalidateQueries(t,e={}){return B.batch(()=>(this.#e.findAll(t).forEach(n=>{n.invalidate()}),t?.refetchType==="none"?Promise.resolve():this.refetchQueries({...t,type:t?.refetchType??t?.type??"active"},e)))}refetchQueries(t,e={}){const n={...e,cancelRefetch:e.cancelRefetch??!0},r=B.batch(()=>this.#e.findAll(t).filter(a=>!a.isDisabled()&&!a.isStatic()).map(a=>{let c=a.fetch(void 0,n);return n.throwOnError||(c=c.catch(ie)),a.state.fetchStatus==="paused"?Promise.resolve():c}));return Promise.all(r).then(ie)}fetchQuery(t){const e=this.defaultQueryOptions(t);e.retry===void 0&&(e.retry=!1);const n=this.#e.build(this,e);return n.isStaleByTime(At(e.staleTime,n))?n.fetch(e):Promise.resolve(n.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(ie).catch(ie)}fetchInfiniteQuery(t){return t.behavior=Ft(t.pages),this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(ie).catch(ie)}ensureInfiniteQueryData(t){return t.behavior=Ft(t.pages),this.ensureQueryData(t)}resumePausedMutations(){return Nt.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.#r.set(Lt(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#r.values()],n={};return e.forEach(r=>{Ht(t,r.queryKey)&&Object.assign(n,r.defaultOptions)}),n}setMutationDefaults(t,e){this.#s.set(Lt(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#s.values()],n={};return e.forEach(r=>{Ht(t,r.mutationKey)&&Object.assign(n,r.defaultOptions)}),n}defaultQueryOptions(t){if(t._defaulted)return t;const e={...this.#n.queries,...this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=Vt(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===jn&&(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 mt="kiki.pinned";function Bt(t){return t.executing??t.main_turn_active}function Ne(t){return t.metadata[mt]===!0}function Ls(t,e){const n={...t.metadata};return e?n[mt]=!0:delete n[mt],n}function Hs(t){return!t}function Fs(t){const e=t.replaceAll("\\","/").replace(/\/+$/,""),n=e.split("/").filter(r=>r!=="");return n.length<=2?e:`…/${n.slice(-2).join("/")}`}async function Ts(t,e,n){n?.throwIfAborted();let r=await t();n?.throwIfAborted();const a=new Set(e?.pages[0]?.items.map(i=>i.id)),c=new Set;for(;a.size>0&&r.has_more&&!r.items.some(i=>a.has(i.id));){const i=r.next_cursor??r.items.at(-1)?.id;if(i===void 0||c.has(i))throw new Error("Session list cursor did not advance");c.add(i);const m=await t(i);n?.throwIfAborted(),r={...m,items:[...r.items,...m.items]}}return r}function Ds(t,e){if(t===void 0)return t;const n=t.pages[0];if(n===void 0||!e.has_more)return{pages:[e],pageParams:[void 0]};const r=new Set(e.items.map(m=>m.id)),a=n.items.findLastIndex(m=>r.has(m.id)),c=n.items.slice(a+1),i=c.length===0?e:{...e,items:[...e.items,...c],has_more:n.has_more,next_cursor:n.next_cursor??n.items.at(-1)?.id};return{...t,pages:[i,...t.pages.slice(1)]}}function Os(t,e){return t===void 0?t:{...t,pages:t.pages.map(n=>({...n,items:n.items.map(r=>r.id===e.id&&Date.parse(e.updated_at)>=Date.parse(r.updated_at)?e:r)}))}}function Un(t,e){return t===void 0||!Array.isArray(t.pages)?t:{...t,pages:t.pages.map(n=>({...n,items:n.items.map(r=>r.id===e.sessionId?{...r,busy:e.busy,executing:e.executing,main_turn_active:e.main_turn_active}:r)}))}}function Qs(t){const e=new Set;return(t?.pages??[]).flatMap(n=>n.items).filter(n=>e.has(n.id)?!1:(e.add(n.id),!0))}const qs=["updated-desc","created-desc","title"];function $s(t){return t==="updated-desc"||t==="updated-asc"||t==="created-desc"||t==="title"}function $e(t){const e=Date.parse(t);return Number.isFinite(e)?e:0}function Ae(t,e){return $e(e.updated_at)-$e(t.updated_at)}function Kn(t,e){return $e(t.updated_at)-$e(e.updated_at)}function Vn(t,e){return e.created_at.localeCompare(t.created_at)||Ae(t,e)}function zn(t,e){const n=t.title.trim(),r=e.title.trim();return n!==r?n.localeCompare(r,void 0,{sensitivity:"base",numeric:!0}):Ae(t,e)}function Ws(t,e,n){const r=t.filter(c=>Bt(c)===!0).sort((c,i)=>i.created_at.localeCompare(c.created_at)||c.id.localeCompare(i.id));if(r.length===0)return;const a=r.findIndex(c=>c.id===e);return a===-1?(n===1?r[0]:r.at(-1))?.id:r[(a+n+r.length)%r.length]?.id}function Us(t){return[...t].sort((e,n)=>{const r=Ne(e),a=Ne(n);return r!==a?r?-1:1:Ae(e,n)})}function Ks(t,e){const n=[],r=[];for(const a of t)(Ne(a)?n:r).push(a);return n.sort(Ae),e==="title"?r.sort(zn):e==="updated-asc"?r.sort(Kn):e==="created-desc"?r.sort(Vn):r.sort(Ae),[...n,...r]}const at=1440*60*1e3;function Bn(t){const e=new Date(t);return e.setHours(0,0,0,0),e.getTime()}function Vs(t,e,n={}){const a=["pinned","today","yesterday","week","month","older"].map(l=>({key:l,label:n[l]??l,items:[]})),[c,i,m,k,L,C]=a,_=Bn(e),T=_-at,y=_-6*at,p=_-29*at;for(const l of t){let d;if(Ne(l))d=c;else{const w=Date.parse(l.updated_at);Number.isFinite(w)?w>=_?d=i:w>=T?d=m:w>=y?d=k:w>=p?d=L:d=C:d=C}d.items.push(l)}return a.filter(l=>l.items.length>0)}const Tt="__none";function zs(t,e,n=c=>c.name,r="ungrouped",a){const c=a===void 0?void 0:{key:"pinned",label:a,items:[]},i=new Map(e.map((y,p)=>[y.id,p])),m=new Map;for(const y of e)m.set(y.id,n(y));const k=new Map,L=(y,p)=>{let l=k.get(y);return l===void 0&&(l={key:y,label:p,items:[]},k.set(y,l)),l};for(const y of t){if(c!==void 0&&Ne(y)){c.items.push(y);continue}const p=y.workspace_id;i.get(p)!==void 0?L(p,m.get(p)??p).items.push(y):L(Tt,r).items.push(y)}const C=[];for(const[y,p]of e.entries()){const l=k.get(p.id);l!==void 0&&(C[y]=l)}const _=k.get(Tt);_!==void 0&&C.push(_);const T=C.filter(y=>y!==void 0);return c!==void 0&&c.items.length>0?[c,...T]:T}function Gn(t){const e=t.pending_interaction;return e==="approval"||e==="question"?"needs-me":Bt(t)===!0?"running":"idle"}function Bs(t,e){const n=new Set(e.status),r=new Set(e.workspaces);return t.filter(a=>{const c=a.archived===!0;return!(e.archived==="hide"&&c||e.archived==="only"&&!c||r.size>0&&!r.has(a.workspace_id)||n.size>0&&!n.has(Gn(a)))})}function Gs(t){return t.status.length>0||t.workspaces.length>0||t.archived!=="hide"}const Gt={12:"h-3 w-3",14:"h-3.5 w-3.5",16:"h-4 w-4"},Yn={read:s.jsxs(s.Fragment,{children:[s.jsx("path",{d:"M4 2.5h5.2L12 5.3v8.2H4z"}),s.jsx("path",{d:"M9 2.5v3h3"})]}),search:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"7",cy:"7",r:"4.2"}),s.jsx("path",{d:"m10.2 10.2 3.3 3.3"})]}),edit:s.jsxs(s.Fragment,{children:[s.jsx("path",{d:"M10.4 2.9 13.1 5.6 6 12.7l-3.2.5.5-3.2z"}),s.jsx("path",{d:"m9.2 4.1 2.7 2.7"})]}),terminal:s.jsxs(s.Fragment,{children:[s.jsx("rect",{x:"2",y:"3",width:"12",height:"10",rx:"1.8"}),s.jsx("path",{d:"m5 6.5 2 1.5-2 1.5M8.5 10H11"})]}),web:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),s.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:s.jsxs(s.Fragment,{children:[s.jsx("rect",{x:"2.5",y:"2.5",width:"7.5",height:"7.5",rx:"1.6"}),s.jsx("path",{d:"M6 13.5h5.9a1.6 1.6 0 0 0 1.6-1.6V6"})]}),skill:s.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:s.jsx("path",{d:"M5.5 4.5h8M5.5 8h8M5.5 11.5h8M2.5 4.5h.01M2.5 8h.01M2.5 11.5h.01"}),task:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),s.jsx("path",{d:"M6.8 5.6v4.8L10.4 8z"})]}),goal:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),s.jsx("circle",{cx:"8",cy:"8",r:"2.4"})]}),memory:s.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:s.jsxs(s.Fragment,{children:[s.jsx("path",{d:"M5.2 11.3a4.3 4.3 0 1 1 5.6 0v1.2H5.2z"}),s.jsx("path",{d:"M6.3 14h3.4"})]}),system:s.jsxs(s.Fragment,{children:[s.jsx("rect",{x:"2.5",y:"2.5",width:"11",height:"11",rx:"2"}),s.jsx("path",{d:"M5.5 6.5h5M5.5 9.5h3"})]}),clock:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),s.jsx("path",{d:"M8 4.8V8l2.2 1.4"})]}),gate:s.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:s.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:s.jsxs(s.Fragment,{children:[s.jsx("path",{d:"M4 2.5h5.2L12 5.3v8.2H4z"}),s.jsx("path",{d:"M6.2 8.2h3.6M6.2 10.6h2.4"})]}),tool:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"8",cy:"8",r:"2.2"}),s.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:s.jsx("path",{d:"m3.5 8.4 2.9 2.9 6.1-6.6"}),cross:s.jsx("path",{d:"m4.3 4.3 7.4 7.4m0-7.4-7.4 7.4"}),dash:s.jsx("path",{d:"M4 8h8"}),warning:s.jsxs(s.Fragment,{children:[s.jsx("path",{d:"M8 2.6 13.8 13H2.2z"}),s.jsx("path",{d:"M8 6.6v2.8M8 11.3h.01"})]}),info:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"8",cy:"8",r:"5.9"}),s.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:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),s.jsx("path",{d:"M6.6 5.8v4.4M9.4 5.8v4.4"})]}),chevron:s.jsx("path",{d:"m6 3.8 4.2 4.2L6 12.2"}),close:s.jsx("path",{d:"m4.5 4.5 7 7m0-7-7 7"}),menu:s.jsx("path",{d:"M2.8 4.5h10.4M2.8 8h10.4M2.8 11.5h10.4"}),more:s.jsx("path",{d:"M3.5 8h.01M8 8h.01M12.5 8h.01",strokeWidth:2.2}),plus:s.jsx("path",{d:"M8 3v10M3 8h10"}),arrowRight:s.jsx("path",{d:"M3 8h10m-3.8-3.8L13 8l-3.8 3.8"}),arrowDown:s.jsx("path",{d:"M8 3v10m-3.8-3.8L8 13l3.8-3.8"}),external:s.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:s.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:s.jsxs(s.Fragment,{children:[s.jsx("rect",{x:"2",y:"3",width:"12",height:"10",rx:"1.6"}),s.jsx("path",{d:"M10 3v10"})]}),filter:s.jsx("path",{d:"M2.5 3.5h11l-4.2 5v4l-2.6 1v-5z"}),sliders:s.jsxs(s.Fragment,{children:[s.jsx("path",{d:"M2.5 4.5h7M13.5 4.5h0M2.5 8h2M7.5 8h6M2.5 11.5h6M12 11.5h1.5"}),s.jsx("circle",{cx:"11",cy:"4.5",r:"1.5"}),s.jsx("circle",{cx:"6",cy:"8",r:"1.5"}),s.jsx("circle",{cx:"10.5",cy:"11.5",r:"1.5"})]}),pin:s.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:s.jsxs(s.Fragment,{children:[s.jsx("rect",{x:"2",y:"2.5",width:"12",height:"11",rx:"1.8"}),s.jsx("path",{d:"M6 2.5v11M10 2.5v7"})]}),usage:s.jsx("path",{d:"M2.5 13.5h11M4.5 11V8M8 11V4.5M11.5 11V6.5"}),notes:s.jsxs(s.Fragment,{children:[s.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"}),s.jsx("path",{d:"M5.2 6.4h4.4M5.2 9h3"})]}),settings:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"8",cy:"8",r:"2.1"}),s.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:s.jsx("path",{d:"M13 8H3m3.8-3.8L3 8l3.8 3.8"}),arrowUp:s.jsx("path",{d:"M8 13V3M4.2 6.8 8 3l3.8 3.8"}),arrowUpRight:s.jsx("path",{d:"M4.5 11.5 11.5 4.5M5.5 4.5h6v6"}),expand:s.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:s.jsx("path",{d:"M13.5 6.5h-4v-4M2.5 9.5h4v4M9.5 6.5l4-4M6.5 9.5l-4 4"}),grip:s.jsx("path",{d:"M6 4h.01M10 4h.01M6 8h.01M10 8h.01M6 12h.01M10 12h.01",strokeWidth:2.2}),stop:s.jsx("rect",{x:"4.5",y:"4.5",width:"7",height:"7",rx:"1.2",fill:"currentColor"}),quote:s.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:s.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:s.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:s.jsx("circle",{cx:"8",cy:"8",r:"3",fill:"currentColor",stroke:"none"}),ring:s.jsx("circle",{cx:"8",cy:"8",r:"4.5"}),partial:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),s.jsx("path",{d:"M8 8V2.2A5.8 5.8 0 0 1 13.8 8z",fill:"currentColor"})]}),bell:s.jsxs(s.Fragment,{children:[s.jsx("path",{d:"M4.2 7a3.8 3.8 0 0 1 7.6 0v2.4l1 1.6H3.2l1-1.6z"}),s.jsx("path",{d:"M6.6 12.4a1.5 1.5 0 0 0 2.8 0"})]}),branch:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"4.5",cy:"3.8",r:"1.3"}),s.jsx("circle",{cx:"4.5",cy:"12.2",r:"1.3"}),s.jsx("circle",{cx:"11.5",cy:"6.2",r:"1.3"}),s.jsx("path",{d:"M4.5 5.1v5.8M11.5 7.5c0 2.2-2 2.9-7 3.4"})]}),eye:s.jsxs(s.Fragment,{children:[s.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"}),s.jsx("circle",{cx:"8",cy:"8",r:"2"})]}),eyeOff:s.jsxs(s.Fragment,{children:[s.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"}),s.jsx("path",{d:"M6.6 6.6a2 2 0 0 0 2.8 2.8M2.5 2.5l11 11"})]}),copy:s.jsxs(s.Fragment,{children:[s.jsx("rect",{x:"5.5",y:"5.5",width:"8",height:"8",rx:"1.6"}),s.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:s.jsx("path",{d:"M13 5V2.5m0 2.5h-2.5M13 5a5.2 5.2 0 1 0 .1 5.8"}),thread:s.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:s.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:s.jsxs(s.Fragment,{children:[s.jsx("rect",{x:"2.5",y:"2.5",width:"11",height:"11",rx:"3"}),s.jsx("circle",{cx:"8",cy:"6.8",r:"1.8"}),s.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:s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),s.jsx("polygon",{points:"10.8,5.2 6.8,7.2 5.2,10.8 9.2,8.8"})]})};function xt({name:t,size:e=14,className:n=""}){const r=/(^|\s)h-/.test(n)?"":Gt[e];return s.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 ${r} ${n}`.trim(),children:Yn[t]})}function Zn({open:t,size:e=12,className:n="text-ink-faint"}){return s.jsx(xt,{name:"chevron",size:e,className:`transition-transform duration-[var(--kiki-motion-quick)] ease-out motion-reduce:transition-none ${t?"rotate-90":""} ${n}`})}function Xn({label:t,size:e=14}){return s.jsxs("svg",{role:"img","aria-label":t,viewBox:"0 0 16 16",fill:"none",className:`spinner shrink-0 text-ink-soft ${Gt[e]}`,children:[s.jsx("circle",{cx:"8",cy:"8",r:"5.8",stroke:"currentColor",strokeOpacity:"0.22",strokeWidth:1.35}),s.jsx("path",{d:"M13.8 8A5.8 5.8 0 0 0 8 2.2",stroke:"currentColor",strokeWidth:1.35,strokeLinecap:"round"})]})}function Ys({state:t,labels:e,title:n}){switch(t){case"running":return s.jsx(Xn,{label:e.running});case"failed":return s.jsx("span",{role:"img","aria-label":e.failed,title:n,"data-outcome":"failed",className:"text-danger",children:s.jsx(xt,{name:"cross"})});case"stopped":return s.jsx("span",{role:"img","aria-label":e.stopped,title:n,"data-outcome":"stopped",className:"text-amber-rule",children:s.jsx(xt,{name:"dash"})});case"done":return s.jsx("span",{className:"sr-only",children:e.done})}}const Jn=10*6e4;function Zs(t,e=Date.now()){if(t.pending_interaction==="approval"||t.pending_interaction==="question")return"waiting";if((t.executing??t.main_turn_active)===!0)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 n=Date.parse(t.updated_at);if(Number.isFinite(n)&&e-n<Jn)return"done"}return"idle"}function Xs(t,e=8){return{"--kiki-i":Math.min(t,e)}}function es(){if(typeof document>"u")return"system";const t=document.documentElement.dataset.kikiMotion;return t==="reduce"||t==="full"?t:"system"}function Js(){const t=es();return t!=="system"?t==="reduce":typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}const Dt=new Map;function ts(t,e){const n=u.useRef(null);if(n.current===null||n.current.life!==e){const r=Dt.get(t);n.current={life:e,changed:e!==void 0&&r!==void 0&&r!==e}}return u.useEffect(()=>{e!==void 0&&Dt.set(t,e)},[t,e]),n.current.changed}function Le({size:t="md",life:e,echo:n}){const r=ts("wordmark",e),a=e==="idle"?void 0:e,c=t==="xl"?"text-[44px] sm:text-[56px]":t==="lg"?"text-4xl":"text-[22px]",i=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 s.jsxs("span",{className:"inline-flex items-baseline select-none","aria-label":"kiki",children:[s.jsx("span",{className:`font-display ${c} leading-none font-semibold tracking-tight text-ink`,style:{fontVariationSettings:t==="xl"?'"opsz" 60':'"opsz" 40'},children:"kiki"}),s.jsx("span",{className:`kiki-wordmark-echo inline-block ${t==="xl"?"ml-1":"ml-[3px]"}`,"data-echo":n===void 0?void 0:n===0?"arrive":n%2===0?"a":"b",children:s.jsx("span",{"data-life":a,"data-life-changed":r?"":void 0,className:`kiki-wordmark-dot block ${i} translate-y-[-1px] rounded-full bg-accent`})})]})}function er({className:t=""}){return s.jsx("span",{"aria-hidden":!0,className:`inline-block h-2.5 w-2.5 rounded-[3px] bg-accent ${t}`})}function Ot({onConnect:t,selectedProfile:e}){const{t:n}=pe(),r=gt(),[a,c]=u.useState([]),[i,m]=u.useState(""),[k,L]=u.useState(""),[C,_]=u.useState(""),[T,y]=u.useState("58627"),[p,l]=u.useState(""),[d,w]=u.useState("stable"),[R,P]=u.useState(null),[E,x]=u.useState(null),[I,Q]=u.useState(null),[F,q]=u.useState(null),[D,Ie]=u.useState(!1);u.useEffect(()=>{if(!r.connection.listSshProfiles)return;let f=!0;return r.connection.listSshProfiles().then(H=>{f&&c(H)},H=>{f&&(Ie(!0),q(String(H)))}),()=>{f=!1}},[r]);const Z=()=>{Q("list"),q(null),r.connection.listSshProfiles().then(f=>{c(f),Ie(!1)},f=>q(String(f))).finally(()=>Q(null))};if(!r.connection.listSshProfiles||!r.connection.saveSshProfile||!r.connection.removeSshProfile)return null;const Ue=f=>{f.preventDefault();const H=Number(T);if(!Number.isInteger(H)||H<1||H>65535||!/^[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$/.test(p.trim())){q(n("connect.sshNeedSetup"));return}const X=a.find(ce=>ce.id===R),me={id:X?.id??crypto.randomUUID(),label:i.trim(),target:X?.target.kind==="host"?{...X.target,hostname:k.trim()}:{kind:"alias",alias:k.trim()},identityFile:C.trim()||null,releaseChannel:d,remotePort:H,serverHomeId:p.trim().toLowerCase()};Q("save"),q(null),r.connection.saveSshProfile(me).then(ce=>{c(ce),m(""),L(""),_(""),y("58627"),l(""),w("stable"),P(null)},ce=>q(String(ce))).finally(()=>Q(null))},oe=f=>{const H=a.find(X=>X.id===f)??(e?.id===f?e:void 0);if(!H?.remotePort||!H.serverHomeId||E?.id!==f||!/^[A-Za-z0-9_-]{43}$/.test(E.value)){q(n("connect.sshNeedSetup"));return}Q(f),q(null),t(f,E.value).then(()=>x(null),X=>q(String(X))).finally(()=>Q(null))},Ke=f=>{Q(f),q(null),r.connection.removeSshProfile(f).then(H=>c(H),H=>q(String(H))).finally(()=>Q(null))};return s.jsxs("section",{className:"mt-5 border-t border-hairline pt-4","aria-label":n("connect.sshTitle"),children:[s.jsx("h2",{className:"text-[13px] font-semibold text-ink",children:n("connect.sshTitle")}),s.jsx("p",{className:"mt-1 text-[11px] leading-relaxed text-ink-soft",children:n("connect.sshHint")}),D?s.jsx("button",{type:"button",disabled:I!==null,onClick:Z,className:"mt-2 rounded-md border border-hairline-strong px-2 py-1 text-[11px] text-ink disabled:opacity-50",children:n("common.retry")}):null,(e&&!a.some(f=>f.id===e.id)?[e,...a]:a).map(f=>s.jsxs("div",{className:"mt-2 rounded-lg border border-hairline px-3 py-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"truncate text-[12px] font-medium text-ink",children:f.label}),s.jsxs("p",{className:"truncate font-mono text-[10px] text-ink-soft",children:[f.target.kind==="alias"?f.target.alias:f.target.hostname,f.remotePort?` · 127.0.0.1:${f.remotePort}`:""," · ",n(f.releaseChannel==="beta"?"st.about.beta":"st.about.stable")]})]}),s.jsx("button",{type:"button",disabled:I!==null,onClick:()=>{P(f.id),m(f.label),L(f.target.kind==="alias"?f.target.alias:f.target.hostname),_(f.identityFile??""),y(String(f.remotePort??58627)),l(f.serverHomeId??""),w(f.releaseChannel),q(null)},className:"rounded-md border border-hairline px-2 py-1 text-[11px] text-ink-soft disabled:opacity-50",children:n("goal.edit")}),s.jsx("button",{type:"button",disabled:I!==null,onClick:()=>Ke(f.id),className:"rounded-md border border-hairline px-2 py-1 text-[11px] text-ink-soft disabled:opacity-50",children:n("connect.sshRemove")})]}),s.jsxs("label",{className:"mt-2 block text-[11px] text-ink-soft",children:[n("connect.sshToken"),s.jsx("input",{type:"password",value:E?.id===f.id?E.value:"",onChange:H=>x({id:f.id,value:H.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"})]}),s.jsx("button",{type:"button",disabled:I!==null,onClick:()=>oe(f.id),className:"mt-2 rounded-md border border-hairline-strong px-2 py-1 text-[11px] text-ink disabled:opacity-50",children:n("connect.sshConnect")})]},f.id)),s.jsxs("form",{onSubmit:Ue,className:"mt-3 grid gap-2",children:[s.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("connect.sshLabel"),s.jsx("input",{value:i,onChange:f=>m(f.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"})]}),s.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("connect.sshAlias"),s.jsx("input",{value:k,onChange:f=>L(f.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"}),s.jsx("span",{className:"mt-1 block leading-relaxed",children:n("connect.sshAliasHint")})]}),s.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("connect.sshIdentity"),s.jsx("input",{value:C,onChange:f=>_(f.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"})]}),s.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("connect.sshPort"),s.jsx("input",{type:"number",min:1,max:65535,required:!0,value:T,onChange:f=>y(f.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"})]}),s.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("connect.sshHomeId"),s.jsx("input",{value:p,onChange:f=>l(f.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"})]}),s.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("st.about.channel"),s.jsxs("select",{value:d,onChange:f=>w(f.target.value),className:"mt-1 w-full rounded-md border border-hairline bg-paper px-2 py-1.5 text-[12px] text-ink",children:[s.jsx("option",{value:"stable",children:n("st.about.stable")}),s.jsx("option",{value:"beta",children:n("st.about.beta")})]}),s.jsx("span",{className:"mt-1 block leading-relaxed",children:n("connect.sshChannelHint")})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("button",{type:"submit",disabled:I!==null,className:"rounded-md border border-hairline-strong px-2 py-1.5 text-[12px] text-ink disabled:opacity-50",children:n("connect.sshAdd")}),R!==null?s.jsx("button",{type:"button",disabled:I!==null,onClick:()=>{P(null),m(""),L(""),_(""),y("58627"),l(""),w("stable")},className:"rounded-md border border-hairline px-2 py-1.5 text-[12px] text-ink-soft disabled:opacity-50",children:n("common.cancel")}):null]})]}),F!==null?s.jsx("p",{role:"alert",className:"mt-2 whitespace-pre-wrap text-[11px] text-danger",children:F}):null]})}function ns({problem:t,onRetry:e}){const{t:n}=pe(),[r,a]=u.useState(!1);return s.jsxs("div",{className:"px-7 pt-6 pb-7","data-web-link-problem":t,children:[s.jsx(Le,{size:"lg"}),s.jsx("p",{className:"mt-3 text-[14px] font-medium text-ink",children:n(t==="retargeted"?"connect.webLinkRetargeted":"connect.webLinkRefused")}),s.jsx("p",{className:"mt-1.5 max-w-[46ch] text-[13px] leading-relaxed text-ink-soft",children:n(t==="retargeted"?"connect.webLinkRetargetedBody":"connect.webLinkRefusedBody")}),e!==void 0?s.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:n("connect.webLinkRetry")}):null,s.jsx("button",{type:"button","data-web-link-connect":!0,"aria-expanded":r,onClick:()=>{a(c=>!c)},className:"mt-3 w-full rounded-md px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:text-ink",children:n(r?"connect.webLinkHideConnect":"connect.webLinkUseConnect")})]})}function ss({initial:t,connecting:e,error:n,onConnect:r,onBack:a,desktopBoot:c,desktopFailure:i,onRetryDesktop:m,onCancelDesktopBoot:k,onConnectSsh:L,onSwitchLocal:C,sshProfile:_,webLink:T,onRetryWebLink:y}){return C!==void 0?s.jsx(Re,{children:i!==null?s.jsxs(s.Fragment,{children:[s.jsx(Qt,{failure:i,onRetry:m,onSwitchLocal:C}),s.jsx("div",{className:"px-7 pb-7",children:s.jsx(Ot,{onConnect:L,selectedProfile:_})})]}):s.jsx(is,{onSwitchLocal:C})}):c!==null?s.jsx(Re,{children:s.jsx(os,{boot:c,onCancel:k})}):i!==null?s.jsxs(Re,{children:[s.jsx(Qt,{failure:i,onRetry:m}),s.jsx("div",{className:"px-7 pb-7",children:s.jsx(Ot,{onConnect:L})})]}):T!==void 0?s.jsx(Re,{children:s.jsx(ns,{problem:T,onRetry:y})}):s.jsx(Re,{children:s.jsx(cs,{initial:t,connecting:e,error:n,onConnect:r,onBack:a})})}function Re({children:t}){return s.jsx("div",{className:"flex h-full items-center justify-center overflow-y-auto bg-paper px-4 py-4",children:s.jsx("div",{className:"anim-enter w-full max-w-[420px]",children:s.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 rs(t){const[e,n]=u.useState(()=>Date.now());return u.useEffect(()=>{n(Date.now());const r=window.setInterval(()=>{n(Date.now())},1e3);return()=>{window.clearInterval(r)}},[t]),Math.max(0,Math.floor((e-t)/1e3))}function is({onSwitchLocal:t}){const{t:e}=pe();return s.jsxs("div",{className:"px-7 pt-6 pb-7",children:[s.jsx(Le,{size:"lg"}),s.jsx("p",{className:"mt-2 text-[13px] text-ink-soft",children:e("connect.sshChecking")}),s.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 os({boot:t,onCancel:e}){const{t:n}=pe(),r=rs(t.startedAtMs);return s.jsxs("div",{className:"px-7 pt-6 pb-7",children:[s.jsx(Le,{size:"lg"}),s.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-soft",children:t.stage==="spawning"?n("connect.desktopBootingSpawning"):n("connect.desktopBootingWaiting")}),s.jsx("p",{className:"mt-1 font-mono text-[12px] text-ink-faint","aria-live":"polite",children:n("connect.desktopElapsed",{seconds:r})}),s.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:n("connect.desktopCancel")})]})}function Qt({failure:t,onRetry:e,onSwitchLocal:n}){const{t:r}=pe(),[a,c]=u.useState(!1);u.useEffect(()=>{if(!a)return;const m=window.setTimeout(()=>{c(!1)},1500);return()=>{window.clearTimeout(m)}},[a]);const i=async()=>{try{await navigator.clipboard.writeText(t.message),c(!0)}catch{}};return s.jsxs("div",{className:"px-7 pt-6 pb-7",children:[s.jsx(Le,{size:"lg"}),s.jsx("p",{className:"mt-2 text-[13px] font-semibold text-danger",children:r(n===void 0?"connect.desktopFailedTitle":"connect.sshFailedTitle")}),s.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?s.jsxs("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-soft",children:[r("connect.desktopLogPathLabel")," ",s.jsx("span",{className:"font-mono",children:t.logPath})]}):null,s.jsxs("div",{className:"mt-4 flex gap-2",children:[s.jsx("button",{type:"button",onClick:n??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:r(n===void 0?"connect.desktopRetry":"connect.switchLocal")}),s.jsx("button",{type:"button",onClick:()=>{i()},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:r(a?"connect.desktopCopied":"connect.desktopCopyDiagnostics")})]})]})}function cs({initial:t,connecting:e,error:n,onConnect:r,onBack:a}){const c=gt(),{t:i}=pe(),[m,k]=u.useState(t.url),[L,C]=u.useState(t.token),[_,T]=u.useState(!1),[y,p]=u.useState(t.url!==""||t.token!==""||n!==null);u.useEffect(()=>{n!==null&&p(!0)},[n]);const[l,d]=u.useState(!1),[w,R]=u.useState(null),P=x=>{x.preventDefault(),r({url:m.trim(),token:L.trim()})},E=async()=>{d(!0),R(null);try{const x=await c.connection.discover();if(x===null){R(i("connect.noneFound"));return}r(x.config,x.persist)}catch(x){R(c.kind==="tauri"?i("connect.desktopStartFailed",{detail:x instanceof Error?x.message:String(x)}):i("connect.detectNeedsDev"))}finally{d(!1)}};return s.jsxs("div",{className:"px-7 pt-6 pb-7",children:[s.jsx(Le,{size:"lg"}),s.jsx("p",{className:"mt-3 font-display text-[18px] leading-snug text-ink-soft",children:i("connect.tagline")}),s.jsxs("form",{onSubmit:P,className:"mt-6",children:[s.jsx("button",{type:"button",onClick:()=>{E()},disabled:l||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:i(l?"connect.detecting":"connect.detect")}),w!==null?s.jsx("p",{role:"status",className:"mt-2 text-[13px] leading-relaxed text-ink-soft",children:w}):null,s.jsxs("button",{type:"button","aria-expanded":y,"aria-controls":"connect-manual",onClick:()=>{p(x=>!x)},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:[s.jsx(Zn,{open:y,className:"text-current"}),i("connect.otherMachine")]}),s.jsxs("div",{id:"connect-manual",hidden:!y,className:"mt-3",children:[s.jsx("label",{htmlFor:"connect-server-url",className:"mb-1 block text-[12px] font-medium text-ink-soft",children:i("connect.serverUrl")}),s.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:i("connect.urlPlaceholder",{target:"http://127.0.0.1:58627"}),value:m,onChange:x=>{k(x.target.value)},spellCheck:!1}),s.jsxs("label",{htmlFor:"connect-token",className:"mb-1 flex items-baseline justify-between gap-2 text-[12px] font-medium text-ink-soft",children:[i("connect.accessToken"),s.jsx("span",{title:i("connect.accessTokenHelp"),className:"cursor-help text-[12px] font-normal text-ink-faint underline decoration-dotted underline-offset-2",children:i("connect.accessTokenWhere")})]}),s.jsxs("div",{className:"mb-5 flex gap-2",children:[s.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:L,onChange:x=>{C(x.target.value)},spellCheck:!1,type:_?"text":"password"}),s.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":`${i(_?"st.providers.hideKey":"st.providers.showKey")} ${i("connect.token")}`,onClick:()=>{T(x=>!x)},children:i(_?"st.providers.hideKey":"st.providers.showKey")})]}),s.jsx("p",{id:"connect-token-help",className:"sr-only",children:i("connect.accessTokenHelp")}),n!==null?s.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:n}):null,s.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:i(e?"connect.connecting":"connect.connect")})]}),a!==void 0?s.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:i("connect.back")}):null]})]})}function as(t,e){const[n,r]=t.queryKey;return n==="usage-v2"||n==="usage-v2-strip"||n==="usage-v2-strip-session"||n==="sessions"?!0:n==="session"?e===void 0||r===e:n!=="agentCapabilities"?!1:e===void 0||typeof r=="object"&&r!==null&&"session_id"in r&&r.session_id===e}function qt(t,e){let n=!0;const r=c=>{const i={predicate:m=>as(m,c)};e.cancelQueries(i).then(()=>{if(n)return e.invalidateQueries(i)})},a=t.events.on("usage.settled",({sessionId:c})=>{n&&r(c)});return a.ready.then(()=>{n&&r()}).catch(()=>{}),()=>{n=!1,a.dispose()}}const ls=[["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 us(t){await Promise.all(ls.map(e=>t.invalidateQueries({queryKey:[...e]})))}function $t(t,e){let n=!0;const r=()=>{us(e).catch(()=>{})},a=t.events.on("plugins.changed",()=>{n&&r()});return a.ready.then(()=>{n&&r()}).catch(()=>{}),()=>{n=!1,a.dispose()}}const vt="kiki.connection",ds=["server","url","token"];function hs(t){const e=new URLSearchParams(t.search);for(const i of ds)e.delete(i);const n=e.toString(),r=t.hash.startsWith("#")?t.hash.slice(1).split("&"):[],a=r.filter(i=>!i.startsWith("token=")&&!i.startsWith("access=")),c=a.length===r.length?t.hash:a.length===0?"":`#${a.join("&")}`;return`${t.pathname}${n===""?"":`?${n}`}${c}`}function fs(t=window.location){const e=new URLSearchParams(t.search),n=e.get("server")??e.get("url"),r=e.get("token");if(n!==null||r!==null)return{url:n??"",token:r??""};const a=/(?:^|#|&)token=([^&]+)/.exec(t.hash);return a!==null?{url:"",token:decodeURIComponent(a[1]??"")}:null}function ps(t){try{const e=(t??localStorage).getItem(vt);if(e===null)return null;const n=JSON.parse(e);return typeof n.url!="string"||typeof n.token!="string"?null:{url:n.url,token:n.token}}catch{return null}}function ms(t,e){try{return(e??localStorage).setItem(vt,JSON.stringify(t)),!0}catch{return!1}}function xs(t){try{return(t??localStorage).removeItem(vt),!0}catch{return!1}}function gs(t){return t.desktop!==void 0?{config:t.desktop,persist:!1,source:"desktop"}:t.deepLink!==void 0&&t.deepLink!==null?{config:t.deepLink,persist:vs(t.deepLink.url),source:"deep-link"}:t.stored!==void 0&&t.stored!==null?{config:t.stored,persist:!0,source:"stored"}:null}function vs(t){if(t==="")return!0;try{const e=new URL(t);if(e.protocol!=="http:"&&e.protocol!=="https:")return!1;const n=e.hostname.toLowerCase();return n==="localhost"||n.endsWith(".localhost")||n==="[::1]"||n==="::1"?!0:/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(n)}catch{return!1}}function lt(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(n=>typeof n=="string"):[],logPath:typeof e.logPath=="string"?e.logPath:null}}return{message:t instanceof Error?t.message:String(t),stderrTail:[],logPath:null}}async function tr(t,e,n){n.throwIfAborted();const r=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(r))throw new b("scope-invalid");if(t.openRemoteSpace===void 0)throw new b("scope-invalid");await t.openRemoteSpace(r),n.throwIfAborted()}async function ut(t,e,n){n.throwIfAborted();const r=new URL(e,"http://example.test").pathname,a=/^\/s\/([^/]+)/.exec(r)?.[1],c=/^\/(?:rooms|r)\/([^/]+)$/.exec(r)?.[1];try{if(a!==void 0){await t.getSession(decodeURIComponent(a)),n.throwIfAborted();const i=/^\/s\/[^/]+\/agent\/([^/]+)$/.exec(r)?.[1];if(i!==void 0&&decodeURIComponent(i)!=="main"){const m=await t.klient.session(decodeURIComponent(a)).agents();if(!Object.hasOwn(m,decodeURIComponent(i)))throw new b("target-missing")}}if(c!==void 0){const i=t.klient.rest;if(i===void 0)throw new b("offline");if(await i.rooms.get(decodeURIComponent(c))===void 0)throw new b("target-missing")}}catch(i){throw a!==void 0&&i instanceof Ee&&Tn(i.message)?new b("target-missing"):c!==void 0&&i instanceof Qe&&i.code===qe.REQUEST_INVALID&&i.message===`Room '${decodeURIComponent(c)}' does not exist.`?new b("target-missing"):(i instanceof Ee||i instanceof Qe)&&i.code===qe.UNAUTHORIZED?new b("auth-required"):i}n.throwIfAborted()}function ws(t){return{async prepare(e,n,r){n.throwIfAborted();const a=t.active(),c=a.scope.homeId!==e.homeId;if(!c&&e.scopeId===a.scope.scopeId&&r===void 0){let p;try{p=await a.client.meta()}catch(d){throw(d instanceof Ee||d instanceof Qe)&&d.code===qe.UNAUTHORIZED?new b("auth-required"):d}n.throwIfAborted();const l=e.serverHomeId??a.scope.serverHomeId;if(l!==void 0&&l!==p.server_home_id||e.connectionRef!==void 0&&e.connectionRef!==a.scope.connectionRef)throw new b("identity-mismatch");return{scope:{...a.scope,serverHomeId:p.server_home_id},validate:(d,w)=>ut(a.client,d,w),commit:()=>{n.throwIfAborted()},dispose:()=>{}}}let i,m,k=!1,L=!1,C=a.scope.homeId,_=!1,T;t.preparing?.(!0);const y=async()=>{try{if(k&&m!==void 0&&(k=!1,await m.klient.close()),T!==void 0){const p=T;T=void 0,await t.host.connection.disconnectSshProfile?.(p.id,p.tunnelId)}L&&(L=!1,await t.host.prepareSpace?.(C))}finally{t.preparing?.(!1)}};try{if(e.scopeId.startsWith("remote:")||e.homeId.startsWith("remote:")){const d=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(d))throw new b("scope-invalid");const w=t.control?.()??t.local();if(w===null||w.selection.source==="remote"||w.selection.source==="ssh")throw new b("offline");const R=w.client.klient.rest?.connections;if(R===void 0)throw new b("offline");const P=await R.list();n.throwIfAborted();const E=P.find(Q=>Q.id===d);if(E===void 0)throw new b("scope-invalid");if(E.enabled!==!0||E.state==="disabled"||E.target.protocol!==Sn)throw new b("identity-mismatch");i={config:w.selection.config,persist:!1,source:"remote",scopeId:e.scopeId,connectionId:E.id,serverHomeId:E.target.homeId},m=t.createClient?.(i)??ft({endpoint:i.config.url,token:i.config.token,connectionId:E.id}),k=!0;const x=await m.meta();if(n.throwIfAborted(),x.server_home_id!==E.target.homeId||e.serverHomeId!==void 0&&e.serverHomeId!==x.server_home_id||e.connectionRef!==void 0&&e.connectionRef!==E.id)throw new b("identity-mismatch");const I=m;return{scope:{...e,serverHomeId:x.server_home_id,connectionRef:E.id},validate:(Q,F)=>ut(I,Q,F),commit:()=>{n.throwIfAborted(),t.commit(i,I,x),t.reload(),k=!1,t.preparing?.(!1)},dispose:y}}if(e.scopeId.startsWith("ssh:")&&!r&&!e.connectionRef)throw new b("auth-required");if(c&&a.selection.source==="remote"&&(C=t.host.activeSpace===void 0?"main":ht(await t.host.activeSpace())?.homeId??"main",n.throwIfAborted(),_=e.homeId===C&&(e.scopeId==="local"||e.scopeId.startsWith("direct:"))),c&&!_){if(!t.host.prepareSpace)throw new b("scope-invalid");const d=await t.host.prepareSpace(e.homeId);if(L=!0,n.throwIfAborted(),d.homeId!==e.homeId)throw new b("identity-mismatch")}if(e.scopeId.startsWith("ssh:")){const d=e.scopeId.slice(4),w=await t.host.connection.listSshProfiles?.();n.throwIfAborted();const R=w?.find(x=>x.id===d);if(R===void 0)throw new b("scope-invalid");if(!R.serverHomeId||!R.remotePort)throw new b("scope-invalid");let P;if(r!==void 0){if(!/^[A-Za-z0-9_-]{43}$/.test(r))throw new b("auth-required");if(!t.host.connection.prepareSshProfile)throw new b("scope-invalid");try{P=await t.host.connection.prepareSshProfile(d,r)}catch(x){if(x instanceof b)throw x;const I=x instanceof Error?x.message:String(x);throw I.includes("rejected the bearer token")?new b("auth-required"):I.includes("home identity")||I.includes("authentication; SSH connection blocked")||I.includes("build identity")||I.includes("release channel")?new b("identity-mismatch"):x}P.tunnelId&&(T={id:d,tunnelId:P.tunnelId})}else{if(!e.connectionRef||!t.host.connection.resumeScopeConnection)throw new b("auth-required");try{P=(await t.host.connection.resumeScopeConnection(e.homeId,d,e.connectionRef)).connection}catch(x){const I=x instanceof Error?x.message:String(x);throw new b(I.includes("offline")?"offline":I.includes("identity changed")?"identity-mismatch":"auth-required")}if(P.tunnelId!==e.connectionRef)throw new b("identity-mismatch")}n.throwIfAborted();let E;try{E=new URL(P.config.url)}catch{throw new b("identity-mismatch")}if(E.protocol!=="http:"||E.hostname!=="127.0.0.1"||E.username||E.password||!E.port||!P.tunnelId||r!==void 0&&P.config.token!==r||P.serverHomeId!==R.serverHomeId)throw new b("identity-mismatch");i={config:P.config,persist:!1,source:"ssh",scopeId:e.scopeId,profile:R,tunnelId:P.tunnelId,serverHomeId:P.serverHomeId,serverInstanceId:P.serverInstanceId,serverVersion:P.serverVersion,buildId:P.buildId,buildChannel:P.buildChannel}}else if(e.scopeId==="local"||_&&e.scopeId.startsWith("direct:"))if(c&&!_){const d=await t.host.connection.discover();if(d===null)throw new b("offline");i={config:d.config,persist:!1,source:"desktop",scopeId:"local"}}else{const d=_?t.control?.()??t.local():t.local();if(d===null)throw new b("offline");if(e.scopeId.startsWith("direct:")&&e.scopeId!==(d.selection.scopeId??`direct:${d.selection.config.url.trim().replace(/\/+$/,"")}`))throw new b("scope-invalid");i=d.selection,m=d.client}else if(e.homeId===a.scope.homeId&&e.scopeId===a.scope.scopeId)i=a.selection,m=a.client;else throw new b("scope-invalid");n.throwIfAborted(),m===void 0&&(m=t.createClient?.(i)??new Te({baseUrl:i.config.url,token:i.config.token}),k=!0);const p=await m.meta();if(n.throwIfAborted(),e.serverHomeId!==void 0&&p.server_home_id!==e.serverHomeId)throw new b("identity-mismatch");if(i.source==="ssh"&&(p.server_home_id!==i.serverHomeId||p.server_id!==i.serverInstanceId||p.server_version!==i.serverVersion||p.dangerous_bypass_auth!==!1||(p.build_id??null)!==i.buildId||(p.build_channel??null)!==i.buildChannel))throw new b("identity-mismatch");const l=m;return{scope:{...e,serverHomeId:p.server_home_id,connectionRef:i.source==="ssh"?i.tunnelId:void 0},validate:(d,w)=>ut(l,d,w),commit:async()=>{if(n.throwIfAborted(),i.source==="ssh"&&i.profile&&i.tunnelId){if(!t.host.connection.commitScopeConnection)throw new b("scope-invalid");await t.host.connection.commitScopeConnection(e.homeId,i.profile.id,i.tunnelId,c),n.throwIfAborted()}c?(k&&await l.klient.close(),n.throwIfAborted(),t.reload()):t.commit(i,l,p),k=!1,L=!1,T=void 0,t.preparing?.(!1)},dispose:y}}catch(p){throw await y(),(p instanceof Ee||p instanceof Qe)&&p.code===qe.UNAUTHORIZED?new b("auth-required"):p}}}}function dt(){const t=`${window.location.pathname}${window.location.search}${window.location.hash}`,e=hs(window.location);if(e!==t)try{window.history.replaceState(window.history.state,"",e)}catch{}}function Yt(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 De(t,e){t.invalidateQueries({queryKey:["sessions"]}),t.invalidateQueries({queryKey:["rooms"]}),t.invalidateQueries({queryKey:["activity-prompts",e]}),t.invalidateQueries({queryKey:["activity-tasks",e]})}const Zt=3,wt=64*1024*1024,Xt=wt/2,Jt=5*6e4,en=4;function Oe(t){const e=t.getState();return e.busy||e.pendingInteraction!=="none"||e.tasks.some(n=>n.status==="running")}function ys(t){const e=t.getState();return e.loaded&&e.loadError===void 0&&!(e.resyncFailed&&e.resyncError?.retryable===!1)}class tn{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??Zt,maxBytes:e.maxBytes??wt,maxEntryBytes:e.maxEntryBytes??Xt,ttlMs:e.ttlMs??Jt,maxLiveParked:e.maxLiveParked??en},this.now=e.now??Date.now,this.setTimer=e.setTimer??((n,r)=>setTimeout(n,r)),this.clearTimer=e.clearTimer??(n=>{clearTimeout(n)})}acquire(e,n,r){let a=this.retained.get(n);a===void 0&&(a=new Map,this.retained.set(n,a));let c=a.get(e);if(c===void 0){const k=r();if(k.sessionId!==e||this.controllers.has(k))throw new Error("Controller factory must return a fresh controller for the requested session");c={controller:k,ready:k.open(),references:1,sessions:a,sessionId:e},a.set(e,c),this.add(k)}else c.parked!==void 0?(this.unpark(c),c.references=1,c.ready=c.controller.resume(),this.add(c.controller)):c.references+=1;const i=c;let m=!1;return{controller:i.controller,ready:i.ready,release:()=>{m||(m=!0,i.references-=1,!(i.references>0)&&(this.park(i,n)||this.dispose(i)))}}}get parkedCount(){return this.parked.size}hasRetained(e,n){return e===""?!1:this.retained.get(n)?.has(e)===!0}evictScope(e){for(const[n,r]of Array.from(this.parked))r===e&&this.dispose(n)}clearParked(){for(const e of Array.from(this.parked.keys()))this.dispose(e)}park(e,n){const{controller:r}=e;if(typeof r.getState!="function"||typeof r.suspend!="function"||!ys(r))return!1;const a=r.residentBytes();if(a>this.limits.maxEntryBytes)return!1;const c=r.subscribe(()=>{this.onParkedChange(e)});return e.parked={at:this.now(),bytes:a,unsubscribe:c},this.parked.set(e,n),Oe(r)||r.suspend(),this.delete(r),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 n=e.parked;if(n===void 0||e.controller.suspended||Oe(e.controller))return;const r=this.parked.get(e)??{};e.parked={...n,at:this.now()},this.parked.delete(e),this.parked.set(e,r),e.controller.suspend(),this.enforceLimits()}isLiveProtected(e){return!e.controller.suspended&&Oe(e.controller)}enforceLimits(){const e=this.now(),n=Array.from(this.parked.keys()).filter(i=>this.isLiveProtected(i));for(const i of n.slice(0,Math.max(0,n.length-this.limits.maxLiveParked)))i.controller.suspend();for(const i of Array.from(this.parked.keys()))!this.isLiveProtected(i)&&e-(i.parked?.at??e)>=this.limits.ttlMs&&this.dispose(i);const r=()=>Array.from(this.parked.keys()).filter(i=>!this.isLiveProtected(i));let a=r(),c=a.reduce((i,m)=>i+(m.parked?.bytes??0),0);for(;a.length>0&&(a.length>this.limits.maxParked||c>this.limits.maxBytes);){const i=a[0];c-=i.parked?.bytes??0,this.dispose(i),a=r()}this.scheduleTtl()}scheduleTtl(){this.ttlTimer!==null&&(this.clearTimer(this.ttlTimer),this.ttlTimer=null);let e=1/0;for(const n of this.parked.keys())this.isLiveProtected(n)||(e=Math.min(e,(n.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 We=u.createContext(null),bs=15e3;let Wt=0;function nn(t=Date.now()){return Wt+=1,`gui-${t.toString(36)}-${Wt.toString(36)}`}function fe(t){return t?.source==="desktop"}function Ut(t,e){return t.url.trim().replace(/\/+$/,"")===e.url.trim().replace(/\/+$/,"")&&t.token.trim()===e.token.trim()}function ks(t,e){for(const n of["server_id","server_home_id","current_space_id","dangerous_bypass_auth"])if(t[n]!==void 0&&e[n]!==void 0&&t[n]!==e[n])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 Is({children:t}){const e=gt(),n=e.kind==="tauri",r=Hn(),{locale:a,t:c}=pe(),i=u.useRef(new Map),m=Mn(),k=u.useRef(m?.scopeId.startsWith("remote:")?m:null),C=u.useSyncExternalStore(Cn,Pn,_n).requestTimeoutSeconds*1e3,[_,T]=u.useState(()=>Rn()),[y,p]=u.useState(_.kind==="failed"?En(_.reason):void 0),[l,d]=u.useState(()=>n||r?null:_.kind==="signed-in"?{config:{url:"",token:""},persist:!1,source:"web-cookie"}:(Nn(o=>{!o||S.current!==null||($.current+=1,d({config:{url:"",token:""},persist:!1,source:"web-cookie"}))}),gs({deepLink:fs(),stored:ps()}))),w=l?.config??null,R=l?.scopeId??(n?"local":`direct:${w?.url.trim().replace(/\/+$/,"")??""}`),P=l?.source==="remote"?l.connectionId??null:null,E=l?.source??null,x=P===null?ot()?.homeId??"main":`remote:${P}`;let I=i.current.get(R);I===void 0&&(I=new Wn({defaultOptions:{queries:{retry:1,staleTime:0,refetchOnWindowFocus:!1}}}),i.current.set(R,I));const[Q,F]=u.useState(null),[q,D]=u.useState(null),[Ie,Z]=u.useState(()=>n?{stage:"spawning",startedAtMs:Date.now()}:null),[Ue,oe]=u.useState(null),[Ke,f]=u.useState(0),H=u.useRef(!1),[X,me]=u.useState("closed"),ce=u.useRef("closed"),te=u.useRef(null),G=u.useRef(null),Ve=u.useRef(new tn),$=u.useRef(0),xe=u.useRef(0),ae=u.useRef(null),[he,sn]=u.useState(null),ne=u.useCallback(o=>{ae.current=o,sn(o)},[]),ze=u.useRef(null),bt=u.useRef(new Map),je=u.useRef(null),Be=u.useRef(!1),rn=u.useRef({promise:null,consumed:!1}),S=u.useRef(l);S.current=l;const on=u.useRef(nn()),le=u.useRef(void 0);u.useEffect(()=>(e.connection.setWorkspaceScope?.(l?.source==="ssh"?"ssh":"local"),()=>e.connection.setWorkspaceScope?.("local")),[e,l?.source]),u.useEffect(()=>{if(!r)return;let o=!1;return e.connection.discover().then(h=>{o||h!==null&&($.current+=1,d({config:h.config,persist:h.persist,source:"local-detection"}))},h=>{o||D({kind:"raw",text:h instanceof Error?h.message:String(h)})}),()=>{o=!0}},[e,r]),u.useEffect(()=>{if(e.kind!=="tauri")return;let o=!1,h=0;H.current=!1;let g;const v=()=>{const j=te.current;return j!==null&&j.selection===S.current&&j.client===de.current&&j.homeId===(ot()?.homeId??"main")&&j.scopeId===(S.current?.scopeId??"local")?j:null},N=j=>{const W=v();return W===null?!1:(G.current={client:W.client,phase:"failed"},me("closed"),Z(null),oe(lt(j)),!0)};let M=!1;const O=j=>{if(o||M&&j===void 0||H.current)return;M=!0;const W=++h,st=v(),ee=st!==null&&(j===void 0||Ut(st.selection.config,j))?st:null;if(ee===null){if(fe(S.current)){const U=te.current;U!==null&&U.selection===S.current&&i.current.get(U.scopeId)?.clear(),$.current+=1,S.current=null,d(null),F(null),te.current=null,G.current=null}ne(null)}else G.current={client:ee.client,phase:"checking"},me("connecting");S.current===null&&Z(U=>({stage:"waiting",startedAtMs:U?.startedAtMs??Date.now()}));const hn=S.current,fn=$.current,He=()=>!o&&!H.current&&W===h&&S.current===hn&&$.current===fn,ke=rn.current;j===void 0&&(ke.promise??=(e.connection.takeScopeConnection?.()??Promise.resolve(null)).then(U=>{if(U===null)return null;const K=U.connection;return{config:K.config,persist:!1,source:"ssh",scopeId:`ssh:${U.profile.id}`,profile:U.profile,tunnelId:K.tunnelId,serverHomeId:K.serverHomeId,serverInstanceId:K.serverInstanceId,serverVersion:K.serverVersion,buildId:K.buildId,buildChannel:K.buildChannel}}).catch(()=>null));const pn=j===void 0?e.connection.discover():Promise.resolve({config:j,persist:!1});Promise.all([pn,ke.consumed||j!==void 0?Promise.resolve(null):ke.promise]).then(async([U,K])=>{if(o||H.current||W!==h||K===null&&!He())return;Z(null),oe(null);const Pt=!fe(S.current)&&S.current!==null;if(U===null){if(N(new Error("Desktop connection discovery returned no verified endpoint."))||(ne(null),Pt))return;D({kind:"key",key:"conn.desktopNoServer"});return}if(ee!==null&&K===null&&Ut(ee.selection.config,U.config)){const it=await ee.client.meta();if(!He()||v()!==ee)return;const _t=ks(ee.meta,it);if(_t==="unknown"){N(new Error("The desktop backend identity could not be verified."));return}if(_t==="same"){te.current={...ee,meta:it},G.current=null,F(it),D(null),me(ce.current);return}}const rt={config:U.config,persist:!1,source:"desktop",scopeId:"local"};if(ne(rt),K!==null&&!ke.consumed){ke.consumed=!0,ke.promise=Promise.resolve(null),S.current=K,K.profile&&K.tunnelId&&(je.current={id:K.profile.id,tunnelId:K.tunnelId}),$.current+=1,d(K);return}Pt||!He()||(ee!==null&&i.current.get(ee.scopeId)?.clear(),te.current=null,G.current=null,F(null),D(null),$.current+=1,S.current=rt,d(rt))}).catch(U=>{!He()||N(U)||(ne(null),!(!fe(S.current)&&S.current!==null)&&($.current+=1,Z(null),F(null),S.current=null,d(null),oe(lt(U))))}).finally(()=>{W===h&&(M=!1)})};let re;le.current=void 0;const V=()=>{re===void 0&&(re=setTimeout(()=>{if(re=void 0,o)return;const j=S.current?.source;!fe(S.current)&&j!=="ssh"&&j!=="remote"||Be.current||O()},250))};le.current=V;const J=()=>S.current?.source==="ssh"||S.current?.source==="remote",nt=()=>S.current===null||fe(S.current);return e.connection.onBackendStage(j=>{if(!(o||H.current||Be.current)){if(j==="waiting"){if(!M||!nt())return;Z(W=>({stage:"waiting",startedAtMs:W?.startedAtMs??Date.now()}));return}if(j!==null&&typeof j=="object"&&"stage"in j&&j.stage==="ready"&&"connection"in j){if(!nt()&&!J()||M&&v()===null)return;const W=j.connection;if(W===null||typeof W!="object"||!("url"in W)||typeof W.url!="string"||!("token"in W)||typeof W.token!="string")return;J()?ne({config:{url:W.url,token:W.token},persist:!1,source:"desktop",scopeId:"local"}):O({url:W.url,token:W.token});return}j===null||typeof j!="object"||!("stage"in j)||j.stage!=="failed"||!("failure"in j)||nt()&&(h+=1,M=!1,!N(j.failure)&&(ne(null),$.current+=1,F(null),d(null),D(null),Z(null),oe(lt(j.failure))))}}).then(j=>{o?j():(g=j,O())},()=>{O()}),()=>{o=!0,h+=1,re!==void 0&&clearTimeout(re),le.current===V&&(le.current=void 0),g?.()}},[e,Ke,ne]);const Ge=u.useCallback(()=>{oe(null),D(null),Z({stage:"spawning",startedAtMs:Date.now()}),f(o=>o+1)},[]),cn=u.useCallback(()=>{H.current=!0,Z(null),oe({message:c("connect.desktopCancelled"),stderrTail:[],logPath:null}),e.connection.cancelStartup?.().catch(()=>{})},[e,c]),Ye=he?.config.url.trim().replace(/\/+$/,"")??null,Ze=he?.config.token.trim()??null,[kt,an]=u.useState(null),ue=he!==null&&kt?.selection===he?kt.client:null,de=u.useRef(ue);de.current=ue;const Xe=u.useRef(null);u.useEffect(()=>{if(he===null||Ye===null||Ze===null)return;const o=new Te({baseUrl:Ye,token:Ze,timeoutMs:C,onSessionMutation:h=>{const g=i.current.get("local");g!==void 0&&De(g,h)}});return an({selection:he,client:o}),()=>{o.klient.close()}},[he,Ye,Ze,C]),u.useEffect(()=>{if(!(e.kind!=="tauri"||ue===null||l?.source!=="ssh"&&l?.source!=="remote"))return ue.klient.terminal.onStatus(o=>{o==="closed"&&le.current?.()})},[e,ue,l?.source]);const ge=w?.url.trim().replace(/\/+$/,"")??null,ve=w?.token.trim()??null,[Se,It]=u.useState(null),we=l?.source==="desktop",Me=ze.current?.selection===l?ze.current:null,Ce=we?ue:null,A=Me?.client??(Se?.endpoint===ge&&Se.token===ve&&Se.scopeId===R&&(!we||Se.client===Ce)?Se.client:null),z=A?.klient??null;u.useEffect(()=>{if(ge===null||ve===null||we&&Ce===null)return;const o=v=>{De(I,v)},h=Me?.client??Ce??(l?.source==="remote"?ft({endpoint:ge,token:ve,connectionId:l.connectionId,timeoutMs:C,onSessionMutation:o}):new Te({baseUrl:ge,token:ve,timeoutMs:C,onSessionMutation:o}));It({endpoint:ge,token:ve,scopeId:R,client:h});const g=Ve.current;return()=>{te.current?.client===h&&(te.current=null),G.current?.client===h&&(G.current=null),g.evictScope(h),h!==Ce&&h.klient.close()}},[ge,ve,R,C,I,we,Ce,Me?.client]),u.useEffect(()=>{if(A===null||k.current!==null&&l?.source!=="remote")return;let o=!1;const h=$.current;D(null);const g=Me?.client===A?Me:Xe.current?.client===A?Xe.current:null;return g!==null&&(Xe.current=null),(g!==null?Promise.resolve(g.meta):A.meta()).then(v=>{if(!(o||h!==$.current)){if(dt(),l?.source==="ssh"){const N=l.serverHomeId,M=bt.current.get(R);if(!N||!l.serverInstanceId||!l.serverVersion||v.server_home_id!==N||v.server_id!==l.serverInstanceId||v.server_version!==l.serverVersion||v.dangerous_bypass_auth!==!1||(v.build_id??null)!==l.buildId||(v.build_channel??null)!==l.buildChannel||M!==void 0&&M!==N){F(null),D({kind:"raw",text:"SSH server identity changed or could not be verified. This connection is blocked."});return}bt.current.set(R,N)}if(l?.source==="remote"&&(!l.serverHomeId||v.server_home_id!==l.serverHomeId)){F(null),D({kind:"raw",text:"identity-mismatch"});return}l?.source!=="remote"&&l?.persist===!0&&w!==null&&ms(w),l?.source==="desktop"&&l===S.current&&(te.current={selection:l,client:A,meta:v,homeId:x,scopeId:R},G.current=null),F(v)}},v=>{o||h!==$.current||(F(null),D({kind:"raw",text:v instanceof Ee||v instanceof Error?v.message:String(v)}),dt())}),()=>{o=!0}},[A,w,l?.persist]);const ye=w!==null&&Q!==null&&A!==null;u.useEffect(()=>{if(!ye||A===null)return;const o=()=>{A.renewLease({clientId:on.current,kind:"gui"}).catch(()=>{})};o();const h=window.setInterval(o,bs);return()=>{window.clearInterval(h)}},[A,ye]),u.useEffect(()=>{if(!ye||l?.source!=="ssh"||!e.connection.sshTunnelRunning)return;const o=l.profile?.id,h=l.tunnelId;if(!o||!h)return;let g=!0,v=!1;const N=()=>{v||(v=!0,e.connection.sshTunnelRunning(o,h).then(O=>{!g||O||($.current+=1,F(null),D({kind:"raw",text:"SSH tunnel disconnected. Check the remote service and connect again."}))},O=>{g&&($.current+=1,F(null),D({kind:"raw",text:`Cannot check the SSH tunnel: ${String(O)}`}))}).finally(()=>{v=!1}))};N();const M=window.setInterval(N,2e3);return()=>{g=!1,window.clearInterval(M)}},[ye,l?.source,l?.profile?.id,l?.tunnelId,e]);const Y=u.useMemo(()=>{const o=ye?z?.terminal??null:null;return o===null||!we?o:{...o,nudge:()=>{o.nudge(),G.current?.client===A&&le.current?.()}}},[ye,z,A,we]);u.useEffect(()=>{if(Y===null||z===null)return;let o=!0;const h=()=>{const V=z.events.on("search.indexStateChanged",J=>{I.cancelQueries({queryKey:["search-index-state"]}).then(()=>{o&&g===V&&I.setQueryData(["search-index-state"],J)})});return V.ready.then(()=>{if(o&&g===V)return I.invalidateQueries({queryKey:["search-index-state"]})}).catch(()=>{}),V};let g=h(),v=qt(z,I),N=$t(z,I);const M=z.events.on("session.workChanged",V=>{I.setQueriesData({queryKey:["sessions"]},J=>Un(J,V))}),O=Y.onStatus(V=>{if(!o)return;ce.current=V,V==="closed"&&e.kind==="tauri"&&fe(S.current)&&(A!==null&&te.current?.client===A&&(G.current={client:A,phase:"checking"}),le.current?.());const J=G.current?.client===A?G.current:null;me(J?.phase==="failed"?"closed":J!==null&&V==="open"?"connecting":V),V==="open"&&J?.phase==="failed"&&le.current?.(),V==="open"&&(g.dispose(),g=h(),v(),v=qt(z,I),N(),N=$t(z,I))}),re=z.events.on("kosong.changed",()=>{Yt({type:"event.model_catalog.changed"},I)});return()=>{o=!1,O(),re.dispose(),g.dispose(),M.dispose(),v(),N()}},[Y,z,I]),u.useEffect(()=>{if(Y!==null)return Dn()},[Y]),u.useEffect(()=>{if(Y===null)return;const o=()=>{Y.nudge();for(const g of Ve.current)g.nudge()},h=()=>{document.visibilityState==="visible"&&o()};return window.addEventListener("online",o),window.addEventListener("focus",o),window.addEventListener("pageshow",o),document.addEventListener("visibilitychange",h),()=>{window.removeEventListener("online",o),window.removeEventListener("focus",o),window.removeEventListener("pageshow",o),document.removeEventListener("visibilitychange",h)}},[Y]);const[jt,ln]=u.useState(!1),se=u.useRef({scope:{homeId:x,scopeId:R},selection:l,client:A});se.current={scope:{homeId:x,scopeId:R},selection:l,client:A};const be=u.useMemo(()=>ws({host:e,active:()=>{const o=se.current;if(o.selection===null||o.client===null)throw new Error("No active connection");return{scope:o.scope,selection:o.selection,client:o.client}},local:()=>ae.current!==null&&de.current!==null?{selection:ae.current,client:de.current}:null,control:()=>{if(ae.current!==null&&de.current!==null)return{selection:ae.current,client:de.current};const o=se.current;return o.selection!==null&&o.client!==null&&o.selection.source!=="remote"&&o.selection.source!=="ssh"?{selection:o.selection,client:o.client}:null},createClient:o=>o.source==="remote"?ft({endpoint:o.config.url,token:o.config.token,connectionId:o.connectionId,timeoutMs:C,onSessionMutation:h=>{const g=i.current.get(o.scopeId);g!==void 0&&De(g,h)}}):new Te({baseUrl:o.config.url,token:o.config.token,timeoutMs:C}),reload:()=>{k.current===null&&ln(!0)},preparing:o=>{Be.current=o},commit:(o,h,g)=>{if(xe.current+=1,$.current+=1,o===se.current.selection&&h===se.current.client){F(g);return}const v=se.current.selection;o.source==="remote"&&!n&&v!==null&&v.source!=="remote"&&v.source!=="ssh"&&ne({...v,scopeId:se.current.scope.scopeId});const N=o.source==="ssh"&&o.profile&&o.tunnelId?{id:o.profile.id,tunnelId:o.tunnelId}:null;je.current=N,ze.current={selection:o,client:h,meta:g},S.current=o,d(o),It({endpoint:o.config.url.trim().replace(/\/+$/,""),token:o.config.token.trim(),scopeId:o.scopeId??"local",client:h}),D(null),F(g)}}),[e,C,n,ne]);u.useEffect(()=>{const o=k.current;if(o===null||A===null||l?.source==="remote")return;const h=new AbortController;return(async()=>{const g=await be.prepare(o,h.signal);try{await g.validate(`${window.location.pathname}${window.location.search}${window.location.hash}`,h.signal),h.signal.throwIfAborted(),await g.commit(),k.current=null}catch(v){throw await g.dispose(),v}})().catch(g=>{h.signal.aborted||(F(null),D({kind:"raw",text:g instanceof Error?g.message:String(g)}))}),()=>{h.abort()}},[A,l?.source,be]);const St=u.useCallback(async(o=new AbortController().signal)=>{const h=de.current,g=S.current,v=xe.current,N=g?.source==="remote"?e.activeSpace===void 0?"main":ht(await e.activeSpace())?.homeId??"main":ot()?.homeId??"main",M=await be.prepare({homeId:N,scopeId:"local"},o);try{if(o.throwIfAborted(),h!==de.current||g!==S.current||v!==xe.current)throw new DOMException("Local connection restoration was superseded.","AbortError");await M.commit()}catch(O){throw await M.dispose(),O}},[be,e]),Pe=u.useCallback(()=>{if(Q!==null&&A!==null){S.current?.source==="remote"?(async()=>{const h=e.activeSpace===void 0?"main":ht(await e.activeSpace())?.homeId??"main";await ct({homeId:h,scopeId:ae.current?.scopeId??"local"})})().catch(()=>{}):ct({scopeId:"local"}).catch(()=>{});return}xe.current+=1,$.current+=1;const o=je.current;je.current=null,o!==null&&e.connection.disconnectSshProfile?.(o.id,o.tunnelId).catch(()=>{}),F(null),D(null),d(ae.current),ae.current===null&&n&&Ge()},[Q,A,e,n,Ge]),Je=u.useCallback(async(o,h)=>{if(se.current.client!==null&&se.current.selection!==null){await ct({scopeId:`ssh:${o}`,token:h});return}if(!e.connection.connectSshProfile||!e.connection.listSshProfiles)throw new Error("SSH connections are available only in the desktop application.");const g=++xe.current,N=(await e.connection.listSshProfiles()).find(re=>re.id===o);if(!N)throw new Error("SSH profile no longer exists.");if(!N.serverHomeId||!N.remotePort||!/^[A-Za-z0-9_-]{43}$/.test(h))throw new Error("Set the remote Kiki port, expected home ID and bearer token first.");const M=await e.connection.connectSshProfile(o,h);if(g!==xe.current){M.tunnelId&&e.connection.disconnectSshProfile?.(o,M.tunnelId).catch(()=>{});return}let O;try{O=new URL(M.config.url)}catch{O=null}if(O?.protocol!=="http:"||O.hostname!=="127.0.0.1"||O.username||O.password||!O.port||!M.tunnelId||M.config.token!==h||M.serverHomeId!==N.serverHomeId)throw M.tunnelId&&e.connection.disconnectSshProfile?.(o,M.tunnelId).catch(()=>{}),new Error("SSH tunnel endpoint or server home ID could not be verified.");je.current={id:o,tunnelId:M.tunnelId},$.current+=1,F(null),D(null),d({config:M.config,persist:!1,source:"ssh",scopeId:`ssh:${o}`,profile:N,tunnelId:M.tunnelId,serverHomeId:M.serverHomeId,serverInstanceId:M.serverInstanceId,serverVersion:M.serverVersion,buildId:M.buildId,buildChannel:M.buildChannel})},[e]),et=u.useCallback(()=>{if(S.current?.source==="ssh"){Pe();return}$.current+=1,xs(),F(null),d(null),D(null),dt()},[Pe]),un=u.useCallback(()=>{Fn(),T({kind:"none"}),p(void 0)},[]),tt=u.useCallback((o,h=!0)=>{const g=++$.current,v=S.current,N=v!==null&&v.config.url.trim().replace(/\/+$/,"")===o.url.trim().replace(/\/+$/,"")&&v.config.token.trim()===o.token.trim();D(null),F(null),d({config:o,persist:h,source:h?"manual":"local-detection",scopeId:N?v.scopeId:`direct:${o.url.trim().replace(/\/+$/,"")}:${g}`})},[]),Mt=u.useCallback(o=>{S.current?.source==="ssh"||S.current?.source==="remote"||tt(o,!0)},[tt]),Ct=u.useMemo(()=>w===null||A===null||z===null||Y===null||Q===null?null:{connectionId:P,connectionSource:l?.source??null,spaceKey:x,scopeId:R,connectionRef:l?.source==="remote"?l.connectionId:l?.source==="ssh"?l.tunnelId:void 0,sshLabel:l?.profile?.label??null,activateSshProfile:Je,activateLocal:Pe,restoreLocal:St,scopeAdapter:be,needsScopeReload:jt,config:w,client:A,localClient:ue,klient:z,socket:Y,meta:Q,wsStatus:X,disconnect:et,applyConnection:Mt},[P,E,x,R,l?.tunnelId,l?.profile?.label,Je,Pe,St,be,jt,w,A,ue,z,Y,Q,X,et,Mt]),_e=q===null?null:q.kind==="key"?An(a,q.key,q.params):q.text,dn=l?.source==="ssh"?_e===null?null:{message:_e,stderrTail:[],logPath:null}:Ue??(n&&_e!==null?{message:_e,stderrTail:[],logPath:null}:null);return s.jsx(We.Provider,{value:Ct,children:Ct!==null?s.jsx(Ln,{client:I,children:s.jsx(yt.Provider,{value:Ve.current,children:t})}):s.jsx(ss,{initial:w??{url:"",token:""},connecting:Ie!==null||w!==null&&q===null,error:n?null:_e,onConnect:tt,onBack:n?void 0:w!==null?et:void 0,desktopBoot:Ie,desktopFailure:dn,onRetryDesktop:Ge,onCancelDesktopBoot:cn,onConnectSsh:Je,onSwitchLocal:l?.source==="ssh"?Pe:void 0,sshProfile:l?.source==="ssh"?l.profile:void 0,webLink:y,onRetryWebLink:un})})}const yt=u.createContext(null);function js(){const t=u.useContext(yt);if(t===null)throw new Error("useControllerRegistry outside provider");return t}function Ss(){return u.useContext(yt)}function Ms({value:t,children:e}){return s.jsx(We.Provider,{value:t,children:e})}function Cs(){const t=u.useContext(We);if(t===null)throw new Error("useConnection used before connecting");return t}function Ps(){return u.useContext(We)}const nr=Object.freeze(Object.defineProperty({__proto__:null,ConnectionProvider:Is,ConnectionScope:Ms,LiveControllerRegistry:tn,VIEW_CACHE_MAX_BYTES:wt,VIEW_CACHE_MAX_ENTRY_BYTES:Xt,VIEW_CACHE_MAX_LIVE_PARKED:en,VIEW_CACHE_MAX_PARKED:Zt,VIEW_CACHE_TTL_MS:Jt,handleGlobalConnectionFrame:Yt,isDesktopSelection:fe,isProtectedView:Oe,nextGuiLeaseClientId:nn,refreshSessionAttention:De,useConnection:Cs,useControllerRegistry:js,useOptionalConnection:Ps,useOptionalControllerRegistry:Ss},Symbol.toStringTag,{value:"Module"}));export{Gn as A,qs as B,Hs as C,Zn as D,Ls as E,Us as F,Qs as G,Ws as H,xt as I,Ts as J,er as K,Ds as L,nr as M,Ys as O,mt as S,Le as W,Ns as a,$s as b,Ne as c,Ks as d,Vs as e,Bs as f,Qn as g,As as h,Ft as i,zs as j,Ps as k,Zs as l,Os as m,us as n,tr as o,Ss as p,Xn as q,Js as r,Bt as s,Xs as t,Cs as u,js as v,Fs as w,Ot as x,Gs as y,Tt as z};
@@ -1,2 +0,0 @@
1
- import{K as qn,u as Xn,M as E,N as Qn,O as Zn,P as et,Q as nt,T as yn,a as tt,U as rt,V as An,W as ot,X as Xe}from"./index-B0KPRi1U.js";import{M as Cn,h as it}from"./spaces-DqMTtCXX.js";function st(e,n){const t=n?.current_space_id;return!n?.server_id||t===void 0||t!==Cn&&!qn.test(t)?null:{client:e,identity:{serverId:n.server_id,homeId:t}}}function Sr(e){return e!==null&&e.identity.homeId!==Cn}const Qe=new WeakMap;let at=0;function ct(e){let n=Qe.get(e);return n===void 0&&(n=++at,Qe.set(e,n)),n}function Er(e,n){const t=Xn({queryKey:["space-settings","meta",e===null?null:ct(e)],queryFn:async({signal:r})=>{if(e===null)throw new Error("Space client unavailable");const o=await e.meta();return r.throwIfAborted(),o},enabled:e!==null&&n===void 0,staleTime:3e4,retry:!1});return e===null?null:st(e,n===void 0?t.data:n)}function Ke(e){return it(e)}const yr={all:["space-settings"],detail:e=>["space-settings","detail",e]},lt=["config","appearance","agents","instructions","skills","mcp","credentials","plugins"],Dn="generic_roots";function Ar(e){return`st.spaces.group.${e}`}const ne={theme:"pref:theme",skin:"pref:skin",tweaks:"pref:tweaks",background:"pref:background",proseFont:"pref:proseFont",defaultAppendTiming:"pref:defaultAppendTiming",foldSteps:"pref:foldSteps",worktreeSkipConfirm:"pref:worktreeSkipConfirm"};function Cr(e,n){return e?.items.find(t=>t.id===n)}function ut(e){return e.replaceAll(/[A-Z]/g,n=>`_${n.toLowerCase()}`)}function Dr(e,n=[]){return`config:${[e,...n].map(ut).join(".")}`}const dt={"pref:theme":"st.appearance.theme","pref:skin":"st.skin.title","pref:tweaks":"st.skin.tweaks","pref:background":"st.bg.title","pref:proseFont":"st.appearance.prose","pref:defaultAppendTiming":"st.communication.appendTimingTitle","pref:foldSteps":"st.transcript.foldSteps","pref:worktreeSkipConfirm":"st.composer.worktreeConfirm","config:default_model":"st.defaults.globalModelLabel","config:fast_model":"st.defaults.row.fast","config:subagent.default_model":"st.defaults.row.subagent","config:session_title.model":"st.defaults.row.title","config:default_permission_mode":"st.defaults.permissionMode","config:default_plan_mode":"st.defaults.planMode","config:thinking.effort":"st.profiles.effort","source:credentials":"st.spaces.group.credentials","source:instructions":"st.spaces.group.instructions","source:generic_roots":"st.spaces.group.generic_roots"};function Ir(e,n,t){const r=dt[e];return r===void 0?n:t(r)}function ft(e,n){const t=e.groups.find(r=>r.domain===n);if(t!==void 0)return{mode:t.mode,fixedCount:t.fixed_count,followCount:t.follow_count,stacked:n==="instructions"&&e.inherit.instructions==="stack"}}function Br(e,n,t){const r=ft(e,n);return r===void 0?t("st.spaces.origin.unknown"):n==="credentials"?t(e.inherit.credentials==="shared"?"st.spaces.group.shared":"st.spaces.group.isolated"):n===Dn?t(e.inherit.generic_roots?"st.spaces.group.available":"st.spaces.group.unavailable"):e.primary?t("st.spaces.group.items",{count:r.fixedCount}):r.mode==="follow"?r.stacked?t("st.spaces.group.stacked"):r.fixedCount===0?t("st.spaces.group.follow"):t("st.spaces.group.followFixed",{count:r.fixedCount}):r.followCount===0?t("st.spaces.group.fixed"):t("st.spaces.group.fixedFollow",{count:r.followCount})}function wr(e){const n=new Map([...lt,Dn].map((t,r)=>[t,r]));return e.items.filter(t=>t.kind!=="source"&&t.origin==="home").toSorted((t,r)=>(n.get(t.domain)??99)-(n.get(r.domain)??99)||t.name.localeCompare(r.name))}const pt={"pref:theme":"/settings/appearance","pref:skin":"/settings/appearance","pref:tweaks":"/settings/appearance","pref:background":"/settings/appearance","pref:proseFont":"/settings/appearance","pref:defaultAppendTiming":"/settings/general","pref:foldSteps":"/settings/general","pref:worktreeSkipConfirm":"/settings/general","config:default_model":"/settings/ai","config:fast_model":"/settings/ai","config:thinking.effort":"/settings/ai","config:session_title.model":"/settings/ai","config:default_permission_mode":"/settings/permissions"},kt=[["resource:agents:","/settings/agents"],["resource:skills:","/settings/skills"],["resource:mcp:","/settings/mcp"],["resource:plugins:","/settings/plugins"],["resource:appearance:","/settings/appearance"]];function _r(e){const n=pt[e];return n!==void 0?n:kt.find(([t])=>e.startsWith(t))?.[1]}function ze(e,n=48){return e.length>n?`${e.slice(0,n-1)}…`:e}function mt(e){try{return ze(JSON.stringify(e),72)}catch{return""}}function ht(e,n,t){if(e==="pref:background"&&n==null)return t("st.spaces.value.backgroundNone");if(e==="pref:theme"&&(n==="light"||n==="dark"||n==="system"))return t(`st.appearance.theme.${n}`);if(e==="pref:proseFont"&&(n==="serif"||n==="sans"))return t(`st.appearance.prose.${n}`);if(e==="pref:defaultAppendTiming"&&(n==="agent_idle"||n==="subagents_done"||n==="tasks_done"))return t(`st.spaces.value.appendTiming.${n}`);if(e==="pref:skin"&&typeof n=="object"&&n!==null){const r=n;if(typeof r.id!="string")return;const o=r.source==="pack"?"st.spaces.value.skinPack":r.source==="user"?"st.spaces.value.skinUser":"st.spaces.value.skinBuiltin";return t(o,{id:r.id})}if(e==="pref:tweaks"&&typeof n=="object"&&n!==null){const r=Object.keys(n).length;return r===0?t("st.spaces.value.tweaksNone"):t("st.spaces.value.tweaksCount",{count:r})}if(e==="pref:background"&&typeof n=="object"&&n!==null){const r=n,o=(r.linked===!1?r.dark:r.light)??r.light??r.dark;if(o==null||typeof o!="object")return t("st.spaces.value.backgroundNone");const i=o.media;if(!Array.isArray(i)||i.length===0)return t("st.spaces.value.backgroundNone");if(i.length>1)return t("st.spaces.value.backgroundCount",{count:i.length});const s=i[0],c=typeof s?.name=="string"&&s.name!==""?s.name:typeof s?.id=="string"?s.id.split("/").at(-1)??s.id:"";return c===""?t("st.spaces.value.backgroundCount",{count:i.length}):ze(c,32)}}function Or(e,n,t){const r=ht(e,n,t);return r!==void 0?r:n==null?t("st.spaces.value.none"):typeof n=="boolean"?t(n?"st.spaces.value.on":"st.spaces.value.off"):typeof n=="string"?ze(n):typeof n=="number"?String(n):Array.isArray(n)?t("st.spaces.group.items",{count:n.length}):mt(n)}function Pr(e){const n=[],t=[],r=[];for(const o of e.rows)o.id.startsWith("group:")?n.push(o):o.same_value?r.push(o):t.push(o);return{changed:t,same:r,groups:n}}function Mr(e){return e.blocked_reason===void 0}const gt=[["Resource content is unavailable","st.spaces.blocked.resourceUnavailable"],["Only resources can be excluded","st.spaces.blocked.onlyResources"],["This item cannot be shared through the ordinary push flow","st.spaces.blocked.notShareable"],["Edit this resource through its resource editor","st.spaces.blocked.editResource"],["Main space has no parent source","st.spaces.blocked.mainNoParent"]];function Nr(e,n){if(e.startsWith("Connection contains account data"))return n("st.spaces.blocked.accountData");const t=gt.find(([r])=>r===e);return t===void 0?e:n(t[1])}function F(e){return`${e.serverId}|${e.homeId}`}const In="kiki.spacePreferences.cache",Ze={entries:{},authorities:{},lastKnown:null,resolved:{}};function de(){try{const e=localStorage.getItem(In);if(e===null)return Ze;const n=JSON.parse(e);return{entries:typeof n.entries=="object"&&n.entries!==null?n.entries:{},authorities:typeof n.authorities=="object"&&n.authorities!==null?n.authorities:{},lastKnown:n.lastKnown??null,resolved:typeof n.resolved=="object"&&n.resolved!==null?n.resolved:{}}}catch{return Ze}}function Bn(e){try{localStorage.setItem(In,JSON.stringify(e))}catch{}}const L={identity:null,confirmed:null,authoritative:!1,drafts:{},writes:{},deviceConflict:!1,loaded:!1};let u=L,K=0,Ft=0,_=0,Ce={},z={};const De=new Set;function b(e){return u.identity!==null&&F(u.identity)===F(e)}function fe(){K+=1,Ce={},z={}}function wn(e){return De.add(e),()=>{De.delete(e)}}function _n(){return u}function Tr(){return L}function C(e){u=e;for(const n of De)n();vt()}function V(e,n,t=!0){const r=de(),o=n.preferences;Bn({...r,entries:{...r.entries,[F(e)]:o},authorities:{...r.authorities,[F(e)]:n.preference_authority},lastKnown:t?{homeId:e.homeId,serverId:e.serverId,values:o}:r.lastKnown})}function Rr(e){return de().resolved[F(e)]===!0}function Lr(e,n){const t=de(),r=t.lastKnown?.homeId===e?t.lastKnown:null,o=n===void 0?r===null?null:{serverId:r.serverId,homeId:e}:{serverId:n,homeId:e};if(o===null||b(o)&&u.loaded)return;const i=n===void 0?r?.values??null:t.entries[F(o)]??null,s=t.authorities[F(o)]===!0?i:null;b(o)||fe(),C({...L,identity:o,confirmed:s})}function $r(e,n){const t=b(e);t||fe(),V(e,n),C({...t?u:L,identity:e,confirmed:n.preferences,authoritative:n.preference_authority,loaded:!0})}function Hr(){u!==L&&(fe(),C(L))}function Ur(){u.deviceConflict||C({...u,deviceConflict:!0})}function xr(e){const n=e??u.identity;if(n!==null){const t=de();Bn({...t,resolved:{...t.resolved,[F(n)]:!0}})}n!==null&&b(n)&&u.deviceConflict&&C({...u,deviceConflict:!1})}function Ie(e){const n=u.drafts[e];return n!==void 0?n:u.confirmed===null?void 0:u.confirmed[e]}function te(){return u.confirmed!==null||Y!==void 0}let Y;const bt=new Set;function jr(e){Y=e}function vt(){for(const e of bt)e()}function Ve(e,n,t,r=[]){if(!b(e)||u.confirmed===null)return n;const o={...n.preferences};for(const s of Object.keys(ne))((z[s]??0)>t||r.includes(s))&&Object.assign(o,{[s]:u.confirmed[s]});const i=Object.values(z).some(s=>s>t);return{...n,preferences:o,preference_authority:i?u.authoritative:n.preference_authority}}async function Kr(e,n){const t=_,r=await Ke(e).detail(n.homeId);return Ve(n,r,t)}async function Be(e,n){const t=Y,r=t?.client()??null,o=t?.identity()??null;return t===void 0||r===null||o===null||t.spaceId()!==o.homeId?!1:St(r,o,{[e]:n})}async function St(e,n,t){if(!b(n))return!1;const r=Object.keys(ne).filter(l=>t[l]!==void 0);if(r.length===0)return!1;const o=Y,i=K,s=_,c=++Ft,d={...u.drafts},f={...u.writes};for(const l of r)Ce[l]=c,d[l]=t[l],f[l]={state:"saving"};C({...u,drafts:d,writes:f});const h=()=>K===i&&b(n),y=()=>r.filter(l=>Ce[l]===c);try{const l=Ke(e),a=r.map(m=>({id:ne[m],value:t[m]})),M=await l.preview(n.homeId,{action:"edit",changes:a});for(const m of a){const ge=M.rows.find(Yn=>Yn.id===m.id);if(ge===void 0||ge.blocked_reason!==void 0)throw new Error(ge?.blocked_reason??`The server returned no plan for ${m.id}`)}const q=await l.apply(n.homeId,{token:M.token,selected:a.map(m=>m.id)});if(!h())return b(n)||V(n,q.detail,!1),!0;const me=y();if(me.length===0)return!0;const X=Ve(n,q.detail,s,r.filter(m=>!me.includes(m))),Ye={...u.drafts},qe={...u.writes};_+=1;for(const m of me)z[m]=_,delete Ye[m],delete qe[m];V(n,X),C({...u,confirmed:X.preferences,authoritative:X.preference_authority,loaded:!0,drafts:Ye,writes:qe});const he=o?.identity();return h()&&he!==null&&he!==void 0&&F(he)===F(n)&&o?.onDetail?.(X),!0}catch(l){if(h()){const a={...u.writes};for(const M of y())a[M]={state:"error",error:l};y().length>0&&C({...u,writes:a})}return!1}}async function zr(e,n,t,r){const o=K,i=_,s=Y;try{const c=await Ke(e).importPreferences(n.homeId,{values:r,device_id:t});if(K!==o||u.identity!==null&&!b(n))return b(n)||V(n,c.detail,!1),{imported:c.imported,conflict:c.device_conflict};const d=Ve(n,c.detail,i);u.identity===null&&fe(),_+=1;for(const h of Object.keys(ne))z[h]=_;V(n,d),C({...u,identity:n,confirmed:d.preferences,authoritative:d.preference_authority,deviceConflict:c.device_conflict,loaded:!0});const f=s?.identity();return b(n)&&f!==null&&f!==void 0&&F(f)===F(n)&&s?.onDetail?.(d),{imported:c.imported,conflict:c.device_conflict}}catch{return null}}function Vr(){const e="kiki.deviceId";try{const n=localStorage.getItem(e);if(n!==null&&n!=="")return n;const t=globalThis.crypto?.randomUUID?.()??`device-${Date.now().toString(36)}`;return localStorage.setItem(e,t),t}catch{return"device-unknown"}}const J={light:null,dark:null,linked:!0,assist:!0},we="kiki.background";function v(e,n,t,r){return typeof e=="number"&&Number.isFinite(e)?Math.min(t,Math.max(n,e)):r}function Fe(e,n,t){return typeof e=="string"&&n.includes(e)?e:t}function On(e){const n=typeof e=="object"&&e!==null?e:{},t=Qn;return{fit:Fe(n.fit,nt,t.fit),alignment:Fe(n.alignment,et,t.alignment),opacity:v(n.opacity,0,1,t.opacity),blur:v(n.blur,0,40,t.blur),brightness:v(n.brightness,.4,1.4,t.brightness),scrim:v(n.scrim,0,.9,t.scrim),scope:Fe(n.scope,Zn,t.scope),surfaceOpacity:v(n.surfaceOpacity,.3,1,t.surfaceOpacity),surfaceBlur:v(n.surfaceBlur,0,32,t.surfaceBlur)}}function en(e){if(typeof e!="object"||e===null)return null;const n=e;return typeof n.id!="string"||!/^(?:local-[\w-]{1,80}|pack:[a-z0-9][a-z0-9-]{0,63}\/[A-Za-z0-9][A-Za-z0-9._-]{0,99})$/.test(n.id)||n.kind!=="image"&&n.kind!=="video"||typeof n.mime!="string"||!/^(image|video)\/[\w.+-]+$/.test(n.mime)?null:{id:n.id,kind:n.kind,mime:n.mime,name:typeof n.name=="string"?n.name.slice(0,200):n.id,bytes:v(n.bytes,0,Number.MAX_SAFE_INTEGER,0)}}function Et(e){if(typeof e!="object"||e===null)return;const n=e;if(!(typeof n.dark!="number"||typeof n.light!="number"))return{dark:v(n.dark,0,1,0),light:v(n.light,0,1,1)}}function nn(e){if(typeof e!="object"||e===null)return null;const n=e,t=(Array.isArray(n.media)?n.media:[]).map(en).filter(o=>o!==null).slice(0,12);if(t.length===0)return null;const r=en(n.poster)??void 0;return{media:t,poster:r,interval:v(n.interval,0,3600,0),look:On(n.look),packId:typeof n.packId=="string"&&/^[a-z0-9][a-z0-9-]{0,63}$/.test(n.packId)?n.packId:void 0,sample:Et(n.sample)}}function Je(e){if(typeof e!="object"||e===null)return J;const n=e;return{light:nn(n.light),dark:nn(n.dark),linked:n.linked!==!1,assist:n.assist!==!1}}const re=new Set;let g;function Pn(){try{const e=E.getItem(we);return e===null?J:Je(JSON.parse(e))}catch{return J}}function Jr(e){return re.add(e),()=>{re.delete(e)}}function Gr(){return Pn()}function tn(e){return{id:e.id,kind:e.kind,mime:e.mime,name:e.name,bytes:e.bytes}}function oe(e){return e===null?null:{media:e.media.map(tn),...e.poster===void 0?{}:{poster:tn(e.poster)},interval:e.interval,look:e.look,...e.packId===void 0?{}:{packId:e.packId},...e.sample===void 0?{}:{sample:e.sample}}}function S(e){return e===null?!0:[...e.media,...e.poster===void 0?[]:[e.poster]].every(n=>n.id.startsWith("pack:"))}function Wr(e){if(!(!S(e.light)||!S(e.dark)))return{light:oe(e.light),dark:oe(e.dark),linked:e.linked,assist:e.assist}}function yt(){const e=Ie("background");if(e!==void 0)return Je(e)}let rn,on,sn=!1;function At(){const e=_n();return(!sn||rn!==e)&&(rn=e,on=yt(),sn=!0),on}function Yr(){const e=pe();return te()&&!(S(e.light)&&S(e.dark))}function pe(){return g??=Pn(),!S(g.light)||!S(g.dark)?g:At()??g}function qr(){return J}function Ct(e){const n=Je({...e,assist:e.assist??pe().assist});if(te()&&S(n.light)&&S(n.dark)){g!==void 0&&(!S(g.light)||!S(g.dark))&&an(n),Be("background",{light:oe(n.light),dark:oe(n.dark),linked:n.linked,assist:n.assist});return}an(n)}function an(e){try{e.light===null&&e.dark===null&&e.linked&&e.assist?E.removeItem(we):E.setItem(we,JSON.stringify(e))}catch{}JSON.stringify(e)!==JSON.stringify(g)&&(g=e);for(const n of re)n()}wn(()=>{g=void 0;for(const e of re)e()});function Xr(){return pe()}function Qr(){g=void 0}function Zr(e,n){return e.linked?e.light??e.dark:e[n]}function eo(e,n){return e.linked?"light":n}function be(e){const n=e.trim().replace("#",""),t=n.length===3?n.split("").map(r=>`${r}${r}`).join(""):n;return/^[0-9a-fA-F]{6}$/.test(t)?[0,2,4].map(r=>Number.parseInt(t.slice(r,r+2),16)/255):null}const ve=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Dt=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055;function _e(e){return .2126*ve(e[0])+.7152*ve(e[1])+.0722*ve(e[2])}function It(e,n){const[t,r]=e>n?[e,n]:[n,e];return(t+.05)/(r+.05)}function cn(e,n,t){return[0,1,2].map(r=>e[r]*t+n[r]*(1-t))}function Bt(e){const n=Dt(Math.min(1,Math.max(0,e)));return[n,n,n]}const wt=4.5,_t=.15;function Ot(e,n,t,r){const o=be(e.surface),i=be(e.ground),s=e.texts.map(be).filter(l=>l!==null);if(o===null||i===null||s.length===0)return 1;const c=n.opacity*(1-n.scrim),d=[t?.dark??0,t?.light??1].map(l=>{const a=Bt(Math.min(1,l*n.brightness));return cn(a,i,c)}),f=l=>d.every(a=>{const M=_e(cn(o,a,l));return s.every(q=>It(_e(q),M)>=wt+_t)});if(f(r))return r;let h=r,y=1;for(let l=0;l<16;l+=1){const a=(h+y)/2;f(a)?y=a:h=a}return Math.min(1,Math.ceil(y*100)/100)}function Pt(e){const n=[];for(let r=0;r+3<e.length;r+=4)e[r+3]<16||n.push(_e([e[r]/255,e[r+1]/255,e[r+2]/255]));if(n.length===0)return{dark:0,light:1};n.sort((r,o)=>r-o);const t=r=>n[Math.min(n.length-1,Math.floor(r*n.length))];return{dark:t(.05),light:t(.95)}}const Mt={center:"center",top:"center top",bottom:"center bottom",left:"left center",right:"right center",topLeft:"left top",topRight:"right top",bottomLeft:"left bottom",bottomRight:"right bottom"};function ln(e){return Mt[e]}const Mn="paper",Nt=new Set(["linen","graphite","forest","claret","heather","nocturne","sand","slate"]),Oe="'Instrument Sans Variable', 'Instrument Sans', ui-sans-serif, system-ui, 'Segoe UI', 'PingFang SC', 'Noto Sans SC', sans-serif",un=Oe,Tt=[{kind:"kiki-skin",version:1,id:Mn,name:"纸色 Paper × 墨砚 Inkstone",description:"Warm white paper and ink-blue marks; cool charcoal and copper after dark.",variants:{light:{colors:{canvas:"#F2EFE8",paper:"#FBFAF6",panel:"#FFFDFA",hairline:"#E4DDD0",hairlineStrong:"#CDC3B1",ink:"#1B1A17",inkSoft:"#4B453E",inkFaint:"#665E54",accent:"#C8401A",accentDeep:"#9C3012",accentSoft:"#F8E3D8",accentInk:"#9C3012",onAccent:"#FFFFFF",sectionInk:"#4B453E",selected:"#DFE8F0",selectedInk:"#1D4D6D",attention:"#B33A12",attentionSoft:"#FAE3D7",amberInk:"#87480B",amberCard:"#F8EEDD",amberRule:"#D9A441",success:"#2F6B45",danger:"#B0261E",onDanger:"#FFFFFF",bubbleUser:"#EEE8DC",scrollbar:"#D8D0C1",scrollbarHover:"#C4BAA8",termScrollbar:"#4A4238",shell:"#1F1B16",shellInk:"#E8DCC4",shellInkStrong:"#F3E9D8",shellInkSoft:"#9B8E7A",shellDanger:"#D9A08A",shellHairline:"#332D24",shellHover:"#2A251D",shadowInk:"#1B1A17"}},dark:{colors:{canvas:"#13191C",paper:"#1B2226",panel:"#252D31",hairline:"#354047",hairlineStrong:"#596870",ink:"#EEEAE2",inkSoft:"#C1C5C5",inkFaint:"#A2ACAF",accent:"#EB946F",accentDeep:"#F4B08F",accentSoft:"#382A25",accentInk:"#F4AE8D",onAccent:"#261A14",sectionInk:"#C1C5C5",selected:"#24323B",selectedInk:"#A3CBDE",attention:"#F4AE8D",attentionSoft:"#382A25",amberInk:"#E6BD78",amberCard:"#322B20",amberRule:"#96783F",success:"#9AC6AE",danger:"#F1A29A",onDanger:"#301414",bubbleUser:"#293238",scrollbar:"#4F5F68",scrollbarHover:"#74838C",termScrollbar:"#526068",shell:"#101518",shellInk:"#D1D9DA",shellInkStrong:"#F0F2EF",shellInkSoft:"#9AA7AB",shellDanger:"#F1A29A",shellHairline:"#354047",shellHover:"#202B30",shadowInk:"#000000"}}}},{kind:"kiki-skin",version:1,id:"porcelain",name:"瓷白 Porcelain × 深海 Deepwater",description:"Cool white paper and cobalt details; layered navy and mist-blue controls at night.",variants:{light:{colors:{canvas:"#E7EDF4",paper:"#F8FBFF",panel:"#FFFFFF",hairline:"#D2DDE9",hairlineStrong:"#A9B9CA",ink:"#17283D",inkSoft:"#405570",inkFaint:"#516279",accent:"#2856A6",accentDeep:"#1B3F84",accentSoft:"#E2EBFA",accentInk:"#204986",onAccent:"#FFFFFF",sectionInk:"#405570",selected:"#DEE8F7",selectedInk:"#204986",attention:"#9C461C",attentionSoft:"#F9E8DC",amberInk:"#7E520D",amberCard:"#F8EED9",amberRule:"#B58A3B",success:"#28664B",danger:"#AF343E",onDanger:"#FFFFFF",bubbleUser:"#E6EDF6",scrollbar:"#B6C5D6",scrollbarHover:"#8B9FB5",termScrollbar:"#52657C",shell:"#142033",shellInk:"#D8E3F1",shellInkStrong:"#F2F7FF",shellInkSoft:"#9CACC2",shellDanger:"#F1A6AB",shellHairline:"#35475E",shellHover:"#24354C",shadowInk:"#132237"}},dark:{colors:{canvas:"#0D1624",paper:"#152238",panel:"#1E304A",hairline:"#304761",hairlineStrong:"#586E88",ink:"#E4EDF9",inkSoft:"#B8C9E0",inkFaint:"#98B0CB",accent:"#9DAEF5",accentDeep:"#BAC8FF",accentSoft:"#283653",accentInk:"#BAC8FF",onAccent:"#17203C",sectionInk:"#B8C9E0",selected:"#293A55",selectedInk:"#BAD1F5",attention:"#F1C28C",attentionSoft:"#362D26",amberInk:"#E9C474",amberCard:"#332D20",amberRule:"#927A46",success:"#99D0B5",danger:"#F2A4AE",onDanger:"#351724",bubbleUser:"#223551",scrollbar:"#455F7E",scrollbarHover:"#6D88A8",termScrollbar:"#4D627C",shell:"#090F1A",shellInk:"#CFDDF0",shellInkStrong:"#EDF4FF",shellInkSoft:"#98ADC8",shellDanger:"#F2A4AE",shellHairline:"#283B53",shellHover:"#17273D",shadowInk:"#000000"}}}},{kind:"kiki-skin",version:1,id:"celadon",name:"青瓷 Celadon × 夜园 Night Garden",description:"Celadon glaze and soft white paper; deep pine surfaces and jade details at night.",variants:{light:{colors:{canvas:"#DDE7DE",paper:"#F2F7EF",panel:"#FCFEF9",hairline:"#C8D8CB",hairlineStrong:"#9DB6A7",ink:"#21382F",inkSoft:"#435D50",inkFaint:"#4D6253",accent:"#24675F",accentDeep:"#174F4A",accentSoft:"#DCECE6",accentInk:"#1E5650",onAccent:"#FFFFFF",sectionInk:"#435D50",selected:"#D7E9DE",selectedInk:"#20594D",attention:"#984B21",attentionSoft:"#F5E7DA",amberInk:"#79520D",amberCard:"#F6EED5",amberRule:"#A1843C",success:"#3E642A",danger:"#A9363C",onDanger:"#FFFFFF",bubbleUser:"#E2ECDD",scrollbar:"#AEC3B1",scrollbarHover:"#839E8B",termScrollbar:"#526A5D",shell:"#14251E",shellInk:"#DDE8DB",shellInkStrong:"#F4F9ED",shellInkSoft:"#9CAC9F",shellDanger:"#F0A8A5",shellHairline:"#364D3F",shellHover:"#253A2F",shadowInk:"#172A23"}},dark:{colors:{canvas:"#111C1A",paper:"#1A2925",panel:"#243830",hairline:"#354E43",hairlineStrong:"#597968",ink:"#E5EEE3",inkSoft:"#BDCEC1",inkFaint:"#9DB4A4",accent:"#8FCBB8",accentDeep:"#ACDCCD",accentSoft:"#283F36",accentInk:"#ACDCCD",onAccent:"#122C23",sectionInk:"#BDCEC1",selected:"#2A4036",selectedInk:"#B4DCC2",attention:"#E8BD86",attentionSoft:"#3B3023",amberInk:"#E2C47E",amberCard:"#34311E",amberRule:"#8C824A",success:"#C0D58F",danger:"#F0AAA4",onDanger:"#351915",bubbleUser:"#2B3E33",scrollbar:"#4E6C5B",scrollbarHover:"#799A85",termScrollbar:"#526B5D",shell:"#0C1512",shellInk:"#D2E1D4",shellInkStrong:"#F0F6EA",shellInkSoft:"#9FB5A6",shellDanger:"#F0AAA4",shellHairline:"#2D493A",shellHover:"#1D3026",shadowInk:"#000000"}}}},{kind:"kiki-skin",version:1,id:"apricot",name:"杏云 Apricot × 晚霞 Afterglow",description:"Apricot-white paper and berry controls; plum-charcoal layers and peach light after dark.",variants:{light:{colors:{canvas:"#F4DED5",paper:"#FFF3EB",panel:"#FFFAF5",hairline:"#DFC7C0",hairlineStrong:"#B698A0",ink:"#382C38",inkSoft:"#604F5C",inkFaint:"#6B5563",accent:"#A13B55",accentDeep:"#822C46",accentSoft:"#F9DFE4",accentInk:"#822C46",onAccent:"#FFFFFF",sectionInk:"#604F5C",selected:"#F2DEE2",selectedInk:"#7D3553",attention:"#934018",attentionSoft:"#FAE2CF",amberInk:"#794C0B",amberCard:"#F8EBD0",amberRule:"#B38A42",success:"#3E674E",danger:"#AF263C",onDanger:"#FFFFFF",bubbleUser:"#F7E3DB",scrollbar:"#CDB0B1",scrollbarHover:"#AC8C96",termScrollbar:"#68576A",shell:"#251D29",shellInk:"#EADDE8",shellInkStrong:"#FFF3F0",shellInkSoft:"#B7A3B6",shellDanger:"#F0A3AD",shellHairline:"#4B3B4C",shellHover:"#382C3A",shadowInk:"#372635"}},dark:{colors:{canvas:"#201A22",paper:"#2C2430",panel:"#3A303E",hairline:"#51404F",hairlineStrong:"#816477",ink:"#F4E9E7",inkSoft:"#D8C2CD",inkFaint:"#C1A9B8",accent:"#F4B29C",accentDeep:"#FFCCB6",accentSoft:"#49323C",accentInk:"#FFCCB6",onAccent:"#351D22",sectionInk:"#D8C2CD",selected:"#443440",selectedInk:"#F3BED0",attention:"#F5C27F",attentionSoft:"#493824",amberInk:"#EDCE8E",amberCard:"#413821",amberRule:"#A48C50",success:"#AFD4B0",danger:"#F8ABB8",onDanger:"#381A29",bubbleUser:"#41323D",scrollbar:"#705768",scrollbarHover:"#9C7F90",termScrollbar:"#705B71",shell:"#17131D",shellInk:"#E5D6E3",shellInkStrong:"#F9EDF1",shellInkSoft:"#BAA3BC",shellDanger:"#F8ABB8",shellHairline:"#46384D",shellHover:"#302638",shadowInk:"#000000"}}}},{kind:"kiki-skin",version:1,id:"iris",name:"鸢尾 Iris × 星幕 Starveil",description:"Violet-white paper and iris ink; indigo-violet layers and silver-lilac controls at night.",variants:{light:{colors:{canvas:"#E7E3F2",paper:"#F6F3FC",panel:"#FCFAFF",hairline:"#D5CEE5",hairlineStrong:"#A99BBF",ink:"#302B48",inkSoft:"#514964",inkFaint:"#615775",accent:"#6542A5",accentDeep:"#4D2F86",accentSoft:"#EAE1F7",accentInk:"#53318B",onAccent:"#FFFFFF",sectionInk:"#514964",selected:"#E7DEF4",selectedInk:"#593793",attention:"#98491B",attentionSoft:"#F7E5D5",amberInk:"#78500B",amberCard:"#F7ECCF",amberRule:"#AE8E45",success:"#306448",danger:"#B1294E",onDanger:"#FFFFFF",bubbleUser:"#ECE6F6",scrollbar:"#BEB1D5",scrollbarHover:"#9985BA",termScrollbar:"#595179",shell:"#211D34",shellInk:"#DED9F0",shellInkStrong:"#F5F0FF",shellInkSoft:"#AAA0C5",shellDanger:"#F0A5BF",shellHairline:"#413857",shellHover:"#312A49",shadowInk:"#29203F"}},dark:{colors:{canvas:"#171626",paper:"#232137",panel:"#312F4A",hairline:"#44405F",hairlineStrong:"#71668F",ink:"#EEECFA",inkSoft:"#CAC3E2",inkFaint:"#ADA4C7",accent:"#C5ADF6",accentDeep:"#DECCFF",accentSoft:"#3D305B",accentInk:"#DECCFF",onAccent:"#27183F",sectionInk:"#CAC3E2",selected:"#35304F",selectedInk:"#D4C6F7",attention:"#F1BE86",attentionSoft:"#413226",amberInk:"#E8CC87",amberCard:"#3C3422",amberRule:"#9E884C",success:"#A5D6BA",danger:"#F3A6C2",onDanger:"#34182A",bubbleUser:"#36304D",scrollbar:"#63577E",scrollbarHover:"#9180B2",termScrollbar:"#615577",shell:"#100F1B",shellInk:"#D8D1EF",shellInkStrong:"#F3EFFF",shellInkSoft:"#ABA0C9",shellDanger:"#F3A6C2",shellHairline:"#39304E",shellHover:"#272238",shadowInk:"#000000"}}}},{kind:"kiki-skin",version:1,id:"contrast",name:"高对比 High contrast × 高对比·黑曜 Obsidian",description:"White paper, black text and visible borders; layered charcoal, ice-cyan focus and near-white controls at night.",variants:{light:{colors:{canvas:"#E7E9EC",paper:"#FFFFFF",panel:"#FFFFFF",hairline:"#6E7781",hairlineStrong:"#20252C",ink:"#0E1116",inkSoft:"#20252C",inkFaint:"#353B44",accent:"#0349B4",accentDeep:"#023787",accentSoft:"#DBE7FB",accentInk:"#023B95",onAccent:"#FFFFFF",sectionInk:"#0E1116",selected:"#DBE7FB",selectedInk:"#023B95",attention:"#A2280A",attentionSoft:"#FDE3D9",amberInk:"#6B3D00",amberCard:"#FDF0CF",amberRule:"#8A5A00",success:"#055D20",danger:"#A0111F",onDanger:"#FFFFFF",bubbleUser:"#F3F3F3",scrollbar:"#C9CBCE",scrollbarHover:"#B3B5B9",termScrollbar:"#4D4F53",shell:"#0E1116",shellInk:"#D4D4D5",shellInkStrong:"#F1F1F1",shellInkSoft:"#939698",shellDanger:"#F0A39C",shellHairline:"#303237",shellHover:"#212429",shadowInk:"#0A0C0F"},fonts:{display:un,sans:Oe},shape:{radius:8}},dark:{colors:{canvas:"#101214",paper:"#1C2024",panel:"#2A3036",hairline:"#8A949E",hairlineStrong:"#C5CDD5",ink:"#F7F9FB",inkSoft:"#E1E6EB",inkFaint:"#C2CBD3",accent:"#E7EDF4",accentDeep:"#FFFFFF",accentSoft:"#303840",accentInk:"#F4F7FA",onAccent:"#11171C",sectionInk:"#F7F9FB",selected:"#303840",selectedInk:"#8DE3F0",attention:"#FFD080",attentionSoft:"#30343A",amberInk:"#F5D58C",amberCard:"#30343A",amberRule:"#BAA276",success:"#A4E0B2",danger:"#FFADB8",onDanger:"#241318",bubbleUser:"#30363C",scrollbar:"#8A949E",scrollbarHover:"#C5CDD5",termScrollbar:"#89939D",shell:"#0C0F12",shellInk:"#E1E6EB",shellInkStrong:"#F7F9FB",shellInkSoft:"#BBC6D0",shellDanger:"#FFADB8",shellHairline:"#89939D",shellHover:"#22282E",shadowInk:"#000000"},fonts:{display:un,sans:Oe},shape:{radius:8}}}}];function Nn(e){return Tt.find(n=>n.id===e)}const dn={paper:"st.skin.desc.paperPair",porcelain:"st.skin.desc.porcelain",celadon:"st.skin.desc.celadon",apricot:"st.skin.desc.apricot",iris:"st.skin.desc.iris",contrast:"st.skin.desc.contrastPair"},fn={paper:"st.skin.name.paper",porcelain:"st.skin.name.porcelain",celadon:"st.skin.name.celadon",apricot:"st.skin.name.apricot",iris:"st.skin.name.iris",contrast:"st.skin.name.contrast"};function no(e){return e!==void 0&&Object.hasOwn(dn,e)?dn[e]:void 0}function to(e){return e!==void 0&&Object.hasOwn(fn,e)?fn[e]:void 0}const Rt=/^[a-z0-9][a-z0-9-]{0,63}$|^[a-z0-9][a-z0-9_-]{0,63}:[a-z0-9][a-z0-9-]{0,63}$/,O={selection:{source:"builtin",id:Mn},tweaks:{}},Tn="kiki.skin",Lt=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,Se=/^[\p{L}\p{N}\u4e00-\u9fff '",\-_. ]{1,200}$/u;function Ge(e){if(typeof e!="object"||e===null)return O;const n=e,t=n.selection,r=typeof t?.id=="string"&&Rt.test(t.id)&&(t.source==="builtin"||t.source==="user"||t.source==="pack")?{source:t.source,id:t.id}:O.selection,o=n.tweaks??{},i={...typeof o.accent=="string"&&Lt.test(o.accent)?{accent:o.accent}:{},...typeof o.fontSans=="string"&&Se.test(o.fontSans)?{fontSans:o.fontSans}:{},...typeof o.fontMono=="string"&&Se.test(o.fontMono)?{fontMono:o.fontMono}:{},...typeof o.fontProse=="string"&&Se.test(o.fontProse)?{fontProse:o.fontProse}:{},...typeof o.radius=="number"&&o.radius>=0&&o.radius<=28?{radius:o.radius}:{},...typeof o.spacing=="number"&&o.spacing>=.19&&o.spacing<=.33?{spacing:o.spacing}:{}};return{selection:$t(r),tweaks:i}}function $t(e){return e.source==="builtin"&&Nt.has(e.id)?O.selection:e}function Ht(){try{const e=E.getItem(Tn);return e===null?O:Ge(JSON.parse(e))}catch{return O}}const ie=.25;function Rn(e){const n=Ge(e),t=e.tweaks.spacing;return t===void 0||!Number.isFinite(t)||t<.5*ie||t>2*ie?n:{...n,tweaks:{...n.tweaks,spacing:t}}}function Ut(e){return{...e.accent===void 0?{}:{accent:e.accent},...e.fontSans===void 0?{}:{fontSans:e.fontSans},...e.fontMono===void 0?{}:{fontMono:e.fontMono},...e.fontProse===void 0?{}:{fontProse:e.fontProse},...e.radius===void 0?{}:{radius:e.radius},...e.spacing===void 0?{}:{spacing:e.spacing*ie}}}function xt(e){return{...e.accent===void 0?{}:{accent:e.accent},...e.fontSans===void 0?{}:{fontSans:e.fontSans},...e.fontMono===void 0?{}:{fontMono:e.fontMono},...e.fontProse===void 0?{}:{fontProse:e.fontProse},...e.radius===void 0?{}:{radius:e.radius},...e.spacing===void 0?{}:{spacing:Number((e.spacing/ie).toFixed(4))}}}function jt(){const e=Ie("skin");if(e!==void 0)return Rn({selection:e,tweaks:Ut(Ie("tweaks")??{})})}let pn,kn,mn=!1;function Kt(){const e=_n();return(!mn||pn!==e)&&(pn=e,kn=jt(),mn=!0),kn}const Pe=new Set;let T;function ro(e){return Pe.add(e),()=>{Pe.delete(e)}}function We(){const e=Kt();return e!==void 0?(T=e,e):(T??=Ht(),T)}function oo(){return O}function $(){for(const e of Pe)e()}function zt(e){if(JSON.stringify(e)===JSON.stringify(T)){$();return}T=e,$()}function Vt(e){const n={...We(),...e},t=te()?Rn(n):Ge(n);if(te()){Be("skin",t.selection),e.tweaks!==void 0&&Be("tweaks",xt(t.tweaks));return}try{E.setItem(Tn,JSON.stringify(t))}catch{}zt(t)}wn(()=>{T=void 0,$()});let se=null;function io(e){const n=JSON.stringify(e)!==JSON.stringify(se);se=e,n&&$()}function so(){return se}function Jt(){return se??We()}const Me="kiki.skin.cache";function Gt(){try{const e=E.getItem(Me);return e===null?null:yn(JSON.parse(e)).skin}catch{return null}}function Ln(e){try{e===null?E.removeItem(Me):E.setItem(Me,JSON.stringify(e))}catch{}}let ae=[],Ne=null,U=null,ce=!1;function ao(e,n){const t=n!==Ne||JSON.stringify(e)!==JSON.stringify(ae);ae=e,Ne=n;const r=Jt().selection;if(r.source==="user"){const o=e.find(i=>i.id===r.id)??null;U=o,ce=!0,Ln(o)}t&&$()}function co(){return ae}function lo(){return Ne}let Te=Wt();const $n="kiki.skin.packCache";function Wt(){try{const e=E.getItem($n);if(e===null)return[];const n=JSON.parse(e);return Array.isArray(n)?n.map(t=>yn(t).skin).filter(t=>t!==null):[]}catch{return[]}}function uo(e){if(JSON.stringify(e)!==JSON.stringify(Te)){Te=e;try{E.setItem($n,JSON.stringify(e))}catch{}$()}}function fo(){U=null,ce=!1,Ln(null)}function Yt(e){if(e.source==="builtin")return Nn(e.id)??null;if(e.source==="pack")return Te.find(t=>t.id===e.id)??null;const n=ae.find(t=>t.id===e.id);return n!==void 0?n:(ce||(U=Gt(),ce=!0),U?.id===e.id?U:null)}function po(e){if(typeof document>"u")return;const n=document.documentElement;n.dataset.kikiMotion=e.motion,n.dataset.kikiProse=e.proseFont}const Q={theme:"system",motion:"system",proseFont:"serif",skin:O,background:J};function ko(){const e=tt();return{theme:e.theme,motion:e.motion,proseFont:e.proseFont,skin:We(),background:pe()}}function mo(e){return e.motion===Q.motion&&e.proseFont===Q.proseFont&&JSON.stringify(e.skin)===JSON.stringify(Q.skin)&&e.background.light===null&&e.background.dark===null}function ho(e){return{...Q,theme:e.theme}}function go(e){rt({theme:e.theme,motion:e.motion,proseFont:e.proseFont}),Vt(e.skin),Ct(e.background)}const Z={canvas:["--color-canvas"],paper:["--color-paper","--color-muted","--color-sidebar"],panel:["--color-panel","--color-background"],hairline:["--color-hairline","--color-border","--color-input"],hairlineStrong:["--color-hairline-strong"],ink:["--color-ink","--color-foreground"],inkSoft:["--color-ink-soft","--color-muted-foreground"],inkFaint:["--color-ink-faint"],accent:["--color-accent","--color-primary"],accentDeep:["--color-accent-deep"],accentSoft:["--color-accent-soft"],accentInk:["--color-accent-ink"],onAccent:["--color-on-accent","--color-primary-foreground"],sectionInk:["--color-section-ink"],selected:["--color-selected"],selectedInk:["--color-selected-ink"],attention:["--color-attention"],attentionSoft:["--color-attention-soft"],amberInk:["--color-amber-ink"],amberCard:["--color-amber-card"],amberRule:["--color-amber-rule"],success:["--color-success"],danger:["--color-danger"],onDanger:["--color-on-danger"],bubbleUser:["--color-bubble-user"],scrollbar:["--color-scrollbar"],scrollbarHover:["--color-scrollbar-hover"],termScrollbar:["--color-term-scrollbar"],shell:["--color-shell"],shellInk:["--color-shell-ink"],shellInkStrong:["--color-shell-ink-strong"],shellInkSoft:["--color-shell-ink-soft"],shellDanger:["--color-shell-danger"],shellHairline:["--color-shell-hairline"],shellHover:["--color-shell-hover"],shadowInk:[]},Hn={display:["--font-display"],sans:["--font-sans"],mono:["--font-mono"]};function qt(e){const n=e.replace("#",""),t=n.length===3?n.split("").map(o=>`${o}${o}`).join(""):n;return/^[0-9a-fA-F]{6}$/.test(t)?[0,2,4].map(o=>Number.parseInt(t.slice(o,o+2),16)).join(" "):null}function Fo(e,n){return e.variants[n]??null}function Xt(e){const n=[];return e.variants.light!==void 0&&n.push("light"),e.variants.dark!==void 0&&n.push("dark"),n}const hn="color-mix(in oklab, var(--color-accent) 72%, var(--color-ink))",Qt={sectionInk:"var(--color-ink-soft)",selected:"color-mix(in oklab, var(--color-accent) 12%, var(--color-panel))",selectedInk:"var(--color-accent-ink)",attention:"var(--color-accent-ink)",attentionSoft:"var(--color-accent-soft)"};function bo(e,n={}){const t={};for(const[o,i]of Object.entries(e?.colors??{}))if(typeof i=="string"){if(o==="shadowInk"){const s=qt(i);s!==null&&(t["--kiki-shadow-ink"]=s);continue}for(const s of Z[o]??[])t[s]=i}for(const[o,i]of Object.entries(e?.fonts??{}))if(typeof i=="string")for(const s of Hn[o]??[])t[s]=i;if(e?.colors?.accent!==void 0&&e.colors.accentInk===void 0&&(t["--color-accent-ink"]=hn),e?.colors!==void 0&&Object.keys(e.colors).length>0){for(const[o,i]of Object.entries(Qt))if(e.colors[o]===void 0)for(const s of Z[o])t[s]=i}const r=e?.shape;if(r?.radius!==void 0&&(t["--kiki-sheet-radius"]=`${r.radius}px`),r?.stageGap!==void 0&&(t["--kiki-stage-gap"]=`${r.stageGap}px`),r?.spacing!==void 0&&(t["--spacing"]=`${r.spacing}rem`),n.accent!==void 0){for(const o of Z.accent)t[o]=n.accent;t["--color-accent-deep"]=`color-mix(in oklab, ${n.accent} 78%, black)`,t["--color-accent-soft"]=`color-mix(in oklab, ${n.accent} 14%, var(--color-panel))`,t["--color-accent-ink"]=hn}return n.fontSans!==void 0&&(t["--font-sans"]=n.fontSans),n.fontMono!==void 0&&(t["--font-mono"]=n.fontMono),n.fontProse!==void 0&&(t["--kiki-prose-user"]=n.fontProse),n.radius!==void 0&&(t["--kiki-sheet-radius"]=`${n.radius}px`),n.spacing!==void 0&&(t["--spacing"]=`${n.spacing}rem`),t}function Zt(){return[...Object.values(Z).flat(),...Object.values(Hn).flat(),"--kiki-shadow-ink","--kiki-prose-user","--kiki-sheet-radius","--kiki-stage-gap","--spacing","--color-accent-deep","--color-accent-soft","--color-accent-ink"]}function vo(e,n){for(const t of Zt())e.style.removeProperty(t);for(const[t,r]of Object.entries(n))e.style.setProperty(t,r)}const A=new Map,er=8;function nr(){if(typeof window>"u")return 2560;const e=Math.min(2,window.devicePixelRatio||1),n=Math.max(window.screen?.width??0,window.screen?.height??0,window.innerWidth,window.innerHeight);return Math.min(3840,Math.max(1920,Math.ceil(n*e)))}const tr=320;function rr(){return typeof createImageBitmap=="function"&&typeof OffscreenCanvas<"u"}async function or(e,n){if(!e.type.startsWith("image/")||e.type==="image/gif"||!rr())return e;let t,r;try{t=await createImageBitmap(e);const o=Math.max(t.width,t.height);if(o<=n)return e;const i=n/o,s=Math.max(1,Math.round(t.width*i)),c=Math.max(1,Math.round(t.height*i));r=await createImageBitmap(t,{resizeWidth:s,resizeHeight:c,resizeQuality:"high"});const d=new OffscreenCanvas(s,c),f=d.getContext("bitmaprenderer");return f===null?e:(f.transferFromImageBitmap(r),r=void 0,await d.convertToBlob({type:"image/webp",quality:.9}))}catch{return e}finally{t?.close(),r?.close()}}function ir(){for(;A.size>er;){const e=A.keys().next().value;A.delete(e)}}function Un(e,n,t){const r=`${e}|${n}`,o=A.get(r);if(o!==void 0)return A.delete(r),A.set(r,o),o.catch(()=>null);const i=t().then(s=>s===null?Promise.reject(new Error("missing")):or(s,n));return A.set(r,i),ir(),i.catch(()=>(A.get(r)===i&&A.delete(r),null))}const sr="kiki-appearance",Re="media",P=new Map;let Le=null;function xn(){return Le??=new Promise(e=>{if(typeof indexedDB>"u"){e(null);return}try{const n=indexedDB.open(sr,1);n.onupgradeneeded=()=>{n.result.createObjectStore(Re)},n.onsuccess=()=>{e(n.result)},n.onerror=()=>{e(null)}}catch{e(null)}}),Le}function ke(e,n){return xn().then(t=>new Promise((r,o)=>{if(t===null){r(void 0);return}const i=t.transaction(Re,e),s=n(i.objectStore(Re));i.oncomplete=()=>{r(s.result)},i.onabort=()=>{o(i.error??new Error("media store aborted"))},i.onerror=()=>{o(i.error??new Error("media store failed"))},s.onerror=()=>{o(s.error??new Error("media store failed"))}}))}const G=new Set;async function So(){return await xn()!==null&&G.size===0}async function ar(e,n){P.set(e,n),await ke("readwrite",r=>r.put(n,e)).catch(()=>{})===void 0?G.add(e):G.delete(e)}async function cr(e){const n=P.get(e);if(n!==void 0)return n;const t=await ke("readonly",r=>r.get(e)).catch(()=>{});return t===void 0?null:(P.set(e,t),t)}async function lr(e){P.delete(e),G.delete(e),await ke("readwrite",n=>n.delete(e)).catch(()=>{})}async function Eo(e,n=e.name){const t=n===void 0?null:An(n),r=await ur(e),o=ot(r);if(o===null)return{ok:!1,reason:t===null?"type":"content"};if(t!==null&&t.mime!==o)return{ok:!1,reason:"content"};const i=o.startsWith("video/")?"video":"image",s=i==="video"?Xe.videoBytes:Xe.imageBytes;return e.size>s?{ok:!1,reason:"size"}:{ok:!0,kind:i,mime:o}}function ur(e){return new Promise(n=>{const t=new FileReader;t.onload=()=>{n(new Uint8Array(t.result))},t.onerror=()=>{n(new Uint8Array)},t.readAsArrayBuffer(e.slice(0,32))})}function yo(e,n){const t=e.type===n.mime?e:new Blob([e],{type:n.mime}),r=URL.createObjectURL(t),o=document.createElement(n.kind==="video"?"video":"img");return new Promise(i=>{const s=d=>{clearTimeout(c),o.onload=null,o.onerror=null,o instanceof HTMLVideoElement?(o.onloadeddata=null,o.removeAttribute("src"),o.load()):o.removeAttribute("src"),URL.revokeObjectURL(r),i(d)},c=setTimeout(()=>{s(!1)},15e3);o.onerror=()=>{s(!1)},o instanceof HTMLVideoElement?(o.muted=!0,o.preload="auto",o.onloadeddata=()=>{s(o.videoWidth>0&&o.videoHeight>0)}):o.onload=()=>{s(o.naturalWidth>0)},o.src=r})}let gn=0;async function Ao(e,n,t){gn+=1;const r=`local-${Date.now().toString(36)}-${gn.toString(36)}`;return await ar(r,e.type===n.mime?e:new Blob([e],{type:n.mime})),{id:r,kind:n.kind,mime:n.mime,name:t.slice(0,200),bytes:e.size}}async function Co(e){for(const t of Array.from(P.keys()))e.has(t)||P.delete(t);const n=await ke("readonly",t=>t.getAllKeys()).catch(()=>{});for(const t of n??[])typeof t=="string"&&!e.has(t)&&await lr(t)}function Do(){P.clear(),G.clear(),Le=null}const jn={missing:!1,heavyVideo:!1,paused:null,surfaceAlpha:null,textAlpha:null};let ee=jn;const $e=new Set;function Io(){return ee}function Bo(e){return $e.add(e),()=>{$e.delete(e)}}function B(e){const n={...ee,...e};if(JSON.stringify(n)!==JSON.stringify(ee)){ee=n;for(const t of $e)t()}}const le=new Map;let He=!0;function dr(e){return le.get(e)}function Kn(e,n){if(!(le.has(n)||typeof document>"u"))try{const t=document.createElement("canvas");t.width=48,t.height=32;const r=t.getContext("2d",{willReadFrequently:!0});if(r===null)return;r.drawImage(e,0,0,t.width,t.height),le.set(n,Pt(r.getImageData(0,0,t.width,t.height).data))}catch{}}function Ee(e){return getComputedStyle(document.documentElement).getPropertyValue(e).trim()}function fr(){const e=["--color-ink","--color-ink-soft","--color-ink-faint"].map(Ee),n=Ee("--color-canvas");return["--color-canvas","--color-paper","--color-panel"].map(t=>({surface:Ee(t),ground:n,texts:e}))}let I=null,p={key:"",element:null,urls:[]},N=null,x,w=0,k=null,R=0;function zn(){if(I!==null&&I.root.isConnected)return I;const e=document.createElement("div");e.dataset.kikiBackdrop="",e.setAttribute("aria-hidden","true");const n=document.createElement("div");n.dataset.kikiBackdropMedia="";const t=document.createElement("div");return t.dataset.kikiBackdropScrim="",e.append(n,t),document.body.prepend(e),I={root:e,media:n,scrim:t},I}function Vn(){const e=document.documentElement.dataset.kikiMotion;return e==="reduce"?!1:e==="full"?!0:!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches}let Jn=!1;function pr(){navigator.getBattery?.().then(n=>{const t=()=>{Jn=!n.charging&&n.level<.2,W()};n.addEventListener("levelchange",t),n.addEventListener("chargingchange",t),t()}).catch(()=>{})}function kr(){return Vn()?document.visibilityState==="hidden"||!document.hasFocus()?"hidden":Jn?"power":null:"motion"}function W(){const e=p.element instanceof HTMLVideoElement?p.element:null;if(e===null){B({paused:null});return}const n=kr();B({paused:n==="hidden"?null:n}),n===null?e.play().catch(()=>{}):e.pause()}function Gn(){for(const e of p.urls)URL.revokeObjectURL(e);p={key:"",element:null,urls:[]},N=null}async function Fn(e,n,t,r=!1){const o=e.kind==="image"&&!r?await Un(e.id,nr(),()=>n(e)):await n(e);if(o===null)return null;const i=URL.createObjectURL(o);return t.push(i),i}async function mr(e){if(le.has(e.id)||typeof createImageBitmap!="function")return;const n=await Un(e.id,tr,()=>H(e));if(n!==null)try{const t=await createImageBitmap(n,{resizeWidth:48,resizeHeight:32,resizeQuality:"low"});Kn(t,e.id),t.close()}catch{}}let H=e=>cr(e.id);function wo(e){e!==H&&(H=e,k!==null&&p.element===null&&(N=null,Ue(k,w,R)))}function _o(e){return H(e)}function bn(e,n,t){const{look:r}=n,o=[r.blur>0?`blur(${r.blur}px)`:"",r.brightness!==1?`brightness(${r.brightness})`:""].filter(Boolean).join(" ");if(e.style.opacity=String(r.opacity),e.style.filter=o,t!==null){e.style.backgroundImage=`url("${t}")`,e.style.backgroundRepeat="repeat",e.style.backgroundPosition=ln(r.alignment);return}e.style.objectFit=r.fit==="contain"?"contain":r.fit==="center"?"none":"cover",e.style.objectPosition=ln(r.alignment)}async function Ue(e,n,t){const{media:r}=zn(),o=e.media[n%e.media.length],i=`${e.packId??""}|${o.id}|${e.look.fit}`;if(p.key===i&&p.element!==null){bn(p.element,e,p.element instanceof HTMLDivElement?p.urls[0]??null:null),W();return}if(N?.key===i)return;const s={key:i};N=s;const c=[],d=()=>t!==R||N!==s,f=await Fn(o,H,c,e.look.fit==="tile");let h=null;if(f!==null&&o.kind==="video"&&e.poster!==void 0&&!d()&&(h=await Fn(e.poster,H,c)),d()){for(const a of c)URL.revokeObjectURL(a);return}N=null;const y=k??e;if(f===null){Gn(),r.replaceChildren(),B({missing:!0});return}let l;if(o.kind==="video"){const a=document.createElement("video");a.muted=!0,a.defaultMuted=!0,a.loop=!0,a.playsInline=!0,a.autoplay=!1,a.preload="auto",a.disablePictureInPicture=!0,a.setAttribute("muted",""),a.setAttribute("playsinline",""),h!==null&&(a.poster=h),a.addEventListener("loadeddata",()=>{p.element===a&&(Kn(a,o.id),B({heavyVideo:a.videoWidth*a.videoHeight>2560*1440}),k!==null&&xe(k))},{once:!0}),a.src=f,l=a}else{if(e.look.fit==="tile")l=document.createElement("div");else{const a=document.createElement("img");a.decoding="async",a.alt="",a.src=f,l=a}mr(o).then(()=>{k!==null&&p.key===i&&xe(k)})}l.addEventListener("error",()=>{p.element===l&&B({missing:!0,heavyVideo:!1})},{once:!0}),l.dataset.kikiBackdropItem=o.kind,bn(l,y,l instanceof HTMLDivElement?f:null),r.replaceChildren(l);for(const a of p.urls)URL.revokeObjectURL(a);p={key:i,element:l,urls:c},B({missing:!1,heavyVideo:!1}),W()}function xe(e){const n=document.documentElement,t=e.sample??dr(e.media[w%e.media.length].id),r=e.look.surfaceOpacity,o=He?Math.max(...fr().map(s=>Ot(s,e.look,t,r))):r,i=r>=1?0:Math.max(0,(o-r)/(1-r));n.style.setProperty("--kiki-surface-alpha",`${Math.round(r*100)}%`),n.style.setProperty("--kiki-text-alpha",`${Math.ceil(i*100)}%`),n.style.setProperty("--kiki-solid-alpha",`${Math.ceil(o*100)}%`),n.style.setProperty("--kiki-surface-blur",`${e.look.surfaceBlur}px`),n.style.setProperty("--kiki-backdrop-scrim",String(e.look.scrim)),n.style.setProperty("--kiki-backdrop-overscan",`${Math.ceil(e.look.blur*3)}px`),He?n.dataset.kikiBgAssist="":delete n.dataset.kikiBgAssist,B({surfaceAlpha:r,textAlpha:o})}function Wn(){R+=1,clearInterval(x),x=void 0,k=null,Gn(),I?.root.remove(),I=null;const e=document.documentElement;delete e.dataset.kikiBg,delete e.dataset.kikiBgAssist;for(const n of["--kiki-surface-alpha","--kiki-text-alpha","--kiki-solid-alpha","--kiki-surface-blur","--kiki-backdrop-scrim","--kiki-backdrop-overscan"])e.style.removeProperty(n);B(jn)}function Oo(e,n=!0){if(typeof document>"u")return;if(He=n,e===null){(k!==null||I!==null)&&Wn();return}const t=JSON.stringify(k?.media)!==JSON.stringify(e.media)||k?.packId!==e.packId;k=e,t&&(R+=1,w=0),document.documentElement.dataset.kikiBg=e.look.scope,zn().root.dataset.scope=e.look.scope,e.look.scope!=="window"&&(vn(),requestAnimationFrame(vn)),xe(e),Ue(e,w,R),clearInterval(x),x=void 0,e.media.length>1&&e.interval>0&&Vn()&&(x=setInterval(()=>{k===null||document.visibilityState==="hidden"||(w=(w+1)%k.media.length,Ue(k,w,R))},e.interval*1e3))}let j=null,D=null;function ue(){const e=D?.getBoundingClientRect().right??0;document.documentElement.style.setProperty("--kiki-backdrop-sidebar",`${Math.round(e)}px`)}function vn(){if(typeof ResizeObserver>"u")return;const e=document.querySelector(".app-sidebar");e!==D&&(j??=new ResizeObserver(ue),D!==null&&j.unobserve(D),D=e,D!==null&&j.observe(D),ue())}function hr(){return window.addEventListener("resize",ue),()=>{window.removeEventListener("resize",ue),j?.disconnect(),j=null,D=null,document.documentElement.style.removeProperty("--kiki-backdrop-sidebar")}}let ye=!1;function Po(){if(ye||typeof window>"u")return()=>{};ye=!0;const e=()=>{W()};document.addEventListener("visibilitychange",e),window.addEventListener("focus",e),window.addEventListener("blur",e);const n=window.matchMedia?.("(prefers-reduced-motion: reduce)");n?.addEventListener?.("change",e),pr();const t=hr();return()=>{ye=!1,t(),document.removeEventListener("visibilitychange",e),window.removeEventListener("focus",e),window.removeEventListener("blur",e),n?.removeEventListener?.("change",e),Wn()}}function Mo(){typeof document<"u"&&W()}const je="pack:";function gr(e,n){return`${je}${e}/${n}`}function No(e){if(!e.startsWith(je))return null;const n=e.slice(je.length),t=n.indexOf("/");return t<=0?null:{packId:n.slice(0,t),file:n.slice(t+1)}}function Sn(e,n){const t=An(n);return t===null?null:{id:gr(e,n),kind:t.kind,mime:t.mime,name:n,bytes:0}}function En(e,n){if(n===void 0)return null;const{media:t,poster:r,interval:o,shuffle:i,...s}=n,c=t.map(d=>Sn(e,d)).filter(d=>d!==null);return c.length===0?null:{media:c,poster:r===void 0?void 0:Sn(e,r)??void 0,interval:o??0,look:On(s),packId:e}}function To(e){const n=En(e.id,e.variants.light?.background),t=En(e.id,e.variants.dark?.background);return n===null||t===null?{light:n??t,dark:null,linked:!0}:{light:n,dark:t,linked:!1}}function Ro(e){const n=o=>{const i=e.variants[o];if(i===void 0)return;const{background:s,...c}=i;return c.colors===void 0&&c.fonts===void 0&&c.shape===void 0?void 0:c},t=n("light"),r=n("dark");return t===void 0&&r===void 0?null:{kind:"kiki-skin",version:1,id:e.id,name:e.name,description:e.description,author:e.author,variants:{light:t,dark:r}}}function Ae(e,n){const t={...e.colors};n.tweaks.accent!==void 0&&(t.accent=n.tweaks.accent);const r={...e.fonts};n.tweaks.fontSans!==void 0&&(r.sans=n.tweaks.fontSans),n.tweaks.fontMono!==void 0&&(r.mono=n.tweaks.fontMono);const o={...e.shape};return n.tweaks.radius!==void 0&&(o.radius=n.tweaks.radius),n.tweaks.spacing!==void 0&&(o.spacing=n.tweaks.spacing),{...e.base!==void 0?{base:e.base}:{},...Object.keys(t).length>0?{colors:t}:{},...Object.keys(r).length>0?{fonts:r}:{},...Object.keys(o).length>0?{shape:o}:{}}}function Lo(e,n){const t=Yt(e.selection)??Nn("paper")??null,r=Fr(n)||"my-skin",o={};for(const s of t===null?[]:Xt(t))o[s]=Ae(t?.variants[s]??{},e);Object.keys(o).length===0&&(o.light=Ae({},e),o.dark=Ae({},e));const i={$schema:"https://kiki.dev/schema/skin-v1.json",kind:"kiki-skin",version:1,id:r,name:n.trim()===""?"My skin":n.trim(),...t?.description!==void 0?{description:t.description}:{},variants:o};return{filename:`${r}.json`,json:`${JSON.stringify(i,null,2)}
2
- `}}function Fr(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,64).replace(/^[^a-z0-9]+/,"")}export{Ge as $,hn as A,Tt as B,Z as C,Q as D,no as E,Qt as F,to as G,yo as H,Eo as I,fo as J,It as K,ho as L,lr as M,eo as N,Nn as O,je as P,cr as Q,Nt as R,co as S,wt as T,lo as U,qt as V,mo as W,So as X,dr as Y,Je as Z,On as _,po as a,ne as a$,nn as a0,ln as a1,To as a2,gr as a3,Ro as a4,be as a5,No as a6,Co as a7,ar as a8,ko as a9,tr as aA,wn as aB,Hr as aC,Lr as aD,jr as aE,Rr as aF,$r as aG,Ur as aH,zr as aI,Vr as aJ,_n as aK,Tr as aL,St as aM,xr as aN,Be as aO,yr as aP,Kr as aQ,ct as aR,Ke as aS,Mr as aT,Pr as aU,Ir as aV,Nr as aW,Or as aX,st as aY,Sr as aZ,Cr as a_,Ht as aa,Gr as ab,Ot as ac,_e as ad,Qr as ae,Do as af,_o as ag,Pt as ah,wo as ai,uo as aj,io as ak,ao as al,oo as am,We as an,so as ao,Fr as ap,Wr as aq,yt as ar,jt as as,xt as at,Ao as au,Bo as av,go as aw,Ct as ax,Vt as ay,Un as az,vo as b,Dr as b0,F as b1,wr as b2,lt as b3,_r as b4,Ar as b5,Br as b6,Dn as b7,Er as b8,Xr as c,Oo as d,Jt as e,Mo as f,Xt as g,Fo as h,ro as i,Jr as j,dn as k,fn as l,J as m,Mn as n,O as o,Hn as p,Zt as q,Yt as r,Zr as s,Io as t,Yr as u,bo as v,Po as w,qr as x,pe as y,Lo as z};
@@ -1 +0,0 @@
1
- import{u as c,v as x,w as d}from"./mermaid-GHXKKRXX-sDJax95P.js";import{r as i,j as f}from"./index-B0KPRi1U.js";import"./connection-C8nwzwXB.js";import"./index-CJqIcuAl.js";import"./client-CXcrCawx.js";import"./LifeMark-UBMVaTWr.js";import"./theme-6OL1RXgY.js";import"./export-Bn8PqPg4.js";import"./spaces-DqMTtCXX.js";var B=({code:s,language:e,raw:t,className:l,startLine:u,lineNumbers:p,...n})=>{let{shikiTheme:o}=i.useContext(c),r=x(),[g,a]=i.useState(t);return i.useEffect(()=>{if(!r){a(t);return}let m=r.highlight({code:s,language:e,themes:o},h=>{a(h)});m&&a(m)},[s,e,o,r,t]),f.jsx(d,{className:l,language:e,lineNumbers:p,result:g,startLine:u,...n})};export{B as HighlightedCodeBlockBody};