@baique/pi-web-sky 0.1.21 → 0.1.22

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 (54) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +6 -6
  3. package/.next/build-manifest.json +3 -3
  4. package/.next/prerender-manifest.json +3 -3
  5. package/.next/react-loadable-manifest.json +1 -1
  6. package/.next/required-server-files.js +2 -2
  7. package/.next/required-server-files.json +2 -2
  8. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  9. package/.next/server/app/_global-error.html +1 -1
  10. package/.next/server/app/_global-error.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  12. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  15. package/.next/server/app/_not-found.html +1 -1
  16. package/.next/server/app/_not-found.rsc +3 -3
  17. package/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
  18. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +3 -3
  19. package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  20. package/.next/server/app/api/app-update/route.js +1 -1
  21. package/.next/server/app/api/terminal/[id]/events/route.js +2 -2
  22. package/.next/server/app/api/terminal/[id]/route.js +2 -2
  23. package/.next/server/app/api/terminal/route.js +2 -2
  24. package/.next/server/app/index.html +1 -1
  25. package/.next/server/app/index.rsc +5 -5
  26. package/.next/server/app/index.segments/__PAGE__.segment.rsc +5 -5
  27. package/.next/server/app/index.segments/_full.segment.rsc +5 -5
  28. package/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  29. package/.next/server/app/page.js +8 -8
  30. package/.next/server/app/page_client-reference-manifest.js +1 -1
  31. package/.next/server/app-paths-manifest.json +6 -6
  32. package/.next/server/middleware-build-manifest.js +1 -1
  33. package/.next/server/middleware-react-loadable-manifest.js +1 -1
  34. package/.next/server/pages/404.html +1 -1
  35. package/.next/server/pages/500.html +1 -1
  36. package/.next/server/server-reference-manifest.json +1 -1
  37. package/.next/static/chunks/3266.326b3add50989a80.js +1 -0
  38. package/.next/static/chunks/app/{layout-ef2f232cb7bda98e.js → layout-2d6062b4d60dd1c3.js} +1 -1
  39. package/.next/static/chunks/app/page-92d0d95f72a5d97d.js +89 -0
  40. package/.next/static/chunks/{webpack-8cc41c498e5b9a1b.js → webpack-053051d7a3c7b828.js} +1 -1
  41. package/.next/static/css/40cb1c7aeb554298.css +1 -0
  42. package/.next/trace +7 -7
  43. package/.next/trace-build +1 -1
  44. package/README.md +6 -2
  45. package/README.zh-CN.md +2 -1
  46. package/package.json +1 -1
  47. package/public/icons/apple-touch-icon.png +0 -0
  48. package/public/icons/icon-192.png +0 -0
  49. package/public/icons/icon-512.png +0 -0
  50. package/.next/static/chunks/3266.4c722f2677595a04.js +0 -1
  51. package/.next/static/chunks/app/page-a99fc55e6eb5ac35.js +0 -89
  52. package/.next/static/css/ad464d16f922f5b9.css +0 -1
  53. /package/.next/static/{pSndmMVwteDd_0Jo8BldA → A7L3-CYh2X502BUR-cjfb}/_buildManifest.js +0 -0
  54. /package/.next/static/{pSndmMVwteDd_0Jo8BldA → A7L3-CYh2X502BUR-cjfb}/_ssgManifest.js +0 -0
@@ -0,0 +1,89 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8974],{14755:(e,t,r)=>{"use strict";r.d(t,{getPresetFromTools:()=>c,sn:()=>d,xG:()=>u});let n=["none","read-only","default","full"],i=[],o=["read","grep","find","ls"],l=["read","bash","edit","write"],a=["bash","read","edit","write","grep","find","ls"],s=new Set(a);function d(e){return"string"==typeof e&&n.includes(e)}function c(e){let t=e.filter(e=>e.active);if(0===t.length)return"none";let r=t.map(e=>e.name).filter(e=>s.has(e)).sort().join(",");return r===[...o].sort().join(",")?"read-only":r===[...l].sort().join(",")?"default":r===[...a].sort().join(",")?"full":"default"}function u(e){return"none"===e?[...i]:"read-only"===e?[...o]:"full"===e?[...a]:[...l]}},31590:(e,t,r)=>{"use strict";r.d(t,{a:()=>s});var n=r(12115);let i="(max-width: 640px)";function o(e){if(!window.matchMedia)return()=>{};let t=window.matchMedia(i);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)}function l(){return!!window.matchMedia&&window.matchMedia(i).matches}function a(){return!1}function s(){return(0,n.useSyncExternalStore)(o,l,a)}},39247:(e,t,r)=>{"use strict";r.d(t,{I18nProvider:()=>c,s:()=>u});var n=r(95155),i=r(12115);let o=new Map;function l(e){if(!e.id.trim())throw Error("Locale id must not be empty");if(o.has(e.id))throw Error(`Locale already registered: ${e.id}`);o.set(e.id,e)}function a(){return[...o.keys()]}l({id:"en",label:"English",messages:{"common.ok":"OK","common.language":"Language","common.models":"Models","common.skills":"Skills","common.plugins":"Plugins","appUpdate.releaseNotes":"Pi Web v{version} is available. View release notes","sidebar.hide":"Hide sidebar","sidebar.show":"Show sidebar","theme.light":"Light mode (click for dark)","theme.dark":"Dark mode (click for system)","theme.auto":"System theme (click for light)","history.full":"Full history","history.unsaved":"Full history is available after the session is saved","history.label":"Full history","title.generating":"Generating...","title.updated":"Title updated","title.failed":"Generation failed","title.generate":"Generate title","title.unsaved":"Title generation is available after the session is saved","title.noMessages":"Send a message before naming this session","title.generateSession":"Generate a session title","system.prompt":"System prompt","system.empty":"System prompt is empty (tools are disabled)","system.load":"System prompt has not loaded yet","system.loading":"Loading system prompt…","system.label":"System","session.info":"Session info","session.name":"Name","session.file":"File","session.inMemory":"In-memory","session.id":"ID","session.user":"User","session.assistant":"Assistant","session.toolCalls":"Tool Calls","session.toolResults":"Tool Results","session.total":"Total","session.input":"Input","session.output":"Output","session.cacheRead":"Cache Read","session.cacheWrite":"Cache Write","session.cost":"Cost","session.context":"Context","session.cacheHitRate":"Avg cache hit rate","session.copy":"Copy {value}","session.copied":"Copied","session.title":"Session info","session.load":"Send a message or run /session to load session info","session.infoSection":"Session Info","session.messages":"Messages","session.tokens":"Tokens","session.totalActive":"Active Time","session.copyFile":"Copy file path","session.copyId":"Copy session ID","workspace.opening":"Opening workspace...","workspace.unable":"Unable to open workspace","workspace.selectSession":"Select a session from the sidebar","workspace.getStarted":"Get Started","workspace.selectProject":"Select a project directory from the sidebar","workspace.addModels":"Add models via the Models button at the bottom","workspace.stepProject":"Select a project directory from the sidebar","workspace.stepModels":"Add models via the Models button at the bottom","files.hidePanel":"Hide file panel","files.showPanel":"Show file panel","files.noneOpen":"No file open","layout.resizeSidebar":"Resize sidebar","layout.resizeFilePanel":"Resize file panel","layout.resizeHint":"Drag to resize. Double-click or press Enter to reset.","sidebar.new":"New","sidebar.newSessionTitle":"New session in {path}","sidebar.refresh":"Refresh","sidebar.selectProject":"Select project…","sidebar.filterProjects":"Filter projects…","sidebar.noMatchingProjects":"No matching projects","sidebar.useDefaultDirectory":"Use default directory","sidebar.customPath":"Custom path…","directoryPicker.selectDirectory":"Select directory","directoryPicker.goToParent":"Go to parent directory","directoryPicker.directoryPath":"Directory path","directoryPicker.goToDirectory":"Go to directory","directoryPicker.go":"Go","directoryPicker.loadingDirectories":"Loading directories…","directoryPicker.noSubdirectories":"No subdirectories","directoryPicker.openBeforeSelecting":"Open this path before selecting it","directoryPicker.selectCurrentDirectory":"Select current directory","directoryPicker.selectThisFolder":"Select this folder","directoryPicker.noDrives":"No drives found","sidebar.checking":"Checking…","sidebar.open":"Open","sidebar.cancel":"Cancel","sidebar.openRepoRoot":"Open repo root","sidebar.openRepoRootTitle":"Open the repository root to manage worktrees.","sidebar.gitRepoRootOnly":"Git repo root only","sidebar.gitRepoRootOnlyTitle":"Worktrees are available in Git repository roots.","sidebar.worktrees":"Worktrees...","sidebar.checkingWorktrees":"Checking worktrees for this directory.","sidebar.filterWorktrees":"Filter worktrees…","sidebar.noMatchingWorktrees":"No matching worktrees","sidebar.switchWorktree":"Switch worktree","sidebar.switchWorktreeTitle":"Switch worktree: {path}","sidebar.main":"main","sidebar.forceRemoveCheckout":"Uncommitted changes. Force remove checkout?","sidebar.force":"Force","sidebar.createWorktreeTitle":"Create a worktree checkout for a branch","sidebar.newWorktree":"New worktree…","sidebar.branchName":"branch name","sidebar.creating":"Creating…","sidebar.create":"Create","sidebar.uploadFilesTitle":"Upload files to project root","sidebar.uploadFiles":"Upload files","sidebar.refreshExplorer":"Refresh explorer","sidebar.changedFiles":"{count} changed files","sidebar.loading":"Loading...","sidebar.noSessions":"No sessions found","sidebar.agentRunning":"Agent running…","sidebar.newActivity":"New activity","sidebar.newSessionActivity":"New session activity","sidebar.deleteSession":"Delete {title}?","sidebar.rename":"Rename","sidebar.delete":"Delete","sidebar.deleteWithShiftClick":"Delete (Shift+click to delete without confirmation)","sidebar.expandForks":"Expand forks","sidebar.collapseForks":"Collapse forks","sidebar.messagesCount":"{count} msgs","sidebar.worktreePath":"Worktree: {path}","sidebar.removeWorktreeTitle":"Remove worktree checkout {path}; the branch is kept","files.modified":"Modified","files.added":"Added","files.deleted":"Deleted","files.renamed":"Renamed","files.untracked":"Untracked","files.conflict":"Conflict","files.newlyUploaded":"Newly uploaded","files.containsChangedFiles":"Contains changed files","files.insertPath":"Insert path into chat","files.mention":"mention","files.download":"Download file","files.dismissError":"Dismiss error","files.addUploadedFile":"Add uploaded file to chat","files.addAllUploadedFiles":"Add all uploaded files to chat","files.dismissUploadResults":"Dismiss upload results","files.loading":"Loading files...","files.noFiles":"No files found","files.explorer":"Explorer","files.changedCount":"{count} files","files.changeStats":"{count} changed files, {additions} lines added, {deletions} lines deleted","files.conflictSummary":"{count} file{countSuffix} already exist: {files}","files.cannotReplace":"Cannot replace: {files}","files.replace":"Replace","files.skipExisting":"Skip existing","files.cancel":"Cancel","files.checking":"Checking files","files.uploading":"Uploading, {progress}%","chat.loadingSession":"Loading session...","chat.runningTool":"Running tool...","chat.generatingToolInput":"Generating parameters...","chat.runningNamedTool":"Running {name}...","chat.runningTools":"Running {names}...","chat.runningToolsMore":"Running {names} (+{count})...","chat.waitingModel":"Waiting for model...","chat.runningCommand":"Running command...","chat.thinking":"Thinking...","chat.processDetails":"Process details","chat.message":"message","chat.messages":"messages","chat.toolCall":"tool call","chat.toolCalls":"tool calls","chat.collapseProcess":"Collapse process details","chat.expandProcess":"Expand process details","chat.filesWritten":"Files changed","chat.openWrittenFile":"Open {name}","chat.loadEarlier":"Scroll up to load earlier messages ({count} hidden)","chat.extensionRequest":"extension request","chat.cancel":"Cancel","chat.confirm":"Confirm","chat.submit":"Submit","chat.extensionInput":"Extension terminal input","chat.extensionPanel":"Extension panel","chat.extensionWidgets":"Extension widgets","chat.extensionWidgetAbove":"Above editor widget","chat.extensionWidgetBelow":"Below editor widget","chat.extensionWidgetLine":"{count} line","chat.extensionWidgetLines":"{count} lines","chat.close":"Close","chat.queued":"Queued \xb7 {count}","chat.recall":"Recall to input","chat.recallTitle":"Remove all queued messages and put them back into the input box for editing","chat.retrying":"Retrying ({attempt}/{max})…","chat.loadingCommands":"Loading commands...","chat.slashCommands":"Slash commands \xb7 {label}","chat.tabEnter":"Tab / Enter","chat.noCommands":"No extension, prompt, or skill commands found","chat.match":"1 match","chat.matches":"{count} matches","chat.command":"1 command","chat.commands":"{count} commands","chat.loadingFiles":"Loading files...","chat.files":"Files \xb7 {label}{hint}","chat.searching":"Searching…","chat.noMatchingFiles":"No matching files","chat.searchingAll":" \xb7 searching all files…","chat.indexTruncated":" \xb7 index truncated","chat.steerPlaceholder":"Steer now / queue follow-up...","chat.agentPlaceholder":"Agent is running…","chat.messagePlaceholder":"Message… Type / for commands, @ for files","chat.steer":"Steer","chat.followUp":"Follow-up","chat.send":"Send","chat.attachImage":"Attach image","chat.previewImage":"Preview image","chat.filterModels":"Filter models…","chat.noMatchingModels":"No matching models","chat.moreControls":"More controls","chat.collapseControls":"Collapse controls","chat.shell":"Shell","chat.outputLocal":"output stays local","chat.outputModel":"output sent to model","chat.noTools":"No tools","chat.readOnlyTools":"{count} read-only built-in tools","chat.builtInTools":"{count} built-in tools","chat.allBuiltInTools":"All built-in tools","chat.changeReasoning":"Change reasoning level: {level}","chat.changeReasoningLabel":"Change reasoning level","chat.changeToolPreset":"Change tool preset","chat.stopCompaction":"Stop compaction","chat.compactContext":"Compact context","chat.compacting":"Compacting…","chat.compact":"Compact","chat.scrollToLatest":"Back to latest","bg.title":"Wallpaper","bg.choose":"Choose image…","bg.replace":"Replace image…","bg.remove":"Remove wallpaper","bg.hint":"The original file is stored locally in your browser — never re-encoded or uploaded.","bg.repeat":"Tile horizontally","bg.fill":"Edge colour fill","bg.adjust":"Adjust horizontal position…","bg.adjustHint":"Drag left / right to reposition","bg.adjustDone":"Done","bg.reset":"Reset position","bg.bubbleOpacity":"Bubble opacity","bg.bubbleBlur":"Frost blur","bg.bubbleReset":"Reset bubbles","chat.stopAgent":"Stop agent","chat.stop":"Stop","chat.disableSound":"Disable completion sound","chat.enableSound":"Enable completion sound","chat.thinkingUseDefault":"Use pi default","chat.thinkingOff":"Reasoning off","chat.thinkingMinimal":"Minimal reasoning","chat.thinkingLow":"Low reasoning","chat.thinkingMedium":"Medium reasoning","chat.thinkingHigh":"High reasoning","chat.thinkingXhigh":"Extra-high reasoning","chat.thinkingMax":"Max reasoning","chat.builtIn":"Built-in","chat.extensions":"Extensions","chat.prompts":"Prompts","chat.skills":"Skills","chat.dormant":"dormant","chat.commandCompact":"Compress context, optionally with instructions","chat.commandReload":"Reload extensions, skills, prompts, and tools","chat.commandName":"Set the session display name","chat.commandSession":"Show session message, token, and cost stats","chat.commandCopy":"Copy the last assistant message","chat.compacted":"Compacted","chat.tokensSaved":"{saved} saved","i18n.close":"Close","i18n.copy":"Copy","i18n.pin":"Pin","i18n.pinTitle":"Pin this message (creates a draggable/resizable float)","i18n.copied":"Copied","i18n.cancel":"Cancel","i18n.save":"Save","i18n.saving":"Saving…","i18n.saved":"Saved","i18n.remove":"Remove","i18n.removing":"Removing…","i18n.delete":"Delete","i18n.loading":"Loading...","i18n.search":"Search","i18n.refresh":"Refresh","i18n.update":"Update","i18n.updating":"Updating...","i18n.check":"Check","i18n.checking":"Checking...","i18n.install":"Install","i18n.installing":"Installing...","i18n.noResults":"No results","i18n.searchProviders":"Search providers…","i18n.noProviders":"No providers match","i18n.newModel":"new model","i18n.addProvider":"Add provider","i18n.selectProviderModel":"Select a provider or model","i18n.visibleInPrompt":"Visible in model prompt — click to disable","i18n.hiddenFromPrompt":"Hidden from model prompt — click to enable","i18n.dormant":"Dormant","i18n.hiddenButInvocable":"Hidden from model, still manually invocable","i18n.skillSearchPlaceholder":"e.g. react, testing, deploy","i18n.searching":"Searching…","i18n.noSkills":"No skills found","i18n.checkUpdates":"Check updates","i18n.updates":"updates","i18n.noResolvedResources":"No resolved resources","i18n.enablePackage":"Enable package","i18n.disablePackage":"Disable package","i18n.filtered":"filtered","i18n.openSessionToReload":"Open a session to reload","i18n.notFound":"Not found","i18n.noPlugins":"No plugins configured","trust.resourcesNotLoaded":"Restricted mode","trust.trustProject":"Trust project","trust.trusting":"Trusting...","trust.cancel":"Cancel","trust.dialogTitle":"Trust this project?","trust.dialogBody":"Project resources can run local code. Trust only projects whose contents you know.","trust.skillsNotLoaded":"Project skills are not loaded because this project is not trusted.","trust.pluginsNotLoaded":"Project plugins are not loaded because this project is not trusted.","trust.projectScopeUnavailable":"Project installs are unavailable while project resources are not loaded.","i18n.creatingSession":"Creating new session…","i18n.creating":"Creating…","i18n.subscription":"Subscription","i18n.subscriptions":"Subscriptions","i18n.customEndpoint":"Custom endpoint format","i18n.noChanges":"No changes","i18n.branches":"Branches","i18n.noActiveSession":"No active session","i18n.noBranches":"This session has no branches","i18n.source":"Source","i18n.preview":"Preview","i18n.diff":"Diff","i18n.downloadFile":"Download file","i18n.liveSync":"Live sync active","i18n.notWatching":"Not watching","i18n.fileViewMode":"File view mode","i18n.compareHead":"Compare working tree with HEAD","i18n.mentionSelectedLines":"Mention selected lines","i18n.disableWrap":"Disable word wrap","i18n.enableWrap":"Enable word wrap","i18n.htmlPreview":"HTML preview","i18n.previewFile":"Preview {file}","i18n.invalidMermaid":"Invalid Mermaid diagram","i18n.renderingMermaid":"Rendering Mermaid diagram","i18n.previewAfterStreaming":"Preview available after streaming","i18n.showMermaidSource":"Show Mermaid source","i18n.previewMermaid":"Preview Mermaid diagram","i18n.openMermaidViewer":"Open diagram viewer","i18n.mermaidViewer":"Mermaid diagram viewer","i18n.mermaidDiagram":"Mermaid diagram","i18n.zoomOut":"Zoom out","i18n.zoomIn":"Zoom in","i18n.fitToWidth":"Fit to width","models.discoveryFetching":"Importing models…","models.discoveryFetch":"Import models…","models.discoveryFilterPlaceholder":"Filter {count} models…","models.discoveryFilter":"Filter upstream models","models.discoverySelectShown":"Select shown","models.discoveryNoMatches":"No matching models.","models.discoveryAdded":"added","models.discoveryShowing":"Showing first {shown} of {total}","models.discoveryFetched":"{count} models fetched","models.discoveryAddSelected":"Add selected","models.discoveryAddSelectedCount":"Add selected ({count})","models.catalogSource":"source: models.dev ↗","models.catalogFilling":"Filling details…","models.catalogFill":"Fill model details","models.catalogFilled":"{count} fields filled","models.catalogNoEmptyFields":"No empty fields to fill","models.catalogNoExactMatch":"No exact models.dev match","models.catalogPriceProvider":"Price matched Provider {provider}","models.catalogPriceBaseUrl":"Price matched Base URL to {provider}","models.catalogPriceConsensus":"Price agreed by {support}/{total} records","models.catalogPriceUnreliable":"No reliable price found","models.catalogUndo":"Undo","models.capabilities":"Capabilities","models.reasoning":"Reasoning / thinking","models.imageInput":"Image input","models.modelSpecs":"Model specifications","models.contextWindow":"Context window (tokens)","models.maxOutputTokens":"Max output tokens","models.costPerMillion":"Cost per million tokens","models.costInput":"Input","models.costOutput":"Output","models.costCacheRead":"Cache read","models.costCacheWrite":"Cache write","models.notProvided":"Not provided","models.editCosts":"Edit prices","models.finishEditingCosts":"Done","models.costAllRequired":"Enter a valid non-negative price; blank fields are saved as 0.","models.advancedSettings":"Advanced settings","models.providerDefaults":"Using provider defaults","models.headersSummary":"Headers: {count}","models.compatSummary":"Compatibility: {count}","models.thinkingSummary":"Thinking levels: {count}","models.apiOverride":"API override","models.headers":"Headers","models.headersHelp":"Added to this model's requests and overrides provider headers.","models.compatibility":"Compatibility","models.deepSeekThinkingCompat":"DeepSeek thinking compatibility","models.developerRole":"Use the developer role for the system prompt","models.thinkingLevelMap":"Thinking level map","models.clearAll":"Clear all","i18n.testingModel":"Testing model connection...","i18n.connected":"Connected","i18n.failed":"Failed","i18n.test":"Test","i18n.testConnection":"Test model connection","i18n.provider":"Provider","i18n.model":"Model","i18n.providerName":"Provider name","i18n.rename":"Rename","i18n.default":"Default","i18n.disabled":"Disabled","i18n.noResources":"No resources","i18n.unknown":"Unknown","i18n.installedVersion":"installed {version}","i18n.configuredVersion":"configured {version}","i18n.extensions":"Extensions","i18n.prompts":"Prompts","i18n.themes":"Themes","i18n.resourceCount":"{count} {label}","i18n.extensionShort":"ext","i18n.skillShort":"skills","i18n.promptShort":"prompts","i18n.themeShort":"themes","i18n.custom":"Custom","i18n.clearAll":"clear all","i18n.connectedSuccessfully":"Connected successfully.","i18n.notConnected":"not connected","i18n.configured":"configured","i18n.notConfigured":"not configured","i18n.openingBrowser":"Opening browser…","i18n.submit":"Submit","i18n.login":"Login","i18n.relogin":"Re-login","i18n.disconnect":"Disconnect","i18n.networkError":"Network error","i18n.continuing":"Continuing…","i18n.skills":"Skills","i18n.plugins":"Plugins","i18n.addSkill":"Add skill","i18n.addPlugin":"Add plugin","i18n.selectSkill":"Select a skill","i18n.selectPackage":"Select a package","i18n.updateAvailable":"Update available","i18n.upToDate":"Up to date","i18n.automaticChecksUnavailable":"Automatic checks unavailable","i18n.checkFailed":"Check failed","i18n.installed":"Installed","i18n.status":"Status","i18n.version":"Version","i18n.package":"Package","i18n.resources":"Resources","i18n.installedPath":"Installed path","i18n.cwd":"CWD","i18n.resolvedResources":"Resolved Resources","i18n.reloadSession":"Reload session","i18n.reloading":"Reloading...","i18n.packageRemoved":"Package removed.","i18n.packageInstalled":"Package installed.","i18n.packageUpdated":"Package updated.","i18n.packageDisabled":"Package disabled.","i18n.packageEnabled":"Package enabled.","i18n.sessionReloaded":"Session reloaded.","i18n.thinking":"Thinking","i18n.largeMessageReveal":"Message content is very large ({size}). Click to view as plain text — markdown rendering is disabled to keep the page responsive.","i18n.loadingThinking":"Loading thinking...","i18n.copyMessage":"Copy message","i18n.editFromHere":"Edit from here","i18n.editFromHereTitle":"Edit from here — branches within this session","i18n.newSession":"New session","i18n.newSessionTitle":"New session — creates an independent copy from here","i18n.estimatedTokens":"Estimated token count while streaming","i18n.noOutput":"(no output)","i18n.noSummary":"(no summary)","i18n.conversationCompacted":"Conversation compacted","i18n.compactionDescription":"The conversation history before this point was compacted into the following summary:","i18n.fileContext":"File context: {details}","i18n.readFiles":"Read files","i18n.modifiedFiles":"Modified files","i18n.hiddenExtensionMessage":"hidden extension message","i18n.noMessage":"(no message)","i18n.showExtensionMessage":"Show extension message","i18n.collapse":"Collapse","i18n.expand":"Expand","i18n.hideDetails":"Hide details","i18n.showDetails":"Show details","i18n.thinkingUnavailable":"Thinking content unavailable","i18n.before":"Before","i18n.after":"After","i18n.sessionComplete":"Session complete","i18n.taskFinished":"Task finished.","i18n.attentionNeeded":"Pi needs your attention","i18n.extensionInputNeeded":"An extension is waiting for your input.","todo.title":"Tasks","todo.completed":"completed","todo.empty":"No active tasks. Ask the agent to add some!","terminal.title":"Terminal","terminal.new":"New terminal","terminal.all":"All terminals","terminal.exited":"exited","terminal.cleanupDisconnected":"Remove disconnected terminals","terminal.empty":"No terminal sessions","terminal.createFirst":"Create a terminal session","terminal.close":"Kill process and close","mcp.sectionTitle":"MCP servers","mcp.addButton":"Add MCP","mcp.emptyList":'No MCP servers yet. Click "Add MCP" below to create one.',"mcp.emptyDetail":'Select an MCP server on the left, or click "Add MCP".',"mcp.itemEnabled":"enabled","mcp.itemDisabled":"disabled","mcp.addTitle":"Add MCP server","mcp.editTitle":"Edit MCP: {name}","mcp.modeBasic":"Basic","mcp.modeJson":"JSON advanced","mcp.nameLabel":"Name","mcp.namePlaceholder":"e.g. github","mcp.specLabel":"Command or URL (http/https is treated as a URL)","mcp.specPlaceholder":"npx -y @modelcontextprotocol/server-github or https://example.com/mcp","mcp.argsLabel":"Extra args (optional, space separated)","mcp.jsonLabel":"Server definition (JSON) - all fields supported: command/url/socket, args, env, lifecycle, directTools, timeout","mcp.loadingDef":"Loading config...","mcp.jsonEmpty":"JSON cannot be empty","mcp.jsonParseError":"JSON parse failed: {message}","mcp.jsonNotObject":'JSON must be an object, e.g. {"command":"npx","args":["-y","..."]}',"mcp.jsonNeedsEntry":"JSON must contain command, url or socket","mcp.save":"Save","mcp.saveEdit":"Save changes","mcp.saving":"Saving...","mcp.cancel":"Cancel","mcp.enable":"Enable","mcp.disable":"Disable","mcp.disabledBadge":"Disabled","mcp.test":"Test connection","mcp.testing":"Testing...","mcp.edit":"Edit","mcp.delete":"Delete","mcp.moveToGlobal":"Move to global","mcp.moveToProject":"Move to project","mcp.kindCommand":"Command","mcp.kindUrl":"URL","mcp.kindSocket":"Socket","mcp.fieldType":"Type","mcp.fieldArgs":"Args","mcp.fieldEnv":"Env vars","mcp.fieldOptions":"Options","mcp.fieldSource":"Source","mcp.fieldCwd":"CWD","mcp.msgEnabled":"Enabled {name} (run /reload to apply)","mcp.msgDisabled":"Disabled {name} (run /reload to apply)","mcp.msgDeleted":"Deleted {name}","mcp.msgMoved":"Moved {name} to {scope} (run /reload to apply)","mcp.msgUpdated":"Updated {name} (run /reload to apply)","mcp.msgAdded":"Added {name} (run /reload to apply)","mcp.msgTestResult":"Test {name}: {result}","mcp.msgTestError":"Test {name}: {error}","common.close":"Close"}}),l({id:"zh-CN",label:"简体中文",messages:{"common.ok":"确定","common.close":"关闭","common.language":"语言","common.models":"模型","common.skills":"技能","common.plugins":"插件","appUpdate.releaseNotes":"Pi Web v{version} 可用,查看更新说明","sidebar.hide":"隐藏侧边栏","sidebar.show":"显示侧边栏","theme.light":"浅色模式(点击切换到深色)","theme.dark":"深色模式(点击切换到跟随系统)","theme.auto":"跟随系统(点击切换到浅色)","history.full":"完整历史","history.unsaved":"会话保存后才能查看完整历史","history.label":"完整历史","title.generating":"正在生成...","title.updated":"标题已更新","title.failed":"生成失败","title.generate":"生成标题","title.unsaved":"会话保存后才能生成标题","title.noMessages":"请先发送消息,再为会话命名","title.generateSession":"生成会话标题","system.prompt":"系统提示词","system.empty":"系统提示词为空(工具已禁用)","system.load":"系统提示词尚未加载","system.loading":"正在加载系统提示词…","system.label":"系统","session.info":"会话信息","session.name":"名称","session.file":"文件","session.inMemory":"内存中","session.id":"ID","session.user":"用户","session.assistant":"助手","session.toolCalls":"工具调用","session.toolResults":"工具结果","session.total":"总计","session.input":"输入","session.output":"输出","session.cacheRead":"缓存读取","session.cacheWrite":"缓存写入","session.cost":"费用","session.context":"上下文","session.cacheHitRate":"平均缓存命中率","session.copy":"复制{value}","session.copied":"已复制","session.title":"会话信息","session.load":"发送消息或运行 /session 以加载会话信息","session.infoSection":"会话信息","session.messages":"消息","session.tokens":"Token","session.totalActive":"活跃时长","session.copyFile":"复制文件路径","session.copyId":"复制会话 ID","workspace.opening":"正在打开工作区...","workspace.unable":"无法打开工作区","workspace.selectSession":"从侧边栏选择一个会话","workspace.getStarted":"开始使用","workspace.selectProject":"从侧边栏选择项目目录","workspace.addModels":"点击底部的“模型”按钮添加模型","workspace.stepProject":"从侧边栏选择项目目录","workspace.stepModels":"点击底部的“模型”按钮添加模型","files.hidePanel":"隐藏文件面板","files.showPanel":"显示文件面板","files.noneOpen":"没有打开的文件","layout.resizeSidebar":"调整侧边栏宽度","layout.resizeFilePanel":"调整文件面板宽度","layout.resizeHint":"拖动调整宽度。双击或按 Enter 恢复默认值。","sidebar.new":"新建","sidebar.newSessionTitle":"在 {path} 中新建会话","sidebar.refresh":"刷新","sidebar.selectProject":"选择项目…","sidebar.filterProjects":"筛选项目…","sidebar.noMatchingProjects":"没有匹配的项目","sidebar.useDefaultDirectory":"使用默认目录","sidebar.customPath":"自定义路径…","directoryPicker.selectDirectory":"选择目录","directoryPicker.goToParent":"转到上级目录","directoryPicker.directoryPath":"目录路径","directoryPicker.goToDirectory":"转到目录","directoryPicker.go":"转到","directoryPicker.loadingDirectories":"正在加载目录…","directoryPicker.noSubdirectories":"没有子目录","directoryPicker.openBeforeSelecting":"选择前请先打开此路径","directoryPicker.selectCurrentDirectory":"选择当前目录","directoryPicker.selectThisFolder":"选择此文件夹","directoryPicker.noDrives":"未找到盘符","sidebar.checking":"检查中…","sidebar.open":"打开","sidebar.cancel":"取消","sidebar.openRepoRoot":"打开仓库根目录","sidebar.openRepoRootTitle":"打开仓库根目录以管理 worktree。","sidebar.gitRepoRootOnly":"仅 Git 仓库根目录","sidebar.gitRepoRootOnlyTitle":"只能在 Git 仓库根目录使用 worktree。","sidebar.worktrees":"Worktrees...","sidebar.checkingWorktrees":"正在检查此目录的 worktree。","sidebar.filterWorktrees":"筛选 worktree…","sidebar.noMatchingWorktrees":"没有匹配的 worktree","sidebar.switchWorktree":"切换 worktree","sidebar.switchWorktreeTitle":"切换 worktree:{path}","sidebar.main":"主分支","sidebar.forceRemoveCheckout":"存在未提交的更改。强制移除 checkout?","sidebar.force":"强制移除","sidebar.createWorktreeTitle":"为分支创建 worktree checkout","sidebar.newWorktree":"新建 worktree…","sidebar.branchName":"分支名称","sidebar.creating":"创建中…","sidebar.create":"创建","sidebar.uploadFilesTitle":"将文件上传到项目根目录","sidebar.uploadFiles":"上传文件","sidebar.refreshExplorer":"刷新文件浏览器","sidebar.changedFiles":"{count} 个变更文件","sidebar.loading":"加载中...","sidebar.noSessions":"未找到会话","sidebar.agentRunning":"Agent 运行中…","sidebar.newActivity":"有新活动","sidebar.newSessionActivity":"会话有新活动","sidebar.deleteSession":"删除 {title}?","sidebar.rename":"重命名","sidebar.delete":"删除","sidebar.deleteWithShiftClick":"删除(按住 Shift 点击可跳过确认)","sidebar.expandForks":"展开分叉","sidebar.collapseForks":"折叠分叉","sidebar.messagesCount":"{count} 条消息","sidebar.worktreePath":"Worktree:{path}","sidebar.removeWorktreeTitle":"移除 worktree checkout {path};保留分支","files.modified":"已修改","files.added":"已添加","files.deleted":"已删除","files.renamed":"已重命名","files.untracked":"未跟踪","files.conflict":"冲突","files.newlyUploaded":"刚上传","files.containsChangedFiles":"包含已更改文件","files.insertPath":"将路径插入聊天","files.mention":"提及","files.download":"下载文件","files.dismissError":"关闭错误","files.addUploadedFile":"将上传的文件添加到聊天","files.addAllUploadedFiles":"将所有上传的文件添加到聊天","files.dismissUploadResults":"关闭上传结果","files.loading":"正在加载文件...","files.noFiles":"未找到文件","files.explorer":"文件浏览器","files.changedCount":"{count} 个文件","files.changeStats":"{count} 个变更文件,新增 {additions} 行,删除 {deletions} 行","files.conflictSummary":"已有 {count} 个文件:{files}","files.cannotReplace":"无法替换:{files}","files.replace":"替换","files.skipExisting":"跳过已有文件","files.cancel":"取消","files.checking":"正在检查文件","files.uploading":"正在上传,{progress}%","chat.loadingSession":"正在加载会话...","chat.runningTool":"正在运行工具...","chat.generatingToolInput":"正在生成参数...","chat.runningNamedTool":"正在运行 {name}...","chat.runningTools":"正在运行 {names}...","chat.runningToolsMore":"正在运行 {names}(另有 {count} 个)...","chat.waitingModel":"正在等待模型...","chat.runningCommand":"正在运行命令...","chat.thinking":"正在思考...","chat.processDetails":"处理详情","chat.message":"条消息","chat.messages":"条消息","chat.toolCall":"次工具调用","chat.toolCalls":"次工具调用","chat.collapseProcess":"收起处理详情","chat.expandProcess":"展开处理详情","chat.filesWritten":"改动的文件","chat.openWrittenFile":"打开 {name}","chat.loadEarlier":"向上滚动以加载更早的消息(隐藏 {count} 条)","chat.extensionRequest":"扩展请求","chat.cancel":"取消","chat.confirm":"确认","chat.submit":"提交","chat.extensionInput":"扩展终端输入","chat.extensionPanel":"扩展面板","chat.extensionWidgets":"扩展组件","chat.extensionWidgetAbove":"输入框上方组件","chat.extensionWidgetBelow":"输入框下方组件","chat.extensionWidgetLine":"{count} 行","chat.extensionWidgetLines":"{count} 行","chat.close":"关闭","chat.queued":"已排队 \xb7 {count}","chat.recall":"移回输入框","chat.recallTitle":"移除所有排队消息并将其放回输入框编辑","chat.retrying":"正在重试({attempt}/{max})…","chat.loadingCommands":"正在加载命令...","chat.slashCommands":"斜杠命令 \xb7 {label}","chat.tabEnter":"Tab / Enter","chat.noCommands":"未找到扩展、提示词或技能命令","chat.match":"1 个匹配项","chat.matches":"{count} 个匹配项","chat.command":"1 个命令","chat.commands":"{count} 个命令","chat.loadingFiles":"正在加载文件...","chat.files":"文件 \xb7 {label}{hint}","chat.searching":"搜索中…","chat.noMatchingFiles":"未找到匹配的文件","chat.searchingAll":" \xb7 正在搜索所有文件…","chat.indexTruncated":" \xb7 索引不完整","chat.steerPlaceholder":"立即引导 / 排队后续消息...","chat.agentPlaceholder":"Agent 运行中…","chat.messagePlaceholder":"消息…输入 / 使用命令,输入 @ 查找文件","chat.steer":"引导","chat.followUp":"后续消息","chat.send":"发送","chat.attachImage":"附加图片","chat.previewImage":"预览图片","chat.filterModels":"筛选模型…","chat.noMatchingModels":"没有匹配的模型","chat.moreControls":"更多控件","chat.collapseControls":"收起控件","chat.shell":"Shell","chat.outputLocal":"输出保留在本地","chat.outputModel":"输出发送给模型","chat.noTools":"不使用工具","chat.readOnlyTools":"{count} 个只读内置工具","chat.builtInTools":"{count} 个内置工具","chat.allBuiltInTools":"全部内置工具","chat.changeReasoning":"更改推理级别:{level}","chat.changeReasoningLabel":"更改推理级别","chat.changeToolPreset":"更改工具预设","chat.stopCompaction":"停止压缩","chat.compactContext":"压缩上下文","chat.compacting":"正在压缩…","chat.compact":"压缩","chat.scrollToLatest":"回到底部","bg.title":"背景图","bg.choose":"选择图片…","bg.replace":"更换图片…","bg.remove":"移除背景图","bg.hint":"原图保存在浏览器本地,不重新编码、不上传。","bg.repeat":"平铺(横向重复)","bg.fill":"边缘色彩填充","bg.adjust":"调整横向位置…","bg.adjustHint":"左右拖拽调整壁纸位置","bg.adjustDone":"移动完成","bg.reset":"重置位置","bg.bubbleOpacity":"气泡透明度","bg.bubbleBlur":"磨砂强度","bg.bubbleReset":"重置气泡","chat.stopAgent":"停止 Agent","chat.stop":"停止","chat.disableSound":"关闭完成提示音","chat.enableSound":"开启完成提示音","chat.thinkingUseDefault":"使用 pi 默认设置","chat.thinkingOff":"关闭推理","chat.thinkingMinimal":"最低限度推理","chat.thinkingLow":"低强度推理","chat.thinkingMedium":"中等强度推理","chat.thinkingHigh":"高强度推理","chat.thinkingXhigh":"超高强度推理","chat.thinkingMax":"最高强度推理","chat.builtIn":"内置","chat.extensions":"扩展","chat.prompts":"提示词","chat.skills":"技能","chat.dormant":"休眠","chat.commandCompact":"压缩上下文,可选附加说明","chat.commandReload":"重新加载扩展、技能、提示词和工具","chat.commandName":"设置会话显示名称","chat.commandSession":"显示会话消息、Token 和费用统计","chat.commandCopy":"复制最后一条助手消息","chat.compacted":"已压缩","chat.tokensSaved":"节省 {saved}","i18n.close":"关闭","i18n.copy":"复制","i18n.pin":"钉","i18n.pinTitle":"钉住此消息(生成可拖拽/缩放的浮窗)","i18n.copied":"已复制","i18n.cancel":"取消","i18n.save":"保存","i18n.saving":"保存中…","i18n.saved":"已保存","i18n.remove":"移除","i18n.removing":"移除中…","i18n.delete":"删除","i18n.loading":"加载中...","i18n.search":"搜索","i18n.refresh":"刷新","i18n.update":"更新","i18n.updating":"更新中...","i18n.check":"检查","i18n.checking":"检查中...","i18n.install":"安装","i18n.installing":"安装中...","i18n.noResults":"没有结果","i18n.searchProviders":"搜索 Provider…","i18n.noProviders":"没有匹配的 Provider","i18n.newModel":"新模型","i18n.addProvider":"添加 Provider","i18n.selectProviderModel":"选择 Provider 或模型","i18n.visibleInPrompt":"在模型提示词中可见,点击以禁用","i18n.hiddenFromPrompt":"在模型提示词中隐藏,点击以启用","i18n.dormant":"休眠","i18n.hiddenButInvocable":"对模型隐藏,仍可手动调用","i18n.skillSearchPlaceholder":"例如 react、testing、deploy","i18n.searching":"搜索中…","i18n.noSkills":"未找到技能","i18n.checkUpdates":"检查更新","i18n.updates":"项更新","i18n.noResolvedResources":"没有已解析资源","i18n.enablePackage":"启用包","i18n.disablePackage":"禁用包","i18n.filtered":"已筛选","i18n.openSessionToReload":"打开会话后才能重新加载","i18n.notFound":"未找到","i18n.noPlugins":"未配置插件","trust.resourcesNotLoaded":"受限模式","trust.trustProject":"信任项目","trust.trusting":"正在信任...","trust.cancel":"取消","trust.dialogTitle":"信任此项目?","trust.dialogBody":"项目资源可以运行本地代码。请仅信任你了解其内容的项目。","trust.skillsNotLoaded":"此项目尚未受信任,项目技能未加载。","trust.pluginsNotLoaded":"此项目尚未受信任,项目插件未加载。","trust.projectScopeUnavailable":"项目资源未加载时,无法安装到项目范围。","i18n.creatingSession":"正在创建新会话…","i18n.creating":"创建中…","i18n.subscription":"订阅","i18n.subscriptions":"订阅服务","i18n.customEndpoint":"自定义端点格式","i18n.noChanges":"没有更改","i18n.branches":"分支","i18n.noActiveSession":"没有活动会话","i18n.noBranches":"此会话没有分支","i18n.source":"源代码","i18n.preview":"预览","i18n.diff":"Diff","i18n.downloadFile":"下载文件","i18n.liveSync":"实时同步已启用","i18n.notWatching":"未监视","i18n.fileViewMode":"文件视图模式","i18n.compareHead":"比较工作区与 HEAD","i18n.mentionSelectedLines":"提及所选行","i18n.disableWrap":"禁用自动换行","i18n.enableWrap":"启用自动换行","i18n.htmlPreview":"HTML 预览","i18n.previewFile":"预览 {file}","i18n.invalidMermaid":"Mermaid 图表无效","i18n.renderingMermaid":"正在渲染 Mermaid 图表","i18n.previewAfterStreaming":"流式输出完成后可预览","i18n.showMermaidSource":"显示 Mermaid 源码","i18n.previewMermaid":"预览 Mermaid 图表","i18n.openMermaidViewer":"打开图表查看器","i18n.mermaidViewer":"Mermaid 图表查看器","i18n.mermaidDiagram":"Mermaid 图表","i18n.zoomOut":"缩小","i18n.zoomIn":"放大","i18n.fitToWidth":"适应宽度","models.discoveryFetching":"正在导入模型…","models.discoveryFetch":"导入模型…","models.discoveryFilterPlaceholder":"筛选 {count} 个模型…","models.discoveryFilter":"筛选上游模型","models.discoverySelectShown":"选择当前结果","models.discoveryNoMatches":"没有匹配的模型。","models.discoveryAdded":"已添加","models.discoveryShowing":"显示前 {shown} 个,共 {total} 个","models.discoveryFetched":"已获取 {count} 个模型","models.discoveryAddSelected":"添加所选模型","models.discoveryAddSelectedCount":"添加所选模型({count})","models.catalogSource":"来源:models.dev ↗","models.catalogFilling":"正在填入模型信息…","models.catalogFill":"填入模型信息","models.catalogFilled":"已填入 {count} 个字段","models.catalogNoEmptyFields":"没有需要填入的空字段","models.catalogNoExactMatch":"models.dev 中没有精确匹配","models.catalogPriceProvider":"价格已匹配 Provider {provider}","models.catalogPriceBaseUrl":"价格已按 Base URL 匹配 {provider}","models.catalogPriceConsensus":"价格得到 {support}/{total} 条记录支持","models.catalogPriceUnreliable":"未找到可靠价格","models.catalogUndo":"撤销","models.capabilities":"能力","models.reasoning":"推理 / 思考","models.imageInput":"图片输入","models.modelSpecs":"模型规格","models.contextWindow":"上下文窗口(tokens)","models.maxOutputTokens":"最大输出 tokens","models.costPerMillion":"每百万 tokens 价格","models.costInput":"输入","models.costOutput":"输出","models.costCacheRead":"缓存读取","models.costCacheWrite":"缓存写入","models.notProvided":"未提供","models.editCosts":"编辑价格","models.finishEditingCosts":"完成","models.costAllRequired":"请输入有效的非负价格;留空项将按 0 保存。","models.advancedSettings":"高级设置","models.providerDefaults":"沿用 Provider 默认设置","models.headersSummary":"Headers:{count}","models.compatSummary":"兼容性:{count}","models.thinkingSummary":"思考等级:{count}","models.apiOverride":"API 覆盖","models.headers":"Headers","models.headersHelp":"仅添加到该模型的请求中,并覆盖 Provider 的同名 Header。","models.compatibility":"兼容性","models.deepSeekThinkingCompat":"DeepSeek 思考兼容","models.developerRole":"使用 developer role 传递系统提示词","models.thinkingLevelMap":"思考等级映射","models.clearAll":"全部清除","i18n.testingModel":"正在测试模型连接...","i18n.connected":"已连接","i18n.failed":"失败","i18n.test":"测试","i18n.testConnection":"测试模型连接","i18n.provider":"Provider","i18n.model":"模型","i18n.providerName":"Provider 名称","i18n.rename":"重命名","i18n.default":"默认","i18n.disabled":"已禁用","i18n.noResources":"没有资源","i18n.unknown":"未知","i18n.installedVersion":"已安装 {version}","i18n.configuredVersion":"已配置 {version}","i18n.extensions":"扩展","i18n.prompts":"提示词","i18n.themes":"主题","i18n.resourceCount":"{count}{label}","i18n.extensionShort":"扩展","i18n.skillShort":"技能","i18n.promptShort":"提示词","i18n.themeShort":"主题","i18n.custom":"自定义","i18n.clearAll":"清除全部","i18n.connectedSuccessfully":"连接成功。","i18n.notConnected":"未连接","i18n.configured":"已配置","i18n.notConfigured":"未配置","i18n.openingBrowser":"正在打开浏览器…","i18n.submit":"提交","i18n.login":"登录","i18n.relogin":"重新登录","i18n.disconnect":"断开连接","i18n.networkError":"网络错误","i18n.continuing":"继续中…","i18n.skills":"技能","i18n.plugins":"插件","i18n.addSkill":"添加技能","i18n.addPlugin":"添加插件","i18n.selectSkill":"选择技能","i18n.selectPackage":"选择包","i18n.updateAvailable":"有可用更新","i18n.upToDate":"已是最新","i18n.automaticChecksUnavailable":"自动检查不可用","i18n.checkFailed":"检查失败","i18n.installed":"已安装","i18n.status":"状态","i18n.version":"版本","i18n.package":"包","i18n.resources":"资源","i18n.installedPath":"安装路径","i18n.cwd":"CWD","i18n.resolvedResources":"已解析资源","i18n.reloadSession":"重新加载会话","i18n.reloading":"重新加载中...","i18n.packageRemoved":"包已移除。","i18n.packageInstalled":"包已安装。","i18n.packageUpdated":"包已更新。","i18n.packageDisabled":"包已禁用。","i18n.packageEnabled":"包已启用。","i18n.sessionReloaded":"会话已重新加载。","i18n.thinking":"思考","i18n.largeMessageReveal":"消息内容过大({size})。点击以纯文本查看 — 已禁用 markdown 渲染以避免页面卡顿。","i18n.loadingThinking":"正在加载思考内容...","i18n.copyMessage":"复制消息","i18n.editFromHere":"从此处编辑","i18n.editFromHereTitle":"从此处编辑,此会话内创建分支","i18n.newSession":"新会话","i18n.newSessionTitle":"新会话,从此处创建独立副本","i18n.estimatedTokens":"流式输出期间的估算 Token 数","i18n.noOutput":"(无输出)","i18n.noSummary":"(无摘要)","i18n.conversationCompacted":"会话已压缩","i18n.compactionDescription":"此处之前的会话历史已压缩为以下摘要:","i18n.fileContext":"文件上下文:{details}","i18n.readFiles":"读取的文件","i18n.modifiedFiles":"修改的文件","i18n.hiddenExtensionMessage":"隐藏的扩展消息","i18n.noMessage":"(无消息)","i18n.showExtensionMessage":"显示扩展消息","i18n.collapse":"收起","i18n.expand":"展开","i18n.hideDetails":"隐藏详情","i18n.showDetails":"显示详情","i18n.thinkingUnavailable":"思考内容不可用","i18n.before":"之前","i18n.after":"之后","i18n.sessionComplete":"任务完成","i18n.taskFinished":"任务已完成。","i18n.attentionNeeded":"Pi 需要你的操作","i18n.extensionInputNeeded":"扩展正在等待你的输入。","todo.title":"任务","todo.completed":"已完成","todo.empty":"暂无任务,可以让 agent 添加。","terminal.title":"终端","terminal.new":"新建终端","terminal.all":"全部终端","terminal.exited":"已退出","terminal.cleanupDisconnected":"清理失联终端","terminal.empty":"暂无终端会话","terminal.createFirst":"新建终端会话","terminal.close":"结束进程并关闭","mcp.sectionTitle":"MCP 服务器","mcp.addButton":"添加MCP","mcp.emptyList":'暂无 MCP 服务器,点击下方"添加MCP"创建',"mcp.emptyDetail":'选择左侧一个 MCP 服务器,或点击"添加MCP"',"mcp.itemEnabled":"已启用","mcp.itemDisabled":"已禁用","mcp.addTitle":"添加 MCP 服务器","mcp.editTitle":"编辑 MCP:{name}","mcp.modeBasic":"基础配置","mcp.modeJson":"JSON 高级","mcp.nameLabel":"名称","mcp.namePlaceholder":"如 github","mcp.specLabel":"命令 或 URL(http/https 开头识别为 URL)","mcp.specPlaceholder":"npx -y @modelcontextprotocol/server-github 或 https://example.com/mcp","mcp.argsLabel":"附加参数(可选,空格分隔)","mcp.jsonLabel":"服务器定义(JSON)—— 支持 command/url/socket、args、env、lifecycle、directTools、timeout 等全部字段","mcp.loadingDef":"加载配置中...","mcp.jsonEmpty":"JSON 不能为空","mcp.jsonParseError":"JSON 解析失败:{message}","mcp.jsonNotObject":'JSON 必须是对象,如 {"command":"npx","args":["-y","..."]}',"mcp.jsonNeedsEntry":"JSON 需要包含 command、url 或 socket 之一","mcp.save":"保存","mcp.saveEdit":"保存修改","mcp.saving":"保存中...","mcp.cancel":"取消","mcp.enable":"启用","mcp.disable":"禁用","mcp.disabledBadge":"已禁用","mcp.test":"测试连接","mcp.testing":"测试中...","mcp.edit":"编辑","mcp.delete":"删除","mcp.moveToGlobal":"移动至global","mcp.moveToProject":"移动至project","mcp.kindCommand":"命令","mcp.kindUrl":"URL","mcp.kindSocket":"Socket","mcp.fieldType":"类型","mcp.fieldArgs":"参数","mcp.fieldEnv":"环境变量","mcp.fieldOptions":"选项","mcp.fieldSource":"来源","mcp.fieldCwd":"CWD","mcp.msgEnabled":"已启用 {name}(执行 /reload 生效)","mcp.msgDisabled":"已禁用 {name}(执行 /reload 生效)","mcp.msgDeleted":"已删除 {name}","mcp.msgMoved":"已移动 {name} → {scope}(执行 /reload 生效)","mcp.msgUpdated":"已更新 {name}(执行 /reload 生效)","mcp.msgAdded":"已添加 {name}(执行 /reload 生效)","mcp.msgTestResult":"测试 {name}:{result}","mcp.msgTestError":"测试 {name}:{error}"}});let s="pi-locale",d=(0,i.createContext)(null);function c({children:e}){let[t,r]=(0,i.useState)("en"),[l,u]=(0,i.useState)(!1),p=(0,i.useMemo)(()=>a().map(e=>o.get(e)).filter(e=>!!e),[]),h=(0,i.useMemo)(()=>Object.fromEntries(a().flatMap(e=>{let t=o.get(e);return t?[[e,t.messages]]:[]})),[]);(0,i.useEffect)(()=>{let e=function(){try{let e=window.localStorage.getItem(s);if("en"===e||"zh-CN"===e)return e}catch{}for(let e of window.navigator.languages.length?window.navigator.languages:[window.navigator.language]){let t=e.toLowerCase();if("en"===t||t.startsWith("en-"))break;if("zh"===t||t.startsWith("zh-"))return"zh-CN"}return"en"}();r(e),document.documentElement.lang=e,u(!0)},[]);let g=(0,i.useCallback)(e=>{if(o.get(e)){r(e),document.documentElement.lang=e;try{window.localStorage.setItem(s,e)}catch{}}},[]),f=(0,i.useCallback)((e,r)=>(function(e,t,r,n={}){let i=r[e]?.[t]??r.en?.[t];return void 0===i?t:function(e,t={}){return e.replace(/\{([\w.-]+)\}/g,(e,r)=>{let n=t[r];return void 0===n?e:String(n)})}(i,n)})(t,e,h,r),[t,h]),x=(0,i.useMemo)(()=>({locale:l?t:"en",setLocale:g,t:f,supportedLocales:p}),[l,t,g,f,p]);return(0,n.jsx)(d.Provider,{value:x,children:e})}function u(){let e=(0,i.useContext)(d);if(!e)throw Error("useI18n must be used inside I18nProvider");return e}},59767:e=>{e.exports={panel:"DraftStash_panel__oKqVT","draft-stash-in":"DraftStash_draft-stash-in__ri0Cg",toggle:"DraftStash_toggle__Bnscj",toggleLabel:"DraftStash_toggleLabel__uY4AC",toggleArrow:"DraftStash_toggleArrow__Ggwg9",expandArea:"DraftStash_expandArea__FsTfq",activeBar:"DraftStash_activeBar__b6iYc",activeDot:"DraftStash_activeDot__lnx2D",activeLabel:"DraftStash_activeLabel__QKNcj",cancelBtn:"DraftStash_cancelBtn__WGbk5",list:"DraftStash_list__J4Tfv",row:"DraftStash_row__AxlvA",btn:"DraftStash_btn__iCSwh",content:"DraftStash_content__OS0mw",time:"DraftStash_time__TpC8e",btnDanger:"DraftStash_btnDanger__RuifZ"}},67061:(e,t,r)=>{Promise.resolve().then(r.bind(r,77467)),Promise.resolve().then(r.bind(r,39247))},77467:(e,t,r)=>{"use strict";r.d(t,{AppShell:()=>ov});var n=r(95155),i=r(12115),o=r(47650),l=r(73321),a=r(37206);let s=null,d="pi-web:file-explorer:open";function c(){try{return window.localStorage}catch{return null}}let u=/^<skill name="([^"\n]+)" location="([^"\n]+)">\nReferences are relative to [^\n]+\.\n\n([\s\S]*)\n<\/skill>(?:\n\n([\s\S]+))?$/;function p(e){let t=e.match(u);if(!t)return null;let[,r,,,n]=t;return n?`/skill:${r} ${n}`:`/skill:${r}`}let h="pi-web:last-open-by-workspace";function g(){try{return window.localStorage}catch{return null}}function f(e){let t=e.getItem(h);if(!t)return{};try{let e=JSON.parse(t);return null===e||"object"!=typeof e||Array.isArray(e)?{}:e}catch{return{}}}function x(e,t=g()){if(t)try{let r=f(t);if(!(e in r))return;delete r[e],0===Object.keys(r).length?t.removeItem(h):t.setItem(h,JSON.stringify(r))}catch{}}function m(e){return e.projectKey??e.projectRoot??e.cwd}function v(e){let t=new Map;for(let r of e){let e=r.projectRoot??r.cwd;if(!e)continue;let n=m(r),i=t.get(n);(!i||r.modified>i.modified)&&t.set(n,{root:e,modified:r.modified})}return[...t.entries()].sort((e,t)=>t[1].modified.localeCompare(e[1].modified)).map(([e,{root:t}])=>({key:e,root:t}))}var b=r(39247);function y(e){let t=e.trim();if(!t.startsWith("file://"))return t;try{let e=new URL(t),r=decodeURIComponent(e.pathname);return/^\/[a-zA-Z]:[\\/]/.test(r)?r=r.slice(1):e.host&&"localhost"!==e.host&&(r=`//${e.host}${r}`),r}catch{let e=t.replace(/^file:\/\/(localhost)?/,"");try{e=decodeURIComponent(e)}catch{}return/^\/[a-zA-Z]:[\\/]/.test(e)&&(e=e.slice(1)),e}}let k=["text/uri-list","x-special/nautilus-clipboard","x-special/gnome-copied-files","x-special/mate-copied-files","x-special/xfce4-copied-files","application/x-kde-cutselection","public.file-url","text/x-moz-url","application/x-moz-file"];function w(e,t){if(!e)return[];let r=[],n=Array.from(e.files??[]);for(let e of n){let t=e.path;"string"==typeof t&&t.trim()&&r.push(t.trim())}if(r.length>0)return Array.from(new Set(r));for(let t of Array.from(e.items??[]))if("file"===t.kind){let e=t.getAsFile(),n=e?.path;"string"==typeof n&&n.trim()&&r.push(n.trim())}if(r.length>0)return Array.from(new Set(r));for(let t of k)try{let n=e.getData(t);if(n){let e=function(e){if(!e)return[];let t=e.split(/\r?\n/),r=[];for(let e of t){let t=e.trim();!(!t||t.startsWith("#"))&&"copy"!==t&&"cut"!==t&&(t.startsWith("file://")?r.push(y(t)):(t.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(t))&&r.push(t))}return r}(n);e.length>0&&r.push(...e)}}catch{}if(r.length>0)return Array.from(new Set(r));try{let t=e.getData("text/plain")||e.getData("text");if(t){let e=t.split(/\r?\n/).map(e=>e.trim()).filter(Boolean),n=e.filter(e=>e.startsWith("file://"));if(n.length>0&&n.length===e.length)for(let e of n)r.push(y(e))}}catch{}if(r.length>0)return Array.from(new Set(r));if(t?.fallbackToFileName&&n.length>0)for(let e of n)e.name&&r.push(e.name);return Array.from(new Set(r))}function j(e,t=" "){return e&&0!==e.length?1===e.length?e[0]:e.map(e=>{let t=e.trim();return!/\s/.test(t)||t.startsWith('"')||t.startsWith("'")?t:`"${t}"`}).join(t):""}async function S(e){let t=e?`?path=${encodeURIComponent(e)}`:"",r=await fetch(`/api/cwd/browse${t}`),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return n}function C(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M1.5 3h4l1.5 2h7.5v7.5h-13z"})})}function T(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"2",y:"3",width:"12",height:"10",rx:"1.5"}),(0,n.jsx)("path",{d:"M2 9h12"}),(0,n.jsx)("circle",{cx:"11.5",cy:"11",r:"0.6",fill:"currentColor",stroke:"none"})]})}function M({onCancel:e,onSelect:t,busy:r=!1,error:l}){let{t:a}=(0,b.s)(),[s,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(""),[p,h]=(0,i.useState)(null),[g,f]=(0,i.useState)(""),[x,m]=(0,i.useState)([]),[v,y]=(0,i.useState)(null),[k,j]=(0,i.useState)(null),[R,I]=(0,i.useState)(!0),L=(0,i.useCallback)(async e=>{I(!0),j(null);try{let t=await S(e),r=t.path??e??"/";u(r),h(t.parentPath??null),f(r),m(t.directories??[]),y(t.drives??null)}catch(e){j(e instanceof Error?e.message:String(e))}finally{I(!1)}},[]);(0,i.useEffect)(()=>{d(document.body),L()},[L]);let E=g.trim()!==c,W=!!c&&!E&&!r,z=!!p||/^[a-zA-Z]:[\\/]?$/.test(c);return s?(0,o.createPortal)((0,n.jsx)("div",{className:"directory-picker-backdrop",role:"dialog","aria-modal":"true","aria-label":a("directoryPicker.selectDirectory"),onClick:t=>{t.target!==t.currentTarget||r||e()},onKeyDown:t=>{"Escape"!==t.key||r||e()},style:{position:"fixed",inset:0,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.35)"},children:(0,n.jsxs)("div",{className:"directory-picker-panel",style:{width:520,maxWidth:"calc(100vw - 16px)",height:"min(620px, calc(100dvh - 16px))",maxHeight:"calc(100dvh - 16px)",display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 8px 32px rgba(0,0,0,0.18)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0,padding:"12px 18px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{minWidth:0,flex:1},children:(0,n.jsx)("div",{style:{color:"var(--text)",fontWeight:700,fontSize:15},children:a("directoryPicker.selectDirectory")})}),(0,n.jsx)("button",{type:"button",onClick:e,disabled:r,title:a("i18n.close"),"aria-label":a("i18n.close"),style:{padding:"2px 6px",border:0,background:"none",color:"var(--text-muted)",fontSize:20,lineHeight:1,cursor:r?"default":"pointer",opacity:r?.5:1},children:"\xd7"})]}),(0,n.jsxs)("form",{onSubmit:e=>{e.preventDefault();let t=g.trim();t&&L(t)},style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,padding:"10px 14px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("button",{className:"directory-picker-back",type:"button",onClick:()=>void L(p??void 0),disabled:R||!z,title:a("directoryPicker.goToParent"),"aria-label":a("directoryPicker.goToParent"),style:{width:36,height:36,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:z?"pointer":"default",opacity:z?1:.45},children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"m18 15-6-6-6 6"})})}),(0,n.jsx)("label",{htmlFor:"directory-path",style:{position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:0},children:a("directoryPicker.directoryPath")}),(0,n.jsx)("input",{className:"directory-picker-path",id:"directory-path",type:"text",value:g,placeholder:"/path/to/project or ~/project",autoFocus:!0,autoComplete:"off",spellCheck:!1,onChange:e=>{f(e.target.value),j(null)},onPaste:e=>{let t=w(e.clipboardData);t.length>0&&(e.preventDefault(),f(t[0]),j(null))},style:{minWidth:0,flex:1,height:36,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,outline:"none",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12}}),(0,n.jsx)("button",{className:"directory-picker-action",type:"submit",disabled:R||!g.trim(),title:a("directoryPicker.goToDirectory"),style:{minWidth:58,height:36,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:R||!g.trim()?"default":"pointer",opacity:R||!g.trim()?.6:1},children:a("directoryPicker.go")})]}),(0,n.jsxs)("div",{className:"directory-picker-list",style:{flex:1,minHeight:0,overflow:"auto",padding:"8px 10px"},children:[R?(0,n.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:a("directoryPicker.loadingDirectories")}):null!==v?(0,n.jsx)(n.Fragment,{children:v.length>0?v.map(e=>(0,n.jsxs)("button",{className:"directory-picker-entry",type:"button",onClick:()=>void L(e.path),title:e.path,style:{width:"100%",minHeight:34,display:"flex",alignItems:"center",gap:7,padding:"6px 8px",border:0,borderRadius:5,background:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-mono)",fontSize:11},children:[(0,n.jsx)(T,{}),(0,n.jsx)("span",{children:e.name})]},e.path)):(0,n.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:a("directoryPicker.noDrives")})}):x.length>0?x.map(e=>(0,n.jsxs)("button",{className:"directory-picker-entry",type:"button",onClick:()=>void L(e.path),title:e.path,style:{width:"100%",minHeight:30,display:"flex",alignItems:"center",gap:7,padding:"5px 8px",border:0,borderRadius:5,background:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-mono)",fontSize:11},children:[(0,n.jsx)(C,{}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.path)):(0,n.jsx)("div",{style:{padding:8,color:"var(--text-dim)",fontSize:11},children:a("directoryPicker.noSubdirectories")}),(k||l)&&(0,n.jsx)("div",{style:{padding:"8px",color:"#dc2626",fontSize:11},children:k??l})]}),(0,n.jsxs)("div",{className:"directory-picker-footer",style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:10,flexShrink:0,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,n.jsx)("button",{className:"directory-picker-action",type:"button",onClick:e,disabled:r,style:{padding:"6px 14px",border:"1px solid var(--border)",borderRadius:6,background:"none",color:"var(--text-muted)",cursor:r?"default":"pointer",fontSize:13},children:a("i18n.cancel")}),(0,n.jsx)("button",{className:"directory-picker-action",type:"button",onClick:()=>t(c),disabled:!W,title:a(E?"directoryPicker.openBeforeSelecting":"directoryPicker.selectCurrentDirectory"),style:{padding:"6px 16px",border:0,borderRadius:6,background:"var(--accent)",color:"#fff",fontSize:13,fontWeight:600,opacity:W?1:.6,cursor:W?"pointer":"default"},children:a(r?"i18n.checking":"directoryPicker.selectThisFolder")})]})]})}),s):null}let R="/icons/catppuccin";function I({name:e,size:t=14}){let r={width:t,height:t,"--catppuccin-icon-light":`url(${R}/latte/${e}.svg)`,"--catppuccin-icon-dark":`url(${R}/mocha/${e}.svg)`};return(0,n.jsx)("span",{"aria-hidden":"true",className:"catppuccin-file-icon",style:r})}function L({size:e=14,open:t=!1}){return(0,n.jsx)(I,{name:t?"_folder_open":"_folder",size:e})}function E({size:e=14}){return(0,n.jsx)(I,{name:"_file",size:e})}let W={ts:"typescript",tsx:"typescript-react",js:"javascript",mjs:"javascript",cjs:"javascript",jsx:"javascript-react",py:"python",json:"json",jsonl:"json",css:"css",less:"css",scss:"sass",html:"html",htm:"html",md:"markdown",mdx:"markdown",yaml:"yaml",yml:"yaml",toml:"toml",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",rs:"rust",go:"go",sql:"database",graphql:"graphql",gql:"graphql",tf:"terraform",hcl:"terraform",docx:"ms-word",pdf:"pdf",lock:"lock"};function z(e,t=14){let r=e.toLowerCase(),i="dockerfile"===r||r.startsWith("dockerfile.")?"docker":".env"===r||r.startsWith(".env.")?"env":[".gitignore",".gitattributes",".gitmodules"].includes(r)?"git":"package-lock.json"===r?"npm-lock":"bun.lock"===r?"bun-lock":["next.config.js","next.config.mjs","next.config.cjs","next.config.ts"].includes(r)?"next":[".eslintrc",".eslintrc.js",".eslintrc.json",".eslintrc.yml","eslint.config.mjs","eslint.config.js"].includes(r)?"eslint":["yarn.lock","pnpm-lock.yaml","cargo.lock"].includes(r)?"lock":r.endsWith(".config.ts")||r.endsWith(".config.js")||r.endsWith(".config.mjs")||r.endsWith(".config.cjs")?"config":void 0;if(i)return(0,n.jsx)(I,{name:i,size:t});let o=W[r.split(".").pop()??""];return o?(0,n.jsx)(I,{name:o,size:t}):(0,n.jsx)(E,{size:t})}function $(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function P(e){return $(e).split("/").filter(Boolean).map(encodeURIComponent).join("/")}function A(e){let t=$(e).replace(/\/+$/,"");return t.split("/").pop()??t}function D(e){let t=$(e).replace(/\/+$/,""),r=t.lastIndexOf("/");return r<0?"":0===r?"/":2===r&&/^[a-zA-Z]:\//.test(t)?t.slice(0,3):t.slice(0,r)}function N(e,t){if(!t)return e;let r=$(e),n=$(t).replace(/\/$/,"");return r.startsWith(n+"/")?r.slice(n.length+1):e}function F(e,t){return`${$(e).replace(/\/$/,"")}/${t}`}async function B(e){let t=P(e),r=await fetch(`/api/files/${t}?type=list`);if(!r.ok){let e=`Failed to load files (HTTP ${r.status})`;try{let t=await r.json();t.error&&(e=t.error)}catch{}throw Error(e)}return((await r.json()).entries??[]).map(t=>({name:t.name,fullPath:F(e,t.name),isDir:t.isDir,size:t.size,children:t.isDir?[]:void 0,loaded:!t.isDir}))}async function H(e){let t=new URLSearchParams({cwd:e}),r=await fetch(`/api/git/status?${t.toString()}`);if(!r.ok)throw Error(`Failed to load Git status (HTTP ${r.status})`);return r.json()}let O={modified:"files.modified",added:"files.added",deleted:"files.deleted",renamed:"files.renamed",untracked:"files.untracked",conflict:"files.conflict"},U={modified:"#d6a84b",added:"#4ade80",deleted:"#f87171",renamed:"#60a5fa",untracked:"#4ade80",conflict:"#f87171"};function _({status:e,t}){return(0,n.jsx)("span",{title:t(O[e.status]),"aria-label":t(O[e.status]),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",color:U[e.status],fontFamily:"var(--font-mono)",fontSize:11,fontWeight:600},children:e.code})}function q({size:e=11}){return(0,n.jsxs)("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]})}function K({onClick:e,title:t}){return(0,n.jsx)("button",{type:"button",onClick:e,title:t,"aria-label":t,style:{width:24,height:24,padding:0,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"none",borderRadius:4,background:"none",color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"m6 6 12 12"}),(0,n.jsx)("path",{d:"m18 6-12 12"})]})})}function V({node:e,depth:t,cwd:r,onOpenFile:o,onAtMention:l,expandedPaths:a,onToggleExpanded:s,refreshToken:d,highlightedPaths:c,gitStatusByPath:u,changedDirectoryPaths:p,t:h}){let g=a.has(e.fullPath),f=c.has(e.fullPath),x=$(e.fullPath),m=u.get(x),v=e.isDir&&(void 0!==m||p.has(x)),[b,y]=(0,i.useState)(e.children??[]),[k,w]=(0,i.useState)(e.loaded??!1),[j,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(!1),M=(0,i.useCallback)(async(t=!1)=>{if(!k||t){S(!0);try{let t=await B(e.fullPath);y(t),w(!0)}catch{}finally{S(!1)}}},[k,e.fullPath]);(0,i.useEffect)(()=>{g&&k&&M(!0)},[d]);let R=(0,i.useCallback)(()=>{if(e.isDir){let t=!g;s(e.fullPath,t),t&&!k&&M()}else o(e.fullPath,e.name)},[e.isDir,e.fullPath,e.name,k,g,M,o,s]);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:R,onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1),style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*t,paddingRight:8,height:24,cursor:"pointer",background:C?"var(--side-hover)":"transparent",borderRadius:4,userSelect:"none"},children:[e.isDir&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:g?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),!e.isDir&&(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,n.jsx)(L,{size:14,open:g}):z(e.name,14)}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:e.fullPath,children:e.name}),f&&(0,n.jsx)("span",{title:h("files.newlyUploaded"),"aria-label":h("files.newlyUploaded"),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"#3b82f6"}})}),!C&&!e.isDir&&m&&(0,n.jsx)(_,{status:m,t:h}),!C&&v&&(0,n.jsx)("span",{title:h("files.containsChangedFiles"),"aria-label":h("files.containsChangedFiles"),style:{width:14,height:14,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"#d6a84b"}})}),j&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),l&&C&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),l(N(e.fullPath,r),e.isDir)},title:h("files.insertPath"),style:{position:"absolute",right:e.isDir?4:28,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--side-input)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsx)(q,{}),h("files.mention")]}),C&&!e.isDir&&(0,n.jsx)("a",{href:`/api/files/${P(e.fullPath)}?type=download`,download:!0,onClick:e=>e.stopPropagation(),title:h("files.download"),style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 5px",height:20,background:"var(--side-input)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap",textDecoration:"none"},children:(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),e.isDir&&g&&(0,n.jsxs)("div",{children:[b.map(e=>(0,n.jsx)(V,{node:e,depth:t+1,cwd:r,onOpenFile:o,onAtMention:l,expandedPaths:a,onToggleExpanded:s,refreshToken:d,highlightedPaths:c,gitStatusByPath:u,changedDirectoryPaths:p,t:h},e.fullPath)),0===b.length&&k&&(0,n.jsx)("div",{style:{paddingLeft:8+(t+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"})]})]})}function J({status:e,cwd:t,onOpenFile:r,t:o}){let[l,a]=(0,i.useState)(!1),s=A(e.filePath),d=N(e.filePath,t);return(0,n.jsxs)("div",{onClick:()=>r(e.filePath,s,{modeHint:"diff"}),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),title:e.filePath,style:{display:"flex",alignItems:"center",gap:6,paddingLeft:10,paddingRight:8,height:24,cursor:"pointer",background:l?"var(--side-hover)":"transparent",borderRadius:4,userSelect:"none"},children:[(0,n.jsx)(_,{status:e,t:o}),(0,n.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center",opacity:.85},children:z(s,13)}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:d})]})}let Y=(0,i.forwardRef)(function({cwd:e,onOpenFile:t,refreshKey:r,onAtMention:o,onAtMentions:l,onUploadBusyChange:a,changesCollapsed:s,onChangesCountChange:d},c){let{t:u}=(0,b.s)(),[p,h]=(0,i.useState)([]),[g,f]=(0,i.useState)(!0),[x,m]=(0,i.useState)(null),[v,y]=(0,i.useState)(new Set),[k,w]=(0,i.useState)(0),[j,S]=(0,i.useState)(new Set),[C,T]=(0,i.useState)([]),[M,R]=(0,i.useState)({additions:0,deletions:0}),[I,L]=(0,i.useState)("idle"),[E,W]=(0,i.useState)(0),[z,A]=(0,i.useState)(null),[O,_]=(0,i.useState)(null),[Y,X]=(0,i.useState)(null),Z=(0,i.useRef)(null),G=(0,i.useRef)(null),Q=`${r??0}:${k}`,ee="idle"!==I,et=(0,i.useMemo)(()=>new Map(C.map(e=>[$(e.filePath),e])),[C]),er=(0,i.useMemo)(()=>{let t=new Set,r=$(e).replace(/\/$/,"");for(let e of C){let n=D($(e.filePath));for(;(n===r||n.startsWith(`${r}/`))&&(t.add(n),n!==r);){let e=D(n);if(e===n)break;n=e}}return t},[e,C]),en=(0,i.useCallback)((e,t)=>{y(r=>{let n=new Set(r);return t?n.add(e):n.delete(e),n})},[]),ei=(0,i.useCallback)(t=>{let r=t.uploaded??[];_({uploaded:r,skipped:t.skipped??[],errors:t.errors??[]}),r.length>0&&(S(new Set(r.map(t=>F(e,t)))),w(e=>e+1))},[e]),eo=(0,i.useCallback)(async(t,r)=>{X(null),A(null),W(0),L("uploading");try{let{status:n,data:i}=await new Promise((n,i)=>{let o=new FormData;t.forEach(e=>o.append("files",e,e.name));let l=new XMLHttpRequest;l.open("POST",`/api/files/${P(e)}?type=upload&conflict=${r}`),l.upload.onprogress=e=>{e.lengthComputable&&e.total>0&&W(Math.round(e.loaded/e.total*100))},l.onerror=()=>i(Error("Network error while uploading files")),l.onabort=()=>i(Error("Upload cancelled")),l.onload=()=>{let e={};try{e=JSON.parse(l.responseText)}catch{l.responseText&&(e.error=l.responseText)}n({status:l.status,data:e})},l.send(o)});if(409===n&&i.conflicts?.length)return void X({files:t,conflicts:i.conflicts,nonReplaceable:i.nonReplaceable??[]});if(n<200||n>=300)throw Error(i.error??`Upload failed (HTTP ${n})`);W(100),ei(i)}catch(e){A(e instanceof Error?e.message:String(e))}finally{L("idle")}},[ei,e]),el=(0,i.useCallback)(async t=>{if(0!==t.length&&!ee){_(null),S(new Set),X(null),A(null),W(0),L("checking");try{let r=await fetch(`/api/files/${P(e)}?type=upload-check`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileNames:t.map(e=>e.name)})}),n=await r.json().catch(()=>({}));if(!r.ok)throw Error(n.error??`Upload check failed (HTTP ${r.status})`);if(n.conflicts?.length)return void X({files:t,conflicts:n.conflicts,nonReplaceable:n.nonReplaceable??[]});await eo(t,"error")}catch(e){A(e instanceof Error?e.message:String(e))}finally{L("idle")}}},[e,eo,ee]),ea=(0,i.useCallback)(e=>{let t=Array.from(e.target.files??[]);e.target.value="",el(t)},[el]);(0,i.useImperativeHandle)(c,()=>({openUploadPicker(){ee||G.current?.click()}}),[ee]),(0,i.useEffect)(()=>{a?.(ee)},[a,ee]),(0,i.useEffect)(()=>()=>a?.(!1),[a]),(0,i.useEffect)(()=>{let t=Z.current!==e;Z.current=e,t&&(y(new Set),S(new Set),_(null),X(null),A(null)),f(t),m(null);let r=!1;return B(e).then(e=>{r||h(e)}).catch(e=>{r||m(e instanceof Error?e.message:String(e))}).finally(()=>{r||f(!1)}),()=>{r=!0}},[e,r,k]),(0,i.useEffect)(()=>{let t=!1;return H(e).then(e=>{t||(T(e.isGitRepository?e.files:[]),R(e.isGitRepository?{additions:e.additions,deletions:e.deletions}:{additions:0,deletions:0}))}).catch(()=>{t||(T([]),R({additions:0,deletions:0}))}),()=>{t=!0}},[e,r,k]),(0,i.useEffect)(()=>{d?.(C.length)},[C,d]);let es=ee||null!==Y||null!==z||null!==O,ed=(0,i.useCallback)(()=>{O&&0!==O.uploaded.length&&l?.(O.uploaded.map(t=>N(F(e,t),e)))},[e,l,O]);return(0,n.jsxs)("div",{style:{minHeight:"100%"},children:[(0,n.jsx)("input",{ref:G,type:"file",multiple:!0,hidden:!0,onChange:ea}),es&&(0,n.jsxs)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:[ee&&(0,n.jsxs)("div",{role:"status","aria-live":"polite","aria-label":"checking"===I?u("files.checking"):u("files.uploading",{progress:E}),children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,minHeight:14,color:"var(--text-muted)"},children:["checking"===I?(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",style:{animation:"spin 0.8s linear infinite"},"aria-hidden":"true",children:(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-5.7-8.4"})}):(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M12 16V4"}),(0,n.jsx)("path",{d:"m7 9 5-5 5 5"}),(0,n.jsx)("path",{d:"M5 20h14"})]}),"uploading"===I&&(0,n.jsxs)("span",{style:{fontSize:10},children:[E,"%"]})]}),"uploading"===I&&(0,n.jsx)("div",{style:{height:3,marginTop:4,overflow:"hidden",borderRadius:2,background:"var(--border)"},children:(0,n.jsx)("div",{style:{width:`${E}%`,height:"100%",background:"var(--text-muted)",transition:"width 120ms ease"}})})]}),Y&&(0,n.jsxs)("div",{role:"alert",style:{padding:7,border:"1px solid color-mix(in srgb, #f59e0b 55%, var(--border))",borderRadius:4,background:"color-mix(in srgb, #f59e0b 9%, var(--bg-panel))"},children:[(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text)",lineHeight:1.35,overflowWrap:"anywhere"},children:u("files.conflictSummary",{count:Y.conflicts.length,countSuffix:1===Y.conflicts.length?"":"s",files:Y.conflicts.join(", ")})}),Y.nonReplaceable.length>0&&(0,n.jsx)("div",{style:{marginTop:3,fontSize:10,color:"#f59e0b",lineHeight:1.35,overflowWrap:"anywhere"},children:u("files.cannotReplace",{files:Y.nonReplaceable.join(", ")})}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,marginTop:7},children:[(0,n.jsx)("button",{type:"button",onClick:()=>void eo(Y.files,"overwrite"),style:{height:22,padding:"0 7px",border:"1px solid #ef4444",borderRadius:4,background:"transparent",color:"#ef4444",cursor:"pointer",fontSize:10},children:u("files.replace")}),(0,n.jsx)("button",{type:"button",onClick:()=>void eo(Y.files,"skip"),style:{height:22,padding:"0 7px",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",fontSize:10},children:u("files.skipExisting")}),(0,n.jsx)("button",{type:"button",onClick:()=>X(null),style:{height:22,padding:"0 7px",border:"none",borderRadius:4,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:10},children:u("files.cancel")})]})]}),z&&(0,n.jsxs)("div",{role:"alert",style:{display:"flex",alignItems:"flex-start",gap:6,fontSize:11,lineHeight:1.35,color:"#f87171"},children:[(0,n.jsx)("span",{style:{minWidth:0,flex:1,overflowWrap:"anywhere"},children:z}),(0,n.jsx)(K,{onClick:()=>A(null),title:u("files.dismissError")})]}),O&&(0,n.jsxs)("div",{"aria-live":"polite",children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minHeight:22,fontSize:11},children:[(0,n.jsxs)("div",{style:{minWidth:0,flex:1,display:"flex",alignItems:"center",gap:8},children:[O.uploaded.length>0&&(0,n.jsxs)("span",{title:`${O.uploaded.length} uploaded`,"aria-label":`${O.uploaded.length} uploaded`,style:{display:"flex",alignItems:"center",gap:3,color:"#22c55e"},children:[(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"m5 12 4 4L19 6"})}),(0,n.jsx)("span",{children:O.uploaded.length})]}),O.skipped.length>0&&(0,n.jsxs)("span",{title:`${O.skipped.length} skipped`,"aria-label":`${O.skipped.length} skipped`,style:{display:"flex",alignItems:"center",gap:3,color:"var(--text-dim)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"M8 12h8"})]}),(0,n.jsx)("span",{children:O.skipped.length})]}),O.errors.length>0&&(0,n.jsxs)("span",{title:`${O.errors.length} failed`,"aria-label":`${O.errors.length} failed`,style:{display:"flex",alignItems:"center",gap:3,color:"#f87171"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M12 3 2.5 20h19L12 3Z"}),(0,n.jsx)("path",{d:"M12 9v4"}),(0,n.jsx)("path",{d:"M12 17h.01"})]}),(0,n.jsx)("span",{children:O.errors.length})]})]}),O.uploaded.length>0&&l&&(0,n.jsxs)("button",{type:"button",onClick:ed,title:1===O.uploaded.length?u("files.addUploadedFile"):u("files.addAllUploadedFiles"),"aria-label":1===O.uploaded.length?u("files.addUploadedFile"):u("files.addAllUploadedFiles"),style:{height:22,padding:"0 7px",display:"flex",alignItems:"center",justifyContent:"center",gap:4,flexShrink:0,border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsx)(q,{}),u("files.mention")]}),(0,n.jsx)(K,{onClick:()=>_(null),title:u("files.dismissUploadResults")})]}),O.errors.map(e=>(0,n.jsxs)("div",{title:e.error,style:{display:"flex",alignItems:"center",gap:4,marginTop:3,minWidth:0,fontSize:10,color:"#f87171"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},"aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"M12 8v5"}),(0,n.jsx)("path",{d:"M12 17h.01"})]}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.name))]})]}),!s&&C.length>0&&(0,n.jsxs)("div",{style:{padding:"0 4px 2px"},children:[(0,n.jsxs)("div",{"aria-label":u("files.changeStats",{count:C.length,additions:M.additions,deletions:M.deletions}),style:{display:"flex",alignItems:"center",gap:6,height:24,padding:"0 10px",fontSize:12},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)"},children:u("files.changedCount",{count:C.length})}),(0,n.jsxs)("span",{style:{color:U.added,fontFamily:"var(--font-mono)"},children:["+",M.additions]}),(0,n.jsxs)("span",{style:{color:U.deleted,fontFamily:"var(--font-mono)"},children:["-",M.deletions]})]}),C.map(r=>(0,n.jsx)(J,{status:r,cwd:e,onOpenFile:t,t:u},r.filePath))]}),(s||0===C.length)&&(0,n.jsxs)("div",{style:{padding:"2px 4px"},children:[g?(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."}):x?(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:x}):p.map(r=>(0,n.jsx)(V,{node:r,depth:0,cwd:e,onOpenFile:t,onAtMention:o,expandedPaths:v,onToggleExpanded:en,refreshToken:Q,highlightedPaths:j,gitStatusByPath:et,changedDirectoryPaths:er,t:u},r.fullPath)),!g&&!x&&0===p.length&&(0,n.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:u("files.noFiles")})]})]})});function X({onClick:e,title:t,disabled:r,skipHover:i,color:o,background:l="none",marginRight:a,ariaPressed:s,children:d}){return(0,n.jsx)("button",{onClick:e,disabled:r,title:t,"aria-label":t,"aria-pressed":s,style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,marginRight:a,background:l,border:"none",color:o,cursor:r?"default":"pointer",borderRadius:5,flexShrink:0,opacity:r?.6:1,transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{r||i||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="var(--side-hover)")},onMouseLeave:e=>{r||i||(e.currentTarget.style.color=o,e.currentTarget.style.background=l)},children:d})}let Z="pi-web:unread-session-ids";function G(e,t){return t&&e.startsWith(t)?"~"+e.slice(t.length):e}function Q({text:e,style:t}){return(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block",minWidth:0,lineHeight:1.35,direction:"rtl",textAlign:"left",...t},children:(0,n.jsx)("span",{style:{unicodeBidi:"plaintext"},children:e})})}function ee({open:e,children:t,style:r}){let[o,l]=(0,i.useState)(e),[a,s]=(0,i.useState)(e);return((0,i.useEffect)(()=>{let t,r;return e?(l(!0),s(!1),t=window.requestAnimationFrame(()=>{t=window.requestAnimationFrame(()=>s(!0))})):(s(!1),r=setTimeout(()=>l(!1),140)),()=>{void 0!==t&&window.cancelAnimationFrame(t),r&&clearTimeout(r)}},[e]),o)?(0,n.jsx)("div",{style:{...r,opacity:+!!a,transform:a?"translateY(0) scale(1)":"translateY(-8px) scale(0.96)",transformOrigin:"top center",transition:"opacity 140ms ease, transform 140ms ease",pointerEvents:e?"auto":"none"},children:t}):null}let et="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";function er(){let[e,t]=(0,i.useState)(!1),[r,o]=(0,i.useState)(!1),l=(0,i.useRef)(null),a=function(e,t){let[r,n]=(0,i.useState)(e),o=(0,i.useRef)(null),l=(0,i.useRef)(0);return(0,i.useEffect)(()=>{if(!t)return void n(e);l.current=0;let r=4*e.length,i=()=>{l.current+=1;let t=Math.floor(l.current/r*e.length);n(e.split("").map((e,r)=>" "===e?" ":r<t?e:et[Math.floor(Math.random()*et.length)]).join("")),l.current<r?o.current=requestAnimationFrame(i):n(e)};return o.current=requestAnimationFrame(i),()=>{o.current&&cancelAnimationFrame(o.current)}},[e,t]),r}(e?"0.1.22p0.84.2":"Pi Web",r),s=(0,i.useCallback)(e=>{t(e),o(!0),setTimeout(()=>o(!1),(e?6:8)*4*(1e3/60)+100)},[]),d=(0,i.useCallback)(()=>{l.current&&clearTimeout(l.current);let t=!e;s(t),t&&(l.current=setTimeout(()=>s(!1),3e3))},[e,s]);return(0,i.useEffect)(()=>()=>{l.current&&clearTimeout(l.current)},[]),(0,n.jsx)("button",{onClick:d,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:e?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"6ch"},children:a})}function en({selectedSessionId:e,onSelectSession:t,onNewSession:r,initialSessionId:o,skipInitialProjectSelection:l,onInitialRestoreDone:a,refreshKey:s,onSessionDeleted:u,selectedCwd:p,onCwdChange:h,onOpenFile:g,explorerRefreshKey:f,onExplorerRefresh:x,onAtMention:y,onAtMentions:k,onBackgroundTaskDone:w,onRunningSessionIdsChange:j}){var S;let{t:C}=(0,b.s)(),[T,R]=(0,i.useState)([]),[I,L]=(0,i.useState)(!0),[E,W]=(0,i.useState)(null),[z,$]=(0,i.useState)(null),[P,A]=(0,i.useState)(""),[D,N]=(0,i.useState)(!1),[F,B]=(0,i.useState)(""),[H,O]=(0,i.useState)(""),[U,_]=(0,i.useState)(!1),[q,K]=(0,i.useState)(""),[V,J]=(0,i.useState)(null),[et,eo]=(0,i.useState)(!1),[el,ea]=(0,i.useState)(null),es=(0,i.useRef)(null),[ed,ec]=(0,i.useState)(null),[eu,ep]=(0,i.useState)(!1),[eh,eg]=(0,i.useState)(!1),[ef,ex]=(0,i.useState)(""),[em,ev]=(0,i.useState)(null),[eb,ey]=(0,i.useState)(!1),[ek,ew]=(0,i.useState)(null),[ej,eS]=(0,i.useState)(null),eC=(0,i.useRef)(null),eT=(0,i.useRef)(null),[eM,eR]=(0,i.useState)(!0),[eI,eL]=(0,i.useState)(0),[eE,eW]=(0,i.useState)(!1),[ez,e$]=(0,i.useState)(0),[eP,eA]=(0,i.useState)(!0),[eD,eN]=(0,i.useState)(!1),[eF,eB]=(0,i.useState)(!1),[eH,eO]=(0,i.useState)(()=>new Set),[eU,e_]=(0,i.useState)(()=>(function(){try{let e=window.localStorage.getItem(Z);if(!e)return new Set;let t=JSON.parse(e);if(Array.isArray(t))return new Set(t.filter(e=>"string"==typeof e));return new Set}catch{return new Set}})()),eq=(0,i.useRef)(new Set),eK=(0,i.useRef)(!1),eV=(0,i.useRef)(null),eJ=(0,i.useRef)(null),eY=(0,i.useRef)(null),eX=(0,i.useCallback)(async(e=!1,t=!1)=>{try{e&&L(!0);let r=await fetch(t?"/api/sessions?force=1":"/api/sessions",{cache:"no-store"});if(!r.ok)throw Error(`HTTP ${r.status}`);let n=await r.json();R(n.sessions),eK.current||eO(new Set(n.runningSessionIds??[]));let i=new Set(n.sessions.map(e=>e.id));e_(e=>{if(0===e.size)return e;let t=new Set([...e].filter(e=>i.has(e)));return t.size===e.size?e:t}),W(null),e||(eN(!0),eV.current&&clearTimeout(eV.current),eV.current=setTimeout(()=>eN(!1),2e3))}catch(e){W(String(e))}finally{e&&L(!1)}},[]),eZ=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let e=!eZ.current;eZ.current=!0,eX(e,!e)},[eX,s]),(0,i.useEffect)(()=>{eR(function(e=c()){if(!e)return!0;try{return"false"!==e.getItem(d)}catch{return!0}}())},[]),(0,i.useEffect)(()=>{try{0===eU.size?window.localStorage.removeItem(Z):window.localStorage.setItem(Z,JSON.stringify([...eU]))}catch{}},[eU]),(0,i.useEffect)(()=>{let e=!1,t=null,r=null,n=()=>{t&&clearTimeout(t),t=null},i=async()=>{if(e||"visible"!==document.visibilityState)return;let o=new AbortController;r?.abort(),r=o;try{let t=await fetch("/api/agent/running",{cache:"no-store",signal:o.signal});if(!t.ok)return;let n=await t.json();if(e||r!==o)return;eK.current=!0,eO(new Set(n.runningSessionIds??[]))}catch{}finally{r===o&&(r=null),n(),e||"visible"!==document.visibilityState||(t=setTimeout(()=>void i(),2500))}},o=()=>{"visible"===document.visibilityState?i():(n(),r?.abort(),r=null)};return i(),document.addEventListener("visibilitychange",o),()=>{e=!0,n(),r?.abort(),document.removeEventListener("visibilitychange",o)}},[]),(0,i.useEffect)(()=>{j?.(eH)},[j,eH]),(0,i.useEffect)(()=>{let t=eq.current,r=[...t].filter(t=>!eH.has(t)&&t!==e),n=[...eH].filter(e=>!t.has(e));(r.length>0||n.length>0)&&e_(e=>{let t=new Set(e);return eH.forEach(e=>t.delete(e)),r.forEach(e=>t.add(e)),t});let i=n.some(e=>!T.some(t=>t.id===e));(r.length>0||i)&&eX(!1,!0),r.length>0&&w?.(),eq.current=eH},[eH,e,T,eX,w]),(0,i.useEffect)(()=>{e&&e_(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),r})},[e]),(0,i.useEffect)(()=>{void 0!==f&&eL(e=>e+1)},[f]),(0,i.useEffect)(()=>{fetch("/api/home").then(e=>e.json()).then(e=>{e.home&&A(e.home)}).catch(()=>{})},[]);let eG=(0,i.useRef)(!1),eQ=(0,i.useCallback)((e,t)=>({root:e,key:t}),[]),e0=(0,i.useCallback)(e=>{if(!e)return null;if(el?.cwd===e)return eQ(el.root,el.key);if(ed&&ed.forCwd===e||ed?.worktrees.some(t=>t.path===e))return eQ(ed.projectRoot,ed.projectKey);let t=T.find(t=>t.cwd===e||(t.projectRoot??t.cwd)===e);return t?eQ(t.projectRoot??t.cwd,m(t)):eQ(e,e)},[el,ed,T,eQ]),e1=(0,i.useRef)(null);(0,i.useEffect)(()=>{let e=e0(z),t=e1.current;(t?.cwd!==z||t.key!==(e?.key??null))&&(e1.current={cwd:z,key:e?.key??null},h?.(z,e?.root??null,e?.key??null))},[z,h,e0]);let e2=(0,i.useRef)(null);(0,i.useEffect)(()=>{p&&p!==e2.current&&(e2.current=p,$(p))},[p]);let[e8,e4]=(0,i.useState)(0);(0,i.useLayoutEffect)(()=>{if(!z){ec(null),eS(null);return}let e=!1;return eS(z),fetch(`/api/worktrees?cwd=${encodeURIComponent(z)}`).then(e=>e.json()).then(t=>{if(!e){if(eS(null),t.error||!t.projectRoot)return void ec(null);ec({forCwd:z,projectRoot:t.projectRoot,projectKey:t.projectKey??t.projectRoot,isGit:t.isGit??!1,isTopLevel:t.isTopLevel??!1,currentWorktreePath:t.currentWorktreePath??null,worktrees:t.worktrees??[]})}}).catch(()=>{e||(eS(null),ec(null))}),()=>{e=!0}},[z,e8,s]),(0,i.useEffect)(()=>{if(0!==T.length&&!l&&null===z){if(o&&!eG.current){eG.current=!0;let e=T.find(e=>e.id===o);if(e){$(e.cwd),t(e,!0);return}a?.()}let e=v(T);e.length>0&&$(e[0].root)}},[T,z,o,l,t,a]);let e6=ed?ed.worktrees.find(e=>e.path===z)??(ed.forCwd===z&&ed.currentWorktreePath?ed.worktrees.find(e=>e.path===ed.currentWorktreePath):void 0)??ed.worktrees.find(e=>e.isMain):void 0,e5=e6?.path??null,e3=(0,i.useCallback)(async e=>{let t=(e??q).trim();if(t&&!et){eo(!0),J(null);try{let e=await fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t})}),r=await e.json().catch(()=>({}));if(!e.ok||r.error||!r.cwd||!r.projectRoot||!r.projectKey)return void J(r.error??`HTTP ${e.status}`);ea({cwd:r.cwd,root:r.projectRoot,key:r.projectKey}),$(r.cwd),_(!1),K(""),N(!1)}catch(e){J(e instanceof Error?e.message:String(e))}finally{eo(!1)}}},[q,et]),e7=(0,i.useCallback)(()=>{_(!0),J(null),N(!1)},[]),e9=(0,i.useCallback)(async()=>{try{let e=await fetch("/api/default-cwd",{method:"POST"}),t=await e.json();t.cwd&&($(t.cwd),_(!1),K(""),J(null),N(!1))}catch{}},[]),te=(0,i.useCallback)(async()=>{let e=ef.trim();if(e&&!eb&&ed){ey(!0),ev(null);try{let t=await fetch("/api/worktrees",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:ed.projectRoot,branch:e})}),r=await t.json().catch(()=>({}));if(!t.ok||r.error||!r.path)return void ev(r.error??`HTTP ${t.status}`);eg(!1),ex(""),ep(!1),ec(t=>t?{...t,forCwd:r.path,currentWorktreePath:r.path,worktrees:[...t.worktrees,{path:r.path,branch:e,isMain:!1}]}:t),$(r.path),e4(e=>e+1)}catch(e){ev(e instanceof Error?e.message:String(e))}finally{ey(!1)}}},[ef,eb,ed]),tt=(0,i.useCallback)(async(e,t)=>{if(ed&&!eb){ey(!0),ev(null);try{let r=await fetch("/api/worktrees",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:ed.projectRoot,path:e,force:t})}),n=await r.json().catch(()=>({}));if(!r.ok){if(n.dirty&&!t)return void ew(e);ev(n.error??`HTTP ${r.status}`);return}ew(null),e5===e&&$(ed.projectRoot),e4(e=>e+1)}catch(e){ev(e instanceof Error?e.message:String(e))}finally{ey(!1)}}},[ed,eb,e5]);(0,i.useEffect)(()=>{let e=e=>{es.current&&!es.current.contains(e.target)&&(N(!1),B("")),eC.current&&!eC.current.contains(e.target)&&(ep(!1),eg(!1),ex(""),ev(null),ew(null),O(""))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let tr=(0,i.useCallback)(e=>{e.cwd&&$(e.cwd),t(e)},[t]),tn=(0,i.useCallback)(()=>{if(!z)return;let e="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;r?.(e,z)},[z,r]),ti=v(T),to=ti.length>8,tl=F.trim()?ti.filter(e=>e.root.toLowerCase().includes(F.trim().toLowerCase())):ti,ta=e0(z),ts=(0,i.useMemo)(()=>(function(e,t,r){let n=new Map;for(let i of e){let e=m(i);if(!e)continue;let o=n.get(e);o||(o={running:0,unread:0},n.set(e,o)),t.has(i.id)&&o.running++,r.has(i.id)&&o.unread++}return n})(T,eH,eU),[T,eH,eU]),td=(0,i.useMemo)(()=>[...ts.entries()].some(([e,{running:t,unread:r}])=>e!==ta?.key&&(t>0||r>0)),[ts,ta]),tc=ta?(S=ta.key,T.filter(e=>m(e)===S)):T,tu=!!(ed?.isGit&&ed.isTopLevel&&z&&ta?.key===ed.projectKey),tp=z&&ed&&ta?.key===ed.projectKey&&!tu?ed.isGit?{label:C("sidebar.openRepoRoot"),title:C("sidebar.openRepoRootTitle")}:{label:C("sidebar.gitRepoRootOnly"),title:C("sidebar.gitRepoRootOnlyTitle")}:null,th=!!(z&&ej===z),tg=tp??(th&&!tu?{label:C("sidebar.worktrees"),title:C("sidebar.checkingWorktrees")}:null),tf=function(e){let t=new Map;for(let r of e)t.set(r.id,{session:r,children:[]});let r=new Map;for(let t of e)t.parentSessionId&&r.set(t.id,t.parentSessionId);let n=[];for(let e of t.values()){let i=function(e){let n=r.get(e),i=new Set;for(;n&&!i.has(n);){if(i.add(n),t.has(n))return n;n=r.get(n)}return null}(e.session.id);i?t.get(i).children.push(e):n.push(e)}let i=e=>{e.sort((e,t)=>t.session.modified.localeCompare(e.session.modified)),e.forEach(e=>i(e.children))};return i(n),n}(tc);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[U&&(0,n.jsx)(M,{busy:et,error:V,onCancel:()=>{_(!1),J(null)},onSelect:e=>void e3(e)}),(0,n.jsxs)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:10},children:[(0,n.jsx)(er,{}),(0,n.jsxs)("div",{style:{display:"flex",gap:2,alignItems:"center"},children:[(0,n.jsxs)("button",{onClick:tn,disabled:!z,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:"transparent",border:"none",color:z?"var(--text-muted)":"var(--text-dim)",cursor:z?"pointer":"not-allowed",padding:"3px 6px",borderRadius:4,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,textDecoration:"none",transition:"color 0.12s"},title:z?C("sidebar.newSessionTitle",{path:z}):C("sidebar.selectProject"),onMouseEnter:e=>{z&&(e.currentTarget.style.color="var(--accent)",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{e.currentTarget.style.color=z?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.textDecoration="none"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,n.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),C("sidebar.new")]}),(0,n.jsxs)("button",{onClick:()=>eX(!1,!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,background:eD?"rgba(74,222,128,0.12)":"transparent",border:"none",color:eD?"#4ade80":"var(--text-muted)",cursor:"pointer",padding:"3px 6px",borderRadius:4,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,textDecoration:"none",transition:"color 0.3s, background 0.3s"},onMouseEnter:e=>{eD||(e.currentTarget.style.color="var(--accent)",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{eD||(e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.textDecoration="none")},title:C("sidebar.refresh"),children:[eD?(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]}),C("sidebar.refresh")]})]})]}),(0,n.jsxs)("div",{ref:es,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>N(e=>!e),title:ta?.root??z??"",style:{width:"100%",display:"flex",alignItems:"center",padding:"6px 10px",background:z?"transparent":"color-mix(in srgb, var(--accent) 8%, transparent)",border:z?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left",transition:"border-color 0.15s, background 0.15s"},children:[z?(0,n.jsx)(Q,{text:G(ta?.root??z,P),style:{flex:1,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text)"}}):(0,n.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:o&&!eG.current?"":C("sidebar.selectProject")}),td&&(0,n.jsx)("span",{title:C("sidebar.newActivity"),"aria-label":C("sidebar.newActivity"),style:{width:8,height:8,borderRadius:"50%",flexShrink:0,marginLeft:6,background:"var(--accent)"}})]}),(0,n.jsxs)(ee,{open:D,style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--panel-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden"},children:[to&&(0,n.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,n.jsx)("input",{value:F,onChange:e=>B(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(B(""),N(!1))},placeholder:C("sidebar.filterProjects"),autoFocus:!0,style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,outline:"none",background:"var(--side-input)",color:"var(--text)",boxSizing:"border-box"}})}),(0,n.jsxs)("div",{style:{maxHeight:"min(50vh, 380px)",overflowY:"auto"},children:[tl.map(e=>{var t,r;return(0,n.jsxs)("button",{onClick:()=>{$(e.root),B(""),_(!1),K(""),J(null),N(!1)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"transparent",border:"none",borderBottom:"1px solid var(--border)",color:e.key===ta?.key?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.root,onMouseEnter:e=>{e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:[e.key===ta?.key&&(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}),e.key!==ta?.key&&(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)(Q,{text:G(e.root,P),style:{flex:1}}),(t=ts.get(e.key),r=C,t&&(0!==t.running||0!==t.unread)?(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:5,flexShrink:0,marginLeft:6},children:[t.running>0&&(0,n.jsxs)("span",{title:r("sidebar.agentRunning"),"aria-label":`${r("sidebar.agentRunning")} (${t.running})`,style:{display:"inline-flex",alignItems:"center",gap:3,color:"var(--accent)",fontSize:10,fontFamily:"var(--font-mono)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block"},children:(0,n.jsxs)("g",{children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-3.8-7.4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"}),(0,n.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})]})}),t.running]}),t.unread>0&&(0,n.jsxs)("span",{title:r("sidebar.newSessionActivity"),"aria-label":`${r("sidebar.newSessionActivity")} (${t.unread})`,style:{display:"inline-flex",alignItems:"center",gap:3,color:"#0891b2",fontSize:10,fontFamily:"var(--font-mono)"},children:[(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:"currentColor",display:"inline-block"}}),t.unread]})]}):null)]},e.key)}),0===tl.length&&F.trim()&&(0,n.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:C("sidebar.noMatchingProjects")})]}),!U&&(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),e9()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:tl.length>0?"1px solid var(--border)":"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("path",{d:"M1 3A1 1 0 0 1 2 2H4L5 3.5H8.5a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5h-7A.5.5 0 0 1 1 8V3Z"})}),(0,n.jsx)("span",{children:C("sidebar.useDefaultDirectory")})]}),(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),e7()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,n.jsx)("span",{children:C("sidebar.customPath")})]})]})]}),tu&&(()=>{if(!ed)return null;let e=ed.worktrees.length>=8,t=e&&H.trim()?ed.worktrees.filter(e=>(e.branch??G(e.path,P)).toLowerCase().includes(H.trim().toLowerCase())):ed.worktrees;return(0,n.jsxs)("div",{ref:eC,style:{position:"relative",marginTop:6},children:[(0,n.jsxs)("button",{onClick:()=>ep(e=>!e),title:e6?C("sidebar.switchWorktreeTitle",{path:e6.path}):C("sidebar.switchWorktree"),style:{width:"100%",height:29,boxSizing:"border-box",display:"flex",alignItems:"center",gap:6,padding:"0 10px",background:"transparent",border:"1px solid var(--border)",borderRadius:7,cursor:"pointer",fontSize:11,lineHeight:1.35,color:"var(--text-muted)",textAlign:"left"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:e6&&!e6.isMain?"var(--accent)":"var(--text-dim)"},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsx)(Q,{text:e6?e6.branch??G(e6.path,P):"…",style:{flex:1,fontFamily:"var(--font-mono)",color:"var(--text)"}}),e6?.isMain&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:C("sidebar.main")}),ed.worktrees.length>1&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:ed.worktrees.length}),(0,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),(0,n.jsxs)(ee,{open:eu,style:{position:"absolute",top:"calc(100% + 4px)",left:0,right:0,zIndex:100,background:"var(--panel-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden"},children:[e&&(0,n.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)"},children:(0,n.jsx)("input",{value:H,onChange:e=>O(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(O(""),ep(!1))},placeholder:C("sidebar.filterWorktrees"),autoFocus:!0,style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,outline:"none",background:"var(--side-input)",color:"var(--text)",boxSizing:"border-box"}})}),(0,n.jsxs)("div",{style:{maxHeight:"min(40vh, 300px)",overflowY:"auto"},children:[t.map(e=>{let t=e.path===e5;return ek===e.path?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"rgba(239,68,68,0.06)"},children:[(0,n.jsx)("span",{style:{flex:1,fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C("sidebar.forceRemoveCheckout")}),(0,n.jsx)("button",{onClick:()=>void tt(e.path,!0),disabled:eb,style:{padding:"3px 9px",background:"#ef4444",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:"pointer",flexShrink:0},children:C("sidebar.force")}),(0,n.jsx)("button",{onClick:()=>ew(null),style:{padding:"3px 9px",background:"transparent",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer",flexShrink:0},children:C("sidebar.cancel")})]},e.path):(0,n.jsxs)("div",{className:"wt-row",style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("button",{onClick:()=>{$(e.path),ep(!1),ev(null),O("")},title:e.path,onMouseEnter:e=>{e.currentTarget.style.background="var(--side-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px",background:"transparent",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)(Q,{text:e.branch??G(e.path,P),style:{flex:1}}),e.isMain&&(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10},children:C("sidebar.main")})]}),!e.isMain&&(0,n.jsx)("button",{onClick:()=>void tt(e.path,!1),disabled:eb,title:C("sidebar.removeWorktreeTitle",{path:e.path}),style:{display:"flex",alignItems:"center",justifyContent:"center",width:34,height:28,padding:0,marginRight:4,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",borderRadius:5,flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="#ef4444",e.currentTarget.style.background="rgba(239,68,68,0.08)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]},e.path)}),e&&0===t.length&&H.trim()&&(0,n.jsx)("div",{style:{padding:"8px 10px",fontSize:11,color:"var(--text-dim)"},children:C("sidebar.noMatchingWorktrees")})]}),eh?(0,n.jsxs)("div",{style:{padding:"6px 8px"},children:[(0,n.jsx)("input",{ref:eT,value:ef,onChange:e=>{ex(e.target.value),ev(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),te()),"Escape"===e.key&&(eg(!1),ex(""),ev(null))},placeholder:C("sidebar.branchName"),style:{width:"100%",fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--side-input)",color:"var(--text)",boxSizing:"border-box"}}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,marginTop:5},children:[(0,n.jsx)("button",{onClick:()=>void te(),disabled:eb||!ef.trim(),style:{flex:1,padding:"4px 0",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",fontSize:11,fontWeight:600,cursor:eb||!ef.trim()?"not-allowed":"pointer",opacity:eb||!ef.trim()?.65:1},children:eb?C("sidebar.creating"):C("sidebar.create")}),(0,n.jsx)("button",{onClick:()=>{eg(!1),ex(""),ev(null)},style:{flex:1,padding:"4px 0",background:"transparent",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",fontSize:11,cursor:"pointer"},children:C("sidebar.cancel")})]})]}):(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),eg(!0),ev(null),setTimeout(()=>eT.current?.focus(),0)},title:C("sidebar.createWorktreeTitle"),style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.1",strokeLinecap:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),(0,n.jsx)("span",{children:C("sidebar.newWorktree")})]}),em&&(0,n.jsx)("div",{style:{padding:"5px 10px 8px",color:"#dc2626",fontSize:11,lineHeight:1.35,overflowWrap:"anywhere"},children:em})]})]})})(),tg&&(0,n.jsxs)("button",{type:"button","aria-disabled":"true",tabIndex:-1,title:tg.title,style:{width:"100%",height:29,boxSizing:"border-box",marginTop:6,display:"flex",alignItems:"center",gap:6,padding:"0 10px",border:"1px solid var(--border)",borderRadius:7,background:"transparent",color:"var(--text-dim)",fontSize:11,lineHeight:1.35,whiteSpace:"nowrap",textAlign:"left",cursor:"default",opacity:.82},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:tg.label})]})]}),(0,n.jsxs)("div",{style:{flex:eM&&(p||z)?"1 1 0":"1 1 auto",overflowY:"auto",padding:"0",minHeight:80},children:[I&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:C("sidebar.loading")}),E&&(0,n.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:E}),!I&&!E&&0===tc.length&&(0,n.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:C("sidebar.noSessions")}),tf.map(t=>(0,n.jsx)(ei,{node:t,selectedSessionId:e,runningSessionIds:eH,unreadSessionIds:eU,onSelectSession:tr,onRenamed:eX,onSessionDeleted:e=>{u?.(e),eX()},depth:0},t.session.id))]}),(p||z)&&(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border)",display:"flex",flexDirection:"column",flex:eM?"1 1 0":"0 0 auto",minHeight:0,overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0},children:[(0,n.jsxs)("button",{onClick:()=>eR(e=>{let t=!e;return!function(e,t=c()){if(t)try{t.setItem(d,String(e))}catch{}}(t),t}),style:{display:"flex",alignItems:"center",gap:6,flex:1,padding:"6px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",textAlign:"left"},children:[(0,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:eM?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,n.jsx)("polyline",{points:"3 2 7 5 3 8"})}),C("files.explorer")]}),eM&&ez>0&&(0,n.jsx)(X,{onClick:()=>eA(e=>!e),title:C("sidebar.changedFiles",{count:ez}),ariaPressed:!eP,color:eP?"var(--text-dim)":"var(--accent)",background:eP?"none":"var(--side-active)",children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("path",{d:"M3 12h6"}),(0,n.jsx)("path",{d:"M15 12h6"})]})}),eM&&(0,n.jsx)(X,{onClick:()=>eY.current?.openUploadPicker(),disabled:eE,title:C("sidebar.uploadFilesTitle"),color:"var(--text-dim)",children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("path",{d:"m17 8-5-5-5 5"}),(0,n.jsx)("path",{d:"M12 3v12"})]})}),(0,n.jsx)(X,{onClick:()=>{x?x():eL(e=>e+1),eB(!0),eJ.current&&clearTimeout(eJ.current),eJ.current=setTimeout(()=>eB(!1),2e3)},title:C("sidebar.refreshExplorer"),skipHover:eF,color:eF?"#4ade80":"var(--text-dim)",background:eF?"rgba(74,222,128,0.18)":"none",marginRight:6,children:eF?(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#4ade80",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]})})]}),eM&&(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",overflowX:"hidden"},children:(0,n.jsx)(Y,{ref:eY,cwd:z??p,onOpenFile:g??(()=>{}),refreshKey:eI,onAtMention:y,onAtMentions:k,onUploadBusyChange:eW,changesCollapsed:eP,onChangesCountChange:e$})})]})]})}function ei({node:e,selectedSessionId:t,runningSessionIds:r,unreadSessionIds:o,onSelectSession:l,onRenamed:a,onSessionDeleted:s,depth:d}){let[c,u]=(0,i.useState)(!1),p=e.children.length>0;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{position:"relative"},children:[d>0&&(0,n.jsx)("div",{style:{position:"absolute",left:12*d+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,n.jsx)(ea,{session:e.session,isSelected:e.session.id===t,isRunning:r.has(e.session.id),isUnread:o.has(e.session.id),onClick:()=>l(e.session),onRenamed:a,onDeleted:e=>s?.(e),depth:d,hasChildren:p,collapsed:c,onToggleCollapse:()=>u(e=>!e)})]}),p&&!c&&(0,n.jsx)("div",{children:e.children.map(e=>(0,n.jsx)(ei,{node:e,selectedSessionId:t,runningSessionIds:r,unreadSessionIds:o,onSelectSession:l,onRenamed:a,onSessionDeleted:s,depth:d+1},e.session.id))})]})}function eo(){let{t:e}=(0,b.s)();return(0,n.jsx)("span",{title:e("sidebar.agentRunning"),"aria-label":e("sidebar.agentRunning"),style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"var(--accent)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{display:"block"},children:(0,n.jsxs)("g",{children:[(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-3.8-7.4",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round"}),(0,n.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})]})})})}function el(){let{t:e}=(0,b.s)();return(0,n.jsx)("span",{title:e("sidebar.newActivity"),"aria-label":e("sidebar.newSessionActivity"),style:{width:14,height:14,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:"#0891b2"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",style:{display:"block"},children:[(0,n.jsx)("circle",{cx:"7",cy:"7",r:"2.5",fill:"currentColor"}),(0,n.jsxs)("circle",{cx:"7",cy:"7",r:"3",stroke:"currentColor",strokeWidth:"1.4",opacity:"0.32",children:[(0,n.jsx)("animate",{attributeName:"r",values:"3;6;3",dur:"1.6s",repeatCount:"indefinite"}),(0,n.jsx)("animate",{attributeName:"opacity",values:"0.32;0;0.32",dur:"1.6s",repeatCount:"indefinite"})]})]})})}function ea({session:e,isSelected:t,isRunning:r,isUnread:o,onClick:l,onRenamed:a,onDeleted:s,depth:d=0,hasChildren:c=!1,collapsed:u=!1,onToggleCollapse:h}){let g,f,x,m,v,{t:y}=(0,b.s)(),[k,w]=(0,i.useState)(!1),[j,S]=(0,i.useState)(!1),[C,T]=(0,i.useState)(""),[M,R]=(0,i.useState)(!1),[I,L]=(0,i.useState)(!1),E=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(j){let e=requestAnimationFrame(()=>E.current?.select());return()=>cancelAnimationFrame(e)}},[j]);let W=p(e.firstMessage)??e.firstMessage,z=e.name||W.slice(0,50)||e.id.slice(0,12),$=(0,i.useCallback)(t=>{t.stopPropagation(),e.transient||(T(e.name||W.slice(0,50)||e.id.slice(0,12)),S(!0))},[e.name,e.transient,W,e.id]),P=(0,i.useCallback)(async()=>{let t=C.trim();if(S(!1),C!==z&&t!==(e.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:t})}),a?.()}catch{}},[C,e.id,e.name,a,z]),A=(0,i.useCallback)(async()=>{if(!e.transient){R(!1),L(!0);try{await fetch(`/api/sessions/${encodeURIComponent(e.id)}`,{method:"DELETE"}),s?.(e.id)}catch{L(!1)}}},[e.id,e.transient,s]),D=(0,i.useCallback)(e=>{e.stopPropagation(),e.shiftKey?A():R(!0)},[A]),N=(0,i.useCallback)(e=>{e.stopPropagation(),A()},[A]),F=(0,i.useCallback)(e=>{e.stopPropagation(),R(!1)},[]),B=(0,i.useCallback)(t=>{(function(e,t=window){let r=new CustomEvent("pi-web:session-row-contextmenu",{cancelable:!0,detail:e});return!t.dispatchEvent(r)})({id:e.id,path:e.path,cwd:e.cwd,name:e.name,clientX:t.clientX,clientY:t.clientY,refresh:()=>{a?.()}})&&(t.preventDefault(),t.stopPropagation())},[a,e.cwd,e.id,e.name,e.path]);return(0,n.jsx)("div",{onClick:M||j?void 0:l,onContextMenu:M||j?void 0:B,onMouseEnter:()=>w(!0),onMouseLeave:()=>{w(!1)},style:{height:54,display:"flex",alignItems:"center",paddingLeft:d>0?12*d+14:14,paddingRight:8,cursor:M||j?"default":"pointer",background:M?"rgba(239,68,68,0.06)":t?"var(--side-selected)":k?"var(--side-hover)":"transparent",borderLeft:M?"2px solid #ef4444":t?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:I?.5:1,gap:6,overflow:"hidden"},children:M?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y("sidebar.deleteSession",{title:z.slice(0,22)+(z.length>22?"…":"")})}),(0,n.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,n.jsxs)("button",{onClick:N,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),y("sidebar.delete")]}),(0,n.jsx)("button",{onClick:F,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--side-input)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:y("sidebar.cancel")})]})]}):j?(0,n.jsx)("input",{ref:E,value:C,onChange:e=>T(e.target.value),onBlur:P,onKeyDown:e=>{"Enter"===e.key&&P(),"Escape"===e.key&&S(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--side-input)",color:"var(--text)",height:30}}):(0,n.jsxs)(n.Fragment,{children:[d>0&&(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",gap:5,minWidth:0,fontSize:12,fontWeight:t?500:400,lineHeight:1.4,color:"var(--text)"},title:z,children:(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:z})}),(0,n.jsxs)("div",{style:{marginTop:2,display:"flex",alignItems:"center",gap:8,color:"var(--text-dim)",fontSize:11,minWidth:0},children:[r?(0,n.jsx)(eo,{}):o?(0,n.jsx)(el,{}):(0,n.jsx)("span",{title:e.modified,children:(g=new Date(e.modified),x=Math.floor((f=new Date().getTime()-g.getTime())/6e4),m=Math.floor(f/36e5),v=Math.floor(f/864e5),x<1?"just now":x<60?`${x}m ago`:m<24?`${m}h ago`:v<7?`${v}d ago`:g.toLocaleDateString())}),(0,n.jsx)("span",{children:y("sidebar.messagesCount",{count:e.messageCount})}),e.worktreeBranch&&(0,n.jsxs)("span",{title:`Worktree: ${e.cwd}`,style:{display:"flex",alignItems:"center",gap:3,color:"var(--accent)",minWidth:0,overflow:"hidden"},children:[(0,n.jsxs)("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.worktreeBranch})]})]})]}),k&&!e.transient&&(0,n.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,n.jsx)("button",{onClick:$,title:y("sidebar.rename"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"transparent",border:"1px solid transparent",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--side-active)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,n.jsx)("button",{onClick:D,title:y("sidebar.deleteWithShiftClick"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"transparent",border:"1px solid transparent",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.12)",e.currentTarget.style.color="#ef4444"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,n.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,n.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]}),c&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h?.()},title:u?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:u?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})})]})})}let es=/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/g,ed=/^\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/,ec=/\x1B\[([0-9;]*)m/g,eu=/\x1B_pi:c\x07/g,ep=["#1f2937","#dc2626","#16a34a","#d97706","#2563eb","#9333ea","#0891b2","#6b7280"],eh=["#9ca3af","#ef4444","#22c55e","#f59e0b","#3b82f6","#a855f7","#06b6d4","#e5e7eb"];function eg(e){return e.replace(eu,"").replace(es,"")}function ef(e){let t=[],r=0;for(;r<e.length;){if(27===e.charCodeAt(r)){let t=e.slice(r).match(ed);if(t){r+=t[0].length;continue}}let n=e.codePointAt(r);if(void 0===n)break;let i=String.fromCodePoint(n);t.push({start:r,end:r+i.length,char:i}),r+=i.length}return t}function ex(e,t){let r=ef(e)[t];return r?e.slice(0,r.start)+e.slice(r.end):e}function em(e){return ef(e)[0]?.char}function ev(e){let t,r=[],n={},i=0;for(ec.lastIndex=0;null!==(t=ec.exec(e));)t.index>i&&r.push({text:e.slice(i,t.index),style:n}),n=function(e,t){let r={...e};for(let e=0;e<t.length;e++){let n=t[e];if(0===n)for(let e of Object.keys(r))delete r[e];else if(1===n)r.fontWeight=700;else if(2===n)r.opacity=.65;else if(3===n)r.fontStyle="italic";else if(4===n)r.textDecoration="underline";else if(22===n)delete r.fontWeight,delete r.opacity;else if(23===n)delete r.fontStyle;else if(24===n)delete r.textDecoration;else if(39===n)delete r.color;else if(49===n)delete r.backgroundColor;else if(n>=30&&n<=37)r.color=ep[n-30];else if(n>=90&&n<=97)r.color=eh[n-90];else if(n>=40&&n<=47)r.backgroundColor=ep[n-40];else if(n>=100&&n<=107)r.backgroundColor=eh[n-100];else if((38===n||48===n)&&2===t[e+1]){let[i,o,l]=[t[e+2],t[e+3],t[e+4]];[i,o,l].every(e=>"number"==typeof e&&Number.isFinite(e))&&(38===n?r.color=`rgb(${i}, ${o}, ${l})`:r.backgroundColor=`rgb(${i}, ${o}, ${l})`),e+=4}else if((38===n||48===n)&&5===t[e+1]){let i=function(e){if(e>=0&&e<8)return ep[e];if(e>=8&&e<16)return eh[e-8];if(e>=16&&e<=231){let t=e-16,r=Math.floor(t/36),n=Math.floor(t%36/6),i=e=>0===e?0:55+40*e;return`rgb(${i(r)}, ${i(n)}, ${i(t%6)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}(t[e+2]);i&&(38===n?r.color=i:r.backgroundColor=i),e+=2}}return r}(n,t[1]?t[1].split(";").map(e=>Number(e||"0")):[0]),i=t.index+t[0].length;return i<e.length&&r.push({text:e.slice(i),style:n}),r}let eb={ArrowUp:"\x1b[A",ArrowDown:"\x1b[B",ArrowRight:"\x1b[C",ArrowLeft:"\x1b[D",Home:"\x1b[H",End:"\x1b[F",Insert:"\x1b[2~",Delete:"\x1b[3~",PageUp:"\x1b[5~",PageDown:"\x1b[6~",Escape:"\x1b",Backspace:""},ey={ArrowLeft:"\x1bb",ArrowRight:"\x1bf",ArrowUp:"\x1bp",ArrowDown:"\x1bn"};function ek(e,t={}){return"thinking"===e.type&&!e.deferred&&!t.isStreaming&&""===e.thinking.trim()}function ew(e,t={}){return(e.content??[]).filter(e=>!ek(e,t))}function ej(e,t={}){return t.isStreaming||"error"!==e.stopReason?null:e.errorMessage?.trim()||"Unknown provider error"}function eS(e,t={}){let r=ew(e,t),n=r.findLastIndex(e=>"text"!==e.type&&"image"!==e.type);return -1===n?{answerBlocks:r,processBlocks:[]}:{answerBlocks:r.slice(n+1),processBlocks:r.slice(0,n+1)}}function eC(e){return e.filter(e=>"toolCall"===e.type).length}function eT(e){try{return decodeURIComponent(e)}catch{return e}}function eM(e){return/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")?e.replace(/\\/g,"/"):e}function eR(e){let t=eM(e),r=/^[a-zA-Z]:\//.test(t),n=t.startsWith("//"),i=t.startsWith("/")&&!r&&!n,o=[];for(let e of t.split("/"))if(e&&"."!==e){if(".."===e){o.length>0&&".."!==o[o.length-1]?o.pop():i||r||n||o.push(e);continue}o.push(e)}let l=o.join("/");return r?l:n?`//${l}`:i?`/${l}`:l}function eI(e,t,r=t){let n,i,o,l,a;if(!e)return null;let s=e.split("#",1)[0].split("?",1)[0].trim();if(!s)return null;let d=null,c=null,u=eT(s),p=u.startsWith("\\\\"),h=eM(u),g=h.toLowerCase();if(g.startsWith("/api/")||g.startsWith("/_next/")||!p&&h.startsWith("//")||/^[a-zA-Z][a-zA-Z0-9+.-]*:/i.test(h)&&!g.startsWith("file:")&&!/^[a-zA-Z]:\//.test(h))return null;if(g.startsWith("file:")?c=(d=function(e){try{let t=new URL(e);if("file:"!==t.protocol)return null;let r=eT(t.pathname);if(t.hostname)return`//${t.hostname}${r.startsWith("/")?r:`/${r}`}`;if(/^\/[a-zA-Z]:\//.test(r))return r.slice(1);return r}catch{return null}}(h))?"absolute":null:/^[a-zA-Z]:\//.test(h)||h.startsWith("/")?(d=h,c="absolute"):t&&!(h.startsWith("#")||h.startsWith("?"))&&(h.startsWith("./")||h.startsWith("../")||h.includes("/")||/(^|\/)\.?[^/]+\.[^/.]+$/.test(h))&&(d=`${eM(t).replace(/\/+$/,"")}/${h}`,c="relative"),!d)return null;let f=eR(d).replace(/:\d+(?::\d+)?$/,"");return"relative"===c&&r&&(n=eR(f).replace(/\/+$/,""),i=eR(r).replace(/\/+$/,""),l=(o=/^[a-zA-Z]:\//.test(n)||/^[a-zA-Z]:\//.test(i))?n.toLowerCase():n,!(l===(a=o?i.toLowerCase():i)||l.startsWith(`${a}/`)))?null:f}function eL(e){let t=e.toLowerCase();return"edit"===t||t.startsWith("edit_")||t.endsWith(".edit")||t.endsWith("_edit")||t.includes("str_replace")||t.includes("replace_editor")}var eE=r(32316),eW=r(88374),ez=r(5924),e$=r(94764),eP=r(63835),eA=r(54152),eD=r(84678),eN=r(98164);let eF={...e$.j,attributes:{...e$.j.attributes,code:[["className",/^language-./,"math-inline","math-display"]]},strip:[...e$.j.strip||[],"iframe","object","style","form"]};function eB(e){let t=e.includes("\r\n")?"\r\n":"\n",r=e.split(/\r?\n/),n=[],i=null,o=0,l=null,a=new Map;for(let e=0;e<r.length;e++){var s;let t=r[e];if(l){n.push(t),RegExp(`</${l}\\s*>`,"i").test(t)&&(l=null);continue}let d=t.match(/^ {0,3}(`{3,}|~{3,})/);if(d){let e=d[1][0],r=d[1].length;i?e===i.marker&&r>=i.size&&(i=null):i={marker:e,size:r},o=0,n.push(t);continue}if(i){n.push(t);continue}let c=t.match(/<(code|pre|script|style)\b/i);if(c){let e=c[1].toLowerCase(),r=t.slice((c.index??0)+c[0].length);RegExp(`</${e}\\s*>`,"i").test(r)||(l=e),o=0,n.push(t);continue}if(/^(?: {4}|\t)/.test(t)||""===t.trim()){o=0,n.push(t);continue}if(o||t.includes("`")){o=function(e,t){let r=t;for(let t=0;t<e.length;){if("`"!==e[t]){t++;continue}let n=t+1;for(;"`"===e[n];)n++;let i=n-t;0===r?r=i:i===r&&(r=0),t=n}return r}(t,o),n.push(t);continue}let u=t.match(/^([ ]{0,3})\\\[[ \t]*(.+?)[ \t]*\\\][ \t]*$/);if(u){let e=u[2].trim();if(e){n.push(`${u[1]}$$`,`${u[1]}${e}`,`${u[1]}$$`);continue}}let p=t.match(/^([ ]{0,3})\\\[[ \t]*$/);if(p){let t=function(e,t){for(let r=t;r<e.length;r++){let t=e[r];if(/^ {0,3}\\\][ \t]*$/.test(t))return r;if(/^ {0,3}(`{3,}|~{3,})/.test(t)||/^ {0,3}\\\[[ \t]*$/.test(t)||/<(code|pre|script|style)\b/i.test(t))break}return -1}(r,e+1);if(-1!==t){n.push(`${p[1]}$$`,...r.slice(e+1,t).map(e=>eO(e,p[1])),`${p[1]}$$`),e=t;continue}}let h=t.match(/^([ \t]{0,3})\$\$(.+)\$\$[ \t]*$/);if(h){let e=h[2].trim();if(e){n.push(`${h[1]}$$`,`${h[1]}${e}`,`${h[1]}$$`);continue}}let g=t.match(/^([ \t]{0,3})\$\$(.+)$/);if(g){let t=g[1],i=g[2].trimEnd();if(i&&!i.includes("$$")){let o=eH(r,e+1,t,a);if(o){n.push(`${t}$$`,`${t}${i}`);for(let i=e+1;i<o.index;i++)n.push(eO(r[i],t));o.content&&n.push(`${t}${o.content}`),n.push(`${t}$$`),e=o.index;continue}}}let f=t.match(/^([ \t]{0,3})\$\$\s*$/);if(f){let t=f[1],i=eH(r,e+1,t,a);if(i&&(i.glued||""!==t)){n.push(`${t}$$`);for(let o=e+1;o<i.index;o++)n.push(eO(r[o],t));i.content&&n.push(`${t}${i.content}`),n.push(`${t}$$`),e=i.index;continue}}n.push((s=t,/^\s{0,3}\[[^\]]+\]:/.test(s)||/]\s*\(/.test(s)||/<(?:!--|\/?[A-Za-z][^>]*>)/.test(s)||/\b(?:https?|file|mailto):/i.test(s)||/\b[A-Za-z]:\\/.test(s)?s:s.replace(/(?<!\\)\\\(([^`\r\n$]+?)(?<!\\)\\\)/g,(e,t)=>t.trim()?`$${t}$`:e)))}return n.join(t)}function eH(e,t,r,n){let i=n.get(r);if(void 0!==i&&t<i)return null;for(let i=t;i<e.length;i++){var o,l,a,s;let t=e[i];if(o=t,""===(l=r)?/^ {0,3}\$\$\s*$/.test(o):o.startsWith(l)&&/^\$\$\s*$/.test(o.slice(l.length)))return{index:i,content:"",glued:!1};if(a=t,/^ {0,3}(`{3,}|~{3,})/.test(a)||/^[ \t]*(?:[-+*]|\d{1,9}[.)])(?:[ \t]+|$)/.test(a)||/^ {0,3}#{1,6}(?:[ \t]+|$)/.test(a)||/^ {0,3}>/.test(a)||/<(code|pre|script|style)\b/i.test(a)||(s=t,/^ {0,3}\$\$(?:\S|[ \t]+\S)/.test(s)))return n.set(r,i),null;let d=function(e,t){if(!e.startsWith(t))return null;let r=e.slice(t.length).match(/^(.+?)\$\$\s*$/);if(!r)return null;let n=r[1].trimEnd();return n&&!n.includes("$$")?n:null}(t,r);if(null!==d)return{index:i,content:d,glued:!0}}return n.set(r,e.length),null}function eO(e,t){if(!t||!e||e.startsWith(" "))return e;let r=e.match(/^ */)?.[0].length??0;return r>=t.length?e:`${t.slice(r)}${e}`}let eU={singleTilde:!1},e_=[[eA.A,["yaml"]],[eD.A,eU],eN.A],eq=[[eA.A,["yaml"]],[eD.A,eU],eN.A],eK=[ez.A,[eP.A,eF],[eW.A,{throwOnError:!1,strict:!1}]],eV=[ez.A,[eP.A,eF],[eW.A,{throwOnError:!1,strict:!1}]];var eJ=r(65063),eY=r(7644);let eX="pi-theme",eZ=["light","dark"],eG={preference:"auto",theme:"light"},eQ=new Set,e0=null,e1=!1;function e2(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function e8(e){return"auto"===e?e2():e}function e4(e){"u">typeof document&&document.documentElement.classList.toggle("dark","dark"===e)}function e6(){if(e0)return e0;let e=function(){try{let e=localStorage.getItem(eX);if("light"===e||"dark"===e)return e;if("auto"===e)return e2()}catch{}return"light"}(),t=e8(e);return e4(t),e0={preference:e,theme:t}}function e5(e,t,r){if(e4(t),r)try{localStorage.setItem(eX,e)}catch{}e0={preference:e,theme:t},eQ.forEach(e=>e())}function e3(){let e=e6();if("auto"!==e.preference)return;let t=e2();t!==e.theme&&e5("auto",t,!1)}function e7(e){return eQ.add(e),e6(),e1||!window.matchMedia||(window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e3),window.addEventListener("focus",e3),document.addEventListener("visibilitychange",()=>{"visible"===document.visibilityState&&e3()}),e1=!0),e3(),()=>{eQ.delete(e)}}function e9(){return e6()}function te(){return eG}function tt(){let e=(0,i.useSyncExternalStore)(e7,e9,te),t=(0,i.useCallback)(e=>{var t;let r,n=(t=e6().preference,r=eZ.indexOf(t),eZ[(r+1)%eZ.length]),i=e8(n),o=()=>{e5(n,i,!0)},l=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;if("function"!=typeof document.startViewTransition||l)return void o();let a=e?.x??window.innerWidth/2,s=e?.y??window.innerHeight/2,d=Math.hypot(Math.max(a,window.innerWidth-a),Math.max(s,window.innerHeight-s));document.startViewTransition(o).ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0px at ${a}px ${s}px)`,`circle(${d}px at ${a}px ${s}px)`]},{duration:450,easing:"cubic-bezier(0.22, 0.61, 0.36, 1)",pseudoElement:"::view-transition-new(root)"})}).catch(()=>{})},[]);return{theme:e.theme,preference:e.preference,toggleTheme:t,isDark:"dark"===e.theme}}function tr(e){if(navigator.clipboard?.writeText)return navigator.clipboard.writeText(e);try{let t=document.createElement("textarea");return t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),Promise.resolve()}catch{return Promise.reject()}}function tn({code:e,isStreaming:t,defaultPreview:o=!1}){let{isDark:l}=tt(),{t:a}=(0,b.s)(),[s,d]=(0,i.useState)(o),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(!1),g=`${l?"dark":"light"}
2
+ ${e}`,f=s&&!t;(0,i.useEffect)(()=>{if(!f)return;let t=!1;return u({key:g,status:"loading"}),(async()=>{let{default:n}=await Promise.all([r.e(988),r.e(9425),r.e(3308)]).then(r.bind(r,43328));if(n.initialize({startOnLoad:!1,securityLevel:"strict",suppressErrorRendering:!0,theme:l?"dark":"default"}),!await n.parse(e,{suppressErrors:!0}))throw Error("Invalid Mermaid diagram");let i="u">typeof crypto&&"randomUUID"in crypto?`mermaid-${crypto.randomUUID()}`:`mermaid-${Date.now()}-${Math.random().toString(36).slice(2)}`,o=await n.render(i,e);t||u({key:g,status:"ready",svg:o.svg})})().catch(()=>{t||u({key:g,status:"error"})}),()=>{t=!0}},[e,g,l,f]);let x=(0,i.useMemo)(()=>(0,n.jsx)("button",{type:"button",onClick:()=>d(e=>!e),disabled:t,title:t?a("i18n.previewAfterStreaming"):f?a("i18n.showMermaidSource"):a("i18n.previewMermaid"),className:["markdown-code-action",f?"is-active":""].filter(Boolean).join(" "),children:f?a("i18n.source"):a("i18n.preview")}),[t,f,a]);if(!f)return(0,n.jsx)(to,{code:e,lang:"mermaid",headerAction:x,isStreaming:t});let m=c?.key===g&&"error"===c.status?(0,n.jsx)("div",{className:"mermaid-block mermaid-block-error",children:a("i18n.invalidMermaid")}):c?.key!==g||"ready"!==c.status?(0,n.jsx)("div",{className:"mermaid-block mermaid-block-loading","aria-label":a("i18n.renderingMermaid")}):(0,n.jsxs)(n.Fragment,{children:[!p&&(0,n.jsx)("button",{type:"button",className:"mermaid-block mermaid-preview-button",title:a("i18n.openMermaidViewer"),"aria-label":a("i18n.openMermaidViewer"),onClick:()=>h(!0),dangerouslySetInnerHTML:{__html:c.svg}}),p&&(0,n.jsx)(ti,{svg:c.svg,onClose:()=>h(!1)})]});return(0,n.jsxs)("div",{className:"markdown-code-block",children:[(0,n.jsxs)("div",{className:"markdown-code-header",children:[(0,n.jsx)("span",{className:"markdown-code-lang",children:"mermaid"}),x]}),m]})}function ti({svg:e,onClose:t}){let{t:r}=(0,b.s)(),o=(0,i.useRef)(null),[l,a]=(0,i.useState)(1);return(0,i.useEffect)(()=>{let e=o.current;if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow="hidden",e.showModal(),()=>{document.body.style.overflow=t,e.open&&e.close()}},[]),(0,n.jsx)("dialog",{ref:o,className:"mermaid-zoom-dialog","aria-label":r("i18n.mermaidViewer"),onCancel:e=>{e.preventDefault(),t()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),t())},children:(0,n.jsxs)("div",{className:"mermaid-zoom-layout",children:[(0,n.jsxs)("div",{className:"mermaid-zoom-toolbar",children:[(0,n.jsx)("span",{className:"mermaid-zoom-title",children:r("i18n.mermaidDiagram")}),(0,n.jsxs)("div",{className:"mermaid-zoom-actions",children:[(0,n.jsxs)("div",{className:"mermaid-zoom-stepper",children:[(0,n.jsx)("button",{type:"button",onClick:()=>a(e=>Math.max(.5,e-.25)),disabled:l<=.5,title:r("i18n.zoomOut"),"aria-label":r("i18n.zoomOut"),children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M5 12h14"})})}),(0,n.jsxs)("span",{className:"mermaid-zoom-value",children:[Math.round(100*l),"%"]}),(0,n.jsx)("button",{type:"button",onClick:()=>a(e=>Math.min(3,e+.25)),disabled:l>=3,title:r("i18n.zoomIn"),"aria-label":r("i18n.zoomIn"),children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M12 5v14M5 12h14"})})})]}),(0,n.jsx)("button",{type:"button",className:"mermaid-zoom-icon-button",onClick:()=>a(1),title:r("i18n.fitToWidth"),"aria-label":r("i18n.fitToWidth"),children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M8 3H3v5M16 3h5v5M8 21H3v-5M16 21h5v-5"})})}),(0,n.jsx)("button",{type:"button",className:"mermaid-zoom-icon-button",onClick:t,title:r("i18n.close"),"aria-label":r("i18n.close"),children:(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})})})]})]}),(0,n.jsx)("div",{className:"mermaid-zoom-viewport",onClick:e=>{e.target===e.currentTarget&&t()},children:(0,n.jsx)("div",{className:"mermaid-zoom-canvas",style:{width:`${100*l}%`},dangerouslySetInnerHTML:{__html:e}})})]})})}let to=(0,i.memo)(function({code:e,lang:t,headerAction:r,isStreaming:o}){let{isDark:l}=tt(),{t:a}=(0,b.s)(),[s,d]=(0,i.useState)(!1);return(0,n.jsxs)("div",{className:"markdown-code-block",children:[(0,n.jsxs)("div",{className:"markdown-code-header",children:[(0,n.jsx)("span",{className:"markdown-code-lang",children:t||"text"}),(0,n.jsxs)("div",{className:"markdown-code-actions",children:[r,(0,n.jsx)("button",{onClick:()=>{tr(e).then(()=>{d(!0),setTimeout(()=>d(!1),1500)})},className:"markdown-code-action",children:a(s?"i18n.copied":"i18n.copy")})]})]}),o?(0,n.jsx)("pre",{style:{margin:0,padding:"11px 13px",fontSize:12.5,lineHeight:1.62,overflowX:"auto",background:"color-mix(in srgb, var(--bg) 92%, var(--bg-panel))"},children:(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:e})}):(0,n.jsx)(eJ.A,{language:t||"text",style:l?eY.xJ:eY.vs,showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal"},customStyle:{margin:0,padding:"11px 13px",fontSize:12.5,lineHeight:1.62,borderRadius:0,background:"color-mix(in srgb, var(--bg) 92%, var(--bg-panel))"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},children:e})]})});function tl({children:e,className:t,isStreaming:r,cwd:o,onOpenFile:l}){let a=(0,i.useMemo)(()=>eB(e),[e]),s=(0,i.useMemo)(()=>({code({className:e,children:t,...i}){let o=e?.replace("language-","").toLowerCase()??"",l=String(t);return e?.includes("language-")||l.includes("\n")?"mermaid"===o?(0,n.jsx)(tn,{code:l.replace(/\n$/,""),isStreaming:r}):(0,n.jsx)(to,{code:l.replace(/\n$/,""),lang:o,isStreaming:r}):(0,n.jsx)("code",{className:"markdown-inline-code",...i,children:t})},pre:({children:e})=>(0,n.jsx)(n.Fragment,{children:e}),a({href:e,children:t,...r}){delete r.node;let i=l?eI(e,o):null;return i&&l?(0,n.jsx)("a",{href:e,...r,onClick:e=>{if(e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.currentTarget.getAttribute("target");t&&"_self"!==t||(e.preventDefault(),l(i))},children:t}):(0,n.jsx)("a",{href:e,...r,target:"_blank",rel:"noopener noreferrer",children:t})},img({src:e,alt:t,...r}){delete r.node;let i="string"==typeof e?eI(e,o):null,l=i?`/api/files/${P(i)}?type=read`:e;return(0,n.jsx)("img",{src:l,alt:t??"",loading:"lazy",...r})},table:({children:e})=>(0,n.jsx)("div",{className:"markdown-table-wrap",children:(0,n.jsx)("table",{children:e})})}),[o,r,l]);return(0,n.jsx)("div",{className:["markdown-body",t].filter(Boolean).join(" "),children:(0,n.jsx)(eE.oz,{remarkPlugins:e_,rehypePlugins:eK,components:s,children:a})})}function ta({src:e,alt:t="",children:r,className:o,style:l}){let{t:a}=(0,b.s)(),[s,d]=(0,i.useState)(!1),c=(0,i.useRef)(null),u=(0,i.useRef)(null),p=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!s)return;let e=u.current;if(!e)return;let t=c.current,r=document.body.style.overflow;return document.body.style.overflow="hidden",e.showModal(),p.current?.focus({preventScroll:!0}),()=>{document.body.style.overflow=r,e.open&&e.close(),t?.isConnected&&t.focus({preventScroll:!0})}},[s]);let h=()=>{u.current?.open&&u.current.close(),d(!1)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:c,type:"button",className:o,style:{display:"block",padding:0,border:"none",background:"none",color:"inherit",cursor:"zoom-in",...l},onClick:()=>d(!0),"aria-label":a("chat.previewImage"),"aria-haspopup":"dialog","aria-expanded":s,title:a("chat.previewImage"),children:r}),s&&(0,n.jsxs)("dialog",{ref:u,className:"image-preview-dialog","aria-label":a("chat.previewImage"),onCancel:e=>{e.preventDefault(),e.stopPropagation(),h()},onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),h())},onClick:e=>{e.target===e.currentTarget&&h()},children:[(0,n.jsx)("img",{className:"image-preview-image",src:e,alt:t}),(0,n.jsx)("button",{ref:p,type:"button",className:"image-preview-close",onClick:h,"aria-label":a("chat.close"),title:a("chat.close"),children:(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})})})]})]})}let ts=/<(read-files|modified-files)>\s*([\s\S]*?)\s*<\/\1>/g,td=/(?:\r?\n){2,}((?:[ \t]*<(?:read-files|modified-files)>[ \t]*\r?\n[\s\S]*?\r?\n[ \t]*<\/(?:read-files|modified-files)>[ \t]*(?:\r?\n)?)+)\s*$/;function tc(e){let t,r=[],n=null,i=0,o=0,l=0,a=0,s=[],d=[],c=()=>({lineNo:null,text:"",type:"empty"}),u=()=>{if(!n){s=[],d=[];return}let e=Math.max(s.length,d.length);for(let t=0;t<e;t++){let e=s[t]?{lineNo:s[t].lineNo,text:s[t].text,type:"removed"}:c(),r=d[t]?{lineNo:d[t].lineNo,text:d[t].text,type:"added"}:c();n.rows.push({type:"line",left:e,right:r})}s=[],d=[]};for(let c of e.split(/\r?\n/)){if(!(l>0||a>0)){if(c.startsWith("--- ")){u(),t=tu(c.slice(4));continue}if(c.startsWith("+++ ")){u(),n={oldPath:t,newPath:tu(c.slice(4)),rows:[]},r.push(n);continue}}let e=c.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);if(e){n||(n={rows:[]},r.push(n)),u(),i=Number(e[1]),o=Number(e[3]),l=void 0===e[2]?1:Number(e[2]),a=void 0===e[4]?1:Number(e[4]),n.rows.push({type:"hunk",text:c});continue}if(!n)continue;if(c.startsWith("\\ ")){u(),n.rows.push({type:"hunk",text:c});continue}let p=c[0],h=c.slice(1);" "===p?(u(),n.rows.push({type:"line",left:{lineNo:i++,text:h,type:"context"},right:{lineNo:o++,text:h,type:"context"}}),l>0&&l--,a>0&&a--):"-"===p?(s.push({lineNo:i++,text:h}),l>0&&l--):"+"===p?(d.push({lineNo:o++,text:h}),a>0&&a--):""!==c&&(u(),n.rows.push({type:"hunk",text:c}))}u();let p=r.filter(e=>e.rows.some(e=>"line"===e.type));return p.length>0?p:null}function tu(e){return e.split(" ")[0].trim()}function tp({files:e,onOpenFile:t}){let{t:r}=(0,b.s)();return 0===e.length?null:(0,n.jsx)("div",{"aria-label":r("chat.filesWritten"),style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:6,marginTop:6},children:e.map(({filePath:e})=>{let i=A(e);return(0,n.jsxs)("button",{type:"button",title:e,"aria-label":r("chat.openWrittenFile",{name:i}),onClick:()=>t?.(e),style:{display:"inline-flex",alignItems:"center",gap:4,padding:"2px 8px",fontSize:12,fontFamily:"var(--font-mono)",color:"var(--text)",background:"var(--bg-subtle)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer"},children:[z(i,12),(0,n.jsx)("span",{children:i})]},e)})})}let th=/[\u3000-\u30ff\u3400-\u9fff\uf900-\ufaff\u{20000}-\u{2fa1f}\uac00-\ud7af]/u;function tg(e){let t=0,r=0;for(let n of e)th.test(n)?t++:r++;return t+r/4}let tf=new Map;function tx({children:e,className:t,...r}){let{t:o}=(0,b.s)(),[l,a]=(0,i.useState)(!1);if(e.length<=1e5)return(0,n.jsx)(tl,{className:t,...r,children:e});if(!l){var s;return(0,n.jsxs)("button",{onClick:()=>a(!0),style:{display:"block",width:"100%",margin:"4px 0",padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:["⚠ ",o("i18n.largeMessageReveal",{size:(s=e.length)>=1e6?`${(s/1e6).toFixed(1)} MB`:s>=1e3?`${Math.round(s/1e3)} KB`:`${s} B`})]})}return(0,n.jsx)("div",{className:t,style:{maxHeight:420,overflow:"auto",fontSize:12,lineHeight:1.5},children:(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)",color:"var(--text-muted)"},children:e})})}function tm(e){if(!e)return null;let t=new Date(e),r=new Date,n=t.getFullYear()===r.getFullYear()&&t.getMonth()===r.getMonth()&&t.getDate()===r.getDate(),i=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(n)return i;let o=t.toLocaleDateString([],{month:"short",day:"numeric",year:t.getFullYear()!==r.getFullYear()?"numeric":void 0});return`${o} ${i}`}let tv=(0,i.memo)(function({message:e,isStreaming:t,toolResults:r,modelNames:i,cwd:o,onOpenFile:l,entryId:a,onFork:s,forking:d,onNavigate:c,prevAssistantEntryId:u,onEditContent:p,showTimestamp:h,prevTimestamp:g,sessionId:f,writtenFiles:x,onPin:m,bare:v}){return"user"===e.role?(0,n.jsx)(tb,{message:e,cwd:o,onOpenFile:l,entryId:a,onFork:s,forking:d,onNavigate:c,prevAssistantEntryId:u,onEditContent:p,onPin:m,bare:v}):"assistant"===e.role?(0,n.jsx)(ty,{message:e,isStreaming:t,toolResults:r,modelNames:i,cwd:o,onOpenFile:l,showTimestamp:h,prevTimestamp:g,sessionId:f,entryId:a,writtenFiles:x,onPin:m,bare:v}):"toolResult"===e.role?null:"custom"===e.role?"compaction"===e.customType?(0,n.jsx)(tE,{message:e}):(0,n.jsx)(t$,{message:e,cwd:o,onOpenFile:l}):"bashExecution"===e.role?(0,n.jsx)(tD,{message:e,sessionId:f}):null},(e,t)=>e.message===t.message&&e.isStreaming===t.isStreaming&&function(e,t,r){if(t===r||"assistant"!==e.role)return!0;for(let n of e.content??[])if("toolCall"===n.type&&t?.get(n.toolCallId)!==r?.get(n.toolCallId))return!1;return!0}(e.message,e.toolResults,t.toolResults)&&e.modelNames===t.modelNames&&e.cwd===t.cwd&&e.onOpenFile===t.onOpenFile&&e.entryId===t.entryId&&e.onFork===t.onFork&&e.forking===t.forking&&e.onNavigate===t.onNavigate&&e.prevAssistantEntryId===t.prevAssistantEntryId&&e.onEditContent===t.onEditContent&&e.showTimestamp===t.showTimestamp&&e.prevTimestamp===t.prevTimestamp&&e.sessionId===t.sessionId&&e.onPin===t.onPin&&e.bare===t.bare);function tb({message:e,cwd:t,onOpenFile:r,entryId:o,onFork:l,forking:a,onNavigate:s,prevAssistantEntryId:d,onEditContent:c,onPin:u,bare:h}){let{t:g}=(0,b.s)(),[f,x]=(0,i.useState)(!1),[m,v]=(0,i.useState)(!1),[y,k]=(0,i.useState)(!1),w="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),j="string"==typeof e.content?[]:e.content.filter(e=>"image"===e.type),S=p(w),C=S?.search(/\s/)??-1,T=S?-1===C?S:S.slice(0,C):"",M=S&&-1!==C?S.slice(C+1):"",R=tm(e.timestamp),I=!!o&&!!l,L=S??w,E=S?function(e,t){if("string"==typeof e.content)return{...e,content:t};let r=[],n=!1;for(let i of e.content){if("text"!==i.type){r.push(i);continue}n||(r.push({...i,text:t}),n=!0)}return n||r.unshift({type:"text",text:t}),{...e,content:r}}(e,S):e,W=j.length>0&&(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!w},children:j.map((e,t)=>{let r=e.source?"base64"===e.source.type?`data:${e.source.media_type};base64,${e.source.data}`:e.source.url??"":e.data?`data:${e.mimeType};base64,${e.data}`:"";return(0,n.jsx)(ta,{src:r,children:(0,n.jsx)("img",{src:r,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid rgba(59,130,246,0.15)"}})},t)})}),z=!!d&&!!s;return(0,n.jsxs)("div",{style:{marginBottom:20,display:"flex",flexDirection:"column",alignItems:"flex-end"},onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),children:[(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",gap:6,maxWidth:"85%"},children:(0,n.jsx)("div",{style:{flex:1,minWidth:0,background:"var(--user-bg-glass)",backdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))",border:h?"none":"1px solid var(--user-border-glass)",borderRadius:12,padding:"8px 12px",fontSize:14,lineHeight:1.6,color:"var(--text)",wordBreak:"break-word",maxHeight:300,overflowY:"auto"},children:S?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,minWidth:0},children:[W,(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,flexWrap:"wrap"},children:[(0,n.jsxs)("button",{onClick:()=>k(e=>!e),title:g(y?"i18n.collapse":"i18n.expand"),"aria-expanded":y,style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,padding:0,background:"none",border:"none",cursor:"pointer",color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:13,textAlign:"left"},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:T}),(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,opacity:.75,transform:y?"rotate(180deg)":"none",transition:"transform 0.15s"},"aria-hidden":"true",children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),M&&(0,n.jsx)("span",{style:{color:"var(--text)",fontSize:14,lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word",minWidth:0,flex:1},children:M})]}),y&&(0,n.jsx)(tl,{className:"markdown-user-message",cwd:t,onOpenFile:r,children:w})]}):(0,n.jsxs)(n.Fragment,{children:[W,w&&(0,n.jsx)(tx,{className:"markdown-user-message",cwd:t,onOpenFile:r,children:w})]})})}),!h&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:3,mixBlendMode:"exclusion"},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:3,opacity:+!!f,pointerEvents:f?"auto":"none",transition:"opacity 0.12s"},children:[u&&(0,n.jsxs)("button",{onClick:t=>u(e,o,t.currentTarget.getBoundingClientRect().top),title:g("i18n.pinTitle"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:"#ffffff",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.fontWeight="600",e.currentTarget.style.textDecoration="underline"},onMouseLeave:e=>{e.currentTarget.style.fontWeight="400",e.currentTarget.style.textDecoration="none"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0-2-2 3 3 0 0 0-3 3V9a4 4 0 0 1-1 2.65"})]}),g("i18n.pin")]}),(0,n.jsxs)("button",{onClick:()=>{tr(L).then(()=>{v(!0),setTimeout(()=>v(!1),1500)})},title:g("i18n.copyMessage"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:m?"var(--accent)":"#ffffff",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{m||(e.currentTarget.style.fontWeight="600",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{m||(e.currentTarget.style.fontWeight="400",e.currentTarget.style.textDecoration="none")},children:[m?(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),g(m?"i18n.copied":"i18n.copy")]})]}),(I||z)&&(0,n.jsxs)("div",{style:{display:"flex",gap:3,opacity:f||a?1:0,pointerEvents:f||a?"auto":"none",transition:"opacity 0.12s"},children:[z&&(0,n.jsxs)("button",{onClick:()=>{s(d),c?.(E)},title:g("i18n.editFromHereTitle"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:"#ffffff",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.fontWeight="600",e.currentTarget.style.textDecoration="underline"},onMouseLeave:e=>{e.currentTarget.style.fontWeight="400",e.currentTarget.style.textDecoration="none"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"15 10 20 15 15 20"}),(0,n.jsx)("path",{d:"M4 4v7a4 4 0 0 0 4 4h12"})]}),g("i18n.editFromHere")]}),I&&(0,n.jsxs)("button",{onClick:()=>{l(o)},disabled:a,title:g(a?"i18n.creatingSession":"i18n.newSessionTitle"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:a?"var(--accent)":"#ffffff",cursor:a?"not-allowed":"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",transition:"color 0.12s"},onMouseEnter:e=>{a||(e.currentTarget.style.fontWeight="600",e.currentTarget.style.textDecoration="underline")},onMouseLeave:e=>{a||(e.currentTarget.style.fontWeight="400",e.currentTarget.style.textDecoration="none")},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),g(a?"i18n.creating":"i18n.newSession")]})]}),R&&(0,n.jsx)("span",{style:{fontSize:10,color:"#ffffff"},children:R})]})]})}function ty({message:e,isStreaming:t,toolResults:r,modelNames:o,cwd:l,onOpenFile:a,showTimestamp:s,prevTimestamp:d,sessionId:c,entryId:u,writtenFiles:p,onPin:h,bare:g}){var f;let x,m,v,y,{t:k}=(0,b.s)(),w=s?tm(e.timestamp):null,j=(0,i.useMemo)(()=>(e.content??[]).map((e,t)=>({block:e,originalIndex:t})).filter(({block:e})=>!ek(e,{isStreaming:t})),[e.content,t]),S=(0,i.useMemo)(()=>j.map(({block:e})=>e),[j]),C=ej(e,{isStreaming:t}),[T,M]=(0,i.useState)(!1),[R,I]=(0,i.useState)(!1),L=(0,i.useRef)(null),[E,W]=(0,i.useState)(null),z=(0,i.useRef)(j);z.current=j;let $=(0,i.useRef)(new Map),P=(0,i.useMemo)(()=>{if(!t)return $.current=new Map,0;let e=new Map,r=0;for(let{block:t,originalIndex:n}of j){let i="text"===t.type?t.text:"thinking"===t.type?t.thinking:"toolCall"===t.type?t.rawInput??JSON.stringify(t.input??{})??"":null;if(null===i)continue;let o=function(e,t){var r,n;if(!e||!t.startsWith(e.text))return tg(t);let i=e.tokens,o=e.text.length;return o>0&&o<t.length&&(r=e.text.charCodeAt(o-1))>=55296&&r<=56319&&(n=t.charCodeAt(o))>=56320&&n<=57343&&(i-=1/4,o--),i+tg(t.slice(o))}($.current.get(n),i);e.set(n,{text:i,tokens:o}),r+=o}return $.current=e,r},[j,t]),A=(0,i.useRef)(P);A.current=P;let D=(0,i.useRef)(new Map),[N,F]=(0,i.useState)(new Map),B=(0,i.useMemo)(()=>{if(!e.timestamp||!d)return;let t=Math.round((e.timestamp-d)/1e3);return t>0?t:void 0},[e.timestamp,d]),H=(0,i.useMemo)(()=>{let t=new Map;if(!r||!e.timestamp)return t;for(let[n,i]of r)if(i.timestamp&&e.timestamp){let r=Math.round((i.timestamp-e.timestamp)/1e3);r>0&&t.set(n,r)}return t},[r,e.timestamp]),O=S.filter(e=>"text"===e.type).map(e=>e.text).join("\n");if((0,i.useEffect)(()=>{if(!t){let e=new Date().getTime();F(t=>{let r=new Map(t);for(let[t,n]of D.current)r.has(t)||r.set(t,Math.round((e-n)/1e3));return r}),L.current=null,W(null);return}let e=setInterval(()=>{let e=z.current,t=Date.now();e.forEach(({originalIndex:e})=>{D.current.has(e)||D.current.set(e,t)}),F(r=>{let n=!1,i=new Map(r);for(let r=0;r<e.length-1;r++){let o=e[r].originalIndex,l=e[r+1].originalIndex;if(!i.has(o)&&D.current.has(o)){let e=D.current.get(o),r=D.current.get(l)??t;i.set(o,Math.round((r-e)/1e3)),n=!0}}return n?i:r});let r=A.current;if(0===r)return;null===L.current&&(L.current=t);let n=(t-L.current)/1e3;n>.5&&W(r/n)},300);return()=>clearInterval(e)},[t]),0===S.length&&!t&&!C)return null;return(0,n.jsx)("div",{style:{marginBottom:20},onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),children:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:"8px 14px",borderRadius:12,background:"var(--assistant-card-glass)",backdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))",border:g?"none":"1px solid color-mix(in srgb, var(--border) 60%, transparent)",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)"},children:[!g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{fontSize:11,color:"var(--text-meta)",display:"flex",alignItems:"center",gap:6},children:[e.provider&&(0,n.jsx)("span",{children:o?.[`${e.provider}:${e.model}`]??o?.[e.model]??e.model}),t&&(m=Math.round(P),(0,n.jsx)(n.Fragment,{children:m>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:"var(--text-meta)"},title:k("i18n.estimatedTokens"),children:[(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:2,fontSize:11,fontWeight:400},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),m]}),null!==E&&(v=E>=50?"#53b3cb":E>=30?"#9bc53d":E>=15?"#f9c22e":"#e01a4f",y=E>=15?"#0f172a":"#fff",(0,n.jsxs)("span",{style:{marginLeft:6,padding:"1px 6px",borderRadius:4,background:v,color:y,fontSize:11,fontWeight:400},children:[E.toFixed(1)," t/s"]}))]})})),h&&(0,n.jsxs)("button",{onClick:t=>h(e,u,t.currentTarget.getBoundingClientRect().top),title:k("i18n.pinTitle"),style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto",padding:"2px 8px",height:22,background:"none",border:"none",borderRadius:5,color:"var(--text-meta)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",opacity:+!!T,pointerEvents:T?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-meta)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0-2-2 3 3 0 0 0-3 3V9a4 4 0 0 1-1 2.65"})]}),k("i18n.pin")]})]}),(0,n.jsx)("div",{style:{height:1,background:"color-mix(in srgb, var(--border) 55%, transparent)",margin:"6px -14px 0"}})]}),j.map(({block:e,originalIndex:i})=>(0,n.jsx)(tk,{block:e,toolResults:r,isStreaming:t,streamingDuration:N.get(i)??("thinking"===e.type?B:void 0),toolCallDurations:H,cwd:l,onOpenFile:a,sessionId:c,entryId:u,blockIndex:i},`${u??"stream"}-${i}`)),C&&(0,n.jsxs)("div",{role:"alert",style:{marginTop:(j.length,0),padding:"7px 10px",border:"1px solid rgba(239,68,68,0.3)",borderRadius:6,background:"rgba(239,68,68,0.07)",color:"#ef4444",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:["Error: ",C]}),p&&p.length>0&&(0,n.jsx)(tp,{files:p,onOpenFile:a}),!g&&!t&&(e.usage||w||O)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{height:1,background:"color-mix(in srgb, var(--border) 55%, transparent)",margin:"2px -14px 0"}}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,paddingTop:2},children:[e.usage&&(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-meta)"},children:(f=e.usage,x=[],f.input&&x.push(`${f.input.toLocaleString()} in`),f.output&&x.push(`${f.output.toLocaleString()} out`),f.cacheRead&&x.push(`${f.cacheRead.toLocaleString()} cache R`),f.cacheWrite&&x.push(`${f.cacheWrite.toLocaleString()} cache W`),f.cost?.total&&x.push(`$${f.cost.total.toFixed(4)}`),x.join(" \xb7 "))}),O&&(0,n.jsxs)("button",{onClick:()=>{tr(O).then(()=>{I(!0),setTimeout(()=>I(!1),1500)})},title:k("i18n.copyMessage"),style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",height:22,background:"none",border:"none",borderRadius:5,color:R?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:400,whiteSpace:"nowrap",opacity:+!!T,pointerEvents:T?"auto":"none",transition:"opacity 0.12s, color 0.12s"},onMouseEnter:e=>{R||(e.currentTarget.style.color="var(--accent)")},onMouseLeave:e=>{R||(e.currentTarget.style.color="var(--text-muted)")},children:[R?(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),k(R?"i18n.copied":"i18n.copy")]}),w&&(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-meta)",marginLeft:"auto"},children:w})]})]})]})})}function tk({block:e,toolResults:t,isStreaming:r,streamingDuration:i,toolCallDurations:o,cwd:l,onOpenFile:a,sessionId:s,entryId:d,blockIndex:c}){if("text"===e.type)return(0,n.jsx)(tw,{block:e,isStreaming:r,cwd:l,onOpenFile:a});if("thinking"===e.type)return(0,n.jsx)(tj,{block:e,duration:i,sessionId:s,entryId:d,blockIndex:c});if("toolCall"===e.type){let r=t?.get(e.toolCallId),i=o?.get(e.toolCallId);return(0,n.jsx)(tS,{block:e,result:r,duration:i})}return null}function tw({block:e,isStreaming:t,cwd:r,onOpenFile:i}){return(0,n.jsx)(tx,{isStreaming:t,cwd:r,onOpenFile:i,children:e.text})}function tj({block:e,duration:t,sessionId:r,entryId:o,blockIndex:l}){let{t:a}=(0,b.s)(),[s,d]=(0,i.useState)(!1),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(!1),[g,f]=(0,i.useState)(null),x=async()=>{let t=!s;if(d(t),t&&e.deferred&&null===c){if(!r||!o)return void f(a("i18n.thinkingUnavailable"));h(!0),f(null);try{u(await function(e,t,r){let n=`${e}:${t}:${r}`,i=tf.get(n);if(i)return tf.delete(n),tf.set(n,i),i;let o=fetch(`/api/sessions/${encodeURIComponent(e)}/entries/${encodeURIComponent(t)}/thinking?blockIndex=${r}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();if("string"!=typeof t.thinking)throw Error("Invalid thinking response");return t.thinking}).catch(e=>{throw tf.delete(n),e});if(tf.set(n,o),tf.size>100){let e=tf.keys().next().value;e&&tf.delete(e)}return o}(r,o,l))}catch(e){f(e instanceof Error?e.message:String(e))}finally{h(!1)}}};return(0,n.jsxs)("div",{style:{border:"1px solid color-mix(in srgb, var(--border) 50%, transparent)",borderRadius:10,overflow:"hidden",fontSize:13,background:"color-mix(in srgb, var(--tool-bg-glass) 62%, transparent)",boxShadow:"0 1px 3px rgba(15,23,42,0.05)"},children:[(0,n.jsxs)("button",{onClick:()=>void x(),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"7px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left"},children:[(0,n.jsx)("span",{children:a("i18n.thinking")}),void 0!==t&&(0,n.jsxs)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-dim)",fontVariantNumeric:"tabular-nums"},children:[t,"s"]})]}),s&&(0,n.jsx)("div",{style:{padding:"8px 10px",color:g?"#f87171":"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",background:"color-mix(in srgb, var(--tool-bg-glass) 66%, transparent)",borderTop:"1px solid color-mix(in srgb, var(--border) 45%, transparent)"},children:p?a("i18n.loadingThinking"):g??(e.deferred?c:e.thinking)})]})}function tS({block:e,result:t,duration:r}){var o;let{t:l}=(0,b.s)(),[a,s]=(0,i.useState)(!1),d=(o=e).rawInput??JSON.stringify(o.input,null,2),c=void 0!==e.rawInput,u=eL(e.toolName),p=t&&!t.isError?function(e){var t;let r=e.details;if(!("object"==typeof(t=r)&&null!==t&&!Array.isArray(t)))return null;let n="string"==typeof r.patch?r.patch:null;if(n)return{text:n};let i="string"==typeof r.diff?r.diff:null;return i?{text:i}:null}(t):null,h=t?t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"):null,g=null!==h&&("(no output)"===h.trim()||""===h.trim()),f=t?.isError??!1;return(0,n.jsxs)("div",{style:{borderRadius:7,overflow:"hidden",fontSize:12,border:f?"1px solid rgba(248,113,113,0.45)":"1px solid rgba(34,197,94,0.25)",background:"color-mix(in srgb, var(--tool-bg-glass) 62%, transparent)",backdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))"},children:[(0,n.jsxs)("button",{onClick:()=>s(e=>!e),style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"6px 10px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",minWidth:0},children:[(0,n.jsx)("span",{style:{color:f?"#f87171":"#16a34a",fontFamily:"var(--font-mono)",fontWeight:600,fontSize:11,flexShrink:0},children:e.toolName}),(0,n.jsx)("span",{style:{color:"var(--text-meta)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:c?l("chat.generatingToolInput"):function(e){let t=e.input;if(!t||"object"!=typeof t)return"";let r=Object.keys(t);return 0===r.length?"":"command"in t?String(t.command).slice(0,120):"path"in t?String(t.path).slice(0,120):"file_path"in t?String(t.file_path).slice(0,120):"pattern"in t?String(t.pattern).slice(0,120):"query"in t?String(t.query).slice(0,120):String(t[r[0]]).slice(0,120)}(e)}),void 0!==r&&(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",flexShrink:0,fontVariantNumeric:"tabular-nums"},children:[r,"s"]}),(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:a?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),a&&(c||!u)&&(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:"var(--text)",fontSize:12,lineHeight:1.5,overflow:"auto",background:"var(--bg-subtle)",borderTop:f?"1px solid rgba(248,113,113,0.25)":"1px solid rgba(34,197,94,0.2)",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:d}),a&&t&&(p?(0,n.jsx)(tC,{diff:p}):(0,n.jsx)(tL,{text:h??"",isEmpty:g,isError:f})),a&&t&&(0,n.jsx)(tA,{content:t.content,isError:f})]})}function tC({diff:e}){return(0,n.jsx)("div",{style:{borderTop:"1px solid rgba(34,197,94,0.15)",background:"color-mix(in srgb, var(--tool-bg-glass) 55%, transparent)"},children:(0,n.jsx)(tT,{text:e.text})})}function tT({text:e}){let{t}=(0,b.s)(),r=(0,i.useMemo)(()=>tc(e),[e]);if(!r)return(0,n.jsx)(tI,{text:e});let o=r.length>1;return(0,n.jsx)("div",{style:{maxHeight:560,overflowY:"auto",overflowX:"hidden",background:"var(--bg)"},children:r.map((e,r)=>(0,n.jsxs)("div",{style:{minWidth:0,borderTop:0===r?"none":"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55},children:[o&&(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",position:"sticky",top:0,zIndex:1,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)(tM,{title:e.oldPath||t("i18n.before"),side:"left"}),(0,n.jsx)(tM,{title:e.newPath||t("i18n.after"),side:"right"})]}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)"},children:e.rows.map((e,t)=>"hunk"===e.type?null:(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)(tR,{cell:e.left,side:"left"}),(0,n.jsx)(tR,{cell:e.right,side:"right"})]},t))})]},r))})}function tM({title:e,side:t}){return(0,n.jsx)("div",{title:e,style:{padding:"5px 10px",color:"var(--text-dim)",borderRight:"left"===t?"1px solid var(--border)":"none",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})}function tR({cell:e,side:t}){let r="added"===e.type?"rgba(34,197,94,0.12)":"removed"===e.type?"rgba(248,113,113,0.13)":"empty"===e.type?"var(--bg-subtle)":"transparent",i="added"===e.type?"+":"removed"===e.type?"-":" ",o="added"===e.type?"#22c55e":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,n.jsxs)("div",{style:{display:"flex",minWidth:0,background:r,borderRight:"left"===t?"1px solid var(--border)":"none"},children:[(0,n.jsx)("span",{style:{width:42,padding:"0 6px",textAlign:"right",color:"var(--text-dim)",userSelect:"none",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",flexShrink:0},children:e.lineNo??""}),(0,n.jsx)("span",{style:{width:18,padding:"0 5px",color:o,userSelect:"none",fontWeight:"context"===e.type||"empty"===e.type?400:700,flexShrink:0},children:i}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 10px 0 0",color:"empty"===e.type?"var(--text-dim)":"var(--text)",whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:e.text||"\xa0"})]})}function tI({text:e}){let t=e.split(/\r?\n/);return(0,n.jsx)("div",{style:{maxHeight:520,overflowY:"auto",overflowX:"hidden",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55,minWidth:0},children:t.map((e,t)=>{let r=e.startsWith("@@")?"hunk":e.startsWith("+")&&!e.startsWith("+++")?"added":e.startsWith("-")&&!e.startsWith("---")?"removed":"context";return(0,n.jsxs)("div",{style:{display:"flex",background:"added"===r?"rgba(34,197,94,0.12)":"removed"===r?"rgba(248,113,113,0.13)":"hunk"===r?"rgba(96,165,250,0.12)":"transparent",borderLeft:"added"===r?"3px solid #22c55e":"removed"===r?"3px solid #f87171":"hunk"===r?"3px solid var(--accent)":"3px solid transparent"},children:[(0,n.jsx)("span",{style:{width:48,padding:"0 8px",color:"var(--text-dim)",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",textAlign:"right",userSelect:"none",flexShrink:0},children:t+1}),(0,n.jsx)("span",{style:{padding:"0 10px",whiteSpace:"pre-wrap",overflowWrap:"anywhere",color:"added"===r?"#22c55e":"removed"===r?"#f87171":"hunk"===r?"var(--accent)":"var(--text)"},children:e||"\xa0"})]},t)})})}function tL({text:e,isEmpty:t,isError:r}){let{t:i}=(0,b.s)();return(0,n.jsx)("div",{style:{borderTop:`1px solid ${r?"rgba(248,113,113,0.3)":"rgba(34,197,94,0.15)"}`,background:"color-mix(in srgb, var(--tool-bg-glass) 55%, transparent)"},children:(0,n.jsx)("pre",{style:{margin:0,padding:"8px 10px",color:r?"#f87171":t?"var(--text-dim)":"var(--text-muted)",fontSize:12,lineHeight:1.5,overflow:"auto",maxHeight:400,background:"var(--bg)",whiteSpace:"pre-wrap",wordBreak:"break-all",fontStyle:t?"italic":"normal",opacity:t?.6:1},children:t?i("i18n.noOutput"):e})})}function tE({message:e}){let{t}=(0,b.s)(),r=tP(e.content),o=(0,i.useMemo)(()=>{let e,t,n,i,o;return e=[],t=[],n=r.match(td),i=n?.[1]??"",o=n?.index===void 0?r:r.slice(0,n.index),i.replace(ts,(r,n,i)=>{let o=i.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);return"read-files"===n?e.push(...o):t.push(...o),""}),{body:o.trim(),readFiles:e,modifiedFiles:t}},[r]),l=tm(e.timestamp);return(0,n.jsx)("div",{style:{marginBottom:20},children:(0,n.jsxs)("div",{style:{borderRadius:12,overflow:"hidden",background:"var(--assistant-card-glass)",backdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",color:"var(--text-muted)"},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:"compaction"}),l&&(0,n.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:l})]}),(0,n.jsxs)("div",{style:{padding:"11px 13px 12px"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:15,fontWeight:700,lineHeight:1.35},children:t("i18n.conversationCompacted")}),(0,n.jsx)("div",{style:{marginTop:3,marginBottom:10,color:"var(--text)",fontSize:14,lineHeight:1.5},children:t("i18n.compactionDescription")}),o.body?(0,n.jsx)(tl,{className:"markdown-compaction-message",children:o.body}):(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:t("i18n.noSummary")}),(0,n.jsx)(tW,{readFiles:o.readFiles,modifiedFiles:o.modifiedFiles})]})]})})}function tW({readFiles:e,modifiedFiles:t}){let{t:r}=(0,b.s)();if(0===e.length+t.length)return null;let i=[];return e.length>0&&i.push(`${e.length} read`),t.length>0&&i.push(`${t.length} modified`),(0,n.jsxs)("details",{className:"compaction-file-details",children:[(0,n.jsx)("summary",{children:r("i18n.fileContext",{details:i.join(", ")})}),t.length>0&&(0,n.jsx)(tz,{title:r("i18n.modifiedFiles"),files:t}),e.length>0&&(0,n.jsx)(tz,{title:r("i18n.readFiles"),files:e})]})}function tz({title:e,files:t}){return(0,n.jsxs)("div",{className:"compaction-file-section",children:[(0,n.jsx)("div",{className:"compaction-file-title",children:e}),(0,n.jsx)("ul",{className:"compaction-file-list",children:t.map(e=>(0,n.jsx)("li",{children:e},e))})]})}function t$({message:e,cwd:t,onOpenFile:r}){var o;let l,{t:a}=(0,b.s)(),s=!1===e.display,[d,c]=(0,i.useState)(!s),[u,p]=(0,i.useState)(!1),[h,g]=(0,i.useState)(!1),f=tP(e.content),x="string"==typeof(o=e.content)?[]:o.filter(e=>"image"===e.type),m=void 0!==e.details,v=m?function(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}(e.details):"",y=e.customType||"extension",k=tm(e.timestamp);return(0,n.jsx)("div",{style:{marginBottom:20},children:(0,n.jsxs)("div",{style:{borderRadius:12,overflow:"hidden",background:s?"color-mix(in srgb, var(--assistant-card-glass) 62%, transparent)":"var(--assistant-card-glass)",backdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-bubble)) saturate(var(--glass-saturate))",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)",opacity:s&&!d?.82:1},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",borderBottom:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",color:"var(--text-muted)",fontSize:11},children:[(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",fontSize:11,fontWeight:650},children:y}),s&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:a("i18n.hiddenExtensionMessage")}),k&&(0,n.jsx)("span",{style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10},children:k})]}),d?(0,n.jsxs)("div",{style:{padding:"6px 9px"},children:[x.length>0&&(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8*!!f},children:x.map((e,t)=>{var r;let i=(r=e).source?"base64"===r.source.type?`data:${r.source.media_type};base64,${r.source.data}`:r.source.url??"":r.data?`data:${r.mimeType};base64,${r.data}`:"";return i?(0,n.jsx)(ta,{src:i,children:(0,n.jsx)("img",{src:i,alt:"",style:{maxWidth:240,maxHeight:240,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid var(--border)"}})},t):null})}),f?(0,n.jsx)(tl,{className:"markdown-custom-message",cwd:t,onOpenFile:r,children:f}):(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:12},children:a("i18n.noMessage")})]}):(0,n.jsx)("button",{onClick:()=>c(!0),style:{display:"block",width:"100%",padding:"8px 10px",border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",fontSize:12,textAlign:"left"},children:f?(l=f.replace(/\s+/g," ").trim())?l.length>140?`${l.slice(0,140)}...`:l:"Show extension message":a("i18n.showExtensionMessage")}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 9px",borderTop:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",background:"color-mix(in srgb, var(--tool-bg-glass) 66%, transparent)"},children:[f||v?(0,n.jsx)("button",{onClick:()=>{tr(f||v).then(()=>{g(!0),setTimeout(()=>g(!1),1500)})},style:{padding:"3px 7px",border:"none",background:"none",color:h?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:11},children:a(h?"i18n.copied":"i18n.copy")}):null,(m||s)&&(0,n.jsx)("button",{onClick:()=>{s?c(e=>!e):p(e=>!e)},style:{marginLeft:"auto",padding:"3px 7px",border:"none",background:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11},children:a(s?d?"i18n.collapse":"i18n.expand":u?"i18n.hideDetails":"i18n.showDetails")})]}),m&&(s&&d||!s&&u)&&(0,n.jsx)("pre",{style:{margin:0,padding:"9px 10px",borderTop:"1px solid color-mix(in srgb, var(--border) 55%, transparent)",background:"color-mix(in srgb, var(--assistant-card-glass) 55%, transparent)",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:360,overflow:"auto",fontFamily:"var(--font-mono)"},children:v})]})})}function tP(e){return"string"==typeof e?e:e.filter(e=>"text"===e.type).map(e=>e.text).join("\n")}function tA({content:e,isError:t}){let r=(e??[]).filter(e=>"object"==typeof e&&null!==e&&"image"===e.type);return 0===r.length?null:(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",padding:"8px 10px",borderTop:t?"1px solid rgba(248,113,113,0.25)":"1px solid rgba(34,197,94,0.15)",background:"var(--bg)"},children:r.map((e,t)=>{let r=e.source?"base64"===e.source.type?`data:${e.source.media_type};base64,${e.source.data}`:e.source.url??"":e.data?`data:${e.mimeType};base64,${e.data}`:"";return r?(0,n.jsx)(ta,{src:r,children:(0,n.jsx)("img",{src:r,alt:"",style:{maxWidth:220,maxHeight:220,borderRadius:6,objectFit:"contain",display:"block",border:"1px solid var(--border)"}})},t):null})})}function tD({message:e,sessionId:t}){let[r,o]=(0,i.useState)(null),[l,a]=(0,i.useState)(!1),[s,d]=(0,i.useState)(null),c=!e.output&&void 0===e.exitCode&&!e.cancelled,u=e.cancelled||void 0!==e.exitCode&&0!==e.exitCode,p=t&&e.fullOutputPath?`/api/agent/${encodeURIComponent(t)}/bash-output?path=${encodeURIComponent(e.fullOutputPath)}`:null,h=e.truncated&&p&&null===r,g=r??e.output;async function f(){if(p){a(!0),d(null);try{let e=await fetch(p),t=await e.json();t.success?o(t.data?.output??""):d(t.error??"failed")}catch(e){d(String(e))}finally{a(!1)}}}let x=e.excludeFromContext?"bash (local)":"bash",m={type:"toolCall",toolCallId:`bash-${e.timestamp??""}`,toolName:x,input:{command:e.command}},v=c?void 0:{role:"toolResult",toolCallId:m.toolCallId,toolName:x,content:g?[{type:"text",text:g}]:[],isError:u,timestamp:e.timestamp};return(0,n.jsxs)("div",{style:{margin:"6px 0"},children:[(0,n.jsx)(tS,{block:m,result:v}),e.truncated&&p&&(0,n.jsxs)("div",{style:{padding:"4px 10px",fontSize:11,marginTop:-1},children:[h&&(0,n.jsx)("button",{onClick:f,disabled:l,style:{background:"none",border:"none",color:"var(--accent)",cursor:l?"default":"pointer",fontSize:11,padding:0,textDecoration:"underline"},children:l?"loading…":"view full output"}),(0,n.jsx)("a",{href:`${p}&download=1`,style:{marginLeft:10*!!h,color:"var(--accent)",fontSize:11,textDecoration:"underline"},children:"download full output"}),s&&(0,n.jsxs)("span",{style:{marginLeft:6,color:"var(--text-dim)",fontSize:11},children:["(",s,")"]})]})]})}function tN({item:e,render:t,zIndex:r,active:o,onClose:l,onActivate:a,onMove:s}){var d;let c,u=(0,i.useRef)(null),p=(0,i.useRef)(null);(0,i.useEffect)(()=>()=>{p.current&&(p.current=null,document.body.style.cursor="",document.body.style.userSelect="")},[]);let h=(t,r)=>{"mouse"===r.pointerType&&0!==r.button||(r.preventDefault(),r.stopPropagation(),a(e.id),p.current&&g(r.pointerId),r.currentTarget.setPointerCapture(r.pointerId),p.current={mode:t,pointerId:r.pointerId,startX:r.clientX,startY:r.clientY,origX:e.x,origY:e.y,origW:e.w,origH:e.h},document.body.style.cursor="move"===t?"grabbing":"nwse-resize",document.body.style.userSelect="none")},g=e=>{let t=p.current;t&&t.pointerId===e&&(p.current=null,document.body.style.cursor="",document.body.style.userSelect="")},f=t=>{let r=p.current;if(!r||r.pointerId!==t.pointerId)return;if("mouse"===t.pointerType&&0===t.buttons)return void g(t.pointerId);t.preventDefault();let n=window.innerWidth,i=window.innerHeight,o=t.clientX-r.startX,l=t.clientY-r.startY;if("move"===r.mode){let t=e.w,a=e.h,d=Math.max(0,n-t),c=Math.max(0,i-a);s(e.id,{x:Math.min(d,Math.max(0,r.origX+o)),y:Math.min(c,Math.max(0,r.origY+l))})}else{let t=Math.max(220,n-r.origX),a=Math.max(140,i-r.origY);s(e.id,{w:Math.min(t,Math.max(220,r.origW+o)),h:Math.min(a,Math.max(140,r.origH+l))})}},x=e=>{g(e.pointerId);let t=e.currentTarget;try{t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId)}catch{}},m="user"===e.message.role?"用户":"助手";return(0,n.jsxs)("div",{ref:u,"data-pin-bubble":!0,tabIndex:0,style:{position:"fixed",left:e.x,top:e.y,width:e.w,height:e.h,zIndex:r,display:"flex",flexDirection:"column",background:"var(--bg-panel)",border:o?"1px solid color-mix(in srgb, var(--border) 90%, transparent)":"1px solid var(--border)",borderRadius:10,boxShadow:o?"0 0 14px 1px color-mix(in srgb, var(--border) 50%, transparent), 0 1px 2px rgba(15,23,42,0.05), 0 8px 30px rgba(0,0,0,0.35)":"0 8px 30px rgba(0,0,0,0.35)",overflow:"hidden",colorScheme:"dark"},onPointerDown:t=>{t.target===t.currentTarget&&a(e.id)},children:[(0,n.jsxs)("div",{"data-pin-handle":!0,onPointerDown:e=>h("move",e),onPointerMove:f,onPointerUp:x,style:{display:"flex",alignItems:"center",gap:8,padding:"4px 8px",cursor:"grab",flexShrink:0,touchAction:"none",background:"color-mix(in srgb, var(--bg-hover) 60%, transparent)",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-muted)",userSelect:"none"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0-2-2 3 3 0 0 0-3 3V9a4 4 0 0 1-1 2.65"})]}),(0,n.jsx)("span",{style:{fontWeight:600},children:m}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",opacity:.7},children:(c=(e=>{if("string"==typeof e)return e;if(Array.isArray(e)){for(let t of e)if(t&&"object"==typeof t){if("string"==typeof t.text)return t.text;if("toolCall"===t.type)return`${t.name??"tool"} ${tF(t.text??"")}`;if("string"==typeof t.thinking)return t.thinking}}return null})((d=e.message).content)??d.summary??"",tF(c.replace(/\s+/g," ")))}),(0,n.jsx)("button",{onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),l(e.id)},title:"关闭",style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,background:"none",border:"none",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"6px 8px"},children:(0,n.jsx)(tv,{message:e.message,isStreaming:!1,bare:!0,toolResults:t.toolResults,modelNames:t.modelNames,cwd:t.cwd,onOpenFile:t.onOpenFile,sessionId:t.sessionId,entryId:t.entryId,writtenFiles:t.writtenFiles})}),(0,n.jsx)("div",{"data-pin-resize":!0,onPointerDown:e=>h("resize",e),onPointerMove:f,onPointerUp:x,style:{position:"absolute",right:0,bottom:0,width:18,height:18,cursor:"nwse-resize",touchAction:"none"},"aria-label":"调整大小",children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",style:{position:"absolute",right:2,bottom:2,pointerEvents:"none"},children:[(0,n.jsx)("path",{d:"M14 20 20 14"}),(0,n.jsx)("path",{d:"M14 14 20 20"}),(0,n.jsx)("path",{d:"M8 20 20 8"})]})})]})}function tF(e,t=40){return e.length<=t?e:e.slice(0,t).trimEnd()+"…"}function tB(e){if(!e||"object"!=typeof e||"string"!=typeof e.data||"string"!=typeof e.mimeType||!e.mimeType.startsWith("image/"))return!1;let t=function(e){if(!e||e.length%4!=0)return null;let t=e.endsWith("==")?2:+!!e.endsWith("="),r=e.length-t;for(let t=0;t<r;t+=1){var n;if(!((n=e.charCodeAt(t))>=65&&n<=90||n>=97&&n<=122||n>=48&&n<=57||43===n||47===n))return null}for(let t=r;t<e.length;t+=1)if("="!==e[t])return null;return e.length/4*3-t}(e.data);return null!==t&&t<=0xa00000}let tH=new Map;function tO(e){return{value:e.value,images:e.images.map(e=>({...e}))}}function tU(e){return!e.value&&0===e.images.length}function t_(e){let t=tH.get(e);return t?tO(t):null}function tq(e,t){tU(t)?tH.delete(e):tH.set(e,tO(t))}function tK(e){tH.delete(e)}function tV(e,t){return e.trim()?t.trim()?`${e}
3
+
4
+ ${t}`:e:t}function tJ(e,t,r,n){let i=[...t??[],...n].filter(tB).slice(0,10).map(({data:e,mimeType:t})=>({data:e,mimeType:t}));return{value:tV(e,r),images:i}}function tY(e,t,r){if(e===t)return r?tO(r):t_(t);let n=t_(e),i=r&&!tU(r)?tO(r):n??(r?tO(r):null),o=t_(t);if(tK(e),!i)return o;let l=o?tJ(o.value,o.images,i.value,i.images):i;return tq(t,l),tO(l)}function tX(e){let t=/(?:^|\s)@"([^"\n]*)$/.exec(e);if(t)return{start:e.length-(t[1].length+2),query:t[1],quoted:!0};let r=/(?:^|\s)@([^\s"]*)$/.exec(e);return r?{start:e.length-(r[1].length+1),query:r[1],quoted:!1}:null}function tZ(e){let t=0;for(let r=0;r<e.length;r++)"/"===e[r]&&t++;return t}function tG(e,t){if(!e)return!0;let r=0;for(let n=0;n<t.length&&r<e.length;n++)t[n]===e[r]&&r++;return r===e.length}function tQ(e,t){let r=t?`${e}/`:e;return r.includes(" ")?`@"${r}" `:`@${r} `}let t0="pi-web.drafts.v1";function t1(){return"u">typeof localStorage?localStorage:null}function t2(e){return"object"==typeof e&&null!==e&&"string"==typeof e.id&&"string"==typeof e.content&&"number"==typeof e.updatedAt}function t8(){let e=t1();if(!e)return[];try{let t=e.getItem(t0);if(!t)return[];let r=JSON.parse(t);if(!Array.isArray(r))return[];return r.filter(t2).sort((e,t)=>t.updatedAt-e.updatedAt)}catch{return[]}}function t4(e){let t=t1();if(t)try{t.setItem(t0,JSON.stringify(e))}catch{}}function t6(e,t=Date.now()){let r={id:"u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,content:e,updatedAt:t};return t4([r,...t8()]),r}function t5(e,t,r=Date.now()){let n=t8(),i=n.findIndex(t=>t.id===e);if(i<0)return null;let o={...n[i],content:t,updatedAt:r};return n.splice(i,1),n.unshift(o),t4(n),o}function t3(e){t4(t8().filter(t=>t.id!==e))}function t7(e){return e<10?`0${e}`:String(e)}var t9=r(59767),re=r.n(t9);function rt(e,t){let r=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value")?.set;r&&r.call(e,t),e.dispatchEvent(new Event("input",{bubbles:!0}))}function rr(e,t){return null!==e&&t.some(t=>t.id===e)}function rn({items:e,expanded:t,activeItem:r,onToggle:i,onPick:o,onDelete:l,onCancelActive:a}){return 0===e.length?null:(0,n.jsxs)("div",{className:re().panel,role:"region","aria-label":"草稿暂存区",children:[(0,n.jsxs)("button",{type:"button",className:re().toggle,onClick:i,"aria-expanded":t,"aria-label":t?"收起草稿列表":"展开草稿列表",children:[(0,n.jsxs)("span",{className:re().toggleLabel,children:[e.length," 条草稿"]}),(0,n.jsx)("span",{className:re().toggleArrow,children:t?"▴":"▾"})]}),t&&(0,n.jsxs)("div",{className:re().expandArea,children:[r&&(0,n.jsxs)("div",{className:re().activeBar,children:[(0,n.jsx)("span",{className:re().activeDot}),(0,n.jsx)("span",{className:re().activeLabel,children:"正在编辑草稿"}),(0,n.jsx)("button",{type:"button",className:re().cancelBtn,onClick:a,title:"取消关联(内容保留在输入框)","aria-label":"取消草稿关联",children:"✕"})]}),(0,n.jsx)("div",{className:re().list,children:e.map(e=>(0,n.jsxs)("div",{className:re().row,children:[(0,n.jsx)("button",{type:"button",className:re().btn,onClick:()=>o(e.id),title:"回填到输入框","aria-label":"回填到输入框",children:(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 5 H1"}),(0,n.jsx)("polyline",{points:"4 1.5 1 5 4 8.5"})]})}),(0,n.jsx)("span",{className:re().content,title:e.content,children:e.content}),(0,n.jsx)("span",{className:re().time,children:function(e,t=Date.now()){let r=t-e;if(r<6e4)return"刚刚";if(r<36e5)return`${Math.floor(r/6e4)}分钟前`;let n=new Date(e),i=new Date(t),o=new Date(i.getFullYear(),i.getMonth(),i.getDate()).getTime();return e>=o?`${t7(n.getHours())}:${t7(n.getMinutes())}`:e>=o-864e5?"昨天":n.getFullYear()===i.getFullYear()?`${n.getMonth()+1}月${n.getDate()}日`:`${n.getFullYear()}年${n.getMonth()+1}月${n.getDate()}日`}(e.updatedAt)}),(0,n.jsx)("button",{type:"button",className:`${re().btn} ${re().btnDanger}`,onClick:()=>l(e.id),title:"删除草稿","aria-label":"删除草稿",children:(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,n.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]},e.id))})]})]})}function ri(){let[e,t]=(0,i.useState)([]),[r,o]=(0,i.useState)(null),[l,a]=(0,i.useState)(!1),s=(0,i.useRef)(e),d=(0,i.useRef)(r);(0,i.useEffect)(()=>{s.current=e},[e]),(0,i.useEffect)(()=>{d.current=r},[r]),(0,i.useEffect)(()=>{t(t8())},[]);let c=(0,i.useCallback)(()=>t(t8()),[]);(0,i.useEffect)(()=>{let e=e=>{let t=e.target;t instanceof HTMLTextAreaElement&&!t.value.trim()&&d.current&&o(null)};return document.addEventListener("input",e,!0),()=>document.removeEventListener("input",e,!0)},[]),(0,i.useEffect)(()=>{let e=e=>{if(e.isComposing||!(e.ctrlKey||e.metaKey)||e.altKey||e.shiftKey)return;let t=document.activeElement instanceof HTMLTextAreaElement?document.activeElement:null;if(t){if("s"===e.key.toLowerCase()){if(e.preventDefault(),!t.value.trim())return;let r=d.current;rr(r,s.current)?t5(r,t.value):t6(t.value),o(null),c(),rt(t,"");return}if("Delete"===e.key){e.preventDefault();let r=d.current;rr(r,s.current)&&(t3(r),o(null),c()),rt(t,"");return}"Enter"===e.key&&!e.shiftKey&&d.current&&setTimeout(()=>{t.value.trim()||o(null)},0)}};return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[c]);let u=(0,i.useCallback)(e=>{let t=s.current.find(t=>t.id===e);if(!t)return;let r=document.activeElement instanceof HTMLTextAreaElement?document.activeElement:document.querySelector("textarea");if(r){if(r.value.trim()){let e=d.current;rr(e,s.current)?t5(e,r.value):t6(r.value)}o(e),c(),rt(r,t.content),r.focus()}},[c]),p=(0,i.useCallback)(e=>{t3(e),d.current===e&&o(null),c()},[c]);if(0===e.length)return null;let h=null!==r?e.find(e=>e.id===r)??null:null;return(0,n.jsx)(rn,{items:e,expanded:l,activeItem:h,onToggle:()=>a(e=>!e),onPick:u,onDelete:p,onCancelActive:()=>o(null)})}var ro=r(31590);let rl=["off","read-only","default","full"],ra={off:"none","read-only":"read-only",default:"default",full:"full"},rs=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function rd(e,t){return rs.compare(e.name||e.modelId,t.name||t.modelId)||rs.compare(e.provider,t.provider)||rs.compare(e.modelId,t.modelId)}let rc=["auto","off","minimal","low","medium","high","xhigh","max"],ru={auto:"chat.thinkingUseDefault",off:"chat.thinkingOff",minimal:"chat.thinkingMinimal",low:"chat.thinkingLow",medium:"chat.thinkingMedium",high:"chat.thinkingHigh",xhigh:"chat.thinkingXhigh",max:"chat.thinkingMax"};function rp(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:e.toLocaleString()}let rh=[{name:"compact",description:"chat.commandCompact",source:"builtin"},{name:"reload",description:"chat.commandReload",source:"builtin"},{name:"name",description:"chat.commandName",source:"builtin"},{name:"session",description:"chat.commandSession",source:"builtin",availableWhileStreaming:!0},{name:"copy",description:"chat.commandCopy",source:"builtin",availableWhileStreaming:!0}];function rg(e){return function(e){let t=e.trim().match(/^\/([^\s]+)(?:\s|$)/);if(t)return rh.find(e=>e.name===t[1])}(e)?.availableWhileStreaming===!0}let rf=["builtin","extension","prompt","skill"],rx={builtin:"chat.builtIn",extension:"chat.extensions",prompt:"chat.prompts",skill:"chat.skills"},rm={builtin:0,extension:1,prompt:2,skill:3};function rv(e,t,r){let n=e.name.toLowerCase(),i=rb(e,r).toLowerCase();return n===t?0:n.startsWith(t)?1:n.includes(t)?2:i.includes(t)?3:4}function rb(e,t){return"builtin"===e.source?t(e.description):e.description??""}function ry(e,t){return"skill"===e.source&&!!e.name.startsWith("skill:")&&!0===t[e.name.slice(6)]}async function rk(e){let t=await createImageBitmap(e).catch(()=>null);if(!t)return{data:btoa(String.fromCharCode(...new Uint8Array(await e.arrayBuffer()))),mimeType:e.type};let r=Math.max(t.width,t.height),n=r>1024?1024/r:1,i=Math.max(1,Math.round(t.width*n)),o=Math.max(1,Math.round(t.height*n)),l=document.createElement("canvas");l.width=i,l.height=o;let a=l.getContext("2d");return a?(a.drawImage(t,0,0,i,o),t.close(),{data:l.toDataURL("image/jpeg",.85).split(",")[1]??"",mimeType:"image/jpeg"}):(t.close(),{data:btoa(String.fromCharCode(...new Uint8Array(await e.arrayBuffer()))),mimeType:e.type})}function rw(e){return{data:e.data,mimeType:e.mimeType}}function rj(e){return{...e,previewUrl:`data:${e.mimeType};base64,${e.data}`}}function rS(e){return(e??[]).filter(tB).slice(0,10).map(rj)}function rC(e){e.previewUrl.startsWith("blob:")&&URL.revokeObjectURL(e.previewUrl)}function rT({kind:e,text:t}){return(0,n.jsxs)("div",{title:t,style:{display:"flex",alignItems:"center",gap:8,padding:"3px 10px",fontSize:12,color:"var(--text-muted)",minWidth:0},children:[(0,n.jsx)("span",{style:{flexShrink:0,fontSize:10,fontFamily:"var(--font-mono)",padding:"1px 7px",borderRadius:999,border:`1px solid ${"steer"===e?"color-mix(in srgb, var(--accent) 45%, transparent)":"var(--border)"}`,color:"steer"===e?"var(--accent)":"var(--text-dim)"},children:e}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t})]})}function rM({tone:e,title:t,body:r}){let[o,l]=(0,i.useState)(!1);if((0,i.useEffect)(()=>{l(!1)},[t,r]),o)return null;let a="error"===e?"#ef4444":"#f59e0b";return(0,n.jsxs)("div",{role:"alert",style:{position:"relative",marginBottom:8,padding:"8px 30px 8px 12px",borderRadius:10,border:`1px solid color-mix(in srgb, ${a} 45%, transparent)`,background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",color:"var(--text)",fontSize:12,lineHeight:1.5,boxShadow:"0 2px 12px -4px rgba(15,23,42,0.16)",animation:"notice-shelf-in 0.18s ease-out both"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:6,height:6,borderRadius:"50%",marginTop:6,background:a}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontWeight:600},children:t}),(0,n.jsx)("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"anywhere"},children:r})]})]}),(0,n.jsx)("button",{type:"button","aria-label":"Dismiss",onClick:()=>l(!0),style:{position:"absolute",top:6,right:6,display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",borderRadius:5},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M1 1l8 8M9 1l-8 8"})})})]})}function rR({error:e}){return e?(0,n.jsx)(rM,{tone:"error",title:"Model error",body:e}):null}function rI({warnings:e}){return e&&0!==e.length?(0,n.jsx)(rM,{tone:"warning",title:e.length>1?"Model scope warnings":"Model scope warning",body:e.join("\n")}):null}let rL=(0,i.forwardRef)(function({onSend:e,onAbort:t,onSteer:r,onFollowUp:o,isStreaming:l,model:a,isAutoModelSelection:s,modelNames:d,modelList:c,modelError:u,modelScopeWarnings:p,onModelChange:h,modelSwitching:g,onCompact:f,onAbortCompaction:x,isCompacting:m,compactError:v,compactResult:y,toolPreset:k,onToolPresetChange:S,thinkingLevel:C,onThinkingLevelChange:T,availableThinkingLevels:M,thinkingLevelMap:R,retryInfo:I,queuedMessages:E,inputHistory:W=[],onRecallQueue:$,slashCommands:P,slashCommandsLoading:A,onLoadSlashCommands:D,onBuiltinCommand:N,soundEnabled:F,onSoundToggle:B,onAudioUnlock:H,onPromptWithStreamingBehavior:O,draftKey:U,cwd:_,atBottom:q=!0,onScrollToBottom:K},V){let J,Y,X,Z,G,Q,ee,et,er,en,{t:ei}=(0,b.s)(),eo=(0,ro.a)(),[el,ea]=(0,i.useState)(()=>U?t_(U)?.value??"":""),[es,ed]=(0,i.useState)(!1);(0,i.useEffect)(()=>{ed(!1)},[v]);let[ec,eu]=(0,i.useState)(!1),[ep,eh]=(0,i.useState)(null),[eg,ef]=(0,i.useState)(""),[ex,em]=(0,i.useState)(!1),[ev,eb]=(0,i.useState)(!1),[ey,ek]=(0,i.useState)(!1),[ew,ej]=(0,i.useState)(()=>U?rS(t_(U)?.images):[]),[eS,eC]=(0,i.useState)(!1),eT=el.trimStart(),eM=0===ew.length&&eT.startsWith("!"),eR=eM&&eT.startsWith("!!"),[eI,eL]=(0,i.useState)(!1),[eE,eW]=(0,i.useState)(0),[ez,e$]=(0,i.useState)(null),[eP,eA]=(0,i.useState)(null),[eD,eN]=(0,i.useState)(!1),[eF,eB]=(0,i.useState)(0),[eH,eO]=(0,i.useState)(!1),[eU,e_]=(0,i.useState)(0),[eq,eK]=(0,i.useState)(null),[eV,eJ]=(0,i.useState)(!1),[eY,eX]=(0,i.useState)(null),[eZ,eG]=(0,i.useState)(null),eQ=_&&eZ?.cwd===_?eZ.values:{},e0=(0,i.useRef)(null),e1=(0,i.useRef)(null),e2=(0,i.useRef)(null),e8=(0,i.useRef)(null),e4=(0,i.useRef)(null),e6=(0,i.useRef)(null),e5=(0,i.useRef)(null),e3=(0,i.useRef)(null),e7=(0,i.useRef)(!1),e9=(0,i.useRef)(0),te=(0,i.useRef)(!1),tt=(0,i.useRef)(null),tr=(0,i.useRef)([]),tn=(0,i.useRef)([]),ti=(0,i.useRef)([]),to=(0,i.useRef)(null),tl=(0,i.useRef)(null),ta=(0,i.useRef)(U),ts=(0,i.useRef)(el),td=(0,i.useRef)(ew),tc=(0,i.useRef)(0);ts.current=el,td.current=ew,(0,i.useImperativeHandle)(V,()=>({insertIfEmpty(e){let t=e0.current;(t?t.value:el).trim()||(ts.current=e,ea(e),eA(null),requestAnimationFrame(()=>{t&&(t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)}))},replaceMessage(e){var t,r,n;let i=e0.current;if(t=i?i.value:el,r=td.current.length,n=tc.current,t.trim()||0!==r||0!==n)return;let o="string"==typeof e.content?e.content:e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n"),l=rS("string"==typeof e.content?[]:e.content.flatMap(e=>{if("image"!==e.type)return[];let t=e.source?.type==="base64"?e.source.data:e.data,r=e.source?.type==="base64"?e.source.media_type:e.mimeType;if("string"!=typeof t||"string"!=typeof r)return[];let n={data:t,mimeType:r};return tB(n)?[n]:[]}));ts.current=o,td.current=l,ea(o),eA(null),eO(!1),ej(e=>(e.forEach(rC),l)),requestAnimationFrame(()=>{i&&(i.focus(),i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight,200)}px`)})},prependText(e){if(!e.trim())return;let t=e0.current,r=[e,t?t.value:el].filter(e=>e.trim()).join("\n\n");ts.current=r,ea(r),eA(null),requestAnimationFrame(()=>{t&&(t.focus(),t.setSelectionRange(r.length,r.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},rekeyDraft(e,t){if(e===t)return;if(ta.current!==e)return void tY(e,t);let r={value:ts.current,images:td.current.map(rw)},n=tY(e,t,r)??{value:"",images:[]},i=n.value===r.value&&n.images.length===r.images.length&&n.images.every((e,t)=>e.data===r.images[t]?.data&&e.mimeType===r.images[t]?.mimeType);if(ta.current=t,i)return;let o=rS(n.images);ts.current=n.value,td.current=o,ea(n.value),ej(e=>(e.forEach(rC),o)),eA(null),eO(!1)},restoreSubmission(e,t,r){if(!e.trim()&&!t?.length)return;let n=ta.current,i=r??n,o=i===n,l=!o&&i?t_(i):null,a=tJ(e,t,o?ts.current:l?.value??"",o?td.current.map(rw):l?.images??[]);if(i&&tq(i,a),!o)return;let s=t?.length?[...rS(t).slice(0,Math.max(0,10-td.current.length)),...td.current].slice(0,10):td.current;ts.current=a.value,td.current=s,ea(t=>{let r=tV(e,t);return ts.current=r,r}),eA(null),eO(!1),t?.length&&ej(e=>{let r=Math.max(0,10-e.length),n=rS(t).slice(0,r),i=n.length>0?[...n,...e]:e;return td.current=i,i}),requestAnimationFrame(()=>{let e=e0.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},insertText(e){let t=e0.current;if(!t)return void ea(t=>t+(t?" ":"")+e);let r=t.selectionStart??t.value.length,n=t.selectionEnd??t.value.length,i=t.value.slice(0,r),o=t.value.slice(n),l=i.length>0&&!i.endsWith(" ")?" ":"",a=i+l+e+o;ts.current=a,ea(a),eA(null),requestAnimationFrame(()=>{if(!t)return;let n=r+l.length+e.length;t.setSelectionRange(n,n),t.focus(),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`})},addImages(e){tu(e)}}));let tu=(0,i.useCallback)(async e=>{let t=Math.max(0,10-td.current.length-tc.current),r=e.filter(e=>e.type.startsWith("image/")&&e.size<=0xa00000).slice(0,t);if(r.length){tc.current+=r.length;try{let e=await Promise.all(r.map(async e=>{let t=await rk(e);return{data:t.data,mimeType:t.mimeType,previewUrl:URL.createObjectURL(e)}}));ej(t=>{let r=e.slice(0,Math.max(0,10-t.length));e.slice(r.length).forEach(rC);let n=[...t,...r];return td.current=n,n})}finally{tc.current-=r.length}}},[]),tp=(0,i.useCallback)(e=>{ej(t=>{let r=[...t],[n]=r.splice(e,1);return n&&rC(n),td.current=r,r})},[]),th=(0,i.useCallback)(()=>{td.current=[],ej(e=>(e.forEach(rC),[]))},[]),tg=(0,i.useCallback)(()=>{ts.current="",ea(""),eA(null),eO(!1),U&&tK(U),ta.current&&ta.current!==U&&tK(ta.current),th(),e0.current&&(e0.current.style.height="auto")},[th,U]);(0,i.useEffect)(()=>{U&&ta.current===U&&tq(U,{value:el,images:ew.map(rw)})},[ew,U,el]),(0,i.useEffect)(()=>{let e=ta.current;if(e===U)return;e&&tq(e,{value:ts.current,images:td.current.map(rw)});let t=U?t_(U):null;ta.current=U;let r=t?.value??"",n=rS(t?.images);ts.current=r,td.current=n,ea(r),eA(null),eO(!1),ej(e=>(e.forEach(rC),n))},[U]),(0,i.useEffect)(()=>{let e=e0.current;e&&(e.style.height="auto",el&&(e.style.height=`${Math.min(e.scrollHeight,200)}px`))},[el]),(0,i.useEffect)(()=>()=>{td.current.forEach(rC)},[]);let tf=(0,i.useCallback)(async e=>{if(ew.length||!e.startsWith("/")||!N)return!1;let t=await N(e);return!!t.handled&&(t.error||tg(),!0)},[ew.length,tg,N]),tx=(0,i.useCallback)(async()=>{let t=el.trim();!t&&!ew.length||(H?.(),(!l||rg(t))&&await tf(t)||l||(tg(),e(t,ew.length?ew:void 0)))},[el,ew,l,tf,e,tg,H]),tm=el.startsWith("/")&&!/\s/.test(el.slice(1))?el.slice(1).toLowerCase():null,tv=null===tm?[]:[...l?rh.filter(e=>e.availableWhileStreaming):rh,...P??[]].filter(e=>{let t=e.name.toLowerCase(),r=rb(e,ei).toLowerCase();return t.includes(tm)||r.includes(tm)}).sort((e,t)=>{let r=rv(e,tm,ei)-rv(t,tm,ei);return 0!==r?r:rm[e.source]-rm[t.source]||rs.compare(e.name,t.name)}),{commands:tb,groups:ty}=(J=0,{commands:(Y=rf.map(e=>{let t=tv.filter(t=>t.source===e),r="skill"===e?[...t.filter(e=>!ry(e,eQ)),...t.filter(e=>ry(e,eQ))]:t;return{source:e,items:r.map(e=>({command:e,index:J++}))}}).filter(e=>e.items.length>0)).flatMap(e=>e.items.map(({command:e})=>e)),groups:Y}),tk=1===tv.length?ei(tm?"chat.match":"chat.command"):ei(tm?"chat.matches":"chat.commands",{count:tv.length}),tw=!!el.trim()||ew.length>0,tj=(0,i.useCallback)((e,t)=>{if(!_)return void eA(null);let r=t??e.length;eA(tX(e.slice(0,r)))},[_]),tS=eP?.query??null,tC=i.useMemo(()=>null!==tS&&eq&&eq.cwd===_?function(e,t,r=20){let n=t.toLowerCase();if(!n)return e.slice(0,r);let i=[];for(let t of e){let e=function(e,t){let r=e.path.toLowerCase(),n=0;if(t.includes("/"))r===t?n=100:r.startsWith(t)?n=80:r.includes(t)?n=50:tG(t,r)&&(n=10);else{let e=r.lastIndexOf("/"),i=-1===e?r:r.slice(e+1);i===t?n=100:i.startsWith(t)?n=80:i.includes(t)?n=50:r.includes(t)?n=30:tG(t,r)&&(n=10)}return e.isDir&&n>0&&(n+=10),n}(t,n);e>0&&i.push({entry:t,score:e})}return i.sort((e,t)=>t.score-e.score||tZ(e.entry.path)-tZ(t.entry.path)||e.entry.path.localeCompare(t.entry.path)),i.slice(0,r).map(e=>e.entry)}(eq.entries,tS):[],[tS,eq,_]),tT=!!(tS&&eq?.truncated&&eq.cwd===_);(0,i.useEffect)(()=>{if(!tT||!_||!tS)return;let e=setTimeout(()=>{fetch(`/api/file-index?cwd=${encodeURIComponent(_)}&q=${encodeURIComponent(tS)}`).then(e=>{if(!e.ok)throw Error(`file search failed: ${e.status}`);return e.json()}).then(e=>eX({cwd:_,query:tS,matches:e.matches??[]})).catch(()=>{})},150);return()=>clearTimeout(e)},[tT,tS,_]);let tM=tT&&null!==eY&&eY.cwd===_&&eY.query===tS,tR=tM?eY.matches:tC,tI=null===eP?null:`${eP.start}:${+!!eP.quoted}:${eP.query}`;(0,i.useEffect)(()=>{if(null===tI){eN(!1),eB(0);return}eN(!0),eB(0)},[tI]);let tL=null!==eP;(0,i.useEffect)(()=>{if(!tL||!_)return;let e=to.current;e&&e.cwd===_&&Date.now()-e.fetchedAt<1e4||tl.current===_||(tl.current=_,eJ(!0),fetch(`/api/file-index?cwd=${encodeURIComponent(_)}`).then(e=>{if(!e.ok)throw Error(`file index failed: ${e.status}`);return e.json()}).then(e=>{eK({cwd:_,entries:function(e){let t=new Set;for(let r of e){let e=r.indexOf("/");for(;-1!==e;)t.add(r.slice(0,e)),e=r.indexOf("/",e+1)}let r=[];for(let e of t)r.push({path:e,isDir:!0});for(let t of e)t&&r.push({path:t,isDir:!1});return r.sort((e,t)=>tZ(e.path)-tZ(t.path)||e.path.localeCompare(t.path)),r}(e.files??[]),truncated:!!e.truncated}),to.current={cwd:_,fetchedAt:Date.now()}}).catch(()=>{to.current=null}).finally(()=>{tl.current=null,eJ(!1)}))},[tL,_]);let tE=(0,i.useCallback)(e=>{if(!eP)return;let t=e0.current,r=t?.selectionStart??el.length,n=el.slice(0,eP.start),i=el.slice(r);eP.quoted&&i.startsWith('"')&&(i=i.slice(1));let o=function(e,t,r=!1){let n=t?`${e}/`:e,i=r||n.includes(" ");if(t){let e=i?`@"${n}"`:`@${n}`;return{text:e,cursorOffset:i?e.length-1:e.length}}let o=i?`@"${n}" `:`@${n} `;return{text:o,cursorOffset:o.length}}(e.path,e.isDir,eP.quoted),l=n+o.text+i,a=n.length+o.cursorOffset;ea(l),eA(tX(l.slice(0,a))),requestAnimationFrame(()=>{let e=e0.current;e&&(e.focus(),e.setSelectionRange(a,a),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[eP,el]);(0,i.useEffect)(()=>{eF>=tR.length&&eB(Math.max(0,tR.length-1))},[tR.length,eF]),(0,i.useEffect)(()=>{tn.current.length=tR.length},[tR.length]),(0,i.useEffect)(()=>{eD&&tn.current[eF]?.scrollIntoView({block:"nearest",inline:"nearest"})},[eF,eD]),(0,i.useEffect)(()=>{eU>=W.length&&e_(Math.max(0,W.length-1))},[W.length,eU]),(0,i.useEffect)(()=>{ti.current.length=W.length},[W.length]),(0,i.useEffect)(()=>{eH&&ti.current[eU]?.scrollIntoView({block:"nearest",inline:"nearest"})},[eU,eH]);let tW=(0,i.useCallback)(e=>{ea(e),eO(!1),e_(0),eA(null),requestAnimationFrame(()=>{let t=e0.current;t&&(t.focus(),t.setSelectionRange(e.length,e.length),t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,200)}px`)})},[]),tz=(0,i.useCallback)(e=>{let t=`/${e.name} `;ea(t),eL(!1),eW(0),requestAnimationFrame(()=>{let e=e0.current;e&&(e.focus(),e.setSelectionRange(t.length,t.length),e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)})},[]),t$=(0,i.useCallback)(e=>{let t=el.trim();if(t||ew.length){if(H?.(),!ew.length&&N&&rg(t))return void tf(t);if(t.startsWith("/")&&O){tg(),O(t,"steer"===e?"steer":"followUp",ew.length?ew:void 0);return}tg(),"steer"===e&&r?r(t,ew.length?ew:void 0):"followup"===e&&o&&o(t,ew.length?ew:void 0)}},[el,ew,N,O,r,o,tg,H,tf]),tP=(0,i.useCallback)(e=>{let t=tb.length-1;if(t<0)return 0;if("left"===e)return Math.max(0,eE-1);if("right"===e)return Math.min(t,eE+1);let r=tr.current[eE];if(!r)return"down"===e?Math.min(t,eE+1):Math.max(0,eE-1);let n=r.getBoundingClientRect(),i=n.left+n.width/2,o=n.top+n.height/2,l=-1,a=1/0;for(let r=0;r<=t;r+=1){if(r===eE)continue;let t=tr.current[r];if(!t)continue;let n=t.getBoundingClientRect(),s=n.top+n.height/2-o;if("down"===e?s<=4:s>=-4)continue;let d=1e3*Math.abs(s)+Math.abs(n.left+n.width/2-i);d<a&&(l=r,a=d)}return l>=0?l:"down"===e?Math.min(t,eE+1):Math.max(0,eE-1)},[tb.length,eE]),tA=(0,i.useCallback)(e=>{let n=e.nativeEvent,i="Enter"===e.key&&!e.shiftKey&&(!eo||e.ctrlKey||e.metaKey),a=Date.now()-e9.current<100,s=e7.current||n.isComposing||229===n.keyCode;if(i&&(s||a)){a&&e.preventDefault();return}if(eH&&!s){if("ArrowDown"===e.key){e.preventDefault(),e_(e=>Math.min(Math.max(0,W.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),e_(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),eO(!1);return}if(("Tab"===e.key||i)&&W[eU]){e.preventDefault(),tW(W[eU]);return}}if(eI&&null!==tm){if("ArrowDown"===e.key){e.preventDefault(),eW(tP("down"));return}if("ArrowUp"===e.key){e.preventDefault(),eW(tP("up"));return}if("ArrowRight"===e.key){e.preventDefault(),eW(tP("right"));return}if("ArrowLeft"===e.key){e.preventDefault(),eW(tP("left"));return}if("Escape"===e.key){e.preventDefault(),eL(!1);return}let t=tb[eE];if("Tab"===e.key&&t){e.preventDefault(),tz(t);return}if(i&&t){var d;(e.preventDefault(),l&&("builtin"!==t.source||!0!==t.availableWhileStreaming)||(d=t.name,el.trim()!==`/${d}`))?tz(t):(eL(!1),tx());return}}if(eD&&null!==eP&&!s){if("ArrowDown"===e.key){e.preventDefault(),eB(e=>Math.min(Math.max(0,tR.length-1),e+1));return}if("ArrowUp"===e.key){e.preventDefault(),eB(e=>Math.max(0,e-1));return}if("Escape"===e.key){e.preventDefault(),eN(!1);return}if(("Tab"===e.key||i)&&tR[eF]){e.preventDefault(),tE(tR[eF]);return}}if("ArrowUp"===e.key&&!s&&!l&&W.length>0&&0===el.trim().length){e.preventDefault(),eL(!1),eN(!1),e_(W.length-1),eO(!0);return}if("Escape"===e.key&&!s&&l&&t){e.preventDefault(),t();return}i&&(e.preventDefault(),l&&(r||o)?t$(r?"steer":"followup"):tx())},[eo,l,r,o,t,eI,tm,tb,eE,tz,t$,tx,tP,eD,eP,tR,eF,tE,eH,W,eU,tW,el]),tD=(0,i.useCallback)(()=>{let e=e0.current;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]),tN=(0,i.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>e.type.startsWith("image/"));if(t.length>0){e.preventDefault(),tu(t.map(e=>e.getAsFile()).filter(e=>null!==e));return}let r=w(e.clipboardData,{fallbackToFileName:!0});if(r.length>0){e.preventDefault();let t=j(r),n=e0.current,i=n?.selectionStart??el.length,o=n?.selectionEnd??el.length;ea(el.slice(0,i)+t+el.slice(o)),requestAnimationFrame(()=>{if(n){let e=i+t.length;n.selectionStart=e,n.selectionEnd=e,tD()}})}},[tu,el,tD]);(0,i.useEffect)(()=>{if(null===tm){eL(!1),eW(0),te.current=!1;return}eL(!0),eW(0),!te.current&&D&&(te.current=!0,Promise.resolve(D()).catch(()=>{te.current=!1}))},[tm,D]),(0,i.useEffect)(()=>{if(!eI||!_)return;let e=!1;return eG({cwd:_,values:{}}),fetch(`/api/skills?cwd=${encodeURIComponent(_)}`).then(e=>{if(!e.ok)throw Error(`skills fetch failed: ${e.status}`);return e.json()}).then(t=>{if(e)return;let r={};for(let e of t.skills??[])r[e.name]=e.disableModelInvocation;eG({cwd:_,values:r})}).catch(()=>{e||eG({cwd:_,values:{}})}),()=>{e=!0}},[eI,_]),(0,i.useEffect)(()=>{eE>=tb.length&&eW(Math.max(0,tb.length-1))},[tb.length,eE]),(0,i.useEffect)(()=>{tr.current.length=tb.length},[tb.length]),(0,i.useEffect)(()=>{eI&&tr.current[eE]?.scrollIntoView({block:"nearest",inline:"nearest"})},[eE,eI]),(0,i.useLayoutEffect)(()=>{if(!eI||null===tm)return void e$(null);let e=tt.current;if(!e)return;let t=null,r=()=>{t=null;let r=function(e,t,r=8){return Math.max(0,Math.floor(e-t-r))}(e.getBoundingClientRect().bottom,function(e){let t=window.visualViewport?.offsetTop??0;for(let r=e.parentElement;r;r=r.parentElement){let e=window.getComputedStyle(r).overflowY;("auto"===e||"scroll"===e||"hidden"===e||"clip"===e)&&(t=Math.max(t,r.getBoundingClientRect().top+r.clientTop))}return t}(e));e$(e=>e===r?e:r)},n=()=>{null!==t&&cancelAnimationFrame(t),t=requestAnimationFrame(r)};r();let i="u">typeof ResizeObserver&&e.parentElement?new ResizeObserver(n):null;e.parentElement&&i?.observe(e.parentElement);let o=window.visualViewport;return o?.addEventListener("resize",n),o?.addEventListener("scroll",n),window.addEventListener("resize",n),window.addEventListener("scroll",n,!0),()=>{i?.disconnect(),o?.removeEventListener("resize",n),o?.removeEventListener("scroll",n),window.removeEventListener("resize",n),window.removeEventListener("scroll",n,!0),null!==t&&cancelAnimationFrame(t)}},[eI,tm]);let tF=c&&c.length>0?c.map(e=>({provider:e.provider,modelId:e.id,name:e.name})).sort(rd):Object.entries(d??{}).map(([e,t])=>({provider:a?.provider??"unknown",modelId:e,name:t})).sort(rd),tH=(X=eg.trim().toLocaleLowerCase())?tF.filter(e=>`${e.name} ${e.modelId}`.toLocaleLowerCase().includes(X)):tF,tO=tF.length>8,tU=[];for(let e of tH){let t=tU.find(t=>t.provider===e.provider);t?t.options.push(e):tU.push({provider:e.provider,options:[e]})}let tQ=a?tF.find(e=>e.modelId===a.modelId&&e.provider===a.provider)?.name??a.modelId:null,t0=y?Math.max(0,y.tokensBefore-y.estimatedTokensAfter):0,t1=y?`${y.reason&&"manual"!==y.reason?`${y.reason[0].toUpperCase()}${y.reason.slice(1)} `:ei("chat.compacted")} ${rp(y.tokensBefore)} -> ${rp(y.estimatedTokensAfter)} tokens (${ei("chat.tokensSaved",{saved:rp(t0)})})`:null,t2="auto"!==(Z=C??"auto")&&R?R[Z]??Z:Z,t8=Object.entries(ra).find(([,e])=>e===(k??"default"))?.[0]??"default";return(0,i.useEffect)(()=>{let e=e=>{e1.current&&!e1.current.contains(e.target)&&e2.current&&!e2.current.contains(e.target)&&(eu(!1),ef("")),e8.current&&!e8.current.contains(e.target)&&em(!1),e4.current&&!e4.current.contains(e.target)&&eb(!1),e6.current&&!e6.current.contains(e.target)&&ek(!1),!e5.current||e5.current.contains(e.target)||e0.current?.contains(e.target)||eO(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,i.useEffect)(()=>{eo||ek(!1)},[eo]),(0,n.jsxs)("div",{style:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:eo?16:52},children:[(0,n.jsx)("input",{ref:e3,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:e=>{tu(Array.from(e.target.files??[])),e.target.value=""}}),(0,n.jsxs)("div",{style:{maxWidth:820,margin:"0 auto"},children:[(0,n.jsx)(rR,{error:u}),(0,n.jsx)(rI,{warnings:p}),(E?.steering.length??0)+(E?.followUp.length??0)>0&&(0,n.jsxs)("div",{style:{marginBottom:8,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:"5px 0"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"2px 8px 4px 10px"},children:[(0,n.jsx)("span",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:.4},children:ei("chat.queued",{count:(E?.steering.length??0)+(E?.followUp.length??0)})}),$&&(0,n.jsxs)("button",{onClick:$,title:ei("chat.recallTitle"),style:{display:"flex",alignItems:"center",gap:6,padding:"4px 12px",fontSize:12,color:"var(--text)",background:"transparent",border:"1px solid var(--border)",borderRadius:7,cursor:"pointer",transition:"background 0.12s, border-color 0.12s",whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.borderColor="color-mix(in srgb, var(--accent) 45%, var(--border))"},onMouseLeave:e=>{e.currentTarget.style.background="transparent",e.currentTarget.style.borderColor="var(--border)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"9 14 4 9 9 4"}),(0,n.jsx)("path",{d:"M20 20v-7a4 4 0 0 0-4-4H4"})]}),ei("chat.recall")]})]}),E?.steering.map((e,t)=>(0,n.jsx)(rT,{kind:"steer",text:e},`steer-${t}`)),E?.followUp.map((e,t)=>(0,n.jsx)(rT,{kind:"follow-up",text:e},`followup-${t}`))]}),I&&(0,n.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"color-mix(in srgb, var(--bg-panel) 92%, #f59e0b 8%)",borderLeft:"3px solid #f59e0b",borderRadius:4,fontSize:12,color:"var(--text)",display:"flex",alignItems:"center",gap:6},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#d97706",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"})]}),ei("chat.retrying",{attempt:I.attempt,max:I.maxAttempts}),I.errorMessage&&(0,n.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",I.errorMessage]})]}),t1&&(0,n.jsxs)("div",{style:{marginBottom:8,padding:"5px 10px",background:"color-mix(in srgb, var(--bg-panel) 92%, #10b981 8%)",borderLeft:"3px solid #10b981",borderRadius:4,fontSize:12,color:"var(--text)",display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"#059669",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),t1]}),v&&!es&&(0,n.jsxs)("div",{role:"alert",style:{position:"relative",marginBottom:8,padding:"8px 30px 8px 12px",borderRadius:10,border:"1px solid color-mix(in srgb, #ef4444 45%, transparent)",background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.5,boxShadow:"0 2px 12px -4px rgba(15,23,42,0.16)",animation:"notice-shelf-in 0.18s ease-out both"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:6,height:6,borderRadius:"50%",marginTop:5,background:"#ef4444"}}),(0,n.jsx)("div",{style:{minWidth:0,flex:1,whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"anywhere"},children:v})]}),(0,n.jsx)("button",{type:"button","aria-label":"Dismiss",onClick:()=>ed(!0),style:{position:"absolute",top:6,right:6,display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",borderRadius:5},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:(0,n.jsx)("path",{d:"M1 1l8 8M9 1l-8 8"})})})]}),m&&(0,n.jsxs)("div",{className:"compaction-status",role:"status",style:{marginBottom:8,display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderRadius:10,border:"1px solid color-mix(in srgb, var(--accent) 42%, transparent)",background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",color:"var(--text)",fontSize:12.5,lineHeight:1.4,boxShadow:"0 2px 12px -4px rgba(15,23,42,0.16)",animation:"compaction-breathe 1.8s ease-in-out infinite"},children:[(0,n.jsx)("span",{className:"compaction-status-dot",style:{flexShrink:0,width:8,height:8,borderRadius:"50%",background:"var(--accent)",animation:"compaction-dot-breathe 1.4s ease-in-out infinite"}}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:ei("chat.compacting")}),(0,n.jsx)("button",{type:"button",onClick:x,style:{flexShrink:0,background:"transparent",border:"none",borderRadius:6,padding:"3px 8px",color:"var(--accent)",fontSize:12,fontWeight:600,cursor:"pointer",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:ei("chat.stopCompaction")})]}),(0,n.jsxs)("div",{style:{borderRadius:eo?14:16,background:"var(--frame-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",border:`1px solid ${eM?"color-mix(in srgb, var(--accent) 45%, transparent)":l&&(r||o)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 90%, transparent)"}`,padding:"8px 8px 8px",boxShadow:eS?"0 0 14px 1px color-mix(in srgb, var(--border) 50%, transparent), 0 1px 2px rgba(15,23,42,0.05), 0 8px 24px -8px rgba(15,23,42,0.24)":"0 1px 2px rgba(15,23,42,0.05), 0 2px 5px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.16)",transition:"border-color 0.15s, box-shadow 0.15s"},children:[(0,n.jsx)(ri,{}),ew.length>0&&(0,n.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",padding:"4px 4px 0"},children:ew.map((e,t)=>(0,n.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,n.jsx)("img",{src:e.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:8,border:"1px solid var(--border)",display:"block"}}),(0,n.jsx)("button",{onClick:()=>tp(t),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,n.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},t))}),(0,n.jsxs)("div",{style:{position:"relative",minWidth:0},children:[eH&&W.length>0&&(0,n.jsxs)("div",{ref:e5,style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(44vh, 360px)"},children:[(0,n.jsx)("div",{title:"Input history",style:{height:30,padding:"0 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",color:"var(--text-dim)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7"}),(0,n.jsx)("path",{d:"M3 4v5h5"}),(0,n.jsx)("path",{d:"M12 7v5l3 2"})]})}),(0,n.jsx)("div",{style:{maxHeight:"calc(min(44vh, 360px) - 31px)",overflowY:"auto",padding:4},children:W.map((e,t)=>{let r=t===eU;return(0,n.jsxs)("button",{ref:e=>{ti.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),tW(e)},onMouseEnter:()=>e_(t),style:{width:"100%",display:"flex",alignItems:"flex-start",gap:8,padding:"7px 8px",border:"none",borderRadius:6,background:r?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,lineHeight:1.45},children:[(0,n.jsx)("span",{style:{flexShrink:0,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",paddingTop:1},children:t+1}),(0,n.jsx)("span",{style:{minWidth:0,display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflow:"hidden",overflowWrap:"anywhere"},children:e})]},`${t}:${e}`)})})]}),eI&&null!==tm&&(0,n.jsxs)("div",{ref:tt,style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",boxSizing:"border-box",display:"flex",flexDirection:"column",maxHeight:null===ez?"min(72.8vh, 598px)":`min(72.8vh, 598px, ${ez}px)`},children:[(0,n.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("span",{children:A?ei("chat.loadingCommands"):ei("chat.slashCommands",{label:tk})}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:ei("chat.tabEnter")})]}),(0,n.jsx)("div",{style:{flex:"1 1 auto",minHeight:0,overflowY:"auto",padding:10},children:A||0!==tv.length?ty.map(e=>(0,n.jsxs)("section",{style:{marginBottom:12},children:[(0,n.jsxs)("div",{style:{position:"sticky",top:-10,zIndex:1,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,padding:"4px 0 6px",background:"var(--bg)",color:"var(--text-dim)",fontSize:10,fontWeight:600,textTransform:"uppercase"},children:[(0,n.jsx)("span",{children:ei(rx[e.source])}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:500},children:e.items.length})]}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:8},children:e.items.map(({command:e,index:t})=>{let r=t===eE,i=ry(e,eQ);return(0,n.jsxs)("button",{ref:e=>{tr.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),tz(e)},onMouseEnter:()=>eW(t),style:{width:"100%",minWidth:0,minHeight:58,display:"flex",flexDirection:"column",gap:4,justifyContent:"center",padding:"9px 10px",border:`1px solid ${r?"var(--accent)":"var(--border)"}`,borderRadius:7,background:r?"var(--bg-selected)":"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",boxShadow:r?"0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent)":"none"},children:[(0,n.jsxs)("span",{style:{fontSize:13,fontFamily:"var(--font-mono)",overflowWrap:"anywhere",wordBreak:"break-word",color:i?"var(--text-dim)":void 0},children:["/",e.name,i&&(0,n.jsx)("span",{style:{marginLeft:6,padding:"0 4px",border:"1px solid var(--border)",borderRadius:3,fontSize:9,color:"var(--text-dim)",whiteSpace:"nowrap"},children:ei("chat.dormant")})]}),e.description&&(0,n.jsx)("span",{style:{display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflow:"hidden",fontSize:11,lineHeight:1.35,color:"var(--text-dim)"},children:rb(e,ei)})]},`${e.source}:${e.name}`)})})]},e.source)):(0,n.jsx)("div",{style:{padding:"2px 2px 4px",fontSize:12,color:"var(--text-dim)"},children:ei("chat.noCommands")})})]}),eD&&null!==eP&&(G=eV&&(!eq||eq.cwd!==_),Q=1===tR.length?ei("chat.match"):ei("chat.matches",{count:tR.length}),ee=eq?.truncated&&!tM?eP.query?ei("chat.searchingAll"):ei("chat.indexTruncated"):"",(0,n.jsxs)("div",{style:{position:"absolute",left:0,right:0,bottom:"calc(100% + 8px)",zIndex:120,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -6px 20px rgba(0,0,0,0.12)",overflow:"hidden",maxHeight:"min(48vh, 400px)"},children:[(0,n.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,fontSize:11,color:"var(--text-dim)"},children:[(0,n.jsx)("span",{children:G?ei("chat.loadingFiles"):ei("chat.files",{label:Q,hint:ee})}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},children:ei("chat.tabEnter")})]}),(0,n.jsx)("div",{style:{maxHeight:"calc(min(48vh, 400px) - 34px)",overflowY:"auto",padding:4},children:G||0!==tR.length?tR.map((e,t)=>{let r=t===eF,i=e.path.split("/").pop()??e.path,o=e.path.slice(0,e.path.length-i.length);return(0,n.jsxs)("button",{ref:e=>{tn.current[t]=e},type:"button",onMouseDown:t=>{t.preventDefault(),tE(e)},onMouseEnter:()=>eB(t),style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"6px 8px",border:"none",borderRadius:6,background:r?"var(--bg-selected)":"none",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12.5,fontFamily:"var(--font-mono)"},children:[(0,n.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:e.isDir?(0,n.jsx)(L,{size:14}):z(i,14)}),(0,n.jsxs)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[o&&(0,n.jsx)("span",{style:{color:"var(--text-dim)"},children:o}),i,e.isDir&&(0,n.jsx)("span",{style:{color:"var(--text-dim)"},children:"/"})]})]},`${e.isDir?"d":"f"}:${e.path}`)}):(0,n.jsx)("div",{style:{padding:"6px 8px",fontSize:12,color:"var(--text-dim)"},children:tT&&!tM?ei("chat.searching"):ei("chat.noMatchingFiles")})})]})),(0,n.jsxs)("div",{style:{minWidth:0,display:"flex",gap:8,alignItems:"center",padding:"8px 4px"},children:[(0,n.jsx)("textarea",{ref:e0,value:el,onChange:e=>{ts.current=e.target.value,ea(e.target.value),eO(!1),tj(e.target.value,e.target.selectionStart)},onSelect:e=>{let t=e.currentTarget;tj(t.value,t.selectionStart)},onKeyDown:tA,onCompositionStart:()=>{e7.current=!0},onCompositionEnd:e=>{e7.current=!1,e9.current=Date.now();let t=e.currentTarget;tj(t.value,t.selectionStart)},onInput:tD,onFocus:()=>eC(!0),onBlur:()=>eC(!1),onPaste:tN,placeholder:l&&(r||o)?ei("chat.steerPlaceholder"):l?ei("chat.agentPlaceholder"):ei("chat.messagePlaceholder"),rows:1,style:{flex:1,minWidth:0,width:"100%",background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto"}}),l?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,alignSelf:"flex-end"},children:[r&&(0,n.jsxs)("button",{onClick:()=>t$("steer"),disabled:!tw,title:"Interrupt the current run and inject this message now",onMouseEnter:e=>{e.currentTarget.disabled||(e.currentTarget.style.background="rgba(120,120,128,0.10)")},onMouseLeave:e=>{e.currentTarget.disabled||(e.currentTarget.style.background="transparent")},style:{display:"flex",alignItems:"center",gap:5,padding:"6px 10px",background:"transparent",borderRadius:8,color:tw?"color-mix(in srgb, var(--text) 20%, var(--text-muted))":"var(--text-dim)",cursor:tw?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M7 3 L11 7 L7 11"}),(0,n.jsx)("line",{x1:"3",y1:"7",x2:"11",y2:"7"})]}),ei("chat.steer")]}),o&&(0,n.jsxs)("button",{onClick:()=>t$("followup"),disabled:!tw,title:"Queue this message after the agent finishes",onMouseEnter:e=>{e.currentTarget.disabled||(e.currentTarget.style.background="rgba(120,120,128,0.10)")},onMouseLeave:e=>{e.currentTarget.disabled||(e.currentTarget.style.background="transparent")},style:{display:"flex",alignItems:"center",gap:5,padding:"6px 10px",background:"transparent",borderRadius:8,color:tw?"color-mix(in srgb, var(--text) 20%, var(--text-muted))":"var(--text-dim)",cursor:tw?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"7",y1:"3",x2:"7",y2:"8"}),(0,n.jsx)("polyline",{points:"4.5 5.5 7 3 9.5 5.5"}),(0,n.jsx)("line",{x1:"4",y1:"11",x2:"10",y2:"11"})]}),ei("chat.followUp")]})]}):(0,n.jsxs)("button",{onClick:tx,disabled:!el.trim()&&!ew.length,style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:6,padding:"6px 10px",borderRadius:8,background:"transparent",color:el.trim()||ew.length?"color-mix(in srgb, var(--text) 20%, var(--text-muted))":"var(--text-dim)",cursor:el.trim()||ew.length?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.disabled||(e.currentTarget.style.background="rgba(120,120,128,0.10)")},onMouseLeave:e=>{e.currentTarget.disabled||(e.currentTarget.style.background="transparent")},onMouseDown:e=>{e.currentTarget.disabled||(e.currentTarget.style.transform="translateY(1px)")},onMouseUp:e=>{e.currentTarget.style.transform="none"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,n.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),ei("chat.send")]})]})]}),eM&&(0,n.jsxs)("div",{className:"text-xs",style:{color:eR?"var(--text-muted)":"var(--accent)",padding:"2px 8px 4px"},children:[ei("chat.shell")," \xb7 ",eR?ei("chat.outputLocal"):ei("chat.outputModel")]}),(0,n.jsxs)("div",{style:{display:eo?"grid":"flex",gridTemplateColumns:eo?"minmax(0, 1fr) auto":void 0,alignItems:"center",gap:6,padding:"6px 4px 4px",marginTop:4,borderRadius:10,background:"color-mix(in srgb, var(--bg-panel) 45%, transparent)"},children:[(0,n.jsxs)("div",{style:{flex:eo?"1 1 auto":"0 0 auto",minWidth:0,display:"flex",alignItems:"center",gap:2},children:[(0,n.jsx)("button",{onClick:()=>e3.current?.click(),title:ei("chat.attachImage"),style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:ew.length?"var(--accent)":"var(--text-muted)",cursor:"pointer",opacity:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color=ew.length?"var(--accent)":"var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=ew.length?"var(--accent)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,n.jsx)("polyline",{points:"21 15 16 10 5 21"})]})}),(tF.length>0||tQ||u)&&h&&(0,n.jsxs)("div",{ref:e1,style:{position:"relative",flex:eo?"1 1 auto":void 0,minWidth:0},children:[(0,n.jsxs)("button",{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();eh({top:t.top,left:t.left,width:t.width}),eu(e=>(e&&ef(""),!e))},disabled:l||g,"aria-busy":g||void 0,style:{display:"flex",alignItems:"center",gap:6,justifyContent:eo?"flex-start":void 0,padding:eo?"8px 10px":"8px 12px",height:32,width:eo?"100%":void 0,maxWidth:eo?"100%":300,overflow:"hidden",background:ec?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l||g?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||g||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ec?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},title:g?"Switching model":tF.length>0?"Change model":"No available models",children:[g?(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",style:{animation:"spin 0.8s linear infinite",flexShrink:0},"aria-hidden":"true",children:(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-2.64-6.36"})}):(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsxs)("span",{style:{display:"flex",alignItems:"baseline",minWidth:0,overflow:"hidden",whiteSpace:"nowrap"},children:[(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:tQ??(tF.length>0?"Select model":"No models")}),a?.provider&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,margin:"0 4px",color:"var(--text-dim)"},children:"\xb7"}),(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:a.provider})]})]})]}),ec&&ep&&(et=window.visualViewport?.height??window.innerHeight,er=Math.max(120,Math.min(ep.top-8,.6*et)),en=eo?{left:0,right:0,width:"100%"}:{left:0,width:"max-content",minWidth:ep.width},(0,n.jsxs)("div",{ref:e2,style:{position:"absolute",bottom:"calc(100% + 6px)",...en,zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:er,display:"flex",flexDirection:"column"},children:[tO&&(0,n.jsx)("div",{style:{padding:"6px 8px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,n.jsx)("input",{value:eg,onChange:e=>ef(e.target.value),onKeyDown:e=>{"Escape"===e.key&&(ef(""),eu(!1))},placeholder:ei("chat.filterModels"),"aria-label":ei("chat.filterModels"),autoFocus:!0,autoComplete:"off",spellCheck:!1,style:{width:"100%",minWidth:220*!eo,fontSize:11,fontFamily:"var(--font-mono)",padding:"5px 8px",border:"1px solid var(--border)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",boxSizing:"border-box"}})}),(0,n.jsx)("div",{style:{minHeight:0,overflowY:"auto"},children:0===tU.length?(0,n.jsx)("div",{style:{padding:"8px 12px",color:"var(--text-dim)",fontSize:12,whiteSpace:"nowrap"},children:eg.trim()?ei("chat.noMatchingModels"):"No available models"}):tU.map((e,t)=>(0,n.jsxs)("div",{children:[tU.length>1&&(0,n.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:t>0?"1px solid var(--border)":"none"},children:e.provider}),e.options.map(e=>{let t=e.modelId===a?.modelId&&e.provider===a?.provider;return(0,n.jsxs)("button",{onClick:()=>{eu(!1),ef(""),(!t||s)&&h(e.provider,e.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),e.name]},`${e.provider}:${e.modelId}`)})]},e.provider))})]}))]})]}),!eo&&(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsxs)("div",{ref:e6,style:{flex:"0 0 auto",display:"flex",alignItems:"center",justifyContent:"flex-end",position:"relative",marginLeft:eo?0:"auto"},children:[eo&&(0,n.jsx)("button",{type:"button",title:ey?void 0:ei("chat.moreControls"),"aria-label":ei("chat.moreControls"),"aria-expanded":ey,"aria-hidden":ey||void 0,tabIndex:ey?-1:void 0,onClick:()=>{eu(!1),ef(""),ek(!0)},style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:32,padding:"8px 10px",background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:ey?"default":"pointer",fontSize:12,fontWeight:500,visibility:ey?"hidden":"visible",pointerEvents:ey?"none":"auto",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{ey||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{ey||(e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)")},children:ei("chat.moreControls")}),(0,n.jsxs)("div",{style:{display:eo?ey?"flex":"none":"flex",alignItems:"center",gap:eo?1:2,...eo?{position:"absolute",right:0,bottom:0,zIndex:60,padding:1,width:"max-content",maxWidth:"calc(100vw - 32px)",flexWrap:"nowrap",justifyContent:"flex-end",border:"1px solid color-mix(in srgb, var(--border) 72%, transparent)",borderRadius:10,background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",boxShadow:"0 8px 24px rgba(0,0,0,0.14)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))"}:null},children:[!l&&T&&(0,n.jsxs)("div",{ref:e4,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&eb(e=>!e),disabled:l,title:ei("chat.changeReasoning",{level:t2}),"aria-label":ei("chat.changeReasoningLabel"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:eo?"0 6px":"8px 12px",width:eo?"auto":void 0,height:32,background:ev?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ev?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9.5 2A5.5 5.5 0 0 0 4 7.5c0 1.7.78 3.21 2 4.21V14a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-2.29c1.22-1 2-2.51 2-4.21A5.5 5.5 0 0 0 9.5 2z"}),(0,n.jsx)("line",{x1:"7",y1:"18",x2:"12",y2:"18"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"11",y2:"21"})]}),(!eo||ey)&&(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:t2})]}),ev&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",...eo?{left:0}:{right:0},zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:180},children:rc.filter(e=>!M||"auto"===e||M.includes(e)).map(e=>{let t=(C??"auto")===e,r=ei(ru[e]),i="auto"!==e&&R?R[e]:void 0,o=null!=i&&i!==e?i:e,l=null!=i&&i!==e;return(0,n.jsxs)("button",{onClick:()=>{eb(!1),t||T(e)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:t?"var(--bg-selected)":"none",border:"none",color:t?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:t?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[t?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsxs)("span",{style:{flex:1},children:[o,l&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",e,")"]})]}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:r})]},e)})})]}),!l&&S&&(0,n.jsxs)("div",{ref:e8,style:{position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>!l&&em(e=>!e),disabled:l,title:ei("chat.changeToolPreset")+`: ${t8}`,"aria-label":ei("chat.changeToolPreset"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:eo?"0 6px":"8px 12px",width:eo?"auto":void 0,height:32,background:ex?"var(--bg-hover)":"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:l?"not-allowed":"pointer",fontSize:12,opacity:l?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{l||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background=ex?"var(--bg-hover)":"none",e.currentTarget.style.color="var(--text-muted)"},children:[(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(!eo||ey)&&(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:t8})]}),ex&&(0,n.jsx)("div",{style:{position:"absolute",bottom:"calc(100% + 6px)",right:eo?void 0:0,left:eo?0:void 0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",minWidth:120},children:rl.map(e=>{let t,r=ra[e],i=(k??"default")===r;return t="off"===e?ei("chat.noTools"):"read-only"===e?ei("chat.readOnlyTools",{count:4}):"default"===e?ei("chat.builtInTools",{count:4}):ei("chat.allBuiltInTools"),(0,n.jsxs)("button",{onClick:()=>{em(!1),i||S(r)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:i?"var(--bg-selected)":"none",border:"none",color:i?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:i?600:400,whiteSpace:"nowrap"},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none")},children:[i?(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,n.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,n.jsx)("span",{style:{width:10,flexShrink:0}}),(0,n.jsx)("span",{style:{flex:1},children:e}),(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:t})]},e)})})]}),!l&&f&&(0,n.jsx)("div",{children:(0,n.jsxs)("button",{onClick:f,disabled:m,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:eo?"0 6px":"8px 12px",width:eo?"auto":void 0,height:32,background:"none",border:"none",borderRadius:9,color:m?"var(--text-dim)":"var(--text-muted)",cursor:m?"not-allowed":"pointer",fontSize:12,opacity:m?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{m||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},title:ei("chat.compactContext"),"aria-label":ei("chat.compactContext"),children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,n.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,n.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]}),(!eo||ey)&&(0,n.jsx)("span",{style:{whiteSpace:"nowrap"},children:ei("chat.compact")})]})}),l&&(0,n.jsxs)("button",{onClick:t,title:ei("chat.stopAgent"),style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:32,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:9,color:"#ef4444",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,n.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),ei("chat.stop")]}),void 0!==B&&(0,n.jsx)("button",{onClick:B,title:F?ei("chat.disableSound"):ei("chat.enableSound"),"aria-label":F?ei("chat.disableSound"):ei("chat.enableSound"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:32,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:F?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:F?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)",e.currentTarget.style.opacity="1"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color=F?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.opacity=F?"1":"0.55"},children:F?(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,n.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,n.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,n.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})}),eo&&ey&&(0,n.jsx)("button",{type:"button",title:ei("chat.collapseControls"),"aria-label":ei("chat.collapseControls"),"aria-expanded":!0,onClick:()=>{em(!1),eb(!1),ek(!1)},style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:32,padding:0,marginLeft:0,background:"var(--bg-hover)",border:"none",borderLeft:"1px solid color-mix(in srgb, var(--border) 72%, transparent)",borderRadius:"0 9px 9px 0",color:"var(--text)",cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-selected)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-hover)"},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),!q&&K&&(0,n.jsx)("button",{type:"button",onClick:()=>K(),title:ei("chat.scrollToLatest"),"aria-label":ei("chat.scrollToLatest"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,flexShrink:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, opacity 0.12s",animation:"back-to-latest-in 0.18s ease-out both"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("polyline",{points:"7 13 12 18 17 13"}),(0,n.jsx)("polyline",{points:"7 6 12 11 17 6"})]})})]})]})]})]})]})]})});var rE=r(88576),rW=r.n(rE);function rz({level:e,children:t,headingIndex:r,onClick:i}){return(0,n.jsx)("button",{type:"button",className:rW().heading,"data-level":e,"data-preview-heading-index":r??void 0,disabled:null===r||!i,onClick:e=>{e.stopPropagation(),null!==r&&i?.(r)},children:t})}let r$=[...eq??[],function(){return e=>{if(!Array.isArray(e.children))return;let t=e.children.filter(e=>"heading"===e.type&&"number"==typeof e.depth&&e.depth<=3);if(t.length>0){t.forEach((e,t)=>{e.data={...e.data,hProperties:{...e.data?.hProperties,"data-preview-heading-index":t}}}),e.children=t;return}let r=e.children.find(e=>"paragraph"===e.type);e.children=r?[r]:[]}}],rP=[[eW.A,{throwOnError:!1,strict:!1}]];function rA(e){let t=e?.properties,r=t?.dataPreviewHeadingIndex??t?.["data-preview-heading-index"];return"number"==typeof r?r:"string"==typeof r&&/^\d+$/.test(r)?Number(r):null}let rD=(0,i.memo)(function({markdown:e,onHeadingClick:t,onAnswerClick:r}){let o=(0,i.useMemo)(()=>eB(e),[e]);return e?(0,n.jsx)("div",{className:rW().outline,children:(0,n.jsx)(eE.oz,{remarkPlugins:r$,rehypePlugins:rP,components:{h1:({children:e,node:r})=>(0,n.jsx)(rz,{level:1,headingIndex:rA(r),onClick:t,children:e}),h2:({children:e,node:r})=>(0,n.jsx)(rz,{level:2,headingIndex:rA(r),onClick:t,children:e}),h3:({children:e,node:r})=>(0,n.jsx)(rz,{level:3,headingIndex:rA(r),onClick:t,children:e}),h4:()=>null,h5:()=>null,h6:()=>null,p:({children:e})=>(0,n.jsx)("button",{type:"button",className:rW().paragraph,onClick:r,children:e}),blockquote:()=>null,ul:()=>null,ol:()=>null,pre:()=>null,table:()=>null,hr:()=>null,a:({children:e})=>(0,n.jsx)(n.Fragment,{children:e}),code:({children:e})=>(0,n.jsx)(n.Fragment,{children:e})},children:o})}):null});function rN({messages:e,streamingMessage:t,scrollContainer:r,messageRefs:o,onRevealHistory:l}){let[a,s]=(0,i.useState)(!1),[d,c]=(0,i.useState)([]),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(600),[f,x]=(0,i.useState)(!1),[m,v]=(0,i.useState)(null),b=(0,i.useRef)(!1),y=(0,i.useRef)(null),k=(0,i.useRef)([]),w=(0,i.useRef)({nodes:[],gap:50,fillsHeight:!1}),j=(0,i.useRef)(null),S=(0,i.useRef)(new Map),C=(0,i.useRef)(null),T=(0,i.useRef)(null),M=(0,i.useRef)(null),R=(0,i.useMemo)(()=>t?[...e,t]:e,[e,t]),I=(0,i.useRef)(R);I.current=R;let L=(0,i.useMemo)(()=>(function(e,t){if(0===e.length)return{nodes:[],gap:50,fillsHeight:!1};let r=Math.max(1,t),n=Math.max(0,r-24);if(1===e.length)return{nodes:[{...e[0],topRatio:12/r}],gap:50,fillsHeight:!1};let i=n/(e.length-1),o=Math.min(50,i);return{nodes:e.map((e,t)=>({...e,topRatio:(12+t*o)/r})),gap:o,fillsHeight:i<=50}})(d,h),[d,h]),{nodes:E,gap:W}=L;w.current=L;let z=(0,i.useCallback)(e=>{T.current={index:e,until:Date.now()+1600},p(e)},[]),$=(0,i.useCallback)((e,t)=>{let r=T.current;if(r&&Date.now()<r.until)return void p(r.index);T.current=null;let n=t.filter(e=>null!==e.targetTurn.scrollTop);if(0===n.length)return void p(null);let i=e.scrollTop+.3*e.clientHeight;p(n.reduce((e,t)=>Math.abs((t.targetTurn.scrollTop??0)-i)<Math.abs((e.targetTurn.scrollTop??0)-i)?t:e,n[0]).index)},[]),P=(0,i.useCallback)(()=>{let e=r.current;if(!e)return;let t=e.scrollHeight-e.clientHeight,n=k.current;s(t>20),$(e,n)},[r,$]),A=(0,i.useRef)(null),D=(0,i.useCallback)(()=>{A.current||(A.current=setTimeout(()=>{A.current=null;let e=r.current,t=y.current;if(!e||!t)return;let n=o.current,i=e.getBoundingClientRect(),l=[],a=0,d=null;for(let t of I.current){if("user"!==t.role&&"assistant"!==t.role)continue;let r=n?.[a];if(a++,"user"===t.role){d=null;let n=r?.getBoundingClientRect();d={userMessage:t,assistantPreviews:[],scrollTop:n?n.top-i.top+e.scrollTop:null},l.push(d);continue}if(!d)continue;let o=function(e){if("assistant"!==e.role)return"";let{answerBlocks:t}=eS(e);return t.filter(e=>"text"===e.type).map(e=>e.text).join("\n\n").trim()}(t);o&&d.assistantPreviews.push({markdown:o,element:r})}let u=l.map((e,t)=>({topRatio:0,targetTurn:e,index:t}));g(t.clientHeight),k.current=u,c(u),s(e.scrollHeight-e.clientHeight>20),$(e,u);let p=M.current,h=p?u[p.nodeIndex]:null;if(p&&h){let t=void 0===p.assistantIndex?null:h.targetTurn.assistantPreviews[p.assistantIndex],r=h.targetTurn.scrollTop;if("assistant"===p.target){let n=t?.element?.getBoundingClientRect();r=n?n.top-i.top+e.scrollTop:null}else if("heading"===p.target){let n=void 0===p.headingIndex?null:t?.element?.querySelectorAll("h1, h2, h3").item(p.headingIndex),o=n?.getBoundingClientRect();r=o?o.top-i.top+e.scrollTop:null}if(null===r)return;M.current=null,z(h.index);let n=.3*e.clientHeight;e.scrollTo({top:Math.max(0,r-n),behavior:"smooth"})}},150))},[z,o,r,$]);(0,i.useEffect)(()=>{let e=r.current;if(e)return e.addEventListener("scroll",P,{passive:!0}),()=>e.removeEventListener("scroll",P)},[r,P]),(0,i.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{D(),P()},n=new ResizeObserver(t);return n.observe(e),e.firstElementChild&&n.observe(e.firstElementChild),t(),()=>{n.disconnect(),A.current&&(clearTimeout(A.current),A.current=null)}},[D,r,P]),(0,i.useEffect)(()=>{let e=setTimeout(()=>{D(),P()},50);return()=>clearTimeout(e)},[e.length,D,P]);let N=(0,i.useCallback)((e,t)=>{let n=r.current;if(!n)return;if(z(e.index),null===e.targetTurn.scrollTop){M.current={nodeIndex:e.index,target:"user"},l();return}let i=Math.max(0,e.targetTurn.scrollTop-.3*n.clientHeight);n.scrollTo({top:i,behavior:t})},[z,l,r]),F=(0,i.useCallback)((e,t)=>{let n=r.current;if(!n)return;let i=e.targetTurn.assistantPreviews[t]?.element;if(!i){M.current={nodeIndex:e.index,target:"assistant",assistantIndex:t},l();return}let o=n.getBoundingClientRect(),a=i.getBoundingClientRect().top-o.top+n.scrollTop-.3*n.clientHeight;z(e.index),n.scrollTo({top:Math.max(0,a),behavior:"smooth"})},[z,l,r]),B=(0,i.useCallback)(e=>{let{nodes:t,gap:r,fillsHeight:n}=w.current,i=y.current?.clientHeight??0;if(0===t.length||i<=0)return null;let o=Math.max(0,Math.min(i,e*i)),l=t[0].topRatio*i,a=r>0?Math.round((o-l)/r):0,s=Math.max(0,Math.min(t.length-1,a)),d=t[s];if(!n&&Math.abs(o-d.topRatio*i)>Math.max(10,r/2))return null;return d},[]),H=(0,i.useCallback)((e,t,n)=>{let i=r.current;if(!i)return;let o=e.targetTurn.assistantPreviews[t]?.element;if(!o){M.current={nodeIndex:e.index,target:"heading",assistantIndex:t,headingIndex:n},l();return}let a=o.querySelectorAll("h1, h2, h3").item(n);if(!a)return;let s=i.getBoundingClientRect(),d=a.getBoundingClientRect().top-s.top+i.scrollTop-.3*i.clientHeight;z(e.index),i.scrollTo({top:Math.max(0,d),behavior:"smooth"})},[z,l,r]),O=(0,i.useCallback)(()=>{C.current&&(clearTimeout(C.current),C.current=null)},[]),U=(0,i.useCallback)(()=>{O(),x(!0)},[O]),_=(0,i.useCallback)(()=>{O(),C.current=setTimeout(()=>{C.current=null,x(!1),v(null)},250)},[O]);(0,i.useEffect)(()=>()=>O(),[O]);let q=(0,i.useCallback)(e=>{if(!a)return;b.current=!0,U();let t=e.currentTarget.getBoundingClientRect();v(Math.max(0,Math.min(1,(e.clientY-t.top)/t.height)));let r=(e,r)=>{let n=B(Math.max(0,Math.min(1,(e-t.top)/t.height)));n&&N(n,r)};r(e.clientY,"smooth");let n=e=>{b.current&&r(e.clientY,"auto")},i=()=>{b.current=!1,window.removeEventListener("mousemove",n),window.removeEventListener("mouseup",i)};window.addEventListener("mousemove",n),window.addEventListener("mouseup",i)},[B,N,U,a]),K=null===m?null:B(m),V=K?.index??null;(0,i.useEffect)(()=>{if(!f||null===V)return;let e=j.current,t=S.current.get(V);if(!e||!t)return;let r=t.offsetTop-(e.clientHeight-t.offsetHeight)/2;e.scrollTop=Math.max(0,r)},[d,f,V]);let J=Math.max(1,(E.length>0?E[E.length-1].topRatio*h:12)-12);return(0,n.jsxs)("div",{ref:y,onMouseDown:q,onMouseEnter:U,onMouseLeave:_,onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();v((e.clientY-t.top)/t.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"pointer",userSelect:"none",border:a?"1px solid color-mix(in srgb, var(--border) 60%, transparent)":"none",background:a?"var(--panel-glass-minimap)":"transparent",backdropFilter:a?"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))":"none",WebkitBackdropFilter:a?"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))":"none",transform:"translateZ(0)",borderRadius:12,boxShadow:a?"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)":"none",overflow:"visible"},children:[a&&(0,n.jsx)("div",{style:{position:"absolute",left:"50%",top:12,height:J,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),a&&E.map(e=>{let t=f&&K?.index===e.index,r=u===e.index;return(0,n.jsx)("div",{"data-minimap-node-index":e.index,"data-minimap-node-active":r?"":void 0,style:{position:"absolute",top:`${100*e.topRatio}%`,transform:"translateY(-50%)",left:0,right:0,height:Math.max(1,W),display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none",zIndex:2},children:(0,n.jsx)("div",{style:{width:8,height:8,borderRadius:2,background:r?"rgba(128,128,128,0.42)":"rgba(128,128,128,0.16)",border:`1.5px solid ${r?"rgba(128,128,128,0.95)":"rgba(128,128,128,0.58)"}`,boxShadow:r?"0 0 0 2px var(--bg-panel)":"none",transition:"transform 0.1s, background 0.1s",transform:t?"scale(1.25)":"scale(1)"}})},e.index)}),a&&f&&d.length>0&&(0,n.jsx)("div",{ref:j,className:rW().preview,"data-minimap-preview-box":"",onMouseEnter:U,onMouseDown:e=>e.stopPropagation(),onMouseMove:e=>e.stopPropagation(),children:d.map(e=>{var t;let r=V===e.index;return(0,n.jsxs)("div",{ref:t=>{t?S.current.set(e.index,t):S.current.delete(e.index)},className:rW().turn,"data-minimap-preview-index":e.index,"data-located":r?"true":void 0,children:[(0,n.jsx)("span",{className:rW().number,"aria-hidden":"true",children:String(e.index+1).padStart(2,"0")}),(0,n.jsxs)("div",{className:rW().content,children:[(0,n.jsx)("button",{type:"button",className:rW().user,"data-minimap-preview-user":e.index,onClick:()=>{N(e,"smooth")},children:(0,n.jsx)("span",{className:rW().userText,children:"string"==typeof(t=e.targetTurn.userMessage).content?t.content.trim():t.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n").trim()})}),e.targetTurn.assistantPreviews.map((t,r)=>(0,n.jsxs)("div",{className:rW().assistant,children:[(0,n.jsx)("button",{type:"button",className:rW().assistantJump,"data-minimap-preview-assistant":`${e.index}-${r}`,onClick:()=>F(e,r),"aria-label":"Locate assistant message",title:"Locate assistant message",children:"A"}),(0,n.jsx)(rD,{markdown:t.markdown,onAnswerClick:()=>F(e,r),onHeadingClick:t=>H(e,r,t)})]},r))]})]},e.index)})})]})}function rF({widgets:e}){let t,r,o,{t:l}=(0,b.s)(),a=(0,i.useId)(),s=(0,i.useRef)(null),d=(0,i.useRef)(new Map),[c,u]=(0,i.useState)(()=>e.find(e=>{let t=e.lines.length;return t>1&&t<=3})?.key??null),[p,h]=(0,i.useState)(()=>new Set),g=(0,i.useRef)(null),f=(0,i.useRef)(null);if((0,i.useEffect)(()=>{var t;let r=new Map(e.map(e=>[e.key,[...e.lines]])),n=(t=s.current,t?Array.from(r,([e,r])=>{let n=t.get(e);return n&&n.length===r.length?r.some((e,t)=>e!==n[t])?e:null:n?e:null}).filter(e=>null!==e):[]);for(let[e,t]of(s.current=r,d.current))r.has(e)||(clearTimeout(t),d.current.delete(e));for(let e of(h(e=>{let t=new Set(Array.from(e).filter(e=>r.has(e)));for(let e of n)t.add(e);return t.size===e.size&&Array.from(t).every(t=>e.has(t))?e:t}),n)){let t=d.current.get(e);t&&clearTimeout(t),d.current.set(e,setTimeout(()=>{d.current.delete(e),h(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),r})},1100))}},[e]),(0,i.useEffect)(()=>()=>{for(let e of d.current.values())clearTimeout(e);d.current.clear()},[]),(0,i.useEffect)(()=>{if(!c)return;let e=e=>{let t=e.target;f.current?.contains(t)||g.current?.contains(t)||u(null)};return document.addEventListener("pointerdown",e,!0),()=>document.removeEventListener("pointerdown",e,!0)},[c]),0===e.length)return null;let x=e.find(e=>e.key===c&&e.lines.length>1);return(0,n.jsxs)(n.Fragment,{children:[x&&(0,n.jsx)("div",{ref:f,className:"extension-widget-panels",children:(t=e.indexOf(x),r=`${a}-trigger-${t}`,o=`${a}-panel-${t}`,(0,n.jsxs)("section",{id:o,className:"extension-widget-panel","aria-labelledby":r,children:[(0,n.jsx)("div",{className:"extension-widget-panel-heading",children:x.key}),(0,n.jsx)("pre",{className:"extension-widget-content",children:x.lines.join("\n")})]},x.key))}),(0,n.jsx)("div",{ref:g,className:"extension-widget-triggers","aria-label":l("chat.extensionWidgets"),children:e.map((e,t)=>{let r=e.lines.length>1,i=r&&e.key===x?.key,o=p.has(e.key),s=l(1===e.lines.length?"chat.extensionWidgetLine":"chat.extensionWidgetLines",{count:e.lines.length}),d=l("belowEditor"===e.placement?"chat.extensionWidgetBelow":"chat.extensionWidgetAbove"),c=`${a}-trigger-${t}`,h=`${a}-panel-${t}`,g=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"extension-widget-update-pulse","aria-hidden":"true"}),(0,n.jsx)("span",{className:"extension-widget-placement","aria-hidden":"true",children:(0,n.jsx)("svg",{className:"extension-widget-placement-icon",viewBox:"0 0 8 6",width:"8",height:"6","data-direction":"belowEditor"===e.placement?"down":"up",focusable:"false",children:(0,n.jsx)("path",{d:"belowEditor"===e.placement?"M0 0h8L4 6z":"M4 0l4 6H0z"})})}),(0,n.jsx)("span",{className:"extension-widget-key",children:e.key})]});return r?(0,n.jsx)("button",{id:c,type:"button",className:`extension-widget-trigger${i?" is-expanded":""}${o?" is-updating":""}`,"aria-controls":h,"aria-expanded":i,"aria-label":`${d}: ${e.key}, ${s}`,title:`${e.key} - ${d} - ${i?l("i18n.collapse"):l("i18n.expand")}`,onClick:()=>{u(t=>{var r;return t===(r=e.key)?null:r})},children:g},e.key):(0,n.jsx)("div",{className:`extension-widget-trigger${o?" is-updating":""}`,"aria-label":`${d}: ${e.key}, ${s}`,title:`${e.key} - ${d}`,children:g},e.key)})})]})}function rB({statuses:e,widgets:t=[],tools:r}){if(0===e.length&&0===t.length)return null;let i=[...e].sort((e,t)=>e.key.localeCompare(t.key)).map(({text:e})=>e.replace(/[\r\n\t]/g," ").replace(/ +/g," ").trim()).join(" "),o=eg(i);return(0,n.jsxs)("div",{className:`extension-status-shelf${t.length>0?" has-widgets":""}${e.length>0?" has-status":""}`,children:[(0,n.jsxs)("div",{className:"extension-status-left",children:[t.length>0&&(0,n.jsx)(rF,{widgets:t}),e.length>0&&(0,n.jsx)("div",{role:"status",className:"extension-status-line","aria-label":o,title:o,children:(0,n.jsx)("span",{className:"extension-status-text",children:ev(i).map((e,t)=>(0,n.jsx)("span",{style:e.style,children:e.text},t))})})]}),(0,n.jsx)("div",{className:`extension-status-right${r?" has-tools":""}`,children:r})]})}function rH(e=document){return"visible"!==e.visibilityState||!e.hasFocus()}function rO(e){switch(e.method){case"select":case"confirm":case"input":case"editor":return!0;case"custom":return!0!==e.closed;default:return!1}}async function rU(e,t={createWindowNotification:(e,t)=>new Notification(e,t),getServiceWorkerRegistration:"serviceWorker"in navigator?()=>navigator.serviceWorker.getRegistration():null}){let r={body:e.body,...e.tag?{tag:e.tag}:{}};if(t.getServiceWorkerRegistration)try{let n=await t.getServiceWorkerRegistration();if(n)return await n.showNotification(e.title,{...r,data:{url:e.sessionUrl}}),"service-worker"}catch{}try{let n=t.createWindowNotification(e.title,r);return n.onclick=()=>{n.close(),e.onClick()},"window"}catch{return null}}function r_(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function rq(e,t={}){if("assistant"!==e.role)return e;let r=e.content;if(!Array.isArray(r))return e;let n=r.map(e=>(function(e,t={}){if(!r_(e)||"toolCall"!==e.type)return null;let r={type:"toolCall",toolCallId:"string"==typeof e.toolCallId?e.toolCallId:"string"==typeof e.id?e.id:"",toolName:"string"==typeof e.toolName?e.toolName:"string"==typeof e.name?e.name:"",input:"object"!=typeof e.input||null===e.input||Array.isArray(e.input)?"object"!=typeof e.arguments||null===e.arguments||Array.isArray(e.arguments)?{}:e.arguments:e.input},n=t.includeStreamingRawInput?function(e){if("string"==typeof e.rawInput)return e.rawInput;if("string"==typeof e.partialJson)return e.partialJson;if("string"==typeof e.partialArgs)return e.partialArgs;let t=r_(e.customInput)?e.customInput:null,r=t&&"string"==typeof t.property?t.property:null,n=r_(e.arguments)?e.arguments:null;return r&&n&&"string"==typeof n[r]?n[r]:void 0}(e):void 0;return void 0===n?r:{...r,rawInput:n}})(e,t)??e);return{...e,content:n}}class rK extends Error{constructor(e,t,r,n){super(e),this.status=t,this.code=r,this.accepted=n,this.name="AgentCommandError"}}function rV(e){return e instanceof rK&&"prompt_rejected"===e.code&&!1===e.accepted}async function rJ(e,t){let r=await fetch(`/api/agent/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json().catch(()=>({}));if(!r.ok||n.error)throw new rK(n.error??`HTTP ${r.status}`,r.status,n.code,n.accepted);return n.data}var rY=r(14755);let rX="pi-tool-preset";function rZ(){try{return window.localStorage}catch{return null}}function rG(e){if(!e||"object"!=typeof e||"image"!==e.type)return"";let t=e.source;return t&&"object"==typeof t?["url"===t.type?"url":"base64","string"==typeof t.media_type?t.media_type:"","string"==typeof t.data?t.data:"","string"==typeof t.url?t.url:""].join(":"):["base64","string"==typeof e.mimeType?e.mimeType:"","string"==typeof e.data?e.data:"",""].join(":")}function rQ(e){let t,r=e.content;return"string"==typeof r?JSON.stringify({text:r,images:[]}):Array.isArray(r)?JSON.stringify({text:"string"==typeof(t=e.content)?t:Array.isArray(t)?t.map(e=>e&&"object"==typeof e&&"text"===e.type&&"string"==typeof e.text?e.text:"").filter(Boolean).join("\n"):"",images:r.map(rG).filter(Boolean)}):JSON.stringify({text:"",images:[]})}class r0 extends Error{constructor(e,t){super(t??("ready_timeout"===e?"Timed out starting the agent session. Please try again.":"Failed to connect to the agent event stream. Please try again.")),this.status=e,this.name="AgentEventConnectionError"}}class r1{constructor(e){this.options=e,this.current=null,this.retry=null,this.retryGeneration=0}close(){this.stopRetrying(),this.current&&this.discard(this.current,new r0("closed"))}maintain(e){if(!this.options.shouldMaintain(e))return;let t=this.retryGeneration;this.ensureConnected(e).catch(r=>{t===this.retryGeneration&&(r instanceof r0?"startup_error"===r.status?this.stopRetrying():this.scheduleRetry(e):this.options.onUnexpectedError?.(r))})}async ensureConnected(e){for(;;){let t=this.current;if(t&&t.sessionId===e){if(t.attempt.ready&&1===t.source.readyState)return}else t=this.open(e);if(await t.attempt.promise,this.current!==t){if(this.current?.sessionId===e)continue;throw new r0("closed")}if(1===t.source.readyState)return;this.discard(t,new r0("closed"))}}open(e){let t,r,n;this.current&&this.discard(this.current,new r0("closed"));try{t=this.options.createSource(e)}catch(e){throw new r0("closed",e instanceof Error?e.message:String(e))}let i=!1,o=new Promise((e,t)=>{r=e,n=t}),l=setTimeout(()=>{this.fail(s,new r0("ready_timeout"))},this.options.readinessTimeoutMs),a={promise:o,ready:!1,succeed(){i||(i=!0,clearTimeout(l),r())},fail(e){i||(i=!0,clearTimeout(l),n(e))}},s={sessionId:e,source:t,attempt:a};return this.current=s,t.onmessage=e=>{let t;if(this.current===s){try{t=JSON.parse(e.data)}catch{return}if("connected"===t.type)a.ready=!0,a.succeed(),this.stopRetrying();else if("startup_error"===t.type){let e="string"==typeof t.errorMessage?t.errorMessage:void 0;this.fail(s,new r0("startup_error",e));return}this.options.onEvent(t)}},t.onerror=()=>{this.fail(s,new r0("closed"))},s}fail(e,t){this.current===e&&(this.discard(e,t),"startup_error"===t.status?this.stopRetrying():this.scheduleRetry(e.sessionId))}discard(e,t){e.attempt.fail(t),e.source.close(),this.current===e&&(this.current=null)}scheduleRetry(e){if(!this.options.shouldMaintain(e)||this.retry?.sessionId===e)return;this.clearRetry();let t=setTimeout(()=>{this.retry?.timer===t&&(this.retry=null,this.maintain(e))},this.options.reconnectDelayMs);this.retry={sessionId:e,timer:t}}stopRetrying(){this.retryGeneration+=1,this.clearRetry()}clearRetry(){this.retry&&clearTimeout(this.retry.timer),this.retry=null}}function r2(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function r8(e,t,r,n=8){return e+t>=r-n}let r4={isStreaming:!1,streamingMessage:null};function r6(e,t,r){let n=e.streamingMessage;if(!n||!Number.isInteger(t)||t<0)return e;let i=[...n.content],o=r(i[t]);return o?(i[t]=o,{isStreaming:!0,streamingMessage:{...n,content:i}}):e}function r5(e,t){switch(t.type){case"start":return{isStreaming:!0,streamingMessage:null};case"snapshot":{let r=rq(t.message,{includeStreamingRawInput:!0});return"assistant"===r.role?{isStreaming:!0,streamingMessage:r}:e}case"delta":var r=t.event;switch(r.type){case"text_start":return r6(e,r.contentIndex,e=>e?.type==="text"?e:{type:"text",text:""});case"text_delta":return r6(e,r.contentIndex,e=>e?.type==="text"?{...e,text:e.text+r.delta}:null);case"text_end":return r6(e,r.contentIndex,e=>({...e?.type==="text"?e:{},type:"text",text:r.content}));case"thinking_start":return r6(e,r.contentIndex,e=>e?.type==="thinking"?e:{type:"thinking",thinking:""});case"thinking_delta":return r6(e,r.contentIndex,e=>e?.type==="thinking"?{...e,thinking:e.thinking+r.delta}:null);case"thinking_end":return r6(e,r.contentIndex,e=>({...e?.type==="thinking"?e:{},type:"thinking",thinking:r.content}));case"toolcall_start":return r6(e,r.contentIndex,e=>e?.type==="toolCall"?{...e,toolCallId:r.id??e.toolCallId,toolName:r.toolName??e.toolName,rawInput:e.rawInput??""}:"string"!=typeof r.toolName?null:{type:"toolCall",toolCallId:r.id??"",toolName:r.toolName,input:{},rawInput:""});case"toolcall_delta":return r6(e,r.contentIndex,e=>e?.type==="toolCall"?{...e,toolCallId:r.id||e.toolCallId,toolName:r.toolName||e.toolName,rawInput:(e.rawInput??"")+r.delta}:null);case"toolcall_end":return r6(e,r.contentIndex,()=>({type:"toolCall",toolCallId:r.toolCall.id,toolName:r.toolCall.name,input:r.toolCall.arguments}));default:return e}case"end":return r4;default:return e}}function r3(e){return{steering:e?.steering??[],followUp:e?.followUp??[]}}function r7(e){return new Promise(t=>setTimeout(t,e))}function r9(e){let t=e.findIndex(e=>!e.exiting);return -1===t?e:e.map((e,r)=>r===t?{...e,exiting:!0}:e)}function ne(e,t){switch(t.type){case"add":if(e.visible.some(e=>e.exiting)||e.visible.length>=5)return{visible:e.visible.some(e=>e.exiting)?e.visible:r9(e.visible),pending:[...e.pending,t.notice]};return{...e,visible:[...e.visible,t.notice]};case"mark_oldest_exiting":return{...e,visible:r9(e.visible)};case"remove":return function(e,t){let r=e,n=t;for(;n.length>0&&r.length<5;){let[e,...t]=n;r=[...r,e],n=t}return n.length>0&&!r.some(e=>e.exiting)&&(r=r9(r)),{visible:r,pending:n}}(e.visible.filter(e=>e.id!==t.id),e.pending);default:return e}}function nt(e,t){return e&&"object"==typeof e?"number"!=typeof e.tokensBefore||"number"!=typeof e.estimatedTokensAfter?null:{reason:t,tokensBefore:e.tokensBefore,estimatedTokensAfter:e.estimatedTokensAfter}:null}function nr({label:e}){let[t,r]=(0,i.useState)(null);if((0,i.useEffect)(()=>{let e=new AbortController;return fetch("/api/app-update",{signal:e.signal}).then(async e=>e.ok?e.json():null).then(e=>{e?.updateAvailable&&e.latestVersion&&e.releaseUrl&&r(e)}).catch(()=>{}),()=>e.abort()},[]),!t)return null;let o=e(t.latestVersion);return(0,n.jsxs)("a",{href:t.releaseUrl,target:"_blank",rel:"noopener noreferrer",title:o,"aria-label":o,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},style:{display:"inline-flex",alignItems:"center",alignSelf:"center",gap:3,minHeight:32,minWidth:0,padding:"0 4px",background:"transparent",borderRadius:5,color:"var(--accent)",fontSize:12,fontWeight:600,lineHeight:1.2,textDecoration:"none",transition:"background 0.12s",whiteSpace:"nowrap"},children:[(0,n.jsxs)("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:["v",t.latestVersion]}),(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M7 17 17 7"}),(0,n.jsx)("path",{d:"M7 7h10v10"})]})]})}function nn(e){return"user"===e.role||"custom"===e.role&&"compaction"===e.customType}function ni(e,t,r={}){let n={...e,content:t};return r.omitUsage&&(n.usage=void 0),n}function no({messageCount:e,toolCallCount:t,defaultExpanded:r=!1,children:o,t:l}){let[a,s]=(0,i.useState)(r),d=[l("chat.processDetails"),`${e} ${l(1===e?"chat.message":"chat.messages")}`];return t>0&&d.push(`${t} ${l(1===t?"chat.toolCall":"chat.toolCalls")}`),(0,n.jsxs)("div",{style:{marginBottom:14},children:[(0,n.jsxs)("button",{type:"button","aria-expanded":a,onClick:()=>s(e=>!e),style:{display:"flex",alignItems:"center",gap:8,width:"auto",minHeight:24,padding:"2px 0",border:"none",background:"transparent",color:"#ffffff",mixBlendMode:"exclusion",cursor:"pointer",fontSize:12,textAlign:"left"},title:l(a?"chat.collapseProcess":"chat.expandProcess"),children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:a?"rotate(90deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"4 2.5 7.5 6 4 9.5"})}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d.join(" \xb7 ")})]}),a&&(0,n.jsx)("div",{style:{marginTop:8},children:o})]})}function nl({session:e,sessionRunning:t,newSessionCwd:o,newSessionDraftKey:l,onAgentEnd:a,onAttentionNeeded:d,onSessionCreated:c,onSessionForked:u,modelsRefreshKey:p,chatInputRef:h,onBranchDataChange:g,onSystemPromptChange:f,onSystemPromptLoaderChange:x,onSessionStatsChange:m,onSessionStatsPanelOpen:v,onTodosChange:y,onContextUsageChange:k,onOpenFile:w,soundEnabled:j=!0,onSoundToggle:S,playDoneSound:C=()=>{},unlockAudio:T,terminalOpen:M=!1,onToggleTerminal:R}){var I;let L,{t:E}=(0,b.s)(),W=(0,ro.a)(),z=(0,i.useRef)(C);z.current=C;let $=(0,i.useRef)(j);$.current=j;let P=(0,i.useRef)(null),A=(0,i.useCallback)(()=>{$.current&&z.current(),a?.()},[a]),D=(0,i.useCallback)(e=>{h?.current?.replaceMessage(e)},[h]),{loading:N,error:F,messages:B,entryIds:H,streamState:O,agentRunning:U,bashRunning:_,pendingBash:q,modelNames:K,modelList:V,modelError:J,modelScopeWarnings:Y,modelThinkingLevels:X,modelThinkingLevelMaps:Z,toolPreset:G,thinkingLevel:Q,retryInfo:ee,contextUsage:et,forkingEntryId:er,isCompacting:en,compactError:ei,compactResult:eo,displayModel:el,modelSwitching:ea,sessionStats:es,todos:ed,slashCommands:ec,slashCommandsLoading:eu,queuedMessages:ep,notices:eh,extensionDialog:eg,extensionCustomUi:ef,extensionStatuses:ex,extensionWidgets:em,respondToExtensionUi:ev,sendExtensionCustomInput:eb,isAutoModelSelection:ey,agentPhase:ek,isNew:eT,sessionIdRef:eM,messagesEndRef:eI,scrollContainerRef:eE,lastUserMsgRef:eW,promptAnchorActive:ez,handleSend:e$,handleAbort:eP,handleFork:eA,handleNavigate:eD,handleModelChange:eN,handleCompact:eF,handleSteer:eB,handleFollowUp:eH,handlePromptWithStreamingBehavior:eO,handleAbortCompaction:eU,handleRecallQueue:e_,handleBuiltinSlashCommand:eq,handleToolPresetChange:eK,handleThinkingLevelChange:eV,loadSlashCommands:eJ,scrollUserMsgToTop:eY,scrollToBottom:eX,loadContext:eZ,activeLeafId:eG,hasOlderChat:eQ}=function(e){let{session:t,sessionRunning:n,newSessionCwd:o,newSessionDraftKey:l,onAgentEnd:a,onAttentionNeeded:s,onSessionCreated:d,onSessionForked:c,modelsRefreshKey:u,onBranchDataChange:p,onSystemPromptChange:h,onSystemPromptLoaderChange:g,onSessionStatsPanelOpen:f}=e,x=null===t&&null!==o,[m,v]=(0,i.useState)(null),[b,y]=(0,i.useState)(!x),[k,w]=(0,i.useState)(null),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(!1),[M,R]=(0,i.useState)([]),[I,L]=(0,i.useState)([]),[E,W]=(0,i.useState)([]),[z,$]=(0,i.useReducer)(r5,r4),[P,A]=(0,i.useState)(!1),[D,N]=(0,i.useState)(!1),[F,B]=(0,i.useState)(null),[H,O]=(0,i.useState)({}),[U,_]=(0,i.useState)([]),[q,K]=(0,i.useState)(null),[V,J]=(0,i.useState)([]),[Y,X]=(0,i.useState)({}),[Z,G]=(0,i.useState)({}),[Q,ee]=(0,i.useState)(null),[et,er]=(0,i.useState)(null),[en,ei]=(0,i.useState)("default"),[eo,el]=(0,i.useState)("auto"),[ea,es]=(0,i.useState)(null),[ed,ec]=(0,i.useState)(null),[eu,ep]=(0,i.useState)(null),[eh,eg]=(0,i.useState)(null),[ef,ex]=(0,i.useState)(null),[em,ev]=(0,i.useState)(null),[eb,ey]=(0,i.useState)(!1),[ek,ew]=(0,i.useState)(!1),[ej,eS]=(0,i.useState)(null),[eC,eT]=(0,i.useState)(null),[eM,eR]=(0,i.useState)(null),[eI,eL]=(0,i.useState)(!1),[eE,eW]=(0,i.useState)([]),[ez,e$]=(0,i.useState)(!1),[eP,eA]=(0,i.useReducer)(ne,{visible:[],pending:[]}),[eD,eN]=(0,i.useState)(null),[eF,eB]=(0,i.useState)(null),[eH,eO]=(0,i.useState)(null),[eU,e_]=(0,i.useState)([]),[eq,eK]=(0,i.useState)([]),[eV,eJ]=(0,i.useState)({steering:[],followUp:[]}),eY=(0,i.useRef)(null),eX=(0,i.useRef)(null),eZ=(0,i.useRef)(0),eG=(0,i.useRef)(!1),eQ=(0,i.useRef)(t?.id??null),e0=(0,i.useRef)(t?.id??null),e1=(0,i.useRef)(!!n),e2=(0,i.useRef)(!1),e8=(0,i.useRef)(!1),e4=(0,i.useRef)(!1),e6=(0,i.useRef)(-1),e5=(0,i.useRef)(!1),e3=(0,i.useRef)(0),e7=(0,i.useRef)(null),e9=(0,i.useRef)(!1),te=(0,i.useRef)(null),tt=(0,i.useRef)(!1),tr=(0,i.useRef)(!0),tn=(0,i.useRef)(0),ti=(0,i.useRef)(null),to=(0,i.useRef)(void 0),tl=(0,i.useRef)(null),ta=(0,i.useRef)(null),ts=(0,i.useRef)(null),td=(0,i.useRef)(!1),tc=(0,i.useRef)(null),tu=(0,i.useRef)(null),tp=(0,i.useRef)(0),th=(0,i.useRef)(null),tg=(0,i.useRef)(!1),tf=(0,i.useRef)(new Map),tx=(0,i.useRef)(!0);e0.current=t?.id??null,e1.current=!!n,eY.current||(eY.current=new r1({createSource:e=>new EventSource(`/api/agent/${encodeURIComponent(e)}/events`),onEvent:e=>e7.current?.(e),shouldMaintain:e=>tx.current&&eQ.current===e&&(e2.current||eG.current||e0.current===e&&e1.current),readinessTimeoutMs:6e4,reconnectDelayMs:1e3,onUnexpectedError:e=>{console.error("Failed to maintain the agent event stream:",e)}}));let tm=e.setToolPreset??ei;(0,i.useLayoutEffect)(()=>{x&&!eQ.current&&tm(function(e=rZ()){if(!e)return"default";try{let t=e.getItem(rX);return(0,rY.sn)(t)?t:"default"}catch{return"default"}}())},[x,tm]);let tv=(0,i.useCallback)((e="smooth")=>{let t=ta.current;tl.current?.scrollIntoView({behavior:e}),t&&(tn.current=t.scrollTop)},[]),tb=ef??m?.context.model??em??null,ty=x?Q??et:tb,tk=t?.id??l??void 0,tw=(0,i.useCallback)(e=>{if(!e)return;let t=e,r=new Set;for(;!r.has(t);){r.add(t);let e=tf.current.get(t);if(!e)break;t=e}return t},[]),tj=(0,i.useCallback)((t,r,n)=>{let i=r?.map(({data:e,mimeType:t})=>({data:e,mimeType:t})),o=tw(n);if(!tx.current&&!td.current&&n===l)return;let a=e.chatInputRef?.current;if(a)a.restoreSubmission(t,i,o);else{let e,r;o&&(r=tJ(t,i,(e=t_(o)??{value:"",images:[]}).value,e.images),tq(o,r))}},[l,e.chatInputRef,tw]),tS=(0,i.useMemo)(()=>{if(eD)return{...eD,totalActiveMs:m?.totalActiveMs};let e={input:0,output:0,cacheRead:0,cacheWrite:0,total:0},r=0,n=0,i=0,o=0,l=0;for(let t of M){if("user"===t.role&&(n+=1),"toolResult"===t.role&&(o+=1),"assistant"!==t.role)continue;i+=1;let a=t.usage;l+=t.content.filter(e=>"toolCall"===e.type).length,a&&(e.input+=a.input??0,e.output+=a.output??0,e.cacheRead+=a.cacheRead??0,e.cacheWrite+=a.cacheWrite??0,r+=a.cost?.total??0)}return(e.total=e.input+e.output+e.cacheRead+e.cacheWrite,0===e.total&&0===M.length)?null:{sessionFile:m?.filePath||void 0,sessionId:eQ.current??t?.id??"",sessionName:t?.name,userMessages:n,assistantMessages:i,toolCalls:l,toolResults:o,totalMessages:M.length,tokens:e,cost:r,totalActiveMs:m?.totalActiveMs,...ed?{contextUsage:ed}:{}}},[M,eD,ed,m?.filePath,m?.totalActiveMs,t?.id,t?.name]),tC=(0,i.useCallback)(async(e,t=!1,r=!1)=>{let n=!1;try{t&&y(!0);let i=new URLSearchParams({deferThinking:"1"}),o=await fetch(`/api/sessions/${encodeURIComponent(e)}?${i}`);if(404===o.status)return t&&(v(null),S(null),R([]),W([]),w(null)),null;if(!o.ok)throw Error(`HTTP ${o.status}`);let l=await o.json();if(eQ.current!==e)return null;let a=l.context.messages;if(v(l),S(l.leafId),R(a),L(l.context.entryIds??[]),W(l.context.todos??[]),T(l.hasMore??!1),ex(e=>tg.current?e:null),w(null),l.context.thinkingLevel&&"off"!==l.context.thinkingLevel&&el(l.context.thinkingLevel),n=!0,t&&y(!1),!r)return null;try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/state`);if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();if(eQ.current!==e)return null;let n=r.state;return n?(void 0!==n.contextUsage&&ec(n.contextUsage??null),void 0!==n.systemPrompt&&ep(n.systemPrompt??null),void 0!==n.thinkingLevel&&el(n.thinkingLevel??"auto"),void 0!==n.extensionStatuses&&e_(n.extensionStatuses??[]),void 0!==n.extensionWidgets&&eK(n.extensionWidgets??[]),void 0!==n.queuedMessages&&eJ(r3(n.queuedMessages))):r.running||eJ({steering:[],followUp:[]}),r}catch(e){return console.error("Failed to load agent state:",e),null}}catch(e){return w(String(e)),null}finally{t&&!n&&y(!1)}},[]),tT=(0,i.useCallback)(async(e,t,r)=>{try{let n=new URLSearchParams({deferThinking:"1"});t&&n.set("leafId",t),r&&n.set("before",r);let i=`/api/sessions/${encodeURIComponent(e)}/context?${n}`,o=await fetch(i);if(!o.ok)throw Error(`HTTP ${o.status}`);let l=await o.json();T(l.hasMore??!1),r?(R(e=>[...l.context.messages,...e]),L(e=>[...l.context.entryIds,...e])):(R(l.context.messages),L(l.context.entryIds??[]),W(l.context.todos??[]))}catch(e){console.error("Failed to load context:",e)}},[]),tM=(0,i.useCallback)(async e=>{try{let t=await rJ(e,{type:"get_tools"});if(t){let{getPresetFromTools:e}=await Promise.resolve().then(r.bind(r,14755));tm(e(t))}}catch(e){console.error("Failed to load tools:",e)}},[tm]),tR=(0,i.useCallback)((t=0,r="(no messages)")=>{let n=eQ.current;if(x&&o&&n&&!td.current&&(td.current=!0,l)){if(l!==n){tf.current.set(l,n);let t=e.chatInputRef?.current;t?t.rekeyDraft(l,n):tY(l,n)}d?.({id:n,path:"",cwd:o,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:t,firstMessage:r,transient:!0},l)}},[x,o,l,d,e.chatInputRef]),tI=(0,i.useCallback)(async()=>{if(eQ.current||!x||!o)return eQ.current;if(ts.current)return ts.current;let e=(async()=>{let e=tc.current,t=tu.current;e&&ev(e);let r=(0,rY.xG)(en),n=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:o,type:"ensure_session",toolNames:r,...e?{provider:e.provider,modelId:e.modelId}:{},...t?{thinkingLevel:t}:{}})});if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.json(),l=i.sessionId;return eQ.current=l,i.model&&tc.current===e&&(ev(i.model),e||er(i.model)),i.thinkingLevel&&tu.current===t&&el(i.thinkingLevel),l})();ts.current=e;try{return await e}finally{ts.current=null}},[x,o,en]),tL=(0,i.useCallback)(async()=>{let e=eQ.current??await tI();if(!e)return;let t=await rJ(e,{type:"get_state"});tx.current&&eQ.current===e&&ep(t.systemPrompt??"")},[tI]),tE=(0,i.useCallback)(async()=>{let e=eQ.current??await tI();if(!e)return eW([]),[];e$(!0);try{let t=await rJ(e,{type:"get_commands"}),r=t?.commands??[];return eW(r),r}catch(e){return console.error("Failed to load slash commands:",e),eW([]),[]}finally{e$(!1)}},[tI]),tW=(0,i.useCallback)(()=>{eZ.current+=1,eG.current=!1,eX.current&&(clearTimeout(eX.current),eX.current=null)},[]),tz=(0,i.useCallback)(()=>{eY.current?.close()},[]),t$=(0,i.useCallback)(e=>eY.current.ensureConnected(e),[]),tP=(0,i.useCallback)(e=>{eY.current.maintain(e)},[]);(0,i.useEffect)(()=>{if(t?.id&&n)return tP(t.id),()=>{eQ.current!==t.id||e2.current||eG.current||e0.current===t.id&&e1.current||eY.current?.close()}},[tP,t?.id,n]);let tA=(0,i.useCallback)(async(e,t)=>{let r=eQ.current;if(eB(t=>t?.id===e.id?null:t),r)try{await rJ(r,{type:"extension_ui_response",id:e.id,...t})}catch(e){console.error("Failed to send extension UI response:",e)}},[]),tD=(0,i.useCallback)(async(e,t)=>{let r=eQ.current;if(r)try{await rJ(r,{type:"extension_ui_input",id:e.id,data:t})}catch(e){console.error("Failed to send extension custom UI input:",e)}},[]),tN=(0,i.useCallback)(e=>{let t=e.message.trim();t&&eA({type:"add",notice:{id:e.id??("u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`),message:t,type:e.type??"info"}})},[]),tF=(0,i.useCallback)(t=>{switch(rO(t)&&s?.(t),t.method){case"select":case"confirm":case"input":case"editor":eB(t);break;case"notify":tN({id:t.id,message:t.message,type:t.notifyType??"info"});break;case"setStatus":e_(e=>{let r=e.filter(e=>e.key!==t.statusKey);return void 0!==t.statusText?[...r,{key:t.statusKey,text:t.statusText}]:r});break;case"setWidget":eK(e=>{let r=e.filter(e=>e.key!==t.widgetKey);return t.widgetLines?[...r,{key:t.widgetKey,lines:t.widgetLines,placement:t.widgetPlacement??"aboveEditor"}]:r});break;case"setTitle":t.title&&(document.title=t.title);break;case"set_editor_text":e.chatInputRef?.current?.insertText(t.text);break;case"custom":eO(e=>t.closed?e?.id===t.id?null:e:t)}},[tN,s,e.chatInputRef]),tB=(0,i.useCallback)(()=>{let e=e2.current;return e2.current=!1,A(!1),eR(null),es(null),$({type:"end"}),e},[]),tH=(0,i.useCallback)(e=>e6.current!==e&&(e6.current=e,a?.(),!0),[a]),tO=(0,i.useCallback)(e=>{tW(),eG.current=!0;let t=eZ.current,r=async()=>{if(t===eZ.current&&eQ.current===e&&eG.current)try{let n=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.json();if(t!==eZ.current||eQ.current!==e||!eG.current)return;let o=i.state;if(i.running&&o&&(o.isStreaming||o.isPromptRunning)){eG.current=!1,eX.current=null,e8.current=!!o?.isStreaming,e4.current=!!o?.isPromptRunning,e2.current=!0,A(!0),eR(o?.isStreaming?{kind:"waiting_model"}:{kind:"running_command"});return}if(i.running&&o?.isCompacting){ew(!0),eX.current=setTimeout(()=>void r(),600);return}eG.current=!1,eX.current=null,tz()}catch{if(t!==eZ.current||eQ.current!==e||!eG.current)return;eX.current=setTimeout(()=>void r(),600)}};eX.current=setTimeout(()=>void r(),3e4)},[tW,tz]),tU=(0,i.useCallback)(async(e=eQ.current,t=tp.current)=>{if(tp.current===t)try{e&&await tC(e)}finally{if(tp.current!==t)return;let r=e4.current,n=e8.current;e4.current=!1,e8.current=!1,th.current=null;let i=tB();r?tH(t):n&&i&&a?.(),e&&tO(e)}},[tC,tH,a,tO,tB]),tV=(0,i.useCallback)(async(e,t)=>{await r7(800);let r=Date.now();for(;e2.current&&Date.now()-r<2e4;){if(void 0!==t&&tp.current!==t)return;try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(r.ok){let n=await r.json(),i=n.state;if(!n.running||!i||!i.isStreaming&&!i.isPromptRunning)return void await tU(e,t)}}catch{}await r7(600)}},[tU]),tX=(0,i.useCallback)(async e=>{let t=e3.current+1;for(e3.current=t;e5.current&&e3.current===t&&eQ.current===e;){await r7(1e3);try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)continue;let n=await r.json();if(n.state?.isBashRunning)continue;if(await tC(e),e3.current!==t||eQ.current!==e)return;e5.current=!1,N(!1),B(null);return}catch{}}},[tC]),tZ=(0,i.useCallback)(async e=>{if(!e2.current||eQ.current!==e)return;let t=tp.current;try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(!r.ok)return;let n=await r.json();if(eQ.current!==e||tp.current!==t)return;let i=n.state;if(ew(i?.isCompacting??!1),eJ(r3(i?.queuedMessages)),n.running&&i&&(i.isStreaming||i.isPromptRunning||i.isCompacting)){e8.current=!!i.isStreaming,e4.current=!!i.isPromptRunning;return}if(!e2.current)return;i&&(void 0!==i.contextUsage&&ec(i.contextUsage??null),void 0!==i.systemPrompt&&ep(i.systemPrompt??null),void 0!==i.extensionStatuses&&e_(i.extensionStatuses??[]),void 0!==i.extensionWidgets&&eK(i.extensionWidgets??[])),await tU(e,t)}catch{}},[tU]);(0,i.useEffect)(()=>{if(!P)return;let e=()=>{let e=eQ.current;e&&tZ(e)},t=()=>{"visible"===document.visibilityState&&e()},r=setInterval(e,15e3);return document.addEventListener("visibilitychange",t),window.addEventListener("online",e),()=>{clearInterval(r),document.removeEventListener("visibilitychange",t),window.removeEventListener("online",e)}},[P,tZ]),(0,i.useEffect)(()=>{e2.current=P},[P]),e7.current=(0,i.useCallback)(e=>{switch(e.type){case"connected":$({type:"end"}),!0===e.isStreaming&&(tW(),e8.current=!0,e2.current=!0,A(!0),eR({kind:"waiting_model"}));break;case"agent_start":tW(),e8.current=!0,e2.current=!0,A(!0),eR({kind:"waiting_model"}),$({type:"start"});break;case"agent_end":if(!e2.current)break;eR(null),es(null),$({type:"end"}),eQ.current&&(tC(eQ.current),fetch(`/api/agent/${encodeURIComponent(eQ.current)}`).then(e=>e.json()).then(e=>{e.state?.contextUsage!==void 0&&ec(e.state.contextUsage??null),e.state?.systemPrompt!==void 0&&ep(e.state.systemPrompt??null),e.state?.extensionStatuses!==void 0&&e_(e.state.extensionStatuses??[]),e.state?.extensionWidgets!==void 0&&eK(e.state.extensionWidgets??[]),eJ(r3(e.state?.queuedMessages))}).catch(()=>{}));break;case"agent_settled":{let e=e8.current;if(e8.current=!1,!e||e4.current)break;let t=eQ.current,r=tB();ew(!1),t&&(tC(t),tO(t)),r&&a?.();break}case"prompt_done":{let e=tp.current,t=e4.current;e4.current=!1,th.current=null;let r=tH(e);if(!t&&!r)break;let n=eQ.current;n&&tC(n),!e8.current&&(tB(),n&&tO(n))}break;case"prompt_error":tN({type:"error",message:e.errorMessage??"Command failed"});break;case"extension_error":tN({type:"error",message:e.error??"Extension command failed"});break;case"message_start":case"message_update":if(!e2.current)break;if("message_start"===e.type){let t=e.message;if(t?.role==="user")break;t?.role==="assistant"?($({type:"snapshot",message:t}),t.content.length>0&&eR(null)):t&&eR(null)}else{let t=e.assistantMessageEvent;t&&($({type:"delta",event:t}),"toolcall_start"!==t.type&&"toolcall_delta"!==t.type&&eR(null))}!tt.current&&tr.current&&null===ti.current&&(ti.current=requestAnimationFrame(()=>{ti.current=null,tr.current&&tv("auto")}));break;case"message_end":{if(!e2.current)break;let t=e.message;if(t&&"user"===t.role){let e=rq(t),r=rQ(e),n=th.current;th.current=null,R(t=>{let i=t[t.length-1];return n&&i?.role==="user"&&rQ(i)===n?n===r?t:[...t.slice(0,-1),e]:[...t,e]})}else t&&R(e=>[...e,rq(t)]);$({type:"end"}),eR({kind:"waiting_model"});break}case"tool_execution_start":{let t=e.toolCallId,r=e.toolName;eR(e=>{let n=e?.kind==="running_tools"?[...e.tools]:[];return n.some(e=>e.id===t)||n.push({id:t,name:r}),{kind:"running_tools",tools:n}});break}case"tool_execution_update":{let t=e.toolCallId,r=e.toolName,n=function(e){if(!r2(e))return null;let t=e.content;if(!Array.isArray(t))return null;let r=t.filter(e=>r2(e)&&"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n").split(/\r?\n/),n="";for(let e=r.length-1;e>=0&&!(n=r[e].trim());e-=1);if(!n)return null;let i=n.replace(/\s+/g," ");return i.length<=500?i:`...${i.slice(-497)}`}(e.partialResult);eR(e=>{let i=e?.kind==="running_tools"?[...e.tools]:[],o=i.find(e=>e.id===t),l={id:t,name:r||o?.name||"tool",progress:n??o?.progress};return{kind:"running_tools",tools:[...i.filter(e=>e.id!==t),l]}});break}case"tool_execution_end":{let t=e.toolCallId;eR(e=>{if(e?.kind!=="running_tools")return e;let r=e.tools.filter(e=>e.id!==t);return 0===r.length?{kind:"waiting_model"}:{kind:"running_tools",tools:r}});break}case"queue_update":eJ({steering:[...e.steering??[]],followUp:[...e.followUp??[]]});break;case"auto_retry_start":es({attempt:e.attempt,maxAttempts:e.maxAttempts,errorMessage:e.errorMessage});break;case"auto_retry_end":es(null);break;case"auto_compaction_start":case"compaction_start":ew(!0),eS(null),eT(null);break;case"auto_compaction_end":case"compaction_end":ew(!1),e.errorMessage?(eS(e.errorMessage),eT(null)):!e.aborted&&(eT(nt(e.result,e.reason??"auto")),eQ.current&&tC(eQ.current));break;case"extension_ui_request":tF(e)}},[tN,tW,tF,tC,tH,a,tO,tv,tB]);let tG=(0,i.useCallback)(async(e,r)=>{let n=e.trim();if(!n&&!r?.length)return;if(e2.current||e5.current)return void tj(e,r,tk);let i=!r?.length&&n.startsWith("/");if(!r?.length&&n.startsWith("!")){let t=n.startsWith("!!"),i=(t?n.slice(2):n.slice(1)).trim();return i?void await to.current?.(i,t):void tj(e,r,tk)}let l=tp.current+1;tW(),e4.current=!0;let a=r?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),s={role:"user",content:a?.length?[...e.trim()?[{type:"text",text:e}]:[],...a]:e,timestamp:Date.now()};R(e=>[...e,s]),th.current=rQ(s),tp.current=l,e2.current=!0,A(!0),eR(i?{kind:"running_command"}:{kind:"waiting_model"}),$({type:"start"}),tt.current=!0,eL(!0);let d=r?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),c=null,u=!1;try{if(x&&o){let t=eQ.current??await ts.current,r=t??await tI();if(!r)throw Error("Unable to create a session for the prompt");c=r,Q&&(ev(Q),t&&await rJ(r,{type:"set_model",provider:Q.provider,modelId:Q.modelId})),await t$(r),u=!0,await rJ(r,{type:"prompt",message:e,...d?.length?{images:d}:{}}),tR(1,e)}else if(t)c=t.id,await t$(t.id),u=!0,await rJ(t.id,{type:"prompt",message:e,...d?.length?{images:d}:{}});else throw Error("No active session for the prompt");i&&c&&tV(c,l)}catch(t){if(console.error("Failed to send message:",t),!(!u||rV(t))&&c)return void tV(c,l);if(e4.current=!1,R(e=>{let t=e.lastIndexOf(s);return -1===t?e:[...e.slice(0,t),...e.slice(t+1)]}),tN({type:"error",message:t instanceof Error?t.message:String(t)}),tj(e,r,tk),th.current=null,c)return void tZ(c);e2.current=!1,tz(),A(!1),eR(null),$({type:"end"})}},[x,o,Q,t,tI,t$,tR,tV,tN,tW,tz,tk,tZ,tj]);to.current=(0,i.useCallback)(async(e,r)=>{if(e2.current||e5.current)return;let n=`${r?"!!":"!"}${e}`;e5.current=!0,B({command:e,excludeFromContext:r}),N(!0);try{let i=eQ.current??t?.id??await tI();if(!i)throw Error("Unable to create a session for the shell command");await rJ(i,{type:"bash",command:e,excludeFromContext:r}),await tC(i),tR(1,n)}catch(e){console.error("Failed to execute shell command:",e),tN({type:"error",message:e instanceof Error?e.message:String(e)}),tj(n,void 0,tk)}finally{e5.current=!1,B(null),N(!1)}},[tN,tk,tI,tC,tR,tj,t]);let tQ=(0,i.useCallback)(async()=>{let e=eQ.current;if(e){if(e5.current){try{await rJ(e,{type:"abort_bash"})}catch(e){console.error("Failed to abort bash:",e)}return}try{await rJ(e,{type:"abort"})}catch(e){console.error("Failed to abort:",e)}}},[]),t0=(0,i.useCallback)(async e=>{if(e5.current)return;let t=eQ.current;if(t){eg(e);try{let{cancelled:r,newSessionId:n}=await rJ(t,{type:"fork",entryId:e})??{};!r&&n&&c?.(n)}catch(e){console.error("Fork failed:",e)}finally{eg(null)}}},[c]),t1=(0,i.useCallback)(async e=>{if(e5.current)return;let t=eQ.current;t&&(rJ(t,{type:"navigate_tree",targetId:e}).catch(()=>{}),S(e),await tT(t,e))},[tT]),t2=(0,i.useCallback)(async e=>{if(e5.current)return;S(e);let t=eQ.current;t&&(await tT(t,e),e&&rJ(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[tT]),t8=(0,i.useCallback)(async(e,t)=>{if(x){let r={provider:e,modelId:t};tc.current=r,ee(r),ev(r);let n=eQ.current??await ts.current;if(!n)return;try{await rJ(n,{type:"set_model",provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}return}let r=eQ.current;if(r&&!tg.current){tg.current=!0,ex({provider:e,modelId:t}),ey(!0);try{await rJ(r,{type:"set_model",provider:e,modelId:t}),tg.current=!1,await tC(r)}catch(e){console.error("Failed to set model:",e),tg.current=!1,ex(ef),tN({type:"error",message:`Failed to switch model: ${e instanceof Error?e.message:String(e)}`}),await tC(r)}finally{tg.current=!1,ey(!1)}}},[tN,ef,x,tC,ee]),t4=(0,i.useCallback)(async()=>{let e=eQ.current;if(e&&!ek){ew(!0),eS(null),eT(null);try{let t=await rJ(e,{type:"compact"});eT(nt(t,"manual")),await tC(e,!0)}catch(e){eS(e instanceof Error?e.message:String(e)),eT(null)}finally{ew(!1)}}},[ek,tC]),t6=(0,i.useCallback)(async e=>{let r=o??t?.cwd??"",n=r?`/api/models?cwd=${encodeURIComponent(r)}`:"/api/models",i=await fetch(n,e?{signal:e}:void 0);if(!i.ok)throw Error(`HTTP ${i.status}`);let l=await i.json();O(l.models),K(l.modelError??null),J(l.modelScopeWarnings??[]),X(l.thinkingLevels??{}),G(l.thinkingLevelMaps??{});let a=l.modelList??[];if(_(a),x&&!eQ.current){let e=(l.defaultModel?a.find(e=>e.id===l.defaultModel?.modelId&&e.provider===l.defaultModel?.provider):void 0)??a[0];er(e?{provider:e.provider,modelId:e.id}:null);let t=e&&l.thinkingLevelPins?.[`${e.provider}/${e.id}`];null===tu.current&&el(t??"auto")}},[x,o,t?.cwd]),t5=(0,i.useCallback)(async e=>{if(!e.startsWith("/"))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,r,n=""]=t,i=n.trim(),o=eQ.current??await tI(),l=e=>(e.handled&&(e.error?tN({type:"error",message:e.error}):"openSessionStats"!==e.action&&tN({type:"success",message:e.message??"Command completed"})),e);try{switch(r){case"compact":{if(!o||ek)return l({handled:!0,error:"No active session to compact"});ew(!0),eS(null),eT(null);let e=await rJ(o,{type:"compact",...i?{customInstructions:i}:{}});return eT(nt(e,"manual")),await tC(o,!0)&&tR(),l({handled:!0,message:"Compacted context"})}case"reload":if(!o)return l({handled:!0,error:"No active session to reload"});return await rJ(o,{type:"reload"}),await Promise.all([tC(o,!1,!0),tM(o),tE(),t6()]),l({handled:!0,message:"Reloaded session resources"});case"name":if(!o)return l({handled:!0,error:"No active session to name"});if(!i)return l({handled:!0,error:"Usage: /name <name>"});return await rJ(o,{type:"set_session_name",name:i}),await tC(o)&&tR(),l({handled:!0,message:`Session renamed to ${i}`});case"session":{if(!o)return l({handled:!0,error:"No active session"});let e=await rJ(o,{type:"get_session_stats"});return e&&eN(e),f?.(),l({handled:!0,action:"openSessionStats"})}case"copy":{if(!o)return l({handled:!0,error:"No active session"});let e=await rJ(o,{type:"get_last_assistant_text"}),t=e?.text??"";if(!t)return l({handled:!0,error:"No assistant message to copy"});return await navigator.clipboard.writeText(t),l({handled:!0,message:"Copied last assistant message"})}default:return{handled:!1}}}catch(e){return l({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{"compact"===r&&ew(!1)}},[tN,tI,ek,t6,tC,tE,tM,tR,f]),t3=(0,i.useCallback)(async(e,t,r)=>{let n=eQ.current;if(!n){tj(e,r,tk),tN({type:"error",message:"No active session for the queued message"});return}let i=r?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));try{await rJ(n,{type:"prompt",message:e,streamingBehavior:t,...i?.length?{images:i}:{}})}catch(t){console.error("Failed to submit streaming prompt:",t),rV(t)&&tj(e,r,tk),tN({type:"error",message:t instanceof Error?t.message:String(t)})}},[tN,tk,tj]),t7=(0,i.useCallback)(async(e,t)=>{await t3(e,"steer",t)},[t3]),t9=(0,i.useCallback)(async(e,t,r)=>{await t3(e,t,r)},[t3]),re=(0,i.useCallback)(async(e,t)=>{await t3(e,"followUp",t)},[t3]),rt=(0,i.useCallback)(async()=>{let e=eQ.current;if(e)try{await rJ(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),rr=(0,i.useCallback)(async()=>{let t=eQ.current;if(t)try{let r=await rJ(t,{type:"clear_queue"});eJ({steering:[],followUp:[]});let n=[...r?.steering??[],...r?.followUp??[]];n.length>0&&e.chatInputRef?.current?.prependText(n.join("\n\n"))}catch(e){console.error("Failed to recall queued messages:",e),tN({type:"error",message:"Failed to recall queued messages"})}},[e.chatInputRef,tN]),rn=(0,i.useCallback)(async e=>{if(el(e),x&&!eQ.current&&(tu.current="auto"===e?null:e),"auto"===e)return;let t=eQ.current??await ts.current;if(t)try{await rJ(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[x]),ri=(0,i.useCallback)(async e=>{let t=(0,rY.xG)(e);!function(e,t=rZ()){if(t)try{t.setItem(rX,e)}catch{}}(e),tm(e);let r=eQ.current??await ts.current;if(r)try{await rJ(r,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[tm]),ro=(0,i.useCallback)(()=>{let e=ta.current,t=te.current;if(!e||!t)return;let r=Math.min(Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop-16),Math.max(0,e.scrollHeight-e.clientHeight));null!==ti.current&&(cancelAnimationFrame(ti.current),ti.current=null),tr.current=!0,tn.current=r,e.scrollTo({top:r,behavior:"auto"})},[]),rl=(0,i.useCallback)(()=>{let e=ta.current;if(e){let{scrollTop:t,clientHeight:r,scrollHeight:n}=e,i=e2.current,o=tr.current,l=function(e,t,r,n,i,o=96){return!!r8(r,n,i)||!(r<t)&&(!!(!e&&r>t&&r8(r,n,i,o))||e)}(o,tn.current,t,r,n,i?96:8);tr.current=l,tn.current=t,!o&&l&&i?tv("auto"):l||null===ti.current||(cancelAnimationFrame(ti.current),ti.current=null)}},[tv]);return(0,i.useEffect)(()=>(tx.current=!0,t&&(eQ.current=t.id,tC(t.id,!0,!0).then(e=>{e?.running&&(tM(t.id),(e.state?.isStreaming||e.state?.isPromptRunning)&&(e8.current=!!e.state.isStreaming,e4.current=!!e.state.isPromptRunning,e2.current=!0,A(!0),eR(e.state.isStreaming?{kind:"waiting_model"}:{kind:"running_command"}),$({type:"start"}),tP(t.id),!e.state.isStreaming&&e.state.isPromptRunning&&tV(t.id)),e.state?.isBashRunning&&(e5.current=!0,N(!0),tX(t.id))),e?.state&&(void 0!==e.state.isCompacting&&ew(e.state.isCompacting),void 0!==e.state.contextUsage&&ec(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&ep(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&el(e.state.thinkingLevel??"auto"),void 0!==e.state.extensionStatuses&&e_(e.state.extensionStatuses??[]),void 0!==e.state.extensionWidgets&&eK(e.state.extensionWidgets??[]),void 0!==e.state.queuedMessages&&eJ(r3(e.state.queuedMessages)))})),()=>{tx.current=!1;let e=x?l:null;e&&queueMicrotask(()=>{tx.current||td.current||tK(e)}),null!==ti.current&&(cancelAnimationFrame(ti.current),ti.current=null),e3.current+=1,tW(),tz()}),[]),(0,i.useEffect)(()=>{h?.(eu)},[eu,h]),(0,i.useEffect)(()=>(g?.(tL),()=>g?.(null)),[tL,g]),(0,i.useEffect)(()=>{p&&p(m?.tree??[],j,t2)},[m?.tree,j,t2,p]),(0,i.useEffect)(()=>{let e=ta.current;if(e)return tn.current=e.scrollTop,e.addEventListener("scroll",rl,{passive:!0}),()=>{e.removeEventListener("scroll",rl)}},[M.length,b,rl]),(0,i.useEffect)(()=>{P||eL(!1)},[P]),(0,i.useLayoutEffect)(()=>{M.length>0&&(tt.current?(tt.current=!1,e9.current=!0,ro()):e9.current?!e2.current&&tr.current&&tv("auto"):(e9.current=!0,tv("instant")))},[M.length,P,tv,ro]),(0,i.useEffect)(()=>{let e=new AbortController;return t6(e.signal).catch(e=>{if(e instanceof DOMException&&"AbortError"===e.name)return}),()=>e.abort()},[t6,u]),(0,i.useEffect)(()=>{if(!eC)return;let e=setTimeout(()=>eT(null),6e3);return()=>clearTimeout(e)},[eC]),(0,i.useEffect)(()=>{if(0===eP.visible.length)return;let e=eP.visible.find(e=>e.exiting);if(e){let t=setTimeout(()=>{eA({type:"remove",id:e.id})},180);return()=>clearTimeout(t)}if(!eP.visible[0])return;let t=setTimeout(()=>{eA({type:"mark_oldest_exiting"})},5e3);return()=>clearTimeout(t)},[eP.visible]),(0,i.useEffect)(()=>{eN(null)},[M.length,ed?.tokens,ed?.percent,ed?.contextWindow]),{data:m,loading:b,error:k,activeLeafId:j,messages:M,entryIds:I,todos:E,streamState:z,agentRunning:P,modelNames:H,modelList:U,modelError:q,modelScopeWarnings:V,modelThinkingLevels:Y,modelThinkingLevelMaps:Z,newSessionModel:Q,toolPreset:en,thinkingLevel:eo,retryInfo:ea,contextUsage:ed,systemPrompt:eu,forkingEntryId:eh,isCompacting:ek,compactError:ej,compactResult:eC,currentModel:tb,displayModel:ty,modelSwitching:eb,sessionStats:tS,slashCommands:eE,slashCommandsLoading:ez,queuedMessages:eV,notices:eP.visible,extensionDialog:eF,extensionCustomUi:eH,extensionStatuses:eU,extensionWidgets:eq,respondToExtensionUi:tA,sendExtensionCustomInput:tD,isAutoModelSelection:x&&null===Q,agentPhase:eM,isNew:x,promptAnchorActive:eI,sessionIdRef:eQ,messagesEndRef:tl,scrollContainerRef:ta,lastUserMsgRef:te,pendingScrollToUserRef:tt,initialScrollDoneRef:e9,handleSend:tG,handleAbort:tQ,handleFork:t0,handleNavigate:t1,handleModelChange:t8,handleCompact:t4,handleSteer:t7,handleFollowUp:re,handlePromptWithStreamingBehavior:t9,handleAbortCompaction:rt,handleRecallQueue:rr,handleBuiltinSlashCommand:t5,handleToolPresetChange:ri,handleThinkingLevelChange:rn,loadTools:tM,loadSlashCommands:tE,setActiveLeafId:S,setData:v,setMessages:R,loadContext:tT,scrollToBottom:tv,scrollUserMsgToTop:ro,hasOlderChat:C,dispatch:$,setAgentRunning:A,setForkingEntryId:eg,bashRunning:D,pendingBash:F,handleAgentEventRef:e7}}({session:e,sessionRunning:t,newSessionCwd:o,newSessionDraftKey:l,onAgentEnd:A,onAttentionNeeded:d,onSessionCreated:c,onSessionForked:u,modelsRefreshKey:p,chatInputRef:h,onBranchDataChange:g,onSystemPromptChange:f,onSystemPromptLoaderChange:x,onSessionStatsPanelOpen:v}),e0=U||_;(0,i.useEffect)(()=>{eg&&P.current!==eg.id&&(P.current=eg.id,z.current())},[eg]),(0,i.useEffect)(()=>{s=e0?eP:null},[e0,eP]);let[e1,e2]=(0,i.useState)(50),e8=(0,i.useRef)(null),e4=(0,i.useRef)(null),e6=(0,i.useRef)(!1),[e5,e3]=(0,i.useState)(!0),[e7,e9]=(0,i.useState)([]),te=(0,i.useRef)(0),tt=(0,i.useCallback)((e,t,r)=>{let n=window.innerWidth,i=window.innerHeight,o=Math.min(300,Math.max(240,n-40)),l=Math.min(500,Math.max(200,i-60)),a=te.current%8*22;te.current+=1,e9(s=>[...s,{id:`pin-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,message:e,entryId:t,x:Math.max(0,n-o-20-a),y:Math.min(Math.max(0,r??16),Math.max(0,i-l)),w:o,h:l}])},[]),tr=(0,i.useCallback)(e=>{e9(t=>t.filter(t=>t.id!==e))},[]),tn=(0,i.useCallback)((e,t)=>{e9(r=>r.map(r=>r.id===e?{...r,...t}:r))},[]),ti=(0,i.useCallback)(e=>{e9(t=>{if(t.length<=1)return t;let r=t.findIndex(t=>t.id===e);if(-1===r||r===t.length-1)return t;let n=[...t],[i]=n.splice(r,1);return n.push(i),n})},[]);(0,i.useEffect)(()=>{let t=e8.current,r=eE.current;if(!t||!r)return;let n=new IntersectionObserver(t=>{if(!t[0]?.isIntersecting||e6.current)return;let n=H[0];if(!n)return;let i=e?.id??eM.current;i&&(e6.current=!0,e4.current=r.scrollHeight-r.scrollTop,eZ(i,eG,n).finally(()=>{e6.current=!1}))},{root:r,threshold:0});return n.observe(t),()=>n.disconnect()},[H,e,eG,eZ,eM,eE]),(0,i.useEffect)(()=>{e2(e=>Math.max(e,B.length))},[B.length]),(0,i.useEffect)(()=>{if(null==e4.current)return;let e=eE.current;if(e){var t;t=e.scrollHeight,e.scrollTop=Math.max(0,t-e4.current),e4.current=null}},[e1,eE]);let to=es?[es.sessionId,es.sessionFile??"",es.sessionName??"",es.userMessages,es.assistantMessages,es.toolCalls,es.toolResults,es.totalMessages,es.tokens.input,es.tokens.output,es.tokens.cacheRead,es.tokens.cacheWrite,es.tokens.total,es.cost??0,es.totalActiveMs??0].join("|"):null,tl=(0,i.useRef)(es);tl.current=es,(0,i.useEffect)(()=>{m?.(tl.current)},[to,m]),(0,i.useEffect)(()=>()=>{m?.(null)},[m]);let ta=(0,i.useRef)(ed);ta.current=ed;let ts=ed.map(e=>e.id??e.content).join("\0");(0,i.useEffect)(()=>{y?.(ta.current)},[ts,y]),(0,i.useEffect)(()=>()=>{y?.([])},[y]);let td=et?`${et.percent??"null"}|${et.contextWindow}|${et.tokens??"null"}`:null,tc=(0,i.useRef)(et);tc.current=et,(0,i.useEffect)(()=>{k?.(tc.current)},[td,k]),(0,i.useEffect)(()=>()=>{k?.(null)},[k]);let{isDragOver:tu,handleDragEnter:tp,handleDragOver:th,handleDragLeave:tg,handleDrop:tf}=function(e){let[t,r]=(0,i.useState)(!1),n=(0,i.useRef)(0),o=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&(e.preventDefault(),n.current+=1,r(!0))},[]),l=(0,i.useCallback)(e=>{Array.from(e.dataTransfer.items).some(e=>e.type.startsWith("image/"))&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:o,handleDragOver:l,handleDragLeave:(0,i.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,i.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files))},[e])}}((0,i.useCallback)(e=>{h?.current?.addImages(e)},[h])),tx=B.filter(e=>"user"===e.role||"assistant"===e.role),tm=(0,i.useMemo)(()=>{let e=new Map;for(let t of B)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[B]),tb=(0,i.useMemo)(()=>{let e=new Set,t=[];for(let r=B.length-1;r>=0;r-=1){let n=function(e){if("user"!==e.role)return null;if("string"==typeof e.content){let t=e.content.trim();return t.length>0?t:null}let t=e.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n").trim();return t.length>0?t:null}(B[r]);if(!(!n||e.has(n))&&(e.add(n),t.push(n),t.length>=50))break}return t.reverse()},[B]),ty=(I=tx.length,(L=(0,i.useRef)([])).current=Array(I).fill(null).map((e,t)=>L.current[t]??null),L),tk=(0,i.useCallback)(()=>{e2(e=>Math.max(e,2*B.length))},[B.length]),tw=eT&&0===B.length&&!O.isStreaming&&!e0,tj=!!O.streamingMessage?.content.length,tS=e?.cwd??o??void 0,tC=(0,i.useRef)(null),tT=(0,i.useRef)(null),tM=(0,i.useRef)(0),tR=(0,i.useRef)(null),tI=(0,i.useRef)(!1),tL=(0,i.useRef)(null);(0,i.useLayoutEffect)(()=>{let e=tT.current;if(!U||!ez){tL.current=null,tM.current=0,tI.current=!1,e&&(e.style.height="");return}let t=eE.current,r=tC.current,n=eW.current;if(!t||!r||!n||!e)return;let i=!1,o=()=>{var o;let l;if(i||eE.current!==t||tC.current!==r||eW.current!==n||tT.current!==e)return;let a=t.getBoundingClientRect().top,s=Math.max(0,n.getBoundingClientRect().top-a+t.scrollTop-16),d=e.getBoundingClientRect().top-a+t.scrollTop,c=(o=t.clientHeight,0===(l=Math.max(0,s))?0:Math.max(0,Math.ceil(l+o-Math.max(0,d)))),u=!tI.current;u&&(tI.current=!0),c!==tM.current&&(tM.current=c,e.style.height=c>0?`${c}px`:"",u&&c>0&&eY())};tL.current=o,o();let l="u"<typeof ResizeObserver?null:new ResizeObserver(()=>{i||null!==tR.current||(tR.current=requestAnimationFrame(()=>{tR.current=null,o()}))});return l?.observe(t),l?.observe(r),l?.observe(n),()=>{i=!0,tL.current===o&&(tL.current=null),l?.disconnect(),null!==tR.current&&(cancelAnimationFrame(tR.current),tR.current=null)}},[U,eW,B.length,ez,eE,eY]),(0,i.useLayoutEffect)(()=>{tL.current?.()},[O.streamingMessage]);let tE=el?X[`${el.provider}:${el.modelId}`]??null:null,tW=el?Z[`${el.provider}:${el.modelId}`]??null:null,tz=(0,n.jsxs)("button",{type:"button",id:"terminal-bottombar-btn",onClick:R,title:E("terminal.title"),"aria-label":E("terminal.title"),"aria-expanded":M,className:`terminal-bar-toggle${M?" is-open":""}`,children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),(0,n.jsx)("span",{children:E("terminal.title")})]}),t$=(0,n.jsx)(rL,{ref:h,onSend:e$,onAbort:eP,onSteer:U?eB:void 0,onFollowUp:U?eH:void 0,onPromptWithStreamingBehavior:U?eO:void 0,isStreaming:e0,model:el,isAutoModelSelection:ey,modelNames:K,modelList:V,modelError:J,modelScopeWarnings:Y,onModelChange:eN,modelSwitching:ea,onCompact:e||eT?eF:void 0,onAbortCompaction:eU,isCompacting:en,compactError:ei,compactResult:eo,toolPreset:G,onToolPresetChange:e||eT?eK:void 0,thinkingLevel:Q,onThinkingLevelChange:e||eT?eV:void 0,availableThinkingLevels:tE,thinkingLevelMap:tW,retryInfo:ee,queuedMessages:ep,inputHistory:tb,onRecallQueue:e_,slashCommands:ec,slashCommandsLoading:eu,onLoadSlashCommands:eJ,onBuiltinCommand:eq,soundEnabled:j,onSoundToggle:S,onAudioUnlock:T,draftKey:e?.id??l??void 0,cwd:e?.cwd??o,atBottom:e5,onScrollToBottom:eX});return N?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:E("chat.loadingSession")}):F?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:F}):(0,n.jsxs)("div",{className:"relative flex h-full min-w-0 flex-col overflow-hidden",style:{paddingBottom:"env(safe-area-inset-bottom)"},onDragEnter:tp,onDragOver:th,onDragLeave:tg,onDrop:tf,children:[tu&&(0,n.jsxs)("div",{className:"pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[rgba(37,99,235,0.06)] backdrop-blur-[1px]",children:[(0,n.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(e=>(0,n.jsx)("div",{className:"absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[rgba(37,99,235,0.5)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]",style:{transformOrigin:"center",animationDelay:`${e}s`}},e))}),(0,n.jsxs)("svg",{width:"280",height:"280",viewBox:"0 0 140 140",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"drop-shadow-[0_6px_18px_rgba(37,99,235,0.18)]",children:[(0,n.jsx)("rect",{x:"28",y:"44",width:"84",height:"60",rx:"8",fill:"rgba(37,99,235,0.08)",stroke:"rgba(37,99,235,0.50)",strokeWidth:"1.8"}),(0,n.jsx)("path",{d:"M36 100 L54 72 L68 88 L80 74 L104 100Z",fill:"rgba(37,99,235,0.16)",stroke:"rgba(37,99,235,0.40)",strokeWidth:"1.4",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"96",cy:"58",r:"8",fill:"rgba(37,99,235,0.22)",stroke:"rgba(37,99,235,0.55)",strokeWidth:"1.6"}),(0,n.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,n.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,n.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,n.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,n.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,n.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,n.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,n.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),eg&&(0,n.jsx)(ns,{request:eg,onRespond:ev}),ef&&(0,n.jsx)(nd,{request:ef,onInput:eb}),W?(0,n.jsx)("div",{style:{position:"fixed",left:"50%",top:60,transform:"translateX(-50%)",zIndex:250,display:"flex",flexDirection:"column",alignItems:"center",maxWidth:"calc(100vw - 32px)",overflowY:"auto",pointerEvents:"none"},children:(0,n.jsx)(na,{notices:eh,floating:!0})}):(0,n.jsx)("div",{style:{position:"fixed",right:51,bottom:118,zIndex:250,display:"flex",flexDirection:"column",alignItems:"flex-end",maxWidth:"min(100vw - 48px, 340px)",maxHeight:"calc(100dvh - 220px)",overflowY:"auto",pointerEvents:"none"},children:(0,n.jsx)(na,{notices:eh})}),tw?(0,n.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-8",children:(0,n.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,n.jsxs)("div",{className:"mb-3",style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,marginLeft:16,marginRight:W?16:52,fontFamily:"var(--font-mono)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:W?7:10,minWidth:0,flex:1,lineHeight:1.4,overflow:"hidden"},children:[(0,n.jsx)("span",{style:{fontSize:34,fontWeight:700,letterSpacing:0,color:"#ffffff",mixBlendMode:"exclusion",flexShrink:0,whiteSpace:"nowrap"},children:"π"}),(0,n.jsx)("span",{style:{fontSize:28,color:"#ffffff",fontWeight:700,letterSpacing:0,mixBlendMode:"exclusion",flexShrink:0,whiteSpace:"nowrap"},children:"Pi Web"}),(0,n.jsx)(nr,{label:e=>E("appUpdate.releaseNotes",{version:e})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:2,flexShrink:0,mixBlendMode:"exclusion"},children:[(0,n.jsxs)("span",{style:{fontSize:12,color:"#ffffff",fontWeight:700},children:["web ",(0,n.jsxs)("span",{style:{color:"#ffffff",fontWeight:700},children:["v","0.1.22"]})]}),(0,n.jsxs)("span",{style:{fontSize:12,color:"#ffffff",fontWeight:700},children:["pi ",(0,n.jsxs)("span",{style:{color:"#ffffff",fontWeight:700},children:["v","0.84.2"]})]})]})]}),t$,(0,n.jsx)(rB,{statuses:ex,widgets:em,tools:tz})]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex min-w-0 flex-1 overflow-hidden",children:[(0,n.jsx)("div",{ref:eE,className:"min-w-0 flex-1 overflow-x-hidden overflow-y-auto pt-4 pb-[4px] mb-[4px] [scrollbar-width:none]",onScroll:e=>{let t=e.currentTarget;e3(r8(t.scrollTop,t.clientHeight,t.scrollHeight))},children:(0,n.jsx)("div",{style:{minWidth:0,padding:"0 16px"},children:(0,n.jsxs)("div",{ref:tC,style:{width:"100%",minWidth:0,maxWidth:820,margin:"0 auto"},children:[(()=>{var t;let r,i,o=-1;for(let e=B.length-1;e>=0;e--)if("user"===B[e].role){o=e;break}let l=-1;for(let e=B.length-1;e>=0;e--)if(nn(B[e])){l=e;break}let a=new Map,s=0;B.forEach((e,t)=>{("user"===e.role||"assistant"===e.role)&&a.set(t,s++)});let d=(t,r={})=>{let i=r.messageOverride??B[t],l="user"===i.role&&t>0&&"assistant"===B[t-1].role?H[t-1]:void 0,s="user"===i.role||"assistant"===i.role,d=a.get(t),c=r.keyPrefix??"message",u=!1;if("assistant"===i.role){u=!0;for(let e=t+1;e<B.length;e++){let t=B[e].role;if("user"===t)break;if("assistant"===t){u=!1;break}}u&&O.isStreaming&&t===B.length-1&&(u=!1)}void 0!==r.showTimestamp&&(u=r.showTimestamp);let p=(0,n.jsx)(tv,{message:i,toolResults:tm,modelNames:K,cwd:tS,onOpenFile:w,entryId:H[t],onFork:e0||eT||0===t&&"user"===i.role?void 0:eA,forking:er===H[t],onNavigate:e0?void 0:eD,prevAssistantEntryId:e0?void 0:l,onEditContent:D,onPin:tt,showTimestamp:u,prevTimestamp:t>0?B[t-1].timestamp:void 0,sessionId:e?.id??eM.current??void 0,writtenFiles:r.writtenFiles},`${c}-view-${t}`);return s&&!1!==r.attachRef&&void 0!==d?(0,n.jsx)("div",{ref:e=>{ty.current[d]=e,t===o&&(eW.current=e)},children:p},`${c}-${t}`):p},c=[];for(let e=0;e<B.length;){if(!nn(B[e])){c.push(d(e)),e+=1;continue}let t=e,r=t+1;for(;r<B.length&&!nn(B[r]);)r+=1;let i=function(e,t,r){for(let i=r-1;i>t;i--){var n;if("assistant"===(n=e[i]).role&&eS(n).answerBlocks.some(e=>"image"===e.type||"text"===e.type&&e.text.trim().length>0))return i}for(let n=r-1;n>t;n--)if(e[n]?.role==="assistant")return n;return -1}(B,t,r);if(-1===i||(e0||O.isStreaming)&&r===B.length&&t===l){for(let e=t;e<r;e++)c.push(d(e));e=r;continue}c.push(d(t));let o=[];for(let e=t+1;e<i;e++)o.push(e);let s=o.filter(e=>{var t;return"assistant"===(t=B[e]).role?ew(t).length>0:"custom"===t.role}),u=B[i],p=eS(u),h=p.processBlocks.length>0?ni(u,p.processBlocks,{omitUsage:!0}):null,g=p.answerBlocks.length>0||ej(u)?ni(u,p.answerBlocks):null,f=s.length+ +!!h;if(f>0){let e=s.map(e=>a.get(e)).find(e=>"number"==typeof e)??(g?void 0:a.get(i)),r=(0,n.jsxs)(no,{messageCount:f,defaultExpanded:!g,t:E,toolCallCount:function(e,t){let r=0;for(let n of t){let t=e[n];t?.role==="assistant"&&(r+=eC(ew(t)))}return r}(B,s)+eC(p.processBlocks),children:[s.map(e=>d(e,{attachRef:!1,keyPrefix:"process"})),h&&d(i,{attachRef:!1,keyPrefix:"process-final",messageOverride:h,showTimestamp:!1})]});c.push((0,n.jsx)("div",{ref:void 0===e?void 0:t=>{ty.current[e]=t},children:r},`process-group-${t}-${i}`))}if(g){let e=[];for(let r=t+1;r<=i;r++){let t=B[r];if(t?.role==="assistant")for(let r of t.content??[])e.push(r)}let r=function(e,t,r){let n=new Set,i=[];for(let o of e){if("toolCall"!==o.type||!function(e){let t;return"write"===(t=e.toLowerCase())||t.startsWith("write_")||t.endsWith(".write")||t.endsWith("_write")||eL(e)}(o.toolName))continue;let e=t?.get(o.toolCallId);if(!e||e.isError)continue;let l=function(e){if(!e)return null;let t=e.file_path??e.path;return"string"==typeof t&&t.length>0?t:null}(o.input);if(!l)continue;let a=function(e,t){let r;if(!e)return null;let n=/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")||void 0!==t&&(/^[a-zA-Z]:[\\/]/.test(t)||t.startsWith("\\\\")),i=e=>n?e.replace(/\\/g,"/"):e,o=i(e),l=t?i(t).replace(/\/+$/,""):void 0,a=/^[a-zA-Z]:\//.test(o),s=o.startsWith("//");if(a||s)r=o;else if(o.startsWith("/")){let e=l?.match(/^([a-zA-Z]:)(?:\/|$)/)?.[1]??l?.match(/^(\/\/[^/]+\/[^/]+)(?:\/|$)/)?.[1];r=e?`${e}${o}`:o}else{if(!l)return null;r=`${l}/${o}`}return eR(r)}(l,r);a&&(n.has(a)||(n.add(a),i.push({filePath:a})))}return i}(e,tm,tS);c.push(d(i,{messageOverride:g,writtenFiles:r}))}for(let e=i+1;e<r;e++)c.push(d(e));e=r}let{startIndex:u}=(r=Math.min(Math.max(e1,0),Math.max(t=c.length,0)),{startIndex:i=Math.max(0,t-r),hasMore:i>0}),p=u>0||eQ;return(0,n.jsxs)(n.Fragment,{children:[p&&(0,n.jsx)("div",{ref:e8,className:"py-3 text-center text-xs text-text-muted",children:E("chat.loadEarlier",{count:u})}),c.slice(u)]})})(),O.isStreaming&&tj&&O.streamingMessage&&(0,n.jsx)(tv,{message:O.streamingMessage,isStreaming:!0,modelNames:K,cwd:tS,onOpenFile:w}),U&&!tj&&ek&&(0,n.jsx)("div",{className:"break-words py-2 text-[13px]",style:{color:"#ffffff",mixBlendMode:"exclusion"},children:(0,n.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:function(e,t){if(e?.kind==="running_tools"){let r=e.tools[e.tools.length-1];if(r?.progress)return`${t("chat.runningNamedTool",{name:r.name})} ${r.progress}`;let n=e.tools.map(e=>e.name);return 0===n.length?t("chat.runningTool"):1===n.length?t("chat.runningNamedTool",{name:n[0]}):n.length<=3?t("chat.runningTools",{names:n.join(", ")}):t("chat.runningToolsMore",{names:n.slice(0,2).join(", "),count:n.length-2})}return e?.kind==="waiting_model"?t("chat.waitingModel"):e?.kind==="running_command"?t("chat.runningCommand"):null}(ek,E)})}),_&&!q&&(0,n.jsx)("div",{className:"py-2 text-[13px]",style:{color:"#ffffff",mixBlendMode:"exclusion"},children:(0,n.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:E("chat.runningCommand")})}),q&&(0,n.jsx)(tv,{message:{role:"bashExecution",command:q.command,output:"",excludeFromContext:q.excludeFromContext},sessionId:e?.id??eM.current??void 0}),(0,n.jsx)("div",{ref:tT,"aria-hidden":"true"}),(0,n.jsx)("div",{ref:eI})]})})}),W?null:(0,n.jsx)(rN,{messages:B,streamingMessage:O.streamingMessage,scrollContainer:eE,messageRefs:ty,onRevealHistory:tk})]}),(0,n.jsxs)("div",{className:"relative",children:[t$,(0,n.jsx)(rB,{statuses:ex,widgets:em,tools:tz})]})]}),e7.map((t,r)=>(0,n.jsx)(tN,{item:t,render:{toolResults:tm,modelNames:K,cwd:tS,sessionId:e?.id??eM.current??void 0,entryId:t.entryId,onOpenFile:w},zIndex:3e3+r,active:r===e7.length-1,onClose:tr,onActivate:ti,onMove:tn},t.id))]})}function na({notices:e,floating:t}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",alignItems:t?"center":"flex-end",gap:6,padding:t?"0 16px":0},children:e.map(e=>{let r="error"===e.type?"#ef4444":"warning"===e.type?"#d97706":"success"===e.type?"#10b981":"var(--accent)";return(0,n.jsxs)("div",{className:"notice-shelf-item",style:{display:"flex",alignItems:"center",gap:8,overflow:"hidden",borderRadius:8,border:"1px solid color-mix(in srgb, var(--border) 45%, transparent)",background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))",color:"var(--text)",width:300,boxShadow:"0 2px 12px -4px rgba(15,23,42,0.16)",fontSize:12.5,lineHeight:1.55,transformOrigin:t?"top center":"bottom right",animation:e.exiting?"notice-shelf-out 0.18s ease-in forwards":"notice-shelf-in 0.18s ease-out both",padding:"8px 12px",pointerEvents:"auto"},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:5,height:5,borderRadius:"50%",background:r}}),(0,n.jsx)("span",{className:"notice-shelf-text",style:{minWidth:0,flex:1,wordBreak:"break-word",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:e.message})]},e.id)})})}function ns({request:e,onRespond:t}){let{t:r}=(0,b.s)(),[o,l]=(0,i.useState)("editor"===e.method?e.prefill??"":"");(0,i.useEffect)(()=>{l("editor"===e.method?e.prefill??"":"")},[e]);let a=()=>{"confirm"===e.method?t(e,{confirmed:!0}):t(e,{value:o})};return(0,n.jsx)("div",{style:{position:"absolute",inset:0,zIndex:90,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",style:{width:"min(560px, 100%)",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:650},children:e.title}),(0,n.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:r("chat.extensionRequest")})]}),(0,n.jsxs)("div",{style:{padding:14},children:["confirm"===e.method&&(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontSize:13,lineHeight:1.6,whiteSpace:"pre-wrap"},children:e.message}),"select"===e.method&&(0,n.jsx)("div",{style:{display:"grid",gap:8},children:e.options.map(r=>(0,n.jsx)("button",{onClick:()=>t(e,{value:r}),style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:13},children:r},r))}),"input"===e.method&&(0,n.jsx)("input",{autoFocus:!0,value:o,placeholder:e.placeholder,onChange:e=>l(e.target.value),onKeyDown:r=>{"Enter"===r.key&&a(),"Escape"===r.key&&t(e,{cancelled:!0})},style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",fontSize:13}}),"editor"===e.method&&(0,n.jsx)("textarea",{autoFocus:!0,value:o,onChange:e=>l(e.target.value),onKeyDown:r=>{"Escape"===r.key&&t(e,{cancelled:!0}),(r.metaKey||r.ctrlKey)&&"Enter"===r.key&&a()},style:{width:"100%",minHeight:220,padding:10,borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",resize:"vertical",fontSize:13,lineHeight:1.55,fontFamily:"var(--font-mono)"}})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 14px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{onClick:()=>t(e,{cancelled:!0}),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer"},children:r("chat.cancel")}),"confirm"===e.method?(0,n.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:r("chat.confirm")}):"select"!==e.method?(0,n.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"#fff",cursor:"pointer"},children:r("chat.submit")}):null]})]})})}function nd({request:e,onInput:t}){let{t:r}=(0,b.s)(),o=(0,i.useRef)(null),l=(0,i.useRef)(!1),a=function(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,r=[];for(let n of e){let e=n.replace(eu,""),i=eg(e).trimEnd();if(t.test(i))continue;let o=e,l=em(o);("│"===l||"┃"===l)&&" "===em(o=ex(o,0))&&(o=ex(o,0));let a=function(e){let t=ef(e);for(let e=t.length-1;e>=0;e--)if(""!==t[e].char.trim())return e;return -1}(o),s=a>=0?ef(o)[a]?.char:void 0;("│"===s||"┃"===s)&&(o=ex(o,a)),r.push(function(e){let t=e;for(;;){let e=ef(t),r=e[e.length-1];if(!r||""!==r.char.trim())return t;t=t.slice(0,r.start)+t.slice(r.end)}}(o))}for(;r.length>0&&""===eg(r[0]).trim();)r.shift();for(;r.length>0&&""===eg(r[r.length-1]).trim();)r.pop();return r.length?r:e}(e.lines);return(0,i.useEffect)(()=>{o.current?.focus()},[e.id]),(0,n.jsx)("div",{style:{position:"absolute",inset:0,zIndex:95,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",onClick:e=>{e.target.closest("button")||o.current?.focus()},style:{position:"relative",width:"min(920px, 100%)",maxHeight:"min(760px, calc(100vh - 40px))",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden",outline:"none"},children:[(0,n.jsx)("textarea",{ref:o,"aria-label":r("chat.extensionInput"),autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",spellCheck:!1,onKeyDown:r=>{if(l.current||r.nativeEvent.isComposing)return;let n=function(e){if(e.metaKey||e.ctrlKey&&!e.altKey&&"v"===e.key.toLowerCase())return null;if(e.ctrlKey&&!e.altKey){let t=function(e){if(1!==e.length)return null;let t=e.toUpperCase().charCodeAt(0);return t>=64&&t<=95?String.fromCharCode(31&t):"?"===e?"":null}(e.key);if(t)return t}if(e.altKey&&!e.ctrlKey){if("Backspace"===e.key)return"\x1b\x7f";let t=ey[e.key];if(t)return t;if(1===e.key.length)return`\x1b${e.key}`}return"Enter"===e.key?e.shiftKey?"\n":"\r":"Tab"===e.key?e.shiftKey?"\x1b[Z":" ":eb[e.key]??null}(r);n&&(r.preventDefault(),r.stopPropagation(),t(e,n))},onInput:r=>{if(l.current||r.nativeEvent.isComposing)return;let n=r.currentTarget.value;r.currentTarget.value="",n&&t(e,n)},onCompositionStart:()=>{l.current=!0},onCompositionEnd:r=>{l.current=!1;let n=r.currentTarget;queueMicrotask(()=>{let r=n.value;n.value="",r&&t(e,r)})},onPaste:r=>{r.preventDefault();let n=w(r.clipboardData),i=n.length>0?j(n):r.clipboardData.getData("text");i&&t(e,`\x1b[200~${i}\x1b[201~`)},style:{position:"absolute",width:1,height:1,padding:0,border:0,opacity:0,pointerEvents:"none"}}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650},children:r("chat.extensionPanel")}),(0,n.jsx)("button",{onClick:()=>t(e,"\x03"),style:{padding:"5px 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:r("chat.close")})]}),(0,n.jsx)("pre",{style:{margin:0,padding:14,maxHeight:"calc(min(760px, 100vh - 40px) - 48px)",overflow:"auto",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.45,whiteSpace:"pre"},children:(a.length?a:[""]).map((e,t,r)=>{var o;return(0,n.jsxs)(i.Fragment,{children:[(o=`line-${t}`,ev(e).map((e,t)=>Object.keys(e.style).length>0?(0,n.jsx)("span",{style:e.style,children:e.text},`${o}-${t}`):e.text)),t<r.length-1?"\n":null]},t)})})]})})}var nc=r(50640);let nu={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",avif:"image/avif"},np={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",oga:"audio/ogg",opus:"audio/ogg",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac",weba:"audio/webm",webm:"audio/webm"};function nh(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}var ng=r(73620);let nf=/^(?:\uFEFF)?---[ \t]*(?:\r\n|\n|\r)/;function nx(e){return function e(t,r){if(null==t)return"";if("string"==typeof t)return t;if("number"==typeof t||"boolean"==typeof t)return String(t);if(Array.isArray(t)){if(r.has(t))return"[Circular]";r.add(t);try{return t.map(t=>e(t,r)).filter(Boolean).join(", ")}finally{r.delete(t)}}if("object"==typeof t)try{return JSON.stringify(t)??Object.prototype.toString.call(t)}catch{return Object.prototype.toString.call(t)}return String(t)}(e,new WeakSet)}let nm=["tags","categories","keywords","tag","category"];function nv({data:e}){var t;if(!e)return null;let r=Object.entries(e);if(0===r.length)return null;let i="string"==typeof(t=e.title)?t.trim()||null:"number"==typeof t||"boolean"==typeof t?String(t):null,o=nm.find(t=>Array.isArray(e[t])),l=o?e[o].map(nx).filter(Boolean):[],a=r.filter(([e])=>e!==o&&("title"!==e||!i));return(0,n.jsxs)("div",{className:"markdown-frontmatter",children:[i&&(0,n.jsx)("div",{className:"markdown-frontmatter-title",children:i}),l.length>0&&(0,n.jsx)("div",{className:"markdown-frontmatter-tags",children:l.map((e,t)=>(0,n.jsx)("span",{className:"markdown-frontmatter-tag",children:e},`${e}-${t}`))}),a.length>0&&(0,n.jsx)("dl",{className:"markdown-frontmatter-rows",children:a.map(([e,t])=>(0,n.jsxs)("div",{className:"markdown-frontmatter-row",children:[(0,n.jsx)("dt",{children:e}),(0,n.jsx)("dd",{children:function(e){let t=nx(e);return t?"string"==typeof e&&/^(https?:\/\/|mailto:)/i.test(e)?(0,n.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:t}):t:null}(t)})]},e))})]})}let nb={source:"Source",preview:"Preview",diff:"Diff"},ny={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6},nk={width:48,minWidth:48,padding:"0 10px",textAlign:"right",color:"var(--text-dim)",background:"var(--bg-panel)",borderRight:"1px solid var(--border)",fontFamily:"var(--font-mono)",fontSize:11,fontStyle:"normal",fontVariantNumeric:"tabular-nums",lineHeight:"20.8px",userSelect:"none",flexShrink:0,verticalAlign:"top"};function nw(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]})}function nj(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?.closest(".file-source-line[data-line-number]")??null}function nS(e,t){if(!t||t.isCollapsed||0===t.rangeCount)return null;let r=t.getRangeAt(0);if(!e.contains(r.startContainer)||!e.contains(r.endContainer))return null;let n=nj(r.startContainer),i=nj(r.endContainer);if(!n||!i||!e.contains(n)||!e.contains(i))return null;let o=Number(n.dataset.lineNumber),l=Number(i.dataset.lineNumber);if(!Number.isInteger(o)||!Number.isInteger(l))return null;if(o<l){let e=n.querySelector(".file-source-line-content");if(e?.contains(r.startContainer)){let t=document.createRange();if(t.selectNodeContents(e),t.setStart(r.startContainer,r.startOffset),0===t.toString().length){let e=n.nextElementSibling;e instanceof HTMLElement&&e.matches(".file-source-line[data-line-number]")&&(o=Number((n=e).dataset.lineNumber))}}let t=i.querySelector(".file-source-line-content");if(t?.contains(r.endContainer)){let e=document.createRange();if(e.selectNodeContents(t),e.setEnd(r.endContainer,r.endOffset),0===e.toString().length){let e=i.previousElementSibling;e instanceof HTMLElement&&e.matches(".file-source-line[data-line-number]")&&(l=Number((i=e).dataset.lineNumber))}}}return o>l?null:{startLine:o,endLine:l}}function nC({rows:e,stylesheet:t,useInlineStyles:r,wrapLines:i}){return e.map((e,o)=>{let l=e.children??[],a=l[0]?.properties?.className,s=Array.isArray(a)&&a.includes("react-syntax-highlighter-line-number"),d=s?l[0]:null,c=s?l.slice(1):l;return(0,n.jsxs)("span",{className:"file-source-line","data-line-number":o+1,style:{display:"flex",minWidth:"100%"},children:[d&&(0,nc.Ay)({node:d,stylesheet:t,useInlineStyles:r,key:`source-line-number-${o}`}),(0,n.jsx)("span",{className:"file-source-line-content",style:{flex:"1 1 auto",minWidth:0,overflowWrap:i?"anywhere":"normal",whiteSpace:i?"pre-wrap":"pre"},children:c.map((e,n)=>(0,nc.Ay)({node:e,stylesheet:t,useInlineStyles:r,key:`source-token-${o}-${n}`}))})]},`source-line-${o}`)})}function nT(e,t,r,n={}){let i=P(e),o=new URLSearchParams({type:t});for(let[e,t]of(r&&o.set("sessionId",r),Object.entries(n)))void 0!==t&&o.set(e,String(t));return`/api/files/${i}?${o.toString()}`}function nM({filePath:e,sourceSessionId:t}){let{t:r}=(0,b.s)();return(0,n.jsx)("a",{href:nT(e,"download",t),download:A(e),title:r("i18n.downloadFile"),"aria-label":r("i18n.downloadFile"),className:"file-viewer-icon-button",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,n.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})}function nR(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function nI({patch:e}){let t,{t:r}=(0,b.s)(),i=(t=tc(e))?t.flatMap(e=>e.rows.flatMap(e=>{if("hunk"===e.type)return[];if("context"===e.left.type&&"context"===e.right.type)return[{type:"unchanged",text:e.right.text,oldLineNo:e.left.lineNo,newLineNo:e.right.lineNo}];let t=[];return"removed"===e.left.type&&t.push({type:"removed",text:e.left.text,oldLineNo:e.left.lineNo,newLineNo:null}),"added"===e.right.type&&t.push({type:"added",text:e.right.text,oldLineNo:null,newLineNo:e.right.lineNo}),t})):[];if(!i.some(e=>"unchanged"!==e.type))return(0,n.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:r("i18n.noChanges")});let o=new Set(i.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),l=new Set;for(let e of o)for(let t=Math.max(0,e-3);t<=Math.min(i.length-1,e+3);t++)l.add(t);let a=[],s=0;for(;s<i.length;)if(l.has(s)){let e=[];for(;s<i.length&&l.has(s);)e.push(i[s]),s++;a.push({hidden:!1,lines:e})}else{let e=0;for(;s<i.length&&!l.has(s);)e++,s++;a.push({hidden:!0,count:e})}return(0,n.jsx)("div",{className:"file-diff-view",style:{width:"max-content",minWidth:"100%",...ny},children:a.map((e,t)=>{if(e.hidden)return(0,n.jsxs)("div",{style:{padding:"2px 16px",color:"var(--text-dim)",background:"var(--bg-panel)",fontSize:11,borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:["... ",e.count," unchanged lines ..."]},t);let r=e.lines.map((e,t)=>{let r="added"===e.type?"rgba(0,200,80,0.12)":"removed"===e.type?"rgba(240,60,60,0.14)":"transparent",i="added"===e.type?"+":"removed"===e.type?"-":" ",o="added"===e.type?"#4ade80":"removed"===e.type?"#f87171":"var(--text-dim)";return(0,n.jsxs)("div",{className:"file-diff-line",style:{display:"flex",minWidth:"100%",background:r,borderLeft:"added"===e.type?"3px solid #4ade80":"removed"===e.type?"3px solid #f87171":"3px solid transparent"},children:[(0,n.jsx)("span",{style:nk,children:"removed"===e.type?e.oldLineNo:e.newLineNo}),(0,n.jsx)("span",{style:{minWidth:16,padding:"0 6px",color:o,userSelect:"none",flexShrink:0,fontWeight:600},children:i}),(0,n.jsx)("span",{className:"file-diff-line-content",style:{flexShrink:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},t)});return(0,n.jsx)("div",{children:r},t)})})}function nL({filePath:e,cwd:t,sourceSessionId:r,watchEnabled:o=!0}){let{t:l}=(0,b.s)(),[a,s]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[f,x]=(0,i.useState)(null),m=(0,i.useRef)(null),v=(0,i.useRef)(0),y=A(e).toLowerCase().split(".").pop()??"";(0,i.useEffect)(()=>{c(0),p(null),g(null),x(null),s(!1)},[e,r]),(0,i.useEffect)(()=>{if(s(!1),m.current&&(m.current.close(),m.current=null),!o)return;let t=!0,n=new EventSource(nT(e,"watch",r));m.current=n,n.addEventListener("connected",()=>{let n;s(!0),n=++v.current,fetch(nT(e,"meta",r)).then(e=>e.json()).then(e=>{if(t&&n===v.current){if(e.error)return void x(e.error);"number"==typeof e.size&&p(e.size),g(null),x(null),c(e=>e+1)}}).catch(e=>{t&&n===v.current&&x(String(e))})}),n.addEventListener("change",e=>{v.current+=1;try{let t=JSON.parse(e.data);"number"==typeof t.size&&p(t.size)}catch{}g(null),x(null),c(e=>e+1)});let i=()=>{s(!1)};return n.addEventListener("error",i),n.onerror=i,()=>{t=!1,n.close(),m.current===n&&(m.current=null)}},[e,r,o]);let k=nT(e,"read",r,d?{v:d}:void 0),w=null!=u?nR(u):null;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:N(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:y||"image"}),h&&(0,n.jsxs)("span",{children:[h.w," \xd7 ",h.h]}),w&&(0,n.jsx)("span",{children:w}),(0,n.jsxs)("span",{title:l(a?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:a?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:a?"#4ade80":"var(--border)",display:"inline-block",boxShadow:a?"0 0 4px #4ade80":"none"}}),a?"live":"static"]}),(0,n.jsx)(nM,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",display:"flex",alignItems:"center",justifyContent:"center",padding:16,backgroundImage:"linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%)",backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px"},children:f?(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13},children:f}):(0,n.jsx)("img",{src:k,alt:e,onLoad:e=>{let t=e.currentTarget;g({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>x("Failed to load image"),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function nE({filePath:e,cwd:t,sourceSessionId:r,watchEnabled:o=!0}){let{t:l}=(0,b.s)(),[a,s]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),[f,x]=(0,i.useState)(null),m=(0,i.useRef)(null),v=(0,i.useRef)(0),y=A(e).toLowerCase().split(".").pop()??"";(0,i.useEffect)(()=>{c(0),p(null),g(null),x(null),s(!1)},[e,r]),(0,i.useEffect)(()=>{if(s(!1),m.current&&(m.current.close(),m.current=null),!o)return;let t=!0,n=new EventSource(nT(e,"watch",r));m.current=n,n.addEventListener("connected",()=>{let n;s(!0),n=++v.current,fetch(nT(e,"meta",r)).then(e=>e.json()).then(e=>{if(t&&n===v.current){if(e.error)return void x(e.error);"number"==typeof e.size&&p(e.size),g(null),x(null),c(e=>e+1)}}).catch(e=>{t&&n===v.current&&x(String(e))})}),n.addEventListener("change",e=>{v.current+=1;try{let t=JSON.parse(e.data);"number"==typeof t.size&&p(t.size)}catch{}g(null),x(null),c(e=>e+1)});let i=()=>{s(!1)};return n.addEventListener("error",i),n.onerror=i,()=>{t=!1,n.close(),m.current===n&&(m.current=null)}},[e,r,o]);let k=nT(e,"read",r,d?{v:d}:void 0);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)"},title:e,children:N(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:y||"audio"}),null!=h&&(0,n.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),r=Math.floor(t/60);return`${r}:${String(t%60).padStart(2,"0")}`}(h)}),null!=u&&(0,n.jsx)("span",{children:nR(u)}),(0,n.jsxs)("span",{title:l(a?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:a?"#4ade80":"var(--text-dim)"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:a?"#4ade80":"var(--border)",display:"inline-block",boxShadow:a?"0 0 4px #4ade80":"none"}}),a?"live":"static"]}),(0,n.jsx)(nM,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,n.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[f&&(0,n.jsx)("div",{style:{color:"#f87171",fontSize:13,marginBottom:12,textAlign:"center"},children:f}),(0,n.jsx)("audio",{controls:!0,preload:"metadata",src:k,onLoadedMetadata:e=>g(e.currentTarget.duration),onError:()=>x("Failed to load audio"),style:{width:"100%"}},k)]})})]})}function nW({filePath:e,cwd:t,sourceSessionId:r,watchEnabled:o=!0}){let{t:l}=(0,b.s)(),[a,s]=(0,i.useState)(!1),[d,c]=(0,i.useState)(0),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(null),f=(0,i.useRef)(null),x=(0,i.useRef)(0),m=nh(e),v="pdf"===m,y=v?nT(e,"read",r,d?{v:d}:void 0):nT(e,"preview",r,d?{v:d}:void 0);return(0,i.useEffect)(()=>{c(0),p(null),g(null),s(!1);let t=!0,n=++x.current;return fetch(nT(e,"meta",r)).then(e=>e.json()).then(e=>{t&&n===x.current&&(e.error&&g(e.error),"number"==typeof e.size&&(p(e.size),!v&&e.size>0xa00000&&g("DOCX too large for preview (>10MB)")))}).catch(e=>{t&&n===x.current&&g(String(e))}),()=>{t=!1}},[e,v,r]),(0,i.useEffect)(()=>{if(s(!1),f.current&&(f.current.close(),f.current=null),!o)return;let t=!0,n=new EventSource(nT(e,"watch",r));f.current=n,n.addEventListener("connected",()=>{let n;s(!0),n=++x.current,fetch(nT(e,"meta",r)).then(e=>e.json()).then(e=>{if(t&&n===x.current){if(e.error)return void g(e.error);if("number"==typeof e.size&&(p(e.size),!v&&e.size>0xa00000))return void g("DOCX too large for preview (>10MB)");g(null),c(e=>e+1)}}).catch(e=>{t&&n===x.current&&g(String(e))})}),n.addEventListener("change",e=>{x.current+=1;try{let t=JSON.parse(e.data);if("number"==typeof t.size&&(p(t.size),!v&&t.size>0xa00000))return void g("DOCX too large for preview (>10MB)")}catch{}g(null),c(e=>e+1)});let i=()=>{s(!1)};return n.addEventListener("error",i),n.onerror=i,()=>{t=!1,n.close(),f.current===n&&(f.current=null)}},[e,v,r,o]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:N(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===m?"docx preview":"pdf"}),null!=u&&(0,n.jsx)("span",{children:nR(u)}),(0,n.jsx)(nM,{filePath:e,sourceSessionId:r}),(0,n.jsxs)("span",{title:l(a?"i18n.liveSync":"i18n.notWatching"),style:{display:"flex",alignItems:"center",gap:4,color:a?"#4ade80":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:a?"#4ade80":"var(--border)",display:"inline-block",boxShadow:a?"0 0 4px #4ade80":"none"}}),a?"live":"static"]})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,background:"var(--bg-panel)"},children:h?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"#f87171",fontSize:13,textAlign:"center"},children:h}):(0,n.jsx)("iframe",{src:y,sandbox:v?void 0:"allow-same-origin",title:l("i18n.previewFile",{file:A(e)}),style:{width:"100%",height:"100%",border:"none",background:v?"var(--bg)":"#eef1f5"}},y)})]})}function nz({filePath:e,cwd:t,sourceSessionId:r,onOpenFile:i,onMentionLines:o,onAtMention:l,gitRefreshKey:a,initialDisplayMode:s,initialState:d,onStateChange:c,watchEnabled:u=!0}){let p;return null!==(nu[nh(e)]??null)?(0,n.jsx)(nL,{filePath:e,cwd:t,sourceSessionId:r,watchEnabled:u}):null!==(np[nh(e)]??null)?(0,n.jsx)(nE,{filePath:e,cwd:t,sourceSessionId:r,watchEnabled:u}):null!==("pdf"===(p=nh(e))||"docx"===p?p:null)?(0,n.jsx)(nW,{filePath:e,cwd:t,sourceSessionId:r,watchEnabled:u}):(0,n.jsx)(n$,{filePath:e,cwd:t,sourceSessionId:r,onOpenFile:i,onMentionLines:o,onAtMention:l,gitRefreshKey:a,initialDisplayMode:s,initialState:d,onStateChange:c,watchEnabled:u})}function n$({filePath:e,cwd:t,sourceSessionId:r,onOpenFile:o,onMentionLines:l,onAtMention:a,gitRefreshKey:s,initialDisplayMode:d,initialState:c,onStateChange:u,watchEnabled:p=!0}){let{isDark:h}=tt(),{t:g}=(0,b.s)(),[f,x]=(0,i.useState)(null),[m,v]=(0,i.useState)(null),[y,k]=(0,i.useState)(!1),[w,j]=(0,i.useState)(!1),[S,C]=(0,i.useState)(!0),[T,M]=(0,i.useState)(null),R=c?.displayMode??d??"source",I=c?.wrapLines??!1,L=c?.scrollTop??0,E=c?.scrollLeft??0,[W,z]=(0,i.useState)(R),[$,P]=(0,i.useState)(I),[A,F]=(0,i.useState)(!1),B=(0,i.useRef)(null),H=(0,i.useRef)(0),O=(0,i.useRef)(0),U=(0,i.useRef)(null),_=(0,i.useRef)(!1),q=(0,i.useRef)(void 0===c&&void 0===d),K=(0,i.useRef)(!0),V=(0,i.useRef)({displayMode:R,wrapLines:I,scrollTop:L,scrollLeft:E}),J=(0,i.useRef)(u),[Y,X]=(0,i.useState)(null);J.current=u;let Z=(0,i.useCallback)(e=>{V.current.displayMode=e,z(e)},[]),G=(0,i.useCallback)(()=>{P(e=>{let t=!e;return V.current.wrapLines=t,t})},[]);(0,i.useEffect)(()=>(V.current={displayMode:R,wrapLines:I,scrollTop:L,scrollLeft:E},K.current=!0,_.current=!1,z(R),P(I),()=>{J.current?.({...V.current})}),[e,r,R,I,L,E]);let Q=(0,i.useCallback)(e=>{let t=++H.current;return fetch(nT(e,"read",r)).then(e=>e.json()).then(e=>t!==H.current?null:e.error?(M(e.error),null):(M(null),x(e),e)).catch(e=>(t!==H.current||M(String(e)),null))},[r]),ee=(0,i.useCallback)(async e=>{let r=++O.current;if(k(!0),!t){v(null),k(!1),j(!0);return}try{let n=new URLSearchParams({cwd:t,path:e}),i=await fetch(`/api/git/diff?${n.toString()}`),o=await i.json();if(r!==O.current)return;v(i.ok&&o.supported&&"string"==typeof o.patch?o:null)}catch{r===O.current&&v(null)}finally{r===O.current&&(k(!1),j(!0))}},[t]);(0,i.useEffect)(()=>{let t=!0;return C(!0),M(null),x(null),v(null),j(!1),F(!1),Q(e).finally(()=>{t&&C(!1)}),()=>{t=!1}},[e,Q,r]),(0,i.useEffect)(()=>{if(F(!1),B.current&&(B.current.close(),B.current=null),!p)return;let t=()=>{Q(e),ee(e)},n=new EventSource(nT(e,"watch",r));B.current=n,n.addEventListener("connected",()=>{F(!0),t()}),n.addEventListener("change",t);let i=()=>{F(!1)};return n.addEventListener("error",i),n.onerror=i,()=>{n.close(),B.current===n&&(B.current=null)}},[e,Q,ee,r,p]),(0,i.useEffect)(()=>{ee(e)},[ee,e,s]),(0,i.useEffect)(()=>{q.current&&(f?.language==="markdown"||f?.language==="html")&&(q.current=!1,Z("preview"))},[f?.language,Z]);let et=m?.supported===!0&&"string"==typeof m.patch,er=et&&"deleted"===m.status;(0,i.useEffect)(()=>{w&&!et&&"diff"===W&&Z("source")},[W,w,et,Z]),(0,i.useEffect)(()=>{"diff"===R&&et&&!_.current&&(_.current=!0,Z("diff"))},[R,et,Z]);let en=(0,i.useMemo)(()=>f?.language==="markdown"?eB(f.content):"",[f]),ei=(0,i.useMemo)(()=>f?.language==="markdown"?function(e){let t=function(e){let t=nf.exec(e);if(!t)return null;let r=/^---[ \t]*(?:(?:\r\n|\n|\r)|$)/gm;r.lastIndex=t[0].length;let n=r.exec(e);return n?{yaml:e.slice(t[0].length,n.index).replace(/(?:\r\n|\n|\r)$/,""),rest:e.slice(n.index+n[0].length)}:null}(e);if(!t)return{data:null,rest:e};try{let e=(0,ng.Hh)(t.yaml);if(e&&"object"==typeof e&&!Array.isArray(e))return{data:e,rest:t.rest}}catch{}return{data:null,rest:t.rest}}(f.content):null,[f]);(0,i.useEffect)(()=>{let e=()=>{let e=U.current;X(l&&"source"===W&&e?nS(e,window.getSelection()):null)};if(e(),l&&"source"===W)return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},[f?.content,W,l]);let eo=(0,i.useCallback)(r=>{l&&r&&l(N(e,t),r.startLine,r.endLine)},[t,e,l]);if((0,i.useEffect)(()=>{if(!l||"source"!==W)return;let e=e=>{if(e.repeat||"i"!==e.key.toLowerCase()||!e.metaKey&&!e.ctrlKey||e.altKey||e.shiftKey)return;let t=e.target;if(t instanceof Element&&t.closest("input, textarea, [contenteditable='true']"))return;let r=U.current,n=r?nS(r,window.getSelection()):null;n&&(e.preventDefault(),eo(n))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[W,eo,l]),(0,i.useEffect)(()=>{if(!K.current||S||T&&!er||"diff"===R&&!w||"diff"===R&&et&&"diff"!==W)return;let e=U.current;e&&(e.scrollTop=V.current.scrollTop,e.scrollLeft=V.current.scrollLeft,K.current=!1)},[f?.content,W,T,w,et,er,S,R]),S||"diff"===R&&y&&!f)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:g("i18n.loading")});if(T&&!er)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:T});if(!f&&!er)return null;let el=f?.language??"text",ea=f?.content??"",es="html"===el,ed="markdown"===el,ec=D(e),eu=ea.split("\n"),ep=er?"diff":W,eh=er?["diff"]:["source",...es||ed?["preview"]:[],...et?["diff"]:[]],eg=er?g("files.deleted"):`${el} \xb7 ${eu.length} lines \xb7 ${nR(f.size)}`;return(0,n.jsxs)("div",{className:"file-viewer-shell",style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{className:"file-viewer-toolbar",style:{display:"flex",alignItems:"center",gap:8,padding:"5px 12px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,n.jsx)("span",{className:"file-viewer-path",style:{fontFamily:"var(--font-mono)"},title:e,children:N(e,t)}),(0,n.jsx)("span",{className:"file-viewer-meta",title:eg,children:eg}),!er&&(0,n.jsx)("span",{title:A?g("i18n.liveSync"):g("i18n.notWatching"),"aria-label":A?g("i18n.liveSync"):g("i18n.notWatching"),className:"file-viewer-live-indicator",style:{background:A?"#4ade80":"var(--border)",boxShadow:A?"0 0 4px #4ade80":"none"}}),(0,n.jsxs)("div",{className:"file-viewer-controls",children:[eh.length>1&&(0,n.jsx)("div",{className:"file-viewer-mode-switch","aria-label":g("i18n.fileViewMode"),children:eh.map(e=>{let t=ep===e;return(0,n.jsx)("button",{type:"button",onClick:()=>Z(e),title:"diff"===e?g("i18n.compareHead"):void 0,"aria-pressed":t,className:"file-viewer-mode-button",style:{background:t?"var(--bg-selected)":"transparent",color:t?"var(--text)":"var(--text-muted)"},children:nb[e]},e)})}),(0,n.jsxs)("div",{className:"file-viewer-actions",children:[(a||l)&&(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onClick:()=>{Y&&l?eo(Y):a?.(N(e,t),!1)},title:Y&&l?`${g("i18n.mentionSelectedLines")} (L${Y.startLine}${Y.startLine!==Y.endLine?`-L${Y.endLine}`:""})`:g("files.insertPath"),"aria-label":g("files.mention"),disabled:!a&&!l,className:"file-viewer-icon-button",children:(0,n.jsx)(nw,{})}),"source"===ep&&(0,n.jsx)(n.Fragment,{children:(0,n.jsx)("button",{type:"button",onClick:G,title:$?g("i18n.disableWrap"):g("i18n.enableWrap"),"aria-label":$?g("i18n.disableWrap"):g("i18n.enableWrap"),"aria-pressed":$,className:"file-viewer-icon-button",style:{background:$?"var(--bg-selected)":"transparent",color:$?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M3 6h18"}),(0,n.jsx)("path",{d:"M3 12h15a3 3 0 1 1 0 6h-4"}),(0,n.jsx)("path",{d:"m16 16-2 2 2 2"}),(0,n.jsx)("path",{d:"M3 18h7"})]})})})]}),!er&&(0,n.jsx)(nM,{filePath:e,sourceSessionId:r})]})]}),(0,n.jsx)("div",{ref:U,className:"file-viewer-content",onScroll:e=>{V.current.scrollTop=e.currentTarget.scrollTop,V.current.scrollLeft=e.currentTarget.scrollLeft},style:{flex:1,overflow:"auto",background:"var(--bg)"},children:"diff"===ep&&et?(0,n.jsx)(nI,{patch:m.patch}):es&&"preview"===ep?(0,n.jsx)("iframe",{srcDoc:ea,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:g("i18n.htmlPreview")}):ed&&"preview"===ep?(0,n.jsxs)("div",{className:"markdown-body markdown-file-preview",style:{padding:"24px 32px"},children:[ei?.data&&(0,n.jsx)(nv,{data:ei.data}),(0,n.jsx)(eE.oz,{remarkPlugins:eq,rehypePlugins:eV,components:{code({className:e,children:t,...r}){let i=e?.replace("language-","").toLowerCase()??"",o=String(t);return e?.includes("language-")||o.includes("\n")?"mermaid"===i?(0,n.jsx)(tn,{code:o.replace(/\n$/,""),defaultPreview:!0}):(0,n.jsx)(to,{code:o.replace(/\n$/,""),lang:i}):(0,n.jsx)("code",{className:e,...r,children:t})},pre:({children:e})=>(0,n.jsx)(n.Fragment,{children:e}),a({href:e,children:r,...i}){delete i.node;let l=o?eI(e,ec,t??ec):null;return l&&o?(0,n.jsx)("a",{href:e,...i,onClick:e=>{e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),o(l))},children:r}):(0,n.jsx)("a",{href:e,...i,children:r})},img({src:e,alt:i,...o}){delete o.node;let l="string"==typeof e?eI(e,ec,t??ec):null,a=l?nT(l,"read",r):e;return(0,n.jsx)("img",{src:a,alt:i??"",loading:"lazy",...o})}},children:en})]}):(0,n.jsx)(eJ.A,{className:$?"file-source-view is-wrapped":"file-source-view",language:"text"===el?"plaintext":el,style:h?eY.xJ:eY.vs,showLineNumbers:!0,lineNumberStyle:{...nk},customStyle:{margin:0,padding:0,border:0,background:"var(--bg)",...ny,width:$?"100%":"max-content",minWidth:"100%",minHeight:"100%",overflow:"visible"},codeTagProps:{style:{fontFamily:"var(--font-mono)",overflowWrap:$?"anywhere":"normal"}},renderer:e=>(0,n.jsx)(nC,{...e,wrapLines:$}),wrapLongLines:$,children:ea})})]})}function nP({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:o}){let{t:l}=(0,b.s)(),[a,s]=(0,i.useState)(null);return(0,n.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:e.map(e=>{let i=e.id===t;return(0,n.jsxs)("div",{onClick:()=>r(e.id),onMouseDown:e=>{1===e.button&&e.preventDefault()},onAuxClick:t=>{1===t.button&&(t.preventDefault(),t.stopPropagation(),o(e.id))},style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:i?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:i?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,n.jsx)("span",{style:{flexShrink:0,opacity:i?1:.7,display:"flex",alignItems:"center"},children:z(e.label,13)}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:i?500:400},title:e.filePath,children:e.label}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),o(e.id)},onMouseEnter:()=>s(e.id),onMouseLeave:()=>s(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:24,height:24,background:a===e.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:4,color:a===e.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:l("i18n.close"),"aria-label":`${l("i18n.close")} ${e.label}`,children:(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,n.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]},e.id)})})}let nA=["input","output","cacheRead","cacheWrite"];function nD(e){return{input:e?.input===void 0?"":String(e.input),output:e?.output===void 0?"":String(e.output),cacheRead:e?.cacheRead===void 0?"":String(e.cacheRead),cacheWrite:e?.cacheWrite===void 0?"":String(e.cacheWrite)}}function nN(e){if(!nF(e))return;let t=e=>{if(!e.trim())return 0;let t=Number(e);return Number.isFinite(t)&&t>=0?t:void 0},r=t(e.input),n=t(e.output),i=t(e.cacheRead),o=t(e.cacheWrite);if(void 0!==r&&void 0!==n&&void 0!==i&&void 0!==o)return{input:r,output:n,cacheRead:i,cacheWrite:o}}function nF(e){return nA.some(t=>""!==e[t].trim())}var nB=r(67381),nH=r(64433),nO=r(70350),nU=r(88195),n_=r(9312),nq=r(87275),nK=r(22008),nV=r(95476),nJ=r(35029),nY=r(14489),nX=r(78728),nZ=r(19872),nG=r(7751),nQ=r(92526),n0=r(48238),n1=r(57794),n2=r(41098),n8=r(84604),n4=r(15315),n6=r(74278),n5=r(55457),n3=r(71437),n7=r(29167),n9=r(97283),ie=r(34166),it=r(33889),ir=r(85486),ii=r(74068),io=r(83546),il=r(83709);let ia={anthropic:{Icon:nB.A,hasColor:!1},openai:{Icon:nH.A,hasColor:!1},"openai-codex":{Icon:nH.A,hasColor:!1},google:{Icon:nO.A,hasColor:!0},"google-vertex":{Icon:nO.A,hasColor:!0},"ant-ling":{Icon:it.A,hasColor:!0},deepseek:{Icon:nU.A,hasColor:!0},groq:{Icon:n_.A,hasColor:!1},mistral:{Icon:nq.A,hasColor:!0},moonshotai:{Icon:nK.A,hasColor:!1},"moonshotai-cn":{Icon:nK.A,hasColor:!1},moonshot:{Icon:nK.A,hasColor:!1},minimax:{Icon:nV.A,hasColor:!0},"minimax-cn":{Icon:nV.A,hasColor:!0},fireworks:{Icon:nJ.A,hasColor:!0},huggingface:{Icon:nY.A,hasColor:!0},cerebras:{Icon:nX.A,hasColor:!0},openrouter:{Icon:nZ.A,hasColor:!1},xai:{Icon:nG.A,hasColor:!1},"cloudflare-ai-gateway":{Icon:nQ.A,hasColor:!0},"cloudflare-workers-ai":{Icon:nQ.A,hasColor:!0},"vercel-ai-gateway":{Icon:n0.A,hasColor:!1},"github-copilot":{Icon:n1.A,hasColor:!1},"amazon-bedrock":{Icon:n2.A,hasColor:!0},"azure-openai-responses":{Icon:n8.A,hasColor:!0},"kimi-coding":{Icon:n4.A,hasColor:!0},nvidia:{Icon:ir.A,hasColor:!0},opencode:{Icon:ii.A,hasColor:!1},"opencode-go":{Icon:ii.A,hasColor:!1},qwen:{Icon:n6.A,hasColor:!0},xiaomi:{Icon:io.A,hasColor:!1},"xiaomi-token-plan-ams":{Icon:io.A,hasColor:!1},"xiaomi-token-plan-cn":{Icon:io.A,hasColor:!1},"xiaomi-token-plan-sgp":{Icon:io.A,hasColor:!1},zai:{Icon:il.A,hasColor:!1},"zai-coding-cn":{Icon:il.A,hasColor:!1},zhipu:{Icon:n5.A,hasColor:!0},cohere:{Icon:n3.A,hasColor:!0},perplexity:{Icon:n7.A,hasColor:!0},together:{Icon:n9.A,hasColor:!0},grok:{Icon:ie.A,hasColor:!1}},is=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function id({label:e,children:t}){return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("label",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:e}),t]})}let ic={padding:"6px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",width:"100%",boxSizing:"border-box"};function iu({value:e,onChange:t,placeholder:r,mono:i}){return(0,n.jsx)("input",{value:e,onChange:e=>t(e.target.value),placeholder:r,style:{...ic,fontFamily:i?"var(--font-mono)":"inherit"}})}function ip({value:e,onChange:t,placeholder:r,mono:o,onKeyDown:l,autoComplete:a="off",spellCheck:s=!1,style:d}){let[c,u]=(0,i.useState)(!1),{t:p}=(0,b.s)();return(0,i.useEffect)(()=>{e||u(!1)},[e]),(0,n.jsxs)("div",{style:{position:"relative",width:"100%",...d},children:[(0,n.jsx)("input",{type:c?"text":"password",value:e,onChange:e=>t(e.target.value),onKeyDown:l,placeholder:r,style:{...ic,paddingRight:34,fontFamily:o?"var(--font-mono)":"inherit"},autoComplete:a,spellCheck:s}),(0,n.jsx)("button",{type:"button",onClick:()=>u(e=>!e),"aria-label":p(c?"i18n.hideDetails":"i18n.showDetails"),title:p(c?"i18n.hideDetails":"i18n.showDetails"),style:{position:"absolute",right:5,top:"50%",transform:"translateY(-50%)",width:24,height:24,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:c?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C7 20 2.73 16.89 1 12a18.45 18.45 0 0 1 5.06-6.94"}),(0,n.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c5 0 9.27 3.11 11 8a18.5 18.5 0 0 1-2.16 3.19"}),(0,n.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,n.jsx)("path",{d:"M1 1l22 22"})]}):(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function ih({value:e,onChange:t,placeholder:r}){return(0,n.jsx)("input",{type:"number",value:e,onChange:e=>t(e.target.value),placeholder:r,style:ic})}function ig({value:e,onChange:t,options:r,required:i}){let{t:o}=(0,b.s)();return(0,n.jsxs)("select",{value:e,onChange:e=>t(e.target.value),style:{...ic,color:e?"var(--text)":"var(--text-dim)"},children:[!i&&(0,n.jsxs)("option",{value:"",children:["— ",o("i18n.default")," / none —"]}),r.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})}function ix({label:e,checked:t,onChange:r}){return(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:12,color:"var(--text-muted)"},children:[(0,n.jsx)("input",{type:"checkbox",checked:t,onChange:e=>r(e.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),e]})}function im({children:e}){return(0,n.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:e})}function iv({name:e,provider:t,onChange:r,onRename:o,onDelete:l,onAddModels:a}){let{t:s}=(0,b.s)(),[d,c]=(0,i.useState)(e),[u,p]=(0,i.useState)({phase:"idle"}),[h,g]=(0,i.useState)(""),[f,x]=(0,i.useState)([]),m=(0,i.useRef)(0),v=(0,i.useRef)(null);(0,i.useEffect)(()=>c(e),[e]);let y=(e,n)=>r({...t,[e]:n});(0,i.useEffect)(()=>{t.api||r({...t,api:"openai-completions"})},[t.api]),(0,i.useEffect)(()=>{m.current+=1,p({phase:"idle"}),g(""),x([])},[e,t.baseUrl,t.api,t.apiKey]);let k=(0,i.useCallback)(async()=>{if(!t.baseUrl?.trim()||"loading"===u.phase)return;let r=++m.current;p({phase:"loading"}),x([]);try{let n=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:{...t,models:void 0}})}),i=await n.json();if(r!==m.current)return;if(!n.ok||i.error||!i.models)return void p({phase:"error",message:i.error??`HTTP ${n.status}`});p({phase:"success",models:i.models,endpoint:i.endpoint??t.baseUrl})}catch(e){if(r!==m.current)return;p({phase:"error",message:e instanceof Error?e.message:String(e)})}},[u.phase,e,t]),w=new Set((t.models??[]).map(e=>e.id)),j="success"===u.phase?u.models:[],S=h.trim().toLocaleLowerCase(),C=j.filter(e=>!S||e.id.toLocaleLowerCase().includes(S)||e.name?.toLocaleLowerCase().includes(S)),T=C.slice(0,300),M=T.filter(e=>!w.has(e.id)).map(e=>e.id),R=f.filter(e=>!w.has(e)).length,I=M.length>0&&M.every(e=>f.includes(e)),L=!I&&M.some(e=>f.includes(e));return(0,i.useEffect)(()=>{v.current&&(v.current.indeterminate=L)},[L]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(im,{children:s("i18n.provider")}),(0,n.jsx)("button",{onClick:l,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11},children:s("i18n.delete")})]}),(0,n.jsxs)(id,{label:s("i18n.providerName"),children:[(0,n.jsx)(iu,{value:d,onChange:c,placeholder:"provider-name",mono:!0}),d!==e&&d.trim()&&(0,n.jsx)("button",{onClick:()=>o(d.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:s("i18n.rename")})]}),(0,n.jsx)(id,{label:"Base URL",children:(0,n.jsx)(iu,{value:t.baseUrl??"",onChange:e=>y("baseUrl",e||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,n.jsxs)(id,{label:"API Key",children:[(0,n.jsx)(ip,{value:t.apiKey??"",onChange:e=>y("apiKey",e||void 0),placeholder:"ENV_VAR_NAME, !shell-command, or literal key",mono:!0}),(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:["Prefix with ",(0,n.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"!"})," to run a shell command, or use an env var name"]})]}),(0,n.jsx)(id,{label:"API",children:(0,n.jsx)(ig,{value:t.api??"openai-completions",onChange:e=>y("api",e),options:is,required:!0})}),(0,n.jsxs)(id,{label:"Headers",children:[(0,n.jsx)(iS,{headers:t.headers,onChange:e=>y("headers",e)}),(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Added to every request from this provider (e.g. User-Agent). Useful for gateways with bot detection."})]}),(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--border)",paddingTop:14,display:"flex",flexDirection:"column",gap:10},children:["success"!==u.phase&&(0,n.jsx)("button",{onClick:k,disabled:!t.baseUrl?.trim()||"loading"===u.phase,style:{alignSelf:"flex-start",height:30,padding:"0 12px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:t.baseUrl?.trim()&&"loading"!==u.phase?"var(--text-muted)":"var(--text-dim)",cursor:t.baseUrl?.trim()&&"loading"!==u.phase?"pointer":"not-allowed",fontSize:11},children:"loading"===u.phase?s("models.discoveryFetching"):s("models.discoveryFetch")}),"error"===u.phase&&(0,n.jsx)("div",{style:{padding:"7px 9px",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",fontSize:11,lineHeight:1.4},children:u.message}),"success"===u.phase&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{value:h,onChange:e=>g(e.target.value),placeholder:s("models.discoveryFilterPlaceholder",{count:u.models.length}),"aria-label":s("models.discoveryFilter"),style:{...ic,width:"100%",minWidth:0}}),(0,n.jsxs)("div",{style:{maxHeight:220,overflowY:"auto",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)"},children:[(0,n.jsxs)("label",{style:{minHeight:32,padding:"5px 9px",display:"flex",alignItems:"center",gap:8,position:"sticky",top:0,zIndex:1,borderBottom:"1px solid var(--border)",background:"var(--bg)",cursor:M.length?"pointer":"default",color:"var(--text-muted)",fontSize:10,fontWeight:600},children:[(0,n.jsx)("input",{ref:v,type:"checkbox",checked:I,disabled:0===M.length,onChange:()=>{let e=new Set(M);x(t=>I?t.filter(t=>!e.has(t)):Array.from(new Set([...t,...M])))},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),s("models.discoverySelectShown")]}),0===T.length?(0,n.jsx)("div",{style:{padding:12,color:"var(--text-dim)",fontSize:11},children:s("models.discoveryNoMatches")}):T.map((e,t)=>{let r=w.has(e.id),i=f.includes(e.id);return(0,n.jsxs)("label",{style:{minHeight:36,padding:"6px 9px",display:"flex",alignItems:"center",gap:8,borderTop:0===t?"none":"1px solid var(--border)",cursor:r?"default":"pointer",opacity:r?.65:1},children:[(0,n.jsx)("input",{type:"checkbox",checked:i||r,disabled:r,onChange:()=>{var t;return t=e.id,void x(e=>e.includes(t)?e.filter(e=>e!==t):[...e,t])},style:{width:13,height:13,accentColor:"var(--accent)",flexShrink:0}}),(0,n.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11},children:e.name??e.id}),e.name&&(0,n.jsx)("code",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)"},children:e.id})]}),r&&(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10},children:s("models.discoveryAdded")})]},e.id)})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,n.jsx)("span",{title:u.endpoint,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:C.length>T.length?s("models.discoveryShowing",{shown:T.length,total:C.length}):s("models.discoveryFetched",{count:u.models.length})}),(0,n.jsx)("button",{onClick:()=>{if("success"!==u.phase)return;let e=new Set(f),t=u.models.filter(t=>e.has(t.id)&&!w.has(t.id));0!==t.length&&(a(t),x([]))},disabled:0===R,style:{height:28,padding:"0 11px",border:"none",borderRadius:5,background:R?"var(--accent)":"var(--bg-panel)",color:R?"#fff":"var(--text-dim)",cursor:R?"pointer":"not-allowed",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:R?s("models.discoveryAddSelectedCount",{count:R}):s("models.discoveryAddSelected")})]})]})]})]})}let ib=["off","minimal","low","medium","high","xhigh","max"],iy={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c",max:"#ef4444"};function ik({value:e,onChange:t}){let r=e??{},i=(e,n)=>{let i={...r};"omit"===n?delete i[e]:i[e]=n,t(Object.keys(i).length?i:void 0)};return(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:ib.map(e=>{let t=r[e],o=e in r?null===t?"null":"string":"omit",l="string"==typeof t?t:"",a=iy[e],s={padding:"4px 10px",fontSize:10,border:"none",cursor:"pointer",fontWeight:400,transition:"background 0.1s, color 0.1s",whiteSpace:"nowrap",background:"var(--bg-panel)",color:"var(--text-dim)"},d={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,n.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:a,flexShrink:0,opacity:"null"===o?.3:1}}),(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===o?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===o?"line-through":"none"},children:e})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,n.jsx)("button",{onClick:()=>i(e,"omit"),style:{...s,..."omit"===o?d:{}},children:"Default"}),(0,n.jsx)("button",{onClick:()=>i(e,null),style:{...s,borderLeft:"1px solid var(--border)",..."null"===o?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===o?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,n.jsx)("button",{onClick:()=>i(e,l||e),style:{...s,..."string"===o?d:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,n.jsx)("input",{value:l,onChange:t=>i(e,t.target.value),onFocus:()=>{"string"!==o&&i(e,l||e)},placeholder:e,maxLength:10,style:{width:"12ch",background:"string"===o?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===o?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},e)})})}let iw={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function ij(e){return e.compat?.thinkingFormat==="deepseek"}function iS({headers:e,onChange:t}){let[r,o]=(0,i.useState)(()=>Object.entries(e??{}).map(([e,t],r)=>({id:r,name:e,value:t}))),l=(0,i.useRef)(r.length),a=e=>{o(e),t(function(e){let t={};for(let r of e){let e=r.name.trim();e&&(t[e]=r.value)}return Object.keys(t).length?t:void 0}(e))},s=(e,t)=>{a(r.map(r=>r.id===e?{...r,...t}:r))},d={padding:"6px 9px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,lineHeight:1};return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[r.map(e=>(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{value:e.name,onChange:t=>s(e.id,{name:t.target.value}),placeholder:"Header-Name",style:{...ic,fontFamily:"var(--font-mono)",flex:1}}),(0,n.jsx)("input",{value:e.value,onChange:t=>s(e.id,{value:t.target.value}),placeholder:"value",style:{...ic,fontFamily:"var(--font-mono)",flex:1}}),(0,n.jsx)("button",{onClick:()=>{var t;return t=e.id,void a(r.filter(e=>e.id!==t))},style:d,children:"✕"})]},e.id)),(0,n.jsx)("button",{onClick:()=>o(e=>[...e,{id:l.current++,name:"",value:""}]),style:{padding:"5px 9px",background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:5,alignSelf:"flex-start"},children:"+ Add header"})]})}function iC({providerName:e,provider:t,model:r,onChange:o,onDelete:l}){let[a,s]=(0,i.useState)({phase:"idle"}),{t:d}=(0,b.s)(),[c,u]=(0,i.useState)({phase:"idle"}),[p,h]=(0,i.useState)(!1),[g,f]=(0,i.useState)(()=>nD(r.cost)),x=(0,i.useRef)(g),[m,v]=(0,i.useState)(!1),y=(0,i.useRef)(0),k=(0,i.useRef)(null),w=(0,i.useRef)(r.cost),j=(e,t)=>o({...r,[e]:t}),S=(()=>{if("idle"===a.phase)return null;if("testing"===a.phase)return d("i18n.testingModel");let e=[void 0!==a.latencyMs?`${a.latencyMs}ms`:null,void 0!==a.status?`HTTP ${a.status}`:null].filter(Boolean);return"success"===a.phase?[d("i18n.connected"),...e,a.responseText||null].filter(Boolean).join(" \xb7 "):[d("i18n.failed"),...e,a.message].filter(Boolean).join(" \xb7 ")})();(0,i.useEffect)(()=>{s({phase:"idle"})},[e,t.baseUrl,t.api,t.apiKey,r.id,r.api]),(0,i.useEffect)(()=>{y.current+=1,u({phase:"idle"}),k.current=null},[e,t.baseUrl,r.id]);let C=(0,i.useCallback)(async()=>{if(r.id.trim()&&"testing"!==a.phase){s({phase:"testing"});try{let n=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:e,provider:t,model:r})}),i=await n.json();if(!n.ok||!i.ok)return void s({phase:"error",message:i.error??`HTTP ${n.status}`,latencyMs:i.latencyMs,status:i.status});s({phase:"success",latencyMs:i.latencyMs,status:i.status,responseText:i.responseText})}catch(e){s({phase:"error",message:e instanceof Error?e.message:String(e)})}}},[r,t,e,a.phase]),T=(0,i.useCallback)(async()=>{let n=r.id.trim();if(!n||"loading"===c.phase)return;let i=++y.current;u({phase:"loading"});try{let l=new URLSearchParams({q:n,provider:e,limit:"50"});t.baseUrl?.trim()&&l.set("baseUrl",t.baseUrl.trim());let a=await fetch(`/api/models-config/catalog?${l}`),s=await a.json();if(i!==y.current)return;if(!a.ok||s.error||!s.recommendation)return void u({phase:"error",message:s.error??`HTTP ${a.status}`});let d=function(e,t){let r={...e},n=0;if(!e.name?.trim()&&t.name&&(r.name=t.name,n+=1),void 0===e.reasoning&&!0===t.reasoning&&(r.reasoning=!0,n+=1),!e.input?.length&&t.input?.length&&(r.input=[...t.input],n+=1),void 0===e.contextWindow&&void 0!==t.contextWindow&&(r.contextWindow=t.contextWindow,n+=1),void 0===e.maxTokens&&void 0!==t.maxTokens&&(r.maxTokens=t.maxTokens,n+=1),t.cost){let i={...e.cost??{}},o=0;for(let e of["input","output","cacheRead","cacheWrite"])void 0===i[e]&&void 0!==t.cost[e]&&(i[e]=t.cost[e],o+=1);let l=nN(nD(i));o>0&&l&&(r.cost={...i,...l},n+=o)}return{model:r,appliedCount:n}}(r,s.recommendation.preset);d.appliedCount>0&&(k.current=r,o(d.model)),h(!1),u({phase:"success",recommendation:s.recommendation,appliedCount:d.appliedCount})}catch(e){if(i!==y.current)return;u({phase:"error",message:e instanceof Error?e.message:String(e)})}},[c.phase,r,o,t.baseUrl,e]),M=(()=>{if("success"!==c.phase)return null;let{recommendation:t,appliedCount:r}=c,n=r>0?d("models.catalogFilled",{count:r}):d("models.catalogNoEmptyFields");if("unreliable"===t.price.status){let e="no-exact-match"===t.price.reason?d("models.catalogNoExactMatch"):d("models.catalogPriceUnreliable");return`${n} \xb7 ${e}`}let i="provider"===t.price.method?d("models.catalogPriceProvider",{provider:t.price.providerName??t.price.providerId??e}):"base-url"===t.price.method?d("models.catalogPriceBaseUrl",{provider:t.price.providerName??t.price.providerId??e}):d("models.catalogPriceConsensus",{support:t.price.support,total:t.price.total});return`${n} \xb7 ${i}`})(),R="error"===c.phase?c.message:M,I="error"===c.phase?"#ef4444":"success"===c.phase&&"unreliable"===c.recommendation.price.status?"#d97706":"var(--text-dim)",L=[{key:"input",label:d("models.costInput")},{key:"output",label:d("models.costOutput")},{key:"cacheRead",label:d("models.costCacheRead")},{key:"cacheWrite",label:d("models.costCacheWrite")}],E=new Set(Object.keys(r.compat??{})),W=0;ij(r)&&(W+=1,E.delete("thinkingFormat"),E.delete("requiresReasoningContentOnAssistantMessages")),Object.prototype.hasOwnProperty.call(r.compat??{},"supportsDeveloperRole")&&(W+=1,E.delete("supportsDeveloperRole")),W+=E.size;let z=[r.api?`API: ${r.api}`:null,Object.keys(r.headers??{}).length?d("models.headersSummary",{count:Object.keys(r.headers??{}).length}):null,W?d("models.compatSummary",{count:W}):null,Object.keys(r.thinkingLevelMap??{}).length?d("models.thinkingSummary",{count:Object.keys(r.thinkingLevelMap??{}).length}):null].filter(e=>!!e),$=z.length?z.join(" \xb7 "):d("models.providerDefaults");return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(im,{children:d("i18n.model")}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[S&&(0,n.jsx)("span",{title:S,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===a.phase?"#fecaca":"success"===a.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===a.phase?"#fee2e2":"success"===a.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:S}),(0,n.jsxs)("button",{onClick:C,disabled:!r.id.trim()||"testing"===a.phase,title:d("i18n.testConnection"),style:{height:24,padding:"0 8px",background:"success"===a.phase?"#16a34a":"none",border:`1px solid ${"success"===a.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===a.phase?"#fff":r.id.trim()&&"testing"!==a.phase?"var(--text-muted)":"var(--text-dim)",cursor:r.id.trim()&&"testing"!==a.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===a.phase&&(0,n.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===a.phase?d("i18n.checking"):"success"===a.phase?d("common.ok"):d("i18n.test")]}),(0,n.jsx)("button",{onClick:l,style:{height:24,padding:"0 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,boxSizing:"border-box"},children:d("i18n.remove")})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,n.jsx)(id,{label:"ID *",children:(0,n.jsx)(iu,{value:r.id,onChange:e=>j("id",e),placeholder:"model-id",mono:!0})}),(0,n.jsx)(id,{label:"Name",children:(0,n.jsx)(iu,{value:r.name??"",onChange:e=>j("name",e||void 0),placeholder:"Display name"})})]}),(0,n.jsxs)("div",{style:{padding:"2px 0"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,n.jsx)("button",{onClick:()=>void T(),disabled:!r.id.trim()||"loading"===c.phase,style:{height:28,padding:"0 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:r.id.trim()&&"loading"!==c.phase?"var(--text-muted)":"var(--text-dim)",cursor:r.id.trim()&&"loading"!==c.phase?"pointer":"not-allowed",fontSize:11},children:"loading"===c.phase?d("models.catalogFilling"):d("models.catalogFill")}),(0,n.jsx)("a",{href:"https://github.com/anomalyco/models.dev",target:"_blank",rel:"noreferrer",style:{marginLeft:"auto",color:"var(--text-dim)",fontSize:10,textDecoration:"none"},children:d("models.catalogSource")})]}),R&&(0,n.jsxs)("div",{"aria-live":"polite",style:{marginTop:8,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,color:I,fontSize:10},children:[(0,n.jsx)("span",{title:R,style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R}),k.current&&(0,n.jsx)("button",{onClick:()=>{let e=k.current;e&&(k.current=null,o(e),u({phase:"idle"}))},style:{flexShrink:0,padding:"0 2px",border:"none",background:"none",color:"var(--accent)",cursor:"pointer",fontSize:10},children:d("models.catalogUndo")})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(im,{children:d("models.capabilities")}),(0,n.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap",marginTop:8},children:[(0,n.jsx)(ix,{label:d("models.reasoning"),checked:r.reasoning??!1,onChange:e=>j("reasoning",e||void 0)}),(0,n.jsx)(ix,{label:d("models.imageInput"),checked:r.input?.includes("image")??!1,onChange:e=>j("input",e?["text","image"]:void 0)})]})]}),(0,n.jsxs)("section",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,n.jsx)(im,{children:d("models.modelSpecs")}),(0,n.jsx)("button",{type:"button",onClick:()=>{if(p)return void h(!1);w.current=r.cost;let e=nD(r.cost);x.current=e,f(e),h(!0)},"aria-expanded":p,style:{padding:"2px 4px",border:"none",background:"transparent",color:"var(--accent)",cursor:"pointer",fontSize:10},children:p?d("models.finishEditingCosts"):d("models.editCosts")})]}),(0,n.jsxs)("div",{style:{marginTop:10,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(170px, 1fr))",gap:10},children:[(0,n.jsx)(id,{label:d("models.contextWindow"),children:(0,n.jsx)(ih,{value:void 0!==r.contextWindow?String(r.contextWindow):"",onChange:e=>j("contextWindow",e?parseInt(e):void 0),placeholder:"128000"})}),(0,n.jsx)(id,{label:d("models.maxOutputTokens"),children:(0,n.jsx)(ih,{value:void 0!==r.maxTokens?String(r.maxTokens):"",onChange:e=>j("maxTokens",e?parseInt(e):void 0),placeholder:"16384"})})]}),(0,n.jsxs)("div",{style:{marginTop:16},children:[(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",fontWeight:600,textTransform:"uppercase"},children:d("models.costPerMillion")}),p?(0,n.jsxs)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(110px, 1fr))",gap:8},children:[L.map(({key:e,label:t})=>(0,n.jsx)(id,{label:t,children:(0,n.jsx)(ih,{value:g[e],onChange:t=>{let n,i,l;return i=nN(n={...x.current,[e]:t}),l={...r},void(x.current=n,f(n),i?(l.cost={...w.current??{},...i},w.current=l.cost):delete l.cost,o(l))},placeholder:"0"})},e)),nF(g)&&!nN(g)&&(0,n.jsx)("div",{"aria-live":"polite",style:{gridColumn:"1 / -1",color:"#d97706",fontSize:10},children:d("models.costAllRequired")})]}):(0,n.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(105px, 1fr))",gap:"8px 16px"},children:L.map(({key:e,label:t})=>{let i,o=r.cost?.[e]===void 0;return(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t}),(0,n.jsx)("div",{style:{marginTop:3,color:o?"var(--text-dim)":"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums"},children:void 0===(i=r.cost?.[e])?d("models.notProvided"):`$${String(i)}`})]},e)})})]})]}),(0,n.jsxs)("section",{style:{borderTop:"1px solid var(--border)",paddingTop:4},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>v(e=>!e),"aria-expanded":m,"aria-controls":"model-advanced-settings",style:{width:"100%",minHeight:48,padding:"8px 0",border:"none",background:"transparent",display:"grid",gridTemplateColumns:"minmax(0, 1fr) 18px",alignItems:"center",gap:10,color:"var(--text)",cursor:"pointer",textAlign:"left"},children:[(0,n.jsxs)("span",{style:{minWidth:0},children:[(0,n.jsx)("span",{style:{display:"block",fontSize:11,fontWeight:600},children:d("models.advancedSettings")}),(0,n.jsx)("span",{style:{display:"block",marginTop:3,color:"var(--text-dim)",fontSize:10,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:$})]}),(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{color:"var(--text-dim)",transform:m?"rotate(180deg)":"none",transition:"transform 0.15s ease"},children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),m&&(0,n.jsxs)("div",{id:"model-advanced-settings",style:{display:"flex",flexDirection:"column",gap:14,padding:"4px 0 16px"},children:[(0,n.jsx)(id,{label:d("models.apiOverride"),children:(0,n.jsx)(ig,{value:r.api??"",onChange:e=>j("api",e||void 0),options:is})}),(0,n.jsxs)(id,{label:d("models.headers"),children:[(0,n.jsx)(iS,{headers:r.headers,onChange:e=>j("headers",e)}),(0,n.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:d("models.headersHelp")})]}),r.reasoning&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[(0,n.jsx)(im,{children:d("models.compatibility")}),(0,n.jsx)(ix,{label:d("models.deepSeekThinkingCompat"),checked:ij(r),onChange:e=>o(function(e,t){if(t)return{...e,compat:{...e.compat??{},...iw}};if(!e.compat)return e;let r={...e.compat};return delete r.thinkingFormat,delete r.requiresReasoningContentOnAssistantMessages,{...e,compat:Object.keys(r).length?r:void 0}}(r,e))}),(0,n.jsx)(ix,{label:d("models.developerRole"),checked:!1!==({...t.compat??{},...r.compat??{}}).supportsDeveloperRole,onChange:e=>o({...r,compat:{...r.compat??{},supportsDeveloperRole:e}})}),(0,n.jsxs)("div",{style:{marginTop:4},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,marginBottom:8},children:[(0,n.jsx)(im,{children:d("models.thinkingLevelMap")}),r.thinkingLevelMap&&(0,n.jsx)("button",{type:"button",onClick:()=>j("thinkingLevelMap",void 0),style:{fontSize:10,padding:"2px 5px",background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer"},children:d("models.clearAll")})]}),(0,n.jsx)(ik,{value:r.thinkingLevelMap,onChange:e=>j("thinkingLevelMap",e)})]})]})]})]})]})}function iT({provider:e,onRefresh:t}){let[r,o]=(0,i.useState)({phase:"idle"}),{t:l}=(0,b.s)(),[a,s]=(0,i.useState)(""),d=(0,i.useRef)(null),c=(0,i.useRef)(null);(0,i.useEffect)(()=>{("auth"===r.phase||"prompt"===r.phase)&&setTimeout(()=>c.current?.focus(),50)},[r.phase]),(0,i.useEffect)(()=>{o({phase:"idle"}),s(""),d.current?.close(),d.current=null},[e.id]),(0,i.useEffect)(()=>()=>{d.current?.close()},[]);let u=(0,i.useCallback)(()=>{d.current?.close(),o({phase:"connecting"}),s("");let r=new EventSource(`/api/auth/login/${encodeURIComponent(e.id)}`);d.current=r,r.onmessage=e=>{let n=JSON.parse(e.data);"auth"===n.type?(o({phase:"auth",url:n.url,instructions:n.instructions??null,token:n.token}),window.open(n.url,"_blank","noopener,noreferrer")):"device_code"===n.type?(o({phase:"device_code",userCode:n.userCode,verificationUri:n.verificationUri,intervalSeconds:n.intervalSeconds??null,expiresInSeconds:n.expiresInSeconds??null}),window.open(n.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===n.type?o({phase:"prompt",message:n.message,placeholder:n.placeholder??null,token:n.token}):"select_request"===n.type?o({phase:"select",message:n.message,options:n.options??[],token:n.token}):"progress"===n.type?o({phase:"progress",message:n.message}):"success"===n.type?(r.close(),o({phase:"success"}),t()):"error"===n.type?(r.close(),o({phase:"error",message:n.message})):"cancelled"===n.type&&(r.close(),o({phase:"idle"}))},r.onerror=()=>{r.close(),o(e=>"success"===e.phase?e:{phase:"error",message:"Connection lost"})}},[e.id,t]),p=(0,i.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(e.id)}`,{method:"POST"}),o({phase:"idle"}),t()},[e.id,t]),h=(0,i.useCallback)(async(t,r)=>{if(r.trim()){o({phase:"progress",message:"Verifying…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r.trim()})});if(!n.ok){let e=await n.json().catch(()=>({}));o({phase:"error",message:e.error??`Server error ${n.status}`});return}s("")}catch(e){o({phase:"error",message:e instanceof Error?e.message:"Network error"})}}},[e.id]),g=(0,i.useCallback)(async(t,r)=>{o({phase:"progress",message:"Continuing…"});try{let n=await fetch(`/api/auth/login/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:t,code:r})});if(!n.ok){let e=await n.json().catch(()=>({}));o({phase:"error",message:e.error??`Server error ${n.status}`})}}catch(e){o({phase:"error",message:e instanceof Error?e.message:"Network error"})}},[e.id]),f="connecting"===r.phase||"progress"===r.phase||"auth"===r.phase||"device_code"===r.phase||"prompt"===r.phase||"select"===r.phase;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(im,{children:l("i18n.subscription")}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.loggedIn?"#4ade80":"var(--text-dim)"},children:l(e.loggedIn?"i18n.connected":"i18n.notConnected")})]})]}),(0,n.jsxs)("div",{style:{minHeight:48},children:["idle"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.loggedIn?"Already connected. You can re-login or disconnect.":`Connect your ${e.name} account.`}),"connecting"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:l("i18n.openingBrowser")}),"select"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:r.message}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.options.map(e=>(0,n.jsx)("button",{onClick:()=>g(r.token,e.id),style:{padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:e.label},e.id))})]}),("auth"===r.phase||"prompt"===r.phase)&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===r.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":r.message}),"auth"===r.phase&&(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,n.jsx)("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("input",{ref:c,value:a,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&h(r.token,a)},placeholder:"auth"===r.phase?"http://localhost:1455/auth/callback?code=…":r.placeholder??"Enter value…",style:{flex:1,padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,n.jsx)("button",{onClick:()=>h(r.token,a),disabled:!a.trim(),style:{padding:"6px 12px",background:a.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:a.trim()?"#fff":"var(--text-dim)",cursor:a.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:l("i18n.submit")})]})]}),"device_code"===r.phase&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Open the verification page and enter this code:"}),(0,n.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:16,fontWeight:700,fontFamily:"var(--font-mono)",letterSpacing:0},children:r.userCode}),(0,n.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,n.jsx)("a",{href:r.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:r.verificationUri}),r.expiresInSeconds?` Expires in ${Math.ceil(r.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:r.message}),"success"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:l("i18n.connectedSuccessfully")}),"error"===r.phase&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:r.message})]}),(0,n.jsx)("div",{style:{display:"flex",gap:8},children:f?(0,n.jsx)("button",{onClick:()=>{d.current?.close(),o({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:l("i18n.cancel")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:u,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:l(e.loggedIn?"i18n.relogin":"i18n.login")}),e.loggedIn&&(0,n.jsx)("button",{onClick:p,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:l("i18n.disconnect")})]})})]})}function iM({provider:e,onRefresh:t}){let[r,o]=(0,i.useState)(""),[l,a]=(0,i.useState)(!1),[s,d]=(0,i.useState)(!1),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(!1),{t:g}=(0,b.s)();(0,i.useEffect)(()=>{o(""),u(null),h(!1)},[e.id]);let f=(0,i.useCallback)(async()=>{if(r.trim()){a(!0),u(null),h(!1);try{let n=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:r.trim()})}),i=await n.json();!n.ok||i.error?u(i.error??`HTTP ${n.status}`):(o(""),h(!0),setTimeout(()=>h(!1),2e3),t())}catch(e){u(String(e))}finally{a(!1)}}},[r,e.id,t]),x=(0,i.useCallback)(async()=>{d(!0),u(null);try{let r=await fetch(`/api/auth/api-key/${encodeURIComponent(e.id)}`,{method:"DELETE"}),n=await r.json();!r.ok||n.error?u(n.error??`HTTP ${r.status}`):t()}catch(e){u(String(e))}finally{d(!1)}},[e.id,t]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(im,{children:"API Key"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:e.configured?"#4ade80":"var(--border)",display:"inline-block"}}),(0,n.jsx)("span",{style:{fontSize:11,color:e.configured?"#4ade80":"var(--text-dim)"},children:g(e.configured?"i18n.configured":"i18n.notConfigured")})]})]}),(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:e.configured?"API key is stored. Enter a new key below to replace it, or disconnect to remove it.":`Enter your ${e.displayName} API key to enable ${e.modelCount} model${1!==e.modelCount?"s":""}.`}),(0,n.jsx)(id,{label:"API Key",children:(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)(ip,{value:r,onChange:o,onKeyDown:e=>{"Enter"===e.key&&r.trim()&&f()},placeholder:e.configured?"Enter new key to replace…":"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,n.jsxs)("button",{onClick:f,disabled:l||!r.trim()||p,style:{padding:"6px 12px",background:p?"#16a34a":r.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:r.trim()||p?"#fff":"var(--text-dim)",cursor:l||!r.trim()||p?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[p&&(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),g(p?"i18n.saved":l?"i18n.saving":"i18n.save")]})]})}),c&&(0,n.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c}),e.configured&&(0,n.jsx)("button",{onClick:x,disabled:s,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:s?"not-allowed":"pointer",fontSize:12},children:g(s?"i18n.removing":"i18n.disconnect")})]})}function iR({id:e,size:t}){let r=ia[e];if(!r){let r=e.split(/[-_]/).filter(Boolean).slice(0,2).map(e=>e[0]).join("").toUpperCase()||"?";return(0,n.jsx)("span",{"aria-hidden":"true",style:{width:t,height:t,border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,fontSize:Math.max(8,Math.floor(.42*t)),fontWeight:700,lineHeight:1},children:r})}return r.hasColor?(0,n.jsx)(r.Icon,{size:t}):(0,n.jsx)(r.Icon,{size:t,style:{color:"var(--text-muted)"}})}function iI({oauthProviders:e,apiKeyProviders:t,onSelectOAuth:r,onSelectApiKey:o,onAddCustom:l,onClose:a}){let[s,d]=(0,i.useState)(""),{t:c}=(0,b.s)(),u=(0,i.useRef)(null);(0,i.useEffect)(()=>{setTimeout(()=>u.current?.focus(),30)},[]);let p=s.trim().toLowerCase(),h=e.filter(e=>!e.loggedIn&&(!p||e.name.toLowerCase().includes(p))),g=t.filter(e=>!e.configured&&(!p||e.displayName.toLowerCase().includes(p)||e.id.toLowerCase().includes(p))),f=!p||"custom".includes(p)||"openai-compatible".includes(p)||"anthropic-compatible".includes(p),x=h.length+g.length+ +!!f,m={display:"flex",flexDirection:"row",alignItems:"center",gap:8,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,boxSizing:"border-box",cursor:"pointer",minWidth:0,textAlign:"left",transition:"border-color 0.12s, background 0.12s",width:"100%"};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&a()},children:(0,n.jsxs)("div",{style:{width:820,maxWidth:"calc(100vw - 32px)",maxHeight:"min(72vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",flexShrink:0,display:"flex",alignItems:"center",gap:8},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,n.jsx)("input",{ref:u,value:s,onChange:e=>d(e.target.value),onKeyDown:e=>{"Escape"===e.key&&a()},placeholder:c("i18n.searchProviders"),style:{flex:1,background:"none",border:"none",outline:"none",color:"var(--text)",fontSize:13,boxSizing:"border-box"}})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:14},children:0===x?(0,n.jsx)("div",{style:{padding:"20px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:c("i18n.noProviders")}):(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(240px, 100%), 1fr))",gap:8},children:[f&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:c("i18n.custom")}),f&&(0,n.jsxs)("button",{onClick:()=>{l(),a()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"OpenAI / Anthropic compatible"}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:c("i18n.customEndpoint")})]}),(0,n.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px dashed var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)"},children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),h.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!f,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:c("i18n.subscriptions")}),h.map(e=>(0,n.jsxs)("button",{onClick:()=>{r(e.id),a()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OAuth"})]}),(0,n.jsx)(iR,{id:e.id,size:28})]},e.id)),g.length>0&&(0,n.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(h.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),g.map(e=>(0,n.jsxs)("button",{onClick:()=>{o(e.id),a()},style:m,onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:[e.modelCount," models"]})]}),(0,n.jsx)(iR,{id:e.id,size:28})]},e.id))]})})]})})}function iL({onClose:e}){let t=(0,ro.a)(),{t:r}=(0,b.s)(),[o,l]=(0,i.useState)({providers:{}}),[a,s]=(0,i.useState)(!0),[d,c]=(0,i.useState)(!1),[u,p]=(0,i.useState)(null),[h,g]=(0,i.useState)(!1),[f,x]=(0,i.useState)(null),[m,v]=(0,i.useState)([]),[y,k]=(0,i.useState)([]),[w,j]=(0,i.useState)(!1),S=(0,i.useCallback)(()=>{fetch("/api/auth/providers").then(e=>e.json()).then(e=>{Array.isArray(e.providers)&&v(e.providers)}).catch(()=>{})},[]),C=(0,i.useCallback)(()=>{fetch("/api/auth/all-providers").then(e=>e.json()).then(e=>{Array.isArray(e.providers)&&k(e.providers)}).catch(()=>{})},[]),T=(0,i.useCallback)(()=>{S(),C()},[S,C]);(0,i.useEffect)(()=>{fetch("/api/models-config").then(e=>e.json()).then(e=>{let t=e.providers?e:{...e,providers:{}};l(t);let r=Object.keys(t.providers??{});r.length>0&&x({type:"provider",name:r[0]})}).catch(()=>l({providers:{}})).finally(()=>s(!1)),T()},[T]);let M=(0,i.useCallback)(()=>{let e="new-provider",t=1;for(;o.providers?.[e];)e=`new-provider-${t++}`;l(t=>({...t,providers:{...t.providers??{},[e]:{api:"openai-completions"}}})),x({type:"provider",name:e})},[o.providers]),R=(0,i.useCallback)((e,t)=>{l(r=>({...r,providers:{...r.providers??{},[e]:t}}))},[]),I=(0,i.useCallback)((e,t)=>{l(r=>{let n=Object.entries(r.providers??{}),i=n.findIndex(([t])=>t===e);return -1===i?r:(n[i]=[t,n[i][1]],{...r,providers:Object.fromEntries(n)})}),x(r=>r?"provider"===r.type&&r.name===e?{type:"provider",name:t}:"model"===r.type&&r.providerName===e?{...r,providerName:t}:r:r)},[]),L=(0,i.useCallback)(e=>{l(t=>{let r={...t.providers??{}};return delete r[e],{...t,providers:r}}),l(e=>{let t=Object.keys(e.providers??{});return x(t.length>0?{type:"provider",name:t[0]}:null),e})},[]),E=(0,i.useCallback)(e=>{l(t=>{let r=t.providers?.[e]??{},n=[...r.models??[],{id:""}];return{...t,providers:{...t.providers??{},[e]:{...r,models:n}}}}),l(t=>{let r=(t.providers?.[e]?.models?.length??1)-1;return x({type:"model",providerName:e,index:r}),t})},[]),W=(0,i.useCallback)((e,t)=>{l(r=>{let n=r.providers?.[e]??{},i=[...n.models??[]],o=new Set(i.map(e=>e.id));for(let e of t)o.has(e.id)||(o.add(e.id),i.push({id:e.id,name:e.name}));return{...r,providers:{...r.providers??{},[e]:{...n,models:i}}}})},[]),z=(0,i.useCallback)((e,t,r)=>{l(n=>{let i=n.providers?.[e]??{},o=[...i.models??[]];return o[t]=r,{...n,providers:{...n.providers??{},[e]:{...i,models:o}}}})},[]),$=(0,i.useCallback)((e,t)=>{l(r=>{let n=r.providers?.[e]??{},i=[...n.models??[]];return i.splice(t,1),{...r,providers:{...r.providers??{},[e]:{...n,models:i.length?i:void 0}}}}),x({type:"provider",name:e})},[]),P=(0,i.useCallback)(async()=>{c(!0),p(null),g(!1);try{let e=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}),t=await e.json();!e.ok||t.error?p(t.error??`HTTP ${e.status}`):(g(!0),setTimeout(()=>g(!1),2e3))}catch(e){p(String(e))}finally{c(!1)}},[o]),A=Object.entries(o.providers??{}),D=m.filter(e=>e.loggedIn),N=y.filter(e=>e.configured),F=(()=>{if(!f)return null;if("oauth"===f.type){let e=m.find(e=>e.id===f.providerId);return e?(0,n.jsx)(iT,{provider:e,onRefresh:T},e.id):null}if("apikey"===f.type){let e=y.find(e=>e.id===f.providerId);return e?(0,n.jsx)(iM,{provider:e,onRefresh:T},e.id):null}if("provider"===f.type){let e=o.providers?.[f.name];return e?(0,n.jsx)(iv,{name:f.name,provider:e,onChange:e=>R(f.name,e),onRename:e=>I(f.name,e),onDelete:()=>L(f.name),onAddModels:e=>W(f.name,e)},f.name):null}let e=o.providers?.[f.providerName],t=e?.models?.[f.index];return t?(0,n.jsx)(iC,{providerName:f.providerName,provider:e,model:t,onChange:e=>z(f.providerName,f.index,e),onDelete:()=>$(f.providerName,f.index)},`${f.providerName}-${f.index}`):null})();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:t=>{t.target===t.currentTarget&&e()},children:(0,n.jsxs)("div",{style:{width:t?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:t?"calc(100dvh - 16px)":"78vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:r("common.models")}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"})]}),(0,n.jsx)("button",{onClick:e,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:t?"column":"row",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:t?"100%":210,maxHeight:t?"40vh":void 0,borderRight:t?"none":"1px solid var(--border)",borderBottom:t?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[D.map(e=>{let t=f?.type==="oauth"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>x({type:"oauth",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)(iR,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]},e.id)}),N.map(e=>{let t=f?.type==="apikey"&&f.providerId===e.id;return(0,n.jsxs)("div",{onClick:()=>x({type:"apikey",providerId:e.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)(iR,{id:e.id,size:16}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName})]},e.id)}),(D.length>0||N.length>0)&&A.length>0&&(0,n.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),a?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:r("i18n.loading")}):A.map(([e,t])=>{let i=f?.type==="provider"&&f.name===e,o=t.models??[];return(0,n.jsxs)("div",{style:{marginBottom:2},children:[(0,n.jsxs)("div",{onClick:()=>x({type:"provider",name:e}),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:i?"var(--bg-selected)":"none"},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:i?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),o.map((t,i)=>{let o=f?.type==="model"&&f.providerName===e&&f.index===i;return(0,n.jsxs)("div",{onClick:()=>x({type:"model",providerName:e,index:i}),style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:o?"var(--bg-selected)":"none"},onMouseEnter:e=>{o||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{o||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:t.id?"var(--text-muted)":"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.id||r("i18n.newModel")}),t.reasoning&&(0,n.jsx)("span",{style:{fontSize:9,padding:"1px 4px",background:"rgba(99,102,241,0.12)",color:"rgba(99,102,241,0.8)",borderRadius:3,flexShrink:0},children:"T"})]},i)}),(0,n.jsx)("div",{onClick:t=>{t.stopPropagation(),E(e)},style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px 4px 26px",borderRadius:5,cursor:"pointer",color:"var(--text-dim)"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-dim)",e.currentTarget.style.background="none"},children:(0,n.jsxs)("span",{style:{fontSize:11},children:["+ ",r("i18n.model")]})})]},e)})]}),(0,n.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,n.jsxs)("button",{onClick:()=>j(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:"100%",padding:"6px 0",background:"none",border:"1px dashed var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.color="var(--text-muted)"},children:["+ ",r("i18n.addProvider")]})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:a?null:F??(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:r("i18n.selectProviderModel")})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[u&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:u}),(0,n.jsx)("button",{onClick:e,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:r("i18n.cancel")}),(0,n.jsxs)("button",{onClick:P,disabled:d||h,style:{position:"relative",padding:"6px 16px",minWidth:92,background:h?"#16a34a":d?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:h?"#fff":d?"var(--text-muted)":"#fff",cursor:d||h?"default":"pointer",fontSize:13,fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,transition:"background-color 0.2s ease, color 0.2s ease",animation:h?"saved-pop 0.45s ease":void 0},children:[h&&(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0},children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,n.jsx)("span",{children:h?r("i18n.saved"):d?r("i18n.saving"):r("i18n.save")})]})]})]})}),w&&(0,n.jsx)(iI,{oauthProviders:m,apiKeyProviders:y,onSelectOAuth:e=>x({type:"oauth",providerId:e}),onSelectApiKey:e=>x({type:"apikey",providerId:e}),onAddCustom:M,onClose:()=>j(!1)})]})}function iE(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function iW(e){let t=e.sourceInfo?.source,r=e.sourceInfo?.scope;return"user"===r||"user"===t?"global":"project"===r||"project"===t?"project":"path"}function iz(e){let t=iW(e);return"path"===t?t:e.install?.skillsShUrl?`${t} / skills.sh`:t}function i$(e){return e.install?`${e.install.scope}\0${e.install.package}`:null}function iP(e){return e?e.slice(0,8):"unknown"}function iA({enabled:e,loading:t,onToggle:r}){let{t:i}=(0,b.s)();return(0,n.jsx)("button",{onClick:r,disabled:t,title:i(e?"i18n.visibleInPrompt":"i18n.hiddenFromPrompt"),style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:t?"wait":"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none"},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:e?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function iD({skill:e,cwd:t,onToggle:r,toggling:i,saveError:o,updateStatus:l,checkingUpdate:a,updating:s,updateError:d,onCheckUpdate:c,onUpdate:u}){let{t:p}=(0,b.s)(),h=iW(e),g=!e.disableModelInvocation;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===h?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===h?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:h}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(e){if("project"===h&&e.startsWith(t)){let r=e.slice(t.length).replace(/^[/\\]/,"");return`./${r}`}return iE(e)}(e.filePath)}),(0,n.jsx)(iA,{enabled:g,loading:i,onToggle:()=>r(e)})]}),(0,n.jsxs)("div",{style:{minHeight:16,display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,flexWrap:"wrap",textAlign:"right"},children:[!g&&(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:p("i18n.hiddenButInvocable")}),o&&(0,n.jsx)("span",{style:{fontSize:12,color:"#f87171",overflowWrap:"anywhere"},children:o})]})]}),e.install?.skillsShUrl&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Source"}),(0,n.jsx)("a",{href:e.install.skillsShUrl,target:"_blank",rel:"noreferrer",title:e.install.skillsShUrl,style:{display:"flex",alignItems:"center",gap:8,width:"fit-content",maxWidth:"100%",color:"var(--accent)",textDecoration:"none"},children:(0,n.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e.install.skillsShUrl.replace(/^https?:\/\//,"")," ↗"]})})]}),e.install&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Version"}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-muted)"},children:iP(l?.currentVersion??e.install.versionHash)}),e.install.canCheckForUpdates&&(0,n.jsx)("button",{onClick:c,disabled:a||s,style:{padding:"4px 9px",border:"1px solid var(--border)",borderRadius:5,background:"none",color:"var(--text-muted)",cursor:a||s?"not-allowed":"pointer",opacity:a||s?.5:1,fontSize:11},children:p("i18n.check")}),l?.state==="update-available"&&(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"#d97706"},children:iP(l.latestVersion)}),(a||l&&"update-available"!==l.state)&&(0,n.jsx)("span",{style:{fontSize:12,color:a?"var(--accent)":l?.state==="up-to-date"?"#16a34a":l?.state==="error"?"#ef4444":"var(--text-dim)"},children:a?p("i18n.checking"):l?.state==="up-to-date"?p("i18n.upToDate"):l?.state==="unsupported"?p("i18n.automaticChecksUnavailable"):l?.message||p("i18n.checkFailed")}),l?.state==="update-available"&&(0,n.jsx)("button",{onClick:u,disabled:s||a,style:{padding:"4px 10px",border:"none",borderRadius:5,background:"var(--accent)",color:"#fff",cursor:s||a?"not-allowed":"pointer",opacity:s||a?.5:1,fontSize:11,fontWeight:600},children:p(s?"i18n.updating":"i18n.update")})]}),d&&(0,n.jsx)("span",{style:{fontSize:12,color:"#ef4444"},children:d})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Name"}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:e.name})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Description"}),(0,n.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:e.description})]})]})}function iN({cwd:e,installedPackages:t,projectResourcesLoaded:r,onInstalled:o}){let{t:l}=(0,b.s)(),[a,s]=(0,i.useState)(""),[d,c]=(0,i.useState)([]),[u,p]=(0,i.useState)(!1),[h,g]=(0,i.useState)(null),[f,x]=(0,i.useState)(null),[m,v]=(0,i.useState)(null),[y,k]=(0,i.useState)(new Set),[w,j]=(0,i.useState)("global"),S=(0,i.useRef)(null);(0,i.useEffect)(()=>{S.current?.focus()},[]);let C=(0,i.useCallback)(async e=>{if(e.trim()){p(!0),g(null),c([]);try{let t=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:e.trim()})}),r=await t.json();if(r.error)return void g(r.error);c(r.results??[]),0===(r.results??[]).length&&g("No skills found")}catch(e){g(String(e))}finally{p(!1)}}},[]),T=(0,i.useCallback)(async t=>{x(t),v(null);try{let r=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:t,scope:w,cwd:e})}),n=await r.json();if(!r.ok||n.error)return void v(n.error??`HTTP ${r.status}`);k(e=>new Set(e).add(`${w}:${t}`)),o()}catch(e){v(String(e))}finally{x(null)}},[o,w,e]),M="global"===w?"~/.pi/agent/skills/":`${iE(e)}/.pi/skills/`;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:l("i18n.addSkill")}),(0,n.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,n.jsx)("input",{ref:S,value:a,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&C(a)},placeholder:l("i18n.skillSearchPlaceholder"),style:{flex:1,padding:"7px 10px",fontSize:13,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,n.jsx)("button",{onClick:()=>C(a),disabled:u||!a.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:u||!a.trim()?"not-allowed":"pointer",opacity:u||!a.trim()?.5:1,flexShrink:0},children:u?l("i18n.searching"):l("i18n.search")})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,n.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(e=>(0,n.jsx)("button",{onClick:()=>{("global"===e||r)&&j(e)},disabled:"project"===e&&!r,title:"project"!==e||r?void 0:l("trust.projectScopeUnavailable"),style:{padding:"3px 10px",border:"none",cursor:"project"!==e||r?"pointer":"not-allowed",background:w===e?"var(--bg-selected)":"none",color:w===e?"var(--text)":"var(--text-dim)",fontWeight:w===e?600:400,opacity:"project"!==e||r?1:.45,borderRight:"global"===e?"1px solid var(--border)":"none"},children:e},e))}),(0,n.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",M]})]}),h&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:h}),m&&(0,n.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:m})]}),d.length>0?(0,n.jsx)("div",{style:{flex:1,overflowY:"auto"},children:d.map(e=>{let r=t[w].has(e.package)||y.has(`${w}:${e.package}`),i=f===e.package,o=e.package.indexOf("@"),a=o>-1?e.package.slice(0,o):e.package,s=o>-1?e.package.slice(o+1):null;return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,n.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:s??a}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:a}),(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:e.installs}),e.url&&(0,n.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,n.jsx)("button",{onClick:()=>!r&&!i&&T(e.package),disabled:r||i||null!==f,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:r||i||null!==f?"not-allowed":"pointer",background:r?"rgba(34,197,94,0.1)":"none",color:r?"#16a34a":i?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:r?`✓ ${l("i18n.installed")}`:i?l("i18n.installing"):l("i18n.install")})]},e.package)})}):!h&&!u&&(0,n.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,n.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"})," ","to discover and install skills for your agent."]})]})}function iF({cwd:e,onClose:t}){let r=(0,ro.a)(),{t:o}=(0,b.s)(),[l,a]=(0,i.useState)([]),[s,d]=(0,i.useState)(!0),[c,u]=(0,i.useState)(null),[p,h]=(0,i.useState)(null),[g,f]=(0,i.useState)(new Set),[x,m]=(0,i.useState)(null),[v,y]=(0,i.useState)(!1),[k,w]=(0,i.useState)({}),[j,S]=(0,i.useState)(new Set),[C,T]=(0,i.useState)(!1),[M,R]=(0,i.useState)(null),[I,L]=(0,i.useState)(null),[E,W]=(0,i.useState)(!0),[z,$]=(0,i.useState)({}),P=(0,i.useCallback)(async()=>{d(!0),u(null);try{let t=await fetch(`/api/skills?cwd=${encodeURIComponent(e)}`),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);let n=r.skills??[];if(a(n),W(r.projectResourcesLoaded??!0),n.length>0&&!p){let e=n.find(e=>!e.disableModelInvocation)??n[0];h(e.filePath),e.disableModelInvocation&&$(t=>({...t,[iz(e)]:!0}))}return n}catch(e){return u(String(e)),[]}finally{d(!1)}},[e,p]);(0,i.useEffect)(()=>{w({}),L(null),P()},[e]);let A=(0,i.useCallback)(async t=>{let r=(t?[t]:l.filter(e=>!!e.install)).map(i$).filter(e=>!!e);if(0!==r.length){L(null),S(e=>new Set([...e,...r])),t||T(!0);try{let r=await fetch("/api/skills/check",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,package:t?.install?.package,scope:t?.install?.scope})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);w(e=>{let t={...e};for(let e of n.updates??[])t[`${e.scope}\0${e.package}`]=e;return t})}catch(e){L(e instanceof Error?e.message:String(e))}finally{S(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t||T(!1)}}},[e,l]),D=(0,i.useCallback)(async t=>{if(!t.install)return;let r=i$(t);R(r),L(null);try{let n=await fetch("/api/skills/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,package:t.install.package,scope:t.install.scope})}),i=await n.json();if(!n.ok||i.error||!i.success)throw Error(i.error??`HTTP ${n.status}`);await P();let o=i.skill?.install?.versionHash;w(e=>({...e,[r]:{package:t.install.package,scope:t.install.scope,state:"up-to-date",currentVersion:o,latestVersion:o}}))}catch(e){L(e instanceof Error?e.message:String(e))}finally{R(null)}},[e,P]),N=(0,i.useCallback)(async e=>{let t=!e.disableModelInvocation;f(t=>new Set(t).add(e.filePath)),m(null);try{let r=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:e.filePath,disableModelInvocation:t})}),n=await r.json();if(!r.ok||n.error)return void m(n.error??`HTTP ${r.status}`);a(r=>r.map(r=>r.filePath===e.filePath?{...r,disableModelInvocation:t}:r)),t&&$(t=>({...t,[iz(e)]:!0}))}catch(e){m(String(e))}finally{f(t=>{let r=new Set(t);return r.delete(e.filePath),r})}},[]),F=l.find(e=>e.filePath===p)??null;return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&t()},children:(0,n.jsxs)("div",{style:{width:r?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:r?"calc(100dvh - 16px)":"78vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:o("common.skills")}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:iE(e)})]}),(0,n.jsx)("button",{onClick:t,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),!E&&(0,n.jsx)("div",{role:"status",style:{padding:"8px 18px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:12},children:o("trust.skillsNotLoaded")}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:r?"column":"row",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:r?"100%":210,maxHeight:r?"40vh":void 0,borderRight:r?"none":"1px solid var(--border)",borderBottom:r?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:s?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:o("i18n.loading")}):c?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:c}):0===l.length?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:o("i18n.noSkills")}):(()=>{let e=[];for(let{label:t,matches:r}of[{label:"project / skills.sh",matches:e=>"project"===iW(e)&&!!e.install?.skillsShUrl},{label:"project",matches:e=>"project"===iW(e)&&!e.install?.skillsShUrl},{label:"global / skills.sh",matches:e=>"global"===iW(e)&&!!e.install?.skillsShUrl},{label:"global",matches:e=>"global"===iW(e)&&!e.install?.skillsShUrl},{label:"path",matches:e=>"path"===iW(e)}]){let n=l.filter(r);n.length>0&&e.push({label:t,skills:n})}let t=e=>{let t,r,i=!v&&p===e.filePath,l=e.disableModelInvocation;return(0,n.jsxs)("div",{onClick:()=>{h(e.filePath),y(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:i?"var(--bg-selected)":"none"},onMouseEnter:e=>{i||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{i||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:l?"var(--border)":"var(--accent)",boxShadow:l?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,n.jsx)("span",{style:{fontSize:12,fontWeight:i?600:400,color:l?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(r=(t=i$(e))?k[t]:void 0,r?.state!=="update-available"?null:(0,n.jsx)("span",{title:o("i18n.updateAvailable"),style:{color:"#d97706",fontSize:13,lineHeight:1,flexShrink:0},children:"↑"}))]},e.filePath)};return e.map(({label:e,skills:r})=>{let i=r.filter(e=>!e.disableModelInvocation),l=r.filter(e=>e.disableModelInvocation),a=z[e]??!1;return(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:e}),i.map(t),l.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{onClick:()=>$(t=>({...t,[e]:!a})),style:{display:"flex",alignItems:"center",gap:5,padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",cursor:"pointer",userSelect:"none"},children:[(0,n.jsx)("span",{style:{fontSize:8},children:a?"▾":"▸"}),o("i18n.dormant")," (",l.length,")"]}),a&&l.map(t)]})]},e)})})()}),(0,n.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("div",{onClick:()=>y(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:v?"var(--bg-selected)":"none",color:v?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{v||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{v||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),o("i18n.addSkill")]})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:v?(0,n.jsx)(iN,{cwd:e,projectResourcesLoaded:E,installedPackages:{global:new Set(l.filter(e=>e.install?.scope==="global").map(e=>e.install.package)),project:new Set(l.filter(e=>e.install?.scope==="project").map(e=>e.install.package))},onInstalled:()=>{P()}}):s?null:F?(0,n.jsx)(iD,{skill:F,cwd:e,onToggle:N,toggling:g.has(F.filePath),saveError:x,updateStatus:i$(F)?k[i$(F)]:void 0,checkingUpdate:!!i$(F)&&j.has(i$(F)),updating:M===i$(F),updateError:I,onCheckUpdate:()=>void A(F),onUpdate:()=>void D(F)},F.filePath):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:o("i18n.selectSkill")})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[l.some(e=>!!e.install)&&(0,n.jsx)("button",{onClick:()=>void A(),disabled:C||null!==M,style:{padding:"6px 12px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:C||null!==M?"not-allowed":"pointer",opacity:C||null!==M?.5:1,fontSize:12},children:C?o("i18n.checking"):o("i18n.checkUpdates")}),Object.values(k).filter(e=>"update-available"===e.state).length>0&&(0,n.jsxs)("span",{style:{fontSize:12,color:"#d97706"},children:[Object.values(k).filter(e=>"update-available"===e.state).length," ",1===Object.values(k).filter(e=>"update-available"===e.state).length?o("i18n.update"):o("i18n.updates")]})]}),(0,n.jsx)("button",{onClick:t,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:o("i18n.close")})]})]})})}function iB(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function iH(e){let t=e.trim().match(/^\$?\s*pi\s+install\s+(\S+)\s*$/);return t?.[1]??e}function iO(e){return`${e.scope}\0${e.source}`}function iU(e,t){if(e.disabled)return t("i18n.disabled");let r=[e.counts.extensions?t("i18n.resourceCount",{count:e.counts.extensions,label:t("i18n.extensionShort")}):"",e.counts.skills?t("i18n.resourceCount",{count:e.counts.skills,label:t("i18n.skillShort")}):"",e.counts.prompts?t("i18n.resourceCount",{count:e.counts.prompts,label:t("i18n.promptShort")}):"",e.counts.themes?t("i18n.resourceCount",{count:e.counts.themes,label:t("i18n.themeShort")}):""].filter(Boolean);return r.length?r.join(" \xb7 "):t("i18n.noResources")}function i_(e,t){let r=[];return e.version&&r.push(t("i18n.installedVersion",{version:e.version})),e.configuredVersion&&r.push(t("i18n.configuredVersion",{version:e.configuredVersion})),r.length?r.join(" \xb7 "):t("i18n.unknown")}function iq(e){return"loaded"===e?"var(--accent)":"installed"===e?"#f59e0b":"disabled"===e?"var(--text-dim)":"#ef4444"}function iK({pkg:e}){let{t}=(0,b.s)(),r=[["extension",t("i18n.extensions")],["skill",t("i18n.skills")],["prompt",t("i18n.prompts")],["theme",t("i18n.themes")]].map(([t,r])=>({kind:t,label:r,resources:e.resources.filter(e=>e.kind===t)})).filter(e=>e.resources.length>0);return 0===r.length?(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)"},children:t(e.disabled?"i18n.packageDisabled":"i18n.noResolvedResources")}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:r.map((e,t)=>(0,n.jsxs)("div",{style:{borderTop:0===t?"none":"1px solid var(--border)",paddingTop:12*(0!==t)},children:[(0,n.jsx)("div",{style:{fontSize:10,fontWeight:700,color:"var(--text-dim)",textTransform:"uppercase",marginBottom:6},children:e.label}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.resources.map(e=>(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.path,children:e.name}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:1},title:e.path,children:e.relativePath})]},`${e.kind}:${e.path}`))})]},e.kind))})}function iV({scope:e}){return(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===e?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===e?"rgba(99,102,241,0.85)":"var(--text-dim)"},children:e})}function iJ(e,t){return{padding:"6px 12px",background:t?"rgba(239,68,68,0.08)":"none",border:"1px solid var(--border)",borderRadius:6,color:t?"#ef4444":"var(--text-muted)",cursor:e?"not-allowed":"pointer",fontSize:12,opacity:e?.5:1}}function iY({enabled:e,loading:t,onToggle:r,label:i}){return(0,n.jsx)("button",{type:"button",onClick:r,disabled:t,title:i,"aria-label":i,"aria-pressed":e,style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:t?"wait":"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none",opacity:t?.65:1},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:e?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function iX({value:e,projectResourcesLoaded:t,onChange:r}){let{t:i}=(0,b.s)();return(0,n.jsx)("div",{style:{display:"inline-flex",border:"1px solid var(--border)",borderRadius:7,overflow:"hidden",height:30},children:["global","project"].map(o=>{let l=e===o,a="project"===o&&!t;return(0,n.jsx)("button",{onClick:()=>{a||r(o)},disabled:a,title:a?i("trust.projectScopeUnavailable"):void 0,style:{width:76,border:"none",borderRight:"global"===o?"1px solid var(--border)":"none",background:l?"var(--bg-selected)":"none",color:l?"var(--text)":"var(--text-muted)",cursor:a?"not-allowed":"pointer",opacity:a?.45:1,fontSize:12},children:o},o)})})}function iZ({cwd:e,source:t,scope:r,projectResourcesLoaded:o,busy:l,actionError:a,onSourceChange:s,onScopeChange:d,onInstall:c}){let{t:u}=(0,b.s)(),p=(0,i.useRef)(null);return(0,i.useEffect)(()=>{p.current?.focus()},[]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:18,maxWidth:660,minHeight:"100%"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:u("i18n.addPlugin")}),(0,n.jsxs)("a",{href:"https://pi.dev/packages",target:"_blank",rel:"noopener noreferrer",style:{display:"inline-flex",alignItems:"center",gap:5,color:"var(--accent)",fontSize:12,textDecoration:"none",whiteSpace:"nowrap"},children:[(0,n.jsxs)("svg",{width:"28",height:"28",viewBox:"0 0 800 800","aria-hidden":"true",focusable:"false",style:{flexShrink:0},children:[(0,n.jsx)("path",{fill:"#000",fillRule:"evenodd",d:"M165.29 165.29H517.36V400H400V517.36H282.65V634.72H165.29ZM282.65 282.65V400H400V282.65Z"}),(0,n.jsx)("path",{fill:"#000",d:"M517.36 400H634.72V634.72H517.36Z"})]}),"pi.dev/packages"]})]}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:"project"===r?`${iB(e)}/.pi/agent/{npm,git}`:"~/.pi/agent/{npm,git}"})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("label",{htmlFor:"plugin-source",style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:"Source"}),(0,n.jsx)("input",{id:"plugin-source",ref:p,value:t,onChange:e=>s(e.target.value),onPaste:e=>{let t=w(e.clipboardData),r=t.length>0?t[0]:e.clipboardData.getData("text"),n=iH(r);(n!==r||0!==t.length)&&(e.preventDefault(),s(n))},onBlur:e=>s(iH(e.currentTarget.value)),placeholder:"npm:@scope/package",style:{width:"100%",height:36,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,outline:"none"},onKeyDown:e=>{"Enter"===e.key&&t.trim()&&!l&&c()}})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)(iX,{value:r,projectResourcesLoaded:o,onChange:d}),(0,n.jsx)("button",{type:"button",onClick:c,disabled:l||!t.trim(),style:{...iJ(l||!t.trim()),background:"var(--accent)",color:"white",borderColor:"var(--accent)"},children:u(l?"i18n.installing":"i18n.install")})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text-muted)"},children:"Examples"}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:["npm:@scope/pi-plugin","git:https://github.com/user/repo","/absolute/path/to/plugin"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>s(e),style:{width:"100%",minHeight:30,textAlign:"left",padding:"6px 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-dim)",cursor:"pointer",fontFamily:"var(--font-mono)",fontSize:11},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text-muted)"},onMouseLeave:e=>{e.currentTarget.style.background="var(--bg-panel)",e.currentTarget.style.color="var(--text-dim)"},children:e},e))})]}),a&&(0,n.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:a})]})}function iG({pkg:e,cwd:t,busyKey:r,actionError:i,actionMessage:o,sessionId:l,onAction:a,onReloadSession:s}){let{t:d}=(0,b.s)(),c=iO(e),u=r?.endsWith(c)??!1,p="reload"===r,h=!e.disabled;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20,maxWidth:680},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,minWidth:0,flexWrap:"wrap"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:180,flex:1},children:[(0,n.jsx)(iY,{enabled:h,loading:u||p,onToggle:()=>a(e.disabled?"enable":"disable",e),label:d(e.disabled?"i18n.enablePackage":"i18n.disablePackage")}),(0,n.jsx)(iV,{scope:e.scope}),e.disabled?(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(120,120,120,0.12)",color:"var(--text-dim)"},children:d("i18n.disabled")}):e.filtered&&(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(245,158,11,0.12)",color:"#d97706"},children:d("i18n.filtered")}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,n.jsx)("button",{onClick:()=>a("update",e),disabled:u||p,style:iJ(u||p),children:d(r===`update:${c}`?"i18n.updating":"i18n.update")}),(0,n.jsx)("button",{onClick:s,disabled:!l||p||u,style:iJ(!l||p||u),title:d(l?"i18n.reloadSession":"i18n.openSessionToReload"),children:d(p?"i18n.reloading":"i18n.reloadSession")}),(0,n.jsx)("button",{onClick:()=>a("remove",e),disabled:u||p,style:iJ(u||p,!0),children:d(r===`remove:${c}`?"i18n.removing":"i18n.remove")})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(96px, 130px) minmax(0, 1fr)",gap:"9px 14px",fontSize:12,lineHeight:1.45},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.status")}),(0,n.jsx)("div",{style:{color:iq(e.status),textTransform:"capitalize"},children:e.status}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.version")}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:i_(e,d)}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.package")}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.packageName??d("i18n.unknown")}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.resources")}),(0,n.jsx)("div",{style:{color:"var(--text-muted)"},children:iU(e,d)}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.installedPath")}),(0,n.jsx)("div",{style:{color:e.installedPath?"var(--text-muted)":"#ef4444",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:e.installedPath?iB(e.installedPath):d("i18n.notFound")}),(0,n.jsx)("div",{style:{color:"var(--text-dim)"},children:d("i18n.cwd")}),(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:iB(t)})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:d("i18n.resolvedResources")}),(0,n.jsx)(iK,{pkg:e})]}),o&&(0,n.jsx)("div",{style:{fontSize:12,color:"#16a34a"},children:o}),i&&(0,n.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:i})]})}function iQ({cwd:e,sessionId:t,onClose:r,onReloaded:o}){let l=(0,ro.a)(),{t:a}=(0,b.s)(),[s,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(!0),[p,h]=(0,i.useState)(null),[g,f]=(0,i.useState)(null),[x,m]=(0,i.useState)(!1),[v,y]=(0,i.useState)(""),[k,w]=(0,i.useState)("global"),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[M,R]=(0,i.useState)(null),I=(0,i.useMemo)(()=>s?.packages??[],[s?.packages]),L=I.find(e=>iO(e)===g)??null,E=s?.projectResourcesLoaded??!0,W=(0,i.useMemo)(()=>["project","global"].map(e=>({scope:e,packages:I.filter(t=>t.scope===e)})).filter(e=>e.packages.length>0),[I]),z=(0,i.useCallback)(async()=>{u(!0),h(null);try{let t=await fetch(`/api/plugins?cwd=${encodeURIComponent(e)}`),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);d(r),m(e=>0===r.packages.length||e),f(e=>e&&r.packages.some(t=>iO(t)===e)?e:r.packages[0]?iO(r.packages[0]):null)}catch(e){h(e instanceof Error?e.message:String(e))}finally{u(!1)}},[e]);(0,i.useEffect)(()=>{z()},[z]);let $=(0,i.useCallback)(async(t,r)=>{let n=iO(r);S(`${t}:${n}`),T(null),R(null);try{let n=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,source:r.source,scope:r.scope,cwd:e})}),i=await n.json();if(!n.ok||i.error)throw Error(i.error??`HTTP ${n.status}`);d(i),"remove"===t?(f(i.packages[0]?iO(i.packages[0]):null),0===i.packages.length&&m(!0),R("Package removed.")):R({install:"Package installed.",update:"Package updated.",disable:"Package disabled.",enable:"Package enabled."}[t])}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}},[e]),P=(0,i.useCallback)(async()=>{let t=iH(v).trim();if(!t)return;y(t);let r=`${k}\0${t}`;S(`install:${r}`),T(null),R(null);try{var n;let i,o,l=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"install",source:t,scope:k,cwd:e})}),a=await l.json();if(!l.ok||a.error)throw Error(a.error??`HTTP ${l.status}`);d(a);let s=(n=a.packages,o=(i=t.trim()).startsWith("npm:")?i.slice(4):i,n.find(e=>e.scope===k&&e.source===i)??n.find(e=>e.scope===k&&e.source===`npm:${o}`)??n.find(e=>e.scope===k&&e.source.endsWith(i)));f(s?iO(s):r),m(!1),y(""),R("Package installed.")}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}},[e,k,v]),A=(0,i.useCallback)(async()=>{if(t){S("reload"),T(null),R(null);try{await rJ(t,{type:"reload"}),o?.(),await z(),R("Session reloaded.")}catch(e){T(e instanceof Error?e.message:String(e))}finally{S(null)}}},[z,o,t]),D=j?.startsWith("install:")??!1;return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:e=>{e.target===e.currentTarget&&r()},children:(0,n.jsxs)("div",{style:{width:l?"calc(100vw - 16px)":860,maxWidth:"calc(100vw - 16px)",height:l?"calc(100dvh - 16px)":"76vh",maxHeight:"calc(100dvh - 16px)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0},children:[(0,n.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:a("common.plugins")}),(0,n.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:iB(e)})]}),(0,n.jsx)("button",{onClick:r,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),!E&&(0,n.jsx)("div",{role:"status",style:{padding:"8px 18px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",fontSize:12},children:a("trust.pluginsNotLoaded")}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:l?"column":"row",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{width:l?"100%":245,maxHeight:l?"40vh":void 0,borderRight:l?"none":"1px solid var(--border)",borderBottom:l?"1px solid var(--border)":"none",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:c?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading..."}):p?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:p}):0===I.length?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No plugins configured"}):W.map(e=>(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase"},children:e.scope}),e.packages.map(e=>{let t=iO(e),r=!x&&g===t;return(0,n.jsxs)("div",{onClick:()=>{f(t),m(!1),T(null),R(null)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:r?"var(--bg-selected)":"none"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:iq(e.status)}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:r?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.source}),(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:iU(e,a)}),(e.version||e.configuredVersion)&&(0,n.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:i_(e,a)})]})]},t)})]},e.scope))}),(0,n.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("button",{type:"button",onClick:()=>{m(!0),T(null),R(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:x?"var(--bg-selected)":"none",color:x?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:e=>{x||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{x||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),a("i18n.addPlugin")]})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:x?(0,n.jsx)(iZ,{cwd:e,source:v,scope:k,projectResourcesLoaded:E,busy:D,actionError:C,onSourceChange:y,onScopeChange:w,onInstall:P}):c?null:L?(0,n.jsx)(iG,{pkg:L,cwd:e,busyKey:j,actionError:C,actionMessage:M,sessionId:t,onAction:$,onReloadSession:A},iO(L)):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:a("i18n.selectPackage")})})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,n.jsx)("div",{style:{minWidth:0,flex:1,fontSize:11,color:"var(--text-dim)",overflow:"hidden"},children:s?.diagnostics.length?(0,n.jsxs)("span",{title:s.diagnostics.map(e=>`${e.type}: ${e.source?`${e.source}: `:""}${e.message}`).join("\n"),style:{color:s.diagnostics.some(e=>"error"===e.type)?"#ef4444":"#d97706"},children:[s.diagnostics.length," diagnostic",1===s.diagnostics.length?"":"s"]}):(0,n.jsx)("span",{children:s?`${s.totals.extensions} ext \xb7 ${s.totals.skills} skills \xb7 ${s.totals.prompts} prompts \xb7 ${s.totals.themes} themes`:""})}),(0,n.jsx)("button",{onClick:()=>void z(),disabled:c||null!==j,style:iJ(c||null!==j),children:a("i18n.refresh")}),(0,n.jsx)("button",{onClick:r,style:iJ(!1),children:a("i18n.close")})]})]})})}function i0(e){return e.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function i1({scope:e}){return(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===e?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===e?"rgba(99,102,241,0.85)":"var(--text-meta)"},children:e})}function i2(e,t){return{padding:"6px 12px",background:t?"rgba(239,68,68,0.08)":"none",border:"1px solid var(--border)",borderRadius:6,color:t?"#ef4444":"var(--text-muted)",cursor:e?"not-allowed":"pointer",fontSize:12,opacity:e?.5:1}}function i8({enabled:e,loading:t,onToggle:r,label:i}){return(0,n.jsx)("button",{type:"button",onClick:r,disabled:t,title:i,"aria-label":i,"aria-pressed":e,style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:t?"wait":"pointer",background:e?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none",opacity:t?.65:1},children:(0,n.jsx)("span",{style:{position:"absolute",top:3,left:e?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function i4({value:e,projectResourcesLoaded:t,onChange:r}){let{t:i}=(0,b.s)();return(0,n.jsx)("div",{style:{display:"inline-flex",border:"1px solid var(--border)",borderRadius:7,overflow:"hidden",height:30},children:["global","project"].map(o=>{let l=e===o,a="project"===o&&!t;return(0,n.jsx)("button",{onClick:()=>{a||r(o)},disabled:a,title:a?i("trust.projectScopeUnavailable"):void 0,style:{width:76,border:"none",cursor:a?"not-allowed":"pointer",opacity:a?.4:1,fontSize:11,background:l?"var(--bg-selected)":"none",color:l?"var(--text)":"var(--text-muted)"},children:o},o)})})}function i6({server:e,cwd:t,busy:r,actionError:i,actionMessage:o,onToggle:l,onRemove:a,onMove:s,onTest:d,onEdit:c}){let{t:u}=(0,b.s)(),p=!e.disabled,h="project"===e.scope?"global":"project",g="url"===e.kind?e.url:"socket"===e.kind?e.socket:e.command,f={color:"var(--text-meta)"},x={color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"};return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20,maxWidth:680},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,minWidth:0,flexWrap:"wrap"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:180,flex:1},children:[(0,n.jsx)(i8,{enabled:p,loading:r,onToggle:l,label:u(p?"mcp.disable":"mcp.enable")}),(0,n.jsx)(i1,{scope:e.scope}),e.disabled&&(0,n.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,background:"rgba(120,120,120,0.12)",color:"var(--text-meta)"},children:u("mcp.disabledBadge")}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]}),(0,n.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,n.jsx)("button",{onClick:d,disabled:r,style:i2(r),children:u(r?"mcp.testing":"mcp.test")}),(0,n.jsx)("button",{onClick:c,disabled:r,style:i2(r),children:u("mcp.edit")}),(0,n.jsx)("button",{onClick:s,disabled:r,style:i2(r),children:u("project"===h?"mcp.moveToProject":"mcp.moveToGlobal")}),(0,n.jsx)("button",{onClick:a,disabled:r,style:i2(r,!0),children:u("mcp.delete")})]})]}),(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(96px, 130px) minmax(0, 1fr)",gap:"9px 14px",fontSize:12,lineHeight:1.45},children:[(0,n.jsx)("div",{style:f,children:u("mcp.fieldType")}),(0,n.jsx)("div",{style:x,children:e.kind}),(0,n.jsx)("div",{style:f,children:u("url"===e.kind?"mcp.kindUrl":"socket"===e.kind?"mcp.kindSocket":"mcp.kindCommand")}),(0,n.jsx)("div",{style:x,children:g??"—"}),"command"===e.kind&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{style:f,children:u("mcp.fieldArgs")}),(0,n.jsx)("div",{style:x,children:e.args.length?e.args.join(" "):"—"})]}),(0,n.jsx)("div",{style:f,children:u("mcp.fieldEnv")}),(0,n.jsx)("div",{style:x,children:e.envKeys.length?e.envKeys.join(", "):"—"}),(0,n.jsx)("div",{style:f,children:u("mcp.fieldOptions")}),(0,n.jsx)("div",{style:x,children:Object.keys(e.options).length?JSON.stringify(e.options):"—"}),(0,n.jsx)("div",{style:f,children:u("mcp.fieldSource")}),(0,n.jsx)("div",{style:{color:"var(--text-meta)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:i0(e.source)}),(0,n.jsx)("div",{style:f,children:u("mcp.fieldCwd")}),(0,n.jsx)("div",{style:{color:"var(--text-meta)",fontFamily:"var(--font-mono)",overflowWrap:"anywhere"},children:i0(t)})]}),o&&(0,n.jsx)("div",{style:{fontSize:12,color:"#16a34a",whiteSpace:"pre-wrap"},children:o}),i&&(0,n.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:i})]})}function i5({cwd:e,scope:t,projectResourcesLoaded:r,busy:o,actionError:l,initial:a,onScopeChange:s,onSave:d,onFetchDef:c,onCancel:u}){let{t:p}=(0,b.s)(),h=!!a,[g,f]=(0,i.useState)(h&&a?a.name:""),[x,m]=(0,i.useState)(()=>a?"command"===a.kind?[a.command,...a.args].join(" "):a.url??a.socket??"":""),[v,y]=(0,i.useState)(""),[k,w]=(0,i.useState)("basic"),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[M,R]=(0,i.useState)(!1),I={width:"100%",height:36,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,outline:"none"},L={fontSize:12,fontWeight:600,color:"var(--text-muted)"},E=/^https?:\/\//.test(x.trim()),W=()=>{let e=x.trim();if(/^https?:\/\//.test(e))return{url:e};let t=e.split(/\s+/),r=t[0]??"",n=v.trim()?v.trim().split(/\s+/):[];return{command:r,args:[...t.slice(1),...n]}},z=async()=>{if(T(null),null!==j)return void w("json");if(h&&a){w("json"),R(!0);try{let e=await c(a.name,a.scope);S(JSON.stringify(e??W(),null,2))}finally{R(!1)}}else S(JSON.stringify(W(),null,2)),w("json")},$=g.trim()&&("json"===k?(j??"").trim().length>0:x.trim().length>0);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:18,maxWidth:660,minHeight:"100%"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:h?p("mcp.editTitle",{name:a?.name??""}):p("mcp.addTitle")}),(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-meta)",fontFamily:"var(--font-mono)"},children:"project"===t?`${i0(e)}/.pi/mcp.json`:"~/.pi/agent/mcp.json"})]}),(0,n.jsx)("div",{style:{display:"flex",gap:8},children:["basic","json"].map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>"json"===e?void z():w("basic"),style:{padding:"6px 14px",borderRadius:6,border:"1px solid var(--border)",cursor:"pointer",fontSize:12,background:k===e?"var(--accent)":"none",color:k===e?"white":"var(--text-muted)"},children:"basic"===e?p("mcp.modeBasic"):p("mcp.modeJson")},e))}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("label",{style:L,children:p("mcp.nameLabel")}),(0,n.jsx)("input",{value:g,onChange:e=>f(e.target.value),placeholder:p("mcp.namePlaceholder"),style:I})]}),"json"===k?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("label",{style:L,children:p("mcp.jsonLabel")}),M?(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)"},children:p("mcp.loadingDef")}):(0,n.jsx)("textarea",{value:j??"",onChange:e=>S(e.target.value),spellCheck:!1,placeholder:'{\n "command": "npx",\n "args": ["-y", "@modelcontextprotocol/server-github"],\n "env": {}\n}',style:{width:"100%",minHeight:200,padding:"9px 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.5,outline:"none",resize:"vertical",whiteSpace:"pre",overflow:"auto"}})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("label",{style:L,children:p("mcp.specLabel")}),(0,n.jsx)("input",{value:x,onChange:e=>m(e.target.value),placeholder:p("mcp.specPlaceholder"),style:I})]}),!E&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:[(0,n.jsx)("label",{style:L,children:p("mcp.argsLabel")}),(0,n.jsx)("input",{value:v,onChange:e=>y(e.target.value),style:I})]})]}),C&&(0,n.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:C}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,n.jsx)(i4,{value:t,projectResourcesLoaded:r,onChange:s}),(0,n.jsx)("button",{type:"button",onClick:()=>{if(T(null),"json"===k){let e,t=j??"";if(!t.trim())return void T(p("mcp.jsonEmpty"));try{e=JSON.parse(t)}catch(e){T(p("mcp.jsonParseError",{message:e instanceof Error?e.message:String(e)}));return}if(!e||"object"!=typeof e||Array.isArray(e))return void T(p("mcp.jsonNotObject"));let r=e;return r.command||r.url||r.socket?void d(g,r):void T(p("mcp.jsonNeedsEntry"))}d(g,W())},disabled:o||!$,style:{...i2(o||!$),background:"var(--accent)",color:"white",borderColor:"var(--accent)"},children:o?p("mcp.saving"):h?p("mcp.saveEdit"):p("mcp.save")}),(0,n.jsx)("button",{type:"button",onClick:u,style:i2(!1),children:p("mcp.cancel")})]}),l&&(0,n.jsx)("div",{style:{fontSize:12,color:"#ef4444",whiteSpace:"pre-wrap"},children:l})]})}function i3({anchorRect:e,cwd:t,hidden:r,onClose:l}){let{t:a}=(0,b.s)(),[s,d]=(0,i.useState)(null),[c,u]=(0,i.useState)(!0),[p,h]=(0,i.useState)(null),[g,f]=(0,i.useState)(!1),[x,m]=(0,i.useState)("global"),[v,y]=(0,i.useState)(null),[k,w]=(0,i.useState)(null),[j,S]=(0,i.useState)(null),[C,T]=(0,i.useState)(null),[M,R]=(0,i.useState)(null),I=(0,i.useRef)(null),L=s?.projectResourcesLoaded??!0,E=(0,i.useMemo)(()=>s?.servers.find(e=>e.name===p)??null,[s,p]),W=(0,i.useMemo)(()=>["project","global"].map(e=>({scope:e,servers:(s?.servers??[]).filter(t=>t.scope===e)})).filter(e=>e.servers.length>0),[s]),z=t??"",$=(0,i.useCallback)(async()=>{if(z){u(!0),w(null);try{let e=await fetch(`/api/mcp?cwd=${encodeURIComponent(z)}`),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);d(t),h(e=>e&&t.servers.some(t=>t.name===e)?e:t.servers[0]?.name??null)}catch(e){w(e instanceof Error?e.message:String(e))}finally{u(!1)}}},[z]);(0,i.useEffect)(()=>{r||$()},[r,$]),(0,i.useEffect)(()=>{if(r)return;let e=e=>{let t=e.target;I.current?.contains(t)||t.closest?.("#mcp-topbar-btn")||l()},t=e=>{"Escape"===e.key&&l()};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[r,l]);let P=(0,i.useCallback)(async(e,t)=>{if(!z)return null;R(`mcp:${e}`),w(null),S(null);try{let r=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:z,action:e,...t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return d(n),n}catch(e){return w(e instanceof Error?e.message:String(e)),null}finally{R(null)}},[z]),A=(0,i.useCallback)(async e=>{await P(e.disabled?"enable":"disable",{name:e.name,scope:e.scope})&&S(e.disabled?a("mcp.msgEnabled",{name:e.name}):a("mcp.msgDisabled",{name:e.name}))},[P,a]),D=(0,i.useCallback)(async e=>{let t=await P("remove",{name:e.name,scope:e.scope});t&&(h(t.servers[0]?.name??null),S(a("mcp.msgDeleted",{name:e.name})),0===t.servers.length&&f(!0))},[P,a]),N=(0,i.useCallback)(async e=>{let t="project"===e.scope?"global":"project";await P("move",{name:e.name,fromScope:e.scope,toScope:t})&&S(a("mcp.msgMoved",{name:e.name,scope:t}))},[P,a]),F=(0,i.useCallback)(async(e,t)=>{let r=!!v,n=r&&v?v.name:e.trim();await P(r?"update":"add",{name:n,scope:x,def:t})&&(h(n),f(!1),y(null),S(r?a("mcp.msgUpdated",{name:n}):a("mcp.msgAdded",{name:n})))},[x,v,P,a]),B=(0,i.useCallback)(async(e,t)=>{if(!z)return null;try{let r=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:z,action:"get",name:e,scope:t})}),n=await r.json();if(!r.ok||n.error)throw Error(n.error??`HTTP ${r.status}`);return n.def??null}catch{return null}},[z]),H=(0,i.useCallback)(async e=>{T(e.name),w(null),S(null);try{let t=await fetch("/api/mcp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:z,action:"test",name:e.name,scope:e.scope})}),r=await t.json();if(!t.ok||r.error)throw Error(r.error??`HTTP ${t.status}`);S(a("mcp.msgTestResult",{name:e.name,result:r.message??""}))}catch(t){w(a("mcp.msgTestError",{name:e.name,error:t instanceof Error?t.message:String(t)}))}finally{T(null)}},[z,a]),O=null!==M,U=(0,n.jsxs)("div",{ref:I,role:"dialog","aria-label":a("mcp.sectionTitle"),style:{position:"fixed",zIndex:130,top:e?.bottom??e?.top??46,left:e?e.left:24,width:780,maxHeight:"min(72vh, 600px)",display:"flex",flexDirection:"column",background:"var(--panel-glass)",backdropFilter:"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))",transform:"translateZ(0)",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderTop:"none",borderRadius:"0 0 12px 12px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 16px",borderBottom:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",flexShrink:0,background:"transparent"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,fontWeight:600,color:"var(--text)"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M19.1 4.9L17 7M7 17l-2.1 2.1"})]}),a("mcp.sectionTitle")]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("button",{onClick:()=>void $(),disabled:c||O,style:i2(c||O),children:a("i18n.refresh")}),(0,n.jsx)("button",{onClick:l,style:i2(!1),children:a("i18n.close")})]})]}),(0,n.jsxs)("div",{style:{display:"flex",flex:"1 1 auto",minHeight:0},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",width:168,flexShrink:0,borderRight:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",background:"transparent"},children:[(0,n.jsxs)("div",{style:{flex:"1 1 auto",minHeight:0,overflowY:"auto",paddingTop:8},children:[(0,n.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-meta)",textTransform:"uppercase"},children:a("mcp.sectionTitle")}),c?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading..."}):!s&&k?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#ef4444"},children:k}):(s?.servers.length??0)===0?(0,n.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-meta)"},children:a("mcp.emptyList")}):W.map(e=>(0,n.jsxs)("div",{style:{marginBottom:6},children:[(0,n.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-meta)",textTransform:"uppercase"},children:e.scope}),e.servers.map(e=>{let t=!g&&p===e.name;return(0,n.jsxs)("div",{onClick:()=>{h(e.name),f(!1),y(null),w(null),S(null)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:t?"var(--bg-selected)":"none"},onMouseEnter:e=>{t||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{t||(e.currentTarget.style.background="none")},children:[(0,n.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:e.disabled?"var(--text-meta)":"var(--accent)"}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:t?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),(0,n.jsxs)("div",{style:{fontSize:10,color:"var(--text-meta)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:2},children:[e.kind," \xb7 ",e.disabled?a("mcp.itemDisabled"):a("mcp.itemEnabled")]})]})]},e.name)})]},e.scope))]}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,n.jsxs)("button",{type:"button",onClick:()=>{f(!0),y(null),m("global"),w(null),S(null)},style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,border:"none",width:"100%",cursor:"pointer",background:g?"var(--bg-selected)":"none",color:g?"var(--accent)":"var(--text-meta)",fontSize:12},onMouseEnter:e=>{g||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{g||(e.currentTarget.style.background="none")},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),a("mcp.addButton")]})})]}),(0,n.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:g?(0,n.jsx)(i5,{cwd:z,scope:x,projectResourcesLoaded:L,busy:O,actionError:k,initial:v,onScopeChange:m,onSave:(e,t)=>void F(e,t),onFetchDef:B,onCancel:()=>{f(!1),y(null)}}):E?(0,n.jsx)(i6,{server:E,cwd:z,busy:O||C===E.name,actionError:k,actionMessage:j,onToggle:()=>void A(E),onRemove:()=>void D(E),onMove:()=>void N(E),onTest:()=>void H(E),onEdit:()=>{y(E),f(!0),w(null),S(null)}},E.name):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-meta)",fontSize:13},children:a("mcp.emptyDetail")})})]})]});return r?null:(0,o.createPortal)(U,document.body)}function i7({cwd:e,busy:t,error:r,onCancel:i,onConfirm:o}){let{t:l}=(0,b.s)();return(0,n.jsx)("div",{role:"presentation",style:{position:"fixed",inset:0,zIndex:1100,display:"flex",alignItems:"center",justifyContent:"center",padding:16,background:"rgba(0,0,0,0.4)"},onClick:e=>{t||e.target!==e.currentTarget||i()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-labelledby":"project-trust-title",style:{width:440,maxWidth:"100%",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",boxShadow:"0 12px 36px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:12,padding:"18px 18px 14px"},children:[(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"#f59e0b",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0,marginTop:1},children:[(0,n.jsx)("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"}),(0,n.jsx)("path",{d:"m9 12 2 2 4-4"})]}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{id:"project-trust-title",style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:l("trust.dialogTitle")}),(0,n.jsx)("div",{style:{marginTop:7,fontSize:12,lineHeight:1.6,color:"var(--text-muted)"},children:l("trust.dialogBody")}),(0,n.jsx)("code",{style:{display:"block",marginTop:10,padding:"8px 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:e}),r&&(0,n.jsx)("div",{role:"alert",style:{marginTop:10,color:"#ef4444",fontSize:12,lineHeight:1.5},children:r})]})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,n.jsx)("button",{type:"button",onClick:i,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:t?"not-allowed":"pointer",fontSize:12},children:l("trust.cancel")}),(0,n.jsx)("button",{type:"button",onClick:o,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--accent)",borderRadius:5,background:"var(--accent)",color:"white",cursor:t?"wait":"pointer",opacity:t?.7:1,fontSize:12,fontWeight:600},children:l(t?"trust.trusting":"trust.trustProject")})]})]})})}function i9(e){return"message"===e.type&&"message"in e}function oe(e){let t=e,r=t.branchPreview,n=i9(t.entry)?t.entry:null,i=t.compressedEntryIds?.length??0;for(;1===t.children.length;)t=t.children[0],r??=t.branchPreview,!n&&i9(t.entry)&&(n=t.entry),i+=1+(t.compressedEntryIds?.length??0);return{node:t,skipped:i,branchPreview:r,labelEntry:n??t.entry}}function ot({node:e,activePathIds:t,depth:r,isLast:i,parentLines:o,onSelect:l}){let{node:a,skipped:s,branchPreview:d,labelEntry:c}=oe(e),u=t.has(a.entry.id),p=t.has(e.entry.id)||t.has(a.entry.id),h=d?.text??function(e){if("message"===e.type&&"message"in e){let t=e.message,r=t.content,n="";if("string"==typeof r?n=r:Array.isArray(r)&&(n=r.filter(e=>"text"===e.type).map(e=>e.text).join(" ")),n.length>40&&(n=n.slice(0,40)+"…"),n)return n;if("assistant"===t.role)return"[assistant]"}return e.type}(c),g=d?d.role??null:i9(c)?c.message.role:null;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>l(a.entry.id),children:[o.map((e,t)=>(0,n.jsx)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:e&&(0,n.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:0,width:1,background:"var(--border)"}})},t)),(0,n.jsxs)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:[(0,n.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:i?"50%":0,width:1,background:"var(--border)"}}),(0,n.jsx)("div",{style:{position:"absolute",left:7,top:"50%",width:9,height:1,background:"var(--border)"}})]}),(0,n.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:u?"var(--accent)":p?"var(--text-muted)":"var(--border)",border:u?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),g&&(0,n.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===g?"var(--accent)":"var(--text-dim)",background:"user"===g?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===g?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===g?"U":"A"}),s>0&&(0,n.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",s]}),(0,n.jsx)("span",{style:{fontSize:11,color:u?"var(--text)":p?"var(--text-muted)":"var(--text-dim)",fontWeight:u?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:h})]}),a.children.map((e,s)=>(0,n.jsx)(ot,{node:e,activePathIds:t,depth:r+1,isLast:s===a.children.length-1,parentLines:[...o,!i],onSelect:l},e.entry.id))]})}function or({tree:e,activeLeafId:t,onLeafChange:r,inline:o,containerRef:l,open:a,onToggle:s,hasSession:d,compact:c,hideInlineButton:u}){let{t:p}=(0,b.s)(),[h,g]=(0,i.useState)(!1),f=void 0!==a?a:h,x=(0,i.useRef)(null),[m,v]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!f||!o)return;let e=l?.current??x.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();v({top:t.bottom,left:t.left,width:t.width})};t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[f,o,l]);let y=(0,i.useMemo)(()=>(function(e,t){if(!t)return new Set;let r=e.map(e=>({node:e,path:[e.entry.id]}));for(;r.length>0;){let{node:e,path:n}=r.pop();if(e.entry.id===t||e.compressedEntryIds?.includes(t))return new Set(n);for(let t of e.children)r.push({node:t,path:[...n,t.entry.id]})}return new Set})(e,t),[e,t]),k=(0,i.useCallback)(e=>{r(e)},[r]),w=d?!function(e){if(e.length>1)return!0;let t=[...e];for(;t.length>0;){let e=t.pop();if(e.children.length>1)return!0;for(let r of e.children)t.push(r)}return!1}(e)?p("i18n.noBranches"):null:p("i18n.noActiveSession"),j=function(e){if(e.length>1)return e;if(0===e.length)return[];let t=oe(e[0]).node;return t.children.length>1?t.children:[]}(e),S=!w&&j.length>0,C=(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:S?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),T=(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{marginLeft:2,transform:f?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,n.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return o?(0,n.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,n.jsxs)("button",{ref:x,"data-top-panel-trigger":!0,onClick:()=>s?s():g(e=>!e),style:{display:u?"none":"flex",alignItems:"center",gap:6,height:"100%",padding:"0 12px",background:f?"var(--bg-selected)":"none",border:"none",borderTop:f?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:"pointer",color:f?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=f?"var(--text)":"var(--text-muted)"},title:p("i18n.branches"),"aria-label":p("i18n.branches"),"aria-pressed":f,children:[C,!c&&(0,n.jsx)("span",{children:p("i18n.branches")})]}),f&&m&&(0,n.jsx)("div",{style:{position:"fixed",top:m.top,left:m.left,width:m.width,zIndex:500},className:"glass-top-panel",children:S?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:j.map((e,t)=>(0,n.jsx)(ot,{node:e,activePathIds:y,depth:0,isLast:t===j.length-1,parentLines:[],onSelect:k},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w})})]}):(0,n.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,n.jsxs)("button",{onClick:()=>g(e=>!e),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 12px",background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:11,textAlign:"left"},children:[C,(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:p("i18n.branches")}),T]}),f&&(0,n.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,background:"var(--bg)",borderBottom:"1px solid var(--border)",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100},children:S?(0,n.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:j.map((e,t)=>(0,n.jsx)(ot,{node:e,activePathIds:y,depth:0,isLast:t===j.length-1,parentLines:[],onSelect:k},e.entry.id))}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:w??p("i18n.noBranches")})})]})}function on(e,t,r){let n=Number.isFinite(e)?e:t,i=Math.max(t,r);return Math.round(Math.max(t,Math.min(i,n)))}function oi(e,t){try{window.localStorage.setItem(e,String(t))}catch{}}function oo(e){let{ariaLabel:t,cssVariable:r,defaultWidth:n,getDefaultWidth:o,getMaxWidth:l,growthDirection:a,maxWidth:s,minWidth:d,storageKey:c,widthRef:u}=e,p=(0,i.useRef)(null),h=(0,i.useRef)(null),g=(0,i.useRef)(!1),[f,x]=(0,i.useState)(n),[m,v]=(0,i.useState)(!1),[b,y]=(0,i.useState)(!1);(0,i.useEffect)(()=>{y(!0)},[]);let k=(0,i.useCallback)(()=>Math.min(s,Math.max(d,l())),[l,s,d]),w=(0,i.useCallback)(e=>on(e,d,k()),[k,d]),j=(0,i.useCallback)(e=>{u.current=e,p.current?.style.setProperty(r,`${e}px`)},[r,u]),S=(0,i.useCallback)((e,t={})=>{let{forcePersist:r=!1,persist:n=!0}=t,i=w(e),o=i!==u.current;return j(i),x(i),n&&(o||r)&&oi(c,i),i},[j,w,c,u]),C=(0,i.useCallback)(e=>{document.body.style.cursor=e.previousCursor,document.body.style.userSelect=e.previousUserSelect},[]),T=(0,i.useCallback)(e=>{let t=h.current;if(t&&t.pointerId===e){h.current=null,C(t),v(!1),S(u.current,{forcePersist:!0});try{t.target.hasPointerCapture(e)&&t.target.releasePointerCapture(e)}catch{}}},[S,C,u]),M=(0,i.useCallback)(e=>{if("mouse"===e.pointerType&&0!==e.button)return;e.preventDefault(),e.stopPropagation();let t=h.current;t&&T(t.pointerId);let r=e.currentTarget;r.focus({preventScroll:!0}),r.setPointerCapture(e.pointerId),h.current={pointerId:e.pointerId,startX:e.clientX,startWidth:u.current,target:r,previousCursor:document.body.style.cursor,previousUserSelect:document.body.style.userSelect},document.body.style.cursor="col-resize",document.body.style.userSelect="none",v(!0)},[T,u]),R=(0,i.useCallback)(e=>{let t=h.current;if(!t||t.pointerId!==e.pointerId)return;if("mouse"===e.pointerType&&0===e.buttons)return void T(e.pointerId);e.preventDefault();let r="right"===a?1:-1,n=w(t.startWidth+(e.clientX-t.startX)*r);j(n),e.currentTarget.setAttribute("aria-valuenow",String(n)),e.currentTarget.setAttribute("aria-valuetext",`${n} px`)},[j,w,T,a]),I=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),L=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),E=(0,i.useCallback)(e=>{T(e.pointerId)},[T]),W=(0,i.useCallback)(()=>{S(o?.()??n,{forcePersist:!0})},[S,n,o]),z=(0,i.useCallback)(()=>{S(u.current)},[S,u]),$=(0,i.useCallback)(e=>{let t=e.shiftKey?32:12,r="right"===a?"ArrowRight":"ArrowLeft",n="right"===a?"ArrowLeft":"ArrowRight";e.key===r?(e.preventDefault(),S(u.current+t,{forcePersist:!0})):e.key===n?(e.preventDefault(),S(u.current-t,{forcePersist:!0})):"Home"===e.key?(e.preventDefault(),S(d,{forcePersist:!0})):"End"===e.key?(e.preventDefault(),S(k(),{forcePersist:!0})):"Enter"===e.key&&(e.preventDefault(),W())},[S,k,a,d,W,u]);return(0,i.useEffect)(()=>{if(g.current)return;g.current=!0;let e=function(e){try{let t=window.localStorage.getItem(e);if(null===t)return null;let r=Number.parseInt(t,10);return Number.isFinite(r)?r:null}catch{return null}}(c),t=S(e??o?.()??n,{persist:!1});null!==e&&e!==t&&oi(c,t)},[S,n,o,c]),(0,i.useEffect)(()=>{if(!g.current)return;S(u.current);let e=()=>{S(u.current)};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[S,u]),(0,i.useEffect)(()=>{if(!m)return;let e=()=>{let e=h.current;e&&T(e.pointerId)},t=()=>{"visible"!==document.visibilityState&&e()};return window.addEventListener("blur",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("blur",e),document.removeEventListener("visibilitychange",t)}},[T,m]),(0,i.useEffect)(()=>()=>{let e=h.current;e&&(h.current=null,C(e))},[C]),{isResizing:m,panelRef:p,reclampWidth:z,resetWidth:W,separatorProps:{"aria-label":t,"aria-orientation":"vertical","aria-valuemax":b?k():s,"aria-valuemin":d,"aria-valuenow":f,"aria-valuetext":`${f} px`,onDoubleClick:W,onKeyDown:$,onLostPointerCapture:E,onPointerCancel:L,onPointerDown:M,onPointerMove:R,onPointerUp:I,role:"separator",tabIndex:0},width:f}}let ol="bg-image",oa="wallpaper";function os(){return new Promise((e,t)=>{let r=indexedDB.open("pi-web",1);r.onupgradeneeded=()=>{r.result.objectStoreNames.contains(ol)||r.result.createObjectStore(ol)},r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error)})}let od=null,oc=null;function ou(e){od&&URL.revokeObjectURL(od),oc=e?e.type.startsWith("video/")?"video":e.type.startsWith("image/")?"image":null:null,od=e?URL.createObjectURL(e):null;let t=document.documentElement.style;return"image"===oc&&od?t.setProperty("--app-bg-image",`url("${od}")`):t.setProperty("--app-bg-image","none"),{url:od,kind:oc}}async function op(){try{let e=await os(),t=await new Promise((t,r)=>{let n=e.transaction(ol,"readonly").objectStore(ol).get(oa);n.onsuccess=()=>t(n.result??null),n.onerror=()=>r(n.error)});if(!t)return{loaded:!1,...ou(null)};return{loaded:!0,...ou(t)}}catch{return{loaded:!1,...ou(null)}}}async function oh(e){let t=await os();await new Promise((r,n)=>{let i=t.transaction(ol,"readwrite"),o=i.objectStore(ol);e?o.put(e,oa):o.delete(oa),i.oncomplete=()=>r(),i.onerror=()=>n(i.error)})}let og={repeat:!1,offsetX:0,fill:!1,fillColorLeft:"#000000",fillColorRight:"#000000",bubbleOpacity:44,bubbleBlur:18},of="wallpaper-settings";async function ox(e){try{let t=await createImageBitmap(e),r=Math.max(2,Math.round(64*t.width/t.height)),n=document.createElement("canvas");n.width=r,n.height=64;let i=n.getContext("2d",{willReadFrequently:!0});if(!i)return null;i.drawImage(t,0,0,r,64);let o=e=>{let t=i.getImageData(e,0,1,64).data,r=0,n=0,o=0;for(let e=0;e<64;e++)r+=t[4*e],n+=t[4*e+1],o+=t[4*e+2];return`rgb(${Math.round(r/64)}, ${Math.round(n/64)}, ${Math.round(o/64)})`},l={left:o(0),right:o(r-1)};return t.close(),l}catch{return null}}let om=(0,a.default)(()=>Promise.all([r.e(1838),r.e(3888),r.e(3266)]).then(r.bind(r,83266)).then(e=>e.TerminalPanel),{loadableGenerated:{webpack:()=>[83266]},ssr:!1});function ov(){let e,t,r,a,d,c,u,p,v,y=(0,l.useRouter)(),k=(0,l.useSearchParams)(),[w]=(0,i.useState)(()=>{let e;return{requestedCwd:e=k.get("cwd")?.trim()||null,sessionId:e?null:k.get("session")}}),{preference:j,toggleTheme:S}=tt(),{hasBg:C,ready:T,pick:M,remove:R,kind:I,url:L}=function(){let[e,t]=(0,i.useState)(!1),[r,n]=(0,i.useState)(!1),[o,l]=(0,i.useState)(null),[a,s]=(0,i.useState)(null);return(0,i.useEffect)(()=>{let e=!0;return op().then(r=>{e&&(t(r.loaded),s(r.url),l(r.kind),n(!0))}),()=>{e=!1}},[]),{hasBg:e,ready:r,pick:(0,i.useCallback)(async e=>{await oh(e);let r=ou(e);s(r.url),l(r.kind),t(!0)},[]),remove:(0,i.useCallback)(async()=>{await oh(null),ou(null),s(null),l(null),t(!1)},[]),kind:o,url:a}}(),{settings:E,update:W}=function(e){let[t,r]=(0,i.useState)(og);return(0,i.useEffect)(()=>{r(function(){try{let e=localStorage.getItem(of);if(!e)return{...og};return{...og,...JSON.parse(e)}}catch{return{...og}}}())},[]),(0,i.useEffect)(()=>{let r;(r=document.documentElement.style).setProperty("--app-bg-repeat",t.repeat?"repeat-x":"no-repeat"),r.setProperty("--app-bg-size","cover"),r.setProperty("--app-bg-pos-x",`calc(50% + ${Math.round(t.offsetX)}px)`),r.setProperty("--bubble-alpha",String(t.bubbleOpacity/100)),r.setProperty("--glass-blur-bubble",`${Math.round(t.bubbleBlur)}px`),t.fill&&!t.repeat&&e?r.setProperty("--app-bg-fill",`linear-gradient(90deg, ${t.fillColorLeft}, ${t.fillColorLeft} 50%, ${t.fillColorRight} 50%, ${t.fillColorRight})`):r.removeProperty("--app-bg-fill")},[t,e]),{settings:t,update:(0,i.useCallback)(e=>r(t=>{let r={...t,...e};try{localStorage.setItem(of,JSON.stringify(r))}catch{}return r}),[])}}(C&&"image"===I),[z,$]=(0,i.useState)(!1),P=(0,i.useRef)(null),D=(0,i.useRef)(null),N=(0,i.useRef)(0);N.current=E.offsetX,(0,i.useEffect)(()=>{let e=P.current;if(!e)return;e.muted=!0,e.preload="auto";let t=!1,r=()=>{!t&&e.paused&&e.play().catch(()=>{})};return e.addEventListener("loadeddata",r),e.addEventListener("canplay",r),e.addEventListener("pause",r),r(),()=>{t=!0,e.removeEventListener("loadeddata",r),e.removeEventListener("canplay",r),e.removeEventListener("pause",r)}},[L]),(0,i.useEffect)(()=>{let e=P.current,t=D.current;if(!e||!t||"video"!==I)return;let r=t.getContext("2d");if(!r)return;let n=0,i=()=>{if(n=requestAnimationFrame(i),!e.videoWidth||!e.videoHeight)return;let o=t.clientWidth,l=t.clientHeight,a=window.devicePixelRatio||1;(t.width!==Math.round(o*a)||t.height!==Math.round(l*a))&&(t.width=Math.round(o*a),t.height=Math.round(l*a));let s=Math.max(t.width/e.videoWidth,t.height/e.videoHeight),d=e.videoWidth*s,c=e.videoHeight*s,u=(t.width-d)/2+N.current*a,p=(t.height-c)/2;r.clearRect(0,0,t.width,t.height),r.drawImage(e,u,p,d,c)};return n=requestAnimationFrame(i),()=>cancelAnimationFrame(n)},[L,I]),(0,i.useEffect)(()=>{if(!z)return;let e=document.body.style.userSelect;document.body.style.userSelect="none";let t=e=>{"Escape"===e.key&&$(!1)};return window.addEventListener("keydown",t),()=>{document.body.style.userSelect=e,window.removeEventListener("keydown",t)}},[z]);let F="light"===j?"theme.light":"theme.dark",{locale:B,setLocale:H,t:O,supportedLocales:U}=(0,b.s)(),_=(0,ro.a)();(0,i.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=document.documentElement,r=null,n=()=>{let n;r=null,!function({hasFocusedEditable:e,innerHeight:t,viewportHeight:r,viewportScale:n}){let i=.01>Math.abs(n-1);return e&&i&&t-r>1}({hasFocusedEditable:(n=document.activeElement)instanceof HTMLElement&&(n.isContentEditable||"INPUT"===n.tagName||"SELECT"===n.tagName||"TEXTAREA"===n.tagName),innerHeight:window.innerHeight,viewportHeight:e.height,viewportScale:e.scale})?t.style.removeProperty("--app-viewport-height"):t.style.setProperty("--app-viewport-height",`${e.height}px`);let i=0!==window.scrollX||0!==window.scrollY,o=.01>Math.abs(e.scale-1);i&&o&&window.scrollTo(0,0)},i=()=>{null!==r&&window.cancelAnimationFrame(r),r=window.requestAnimationFrame(n)};return i(),e.addEventListener("resize",i),e.addEventListener("scroll",i),window.addEventListener("resize",i),window.addEventListener("focusin",i),window.addEventListener("focusout",i),window.addEventListener("pageshow",i),()=>{e.removeEventListener("resize",i),e.removeEventListener("scroll",i),window.removeEventListener("resize",i),window.removeEventListener("focusin",i),window.removeEventListener("focusout",i),window.removeEventListener("pageshow",i),null!==r&&window.cancelAnimationFrame(r),t.style.removeProperty("--app-viewport-height")}},[]);let{soundEnabled:q,onSoundToggle:K,playDoneSound:V,unlockAudio:J,soundEnabledRef:Y}=function(){let[e,t]=(0,i.useState)(()=>{let e=localStorage.getItem("pi-sound-enabled");return null===e||"true"===e}),r=(0,i.useRef)(e);(0,i.useEffect)(()=>{r.current=e},[e]);let n=(0,i.useRef)(null),o=(0,i.useCallback)(()=>{if(n.current&&"closed"!==n.current.state)return n.current;try{n.current=new AudioContext}catch{return null}return n.current},[]),l=(0,i.useCallback)((e=!1)=>{if(!e&&!r.current)return;let t=o();t&&"suspended"===t.state&&t.resume().catch(()=>{})},[o]);return{soundEnabled:e,onSoundToggle:(0,i.useCallback)(()=>{let e=!r.current;e&&l(!0),r.current=e,localStorage.setItem("pi-sound-enabled",String(e)),t(e)},[l]),playDoneSound:(0,i.useCallback)(()=>{if(!r.current)return;let e=o();if(!e)return;let t=()=>{try{let t;t=e.currentTime,[523.25,659.25].forEach((r,n)=>{let i=e.createOscillator(),o=e.createGain();i.connect(o),o.connect(e.destination),i.type="sine",i.frequency.value=r;let l=t+.18*n;o.gain.setValueAtTime(0,l),o.gain.linearRampToValueAtTime(.18,l+.02),o.gain.exponentialRampToValueAtTime(.001,l+.45),i.start(l),i.stop(l+.45)})}catch{}};"suspended"===e.state?e.resume().then(t).catch(()=>{}):t()},[o]),unlockAudio:l,soundEnabledRef:r}}(),X=(0,i.useRef)(new Set),Z=(0,i.useCallback)(()=>{Y.current&&V()},[V,Y]),[G,Q]=(0,i.useState)(null),[ee,et]=(0,i.useState)(()=>new Set),er=(0,i.useCallback)(e=>{et(t=>t.size===e.size&&[...e].every(e=>t.has(e))?t:e)},[]),[ei,eo]=(0,i.useState)(null),[el,ea]=(0,i.useState)("initial"),es=(0,i.useRef)(null),[ed,ec]=(0,i.useState)(()=>w.requestedCwd?"validating":"idle"),[eu,ep]=(0,i.useState)(null),[eh,eg]=(0,i.useState)(0),[ef,ex]=(0,i.useState)(0),[em,ev]=(0,i.useState)(0),[eb,ey]=(0,i.useState)(!1),[ek,ew]=(0,i.useState)(0),[ej,eS]=(0,i.useState)(!1),[eC,eT]=(0,i.useState)(!1),[eM,eR]=(0,i.useState)(null),[eI,eL]=(0,i.useState)(!1),[eE,eW]=(0,i.useState)(!1),[ez,e$]=(0,i.useState)(null),[eP,eA]=(0,i.useState)(!0),[eD,eN]=(0,i.useState)(!1),[eF,eB]=(0,i.useState)("top"),[eH,eO]=(0,i.useState)(null),eU=(0,i.useRef)(null),[e_,eq]=(0,i.useState)(!1),eK=(0,i.useRef)(null),[eV,eJ]=(0,i.useState)(!1),[eY,eX]=(0,i.useState)(!1),[eZ,eG]=(0,i.useState)(!1),eQ=(0,i.useRef)(null),e0=(0,i.useRef)(null),e1=(0,i.useRef)(null),[e2,e8]=(0,i.useState)(null),[e4,e6]=(0,i.useState)(!1),e5=(0,i.useRef)(260),e3=(0,i.useRef)(560),e7=(0,i.useCallback)(()=>on(.42*window.innerWidth,360,640),[]),e9=(0,i.useCallback)(()=>(function(e){let{viewportWidth:t,rightPanelOpen:r,rightPanelWidth:n}=e;if(t<=640)return 480;let i=t<960;return Math.min(480,t-(i?320:420)-(!i&&r?n:0))})({viewportWidth:window.innerWidth,rightPanelOpen:eV,rightPanelWidth:e3.current}),[eV]),te=(0,i.useCallback)(()=>(function(e){let{viewportWidth:t,sidebarOpen:r,sidebarWidth:n}=e;return t<960?1200:Math.min(1200,t-420-(r?n:0))})({viewportWidth:window.innerWidth,sidebarOpen:eP,sidebarWidth:e5.current}),[eP]),tn=oo({ariaLabel:O("layout.resizeSidebar"),cssVariable:"--sidebar-width",defaultWidth:260,getMaxWidth:e9,growthDirection:"right",maxWidth:480,minWidth:180,storageKey:"pi-sidebar-width",widthRef:e5}),ti=oo({ariaLabel:O("layout.resizeFilePanel"),cssVariable:"--right-panel-width",defaultWidth:560,getDefaultWidth:e7,getMaxWidth:te,growthDirection:"left",maxWidth:1200,minWidth:300,storageKey:"pi-right-panel-width",widthRef:e3}),to=tn.reclampWidth,tl=ti.reclampWidth;(0,i.useEffect)(()=>{_&&eA(!1)},[_]);let ta=(0,i.useCallback)(e=>{let t=e.currentTarget.getBoundingClientRect(),r=t.left;r+264>window.innerWidth-8&&(r=Math.max(8,window.innerWidth-264-8)),e8({left:r,top:t.bottom}),eG(e=>!e)},[]);(0,i.useEffect)(()=>{if(!eZ)return;let e=e=>{eQ.current&&!eQ.current.contains(e.target)&&e1.current&&!e1.current.contains(e.target)&&eG(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[eZ]),(0,i.useEffect)(()=>{e6(!0)},[]),(0,i.useEffect)(()=>{eV&&(to(),tl())},[tl,to,eV]);let ts=(0,i.useRef)(null),td=(0,i.useRef)(null),tc=(0,i.useRef)(null),tu=(0,i.useRef)(null),[tp,th]=(0,i.useState)([]),[tg,tf]=(0,i.useState)(null),tx=(0,i.useRef)(null),tm=(0,i.useCallback)((e,t,r)=>{th(e),tf(t),tx.current=r},[]),tv=(0,i.useCallback)(e=>{tx.current?.(e)},[]),[tb,ty]=(0,i.useState)(null),[tk,tw]=(0,i.useState)(!1),tj=(0,i.useRef)(null),tS=(0,i.useRef)(0),tC=(0,i.useRef)(null),tT=(0,i.useCallback)(e=>{ty(e),tw(!1)},[]),tM=(0,i.useCallback)(e=>{tS.current+=1,tj.current=e,tw(!1)},[]),[tR,tI]=(0,i.useState)(null),[tL,tE]=(0,i.useState)([]),[tW,tz]=(0,i.useState)(!1),[t$,tP]=(0,i.useState)(null),tA=(0,i.useRef)(null),tD=(0,i.useRef)(null),[tN,tF]=(0,i.useState)({kind:"idle"}),tB=(0,i.useRef)(null),tH=(0,i.useRef)(G?.id??null);tH.current=G?.id??null;let tO=(0,i.useCallback)(e=>{tI(e)},[]),tU=(0,i.useCallback)(e=>{tE(e)},[]),t_=(0,i.useCallback)(async e=>{try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/todos`);if(!t.ok)return;let r=await t.json();Array.isArray(r.todos)&&tE(r.todos)}catch{}},[]),[tq,tK]=(0,i.useState)(null),tV=(0,i.useRef)(null),tJ=(0,i.useCallback)((e,t)=>{tr(t).then(()=>{tV.current&&clearTimeout(tV.current),tK(e),tV.current=setTimeout(()=>tK(null),1400)})},[]);(0,i.useEffect)(()=>()=>{tV.current&&clearTimeout(tV.current),tB.current&&clearTimeout(tB.current)},[]);let[tY,tX]=(0,i.useState)(null),tZ=(0,i.useCallback)(e=>{tX(e)},[]),[tG,t0]=(0,i.useState)(null),[t1,t2]=(0,i.useState)(null),t8=(0,i.useRef)(null),t4=(0,i.useCallback)((e,t=!1)=>{_&&eA(!1),tz(!1),t0(t=>t===e?null:e),_&&t&&eX(!0)},[_]),t6=(0,i.useCallback)((e=!1)=>{let t="system"!==tG;if(t4("system",e),!t||tk)return;let r=tj.current;if(!r)return;let n=++tS.current;tw(!0),r().catch(e=>{console.error("Failed to load system prompt:",e)}).finally(()=>{tS.current===n&&tw(!1)})},[tG,tk,t4]),t5=(0,i.useCallback)(()=>{_&&eA(!1),eX(!1),tz(!1),t0("session")},[_]),t3=(0,i.useCallback)(()=>{_&&eA(!1),eX(!1),t0(null),!tW&&G?.id&&t_(G.id),tz(e=>!e)},[_,tW,G?.id,t_]);(0,i.useEffect)(()=>{if(!tW||!tA.current)return;let e=()=>{let e=tA.current;if(!e)return;let t=e.getBoundingClientRect();tP({top:t.bottom,right:Math.max(8,Math.round(window.innerWidth-t.right))})};e();let t=new ResizeObserver(e);t.observe(document.documentElement);let r=tA.current.parentElement;for(;r;)t.observe(r),r=r.parentElement;return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{t.disconnect(),window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[tW]),(0,i.useEffect)(()=>{if(!tW)return;let e=e=>{let t=e.target;tA.current?.contains(t)||tD.current?.contains(t)||tz(!1)},t=e=>{"Escape"===e.key&&tz(!1)};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[tW]),(0,i.useEffect)(()=>{if(!eD)return;let e=()=>{let e="top"===eF?eU.current:document.getElementById("terminal-bottombar-btn");if(!e)return;let t=e.getBoundingClientRect();eO({top:t.top,left:t.left,right:t.right,bottom:t.bottom})};e();let t=new ResizeObserver(e);return t.observe(document.documentElement),window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{t.disconnect(),window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[eD,eF]);let t7=(0,i.useCallback)(e=>{eB(e),eN(t=>e!==eF||!t)},[eF]);(0,i.useEffect)(()=>{if(!tG)return;let e=e=>{let t=e.target;t8.current?.contains(t)||t.closest?.("button[data-top-panel-trigger]")||t0(null)},t=e=>{"Escape"===e.key&&t0(null)};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[tG]);let t9=(0,i.useCallback)(()=>{_&&(t0(null),tz(!1),eX(!1)),eA(e=>!e)},[_]),re=(0,i.useCallback)(()=>{eA(!1),t0(null),tz(!1),eX(e=>!e)},[]),rt=(0,i.useCallback)(()=>{_&&(eA(!1),t0(null),eX(!1)),eJ(e=>!e)},[_]);(0,i.useEffect)(()=>{if(!eY)return;let e=e=>{let t=tc.current;t&&e.composedPath().includes(t)||eX(!1)},t=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),eX(!1))};return document.addEventListener("pointerdown",e,!0),document.addEventListener("keydown",t,!0),()=>{document.removeEventListener("pointerdown",e,!0),document.removeEventListener("keydown",t,!0)}},[eY]),(0,i.useEffect)(()=>{eX(!1)},[_,G?.id,el]),(0,i.useEffect)(()=>{if(!tG||!td.current)return;let e=()=>{let e=td.current.getBoundingClientRect();if("language"===tG&&!_&&tu.current){let t=tu.current.getBoundingClientRect(),r=Math.min(176,e.width),n=Math.min(t.left-1,Math.max(e.left,e.right-r));t2({top:e.bottom,left:n,width:r});return}t2({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(td.current),tu.current&&t.observe(tu.current),()=>t.disconnect()},[tG,_]);let[rr,rn]=(0,i.useState)([]),[ri,rl]=(0,i.useState)(null),ra=(0,i.useCallback)((e,t,r)=>{rn(n=>(function(e,t,r,n){let i=e.findIndex(e=>e.id===t);if(-1===i||(e[i].viewerRevision??0)!==r)return e;let o=[...e];return o[i]={...o[i],viewerState:n},o})(n,e,t,r))},[]),rs=(0,i.useCallback)((e,t)=>{ts.current?.insertText(tQ(e,t)),_&&(eJ(!1),eA(!1))},[_]),rd=(0,i.useCallback)(e=>{let t=e.map(e=>tQ(e,!1)).join("");t&&ts.current?.insertText(t),_&&(eJ(!1),eA(!1))},[_]),rc=(0,i.useCallback)((e,t,r)=>{let n,i,o,l;ts.current?.insertText((n=Math.max(1,Math.min(t,r)),i=Math.max(1,Math.max(t,r)),o=e.includes(" ")?`@"${e}"`:`@${e}`,l=n===i?`:${n}`:`:${n}-${i}`,`${o}${l} `)),_&&(eJ(!1),eA(!1))},[_]),ru=w.sessionId,[rp,rh]=(0,i.useState)(null),rg=(0,i.useRef)(null),[rf,rx]=(0,i.useState)(()=>!ru),rm=(0,i.useRef)(!1),rv=(0,i.useRef)(0),rb=(0,i.useCallback)(()=>{rv.current+=1},[]);(0,i.useEffect)(()=>{G&&function(e,t,r=g()){if(r)try{let n=f(r);n[e]=t,r.setItem(h,JSON.stringify(n))}catch{}}(G.projectKey??rg.current??m(G),G.id)},[G]),(0,i.useEffect)(()=>{let e=w.requestedCwd;if(!e)return;let t=new AbortController;return ec("validating"),ep(null),fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e}),signal:t.signal}).then(async t=>{let r=await t.json().catch(()=>({}));if(!t.ok||!r.cwd)throw Error(r.error??`HTTP ${t.status}`);rm.current=!0;let n=`initial:${e}`;ea(n),es.current=`new:${n}:${r.cwd}`,eo(r.cwd),ec("ready")}).catch(e=>{t.signal.aborted||(ep(e instanceof Error?e.message:String(e)),ec("error"))}),()=>t.abort()},[w]);let ry=(0,i.useCallback)(e=>{let t=++rv.current,r=function(e,t=g()){if(!t)return null;try{let r=f(t)[e];return"string"==typeof r&&r.length>0?r:null}catch{return null}}(e);r&&fetch("/api/sessions").then(e=>e.ok?e.json():null).then(n=>{if(t!==rv.current)return;let i=n?.sessions.find(e=>e.id===r);if(!i){n&&x(e);return}m(i)!==e?x(e):(Q(i),ex(e=>e+1),new URLSearchParams(window.location.search).get("session")!==i.id&&y.replace(`?session=${encodeURIComponent(i.id)}`,{scroll:!1}))}).catch(()=>{})},[y]),rk=(0,i.useCallback)((e,t,r)=>{rb();let n=ei??rp;if(rh(e),!e)return;let i=r??t??e,o=rg.current??(G?m(G):null);if(rg.current=i,rm.current){rm.current=!1;return}if(n===e&&o!==i||o===i&&(null!==G||n===e))return;let l="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;ea(l),es.current=`new:${l}:${e}`,Q(null),eo(t=>t&&t!==e?null:t),ex(e=>e+1),th([]),tf(null),ty(null),tw(!1),t0(null),o!==i&&(rn([]),rl(null),eJ(!1),ry(i)),y.replace("/",{scroll:!1})},[rp,rb,ei,y,G,ry]),rw=(0,i.useCallback)((e,t=!1)=>{if(rb(),es.current=null,!t&&G){let t=m(G)===m(e);if(G.id===e.id&&t){_&&eA(!1);return}}eo(null),Q(e),ex(e=>e+1),ty(null),tw(!1),rx(!0),_&&!t&&eA(!1),t&&(rm.current=!0),t||y.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1})},[rb,y,_,G]),rj=(0,i.useCallback)((e,t)=>{rb(),es.current=`new:${e}:${t}`,ea(e),Q(null),eo(t),ex(e=>e+1),th([]),tf(null),ty(null),tw(!1),t0(null),_&&eA(!1),y.replace("/",{scroll:!1})},[rb,y,_]);!function(e){let{onNewSession:t,activeCwd:r}=e;(0,i.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(!s)return;let t=e.target?.tagName;if("TEXTAREA"===t||"INPUT"===t)return;e.preventDefault(),s();return}if("n"===e.key&&e.ctrlKey&&e.altKey){if(!r||!t)return;e.preventDefault(),t(r)}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[r,t])}({onNewSession:e=>rj(`kb-${Date.now()}`,e),activeCwd:rp});let rS=(0,i.useCallback)(e=>{fetch("/api/sessions",{cache:"no-store"}).then(e=>e.ok?e.json():null).then(t=>{let r=t?.sessions.find(t=>t.id===e);r&&Q(t=>t?.id===e?{...t,...r,transient:r.transient??!1}:t)}).catch(()=>{})},[]),rC=(0,i.useCallback)((e,t)=>{eg(e=>e+1),es.current===t&&(rb(),es.current=null,eo(null),Q(e),rS(e.id),y.replace(`?session=${encodeURIComponent(e.id)}`,{scroll:!1}))},[rb,y,rS]),rT=(0,i.useCallback)(({targetSession:e,title:t,body:r,tag:n})=>{if(!("Notification"in window))return;let i=()=>{rU({title:t,body:r,sessionUrl:e?`/?session=${encodeURIComponent(e.id)}`:"/",tag:n,onClick:()=>{window.focus(),e&&rw(e)}})};"granted"===Notification.permission?i():"default"===Notification.permission&&Notification.requestPermission().then(e=>{"granted"===e&&i()})},[rw]),rM=(0,i.useCallback)(()=>{eg(e=>e+1),ev(e=>e+1),G&&rS(G.id),rH()&&rT({targetSession:G,title:G?.name??O("i18n.sessionComplete"),body:O("i18n.taskFinished")})},[rT,rS,G,O]),rR=(0,i.useCallback)(e=>{var t;rH()&&(t=X.current,!(!rO(e)||t.has(e.id))&&(t.add(e.id),1)&&rT({targetSession:G,title:O("i18n.attentionNeeded"),body:"custom"===e.method?O("i18n.extensionInputNeeded"):e.title,tag:`pi-extension-ui:${e.id}`}))},[rT,G,O]),rI=(0,i.useCallback)(async()=>{let e=G?.id;if(e&&"naming"!==tN.kind){tB.current&&clearTimeout(tB.current),t0(null),tF({kind:"naming"});try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/auto-name`,{method:"POST"}),r=await t.json().catch(()=>({}));if(!t.ok||!r.title)throw Error(r.error||`HTTP ${t.status}`);let n=r.title.trim();if(eg(e=>e+1),tH.current!==e)return;Q(t=>t?.id===e?{...t,name:n}:t),tI(t=>t?.sessionId===e?{...t,sessionName:n}:t),tF({kind:"success"}),tB.current=setTimeout(()=>tF({kind:"idle"}),1800)}catch(t){if(tH.current!==e)return;tF({kind:"error",message:t instanceof Error?t.message:String(t)}),tB.current=setTimeout(()=>tF({kind:"idle"}),5e3)}}},[tN.kind,G?.id]);(0,i.useEffect)(()=>{tB.current&&clearTimeout(tB.current),tF({kind:"idle"})},[G?.id]),(0,i.useEffect)(()=>{tz(!1);let e=G?.id;e&&t_(e)},[G?.id,t_]);let rL=!!(G?.id&&ee.has(G.id));(0,i.useEffect)(()=>{let e,t=G?.id;if(!t||!rL)return;let r=!1,n=async()=>{await t_(t),r||(e=setTimeout(n,6e3))};return n(),()=>{r=!0,e&&clearTimeout(e)}},[G?.id,rL,t_]);let rE=(0,i.useCallback)(()=>{ev(e=>e+1)},[]),rW=(0,i.useCallback)(e=>{rb(),es.current=null,eg(e=>e+1),ex(e=>e+1),eo(null),Q(t=>({...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e,transient:!1})),rS(e),y.replace(`?session=${encodeURIComponent(e)}`,{scroll:!1})},[rb,y,rS]),rz=(0,i.useCallback)(()=>{rx(!0)},[]),r$=(0,i.useCallback)(e=>{if(rb(),eg(e=>e+1),G?.id===e){let e=G.cwd,t="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;ea(t),es.current=e?`new:${t}:${e}`:null,Q(null),eo(e??null),ex(e=>e+1),th([]),tf(null),ty(null),tw(!1),t0(null),y.replace("/",{scroll:!1})}},[rb,G,y]),rP=(0,i.useCallback)((e,t,r)=>{let n=r?.sourceSessionId,i=r?.modeHint,o=`file:${e}`;rn(r=>(function(e,t){let r=e.find(e=>e.id===t.tabId);if(!r)return[...e,{id:t.tabId,label:t.fileName,filePath:t.filePath,sourceSessionId:t.sourceSessionId,initialDisplayMode:t.modeHint,viewerState:t.modeHint?{displayMode:t.modeHint,wrapLines:!1,scrollTop:0,scrollLeft:0}:void 0,viewerRevision:0}];let n=!!(t.sourceSessionId&&r.sourceSessionId!==t.sourceSessionId);return n||t.modeHint?e.map(e=>{if(e.id!==t.tabId)return e;let r={...e};return n&&(r.sourceSessionId=t.sourceSessionId),t.modeHint?(r.initialDisplayMode=t.modeHint,r.viewerState={displayMode:t.modeHint,wrapLines:e.viewerState?.wrapLines??!1,scrollTop:0,scrollLeft:0},r.viewerRevision=(e.viewerRevision??0)+1):n&&(r.viewerRevision=(e.viewerRevision??0)+1),r}):e})(r,{fileName:t,filePath:e,modeHint:i,sourceSessionId:n,tabId:o})),rl(o),eJ(!0),_&&eA(!1)},[_]),rA=(0,i.useCallback)(e=>{rP(e,A(e),{sourceSessionId:G?.id??null})},[rP,G?.id]),rD=(0,i.useCallback)(e=>{rn(t=>{let r=t.filter(t=>t.id!==e);return 0===r.length&&eJ(!1),r}),rl(t=>{if(t!==e)return t;let r=rr.filter(t=>t.id!==e);return r.length>0?r[r.length-1].id:null})},[rr]),rN=(0,i.useCallback)(()=>{G&&window.open(`/api/sessions/${encodeURIComponent(G.id)}/export?inline=1`,"_blank","noopener,noreferrer")},[G]),rF=ei??(null===G&&rp?rp:null),rB=null===G&&rF?`new:${el}:${rF}`:null;(0,i.useLayoutEffect)(()=>{es.current=rB},[rB]);let r_=null!==G||null!==rF,rq=G?.cwd??rF,rK=rf&&!r_;(0,i.useEffect)(()=>{if(eR(null),eL(!1),e$(null),!rq)return;let e=new AbortController;return fetch(`/api/project-trust?cwd=${encodeURIComponent(rq)}`,{signal:e.signal}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);eR(t)}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||console.error("Failed to load project trust:",e)}),()=>e.abort()},[rq]);let rV=(0,i.useCallback)(async()=>{if(rq&&!eE){eW(!0),e$(null);try{let e=await fetch("/api/project-trust",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:rq})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);eR(t),eL(!1),ew(e=>e+1),ex(e=>e+1)}catch(e){e$(e instanceof Error?e.message:String(e))}finally{eW(!1)}}},[eE,rq]),rJ=rr.find(e=>e.id===ri)??null,rY=rp?A(rp)||rp:null,rX=rY?`${rY} - Pi Web`:"Pi Web";(0,i.useEffect)(()=>{let e=()=>{document.title!==rX&&(document.title=rX)};e();let t=new MutationObserver(e);return t.observe(document.head,{childList:!0,subtree:!0,characterData:!0}),()=>t.disconnect()},[rX]);let rZ=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(en,{selectedSessionId:G?.id??null,onSelectSession:rw,onNewSession:rj,initialSessionId:ru,skipInitialProjectSelection:null!==w.requestedCwd,onInitialRestoreDone:rz,refreshKey:eh,onSessionDeleted:r$,selectedCwd:G?.cwd??ei??null,onCwdChange:rk,onOpenFile:rP,explorerRefreshKey:em,onExplorerRefresh:rE,onAtMention:rs,onAtMentions:rd,onBackgroundTaskDone:Z,onRunningSessionIdsChange:er}),(0,n.jsx)("div",{style:{padding:"8px",flexShrink:0,display:"flex",justifyContent:"space-between",gap:4},children:[{label:O("common.models"),onClick:()=>ey(!0),disabled:!1,icon:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,n.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,n.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,n.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,n.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,n.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,n.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,n.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,n.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]})},{label:O("common.skills"),onClick:()=>eS(!0),disabled:!rp&&!G?.cwd&&!ei,icon:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,n.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,n.jsx)("path",{d:"M2 12l10 5 10-5"})]})},{label:O("common.plugins"),onClick:()=>eT(!0),disabled:!rp&&!G?.cwd&&!ei,icon:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M9 7V2"}),(0,n.jsx)("path",{d:"M15 7V2"}),(0,n.jsx)("path",{d:"M6 13V8a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v5a6 6 0 0 1-12 0Z"}),(0,n.jsx)("path",{d:"M12 19v3"})]})}].map(({label:e,onClick:t,disabled:r,icon:i})=>(0,n.jsxs)("button",{onClick:t,disabled:r,title:e,style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:32,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:r?"default":"pointer",fontSize:12,opacity:r?.35:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:[i,e]},e))})]}),rG=e=>(0,n.jsx)("button",{type:"button",onClick:t=>{let r=t.currentTarget.getBoundingClientRect();S({x:r.left+r.width/2,y:r.top+r.height/2}),e&&eX(!0)},title:O(F),"aria-label":O(F),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},"data-mobile-toolbar-action":e?"theme":void 0,children:"light"===j?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,n.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,n.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,n.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,n.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,n.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,n.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,n.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,n.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):"dark"===j?(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}):(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}),rQ=e=>(0,n.jsx)("button",{ref:e1,type:"button",onClick:t=>{ta(t),e&&eX(!0)},title:O("bg.title"),"aria-label":O("bg.title"),"aria-haspopup":"menu","aria-expanded":eZ,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:eZ?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},"data-mobile-toolbar-action":e?"bg":void 0,children:(0,n.jsxs)("span",{style:{position:"relative",display:"inline-flex"},children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,n.jsx)("path",{d:"M21 15l-5-5L5 21"})]}),C&&(0,n.jsx)("span",{"aria-label":O("bg.title"),title:O("bg.title"),style:{position:"absolute",top:-2,right:-2,width:7,height:7,borderRadius:"50%",background:"var(--accent)",boxShadow:"0 0 0 2px var(--bg-panel)"}})]})}),r0=e=>(0,n.jsx)("button",{ref:tu,type:"button","data-top-panel-trigger":!0,onClick:()=>t4("language",e),title:O("common.language"),"aria-label":O("common.language"),"aria-haspopup":"menu","aria-expanded":"language"===tG,"aria-pressed":"language"===tG,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"language"===tG?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:"language"===tG?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="language"===tG?"var(--text)":"var(--text-muted)"},"data-mobile-toolbar-action":e?"language":void 0,children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"m5 8 6 6"}),(0,n.jsx)("path",{d:"m4 14 6-6 2-3"}),(0,n.jsx)("path",{d:"M2 5h12"}),(0,n.jsx)("path",{d:"M7 2h1"}),(0,n.jsx)("path",{d:"m22 22-5-10-5 10"}),(0,n.jsx)("path",{d:"M14 18h6"})]})}),r1=e=>r_&&eM?.requiresTrust&&!eM.trusted?(0,n.jsxs)("button",{type:"button",onClick:()=>{e$(null),eL(!0)},title:O("trust.resourcesNotLoaded"),"aria-label":O("trust.resourcesNotLoaded"),style:{display:"flex",alignItems:"center",justifyContent:e?"flex-start":"center",gap:6,width:e?"100%":void 0,minHeight:e?32:void 0,height:e?void 0:"100%",padding:e?"6px 12px":"0 12px",background:e?"color-mix(in srgb, #d97706 8%, var(--bg-panel))":"none",border:"none",borderRight:e?"none":"1px solid var(--border)",borderBottom:e?"1px solid var(--border)":"none",color:"#d97706",cursor:"pointer",flexShrink:0,fontSize:11,lineHeight:1.35,textAlign:"left"},"data-mobile-trust-banner":e?"true":void 0,children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{flexShrink:0},children:[(0,n.jsx)("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"}),(0,n.jsx)("path",{d:"M12 8v4"}),(0,n.jsx)("path",{d:"M12 16h.01"})]}),(0,n.jsx)("span",{children:O("trust.resourcesNotLoaded")})]}):null,r2=e=>{let t,r,i,o,l,a;return e||r_?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"stretch",height:"100%"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>{rN(),e&&eX(!0)},disabled:!G,title:G?O("history.full"):O("history.unsaved"),"aria-label":O("history.full"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:e?36:void 0,height:"100%",padding:e?0:"0 12px",background:"none",border:"none",borderTop:"2px solid transparent",borderRight:"1px solid var(--border)",color:G?"var(--text-muted)":"var(--text-dim)",cursor:G?"pointer":"not-allowed",opacity:G?1:.45,flexShrink:0,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>{G&&(e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=G?"var(--text-muted)":"var(--text-dim)",e.currentTarget.style.background="none"},"data-mobile-toolbar-action":e?"history":void 0,children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:G?"var(--text-muted)":"var(--text-dim)",flexShrink:0},"aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7L3 8"}),(0,n.jsx)("path",{d:"M3 3v5h5"}),(0,n.jsx)("path",{d:"M12 7v5l3 2"})]}),!e&&(0,n.jsx)("span",{children:O("history.label")})]}),(t=!!(G&&((tR?.userMessages??0)>0||G.messageCount>0)),r=!G||G.transient||!t||"naming"===tN.kind,i="success"===tN.kind,o="error"===tN.kind,l="naming"===tN.kind?O("title.generating"):i?O("title.updated"):o?O("title.failed"):O("title.generate"),a=!G||G.transient?O("title.unsaved"):t?o?tN.message:O("title.generateSession"):O("title.noMessages"),(0,n.jsxs)("button",{type:"button",onClick:()=>{rI(),e&&eX(!0)},disabled:r,title:a,"aria-label":l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:e?36:void 0,height:"100%",padding:e?0:"0 12px",background:"none",border:"none",borderTop:"2px solid transparent",borderRight:"1px solid var(--border)",color:o?"#dc2626":i?"var(--accent)":r?"var(--text-dim)":"var(--text-muted)",cursor:r?"not-allowed":"pointer",opacity:r&&"naming"!==tN.kind?.45:1,flexShrink:0,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, opacity 0.1s"},onMouseEnter:e=>{r||(e.currentTarget.style.color=o?"#dc2626":"var(--text)",e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{e.currentTarget.style.color=o?"#dc2626":i?"var(--accent)":r?"var(--text-dim)":"var(--text-muted)",e.currentTarget.style.background="none"},"data-mobile-toolbar-action":e?"name":void 0,children:["naming"===tN.kind?(0,n.jsxs)("svg",{className:"animate-spin",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,n.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}):i?(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"m15 4 5 5L7 22l-5-5Z"}),(0,n.jsx)("path",{d:"m14 5 5 5"}),(0,n.jsx)("path",{d:"M6 4V2M5 3H3M19 19v3M17.5 20.5h3"})]}),!e&&(0,n.jsx)("span",{children:l})]})),e?(0,n.jsx)("button",{type:"button","data-top-panel-trigger":!0,onClick:()=>t4("branches",!0),title:O("i18n.branches"),"aria-label":O("i18n.branches"),"aria-pressed":"branches"===tG,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:"100%",padding:0,background:"branches"===tG?"var(--bg-selected)":"none",border:"none",borderTop:"branches"===tG?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",color:"branches"===tG?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0},"data-mobile-toolbar-action":"branches",children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:tp.length>0?"var(--accent)":"var(--text-dim)"},"aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]})}):(0,n.jsx)(or,{tree:tp,activeLeafId:tg,onLeafChange:tv,inline:!0,containerRef:td,open:"branches"===tG,onToggle:()=>t4("branches"),hasSession:!0}),(0,n.jsxs)("button",{ref:tC,type:"button","data-top-panel-trigger":!0,onClick:()=>t6(e),disabled:e&&!r_,title:O("system.prompt"),"aria-label":O("system.prompt"),"aria-pressed":"system"===tG,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:e?36:void 0,height:"100%",padding:e?0:"0 12px",background:"system"===tG?"var(--bg-selected)":"none",border:"none",borderTop:"system"===tG?"2px solid var(--accent)":"2px solid transparent",borderRight:"1px solid var(--border)",cursor:e&&!r_?"not-allowed":"pointer",color:"system"===tG?"var(--text)":"var(--text-muted)",opacity:e&&!r_?.45:1,fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:t=>{(!e||r_)&&(t.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="system"===tG?"var(--text)":"var(--text-muted)"},"data-mobile-toolbar-action":e?"system":void 0,children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:tb?"var(--accent)":"var(--text-dim)",flexShrink:0},"aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,n.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,n.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,n.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}),!e&&(0,n.jsx)("span",{children:O("system.label")})]}),!e&&r6(),!e&&r5(),e&&rG(!0),e&&r0(!0),e&&rQ(!0)]}):null},r8=e=>{if(!e&&(!r_||!tR&&!tY))return null;let t=tR?.tokens,r=tR?.cost??0,i=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}k`:String(e),o=r>0?r>=.01?`$${r.toFixed(2)}`:"<$0.01":null,l="var(--text-muted)",a=null,s=null;if(tY?.contextWindow){let e=tY.percent;null!==e&&e>90?l="#ef4444":null!==e&&e>70&&(l="rgba(234,179,8,0.95)"),a=null!==e?`${e.toFixed(0)}% / ${i(tY.contextWindow)}`:`? / ${i(tY.contextWindow)}`,s=null!==e?`${e.toFixed(0)}%`:null}let d=[];if(t&&(d.push(`in: ${t.input.toLocaleString(B)}`),d.push(`out: ${t.output.toLocaleString(B)}`),d.push(`cache read: ${t.cacheRead.toLocaleString(B)}`),d.push(`cache write: ${t.cacheWrite.toLocaleString(B)}`),r>0&&d.push(`cost: $${r.toFixed(4)}`)),tY?.contextWindow){let e=tY.percent;d.push(`context: ${null!==e?e.toFixed(1)+"%":"unknown"} of ${tY.contextWindow.toLocaleString()} tokens`)}let c=d.join(" | "),u=e&&eY,p=!!(t&&(t.input>0||t.output>0)||o||s);return(0,n.jsx)("button",{type:"button","data-top-panel-trigger":!0,onClick:()=>t4("session"),disabled:!r_||u,tabIndex:u?-1:void 0,title:c||O("session.title"),"aria-label":O("session.title"),"aria-pressed":"session"===tG,"aria-hidden":!!u||void 0,className:e?"mobile-session-stats":void 0,"data-mobile-toolbar-stats":e?"true":void 0,style:{marginLeft:e?0:"auto",display:"flex",alignItems:"center",justifyContent:"flex-end",flex:e?1:void 0,minWidth:0,gap:e?7:10,paddingLeft:e?6:12,paddingRight:e?6:12,height:"100%",overflow:"hidden",visibility:u?"hidden":"visible",pointerEvents:u?"none":"auto",background:"session"===tG?"var(--bg-selected)":"none",border:"none",borderTop:"session"===tG?"2px solid var(--accent)":"2px solid transparent",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:r_?"pointer":"default",fontVariantNumeric:"tabular-nums",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{r_&&!u&&(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color="session"===tG?"var(--text)":"var(--text-muted)"},children:e?(0,n.jsxs)(n.Fragment,{children:[t&&t.input>0&&(0,n.jsxs)("span",{className:"mobile-session-stat-io",style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,n.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),i(t.input)]}),t&&t.output>0&&(0,n.jsxs)("span",{className:"mobile-session-stat-io",style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),i(t.output)]}),o&&(0,n.jsx)("span",{className:"mobile-session-stat-cost",style:{color:"var(--text)",fontWeight:500,flexShrink:0},children:o}),s&&(0,n.jsx)("span",{style:{color:l,flexShrink:0},children:s}),!p&&r_&&(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",color:"var(--text-dim)"},children:O("session.title")})]}):(0,n.jsxs)(n.Fragment,{children:[t&&t.input>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,n.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),i(t.input)]}),t&&t.output>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,n.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),i(t.output)]}),t&&t.cacheRead>0&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,n.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),i(t.cacheRead)]}),o&&(0,n.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text)",fontWeight:500},children:o}),a&&(0,n.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:l},children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,n.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),a]})]})})},r4=e=>{if(0===tL.length)return null;let t=tL.filter(e=>"completed"!==e.status).length,r=tW&&!e;return(0,n.jsxs)("button",{type:"button",ref:tA,onClick:t3,title:O("todo.title"),"aria-label":O("todo.title"),"aria-expanded":tW,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,height:"100%",padding:e?"0 8px":"0 12px",background:r?"var(--bg-selected)":"none",border:"none",borderTop:r?"2px solid var(--accent)":"2px solid transparent",borderLeft:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=r?"var(--text)":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"3"}),(0,n.jsx)("path",{d:"M8 9h8M8 13h5"})]}),(0,n.jsx)("span",{children:t>0?t:"✓"})]})},r6=()=>{let e=eD&&"top"===eF;return(0,n.jsxs)("button",{type:"button",id:"terminal-topbar-btn",ref:eU,onClick:()=>t7("top"),title:O("terminal.title"),"aria-label":O("terminal.title"),"aria-expanded":e,style:{display:"flex",alignItems:"center",justifyContent:"center",width:"auto",height:"100%",padding:"0 10px",gap:5,background:e?"var(--bg-selected)":"none",border:"none",borderTop:e?"2px solid var(--accent)":"2px solid transparent",borderLeft:"1px solid var(--border)",color:e?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s",fontSize:11,whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:t=>{t.currentTarget.style.color=e?"var(--text)":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),(0,n.jsx)("span",{children:O("terminal.title")})]})},r5=()=>(0,n.jsxs)("button",{type:"button",id:"mcp-topbar-btn",ref:eK,onClick:()=>eq(e=>!e),title:"MCP","aria-label":"MCP","aria-expanded":e_,style:{display:"flex",alignItems:"center",justifyContent:"center",width:"auto",height:"100%",padding:"0 10px",gap:5,background:e_?"var(--bg-selected)":"none",border:"none",borderTop:e_?"2px solid var(--accent)":"2px solid transparent",borderLeft:"1px solid var(--border)",color:e_?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s",fontSize:11,whiteSpace:"nowrap"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color=e_?"var(--text)":"var(--text-muted)"},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M19.1 4.9L17 7M7 17l-2.1 2.1"})]}),(0,n.jsx)("span",{children:"MCP"})]}),r3=e=>{let t=e&&eY;return(0,n.jsx)("button",{type:"button",onClick:rt,disabled:t,tabIndex:t?-1:void 0,"aria-controls":"file-panel","aria-expanded":eV,"aria-hidden":!!t||void 0,title:eV?O("files.hidePanel"):O("files.showPanel"),"aria-label":eV?O("files.hidePanel"):O("files.showPanel"),"data-mobile-toolbar-file":e?"true":void 0,style:{marginLeft:e||tR||tY?0:"auto",display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,visibility:t?"hidden":"visible",pointerEvents:t?"none":"auto",background:eV?"var(--bg-selected)":"none",border:"none",borderLeft:"1px solid var(--border)",color:eV?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:e=>{t||(e.currentTarget.style.color="var(--text)")},onMouseLeave:e=>{e.currentTarget.style.color=eV?"var(--text)":"var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})},r7=(0,i.useMemo)(()=>{if(G){let e=G.projectRoot??G.cwd,t=e.split(/[\\/]/).filter(Boolean).pop()??e;return G.worktreeBranch?`${t}\xb7${G.worktreeBranch}`:t}return rF?rF.split(/[\\/]/).filter(Boolean).pop()??rF:null},[G,rF]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("style",{children:`
5
+ @keyframes session-info-pop {
6
+ 0% {
7
+ opacity: 0;
8
+ transform: translateY(-24px);
9
+ filter: blur(6px);
10
+ box-shadow: 0 2px 8px rgba(0,0,0,0);
11
+ }
12
+ 55% {
13
+ opacity: 1;
14
+ transform: translateY(0);
15
+ filter: blur(0);
16
+ background: color-mix(in srgb, var(--accent) 8%, var(--bg-panel));
17
+ box-shadow: 0 18px 44px rgba(37,99,235,0.16);
18
+ }
19
+ 100% {
20
+ opacity: 1;
21
+ transform: translateY(0);
22
+ filter: blur(0);
23
+ background: var(--bg-panel);
24
+ box-shadow: 0 10px 28px rgba(0,0,0,0.10);
25
+ }
26
+ }
27
+ @keyframes session-info-light-wash {
28
+ 0% {
29
+ opacity: 0;
30
+ transform: translateX(-110%) skewX(-16deg);
31
+ }
32
+ 24% {
33
+ opacity: 0.42;
34
+ }
35
+ 100% {
36
+ opacity: 0;
37
+ transform: translateX(115%) skewX(-16deg);
38
+ }
39
+ }
40
+ .session-info-popover {
41
+ position: relative;
42
+ overflow: hidden;
43
+ transform-origin: top right;
44
+ animation: session-info-pop 360ms ease-out both;
45
+ /* 不设 will-change:会压住 glass-top-panel 的 backdrop-filter,
46
+ 导致浏览器在合成层不渲染毛玻璃模糊(此前会话信息面板 blur 失效)。
47
+ 动画很短,去掉优化提示无感知损失。 */
48
+ }
49
+ .session-info-popover::after {
50
+ content: "";
51
+ position: absolute;
52
+ top: 0;
53
+ bottom: 0;
54
+ left: 0;
55
+ width: 44%;
56
+ pointer-events: none;
57
+ background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 24%, transparent), transparent);
58
+ animation: session-info-light-wash 620ms ease-out both;
59
+ }
60
+ @media (prefers-reduced-motion: reduce) {
61
+ .session-info-popover,
62
+ .session-info-popover::after {
63
+ animation: none;
64
+ }
65
+ }
66
+ .mobile-session-stats {
67
+ container-type: inline-size;
68
+ }
69
+ @container (max-width: 158px) {
70
+ .mobile-session-stat-io {
71
+ display: none !important;
72
+ }
73
+ }
74
+ @container (max-width: 88px) {
75
+ .mobile-session-stat-cost {
76
+ display: none !important;
77
+ }
78
+ }
79
+ @media (max-width: 640px) {
80
+ .sidebar-overlay-backdrop.sidebar-mobile-pending {
81
+ opacity: 0 !important;
82
+ pointer-events: none !important;
83
+ }
84
+ .sidebar-container.sidebar-mobile-pending.sidebar-open {
85
+ transform: translateX(calc(-100% - env(safe-area-inset-left)));
86
+ box-shadow: none;
87
+ }
88
+ }
89
+ `}),(0,n.jsxs)("div",{style:{display:"flex",width:"100%",height:"var(--app-viewport-height, 100dvh)",paddingLeft:"env(safe-area-inset-left)",paddingRight:"env(safe-area-inset-right)",overflow:"hidden",background:"transparent"},children:[eZ&&e2&&(0,n.jsxs)("div",{ref:eQ,role:"menu","aria-label":O("bg.title"),className:"glass-top-panel",style:{position:"fixed",top:e2.top,left:e2.left,zIndex:600,width:264,padding:12,fontFamily:"inherit"},children:[(0,n.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",letterSpacing:0,marginBottom:10},children:O("bg.title")}),(0,n.jsx)("input",{ref:e0,type:"file",accept:"image/*,video/mp4,video/webm",style:{display:"none"},onChange:async e=>{let t=e.target.files?.[0];t&&(await M(t),W({offsetX:0})),e.target.value=""}}),(0,n.jsxs)("button",{type:"button",onClick:()=>e0.current?.click(),disabled:!T,style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"var(--accent)",color:"#fff",border:"none",borderRadius:8,fontSize:13,fontWeight:600,cursor:"pointer",transition:"opacity 0.12s"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,n.jsx)("polyline",{points:"17 8 12 3 7 8"}),(0,n.jsx)("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),C?O("bg.replace"):O("bg.choose")]}),C&&(0,n.jsxs)("button",{type:"button",onClick:async()=>{await R(),eG(!1)},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",marginTop:6,background:"rgba(239,68,68,0.08)",color:"#dc2626",border:"1px solid rgba(239,68,68,0.25)",borderRadius:8,fontSize:13,cursor:"pointer",transition:"background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="rgba(239,68,68,0.14)"},onMouseLeave:e=>{e.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),O("bg.remove")]}),C&&(0,n.jsxs)("div",{style:{marginTop:8,display:"flex",flexDirection:"column",gap:4},children:["image"===I&&(0,n.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":E.repeat,onClick:()=>W({repeat:!E.repeat}),style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",background:E.repeat?"var(--bg-selected)":"transparent",color:"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5,cursor:"pointer",textAlign:"left",transition:"background 0.12s"},children:[(0,n.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center",color:"var(--accent)"},children:E.repeat?"✓":""}),O("bg.repeat")]}),"image"===I&&!E.repeat&&(0,n.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":E.fill,onClick:async()=>{let e=!E.fill;if(e&&L)try{let t=await (await fetch(L)).blob(),r=await ox(t);if(r)return void W({fill:e,fillColorLeft:r.left,fillColorRight:r.right})}catch{}W({fill:e})},disabled:!T,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",background:E.fill?"var(--bg-selected)":"transparent",color:"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5,cursor:"pointer",textAlign:"left",transition:"background 0.12s"},children:[(0,n.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center",color:"var(--accent)"},children:E.fill?"✓":""}),O("bg.fill")]}),(0,n.jsxs)("button",{type:"button",onClick:()=>$(!0),style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",background:"transparent",color:"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5,cursor:"pointer",textAlign:"left",transition:"background 0.12s"},children:[(0,n.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center"},children:"↔"}),O("bg.adjust")]}),(0,n.jsxs)("button",{type:"button",onClick:()=>W({offsetX:0}),disabled:0===E.offsetX,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",background:(E.offsetX,"transparent"),color:0===E.offsetX?"var(--text-dim)":"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5,cursor:0===E.offsetX?"default":"pointer",textAlign:"left",opacity:0===E.offsetX?.55:1,transition:"background 0.12s"},children:[(0,n.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center"},children:"↺"}),O("bg.reset")]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",color:"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5},children:[(0,n.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center",fontSize:12},children:"◐"}),(0,n.jsx)("span",{style:{flexShrink:0},children:O("bg.bubbleOpacity")}),(0,n.jsx)("input",{type:"range",min:0,max:100,value:E.bubbleOpacity,onChange:e=>W({bubbleOpacity:Number(e.target.value)}),style:{flex:1,minWidth:0,accentColor:"var(--accent)",cursor:"pointer"},"aria-label":O("bg.bubbleOpacity")}),(0,n.jsxs)("span",{style:{width:30,flexShrink:0,textAlign:"right",fontSize:11,color:"var(--text-dim)"},children:[E.bubbleOpacity,"%"]})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",color:"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5},children:[(0,n.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center",fontSize:12},children:"❄"}),(0,n.jsx)("span",{style:{flexShrink:0},children:O("bg.bubbleBlur")}),(0,n.jsx)("input",{type:"range",min:0,max:30,value:E.bubbleBlur,onChange:e=>W({bubbleBlur:Number(e.target.value)}),style:{flex:1,minWidth:0,accentColor:"var(--accent)",cursor:"pointer"},"aria-label":O("bg.bubbleBlur")}),(0,n.jsxs)("span",{style:{width:30,flexShrink:0,textAlign:"right",fontSize:11,color:"var(--text-dim)"},children:[E.bubbleBlur,"px"]})]}),(0,n.jsxs)("button",{type:"button",onClick:()=>W({bubbleOpacity:44,bubbleBlur:18}),disabled:44===E.bubbleOpacity&&18===E.bubbleBlur,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 10px",background:"transparent",color:44===E.bubbleOpacity&&18===E.bubbleBlur?"var(--text-dim)":"var(--text)",border:"1px solid var(--border)",borderRadius:8,fontSize:12.5,cursor:44===E.bubbleOpacity&&18===E.bubbleBlur?"default":"pointer",textAlign:"left",opacity:44===E.bubbleOpacity&&18===E.bubbleBlur?.55:1,transition:"background 0.12s"},children:[(0,n.jsx)("span",{style:{width:14,flexShrink:0,textAlign:"center"},children:"↺"}),O("bg.bubbleReset")]})]}),(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",lineHeight:1.5,marginTop:10},children:O("bg.hint")})]}),"video"===I&&L&&(0,n.jsxs)("div",{style:{position:"fixed",inset:0,zIndex:0,overflow:"hidden",pointerEvents:"none"},children:[(0,n.jsx)("video",{ref:P,src:L,autoPlay:!0,loop:!0,playsInline:!0,preload:"auto",style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}}),(0,n.jsx)("canvas",{ref:D,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),(0,n.jsx)("div",{style:{position:"absolute",inset:0,background:"var(--app-bg-scrim)"}})]}),z&&(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:700,cursor:"ew-resize",touchAction:"none"},onPointerDown:e=>{e.preventDefault();let t=e.currentTarget;t.setPointerCapture(e.pointerId);let r=e.clientX,n=E.offsetX,i=e=>{W({offsetX:n+e.clientX-r})},o=()=>{t.removeEventListener("pointermove",i),t.removeEventListener("pointerup",o)};t.addEventListener("pointermove",i),t.addEventListener("pointerup",o)},children:(0,n.jsxs)("div",{onPointerDown:e=>e.stopPropagation(),style:{position:"absolute",left:"50%",top:16,transform:"translateX(-50%)",display:"flex",alignItems:"center",gap:10,padding:"8px 14px",borderRadius:999,background:"var(--panel-glass)",color:"var(--text)",border:"1px solid var(--border)",fontSize:12,whiteSpace:"nowrap"},children:[O("bg.adjustHint"),(0,n.jsx)("button",{type:"button",onClick:()=>$(!1),style:{background:"var(--accent)",color:"#fff",border:"none",borderRadius:999,padding:"4px 12px",fontSize:12,fontWeight:600,cursor:"pointer",flexShrink:0},children:O("bg.adjustDone")})]})}),(0,n.jsx)("div",{className:`sidebar-overlay-backdrop${e4?"":" sidebar-mobile-pending"}`,onClick:()=>eA(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!eP,pointerEvents:eP?"auto":"none",transition:"opacity 0.25s ease"}}),(0,n.jsx)("div",{ref:tn.panelRef,id:"session-sidebar",className:`sidebar-container${eP?" sidebar-open":" sidebar-closed"}${e4?"":" sidebar-mobile-pending"}${tn.isResizing?" sidebar-resizing":""}`,style:{"--sidebar-width":`${tn.width}px`,background:"var(--side-panel)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",borderRight:"1px solid color-mix(in srgb, var(--border) 80%, transparent)",display:"flex",flexDirection:"column",flexShrink:0,paddingTop:"env(safe-area-inset-top)",paddingBottom:"env(safe-area-inset-bottom)",zIndex:200},children:rZ}),eP&&(0,n.jsx)("div",{...tn.separatorProps,"aria-controls":"session-sidebar",className:`panel-resize-handle sidebar-resize-handle${tn.isResizing?" is-resizing":""}`,"data-resize-handle":"sidebar",title:`${O("layout.resizeSidebar")}: ${O("layout.resizeHint")}`}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,n.jsxs)("div",{ref:td,style:{position:"relative",zIndex:300,flexShrink:0,background:"var(--frame-glass)",backdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-heavy)) saturate(var(--glass-saturate))"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",position:"relative",borderBottom:"1px solid var(--border)",height:"calc(36px + env(safe-area-inset-top))",paddingTop:"env(safe-area-inset-top)"},children:[(0,n.jsx)("button",{onClick:t9,title:eP?O("sidebar.hide"):O("sidebar.show"),"aria-label":eP?O("sidebar.hide"):O("sidebar.show"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",borderRight:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},children:eP?(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,n.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),_&&(0,n.jsxs)("div",{ref:tc,"data-mobile-toolbar":"true",style:{position:"relative",display:"flex",alignItems:"stretch",flex:1,minWidth:0,height:"100%"},children:[(0,n.jsx)("button",{type:"button",onClick:re,title:eY?O("chat.close"):O("chat.moreControls"),"aria-label":eY?O("chat.close"):O("chat.moreControls"),"aria-controls":"mobile-toolbar-actions","aria-expanded":eY,"data-mobile-toolbar-more":"true",style:{position:"relative",zIndex:eY?21:void 0,display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:eY?"var(--bg-selected)":"none",border:"none",borderRight:"1px solid var(--border)",color:eY?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},children:eY?(0,n.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("line",{x1:"5",y1:"5",x2:"19",y2:"19"}),(0,n.jsx)("line",{x1:"19",y1:"5",x2:"5",y2:"19"})]}):(0,n.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),r8(!0),r4(!0),r3(!0),eY&&(0,n.jsx)("div",{id:"mobile-toolbar-actions",role:"toolbar","aria-label":O("chat.moreControls"),"data-mobile-toolbar-actions":"true",style:{position:"absolute",top:0,right:0,bottom:0,left:36,zIndex:20,display:"flex",alignItems:"stretch",background:"color-mix(in srgb, var(--glass-bg-strong) 60%, transparent)",boxShadow:"4px 0 18px rgba(0,0,0,0.12)",backdropFilter:"blur(var(--glass-blur-popover)) saturate(var(--glass-saturate))"},children:r2(!0)})]}),!_&&(0,n.jsxs)(n.Fragment,{children:[rQ(!1),rG(!1),r0(!1),r1(!1),r2(!1),r8(!1),r4(!1)]}),!_&&r3(!1),_&&(0,n.jsx)(or,{tree:tp,activeLeafId:tg,onLeafChange:tv,inline:!0,compact:!0,containerRef:td,open:"branches"===tG,onToggle:()=>t4("branches"),hasSession:r_,hideInlineButton:!0}),tG&&t1&&(0,o.createPortal)((0,n.jsxs)("div",{ref:t8,style:{position:"fixed",top:t1.top,left:t1.left,width:t1.width,maxHeight:`calc(100dvh - ${t1.top}px)`,overflowY:"auto",zIndex:500},children:["language"===tG&&(0,n.jsx)("div",{role:"menu","aria-label":O("common.language"),className:"glass-top-panel",style:{overflow:"hidden",padding:4},children:U.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>{H(e.id),t0(null)},role:"menuitemradio","aria-checked":B===e.id,style:{display:"flex",alignItems:"center",width:"100%",height:34,padding:"0 10px",border:"none",borderRadius:4,background:B===e.id?"var(--side-selected)":"transparent",color:B===e.id?"var(--accent)":"var(--text)",cursor:"pointer",textAlign:"left",fontSize:12,transition:"background 0.1s",fontWeight:B===e.id?600:400},onMouseEnter:t=>{B!==e.id&&(t.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:t=>{B!==e.id&&(t.currentTarget.style.background="transparent")},children:(0,n.jsx)("span",{children:e.label})},e.id))}),"system"===tG&&(0,n.jsx)("div",{className:"glass-top-panel",children:tb?(0,n.jsx)("div",{style:{maxHeight:"min(600px, 75vh)",overflowY:"auto",padding:"12px 16px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:tb}):""===tb?(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:O("system.empty")}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:tk?O("system.loading"):O("system.load")})}),"session"===tG&&(0,n.jsx)("div",{className:"session-info-popover glass-top-panel",style:{padding:"12px 16px",maxWidth:"min(560px, 100%)",marginLeft:"auto"},children:tR?(e=tR.totalActiveMs??0,t=[...tR.sessionName?[{label:O("session.name"),value:tR.sessionName,copyField:null}]:[],{label:O("session.file"),value:tR.sessionFile??O("session.inMemory"),copyField:"file"},{label:O("session.id"),value:tR.sessionId,copyField:"id"},...e>0?[{label:O("session.totalActive"),value:(e=>{if(e<=0)return"0s";let t=Math.floor(e/1e3),r=Math.floor(t/3600),n=Math.floor(t%3600/60),i=t%60;return r>0?`${r}h ${n}m`:n>0?`${n}m ${i}s`:`${i}s`})(e),copyField:null}]:[]],r=[[O("session.user"),tR.userMessages.toLocaleString(B)],[O("session.assistant"),tR.assistantMessages.toLocaleString(B)],[O("session.toolCalls"),tR.toolCalls.toLocaleString(B)],[O("session.toolResults"),tR.toolResults.toLocaleString(B)],[O("session.total"),tR.totalMessages.toLocaleString(B)]],a=[[O("session.input"),tR.tokens.input.toLocaleString(B)],[O("session.output"),tR.tokens.output.toLocaleString(B)],...tR.tokens.cacheRead>0?[[O("session.cacheRead"),tR.tokens.cacheRead.toLocaleString(B)]]:[],...tR.tokens.cacheWrite>0?[[O("session.cacheWrite"),tR.tokens.cacheWrite.toLocaleString(B)]]:[],[O("session.total"),tR.tokens.total.toLocaleString(B)]],d=tY??tR.contextUsage,u=[...tR.cost>0?[[O("session.cost"),`$${tR.cost.toFixed(4)}`]]:[],...d?.contextWindow?[[O("session.context"),`${null!==d.percent?`${d.percent.toFixed(1)}%`:"?"} / ${(c=d.contextWindow)>=1e6?`${(c/1e6).toFixed(1)}M`:c>=1e3?`${(c/1e3).toFixed(0)}k`:String(c)}`]]:[],...tR.tokens.cacheRead+tR.tokens.cacheWrite>0&&tR.tokens.cacheRead+tR.tokens.cacheWrite+tR.tokens.input>0?[[O("session.cacheHitRate"),`${(tR.tokens.cacheRead/(tR.tokens.cacheRead+tR.tokens.cacheWrite+tR.tokens.input)*100).toFixed(1)}%`]]:[]],p=(e,t,r="left",i=!1)=>(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:e}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:i?"max-content minmax(0, 1fr)":"auto minmax(0, 1fr)",columnGap:i?14:12,rowGap:4,justifyContent:i?"start":void 0},children:t.map(([t,i])=>(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-meta)",whiteSpace:"nowrap"},children:t}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",textAlign:r,whiteSpace:"normal"},children:i})]},`${e}:${t}`))})]}),v=(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:O("session.infoSection")}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:t.map(e=>{var t,r;let i;return(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-meta)",whiteSpace:"nowrap"},children:e.label}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"normal"},children:e.value}),(0,n.jsx)("div",{children:e.copyField?(t=e.copyField,r=e.value,i=tq===t,(0,n.jsx)("button",{type:"button",title:i?O("session.copied"):O("file"===t?"session.copyFile":"session.copyId"),onClick:()=>tJ(t,r),style:{alignSelf:"start",display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,marginTop:-2,color:i?"var(--accent)":"var(--text-meta)",background:"transparent",border:"1px solid var(--border)",borderRadius:4,cursor:"pointer",flex:"0 0 auto",transition:"color 0.12s, border-color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=i?"var(--accent)":"var(--text-meta)",e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="transparent"},children:i?(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})}):(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})):null})]},`session-info:${e.label}`)})})]}),(0,n.jsxs)("div",{style:{display:"grid",gap:_?16:20,fontSize:12,lineHeight:1.5,fontFamily:"var(--font-mono)"},children:[v,(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:_?"1fr":"minmax(160px, 0.5fr) minmax(240px, 0.7fr)",gap:_?16:24},children:[p(O("session.messages"),r),p(O("session.tokens"),[...a,...u],"right",!0)]})]})):(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:O("session.load")})})]}),document.body),tW&&t$&&(0,o.createPortal)((0,n.jsxs)("div",{ref:tD,role:"menu","aria-label":O("todo.title"),style:{position:"fixed",top:t$.top,right:t$.right,width:300,maxHeight:"min(440px, calc(100dvh - 44px))",overflowY:"auto",zIndex:500,background:"var(--panel-glass-todo)",backdropFilter:"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))",WebkitBackdropFilter:"blur(var(--glass-blur-panel)) saturate(var(--glass-saturate))",transform:"translateZ(0)",border:"1px solid color-mix(in srgb, var(--border) 60%, transparent)",borderRadius:"0 0 12px 12px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 4px 16px -8px rgba(15,23,42,0.10)",fontFamily:"inherit"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"9px 12px",borderBottom:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",fontSize:12,fontWeight:650,color:"var(--text)"},children:[O("todo.title"),(0,n.jsxs)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-meta)",fontWeight:500},children:[tL.filter(e=>"completed"===e.status).length,"/",tL.length," ",O("todo.completed")]})]}),0===tL.length?(0,n.jsx)("div",{style:{padding:"12px 14px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:O("todo.empty")}):(0,n.jsx)("div",{style:{maxHeight:330,overflowY:"auto"},children:tL.map(e=>{let t="completed"===e.status,r="high"===e.priority?"#ef4444":"medium"===e.priority?"rgba(234,179,8,0.9)":"var(--text-meta)";return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,padding:"7px 12px",borderBottom:"1px solid color-mix(in srgb, var(--border) 45%, transparent)"},children:[(0,n.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,marginTop:2,width:13,height:13,borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:800,lineHeight:1,color:t?"#fff":"transparent",background:t?"#16a34a":"color-mix(in srgb, var(--border) 70%, transparent)",border:t?"none":"1px solid color-mix(in srgb, var(--border) 80%, transparent)"},children:"✓"}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,fontSize:12,lineHeight:1.4,color:t?"var(--text-meta)":"var(--text)",textDecoration:t?"line-through":"none",wordBreak:"break-word"},children:e.content}),(0,n.jsx)("span",{"aria-hidden":"true",style:{flexShrink:0,marginTop:5,width:7,height:7,borderRadius:"50%",background:r}})]},e.id??e.content)})})]}),document.body)]}),_&&r1(!0)]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:r_?(0,n.jsx)(nl,{session:G,sessionRunning:!!(G&&ee.has(G.id)),newSessionCwd:rF,newSessionDraftKey:rB,onAgentEnd:rM,onAttentionNeeded:rR,onSessionCreated:rC,onSessionForked:rW,modelsRefreshKey:ek,chatInputRef:ts,onBranchDataChange:tm,onSystemPromptChange:tT,onSystemPromptLoaderChange:tM,onSessionStatsChange:tO,onSessionStatsPanelOpen:t5,onTodosChange:tU,onContextUsageChange:tZ,onOpenFile:rA,soundEnabled:q,onSoundToggle:K,playDoneSound:V,unlockAudio:J,terminalOpen:eD&&"bottombar"===eF,onToggleTerminal:()=>t7("bottombar")},ef):"validating"===ed?(0,n.jsxs)("div",{role:"status",style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,padding:24,color:"var(--text-muted)",textAlign:"center"},children:[(0,n.jsx)("div",{style:{fontSize:14,color:"var(--text)"},children:O("workspace.opening")}),(0,n.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:w.requestedCwd})]}):"error"===ed?(0,n.jsxs)("div",{role:"alert",style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,padding:24,color:"var(--text-muted)",textAlign:"center"},children:[(0,n.jsx)("div",{style:{fontSize:14,color:"#dc2626"},children:O("workspace.unable")}),(0,n.jsx)("div",{style:{maxWidth:"min(720px, 100%)",overflowWrap:"anywhere",fontFamily:"var(--font-mono)",fontSize:12},children:w.requestedCwd}),(0,n.jsx)("div",{style:{maxWidth:720,fontSize:12},children:eu})]}):rK?rp?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:O("workspace.selectSession")}):(0,n.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,n.jsxs)("svg",{width:"44",height:"44",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.7,flexShrink:0},children:[(0,n.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,n.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:O("workspace.getStarted")}),(0,n.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,n.jsx)("span",{style:{color:"var(--text-meta)",marginRight:6},children:"1."}),O("workspace.selectProject"),(0,n.jsx)("br",{}),(0,n.jsx)("span",{style:{color:"var(--text-meta)",marginRight:6},children:"2."}),O("workspace.addModels")]})]})]}):null})]}),(0,n.jsx)("div",{"aria-hidden":"true",className:`right-panel-overlay-backdrop${eV?" is-open":""}`,onClick:()=>eJ(!1)}),eV&&(0,n.jsx)("div",{...ti.separatorProps,"aria-controls":"file-panel",className:`panel-resize-handle right-panel-resize-handle${ti.isResizing?" is-resizing":""}`,"data-resize-handle":"right-panel",title:`${O("layout.resizeFilePanel")}: ${O("layout.resizeHint")}`}),(0,n.jsxs)("div",{ref:ti.panelRef,id:"file-panel",className:`right-panel-container${eV?" right-panel-open":" right-panel-closed"}${ti.isResizing?" right-panel-resizing":""}`,style:{"--right-panel-width":`${ti.width}px`,display:"flex",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,height:"calc(36px + env(safe-area-inset-top))",paddingTop:"env(safe-area-inset-top)",background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,n.jsx)(nP,{tabs:rr,activeTabId:ri??"",onSelectTab:rl,onCloseTab:rD})}),(0,n.jsx)("button",{type:"button",onClick:()=>eJ(!1),"aria-controls":"file-panel","aria-expanded":eV,title:O("files.hidePanel"),"aria-label":O("files.hidePanel"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"var(--bg-selected)",border:"none",borderLeft:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",flexShrink:0,transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text)"},children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"hidden",paddingBottom:"env(safe-area-inset-bottom)"},children:rJ?.filePath?(0,n.jsx)(nz,{filePath:rJ.filePath,cwd:rp??void 0,sourceSessionId:rJ.sourceSessionId,gitRefreshKey:em,initialDisplayMode:rJ.initialDisplayMode,initialState:rJ.viewerState,watchEnabled:eV,onStateChange:e=>ra(rJ.id,rJ.viewerRevision??0,e),onMentionLines:eV?rc:void 0,onAtMention:rs,onOpenFile:e=>rP(e,A(e),{sourceSessionId:rJ.sourceSessionId})},`${rJ.id}:${rJ.viewerRevision??0}`):(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-meta)",fontSize:12},children:O("files.noneOpen")})})]})]}),eb&&(0,n.jsx)(iL,{onClose:()=>{ey(!1),ew(e=>e+1)}}),(0,n.jsx)(om,{origin:eF,anchorRect:eH,activeCwd:G?.cwd??rF??null,activeProjectLabel:r7,hidden:!eD,onClose:()=>eN(!1)}),(0,n.jsx)(i3,{anchorRect:e_?(()=>{let e=eK.current;if(!e)return null;let t=e.getBoundingClientRect();return{top:t.top,left:t.left,right:t.right,bottom:t.bottom}})():null,cwd:G?.cwd??rF??null,hidden:!e_,onClose:()=>eq(!1)}),eI&&rq&&(0,n.jsx)(i7,{cwd:rq,busy:eE,error:ez,onCancel:()=>{eE||eL(!1)},onConfirm:()=>void rV()}),ej&&rq&&(0,n.jsx)(iF,{cwd:rq,onClose:()=>eS(!1)}),eC&&rq&&(0,n.jsx)(iQ,{cwd:rq,sessionId:G?.id??null,onClose:()=>eT(!1),onReloaded:()=>ex(e=>e+1)})]})}},88576:e=>{e.exports={preview:"ChatMinimap_preview__laAya",turn:"ChatMinimap_turn__fZuce",number:"ChatMinimap_number__3C_cY",content:"ChatMinimap_content__C7_ju",user:"ChatMinimap_user__WHJHv",userText:"ChatMinimap_userText__Nj9jo",assistant:"ChatMinimap_assistant__s6JLb",assistantJump:"ChatMinimap_assistantJump__3CM2M",outline:"ChatMinimap_outline__aleIF",heading:"ChatMinimap_heading__djZbv",paragraph:"ChatMinimap_paragraph__EqWlO"}}},e=>{e.O(0,[3578,7330,1074,8441,3794,7358],()=>e(e.s=67061)),_N_E=e.O()}]);