@openchambery/web 1.19.5-beta.11 → 1.19.5-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AssistantView-CJhgVhRf.js → AssistantView-B5gousNu.js} +1 -1
- package/dist/assets/{ChatContainer-D2B5tinV.js → ChatContainer-Ce3b2cNC.js} +39 -39
- package/dist/assets/{ContextPanel-BUfmDmiM.js → ContextPanel-CxgoBKyL.js} +7 -7
- package/dist/assets/{DiagramView-Fg17seCF.js → DiagramView-chb1AAev.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-BNNNyBx4.js → MarkdownRendererImpl-BCkCnvcU.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-qdgFPEWF.js → MobileDetailNavigation-D0QxNSBn.js} +1 -1
- package/dist/assets/{MobileShareBridge-BJ2pWe8B.js → MobileShareBridge-uQvUeFoD.js} +1 -1
- package/dist/assets/{MobileSurface-CPqT1wMU.js → MobileSurface-CAFfh00F.js} +1 -1
- package/dist/assets/{MultiRunWindow-BWrCnm6f.js → MultiRunWindow-CL9HUaQ6.js} +1 -1
- package/dist/assets/{SettingsView-CwOBrdDU.js → SettingsView-DI-xR28w.js} +1 -1
- package/dist/assets/{SettingsWindow-B5cijimD.js → SettingsWindow-C08nRzF9.js} +1 -1
- package/dist/assets/{TerminalView-DfvAscgy.js → TerminalView-BfaV2UtT.js} +1 -1
- package/dist/assets/{ToolOutputDialog-CyyC8L_p.js → ToolOutputDialog-BMSDSqF-.js} +1 -1
- package/dist/assets/{appThemeRegistry-BtwC37-e.js → appThemeRegistry-BQAoUoXG.js} +2 -2
- package/dist/assets/{gitApi-pDTwL1DO.js → gitApi-MThvLXsN.js} +1 -1
- package/dist/assets/insertionBoundaries-BD8gnU2G.js +4 -0
- package/dist/assets/{main-CvESN9iu.js → main-BqRvL_2H.js} +2 -2
- package/dist/assets/{main-bTR_9bps.js → main-HlON3iI7.js} +4 -4
- package/dist/assets/{miniChat-DUsG98HD.js → miniChat-THt7sAU8.js} +2 -2
- package/dist/assets/{mobile-CghL7wNK.js → mobile-B8X5spVS.js} +2 -2
- package/dist/assets/{multirun-BlPR4URy.js → multirun-DCvdvIa_.js} +1 -1
- package/dist/assets/{projectMeta-B4xE5Xxg.js → projectMeta-rDf2igM9.js} +1 -1
- package/dist/assets/{radio-CUgRCrMQ.js → radio-Bn5ronTr.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-C9rJsVd5.js → renderElectronMiniChatApp-CRiqMh8B.js} +2 -2
- package/dist/assets/renderMobileApp-Dt2MLCGK.js +25 -0
- package/dist/assets/{runtimeConfig-Byn_gAWc.js → runtimeConfig-CiXSoZmf.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-CbrVMVzQ.js → runtimeEndpointReset-Dy_-6DS5.js} +1 -1
- package/dist/assets/{shikiHighlight-mVzsjFp8.js → shikiHighlight-BMya_gQv.js} +1 -1
- package/dist/assets/src-CJXwqXhB.css +2 -0
- package/dist/assets/{useAppFontEffects-CM3QTgE_.js → useAppFontEffects-ccN1Nplv.js} +2 -2
- package/dist/assets/{useDesktopWindowControlsLayout-BDLBsnSY.js → useDesktopWindowControlsLayout-5VYu0grF.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-P4i5GtC0.js → useEffectiveDirectory-CRHavvW8.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-u51zoFzN.js → useMobileNavigationStore-gXgGtIqj.js} +1 -1
- package/dist/assets/{useSessionAutoCleanup-DxEX_HCr.js → useSessionAutoCleanup-BxkIFBdx.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-DsjpSlQ0.js → useWorkerHighlightedLines-B_hH_qlZ.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/dist/assets/insertionBoundaries-DGIjWHa5.js +0 -4
- package/dist/assets/renderMobileApp-MRGBPcsf.js +0 -25
- package/dist/assets/src-BsoTg-Cl.css +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{j as t,t as n}from"./useUIStore-BXjMQrel.js";import{Kt as r,kn as i,qt as a,u as o}from"./persistence-CLUawIlm.js";import{h as s}from"./desktopHosts-DceeVBky.js";import{i as c,n as l,r as u}from"./desktopRelayRestore-B0MRdR5y.js";import{nt as d,rt as f}from"./vendor-base-ui-CnHfUmDN.js";import{Nt as p}from"./platform-BrncW9ab.js";import{n as m}from"./vendor-react-DLPElpoQ.js";import{n as h}from"./vendor-tanstack-query-core-BWz0ose6.js";import{i as g,r as _}from"./vendor-tanstack-react-query-D7pys_c9.js";import{n as v}from"./clipboard-C0bgPFn5.js";import{i as y,t as b}from"./store-DzpbXWX1.js";import{fr as x,hr as ee,l as S,lr as te,ra as C,rr as w}from"./useMobileNavigationStore-u51zoFzN.js";import{t as ne}from"./utils-D94hxQYq.js";import{i as re,n as ie,r as ae,t as oe}from"./vendor-simplewebauthn-browser-Dwhcdg_5.js";import{n as se,r as ce}from"./radio-CUgRCrMQ.js";var T=m(),E=[`desktopHostSwitch`],D=class extends Error{result;host;constructor(e,t){super(e.reason),this.name=`DesktopHostSwitchError`,this.result=e,this.host=t}},le=(e,t)=>b(y.getState().dictionary,e,t),ue=async e=>{let{host:n}=e;if(n.id===`local`){let r=(e.localApiOrigin||``).trim();if(!r)throw new D({ok:!1,status:{status:`unreachable`,latencyMs:0},reason:`unreachable`},n);return t({apiBaseUrl:r,clientToken:e.localClientToken||null,runtimeKey:u(n)}),{ok:!0,via:`direct`,status:{status:`ok`,latencyMs:0}}}let r=await c(n,{cachedProbe:e.cachedProbe});if(!r.ok)throw new D(r,n);return r},O=null,de=()=>O||(O=new h(o,{mutationKey:E,mutationFn:ue,onError:(e,t)=>{e instanceof D&&e.result.reason!==`unsupported`&&ee.error(le(`desktopHostSwitcher.toast.instanceUnreachable`,{host:s(t.host.label)}))}}),O.subscribe(()=>void 0),O),fe=async e=>{if(l(e.host))return{ok:!0,via:`direct`,status:e.cachedProbe?.status===`ok`?e.cachedProbe:{status:`ok`,latencyMs:0}};if(o.isMutating({mutationKey:E})>0)return{ok:!1,status:{status:`unreachable`,latencyMs:0},reason:`unsupported`};try{return await de().mutate(e)}catch(e){if(e instanceof D)return e.result;throw e}},pe=()=>{let e=(0,T.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={mutationKey:E},e[0]=t):t=e[0],_(t)>0},me=()=>{let e=(0,T.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={filters:{mutationKey:E,status:`pending`},select:he},e[0]=t):t=e[0],g(t)[0]?.host.id??null};function he(e){return e.state.variables}var k=e=>typeof e==`object`&&!!e,A=(e,t)=>{let n=e[t];return typeof n==`string`?n:null},j=(e,t)=>{let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null},M=(e,t)=>{let n=e[t];return typeof n==`boolean`?n:null},N=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[],P=()=>r()?(e,t)=>a(e,t):null,F=e=>{if(!k(e))return;let t=M(e,`enabled`)??!1,n=A(e,`store`)?.toLowerCase()===`settings`?`settings`:`never`,r=A(e,`value`);return{enabled:t,store:n,...r?{value:r}:{}}},ge=e=>e===`remote`||e===`dynamic`?e:`local`,_e=e=>{if(!k(e))return null;let t=A(e,`id`);if(!t)return null;let n=M(e,`enabled`)??!0,r=ge(A(e,`type`)),i=A(e,`localHost`)||A(e,`local_host`)||void 0,a=j(e,`localPort`)??j(e,`local_port`)??void 0,o=A(e,`remoteHost`)||A(e,`remote_host`)||void 0,s=j(e,`remotePort`)??j(e,`remote_port`)??void 0;return{id:t,enabled:n,type:r,...i?{localHost:i}:{},...typeof a==`number`?{localPort:a}:{},...o?{remoteHost:o}:{},...typeof s==`number`?{remotePort:s}:{}}},ve=e=>{if(!k(e))return null;let t=A(e,`id`),n=A(e,`sshCommand`)||A(e,`ssh_command`);if(!t||!n)return null;let r=A(e,`nickname`),i=e.sshParsed,a=k(i)?{destination:A(i,`destination`)||``,args:N(i.args)}:void 0,o=k(e.remoteOpenchamber)?e.remoteOpenchamber:k(e.remote_openchamber)?e.remote_openchamber:{},s=k(e.localForward)?e.localForward:k(e.local_forward)?e.local_forward:{},c=k(e.auth)?e.auth:{},l=A(o,`mode`)?.toLowerCase()===`external`?`external`:`managed`,u=A(o,`installMethod`)||A(o,`install_method`),d=u===`npm`||u===`download_release`||u===`upload_bundle`?u:`bun`,f=A(s,`bindHost`)||A(s,`bind_host`)||`127.0.0.1`,p=f===`localhost`||f===`0.0.0.0`?f:`127.0.0.1`,m=(Array.isArray(e.portForwards)?e.portForwards:Array.isArray(e.port_forwards)?e.port_forwards:[]).map(e=>_e(e)).filter(e=>!!e),h=j(o,`preferredPort`)??j(o,`preferred_port`),g=j(s,`preferredLocalPort`)??j(s,`preferred_local_port`),_=F(c.sshPassword||c.ssh_password),v=F(c.openchamberPassword||c.openchamber_password);return{id:t,...r?{nickname:r}:{},sshCommand:n,...a&&a.destination?{sshParsed:a}:{},connectionTimeoutSec:j(e,`connectionTimeoutSec`)??j(e,`connection_timeout_sec`)??60,remoteOpenchamber:{mode:l,keepRunning:M(o,`keepRunning`)??M(o,`keep_running`)??!0,relayHost:M(o,`relayHost`)??M(o,`relay_host`)??!0,...h?{preferredPort:h}:{},installMethod:d,uploadBundleOverSsh:M(o,`uploadBundleOverSsh`)??M(o,`upload_bundle_over_ssh`)??!1},localForward:{...g?{preferredLocalPort:g}:{},bindHost:p},auth:{..._?{sshPassword:_}:{},...v?{openchamberPassword:v}:{}},portForwards:m}},ye=e=>{switch(e){case`config_resolved`:case`auth_check`:case`master_connecting`:case`remote_probe`:case`installing`:case`updating`:case`server_detecting`:case`server_starting`:case`forwarding`:case`ready`:case`degraded`:case`error`:return e;default:return`idle`}},I=e=>{if(!k(e))return null;let t=A(e,`id`);return t?{id:t,phase:ye(A(e,`phase`)),...A(e,`detail`)?{detail:A(e,`detail`)||void 0}:{},...A(e,`localUrl`)||A(e,`local_url`)?{localUrl:A(e,`localUrl`)||A(e,`local_url`)||void 0}:{},...typeof(j(e,`localPort`)??j(e,`local_port`))==`number`?{localPort:j(e,`localPort`)??j(e,`local_port`)??void 0}:{},...typeof(j(e,`remotePort`)??j(e,`remote_port`))==`number`?{remotePort:j(e,`remotePort`)??j(e,`remote_port`)??void 0}:{},startedByUs:M(e,`startedByUs`)??M(e,`started_by_us`)??!1,retryAttempt:j(e,`retryAttempt`)??j(e,`retry_attempt`)??0,requiresUserAction:M(e,`requiresUserAction`)??M(e,`requires_user_action`)??!1,...A(e,`errorCode`)||A(e,`error_code`)?{errorCode:A(e,`errorCode`)||A(e,`error_code`)||void 0}:{},updatedAtMs:j(e,`updatedAtMs`)??j(e,`updated_at_ms`)??Date.now()}:null},be=e=>{if(!k(e))return null;let t=A(e,`host`),n=A(e,`source`),r=A(e,`sshCommand`)||A(e,`ssh_command`);return!t||!n||!r?null:{host:t,source:n,sshCommand:r,pattern:M(e,`pattern`)??!1}},xe=(e,t)=>({id:e,sshCommand:t,connectionTimeoutSec:60,remoteOpenchamber:{mode:`managed`,keepRunning:!0,relayHost:!0,installMethod:`bun`,uploadBundleOverSsh:!1},localForward:{bindHost:`127.0.0.1`},auth:{},portForwards:[]}),Se=async()=>{let e=P();if(!e)return{instances:[]};let t=await e(`desktop_ssh_instances_get`);return k(t)?{instances:(Array.isArray(t.instances)?t.instances:Array.isArray(t.desktopSshInstances)?t.desktopSshInstances:[]).map(e=>ve(e)).filter(e=>!!e)}:{instances:[]}},Ce=async e=>{let t=P();t&&await t(`desktop_ssh_instances_set`,{config:{instances:e.instances}})},we=async()=>{let e=P();if(!e)return[];let t=await e(`desktop_ssh_import_hosts`);return Array.isArray(t)?t.map(e=>be(e)).filter(e=>!!e):[]},Te=async e=>{let t=P();t&&await t(`desktop_ssh_connect`,{id:e})},Ee=async e=>{let t=P();t&&await t(`desktop_ssh_disconnect`,{id:e})},De=async e=>{let t=P();if(!t)return[];let n=await t(`desktop_ssh_status`,{...e?{id:e}:{}});return Array.isArray(n)?n.map(e=>I(e)).filter(e=>!!e):[]},Oe=async(e,t)=>{let n=P();if(!n)return[];let r=await n(`desktop_ssh_logs`,{id:e,...typeof t==`number`?{limit:t}:{}});return Array.isArray(r)?r.filter(e=>typeof e==`string`):[]},ke=async e=>{let t=P();t&&await t(`desktop_ssh_logs_clear`,{id:e})},Ae=(e,t)=>{let n=Math.max(0,Math.trunc(Number(e.fileGroups)||0)),r=Math.max(0,Math.trunc(Number(e.singleFiles)||0)),i=Math.max(0,Math.trunc(Number(e.directories)||0));return{fileGroups:Array.from({length:n},()=>!0),singleFiles:Array.from({length:r},()=>!0),directories:Array.from({length:i},()=>!0),agentsRoot:!0,authFile:t?.includeAuthFile===!0}},je=e=>{if(!k(e))return null;let t=A(e,`path`),n=j(e,`bytes`);return!t||n===null?null:{path:t,bytes:n}},Me=e=>{if(!k(e))return null;let t=A(e,`path`),n=j(e,`fileCount`)??j(e,`file_count`),r=j(e,`bytes`);return!t||n===null||r===null?null:{path:t,fileCount:n,bytes:r}},Ne=e=>{if(e==null||!k(e))return null;let t=j(e,`fileCount`)??j(e,`file_count`),n=j(e,`bytes`);return t===null||n===null?null:{fileCount:t,bytes:n}},L=e=>{if(e==null||!k(e))return null;let t=j(e,`bytes`);return t===null?null:{bytes:t}},R=e=>{if(!k(e))return null;let t=Array.isArray(e.files)?e.files:null,n=Array.isArray(e.directories)?e.directories:null,r=N(e.deletes),i=j(e,`totalBytes`)??j(e,`total_bytes`);if(!t||!n||i===null||!(`agentsRoot`in e)&&!(`agents_root`in e))return null;let a=t.map(e=>je(e)).filter(e=>!!e),o=n.map(e=>Me(e)).filter(e=>!!e);if(a.length!==t.length||o.length!==n.length)return null;let s=e.agentsRoot??e.agents_root,c=s==null?null:Ne(s);if(s!=null&&c===null)return null;let l=e.authFile??e.auth_file,u=l==null?null:L(l),d=e.direction===`pull`||e.direction===`push`?e.direction:void 0,f=e.selections,p=k(f)?{fileGroups:Array.isArray(f.fileGroups)?f.fileGroups.map(e=>e!==!1):[],singleFiles:Array.isArray(f.singleFiles)?f.singleFiles.map(e=>e!==!1):[],directories:Array.isArray(f.directories)?f.directories.map(e=>e!==!1):[],agentsRoot:f.agentsRoot!==!1,authFile:f.authFile===!0}:void 0,m=z(e.selectionShape??e.selection_shape);return{files:a,directories:o,agentsRoot:c,authFile:u,deletes:r,totalBytes:i,...d?{direction:d}:{},...p?{selections:p}:{},...m?{selectionShape:m}:{}}},z=e=>{if(!k(e))return null;let t=j(e,`fileGroups`)??j(e,`file_groups`),n=j(e,`singleFiles`)??j(e,`single_files`),r=j(e,`directories`);return t===null||n===null||r===null||t<0||n<0||r<0?null:{fileGroups:t,singleFiles:n,directories:r}},Pe=e=>{if(!k(e))return null;let t=R(e.plan);if(!t)return null;let n=z(e.selectionShape??e.selection_shape)??t.selectionShape??null;return{plan:t,remoteExisting:N(e.remoteExisting??e.remote_existing),remoteAgentsRootExists:M(e,`remoteAgentsRootExists`)??M(e,`remote_agents_root_exists`)??!1,remoteAuthFileExists:M(e,`remoteAuthFileExists`)??M(e,`remote_auth_file_exists`)??!1,...n?{selectionShape:n}:{}}},Fe=e=>{if(!k(e)||M(e,`ok`)!==!0)return null;let t=j(e,`files`),n=j(e,`directories`),r=j(e,`deletes`),i=j(e,`totalBytes`)??j(e,`total_bytes`);if(t===null||n===null||r===null||i===null||!(`agentsRoot`in e)&&!(`agents_root`in e))return null;let a=e.agentsRoot??e.agents_root,o=null;if(a!=null){if(!k(a))return null;let e=j(a,`fileCount`)??j(a,`file_count`);if(e===null)return null;o={fileCount:e}}let s=e.authFile??e.auth_file,c=s==null?null:L(s);return{ok:!0,files:t,directories:n,deletes:r,totalBytes:i,agentsRoot:o,authFile:c}},Ie=async(e={})=>{let t=P();if(!t)return console.error(`[desktopSsh] config sync local scan skipped: desktop IPC bridge is unavailable in this window`),null;let n=await t(`desktop_ssh_sync_opencode_config`,{stage:`local`,...e.direction?{direction:e.direction}:{},...e.selections?{selections:e.selections}:{}});if(!k(n))return console.error(`[desktopSsh] config sync local scan returned a non-object payload`,n),null;let r=R(n.plan);if(!r)return console.error(`[desktopSsh] config sync local scan plan payload was not recognized`,n),null;let i=z(n.selectionShape??n.selection_shape)??r.selectionShape??null;return i?{...r,selectionShape:i}:r},Le=async(e,t={})=>{let n=P();if(!n)return console.error(`[desktopSsh] config sync preview skipped: desktop IPC bridge is unavailable in this window`),null;let r=await n(`desktop_ssh_sync_opencode_config`,{id:e,...t.targetKind?{targetKind:t.targetKind}:{},...t.direction?{direction:t.direction}:{},...t.selections?{selections:t.selections}:{}}),i=Pe(r);return i||console.error(`[desktopSsh] config sync preview payload was not recognized`,r),i},Re=async(e,t={})=>{let n=P();if(!n)return console.error(`[desktopSsh] config sync apply skipped: desktop IPC bridge is unavailable in this window`),null;let r=await n(`desktop_ssh_sync_opencode_config`,{id:e,apply:!0,...t.targetKind?{targetKind:t.targetKind}:{},...t.direction?{direction:t.direction}:{},...t.selections?{selections:t.selections}:{}}),i=Fe(r);return i||console.error(`[desktopSsh] config sync apply payload was not recognized`,r),i},ze=async(e,t={})=>{let n=P();if(!n)return[];let r=await n(`desktop_ssh_sync_runs_list`,{id:e,...t.targetKind?{targetKind:t.targetKind}:{}});return Array.isArray(r)?r.filter(e=>k(e)&&typeof e.syncRunId==`string`&&typeof e.targetId==`string`):[]},Be=async e=>{if(!r())return async()=>{};let t=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof t!=`function`)return async()=>{};let n=await t(`openchamber:ssh-instance-status`,t=>{let n=I(t?.payload);n&&e(n)});return async()=>{await n()}},Ve=new Set([`nodeRuntimeMissing`,`packageManagerMissing`,`nativeBinding`,`openchamberCliMissing`,`openchamberRegistry`,`openchamberInstall`,`openchamberCliIncompatible`,`opencodeInstall`,`serverStart`,`sshAuth`,`sshUnreachable`,`timeout`,`unknown`]),He=e=>typeof e==`string`&&Ve.has(e),Ue=e=>{let t=String(e||``);return/requires Node\.js \d+|no supported Node runtime/i.test(t)?`nodeRuntimeMissing`:/neither bun nor npm/i.test(t)?`packageManagerMissing`:/better-sqlite3|node_gyp_bins|gyp ERR|failed to prepare better-sqlite3/i.test(t)?`nativeBinding`:/OpenChamber installation completed but the executable is unavailable/i.test(t)?`openchamberCliMissing`:/could not reach the npm registry|ENOTFOUND|ECONNREFUSED|ETIMEDOUT|EAI_AGAIN|CERT_HAS_EXPIRED|UNABLE_TO_GET_ISSUER_CERT|self-signed certificate|registry\.npmjs|npm error code E404|npm ERR! code E404|getaddrinfo/i.test(t)?`openchamberRegistry`:/Failed to install OpenChamber/i.test(t)?`openchamberInstall`:/Unknown option:\s*--relay-host|does not advertise --relay-host|does not support --relay-host/i.test(t)||/Unknown option:/i.test(t)?`openchamberCliIncompatible`:/Failed to install OpenCode|OpenCode CLI/i.test(t)?`opencodeInstall`:/failed to become reachable|Managed OpenChamber server failed/i.test(t)?`serverStart`:/Permission denied|Authentication failed|publickey|keyboard-interactive/i.test(t)?`sshAuth`:/Could not resolve hostname|Connection refused|Connection timed out|ControlMaster connection timed out|SSH master process exited|Network is unreachable/i.test(t)?`sshUnreachable`:/Timed out waiting for SSH|Timed out waiting for forwarded/i.test(t)?`timeout`:`unknown`},B=(e,t)=>He(e)?e:Ue(t),V=e=>{switch(e){case`nodeRuntimeMissing`:return`desktopHostSwitcher.sshError.nodeRuntimeMissing.title`;case`packageManagerMissing`:return`desktopHostSwitcher.sshError.packageManagerMissing.title`;case`nativeBinding`:return`desktopHostSwitcher.sshError.nativeBinding.title`;case`openchamberCliMissing`:return`desktopHostSwitcher.sshError.openchamberCliMissing.title`;case`openchamberRegistry`:return`desktopHostSwitcher.sshError.openchamberRegistry.title`;case`openchamberInstall`:return`desktopHostSwitcher.sshError.openchamberInstall.title`;case`openchamberCliIncompatible`:return`desktopHostSwitcher.sshError.openchamberCliIncompatible.title`;case`opencodeInstall`:return`desktopHostSwitcher.sshError.opencodeInstall.title`;case`serverStart`:return`desktopHostSwitcher.sshError.serverStart.title`;case`sshAuth`:return`desktopHostSwitcher.sshError.sshAuth.title`;case`sshUnreachable`:return`desktopHostSwitcher.sshError.sshUnreachable.title`;case`timeout`:return`desktopHostSwitcher.sshError.timeout.title`;default:return`desktopHostSwitcher.sshError.unknown.title`}},H=e=>{switch(e){case`nodeRuntimeMissing`:return`desktopHostSwitcher.sshError.nodeRuntimeMissing.guidance`;case`packageManagerMissing`:return`desktopHostSwitcher.sshError.packageManagerMissing.guidance`;case`nativeBinding`:return`desktopHostSwitcher.sshError.nativeBinding.guidance`;case`openchamberCliMissing`:return`desktopHostSwitcher.sshError.openchamberCliMissing.guidance`;case`openchamberRegistry`:return`desktopHostSwitcher.sshError.openchamberRegistry.guidance`;case`openchamberInstall`:return`desktopHostSwitcher.sshError.openchamberInstall.guidance`;case`openchamberCliIncompatible`:return`desktopHostSwitcher.sshError.openchamberCliIncompatible.guidance`;case`opencodeInstall`:return`desktopHostSwitcher.sshError.opencodeInstall.guidance`;case`serverStart`:return`desktopHostSwitcher.sshError.serverStart.guidance`;case`sshAuth`:return`desktopHostSwitcher.sshError.sshAuth.guidance`;case`sshUnreachable`:return`desktopHostSwitcher.sshError.sshUnreachable.guidance`;case`timeout`:return`desktopHostSwitcher.sshError.timeout.guidance`;default:return`desktopHostSwitcher.sshError.unknown.guidance`}},U=e=>e===`unknown`||e===`openchamberCliIncompatible`,We=(e,t,n)=>{let r=typeof n==`string`?n.trim():``;return!U(t)||!r||r===e?e:`${e}\n${r}`},W=d();function Ge(e){let t=(0,T.c)(27),{errorCode:n,detail:r,className:i}=e,{t:a}=v(),o,s,c,l,u,d;if(t[0]!==i||t[1]!==r||t[2]!==n||t[3]!==a){let e=B(n,r);o=a(H(e));let f;t[10]===r?f=t[11]:(f=typeof r==`string`?r.trim():``,t[10]=r,t[11]=f),s=f,c=U(e)&&!!s&&s!==o,t[12]===i?d=t[13]:(d=ne(`space-y-1`,i),t[12]=i,t[13]=d),l=`typography-ui-label text-[var(--status-error)]`,u=a(V(e)),t[0]=i,t[1]=r,t[2]=n,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d}else o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9];let f;t[14]!==l||t[15]!==u?(f=(0,W.jsx)(`p`,{className:l,children:u}),t[14]=l,t[15]=u,t[16]=f):f=t[16];let p;t[17]===o?p=t[18]:(p=(0,W.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:o}),t[17]=o,t[18]=p);let m;t[19]!==s||t[20]!==c?(m=c?(0,W.jsx)(`p`,{className:`typography-meta break-words text-muted-foreground`,children:s}):null,t[19]=s,t[20]=c,t[21]=m):m=t[21];let h;return t[22]!==d||t[23]!==f||t[24]!==p||t[25]!==m?(h=(0,W.jsxs)(`div`,{className:d,children:[f,p,m]}),t[22]=d,t[23]=f,t[24]=p,t[25]=m,t[26]=h):h=t[26],h}var Ke=`/auth/passkey/authenticate/options`,qe=`/auth/passkey/authenticate/verify`,Je=`/auth/passkey/register/options`,Ye=`/auth/passkey/register/verify`,G=`/api/passkeys`,Xe=`/auth/passkey/status`,Ze=`/api/auth/reset`,K={enabled:!1,hasPasskeys:!1,passkeyCount:0,rpID:null},q=async(e,t)=>i(e,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:t===void 0?void 0:JSON.stringify(t)}),J=async(e,t)=>{try{let t=await e.json();if(t&&typeof t.error==`string`&&t.error.trim())return t.error}catch{}return t},Qe=e=>e instanceof re&&e.code===`ERROR_CEREMONY_ABORTED`,$e=()=>{ae.cancelCeremony()},Y=()=>typeof window>`u`?{supported:!1,reason:`Passkeys are unavailable outside the browser.`}:window.isSecureContext?{supported:!0,reason:``}:{supported:!1,reason:`Passkeys require HTTPS or localhost.`},et=async()=>{let e=Y();if(!e.supported)throw Error(e.reason);let t=await q(Je,{label:typeof navigator.userAgent==`string`&&navigator.userAgent.trim()?navigator.userAgent:`This device`});if(!t.ok)throw Error(await J(t,`Could not start passkey setup.`));let{requestId:n,optionsJSON:r}=await t.json(),i=await q(Ye,{requestId:n,response:await ie({optionsJSON:r})});if(!i.ok)throw Error(await J(i,`Could not finish passkey setup.`));return i.json().catch(()=>null)},tt=async(e,t={})=>{let n=Y();if(!n.supported)throw Error(n.reason);let r=await q(Ke);if(!r.ok)throw Error(await J(r,`Passkey sign-in is not available right now.`));let{requestId:i,optionsJSON:a}=await r.json(),o=await q(qe,{requestId:i,response:await oe({optionsJSON:a}),trustDevice:e,issueClientToken:t.issueClientToken===!0,clientLabel:t.clientLabel,clientKind:t.clientKind,dedupeKey:t.dedupeKey});if(!o.ok)throw Error(await J(o,`Passkey sign-in failed.`));return o.json().catch(()=>null)},nt=async()=>{let e=await i(Xe,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return K;let t=await e.json().catch(()=>null);return{enabled:t?.enabled===!0,hasPasskeys:t?.hasPasskeys===!0,passkeyCount:typeof t?.passkeyCount==`number`?t.passkeyCount:0,rpID:typeof t?.rpID==`string`&&t.rpID?t.rpID:null}},rt=async()=>{let e=await i(G,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)throw Error(await J(e,`Could not load passkeys.`));let t=await e.json().catch(()=>null);return Array.isArray(t?.passkeys)?t.passkeys:[]},it=async e=>{let t=await i(`${G}/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`,headers:{Accept:`application/json`}});if(!t.ok)throw Error(await J(t,`Could not remove passkey.`));return t.json().catch(()=>null)},at=async()=>{let e=await q(Ze);if(!e.ok)throw Error(await J(e,`Could not clear saved authentication.`));return e.json().catch(()=>null)},X=e=>b(y.getState().dictionary,e),ot=e=>typeof e!=`number`||!Number.isFinite(e)?null:Math.max(0,Math.min(100,Math.round(e))),st=e=>typeof e!=`number`||!Number.isFinite(e)?`-`:`${Math.round(e)}%`,ct=(e,t)=>e??st(t),lt=(e,t,n=`auto`)=>{if(!e)return t??``;try{let r=new Date(e);if(!Number.isFinite(r.getTime()))return t??``;let i=new Date;return r.toDateString()===i.toDateString()?ce(r,n,{fallback:t??``}):se(r,n,{month:`short`,day:`numeric`,weekday:`short`,hour:`numeric`,minute:`2-digit`})}catch{return t??``}},ut=e=>e===null?`safe`:e>=80?`critical`:e>=50?`warn`:`safe`,dt=e=>e===`5h`?X(`quota.window.5h`):e===`7d`?X(`quota.window.7d`):e===`7d-sonnet`?X(`quota.window.7dSonnet`):e===`7d-opus`?X(`quota.window.7dOpus`):e===`weekly`?X(`quota.window.weekly`):e===`daily`?X(`quota.window.daily`):e===`monthly`?X(`quota.window.monthly`):e===`credits`?X(`quota.window.credits`):e===`credits_balance`?X(`quota.window.creditsBalance`):e===`billing_cycle`?X(`quota.window.billingCycle`):e===`auto`?X(`quota.window.auto`):e===`api`?X(`quota.window.api`):e===`plan_limit`?X(`quota.window.planLimit`):e===`on_demand`?X(`quota.window.onDemand`):e===`session`?X(`quota.window.session`):e===`premium`?X(`quota.window.premium`):e===`chat`?X(`quota.window.chat`):e===`completions`?X(`quota.window.completions`):e===`premium_interactions`?X(`quota.window.premiumInteractions`):e,ft=e=>{let t=e.toLowerCase().trim();if(t===`5h`)return 18e3;if(t===`7d`||t===`weekly`||t===`7d-sonnet`||t===`7d-opus`)return 604800;if(t===`monthly`)return 2592e3;if(t===`24h`||t===`daily`)return 86400;if(t===`1h`)return 3600;let n=t.match(/^(\d+)h$/);if(n)return parseInt(n[1],10)*3600;let r=t.match(/^(\d+)d$/);return r?parseInt(r[1],10)*86400:null},pt=(e,t,n,r)=>{let i=n;if(i===null&&r&&(i=ft(r)),e===null||t===null||i===null||i<=0)return null;let a=Math.max(0,(t-Date.now())/1e3),o=Math.max(0,Math.min(i,i-a)),s=Math.max(0,Math.min(1,o/i)),c=e/100,l=e>=100&&a>0,u;u=s>.01?Math.min(999,c/s*100):e;let d;d=l?`exhausted`:c<=s?`on-track`:u<=130?`slightly-fast`:`too-fast`;let f=i>=432e3,p=f?86400:3600,m=f?`d`:`h`,h=i/p,g=e/Math.max(o/p,h*.01),_=Number.isFinite(g)?`${Math.min(999.9,Math.max(0,g)).toFixed(1)}%/${m}`:`-`,v=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`,y=null,b=i/86400;return b>=7&&(y=100/b),{elapsedRatio:s,usageRatio:c,predictedFinalPercent:u,remainingSeconds:a,isExhausted:l,elapsedSeconds:o,totalSeconds:i,status:d,paceRateText:_,predictText:v,dailyAllocationPercent:y}},mt=e=>{switch(e){case`exhausted`:case`too-fast`:return`var(--status-error)`;case`slightly-fast`:return`var(--status-warning)`;case`on-track`:return`var(--status-success)`}},ht=e=>{let t=Math.floor(Math.max(0,Math.floor(e))/60),n=Math.floor(t/60),r=Math.floor(n/24),i=n%24,a=t%60;return r>0?`${r}d ${i}h`:n>0?`${n}h`:t===0?`<1m`:`${a}m`},gt=e=>Math.min(100,Math.max(0,e*100)),_t=[`standalone`,`minimal-ui`,`fullscreen`,`window-controls-overlay`],vt=`openchamber.pwaRecentSessions`,yt=e=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(display-mode: ${e})`).matches,bt=()=>typeof window>`u`?`browser`:typeof document<`u`&&document.referrer.startsWith(`android-app://`)?`twa`:window.navigator.standalone?`standalone`:_t.find(e=>yt(e))??`browser`,Z=e(f(),1),xt=864e5,Q=5,St=864e5,$=e=>e.time?.updated??e.time?.created??0,Ct=({sessions:e,currentSessionId:t,cutoffDays:n,keepRecent:r=Q,now:i=Date.now()})=>{if(!Array.isArray(e)||n<=0)return[];let a=i-n*xt,o=[...e].sort((e,t)=>$(t)-$(e)),s=new Set(o.slice(0,r).map(e=>e.id));return o.filter(e=>{if(!e?.id||s.has(e.id)||e.id===t||e.share)return!1;let n=$(e);return n?n<a:!1}).map(e=>e.id)},wt=e=>{let t=typeof e==`object`?e:void 0,r=t?.autoRun!==!1,i=typeof e==`boolean`?e:t?.enabled??!0,a=S(e=>e.currentSessionId),o=S(e=>e.isLoading),s=x(e=>e.activeSessions),c=x(e=>e.hasLoadedFullCatalog),l=n(e=>e.autoDeleteEnabled),u=n(e=>e.autoDeleteAfterDays),d=n(e=>e.sessionRetentionAction),f=n(e=>e.autoDeleteLastRunAt),m=n(e=>e.setAutoDeleteLastRunAt),[h,g]=Z.useState(!1),_=Z.useRef(!1);Z.useEffect(()=>{if(!i||!r||!l||u<=0)return;let e=window.setTimeout(()=>{w(C())},8e3);return()=>window.clearTimeout(e)},[u,l,r,i]);let v=Z.useMemo(()=>u<=0?[]:Ct({sessions:s,currentSessionId:a,cutoffDays:u}),[u,a,s]),y=Z.useCallback(async({force:e=!1}={})=>{if(_.current)return{completedIds:[],failedIds:[],action:d,skippedReason:`running`};if((!l||u<=0)&&!e)return{completedIds:[],failedIds:[],action:d,skippedReason:`disabled`};if(o)return{completedIds:[],failedIds:[],action:d,skippedReason:`loading`};let t=Date.now();if(!e&&f&&t-f<St)return{completedIds:[],failedIds:[],action:d,skippedReason:`cooldown`};let{activeSessions:n}=await w(C());if(n.length===0)return{completedIds:[],failedIds:[],action:d,skippedReason:`no-candidates`};let r=Ct({sessions:n,currentSessionId:a,cutoffDays:u,now:t});if(r.length===0)return m(t),{completedIds:[],failedIds:[],action:d,skippedReason:`no-candidates`};_.current=!0,g(!0);try{let e=new Map(n.map(e=>[e.id,e])),t=[],i=[];for(let n of r){let r=e.get(n),a=r?te(r):null;if(!a){i.push(n);continue}try{d===`archive`?await p.updateSession(n,{time:{archived:Date.now()}},a):await p.deleteSession(n,a),t.push(n)}catch{i.push(n)}}return d===`archive`?x.getState().archiveSessions(t):x.getState().removeSessions(t),{completedIds:t,failedIds:i,action:d}}finally{_.current=!1,g(!1),m(Date.now())}},[u,l,f,a,o,d,m]);return Z.useEffect(()=>{i&&r&&(!l||u<=0||o||!c||s.length===0||f&&Date.now()-f<St||y())},[u,l,f,r,i,c,s.length,o,y]),{candidates:v,isRunning:h,runCleanup:y,keepRecentCount:Q,action:d}};export{Te as A,Le as B,Ge as C,V as D,H as E,Oe as F,me as G,Be as H,ke as I,De as L,we as M,Se as N,Ae as O,Ce as P,Re as R,it as S,B as T,fe as U,ze as V,pe as W,rt as _,pt as a,et as b,ct as c,mt as d,ut as f,nt as g,K as h,gt as i,Ee as j,xe as k,ht as l,$e as m,vt as n,ot as o,tt as p,bt as r,lt as s,wt as t,dt as u,Y as v,We as w,at as x,Qe as y,Ie as z};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{j as t,t as n}from"./useUIStore-BXjMQrel.js";import{Kt as r,kn as i,qt as a,u as o}from"./persistence-CLUawIlm.js";import{h as s}from"./desktopHosts-DceeVBky.js";import{i as c,n as l,r as u}from"./desktopRelayRestore-B0MRdR5y.js";import{nt as d,rt as f}from"./vendor-base-ui-CnHfUmDN.js";import{Nt as p}from"./platform-BrncW9ab.js";import{n as m}from"./vendor-react-DLPElpoQ.js";import{n as h}from"./vendor-tanstack-query-core-BWz0ose6.js";import{i as g,r as _}from"./vendor-tanstack-react-query-D7pys_c9.js";import{n as v}from"./clipboard-C0bgPFn5.js";import{i as y,t as b}from"./store-DzpbXWX1.js";import{fr as x,hr as ee,l as S,lr as te,ra as C,rr as w}from"./useMobileNavigationStore-gXgGtIqj.js";import{t as ne}from"./utils-D94hxQYq.js";import{i as re,n as ie,r as ae,t as oe}from"./vendor-simplewebauthn-browser-Dwhcdg_5.js";import{n as se,r as ce}from"./radio-Bn5ronTr.js";var T=m(),E=[`desktopHostSwitch`],D=class extends Error{result;host;constructor(e,t){super(e.reason),this.name=`DesktopHostSwitchError`,this.result=e,this.host=t}},le=(e,t)=>b(y.getState().dictionary,e,t),ue=async e=>{let{host:n}=e;if(n.id===`local`){let r=(e.localApiOrigin||``).trim();if(!r)throw new D({ok:!1,status:{status:`unreachable`,latencyMs:0},reason:`unreachable`},n);return t({apiBaseUrl:r,clientToken:e.localClientToken||null,runtimeKey:u(n)}),{ok:!0,via:`direct`,status:{status:`ok`,latencyMs:0}}}let r=await c(n,{cachedProbe:e.cachedProbe});if(!r.ok)throw new D(r,n);return r},O=null,de=()=>O||(O=new h(o,{mutationKey:E,mutationFn:ue,onError:(e,t)=>{e instanceof D&&e.result.reason!==`unsupported`&&ee.error(le(`desktopHostSwitcher.toast.instanceUnreachable`,{host:s(t.host.label)}))}}),O.subscribe(()=>void 0),O),fe=async e=>{if(l(e.host))return{ok:!0,via:`direct`,status:e.cachedProbe?.status===`ok`?e.cachedProbe:{status:`ok`,latencyMs:0}};if(o.isMutating({mutationKey:E})>0)return{ok:!1,status:{status:`unreachable`,latencyMs:0},reason:`unsupported`};try{return await de().mutate(e)}catch(e){if(e instanceof D)return e.result;throw e}},pe=()=>{let e=(0,T.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={mutationKey:E},e[0]=t):t=e[0],_(t)>0},me=()=>{let e=(0,T.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={filters:{mutationKey:E,status:`pending`},select:he},e[0]=t):t=e[0],g(t)[0]?.host.id??null};function he(e){return e.state.variables}var k=e=>typeof e==`object`&&!!e,A=(e,t)=>{let n=e[t];return typeof n==`string`?n:null},j=(e,t)=>{let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null},M=(e,t)=>{let n=e[t];return typeof n==`boolean`?n:null},N=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[],P=()=>r()?(e,t)=>a(e,t):null,F=e=>{if(!k(e))return;let t=M(e,`enabled`)??!1,n=A(e,`store`)?.toLowerCase()===`settings`?`settings`:`never`,r=A(e,`value`);return{enabled:t,store:n,...r?{value:r}:{}}},ge=e=>e===`remote`||e===`dynamic`?e:`local`,_e=e=>{if(!k(e))return null;let t=A(e,`id`);if(!t)return null;let n=M(e,`enabled`)??!0,r=ge(A(e,`type`)),i=A(e,`localHost`)||A(e,`local_host`)||void 0,a=j(e,`localPort`)??j(e,`local_port`)??void 0,o=A(e,`remoteHost`)||A(e,`remote_host`)||void 0,s=j(e,`remotePort`)??j(e,`remote_port`)??void 0;return{id:t,enabled:n,type:r,...i?{localHost:i}:{},...typeof a==`number`?{localPort:a}:{},...o?{remoteHost:o}:{},...typeof s==`number`?{remotePort:s}:{}}},ve=e=>{if(!k(e))return null;let t=A(e,`id`),n=A(e,`sshCommand`)||A(e,`ssh_command`);if(!t||!n)return null;let r=A(e,`nickname`),i=e.sshParsed,a=k(i)?{destination:A(i,`destination`)||``,args:N(i.args)}:void 0,o=k(e.remoteOpenchamber)?e.remoteOpenchamber:k(e.remote_openchamber)?e.remote_openchamber:{},s=k(e.localForward)?e.localForward:k(e.local_forward)?e.local_forward:{},c=k(e.auth)?e.auth:{},l=A(o,`mode`)?.toLowerCase()===`external`?`external`:`managed`,u=A(o,`installMethod`)||A(o,`install_method`),d=u===`npm`||u===`download_release`||u===`upload_bundle`?u:`bun`,f=A(s,`bindHost`)||A(s,`bind_host`)||`127.0.0.1`,p=f===`localhost`||f===`0.0.0.0`?f:`127.0.0.1`,m=(Array.isArray(e.portForwards)?e.portForwards:Array.isArray(e.port_forwards)?e.port_forwards:[]).map(e=>_e(e)).filter(e=>!!e),h=j(o,`preferredPort`)??j(o,`preferred_port`),g=j(s,`preferredLocalPort`)??j(s,`preferred_local_port`),_=F(c.sshPassword||c.ssh_password),v=F(c.openchamberPassword||c.openchamber_password);return{id:t,...r?{nickname:r}:{},sshCommand:n,...a&&a.destination?{sshParsed:a}:{},connectionTimeoutSec:j(e,`connectionTimeoutSec`)??j(e,`connection_timeout_sec`)??60,remoteOpenchamber:{mode:l,keepRunning:M(o,`keepRunning`)??M(o,`keep_running`)??!0,relayHost:M(o,`relayHost`)??M(o,`relay_host`)??!0,...h?{preferredPort:h}:{},installMethod:d,uploadBundleOverSsh:M(o,`uploadBundleOverSsh`)??M(o,`upload_bundle_over_ssh`)??!1},localForward:{...g?{preferredLocalPort:g}:{},bindHost:p},auth:{..._?{sshPassword:_}:{},...v?{openchamberPassword:v}:{}},portForwards:m}},ye=e=>{switch(e){case`config_resolved`:case`auth_check`:case`master_connecting`:case`remote_probe`:case`installing`:case`updating`:case`server_detecting`:case`server_starting`:case`forwarding`:case`ready`:case`degraded`:case`error`:return e;default:return`idle`}},I=e=>{if(!k(e))return null;let t=A(e,`id`);return t?{id:t,phase:ye(A(e,`phase`)),...A(e,`detail`)?{detail:A(e,`detail`)||void 0}:{},...A(e,`localUrl`)||A(e,`local_url`)?{localUrl:A(e,`localUrl`)||A(e,`local_url`)||void 0}:{},...typeof(j(e,`localPort`)??j(e,`local_port`))==`number`?{localPort:j(e,`localPort`)??j(e,`local_port`)??void 0}:{},...typeof(j(e,`remotePort`)??j(e,`remote_port`))==`number`?{remotePort:j(e,`remotePort`)??j(e,`remote_port`)??void 0}:{},startedByUs:M(e,`startedByUs`)??M(e,`started_by_us`)??!1,retryAttempt:j(e,`retryAttempt`)??j(e,`retry_attempt`)??0,requiresUserAction:M(e,`requiresUserAction`)??M(e,`requires_user_action`)??!1,...A(e,`errorCode`)||A(e,`error_code`)?{errorCode:A(e,`errorCode`)||A(e,`error_code`)||void 0}:{},updatedAtMs:j(e,`updatedAtMs`)??j(e,`updated_at_ms`)??Date.now()}:null},be=e=>{if(!k(e))return null;let t=A(e,`host`),n=A(e,`source`),r=A(e,`sshCommand`)||A(e,`ssh_command`);return!t||!n||!r?null:{host:t,source:n,sshCommand:r,pattern:M(e,`pattern`)??!1}},xe=(e,t)=>({id:e,sshCommand:t,connectionTimeoutSec:60,remoteOpenchamber:{mode:`managed`,keepRunning:!0,relayHost:!0,installMethod:`bun`,uploadBundleOverSsh:!1},localForward:{bindHost:`127.0.0.1`},auth:{},portForwards:[]}),Se=async()=>{let e=P();if(!e)return{instances:[]};let t=await e(`desktop_ssh_instances_get`);return k(t)?{instances:(Array.isArray(t.instances)?t.instances:Array.isArray(t.desktopSshInstances)?t.desktopSshInstances:[]).map(e=>ve(e)).filter(e=>!!e)}:{instances:[]}},Ce=async e=>{let t=P();t&&await t(`desktop_ssh_instances_set`,{config:{instances:e.instances}})},we=async()=>{let e=P();if(!e)return[];let t=await e(`desktop_ssh_import_hosts`);return Array.isArray(t)?t.map(e=>be(e)).filter(e=>!!e):[]},Te=async e=>{let t=P();t&&await t(`desktop_ssh_connect`,{id:e})},Ee=async e=>{let t=P();t&&await t(`desktop_ssh_disconnect`,{id:e})},De=async e=>{let t=P();if(!t)return[];let n=await t(`desktop_ssh_status`,{...e?{id:e}:{}});return Array.isArray(n)?n.map(e=>I(e)).filter(e=>!!e):[]},Oe=async(e,t)=>{let n=P();if(!n)return[];let r=await n(`desktop_ssh_logs`,{id:e,...typeof t==`number`?{limit:t}:{}});return Array.isArray(r)?r.filter(e=>typeof e==`string`):[]},ke=async e=>{let t=P();t&&await t(`desktop_ssh_logs_clear`,{id:e})},Ae=(e,t)=>{let n=Math.max(0,Math.trunc(Number(e.fileGroups)||0)),r=Math.max(0,Math.trunc(Number(e.singleFiles)||0)),i=Math.max(0,Math.trunc(Number(e.directories)||0));return{fileGroups:Array.from({length:n},()=>!0),singleFiles:Array.from({length:r},()=>!0),directories:Array.from({length:i},()=>!0),agentsRoot:!0,authFile:t?.includeAuthFile===!0}},je=e=>{if(!k(e))return null;let t=A(e,`path`),n=j(e,`bytes`);return!t||n===null?null:{path:t,bytes:n}},Me=e=>{if(!k(e))return null;let t=A(e,`path`),n=j(e,`fileCount`)??j(e,`file_count`),r=j(e,`bytes`);return!t||n===null||r===null?null:{path:t,fileCount:n,bytes:r}},Ne=e=>{if(e==null||!k(e))return null;let t=j(e,`fileCount`)??j(e,`file_count`),n=j(e,`bytes`);return t===null||n===null?null:{fileCount:t,bytes:n}},L=e=>{if(e==null||!k(e))return null;let t=j(e,`bytes`);return t===null?null:{bytes:t}},R=e=>{if(!k(e))return null;let t=Array.isArray(e.files)?e.files:null,n=Array.isArray(e.directories)?e.directories:null,r=N(e.deletes),i=j(e,`totalBytes`)??j(e,`total_bytes`);if(!t||!n||i===null||!(`agentsRoot`in e)&&!(`agents_root`in e))return null;let a=t.map(e=>je(e)).filter(e=>!!e),o=n.map(e=>Me(e)).filter(e=>!!e);if(a.length!==t.length||o.length!==n.length)return null;let s=e.agentsRoot??e.agents_root,c=s==null?null:Ne(s);if(s!=null&&c===null)return null;let l=e.authFile??e.auth_file,u=l==null?null:L(l),d=e.direction===`pull`||e.direction===`push`?e.direction:void 0,f=e.selections,p=k(f)?{fileGroups:Array.isArray(f.fileGroups)?f.fileGroups.map(e=>e!==!1):[],singleFiles:Array.isArray(f.singleFiles)?f.singleFiles.map(e=>e!==!1):[],directories:Array.isArray(f.directories)?f.directories.map(e=>e!==!1):[],agentsRoot:f.agentsRoot!==!1,authFile:f.authFile===!0}:void 0,m=z(e.selectionShape??e.selection_shape);return{files:a,directories:o,agentsRoot:c,authFile:u,deletes:r,totalBytes:i,...d?{direction:d}:{},...p?{selections:p}:{},...m?{selectionShape:m}:{}}},z=e=>{if(!k(e))return null;let t=j(e,`fileGroups`)??j(e,`file_groups`),n=j(e,`singleFiles`)??j(e,`single_files`),r=j(e,`directories`);return t===null||n===null||r===null||t<0||n<0||r<0?null:{fileGroups:t,singleFiles:n,directories:r}},Pe=e=>{if(!k(e))return null;let t=R(e.plan);if(!t)return null;let n=z(e.selectionShape??e.selection_shape)??t.selectionShape??null;return{plan:t,remoteExisting:N(e.remoteExisting??e.remote_existing),remoteAgentsRootExists:M(e,`remoteAgentsRootExists`)??M(e,`remote_agents_root_exists`)??!1,remoteAuthFileExists:M(e,`remoteAuthFileExists`)??M(e,`remote_auth_file_exists`)??!1,...n?{selectionShape:n}:{}}},Fe=e=>{if(!k(e)||M(e,`ok`)!==!0)return null;let t=j(e,`files`),n=j(e,`directories`),r=j(e,`deletes`),i=j(e,`totalBytes`)??j(e,`total_bytes`);if(t===null||n===null||r===null||i===null||!(`agentsRoot`in e)&&!(`agents_root`in e))return null;let a=e.agentsRoot??e.agents_root,o=null;if(a!=null){if(!k(a))return null;let e=j(a,`fileCount`)??j(a,`file_count`);if(e===null)return null;o={fileCount:e}}let s=e.authFile??e.auth_file,c=s==null?null:L(s);return{ok:!0,files:t,directories:n,deletes:r,totalBytes:i,agentsRoot:o,authFile:c}},Ie=async(e={})=>{let t=P();if(!t)return console.error(`[desktopSsh] config sync local scan skipped: desktop IPC bridge is unavailable in this window`),null;let n=await t(`desktop_ssh_sync_opencode_config`,{stage:`local`,...e.direction?{direction:e.direction}:{},...e.selections?{selections:e.selections}:{}});if(!k(n))return console.error(`[desktopSsh] config sync local scan returned a non-object payload`,n),null;let r=R(n.plan);if(!r)return console.error(`[desktopSsh] config sync local scan plan payload was not recognized`,n),null;let i=z(n.selectionShape??n.selection_shape)??r.selectionShape??null;return i?{...r,selectionShape:i}:r},Le=async(e,t={})=>{let n=P();if(!n)return console.error(`[desktopSsh] config sync preview skipped: desktop IPC bridge is unavailable in this window`),null;let r=await n(`desktop_ssh_sync_opencode_config`,{id:e,...t.targetKind?{targetKind:t.targetKind}:{},...t.direction?{direction:t.direction}:{},...t.selections?{selections:t.selections}:{}}),i=Pe(r);return i||console.error(`[desktopSsh] config sync preview payload was not recognized`,r),i},Re=async(e,t={})=>{let n=P();if(!n)return console.error(`[desktopSsh] config sync apply skipped: desktop IPC bridge is unavailable in this window`),null;let r=await n(`desktop_ssh_sync_opencode_config`,{id:e,apply:!0,...t.targetKind?{targetKind:t.targetKind}:{},...t.direction?{direction:t.direction}:{},...t.selections?{selections:t.selections}:{}}),i=Fe(r);return i||console.error(`[desktopSsh] config sync apply payload was not recognized`,r),i},ze=async(e,t={})=>{let n=P();if(!n)return[];let r=await n(`desktop_ssh_sync_runs_list`,{id:e,...t.targetKind?{targetKind:t.targetKind}:{}});return Array.isArray(r)?r.filter(e=>k(e)&&typeof e.syncRunId==`string`&&typeof e.targetId==`string`):[]},Be=async e=>{if(!r())return async()=>{};let t=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof t!=`function`)return async()=>{};let n=await t(`openchamber:ssh-instance-status`,t=>{let n=I(t?.payload);n&&e(n)});return async()=>{await n()}},Ve=new Set([`nodeRuntimeMissing`,`packageManagerMissing`,`nativeBinding`,`openchamberCliMissing`,`openchamberRegistry`,`openchamberInstall`,`openchamberCliIncompatible`,`opencodeInstall`,`serverStart`,`sshAuth`,`sshUnreachable`,`timeout`,`unknown`]),He=e=>typeof e==`string`&&Ve.has(e),Ue=e=>{let t=String(e||``);return/requires Node\.js \d+|no supported Node runtime/i.test(t)?`nodeRuntimeMissing`:/neither bun nor npm/i.test(t)?`packageManagerMissing`:/better-sqlite3|node_gyp_bins|gyp ERR|failed to prepare better-sqlite3/i.test(t)?`nativeBinding`:/OpenChamber installation completed but the executable is unavailable/i.test(t)?`openchamberCliMissing`:/could not reach the npm registry|ENOTFOUND|ECONNREFUSED|ETIMEDOUT|EAI_AGAIN|CERT_HAS_EXPIRED|UNABLE_TO_GET_ISSUER_CERT|self-signed certificate|registry\.npmjs|npm error code E404|npm ERR! code E404|getaddrinfo/i.test(t)?`openchamberRegistry`:/Failed to install OpenChamber/i.test(t)?`openchamberInstall`:/Unknown option:\s*--relay-host|does not advertise --relay-host|does not support --relay-host/i.test(t)||/Unknown option:/i.test(t)?`openchamberCliIncompatible`:/Failed to install OpenCode|OpenCode CLI/i.test(t)?`opencodeInstall`:/failed to become reachable|Managed OpenChamber server failed/i.test(t)?`serverStart`:/Permission denied|Authentication failed|publickey|keyboard-interactive/i.test(t)?`sshAuth`:/Could not resolve hostname|Connection refused|Connection timed out|ControlMaster connection timed out|SSH master process exited|Network is unreachable/i.test(t)?`sshUnreachable`:/Timed out waiting for SSH|Timed out waiting for forwarded/i.test(t)?`timeout`:`unknown`},B=(e,t)=>He(e)?e:Ue(t),V=e=>{switch(e){case`nodeRuntimeMissing`:return`desktopHostSwitcher.sshError.nodeRuntimeMissing.title`;case`packageManagerMissing`:return`desktopHostSwitcher.sshError.packageManagerMissing.title`;case`nativeBinding`:return`desktopHostSwitcher.sshError.nativeBinding.title`;case`openchamberCliMissing`:return`desktopHostSwitcher.sshError.openchamberCliMissing.title`;case`openchamberRegistry`:return`desktopHostSwitcher.sshError.openchamberRegistry.title`;case`openchamberInstall`:return`desktopHostSwitcher.sshError.openchamberInstall.title`;case`openchamberCliIncompatible`:return`desktopHostSwitcher.sshError.openchamberCliIncompatible.title`;case`opencodeInstall`:return`desktopHostSwitcher.sshError.opencodeInstall.title`;case`serverStart`:return`desktopHostSwitcher.sshError.serverStart.title`;case`sshAuth`:return`desktopHostSwitcher.sshError.sshAuth.title`;case`sshUnreachable`:return`desktopHostSwitcher.sshError.sshUnreachable.title`;case`timeout`:return`desktopHostSwitcher.sshError.timeout.title`;default:return`desktopHostSwitcher.sshError.unknown.title`}},H=e=>{switch(e){case`nodeRuntimeMissing`:return`desktopHostSwitcher.sshError.nodeRuntimeMissing.guidance`;case`packageManagerMissing`:return`desktopHostSwitcher.sshError.packageManagerMissing.guidance`;case`nativeBinding`:return`desktopHostSwitcher.sshError.nativeBinding.guidance`;case`openchamberCliMissing`:return`desktopHostSwitcher.sshError.openchamberCliMissing.guidance`;case`openchamberRegistry`:return`desktopHostSwitcher.sshError.openchamberRegistry.guidance`;case`openchamberInstall`:return`desktopHostSwitcher.sshError.openchamberInstall.guidance`;case`openchamberCliIncompatible`:return`desktopHostSwitcher.sshError.openchamberCliIncompatible.guidance`;case`opencodeInstall`:return`desktopHostSwitcher.sshError.opencodeInstall.guidance`;case`serverStart`:return`desktopHostSwitcher.sshError.serverStart.guidance`;case`sshAuth`:return`desktopHostSwitcher.sshError.sshAuth.guidance`;case`sshUnreachable`:return`desktopHostSwitcher.sshError.sshUnreachable.guidance`;case`timeout`:return`desktopHostSwitcher.sshError.timeout.guidance`;default:return`desktopHostSwitcher.sshError.unknown.guidance`}},U=e=>e===`unknown`||e===`openchamberCliIncompatible`,We=(e,t,n)=>{let r=typeof n==`string`?n.trim():``;return!U(t)||!r||r===e?e:`${e}\n${r}`},W=d();function Ge(e){let t=(0,T.c)(27),{errorCode:n,detail:r,className:i}=e,{t:a}=v(),o,s,c,l,u,d;if(t[0]!==i||t[1]!==r||t[2]!==n||t[3]!==a){let e=B(n,r);o=a(H(e));let f;t[10]===r?f=t[11]:(f=typeof r==`string`?r.trim():``,t[10]=r,t[11]=f),s=f,c=U(e)&&!!s&&s!==o,t[12]===i?d=t[13]:(d=ne(`space-y-1`,i),t[12]=i,t[13]=d),l=`typography-ui-label text-[var(--status-error)]`,u=a(V(e)),t[0]=i,t[1]=r,t[2]=n,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d}else o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9];let f;t[14]!==l||t[15]!==u?(f=(0,W.jsx)(`p`,{className:l,children:u}),t[14]=l,t[15]=u,t[16]=f):f=t[16];let p;t[17]===o?p=t[18]:(p=(0,W.jsx)(`p`,{className:`typography-meta text-muted-foreground`,children:o}),t[17]=o,t[18]=p);let m;t[19]!==s||t[20]!==c?(m=c?(0,W.jsx)(`p`,{className:`typography-meta break-words text-muted-foreground`,children:s}):null,t[19]=s,t[20]=c,t[21]=m):m=t[21];let h;return t[22]!==d||t[23]!==f||t[24]!==p||t[25]!==m?(h=(0,W.jsxs)(`div`,{className:d,children:[f,p,m]}),t[22]=d,t[23]=f,t[24]=p,t[25]=m,t[26]=h):h=t[26],h}var Ke=`/auth/passkey/authenticate/options`,qe=`/auth/passkey/authenticate/verify`,Je=`/auth/passkey/register/options`,Ye=`/auth/passkey/register/verify`,G=`/api/passkeys`,Xe=`/auth/passkey/status`,Ze=`/api/auth/reset`,K={enabled:!1,hasPasskeys:!1,passkeyCount:0,rpID:null},q=async(e,t)=>i(e,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:t===void 0?void 0:JSON.stringify(t)}),J=async(e,t)=>{try{let t=await e.json();if(t&&typeof t.error==`string`&&t.error.trim())return t.error}catch{}return t},Qe=e=>e instanceof re&&e.code===`ERROR_CEREMONY_ABORTED`,$e=()=>{ae.cancelCeremony()},Y=()=>typeof window>`u`?{supported:!1,reason:`Passkeys are unavailable outside the browser.`}:window.isSecureContext?{supported:!0,reason:``}:{supported:!1,reason:`Passkeys require HTTPS or localhost.`},et=async()=>{let e=Y();if(!e.supported)throw Error(e.reason);let t=await q(Je,{label:typeof navigator.userAgent==`string`&&navigator.userAgent.trim()?navigator.userAgent:`This device`});if(!t.ok)throw Error(await J(t,`Could not start passkey setup.`));let{requestId:n,optionsJSON:r}=await t.json(),i=await q(Ye,{requestId:n,response:await ie({optionsJSON:r})});if(!i.ok)throw Error(await J(i,`Could not finish passkey setup.`));return i.json().catch(()=>null)},tt=async(e,t={})=>{let n=Y();if(!n.supported)throw Error(n.reason);let r=await q(Ke);if(!r.ok)throw Error(await J(r,`Passkey sign-in is not available right now.`));let{requestId:i,optionsJSON:a}=await r.json(),o=await q(qe,{requestId:i,response:await oe({optionsJSON:a}),trustDevice:e,issueClientToken:t.issueClientToken===!0,clientLabel:t.clientLabel,clientKind:t.clientKind,dedupeKey:t.dedupeKey});if(!o.ok)throw Error(await J(o,`Passkey sign-in failed.`));return o.json().catch(()=>null)},nt=async()=>{let e=await i(Xe,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return K;let t=await e.json().catch(()=>null);return{enabled:t?.enabled===!0,hasPasskeys:t?.hasPasskeys===!0,passkeyCount:typeof t?.passkeyCount==`number`?t.passkeyCount:0,rpID:typeof t?.rpID==`string`&&t.rpID?t.rpID:null}},rt=async()=>{let e=await i(G,{method:`GET`,credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)throw Error(await J(e,`Could not load passkeys.`));let t=await e.json().catch(()=>null);return Array.isArray(t?.passkeys)?t.passkeys:[]},it=async e=>{let t=await i(`${G}/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`,headers:{Accept:`application/json`}});if(!t.ok)throw Error(await J(t,`Could not remove passkey.`));return t.json().catch(()=>null)},at=async()=>{let e=await q(Ze);if(!e.ok)throw Error(await J(e,`Could not clear saved authentication.`));return e.json().catch(()=>null)},X=e=>b(y.getState().dictionary,e),ot=e=>typeof e!=`number`||!Number.isFinite(e)?null:Math.max(0,Math.min(100,Math.round(e))),st=e=>typeof e!=`number`||!Number.isFinite(e)?`-`:`${Math.round(e)}%`,ct=(e,t)=>e??st(t),lt=(e,t,n=`auto`)=>{if(!e)return t??``;try{let r=new Date(e);if(!Number.isFinite(r.getTime()))return t??``;let i=new Date;return r.toDateString()===i.toDateString()?ce(r,n,{fallback:t??``}):se(r,n,{month:`short`,day:`numeric`,weekday:`short`,hour:`numeric`,minute:`2-digit`})}catch{return t??``}},ut=e=>e===null?`safe`:e>=80?`critical`:e>=50?`warn`:`safe`,dt=e=>e===`5h`?X(`quota.window.5h`):e===`7d`?X(`quota.window.7d`):e===`7d-sonnet`?X(`quota.window.7dSonnet`):e===`7d-opus`?X(`quota.window.7dOpus`):e===`weekly`?X(`quota.window.weekly`):e===`daily`?X(`quota.window.daily`):e===`monthly`?X(`quota.window.monthly`):e===`credits`?X(`quota.window.credits`):e===`credits_balance`?X(`quota.window.creditsBalance`):e===`billing_cycle`?X(`quota.window.billingCycle`):e===`auto`?X(`quota.window.auto`):e===`api`?X(`quota.window.api`):e===`plan_limit`?X(`quota.window.planLimit`):e===`on_demand`?X(`quota.window.onDemand`):e===`session`?X(`quota.window.session`):e===`premium`?X(`quota.window.premium`):e===`chat`?X(`quota.window.chat`):e===`completions`?X(`quota.window.completions`):e===`premium_interactions`?X(`quota.window.premiumInteractions`):e,ft=e=>{let t=e.toLowerCase().trim();if(t===`5h`)return 18e3;if(t===`7d`||t===`weekly`||t===`7d-sonnet`||t===`7d-opus`)return 604800;if(t===`monthly`)return 2592e3;if(t===`24h`||t===`daily`)return 86400;if(t===`1h`)return 3600;let n=t.match(/^(\d+)h$/);if(n)return parseInt(n[1],10)*3600;let r=t.match(/^(\d+)d$/);return r?parseInt(r[1],10)*86400:null},pt=(e,t,n,r)=>{let i=n;if(i===null&&r&&(i=ft(r)),e===null||t===null||i===null||i<=0)return null;let a=Math.max(0,(t-Date.now())/1e3),o=Math.max(0,Math.min(i,i-a)),s=Math.max(0,Math.min(1,o/i)),c=e/100,l=e>=100&&a>0,u;u=s>.01?Math.min(999,c/s*100):e;let d;d=l?`exhausted`:c<=s?`on-track`:u<=130?`slightly-fast`:`too-fast`;let f=i>=432e3,p=f?86400:3600,m=f?`d`:`h`,h=i/p,g=e/Math.max(o/p,h*.01),_=Number.isFinite(g)?`${Math.min(999.9,Math.max(0,g)).toFixed(1)}%/${m}`:`-`,v=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`,y=null,b=i/86400;return b>=7&&(y=100/b),{elapsedRatio:s,usageRatio:c,predictedFinalPercent:u,remainingSeconds:a,isExhausted:l,elapsedSeconds:o,totalSeconds:i,status:d,paceRateText:_,predictText:v,dailyAllocationPercent:y}},mt=e=>{switch(e){case`exhausted`:case`too-fast`:return`var(--status-error)`;case`slightly-fast`:return`var(--status-warning)`;case`on-track`:return`var(--status-success)`}},ht=e=>{let t=Math.floor(Math.max(0,Math.floor(e))/60),n=Math.floor(t/60),r=Math.floor(n/24),i=n%24,a=t%60;return r>0?`${r}d ${i}h`:n>0?`${n}h`:t===0?`<1m`:`${a}m`},gt=e=>Math.min(100,Math.max(0,e*100)),_t=[`standalone`,`minimal-ui`,`fullscreen`,`window-controls-overlay`],vt=`openchamber.pwaRecentSessions`,yt=e=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(display-mode: ${e})`).matches,bt=()=>typeof window>`u`?`browser`:typeof document<`u`&&document.referrer.startsWith(`android-app://`)?`twa`:window.navigator.standalone?`standalone`:_t.find(e=>yt(e))??`browser`,Z=e(f(),1),xt=864e5,Q=5,St=864e5,$=e=>e.time?.updated??e.time?.created??0,Ct=({sessions:e,currentSessionId:t,cutoffDays:n,keepRecent:r=Q,now:i=Date.now()})=>{if(!Array.isArray(e)||n<=0)return[];let a=i-n*xt,o=[...e].sort((e,t)=>$(t)-$(e)),s=new Set(o.slice(0,r).map(e=>e.id));return o.filter(e=>{if(!e?.id||s.has(e.id)||e.id===t||e.share)return!1;let n=$(e);return n?n<a:!1}).map(e=>e.id)},wt=e=>{let t=typeof e==`object`?e:void 0,r=t?.autoRun!==!1,i=typeof e==`boolean`?e:t?.enabled??!0,a=S(e=>e.currentSessionId),o=S(e=>e.isLoading),s=x(e=>e.activeSessions),c=x(e=>e.hasLoadedFullCatalog),l=n(e=>e.autoDeleteEnabled),u=n(e=>e.autoDeleteAfterDays),d=n(e=>e.sessionRetentionAction),f=n(e=>e.autoDeleteLastRunAt),m=n(e=>e.setAutoDeleteLastRunAt),[h,g]=Z.useState(!1),_=Z.useRef(!1);Z.useEffect(()=>{if(!i||!r||!l||u<=0)return;let e=window.setTimeout(()=>{w(C())},8e3);return()=>window.clearTimeout(e)},[u,l,r,i]);let v=Z.useMemo(()=>u<=0?[]:Ct({sessions:s,currentSessionId:a,cutoffDays:u}),[u,a,s]),y=Z.useCallback(async({force:e=!1}={})=>{if(_.current)return{completedIds:[],failedIds:[],action:d,skippedReason:`running`};if((!l||u<=0)&&!e)return{completedIds:[],failedIds:[],action:d,skippedReason:`disabled`};if(o)return{completedIds:[],failedIds:[],action:d,skippedReason:`loading`};let t=Date.now();if(!e&&f&&t-f<St)return{completedIds:[],failedIds:[],action:d,skippedReason:`cooldown`};let{activeSessions:n}=await w(C());if(n.length===0)return{completedIds:[],failedIds:[],action:d,skippedReason:`no-candidates`};let r=Ct({sessions:n,currentSessionId:a,cutoffDays:u,now:t});if(r.length===0)return m(t),{completedIds:[],failedIds:[],action:d,skippedReason:`no-candidates`};_.current=!0,g(!0);try{let e=new Map(n.map(e=>[e.id,e])),t=[],i=[];for(let n of r){let r=e.get(n),a=r?te(r):null;if(!a){i.push(n);continue}try{d===`archive`?await p.updateSession(n,{time:{archived:Date.now()}},a):await p.deleteSession(n,a),t.push(n)}catch{i.push(n)}}return d===`archive`?x.getState().archiveSessions(t):x.getState().removeSessions(t),{completedIds:t,failedIds:i,action:d}}finally{_.current=!1,g(!1),m(Date.now())}},[u,l,f,a,o,d,m]);return Z.useEffect(()=>{i&&r&&(!l||u<=0||o||!c||s.length===0||f&&Date.now()-f<St||y())},[u,l,f,r,i,c,s.length,o,y]),{candidates:v,isRunning:h,runCleanup:y,keepRecentCount:Q,action:d}};export{Te as A,Le as B,Ge as C,V as D,H as E,Oe as F,me as G,Be as H,ke as I,De as L,we as M,Se as N,Ae as O,Ce as P,Re as R,it as S,B as T,fe as U,ze as V,pe as W,rt as _,pt as a,et as b,ct as c,mt as d,ut as f,nt as g,K as h,gt as i,Ee as j,xe as k,ht as l,$e as m,vt as n,ot as o,tt as p,bt as r,lt as s,wt as t,dt as u,Y as v,We as w,at as x,Qe as y,Ie as z};
|
package/dist/assets/{useWorkerHighlightedLines-DsjpSlQ0.js → useWorkerHighlightedLines-B_hH_qlZ.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{_ as t}from"./useUIStore-BXjMQrel.js";import{$t as n,kn as r,xn as i}from"./persistence-CLUawIlm.js";import{nt as a,rt as o}from"./vendor-base-ui-CnHfUmDN.js";import{n as s}from"./platform-BrncW9ab.js";import{a as c,n as l}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as u}from"./vendor-react-DLPElpoQ.js";import{n as d}from"./clipboard-C0bgPFn5.js";import{t as f}from"./utils-D94hxQYq.js";import{n as p}from"./Icon-Du1LX11Q.js";import{t as m}from"./button-p6vbd3r6.js";import{i as h,n as g,t as _}from"./tooltip-D1a6rKLA.js";import{n as v}from"./useThemeSystem-DMzWVJaW.js";import{c as y,n as b,o as x,r as S,s as C}from"./markdownTheme-St8zxDvJ.js";import{i as w}from"./appThemeRegistry-BtwC37-e.js";import{d as T,f as E,n as D,t as ee}from"./markdown-worker-CoO82KYF.js";import{t as te}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";var O=e(o(),1),k=u(),A=a(),ne=`w-[min(30rem,calc(100cqw-1rem))] min-w-[280px] max-w-full overflow-hidden rounded-xl shadow-[inset_0_1px_0_0_rgba(255,255,255,0.8),inset_0_0_0_1px_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.10),0_1px_2px_-0.5px_rgba(0,0,0,0.08),0_4px_8px_-2px_rgba(0,0,0,0.08),0_12px_20px_-4px_rgba(0,0,0,0.08)] dark:shadow-[inset_0_1px_0_0_rgba(255,255,255,0.12),inset_0_0_0_1px_rgba(255,255,255,0.08),0_0_0_1px_rgba(0,0,0,0.36),0_1px_1px_-0.5px_rgba(0,0,0,0.22),0_3px_3px_-1.5px_rgba(0,0,0,0.20),0_6px_6px_-3px_rgba(0,0,0,0.16)]`,j={maxWidth:`min(28rem, calc(100cqw - 4ch))`,backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},M=`flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] px-3 py-2.5`,N=`text-xs font-medium leading-4 text-foreground md:text-[0.8125rem] md:leading-5`,re=`text-xs tabular-nums leading-4 text-muted-foreground md:text-[0.8125rem] md:leading-5`,P=`m-0 list-none divide-y divide-[var(--surface-subtle)] p-0`,F=`${P} max-h-[min(22rem,50vh)] overflow-y-auto`,ie=`${P} w-full`,ae={className:`p-0 rounded-none`,maxHeightClass:`max-h-[46vh]`,disableHorizontal:!0},I=`px-2.5 py-1.5 text-xs leading-4 md:py-2 md:text-[0.8125rem] md:leading-5`,oe=`flex min-w-0 items-center gap-1 text-xs leading-4 text-muted-foreground md:gap-1.5 md:text-[0.8125rem] md:leading-5`,se=`min-w-0 truncate text-xs leading-4 text-foreground md:text-[0.8125rem] md:leading-5`,ce=`inline-flex shrink-0 items-center gap-1 text-xs leading-4 tabular-nums text-muted-foreground md:text-[0.8125rem] md:leading-5`,le=`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`,ue={in_progress:`text-foreground`,pending:`text-foreground`,completed:`text-muted-foreground line-through`,cancelled:`text-muted-foreground line-through`},L={in_progress:`chat.statusRow.todo.status.inProgress`,pending:`chat.statusRow.todo.status.pending`,completed:`chat.statusRow.todo.status.completed`,cancelled:`chat.statusRow.todo.status.cancelled`},R=e=>{let t=(0,k.c)(26),{todo:n,isActive:r,activeRef:i}=e,{t:a}=d(),o=z.has(n.status)?n.status:`pending`,s=L[o],c;t[0]!==a||t[1]!==s?(c=a(s),t[0]=a,t[1]=s,t[2]=c):c=t[2];let l=c,u;t[3]===o?u=t[4]:(u=o===`in_progress`?(0,A.jsx)(p,{name:`record-circle`,className:`h-3.5 w-3.5 text-[var(--status-info)]`,"aria-hidden":`true`}):o===`completed`?(0,A.jsx)(p,{name:`checkbox-circle`,className:`h-3.5 w-3.5 text-[var(--status-success)]`,"aria-hidden":`true`}):(0,A.jsx)(p,{name:`time`,className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":`true`}),t[3]=o,t[4]=u);let m=u,v=r?`step`:void 0,y=r&&`bg-[var(--surface-muted)] before:absolute before:inset-y-2 before:left-0 before:w-0.5 before:rounded-full before:bg-[var(--status-info)]`,b;t[5]===y?b=t[6]:(b=f(`group relative grid min-w-0 grid-cols-[1rem_minmax(0,1fr)] items-start gap-2.5`,I,y),t[5]=y,t[6]=b);let x;t[7]!==m||t[8]!==l?(x=(0,A.jsx)(h,{asChild:!0,children:(0,A.jsx)(`span`,{className:`flex size-4 items-center justify-center`,"aria-label":l,children:m})}),t[7]=m,t[8]=l,t[9]=x):x=t[9];let S;t[10]===l?S=t[11]:(S=(0,A.jsx)(g,{side:`left`,sideOffset:6,children:l}),t[10]=l,t[11]=S);let C;t[12]!==x||t[13]!==S?(C=(0,A.jsxs)(_,{children:[x,S]}),t[12]=x,t[13]=S,t[14]=C):C=t[14];let w=ue[o],T;t[15]===w?T=t[16]:(T=f(`block whitespace-normal break-words`,w),t[15]=w,t[16]=T);let E;t[17]!==T||t[18]!==n.content?(E=(0,A.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,A.jsx)(`span`,{className:T,children:n.content})}),t[17]=T,t[18]=n.content,t[19]=E):E=t[19];let D;return t[20]!==i||t[21]!==E||t[22]!==v||t[23]!==b||t[24]!==C?(D=(0,A.jsxs)(`li`,{ref:i,"aria-current":v,className:b,children:[C,E]}),t[20]=i,t[21]=E,t[22]=v,t[23]=b,t[24]=C,t[25]=D):D=t[25],D},z=new Set([`in_progress`,`pending`,`completed`,`cancelled`]),B=`image/png`,V=c(`OpenChamberMedia`),H=e=>{let t=e.toLowerCase().split(`;`)[0]?.trim()||B;if(t===`image/jpeg`||t===`image/jpg`)return`jpg`;if(t===`image/webp`)return`webp`;if(t===`image/gif`)return`gif`;if(t===`image/svg+xml`)return`svg`;if(t===`image/png`)return`png`;let n=t.split(`/`)[1];return n&&/^[a-z0-9.+-]+$/i.test(n)?n:`png`},U=(e,t)=>{let n=`image.${H(t)}`,r=(((e||``).trim()||n).split(/[\\/]/).pop()||n).replace(/[^\w.\- ()[\]]+/g,`_`).replace(/^\.+/,``);return r?/\.[a-z0-9]{1,8}$/i.test(r)?r:`${r}.${H(t)}`:n},W=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{if(typeof r.result==`string`){t(r.result);return}n(Error(`Failed to encode image`))},r.onerror=()=>n(r.error??Error(`Failed to encode image`)),r.readAsDataURL(e)}),de=async e=>{let t=await W(e),n=t.indexOf(`,`);return n>=0?t.slice(n+1):t},fe=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),document.body.removeChild(r),window.setTimeout(()=>URL.revokeObjectURL(n),1e3)},G=async(e,t)=>{let n=await fetch(e,{signal:t,cache:`no-store`});if(!n.ok)throw Error(`Image fetch failed (${n.status})`);return n.blob()},pe=async(e,t=B)=>{if(!e.naturalWidth||!e.naturalHeight)return null;let n=e.currentSrc||e.src;if(n&&(/^(?:blob:|data:|openchamber-asset:)/i.test(n)||/^https?:/i.test(n)||/^\/api(?=\/|[?#]|$)/.test(n)))try{let e=await G(n);if(e.size>0)return e}catch{}try{let n=document.createElement(`canvas`);n.width=e.naturalWidth,n.height=e.naturalHeight;let r=n.getContext(`2d`);if(!r)return null;r.drawImage(e,0,0);let i=t.startsWith(`image/`)?t:B,a=await new Promise(e=>{n.toBlob(t=>e(t),i===`image/jpg`?`image/jpeg`:i)});return a&&a.size>0?a:null}catch{return null}},me=async(e,t)=>{let n=``;try{return n=await S(e,t??new AbortController().signal),await G(n,t)}finally{n&&C(n)}},he=async(e,t)=>{let n=e.effectiveDirectory??``,i=null;e.prefetchedBlob&&e.prefetchedBlob.size>0&&(i=e.prefetchedBlob);let a=e.displayUrl?.trim();if(!i&&a)try{i=await G(a,t)}catch{i=null}if(!i){let a=e.sourceUrl.trim();if(!a)throw Error(`Image source is empty`);if(/^(?:data|blob):/i.test(a)||/^https?:/i.test(a)||/^\/api(?=\/|[?#]|$)/.test(a))i=await G(a,t);else{let e=y(a,n);if(x(e))try{i=await me(e.path,t)}catch{let n=await r(`/api/fs/raw`,{method:`GET`,cache:`no-store`,query:{path:e.path},signal:t});if(!n.ok)throw Error(`Image source request failed with status ${n.status}`);i=await n.blob()}else i=await G(e.source,t)}}if(!i||i.size<=0)throw Error(`Image is empty`);let o=(e.mimeType||(i.type&&i.type.startsWith(`image/`)?i.type:``)||B).split(`;`)[0].trim()||B;return{blob:i,filename:U(e.filename,o),mimeType:o}},ge=()=>!s()||l===void 0?!1:l.isPluginAvailable(`OpenChamberMedia`),_e=async(e,t)=>{let{blob:r,filename:a,mimeType:o}=await he(e,t);if(ge()){let e=await de(r);return await V.saveImage({dataBase64:e,mimeType:o,filename:a}),`saved`}if(n()){let e=i()?.vscode;if(e?.saveImage){let t=await W(r);return await e.saveImage({fileName:a,dataUrl:t}),`saved`}}return fe(r,a),`downloaded`},ve=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),ye=e=>e?Object.entries(e).map(([e,t])=>t==null?``:`${e.startsWith(`--`)?e:e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}:${typeof t==`number`?`${t}px`:t};`).join(``):``,K=(e,t,n)=>{let r=e.querySelector(`pre`);r&&(r.style.margin=`0`,r.style.background=`transparent`,r.style.whiteSpace=t?`pre-wrap`:`pre`,t&&(r.style.wordBreak=`break-word`,r.style.overflowWrap=`break-word`));let i=e.querySelector(`code`);if(i){let e=ye(n);e&&i.setAttribute(`style`,`${i.getAttribute(`style`)??``}${e}`)}},be=e=>`<pre><code>${ve(e)}</code></pre>`,xe=e=>{let t=(0,k.c)(21),{code:n,language:r,className:i,style:a,codeStyle:o,wrap:s}=e,c=s!==void 0&&s,{currentTheme:l}=v(),u=O.useRef(null),d;t[0]===l?d=t[1]:(d=b(l),t[0]=l,t[1]=d);let p=d,m,h;t[2]!==n||t[3]!==o||t[4]!==c?(m=()=>{let e=u.current;e&&(e.innerHTML=be(n),K(e,c,o))},h=[n,c,o],t[2]=n,t[3]=o,t[4]=c,t[5]=m,t[6]=h):(m=t[5],h=t[6]),O.useLayoutEffect(m,h);let g,_;t[7]!==n||t[8]!==o||t[9]!==r||t[10]!==c?(g=()=>{let e=u.current;if(!e)return;let t=!0,i=new AbortController;return ee(n,(r||`text`).toLowerCase(),{signal:i.signal,priority:`visible`}).then(n=>{!t||!e||!n||(e.innerHTML=n,K(e,c,o))}),()=>{t=!1,i.abort()}},_=[n,r,c,o],t[7]=n,t[8]=o,t[9]=r,t[10]=c,t[11]=g,t[12]=_):(g=t[11],_=t[12]),O.useEffect(g,_);let y;t[13]===i?y=t[14]:(y=f(`typography-code`,i),t[13]=i,t[14]=y);let x=p,S;t[15]!==a||t[16]!==x?(S={...x,...a},t[15]=a,t[16]=x,t[17]=S):S=t[17];let C;return t[18]!==y||t[19]!==S?(C=(0,A.jsx)(`div`,{ref:u,className:y,style:S}),t[18]=y,t[19]=S,t[20]=C):C=t[20],C},Se=e=>{let t=e.replace(/^<file>\s*\n?/,``).replace(/\n?<\/file>\s*$/,``);return t=t.replace(/^\s*\d{5}\|\s?/gm,``),t.trim()},Ce=(e,t=``)=>{if(typeof e==`string`)return e;if(e==null)return t;if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return String(e);try{return JSON.stringify(e)}catch{return t}},we=e=>e?e.includes(`<diagnostics`)||e.includes(`<file_diagnostics>`)||e.includes(`LSP errors detected`)||e.includes(`This file has errors`):!1,Te=e=>e?e.replace(/\n{0,2}LSP errors detected[\s\S]*?<diagnostics[^>]*>[\s\S]*?<\/diagnostics>/g,``).replace(/\n{0,2}This file has errors[\s\S]*?<\/file_diagnostics>/g,``).replace(/<diagnostics[^>]*>[\s\S]*?<\/diagnostics>/g,``).replace(/<file_diagnostics>[\s\S]*?<\/file_diagnostics>/g,``).trim():``,Ee=(e,t)=>!e||typeof e!=`object`?String(e):E(e,t||``),q=e=>{if(typeof e==`string`){let t=e.trim();return t.length>0?t:void 0}if(e&&typeof e==`object`){let t=e.patch;if(typeof t==`string`){let e=t.trim();return e.length>0?e:void 0}}},De=e=>{if(!e||typeof e!=`object`)return;let t=q(e.patch)??q(e.diff);if(t)return t;let n=Array.isArray(e.files)?e.files:[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=q(e.patch)??q(e.diff);if(t)return t}},Oe=e=>{if(!e||typeof e!=`string`)return{data:null,isJson:!1};let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`)||!t.endsWith(`}`)&&!t.endsWith(`]`)||t.length<2)return{data:null,isJson:!1};try{let e=JSON.parse(t);return typeof e==`object`&&e?{data:e,isJson:!0}:{data:null,isJson:!1}}catch{return{data:null,isJson:!1}}},ke=(e,t,n)=>{let r=Se(e);if((t===`edit`||t===`multiedit`||t===`write`||t===`apply_patch`)&&we(r)&&(r=Te(r)),(t===`edit`||t===`multiedit`||t===`apply_patch`)&&r.trim().length===0){let e=De(n);if(e)return e}return r},Ae=e=>{let t=e.match(/<type>(file|directory)<\/type>/i)?.[1]?.toLowerCase()??`unknown`,n=(e.match(/<content>([\s\S]*?)<\/content>/i)?.[1]??e).replace(/\r\n/g,`
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{_ as t}from"./useUIStore-BXjMQrel.js";import{$t as n,kn as r,xn as i}from"./persistence-CLUawIlm.js";import{nt as a,rt as o}from"./vendor-base-ui-CnHfUmDN.js";import{n as s}from"./platform-BrncW9ab.js";import{a as c,n as l}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as u}from"./vendor-react-DLPElpoQ.js";import{n as d}from"./clipboard-C0bgPFn5.js";import{t as f}from"./utils-D94hxQYq.js";import{n as p}from"./Icon-Du1LX11Q.js";import{t as m}from"./button-p6vbd3r6.js";import{i as h,n as g,t as _}from"./tooltip-D1a6rKLA.js";import{n as v}from"./useThemeSystem-DMzWVJaW.js";import{c as y,n as b,o as x,r as S,s as C}from"./markdownTheme-St8zxDvJ.js";import{i as w}from"./appThemeRegistry-BQAoUoXG.js";import{d as T,f as E,n as D,t as ee}from"./markdown-worker-CoO82KYF.js";import{t as te}from"./vendor-tanstack-react-virtual-tlDgH6PG.js";var O=e(o(),1),k=u(),A=a(),ne=`w-[min(30rem,calc(100cqw-1rem))] min-w-[280px] max-w-full overflow-hidden rounded-xl shadow-[inset_0_1px_0_0_rgba(255,255,255,0.8),inset_0_0_0_1px_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.10),0_1px_2px_-0.5px_rgba(0,0,0,0.08),0_4px_8px_-2px_rgba(0,0,0,0.08),0_12px_20px_-4px_rgba(0,0,0,0.08)] dark:shadow-[inset_0_1px_0_0_rgba(255,255,255,0.12),inset_0_0_0_1px_rgba(255,255,255,0.08),0_0_0_1px_rgba(0,0,0,0.36),0_1px_1px_-0.5px_rgba(0,0,0,0.22),0_3px_3px_-1.5px_rgba(0,0,0,0.20),0_6px_6px_-3px_rgba(0,0,0,0.16)]`,j={maxWidth:`min(28rem, calc(100cqw - 4ch))`,backgroundColor:`var(--surface-elevated)`,color:`var(--surface-elevated-foreground)`},M=`flex items-center justify-between gap-3 border-b border-[var(--surface-subtle)] px-3 py-2.5`,N=`text-xs font-medium leading-4 text-foreground md:text-[0.8125rem] md:leading-5`,re=`text-xs tabular-nums leading-4 text-muted-foreground md:text-[0.8125rem] md:leading-5`,P=`m-0 list-none divide-y divide-[var(--surface-subtle)] p-0`,F=`${P} max-h-[min(22rem,50vh)] overflow-y-auto`,ie=`${P} w-full`,ae={className:`p-0 rounded-none`,maxHeightClass:`max-h-[46vh]`,disableHorizontal:!0},I=`px-2.5 py-1.5 text-xs leading-4 md:py-2 md:text-[0.8125rem] md:leading-5`,oe=`flex min-w-0 items-center gap-1 text-xs leading-4 text-muted-foreground md:gap-1.5 md:text-[0.8125rem] md:leading-5`,se=`min-w-0 truncate text-xs leading-4 text-foreground md:text-[0.8125rem] md:leading-5`,ce=`inline-flex shrink-0 items-center gap-1 text-xs leading-4 tabular-nums text-muted-foreground md:text-[0.8125rem] md:leading-5`,le=`h-3 w-3 shrink-0 md:h-3.5 md:w-3.5`,ue={in_progress:`text-foreground`,pending:`text-foreground`,completed:`text-muted-foreground line-through`,cancelled:`text-muted-foreground line-through`},L={in_progress:`chat.statusRow.todo.status.inProgress`,pending:`chat.statusRow.todo.status.pending`,completed:`chat.statusRow.todo.status.completed`,cancelled:`chat.statusRow.todo.status.cancelled`},R=e=>{let t=(0,k.c)(26),{todo:n,isActive:r,activeRef:i}=e,{t:a}=d(),o=z.has(n.status)?n.status:`pending`,s=L[o],c;t[0]!==a||t[1]!==s?(c=a(s),t[0]=a,t[1]=s,t[2]=c):c=t[2];let l=c,u;t[3]===o?u=t[4]:(u=o===`in_progress`?(0,A.jsx)(p,{name:`record-circle`,className:`h-3.5 w-3.5 text-[var(--status-info)]`,"aria-hidden":`true`}):o===`completed`?(0,A.jsx)(p,{name:`checkbox-circle`,className:`h-3.5 w-3.5 text-[var(--status-success)]`,"aria-hidden":`true`}):(0,A.jsx)(p,{name:`time`,className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":`true`}),t[3]=o,t[4]=u);let m=u,v=r?`step`:void 0,y=r&&`bg-[var(--surface-muted)] before:absolute before:inset-y-2 before:left-0 before:w-0.5 before:rounded-full before:bg-[var(--status-info)]`,b;t[5]===y?b=t[6]:(b=f(`group relative grid min-w-0 grid-cols-[1rem_minmax(0,1fr)] items-start gap-2.5`,I,y),t[5]=y,t[6]=b);let x;t[7]!==m||t[8]!==l?(x=(0,A.jsx)(h,{asChild:!0,children:(0,A.jsx)(`span`,{className:`flex size-4 items-center justify-center`,"aria-label":l,children:m})}),t[7]=m,t[8]=l,t[9]=x):x=t[9];let S;t[10]===l?S=t[11]:(S=(0,A.jsx)(g,{side:`left`,sideOffset:6,children:l}),t[10]=l,t[11]=S);let C;t[12]!==x||t[13]!==S?(C=(0,A.jsxs)(_,{children:[x,S]}),t[12]=x,t[13]=S,t[14]=C):C=t[14];let w=ue[o],T;t[15]===w?T=t[16]:(T=f(`block whitespace-normal break-words`,w),t[15]=w,t[16]=T);let E;t[17]!==T||t[18]!==n.content?(E=(0,A.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,A.jsx)(`span`,{className:T,children:n.content})}),t[17]=T,t[18]=n.content,t[19]=E):E=t[19];let D;return t[20]!==i||t[21]!==E||t[22]!==v||t[23]!==b||t[24]!==C?(D=(0,A.jsxs)(`li`,{ref:i,"aria-current":v,className:b,children:[C,E]}),t[20]=i,t[21]=E,t[22]=v,t[23]=b,t[24]=C,t[25]=D):D=t[25],D},z=new Set([`in_progress`,`pending`,`completed`,`cancelled`]),B=`image/png`,V=c(`OpenChamberMedia`),H=e=>{let t=e.toLowerCase().split(`;`)[0]?.trim()||B;if(t===`image/jpeg`||t===`image/jpg`)return`jpg`;if(t===`image/webp`)return`webp`;if(t===`image/gif`)return`gif`;if(t===`image/svg+xml`)return`svg`;if(t===`image/png`)return`png`;let n=t.split(`/`)[1];return n&&/^[a-z0-9.+-]+$/i.test(n)?n:`png`},U=(e,t)=>{let n=`image.${H(t)}`,r=(((e||``).trim()||n).split(/[\\/]/).pop()||n).replace(/[^\w.\- ()[\]]+/g,`_`).replace(/^\.+/,``);return r?/\.[a-z0-9]{1,8}$/i.test(r)?r:`${r}.${H(t)}`:n},W=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{if(typeof r.result==`string`){t(r.result);return}n(Error(`Failed to encode image`))},r.onerror=()=>n(r.error??Error(`Failed to encode image`)),r.readAsDataURL(e)}),de=async e=>{let t=await W(e),n=t.indexOf(`,`);return n>=0?t.slice(n+1):t},fe=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),document.body.removeChild(r),window.setTimeout(()=>URL.revokeObjectURL(n),1e3)},G=async(e,t)=>{let n=await fetch(e,{signal:t,cache:`no-store`});if(!n.ok)throw Error(`Image fetch failed (${n.status})`);return n.blob()},pe=async(e,t=B)=>{if(!e.naturalWidth||!e.naturalHeight)return null;let n=e.currentSrc||e.src;if(n&&(/^(?:blob:|data:|openchamber-asset:)/i.test(n)||/^https?:/i.test(n)||/^\/api(?=\/|[?#]|$)/.test(n)))try{let e=await G(n);if(e.size>0)return e}catch{}try{let n=document.createElement(`canvas`);n.width=e.naturalWidth,n.height=e.naturalHeight;let r=n.getContext(`2d`);if(!r)return null;r.drawImage(e,0,0);let i=t.startsWith(`image/`)?t:B,a=await new Promise(e=>{n.toBlob(t=>e(t),i===`image/jpg`?`image/jpeg`:i)});return a&&a.size>0?a:null}catch{return null}},me=async(e,t)=>{let n=``;try{return n=await S(e,t??new AbortController().signal),await G(n,t)}finally{n&&C(n)}},he=async(e,t)=>{let n=e.effectiveDirectory??``,i=null;e.prefetchedBlob&&e.prefetchedBlob.size>0&&(i=e.prefetchedBlob);let a=e.displayUrl?.trim();if(!i&&a)try{i=await G(a,t)}catch{i=null}if(!i){let a=e.sourceUrl.trim();if(!a)throw Error(`Image source is empty`);if(/^(?:data|blob):/i.test(a)||/^https?:/i.test(a)||/^\/api(?=\/|[?#]|$)/.test(a))i=await G(a,t);else{let e=y(a,n);if(x(e))try{i=await me(e.path,t)}catch{let n=await r(`/api/fs/raw`,{method:`GET`,cache:`no-store`,query:{path:e.path},signal:t});if(!n.ok)throw Error(`Image source request failed with status ${n.status}`);i=await n.blob()}else i=await G(e.source,t)}}if(!i||i.size<=0)throw Error(`Image is empty`);let o=(e.mimeType||(i.type&&i.type.startsWith(`image/`)?i.type:``)||B).split(`;`)[0].trim()||B;return{blob:i,filename:U(e.filename,o),mimeType:o}},ge=()=>!s()||l===void 0?!1:l.isPluginAvailable(`OpenChamberMedia`),_e=async(e,t)=>{let{blob:r,filename:a,mimeType:o}=await he(e,t);if(ge()){let e=await de(r);return await V.saveImage({dataBase64:e,mimeType:o,filename:a}),`saved`}if(n()){let e=i()?.vscode;if(e?.saveImage){let t=await W(r);return await e.saveImage({fileName:a,dataUrl:t}),`saved`}}return fe(r,a),`downloaded`},ve=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),ye=e=>e?Object.entries(e).map(([e,t])=>t==null?``:`${e.startsWith(`--`)?e:e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}:${typeof t==`number`?`${t}px`:t};`).join(``):``,K=(e,t,n)=>{let r=e.querySelector(`pre`);r&&(r.style.margin=`0`,r.style.background=`transparent`,r.style.whiteSpace=t?`pre-wrap`:`pre`,t&&(r.style.wordBreak=`break-word`,r.style.overflowWrap=`break-word`));let i=e.querySelector(`code`);if(i){let e=ye(n);e&&i.setAttribute(`style`,`${i.getAttribute(`style`)??``}${e}`)}},be=e=>`<pre><code>${ve(e)}</code></pre>`,xe=e=>{let t=(0,k.c)(21),{code:n,language:r,className:i,style:a,codeStyle:o,wrap:s}=e,c=s!==void 0&&s,{currentTheme:l}=v(),u=O.useRef(null),d;t[0]===l?d=t[1]:(d=b(l),t[0]=l,t[1]=d);let p=d,m,h;t[2]!==n||t[3]!==o||t[4]!==c?(m=()=>{let e=u.current;e&&(e.innerHTML=be(n),K(e,c,o))},h=[n,c,o],t[2]=n,t[3]=o,t[4]=c,t[5]=m,t[6]=h):(m=t[5],h=t[6]),O.useLayoutEffect(m,h);let g,_;t[7]!==n||t[8]!==o||t[9]!==r||t[10]!==c?(g=()=>{let e=u.current;if(!e)return;let t=!0,i=new AbortController;return ee(n,(r||`text`).toLowerCase(),{signal:i.signal,priority:`visible`}).then(n=>{!t||!e||!n||(e.innerHTML=n,K(e,c,o))}),()=>{t=!1,i.abort()}},_=[n,r,c,o],t[7]=n,t[8]=o,t[9]=r,t[10]=c,t[11]=g,t[12]=_):(g=t[11],_=t[12]),O.useEffect(g,_);let y;t[13]===i?y=t[14]:(y=f(`typography-code`,i),t[13]=i,t[14]=y);let x=p,S;t[15]!==a||t[16]!==x?(S={...x,...a},t[15]=a,t[16]=x,t[17]=S):S=t[17];let C;return t[18]!==y||t[19]!==S?(C=(0,A.jsx)(`div`,{ref:u,className:y,style:S}),t[18]=y,t[19]=S,t[20]=C):C=t[20],C},Se=e=>{let t=e.replace(/^<file>\s*\n?/,``).replace(/\n?<\/file>\s*$/,``);return t=t.replace(/^\s*\d{5}\|\s?/gm,``),t.trim()},Ce=(e,t=``)=>{if(typeof e==`string`)return e;if(e==null)return t;if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return String(e);try{return JSON.stringify(e)}catch{return t}},we=e=>e?e.includes(`<diagnostics`)||e.includes(`<file_diagnostics>`)||e.includes(`LSP errors detected`)||e.includes(`This file has errors`):!1,Te=e=>e?e.replace(/\n{0,2}LSP errors detected[\s\S]*?<diagnostics[^>]*>[\s\S]*?<\/diagnostics>/g,``).replace(/\n{0,2}This file has errors[\s\S]*?<\/file_diagnostics>/g,``).replace(/<diagnostics[^>]*>[\s\S]*?<\/diagnostics>/g,``).replace(/<file_diagnostics>[\s\S]*?<\/file_diagnostics>/g,``).trim():``,Ee=(e,t)=>!e||typeof e!=`object`?String(e):E(e,t||``),q=e=>{if(typeof e==`string`){let t=e.trim();return t.length>0?t:void 0}if(e&&typeof e==`object`){let t=e.patch;if(typeof t==`string`){let e=t.trim();return e.length>0?e:void 0}}},De=e=>{if(!e||typeof e!=`object`)return;let t=q(e.patch)??q(e.diff);if(t)return t;let n=Array.isArray(e.files)?e.files:[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=q(e.patch)??q(e.diff);if(t)return t}},Oe=e=>{if(!e||typeof e!=`string`)return{data:null,isJson:!1};let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`)||!t.endsWith(`}`)&&!t.endsWith(`]`)||t.length<2)return{data:null,isJson:!1};try{let e=JSON.parse(t);return typeof e==`object`&&e?{data:e,isJson:!0}:{data:null,isJson:!1}}catch{return{data:null,isJson:!1}}},ke=(e,t,n)=>{let r=Se(e);if((t===`edit`||t===`multiedit`||t===`write`||t===`apply_patch`)&&we(r)&&(r=Te(r)),(t===`edit`||t===`multiedit`||t===`apply_patch`)&&r.trim().length===0){let e=De(n);if(e)return e}return r},Ae=e=>{let t=e.match(/<type>(file|directory)<\/type>/i)?.[1]?.toLowerCase()??`unknown`,n=(e.match(/<content>([\s\S]*?)<\/content>/i)?.[1]??e).replace(/\r\n/g,`
|
|
2
2
|
`).split(`
|
|
3
3
|
`),r=e=>/\(\s*File has more lines\..*offset.*\)/i.test(e.trim());return{type:t,lines:n.map(e=>{let n=e.trim(),i=n.startsWith(`(`)&&n.endsWith(`)`)||r(n);if(t!==`directory`){let t=e.match(/^(\d+):\s?(.*)$/);if(t){let e=t[2],n=e.trim(),i=n.startsWith(`(`)&&n.endsWith(`)`)||r(n);return{lineNumber:i?null:Number(t[1]),text:e,isInfo:i}}}return{lineNumber:null,text:e,isInfo:i}}).filter((e,t,n)=>{if(e.text.trim().length>0)return!0;let r=n[t-1],i=n[t+1],a=!!(r?.isInfo||i?.isInfo),o=e.lineNumber!==null;return!(a&&o)})}},je=(e,n)=>{try{let r=e.trim().split(`
|
|
4
4
|
`).filter(Boolean);if(r.length===0)return null;let i=[];return r.forEach(e=>{let t=e.match(/^(\s*)(.+)$/);if(t){let[,e,n]=t,r=Math.floor(e.length/2),a=!n.endsWith(`/`);i.push({name:n.replace(/\/$/,``),depth:r,isFile:a})}}),(0,A.jsx)(`div`,{className:f(`w-full min-w-0 font-mono space-y-0.5`,n?.unstyled?null:`p-3 bg-muted/20 rounded-xl border border-border/30`),style:t.tool.popup,children:i.map((e,t)=>(0,A.jsx)(`div`,{className:`min-w-0`,style:{paddingLeft:`${e.depth*20}px`},children:e.isFile?(0,A.jsx)(`span`,{className:`text-foreground/90 block truncate`,children:e.name}):(0,A.jsxs)(`span`,{className:`font-semibold text-foreground block truncate`,children:[e.name,`/`]})},t))})}catch{return null}},Me={backgroundColor:`var(--status-info)`,opacity:.6},Ne=(e,n,r)=>{try{let i=e.trim().split(`
|
package/dist/index.html
CHANGED
|
@@ -552,7 +552,7 @@
|
|
|
552
552
|
opacity: 0.72;
|
|
553
553
|
}
|
|
554
554
|
</style>
|
|
555
|
-
<script type="module" crossorigin src="/assets/main-
|
|
555
|
+
<script type="module" crossorigin src="/assets/main-BqRvL_2H.js"></script>
|
|
556
556
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
557
557
|
<link rel="modulepreload" crossorigin href="/assets/vendor-base-ui-CnHfUmDN.js">
|
|
558
558
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-B4dlGEM2.js">
|
|
@@ -569,8 +569,8 @@
|
|
|
569
569
|
<link rel="modulepreload" crossorigin href="/assets/terminalApi-D2OzR0I3.js">
|
|
570
570
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
571
571
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
572
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
573
|
-
<link rel="stylesheet" crossorigin href="/assets/src-
|
|
572
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-CiXSoZmf.js">
|
|
573
|
+
<link rel="stylesheet" crossorigin href="/assets/src-CJXwqXhB.css">
|
|
574
574
|
</head>
|
|
575
575
|
<body class="h-full bg-background text-foreground">
|
|
576
576
|
<!-- Keep the startup layer outside #root. React replaces every child of
|
package/dist/mini-chat.html
CHANGED
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
}
|
|
75
75
|
</style>
|
|
76
76
|
|
|
77
|
-
<script type="module" crossorigin src="/assets/miniChat-
|
|
77
|
+
<script type="module" crossorigin src="/assets/miniChat-THt7sAU8.js"></script>
|
|
78
78
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
79
79
|
<link rel="modulepreload" crossorigin href="/assets/vendor-base-ui-CnHfUmDN.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-B4dlGEM2.js">
|
|
@@ -91,8 +91,8 @@
|
|
|
91
91
|
<link rel="modulepreload" crossorigin href="/assets/terminalApi-D2OzR0I3.js">
|
|
92
92
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
93
93
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
94
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
95
|
-
<link rel="stylesheet" crossorigin href="/assets/src-
|
|
94
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-CiXSoZmf.js">
|
|
95
|
+
<link rel="stylesheet" crossorigin href="/assets/src-CJXwqXhB.css">
|
|
96
96
|
</head>
|
|
97
97
|
<body class="h-full bg-background text-foreground">
|
|
98
98
|
<div id="root" class="h-full">
|
package/dist/mobile.html
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
})();
|
|
64
64
|
</script>
|
|
65
65
|
|
|
66
|
-
<script type="module" crossorigin src="/assets/mobile-
|
|
66
|
+
<script type="module" crossorigin src="/assets/mobile-B8X5spVS.js"></script>
|
|
67
67
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
68
68
|
<link rel="modulepreload" crossorigin href="/assets/vendor-base-ui-CnHfUmDN.js">
|
|
69
69
|
<link rel="modulepreload" crossorigin href="/assets/vendor-zustand-B4dlGEM2.js">
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/assets/terminalApi-D2OzR0I3.js">
|
|
81
81
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
82
82
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
83
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
84
|
-
<link rel="stylesheet" crossorigin href="/assets/src-
|
|
83
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-CiXSoZmf.js">
|
|
84
|
+
<link rel="stylesheet" crossorigin href="/assets/src-CJXwqXhB.css">
|
|
85
85
|
</head>
|
|
86
86
|
<body class="h-full bg-background text-foreground">
|
|
87
87
|
<div id="root" class="h-full"></div>
|
package/package.json
CHANGED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{A as t,E as n,b as r,t as i,y as a}from"./useUIStore-BXjMQrel.js";import{$t as o,D as s,d as c,k as l,ot as u,u as d,xn as f}from"./persistence-CLUawIlm.js";import{a as p,i as m,r as h}from"./vendor-zustand-B4dlGEM2.js";import{nt as g,rt as _}from"./vendor-base-ui-CnHfUmDN.js";import{B as v,Ct as y,M as b,Mt as x}from"./platform-BrncW9ab.js";import{n as S}from"./vendor-react-DLPElpoQ.js";import{s as C}from"./vendor-tanstack-react-query-D7pys_c9.js";import{n as ee}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as te}from"./clipboard-C0bgPFn5.js";import{_ as ne,an as re,b as ie,bo as w,ct as ae,fr as oe,ft as T,hn as E,l as D,lt as se,ot as O,pt as ce,ro as le,st as k,ta as ue,ut as de,yo as A}from"./useMobileNavigationStore-u51zoFzN.js";import{c as j,t as M}from"./utils-D94hxQYq.js";import{n as N,r as P,t as F}from"./Icon-Du1LX11Q.js";import{g as I,v as fe}from"./gitApi-pDTwL1DO.js";import{A as pe,X as me,p as he,s as ge}from"./projectMeta-B4xE5Xxg.js";var L=e(_(),1),R=S(),z=e=>{switch(e.name){case`new`:return`add`;case`init`:return`file`;case`undo`:return`arrow-go-back`;case`redo`:return`arrow-go-forward`;case`timeline`:return`time`;case`compact`:return`scissors`;case`goal`:return`target`;case`review`:return`search-eye`;case`test`:case`build`:case`run`:return`terminal-box`;default:return e.isBuiltIn?`flashlight`:`command`}},B=()=>`book-open`,_e=e=>{if(e.isDirectory)return`folder-3-fill`;switch(e.extension?.toLowerCase()){case`ts`:case`tsx`:case`js`:case`jsx`:case`json`:return`code`;case`md`:case`mdx`:return`file`;case`png`:case`jpg`:case`jpeg`:case`gif`:case`svg`:return`file-image`;default:return`file-pdf`}},V=()=>`ai-agent`,ve=()=>`chat-thread`,H=32,ye=(e,t)=>{let n=P[e];return typeof n!=`string`||n.length===0?null:`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${t}" stroke-width="${F}" stroke-linecap="round" stroke-linejoin="round">${n}</svg>`},be=(e,t)=>{let n=ye(e,t);return!n||typeof document>`u`?Promise.resolve(null):new Promise(e=>{let t=new Image;t.decoding=`async`,t.onload=()=>{try{let n=document.createElement(`canvas`);n.width=H,n.height=H;let r=n.getContext(`2d`);if(!r){e(null);return}r.clearRect(0,0,H,H),r.drawImage(t,0,0,H,H);let i=n.toDataURL(`image/png`),a=i.indexOf(`,`);e(a>=0?i.slice(a+1):null)}catch{e(null)}},t.onerror=()=>e(null),t.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`})},U=(e,t)=>e.map(e=>{let n=e.isSkill?t.skill:e.isOpenChamber?`OpenChamber`:e.isBuiltIn?t.system:e.scope||e.agent||t.command;return{id:e.id,title:`/${e.name}`,subtitle:e.description,badge:n,iconName:z(e)}}),xe=e=>e.map(e=>({id:`${e.name}-${e.scope}`,title:e.name,subtitle:e.description,badge:e.scope,iconName:B()})),Se=({agents:e,sessions:t,recentFiles:n,pathHits:r,untitledSession:i,sessionBadge:a})=>{let o=[];for(let t of e)o.push({id:`agent:${t.name}`,title:`@${t.name}`,subtitle:t.description,iconName:V()});for(let e of t)o.push({id:`session:${e.id}`,title:e.title||i,badge:a,iconName:ve()});for(let e of n)o.push({id:`recent:${e.path}`,title:e.relativePath||e.name,iconName:_e(e)});for(let e of r)o.push({id:`file:${e.path}`,title:e.relativePath||e.name,iconName:_e(e)});return o},Ce=(e,t)=>{let n=t.trim();if(!n)return[...e].sort((e,t)=>e.isBuiltIn===t.isBuiltIn?e.name.localeCompare(t.name):e.isBuiltIn?-1:1);let r=ce([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>e.score===t.score?e.item.isBuiltIn===t.item.isBuiltIn?e.item.name.localeCompare(t.item.name):e.item.isBuiltIn?-1:1:e.score-t.score),r.map(e=>e.item)},we=(e,t)=>{if(!e.includes(`/`)||t.size===0)return[];let n=RegExp(`(^|\\s)/(${u})?([A-Za-z0-9][A-Za-z0-9_-]*)(?=$|\\s)`,`g`),r=[],i;for(;(i=n.exec(e))!==null;){let e=i[3]??``;if(!t.has(e.toLowerCase()))continue;let n=i[2]??``,a=i.index+(i[1]?.length??0);r.push({start:a,end:a+1+n.length+e.length,name:e,hasSlot:n.length>0})}return r},W=(e,t,n=e.length)=>{let r=we(e,t).filter(e=>!e.hasSlot);if(r.length===0)return null;let i=e,a=n;for(let e=r.length-1;e>=0;--e){let t=r[e].start+1;i=`${i.slice(0,t)}${u}${i.slice(t)}`,a>t&&(a+=u.length)}return i===e?null:{text:i,caret:a}},G=e=>e.startsWith(u)?e.slice(u.length):e,K=e=>{if(e.inputMode===`shell`)return null;let t=e.text,n=Math.max(0,Math.min(e.cursor,t.length));if(t.startsWith(`/`)){let e=t.indexOf(` `),r=t.indexOf(`
|
|
2
|
-
`),i=Math.min(e===-1?t.length:e,r===-1?t.length:r);if(n<=i&&e===-1)return{kind:`slash-command`,query:G(t.substring(1,i)),tokenStart:0,tokenEnd:i}}let r=t.substring(0,n),i=r.lastIndexOf(`/`);if(i!==-1){let e=i>0?r[i-1]:null,t=G(r.substring(i+1)),a=t.includes(` `)||t.includes(`
|
|
3
|
-
`);if((!e||/\s/.test(e))&&!a)return{kind:`slash-skill`,query:t,tokenStart:i,tokenEnd:n}}let a=r.lastIndexOf(`#`);if(a!==-1){let e=a>0?r[a-1]:null,t=r.substring(a+1);if((!e||/\s/.test(e))&&!t.includes(` `)&&!t.includes(`
|
|
4
|
-
`))return{kind:`snippet`,query:t,tokenStart:a,tokenEnd:n}}let o=O({value:t,cursorPosition:n,inputSource:e.mentionInputSource??`manual`,insertedText:e.insertedText});return o===null?null:{kind:`mention`,query:o,tokenStart:r.lastIndexOf(`@`),tokenEnd:n}},q=e=>e===`mention`?`@`:e===`snippet`?`#`:`/`,Te=(e,t,n)=>{if(n&&n.tokenStart>=0&&n.tokenEnd>=n.tokenStart&&n.tokenEnd<=e.length&&e.startsWith(q(n.kind),n.tokenStart))return{start:n.tokenStart,end:n.tokenEnd};let r=K({text:e,cursor:t});return r?{start:r.tokenStart,end:r.tokenEnd}:null},Ee=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>{let r=t[n];return r!=null&&e.id===r.id&&e.title===r.title&&(e.subtitle??``)===(r.subtitle??``)&&(e.badge??``)===(r.badge??``)&&e.iconName===r.iconName}),De=(e,t)=>e.highlightedIndex===t.highlightedIndex&&Ee(e.rows,t.rows),Oe=(e,t)=>Ee(e,t)?e:t.slice(),ke=(e,t,n)=>{e&&(t.current&&De(t.current,n)||(t.current=n,e(n)))},Ae=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},J=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+/g,`/`);n&&!r.startsWith(`//`)&&(r=`/${r}`);let i=r===`/`,a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,``)),r},Y=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,X=(e,t)=>{let n=J(t),r=J(e);if(!n||!r)return!1;let i=Y(n),a=Y(r);return a===i||a.startsWith(`${i}/`)},je=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=J(e);if(!t||!r||typeof r!=`object`)continue;let i=r,a=Array.isArray(i.openPaths)?Array.from(new Set(i.openPaths.filter(e=>typeof e==`string`).map(e=>J(e)).filter(e=>X(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>J(e)).filter(e=>X(e,t)))):[],s=typeof i.selectedPath==`string`?J(i.selectedPath):null,c=s&&X(s,t)?s:a[0]??null,l=typeof i.touchedAt==`number`&&Number.isFinite(i.touchedAt)?i.touchedAt:Date.now(),u=n[t];if(u){let e=Array.from(new Set([...u.openPaths,...a])),r=Array.from(new Set([...u.expandedPaths,...o]));n[t]={openPaths:e,selectedPath:u.selectedPath??c??e[0]??null,expandedPaths:r,touchedAt:Math.max(u.touchedAt,l)};continue}n[t]={openPaths:a,selectedPath:c,expandedPaths:o,touchedAt:l}}return n},Me=(e,t)=>{let n=Object.entries(e);if(n.length<=t)return e;n.sort((e,t)=>(t[1]?.touchedAt??0)-(e[1]?.touchedAt??0));let r={};for(let[e,i]of n.slice(0,t))r[e]=i;return r},Ne=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},Pe=p()(h(m((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=J((t||``).trim()),a=J((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!X(a,i)||e(e=>{let t=e.byRoot[i],n=Ne(t),r=n.openPaths.includes(a),o=r?n.openPaths:[...n.openPaths,a],s=n.selectedPath??a;return t&&r&&t.selectedPath===s?e:{byRoot:Me({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=J((t||``).trim()),i=J((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=Y(i),a=e=>Y(e)===n,o=t.selectedPath?a(t.selectedPath):!1;if(!t.openPaths.some(a)&&!o)return e;let s=t.openPaths.filter(e=>!a(e)),c=o?s[0]??null:t.selectedPath;return{byRoot:Me({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=J((t||``).trim()),i=J((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=Y(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=Y(e);return t===n||t.startsWith(a)},s=t.openPaths.filter(e=>!o(e));if(s.length===t.openPaths.length)return e;let c=t.selectedPath&&o(t.selectedPath)?s[0]??null:t.selectedPath;return{byRoot:Me({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=J((t||``).trim()),i=J((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=Y(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=Y(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:Me({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=J((t||``).trim()),a=n?J(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!X(a,i)||e(e=>{let t=e.byRoot[i],n=Ne(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:Me({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=J((e||``).trim());if(!n)return;let r=t().byRoot[n];if(!r||r.selectedPath)return;let i=r.openPaths[0]??null;i&&t().setSelectedPath(n,i)},toggleExpandedPath:(t,n)=>{let r=J((t||``).trim()),i=J((n||``).trim());!r||!i||!X(i,r)||e(e=>{let t=e.byRoot[r],n=Ne(t),a=n.expandedPaths.includes(i)?n.expandedPaths.filter(e=>e!==i):[...n.expandedPaths,i];return t&&t.expandedPaths===a&&t.selectedPath===n.selectedPath&&t.openPaths===n.openPaths?e:{byRoot:Me({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=J((t||``).trim()),i=J((n||``).trim());!r||!i||!X(i,r)||e(e=>{let t=e.byRoot[r],n=Ne(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:Me({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=J((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>J((e||``).trim())).filter(e=>e&&X(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=Ne(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:Me({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:a(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:je(t)}},partialize:e=>({byRoot:je(e.byRoot)})}),{name:`files-view-tabs-store`})),Fe=(e,t)=>{let n=(0,R.c)(4),r=t===void 0?200:t,[i,a]=L.useState(e),o,s;return n[0]!==r||n[1]!==e?(o=()=>{let t=window.setTimeout(()=>{a(e)},r);return()=>{window.clearTimeout(t)}},s=[e,r],n[0]=r,n[1]=e,n[2]=o,n[3]=s):(o=n[2],s=n[3]),L.useEffect(o,s),i},Ie=()=>{let e=(0,R.c)(17),t=D(Le),n=E(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=ie(r),a=D(Re),o=D(ze),s=w(Be),c=w(Ve),l=y(He);if(t){let r;e[2]===i?r=e[3]:(r=ne(i),e[2]=i,e[3]=r);let o=r;if(o)return o;let s;e[4]!==t||e[5]!==a?(s=a.get(t),e[4]=t,e[5]=a,e[6]=s):s=e[6];let c=s;if(c?.path)return c.path;let l;if(e[7]!==t||e[8]!==n){let r;e[10]===t?r=e[11]:(r=e=>e.id===t,e[10]=t,e[11]=r),l=n.find(r),e[7]=t,e[8]=n,e[9]=l}else l=e[9];let u=l;if(u?.directory)return u.directory}if(o?.open&&(o.bootstrapPendingDirectory||o.directoryOverride))return(o.bootstrapPendingDirectory||o.directoryOverride)??void 0;if(s){let t;if(e[12]!==s||e[13]!==c){let n;e[15]===s?n=e[16]:(n=e=>e.id===s,e[15]=s,e[16]=n),t=c.find(n),e[12]=s,e[13]=c,e[14]=t}else t=e[14];let n=t;if(n?.path)return n.path}return l??void 0};function Le(e){return e.currentSessionId}function Re(e){return e.worktreeMetadata}function ze(e){return e.newSessionDraft}function Be(e){return e.activeProjectId}function Ve(e){return e.projects}function He(e){return e.currentDirectory}var Ue=.4,We=8,Ge=e=>{let t=e.gap??We,n=Math.max(0,e.popupBottom-e.boundaryTop-t),r=e.viewportHeight*Ue,i=Math.floor(Math.min(n,r));return n>=120?Math.min(n,Math.max(120,i)):i},Ke=(e,t=0)=>{let n=e.closest(`main`);if(!n)return null;let r=(e.closest(`.mobile-chat-screen__content`)?.parentElement??n.parentElement?.closest(`main`)??n).querySelector(`:scope > .oc-mobile-detail-navigation`)?.getBoundingClientRect().bottom,i=n.getBoundingClientRect().top;return Math.max(r===void 0?i:Math.max(r,i),t)},qe=(e,t)=>{let n=(0,R.c)(3),[r,i]=L.useState(void 0),a;return n[0]!==e||n[1]!==t?(a=()=>{if(!t)return;let n=()=>{let t=e.current;if(!t)return;let n=window.visualViewport,r=Ke(t,n?.offsetTop??0);if(r===null)return;let a=n?.height??window.innerHeight,o=Ge({popupBottom:t.getBoundingClientRect().bottom,boundaryTop:r,viewportHeight:a});i(e=>e===o?e:o)};return n(),window.addEventListener(`resize`,n),window.addEventListener(`oc:keyboard-settled`,n),window.visualViewport?.addEventListener(`resize`,n),window.visualViewport?.addEventListener(`scroll`,n),()=>{window.removeEventListener(`resize`,n),window.removeEventListener(`oc:keyboard-settled`,n),window.visualViewport?.removeEventListener(`resize`,n),window.visualViewport?.removeEventListener(`scroll`,n)}},n[0]=e,n[1]=t,n[2]=a):a=n[2],L.useLayoutEffect(a),t?r:void 0},Je=`absolute z-[100] min-w-0 w-full bottom-full mb-2 left-0 flex flex-col rounded-xl`;function Ye(e,t){return M(Je,e?`oc-composer-autocomplete-surface`:`bg-background border-2 border-border/60 shadow-none`,t)}function Xe(e,t){return e?`oc-composer-autocomplete-row`:t?`bg-interactive-selection`:void 0}var Ze=()=>{let e=null,t=!1,n=!1;return{pointerDown:(n,r)=>{e={x:n,y:r},t=!1},pointerMove:(n,r)=>{e&&Math.hypot(n-e.x,r-e.y)>6&&(t=!0)},pointerCancel:()=>{e=null,t=!1},pointerUp:r=>{if(!e)return!1;let i=!t;return e=null,t=!1,i?(n=!0,r(),!0):(n=!0,!1)},click:e=>n?(n=!1,!1):(e(),!0)}},Z=g(),Qe=L.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSessionSelect:r,onClose:a,style:o,onRowsChange:c},u)=>{let{t:d}=te(),f=Ie()??``,p=D(e=>e.currentSessionId),m=oe(e=>e.activeSessions),h=w(e=>e.activeProjectId),g=w(e=>e.projects),_=L.useMemo(()=>g.find(e=>e.id===h)?.path??null,[h,g]),v=L.useMemo(()=>{let e=_||f;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[_,f]),y=Pe(e=>v?e.byRoot[v]:void 0),b=ue(e=>e.getVisibleAgents),S=x(e=>e.searchFiles),C=Fe(e,180),ne=l(),re=s(),[ie,E]=L.useState([]),[O,ce]=L.useState([]),[le,A]=L.useState(!1),[P,F]=L.useState(0),I=L.useRef(0),[fe,me]=L.useState(360),[he,ge]=L.useState({}),[R,z]=L.useState({}),B=L.useRef([]),V=L.useRef([]),ve=L.useRef([]),H=L.useRef(null),ye=L.useRef(null),be=L.useRef(null);be.current||=Ze();let U=i(e=>e.isMobile),xe=qe(H,U),Ce=(e??``).trim(),we=L.useMemo(()=>{if(!v||!y)return[];let e=[y.selectedPath,...y.openPaths.slice().reverse()].filter(e=>typeof e==`string`&&e.length>0),t=new Set,n=[];for(let r of e){if(t.has(r))continue;t.add(r);let e=r.replace(/\\/g,`/`),i=e.split(`/`).filter(Boolean).pop()||e,a=e.startsWith(`${v}/`)?e.slice(v.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return de(n,Ce,{limit:6})},[Ce,v,y]),W=L.useMemo(()=>Ce.length>0?O:O.slice(0,2),[O,Ce.length]),G=L.useMemo(()=>r?k({sessions:m,currentSessionId:p,searchQuery:Ce}):[],[m,p,Ce,r]),K=we,q=ie;L.useEffect(()=>{let e=e=>{let t=e.target;!t||!H.current||H.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),L.useEffect(()=>{if(!f){E([]);return}let e=(C??``).trim(),t=T(e);if(!t){E([]);return}let n=!1;A(!0);let r={includeHidden:ne,respectGitignore:!re};return Promise.all([S(f,t,80,{...r,type:`file`}),S(f,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(we.map(e=>e.path));E(ae({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{n||E([])}).finally(()=>{n||A(!1)}),()=>{n=!0}},[f,C,we,S,ne,re]),L.useEffect(()=>{let t=b().filter(e=>e.mode&&e.mode!==`primary`).map(e=>({name:e.name,description:e.description,mode:e.mode}));ce(se(t,e??``))},[b,e]),L.useEffect(()=>{F(0),ge({}),z({})},[q,K.length,W.length,G.length]),L.useEffect(()=>{I.current=P},[P]),L.useEffect(()=>{B.current[P]?.scrollIntoView({block:`nearest`})},[P]),L.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};V.current.forEach((n,r)=>{if(!n)return;let i=ve.current[r]?.offsetWidth??n.scrollWidth,a=Math.max(0,i-n.clientWidth),o=a>8;if(e[r]=o,o){let e=Math.max(.6,a/110);t[r]=e}}),ge(e),z(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[q,K]),L.useEffect(()=>{let e=V.current[P];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&me(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[P]);let Te=ee(e=>{t(e)}),Ee=ee(e=>{n?.(e)}),De=ee(e=>{r?.(e)}),Oe=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&be.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&be.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(be.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>be.current?.pointerCancel(),onClick:()=>{be.current?.click(t)},onMouseMove:()=>F(e)}),J=e=>{let t=W.length+G.length+K.length+q.length;if(t===0)return;let n=(e%t+t)%t;if(n<W.length){let e=W[n];e&&Ee(e.name);return}let r=n-W.length;if(r<G.length){let e=G[r];e&&De(e);return}let i=r-G.length,a=i<K.length?K[i]:q[i-K.length];a&&Te(a)};L.useEffect(()=>{ke(c,ye,{rows:Se({agents:W,sessions:G,recentFiles:K,pathHits:q,untitledSession:d(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:d(`chat.fileMentionAutocomplete.sessionType`)}),highlightedIndex:P})},[c,P,d,W,q,K,G]);let Y=L.useRef(c);Y.current=c,L.useEffect(()=>()=>{Ae(Y.current,ye)},[]),L.useImperativeHandle(u,()=>({acceptIndex:e=>{J(e)},handleKeyDown:e=>{if(e===`Escape`){a();return}let t=W.length+G.length+K.length+q.length;if(t!==0){if(e===`ArrowDown`){F(e=>(e+1)%t);return}if(e===`ArrowUp`){F(e=>(e-1+t)%t);return}(e===`Enter`||e===`Tab`)&&J(I.current)}}}),[q,K,W,G,a,Te,Ee,De]);let X=e=>(0,Z.jsx)(N,{name:_e(e),className:`h-3.5 w-3.5 text-current`});return(0,Z.jsxs)(`div`,{ref:H,className:Ye(U,`max-w-[640px] max-h-64`),style:xe===void 0?o:{...o,maxHeight:xe},children:[(0,Z.jsx)(pe,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,Z.jsxs)(`div`,{className:`pb-2`,children:[W.length>0&&(0,Z.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.agents`)}),W.map((e,t)=>{let n=P===t;return(0,Z.jsx)(`div`,{ref:e=>{B.current[t]=e},className:M(`flex items-start gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,Xe(U,n),!U&&n&&`text-interactive-selection-foreground`),...Oe(t,()=>Ee(e.name)),children:(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`font-semibold truncate`,children:[`@`,e.name]}),e.description&&!U?(0,Z.jsx)(`div`,{className:`typography-meta text-muted-foreground truncate`,children:e.description}):null]})},`agent-${e.name}`)}),W.length===2&&Ce.length===0&&O.length>2&&(0,Z.jsx)(`div`,{className:`px-3 py-1 typography-meta text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.searchMoreAgents`)}),G.length>0&&(0,Z.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.sessions`)}),G.map((e,t)=>{let n=W.length+t,r=P===n;return(0,Z.jsxs)(`div`,{ref:e=>{B.current[n]=e},className:M(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,Xe(U,r),!U&&r&&`text-interactive-selection-foreground`),...Oe(n,()=>De(e)),children:[(0,Z.jsx)(N,{name:`chat-thread`,className:`h-4 w-4 flex-shrink-0 text-[var(--primary-base)]`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.title||d(`chat.fileMentionAutocomplete.untitledSession`),children:e.title||d(`chat.fileMentionAutocomplete.untitledSession`)}),U?null:(0,Z.jsx)(`span`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.sessionType`)})]},`session-${e.id}`)}),K.length>0&&(0,Z.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.recentFiles`)}),K.map((e,t)=>{let n=W.length+G.length+t,r=e.relativePath||e.name,i=j(r,{maxLength:60}),a=P===n,o=he[n]??!1,s=R[n]??2.6;return(0,Z.jsxs)(`div`,{ref:e=>{B.current[n]=e},className:M(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,Xe(U,a),!U&&a&&`text-interactive-selection-foreground`),...Oe(n,()=>Te(e)),children:[X(e),(0,Z.jsxs)(`span`,{ref:e=>{V.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${fe}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,Z.jsx)(`span`,{ref:e=>{ve.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,Z.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:r}):(0,Z.jsx)(`span`,{className:`block truncate`,children:i})]})]},`recent-${e.path}`)}),q.length>0&&(0,Z.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.files`)}),q.map((e,t)=>{let n=W.length+G.length+K.length+t,r=e.relativePath||e.name,i=j(r,{maxLength:60}),a=P===n,o=he[n]??!1,s=R[n]??2.6;return(0,Z.jsxs)(`div`,{ref:e=>{B.current[n]=e},className:M(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,Xe(U,a),!U&&a&&`text-interactive-selection-foreground`),...Oe(n,()=>Te(e)),children:[X(e),(0,Z.jsxs)(`span`,{ref:e=>{V.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${fe}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,Z.jsx)(`span`,{ref:e=>{ve.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,Z.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:r}):(0,Z.jsx)(`span`,{className:`block truncate`,children:i})]})]},e.path)}),le&&q.length===0?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,Z.jsx)(N,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!le&&q.length===0&&K.length===0&&W.length===0&&G.length===0&&(0,Z.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.empty`)})]})}),!U&&(0,Z.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:d(`chat.autocomplete.keyboardHint`)})]})}),$e=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`model`,`goal`]),et=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&$e.has(n))},tt=(e,t)=>!e||t({name:e}),nt=` `,rt=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=n;for(;r>0&&!/\s/.test(e[r-1]);)--r;return r>=2&&e[r-1]===nt&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},it=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,at=M(it,`bg-[color-mix(in_srgb,var(--primary-base)_12%,transparent)] text-[color-mix(in_srgb,var(--primary-base)_70%,transparent)] border-[color-mix(in_srgb,var(--primary-base)_24%,transparent)]`),ot=M(it,`bg-[color-mix(in_srgb,var(--status-success)_12%,transparent)] text-[color-mix(in_srgb,var(--status-success)_70%,transparent)] border-[color-mix(in_srgb,var(--status-success)_24%,transparent)]`),st=M(it,`bg-[color-mix(in_srgb,var(--status-info)_12%,transparent)] text-[color-mix(in_srgb,var(--status-info)_70%,transparent)] border-[color-mix(in_srgb,var(--status-info)_24%,transparent)]`),ct=M(it,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),lt=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id),ut=(e,t)=>{let n=!!e.sessionID;return{hasSession:n,canStartSessionCommand:n||e.hasNewDraft,canUseReviewHandoffFlow:n&&!t&&!o()}},dt=L.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:r,style:a,commandPolicy:o,commandContext:s,onRowsChange:c},l)=>{let{t:u}=te(),d=i(e=>e.isMobile),f=D(e=>e.currentSessionId),p=D(e=>!!e.newSessionDraft?.open),m=D(L.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=re(f??``,m??void 0),g=L.useMemo(()=>s??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[s,f,h.length,p]),{hasSession:_,canStartSessionCommand:v,canUseReviewHandoffFlow:y}=L.useMemo(()=>ut(g,d),[g,d]),b=g.hasMessages,[x,S]=L.useState([]),[C,ee]=L.useState(!1),ne=A({directory:r}),ie=L.useMemo(()=>ne.data??[],[ne.data]),w=ne.isFetching,ae=le({directory:r}),oe=L.useMemo(()=>ae.data??[],[ae.data]),[T,E]=L.useState(0),se=L.useRef(0),O=L.useRef(!1),ce=L.useRef([]),k=L.useRef(null),ue=qe(k,d),de=L.useRef(!1),j=L.useRef(null),P=L.useRef(!1),F=L.useRef(null);L.useEffect(()=>{let e=e=>{let t=e.target;!t||!k.current||k.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),L.useEffect(()=>{(async()=>{ee(w);try{let t=ie.map((e,t)=>({id:`opencode:${e.scope??`global`}:${e.name}:${e.agent??``}:${e.model??``}:${t}`,name:e.name,source:`opencode`,description:e.description,agent:e.agent??void 0,model:e.model??void 0,isBuiltIn:e.isBuiltIn,isSkill:e.source===`skill`,scope:e.scope,reference:e.reference})),n=oe.map((e,t)=>({id:`skill:${e.scope}:${e.source??`opencode`}:${e.name}:${t}`,name:e.name,source:`skill`,description:e.description,isSkill:!0,scope:e.scope})),r=[{id:`openchamber:new`,name:`new`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!b?[{id:`openchamber:init`,name:`init`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:undo`,name:`undo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`openchamber:redo`,name:`redo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`openchamber:fork`,name:`fork`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`openchamber:timeline`,name:`timeline`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`openchamber:model`,name:`model`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`openchamber:compact`,name:`compact`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},..._?[{id:`openchamber:summary`,name:`summary`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:workspace-review`,name:`workspace-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isOpenChamber:!0}]:[],...y?[{id:`openchamber:handoff-review`,name:`handoff-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:craft-goal`,name:`craft-goal`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:goal`,name:`goal`,source:`openchamber`,description:u(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],...v?[{id:`openchamber:catch-up`,name:`catch-up`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:debug`,name:`debug`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.debugDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:weigh`,name:`weigh`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.weighDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:explore`,name:`explore`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isOpenChamber:!0}]:[],...t,...n],i=!b,a=Ce(r.filter(e=>(i||e.name!==`init`)&&(o?.(e)??!0)),e);S(e=>lt(e,a)?e:a)}catch{let t=!b,n=Ce([{id:`openchamber:new`,name:`new`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!b?[{id:`openchamber:init`,name:`init`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:undo`,name:`undo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`openchamber:redo`,name:`redo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`openchamber:fork`,name:`fork`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`openchamber:timeline`,name:`timeline`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`openchamber:model`,name:`model`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`openchamber:compact`,name:`compact`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},..._?[{id:`openchamber:summary`,name:`summary`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:workspace-review`,name:`workspace-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isOpenChamber:!0}]:[],...y?[{id:`openchamber:handoff-review`,name:`handoff-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:craft-goal`,name:`craft-goal`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:goal`,name:`goal`,source:`openchamber`,description:u(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],...v?[{id:`openchamber:catch-up`,name:`catch-up`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:debug`,name:`debug`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.debugDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:weigh`,name:`weigh`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.weighDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:explore`,name:`explore`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isOpenChamber:!0}]:[]].filter(e=>(t||e.name!==`init`)&&(o?.(e)??!0)),e);S(e=>lt(e,n)?e:n)}finally{ee(!1)}})()},[e,b,_,v,y,ie,w,oe,u,o]),L.useEffect(()=>{E(0)},[x]),L.useEffect(()=>{se.current=T},[T]),L.useEffect(()=>{ce.current[T]?.scrollIntoView({block:`nearest`})},[T]),L.useEffect(()=>{ke(c,F,{rows:U(x,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:T})},[x,c,T,u]);let I=L.useRef(c);I.current=c,L.useEffect(()=>()=>{Ae(I.current,F)},[]),L.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=x[e];r&&t(r,et(r,n))},handleKeyDown:e=>{let r=x.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){O.current=!0,E(e=>(e+1)%r);return}if(e===`ArrowUp`){O.current=!0,E(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(se.current%r+r)%r,i=x[n];i&&t(i,et(i,e===`Enter`))}}}}),[x,n,t]);let fe=e=>{let t=z(e);switch(e.name){case`new`:return(0,Z.jsx)(N,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,Z.jsx)(N,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,Z.jsx)(N,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,Z.jsx)(N,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:return(0,Z.jsx)(N,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,Z.jsx)(N,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,Z.jsx)(N,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,Z.jsx)(N,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,Z.jsx)(N,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,Z.jsx)(N,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,Z.jsx)(N,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,Z.jsxs)(`div`,{ref:k,className:Ye(d,`max-w-[450px] max-h-64`),style:ue===void 0?a:{...a,maxHeight:ue},children:[(0,Z.jsx)(pe,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 pb-2`,children:C?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,Z.jsx)(N,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,Z.jsxs)(`div`,{children:[x.map((e,n)=>{let r=e.isBuiltIn,i=e.isOpenChamber;return(0,Z.jsxs)(`div`,{ref:e=>{ce.current[n]=e},className:M(`flex gap-2 px-3 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,Xe(d,n===T)),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(j.current={x:e.clientX,y:e.clientY},P.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!j.current)return;let t=e.clientX-j.current.x,n=e.clientY-j.current.y;Math.hypot(t,n)>6&&(P.current=!0)},onPointerUp:n=>{if(n.pointerType!==`touch`)return;let r=P.current;j.current=null,P.current=!1,!r&&(n.preventDefault(),n.stopPropagation(),de.current=!0,t(e,et(e,d)))},onPointerCancel:()=>{j.current=null,P.current=!1},onClick:()=>{if(de.current){de.current=!1;return}t(e,et(e,d))},onMouseMove:()=>{O.current=!1,E(n)},children:[(0,Z.jsx)(`div`,{className:M(!d&&`mt-0.5`),children:fe(e)}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,e.name]}),e.isSkill?(0,Z.jsx)(`span`,{className:at,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,Z.jsx)(`span`,{className:at,children:u(`chat.commandAutocomplete.badge.command`)}),i?(0,Z.jsx)(`span`,{className:ct,children:`OpenChamber`}):r?(0,Z.jsx)(`span`,{className:ct,children:u(`chat.commandAutocomplete.badge.system`)}):e.scope?(0,Z.jsx)(`span`,{className:e.scope===`project`?st:ot,children:e.scope}):null,e.agent&&(0,Z.jsx)(`span`,{className:ct,children:e.agent})]}),e.description&&!d&&(0,Z.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:e.description})]})]},e.id)}),x.length===0&&(0,Z.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,Z.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});dt.displayName=`CommandAutocomplete`;function ft(e){return(e.description||e.content).replace(/\s+/g,` `).trim().slice(0,120)}var pt=L.forwardRef((e,t)=>{let n=(0,R.c)(67),{searchQuery:r,onSnippetSelect:a,onClose:o,style:s}=e,{t:c}=te(),l=L.useRef(null),u=i(mt),d=qe(l,u),[f,p]=L.useState(0),m=L.useRef(0),h;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=[],n[0]=h):h=n[0];let[g,_]=L.useState(h),v;n[1]===Symbol.for(`react.memo_cache_sentinel`)?(v=[],n[1]=v):v=n[1];let y=L.useRef(v),b=me(ht),x=me(gt),S=me(_t),C=me(vt),ee=i(yt),ne=i(bt),re,ie;n[2]===x?(re=n[3],ie=n[4]):(re=()=>{x()},ie=[x],n[2]=x,n[3]=re,n[4]=ie),L.useEffect(re,ie);let w,ae;n[5]!==r||n[6]!==b?(w=()=>{let e=r.trim();if(!e.length){let e=[...b].sort(xt);_(e),p(+!!e.length);return}let t=ce(b,e,St);t.sort(Ct);let n=t.map(wt);_(n),p(+!!n.length)},ae=[r,b],n[5]=r,n[6]=b,n[7]=w,n[8]=ae):(w=n[7],ae=n[8]),L.useEffect(w,ae);let oe,T;n[9]===f?(oe=n[10],T=n[11]):(oe=()=>{m.current=f,y.current[f]?.scrollIntoView({block:`nearest`})},T=[f],n[9]=f,n[10]=oe,n[11]=T),L.useEffect(oe,T);let E,D;n[12]===o?(E=n[13],D=n[14]):(D=()=>{let e=e=>{let t=e.target;t&&l.current&&!l.current.contains(t)&&o()};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},E=[o],n[12]=o,n[13]=E,n[14]=D),L.useEffect(D,E);let se;n[15]!==a||n[16]!==r?(se=e=>{let t=r.trim(),n=e.aliases.includes(t)?t:e.name;a(e,n)},n[15]=a,n[16]=r,n[17]=se):se=n[17];let O=se,le;n[18]!==o||n[19]!==C||n[20]!==ee||n[21]!==ne||n[22]!==S||n[23]!==b?(le=()=>{let e=new Set(b.map(Tt)),t=`new-snippet`,n=1;for(;e.has(t);)t=`new-snippet-${n++}`;S({name:t,scope:`global`}),C(t),ne(`snippets`),ee(!0),o()},n[18]=o,n[19]=C,n[20]=ee,n[21]=ne,n[22]=S,n[23]=b,n[24]=le):le=n[24];let k=le,ue,de;n[25]!==O||n[26]!==g||n[27]!==o||n[28]!==k?(ue=()=>({handleKeyDown:e=>{if(e===`Escape`){o();return}let t=g.length+1;if(e===`ArrowDown`){p(e=>(e+1)%t);return}if(e===`ArrowUp`){p(e=>(e-1+t)%t);return}if(e===`Enter`||e===`Tab`){if(m.current===0){k();return}let e=g[m.current-1];e&&O(e)}}}),de=[O,g,o,k],n[25]=O,n[26]=g,n[27]=o,n[28]=k,n[29]=ue,n[30]=de):(ue=n[29],de=n[30]),L.useImperativeHandle(t,ue,de);let A;n[31]===u?A=n[32]:(A=Ye(u,`max-w-[450px] max-h-60`),n[31]=u,n[32]=A);let j;n[33]!==d||n[34]!==s?(j=d===void 0?s:{...s,maxHeight:d},n[33]=d,n[34]=s,n[35]=j):j=n[35];let P;n[36]===Symbol.for(`react.memo_cache_sentinel`)?(P=e=>{y.current[0]=e},n[36]=P):P=n[36];let F;n[37]!==u||n[38]!==f?(F=M(`flex items-center gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,Xe(u,f===0)),n[37]=u,n[38]=f,n[39]=F):F=n[39];let I,fe;n[40]===Symbol.for(`react.memo_cache_sentinel`)?(I=()=>p(0),fe=(0,Z.jsx)(N,{name:`add`,className:`h-3.5 w-3.5 text-muted-foreground`}),n[40]=I,n[41]=fe):(I=n[40],fe=n[41]);let he;n[42]===c?he=n[43]:(he=c(`chat.snippetAutocomplete.action.addNew`),n[42]=c,n[43]=he);let ge;n[44]===he?ge=n[45]:(ge=(0,Z.jsx)(`span`,{className:`font-medium text-foreground`,children:he}),n[44]=he,n[45]=ge);let z;n[46]!==k||n[47]!==F||n[48]!==ge?(z=(0,Z.jsxs)(`div`,{ref:P,className:F,onClick:k,onMouseMove:I,children:[fe,ge]}),n[46]=k,n[47]=F,n[48]=ge,n[49]=z):z=n[49];let B;n[50]!==O||n[51]!==g||n[52]!==u||n[53]!==f||n[54]!==c?(B=g.length?g.map((e,t)=>(0,Z.jsx)(`div`,{ref:e=>{y.current[t+1]=e},className:M(`flex gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,u?`items-center`:`items-start`,Xe(u,t+1===f)),onClick:()=>O(e),onMouseMove:()=>p(t+1),children:(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(`span`,{className:`font-semibold truncate`,children:[`#`,e.name]}),(0,Z.jsx)(`span`,{className:`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0 bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`,children:c(`snippets.source.${e.source}`)})]}),!u&&(0,Z.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:ft(e)})]})},`${e.source}:${e.filePath}`)):(0,Z.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:c(`chat.snippetAutocomplete.empty`)}),n[50]=O,n[51]=g,n[52]=u,n[53]=f,n[54]=c,n[55]=B):B=n[55];let _e;n[56]!==z||n[57]!==B?(_e=(0,Z.jsxs)(pe,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 pb-2`,children:[z,B]}),n[56]=z,n[57]=B,n[58]=_e):_e=n[58];let V;n[59]!==u||n[60]!==c?(V=!u&&(0,Z.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:c(`chat.snippetAutocomplete.footer`)}),n[59]=u,n[60]=c,n[61]=V):V=n[61];let ve;return n[62]!==A||n[63]!==j||n[64]!==_e||n[65]!==V?(ve=(0,Z.jsxs)(`div`,{ref:l,className:A,style:j,children:[_e,V]}),n[62]=A,n[63]=j,n[64]=_e,n[65]=V,n[66]=ve):ve=n[66],ve});pt.displayName=`SnippetAutocomplete`;function mt(e){return e.isMobile}function ht(e){return e.snippets}function gt(e){return e.loadSnippets}function _t(e){return e.setSnippetDraft}function vt(e){return e.setSelectedSnippet}function yt(e){return e.setSettingsDialogOpen}function bt(e){return e.setSettingsPage}function xt(e,t){return e.source===`project`&&t.source!==`project`?-1:e.source!==`project`&&t.source===`project`?1:e.name.localeCompare(t.name)}function St(e){return[e.name,...e.aliases]}function Ct(e,t){return e.score===t.score?e.item.source===`project`&&t.item.source!==`project`?-1:e.item.source!==`project`&&t.item.source===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score}function wt(e){return e.item}function Tt(e){return e.name}var Et=2,Dt=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Ot=e=>{let t=e?.trim().replace(/\\/g,`/`);return t?t.length>1?t.replace(/\/+$/,``):t:null},kt=e=>Dt(e)&&Array.isArray(e.all)&&e.all.every(e=>typeof e==`string`)&&typeof e.current==`string`&&Dt(e.branches),At=(e,t)=>JSON.stringify([e,t]),jt=e=>`version`in e&&e.version===Et&&Dt(e.entries),Mt=e=>{if(!e)return null;try{let t=JSON.parse(e);return Dt(t)?t.version===Et&&Dt(t.entries)?{version:Et,entries:t.entries}:t:null}catch{return null}},Nt=(e,t)=>{try{e.setItem(`oc.gitBranchCache`,JSON.stringify(t))}catch{}},Pt=(e,t,n)=>{let r=Ot(e);if(!r||!t)return null;let i;try{i=n.getItem(`oc.gitBranchCache`)}catch{return null}let a=Mt(i);if(!a)return null;if(jt(a))return kt(a.entries[At(t,r)])?a.entries[At(t,r)]:null;let o={};for(let[e,n]of Object.entries(a)){let r=Ot(e);r&&kt(n)&&(o[At(t,r)]=n)}return Nt(n,{version:Et,entries:o}),o[At(t,r)]??null},Ft=(e,t,n,r)=>{let i=Ot(e);if(!i||!t||!kt(n))return;let a=null;try{a=r.getItem(`oc.gitBranchCache`)}catch{return}let o=Mt(a);Nt(r,{version:Et,entries:{...o&&jt(o)?o.entries:{},[At(t,i)]:n}})},It=3e4,Lt=Ot,Rt=(e,t=n())=>c.git.branches(Lt(e),t),zt=(e,t=n())=>c.git.remotes(Lt(e),t),Bt=async(e,t,n)=>{n.throwIfAborted();let r=f()?.git,i=t?.getGitBranches?await t.getGitBranches(e,{signal:n}):r?await r.getGitBranches(e,{signal:n}):await b(e,{signal:n});return n.throwIfAborted(),i},Vt=async(e,t,n)=>{n.throwIfAborted();let r=f()?.git,i=t?.getRemotes?await t.getRemotes(e,{signal:n}):r?await r.getRemotes(e,{signal:n}):await v(e,{signal:n});return n.throwIfAborted(),i},Ht=(e,t,i=n(),a=r())=>{let o=Lt(e),s=t;return{queryKey:Rt(o,i),queryFn:async({signal:e})=>{if(!o)throw Error(`Git branches require a directory`);let t=await Bt(o,s,e);return Ft(o,i,t,a),t},staleTime:It,gcTime:1/0,initialData:()=>Pt(o,i,a)??void 0,initialDataUpdatedAt:0}},Ut=(e,t,r=n())=>{let i=Lt(e),a=t;return{queryKey:zt(i,r),queryFn:({signal:e})=>{if(!i)throw Error(`Git remotes require a directory`);return Vt(i,a,e)},staleTime:It,gcTime:1/0}},Wt=(e,r,i)=>{let a=(0,R.c)(9),o=i===void 0||i,s=L.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=Lt(e),u=C,l=Ht(c,r,s),a[0]=e,a[1]=r,a[2]=s,a[3]=c,a[4]=l,a[5]=u):(c=a[3],l=a[4],u=a[5]);let d=o&&!!c,f;return a[6]!==l||a[7]!==d?(f={...l,enabled:d},a[6]=l,a[7]=d,a[8]=f):f=a[8],u(f)},Gt=(e,r,i)=>{let a=(0,R.c)(9),o=i===void 0||i,s=L.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=Lt(e),u=C,l=Ut(c,r,s),a[0]=e,a[1]=r,a[2]=s,a[3]=c,a[4]=l,a[5]=u):(c=a[3],l=a[4],u=a[5]);let d=o&&!!c,f;return a[6]!==l||a[7]!==d?(f={...l,enabled:d},a[6]=l,a[7]=d,a[8]=f):f=a[8],u(f)},Kt=(e,t,r=d,i=n())=>r.fetchQuery(Ht(e,t,i)),qt=(e,t,r=d,i=n())=>r.fetchQuery({...Ht(e,t,i),staleTime:0}),Jt=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,Yt=1e4,Xt=6e4,Zt=5e3,Qt=3e4,$t=6e4,en=25,tn=40,nn=2,rn=15e3,an=500,on=30,sn=20971520,cn=new Map,ln=new Map,un=new Map,dn=new Map,fn=new Map,pn=(e,t)=>`${t}:${e}`,mn=e=>ln.get(e)??0,hn=e=>{let t=mn(e)+1;return ln.set(e,t),t},gn=e=>{let t=(un.get(e)??0)+1;return un.set(e,t),t},_n=e=>{let t=cn.get(e);if(t)return t;let n=new Set;return cn.set(e,n),n},Q=()=>({isGitRepo:null,status:null,branches:null,branchesTransportIdentity:null,log:null,identity:null,diffCache:new Map,indexRevision:0,lastRepoCheckAt:0,lastStatusFetch:0,lastStatusChange:0,lastLogFetch:0,lastBranchesFetch:0,lastIdentityFetch:0,logMaxCount:25,isLoadingStatus:!1,isLoadingLog:!1,isLoadingBranches:!1,isLoadingIdentity:!1}),vn=(e,t=on,n=sn)=>{let r=0;for(let t of e.values())r+=(t.original?.length??0)+(t.modified?.length??0);if(e.size<=t&&r<=n)return e;let i=Array.from(e.entries()).sort((e,t)=>e[1].fetchedAt-t[1].fetchedAt),a=new Map,o=0;for(let e=i.length-1;e>=0;e--){let[r,s]=i[e],c=(s.original?.length??0)+(s.modified?.length??0);if(a.size>=t)break;o+c>n&&a.size>0||(a.set(r,s),o+=c)}return a},yn=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=new Set([...Object.keys(e),...Object.keys(t)]);for(let r of n){let n=e[r],i=t[r];if(!(!n&&!i)&&(!n||!i||n.insertions!==i.insertions||n.deletions!==i.deletions))return!0}return!1},bn=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,xn=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=e.files??[],r=t.files??[];if(n.length!==r.length||e.ahead!==t.ahead||e.behind!==t.behind||e.current!==t.current||e.tracking!==t.tracking||e.isClean!==t.isClean||t.upstreamComparison!==void 0&&bn(e.upstreamComparison,t.upstreamComparison))return!0;let i=new Set(n.map(e=>`${e.path}:${e.index}:${e.working_dir}`));for(let e of r)if(!i.has(`${e.path}:${e.index}:${e.working_dir}`))return!0;return!!(t.diffStats!==void 0&&yn(e.diffStats,t.diffStats))},Sn=(e,t)=>{let n=new Set;if(!t)return n;let r=e?.files??[],i=t.files??[],a=new Map(r.map(e=>[e.path,e])),o=new Map(i.map(e=>[e.path,e])),s=new Set([...a.keys(),...o.keys()]);for(let e of s){let t=a.get(e),r=o.get(e);if(!t||!r){n.add(e);continue}if(t.index!==r.index||t.working_dir!==r.working_dir){n.add(e);continue}}if(t.diffStats!==void 0){let r=e?.diffStats??{},i=t.diffStats??{},a=new Set([...Object.keys(r),...Object.keys(i)]);for(let e of a){let t=r[e],a=i[e];if(!t||!a){n.add(e);continue}(t.insertions!==a.insertions||t.deletions!==a.deletions)&&n.add(e)}}return n},Cn=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=e.files??[],r=t.files??[],i=e=>{let t=e?.trim()??``;return t===`?`?``:t},a=new Map(n.map(e=>[e.path,i(e.index)])),o=new Map(r.map(e=>[e.path,i(e.index)])),s=new Set([...a.keys(),...o.keys()]);for(let e of s)if((a.get(e)??``)!==(o.get(e)??``))return!0;return!1},wn=e=>!e||e.trim().length===0,Tn=e=>(e||``).trim()===`U`,En=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Tn(t)||Tn(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},Dn=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Tn(t)||Tn(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},On=e=>wn(e.index)&&wn(e.working_dir),$=p()(h((e,t)=>({directories:new Map,activeDirectory:null,setActiveDirectory:n=>{let{activeDirectory:r,directories:i}=t();if(r!==n)if(r&&hn(r),n&&hn(n),n&&!i.has(n)){let t=new Map(i);t.set(n,Q()),e({activeDirectory:n,directories:t})}else e({activeDirectory:n})},getDirectoryState:e=>t().directories.get(e)??null,fetchStatus:async(n,r,i={})=>{let a=i.mode??`full`,o=pn(n,a),s=dn.get(o)??(a===`light`?dn.get(pn(n,`full`)):void 0);if(s)return s;let c=(async()=>{let{silent:a=!1}=i,{directories:o}=t(),s=o.get(n);if(s||=Q(),!a){let r=new Map(t().directories),i=r.get(n)??Q();r.set(n,{...i,isLoadingStatus:!0}),e({directories:r})}let c=!1;try{let a=Date.now(),o=s.isGitRepo!==!0||a-(s.lastRepoCheckAt||0)>Xt,l=s.isGitRepo===!0;if(o&&(l=await r.checkIsGitRepository(n)),!l){let r=new Map(t().directories),i=r.get(n)??s;return r.set(n,{...i,isGitRepo:!1,status:null,isLoadingStatus:!1,lastRepoCheckAt:a,lastStatusFetch:a}),e({directories:r}),!1}let u=await r.getGitStatus(n,i.mode?{mode:i.mode}:void 0);if(xn(s.status,u)){c=!0;let r=new Map(t().directories),i=r.get(n)??Q(),s=Sn(i.status,u),l=Cn(i.status,u),d=new Set((i.status?.files??[]).map(e=>e.path)),f=new Set((u.files??[]).map(e=>e.path)),p=new Map(i.diffCache);for(let e of d)f.has(e)||p.delete(e);for(let e of s)p.delete(e);let m=s.size>0;m&&hn(n);let h={...u,diffStats:u.diffStats===void 0&&i.status?.diffStats!==void 0?i.status.diffStats:u.diffStats,upstreamComparison:u.upstreamComparison===void 0?i.status?.upstreamComparison:u.upstreamComparison};r.set(n,{...i,isGitRepo:!0,status:h,diffCache:p,indexRevision:l?i.indexRevision+1:i.indexRevision,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:m?Date.now():i.lastStatusChange}),e({directories:r})}else{let r=new Map(t().directories),i=r.get(n)??Q();r.set(n,{...i,isGitRepo:!0,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:i.lastStatusChange}),e({directories:r})}}catch(e){console.error(`Failed to fetch git status:`,e)}finally{if(!a){let r=new Map(t().directories),i=r.get(n)??Q();r.set(n,{...i,isLoadingStatus:!1}),e({directories:r})}}return c})();dn.set(o,c);try{return await c}finally{dn.get(o)===c&&dn.delete(o)}},moveStatusPathsOptimistically:(n,r,i)=>{let a=new Set(r.map(e=>e.trim()).filter(Boolean));if(a.size===0)return null;let{directories:o}=t(),s=o.get(n),c=s?.status??null;if(!s||!c)return c;let l=!1,u=[];for(let e of c.files){if(!a.has(e.path)){u.push(e);continue}let t=i===`stage`?En(e):Dn(e);t!==e&&(l=!0),On(t)?l=!0:u.push(t)}if(!l)return c;let d=new Map(o);return d.set(n,{...s,status:{...c,files:u,isClean:u.length===0},indexRevision:s.indexRevision+1,lastStatusChange:Date.now()}),e({directories:d}),c},restoreStatus:(n,r)=>{let{directories:i}=t(),a=i.get(n);if(!a)return;let o=new Map(i);o.set(n,{...a,status:r,indexRevision:a.indexRevision+1,lastStatusChange:Date.now()}),e({directories:o})},bumpIndexRevision:n=>{let{directories:r}=t(),i=r.get(n);if(!i)return;let a=new Map(r);a.set(n,{...i,indexRevision:i.indexRevision+1}),e({directories:a})},fetchBranches:async(r,i,a={})=>{let o=n(),s=gn(r);{let n=new Map(t().directories),i=n.get(r)??Q();n.set(r,{...i,isLoadingBranches:!0}),e({directories:n})}try{let c=a.force?await qt(r,i,void 0,o):await Kt(r,i,void 0,o);if(s!==un.get(r)||o!==n())return;let l=new Map(t().directories),u=l.get(r)??Q();l.set(r,{...u,branches:c,branchesTransportIdentity:o,isLoadingBranches:!1,lastBranchesFetch:Date.now()}),e({directories:l})}catch(i){if(Jt(i)||console.error(`Failed to fetch git branches:`,i),s!==un.get(r)||o!==n())return;let a=new Map(t().directories),c=a.get(r)??Q();a.set(r,{...c,isLoadingBranches:!1}),e({directories:a})}},fetchLog:async(n,r,i)=>{let{directories:a}=t(),o=a.get(n),s=i??o?.logMaxCount??25;{let r=new Map(t().directories),i=r.get(n)??Q();r.set(n,{...i,isLoadingLog:!0}),e({directories:r})}try{let i=await r.getGitLog(n,{maxCount:s}),a=new Map(t().directories),o=a.get(n)??Q();a.set(n,{...o,log:i,isLoadingLog:!1,lastLogFetch:Date.now(),logMaxCount:s}),e({directories:a})}catch(r){console.error(`Failed to fetch git log:`,r);let i=new Map(t().directories),a=i.get(n)??Q();i.set(n,{...a,isLoadingLog:!1}),e({directories:i})}},fetchIdentity:async(n,r)=>{{let r=new Map(t().directories),i=r.get(n)??Q();r.set(n,{...i,isLoadingIdentity:!0}),e({directories:r})}try{let i=await r.getCurrentGitIdentity(n),a=new Map(t().directories),o=a.get(n)??Q();a.set(n,{...o,identity:i,isLoadingIdentity:!1,lastIdentityFetch:Date.now()}),e({directories:a})}catch(r){console.error(`Failed to fetch git identity:`,r);let i=new Map(t().directories),a=i.get(n)??Q();i.set(n,{...a,isLoadingIdentity:!1}),e({directories:i})}},fetchAll:async(n,r,i={})=>{let{directories:a}=t(),o=a.get(n);if(!o){o=Q();let t=new Map(a);t.set(n,o),e({directories:t})}let{force:s=!1,silentIfCached:c=!1}=i,l=Date.now();await t().fetchStatus(n,r,{silent:c&&!!o?.status});let u=t().directories.get(n);if(!u?.isGitRepo)return;await t().fetchBranches(n,r,{force:s});let d=l-(u.lastLogFetch||0);(s||d>Yt||!u.log)&&await t().fetchLog(n,r),await t().fetchIdentity(n,r)},getDiff:(e,n)=>t().directories.get(e)?.diffCache.get(n)??null,setDiff:(n,r,i)=>{let a=new Map(t().directories),o=a.get(n)??Q(),s=new Map(o.diffCache);s.set(r,{...i,fetchedAt:Date.now()});let c=vn(s);a.set(n,{...o,diffCache:c}),e({directories:a})},clearDiffCache:n=>{hn(n);let r=new Map(t().directories),i=r.get(n);i&&(r.set(n,{...i,diffCache:new Map}),e({directories:r}))},fetchAllDiffs:async(e,n)=>{let r=t().directories.get(e);if(!r?.status?.files||r.status.files.length===0)return;let i=r.status.files.map(e=>e.path).slice(0,en);await t().prefetchDiffs(e,n,i,{maxFiles:en})},prefetchDiffs:async(n,r,i,a={})=>{let o=t().directories.get(n);if(!o?.status?.files||o.status.files.length===0||i.length===0)return;let{maxFiles:s=tn}=a,c=new Set(o.status.files.map(e=>e.path)),l=o.status.diffStats,u=_n(n),d=[],f=new Set;for(let e of i){if(!e||f.has(e)||(f.add(e),!c.has(e))||o.diffCache.has(e)||u.has(e))continue;let t=l?.[e];t&&t.insertions+t.deletions>an||d.push(e)}let p=d.slice(0,Math.max(1,s));if(p.length===0)return;let m=mn(n);if(typeof document<`u`&&document.hidden)return;p.forEach(e=>u.add(e));let h=0,g=[],_=()=>{let e=h;return h+=1,e<p.length?p[e]:null},v=async e=>{let t=r.getGitFileDiff(n,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${rn}ms`)),rn)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},y=async()=>{for(;;){if(m!==mn(n))return;let e=_();if(!e)return;try{g.push(await v(e))}catch{}finally{u.delete(e)}}},b=Math.min(nn,p.length);if(await Promise.allSettled(Array.from({length:b},()=>y())),p.forEach(e=>u.delete(e)),m!==mn(n))return;let x=new Map(t().directories),S=x.get(n);if(!S)return;let C=new Map(S.diffCache),ee=Date.now();g.forEach(e=>{!e.diff.isBinary&&e.diff.original===``&&e.diff.modified===``||C.set(e.path,{...e.diff,fetchedAt:ee})});let te=vn(C);x.set(n,{...S,diffCache:te}),e({directories:x})},setLogMaxCount:(n,r)=>{let i=new Map(t().directories),a=i.get(n)??Q();i.set(n,{...a,logMaxCount:r}),e({directories:i})},ensureStatus:async(e,n)=>{let r=t().directories.get(e),i=Date.now();r?.status&&i-r.lastStatusFetch<Zt||await t().fetchStatus(e,n,{silent:!!r?.status})},ensureAll:(e,n)=>{let r=fn.get(e);if(r)return r;let i=(async()=>{let r=t().directories.get(e),i=Date.now();(!r?.status||r.status.diffStats===void 0||i-(r?.lastStatusFetch??0)>=Zt)&&await t().fetchStatus(e,n,{silent:!!r?.status});let a=t().directories.get(e);if(!a?.isGitRepo)return;let o=[];(!a.branches||i-a.lastBranchesFetch>=Qt)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=Yt)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=$t)&&o.push(t().fetchIdentity(e,n)),o.length>0&&await Promise.all(o)})();return fn.set(e,i),i.finally(()=>{fn.get(e)===i&&fn.delete(e)}),i},refresh:async(e,n={})=>{let{activeDirectory:r}=t();r&&await t().fetchAll(r,e,n)}}),{name:`git-store`})),kn=e=>{let t=(0,R.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status??null:null,t[0]=e,t[1]=n),$(n)},An=e=>{let r=(0,R.c)(3),i=L.useSyncExternalStore(t,n,n),a;return r[0]!==e||r[1]!==i?(a=t=>{if(!e)return null;let n=t.directories.get(e);return n?.branchesTransportIdentity===i?n.branches:null},r[0]=e,r[1]=i,r[2]=a):a=r[2],$(a)},jn=e=>{let t=(0,R.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.log??null:null,t[0]=e,t[1]=n),$(n)},Mn=e=>{let t=(0,R.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isGitRepo??null:null,t[0]=e,t[1]=n),$(n)},Nn=e=>{let t=(0,R.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status?.current?.trim()??null:null,t[0]=e,t[1]=n),$(n)},Pn={current:new Map},Fn=()=>$(Bn),In=e=>{let t=(0,R.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=L.useRef(n),i;return t[1]===e?i=t[2]:(i=t=>{let n=r.current,i=n.size===e.length;if(i)for(let r of e){let e=t.directories.get(r),a=n.get(r);if(!a||(e?.isGitRepo??null)!==a.isGitRepo||(e?.status?.current??null)!==a.branch){i=!1;break}}if(i)return n;let a=new Map;for(let n of e){let e=t.directories.get(n);a.set(n,{isGitRepo:e?.isGitRepo??null,branch:e?.status?.current??null})}return r.current=a,a},t[1]=e,t[2]=i),$(i)},Ln=e=>{let t=(0,R.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingStatus??!1:!1,t[0]=e,t[1]=n),$(n)},Rn=e=>{let t=(0,R.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingLog??!1:!1,t[0]=e,t[1]=n),$(n)},zn=e=>{let t=(0,R.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingBranches??!1:!1,t[0]=e,t[1]=n),$(n)};function Bn(e){let t=Pn.current,n=t.size===e.directories.size;if(n){for(let[r,i]of e.directories)if(t.get(r)!==(i.status?.current??null)){n=!1;break}}if(n)return t;let r=new Map;for(let[t,n]of e.directories)r.set(t,n.status?.current??null);return Pn.current=r,r}var Vn=e=>{let t=String(e||``).trim().replace(/^remotes\//,``);if(!t)return null;let n=t.indexOf(`/`);return n<=0||n>=t.length-1?null:{remote:t.slice(0,n),branch:t.slice(n+1)}},Hn=e=>String(e||``).trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/^remotes\//,``),Un=e=>e.branchName?Hn(e.branchName):e.mode===`existing`?Hn(e.existingBranch||e.preferredName||``):Hn(e.preferredName||``),Wn=async e=>{let t=await he(e);try{let n=Vn((await I(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=Vn((await fe(e)).tracking);if(t?.remote)return t.remote}catch{}return null},Gn=async(e,t)=>{let n=await Wn(e),r=Hn(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},Kn=async(e,t,n)=>{let r=Un(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await Gn(e,r):i&&Hn(r)?{setUpstream:!0,upstreamRemote:i,upstreamBranch:Hn(r)}:null;return a?{...t,setUpstream:t.setUpstream??a.setUpstream,upstreamRemote:t.upstreamRemote||a.upstreamRemote,upstreamBranch:t.upstreamBranch||a.upstreamBranch}:t},qn=async(e,t,n)=>{let r=await Kn(e.path,t,n);return ge(e,r)},Jn=`oc:lastWorktreeSourceBranch`,Yn=({mode:e,sourceBranch:t,linkedPr:n,selectedBranch:r})=>e===`existing-branch`?r||null:n?null:t||null,Xn=({branches:e,savedSourceBranch:t,rootBranch:n})=>t&&e.includes(t)&&t?{sourceBranch:t,shouldClearSavedSourceBranch:!1}:{sourceBranch:n&&e.includes(n)?n:e.includes(`main`)?`main`:e.includes(`master`)?`master`:e[0]??``,shouldClearSavedSourceBranch:!!t},Zn=(e,t,n)=>{if(!e)return e;let r=t.length>0&&!/\s$/.test(t)&&!/^\s/.test(e)&&!/[([{]$/.test(t),i=n.length>0&&!/\s$/.test(e)&&!/^\s/.test(n)&&!/^[\])}.,;:!?]/.test(n);return`${r?` `:``}${e}${i?` `:``}`},Qn=(e,t,n)=>{let r=Zn(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},$n=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=Qn(r,i,a),s=Math.max(0,o.indexOf(r)),c=i.length+s;return{text:`${i}${o}${a}`,caret:i.length+o.length,start:c,end:c+r.length}},er=(e,t)=>{let n=e=>`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`;return new Set(e.map(n)).has(n(t))?[...e]:[...e,t]},tr=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{Xe as A,K as B,Wt as C,rt as D,dt as E,Pe as F,G as H,Oe as I,ke as L,qe as M,Ie as N,tt as O,Fe as P,Ae as R,qt as S,pt as T,xe as U,W as V,be as W,jn as _,Jn as a,$ as b,qn as c,Fn as d,Nn as f,Ln as g,Rn as h,Qn as i,Ye as j,Qe as k,Wn as l,zn as m,er as n,Xn as o,An as p,$n as r,Yn as s,tr as t,Kn as u,In as v,Gt as w,Mn as x,kn as y,Te as z};
|