@openchamber/web 1.22.1 → 1.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/bin/cli.js +4 -1
  2. package/bin/cli.test.js +92 -0
  3. package/bin/lib/cli-startup.js +49 -0
  4. package/bin/lib/commands-startup.js +41 -6
  5. package/dist/assets/{CodeMirrorCommentWidgets-BO_2OW4E.js → CodeMirrorCommentWidgets-BI-TY1UG.js} +1 -1
  6. package/dist/assets/{DiffView-CNnDxRmO.js → DiffView-cOmByCaX.js} +3 -3
  7. package/dist/assets/{DirtyBranchSwitchDialog-jADfXQnR.js → DirtyBranchSwitchDialog-BwSnDlNy.js} +1 -1
  8. package/dist/assets/FilesView-DRRy_6oZ.js +17 -0
  9. package/dist/assets/{GitView-Cv2xH-S6.js → GitView-B7YCg1YM.js} +4 -4
  10. package/dist/assets/{JsonTreeView-DUiIpERC.js → JsonTreeView-CjzNsiIU.js} +1 -1
  11. package/dist/assets/{LinearIssuesView-CoZ7pQN5.js → LinearIssuesView-BYlE0YrW.js} +1 -1
  12. package/dist/assets/{MarkdownImageGallery-DffjmciG.js → MarkdownImageGallery-DlTF-wua.js} +1 -1
  13. package/dist/assets/MarkdownRendererImpl-CqgeZRlP.js +12 -0
  14. package/dist/assets/{OnboardingScreen-CTZe6HZn.js → OnboardingScreen-BsJU7oav.js} +1 -1
  15. package/dist/assets/{PatchDiff-BymkP9JA.js → PatchDiff-CDNu968J.js} +1 -1
  16. package/dist/assets/{PierreDiffViewer-BvwtCxW4.js → PierreDiffViewer-BoBsAanf.js} +1 -1
  17. package/dist/assets/{PlanView-C1qvAm7m.js → PlanView-Cxr8LQT1.js} +4 -4
  18. package/dist/assets/SettingsView-bsKpCZbB.js +28 -0
  19. package/dist/assets/{SettingsWindow-COzgfFxM.js → SettingsWindow-B0rHQdw4.js} +1 -1
  20. package/dist/assets/{ToolOutputDialog-Dlhh_-oe.js → ToolOutputDialog-6zP8hwzX.js} +6 -6
  21. package/dist/assets/{ToolPartDiffPreview-b9joNtXH.js → ToolPartDiffPreview-Bvwh4Y31.js} +2 -2
  22. package/dist/assets/{VirtualizedFileDiff-vqW3KKo5.js → VirtualizedFileDiff-aaIfrRxl.js} +1 -1
  23. package/dist/assets/{WalkthroughView-D-HFgdmM.js → WalkthroughView-baZ0ssy9.js} +2 -2
  24. package/dist/assets/{computeVirtualFileMetrics-DUnyszhW.js → computeVirtualFileMetrics-DfgllYQc.js} +2 -2
  25. package/dist/assets/{contextPanelEmbeddedChat-CV-DwAiX.js → contextPanelEmbeddedChat-prHos-tt.js} +1 -1
  26. package/dist/assets/{de-Cv_4FoXm.js → de-hknQLFxa.js} +2 -2
  27. package/dist/assets/{es-BIWNEbnS.js → es-C_bD3kvW.js} +2 -2
  28. package/dist/assets/{fr-SD3OfMHJ.js → fr-BVF-C2Nu.js} +2 -2
  29. package/dist/assets/index-B0aX0JeI.js +39 -0
  30. package/dist/assets/{index-DLiD86ge.js → index-DUwZ2cWA.js} +1 -1
  31. package/dist/assets/index-Dl3xbAB_.css +1 -0
  32. package/dist/assets/{isDiffPlainText-TNageFjy.js → isDiffPlainText-COIS9Df5.js} +1 -1
  33. package/dist/assets/{isFilePlainText-JPmZOYSp.js → isFilePlainText-D7LEG-KY.js} +1 -1
  34. package/dist/assets/{ja-D7I9HofF.js → ja-B2G5hD59.js} +2 -2
  35. package/dist/assets/{ko-BsVJM_PQ.js → ko-D6OrOdZ3.js} +2 -2
  36. package/dist/assets/main-BBuBZzoi.js +930 -0
  37. package/dist/assets/{main-DCB4JgVe.js → main-CwIEELQq.js} +2 -2
  38. package/dist/assets/{markdownCore-BoQVG5-a.js → markdownCore-BE_Hhps5.js} +2 -2
  39. package/dist/assets/{miniChat-BtV7N5OF.js → miniChat-CeXAoWiF.js} +2 -2
  40. package/dist/assets/{mobile-DZV_sfX7.js → mobile-ilq39yLQ.js} +2 -2
  41. package/dist/assets/{patchFileDiff-Chmiz6hq.js → patchFileDiff-DLky6SYr.js} +5 -5
  42. package/dist/assets/{pl-XR9Bs8Be.js → pl-CVroZXt1.js} +2 -2
  43. package/dist/assets/{pt-BR-Due4be8g.js → pt-BR-eH3onaIW.js} +2 -2
  44. package/dist/assets/{renderElectronMiniChatApp-8tXADjfl.js → renderElectronMiniChatApp-BsywqmJT.js} +2 -2
  45. package/dist/assets/{renderMobileApp-Cji7Hma5.js → renderMobileApp-CDun1795.js} +7 -7
  46. package/dist/assets/runtimeEndpointReset-DebJIo5U.js +17 -0
  47. package/dist/assets/{scheduledTasksApi-9e-UX6im.js → scheduledTasksApi-B0tChXQC.js} +1 -1
  48. package/dist/assets/{shikiHighlight-CRpCl7UT.js → shikiHighlight-DJSXdcG4.js} +1 -1
  49. package/dist/assets/tr-BvtU2tXS.js +7 -0
  50. package/dist/assets/{uk-COYh2BaN.js → uk-nu36iqFz.js} +2 -2
  51. package/dist/assets/{useAppFontEffects-CCgvcQ6u.js → useAppFontEffects-Bb1Zihd2.js} +134 -131
  52. package/dist/assets/useInlineCommentController-B8dQWRpH.js +2 -0
  53. package/dist/assets/{useRootScrollLock-KzOUytpn.js → useRootScrollLock-DrJ8gE-x.js} +1 -1
  54. package/dist/assets/{vendor-codemirror-language-data-BxpoC5Fp.js → vendor-codemirror-language-data-CNjvbb69.js} +2 -2
  55. package/dist/assets/vendor-zod-CK21ihK-.js +39 -0
  56. package/dist/assets/{web-components-B6QgbmTo.js → web-components-C06MmTcR.js} +1 -1
  57. package/dist/assets/{zh-CN-Cjk6lzhc.js → zh-CN-BClBzZ64.js} +2 -2
  58. package/dist/assets/{zh-TW-Dk0dOg03.js → zh-TW-CXtSqJHF.js} +2 -2
  59. package/dist/index.html +5 -5
  60. package/dist/mini-chat.html +4 -4
  61. package/dist/mobile.html +4 -4
  62. package/package.json +3 -3
  63. package/server/index.js +7 -1
  64. package/server/lib/changelog/update-notes.js +82 -0
  65. package/server/lib/changelog/update-notes.test.js +59 -0
  66. package/server/lib/fs/DOCUMENTATION.md +2 -0
  67. package/server/lib/fs/routes.js +32 -21
  68. package/server/lib/fs/routes.test.js +77 -0
  69. package/server/lib/git/service.js +10 -0
  70. package/server/lib/git/service.test.js +18 -0
  71. package/server/lib/message-queue/DOCUMENTATION.md +17 -7
  72. package/server/lib/message-queue/runtime.js +59 -7
  73. package/server/lib/message-queue/runtime.test.js +59 -3
  74. package/server/lib/opencode/DOCUMENTATION.md +8 -4
  75. package/server/lib/opencode/config-paths.test.js +116 -0
  76. package/server/lib/opencode/feature-routes-runtime.js +2 -0
  77. package/server/lib/opencode/input-history-scope.js +14 -0
  78. package/server/lib/opencode/plugins.js +2 -2
  79. package/server/lib/opencode/providers.js +44 -2
  80. package/server/lib/opencode/providers.test.js +131 -4
  81. package/server/lib/opencode/routes.js +4 -4
  82. package/server/lib/opencode/server-startup-runtime.js +1 -1
  83. package/server/lib/opencode/settings-helpers.js +28 -0
  84. package/server/lib/opencode/settings-helpers.test.js +177 -0
  85. package/server/lib/opencode/shared.js +4 -1
  86. package/server/lib/opencode/skill-routes.js +2 -1
  87. package/server/lib/opencode/snippets.js +1 -2
  88. package/server/lib/package-manager.js +3 -28
  89. package/server/lib/quota/utils/auth.js +1 -1
  90. package/server/lib/relay/host-client.test.js +9 -1
  91. package/server/lib/session-goal/DOCUMENTATION.md +20 -7
  92. package/server/lib/session-goal/runtime.js +76 -11
  93. package/server/lib/session-goal/runtime.test.js +426 -0
  94. package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
  95. package/server/lib/skills-catalog/install.js +3 -2
  96. package/server/lib/terminal/DOCUMENTATION.md +11 -7
  97. package/server/lib/terminal/runtime.js +150 -19
  98. package/server/lib/terminal/runtime.test.js +553 -26
  99. package/server/lib/terminal/shells.js +17 -0
  100. package/server/lib/terminal/shells.test.js +32 -1
  101. package/server/lib/walkthrough/routes.test.js +26 -5
  102. package/dist/assets/FilesView-8wdiG2mj.js +0 -17
  103. package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +0 -12
  104. package/dist/assets/SettingsView-xGONHFGS.js +0 -28
  105. package/dist/assets/index-CHUT_bDS.css +0 -1
  106. package/dist/assets/index-DDInLQDd.js +0 -40
  107. package/dist/assets/main-De8Z5w49.js +0 -928
  108. package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +0 -16
  109. package/dist/assets/tr-DBJcAv4y.js +0 -7
  110. package/dist/assets/useInlineCommentController-BkfXnjNZ.js +0 -2
  111. package/dist/assets/vendor-zod-DVWEh-IS.js +0 -39
