@adhdev/daemon-standalone 1.0.17 → 1.0.18-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-standalone",
3
- "version": "1.0.17",
3
+ "version": "1.0.18-rc.1",
4
4
  "description": "ADHDev standalone daemon — embedded HTTP/WS server for local dashboard",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -37,7 +37,7 @@
37
37
  "license": "AGPL-3.0-or-later",
38
38
  "dependencies": {
39
39
  "@adhdev/ghostty-vt-node": "*",
40
- "@adhdev/session-host-core": "*",
40
+ "@adhdev/session-host-core": "1.0.18-rc.1",
41
41
  "@xterm/addon-serialize": "^0.14.0",
42
42
  "@xterm/xterm": "^6.0.0",
43
43
  "chalk": "^5.3.0",
@@ -1,11 +1,11 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-BZj_X5zy.js","assets/vendor-cL4V2vaO.js","assets/terminal-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
2
- var kh=Object.defineProperty;var Sh=(e,t,n)=>t in e?kh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var st=(e,t,n)=>Sh(e,typeof t!="symbol"?t+"":t,n);import{r as l,j as s,u as Ne,M as Si,a as Ch,b as jh,c as Nh,t as Ah,d as Mh,i as wt,e as Th,f as fn,R as Rt,T as Bo,g as mr,h as Oo,k as Wo,D as Ih,E as Ph,l as Dh,C as Lh,m as Rh,B as Eh,n as _h,o as $h,p as Hh,H as yr,P as Cs,q as Fh,s as Bh,v as Oh,w as jl,x as Wh,y as Uh,z as Ci,A as Gh,F as qh,G as zh,I as Kh,J as js,N as Uo,K as Vh}from"./vendor-cL4V2vaO.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const o of a)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(a){const o={};return a.integrity&&(o.integrity=a.integrity),a.referrerPolicy&&(o.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?o.credentials="include":a.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(a){if(a.ep)return;a.ep=!0;const o=n(a);fetch(a.href,o)}})();function Yh(e={}){const t=Math.max(1,Math.floor(e.capacity||200)),n=[];return{record(r){const a={id:`webdbg_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`,ts:Date.now(),...r,payload:r.payload?{...r.payload}:{}};return n.push(a),n.length>t&&n.splice(0,n.length-t),a},list(r={}){const a=Math.max(1,Math.floor(r.limit||100));return n.filter(o=>!r.interactionId||o.interactionId===r.interactionId).filter(o=>!r.topic||o.topic===r.topic).filter(o=>!r.kind||o.kind===r.kind).slice(-a).map(o=>({...o,payload:o.payload?{...o.payload}:{}}))},clear(){n.splice(0,n.length)}}}const bn=Yh();function Nl(e){const t={};for(const n of e)n.transport&&(t[n.transport]=(t[n.transport]||0)+1);return{count:e.length,ids:e.map(n=>n.id),statuses:e.map(n=>String(n.status||"unknown")),transports:t}}function Jh(e,t){return typeof e=="string"&&e.trim().length>0&&e!==t}function Al(e){return Array.isArray(e)?[...e]:[]}function _d(e,t){if(!e)return t??null;const n=Object.prototype.hasOwnProperty.call(e,"messages"),r=Object.prototype.hasOwnProperty.call(e,"activeModal"),a=typeof e.id=="string"?e.id.trim():"",o=typeof(t==null?void 0:t.id)=="string"?t.id.trim():"",i=!!a&&!!o&&a!==o;return t?{...t,...e,messages:n?Al(e.messages):i?[]:t.messages,activeModal:r?e.activeModal??null:t.activeModal,inputContent:e.inputContent??t.inputContent}:{...e,...n?{messages:Al(e.messages)}:{},...r?{activeModal:e.activeModal??null}:{}}}function zn(e,t){const n=Jh(e.providerName,e.providerType)?e.providerName:void 0;return{...e,parentId:e.parentId??(t==null?void 0:t.parentSessionId)??null,providerSessionId:e.providerSessionId??(t==null?void 0:t.providerSessionId),providerName:n??(t==null?void 0:t.providerName)??(t==null?void 0:t.cliName)??(t==null?void 0:t.type)??e.providerName??e.providerType,title:e.title??(t==null?void 0:t.title)??n??(t==null?void 0:t.providerName)??e.providerName??e.providerType,workspace:e.workspace??(t==null?void 0:t.workspace)??null,mode:e.mode??(t==null?void 0:t.mode),capabilities:e.capabilities??(t==null?void 0:t.sessionCapabilities)??(t==null?void 0:t.capabilities)??[],cdpConnected:e.cdpConnected??(t==null?void 0:t.cdpConnected),activeChat:_d(e.activeChat,t==null?void 0:t.activeChat),activeInteractivePrompt:Object.prototype.hasOwnProperty.call(e,"activeInteractivePrompt")?e.activeInteractivePrompt??null:(t==null?void 0:t.activeInteractivePrompt)??null,controlValues:e.controlValues??(t==null?void 0:t.controlValues),providerControls:e.providerControls??(t==null?void 0:t.providerControls),summaryMetadata:e.summaryMetadata??(t==null?void 0:t.summaryMetadata),runtimeWriteOwner:e.runtimeWriteOwner??(t==null?void 0:t.runtimeWriteOwner),runtimeAttachedClients:e.runtimeAttachedClients??(t==null?void 0:t.runtimeAttachedClients),lastMessagePreview:e.lastMessagePreview??(t==null?void 0:t.lastMessagePreview),lastMessageRole:e.lastMessageRole??(t==null?void 0:t.lastMessageRole),lastMessageAt:e.lastMessageAt??(t==null?void 0:t.lastMessageAt),lastMessageHash:e.lastMessageHash??(t==null?void 0:t.lastMessageHash),unread:e.unread??(t==null?void 0:t.unread),lastSeenAt:e.lastSeenAt??(t==null?void 0:t.lastSeenAt),inboxBucket:e.inboxBucket??(t==null?void 0:t.inboxBucket),completionMarker:e.completionMarker??(t==null?void 0:t.completionMarker),seenCompletionMarker:e.seenCompletionMarker??(t==null?void 0:t.seenCompletionMarker),surfaceHidden:e.surfaceHidden??(t==null?void 0:t.surfaceHidden),muted:e.muted??(t==null?void 0:t.muted),resume:e.resume??(t==null?void 0:t.resume),runtimeKey:e.runtimeKey??(t==null?void 0:t.runtimeKey),runtimeDisplayName:e.runtimeDisplayName??(t==null?void 0:t.runtimeDisplayName),runtimeWorkspaceLabel:e.runtimeWorkspaceLabel??(t==null?void 0:t.runtimeWorkspaceLabel),settings:e.settings??(t==null?void 0:t.settings)}}function $d(e,t,n){if(!(t!=null&&t.length))return(n==null?void 0:n.preserveMissing)===!1&&Array.isArray(t)?t:e;if(!(e!=null&&e.length))return t;const r=t.map(a=>{const o=e.find(i=>i.id===a.id);return o?zn(a,o):a});if((n==null?void 0:n.preserveMissing)!==!1){const a=new Set(t.map(o=>o.id));for(const o of e)a.has(o.id)||r.push(o)}return r}function Ml(e){return!!e&&typeof e=="object"&&"text"in e}function ji(e,t){const n=(t==null?void 0:t.joiner)??" ",r=(t==null?void 0:t.normalizeWhitespace)??!1;let a="";return typeof e=="string"?a=e:Array.isArray(e)?a=e.map(o=>typeof o=="string"?o:Ml(o)?String(o.text||""):"").join(n):Ml(e)?a=String(e.text||""):a=String(e||""),r?a.replace(/\s+/g," ").trim():a}function gn(e){return ji(e,{normalizeWhitespace:!0})}function Qh(e){let t="";for(let n=0;n<e.length;n++){const r=e[n],a=e.charCodeAt(n);if(!(a<=31&&r!==`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-DiXj2eIR.js","assets/vendor-DyCWA2YZ.js","assets/terminal-6GBZ9nXN.css"])))=>i.map(i=>d[i]);
2
+ var kh=Object.defineProperty;var Sh=(e,t,n)=>t in e?kh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var st=(e,t,n)=>Sh(e,typeof t!="symbol"?t+"":t,n);import{r as l,j as s,u as Ne,M as Si,a as Ch,b as jh,c as Nh,t as Ah,d as Mh,i as wt,e as Th,f as fn,R as Rt,T as Bo,g as mr,h as Oo,k as Wo,D as Ih,E as Ph,l as Dh,C as Lh,m as Rh,B as Eh,n as _h,o as $h,p as Hh,H as yr,P as Cs,q as Fh,s as Bh,v as Oh,w as jl,x as Wh,y as Uh,z as Ci,A as Gh,F as qh,G as zh,I as Kh,J as js,N as Uo,K as Vh}from"./vendor-DyCWA2YZ.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const o of a)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(a){const o={};return a.integrity&&(o.integrity=a.integrity),a.referrerPolicy&&(o.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?o.credentials="include":a.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(a){if(a.ep)return;a.ep=!0;const o=n(a);fetch(a.href,o)}})();function Yh(e={}){const t=Math.max(1,Math.floor(e.capacity||200)),n=[];return{record(r){const a={id:`webdbg_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`,ts:Date.now(),...r,payload:r.payload?{...r.payload}:{}};return n.push(a),n.length>t&&n.splice(0,n.length-t),a},list(r={}){const a=Math.max(1,Math.floor(r.limit||100));return n.filter(o=>!r.interactionId||o.interactionId===r.interactionId).filter(o=>!r.topic||o.topic===r.topic).filter(o=>!r.kind||o.kind===r.kind).slice(-a).map(o=>({...o,payload:o.payload?{...o.payload}:{}}))},clear(){n.splice(0,n.length)}}}const bn=Yh();function Nl(e){const t={};for(const n of e)n.transport&&(t[n.transport]=(t[n.transport]||0)+1);return{count:e.length,ids:e.map(n=>n.id),statuses:e.map(n=>String(n.status||"unknown")),transports:t}}function Jh(e,t){return typeof e=="string"&&e.trim().length>0&&e!==t}function Al(e){return Array.isArray(e)?[...e]:[]}function _d(e,t){if(!e)return t??null;const n=Object.prototype.hasOwnProperty.call(e,"messages"),r=Object.prototype.hasOwnProperty.call(e,"activeModal"),a=typeof e.id=="string"?e.id.trim():"",o=typeof(t==null?void 0:t.id)=="string"?t.id.trim():"",i=!!a&&!!o&&a!==o;return t?{...t,...e,messages:n?Al(e.messages):i?[]:t.messages,activeModal:r?e.activeModal??null:t.activeModal,inputContent:e.inputContent??t.inputContent}:{...e,...n?{messages:Al(e.messages)}:{},...r?{activeModal:e.activeModal??null}:{}}}function zn(e,t){const n=Jh(e.providerName,e.providerType)?e.providerName:void 0;return{...e,parentId:e.parentId??(t==null?void 0:t.parentSessionId)??null,providerSessionId:e.providerSessionId??(t==null?void 0:t.providerSessionId),providerName:n??(t==null?void 0:t.providerName)??(t==null?void 0:t.cliName)??(t==null?void 0:t.type)??e.providerName??e.providerType,title:e.title??(t==null?void 0:t.title)??n??(t==null?void 0:t.providerName)??e.providerName??e.providerType,workspace:e.workspace??(t==null?void 0:t.workspace)??null,mode:e.mode??(t==null?void 0:t.mode),capabilities:e.capabilities??(t==null?void 0:t.sessionCapabilities)??(t==null?void 0:t.capabilities)??[],cdpConnected:e.cdpConnected??(t==null?void 0:t.cdpConnected),activeChat:_d(e.activeChat,t==null?void 0:t.activeChat),activeInteractivePrompt:Object.prototype.hasOwnProperty.call(e,"activeInteractivePrompt")?e.activeInteractivePrompt??null:(t==null?void 0:t.activeInteractivePrompt)??null,controlValues:e.controlValues??(t==null?void 0:t.controlValues),providerControls:e.providerControls??(t==null?void 0:t.providerControls),summaryMetadata:e.summaryMetadata??(t==null?void 0:t.summaryMetadata),runtimeWriteOwner:e.runtimeWriteOwner??(t==null?void 0:t.runtimeWriteOwner),runtimeAttachedClients:e.runtimeAttachedClients??(t==null?void 0:t.runtimeAttachedClients),lastMessagePreview:e.lastMessagePreview??(t==null?void 0:t.lastMessagePreview),lastMessageRole:e.lastMessageRole??(t==null?void 0:t.lastMessageRole),lastMessageAt:e.lastMessageAt??(t==null?void 0:t.lastMessageAt),lastMessageHash:e.lastMessageHash??(t==null?void 0:t.lastMessageHash),unread:e.unread??(t==null?void 0:t.unread),lastSeenAt:e.lastSeenAt??(t==null?void 0:t.lastSeenAt),inboxBucket:e.inboxBucket??(t==null?void 0:t.inboxBucket),completionMarker:e.completionMarker??(t==null?void 0:t.completionMarker),seenCompletionMarker:e.seenCompletionMarker??(t==null?void 0:t.seenCompletionMarker),surfaceHidden:e.surfaceHidden??(t==null?void 0:t.surfaceHidden),muted:e.muted??(t==null?void 0:t.muted),resume:e.resume??(t==null?void 0:t.resume),runtimeKey:e.runtimeKey??(t==null?void 0:t.runtimeKey),runtimeDisplayName:e.runtimeDisplayName??(t==null?void 0:t.runtimeDisplayName),runtimeWorkspaceLabel:e.runtimeWorkspaceLabel??(t==null?void 0:t.runtimeWorkspaceLabel),settings:e.settings??(t==null?void 0:t.settings)}}function $d(e,t,n){if(!(t!=null&&t.length))return(n==null?void 0:n.preserveMissing)===!1&&Array.isArray(t)?t:e;if(!(e!=null&&e.length))return t;const r=t.map(a=>{const o=e.find(i=>i.id===a.id);return o?zn(a,o):a});if((n==null?void 0:n.preserveMissing)!==!1){const a=new Set(t.map(o=>o.id));for(const o of e)a.has(o.id)||r.push(o)}return r}function Ml(e){return!!e&&typeof e=="object"&&"text"in e}function ji(e,t){const n=(t==null?void 0:t.joiner)??" ",r=(t==null?void 0:t.normalizeWhitespace)??!1;let a="";return typeof e=="string"?a=e:Array.isArray(e)?a=e.map(o=>typeof o=="string"?o:Ml(o)?String(o.text||""):"").join(n):Ml(e)?a=String(e.text||""):a=String(e||""),r?a.replace(/\s+/g," ").trim():a}function gn(e){return ji(e,{normalizeWhitespace:!0})}function Qh(e){let t="";for(let n=0;n<e.length;n++){const r=e[n],a=e.charCodeAt(n);if(!(a<=31&&r!==`
3
3
  `&&r!==" ")&&!(a>=127&&a<=159)&&!(a>=8203&&a<=8207||a>=8234&&a<=8238||a===8288||a===65279)&&a!==65533){if(a===65038||a===65039){const o=t.length>0?t[t.length-1]:"";if(!o||o===`
