kiki-agent 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/en/configuration/config-files.md +32 -19
- package/dist/docs/en/configuration/data-locations.md +23 -1
- package/dist/docs/en/configuration/env-vars.md +6 -8
- package/dist/docs/en/configuration/overrides.md +19 -8
- package/dist/docs/en/configuration/providers.md +75 -4
- package/dist/docs/en/customization/agents-and-subagents.md +6 -2
- package/dist/docs/en/customization/personas.md +36 -2
- package/dist/docs/en/customization/plugins.md +41 -1
- package/dist/docs/en/customization/prompt-fields.md +4 -0
- package/dist/docs/en/features/agent-workflows.md +8 -8
- package/dist/docs/en/features/browser-and-computer.md +40 -0
- package/dist/docs/en/features/daily.md +10 -10
- package/dist/docs/en/features/ecosystem.md +5 -5
- package/dist/docs/en/features/extend.md +9 -8
- package/dist/docs/en/features/freedom.md +8 -8
- package/dist/docs/en/features/index.md +44 -28
- package/dist/docs/en/features/long-work.md +9 -9
- package/dist/docs/en/features/look.md +5 -5
- package/dist/docs/en/features/people.md +6 -6
- package/dist/docs/en/features/phone.md +5 -3
- package/dist/docs/en/features/spaces.md +7 -7
- package/dist/docs/en/features/workbench.md +8 -8
- package/dist/docs/en/guides/interface.md +16 -4
- package/dist/docs/en/guides/sessions.md +6 -2
- package/dist/docs/en/guides/settings.md +15 -2
- package/dist/docs/en/reference/command.md +58 -1
- package/dist/docs/en/reference/tools.md +25 -5
- package/dist/docs/en/server/acp.md +3 -1
- package/dist/docs/en/server/mcp.md +5 -1
- package/dist/docs/en/server/rest-api.md +115 -4
- package/dist/docs/zh/configuration/config-files.md +32 -19
- package/dist/docs/zh/configuration/data-locations.md +23 -1
- package/dist/docs/zh/configuration/env-vars.md +6 -8
- package/dist/docs/zh/configuration/overrides.md +19 -8
- package/dist/docs/zh/configuration/providers.md +75 -4
- package/dist/docs/zh/customization/agents-and-subagents.md +6 -2
- package/dist/docs/zh/customization/personas.md +36 -2
- package/dist/docs/zh/customization/plugins.md +41 -1
- package/dist/docs/zh/customization/prompt-fields.md +4 -0
- package/dist/docs/zh/features/agent-workflows.md +10 -10
- package/dist/docs/zh/features/browser-and-computer.md +40 -0
- package/dist/docs/zh/features/daily.md +10 -10
- package/dist/docs/zh/features/ecosystem.md +5 -5
- package/dist/docs/zh/features/extend.md +8 -7
- package/dist/docs/zh/features/freedom.md +8 -8
- package/dist/docs/zh/features/index.md +44 -28
- package/dist/docs/zh/features/long-work.md +8 -8
- package/dist/docs/zh/features/look.md +5 -5
- package/dist/docs/zh/features/people.md +5 -5
- package/dist/docs/zh/features/phone.md +5 -3
- package/dist/docs/zh/features/spaces.md +7 -7
- package/dist/docs/zh/features/workbench.md +8 -8
- package/dist/docs/zh/guides/interface.md +16 -4
- package/dist/docs/zh/guides/sessions.md +6 -2
- package/dist/docs/zh/guides/settings.md +15 -2
- package/dist/docs/zh/reference/command.md +58 -1
- package/dist/docs/zh/reference/tools.md +25 -5
- package/dist/docs/zh/server/acp.md +3 -1
- package/dist/docs/zh/server/mcp.md +5 -1
- package/dist/docs/zh/server/rest-api.md +114 -3
- package/dist/hostRunner.mjs +92 -1
- package/dist/mailbox-worker.mjs +297 -0
- package/dist/main.mjs +2 -2
- package/dist/native/windows-process-helper.exe +0 -0
- package/dist/query-store-worker.mjs +446 -0
- package/dist/sqlite-indexer.mjs +223 -401
- package/dist/sqlite-query-worker.mjs +226 -249
- package/dist/usage-parser-worker.mjs +24 -5
- package/dist/web/assets/AppErrorBoundary-BN6IDdP1.js +1 -0
- package/dist/web/assets/{LifeMark-CL6-HWDu.js → LifeMark-UBMVaTWr.js} +1 -1
- package/dist/web/assets/{NavScopeBoundary-CFCnvZR0.js → NavScopeBoundary-BCryw-UG.js} +1 -1
- package/dist/web/assets/{arc-DYDCMlOS.js → arc-C7IAvCCJ.js} +1 -1
- package/dist/web/assets/{architectureDiagram-3BPJPVTR-C9Y7T0O2.js → architectureDiagram-3BPJPVTR-CbwFBxn7.js} +1 -1
- package/dist/web/assets/{blockDiagram-GPEHLZMM-CdUrp-tD.js → blockDiagram-GPEHLZMM-B20N4t8r.js} +1 -1
- package/dist/web/assets/{c4Diagram-AAUBKEIU-PrwvB9IJ.js → c4Diagram-AAUBKEIU-3BYtlcP-.js} +1 -1
- package/dist/web/assets/channel-BJs5vJuh.js +1 -0
- package/dist/web/assets/{chunk-2J33WTMH-BL56g_Es.js → chunk-2J33WTMH-CpjgczxM.js} +1 -1
- package/dist/web/assets/{chunk-4BX2VUAB-DvJD5M9M.js → chunk-4BX2VUAB-BScxUF5G.js} +1 -1
- package/dist/web/assets/{chunk-55IACEB6-C8f-nzvx.js → chunk-55IACEB6-CrcLYJXd.js} +1 -1
- package/dist/web/assets/{chunk-727SXJPM-DOGkWKkV.js → chunk-727SXJPM-BwlyIOjw.js} +1 -1
- package/dist/web/assets/{chunk-AQP2D5EJ-fFOuz7g6.js → chunk-AQP2D5EJ-DKKIRkRv.js} +1 -1
- package/dist/web/assets/{chunk-FMBD7UC4-BpeXZ9LM.js → chunk-FMBD7UC4-CVDMj2kX.js} +1 -1
- package/dist/web/assets/{chunk-ND2GUHAM-CRUh76fb.js → chunk-ND2GUHAM-CL-PM6r8.js} +1 -1
- package/dist/web/assets/{chunk-QZHKN3VN-uNfxaPk0.js → chunk-QZHKN3VN-DPV2KbKZ.js} +1 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-BookeACB.js +1 -0
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-BookeACB.js +1 -0
- package/dist/web/assets/client-CXcrCawx.js +3 -0
- package/dist/web/assets/connection-C8nwzwXB.js +1 -0
- package/dist/web/assets/{cose-bilkent-S5V4N54A-BNkxG-qX.js → cose-bilkent-S5V4N54A-D1CEiQM6.js} +1 -1
- package/dist/web/assets/{dagre-BM42HDAG-BerioUei.js → dagre-BM42HDAG-BlFV941E.js} +1 -1
- package/dist/web/assets/{diagram-2AECGRRQ-Czv2SR07.js → diagram-2AECGRRQ-BC0ldkFY.js} +1 -1
- package/dist/web/assets/{diagram-5GNKFQAL-Uzi1weGK.js → diagram-5GNKFQAL-B22Iej6G.js} +1 -1
- package/dist/web/assets/{diagram-KO2AKTUF-W36h_ff3.js → diagram-KO2AKTUF-B75UNw6D.js} +1 -1
- package/dist/web/assets/{diagram-LMA3HP47-FG4dDk52.js → diagram-LMA3HP47-CypI7IJM.js} +1 -1
- package/dist/web/assets/{diagram-OG6HWLK6-CQoEjIAY.js → diagram-OG6HWLK6-OsXumvcD.js} +1 -1
- package/dist/web/assets/{erDiagram-TEJ5UH35-Ck06KVyZ.js → erDiagram-TEJ5UH35-3756GOvS.js} +1 -1
- package/dist/web/assets/{export-T_izwEkQ.js → export-Bn8PqPg4.js} +1 -1
- package/dist/web/assets/{flowDiagram-I6XJVG4X-C5hgxdFZ.js → flowDiagram-I6XJVG4X-DB6Y_UDg.js} +1 -1
- package/dist/web/assets/{ganttDiagram-6RSMTGT7-BS52Pw5_.js → ganttDiagram-6RSMTGT7-CHJeuoAY.js} +1 -1
- package/dist/web/assets/{gitGraphDiagram-PVQCEYII-DLlQKZHs.js → gitGraphDiagram-PVQCEYII-Dj85554Y.js} +1 -1
- package/dist/web/assets/{highlighted-body-OFNGDK62-Btm6MuZ4.js → highlighted-body-OFNGDK62-DMgPHetp.js} +1 -1
- package/dist/web/assets/{index-CZX3qUe2.js → index-0tHq8zh2.js} +1 -1
- package/dist/web/assets/index-7ySDqvaN.css +1 -0
- package/dist/web/assets/index-B0KPRi1U.js +166 -0
- package/dist/web/assets/{index-CRDDqofN.js → index-B599VnpP.js} +1 -1
- package/dist/web/assets/{index-Cd62y0wD.js → index-BFK-GypQ.js} +1 -1
- package/dist/web/assets/{index-BMWid2q9.js → index-BPX8gmpB.js} +1 -1
- package/dist/web/assets/{index-5_yzg61S.js → index-BSGYc1tb.js} +1 -1
- package/dist/web/assets/{index-CJ92kLtO.js → index-BTt9Q5iv.js} +1 -1
- package/dist/web/assets/{index-B4iu4SJW.js → index-BWzUsoY_.js} +1 -1
- package/dist/web/assets/{index-CgcJPsK6.js → index-BYlSV3FO.js} +1 -1
- package/dist/web/assets/{index-BkPV0psm.js → index-BpXQ1q-u.js} +1 -1
- package/dist/web/assets/{index-Dceu0bqY.js → index-BqPxpGUh.js} +1 -1
- package/dist/web/assets/{index-CM-nNfuV.js → index-C6qeLCPw.js} +4 -4
- package/dist/web/assets/{index-ByiwExpV.js → index-C7mOS2T4.js} +1 -1
- package/dist/web/assets/{index-CG8uIlD7.js → index-C8OFfbEs.js} +1 -1
- package/dist/web/assets/{index-B-6LiYTY.js → index-CI7yuMGZ.js} +1 -1
- package/dist/web/assets/{index-B2Pu0Iuu.js → index-CJqIcuAl.js} +1 -1
- package/dist/web/assets/{index-BECSk4If.js → index-CTRJmDep.js} +1 -1
- package/dist/web/assets/{index-Bezli3SF.js → index-CXGCKoId.js} +1 -1
- package/dist/web/assets/{index-hG2s2Spn.js → index-CsY571EL.js} +1 -1
- package/dist/web/assets/{index-BFcyN2Zw.js → index-CwQG_9rB.js} +1 -1
- package/dist/web/assets/{index-BLU8_Um7.js → index-D--cw39y.js} +1 -1
- package/dist/web/assets/{index-B9MlqF7J.js → index-D260jsUJ.js} +1 -1
- package/dist/web/assets/{index-D_oPSlBL.js → index-DJjmEXx4.js} +1 -1
- package/dist/web/assets/{index-BNch_a4L.js → index-DRMjjql1.js} +1 -1
- package/dist/web/assets/{index-BeMvPEXs.js → index-DUxOVxHS.js} +1 -1
- package/dist/web/assets/{index-Ca607_hK.js → index-DZMkZKhW.js} +1 -1
- package/dist/web/assets/{index-BwcG86o3.js → index-DqK8MfQN.js} +1 -1
- package/dist/web/assets/{index-DKIysLbI.js → index-DxUmR9aV.js} +1 -1
- package/dist/web/assets/{index-Cy8C_eFR.js → index-GK8aa9pT.js} +1 -1
- package/dist/web/assets/{index-Bg99yVX_.js → index-bYtKyBMB.js} +1 -1
- package/dist/web/assets/{index-eUyF-8Sq.js → index-wxHFHTgD.js} +1 -1
- package/dist/web/assets/{infoDiagram-5YYISTIA-CD4XJGFm.js → infoDiagram-5YYISTIA-DeDPIdEH.js} +1 -1
- package/dist/web/assets/{ishikawaDiagram-YF4QCWOH-fu5E3_CT.js → ishikawaDiagram-YF4QCWOH-ButuBiBW.js} +1 -1
- package/dist/web/assets/{journeyDiagram-JHISSGLW-CXcnKBfJ.js → journeyDiagram-JHISSGLW-Dlbmqm-j.js} +1 -1
- package/dist/web/assets/{kanban-definition-UN3LZRKU-BawKH6Pl.js → kanban-definition-UN3LZRKU-tlQK1cOz.js} +1 -1
- package/dist/web/assets/{linear-BplJuXph.js → linear-iXuNfUWp.js} +1 -1
- package/dist/web/assets/mermaid-GHXKKRXX-sDJax95P.js +624 -0
- package/dist/web/assets/{mindmap-definition-RKZ34NQL-DA1SE2uy.js → mindmap-definition-RKZ34NQL-2qPv-mwT.js} +1 -1
- package/dist/web/assets/{pieDiagram-4H26LBE5-6i021QeX.js → pieDiagram-4H26LBE5-CrLe1C-O.js} +1 -1
- package/dist/web/assets/{quadrantDiagram-W4KKPZXB-CcKSZDMT.js → quadrantDiagram-W4KKPZXB-DfeIFxc0.js} +1 -1
- package/dist/web/assets/{requirementDiagram-4Y6WPE33-lYVuWRuD.js → requirementDiagram-4Y6WPE33-BWtjdxie.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-5OEKKPKP-4Zfb4_h4.js → sankeyDiagram-5OEKKPKP-B5TxJ6mb.js} +1 -1
- package/dist/web/assets/{sequenceDiagram-3UESZ5HK-DqltKmlY.js → sequenceDiagram-3UESZ5HK-Cf92ZCl1.js} +1 -1
- package/dist/web/assets/{spaces-CjuXbmxF.js → spaces-DqMTtCXX.js} +1 -1
- package/dist/web/assets/{stateDiagram-AJRCARHV-HFdhqxzx.js → stateDiagram-AJRCARHV-NR9I-Q4d.js} +1 -1
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-BiegFWxE.js +1 -0
- package/dist/web/assets/{theme-beWE_6f8.js → theme-6OL1RXgY.js} +1 -1
- package/dist/web/assets/{timeline-definition-PNZ67QCA-HNRxaB3t.js → timeline-definition-PNZ67QCA-CBAOVMfm.js} +1 -1
- package/dist/web/assets/{vennDiagram-CIIHVFJN-DwsCTyaD.js → vennDiagram-CIIHVFJN-C68x6TdS.js} +1 -1
- package/dist/web/assets/{wardley-L42UT6IY-BWW2wtVO.js → wardley-L42UT6IY-DuZZr5jm.js} +1 -1
- package/dist/web/assets/{wardleyDiagram-YWT4CUSO-C-ktKm7v.js → wardleyDiagram-YWT4CUSO-D6dVGtHd.js} +1 -1
- package/dist/web/assets/{xychartDiagram-2RQKCTM6-48AxNW9k.js → xychartDiagram-2RQKCTM6-DYLUhZX4.js} +1 -1
- package/dist/web/index.html +2 -2
- package/native/auth-native/prebuilds/linux-arm64/auth-native.node +0 -0
- package/native/auth-native/prebuilds/linux-x64/auth-native.node +0 -0
- package/native/auth-native/prebuilds/win32-arm64/auth-native.node +0 -0
- package/native/auth-native/prebuilds/win32-x64/auth-native.node +0 -0
- package/package.json +2 -2
- package/dist/search-worker.mjs +0 -14177
- package/dist/web/assets/AppErrorBoundary-DiGMUg4r.js +0 -1
- package/dist/web/assets/channel-Bj_gZ_Lv.js +0 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-ssCwe2R4.js +0 -1
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-ssCwe2R4.js +0 -1
- package/dist/web/assets/client-DGj93bGT.js +0 -3
- package/dist/web/assets/connection-Bpf-EjrL.js +0 -1
- package/dist/web/assets/index-BIebkSEI.css +0 -1
- package/dist/web/assets/index-D8z7lcQn.js +0 -166
- package/dist/web/assets/mermaid-GHXKKRXX-BO9hkP3Z.js +0 -621
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-Dx28QuZF.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
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};
|