@@ -0,0 +1,12 @@
1
+ import{R as E,f as se,j as te}from"./vendor-react-BUCujlKS.js";import{m as zt}from"./vendor-morphdom-B7dS_VPB.js";import{r as Ht,a as Vt}from"./vendor-beautiful-mermaid-DztCUpLZ.js";import{fu as at,fv as Kt,fw as jt,fx as Ut,g as we,bb as Zt,be as Xt,fy as Gt,fz as Yt,W as lt,ac as ct,fA as dt,f as ut,h as mt,ea as Jt,eb as We,fB as Qt,fC as qe,fD as en,fE as tn,fF as nn,fG as rn,fH as on,o as sn}from"./useAppFontEffects-Bb1Zihd2.js";import{r as an,G as pt,J as ne,cB as ln,u as G,a as cn,z as dn,A as un}from"./index-B0aX0JeI.js";import{h as mn}from"./contextPanelEmbeddedChat-prHos-tt.js";import{getCachedMarkdownBlocks as Be,renderMarkdownSync as pn,renderMarkdownBlocks as fn}from"./markdownCore-BE_Hhps5.js";import{r as hn}from"./registerCustomTheme-BBXUCRnG.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-elkjs-BRwcR927.js";import"./vendor-entities-C3BA0AJP.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CNjvbb69.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-zod-CK21ihK-.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-marked-linkify-it-CXI_LHIE.js";import"./vendor-linkify-it-DZCzzDkK.js";import"./vendor-uc.micro-BAd0H0z4.js";import"./vendor-remend-BWYYytN3.js";import"./vendor-katex-k3Ppq1Ha.js";import"./vendor-dompurify-r8glNMJW.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const ft=t=>{const e=t.target;if(!(e instanceof Element))return null;const n=e.closest("a[href]");return!(n instanceof HTMLAnchorElement)||n.getAttribute("data-openchamber-file-link")==="true"?null:n},Me=(t,e)=>{if(t.defaultPrevented)return!1;const r=ft(t)?.getAttribute("href")??"";return Kt(r)?(t.preventDefault(),t.stopPropagation(),e?.(r),!0):!1},gn=t=>t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey,bn=(t,e)=>{const n=o=>{if(Me(o,e.openAppLink)||!e.allowExternalHttp||o.defaultPrevented||!gn(o))return;const s=ft(o)?.getAttribute("href")??"";at(s)&&(o.preventDefault(),o.stopPropagation(),e.openExternalHttp(s))},r=o=>{o.button===1&&Me(o,e.openAppLink)},i=o=>{Me(o)};return t.addEventListener("click",n),t.addEventListener("auxclick",r),t.addEventListener("dragstart",i),()=>{t.removeEventListener("click",n),t.removeEventListener("auxclick",r),t.removeEventListener("dragstart",i)}},ht="openchamber-md",wn={name:ht,colors:{"editor.background":"transparent","editor.foreground":"var(--md-syntax-foreground)"},tokenColors:[{scope:["comment","punctuation.definition.comment","string.comment"],settings:{foreground:"var(--md-syntax-comment)",fontStyle:"italic"}},{scope:["string","punctuation.definition.string","string.template"],settings:{foreground:"var(--md-syntax-string)"}},{scope:["constant.numeric","constant.language","constant.character","constant"],settings:{foreground:"var(--md-syntax-number)"}},{scope:["keyword","storage","storage.type","storage.modifier","keyword.control"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["keyword.operator","punctuation.separator","punctuation.terminator"],settings:{foreground:"var(--md-syntax-operator)"}},{scope:["entity.name.function","support.function","meta.function-call"],settings:{foreground:"var(--md-syntax-function)"}},{scope:["entity.name.type","entity.name.class","support.type","support.class","entity.other.inherited-class"],settings:{foreground:"var(--md-syntax-type)"}},{scope:["variable","variable.other","variable.parameter","meta.definition.variable"],settings:{foreground:"var(--md-syntax-variable)"}},{scope:["variable.other.property","meta.property-name","support.type.property-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["entity.name.tag","punctuation.definition.tag"],settings:{foreground:"var(--md-syntax-keyword)"}},{scope:["entity.other.attribute-name"],settings:{foreground:"var(--md-syntax-property)"}},{scope:["markup.bold","punctuation.definition.bold"],settings:{fontStyle:"bold"}},{scope:["markup.italic","punctuation.definition.italic"],settings:{fontStyle:"italic"}},{scope:["markup.heading","markup.heading entity.name"],settings:{foreground:"var(--md-syntax-keyword)",fontStyle:"bold"}},{scope:["markup.inserted","punctuation.definition.inserted"],settings:{foreground:"var(--md-syntax-inserted)"}},{scope:["markup.deleted","punctuation.definition.deleted"],settings:{foreground:"var(--md-syntax-deleted)"}},{scope:["invalid","invalid.illegal"],settings:{foreground:"var(--md-syntax-deleted)"}}]};let $e=!1;const yn=()=>{$e||($e=!0,hn(ht,()=>Promise.resolve(wn)))},T=t=>Number.isFinite(t)&&t>0,ze=t=>{if(t==null)return null;const e=String(t).trim().match(/^([+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?)(?:px)?$/);if(!e)return null;const n=Number(e[1]);return T(n)?n:null},Ne=(t,e,n)=>Math.min(n,Math.max(e,t)),An=6,He=1.25,vn=1.0015,kn=.5,En=12,Ve=3,Cn=400,re='[data-markdown="mermaid-block"]',I=t=>t.querySelector(re)!==null,Sn=t=>[t.x,t.y,t.width,t.height].map(e=>{const n=Number(e.toFixed(An));return Object.is(n,-0)?"0":String(n)}).join(" "),Ln=t=>{const e=t.viewBox?.trim().split(/[\s,]+/).map(i=>Number.parseFloat(i));if(e?.length===4){const[i,o,s,a]=e;if(Number.isFinite(i)&&Number.isFinite(o)&&T(s)&&T(a))return{x:i,y:o,width:s,height:a}}const n=ze(t.width),r=ze(t.height);return n===null||r===null?null:{x:0,y:0,width:n,height:r}},Mn=t=>{let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0).toString(36)},Nn=t=>{const e=t.renderMode||"unknown",n=t.svgMarkup??"";if(!n){const r=[t.viewBox??"",t.width??"",t.height??""];return r.some(i=>i!=="")?`${e}:bounds:${r.join(":")}`:`${e}:no-svg`}return[e,Mn(n)].join(":")},gt=(t,e)=>{if(!T(e.width)||!T(e.height))return t;const n=t.width/t.height,r=e.width/e.height;if(n>r){const o=t.width/r;return{x:t.x,y:t.y-(o-t.height)/2,width:t.width,height:o}}const i=t.height*r;return{x:t.x-(i-t.width)/2,y:t.y,width:i,height:t.height}},Rn=({currentBox:t,viewport:e,delta:n})=>!T(e.width)||!T(e.height)||!T(t.width)||!T(t.height)?t:{x:t.x-n.x/e.width*t.width,y:t.y-n.y/e.height*t.height,width:t.width,height:t.height},Tn=(t,e)=>{const n=e.x-t.x,r=e.y-t.y;return n*n+r*r>Ve*Ve},_n=({currentBox:t,contentBox:e,viewport:n,pointer:r,zoomFactor:i,minScale:o,maxScale:s})=>{if(!T(n.width)||!T(n.height)||!T(i)||!T(t.width)||!T(t.height)||!T(e.width)||!T(e.height)||!T(o)||!T(s))return t;const a=Math.min(o,s),l=Math.max(o,s),c=gt(e,n),u=c.width/t.width,f=Ne(u*i,a,l),m=c.width/f,g=m/(t.width/t.height),y=Ne(r.x/n.width,0,1),v=Ne(r.y/n.height,0,1),C=t.x+y*t.width,p=t.y+v*t.height;return{x:C-y*m,y:p-v*g,width:m,height:g}},ye=new WeakMap,Ie=new WeakMap,K=new Set,oe=new Set;let V=null,ee=null,J=null;const xn=t=>t.querySelector('[data-markdown="mermaid-viewport"]')??t.querySelector('[data-markdown="mermaid"]'),bt=t=>{const e=t.querySelector('[data-markdown="mermaid"] svg'),n=t.querySelector('[data-markdown="mermaid"]');return Nn({renderMode:t.getAttribute("data-mermaid-render"),svgMarkup:n?.getAttribute("data-md-original-svg")??e?.outerHTML??null,viewBox:e?.getAttribute("viewBox"),width:e?.getAttribute("width"),height:e?.getAttribute("height")})},X=t=>{const e=t.getBoundingClientRect();return{width:e.width,height:e.height}},Pn=(t,e)=>{const n=e.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}},In=t=>t instanceof Element&&!!t.closest('button, a, [role="button"]'),wt=t=>{const e=t.map(n=>X(n.viewport));t.forEach((n,r)=>{const i=e[r];i&&n.fitToViewport(i)})},yt=()=>{J!==null||K.size===0||(J=window.requestAnimationFrame(()=>{J=null,wt(Array.from(K))}))},Fn=()=>{if(V)return V;const t=globalThis.ResizeObserver;return t?(V=new t(e=>{for(const n of e)n.target instanceof HTMLElement&&Ie.get(n.target)?.fitToViewport({width:n.contentRect.width,height:n.contentRect.height})}),V):null},Dn=t=>{if(K.has(t))return;const e=K.size===0;K.add(t),Ie.set(t.viewport,t),Fn()?.observe(t.viewport),e&&window.addEventListener("resize",yt)},On=t=>{K.delete(t)&&(V?.unobserve(t.viewport),Ie.delete(t.viewport),!(K.size>0)&&(V?.disconnect(),V=null,window.removeEventListener("resize",yt),J!==null&&(window.cancelAnimationFrame(J),J=null)))},Wn=t=>{const e=xn(t),n=t.querySelector('[data-markdown="mermaid"] svg');if(!e||!n)return null;const r=Ln({viewBox:n.getAttribute("viewBox"),width:n.getAttribute("width"),height:n.getAttribute("height")});if(!r)return null;let i=r,o=null,s=null,a=null,l=null;const c=d=>{i=d,n.setAttribute("viewBox",Sn(d)),n.removeAttribute("width"),n.removeAttribute("height")},u=d=>{c(gt(r,d))},f=()=>{u(X(e))},m=(d,b)=>{c(_n({currentBox:i,contentBox:r,viewport:X(e),pointer:d,zoomFactor:b,minScale:kn,maxScale:En}))},g=()=>{const d=X(e);m({x:d.width/2,y:d.height/2},He)},y=()=>{const d=X(e);m({x:d.width/2,y:d.height/2},1/He)},v=d=>{!d.ctrlKey&&!d.metaKey||(d.preventDefault(),d.stopPropagation(),m(Pn(d,e),Math.pow(vn,-d.deltaY)))},C=d=>{d.button!==0||In(d.target)||(o=d.pointerId,s={x:d.clientX,y:d.clientY},a=s,l!==null&&(window.clearTimeout(l),l=null),t.removeAttribute("data-mermaid-suppress-click"),e.setPointerCapture?.(d.pointerId),t.setAttribute("data-mermaid-panning","true"),d.preventDefault())},p=d=>{if(o!==d.pointerId||!a)return;const b={x:d.clientX,y:d.clientY};c(Rn({currentBox:i,viewport:X(e),delta:{x:b.x-a.x,y:b.y-a.y}})),a=b,s&&Tn(s,b)&&t.setAttribute("data-mermaid-suppress-click","true"),d.preventDefault()},h=d=>{o===d.pointerId&&(e.releasePointerCapture?.(d.pointerId),o=null,s=null,a=null,t.removeAttribute("data-mermaid-panning"),t.hasAttribute("data-mermaid-suppress-click")&&(l=window.setTimeout(()=>{t.removeAttribute("data-mermaid-suppress-click"),l=null},Cn)))};e.addEventListener("wheel",v,{passive:!1}),e.addEventListener("pointerdown",C),e.addEventListener("pointermove",p),e.addEventListener("pointerup",h),e.addEventListener("pointercancel",h);const k={viewport:e,zoomIn:g,zoomOut:y,fit:f,fitToViewport:u,cleanup:()=>{On(k),e.removeEventListener("wheel",v),e.removeEventListener("pointerdown",C),e.removeEventListener("pointermove",p),e.removeEventListener("pointerup",h),e.removeEventListener("pointercancel",h),l!==null&&window.clearTimeout(l),t.removeAttribute("data-mermaid-panning"),t.removeAttribute("data-mermaid-suppress-click"),ye.delete(t)}};return k},At=t=>{for(const[e,n]of t.controllers){const r=bt(e);(!t.container.contains(e)||r!==t.signatures.get(e))&&(n.cleanup(),t.controllers.delete(e),t.signatures.delete(e))}},qn=t=>{if(t.disposed)return[];const e=[];for(const n of Array.from(t.container.querySelectorAll(re))){if(t.controllers.has(n)||n.querySelector('[data-markdown="mermaid"] svg')===null)continue;const r=Wn(n);r&&(t.controllers.set(n,r),t.signatures.set(n,bt(n)),ye.set(n,r),e.push(r))}return e},vt=()=>{const t=Array.from(oe);oe.clear();const e=[];for(const n of t)n.disposed||(At(n),e.push(...qn(n)));wt(e);for(const n of e)Dn(n)},Bn=()=>{ee===null&&(ee=window.requestAnimationFrame(()=>{ee=null,ee=window.requestAnimationFrame(()=>{ee=null,vt()})}))},$n=t=>{t.disposed||(At(t),oe.add(t),Bn())},zn=t=>{if(!(t instanceof HTMLElement))return null;const e=ye.get(t);if(e)return e;for(const n of oe)if(n.container.contains(t))return vt(),ye.get(t)??null;return null},Hn=t=>{const e={container:t,controllers:new Map,signatures:new Map,disposed:!1},n=()=>$n(e),r=()=>{e.disposed=!0,oe.delete(e);for(const i of e.controllers.values())i.cleanup();e.controllers.clear(),e.signatures.clear()};return n(),{refresh:n,cleanup:r}},Vn={copy:"file-copy",check:"check",download:"download",zoomIn:"add",zoomOut:"subtract",fit:"refresh",textWrap:"text-wrap",image:"file-image"},kt="p-1 rounded hover:bg-interactive-hover/60 text-muted-foreground hover:text-foreground transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--interactive-focus-ring)]",ie=(t,e)=>{const n=Vn[e],r=t.ownerDocument.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("class","remixicon size-3.5"),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("aria-hidden","true");const i=t.ownerDocument.createElementNS("http://www.w3.org/2000/svg","use");i.setAttribute("href",`#oc-${n}`),r.appendChild(i),t.replaceChildren(r)},Kn=t=>{for(const e of Array.from(t.querySelectorAll('[data-openchamber-markdown-image-label="true"]'))){if(e.querySelector("[data-openchamber-markdown-image-label-icon]"))continue;const n=document.createElement("span");n.className="inline-flex shrink-0",n.setAttribute("aria-hidden","true"),n.setAttribute("data-openchamber-markdown-image-label-icon","true"),ie(n,"image"),e.prepend(n)}},B=(t,e,n)=>{const r=document.createElement("button");return r.type="button",r.className=kt,r.setAttribute("data-md-action",n),r.setAttribute("title",e),r.setAttribute("aria-label",e),ie(r,t),r},Et=(t,e,n)=>{const r=t.querySelector("[data-md-code-body]"),i=t.querySelector("pre"),o=t.querySelector("pre code"),s=t.querySelectorAll("[data-md-code-line-content]"),a=t.querySelector('[data-md-action="toggle-code-wrap"]');t.setAttribute("data-code-wrap",e?"true":"false"),r?.classList.toggle("overflow-x-auto",!e),r?.classList.toggle("overflow-x-hidden",e),i?.classList.toggle("whitespace-pre-wrap",e),i?.classList.toggle("break-words",e),o?.classList.toggle("whitespace-pre-wrap",e),o?.classList.toggle("break-words",e),i&&(i.style.whiteSpace=e?"pre-wrap":"pre",i.style.overflowWrap=e?"anywhere":"normal"),o&&(o.style.whiteSpace=e?"pre-wrap":"pre",o.style.overflowWrap=e?"anywhere":"normal");for(const l of Array.from(s))l.style.whiteSpace=e?"pre-wrap":"pre",l.style.overflowWrap=e?"anywhere":"normal";if(a){const l=e?n.disableCodeWrap:n.enableCodeWrap;a.setAttribute("title",l),a.setAttribute("aria-label",l),a.classList.toggle("text-foreground",e),a.classList.toggle("opacity-100",e),a.classList.toggle("text-muted-foreground",!e),a.classList.toggle("opacity-65",!e),a.setAttribute("aria-pressed",e?"true":"false")}},Ct=t=>{const e=t.querySelector(":scope > code");if(!e||e.hasAttribute("data-md-code-lines"))return;t.removeAttribute("data-md-gutter-reserved");const n=e.textContent??"",r=n.endsWith(`
2
+ `),i=r?n.slice(0,-1).split(`
3
+ `):n.split(`
4
+ `),o=i.length>0?i:[""],s=Array.from(e.children).filter(c=>c.classList.contains("line"));r&&s.length===o.length+1&&s.at(-1)?.textContent===""&&s.pop();const a=s.length===o.length,l=document.createDocumentFragment();o.forEach((c,u)=>{const f=document.createElement("span");f.setAttribute("data-md-code-line","");const m=document.createElement("span");m.setAttribute("data-md-code-line-number",String(u+1)),m.setAttribute("aria-hidden","true");const g=document.createElement("span");if(g.setAttribute("data-md-code-line-content",""),a){const y=s[u];y&&g.append(...Array.from(y.childNodes))}else g.textContent=c;if(f.append(m,g),l.appendChild(f),u<o.length-1||r){const y=document.createElement("span");y.setAttribute("data-md-code-line-break",""),y.textContent=`
5
+ `,l.appendChild(y)}}),e.replaceChildren(l),e.setAttribute("data-md-code-lines",""),e.toggleAttribute("data-md-code-trailing-newline",r)},St=t=>{const e=Array.from(t.querySelectorAll("[data-md-code-line-content]"));if(e.length===0)return t.textContent??"";const n=e.map(r=>r.textContent??"").join(`
6
+ `);return t.hasAttribute("data-md-code-trailing-newline")?`${n}
7
+ `:n},Ke=(t,e,n)=>{const r=t.querySelectorAll('[data-component="markdown-code"]');for(const i of Array.from(r)){const o=i.querySelector("pre");o&&Ct(o),Et(i,e,n)}},je=(t,e,n,r)=>{ie(t,"check"),t.setAttribute("title",e),t.setAttribute("aria-label",e),window.setTimeout(()=>{ie(t,n),t.setAttribute("title",r),t.setAttribute("aria-label",r)},2e3)},jn=t=>{const e=t.querySelectorAll(":not(pre) > code");for(const n of Array.from(e))n.getAttribute("data-markdown")!=="inline-code"&&n.setAttribute("data-markdown","inline-code")},Un=(t,e)=>{const n=t.querySelectorAll("pre");for(const r of Array.from(n)){if(r.querySelector("code.language-mermaid"))continue;const i=r.parentElement;if(!i||i.closest('[data-component="markdown-code"]'))continue;const o=r.querySelector("code")?.className.match(/language-([\w+#.-]+)/)?.[1],s=r.getAttribute("data-md-lang")??o??"text",a=document.createElement("div");a.setAttribute("data-component","markdown-code"),a.className="my-4 group overflow-hidden rounded-2xl border border-border/80 bg-[var(--surface-elevated)]";const l=document.createElement("div");l.className="flex items-center justify-between border-b border-border/70 px-3 py-1.5";const c=document.createElement("span");c.className="font-mono text-[13px] text-muted-foreground",c.textContent=s;const u=B("copy",e.labels.copy,"copy-code"),f=B("textWrap",e.codeBlockLineWrap?e.labels.disableCodeWrap:e.labels.enableCodeWrap,"toggle-code-wrap");l.appendChild(c);const m=document.createElement("div");m.className="flex items-center gap-1",m.setAttribute("data-md-code-actions",""),m.appendChild(f),m.appendChild(u),l.appendChild(m);const g=document.createElement("div");g.setAttribute("data-md-code-body",""),g.className="px-3 py-2.5 overflow-x-auto",i.replaceChild(a,r),r.style.margin="0",r.style.background="transparent",r.classList.add("min-w-0","w-full","flex-1"),e.deferCodeLineNumberSync?r.setAttribute("data-md-gutter-reserved",""):Ct(r),g.appendChild(r),a.appendChild(l),a.appendChild(g),Et(a,e.codeBlockLineWrap,e.labels)}},Ue=t=>{const e=[],n=[],r=t.querySelectorAll("thead th");for(const o of Array.from(r))e.push((o.textContent??"").trim());const i=t.querySelectorAll("tbody tr");for(const o of Array.from(i)){const s=Array.from(o.querySelectorAll("td")).map(a=>(a.textContent??"").trim());s.length>0&&n.push(s)}return{headers:e,rows:n}},Zn=t=>/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t,Ze=({headers:t,rows:e})=>[t,...e].map(n=>n.map(Zn).join(",")).join(`
8
+ `),Xn=({headers:t,rows:e})=>[t,...e].map(n=>n.join(" ")).join(`
9
+ `),Xe=({headers:t,rows:e})=>{const n=`| ${t.join(" | ")} |`,r=`| ${t.map(()=>"---").join(" | ")} |`,i=e.map(o=>`| ${o.join(" | ")} |`).join(`
10
+ `);return`${n}
11
+ ${r}
12
+ ${i}`},Ge=(t,e)=>{const n=document.createElement("div");n.className=`absolute top-full right-0 mt-1 hidden ${Zt}`,n.style.backgroundColor="var(--surface-elevated)",n.style.color="var(--surface-elevated-foreground)",n.setAttribute("data-md-menu",t);for(const r of e){const i=document.createElement("button");i.type="button",i.className=`w-full text-left ${Xt}`,i.setAttribute("data-md-action",`${t}-${r.key}`),i.textContent=r.label,n.appendChild(i)}return n},Gn=120,Yn=320,Pe="data-md-table-layout",Jn=(t,e)=>{const n=t.querySelectorAll("table");for(const r of Array.from(n)){if(r.closest('[data-markdown="table-wrapper"]'))continue;const o=document.createElement("div");o.className="group my-4 flex flex-col space-y-2",o.setAttribute("data-markdown","table-wrapper");const s=document.createElement("div");s.className="flex items-center justify-end gap-1";const a=document.createElement("div");a.className="relative",a.appendChild(B("copy",e.copyTable,"table-copy-toggle")),a.appendChild(Ge("table-copy",[{key:"csv",label:"CSV"},{key:"tsv",label:"TSV"},{key:"markdown",label:"Markdown"}]));const l=document.createElement("div");l.className="relative",l.appendChild(B("download",e.downloadTable,"table-download-toggle")),l.appendChild(Ge("table-download",[{key:"csv",label:"CSV"},{key:"markdown",label:"Markdown"}])),s.appendChild(a),s.appendChild(l);const c=document.createElement("div");c.className="overflow-x-auto rounded-lg border border-border/80 bg-[var(--surface-elevated)]";const u=r.parentElement;if(!u)continue;u.replaceChild(o,r),r.setAttribute("data-markdown","table"),r.setAttribute(Pe,"pending"),r.classList.add("w-max","border-collapse","text-sm");for(const m of Array.from(r.querySelectorAll("tr")))m.classList.add("border-b","border-border/60");const f=r.querySelector("tbody tr:last-child");f?.classList.remove("border-b"),f?.classList.add("border-0");for(const m of Array.from(r.querySelectorAll("th")))m.classList.add("min-w-[120px]","max-w-[320px]","whitespace-normal","[overflow-wrap:anywhere]","border-r","border-border/60","px-4","py-2.5","text-left","align-middle","font-semibold","text-foreground","last:border-r-0");for(const m of Array.from(r.querySelectorAll("td")))m.classList.add("min-w-[120px]","max-w-[320px]","whitespace-normal","[overflow-wrap:anywhere]","border-r","border-border/60","px-4","py-2.5","align-middle","text-foreground/90","last:border-r-0");c.appendChild(r),o.appendChild(s),o.appendChild(c)}},Qn=t=>{const e=Array.from(t.querySelectorAll(`table[data-markdown="table"]:not([${Pe}="fixed"])`));if(e.length===0||!t.isConnected)return;const n=t.ownerDocument.createElement("div");n.setAttribute("aria-hidden","true"),n.setAttribute("data-md-table-measure",""),n.style.position="fixed",n.style.left="-100000px",n.style.top="0",n.style.visibility="hidden",n.style.pointerEvents="none",n.style.width="max-content";const r=e.map(o=>{const s=f=>Array.from(f.children).filter(m=>m.tagName==="TH"||m.tagName==="TD"),a=Array.from(o.querySelectorAll("tbody tr")),l=a.some(f=>s(f).length>0)?a:Array.from(o.querySelectorAll("thead tr")),c=Math.max(0,...Array.from(o.querySelectorAll("tr")).map(f=>s(f).length)),u=[];for(let f=0;f<c;f+=1){const m=t.ownerDocument.createElement("table");m.className=o.className,m.style.tableLayout="auto",m.style.width="max-content";const g=t.ownerDocument.createElement("tbody");for(const y of l){const v=s(y)[f];if(!v)continue;const C=t.ownerDocument.createElement("tr"),p=v.cloneNode(!0);p instanceof HTMLElement&&(p.style.width="auto",p.style.minWidth="0",p.style.maxWidth="none",p.style.whiteSpace="nowrap",p.style.overflowWrap="normal",C.appendChild(p),g.appendChild(C))}m.appendChild(g),n.appendChild(m),u.push(m)}return{table:o,columnProbes:u}});t.appendChild(n);const i=r.map(({table:o,columnProbes:s})=>({table:o,widths:s.map(a=>Math.min(Yn,Math.max(Gn,Math.ceil(a.getBoundingClientRect().width))))}));n.remove();for(const{table:o,widths:s}of i){Array.from(o.children).find(u=>u.matches("colgroup[data-md-table-columns]"))?.remove();const l=t.ownerDocument.createElement("colgroup");l.setAttribute("data-md-table-columns","");for(const u of s){const f=t.ownerDocument.createElement("col");f.style.width=`${u}px`,l.appendChild(f)}const c=Array.from(o.children).find(u=>u.tagName==="THEAD"||u.tagName==="TBODY"||u.tagName==="TFOOT")??null;o.insertBefore(l,c),o.style.tableLayout="fixed",o.style.width=`${s.reduce((u,f)=>u+f,0)}px`,o.setAttribute(Pe,"fixed")}},er=(t,e)=>{const n=t.querySelectorAll("pre > code.language-mermaid");for(const r of Array.from(n)){const i=r.parentElement;if(!i)continue;const o=(r.textContent??"").replace(/\s+$/,""),s=e.renderMermaid(o),a=document.createElement("div");a.setAttribute("data-markdown","mermaid-block"),a.setAttribute("data-md-source",o),a.className="group relative";const l=document.createElement("div");l.setAttribute("data-markdown","mermaid-scroll");const c=document.createElement("div");if(c.setAttribute("data-markdown","mermaid-toolbar"),c.className="absolute top-1 right-2 flex items-center gap-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity",s.svg){a.setAttribute("data-mermaid-render","svg");const f=document.createElement("div");f.setAttribute("data-markdown","mermaid-viewport");const m=document.createElement("div");if(m.setAttribute("data-markdown","mermaid"),m.setAttribute("data-md-original-svg",s.svg),m.innerHTML=s.svg,f.appendChild(m),l.appendChild(f),e.mermaidControls.showPanZoomControls&&(c.appendChild(B("zoomIn",e.labels.zoomInDiagram,"mermaid-zoom-in")),c.appendChild(B("zoomOut",e.labels.zoomOutDiagram,"mermaid-zoom-out")),c.appendChild(B("fit",e.labels.resetDiagramView,"mermaid-fit"))),e.mermaidControls.copy){const g=B("copy",e.labels.copyDiagram,"mermaid-copy");g.setAttribute("data-md-source",o),c.appendChild(g)}if(e.mermaidControls.download){const g=B("download",e.labels.downloadDiagram,"mermaid-download");g.setAttribute("data-md-svg","1"),c.appendChild(g)}}else{a.setAttribute("data-mermaid-render","ascii");const f=document.createElement("pre");if(f.setAttribute("data-markdown","mermaid-ascii"),f.textContent=s.ascii||o,l.appendChild(f),e.mermaidControls.copy){const m=B("copy",e.labels.copyDiagram,"mermaid-copy");m.setAttribute("data-md-source",s.ascii||o),c.appendChild(m)}}a.appendChild(l),a.appendChild(c);const u=i.parentElement;u&&u.replaceChild(a,i)}},tr=(t,e)=>{const n=t.querySelectorAll("a[href]");for(const r of Array.from(n)){if(r.getAttribute("data-md-link-decorated")==="true"||r.getAttribute("data-openchamber-file-link")==="true")continue;const i=r.getAttribute("href")??"";if(!at(i))continue;r.setAttribute("data-md-link-decorated","true");const o=jt(i);if(o){const s=document.createElement("span");s.className="mr-1 inline-flex size-[18px] items-center justify-center rounded border border-[var(--border)] bg-[var(--interactive-hover)] align-middle";const a=document.createElement("img");a.src=o,a.alt="",a.setAttribute("aria-hidden","true"),a.loading="lazy",a.decoding="async",a.className="size-3.5 rounded-sm",a.addEventListener("error",()=>s.remove(),{once:!0}),s.appendChild(a),r.parentNode?.insertBefore(s,r)}if(e.onPreviewLoopback&&Ut(i)){const s=document.createElement("button");s.type="button",s.className=`ml-1 align-middle ${kt}`,s.setAttribute("data-md-action","preview-loopback"),s.setAttribute("data-md-url",i),s.setAttribute("title",e.labels.previewTitle),s.setAttribute("aria-label",e.labels.previewLabel),ie(s,"download"),r.parentNode?.insertBefore(s,r.nextSibling)}}},pe=(t,e)=>{Kn(t),jn(t),er(t,e),Un(t,e),Jn(t,e.labels),tr(t,e)},Ye=(t,e,n)=>{const r=new Blob([e],{type:n}),i=URL.createObjectURL(r),o=document.createElement("a");o.href=i,o.download=t,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i)},fe=t=>{for(const e of Array.from(t.querySelectorAll("[data-md-menu]")))e.classList.add("hidden")},Je=t=>(t.nodeType===1?t:t.parentElement)?.closest("pre code[data-md-code-lines]")??null,nr=t=>{const e=Je(t.startContainer);return!e||e!==Je(t.endContainer)?null:t.toString()},he=new WeakMap,rr=t=>{let e=he.get(t);if(!e){const n=()=>{const o=t.getSelection();return!o||o.rangeCount!==1||o.isCollapsed?null:nr(o.getRangeAt(0))},r=o=>{if(!o.clipboardData)return;const s=n();s!==null&&(o.preventDefault(),o.stopPropagation(),o.clipboardData.setData("text/plain",s))},i=o=>{const s=n();s!==null&&(o.preventDefault(),we(s))};e={registrations:0,handler:r,menuHandler:i},he.set(t,e),t.addEventListener("copy",r,!0),t.defaultView?.addEventListener("openchamber:copy",i)}return e.registrations+=1,()=>{const n=he.get(t);n&&(n.registrations-=1,!(n.registrations>0)&&(t.removeEventListener("copy",n.handler,!0),t.defaultView?.removeEventListener("openchamber:copy",n.menuHandler),he.delete(t)))}},or=(t,e)=>{const n=rr(t.ownerDocument),r=i=>{const o=i.target;if(!(o instanceof Element))return;const s=o.closest("[data-md-action]");if(!s){fe(t);return}const a=s.getAttribute("data-md-action")??"";if(a==="copy-code"){const l=s.closest('[data-component="markdown-code"]')?.querySelector("code"),c=l?St(l):"";c&&(s.setAttribute("data-md-copy-pending",""),we(c).then(()=>je(s,e.labels.copied,"copy",e.labels.copy)).finally(()=>s.removeAttribute("data-md-copy-pending")));return}if(a==="toggle-code-wrap"){i.preventDefault(),e.onToggleCodeBlockLineWrap?.();return}if(a==="table-copy-toggle"||a==="table-download-toggle"){i.preventDefault();const l=s.parentElement?.querySelector("[data-md-menu]")??null,c=l?.classList.contains("hidden")??!1;fe(t),l&&c&&l.classList.remove("hidden");return}if(a.startsWith("table-copy-")){const l=a.replace("table-copy-",""),c=s.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(c instanceof HTMLTableElement){const u=Ue(c),f=l==="csv"?Ze(u):l==="tsv"?Xn(u):Xe(u);we(f)}fe(t);return}if(a.startsWith("table-download-")){const l=a.replace("table-download-",""),c=s.closest('[data-markdown="table-wrapper"]')?.querySelector("table");if(c instanceof HTMLTableElement){const u=Ue(c),f=l==="csv"?Ze(u):Xe(u);Ye(l==="csv"?"table.csv":"table.md",f,l==="csv"?"text/csv":"text/markdown")}fe(t);return}if(a==="mermaid-copy"){const l=s.getAttribute("data-md-source")??"";l&&we(l).then(()=>je(s,e.labels.copied,"copy",e.labels.copyDiagram));return}if(a==="mermaid-zoom-in"||a==="mermaid-zoom-out"||a==="mermaid-fit"){i.preventDefault();const l=s.closest('[data-markdown="mermaid-block"]'),c=zn(l);a==="mermaid-zoom-in"?c?.zoomIn():a==="mermaid-zoom-out"?c?.zoomOut():c?.fit();return}if(a==="mermaid-download"){const l=s.closest('[data-markdown="mermaid-block"]')?.querySelector('[data-markdown="mermaid"]'),c=l?.getAttribute("data-md-original-svg")??l?.innerHTML??"";c&&Ye("diagram.svg",c,"image/svg+xml;charset=utf-8");return}if(a==="preview-loopback"){i.preventDefault();const l=s.getAttribute("data-md-url")??"";l&&e.onPreviewLoopback?.(l);return}};return t.addEventListener("click",r),()=>{n(),t.removeEventListener("click",r)}},Qe=(t,e,n)=>{let r=0;for(const o of t){const s=r+o.data.length;if(e<s||e===s&&n==="left")return{node:o,offset:Math.max(0,e-r)};r=s}const i=t.at(-1);return i?{node:i,offset:i.data.length}:null},ir=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),et=Array.from(ir).map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),Lt=t=>Gt(t),sr=t=>Yt(t),ar=t=>{let e;try{e=new URL(t.trim())}catch{return null}if(e.protocol!=="file:"||e.hostname&&e.hostname!=="localhost")return null;try{const n=decodeURIComponent(e.pathname);return/^\/[A-Za-z]:\//.test(n)?n.slice(1):n.startsWith("/")?n:null}catch{return null}},Ae=t=>{let e=(t||"").trim();return e?((e.startsWith("`")&&e.endsWith("`")||e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1).trim()),e=e.replace(/[.,;!?]+$/g,""),e.endsWith(")")&&!e.includes("(")&&(e=e.slice(0,-1)),e.endsWith("]")&&!e.includes("[")&&(e=e.slice(0,-1)),e):""},ge=t=>{let e=Ae(t);if(!e)return"";const n=e.indexOf(";");n>=0&&(e=e.slice(0,n)),e=e.replace(/#.*$/,"");const r=e.match(/^(.*\.[A-Za-z0-9_-]{1,16}):.*$/);r&&(e=r[1]??e);const i=et.length>0?e.match(new RegExp(`^(.*(?:/|^)(${et})):.*$`,"i")):null;return i&&(e=i[1]??e),Ae(e)},Mt=t=>{const e=Ae(t);if(!e)return null;const n=e.indexOf(";"),r=n>=0?Ae(e.slice(0,n)):e;if(!r)return null;const i=r.match(/^(.*?):(\d+)-(\d+)$/);if(i){const l=ge(i[1]??""),c=Number.parseInt(i[2]??"",10),u=Number.parseInt(i[3]??"",10);return!l||!Number.isFinite(c)||!Number.isFinite(u)||u<c?null:{path:l,line:c,endLine:u}}const o=r.match(/^(.*)#L(\d+)(?:C(\d+))?$/i);if(o){const l=ge(o[1]??""),c=Number.parseInt(o[2]??"",10),u=o[3]?Number.parseInt(o[3],10):void 0;return!l||!Number.isFinite(c)?null:{path:l,line:c,column:Number.isFinite(u??Number.NaN)?u:void 0}}const s=r.match(/^(.*?):(\d+)(?::(\d+))?$/);if(s){const l=ge(s[1]??""),c=Number.parseInt(s[2]??"",10),u=s[3]?Number.parseInt(s[3],10):void 0;return!l||!Number.isFinite(c)?null:{path:l,line:c,column:Number.isFinite(u??Number.NaN)?u:void 0}}const a=ge(r);return a?{path:a}:null},Re=/(?:[A-Za-z]:[\\/])?[\w.\-/@+]*[\w\-/@+]\.[A-Za-z0-9]{1,8}(?::\d+(?:-\d+)?(?::\d+)?)?/g,lr=4,cr=1e3,dr=200,$=new Map;let be=0;const tt=[],ur=()=>pt()?dr:cr,mr=(t,e)=>`${t}\0${e}`,pr=(t,e)=>{const n=Lt(t);if(!n)return Promise.resolve(!1);const r=mr(e,n),i=$.get(r);if(i)return $.delete(r),$.set(r,i),i;const o=new Promise(a=>{const l=()=>{be+=1,an(`/api/fs/stat?path=${encodeURIComponent(n)}&optional=true`,{method:"GET",cache:"no-store",headers:e?{"x-opencode-directory":e}:void 0}).then(async c=>{if(!c.ok){a(!1);return}const u=await c.json().catch(()=>null);a(u?.exists!==!1)}).catch(()=>a(!1)).finally(()=>{be=Math.max(0,be-1),tt.shift()?.()})};if(be<lr){l();return}tt.push(l)}),s=ur();for(;$.size>=s;){const a=$.keys().next().value;if(typeof a!="string")break;$.delete(a)}return $.set(r,o),o},fr={maxSessions:8,maxEntriesPerSession:4};class hr{maxSessions;maxEntriesPerSession;sessions=new Map;constructor(e=fr){this.maxSessions=Math.max(1,e.maxSessions),this.maxEntriesPerSession=Math.max(1,e.maxEntriesPerSession)}store(e){const n=e.scope,r=e.id;let i=this.sessions.get(n);for(i===void 0?(i=new Map,this.sessions.set(n,i)):this.refreshSession(n,i),i.delete(r),i.set(r,e);i.size>this.maxEntriesPerSession;)this.removeOldestEntry(i);for(;this.sessions.size>this.maxSessions;)this.removeOldestSession()}take(e){const n=e.scope,r=this.sessions.get(n);if(!r)return null;const i=e.id;this.refreshSession(n,r);const o=r.get(i);return o===void 0||o.locale!==e.locale||o.directory!==e.directory?null:(r.delete(i),r.size===0&&this.sessions.delete(n),o.fragment)}clear(){this.sessions.clear()}stats(){let e=0;for(const n of this.sessions.values())e+=n.size;return{sessions:this.sessions.size,entries:e}}refreshSession(e,n){this.sessions.delete(e),this.sessions.set(e,n)}removeOldestEntry(e){const n=e.keys().next().value;n!==void 0&&e.delete(n)}removeOldestSession(){const e=this.sessions.keys().next().value;e!==void 0&&this.sessions.delete(e)}}const nt=new hr,Nt=()=>{const t=se.c(4),e=Jt();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=We(!1),t[0]=n):n=t[0];const r=n;let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=We(!0),t[1]=i):i=t[1];const o=i;let s;return t[2]!==e?.currentTheme?(s=e?.currentTheme??(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?o:r),t[2]=e?.currentTheme,t[3]=s):s=t[3],s},Rt=t=>{const e=se.c(4),{containerRef:n,enabled:r}=t;let i,o;e[0]!==n||e[1]!==r?(i=()=>{const s=n.current;if(s)return bn(s,{allowExternalHttp:r!==!1,openAppLink:Fr,openExternalHttp:Dr})},o=[n,r],e[0]=n,e[1]=r,e[2]=i,e[3]=o):(i=e[2],o=e[3]),E.useEffect(i,o)},Q={download:!0,copy:!0,showPanZoomControls:!0},Tt=!0,gr=t=>{const e=t.match(/^(?:\uFEFF)?(---|\+\+\+)[^\S\r\n]*\r?\n[\s\S]*?\r?\n\1[^\S\r\n]*(?:\r?\n|$)/);return e?t.slice(e[0].length):t},rt='[data-openchamber-file-link="true"]',_t="data-openchamber-block-path-token",xt=`[${_t}]`,Y="data-openchamber-block-paths-scanned",br=2e5,wr=80,yr=40,ot=160,Ar=()=>pt()?yr:wr,vr=new Set(["dockerfile","makefile","readme","license",".env",".gitignore",".npmrc"]),Pt=t=>Lt(t),kr=t=>sr(t),Er=(t,e)=>nn(t,e),Cr=t=>{const e=t.split("/").filter(Boolean).pop()??"";return!e||e.endsWith(".")?!1:/\.[A-Za-z0-9_-]{1,16}$/.test(e)},It=t=>{if(!t||t.startsWith("--")||t.includes("://")||/[<>]/.test(t)||/\s{2,}/.test(t))return!1;const e=Pt(t),n=e.split("/").filter(Boolean).pop()??e;if(!n||n==="."||n==="..")return!1;const r=n.toLowerCase();return vr.has(r)||r.startsWith(".")&&r.length>1?!0:Cr(e)},Ft=t=>{const e=Mt(t);return e?It(e.path):!1},Sr=t=>{const e=t.querySelectorAll(xt);for(const r of Array.from(e))r.replaceWith(t.ownerDocument.createTextNode(r.textContent??""));const n=t.querySelectorAll(`code[${Y}]`);for(const r of Array.from(n))r.removeAttribute(Y),r.normalize()},Te=t=>{if(t.tagName.toLowerCase()==="a"){const e=t.getAttribute("href")?.trim(),n=e?ar(e):null;if(n)return n;if(e&&Ft(e))return e}return(t.textContent||"").trim()},Lr=t=>{const e=t.querySelectorAll("pre code");if(e.length===0)return;const n=t.ownerDocument;if(n)for(const r of Array.from(e)){if(r.getAttribute(Y)==="true")continue;if((r.textContent??"").length>br){r.setAttribute(Y,"true");continue}const i=n.createTreeWalker(r,NodeFilter.SHOW_TEXT),o=[];let s=i.nextNode();for(;s;){const u=s;u.parentElement?.closest("[data-md-code-line-number]")||o.push(u),s=i.nextNode()}const a=St(r);if(!a.includes(".")){r.setAttribute(Y,"true");continue}Re.lastIndex=0;const l=[];let c=Re.exec(a);for(;c;){const u=c[0];u&&Ft(u)&&l.push({start:c.index,end:c.index+u.length,raw:u}),c=Re.exec(a)}for(const{start:u,end:f,raw:m}of l.reverse()){const g=Qe(o,u,"right"),y=Qe(o,f,"left");if(!g||!y)continue;const v=n.createRange();v.setStart(g.node,g.offset),v.setEnd(y.node,y.offset);const C=n.createElement("span");C.setAttribute(_t,"true"),C.textContent=m,v.deleteContents(),v.insertNode(C)}r.setAttribute(Y,"true")}},_e=(t,e)=>{const n=Mt(t);if(!n||!It(n.path))return null;const r=kr(n.path)?Pt(n.path):Er(e,n.path);return r?{...n,resolvedPath:r}:null},Mr=(t,e)=>t||tn(t,e),Dt=({containerRef:t,effectiveDirectory:e,editor:n,preferRuntimeEditor:r,enabled:i})=>{const o=E.useRef(null);E.useEffect(()=>{const s=t.current;if(!s||i&&!e)return;let a=!1;const l=Ar(),c=i&&!mn(),u=d=>{d.removeAttribute("data-openchamber-file-link"),d.removeAttribute("data-openchamber-file-ref"),d.removeAttribute("data-openchamber-file-path"),d.getAttribute("title")==="Open file"&&d.removeAttribute("title"),d.tagName.toLowerCase()!=="a"&&(d.removeAttribute("role"),d.removeAttribute("tabindex"))},f=()=>{const d=s.querySelectorAll(rt);for(const b of Array.from(d))u(b);Sr(s)};if(!c){f();return}const m=(d=0)=>{if(o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),typeof window>"u"){g();return}o.current=window.setTimeout(()=>{o.current=null,window.requestAnimationFrame(()=>{a||g()})},d)},g=()=>{h+=1;try{y()}finally{queueMicrotask(()=>{h-=1})}},y=()=>{c&&Lr(s);const d=s.querySelectorAll(`[data-markdown="inline-code"], a, ${xt}`);let b=0;for(const w of Array.from(d)){const A=Te(w),L=_e(A,e);if(u(w),!L||b>=l)continue;b+=1,(dn()&&un()&&!qe(L.resolvedPath,e)?Promise.resolve(!0):pr(L.resolvedPath,e)).then(M=>{if(a||!M||!s.contains(w))return;const N=Te(w),S=_e(N,e);!S||S.resolvedPath!==L.resolvedPath||(w.setAttribute("data-openchamber-file-link","true"),w.setAttribute("data-openchamber-file-ref",N),w.setAttribute("data-openchamber-file-path",S.resolvedPath),w.setAttribute("title","Open file"),w.tagName.toLowerCase()!=="a"&&(w.setAttribute("role","button"),w.setAttribute("tabindex","0")))})}},v=async d=>{const b=d.getAttribute("data-openchamber-file-ref")||Te(d),w=_e(b,e);if(!w)return;const A=Mr(e,w.resolvedPath);if(r&&n){n.openFile(w.resolvedPath,Number.isFinite(w.line??Number.NaN)?Math.max(1,Math.trunc(w.line)):void 0,Number.isFinite(w.column??Number.NaN)?Math.max(1,Math.trunc(w.column)):void 0);return}qe(w.resolvedPath,e)||await en(w.resolvedPath,e);const L=G.getState();Number.isFinite(w.line??Number.NaN)?L.openContextFileAtLine(A,w.resolvedPath,Math.max(1,Math.trunc(w.line)),Number.isFinite(w.column??Number.NaN)?Math.max(1,Math.trunc(w.column)):1):L.openContextFile(A,w.resolvedPath)},C=d=>{const b=d.target;if(!(b instanceof Element))return;const w=b.closest(rt);w instanceof HTMLElement&&(d.preventDefault(),d.stopPropagation(),v(w))},p=d=>{if(d.key!=="Enter"&&d.key!==" ")return;const b=d.target;!(b instanceof HTMLElement)||b.getAttribute("data-openchamber-file-link")!=="true"||(d.preventDefault(),d.stopPropagation(),v(b))};m(ot);let h=0;const k=new MutationObserver(()=>{h>0||m(ot)});return k.observe(s,{childList:!0,subtree:!0}),s.addEventListener("click",C),s.addEventListener("keydown",p),()=>{a=!0,o.current!==null&&typeof window<"u"&&window.clearTimeout(o.current),o.current=null,k.disconnect(),s.removeEventListener("click",C),s.removeEventListener("keydown",p)}},[t,n,e,r,i])},Ot=t=>{const e=se.c(7),{containerRef:n,onShowPopup:r,enableFullscreen:i,enablePanZoom:o,allowMermaidWheelEvents:s}=t;let a,l;e[0]!==s||e[1]!==n||e[2]!==i||e[3]!==o||e[4]!==r?(a=()=>{const c=n.current;if(!c)return;const u=m=>{if(!i||!r)return;const g=m.target;if(!(g instanceof Element)||g.closest('button, a, [role="button"]'))return;const y=g.closest(re);if(!y)return;if(y instanceof HTMLElement&&y.hasAttribute("data-mermaid-suppress-click")){y.removeAttribute("data-mermaid-suppress-click");return}const C=Array.from(c.querySelectorAll(re)).indexOf(y);if(C<0)return;const p=y instanceof HTMLElement?y.getAttribute("data-md-source"):null;if(!p||p.trim().length===0)return;const h=`Diagram ${C+1}`;r({open:!0,title:h,content:"",metadata:{tool:"mermaid-preview",filename:h},mermaid:{url:`data:text/plain;charset=utf-8,${encodeURIComponent(p)}`,source:p,filename:h}})},f=m=>{if(s||(m.ctrlKey||m.metaKey)&&o)return;const g=m.target;!(g instanceof Element)||!g.closest(re)||m.stopPropagation()};return c.addEventListener("click",u),c.addEventListener("wheel",f,{capture:!0,passive:!0}),()=>{c.removeEventListener("click",u),c.removeEventListener("wheel",f,!0)}},l=[s,n,i,o,r],e[0]=s,e[1]=n,e[2]=i,e[3]=o,e[4]=r,e[5]=a,e[6]=l):(a=e[5],l=e[6]),E.useEffect(a,l)},z=new Map,Nr=100,H="data-md-decoration-id",Rr=(t,e,n)=>{const r=t.children;if(r.length!==e.length)return!1;for(let i=0;i<e.length;i+=1){const o=r[i];if(!o||o.getAttribute("data-md-id")!==e[i]?.id||o.getAttribute(H)!==n)return!1}return!0},it=new WeakMap;let st=0;const Tr=2e5,xe=t=>{const e=it.get(t);if(e)return e;const n=`decoration-${st}`;return st+=1,it.set(t,n),n},_r=(t,e)=>{const n=z.get(t);if(n)return z.delete(t),z.set(t,n),n;const r=e();if(z.set(t,r),z.size>Nr){const i=z.keys().next().value;i&&z.delete(i)}return r},xr=t=>({bg:t.colors.surface.elevated,fg:t.colors.surface.foreground,line:t.colors.interactive.border,accent:t.colors.primary.base,muted:t.colors.surface.mutedForeground,surface:t.colors.surface.muted,border:t.colors.interactive.border,transparent:!0,font:"system-ui, sans-serif"}),Wt=(t,e,n,r=Q)=>{const{t:i}=ut(),o=E.useMemo(()=>({copy:i("markdownRenderer.code.actions.copyTitle"),copied:i("markdownRenderer.code.actions.copiedTitle"),enableCodeWrap:i("markdownRenderer.code.actions.enableWrapTitle"),disableCodeWrap:i("markdownRenderer.code.actions.disableWrapTitle"),copyTable:i("markdownRenderer.table.actions.copyTitle"),downloadTable:i("markdownRenderer.table.actions.downloadTitle"),copyDiagram:i("markdownRenderer.mermaid.actions.copySourceTitle"),downloadDiagram:i("markdownRenderer.mermaid.actions.downloadSvgTitle"),zoomInDiagram:i("markdownRenderer.mermaid.actions.zoomInTitle"),zoomOutDiagram:i("markdownRenderer.mermaid.actions.zoomOutTitle"),resetDiagramView:i("markdownRenderer.mermaid.actions.resetViewTitle"),previewLabel:i("terminalView.preview.open"),previewTitle:i("terminalView.preview.openTitle")}),[i]),s=G(c=>c.codeBlockLineWrap),a=G(c=>c.setCodeBlockLineWrap),l=E.useCallback(()=>{a(!G.getState().codeBlockLineWrap)},[a]);return E.useMemo(()=>{const c=xr(t),u=G.getState().mermaidRenderingMode,f=t.metadata?.id??"theme";return{labels:o,mermaidControls:r,codeBlockLineWrap:s,deferCodeLineNumberSync:e,onToggleCodeBlockLineWrap:l,renderMermaid:g=>_r(`${f}:${u}:${g}`,()=>{try{return u==="ascii"?{ascii:Ht(g)}:{svg:Vt(g,c)}}catch{return{}}}),onPreviewLoopback:n}},[t,o,r,s,e,l,n])},qt=({containerRef:t,text:e,streaming:n,imageMode:r="inline",syntaxVars:i,ctx:o,domCacheKey:s,tableLayoutSettled:a})=>{E.useEffect(()=>{yn()},[]);const l=E.useRef(null),c=E.useRef(0),u=E.useRef(null),f=E.useContext(Qt),m=E.useRef(null),g=E.useCallback(()=>{m.current?.(),m.current=null},[]);E.useEffect(()=>g,[g]);const y=E.useRef(null),v=E.useCallback(()=>{const p=t.current;if(p){if(!l.current){if(!I(p))return;l.current=Hn(p);return}l.current.refresh()}},[t]),C=E.useCallback(()=>{if(!a)return;const p=u.current;p!==null&&window.cancelAnimationFrame(p);const h=c.current,k=window.requestAnimationFrame(()=>{if(u.current!==k||(u.current=null,c.current!==h))return;const d=t.current,b=d?.querySelector("[data-markdown-content]")??d;b&&Qn(b)});u.current=k},[t,a]);E.useEffect(()=>()=>{const p=u.current;p!==null&&(window.cancelAnimationFrame(p),u.current=null)},[]),E.useLayoutEffect(()=>{c.current+=1,y.current=null},[o,r,n,e]),E.useLayoutEffect(()=>{if(!s)return;const p=t.current,h=p?.querySelector("[data-markdown-content]")??p;if(!h||h.childNodes.length>0)return;const k=nt.take(s);if(k){h.appendChild(k);const d=xe(o);for(const b of Array.from(h.children))b.setAttribute(H,d);for(const[b,w]of Object.entries(i))h.style.setProperty(b,w);Ke(h,o.codeBlockLineWrap,o.labels),y.current={key:s,copiedLabel:o.labels.copied},ne("ui.markdown_renderer.dom_cache.hit")}},[t,o,s,i,e.length]),E.useLayoutEffect(()=>{const p=t.current,h=p?.querySelector("[data-markdown-content]")??p;if(h)return()=>{const k=y.current;if(!k||h.childNodes.length===0||I(h)||Array.from(h.children).some(L=>!L.hasAttribute("data-md-id"))||h.querySelector("[data-md-copy-pending]"))return;const d=window.getSelection();if(d?.rangeCount&&!d.isCollapsed&&d.getRangeAt(0).intersectsNode(h))return;const b=h.querySelector("[data-md-menu]:not(.hidden)"),w=Array.from(h.querySelectorAll("[data-md-action]")).some(L=>L.getAttribute("title")===k.copiedLabel);if(b||w)return;const A=document.createDocumentFragment();A.append(...Array.from(h.childNodes)),nt.store({...k.key,fragment:A}),ne("ui.markdown_renderer.dom_cache.capture")}},[t]),E.useLayoutEffect(()=>{const p=t.current,h=p?.querySelector("[data-markdown-content]")??p;if(!h)return;const k=xe(o);if(e&&h.childNodes.length===0){const d=n?null:Be(e,r);if(d){let b=!1;for(const w of d){const A=document.createElement("div");A.setAttribute("data-md-block",""),A.style.display="contents",A.innerHTML=w.html,pe(A,o),A.setAttribute("data-md-id",w.id),A.setAttribute(H,k),b||=I(A),h.appendChild(A)}b&&v()}else{!n&&!m.current&&(m.current=f?.hold()??null);const b=document.createElement("div");b.setAttribute("data-md-block",""),b.style.display="contents",b.innerHTML=pn(e,r),pe(b,o),b.setAttribute(H,k),h.appendChild(b),I(b)&&v()}}else!l.current&&I(h)&&v()},[t,e,n,r,o,v,f]),E.useEffect(()=>()=>{l.current?.cleanup(),l.current=null},[]),E.useEffect(()=>{const p=t.current;if(!p)return;const h=p.querySelector("[data-markdown-content]")??p;let k=!0;const d=c.current,b=xe(o);if(!n){const w=Be(e,r);if(w&&Rr(h,w,b)){y.current=s?{key:s,copiedLabel:o.labels.copied}:null,ne("ui.markdown_renderer.settled_paint.reused"),C(),g();return}}return fn(e,n,r).then(w=>{if(!k||c.current!==d)return;const A=Array.from(h.children);let L=0;w.forEach((M,N)=>{let S=A[N],F=!1;if(S||(S=document.createElement("div"),S.setAttribute("data-md-block",""),S.style.display="contents",h.appendChild(S),F=!0),S.getAttribute("data-md-id")===M.id){if(S.getAttribute(H)!==b){const x=I(S);x&&(l.current?.cleanup(),l.current=null);const R=document.createElement("div");R.setAttribute("data-md-block",""),R.style.display="contents",R.innerHTML=M.html,pe(R,o),R.setAttribute("data-md-id",M.id),R.setAttribute(H,b),S.replaceWith(R),(x||I(R))&&v()}!l.current&&I(S)&&v();return}const _=document.createElement("div");if(_.innerHTML=M.html,pe(_,o),F&&n&&N>0){const x=Math.min(L,4)*55;L+=1;for(const R of Array.from(_.children))R.classList.add("oc-md-block-enter"),x>0&&R instanceof HTMLElement&&R.style.setProperty("--oc-md-enter-delay",`${x}ms`)}const P=I(S),D=I(_);zt(S,_,{childrenOnly:!0,onBeforeElUpdated:(x,R)=>!x.isEqualNode(R)}),S.setAttribute("data-md-id",M.id),S.setAttribute(H,b),(P||D||I(S))&&v()});const O=I(h);let W=!1;for(let M=A.length-1;M>=w.length;M-=1){const N=A[M];N&&I(N)&&(W=!0),N?.remove()}(W||A.length>w.length&&O)&&v(),y.current=s?{key:s,copiedLabel:o.labels.copied}:null,C(),g()}),()=>{k=!1}},[t,o,s,r,v,g,C,n,e]),E.useEffect(()=>{const p=t.current;if(p)return or(p,o)},[t,o]),E.useEffect(()=>{const p=t.current,h=p?.querySelector("[data-markdown-content]")??p;if(h)for(const[k,d]of Object.entries(i))h.style.setProperty(k,d)},[t,i]),E.useEffect(()=>{const p=t.current,h=p?.querySelector("[data-markdown-content]")??p;h&&(o.deferCodeLineNumberSync||Ke(h,o.codeBlockLineWrap,o.labels))},[t,o.codeBlockLineWrap,o.deferCodeLineNumberSync,o.labels])},Bt=t=>t==="tool"?"markdown-content markdown-tool":t==="reasoning"?"markdown-content markdown-reasoning":"markdown-content leading-relaxed",Pr=t=>{const e=se.c(40),{content:n,part:r,messageId:i,isAnimated:o,skipFadeIn:s,className:a,isStreaming:l,disableStreamAnimation:c,variant:u,onShowPopup:f,enableFileReferences:m}=t,g=o===void 0?!0:o,y=s===void 0?!1:s,v=l===void 0?!1:l,C=c===void 0?!1:c,p=u===void 0?"assistant":u,h=m===void 0?!0:m;ne("ui.markdown_renderer.render"),v&&ne("ui.markdown_renderer.render.streaming"),ln("ui.markdown_renderer.content_len",n.length);const k=Nt(),{editor:d,runtime:b}=lt(),w=E.useRef(null),A=ct()??"",L=G(Or);let O;e[0]!==A||e[1]!==L?(O=q=>{A&&L(A,q)},e[0]=A,e[1]=L,e[2]=O):O=e[2];const W=O,M=v&&!C;let N;e[3]!==f?(N={containerRef:w,onShowPopup:f,enableFullscreen:Tt,enablePanZoom:Q.showPanZoomControls},e[3]=f,e[4]=N):N=e[4],Ot(N);const S=h&&!v;let F;e[5]!==d||e[6]!==A||e[7]!==b.isVSCode||e[8]!==S?(F={containerRef:w,effectiveDirectory:A,editor:d,preferRuntimeEditor:b.isVSCode,enabled:S},e[5]=d,e[6]=A,e[7]=b.isVSCode,e[8]=S,e[9]=F):F=e[9],Dt(F);let _;e[10]===Symbol.for("react.memo_cache_sentinel")?(_={containerRef:w},e[10]=_):_=e[10],Rt(_);let P;e[11]!==k?(P=dt(k),e[11]=k,e[12]=P):P=e[12];const D=P,x=Wt(k,M,A?W:void 0,Q),{locale:R}=ut(),ae=p==="assistant"?"label":"inline",ve=r&&(r.type==="text"||r.type==="reasoning")&&r.time?.end!==void 0?r:null;let le;e[13]===Symbol.for("react.memo_cache_sentinel")?(le=cn(),e[13]=le):le=e[13];const $t=le,Fe=ve?.sessionID,De=ve?.messageID,Oe=ve?.id;let ke;e:{if(v||!Fe||!De||!Oe||n.length===0||n.length>Tr){ke=null;break e}const q=`${$t}\0${Fe}`,Le=`${De}\0${Oe}\0${ae}\0${n.length}`;let me;e[14]!==A||e[15]!==R||e[16]!==q||e[17]!==Le?(me={scope:q,id:Le,locale:R,directory:A},e[14]=A,e[15]=R,e[16]=q,e[17]=Le,e[18]=me):me=e[18],ke=me}const Ee=ke,Ce=`markdown-${r?.id?`part-${r.id}`:`message-${i}`}`,Se=!v;let ce;e[19]!==n||e[20]!==x||e[21]!==Ee||e[22]!==ae||e[23]!==M||e[24]!==D||e[25]!==Se?(ce={containerRef:w,text:n,streaming:M,imageMode:ae,syntaxVars:D,ctx:x,domCacheKey:Ee,tableLayoutSettled:Se},e[19]=n,e[20]=x,e[21]=Ee,e[22]=ae,e[23]=M,e[24]=D,e[25]=Se,e[26]=ce):ce=e[26],qt(ce);let j;e[27]!==a?(j=mt("break-words w-full min-w-0",a),e[27]=a,e[28]=j):j=e[28];let U;e[29]!==p?(U=Bt(p),e[29]=p,e[30]=U):U=e[30];let Z;e[31]!==U?(Z=te.jsx("div",{className:U,"data-markdown-content":!0}),e[31]=U,e[32]=Z):Z=e[32];let de;e[33]!==j||e[34]!==Z?(de=te.jsx("div",{className:j,ref:w,children:Z}),e[33]=j,e[34]=Z,e[35]=de):de=e[35];const ue=de;if(g){let q;return e[36]!==Ce||e[37]!==ue||e[38]!==y?(q=te.jsx(rn,{skipAnimation:y,children:ue},Ce),e[36]=Ce,e[37]=ue,e[38]=y,e[39]=q):q=e[39],q}return ue},$i=E.memo(Pr,(t,e)=>t.content===e.content&&t.isStreaming===e.isStreaming&&t.disableStreamAnimation===e.disableStreamAnimation&&t.variant===e.variant&&t.isAnimated===e.isAnimated&&t.skipFadeIn===e.skipFadeIn&&t.className===e.className&&t.messageId===e.messageId&&t.onShowPopup===e.onShowPopup&&t.enableFileReferences===e.enableFileReferences&&t.part?.id===e.part?.id),Ir=t=>{const e=se.c(29),{content:n,className:r,variant:i,disableLinkSafety:o,stripFrontmatter:s,onShowPopup:a,mermaidControls:l,allowMermaidWheelEvents:c,enableFileReferences:u}=t,f=i===void 0?"assistant":i,m=s===void 0?!1:s,g=l===void 0?Q:l,y=c===void 0?!1:c,v=u===void 0?!0:u,{editor:C,runtime:p}=lt(),h=Nt(),k=E.useRef(null),d=ct()??"";let b;e[0]!==n||e[1]!==m?(b=m?gr(n):n,e[0]=n,e[1]=m,e[2]=b):b=e[2];const w=b;let A;e[3]!==y||e[4]!==g.showPanZoomControls||e[5]!==a?(A={containerRef:k,onShowPopup:a,enableFullscreen:Tt,enablePanZoom:g.showPanZoomControls,allowMermaidWheelEvents:y},e[3]=y,e[4]=g.showPanZoomControls,e[5]=a,e[6]=A):A=e[6],Ot(A);let L;e[7]!==C||e[8]!==d||e[9]!==v||e[10]!==p.isVSCode?(L={containerRef:k,effectiveDirectory:d,editor:C,preferRuntimeEditor:p.isVSCode,enabled:v},e[7]=C,e[8]=d,e[9]=v,e[10]=p.isVSCode,e[11]=L):L=e[11],Dt(L);const O=!o;let W;e[12]!==O?(W={containerRef:k,enabled:O},e[12]=O,e[13]=W):W=e[13],Rt(W);let M;e[14]!==h?(M=dt(h),e[14]=h,e[15]=M):M=e[15];const N=M,S=Wt(h,!1,void 0,g);let F;e[16]!==S||e[17]!==w||e[18]!==N?(F={containerRef:k,text:w,streaming:!1,syntaxVars:N,ctx:S,tableLayoutSettled:!0},e[16]=S,e[17]=w,e[18]=N,e[19]=F):F=e[19],qt(F);let _;e[20]!==r?(_=mt("break-words w-full min-w-0",r),e[20]=r,e[21]=_):_=e[21];let P;e[22]!==f?(P=Bt(f),e[22]=f,e[23]=P):P=e[23];let D;e[24]!==P?(D=te.jsx("div",{className:P,"data-markdown-content":!0}),e[24]=P,e[25]=D):D=e[25];let x;return e[26]!==_||e[27]!==D?(x=te.jsx("div",{className:_,ref:k,children:D}),e[26]=_,e[27]=D,e[28]=x):x=e[28],x},zi=E.memo(Ir,(t,e)=>{const n=t.mermaidControls??Q,r=e.mermaidControls??Q;return t.content===e.content&&t.variant===e.variant&&t.className===e.className&&t.disableLinkSafety===e.disableLinkSafety&&t.stripFrontmatter===e.stripFrontmatter&&t.onShowPopup===e.onShowPopup&&n.download===r.download&&n.copy===r.copy&&n.showPanZoomControls===r.showPanZoomControls&&t.allowMermaidWheelEvents===e.allowMermaidWheelEvents&&t.enableFileReferences===e.enableFileReferences});function Fr(t){on(t)}function Dr(t){sn(t)}function Or(t){return t.openContextPreview}export{$i as MarkdownRenderer,zi as SimpleMarkdownRenderer};
@@ -1 +1 @@
1
- import{r as _,j as e,R as i,f as J}from"./vendor-react-BUCujlKS.js";import{K as V,ck as we,ch as le,cd as G,z as $,ar as P,dl as je,r as z,U as ue,az as me,a7 as pe,R as ne}from"./index-DDInLQDd.js";import{f as Q,B as L,T as Y,g as he,h as re,I as A}from"./useAppFontEffects-CCgvcQ6u.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-zod-DVWEh-IS.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-CV-DwAiX.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-BxpoC5Fp.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";function ke(a){switch(a){case"ok":return null;case"auth":return"onboarding.remoteConnection.probe.authMessage";case"update-recommended":return"onboarding.remoteConnection.probe.updateRecommendedMessage";case"incompatible":return"onboarding.remoteConnection.probe.incompatibleMessage";case"wrong-service":return"onboarding.remoteConnection.probe.wrongServiceMessage";case"unreachable":return"onboarding.remoteConnection.probe.unreachableMessage";default:return null}}function oe(a){return a==="wrong-service"||a==="unreachable"||a==="incompatible"}function xe({onBack:a,showBackButton:t=!0,initialUrl:s="",initialLabel:r="",isRecoveryMode:n=!1,onConnect:l,onSwitchToLocal:u,showInstancePicker:h=!1}){const{t:o}=Q(),[w,S]=_.useState(s),[j,U]=_.useState(r),[K,x]=_.useState("idle"),[m,k]=_.useState(null),[C,g]=_.useState(""),[T,I]=_.useState([]),[y,f]=_.useState(()=>h?"instances":"add"),[b,R]=_.useState("");_.useEffect(()=>{h&&V().then(p=>I(p.hosts)).catch(p=>{g(p instanceof Error?p.message:String(p))})},[h]);const N=we(w),E=N?.persistedUrl??null,F=_.useCallback(p=>{S(p.target.value),x("idle"),k(null),g("")},[]),O=_.useCallback(p=>{U(p.target.value)},[]),c=_.useCallback(async()=>{if(E){x("testing"),k(null),g("");try{const p=await le(E);k(p),x(p.status==="ok"||p.status==="update-recommended"?"success":"error")}catch(p){g(p instanceof Error?p.message:o("onboarding.remoteConnection.errors.connectionTestFailed")),x("error")}}},[E,o]),D=_.useCallback(async()=>{if(!N)return;const p=N.persistedUrl;x("testing"),k(null),g("");try{const H=await le(p);if(k(H),oe(H.status)){x("error");return}const Z=await V(),ye=j.trim()||p,ee=Z.hosts.find(X=>X.url===p),te=ee?ee.id:`host-${Date.now().toString(16)}`,ie={id:te,label:ye,url:p,apiUrl:p},ve=ee?Z.hosts.map(X=>X.id===te?ie:X):[...Z.hosts,ie];if(await G({hosts:ve,defaultHostId:te,initialHostChoiceCompleted:!0}),l?.(),N.redeemUrl){window.location.assign(N.redeemUrl);return}$()&&await P()}catch(H){g(H instanceof Error?H.message:o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[N,j,l,o]),B=_.useCallback(async p=>{const H=await V();await G({hosts:H.hosts,defaultHostId:p,initialHostChoiceCompleted:!0}),await P()},[]),d=_.useCallback(async()=>{x("testing"),g("");try{const p=await V(),H=await je(b,p.hosts);await G({hosts:H.hosts,defaultHostId:H.hostId,initialHostChoiceCompleted:!0}),await P()}catch(p){g(p instanceof Error&&p.message==="invalid-connect-link"?o("settings.remoteInstances.direct.error.invalidConnectLink"):o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[b,o]),v=K==="testing",M=E!==null&&!v,W=E!==null&&!v&&!oe(m?.status??null),q=ke(m?.status??null),fe=m?.status==="ok",be=m?.status==="update-recommended",ge=m?.status==="auth",ae=oe(m?.status??null);return h&&y==="instances"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("desktopHostSwitcher.actions.switchInstance")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.description")})]}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx("div",{className:"space-y-2",children:T.length===0?e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:o("settings.remoteInstances.direct.state.empty")}):T.map(p=>e.jsx(L,{variant:"outline",className:"w-full justify-start",onClick:()=>{B(p.id)},children:e.jsx("span",{className:"min-w-0 truncate",children:p.label})},p.id))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{variant:"outline",className:"flex-1",onClick:()=>f("import"),children:o("settings.remoteInstances.direct.import.action")}),e.jsx(L,{className:"flex-1",onClick:()=>f("add"),children:o("settings.remoteInstances.direct.actions.add")})]})]})}):h&&y==="import"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsx(L,{variant:"ghost",onClick:()=>f("instances"),className:"p-0 text-muted-foreground",children:o("onboarding.common.actions.back")}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("settings.remoteInstances.direct.import.action")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.import.description")})]}),e.jsx(Y,{value:b,onChange:p=>R(p.target.value),placeholder:o("settings.remoteInstances.direct.import.placeholder"),disabled:v,autoFocus:!0}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx(L,{onClick:()=>{d()},disabled:v||!b.trim(),children:o("settings.remoteInstances.direct.import.action")})]})}):e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[(t||h)&&e.jsx("div",{className:"flex items-center",children:e.jsx(L,{variant:"ghost",onClick:h?()=>f("instances"):a,className:"p-0 text-muted-foreground hover:text-foreground",children:o("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o(n?"onboarding.remoteConnection.titleRecovery":"onboarding.remoteConnection.title")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("onboarding.remoteConnection.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-url",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.serverAddress")}),e.jsx(Y,{id:"remote-url",type:"url",value:w,onChange:F,placeholder:o("onboarding.remoteConnection.field.serverAddressPlaceholder"),disabled:v})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-label",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.nameOptional")}),e.jsx(Y,{id:"remote-label",type:"text",value:j,onChange:O,placeholder:o("onboarding.remoteConnection.field.namePlaceholder"),disabled:v})]})]}),m&&fe&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-success)",color:"var(--status-success)"},children:o("onboarding.remoteConnection.status.connectedSuccessfully",{latencyMs:m.latencyMs})}),m&&ge&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:o("onboarding.remoteConnection.status.authWarning")}),m&&be&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:q?o(q):null}),m&&ae&&e.jsxs("div",{className:"rounded-lg border p-3 text-sm space-y-3",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold mb-1",children:o("onboarding.remoteConnection.status.connectionFailed")}),e.jsx("div",{className:"opacity-90",children:q?o(q):null})]}),e.jsx("div",{className:"text-xs opacity-80",children:m.status==="unreachable"?o("onboarding.remoteConnection.status.suggestionsUnreachable"):o("onboarding.remoteConnection.status.suggestionsWrongService")})]}),C&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:C}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(L,{variant:"outline",onClick:c,disabled:!M,children:o(v?"onboarding.remoteConnection.actions.testing":"onboarding.remoteConnection.actions.testConnection")}),e.jsx(L,{onClick:D,disabled:!W,children:o("onboarding.remoteConnection.actions.connectAndRestart")})]}),ae&&e.jsxs("div",{className:"flex flex-col gap-2 pt-2 border-t border-border",children:[e.jsx("div",{className:"text-xs text-muted-foreground text-center",children:o("onboarding.remoteConnection.actions.whatToDo")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:a,className:"flex-1",children:o("onboarding.remoteConnection.actions.chooseDifferentServer")}),!n&&u&&e.jsx(L,{variant:"outline",size:"sm",onClick:u,className:"flex-1",children:o("onboarding.remoteConnection.actions.useLocalInstead")})]})]})]})})}const Ce="curl -fsSL https://opencode.ai/install | bash",Ne="https://opencode.ai/docs",ce=2500;function Se(a){const t=J.c(5),{onCopy:s,copyTitle:r}=a;let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=e.jsxs("code",{className:"flex-1 text-left overflow-x-auto whitespace-nowrap",children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]}),t[0]=n):n=t[0];let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l=e.jsx(A,{name:"file-copy",className:"h-4 w-4"}),t[1]=l):l=t[1];let u;return t[2]!==r||t[3]!==s?(u=e.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[n,e.jsx("button",{onClick:s,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors shrink-0",title:r,"aria-label":r,children:l})]}),t[2]=r,t[3]=s,t[4]=u):u=t[4],u}function Re({onCliAvailable:a,localAvailable:t=!0}){const{t:s}=Q(),[r,n]=i.useState(!1),[l,u]=i.useState(!1),[h,o]=i.useState(!1),[w,S]=i.useState(!1),[j,U]=i.useState(""),[K,x]=i.useState("unknown"),[m,k]=i.useState(()=>t?"local":"remote"),[C,g]=i.useState(!1),[T,I]=i.useState(!1);i.useEffect(()=>{u($())},[]),i.useEffect(()=>{if(typeof navigator>"u"){x("unknown");return}const d=navigator.userAgent||"";/Windows/i.test(d)?x("windows"):/Macintosh|Mac OS X/i.test(d)?x("macos"):/Linux/i.test(d)?x("linux"):x("unknown")},[]),i.useEffect(()=>{let d=!1;return(async()=>{try{const v=await z("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!v.ok)return;const M=await v.json().catch(()=>null);if(!M||d)return;const W=typeof M.opencodeBinary=="string"?M.opencodeBinary.trim():"";W&&U(W)}catch{}})(),()=>{d=!0}},[]);const y=i.useCallback(async d=>{const v=d.target;v.closest(".app-region-no-drag")||v.closest("button, a, input, select, textarea, code, summary, details")||d.button===0&&l&&await ue()},[l]),f=i.useCallback(async()=>{try{const d=await z("/health");if(!d.ok)return!1;const v=await d.json();return v.openCodeRunning===!0||v.isOpenCodeReady===!0}catch{return!1}},[]),b=i.useCallback(async d=>{if(!l)return;const v=await V();await G({...v,...d==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})},[l]),R=i.useCallback(async()=>{l&&await b("local"),a?.()},[l,a,b]);i.useEffect(()=>{if(!t||m!=="local")return;let d=!1,v=null;const M=async()=>{if(!d){try{const W=await f();if(d)return;if(W){await R();return}}catch{}d||(v=setTimeout(M,ce))}};return v=setTimeout(M,ce),()=>{d=!0,v&&clearTimeout(v)}},[m,f,R,t]);const N=i.useCallback(async()=>{S(!0);try{await f()&&await R()}finally{S(!1)}},[f,R]),E=i.useCallback(async()=>{if(!(typeof window>"u")&&l)try{const d=await me();d.success&&d.path&&d.path.trim().length>0&&U(d.path.trim())}catch{}},[l]),F=i.useCallback(async()=>{o(!0);try{if(await pe({opencodeBinary:j.trim()}),l){await b("local"),await P();return}await z("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>o(!1),1e3)}},[l,j,b]),O=i.useCallback(async()=>{const d=await he(Ce);d.ok?(n(!0),setTimeout(()=>n(!1),2e3)):console.error("Failed to copy:",d.error)},[]),c=Ne,D=K==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":K==="linux"?"/home/you/.bun/bin/opencode":"/Users/you/.bun/bin/opencode",B=t&&(!l||m==="local");return e.jsx("div",{className:"app-region-drag h-full flex items-center justify-center bg-transparent p-8 cursor-default select-none overflow-y-auto",onMouseDown:y,children:e.jsxs("div",{className:"w-full max-w-md space-y-7",children:[e.jsxs("header",{className:"text-center space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight text-foreground",children:s("onboarding.chooser.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("onboarding.chooser.description")})]}),l&&t&&e.jsxs("div",{className:"app-region-no-drag flex gap-1.5",children:[e.jsx("button",{type:"button",className:re("flex-1 px-4 py-2 rounded-lg border transition-colors text-sm",m==="local"?"border-[var(--interactive-selection)] text-foreground bg-[var(--interactive-selection)]/10":"border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),onClick:()=>k("local"),children:s("onboarding.chooser.tabs.localInstall")}),e.jsx("button",{type:"button",className:re("flex-1 px-4 py-2 rounded-lg border transition-colors text-sm",m==="remote"?"border-[var(--interactive-selection)] text-foreground bg-[var(--interactive-selection)]/10":"border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),onClick:()=>k("remote"),children:s("onboarding.chooser.tabs.connectRemote")})]}),l&&m==="remote"?e.jsx("div",{className:"app-region-no-drag",children:e.jsx(xe,{onBack:()=>t&&k("local"),showBackButton:!1,showInstancePicker:!t,onSwitchToLocal:t?()=>k("local"):void 0})}):null,B&&e.jsxs("div",{className:"space-y-4",children:[K==="windows"&&e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-4",children:[e.jsx("div",{className:"text-sm text-foreground",children:s("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:s("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:s("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground text-center leading-relaxed",children:s("onboarding.localSetup.intro")}),e.jsx("div",{className:"app-region-no-drag rounded-lg border border-border bg-background/60 backdrop-blur-sm px-4 py-3 font-mono text-sm",children:r?e.jsxs("div",{className:"flex items-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(A,{name:"check",className:"h-4 w-4"}),s("onboarding.common.status.copiedToClipboard")]}):e.jsx(Se,{onCopy:O,copyTitle:s("onboarding.common.copyToClipboard")})}),e.jsxs("div",{className:"app-region-no-drag flex items-center justify-between",children:[e.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1",children:[s(K==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(A,{name:"external-link",className:"h-3 w-3"})]}),e.jsx("button",{type:"button",onClick:N,disabled:w,className:"text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",children:s(w?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkNow")})]}),e.jsxs("div",{className:"rounded-lg border px-4 py-3 flex items-center gap-3",style:{borderColor:"color-mix(in srgb, var(--primary-base) 20%, transparent)",backgroundColor:"color-mix(in srgb, var(--primary-base) 6%, transparent)"},role:"status","aria-live":"polite",children:[e.jsxs("span",{className:"relative inline-flex h-2.5 w-2.5 shrink-0","aria-hidden":!0,children:[e.jsx("span",{className:"absolute inset-0 rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity 1.6s ease-in-out infinite"}}),e.jsx("span",{className:"absolute inset-[-4px] rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity-dim 1.6s ease-in-out infinite",opacity:0}})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm text-foreground leading-tight",children:s("onboarding.localSetup.status.watching")}),e.jsx("div",{className:"text-xs text-muted-foreground leading-tight mt-0.5",children:s("onboarding.localSetup.status.autoContinue")})]})]}),e.jsxs("details",{className:"app-region-no-drag group rounded-lg border border-border/60 px-4 open:bg-background/40 transition-colors",open:C,onToggle:d=>g(d.currentTarget.open),children:[e.jsxs("summary",{className:"flex items-center justify-between cursor-pointer py-2.5 text-sm text-muted-foreground hover:text-foreground transition-colors list-none [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.advanced.title")}),e.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsxs("div",{className:"pb-4 space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Y,{value:j,onChange:d=>U(d.target.value),placeholder:D,disabled:h,className:"flex-1 font-mono text-xs"}),e.jsx(L,{type:"button",variant:"secondary",size:"sm",onClick:E,disabled:h||!l,children:s("onboarding.localSetup.actions.browse")}),e.jsx(L,{type:"button",size:"sm",onClick:F,disabled:h||!j.trim(),children:s("onboarding.localSetup.actions.apply")})]}),e.jsx("p",{className:"text-xs text-muted-foreground/70",children:s("onboarding.localSetup.helper.saveAndReload")})]})]}),e.jsxs("details",{className:"app-region-no-drag group rounded-lg border border-border/60 px-4 open:bg-background/40 transition-colors",open:T,onToggle:d=>I(d.currentTarget.open),children:[e.jsxs("summary",{className:"flex items-center justify-between cursor-pointer py-2.5 text-sm text-muted-foreground hover:text-foreground transition-colors list-none [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.troubleshoot.title")}),e.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsx("ul",{className:"pb-4 space-y-1.5 text-xs text-muted-foreground list-disc pl-4",children:K==="windows"?e.jsx(e.Fragment,{children:e.jsx("li",{children:s("onboarding.localSetup.windows.hintDetectionFailed")})}):e.jsxs(e.Fragment,{children:[e.jsx("li",{children:s("onboarding.localSetup.hint.ensurePath")}),e.jsx("li",{children:s("onboarding.localSetup.hint.setEnv")}),e.jsx("li",{children:s("onboarding.localSetup.hint.missingRuntime")})]})})]})]})]})})}const Le="curl -fsSL https://opencode.ai/install | bash",Ue="https://opencode.ai/docs";function Te(a){const t=J.c(5),{onCopy:s,copyTitle:r}=a;let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=e.jsxs("code",{children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]}),t[0]=n):n=t[0];let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l=e.jsx(A,{name:"file-copy",className:"h-4 w-4"}),t[1]=l):l=t[1];let u;return t[2]!==r||t[3]!==s?(u=e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[n,e.jsx("button",{onClick:s,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors",title:r,children:l})]}),t[2]=r,t[3]=s,t[4]=u):u=t[4],u}const Ke=3e4;function Ie({onBack:a,onCliAvailable:t,isFromRecovery:s=!1,onSwitchToRemote:r}){const{t:n}=Q(),[l,u]=i.useState(!1),[h,o]=i.useState(!1),[w,S]=i.useState(!1),[j,U]=i.useState(!1),[K,x]=i.useState(!1),[m,k]=i.useState(null),[C,g]=i.useState(""),[T,I]=i.useState("unknown");i.useEffect(()=>{const c=setTimeout(()=>o(!0),Ke);return()=>clearTimeout(c)},[]),i.useEffect(()=>{S($())},[]),i.useEffect(()=>{if(typeof navigator>"u"){I("unknown");return}const c=navigator.userAgent||"";if(/Windows/i.test(c)){I("windows");return}if(/Macintosh|Mac OS X/i.test(c)){I("macos");return}if(/Linux/i.test(c)){I("linux");return}I("unknown")},[]),i.useEffect(()=>{let c=!1;return(async()=>{try{const D=await z("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const B=await D.json().catch(()=>null);if(!B||c)return;const d=typeof B.opencodeBinary=="string"?B.opencodeBinary.trim():"";d&&g(d)}catch{}})(),()=>{c=!0}},[]);const y=i.useCallback(async c=>{c.target.closest("button, a, input, select, textarea, code")||c.button===0&&w&&await ue()},[w]),f=i.useCallback(async()=>{try{const c=await z("/health");if(!c.ok)return!1;const D=await c.json();return D.openCodeRunning===!0||D.isOpenCodeReady===!0}catch{return!1}},[]),b=i.useCallback(async()=>{if(!(typeof window>"u")&&w)try{const c=await me();c.success&&c.path&&c.path.trim().length>0&&g(c.path.trim())}catch{}},[w]),R=i.useCallback(async()=>{U(!0);try{if(await pe({opencodeBinary:C.trim()}),w){await P();return}await z("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>U(!1),1e3)}},[w,C]),N=i.useCallback(async()=>{const c=await he(Le);c.ok?(u(!0),setTimeout(()=>u(!1),2e3)):console.error("Failed to copy:",c.error)},[]),E=i.useCallback(async()=>{x(!0),k(null);try{await f()?t?.():k(n("onboarding.localSetup.errors.cliNotReady"))}catch(c){k(c instanceof Error?c.message:n("onboarding.localSetup.errors.detectionFailed"))}finally{x(!1)}},[f,t,n]),F=Ue,O=T==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":T==="linux"?"/home/you/.bun/bin/opencode":"/Users/you/.bun/bin/opencode";return e.jsxs("div",{className:"h-full flex items-center justify-center bg-transparent p-8 relative cursor-default select-none",onMouseDown:y,children:[e.jsxs("div",{className:"w-full max-w-lg space-y-4 text-center",children:[e.jsx("div",{className:"flex items-center",children:e.jsx(L,{variant:"ghost",onClick:a,className:"p-0 text-muted-foreground hover:text-foreground",children:n("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-foreground",children:n("onboarding.localSetup.title")}),e.jsx("p",{className:"text-muted-foreground",children:n("onboarding.localSetup.description")})]}),T==="windows"&&e.jsxs("div",{className:"mx-auto max-w-2xl rounded-lg border border-border bg-background/50 p-4 text-left",children:[e.jsx("div",{className:"text-sm text-foreground",children:n("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:n("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:n("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"bg-background/60 backdrop-blur-sm border border-border rounded-lg px-5 py-3 font-mono text-sm w-fit",children:l?e.jsxs("div",{className:"flex items-center justify-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(A,{name:"check",className:"h-4 w-4"}),n("onboarding.common.status.copiedToClipboard")]}):e.jsx(Te,{onCopy:N,copyTitle:n("onboarding.common.copyToClipboard")})})}),e.jsxs("a",{href:F,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1 justify-center",children:[n(T==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(A,{name:"external-link",className:"h-3 w-3"})]}),m&&e.jsx("div",{className:"mx-auto max-w-md rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",children:m}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(L,{type:"button",onClick:E,disabled:K,className:"w-full max-w-xs",size:"lg",children:n(K?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkAndContinue")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("onboarding.localSetup.helper.checkAndContinue")})]}),e.jsx("div",{className:"mx-auto w-full max-w-xl pt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:n("onboarding.localSetup.field.alreadyInstalled")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Y,{value:C,onChange:c=>g(c.target.value),placeholder:O,disabled:j,className:"flex-1 font-mono text-xs"}),e.jsx(L,{type:"button",variant:"secondary",onClick:b,disabled:j||!w,children:n("onboarding.localSetup.actions.browse")}),e.jsx(L,{type:"button",onClick:R,disabled:j,children:n("onboarding.localSetup.actions.apply")})]}),e.jsx("div",{className:"text-xs text-muted-foreground/70",children:n("onboarding.localSetup.helper.saveAndReload")})]})}),s&&r&&e.jsxs("div",{className:"text-center pt-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:n("onboarding.localSetup.remotePreference")}),e.jsx(L,{variant:"link",onClick:r,children:n("onboarding.localSetup.actions.connectRemoteServer")})]})]}),h&&e.jsx("div",{className:"absolute bottom-8 left-0 right-0 text-center space-y-1",children:T==="windows"?e.jsx(e.Fragment,{children:e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.windows.hintDetectionFailed")})}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.ensurePath")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.setEnv")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.missingRuntime")})]})})]})}function se(a,t){if(a?.trim())return ne(a.trim());if(t)return ne(t)}function _e(a,t,s){switch(a){case"local-unavailable":return{title:"Local OpenCode Unavailable",description:"OpenCode CLI could not be started or is not installed. Install OpenCode or connect to a remote server instead.",titleKey:"onboarding.desktopRecovery.localUnavailable.title",descriptionKey:"onboarding.desktopRecovery.localUnavailable.description",iconKey:"local",showRetry:!0,retryLabel:"Retry Local",retryLabelKey:"onboarding.desktopRecovery.localUnavailable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Set Up Local",useLocalLabelKey:"onboarding.desktopRecovery.localUnavailable.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-missing":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-unreachable":{const r=se(t,s);return{title:"Remote Server Unreachable",description:`Could not connect to "${r||"the remote server"}". Check your network connection and verify the server address.`,titleKey:"onboarding.desktopRecovery.remoteUnreachable.title",descriptionKey:"onboarding.desktopRecovery.remoteUnreachable.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-wrong-service":{const r=se(t,s);return{title:"Incompatible Server",description:`The server at "${r||"unknown"}" is not running OpenChamber. Verify the address points to an OpenChamber server.`,titleKey:"onboarding.desktopRecovery.incompatibleServer.title",descriptionKey:"onboarding.desktopRecovery.incompatibleServer.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-incompatible":{const r=se(t,s);return{title:"Server Update Required",description:`The OpenChamber server at "${r||"unknown"}" is not compatible with this app version. Update OpenChamber on the server, then try again.`,titleKey:"onboarding.desktopRecovery.remoteIncompatible.title",descriptionKey:"onboarding.desktopRecovery.remoteIncompatible.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"missing-default-host":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};default:{const r=a;throw new Error(`Unknown recovery variant: ${r}`)}}}function De(a){switch(a){case"local":return e.jsx(A,{name:"macbook",className:"h-8 w-8"});case"remote":return e.jsx(A,{name:"server",className:"h-8 w-8"})}}function Ee({variant:a,hostLabel:t,hostUrl:s,onRetry:r,onUseLocal:n,onUseRemote:l,isRetrying:u=!1}){const{t:h}=Q(),o=_e(a,t,s),w=o.retryLabelKey??"onboarding.desktopRecovery.actions.retryConnection",S=i.useMemo(()=>{if(o.descriptionParams?.host)return o.descriptionParams;if(a==="remote-unreachable")return{host:h("onboarding.desktopRecovery.placeholders.remoteServer")};if(a==="remote-wrong-service"||a==="remote-incompatible")return{host:h("onboarding.desktopRecovery.placeholders.unknownServer")}},[o.descriptionParams,h,a]);return e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-3 text-center",children:[e.jsx("div",{className:"p-3 rounded-full",style:{backgroundColor:"var(--status-warning)",opacity:.15},children:e.jsx("div",{style:{color:"var(--status-warning)"},children:De(o.iconKey)})}),e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:h(o.titleKey)}),e.jsx("p",{className:"text-muted-foreground text-sm max-w-sm",children:h(o.descriptionKey,S)})]}),s&&(a==="remote-unreachable"||a==="remote-wrong-service"||a==="remote-incompatible")&&e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:h("onboarding.remoteConnection.field.serverAddress")}),e.jsx("div",{className:"font-mono text-sm text-foreground truncate",children:ne(s)})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[o.showRetry&&r&&e.jsxs(L,{onClick:r,disabled:u,className:"w-full",children:[e.jsx(A,{name:"refresh",className:re("h-4 w-4",u&&"animate-spin")}),h(u?"onboarding.desktopRecovery.actions.retrying":w)]}),e.jsxs("div",{className:"flex gap-2",children:[o.showUseLocal&&n&&e.jsxs(L,{variant:"outline",onClick:n,disabled:u,className:"flex-1",children:[e.jsx(A,{name:"macbook",className:"h-4 w-4"}),h(o.useLocalLabelKey)]}),o.showUseRemote&&l&&e.jsxs(L,{variant:"outline",onClick:l,disabled:u,className:"flex-1",children:[e.jsx(A,{name:"server",className:"h-4 w-4"}),h(o.useRemoteLabelKey)]})]})]})]})})}function de(a,t){if(t==="use-remote")return{kind:"remote-form"};switch(a){case"local-unavailable":return{kind:"local-setup"};case"remote-unreachable":case"remote-incompatible":case"remote-wrong-service":case"remote-missing":case"missing-default-host":return{kind:"switch-default-to-local"};default:{const s=a;throw new Error(`Unhandled RecoveryVariant: ${s}`)}}}function Ae(a){const t=J.c(29),{variant:s,hostUrl:r,hostLabel:n,onRetry:l,onChooseRemote:u,showRemoteForm:h,onCloseRemoteForm:o,onSwitchToLocalFromRemote:w,onEnterLocalSetup:S,isRetrying:j,localAvailable:U}=a,K=h===void 0?!1:h,x=j===void 0?!1:j,m=U===void 0?!0:U,k=Fe;let C;t[0]!==l?(C=async()=>{if($()){await P();return}await z("/api/config/reload",{method:"POST"}),l?.()},t[0]=l,t[1]=C):C=t[1];const g=C;let T;t[2]!==S||t[3]!==s?(T=async()=>{if(de(s,"use-local").kind==="local-setup"){S?.();return}if(await k("local"),$()){await P();return}window.location.reload()},t[2]=S,t[3]=s,t[4]=T):T=t[4];const I=T;let y;t[5]!==u||t[6]!==s?(y=()=>{de(s,"use-remote").kind==="remote-form"&&u?.()},t[5]=u,t[6]=s,t[7]=y):y=t[7];const f=y;if(K){const N=s==="remote-wrong-service"?"":r||"",E=s==="remote-wrong-service"?"":n||"";let F;t[8]!==u||t[9]!==o?(F=o||(()=>u?.()),t[8]=u,t[9]=o,t[10]=F):F=t[10];const O=!m;let c;t[11]!==m||t[12]!==S||t[13]!==w?(c=m?w||(()=>{k("local").then(()=>{$()?P():S?.()})}):void 0,t[11]=m,t[12]=S,t[13]=w,t[14]=c):c=t[14];let D;return t[15]!==E||t[16]!==N||t[17]!==F||t[18]!==O||t[19]!==c?(D=e.jsx(xe,{onBack:F,initialUrl:N,initialLabel:E,isRecoveryMode:!0,showInstancePicker:O,onSwitchToLocal:c}),t[15]=E,t[16]=N,t[17]=F,t[18]=O,t[19]=c,t[20]=D):D=t[20],D}const b=m?I:void 0;let R;return t[21]!==g||t[22]!==f||t[23]!==n||t[24]!==r||t[25]!==x||t[26]!==b||t[27]!==s?(R=e.jsx(Ee,{variant:s,hostLabel:n,hostUrl:r,onRetry:g,onUseLocal:b,onUseRemote:f,isRetrying:x}),t[21]=g,t[22]=f,t[23]=n,t[24]=r,t[25]=x,t[26]=b,t[27]=s,t[28]=R):R=t[28],R}async function Fe(a){if(!$())return;const t=await V();await G({...t,...a==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})}function mo(a){const t=J.c(29),{onBack:s,onCliAvailable:r,mode:n,recoveryVariant:l,recoveryHostUrl:u,recoveryHostLabel:h,onEnterLocalSetup:o,localAvailable:w}=a,S=n===void 0?"first-launch":n,j=l===void 0?"missing-default-host":l,U=w===void 0?!0:w,[K,x]=i.useState(!1),[m,k]=i.useState(!1);let C;t[0]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{k(!1),x(!1)},t[0]=C):C=t[0];let g;t[1]!==S||t[2]!==h||t[3]!==u||t[4]!==j?(g=[S,j,u,h],t[1]=S,t[2]=h,t[3]=u,t[4]=j,t[5]=g):g=t[5],i.useEffect(C,g);const T=m?"local-setup":S;if(T==="recovery"){let y;t[6]===Symbol.for("react.memo_cache_sentinel")?(y=()=>x(!0),t[6]=y):y=t[6];let f,b;t[7]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!1),b=()=>{x(!1),k(!0)},t[7]=f,t[8]=b):(f=t[7],b=t[8]);let R;t[9]!==o?(R=()=>{k(!0),o?.()},t[9]=o,t[10]=R):R=t[10];let N;return t[11]!==U||t[12]!==h||t[13]!==u||t[14]!==j||t[15]!==K||t[16]!==R?(N=e.jsx(Ae,{variant:j,hostUrl:u,hostLabel:h,onChooseRemote:y,showRemoteForm:K,onCloseRemoteForm:f,onSwitchToLocalFromRemote:b,onEnterLocalSetup:R,localAvailable:U}),t[11]=U,t[12]=h,t[13]=u,t[14]=j,t[15]=K,t[16]=R,t[17]=N):N=t[17],N}if(T==="local-setup"){let y;t[18]!==s||t[19]!==m?(y=()=>{m?k(!1):s?.()},t[18]=s,t[19]=m,t[20]=y):y=t[20];let f;t[21]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!0),t[21]=f):f=t[21];let b;return t[22]!==r||t[23]!==m||t[24]!==y?(b=e.jsx(Ie,{onBack:y,onCliAvailable:r,isFromRecovery:m,onSwitchToRemote:f}),t[22]=r,t[23]=m,t[24]=y,t[25]=b):b=t[25],b}let I;return t[26]!==U||t[27]!==r?(I=e.jsx(Re,{onCliAvailable:r,localAvailable:U}),t[26]=U,t[27]=r,t[28]=I):I=t[28],I}export{mo as OnboardingScreen};
1
+ import{r as _,j as e,R as i,f as J}from"./vendor-react-BUCujlKS.js";import{L as W,cs as we,cp as le,cl as G,z as $,au as P,dz as je,r as z,V as ue,aC as me,a8 as pe,S as ne}from"./index-B0aX0JeI.js";import{f as Q,B as L,T as Y,g as he,h as re,I as A}from"./useAppFontEffects-Bb1Zihd2.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-zod-CK21ihK-.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-prHos-tt.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CNjvbb69.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";function ke(a){switch(a){case"ok":return null;case"auth":return"onboarding.remoteConnection.probe.authMessage";case"update-recommended":return"onboarding.remoteConnection.probe.updateRecommendedMessage";case"incompatible":return"onboarding.remoteConnection.probe.incompatibleMessage";case"wrong-service":return"onboarding.remoteConnection.probe.wrongServiceMessage";case"unreachable":return"onboarding.remoteConnection.probe.unreachableMessage";default:return null}}function oe(a){return a==="wrong-service"||a==="unreachable"||a==="incompatible"}function xe({onBack:a,showBackButton:t=!0,initialUrl:s="",initialLabel:r="",isRecoveryMode:n=!1,onConnect:l,onSwitchToLocal:u,showInstancePicker:h=!1}){const{t:o}=Q(),[w,S]=_.useState(s),[j,U]=_.useState(r),[K,x]=_.useState("idle"),[m,k]=_.useState(null),[C,g]=_.useState(""),[T,I]=_.useState([]),[y,f]=_.useState(()=>h?"instances":"add"),[b,R]=_.useState("");_.useEffect(()=>{h&&W().then(p=>I(p.hosts)).catch(p=>{g(p instanceof Error?p.message:String(p))})},[h]);const N=we(w),E=N?.persistedUrl??null,F=_.useCallback(p=>{S(p.target.value),x("idle"),k(null),g("")},[]),O=_.useCallback(p=>{U(p.target.value)},[]),c=_.useCallback(async()=>{if(E){x("testing"),k(null),g("");try{const p=await le(E);k(p),x(p.status==="ok"||p.status==="update-recommended"?"success":"error")}catch(p){g(p instanceof Error?p.message:o("onboarding.remoteConnection.errors.connectionTestFailed")),x("error")}}},[E,o]),D=_.useCallback(async()=>{if(!N)return;const p=N.persistedUrl;x("testing"),k(null),g("");try{const H=await le(p);if(k(H),oe(H.status)){x("error");return}const Z=await W(),ye=j.trim()||p,ee=Z.hosts.find(X=>X.url===p),te=ee?ee.id:`host-${Date.now().toString(16)}`,ie={id:te,label:ye,url:p,apiUrl:p},ve=ee?Z.hosts.map(X=>X.id===te?ie:X):[...Z.hosts,ie];if(await G({hosts:ve,defaultHostId:te,initialHostChoiceCompleted:!0}),l?.(),N.redeemUrl){window.location.assign(N.redeemUrl);return}$()&&await P()}catch(H){g(H instanceof Error?H.message:o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[N,j,l,o]),B=_.useCallback(async p=>{const H=await W();await G({hosts:H.hosts,defaultHostId:p,initialHostChoiceCompleted:!0}),await P()},[]),d=_.useCallback(async()=>{x("testing"),g("");try{const p=await W(),H=await je(b,p.hosts);await G({hosts:H.hosts,defaultHostId:H.hostId,initialHostChoiceCompleted:!0}),await P()}catch(p){g(p instanceof Error&&p.message==="invalid-connect-link"?o("settings.remoteInstances.direct.error.invalidConnectLink"):o("onboarding.remoteConnection.errors.failedToSaveConnection")),x("error")}},[b,o]),v=K==="testing",M=E!==null&&!v,V=E!==null&&!v&&!oe(m?.status??null),q=ke(m?.status??null),fe=m?.status==="ok",be=m?.status==="update-recommended",ge=m?.status==="auth",ae=oe(m?.status??null);return h&&y==="instances"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("desktopHostSwitcher.actions.switchInstance")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.description")})]}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx("div",{className:"space-y-2",children:T.length===0?e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:o("settings.remoteInstances.direct.state.empty")}):T.map(p=>e.jsx(L,{variant:"outline",className:"w-full justify-start",onClick:()=>{B(p.id)},children:e.jsx("span",{className:"min-w-0 truncate",children:p.label})},p.id))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{variant:"outline",className:"flex-1",onClick:()=>f("import"),children:o("settings.remoteInstances.direct.import.action")}),e.jsx(L,{className:"flex-1",onClick:()=>f("add"),children:o("settings.remoteInstances.direct.actions.add")})]})]})}):h&&y==="import"?e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsx(L,{variant:"ghost",onClick:()=>f("instances"),className:"p-0 text-muted-foreground",children:o("onboarding.common.actions.back")}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o("settings.remoteInstances.direct.import.action")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("settings.remoteInstances.direct.import.description")})]}),e.jsx(Y,{value:b,onChange:p=>R(p.target.value),placeholder:o("settings.remoteInstances.direct.import.placeholder"),disabled:v,autoFocus:!0}),C?e.jsx("div",{className:"text-sm text-[var(--status-error)]",children:C}):null,e.jsx(L,{onClick:()=>{d()},disabled:v||!b.trim(),children:o("settings.remoteInstances.direct.import.action")})]})}):e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[(t||h)&&e.jsx("div",{className:"flex items-center",children:e.jsx(L,{variant:"ghost",onClick:h?()=>f("instances"):a,className:"p-0 text-muted-foreground hover:text-foreground",children:o("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:o(n?"onboarding.remoteConnection.titleRecovery":"onboarding.remoteConnection.title")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:o("onboarding.remoteConnection.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-url",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.serverAddress")}),e.jsx(Y,{id:"remote-url",type:"url",value:w,onChange:F,placeholder:o("onboarding.remoteConnection.field.serverAddressPlaceholder"),disabled:v})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"remote-label",className:"text-sm text-foreground",children:o("onboarding.remoteConnection.field.nameOptional")}),e.jsx(Y,{id:"remote-label",type:"text",value:j,onChange:O,placeholder:o("onboarding.remoteConnection.field.namePlaceholder"),disabled:v})]})]}),m&&fe&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-success)",color:"var(--status-success)"},children:o("onboarding.remoteConnection.status.connectedSuccessfully",{latencyMs:m.latencyMs})}),m&&ge&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:o("onboarding.remoteConnection.status.authWarning")}),m&&be&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-warning)",color:"var(--status-warning)"},children:q?o(q):null}),m&&ae&&e.jsxs("div",{className:"rounded-lg border p-3 text-sm space-y-3",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold mb-1",children:o("onboarding.remoteConnection.status.connectionFailed")}),e.jsx("div",{className:"opacity-90",children:q?o(q):null})]}),e.jsx("div",{className:"text-xs opacity-80",children:m.status==="unreachable"?o("onboarding.remoteConnection.status.suggestionsUnreachable"):o("onboarding.remoteConnection.status.suggestionsWrongService")})]}),C&&e.jsx("div",{className:"rounded-lg border p-3 text-sm",style:{borderColor:"var(--status-error)",color:"var(--status-error)"},children:C}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(L,{variant:"outline",onClick:c,disabled:!M,children:o(v?"onboarding.remoteConnection.actions.testing":"onboarding.remoteConnection.actions.testConnection")}),e.jsx(L,{onClick:D,disabled:!V,children:o("onboarding.remoteConnection.actions.connectAndRestart")})]}),ae&&e.jsxs("div",{className:"flex flex-col gap-2 pt-2 border-t border-border",children:[e.jsx("div",{className:"text-xs text-muted-foreground text-center",children:o("onboarding.remoteConnection.actions.whatToDo")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:a,className:"flex-1",children:o("onboarding.remoteConnection.actions.chooseDifferentServer")}),!n&&u&&e.jsx(L,{variant:"outline",size:"sm",onClick:u,className:"flex-1",children:o("onboarding.remoteConnection.actions.useLocalInstead")})]})]})]})})}const Ce="curl -fsSL https://opencode.ai/install | bash",Ne="https://opencode.ai/docs",ce=2500;function Se(a){const t=J.c(5),{onCopy:s,copyTitle:r}=a;let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=e.jsxs("code",{className:"flex-1 text-left overflow-x-auto whitespace-nowrap",children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]}),t[0]=n):n=t[0];let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l=e.jsx(A,{name:"file-copy",className:"h-4 w-4"}),t[1]=l):l=t[1];let u;return t[2]!==r||t[3]!==s?(u=e.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[n,e.jsx("button",{onClick:s,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors shrink-0",title:r,"aria-label":r,children:l})]}),t[2]=r,t[3]=s,t[4]=u):u=t[4],u}function Re({onCliAvailable:a,localAvailable:t=!0}){const{t:s}=Q(),[r,n]=i.useState(!1),[l,u]=i.useState(!1),[h,o]=i.useState(!1),[w,S]=i.useState(!1),[j,U]=i.useState(""),[K,x]=i.useState("unknown"),[m,k]=i.useState(()=>t?"local":"remote"),[C,g]=i.useState(!1),[T,I]=i.useState(!1);i.useEffect(()=>{u($())},[]),i.useEffect(()=>{if(typeof navigator>"u"){x("unknown");return}const d=navigator.userAgent||"";/Windows/i.test(d)?x("windows"):/Macintosh|Mac OS X/i.test(d)?x("macos"):/Linux/i.test(d)?x("linux"):x("unknown")},[]),i.useEffect(()=>{let d=!1;return(async()=>{try{const v=await z("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!v.ok)return;const M=await v.json().catch(()=>null);if(!M||d)return;const V=typeof M.opencodeBinary=="string"?M.opencodeBinary.trim():"";V&&U(V)}catch{}})(),()=>{d=!0}},[]);const y=i.useCallback(async d=>{const v=d.target;v.closest(".app-region-no-drag")||v.closest("button, a, input, select, textarea, code, summary, details")||d.button===0&&l&&await ue()},[l]),f=i.useCallback(async()=>{try{const d=await z("/health");if(!d.ok)return!1;const v=await d.json();return v.openCodeRunning===!0||v.isOpenCodeReady===!0}catch{return!1}},[]),b=i.useCallback(async d=>{if(!l)return;const v=await W();await G({...v,...d==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})},[l]),R=i.useCallback(async()=>{l&&await b("local"),a?.()},[l,a,b]);i.useEffect(()=>{if(!t||m!=="local")return;let d=!1,v=null;const M=async()=>{if(!d){try{const V=await f();if(d)return;if(V){await R();return}}catch{}d||(v=setTimeout(M,ce))}};return v=setTimeout(M,ce),()=>{d=!0,v&&clearTimeout(v)}},[m,f,R,t]);const N=i.useCallback(async()=>{S(!0);try{await f()&&await R()}finally{S(!1)}},[f,R]),E=i.useCallback(async()=>{if(!(typeof window>"u")&&l)try{const d=await me();d.success&&d.path&&d.path.trim().length>0&&U(d.path.trim())}catch{}},[l]),F=i.useCallback(async()=>{o(!0);try{if(await pe({opencodeBinary:j.trim()}),l){await b("local"),await P();return}await z("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>o(!1),1e3)}},[l,j,b]),O=i.useCallback(async()=>{const d=await he(Ce);d.ok?(n(!0),setTimeout(()=>n(!1),2e3)):console.error("Failed to copy:",d.error)},[]),c=Ne,D=K==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":K==="linux"?"/home/you/.bun/bin/opencode":"/Users/you/.bun/bin/opencode",B=t&&(!l||m==="local");return e.jsx("div",{className:"app-region-drag h-full flex items-center justify-center bg-transparent p-8 cursor-default select-none overflow-y-auto",onMouseDown:y,children:e.jsxs("div",{className:"w-full max-w-md space-y-7",children:[e.jsxs("header",{className:"text-center space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight text-foreground",children:s("onboarding.chooser.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("onboarding.chooser.description")})]}),l&&t&&e.jsxs("div",{className:"app-region-no-drag flex gap-1.5",children:[e.jsx("button",{type:"button",className:re("flex-1 px-4 py-2 rounded-lg border transition-colors text-sm",m==="local"?"border-[var(--interactive-selection)] text-foreground bg-[var(--interactive-selection)]/10":"border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),onClick:()=>k("local"),children:s("onboarding.chooser.tabs.localInstall")}),e.jsx("button",{type:"button",className:re("flex-1 px-4 py-2 rounded-lg border transition-colors text-sm",m==="remote"?"border-[var(--interactive-selection)] text-foreground bg-[var(--interactive-selection)]/10":"border-border text-muted-foreground hover:text-foreground hover:border-muted-foreground"),onClick:()=>k("remote"),children:s("onboarding.chooser.tabs.connectRemote")})]}),l&&m==="remote"?e.jsx("div",{className:"app-region-no-drag",children:e.jsx(xe,{onBack:()=>t&&k("local"),showBackButton:!1,showInstancePicker:!t,onSwitchToLocal:t?()=>k("local"):void 0})}):null,B&&e.jsxs("div",{className:"space-y-4",children:[K==="windows"&&e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-4",children:[e.jsx("div",{className:"text-sm text-foreground",children:s("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:s("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:s("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground text-center leading-relaxed",children:s("onboarding.localSetup.intro")}),e.jsx("div",{className:"app-region-no-drag rounded-lg border border-border bg-background/60 backdrop-blur-sm px-4 py-3 font-mono text-sm",children:r?e.jsxs("div",{className:"flex items-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(A,{name:"check",className:"h-4 w-4"}),s("onboarding.common.status.copiedToClipboard")]}):e.jsx(Se,{onCopy:O,copyTitle:s("onboarding.common.copyToClipboard")})}),e.jsxs("div",{className:"app-region-no-drag flex items-center justify-between",children:[e.jsxs("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1",children:[s(K==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(A,{name:"external-link",className:"h-3 w-3"})]}),e.jsx("button",{type:"button",onClick:N,disabled:w,className:"text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",children:s(w?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkNow")})]}),e.jsxs("div",{className:"rounded-lg border px-4 py-3 flex items-center gap-3",style:{borderColor:"color-mix(in srgb, var(--primary-base) 20%, transparent)",backgroundColor:"color-mix(in srgb, var(--primary-base) 6%, transparent)"},role:"status","aria-live":"polite",children:[e.jsxs("span",{className:"relative inline-flex h-2.5 w-2.5 shrink-0","aria-hidden":!0,children:[e.jsx("span",{className:"absolute inset-0 rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity 1.6s ease-in-out infinite"}}),e.jsx("span",{className:"absolute inset-[-4px] rounded-full",style:{backgroundColor:"var(--primary-base)",animation:"pulse-opacity-dim 1.6s ease-in-out infinite",opacity:0}})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm text-foreground leading-tight",children:s("onboarding.localSetup.status.watching")}),e.jsx("div",{className:"text-xs text-muted-foreground leading-tight mt-0.5",children:s("onboarding.localSetup.status.autoContinue")})]})]}),e.jsxs("details",{className:"app-region-no-drag group rounded-lg border border-border/60 px-4 open:bg-background/40 transition-colors",open:C,onToggle:d=>g(d.currentTarget.open),children:[e.jsxs("summary",{className:"flex items-center justify-between cursor-pointer py-2.5 text-sm text-muted-foreground hover:text-foreground transition-colors list-none [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.advanced.title")}),e.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsxs("div",{className:"pb-4 space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Y,{value:j,onChange:d=>U(d.target.value),placeholder:D,disabled:h,className:"flex-1 font-mono text-xs"}),e.jsx(L,{type:"button",variant:"secondary",size:"sm",onClick:E,disabled:h||!l,children:s("onboarding.localSetup.actions.browse")}),e.jsx(L,{type:"button",size:"sm",onClick:F,disabled:h||!j.trim(),children:s("onboarding.localSetup.actions.apply")})]}),e.jsx("p",{className:"text-xs text-muted-foreground/70",children:s("onboarding.localSetup.helper.saveAndReload")})]})]}),e.jsxs("details",{className:"app-region-no-drag group rounded-lg border border-border/60 px-4 open:bg-background/40 transition-colors",open:T,onToggle:d=>I(d.currentTarget.open),children:[e.jsxs("summary",{className:"flex items-center justify-between cursor-pointer py-2.5 text-sm text-muted-foreground hover:text-foreground transition-colors list-none [&::-webkit-details-marker]:hidden",children:[e.jsx("span",{children:s("onboarding.localSetup.troubleshoot.title")}),e.jsx(A,{name:"arrow-down-s",className:"h-4 w-4 transition-transform group-open:rotate-180"})]}),e.jsx("ul",{className:"pb-4 space-y-1.5 text-xs text-muted-foreground list-disc pl-4",children:K==="windows"?e.jsx(e.Fragment,{children:e.jsx("li",{children:s("onboarding.localSetup.windows.hintDetectionFailed")})}):e.jsxs(e.Fragment,{children:[e.jsx("li",{children:s("onboarding.localSetup.hint.ensurePath")}),e.jsx("li",{children:s("onboarding.localSetup.hint.setEnv")}),e.jsx("li",{children:s("onboarding.localSetup.hint.missingRuntime")})]})})]})]})]})})}const Le="curl -fsSL https://opencode.ai/install | bash",Ue="https://opencode.ai/docs";function Te(a){const t=J.c(5),{onCopy:s,copyTitle:r}=a;let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n=e.jsxs("code",{children:[e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"curl"}),e.jsx("span",{className:"text-muted-foreground",children:" -fsSL "}),e.jsx("span",{style:{color:"var(--syntax-string)"},children:"https://opencode.ai/install"}),e.jsx("span",{className:"text-muted-foreground",children:" | "}),e.jsx("span",{style:{color:"var(--syntax-keyword)"},children:"bash"})]}),t[0]=n):n=t[0];let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l=e.jsx(A,{name:"file-copy",className:"h-4 w-4"}),t[1]=l):l=t[1];let u;return t[2]!==r||t[3]!==s?(u=e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[n,e.jsx("button",{onClick:s,className:"inline-flex items-center text-muted-foreground hover:text-foreground transition-colors",title:r,children:l})]}),t[2]=r,t[3]=s,t[4]=u):u=t[4],u}const Ke=3e4;function Ie({onBack:a,onCliAvailable:t,isFromRecovery:s=!1,onSwitchToRemote:r}){const{t:n}=Q(),[l,u]=i.useState(!1),[h,o]=i.useState(!1),[w,S]=i.useState(!1),[j,U]=i.useState(!1),[K,x]=i.useState(!1),[m,k]=i.useState(null),[C,g]=i.useState(""),[T,I]=i.useState("unknown");i.useEffect(()=>{const c=setTimeout(()=>o(!0),Ke);return()=>clearTimeout(c)},[]),i.useEffect(()=>{S($())},[]),i.useEffect(()=>{if(typeof navigator>"u"){I("unknown");return}const c=navigator.userAgent||"";if(/Windows/i.test(c)){I("windows");return}if(/Macintosh|Mac OS X/i.test(c)){I("macos");return}if(/Linux/i.test(c)){I("linux");return}I("unknown")},[]),i.useEffect(()=>{let c=!1;return(async()=>{try{const D=await z("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!D.ok)return;const B=await D.json().catch(()=>null);if(!B||c)return;const d=typeof B.opencodeBinary=="string"?B.opencodeBinary.trim():"";d&&g(d)}catch{}})(),()=>{c=!0}},[]);const y=i.useCallback(async c=>{c.target.closest("button, a, input, select, textarea, code")||c.button===0&&w&&await ue()},[w]),f=i.useCallback(async()=>{try{const c=await z("/health");if(!c.ok)return!1;const D=await c.json();return D.openCodeRunning===!0||D.isOpenCodeReady===!0}catch{return!1}},[]),b=i.useCallback(async()=>{if(!(typeof window>"u")&&w)try{const c=await me();c.success&&c.path&&c.path.trim().length>0&&g(c.path.trim())}catch{}},[w]),R=i.useCallback(async()=>{U(!0);try{if(await pe({opencodeBinary:C.trim()}),w){await P();return}await z("/api/config/reload",{method:"POST"})}finally{setTimeout(()=>U(!1),1e3)}},[w,C]),N=i.useCallback(async()=>{const c=await he(Le);c.ok?(u(!0),setTimeout(()=>u(!1),2e3)):console.error("Failed to copy:",c.error)},[]),E=i.useCallback(async()=>{x(!0),k(null);try{await f()?t?.():k(n("onboarding.localSetup.errors.cliNotReady"))}catch(c){k(c instanceof Error?c.message:n("onboarding.localSetup.errors.detectionFailed"))}finally{x(!1)}},[f,t,n]),F=Ue,O=T==="windows"?"C:\\Users\\you\\AppData\\Roaming\\npm\\opencode.cmd":T==="linux"?"/home/you/.bun/bin/opencode":"/Users/you/.bun/bin/opencode";return e.jsxs("div",{className:"h-full flex items-center justify-center bg-transparent p-8 relative cursor-default select-none",onMouseDown:y,children:[e.jsxs("div",{className:"w-full max-w-lg space-y-4 text-center",children:[e.jsx("div",{className:"flex items-center",children:e.jsx(L,{variant:"ghost",onClick:a,className:"p-0 text-muted-foreground hover:text-foreground",children:n("onboarding.common.actions.back")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-foreground",children:n("onboarding.localSetup.title")}),e.jsx("p",{className:"text-muted-foreground",children:n("onboarding.localSetup.description")})]}),T==="windows"&&e.jsxs("div",{className:"mx-auto max-w-2xl rounded-lg border border-border bg-background/50 p-4 text-left",children:[e.jsx("div",{className:"text-sm text-foreground",children:n("onboarding.localSetup.windows.title")}),e.jsxs("ol",{className:"mt-2 list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:n("onboarding.localSetup.windows.stepRunInstallInWsl")}),e.jsx("li",{children:n("onboarding.localSetup.windows.stepSetBinaryPath")})]})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"bg-background/60 backdrop-blur-sm border border-border rounded-lg px-5 py-3 font-mono text-sm w-fit",children:l?e.jsxs("div",{className:"flex items-center justify-center gap-2",style:{color:"var(--status-success)"},children:[e.jsx(A,{name:"check",className:"h-4 w-4"}),n("onboarding.common.status.copiedToClipboard")]}):e.jsx(Te,{onCopy:N,copyTitle:n("onboarding.common.copyToClipboard")})})}),e.jsxs("a",{href:F,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground transition-colors inline-flex items-center gap-1 justify-center",children:[n(T==="windows"?"onboarding.localSetup.docs.windows":"onboarding.localSetup.docs.default"),e.jsx(A,{name:"external-link",className:"h-3 w-3"})]}),m&&e.jsx("div",{className:"mx-auto max-w-md rounded-lg border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive",children:m}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(L,{type:"button",onClick:E,disabled:K,className:"w-full max-w-xs",size:"lg",children:n(K?"onboarding.localSetup.actions.checking":"onboarding.localSetup.actions.checkAndContinue")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("onboarding.localSetup.helper.checkAndContinue")})]}),e.jsx("div",{className:"mx-auto w-full max-w-xl pt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:n("onboarding.localSetup.field.alreadyInstalled")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Y,{value:C,onChange:c=>g(c.target.value),placeholder:O,disabled:j,className:"flex-1 font-mono text-xs"}),e.jsx(L,{type:"button",variant:"secondary",onClick:b,disabled:j||!w,children:n("onboarding.localSetup.actions.browse")}),e.jsx(L,{type:"button",onClick:R,disabled:j,children:n("onboarding.localSetup.actions.apply")})]}),e.jsx("div",{className:"text-xs text-muted-foreground/70",children:n("onboarding.localSetup.helper.saveAndReload")})]})}),s&&r&&e.jsxs("div",{className:"text-center pt-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:n("onboarding.localSetup.remotePreference")}),e.jsx(L,{variant:"link",onClick:r,children:n("onboarding.localSetup.actions.connectRemoteServer")})]})]}),h&&e.jsx("div",{className:"absolute bottom-8 left-0 right-0 text-center space-y-1",children:T==="windows"?e.jsx(e.Fragment,{children:e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.windows.hintDetectionFailed")})}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.ensurePath")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.setEnv")}),e.jsx("p",{className:"text-sm text-muted-foreground/70",children:n("onboarding.localSetup.hint.missingRuntime")})]})})]})}function se(a,t){if(a?.trim())return ne(a.trim());if(t)return ne(t)}function _e(a,t,s){switch(a){case"local-unavailable":return{title:"Local OpenCode Unavailable",description:"OpenCode CLI could not be started or is not installed. Install OpenCode or connect to a remote server instead.",titleKey:"onboarding.desktopRecovery.localUnavailable.title",descriptionKey:"onboarding.desktopRecovery.localUnavailable.description",iconKey:"local",showRetry:!0,retryLabel:"Retry Local",retryLabelKey:"onboarding.desktopRecovery.localUnavailable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Set Up Local",useLocalLabelKey:"onboarding.desktopRecovery.localUnavailable.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-missing":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};case"remote-unreachable":{const r=se(t,s);return{title:"Remote Server Unreachable",description:`Could not connect to "${r||"the remote server"}". Check your network connection and verify the server address.`,titleKey:"onboarding.desktopRecovery.remoteUnreachable.title",descriptionKey:"onboarding.desktopRecovery.remoteUnreachable.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-wrong-service":{const r=se(t,s);return{title:"Incompatible Server",description:`The server at "${r||"unknown"}" is not running OpenChamber. Verify the address points to an OpenChamber server.`,titleKey:"onboarding.desktopRecovery.incompatibleServer.title",descriptionKey:"onboarding.desktopRecovery.incompatibleServer.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"remote-incompatible":{const r=se(t,s);return{title:"Server Update Required",description:`The OpenChamber server at "${r||"unknown"}" is not compatible with this app version. Update OpenChamber on the server, then try again.`,titleKey:"onboarding.desktopRecovery.remoteIncompatible.title",descriptionKey:"onboarding.desktopRecovery.remoteIncompatible.description",descriptionParams:r?{host:r}:void 0,iconKey:"remote",showRetry:!0,retryLabel:"Retry Connection",retryLabelKey:"onboarding.desktopRecovery.remoteUnreachable.retry",showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"}}case"missing-default-host":return{title:"No Default Connection",description:"Your saved default connection could not be found. Choose how you want to connect.",titleKey:"onboarding.desktopRecovery.noDefaultConnection.title",descriptionKey:"onboarding.desktopRecovery.noDefaultConnection.description",iconKey:"local",showRetry:!1,showUseLocal:!0,showUseRemote:!0,useLocalLabel:"Use Local",useLocalLabelKey:"onboarding.desktopRecovery.common.useLocal",useRemoteLabel:"Use Remote",useRemoteLabelKey:"onboarding.desktopRecovery.common.useRemote"};default:{const r=a;throw new Error(`Unknown recovery variant: ${r}`)}}}function De(a){switch(a){case"local":return e.jsx(A,{name:"macbook",className:"h-8 w-8"});case"remote":return e.jsx(A,{name:"server",className:"h-8 w-8"})}}function Ee({variant:a,hostLabel:t,hostUrl:s,onRetry:r,onUseLocal:n,onUseRemote:l,isRetrying:u=!1}){const{t:h}=Q(),o=_e(a,t,s),w=o.retryLabelKey??"onboarding.desktopRecovery.actions.retryConnection",S=i.useMemo(()=>{if(o.descriptionParams?.host)return o.descriptionParams;if(a==="remote-unreachable")return{host:h("onboarding.desktopRecovery.placeholders.remoteServer")};if(a==="remote-wrong-service"||a==="remote-incompatible")return{host:h("onboarding.desktopRecovery.placeholders.unknownServer")}},[o.descriptionParams,h,a]);return e.jsx("div",{className:"flex flex-col items-center justify-center h-full p-8",children:e.jsxs("div",{className:"w-full max-w-md space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-3 text-center",children:[e.jsx("div",{className:"p-3 rounded-full",style:{backgroundColor:"var(--status-warning)",opacity:.15},children:e.jsx("div",{style:{color:"var(--status-warning)"},children:De(o.iconKey)})}),e.jsx("h1",{className:"typography-ui-header text-xl font-semibold text-foreground",children:h(o.titleKey)}),e.jsx("p",{className:"text-muted-foreground text-sm max-w-sm",children:h(o.descriptionKey,S)})]}),s&&(a==="remote-unreachable"||a==="remote-wrong-service"||a==="remote-incompatible")&&e.jsxs("div",{className:"rounded-lg border border-border bg-background/50 p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:h("onboarding.remoteConnection.field.serverAddress")}),e.jsx("div",{className:"font-mono text-sm text-foreground truncate",children:ne(s)})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[o.showRetry&&r&&e.jsxs(L,{onClick:r,disabled:u,className:"w-full",children:[e.jsx(A,{name:"refresh",className:re("h-4 w-4",u&&"animate-spin")}),h(u?"onboarding.desktopRecovery.actions.retrying":w)]}),e.jsxs("div",{className:"flex gap-2",children:[o.showUseLocal&&n&&e.jsxs(L,{variant:"outline",onClick:n,disabled:u,className:"flex-1",children:[e.jsx(A,{name:"macbook",className:"h-4 w-4"}),h(o.useLocalLabelKey)]}),o.showUseRemote&&l&&e.jsxs(L,{variant:"outline",onClick:l,disabled:u,className:"flex-1",children:[e.jsx(A,{name:"server",className:"h-4 w-4"}),h(o.useRemoteLabelKey)]})]})]})]})})}function de(a,t){if(t==="use-remote")return{kind:"remote-form"};switch(a){case"local-unavailable":return{kind:"local-setup"};case"remote-unreachable":case"remote-incompatible":case"remote-wrong-service":case"remote-missing":case"missing-default-host":return{kind:"switch-default-to-local"};default:{const s=a;throw new Error(`Unhandled RecoveryVariant: ${s}`)}}}function Ae(a){const t=J.c(29),{variant:s,hostUrl:r,hostLabel:n,onRetry:l,onChooseRemote:u,showRemoteForm:h,onCloseRemoteForm:o,onSwitchToLocalFromRemote:w,onEnterLocalSetup:S,isRetrying:j,localAvailable:U}=a,K=h===void 0?!1:h,x=j===void 0?!1:j,m=U===void 0?!0:U,k=Fe;let C;t[0]!==l?(C=async()=>{if($()){await P();return}await z("/api/config/reload",{method:"POST"}),l?.()},t[0]=l,t[1]=C):C=t[1];const g=C;let T;t[2]!==S||t[3]!==s?(T=async()=>{if(de(s,"use-local").kind==="local-setup"){S?.();return}if(await k("local"),$()){await P();return}window.location.reload()},t[2]=S,t[3]=s,t[4]=T):T=t[4];const I=T;let y;t[5]!==u||t[6]!==s?(y=()=>{de(s,"use-remote").kind==="remote-form"&&u?.()},t[5]=u,t[6]=s,t[7]=y):y=t[7];const f=y;if(K){const N=s==="remote-wrong-service"?"":r||"",E=s==="remote-wrong-service"?"":n||"";let F;t[8]!==u||t[9]!==o?(F=o||(()=>u?.()),t[8]=u,t[9]=o,t[10]=F):F=t[10];const O=!m;let c;t[11]!==m||t[12]!==S||t[13]!==w?(c=m?w||(()=>{k("local").then(()=>{$()?P():S?.()})}):void 0,t[11]=m,t[12]=S,t[13]=w,t[14]=c):c=t[14];let D;return t[15]!==E||t[16]!==N||t[17]!==F||t[18]!==O||t[19]!==c?(D=e.jsx(xe,{onBack:F,initialUrl:N,initialLabel:E,isRecoveryMode:!0,showInstancePicker:O,onSwitchToLocal:c}),t[15]=E,t[16]=N,t[17]=F,t[18]=O,t[19]=c,t[20]=D):D=t[20],D}const b=m?I:void 0;let R;return t[21]!==g||t[22]!==f||t[23]!==n||t[24]!==r||t[25]!==x||t[26]!==b||t[27]!==s?(R=e.jsx(Ee,{variant:s,hostLabel:n,hostUrl:r,onRetry:g,onUseLocal:b,onUseRemote:f,isRetrying:x}),t[21]=g,t[22]=f,t[23]=n,t[24]=r,t[25]=x,t[26]=b,t[27]=s,t[28]=R):R=t[28],R}async function Fe(a){if(!$())return;const t=await W();await G({...t,...a==="local"?{defaultHostId:"local"}:{},initialHostChoiceCompleted:!0})}function mo(a){const t=J.c(29),{onBack:s,onCliAvailable:r,mode:n,recoveryVariant:l,recoveryHostUrl:u,recoveryHostLabel:h,onEnterLocalSetup:o,localAvailable:w}=a,S=n===void 0?"first-launch":n,j=l===void 0?"missing-default-host":l,U=w===void 0?!0:w,[K,x]=i.useState(!1),[m,k]=i.useState(!1);let C;t[0]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{k(!1),x(!1)},t[0]=C):C=t[0];let g;t[1]!==S||t[2]!==h||t[3]!==u||t[4]!==j?(g=[S,j,u,h],t[1]=S,t[2]=h,t[3]=u,t[4]=j,t[5]=g):g=t[5],i.useEffect(C,g);const T=m?"local-setup":S;if(T==="recovery"){let y;t[6]===Symbol.for("react.memo_cache_sentinel")?(y=()=>x(!0),t[6]=y):y=t[6];let f,b;t[7]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!1),b=()=>{x(!1),k(!0)},t[7]=f,t[8]=b):(f=t[7],b=t[8]);let R;t[9]!==o?(R=()=>{k(!0),o?.()},t[9]=o,t[10]=R):R=t[10];let N;return t[11]!==U||t[12]!==h||t[13]!==u||t[14]!==j||t[15]!==K||t[16]!==R?(N=e.jsx(Ae,{variant:j,hostUrl:u,hostLabel:h,onChooseRemote:y,showRemoteForm:K,onCloseRemoteForm:f,onSwitchToLocalFromRemote:b,onEnterLocalSetup:R,localAvailable:U}),t[11]=U,t[12]=h,t[13]=u,t[14]=j,t[15]=K,t[16]=R,t[17]=N):N=t[17],N}if(T==="local-setup"){let y;t[18]!==s||t[19]!==m?(y=()=>{m?k(!1):s?.()},t[18]=s,t[19]=m,t[20]=y):y=t[20];let f;t[21]===Symbol.for("react.memo_cache_sentinel")?(f=()=>x(!0),t[21]=f):f=t[21];let b;return t[22]!==r||t[23]!==m||t[24]!==y?(b=e.jsx(Ie,{onBack:y,onCliAvailable:r,isFromRecovery:m,onSwitchToRemote:f}),t[22]=r,t[23]=m,t[24]=y,t[25]=b):b=t[25],b}let I;return t[26]!==U||t[27]!==r?(I=e.jsx(Re,{onCliAvailable:r,localAvailable:U}),t[26]=U,t[27]=r,t[28]=I):I=t[28],I}export{mo as OnboardingScreen};
@@ -1 +1 @@
1
- import{hK as j,h3 as k,hb as y}from"./useAppFontEffects-CCgvcQ6u.js";import{k as D,a as C}from"./web-components-B6QgbmTo.js";import{M as P,G as O,u as L,W as A,a as M,b as R,n as F,t as H}from"./Virtualizer-CZlLSacm.js";import{j as d,r as w}from"./vendor-react-BUCujlKS.js";import{V as _,F as N}from"./VirtualizedFileDiff-vqW3KKo5.js";function T({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function V(e,t){const n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:b(n,e.startContentIndex)}}function b(e,t){let n=e.unifiedLineStart;for(let l=0;l<t;l++){const o=e.hunkContent[l];n+=o.type==="context"?o.lines:o.deletions+o.additions}return n}function z(e){const t=j(e);if(t.length!==1)throw console.error(t),new Error("PatchDiff: Provided patch must include only 1 patch, with 1 diff");const{files:n}=t[0];if(n.length!==1)throw console.error(n),new Error("FileDiff: Provided patch must contain exactly 1 file diff");return n[0]}function U({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:l,renderHeaderFilenameSuffix:o,renderHeaderMetadata:x,renderAnnotation:f,renderGutterUtility:u,renderMergeConflictUtility:s,lineAnnotations:a,getHoveredLine:p,getInstance:m}){const g=n?.(e),c=l?.(e),i=o?.(e),v=x?.(e);return d.jsxs(d.Fragment,{children:[g!=null?d.jsx("div",{slot:k,children:g}):d.jsxs(d.Fragment,{children:[c!=null&&d.jsx("div",{slot:"header-prefix",children:c}),i!=null&&d.jsx("div",{slot:"header-filename-suffix",children:i}),v!=null&&d.jsx("div",{slot:"header-metadata",children:v})]}),f!=null&&a?.map((r,h)=>d.jsx("div",{slot:D(r),children:f(r)},h)),t!=null&&s!=null&&m!=null&&t.map(r=>{if(r==null)return;const h=$(r,e);return d.jsx("div",{slot:h,style:P,children:s(r,m)},h)}),u!=null&&d.jsx("div",{slot:"gutter-utility-slot",style:O,children:u(p)})]})}function $(e,t){const n=V(e,t);return n!=null?T({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex}):void 0}const S=typeof window>"u"?w.useEffect:w.useLayoutEffect;function G({fileDiff:e,options:t,lineAnnotations:n,selectedLines:l,prerenderedHTML:o,metrics:x,hasGutterRenderUtility:f,hasCustomHeader:u,disableWorkerPool:s,contentEditable:a}){const p=L(),m=l!==void 0,g=w.useContext(A),c=M(),i=w.useRef(null),v=R(r=>{if(r!=null){if(i.current!=null)throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");p!=null?i.current=new _(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),p,x,s?void 0:g,!0):i.current=new N(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),s?void 0:g,!0),i.current.hydrate({fileDiff:e,fileContainer:r,lineAnnotations:n,prerenderedHTML:o})}else{if(i.current==null)throw new Error("useFileDiffInstance: A FileDiff instance should exist when unmounting");i.current.cleanUp(),i.current=null}});return S(()=>{const{current:r}=i;if(r==null)return;const h=E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),I=!C(r.options,h);r.setOptions(h),r.render({forceRender:I,fileDiff:e,lineAnnotations:n}),l!==void 0&&r.setSelectedLines(l)}),S(()=>{if(a&&i.current!=null){if(c===void 0)throw new Error("FileDiff: Editor is not attached");return c.edit(i.current)}},[a,c]),{ref:v,getHoveredLine:w.useCallback(()=>i.current?.getHoveredLine(),[])}}function E({options:e,controlledSelection:t,contentEditable:n,hasCustomHeader:l,hasEditor:o,hasGutterRenderUtility:x}){const f=n&&o,u=t||x||l;if(!u&&!f)return e;let s={...e};return u&&(s={...s,controlledSelection:t,renderCustomHeader:l?F:e?.renderCustomHeader,renderGutterUtility:x?F:e?.renderGutterUtility}),f&&(s={...s,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,expandUnchanged:!0,lineHoverHighlight:"disabled"}),s}function X({patch:e,options:t,metrics:n,lineAnnotations:l,selectedLines:o,className:x,style:f,prerenderedHTML:u,renderAnnotation:s,renderCustomHeader:a,renderHeaderPrefix:p,renderHeaderFilenameSuffix:m,renderHeaderMetadata:g,renderGutterUtility:c,disableWorkerPool:i=!1,contentEditable:v=!1}){const r=q(e),{ref:h,getHoveredLine:I}=G({fileDiff:r,options:t,metrics:n,lineAnnotations:l,selectedLines:o,prerenderedHTML:u,hasGutterRenderUtility:c!=null,hasCustomHeader:a!=null,disableWorkerPool:i,contentEditable:v});return d.jsx(y,{ref:h,className:x,style:f,children:H(U({fileDiff:r,renderCustomHeader:a,renderHeaderPrefix:p,renderHeaderFilenameSuffix:m,renderHeaderMetadata:g,renderAnnotation:s,lineAnnotations:l,renderGutterUtility:c,getHoveredLine:I}),u)})}function q(e){return w.useMemo(()=>z(e),[e])}export{X as P};
1
+ import{hM as j,h5 as k,hd as y}from"./useAppFontEffects-Bb1Zihd2.js";import{k as D,a as C}from"./web-components-C06MmTcR.js";import{M as P,G as O,u as L,W as M,a as A,b as R,n as F,t as H}from"./Virtualizer-CZlLSacm.js";import{j as d,r as w}from"./vendor-react-BUCujlKS.js";import{V as _,F as N}from"./VirtualizedFileDiff-aaIfrRxl.js";function T({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function V(e,t){const n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:z(n,e.startContentIndex)}}function z(e,t){let n=e.unifiedLineStart;for(let l=0;l<t;l++){const o=e.hunkContent[l];n+=o.type==="context"?o.lines:o.deletions+o.additions}return n}function U(e){const t=j(e);if(t.length!==1)throw console.error(t),new Error("PatchDiff: Provided patch must include only 1 patch, with 1 diff");const{files:n}=t[0];if(n.length!==1)throw console.error(n),new Error("FileDiff: Provided patch must contain exactly 1 file diff");return n[0]}function $({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:l,renderHeaderFilenameSuffix:o,renderHeaderMetadata:x,renderAnnotation:f,renderGutterUtility:u,renderMergeConflictUtility:s,lineAnnotations:a,getHoveredLine:p,getInstance:m}){const g=n?.(e),c=l?.(e),i=o?.(e),v=x?.(e);return d.jsxs(d.Fragment,{children:[g!=null?d.jsx("div",{slot:k,children:g}):d.jsxs(d.Fragment,{children:[c!=null&&d.jsx("div",{slot:"header-prefix",children:c}),i!=null&&d.jsx("div",{slot:"header-filename-suffix",children:i}),v!=null&&d.jsx("div",{slot:"header-metadata",children:v})]}),f!=null&&a?.map((r,h)=>d.jsx("div",{slot:D(r),children:f(r)},h)),t!=null&&s!=null&&m!=null&&t.map(r=>{if(r==null)return;const h=b(r,e);return d.jsx("div",{slot:h,style:P,children:s(r,m)},h)}),u!=null&&d.jsx("div",{slot:"gutter-utility-slot",style:O,children:u(p)})]})}function b(e,t){const n=V(e,t);return n!=null?T({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex}):void 0}const S=typeof window>"u"?w.useEffect:w.useLayoutEffect;function G({fileDiff:e,options:t,lineAnnotations:n,selectedLines:l,prerenderedHTML:o,metrics:x,hasGutterRenderUtility:f,hasCustomHeader:u,disableWorkerPool:s,contentEditable:a}){const p=L(),m=l!==void 0,g=w.useContext(M),c=A(),i=w.useRef(null),v=R(r=>{if(r!=null){if(i.current!=null)throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");p!=null?i.current=new _(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),p,x,s?void 0:g,!0):i.current=new N(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),s?void 0:g,!0),i.current.hydrate({fileDiff:e,fileContainer:r,lineAnnotations:n,prerenderedHTML:o})}else{if(i.current==null)throw new Error("useFileDiffInstance: A FileDiff instance should exist when unmounting");i.current.cleanUp(),i.current=null}});return S(()=>{const{current:r}=i;if(r==null)return;const h=E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),I=!C(r.options,h);r.setOptions(h),r.render({forceRender:I,fileDiff:e,lineAnnotations:n}),l!==void 0&&r.setSelectedLines(l)}),S(()=>{if(a&&i.current!=null){if(c===void 0)throw new Error("FileDiff: Editor is not attached");return c.edit(i.current)}},[a,c]),{ref:v,getHoveredLine:w.useCallback(()=>i.current?.getHoveredLine(),[])}}function E({options:e,controlledSelection:t,contentEditable:n,hasCustomHeader:l,hasEditor:o,hasGutterRenderUtility:x}){const f=n&&o,u=t||x||l;if(!u&&!f)return e;let s={...e};return u&&(s={...s,controlledSelection:t,renderCustomHeader:l?F:e?.renderCustomHeader,renderGutterUtility:x?F:e?.renderGutterUtility}),f&&(s={...s,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,expandUnchanged:!0,lineHoverHighlight:"disabled"}),s}function X({patch:e,options:t,metrics:n,lineAnnotations:l,selectedLines:o,className:x,style:f,prerenderedHTML:u,renderAnnotation:s,renderCustomHeader:a,renderHeaderPrefix:p,renderHeaderFilenameSuffix:m,renderHeaderMetadata:g,renderGutterUtility:c,disableWorkerPool:i=!1,contentEditable:v=!1}){const r=q(e),{ref:h,getHoveredLine:I}=G({fileDiff:r,options:t,metrics:n,lineAnnotations:l,selectedLines:o,prerenderedHTML:u,hasGutterRenderUtility:c!=null,hasCustomHeader:a!=null,disableWorkerPool:i,contentEditable:v});return d.jsx(y,{ref:h,className:x,style:f,children:H($({fileDiff:r,renderCustomHeader:a,renderHeaderPrefix:p,renderHeaderFilenameSuffix:m,renderHeaderMetadata:g,renderAnnotation:s,lineAnnotations:l,renderGutterUtility:c,getHoveredLine:I}),u)})}function q(e){return w.useMemo(()=>U(e),[e])}export{X as P};
@@ -1,4 +1,4 @@
1
- import{R as N,j as T,c as xe,r as a}from"./vendor-react-BUCujlKS.js";import{a as Be}from"./web-components-B6QgbmTo.js";import{f as Te}from"./computeVirtualFileMetrics-DUnyszhW.js";import{V as je,F as Oe}from"./VirtualizedFileDiff-vqW3KKo5.js";import{V as De}from"./Virtualizer-D_a8gKmg.js";import{e8 as Ve,e9 as Ce,b7 as Ue,b$ as Ge,h as Pe}from"./useAppFontEffects-CCgvcQ6u.js";import{I as Ae,a as Ke,u as _e}from"./useInlineCommentController-BkfXnjNZ.js";import"./index-DDInLQDd.js";import{a0 as Ye}from"./runtimeEndpointReset-gWt3Lb5D.js";import{ensurePierreThemeRegistered as Fe,getResolvedShikiTheme as Ie}from"./appThemeRegistry-BK0dHKa6.js";const he=r=>{if(r.type==="new"){const t=Math.min(r.selection.start,r.selection.end),i=Math.max(r.selection.start,r.selection.end);return`new-comment-${r.selection.side??"additions"}-${t}-${i}`}return`draft-${r.draft.id}`},Xe=r=>{const{drafts:t,editingDraftId:i,selection:o}=r,l=[];for(const g of t){if(!Number.isFinite(g.endLine))continue;const E=Math.max(1,Math.floor(g.endLine)),C=g.side==="original"?"deletions":"additions";l.push({lineNumber:E,side:C,metadata:{type:g.id===i?"edit":"saved",draft:g}})}return o&&!i&&l.push({lineNumber:Math.max(o.start,o.end),side:o.side??"additions",metadata:{type:"new",selection:o}}),l};function Je(r){const t=r.trim();if(!t)return null;if(/^-?\d+(\.\d+)?$/.test(t)){const i=Number.parseFloat(t);return Number.isFinite(i)?i:null}if(t.endsWith("px")){const i=Number.parseFloat(t.slice(0,-2));return Number.isFinite(i)?i:null}return null}function ze(r){if(!(!r||r<=0))return Math.max(200,Math.floor(r))}function Qe(r){const{diffRootRef:t,drafts:i,selection:o,editingDraftId:l,commentText:g,onTextChange:E,fileLabel:C,onSave:u,onCancel:q,onEdit:P,onDelete:O}=r,[U,oe]=N.useState(0),[se,Q]=N.useState(null),w=N.useMemo(()=>!o||l?null:he({type:"new",selection:o}),[l,o]),H=N.useMemo(()=>{const c=i.map(b=>he({type:b.id===l?"edit":"saved",draft:b}));return w&&c.push(w),c},[i,l,w]),D=N.useCallback(c=>{const b=t.current;if(!b)return null;const R=b.querySelector("diffs-container");if(!(R instanceof HTMLElement))return null;const S=R.querySelector(`[data-annotation-id="${c}"]`);if(S instanceof HTMLElement)return S;const $=R.shadowRoot;return $?$.querySelector(`[data-annotation-id="${c}"]`):null},[t]);N.useEffect(()=>{if(H.length===0)return;let c=!1,b=0;const R=12,S=()=>{c||H.every(A=>!!D(A))||b>=R||(b+=1,requestAnimationFrame(()=>{c||(oe(A=>A+1),S())}))};return S(),()=>{c=!0}},[H,D]),N.useEffect(()=>{const c=t.current;if(!c)return;const b=()=>{const S=getComputedStyle(c),$=Je(S.getPropertyValue("--oc-context-panel-width")),A=c.getBoundingClientRect(),F=$??A.width;Q(F>0?F:null)};b();const R=new ResizeObserver(()=>{b()});return R.observe(c),window.addEventListener("resize",b),()=>{R.disconnect(),window.removeEventListener("resize",b)}},[t]);const I=N.useCallback(c=>{const R=t.current?.getBoundingClientRect(),S=c.closest("[data-annotation-content]"),$=S instanceof HTMLElement?S.getBoundingClientRect():c.getBoundingClientRect(),A=[$.width];R&&A.push(R.right-$.left);const F=A.filter(V=>Number.isFinite(V)&&V>0);return F.length>0?ze(Math.min(...F)):ze(se)},[t,se]);return T.jsxs(T.Fragment,{children:[i.map(c=>{const b=he({type:c.id===l?"edit":"saved",draft:c}),R=D(b);if(!R)return null;const S=I(R);return c.id===l?xe.createPortal(T.jsx(Ae,{initialText:g,onTextChange:E,fileLabel:C,lineRange:{start:c.startLine,end:c.endLine,side:c.side==="original"?"deletions":"additions"},isEditing:!0,onSave:u,onCancel:q,maxWidth:S}),R,`draft-edit-${c.id}`):xe.createPortal(T.jsx(Ke,{draft:c,onEdit:()=>P(c),onDelete:()=>O(c),maxWidth:S}),R,`draft-card-${c.id}`)}),o&&!l&&w&&(()=>{const c=D(w);if(!c)return null;const b=I(c);return xe.createPortal(T.jsx(Ae,{initialText:g,onTextChange:E,fileLabel:C,lineRange:o,isEditing:!1,onSave:u,onCancel:q,maxWidth:b}),c,w)})()]})}const qe=5e5,Ze=`
1
+ import{R as N,j as T,c as xe,r as a}from"./vendor-react-BUCujlKS.js";import{a as Be}from"./web-components-C06MmTcR.js";import{f as Te}from"./computeVirtualFileMetrics-DfgllYQc.js";import{V as je,F as Oe}from"./VirtualizedFileDiff-aaIfrRxl.js";import{V as De}from"./Virtualizer-D_a8gKmg.js";import{ea as Ve,eb as Ce,b7 as Ue,c0 as Ge,h as Pe}from"./useAppFontEffects-Bb1Zihd2.js";import{I as Ae,a as Ke,u as _e}from"./useInlineCommentController-B8dQWRpH.js";import"./index-B0aX0JeI.js";import{a6 as Ye}from"./runtimeEndpointReset-DebJIo5U.js";import{ensurePierreThemeRegistered as Fe,getResolvedShikiTheme as Ie}from"./appThemeRegistry-BK0dHKa6.js";const he=r=>{if(r.type==="new"){const t=Math.min(r.selection.start,r.selection.end),i=Math.max(r.selection.start,r.selection.end);return`new-comment-${r.selection.side??"additions"}-${t}-${i}`}return`draft-${r.draft.id}`},Xe=r=>{const{drafts:t,editingDraftId:i,selection:o}=r,l=[];for(const g of t){if(!Number.isFinite(g.endLine))continue;const E=Math.max(1,Math.floor(g.endLine)),C=g.side==="original"?"deletions":"additions";l.push({lineNumber:E,side:C,metadata:{type:g.id===i?"edit":"saved",draft:g}})}return o&&!i&&l.push({lineNumber:Math.max(o.start,o.end),side:o.side??"additions",metadata:{type:"new",selection:o}}),l};function Je(r){const t=r.trim();if(!t)return null;if(/^-?\d+(\.\d+)?$/.test(t)){const i=Number.parseFloat(t);return Number.isFinite(i)?i:null}if(t.endsWith("px")){const i=Number.parseFloat(t.slice(0,-2));return Number.isFinite(i)?i:null}return null}function ze(r){if(!(!r||r<=0))return Math.max(200,Math.floor(r))}function Qe(r){const{diffRootRef:t,drafts:i,selection:o,editingDraftId:l,commentText:g,onTextChange:E,fileLabel:C,onSave:u,onCancel:q,onEdit:P,onDelete:O}=r,[U,oe]=N.useState(0),[se,Q]=N.useState(null),w=N.useMemo(()=>!o||l?null:he({type:"new",selection:o}),[l,o]),H=N.useMemo(()=>{const c=i.map(b=>he({type:b.id===l?"edit":"saved",draft:b}));return w&&c.push(w),c},[i,l,w]),D=N.useCallback(c=>{const b=t.current;if(!b)return null;const R=b.querySelector("diffs-container");if(!(R instanceof HTMLElement))return null;const S=R.querySelector(`[data-annotation-id="${c}"]`);if(S instanceof HTMLElement)return S;const $=R.shadowRoot;return $?$.querySelector(`[data-annotation-id="${c}"]`):null},[t]);N.useEffect(()=>{if(H.length===0)return;let c=!1,b=0;const R=12,S=()=>{c||H.every(A=>!!D(A))||b>=R||(b+=1,requestAnimationFrame(()=>{c||(oe(A=>A+1),S())}))};return S(),()=>{c=!0}},[H,D]),N.useEffect(()=>{const c=t.current;if(!c)return;const b=()=>{const S=getComputedStyle(c),$=Je(S.getPropertyValue("--oc-context-panel-width")),A=c.getBoundingClientRect(),F=$??A.width;Q(F>0?F:null)};b();const R=new ResizeObserver(()=>{b()});return R.observe(c),window.addEventListener("resize",b),()=>{R.disconnect(),window.removeEventListener("resize",b)}},[t]);const I=N.useCallback(c=>{const R=t.current?.getBoundingClientRect(),S=c.closest("[data-annotation-content]"),$=S instanceof HTMLElement?S.getBoundingClientRect():c.getBoundingClientRect(),A=[$.width];R&&A.push(R.right-$.left);const F=A.filter(V=>Number.isFinite(V)&&V>0);return F.length>0?ze(Math.min(...F)):ze(se)},[t,se]);return T.jsxs(T.Fragment,{children:[i.map(c=>{const b=he({type:c.id===l?"edit":"saved",draft:c}),R=D(b);if(!R)return null;const S=I(R);return c.id===l?xe.createPortal(T.jsx(Ae,{initialText:g,onTextChange:E,fileLabel:C,lineRange:{start:c.startLine,end:c.endLine,side:c.side==="original"?"deletions":"additions"},isEditing:!0,onSave:u,onCancel:q,maxWidth:S}),R,`draft-edit-${c.id}`):xe.createPortal(T.jsx(Ke,{draft:c,onEdit:()=>P(c),onDelete:()=>O(c),maxWidth:S}),R,`draft-card-${c.id}`)}),o&&!l&&w&&(()=>{const c=D(w);if(!c)return null;const b=I(c);return xe.createPortal(T.jsx(Ae,{initialText:g,onTextChange:E,fileLabel:C,lineRange:o,isEditing:!1,onSave:u,onCancel:q,maxWidth:b}),c,w)})()]})}const qe=5e5,Ze=`
2
2
  :host {
3
3
  font-family: var(--font-mono);
4
4
  font-size: var(--text-code);
@@ -1,5 +1,5 @@
1
- import{R as t,j as n}from"./vendor-react-BUCujlKS.js";import{m as xt,u as Ze,a as he,o as qe,r as Xe,v as jt}from"./index-DDInLQDd.js";import{c as Ct,s as Rt,P as Pt,C as Mt}from"./shikiHighlight-CRpCl7UT.js";import{f as Tt,y as H,c7 as kt,ax as Nt,b as et,ai as Et,ac as It,W as Dt,b7 as Vt,N as Ft,f2 as Lt,Z as $t,gY as At,l as tt,f1 as Ot,ao as nt,gb as Kt,e$ as Wt,cT as rt,f4 as zt,f5 as _t,m as Bt,gZ as Gt,b6 as st,a7 as ge,a8 as we,b3 as it,B as ne,I as W,a9 as ve,b5 as ot,b2 as re,g as Jt,b$ as Ut,aq as Ht,bY as Yt,g_ as Qt}from"./useAppFontEffects-CCgvcQ6u.js";import{u as Zt,n as qt}from"./useInlineCommentController-BkfXnjNZ.js";import{b as Xt}from"./CodeMirrorCommentWidgets-BO_2OW4E.js";import{getResolvedShikiTheme as en}from"./appThemeRegistry-BK0dHKa6.js";import{E as tn}from"./vendor-codemirror-view-CiLROUVV.js";import{$ as nn}from"./runtimeEndpointReset-gWt3Lb5D.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-zod-DVWEh-IS.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-CV-DwAiX.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-BxpoC5Fp.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./registerCustomTheme-BBXUCRnG.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const rn=()=>{const l=new Map,c=new Map;return{schedule:(o,s,f)=>{if(s<=(c.get(o)??Number.NEGATIVE_INFINITY))return l.get(o)??Promise.resolve();c.set(o,s);const g=(l.get(o)??Promise.resolve()).then(f,f);return l.set(o,g.catch(()=>{c.get(o)===s&&c.delete(o)})),g},pendingFor:async o=>{await l.get(o)},reset:o=>{c.delete(o)}}},b=l=>{if(!l)return"";const c=l.replace(/\\/g,"/");return c==="/"?"/":c.replace(/\/+$/,"")},Se=(l,c)=>{const o=b(l),s=c.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!o||o==="/"?`/${s}`:`${o}/${s}`},sn=(l,c,o)=>Se(Se(Se(l,".opencode"),"plans"),`${c}-${o}.md`),on=(l,c)=>`~/.opencode/plans/${l}-${c}.md`,an=(l,c)=>{const o=l.trim();return o.startsWith("~")?o==="~"?c||o:(o.startsWith("~/")||o.startsWith("~\\"))&&c?`${c}${o.slice(1)}`:o:o},ln=(l,c)=>{const o=b(c.currentDirectory),s=b(c.homeDirectory),f=b(l);return o&&f.startsWith(o+"/")?f.slice(o.length+1):s&&f===s?"~":s&&f.startsWith(s+"/")?`~${f.slice(s.length)}`:f},cn=(l,c,o)=>{const s=b(l.trim());if(!s)return null;const f=o?c.find(g=>g.id===o)??null:null;if(f?.path){const g=b(f.path);if(s===g||s.startsWith(`${g}/`))return{id:f.id,path:f.path}}const N=c.filter(g=>{const E=b(g.path);return s===E||s.startsWith(`${E}/`)}).sort((g,E)=>b(E.path).length-b(g.path).length)[0];return N?{id:N.id,path:N.path}:null},un=l=>jt(()=>l()),cs=({targetPath:l=null,savedProjectPlan:c=null,onNavigatedToChat:o})=>{const{t:s}=Tt(),f=H(e=>e.currentSessionId),N=H(e=>e.createSession),g=H(e=>e.initializeNewOpenChamberSession),E=H(e=>e.sendMessage),ye=H(e=>e.setCurrentSession),be=kt(),z=xt(e=>e.homeDirectory),xe=Nt(e=>e.planModeEnabled),je=et(e=>e.projects),Ce=et(e=>e.activeProjectId),Re=Et(e=>e.directories),Pe=It()??"",Me=Ze(e=>e.setSessionSwitcherOpen),_=Dt(),I=t.useSyncExternalStore(un,he,he),{isMobile:Te}=Vt(),{currentTheme:Y}=Ft(),S=t.useMemo(()=>f?be.find(e=>e.id===f)??null:null,[f,be]),R=t.useMemo(()=>{const e=typeof S?.directory=="string"?S.directory:"";return b(e||"")},[S?.directory]),ke=t.useMemo(()=>b(Pe||R),[Pe,R]),B=t.useMemo(()=>cn(ke,je,Ce),[Ce,ke,je]),se=c?.projectRef.id??null,ie=c?.projectRef.path??null,v=t.useMemo(()=>se&&ie?{id:se,path:ie}:null,[se,ie]),P=c?.planId??null,G=v&&P?JSON.stringify(["saved-plan",I,Lt(v),P]):null,L=v?.id===$t,Q=t.useMemo(()=>{const e=v??B;return e?Re.get(e.path)?.isGitRepo===!0:!1},[B,Re,v]),[D,$]=t.useState(null),[Ne,Ee]=t.useState(!1),[p,M]=t.useState(null),[oe,ae]=t.useState(null),at=!!p||!!oe,le=t.useMemo(()=>!p||!R||!z?p:ln(p,{currentDirectory:R,homeDirectory:z}),[p,R,z]),[h,x]=t.useState(""),{isPlaying:Z,play:lt,stop:ct}=At(),ut=tt(e=>e.showMessageTTSButtons),[Ie,ce]=t.useState(null),[De,ue]=t.useState(null),de=t.useMemo(()=>le&&le.split("/").pop()||s("planView.file.defaultName"),[le,s]),me=t.useMemo(()=>h.trim()?Ot(h,s("planView.title.default")).title:s("planView.title.default"),[h,s]),q=t.useMemo(()=>me.trim()||s("planView.title.default"),[me,s]),[dt,V]=t.useState(!1),[mt,Ve]=t.useState(!1),[X,Fe]=t.useState("edit"),J=t.useRef(null),[u,y]=t.useState(null),Le=t.useRef(null),pt=t.useRef(null),$e="openchamber:plan:md-viewer-mode";t.useEffect(()=>{try{const e=localStorage.getItem($e);if(!e)return;const i=JSON.parse(e);(i==="preview"||i==="edit")&&Fe(i)}catch{}},[]);const ft=t.useCallback(e=>{Fe(e);try{localStorage.setItem($e,JSON.stringify(e))}catch{}},[]),A=t.useRef(!1),T=t.useRef(null),[Ae,O]=t.useState(!1);t.useEffect(()=>{const e=()=>{A.current=!1,T.current=null,O(!1)};return document.addEventListener("mouseup",e),()=>document.removeEventListener("mouseup",e)},[]);const ht=t.useCallback((e,i)=>{const a=e.split(`
1
+ import{R as t,j as n}from"./vendor-react-BUCujlKS.js";import{m as xt,u as Ze,a as he,o as qe,r as Xe,v as jt}from"./index-B0aX0JeI.js";import{c as Ct,s as Rt,P as Pt,C as Mt}from"./shikiHighlight-DJSXdcG4.js";import{f as Tt,y as H,c8 as kt,ax as Nt,b as et,ai as Et,ac as It,W as Dt,b7 as Vt,N as Ft,f5 as Lt,Z as At,g_ as Ot,l as tt,f4 as $t,ao as nt,ge as Kt,f2 as Wt,cV as rt,f7 as zt,f8 as _t,m as Bt,g$ as Gt,b6 as st,a7 as ge,a8 as we,b3 as it,B as ne,I as W,a9 as ve,b5 as ot,b2 as re,g as Jt,c0 as Ut,aq as Ht,bZ as Qt,h0 as Yt}from"./useAppFontEffects-Bb1Zihd2.js";import{u as Zt,n as qt}from"./useInlineCommentController-B8dQWRpH.js";import{b as Xt}from"./CodeMirrorCommentWidgets-BI-TY1UG.js";import{getResolvedShikiTheme as en}from"./appThemeRegistry-BK0dHKa6.js";import{E as tn}from"./vendor-codemirror-view-CiLROUVV.js";import{a5 as nn}from"./runtimeEndpointReset-DebJIo5U.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-zod-CK21ihK-.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-prHos-tt.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-CNjvbb69.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./registerCustomTheme-BBXUCRnG.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";const rn=()=>{const l=new Map,c=new Map;return{schedule:(o,s,f)=>{if(s<=(c.get(o)??Number.NEGATIVE_INFINITY))return l.get(o)??Promise.resolve();c.set(o,s);const g=(l.get(o)??Promise.resolve()).then(f,f);return l.set(o,g.catch(()=>{c.get(o)===s&&c.delete(o)})),g},pendingFor:async o=>{await l.get(o)},reset:o=>{c.delete(o)}}},b=l=>{if(!l)return"";const c=l.replace(/\\/g,"/");return c==="/"?"/":c.replace(/\/+$/,"")},Se=(l,c)=>{const o=b(l),s=c.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!o||o==="/"?`/${s}`:`${o}/${s}`},sn=(l,c,o)=>Se(Se(Se(l,".opencode"),"plans"),`${c}-${o}.md`),on=(l,c)=>`~/.opencode/plans/${l}-${c}.md`,an=(l,c)=>{const o=l.trim();return o.startsWith("~")?o==="~"?c||o:(o.startsWith("~/")||o.startsWith("~\\"))&&c?`${c}${o.slice(1)}`:o:o},ln=(l,c)=>{const o=b(c.currentDirectory),s=b(c.homeDirectory),f=b(l);return o&&f.startsWith(o+"/")?f.slice(o.length+1):s&&f===s?"~":s&&f.startsWith(s+"/")?`~${f.slice(s.length)}`:f},cn=(l,c,o)=>{const s=b(l.trim());if(!s)return null;const f=o?c.find(g=>g.id===o)??null:null;if(f?.path){const g=b(f.path);if(s===g||s.startsWith(`${g}/`))return{id:f.id,path:f.path}}const N=c.filter(g=>{const E=b(g.path);return s===E||s.startsWith(`${E}/`)}).sort((g,E)=>b(E.path).length-b(g.path).length)[0];return N?{id:N.id,path:N.path}:null},un=l=>jt(()=>l()),cs=({targetPath:l=null,savedProjectPlan:c=null,onNavigatedToChat:o})=>{const{t:s}=Tt(),f=H(e=>e.currentSessionId),N=H(e=>e.createSession),g=H(e=>e.initializeNewOpenChamberSession),E=H(e=>e.sendMessage),ye=H(e=>e.setCurrentSession),be=kt(),z=xt(e=>e.homeDirectory),xe=Nt(e=>e.planModeEnabled),je=et(e=>e.projects),Ce=et(e=>e.activeProjectId),Re=Et(e=>e.directories),Pe=It()??"",Me=Ze(e=>e.setSessionSwitcherOpen),_=Dt(),I=t.useSyncExternalStore(un,he,he),{isMobile:Te}=Vt(),{currentTheme:Q}=Ft(),S=t.useMemo(()=>f?be.find(e=>e.id===f)??null:null,[f,be]),R=t.useMemo(()=>{const e=typeof S?.directory=="string"?S.directory:"";return b(e||"")},[S?.directory]),ke=t.useMemo(()=>b(Pe||R),[Pe,R]),B=t.useMemo(()=>cn(ke,je,Ce),[Ce,ke,je]),se=c?.projectRef.id??null,ie=c?.projectRef.path??null,v=t.useMemo(()=>se&&ie?{id:se,path:ie}:null,[se,ie]),P=c?.planId??null,G=v&&P?JSON.stringify(["saved-plan",I,Lt(v),P]):null,L=v?.id===At,Y=t.useMemo(()=>{const e=v??B;return e?Re.get(e.path)?.isGitRepo===!0:!1},[B,Re,v]),[D,A]=t.useState(null),[Ne,Ee]=t.useState(!1),[p,M]=t.useState(null),[oe,ae]=t.useState(null),at=!!p||!!oe,le=t.useMemo(()=>!p||!R||!z?p:ln(p,{currentDirectory:R,homeDirectory:z}),[p,R,z]),[h,x]=t.useState(""),{isPlaying:Z,play:lt,stop:ct}=Ot(),ut=tt(e=>e.showMessageTTSButtons),[Ie,ce]=t.useState(null),[De,ue]=t.useState(null),de=t.useMemo(()=>le&&le.split("/").pop()||s("planView.file.defaultName"),[le,s]),me=t.useMemo(()=>h.trim()?$t(h,s("planView.title.default")).title:s("planView.title.default"),[h,s]),q=t.useMemo(()=>me.trim()||s("planView.title.default"),[me,s]),[dt,V]=t.useState(!1),[mt,Ve]=t.useState(!1),[X,Fe]=t.useState("edit"),J=t.useRef(null),[u,y]=t.useState(null),Le=t.useRef(null),pt=t.useRef(null),Ae="openchamber:plan:md-viewer-mode";t.useEffect(()=>{try{const e=localStorage.getItem(Ae);if(!e)return;const i=JSON.parse(e);(i==="preview"||i==="edit")&&Fe(i)}catch{}},[]);const ft=t.useCallback(e=>{Fe(e);try{localStorage.setItem(Ae,JSON.stringify(e))}catch{}},[]),O=t.useRef(!1),T=t.useRef(null),[Oe,$]=t.useState(!1);t.useEffect(()=>{const e=()=>{O.current=!1,T.current=null,$(!1)};return document.addEventListener("mouseup",e),()=>document.removeEventListener("mouseup",e)},[]);const ht=t.useCallback((e,i)=>{const a=e.split(`
2
2
  `),r=Math.max(1,i.start),d=Math.min(a.length,i.end);return r>d?"":a.slice(r-1,d).join(`
3
- `)},[]),gt=Zt({source:"plan",fileLabel:de,language:p&&nt(p)||"markdown",getCodeForRange:e=>ht(h,qt(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})}),{drafts:Oe,commentText:ee,setCommentText:Ke,editingDraftId:pe,setSelection:We,saveComment:ze,cancel:U,reset:_e,startEdit:Be,deleteDraft:Ge}=gt;t.useEffect(()=>{y(null),_e()},[h,_e]),t.useEffect(()=>{We(u)},[u,We]);const Je=t.useCallback(()=>{y(null),U()},[U]),Ue=t.useCallback((e,i)=>{i&&y(i),ze(e,i??u??void 0),y(null)},[u,ze]);t.useEffect(()=>{if(!u)return;const e=a=>{const r=a.target;r.closest('[data-comment-card="true"]')||r.closest('[data-comment-input="true"]')||r.closest(".oc-block-widget")||r.closest(".cm-gutterElement")||r.closest("[data-sonner-toast]")||r.closest("[data-sonner-toaster]")||ee.trim()||(y(null),U())},i=window.setTimeout(()=>{document.addEventListener("click",e)},100);return()=>{window.clearTimeout(i),document.removeEventListener("click",e)}},[U,ee,pe,Te,u]);const fe=Ze(e=>e.editorFontSize),wt=t.useMemo(()=>{const e=p?nt(p):null,i=!!e&&e!=="markdown",a=[Ct(Y,i?{syntaxColors:!1,fontSize:fe}:{fontSize:fe})],r=Kt(p||"plan.md");return r&&a.push(r),i&&e&&a.push(Rt({language:e,themeName:Y.metadata.id,theme:en(Y)})),a.push(tn.lineWrapping),a},[Y,p,fe]),j=t.useRef({key:null,target:null,content:"",editRevision:0,savedRevision:0,runtimeKey:""}),C=t.useState(rn)[0],He=t.useCallback(async(e,i)=>{if("filePath"in e){const r=_.files??qe()?.files;if(r?.writeFile){if(!(await r.writeFile(e.filePath,i))?.success)throw new Error("Plan file write failed");return}const d=await Xe("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e.filePath,content:i})});if(!d.ok)throw new Error(`Failed to write plan file (${d.status})`);return}if(!await Wt.getState().savePlan(e.projectRef,e.planId,i))throw new Error("Plan save rejected: the plan no longer exists")},[_.files]),Ye=t.useRef(He);Ye.current=He;const F=t.useCallback(()=>{const e=j.current;if(!e.key||!e.target||e.editRevision<=e.savedRevision)return;const i={key:e.key,target:e.target,content:e.content,revision:e.editRevision,runtimeKey:e.runtimeKey,write:Ye.current};C.schedule(i.key,i.revision,async()=>{if(he()!==i.runtimeKey)return;await i.write(i.target,i.content);const a=j.current;a.key===i.key&&(a.savedRevision=Math.max(a.savedRevision,i.revision),ce(null))}).catch(a=>{j.current.key===i.key&&ce(a instanceof Error?a.message:"Plan save failed")})},[C]);t.useEffect(()=>{if(!xe&&!l&&!P){F(),j.current={key:null,target:null,content:"",editRevision:0,savedRevision:0,runtimeKey:""},M(null),ae(null),x(""),V(!1);return}let e=!1;const i=async r=>{if(_.files?.readFile)return(await _.files.readFile(r))?.content??"";const d=qe()?.files;if(d?.readFile)return(await d.readFile(r,{optional:!0}))?.content??"";const m=await Xe(`/api/fs/read?path=${encodeURIComponent(r)}&optional=true`,{cache:"no-store"});if(!m.ok)throw new Error(`Failed to read plan file (${m.status})`);return m.text()};return(async()=>{if(F(),j.current={key:null,target:null,content:"",editRevision:0,savedRevision:0,runtimeKey:""},M(null),ae(null),x(""),ce(null),ue(null),P&&v&&G){if(await C.pendingFor(G),e)return;C.reset(G),V(!0);try{const r=await Qt(v,P);if(e)return;if(!r){ue("Plan not found");return}j.current={key:G,target:{projectRef:v,planId:P},content:r.raw,editRevision:0,savedRevision:0,runtimeKey:I},x(r.raw),ae(P)}catch(r){if(e)return;ue(r instanceof Error?r.message:"Plan load failed")}finally{e||V(!1)}return}if(l){const r=JSON.stringify(["plan-file",I,l]);if(await C.pendingFor(r),e)return;C.reset(r),V(!0);try{const d=await i(l);if(e)return;j.current={key:r,target:{filePath:l},content:d,editRevision:0,savedRevision:0,runtimeKey:I},M(l),x(d)}catch{if(e)return;M(null),x("")}finally{e||V(!1)}return}if(!S?.slug||!S?.time?.created||!R){M(null),x("");return}V(!0);try{const r=sn(R,S.time.created,S.slug),d=an(on(S.time.created,S.slug),z||null);let m=null;try{await i(r),m=r}catch{}if(!m)try{await i(d),m=d}catch{}if(e)return;if(!m){M(null),x("");return}const w=JSON.stringify(["plan-file",I,m]);if(await C.pendingFor(w),e)return;const K=await i(m);if(e)return;C.reset(w),j.current={key:w,target:{filePath:m},content:K,editRevision:0,savedRevision:0,runtimeKey:I},M(m),x(K)}catch{if(e)return;M(null),x("")}finally{e||V(!1)}})(),()=>{e=!0}},[I,z,xe,_.files,P,G,v,C,F,S?.slug,S?.time?.created,R,l]);const vt=t.useCallback(e=>{j.current.content=e,j.current.editRevision+=1,x(e)},[]);t.useEffect(()=>{if(!p&&!oe)return;const e=window.setTimeout(()=>{F()},350);return()=>{window.clearTimeout(e)}},[h,oe,p,F]),t.useEffect(()=>()=>{F()},[F]),t.useEffect(()=>()=>{J.current!==null&&window.clearTimeout(J.current)},[]);const Qe=t.useCallback(()=>{Me(!1),o?.()},[o,Me]),St=t.useCallback(async e=>{const i=v??B;if(!i||!D||L)return;const a=await rt(D.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:q}),r=await rt(D.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:q,plan_path:p??""}),m=[{synthetic:!0,text:p?r:[r,"","The plan is not stored as a file in the repository and has no file path. Its full current contents follow below this note and are the source of truth for the plan. Where the instructions above refer to the plan file, treat the plan as stored in OpenChamber project knowledge (it is edited through the OpenChamber UI): propose plan revisions as plan text in the chat rather than editing a file.","",h].join(`
4
- `)}];Ee(!0);try{Qe();let w=null,K=i.path;if(D.target==="worktree"){if(!Q)return;const k=await zt(i.path,_t());if(!k?.id)return;w=k.id,K=k.path}else{const k=await N(void 0,i.path,null);if(!k?.id)return;w=k.id,K=k.directory??i.path,g(k.id,tt.getState().agents??[])}if(!w)return;const te=Bt.getState();te.saveSessionModelSelection(w,e.providerID,e.modelID),e.agent.trim()&&(te.saveSessionAgentSelection(w,e.agent),te.saveAgentModelForSession(w,e.agent,e.providerID,e.modelID),te.saveAgentModelVariantForSession(w,e.agent,e.providerID,e.modelID,e.variant||void 0)),ye(w,K);const bt=e.runAsGoal===!0?[`Implement the plan "${q}" end-to-end${p?` (plan file: ${p})`:" (the full plan follows)"}.`,p?"Re-read that file for full details — it is the source of truth.":"The full plan follows in this message and is the source of truth.","",h].join(`
5
- `):null;Gt.getState().setArmed(e.runAsGoal===!0,bt),await E(a,e.providerID,e.modelID,e.agent.trim()||void 0,void 0,void 0,m,e.variant||void 0),$(null)}finally{Ee(!1)}},[Q,h,N,B,g,L,D,p,Qe,v,E,q,ye]),yt=t.useMemo(()=>Xt({drafts:Oe,editingDraftId:pe,commentText:ee,onTextChange:Ke,selection:u,isDragging:Ae,fileLabel:de,newWidgetId:"plan-new-comment-input",mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:Ue,onCancel:Je,onEdit:e=>{Be(e),y({start:e.startLine,end:e.endLine})},onDelete:Ge}),[ee,Ge,pe,Je,Ue,Ae,u,Oe,de,Ke,Be]);return n.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"typography-ui-label font-medium truncate",children:me}),De?n.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:De,children:s("planView.error.loadFailed")}):null,Ie?n.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:Ie,children:s("planView.error.saveFailed")}):null]}),at?n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs(st,{children:[n.jsxs(ge,{children:[n.jsx(we,{asChild:!0,children:n.jsx(it,{asChild:!0,children:n.jsx(ne,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":s("planView.actions.improvePlanAria"),disabled:!h.trim()||L,children:n.jsx(W,{name:"loop-right-ai",className:"size-4"})})})}),n.jsx(ve,{sideOffset:8,children:s("planView.actions.improve")})]}),n.jsxs(ot,{align:"end",children:[n.jsx(re,{onClick:()=>$({action:"improve",target:"session"}),disabled:L,children:s("planView.actions.sendToNewSession")}),n.jsx(re,{onClick:()=>$({action:"improve",target:"worktree"}),disabled:!Q,children:s("planView.actions.sendToNewWorktreeSession")})]})]}),n.jsxs(st,{children:[n.jsxs(ge,{children:[n.jsx(we,{asChild:!0,children:n.jsx(it,{asChild:!0,children:n.jsx(ne,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":s("planView.actions.implementPlanAria"),disabled:!h.trim()||L,children:n.jsx(W,{name:"code-ai",className:"size-4"})})})}),n.jsx(ve,{sideOffset:8,children:s("planView.actions.implement")})]}),n.jsxs(ot,{align:"end",children:[n.jsx(re,{onClick:()=>$({action:"implement",target:"session"}),disabled:L,children:s("planView.actions.sendToNewSession")}),n.jsx(re,{onClick:()=>$({action:"implement",target:"worktree"}),disabled:!Q,children:s("planView.actions.sendToNewWorktreeSession")})]})]}),n.jsx(Pt,{currentMode:X,onToggle:()=>ft(X==="preview"?"edit":"preview")}),X==="preview"&&ut&&n.jsxs(ge,{children:[n.jsx(we,{asChild:!0,children:n.jsx(ne,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":s(Z?"planView.tts.stopSpeaking":"planView.tts.readAloud"),onClick:()=>{Z?ct():h.trim()&&lt(h)},children:Z?n.jsx(W,{name:"stop",className:"h-4 w-4 text-[color:var(--status-success)]"}):n.jsx(W,{name:"volume-up",className:"h-4 w-4"})})}),n.jsx(ve,{sideOffset:8,children:s(Z?"planView.tts.stopSpeaking":"planView.tts.readAloud")})]}),n.jsx(ne,{variant:"ghost",size:"sm",onClick:async()=>{(await Jt(h)).ok&&(Ve(!0),J.current!==null&&window.clearTimeout(J.current),J.current=window.setTimeout(()=>{Ve(!1)},1200))},className:"h-5 w-5 p-0",title:s("planView.actions.copyPlanContents"),"aria-label":s("planView.actions.copyPlanContents"),children:mt?n.jsx(W,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):n.jsx(W,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),n.jsx(nn,{open:D!==null,onOpenChange:e=>{!e&&!Ne&&$(null)},target:D?.target??"session",projectDirectory:v?.path??B?.path??null,submitting:Ne,allowRunAsGoal:!0,onConfirm:St}),n.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:n.jsx(Ut,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:dt?n.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:s("planView.state.loading")}):n.jsx("div",{className:"relative h-full",children:n.jsx("div",{className:"h-full",children:X==="preview"?n.jsx("div",{className:"h-full overflow-auto p-3",children:n.jsx(Ht,{fallback:n.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[n.jsx("div",{className:"mb-1 font-medium text-destructive",children:s("planView.error.previewUnavailable")}),n.jsx("div",{className:"text-sm text-muted-foreground",children:s("planView.error.switchToEditMode")})]}),children:n.jsx(Yt,{content:h,className:"typography-markdown-body",enableFileReferences:!1})})}):n.jsx("div",{className:"relative h-full",ref:pt,children:n.jsx(Mt,{value:h,onChange:vt,readOnly:!1,className:"h-full",extensions:wt,onViewReady:e=>{Le.current=e},onViewDestroy:()=>{Le.current=null},blockWidgets:yt,highlightLines:u?{start:Math.min(u.start,u.end),end:Math.max(u.start,u.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(e,i,a)=>{if(!(a instanceof MouseEvent)||a.button!==0)return!1;a.preventDefault();const r=e.state.doc.lineAt(i.from).number;if(u&&!a.shiftKey&&Math.min(u.start,u.end)===r&&Math.max(u.start,u.end)===r)return y(null),U(),A.current=!1,T.current=null,O(!1),!0;if(Te&&u&&!a.shiftKey){const d=Math.min(u.start,u.end,r),m=Math.max(u.start,u.end,r);return y({start:d,end:m}),A.current=!1,T.current=null,O(!1),!0}if(A.current=!0,T.current=r,O(!0),u&&a.shiftKey){const d=Math.min(u.start,r),m=Math.max(u.end,r);y({start:d,end:m})}else y({start:r,end:r});return!0},mouseover:(e,i,a)=>{if(!(a instanceof MouseEvent)||a.buttons!==1||!A.current||T.current===null)return!1;const r=e.state.doc.lineAt(i.from).number,d=Math.min(T.current,r),m=Math.max(T.current,r);return y({start:d,end:m}),O(!0),!1},mouseup:()=>(A.current=!1,T.current=null,O(!1),!1)}}})})})})})})]})};export{cs as PlanView};
3
+ `)},[]),gt=Zt({source:"plan",fileLabel:de,language:p&&nt(p)||"markdown",getCodeForRange:e=>ht(h,qt(e)),toStoreRange:e=>({startLine:e.start,endLine:e.end}),fromDraftRange:e=>({start:e.startLine,end:e.endLine})}),{drafts:$e,commentText:ee,setCommentText:Ke,editingDraftId:pe,setSelection:We,saveComment:ze,cancel:U,reset:_e,startEdit:Be,deleteDraft:Ge}=gt;t.useEffect(()=>{y(null),_e()},[h,_e]),t.useEffect(()=>{We(u)},[u,We]);const Je=t.useCallback(()=>{y(null),U()},[U]),Ue=t.useCallback((e,i)=>{i&&y(i),ze(e,i??u??void 0),y(null)},[u,ze]);t.useEffect(()=>{if(!u)return;const e=a=>{const r=a.target;r.closest('[data-comment-card="true"]')||r.closest('[data-comment-input="true"]')||r.closest(".oc-block-widget")||r.closest(".cm-gutterElement")||r.closest("[data-sonner-toast]")||r.closest("[data-sonner-toaster]")||ee.trim()||(y(null),U())},i=window.setTimeout(()=>{document.addEventListener("click",e)},100);return()=>{window.clearTimeout(i),document.removeEventListener("click",e)}},[U,ee,pe,Te,u]);const fe=Ze(e=>e.editorFontSize),wt=t.useMemo(()=>{const e=p?nt(p):null,i=!!e&&e!=="markdown",a=[Ct(Q,i?{syntaxColors:!1,fontSize:fe}:{fontSize:fe})],r=Kt(p||"plan.md");return r&&a.push(r),i&&e&&a.push(Rt({language:e,themeName:Q.metadata.id,theme:en(Q)})),a.push(tn.lineWrapping),a},[Q,p,fe]),j=t.useRef({key:null,target:null,content:"",editRevision:0,savedRevision:0,runtimeKey:""}),C=t.useState(rn)[0],He=t.useCallback(async(e,i)=>{if("filePath"in e){const r=_.files??qe()?.files;if(r?.writeFile){if(!(await r.writeFile(e.filePath,i))?.success)throw new Error("Plan file write failed");return}const d=await Xe("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e.filePath,content:i})});if(!d.ok)throw new Error(`Failed to write plan file (${d.status})`);return}if(!await Wt.getState().savePlan(e.projectRef,e.planId,i))throw new Error("Plan save rejected: the plan no longer exists")},[_.files]),Qe=t.useRef(He);Qe.current=He;const F=t.useCallback(()=>{const e=j.current;if(!e.key||!e.target||e.editRevision<=e.savedRevision)return;const i={key:e.key,target:e.target,content:e.content,revision:e.editRevision,runtimeKey:e.runtimeKey,write:Qe.current};C.schedule(i.key,i.revision,async()=>{if(he()!==i.runtimeKey)return;await i.write(i.target,i.content);const a=j.current;a.key===i.key&&(a.savedRevision=Math.max(a.savedRevision,i.revision),ce(null))}).catch(a=>{j.current.key===i.key&&ce(a instanceof Error?a.message:"Plan save failed")})},[C]);t.useEffect(()=>{if(!xe&&!l&&!P){F(),j.current={key:null,target:null,content:"",editRevision:0,savedRevision:0,runtimeKey:""},M(null),ae(null),x(""),V(!1);return}let e=!1;const i=async r=>{if(_.files?.readFile)return(await _.files.readFile(r))?.content??"";const d=qe()?.files;if(d?.readFile)return(await d.readFile(r,{optional:!0}))?.content??"";const m=await Xe(`/api/fs/read?path=${encodeURIComponent(r)}&optional=true`,{cache:"no-store"});if(!m.ok)throw new Error(`Failed to read plan file (${m.status})`);return m.text()};return(async()=>{if(F(),j.current={key:null,target:null,content:"",editRevision:0,savedRevision:0,runtimeKey:""},M(null),ae(null),x(""),ce(null),ue(null),P&&v&&G){if(await C.pendingFor(G),e)return;C.reset(G),V(!0);try{const r=await Yt(v,P);if(e)return;if(!r){ue("Plan not found");return}j.current={key:G,target:{projectRef:v,planId:P},content:r.raw,editRevision:0,savedRevision:0,runtimeKey:I},x(r.raw),ae(P)}catch(r){if(e)return;ue(r instanceof Error?r.message:"Plan load failed")}finally{e||V(!1)}return}if(l){const r=JSON.stringify(["plan-file",I,l]);if(await C.pendingFor(r),e)return;C.reset(r),V(!0);try{const d=await i(l);if(e)return;j.current={key:r,target:{filePath:l},content:d,editRevision:0,savedRevision:0,runtimeKey:I},M(l),x(d)}catch{if(e)return;M(null),x("")}finally{e||V(!1)}return}if(!S?.slug||!S?.time?.created||!R){M(null),x("");return}V(!0);try{const r=sn(R,S.time.created,S.slug),d=an(on(S.time.created,S.slug),z||null);let m=null;try{await i(r),m=r}catch{}if(!m)try{await i(d),m=d}catch{}if(e)return;if(!m){M(null),x("");return}const w=JSON.stringify(["plan-file",I,m]);if(await C.pendingFor(w),e)return;const K=await i(m);if(e)return;C.reset(w),j.current={key:w,target:{filePath:m},content:K,editRevision:0,savedRevision:0,runtimeKey:I},M(m),x(K)}catch{if(e)return;M(null),x("")}finally{e||V(!1)}})(),()=>{e=!0}},[I,z,xe,_.files,P,G,v,C,F,S?.slug,S?.time?.created,R,l]);const vt=t.useCallback(e=>{j.current.content=e,j.current.editRevision+=1,x(e)},[]);t.useEffect(()=>{if(!p&&!oe)return;const e=window.setTimeout(()=>{F()},350);return()=>{window.clearTimeout(e)}},[h,oe,p,F]),t.useEffect(()=>()=>{F()},[F]),t.useEffect(()=>()=>{J.current!==null&&window.clearTimeout(J.current)},[]);const Ye=t.useCallback(()=>{Me(!1),o?.()},[o,Me]),St=t.useCallback(async e=>{const i=v??B;if(!i||!D||L)return;const a=await rt(D.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:q}),r=await rt(D.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:q,plan_path:p??""}),m=[{synthetic:!0,text:p?r:[r,"","The plan is not stored as a file in the repository and has no file path. Its full current contents follow below this note and are the source of truth for the plan. Where the instructions above refer to the plan file, treat the plan as stored in OpenChamber project knowledge (it is edited through the OpenChamber UI): propose plan revisions as plan text in the chat rather than editing a file.","",h].join(`
4
+ `)}];Ee(!0);try{Ye();let w=null,K=i.path;if(D.target==="worktree"){if(!Y)return;const k=await zt(i.path,_t());if(!k?.id)return;w=k.id,K=k.path}else{const k=await N(void 0,i.path,null);if(!k?.id)return;w=k.id,K=k.directory??i.path,g(k.id,tt.getState().agents??[])}if(!w)return;const te=Bt.getState();te.saveSessionModelSelection(w,e.providerID,e.modelID),e.agent.trim()&&(te.saveSessionAgentSelection(w,e.agent),te.saveAgentModelForSession(w,e.agent,e.providerID,e.modelID),te.saveAgentModelVariantForSession(w,e.agent,e.providerID,e.modelID,e.variant||void 0)),ye(w,K);const bt=e.runAsGoal===!0?[`Implement the plan "${q}" end-to-end${p?` (plan file: ${p})`:" (the full plan follows)"}.`,p?"Re-read that file for full details — it is the source of truth.":"The full plan follows in this message and is the source of truth.","",h].join(`
5
+ `):null;Gt.getState().setArmed(e.runAsGoal===!0,bt),await E(a,e.providerID,e.modelID,e.agent.trim()||void 0,void 0,void 0,m,e.variant||void 0),A(null)}finally{Ee(!1)}},[Y,h,N,B,g,L,D,p,Ye,v,E,q,ye]),yt=t.useMemo(()=>Xt({drafts:$e,editingDraftId:pe,commentText:ee,onTextChange:Ke,selection:u,isDragging:Oe,fileLabel:de,newWidgetId:"plan-new-comment-input",mapDraftToRange:e=>({start:e.startLine,end:e.endLine}),onSave:Ue,onCancel:Je,onEdit:e=>{Be(e),y({start:e.startLine,end:e.endLine})},onDelete:Ge}),[ee,Ge,pe,Je,Ue,Oe,u,$e,de,Ke,Be]);return n.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"typography-ui-label font-medium truncate",children:me}),De?n.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:De,children:s("planView.error.loadFailed")}):null,Ie?n.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:Ie,children:s("planView.error.saveFailed")}):null]}),at?n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs(st,{children:[n.jsxs(ge,{children:[n.jsx(we,{asChild:!0,children:n.jsx(it,{asChild:!0,children:n.jsx(ne,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":s("planView.actions.improvePlanAria"),disabled:!h.trim()||L,children:n.jsx(W,{name:"loop-right-ai",className:"size-4"})})})}),n.jsx(ve,{sideOffset:8,children:s("planView.actions.improve")})]}),n.jsxs(ot,{align:"end",children:[n.jsx(re,{onClick:()=>A({action:"improve",target:"session"}),disabled:L,children:s("planView.actions.sendToNewSession")}),n.jsx(re,{onClick:()=>A({action:"improve",target:"worktree"}),disabled:!Y,children:s("planView.actions.sendToNewWorktreeSession")})]})]}),n.jsxs(st,{children:[n.jsxs(ge,{children:[n.jsx(we,{asChild:!0,children:n.jsx(it,{asChild:!0,children:n.jsx(ne,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":s("planView.actions.implementPlanAria"),disabled:!h.trim()||L,children:n.jsx(W,{name:"code-ai",className:"size-4"})})})}),n.jsx(ve,{sideOffset:8,children:s("planView.actions.implement")})]}),n.jsxs(ot,{align:"end",children:[n.jsx(re,{onClick:()=>A({action:"implement",target:"session"}),disabled:L,children:s("planView.actions.sendToNewSession")}),n.jsx(re,{onClick:()=>A({action:"implement",target:"worktree"}),disabled:!Y,children:s("planView.actions.sendToNewWorktreeSession")})]})]}),n.jsx(Pt,{currentMode:X,onToggle:()=>ft(X==="preview"?"edit":"preview")}),X==="preview"&&ut&&n.jsxs(ge,{children:[n.jsx(we,{asChild:!0,children:n.jsx(ne,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":s(Z?"planView.tts.stopSpeaking":"planView.tts.readAloud"),onClick:()=>{Z?ct():h.trim()&&lt(h)},children:Z?n.jsx(W,{name:"stop",className:"h-4 w-4 text-[color:var(--status-success)]"}):n.jsx(W,{name:"volume-up",className:"h-4 w-4"})})}),n.jsx(ve,{sideOffset:8,children:s(Z?"planView.tts.stopSpeaking":"planView.tts.readAloud")})]}),n.jsx(ne,{variant:"ghost",size:"sm",onClick:async()=>{(await Jt(h)).ok&&(Ve(!0),J.current!==null&&window.clearTimeout(J.current),J.current=window.setTimeout(()=>{Ve(!1)},1200))},className:"h-5 w-5 p-0",title:s("planView.actions.copyPlanContents"),"aria-label":s("planView.actions.copyPlanContents"),children:mt?n.jsx(W,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):n.jsx(W,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),n.jsx(nn,{open:D!==null,onOpenChange:e=>{!e&&!Ne&&A(null)},target:D?.target??"session",projectDirectory:v?.path??B?.path??null,submitting:Ne,allowRunAsGoal:!0,onConfirm:St}),n.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:n.jsx(Ut,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:dt?n.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:s("planView.state.loading")}):n.jsx("div",{className:"relative h-full",children:n.jsx("div",{className:"h-full",children:X==="preview"?n.jsx("div",{className:"h-full overflow-auto p-3",children:n.jsx(Ht,{fallback:n.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[n.jsx("div",{className:"mb-1 font-medium text-destructive",children:s("planView.error.previewUnavailable")}),n.jsx("div",{className:"text-sm text-muted-foreground",children:s("planView.error.switchToEditMode")})]}),children:n.jsx(Qt,{content:h,className:"typography-markdown-body",enableFileReferences:!1})})}):n.jsx("div",{className:"relative h-full",ref:pt,children:n.jsx(Mt,{value:h,onChange:vt,readOnly:!1,className:"h-full",extensions:wt,onViewReady:e=>{Le.current=e},onViewDestroy:()=>{Le.current=null},blockWidgets:yt,highlightLines:u?{start:Math.min(u.start,u.end),end:Math.max(u.start,u.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(e,i,a)=>{if(!(a instanceof MouseEvent)||a.button!==0)return!1;a.preventDefault();const r=e.state.doc.lineAt(i.from).number;if(u&&!a.shiftKey&&Math.min(u.start,u.end)===r&&Math.max(u.start,u.end)===r)return y(null),U(),O.current=!1,T.current=null,$(!1),!0;if(Te&&u&&!a.shiftKey){const d=Math.min(u.start,u.end,r),m=Math.max(u.start,u.end,r);return y({start:d,end:m}),O.current=!1,T.current=null,$(!1),!0}if(O.current=!0,T.current=r,$(!0),u&&a.shiftKey){const d=Math.min(u.start,r),m=Math.max(u.end,r);y({start:d,end:m})}else y({start:r,end:r});return!0},mouseover:(e,i,a)=>{if(!(a instanceof MouseEvent)||a.buttons!==1||!O.current||T.current===null)return!1;const r=e.state.doc.lineAt(i.from).number,d=Math.min(T.current,r),m=Math.max(T.current,r);return y({start:d,end:m}),$(!0),!1},mouseup:()=>(O.current=!1,T.current=null,$(!1),!1)}}})})})})})})]})};export{cs as PlanView};