4
4
  `||o===" "||o===" ")continue}t+=r}}return t}function Tl(e){var n,r;let t=0;return e.activeChat!==void 0&&(t+=4),e.activeInteractivePrompt!==void 0&&(t+=2),(n=e.childSessions)!=null&&n.length&&(t+=2),e.workspace&&(t+=1),e.machine&&(t+=1),(r=e.agents)!=null&&r.length&&(t+=1),t}function Hd(e,t,n){if(n.type!=="adhdev-daemon")return n;const r={...n},a=t.version??n.version??e.version,o=t.serverVersion??e.serverVersion??n.serverVersion,i=t.versionMismatch===!0||e.versionMismatch===!0,c=t.versionUpdateRequired===!0||e.versionUpdateRequired===!0,u=t.versionUpdateReason??e.versionUpdateReason??n.versionUpdateReason;return a&&(r.version=a),o&&(r.serverVersion=o),u&&(r.versionUpdateReason=u),a&&o&&a===o?(delete r.versionMismatch,delete r.serverVersion,delete r.versionUpdateRequired,delete r.versionUpdateReason,r):((t.versionMismatch===!0||i&&a&&o&&a!==o)&&(r.versionMismatch=!0),c&&(r.versionUpdateRequired=!0),r)}function Xh(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return t.toString(16).padStart(8,"0")}function Ua(e){if(!e||typeof e!="object")return"";const t=e,n=Xh(gn(t.content).slice(0,512));return[String(t.id||""),String(t._localId||""),String(t._turnKey||""),String(t.index??""),String(t.role||""),String(t.receivedAt??t.timestamp??""),n].join(":")}function Zh(e,t){if(!Array.isArray(e))return e;if(t!=null&&t.has(e))return{count:e.length,sharedRef:!0};let n=2166136261;for(const r of e){const a=Ua(r);for(let o=0;o<a.length;o+=1)n^=a.charCodeAt(o),n=Math.imul(n,16777619)>>>0}return{count:e.length,hash:n.toString(16).padStart(8,"0"),first:Ua(e[0]),last:Ua(e[e.length-1])}}function Go(e){return!!e&&typeof e=="object"&&"messages"in e&&("activeModal"in e||"inputContent"in e||"status"in e)}function qo(e,t,n){if(!e||!t||typeof e!="object"||typeof t!="object")return;if(Go(e)&&Go(t)){const i=e.messages;Array.isArray(i)&&i===t.messages&&n.add(i)}if(Array.isArray(e)&&Array.isArray(t)){const i=Math.min(e.length,t.length);for(let c=0;c<i;c+=1)qo(e[c],t[c],n);return}const r=e,a=t,o=new Set([...Object.keys(r),...Object.keys(a)]);for(const i of o)i!=="messages"&&qo(r[i],a[i],n)}function Jn(e,t){return Array.isArray(e)?e.map(n=>Jn(n,t)):!e||typeof e!="object"?e:Go(e)?Object.fromEntries(Object.entries(e).filter(([r])=>r!=="timestamp"&&r!=="_lastUpdate").sort(([r],[a])=>r.localeCompare(a)).map(([r,a])=>[r,r==="messages"?Zh(a,t):Jn(a,t)])):Object.fromEntries(Object.entries(e).filter(([n])=>n!=="timestamp"&&n!=="_lastUpdate").sort(([n],[r])=>n.localeCompare(r)).map(([n,r])=>[n,Jn(r,t)]))}function ef(e,t){try{const n=new WeakSet;return qo(e,t,n),JSON.stringify(Jn(e,n))===JSON.stringify(Jn(t,n))}catch{return!1}}function zo(e,t,n){return ef(e,t)?(e._lastUpdate=n,typeof t.timestamp=="number"&&(e.timestamp=t.timestamp),e):t}function Fd(e){var t;return e.daemonId||((t=e.id)==null?void 0:t.split(":")[0])||e.id}function tf(e,t,n){t[n]!==void 0&&(e[n]=t[n])}function Il(e,t,n,r){var u;const a=(u=t.chats)!=null&&u.length?t.chats:e.chats,o=$d(e.childSessions,t.childSessions,{preserveMissing:r}),i=_d(t.activeChat,e.activeChat),c=t.workspace||e.workspace;return Hd(e,t,{...e,...t,chats:a,childSessions:o,activeChat:i,workspace:c,_lastUpdate:n})}function sf(e,t,n){var a,o;const r={};t.status&&t.status!==e.status&&(r.status=t.status),t.cdpConnected!==void 0&&(r.cdpConnected=t.cdpConnected),t.childSessions!==void 0&&(r.childSessions=$d(e.childSessions,t.childSessions,{preserveMissing:n})),(a=t.chats)!=null&&a.length&&!((o=e.chats)!=null&&o.length)&&(r.chats=t.chats),t.workspace&&(r.workspace=t.workspace);for(const i of["title","providerSessionId","parentSessionId","sessionKind","sessionCapabilities","controlValues","providerControls","summaryMetadata","activeInteractivePrompt","lastMessagePreview","lastMessageRole","lastMessageAt","lastMessageHash","lastUpdated","unread","lastSeenAt","inboxBucket","completionMarker","seenCompletionMarker","surfaceHidden","muted","runtimeKey","runtimeDisplayName","runtimeWorkspaceLabel","runtimeWriteOwner","runtimeAttachedClients","version","serverVersion","versionUpdateReason","versionUpdateRequired","updateCommand","updatePolicy","updateChannel","releaseChannel"])tf(r,t,i);return t.machineNickname!==void 0&&t.machineNickname!==e.machineNickname&&(r.machineNickname=t.machineNickname),t.versionMismatch===!0&&(r.versionMismatch=!0),r}function nf(e,t,n,r){const a=sf(e,t,r),o=Object.keys(a).length>0?Hd(e,t,{...e,...a,_lastUpdate:n}):{...e,_lastUpdate:n};return zo(e,o,n)}function rf(e){const t=new Set(e.map(o=>o.id)),n=new Set,r=new Set,a=new Set;for(const o of e){const i=Fd(o);i&&n.add(i),i&&o.type!=="adhdev-daemon"&&r.add(i),i&&o.type==="adhdev-daemon"&&o._sessionListAuthoritative&&a.add(i)}return{incomingIds:t,incomingDaemonIds:n,daemonIdsWithSessionEntries:r,daemonIdsWithAuthoritativeSessionList:a}}function af(e,t,n,r,a,o){return!a.has(t)||!o.has(t)||r.has(e.id)?!1:e.transport==="pty"||e.transport==="acp"?n>1e4:e.transport==="cdp-page"?n>3e4:!1}function of(e,t,n,r,a){return e.transport?n.has(t)&&!r.has(t)?!0:a.has(t):!1}function lf(e,t,n){var d,m;const r=Date.now(),a=new Set((n==null?void 0:n.authoritativeDaemonIds)||[]);if(t.length===0)return e.map(f=>({...f,_lastUpdate:r}));const o=new Map;for(const f of t)o.set(f.id,f);const{incomingIds:i,incomingDaemonIds:c,daemonIdsWithSessionEntries:u,daemonIdsWithAuthoritativeSessionList:p}=rf(e);for(const f of e){const g=o.get(f.id);if(!g){o.set(f.id,{...f,_lastUpdate:r});continue}const w=Tl(f),h=Tl(g),x=Fd(f),k=!a.has(x);if(w>h){const j=Il(g,f,r,k);o.set(f.id,zo(g,j,r));continue}if(w<h){o.set(f.id,nf(g,f,r,k));continue}const b=f.timestamp||r,S=g._lastUpdate||g.timestamp||0;if(b>=S){const j=Il(g,f,r,k);o.set(f.id,zo(g,j,r));continue}(d=f.chats)!=null&&d.length&&!((m=g.chats)!=null&&m.length)&&o.set(f.id,{...g,chats:f.chats})}for(const[f,g]of o){const w=g.daemonId||f.split(":")[0];if(!c.has(w))continue;if(a.has(w)&&p.has(w)&&!i.has(f)){o.delete(f);continue}const h=r-(g._lastUpdate||g.timestamp||0);af(g,w,h,i,a,u)&&o.delete(f)}for(const[f,g]of o){const w=g.daemonId||f.split(":")[0];if(of(g,w,c,u,o))continue;r-(g._lastUpdate||g.timestamp||0)>3e5&&g.status!=="online"&&o.delete(f)}return Array.from(o.values())}function cf(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}const Bd=l.createContext({ides:[],updateRouteChats:()=>{},initialLoaded:!1,toasts:[],setToasts:()=>{},wsStatus:"connected",isConnected:!0,connectionStates:{},connectionTransports:{},showReconnected:!1,userName:void 0,setUserName:()=>{},isP2PActive:!1,p2pStates:{},userRole:void 0,connectionRetryStatuses:void 0}),Od=l.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function df({children:e,connectionOverrides:t}){const[n,r]=l.useState([]),[a,o]=l.useState(!1),[i,c]=l.useState([]),[u,p]=l.useState(void 0),d=l.useRef(n);l.useEffect(()=>{d.current=n},[n]);const m=l.useCallback((k,b)=>{r(S=>{let j=!1;const y=S.map(v=>v.id!==k||v.chats===b?v:(j=!0,{...v,chats:b}));return j?y:S})},[]),f=l.useCallback((k,b)=>{r(S=>{const j=S.length===0?k:lf(k,S,b),y=!cf(S,j);return y&&bn.record({kind:"dashboard.entries_applied",payload:{incoming:Nl(k),next:Nl(j)}}),y?j:S})},[]),g=l.useCallback(()=>o(!0),[]),w=l.useMemo(()=>({injectEntries:f,markLoaded:g,getIdes:()=>d.current}),[f,g]),h=t,x=l.useMemo(()=>({ides:n,updateRouteChats:m,initialLoaded:a,toasts:i,setToasts:c,wsStatus:(h==null?void 0:h.wsStatus)??"connected",isConnected:(h==null?void 0:h.isConnected)??!0,connectionStates:(h==null?void 0:h.connectionStates)??{},connectionTransports:(h==null?void 0:h.connectionTransports)??{},showReconnected:(h==null?void 0:h.showReconnected)??!1,retryConnection:h==null?void 0:h.retryConnection,retryServerConnection:h==null?void 0:h.retryServerConnection,connectionLoginUrl:h==null?void 0:h.connectionLoginUrl,isP2PActive:(h==null?void 0:h.isP2PActive)??!1,p2pStates:(h==null?void 0:h.p2pStates)??{},userRole:h==null?void 0:h.userRole,connectionRetryStatuses:h==null?void 0:h.connectionRetryStatuses,userName:u,setUserName:p}),[n,m,a,i,h==null?void 0:h.wsStatus,h==null?void 0:h.isConnected,h==null?void 0:h.connectionStates,h==null?void 0:h.connectionTransports,h==null?void 0:h.showReconnected,h==null?void 0:h.retryConnection,h==null?void 0:h.retryServerConnection,h==null?void 0:h.connectionLoginUrl,h==null?void 0:h.isP2PActive,h==null?void 0:h.p2pStates,h==null?void 0:h.userRole,h==null?void 0:h.connectionRetryStatuses,u]);return s.jsx(Od.Provider,{value:w,children:s.jsx(Bd.Provider,{value:x,children:e})})}function gs(){return l.useContext(Bd)}function ar(){return l.useContext(Od)}function Wd(e){const{baseUrl:t,getToken:n,onUnauthorized:r}=e;function a(c){return c.startsWith("http")?c:`${t}${c.startsWith("/")?"":"/"}${c}`}function o(c){const u=n==null?void 0:n(),p=a(c),d=c.startsWith("http")?new URL(p):new URL(p,typeof window<"u"?window.location.origin:"http://localhost");return u&&d.searchParams.set("token",u),!c.startsWith("http")&&!t?`${d.pathname}${d.search}${d.hash}`:d.toString()}async function i(c,u={}){const p={"Content-Type":"application/json",...u.headers||{}},d=n==null?void 0:n();d&&(p.Authorization=`Bearer ${d}`);const m=a(c),f=new AbortController,g=setTimeout(()=>f.abort(),15e3);try{const w=await fetch(m,{...u,headers:p,signal:f.signal});if(w.status===401)throw r==null||r(),new Error("Unauthorized");if(!w.ok){const h=await w.json().catch(()=>({error:w.statusText}));throw new Error(h.error||`API Error: ${w.status}`)}return w.json()}finally{clearTimeout(g)}}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:c=>i(`/api/v1/daemons/${c}/status`),sendCommand:(c,u,p={})=>i(`/api/v1/daemons/${c}/command`,{method:"POST",body:JSON.stringify({type:u,payload:p})}),execTerminal:(c,u,p)=>i(`/api/v1/daemons/${c}/terminal`,{method:"POST",body:JSON.stringify({command:u,name:p})}),sendAgentMessage:(c,u,p)=>i(`/api/v1/shortcuts/${c}/chat`,{method:"POST",body:JSON.stringify({agentType:u,message:p})}),getAgentStatus:c=>i(`/api/v1/shortcuts/${c}/status`),approveAgent:(c,u,p)=>i(`/api/v1/shortcuts/${c}/approve`,{method:"POST",body:JSON.stringify({agentType:u,action:p?"approve":"reject"})}),getMuxState:c=>i(`/api/v1/mux/${encodeURIComponent(c)}/state`),getMuxSocketInfo:c=>i(`/api/v1/mux/${encodeURIComponent(c)}/socket-info`),controlMux:(c,u,p={})=>i(`/api/v1/mux/${encodeURIComponent(c)}/control`,{method:"POST",body:JSON.stringify({type:u,payload:p})}),getMuxEventsUrl:c=>o(`/api/v1/mux/${encodeURIComponent(c)}/events`),getRuntimeEventsUrl:c=>o(`/api/v1/runtime/${encodeURIComponent(c)}/events`),request:i}}const uf=Wd({baseUrl:"http://localhost:3847"}),pf=l.createContext(uf);function mf({client:e,children:t}){return s.jsx(pf.Provider,{value:e,children:t})}const hf={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Ud=l.createContext(hf);function ff({value:e,children:t}){return s.jsx(Ud.Provider,{value:e,children:t})}function vt(){return l.useContext(Ud)}function Gd(e){return e&&typeof e=="object"&&e.result&&typeof e.result=="object"?e.result:e}function bf(e){const t=Gd(e);if(!t||t.error!=="untrusted_external_provider")return null;const n=t.provider&&typeof t.provider=="object"?t.provider:null;return{providerType:typeof(n==null?void 0:n.type)=="string"?n.type:null,sourceName:typeof(n==null?void 0:n.sourceName)=="string"?n.sourceName:null,description:typeof t.hint=="string"?t.hint:void 0}}function gf(e){const[t,n]=l.useState(null),r=l.useCallback(async(i,c)=>{const u=m=>e(i,"launch_cli",{...c,...m}),p=await u({}),d=bf(p);return d?new Promise(m=>{n({providerType:d.providerType||String(c.cliType??"?"),sourceName:d.sourceName,description:d.description,retry:()=>u({confirmExternalUntrusted:!0}),resolve:f=>{f.cancelled?m({success:!1,error:"user_cancelled_untrusted_launch"}):m(f.response)}})}):p},[e]),a=l.useCallback(async()=>{const i=t;if(i){n(null);try{const c=await i.retry(),u=Gd(c);u!=null&&u.success?i.resolve({ok:!0,response:c}):i.resolve({ok:!1,error:(u==null?void 0:u.error)||"launch failed after confirm",response:c})}catch(c){i.resolve({ok:!1,error:(c==null?void 0:c.message)||String(c)})}}},[t]),o=l.useCallback(()=>{const i=t;i&&(n(null),i.resolve({ok:!1,cancelled:!0}))},[t]);return{launchCli:r,pending:t,confirm:a,cancel:o}}function xf({providerType:e,sourceName:t,description:n,onConfirm:r,onCancel:a}){const{t:o}=Ne("common"),i=l.useRef(null);return l.useEffect(()=>{var c;(c=i.current)==null||c.focus()},[]),l.useEffect(()=>{const c=u=>{u.key==="Escape"&&a()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[a]),s.jsx("div",{role:"dialog","aria-modal":"true","aria-label":o("machine.confirmExternal.dialogAria"),className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:a,style:{pointerEvents:"auto"},children:s.jsxs("div",{className:"bg-[var(--surface-primary)] text-text-primary border border-amber-500/40 rounded-lg shadow-xl max-w-lg w-full",onClick:c=>c.stopPropagation(),children:[s.jsxs("div",{className:"px-4 py-3 border-b border-border-subtle flex items-center gap-2",children:[s.jsx("span",{"aria-hidden":!0,className:"text-amber-400 text-base",children:"⚠"}),s.jsx("h2",{className:"text-sm font-semibold",children:o("machine.confirmExternal.title")})]}),s.jsxs("div",{className:"px-4 py-3 text-[12px] flex flex-col gap-3",children:[s.jsxs("p",{children:["You're about to activate ",s.jsx("span",{className:"font-mono",children:e}),t?s.jsxs(s.Fragment,{children:[" from ",s.jsx("span",{className:"font-mono",children:t})]}):null,"."]}),s.jsx("p",{className:"text-text-secondary",children:n??o("machine.confirmExternal.description")}),s.jsx("p",{className:"text-text-secondary",children:o("machine.confirmExternal.proceedWarning")})]}),s.jsxs("div",{className:"px-4 py-2 border-t border-border-subtle flex justify-end gap-2",children:[s.jsx("button",{ref:i,type:"button",onClick:a,className:"px-3 py-1 text-sm rounded border border-border-default hover:bg-surface-secondary",children:o("machine.confirmExternal.cancel")}),s.jsx("button",{type:"button",onClick:r,className:"px-3 py-1 text-sm rounded bg-amber-500 text-black font-semibold hover:opacity-90",children:o("machine.confirmExternal.activate")})]})]})})}const qd=l.createContext(null);function vf({sendDaemonCommand:e,children:t}){const n=gf(e),r=l.useMemo(()=>({launchCli:n.launchCli}),[n.launchCli]);return s.jsxs(qd.Provider,{value:r,children:[t,n.pending&&s.jsx(xf,{providerType:n.pending.providerType,sourceName:n.pending.sourceName,description:n.pending.description,onConfirm:n.confirm,onCancel:n.cancel})]})}function ka(){const e=l.useContext(qd);return e||{launchCli:async()=>{throw new Error("useLaunchCli must be used inside <LaunchCliProvider>")}}}function zd(e){return e?new Date(e).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function yf(e,t,n){return Number(e.receivedAt||n[sa(e)]||0)||0}function Kd(e){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(e)}function wf(e){return Array.isArray(e)&&e.some(t=>!!t&&typeof t=="object"&&"type"in t)}function Dn(e,t){if(!e)return t;try{return(e.startsWith("file://")?new URL(e).pathname:e).split(/[\\/]/).filter(Boolean).pop()||t}catch{return e.split(/[\\/]/).filter(Boolean).pop()||t}}function Ga(e){if(typeof e.uri=="string"&&e.uri)return e.uri;if(typeof e.data=="string"&&e.data&&typeof e.mimeType=="string"&&e.mimeType)return`data:${e.mimeType};base64,${e.data}`}function kf(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n),t|=0;return(t>>>0).toString(36)}function sa(e,t){const n=e,r=ji(e.content,{joiner:`
