kiki-agent 0.4.2 → 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.
- package/README.md +3 -3
- package/dist/cpu-worker.mjs +52744 -0
- package/dist/docs/en/configuration/config-files.md +121 -46
- package/dist/docs/en/configuration/data-locations.md +34 -7
- package/dist/docs/en/configuration/env-vars.md +37 -9
- package/dist/docs/en/configuration/overrides.md +20 -9
- package/dist/docs/en/configuration/providers.md +114 -9
- package/dist/docs/en/customization/agent-profiles.md +1 -1
- package/dist/docs/en/customization/agents-and-subagents.md +55 -12
- package/dist/docs/en/customization/hooks.md +3 -3
- package/dist/docs/en/customization/personas.md +36 -2
- package/dist/docs/en/customization/plugins.md +56 -3
- package/dist/docs/en/customization/prompt-fields.md +65 -5
- package/dist/docs/en/customization/recipes.md +77 -0
- package/dist/docs/en/customization/skins.md +2 -2
- package/dist/docs/en/customization/themes.md +1 -1
- 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 +13 -13
- package/dist/docs/en/features/ecosystem.md +6 -6
- package/dist/docs/en/features/extend.md +11 -10
- package/dist/docs/en/features/freedom.md +9 -9
- package/dist/docs/en/features/index.md +58 -28
- package/dist/docs/en/features/long-work.md +18 -14
- package/dist/docs/en/features/look.md +6 -6
- package/dist/docs/en/features/people.md +6 -6
- package/dist/docs/en/features/phone.md +13 -3
- package/dist/docs/en/features/spaces.md +12 -12
- package/dist/docs/en/features/workbench.md +8 -8
- package/dist/docs/en/getting-started/desktop-app.md +4 -8
- package/dist/docs/en/getting-started/first-launch.md +1 -1
- package/dist/docs/en/guides/goals.md +4 -2
- package/dist/docs/en/guides/interface.md +32 -10
- package/dist/docs/en/guides/memory.md +64 -10
- package/dist/docs/en/guides/sessions.md +21 -9
- package/dist/docs/en/guides/settings.md +64 -40
- package/dist/docs/en/index.md +3 -1
- package/dist/docs/en/reference/command.md +90 -31
- package/dist/docs/en/reference/model-vocabulary.md +2 -2
- package/dist/docs/en/reference/slash-commands.md +1 -1
- package/dist/docs/en/reference/tools.md +65 -20
- package/dist/docs/en/server/acp.md +9 -3
- package/dist/docs/en/server/local-server.md +19 -27
- package/dist/docs/en/server/mcp.md +9 -5
- package/dist/docs/en/server/rest-api.md +350 -22
- package/dist/docs/en/server/script-tools.md +268 -0
- package/dist/docs/zh/configuration/config-files.md +121 -46
- package/dist/docs/zh/configuration/data-locations.md +34 -7
- package/dist/docs/zh/configuration/env-vars.md +37 -9
- package/dist/docs/zh/configuration/overrides.md +20 -9
- package/dist/docs/zh/configuration/providers.md +114 -9
- package/dist/docs/zh/customization/agent-profiles.md +1 -1
- package/dist/docs/zh/customization/agents-and-subagents.md +55 -12
- package/dist/docs/zh/customization/hooks.md +3 -3
- package/dist/docs/zh/customization/personas.md +36 -2
- package/dist/docs/zh/customization/plugins.md +56 -3
- package/dist/docs/zh/customization/prompt-fields.md +65 -5
- package/dist/docs/zh/customization/recipes.md +77 -0
- package/dist/docs/zh/customization/skins.md +2 -2
- package/dist/docs/zh/customization/themes.md +1 -1
- 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 +13 -13
- package/dist/docs/zh/features/ecosystem.md +6 -6
- package/dist/docs/zh/features/extend.md +10 -9
- package/dist/docs/zh/features/freedom.md +9 -9
- package/dist/docs/zh/features/index.md +58 -28
- package/dist/docs/zh/features/long-work.md +17 -13
- package/dist/docs/zh/features/look.md +6 -6
- package/dist/docs/zh/features/people.md +5 -5
- package/dist/docs/zh/features/phone.md +13 -3
- package/dist/docs/zh/features/spaces.md +12 -12
- package/dist/docs/zh/features/workbench.md +8 -8
- package/dist/docs/zh/getting-started/desktop-app.md +4 -8
- package/dist/docs/zh/getting-started/first-launch.md +1 -1
- package/dist/docs/zh/guides/goals.md +4 -2
- package/dist/docs/zh/guides/interface.md +32 -10
- package/dist/docs/zh/guides/memory.md +64 -10
- package/dist/docs/zh/guides/sessions.md +21 -9
- package/dist/docs/zh/guides/settings.md +64 -40
- package/dist/docs/zh/index.md +4 -2
- package/dist/docs/zh/reference/command.md +90 -31
- package/dist/docs/zh/reference/model-vocabulary.md +2 -2
- package/dist/docs/zh/reference/slash-commands.md +1 -1
- package/dist/docs/zh/reference/tools.md +65 -20
- package/dist/docs/zh/server/acp.md +9 -3
- package/dist/docs/zh/server/local-server.md +19 -27
- package/dist/docs/zh/server/mcp.md +9 -5
- package/dist/docs/zh/server/rest-api.md +338 -21
- package/dist/docs/zh/server/script-tools.md +268 -0
- package/dist/external-harness/agy-cli-acp.mjs +168 -162
- package/dist/external-harness/agy-hook-registration.mjs +69 -30
- package/dist/external-harness/agy-mcp-plugin.mjs +19 -0
- package/dist/external-harness/agy-permission-hook.mjs +29 -2
- package/dist/hostRunner.mjs +112 -3
- package/dist/mailbox-worker.mjs +403 -0
- package/dist/main.mjs +2 -2
- package/dist/memory-worker.mjs +1008 -0
- package/dist/native/windows-process-helper.exe +0 -0
- package/dist/query-store-worker.mjs +487 -0
- package/dist/sqlite-indexer.mjs +255 -403
- package/dist/sqlite-query-worker.mjs +261 -249
- package/dist/usage-parser-worker.mjs +3977 -9
- package/dist/usage-read-model-worker.mjs +761 -0
- package/dist/web/assets/AppErrorBoundary-B5Fc4f6-.js +1 -0
- package/dist/web/assets/NavScopeBoundary-C7MnGQio.js +1 -0
- package/dist/web/assets/{arc-DYDCMlOS.js → arc-DGB9OVgQ.js} +1 -1
- package/dist/web/assets/{architectureDiagram-3BPJPVTR-C9Y7T0O2.js → architectureDiagram-3BPJPVTR-glnQCMub.js} +1 -1
- package/dist/web/assets/{blockDiagram-GPEHLZMM-CdUrp-tD.js → blockDiagram-GPEHLZMM-bM0tnGby.js} +1 -1
- package/dist/web/assets/{c4Diagram-AAUBKEIU-PrwvB9IJ.js → c4Diagram-AAUBKEIU-DMf_rTtt.js} +1 -1
- package/dist/web/assets/channel-Cj8SKJ38.js +1 -0
- package/dist/web/assets/{chunk-2J33WTMH-BL56g_Es.js → chunk-2J33WTMH-mTccJ3tW.js} +1 -1
- package/dist/web/assets/{chunk-4BX2VUAB-DvJD5M9M.js → chunk-4BX2VUAB-DhqPYMjY.js} +1 -1
- package/dist/web/assets/{chunk-55IACEB6-C8f-nzvx.js → chunk-55IACEB6-BujrYRoO.js} +1 -1
- package/dist/web/assets/{chunk-727SXJPM-DOGkWKkV.js → chunk-727SXJPM-ciMmSI4G.js} +1 -1
- package/dist/web/assets/{chunk-AQP2D5EJ-fFOuz7g6.js → chunk-AQP2D5EJ-CZW9pKTc.js} +1 -1
- package/dist/web/assets/{chunk-FMBD7UC4-BpeXZ9LM.js → chunk-FMBD7UC4-hdALNnnU.js} +1 -1
- package/dist/web/assets/{chunk-ND2GUHAM-CRUh76fb.js → chunk-ND2GUHAM-CgKyqUdb.js} +1 -1
- package/dist/web/assets/{chunk-QZHKN3VN-uNfxaPk0.js → chunk-QZHKN3VN-B2mmUz_E.js} +1 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-f8V9p-dD.js +1 -0
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-f8V9p-dD.js +1 -0
- package/dist/web/assets/client-ClWQBErG.js +3 -0
- package/dist/web/assets/connection-C0J3BPgk.js +1 -0
- package/dist/web/assets/{cose-bilkent-S5V4N54A-BNkxG-qX.js → cose-bilkent-S5V4N54A-UV3uPjkK.js} +1 -1
- package/dist/web/assets/{dagre-BM42HDAG-BerioUei.js → dagre-BM42HDAG-Zjy-gQ6C.js} +1 -1
- package/dist/web/assets/{diagram-2AECGRRQ-Czv2SR07.js → diagram-2AECGRRQ-DL-kilIf.js} +1 -1
- package/dist/web/assets/{diagram-5GNKFQAL-Uzi1weGK.js → diagram-5GNKFQAL-CjB_xR5B.js} +1 -1
- package/dist/web/assets/{diagram-KO2AKTUF-W36h_ff3.js → diagram-KO2AKTUF-CjN4i3b9.js} +1 -1
- package/dist/web/assets/{diagram-LMA3HP47-FG4dDk52.js → diagram-LMA3HP47-CPCAMndo.js} +1 -1
- package/dist/web/assets/{diagram-OG6HWLK6-CQoEjIAY.js → diagram-OG6HWLK6-DVeBWBKd.js} +1 -1
- package/dist/web/assets/{erDiagram-TEJ5UH35-Ck06KVyZ.js → erDiagram-TEJ5UH35-CHKzBHrr.js} +1 -1
- package/dist/web/assets/export-CXoWon32.js +2 -0
- package/dist/web/assets/{flowDiagram-I6XJVG4X-C5hgxdFZ.js → flowDiagram-I6XJVG4X-C5rQa2pq.js} +1 -1
- package/dist/web/assets/{ganttDiagram-6RSMTGT7-BS52Pw5_.js → ganttDiagram-6RSMTGT7-BrLjEsNJ.js} +1 -1
- package/dist/web/assets/{gitGraphDiagram-PVQCEYII-DLlQKZHs.js → gitGraphDiagram-PVQCEYII-3DRR5VZj.js} +1 -1
- package/dist/web/assets/highlighted-body-OFNGDK62-Bdj5SJfv.js +1 -0
- package/dist/web/assets/index-2Vx5mHRn.js +1 -0
- package/dist/web/assets/index-B1UXw2C9.js +1 -0
- package/dist/web/assets/{index-CM-nNfuV.js → index-BJxtlf4P.js} +4 -4
- package/dist/web/assets/{index-DKIysLbI.js → index-BY7jPurv.js} +1 -1
- package/dist/web/assets/index-Bq79v-Sa.js +1 -0
- package/dist/web/assets/index-BqD3iTIl.js +1 -0
- package/dist/web/assets/index-Br3AlBrQ.js +1 -0
- package/dist/web/assets/{index-Ca607_hK.js → index-BvRBCpc6.js} +2 -2
- package/dist/web/assets/index-BxYCSNg_.js +3 -0
- package/dist/web/assets/{index-B2Pu0Iuu.js → index-C62wjCF_.js} +1 -1
- package/dist/web/assets/index-CBvwNH_H.js +1 -0
- package/dist/web/assets/{index-BNch_a4L.js → index-CG9e6lgq.js} +1 -1
- package/dist/web/assets/{index-ByiwExpV.js → index-CPSWYh_R.js} +2 -2
- package/dist/web/assets/index-CS4xJLZV.js +1 -0
- package/dist/web/assets/index-CjvqtF2I.js +1 -0
- package/dist/web/assets/index-CprdjRRk.js +13 -0
- package/dist/web/assets/{index-Bg99yVX_.js → index-CypTtrCB.js} +1 -1
- package/dist/web/assets/{index-BwcG86o3.js → index-DDJQGcUL.js} +1 -1
- package/dist/web/assets/index-DLWzxUOO.js +1 -0
- package/dist/web/assets/index-DQxkxZmn.js +7 -0
- package/dist/web/assets/index-DRo5Y_9p.js +1 -0
- package/dist/web/assets/index-De_LkTZx.js +1 -0
- package/dist/web/assets/{index-CZX3qUe2.js → index-DfUpwUTM.js} +2 -2
- package/dist/web/assets/{index-BLU8_Um7.js → index-Dkbz748K.js} +2 -2
- package/dist/web/assets/index-DmwFFSkV.js +1 -0
- package/dist/web/assets/index-DpcWEDhW.js +1 -0
- package/dist/web/assets/index-Dqq1RDP4.js +1 -0
- package/dist/web/assets/index-H1uMvIoa.css +1 -0
- package/dist/web/assets/index-ICHWJ2SM.js +1 -0
- package/dist/web/assets/index-O5fSd569.js +229 -0
- package/dist/web/assets/index-odjtqLLS.js +1 -0
- package/dist/web/assets/index-v_yAQ0Am.js +1 -0
- package/dist/web/assets/{infoDiagram-5YYISTIA-CD4XJGFm.js → infoDiagram-5YYISTIA-CCwV4Z0v.js} +1 -1
- package/dist/web/assets/{ishikawaDiagram-YF4QCWOH-fu5E3_CT.js → ishikawaDiagram-YF4QCWOH-BwwZcGyZ.js} +1 -1
- package/dist/web/assets/{journeyDiagram-JHISSGLW-CXcnKBfJ.js → journeyDiagram-JHISSGLW-Dc6WqniQ.js} +1 -1
- package/dist/web/assets/{kanban-definition-UN3LZRKU-BawKH6Pl.js → kanban-definition-UN3LZRKU-DVUqULOS.js} +1 -1
- package/dist/web/assets/{linear-BplJuXph.js → linear-d6rWsNOU.js} +1 -1
- package/dist/web/assets/memoryAdvisor-DBQXJB1o.js +1 -0
- package/dist/web/assets/mermaid-GHXKKRXX-Ik6SkVDT.js +642 -0
- package/dist/web/assets/{mindmap-definition-RKZ34NQL-DA1SE2uy.js → mindmap-definition-RKZ34NQL-_JHAkhHL.js} +1 -1
- package/dist/web/assets/navViewState-DaCMIYWA.js +1 -0
- package/dist/web/assets/{pieDiagram-4H26LBE5-6i021QeX.js → pieDiagram-4H26LBE5-BlhlygGy.js} +1 -1
- package/dist/web/assets/{quadrantDiagram-W4KKPZXB-CcKSZDMT.js → quadrantDiagram-W4KKPZXB-jn6R_C0S.js} +1 -1
- package/dist/web/assets/{requirementDiagram-4Y6WPE33-lYVuWRuD.js → requirementDiagram-4Y6WPE33-B9fXCHBr.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-5OEKKPKP-4Zfb4_h4.js → sankeyDiagram-5OEKKPKP-fPJwIxkl.js} +1 -1
- package/dist/web/assets/{sequenceDiagram-3UESZ5HK-DqltKmlY.js → sequenceDiagram-3UESZ5HK-1v1DTNGt.js} +1 -1
- package/dist/web/assets/{spaces-CjuXbmxF.js → spaces-CvL2DRZM.js} +1 -1
- package/dist/web/assets/{stateDiagram-AJRCARHV-HFdhqxzx.js → stateDiagram-AJRCARHV-CEc_PLov.js} +1 -1
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-iAMctzaT.js +1 -0
- package/dist/web/assets/theme-LRSmy8mD.js +1 -0
- package/dist/web/assets/{timeline-definition-PNZ67QCA-HNRxaB3t.js → timeline-definition-PNZ67QCA-CEjhuitj.js} +1 -1
- package/dist/web/assets/{vennDiagram-CIIHVFJN-DwsCTyaD.js → vennDiagram-CIIHVFJN-CActt9h9.js} +1 -1
- package/dist/web/assets/{wardley-L42UT6IY-BWW2wtVO.js → wardley-L42UT6IY-Bp3q2izt.js} +1 -1
- package/dist/web/assets/{wardleyDiagram-YWT4CUSO-C-ktKm7v.js → wardleyDiagram-YWT4CUSO-C_zutiQ2.js} +1 -1
- package/dist/web/assets/{xychartDiagram-2RQKCTM6-48AxNW9k.js → xychartDiagram-2RQKCTM6-CRafvv33.js} +1 -1
- package/dist/web/icons/apple-touch-icon.png +0 -0
- package/dist/web/icons/icon-192.png +0 -0
- package/dist/web/icons/icon-512.png +0 -0
- package/dist/web/icons/maskable-512.png +0 -0
- package/dist/web/index.html +12 -2
- package/dist/web/manifest.webmanifest +16 -0
- 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 +23 -4
- package/dist/search-worker.mjs +0 -14177
- package/dist/web/assets/AppErrorBoundary-DiGMUg4r.js +0 -1
- package/dist/web/assets/LifeMark-CL6-HWDu.js +0 -1
- package/dist/web/assets/NavScopeBoundary-CFCnvZR0.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/export-T_izwEkQ.js +0 -2
- package/dist/web/assets/highlighted-body-OFNGDK62-Btm6MuZ4.js +0 -1
- package/dist/web/assets/index-5_yzg61S.js +0 -1
- package/dist/web/assets/index-B-6LiYTY.js +0 -1
- package/dist/web/assets/index-B4iu4SJW.js +0 -1
- package/dist/web/assets/index-B9MlqF7J.js +0 -1
- package/dist/web/assets/index-BECSk4If.js +0 -1
- package/dist/web/assets/index-BFcyN2Zw.js +0 -1
- package/dist/web/assets/index-BIebkSEI.css +0 -1
- package/dist/web/assets/index-BMWid2q9.js +0 -1
- package/dist/web/assets/index-BeMvPEXs.js +0 -1
- package/dist/web/assets/index-Bezli3SF.js +0 -1
- package/dist/web/assets/index-BkPV0psm.js +0 -1
- package/dist/web/assets/index-CG8uIlD7.js +0 -1
- package/dist/web/assets/index-CJ92kLtO.js +0 -1
- package/dist/web/assets/index-CRDDqofN.js +0 -1
- package/dist/web/assets/index-Cd62y0wD.js +0 -1
- package/dist/web/assets/index-CgcJPsK6.js +0 -3
- package/dist/web/assets/index-Cy8C_eFR.js +0 -7
- package/dist/web/assets/index-D8z7lcQn.js +0 -166
- package/dist/web/assets/index-D_oPSlBL.js +0 -1
- package/dist/web/assets/index-Dceu0bqY.js +0 -1
- package/dist/web/assets/index-eUyF-8Sq.js +0 -1
- package/dist/web/assets/index-hG2s2Spn.js +0 -13
- package/dist/web/assets/mermaid-GHXKKRXX-BO9hkP3Z.js +0 -621
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-Dx28QuZF.js +0 -1
- package/dist/web/assets/theme-beWE_6f8.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$ as Cn,a0 as _n,a1 as Pn,a2 as Rn,a3 as En,a4 as Nn,a5 as Z,a6 as rn,a7 as $t,a8 as ce,a9 as sn,aa as An,ab as Ut,ac as Ln,ad as Wt,ae as Kt,af as Tn,ag as Vt,ah as zt,ai as Dn,j as r,r as u,e as _t,S,aj as Hn,ak as It,al as Fn,s as On,am as Qn,an as qn,ao as $n,ap as Un,aq as Wn,b as xt,c as gt,D as Kn,ar as Vn,as as zn,at as Bn}from"./index-O5fSd569.js";import{u as ge}from"./index-C62wjCF_.js";import"./memoryAdvisor-DBQXJB1o.js";import{A as xe,a as Ce,R as Xe,c as St,K as qe,i as Gn,w as Yn}from"./client-ClWQBErG.js";const jt="kiki.pinned";function on(t){return t.executing??t.main_turn_active}function _e(t){return t.metadata[jt]===!0}function Gr(t,e){const n={...t.metadata};return e?n[jt]=!0:delete n[jt],n}function Yr(t){return!t}function Zr(t){const e=t.replaceAll("\\","/").replace(/\/+$/,""),n=e.split("/").filter(s=>s!=="");return n.length<=2?e:`…/${n.slice(-2).join("/")}`}async function Xr(t,e,n){n?.throwIfAborted();let s=await t();n?.throwIfAborted();const a=new Set(e?.pages[0]?.items.map(i=>i.id)),c=new Set;for(;a.size>0&&s.has_more&&!s.items.some(i=>a.has(i.id));){const i=s.next_cursor??s.items.at(-1)?.id;if(i===void 0||c.has(i))throw new Error("Session list cursor did not advance");c.add(i);const f=await t(i);n?.throwIfAborted(),s={...f,items:[...s.items,...f.items]}}return s}function Jr(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 s=new Set(e.items.map(f=>f.id)),a=n.items.findLastIndex(f=>s.has(f.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 es(t,e){return t===void 0?t:{...t,pages:t.pages.map(n=>({...n,items:n.items.map(s=>s.id===e.id&&Date.parse(e.updated_at)>=Date.parse(s.updated_at)?e:s)}))}}function cn(t,e){return t.id===e.sessionId?{...t,busy:e.busy,executing:e.executing,cleanup_pending:e.cleanup_pending,main_turn_active:e.main_turn_active,pending_interaction:e.pending_interaction,last_turn_reason:e.last_turn_reason}:t}function Zn(t,e){return t===void 0||!Array.isArray(t.pages)?t:{...t,pages:t.pages.map(n=>({...n,items:n.items.map(s=>cn(s,e))}))}}const Xn=20;async function ts(t,e,n=Xn){const s=[],a=new Set;let c;for(let i=0;i<n;i+=1){e?.throwIfAborted();const f=await t(c);if(s.push(...f.items),!f.has_more||(c=f.next_cursor??f.items.at(-1)?.id,c===void 0||a.has(c)))break;a.add(c)}return{pages:[{items:s,has_more:!1}],pageParams:[void 0]}}function ns(t,e){const n=Bt(t),s=new Set(n.map(c=>c.id)),a=Bt(e).filter(c=>!s.has(c.id)&&_e(c));return a.length===0?n:[...n,...a]}function Bt(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 rs=["updated-desc","created-desc","title"];function ss(t){return t==="updated-desc"||t==="updated-asc"||t==="created-desc"||t==="title"}function Je(t){const e=Date.parse(t);return Number.isFinite(e)?e:0}function $e(t,e){return Je(e.updated_at)-Je(t.updated_at)}function Jn(t,e){return Je(t.updated_at)-Je(e.updated_at)}function er(t,e){return e.created_at.localeCompare(t.created_at)||$e(t,e)}function tr(t,e){const n=t.title.trim(),s=e.title.trim();return n!==s?n.localeCompare(s,void 0,{sensitivity:"base",numeric:!0}):$e(t,e)}function is(t,e,n){const s=t.filter(c=>on(c)===!0).sort((c,i)=>i.created_at.localeCompare(c.created_at)||c.id.localeCompare(i.id));if(s.length===0)return;const a=s.findIndex(c=>c.id===e);return a===-1?(n===1?s[0]:s.at(-1))?.id:s[(a+n+s.length)%s.length]?.id}function os(t){return[...t].sort((e,n)=>{const s=_e(e),a=_e(n);return s!==a?s?-1:1:$e(e,n)})}function cs(t,e){const n=[],s=[];for(const a of t)(_e(a)?n:s).push(a);return n.sort($e),e==="title"?s.sort(tr):e==="updated-asc"?s.sort(Jn):e==="created-desc"?s.sort(er):s.sort($e),[...n,...s]}const vt=1440*60*1e3;function nr(t){const e=new Date(t);return e.setHours(0,0,0,0),e.getTime()}function as(t,e,n={}){const a=["pinned","today","yesterday","week","month","older"].map(l=>({key:l,label:n[l]??l,items:[]})),[c,i,f,y,L,j]=a,P=nr(e),F=P-vt,k=P-6*vt,m=P-29*vt;for(const l of t){let h;if(_e(l))h=c;else{const b=Date.parse(l.updated_at);Number.isFinite(b)?b>=P?h=i:b>=F?h=f:b>=k?h=y:b>=m?h=L:h=j:h=j}h.items.push(l)}return a.filter(l=>l.items.length>0)}const Gt="__none";function ls(t,e,n=c=>c.name,s="ungrouped",a){const c=a===void 0?void 0:{key:"pinned",label:a,items:[]},i=new Map(e.map((k,m)=>[k.id,m])),f=new Map;for(const k of e)f.set(k.id,n(k));const y=new Map,L=(k,m)=>{let l=y.get(k);return l===void 0&&(l={key:k,label:m,items:[]},y.set(k,l)),l};for(const k of t){if(c!==void 0&&_e(k)){c.items.push(k);continue}const m=k.workspace_id;i.get(m)!==void 0?L(m,f.get(m)??m).items.push(k):L(Gt,s).items.push(k)}const j=[];for(const[k,m]of e.entries()){const l=y.get(m.id);l!==void 0&&(j[k]=l)}const P=y.get(Gt);P!==void 0&&j.push(P);const F=j.filter(k=>k!==void 0);return c!==void 0&&c.items.length>0?[c,...F]:F}function rr(t){const e=t.pending_interaction;return e==="approval"||e==="question"?"needs-me":t.cleanup_pending===!0?"cleanup-pending":on(t)===!0?"running":"idle"}function us(t,e){const n=new Set(e.status),s=new Set(e.workspaces);return t.filter(a=>{const c=a.archived===!0;return!(e.archived==="hide"&&c||e.archived==="only"&&!c||s.size>0&&!s.has(a.workspace_id)||n.size>0&&!n.has(rr(a)))})}function ds(t){return t.status.length>0||t.workspaces.length>0||t.archived!=="hide"}function Yt(t){return{onFetch:(e,n)=>{const s=e.options,a=e.fetchOptions?.meta?.fetchMore?.direction,c=e.state.data?.pages||[],i=e.state.data?.pageParams||[];let f={pages:[],pageParams:[]},y=0;const L=async()=>{let j=!1;const P=m=>{Rn(m,()=>e.signal,()=>j=!0)},F=Cn(e.options,e.fetchOptions),k=async(m,l,h)=>{if(j)return Promise.reject();if(l==null&&m.pages.length)return Promise.resolve(m);const E=(()=>{const I={client:e.client,queryKey:e.queryKey,pageParam:l,direction:h?"backward":"forward",meta:e.options.meta};return P(I),I})(),R=await F(E),{maxPages:N}=e.options,g=h?_n:Pn;return{pages:g(m.pages,R,N),pageParams:g(m.pageParams,l,N)}};if(a&&c.length){const m=a==="backward",l=m?an:Mt,h={pages:c,pageParams:i},b=l(s,h);f=await k(h,b,m)}else{const m=t??c.length;do{const l=y===0?i[0]??s.initialPageParam:Mt(s,f);if(y>0&&l==null)break;f=await k(f,l),y++}while(y<m)}return f};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 Mt(t,{pages:e,pageParams:n}){const s=e.length-1;return e.length>0?t.getNextPageParam(e[s],e,n[s],n):void 0}function an(t,{pages:e,pageParams:n}){return e.length>0?t.getPreviousPageParam?.(e[0],e,n[0],n):void 0}function hs(t,e){return e?Mt(t,e)!=null:!1}function fs(t,e){return!e||!t.getPreviousPageParam?!1:an(t,e)!=null}var sr=class extends En{#e;#t;#n;#s;constructor(t){super(),this.#e=t.client,this.mutationId=t.mutationId,this.#n=t.mutationCache,this.#t=[],this.state=t.state||ir(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){this.#t.includes(t)||(this.#t.push(t),this.clearGcTimeout(),this.#n.notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){this.#t=this.#t.filter(e=>e!==t),this.scheduleGc(),this.#n.notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){this.#t.length||(this.state.status==="pending"?this.scheduleGc():this.#n.remove(this))}continue(){return this.#s?.continue()??this.execute(this.state.variables)}async execute(t){const e=()=>{this.#r({type:"continue"})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#s=Nn({fn:()=>this.options.mutationFn?this.options.mutationFn(t,n):Promise.reject(new Error("No mutationFn found")),onFail:(c,i)=>{this.#r({type:"failed",failureCount:c,error:i})},onPause:()=>{this.#r({type:"pause"})},onContinue:e,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)});const s=this.state.status==="pending",a=!this.#s.canStart();try{if(s)e();else{this.#r({type:"pending",variables:t,isPaused:a}),this.#n.config.onMutate&&await this.#n.config.onMutate(t,this,n);const i=await this.options.onMutate?.(t,n);i!==this.state.context&&this.#r({type:"pending",context:i,variables:t,isPaused:a})}const c=await this.#s.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.#r({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.#r({type:"error",error:c}),c}finally{this.#n.runNext(this)}}#r(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),Z.batch(()=>{this.#t.forEach(n=>{n.onMutationUpdate(t)}),this.#n.notify({mutation:this,type:"updated",action:t})})}};function ir(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var or=class extends rn{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 s=new sr({client:t,mutationCache:this,mutationId:++this.#n,options:t.defaultMutationOptions(e),state:n});return this.add(s),s}add(t){this.#e.add(t);const e=Ge(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=Ge(t);if(typeof e=="string"){const n=this.#t.get(e);if(n)if(n.length>1){const s=n.indexOf(t);s!==-1&&n.splice(s,1)}else n[0]===t&&this.#t.delete(e)}}this.notify({type:"removed",mutation:t})}canRun(t){const e=Ge(t);if(typeof e=="string"){const s=this.#t.get(e)?.find(a=>a.state.status==="pending");return!s||s===t}else return!0}runNext(t){const e=Ge(t);return typeof e=="string"?this.#t.get(e)?.find(s=>s!==t&&s.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){Z.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=>$t(e,n))}findAll(t={}){return this.getAll().filter(e=>$t(t,e))}notify(t){Z.batch(()=>{this.listeners.forEach(e=>{e(t)})})}resumePausedMutations(){const t=this.getAll().filter(e=>e.state.isPaused);return Z.batch(()=>Promise.all(t.map(e=>e.continue().catch(ce))))}};function Ge(t){return t.options.scope?.id}var cr=class extends rn{constructor(t={}){super(),this.config=t,this.#e=new Map}#e;build(t,e,n){const s=e.queryKey,a=e.queryHash??sn(s,e);let c=this.get(a);return c||(c=new An({client:t,queryKey:s,queryHash:a,options:t.defaultQueryOptions(e),state:n,defaultOptions:t.getQueryDefaults(s)}),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(){Z.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=>Ut(e,n))}findAll(t={}){const e=this.getAll();return Object.keys(t).length>0?e.filter(n=>Ut(t,n)):e}notify(t){Z.batch(()=>{this.listeners.forEach(e=>{e(t)})})}onFocus(){Z.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){Z.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},ar=class{#e;#t;#n;#s;#r;#i;#o;#c;constructor(t={}){this.#e=t.queryCache||new cr,this.#t=t.mutationCache||new or,this.#n=t.defaultOptions||{},this.#s=new Map,this.#r=new Map,this.#i=0}mount(){this.#i++,this.#i===1&&(this.#o=Ln.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#c=Wt.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),s=n.state.data;return s===void 0?this.fetchQuery(t):(t.revalidateIfStale&&n.isStaleByTime(Kt(e.staleTime,n))&&this.prefetchQuery(e),Promise.resolve(s))}getQueriesData(t){return this.#e.findAll(t).map(({queryKey:e,state:n})=>{const s=n.data;return[e,s]})}setQueryData(t,e,n){const s=this.defaultQueryOptions({queryKey:t}),c=this.#e.get(s.queryHash)?.state.data,i=Tn(e,c);if(i!==void 0)return this.#e.build(this,s).setData(i,{...n,manual:!0})}setQueriesData(t,e,n){return Z.batch(()=>this.#e.findAll(t).map(({queryKey:s})=>[s,this.setQueryData(s,e,n)]))}getQueryState(t){const e=this.defaultQueryOptions({queryKey:t});return this.#e.get(e.queryHash)?.state}removeQueries(t){const e=this.#e;Z.batch(()=>{e.findAll(t).forEach(n=>{e.remove(n)})})}resetQueries(t,e){const n=this.#e;return Z.batch(()=>(n.findAll(t).forEach(s=>{s.reset()}),this.refetchQueries({type:"active",...t},e)))}cancelQueries(t,e={}){const n={revert:!0,...e},s=Z.batch(()=>this.#e.findAll(t).map(a=>a.cancel(n)));return Promise.all(s).then(ce).catch(ce)}invalidateQueries(t,e={}){return Z.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},s=Z.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(ce)),a.state.fetchStatus==="paused"?Promise.resolve():c}));return Promise.all(s).then(ce)}fetchQuery(t){const e=this.defaultQueryOptions(t);e.retry===void 0&&(e.retry=!1);const n=this.#e.build(this,e);return n.isStaleByTime(Kt(e.staleTime,n))?n.fetch(e):Promise.resolve(n.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(ce).catch(ce)}fetchInfiniteQuery(t){return t.behavior=Yt(t.pages),this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(ce).catch(ce)}ensureInfiniteQueryData(t){return t.behavior=Yt(t.pages),this.ensureQueryData(t)}resumePausedMutations(){return Wt.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(t){this.#n=t}setQueryDefaults(t,e){this.#s.set(Vt(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#s.values()],n={};return e.forEach(s=>{zt(t,s.queryKey)&&Object.assign(n,s.defaultOptions)}),n}setMutationDefaults(t,e){this.#r.set(Vt(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#r.values()],n={};return e.forEach(s=>{zt(t,s.mutationKey)&&Object.assign(n,s.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=sn(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===Dn&&(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 ln={12:"h-3 w-3",14:"h-3.5 w-3.5",16:"h-4 w-4"},lr={read:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M4 2.5h5.2L12 5.3v8.2H4z"}),r.jsx("path",{d:"M9 2.5v3h3"})]}),search:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"7",cy:"7",r:"4.2"}),r.jsx("path",{d:"m10.2 10.2 3.3 3.3"})]}),edit:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M10.4 2.9 13.1 5.6 6 12.7l-3.2.5.5-3.2z"}),r.jsx("path",{d:"m9.2 4.1 2.7 2.7"})]}),terminal:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"2",y:"3",width:"12",height:"10",rx:"1.8"}),r.jsx("path",{d:"m5 6.5 2 1.5-2 1.5M8.5 10H11"})]}),web:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),r.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:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"2.5",y:"2.5",width:"7.5",height:"7.5",rx:"1.6"}),r.jsx("path",{d:"M6 13.5h5.9a1.6 1.6 0 0 0 1.6-1.6V6"})]}),skill:r.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:r.jsx("path",{d:"M5.5 4.5h8M5.5 8h8M5.5 11.5h8M2.5 4.5h.01M2.5 8h.01M2.5 11.5h.01"}),task:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),r.jsx("path",{d:"M6.8 5.6v4.8L10.4 8z"})]}),goal:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),r.jsx("circle",{cx:"8",cy:"8",r:"2.4"})]}),memory:r.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:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M5.2 11.3a4.3 4.3 0 1 1 5.6 0v1.2H5.2z"}),r.jsx("path",{d:"M6.3 14h3.4"})]}),system:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"2.5",y:"2.5",width:"11",height:"11",rx:"2"}),r.jsx("path",{d:"M5.5 6.5h5M5.5 9.5h3"})]}),clock:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),r.jsx("path",{d:"M8 4.8V8l2.2 1.4"})]}),gate:r.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:r.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:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M4 2.5h5.2L12 5.3v8.2H4z"}),r.jsx("path",{d:"M6.2 8.2h3.6M6.2 10.6h2.4"})]}),tool:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"2.2"}),r.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:r.jsx("path",{d:"m3.5 8.4 2.9 2.9 6.1-6.6"}),cross:r.jsx("path",{d:"m4.3 4.3 7.4 7.4m0-7.4-7.4 7.4"}),dash:r.jsx("path",{d:"M4 8h8"}),warning:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M8 2.6 13.8 13H2.2z"}),r.jsx("path",{d:"M8 6.6v2.8M8 11.3h.01"})]}),info:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"5.9"}),r.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:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),r.jsx("path",{d:"M6.6 5.8v4.4M9.4 5.8v4.4"})]}),chevron:r.jsx("path",{d:"m6 3.8 4.2 4.2L6 12.2"}),close:r.jsx("path",{d:"m4.5 4.5 7 7m0-7-7 7"}),menu:r.jsx("path",{d:"M2.8 4.5h10.4M2.8 8h10.4M2.8 11.5h10.4"}),more:r.jsx("path",{d:"M3.5 8h.01M8 8h.01M12.5 8h.01",strokeWidth:2.2}),plus:r.jsx("path",{d:"M8 3v10M3 8h10"}),arrowRight:r.jsx("path",{d:"M3 8h10m-3.8-3.8L13 8l-3.8 3.8"}),arrowDown:r.jsx("path",{d:"M8 3v10m-3.8-3.8L8 13l3.8-3.8"}),external:r.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:r.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:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"2",y:"3",width:"12",height:"10",rx:"1.6"}),r.jsx("path",{d:"M10 3v10"})]}),filter:r.jsx("path",{d:"M2.5 3.5h11l-4.2 5v4l-2.6 1v-5z"}),sliders:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M2.5 4.5h7M13.5 4.5h0M2.5 8h2M7.5 8h6M2.5 11.5h6M12 11.5h1.5"}),r.jsx("circle",{cx:"11",cy:"4.5",r:"1.5"}),r.jsx("circle",{cx:"6",cy:"8",r:"1.5"}),r.jsx("circle",{cx:"10.5",cy:"11.5",r:"1.5"})]}),pin:r.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:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"2",y:"2.5",width:"12",height:"11",rx:"1.8"}),r.jsx("path",{d:"M6 2.5v11M10 2.5v7"})]}),usage:r.jsx("path",{d:"M2.5 13.5h11M4.5 11V8M8 11V4.5M11.5 11V6.5"}),notes:r.jsxs(r.Fragment,{children:[r.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"}),r.jsx("path",{d:"M5.2 6.4h4.4M5.2 9h3"})]}),settings:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"2.1"}),r.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:r.jsx("path",{d:"M13 8H3m3.8-3.8L3 8l3.8 3.8"}),arrowUp:r.jsx("path",{d:"M8 13V3M4.2 6.8 8 3l3.8 3.8"}),arrowUpRight:r.jsx("path",{d:"M4.5 11.5 11.5 4.5M5.5 4.5h6v6"}),expand:r.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:r.jsx("path",{d:"M13.5 6.5h-4v-4M2.5 9.5h4v4M9.5 6.5l4-4M6.5 9.5l-4 4"}),grip:r.jsx("path",{d:"M6 4h.01M10 4h.01M6 8h.01M10 8h.01M6 12h.01M10 12h.01",strokeWidth:2.2}),stop:r.jsx("rect",{x:"4.5",y:"4.5",width:"7",height:"7",rx:"1.2",fill:"currentColor"}),quote:r.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:r.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:r.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:r.jsx("circle",{cx:"8",cy:"8",r:"3",fill:"currentColor",stroke:"none"}),ring:r.jsx("circle",{cx:"8",cy:"8",r:"4.5"}),partial:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),r.jsx("path",{d:"M8 8V2.2A5.8 5.8 0 0 1 13.8 8z",fill:"currentColor"})]}),bell:r.jsxs(r.Fragment,{children:[r.jsx("path",{d:"M4.2 7a3.8 3.8 0 0 1 7.6 0v2.4l1 1.6H3.2l1-1.6z"}),r.jsx("path",{d:"M6.6 12.4a1.5 1.5 0 0 0 2.8 0"})]}),branch:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"4.5",cy:"3.8",r:"1.3"}),r.jsx("circle",{cx:"4.5",cy:"12.2",r:"1.3"}),r.jsx("circle",{cx:"11.5",cy:"6.2",r:"1.3"}),r.jsx("path",{d:"M4.5 5.1v5.8M11.5 7.5c0 2.2-2 2.9-7 3.4"})]}),eye:r.jsxs(r.Fragment,{children:[r.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"}),r.jsx("circle",{cx:"8",cy:"8",r:"2"})]}),eyeOff:r.jsxs(r.Fragment,{children:[r.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"}),r.jsx("path",{d:"M6.6 6.6a2 2 0 0 0 2.8 2.8M2.5 2.5l11 11"})]}),copy:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"5.5",y:"5.5",width:"8",height:"8",rx:"1.6"}),r.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:r.jsx("path",{d:"M13 5V2.5m0 2.5h-2.5M13 5a5.2 5.2 0 1 0 .1 5.8"}),thread:r.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:r.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:r.jsxs(r.Fragment,{children:[r.jsx("rect",{x:"2.5",y:"2.5",width:"11",height:"11",rx:"3"}),r.jsx("circle",{cx:"8",cy:"6.8",r:"1.8"}),r.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:r.jsxs(r.Fragment,{children:[r.jsx("circle",{cx:"8",cy:"8",r:"5.8"}),r.jsx("polygon",{points:"10.8,5.2 6.8,7.2 5.2,10.8 9.2,8.8"})]})};function Ct({name:t,size:e=14,className:n=""}){const s=/(^|\s)h-/.test(n)?"":ln[e];return r.jsx("svg",{"aria-hidden":!0,"data-icon":t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.35,strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 ${s} ${n}`.trim(),children:lr[t]})}function ur({open:t,size:e=12,className:n="text-ink-faint"}){return r.jsx(Ct,{name:"chevron",size:e,className:`transition-transform duration-[var(--kiki-motion-quick)] ease-out motion-reduce:transition-none ${t?"rotate-90":""} ${n}`})}function dr({label:t,size:e=14}){return r.jsxs("svg",{role:"img","aria-label":t,viewBox:"0 0 16 16",fill:"none",className:`spinner shrink-0 text-ink-soft ${ln[e]}`,children:[r.jsx("circle",{cx:"8",cy:"8",r:"5.8",stroke:"currentColor",strokeOpacity:"0.22",strokeWidth:1.35}),r.jsx("path",{d:"M13.8 8A5.8 5.8 0 0 0 8 2.2",stroke:"currentColor",strokeWidth:1.35,strokeLinecap:"round"})]})}function ps({state:t,labels:e,title:n}){switch(t){case"running":return r.jsx(dr,{label:e.running});case"failed":return r.jsx("span",{role:"img","aria-label":e.failed,title:n,"data-outcome":"failed",className:"text-danger",children:r.jsx(Ct,{name:"cross"})});case"stopped":return r.jsx("span",{role:"img","aria-label":e.stopped,title:n,"data-outcome":"stopped",className:"text-amber-rule",children:r.jsx(Ct,{name:"dash"})});case"done":return r.jsx("span",{className:"sr-only",children:e.done})}}const hr=10*6e4;function ms(t,e=Date.now()){if(t.pending_interaction==="approval"||t.pending_interaction==="question"||t.cleanup_pending===!0)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<hr)return"done"}return"idle"}function xs(t,e=8){return{"--kiki-i":Math.min(t,e)}}function fr(){if(typeof document>"u")return"system";const t=document.documentElement.dataset.kikiMotion;return t==="reduce"||t==="full"?t:"system"}function gs(){const t=fr();return t!=="system"?t==="reduce":typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}const Zt=new Map;function pr(t,e){const n=u.useRef(null);if(n.current===null||n.current.life!==e){const s=Zt.get(t);n.current={life:e,changed:e!==void 0&&s!==void 0&&s!==e}}return u.useEffect(()=>{e!==void 0&&Zt.set(t,e)},[t,e]),n.current.changed}function Ue({size:t="md",life:e,echo:n}){const s=pr("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 r.jsxs("span",{className:"inline-flex items-baseline select-none","aria-label":"kiki",children:[r.jsx("span",{className:`font-display ${c} leading-none font-semibold tracking-tight text-ink`,style:{fontVariationSettings:t==="xl"?'"opsz" 60':'"opsz" 40'},children:"kiki"}),r.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:r.jsx("span",{"data-life":a,"data-life-changed":s?"":void 0,className:`kiki-wordmark-dot block ${i} translate-y-[-1px] rounded-full bg-accent`})})]})}function vs({className:t=""}){return r.jsx("span",{"aria-hidden":!0,className:`inline-block h-2.5 w-2.5 rounded-[3px] bg-accent ${t}`})}const mr=/\bKikiApp\/(android|ios)\b/;function xr(t=globalThis.navigator?.userAgent??""){const e=mr.exec(t)?.[1];return e==="android"?"https://localhost/index.html#change":e==="ios"?"capacitor://localhost/index.html#change":null}function Xt({onConnect:t,selectedProfile:e}){const{t:n}=ge(),s=_t(),[a,c]=u.useState([]),[i,f]=u.useState(""),[y,L]=u.useState(""),[j,P]=u.useState(""),[F,k]=u.useState("58627"),[m,l]=u.useState(""),[h,b]=u.useState("stable"),[E,R]=u.useState(null),[N,g]=u.useState(null),[I,U]=u.useState(null),[O,W]=u.useState(null),[q,Pe]=u.useState(!1);u.useEffect(()=>{if(!s.connection.listSshProfiles)return;let p=!0;return s.connection.listSshProfiles().then(T=>{p&&c(T)},T=>{p&&(Pe(!0),W(String(T)))}),()=>{p=!1}},[s]);const ee=()=>{U("list"),W(null),s.connection.listSshProfiles().then(p=>{c(p),Pe(!1)},p=>W(String(p))).finally(()=>U(null))};if(!s.connection.listSshProfiles||!s.connection.saveSshProfile||!s.connection.removeSshProfile)return null;const Re=p=>{p.preventDefault();const T=Number(F);if(!Number.isInteger(T)||T<1||T>65535||!/^[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$/.test(m.trim())){W(n("connect.sshNeedSetup"));return}const te=a.find(ie=>ie.id===E),ve={id:te?.id??crypto.randomUUID(),label:i.trim(),target:te?.target.kind==="host"?{...te.target,hostname:y.trim()}:{kind:"alias",alias:y.trim()},identityFile:j.trim()||null,releaseChannel:h,remotePort:T,serverHomeId:m.trim().toLowerCase()};U("save"),W(null),s.connection.saveSshProfile(ve).then(ie=>{c(ie),f(""),L(""),P(""),k("58627"),l(""),b("stable"),R(null)},ie=>W(String(ie))).finally(()=>U(null))},se=p=>{const T=a.find(te=>te.id===p)??(e?.id===p?e:void 0);if(!T?.remotePort||!T.serverHomeId||N?.id!==p||!/^[A-Za-z0-9_-]{43}$/.test(N.value)){W(n("connect.sshNeedSetup"));return}U(p),W(null),t(p,N.value).then(()=>g(null),te=>W(String(te))).finally(()=>U(null))},tt=p=>{U(p),W(null),s.connection.removeSshProfile(p).then(T=>c(T),T=>W(String(T))).finally(()=>U(null))};return r.jsxs("section",{className:"mt-5 border-t border-hairline pt-4","aria-label":n("connect.sshTitle"),children:[r.jsx("h2",{className:"text-[13px] font-semibold text-ink",children:n("connect.sshTitle")}),r.jsx("p",{className:"mt-1 text-[11px] leading-relaxed text-ink-soft",children:n("connect.sshHint")}),q?r.jsx("button",{type:"button",disabled:I!==null,onClick:ee,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(p=>p.id===e.id)?[e,...a]:a).map(p=>r.jsxs("div",{className:"mt-2 rounded-lg border border-hairline px-3 py-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"truncate text-[12px] font-medium text-ink",children:p.label}),r.jsxs("p",{className:"truncate font-mono text-[10px] text-ink-soft",children:[p.target.kind==="alias"?p.target.alias:p.target.hostname,p.remotePort?` · 127.0.0.1:${p.remotePort}`:""," · ",n(p.releaseChannel==="beta"?"st.about.beta":"st.about.stable")]})]}),r.jsx("button",{type:"button",disabled:I!==null,onClick:()=>{R(p.id),f(p.label),L(p.target.kind==="alias"?p.target.alias:p.target.hostname),P(p.identityFile??""),k(String(p.remotePort??58627)),l(p.serverHomeId??""),b(p.releaseChannel),W(null)},className:"rounded-md border border-hairline px-2 py-1 text-[11px] text-ink-soft disabled:opacity-50",children:n("goal.edit")}),r.jsx("button",{type:"button",disabled:I!==null,onClick:()=>tt(p.id),className:"rounded-md border border-hairline px-2 py-1 text-[11px] text-ink-soft disabled:opacity-50",children:n("connect.sshRemove")})]}),r.jsxs("label",{className:"mt-2 block text-[11px] text-ink-soft",children:[n("connect.sshToken"),r.jsx("input",{type:"password",value:N?.id===p.id?N.value:"",onChange:T=>g({id:p.id,value:T.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"})]}),r.jsx("button",{type:"button",disabled:I!==null,onClick:()=>se(p.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")})]},p.id)),r.jsxs("form",{onSubmit:Re,className:"mt-3 grid gap-2",children:[r.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("connect.sshLabel"),r.jsx("input",{value:i,onChange:p=>f(p.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"})]}),r.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("connect.sshAlias"),r.jsx("input",{value:y,onChange:p=>L(p.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"}),r.jsx("span",{className:"mt-1 block leading-relaxed",children:n("connect.sshAliasHint")})]}),r.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("connect.sshIdentity"),r.jsx("input",{value:j,onChange:p=>P(p.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"})]}),r.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("connect.sshPort"),r.jsx("input",{type:"number",min:1,max:65535,required:!0,value:F,onChange:p=>k(p.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"})]}),r.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("connect.sshHomeId"),r.jsx("input",{value:m,onChange:p=>l(p.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"})]}),r.jsxs("label",{className:"text-[11px] text-ink-soft",children:[n("st.about.channel"),r.jsxs("select",{value:h,onChange:p=>b(p.target.value),className:"mt-1 w-full rounded-md border border-hairline bg-paper px-2 py-1.5 text-[12px] text-ink",children:[r.jsx("option",{value:"stable",children:n("st.about.stable")}),r.jsx("option",{value:"beta",children:n("st.about.beta")})]}),r.jsx("span",{className:"mt-1 block leading-relaxed",children:n("connect.sshChannelHint")})]}),r.jsxs("div",{className:"flex gap-2",children:[r.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")}),E!==null?r.jsx("button",{type:"button",disabled:I!==null,onClick:()=>{R(null),f(""),L(""),P(""),k("58627"),l(""),b("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]})]}),O!==null?r.jsx("p",{role:"alert",className:"mt-2 whitespace-pre-wrap text-[11px] text-danger",children:O}):null]})}function gr({problem:t,onRetry:e}){const{t:n}=ge(),[s,a]=u.useState(!1),c=xr();return r.jsxs("div",{className:"px-7 pt-6 pb-7","data-web-link-problem":t,children:[r.jsx(Ue,{size:"lg"}),r.jsx("p",{className:"mt-3 text-[14px] font-medium text-ink",children:n(t==="retargeted"?"connect.webLinkRetargeted":"connect.webLinkRefused")}),r.jsx("p",{className:"mt-1.5 max-w-[46ch] text-[13px] leading-relaxed text-ink-soft",children:n(t==="retargeted"?"connect.webLinkRetargetedBody":"connect.webLinkRefusedBody")}),c!==null?r.jsx("a",{href:c,"data-web-link-app-connect":!0,className:"mt-5 block w-full rounded-md bg-accent px-3 py-2 text-center 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.webLinkEnterNew")}):e!==void 0?r.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,r.jsx("button",{type:"button","data-web-link-connect":!0,"aria-expanded":s,onClick:()=>{a(i=>!i)},className:"mt-3 w-full rounded-md px-3 py-1.5 text-[12px] text-ink-soft transition-colors hover:text-ink",children:n(s?"connect.webLinkHideConnect":"connect.webLinkUseConnect")})]})}function vr({initial:t,connecting:e,error:n,onConnect:s,onBack:a,desktopBoot:c,desktopFailure:i,onRetryDesktop:f,onCancelDesktopBoot:y,onConnectSsh:L,onSwitchLocal:j,sshProfile:P,webLink:F,onRetryWebLink:k}){return j!==void 0?r.jsx(Qe,{children:i!==null?r.jsxs(r.Fragment,{children:[r.jsx(Jt,{failure:i,onRetry:f,onSwitchLocal:j}),r.jsx("div",{className:"px-7 pb-7",children:r.jsx(Xt,{onConnect:L,selectedProfile:P})})]}):r.jsx(br,{onSwitchLocal:j})}):c!==null?r.jsx(Qe,{children:r.jsx(wr,{boot:c,onCancel:y})}):i!==null?r.jsxs(Qe,{children:[r.jsx(Jt,{failure:i,onRetry:f}),r.jsx("div",{className:"px-7 pb-7",children:r.jsx(Xt,{onConnect:L})})]}):F!==void 0?r.jsx(Qe,{children:r.jsx(gr,{problem:F,onRetry:k})}):r.jsx(Qe,{children:r.jsx(kr,{initial:t,connecting:e,error:n,onConnect:s,onBack:a})})}function Qe({children:t}){return r.jsx("div",{className:"flex h-full items-center justify-center overflow-y-auto bg-paper px-4 py-4",children:r.jsx("div",{className:"anim-enter w-full max-w-[420px]",children:r.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 yr(t){const[e,n]=u.useState(()=>Date.now());return u.useEffect(()=>{n(Date.now());const s=window.setInterval(()=>{n(Date.now())},1e3);return()=>{window.clearInterval(s)}},[t]),Math.max(0,Math.floor((e-t)/1e3))}function br({onSwitchLocal:t}){const{t:e}=ge();return r.jsxs("div",{className:"px-7 pt-6 pb-7",children:[r.jsx(Ue,{size:"lg"}),r.jsx("p",{className:"mt-2 text-[13px] text-ink-soft",children:e("connect.sshChecking")}),r.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 wr({boot:t,onCancel:e}){const{t:n}=ge(),s=yr(t.startedAtMs);return r.jsxs("div",{className:"px-7 pt-6 pb-7",children:[r.jsx(Ue,{size:"lg"}),r.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-soft",children:t.stage==="spawning"?n("connect.desktopBootingSpawning"):n("connect.desktopBootingWaiting")}),r.jsx("p",{className:"mt-1 font-mono text-[12px] text-ink-faint","aria-live":"polite",children:n("connect.desktopElapsed",{seconds:s})}),r.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 Jt({failure:t,onRetry:e,onSwitchLocal:n}){const{t:s}=ge(),[a,c]=u.useState(!1);u.useEffect(()=>{if(!a)return;const f=window.setTimeout(()=>{c(!1)},1500);return()=>{window.clearTimeout(f)}},[a]);const i=async()=>{try{await navigator.clipboard.writeText(t.message),c(!0)}catch{}};return r.jsxs("div",{className:"px-7 pt-6 pb-7",children:[r.jsx(Ue,{size:"lg"}),r.jsx("p",{className:"mt-2 text-[13px] font-semibold text-danger",children:s(n===void 0?"connect.desktopFailedTitle":"connect.sshFailedTitle")}),r.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?r.jsxs("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-soft",children:[s("connect.desktopLogPathLabel")," ",r.jsx("span",{className:"font-mono",children:t.logPath})]}):null,r.jsxs("div",{className:"mt-4 flex gap-2",children:[r.jsx("button",{type:"button",onClick:n??e,className:"flex-1 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-on-accent transition-colors hover:bg-accent-deep",children:s(n===void 0?"connect.desktopRetry":"connect.switchLocal")}),r.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:s(a?"connect.desktopCopied":"connect.desktopCopyDiagnostics")})]})]})}function kr({initial:t,connecting:e,error:n,onConnect:s,onBack:a}){const c=_t(),{t:i}=ge(),[f,y]=u.useState(t.url),[L,j]=u.useState(t.token),[P,F]=u.useState(!1),[k,m]=u.useState(t.url!==""||t.token!==""||n!==null);u.useEffect(()=>{n!==null&&m(!0)},[n]);const[l,h]=u.useState(!1),[b,E]=u.useState(null),R=g=>{g.preventDefault(),s({url:f.trim(),token:L.trim()})},N=async()=>{h(!0),E(null);try{const g=await c.connection.discover();if(g===null){E(i("connect.noneFound"));return}s(g.config,g.persist)}catch(g){E(c.kind==="tauri"?i("connect.desktopStartFailed",{detail:g instanceof Error?g.message:String(g)}):i("connect.detectNeedsDev"))}finally{h(!1)}};return r.jsxs("div",{className:"px-7 pt-6 pb-7",children:[r.jsx(Ue,{size:"lg"}),r.jsx("p",{className:"mt-3 font-display text-[18px] leading-snug text-ink-soft",children:i("connect.tagline")}),r.jsxs("form",{onSubmit:R,className:"mt-6",children:[r.jsx("button",{type:"button",onClick:()=>{N()},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")}),b!==null?r.jsx("p",{role:"status",className:"mt-2 text-[13px] leading-relaxed text-ink-soft",children:b}):null,r.jsxs("button",{type:"button","aria-expanded":k,"aria-controls":"connect-manual",onClick:()=>{m(g=>!g)},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:[r.jsx(ur,{open:k,className:"text-current"}),i("connect.otherMachine")]}),r.jsxs("div",{id:"connect-manual",hidden:!k,className:"mt-3",children:[r.jsx("label",{htmlFor:"connect-server-url",className:"mb-1 block text-[12px] font-medium text-ink-soft",children:i("connect.serverUrl")}),r.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:f,onChange:g=>{y(g.target.value)},spellCheck:!1}),r.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"),r.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")})]}),r.jsxs("div",{className:"mb-5 flex gap-2",children:[r.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:g=>{j(g.target.value)},spellCheck:!1,type:P?"text":"password"}),r.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(P?"st.providers.hideKey":"st.providers.showKey")} ${i("connect.token")}`,onClick:()=>{F(g=>!g)},children:i(P?"st.providers.hideKey":"st.providers.showKey")})]}),r.jsx("p",{id:"connect-token-help",className:"sr-only",children:i("connect.accessTokenHelp")}),n!==null?r.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,r.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?r.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 Ir(t,e){const[n,s]=t.queryKey;return n==="usage-v2"||n==="usage-v2-strip"||n==="usage-v2-strip-session"||n==="sessions"?!0:n==="session"?e===void 0||s===e:n!=="agentCapabilities"||t.queryKey.at(-1)==="catalog"?!1:e===void 0||typeof s=="object"&&s!==null&&"session_id"in s&&s.session_id===e}function en(t,e){let n=!0,s=!1;const a=new Set,c=async()=>{s=!0;try{for(;a.size>0;){if(!n)return;const y=[...a];a.clear();const L={predicate:j=>y.some(P=>Ir(j,P))};await e.cancelQueries(L),n&&await e.invalidateQueries(L,{cancelRefetch:!1})}}finally{s=!1}},i=y=>{a.add(y),s||c().catch(()=>{})},f=t.events.on("usage.settled",({sessionId:y})=>{n&&i(y)});return f.ready.then(()=>{n&&i()}).catch(()=>{}),()=>{n=!1,f.dispose()}}const Sr=[["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 jr(t){await Promise.all(Sr.map(e=>t.invalidateQueries({queryKey:[...e]})))}function tn(t,e){let n=!0;const s=()=>{jr(e).catch(()=>{})},a=t.events.on("plugins.changed",()=>{n&&s()});return a.ready.then(()=>{n&&s()}).catch(()=>{}),()=>{n=!1,a.dispose()}}const Pt="kiki.connection",Mr=["server","url","token"];function Cr(t){const e=new URLSearchParams(t.search);for(const i of Mr)e.delete(i);const n=e.toString(),s=t.hash.startsWith("#")?t.hash.slice(1).split("&"):[],a=s.filter(i=>!i.startsWith("token=")&&!i.startsWith("access=")),c=a.length===s.length?t.hash:a.length===0?"":`#${a.join("&")}`;return`${t.pathname}${n===""?"":`?${n}`}${c}`}function _r(t=window.location){const e=new URLSearchParams(t.search),n=e.get("server")??e.get("url"),s=e.get("token");if(n!==null||s!==null)return{url:n??"",token:s??""};const a=/(?:^|#|&)token=([^&]+)/.exec(t.hash);return a!==null?{url:"",token:decodeURIComponent(a[1]??"")}:null}function Pr(t){try{const e=(t??localStorage).getItem(Pt);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 Rr(t,e){try{return(e??localStorage).setItem(Pt,JSON.stringify(t)),!0}catch{return!1}}function Er(t){try{return(t??localStorage).removeItem(Pt),!0}catch{return!1}}function Nr(t){return t.desktop!==void 0?{config:t.desktop,persist:!1,source:"desktop"}:t.deepLink!==void 0&&t.deepLink!==null?{config:t.deepLink,persist:Ar(t.deepLink.url),source:"deep-link"}:t.stored!==void 0&&t.stored!==null?{config:t.stored,persist:!0,source:"stored"}:null}function Ar(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}}class yt extends Error{constructor(e,n){super(n),this.kind=e}}function bt(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,kind:e.kind==="identity"||e.kind==="authentication"||e.kind==="protocol"?e.kind:t instanceof xe&&t.code===Ce.UNAUTHORIZED?"authentication":t instanceof xe&&t.code===Ce.INVALID_RESPONSE?"protocol":void 0}}return{message:t instanceof Error?t.message:String(t),stderrTail:[],logPath:null}}async function ys(t,e,n){n.throwIfAborted();const s=e.scopeId.slice(7);if(e.homeId!==e.scopeId||!e.scopeId.startsWith("remote:")||!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(s))throw new S("scope-invalid");if(t.openRemoteSpace===void 0)throw new S("scope-invalid");await t.openRemoteSpace(s),n.throwIfAborted()}async function wt(t,e,n){n.throwIfAborted();const s=new URL(e,"http://example.test").pathname,a=/^\/s\/([^/]+)/.exec(s)?.[1],c=/^\/(?:rooms|r)\/([^/]+)$/.exec(s)?.[1];try{if(a!==void 0){await t.getSession(decodeURIComponent(a)),n.throwIfAborted();const i=/^\/s\/[^/]+\/agent\/([^/]+)$/.exec(s)?.[1];if(i!==void 0&&decodeURIComponent(i)!=="main"){const f=await t.klient.session(decodeURIComponent(a)).agents();if(!Object.hasOwn(f,decodeURIComponent(i)))throw new S("target-missing")}}if(c!==void 0){const i=t.klient.rest;if(i===void 0)throw new S("offline");if(await i.rooms.get(decodeURIComponent(c))===void 0)throw new S("target-missing")}}catch(i){throw a!==void 0&&i instanceof xe&&Gn(i.message)?new S("target-missing"):c!==void 0&&i instanceof Xe&&i.code===Ce.REQUEST_INVALID&&i.message===`Room '${decodeURIComponent(c)}' does not exist.`?new S("target-missing"):(i instanceof xe||i instanceof Xe)&&i.code===Ce.UNAUTHORIZED?new S("auth-required"):i}n.throwIfAborted()}function Lr(t){return{async prepare(e,n,s){n.throwIfAborted();const a=t.active(),c=a.scope.homeId!==e.homeId;if(!c&&e.scopeId===a.scope.scopeId&&s===void 0){let m;try{m=await a.client.meta()}catch(h){throw(h instanceof xe||h instanceof Xe)&&h.code===Ce.UNAUTHORIZED?new S("auth-required"):h}n.throwIfAborted();const l=e.serverHomeId??a.scope.serverHomeId;if(l!==void 0&&l!==m.server_home_id||e.connectionRef!==void 0&&e.connectionRef!==a.scope.connectionRef)throw new S("identity-mismatch");return{scope:{...a.scope,serverHomeId:m.server_home_id},validate:(h,b)=>wt(a.client,h,b),commit:()=>{n.throwIfAborted()},dispose:()=>{}}}let i,f,y=!1,L=!1,j=a.scope.homeId,P=!1,F;t.preparing?.(!0);const k=async()=>{try{if(y&&f!==void 0&&(y=!1,await f.klient.close()),F!==void 0){const m=F;F=void 0,await t.host.connection.disconnectSshProfile?.(m.id,m.tunnelId)}L&&(L=!1,await t.host.prepareSpace?.(j))}finally{t.preparing?.(!1)}};try{if(e.scopeId.startsWith("remote:")||e.homeId.startsWith("remote:")){const h=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(h))throw new S("scope-invalid");const b=t.control?.()??t.local();if(b===null||b.selection.source==="remote"||b.selection.source==="ssh")throw new S("offline");const E=b.client.klient.rest?.connections;if(E===void 0)throw new S("offline");const R=await E.list();n.throwIfAborted();const N=R.find(U=>U.id===h);if(N===void 0)throw new S("scope-invalid");if(N.enabled!==!0||N.state==="disabled"||N.target.protocol!==Hn)throw new S("identity-mismatch");i={config:b.selection.config,persist:!1,source:"remote",scopeId:e.scopeId,connectionId:N.id,serverHomeId:N.target.homeId},f=t.createClient?.(i)??St({endpoint:i.config.url,token:i.config.token,connectionId:N.id}),y=!0;const g=await f.meta();if(n.throwIfAborted(),g.server_home_id!==N.target.homeId||e.serverHomeId!==void 0&&e.serverHomeId!==g.server_home_id||e.connectionRef!==void 0&&e.connectionRef!==N.id)throw new S("identity-mismatch");const I=f;return{scope:{...e,serverHomeId:g.server_home_id,connectionRef:N.id},validate:(U,O)=>wt(I,U,O),commit:()=>{n.throwIfAborted(),t.commit(i,I,g),t.reload(),y=!1,t.preparing?.(!1)},dispose:k}}if(e.scopeId.startsWith("ssh:")&&!s&&!e.connectionRef)throw new S("auth-required");if(c&&a.selection.source==="remote"&&(j=t.host.activeSpace===void 0?"main":It(await t.host.activeSpace())?.homeId??"main",n.throwIfAborted(),P=e.homeId===j&&(e.scopeId==="local"||e.scopeId.startsWith("direct:"))),c&&!P){if(!t.host.prepareSpace)throw new S("scope-invalid");const h=await t.host.prepareSpace(e.homeId);if(L=!0,n.throwIfAborted(),h.homeId!==e.homeId)throw new S("identity-mismatch")}if(e.scopeId.startsWith("ssh:")){const h=e.scopeId.slice(4),b=await t.host.connection.listSshProfiles?.();n.throwIfAborted();const E=b?.find(g=>g.id===h);if(E===void 0)throw new S("scope-invalid");if(!E.serverHomeId||!E.remotePort)throw new S("scope-invalid");let R;if(s!==void 0){if(!/^[A-Za-z0-9_-]{43}$/.test(s))throw new S("auth-required");if(!t.host.connection.prepareSshProfile)throw new S("scope-invalid");try{R=await t.host.connection.prepareSshProfile(h,s)}catch(g){if(g instanceof S)throw g;const I=g instanceof Error?g.message:String(g);throw I.includes("rejected the bearer token")?new S("auth-required"):I.includes("home identity")||I.includes("authentication; SSH connection blocked")||I.includes("build identity")||I.includes("release channel")?new S("identity-mismatch"):g}R.tunnelId&&(F={id:h,tunnelId:R.tunnelId})}else{if(!e.connectionRef||!t.host.connection.resumeScopeConnection)throw new S("auth-required");try{R=(await t.host.connection.resumeScopeConnection(e.homeId,h,e.connectionRef)).connection}catch(g){const I=g instanceof Error?g.message:String(g);throw new S(I.includes("offline")?"offline":I.includes("identity changed")?"identity-mismatch":"auth-required")}if(R.tunnelId!==e.connectionRef)throw new S("identity-mismatch")}n.throwIfAborted();let N;try{N=new URL(R.config.url)}catch{throw new S("identity-mismatch")}if(N.protocol!=="http:"||N.hostname!=="127.0.0.1"||N.username||N.password||!N.port||!R.tunnelId||s!==void 0&&R.config.token!==s||R.serverHomeId!==E.serverHomeId)throw new S("identity-mismatch");i={config:R.config,persist:!1,source:"ssh",scopeId:e.scopeId,profile:E,tunnelId:R.tunnelId,serverHomeId:R.serverHomeId,serverInstanceId:R.serverInstanceId,serverVersion:R.serverVersion,buildId:R.buildId,buildChannel:R.buildChannel}}else if(e.scopeId==="local"||P&&e.scopeId.startsWith("direct:"))if(c&&!P){const h=await t.host.connection.discover();if(h===null)throw new S("offline");i={config:h.config,persist:!1,source:"desktop",scopeId:"local"}}else{const h=P?t.control?.()??t.local():t.local();if(h===null)throw new S("offline");if(e.scopeId.startsWith("direct:")&&e.scopeId!==(h.selection.scopeId??`direct:${h.selection.config.url.trim().replace(/\/+$/,"")}`))throw new S("scope-invalid");i=h.selection,f=h.client}else if(e.homeId===a.scope.homeId&&e.scopeId===a.scope.scopeId)i=a.selection,f=a.client;else throw new S("scope-invalid");n.throwIfAborted(),f===void 0&&(f=t.createClient?.(i)??new qe({baseUrl:i.config.url,token:i.config.token}),y=!0);const m=await f.meta();if(n.throwIfAborted(),e.serverHomeId!==void 0&&m.server_home_id!==e.serverHomeId)throw new S("identity-mismatch");if(i.source==="ssh"&&(m.server_home_id!==i.serverHomeId||m.server_id!==i.serverInstanceId||m.server_version!==i.serverVersion||m.dangerous_bypass_auth!==!1||(m.build_id??null)!==i.buildId||(m.build_channel??null)!==i.buildChannel))throw new S("identity-mismatch");const l=f;return{scope:{...e,serverHomeId:m.server_home_id,connectionRef:i.source==="ssh"?i.tunnelId:void 0},validate:(h,b)=>wt(l,h,b),commit:async()=>{if(n.throwIfAborted(),i.source==="ssh"&&i.profile&&i.tunnelId){if(!t.host.connection.commitScopeConnection)throw new S("scope-invalid");await t.host.connection.commitScopeConnection(e.homeId,i.profile.id,i.tunnelId,c),n.throwIfAborted()}c?(y&&await l.klient.close(),n.throwIfAborted(),t.reload()):t.commit(i,l,m),y=!1,L=!1,F=void 0,t.preparing?.(!1)},dispose:k}}catch(m){throw await k(),(m instanceof xe||m instanceof Xe)&&m.code===Ce.UNAUTHORIZED?new S("auth-required"):m}}}}function kt(){const t=`${window.location.pathname}${window.location.search}${window.location.hash}`,e=Cr(window.location);if(e!==t)try{window.history.replaceState(window.history.state,"",e)}catch{}}function un(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 Ye(t,e){t.invalidateQueries({queryKey:["sessions"]}),t.invalidateQueries({queryKey:["rooms"]}),t.invalidateQueries({queryKey:["activity-prompts",e]}),t.invalidateQueries({queryKey:["activity-tasks",e]})}const dn=3,Rt=64*1024*1024,hn=Rt/2,fn=5*6e4,pn=4;function Ze(t){const e=t.getState();return e.busy||e.pendingInteraction!=="none"||e.tasks.some(n=>n.status==="running")}function Tr(t){const e=t.getState();return e.loaded&&e.loadError===void 0&&!(e.resyncFailed&&e.resyncError?.retryable===!1)}class mn{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??dn,maxBytes:e.maxBytes??Rt,maxEntryBytes:e.maxEntryBytes??hn,ttlMs:e.ttlMs??fn,maxLiveParked:e.maxLiveParked??pn},this.now=e.now??Date.now,this.setTimer=e.setTimer??((n,s)=>setTimeout(n,s)),this.clearTimer=e.clearTimer??(n=>{clearTimeout(n)})}acquire(e,n,s){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 y=s();if(y.sessionId!==e||this.controllers.has(y))throw new Error("Controller factory must return a fresh controller for the requested session");c={controller:y,ready:y.open(),references:1,sessions:a,sessionId:e},a.set(e,c),this.add(y)}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 f=!1;return{controller:i.controller,ready:i.ready,release:()=>{f||(f=!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,s]of Array.from(this.parked))s===e&&this.dispose(n)}clearParked(){for(const e of Array.from(this.parked.keys()))this.dispose(e)}park(e,n){const{controller:s}=e;if(typeof s.getState!="function"||typeof s.suspend!="function"||!Tr(s))return!1;const a=s.residentBytes();if(a>this.limits.maxEntryBytes)return!1;const c=s.subscribe(()=>{this.onParkedChange(e)});return e.parked={at:this.now(),bytes:a,unsubscribe:c},this.parked.set(e,n),Ze(s)||s.suspend(),this.delete(s),this.enforceLimits(),!0}unpark(e){e.parked?.unsubscribe(),e.parked=void 0,this.parked.delete(e),this.scheduleTtl()}dispose(e){e.parked!==void 0&&this.unpark(e),e.sessions.get(e.sessionId)===e&&e.sessions.delete(e.sessionId),e.controller.close(),this.delete(e.controller)}onParkedChange(e){const n=e.parked;if(n===void 0||e.controller.suspended||Ze(e.controller))return;const s=this.parked.get(e)??{};e.parked={...n,at:this.now()},this.parked.delete(e),this.parked.set(e,s),e.controller.suspend(),this.enforceLimits()}isLiveProtected(e){return!e.controller.suspended&&Ze(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 s=()=>Array.from(this.parked.keys()).filter(i=>!this.isLiveProtected(i));let a=s(),c=a.reduce((i,f)=>i+(f.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=s()}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 et=u.createContext(null),Dr=15e3;let nn=0;function xn(t=Date.now()){return nn+=1,`gui-${t.toString(36)}-${nn.toString(36)}`}function me(t){return t?.source==="desktop"}function Hr(t,e){return t.url.trim().replace(/\/+$/,"")===e.url.trim().replace(/\/+$/,"")&&t.token.trim()===e.token.trim()}function Fr(t,e){for(const n of["server_id","server_home_id","current_space_id","dangerous_bypass_auth","started_at"])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 Or({children:t}){const e=_t(),n=e.kind==="tauri",s=zn(),{locale:a,t:c}=ge(),i=u.useRef(new Map),f=Fn(),y=u.useRef(f?.scopeId.startsWith("remote:")?f:null),j=u.useSyncExternalStore(On,Qn,qn).requestTimeoutSeconds*1e3,[P,F]=u.useState(()=>$n()),[k,m]=u.useState(P.kind==="failed"?Un(P.reason):void 0),[l,h]=u.useState(()=>n||s?null:P.kind==="signed-in"?{config:{url:"",token:""},persist:!1,source:"web-cookie"}:(Wn(o=>{!o||C.current!==null||(K.current+=1,h({config:{url:"",token:""},persist:!1,source:"web-cookie"}))}),Nr({deepLink:_r(),stored:Pr()}))),b=l?.config??null,E=l?.scopeId??(n?"local":`direct:${b?.url.trim().replace(/\/+$/,"")??""}`),R=l?.source==="remote"?l.connectionId??null:null,N=l?.source??null,g=R===null?xt()?.homeId??"main":`remote:${R}`;let I=i.current.get(E);I===void 0&&(I=new ar({defaultOptions:{queries:{retry:1,staleTime:0,refetchOnWindowFocus:!1}}}),i.current.set(E,I));const[U,O]=u.useState(null),[W,q]=u.useState(null),[Pe,ee]=u.useState(()=>n?{stage:"spawning",startedAtMs:Date.now()}:null),[Re,se]=u.useState(null),[tt,p]=u.useState(0),T=u.useRef(!1),[te,ve]=u.useState("closed"),ie=u.useRef("closed"),ne=u.useRef(null),H=u.useRef(null),nt=u.useRef(!1),We=u.useRef(new mn),K=u.useRef(0),ye=u.useRef(0),ae=u.useRef(null),[le,gn]=u.useState(null),re=u.useCallback(o=>{ae.current=o,gn(o)},[]),rt=u.useRef(null),Nt=u.useRef(new Map),Ee=u.useRef(null),Ke=u.useRef(!1),vn=u.useRef({promise:null,consumed:!1}),C=u.useRef(l);C.current=l;const yn=u.useRef(xn()),ue=u.useRef(void 0),Ve=u.useRef(void 0);u.useEffect(()=>(e.connection.setWorkspaceScope?.(l?.source==="ssh"?"ssh":"local"),()=>e.connection.setWorkspaceScope?.("local")),[e,l?.source]),u.useEffect(()=>{if(!s)return;let o=!1;return e.connection.discover().then(d=>{o||d!==null&&(K.current+=1,h({config:d.config,persist:d.persist,source:"local-detection"}))},d=>{o||q({kind:"raw",text:d instanceof Error?d.message:String(d)})}),()=>{o=!0}},[e,s]),u.useEffect(()=>{if(e.kind!=="tauri")return;let o=!1,d=0;T.current=!1;let v,x,D=0;const _=()=>{if(o||T.current||x!==void 0||H.current?.phase==="blocked")return;const M=Math.min(1e3*2**Math.min(D++,4),1e4);x=setTimeout(()=>{if(x=void 0,o||T.current||Ke.current)return;const G=C.current?.source;G!==void 0&&G!=="desktop"&&G!=="ssh"&&G!=="remote"||He()},M)},Q=()=>{x!==void 0&&clearTimeout(x),x=void 0,D=0},fe=()=>{const M=ne.current;return M!==null&&M.selection===C.current&&M.client===he.current&&M.homeId===(xt()?.homeId??"main")&&M.scopeId===(C.current?.scopeId??"local")?M:null},B=M=>{const G=fe();if(G===null)return!1;const w=bt(M);return H.current={client:G.client,phase:w.kind===void 0?"failed":"blocked",suspended:w.kind!==void 0||H.current?.suspended===!0},ve("closed"),ee(null),se(w),w.kind===void 0?_():(Q(),G.client.suspendDesktop()),!0};let V=!1;const He=M=>{if(o||V&&M===void 0||T.current)return;V=!0;const G=++d,w=fe(),ft=H.current?.suspended===!0;w!==null?(H.current={client:w.client,phase:"checking",suspended:ft},ve("connecting")):me(C.current)||re(null),C.current===null&&ee(z=>({stage:"waiting",startedAtMs:z?.startedAtMs??Date.now()}));const Sn=C.current,jn=K.current,Be=()=>!o&&!T.current&&G===d&&C.current===Sn&&K.current===jn,Me=vn.current;M===void 0&&(Me.promise??=(e.connection.takeScopeConnection?.()??Promise.resolve(null)).then(z=>{if(z===null)return null;const $=z.connection;return{config:$.config,persist:!1,source:"ssh",scopeId:`ssh:${z.profile.id}`,profile:z.profile,tunnelId:$.tunnelId,serverHomeId:$.serverHomeId,serverInstanceId:$.serverInstanceId,serverVersion:$.serverVersion,buildId:$.buildId,buildChannel:$.buildChannel}}).catch(()=>null));const Mn=M===void 0?e.connection.discover():Promise.resolve({config:M,persist:!1});Promise.all([Mn,Me.consumed||M!==void 0?Promise.resolve(null):Me.promise]).then(async([z,$])=>{if(o||T.current||G!==d||$===null&&!Be())return;ee(null);const Ot=!me(C.current)&&C.current!==null;if(z===null){if(B(new Error("Desktop connection discovery returned no verified endpoint."))||(re(null),Ot))return;q({kind:"key",key:"conn.desktopNoServer"}),_();return}if(w!==null&&$===null){const Qt=Hr(w.selection.config,z.config),mt=Qt&&!ft?w.client:new qe({baseUrl:z.config.url.trim().replace(/\/+$/,""),token:z.config.token.trim(),timeoutMs:j});let J;try{J=await mt.meta()}finally{mt!==w.client&&mt.klient.close()}if(!Be()||fe()!==w)return;const qt=Fr(w.meta,J);if(!w.meta.server_home_id||w.meta.server_home_id!==J.server_home_id||w.meta.current_space_id!==J.current_space_id||J.current_space_id!==w.homeId)throw new yt("identity","The desktop backend home or space changed. Reopen the intended space to connect.");if(w.meta.dangerous_bypass_auth!==J.dangerous_bypass_auth||J.dangerous_bypass_auth!==!1)throw new yt("authentication","The desktop backend authentication mode changed. This connection is blocked.");if(qt==="unknown")throw new yt("identity","The desktop backend identity could not be verified.");if(ft||!Qt||qt==="changed"){const Oe={config:z.config,persist:!1,source:"desktop",scopeId:w.scopeId};H.current=null,nt.current=!0;try{w.client.rebindDesktop(z.config)}finally{nt.current=!1}K.current+=1,ze.current={client:w.client,meta:J},pe.current={selection:Oe,client:w.client,timeoutMs:j},ct(pe.current),re(Oe),at({endpoint:z.config.url.trim().replace(/\/+$/,""),token:z.config.token.trim(),scopeId:w.scopeId,client:w.client}),C.current=Oe,h(Oe),ne.current={...w,selection:Oe,meta:J},I.invalidateQueries()}else ne.current={...w,meta:J},H.current=null;Q(),se(null),O(J),q(null),ve(ie.current),ie.current!=="open"&&w.client.klient.terminal.nudge();return}Q(),se(null);const pt={config:z.config,persist:!1,source:"desktop",scopeId:"local"};if(re(pt),$!==null&&!Me.consumed){Me.consumed=!0,Me.promise=Promise.resolve(null),C.current=$,$.profile&&$.tunnelId&&(Ee.current={id:$.profile.id,tunnelId:$.tunnelId}),K.current+=1,h($);return}Ot||!Be()||(w!==null&&i.current.get(w.scopeId)?.clear(),ne.current=null,H.current=null,O(null),q(null),K.current+=1,C.current=pt,h(pt))}).catch(z=>{if(!Be()||B(z)||(re(null),!me(C.current)&&C.current!==null))return;K.current+=1,ee(null),O(null),C.current=null,h(null);const $=bt(z);se($),$.kind===void 0?_():Q()}).finally(()=>{G===d&&(V=!1)})};let Fe;ue.current=void 0;const Ht=()=>{Fe===void 0&&(Fe=setTimeout(()=>{if(Fe=void 0,o||H.current?.phase==="blocked")return;const M=C.current?.source;!me(C.current)&&M!=="ssh"&&M!=="remote"||Ke.current||He()},250))};ue.current=Ht,Ve.current=_;const Ft=()=>C.current?.source==="ssh"||C.current?.source==="remote",ht=()=>C.current===null||me(C.current);return e.connection.onBackendStage(M=>{if(o||T.current||Ke.current)return;if(M==="waiting"){if(!V||!ht())return;ee(w=>({stage:"waiting",startedAtMs:w?.startedAtMs??Date.now()}));return}if(M!==null&&typeof M=="object"&&"stage"in M&&M.stage==="ready"&&"connection"in M){if(!ht()&&!Ft()||V&&fe()===null)return;const w=M.connection;if(w===null||typeof w!="object"||!("url"in w)||typeof w.url!="string"||!("token"in w)||typeof w.token!="string")return;Ft()?re({config:{url:w.url,token:w.token},persist:!1,source:"desktop",scopeId:"local"}):He({url:w.url,token:w.token});return}if(M===null||typeof M!="object"||!("stage"in M)||M.stage!=="failed"||!("failure"in M)||!ht()||(d+=1,V=!1,B(M.failure)))return;re(null),K.current+=1,O(null),h(null),q(null),ee(null);const G=bt(M.failure);se(G),G.kind===void 0?_():Q()}).then(M=>{o?M():(v=M,He())},()=>{He()}),()=>{o=!0,d+=1,Fe!==void 0&&clearTimeout(Fe),x!==void 0&&clearTimeout(x),Ve.current===_&&(Ve.current=void 0),ue.current===Ht&&(ue.current=void 0),v?.()}},[e,tt,re,j]);const st=u.useCallback(()=>{se(null),q(null),ee({stage:"spawning",startedAtMs:Date.now()}),p(o=>o+1)},[]),bn=u.useCallback(()=>{T.current=!0,ee(null),se({message:c("connect.desktopCancelled"),stderrTail:[],logPath:null}),e.connection.cancelStartup?.().catch(()=>{})},[e,c]),it=le?.config.url.trim().replace(/\/+$/,"")??null,ot=le?.config.token.trim()??null,[be,ct]=u.useState(null),pe=u.useRef(be);pe.current=be;const de=le!==null&&be?.selection===le?be.client:null,he=u.useRef(de);he.current=de;const ze=u.useRef(null);u.useEffect(()=>{if(le===null||it===null||ot===null){ct(null);return}if(pe.current?.selection===le&&pe.current.timeoutMs===j)return;const o=new qe({baseUrl:it,token:ot,timeoutMs:j,onSessionMutation:d=>{const v=i.current.get("local");v!==void 0&&Ye(v,d)}});pe.current={selection:le,client:o,timeoutMs:j},ct(pe.current)},[le,it,ot,j]),u.useEffect(()=>{const o=be?.client,d=We.current;return()=>{o!==void 0&&(ne.current?.client===o&&(ne.current=null),H.current?.client===o&&(H.current=null),d.evictScope(o),o.klient.close())}},[be?.client]),u.useEffect(()=>{if(!(e.kind!=="tauri"||de===null||l?.source!=="ssh"&&l?.source!=="remote"))return de.klient.terminal.onStatus(o=>{o==="closed"&&ue.current?.()})},[e,de,l?.source]);const we=b?.url.trim().replace(/\/+$/,"")??null,ke=b?.token.trim()??null,[Ne,at]=u.useState(null),Ie=l?.source==="desktop",Ae=rt.current?.selection===l?rt.current:null,Le=Ie?de:null,A=Ae?.client??(Ne?.endpoint===we&&Ne.token===ke&&Ne.scopeId===E&&(!Ie||Ne.client===Le)?Ne.client:null),Y=A?.klient??null;u.useEffect(()=>{if(we===null||ke===null||Ie&&Le===null)return;const o=x=>{Ye(I,x)},d=Ae?.client??Le??(l?.source==="remote"?St({endpoint:we,token:ke,connectionId:l.connectionId,timeoutMs:j,onSessionMutation:o}):new qe({baseUrl:we,token:ke,timeoutMs:j,onSessionMutation:o}));at({endpoint:we,token:ke,scopeId:E,client:d});const v=We.current;return()=>{d!==Le&&(ne.current?.client===d&&(ne.current=null),H.current?.client===d&&(H.current=null),v.evictScope(d),d.klient.close())}},[we,ke,E,j,I,Ie,Le,Ae?.client]),u.useEffect(()=>{if(A===null||y.current!==null&&l?.source!=="remote")return;let o=!1;const d=K.current;q(null);const v=Ae?.client===A?Ae:ze.current?.client===A?ze.current:null;return v!==null&&(ze.current=null),(v!==null?Promise.resolve(v.meta):A.meta()).then(x=>{if(!(o||d!==K.current)){if(kt(),l?.source==="ssh"){const D=l.serverHomeId,_=Nt.current.get(E);if(!D||!l.serverInstanceId||!l.serverVersion||x.server_home_id!==D||x.server_id!==l.serverInstanceId||x.server_version!==l.serverVersion||x.dangerous_bypass_auth!==!1||(x.build_id??null)!==l.buildId||(x.build_channel??null)!==l.buildChannel||_!==void 0&&_!==D){O(null),q({kind:"raw",text:"SSH server identity changed or could not be verified. This connection is blocked."});return}Nt.current.set(E,D)}if(l?.source==="remote"&&(!l.serverHomeId||x.server_home_id!==l.serverHomeId)){O(null),q({kind:"raw",text:"identity-mismatch"});return}l?.source!=="remote"&&l?.persist===!0&&b!==null&&Rr(b),l?.source==="desktop"&&l===C.current&&(ne.current={selection:l,client:A,meta:x,homeId:g,scopeId:E},H.current=null),O(x)}},x=>{o||d!==K.current||(O(null),q({kind:"raw",text:x instanceof xe||x instanceof Error?x.message:String(x)}),kt(),l?.source==="desktop"&&Ve.current?.())}),()=>{o=!0}},[A,b,l?.persist]);const Se=b!==null&&U!==null&&A!==null;u.useEffect(()=>{if(!Se||A===null)return;const o=()=>{A.renewLease({clientId:yn.current,kind:"gui"}).catch(()=>{})};o();const d=window.setInterval(o,Dr);return()=>{window.clearInterval(d)}},[A,Se]),u.useEffect(()=>{if(!Se||l?.source!=="ssh"||!e.connection.sshTunnelRunning)return;const o=l.profile?.id,d=l.tunnelId;if(!o||!d)return;let v=!0,x=!1;const D=()=>{x||(x=!0,e.connection.sshTunnelRunning(o,d).then(Q=>{!v||Q||(K.current+=1,O(null),q({kind:"raw",text:"SSH tunnel disconnected. Check the remote service and connect again."}))},Q=>{v&&(K.current+=1,O(null),q({kind:"raw",text:`Cannot check the SSH tunnel: ${String(Q)}`}))}).finally(()=>{x=!1}))};D();const _=window.setInterval(D,2e3);return()=>{v=!1,window.clearInterval(_)}},[Se,l?.source,l?.profile?.id,l?.tunnelId,e]);const X=u.useMemo(()=>{const o=Se?Y?.terminal??null:null;return o===null||!Ie?o:{...o,nudge:()=>{H.current?.client===A&&H.current.phase==="blocked"||(o.nudge(),H.current?.client===A&&ue.current?.())}}},[Se,Y,A,Ie]);u.useEffect(()=>{if(X===null||Y===null)return;let o=!0;const d=()=>{const B=Y.events.on("search.indexStateChanged",V=>{I.cancelQueries({queryKey:["search-index-state"]}).then(()=>{o&&v===B&&I.setQueryData(["search-index-state"],V)})});return B.ready.then(()=>{if(o&&v===B)return I.invalidateQueries({queryKey:["search-index-state"]})}).catch(()=>{}),B};let v=d(),x=en(Y,I),D=tn(Y,I);const _=Y.events.on("session.workChanged",B=>{I.setQueriesData({queryKey:["sessions"]},V=>Zn(V,B)),I.setQueriesData({queryKey:["thread-ref"]},V=>V===void 0?V:cn(V,B))}),Q=X.onStatus(B=>{if(!o)return;ie.current=B,B==="closed"&&!nt.current&&e.kind==="tauri"&&me(C.current)&&H.current?.phase!=="blocked"&&(A!==null&&ne.current?.client===A&&H.current===null&&(H.current={client:A,phase:"checking"}),ue.current?.());const V=H.current?.client===A?H.current:null;ve(V?.phase==="blocked"||V?.phase==="failed"?"closed":V!==null&&B==="open"?"connecting":B),B==="open"&&V?.phase==="failed"&&ue.current?.(),B==="open"&&(v.dispose(),v=d(),x(),x=en(Y,I),D(),D=tn(Y,I))}),fe=Y.events.on("kosong.changed",()=>{un({type:"event.model_catalog.changed"},I)});return()=>{o=!1,Q(),fe.dispose(),v.dispose(),_.dispose(),x(),D()}},[X,Y,I]),u.useEffect(()=>{if(X!==null)return Yn()},[X]),u.useEffect(()=>{if(X===null)return;const o=()=>{X.nudge();for(const v of We.current)v.nudge()},d=()=>{document.visibilityState==="visible"&&o()};return window.addEventListener("online",o),window.addEventListener("focus",o),window.addEventListener("pageshow",o),document.addEventListener("visibilitychange",d),()=>{window.removeEventListener("online",o),window.removeEventListener("focus",o),window.removeEventListener("pageshow",o),document.removeEventListener("visibilitychange",d)}},[X]);const[At,wn]=u.useState(!1),oe=u.useRef({scope:{homeId:g,scopeId:E},selection:l,client:A});oe.current={scope:{homeId:g,scopeId:E},selection:l,client:A};const je=u.useMemo(()=>Lr({host:e,active:()=>{const o=oe.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&&he.current!==null?{selection:ae.current,client:he.current}:null,control:()=>{if(ae.current!==null&&he.current!==null)return{selection:ae.current,client:he.current};const o=oe.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"?St({endpoint:o.config.url,token:o.config.token,connectionId:o.connectionId,timeoutMs:j,onSessionMutation:d=>{const v=i.current.get(o.scopeId);v!==void 0&&Ye(v,d)}}):new qe({baseUrl:o.config.url,token:o.config.token,timeoutMs:j}),reload:()=>{y.current===null&&wn(!0)},preparing:o=>{Ke.current=o},commit:(o,d,v)=>{if(ye.current+=1,K.current+=1,o===oe.current.selection&&d===oe.current.client){O(v);return}const x=oe.current.selection;o.source==="remote"&&!n&&x!==null&&x.source!=="remote"&&x.source!=="ssh"&&re({...x,scopeId:oe.current.scope.scopeId});const D=o.source==="ssh"&&o.profile&&o.tunnelId?{id:o.profile.id,tunnelId:o.tunnelId}:null;Ee.current=D,rt.current={selection:o,client:d,meta:v},C.current=o,h(o),at({endpoint:o.config.url.trim().replace(/\/+$/,""),token:o.config.token.trim(),scopeId:o.scopeId??"local",client:d}),q(null),O(v)}}),[e,j,n,re]);u.useEffect(()=>{const o=y.current;if(o===null||A===null||l?.source==="remote")return;const d=new AbortController;return(async()=>{const v=await je.prepare(o,d.signal);try{await v.validate(`${window.location.pathname}${window.location.search}${window.location.hash}`,d.signal),d.signal.throwIfAborted(),await v.commit(),y.current=null}catch(x){throw await v.dispose(),x}})().catch(v=>{d.signal.aborted||(O(null),q({kind:"raw",text:v instanceof Error?v.message:String(v)}))}),()=>{d.abort()}},[A,l?.source,je]);const Lt=u.useCallback(async(o=new AbortController().signal)=>{const d=he.current,v=C.current,x=ye.current,D=v?.source==="remote"?e.activeSpace===void 0?"main":It(await e.activeSpace())?.homeId??"main":xt()?.homeId??"main",_=await je.prepare({homeId:D,scopeId:"local"},o);try{if(o.throwIfAborted(),d!==he.current||v!==C.current||x!==ye.current)throw new DOMException("Local connection restoration was superseded.","AbortError");await _.commit()}catch(Q){throw await _.dispose(),Q}},[je,e]),Te=u.useCallback(()=>{if(U!==null&&A!==null){C.current?.source==="remote"?(async()=>{const d=e.activeSpace===void 0?"main":It(await e.activeSpace())?.homeId??"main";await gt({homeId:d,scopeId:ae.current?.scopeId??"local"})})().catch(()=>{}):gt({scopeId:"local"}).catch(()=>{});return}ye.current+=1,K.current+=1;const o=Ee.current;Ee.current=null,o!==null&&e.connection.disconnectSshProfile?.(o.id,o.tunnelId).catch(()=>{}),O(null),q(null),h(ae.current),ae.current===null&&n&&st()},[U,A,e,n,st]),lt=u.useCallback(async(o,d)=>{if(oe.current.client!==null&&oe.current.selection!==null){await gt({scopeId:`ssh:${o}`,token:d});return}if(!e.connection.connectSshProfile||!e.connection.listSshProfiles)throw new Error("SSH connections are available only in the desktop application.");const v=++ye.current,D=(await e.connection.listSshProfiles()).find(fe=>fe.id===o);if(!D)throw new Error("SSH profile no longer exists.");if(!D.serverHomeId||!D.remotePort||!/^[A-Za-z0-9_-]{43}$/.test(d))throw new Error("Set the remote Kiki port, expected home ID and bearer token first.");const _=await e.connection.connectSshProfile(o,d);if(v!==ye.current){_.tunnelId&&e.connection.disconnectSshProfile?.(o,_.tunnelId).catch(()=>{});return}let Q;try{Q=new URL(_.config.url)}catch{Q=null}if(Q?.protocol!=="http:"||Q.hostname!=="127.0.0.1"||Q.username||Q.password||!Q.port||!_.tunnelId||_.config.token!==d||_.serverHomeId!==D.serverHomeId)throw _.tunnelId&&e.connection.disconnectSshProfile?.(o,_.tunnelId).catch(()=>{}),new Error("SSH tunnel endpoint or server home ID could not be verified.");Ee.current={id:o,tunnelId:_.tunnelId},K.current+=1,O(null),q(null),h({config:_.config,persist:!1,source:"ssh",scopeId:`ssh:${o}`,profile:D,tunnelId:_.tunnelId,serverHomeId:_.serverHomeId,serverInstanceId:_.serverInstanceId,serverVersion:_.serverVersion,buildId:_.buildId,buildChannel:_.buildChannel})},[e]),ut=u.useCallback(()=>{if(C.current?.source==="ssh"){Te();return}K.current+=1,Er(),O(null),h(null),q(null),kt()},[Te]),kn=u.useCallback(()=>{Bn(),F({kind:"none"}),m(void 0)},[]),dt=u.useCallback((o,d=!0)=>{const v=++K.current,x=C.current,D=x!==null&&x.config.url.trim().replace(/\/+$/,"")===o.url.trim().replace(/\/+$/,"")&&x.config.token.trim()===o.token.trim();q(null),O(null),h({config:o,persist:d,source:d?"manual":"local-detection",scopeId:D?x.scopeId:`direct:${o.url.trim().replace(/\/+$/,"")}:${v}`})},[]),Tt=u.useCallback(o=>{C.current?.source==="ssh"||C.current?.source==="remote"||dt(o,!0)},[dt]),Dt=u.useMemo(()=>b===null||A===null||Y===null||X===null||U===null?null:{connectionId:R,connectionSource:l?.source??null,spaceKey:g,scopeId:E,connectionRef:l?.source==="remote"?l.connectionId:l?.source==="ssh"?l.tunnelId:void 0,sshLabel:l?.profile?.label??null,activateSshProfile:lt,activateLocal:Te,restoreLocal:Lt,scopeAdapter:je,needsScopeReload:At,config:b,client:A,localClient:de,klient:Y,socket:X,meta:U,wsStatus:te,recovery:l?.source==="desktop"&&H.current?.client===A?{status:H.current.phase==="blocked"?"blocked":"retrying",failure:Re}:void 0,disconnect:ut,applyConnection:Tt},[R,N,g,E,l?.tunnelId,l?.profile?.label,lt,Te,Lt,je,At,b,A,de,Y,X,U,te,Re,ut,Tt]),De=W===null?null:W.kind==="key"?Kn(a,W.key,W.params):W.text,In=l?.source==="ssh"?De===null?null:{message:De,stderrTail:[],logPath:null}:Re??(n&&De!==null?{message:De,stderrTail:[],logPath:null}:null);return r.jsx(et.Provider,{value:Dt,children:Dt!==null?r.jsx(Vn,{client:I,children:r.jsx(Et.Provider,{value:We.current,children:t})}):r.jsx(vr,{initial:b??{url:"",token:""},connecting:Pe!==null||b!==null&&W===null,error:n?null:De,onConnect:dt,onBack:n?void 0:b!==null?ut:void 0,desktopBoot:Pe,desktopFailure:In,onRetryDesktop:st,onCancelDesktopBoot:bn,onConnectSsh:lt,onSwitchLocal:l?.source==="ssh"?Te:void 0,sshProfile:l?.source==="ssh"?l.profile:void 0,webLink:k,onRetryWebLink:kn})})}const Et=u.createContext(null);function Qr(){const t=u.useContext(Et);if(t===null)throw new Error("useControllerRegistry outside provider");return t}function qr(){return u.useContext(Et)}function $r({value:t,children:e}){return r.jsx(et.Provider,{value:t,children:e})}function Ur(){const t=u.useContext(et);if(t===null)throw new Error("useConnection used before connecting");return t}function Wr(){return u.useContext(et)}const bs=Object.freeze(Object.defineProperty({__proto__:null,ConnectionProvider:Or,ConnectionScope:$r,LiveControllerRegistry:mn,VIEW_CACHE_MAX_BYTES:Rt,VIEW_CACHE_MAX_ENTRY_BYTES:hn,VIEW_CACHE_MAX_LIVE_PARKED:pn,VIEW_CACHE_MAX_PARKED:dn,VIEW_CACHE_TTL_MS:fn,handleGlobalConnectionFrame:un,isDesktopSelection:me,isProtectedView:Ze,nextGuiLeaseClientId:xn,refreshSessionAttention:Ye,useConnection:Ur,useControllerRegistry:Qr,useOptionalConnection:Wr,useOptionalControllerRegistry:qr},Symbol.toStringTag,{value:"Module"}));export{Gt as A,rr as B,rs as C,ur as D,Yr as E,Gr as F,os as G,ns as H,Ct as I,is as J,vs as K,Xr as L,Jr as M,ts as N,ps as O,bs as P,jt as S,Ue as W,hs as a,ss as b,_e as c,cs as d,as as e,us as f,ir as g,fs as h,Yt as i,ls as j,Wr as k,Bt as l,es as m,ms as n,ys as o,gs as p,dr as q,jr as r,on as s,xs as t,Ur as u,qr as v,Qr as w,Zr as x,Xt as y,ds as z};
|