@pi-chamber/web 1.0.5-rc.3 → 1.0.5

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 (52) hide show
  1. package/dist/assets/{DiagramView-DxLAcmg-.js → DiagramView-CrKjR8CR.js} +1 -1
  2. package/dist/assets/{DiffView-BzVBoNCp.js → DiffView-CSonR3pr.js} +1 -1
  3. package/dist/assets/{FileSaveConflictDialog-2KqGdUdB.js → FileSaveConflictDialog-Cun0LIbj.js} +1 -1
  4. package/dist/assets/{FilesView-3spQTRpf.js → FilesView-BRR3N7UA.js} +1 -1
  5. package/dist/assets/{GitHubDetailScaffold-C2d4WqKe.js → GitHubDetailScaffold-C1UHuETI.js} +1 -1
  6. package/dist/assets/{GitHubLinkPicker-BDwZtk0x.js → GitHubLinkPicker-B0O3Vapu.js} +1 -1
  7. package/dist/assets/{GitHubListPrimitives-Dor_K85Y.js → GitHubListPrimitives-DvQDU--z.js} +1 -1
  8. package/dist/assets/{GitView-CSAJagWK.js → GitView-wAscrRhO.js} +3 -3
  9. package/dist/assets/{IssuesSurface-euZzv2L9.js → IssuesSurface-mh50UUQ8.js} +2 -2
  10. package/dist/assets/{JsonTreeView-Drmn7tIN.js → JsonTreeView-BfErTllU.js} +1 -1
  11. package/dist/assets/{MarkdownRendererImpl-Bq0p5v9N.js → MarkdownRendererImpl-SXAK4uOu.js} +1 -1
  12. package/dist/assets/{PatchDiff-BegAimf3.js → PatchDiff-CHr79sJ6.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-DgU2Zcmr.js → PierreDiffViewer-CGpKcLro.js} +1 -1
  14. package/dist/assets/{PullRequestsSurface-CnGgmkuf.js → PullRequestsSurface-CfaOpeZn.js} +2 -2
  15. package/dist/assets/{SessionSwitcherContent-Cq5LIBuG.js → SessionSwitcherContent-DEAw6v12.js} +1 -1
  16. package/dist/assets/{SessionSwitcherDropdown-Dpob2_y5.js → SessionSwitcherDropdown-BSutduo7.js} +2 -2
  17. package/dist/assets/{SessionUnreadDot-BPKnpGAh.js → SessionUnreadDot-Dav_rix1.js} +1 -1
  18. package/dist/assets/{SettingsView-DcOJRyym.js → SettingsView-CQJkOPJh.js} +4 -4
  19. package/dist/assets/{SettingsWindow-C2RB0AjV.js → SettingsWindow-BiY5FmhZ.js} +1 -1
  20. package/dist/assets/{ToolOutputDialog-DmzNX2QX.js → ToolOutputDialog-B3RRLhR3.js} +1 -1
  21. package/dist/assets/{ToolPartDiffPreview-CO5Gg17_.js → ToolPartDiffPreview-D9m_vrht.js} +1 -1
  22. package/dist/assets/{VirtualizedFileDiff-CJ1m8JE-.js → VirtualizedFileDiff-B8lhZGLu.js} +1 -1
  23. package/dist/assets/{collapsible-BOcd0lzY.js → collapsible-9MJx4VhA.js} +1 -1
  24. package/dist/assets/{computeVirtualFileMetrics-8mC_o5zA.js → computeVirtualFileMetrics-Bjhk2CQS.js} +1 -1
  25. package/dist/assets/{contextFileOpenGuard-CRboGmXF.js → contextFileOpenGuard-CsF5Boky.js} +1 -1
  26. package/dist/assets/{gitStatusPredicates-BqV-kOGY.js → gitStatusPredicates-B3Zxud6E.js} +1 -1
  27. package/dist/assets/{githubLink-DSgdECMr.js → githubLink-CbGYxsIq.js} +1 -1
  28. package/dist/assets/{index-B3qmI8VW.js → index-B0h6_x5N.js} +1 -1
  29. package/dist/assets/{index-DsQIBAWK.css → index-BwoW_-vk.css} +1 -1
  30. package/dist/assets/{index-DWSrsQWl.js → index-D4n3TVp2.js} +2 -2
  31. package/dist/assets/{main-Bn93XwxQ.js → main-C6i4ph9N.js} +2 -2
  32. package/dist/assets/{main-HPNu-7DG.js → main-r5elIPBi.js} +4 -4
  33. package/dist/assets/{markdownCore-Csm6UEBe.js → markdownCore-C2YQ3Z0q.js} +1 -1
  34. package/dist/assets/{miniChat-C3W5IvM4.js → miniChat-d_GCHoIf.js} +2 -2
  35. package/dist/assets/{mobile-COEEitAQ.js → mobile-BJ3tgyKd.js} +2 -2
  36. package/dist/assets/{nativeFileSave-CFuugNKV.js → nativeFileSave-BJsGPh58.js} +1 -1
  37. package/dist/assets/{pi-session-focus-preference-DQjF7Nh1.js → pi-session-focus-preference-BFnGFuvP.js} +1 -1
  38. package/dist/assets/{renderDiffWithHighlighter-BBwvKSDe.js → renderDiffWithHighlighter-BhMEWmHn.js} +1 -1
  39. package/dist/assets/{renderElectronMiniChatApp-7vIiCPiK.js → renderElectronMiniChatApp-Bap5OwgB.js} +2 -2
  40. package/dist/assets/{renderFileWithHighlighter-VOwWxIE1.js → renderFileWithHighlighter-DUGluXlw.js} +1 -1
  41. package/dist/assets/{renderMobileApp-BQDG02OP.js → renderMobileApp-DJbslvby.js} +3 -3
  42. package/dist/assets/{runtimeEndpointReset-CzwDZ_EP.js → runtimeEndpointReset-D22U_Vjs.js} +6 -6
  43. package/dist/assets/{runtimeSurface-Der4qUnI.js → runtimeSurface-k1Eit61v.js} +1 -1
  44. package/dist/assets/{useAppFontEffects-BQ1JUauS.js → useAppFontEffects-CqHhRKmN.js} +77 -77
  45. package/dist/assets/{useFilesViewSearch-BYG2TZWz.js → useFilesViewSearch-CqoYEK0U.js} +1 -1
  46. package/dist/assets/{useGitHubRemoteSearch-Bo1LF-x_.js → useGitHubRemoteSearch-DYoLQ4ro.js} +1 -1
  47. package/dist/assets/{useSwitcherItems-q0ZavMJb.js → useSwitcherItems-BS6E199F.js} +1 -1
  48. package/dist/assets/{web-components-CJ0xIy7r.js → web-components-DzQ9ybbb.js} +1 -1
  49. package/dist/index.html +4 -4
  50. package/dist/mini-chat.html +3 -3
  51. package/dist/mobile.html +3 -3
  52. package/package.json +1 -1