5
5
  `}),a=[e.id?`id:${e.id}`:"",n._localId?`local:${n._localId}`:"",n._turnKey?`turn:${n._turnKey}`:"",e.bubbleId?`bubble:${e.bubbleId}`:"",e.providerUnitKey?`unit:${e.providerUnitKey}`:"",typeof e.index=="number"?`msgIndex:${e.index}`:"",typeof e.sequence=="number"?`seq:${e.sequence}`:""].filter(Boolean);if(a.length>0)return a.join("|");const o=e.receivedAt||e.timestamp||0;return[e.role?`role:${e.role}`:"role:",`chash:${kf(r)}`,o?`ts:${o}`:""].filter(Boolean).join("|")}function Sf(e){let t=2166136261;for(const n of e){const r=String(n||"");for(let a=0;a<r.length;a+=1)t^=r.charCodeAt(a),t=Math.imul(t,16777619)>>>0;t^=255,t=Math.imul(t,16777619)>>>0}return t.toString(16).padStart(8,"0")}function Cf(e){try{return JSON.stringify(e??"")}catch{return String(e??"")}}function Vd(e){return e?Sf([String(e.id||""),String(e.index??""),String(e.role||""),String(e.receivedAt??e.timestamp??""),Cf(e.content)]):""}const Ni=200,jf=80,Pl=650,Ln=new Map;function na(e,t){if(!e)return!1;const n=String(e.messageFingerprint||"");return n?n===String(t||""):!0}function Nf(e,t){if(!Array.isArray(e)||e.length===0)return"0:empty";const n=String(t||"").trim();if(n)return`${e.length}:${n}`;const r=e[e.length-1];return`${e.length}:${Vd(r)}`}function Af(e,t,n,r){return e||!t?!1:na(n,r)}function Mf({scrollTop:e,scrollHeight:t,clientHeight:n,topThresholdPx:r=jf,bottomThresholdPx:a=Ni}){const o=Math.max(0,Number(e)||0),i=Math.max(0,Number(t)||0),c=Math.max(0,Number(n)||0);return Math.max(0,i-c)<=0?{showTop:!1,showBottom:!1}:{showTop:o>r,showBottom:Math.max(0,i-o-c)>a}}function Tf(e){return Mf({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight})}function Kn(e,t=Ni){return!!e&&e.fromBottom>=t}function If(e,t){return na(e,t)?!Kn(e):!0}function Pf({hasSelection:e,userScrolledUp:t,hasChatContentChanged:n=!0}){return!(e||t||!n)}function Df({hasSelection:e,userScrolledUp:t,contextAutoScrollActive:n}){return e?!1:n||!t}function qa(e,t){const n=Math.max(0,e.scrollHeight-e.clientHeight-t.fromBottom);e.scrollTop=Number.isFinite(n)?n:t.top}const Je={size:18};function Yd({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),s.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),s.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),s.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]})}function Ai({size:e=Je.size,className:t}){return s.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:s.jsx("polyline",{points:"15 18 9 12 15 6"})})}function Ts({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2"}),s.jsx("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2"}),s.jsx("circle",{cx:"6",cy:"6",r:"1",fill:"currentColor",stroke:"none"}),s.jsx("circle",{cx:"6",cy:"18",r:"1",fill:"currentColor",stroke:"none"}),s.jsx("line",{x1:"10",y1:"6",x2:"18",y2:"6"}),s.jsx("line",{x1:"10",y1:"18",x2:"18",y2:"18"})]})}function Jd({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),s.jsx("circle",{cx:"9",cy:"7",r:"4"}),s.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),s.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function Lf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),s.jsx("circle",{cx:"12",cy:"7",r:"4"})]})}function Rf({size:e=Je.size,className:t}){return s.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:s.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})})}function Qd({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20"}),s.jsx("path",{d:"M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"}),s.jsx("line",{x1:"9",y1:"7",x2:"16",y2:"7"}),s.jsx("line",{x1:"9",y1:"11",x2:"14",y2:"11"})]})}function Xd({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"}),s.jsx("rect",{x:"8",y:"2",width:"8",height:"4",rx:"1"}),s.jsx("line",{x1:"8",y1:"10",x2:"16",y2:"10"}),s.jsx("line",{x1:"8",y1:"14",x2:"14",y2:"14"}),s.jsx("line",{x1:"8",y1:"18",x2:"12",y2:"18"})]})}function Zd({size:e=Je.size,className:t}){return s.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:s.jsx("polyline",{points:"20 6 9 17 4 12"})})}function Sa({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("circle",{cx:"12",cy:"12",r:"3"}),s.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function Mi({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("circle",{cx:"12",cy:"12",r:"10"}),s.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),s.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function Ef({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("circle",{cx:"12",cy:"12",r:"10"}),s.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),s.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function _f({size:e=Je.size,className:t}){return s.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:s.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})})}function Zs({size:e=Je.size,className:t}){return s.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:s.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function us({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),s.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),s.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Ti({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),s.jsx("polyline",{points:"14 2 14 8 20 8"}),s.jsx("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),s.jsx("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]})}function xn({size:e=Je.size,className:t}){return s.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:s.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function Ca({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("polyline",{points:"23 4 23 10 17 10"}),s.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}function Ys({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),s.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),s.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function or({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M12 22v-5"}),s.jsx("path",{d:"M9 8V2"}),s.jsx("path",{d:"M15 8V2"}),s.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}function es({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("circle",{cx:"12",cy:"5",r:"2"}),s.jsx("circle",{cx:"5",cy:"19",r:"2"}),s.jsx("circle",{cx:"19",cy:"19",r:"2"}),s.jsx("line",{x1:"12",y1:"7",x2:"5",y2:"17"}),s.jsx("line",{x1:"12",y1:"7",x2:"19",y2:"17"}),s.jsx("line",{x1:"5",y1:"19",x2:"19",y2:"19"})]})}function $f({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("polygon",{points:"12 2 2 7 12 12 22 7 12 2"}),s.jsx("polyline",{points:"2 12 12 17 22 12"}),s.jsx("polyline",{points:"2 17 12 22 22 17"})]})}function eu({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),s.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function Ii({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C5 20 1 12 1 12a21.8 21.8 0 0 1 5.06-5.94"}),s.jsx("path",{d:"M9.9 4.24A10.93 10.93 0 0 1 12 4c7 0 11 8 11 8a21.77 21.77 0 0 1-2.16 3.19"}),s.jsx("path",{d:"M14.12 14.12a3 3 0 1 1-4.24-4.24"}),s.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})}function tu({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("circle",{cx:"12",cy:"12",r:"10"}),s.jsx("polyline",{points:"12 6 12 12 16 14"})]})}function Hf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"10"}),s.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),s.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"14"})]})}function Pi({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("polyline",{points:"4 17 10 11 4 5"}),s.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function Ff({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"})]})}function su({size:e=Je.size,className:t}){return s.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:s.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})})}function Di({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),s.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function At({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),s.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Bf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"}),s.jsx("path",{d:"M12 15l-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"}),s.jsx("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),s.jsx("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}function Of({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("rect",{x:"3",y:"8",width:"18",height:"12",rx:"2"}),s.jsx("path",{d:"M12 2v6"}),s.jsx("circle",{cx:"8.5",cy:"14",r:"1.5",fill:"currentColor",stroke:"none"}),s.jsx("circle",{cx:"15.5",cy:"14",r:"1.5",fill:"currentColor",stroke:"none"})]})}function Wf({size:e=Je.size,className:t}){return s.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:s.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})})}function Uf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("rect",{x:"9",y:"10",width:"6",height:"12",rx:"1"}),s.jsx("path",{d:"M12 2c-1.5 2-3 3.5-3 5a3 3 0 0 0 6 0c0-1.5-1.5-3-3-5z"})]})}function Nn({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),s.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})}function nu({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M8.7 3A6 6 0 0 1 18 8c0 3 .6 5 1.4 6.5"}),s.jsx("path",{d:"M17 17H3s3-2 3-9a5.98 5.98 0 0 1 .6-2.6"}),s.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"}),s.jsx("line",{x1:"2",y1:"2",x2:"22",y2:"22"})]})}function Gf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("circle",{cx:"12",cy:"12",r:"5"}),s.jsx("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),s.jsx("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),s.jsx("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),s.jsx("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),s.jsx("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),s.jsx("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),s.jsx("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),s.jsx("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]})}function qf({size:e=Je.size,className:t}){return s.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:s.jsx("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}function zf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),s.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),s.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function ru({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),s.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]})}function Kf({size:e=Je.size,className:t}){return s.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:s.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})})}function Vf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),s.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"})]})}function Yf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("path",{d:"M14.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),s.jsx("path",{d:"M9.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),s.jsx("path",{d:"M19.35 6.07A16.03 16.03 0 0 0 15 4a.84.84 0 0 0-.46.33 11 11 0 0 0-.74 1.5 15.68 15.68 0 0 0-3.6 0 11.23 11.23 0 0 0-.74-1.5A.84.84 0 0 0 9 4a16.03 16.03 0 0 0-4.35 2.07A16.8 16.8 0 0 0 2 15a16.22 16.22 0 0 0 4 3c.12.08.27.06.37-.04a11.14 11.14 0 0 0 1.2-1.92.35.35 0 0 0-.18-.46 10.4 10.4 0 0 1-1.63-.78.36.36 0 0 1 .03-.6 6.8 6.8 0 0 0 .32-.24.36.36 0 0 1 .37-.04c2.2.98 4.6.98 6.8 0a.36.36 0 0 1 .37.04c.1.08.21.16.32.24a.36.36 0 0 1 .03.6 10.4 10.4 0 0 1-1.63.78.35.35 0 0 0-.18.46c.39.67.8 1.3 1.2 1.92a.37.37 0 0 0 .37.04 16.22 16.22 0 0 0 4-3 16.8 16.8 0 0 0-2.65-8.93z"})]})}function Jf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("rect",{x:"2",y:"7",width:"15",height:"14",rx:"2"}),s.jsx("path",{d:"M13 2h9v9"}),s.jsx("path",{d:"M22 2L13 11"})]})}function Qf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("polyline",{points:"9 14 4 9 9 4"}),s.jsx("path",{d:"M20 20v-7a4 4 0 0 0-4-4H4"})]})}function Xf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),s.jsx("line",{x1:"6",y1:"8",x2:"6.01",y2:"8"}),s.jsx("line",{x1:"10",y1:"8",x2:"10.01",y2:"8"}),s.jsx("line",{x1:"14",y1:"8",x2:"14.01",y2:"8"}),s.jsx("line",{x1:"18",y1:"8",x2:"18.01",y2:"8"}),s.jsx("line",{x1:"6",y1:"12",x2:"6.01",y2:"12"}),s.jsx("line",{x1:"10",y1:"12",x2:"10.01",y2:"12"}),s.jsx("line",{x1:"14",y1:"12",x2:"14.01",y2:"12"}),s.jsx("line",{x1:"18",y1:"12",x2:"18.01",y2:"12"}),s.jsx("line",{x1:"7",y1:"16",x2:"17",y2:"16"})]})}function Zf({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("rect",{x:"2",y:"6",width:"13",height:"13",rx:"2"}),s.jsx("path",{d:"M9 6V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-2"})]})}function eb({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),s.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"}),s.jsx("line",{x1:"3",y1:"12",x2:"12",y2:"12"})]})}function tb({size:e=Je.size,className:t}){return s.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[s.jsx("circle",{cx:"12",cy:"12",r:"10"}),s.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),s.jsx("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]})}const au="adhdev_chat_activity_visible",Dl=new Set(["hidden","debug","internal"]),Ll=new Set(["visible","user","chat"]),sb=new Set(["debug","trace","internal"]),nb=new Set(["tool_call","terminal_command","runtime_activity"]),rb=new Set(["runtime_status","provider_chrome","control"]),ab=new Set(["thought","tool","terminal"]);function ou(e){const t=e.meta;return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function rn(e){return typeof e=="string"?e.trim().toLowerCase():""}function za(e,t,n){return e[n]??(t==null?void 0:t[n])}function Rl(e,t,n){const r=e;return n.some(a=>r[a]===!0||(t==null?void 0:t[a])===!0)}function ob(e,t){const n=rn(e.kind);return n||(t==="tool"?"tool":"standard")}function Ka(e,t,n){const r=ou(e),a=typeof(r==null?void 0:r.label)=="string"?r.label.trim():"";return a||(t==="terminal"||n==="terminal_command"?"Terminal":t==="tool"||n==="tool_call"?"Tool":t==="thought"?"Thought":n==="runtime_activity"?"Runtime":"Activity")}function ib(e){const t=e.content;return Array.isArray(t)&&t.some(n=>!!n&&typeof n=="object"&&n.type!=="text")}function Li(e){if(!e)return{surface:"internal",isUserFacing:!1,isActivityFacing:!1,isInternal:!0,role:"",kind:"standard",label:"Internal"};const t=ou(e),n=rn(e.role),r=ob(e,n),a=rn(za(e,t,"visibility")),o=rn(e.transcriptVisibility??(t==null?void 0:t.transcriptVisibility)??a),i=rn(za(e,t,"audience")),c=rn(za(e,t,"source")),u=Dl.has(a)||Dl.has(o)||sb.has(i)||Rl(e,t,["internal","isInternal","debug","statusOnly","controlOnly"]),p=Ll.has(a)||Ll.has(o)||i==="chat"||Rl(e,t,["userFacing"]),d=ab.has(r)||nb.has(c);if(u)return{surface:d?"activity":"internal",isUserFacing:!1,isActivityFacing:d,isInternal:!d,role:n,kind:r,label:Ka(e,r,c)};if(p)return{surface:"chat",isUserFacing:!0,isActivityFacing:!1,isInternal:!1,role:n,kind:r,label:Ka(e,r,c)};if((n==="system"||r==="system")&&ib(e))return{surface:"chat",isUserFacing:!0,isActivityFacing:!1,isInternal:!1,role:n,kind:r,label:"Chat"};if(rb.has(c)||n==="system"||r==="system")return{surface:"internal",isUserFacing:!1,isActivityFacing:!1,isInternal:!0,role:n,kind:r,label:"Internal"};if(d)return{surface:"activity",isUserFacing:!1,isActivityFacing:!0,isInternal:!1,role:n,kind:r,label:Ka(e,r,c)};const m=(n==="user"||n==="human"||n==="assistant")&&(r==="standard"||r==="");return{surface:m?"chat":"internal",isUserFacing:m,isActivityFacing:!1,isInternal:!m,role:n,kind:r,label:m?"Chat":"Internal"}}function lb(e){return(Array.isArray(e)?e:[]).filter(t=>Li(t).isUserFacing)}function iu(e){return(Array.isArray(e)?e:[]).filter(t=>Li(t).isActivityFacing)}function lu(e){const t=e.content;return typeof t=="string"?t:(()=>{try{return JSON.stringify(t??"")}catch{return String(t??"")}})()}function cb(e){return`${String(e.role||"")}::${lu(e)}`}function db(e){if(e.length<2)return e;const t=[];let n="";for(const r of e){const a=cb(r);lu(r).trim().length>0&&a===n||(t.push(r),n=a)}return t}function ub(e,t,n){return!n||t.length===0?e:[...e,...t].sort((r,a)=>{const o=Number(r.receivedAt??r.timestamp??0)||0,i=Number(a.receivedAt??a.timestamp??0)||0;if(o!==i)return o-i;const c=Number(r.index??0)||0,u=Number(a.index??0)||0;return c-u})}function El(e=typeof localStorage<"u"?localStorage:void 0){try{return(e==null?void 0:e.getItem(au))==="1"}catch{return!1}}function pb({text:e}){const{t}=Ne("common"),[n,r]=l.useState(!1),a=l.useCallback(()=>{navigator.clipboard.writeText(e).catch(()=>{}),r(!0),setTimeout(()=>r(!1),1500)},[e]);return s.jsx("button",{type:"button",onClick:a,"aria-label":t("chat.copyMessage"),className:"chat-copy-btn",children:n?s.jsx(Zd,{size:11}):s.jsx(Xd,{size:11})})}const cu=[Ch,{singleTilde:!1}],du=[cu,jh,Nh],mb=[cu];function wr(e,t,n){return s.jsxs("div",{className:"rounded-md border border-border-subtle p-2 text-sm",role:"note",children:[s.jsx("span",{className:"font-medium",children:e}),t?s.jsx("span",{className:"ml-1 break-all",children:t}):null,n?s.jsx("div",{className:"mt-1 opacity-80",style:{whiteSpace:"pre-wrap"},children:n}):null]})}function _l(e,t){return e?t?s.jsx("pre",{className:"chat-preformatted",children:e}):Kd(e)?s.jsx(Si,{remarkPlugins:du,children:e}):s.jsx("div",{style:{whiteSpace:"pre-wrap"},children:e}):null}const hb=l.memo(function({content:t,renderAsPreformatted:n,renderAsMarkdown:r}){return n?s.jsx("pre",{className:"chat-preformatted",children:t}):r?s.jsx(Si,{remarkPlugins:du,children:t}):s.jsx("div",{style:{whiteSpace:"pre-wrap"},children:t})});function Rn({parts:e,renderAsPreformatted:t}){return s.jsx("div",{className:"flex flex-col gap-2",children:e.map((n,r)=>{if(n.type==="text")return s.jsx("div",{children:_l(String(n.text||""),t)},`text-${r}`);if(n.type==="image"){const a=Ga(n),o=n.alt||n.description||Dn(n.uri,"image");return a?s.jsx("img",{src:a,alt:o,className:"max-w-full rounded-md border border-border-subtle"},`image-${r}`):s.jsx("div",{children:wr("Image",o,n.mimeType)},`image-fallback-${r}`)}if(n.type==="audio"){const a=Ga(n);return a?s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("audio",{controls:!0,src:a,className:"max-w-full"}),n.transcript?s.jsx("div",{className:"text-sm opacity-80",style:{whiteSpace:"pre-wrap"},children:n.transcript}):null]},`audio-${r}`):s.jsx("div",{children:wr("Audio",Dn(n.uri,"audio"),n.transcript||n.mimeType)},`audio-fallback-${r}`)}if(n.type==="video"){const a=Ga(n),o=n.title||n.name||n.alt||Dn(n.uri,"video"),i=[n.transcript,n.description,n.mimeType].filter(Boolean).join(`
6
6
  `);return s.jsxs("div",{className:"flex flex-col gap-1",children:[a?s.jsx("video",{controls:!0,src:a,poster:n.posterUri,className:"max-w-full rounded-md border border-border-subtle"}):wr("Video",o,i),a&&i?s.jsx("div",{className:"text-sm opacity-80",style:{whiteSpace:"pre-wrap"},children:i}):null]},`video-${r}`)}if(n.type==="resource_link"){const a=n.title||n.name||Dn(n.uri,"resource"),o=[n.description,n.mimeType].filter(Boolean).join(`
