@adhdev/daemon-standalone 1.0.2 → 1.0.3-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.2",
3
+ "version": "1.0.3-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.3-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 yh=Object.defineProperty;var wh=(e,t,n)=>t in e?yh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var st=(e,t,n)=>wh(e,typeof t!="symbol"?t+"":t,n);import{r as l,j as s,u as Ne,M as ki,a as kh,b as Sh,c as Ch,t as jh,d as Nh,i as wt,e as Ah,f as bn,R as Rt,T as Bo,g as hr,h as Fo,k as Oo,D as Ih,E as Th,l as Mh,C as Ph,m as Dh,B as Lh,n as Rh,o as Eh,p as _h,H as wr,P as Cs,q as $h,s as Hh,v as Bh,w as Cl,x as Fh,y as Oh,z as Si,A as Wh,F as Uh,G as Gh,I as qh,J as js,N as Wo,K as zh}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 Kh(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 gn=Kh();function jl(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 Vh(e,t){return typeof e=="string"&&e.trim().length>0&&e!==t}function Nl(e){return Array.isArray(e)?[...e]:[]}function Rd(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?Nl(e.messages):i?[]:t.messages,activeModal:r?e.activeModal??null:t.activeModal,inputContent:e.inputContent??t.inputContent}:{...e,...n?{messages:Nl(e.messages)}:{},...r?{activeModal:e.activeModal??null}:{}}}function Kn(e,t){const n=Vh(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:Rd(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 Ed(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?Kn(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 Al(e){return!!e&&typeof e=="object"&&"text"in e}function Ci(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:Al(o)?String(o.text||""):"").join(n):Al(e)?a=String(e.text||""):a=String(e||""),r?a.replace(/\s+/g," ").trim():a}function xn(e){return Ci(e,{normalizeWhitespace:!0})}function Yh(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 yh=Object.defineProperty;var wh=(e,t,n)=>t in e?yh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var st=(e,t,n)=>wh(e,typeof t!="symbol"?t+"":t,n);import{r as l,j as s,u as Ne,M as ki,a as kh,b as Sh,c as Ch,t as jh,d as Nh,i as wt,e as Ah,f as bn,R as Rt,T as Bo,g as hr,h as Fo,k as Oo,D as Ih,E as Th,l as Mh,C as Ph,m as Dh,B as Lh,n as Rh,o as Eh,p as _h,H as wr,P as Cs,q as $h,s as Hh,v as Bh,w as Cl,x as Fh,y as Oh,z as Si,A as Wh,F as Uh,G as Gh,I as qh,J as js,N as Wo,K as zh}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 Kh(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 gn=Kh();function jl(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 Vh(e,t){return typeof e=="string"&&e.trim().length>0&&e!==t}function Nl(e){return Array.isArray(e)?[...e]:[]}function Rd(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?Nl(e.messages):i?[]:t.messages,activeModal:r?e.activeModal??null:t.activeModal,inputContent:e.inputContent??t.inputContent}:{...e,...n?{messages:Nl(e.messages)}:{},...r?{activeModal:e.activeModal??null}:{}}}function Kn(e,t){const n=Vh(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:Rd(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 Ed(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?Kn(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 Al(e){return!!e&&typeof e=="object"&&"text"in e}function Ci(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:Al(o)?String(o.text||""):"").join(n):Al(e)?a=String(e.text||""):a=String(e||""),r?a.replace(/\s+/g," ").trim():a}function xn(e){return Ci(e,{normalizeWhitespace:!0})}function Yh(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 Il(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 _d(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,d=t.versionUpdateReason??e.versionUpdateReason??n.versionUpdateReason;return a&&(r.version=a),o&&(r.serverVersion=o),d&&(r.versionUpdateReason=d),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 Jh(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=Jh(xn(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 Qh(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 Uo(e){return!!e&&typeof e=="object"&&"messages"in e&&("activeModal"in e||"inputContent"in e||"status"in e)}function Go(e,t,n){if(!e||!t||typeof e!="object"||typeof t!="object")return;if(Uo(e)&&Uo(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)Go(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"&&Go(r[i],a[i],n)}function Qn(e,t){return Array.isArray(e)?e.map(n=>Qn(n,t)):!e||typeof e!="object"?e:Uo(e)?Object.fromEntries(Object.entries(e).filter(([r])=>r!=="timestamp"&&r!=="_lastUpdate").sort(([r],[a])=>r.localeCompare(a)).map(([r,a])=>[r,r==="messages"?Qh(a,t):Qn(a,t)])):Object.fromEntries(Object.entries(e).filter(([n])=>n!=="timestamp"&&n!=="_lastUpdate").sort(([n],[r])=>n.localeCompare(r)).map(([n,r])=>[n,Qn(r,t)]))}function Xh(e,t){try{const n=new WeakSet;return Go(e,t,n),JSON.stringify(Qn(e,n))===JSON.stringify(Qn(t,n))}catch{return!1}}function qo(e,t,n){return Xh(e,t)?(e._lastUpdate=n,typeof t.timestamp=="number"&&(e.timestamp=t.timestamp),e):t}function $d(e){var t;return e.daemonId||((t=e.id)==null?void 0:t.split(":")[0])||e.id}function Zh(e,t,n){t[n]!==void 0&&(e[n]=t[n])}function Tl(e,t,n,r){var d;const a=(d=t.chats)!=null&&d.length?t.chats:e.chats,o=Ed(e.childSessions,t.childSessions,{preserveMissing:r}),i=Rd(t.activeChat,e.activeChat),c=t.workspace||e.workspace;return _d(e,t,{...e,...t,chats:a,childSessions:o,activeChat:i,workspace:c,_lastUpdate:n})}function ef(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=Ed(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"])Zh(r,t,i);return t.machineNickname!==void 0&&t.machineNickname!==e.machineNickname&&(r.machineNickname=t.machineNickname),t.versionMismatch===!0&&(r.versionMismatch=!0),r}function tf(e,t,n,r){const a=ef(e,t,r),o=Object.keys(a).length>0?_d(e,t,{...e,...a,_lastUpdate:n}):{...e,_lastUpdate:n};return qo(e,o,n)}function sf(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=$d(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 nf(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 rf(e,t,n,r,a){return e.transport?n.has(t)&&!r.has(t)?!0:a.has(t):!1}function af(e,t,n){var u,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:d,daemonIdsWithAuthoritativeSessionList:p}=sf(e);for(const f of e){const g=o.get(f.id);if(!g){o.set(f.id,{...f,_lastUpdate:r});continue}const C=Il(f),h=Il(g),x=$d(f),y=!a.has(x);if(C>h){const k=Tl(g,f,r,y);o.set(f.id,qo(g,k,r));continue}if(C<h){o.set(f.id,tf(g,f,r,y));continue}const b=f.timestamp||r,S=g._lastUpdate||g.timestamp||0;if(b>=S){const k=Tl(g,f,r,y);o.set(f.id,qo(g,k,r));continue}(u=f.chats)!=null&&u.length&&!((m=g.chats)!=null&&m.length)&&o.set(f.id,{...g,chats:f.chats})}for(const[f,g]of o){const C=g.daemonId||f.split(":")[0];if(!c.has(C))continue;if(a.has(C)&&p.has(C)&&!i.has(f)){o.delete(f);continue}const h=r-(g._lastUpdate||g.timestamp||0);nf(g,C,h,i,a,d)&&o.delete(f)}for(const[f,g]of o){const C=g.daemonId||f.split(":")[0];if(rf(g,C,c,d,o))continue;r-(g._lastUpdate||g.timestamp||0)>3e5&&g.status!=="online"&&o.delete(f)}return Array.from(o.values())}function of(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 Hd=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}),Bd=l.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function lf({children:e,connectionOverrides:t}){const[n,r]=l.useState([]),[a,o]=l.useState(!1),[i,c]=l.useState([]),[d,p]=l.useState(void 0),u=l.useRef(n);l.useEffect(()=>{u.current=n},[n]);const m=l.useCallback((y,b)=>{r(S=>{let k=!1;const w=S.map(v=>v.id!==y||v.chats===b?v:(k=!0,{...v,chats:b}));return k?w:S})},[]),f=l.useCallback((y,b)=>{r(S=>{const k=S.length===0?y:af(y,S,b),w=!of(S,k);return w&&gn.record({kind:"dashboard.entries_applied",payload:{incoming:jl(y),next:jl(k)}}),w?k:S})},[]),g=l.useCallback(()=>o(!0),[]),C=l.useMemo(()=>({injectEntries:f,markLoaded:g,getIdes:()=>u.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:d,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,d]);return s.jsx(Bd.Provider,{value:C,children:s.jsx(Hd.Provider,{value:x,children:e})})}function gs(){return l.useContext(Hd)}function or(){return l.useContext(Bd)}function Fd(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 d=n==null?void 0:n(),p=a(c),u=c.startsWith("http")?new URL(p):new URL(p,typeof window<"u"?window.location.origin:"http://localhost");return d&&u.searchParams.set("token",d),!c.startsWith("http")&&!t?`${u.pathname}${u.search}${u.hash}`:u.toString()}async function i(c,d={}){const p={"Content-Type":"application/json",...d.headers||{}},u=n==null?void 0:n();u&&(p.Authorization=`Bearer ${u}`);const m=a(c),f=new AbortController,g=setTimeout(()=>f.abort(),15e3);try{const C=await fetch(m,{...d,headers:p,signal:f.signal});if(C.status===401)throw r==null||r(),new Error("Unauthorized");if(!C.ok){const h=await C.json().catch(()=>({error:C.statusText}));throw new Error(h.error||`API Error: ${C.status}`)}return C.json()}finally{clearTimeout(g)}}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:c=>i(`/api/v1/daemons/${c}/status`),sendCommand:(c,d,p={})=>i(`/api/v1/daemons/${c}/command`,{method:"POST",body:JSON.stringify({type:d,payload:p})}),execTerminal:(c,d,p)=>i(`/api/v1/daemons/${c}/terminal`,{method:"POST",body:JSON.stringify({command:d,name:p})}),sendAgentMessage:(c,d,p)=>i(`/api/v1/shortcuts/${c}/chat`,{method:"POST",body:JSON.stringify({agentType:d,message:p})}),getAgentStatus:c=>i(`/api/v1/shortcuts/${c}/status`),approveAgent:(c,d,p)=>i(`/api/v1/shortcuts/${c}/approve`,{method:"POST",body:JSON.stringify({agentType:d,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,d,p={})=>i(`/api/v1/mux/${encodeURIComponent(c)}/control`,{method:"POST",body:JSON.stringify({type:d,payload:p})}),getMuxEventsUrl:c=>o(`/api/v1/mux/${encodeURIComponent(c)}/events`),getRuntimeEventsUrl:c=>o(`/api/v1/runtime/${encodeURIComponent(c)}/events`),request:i}}const cf=Fd({baseUrl:"http://localhost:3847"}),df=l.createContext(cf);function uf({client:e,children:t}){return s.jsx(df.Provider,{value:e,children:t})}const pf={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Od=l.createContext(pf);function mf({value:e,children:t}){return s.jsx(Od.Provider,{value:e,children:t})}function vt(){return l.useContext(Od)}function Wd(e){return e&&typeof e=="object"&&e.result&&typeof e.result=="object"?e.result:e}function hf(e){const t=Wd(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 ff(e){const[t,n]=l.useState(null),r=l.useCallback(async(i,c)=>{const d=m=>e(i,"launch_cli",{...c,...m}),p=await d({}),u=hf(p);return u?new Promise(m=>{n({providerType:u.providerType||String(c.cliType??"?"),sourceName:u.sourceName,description:u.description,retry:()=>d({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(),d=Wd(c);d!=null&&d.success?i.resolve({ok:!0,response:c}):i.resolve({ok:!1,error:(d==null?void 0:d.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 bf({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=d=>{d.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 Ud=l.createContext(null);function gf({sendDaemonCommand:e,children:t}){const n=ff(e),r=l.useMemo(()=>({launchCli:n.launchCli}),[n.launchCli]);return s.jsxs(Ud.Provider,{value:r,children:[t,n.pending&&s.jsx(bf,{providerType:n.pending.providerType,sourceName:n.pending.sourceName,description:n.pending.description,onConfirm:n.confirm,onCancel:n.cancel})]})}function ka(){const e=l.useContext(Ud);return e||{launchCli:async()=>{throw new Error("useLaunchCli must be used inside <LaunchCliProvider>")}}}function Gd(e){return e?new Date(e).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function xf(e,t,n){return Number(e.receivedAt||n[sa(e)]||0)||0}function qd(e){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(e)}function vf(e){return Array.isArray(e)&&e.some(t=>!!t&&typeof t=="object"&&"type"in t)}function Ln(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 yf(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=Ci(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:${yf(r)}`,o?`ts:${o}`:""].filter(Boolean).join("|")}function wf(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 kf(e){try{return JSON.stringify(e??"")}catch{return String(e??"")}}function zd(e){return e?wf([String(e.id||""),String(e.index??""),String(e.role||""),String(e.receivedAt??e.timestamp??""),kf(e.content)]):""}const ji=200,Sf=80,Ml=650,Rn=new Map;function na(e,t){if(!e)return!1;const n=String(e.messageFingerprint||"");return n?n===String(t||""):!0}function Cf(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}:${zd(r)}`}function jf(e,t,n,r){return e||!t?!1:na(n,r)}function Nf({scrollTop:e,scrollHeight:t,clientHeight:n,topThresholdPx:r=Sf,bottomThresholdPx:a=ji}){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 Af(e){return Nf({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight})}function Vn(e,t=ji){return!!e&&e.fromBottom>=t}function If(e,t){return na(e,t)?!Vn(e):!0}function Tf({hasSelection:e,userScrolledUp:t,hasChatContentChanged:n=!0}){return!(e||t||!n)}function Mf({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 Kd({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 Ni({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 Vd({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 Pf({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 Df({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 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("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 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 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 Qd({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 Ai({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 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("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 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:"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 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:"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 vn({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 ir({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 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("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 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:"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 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:"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 Zd({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 _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("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 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("polyline",{points:"4 17 10 11 4 5"}),s.jsx("line",{x1:"12",y1:"19",x2:"20",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("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),s.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"})]})}function eu({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 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("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 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("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 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("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 Ff({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 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:"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 An({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 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("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 Wf({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 Uf({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 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("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 su({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 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("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})})}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("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 Kf({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 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("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 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("polyline",{points:"9 14 4 9 9 4"}),s.jsx("path",{d:"M20 20v-7a4 4 0 0 0-4-4H4"})]})}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:"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 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("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 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:"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 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("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 nu="adhdev_chat_activity_visible",Pl=new Set(["hidden","debug","internal"]),Dl=new Set(["visible","user","chat"]),eb=new Set(["debug","trace","internal"]),tb=new Set(["tool_call","terminal_command","runtime_activity"]),sb=new Set(["runtime_status","provider_chrome","control"]),nb=new Set(["thought","tool","terminal"]);function ru(e){const t=e.meta;return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function an(e){return typeof e=="string"?e.trim().toLowerCase():""}function za(e,t,n){return e[n]??(t==null?void 0:t[n])}function Ll(e,t,n){const r=e;return n.some(a=>r[a]===!0||(t==null?void 0:t[a])===!0)}function rb(e,t){const n=an(e.kind);return n||(t==="tool"?"tool":"standard")}function Ka(e,t,n){const r=ru(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 ab(e){const t=e.content;return Array.isArray(t)&&t.some(n=>!!n&&typeof n=="object"&&n.type!=="text")}function Di(e){if(!e)return{surface:"internal",isUserFacing:!1,isActivityFacing:!1,isInternal:!0,role:"",kind:"standard",label:"Internal"};const t=ru(e),n=an(e.role),r=rb(e,n),a=an(za(e,t,"visibility")),o=an(e.transcriptVisibility??(t==null?void 0:t.transcriptVisibility)??a),i=an(za(e,t,"audience")),c=an(za(e,t,"source")),d=Pl.has(a)||Pl.has(o)||eb.has(i)||Ll(e,t,["internal","isInternal","debug","statusOnly","controlOnly"]),p=Dl.has(a)||Dl.has(o)||i==="chat"||Ll(e,t,["userFacing"]),u=nb.has(r)||tb.has(c);if(d)return{surface:u?"activity":"internal",isUserFacing:!1,isActivityFacing:u,isInternal:!u,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")&&ab(e))return{surface:"chat",isUserFacing:!0,isActivityFacing:!1,isInternal:!1,role:n,kind:r,label:"Chat"};if(sb.has(c)||n==="system"||r==="system")return{surface:"internal",isUserFacing:!1,isActivityFacing:!1,isInternal:!0,role:n,kind:r,label:"Internal"};if(u)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 ob(e){return(Array.isArray(e)?e:[]).filter(t=>Di(t).isUserFacing)}function au(e){return(Array.isArray(e)?e:[]).filter(t=>Di(t).isActivityFacing)}function ou(e){const t=e.content;return typeof t=="string"?t:(()=>{try{return JSON.stringify(t??"")}catch{return String(t??"")}})()}function ib(e){return`${String(e.role||"")}::${ou(e)}`}function lb(e){if(e.length<2)return e;const t=[];let n="";for(const r of e){const a=ib(r);ou(r).trim().length>0&&a===n||(t.push(r),n=a)}return t}function cb(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,d=Number(a.index??0)||0;return c-d})}function Rl(e=typeof localStorage<"u"?localStorage:void 0){try{return(e==null?void 0:e.getItem(nu))==="1"}catch{return!1}}function db({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(Qd,{size:11}):s.jsx(Jd,{size:11})})}const iu=[kh,{singleTilde:!1}],lu=[iu,Sh,Ch],ub=[iu];function kr(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 El(e,t){return e?t?s.jsx("pre",{className:"chat-preformatted",children:e}):qd(e)?s.jsx(ki,{remarkPlugins:lu,children:e}):s.jsx("div",{style:{whiteSpace:"pre-wrap"},children:e}):null}const pb=l.memo(function({content:t,renderAsPreformatted:n,renderAsMarkdown:r}){return n?s.jsx("pre",{className:"chat-preformatted",children:t}):r?s.jsx(ki,{remarkPlugins:lu,children:t}):s.jsx("div",{style:{whiteSpace:"pre-wrap"},children:t})});function En({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:El(String(n.text||""),t)},`text-${r}`);if(n.type==="image"){const a=Ga(n),o=n.alt||n.description||Ln(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:kr("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:kr("Audio",Ln(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||Ln(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"}):kr("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||Ln(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}):kr("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=Ln(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}),El(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 mb=l.memo(function({log:t}){return s.jsxs("div",{className:"self-center chat-msg-action",children:[s.jsx(ki,{remarkPlugins:ub,children:t.text}),s.jsx("span",{className:"action-time",children:Gd(t.timestamp)})]})},(e,t)=>e.log===t.log);function _l(e){const t=e.meta;return[zd(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 hb=l.memo(function({message:t,receivedAt:n,agentName:r,userName:a,isCliMode:o,isTextExpanded:i,onToggleTextExpanded:c}){var j,A,I;const d=(t.role||"").toLowerCase(),p=d==="user"||d==="human",u=t.kind||(d==="tool"?"tool":"standard"),m=Di(t),f=vf(t.content)?t.content:null,g=!!(f!=null&&f.some(M=>M.type!=="text")),C=Ci(t.content,{joiner:`
8
- `});if(m.isActivityFacing&&u!=="thought"&&u!=="tool"&&u!=="terminal"){const M=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:M})]}),g&&f?s.jsx("div",{className:"chat-msg-activity-body",children:s.jsx(En,{parts:f,renderAsPreformatted:!1})}):s.jsx("div",{className:"chat-msg-activity-body",style:{whiteSpace:"pre-wrap"},children:C})]})}if(u==="thought"){const M=typeof((j=t.meta)==null?void 0:j.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(Ff,{size:13}),s.jsx("span",{children:M})]}),s.jsx("div",{className:"chat-msg-body",children:C})]})}if(u==="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(En,{parts:f,renderAsPreformatted:!1})}):s.jsx("div",{className:"tool-text w-full",style:{whiteSpace:"pre-wrap"},children:C})]});if(u==="terminal"){const M=(A=t.meta)!=null&&A.isRunning?"⏳":"✅",D=typeof((I=t.meta)==null?void 0:I.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:M}),s.jsx("span",{children:D})]}),g&&f?s.jsx("div",{className:"chat-msg-body",children:s.jsx(En,{parts:f,renderAsPreformatted:!0})}):s.jsx("pre",{className:"chat-msg-body",children:C})]})}if(u==="system")return s.jsx("div",{className:"self-center chat-msg-system",children:g&&f?s.jsx(En,{parts:f,renderAsPreformatted:!1}):C.slice(0,100)});const h=t.meta,y=(typeof(h==null?void 0:h.renderMode)=="string"?h.renderMode.trim():"")==="preformatted",b=C,S=!1,k=b,w=y,v=!p&&!w&&qd(k),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(db,{text:C}),n!=null&&s.jsx("span",{className:"chat-time",children:Gd(n)})]})]}),(b||g)&&s.jsx("div",{className:"chat-markdown",children:g&&f?s.jsx(En,{parts:f,renderAsPreformatted:w}):s.jsx(pb,{content:k,renderAsPreformatted:w,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),fb=l.forwardRef(function({messages:t,actionLogs:n,agentName:r="Agent",userName:a,isCliMode:o=!1,isWorking:i=!1,contextKey:c="",receivedAtMap:d={},lastMessageHash:p,showActivityMessages:u=!1,emptyState:m,onLoadMore:f,isLoadingMore:g,hasMoreHistory:C,hiddenLiveCount:h=0,loadError:x,scrollToBottomRequestNonce:y,isVisible:b=!0},S){const{t:k}=Ne("common"),w=l.useRef(null),v=l.useRef(null),N=l.useRef(null),j=l.useRef(0),A=l.useRef(""),I=l.useRef(""),M=l.useRef(!1),D=l.useRef(null),L=l.useRef(!1),_=l.useRef(null),q=l.useRef(!1),[B,E]=l.useState(new Set),[K,R]=l.useState({showTop:!1,showBottom:!1}),T=l.useRef(!1),H=l.useRef(!1),P=l.useRef(b),W=l.useRef(b),J=l.useRef(null);W.current=b;const re=()=>{const ce=w.current;return ce?ce.scrollHeight-ce.scrollTop-ce.clientHeight<ji:!0},V=l.useCallback(()=>{const ce=w.current,$=ce?Af(ce):{showTop:!1,showBottom:!1};R(pe=>pe.showTop===$.showTop&&pe.showBottom===$.showBottom?pe:$)},[]),X=l.useCallback((ce="auto")=>{var pe;const $=w.current;$&&($.scrollTo({top:$.scrollHeight,behavior:ce}),(pe=$.ownerDocument.defaultView)==null||pe.requestAnimationFrame(()=>V()))},[V]),de=l.useCallback((ce="auto")=>{var pe;const $=w.current;$&&($.scrollTo({top:0,behavior:ce}),(pe=$.ownerDocument.defaultView)==null||pe.requestAnimationFrame(()=>V()))},[V]),ne=l.useCallback(()=>{var F;const ce=w.current,$=(F=window.getSelection)==null?void 0:F.call(window);if(!ce||!$||$.rangeCount===0||$.isCollapsed){q.current=!1;return}const pe=$.anchorNode,le=$.focusNode;q.current=!!(pe&&le&&ce.contains(pe)&&ce.contains(le))},[]),O=l.useMemo(()=>{const ce=ob(t),$=au(t);return lb(cb(ce,$,u))},[t,u]),ie=O.length===t.length?p:void 0,z=Cf(O,ie),ae=l.useCallback(()=>{const ce=w.current;if(!ce||!c||!W.current)return;const $={top:ce.scrollTop,fromBottom:Math.max(0,ce.scrollHeight-ce.scrollTop-ce.clientHeight),messageFingerprint:z};J.current={contextKey:c,snapshot:$},Rn.set(c,$)},[c,z]),Ce=l.useCallback((ce="auto")=>{D.current!=null&&cancelAnimationFrame(D.current),D.current=requestAnimationFrame(()=>{D.current=null,X(ce)})},[X]),ye=l.useCallback(()=>{T.current=!1,L.current=!0,H.current=!0,_.current!=null&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>{L.current=!1,_.current=null},Ml)},[]);l.useEffect(()=>{const ce=!M.current,$=I.current!==c;if(I.current=c,ce||$){M.current=!0;const le=c?Rn.get(c):null,F=!!le&&na(le,z);T.current=F?Vn(le):!1,L.current=If(le,z),q.current||(F?requestAnimationFrame(()=>{const be=w.current;be&&(qa(be,le),T.current=Vn(le),V(),H.current=!0)}):Ce("auto")),j.current=O.length,A.current=z;return}O.length>j.current;const pe=z!==A.current;Tf({hasSelection:q.current,userScrolledUp:T.current,hasChatContentChanged:pe})&&Ce("auto"),j.current=O.length,A.current=z},[z,c,O.length,Ce,V]),l.useEffect(()=>{y&&(ye(),q.current||Ce("auto"))},[ye,Ce,y]),l.useEffect(()=>{const ce=P.current;ce&&!b&&ae(),W.current=b,P.current=b;const $=c?Rn.get(c):null;if(jf(ce,b,$,z)){if(!$)return;T.current=Vn($),L.current=!1,q.current||requestAnimationFrame(()=>{const pe=w.current;pe&&(qa(pe,$),V())});return}},[b,c,z,ye,ae,Ce,V]),l.useEffect(()=>()=>{const ce=J.current;ce&&Rn.set(ce.contextKey,ce.snapshot),D.current!=null&&cancelAnimationFrame(D.current),_.current!=null&&window.clearTimeout(_.current)},[]),l.useEffect(()=>{const ce=v.current,$=w.current;if(!ce||!$)return;const pe=()=>{_.current!=null&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>{L.current=!1,_.current=null},Ml)},le=new ResizeObserver(()=>{V();const F=L.current;Mf({hasSelection:q.current,userScrolledUp:T.current,contextAutoScrollActive:F})&&(Ce("auto"),F&&pe())});return le.observe(ce),$!==ce&&le.observe($),()=>{le.disconnect(),_.current!=null&&(window.clearTimeout(_.current),_.current=null)}},[Ce,c,V]),l.useImperativeHandle(S,()=>({scrollToBottom:(ce="smooth")=>{X(ce)}}),[X]),l.useEffect(()=>{const ce=w.current;if(!ce)return;let $;const pe=()=>{ae(),clearTimeout($),$=setTimeout(()=>{T.current=!re(),V()},50)};return ce.addEventListener("scroll",pe,{passive:!0}),()=>{ce.removeEventListener("scroll",pe),clearTimeout($)}},[ae,V]),l.useEffect(()=>(document.addEventListener("selectionchange",ne),()=>document.removeEventListener("selectionchange",ne)),[ne]);const ke=l.useRef(0),me=l.useRef(!1);l.useEffect(()=>{const ce=w.current;if(!ce||!me.current||ke.current===0)return;const $=ce.scrollHeight-ke.current;$>0&&(ce.scrollTop=$),V(),ae(),ke.current=0,me.current=!1},[O.length,ae,V]),l.useEffect(()=>{if(H.current||!c)return;const ce=Rn.get(c),$=w.current;if(!(!ce||!$)){if(!na(ce,z)){X("auto"),H.current=!0;return}qa($,ce),T.current=Vn(ce),V(),H.current=!0}},[c,z,O.length,X,V]);const G=()=>{const ce=w.current;ce&&(ke.current=ce.scrollHeight),me.current=!0,f==null||f()},U=()=>{T.current=!0,de("smooth"),ae()},Z=()=>{ye(),X("smooth"),ae()},Y=l.useMemo(()=>{const ce=O.map((F,be)=>({type:"message",data:F,index:be,ts:xf(F,be,d)}));if(!n||n.length===0)return ce;const $=[...n].sort((F,be)=>F.timestamp-be.timestamp).map((F,be)=>({type:"action",data:F,index:be,ts:F.timestamp})),pe=[];let le=0;for(const F of ce){for(;le<$.length&&F.ts>0&&$[le].ts<F.ts;)pe.push($[le++]);pe.push(F)}for(;le<$.length;)pe.push($[le++]);return pe},[O,n,d]),fe=h>0||!!C,Te=h>0?h>80?k("chatList.showEarlierMessagesHidden",{count:Math.min(h,80),total:h}):k("chatList.showEarlierMessages",{count:Math.min(h,80)}):x?k("chatList.loadErrorRetry",{error:x}):k("chatList.loadOlderMessages");return s.jsxs("div",{className:"chat-scroll-frame",children:[s.jsx("div",{ref:w,"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:k("chatList.loadingOlderMessages")}),fe&&!g&&s.jsx("div",{className:"text-center py-2",children:s.jsx("button",{type:"button",onClick:G,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})}),Y.length===0&&!fe&&(m||s.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:k("chatList.waitingForMessages")})),Y.map(ce=>{if(ce.type==="action"){const je=ce.data;return s.jsx(mb,{log:je},`action-${ce.index}`)}const $=ce.data;ce.index;const pe=sa($),le=$.receivedAt||d[pe],F=`${c}-${pe}`,be=B.has(F);return s.jsx(hb,{message:$,receivedAt:le,agentName:r,userName:a,isCliMode:o,isTextExpanded:be,onToggleTextExpanded:()=>E(je=>{const Se=new Set(je);return be?Se.delete(F):Se.add(F),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:k("chatList.agentGenerating")})]})}),s.jsx("div",{className:"min-h-10",ref:N})]})}),(K.showTop||K.showBottom)&&s.jsxs("div",{className:"chat-scroll-jump-controls","aria-label":k("chatList.jumpToTop"),children:[K.showTop&&s.jsx("button",{type:"button",className:"chat-scroll-jump-button",onClick:U,"aria-label":k("chatList.jumpToOldestMessages"),title:k("chatList.jumpToTop"),children:k("chatList.top")}),K.showBottom&&s.jsx("button",{type:"button",className:"chat-scroll-jump-button chat-scroll-jump-button-primary",onClick:Z,"aria-label":k("chatList.jumpToLatestMessages"),title:k("chatList.jumpToBottom"),children:k("chatList.latest")})]})]})}),bb=l.memo(fb,(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),gb="modulepreload",xb=function(e){return"/"+e},$l={},vb=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(d=>{if(d=xb(d),d in $l)return;$l[d]=!0;const p=d.endsWith(".css"),u=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${u}`))return;const m=document.createElement("link");if(m.rel=p?"stylesheet":gb,p||(m.as="script"),m.crossOrigin="",m.href=d,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 ${d}`)))})}))}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 Hl=!1;const cu=l.forwardRef(({onInput:e,onViewportMetrics:t,onScrollMetrics:n,fontSize:r=13,readOnly:a=!1,sizingMode:o="measured"},i)=>{const c=l.useRef(null),[d,p]=l.useState(null),u=l.useRef([]),m=l.useRef(!1),f=l.useRef(!1),g=l.useRef(!1),C=l.useRef(!1),h=()=>{const x=c.current;if(x){m.current&&(x.clear(),m.current=!1);for(const y of u.current)x.write(y.data,y.onProcessed);u.current=[],f.current&&(x.fit(),f.current=!1),g.current&&(x.bumpResize(),g.current=!1),C.current&&(x.scrollToTop(),C.current=!1)}};return l.useImperativeHandle(i,()=>({write:(x,y)=>{c.current?c.current.write(x,y):u.current.push({data:x,onProcessed:y})},clear:()=>{c.current?c.current.clear():(u.current=[],m.current=!0)},reset:()=>{c.current&&typeof c.current.reset=="function"?c.current.reset():(u.current=[],m.current=!0)},resize:(x,y)=>{c.current&&typeof c.current.resize=="function"&&c.current.resize(x,y)},fit:()=>{c.current?c.current.fit():f.current=!0},bumpResize:()=>{c.current?c.current.bumpResize():g.current=!0},scrollToTop:()=>{c.current?c.current.scrollToTop():C.current=!0},getSelection:()=>{var x,y;return((y=(x=c.current)==null?void 0:x.getSelection)==null?void 0:y.call(x))||""},getVisibleText:()=>{var x,y;return((y=(x=c.current)==null?void 0:x.getVisibleText)==null?void 0:y.call(x))||""}}),[]),l.useEffect(()=>{d&&h()},[d]),l.useEffect(()=>{let x=!1;return vb(()=>import("./terminal-BZj_X5zy.js"),__vite__mapDeps([0,1,2])).then(y=>{Hl||(Hl=!0,console.info("[CliTerminal] renderer module loaded: terminal-render-web")),x||p(()=>y.GhosttyTerminalView)}).catch(y=>{console.error("[CliTerminal] failed to load terminal renderer",y)}),()=>{x=!0}},[]),d?s.jsx(d,{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"}})});cu.displayName="CliTerminal";function Ft(...e){return jh(Nh(e))}const yb={lg:"rounded-lg",xl:"rounded-xl","2xl":"rounded-2xl"},wb={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:Ft("border border-border-subtle bg-bg-secondary",yb[t],wb[n],r),...a})});function Sr({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 kb({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,d=i/c,p=a.width/a.height;let u,m,f,g;d>p?(u=a.width,m=a.width/d,f=0,g=(a.height-m)/2):(m=a.height,u=a.height*d,f=(a.width-u)/2,g=0);const C=a.left-o.left+f+u*e.nx,h=a.top-o.top+g+m*e.ny,x=Math.max(8,Math.min(o.width-8,C)),y=Math.max(8,Math.min(o.height-8,h));return s.jsxs("div",{style:{position:"absolute",left:x-8,top:y-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 Sb({inputMode:e,onToggleInputMode:t,isImeOpen:n,setIsImeOpen:r,isMenuOpen:a,setIsMenuOpen:o,imeText:i,setImeText:c,handleImeSubmit:d,isConnActive:p,zoom:u,isMobile:m,mobileFillZoom:f,onZoomOut:g,onZoomReset:C,onZoomIn:h,transportType:x,screenshotUsage:y,lastActionStatus:b}){const{t:S}=Ne("common");return s.jsxs(s.Fragment,{children:[s.jsxs("div",{onTouchStart:k=>k.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(k=>!k),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:k=>k.stopPropagation(),onChange:k=>c(k.target.value),onKeyDown:k=>{d(k)},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(k=>!k),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")})]}),u>1&&s.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(u*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")}),y&&y.dailyBudgetMinutes>0&&s.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:y.budgetExhausted?"#ef4444":"#c4b5fd",background:y.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:S("remote.dailyTurnTitle"),children:y.budgetExhausted?S("remote.turnBlocked"):S("remote.turnUsage",{used:y.dailyUsedMinutes,budget:y.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:k=>k.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")," ",u<=(m?f:1)+.01?S(m?"remote.fill":"remote.fit"):`${Math.round(u*100)}%`]}),s.jsxs("div",{style:{display:"flex",gap:4},children:[s.jsx("button",{onClick:k=>{k.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:k=>{k.stopPropagation(),C()},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:k=>{k.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 Cb({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 jb(){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 Fl(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 fr(e,t){const n=l.useRef(null),r=l.useRef(0);l.useEffect(()=>{if(!jb())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,Fl(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,Fl(t[i])]))}),n.current=t})}function Nb({containerRef:e,viewportRef:t,imgRef:n,inputMode:r,setInputMode:a,minZoom:o,zoomRef:i,panXRef:c,panYRef:d,setPanX:p,setPanY:u,setZoom:m,lastWheelTimeRef:f,onAction:g,setLastActionStatus:C,spawnRippleFromNormalized:h,clampPan:x,isMobile:y,mobileFillZoom:b}){const[S,k]=l.useState(null),w=l.useRef(null),v=l.useRef(null),N=l.useRef(null),j=l.useRef(!1),A=l.useRef(null),I=l.useRef(0),M=l.useRef(null),D=l.useRef(1),L=l.useRef({x:0,y:0}),_=l.useRef(!1),q=l.useRef(r),B=l.useRef(g),E=30,K=550,R=18,T=60,H=400,P=12,W=()=>{if(w.current)return;const V={nx:.5,ny:.5};w.current=V,k(V)};return l.useEffect(()=>{q.current=r,r==="mouse"&&W()},[r]),l.useEffect(()=>{B.current=g},[g]),l.useEffect(()=>{const V=e.current;if(!V)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,G=ye.naturalHeight||ke.height,U=me/G,Z=ke.width/ke.height;let Y,fe;return U>Z?(Y=ke.width,fe=ke.width/U):(fe=ke.height,Y=ke.height*U),{dnx:ae/Y,dny:Ce/fe}},ne=(ae,Ce,ye)=>{if(ye<=1.05)return;const ke=-(ae-.5)*100,me=-(Ce-.5)*100,G=x(ke,me,ye);(Math.abs(G.x-c.current)>.1||Math.abs(G.y-d.current)>.1)&&(p(G.x),u(G.y),c.current=G.x,d.current=G.y)},O=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||(j.current=!1),A.current=setTimeout(()=>{if(!j.current&&!_.current)if(j.current=!0,q.current==="mouse"){const ke=w.current||{nx:.5,ny:.5};C("Right Click"),h(ke.nx,ke.ny,"right"),B.current("input_click",{...ke,button:"right"}).catch(()=>{})}else{const ke=X(ye);ke&&(C("Right Click"),h(ke.nx,ke.ny,"right"),B.current("input_click",{...ke,button:"right"}).catch(()=>{}))}},500);return}if(ae.touches.length===2){A.current&&clearTimeout(A.current),j.current=!0,_.current=!0;const ye=ae.touches[1].clientX-ae.touches[0].clientX,ke=ae.touches[1].clientY-ae.touches[0].clientY;M.current=Math.sqrt(ye*ye+ke*ke),D.current=i.current,L.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(!j.current&&v.current){const G=ye.clientX-v.current.x,U=ye.clientY-v.current.y;Math.sqrt(G*G+U*U)>8&&(j.current=!0,A.current&&clearTimeout(A.current))}if(j.current)if(q.current==="mouse"){const G=de(ke,me),U=w.current||{nx:.5,ny:.5},Z=Math.max(0,Math.min(1,U.nx+G.dnx)),Y=Math.max(0,Math.min(1,U.ny+G.dny));w.current={nx:Z,ny:Y},k({nx:Z,ny:Y}),C(`Cursor: ${Math.round(Z*100)}%, ${Math.round(Y*100)}%`),ne(Z,Y,i.current);const fe=Date.now();fe-f.current>=30&&(f.current=fe,B.current("input_mouseMoved",{nx:Z,ny:Y}).catch(()=>{}))}else if(i.current>1){const G=t.current;if(G){const U=G.clientWidth,Z=G.clientHeight,Y=c.current+ke/U*100,fe=d.current+me/Z*100,Te=x(Y,fe,i.current);p(Te.x),u(Te.y),c.current=Te.x,d.current=Te.y}}else{const G=X(ye);if(G){const U=Date.now();U-f.current>=40&&(f.current=U,C("Scroll"),B.current("input_wheel",{nx:G.nx,ny:G.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&&M.current!==null){const ye=ae.touches[1].clientX-ae.touches[0].clientX,ke=ae.touches[1].clientY-ae.touches[0].clientY,G=Math.sqrt(ye*ye+ke*ke)/M.current,U=(ae.touches[0].clientX+ae.touches[1].clientX)/2,Z=(ae.touches[0].clientY+ae.touches[1].clientY)/2,Y=U-L.current.x,fe=Z-L.current.y,Te=Math.abs(G-1)>.03;if(q.current==="mouse"){if(Te){const ce=Math.max(o,Math.min(5,D.current*G));m(ce),i.current=ce}else if(Math.abs(Y)>2||Math.abs(fe)>2){const ce=w.current||{nx:.5,ny:.5},$=Date.now();$-f.current>=30&&(f.current=$,C("Scroll"),B.current("input_wheel",{nx:ce.nx,ny:ce.ny,deltaX:Math.round(-Y*3),deltaY:Math.round(-fe*3)}).catch(()=>{}))}}else{const ce=Math.max(o,Math.min(5,D.current*G));m(ce),i.current=ce;const $=t.current;if($&&ce>1){const pe=$.clientWidth,le=$.clientHeight,F=c.current+Y/pe*100,be=d.current+fe/le*100,je=x(F,be,ce);p(je.x),u(je.y),c.current=je.x,d.current=je.y}}L.current={x:U,y:Z}}},z=ae=>{var Ce;if(A.current&&clearTimeout(A.current),M.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},j.current=!0;return}if(ae.touches.length===0){if(_.current){_.current=!1,j.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),G=v.current?ye.clientX-v.current.x:0,U=v.current?ye.clientY-v.current.y:0,Z=Math.sqrt(G*G+U*U);if(q.current==="mouse"){if(me<E||me>K||Z>R){j.current=!1;return}const Y=w.current||X(ye);Y&&(C(`Click: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),h(Y.nx,Y.ny,"left"),B.current("input_click",{...Y}).catch(()=>{}))}else{if(j.current){j.current=!1;return}if(me<T||me>H||Z>P){j.current=!1;return}const Y=X(ye);if(!Y)return;ke-I.current<300?(C("Double tap"),h(Y.nx,Y.ny,"double"),B.current("input_click",{...Y,clickCount:2}).catch(()=>{}),I.current=0):(C(`Tap: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),h(Y.nx,Y.ny,"left"),B.current("input_click",{...Y}).catch(()=>{}),I.current=ke)}}j.current=!1}};return V.addEventListener("touchstart",O,{passive:!1}),V.addEventListener("touchmove",ie,{passive:!1}),V.addEventListener("touchend",z,{passive:!1}),()=>{V.removeEventListener("touchstart",O),V.removeEventListener("touchmove",ie),V.removeEventListener("touchend",z),A.current&&clearTimeout(A.current)}},[e,t,n,o,i,c,d,p,u,m,f,C,h,x]),{cursorPos:S,cursorPosRef:w,handleToggleInputMode:()=>{a(V=>{const X=V==="touch"?"mouse":"touch";return X==="mouse"&&W(),X})},handleZoomReset:()=>{const V=y?b:1;m(V),i.current=V,p(0),u(0),c.current=0,d.current=0}}}function du({onAction:e,addLog:t,connState:n,connScreenshot:r,screenshotUsage:a,transportType:o}){const i=l.useRef(null),c=l.useRef(null),d=l.useRef(null),[p,u]=l.useState(null),[m,f]=l.useState(""),[,g]=l.useState(!1),[C,h]=l.useState([]),x=l.useRef(0),[y,b]=l.useState(!1),[S,k]=l.useState(!1),w=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[v,N]=l.useState(w?"mouse":"touch"),[j,A]=l.useState(1),I=l.useRef(!1),[M,D]=l.useState(1),[L,_]=l.useState(0),[q,B]=l.useState(0);fr("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:v,zoom:M,panX:L,panY:q,isMenuOpen:y,isImeOpen:S});const E=l.useRef(0),K=l.useRef(M),R=l.useRef(L),T=l.useRef(q);l.useEffect(()=>{K.current=M},[M]),l.useEffect(()=>{R.current=L},[L]),l.useEffect(()=>{T.current=q},[q]),l.useEffect(()=>{var me;(me=i.current)==null||me.focus()},[]);const H=n==="connected",P=r,W=H?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",J=H?"The remote stream is warming up":"Waiting for the remote stream to catch up";l.useEffect(()=>{if(!w||I.current||!P)return;const me=d.current,G=c.current;if(!me||!G)return;const U=()=>{const Z=G.clientWidth,Y=G.clientHeight,fe=me.naturalWidth,Te=me.naturalHeight;if(!fe||!Te||!Z||!Y)return;const ce=Math.min(Z/fe,Y/Te),pe=Math.max(Z/fe,Y/Te)/ce;pe>1.01&&(A(pe),D(pe),K.current=pe),I.current=!0};me.complete&&me.naturalWidth?U():me.addEventListener("load",U,{once:!0})},[P,w]);const re=.5;l.useEffect(()=>{M<=re&&(_(0),B(0))},[M,re]);const V=(me,G,U)=>{if(U<=re)return{x:0,y:0};const Z=(U-1)/(2*U)*100,Y=(U-1)/(2*U)*100;return{x:Math.max(-Z,Math.min(Z,me)),y:Math.max(-Y,Math.min(Y,G))}},X=(me,G)=>{if(!d.current)return null;const U=d.current.getBoundingClientRect();return!U.width||!U.height?null:{nx:Math.max(0,Math.min(1,(me-U.left)/U.width)),ny:Math.max(0,Math.min(1,(G-U.top)/U.height))}},de=(me,G,U)=>{const Z=c.current;if(!Z)return;const Y=Z.getBoundingClientRect(),fe=++x.current;h(Te=>[...Te,{id:fe,x:me-Y.left,y:G-Y.top,type:U}]),setTimeout(()=>h(Te=>Te.filter(ce=>ce.id!==fe)),600)},ne=(me,G,U)=>{const Z=d.current,Y=c.current;if(!Z||!Y)return;const fe=Z.getBoundingClientRect(),Te=Y.getBoundingClientRect(),ce=Z.naturalWidth||fe.width,$=Z.naturalHeight||fe.height,pe=ce/$,le=fe.width/fe.height;let F,be,je,Se;pe>le?(F=fe.width,be=fe.width/pe,je=0,Se=(fe.height-be)/2):(be=fe.height,F=fe.height*pe,je=(fe.width-F)/2,Se=0);const He=fe.left-Te.left+je+F*me,Xe=fe.top-Te.top+Se+be*G,dt=++x.current;h(it=>[...it,{id:dt,x:He,y:Xe,type:U}]),setTimeout(()=>h(it=>it.filter(he=>he.id!==dt)),600)},O=async me=>{var U;const G=X(me.clientX,me.clientY);if(G){u(`Click: ${Math.round(G.nx*100)}%, ${Math.round(G.ny*100)}%`),de(me.clientX,me.clientY,"left"),(U=i.current)==null||U.focus();try{const Z=await e("input_click",{nx:G.nx,ny:G.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,G,U,Z=0)=>{try{await e("input_key",{type:U?"char":"keyDown",key:me,code:G,text:U?me:void 0,unmodifiedText:U?me:void 0,modifiers:Z})}catch(Y){t(`❌ Key error: ${Y.message||Y}`)}},z=async me=>{if(me.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(me.key)&&me.preventDefault();let U=0;me.altKey&&(U|=1),me.ctrlKey&&(U|=2),me.metaKey&&(U|=4),me.shiftKey&&(U|=8),u(`Key: ${me.key}`),await ie(me.key,me.code,me.key.length===1,U)},ae=async me=>{if(me.key==="Enter"){if(me.nativeEvent.isComposing)return;if(m){const G=m;f(""),u(`IME Sent: ${G}`);try{const U=await e("input_type",{text:G});U!=null&&U.success||t(`❌ IME error: ${U==null?void 0:U.error}`)}catch(U){t(`❌ IME error: ${U.message}`)}}else u("Key: Enter"),await ie("Enter","Enter",!1)}};l.useEffect(()=>{const me=i.current;if(!me)return;const G=U=>{var Z;if((Z=d.current)!=null&&Z.contains(U.target)){U.preventDefault();const Y=Date.now();if(Y-E.current<40)return;E.current=Y;const fe=X(U.clientX,U.clientY);if(!fe)return;u(`Scroll: ${Math.round(U.deltaY)}`),e("input_wheel",{nx:fe.nx,ny:fe.ny,deltaX:Math.round(U.deltaX),deltaY:Math.round(U.deltaY)}).catch(()=>{})}};return me.addEventListener("wheel",G,{passive:!1}),()=>me.removeEventListener("wheel",G)},[e]);const{cursorPos:Ce,handleToggleInputMode:ye,handleZoomReset:ke}=Nb({containerRef:i,viewportRef:c,imgRef:d,inputMode:v,setInputMode:N,minZoom:re,zoomRef:K,panXRef:R,panYRef:T,setPanX:_,setPanY:B,setZoom:D,lastWheelTimeRef:E,onAction:e,setLastActionStatus:u,spawnRippleFromNormalized:ne,clampPan:V,isMobile:w,mobileFillZoom:j});return s.jsxs("div",{ref:i,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:z,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:d,src:P,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${M}) translate(${L}%, ${q}%)`,transformOrigin:"center center",cursor:v==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:O,onContextMenu:me=>me.preventDefault(),onDragStart:me=>me.preventDefault()}):s.jsx(Cb,{waitingLabel:W,waitingHint:J,transportType:o}),v==="mouse"&&P&&s.jsx(kb,{cursorPos:Ce,viewportRef:c,imgRef:d}),C.map(me=>{const U={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(${U}, 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(${U}, 0.9)`,boxShadow:`0 0 12px rgba(${U}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},me.id)})]}),s.jsx(Sb,{inputMode:v,onToggleInputMode:ye,isImeOpen:S,setIsImeOpen:k,isMenuOpen:y,setIsMenuOpen:b,imeText:m,setImeText:f,handleImeSubmit:ae,isConnActive:H,zoom:M,isMobile:w,mobileFillZoom:j,onZoomOut:()=>D(me=>Math.max(.5,me-.25)),onZoomReset:ke,onZoomIn:()=>D(me=>Math.min(5,me+.25)),transportType:o,screenshotUsage:a,lastActionStatus:p}),s.jsx("style",{children:`
8
+ `});if(m.isActivityFacing&&u!=="thought"&&u!=="tool"&&u!=="terminal"){const M=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:M})]}),g&&f?s.jsx("div",{className:"chat-msg-activity-body",children:s.jsx(En,{parts:f,renderAsPreformatted:!1})}):s.jsx("div",{className:"chat-msg-activity-body",style:{whiteSpace:"pre-wrap"},children:C})]})}if(u==="thought"){const M=typeof((j=t.meta)==null?void 0:j.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(Ff,{size:13}),s.jsx("span",{children:M})]}),s.jsx("div",{className:"chat-msg-body",children:C})]})}if(u==="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(En,{parts:f,renderAsPreformatted:!1})}):s.jsx("div",{className:"tool-text w-full",style:{whiteSpace:"pre-wrap"},children:C})]});if(u==="terminal"){const M=(A=t.meta)!=null&&A.isRunning?"⏳":"✅",D=typeof((I=t.meta)==null?void 0:I.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:M}),s.jsx("span",{children:D})]}),g&&f?s.jsx("div",{className:"chat-msg-body",children:s.jsx(En,{parts:f,renderAsPreformatted:!0})}):s.jsx("pre",{className:"chat-msg-body",children:C})]})}if(u==="system")return s.jsx("div",{className:"self-center chat-msg-system",children:g&&f?s.jsx(En,{parts:f,renderAsPreformatted:!1}):C.slice(0,100)});const h=t.meta,y=(typeof(h==null?void 0:h.renderMode)=="string"?h.renderMode.trim():"")==="preformatted",b=C,S=!1,k=b,w=y,v=!p&&!w&&qd(k),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(db,{text:C}),n!=null&&s.jsx("span",{className:"chat-time",children:Gd(n)})]})]}),(b||g)&&s.jsx("div",{className:"chat-markdown",children:g&&f?s.jsx(En,{parts:f,renderAsPreformatted:w}):s.jsx(pb,{content:k,renderAsPreformatted:w,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),fb=l.forwardRef(function({messages:t,actionLogs:n,agentName:r="Agent",userName:a,isCliMode:o=!1,isWorking:i=!1,contextKey:c="",receivedAtMap:d={},lastMessageHash:p,showActivityMessages:u=!1,emptyState:m,onLoadMore:f,isLoadingMore:g,hasMoreHistory:C,hiddenLiveCount:h=0,loadError:x,scrollToBottomRequestNonce:y,isVisible:b=!0},S){const{t:k}=Ne("common"),w=l.useRef(null),v=l.useRef(null),N=l.useRef(null),j=l.useRef(0),A=l.useRef(""),I=l.useRef(""),M=l.useRef(!1),D=l.useRef(null),L=l.useRef(!1),_=l.useRef(null),q=l.useRef(!1),[B,E]=l.useState(new Set),[K,R]=l.useState({showTop:!1,showBottom:!1}),T=l.useRef(!1),H=l.useRef(!1),P=l.useRef(b),W=l.useRef(b),J=l.useRef(null);W.current=b;const re=()=>{const ce=w.current;return ce?ce.scrollHeight-ce.scrollTop-ce.clientHeight<ji:!0},V=l.useCallback(()=>{const ce=w.current,$=ce?Af(ce):{showTop:!1,showBottom:!1};R(pe=>pe.showTop===$.showTop&&pe.showBottom===$.showBottom?pe:$)},[]),X=l.useCallback((ce="auto")=>{var pe;const $=w.current;$&&($.scrollTo({top:$.scrollHeight,behavior:ce}),(pe=$.ownerDocument.defaultView)==null||pe.requestAnimationFrame(()=>V()))},[V]),de=l.useCallback((ce="auto")=>{var pe;const $=w.current;$&&($.scrollTo({top:0,behavior:ce}),(pe=$.ownerDocument.defaultView)==null||pe.requestAnimationFrame(()=>V()))},[V]),ne=l.useCallback(()=>{var F;const ce=w.current,$=(F=window.getSelection)==null?void 0:F.call(window);if(!ce||!$||$.rangeCount===0||$.isCollapsed){q.current=!1;return}const pe=$.anchorNode,le=$.focusNode;q.current=!!(pe&&le&&ce.contains(pe)&&ce.contains(le))},[]),O=l.useMemo(()=>{const ce=ob(t),$=au(t);return lb(cb(ce,$,u))},[t,u]),ie=O.length===t.length?p:void 0,z=Cf(O,ie),ae=l.useCallback(()=>{const ce=w.current;if(!ce||!c||!W.current)return;const $={top:ce.scrollTop,fromBottom:Math.max(0,ce.scrollHeight-ce.scrollTop-ce.clientHeight),messageFingerprint:z};J.current={contextKey:c,snapshot:$},Rn.set(c,$)},[c,z]),Ce=l.useCallback((ce="auto")=>{D.current!=null&&cancelAnimationFrame(D.current),D.current=requestAnimationFrame(()=>{D.current=null,X(ce)})},[X]),ye=l.useCallback(()=>{T.current=!1,L.current=!0,H.current=!0,_.current!=null&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>{L.current=!1,_.current=null},Ml)},[]);l.useEffect(()=>{const ce=!M.current,$=I.current!==c;if(I.current=c,ce||$){M.current=!0;const le=c?Rn.get(c):null,F=!!le&&na(le,z);T.current=F?Vn(le):!1,L.current=If(le,z),q.current||(F?requestAnimationFrame(()=>{const be=w.current;be&&(qa(be,le),T.current=Vn(le),V(),H.current=!0)}):Ce("auto")),j.current=O.length,A.current=z;return}O.length>j.current;const pe=z!==A.current;Tf({hasSelection:q.current,userScrolledUp:T.current,hasChatContentChanged:pe})&&Ce("auto"),j.current=O.length,A.current=z},[z,c,O.length,Ce,V]),l.useEffect(()=>{y&&(ye(),q.current||Ce("auto"))},[ye,Ce,y]),l.useEffect(()=>{const ce=P.current;ce&&!b&&ae(),W.current=b,P.current=b;const $=c?Rn.get(c):null;if(jf(ce,b,$,z)){if(!$)return;T.current=Vn($),L.current=!1,q.current||requestAnimationFrame(()=>{const pe=w.current;pe&&(qa(pe,$),V())});return}},[b,c,z,ye,ae,Ce,V]),l.useEffect(()=>()=>{const ce=J.current;ce&&Rn.set(ce.contextKey,ce.snapshot),D.current!=null&&cancelAnimationFrame(D.current),_.current!=null&&window.clearTimeout(_.current)},[]),l.useEffect(()=>{const ce=v.current,$=w.current;if(!ce||!$)return;const pe=()=>{_.current!=null&&window.clearTimeout(_.current),_.current=window.setTimeout(()=>{L.current=!1,_.current=null},Ml)},le=new ResizeObserver(()=>{V();const F=L.current;Mf({hasSelection:q.current,userScrolledUp:T.current,contextAutoScrollActive:F})&&(Ce("auto"),F&&pe())});return le.observe(ce),$!==ce&&le.observe($),()=>{le.disconnect(),_.current!=null&&(window.clearTimeout(_.current),_.current=null)}},[Ce,c,V]),l.useImperativeHandle(S,()=>({scrollToBottom:(ce="smooth")=>{X(ce)}}),[X]),l.useEffect(()=>{const ce=w.current;if(!ce)return;let $;const pe=()=>{ae(),clearTimeout($),$=setTimeout(()=>{T.current=!re(),V()},50)};return ce.addEventListener("scroll",pe,{passive:!0}),()=>{ce.removeEventListener("scroll",pe),clearTimeout($)}},[ae,V]),l.useEffect(()=>(document.addEventListener("selectionchange",ne),()=>document.removeEventListener("selectionchange",ne)),[ne]);const ke=l.useRef(0),me=l.useRef(!1);l.useEffect(()=>{const ce=w.current;if(!ce||!me.current||ke.current===0)return;const $=ce.scrollHeight-ke.current;$>0&&(ce.scrollTop=$),V(),ae(),ke.current=0,me.current=!1},[O.length,ae,V]),l.useEffect(()=>{if(H.current||!c)return;const ce=Rn.get(c),$=w.current;if(!(!ce||!$)){if(!na(ce,z)){X("auto"),H.current=!0;return}qa($,ce),T.current=Vn(ce),V(),H.current=!0}},[c,z,O.length,X,V]);const G=()=>{const ce=w.current;ce&&(ke.current=ce.scrollHeight),me.current=!0,f==null||f()},U=()=>{T.current=!0,de("smooth"),ae()},Z=()=>{ye(),X("smooth"),ae()},Y=l.useMemo(()=>{const ce=O.map((F,be)=>({type:"message",data:F,index:be,ts:xf(F,be,d)}));if(!n||n.length===0)return ce;const $=[...n].sort((F,be)=>F.timestamp-be.timestamp).map((F,be)=>({type:"action",data:F,index:be,ts:F.timestamp})),pe=[];let le=0;for(const F of ce){for(;le<$.length&&F.ts>0&&$[le].ts<F.ts;)pe.push($[le++]);pe.push(F)}for(;le<$.length;)pe.push($[le++]);return pe},[O,n,d]),fe=h>0||!!C,Te=h>0?h>80?k("chatList.showEarlierMessagesHidden",{count:Math.min(h,80),total:h}):k("chatList.showEarlierMessages",{count:Math.min(h,80)}):x?k("chatList.loadErrorRetry",{error:x}):k("chatList.loadOlderMessages");return s.jsxs("div",{className:"chat-scroll-frame",children:[s.jsx("div",{ref:w,"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:k("chatList.loadingOlderMessages")}),fe&&!g&&s.jsx("div",{className:"text-center py-2",children:s.jsx("button",{type:"button",onClick:G,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})}),Y.length===0&&!fe&&(m||s.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:k("chatList.waitingForMessages")})),Y.map(ce=>{if(ce.type==="action"){const je=ce.data;return s.jsx(mb,{log:je},`action-${ce.index}`)}const $=ce.data;ce.index;const pe=sa($),le=$.receivedAt||d[pe],F=`${c}-${pe}`,be=B.has(F);return s.jsx(hb,{message:$,receivedAt:le,agentName:r,userName:a,isCliMode:o,isTextExpanded:be,onToggleTextExpanded:()=>E(je=>{const Se=new Set(je);return be?Se.delete(F):Se.add(F),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:k("chatList.agentGenerating")})]})}),s.jsx("div",{className:"min-h-10",ref:N})]})}),(K.showTop||K.showBottom)&&s.jsxs("div",{className:"chat-scroll-jump-controls","aria-label":k("chatList.jumpToTop"),children:[K.showTop&&s.jsx("button",{type:"button",className:"chat-scroll-jump-button",onClick:U,"aria-label":k("chatList.jumpToOldestMessages"),title:k("chatList.jumpToTop"),children:k("chatList.top")}),K.showBottom&&s.jsx("button",{type:"button",className:"chat-scroll-jump-button chat-scroll-jump-button-primary",onClick:Z,"aria-label":k("chatList.jumpToLatestMessages"),title:k("chatList.jumpToBottom"),children:k("chatList.latest")})]})]})}),bb=l.memo(fb,(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),gb="modulepreload",xb=function(e){return"/"+e},$l={},vb=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(d=>{if(d=xb(d),d in $l)return;$l[d]=!0;const p=d.endsWith(".css"),u=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${u}`))return;const m=document.createElement("link");if(m.rel=p?"stylesheet":gb,p||(m.as="script"),m.crossOrigin="",m.href=d,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 ${d}`)))})}))}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 Hl=!1;const cu=l.forwardRef(({onInput:e,onViewportMetrics:t,onScrollMetrics:n,fontSize:r=13,readOnly:a=!1,sizingMode:o="measured"},i)=>{const c=l.useRef(null),[d,p]=l.useState(null),u=l.useRef([]),m=l.useRef(!1),f=l.useRef(!1),g=l.useRef(!1),C=l.useRef(!1),h=()=>{const x=c.current;if(x){m.current&&(x.clear(),m.current=!1);for(const y of u.current)x.write(y.data,y.onProcessed);u.current=[],f.current&&(x.fit(),f.current=!1),g.current&&(x.bumpResize(),g.current=!1),C.current&&(x.scrollToTop(),C.current=!1)}};return l.useImperativeHandle(i,()=>({write:(x,y)=>{c.current?c.current.write(x,y):u.current.push({data:x,onProcessed:y})},clear:()=>{c.current?c.current.clear():(u.current=[],m.current=!0)},reset:()=>{c.current&&typeof c.current.reset=="function"?c.current.reset():(u.current=[],m.current=!0)},resize:(x,y)=>{c.current&&typeof c.current.resize=="function"&&c.current.resize(x,y)},fit:()=>{c.current?c.current.fit():f.current=!0},bumpResize:()=>{c.current?c.current.bumpResize():g.current=!0},scrollToTop:()=>{c.current?c.current.scrollToTop():C.current=!0},getSelection:()=>{var x,y;return((y=(x=c.current)==null?void 0:x.getSelection)==null?void 0:y.call(x))||""},getVisibleText:()=>{var x,y;return((y=(x=c.current)==null?void 0:x.getVisibleText)==null?void 0:y.call(x))||""}}),[]),l.useEffect(()=>{d&&h()},[d]),l.useEffect(()=>{let x=!1;return vb(()=>import("./terminal-DiXj2eIR.js"),__vite__mapDeps([0,1,2])).then(y=>{Hl||(Hl=!0,console.info("[CliTerminal] renderer module loaded: terminal-render-web")),x||p(()=>y.GhosttyTerminalView)}).catch(y=>{console.error("[CliTerminal] failed to load terminal renderer",y)}),()=>{x=!0}},[]),d?s.jsx(d,{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"}})});cu.displayName="CliTerminal";function Ft(...e){return jh(Nh(e))}const yb={lg:"rounded-lg",xl:"rounded-xl","2xl":"rounded-2xl"},wb={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:Ft("border border-border-subtle bg-bg-secondary",yb[t],wb[n],r),...a})});function Sr({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 kb({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,d=i/c,p=a.width/a.height;let u,m,f,g;d>p?(u=a.width,m=a.width/d,f=0,g=(a.height-m)/2):(m=a.height,u=a.height*d,f=(a.width-u)/2,g=0);const C=a.left-o.left+f+u*e.nx,h=a.top-o.top+g+m*e.ny,x=Math.max(8,Math.min(o.width-8,C)),y=Math.max(8,Math.min(o.height-8,h));return s.jsxs("div",{style:{position:"absolute",left:x-8,top:y-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 Sb({inputMode:e,onToggleInputMode:t,isImeOpen:n,setIsImeOpen:r,isMenuOpen:a,setIsMenuOpen:o,imeText:i,setImeText:c,handleImeSubmit:d,isConnActive:p,zoom:u,isMobile:m,mobileFillZoom:f,onZoomOut:g,onZoomReset:C,onZoomIn:h,transportType:x,screenshotUsage:y,lastActionStatus:b}){const{t:S}=Ne("common");return s.jsxs(s.Fragment,{children:[s.jsxs("div",{onTouchStart:k=>k.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(k=>!k),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:k=>k.stopPropagation(),onChange:k=>c(k.target.value),onKeyDown:k=>{d(k)},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(k=>!k),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")})]}),u>1&&s.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(u*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")}),y&&y.dailyBudgetMinutes>0&&s.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:y.budgetExhausted?"#ef4444":"#c4b5fd",background:y.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:S("remote.dailyTurnTitle"),children:y.budgetExhausted?S("remote.turnBlocked"):S("remote.turnUsage",{used:y.dailyUsedMinutes,budget:y.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:k=>k.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")," ",u<=(m?f:1)+.01?S(m?"remote.fill":"remote.fit"):`${Math.round(u*100)}%`]}),s.jsxs("div",{style:{display:"flex",gap:4},children:[s.jsx("button",{onClick:k=>{k.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:k=>{k.stopPropagation(),C()},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:k=>{k.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 Cb({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 jb(){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 Fl(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 fr(e,t){const n=l.useRef(null),r=l.useRef(0);l.useEffect(()=>{if(!jb())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,Fl(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,Fl(t[i])]))}),n.current=t})}function Nb({containerRef:e,viewportRef:t,imgRef:n,inputMode:r,setInputMode:a,minZoom:o,zoomRef:i,panXRef:c,panYRef:d,setPanX:p,setPanY:u,setZoom:m,lastWheelTimeRef:f,onAction:g,setLastActionStatus:C,spawnRippleFromNormalized:h,clampPan:x,isMobile:y,mobileFillZoom:b}){const[S,k]=l.useState(null),w=l.useRef(null),v=l.useRef(null),N=l.useRef(null),j=l.useRef(!1),A=l.useRef(null),I=l.useRef(0),M=l.useRef(null),D=l.useRef(1),L=l.useRef({x:0,y:0}),_=l.useRef(!1),q=l.useRef(r),B=l.useRef(g),E=30,K=550,R=18,T=60,H=400,P=12,W=()=>{if(w.current)return;const V={nx:.5,ny:.5};w.current=V,k(V)};return l.useEffect(()=>{q.current=r,r==="mouse"&&W()},[r]),l.useEffect(()=>{B.current=g},[g]),l.useEffect(()=>{const V=e.current;if(!V)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,G=ye.naturalHeight||ke.height,U=me/G,Z=ke.width/ke.height;let Y,fe;return U>Z?(Y=ke.width,fe=ke.width/U):(fe=ke.height,Y=ke.height*U),{dnx:ae/Y,dny:Ce/fe}},ne=(ae,Ce,ye)=>{if(ye<=1.05)return;const ke=-(ae-.5)*100,me=-(Ce-.5)*100,G=x(ke,me,ye);(Math.abs(G.x-c.current)>.1||Math.abs(G.y-d.current)>.1)&&(p(G.x),u(G.y),c.current=G.x,d.current=G.y)},O=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||(j.current=!1),A.current=setTimeout(()=>{if(!j.current&&!_.current)if(j.current=!0,q.current==="mouse"){const ke=w.current||{nx:.5,ny:.5};C("Right Click"),h(ke.nx,ke.ny,"right"),B.current("input_click",{...ke,button:"right"}).catch(()=>{})}else{const ke=X(ye);ke&&(C("Right Click"),h(ke.nx,ke.ny,"right"),B.current("input_click",{...ke,button:"right"}).catch(()=>{}))}},500);return}if(ae.touches.length===2){A.current&&clearTimeout(A.current),j.current=!0,_.current=!0;const ye=ae.touches[1].clientX-ae.touches[0].clientX,ke=ae.touches[1].clientY-ae.touches[0].clientY;M.current=Math.sqrt(ye*ye+ke*ke),D.current=i.current,L.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(!j.current&&v.current){const G=ye.clientX-v.current.x,U=ye.clientY-v.current.y;Math.sqrt(G*G+U*U)>8&&(j.current=!0,A.current&&clearTimeout(A.current))}if(j.current)if(q.current==="mouse"){const G=de(ke,me),U=w.current||{nx:.5,ny:.5},Z=Math.max(0,Math.min(1,U.nx+G.dnx)),Y=Math.max(0,Math.min(1,U.ny+G.dny));w.current={nx:Z,ny:Y},k({nx:Z,ny:Y}),C(`Cursor: ${Math.round(Z*100)}%, ${Math.round(Y*100)}%`),ne(Z,Y,i.current);const fe=Date.now();fe-f.current>=30&&(f.current=fe,B.current("input_mouseMoved",{nx:Z,ny:Y}).catch(()=>{}))}else if(i.current>1){const G=t.current;if(G){const U=G.clientWidth,Z=G.clientHeight,Y=c.current+ke/U*100,fe=d.current+me/Z*100,Te=x(Y,fe,i.current);p(Te.x),u(Te.y),c.current=Te.x,d.current=Te.y}}else{const G=X(ye);if(G){const U=Date.now();U-f.current>=40&&(f.current=U,C("Scroll"),B.current("input_wheel",{nx:G.nx,ny:G.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&&M.current!==null){const ye=ae.touches[1].clientX-ae.touches[0].clientX,ke=ae.touches[1].clientY-ae.touches[0].clientY,G=Math.sqrt(ye*ye+ke*ke)/M.current,U=(ae.touches[0].clientX+ae.touches[1].clientX)/2,Z=(ae.touches[0].clientY+ae.touches[1].clientY)/2,Y=U-L.current.x,fe=Z-L.current.y,Te=Math.abs(G-1)>.03;if(q.current==="mouse"){if(Te){const ce=Math.max(o,Math.min(5,D.current*G));m(ce),i.current=ce}else if(Math.abs(Y)>2||Math.abs(fe)>2){const ce=w.current||{nx:.5,ny:.5},$=Date.now();$-f.current>=30&&(f.current=$,C("Scroll"),B.current("input_wheel",{nx:ce.nx,ny:ce.ny,deltaX:Math.round(-Y*3),deltaY:Math.round(-fe*3)}).catch(()=>{}))}}else{const ce=Math.max(o,Math.min(5,D.current*G));m(ce),i.current=ce;const $=t.current;if($&&ce>1){const pe=$.clientWidth,le=$.clientHeight,F=c.current+Y/pe*100,be=d.current+fe/le*100,je=x(F,be,ce);p(je.x),u(je.y),c.current=je.x,d.current=je.y}}L.current={x:U,y:Z}}},z=ae=>{var Ce;if(A.current&&clearTimeout(A.current),M.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},j.current=!0;return}if(ae.touches.length===0){if(_.current){_.current=!1,j.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),G=v.current?ye.clientX-v.current.x:0,U=v.current?ye.clientY-v.current.y:0,Z=Math.sqrt(G*G+U*U);if(q.current==="mouse"){if(me<E||me>K||Z>R){j.current=!1;return}const Y=w.current||X(ye);Y&&(C(`Click: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),h(Y.nx,Y.ny,"left"),B.current("input_click",{...Y}).catch(()=>{}))}else{if(j.current){j.current=!1;return}if(me<T||me>H||Z>P){j.current=!1;return}const Y=X(ye);if(!Y)return;ke-I.current<300?(C("Double tap"),h(Y.nx,Y.ny,"double"),B.current("input_click",{...Y,clickCount:2}).catch(()=>{}),I.current=0):(C(`Tap: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),h(Y.nx,Y.ny,"left"),B.current("input_click",{...Y}).catch(()=>{}),I.current=ke)}}j.current=!1}};return V.addEventListener("touchstart",O,{passive:!1}),V.addEventListener("touchmove",ie,{passive:!1}),V.addEventListener("touchend",z,{passive:!1}),()=>{V.removeEventListener("touchstart",O),V.removeEventListener("touchmove",ie),V.removeEventListener("touchend",z),A.current&&clearTimeout(A.current)}},[e,t,n,o,i,c,d,p,u,m,f,C,h,x]),{cursorPos:S,cursorPosRef:w,handleToggleInputMode:()=>{a(V=>{const X=V==="touch"?"mouse":"touch";return X==="mouse"&&W(),X})},handleZoomReset:()=>{const V=y?b:1;m(V),i.current=V,p(0),u(0),c.current=0,d.current=0}}}function du({onAction:e,addLog:t,connState:n,connScreenshot:r,screenshotUsage:a,transportType:o}){const i=l.useRef(null),c=l.useRef(null),d=l.useRef(null),[p,u]=l.useState(null),[m,f]=l.useState(""),[,g]=l.useState(!1),[C,h]=l.useState([]),x=l.useRef(0),[y,b]=l.useState(!1),[S,k]=l.useState(!1),w=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[v,N]=l.useState(w?"mouse":"touch"),[j,A]=l.useState(1),I=l.useRef(!1),[M,D]=l.useState(1),[L,_]=l.useState(0),[q,B]=l.useState(0);fr("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:v,zoom:M,panX:L,panY:q,isMenuOpen:y,isImeOpen:S});const E=l.useRef(0),K=l.useRef(M),R=l.useRef(L),T=l.useRef(q);l.useEffect(()=>{K.current=M},[M]),l.useEffect(()=>{R.current=L},[L]),l.useEffect(()=>{T.current=q},[q]),l.useEffect(()=>{var me;(me=i.current)==null||me.focus()},[]);const H=n==="connected",P=r,W=H?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",J=H?"The remote stream is warming up":"Waiting for the remote stream to catch up";l.useEffect(()=>{if(!w||I.current||!P)return;const me=d.current,G=c.current;if(!me||!G)return;const U=()=>{const Z=G.clientWidth,Y=G.clientHeight,fe=me.naturalWidth,Te=me.naturalHeight;if(!fe||!Te||!Z||!Y)return;const ce=Math.min(Z/fe,Y/Te),pe=Math.max(Z/fe,Y/Te)/ce;pe>1.01&&(A(pe),D(pe),K.current=pe),I.current=!0};me.complete&&me.naturalWidth?U():me.addEventListener("load",U,{once:!0})},[P,w]);const re=.5;l.useEffect(()=>{M<=re&&(_(0),B(0))},[M,re]);const V=(me,G,U)=>{if(U<=re)return{x:0,y:0};const Z=(U-1)/(2*U)*100,Y=(U-1)/(2*U)*100;return{x:Math.max(-Z,Math.min(Z,me)),y:Math.max(-Y,Math.min(Y,G))}},X=(me,G)=>{if(!d.current)return null;const U=d.current.getBoundingClientRect();return!U.width||!U.height?null:{nx:Math.max(0,Math.min(1,(me-U.left)/U.width)),ny:Math.max(0,Math.min(1,(G-U.top)/U.height))}},de=(me,G,U)=>{const Z=c.current;if(!Z)return;const Y=Z.getBoundingClientRect(),fe=++x.current;h(Te=>[...Te,{id:fe,x:me-Y.left,y:G-Y.top,type:U}]),setTimeout(()=>h(Te=>Te.filter(ce=>ce.id!==fe)),600)},ne=(me,G,U)=>{const Z=d.current,Y=c.current;if(!Z||!Y)return;const fe=Z.getBoundingClientRect(),Te=Y.getBoundingClientRect(),ce=Z.naturalWidth||fe.width,$=Z.naturalHeight||fe.height,pe=ce/$,le=fe.width/fe.height;let F,be,je,Se;pe>le?(F=fe.width,be=fe.width/pe,je=0,Se=(fe.height-be)/2):(be=fe.height,F=fe.height*pe,je=(fe.width-F)/2,Se=0);const He=fe.left-Te.left+je+F*me,Xe=fe.top-Te.top+Se+be*G,dt=++x.current;h(it=>[...it,{id:dt,x:He,y:Xe,type:U}]),setTimeout(()=>h(it=>it.filter(he=>he.id!==dt)),600)},O=async me=>{var U;const G=X(me.clientX,me.clientY);if(G){u(`Click: ${Math.round(G.nx*100)}%, ${Math.round(G.ny*100)}%`),de(me.clientX,me.clientY,"left"),(U=i.current)==null||U.focus();try{const Z=await e("input_click",{nx:G.nx,ny:G.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,G,U,Z=0)=>{try{await e("input_key",{type:U?"char":"keyDown",key:me,code:G,text:U?me:void 0,unmodifiedText:U?me:void 0,modifiers:Z})}catch(Y){t(`❌ Key error: ${Y.message||Y}`)}},z=async me=>{if(me.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(me.key)&&me.preventDefault();let U=0;me.altKey&&(U|=1),me.ctrlKey&&(U|=2),me.metaKey&&(U|=4),me.shiftKey&&(U|=8),u(`Key: ${me.key}`),await ie(me.key,me.code,me.key.length===1,U)},ae=async me=>{if(me.key==="Enter"){if(me.nativeEvent.isComposing)return;if(m){const G=m;f(""),u(`IME Sent: ${G}`);try{const U=await e("input_type",{text:G});U!=null&&U.success||t(`❌ IME error: ${U==null?void 0:U.error}`)}catch(U){t(`❌ IME error: ${U.message}`)}}else u("Key: Enter"),await ie("Enter","Enter",!1)}};l.useEffect(()=>{const me=i.current;if(!me)return;const G=U=>{var Z;if((Z=d.current)!=null&&Z.contains(U.target)){U.preventDefault();const Y=Date.now();if(Y-E.current<40)return;E.current=Y;const fe=X(U.clientX,U.clientY);if(!fe)return;u(`Scroll: ${Math.round(U.deltaY)}`),e("input_wheel",{nx:fe.nx,ny:fe.ny,deltaX:Math.round(U.deltaX),deltaY:Math.round(U.deltaY)}).catch(()=>{})}};return me.addEventListener("wheel",G,{passive:!1}),()=>me.removeEventListener("wheel",G)},[e]);const{cursorPos:Ce,handleToggleInputMode:ye,handleZoomReset:ke}=Nb({containerRef:i,viewportRef:c,imgRef:d,inputMode:v,setInputMode:N,minZoom:re,zoomRef:K,panXRef:R,panYRef:T,setPanX:_,setPanY:B,setZoom:D,lastWheelTimeRef:E,onAction:e,setLastActionStatus:u,spawnRippleFromNormalized:ne,clampPan:V,isMobile:w,mobileFillZoom:j});return s.jsxs("div",{ref:i,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:z,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:d,src:P,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${M}) translate(${L}%, ${q}%)`,transformOrigin:"center center",cursor:v==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:O,onContextMenu:me=>me.preventDefault(),onDragStart:me=>me.preventDefault()}):s.jsx(Cb,{waitingLabel:W,waitingHint:J,transportType:o}),v==="mouse"&&P&&s.jsx(kb,{cursorPos:Ce,viewportRef:c,imgRef:d}),C.map(me=>{const U={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(${U}, 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(${U}, 0.9)`,boxShadow:`0 0 12px rgba(${U}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},me.id)})]}),s.jsx(Sb,{inputMode:v,onToggleInputMode:ye,isImeOpen:S,setIsImeOpen:k,isMenuOpen:y,setIsMenuOpen:b,imeText:m,setImeText:f,handleImeSubmit:ae,isConnActive:H,zoom:M,isMobile:w,mobileFillZoom:j,onZoomOut:()=>D(me=>Math.max(.5,me-.25)),onZoomReset:ke,onZoomIn:()=>D(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
  *