@@ -1 +1 @@
1
- import{r as l}from"./vendor-boot-EC6IyLt1.js";import{b as a}from"./index-DWSrsQWl.js";import"./vendor-react-DASdDPIk.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CUi8eEds.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";const c=l("PiChamberFiles");function f(t){return t instanceof Error&&(t.name==="AbortError"||t.message.includes("AbortError")||t.message.toLowerCase().includes("cancel"))}const s=async t=>{const e=new Uint8Array(await t.arrayBuffer()),n=32768;let r="";for(let o=0;o<e.length;o+=n)r+=String.fromCharCode(...e.subarray(o,o+n));return btoa(r)},u=async(t,e)=>{if(typeof t=="string"){if(t.startsWith("data:")){const r=t.indexOf(",");if(r!==-1&&t.slice(0,r).includes(";base64"))return t.slice(r+1)}const n=new Blob([t],{type:e??"text/plain;charset=utf-8"});return s(n)}return s(t)},p=async(t,e,n)=>{if(t instanceof File)return t;if(t instanceof Blob)return new File([t],e,{type:n||t.type||"application/octet-stream"});if(typeof t=="string"&&t.startsWith("data:")){const r=await(await fetch(t)).blob();return new File([r],e,{type:n||r.type||"application/octet-stream"})}return new File([t],e,{type:n??"text/plain;charset=utf-8"})},b=(t,e,n)=>{if(typeof document>"u")return;const r=typeof e=="string"&&e.startsWith("data:"),o=r?e:URL.createObjectURL(e instanceof Blob?e:new Blob([e],{type:n||"application/octet-stream"})),i=document.createElement("a");i.href=o,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),r||URL.revokeObjectURL(o)};async function C({filename:t,mimeType:e,data:n}){const r=a();if(r==="android"){const o=await u(n,e);return await c.share({filename:t,mimeType:e,base64:o}),"shared"}if(r==="ios"&&typeof navigator<"u"&&typeof navigator.share=="function"){const o=await p(n,t,e);if(typeof navigator.canShare=="function"&&navigator.canShare({files:[o]}))try{return await navigator.share({files:[o]}),"shared"}catch(i){if(f(i))return"cancelled";throw i}}return b(t,n,e),"downloaded"}async function F(t){if(a()==="android")try{await c.setWebViewBackground({color:t})}catch{}}export{f as isShareCancelledError,C as saveOrShareFile,F as setNativeWebViewBackground};
1
+ import{r as l}from"./vendor-boot-EC6IyLt1.js";import{b as a}from"./index-D4n3TVp2.js";import"./vendor-react-DASdDPIk.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CUi8eEds.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";const c=l("PiChamberFiles");function f(t){return t instanceof Error&&(t.name==="AbortError"||t.message.includes("AbortError")||t.message.toLowerCase().includes("cancel"))}const s=async t=>{const e=new Uint8Array(await t.arrayBuffer()),n=32768;let r="";for(let o=0;o<e.length;o+=n)r+=String.fromCharCode(...e.subarray(o,o+n));return btoa(r)},u=async(t,e)=>{if(typeof t=="string"){if(t.startsWith("data:")){const r=t.indexOf(",");if(r!==-1&&t.slice(0,r).includes(";base64"))return t.slice(r+1)}const n=new Blob([t],{type:e??"text/plain;charset=utf-8"});return s(n)}return s(t)},p=async(t,e,n)=>{if(t instanceof File)return t;if(t instanceof Blob)return new File([t],e,{type:n||t.type||"application/octet-stream"});if(typeof t=="string"&&t.startsWith("data:")){const r=await(await fetch(t)).blob();return new File([r],e,{type:n||r.type||"application/octet-stream"})}return new File([t],e,{type:n??"text/plain;charset=utf-8"})},b=(t,e,n)=>{if(typeof document>"u")return;const r=typeof e=="string"&&e.startsWith("data:"),o=r?e:URL.createObjectURL(e instanceof Blob?e:new Blob([e],{type:n||"application/octet-stream"})),i=document.createElement("a");i.href=o,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),r||URL.revokeObjectURL(o)};async function C({filename:t,mimeType:e,data:n}){const r=a();if(r==="android"){const o=await u(n,e);return await c.share({filename:t,mimeType:e,base64:o}),"shared"}if(r==="ios"&&typeof navigator<"u"&&typeof navigator.share=="function"){const o=await p(n,t,e);if(typeof navigator.canShare=="function"&&navigator.canShare({files:[o]}))try{return await navigator.share({files:[o]}),"shared"}catch(i){if(f(i))return"cancelled";throw i}}return b(t,n,e),"downloaded"}async function F(t){if(a()==="android")try{await c.setWebViewBackground({color:t})}catch{}}export{f as isShareCancelledError,C as saveOrShareFile,F as setNativeWebViewBackground};
@@ -1,4 +1,4 @@
1
- import{h as R,c9 as D,ca as O,g as C,ao as U,cb as j,bU as H,cc as Y,cd as W,a as z,ce as K,cf as b,cg as J,ch as V}from"./useAppFontEffects-BQ1JUauS.js";import{az as q,u as A,aA as Z,a as Q,t as B,aB as X,v as ee,aC as se,p as k}from"./index-DWSrsQWl.js";const te=[];function L(){return[...te].reverse()}const oe={getLastAssistantMessage(){if(!R.getState().currentSessionId)return console.log("[ERROR] No active session"),null;const s=b();if(!s||s.length===0)return console.log("[ERROR] No messages in current session"),null;for(let t=s.length-1;t>=0;t--){const n=s[t];if(n.role==="assistant"){const c=(D(n.id)||[]).map(i=>{const u={id:i.id,type:i.type};return i.type==="text"?(u.text=i.text,u.textLength=i.text?.length||0):i.type==="tool"?(u.tool=i.tool,u.state=i.state?.status):(i.type==="step-start"||i.type==="step-finish")&&(u.isStepMarker=!0),u}),m=c.some(i=>i.type==="text"&&i.text&&i.text.trim().length>0),a=c.some(i=>i.type==="tool"),g=c.some(i=>i.type==="step-start"||i.type==="step-finish"),p=c.length===0,S=!m&&!a&&(!p||g),r={messageId:n.id,role:n.role,timestamp:n.time?.created||0,partsCount:c.length,parts:c,isEmpty:p,isEmptyResponse:S,raw:n};return console.log("[INSPECT] Last Assistant Message:",r),console.log("[SUMMARY] Summary:",{messageId:r.messageId,partsCount:r.partsCount,isEmpty:r.isEmpty,isEmptyResponse:r.isEmptyResponse,hasText:m,hasTools:a,hasStepMarkers:g,onlyStepMarkers:g&&!m&&!a}),r.isEmpty&&console.warn("[WARNING] Message has NO parts!"),r.isEmptyResponse&&(console.warn("[WARNING] Message has parts but NO meaningful content (empty text, no tools)!"),g&&!m&&!a&&(console.warn("[CRITICAL] CLAUDE EMPTY RESPONSE BUG: Only step-start/step-finish markers, no actual content!"),console.log("This is a known issue with Claude models (anthropic provider)"),console.log("Recommendation: Send a follow-up message or try a different model"))),r}}return console.log("[ERROR] No assistant messages found in current session"),null},truncateString(e,o=80){return!e||typeof e!="string"||e.length<=o?e:e.substring(0,o)+"…"},truncateMessages(e){return e.map(o=>({...o,parts:(D(o.id)||[]).map(s=>{const t={...s};return"text"in s&&(t.text=this.truncateString(s.text)),"textPreview"in s&&(t.textPreview=this.truncateString(s.textPreview)),s.state&&(t.state={...s.state},"output"in s.state&&(t.state.output=this.truncateString(s.state.output)),"error"in s.state&&(t.state.error=this.truncateString(s.state.error)),s.state.metadata&&"preview"in s.state.metadata&&(t.state.metadata={...s.state.metadata,preview:this.truncateString(s.state.metadata.preview)})),t})}))},getAllMessages(e=!1){if(!R.getState().currentSessionId)return console.log("[ERROR] No active session"),[];const t=b();return console.log(`[MESSAGES] Total messages in session: ${t.length}`),t.forEach((n,d)=>{const c=D(n.id)||[];console.log(`[${d}] ${n.role} - ${n.id} - ${c.length} parts`)}),e?this.truncateMessages(t):t},async getAppStatus(){const e=A.getState(),o=R.getState(),s=z.getState(),t=e.currentDirectory||null,n=C().getState(),d=n.directory??null,c=K(),m=new Set,a={};c.forEach(l=>{const y=l.directory;typeof y=="string"&&y.trim().length>0?(m.add(y),a[y]=(a[y]??0)+1):a["(none)"]=(a["(none)"]??0)+1});const g=(()=>{if(typeof window>"u")return{available:!1};try{return{available:!0,lastDirectory:window.localStorage.getItem("lastDirectory"),homeDirectory:window.localStorage.getItem("homeDirectory")}}catch(l){return{available:!1,error:l instanceof Error?l.message:String(l)}}})(),p=B(),S=typeof window<"u"&&!!window.__PICHAMBER_ELECTRON__,r=async l=>{try{return await l.json()}catch{return null}},u=await(async l=>{try{const y=await ee(l);return y.ok?await r(y):{status:y.status}}catch(y){return{error:y instanceof Error?y.message:String(y)}}})("/api/pi/ui-settings");let I=null;try{I=await Z.health({runtimeKey:Q()})}catch(l){I={error:l instanceof Error?l.message:String(l)}}let w={isGitRepo:null};if(t)try{const l=B()?.git.checkIsGitRepository??X;w.isGitRepo=await l(t)}catch(l){w={isGitRepo:null,error:l instanceof Error?l.message:String(l)}}const E=s.projects.map(l=>({id:l.id,path:l.path,label:l.label})),h={runtime:{platform:p?.runtime?.platform??null,isDesktop:S,hasRuntimeApis:!!p,desktopServerOrigin:null},location:typeof window<"u"?{href:window.location?.href??null,origin:window.location?.origin??null}:null,directories:{currentDirectory:t,piDirectory:d,homeDirectory:e.homeDirectory||null,isHomeReady:e.isHomeReady,hasPersistedDirectory:e.hasPersistedDirectory,isSwitchingDirectory:e.isSwitchingDirectory},projects:{total:s.projects.length,activeProjectId:s.activeProjectId,samples:E},sessions:{total:c.length,currentSessionId:o.currentSessionId,uniqueDirectories:m.size,directorySamples:Array.from(m).slice(0,5),directoryCounts:a},git:w,localStorage:g,pi:{health:I,connection:n.connection},pichamber:{settingsInfo:u},recentSendFailures:L(),currentSessionDirectoryResolution:o.currentSessionId?this.diagnoseSessionDirectory(o.currentSessionId):null};return console.log("[DEBUG] App status snapshot:",h),h},getRecentSendFailures(){const e=L();return e.length===0?console.log("[OK] No prompt sends were rejected in this session."):(console.warn(`[ALERT] ${e.length} rejected prompt send(s):`),console.table(e)),e},diagnoseSessionDirectory(e){const o=R.getState(),s=e??o.currentSessionId;if(!s)return console.log("[ERROR] No session selected and no session id passed"),null;const t=j(s),n=H().find(u=>u.id===s),d=n?.directory??null,c=s===o.currentSessionId?o.currentSessionDirectory:null,a=Y({session:n??null,currentDirectory:c}),g=o.getDirectoryForSession(s),p=W(s),S=[["owning child store",t],["session record",d],["current selection",c],["runtime memory",p.runtime],["persisted memory",p.persisted]],r=g?S.find(([,u])=>u&&u!==g):void 0,i={sessionId:s,isCurrentSession:s===o.currentSessionId,routedDirectory:g,resolvedFrom:a.source,conflict:r?{source:r[0],directory:r[1]}:null,sources:J(),details:{owningChildStore:t,sessionRecordDirectory:d,sessionIndexed:!!n,currentSessionDirectory:o.currentSessionDirectory,rememberedForRuntime:p.runtime,persistedAcrossRestarts:p.persisted,activeDirectory:A.getState().currentDirectory??null,piSessionDirectory:C().getState().directory??null}};return console.log("[DEBUG] Session directory resolution:",i),r?console.warn(`[ALERT] Directory sources disagree: routing to "${g}" while "${r[1]}" came from ${r[0]}.`):g?console.log("[OK] All known sources agree on the session directory."):console.warn("[ALERT] No directory resolved for this session — sends fall back to the active directory."),i},async buildDiagnosticsReport(){const e=await this.getAppStatus();return JSON.stringify(e,null,2)},async copyTextToClipboard(e){return U(e)},async copyDiagnosticsReport(){const e=await this.buildDiagnosticsReport();return{...await this.copyTextToClipboard(e),report:e}},checkLastMessage(){const e=this.getLastAssistantMessage();if(!e)return!1;const o=e.isEmpty||e.isEmptyResponse;return o?(console.error("[ALERT] PROBLEMATIC MESSAGE DETECTED!"),console.log("Details:",{messageId:e.messageId,isEmpty:e.isEmpty,isEmptyResponse:e.isEmptyResponse,partsCount:e.partsCount}),e.parts.length>0&&console.log("Parts:",e.parts)):console.log("[OK] Last message looks good!"),o},getStreamingState(){const e=R.getState(),o=C().getState().reducer.bySession,s=new Map;for(const[n,d]of o)s.set(n,O(d));const t=e.currentSessionId?s.get(e.currentSessionId)??null:null;return console.log("[STREAM] Streaming State:",{streamingMessageId:t,streamingMessageIds:Array.from(s.entries())}),{streamingMessageId:t,streamingMessageIds:s}},findEmptyMessages(){if(!R.getState().currentSessionId)return console.log("[ERROR] No active session"),[];const t=b().filter(n=>n.role==="assistant").filter(n=>{const d=D(n.id)||[],c=d.some(a=>a.type==="text"&&a.text&&a.text.trim().length>0),m=d.some(a=>a.type==="tool");return d.length===0||!c&&!m});return console.log(`[INSPECT] Found ${t.length} empty assistant messages`),t.forEach((n,d)=>{const c=D(n.id)||[];console.log(`[${d}] Empty message:`,{messageId:n.id,partsCount:c.length,provider:n.providerID,model:n.modelID,timestamp:n.time?.created})}),t},showRetryHelp(){console.log(`[DEBUG] How to handle empty Claude responses:
1
+ import{h as R,c9 as D,ca as O,g as C,ao as U,cb as j,bU as H,cc as Y,cd as W,a as z,ce as K,cf as b,cg as J,ch as V}from"./useAppFontEffects-CqHhRKmN.js";import{az as q,u as A,aA as Z,a as Q,t as B,aB as X,v as ee,aC as se,p as k}from"./index-D4n3TVp2.js";const te=[];function L(){return[...te].reverse()}const oe={getLastAssistantMessage(){if(!R.getState().currentSessionId)return console.log("[ERROR] No active session"),null;const s=b();if(!s||s.length===0)return console.log("[ERROR] No messages in current session"),null;for(let t=s.length-1;t>=0;t--){const n=s[t];if(n.role==="assistant"){const c=(D(n.id)||[]).map(i=>{const u={id:i.id,type:i.type};return i.type==="text"?(u.text=i.text,u.textLength=i.text?.length||0):i.type==="tool"?(u.tool=i.tool,u.state=i.state?.status):(i.type==="step-start"||i.type==="step-finish")&&(u.isStepMarker=!0),u}),m=c.some(i=>i.type==="text"&&i.text&&i.text.trim().length>0),a=c.some(i=>i.type==="tool"),g=c.some(i=>i.type==="step-start"||i.type==="step-finish"),p=c.length===0,S=!m&&!a&&(!p||g),r={messageId:n.id,role:n.role,timestamp:n.time?.created||0,partsCount:c.length,parts:c,isEmpty:p,isEmptyResponse:S,raw:n};return console.log("[INSPECT] Last Assistant Message:",r),console.log("[SUMMARY] Summary:",{messageId:r.messageId,partsCount:r.partsCount,isEmpty:r.isEmpty,isEmptyResponse:r.isEmptyResponse,hasText:m,hasTools:a,hasStepMarkers:g,onlyStepMarkers:g&&!m&&!a}),r.isEmpty&&console.warn("[WARNING] Message has NO parts!"),r.isEmptyResponse&&(console.warn("[WARNING] Message has parts but NO meaningful content (empty text, no tools)!"),g&&!m&&!a&&(console.warn("[CRITICAL] CLAUDE EMPTY RESPONSE BUG: Only step-start/step-finish markers, no actual content!"),console.log("This is a known issue with Claude models (anthropic provider)"),console.log("Recommendation: Send a follow-up message or try a different model"))),r}}return console.log("[ERROR] No assistant messages found in current session"),null},truncateString(e,o=80){return!e||typeof e!="string"||e.length<=o?e:e.substring(0,o)+"…"},truncateMessages(e){return e.map(o=>({...o,parts:(D(o.id)||[]).map(s=>{const t={...s};return"text"in s&&(t.text=this.truncateString(s.text)),"textPreview"in s&&(t.textPreview=this.truncateString(s.textPreview)),s.state&&(t.state={...s.state},"output"in s.state&&(t.state.output=this.truncateString(s.state.output)),"error"in s.state&&(t.state.error=this.truncateString(s.state.error)),s.state.metadata&&"preview"in s.state.metadata&&(t.state.metadata={...s.state.metadata,preview:this.truncateString(s.state.metadata.preview)})),t})}))},getAllMessages(e=!1){if(!R.getState().currentSessionId)return console.log("[ERROR] No active session"),[];const t=b();return console.log(`[MESSAGES] Total messages in session: ${t.length}`),t.forEach((n,d)=>{const c=D(n.id)||[];console.log(`[${d}] ${n.role} - ${n.id} - ${c.length} parts`)}),e?this.truncateMessages(t):t},async getAppStatus(){const e=A.getState(),o=R.getState(),s=z.getState(),t=e.currentDirectory||null,n=C().getState(),d=n.directory??null,c=K(),m=new Set,a={};c.forEach(l=>{const y=l.directory;typeof y=="string"&&y.trim().length>0?(m.add(y),a[y]=(a[y]??0)+1):a["(none)"]=(a["(none)"]??0)+1});const g=(()=>{if(typeof window>"u")return{available:!1};try{return{available:!0,lastDirectory:window.localStorage.getItem("lastDirectory"),homeDirectory:window.localStorage.getItem("homeDirectory")}}catch(l){return{available:!1,error:l instanceof Error?l.message:String(l)}}})(),p=B(),S=typeof window<"u"&&!!window.__PICHAMBER_ELECTRON__,r=async l=>{try{return await l.json()}catch{return null}},u=await(async l=>{try{const y=await ee(l);return y.ok?await r(y):{status:y.status}}catch(y){return{error:y instanceof Error?y.message:String(y)}}})("/api/pi/ui-settings");let I=null;try{I=await Z.health({runtimeKey:Q()})}catch(l){I={error:l instanceof Error?l.message:String(l)}}let w={isGitRepo:null};if(t)try{const l=B()?.git.checkIsGitRepository??X;w.isGitRepo=await l(t)}catch(l){w={isGitRepo:null,error:l instanceof Error?l.message:String(l)}}const E=s.projects.map(l=>({id:l.id,path:l.path,label:l.label})),h={runtime:{platform:p?.runtime?.platform??null,isDesktop:S,hasRuntimeApis:!!p,desktopServerOrigin:null},location:typeof window<"u"?{href:window.location?.href??null,origin:window.location?.origin??null}:null,directories:{currentDirectory:t,piDirectory:d,homeDirectory:e.homeDirectory||null,isHomeReady:e.isHomeReady,hasPersistedDirectory:e.hasPersistedDirectory,isSwitchingDirectory:e.isSwitchingDirectory},projects:{total:s.projects.length,activeProjectId:s.activeProjectId,samples:E},sessions:{total:c.length,currentSessionId:o.currentSessionId,uniqueDirectories:m.size,directorySamples:Array.from(m).slice(0,5),directoryCounts:a},git:w,localStorage:g,pi:{health:I,connection:n.connection},pichamber:{settingsInfo:u},recentSendFailures:L(),currentSessionDirectoryResolution:o.currentSessionId?this.diagnoseSessionDirectory(o.currentSessionId):null};return console.log("[DEBUG] App status snapshot:",h),h},getRecentSendFailures(){const e=L();return e.length===0?console.log("[OK] No prompt sends were rejected in this session."):(console.warn(`[ALERT] ${e.length} rejected prompt send(s):`),console.table(e)),e},diagnoseSessionDirectory(e){const o=R.getState(),s=e??o.currentSessionId;if(!s)return console.log("[ERROR] No session selected and no session id passed"),null;const t=j(s),n=H().find(u=>u.id===s),d=n?.directory??null,c=s===o.currentSessionId?o.currentSessionDirectory:null,a=Y({session:n??null,currentDirectory:c}),g=o.getDirectoryForSession(s),p=W(s),S=[["owning child store",t],["session record",d],["current selection",c],["runtime memory",p.runtime],["persisted memory",p.persisted]],r=g?S.find(([,u])=>u&&u!==g):void 0,i={sessionId:s,isCurrentSession:s===o.currentSessionId,routedDirectory:g,resolvedFrom:a.source,conflict:r?{source:r[0],directory:r[1]}:null,sources:J(),details:{owningChildStore:t,sessionRecordDirectory:d,sessionIndexed:!!n,currentSessionDirectory:o.currentSessionDirectory,rememberedForRuntime:p.runtime,persistedAcrossRestarts:p.persisted,activeDirectory:A.getState().currentDirectory??null,piSessionDirectory:C().getState().directory??null}};return console.log("[DEBUG] Session directory resolution:",i),r?console.warn(`[ALERT] Directory sources disagree: routing to "${g}" while "${r[1]}" came from ${r[0]}.`):g?console.log("[OK] All known sources agree on the session directory."):console.warn("[ALERT] No directory resolved for this session — sends fall back to the active directory."),i},async buildDiagnosticsReport(){const e=await this.getAppStatus();return JSON.stringify(e,null,2)},async copyTextToClipboard(e){return U(e)},async copyDiagnosticsReport(){const e=await this.buildDiagnosticsReport();return{...await this.copyTextToClipboard(e),report:e}},checkLastMessage(){const e=this.getLastAssistantMessage();if(!e)return!1;const o=e.isEmpty||e.isEmptyResponse;return o?(console.error("[ALERT] PROBLEMATIC MESSAGE DETECTED!"),console.log("Details:",{messageId:e.messageId,isEmpty:e.isEmpty,isEmptyResponse:e.isEmptyResponse,partsCount:e.partsCount}),e.parts.length>0&&console.log("Parts:",e.parts)):console.log("[OK] Last message looks good!"),o},getStreamingState(){const e=R.getState(),o=C().getState().reducer.bySession,s=new Map;for(const[n,d]of o)s.set(n,O(d));const t=e.currentSessionId?s.get(e.currentSessionId)??null:null;return console.log("[STREAM] Streaming State:",{streamingMessageId:t,streamingMessageIds:Array.from(s.entries())}),{streamingMessageId:t,streamingMessageIds:s}},findEmptyMessages(){if(!R.getState().currentSessionId)return console.log("[ERROR] No active session"),[];const t=b().filter(n=>n.role==="assistant").filter(n=>{const d=D(n.id)||[],c=d.some(a=>a.type==="text"&&a.text&&a.text.trim().length>0),m=d.some(a=>a.type==="tool");return d.length===0||!c&&!m});return console.log(`[INSPECT] Found ${t.length} empty assistant messages`),t.forEach((n,d)=>{const c=D(n.id)||[];console.log(`[${d}] Empty message:`,{messageId:n.id,partsCount:c.length,provider:n.providerID,model:n.modelID,timestamp:n.time?.created})}),t},showRetryHelp(){console.log(`[DEBUG] How to handle empty Claude responses:
2
2
  `),console.log("1. Check the last message:"),console.log(` __piDebug.getLastAssistantMessage()
3
3
  `),console.log("2. Find all empty messages in session:"),console.log(` __piDebug.findEmptyMessages()
4
4
  `),console.log("3. To retry, you can:"),console.log(" - Edit your last user message and resend"),console.log(' - Send a follow-up message like "Please provide the response"'),console.log(` - Try a different model (OpenAI models tend to be more reliable)
@@ -1 +1 @@
1
- import{b as q,i as M,n as K,k as j,j as G,m as W,l as A}from"./computeVirtualFileMetrics-8mC_o5zA.js";import{ci as J,dA as z}from"./useAppFontEffects-BQ1JUauS.js";import{d as X,a as Q}from"./vendor-diff-C3JhlQdm.js";function gn(n,e){return n===e||n?.cacheKey!=null&&n.cacheKey===e?.cacheKey}function mn(n,e){return q(n.theme,e.theme)&&n.useTokenTransformer===e.useTokenTransformer&&n.tokenizeMaxLineLength===e.tokenizeMaxLineLength&&n.lineDiffType===e.lineDiffType&&n.maxLineDiffLength===e.maxLineDiffLength}function pn(n){const e=n.lang??M(n.name),r=n.lang??(n.prevName!=null?M(n.prevName):"text");return e==="text"&&r==="text"}function B({isPartial:n,rangeSize:e,expandedHunks:r,hunkIndex:l,collapsedContextThreshold:f}){const t=Math.max(e,0);if(t===0||n)return{fromStart:0,fromEnd:0,rangeSize:t,collapsedLines:t,renderAll:!1};if(r===!0||t<=f)return{fromStart:t,fromEnd:0,rangeSize:t,collapsedLines:0,renderAll:!0};const h=r?.get(l),d=Math.min(Math.max(h?.fromStart??0,0),t),i=Math.min(Math.max(h?.fromEnd??0,0),t),u=d+i,o=u>=t;return{fromStart:o?t:d,fromEnd:o?0:i,rangeSize:t,collapsedLines:Math.max(t-u,0),renderAll:o}}function In(n){const e=n.hunks[n.hunks.length-1];if(e==null||n.isPartial||n.additionLines.length===0||n.deletionLines.length===0)return!1;const r=n.additionLines.length-(e.additionLineIndex+e.additionCount),l=n.deletionLines.length-(e.deletionLineIndex+e.deletionCount);return r<=0&&l<=0?!1:r!==l}function Y({fileDiff:n,errorPrefix:e}){const r=n.hunks[n.hunks.length-1];if(r==null||n.isPartial||n.additionLines.length===0||n.deletionLines.length===0)return 0;const l=n.additionLines.length-(r.additionLineIndex+r.additionCount),f=n.deletionLines.length-(r.deletionLineIndex+r.deletionCount);if(l<=0&&f<=0)return 0;if(l!==f)throw new Error(`${e}: trailing context mismatch (additions=${l}, deletions=${f}) for ${n.name}`);return Math.min(l,f)}function V({fileDiff:n,hunkIndex:e,expandedHunks:r,collapsedContextThreshold:l,errorPrefix:f}){if(e!==n.hunks.length-1)return;const t=Y({fileDiff:n,errorPrefix:f});if(t<=0)return;if(r===!0||t<=l)return{fromStart:t,fromEnd:0,rangeSize:t,collapsedLines:0,renderAll:!0};const h=r?.get(n.hunks.length),d=Math.min(Math.max(h?.fromStart??0,0),t);return{fromStart:d,fromEnd:0,rangeSize:t,collapsedLines:t-d,renderAll:d>=t}}function $({type:n,metrics:e}){return e.hunkSeparatorHeight??K(n)}function U({type:n,metrics:e}){return n==="simple"||n==="metadata"||n==="line-info-basic"?0:e.spacing}function Z({type:n,hunkIndex:e,hunkSpecs:r}){switch(n){case"simple":return e>0;case"metadata":return r!=null;case"line-info":case"line-info-basic":case"custom":return!0}}function y(n){return n!=="simple"&&n!=="metadata"}function Cn({type:n,metrics:e,hunkIndex:r,hunkSpecs:l}){if(!Z({type:n,hunkIndex:r,hunkSpecs:l}))return;const f=$({type:n,metrics:e}),t=U({type:n,metrics:e}),h=r>0?t:0,d=t;return{height:f,gapBefore:h,gapAfter:d,totalHeight:h+f+d}}function Ln({type:n,metrics:e}){if(!y(n))return;const r=$({type:n,metrics:e}),l=U({type:n,metrics:e});return{height:r,gapBefore:l,gapAfter:0,totalHeight:l+r}}function nn({diff:n,diffStyle:e,startingLine:r=0,totalLines:l=1/0,expandedHunks:f,collapsedContextThreshold:t=1,callback:h}){const d=en({diff:n,diffStyle:e,startingLine:r,expandedHunks:f,collapsedContextThreshold:t}),i={viewportStart:r,viewportEnd:r+l,isWindowedHighlight:r>0||l<1/0,splitCount:d.splitCount,unifiedCount:d.unifiedCount,finalHunkIndex:n.hunks.length-1,shouldBreak(){if(!i.isWindowedHighlight)return!1;const u=i.unifiedCount>=r+l,o=i.splitCount>=r+l;return e==="unified"?u:(e==="split"||u)&&o},shouldSkip(u,o){if(!i.isWindowedHighlight)return!1;const s=i.unifiedCount+u<r,a=i.splitCount+o<r;return e==="unified"?s:(e==="split"||s)&&a},incrementCounts(u,o){(e==="unified"||e==="both")&&(i.unifiedCount+=u),(e==="split"||e==="both")&&(i.splitCount+=o)},isInWindow(u,o){if(!i.isWindowedHighlight)return!0;const s=i.isInUnifiedWindow(u),a=i.isInSplitWindow(o);return e==="unified"?s:e==="split"?a:s||a},isInUnifiedWindow(u){return!i.isWindowedHighlight||i.unifiedCount>=r-u&&i.unifiedCount<r+l},isInSplitWindow(u){return!i.isWindowedHighlight||i.splitCount>=r-u&&i.splitCount<r+l},emit(u,o=!1){return o||(e==="unified"?i.incrementCounts(1,0):e==="split"?i.incrementCounts(0,1):i.incrementCounts(1,1)),h(u)??!1}};n:for(let u=d.hunkIndex;u<n.hunks.length;u++){let g=function(c,p){return a==null||a.collapsedLines<=0||a.fromStart+a.fromEnd>0?0:e==="unified"?c===o.unifiedLineStart+o.unifiedLineCount-1?a.collapsedLines:0:p===o.splitLineStart+o.splitLineCount-1?a.collapsedLines:0},b=function(){return O?0:(O=!0,s.collapsedLines)};const o=n.hunks[u];if(o==null)throw new Error("iterateOverDiff: invalid hunk index");if(i.shouldBreak())break;const s=B({isPartial:n.isPartial,rangeSize:o.collapsedBefore,expandedHunks:f,hunkIndex:u,collapsedContextThreshold:t}),a=u===i.finalHunkIndex?V({fileDiff:n,hunkIndex:u,expandedHunks:f,collapsedContextThreshold:t,errorPrefix:"iterateOverDiff"}):void 0,m=s.fromStart+s.fromEnd;let O=s.collapsedLines===0;if(i.shouldSkip(m,m))i.incrementCounts(m,m),b();else{let c=o.unifiedLineStart-s.rangeSize,p=o.splitLineStart-s.rangeSize,k=o.deletionLineIndex-s.rangeSize,R=o.additionLineIndex-s.rangeSize,S=o.deletionStart-s.rangeSize,H=o.additionStart-s.rangeSize;if(T(i,s.fromStart,e,E=>i.emit({hunkIndex:u,hunk:o,collapsedBefore:0,collapsedAfter:0,type:"context-expanded",deletionLine:{lineNumber:S+E,lineIndex:k+E,noEOFCR:!1,unifiedLineIndex:c+E,splitLineIndex:p+E},additionLine:{unifiedLineIndex:c+E,splitLineIndex:p+E,lineIndex:R+E,lineNumber:H+E,noEOFCR:!1}}))||(c=o.unifiedLineStart-s.fromEnd,p=o.splitLineStart-s.fromEnd,k=o.deletionLineIndex-s.fromEnd,R=o.additionLineIndex-s.fromEnd,S=o.deletionStart-s.fromEnd,H=o.additionStart-s.fromEnd,T(i,s.fromEnd,e,E=>i.emit({hunkIndex:u,hunk:o,collapsedBefore:b(),collapsedAfter:0,type:"context-expanded",deletionLine:{lineNumber:S+E,lineIndex:k+E,noEOFCR:!1,unifiedLineIndex:c+E,splitLineIndex:p+E},additionLine:{unifiedLineIndex:c+E,splitLineIndex:p+E,lineIndex:R+E,lineNumber:H+E,noEOFCR:!1}}),()=>{b()})))break n}let N=o.unifiedLineStart,w=o.splitLineStart,I=o.deletionLineIndex,C=o.additionLineIndex,L=o.deletionStart,v=o.additionStart;const x=o.hunkContent.at(-1);for(const c of o.hunkContent){if(i.shouldBreak())break n;const p=c===x;if(c.type==="context"){if(i.shouldSkip(c.lines,c.lines))i.incrementCounts(c.lines,c.lines),b();else if(T(i,c.lines,e,k=>{const R=p&&k===c.lines-1,S=N+k,H=w+k;return i.emit({hunkIndex:u,hunk:o,collapsedBefore:b(),collapsedAfter:g(S,H),type:"context",deletionLine:{lineNumber:L+k,lineIndex:I+k,noEOFCR:R&&o.noEOFCRDeletions,unifiedLineIndex:S,splitLineIndex:H},additionLine:{unifiedLineIndex:S,splitLineIndex:H,lineIndex:C+k,lineNumber:v+k,noEOFCR:R&&o.noEOFCRAdditions}})},()=>{b()}))break n;N+=c.lines,w+=c.lines,I+=c.lines,C+=c.lines,L+=c.lines,v+=c.lines}else{const k=Math.max(c.deletions,c.additions),R=c.deletions+c.additions;if(!i.shouldSkip(R,k)){const S=rn(i,c,e);(S[0]?.[0]??0)>0&&b();for(const[H,E]of S)for(let D=H;D<E;D++){const _=g(N+D,e==="unified"?w+(D<c.deletions?D:D-c.deletions):w+D);if(i.emit(sn({hunkIndex:u,hunk:o,collapsedBefore:b(),collapsedAfter:_,diffStyle:e,index:D,unifiedLineIndex:N,splitLineIndex:w,additionLineIndex:C,deletionLineIndex:I,additionLineNumber:v,deletionLineNumber:L,content:c,isLastContent:p,unifiedCount:R,splitCount:k}),!0))break n}}b(),i.incrementCounts(R,k),N+=R,w+=k,I+=c.deletions,C+=c.additions,L+=c.deletions,v+=c.additions}}if(a!=null){const{collapsedLines:c,fromStart:p,fromEnd:k}=a,R=p+k;if(T(i,R,e,S=>{const H=S===R-1;return i.emit({hunkIndex:n.hunks.length,hunk:void 0,collapsedBefore:0,collapsedAfter:H?c:0,type:"context-expanded",deletionLine:{lineNumber:L+S,lineIndex:I+S,noEOFCR:!1,unifiedLineIndex:N+S,splitLineIndex:w+S},additionLine:{unifiedLineIndex:N+S,splitLineIndex:w+S,lineIndex:C+S,lineNumber:v+S,noEOFCR:!1}})},void 0,()=>i.shouldBreak()))break n}}}function en({diff:n,diffStyle:e,startingLine:r,expandedHunks:l,collapsedContextThreshold:f}){if(r<=0||e==="both")return{hunkIndex:0,splitCount:0,unifiedCount:0};const t=tn({diff:n,expandedHunks:l,collapsedContextThreshold:f});let h=0,d=n.hunks.length-1,i=n.hunks.length;for(;h<=d;){const o=h+d>>1,s=t[o+1];if(s==null)throw new Error("iterateOverDiff: invalid hunk prefix index");(e==="unified"?s.unifiedCount:s.splitCount)>r?(i=o,d=o-1):h=o+1}if(i>=n.hunks.length){const o=t[n.hunks.length];if(o==null)throw new Error("iterateOverDiff: invalid terminal hunk prefix index");return{hunkIndex:n.hunks.length,splitCount:o.splitCount,unifiedCount:o.unifiedCount}}const u=t[i];if(u==null)throw new Error("iterateOverDiff: invalid selected hunk prefix index");return{hunkIndex:i,splitCount:u.splitCount,unifiedCount:u.unifiedCount}}function tn({diff:n,expandedHunks:e,collapsedContextThreshold:r}){let l=0,f=0;const t=n.hunks.length-1,h=[{splitCount:0,unifiedCount:0}];for(let d=0;d<n.hunks.length;d++){const i=n.hunks[d];if(i==null)throw new Error("iterateOverDiff: invalid hunk summary index");const u=B({isPartial:n.isPartial,rangeSize:i.collapsedBefore,expandedHunks:e,hunkIndex:d,collapsedContextThreshold:r}),o=u.fromStart+u.fromEnd;l+=o+i.splitLineCount,f+=o+i.unifiedLineCount;const s=d===t?V({fileDiff:n,hunkIndex:d,expandedHunks:e,collapsedContextThreshold:r,errorPrefix:"iterateOverDiff"}):void 0;if(s!=null){const a=s.fromStart+s.fromEnd;l+=a,f+=a}h.push({splitCount:l,unifiedCount:f})}return h}function on(n,e,r){if(!n.isWindowedHighlight||e<=0)return[0,e];const l=[];function f(d){const i=Math.max(0,n.viewportStart-d),u=Math.min(e,n.viewportEnd-d);u>i&&l.push([i,u])}if(r!=="split"&&f(n.unifiedCount),r!=="unified"&&f(n.splitCount),l.length===0)return[0,0];let t=l[0][0],h=l[0][1];for(let d=1;d<l.length;d++){const i=l[d];t=Math.min(t,i[0]),h=Math.max(h,i[1])}return[t,h]}function T(n,e,r,l,f,t){const[h,d]=on(n,e,r);h>0&&(n.incrementCounts(h,h),f?.());let i=h;for(;i<e;){if(t?.()===!0)return!0;if(i>=d){n.incrementCounts(e-i,e-i);break}if(n.isInWindow(0,0)){if(l(i)===!0)return!0}else n.incrementCounts(1,1);i++}return!1}function rn(n,e,r){if(!n.isWindowedHighlight)return[[0,r==="unified"?e.deletions+e.additions:Math.max(e.deletions,e.additions)]];const l=r!=="split",f=r!=="unified",t=r==="unified"?"unified":"split",h=[];function d(s,a){if(s+a<=n.viewportStart||s>=n.viewportEnd)return;const m=Math.max(0,n.viewportStart-s),g=Math.min(a,n.viewportEnd-s);return g>m?[m,g]:void 0}function i(s,a){return t==="split"?s:a==="additions"?[s[0]+e.deletions,s[1]+e.deletions]:s}function u(s,a){if(s==null)return;const[m,g]=i(s,a);g>m&&h.push([m,g])}if(l&&(u(d(n.unifiedCount,e.deletions),"deletions"),u(d(n.unifiedCount+e.deletions,e.additions),"additions")),f&&(u(d(n.splitCount,e.deletions),"deletions"),u(d(n.splitCount,e.additions),"additions")),h.length===0)return h;h.sort((s,a)=>s[0]-a[0]);const o=[h[0]];for(const[s,a]of h.slice(1)){const m=o[o.length-1];s<=m[1]?m[1]=Math.max(m[1],a):o.push([s,a])}return o}function sn({hunkIndex:n,hunk:e,collapsedAfter:r,collapsedBefore:l,diffStyle:f,index:t,unifiedLineIndex:h,splitLineIndex:d,additionLineIndex:i,deletionLineIndex:u,additionLineNumber:o,deletionLineNumber:s,content:a,isLastContent:m,unifiedCount:g,splitCount:O}){const b=t<a.deletions?h+t:void 0,N=f==="unified"?t>=a.deletions?h+t:void 0:t<a.additions?h+a.deletions+t:void 0,w=f==="unified"?d+(t<a.deletions?t:t-a.deletions):d+t,I=t<a.deletions?u+t:void 0,C=t<a.deletions?s+t:void 0,L=f==="unified"?t>=a.deletions?i+(t-a.deletions):void 0:t<a.additions?i+t:void 0,v=f==="unified"?t>=a.deletions?o+(t-a.deletions):void 0:t<a.additions?o+t:void 0,x=f==="unified"?m&&t===a.deletions-1&&e.noEOFCRDeletions:m&&t===O-1&&e.noEOFCRDeletions,c=f==="unified"?m&&t===g-1&&e.noEOFCRAdditions:m&&t===O-1&&e.noEOFCRAdditions,p=I!=null&&C!=null&&b!=null?{lineNumber:C,lineIndex:I,noEOFCR:x,unifiedLineIndex:b,splitLineIndex:w}:void 0,k=L!=null&&v!=null&&N!=null?{unifiedLineIndex:N,splitLineIndex:w,lineIndex:L,lineNumber:v,noEOFCR:c}:void 0;if(p==null&&k!=null)return{type:"change",hunkIndex:n,hunk:e,collapsedAfter:r,collapsedBefore:l,deletionLine:void 0,additionLine:k};if(p!=null&&k==null)return{type:"change",hunkIndex:n,hunk:e,collapsedAfter:r,collapsedBefore:l,deletionLine:p,additionLine:void 0};if(p==null||k==null)throw new Error("iterateOverDiff: missing change line data");return{type:"change",hunkIndex:n,hunk:e,collapsedAfter:r,collapsedBefore:l,deletionLine:p,additionLine:k}}function P({line:n,spanStart:e,spanLength:r}){return{start:{line:n,character:e},end:{line:n,character:e+r},properties:{"data-diff-span":""},alwaysWrap:!0}}function F({item:n,arr:e,enableJoin:r,isNeutral:l=!1,isLastItem:f=!1}){const t=e[e.length-1];if(t==null||f||!r){e.push([l?0:1,n.value]);return}const h=t[0]===0;if(l===h||l&&n.value.length===1&&!h){t[1]+=n.value;return}e.push([l?0:1,n.value])}const ln={forcePlainText:!1};function xn(n,e,r,{forcePlainText:l,startingLine:f,totalLines:t,expandedHunks:h,collapsedContextThreshold:d=1}=ln){l?(f??=0,t??=1/0):(f=0,t=1/0);const i=f>0||t<1/0,u=typeof r.theme=="string"?e.getTheme(r.theme).type:void 0,o=j({theme:r.theme,highlighter:e}),s=l&&!i&&(n.unifiedLineCount>1e3||n.splitLineCount>1e3)?"none":r.lineDiffType,a={deletionLines:[],additionLines:[]},{maxLineDiffLength:m}=r,g=!l&&!n.isPartial,O=l?h:void 0,b=new Map;function N(I){const C=g?0:I,L=b.get(C)??un();return b.set(C,L),L}function w(I,C,L,v){if(i){let x=L.at(-1);(x==null||x.targetIndex+x.count!==C)&&(x={targetIndex:C,originalOffset:v.length,count:0},L.push(x)),x.count++}v.push(I)}nn({diff:n,diffStyle:"both",startingLine:f,totalLines:t,expandedHunks:i?O:!0,collapsedContextThreshold:d,callback:({hunkIndex:I,additionLine:C,deletionLine:L,type:v})=>{const x=N(I),c=C!=null?C.splitLineIndex:L.splitLineIndex;v==="change"&&C!=null&&L!=null&&an({additionLine:n.additionLines[C.lineIndex],deletionLine:n.deletionLines[L.lineIndex],deletionLineIndex:x.deletionContent.length,additionLineIndex:x.additionContent.length,deletionDecorations:x.deletionDecorations,additionDecorations:x.additionDecorations,lineDiffType:s,maxLineDiffLength:m}),L!=null&&(w(n.deletionLines[L.lineIndex],L.lineIndex,x.deletionSegments,x.deletionContent),x.deletionInfo.push({type:v==="change"?"change-deletion":v,lineNumber:L.lineNumber,altLineNumber:v==="change"?void 0:C.lineNumber??void 0,lineIndex:`${L.unifiedLineIndex},${c}`})),C!=null&&(w(n.additionLines[C.lineIndex],C.lineIndex,x.additionSegments,x.additionContent),x.additionInfo.push({type:v==="change"?"change-addition":v,lineNumber:C.lineNumber,altLineNumber:v==="change"?void 0:L.lineNumber??void 0,lineIndex:`${C.unifiedLineIndex},${c}`}))}});for(const I of b.values()){if(I.deletionContent.length===0&&I.additionContent.length===0)continue;const C={name:n.prevName??n.name,contents:I.deletionContent.value},L={name:n.name,contents:I.additionContent.value},{deletionLines:v,additionLines:x}=dn({deletionFile:C,deletionInfo:I.deletionInfo,deletionDecorations:I.deletionDecorations,additionFile:L,additionInfo:I.additionInfo,additionDecorations:I.additionDecorations,highlighter:e,options:r,languageOverride:l?"text":n.lang});if(g){a.deletionLines=v,a.additionLines=x;continue}if(I.deletionSegments.length>0)for(const c of I.deletionSegments)for(let p=0;p<c.count;p++)a.deletionLines[c.targetIndex+p]=v[c.originalOffset+p];else a.deletionLines.push(...v);if(I.additionSegments.length>0)for(const c of I.additionSegments)for(let p=0;p<c.count;p++)a.additionLines[c.targetIndex+p]=x[c.originalOffset+p];else a.additionLines.push(...x)}return{code:a,themeStyles:o,baseThemeType:u}}function an({deletionLine:n,additionLine:e,deletionLineIndex:r,additionLineIndex:l,deletionDecorations:f,additionDecorations:t,lineDiffType:h,maxLineDiffLength:d}){if(n==null||e==null||h==="none"||(n=z(n),e=z(e),n.length>d||e.length>d))return;const i=h==="char"?X(n,e):Q(n,e),u=[],o=[],s=h==="word-alt",a=i.at(-1);for(const g of i){const O=g===a;!g.added&&!g.removed?(F({item:g,arr:u,enableJoin:s,isNeutral:!0,isLastItem:O}),F({item:g,arr:o,enableJoin:s,isNeutral:!0,isLastItem:O})):g.removed?F({item:g,arr:u,enableJoin:s,isLastItem:O}):F({item:g,arr:o,enableJoin:s,isLastItem:O})}let m=0;for(const g of u)g[0]===1&&f.push(P({line:r,spanStart:m,spanLength:g[1].length})),m+=g[1].length;m=0;for(const g of o)g[0]===1&&t.push(P({line:l,spanStart:m,spanLength:g[1].length})),m+=g[1].length}function un(){return{deletionContent:{push(n){this.value+=n,this.length++},value:"",length:0},additionContent:{push(n){this.value+=n,this.length++},value:"",length:0},deletionInfo:[],additionInfo:[],deletionDecorations:[],additionDecorations:[],deletionSegments:[],additionSegments:[]}}function dn({deletionFile:n,additionFile:e,deletionInfo:r,additionInfo:l,highlighter:f,deletionDecorations:t,additionDecorations:h,languageOverride:d,options:{theme:i=J,...u}}){const o=d??M(n.name),s=d??M(e.name),{state:a,transformers:m}=G(u.useTokenTransformer),g=typeof i=="string"?{...u,lang:"text",theme:i,transformers:m,decorations:void 0,defaultColor:!1,cssVariablePrefix:W("token"),tokenizeTimeLimit:0}:{...u,lang:"text",themes:i,transformers:m,decorations:void 0,defaultColor:!1,cssVariablePrefix:W("token"),tokenizeTimeLimit:0};return{deletionLines:n.contents===""?[]:(g.lang=o,a.lineInfo=r,g.decorations=t,A(f.codeToHast(z(n.contents),g))),additionLines:e.contents===""?[]:(g.lang=s,g.decorations=h,a.lineInfo=l,A(f.codeToHast(z(e.contents),g)))}}export{mn as a,gn as b,nn as c,B as d,Cn as e,V as f,Y as g,In as h,pn as i,Ln as j,xn as r};
1
+ import{b as q,i as M,n as K,k as j,j as G,m as W,l as A}from"./computeVirtualFileMetrics-Bjhk2CQS.js";import{ci as J,dA as z}from"./useAppFontEffects-CqHhRKmN.js";import{d as X,a as Q}from"./vendor-diff-C3JhlQdm.js";function gn(n,e){return n===e||n?.cacheKey!=null&&n.cacheKey===e?.cacheKey}function mn(n,e){return q(n.theme,e.theme)&&n.useTokenTransformer===e.useTokenTransformer&&n.tokenizeMaxLineLength===e.tokenizeMaxLineLength&&n.lineDiffType===e.lineDiffType&&n.maxLineDiffLength===e.maxLineDiffLength}function pn(n){const e=n.lang??M(n.name),r=n.lang??(n.prevName!=null?M(n.prevName):"text");return e==="text"&&r==="text"}function B({isPartial:n,rangeSize:e,expandedHunks:r,hunkIndex:l,collapsedContextThreshold:f}){const t=Math.max(e,0);if(t===0||n)return{fromStart:0,fromEnd:0,rangeSize:t,collapsedLines:t,renderAll:!1};if(r===!0||t<=f)return{fromStart:t,fromEnd:0,rangeSize:t,collapsedLines:0,renderAll:!0};const h=r?.get(l),d=Math.min(Math.max(h?.fromStart??0,0),t),i=Math.min(Math.max(h?.fromEnd??0,0),t),u=d+i,o=u>=t;return{fromStart:o?t:d,fromEnd:o?0:i,rangeSize:t,collapsedLines:Math.max(t-u,0),renderAll:o}}function In(n){const e=n.hunks[n.hunks.length-1];if(e==null||n.isPartial||n.additionLines.length===0||n.deletionLines.length===0)return!1;const r=n.additionLines.length-(e.additionLineIndex+e.additionCount),l=n.deletionLines.length-(e.deletionLineIndex+e.deletionCount);return r<=0&&l<=0?!1:r!==l}function Y({fileDiff:n,errorPrefix:e}){const r=n.hunks[n.hunks.length-1];if(r==null||n.isPartial||n.additionLines.length===0||n.deletionLines.length===0)return 0;const l=n.additionLines.length-(r.additionLineIndex+r.additionCount),f=n.deletionLines.length-(r.deletionLineIndex+r.deletionCount);if(l<=0&&f<=0)return 0;if(l!==f)throw new Error(`${e}: trailing context mismatch (additions=${l}, deletions=${f}) for ${n.name}`);return Math.min(l,f)}function V({fileDiff:n,hunkIndex:e,expandedHunks:r,collapsedContextThreshold:l,errorPrefix:f}){if(e!==n.hunks.length-1)return;const t=Y({fileDiff:n,errorPrefix:f});if(t<=0)return;if(r===!0||t<=l)return{fromStart:t,fromEnd:0,rangeSize:t,collapsedLines:0,renderAll:!0};const h=r?.get(n.hunks.length),d=Math.min(Math.max(h?.fromStart??0,0),t);return{fromStart:d,fromEnd:0,rangeSize:t,collapsedLines:t-d,renderAll:d>=t}}function $({type:n,metrics:e}){return e.hunkSeparatorHeight??K(n)}function U({type:n,metrics:e}){return n==="simple"||n==="metadata"||n==="line-info-basic"?0:e.spacing}function Z({type:n,hunkIndex:e,hunkSpecs:r}){switch(n){case"simple":return e>0;case"metadata":return r!=null;case"line-info":case"line-info-basic":case"custom":return!0}}function y(n){return n!=="simple"&&n!=="metadata"}function Cn({type:n,metrics:e,hunkIndex:r,hunkSpecs:l}){if(!Z({type:n,hunkIndex:r,hunkSpecs:l}))return;const f=$({type:n,metrics:e}),t=U({type:n,metrics:e}),h=r>0?t:0,d=t;return{height:f,gapBefore:h,gapAfter:d,totalHeight:h+f+d}}function Ln({type:n,metrics:e}){if(!y(n))return;const r=$({type:n,metrics:e}),l=U({type:n,metrics:e});return{height:r,gapBefore:l,gapAfter:0,totalHeight:l+r}}function nn({diff:n,diffStyle:e,startingLine:r=0,totalLines:l=1/0,expandedHunks:f,collapsedContextThreshold:t=1,callback:h}){const d=en({diff:n,diffStyle:e,startingLine:r,expandedHunks:f,collapsedContextThreshold:t}),i={viewportStart:r,viewportEnd:r+l,isWindowedHighlight:r>0||l<1/0,splitCount:d.splitCount,unifiedCount:d.unifiedCount,finalHunkIndex:n.hunks.length-1,shouldBreak(){if(!i.isWindowedHighlight)return!1;const u=i.unifiedCount>=r+l,o=i.splitCount>=r+l;return e==="unified"?u:(e==="split"||u)&&o},shouldSkip(u,o){if(!i.isWindowedHighlight)return!1;const s=i.unifiedCount+u<r,a=i.splitCount+o<r;return e==="unified"?s:(e==="split"||s)&&a},incrementCounts(u,o){(e==="unified"||e==="both")&&(i.unifiedCount+=u),(e==="split"||e==="both")&&(i.splitCount+=o)},isInWindow(u,o){if(!i.isWindowedHighlight)return!0;const s=i.isInUnifiedWindow(u),a=i.isInSplitWindow(o);return e==="unified"?s:e==="split"?a:s||a},isInUnifiedWindow(u){return!i.isWindowedHighlight||i.unifiedCount>=r-u&&i.unifiedCount<r+l},isInSplitWindow(u){return!i.isWindowedHighlight||i.splitCount>=r-u&&i.splitCount<r+l},emit(u,o=!1){return o||(e==="unified"?i.incrementCounts(1,0):e==="split"?i.incrementCounts(0,1):i.incrementCounts(1,1)),h(u)??!1}};n:for(let u=d.hunkIndex;u<n.hunks.length;u++){let g=function(c,p){return a==null||a.collapsedLines<=0||a.fromStart+a.fromEnd>0?0:e==="unified"?c===o.unifiedLineStart+o.unifiedLineCount-1?a.collapsedLines:0:p===o.splitLineStart+o.splitLineCount-1?a.collapsedLines:0},b=function(){return O?0:(O=!0,s.collapsedLines)};const o=n.hunks[u];if(o==null)throw new Error("iterateOverDiff: invalid hunk index");if(i.shouldBreak())break;const s=B({isPartial:n.isPartial,rangeSize:o.collapsedBefore,expandedHunks:f,hunkIndex:u,collapsedContextThreshold:t}),a=u===i.finalHunkIndex?V({fileDiff:n,hunkIndex:u,expandedHunks:f,collapsedContextThreshold:t,errorPrefix:"iterateOverDiff"}):void 0,m=s.fromStart+s.fromEnd;let O=s.collapsedLines===0;if(i.shouldSkip(m,m))i.incrementCounts(m,m),b();else{let c=o.unifiedLineStart-s.rangeSize,p=o.splitLineStart-s.rangeSize,k=o.deletionLineIndex-s.rangeSize,R=o.additionLineIndex-s.rangeSize,S=o.deletionStart-s.rangeSize,H=o.additionStart-s.rangeSize;if(T(i,s.fromStart,e,E=>i.emit({hunkIndex:u,hunk:o,collapsedBefore:0,collapsedAfter:0,type:"context-expanded",deletionLine:{lineNumber:S+E,lineIndex:k+E,noEOFCR:!1,unifiedLineIndex:c+E,splitLineIndex:p+E},additionLine:{unifiedLineIndex:c+E,splitLineIndex:p+E,lineIndex:R+E,lineNumber:H+E,noEOFCR:!1}}))||(c=o.unifiedLineStart-s.fromEnd,p=o.splitLineStart-s.fromEnd,k=o.deletionLineIndex-s.fromEnd,R=o.additionLineIndex-s.fromEnd,S=o.deletionStart-s.fromEnd,H=o.additionStart-s.fromEnd,T(i,s.fromEnd,e,E=>i.emit({hunkIndex:u,hunk:o,collapsedBefore:b(),collapsedAfter:0,type:"context-expanded",deletionLine:{lineNumber:S+E,lineIndex:k+E,noEOFCR:!1,unifiedLineIndex:c+E,splitLineIndex:p+E},additionLine:{unifiedLineIndex:c+E,splitLineIndex:p+E,lineIndex:R+E,lineNumber:H+E,noEOFCR:!1}}),()=>{b()})))break n}let N=o.unifiedLineStart,w=o.splitLineStart,I=o.deletionLineIndex,C=o.additionLineIndex,L=o.deletionStart,v=o.additionStart;const x=o.hunkContent.at(-1);for(const c of o.hunkContent){if(i.shouldBreak())break n;const p=c===x;if(c.type==="context"){if(i.shouldSkip(c.lines,c.lines))i.incrementCounts(c.lines,c.lines),b();else if(T(i,c.lines,e,k=>{const R=p&&k===c.lines-1,S=N+k,H=w+k;return i.emit({hunkIndex:u,hunk:o,collapsedBefore:b(),collapsedAfter:g(S,H),type:"context",deletionLine:{lineNumber:L+k,lineIndex:I+k,noEOFCR:R&&o.noEOFCRDeletions,unifiedLineIndex:S,splitLineIndex:H},additionLine:{unifiedLineIndex:S,splitLineIndex:H,lineIndex:C+k,lineNumber:v+k,noEOFCR:R&&o.noEOFCRAdditions}})},()=>{b()}))break n;N+=c.lines,w+=c.lines,I+=c.lines,C+=c.lines,L+=c.lines,v+=c.lines}else{const k=Math.max(c.deletions,c.additions),R=c.deletions+c.additions;if(!i.shouldSkip(R,k)){const S=rn(i,c,e);(S[0]?.[0]??0)>0&&b();for(const[H,E]of S)for(let D=H;D<E;D++){const _=g(N+D,e==="unified"?w+(D<c.deletions?D:D-c.deletions):w+D);if(i.emit(sn({hunkIndex:u,hunk:o,collapsedBefore:b(),collapsedAfter:_,diffStyle:e,index:D,unifiedLineIndex:N,splitLineIndex:w,additionLineIndex:C,deletionLineIndex:I,additionLineNumber:v,deletionLineNumber:L,content:c,isLastContent:p,unifiedCount:R,splitCount:k}),!0))break n}}b(),i.incrementCounts(R,k),N+=R,w+=k,I+=c.deletions,C+=c.additions,L+=c.deletions,v+=c.additions}}if(a!=null){const{collapsedLines:c,fromStart:p,fromEnd:k}=a,R=p+k;if(T(i,R,e,S=>{const H=S===R-1;return i.emit({hunkIndex:n.hunks.length,hunk:void 0,collapsedBefore:0,collapsedAfter:H?c:0,type:"context-expanded",deletionLine:{lineNumber:L+S,lineIndex:I+S,noEOFCR:!1,unifiedLineIndex:N+S,splitLineIndex:w+S},additionLine:{unifiedLineIndex:N+S,splitLineIndex:w+S,lineIndex:C+S,lineNumber:v+S,noEOFCR:!1}})},void 0,()=>i.shouldBreak()))break n}}}function en({diff:n,diffStyle:e,startingLine:r,expandedHunks:l,collapsedContextThreshold:f}){if(r<=0||e==="both")return{hunkIndex:0,splitCount:0,unifiedCount:0};const t=tn({diff:n,expandedHunks:l,collapsedContextThreshold:f});let h=0,d=n.hunks.length-1,i=n.hunks.length;for(;h<=d;){const o=h+d>>1,s=t[o+1];if(s==null)throw new Error("iterateOverDiff: invalid hunk prefix index");(e==="unified"?s.unifiedCount:s.splitCount)>r?(i=o,d=o-1):h=o+1}if(i>=n.hunks.length){const o=t[n.hunks.length];if(o==null)throw new Error("iterateOverDiff: invalid terminal hunk prefix index");return{hunkIndex:n.hunks.length,splitCount:o.splitCount,unifiedCount:o.unifiedCount}}const u=t[i];if(u==null)throw new Error("iterateOverDiff: invalid selected hunk prefix index");return{hunkIndex:i,splitCount:u.splitCount,unifiedCount:u.unifiedCount}}function tn({diff:n,expandedHunks:e,collapsedContextThreshold:r}){let l=0,f=0;const t=n.hunks.length-1,h=[{splitCount:0,unifiedCount:0}];for(let d=0;d<n.hunks.length;d++){const i=n.hunks[d];if(i==null)throw new Error("iterateOverDiff: invalid hunk summary index");const u=B({isPartial:n.isPartial,rangeSize:i.collapsedBefore,expandedHunks:e,hunkIndex:d,collapsedContextThreshold:r}),o=u.fromStart+u.fromEnd;l+=o+i.splitLineCount,f+=o+i.unifiedLineCount;const s=d===t?V({fileDiff:n,hunkIndex:d,expandedHunks:e,collapsedContextThreshold:r,errorPrefix:"iterateOverDiff"}):void 0;if(s!=null){const a=s.fromStart+s.fromEnd;l+=a,f+=a}h.push({splitCount:l,unifiedCount:f})}return h}function on(n,e,r){if(!n.isWindowedHighlight||e<=0)return[0,e];const l=[];function f(d){const i=Math.max(0,n.viewportStart-d),u=Math.min(e,n.viewportEnd-d);u>i&&l.push([i,u])}if(r!=="split"&&f(n.unifiedCount),r!=="unified"&&f(n.splitCount),l.length===0)return[0,0];let t=l[0][0],h=l[0][1];for(let d=1;d<l.length;d++){const i=l[d];t=Math.min(t,i[0]),h=Math.max(h,i[1])}return[t,h]}function T(n,e,r,l,f,t){const[h,d]=on(n,e,r);h>0&&(n.incrementCounts(h,h),f?.());let i=h;for(;i<e;){if(t?.()===!0)return!0;if(i>=d){n.incrementCounts(e-i,e-i);break}if(n.isInWindow(0,0)){if(l(i)===!0)return!0}else n.incrementCounts(1,1);i++}return!1}function rn(n,e,r){if(!n.isWindowedHighlight)return[[0,r==="unified"?e.deletions+e.additions:Math.max(e.deletions,e.additions)]];const l=r!=="split",f=r!=="unified",t=r==="unified"?"unified":"split",h=[];function d(s,a){if(s+a<=n.viewportStart||s>=n.viewportEnd)return;const m=Math.max(0,n.viewportStart-s),g=Math.min(a,n.viewportEnd-s);return g>m?[m,g]:void 0}function i(s,a){return t==="split"?s:a==="additions"?[s[0]+e.deletions,s[1]+e.deletions]:s}function u(s,a){if(s==null)return;const[m,g]=i(s,a);g>m&&h.push([m,g])}if(l&&(u(d(n.unifiedCount,e.deletions),"deletions"),u(d(n.unifiedCount+e.deletions,e.additions),"additions")),f&&(u(d(n.splitCount,e.deletions),"deletions"),u(d(n.splitCount,e.additions),"additions")),h.length===0)return h;h.sort((s,a)=>s[0]-a[0]);const o=[h[0]];for(const[s,a]of h.slice(1)){const m=o[o.length-1];s<=m[1]?m[1]=Math.max(m[1],a):o.push([s,a])}return o}function sn({hunkIndex:n,hunk:e,collapsedAfter:r,collapsedBefore:l,diffStyle:f,index:t,unifiedLineIndex:h,splitLineIndex:d,additionLineIndex:i,deletionLineIndex:u,additionLineNumber:o,deletionLineNumber:s,content:a,isLastContent:m,unifiedCount:g,splitCount:O}){const b=t<a.deletions?h+t:void 0,N=f==="unified"?t>=a.deletions?h+t:void 0:t<a.additions?h+a.deletions+t:void 0,w=f==="unified"?d+(t<a.deletions?t:t-a.deletions):d+t,I=t<a.deletions?u+t:void 0,C=t<a.deletions?s+t:void 0,L=f==="unified"?t>=a.deletions?i+(t-a.deletions):void 0:t<a.additions?i+t:void 0,v=f==="unified"?t>=a.deletions?o+(t-a.deletions):void 0:t<a.additions?o+t:void 0,x=f==="unified"?m&&t===a.deletions-1&&e.noEOFCRDeletions:m&&t===O-1&&e.noEOFCRDeletions,c=f==="unified"?m&&t===g-1&&e.noEOFCRAdditions:m&&t===O-1&&e.noEOFCRAdditions,p=I!=null&&C!=null&&b!=null?{lineNumber:C,lineIndex:I,noEOFCR:x,unifiedLineIndex:b,splitLineIndex:w}:void 0,k=L!=null&&v!=null&&N!=null?{unifiedLineIndex:N,splitLineIndex:w,lineIndex:L,lineNumber:v,noEOFCR:c}:void 0;if(p==null&&k!=null)return{type:"change",hunkIndex:n,hunk:e,collapsedAfter:r,collapsedBefore:l,deletionLine:void 0,additionLine:k};if(p!=null&&k==null)return{type:"change",hunkIndex:n,hunk:e,collapsedAfter:r,collapsedBefore:l,deletionLine:p,additionLine:void 0};if(p==null||k==null)throw new Error("iterateOverDiff: missing change line data");return{type:"change",hunkIndex:n,hunk:e,collapsedAfter:r,collapsedBefore:l,deletionLine:p,additionLine:k}}function P({line:n,spanStart:e,spanLength:r}){return{start:{line:n,character:e},end:{line:n,character:e+r},properties:{"data-diff-span":""},alwaysWrap:!0}}function F({item:n,arr:e,enableJoin:r,isNeutral:l=!1,isLastItem:f=!1}){const t=e[e.length-1];if(t==null||f||!r){e.push([l?0:1,n.value]);return}const h=t[0]===0;if(l===h||l&&n.value.length===1&&!h){t[1]+=n.value;return}e.push([l?0:1,n.value])}const ln={forcePlainText:!1};function xn(n,e,r,{forcePlainText:l,startingLine:f,totalLines:t,expandedHunks:h,collapsedContextThreshold:d=1}=ln){l?(f??=0,t??=1/0):(f=0,t=1/0);const i=f>0||t<1/0,u=typeof r.theme=="string"?e.getTheme(r.theme).type:void 0,o=j({theme:r.theme,highlighter:e}),s=l&&!i&&(n.unifiedLineCount>1e3||n.splitLineCount>1e3)?"none":r.lineDiffType,a={deletionLines:[],additionLines:[]},{maxLineDiffLength:m}=r,g=!l&&!n.isPartial,O=l?h:void 0,b=new Map;function N(I){const C=g?0:I,L=b.get(C)??un();return b.set(C,L),L}function w(I,C,L,v){if(i){let x=L.at(-1);(x==null||x.targetIndex+x.count!==C)&&(x={targetIndex:C,originalOffset:v.length,count:0},L.push(x)),x.count++}v.push(I)}nn({diff:n,diffStyle:"both",startingLine:f,totalLines:t,expandedHunks:i?O:!0,collapsedContextThreshold:d,callback:({hunkIndex:I,additionLine:C,deletionLine:L,type:v})=>{const x=N(I),c=C!=null?C.splitLineIndex:L.splitLineIndex;v==="change"&&C!=null&&L!=null&&an({additionLine:n.additionLines[C.lineIndex],deletionLine:n.deletionLines[L.lineIndex],deletionLineIndex:x.deletionContent.length,additionLineIndex:x.additionContent.length,deletionDecorations:x.deletionDecorations,additionDecorations:x.additionDecorations,lineDiffType:s,maxLineDiffLength:m}),L!=null&&(w(n.deletionLines[L.lineIndex],L.lineIndex,x.deletionSegments,x.deletionContent),x.deletionInfo.push({type:v==="change"?"change-deletion":v,lineNumber:L.lineNumber,altLineNumber:v==="change"?void 0:C.lineNumber??void 0,lineIndex:`${L.unifiedLineIndex},${c}`})),C!=null&&(w(n.additionLines[C.lineIndex],C.lineIndex,x.additionSegments,x.additionContent),x.additionInfo.push({type:v==="change"?"change-addition":v,lineNumber:C.lineNumber,altLineNumber:v==="change"?void 0:L.lineNumber??void 0,lineIndex:`${C.unifiedLineIndex},${c}`}))}});for(const I of b.values()){if(I.deletionContent.length===0&&I.additionContent.length===0)continue;const C={name:n.prevName??n.name,contents:I.deletionContent.value},L={name:n.name,contents:I.additionContent.value},{deletionLines:v,additionLines:x}=dn({deletionFile:C,deletionInfo:I.deletionInfo,deletionDecorations:I.deletionDecorations,additionFile:L,additionInfo:I.additionInfo,additionDecorations:I.additionDecorations,highlighter:e,options:r,languageOverride:l?"text":n.lang});if(g){a.deletionLines=v,a.additionLines=x;continue}if(I.deletionSegments.length>0)for(const c of I.deletionSegments)for(let p=0;p<c.count;p++)a.deletionLines[c.targetIndex+p]=v[c.originalOffset+p];else a.deletionLines.push(...v);if(I.additionSegments.length>0)for(const c of I.additionSegments)for(let p=0;p<c.count;p++)a.additionLines[c.targetIndex+p]=x[c.originalOffset+p];else a.additionLines.push(...x)}return{code:a,themeStyles:o,baseThemeType:u}}function an({deletionLine:n,additionLine:e,deletionLineIndex:r,additionLineIndex:l,deletionDecorations:f,additionDecorations:t,lineDiffType:h,maxLineDiffLength:d}){if(n==null||e==null||h==="none"||(n=z(n),e=z(e),n.length>d||e.length>d))return;const i=h==="char"?X(n,e):Q(n,e),u=[],o=[],s=h==="word-alt",a=i.at(-1);for(const g of i){const O=g===a;!g.added&&!g.removed?(F({item:g,arr:u,enableJoin:s,isNeutral:!0,isLastItem:O}),F({item:g,arr:o,enableJoin:s,isNeutral:!0,isLastItem:O})):g.removed?F({item:g,arr:u,enableJoin:s,isLastItem:O}):F({item:g,arr:o,enableJoin:s,isLastItem:O})}let m=0;for(const g of u)g[0]===1&&f.push(P({line:r,spanStart:m,spanLength:g[1].length})),m+=g[1].length;m=0;for(const g of o)g[0]===1&&t.push(P({line:l,spanStart:m,spanLength:g[1].length})),m+=g[1].length}function un(){return{deletionContent:{push(n){this.value+=n,this.length++},value:"",length:0},additionContent:{push(n){this.value+=n,this.length++},value:"",length:0},deletionInfo:[],additionInfo:[],deletionDecorations:[],additionDecorations:[],deletionSegments:[],additionSegments:[]}}function dn({deletionFile:n,additionFile:e,deletionInfo:r,additionInfo:l,highlighter:f,deletionDecorations:t,additionDecorations:h,languageOverride:d,options:{theme:i=J,...u}}){const o=d??M(n.name),s=d??M(e.name),{state:a,transformers:m}=G(u.useTokenTransformer),g=typeof i=="string"?{...u,lang:"text",theme:i,transformers:m,decorations:void 0,defaultColor:!1,cssVariablePrefix:W("token"),tokenizeTimeLimit:0}:{...u,lang:"text",themes:i,transformers:m,decorations:void 0,defaultColor:!1,cssVariablePrefix:W("token"),tokenizeTimeLimit:0};return{deletionLines:n.contents===""?[]:(g.lang=o,a.lineInfo=r,g.decorations=t,A(f.codeToHast(z(n.contents),g))),additionLines:e.contents===""?[]:(g.lang=s,g.decorations=h,a.lineInfo=l,A(f.codeToHast(z(e.contents),g)))}}export{mn as a,gn as b,nn as c,B as d,Cn as e,V as f,Y as g,In as h,pn as i,Ln as j,xn as r};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionSwitcherDropdown-Dpob2_y5.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-boot-EC6IyLt1.js","assets/vendor-react-DASdDPIk.js","assets/vendor-clsx-B-dksMZM.js","assets/useAppFontEffects-BQ1JUauS.js","assets/index-DWSrsQWl.js","assets/vendor-zustand-CUi8eEds.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-DsQIBAWK.css","assets/runtimeSurface-Der4qUnI.js","assets/nativeFileSave-CFuugNKV.js"])))=>i.map(i=>d[i]);
2
- import{k as e,aN as ye}from"./vendor-boot-EC6IyLt1.js";import{R as c,a as me}from"./vendor-react-DASdDPIk.js";/* empty css */import{e as K,u as J,ay as ge,w as X,f as ie,au as U,L as we,O as ve,l as le,t as je,o as be}from"./index-DWSrsQWl.js";import{f as Se,a as Ie,s as Ce}from"./pi-session-focus-preference-DQjF7Nh1.js";import{c2 as Ne,I as V,b6 as De,aj as Pe,ak as Me,am as ke,c3 as Ee,c4 as _e,h as j,bi as Oe,a as ae,O as P,aC as ce,c5 as Le,z as Te,aN as Re,bS as Ae,bF as Be,B as de,bW as Fe,c6 as ue,c7 as ze,t as Ue,g as $e,Y as We,E as He,_ as Ge,$ as Ke,a0 as Ve,a4 as Je,a6 as Ye,a7 as qe,c8 as Qe,bT as Xe,aa as Ze,ab as et,ac as tt,ad as st}from"./useAppFontEffects-BQ1JUauS.js";import{_ as rt}from"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CUi8eEds.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./runtimeSurface-Der4qUnI.js";import"./nativeFileSave-CFuugNKV.js";const nt=({mode:t,children:r})=>e.jsx(Ne.Provider,{value:t,children:r}),ot=Ee,it=_e,at=({totalTokens:t,percentage:r,colorPercentage:n,contextLimit:a,outputLimit:o,size:u="default",isMobile:l=!1,hideIcon:D=!1,showPercentIcon:E=!1,className:p,valueClassName:f,percentIconClassName:_,onClick:M,pressed:L=!1,cacheRead:x,cacheWrite:C,cacheHitPercent:h})=>{const[b,i]=c.useState(!1),g=typeof n=="number"?n:r,m=ot(r)??0,y=it(g),Y=y==="critical"?"var(--status-error)":y==="warn"?"var(--status-warning)":"var(--status-success)",w=I=>I>=1e6?`${(I/1e6).toFixed(1)}M`:I>=1e3?`${(I/1e3).toFixed(1)}K`:I.toFixed(1).replace(/\.0$/,""),N=I=>I>=90?"text-status-error":I>=75?"text-status-warning":"text-status-success",k=20,$=3,W=(k-$)/2,re=2*Math.PI*W,q=re*(1-m/100),R=typeof o=="number"?Math.max(o,0):0,A=typeof x=="number"&&typeof C=="number",Z=A?Math.max(0,x):0,B=A?Math.max(0,C):0,O=typeof h=="number"&&Number.isFinite(h),T=[`Used tokens: ${w(t)}`,`Context limit: ${w(a)}`,`Output limit: ${w(R)}`,...A?[`Cache read: ${w(Z)}`,`Cache write: ${w(B)}`]:[],...O?[`Cache hit: ${h.toFixed(1)}%`]:[],`${Math.min(r,999).toFixed(1)}% used`],F=!l&&typeof M=="function",v=e.jsxs(e.Fragment,{children:[!l&&!D&&e.jsx(V,{name:"donut-chart",className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:K("font-medium inline-flex items-center gap-1.5",f),children:E?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{viewBox:`0 0 ${k} ${k}`,className:K("h-3.5 w-3.5 -rotate-90",_),role:"progressbar","aria-valuenow":Math.round(m),"aria-valuemin":0,"aria-valuemax":100,children:[e.jsx("circle",{cx:k/2,cy:k/2,r:W,fill:"none",stroke:"var(--interactive-border)",strokeWidth:$}),e.jsx("circle",{cx:k/2,cy:k/2,r:W,fill:"none",stroke:Y,strokeWidth:$,strokeLinecap:"round",strokeDasharray:re,strokeDashoffset:q,className:"transition-[stroke-dashoffset,stroke] duration-300"})]}),e.jsxs("span",{className:"text-foreground",children:[Math.min(r,999).toFixed(1),"%"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:N(g),children:Math.min(r,999).toFixed(1)}),"%"]})})]}),S=K("app-region-no-drag flex items-center gap-1.5 select-none",u==="compact"?"typography-micro":"typography-meta",F?K("rounded-md px-2 py-1.5 text-foreground transition-colors","hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"):"text-muted-foreground/60",p),H=F?e.jsx("button",{type:"button",className:S,"aria-label":"Context usage","aria-pressed":L,onClick:M,children:v}):e.jsx("div",{className:S,"aria-label":"Context usage",onClick:l?()=>i(!0):void 0,children:v});return l?e.jsxs(e.Fragment,{children:[H,e.jsx(De,{open:b,onClose:()=>i(!1),title:"Context Usage",children:e.jsx("div",{className:"flex flex-col gap-1.5",children:e.jsxs("div",{className:"rounded-xl border border-border/40 bg-sidebar/30 px-3 py-2 space-y-1",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Used tokens"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(t)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Context limit"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(a)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Output limit"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(R)})]}),A?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache read"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(Z)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache write"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(B)})]})]}):null,O?e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache hit"}),e.jsxs("span",{className:"typography-meta text-foreground font-medium",children:[h.toFixed(1),"%"]})]}):null,e.jsxs("div",{className:"flex justify-between items-center pt-1 border-t border-border/40",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Usage"}),e.jsxs("span",{className:K("typography-meta font-semibold",N(g)),children:[Math.min(r,999).toFixed(1),"%"]})]})]})})})]}):e.jsxs(Pe,{children:[e.jsx(Me,{asChild:!0,children:H}),e.jsx(ke,{children:e.jsx("div",{className:"space-y-0.5",children:T.map(I=>e.jsx("p",{className:"typography-micro leading-tight",children:I},I))})})]})},ct=c.lazy(()=>rt(()=>import("./SessionSwitcherDropdown-Dpob2_y5.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(t=>({default:t.SessionSwitcherDropdown}))),lt=t=>{const r=typeof t=="string"?t.trim():"";if(!r)return"";const n=typeof window<"u"?window.__PICHAMBER_HOME__:"";if(n&&r===n)return"~";if(n&&r.startsWith(`${n}/`))return`~/${r.slice(n.length+1)}`;const a=r.split("/").filter(Boolean);return a.length<=3?r:`.../${a.slice(-3).join("/")}`},se=t=>{const r=typeof t=="string"?t.trim():"";if(!r)return"";const n=r.replace(/\\/g,"/");return n==="/"?"/":n.replace(/\/+$/,"")},dt=({mode:t})=>{const r=j(s=>s.currentSessionId),n=j(s=>!!s.newSessionDraft?.open),a=j(s=>s.newSessionDraft?.selectedProjectId??null),o=J(s=>s.currentDirectory),u=ae(s=>s.projects),l=ae(s=>s.getActiveProject()),D=P(s=>s.getCurrentModel),E=P(s=>s.providers),p=ce(),f=Le(r??""),_=Te(),M=Re(s=>s.ensureStatus),L=j(s=>s.newSessionDraft?.open?se(s.newSessionDraft.directoryOverride??""):""),[x,C]=c.useState(!1),h=typeof window<"u"?window.__PICHAMBER_MACOS_MAJOR__??0:0,b=Number.isFinite(h)&&h>0,i=Ae(),g=b?h>=26?"h-12":h<=15?"h-14":"":"",m=c.useMemo(()=>r?p.find(s=>s.id===r)??null:null,[r,p]);c.useEffect(()=>{ge()&&X("desktop_get_window_pinned").then(s=>{typeof s?.pinned=="boolean"&&C(s.pinned)})},[]);const y=m?.title?.trim()||(n||t==="draft"?"New session":"Session"),Y=se(m?.directory??null),w=se(o),N=Y||L||w,k=lt(N);c.useEffect(()=>{N&&M(N,_.git).catch(()=>{})},[M,N,_.git]);const $=c.useMemo(()=>{const s=N;return s?u.map(d=>({...d,normalizedPath:se(d.path)})).filter(d=>d.normalizedPath&&(d.normalizedPath===s||s.startsWith(`${d.normalizedPath}/`))).sort((d,G)=>G.path.length-d.path.length)[0]??null:null},[N,u]),W=c.useMemo(()=>{const s=$??l;if(!s)return k||"PiChamber";const d=s.label?.trim();return d||(s.path.split(/[\\/]/).filter(Boolean).at(-1)??s.path)},[l,k,$]),q=Be(N||null),R=q&&q!=="HEAD"?q:null,A=D(),Z=c.useMemo(()=>{for(let s=f.length-1;s>=0;s-=1){const d=f[s];if(d.role!=="assistant"||typeof d.providerID!="string"||typeof d.modelID!="string")continue;const te=E.find(Q=>Q.id===d.providerID)?.models.find(Q=>Q.id===d.modelID);if(te)return te}},[f,E]),B=A?.limit?A:Z,O=B&&typeof B.limit=="object"&&B.limit!==null?B.limit:null,T=O&&typeof O.context=="number"?O.context:0,F=O&&typeof O.output=="number"?O.output:0,v=c.useMemo(()=>{if(!r||f.length===0)return null;let s,d;for(let ne=f.length-1;ne>=0;ne-=1){const oe=f[ne];if(oe.role!=="assistant")continue;const z=oe.tokens;if(!z)continue;if(z.input+z.output+z.reasoning+(z.cache?.read??0)+(z.cache?.write??0)>0){s=z,d=oe.id;break}}if(!s)return null;const G=s.input+s.output+s.reasoning+(s.cache?.read??0)+(s.cache?.write??0),te=T>0?T:2e5,Q=T>0?Math.round(G/T*100):0,xe=F>0?Math.round(s.output/F*100):void 0;return{totalTokens:G,percentage:Q,contextLimit:T||0,outputLimit:F||void 0,normalizedOutput:xe,thresholdLimit:te,lastMessageId:d}},[T,r,f,F]),[S,H]=c.useState(null),I={WebkitAppRegion:"drag"},ee={WebkitAppRegion:"no-drag"};c.useEffect(()=>{if(!r){H(s=>s===null?s:null);return}if(v&&v.totalTokens>0){H(s=>s&&s.totalTokens===v.totalTokens&&s.percentage===v.percentage&&s.contextLimit===v.contextLimit&&(s.outputLimit??0)===(v.outputLimit??0)&&(s.normalizedOutput??0)===(v.normalizedOutput??0)&&s.thresholdLimit===v.thresholdLimit&&s.lastMessageId===v.lastMessageId?s:v);return}H(s=>s===null?s:null)},[v,r]);const fe=S&&S.contextLimit>0?Math.min(999,S.totalTokens/S.contextLimit*100):0,pe=c.useCallback(()=>{const s=!x;C(s),X("desktop_set_window_pinned",{pinned:s}).catch(()=>{C(!s)})},[x]),he=c.useCallback(()=>{const s=r?{sessionId:r,directory:m?.directory??o??""}:{mode:"draft",directory:N||o||"",projectId:a};X("desktop_focus_main_window",s).then(d=>d?.focused===!0?X("desktop_close_current_window"):null)},[o,r,a,N,m]);return e.jsxs("header",{className:K("flex items-center gap-3 bg-background pr-3",b?"pl-[5.5rem]":"pl-3",i?"h-12":g||"min-h-14"),style:I,children:[e.jsx(me.Suspense,{fallback:e.jsxs("button",{type:"button","aria-label":"Open session switcher",style:ee,className:"flex min-w-0 max-w-full flex-col items-start rounded-md px-1 py-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[e.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:y}),e.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[e.jsx("span",{className:"truncate",children:W}),R?e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[e.jsx(V,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"truncate",children:R})]}):null]})]}),children:e.jsx(ct,{children:e.jsxs("button",{type:"button","aria-label":"Open session switcher",style:ee,className:"flex min-w-0 max-w-full flex-col items-start rounded-md px-1 py-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[e.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:y}),e.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[e.jsx("span",{className:"truncate",children:W}),R?e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[e.jsx(V,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"truncate",children:R})]}):null]})]})})}),e.jsx("div",{className:"min-w-0 flex-1"}),S&&S.totalTokens>0?e.jsx(at,{totalTokens:S.totalTokens,percentage:fe,colorPercentage:S.percentage,contextLimit:S.contextLimit,outputLimit:S.outputLimit??0,className:"h-9 shrink-0 pl-1 pr-1 typography-ui-label",valueClassName:"font-semibold leading-none",hideIcon:!0,showPercentIcon:!0,percentIconClassName:"h-4.5 w-4.5"}):null,e.jsx(de,{type:"button",variant:"ghost",size:"icon",onClick:pe,"aria-label":x?"Unpin Mini Chat window":"Pin Mini Chat window",title:x?"Unpin window":"Pin above other windows",style:ee,children:x?e.jsx(V,{name:"pushpin-2-fill",className:"h-4 w-4"}):e.jsx(V,{name:"pushpin-2",className:"h-4 w-4"})}),e.jsx(de,{type:"button",variant:"ghost",size:"icon",onClick:he,"aria-label":"Open session in main window",title:"Open in main window",style:ee,children:e.jsx(V,{name:"external-link",className:"h-4 w-4"})}),e.jsx(Fe,{visible:i})]})},ut=({mode:t,autoOpenDraft:r=!1,unavailable:n=!1})=>{const a=j(o=>o.currentSessionId);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[e.jsx(dt,{mode:t}),e.jsx("main",{className:"min-h-0 flex-1",children:n?e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center typography-ui-label text-muted-foreground",children:e.jsxs("div",{className:"max-w-sm rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-4 py-3",children:[e.jsx("div",{className:"font-medium text-foreground",children:"Session unavailable"}),e.jsx("div",{className:"mt-1 typography-small text-muted-foreground",children:"This session could not be loaded. It may have been deleted, archived, or opened from a different project context."})]})}):e.jsx(nt,{mode:"mini-chat",children:e.jsx(Oe,{autoOpenDraft:r},a??"no-session")})})]})},mt=()=>{const t=ie(o=>o.shortcutOverrides),r=J(o=>o.currentDirectory),n=ae(o=>o.getActiveProject()),a=j(o=>o.openNewSessionDraft);c.useEffect(()=>{const o=l=>ve(l,t),u=l=>{if(U(l,o("focus_input"))){l.preventDefault(),ue();return}if(we()&&U(l,o("new_mini_chat"))){l.preventDefault(),X("desktop_open_draft_mini_chat_window",{directory:r||n?.path||"",projectId:n?.id??null})?.catch(p=>{console.warn("[mini-chat-shortcuts] failed to open draft mini chat window",p)});return}if(U(l,o("new_chat"))){l.preventDefault(),a({selectedProjectId:n?.id??null,directoryOverride:r||n?.path||null,preserveDirectoryOverride:!!(r||n?.path)}),ue();return}if(U(l,o("open_model_selector"))){l.preventDefault();const{isModelSelectorOpen:p,setModelSelectorOpen:f}=ie.getState();f(!p);return}if(U(l,o("cycle_thinking_variant"))){if(P.getState().getCurrentModelVariants().length===0)return;l.preventDefault(),ze(1).catch(()=>{Ue.error("Couldn't update thinking")});return}const D=U(l,o("cycle_favorite_model_forward")),E=U(l,o("cycle_favorite_model_backward"));if(D||E){const{favoriteModels:p,addRecentModel:f}=ie.getState();if(p.length===0)return;l.preventDefault();const{currentProviderId:_,currentModelId:M,setProvider:L,setModel:x}=P.getState(),C=p.findIndex(i=>i.providerID===_&&i.modelID===M),b=p[(C+(D?1:-1)+p.length)%p.length];L(b.providerID),x(b.modelID),f(b.providerID,b.modelID)}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n?.id,n?.path,r,a,t])},ft="pichamber:mini-chat-presence",pt=()=>{const t=typeof window<"u"?new URLSearchParams(window.location.search):new URLSearchParams,r=t.get("mode")==="session"?"session":"draft",n=t.get("sessionId")?.trim()||null,a=t.get("directory")?.trim()||null,o=t.get("projectId")?.trim()||null;return{mode:r,sessionId:n,directory:a,projectId:o}},ht=({config:t})=>{const r=ce(),n=J(i=>i.currentDirectory),a=J(i=>i.setDirectory),o=j(i=>i.currentSessionId),u=j(i=>!!i.newSessionDraft?.open),l=j(i=>i.newSessionDraft?.open?i.newSessionDraft.bootstrapPendingDirectory??i.newSessionDraft.directoryOverride??"":""),D=j(i=>i.setCurrentSession),E=j(i=>i.openNewSessionDraft),p=P(i=>i.initializeApp),f=P(i=>i.isInitialized),_=P(i=>i.isConnected),M=P(i=>i.loadProviders),L=P(i=>i.providers.length),x=Xe();c.useEffect(()=>{p()},[p]),c.useEffect(()=>{if(f)return;let i=!0,g=0;const m=window.setInterval(()=>{if(i){if(g+=1,g>10){window.clearInterval(m);return}P.getState().isInitialized||P.getState().initializeApp()}},1e3);return()=>{i=!1,window.clearInterval(m)}},[f]);const C=c.useRef(!1);c.useEffect(()=>{if(!C.current&&t.mode==="session"&&t.directory){if(n===t.directory){C.current=!0;return}a(t.directory,{showOverlay:!1}),C.current=!0}},[t.directory,t.mode,n,a]),c.useEffect(()=>{t.mode!=="draft"||!u||o||!l||n===l||a(l,{showOverlay:!1})},[t.mode,n,o,l,u,a]),c.useEffect(()=>{_&&L===0&&M({source:"electronMiniChat:recovery"})},[_,M,L]);const h=c.useRef(!1);c.useEffect(()=>{if(h.current||t.mode!=="session"||!t.sessionId)return;if(o===t.sessionId){h.current=!0;return}if(o){h.current=!0;return}const i=r.find(m=>m.id===t.sessionId);if(!i){x.ensureSessionRenderable(t.sessionId);return}const g=i.directory??t.directory;D(t.sessionId,g),h.current=!0},[t,o,r,D,x]),c.useEffect(()=>{const i=g=>{const m=g.detail,y=typeof m?.sessionId=="string"?m.sessionId.trim():"";if(!y||j.getState().currentSessionId===y)return;const Y=typeof m?.directory=="string"&&m.directory.trim().length>0?m.directory.trim():r.find(w=>w.id===y)?.directory??null;x.ensureSessionRenderable(y),D(y,Y),h.current=!0};return window.addEventListener("pichamber:open-session",i),()=>window.removeEventListener("pichamber:open-session",i)},[r,D,x]),c.useEffect(()=>{t.mode!=="draft"||u||o||E({selectedProjectId:t.projectId,directoryOverride:t.directory,preserveDirectoryOverride:!!t.directory})},[t,o,u,E]);const b=c.useRef(!1);return c.useEffect(()=>{if(b.current||!f)return;const i=()=>{if(b.current)return;b.current=!0;const y=typeof document<"u"?document.getElementById("initial-loading"):null;y&&(y.classList.add("fade-out"),window.setTimeout(()=>y.remove(),300))},g=t.mode==="session"?o===t.sessionId:u,m=window.setTimeout(i,g?100:1500);return()=>window.clearTimeout(m)},[f,t.mode,t.sessionId,o,u]),null},xt=()=>{const t=j(n=>n.currentSessionId),r=J(n=>n.currentDirectory);return c.useEffect(()=>{if(!t||!r||typeof BroadcastChannel>"u")return;const n=new BroadcastChannel(ft),a=l=>{n.postMessage({type:"mini-chat-session-presence",sessionId:t,directory:r,viewed:l})};a(!0);const o=window.setInterval(()=>a(!0),5e3),u=()=>a(!1);return window.addEventListener("beforeunload",u),()=>{window.clearInterval(o),window.removeEventListener("beforeunload",u),a(!1),n.close()}},[r,t]),null},yt=t=>{const r=ce(),n=j(u=>u.currentSessionId),[a,o]=c.useState(!1);return c.useEffect(()=>{if(t.mode!=="session"||!t.sessionId||n===t.sessionId){o(!1);return}if(r.some(l=>l.id===t.sessionId)){o(!1);return}const u=window.setTimeout(()=>o(!0),5e3);return()=>window.clearTimeout(u)},[t.mode,t.sessionId,n,r]),a};function gt({apis:t}){const r=c.useMemo(()=>pt(),[]),n=J(a=>a.currentDirectory);return c.useEffect(()=>{const a=n||r.directory;if(!a)return;const o=r.mode==="session"?{sessionId:r.sessionId,directory:r.directory}:null;$e().focusProject(a,Se(a,o))},[r.directory,r.mode,r.sessionId,n]),c.useEffect(()=>(le(t),()=>le(null)),[t]),We(),mt(),e.jsx(He,{children:e.jsx(Ge,{directory:n||r.directory,children:e.jsxs(Ke,{apis:t,children:[e.jsx(Ve,{}),e.jsx(Je,{delayDuration:300,skipDelayDuration:150,children:e.jsxs("div",{className:"h-full text-foreground bg-background",children:[e.jsx(wt,{config:r}),e.jsx(Ye,{}),e.jsx(qe,{})]})})]})})})}const wt=({config:t})=>{const r=yt(t);return e.jsxs(e.Fragment,{children:[e.jsx(ht,{config:t}),e.jsx(xt,{}),e.jsx(Qe,{embeddedBackgroundWorkEnabled:!0}),e.jsx(ut,{mode:t.mode,autoOpenDraft:t.mode==="draft",unavailable:r})]})},vt=()=>{(async()=>{try{await Promise.all([be(),Ie()])}catch(t){console.error("[mini-chat-main] settings init failed:",t)}tt(),st(),Ce()})()};function Tt(t){const r=t??je();if(!r)throw new Error("Runtime APIs not registered");vt();const n=document.getElementById("root");if(!n)throw new Error("Root element not found");ye.createRoot(n).render(e.jsx(me.StrictMode,{children:e.jsx(Ze,{children:e.jsx(et,{children:e.jsx(gt,{apis:r})})})}))}export{Tt as renderElectronMiniChatApp};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionSwitcherDropdown-BSutduo7.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-boot-EC6IyLt1.js","assets/vendor-react-DASdDPIk.js","assets/vendor-clsx-B-dksMZM.js","assets/useAppFontEffects-CqHhRKmN.js","assets/index-D4n3TVp2.js","assets/vendor-zustand-CUi8eEds.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/index-BwoW_-vk.css","assets/runtimeSurface-k1Eit61v.js","assets/nativeFileSave-BJsGPh58.js"])))=>i.map(i=>d[i]);
2
+ import{k as e,aN as ye}from"./vendor-boot-EC6IyLt1.js";import{R as c,a as me}from"./vendor-react-DASdDPIk.js";/* empty css */import{e as K,u as J,ay as ge,w as X,f as ie,au as U,L as we,O as ve,l as le,t as je,o as be}from"./index-D4n3TVp2.js";import{f as Se,a as Ie,s as Ce}from"./pi-session-focus-preference-BFnGFuvP.js";import{c2 as Ne,I as V,b6 as De,aj as Pe,ak as Me,am as ke,c3 as Ee,c4 as _e,h as j,bi as Oe,a as ae,O as P,aC as ce,c5 as Le,z as Te,aN as Re,bS as Ae,bF as Be,B as de,bW as Fe,c6 as ue,c7 as ze,t as Ue,g as $e,Y as We,E as He,_ as Ge,$ as Ke,a0 as Ve,a4 as Je,a6 as Ye,a7 as qe,c8 as Qe,bT as Xe,aa as Ze,ab as et,ac as tt,ad as st}from"./useAppFontEffects-CqHhRKmN.js";import{_ as rt}from"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CUi8eEds.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./runtimeSurface-k1Eit61v.js";import"./nativeFileSave-BJsGPh58.js";const nt=({mode:t,children:r})=>e.jsx(Ne.Provider,{value:t,children:r}),ot=Ee,it=_e,at=({totalTokens:t,percentage:r,colorPercentage:n,contextLimit:a,outputLimit:o,size:u="default",isMobile:l=!1,hideIcon:D=!1,showPercentIcon:E=!1,className:p,valueClassName:f,percentIconClassName:_,onClick:M,pressed:L=!1,cacheRead:x,cacheWrite:C,cacheHitPercent:h})=>{const[b,i]=c.useState(!1),g=typeof n=="number"?n:r,m=ot(r)??0,y=it(g),Y=y==="critical"?"var(--status-error)":y==="warn"?"var(--status-warning)":"var(--status-success)",w=I=>I>=1e6?`${(I/1e6).toFixed(1)}M`:I>=1e3?`${(I/1e3).toFixed(1)}K`:I.toFixed(1).replace(/\.0$/,""),N=I=>I>=90?"text-status-error":I>=75?"text-status-warning":"text-status-success",k=20,$=3,W=(k-$)/2,re=2*Math.PI*W,q=re*(1-m/100),R=typeof o=="number"?Math.max(o,0):0,A=typeof x=="number"&&typeof C=="number",Z=A?Math.max(0,x):0,B=A?Math.max(0,C):0,O=typeof h=="number"&&Number.isFinite(h),T=[`Used tokens: ${w(t)}`,`Context limit: ${w(a)}`,`Output limit: ${w(R)}`,...A?[`Cache read: ${w(Z)}`,`Cache write: ${w(B)}`]:[],...O?[`Cache hit: ${h.toFixed(1)}%`]:[],`${Math.min(r,999).toFixed(1)}% used`],F=!l&&typeof M=="function",v=e.jsxs(e.Fragment,{children:[!l&&!D&&e.jsx(V,{name:"donut-chart",className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:K("font-medium inline-flex items-center gap-1.5",f),children:E?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{viewBox:`0 0 ${k} ${k}`,className:K("h-3.5 w-3.5 -rotate-90",_),role:"progressbar","aria-valuenow":Math.round(m),"aria-valuemin":0,"aria-valuemax":100,children:[e.jsx("circle",{cx:k/2,cy:k/2,r:W,fill:"none",stroke:"var(--interactive-border)",strokeWidth:$}),e.jsx("circle",{cx:k/2,cy:k/2,r:W,fill:"none",stroke:Y,strokeWidth:$,strokeLinecap:"round",strokeDasharray:re,strokeDashoffset:q,className:"transition-[stroke-dashoffset,stroke] duration-300"})]}),e.jsxs("span",{className:"text-foreground",children:[Math.min(r,999).toFixed(1),"%"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:N(g),children:Math.min(r,999).toFixed(1)}),"%"]})})]}),S=K("app-region-no-drag flex items-center gap-1.5 select-none",u==="compact"?"typography-micro":"typography-meta",F?K("rounded-md px-2 py-1.5 text-foreground transition-colors","hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"):"text-muted-foreground/60",p),H=F?e.jsx("button",{type:"button",className:S,"aria-label":"Context usage","aria-pressed":L,onClick:M,children:v}):e.jsx("div",{className:S,"aria-label":"Context usage",onClick:l?()=>i(!0):void 0,children:v});return l?e.jsxs(e.Fragment,{children:[H,e.jsx(De,{open:b,onClose:()=>i(!1),title:"Context Usage",children:e.jsx("div",{className:"flex flex-col gap-1.5",children:e.jsxs("div",{className:"rounded-xl border border-border/40 bg-sidebar/30 px-3 py-2 space-y-1",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Used tokens"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(t)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Context limit"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(a)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Output limit"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(R)})]}),A?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache read"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(Z)})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache write"}),e.jsx("span",{className:"typography-meta text-foreground font-medium",children:w(B)})]})]}):null,O?e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Cache hit"}),e.jsxs("span",{className:"typography-meta text-foreground font-medium",children:[h.toFixed(1),"%"]})]}):null,e.jsxs("div",{className:"flex justify-between items-center pt-1 border-t border-border/40",children:[e.jsx("span",{className:"typography-meta text-muted-foreground",children:"Usage"}),e.jsxs("span",{className:K("typography-meta font-semibold",N(g)),children:[Math.min(r,999).toFixed(1),"%"]})]})]})})})]}):e.jsxs(Pe,{children:[e.jsx(Me,{asChild:!0,children:H}),e.jsx(ke,{children:e.jsx("div",{className:"space-y-0.5",children:T.map(I=>e.jsx("p",{className:"typography-micro leading-tight",children:I},I))})})]})},ct=c.lazy(()=>rt(()=>import("./SessionSwitcherDropdown-BSutduo7.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(t=>({default:t.SessionSwitcherDropdown}))),lt=t=>{const r=typeof t=="string"?t.trim():"";if(!r)return"";const n=typeof window<"u"?window.__PICHAMBER_HOME__:"";if(n&&r===n)return"~";if(n&&r.startsWith(`${n}/`))return`~/${r.slice(n.length+1)}`;const a=r.split("/").filter(Boolean);return a.length<=3?r:`.../${a.slice(-3).join("/")}`},se=t=>{const r=typeof t=="string"?t.trim():"";if(!r)return"";const n=r.replace(/\\/g,"/");return n==="/"?"/":n.replace(/\/+$/,"")},dt=({mode:t})=>{const r=j(s=>s.currentSessionId),n=j(s=>!!s.newSessionDraft?.open),a=j(s=>s.newSessionDraft?.selectedProjectId??null),o=J(s=>s.currentDirectory),u=ae(s=>s.projects),l=ae(s=>s.getActiveProject()),D=P(s=>s.getCurrentModel),E=P(s=>s.providers),p=ce(),f=Le(r??""),_=Te(),M=Re(s=>s.ensureStatus),L=j(s=>s.newSessionDraft?.open?se(s.newSessionDraft.directoryOverride??""):""),[x,C]=c.useState(!1),h=typeof window<"u"?window.__PICHAMBER_MACOS_MAJOR__??0:0,b=Number.isFinite(h)&&h>0,i=Ae(),g=b?h>=26?"h-12":h<=15?"h-14":"":"",m=c.useMemo(()=>r?p.find(s=>s.id===r)??null:null,[r,p]);c.useEffect(()=>{ge()&&X("desktop_get_window_pinned").then(s=>{typeof s?.pinned=="boolean"&&C(s.pinned)})},[]);const y=m?.title?.trim()||(n||t==="draft"?"New session":"Session"),Y=se(m?.directory??null),w=se(o),N=Y||L||w,k=lt(N);c.useEffect(()=>{N&&M(N,_.git).catch(()=>{})},[M,N,_.git]);const $=c.useMemo(()=>{const s=N;return s?u.map(d=>({...d,normalizedPath:se(d.path)})).filter(d=>d.normalizedPath&&(d.normalizedPath===s||s.startsWith(`${d.normalizedPath}/`))).sort((d,G)=>G.path.length-d.path.length)[0]??null:null},[N,u]),W=c.useMemo(()=>{const s=$??l;if(!s)return k||"PiChamber";const d=s.label?.trim();return d||(s.path.split(/[\\/]/).filter(Boolean).at(-1)??s.path)},[l,k,$]),q=Be(N||null),R=q&&q!=="HEAD"?q:null,A=D(),Z=c.useMemo(()=>{for(let s=f.length-1;s>=0;s-=1){const d=f[s];if(d.role!=="assistant"||typeof d.providerID!="string"||typeof d.modelID!="string")continue;const te=E.find(Q=>Q.id===d.providerID)?.models.find(Q=>Q.id===d.modelID);if(te)return te}},[f,E]),B=A?.limit?A:Z,O=B&&typeof B.limit=="object"&&B.limit!==null?B.limit:null,T=O&&typeof O.context=="number"?O.context:0,F=O&&typeof O.output=="number"?O.output:0,v=c.useMemo(()=>{if(!r||f.length===0)return null;let s,d;for(let ne=f.length-1;ne>=0;ne-=1){const oe=f[ne];if(oe.role!=="assistant")continue;const z=oe.tokens;if(!z)continue;if(z.input+z.output+z.reasoning+(z.cache?.read??0)+(z.cache?.write??0)>0){s=z,d=oe.id;break}}if(!s)return null;const G=s.input+s.output+s.reasoning+(s.cache?.read??0)+(s.cache?.write??0),te=T>0?T:2e5,Q=T>0?Math.round(G/T*100):0,xe=F>0?Math.round(s.output/F*100):void 0;return{totalTokens:G,percentage:Q,contextLimit:T||0,outputLimit:F||void 0,normalizedOutput:xe,thresholdLimit:te,lastMessageId:d}},[T,r,f,F]),[S,H]=c.useState(null),I={WebkitAppRegion:"drag"},ee={WebkitAppRegion:"no-drag"};c.useEffect(()=>{if(!r){H(s=>s===null?s:null);return}if(v&&v.totalTokens>0){H(s=>s&&s.totalTokens===v.totalTokens&&s.percentage===v.percentage&&s.contextLimit===v.contextLimit&&(s.outputLimit??0)===(v.outputLimit??0)&&(s.normalizedOutput??0)===(v.normalizedOutput??0)&&s.thresholdLimit===v.thresholdLimit&&s.lastMessageId===v.lastMessageId?s:v);return}H(s=>s===null?s:null)},[v,r]);const fe=S&&S.contextLimit>0?Math.min(999,S.totalTokens/S.contextLimit*100):0,pe=c.useCallback(()=>{const s=!x;C(s),X("desktop_set_window_pinned",{pinned:s}).catch(()=>{C(!s)})},[x]),he=c.useCallback(()=>{const s=r?{sessionId:r,directory:m?.directory??o??""}:{mode:"draft",directory:N||o||"",projectId:a};X("desktop_focus_main_window",s).then(d=>d?.focused===!0?X("desktop_close_current_window"):null)},[o,r,a,N,m]);return e.jsxs("header",{className:K("flex items-center gap-3 bg-background pr-3",b?"pl-[5.5rem]":"pl-3",i?"h-12":g||"min-h-14"),style:I,children:[e.jsx(me.Suspense,{fallback:e.jsxs("button",{type:"button","aria-label":"Open session switcher",style:ee,className:"flex min-w-0 max-w-full flex-col items-start rounded-md px-1 py-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[e.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:y}),e.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[e.jsx("span",{className:"truncate",children:W}),R?e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[e.jsx(V,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"truncate",children:R})]}):null]})]}),children:e.jsx(ct,{children:e.jsxs("button",{type:"button","aria-label":"Open session switcher",style:ee,className:"flex min-w-0 max-w-full flex-col items-start rounded-md px-1 py-0.5 text-left transition-colors hover:bg-interactive-hover/60 focus-visible:outline-none focus-visible:bg-interactive-hover/60",children:[e.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:y}),e.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[e.jsx("span",{className:"truncate",children:W}),R?e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[e.jsx(V,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),e.jsx("span",{className:"truncate",children:R})]}):null]})]})})}),e.jsx("div",{className:"min-w-0 flex-1"}),S&&S.totalTokens>0?e.jsx(at,{totalTokens:S.totalTokens,percentage:fe,colorPercentage:S.percentage,contextLimit:S.contextLimit,outputLimit:S.outputLimit??0,className:"h-9 shrink-0 pl-1 pr-1 typography-ui-label",valueClassName:"font-semibold leading-none",hideIcon:!0,showPercentIcon:!0,percentIconClassName:"h-4.5 w-4.5"}):null,e.jsx(de,{type:"button",variant:"ghost",size:"icon",onClick:pe,"aria-label":x?"Unpin Mini Chat window":"Pin Mini Chat window",title:x?"Unpin window":"Pin above other windows",style:ee,children:x?e.jsx(V,{name:"pushpin-2-fill",className:"h-4 w-4"}):e.jsx(V,{name:"pushpin-2",className:"h-4 w-4"})}),e.jsx(de,{type:"button",variant:"ghost",size:"icon",onClick:he,"aria-label":"Open session in main window",title:"Open in main window",style:ee,children:e.jsx(V,{name:"external-link",className:"h-4 w-4"})}),e.jsx(Fe,{visible:i})]})},ut=({mode:t,autoOpenDraft:r=!1,unavailable:n=!1})=>{const a=j(o=>o.currentSessionId);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background text-foreground",children:[e.jsx(dt,{mode:t}),e.jsx("main",{className:"min-h-0 flex-1",children:n?e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center typography-ui-label text-muted-foreground",children:e.jsxs("div",{className:"max-w-sm rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-4 py-3",children:[e.jsx("div",{className:"font-medium text-foreground",children:"Session unavailable"}),e.jsx("div",{className:"mt-1 typography-small text-muted-foreground",children:"This session could not be loaded. It may have been deleted, archived, or opened from a different project context."})]})}):e.jsx(nt,{mode:"mini-chat",children:e.jsx(Oe,{autoOpenDraft:r},a??"no-session")})})]})},mt=()=>{const t=ie(o=>o.shortcutOverrides),r=J(o=>o.currentDirectory),n=ae(o=>o.getActiveProject()),a=j(o=>o.openNewSessionDraft);c.useEffect(()=>{const o=l=>ve(l,t),u=l=>{if(U(l,o("focus_input"))){l.preventDefault(),ue();return}if(we()&&U(l,o("new_mini_chat"))){l.preventDefault(),X("desktop_open_draft_mini_chat_window",{directory:r||n?.path||"",projectId:n?.id??null})?.catch(p=>{console.warn("[mini-chat-shortcuts] failed to open draft mini chat window",p)});return}if(U(l,o("new_chat"))){l.preventDefault(),a({selectedProjectId:n?.id??null,directoryOverride:r||n?.path||null,preserveDirectoryOverride:!!(r||n?.path)}),ue();return}if(U(l,o("open_model_selector"))){l.preventDefault();const{isModelSelectorOpen:p,setModelSelectorOpen:f}=ie.getState();f(!p);return}if(U(l,o("cycle_thinking_variant"))){if(P.getState().getCurrentModelVariants().length===0)return;l.preventDefault(),ze(1).catch(()=>{Ue.error("Couldn't update thinking")});return}const D=U(l,o("cycle_favorite_model_forward")),E=U(l,o("cycle_favorite_model_backward"));if(D||E){const{favoriteModels:p,addRecentModel:f}=ie.getState();if(p.length===0)return;l.preventDefault();const{currentProviderId:_,currentModelId:M,setProvider:L,setModel:x}=P.getState(),C=p.findIndex(i=>i.providerID===_&&i.modelID===M),b=p[(C+(D?1:-1)+p.length)%p.length];L(b.providerID),x(b.modelID),f(b.providerID,b.modelID)}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[n?.id,n?.path,r,a,t])},ft="pichamber:mini-chat-presence",pt=()=>{const t=typeof window<"u"?new URLSearchParams(window.location.search):new URLSearchParams,r=t.get("mode")==="session"?"session":"draft",n=t.get("sessionId")?.trim()||null,a=t.get("directory")?.trim()||null,o=t.get("projectId")?.trim()||null;return{mode:r,sessionId:n,directory:a,projectId:o}},ht=({config:t})=>{const r=ce(),n=J(i=>i.currentDirectory),a=J(i=>i.setDirectory),o=j(i=>i.currentSessionId),u=j(i=>!!i.newSessionDraft?.open),l=j(i=>i.newSessionDraft?.open?i.newSessionDraft.bootstrapPendingDirectory??i.newSessionDraft.directoryOverride??"":""),D=j(i=>i.setCurrentSession),E=j(i=>i.openNewSessionDraft),p=P(i=>i.initializeApp),f=P(i=>i.isInitialized),_=P(i=>i.isConnected),M=P(i=>i.loadProviders),L=P(i=>i.providers.length),x=Xe();c.useEffect(()=>{p()},[p]),c.useEffect(()=>{if(f)return;let i=!0,g=0;const m=window.setInterval(()=>{if(i){if(g+=1,g>10){window.clearInterval(m);return}P.getState().isInitialized||P.getState().initializeApp()}},1e3);return()=>{i=!1,window.clearInterval(m)}},[f]);const C=c.useRef(!1);c.useEffect(()=>{if(!C.current&&t.mode==="session"&&t.directory){if(n===t.directory){C.current=!0;return}a(t.directory,{showOverlay:!1}),C.current=!0}},[t.directory,t.mode,n,a]),c.useEffect(()=>{t.mode!=="draft"||!u||o||!l||n===l||a(l,{showOverlay:!1})},[t.mode,n,o,l,u,a]),c.useEffect(()=>{_&&L===0&&M({source:"electronMiniChat:recovery"})},[_,M,L]);const h=c.useRef(!1);c.useEffect(()=>{if(h.current||t.mode!=="session"||!t.sessionId)return;if(o===t.sessionId){h.current=!0;return}if(o){h.current=!0;return}const i=r.find(m=>m.id===t.sessionId);if(!i){x.ensureSessionRenderable(t.sessionId);return}const g=i.directory??t.directory;D(t.sessionId,g),h.current=!0},[t,o,r,D,x]),c.useEffect(()=>{const i=g=>{const m=g.detail,y=typeof m?.sessionId=="string"?m.sessionId.trim():"";if(!y||j.getState().currentSessionId===y)return;const Y=typeof m?.directory=="string"&&m.directory.trim().length>0?m.directory.trim():r.find(w=>w.id===y)?.directory??null;x.ensureSessionRenderable(y),D(y,Y),h.current=!0};return window.addEventListener("pichamber:open-session",i),()=>window.removeEventListener("pichamber:open-session",i)},[r,D,x]),c.useEffect(()=>{t.mode!=="draft"||u||o||E({selectedProjectId:t.projectId,directoryOverride:t.directory,preserveDirectoryOverride:!!t.directory})},[t,o,u,E]);const b=c.useRef(!1);return c.useEffect(()=>{if(b.current||!f)return;const i=()=>{if(b.current)return;b.current=!0;const y=typeof document<"u"?document.getElementById("initial-loading"):null;y&&(y.classList.add("fade-out"),window.setTimeout(()=>y.remove(),300))},g=t.mode==="session"?o===t.sessionId:u,m=window.setTimeout(i,g?100:1500);return()=>window.clearTimeout(m)},[f,t.mode,t.sessionId,o,u]),null},xt=()=>{const t=j(n=>n.currentSessionId),r=J(n=>n.currentDirectory);return c.useEffect(()=>{if(!t||!r||typeof BroadcastChannel>"u")return;const n=new BroadcastChannel(ft),a=l=>{n.postMessage({type:"mini-chat-session-presence",sessionId:t,directory:r,viewed:l})};a(!0);const o=window.setInterval(()=>a(!0),5e3),u=()=>a(!1);return window.addEventListener("beforeunload",u),()=>{window.clearInterval(o),window.removeEventListener("beforeunload",u),a(!1),n.close()}},[r,t]),null},yt=t=>{const r=ce(),n=j(u=>u.currentSessionId),[a,o]=c.useState(!1);return c.useEffect(()=>{if(t.mode!=="session"||!t.sessionId||n===t.sessionId){o(!1);return}if(r.some(l=>l.id===t.sessionId)){o(!1);return}const u=window.setTimeout(()=>o(!0),5e3);return()=>window.clearTimeout(u)},[t.mode,t.sessionId,n,r]),a};function gt({apis:t}){const r=c.useMemo(()=>pt(),[]),n=J(a=>a.currentDirectory);return c.useEffect(()=>{const a=n||r.directory;if(!a)return;const o=r.mode==="session"?{sessionId:r.sessionId,directory:r.directory}:null;$e().focusProject(a,Se(a,o))},[r.directory,r.mode,r.sessionId,n]),c.useEffect(()=>(le(t),()=>le(null)),[t]),We(),mt(),e.jsx(He,{children:e.jsx(Ge,{directory:n||r.directory,children:e.jsxs(Ke,{apis:t,children:[e.jsx(Ve,{}),e.jsx(Je,{delayDuration:300,skipDelayDuration:150,children:e.jsxs("div",{className:"h-full text-foreground bg-background",children:[e.jsx(wt,{config:r}),e.jsx(Ye,{}),e.jsx(qe,{})]})})]})})})}const wt=({config:t})=>{const r=yt(t);return e.jsxs(e.Fragment,{children:[e.jsx(ht,{config:t}),e.jsx(xt,{}),e.jsx(Qe,{embeddedBackgroundWorkEnabled:!0}),e.jsx(ut,{mode:t.mode,autoOpenDraft:t.mode==="draft",unavailable:r})]})},vt=()=>{(async()=>{try{await Promise.all([be(),Ie()])}catch(t){console.error("[mini-chat-main] settings init failed:",t)}tt(),st(),Ce()})()};function Tt(t){const r=t??je();if(!r)throw new Error("Runtime APIs not registered");vt();const n=document.getElementById("root");if(!n)throw new Error("Root element not found");ye.createRoot(n).render(e.jsx(me.StrictMode,{children:e.jsx(Ze,{children:e.jsx(et,{children:e.jsx(gt,{apis:r})})})}))}export{Tt as renderElectronMiniChatApp};
@@ -1 +1 @@
1
- import{t as I}from"./themeResolver-yJ9XpNMI.js";import{b as R,i as y,j as k,k as A,l as S,m as T}from"./computeVirtualFileMetrics-8mC_o5zA.js";import{ci as _}from"./useAppFontEffects-BQ1JUauS.js";function w(e){return I.hasResolvedThemes(e)}function z(e,t){return R(e.theme,t.theme)&&e.useTokenTransformer===t.useTokenTransformer&&e.tokenizeMaxLineLength===t.tokenizeMaxLineLength}function D(e){return(e.lang??y(e.name))==="text"}const d=10,g=13;function N(e){const t=[0];for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);(r===d||r===g)&&(r===g&&n+1<e.length&&e.charCodeAt(n+1)===d&&n++,t.push(n+1))}return t}function P(e){const t=N(e);return Array.from({length:t.length},(n,r)=>{const i=t[r],s=t[r+1]??e.length;return e.slice(i,s)})}const b={forcePlainText:!1};function M(e,t,{theme:n=_,tokenizeMaxLineLength:r,useTokenTransformer:i},{forcePlainText:s,startingLine:o,totalLines:a,lines:E}=b){s?(o??=0,a??=1/0):(o=0,a=1/0);const f=o>0||a<1/0,{state:F,transformers:l}=k(i),c=s?"text":e.lang??y(e.name),x=typeof n=="string"?t.getTheme(n).type:void 0,p=A({theme:n,highlighter:t});F.lineInfo=u=>({type:"context",lineIndex:u-1+o,lineNumber:u+o});const C=typeof n=="string"?{lang:c,theme:n,transformers:l,defaultColor:!1,cssVariablePrefix:T("token"),tokenizeMaxLineLength:r,tokenizeTimeLimit:0}:{lang:c,themes:n,transformers:l,defaultColor:!1,cssVariablePrefix:T("token"),tokenizeMaxLineLength:r,tokenizeTimeLimit:0},m=S(t.codeToHast(f?H(E??P(e.contents),o,a):e.contents,C)),h=f?new Array(o):m;return f&&h.push(...m),{code:h,themeStyles:p,baseThemeType:x}}function H(e,t,n){if(e.length===0)return"";const r=Math.min(t+n,e.length);return e.slice(t,r).join("")}export{z as a,w as h,D as i,P as l,M as r};
1
+ import{t as I}from"./themeResolver-yJ9XpNMI.js";import{b as R,i as y,j as k,k as A,l as S,m as T}from"./computeVirtualFileMetrics-Bjhk2CQS.js";import{ci as _}from"./useAppFontEffects-CqHhRKmN.js";function w(e){return I.hasResolvedThemes(e)}function z(e,t){return R(e.theme,t.theme)&&e.useTokenTransformer===t.useTokenTransformer&&e.tokenizeMaxLineLength===t.tokenizeMaxLineLength}function D(e){return(e.lang??y(e.name))==="text"}const d=10,g=13;function N(e){const t=[0];for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);(r===d||r===g)&&(r===g&&n+1<e.length&&e.charCodeAt(n+1)===d&&n++,t.push(n+1))}return t}function P(e){const t=N(e);return Array.from({length:t.length},(n,r)=>{const i=t[r],s=t[r+1]??e.length;return e.slice(i,s)})}const b={forcePlainText:!1};function M(e,t,{theme:n=_,tokenizeMaxLineLength:r,useTokenTransformer:i},{forcePlainText:s,startingLine:o,totalLines:a,lines:E}=b){s?(o??=0,a??=1/0):(o=0,a=1/0);const f=o>0||a<1/0,{state:F,transformers:l}=k(i),c=s?"text":e.lang??y(e.name),x=typeof n=="string"?t.getTheme(n).type:void 0,p=A({theme:n,highlighter:t});F.lineInfo=u=>({type:"context",lineIndex:u-1+o,lineNumber:u+o});const C=typeof n=="string"?{lang:c,theme:n,transformers:l,defaultColor:!1,cssVariablePrefix:T("token"),tokenizeMaxLineLength:r,tokenizeTimeLimit:0}:{lang:c,themes:n,transformers:l,defaultColor:!1,cssVariablePrefix:T("token"),tokenizeMaxLineLength:r,tokenizeTimeLimit:0},m=S(t.codeToHast(f?H(E??P(e.contents),o,a):e.contents,C)),h=f?new Array(o):m;return f&&h.push(...m),{code:h,themeStyles:p,baseThemeType:x}}function H(e,t,n){if(e.length===0)return"";const r=Math.min(t+n,e.length);return e.slice(t,r).join("")}export{z as a,w as h,D as i,P as l,M as r};