7
7
  `);return s.jsxs("div",{className:"flex flex-col gap-1",children:[n.uri?s.jsx("a",{href:n.uri,target:"_blank",rel:"noreferrer",download:!0,className:"underline break-all",children:a}):wr("Resource",a,o),n.uri&&o?s.jsx("div",{className:"text-sm opacity-80",style:{whiteSpace:"pre-wrap"},children:o}):null]},`resource-link-${r}`)}if(n.type==="resource"&&n.resource){const a=Dn(n.resource.uri,"resource");if(n.resource.text)return s.jsxs("div",{className:"rounded-md border border-border-subtle p-2",children:[s.jsx("div",{className:"text-[11px] opacity-70 mb-1",children:a}),_l(n.resource.text,!0)]},`resource-${r}`);if(n.resource.uri)return s.jsx("a",{href:n.resource.uri,target:"_blank",rel:"noreferrer",className:"underline break-all",children:a},`resource-uri-${r}`)}return null})})}const fb=l.memo(function({log:t}){return s.jsxs("div",{className:"self-center chat-msg-action",children:[s.jsx(Si,{remarkPlugins:mb,children:t.text}),s.jsx("span",{className:"action-time",children:zd(t.timestamp)})]})},(e,t)=>e.log===t.log);function $l(e){const t=e.meta;return[Vd(e),e.kind||"",e.senderName||"",e.bubbleId||"",e.bubbleState||"",e.visibility||"",e.transcriptVisibility||"",e.audience||"",e.source||"",e.userFacing===void 0?"":String(e.userFacing),e.internal===void 0?"":String(e.internal),e.isInternal===void 0?"":String(e.isInternal),e.debug===void 0?"":String(e.debug),t?String(t.label??""):"",t?String(t.isRunning??""):"",t?String(t.renderMode??""):""].join("")}const bb=l.memo(function({message:t,receivedAt:n,agentName:r,userName:a,isCliMode:o,isTextExpanded:i,onToggleTextExpanded:c}){var C,A,M;const u=(t.role||"").toLowerCase(),p=u==="user"||u==="human",d=t.kind||(u==="tool"?"tool":"standard"),m=Li(t),f=wf(t.content)?t.content:null,g=!!(f!=null&&f.some(T=>T.type!=="text")),w=ji(t.content,{joiner:`
8
- `});if(m.isActivityFacing&&d!=="thought"&&d!=="tool"&&d!=="terminal"){const T=m.label||"Activity";return s.jsxs("div",{className:"self-start chat-msg-activity","data-chat-activity-row":"true",children:[s.jsxs("div",{className:"chat-msg-activity-meta","aria-label":"Activity message",children:[s.jsx("span",{className:"activity-dot"}),s.jsx("span",{children:T})]}),g&&f?s.jsx("div",{className:"chat-msg-activity-body",children:s.jsx(Rn,{parts:f,renderAsPreformatted:!1})}):s.jsx("div",{className:"chat-msg-activity-body",style:{whiteSpace:"pre-wrap"},children:w})]})}if(d==="thought"){const T=typeof((C=t.meta)==null?void 0:C.label)=="string"?t.meta.label:"Thought";return s.jsxs("div",{className:"self-start chat-msg-thought","data-chat-activity-row":m.isActivityFacing?"true":void 0,children:[s.jsxs("div",{className:"chat-msg-header",children:[s.jsx(Wf,{size:13}),s.jsx("span",{children:T})]}),s.jsx("div",{className:"chat-msg-body",children:w})]})}if(d==="tool")return s.jsxs("div",{className:"self-start chat-msg-tool","data-chat-activity-row":m.isActivityFacing?"true":void 0,children:[s.jsxs("div",{className:"chat-msg-tool-meta","aria-label":"Tool message",children:[s.jsx("span",{className:"tool-icon",children:"⏺"}),s.jsx("span",{className:"tool-label",children:"Tool"})]}),g&&f?s.jsx("div",{className:"tool-text w-full",children:s.jsx(Rn,{parts:f,renderAsPreformatted:!1})}):s.jsx("div",{className:"tool-text w-full",style:{whiteSpace:"pre-wrap"},children:w})]});if(d==="terminal"){const T=(A=t.meta)!=null&&A.isRunning?"⏳":"✅",R=typeof((M=t.meta)==null?void 0:M.label)=="string"?t.meta.label:"Ran command";return s.jsxs("div",{className:"self-start chat-msg-terminal","data-chat-activity-row":m.isActivityFacing?"true":void 0,children:[s.jsxs("div",{className:"chat-msg-header",children:[s.jsx("span",{children:T}),s.jsx("span",{children:R})]}),g&&f?s.jsx("div",{className:"chat-msg-body",children:s.jsx(Rn,{parts:f,renderAsPreformatted:!0})}):s.jsx("pre",{className:"chat-msg-body",children:w})]})}if(d==="system")return s.jsx("div",{className:"self-center chat-msg-system",children:g&&f?s.jsx(Rn,{parts:f,renderAsPreformatted:!1}):w.slice(0,100)});const h=t.meta,k=(typeof(h==null?void 0:h.renderMode)=="string"?h.renderMode.trim():"")==="preformatted",b=w,S=!1,j=b,y=k,v=!p&&!y&&Kd(j),N=["chat-message-row",p?"chat-message-row-user self-end":"chat-message-row-assistant self-start"].join(" ");return s.jsx("div",{className:N,children:(b||g||p)&&s.jsxs("div",{className:`chat-bubble ${p?"chat-bubble-user":"chat-bubble-assistant"}`,children:[s.jsxs("div",{className:`chat-bubble-header ${b||g?"mb-1.5":"mb-0"}`,children:[s.jsx("span",{className:"chat-sender",children:p?a||"You":t.senderName||r}),s.jsxs("span",{className:"chat-bubble-header-end",children:[(b||g)&&s.jsx(pb,{text:w}),n!=null&&s.jsx("span",{className:"chat-time",children:zd(n)})]})]}),(b||g)&&s.jsx("div",{className:"chat-markdown",children:g&&f?s.jsx(Rn,{parts:f,renderAsPreformatted:y}):s.jsx(hb,{content:j,renderAsPreformatted:y,renderAsMarkdown:v})}),S]})})},(e,t)=>(e.message===t.message||$l(e.message)===$l(t.message))&&e.receivedAt===t.receivedAt&&e.agentName===t.agentName&&e.userName===t.userName&&e.isCliMode===t.isCliMode&&e.isTextExpanded===t.isTextExpanded),gb=l.forwardRef(function({messages:t,actionLogs:n,agentName:r="Agent",userName:a,isCliMode:o=!1,isWorking:i=!1,contextKey:c="",receivedAtMap:u={},lastMessageHash:p,showActivityMessages:d=!1,emptyState:m,onLoadMore:f,isLoadingMore:g,hasMoreHistory:w,hiddenLiveCount:h=0,loadError:x,scrollToBottomRequestNonce:k,isVisible:b=!0},S){const{t:j}=Ne("common"),y=l.useRef(null),v=l.useRef(null),N=l.useRef(null),C=l.useRef(0),A=l.useRef(""),M=l.useRef(""),T=l.useRef(!1),R=l.useRef(null),E=l.useRef(!1),_=l.useRef(null),z=l.useRef(!1),[F,D]=l.useState(new Set),[O,L]=l.useState({showTop:!1,showBottom:!1}),I=l.useRef(!1),$=l.useRef(!1),P=l.useRef(b),U=l.useRef(b),J=l.useRef(null);U.current=b;const re=()=>{const ce=y.current;return ce?ce.scrollHeight-ce.scrollTop-ce.clientHeight<Ni:!0},Y=l.useCallback(()=>{const ce=y.current,H=ce?Tf(ce):{showTop:!1,showBottom:!1};L(pe=>pe.showTop===H.showTop&&pe.showBottom===H.showBottom?pe:H)},[]),X=l.useCallback((ce="auto")=>{var pe;const H=y.current;H&&(H.scrollTo({top:H.scrollHeight,behavior:ce}),(pe=H.ownerDocument.defaultView)==null||pe.requestAnimationFrame(()=>Y()))},[Y]),de=l.useCallback((ce="auto")=>{var pe;const H=y.current;H&&(H.scrollTo({top:0,behavior:ce}),(pe=H.ownerDocument.defaultView)==null||pe.requestAnimationFrame(()=>Y()))},[Y]),ne=l.useCallback(()=>{var W;const ce=y.current,H=(W=window.getSelection)==null?void 0:W.call(window);if(!ce||!H||H.rangeCount===0||H.isCollapsed){z.current=!1;return}const pe=H.anchorNode,le=H.focusNode;z.current=!!(pe&&le&&ce.contains(pe)&&ce.contains(le))},[]),B=l.useMemo(()=>{const ce=lb(t),H=iu(t);return db(ub(ce,H,d))},[t,d]),ie=B.length===t.length?p:void 0,K=Nf(B,ie),ae=l.useCallback(()=>{const ce=y.current;if(!ce||!c||!U.current)return;const H={top:ce.scrollTop,fromBottom:Math.max(0,ce.scrollHeight-ce.scrollTop-ce.clientHeight),messageFingerprint:K};J.current={contextKey:c,snapshot:H},Ln.set(c,H)},[c,K]),Ce=l.useCallback((ce="auto")=>{R.current!=null&&cancelAnimationFrame(R.current),R.current=requestAnimationFrame(()=>{R.current=null,X(ce)})},[X]),ye=l.useCallback(()=>{I.current=!1,E.current=!0,$.current=!0,_.current!=null&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>{E.current=!1,_.current=null},Pl)},[]);l.useEffect(()=>{const ce=!T.current,H=M.current!==c;if(M.current=c,ce||H){T.current=!0;const le=c?Ln.get(c):null,W=!!le&&na(le,K);I.current=W?Kn(le):!1,E.current=If(le,K),z.current||(W?requestAnimationFrame(()=>{const be=y.current;be&&(qa(be,le),I.current=Kn(le),Y(),$.current=!0)}):Ce("auto")),C.current=B.length,A.current=K;return}B.length>C.current;const pe=K!==A.current;Pf({hasSelection:z.current,userScrolledUp:I.current,hasChatContentChanged:pe})&&Ce("auto"),C.current=B.length,A.current=K},[K,c,B.length,Ce,Y]),l.useEffect(()=>{k&&(ye(),z.current||Ce("auto"))},[ye,Ce,k]),l.useEffect(()=>{const ce=P.current;ce&&!b&&ae(),U.current=b,P.current=b;const H=c?Ln.get(c):null;if(Af(ce,b,H,K)){if(!H)return;I.current=Kn(H),E.current=!1,z.current||requestAnimationFrame(()=>{const pe=y.current;pe&&(qa(pe,H),Y())});return}},[b,c,K,ye,ae,Ce,Y]),l.useEffect(()=>()=>{const ce=J.current;ce&&Ln.set(ce.contextKey,ce.snapshot),R.current!=null&&cancelAnimationFrame(R.current),_.current!=null&&window.clearTimeout(_.current)},[]),l.useEffect(()=>{const ce=v.current,H=y.current;if(!ce||!H)return;const pe=()=>{_.current!=null&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>{E.current=!1,_.current=null},Pl)},le=new ResizeObserver(()=>{Y();const W=E.current;Df({hasSelection:z.current,userScrolledUp:I.current,contextAutoScrollActive:W})&&(Ce("auto"),W&&pe())});return le.observe(ce),H!==ce&&le.observe(H),()=>{le.disconnect(),_.current!=null&&(window.clearTimeout(_.current),_.current=null)}},[Ce,c,Y]),l.useImperativeHandle(S,()=>({scrollToBottom:(ce="smooth")=>{X(ce)}}),[X]),l.useEffect(()=>{const ce=y.current;if(!ce)return;let H;const pe=()=>{ae(),clearTimeout(H),H=setTimeout(()=>{I.current=!re(),Y()},50)};return ce.addEventListener("scroll",pe,{passive:!0}),()=>{ce.removeEventListener("scroll",pe),clearTimeout(H)}},[ae,Y]),l.useEffect(()=>(document.addEventListener("selectionchange",ne),()=>document.removeEventListener("selectionchange",ne)),[ne]);const ke=l.useRef(0),me=l.useRef(!1);l.useEffect(()=>{const ce=y.current;if(!ce||!me.current||ke.current===0)return;const H=ce.scrollHeight-ke.current;H>0&&(ce.scrollTop=H),Y(),ae(),ke.current=0,me.current=!1},[B.length,ae,Y]),l.useEffect(()=>{if($.current||!c)return;const ce=Ln.get(c),H=y.current;if(!(!ce||!H)){if(!na(ce,K)){X("auto"),$.current=!0;return}qa(H,ce),I.current=Kn(ce),Y(),$.current=!0}},[c,K,B.length,X,Y]);const q=()=>{const ce=y.current;ce&&(ke.current=ce.scrollHeight),me.current=!0,f==null||f()},G=()=>{I.current=!0,de("smooth"),ae()},Z=()=>{ye(),X("smooth"),ae()},V=l.useMemo(()=>{const ce=B.map((W,be)=>({type:"message",data:W,index:be,ts:yf(W,be,u)}));if(!n||n.length===0)return ce;const H=[...n].sort((W,be)=>W.timestamp-be.timestamp).map((W,be)=>({type:"action",data:W,index:be,ts:W.timestamp})),pe=[];let le=0;for(const W of ce){for(;le<H.length&&W.ts>0&&H[le].ts<W.ts;)pe.push(H[le++]);pe.push(W)}for(;le<H.length;)pe.push(H[le++]);return pe},[B,n,u]),fe=h>0||!!w,Te=h>0?h>80?j("chatList.showEarlierMessagesHidden",{count:Math.min(h,80),total:h}):j("chatList.showEarlierMessages",{count:Math.min(h,80)}):x?j("chatList.loadErrorRetry",{error:x}):j("chatList.loadOlderMessages");return s.jsxs("div",{className:"chat-scroll-frame",children:[s.jsx("div",{ref:y,"data-chat-scroll":!0,className:"chat-container",children:s.jsxs("div",{ref:v,className:"chat-container-content",children:[g&&s.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:j("chatList.loadingOlderMessages")}),fe&&!g&&s.jsx("div",{className:"text-center py-2",children:s.jsx("button",{type:"button",onClick:q,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${x&&h===0?"bg-transparent border-yellow-500/30 text-yellow-400 opacity-80 hover:opacity-100":"bg-transparent border-border-subtle text-text-muted opacity-70 hover:opacity-100 hover:border-accent/40"}`,children:Te})}),V.length===0&&!fe&&(m||s.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:j("chatList.waitingForMessages")})),V.map(ce=>{if(ce.type==="action"){const je=ce.data;return s.jsx(fb,{log:je},`action-${ce.index}`)}const H=ce.data;ce.index;const pe=sa(H),le=H.receivedAt||u[pe],W=`${c}-${pe}`,be=F.has(W);return s.jsx(bb,{message:H,receivedAt:le,agentName:r,userName:a,isCliMode:o,isTextExpanded:be,onToggleTextExpanded:()=>D(je=>{const Se=new Set(je);return be?Se.delete(W):Se.add(W),Se})},`msg-${pe}`)}),i&&s.jsx("div",{className:"self-start chat-typing-wrapper",children:s.jsxs("div",{className:"typing-indicator",children:[s.jsx("div",{className:"dot"}),s.jsx("div",{className:"dot"}),s.jsx("div",{className:"dot"}),s.jsx("span",{className:"text-[11px] text-text-muted ml-1",children:j("chatList.agentGenerating")})]})}),s.jsx("div",{className:"min-h-10",ref:N})]})}),(O.showTop||O.showBottom)&&s.jsxs("div",{className:"chat-scroll-jump-controls","aria-label":j("chatList.jumpToTop"),children:[O.showTop&&s.jsx("button",{type:"button",className:"chat-scroll-jump-button",onClick:G,"aria-label":j("chatList.jumpToOldestMessages"),title:j("chatList.jumpToTop"),children:j("chatList.top")}),O.showBottom&&s.jsx("button",{type:"button",className:"chat-scroll-jump-button chat-scroll-jump-button-primary",onClick:Z,"aria-label":j("chatList.jumpToLatestMessages"),title:j("chatList.jumpToBottom"),children:j("chatList.latest")})]})]})}),xb=l.memo(gb,(e,t)=>e.messages===t.messages&&e.actionLogs===t.actionLogs&&e.agentName===t.agentName&&e.userName===t.userName&&e.isCliMode===t.isCliMode&&e.isWorking===t.isWorking&&e.contextKey===t.contextKey&&e.receivedAtMap===t.receivedAtMap&&e.lastMessageHash===t.lastMessageHash&&e.showActivityMessages===t.showActivityMessages&&e.emptyState===t.emptyState&&e.onLoadMore===t.onLoadMore&&e.isLoadingMore===t.isLoadingMore&&e.hasMoreHistory===t.hasMoreHistory&&e.hiddenLiveCount===t.hiddenLiveCount&&e.loadError===t.loadError&&e.scrollToBottomRequestNonce===t.scrollToBottomRequestNonce&&e.isVisible===t.isVisible),vb="modulepreload",yb=function(e){return"/"+e},Hl={},wb=function(t,n,r){let a=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const i=document.querySelector("meta[property=csp-nonce]"),c=(i==null?void 0:i.nonce)||(i==null?void 0:i.getAttribute("nonce"));a=Promise.allSettled(n.map(u=>{if(u=yb(u),u in Hl)return;Hl[u]=!0;const p=u.endsWith(".css"),d=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${d}`))return;const m=document.createElement("link");if(m.rel=p?"stylesheet":vb,p||(m.as="script"),m.crossOrigin="",m.href=u,c&&m.setAttribute("nonce",c),document.head.appendChild(m),p)return new Promise((f,g)=>{m.addEventListener("load",f),m.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${u}`)))})}))}function o(i){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=i,window.dispatchEvent(c),!c.defaultPrevented)throw i}return a.then(i=>{for(const c of i||[])c.status==="rejected"&&o(c.reason);return t().catch(o)})};let Fl=!1;const uu=l.forwardRef(({onInput:e,onViewportMetrics:t,onScrollMetrics:n,fontSize:r=13,readOnly:a=!1,sizingMode:o="measured"},i)=>{const c=l.useRef(null),[u,p]=l.useState(null),d=l.useRef([]),m=l.useRef(!1),f=l.useRef(!1),g=l.useRef(!1),w=l.useRef(!1),h=()=>{const x=c.current;if(x){m.current&&(x.clear(),m.current=!1);for(const k of d.current)x.write(k.data,k.onProcessed);d.current=[],f.current&&(x.fit(),f.current=!1),g.current&&(x.bumpResize(),g.current=!1),w.current&&(x.scrollToTop(),w.current=!1)}};return l.useImperativeHandle(i,()=>({write:(x,k)=>{c.current?c.current.write(x,k):d.current.push({data:x,onProcessed:k})},clear:()=>{c.current?c.current.clear():(d.current=[],m.current=!0)},reset:()=>{c.current&&typeof c.current.reset=="function"?c.current.reset():(d.current=[],m.current=!0)},resize:(x,k)=>{c.current&&typeof c.current.resize=="function"&&c.current.resize(x,k)},fit:()=>{c.current?c.current.fit():f.current=!0},bumpResize:()=>{c.current?c.current.bumpResize():g.current=!0},scrollToTop:()=>{c.current?c.current.scrollToTop():w.current=!0},getSelection:()=>{var x,k;return((k=(x=c.current)==null?void 0:x.getSelection)==null?void 0:k.call(x))||""},getVisibleText:()=>{var x,k;return((k=(x=c.current)==null?void 0:x.getVisibleText)==null?void 0:k.call(x))||""}}),[]),l.useEffect(()=>{u&&h()},[u]),l.useEffect(()=>{let x=!1;return wb(()=>import("./terminal-BZj_X5zy.js"),__vite__mapDeps([0,1,2])).then(k=>{Fl||(Fl=!0,console.info("[CliTerminal] renderer module loaded: terminal-render-web")),x||p(()=>k.GhosttyTerminalView)}).catch(k=>{console.error("[CliTerminal] failed to load terminal renderer",k)}),()=>{x=!0}},[]),u?s.jsx(u,{ref:c,onInput:e,onViewportMetrics:t,onScrollMetrics:n,fontSize:r,readOnly:a,sizingMode:o,className:"w-full h-full rounded-lg overflow-hidden"}):s.jsx("div",{className:"w-full h-full rounded-lg overflow-hidden animate-pulse",style:{background:"#0f1117"}})});uu.displayName="CliTerminal";function Bt(...e){return Ah(Mh(e))}const kb={lg:"rounded-lg",xl:"rounded-xl","2xl":"rounded-2xl"},Sb={none:"",sm:"p-3",md:"px-4 py-3.5",lg:"px-5 py-4"},Ss=l.forwardRef(function({radius:t="xl",padding:n="md",className:r,...a},o){return s.jsx("div",{ref:o,className:Bt("border border-border-subtle bg-bg-secondary",kb[t],Sb[n],r),...a})});function kr({label:e,value:t,sub:n,icon:r}){return s.jsxs(Ss,{children:[s.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[s.jsx("span",{className:"text-base flex items-center",children:r}),s.jsx("span",{className:"text-[10px] text-text-muted uppercase tracking-wide font-semibold",children:e})]}),s.jsx("div",{className:"text-[22px] font-bold text-text-primary tracking-tight",children:t}),n&&s.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:n})]})}function Bl({value:e,max:t,label:n,color:r="#8b5cf6",detail:a,compact:o=!1}){const i=t>0?Math.min(Math.round(e/t*100),100):0,c=i>85?"#ef4444":i>60?"var(--status-warning)":r;return o?s.jsxs("div",{className:"flex-1",children:[s.jsxs("div",{className:"flex justify-between mb-0.5",children:[s.jsx("span",{className:"text-[9px] text-text-muted uppercase tracking-wide font-semibold",children:n}),s.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[i,"%"]})]}),s.jsx("div",{className:"h-1 bg-white/[0.04] rounded-sm overflow-hidden",children:s.jsx("div",{className:"h-full rounded-sm transition-[width] duration-500",style:{width:`${i}%`,background:c}})})]}):s.jsxs("div",{className:"flex-1",children:[s.jsxs("div",{className:"flex justify-between mb-1.5",children:[s.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:n}),s.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[i,"%"]})]}),s.jsx("div",{className:"h-1.5 bg-white/[0.04] rounded-sm overflow-hidden",children:s.jsx("div",{className:"h-full rounded-sm transition-[width] duration-[600ms]",style:{width:`${i}%`,background:`linear-gradient(90deg, ${c}, ${c}cc)`}})}),a&&s.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:a})]})}function Cb({cursorPos:e,viewportRef:t,imgRef:n}){var b;if(!e||!n.current)return null;const r=n.current,a=r.getBoundingClientRect(),o=(b=t.current)==null?void 0:b.getBoundingClientRect();if(!o)return null;const i=r.naturalWidth||a.width,c=r.naturalHeight||a.height,u=i/c,p=a.width/a.height;let d,m,f,g;u>p?(d=a.width,m=a.width/u,f=0,g=(a.height-m)/2):(m=a.height,d=a.height*u,f=(a.width-d)/2,g=0);const w=a.left-o.left+f+d*e.nx,h=a.top-o.top+g+m*e.ny,x=Math.max(8,Math.min(o.width-8,w)),k=Math.max(8,Math.min(o.height-8,h));return s.jsxs("div",{style:{position:"absolute",left:x-8,top:k-8,width:16,height:16,pointerEvents:"none",zIndex:100},children:[s.jsx("div",{style:{position:"absolute",left:7,top:0,width:2,height:16,background:"rgba(59,130,246,0.8)"}}),s.jsx("div",{style:{position:"absolute",left:0,top:7,width:16,height:2,background:"rgba(59,130,246,0.8)"}}),s.jsx("div",{style:{position:"absolute",left:5,top:5,width:6,height:6,borderRadius:"50%",background:"#3b82f6",boxShadow:"0 0 8px rgba(59,130,246,0.6)"}})]})}function jb({inputMode:e,onToggleInputMode:t,isImeOpen:n,setIsImeOpen:r,isMenuOpen:a,setIsMenuOpen:o,imeText:i,setImeText:c,handleImeSubmit:u,isConnActive:p,zoom:d,isMobile:m,mobileFillZoom:f,onZoomOut:g,onZoomReset:w,onZoomIn:h,transportType:x,screenshotUsage:k,lastActionStatus:b}){const{t:S}=Ne("common");return s.jsxs(s.Fragment,{children:[s.jsxs("div",{onTouchStart:j=>j.stopPropagation(),className:"absolute bottom-0 left-0 right-0 z-20 flex items-center justify-center gap-1.5 px-3 py-2 bg-black/75 backdrop-blur-xl border-t border-white/[0.08] touch-none",children:[s.jsxs("div",{onClick:t,className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${e==="mouse"?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:[s.jsx("span",{className:"text-sm",children:e==="mouse"?"🖱️":"👆"}),s.jsx("span",{className:`text-[10px] font-bold ${e==="mouse"?"text-blue-400":"text-slate-400"}`,children:S(e==="mouse"?"remote.mouse":"remote.touch")})]}),s.jsxs("div",{className:"relative",children:[s.jsx("div",{onClick:()=>{r(j=>!j),o(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${n?"bg-emerald-500/25 border border-emerald-500/40":"bg-white/[0.08] border border-white/10"}`,children:s.jsx("span",{className:"text-sm",children:"⌨️"})}),n&&s.jsx("div",{className:"absolute bottom-10 left-1/2 -translate-x-1/2 w-[220px] bg-neutral-950/[0.98] backdrop-blur-[30px] rounded-xl border border-white/20 p-[10px_12px] shadow-[0_10px_30px_rgba(0,0,0,0.8)] flex flex-col gap-2 z-20",style:{animation:"slideUp 0.15s ease-out"},children:s.jsx("input",{type:"text",placeholder:S("remote.typeAndEnter"),value:i,autoFocus:!0,onTouchStart:j=>j.stopPropagation(),onChange:j=>c(j.target.value),onKeyDown:j=>{u(j)},className:"w-full bg-black/60 border border-white/15 rounded-lg px-2.5 py-2 text-white text-[13px] outline-none"})})]}),s.jsx("div",{className:"relative",children:s.jsx("div",{onClick:()=>{o(j=>!j),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${a?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:s.jsx("span",{className:"text-sm",children:"⚙️"})})}),s.jsx("div",{className:"w-px h-[18px] bg-white/10"}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:p?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[s.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:p?"#22c55e":"#eab308",boxShadow:p?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),s.jsx("span",{className:"text-[8px] font-extrabold",style:{color:p?"#22c55e":"#eab308"},children:S(p?"remote.connected":"remote.ws")})]}),d>1&&s.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(d*100),"%"]}),x==="direct"&&s.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#22c55e",background:"rgba(34,197,94,0.12)"},title:S("remote.directP2PTitle"),children:S("remote.direct")}),x==="relay"&&s.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 12%, transparent)"},title:S("remote.turnRelayTitle"),children:S("remote.relay")}),k&&k.dailyBudgetMinutes>0&&s.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:k.budgetExhausted?"#ef4444":"#c4b5fd",background:k.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:S("remote.dailyTurnTitle"),children:k.budgetExhausted?S("remote.turnBlocked"):S("remote.turnUsage",{used:k.dailyUsedMinutes,budget:k.dailyBudgetMinutes})}),b&&s.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:b})]})]}),a&&s.jsxs("div",{onTouchStart:j=>j.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[s.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:S("remote.settings")}),s.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[s.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:[S("remote.zoom")," ",d<=(m?f:1)+.01?S(m?"remote.fill":"remote.fit"):`${Math.round(d*100)}%`]}),s.jsxs("div",{style:{display:"flex",gap:4},children:[s.jsx("button",{onClick:j=>{j.stopPropagation(),g()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),s.jsx("button",{onClick:j=>{j.stopPropagation(),w()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:9,fontWeight:800,cursor:"pointer"},children:S(m?"remote.fill":"remote.fit")}),s.jsx("button",{onClick:j=>{j.stopPropagation(),h()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"+"})]})]})]})]})}function Nb({waitingLabel:e,waitingHint:t,transportType:n}){const{t:r}=Ne("common");return s.jsxs("div",{className:"text-center flex flex-col items-center gap-3 px-6",children:[s.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.35)]",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:s.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),s.jsx("div",{className:"text-white/85 text-[13px] font-semibold tracking-wide",children:e}),s.jsx("div",{className:"text-[11px] text-white/40",children:t}),n==="relay"&&s.jsx("div",{className:"text-[10px] font-medium",style:{color:"var(--status-warning)",opacity:.8},children:r("remote.waitingState.turnRelayActive")})]})}function Ab(){if(typeof window>"u")return!1;try{return window.__ADHDEV_DEBUG_RENDERS__===!0||window.localStorage.getItem("adhdev_debug_renders")==="1"}catch{return window.__ADHDEV_DEBUG_RENDERS__===!0}}function Ol(e){return e==null||typeof e=="number"||typeof e=="boolean"?e:typeof e=="string"?e.length>64?`${e.slice(0,61)}...`:e:Array.isArray(e)?`Array(${e.length})`:typeof e=="object"?"Object":typeof e}function hr(e,t){const n=l.useRef(null),r=l.useRef(0);l.useEffect(()=>{if(!Ab())return;r.current+=1;const a=n.current;if(!a){console.debug(`[render-trace] ${e}#${r.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(t).map(([i,c])=>[i,Ol(c)]))}),n.current=t;return}const o=Object.keys({...a,...t}).filter(i=>!Object.is(a[i],t[i]));o.length>0&&console.debug(`[render-trace] ${e}#${r.current}`,{changed:o,snapshot:Object.fromEntries(o.map(i=>[i,Ol(t[i])]))}),n.current=t})}function Mb({containerRef:e,viewportRef:t,imgRef:n,inputMode:r,setInputMode:a,minZoom:o,zoomRef:i,panXRef:c,panYRef:u,setPanX:p,setPanY:d,setZoom:m,lastWheelTimeRef:f,onAction:g,setLastActionStatus:w,spawnRippleFromNormalized:h,clampPan:x,isMobile:k,mobileFillZoom:b}){const[S,j]=l.useState(null),y=l.useRef(null),v=l.useRef(null),N=l.useRef(null),C=l.useRef(!1),A=l.useRef(null),M=l.useRef(0),T=l.useRef(null),R=l.useRef(1),E=l.useRef({x:0,y:0}),_=l.useRef(!1),z=l.useRef(r),F=l.useRef(g),D=30,O=550,L=18,I=60,$=400,P=12,U=()=>{if(y.current)return;const Y={nx:.5,ny:.5};y.current=Y,j(Y)};return l.useEffect(()=>{z.current=r,r==="mouse"&&U()},[r]),l.useEffect(()=>{F.current=g},[g]),l.useEffect(()=>{const Y=e.current;if(!Y)return;const X=ae=>{if(!n.current)return null;const Ce=n.current.getBoundingClientRect();return!Ce.width||!Ce.height?null:{nx:Math.max(0,Math.min(1,(ae.clientX-Ce.left)/Ce.width)),ny:Math.max(0,Math.min(1,(ae.clientY-Ce.top)/Ce.height))}},de=(ae,Ce)=>{if(!n.current)return{dnx:0,dny:0};const ye=n.current,ke=ye.getBoundingClientRect(),me=ye.naturalWidth||ke.width,q=ye.naturalHeight||ke.height,G=me/q,Z=ke.width/ke.height;let V,fe;return G>Z?(V=ke.width,fe=ke.width/G):(fe=ke.height,V=ke.height*G),{dnx:ae/V,dny:Ce/fe}},ne=(ae,Ce,ye)=>{if(ye<=1.05)return;const ke=-(ae-.5)*100,me=-(Ce-.5)*100,q=x(ke,me,ye);(Math.abs(q.x-c.current)>.1||Math.abs(q.y-u.current)>.1)&&(p(q.x),d(q.y),c.current=q.x,u.current=q.y)},B=ae=>{const Ce=t.current;if(Ce&&ae.target instanceof Node&&Ce.contains(ae.target))ae.preventDefault();else return;if(ae.touches.length===1){const ye=ae.touches[0];v.current={x:ye.clientX,y:ye.clientY,time:Date.now()},N.current={x:ye.clientX,y:ye.clientY},_.current||(C.current=!1),A.current=setTimeout(()=>{if(!C.current&&!_.current)if(C.current=!0,z.current==="mouse"){const ke=y.current||{nx:.5,ny:.5};w("Right Click"),h(ke.nx,ke.ny,"right"),F.current("input_click",{...ke,button:"right"}).catch(()=>{})}else{const ke=X(ye);ke&&(w("Right Click"),h(ke.nx,ke.ny,"right"),F.current("input_click",{...ke,button:"right"}).catch(()=>{}))}},500);return}if(ae.touches.length===2){A.current&&clearTimeout(A.current),C.current=!0,_.current=!0;const ye=ae.touches[1].clientX-ae.touches[0].clientX,ke=ae.touches[1].clientY-ae.touches[0].clientY;T.current=Math.sqrt(ye*ye+ke*ke),R.current=i.current,E.current={x:(ae.touches[0].clientX+ae.touches[1].clientX)/2,y:(ae.touches[0].clientY+ae.touches[1].clientY)/2}}},ie=ae=>{const Ce=t.current;if(Ce&&ae.target instanceof Node&&Ce.contains(ae.target)&&ae.preventDefault(),ae.touches.length===1&&N.current){const ye=ae.touches[0],ke=ye.clientX-N.current.x,me=ye.clientY-N.current.y;if(!C.current&&v.current){const q=ye.clientX-v.current.x,G=ye.clientY-v.current.y;Math.sqrt(q*q+G*G)>8&&(C.current=!0,A.current&&clearTimeout(A.current))}if(C.current)if(z.current==="mouse"){const q=de(ke,me),G=y.current||{nx:.5,ny:.5},Z=Math.max(0,Math.min(1,G.nx+q.dnx)),V=Math.max(0,Math.min(1,G.ny+q.dny));y.current={nx:Z,ny:V},j({nx:Z,ny:V}),w(`Cursor: ${Math.round(Z*100)}%, ${Math.round(V*100)}%`),ne(Z,V,i.current);const fe=Date.now();fe-f.current>=30&&(f.current=fe,F.current("input_mouseMoved",{nx:Z,ny:V}).catch(()=>{}))}else if(i.current>1){const q=t.current;if(q){const G=q.clientWidth,Z=q.clientHeight,V=c.current+ke/G*100,fe=u.current+me/Z*100,Te=x(V,fe,i.current);p(Te.x),d(Te.y),c.current=Te.x,u.current=Te.y}}else{const q=X(ye);if(q){const G=Date.now();G-f.current>=40&&(f.current=G,w("Scroll"),F.current("input_wheel",{nx:q.nx,ny:q.ny,deltaX:Math.round(-ke*2.5),deltaY:Math.round(-me*2.5)}).catch(()=>{}))}}N.current={x:ye.clientX,y:ye.clientY};return}if(ae.touches.length===2&&T.current!==null){const ye=ae.touches[1].clientX-ae.touches[0].clientX,ke=ae.touches[1].clientY-ae.touches[0].clientY,q=Math.sqrt(ye*ye+ke*ke)/T.current,G=(ae.touches[0].clientX+ae.touches[1].clientX)/2,Z=(ae.touches[0].clientY+ae.touches[1].clientY)/2,V=G-E.current.x,fe=Z-E.current.y,Te=Math.abs(q-1)>.03;if(z.current==="mouse"){if(Te){const ce=Math.max(o,Math.min(5,R.current*q));m(ce),i.current=ce}else if(Math.abs(V)>2||Math.abs(fe)>2){const ce=y.current||{nx:.5,ny:.5},H=Date.now();H-f.current>=30&&(f.current=H,w("Scroll"),F.current("input_wheel",{nx:ce.nx,ny:ce.ny,deltaX:Math.round(-V*3),deltaY:Math.round(-fe*3)}).catch(()=>{}))}}else{const ce=Math.max(o,Math.min(5,R.current*q));m(ce),i.current=ce;const H=t.current;if(H&&ce>1){const pe=H.clientWidth,le=H.clientHeight,W=c.current+V/pe*100,be=u.current+fe/le*100,je=x(W,be,ce);p(je.x),d(je.y),c.current=je.x,u.current=je.y}}E.current={x:G,y:Z}}},K=ae=>{var Ce;if(A.current&&clearTimeout(A.current),T.current=null,ae.touches.length===1&&_.current){const ye=ae.touches[0];v.current={x:ye.clientX,y:ye.clientY,time:Date.now()},N.current={x:ye.clientX,y:ye.clientY},C.current=!0;return}if(ae.touches.length===0){if(_.current){_.current=!1,C.current=!1;return}if(ae.changedTouches.length===1){const ye=ae.changedTouches[0],ke=Date.now(),me=ke-(((Ce=v.current)==null?void 0:Ce.time)||0),q=v.current?ye.clientX-v.current.x:0,G=v.current?ye.clientY-v.current.y:0,Z=Math.sqrt(q*q+G*G);if(z.current==="mouse"){if(me<D||me>O||Z>L){C.current=!1;return}const V=y.current||X(ye);V&&(w(`Click: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),h(V.nx,V.ny,"left"),F.current("input_click",{...V}).catch(()=>{}))}else{if(C.current){C.current=!1;return}if(me<I||me>$||Z>P){C.current=!1;return}const V=X(ye);if(!V)return;ke-M.current<300?(w("Double tap"),h(V.nx,V.ny,"double"),F.current("input_click",{...V,clickCount:2}).catch(()=>{}),M.current=0):(w(`Tap: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),h(V.nx,V.ny,"left"),F.current("input_click",{...V}).catch(()=>{}),M.current=ke)}}C.current=!1}};return Y.addEventListener("touchstart",B,{passive:!1}),Y.addEventListener("touchmove",ie,{passive:!1}),Y.addEventListener("touchend",K,{passive:!1}),()=>{Y.removeEventListener("touchstart",B),Y.removeEventListener("touchmove",ie),Y.removeEventListener("touchend",K),A.current&&clearTimeout(A.current)}},[e,t,n,o,i,c,u,p,d,m,f,w,h,x]),{cursorPos:S,cursorPosRef:y,handleToggleInputMode:()=>{a(Y=>{const X=Y==="touch"?"mouse":"touch";return X==="mouse"&&U(),X})},handleZoomReset:()=>{const Y=k?b:1;m(Y),i.current=Y,p(0),d(0),c.current=0,u.current=0}}}function pu({onAction:e,addLog:t,connState:n,connScreenshot:r,screenshotUsage:a,transportType:o}){const i=l.useRef(null),c=l.useRef(null),u=l.useRef(null),[p,d]=l.useState(null),[m,f]=l.useState(""),[,g]=l.useState(!1),[w,h]=l.useState([]),x=l.useRef(0),[k,b]=l.useState(!1),[S,j]=l.useState(!1),y=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[v,N]=l.useState(y?"mouse":"touch"),[C,A]=l.useState(1),M=l.useRef(!1),[T,R]=l.useState(1),[E,_]=l.useState(0),[z,F]=l.useState(0);hr("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:v,zoom:T,panX:E,panY:z,isMenuOpen:k,isImeOpen:S});const D=l.useRef(0),O=l.useRef(T),L=l.useRef(E),I=l.useRef(z);l.useEffect(()=>{O.current=T},[T]),l.useEffect(()=>{L.current=E},[E]),l.useEffect(()=>{I.current=z},[z]),l.useEffect(()=>{var me;(me=i.current)==null||me.focus()},[]);const $=n==="connected",P=r,U=$?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",J=$?"The remote stream is warming up":"Waiting for the remote stream to catch up";l.useEffect(()=>{if(!y||M.current||!P)return;const me=u.current,q=c.current;if(!me||!q)return;const G=()=>{const Z=q.clientWidth,V=q.clientHeight,fe=me.naturalWidth,Te=me.naturalHeight;if(!fe||!Te||!Z||!V)return;const ce=Math.min(Z/fe,V/Te),pe=Math.max(Z/fe,V/Te)/ce;pe>1.01&&(A(pe),R(pe),O.current=pe),M.current=!0};me.complete&&me.naturalWidth?G():me.addEventListener("load",G,{once:!0})},[P,y]);const re=.5;l.useEffect(()=>{T<=re&&(_(0),F(0))},[T,re]);const Y=(me,q,G)=>{if(G<=re)return{x:0,y:0};const Z=(G-1)/(2*G)*100,V=(G-1)/(2*G)*100;return{x:Math.max(-Z,Math.min(Z,me)),y:Math.max(-V,Math.min(V,q))}},X=(me,q)=>{if(!u.current)return null;const G=u.current.getBoundingClientRect();return!G.width||!G.height?null:{nx:Math.max(0,Math.min(1,(me-G.left)/G.width)),ny:Math.max(0,Math.min(1,(q-G.top)/G.height))}},de=(me,q,G)=>{const Z=c.current;if(!Z)return;const V=Z.getBoundingClientRect(),fe=++x.current;h(Te=>[...Te,{id:fe,x:me-V.left,y:q-V.top,type:G}]),setTimeout(()=>h(Te=>Te.filter(ce=>ce.id!==fe)),600)},ne=(me,q,G)=>{const Z=u.current,V=c.current;if(!Z||!V)return;const fe=Z.getBoundingClientRect(),Te=V.getBoundingClientRect(),ce=Z.naturalWidth||fe.width,H=Z.naturalHeight||fe.height,pe=ce/H,le=fe.width/fe.height;let W,be,je,Se;pe>le?(W=fe.width,be=fe.width/pe,je=0,Se=(fe.height-be)/2):(be=fe.height,W=fe.height*pe,je=(fe.width-W)/2,Se=0);const He=fe.left-Te.left+je+W*me,Xe=fe.top-Te.top+Se+be*q,dt=++x.current;h(it=>[...it,{id:dt,x:He,y:Xe,type:G}]),setTimeout(()=>h(it=>it.filter(he=>he.id!==dt)),600)},B=async me=>{var G;const q=X(me.clientX,me.clientY);if(q){d(`Click: ${Math.round(q.nx*100)}%, ${Math.round(q.ny*100)}%`),de(me.clientX,me.clientY,"left"),(G=i.current)==null||G.focus();try{const Z=await e("input_click",{nx:q.nx,ny:q.ny});Z!=null&&Z.success||t(`❌ Click failed: ${Z==null?void 0:Z.error}`)}catch(Z){t(`❌ Click error: ${Z.message||Z}`)}}},ie=async(me,q,G,Z=0)=>{try{await e("input_key",{type:G?"char":"keyDown",key:me,code:q,text:G?me:void 0,unmodifiedText:G?me:void 0,modifiers:Z})}catch(V){t(`❌ Key error: ${V.message||V}`)}},K=async me=>{if(me.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(me.key)&&me.preventDefault();let G=0;me.altKey&&(G|=1),me.ctrlKey&&(G|=2),me.metaKey&&(G|=4),me.shiftKey&&(G|=8),d(`Key: ${me.key}`),await ie(me.key,me.code,me.key.length===1,G)},ae=async me=>{if(me.key==="Enter"){if(me.nativeEvent.isComposing)return;if(m){const q=m;f(""),d(`IME Sent: ${q}`);try{const G=await e("input_type",{text:q});G!=null&&G.success||t(`❌ IME error: ${G==null?void 0:G.error}`)}catch(G){t(`❌ IME error: ${G.message}`)}}else d("Key: Enter"),await ie("Enter","Enter",!1)}};l.useEffect(()=>{const me=i.current;if(!me)return;const q=G=>{var Z;if((Z=u.current)!=null&&Z.contains(G.target)){G.preventDefault();const V=Date.now();if(V-D.current<40)return;D.current=V;const fe=X(G.clientX,G.clientY);if(!fe)return;d(`Scroll: ${Math.round(G.deltaY)}`),e("input_wheel",{nx:fe.nx,ny:fe.ny,deltaX:Math.round(G.deltaX),deltaY:Math.round(G.deltaY)}).catch(()=>{})}};return me.addEventListener("wheel",q,{passive:!1}),()=>me.removeEventListener("wheel",q)},[e]);const{cursorPos:Ce,handleToggleInputMode:ye,handleZoomReset:ke}=Mb({containerRef:i,viewportRef:c,imgRef:u,inputMode:v,setInputMode:N,minZoom:re,zoomRef:O,panXRef:L,panYRef:I,setPanX:_,setPanY:F,setZoom:R,lastWheelTimeRef:D,onAction:e,setLastActionStatus:d,spawnRippleFromNormalized:ne,clampPan:Y,isMobile:y,mobileFillZoom:C});return s.jsxs("div",{ref:i,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:K,onContextMenu:me=>me.preventDefault(),onFocus:()=>g(!0),onBlur:()=>g(!1),tabIndex:0,children:[s.jsxs("div",{ref:c,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[P?s.jsx("img",{ref:u,src:P,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${T}) translate(${E}%, ${z}%)`,transformOrigin:"center center",cursor:v==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:B,onContextMenu:me=>me.preventDefault(),onDragStart:me=>me.preventDefault()}):s.jsx(Nb,{waitingLabel:U,waitingHint:J,transportType:o}),v==="mouse"&&P&&s.jsx(Cb,{cursorPos:Ce,viewportRef:c,imgRef:u}),w.map(me=>{const G={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[me.type];return s.jsxs("div",{style:{position:"absolute",left:me.x,top:me.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[s.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${G}, 0.8)`,animation:"click-ripple-ring 0.5s ease-out forwards",position:"absolute",left:-20,top:-20}}),s.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:`rgba(${G}, 0.9)`,boxShadow:`0 0 12px rgba(${G}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},me.id)})]}),s.jsx(jb,{inputMode:v,onToggleInputMode:ye,isImeOpen:S,setIsImeOpen:j,isMenuOpen:k,setIsMenuOpen:b,imeText:m,setImeText:f,handleImeSubmit:ae,isConnActive:$,zoom:T,isMobile:y,mobileFillZoom:C,onZoomOut:()=>R(me=>Math.max(.5,me-.25)),onZoomReset:ke,onZoomIn:()=>R(me=>Math.min(5,me+.25)),transportType:o,screenshotUsage:a,lastActionStatus:p}),s.jsx("style",{children:`
8
+ `});if(m.isActivityFacing&&d!=="thought"&&d!=="tool"&&d!=="terminal"){const T=m.label||"Activity";return s.jsxs("div",{className:"self-start chat-msg-activity","data-chat-activity-row":"true",children:[s.jsxs("div",{className:"chat-msg-activity-meta","aria-label":"Activity message",children:[s.jsx("span",{className:"activity-dot"}),s.jsx("span",{children:T})]}),g&&f?s.jsx("div",{className:"chat-msg-activity-body",children:s.jsx(Rn,{parts:f,renderAsPreformatted:!1})}):s.jsx("div",{className:"chat-msg-activity-body",style:{whiteSpace:"pre-wrap"},children:w})]})}if(d==="thought"){const T=typeof((C=t.meta)==null?void 0:C.label)=="string"?t.meta.label:"Thought";return s.jsxs("div",{className:"self-start chat-msg-thought","data-chat-activity-row":m.isActivityFacing?"true":void 0,children:[s.jsxs("div",{className:"chat-msg-header",children:[s.jsx(Wf,{size:13}),s.jsx("span",{children:T})]}),s.jsx("div",{className:"chat-msg-body",children:w})]})}if(d==="tool")return s.jsxs("div",{className:"self-start chat-msg-tool","data-chat-activity-row":m.isActivityFacing?"true":void 0,children:[s.jsxs("div",{className:"chat-msg-tool-meta","aria-label":"Tool message",children:[s.jsx("span",{className:"tool-icon",children:"⏺"}),s.jsx("span",{className:"tool-label",children:"Tool"})]}),g&&f?s.jsx("div",{className:"tool-text w-full",children:s.jsx(Rn,{parts:f,renderAsPreformatted:!1})}):s.jsx("div",{className:"tool-text w-full",style:{whiteSpace:"pre-wrap"},children:w})]});if(d==="terminal"){const T=(A=t.meta)!=null&&A.isRunning?"⏳":"✅",R=typeof((M=t.meta)==null?void 0:M.label)=="string"?t.meta.label:"Ran command";return s.jsxs("div",{className:"self-start chat-msg-terminal","data-chat-activity-row":m.isActivityFacing?"true":void 0,children:[s.jsxs("div",{className:"chat-msg-header",children:[s.jsx("span",{children:T}),s.jsx("span",{children:R})]}),g&&f?s.jsx("div",{className:"chat-msg-body",children:s.jsx(Rn,{parts:f,renderAsPreformatted:!0})}):s.jsx("pre",{className:"chat-msg-body",children:w})]})}if(d==="system")return s.jsx("div",{className:"self-center chat-msg-system",children:g&&f?s.jsx(Rn,{parts:f,renderAsPreformatted:!1}):w.slice(0,100)});const h=t.meta,k=(typeof(h==null?void 0:h.renderMode)=="string"?h.renderMode.trim():"")==="preformatted",b=w,S=!1,j=b,y=k,v=!p&&!y&&Kd(j),N=["chat-message-row",p?"chat-message-row-user self-end":"chat-message-row-assistant self-start"].join(" ");return s.jsx("div",{className:N,children:(b||g||p)&&s.jsxs("div",{className:`chat-bubble ${p?"chat-bubble-user":"chat-bubble-assistant"}`,children:[s.jsxs("div",{className:`chat-bubble-header ${b||g?"mb-1.5":"mb-0"}`,children:[s.jsx("span",{className:"chat-sender",children:p?a||"You":t.senderName||r}),s.jsxs("span",{className:"chat-bubble-header-end",children:[(b||g)&&s.jsx(pb,{text:w}),n!=null&&s.jsx("span",{className:"chat-time",children:zd(n)})]})]}),(b||g)&&s.jsx("div",{className:"chat-markdown",children:g&&f?s.jsx(Rn,{parts:f,renderAsPreformatted:y}):s.jsx(hb,{content:j,renderAsPreformatted:y,renderAsMarkdown:v})}),S]})})},(e,t)=>(e.message===t.message||$l(e.message)===$l(t.message))&&e.receivedAt===t.receivedAt&&e.agentName===t.agentName&&e.userName===t.userName&&e.isCliMode===t.isCliMode&&e.isTextExpanded===t.isTextExpanded),gb=l.forwardRef(function({messages:t,actionLogs:n,agentName:r="Agent",userName:a,isCliMode:o=!1,isWorking:i=!1,contextKey:c="",receivedAtMap:u={},lastMessageHash:p,showActivityMessages:d=!1,emptyState:m,onLoadMore:f,isLoadingMore:g,hasMoreHistory:w,hiddenLiveCount:h=0,loadError:x,scrollToBottomRequestNonce:k,isVisible:b=!0},S){const{t:j}=Ne("common"),y=l.useRef(null),v=l.useRef(null),N=l.useRef(null),C=l.useRef(0),A=l.useRef(""),M=l.useRef(""),T=l.useRef(!1),R=l.useRef(null),E=l.useRef(!1),_=l.useRef(null),z=l.useRef(!1),[F,D]=l.useState(new Set),[O,L]=l.useState({showTop:!1,showBottom:!1}),I=l.useRef(!1),$=l.useRef(!1),P=l.useRef(b),U=l.useRef(b),J=l.useRef(null);U.current=b;const re=()=>{const ce=y.current;return ce?ce.scrollHeight-ce.scrollTop-ce.clientHeight<Ni:!0},Y=l.useCallback(()=>{const ce=y.current,H=ce?Tf(ce):{showTop:!1,showBottom:!1};L(pe=>pe.showTop===H.showTop&&pe.showBottom===H.showBottom?pe:H)},[]),X=l.useCallback((ce="auto")=>{var pe;const H=y.current;H&&(H.scrollTo({top:H.scrollHeight,behavior:ce}),(pe=H.ownerDocument.defaultView)==null||pe.requestAnimationFrame(()=>Y()))},[Y]),de=l.useCallback((ce="auto")=>{var pe;const H=y.current;H&&(H.scrollTo({top:0,behavior:ce}),(pe=H.ownerDocument.defaultView)==null||pe.requestAnimationFrame(()=>Y()))},[Y]),ne=l.useCallback(()=>{var W;const ce=y.current,H=(W=window.getSelection)==null?void 0:W.call(window);if(!ce||!H||H.rangeCount===0||H.isCollapsed){z.current=!1;return}const pe=H.anchorNode,le=H.focusNode;z.current=!!(pe&&le&&ce.contains(pe)&&ce.contains(le))},[]),B=l.useMemo(()=>{const ce=lb(t),H=iu(t);return db(ub(ce,H,d))},[t,d]),ie=B.length===t.length?p:void 0,K=Nf(B,ie),ae=l.useCallback(()=>{const ce=y.current;if(!ce||!c||!U.current)return;const H={top:ce.scrollTop,fromBottom:Math.max(0,ce.scrollHeight-ce.scrollTop-ce.clientHeight),messageFingerprint:K};J.current={contextKey:c,snapshot:H},Ln.set(c,H)},[c,K]),Ce=l.useCallback((ce="auto")=>{R.current!=null&&cancelAnimationFrame(R.current),R.current=requestAnimationFrame(()=>{R.current=null,X(ce)})},[X]),ye=l.useCallback(()=>{I.current=!1,E.current=!0,$.current=!0,_.current!=null&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>{E.current=!1,_.current=null},Pl)},[]);l.useEffect(()=>{const ce=!T.current,H=M.current!==c;if(M.current=c,ce||H){T.current=!0;const le=c?Ln.get(c):null,W=!!le&&na(le,K);I.current=W?Kn(le):!1,E.current=If(le,K),z.current||(W?requestAnimationFrame(()=>{const be=y.current;be&&(qa(be,le),I.current=Kn(le),Y(),$.current=!0)}):Ce("auto")),C.current=B.length,A.current=K;return}B.length>C.current;const pe=K!==A.current;Pf({hasSelection:z.current,userScrolledUp:I.current,hasChatContentChanged:pe})&&Ce("auto"),C.current=B.length,A.current=K},[K,c,B.length,Ce,Y]),l.useEffect(()=>{k&&(ye(),z.current||Ce("auto"))},[ye,Ce,k]),l.useEffect(()=>{const ce=P.current;ce&&!b&&ae(),U.current=b,P.current=b;const H=c?Ln.get(c):null;if(Af(ce,b,H,K)){if(!H)return;I.current=Kn(H),E.current=!1,z.current||requestAnimationFrame(()=>{const pe=y.current;pe&&(qa(pe,H),Y())});return}},[b,c,K,ye,ae,Ce,Y]),l.useEffect(()=>()=>{const ce=J.current;ce&&Ln.set(ce.contextKey,ce.snapshot),R.current!=null&&cancelAnimationFrame(R.current),_.current!=null&&window.clearTimeout(_.current)},[]),l.useEffect(()=>{const ce=v.current,H=y.current;if(!ce||!H)return;const pe=()=>{_.current!=null&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>{E.current=!1,_.current=null},Pl)},le=new ResizeObserver(()=>{Y();const W=E.current;Df({hasSelection:z.current,userScrolledUp:I.current,contextAutoScrollActive:W})&&(Ce("auto"),W&&pe())});return le.observe(ce),H!==ce&&le.observe(H),()=>{le.disconnect(),_.current!=null&&(window.clearTimeout(_.current),_.current=null)}},[Ce,c,Y]),l.useImperativeHandle(S,()=>({scrollToBottom:(ce="smooth")=>{X(ce)}}),[X]),l.useEffect(()=>{const ce=y.current;if(!ce)return;let H;const pe=()=>{ae(),clearTimeout(H),H=setTimeout(()=>{I.current=!re(),Y()},50)};return ce.addEventListener("scroll",pe,{passive:!0}),()=>{ce.removeEventListener("scroll",pe),clearTimeout(H)}},[ae,Y]),l.useEffect(()=>(document.addEventListener("selectionchange",ne),()=>document.removeEventListener("selectionchange",ne)),[ne]);const ke=l.useRef(0),me=l.useRef(!1);l.useEffect(()=>{const ce=y.current;if(!ce||!me.current||ke.current===0)return;const H=ce.scrollHeight-ke.current;H>0&&(ce.scrollTop=H),Y(),ae(),ke.current=0,me.current=!1},[B.length,ae,Y]),l.useEffect(()=>{if($.current||!c)return;const ce=Ln.get(c),H=y.current;if(!(!ce||!H)){if(!na(ce,K)){X("auto"),$.current=!0;return}qa(H,ce),I.current=Kn(ce),Y(),$.current=!0}},[c,K,B.length,X,Y]);const q=()=>{const ce=y.current;ce&&(ke.current=ce.scrollHeight),me.current=!0,f==null||f()},G=()=>{I.current=!0,de("smooth"),ae()},Z=()=>{ye(),X("smooth"),ae()},V=l.useMemo(()=>{const ce=B.map((W,be)=>({type:"message",data:W,index:be,ts:yf(W,be,u)}));if(!n||n.length===0)return ce;const H=[...n].sort((W,be)=>W.timestamp-be.timestamp).map((W,be)=>({type:"action",data:W,index:be,ts:W.timestamp})),pe=[];let le=0;for(const W of ce){for(;le<H.length&&W.ts>0&&H[le].ts<W.ts;)pe.push(H[le++]);pe.push(W)}for(;le<H.length;)pe.push(H[le++]);return pe},[B,n,u]),fe=h>0||!!w,Te=h>0?h>80?j("chatList.showEarlierMessagesHidden",{count:Math.min(h,80),total:h}):j("chatList.showEarlierMessages",{count:Math.min(h,80)}):x?j("chatList.loadErrorRetry",{error:x}):j("chatList.loadOlderMessages");return s.jsxs("div",{className:"chat-scroll-frame",children:[s.jsx("div",{ref:y,"data-chat-scroll":!0,className:"chat-container",children:s.jsxs("div",{ref:v,className:"chat-container-content",children:[g&&s.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:j("chatList.loadingOlderMessages")}),fe&&!g&&s.jsx("div",{className:"text-center py-2",children:s.jsx("button",{type:"button",onClick:q,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${x&&h===0?"bg-transparent border-yellow-500/30 text-yellow-400 opacity-80 hover:opacity-100":"bg-transparent border-border-subtle text-text-muted opacity-70 hover:opacity-100 hover:border-accent/40"}`,children:Te})}),V.length===0&&!fe&&(m||s.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:j("chatList.waitingForMessages")})),V.map(ce=>{if(ce.type==="action"){const je=ce.data;return s.jsx(fb,{log:je},`action-${ce.index}`)}const H=ce.data;ce.index;const pe=sa(H),le=H.receivedAt||u[pe],W=`${c}-${pe}`,be=F.has(W);return s.jsx(bb,{message:H,receivedAt:le,agentName:r,userName:a,isCliMode:o,isTextExpanded:be,onToggleTextExpanded:()=>D(je=>{const Se=new Set(je);return be?Se.delete(W):Se.add(W),Se})},`msg-${pe}`)}),i&&s.jsx("div",{className:"self-start chat-typing-wrapper",children:s.jsxs("div",{className:"typing-indicator",children:[s.jsx("div",{className:"dot"}),s.jsx("div",{className:"dot"}),s.jsx("div",{className:"dot"}),s.jsx("span",{className:"text-[11px] text-text-muted ml-1",children:j("chatList.agentGenerating")})]})}),s.jsx("div",{className:"min-h-10",ref:N})]})}),(O.showTop||O.showBottom)&&s.jsxs("div",{className:"chat-scroll-jump-controls","aria-label":j("chatList.jumpToTop"),children:[O.showTop&&s.jsx("button",{type:"button",className:"chat-scroll-jump-button",onClick:G,"aria-label":j("chatList.jumpToOldestMessages"),title:j("chatList.jumpToTop"),children:j("chatList.top")}),O.showBottom&&s.jsx("button",{type:"button",className:"chat-scroll-jump-button chat-scroll-jump-button-primary",onClick:Z,"aria-label":j("chatList.jumpToLatestMessages"),title:j("chatList.jumpToBottom"),children:j("chatList.latest")})]})]})}),xb=l.memo(gb,(e,t)=>e.messages===t.messages&&e.actionLogs===t.actionLogs&&e.agentName===t.agentName&&e.userName===t.userName&&e.isCliMode===t.isCliMode&&e.isWorking===t.isWorking&&e.contextKey===t.contextKey&&e.receivedAtMap===t.receivedAtMap&&e.lastMessageHash===t.lastMessageHash&&e.showActivityMessages===t.showActivityMessages&&e.emptyState===t.emptyState&&e.onLoadMore===t.onLoadMore&&e.isLoadingMore===t.isLoadingMore&&e.hasMoreHistory===t.hasMoreHistory&&e.hiddenLiveCount===t.hiddenLiveCount&&e.loadError===t.loadError&&e.scrollToBottomRequestNonce===t.scrollToBottomRequestNonce&&e.isVisible===t.isVisible),vb="modulepreload",yb=function(e){return"/"+e},Hl={},wb=function(t,n,r){let a=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const i=document.querySelector("meta[property=csp-nonce]"),c=(i==null?void 0:i.nonce)||(i==null?void 0:i.getAttribute("nonce"));a=Promise.allSettled(n.map(u=>{if(u=yb(u),u in Hl)return;Hl[u]=!0;const p=u.endsWith(".css"),d=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${u}"]${d}`))return;const m=document.createElement("link");if(m.rel=p?"stylesheet":vb,p||(m.as="script"),m.crossOrigin="",m.href=u,c&&m.setAttribute("nonce",c),document.head.appendChild(m),p)return new Promise((f,g)=>{m.addEventListener("load",f),m.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${u}`)))})}))}function o(i){const c=new Event("vite:preloadError",{cancelable:!0});if(c.payload=i,window.dispatchEvent(c),!c.defaultPrevented)throw i}return a.then(i=>{for(const c of i||[])c.status==="rejected"&&o(c.reason);return t().catch(o)})};let Fl=!1;const uu=l.forwardRef(({onInput:e,onViewportMetrics:t,onScrollMetrics:n,fontSize:r=13,readOnly:a=!1,sizingMode:o="measured"},i)=>{const c=l.useRef(null),[u,p]=l.useState(null),d=l.useRef([]),m=l.useRef(!1),f=l.useRef(!1),g=l.useRef(!1),w=l.useRef(!1),h=()=>{const x=c.current;if(x){m.current&&(x.clear(),m.current=!1);for(const k of d.current)x.write(k.data,k.onProcessed);d.current=[],f.current&&(x.fit(),f.current=!1),g.current&&(x.bumpResize(),g.current=!1),w.current&&(x.scrollToTop(),w.current=!1)}};return l.useImperativeHandle(i,()=>({write:(x,k)=>{c.current?c.current.write(x,k):d.current.push({data:x,onProcessed:k})},clear:()=>{c.current?c.current.clear():(d.current=[],m.current=!0)},reset:()=>{c.current&&typeof c.current.reset=="function"?c.current.reset():(d.current=[],m.current=!0)},resize:(x,k)=>{c.current&&typeof c.current.resize=="function"&&c.current.resize(x,k)},fit:()=>{c.current?c.current.fit():f.current=!0},bumpResize:()=>{c.current?c.current.bumpResize():g.current=!0},scrollToTop:()=>{c.current?c.current.scrollToTop():w.current=!0},getSelection:()=>{var x,k;return((k=(x=c.current)==null?void 0:x.getSelection)==null?void 0:k.call(x))||""},getVisibleText:()=>{var x,k;return((k=(x=c.current)==null?void 0:x.getVisibleText)==null?void 0:k.call(x))||""}}),[]),l.useEffect(()=>{u&&h()},[u]),l.useEffect(()=>{let x=!1;return wb(()=>import("./terminal-DiXj2eIR.js"),__vite__mapDeps([0,1,2])).then(k=>{Fl||(Fl=!0,console.info("[CliTerminal] renderer module loaded: terminal-render-web")),x||p(()=>k.GhosttyTerminalView)}).catch(k=>{console.error("[CliTerminal] failed to load terminal renderer",k)}),()=>{x=!0}},[]),u?s.jsx(u,{ref:c,onInput:e,onViewportMetrics:t,onScrollMetrics:n,fontSize:r,readOnly:a,sizingMode:o,className:"w-full h-full rounded-lg overflow-hidden"}):s.jsx("div",{className:"w-full h-full rounded-lg overflow-hidden animate-pulse",style:{background:"#0f1117"}})});uu.displayName="CliTerminal";function Bt(...e){return Ah(Mh(e))}const kb={lg:"rounded-lg",xl:"rounded-xl","2xl":"rounded-2xl"},Sb={none:"",sm:"p-3",md:"px-4 py-3.5",lg:"px-5 py-4"},Ss=l.forwardRef(function({radius:t="xl",padding:n="md",className:r,...a},o){return s.jsx("div",{ref:o,className:Bt("border border-border-subtle bg-bg-secondary",kb[t],Sb[n],r),...a})});function kr({label:e,value:t,sub:n,icon:r}){return s.jsxs(Ss,{children:[s.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[s.jsx("span",{className:"text-base flex items-center",children:r}),s.jsx("span",{className:"text-[10px] text-text-muted uppercase tracking-wide font-semibold",children:e})]}),s.jsx("div",{className:"text-[22px] font-bold text-text-primary tracking-tight",children:t}),n&&s.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:n})]})}function Bl({value:e,max:t,label:n,color:r="#8b5cf6",detail:a,compact:o=!1}){const i=t>0?Math.min(Math.round(e/t*100),100):0,c=i>85?"#ef4444":i>60?"var(--status-warning)":r;return o?s.jsxs("div",{className:"flex-1",children:[s.jsxs("div",{className:"flex justify-between mb-0.5",children:[s.jsx("span",{className:"text-[9px] text-text-muted uppercase tracking-wide font-semibold",children:n}),s.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[i,"%"]})]}),s.jsx("div",{className:"h-1 bg-white/[0.04] rounded-sm overflow-hidden",children:s.jsx("div",{className:"h-full rounded-sm transition-[width] duration-500",style:{width:`${i}%`,background:c}})})]}):s.jsxs("div",{className:"flex-1",children:[s.jsxs("div",{className:"flex justify-between mb-1.5",children:[s.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:n}),s.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[i,"%"]})]}),s.jsx("div",{className:"h-1.5 bg-white/[0.04] rounded-sm overflow-hidden",children:s.jsx("div",{className:"h-full rounded-sm transition-[width] duration-[600ms]",style:{width:`${i}%`,background:`linear-gradient(90deg, ${c}, ${c}cc)`}})}),a&&s.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:a})]})}function Cb({cursorPos:e,viewportRef:t,imgRef:n}){var b;if(!e||!n.current)return null;const r=n.current,a=r.getBoundingClientRect(),o=(b=t.current)==null?void 0:b.getBoundingClientRect();if(!o)return null;const i=r.naturalWidth||a.width,c=r.naturalHeight||a.height,u=i/c,p=a.width/a.height;let d,m,f,g;u>p?(d=a.width,m=a.width/u,f=0,g=(a.height-m)/2):(m=a.height,d=a.height*u,f=(a.width-d)/2,g=0);const w=a.left-o.left+f+d*e.nx,h=a.top-o.top+g+m*e.ny,x=Math.max(8,Math.min(o.width-8,w)),k=Math.max(8,Math.min(o.height-8,h));return s.jsxs("div",{style:{position:"absolute",left:x-8,top:k-8,width:16,height:16,pointerEvents:"none",zIndex:100},children:[s.jsx("div",{style:{position:"absolute",left:7,top:0,width:2,height:16,background:"rgba(59,130,246,0.8)"}}),s.jsx("div",{style:{position:"absolute",left:0,top:7,width:16,height:2,background:"rgba(59,130,246,0.8)"}}),s.jsx("div",{style:{position:"absolute",left:5,top:5,width:6,height:6,borderRadius:"50%",background:"#3b82f6",boxShadow:"0 0 8px rgba(59,130,246,0.6)"}})]})}function jb({inputMode:e,onToggleInputMode:t,isImeOpen:n,setIsImeOpen:r,isMenuOpen:a,setIsMenuOpen:o,imeText:i,setImeText:c,handleImeSubmit:u,isConnActive:p,zoom:d,isMobile:m,mobileFillZoom:f,onZoomOut:g,onZoomReset:w,onZoomIn:h,transportType:x,screenshotUsage:k,lastActionStatus:b}){const{t:S}=Ne("common");return s.jsxs(s.Fragment,{children:[s.jsxs("div",{onTouchStart:j=>j.stopPropagation(),className:"absolute bottom-0 left-0 right-0 z-20 flex items-center justify-center gap-1.5 px-3 py-2 bg-black/75 backdrop-blur-xl border-t border-white/[0.08] touch-none",children:[s.jsxs("div",{onClick:t,className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${e==="mouse"?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:[s.jsx("span",{className:"text-sm",children:e==="mouse"?"🖱️":"👆"}),s.jsx("span",{className:`text-[10px] font-bold ${e==="mouse"?"text-blue-400":"text-slate-400"}`,children:S(e==="mouse"?"remote.mouse":"remote.touch")})]}),s.jsxs("div",{className:"relative",children:[s.jsx("div",{onClick:()=>{r(j=>!j),o(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${n?"bg-emerald-500/25 border border-emerald-500/40":"bg-white/[0.08] border border-white/10"}`,children:s.jsx("span",{className:"text-sm",children:"⌨️"})}),n&&s.jsx("div",{className:"absolute bottom-10 left-1/2 -translate-x-1/2 w-[220px] bg-neutral-950/[0.98] backdrop-blur-[30px] rounded-xl border border-white/20 p-[10px_12px] shadow-[0_10px_30px_rgba(0,0,0,0.8)] flex flex-col gap-2 z-20",style:{animation:"slideUp 0.15s ease-out"},children:s.jsx("input",{type:"text",placeholder:S("remote.typeAndEnter"),value:i,autoFocus:!0,onTouchStart:j=>j.stopPropagation(),onChange:j=>c(j.target.value),onKeyDown:j=>{u(j)},className:"w-full bg-black/60 border border-white/15 rounded-lg px-2.5 py-2 text-white text-[13px] outline-none"})})]}),s.jsx("div",{className:"relative",children:s.jsx("div",{onClick:()=>{o(j=>!j),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${a?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:s.jsx("span",{className:"text-sm",children:"⚙️"})})}),s.jsx("div",{className:"w-px h-[18px] bg-white/10"}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:p?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[s.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:p?"#22c55e":"#eab308",boxShadow:p?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),s.jsx("span",{className:"text-[8px] font-extrabold",style:{color:p?"#22c55e":"#eab308"},children:S(p?"remote.connected":"remote.ws")})]}),d>1&&s.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(d*100),"%"]}),x==="direct"&&s.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#22c55e",background:"rgba(34,197,94,0.12)"},title:S("remote.directP2PTitle"),children:S("remote.direct")}),x==="relay"&&s.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 12%, transparent)"},title:S("remote.turnRelayTitle"),children:S("remote.relay")}),k&&k.dailyBudgetMinutes>0&&s.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:k.budgetExhausted?"#ef4444":"#c4b5fd",background:k.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:S("remote.dailyTurnTitle"),children:k.budgetExhausted?S("remote.turnBlocked"):S("remote.turnUsage",{used:k.dailyUsedMinutes,budget:k.dailyBudgetMinutes})}),b&&s.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:b})]})]}),a&&s.jsxs("div",{onTouchStart:j=>j.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[s.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:S("remote.settings")}),s.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[s.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:[S("remote.zoom")," ",d<=(m?f:1)+.01?S(m?"remote.fill":"remote.fit"):`${Math.round(d*100)}%`]}),s.jsxs("div",{style:{display:"flex",gap:4},children:[s.jsx("button",{onClick:j=>{j.stopPropagation(),g()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),s.jsx("button",{onClick:j=>{j.stopPropagation(),w()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:9,fontWeight:800,cursor:"pointer"},children:S(m?"remote.fill":"remote.fit")}),s.jsx("button",{onClick:j=>{j.stopPropagation(),h()},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"+"})]})]})]})]})}function Nb({waitingLabel:e,waitingHint:t,transportType:n}){const{t:r}=Ne("common");return s.jsxs("div",{className:"text-center flex flex-col items-center gap-3 px-6",children:[s.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.35)]",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:s.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),s.jsx("div",{className:"text-white/85 text-[13px] font-semibold tracking-wide",children:e}),s.jsx("div",{className:"text-[11px] text-white/40",children:t}),n==="relay"&&s.jsx("div",{className:"text-[10px] font-medium",style:{color:"var(--status-warning)",opacity:.8},children:r("remote.waitingState.turnRelayActive")})]})}function Ab(){if(typeof window>"u")return!1;try{return window.__ADHDEV_DEBUG_RENDERS__===!0||window.localStorage.getItem("adhdev_debug_renders")==="1"}catch{return window.__ADHDEV_DEBUG_RENDERS__===!0}}function Ol(e){return e==null||typeof e=="number"||typeof e=="boolean"?e:typeof e=="string"?e.length>64?`${e.slice(0,61)}...`:e:Array.isArray(e)?`Array(${e.length})`:typeof e=="object"?"Object":typeof e}function hr(e,t){const n=l.useRef(null),r=l.useRef(0);l.useEffect(()=>{if(!Ab())return;r.current+=1;const a=n.current;if(!a){console.debug(`[render-trace] ${e}#${r.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(t).map(([i,c])=>[i,Ol(c)]))}),n.current=t;return}const o=Object.keys({...a,...t}).filter(i=>!Object.is(a[i],t[i]));o.length>0&&console.debug(`[render-trace] ${e}#${r.current}`,{changed:o,snapshot:Object.fromEntries(o.map(i=>[i,Ol(t[i])]))}),n.current=t})}function Mb({containerRef:e,viewportRef:t,imgRef:n,inputMode:r,setInputMode:a,minZoom:o,zoomRef:i,panXRef:c,panYRef:u,setPanX:p,setPanY:d,setZoom:m,lastWheelTimeRef:f,onAction:g,setLastActionStatus:w,spawnRippleFromNormalized:h,clampPan:x,isMobile:k,mobileFillZoom:b}){const[S,j]=l.useState(null),y=l.useRef(null),v=l.useRef(null),N=l.useRef(null),C=l.useRef(!1),A=l.useRef(null),M=l.useRef(0),T=l.useRef(null),R=l.useRef(1),E=l.useRef({x:0,y:0}),_=l.useRef(!1),z=l.useRef(r),F=l.useRef(g),D=30,O=550,L=18,I=60,$=400,P=12,U=()=>{if(y.current)return;const Y={nx:.5,ny:.5};y.current=Y,j(Y)};return l.useEffect(()=>{z.current=r,r==="mouse"&&U()},[r]),l.useEffect(()=>{F.current=g},[g]),l.useEffect(()=>{const Y=e.current;if(!Y)return;const X=ae=>{if(!n.current)return null;const Ce=n.current.getBoundingClientRect();return!Ce.width||!Ce.height?null:{nx:Math.max(0,Math.min(1,(ae.clientX-Ce.left)/Ce.width)),ny:Math.max(0,Math.min(1,(ae.clientY-Ce.top)/Ce.height))}},de=(ae,Ce)=>{if(!n.current)return{dnx:0,dny:0};const ye=n.current,ke=ye.getBoundingClientRect(),me=ye.naturalWidth||ke.width,q=ye.naturalHeight||ke.height,G=me/q,Z=ke.width/ke.height;let V,fe;return G>Z?(V=ke.width,fe=ke.width/G):(fe=ke.height,V=ke.height*G),{dnx:ae/V,dny:Ce/fe}},ne=(ae,Ce,ye)=>{if(ye<=1.05)return;const ke=-(ae-.5)*100,me=-(Ce-.5)*100,q=x(ke,me,ye);(Math.abs(q.x-c.current)>.1||Math.abs(q.y-u.current)>.1)&&(p(q.x),d(q.y),c.current=q.x,u.current=q.y)},B=ae=>{const Ce=t.current;if(Ce&&ae.target instanceof Node&&Ce.contains(ae.target))ae.preventDefault();else return;if(ae.touches.length===1){const ye=ae.touches[0];v.current={x:ye.clientX,y:ye.clientY,time:Date.now()},N.current={x:ye.clientX,y:ye.clientY},_.current||(C.current=!1),A.current=setTimeout(()=>{if(!C.current&&!_.current)if(C.current=!0,z.current==="mouse"){const ke=y.current||{nx:.5,ny:.5};w("Right Click"),h(ke.nx,ke.ny,"right"),F.current("input_click",{...ke,button:"right"}).catch(()=>{})}else{const ke=X(ye);ke&&(w("Right Click"),h(ke.nx,ke.ny,"right"),F.current("input_click",{...ke,button:"right"}).catch(()=>{}))}},500);return}if(ae.touches.length===2){A.current&&clearTimeout(A.current),C.current=!0,_.current=!0;const ye=ae.touches[1].clientX-ae.touches[0].clientX,ke=ae.touches[1].clientY-ae.touches[0].clientY;T.current=Math.sqrt(ye*ye+ke*ke),R.current=i.current,E.current={x:(ae.touches[0].clientX+ae.touches[1].clientX)/2,y:(ae.touches[0].clientY+ae.touches[1].clientY)/2}}},ie=ae=>{const Ce=t.current;if(Ce&&ae.target instanceof Node&&Ce.contains(ae.target)&&ae.preventDefault(),ae.touches.length===1&&N.current){const ye=ae.touches[0],ke=ye.clientX-N.current.x,me=ye.clientY-N.current.y;if(!C.current&&v.current){const q=ye.clientX-v.current.x,G=ye.clientY-v.current.y;Math.sqrt(q*q+G*G)>8&&(C.current=!0,A.current&&clearTimeout(A.current))}if(C.current)if(z.current==="mouse"){const q=de(ke,me),G=y.current||{nx:.5,ny:.5},Z=Math.max(0,Math.min(1,G.nx+q.dnx)),V=Math.max(0,Math.min(1,G.ny+q.dny));y.current={nx:Z,ny:V},j({nx:Z,ny:V}),w(`Cursor: ${Math.round(Z*100)}%, ${Math.round(V*100)}%`),ne(Z,V,i.current);const fe=Date.now();fe-f.current>=30&&(f.current=fe,F.current("input_mouseMoved",{nx:Z,ny:V}).catch(()=>{}))}else if(i.current>1){const q=t.current;if(q){const G=q.clientWidth,Z=q.clientHeight,V=c.current+ke/G*100,fe=u.current+me/Z*100,Te=x(V,fe,i.current);p(Te.x),d(Te.y),c.current=Te.x,u.current=Te.y}}else{const q=X(ye);if(q){const G=Date.now();G-f.current>=40&&(f.current=G,w("Scroll"),F.current("input_wheel",{nx:q.nx,ny:q.ny,deltaX:Math.round(-ke*2.5),deltaY:Math.round(-me*2.5)}).catch(()=>{}))}}N.current={x:ye.clientX,y:ye.clientY};return}if(ae.touches.length===2&&T.current!==null){const ye=ae.touches[1].clientX-ae.touches[0].clientX,ke=ae.touches[1].clientY-ae.touches[0].clientY,q=Math.sqrt(ye*ye+ke*ke)/T.current,G=(ae.touches[0].clientX+ae.touches[1].clientX)/2,Z=(ae.touches[0].clientY+ae.touches[1].clientY)/2,V=G-E.current.x,fe=Z-E.current.y,Te=Math.abs(q-1)>.03;if(z.current==="mouse"){if(Te){const ce=Math.max(o,Math.min(5,R.current*q));m(ce),i.current=ce}else if(Math.abs(V)>2||Math.abs(fe)>2){const ce=y.current||{nx:.5,ny:.5},H=Date.now();H-f.current>=30&&(f.current=H,w("Scroll"),F.current("input_wheel",{nx:ce.nx,ny:ce.ny,deltaX:Math.round(-V*3),deltaY:Math.round(-fe*3)}).catch(()=>{}))}}else{const ce=Math.max(o,Math.min(5,R.current*q));m(ce),i.current=ce;const H=t.current;if(H&&ce>1){const pe=H.clientWidth,le=H.clientHeight,W=c.current+V/pe*100,be=u.current+fe/le*100,je=x(W,be,ce);p(je.x),d(je.y),c.current=je.x,u.current=je.y}}E.current={x:G,y:Z}}},K=ae=>{var Ce;if(A.current&&clearTimeout(A.current),T.current=null,ae.touches.length===1&&_.current){const ye=ae.touches[0];v.current={x:ye.clientX,y:ye.clientY,time:Date.now()},N.current={x:ye.clientX,y:ye.clientY},C.current=!0;return}if(ae.touches.length===0){if(_.current){_.current=!1,C.current=!1;return}if(ae.changedTouches.length===1){const ye=ae.changedTouches[0],ke=Date.now(),me=ke-(((Ce=v.current)==null?void 0:Ce.time)||0),q=v.current?ye.clientX-v.current.x:0,G=v.current?ye.clientY-v.current.y:0,Z=Math.sqrt(q*q+G*G);if(z.current==="mouse"){if(me<D||me>O||Z>L){C.current=!1;return}const V=y.current||X(ye);V&&(w(`Click: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),h(V.nx,V.ny,"left"),F.current("input_click",{...V}).catch(()=>{}))}else{if(C.current){C.current=!1;return}if(me<I||me>$||Z>P){C.current=!1;return}const V=X(ye);if(!V)return;ke-M.current<300?(w("Double tap"),h(V.nx,V.ny,"double"),F.current("input_click",{...V,clickCount:2}).catch(()=>{}),M.current=0):(w(`Tap: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),h(V.nx,V.ny,"left"),F.current("input_click",{...V}).catch(()=>{}),M.current=ke)}}C.current=!1}};return Y.addEventListener("touchstart",B,{passive:!1}),Y.addEventListener("touchmove",ie,{passive:!1}),Y.addEventListener("touchend",K,{passive:!1}),()=>{Y.removeEventListener("touchstart",B),Y.removeEventListener("touchmove",ie),Y.removeEventListener("touchend",K),A.current&&clearTimeout(A.current)}},[e,t,n,o,i,c,u,p,d,m,f,w,h,x]),{cursorPos:S,cursorPosRef:y,handleToggleInputMode:()=>{a(Y=>{const X=Y==="touch"?"mouse":"touch";return X==="mouse"&&U(),X})},handleZoomReset:()=>{const Y=k?b:1;m(Y),i.current=Y,p(0),d(0),c.current=0,u.current=0}}}function pu({onAction:e,addLog:t,connState:n,connScreenshot:r,screenshotUsage:a,transportType:o}){const i=l.useRef(null),c=l.useRef(null),u=l.useRef(null),[p,d]=l.useState(null),[m,f]=l.useState(""),[,g]=l.useState(!1),[w,h]=l.useState([]),x=l.useRef(0),[k,b]=l.useState(!1),[S,j]=l.useState(!1),y=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[v,N]=l.useState(y?"mouse":"touch"),[C,A]=l.useState(1),M=l.useRef(!1),[T,R]=l.useState(1),[E,_]=l.useState(0),[z,F]=l.useState(0);hr("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:v,zoom:T,panX:E,panY:z,isMenuOpen:k,isImeOpen:S});const D=l.useRef(0),O=l.useRef(T),L=l.useRef(E),I=l.useRef(z);l.useEffect(()=>{O.current=T},[T]),l.useEffect(()=>{L.current=E},[E]),l.useEffect(()=>{I.current=z},[z]),l.useEffect(()=>{var me;(me=i.current)==null||me.focus()},[]);const $=n==="connected",P=r,U=$?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",J=$?"The remote stream is warming up":"Waiting for the remote stream to catch up";l.useEffect(()=>{if(!y||M.current||!P)return;const me=u.current,q=c.current;if(!me||!q)return;const G=()=>{const Z=q.clientWidth,V=q.clientHeight,fe=me.naturalWidth,Te=me.naturalHeight;if(!fe||!Te||!Z||!V)return;const ce=Math.min(Z/fe,V/Te),pe=Math.max(Z/fe,V/Te)/ce;pe>1.01&&(A(pe),R(pe),O.current=pe),M.current=!0};me.complete&&me.naturalWidth?G():me.addEventListener("load",G,{once:!0})},[P,y]);const re=.5;l.useEffect(()=>{T<=re&&(_(0),F(0))},[T,re]);const Y=(me,q,G)=>{if(G<=re)return{x:0,y:0};const Z=(G-1)/(2*G)*100,V=(G-1)/(2*G)*100;return{x:Math.max(-Z,Math.min(Z,me)),y:Math.max(-V,Math.min(V,q))}},X=(me,q)=>{if(!u.current)return null;const G=u.current.getBoundingClientRect();return!G.width||!G.height?null:{nx:Math.max(0,Math.min(1,(me-G.left)/G.width)),ny:Math.max(0,Math.min(1,(q-G.top)/G.height))}},de=(me,q,G)=>{const Z=c.current;if(!Z)return;const V=Z.getBoundingClientRect(),fe=++x.current;h(Te=>[...Te,{id:fe,x:me-V.left,y:q-V.top,type:G}]),setTimeout(()=>h(Te=>Te.filter(ce=>ce.id!==fe)),600)},ne=(me,q,G)=>{const Z=u.current,V=c.current;if(!Z||!V)return;const fe=Z.getBoundingClientRect(),Te=V.getBoundingClientRect(),ce=Z.naturalWidth||fe.width,H=Z.naturalHeight||fe.height,pe=ce/H,le=fe.width/fe.height;let W,be,je,Se;pe>le?(W=fe.width,be=fe.width/pe,je=0,Se=(fe.height-be)/2):(be=fe.height,W=fe.height*pe,je=(fe.width-W)/2,Se=0);const He=fe.left-Te.left+je+W*me,Xe=fe.top-Te.top+Se+be*q,dt=++x.current;h(it=>[...it,{id:dt,x:He,y:Xe,type:G}]),setTimeout(()=>h(it=>it.filter(he=>he.id!==dt)),600)},B=async me=>{var G;const q=X(me.clientX,me.clientY);if(q){d(`Click: ${Math.round(q.nx*100)}%, ${Math.round(q.ny*100)}%`),de(me.clientX,me.clientY,"left"),(G=i.current)==null||G.focus();try{const Z=await e("input_click",{nx:q.nx,ny:q.ny});Z!=null&&Z.success||t(`❌ Click failed: ${Z==null?void 0:Z.error}`)}catch(Z){t(`❌ Click error: ${Z.message||Z}`)}}},ie=async(me,q,G,Z=0)=>{try{await e("input_key",{type:G?"char":"keyDown",key:me,code:q,text:G?me:void 0,unmodifiedText:G?me:void 0,modifiers:Z})}catch(V){t(`❌ Key error: ${V.message||V}`)}},K=async me=>{if(me.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(me.key)&&me.preventDefault();let G=0;me.altKey&&(G|=1),me.ctrlKey&&(G|=2),me.metaKey&&(G|=4),me.shiftKey&&(G|=8),d(`Key: ${me.key}`),await ie(me.key,me.code,me.key.length===1,G)},ae=async me=>{if(me.key==="Enter"){if(me.nativeEvent.isComposing)return;if(m){const q=m;f(""),d(`IME Sent: ${q}`);try{const G=await e("input_type",{text:q});G!=null&&G.success||t(`❌ IME error: ${G==null?void 0:G.error}`)}catch(G){t(`❌ IME error: ${G.message}`)}}else d("Key: Enter"),await ie("Enter","Enter",!1)}};l.useEffect(()=>{const me=i.current;if(!me)return;const q=G=>{var Z;if((Z=u.current)!=null&&Z.contains(G.target)){G.preventDefault();const V=Date.now();if(V-D.current<40)return;D.current=V;const fe=X(G.clientX,G.clientY);if(!fe)return;d(`Scroll: ${Math.round(G.deltaY)}`),e("input_wheel",{nx:fe.nx,ny:fe.ny,deltaX:Math.round(G.deltaX),deltaY:Math.round(G.deltaY)}).catch(()=>{})}};return me.addEventListener("wheel",q,{passive:!1}),()=>me.removeEventListener("wheel",q)},[e]);const{cursorPos:Ce,handleToggleInputMode:ye,handleZoomReset:ke}=Mb({containerRef:i,viewportRef:c,imgRef:u,inputMode:v,setInputMode:N,minZoom:re,zoomRef:O,panXRef:L,panYRef:I,setPanX:_,setPanY:F,setZoom:R,lastWheelTimeRef:D,onAction:e,setLastActionStatus:d,spawnRippleFromNormalized:ne,clampPan:Y,isMobile:y,mobileFillZoom:C});return s.jsxs("div",{ref:i,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:K,onContextMenu:me=>me.preventDefault(),onFocus:()=>g(!0),onBlur:()=>g(!1),tabIndex:0,children:[s.jsxs("div",{ref:c,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[P?s.jsx("img",{ref:u,src:P,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${T}) translate(${E}%, ${z}%)`,transformOrigin:"center center",cursor:v==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:B,onContextMenu:me=>me.preventDefault(),onDragStart:me=>me.preventDefault()}):s.jsx(Nb,{waitingLabel:U,waitingHint:J,transportType:o}),v==="mouse"&&P&&s.jsx(Cb,{cursorPos:Ce,viewportRef:c,imgRef:u}),w.map(me=>{const G={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[me.type];return s.jsxs("div",{style:{position:"absolute",left:me.x,top:me.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[s.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${G}, 0.8)`,animation:"click-ripple-ring 0.5s ease-out forwards",position:"absolute",left:-20,top:-20}}),s.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:`rgba(${G}, 0.9)`,boxShadow:`0 0 12px rgba(${G}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},me.id)})]}),s.jsx(jb,{inputMode:v,onToggleInputMode:ye,isImeOpen:S,setIsImeOpen:j,isMenuOpen:k,setIsMenuOpen:b,imeText:m,setImeText:f,handleImeSubmit:ae,isConnActive:$,zoom:T,isMobile:y,mobileFillZoom:C,onZoomOut:()=>R(me=>Math.max(.5,me-.25)),onZoomReset:ke,onZoomIn:()=>R(me=>Math.min(5,me+.25)),transportType:o,screenshotUsage:a,lastActionStatus:p}),s.jsx("style",{children:`
9
9
  @keyframes slideUp {
10
10
  from { opacity: 0; transform: translateY(6px); }
11
11
  to { opacity: 1; transform: translateY(0); }
@@ -1,4 +1,4 @@
1
- import{r as Z,j as ui}from"./vendor-cL4V2vaO.js";/**
1
+ import{r as Z,j as ui}from"./vendor-DyCWA2YZ.js";/**
2
2
  * Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
3
3
  * @license MIT
4
4
  *