@ww-ai-lab/openclaw-office 2026.3.21 → 2026.3.23
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/dist/assets/{ActivityHeatmap-CvGomuJN.js → ActivityHeatmap-D0IyZYFP.js} +1 -1
- package/dist/assets/{CostPieChart-BIcqqhp7.js → CostPieChart-CO-ieeMV.js} +1 -1
- package/dist/assets/{NetworkGraph-B-nEMJ_M.js → NetworkGraph-B7rKNCND.js} +1 -1
- package/dist/assets/{Scene3D-DC1g2KU1.js → Scene3D-DEX7kPiS.js} +1 -1
- package/dist/assets/{TokenLineChart-CfPgD-hP.js → TokenLineChart-PcKKH8m7.js} +1 -1
- package/dist/assets/{generateCategoricalChart-DUrRp22n.js → generateCategoricalChart-CCtxdbf_.js} +1 -1
- package/dist/assets/index-BZZCdxbc.css +1 -0
- package/dist/assets/{index-DqQHpfxy.js → index-Ds3VfRxk.js} +4 -4
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/dist/assets/index-DehfYC23.css +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TokenLineChart-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TokenLineChart-PcKKH8m7.js","assets/generateCategoricalChart-CCtxdbf_.js","assets/CostPieChart-CO-ieeMV.js"])))=>i.map(i=>d[i]);
|
|
2
2
|
var ej=Object.defineProperty;var tj=(e,t,n)=>t in e?ej(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var je=(e,t,n)=>tj(e,typeof t!="symbol"?t+"":t,n);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const u of o.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&r(u)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();var wI=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function mg(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Lf={exports:{}},Bs={};/**
|
|
3
3
|
* @license React
|
|
4
4
|
* react-jsx-runtime.production.js
|
|
@@ -427,7 +427,7 @@ Please change the parent <Route path="${C}"> to <Route path="${C==="/"?"*":`${C}
|
|
|
427
427
|
|
|
428
428
|
这是 Mock 模式下的模拟回复。在连接真实 Gateway 后,这里将显示 Agent 的实际响应。`;this.scheduleTimer(()=>{this.emit("chat",{type:"event",event:"chat",payload:{runId:n,state:"delta",message:{role:"assistant",content:r.slice(0,Math.floor(r.length/2))}}})},300),this.scheduleTimer(()=>{this.emit("chat",{type:"event",event:"chat",payload:{runId:n,state:"delta",message:{role:"assistant",content:r}}})},800),this.scheduleTimer(()=>{this.emit("chat",{type:"event",event:"chat",payload:{runId:n,state:"final",message:{role:"assistant",content:r,id:`mock-msg-${Date.now()}`,stopReason:"end_turn"}}})},1200)}async chatAbort(t){this.cancelPendingTimers(),this.emit("chat",{type:"event",event:"chat",payload:{state:"aborted"}})}async sessionsList(){return[{key:"agent:main:main",agentId:"main",label:"默认会话",createdAt:Date.now()-36e5,lastActiveAt:Date.now(),messageCount:12},{key:"agent:main:feishu:direct:test-user",agentId:"main",label:"飞书会话",createdAt:Date.now()-18e5,lastActiveAt:Date.now()-6e4,messageCount:8}]}async sessionsPreview(t){return{key:t,messages:await this.chatHistory()}}async sessionsDelete(t,n){}async channelsStatus(){return[...M3]}async skillsStatus(t){return[...O3]}async cronList(){return[...Zx]}async channelsLogout(t,n){return{cleared:!0}}async webLoginStart(t){return{qrDataUrl:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",message:"Scan QR code with WhatsApp"}}async webLoginWait(){return await new Promise(t=>setTimeout(t,2e3)),{connected:!0,message:"WhatsApp connected successfully"}}async skillsInstall(t,n){return{ok:!0,message:"Mock install completed",stdout:"mock: skill installed successfully",code:0}}async skillsUpdate(t,n){return{ok:!0}}async cronAdd(t){const n=Date.now();return{id:`cron-${n}`,name:t.name,description:t.description,schedule:t.schedule,enabled:t.enabled??!0,createdAtMs:n,updatedAtMs:n,sessionTarget:t.sessionTarget,wakeMode:t.wakeMode,payload:t.payload,delivery:t.delivery,agentId:t.agentId,sessionKey:t.sessionKey,state:{}}}async cronUpdate(t,n){const r=Zx.find(s=>s.id===t);if(!r)throw new Error(`Cron task not found: ${t}`);return{...r,...n,updatedAtMs:Date.now()}}async cronRemove(t){}async cronRun(t){}async agentsList(){return{defaultId:"main",mainKey:"agent:main:main",scope:"global",agents:[{id:"main",name:"main",default:!0,identity:{name:"main",emoji:"m"}},{id:"ai-researcher",name:"ResearchClaw",identity:{name:"ResearchClaw",emoji:"🔬"}},{id:"coder",name:"CodeClaw",identity:{name:"CodeClaw",emoji:"💻"}},{id:"ecommerce",name:"TradeClaw",identity:{name:"TradeClaw",emoji:"🛒"}}]}}async agentsCreate(t){return{ok:!0,agentId:`agent-${Date.now()}`,name:t.name,workspace:t.workspace}}async agentsUpdate(t){return{ok:!0,agentId:t.agentId}}async agentsDelete(t){return{ok:!0,agentId:t.agentId,removedBindings:0}}async agentsFilesList(t){const n=new Date().toISOString();return{agentId:t,workspace:"~/.openclaw/workspace",files:[{name:"AGENTS.md",size:7900,modifiedAt:n},{name:"SOUL.md",size:2048,modifiedAt:n},{name:"TOOLS.md",size:860,modifiedAt:n},{name:"IDENTITY.md",size:759,modifiedAt:n},{name:"USER.md",size:1800,modifiedAt:n},{name:"HEARTBEAT.md",size:512,modifiedAt:n}]}}async agentsFilesGet(t,n){return{agentId:t,workspace:"~/.openclaw/workspace",file:{name:n,content:`# ${n}
|
|
429
429
|
|
|
430
|
-
Mock content for ${n}`,size:128,modifiedAt:new Date().toISOString()}}}async agentsFilesSet(t,n,r){return{ok:!0,agentId:t,workspace:"~/.openclaw/workspace",file:{name:n,size:r.length,modifiedAt:new Date().toISOString()}}}async toolsCatalog(t){return{tools:[{name:"web_search",description:"搜索互联网",source:"built-in",group:"core",enabled:!0},{name:"code_exec",description:"执行代码",source:"built-in",group:"core",enabled:!0},{name:"file_read",description:"读取文件内容",source:"built-in",group:"fs",enabled:!0},{name:"file_write",description:"写入文件",source:"built-in",group:"fs",enabled:!0},{name:"bash",description:"执行 Bash 命令",source:"built-in",group:"exec",enabled:!0,optional:!0},{name:"mcp_client",description:"MCP 协议客户端",source:"plugin",group:"integrations",enabled:!1,optional:!0}]}}async usageStatus(){return{updatedAt:Date.now(),providers:[{provider:"anthropic",displayName:"Anthropic",plan:"pro",windows:[{label:"daily",usedPercent:45,resetAt:Date.now()+12*36e5},{label:"monthly",usedPercent:22}]},{provider:"openai",displayName:"OpenAI",plan:"tier-3",windows:[{label:"daily",usedPercent:12}]}]}}async modelsList(){return[{id:"claude-sonnet-4-20250514",name:"Claude Sonnet 4",provider:"anthropic",reasoning:!0,input:["text","image"],contextWindow:2e5},{id:"claude-opus-4-20250514",name:"Claude Opus 4",provider:"anthropic",reasoning:!0,input:["text","image"],contextWindow:2e5},{id:"gpt-4o",name:"GPT-4o",provider:"openai",reasoning:!1,input:["text","image"],contextWindow:128e3},{id:"o3",name:"o3",provider:"openai",reasoning:!0,input:["text","image"],contextWindow:2e5},{id:"gpt-5.3-codex",name:"gpt-5.3-codex",provider:"openai-codex",reasoning:!0,input:["text"],contextWindow:1048576},{id:"gpt-5.3-codex-spark",name:"gpt-5.3-codex-spark",provider:"openai-codex",reasoning:!0,input:["text"],contextWindow:1048576},{id:"gpt-5.1-codex",name:"gpt-5.1-codex",provider:"openai-codex",reasoning:!0,input:["text"],contextWindow:2e5}]}async configGet(){return{config:this.mockConfig,hash:this.mockHash,raw:JSON.stringify(this.mockConfig,null,2),valid:!0,path:"~/.openclaw/openclaw.json"}}async configSet(t,n){return n&&n!==this.mockHash?{ok:!1,path:"~/.openclaw/openclaw.json",config:this.mockConfig,error:"config changed since last load; re-run config.get and retry"}:(this.mockConfig=JSON.parse(t),this.mockHash=Date.now().toString(36),{ok:!0,path:"~/.openclaw/openclaw.json",config:this.mockConfig})}async configApply(t,n,r){return n&&n!==this.mockHash?{ok:!1,path:"~/.openclaw/openclaw.json",config:this.mockConfig,error:"config changed since last load; re-run config.get and retry"}:(this.mockConfig=JSON.parse(t),this.mockHash=Date.now().toString(36),{ok:!0,path:"~/.openclaw/openclaw.json",config:this.mockConfig,restart:{scheduled:!0,delayMs:2e3}})}async configPatch(t,n){if(n&&n!==this.mockHash)return{ok:!1,config:this.mockConfig,error:"config changed since last load; re-run config.get and retry"};const r=JSON.parse(t);return this.mockConfig=B1(this.mockConfig,r),this.mockHash=Date.now().toString(36),{ok:!0,config:this.mockConfig,restart:{scheduled:!0,delayMs:2e3}}}async configSchema(){return{schema:{},uiHints:{"models.providers.*.apiKey":{sensitive:!0,label:"API Key"},"gateway.auth.token":{sensitive:!0,label:"Gateway Token"}},version:"mock"}}async statusSummary(){return{version:"2026.2.27-mock",port:18789,uptime:86400,mode:"local",pid:12345,nodeVersion:"v22.0.0",platform:"darwin"}}async updateRun(t){return{ok:!0,result:{status:"noop",mode:"npm",reason:"already up to date",steps:[],durationMs:1200},restart:null}}}function Tg(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;const t=Array.from(e,n=>n.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}const I3=1e4;class Wf extends Error{constructor(t,n){super(n),this.code=t,this.name="RpcError"}}class U1{constructor(t){this.wsClient=t}request(t,n={},r=I3){return new Promise((s,o)=>{if(!this.wsClient.isConnected()){o(new Wf("NOT_CONNECTED","WebSocket is not connected"));return}const u=Tg();let f=null;const h=()=>{f&&(clearTimeout(f),f=null)};this.wsClient.onResponse(u,g=>{h(),g.ok?s(g.payload):o(new Wf(g.error.code,g.error.message))}),f=setTimeout(()=>{o(new Wf("TIMEOUT",`RPC request timed out: ${t}`))},r),this.wsClient.send({type:"req",id:u,method:t,params:n})})}}const Qc=class Qc{constructor(t,n){je(this,"handlers",new Set);je(this,"unsubscribers",[]);this.wsClient=t,this.rpcClient=n}async connect(){for(const t of Qc.WATCHED_EVENTS){const n=this.wsClient.onEvent(t,r=>{for(const s of this.handlers)s(t,r)});this.unsubscribers.push(n)}}disconnect(){for(const t of this.unsubscribers)t();this.unsubscribers=[],this.handlers.clear()}onEvent(t){return this.handlers.add(t),()=>{this.handlers.delete(t)}}async chatHistory(t){return this.rpcClient.request("chat.history",t?{sessionKey:t}:{})}async chatSend(t){await this.rpcClient.request("chat.send",{sessionKey:t.sessionKey,message:t.text,deliver:!1,idempotencyKey:Tg()})}async chatAbort(t){await this.rpcClient.request("chat.abort",{sessionKey:t})}async sessionsList(){const t=await this.rpcClient.request("sessions.list");return Array.isArray(t)?t:(t==null?void 0:t.sessions)??[]}async sessionsPreview(t){return this.rpcClient.request("sessions.preview",{sessionKey:t})}async sessionsDelete(t,n){await this.rpcClient.request("sessions.delete",{key:t,...(n==null?void 0:n.deleteTranscript)!=null?{deleteTranscript:n.deleteTranscript}:{}})}async channelsStatus(){const t=await this.rpcClient.request("channels.status",{probe:!0});return $3(t)}async channelsLogout(t,n){return this.rpcClient.request("channels.logout",{channel:t,accountId:n})}async webLoginStart(t){return this.rpcClient.request("web.login.start",{force:t})}async webLoginWait(){return this.rpcClient.request("web.login.wait")}async skillsStatus(t){const n=t?{agentId:t}:void 0,r=await this.rpcClient.request("skills.status",n);return q3(r.skills??[])}async skillsInstall(t,n){return this.rpcClient.request("skills.install",{name:t,installId:n})}async skillsUpdate(t,n){return this.rpcClient.request("skills.update",{skillKey:t,...n})}async cronList(){return(await this.rpcClient.request("cron.list")).jobs??[]}async cronAdd(t){return this.rpcClient.request("cron.add",t)}async cronUpdate(t,n){return this.rpcClient.request("cron.update",{id:t,patch:n})}async cronRemove(t){await this.rpcClient.request("cron.remove",{id:t})}async cronRun(t){await this.rpcClient.request("cron.run",{id:t})}async agentsList(){return this.rpcClient.request("agents.list")}async agentsCreate(t){return this.rpcClient.request("agents.create",t)}async agentsUpdate(t){return this.rpcClient.request("agents.update",t)}async agentsDelete(t){return this.rpcClient.request("agents.delete",t)}async agentsFilesList(t){return this.rpcClient.request("agents.files.list",{agentId:t})}async agentsFilesGet(t,n){return this.rpcClient.request("agents.files.get",{agentId:t,name:n})}async agentsFilesSet(t,n,r){return this.rpcClient.request("agents.files.set",{agentId:t,name:n,content:r})}async toolsCatalog(t){const n=t?{agentId:t}:void 0;return this.rpcClient.request("tools.catalog",n)}async usageStatus(){return this.rpcClient.request("usage.status")}async modelsList(){return(await this.rpcClient.request("models.list")).models??[]}async configGet(){return this.rpcClient.request("config.get")}async configSet(t,n){const r=await this.rpcClient.request("config.set",{raw:t,...n?{baseHash:n}:{}});return Jx(r)}async configApply(t,n,r){const s=await this.rpcClient.request("config.apply",{raw:t,...n?{baseHash:n}:{},...r!=null&&r.sessionKey?{sessionKey:r.sessionKey}:{},...r!=null&&r.note?{note:r.note}:{},...(r==null?void 0:r.restartDelayMs)!=null?{restartDelayMs:r.restartDelayMs}:{}});return Jx(s)}async configPatch(t,n){const r=await this.rpcClient.request("config.patch",{raw:t,...n?{baseHash:n}:{}});return H3(r)}async configSchema(){return this.rpcClient.request("config.schema")}async statusSummary(){const t=this.wsClient.getSnapshot(),n=this.wsClient.getServerInfo();return{version:n==null?void 0:n.version,port:18789,uptime:(t==null?void 0:t.uptimeMs)!=null?Math.floor(t.uptimeMs/1e3):void 0,mode:"local",configPath:t==null?void 0:t.configPath}}async updateRun(t){const n=await this.rpcClient.request("update.run",t??{});return B3(n)}};je(Qc,"WATCHED_EVENTS",["agent","chat","presence","health","heartbeat","cron","shutdown"]);let Gh=Qc;function Dg(e){if(!e.restart)return e;const t=e.restart;return{...e,restart:{scheduled:t.ok!==!1,delayMs:t.delayMs??0,...t.coalesced!=null?{coalesced:t.coalesced}:{}}}}function Jx(e){return Dg(e)}function H3(e){return Dg(e)}function B3(e){return Dg(e)}function U3(e){return e.error??e.lastError??void 0?"error":e.connected===!0?"connected":e.connected===!1?e.running?"connecting":"disconnected":e.running&&e.linked!==!1&&e.configured!==!1?"connected":e.running?"connecting":"disconnected"}function $3(e){const t=e.channelAccounts??{},n=e.channelLabels??{},r=[];for(const[s,o]of Object.entries(t))for(const u of o)!u.accountId&&o.length===0||r.push({id:u.accountId?`${s}:${u.accountId}`:s,type:s,name:u.name??n[s]??s,status:U3(u),accountId:u.accountId,error:u.error??u.lastError??void 0,configured:u.configured,linked:u.linked,running:u.running,lastConnectedAt:u.lastConnectedAt,lastMessageAt:u.lastMessageAt,reconnectAttempts:u.reconnectAttempts,mode:u.mode});return r}function q3(e){return e.map(t=>({id:t.skillKey??"",slug:t.skillKey??"",name:t.name??t.skillKey??"",description:t.description??"",enabled:!t.disabled,icon:t.emoji??"📦",version:t.version??"",author:t.author,isCore:t.core,isBundled:t.bundled,config:t.config,source:t.source,homepage:t.homepage,primaryEnv:t.primaryEnv,always:t.always,eligible:t.eligible,blockedByAllowlist:t.blockedByAllowlist,requirements:t.requirements,missing:t.missing,installOptions:t.install,configChecks:t.configChecks}))}function K3(e){return["v2",e.deviceId,e.clientId,e.clientMode,e.role,e.scopes.join(","),String(e.signedAtMs),e.token??"",e.nonce].join("|")}const Xf="openclaw-office.device-identity.v1";function Vh(e){let t="";for(const n of e)t+=String.fromCharCode(n);return btoa(t).replaceAll("+","-").replaceAll("/","_").replace(/=+$/g,"")}function $1(e){const t=e.replaceAll("-","+").replaceAll("_","/"),n=t+"=".repeat((4-t.length%4)%4),r=atob(n);return Uint8Array.from(r,s=>s.charCodeAt(0))}function P3(e){return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function q1(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}async function K1(e){const t=await crypto.subtle.digest("SHA-256",q1(e));return P3(new Uint8Array(t))}async function F3(){const e=await crypto.subtle.generateKey("Ed25519",!0,["sign","verify"]),t=new Uint8Array(await crypto.subtle.exportKey("raw",e.publicKey)),n=new Uint8Array(await crypto.subtle.exportKey("pkcs8",e.privateKey));return{deviceId:await K1(t),publicKey:Vh(t),privateKey:Vh(n)}}async function G3(){try{const t=localStorage.getItem(Xf);if(t){const n=JSON.parse(t);if((n==null?void 0:n.version)===1&&typeof n.deviceId=="string"&&typeof n.publicKey=="string"&&typeof n.privateKey=="string"){const r=await K1($1(n.publicKey));return r!==n.deviceId?(localStorage.setItem(Xf,JSON.stringify({...n,deviceId:r})),{deviceId:r,publicKey:n.publicKey,privateKey:n.privateKey}):{deviceId:n.deviceId,publicKey:n.publicKey,privateKey:n.privateKey}}}}catch{}const e=await F3();return localStorage.setItem(Xf,JSON.stringify({version:1,deviceId:e.deviceId,publicKey:e.publicKey,privateKey:e.privateKey,createdAtMs:Date.now()})),e}async function V3(e,t){const n=await crypto.subtle.importKey("pkcs8",q1($1(e)),"Ed25519",!1,["sign"]),r=await crypto.subtle.sign("Ed25519",n,new TextEncoder().encode(t));return Vh(new Uint8Array(r))}const Y3=20,Q3=1e3,W3=3e4,X3=1e3;class P1{constructor(){je(this,"ws",null);je(this,"url","");je(this,"token","");je(this,"status","disconnected");je(this,"reconnectAttempt",0);je(this,"reconnectTimer",null);je(this,"shutdownReceived",!1);je(this,"eventHandlers",new Map);je(this,"statusHandlers",new Set);je(this,"responseHandlers",new Map);je(this,"snapshot",null);je(this,"serverInfo",null);je(this,"handleClose",()=>{})}getStatus(){return this.status}getSnapshot(){return this.snapshot}getServerInfo(){return this.serverInfo}isConnected(){var t;return this.status==="connected"&&((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN}connect(t,n){this.url=t,this.token=n,this.shutdownReceived=!1,this.reconnectAttempt=0,this.doConnect()}disconnect(){this.shutdownReceived=!0,this.clearReconnectTimer(),this.ws&&(this.ws.removeEventListener("close",this.handleClose),this.ws.close(),this.ws=null),this.setStatus("disconnected")}onEvent(t,n){let r=this.eventHandlers.get(t);return r||(r=new Set,this.eventHandlers.set(t,r)),r.add(n),()=>r.delete(n)}onStatusChange(t){return this.statusHandlers.add(t),()=>this.statusHandlers.delete(t)}onResponse(t,n){this.responseHandlers.set(t,n)}send(t){var n;((n=this.ws)==null?void 0:n.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify(t))}doConnect(){this.setStatus(this.reconnectAttempt>0?"reconnecting":"connecting");try{this.ws=new WebSocket(this.url)}catch{this.scheduleReconnect();return}this.handleClose=()=>{this.shutdownReceived||this.scheduleReconnect()},this.ws.addEventListener("open",()=>{}),this.ws.addEventListener("message",t=>{this.handleMessage(t)}),this.ws.addEventListener("close",this.handleClose),this.ws.addEventListener("error",()=>{})}handleMessage(t){let n;try{n=JSON.parse(t.data)}catch{return}if(n.type==="event"){const r=n;this.handleEvent(r)}else if(n.type==="res"){const r=n;this.handleResponse(r)}}handleEvent(t){if(t.event==="connect.challenge"){const s=typeof t.payload=="object"&&t.payload!==null&&"nonce"in t.payload&&typeof t.payload.nonce=="string"?t.payload.nonce:"";this.sendConnect(s);return}t.event==="shutdown"&&(this.shutdownReceived=!0,this.clearReconnectTimer(),this.setStatus("disconnected"));const n=this.eventHandlers.get(t.event);if(n)for(const s of n)s(t);const r=this.eventHandlers.get("*");if(r)for(const s of r)s(t)}handleResponse(t){var r;const n=this.responseHandlers.get(t.id);if(n){this.responseHandlers.delete(t.id),n(t);return}t.ok&&((r=t.payload)==null?void 0:r.type)==="hello-ok"?this.handleConnectSuccess(t.payload):t.ok||this.setStatus("error",t.error.message)}async sendConnect(t){const n="operator",r=["operator.admin"],s={minProtocol:3,maxProtocol:3,role:n,client:{id:"openclaw-control-ui",version:"0.1.0",platform:"web",mode:"ui"},caps:["tool-events"],scopes:r,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,locale:typeof navigator<"u"?navigator.language:void 0};if(this.token&&(s.auth={token:this.token}),typeof window<"u"&&window.isSecureContext&&typeof crypto<"u"&&typeof crypto.subtle<"u")try{const u=await G3(),f=Date.now(),h=K3({deviceId:u.deviceId,clientId:s.client.id,clientMode:s.client.mode,role:n,scopes:r,signedAtMs:f,token:this.token||null,nonce:t});s.device={id:u.deviceId,publicKey:u.publicKey,signature:await V3(u.privateKey,h),signedAt:f,nonce:t}}catch{}this.send({type:"req",id:Tg(),method:"connect",params:s})}handleConnectSuccess(t){this.snapshot=t.snapshot??null,this.serverInfo=t.server??null,this.reconnectAttempt=0,this.setStatus("connected")}scheduleReconnect(){if(this.shutdownReceived)return;if(this.reconnectAttempt>=Y3){this.setStatus("disconnected");return}this.setStatus("reconnecting");const t=Math.min(Q3*Math.pow(2,this.reconnectAttempt),W3)+Math.random()*X3;this.reconnectAttempt++,this.reconnectTimer=setTimeout(()=>{this.doConnect()},t)}clearReconnectTimer(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}setStatus(t,n){this.status=t;for(const r of this.statusHandlers)r(t,n)}}let Dr=null,Ks=null,Lc=null,Rr=[];function Oe(){if(Dr)return Dr;throw new Error("GatewayAdapter not initialized. Call initAdapter() first.")}function Pe(e=15e3){return Dr?Promise.resolve(Dr):Lc?Promise.reject(Lc):new Promise((t,n)=>{const r=setTimeout(()=>{Rr=Rr.filter(u=>u.resolve!==s),n(new Error("Adapter initialization timed out"))},e),s=u=>{clearTimeout(r),t(u)},o=u=>{clearTimeout(r),n(u)};Rr.push({resolve:s,reject:o})})}async function Z3(e,t){if(Dr)return Dr;if(Ks)return Ks;Lc=null;const n=(async()=>{try{const r=e==="mock"?new z3:J3(t);return await r.connect(),Dr=r,eE(r),r}catch(r){const s=nE(r);throw Lc=s,tE(s),s}})();Ks=n;try{return await n}finally{Ks===n&&(Ks=null)}}function J3(e){if(!e)throw new Error("WsAdapter requires wsClient and rpcClient");if(!(e.wsClient instanceof P1))throw new Error("Invalid wsClient");if(!(e.rpcClient instanceof U1))throw new Error("Invalid rpcClient");return new Gh(e.wsClient,e.rpcClient)}function eE(e){for(const t of Rr)t.resolve(e);Rr=[]}function tE(e){for(const t of Rr)t.reject(e);Rr=[]}function nE(e){return e instanceof Error?e:new Error(String(e))}const aE="openclaw-office-cache",rE=1,iE=500,sE=1e3,lE=30,oE=7,eb=.8,Rt="chat_messages",Qt="event_history";class cE{constructor(t){je(this,"db",null);je(this,"available",!0);je(this,"dbName");je(this,"version");je(this,"maxMessagesPerSession");je(this,"maxEvents");je(this,"messageExpireDays");je(this,"eventExpireDays");this.dbName=(t==null?void 0:t.dbName)??aE,this.version=(t==null?void 0:t.version)??rE,this.maxMessagesPerSession=(t==null?void 0:t.maxMessagesPerSession)??iE,this.maxEvents=(t==null?void 0:t.maxEvents)??sE,this.messageExpireDays=(t==null?void 0:t.messageExpireDays)??lE,this.eventExpireDays=(t==null?void 0:t.eventExpireDays)??oE}async open(){if(!this.db)try{if(typeof indexedDB>"u"){this.available=!1;return}this.db=await new Promise((t,n)=>{const r=indexedDB.open(this.dbName,this.version);r.onupgradeneeded=()=>{const s=r.result;if(!s.objectStoreNames.contains(Rt)){const o=s.createObjectStore(Rt,{keyPath:"id"});o.createIndex("sessionKey","sessionKey",{unique:!1}),o.createIndex("timestamp","timestamp",{unique:!1}),o.createIndex("session_time",["sessionKey","timestamp"],{unique:!1})}s.objectStoreNames.contains(Qt)||s.createObjectStore(Qt,{autoIncrement:!0}).createIndex("timestamp","timestamp",{unique:!1})},r.onsuccess=()=>t(r.result),r.onerror=()=>n(r.error)})}catch{this.available=!1}}close(){this.db&&(this.db.close(),this.db=null)}async getMessages(t){if(!this.canOperate())return[];try{const s=this.db.transaction(Rt,"readonly").objectStore(Rt).index("session_time"),o=IDBKeyRange.bound([t,0],[t,Number.MAX_SAFE_INTEGER]);return(await Qa(s.getAll(o))).map(({sessionKey:f,...h})=>h)}catch{return[]}}async saveMessage(t,n){if(this.canOperate())try{if(await this.isQuotaExceeded())return;const r={...n,sessionKey:t},s=this.db.transaction(Rt,"readwrite");s.objectStore(Rt).put(r),await Vn(s),await this.enforceMessageLimit(t)}catch{}}async saveMessages(t,n){if(!(!this.canOperate()||n.length===0))try{if(await this.isQuotaExceeded())return;const r=this.db.transaction(Rt,"readwrite"),s=r.objectStore(Rt),o=s.index("sessionKey"),u=await Qa(o.getAllKeys(t));for(const y of u)s.delete(y);await Vn(r);const f=this.db.transaction(Rt,"readwrite"),h=f.objectStore(Rt),g=n.slice(-this.maxMessagesPerSession);for(const y of g)h.put({...y,sessionKey:t});await Vn(f)}catch{}}async clearMessages(t){if(this.canOperate())try{const n=this.db.transaction(Rt,"readwrite"),r=n.objectStore(Rt),s=r.index("sessionKey"),o=await Qa(s.getAllKeys(t));for(const u of o)r.delete(u);await Vn(n)}catch{}}async getEvents(t){if(!this.canOperate())return[];try{const r=this.db.transaction(Qt,"readonly").objectStore(Qt),s=await Qa(r.getAll());return s.sort((o,u)=>o.timestamp-u.timestamp),t&&s.length>t?s.slice(-t):s}catch{return[]}}async saveEvent(t){if(this.canOperate())try{if(await this.isQuotaExceeded())return;const n=this.db.transaction(Qt,"readwrite");n.objectStore(Qt).add(t),await Vn(n),await this.enforceEventLimit()}catch{}}async saveEvents(t){if(!(!this.canOperate()||t.length===0))try{if(await this.isQuotaExceeded())return;const n=this.db.transaction(Qt,"readwrite"),r=n.objectStore(Qt);for(const s of t)r.add(s);await Vn(n),await this.enforceEventLimit()}catch{}}async clearEvents(){if(this.canOperate())try{const t=this.db.transaction(Qt,"readwrite");t.objectStore(Qt).clear(),await Vn(t)}catch{}}async cleanup(){if(this.canOperate())try{const t=Date.now(),n=this.messageExpireDays*24*60*60*1e3,r=this.eventExpireDays*24*60*60*1e3,s=this.db.transaction(Rt,"readwrite"),o=s.objectStore(Rt),u=o.index("timestamp"),f=IDBKeyRange.upperBound(t-n),h=await Qa(u.getAllKeys(f));for(const k of h)o.delete(k);await Vn(s);const g=this.db.transaction(Qt,"readwrite"),y=g.objectStore(Qt),p=y.index("timestamp"),b=IDBKeyRange.upperBound(t-r),v=await Qa(p.getAllKeys(b));for(const k of v)y.delete(k);await Vn(g)}catch{}}async getStorageEstimate(){var t;try{if((t=navigator.storage)!=null&&t.estimate){const n=await navigator.storage.estimate();return{usage:n.usage??0,quota:n.quota??0}}}catch{}return{usage:0,quota:0}}canOperate(){return this.available&&this.db!==null}async isQuotaExceeded(){try{const{usage:t,quota:n}=await this.getStorageEstimate();if(n>0&&t/n>eb){await this.cleanup();const r=await this.getStorageEstimate();return r.quota>0&&r.usage/r.quota>eb}}catch{}return!1}async enforceMessageLimit(t){try{const n=this.db.transaction(Rt,"readwrite"),r=n.objectStore(Rt),s=r.index("session_time"),o=IDBKeyRange.bound([t,0],[t,Number.MAX_SAFE_INTEGER]),u=await Qa(s.getAllKeys(o));if(u.length>this.maxMessagesPerSession){const f=u.slice(0,u.length-this.maxMessagesPerSession);for(const h of f)r.delete(h);await Vn(n)}}catch{}}async enforceEventLimit(){try{const n=this.db.transaction(Qt,"readwrite").objectStore(Qt),r=await Qa(n.count());if(r>this.maxEvents){const s=r-this.maxEvents,o=n.openCursor();let u=0;await new Promise((f,h)=>{o.onsuccess=()=>{const g=o.result;g&&u<s?(g.delete(),u++,g.continue()):f()},o.onerror=()=>h(o.error)})}}catch{}}}function Qa(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function Vn(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error)})}const Wn=new cE;function tb(){const e=Date.now(),t=Math.random().toString(36).slice(2,8);return`msg-${e}-${t}`}function uE(e){return`agent:${e}:main`}function dE(e){return typeof e=="string"?e:Array.isArray(e)?e.filter(t=>t.type==="text"&&t.text).map(t=>t.text).join(`
|
|
430
|
+
Mock content for ${n}`,size:128,modifiedAt:new Date().toISOString()}}}async agentsFilesSet(t,n,r){return{ok:!0,agentId:t,workspace:"~/.openclaw/workspace",file:{name:n,size:r.length,modifiedAt:new Date().toISOString()}}}async toolsCatalog(t){return{tools:[{name:"web_search",description:"搜索互联网",source:"built-in",group:"core",enabled:!0},{name:"code_exec",description:"执行代码",source:"built-in",group:"core",enabled:!0},{name:"file_read",description:"读取文件内容",source:"built-in",group:"fs",enabled:!0},{name:"file_write",description:"写入文件",source:"built-in",group:"fs",enabled:!0},{name:"bash",description:"执行 Bash 命令",source:"built-in",group:"exec",enabled:!0,optional:!0},{name:"mcp_client",description:"MCP 协议客户端",source:"plugin",group:"integrations",enabled:!1,optional:!0}]}}async usageStatus(){return{updatedAt:Date.now(),providers:[{provider:"anthropic",displayName:"Anthropic",plan:"pro",windows:[{label:"daily",usedPercent:45,resetAt:Date.now()+12*36e5},{label:"monthly",usedPercent:22}]},{provider:"openai",displayName:"OpenAI",plan:"tier-3",windows:[{label:"daily",usedPercent:12}]}]}}async modelsList(){return[{id:"claude-sonnet-4-20250514",name:"Claude Sonnet 4",provider:"anthropic",reasoning:!0,input:["text","image"],contextWindow:2e5},{id:"claude-opus-4-20250514",name:"Claude Opus 4",provider:"anthropic",reasoning:!0,input:["text","image"],contextWindow:2e5},{id:"gpt-4o",name:"GPT-4o",provider:"openai",reasoning:!1,input:["text","image"],contextWindow:128e3},{id:"o3",name:"o3",provider:"openai",reasoning:!0,input:["text","image"],contextWindow:2e5},{id:"gpt-5.3-codex",name:"gpt-5.3-codex",provider:"openai-codex",reasoning:!0,input:["text"],contextWindow:1048576},{id:"gpt-5.3-codex-spark",name:"gpt-5.3-codex-spark",provider:"openai-codex",reasoning:!0,input:["text"],contextWindow:1048576},{id:"gpt-5.1-codex",name:"gpt-5.1-codex",provider:"openai-codex",reasoning:!0,input:["text"],contextWindow:2e5}]}async configGet(){return{config:this.mockConfig,hash:this.mockHash,raw:JSON.stringify(this.mockConfig,null,2),valid:!0,path:"~/.openclaw/openclaw.json"}}async configSet(t,n){return n&&n!==this.mockHash?{ok:!1,path:"~/.openclaw/openclaw.json",config:this.mockConfig,error:"config changed since last load; re-run config.get and retry"}:(this.mockConfig=JSON.parse(t),this.mockHash=Date.now().toString(36),{ok:!0,path:"~/.openclaw/openclaw.json",config:this.mockConfig})}async configApply(t,n,r){return n&&n!==this.mockHash?{ok:!1,path:"~/.openclaw/openclaw.json",config:this.mockConfig,error:"config changed since last load; re-run config.get and retry"}:(this.mockConfig=JSON.parse(t),this.mockHash=Date.now().toString(36),{ok:!0,path:"~/.openclaw/openclaw.json",config:this.mockConfig,restart:{scheduled:!0,delayMs:2e3}})}async configPatch(t,n){if(n&&n!==this.mockHash)return{ok:!1,config:this.mockConfig,error:"config changed since last load; re-run config.get and retry"};const r=JSON.parse(t);return this.mockConfig=B1(this.mockConfig,r),this.mockHash=Date.now().toString(36),{ok:!0,config:this.mockConfig,restart:{scheduled:!0,delayMs:2e3}}}async configSchema(){return{schema:{},uiHints:{"models.providers.*.apiKey":{sensitive:!0,label:"API Key"},"gateway.auth.token":{sensitive:!0,label:"Gateway Token"}},version:"mock"}}async statusSummary(){return{version:"2026.2.27-mock",port:18789,uptime:86400,mode:"local",pid:12345,nodeVersion:"v22.0.0",platform:"darwin"}}async updateRun(t){return{ok:!0,result:{status:"noop",mode:"npm",reason:"already up to date",steps:[],durationMs:1200},restart:null}}}function Tg(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();const e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;const t=Array.from(e,n=>n.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}const I3=1e4;class Wf extends Error{constructor(t,n){super(n),this.code=t,this.name="RpcError"}}class U1{constructor(t){this.wsClient=t}request(t,n={},r=I3){return new Promise((s,o)=>{if(!this.wsClient.isConnected()){o(new Wf("NOT_CONNECTED","WebSocket is not connected"));return}const u=Tg();let f=null;const h=()=>{f&&(clearTimeout(f),f=null)};this.wsClient.onResponse(u,g=>{h(),g.ok?s(g.payload):o(new Wf(g.error.code,g.error.message))}),f=setTimeout(()=>{o(new Wf("TIMEOUT",`RPC request timed out: ${t}`))},r),this.wsClient.send({type:"req",id:u,method:t,params:n})})}}const Qc=class Qc{constructor(t,n){je(this,"handlers",new Set);je(this,"unsubscribers",[]);this.wsClient=t,this.rpcClient=n}async connect(){for(const t of Qc.WATCHED_EVENTS){const n=this.wsClient.onEvent(t,r=>{for(const s of this.handlers)s(t,r)});this.unsubscribers.push(n)}}disconnect(){for(const t of this.unsubscribers)t();this.unsubscribers=[],this.handlers.clear()}onEvent(t){return this.handlers.add(t),()=>{this.handlers.delete(t)}}async chatHistory(t){return this.rpcClient.request("chat.history",t?{sessionKey:t}:{})}async chatSend(t){await this.rpcClient.request("chat.send",{sessionKey:t.sessionKey,message:t.text,deliver:!1,idempotencyKey:Tg()})}async chatAbort(t){await this.rpcClient.request("chat.abort",{sessionKey:t})}async sessionsList(){const t=await this.rpcClient.request("sessions.list");return Array.isArray(t)?t:(t==null?void 0:t.sessions)??[]}async sessionsPreview(t){return this.rpcClient.request("sessions.preview",{sessionKey:t})}async sessionsDelete(t,n){await this.rpcClient.request("sessions.delete",{key:t,...(n==null?void 0:n.deleteTranscript)!=null?{deleteTranscript:n.deleteTranscript}:{}})}async channelsStatus(){const t=await this.rpcClient.request("channels.status",{probe:!0});return $3(t)}async channelsLogout(t,n){return this.rpcClient.request("channels.logout",{channel:t,accountId:n})}async webLoginStart(t){return this.rpcClient.request("web.login.start",{force:t})}async webLoginWait(){return this.rpcClient.request("web.login.wait")}async skillsStatus(t){const n=t?{agentId:t}:void 0,r=await this.rpcClient.request("skills.status",n);return q3(r.skills??[])}async skillsInstall(t,n){return this.rpcClient.request("skills.install",{name:t,installId:n})}async skillsUpdate(t,n){return this.rpcClient.request("skills.update",{skillKey:t,...n})}async cronList(){return(await this.rpcClient.request("cron.list")).jobs??[]}async cronAdd(t){return this.rpcClient.request("cron.add",t)}async cronUpdate(t,n){return this.rpcClient.request("cron.update",{id:t,patch:n})}async cronRemove(t){await this.rpcClient.request("cron.remove",{id:t})}async cronRun(t){await this.rpcClient.request("cron.run",{id:t})}async agentsList(){return this.rpcClient.request("agents.list")}async agentsCreate(t){return this.rpcClient.request("agents.create",t)}async agentsUpdate(t){return this.rpcClient.request("agents.update",t)}async agentsDelete(t){return this.rpcClient.request("agents.delete",t)}async agentsFilesList(t){return this.rpcClient.request("agents.files.list",{agentId:t})}async agentsFilesGet(t,n){return this.rpcClient.request("agents.files.get",{agentId:t,name:n})}async agentsFilesSet(t,n,r){return this.rpcClient.request("agents.files.set",{agentId:t,name:n,content:r})}async toolsCatalog(t){const n=t?{agentId:t}:void 0;return this.rpcClient.request("tools.catalog",n)}async usageStatus(){return this.rpcClient.request("usage.status")}async modelsList(){return(await this.rpcClient.request("models.list")).models??[]}async configGet(){return this.rpcClient.request("config.get")}async configSet(t,n){const r=await this.rpcClient.request("config.set",{raw:t,...n?{baseHash:n}:{}});return Jx(r)}async configApply(t,n,r){const s=await this.rpcClient.request("config.apply",{raw:t,...n?{baseHash:n}:{},...r!=null&&r.sessionKey?{sessionKey:r.sessionKey}:{},...r!=null&&r.note?{note:r.note}:{},...(r==null?void 0:r.restartDelayMs)!=null?{restartDelayMs:r.restartDelayMs}:{}});return Jx(s)}async configPatch(t,n){const r=await this.rpcClient.request("config.patch",{raw:t,...n?{baseHash:n}:{}});return H3(r)}async configSchema(){return this.rpcClient.request("config.schema")}async statusSummary(){const t=this.wsClient.getSnapshot(),n=this.wsClient.getServerInfo();return{version:n==null?void 0:n.version,port:18789,uptime:(t==null?void 0:t.uptimeMs)!=null?Math.floor(t.uptimeMs/1e3):void 0,mode:"local",configPath:t==null?void 0:t.configPath}}async updateRun(t){const n=await this.rpcClient.request("update.run",t??{});return B3(n)}};je(Qc,"WATCHED_EVENTS",["agent","chat","presence","health","heartbeat","cron","shutdown"]);let Gh=Qc;function Dg(e){if(!e.restart)return e;const t=e.restart;return{...e,restart:{scheduled:t.ok!==!1,delayMs:t.delayMs??0,...t.coalesced!=null?{coalesced:t.coalesced}:{}}}}function Jx(e){return Dg(e)}function H3(e){return Dg(e)}function B3(e){return Dg(e)}function U3(e){return e.error??e.lastError??void 0?"error":e.connected===!0?"connected":e.connected===!1?e.running?"connecting":"disconnected":e.running&&e.linked!==!1&&e.configured!==!1?"connected":e.running?"connecting":"disconnected"}function $3(e){const t=e.channelAccounts??{},n=e.channelLabels??{},r=[];for(const[s,o]of Object.entries(t))for(const u of o)!u.accountId&&o.length===0||r.push({id:u.accountId?`${s}:${u.accountId}`:s,type:s,name:u.name??n[s]??s,status:U3(u),accountId:u.accountId,error:u.error??u.lastError??void 0,configured:u.configured,linked:u.linked,running:u.running,lastConnectedAt:u.lastConnectedAt,lastMessageAt:u.lastMessageAt,reconnectAttempts:u.reconnectAttempts,mode:u.mode});return r}function q3(e){return e.map(t=>({id:t.skillKey??"",slug:t.skillKey??"",name:t.name??t.skillKey??"",description:t.description??"",enabled:!t.disabled,icon:t.emoji??"📦",version:t.version??"",author:t.author,isCore:t.core,isBundled:t.bundled,config:t.config,source:t.source,homepage:t.homepage,primaryEnv:t.primaryEnv,always:t.always,eligible:t.eligible,blockedByAllowlist:t.blockedByAllowlist,requirements:t.requirements,missing:t.missing,installOptions:t.install,configChecks:t.configChecks}))}function K3(e){return["v2",e.deviceId,e.clientId,e.clientMode,e.role,e.scopes.join(","),String(e.signedAtMs),e.token??"",e.nonce].join("|")}const Xf="openclaw-office.device-identity.v1";function Vh(e){let t="";for(const n of e)t+=String.fromCharCode(n);return btoa(t).replaceAll("+","-").replaceAll("/","_").replace(/=+$/g,"")}function $1(e){const t=e.replaceAll("-","+").replaceAll("_","/"),n=t+"=".repeat((4-t.length%4)%4),r=atob(n);return Uint8Array.from(r,s=>s.charCodeAt(0))}function P3(e){return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function q1(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}async function K1(e){const t=await crypto.subtle.digest("SHA-256",q1(e));return P3(new Uint8Array(t))}async function F3(){const e=await crypto.subtle.generateKey("Ed25519",!0,["sign","verify"]),t=new Uint8Array(await crypto.subtle.exportKey("raw",e.publicKey)),n=new Uint8Array(await crypto.subtle.exportKey("pkcs8",e.privateKey));return{deviceId:await K1(t),publicKey:Vh(t),privateKey:Vh(n)}}async function G3(){try{const t=localStorage.getItem(Xf);if(t){const n=JSON.parse(t);if((n==null?void 0:n.version)===1&&typeof n.deviceId=="string"&&typeof n.publicKey=="string"&&typeof n.privateKey=="string"){const r=await K1($1(n.publicKey));return r!==n.deviceId?(localStorage.setItem(Xf,JSON.stringify({...n,deviceId:r})),{deviceId:r,publicKey:n.publicKey,privateKey:n.privateKey}):{deviceId:n.deviceId,publicKey:n.publicKey,privateKey:n.privateKey}}}}catch{}const e=await F3();return localStorage.setItem(Xf,JSON.stringify({version:1,deviceId:e.deviceId,publicKey:e.publicKey,privateKey:e.privateKey,createdAtMs:Date.now()})),e}async function V3(e,t){const n=await crypto.subtle.importKey("pkcs8",q1($1(e)),"Ed25519",!1,["sign"]),r=await crypto.subtle.sign("Ed25519",n,new TextEncoder().encode(t));return Vh(new Uint8Array(r))}const Y3=20,Q3=1e3,W3=3e4,X3=1e3;class P1{constructor(){je(this,"ws",null);je(this,"url","");je(this,"token","");je(this,"status","disconnected");je(this,"reconnectAttempt",0);je(this,"reconnectTimer",null);je(this,"shutdownReceived",!1);je(this,"eventHandlers",new Map);je(this,"statusHandlers",new Set);je(this,"responseHandlers",new Map);je(this,"snapshot",null);je(this,"serverInfo",null);je(this,"authInfo",null);je(this,"handleClose",()=>{})}getStatus(){return this.status}getSnapshot(){return this.snapshot}getAuthInfo(){return this.authInfo}getServerInfo(){return this.serverInfo}isConnected(){var t;return this.status==="connected"&&((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN}connect(t,n){this.url=t,this.token=n,this.shutdownReceived=!1,this.reconnectAttempt=0,this.doConnect()}disconnect(){this.shutdownReceived=!0,this.clearReconnectTimer(),this.ws&&(this.ws.removeEventListener("close",this.handleClose),this.ws.close(),this.ws=null),this.setStatus("disconnected")}onEvent(t,n){let r=this.eventHandlers.get(t);return r||(r=new Set,this.eventHandlers.set(t,r)),r.add(n),()=>r.delete(n)}onStatusChange(t){return this.statusHandlers.add(t),()=>this.statusHandlers.delete(t)}onResponse(t,n){this.responseHandlers.set(t,n)}send(t){var n;((n=this.ws)==null?void 0:n.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify(t))}doConnect(){this.setStatus(this.reconnectAttempt>0?"reconnecting":"connecting");try{this.ws=new WebSocket(this.url)}catch{this.scheduleReconnect();return}this.handleClose=()=>{this.shutdownReceived||this.scheduleReconnect()},this.ws.addEventListener("open",()=>{}),this.ws.addEventListener("message",t=>{this.handleMessage(t)}),this.ws.addEventListener("close",this.handleClose),this.ws.addEventListener("error",()=>{})}handleMessage(t){let n;try{n=JSON.parse(t.data)}catch{return}if(n.type==="event"){const r=n;this.handleEvent(r)}else if(n.type==="res"){const r=n;this.handleResponse(r)}}handleEvent(t){if(t.event==="connect.challenge"){const s=typeof t.payload=="object"&&t.payload!==null&&"nonce"in t.payload&&typeof t.payload.nonce=="string"?t.payload.nonce:"";this.sendConnect(s);return}t.event==="shutdown"&&(this.shutdownReceived=!0,this.clearReconnectTimer(),this.setStatus("disconnected"));const n=this.eventHandlers.get(t.event);if(n)for(const s of n)s(t);const r=this.eventHandlers.get("*");if(r)for(const s of r)s(t)}handleResponse(t){var r;const n=this.responseHandlers.get(t.id);if(n){this.responseHandlers.delete(t.id),n(t);return}t.ok&&((r=t.payload)==null?void 0:r.type)==="hello-ok"?this.handleConnectSuccess(t.payload):t.ok||this.setStatus("error",t.error.message)}async sendConnect(t){const n="operator",r=["operator.admin","operator.read"],s={minProtocol:3,maxProtocol:3,role:n,client:{id:"openclaw-control-ui",version:"0.1.0",platform:"web",mode:"ui"},caps:["tool-events"],scopes:r,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,locale:typeof navigator<"u"?navigator.language:void 0};if(this.token&&(s.auth={token:this.token}),typeof window<"u"&&window.isSecureContext&&typeof crypto<"u"&&typeof crypto.subtle<"u")try{const u=await G3(),f=Date.now(),h=K3({deviceId:u.deviceId,clientId:s.client.id,clientMode:s.client.mode,role:n,scopes:r,signedAtMs:f,token:this.token||null,nonce:t});s.device={id:u.deviceId,publicKey:u.publicKey,signature:await V3(u.privateKey,h),signedAt:f,nonce:t}}catch{}this.send({type:"req",id:Tg(),method:"connect",params:s})}handleConnectSuccess(t){this.snapshot=t.snapshot??null,this.serverInfo=t.server??null,this.authInfo=t.auth??null,this.reconnectAttempt=0,this.setStatus("connected")}scheduleReconnect(){if(this.shutdownReceived)return;if(this.reconnectAttempt>=Y3){this.setStatus("disconnected");return}this.setStatus("reconnecting");const t=Math.min(Q3*Math.pow(2,this.reconnectAttempt),W3)+Math.random()*X3;this.reconnectAttempt++,this.reconnectTimer=setTimeout(()=>{this.doConnect()},t)}clearReconnectTimer(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}setStatus(t,n){this.status=t;for(const r of this.statusHandlers)r(t,n)}}let Dr=null,Ks=null,Lc=null,Rr=[];function Oe(){if(Dr)return Dr;throw new Error("GatewayAdapter not initialized. Call initAdapter() first.")}function Pe(e=15e3){return Dr?Promise.resolve(Dr):Lc?Promise.reject(Lc):new Promise((t,n)=>{const r=setTimeout(()=>{Rr=Rr.filter(u=>u.resolve!==s),n(new Error("Adapter initialization timed out"))},e),s=u=>{clearTimeout(r),t(u)},o=u=>{clearTimeout(r),n(u)};Rr.push({resolve:s,reject:o})})}async function Z3(e,t){if(Dr)return Dr;if(Ks)return Ks;Lc=null;const n=(async()=>{try{const r=e==="mock"?new z3:J3(t);return await r.connect(),Dr=r,eE(r),r}catch(r){const s=nE(r);throw Lc=s,tE(s),s}})();Ks=n;try{return await n}finally{Ks===n&&(Ks=null)}}function J3(e){if(!e)throw new Error("WsAdapter requires wsClient and rpcClient");if(!(e.wsClient instanceof P1))throw new Error("Invalid wsClient");if(!(e.rpcClient instanceof U1))throw new Error("Invalid rpcClient");return new Gh(e.wsClient,e.rpcClient)}function eE(e){for(const t of Rr)t.resolve(e);Rr=[]}function tE(e){for(const t of Rr)t.reject(e);Rr=[]}function nE(e){return e instanceof Error?e:new Error(String(e))}const aE="openclaw-office-cache",rE=1,iE=500,sE=1e3,lE=30,oE=7,eb=.8,Rt="chat_messages",Qt="event_history";class cE{constructor(t){je(this,"db",null);je(this,"available",!0);je(this,"dbName");je(this,"version");je(this,"maxMessagesPerSession");je(this,"maxEvents");je(this,"messageExpireDays");je(this,"eventExpireDays");this.dbName=(t==null?void 0:t.dbName)??aE,this.version=(t==null?void 0:t.version)??rE,this.maxMessagesPerSession=(t==null?void 0:t.maxMessagesPerSession)??iE,this.maxEvents=(t==null?void 0:t.maxEvents)??sE,this.messageExpireDays=(t==null?void 0:t.messageExpireDays)??lE,this.eventExpireDays=(t==null?void 0:t.eventExpireDays)??oE}async open(){if(!this.db)try{if(typeof indexedDB>"u"){this.available=!1;return}this.db=await new Promise((t,n)=>{const r=indexedDB.open(this.dbName,this.version);r.onupgradeneeded=()=>{const s=r.result;if(!s.objectStoreNames.contains(Rt)){const o=s.createObjectStore(Rt,{keyPath:"id"});o.createIndex("sessionKey","sessionKey",{unique:!1}),o.createIndex("timestamp","timestamp",{unique:!1}),o.createIndex("session_time",["sessionKey","timestamp"],{unique:!1})}s.objectStoreNames.contains(Qt)||s.createObjectStore(Qt,{autoIncrement:!0}).createIndex("timestamp","timestamp",{unique:!1})},r.onsuccess=()=>t(r.result),r.onerror=()=>n(r.error)})}catch{this.available=!1}}close(){this.db&&(this.db.close(),this.db=null)}async getMessages(t){if(!this.canOperate())return[];try{const s=this.db.transaction(Rt,"readonly").objectStore(Rt).index("session_time"),o=IDBKeyRange.bound([t,0],[t,Number.MAX_SAFE_INTEGER]);return(await Qa(s.getAll(o))).map(({sessionKey:f,...h})=>h)}catch{return[]}}async saveMessage(t,n){if(this.canOperate())try{if(await this.isQuotaExceeded())return;const r={...n,sessionKey:t},s=this.db.transaction(Rt,"readwrite");s.objectStore(Rt).put(r),await Vn(s),await this.enforceMessageLimit(t)}catch{}}async saveMessages(t,n){if(!(!this.canOperate()||n.length===0))try{if(await this.isQuotaExceeded())return;const r=this.db.transaction(Rt,"readwrite"),s=r.objectStore(Rt),o=s.index("sessionKey"),u=await Qa(o.getAllKeys(t));for(const y of u)s.delete(y);await Vn(r);const f=this.db.transaction(Rt,"readwrite"),h=f.objectStore(Rt),g=n.slice(-this.maxMessagesPerSession);for(const y of g)h.put({...y,sessionKey:t});await Vn(f)}catch{}}async clearMessages(t){if(this.canOperate())try{const n=this.db.transaction(Rt,"readwrite"),r=n.objectStore(Rt),s=r.index("sessionKey"),o=await Qa(s.getAllKeys(t));for(const u of o)r.delete(u);await Vn(n)}catch{}}async getEvents(t){if(!this.canOperate())return[];try{const r=this.db.transaction(Qt,"readonly").objectStore(Qt),s=await Qa(r.getAll());return s.sort((o,u)=>o.timestamp-u.timestamp),t&&s.length>t?s.slice(-t):s}catch{return[]}}async saveEvent(t){if(this.canOperate())try{if(await this.isQuotaExceeded())return;const n=this.db.transaction(Qt,"readwrite");n.objectStore(Qt).add(t),await Vn(n),await this.enforceEventLimit()}catch{}}async saveEvents(t){if(!(!this.canOperate()||t.length===0))try{if(await this.isQuotaExceeded())return;const n=this.db.transaction(Qt,"readwrite"),r=n.objectStore(Qt);for(const s of t)r.add(s);await Vn(n),await this.enforceEventLimit()}catch{}}async clearEvents(){if(this.canOperate())try{const t=this.db.transaction(Qt,"readwrite");t.objectStore(Qt).clear(),await Vn(t)}catch{}}async cleanup(){if(this.canOperate())try{const t=Date.now(),n=this.messageExpireDays*24*60*60*1e3,r=this.eventExpireDays*24*60*60*1e3,s=this.db.transaction(Rt,"readwrite"),o=s.objectStore(Rt),u=o.index("timestamp"),f=IDBKeyRange.upperBound(t-n),h=await Qa(u.getAllKeys(f));for(const k of h)o.delete(k);await Vn(s);const g=this.db.transaction(Qt,"readwrite"),y=g.objectStore(Qt),p=y.index("timestamp"),b=IDBKeyRange.upperBound(t-r),v=await Qa(p.getAllKeys(b));for(const k of v)y.delete(k);await Vn(g)}catch{}}async getStorageEstimate(){var t;try{if((t=navigator.storage)!=null&&t.estimate){const n=await navigator.storage.estimate();return{usage:n.usage??0,quota:n.quota??0}}}catch{}return{usage:0,quota:0}}canOperate(){return this.available&&this.db!==null}async isQuotaExceeded(){try{const{usage:t,quota:n}=await this.getStorageEstimate();if(n>0&&t/n>eb){await this.cleanup();const r=await this.getStorageEstimate();return r.quota>0&&r.usage/r.quota>eb}}catch{}return!1}async enforceMessageLimit(t){try{const n=this.db.transaction(Rt,"readwrite"),r=n.objectStore(Rt),s=r.index("session_time"),o=IDBKeyRange.bound([t,0],[t,Number.MAX_SAFE_INTEGER]),u=await Qa(s.getAllKeys(o));if(u.length>this.maxMessagesPerSession){const f=u.slice(0,u.length-this.maxMessagesPerSession);for(const h of f)r.delete(h);await Vn(n)}}catch{}}async enforceEventLimit(){try{const n=this.db.transaction(Qt,"readwrite").objectStore(Qt),r=await Qa(n.count());if(r>this.maxEvents){const s=r-this.maxEvents,o=n.openCursor();let u=0;await new Promise((f,h)=>{o.onsuccess=()=>{const g=o.result;g&&u<s?(g.delete(),u++,g.continue()):f()},o.onerror=()=>h(o.error)})}}catch{}}}function Qa(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}function Vn(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error)})}const Wn=new cE;function tb(){const e=Date.now(),t=Math.random().toString(36).slice(2,8);return`msg-${e}-${t}`}function uE(e){return`agent:${e}:main`}function dE(e){return typeof e=="string"?e:Array.isArray(e)?e.filter(t=>t.type==="text"&&t.text).map(t=>t.text).join(`
|
|
431
431
|
`):""}Wn.open().catch(()=>{});const Qe=Mn((e,t)=>({messages:[],isStreaming:!1,currentSessionKey:"agent:main:main",dockExpanded:!1,targetAgentId:null,sessions:[],error:null,activeRunId:null,streamingMessage:null,isHistoryLoaded:!1,isHistoryLoading:!1,sendMessage:async n=>{const r=n.trim();if(!r)return;const{currentSessionKey:s}=t(),o={id:tb(),role:"user",content:r,timestamp:Date.now()};e(u=>({messages:[...u.messages,o],isStreaming:!0,dockExpanded:!0,error:null,streamingMessage:null})),Wn.saveMessage(s,o).catch(()=>{});try{let u;try{u=Oe()}catch(f){console.error("[ChatDock] Adapter not initialized:",f),e({error:we.t("common:errors.adapterNotInitialized"),isStreaming:!1});return}console.log("[ChatDock] Sending chat.send:",{text:r,sessionKey:s}),await u.chatSend({text:r,sessionKey:s}),console.log("[ChatDock] chat.send completed")}catch(u){console.error("[ChatDock] chat.send error:",u),e({error:String(u),isStreaming:!1})}},abort:async()=>{const{currentSessionKey:n}=t();e({isStreaming:!1,streamingMessage:null});try{await Oe().chatAbort(n)}catch(r){e({error:String(r)})}},toggleDock:()=>{e(n=>({dockExpanded:!n.dockExpanded}))},setDockExpanded:n=>{e({dockExpanded:n})},switchSession:n=>{e({currentSessionKey:n,messages:[],streamingMessage:null,activeRunId:null,error:null,isStreaming:!1,isHistoryLoaded:!1}),t().initializeHistory()},newSession:()=>{const{targetAgentId:n}=t(),s=`agent:${n??"main"}:session-${Date.now()}`;e({currentSessionKey:s,messages:[],streamingMessage:null,activeRunId:null,error:null,isStreaming:!1})},loadSessions:async()=>{try{const r=await Oe().sessionsList();e({sessions:Array.isArray(r)?r:[]})}catch{}},loadHistory:async()=>{const{currentSessionKey:n}=t();try{const o=(await Oe().chatHistory(n)).map(u=>({id:u.id,role:u.role==="user"?"user":"assistant",content:u.content,timestamp:u.timestamp}));e({messages:o}),Wn.saveMessages(n,o).catch(()=>{})}catch{e({messages:[]})}},initializeHistory:async()=>{const{currentSessionKey:n}=t();e({isHistoryLoading:!0});try{const o=(await Oe().chatHistory(n)).map(u=>({id:u.id,role:u.role==="user"?"user":"assistant",content:u.content,timestamp:u.timestamp}));e({messages:o,isHistoryLoaded:!0,isHistoryLoading:!1}),Wn.saveMessages(n,o).catch(()=>{})}catch{try{const r=await Wn.getMessages(n);e({messages:r,isHistoryLoaded:!0,isHistoryLoading:!1})}catch{e({messages:[],isHistoryLoaded:!0,isHistoryLoading:!1})}}},setTargetAgent:n=>{const r=uE(n);e({targetAgentId:n,currentSessionKey:r,messages:[],streamingMessage:null,activeRunId:null,error:null,isStreaming:!1,isHistoryLoaded:!1}),t().initializeHistory()},handleChatEvent:n=>{const r=String(n.state||""),s=String(n.runId||""),o=n.message;let u=r;switch(!u&&o&&(o.stopReason??o.stop_reason?u="final":(o.role||o.content)&&(u="delta")),u){case"delta":{o&&e({streamingMessage:o,activeRunId:s||t().activeRunId});break}case"final":{if(o){const f=dE(o.content);if(f){const h={id:o.id||tb(),role:"assistant",content:f,timestamp:Date.now()};e(y=>({messages:[...y.messages,h],isStreaming:!1,streamingMessage:null,activeRunId:null}));const{currentSessionKey:g}=t();Wn.saveMessage(g,h).catch(()=>{})}else e({isStreaming:!1,streamingMessage:null,activeRunId:null}),t().loadHistory()}else e({isStreaming:!1,streamingMessage:null,activeRunId:null}),t().loadHistory();break}case"error":{const f=String(n.errorMessage||we.t("common:errors.errorOccurred"));e({error:f,isStreaming:!1,streamingMessage:null,activeRunId:null});break}case"aborted":{e({isStreaming:!1,streamingMessage:null,activeRunId:null});break}default:{t().isStreaming&&o&&e({streamingMessage:o});break}}},clearError:()=>e({error:null}),initEventListeners:n=>n?n.onEvent("chat",s=>{const o=s.payload;t().handleChatEvent(o)}):()=>{}}));var F1=Symbol.for("immer-nothing"),nb=Symbol.for("immer-draftable"),Ye=Symbol.for("immer-state");function Nn(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var yl=Object.getPrototypeOf;function zi(e){return!!e&&!!e[Ye]}function wa(e){var t;return e?G1(e)||Array.isArray(e)||!!e[nb]||!!((t=e.constructor)!=null&&t[nb])||Rl(e)||lu(e):!1}var fE=Object.prototype.constructor.toString(),ab=new WeakMap;function G1(e){if(!e||typeof e!="object")return!1;const t=Object.getPrototypeOf(e);if(t===null||t===Object.prototype)return!0;const n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;if(n===Object)return!0;if(typeof n!="function")return!1;let r=ab.get(n);return r===void 0&&(r=Function.toString.call(n),ab.set(n,r)),r===fE}function xl(e,t,n=!0){su(e)===0?(n?Reflect.ownKeys(e):Object.keys(e)).forEach(s=>{t(s,e[s],e)}):e.forEach((r,s)=>t(s,r,e))}function su(e){const t=e[Ye];return t?t.type_:Array.isArray(e)?1:Rl(e)?2:lu(e)?3:0}function Yh(e,t){return su(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function V1(e,t,n){const r=su(e);r===2?e.set(t,n):r===3?e.add(n):e[t]=n}function hE(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function Rl(e){return e instanceof Map}function lu(e){return e instanceof Set}function St(e){return e.copy_||e.base_}function Qh(e,t){if(Rl(e))return new Map(e);if(lu(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const n=G1(e);if(t===!0||t==="class_only"&&!n){const r=Object.getOwnPropertyDescriptors(e);delete r[Ye];let s=Reflect.ownKeys(r);for(let o=0;o<s.length;o++){const u=s[o],f=r[u];f.writable===!1&&(f.writable=!0,f.configurable=!0),(f.get||f.set)&&(r[u]={configurable:!0,writable:!0,enumerable:f.enumerable,value:e[u]})}return Object.create(yl(e),r)}else{const r=yl(e);if(r!==null&&n)return{...e};const s=Object.create(r);return Object.assign(s,e)}}function Rg(e,t=!1){return ou(e)||zi(e)||!wa(e)||(su(e)>1&&Object.defineProperties(e,{set:ic,add:ic,clear:ic,delete:ic}),Object.freeze(e),t&&Object.values(e).forEach(n=>Rg(n,!0))),e}function gE(){Nn(2)}var ic={value:gE};function ou(e){return e===null||typeof e!="object"?!0:Object.isFrozen(e)}var Wh={};function Or(e){const t=Wh[e];return t||Nn(0,e),t}function mE(e,t){Wh[e]||(Wh[e]=t)}var bl;function zc(){return bl}function pE(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function rb(e,t){t&&(Or("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function Xh(e){Zh(e),e.drafts_.forEach(yE),e.drafts_=null}function Zh(e){e===bl&&(bl=e.parent_)}function ib(e){return bl=pE(bl,e)}function yE(e){const t=e[Ye];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function sb(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];return e!==void 0&&e!==n?(n[Ye].modified_&&(Xh(t),Nn(4)),wa(e)&&(e=Ic(t,e),t.parent_||Hc(t,e)),t.patches_&&Or("Patches").generateReplacementPatches_(n[Ye].base_,e,t.patches_,t.inversePatches_)):e=Ic(t,n,[]),Xh(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==F1?e:void 0}function Ic(e,t,n){if(ou(t))return t;const r=e.immer_.shouldUseStrictIteration(),s=t[Ye];if(!s)return xl(t,(o,u)=>lb(e,s,t,o,u,n),r),t;if(s.scope_!==e)return t;if(!s.modified_)return Hc(e,s.base_,!0),s.base_;if(!s.finalized_){s.finalized_=!0,s.scope_.unfinalizedDrafts_--;const o=s.copy_;let u=o,f=!1;s.type_===3&&(u=new Set(o),o.clear(),f=!0),xl(u,(h,g)=>lb(e,s,o,h,g,n,f),r),Hc(e,o,!1),n&&e.patches_&&Or("Patches").generatePatches_(s,n,e.patches_,e.inversePatches_)}return s.copy_}function lb(e,t,n,r,s,o,u){if(s==null||typeof s!="object"&&!u)return;const f=ou(s);if(!(f&&!u)){if(zi(s)){const h=o&&t&&t.type_!==3&&!Yh(t.assigned_,r)?o.concat(r):void 0,g=Ic(e,s,h);if(V1(n,r,g),zi(g))e.canAutoFreeze_=!1;else return}else u&&n.add(s);if(wa(s)&&!f){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||t&&t.base_&&t.base_[r]===s&&f)return;Ic(e,s),(!t||!t.scope_.parent_)&&typeof r!="symbol"&&(Rl(n)?n.has(r):Object.prototype.propertyIsEnumerable.call(n,r))&&Hc(e,s)}}}function Hc(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Rg(t,n)}function xE(e,t){const n=Array.isArray(e),r={type_:n?1:0,scope_:t?t.scope_:zc(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let s=r,o=Mg;n&&(s=[r],o=vl);const{revoke:u,proxy:f}=Proxy.revocable(s,o);return r.draft_=f,r.revoke_=u,f}var Mg={get(e,t){if(t===Ye)return e;const n=St(e);if(!Yh(n,t))return bE(e,n,t);const r=n[t];return e.finalized_||!wa(r)?r:r===Zf(e.base_,t)?(Jf(e),e.copy_[t]=kl(r,e)):r},has(e,t){return t in St(e)},ownKeys(e){return Reflect.ownKeys(St(e))},set(e,t,n){const r=Y1(St(e),t);if(r!=null&&r.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){const s=Zf(St(e),t),o=s==null?void 0:s[Ye];if(o&&o.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(hE(n,s)&&(n!==void 0||Yh(e.base_,t)))return!0;Jf(e),va(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_[t]=!0),!0},deleteProperty(e,t){return Zf(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,Jf(e),va(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const n=St(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:r.enumerable,value:n[t]}},defineProperty(){Nn(11)},getPrototypeOf(e){return yl(e.base_)},setPrototypeOf(){Nn(12)}},vl={};xl(Mg,(e,t)=>{vl[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});vl.deleteProperty=function(e,t){return vl.set.call(this,e,t,void 0)};vl.set=function(e,t,n){return Mg.set.call(this,e[0],t,n,e[0])};function Zf(e,t){const n=e[Ye];return(n?St(n):e)[t]}function bE(e,t,n){var s;const r=Y1(t,n);return r?"value"in r?r.value:(s=r.get)==null?void 0:s.call(e.draft_):void 0}function Y1(e,t){if(!(t in e))return;let n=yl(e);for(;n;){const r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=yl(n)}}function va(e){e.modified_||(e.modified_=!0,e.parent_&&va(e.parent_))}function Jf(e){e.copy_||(e.copy_=Qh(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var vE=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(t,n,r)=>{if(typeof t=="function"&&typeof n!="function"){const o=n;n=t;const u=this;return function(h=o,...g){return u.produce(h,y=>n.call(this,y,...g))}}typeof n!="function"&&Nn(6),r!==void 0&&typeof r!="function"&&Nn(7);let s;if(wa(t)){const o=ib(this),u=kl(t,void 0);let f=!0;try{s=n(u),f=!1}finally{f?Xh(o):Zh(o)}return rb(o,r),sb(s,o)}else if(!t||typeof t!="object"){if(s=n(t),s===void 0&&(s=t),s===F1&&(s=void 0),this.autoFreeze_&&Rg(s,!0),r){const o=[],u=[];Or("Patches").generateReplacementPatches_(t,s,o,u),r(o,u)}return s}else Nn(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(u,...f)=>this.produceWithPatches(u,h=>t(h,...f));let r,s;return[this.produce(t,n,(u,f)=>{r=u,s=f}),r,s]},typeof(e==null?void 0:e.autoFreeze)=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof(e==null?void 0:e.useStrictShallowCopy)=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),typeof(e==null?void 0:e.useStrictIteration)=="boolean"&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){wa(e)||Nn(8),zi(e)&&(e=kE(e));const t=ib(this),n=kl(e,void 0);return n[Ye].isManual_=!0,Zh(t),n}finishDraft(e,t){const n=e&&e[Ye];(!n||!n.isManual_)&&Nn(9);const{scope_:r}=n;return rb(r,t),sb(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){const s=t[n];if(s.path.length===0&&s.op==="replace"){e=s.value;break}}n>-1&&(t=t.slice(n+1));const r=Or("Patches").applyPatches_;return zi(e)?r(e,t):this.produce(e,s=>r(s,t))}};function kl(e,t){const n=Rl(e)?Or("MapSet").proxyMap_(e,t):lu(e)?Or("MapSet").proxySet_(e,t):xE(e,t);return(t?t.scope_:zc()).drafts_.push(n),n}function kE(e){return zi(e)||Nn(10,e),Q1(e)}function Q1(e){if(!wa(e)||ou(e))return e;const t=e[Ye];let n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=Qh(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=Qh(e,!0);return xl(n,(s,o)=>{V1(n,s,Q1(o))},r),t&&(t.finalized_=!1),n}function W1(){class e extends Map{constructor(h,g){super(),this[Ye]={type_:2,parent_:g,scope_:g?g.scope_:zc(),modified_:!1,finalized_:!1,copy_:void 0,assigned_:void 0,base_:h,draft_:this,isManual_:!1,revoked_:!1}}get size(){return St(this[Ye]).size}has(h){return St(this[Ye]).has(h)}set(h,g){const y=this[Ye];return u(y),(!St(y).has(h)||St(y).get(h)!==g)&&(n(y),va(y),y.assigned_.set(h,!0),y.copy_.set(h,g),y.assigned_.set(h,!0)),this}delete(h){if(!this.has(h))return!1;const g=this[Ye];return u(g),n(g),va(g),g.base_.has(h)?g.assigned_.set(h,!1):g.assigned_.delete(h),g.copy_.delete(h),!0}clear(){const h=this[Ye];u(h),St(h).size&&(n(h),va(h),h.assigned_=new Map,xl(h.base_,g=>{h.assigned_.set(g,!1)}),h.copy_.clear())}forEach(h,g){const y=this[Ye];St(y).forEach((p,b,v)=>{h.call(g,this.get(b),b,this)})}get(h){const g=this[Ye];u(g);const y=St(g).get(h);if(g.finalized_||!wa(y)||y!==g.base_.get(h))return y;const p=kl(y,g);return n(g),g.copy_.set(h,p),p}keys(){return St(this[Ye]).keys()}values(){const h=this.keys();return{[Symbol.iterator]:()=>this.values(),next:()=>{const g=h.next();return g.done?g:{done:!1,value:this.get(g.value)}}}}entries(){const h=this.keys();return{[Symbol.iterator]:()=>this.entries(),next:()=>{const g=h.next();if(g.done)return g;const y=this.get(g.value);return{done:!1,value:[g.value,y]}}}}[Symbol.iterator](){return this.entries()}}function t(f,h){return new e(f,h)}function n(f){f.copy_||(f.assigned_=new Map,f.copy_=new Map(f.base_))}class r extends Set{constructor(h,g){super(),this[Ye]={type_:3,parent_:g,scope_:g?g.scope_:zc(),modified_:!1,finalized_:!1,copy_:void 0,base_:h,draft_:this,drafts_:new Map,revoked_:!1,isManual_:!1}}get size(){return St(this[Ye]).size}has(h){const g=this[Ye];return u(g),g.copy_?!!(g.copy_.has(h)||g.drafts_.has(h)&&g.copy_.has(g.drafts_.get(h))):g.base_.has(h)}add(h){const g=this[Ye];return u(g),this.has(h)||(o(g),va(g),g.copy_.add(h)),this}delete(h){if(!this.has(h))return!1;const g=this[Ye];return u(g),o(g),va(g),g.copy_.delete(h)||(g.drafts_.has(h)?g.copy_.delete(g.drafts_.get(h)):!1)}clear(){const h=this[Ye];u(h),St(h).size&&(o(h),va(h),h.copy_.clear())}values(){const h=this[Ye];return u(h),o(h),h.copy_.values()}entries(){const h=this[Ye];return u(h),o(h),h.copy_.entries()}keys(){return this.values()}[Symbol.iterator](){return this.values()}forEach(h,g){const y=this.values();let p=y.next();for(;!p.done;)h.call(g,p.value,p.value,this),p=y.next()}}function s(f,h){return new r(f,h)}function o(f){f.copy_||(f.copy_=new Set,f.base_.forEach(h=>{if(wa(h)){const g=kl(h,f);f.drafts_.set(h,g),f.copy_.add(g)}else f.copy_.add(h)}))}function u(f){f.revoked_&&Nn(3,JSON.stringify(St(f)))}mE("MapSet",{proxyMap_:t,proxySet_:s})}var wE=new vE,SE=wE.produce;const jE=e=>(t,n,r)=>(r.setState=(s,o,...u)=>{const f=typeof s=="function"?SE(s):s;return t(f,o,...u)},e(r.setState,n,r)),X1=jE;function CE(e){const t={runId:e.runId,sessionKey:e.sessionKey,status:"idle",currentTool:null,speechBubble:null,clearTool:!1,clearSpeech:!1,incrementToolCount:!1,toolRecord:null,summary:""};switch(e.stream){case"lifecycle":return NE(t,e);case"tool":return AE(t,e);case"assistant":return EE(t,e);case"error":return TE(t,e);default:return t.summary=we.t("common:events.unknownStream",{stream:e.stream}),t}}function NE(e,t){const n=t.data.phase;switch(n){case"start":case"thinking":e.status="thinking",e.summary=n==="start"?we.t("common:events.startRunning"):we.t("common:events.thinking");break;case"end":e.status="idle",e.clearTool=!0,e.clearSpeech=!0,e.summary=we.t("common:events.runEnded");break;case"fallback":e.status="error",e.summary=we.t("common:events.fallback");break;default:e.status="thinking",e.summary=we.t("common:events.lifecycleUnknown",{phase:n??"unknown"})}return e}function AE(e,t){const n=t.data.phase,r=t.data.name??"unknown";return n==="start"?(e.status="tool_calling",e.currentTool={name:r,args:t.data.args,startedAt:t.ts},e.incrementToolCount=!0,e.toolRecord={name:r,timestamp:t.ts},e.summary=we.t("common:events.toolCall",{name:r})):(e.status="thinking",e.clearTool=!0,e.summary=we.t("common:events.toolDone",{name:r})),e}function EE(e,t){const n=t.data.text??"";return e.status="speaking",e.speechBubble={text:n,timestamp:t.ts},e.summary=n.length>40?`${n.slice(0,40)}...`:n,e}function TE(e,t){const n=t.data.message??we.t("common:errors.unknownError");return e.status="error",e.summary=we.t("common:events.errorPrefix",{message:n}),e}const Og=1200,_g=700,ue={x:30,y:20,width:Og-60,height:_g-40,wallThickness:6,cornerRadius:18,corridorWidth:28},nl=(ue.width-ue.corridorWidth)/2,al=(ue.height-ue.corridorWidth)/2,ob=ue.x+nl+ue.corridorWidth,cb=ue.y+al+ue.corridorWidth,Me={desk:{x:ue.x,y:ue.y,width:nl,height:al,label:"固定工位区"},meeting:{x:ob,y:ue.y,width:nl,height:al,label:"会议区"},hotDesk:{x:ue.x,y:cb,width:nl,height:al,label:"热工位区"},lounge:{x:ob,y:cb,width:nl,height:al,label:"休息区"}},Jh={x:Me.lounge.x+Me.lounge.width/2,y:ue.y+ue.height-30},Lg={desk:"#f4f6f9",meeting:"#eef3fa",hotDesk:"#f1f3f7",lounge:"#f3f1f7",corridor:"#e8ecf1",wall:"#8b9bb0"},zg={desk:"#1e293b",meeting:"#1a2744",hotDesk:"#1e2433",lounge:"#231e33",corridor:"#0f172a",wall:"#475569"},Ml={idle:"#22c55e",thinking:"#3b82f6",tool_calling:"#f97316",speaking:"#a855f7",spawning:"#06b6d4",error:"#ef4444",offline:"#6b7280"},Z1=4,J1=3,eh=Z1*J1,DE=4,RE=3,ME=100,ub={width:140,height:110},rl={radius:20,selectedRadius:24,strokeWidth:3,nameLabelMaxChars:12},ek=16/Og,tk=12/_g,db=1.7;function th(e){let t=0;for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);t=(t<<5)-t+r|0}return Math.abs(t)}function nk(e,t,n){const r=[],s=e.width/(t+1),o=e.height/(n+1);for(let u=0;u<n;u++)for(let f=0;f<t;f++)r.push({x:Math.round(e.x+s*(f+1)),y:Math.round(e.y+o*(u+1))});return r}const OE=nk(Me.desk,Z1,J1),_E=nk(Me.hotDesk,DE,RE);function fb(e){return`${e.x},${e.y}`}function Ig(e,t,n){if(!t){const o=th(e)%eh;for(let u=0;u<eh;u++){const f=(o+u)%eh,h=OE[f];if(!n.has(fb(h)))return h}}for(const s of _E)if(!n.has(fb(s)))return s;const r=t?Me.hotDesk:Me.desk;return{x:r.x+30+th(e)%(r.width-60),y:r.y+30+th(e)%(r.height-60)}}function SI(e){return[e.x*ek,0,e.y*tk]}function LE(e,t){const n=e.length;return n===0?[]:e.map((r,s)=>{const o=2*Math.PI*s/n-Math.PI/2;return{x:Math.round(t.x+Math.cos(o)*db/ek),y:Math.round(t.y+Math.sin(o)*db/tk)}})}function zE(e,t,n=40){const r=e-n*2,s=Math.max(1,Math.floor(r/ME));return Math.min(s,Math.max(t,4))}function hb(e,t,n){const r=n??t;if(r===0)return[];const s=40,o=50,u=zE(e.width,r,s),f=Math.ceil(r/u),h=e.width-s*2,g=e.height-o*2,y=Math.min(ub.width,h/u),p=Math.min(ub.height,g/Math.max(f,1)),b=[];for(let v=0;v<r;v++){const k=v%u,j=Math.floor(v/u);b.push({unitX:Math.round(e.x+s+y*(k+.5)),unitY:Math.round(e.y+o+p*(j+.5))})}return b}function Bc(e){const t=Me.lounge,n=[{x:t.x+60,y:t.y+40},{x:t.x+160,y:t.y+40},{x:t.x+260,y:t.y+40},{x:t.x+360,y:t.y+40},{x:t.x+60,y:t.y+120},{x:t.x+160,y:t.y+120},{x:t.x+260,y:t.y+120},{x:t.x+360,y:t.y+120},{x:t.x+440,y:t.y+60},{x:t.x+440,y:t.y+130},{x:t.x+100,y:t.y+180},{x:t.x+280,y:t.y+180}];return n.slice(0,Math.min(e,n.length))}function IE(e,t,n){return e===0?[]:Array.from({length:e},(r,s)=>{const o=2*Math.PI*s/e-Math.PI/2;return{x:Math.round(t.x+Math.cos(o)*n),y:Math.round(t.y+Math.sin(o)*n)}})}const HE=120,BE=1.5,Ja=ue.corridorWidth,UE=(ue.width-Ja)/2,$E=(ue.height-Ja)/2,qE={x:ue.x+UE+Ja/2,y:ue.y+$E+Ja/2};function gb(e){if(e==="corridor")return{...Jh};const t=Me[e];switch(e){case"desk":return{x:t.x+t.width/2,y:t.y+t.height+Ja/2};case"meeting":return{x:t.x+t.width/2,y:t.y+t.height+Ja/2};case"hotDesk":return{x:t.x+t.width/2,y:t.y-Ja/2};case"lounge":return{x:t.x+t.width/2,y:t.y-Ja/2};default:return{...Jh}}}function KE(e,t){if(e==="corridor"||t==="corridor")return!1;const n=["desk","hotDesk"],r=["meeting","lounge"],s=["desk","meeting"],o=["hotDesk","lounge"];return!!(n.includes(e)&&n.includes(t)||r.includes(e)&&r.includes(t)||s.includes(e)&&s.includes(t)||o.includes(e)&&o.includes(t))}function PE(e,t,n,r){if(n===r)return[{...e},{...t}];const s=gb(n),o=gb(r);return KE(n,r)?[{...e},s,o,{...t}]:[{...e},s,{...qE},o,{...t}]}function ak(e,t){const n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)}function rk(e){let t=0;for(let n=1;n<e.length;n++)t+=ak(e[n-1],e[n]);return t}function FE(e){const n=rk(e)/HE;return Math.max(n,BE)}function GE(e,t){if(e.length===0)return{x:0,y:0};if(t<=0)return{...e[0]};if(t>=1)return{...e[e.length-1]};const n=rk(e);if(n===0)return{...e[0]};const r=t*n;let s=0;for(let o=1;o<e.length;o++){const u=ak(e[o-1],e[o]);if(s+u>=r){const f=u>0?(r-s)/u:0;return{x:e[o-1].x+(e[o].x-e[o-1].x)*f,y:e[o-1].y+(e[o].y-e[o-1].y)*f}}s+=u}return{...e[e.length-1]}}const mb=5e3,Uc=new Map,nh=new Map;function pb(e){return e==="thinking"||e==="tool_calling"||e==="speaking"||e==="spawning"||e==="error"}function VE(e,t){const n=Date.now();if(pb(t.status))ik(e.id),nh.set(e.id,n),e.status=t.status;else if(t.status==="idle"){const r=nh.get(e.id)??0,s=n-r;pb(e.status)&&s<mb?QE(e,mb-s):(e.status="idle",nh.delete(e.id))}else e.status=t.status;e.lastActiveAt=n,t.currentTool&&(e.currentTool=t.currentTool),t.clearTool&&e.status==="idle"&&(e.currentTool=null),t.speechBubble&&(e.speechBubble=t.speechBubble),t.clearSpeech&&e.status==="idle"&&(e.speechBubble=null),t.incrementToolCount&&e.toolCallCount++,t.toolRecord&&(e.toolCallHistory=[t.toolRecord,...e.toolCallHistory.slice(0,9)]),t.runId&&!e.runId&&(e.runId=t.runId)}let Cc=null;function YE(e){Cc=e}function QE(e,t){ik(e.id);const n=e.id,r=setTimeout(()=>{Uc.delete(n),Cc==null||Cc(n)},t);Uc.set(n,r)}function ik(e){const t=Uc.get(e);t&&(clearTimeout(t),Uc.delete(e))}const WE=.3,XE=3,yb=[{x:Me.meeting.x+Me.meeting.width/2,y:Me.meeting.y+Me.meeting.height/2},{x:Me.meeting.x+Me.meeting.width*.25,y:Me.meeting.y+Me.meeting.height*.3},{x:Me.meeting.x+Me.meeting.width*.75,y:Me.meeting.y+Me.meeting.height*.7}];function ZE(e,t,n){const r=n&&n.length>0?new Set(n):null,s=new Map;for(const u of e){if(u.strength<WE||!t.has(u.sourceId)||!t.has(u.targetId)||r&&(!r.has(u.sourceId)||!r.has(u.targetId)))continue;let f=s.get(u.sessionKey);f||(f=new Set,s.set(u.sessionKey,f)),f.add(u.sourceId),f.add(u.targetId)}const o=[];for(const[u,f]of s)if(f.size>=2&&o.push({sessionKey:u,agentIds:Array.from(f)}),o.length>=XE)break;return o}function JE(e,t){const n=yb[t%yb.length],r=LE(e.agentIds,n),s=new Map;return e.agentIds.forEach((o,u)=>{s.set(o,r[u])}),s}function eT(e,t,n,r){const s=new Set;t.forEach((o,u)=>{var h;const f=JE(o,u);for(const[g,y]of f){const p=e.get(g);p&&p.zone!=="meeting"&&((h=p.movement)==null?void 0:h.toZone)!=="meeting"&&n(g,y),s.add(g)}});for(const o of e.values())o.zone==="meeting"&&!s.has(o.id)&&r(o.id)}function Bn(e,t){let n=0,r=0;for(const o of e.values())o.isPlaceholder||!o.confirmed||(r++,o.status!=="idle"&&o.status!=="offline"&&n++);const s=r>0?Math.min(n/r*100,100):0;return{activeAgents:n,totalAgents:r,totalTokens:t.totalTokens,tokenRate:t.tokenRate,collaborationHeat:s}}W1();const ah=200,tT=6e4,sk="openclaw-theme",lk="openclaw-chat-dock-height",xb=300,nT=300,aT=3e4,rT=1e4,$c=new Map,Za=new Map,Ei=new Map,Ps=new Set,bb=3e4,iT=5e3;let rh=null,vb="";const sT=500;function qc(e){return e==="thinking"||e==="tool_calling"||e==="speaking"||e==="spawning"}function lT(){if(typeof window>"u")return xb;const e=localStorage.getItem(lk);if(e){const t=parseInt(e,10);if(!Number.isNaN(t)&&t>=150&&t<=800)return t}return xb}function oT(){if(typeof window>"u")return"dark";const e=localStorage.getItem(sk);return e==="light"||e==="dark"?e:"dark"}function cT(){return typeof window>"u"?!0:window.devicePixelRatio>=1.5}function Fs(e,t,n,r,s=!0){if(!s)return{id:e,name:t,status:"idle",position:{...Jh},currentTool:null,speechBubble:null,lastActiveAt:Date.now(),toolCallCount:0,toolCallHistory:[],runId:null,isSubAgent:!1,isPlaceholder:!1,parentAgentId:null,childAgentIds:[],zone:"corridor",originalPosition:null,movement:null,confirmed:!1,arrivedAtHotDeskAt:null,pendingRetire:!1};const o=Ig(e,n,r);return{id:e,name:t,status:"idle",position:o,currentTool:null,speechBubble:null,lastActiveAt:Date.now(),toolCallCount:0,toolCallHistory:[],runId:null,isSubAgent:n,isPlaceholder:!1,parentAgentId:null,childAgentIds:[],zone:n?"hotDesk":"desk",originalPosition:null,movement:null,confirmed:!0,arrivedAtHotDeskAt:n?Date.now():null,pendingRetire:!1}}function un(e){return`${e.x},${e.y}`}function uT(e){let t=-1;for(const n of e.values())if(n.id.startsWith("placeholder-")){const r=parseInt(n.id.slice(12),10);!Number.isNaN(r)&&r>t&&(t=r)}return t+1}function dT(e,t,n){if(t==="lounge"){const s=Bc(n),o=new Set;for(const f of e.values())f.zone==="lounge"&&o.add(un(f.position));const u=s.find(f=>!o.has(un(f)));return u||(s[0]??{x:Me.lounge.x+60,y:Me.lounge.y+40})}const r=new Set;for(const s of e.values())s.zone===t&&r.add(un(s.position));return Ig("temp-"+Date.now(),t==="hotDesk",r)}function ih(e,t){let n;for(const r of e.agents.values())if(r.isPlaceholder&&r.zone==="lounge"){n=r;break}if(n)t.position={...n.position},t.zone="lounge",e.agents.delete(n.id);else{const r=Bc(e.maxSubAgents),s=new Set;for(const u of e.agents.values())u.zone==="lounge"&&s.add(un(u.position));const o=r.find(u=>!s.has(un(u)));t.position=o??r[0]??{x:Me.lounge.x+60,y:Me.lounge.y+40},t.zone="lounge"}}const ie=Mn()(X1(e=>({agents:new Map,links:[],globalMetrics:{activeAgents:0,totalAgents:0,totalTokens:0,tokenRate:0,collaborationHeat:0},connectionStatus:"disconnected",connectionError:null,selectedAgentId:null,viewMode:"2d",eventHistory:[],sidebarCollapsed:!0,lastSessionsSnapshot:null,theme:oT(),bloomEnabled:cT(),operatorScopes:[],tokenHistory:[],agentCosts:{},currentPage:"office",chatDockHeight:lT(),maxSubAgents:8,agentToAgentConfig:{enabled:!1,allow:[]},runIdMap:new Map,sessionKeyMap:new Map,addAgent:t=>{e(n=>{n.agents.set(t.id,t),n.globalMetrics=Bn(n.agents,n.globalMetrics)})},updateAgent:(t,n)=>{e(r=>{const s=r.agents.get(t);s&&(Object.assign(s,n),r.globalMetrics=Bn(r.agents,r.globalMetrics))})},removeAgent:t=>{e(n=>{n.agents.delete(t),n.selectedAgentId===t&&(n.selectedAgentId=null),n.globalMetrics=Bn(n.agents,n.globalMetrics)})},addSubAgent:(t,n)=>{e(s=>{const o=s.agents.get(n.agentId);if(o&&!o.confirmed){const f=Ei.get(n.agentId);f&&(clearTimeout(f),Ei.delete(n.agentId)),o.confirmed=!0,o.isSubAgent=!0,o.parentAgentId=t,o.name=n.label||o.name,ih(s,o)}else if(o&&o.confirmed){const f=!o.isSubAgent;o.isSubAgent=!0,o.parentAgentId=t,o.name=n.label||o.name,f&&(o.movement=null,ih(s,o))}else{let f;for(const h of s.agents.values())if(h.isPlaceholder&&h.zone==="lounge"){f=h;break}if(f){const h=f.id,g={...f.position};s.agents.delete(h),f.id=n.agentId,f.name=n.label||`Sub-${n.agentId.slice(0,6)}`,f.isPlaceholder=!1,f.isSubAgent=!0,f.parentAgentId=t,f.runId=n.sessionKey,f.status="idle",f.position=g,f.confirmed=!0,f.arrivedAtHotDeskAt=null,f.pendingRetire=!1,s.agents.set(n.agentId,f)}else{const h=new Set;for(const y of s.agents.values())h.add(un(y.position));const g=Fs(n.agentId,n.label||`Sub-${n.agentId.slice(0,6)}`,!0,h);g.parentAgentId=t,g.runId=n.sessionKey,g.zone="hotDesk",s.agents.set(n.agentId,g)}}const u=s.agents.get(t);if(u&&!u.childAgentIds.includes(n.agentId)&&u.childAgentIds.push(n.agentId),n.sessionKey){const f=s.sessionKeyMap.get(n.sessionKey)??[];f.includes(n.agentId)||(f.push(n.agentId),s.sessionKeyMap.set(n.sessionKey,f))}s.globalMetrics=Bn(s.agents,s.globalMetrics)});const r=ie.getState().agents.get(n.agentId);r&&r.zone!=="hotDesk"&&r.zone!=="meeting"&&ie.getState().startMovement(n.agentId,"hotDesk")},removeSubAgent:t=>{eg(t);const n=Za.get(t);n&&(clearTimeout(n),Za.delete(t)),e(r=>{const s=r.agents.get(t);if(s!=null&&s.parentAgentId){const h=r.agents.get(s.parentAgentId);h&&(h.childAgentIds=h.childAgentIds.filter(g=>g!==t))}Ps.add(t),setTimeout(()=>Ps.delete(t),bb);for(const[h,g]of r.runIdMap)g===t&&(r.runIdMap.delete(h),Ps.add(h),setTimeout(()=>Ps.delete(h),bb));for(const[h,g]of r.sessionKeyMap){const y=g.filter(p=>p!==t);y.length===0?r.sessionKeyMap.delete(h):r.sessionKeyMap.set(h,y)}const o=Bc(r.maxSubAgents),u=new Set;for(const h of r.agents.values())h.zone==="lounge"&&h.id!==t&&u.add(un(h.position));const f=o.find(h=>!u.has(un(h)));if(r.agents.delete(t),r.selectedAgentId===t&&(r.selectedAgentId=null),f){const h=uT(r.agents),g=`placeholder-${h}`,y={id:g,name:`待命-${h}`,status:"idle",position:f,currentTool:null,speechBubble:null,lastActiveAt:Date.now(),toolCallCount:0,toolCallHistory:[],runId:null,isSubAgent:!0,isPlaceholder:!0,parentAgentId:null,childAgentIds:[],zone:"lounge",originalPosition:null,movement:null,confirmed:!0,arrivedAtHotDeskAt:null,pendingRetire:!1};r.agents.set(g,y)}r.globalMetrics=Bn(r.agents,r.globalMetrics)})},retireSubAgent:t=>{const n=ie.getState().agents.get(t);!(n!=null&&n.isSubAgent)||n.isPlaceholder||n.pendingRetire||(e(r=>{const s=r.agents.get(t);s&&(s.pendingRetire=!0)}),Nc(t))},moveToMeeting:(t,n)=>{e(r=>{const s=r.agents.get(t);s&&(s.originalPosition||(s.originalPosition={...s.position}))}),ie.getState().startMovement(t,"meeting",n)},returnFromMeeting:t=>{const n=ie.getState().agents.get(t);if(!(n!=null&&n.originalPosition))return;const r=n.isSubAgent?"hotDesk":"desk",s={...n.originalPosition};e(o=>{const u=o.agents.get(t);u&&(u.originalPosition=null)}),ie.getState().startMovement(t,r,s)},startMovement:(t,n,r)=>{e(s=>{const o=s.agents.get(t);if(!o||o.movement&&o.movement.toZone===n)return;const u=o.zone,f=r??dT(s.agents,n,s.maxSubAgents),h=PE(o.position,f,u,n),g=FE(h);o.movement={path:h,progress:0,duration:g,startTime:Date.now(),fromZone:u,toZone:n}})},tickMovement:(t,n)=>{let r=!1,s=!1;if(e(o=>{const u=o.agents.get(t);if(!(u!=null&&u.movement))return;const f=n/u.movement.duration;u.movement.progress=Math.min(u.movement.progress+f,1);const h=GE(u.movement.path,u.movement.progress);if(u.position=h,u.movement.progress>=1){const g=u.movement.toZone,y=u.movement.path[u.movement.path.length-1];u.movement=null,u.zone=g,u.position={...y},g==="hotDesk"&&u.isSubAgent&&(u.arrivedAtHotDeskAt=Date.now(),r=!0),g==="lounge"&&u.isSubAgent&&u.pendingRetire&&(s=!0)}}),r){const o=ie.getState().agents.get(t);o!=null&&o.pendingRetire&&Nc(t)}if(s){const o=ie.getState().agents.get(t);o!=null&&o.isSubAgent&&!o.isPlaceholder&&o.pendingRetire&&ie.getState().removeSubAgent(t)}},completeMovement:t=>{let n=!1,r=!1;if(e(s=>{const o=s.agents.get(t);if(!(o!=null&&o.movement))return;const u=o.movement.toZone,f=o.movement.path[o.movement.path.length-1];o.movement=null,o.zone=u,o.position={...f},u==="hotDesk"&&o.isSubAgent&&(o.arrivedAtHotDeskAt=Date.now(),n=!0),u==="lounge"&&o.isSubAgent&&o.pendingRetire&&(r=!0)}),n){const s=ie.getState().agents.get(t);s!=null&&s.pendingRetire&&Nc(t)}if(r){const s=ie.getState().agents.get(t);s!=null&&s.isSubAgent&&!s.isPlaceholder&&s.pendingRetire&&ie.getState().removeSubAgent(t)}},prefillLoungePlaceholders:t=>{e(n=>{const r=Bc(t);for(let s=0;s<Math.min(t,r.length);s++){const o=`placeholder-${s}`;if(n.agents.has(o))continue;const u={id:o,name:`待命-${s}`,status:"idle",position:{...r[s]},currentTool:null,speechBubble:null,lastActiveAt:Date.now(),toolCallCount:0,toolCallHistory:[],runId:null,isSubAgent:!0,isPlaceholder:!0,parentAgentId:null,childAgentIds:[],zone:"lounge",originalPosition:null,movement:null,confirmed:!0,arrivedAtHotDeskAt:null,pendingRetire:!1};n.agents.set(o,u)}})},confirmAgent:(t,n,r)=>{e(o=>{const u=o.agents.get(t);if(!u||u.confirmed)return;u.confirmed=!0;const f=Ei.get(t);if(f&&(clearTimeout(f),Ei.delete(t)),n==="sub")u.isSubAgent=!0,r&&(u.parentAgentId=r),ih(o,u);else{const h=new Set;for(const g of o.agents.values())g.zone==="desk"&&g.id!==t&&h.add(un(g.position));u.position=Ig(t,!1,h),u.zone="desk"}o.globalMetrics=Bn(o.agents,o.globalMetrics)});const s=ie.getState().agents.get(t);s&&!s.movement&&(n==="sub"?ie.getState().startMovement(t,"hotDesk"):ie.getState().startMovement(t,"desk"))},setSessionsSnapshot:t=>{e(n=>{n.lastSessionsSnapshot=t})},initAgents:t=>{e(n=>{var s;n.agents.clear(),n.runIdMap.clear(),n.sessionKeyMap.clear();const r=new Set;for(const o of t){const u=((s=o.identity)==null?void 0:s.name)??o.name??o.id,f=Fs(o.id,u,!1,r);r.add(un(f.position)),n.agents.set(o.id,f)}n.globalMetrics=Bn(n.agents,n.globalMetrics)}),ie.getState().prefillLoungePlaceholders(ie.getState().maxSubAgents)},syncMainAgents:t=>{e(n=>{var o,u;const r=new Set(t.map(f=>f.id)),s=new Set;for(const f of n.agents.values())s.add(un(f.position));for(const f of t){const h=n.agents.get(f.id);if(h){const g=((o=f.identity)==null?void 0:o.name)??f.name??f.id;h.name!==g&&(h.name=g)}else{const g=((u=f.identity)==null?void 0:u.name)??f.name??f.id,y=Fs(f.id,g,!1,s);s.add(un(y.position)),n.agents.set(f.id,y)}}for(const[f,h]of n.agents)!h.isSubAgent&&!h.isPlaceholder&&h.confirmed&&!r.has(f)&&(n.agents.delete(f),n.selectedAgentId===f&&(n.selectedAgentId=null));n.globalMetrics=Bn(n.agents,n.globalMetrics)})},processAgentEvent:t=>{const n={value:null};let r=null,s=null,o=null;e(f=>{var E;const h=CE(t),g=t.data.agentId,y=t.data.parentAgentId,p=!!g&&!!y&&t.stream==="lifecycle"&&t.data.phase==="start",b=t.sessionKey??"",v=b.includes(":subagent:")&&!b.startsWith("announce:");let k;if(v){if(k=f.runIdMap.get(t.runId),!k){const R=f.sessionKeyMap.get(b);R&&R.length>0&&(k=R[0])}if(!k){const R=":subagent:",H=b.indexOf(R);H>=0&&(k=b.slice(H+R.length))}k||(k=t.runId)}else{if(k=f.runIdMap.get(t.runId),!k&&g&&(k=g),!k&&t.sessionKey){const R=f.sessionKeyMap.get(t.sessionKey);R&&R.length>0&&(k=R[0])}if(!k&&t.sessionKey){const R=t.sessionKey.match(/^agent:([^:]+):/);if(R){const H=R[1];for(const[z,L]of f.agents)if(!L.isSubAgent&&!L.isPlaceholder&&(L.id===H||L.name===H)){k=z;break}}}k||(k=t.runId)}if(Ps.has(k)||t.runId.startsWith("announce:"))return;const j=v?hT(f,b):null;if(p&&g&&y&&!f.agents.has(g))n.value={parentId:y,info:{sessionKey:t.sessionKey??t.runId,agentId:g,label:`Sub-${g.slice(0,8)}`,task:"",requesterSessionKey:t.sessionKey??"",startedAt:t.ts}};else if(!f.agents.has(k)&&v&&j)n.value={parentId:j,info:{sessionKey:b,agentId:k,label:`Sub-${k.slice(0,8)}`,task:"",requesterSessionKey:b,startedAt:t.ts}};else if(!f.agents.has(k))if(fT(f,k,t.sessionKey)){const H=new Set;for(const L of f.agents.values())H.add(un(L.position));const z=Fs(k,`Agent-${k.slice(0,6)}`,!1,H,!0);z.runId=t.runId,f.agents.set(k,z)}else{const H=Fs(k,`Agent-${k.slice(0,6)}`,!1,new Set,!1);H.runId=t.runId,f.agents.set(k,H),r=k}if(f.runIdMap.set(t.runId,k),t.sessionKey){const R=f.sessionKeyMap.get(t.sessionKey)??[];R.includes(k)||(R.push(k),f.sessionKeyMap.set(t.sessionKey,R)),gT(f,t.sessionKey,k),mT()}const N=f.agents.get(k);if(N){const R=N.status;VE(N,h),N.isSubAgent&&N.confirmed&&qc(h.status)&&(N.pendingRetire&&(N.pendingRetire=!1,N.arrivedAtHotDeskAt=null,eg(N.id)),((E=N.movement)==null?void 0:E.toZone)==="lounge"&&(N.movement=null,s=N.id),!N.movement&&N.zone==="lounge"&&(s=N.id)),N.isSubAgent&&N.confirmed&&N.zone!=="meeting"&&kb(N.id,R,N.status)}t.stream==="lifecycle"&&t.data.phase==="end"&&(N!=null&&N.isSubAgent)&&!N.isPlaceholder&&(o=k);const C={timestamp:t.ts,agentId:k,agentName:(N==null?void 0:N.name)??k,stream:t.stream,summary:h.summary};f.eventHistory.push(C),f.eventHistory.length>ah&&(f.eventHistory=f.eventHistory.slice(-ah)),queueMicrotask(()=>{Wn.saveEvent(C).catch(()=>{})}),f.globalMetrics=Bn(f.agents,f.globalMetrics)}),s&&ie.getState().startMovement(s,"hotDesk");const u=n.value;if(u&&ie.getState().addSubAgent(u.parentId,u.info),r){const f=r,h=setTimeout(()=>{Ei.delete(f);const g=ie.getState(),y=g.agents.get(f);y&&!y.confirmed&&g.confirmAgent(f,"main")},iT);Ei.set(f,h)}o&&ie.getState().retireSubAgent(o)},deferredSetIdle:t=>{e(n=>{const r=n.agents.get(t);r&&(r.status="idle",r.currentTool=null,r.speechBubble=null,r.isSubAgent&&r.confirmed&&r.zone!=="meeting"&&kb(r.id,"thinking","idle"),n.globalMetrics=Bn(n.agents,n.globalMetrics))})},selectAgent:t=>{e(n=>{n.selectedAgentId=n.selectedAgentId===t?null:t})},setViewMode:t=>{e(n=>{n.viewMode=t})},setConnectionStatus:(t,n)=>{e(r=>{r.connectionStatus=t,r.connectionError=n??null})},setSidebarCollapsed:t=>{e(n=>{n.sidebarCollapsed=t})},setTheme:t=>{e(n=>{n.theme=t});try{localStorage.setItem(sk,t)}catch{}},setBloomEnabled:t=>{e(n=>{n.bloomEnabled=t})},setOperatorScopes:t=>{e(n=>{n.operatorScopes=t})},pushTokenSnapshot:t=>{e(n=>{const r=n.tokenHistory[n.tokenHistory.length-1];n.tokenHistory.push(t),n.tokenHistory.length>30&&(n.tokenHistory=n.tokenHistory.slice(-30));const s=r?(t.timestamp-r.timestamp)/6e4:0,o=s>0?Math.max(0,(t.total-r.total)/s):0;n.globalMetrics.totalTokens=t.total,n.globalMetrics.tokenRate=Number.isFinite(o)?o:0})},setAgentCosts:t=>{e(n=>{n.agentCosts=t})},setCurrentPage:t=>{e(n=>{n.currentPage=t})},setChatDockHeight:t=>{e(n=>{n.chatDockHeight=t});try{localStorage.setItem(lk,String(t))}catch{}},setMaxSubAgents:t=>{e(n=>{t>=1&&t<=50&&(n.maxSubAgents=t)})},setAgentToAgentConfig:t=>{e(n=>{n.agentToAgentConfig=t})},initEventHistory:async()=>{try{await Wn.open();const t=await Wn.getEvents(ah);t.length>0&&e(n=>{n.eventHistory=t}),Wn.cleanup().catch(()=>{})}catch{}},updateMetrics:()=>{e(t=>{t.globalMetrics=Bn(t.agents,t.globalMetrics)})}})));YE(e=>{ie.getState().deferredSetIdle(e)});function fT(e,t,n){for(const r of e.agents.values())if(!r.isSubAgent&&!r.isPlaceholder&&r.confirmed&&r.id===t)return!0;if(n){const r=e.sessionKeyMap.get(n);if(r)for(const s of r){const o=e.agents.get(s);if(o&&!o.isSubAgent&&o.confirmed)return!1}}return!1}function hT(e,t){const n=t.split(":"),r=n.indexOf("subagent");if(r>=2){const s=n.slice(1,r).join(":");for(const[o,u]of e.sessionKeyMap)if(o.startsWith(`agent:${s}:`)&&!o.includes(":subagent:")&&u.length>0)return u[0];for(const[o,u]of e.agents)if(!u.isSubAgent&&!u.isPlaceholder&&(u.id===s||u.name===s))return o}for(const[s,o]of e.agents)if(!o.isSubAgent&&!o.isPlaceholder&&o.confirmed)return s;return null}function gT(e,t,n){const r=e.sessionKeyMap.get(t);if(!r||r.length<2)return;const s=Date.now();for(const o of r){if(o===n)continue;const u=e.links.findIndex(f=>f.sessionKey===t&&(f.sourceId===n&&f.targetId===o||f.sourceId===o&&f.targetId===n));if(u>=0){const f=e.links[u];f.lastActivityAt=s,f.strength=Math.min(f.strength+.1,1)}else e.links.push({sourceId:n,targetId:o,sessionKey:t,strength:.3,lastActivityAt:s})}e.links=e.links.filter(o=>s-o.lastActivityAt<tT)}function mT(){rh||(rh=setTimeout(()=>{rh=null;const e=ie.getState(),t=e.agentToAgentConfig.enabled?e.agentToAgentConfig.allow:void 0,n=ZE(e.links,e.agents,t),r=JSON.stringify(n.map(s=>s.agentIds.sort()));r!==vb&&(vb=r,eT(e.agents,n,(s,o)=>ie.getState().moveToMeeting(s,o),s=>ie.getState().returnFromMeeting(s)))},sT))}function kb(e,t,n){const r=Za.get(e);r&&(clearTimeout(r),Za.delete(e));const s=qc(t),o=qc(n);if(!s&&o){const u=setTimeout(()=>{Za.delete(e),pT(e)},nT);Za.set(e,u)}else if(s&&!o&&n==="idle"){const u=setTimeout(()=>{Za.delete(e),yT(e)},aT);Za.set(e,u)}}function pT(e){var r;const n=ie.getState().agents.get(e);!n||!n.isSubAgent||n.zone!=="lounge"||((r=n.movement)==null?void 0:r.toZone)!=="hotDesk"&&ie.getState().startMovement(e,"hotDesk")}function yT(e){var r;const n=ie.getState().agents.get(e);!n||!n.isSubAgent||n.zone!=="hotDesk"||qc(n.status)||((r=n.movement)==null?void 0:r.toZone)!=="lounge"&&(n.pendingRetire||ie.getState().startMovement(e,"lounge"))}function eg(e){const t=$c.get(e);t&&(clearTimeout(t),$c.delete(e))}function Nc(e){var n;eg(e);const t=ie.getState().agents.get(e);if(!(!(t!=null&&t.isSubAgent)||t.isPlaceholder||!t.pendingRetire)&&((n=t.movement)==null?void 0:n.toZone)!=="hotDesk"){if(t.zone==="hotDesk"){const r=t.arrivedAtHotDeskAt??Date.now(),s=Date.now()-r,o=rT-s;if(o>0){const u=setTimeout(()=>{$c.delete(e),Nc(e)},o);$c.set(e,u);return}ie.getState().startMovement(e,"lounge");return}if(t.zone==="lounge"&&!t.movement){ie.getState().startMovement(e,"hotDesk");return}}}function ok(){const{t:e}=se("chat"),[t,n]=S.useState(!1),r=S.useRef(null),s=ie(g=>g.agents),o=Qe(g=>g.targetAgentId),u=Qe(g=>g.setTargetAgent),f=Array.from(s.values()).filter(g=>!g.isPlaceholder),h=f.find(g=>g.id===o)??f[0];return S.useEffect(()=>{function g(y){r.current&&!r.current.contains(y.target)&&n(!1)}if(t)return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[t]),f.length===0?null:c.jsxs("div",{className:"relative",ref:r,children:[c.jsxs("button",{type:"button",onClick:()=>n(!t),className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-gray-600 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-800",children:[c.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-full",style:{backgroundColor:wb((h==null?void 0:h.id)??"")}}),c.jsx("span",{className:"max-w-[100px] truncate",children:(h==null?void 0:h.name)??e("agentSelector.defaultLabel")}),c.jsx(qn,{className:"h-3 w-3"})]}),t&&c.jsx("div",{className:"absolute bottom-full left-0 z-50 mb-1 min-w-[160px] rounded-lg border border-gray-200 bg-white py-1 shadow-lg dark:border-gray-700 dark:bg-gray-900",children:f.map(g=>c.jsxs("button",{type:"button",onClick:()=>{u(g.id),n(!1)},className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs hover:bg-gray-50 dark:hover:bg-gray-800 ${g.id===o?"bg-blue-50 text-blue-700 dark:bg-blue-900/20 dark:text-blue-400":"text-gray-700 dark:text-gray-300"}`,children:[c.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-full",style:{backgroundColor:wb(g.id)}}),c.jsx("span",{className:"truncate",children:g.name})]},g.id))})]})}function wb(e){const t=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899"];let n=0;for(let r=0;r<e.length;r++)n=(n<<5)-n+e.charCodeAt(r)|0;return t[Math.abs(n)%t.length]}function xT(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const bT=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,vT=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,kT={};function Sb(e,t){return(kT.jsx?vT:bT).test(e)}const wT=/[ \t\n\f\r]/g;function ST(e){return typeof e=="object"?e.type==="text"?jb(e.value):!1:jb(e)}function jb(e){return e.replace(wT,"")===""}class Ol{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}Ol.prototype.normal={};Ol.prototype.property={};Ol.prototype.space=void 0;function ck(e,t){const n={},r={};for(const s of e)Object.assign(n,s.property),Object.assign(r,s.normal);return new Ol(n,r,t)}function tg(e){return e.toLowerCase()}class Jt{constructor(t,n){this.attribute=n,this.property=t}}Jt.prototype.attribute="";Jt.prototype.booleanish=!1;Jt.prototype.boolean=!1;Jt.prototype.commaOrSpaceSeparated=!1;Jt.prototype.commaSeparated=!1;Jt.prototype.defined=!1;Jt.prototype.mustUseProperty=!1;Jt.prototype.number=!1;Jt.prototype.overloadedBoolean=!1;Jt.prototype.property="";Jt.prototype.spaceSeparated=!1;Jt.prototype.space=void 0;let jT=0;const De=zr(),xt=zr(),ng=zr(),le=zr(),it=zr(),Li=zr(),cn=zr();function zr(){return 2**++jT}const ag=Object.freeze(Object.defineProperty({__proto__:null,boolean:De,booleanish:xt,commaOrSpaceSeparated:cn,commaSeparated:Li,number:le,overloadedBoolean:ng,spaceSeparated:it},Symbol.toStringTag,{value:"Module"})),sh=Object.keys(ag);class Hg extends Jt{constructor(t,n,r,s){let o=-1;if(super(t,n),Cb(this,"space",s),typeof r=="number")for(;++o<sh.length;){const u=sh[o];Cb(this,sh[o],(r&ag[u])===ag[u])}}}Hg.prototype.defined=!0;function Cb(e,t,n){n&&(e[t]=n)}function Fi(e){const t={},n={};for(const[r,s]of Object.entries(e.properties)){const o=new Hg(r,e.transform(e.attributes||{},r),s,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(o.mustUseProperty=!0),t[r]=o,n[tg(r)]=r,n[tg(o.attribute)]=r}return new Ol(t,n,e.space)}const uk=Fi({properties:{ariaActiveDescendant:null,ariaAtomic:xt,ariaAutoComplete:null,ariaBusy:xt,ariaChecked:xt,ariaColCount:le,ariaColIndex:le,ariaColSpan:le,ariaControls:it,ariaCurrent:null,ariaDescribedBy:it,ariaDetails:null,ariaDisabled:xt,ariaDropEffect:it,ariaErrorMessage:null,ariaExpanded:xt,ariaFlowTo:it,ariaGrabbed:xt,ariaHasPopup:null,ariaHidden:xt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:it,ariaLevel:le,ariaLive:null,ariaModal:xt,ariaMultiLine:xt,ariaMultiSelectable:xt,ariaOrientation:null,ariaOwns:it,ariaPlaceholder:null,ariaPosInSet:le,ariaPressed:xt,ariaReadOnly:xt,ariaRelevant:null,ariaRequired:xt,ariaRoleDescription:it,ariaRowCount:le,ariaRowIndex:le,ariaRowSpan:le,ariaSelected:xt,ariaSetSize:le,ariaSort:null,ariaValueMax:le,ariaValueMin:le,ariaValueNow:le,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function dk(e,t){return t in e?e[t]:t}function fk(e,t){return dk(e,t.toLowerCase())}const CT=Fi({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:Li,acceptCharset:it,accessKey:it,action:null,allow:null,allowFullScreen:De,allowPaymentRequest:De,allowUserMedia:De,alt:null,as:null,async:De,autoCapitalize:null,autoComplete:it,autoFocus:De,autoPlay:De,blocking:it,capture:null,charSet:null,checked:De,cite:null,className:it,cols:le,colSpan:null,content:null,contentEditable:xt,controls:De,controlsList:it,coords:le|Li,crossOrigin:null,data:null,dateTime:null,decoding:null,default:De,defer:De,dir:null,dirName:null,disabled:De,download:ng,draggable:xt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:De,formTarget:null,headers:it,height:le,hidden:ng,high:le,href:null,hrefLang:null,htmlFor:it,httpEquiv:it,id:null,imageSizes:null,imageSrcSet:null,inert:De,inputMode:null,integrity:null,is:null,isMap:De,itemId:null,itemProp:it,itemRef:it,itemScope:De,itemType:it,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:De,low:le,manifest:null,max:null,maxLength:le,media:null,method:null,min:null,minLength:le,multiple:De,muted:De,name:null,nonce:null,noModule:De,noValidate:De,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:De,optimum:le,pattern:null,ping:it,placeholder:null,playsInline:De,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:De,referrerPolicy:null,rel:it,required:De,reversed:De,rows:le,rowSpan:le,sandbox:it,scope:null,scoped:De,seamless:De,selected:De,shadowRootClonable:De,shadowRootDelegatesFocus:De,shadowRootMode:null,shape:null,size:le,sizes:null,slot:null,span:le,spellCheck:xt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:le,step:null,style:null,tabIndex:le,target:null,title:null,translate:null,type:null,typeMustMatch:De,useMap:null,value:xt,width:le,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:it,axis:null,background:null,bgColor:null,border:le,borderColor:null,bottomMargin:le,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:De,declare:De,event:null,face:null,frame:null,frameBorder:null,hSpace:le,leftMargin:le,link:null,longDesc:null,lowSrc:null,marginHeight:le,marginWidth:le,noResize:De,noHref:De,noShade:De,noWrap:De,object:null,profile:null,prompt:null,rev:null,rightMargin:le,rules:null,scheme:null,scrolling:xt,standby:null,summary:null,text:null,topMargin:le,valueType:null,version:null,vAlign:null,vLink:null,vSpace:le,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:De,disableRemotePlayback:De,prefix:null,property:null,results:le,security:null,unselectable:null},space:"html",transform:fk}),NT=Fi({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:cn,accentHeight:le,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:le,amplitude:le,arabicForm:null,ascent:le,attributeName:null,attributeType:null,azimuth:le,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:le,by:null,calcMode:null,capHeight:le,className:it,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:le,diffuseConstant:le,direction:null,display:null,dur:null,divisor:le,dominantBaseline:null,download:De,dx:null,dy:null,edgeMode:null,editable:null,elevation:le,enableBackground:null,end:null,event:null,exponent:le,externalResourcesRequired:null,fill:null,fillOpacity:le,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:Li,g2:Li,glyphName:Li,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:le,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:le,horizOriginX:le,horizOriginY:le,id:null,ideographic:le,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:le,k:le,k1:le,k2:le,k3:le,k4:le,kernelMatrix:cn,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:le,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:le,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:le,overlineThickness:le,paintOrder:null,panose1:null,path:null,pathLength:le,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:it,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:le,pointsAtY:le,pointsAtZ:le,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:cn,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:cn,rev:cn,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:cn,requiredFeatures:cn,requiredFonts:cn,requiredFormats:cn,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:le,specularExponent:le,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:le,strikethroughThickness:le,string:null,stroke:null,strokeDashArray:cn,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:le,strokeOpacity:le,strokeWidth:null,style:null,surfaceScale:le,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:cn,tabIndex:le,tableValues:null,target:null,targetX:le,targetY:le,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:cn,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:le,underlineThickness:le,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:le,values:null,vAlphabetic:le,vMathematical:le,vectorEffect:null,vHanging:le,vIdeographic:le,version:null,vertAdvY:le,vertOriginX:le,vertOriginY:le,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:le,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:dk}),hk=Fi({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),gk=Fi({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:fk}),mk=Fi({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),AT={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},ET=/[A-Z]/g,Nb=/-[a-z]/g,TT=/^data[-\w.:]+$/i;function DT(e,t){const n=tg(t);let r=t,s=Jt;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&TT.test(t)){if(t.charAt(4)==="-"){const o=t.slice(5).replace(Nb,MT);r="data"+o.charAt(0).toUpperCase()+o.slice(1)}else{const o=t.slice(4);if(!Nb.test(o)){let u=o.replace(ET,RT);u.charAt(0)!=="-"&&(u="-"+u),t="data"+u}}s=Hg}return new s(r,t)}function RT(e){return"-"+e.toLowerCase()}function MT(e){return e.charAt(1).toUpperCase()}const OT=ck([uk,CT,hk,gk,mk],"html"),Bg=ck([uk,NT,hk,gk,mk],"svg");function _T(e){return e.join(" ").trim()}var Ti={},lh,Ab;function LT(){if(Ab)return lh;Ab=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,s=/^:\s*/,o=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,u=/^[;\s]*/,f=/^\s+|\s+$/g,h=`
|
|
432
432
|
`,g="/",y="*",p="",b="comment",v="declaration";function k(N,C){if(typeof N!="string")throw new TypeError("First argument must be a string");if(!N)return[];C=C||{};var E=1,R=1;function H(J){var Z=J.match(t);Z&&(E+=Z.length);var U=J.lastIndexOf(h);R=~U?J.length-U:R+J.length}function z(){var J={line:E,column:R};return function(Z){return Z.position=new L(J),P(),Z}}function L(J){this.start=J,this.end={line:E,column:R},this.source=C.source}L.prototype.content=N;function G(J){var Z=new Error(C.source+":"+E+":"+R+": "+J);if(Z.reason=J,Z.filename=C.source,Z.line=E,Z.column=R,Z.source=N,!C.silent)throw Z}function W(J){var Z=J.exec(N);if(Z){var U=Z[0];return H(U),N=N.slice(U.length),Z}}function P(){W(n)}function M(J){var Z;for(J=J||[];Z=$();)Z!==!1&&J.push(Z);return J}function $(){var J=z();if(!(g!=N.charAt(0)||y!=N.charAt(1))){for(var Z=2;p!=N.charAt(Z)&&(y!=N.charAt(Z)||g!=N.charAt(Z+1));)++Z;if(Z+=2,p===N.charAt(Z-1))return G("End of comment missing");var U=N.slice(2,Z-2);return R+=2,H(U),N=N.slice(Z),R+=2,J({type:b,comment:U})}}function V(){var J=z(),Z=W(r);if(Z){if($(),!W(s))return G("property missing ':'");var U=W(o),ee=J({type:v,property:j(Z[0].replace(e,p)),value:U?j(U[0].replace(e,p)):p});return W(u),ee}}function ae(){var J=[];M(J);for(var Z;Z=V();)Z!==!1&&(J.push(Z),M(J));return J}return P(),ae()}function j(N){return N?N.replace(f,p):p}return lh=k,lh}var Eb;function zT(){if(Eb)return Ti;Eb=1;var e=Ti&&Ti.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ti,"__esModule",{value:!0}),Ti.default=n;const t=e(LT());function n(r,s){let o=null;if(!r||typeof r!="string")return o;const u=(0,t.default)(r),f=typeof s=="function";return u.forEach(h=>{if(h.type!=="declaration")return;const{property:g,value:y}=h;f?s(g,y,h):y&&(o=o||{},o[g]=y)}),o}return Ti}var Gs={},Tb;function IT(){if(Tb)return Gs;Tb=1,Object.defineProperty(Gs,"__esModule",{value:!0}),Gs.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,s=/^-(ms)-/,o=function(g){return!g||n.test(g)||e.test(g)},u=function(g,y){return y.toUpperCase()},f=function(g,y){return"".concat(y,"-")},h=function(g,y){return y===void 0&&(y={}),o(g)?g:(g=g.toLowerCase(),y.reactCompat?g=g.replace(s,f):g=g.replace(r,f),g.replace(t,u))};return Gs.camelCase=h,Gs}var Vs,Db;function HT(){if(Db)return Vs;Db=1;var e=Vs&&Vs.__importDefault||function(s){return s&&s.__esModule?s:{default:s}},t=e(zT()),n=IT();function r(s,o){var u={};return!s||typeof s!="string"||(0,t.default)(s,function(f,h){f&&h&&(u[(0,n.camelCase)(f,o)]=h)}),u}return r.default=r,Vs=r,Vs}var BT=HT();const UT=mg(BT),pk=yk("end"),Ug=yk("start");function yk(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function $T(e){const t=Ug(e),n=pk(e);if(t&&n)return{start:t,end:n}}function ul(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?Rb(e.position):"start"in e||"end"in e?Rb(e):"line"in e||"column"in e?rg(e):""}function rg(e){return Mb(e&&e.line)+":"+Mb(e&&e.column)}function Rb(e){return rg(e&&e.start)+"-"+rg(e&&e.end)}function Mb(e){return e&&typeof e=="number"?e:1}class _t extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let s="",o={},u=!1;if(n&&("line"in n&&"column"in n?o={place:n}:"start"in n&&"end"in n?o={place:n}:"type"in n?o={ancestors:[n],place:n.position}:o={...n}),typeof t=="string"?s=t:!o.cause&&t&&(u=!0,s=t.message,o.cause=t),!o.ruleId&&!o.source&&typeof r=="string"){const h=r.indexOf(":");h===-1?o.ruleId=r:(o.source=r.slice(0,h),o.ruleId=r.slice(h+1))}if(!o.place&&o.ancestors&&o.ancestors){const h=o.ancestors[o.ancestors.length-1];h&&(o.place=h.position)}const f=o.place&&"start"in o.place?o.place.start:o.place;this.ancestors=o.ancestors||void 0,this.cause=o.cause||void 0,this.column=f?f.column:void 0,this.fatal=void 0,this.file="",this.message=s,this.line=f?f.line:void 0,this.name=ul(o.place)||"1:1",this.place=o.place||void 0,this.reason=this.message,this.ruleId=o.ruleId||void 0,this.source=o.source||void 0,this.stack=u&&o.cause&&typeof o.cause.stack=="string"?o.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}_t.prototype.file="";_t.prototype.name="";_t.prototype.reason="";_t.prototype.message="";_t.prototype.stack="";_t.prototype.column=void 0;_t.prototype.line=void 0;_t.prototype.ancestors=void 0;_t.prototype.cause=void 0;_t.prototype.fatal=void 0;_t.prototype.place=void 0;_t.prototype.ruleId=void 0;_t.prototype.source=void 0;const $g={}.hasOwnProperty,qT=new Map,KT=/[A-Z]/g,PT=new Set(["table","tbody","thead","tfoot","tr"]),FT=new Set(["td","th"]),xk="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function GT(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=eD(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=JT(n,t.jsx,t.jsxs)}const s={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?Bg:OT,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},o=bk(s,e,void 0);return o&&typeof o!="string"?o:s.create(e,s.Fragment,{children:o||void 0},void 0)}function bk(e,t,n){if(t.type==="element")return VT(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return YT(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return WT(e,t,n);if(t.type==="mdxjsEsm")return QT(e,t);if(t.type==="root")return XT(e,t,n);if(t.type==="text")return ZT(e,t)}function VT(e,t,n){const r=e.schema;let s=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(s=Bg,e.schema=s),e.ancestors.push(t);const o=kk(e,t.tagName,!1),u=tD(e,t);let f=Kg(e,t);return PT.has(t.tagName)&&(f=f.filter(function(h){return typeof h=="string"?!ST(h):!0})),vk(e,u,o,t),qg(u,f),e.ancestors.pop(),e.schema=r,e.create(t,o,u,n)}function YT(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}wl(e,t.position)}function QT(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);wl(e,t.position)}function WT(e,t,n){const r=e.schema;let s=r;t.name==="svg"&&r.space==="html"&&(s=Bg,e.schema=s),e.ancestors.push(t);const o=t.name===null?e.Fragment:kk(e,t.name,!0),u=nD(e,t),f=Kg(e,t);return vk(e,u,o,t),qg(u,f),e.ancestors.pop(),e.schema=r,e.create(t,o,u,n)}function XT(e,t,n){const r={};return qg(r,Kg(e,t)),e.create(t,e.Fragment,r,n)}function ZT(e,t){return t.value}function vk(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function qg(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function JT(e,t,n){return r;function r(s,o,u,f){const g=Array.isArray(u.children)?n:t;return f?g(o,u,f):g(o,u)}}function eD(e,t){return n;function n(r,s,o,u){const f=Array.isArray(o.children),h=Ug(r);return t(s,o,u,f,{columnNumber:h?h.column-1:void 0,fileName:e,lineNumber:h?h.line:void 0},void 0)}}function tD(e,t){const n={};let r,s;for(s in t.properties)if(s!=="children"&&$g.call(t.properties,s)){const o=aD(e,s,t.properties[s]);if(o){const[u,f]=o;e.tableCellAlignToStyle&&u==="align"&&typeof f=="string"&&FT.has(t.tagName)?r=f:n[u]=f}}if(r){const o=n.style||(n.style={});o[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function nD(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const o=r.data.estree.body[0];o.type;const u=o.expression;u.type;const f=u.properties[0];f.type,Object.assign(n,e.evaluater.evaluateExpression(f.argument))}else wl(e,t.position);else{const s=r.name;let o;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const f=r.value.data.estree.body[0];f.type,o=e.evaluater.evaluateExpression(f.expression)}else wl(e,t.position);else o=r.value===null?!0:r.value;n[s]=o}return n}function Kg(e,t){const n=[];let r=-1;const s=e.passKeys?new Map:qT;for(;++r<t.children.length;){const o=t.children[r];let u;if(e.passKeys){const h=o.type==="element"?o.tagName:o.type==="mdxJsxFlowElement"||o.type==="mdxJsxTextElement"?o.name:void 0;if(h){const g=s.get(h)||0;u=h+"-"+g,s.set(h,g+1)}}const f=bk(e,o,u);f!==void 0&&n.push(f)}return n}function aD(e,t,n){const r=DT(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?xT(n):_T(n)),r.property==="style"){let s=typeof n=="object"?n:rD(e,String(n));return e.stylePropertyNameCase==="css"&&(s=iD(s)),["style",s]}return[e.elementAttributeNameCase==="react"&&r.space?AT[r.property]||r.property:r.attribute,n]}}function rD(e,t){try{return UT(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,s=new _t("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw s.file=e.filePath||void 0,s.url=xk+"#cannot-parse-style-attribute",s}}function kk(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const s=t.split(".");let o=-1,u;for(;++o<s.length;){const f=Sb(s[o])?{type:"Identifier",name:s[o]}:{type:"Literal",value:s[o]};u=u?{type:"MemberExpression",object:u,property:f,computed:!!(o&&f.type==="Literal"),optional:!1}:f}r=u}else r=Sb(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const s=r.value;return $g.call(e.components,s)?e.components[s]:s}if(e.evaluater)return e.evaluater.evaluateExpression(r);wl(e)}function wl(e,t){const n=new _t("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=xk+"#cannot-handle-mdx-estrees-without-createevaluater",n}function iD(e){const t={};let n;for(n in e)$g.call(e,n)&&(t[sD(n)]=e[n]);return t}function sD(e){let t=e.replace(KT,lD);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function lD(e){return"-"+e.toLowerCase()}const oh={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},oD={};function Pg(e,t){const n=oD,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,s=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return wk(e,r,s)}function wk(e,t,n){if(cD(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return Ob(e.children,t,n)}return Array.isArray(e)?Ob(e,t,n):""}function Ob(e,t,n){const r=[];let s=-1;for(;++s<e.length;)r[s]=wk(e[s],t,n);return r.join("")}function cD(e){return!!(e&&typeof e=="object")}const _b=document.createElement("i");function Fg(e){const t="&"+e+";";_b.innerHTML=t;const n=_b.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function dn(e,t,n,r){const s=e.length;let o=0,u;if(t<0?t=-t>s?0:s+t:t=t>s?s:t,n=n>0?n:0,r.length<1e4)u=Array.from(r),u.unshift(t,n),e.splice(...u);else for(n&&e.splice(t,n);o<r.length;)u=r.slice(o,o+1e4),u.unshift(t,0),e.splice(...u),o+=1e4,t+=1e4}function Cn(e,t){return e.length>0?(dn(e,e.length,0,t),e):t}const Lb={}.hasOwnProperty;function Sk(e){const t={};let n=-1;for(;++n<e.length;)uD(t,e[n]);return t}function uD(e,t){let n;for(n in t){const s=(Lb.call(e,n)?e[n]:void 0)||(e[n]={}),o=t[n];let u;if(o)for(u in o){Lb.call(s,u)||(s[u]=[]);const f=o[u];dD(s[u],Array.isArray(f)?f:f?[f]:[])}}}function dD(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);dn(e,0,0,r)}function jk(e,t){const n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function Un(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Ut=nr(/[A-Za-z]/),Ot=nr(/[\dA-Za-z]/),fD=nr(/[#-'*+\--9=?A-Z^-~]/);function Kc(e){return e!==null&&(e<32||e===127)}const ig=nr(/\d/),hD=nr(/[\dA-Fa-f]/),gD=nr(/[!-/:-@[-`{-~]/);function be(e){return e!==null&&e<-2}function at(e){return e!==null&&(e<0||e===32)}function Ie(e){return e===-2||e===-1||e===32}const cu=nr(new RegExp("\\p{P}|\\p{S}","u")),_r=nr(/\s/);function nr(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function Gi(e){const t=[];let n=-1,r=0,s=0;for(;++n<e.length;){const o=e.charCodeAt(n);let u="";if(o===37&&Ot(e.charCodeAt(n+1))&&Ot(e.charCodeAt(n+2)))s=2;else if(o<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(o))||(u=String.fromCharCode(o));else if(o>55295&&o<57344){const f=e.charCodeAt(n+1);o<56320&&f>56319&&f<57344?(u=String.fromCharCode(o,f),s=1):u="�"}else u=String.fromCharCode(o);u&&(t.push(e.slice(r,n),encodeURIComponent(u)),r=n+s+1,u=""),s&&(n+=s,s=0)}return t.join("")+e.slice(r)}function $e(e,t,n,r){const s=r?r-1:Number.POSITIVE_INFINITY;let o=0;return u;function u(h){return Ie(h)?(e.enter(n),f(h)):t(h)}function f(h){return Ie(h)&&o++<s?(e.consume(h),f):(e.exit(n),t(h))}}const mD={tokenize:pD};function pD(e){const t=e.attempt(this.parser.constructs.contentInitial,r,s);let n;return t;function r(f){if(f===null){e.consume(f);return}return e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),$e(e,t,"linePrefix")}function s(f){return e.enter("paragraph"),o(f)}function o(f){const h=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=h),n=h,u(f)}function u(f){if(f===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(f);return}return be(f)?(e.consume(f),e.exit("chunkText"),o):(e.consume(f),u)}}const yD={tokenize:xD},zb={tokenize:bD};function xD(e){const t=this,n=[];let r=0,s,o,u;return f;function f(R){if(r<n.length){const H=n[r];return t.containerState=H[1],e.attempt(H[0].continuation,h,g)(R)}return g(R)}function h(R){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,s&&E();const H=t.events.length;let z=H,L;for(;z--;)if(t.events[z][0]==="exit"&&t.events[z][1].type==="chunkFlow"){L=t.events[z][1].end;break}C(r);let G=H;for(;G<t.events.length;)t.events[G][1].end={...L},G++;return dn(t.events,z+1,0,t.events.slice(H)),t.events.length=G,g(R)}return f(R)}function g(R){if(r===n.length){if(!s)return b(R);if(s.currentConstruct&&s.currentConstruct.concrete)return k(R);t.interrupt=!!(s.currentConstruct&&!s._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(zb,y,p)(R)}function y(R){return s&&E(),C(r),b(R)}function p(R){return t.parser.lazy[t.now().line]=r!==n.length,u=t.now().offset,k(R)}function b(R){return t.containerState={},e.attempt(zb,v,k)(R)}function v(R){return r++,n.push([t.currentConstruct,t.containerState]),b(R)}function k(R){if(R===null){s&&E(),C(0),e.consume(R);return}return s=s||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:s,contentType:"flow",previous:o}),j(R)}function j(R){if(R===null){N(e.exit("chunkFlow"),!0),C(0),e.consume(R);return}return be(R)?(e.consume(R),N(e.exit("chunkFlow")),r=0,t.interrupt=void 0,f):(e.consume(R),j)}function N(R,H){const z=t.sliceStream(R);if(H&&z.push(null),R.previous=o,o&&(o.next=R),o=R,s.defineSkip(R.start),s.write(z),t.parser.lazy[R.start.line]){let L=s.events.length;for(;L--;)if(s.events[L][1].start.offset<u&&(!s.events[L][1].end||s.events[L][1].end.offset>u))return;const G=t.events.length;let W=G,P,M;for(;W--;)if(t.events[W][0]==="exit"&&t.events[W][1].type==="chunkFlow"){if(P){M=t.events[W][1].end;break}P=!0}for(C(r),L=G;L<t.events.length;)t.events[L][1].end={...M},L++;dn(t.events,W+1,0,t.events.slice(G)),t.events.length=L}}function C(R){let H=n.length;for(;H-- >R;){const z=n[H];t.containerState=z[1],z[0].exit.call(t,e)}n.length=R}function E(){s.write([null]),o=void 0,s=void 0,t.containerState._closeFlow=void 0}}function bD(e,t,n){return $e(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function Ii(e){if(e===null||at(e)||_r(e))return 1;if(cu(e))return 2}function uu(e,t,n){const r=[];let s=-1;for(;++s<e.length;){const o=e[s].resolveAll;o&&!r.includes(o)&&(t=o(t,n),r.push(o))}return t}const sg={name:"attention",resolveAll:vD,tokenize:kD};function vD(e,t){let n=-1,r,s,o,u,f,h,g,y;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;h=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const p={...e[r][1].end},b={...e[n][1].start};Ib(p,-h),Ib(b,h),u={type:h>1?"strongSequence":"emphasisSequence",start:p,end:{...e[r][1].end}},f={type:h>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:b},o={type:h>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},s={type:h>1?"strong":"emphasis",start:{...u.start},end:{...f.end}},e[r][1].end={...u.start},e[n][1].start={...f.end},g=[],e[r][1].end.offset-e[r][1].start.offset&&(g=Cn(g,[["enter",e[r][1],t],["exit",e[r][1],t]])),g=Cn(g,[["enter",s,t],["enter",u,t],["exit",u,t],["enter",o,t]]),g=Cn(g,uu(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),g=Cn(g,[["exit",o,t],["enter",f,t],["exit",f,t],["exit",s,t]]),e[n][1].end.offset-e[n][1].start.offset?(y=2,g=Cn(g,[["enter",e[n][1],t],["exit",e[n][1],t]])):y=0,dn(e,r-1,n-r+3,g),n=r+g.length-y-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function kD(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,s=Ii(r);let o;return u;function u(h){return o=h,e.enter("attentionSequence"),f(h)}function f(h){if(h===o)return e.consume(h),f;const g=e.exit("attentionSequence"),y=Ii(h),p=!y||y===2&&s||n.includes(h),b=!s||s===2&&y||n.includes(r);return g._open=!!(o===42?p:p&&(s||!b)),g._close=!!(o===42?b:b&&(y||!p)),t(h)}}function Ib(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const wD={name:"autolink",tokenize:SD};function SD(e,t,n){let r=0;return s;function s(v){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(v),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),o}function o(v){return Ut(v)?(e.consume(v),u):v===64?n(v):g(v)}function u(v){return v===43||v===45||v===46||Ot(v)?(r=1,f(v)):g(v)}function f(v){return v===58?(e.consume(v),r=0,h):(v===43||v===45||v===46||Ot(v))&&r++<32?(e.consume(v),f):(r=0,g(v))}function h(v){return v===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(v),e.exit("autolinkMarker"),e.exit("autolink"),t):v===null||v===32||v===60||Kc(v)?n(v):(e.consume(v),h)}function g(v){return v===64?(e.consume(v),y):fD(v)?(e.consume(v),g):n(v)}function y(v){return Ot(v)?p(v):n(v)}function p(v){return v===46?(e.consume(v),r=0,y):v===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(v),e.exit("autolinkMarker"),e.exit("autolink"),t):b(v)}function b(v){if((v===45||Ot(v))&&r++<63){const k=v===45?b:p;return e.consume(v),k}return n(v)}}const _l={partial:!0,tokenize:jD};function jD(e,t,n){return r;function r(o){return Ie(o)?$e(e,s,"linePrefix")(o):s(o)}function s(o){return o===null||be(o)?t(o):n(o)}}const Ck={continuation:{tokenize:ND},exit:AD,name:"blockQuote",tokenize:CD};function CD(e,t,n){const r=this;return s;function s(u){if(u===62){const f=r.containerState;return f.open||(e.enter("blockQuote",{_container:!0}),f.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(u),e.exit("blockQuoteMarker"),o}return n(u)}function o(u){return Ie(u)?(e.enter("blockQuotePrefixWhitespace"),e.consume(u),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(u))}}function ND(e,t,n){const r=this;return s;function s(u){return Ie(u)?$e(e,o,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(u):o(u)}function o(u){return e.attempt(Ck,t,n)(u)}}function AD(e){e.exit("blockQuote")}const Nk={name:"characterEscape",tokenize:ED};function ED(e,t,n){return r;function r(o){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(o),e.exit("escapeMarker"),s}function s(o){return gD(o)?(e.enter("characterEscapeValue"),e.consume(o),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(o)}}const Ak={name:"characterReference",tokenize:TD};function TD(e,t,n){const r=this;let s=0,o,u;return f;function f(p){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(p),e.exit("characterReferenceMarker"),h}function h(p){return p===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(p),e.exit("characterReferenceMarkerNumeric"),g):(e.enter("characterReferenceValue"),o=31,u=Ot,y(p))}function g(p){return p===88||p===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(p),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),o=6,u=hD,y):(e.enter("characterReferenceValue"),o=7,u=ig,y(p))}function y(p){if(p===59&&s){const b=e.exit("characterReferenceValue");return u===Ot&&!Fg(r.sliceSerialize(b))?n(p):(e.enter("characterReferenceMarker"),e.consume(p),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return u(p)&&s++<o?(e.consume(p),y):n(p)}}const Hb={partial:!0,tokenize:RD},Bb={concrete:!0,name:"codeFenced",tokenize:DD};function DD(e,t,n){const r=this,s={partial:!0,tokenize:z};let o=0,u=0,f;return h;function h(L){return g(L)}function g(L){const G=r.events[r.events.length-1];return o=G&&G[1].type==="linePrefix"?G[2].sliceSerialize(G[1],!0).length:0,f=L,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),y(L)}function y(L){return L===f?(u++,e.consume(L),y):u<3?n(L):(e.exit("codeFencedFenceSequence"),Ie(L)?$e(e,p,"whitespace")(L):p(L))}function p(L){return L===null||be(L)?(e.exit("codeFencedFence"),r.interrupt?t(L):e.check(Hb,j,H)(L)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),b(L))}function b(L){return L===null||be(L)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),p(L)):Ie(L)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),$e(e,v,"whitespace")(L)):L===96&&L===f?n(L):(e.consume(L),b)}function v(L){return L===null||be(L)?p(L):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),k(L))}function k(L){return L===null||be(L)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),p(L)):L===96&&L===f?n(L):(e.consume(L),k)}function j(L){return e.attempt(s,H,N)(L)}function N(L){return e.enter("lineEnding"),e.consume(L),e.exit("lineEnding"),C}function C(L){return o>0&&Ie(L)?$e(e,E,"linePrefix",o+1)(L):E(L)}function E(L){return L===null||be(L)?e.check(Hb,j,H)(L):(e.enter("codeFlowValue"),R(L))}function R(L){return L===null||be(L)?(e.exit("codeFlowValue"),E(L)):(e.consume(L),R)}function H(L){return e.exit("codeFenced"),t(L)}function z(L,G,W){let P=0;return M;function M(Z){return L.enter("lineEnding"),L.consume(Z),L.exit("lineEnding"),$}function $(Z){return L.enter("codeFencedFence"),Ie(Z)?$e(L,V,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(Z):V(Z)}function V(Z){return Z===f?(L.enter("codeFencedFenceSequence"),ae(Z)):W(Z)}function ae(Z){return Z===f?(P++,L.consume(Z),ae):P>=u?(L.exit("codeFencedFenceSequence"),Ie(Z)?$e(L,J,"whitespace")(Z):J(Z)):W(Z)}function J(Z){return Z===null||be(Z)?(L.exit("codeFencedFence"),G(Z)):W(Z)}}}function RD(e,t,n){const r=this;return s;function s(u){return u===null?n(u):(e.enter("lineEnding"),e.consume(u),e.exit("lineEnding"),o)}function o(u){return r.parser.lazy[r.now().line]?n(u):t(u)}}const ch={name:"codeIndented",tokenize:OD},MD={partial:!0,tokenize:_D};function OD(e,t,n){const r=this;return s;function s(g){return e.enter("codeIndented"),$e(e,o,"linePrefix",5)(g)}function o(g){const y=r.events[r.events.length-1];return y&&y[1].type==="linePrefix"&&y[2].sliceSerialize(y[1],!0).length>=4?u(g):n(g)}function u(g){return g===null?h(g):be(g)?e.attempt(MD,u,h)(g):(e.enter("codeFlowValue"),f(g))}function f(g){return g===null||be(g)?(e.exit("codeFlowValue"),u(g)):(e.consume(g),f)}function h(g){return e.exit("codeIndented"),t(g)}}function _D(e,t,n){const r=this;return s;function s(u){return r.parser.lazy[r.now().line]?n(u):be(u)?(e.enter("lineEnding"),e.consume(u),e.exit("lineEnding"),s):$e(e,o,"linePrefix",5)(u)}function o(u){const f=r.events[r.events.length-1];return f&&f[1].type==="linePrefix"&&f[2].sliceSerialize(f[1],!0).length>=4?t(u):be(u)?s(u):n(u)}}const LD={name:"codeText",previous:ID,resolve:zD,tokenize:HD};function zD(e){let t=e.length-4,n=3,r,s;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)s===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(s=r):(r===t||e[r][1].type==="lineEnding")&&(e[s][1].type="codeTextData",r!==s+2&&(e[s][1].end=e[r-1][1].end,e.splice(s+2,r-s-2),t-=r-s-2,r=s+2),s=void 0);return e}function ID(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function HD(e,t,n){let r=0,s,o;return u;function u(p){return e.enter("codeText"),e.enter("codeTextSequence"),f(p)}function f(p){return p===96?(e.consume(p),r++,f):(e.exit("codeTextSequence"),h(p))}function h(p){return p===null?n(p):p===32?(e.enter("space"),e.consume(p),e.exit("space"),h):p===96?(o=e.enter("codeTextSequence"),s=0,y(p)):be(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),h):(e.enter("codeTextData"),g(p))}function g(p){return p===null||p===32||p===96||be(p)?(e.exit("codeTextData"),h(p)):(e.consume(p),g)}function y(p){return p===96?(e.consume(p),s++,y):s===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(p)):(o.type="codeTextData",g(p))}}class BD{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const s=n||0;this.setCursor(Math.trunc(t));const o=this.right.splice(this.right.length-s,Number.POSITIVE_INFINITY);return r&&Ys(this.left,r),o.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Ys(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Ys(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);Ys(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Ys(this.left,n.reverse())}}}function Ys(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function Ek(e){const t={};let n=-1,r,s,o,u,f,h,g;const y=new BD(e);for(;++n<y.length;){for(;n in t;)n=t[n];if(r=y.get(n),n&&r[1].type==="chunkFlow"&&y.get(n-1)[1].type==="listItemPrefix"&&(h=r[1]._tokenizer.events,o=0,o<h.length&&h[o][1].type==="lineEndingBlank"&&(o+=2),o<h.length&&h[o][1].type==="content"))for(;++o<h.length&&h[o][1].type!=="content";)h[o][1].type==="chunkText"&&(h[o][1]._isInFirstContentOfListItem=!0,o++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,UD(y,n)),n=t[n],g=!0);else if(r[1]._container){for(o=n,s=void 0;o--;)if(u=y.get(o),u[1].type==="lineEnding"||u[1].type==="lineEndingBlank")u[0]==="enter"&&(s&&(y.get(s)[1].type="lineEndingBlank"),u[1].type="lineEnding",s=o);else if(!(u[1].type==="linePrefix"||u[1].type==="listItemIndent"))break;s&&(r[1].end={...y.get(s)[1].start},f=y.slice(s,n),f.unshift(r),y.splice(s,n-s+1,f))}}return dn(e,0,Number.POSITIVE_INFINITY,y.slice(0)),!g}function UD(e,t){const n=e.get(t)[1],r=e.get(t)[2];let s=t-1;const o=[];let u=n._tokenizer;u||(u=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(u._contentTypeTextTrailing=!0));const f=u.events,h=[],g={};let y,p,b=-1,v=n,k=0,j=0;const N=[j];for(;v;){for(;e.get(++s)[1]!==v;);o.push(s),v._tokenizer||(y=r.sliceStream(v),v.next||y.push(null),p&&u.defineSkip(v.start),v._isInFirstContentOfListItem&&(u._gfmTasklistFirstContentOfListItem=!0),u.write(y),v._isInFirstContentOfListItem&&(u._gfmTasklistFirstContentOfListItem=void 0)),p=v,v=v.next}for(v=n;++b<f.length;)f[b][0]==="exit"&&f[b-1][0]==="enter"&&f[b][1].type===f[b-1][1].type&&f[b][1].start.line!==f[b][1].end.line&&(j=b+1,N.push(j),v._tokenizer=void 0,v.previous=void 0,v=v.next);for(u.events=[],v?(v._tokenizer=void 0,v.previous=void 0):N.pop(),b=N.length;b--;){const C=f.slice(N[b],N[b+1]),E=o.pop();h.push([E,E+C.length-1]),e.splice(E,2,C)}for(h.reverse(),b=-1;++b<h.length;)g[k+h[b][0]]=k+h[b][1],k+=h[b][1]-h[b][0]-1;return g}const $D={resolve:KD,tokenize:PD},qD={partial:!0,tokenize:FD};function KD(e){return Ek(e),e}function PD(e,t){let n;return r;function r(f){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),s(f)}function s(f){return f===null?o(f):be(f)?e.check(qD,u,o)(f):(e.consume(f),s)}function o(f){return e.exit("chunkContent"),e.exit("content"),t(f)}function u(f){return e.consume(f),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,s}}function FD(e,t,n){const r=this;return s;function s(u){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(u),e.exit("lineEnding"),$e(e,o,"linePrefix")}function o(u){if(u===null||be(u))return n(u);const f=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&f&&f[1].type==="linePrefix"&&f[2].sliceSerialize(f[1],!0).length>=4?t(u):e.interrupt(r.parser.constructs.flow,n,t)(u)}}function Tk(e,t,n,r,s,o,u,f,h){const g=h||Number.POSITIVE_INFINITY;let y=0;return p;function p(C){return C===60?(e.enter(r),e.enter(s),e.enter(o),e.consume(C),e.exit(o),b):C===null||C===32||C===41||Kc(C)?n(C):(e.enter(r),e.enter(u),e.enter(f),e.enter("chunkString",{contentType:"string"}),j(C))}function b(C){return C===62?(e.enter(o),e.consume(C),e.exit(o),e.exit(s),e.exit(r),t):(e.enter(f),e.enter("chunkString",{contentType:"string"}),v(C))}function v(C){return C===62?(e.exit("chunkString"),e.exit(f),b(C)):C===null||C===60||be(C)?n(C):(e.consume(C),C===92?k:v)}function k(C){return C===60||C===62||C===92?(e.consume(C),v):v(C)}function j(C){return!y&&(C===null||C===41||at(C))?(e.exit("chunkString"),e.exit(f),e.exit(u),e.exit(r),t(C)):y<g&&C===40?(e.consume(C),y++,j):C===41?(e.consume(C),y--,j):C===null||C===32||C===40||Kc(C)?n(C):(e.consume(C),C===92?N:j)}function N(C){return C===40||C===41||C===92?(e.consume(C),j):j(C)}}function Dk(e,t,n,r,s,o){const u=this;let f=0,h;return g;function g(v){return e.enter(r),e.enter(s),e.consume(v),e.exit(s),e.enter(o),y}function y(v){return f>999||v===null||v===91||v===93&&!h||v===94&&!f&&"_hiddenFootnoteSupport"in u.parser.constructs?n(v):v===93?(e.exit(o),e.enter(s),e.consume(v),e.exit(s),e.exit(r),t):be(v)?(e.enter("lineEnding"),e.consume(v),e.exit("lineEnding"),y):(e.enter("chunkString",{contentType:"string"}),p(v))}function p(v){return v===null||v===91||v===93||be(v)||f++>999?(e.exit("chunkString"),y(v)):(e.consume(v),h||(h=!Ie(v)),v===92?b:p)}function b(v){return v===91||v===92||v===93?(e.consume(v),f++,p):p(v)}}function Rk(e,t,n,r,s,o){let u;return f;function f(b){return b===34||b===39||b===40?(e.enter(r),e.enter(s),e.consume(b),e.exit(s),u=b===40?41:b,h):n(b)}function h(b){return b===u?(e.enter(s),e.consume(b),e.exit(s),e.exit(r),t):(e.enter(o),g(b))}function g(b){return b===u?(e.exit(o),h(u)):b===null?n(b):be(b)?(e.enter("lineEnding"),e.consume(b),e.exit("lineEnding"),$e(e,g,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),y(b))}function y(b){return b===u||b===null||be(b)?(e.exit("chunkString"),g(b)):(e.consume(b),b===92?p:y)}function p(b){return b===u||b===92?(e.consume(b),y):y(b)}}function dl(e,t){let n;return r;function r(s){return be(s)?(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),n=!0,r):Ie(s)?$e(e,r,n?"linePrefix":"lineSuffix")(s):t(s)}}const GD={name:"definition",tokenize:YD},VD={partial:!0,tokenize:QD};function YD(e,t,n){const r=this;let s;return o;function o(v){return e.enter("definition"),u(v)}function u(v){return Dk.call(r,e,f,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(v)}function f(v){return s=Un(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),v===58?(e.enter("definitionMarker"),e.consume(v),e.exit("definitionMarker"),h):n(v)}function h(v){return at(v)?dl(e,g)(v):g(v)}function g(v){return Tk(e,y,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(v)}function y(v){return e.attempt(VD,p,p)(v)}function p(v){return Ie(v)?$e(e,b,"whitespace")(v):b(v)}function b(v){return v===null||be(v)?(e.exit("definition"),r.parser.defined.push(s),t(v)):n(v)}}function QD(e,t,n){return r;function r(f){return at(f)?dl(e,s)(f):n(f)}function s(f){return Rk(e,o,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(f)}function o(f){return Ie(f)?$e(e,u,"whitespace")(f):u(f)}function u(f){return f===null||be(f)?t(f):n(f)}}const WD={name:"hardBreakEscape",tokenize:XD};function XD(e,t,n){return r;function r(o){return e.enter("hardBreakEscape"),e.consume(o),s}function s(o){return be(o)?(e.exit("hardBreakEscape"),t(o)):n(o)}}const ZD={name:"headingAtx",resolve:JD,tokenize:e6};function JD(e,t){let n=e.length-2,r=3,s,o;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(s={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},o={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},dn(e,r,n-r+1,[["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t]])),e}function e6(e,t,n){let r=0;return s;function s(y){return e.enter("atxHeading"),o(y)}function o(y){return e.enter("atxHeadingSequence"),u(y)}function u(y){return y===35&&r++<6?(e.consume(y),u):y===null||at(y)?(e.exit("atxHeadingSequence"),f(y)):n(y)}function f(y){return y===35?(e.enter("atxHeadingSequence"),h(y)):y===null||be(y)?(e.exit("atxHeading"),t(y)):Ie(y)?$e(e,f,"whitespace")(y):(e.enter("atxHeadingText"),g(y))}function h(y){return y===35?(e.consume(y),h):(e.exit("atxHeadingSequence"),f(y))}function g(y){return y===null||y===35||at(y)?(e.exit("atxHeadingText"),f(y)):(e.consume(y),g)}}const t6=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],Ub=["pre","script","style","textarea"],n6={concrete:!0,name:"htmlFlow",resolveTo:i6,tokenize:s6},a6={partial:!0,tokenize:o6},r6={partial:!0,tokenize:l6};function i6(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function s6(e,t,n){const r=this;let s,o,u,f,h;return g;function g(D){return y(D)}function y(D){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(D),p}function p(D){return D===33?(e.consume(D),b):D===47?(e.consume(D),o=!0,j):D===63?(e.consume(D),s=3,r.interrupt?t:T):Ut(D)?(e.consume(D),u=String.fromCharCode(D),N):n(D)}function b(D){return D===45?(e.consume(D),s=2,v):D===91?(e.consume(D),s=5,f=0,k):Ut(D)?(e.consume(D),s=4,r.interrupt?t:T):n(D)}function v(D){return D===45?(e.consume(D),r.interrupt?t:T):n(D)}function k(D){const ce="CDATA[";return D===ce.charCodeAt(f++)?(e.consume(D),f===ce.length?r.interrupt?t:V:k):n(D)}function j(D){return Ut(D)?(e.consume(D),u=String.fromCharCode(D),N):n(D)}function N(D){if(D===null||D===47||D===62||at(D)){const ce=D===47,me=u.toLowerCase();return!ce&&!o&&Ub.includes(me)?(s=1,r.interrupt?t(D):V(D)):t6.includes(u.toLowerCase())?(s=6,ce?(e.consume(D),C):r.interrupt?t(D):V(D)):(s=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(D):o?E(D):R(D))}return D===45||Ot(D)?(e.consume(D),u+=String.fromCharCode(D),N):n(D)}function C(D){return D===62?(e.consume(D),r.interrupt?t:V):n(D)}function E(D){return Ie(D)?(e.consume(D),E):M(D)}function R(D){return D===47?(e.consume(D),M):D===58||D===95||Ut(D)?(e.consume(D),H):Ie(D)?(e.consume(D),R):M(D)}function H(D){return D===45||D===46||D===58||D===95||Ot(D)?(e.consume(D),H):z(D)}function z(D){return D===61?(e.consume(D),L):Ie(D)?(e.consume(D),z):R(D)}function L(D){return D===null||D===60||D===61||D===62||D===96?n(D):D===34||D===39?(e.consume(D),h=D,G):Ie(D)?(e.consume(D),L):W(D)}function G(D){return D===h?(e.consume(D),h=null,P):D===null||be(D)?n(D):(e.consume(D),G)}function W(D){return D===null||D===34||D===39||D===47||D===60||D===61||D===62||D===96||at(D)?z(D):(e.consume(D),W)}function P(D){return D===47||D===62||Ie(D)?R(D):n(D)}function M(D){return D===62?(e.consume(D),$):n(D)}function $(D){return D===null||be(D)?V(D):Ie(D)?(e.consume(D),$):n(D)}function V(D){return D===45&&s===2?(e.consume(D),U):D===60&&s===1?(e.consume(D),ee):D===62&&s===4?(e.consume(D),O):D===63&&s===3?(e.consume(D),T):D===93&&s===5?(e.consume(D),ke):be(D)&&(s===6||s===7)?(e.exit("htmlFlowData"),e.check(a6,Q,ae)(D)):D===null||be(D)?(e.exit("htmlFlowData"),ae(D)):(e.consume(D),V)}function ae(D){return e.check(r6,J,Q)(D)}function J(D){return e.enter("lineEnding"),e.consume(D),e.exit("lineEnding"),Z}function Z(D){return D===null||be(D)?ae(D):(e.enter("htmlFlowData"),V(D))}function U(D){return D===45?(e.consume(D),T):V(D)}function ee(D){return D===47?(e.consume(D),u="",de):V(D)}function de(D){if(D===62){const ce=u.toLowerCase();return Ub.includes(ce)?(e.consume(D),O):V(D)}return Ut(D)&&u.length<8?(e.consume(D),u+=String.fromCharCode(D),de):V(D)}function ke(D){return D===93?(e.consume(D),T):V(D)}function T(D){return D===62?(e.consume(D),O):D===45&&s===2?(e.consume(D),T):V(D)}function O(D){return D===null||be(D)?(e.exit("htmlFlowData"),Q(D)):(e.consume(D),O)}function Q(D){return e.exit("htmlFlow"),t(D)}}function l6(e,t,n){const r=this;return s;function s(u){return be(u)?(e.enter("lineEnding"),e.consume(u),e.exit("lineEnding"),o):n(u)}function o(u){return r.parser.lazy[r.now().line]?n(u):t(u)}}function o6(e,t,n){return r;function r(s){return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),e.attempt(_l,t,n)}}const c6={name:"htmlText",tokenize:u6};function u6(e,t,n){const r=this;let s,o,u;return f;function f(T){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(T),h}function h(T){return T===33?(e.consume(T),g):T===47?(e.consume(T),z):T===63?(e.consume(T),R):Ut(T)?(e.consume(T),W):n(T)}function g(T){return T===45?(e.consume(T),y):T===91?(e.consume(T),o=0,k):Ut(T)?(e.consume(T),E):n(T)}function y(T){return T===45?(e.consume(T),v):n(T)}function p(T){return T===null?n(T):T===45?(e.consume(T),b):be(T)?(u=p,ee(T)):(e.consume(T),p)}function b(T){return T===45?(e.consume(T),v):p(T)}function v(T){return T===62?U(T):T===45?b(T):p(T)}function k(T){const O="CDATA[";return T===O.charCodeAt(o++)?(e.consume(T),o===O.length?j:k):n(T)}function j(T){return T===null?n(T):T===93?(e.consume(T),N):be(T)?(u=j,ee(T)):(e.consume(T),j)}function N(T){return T===93?(e.consume(T),C):j(T)}function C(T){return T===62?U(T):T===93?(e.consume(T),C):j(T)}function E(T){return T===null||T===62?U(T):be(T)?(u=E,ee(T)):(e.consume(T),E)}function R(T){return T===null?n(T):T===63?(e.consume(T),H):be(T)?(u=R,ee(T)):(e.consume(T),R)}function H(T){return T===62?U(T):R(T)}function z(T){return Ut(T)?(e.consume(T),L):n(T)}function L(T){return T===45||Ot(T)?(e.consume(T),L):G(T)}function G(T){return be(T)?(u=G,ee(T)):Ie(T)?(e.consume(T),G):U(T)}function W(T){return T===45||Ot(T)?(e.consume(T),W):T===47||T===62||at(T)?P(T):n(T)}function P(T){return T===47?(e.consume(T),U):T===58||T===95||Ut(T)?(e.consume(T),M):be(T)?(u=P,ee(T)):Ie(T)?(e.consume(T),P):U(T)}function M(T){return T===45||T===46||T===58||T===95||Ot(T)?(e.consume(T),M):$(T)}function $(T){return T===61?(e.consume(T),V):be(T)?(u=$,ee(T)):Ie(T)?(e.consume(T),$):P(T)}function V(T){return T===null||T===60||T===61||T===62||T===96?n(T):T===34||T===39?(e.consume(T),s=T,ae):be(T)?(u=V,ee(T)):Ie(T)?(e.consume(T),V):(e.consume(T),J)}function ae(T){return T===s?(e.consume(T),s=void 0,Z):T===null?n(T):be(T)?(u=ae,ee(T)):(e.consume(T),ae)}function J(T){return T===null||T===34||T===39||T===60||T===61||T===96?n(T):T===47||T===62||at(T)?P(T):(e.consume(T),J)}function Z(T){return T===47||T===62||at(T)?P(T):n(T)}function U(T){return T===62?(e.consume(T),e.exit("htmlTextData"),e.exit("htmlText"),t):n(T)}function ee(T){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(T),e.exit("lineEnding"),de}function de(T){return Ie(T)?$e(e,ke,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(T):ke(T)}function ke(T){return e.enter("htmlTextData"),u(T)}}const Gg={name:"labelEnd",resolveAll:g6,resolveTo:m6,tokenize:p6},d6={tokenize:y6},f6={tokenize:x6},h6={tokenize:b6};function g6(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const s=r.type==="labelImage"?4:2;r.type="data",t+=s}}return e.length!==n.length&&dn(e,0,e.length,n),e}function m6(e,t){let n=e.length,r=0,s,o,u,f;for(;n--;)if(s=e[n][1],o){if(s.type==="link"||s.type==="labelLink"&&s._inactive)break;e[n][0]==="enter"&&s.type==="labelLink"&&(s._inactive=!0)}else if(u){if(e[n][0]==="enter"&&(s.type==="labelImage"||s.type==="labelLink")&&!s._balanced&&(o=n,s.type!=="labelLink")){r=2;break}}else s.type==="labelEnd"&&(u=n);const h={type:e[o][1].type==="labelLink"?"link":"image",start:{...e[o][1].start},end:{...e[e.length-1][1].end}},g={type:"label",start:{...e[o][1].start},end:{...e[u][1].end}},y={type:"labelText",start:{...e[o+r+2][1].end},end:{...e[u-2][1].start}};return f=[["enter",h,t],["enter",g,t]],f=Cn(f,e.slice(o+1,o+r+3)),f=Cn(f,[["enter",y,t]]),f=Cn(f,uu(t.parser.constructs.insideSpan.null,e.slice(o+r+4,u-3),t)),f=Cn(f,[["exit",y,t],e[u-2],e[u-1],["exit",g,t]]),f=Cn(f,e.slice(u+1)),f=Cn(f,[["exit",h,t]]),dn(e,o,e.length,f),e}function p6(e,t,n){const r=this;let s=r.events.length,o,u;for(;s--;)if((r.events[s][1].type==="labelImage"||r.events[s][1].type==="labelLink")&&!r.events[s][1]._balanced){o=r.events[s][1];break}return f;function f(b){return o?o._inactive?p(b):(u=r.parser.defined.includes(Un(r.sliceSerialize({start:o.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(b),e.exit("labelMarker"),e.exit("labelEnd"),h):n(b)}function h(b){return b===40?e.attempt(d6,y,u?y:p)(b):b===91?e.attempt(f6,y,u?g:p)(b):u?y(b):p(b)}function g(b){return e.attempt(h6,y,p)(b)}function y(b){return t(b)}function p(b){return o._balanced=!0,n(b)}}function y6(e,t,n){return r;function r(p){return e.enter("resource"),e.enter("resourceMarker"),e.consume(p),e.exit("resourceMarker"),s}function s(p){return at(p)?dl(e,o)(p):o(p)}function o(p){return p===41?y(p):Tk(e,u,f,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(p)}function u(p){return at(p)?dl(e,h)(p):y(p)}function f(p){return n(p)}function h(p){return p===34||p===39||p===40?Rk(e,g,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(p):y(p)}function g(p){return at(p)?dl(e,y)(p):y(p)}function y(p){return p===41?(e.enter("resourceMarker"),e.consume(p),e.exit("resourceMarker"),e.exit("resource"),t):n(p)}}function x6(e,t,n){const r=this;return s;function s(f){return Dk.call(r,e,o,u,"reference","referenceMarker","referenceString")(f)}function o(f){return r.parser.defined.includes(Un(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(f):n(f)}function u(f){return n(f)}}function b6(e,t,n){return r;function r(o){return e.enter("reference"),e.enter("referenceMarker"),e.consume(o),e.exit("referenceMarker"),s}function s(o){return o===93?(e.enter("referenceMarker"),e.consume(o),e.exit("referenceMarker"),e.exit("reference"),t):n(o)}}const v6={name:"labelStartImage",resolveAll:Gg.resolveAll,tokenize:k6};function k6(e,t,n){const r=this;return s;function s(f){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(f),e.exit("labelImageMarker"),o}function o(f){return f===91?(e.enter("labelMarker"),e.consume(f),e.exit("labelMarker"),e.exit("labelImage"),u):n(f)}function u(f){return f===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(f):t(f)}}const w6={name:"labelStartLink",resolveAll:Gg.resolveAll,tokenize:S6};function S6(e,t,n){const r=this;return s;function s(u){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(u),e.exit("labelMarker"),e.exit("labelLink"),o}function o(u){return u===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(u):t(u)}}const uh={name:"lineEnding",tokenize:j6};function j6(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),$e(e,t,"linePrefix")}}const Ac={name:"thematicBreak",tokenize:C6};function C6(e,t,n){let r=0,s;return o;function o(g){return e.enter("thematicBreak"),u(g)}function u(g){return s=g,f(g)}function f(g){return g===s?(e.enter("thematicBreakSequence"),h(g)):r>=3&&(g===null||be(g))?(e.exit("thematicBreak"),t(g)):n(g)}function h(g){return g===s?(e.consume(g),r++,h):(e.exit("thematicBreakSequence"),Ie(g)?$e(e,f,"whitespace")(g):f(g))}}const Wt={continuation:{tokenize:T6},exit:R6,name:"list",tokenize:E6},N6={partial:!0,tokenize:M6},A6={partial:!0,tokenize:D6};function E6(e,t,n){const r=this,s=r.events[r.events.length-1];let o=s&&s[1].type==="linePrefix"?s[2].sliceSerialize(s[1],!0).length:0,u=0;return f;function f(v){const k=r.containerState.type||(v===42||v===43||v===45?"listUnordered":"listOrdered");if(k==="listUnordered"?!r.containerState.marker||v===r.containerState.marker:ig(v)){if(r.containerState.type||(r.containerState.type=k,e.enter(k,{_container:!0})),k==="listUnordered")return e.enter("listItemPrefix"),v===42||v===45?e.check(Ac,n,g)(v):g(v);if(!r.interrupt||v===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),h(v)}return n(v)}function h(v){return ig(v)&&++u<10?(e.consume(v),h):(!r.interrupt||u<2)&&(r.containerState.marker?v===r.containerState.marker:v===41||v===46)?(e.exit("listItemValue"),g(v)):n(v)}function g(v){return e.enter("listItemMarker"),e.consume(v),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||v,e.check(_l,r.interrupt?n:y,e.attempt(N6,b,p))}function y(v){return r.containerState.initialBlankLine=!0,o++,b(v)}function p(v){return Ie(v)?(e.enter("listItemPrefixWhitespace"),e.consume(v),e.exit("listItemPrefixWhitespace"),b):n(v)}function b(v){return r.containerState.size=o+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(v)}}function T6(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(_l,s,o);function s(f){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,$e(e,t,"listItemIndent",r.containerState.size+1)(f)}function o(f){return r.containerState.furtherBlankLines||!Ie(f)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,u(f)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(A6,t,u)(f))}function u(f){return r.containerState._closeFlow=!0,r.interrupt=void 0,$e(e,e.attempt(Wt,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(f)}}function D6(e,t,n){const r=this;return $e(e,s,"listItemIndent",r.containerState.size+1);function s(o){const u=r.events[r.events.length-1];return u&&u[1].type==="listItemIndent"&&u[2].sliceSerialize(u[1],!0).length===r.containerState.size?t(o):n(o)}}function R6(e){e.exit(this.containerState.type)}function M6(e,t,n){const r=this;return $e(e,s,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function s(o){const u=r.events[r.events.length-1];return!Ie(o)&&u&&u[1].type==="listItemPrefixWhitespace"?t(o):n(o)}}const $b={name:"setextUnderline",resolveTo:O6,tokenize:_6};function O6(e,t){let n=e.length,r,s,o;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(s=n)}else e[n][1].type==="content"&&e.splice(n,1),!o&&e[n][1].type==="definition"&&(o=n);const u={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[s][1].type="setextHeadingText",o?(e.splice(s,0,["enter",u,t]),e.splice(o+1,0,["exit",e[r][1],t]),e[r][1].end={...e[o][1].end}):e[r][1]=u,e.push(["exit",u,t]),e}function _6(e,t,n){const r=this;let s;return o;function o(g){let y=r.events.length,p;for(;y--;)if(r.events[y][1].type!=="lineEnding"&&r.events[y][1].type!=="linePrefix"&&r.events[y][1].type!=="content"){p=r.events[y][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||p)?(e.enter("setextHeadingLine"),s=g,u(g)):n(g)}function u(g){return e.enter("setextHeadingLineSequence"),f(g)}function f(g){return g===s?(e.consume(g),f):(e.exit("setextHeadingLineSequence"),Ie(g)?$e(e,h,"lineSuffix")(g):h(g))}function h(g){return g===null||be(g)?(e.exit("setextHeadingLine"),t(g)):n(g)}}const L6={tokenize:z6};function z6(e){const t=this,n=e.attempt(_l,r,e.attempt(this.parser.constructs.flowInitial,s,$e(e,e.attempt(this.parser.constructs.flow,s,e.attempt($D,s)),"linePrefix")));return n;function r(o){if(o===null){e.consume(o);return}return e.enter("lineEndingBlank"),e.consume(o),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function s(o){if(o===null){e.consume(o);return}return e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const I6={resolveAll:Ok()},H6=Mk("string"),B6=Mk("text");function Mk(e){return{resolveAll:Ok(e==="text"?U6:void 0),tokenize:t};function t(n){const r=this,s=this.parser.constructs[e],o=n.attempt(s,u,f);return u;function u(y){return g(y)?o(y):f(y)}function f(y){if(y===null){n.consume(y);return}return n.enter("data"),n.consume(y),h}function h(y){return g(y)?(n.exit("data"),o(y)):(n.consume(y),h)}function g(y){if(y===null)return!0;const p=s[y];let b=-1;if(p)for(;++b<p.length;){const v=p[b];if(!v.previous||v.previous.call(r,r.previous))return!0}return!1}}}function Ok(e){return t;function t(n,r){let s=-1,o;for(;++s<=n.length;)o===void 0?n[s]&&n[s][1].type==="data"&&(o=s,s++):(!n[s]||n[s][1].type!=="data")&&(s!==o+2&&(n[o][1].end=n[s-1][1].end,n.splice(o+2,s-o-2),s=o+2),o=void 0);return e?e(n,r):n}}function U6(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],s=t.sliceStream(r);let o=s.length,u=-1,f=0,h;for(;o--;){const g=s[o];if(typeof g=="string"){for(u=g.length;g.charCodeAt(u-1)===32;)f++,u--;if(u)break;u=-1}else if(g===-2)h=!0,f++;else if(g!==-1){o++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(f=0),f){const g={type:n===e.length||h||f<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:o?u:r.start._bufferIndex+u,_index:r.start._index+o,line:r.end.line,column:r.end.column-f,offset:r.end.offset-f},end:{...r.end}};r.end={...g.start},r.start.offset===r.end.offset?Object.assign(r,g):(e.splice(n,0,["enter",g,t],["exit",g,t]),n+=2)}n++}return e}const $6={42:Wt,43:Wt,45:Wt,48:Wt,49:Wt,50:Wt,51:Wt,52:Wt,53:Wt,54:Wt,55:Wt,56:Wt,57:Wt,62:Ck},q6={91:GD},K6={[-2]:ch,[-1]:ch,32:ch},P6={35:ZD,42:Ac,45:[$b,Ac],60:n6,61:$b,95:Ac,96:Bb,126:Bb},F6={38:Ak,92:Nk},G6={[-5]:uh,[-4]:uh,[-3]:uh,33:v6,38:Ak,42:sg,60:[wD,c6],91:w6,92:[WD,Nk],93:Gg,95:sg,96:LD},V6={null:[sg,I6]},Y6={null:[42,95]},Q6={null:[]},W6=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:Y6,contentInitial:q6,disable:Q6,document:$6,flow:P6,flowInitial:K6,insideSpan:V6,string:F6,text:G6},Symbol.toStringTag,{value:"Module"}));function X6(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const s={},o=[];let u=[],f=[];const h={attempt:G(z),check:G(L),consume:E,enter:R,exit:H,interrupt:G(L,{interrupt:!0})},g={code:null,containerState:{},defineSkip:j,events:[],now:k,parser:e,previous:null,sliceSerialize:b,sliceStream:v,write:p};let y=t.tokenize.call(g,h);return t.resolveAll&&o.push(t),g;function p($){return u=Cn(u,$),N(),u[u.length-1]!==null?[]:(W(t,0),g.events=uu(o,g.events,g),g.events)}function b($,V){return J6(v($),V)}function v($){return Z6(u,$)}function k(){const{_bufferIndex:$,_index:V,line:ae,column:J,offset:Z}=r;return{_bufferIndex:$,_index:V,line:ae,column:J,offset:Z}}function j($){s[$.line]=$.column,M()}function N(){let $;for(;r._index<u.length;){const V=u[r._index];if(typeof V=="string")for($=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===$&&r._bufferIndex<V.length;)C(V.charCodeAt(r._bufferIndex));else C(V)}}function C($){y=y($)}function E($){be($)?(r.line++,r.column=1,r.offset+=$===-3?2:1,M()):$!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===u[r._index].length&&(r._bufferIndex=-1,r._index++)),g.previous=$}function R($,V){const ae=V||{};return ae.type=$,ae.start=k(),g.events.push(["enter",ae,g]),f.push(ae),ae}function H($){const V=f.pop();return V.end=k(),g.events.push(["exit",V,g]),V}function z($,V){W($,V.from)}function L($,V){V.restore()}function G($,V){return ae;function ae(J,Z,U){let ee,de,ke,T;return Array.isArray(J)?Q(J):"tokenize"in J?Q([J]):O(J);function O(ye){return Re;function Re(rt){const Ge=rt!==null&&ye[rt],Lt=rt!==null&&ye.null,_n=[...Array.isArray(Ge)?Ge:Ge?[Ge]:[],...Array.isArray(Lt)?Lt:Lt?[Lt]:[]];return Q(_n)(rt)}}function Q(ye){return ee=ye,de=0,ye.length===0?U:D(ye[de])}function D(ye){return Re;function Re(rt){return T=P(),ke=ye,ye.partial||(g.currentConstruct=ye),ye.name&&g.parser.constructs.disable.null.includes(ye.name)?me():ye.tokenize.call(V?Object.assign(Object.create(g),V):g,h,ce,me)(rt)}}function ce(ye){return $(ke,T),Z}function me(ye){return T.restore(),++de<ee.length?D(ee[de]):U}}}function W($,V){$.resolveAll&&!o.includes($)&&o.push($),$.resolve&&dn(g.events,V,g.events.length-V,$.resolve(g.events.slice(V),g)),$.resolveTo&&(g.events=$.resolveTo(g.events,g))}function P(){const $=k(),V=g.previous,ae=g.currentConstruct,J=g.events.length,Z=Array.from(f);return{from:J,restore:U};function U(){r=$,g.previous=V,g.currentConstruct=ae,g.events.length=J,f=Z,M()}}function M(){r.line in s&&r.column<2&&(r.column=s[r.line],r.offset+=s[r.line]-1)}}function Z6(e,t){const n=t.start._index,r=t.start._bufferIndex,s=t.end._index,o=t.end._bufferIndex;let u;if(n===s)u=[e[n].slice(r,o)];else{if(u=e.slice(n,s),r>-1){const f=u[0];typeof f=="string"?u[0]=f.slice(r):u.shift()}o>0&&u.push(e[s].slice(0,o))}return u}function J6(e,t){let n=-1;const r=[];let s;for(;++n<e.length;){const o=e[n];let u;if(typeof o=="string")u=o;else switch(o){case-5:{u="\r";break}case-4:{u=`
|
|
433
433
|
`;break}case-3:{u=`\r
|
|
@@ -457,6 +457,6 @@ Mock content for ${n}`,size:128,modifiedAt:new Date().toISOString()}}}async agen
|
|
|
457
457
|
`,...o.current()});return/^[\t ]/.test(g)&&(g=Sl(g.charCodeAt(0))+g.slice(1)),g=g?u+" "+g:u,n.options.closeAtx&&(g+=" "+u),h(),f(),g}Wk.peek=TO;function Wk(e){return e.value||""}function TO(){return"<"}Xk.peek=DO;function Xk(e,t,n,r){const s=Jg(n),o=s==='"'?"Quote":"Apostrophe",u=n.enter("image");let f=n.enter("label");const h=n.createTracker(r);let g=h.move("![");return g+=h.move(n.safe(e.alt,{before:g,after:"]",...h.current()})),g+=h.move("]("),f(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(f=n.enter("destinationLiteral"),g+=h.move("<"),g+=h.move(n.safe(e.url,{before:g,after:">",...h.current()})),g+=h.move(">")):(f=n.enter("destinationRaw"),g+=h.move(n.safe(e.url,{before:g,after:e.title?" ":")",...h.current()}))),f(),e.title&&(f=n.enter(`title${o}`),g+=h.move(" "+s),g+=h.move(n.safe(e.title,{before:g,after:s,...h.current()})),g+=h.move(s),f()),g+=h.move(")"),u(),g}function DO(){return"!"}Zk.peek=RO;function Zk(e,t,n,r){const s=e.referenceType,o=n.enter("imageReference");let u=n.enter("label");const f=n.createTracker(r);let h=f.move("![");const g=n.safe(e.alt,{before:h,after:"]",...f.current()});h+=f.move(g+"]["),u();const y=n.stack;n.stack=[],u=n.enter("reference");const p=n.safe(n.associationId(e),{before:h,after:"]",...f.current()});return u(),n.stack=y,o(),s==="full"||!g||g!==p?h+=f.move(p+"]"):s==="shortcut"?h=h.slice(0,-1):h+=f.move("]"),h}function RO(){return"!"}Jk.peek=MO;function Jk(e,t,n){let r=e.value||"",s="`",o=-1;for(;new RegExp("(^|[^`])"+s+"([^`]|$)").test(r);)s+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++o<n.unsafe.length;){const u=n.unsafe[o],f=n.compilePattern(u);let h;if(u.atBreak)for(;h=f.exec(r);){let g=h.index;r.charCodeAt(g)===10&&r.charCodeAt(g-1)===13&&g--,r=r.slice(0,g)+" "+r.slice(h.index+1)}}return s+r+s}function MO(){return"`"}function ew(e,t){const n=Pg(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(n===e.url||"mailto:"+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}tw.peek=OO;function tw(e,t,n,r){const s=Jg(n),o=s==='"'?"Quote":"Apostrophe",u=n.createTracker(r);let f,h;if(ew(e,n)){const y=n.stack;n.stack=[],f=n.enter("autolink");let p=u.move("<");return p+=u.move(n.containerPhrasing(e,{before:p,after:">",...u.current()})),p+=u.move(">"),f(),n.stack=y,p}f=n.enter("link"),h=n.enter("label");let g=u.move("[");return g+=u.move(n.containerPhrasing(e,{before:g,after:"](",...u.current()})),g+=u.move("]("),h(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(h=n.enter("destinationLiteral"),g+=u.move("<"),g+=u.move(n.safe(e.url,{before:g,after:">",...u.current()})),g+=u.move(">")):(h=n.enter("destinationRaw"),g+=u.move(n.safe(e.url,{before:g,after:e.title?" ":")",...u.current()}))),h(),e.title&&(h=n.enter(`title${o}`),g+=u.move(" "+s),g+=u.move(n.safe(e.title,{before:g,after:s,...u.current()})),g+=u.move(s),h()),g+=u.move(")"),f(),g}function OO(e,t,n){return ew(e,n)?"<":"["}nw.peek=_O;function nw(e,t,n,r){const s=e.referenceType,o=n.enter("linkReference");let u=n.enter("label");const f=n.createTracker(r);let h=f.move("[");const g=n.containerPhrasing(e,{before:h,after:"]",...f.current()});h+=f.move(g+"]["),u();const y=n.stack;n.stack=[],u=n.enter("reference");const p=n.safe(n.associationId(e),{before:h,after:"]",...f.current()});return u(),n.stack=y,o(),s==="full"||!g||g!==p?h+=f.move(p+"]"):s==="shortcut"?h=h.slice(0,-1):h+=f.move("]"),h}function _O(){return"["}function em(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function LO(e){const t=em(e),n=e.options.bulletOther;if(!n)return t==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function zO(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function aw(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function IO(e,t,n,r){const s=n.enter("list"),o=n.bulletCurrent;let u=e.ordered?zO(n):em(n);const f=e.ordered?u==="."?")":".":LO(n);let h=t&&n.bulletLastUsed?u===n.bulletLastUsed:!1;if(!e.ordered){const y=e.children?e.children[0]:void 0;if((u==="*"||u==="-")&&y&&(!y.children||!y.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(h=!0),aw(n)===u&&y){let p=-1;for(;++p<e.children.length;){const b=e.children[p];if(b&&b.type==="listItem"&&b.children&&b.children[0]&&b.children[0].type==="thematicBreak"){h=!0;break}}}}h&&(u=f),n.bulletCurrent=u;const g=n.containerFlow(e,r);return n.bulletLastUsed=u,n.bulletCurrent=o,s(),g}function HO(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function BO(e,t,n,r){const s=HO(n);let o=n.bulletCurrent||em(n);t&&t.type==="list"&&t.ordered&&(o=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+o);let u=o.length+1;(s==="tab"||s==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(u=Math.ceil(u/4)*4);const f=n.createTracker(r);f.move(o+" ".repeat(u-o.length)),f.shift(u);const h=n.enter("listItem"),g=n.indentLines(n.containerFlow(e,f.current()),y);return h(),g;function y(p,b,v){return b?(v?"":" ".repeat(u))+p:(v?o:o+" ".repeat(u-o.length))+p}}function UO(e,t,n,r){const s=n.enter("paragraph"),o=n.enter("phrasing"),u=n.containerPhrasing(e,r);return o(),s(),u}const $O=fu(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function qO(e,t,n,r){return(e.children.some(function(u){return $O(u)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function KO(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}rw.peek=PO;function rw(e,t,n,r){const s=KO(n),o=n.enter("strong"),u=n.createTracker(r),f=u.move(s+s);let h=u.move(n.containerPhrasing(e,{after:s,before:f,...u.current()}));const g=h.charCodeAt(0),y=Gc(r.before.charCodeAt(r.before.length-1),g,s);y.inside&&(h=Sl(g)+h.slice(1));const p=h.charCodeAt(h.length-1),b=Gc(r.after.charCodeAt(0),p,s);b.inside&&(h=h.slice(0,-1)+Sl(p));const v=u.move(s+s);return o(),n.attentionEncodeSurroundingInfo={after:b.outside,before:y.outside},f+h+v}function PO(e,t,n){return n.options.strong||"*"}function FO(e,t,n,r){return n.safe(e.value,r)}function GO(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function VO(e,t,n){const r=(aw(n)+(n.options.ruleSpaces?" ":"")).repeat(GO(n));return n.options.ruleSpaces?r.slice(0,-1):r}const iw={blockquote:pO,break:ov,code:wO,definition:jO,emphasis:Qk,hardBreak:ov,heading:EO,html:Wk,image:Xk,imageReference:Zk,inlineCode:Jk,link:tw,linkReference:nw,list:IO,listItem:BO,paragraph:UO,root:qO,strong:rw,text:FO,thematicBreak:VO};function YO(){return{enter:{table:QO,tableData:cv,tableHeader:cv,tableRow:XO},exit:{codeText:ZO,table:WO,tableData:wh,tableHeader:wh,tableRow:wh}}}function QO(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function WO(e){this.exit(e),this.data.inTable=void 0}function XO(e){this.enter({type:"tableRow",children:[]},e)}function wh(e){this.exit(e)}function cv(e){this.enter({type:"tableCell",children:[]},e)}function ZO(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,JO));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function JO(e,t){return t==="|"?t:e}function e_(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,s=t.stringLength,o=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
|
|
458
458
|
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:b,table:u,tableCell:h,tableRow:f}};function u(v,k,j,N){return g(y(v,j,N),v.align)}function f(v,k,j,N){const C=p(v,j,N),E=g([C]);return E.slice(0,E.indexOf(`
|
|
459
459
|
`))}function h(v,k,j,N){const C=j.enter("tableCell"),E=j.enter("phrasing"),R=j.containerPhrasing(v,{...N,before:o,after:o});return E(),C(),R}function g(v,k){return gO(v,{align:k,alignDelimiters:r,padding:n,stringLength:s})}function y(v,k,j){const N=v.children;let C=-1;const E=[],R=k.enter("table");for(;++C<N.length;)E[C]=p(N[C],k,j);return R(),E}function p(v,k,j){const N=v.children;let C=-1;const E=[],R=k.enter("tableRow");for(;++C<N.length;)E[C]=h(N[C],v,k,j);return R(),E}function b(v,k,j){let N=iw.inlineCode(v,k,j);return j.stack.includes("tableCell")&&(N=N.replace(/\|/g,"\\$&")),N}}function t_(){return{exit:{taskListCheckValueChecked:uv,taskListCheckValueUnchecked:uv,paragraph:a_}}}function n_(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:r_}}}function uv(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function a_(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const s=t.children;let o=-1,u;for(;++o<s.length;){const f=s[o];if(f.type==="paragraph"){u=f;break}}u===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function r_(e,t,n,r){const s=e.children[0],o=typeof e.checked=="boolean"&&s&&s.type==="paragraph",u="["+(e.checked?"x":" ")+"] ",f=n.createTracker(r);o&&f.move(u);let h=iw.listItem(e,t,n,{...r,...f.current()});return o&&(h=h.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,g)),h;function g(y){return y+u}}function i_(){return[IM(),rO(),oO(),YO(),t_()]}function s_(e){return{extensions:[HM(),iO(e),cO(),e_(e),n_()]}}const l_={tokenize:h_,partial:!0},sw={tokenize:g_,partial:!0},lw={tokenize:m_,partial:!0},ow={tokenize:p_,partial:!0},o_={tokenize:y_,partial:!0},cw={name:"wwwAutolink",tokenize:d_,previous:dw},uw={name:"protocolAutolink",tokenize:f_,previous:fw},Sa={name:"emailAutolink",tokenize:u_,previous:hw},Jn={};function c_(){return{text:Jn}}let Cr=48;for(;Cr<123;)Jn[Cr]=Sa,Cr++,Cr===58?Cr=65:Cr===91&&(Cr=97);Jn[43]=Sa;Jn[45]=Sa;Jn[46]=Sa;Jn[95]=Sa;Jn[72]=[Sa,uw];Jn[104]=[Sa,uw];Jn[87]=[Sa,cw];Jn[119]=[Sa,cw];function u_(e,t,n){const r=this;let s,o;return u;function u(p){return!dg(p)||!hw.call(r,r.previous)||tm(r.events)?n(p):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),f(p))}function f(p){return dg(p)?(e.consume(p),f):p===64?(e.consume(p),h):n(p)}function h(p){return p===46?e.check(o_,y,g)(p):p===45||p===95||Ot(p)?(o=!0,e.consume(p),h):y(p)}function g(p){return e.consume(p),s=!0,h}function y(p){return o&&s&&Ut(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(p)):n(p)}}function d_(e,t,n){const r=this;return s;function s(u){return u!==87&&u!==119||!dw.call(r,r.previous)||tm(r.events)?n(u):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(l_,e.attempt(sw,e.attempt(lw,o),n),n)(u))}function o(u){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(u)}}function f_(e,t,n){const r=this;let s="",o=!1;return u;function u(p){return(p===72||p===104)&&fw.call(r,r.previous)&&!tm(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),s+=String.fromCodePoint(p),e.consume(p),f):n(p)}function f(p){if(Ut(p)&&s.length<5)return s+=String.fromCodePoint(p),e.consume(p),f;if(p===58){const b=s.toLowerCase();if(b==="http"||b==="https")return e.consume(p),h}return n(p)}function h(p){return p===47?(e.consume(p),o?g:(o=!0,h)):n(p)}function g(p){return p===null||Kc(p)||at(p)||_r(p)||cu(p)?n(p):e.attempt(sw,e.attempt(lw,y),n)(p)}function y(p){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(p)}}function h_(e,t,n){let r=0;return s;function s(u){return(u===87||u===119)&&r<3?(r++,e.consume(u),s):u===46&&r===3?(e.consume(u),o):n(u)}function o(u){return u===null?n(u):t(u)}}function g_(e,t,n){let r,s,o;return u;function u(g){return g===46||g===95?e.check(ow,h,f)(g):g===null||at(g)||_r(g)||g!==45&&cu(g)?h(g):(o=!0,e.consume(g),u)}function f(g){return g===95?r=!0:(s=r,r=void 0),e.consume(g),u}function h(g){return s||r||!o?n(g):t(g)}}function m_(e,t){let n=0,r=0;return s;function s(u){return u===40?(n++,e.consume(u),s):u===41&&r<n?o(u):u===33||u===34||u===38||u===39||u===41||u===42||u===44||u===46||u===58||u===59||u===60||u===63||u===93||u===95||u===126?e.check(ow,t,o)(u):u===null||at(u)||_r(u)?t(u):(e.consume(u),s)}function o(u){return u===41&&r++,e.consume(u),s}}function p_(e,t,n){return r;function r(f){return f===33||f===34||f===39||f===41||f===42||f===44||f===46||f===58||f===59||f===63||f===95||f===126?(e.consume(f),r):f===38?(e.consume(f),o):f===93?(e.consume(f),s):f===60||f===null||at(f)||_r(f)?t(f):n(f)}function s(f){return f===null||f===40||f===91||at(f)||_r(f)?t(f):r(f)}function o(f){return Ut(f)?u(f):n(f)}function u(f){return f===59?(e.consume(f),r):Ut(f)?(e.consume(f),u):n(f)}}function y_(e,t,n){return r;function r(o){return e.consume(o),s}function s(o){return Ot(o)?n(o):t(o)}}function dw(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||at(e)}function fw(e){return!Ut(e)}function hw(e){return!(e===47||dg(e))}function dg(e){return e===43||e===45||e===46||e===95||Ot(e)}function tm(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const x_={tokenize:N_,partial:!0};function b_(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:S_,continuation:{tokenize:j_},exit:C_}},text:{91:{name:"gfmFootnoteCall",tokenize:w_},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:v_,resolveTo:k_}}}}function v_(e,t,n){const r=this;let s=r.events.length;const o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let u;for(;s--;){const h=r.events[s][1];if(h.type==="labelImage"){u=h;break}if(h.type==="gfmFootnoteCall"||h.type==="labelLink"||h.type==="label"||h.type==="image"||h.type==="link")break}return f;function f(h){if(!u||!u._balanced)return n(h);const g=Un(r.sliceSerialize({start:u.end,end:r.now()}));return g.codePointAt(0)!==94||!o.includes(g.slice(1))?n(h):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(h),e.exit("gfmFootnoteCallLabelMarker"),t(h))}}function k_(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},s={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};s.end.column++,s.end.offset++,s.end._bufferIndex++;const o={type:"gfmFootnoteCallString",start:Object.assign({},s.end),end:Object.assign({},e[e.length-1][1].start)},u={type:"chunkString",contentType:"string",start:Object.assign({},o.start),end:Object.assign({},o.end)},f=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",s,t],["exit",s,t],["enter",o,t],["enter",u,t],["exit",u,t],["exit",o,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...f),e}function w_(e,t,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o=0,u;return f;function f(p){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),h}function h(p){return p!==94?n(p):(e.enter("gfmFootnoteCallMarker"),e.consume(p),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",g)}function g(p){if(o>999||p===93&&!u||p===null||p===91||at(p))return n(p);if(p===93){e.exit("chunkString");const b=e.exit("gfmFootnoteCallString");return s.includes(Un(r.sliceSerialize(b)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(p)}return at(p)||(u=!0),o++,e.consume(p),p===92?y:g}function y(p){return p===91||p===92||p===93?(e.consume(p),o++,g):g(p)}}function S_(e,t,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o,u=0,f;return h;function h(k){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(k),e.exit("gfmFootnoteDefinitionLabelMarker"),g}function g(k){return k===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(k),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",y):n(k)}function y(k){if(u>999||k===93&&!f||k===null||k===91||at(k))return n(k);if(k===93){e.exit("chunkString");const j=e.exit("gfmFootnoteDefinitionLabelString");return o=Un(r.sliceSerialize(j)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(k),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),b}return at(k)||(f=!0),u++,e.consume(k),k===92?p:y}function p(k){return k===91||k===92||k===93?(e.consume(k),u++,y):y(k)}function b(k){return k===58?(e.enter("definitionMarker"),e.consume(k),e.exit("definitionMarker"),s.includes(o)||s.push(o),$e(e,v,"gfmFootnoteDefinitionWhitespace")):n(k)}function v(k){return t(k)}}function j_(e,t,n){return e.check(_l,t,e.attempt(x_,t,n))}function C_(e){e.exit("gfmFootnoteDefinition")}function N_(e,t,n){const r=this;return $e(e,s,"gfmFootnoteDefinitionIndent",5);function s(o){const u=r.events[r.events.length-1];return u&&u[1].type==="gfmFootnoteDefinitionIndent"&&u[2].sliceSerialize(u[1],!0).length===4?t(o):n(o)}}function A_(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:o,resolveAll:s};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function s(u,f){let h=-1;for(;++h<u.length;)if(u[h][0]==="enter"&&u[h][1].type==="strikethroughSequenceTemporary"&&u[h][1]._close){let g=h;for(;g--;)if(u[g][0]==="exit"&&u[g][1].type==="strikethroughSequenceTemporary"&&u[g][1]._open&&u[h][1].end.offset-u[h][1].start.offset===u[g][1].end.offset-u[g][1].start.offset){u[h][1].type="strikethroughSequence",u[g][1].type="strikethroughSequence";const y={type:"strikethrough",start:Object.assign({},u[g][1].start),end:Object.assign({},u[h][1].end)},p={type:"strikethroughText",start:Object.assign({},u[g][1].end),end:Object.assign({},u[h][1].start)},b=[["enter",y,f],["enter",u[g][1],f],["exit",u[g][1],f],["enter",p,f]],v=f.parser.constructs.insideSpan.null;v&&dn(b,b.length,0,uu(v,u.slice(g+1,h),f)),dn(b,b.length,0,[["exit",p,f],["enter",u[h][1],f],["exit",u[h][1],f],["exit",y,f]]),dn(u,g-1,h-g+3,b),h=g+b.length-2;break}}for(h=-1;++h<u.length;)u[h][1].type==="strikethroughSequenceTemporary"&&(u[h][1].type="data");return u}function o(u,f,h){const g=this.previous,y=this.events;let p=0;return b;function b(k){return g===126&&y[y.length-1][1].type!=="characterEscape"?h(k):(u.enter("strikethroughSequenceTemporary"),v(k))}function v(k){const j=Ii(g);if(k===126)return p>1?h(k):(u.consume(k),p++,v);if(p<2&&!n)return h(k);const N=u.exit("strikethroughSequenceTemporary"),C=Ii(k);return N._open=!C||C===2&&!!j,N._close=!j||j===2&&!!C,f(k)}}}class E_{constructor(){this.map=[]}add(t,n,r){T_(this,t,n,r)}consume(t){if(this.map.sort(function(o,u){return o[0]-u[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let s=r.pop();for(;s;){for(const o of s)t.push(o);s=r.pop()}this.map.length=0}}function T_(e,t,n,r){let s=0;if(!(n===0&&r.length===0)){for(;s<e.map.length;){if(e.map[s][0]===t){e.map[s][1]+=n,e.map[s][2].push(...r);return}s+=1}e.map.push([t,n,r])}}function D_(e,t){let n=!1;const r=[];for(;t<e.length;){const s=e[t];if(n){if(s[0]==="enter")s[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(s[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const o=r.length-1;r[o]=r[o]==="left"?"center":"right"}}else if(s[1].type==="tableDelimiterRow")break}else s[0]==="enter"&&s[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function R_(){return{flow:{null:{name:"table",tokenize:M_,resolveAll:O_}}}}function M_(e,t,n){const r=this;let s=0,o=0,u;return f;function f(M){let $=r.events.length-1;for(;$>-1;){const J=r.events[$][1].type;if(J==="lineEnding"||J==="linePrefix")$--;else break}const V=$>-1?r.events[$][1].type:null,ae=V==="tableHead"||V==="tableRow"?L:h;return ae===L&&r.parser.lazy[r.now().line]?n(M):ae(M)}function h(M){return e.enter("tableHead"),e.enter("tableRow"),g(M)}function g(M){return M===124||(u=!0,o+=1),y(M)}function y(M){return M===null?n(M):be(M)?o>1?(o=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(M),e.exit("lineEnding"),v):n(M):Ie(M)?$e(e,y,"whitespace")(M):(o+=1,u&&(u=!1,s+=1),M===124?(e.enter("tableCellDivider"),e.consume(M),e.exit("tableCellDivider"),u=!0,y):(e.enter("data"),p(M)))}function p(M){return M===null||M===124||at(M)?(e.exit("data"),y(M)):(e.consume(M),M===92?b:p)}function b(M){return M===92||M===124?(e.consume(M),p):p(M)}function v(M){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(M):(e.enter("tableDelimiterRow"),u=!1,Ie(M)?$e(e,k,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(M):k(M))}function k(M){return M===45||M===58?N(M):M===124?(u=!0,e.enter("tableCellDivider"),e.consume(M),e.exit("tableCellDivider"),j):z(M)}function j(M){return Ie(M)?$e(e,N,"whitespace")(M):N(M)}function N(M){return M===58?(o+=1,u=!0,e.enter("tableDelimiterMarker"),e.consume(M),e.exit("tableDelimiterMarker"),C):M===45?(o+=1,C(M)):M===null||be(M)?H(M):z(M)}function C(M){return M===45?(e.enter("tableDelimiterFiller"),E(M)):z(M)}function E(M){return M===45?(e.consume(M),E):M===58?(u=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(M),e.exit("tableDelimiterMarker"),R):(e.exit("tableDelimiterFiller"),R(M))}function R(M){return Ie(M)?$e(e,H,"whitespace")(M):H(M)}function H(M){return M===124?k(M):M===null||be(M)?!u||s!==o?z(M):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(M)):z(M)}function z(M){return n(M)}function L(M){return e.enter("tableRow"),G(M)}function G(M){return M===124?(e.enter("tableCellDivider"),e.consume(M),e.exit("tableCellDivider"),G):M===null||be(M)?(e.exit("tableRow"),t(M)):Ie(M)?$e(e,G,"whitespace")(M):(e.enter("data"),W(M))}function W(M){return M===null||M===124||at(M)?(e.exit("data"),G(M)):(e.consume(M),M===92?P:W)}function P(M){return M===92||M===124?(e.consume(M),W):W(M)}}function O_(e,t){let n=-1,r=!0,s=0,o=[0,0,0,0],u=[0,0,0,0],f=!1,h=0,g,y,p;const b=new E_;for(;++n<e.length;){const v=e[n],k=v[1];v[0]==="enter"?k.type==="tableHead"?(f=!1,h!==0&&(dv(b,t,h,g,y),y=void 0,h=0),g={type:"table",start:Object.assign({},k.start),end:Object.assign({},k.end)},b.add(n,0,[["enter",g,t]])):k.type==="tableRow"||k.type==="tableDelimiterRow"?(r=!0,p=void 0,o=[0,0,0,0],u=[0,n+1,0,0],f&&(f=!1,y={type:"tableBody",start:Object.assign({},k.start),end:Object.assign({},k.end)},b.add(n,0,[["enter",y,t]])),s=k.type==="tableDelimiterRow"?2:y?3:1):s&&(k.type==="data"||k.type==="tableDelimiterMarker"||k.type==="tableDelimiterFiller")?(r=!1,u[2]===0&&(o[1]!==0&&(u[0]=u[1],p=cc(b,t,o,s,void 0,p),o=[0,0,0,0]),u[2]=n)):k.type==="tableCellDivider"&&(r?r=!1:(o[1]!==0&&(u[0]=u[1],p=cc(b,t,o,s,void 0,p)),o=u,u=[o[1],n,0,0])):k.type==="tableHead"?(f=!0,h=n):k.type==="tableRow"||k.type==="tableDelimiterRow"?(h=n,o[1]!==0?(u[0]=u[1],p=cc(b,t,o,s,n,p)):u[1]!==0&&(p=cc(b,t,u,s,n,p)),s=0):s&&(k.type==="data"||k.type==="tableDelimiterMarker"||k.type==="tableDelimiterFiller")&&(u[3]=n)}for(h!==0&&dv(b,t,h,g,y),b.consume(t.events),n=-1;++n<t.events.length;){const v=t.events[n];v[0]==="enter"&&v[1].type==="table"&&(v[1]._align=D_(t.events,n))}return e}function cc(e,t,n,r,s,o){const u=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",f="tableContent";n[0]!==0&&(o.end=Object.assign({},_i(t.events,n[0])),e.add(n[0],0,[["exit",o,t]]));const h=_i(t.events,n[1]);if(o={type:u,start:Object.assign({},h),end:Object.assign({},h)},e.add(n[1],0,[["enter",o,t]]),n[2]!==0){const g=_i(t.events,n[2]),y=_i(t.events,n[3]),p={type:f,start:Object.assign({},g),end:Object.assign({},y)};if(e.add(n[2],0,[["enter",p,t]]),r!==2){const b=t.events[n[2]],v=t.events[n[3]];if(b[1].end=Object.assign({},v[1].end),b[1].type="chunkText",b[1].contentType="text",n[3]>n[2]+1){const k=n[2]+1,j=n[3]-n[2]-1;e.add(k,j,[])}}e.add(n[3]+1,0,[["exit",p,t]])}return s!==void 0&&(o.end=Object.assign({},_i(t.events,s)),e.add(s,0,[["exit",o,t]]),o=void 0),o}function dv(e,t,n,r,s){const o=[],u=_i(t.events,n);s&&(s.end=Object.assign({},u),o.push(["exit",s,t])),r.end=Object.assign({},u),o.push(["exit",r,t]),e.add(n+1,0,o)}function _i(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const __={name:"tasklistCheck",tokenize:z_};function L_(){return{text:{91:__}}}function z_(e,t,n){const r=this;return s;function s(h){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(h):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(h),e.exit("taskListCheckMarker"),o)}function o(h){return at(h)?(e.enter("taskListCheckValueUnchecked"),e.consume(h),e.exit("taskListCheckValueUnchecked"),u):h===88||h===120?(e.enter("taskListCheckValueChecked"),e.consume(h),e.exit("taskListCheckValueChecked"),u):n(h)}function u(h){return h===93?(e.enter("taskListCheckMarker"),e.consume(h),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),f):n(h)}function f(h){return be(h)?t(h):Ie(h)?e.check({tokenize:I_},t,n)(h):n(h)}}function I_(e,t,n){return $e(e,r,"whitespace");function r(s){return s===null?n(s):t(s)}}function H_(e){return Sk([c_(),b_(),A_(e),R_(),L_()])}const B_={};function U_(e){const t=this,n=e||B_,r=t.data(),s=r.micromarkExtensions||(r.micromarkExtensions=[]),o=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),u=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);s.push(H_(n)),o.push(i_()),u.push(s_(n))}const gw=S.memo(function({content:t}){return c.jsx("div",{className:"prose prose-sm max-w-none break-words dark:prose-invert prose-p:my-1 prose-pre:my-2 prose-ul:my-1 prose-ol:my-1 prose-li:my-0",children:c.jsx(Pk,{remarkPlugins:[U_],components:{pre:({children:n,...r})=>c.jsx("pre",{className:"overflow-x-auto rounded bg-gray-100 p-2 text-xs dark:bg-gray-800",...r,children:n}),code:({children:n,className:r,...s})=>r?c.jsx("code",{className:r,...s,children:n}):c.jsx("code",{className:"rounded bg-gray-100 px-1 py-0.5 text-xs dark:bg-gray-800",...s,children:n}),a:({children:n,...r})=>c.jsx("a",{className:"text-blue-600 underline dark:text-blue-400",target:"_blank",rel:"noopener noreferrer",...r,children:n})},children:t})})});function mw(){return c.jsx("span",{className:"ml-0.5 inline-block h-4 w-1.5 animate-pulse rounded-sm bg-blue-500 align-middle"})}const $_=S.memo(function({message:t}){const n=t.role==="user";return c.jsx("div",{className:`flex ${n?"justify-end":"justify-start"} mb-3`,children:c.jsx("div",{className:`max-w-[80%] rounded-lg px-3 py-2 text-sm ${n?"bg-blue-600 text-white":"bg-gray-100 text-gray-900 dark:bg-gray-800 dark:text-gray-100"}`,children:n?c.jsx("p",{className:"whitespace-pre-wrap",children:t.content}):c.jsxs(c.Fragment,{children:[c.jsx(gw,{content:t.content}),t.isStreaming&&c.jsx(mw,{})]})})})});function fv(e){const t=e.split(":");if(t.length>=3&&t[0]==="agent"){const n=t.slice(2).join(":");return n==="main"?t[1]:n.length>20?n.slice(0,20)+"…":n}return e.length>15?e.slice(0,15)+"…":e}function q_(e){const t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n}m`;const r=Math.floor(n/60);return r<24?`${r}h`:`${Math.floor(r/24)}d`}function K_(){const{t:e}=se("chat"),t=Qe(E=>E.sessions),n=Qe(E=>E.currentSessionKey),r=Qe(E=>E.switchSession),s=Qe(E=>E.newSession),o=Qe(E=>E.setTargetAgent),u=Qe(E=>E.loadSessions),f=Qe(E=>E.dockExpanded),h=ie(E=>E.agents),g=Array.from(h.values()).filter(E=>!E.isSubAgent&&!E.isPlaceholder&&E.confirmed),[y,p]=S.useState(!1),b=S.useRef(null);S.useEffect(()=>{f&&u()},[f,u]),S.useEffect(()=>{if(!y)return;const E=R=>{b.current&&!b.current.contains(R.target)&&p(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[y]);const v=S.useCallback(E=>{r(E),p(!1)},[r]),k=S.useCallback(E=>{o(E),setTimeout(()=>{s(),p(!1)},0)},[o,s]),j=S.useCallback(()=>{s()},[s]),N=fv(n),C=[...t??[]].sort((E,R)=>R.lastActiveAt-E.lastActiveAt);return c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsxs("div",{ref:b,className:"relative",children:[c.jsxs("button",{type:"button",onClick:()=>p(!y),className:"flex items-center gap-1.5 rounded-md px-2 py-1 text-xs text-gray-600 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-800",children:[c.jsx(b4,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"max-w-[140px] truncate",children:N}),c.jsx(qn,{className:`h-3 w-3 transition-transform ${y?"rotate-180":""}`})]}),y&&c.jsxs("div",{className:"absolute left-0 top-full z-60 mt-1 w-72 rounded-lg border border-gray-200 bg-white py-1 shadow-lg dark:border-gray-700 dark:bg-gray-900",children:[C.length>0?C.map(E=>c.jsxs("button",{type:"button",onClick:()=>v(E.key),className:`flex w-full items-center gap-2 px-3 py-2 text-left text-xs hover:bg-gray-50 dark:hover:bg-gray-800 ${E.key===n?"bg-blue-50 text-blue-700 dark:bg-blue-900/20 dark:text-blue-400":"text-gray-700 dark:text-gray-300"}`,children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"truncate font-medium",children:fv(E.key)}),c.jsxs("div",{className:"truncate text-[10px] text-gray-400",children:[q_(E.lastActiveAt),E.messageCount>0&&` · ${E.messageCount} msgs`]})]}),E.key===n&&c.jsx("div",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full bg-blue-500"})]},E.key)):c.jsx("div",{className:"px-3 py-2 text-xs text-gray-400",children:e("sessionSwitcher.noSessions")}),c.jsxs("div",{className:"border-t border-gray-100 dark:border-gray-800",children:[c.jsx("div",{className:"px-3 py-1.5 text-[10px] font-medium uppercase tracking-wider text-gray-400",children:e("sessionSwitcher.newSession")}),g.map(E=>c.jsxs("button",{type:"button",onClick:()=>k(E.id),className:"flex w-full items-center gap-2 px-3 py-1.5 text-xs text-gray-600 hover:bg-gray-50 dark:text-gray-400 dark:hover:bg-gray-800",children:[c.jsx(En,{className:"h-3.5 w-3.5 text-green-500"}),c.jsx("span",{className:"truncate",children:e("sessionSwitcher.newSessionWith",{agent:E.name})})]},`new-${E.id}`)),g.length===0&&c.jsxs("button",{type:"button",onClick:()=>{s(),p(!1)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-xs text-gray-600 hover:bg-gray-50 dark:text-gray-400 dark:hover:bg-gray-800",children:[c.jsx(En,{className:"h-3.5 w-3.5 text-green-500"}),c.jsx("span",{children:e("sessionSwitcher.newSession")})]})]})]})]}),c.jsx("button",{type:"button",onClick:j,className:"flex h-6 w-6 items-center justify-center rounded-md text-gray-400 hover:bg-gray-100 hover:text-green-600 dark:hover:bg-gray-800 dark:hover:text-green-400",title:e("sessionSwitcher.newSessionTooltip"),children:c.jsx(En,{className:"h-4 w-4"})})]})}const pw=220,P_=.7,F_=420,fg="openclaw-chat-dialog-height";function G_(){try{const e=localStorage.getItem(fg);if(e){const t=parseInt(e,10);if(!Number.isNaN(t)&&t>=pw)return t}}catch{}return F_}function V_(e){if(!e)return"";const t=e.content;return typeof t=="string"?t:Array.isArray(t)?t.filter(n=>n.type==="text"&&n.text).map(n=>n.text).join(`
|
|
460
|
-
`):""}function Y_(){const{t:e}=se("chat"),t=Qe(T=>T.dockExpanded),n=Qe(T=>T.messages),r=Qe(T=>T.isStreaming),s=Qe(T=>T.streamingMessage),o=Qe(T=>T.isHistoryLoading),u=Qe(T=>T.setDockExpanded),f=Qe(T=>T.sendMessage),h=Qe(T=>T.abort),g=Qe(T=>T.error),y=Qe(T=>T.clearError),p=S.useRef(null),b=S.useRef(null),[v,k]=S.useState(!0),[j,N]=S.useState(G_),[C,E]=S.useState(!1),[R,H]=S.useState(!1),[z,L]=S.useState(""),[G,W]=S.useState(!1),P=S.useRef(0),M=S.useRef(0),$=S.useRef(!1),V=V_(s),ae=z.trim().length>0&&!r;S.useEffect(()=>{if(t&&!$.current){H(!0);const T=setTimeout(()=>H(!1),200);return $.current=!0,()=>clearTimeout(T)}if(!t&&$.current){H(!0);const T=setTimeout(()=>{H(!1),$.current=!1},150);return()=>clearTimeout(T)}},[t]),S.useEffect(()=>{if(t&&b.current){const T=setTimeout(()=>{var O;return(O=b.current)==null?void 0:O.focus()},220);return()=>clearTimeout(T)}},[t]),S.useEffect(()=>{v&&p.current&&(p.current.scrollTop=p.current.scrollHeight)},[n,V,v]);const J=S.useCallback(()=>{if(!p.current)return;const{scrollTop:T,scrollHeight:O,clientHeight:Q}=p.current,D=O-T-Q<40;k(D)},[]),Z=S.useCallback(()=>{p.current&&(p.current.scrollTop=p.current.scrollHeight,k(!0))},[]);S.useEffect(()=>{if(!t)return;const T=O=>{O.key==="Escape"&&u(!1)};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[t,u]);const U=S.useCallback(T=>{T.preventDefault(),E(!0),P.current=T.clientY,M.current=j},[j]);S.useEffect(()=>{if(!C)return;const T=Q=>{const D=P.current-Q.clientY,ce=window.innerHeight*P_,me=Math.max(pw,Math.min(ce,M.current+D));N(me)},O=()=>{E(!1);try{localStorage.setItem(fg,String(j))}catch{}};return document.addEventListener("mousemove",T),document.addEventListener("mouseup",O),()=>{document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",O)}},[C,j]),S.useEffect(()=>{if(!C)try{localStorage.setItem(fg,String(j))}catch{}},[j,C]);const ee=S.useCallback(()=>{const T=z.trim();!T||r||(f(T),L(""))},[z,r,f]),de=S.useCallback(T=>{T.key==="Enter"&&!T.shiftKey&&!G&&(T.preventDefault(),ee()),T.key==="Escape"&&u(!1)},[ee,G,u]);if(!t&&!R)return null;const ke=[...n];return c.jsxs("div",{className:`absolute inset-x-0 bottom-0 z-30 mx-auto flex w-full max-w-2xl flex-col overflow-hidden rounded-t-xl border border-b-0 border-gray-200 bg-white shadow-2xl dark:border-gray-700 dark:bg-gray-900 ${t?"animate-slide-up":"animate-slide-down"}`,style:{height:`${j}px`,transition:C?"none":void 0},children:[c.jsx("div",{className:"flex h-3 shrink-0 cursor-ns-resize items-center justify-center hover:bg-gray-100 dark:hover:bg-gray-800",onMouseDown:U,children:c.jsx("div",{className:"h-0.5 w-8 rounded-full bg-gray-300 dark:bg-gray-600"})}),c.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-gray-100 px-3 py-1 dark:border-gray-800",children:[c.jsx(K_,{}),c.jsx("button",{type:"button",onClick:()=>u(!1),className:"flex h-7 w-7 items-center justify-center rounded-md text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:e("dock.collapseDock"),children:c.jsx(k4,{className:"h-4 w-4"})})]}),o&&c.jsxs("div",{className:"flex shrink-0 items-center justify-center gap-2 py-3 text-sm text-gray-400",children:[c.jsx(Mt,{className:"h-4 w-4 animate-spin"}),c.jsx("span",{children:e("chatDialog.loadingHistory")})]}),c.jsxs("div",{ref:p,onScroll:J,className:"relative min-h-0 flex-1 overflow-y-auto px-4 py-2",children:[ke.length===0&&!r&&!o?c.jsx("div",{className:"flex h-full items-center justify-center text-sm text-gray-400",children:e("dock.startNewChat")}):c.jsxs(c.Fragment,{children:[ke.map(T=>c.jsx($_,{message:T},T.id)),r&&V&&c.jsx("div",{className:"mb-3 flex justify-start",children:c.jsxs("div",{className:"max-w-[80%] rounded-lg bg-gray-100 px-3 py-2 text-sm text-gray-900 dark:bg-gray-800 dark:text-gray-100",children:[c.jsx(gw,{content:V}),c.jsx(mw,{})]})}),r&&!V&&c.jsx("div",{className:"mb-3 flex justify-start",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-gray-100 px-3 py-2 text-sm text-gray-400 dark:bg-gray-800",children:[c.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-blue-500 border-t-transparent"}),c.jsx("span",{children:e("dock.thinkingStatus")})]})})]}),!v&&c.jsx("button",{type:"button",onClick:Z,title:e("chatDialog.scrollToBottom"),className:"sticky bottom-2 left-full z-10 -mr-2 flex h-8 w-8 items-center justify-center rounded-full border border-gray-200 bg-white shadow-md hover:bg-gray-50 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700",children:c.jsx(zA,{className:"h-4 w-4 text-gray-500"})})]}),g&&c.jsxs("div",{className:"flex shrink-0 items-center justify-between bg-red-50 px-3 py-1.5 text-xs text-red-600 dark:bg-red-900/20 dark:text-red-400",children:[c.jsx("span",{className:"truncate",children:g}),c.jsx("button",{type:"button",onClick:y,className:"ml-2 text-red-500 hover:text-red-700",children:"✕"})]}),c.jsx("div",{className:"shrink-0 border-t border-gray-200 bg-white px-3 py-2 dark:border-gray-700 dark:bg-gray-900",children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx(ok,{}),c.jsx("button",{type:"button",className:"rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:e("dock.attachmentWip"),children:c.jsx(R1,{className:"h-4 w-4"})}),c.jsx(H1,{ref:b,value:z,onChange:T=>L(T.target.value),onKeyDown:de,onCompositionStart:()=>W(!0),onCompositionEnd:()=>W(!1),placeholder:e("dock.placeholder"),maxRows:4,className:"flex-1 resize-none rounded-lg border border-gray-200 bg-gray-50 px-3 py-1.5 text-sm outline-none transition-colors placeholder:text-gray-400 focus:border-blue-400 focus:bg-white dark:border-gray-700 dark:bg-gray-800 dark:placeholder:text-gray-500 dark:focus:border-blue-500 dark:focus:bg-gray-900"}),r?c.jsx("button",{type:"button",onClick:()=>h(),className:"rounded-lg bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:e("common:actions.stop"),children:c.jsx(Ng,{className:"h-4 w-4"})}):c.jsx("button",{type:"button",onClick:ee,disabled:!ae,className:`rounded-lg p-1.5 transition-colors ${ae?"bg-blue-600 text-white hover:bg-blue-700":"bg-gray-200 text-gray-400 dark:bg-gray-700"}`,title:e("common:actions.send"),children:c.jsx(_1,{className:"h-4 w-4"})})]})})]})}function Q_(){const{t:e}=se("chat"),[t,n]=S.useState(""),[r,s]=S.useState(!1),o=S.useRef(null),u=Qe(N=>N.sendMessage),f=Qe(N=>N.abort),h=Qe(N=>N.isStreaming),g=Qe(N=>N.dockExpanded),y=Qe(N=>N.setDockExpanded),p=Qe(N=>N.error),b=Qe(N=>N.clearError),v=t.trim().length>0&&!h,k=S.useCallback(()=>{const N=t.trim();!N||h||(u(N),n(""))},[t,h,u]),j=S.useCallback(N=>{N.key==="Enter"&&!N.shiftKey&&!r&&(N.preventDefault(),k())},[k,r]);return g?null:c.jsxs("div",{className:"border-t border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900",children:[p&&c.jsxs("div",{className:"flex items-center justify-between bg-red-50 px-3 py-1.5 text-xs text-red-600 dark:bg-red-900/20 dark:text-red-400",children:[c.jsx("span",{className:"truncate",children:p}),c.jsx("button",{type:"button",onClick:b,className:"ml-2 text-red-500 hover:text-red-700",children:"✕"})]}),c.jsxs("div",{className:"flex items-end gap-2 px-3 py-2",children:[c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx(ok,{}),c.jsx("button",{type:"button",onClick:()=>y(!0),className:"rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:e("dock.expandDock"),children:c.jsx(y4,{className:"h-4 w-4"})})]}),c.jsx("button",{type:"button",className:"rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:e("dock.attachmentWip"),onClick:()=>{},children:c.jsx(R1,{className:"h-4 w-4"})}),c.jsx(H1,{ref:o,value:t,onChange:N=>n(N.target.value),onKeyDown:j,onFocus:()=>y(!0),onCompositionStart:()=>s(!0),onCompositionEnd:()=>s(!1),placeholder:e("dock.placeholder"),maxRows:4,className:"flex-1 resize-none rounded-lg border border-gray-200 bg-gray-50 px-3 py-1.5 text-sm outline-none transition-colors placeholder:text-gray-400 focus:border-blue-400 focus:bg-white dark:border-gray-700 dark:bg-gray-800 dark:placeholder:text-gray-500 dark:focus:border-blue-500 dark:focus:bg-gray-900"}),h?c.jsx("button",{type:"button",onClick:()=>f(),className:"rounded-lg bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:e("common:actions.stop"),children:c.jsx(Ng,{className:"h-4 w-4"})}):c.jsx("button",{type:"button",onClick:k,disabled:!v,className:`rounded-lg p-1.5 transition-colors ${v?"bg-blue-600 text-white hover:bg-blue-700":"bg-gray-200 text-gray-400 dark:bg-gray-700"}`,title:e("common:actions.send"),children:c.jsx(_1,{className:"h-4 w-4"})})]})]})}const Ee=Mn((e,t)=>({config:null,hash:null,configPath:null,configRaw:null,configValid:!0,loading:!1,error:null,schemaHints:null,status:null,statusLoading:!1,statusError:null,updateResult:null,updateLoading:!1,catalogModels:[],catalogLoading:!1,restartState:null,lifecycleState:null,setRestartPending:n=>e({restartState:{status:"pending",startedAt:Date.now(),estimatedDelayMs:n}}),setRestartReconnecting:()=>e(n=>n.restartState?{restartState:{...n.restartState,status:"reconnecting"}}:{}),setRestartComplete:()=>e(n=>n.restartState?{restartState:{...n.restartState,status:"complete"}}:{}),clearRestart:()=>e({restartState:null}),setLifecycleState:n=>e({lifecycleState:n}),setLifecycleFromWriteResult:(n,r,s)=>{var u;const o=Date.now();if((u=n.restart)!=null&&u.scheduled){e({lifecycleState:{status:r==="apply"?"apply-restarting":"saved-restart-required",source:r,startedAt:o,estimatedDelayMs:n.restart.delayMs},restartState:r==="apply"?{status:"pending",startedAt:o,estimatedDelayMs:n.restart.delayMs}:null});return}e({lifecycleState:s?{status:"saved-cli-restart-required",source:"cli",startedAt:o,command:s}:{status:"saved-hot-reload",source:r,startedAt:o},restartState:null})},setRuntimeApplied:n=>e({lifecycleState:{status:"effective-now",source:"runtime",startedAt:Date.now(),messageKey:n},restartState:null}),setLifecycleDisconnected:()=>e(n=>n.lifecycleState?{lifecycleState:{...n.lifecycleState,status:"disconnected"},restartState:n.restartState?{...n.restartState,status:"disconnected"}:n.restartState}:{}),setLifecycleReconnecting:()=>e(n=>n.lifecycleState?{lifecycleState:{...n.lifecycleState,status:"reconnecting"},restartState:n.restartState?{...n.restartState,status:"reconnecting"}:n.restartState}:{}),setLifecycleComplete:()=>e(n=>n.lifecycleState?{lifecycleState:{...n.lifecycleState,status:"complete"},restartState:n.restartState?{...n.restartState,status:"complete"}:n.restartState}:{}),clearLifecycle:()=>e({lifecycleState:null,restartState:null}),fetchConfig:async()=>{e({loading:!0,error:null});try{const r=await(await Pe()).configGet();e({config:r.config,hash:r.hash??null,configPath:r.path??null,configRaw:r.raw??null,configValid:r.valid,loading:!1})}catch(n){e({loading:!1,error:String(n)})}},saveConfig:async(n,r)=>{const s=t().config,o=t().hash??void 0;if(!s)return{ok:!1,config:{},error:"config not loaded"};try{const u=await Pe(),f=n(structuredClone(s)),h=await u.configSet(JSON.stringify(f),o);if(h.ok)e({config:h.config,error:null}),t().setLifecycleFromWriteResult(h,"save",r==null?void 0:r.fallbackCommand),await t().fetchConfig();else{const g=h.error??"config set failed";e({error:g}),g.includes("config changed")&&await t().fetchConfig()}return h}catch(u){const f=String(u);return e({error:f}),{ok:!1,config:s,error:f}}},applyConfig:async(n,r)=>{const s=t().config,o=t().hash??void 0;if(!s)return{ok:!1,config:{},error:"config not loaded"};try{const u=await Pe(),f=n(structuredClone(s)),h=await u.configApply(JSON.stringify(f),o,r);if(h.ok)e({config:h.config,error:null}),t().setLifecycleFromWriteResult(h,"apply"),await t().fetchConfig();else{const g=h.error??"config apply failed";e({error:g}),g.includes("config changed")&&await t().fetchConfig()}return h}catch(u){const f=String(u);return e({error:f}),{ok:!1,config:s,error:f}}},patchConfig:async n=>{var s;const{hash:r}=t();try{const o=await Pe(),u=JSON.stringify(n),f=await o.configPatch(u,r??void 0);if(f.ok)e({config:f.config,error:null}),(s=f.restart)!=null&&s.scheduled&&t().setRestartPending(f.restart.delayMs),await t().fetchConfig();else{const h=f.error??"config patch failed";e({error:h}),h.includes("config changed")&&await t().fetchConfig()}return f}catch(o){const u=String(o);return e({error:u}),{ok:!1,config:t().config??{},error:u}}},fetchSchema:async()=>{try{const r=await(await Pe()).configSchema();e({schemaHints:r})}catch{}},fetchStatus:async()=>{e({statusLoading:!0,statusError:null});try{const r=await(await Pe()).statusSummary();e({status:r,statusLoading:!1})}catch(n){e({statusLoading:!1,statusError:String(n)})}},fetchCatalogModels:async()=>{e({catalogLoading:!0});try{const r=await(await Pe()).modelsList();e({catalogModels:r,catalogLoading:!1})}catch{e({catalogLoading:!1})}},runUpdate:async n=>{e({updateLoading:!0,updateResult:null});try{const s=await(await Pe()).updateRun(n);return e({updateResult:s,updateLoading:!1}),s}catch(r){const s={ok:!1,result:{status:"error",mode:"unknown",reason:String(r),steps:[],durationMs:0},restart:null};return e({updateResult:s,updateLoading:!1}),s}}})),W_=2500;function yw(){const{t:e}=se("console"),t=Ee(j=>j.lifecycleState),n=Ee(j=>j.clearLifecycle),r=Ee(j=>j.setLifecycleDisconnected),s=Ee(j=>j.setLifecycleReconnecting),o=Ee(j=>j.setLifecycleComplete),u=ie(j=>j.connectionStatus),[f,h]=S.useState(null),[g,y]=S.useState(!1);S.useEffect(()=>{if(!(t!=null&&t.estimatedDelayMs)){h(null);return}const j=()=>{const C=Math.max(0,t.estimatedDelayMs-(Date.now()-t.startedAt));h(Math.ceil(C/1e3))};j();const N=setInterval(j,1e3);return()=>clearInterval(N)},[t]),S.useEffect(()=>{if(t){if(t.status==="apply-restarting"){u==="disconnected"||u==="error"?r():u==="connecting"||u==="reconnecting"?s():u==="connected"&&o();return}(t.status==="disconnected"||t.status==="reconnecting")&&(u==="connected"?o():(u==="connecting"||u==="reconnecting")&&t.status!=="reconnecting"?s():(u==="disconnected"||u==="error")&&t.status!=="disconnected"&&r())}},[u,t,o,r,s]),S.useEffect(()=>{if(t&&(t.status==="complete"||t.status==="effective-now"||t.status==="saved-hot-reload")){const j=setTimeout(()=>n(),W_);return()=>clearTimeout(j)}},[n,t]);const p=S.useMemo(()=>{if(!t)return null;const j=t.messageKey??X_(t.status),N=t.status==="apply-restarting"?e(j,{seconds:f??0}):e(j);switch(t.status){case"effective-now":case"saved-hot-reload":case"complete":return{icon:qi,className:"border-green-200 bg-green-50 text-green-800 dark:border-green-800 dark:bg-green-900/20 dark:text-green-300",message:N,animate:""};case"saved-restart-required":case"saved-cli-restart-required":return{icon:Rn,className:"border-amber-200 bg-amber-50 text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300",message:N,animate:""};case"apply-restarting":case"disconnected":case"reconnecting":return{icon:Mt,className:"border-blue-200 bg-blue-50 text-blue-800 dark:border-blue-800 dark:bg-blue-900/20 dark:text-blue-300",message:N,animate:"animate-spin"};default:return null}},[f,t,e]);if(!t||!p)return null;const b=p.icon,v=!!t.command,k=async()=>{!t.command||!navigator.clipboard||(await navigator.clipboard.writeText(t.command),y(!0),setTimeout(()=>y(!1),1500))};return c.jsx("div",{className:`border-b px-4 py-3 text-sm ${p.className}`,children:c.jsxs("div",{className:"mx-auto flex max-w-7xl items-start gap-3",children:[c.jsx(b,{className:`mt-0.5 h-4 w-4 shrink-0 ${p.animate}`}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("p",{className:"font-medium",children:p.message}),v&&c.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[c.jsxs("div",{className:"inline-flex items-center gap-2 rounded-md border border-current/20 bg-black/5 px-3 py-1.5 font-mono text-xs dark:bg-white/5",children:[c.jsx(z1,{className:"h-3.5 w-3.5"}),t.command]}),c.jsxs("button",{type:"button",onClick:()=>void k(),className:"inline-flex items-center gap-1 rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5",children:[c.jsx(jg,{className:"h-3.5 w-3.5"}),e(g?"configLifecycle.copiedCommand":"configLifecycle.copyCommand")]})]})]})]})})}function X_(e){switch(e){case"effective-now":return"configLifecycle.effectiveNow";case"saved-hot-reload":return"configLifecycle.savedHotReload";case"saved-restart-required":return"configLifecycle.savedRestartRequired";case"saved-cli-restart-required":return"configLifecycle.savedCliRestartRequired";case"apply-restarting":return"configLifecycle.applyRestarting";case"disconnected":return"configLifecycle.disconnected";case"reconnecting":return"configLifecycle.reconnecting";case"complete":return"configLifecycle.complete"}}const Z_=5,gu=Mn(e=>({toasts:[],addToast:t=>{const n=`toast-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,r={id:n,type:t.type,title:t.title,message:t.message,detail:t.detail,duration:t.duration??5e3,createdAt:Date.now()};return e(s=>{const o=[...s.toasts,r];return o.length>Z_&&o.shift(),{toasts:o}}),n},removeToast:t=>e(n=>({toasts:n.toasts.filter(r=>r.id!==t)})),clearAll:()=>e({toasts:[]})}));function hv(e,t){return gu.getState().addToast({type:"success",title:e,message:t})}function uc(e,t,n){return gu.getState().addToast({type:"error",title:e,message:t,detail:n,duration:0})}const J_={success:qi,error:Sg,warning:Pi,info:ru},eL={success:{border:"border-green-300 dark:border-green-700",icon:"text-green-500",bg:"bg-green-50 dark:bg-green-900/20"},error:{border:"border-red-300 dark:border-red-700",icon:"text-red-500",bg:"bg-red-50 dark:bg-red-900/20"},warning:{border:"border-yellow-300 dark:border-yellow-700",icon:"text-yellow-500",bg:"bg-yellow-50 dark:bg-yellow-900/20"},info:{border:"border-blue-300 dark:border-blue-700",icon:"text-blue-500",bg:"bg-blue-50 dark:bg-blue-900/20"}};function tL({toast:e}){const{t}=se("console"),n=gu(b=>b.removeToast),[r,s]=S.useState(!1),[o,u]=S.useState(!1),f=S.useRef(null),h=S.useCallback(()=>{f.current&&(clearTimeout(f.current),f.current=null)},[]),g=S.useCallback(()=>{h(),e.duration>0&&!r&&(f.current=setTimeout(()=>n(e.id),e.duration))},[e.duration,e.id,r,n,h]);S.useEffect(()=>(o?h():g(),h),[o,g,h]);const y=J_[e.type],p=eL[e.type];return c.jsx("div",{onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),className:`pointer-events-auto w-80 rounded-xl border ${p.border} ${p.bg} p-3 shadow-lg backdrop-blur-sm animate-in slide-in-from-right-5 fade-in duration-200`,children:c.jsxs("div",{className:"flex items-start gap-2.5",children:[c.jsx(y,{className:`mt-0.5 h-4 w-4 shrink-0 ${p.icon}`}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:e.title}),e.message&&c.jsx("p",{className:"mt-0.5 text-xs text-gray-600 dark:text-gray-400",children:e.message}),e.detail&&c.jsxs(c.Fragment,{children:[c.jsxs("button",{type:"button",onClick:()=>s(!r),className:"mt-1 flex items-center gap-1 text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",children:[r?c.jsx(wg,{className:"h-3 w-3"}):c.jsx(qn,{className:"h-3 w-3"}),t(r?"toast.hideDetail":"toast.showDetail")]}),r&&c.jsx("pre",{className:"mt-1.5 max-h-[200px] overflow-auto rounded-lg bg-gray-900 p-2 text-xs text-gray-200 dark:bg-gray-800",children:e.detail})]})]}),c.jsx("button",{type:"button",onClick:()=>n(e.id),className:"shrink-0 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:c.jsx(An,{className:"h-3.5 w-3.5"})})]})})}function nL(){const e=gu(t=>t.toasts);return e.length===0?null:c.jsx("div",{className:"pointer-events-none fixed right-4 top-4 z-50 flex flex-col gap-2",children:e.map(t=>c.jsx(tL,{toast:t},t.id))})}const Hi=["#ef4444","#f97316","#f59e0b","#84cc16","#22c55e","#14b8a6","#06b6d4","#3b82f6","#6366f1","#8b5cf6","#a855f7","#ec4899"];function nm(e){let t=0;for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);t=(t<<5)-t+r|0}return Math.abs(t)}function aL(e){const t=parseInt(e.slice(1,3),16)/255,n=parseInt(e.slice(3,5),16)/255,r=parseInt(e.slice(5,7),16)/255;return .299*t+.587*n+.114*r}function rL(e,t){const n=nm(e),r=Hi[n%Hi.length],s=aL(r)>.5?"#000000":"#ffffff",u=(t??e).charAt(0).toUpperCase()||"?";return{backgroundColor:r,textColor:s,initial:u}}function jI(e){const t=nm(e);return Hi[t%Hi.length]}const gv=["round","square","oval"],mv=["short","spiky","side-part","curly","buzz"],pv=["dot","line","wide"],yv=["#fde2c8","#f5c5a0","#d4956b","#a0714f","#6b4226","#ffe0bd"],xv=["#2c1b0e","#5a3214","#c2884a","#e8c068"];function xw(e){const t=nm(e),n=(r,s)=>(t>>>r)%s;return{faceShape:gv[n(0,gv.length)],hairStyle:mv[n(3,mv.length)],eyeStyle:pv[n(6,pv.length)],skinColor:yv[n(8,yv.length)],hairColor:xv[n(11,xv.length)],shirtColor:Hi[t%Hi.length]}}function iL({shape:e,color:t}){switch(e){case"round":return c.jsx("circle",{cx:"24",cy:"20",r:"12",fill:t});case"square":return c.jsx("rect",{x:"12",y:"8",width:"24",height:"24",rx:"4",fill:t});case"oval":return c.jsx("ellipse",{cx:"24",cy:"20",rx:"11",ry:"14",fill:t})}}function sL({style:e,color:t}){switch(e){case"short":return c.jsx("path",{d:"M12 16 Q12 6 24 6 Q36 6 36 16 L36 12 Q36 4 24 4 Q12 4 12 12 Z",fill:t});case"spiky":return c.jsx("path",{d:"M14 14 L16 4 L20 12 L24 2 L28 12 L32 4 L34 14 Q34 6 24 6 Q14 6 14 14 Z",fill:t});case"side-part":return c.jsx("path",{d:"M12 16 Q12 5 24 5 Q36 5 36 16 L36 11 Q36 3 24 3 Q14 3 10 10 Z",fill:t});case"curly":return c.jsx("path",{d:"M12 18 Q10 8 16 5 Q20 2 24 4 Q28 2 32 5 Q38 8 36 18 L36 12 Q36 4 24 4 Q12 4 12 12 Z",fill:t});case"buzz":return c.jsx("path",{d:"M13 15 Q13 6 24 6 Q35 6 35 15 L35 13 Q35 5 24 5 Q13 5 13 13 Z",fill:t})}}function lL({style:e}){switch(e){case"dot":return c.jsxs(c.Fragment,{children:[c.jsx("circle",{cx:"19",cy:"19",r:"1.5",fill:"#333"}),c.jsx("circle",{cx:"29",cy:"19",r:"1.5",fill:"#333"})]});case"line":return c.jsxs(c.Fragment,{children:[c.jsx("line",{x1:"17",y1:"19",x2:"21",y2:"19",stroke:"#333",strokeWidth:"1.5",strokeLinecap:"round"}),c.jsx("line",{x1:"27",y1:"19",x2:"31",y2:"19",stroke:"#333",strokeWidth:"1.5",strokeLinecap:"round"})]});case"wide":return c.jsxs(c.Fragment,{children:[c.jsx("ellipse",{cx:"19",cy:"19",rx:"2.5",ry:"2",fill:"white"}),c.jsx("circle",{cx:"19",cy:"19",r:"1.2",fill:"#333"}),c.jsx("ellipse",{cx:"29",cy:"19",rx:"2.5",ry:"2",fill:"white"}),c.jsx("circle",{cx:"29",cy:"19",r:"1.2",fill:"#333"})]})}}function bw({agentId:e,size:t=40,className:n}){const r=xw(e);return c.jsxs("svg",{viewBox:"0 0 48 48",width:t,height:t,className:n,style:{borderRadius:"50%",overflow:"hidden"},children:[c.jsx("rect",{width:"48",height:"48",fill:r.shirtColor,rx:"24"}),c.jsx("path",{d:"M8 42 Q8 34 24 34 Q40 34 40 42 L40 48 L8 48 Z",fill:r.shirtColor}),c.jsx(iL,{shape:r.faceShape,color:r.skinColor}),c.jsx(sL,{style:r.hairStyle,color:r.hairColor}),c.jsx(lL,{style:r.eyeStyle}),c.jsx("path",{d:"M21 24 Q24 26 27 24",stroke:"#333",strokeWidth:"0.8",fill:"none",strokeLinecap:"round"})]})}function oL(){const{t:e}=se("panels"),t=ie(o=>o.selectedAgentId),n=ie(o=>o.agents),r=ie(o=>o.selectAgent);if(!t)return null;const s=n.get(t);return s?c.jsxs("div",{className:"px-3 py-2",children:[c.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[c.jsx(bw,{agentId:s.id,size:32}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"truncate text-sm font-medium text-gray-800 dark:text-gray-200",children:s.name}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:Ml[s.status]}}),c.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:e(`common:agent.statusLabels.${s.status}`)})]})]}),c.jsx("button",{onClick:()=>r(null),className:"shrink-0 text-xs text-gray-400 hover:text-gray-600 dark:hover:text-gray-200",title:e("agentDetail.deselect"),children:"✕"})]}),s.currentTool&&c.jsx("div",{className:"mb-2 rounded bg-orange-50 px-2 py-1.5 text-xs dark:bg-orange-950/50",children:c.jsxs("div",{className:"text-orange-600 dark:text-orange-400",children:["🔧 ",s.currentTool.name]})}),s.speechBubble&&c.jsx("div",{className:"mb-2 rounded bg-white px-2 py-1.5 text-xs leading-relaxed text-gray-700 shadow-sm dark:bg-gray-800 dark:text-gray-300",children:c.jsx(Pk,{children:s.speechBubble.text})}),s.toolCallHistory.length>0&&c.jsxs("div",{className:"mt-2",children:[c.jsx("div",{className:"mb-1 text-xs font-medium text-gray-400 dark:text-gray-500",children:e("agentDetail.toolCallHistory")}),s.toolCallHistory.map((o,u)=>c.jsxs("div",{className:"flex items-center justify-between border-b border-gray-100 py-1 text-xs text-gray-500 dark:border-gray-700 dark:text-gray-400",children:[c.jsx("span",{children:o.name}),c.jsx("span",{className:"text-gray-400",children:new Date(o.timestamp).toLocaleTimeString()})]},`${o.name}-${o.timestamp}-${u}`))]})]}):null}const cL={lifecycle:"●",tool:"🔧",assistant:"💬",error:"⚠"},uL={lifecycle:"生命周期",tool:"工具调用",assistant:"对话输出",error:"异常"};function dL(){const{t:e}=se("panels"),t=ie(b=>b.eventHistory),n=ie(b=>b.selectAgent),r=S.useRef(null),[s,o]=S.useState(!0),u=S.useRef(0),[f,h]=S.useState(null),g=t.slice(-50);S.useEffect(()=>{s&&r.current&&t.length>u.current&&(r.current.scrollTop=r.current.scrollHeight),u.current=t.length},[t.length,s]);const y=S.useCallback(()=>{if(!r.current)return;const{scrollTop:b,scrollHeight:v,clientHeight:k}=r.current,j=v-b-k<30;o(j)},[]),p=S.useCallback((b,v)=>{f===b?h(null):(h(b),n(v))},[f,n]);return c.jsxs("div",{ref:r,onScroll:y,className:"flex-1 overflow-y-auto",children:[!s&&t.length>0&&c.jsx("div",{className:"sticky top-0 z-10 flex justify-end bg-white/80 px-2 py-0.5 backdrop-blur-sm dark:bg-gray-900/80",children:c.jsx("button",{onClick:()=>{o(!0),r.current&&(r.current.scrollTop=r.current.scrollHeight)},className:"rounded bg-blue-600 px-1.5 py-0.5 text-[10px] text-white",children:e("eventTimeline.newEvents")})}),g.map((b,v)=>{const k=f===v;return c.jsxs("div",{children:[c.jsxs("button",{onClick:()=>p(v,b.agentId),className:`flex w-full items-start gap-1.5 border-b border-gray-100 px-3 py-1.5 text-left text-xs transition-colors hover:bg-gray-50 dark:border-gray-800 dark:hover:bg-gray-800 ${k?"bg-blue-50/50 dark:bg-blue-950/30":""}`,children:[c.jsx("span",{className:"mt-0.5 shrink-0 text-gray-400",children:new Date(b.timestamp).toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}),c.jsx("span",{className:"shrink-0",children:cL[b.stream]??"·"}),c.jsx("span",{className:"shrink-0 font-medium",style:{color:Ml[b.stream==="error"?"error":"thinking"]},children:b.agentName}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-gray-500 dark:text-gray-400",children:b.summary}),c.jsx("span",{className:"shrink-0 text-[10px] text-gray-300 dark:text-gray-600",children:k?"▼":"▶"})]}),k&&c.jsx("div",{className:"border-b border-gray-100 bg-gray-50/50 px-3 py-2 dark:border-gray-800 dark:bg-gray-800/50",children:c.jsxs("div",{className:"space-y-1 text-[11px]",children:[c.jsx(Sh,{label:"类型",value:uL[b.stream]??b.stream}),c.jsx(Sh,{label:"Agent",value:`${b.agentName} (${b.agentId})`}),c.jsx(Sh,{label:"时间",value:new Date(b.timestamp).toLocaleString("zh-CN",{hour12:!1})}),c.jsxs("div",{className:"pt-1",children:[c.jsx("div",{className:"text-gray-400 dark:text-gray-500",children:"详情"}),c.jsx("div",{className:"mt-0.5 whitespace-pre-wrap break-all rounded bg-white/60 p-1.5 text-gray-700 dark:bg-gray-900/60 dark:text-gray-300",children:b.summary||"—"})]})]})})]},`${b.timestamp}-${b.agentId}-${v}`)}),g.length===0&&c.jsx("div",{className:"py-3 text-center text-xs text-gray-400 dark:text-gray-500",children:e("common:empty.noEvents")})]})}function Sh({label:e,value:t}){return c.jsxs("div",{className:"flex gap-2",children:[c.jsx("span",{className:"w-10 shrink-0 text-gray-400 dark:text-gray-500",children:e}),c.jsx("span",{className:"min-w-0 break-all text-gray-600 dark:text-gray-300",children:t})]})}const fL=S.lazy(()=>El(()=>import("./TokenLineChart-CfPgD-hP.js"),__vite__mapDeps([0,1])).then(e=>({default:e.TokenLineChart}))),hL=S.lazy(()=>El(()=>import("./CostPieChart-BIcqqhp7.js"),__vite__mapDeps([2,1])).then(e=>({default:e.CostPieChart}))),gL=S.lazy(()=>El(()=>import("./NetworkGraph-B-nEMJ_M.js"),[]).then(e=>({default:e.NetworkGraph}))),mL=S.lazy(()=>El(()=>import("./ActivityHeatmap-CvGomuJN.js"),[]).then(e=>({default:e.ActivityHeatmap})));function dc(){return c.jsx("div",{className:"flex min-h-[140px] items-center justify-center",children:c.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-blue-500 border-t-transparent"})})}function pL(){const{t:e}=se("panels"),[t,n]=S.useState("overview"),r=ie(u=>u.globalMetrics),s=[{id:"overview",label:e("metrics.tabs.overview")},{id:"trend",label:e("metrics.tabs.trend")},{id:"topology",label:e("metrics.tabs.topology")},{id:"activity",label:e("metrics.tabs.activity")}],o=[{label:e("metrics.activeAgents"),value:`${r.activeAgents}/${r.totalAgents}`,color:"#3b82f6"},{label:e("metrics.totalTokens"),value:yL(r.totalTokens),color:"#22c55e"},{label:e("metrics.collaboration"),value:`${Math.round(r.collaborationHeat)}%`,color:"#f97316"},{label:e("metrics.tokenRate"),value:`${r.tokenRate.toFixed(0)}${e("metrics.tokenRateUnit")}`,color:"#a855f7"}];return c.jsxs("div",{className:"flex flex-col",children:[c.jsx("div",{className:"grid grid-cols-4 gap-1 p-2",children:o.map(u=>c.jsxs("div",{className:"rounded-lg bg-gray-50 px-1 py-1 text-center dark:bg-gray-800",children:[c.jsx("div",{className:"text-xs font-bold leading-tight",style:{color:u.color},children:u.value}),c.jsx("div",{className:"text-[8px] text-gray-500 dark:text-gray-400",children:u.label})]},u.label))}),c.jsx("div",{className:"flex gap-1 border-t border-gray-100 px-2 py-1 dark:border-gray-800",children:s.map(u=>c.jsx("button",{type:"button",onClick:()=>n(u.id),className:`rounded px-2 py-0.5 text-[10px] ${t===u.id?"bg-gray-200 font-medium dark:bg-gray-700 dark:text-gray-200":"text-gray-600 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-800"}`,children:u.label},u.id))}),c.jsxs("div",{className:"p-2",children:[t==="overview"&&c.jsx(S.Suspense,{fallback:c.jsx(dc,{}),children:c.jsx(hL,{})}),t==="trend"&&c.jsx(S.Suspense,{fallback:c.jsx(dc,{}),children:c.jsx(fL,{})}),t==="topology"&&c.jsx(S.Suspense,{fallback:c.jsx(dc,{}),children:c.jsx(gL,{})}),t==="activity"&&c.jsx(S.Suspense,{fallback:c.jsx(dc,{}),children:c.jsx(mL,{})})]})]})}function yL(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function xL({agentId:e,agentName:t,size:n=32}){const{backgroundColor:r,textColor:s,initial:o}=rL(e,t);return c.jsx("div",{className:"flex shrink-0 items-center justify-center rounded-full font-bold",style:{width:n,height:n,backgroundColor:r,color:s,fontSize:n*.45},children:o})}function bL(){const{t:e}=se(),t=ie(s=>s.agents),n=ie(s=>s.selectAgent),r=Array.from(t.values()).filter(s=>s.isSubAgent);return r.length===0?c.jsx("div",{className:"py-2 text-center text-xs text-gray-400 dark:text-gray-500",children:e("empty.noSubAgents")}):c.jsx("div",{children:r.map(s=>{const o=s.parentAgentId?t.get(s.parentAgentId):null,u=vL(s.lastActiveAt,e);return c.jsxs("button",{onClick:()=>n(s.id),className:"flex w-full items-start gap-2 border-b border-gray-50 px-3 py-2 text-left transition-colors hover:bg-blue-50 dark:border-gray-800 dark:hover:bg-blue-950",children:[c.jsx(xL,{agentId:s.id,agentName:s.name,size:24}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsx("span",{className:"truncate text-xs font-medium text-gray-800 dark:text-gray-200",children:s.name}),c.jsx("span",{className:"inline-flex items-center rounded px-1 py-0.5 text-[9px] font-medium text-white",style:{backgroundColor:Ml[s.status]},children:e(`agent.statusLabels.${s.status}`)})]}),o&&c.jsxs("span",{role:"link",tabIndex:0,onClick:f=>{f.stopPropagation(),n(o.id)},onKeyDown:f=>{f.key==="Enter"&&(f.stopPropagation(),n(o.id))},className:"cursor-pointer text-[10px] text-blue-500 hover:underline",children:["← ",o.name]}),s.speechBubble&&c.jsx("div",{className:"mt-0.5 truncate text-[10px] text-gray-400",children:s.speechBubble.text.slice(0,80)}),c.jsx("div",{className:"text-[10px] text-gray-400",children:u})]})]},s.id)})})}function vL(e,t){const n=Math.max(0,Math.floor((Date.now()-e)/1e3));if(n<60)return t("time.running",{seconds:n});const r=Math.floor(n/60),s=n%60;return t("time.runningMinutes",{minutes:r,seconds:s})}function Ws({title:e,collapsed:t,onToggle:n,height:r,onHeightChange:s,minHeight:o=60,maxHeight:u=600,headerExtra:f,children:h,flex:g=!1,badge:y}){const p=S.useRef(null),b=S.useRef(null),v=t?0:r??o,k=S.useCallback(j=>{var R;if(t)return;j.preventDefault();const N=((R=p.current)==null?void 0:R.offsetHeight)??v;b.current={startY:j.clientY,startHeight:N};const C=H=>{if(!b.current)return;const z=H.clientY-b.current.startY,L=Math.max(o,Math.min(u,b.current.startHeight+z));s(L)},E=()=>{b.current=null,document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",E),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="ns-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",C),document.addEventListener("mouseup",E)},[t,v,o,u,s]);return S.useEffect(()=>()=>{document.body.style.cursor="",document.body.style.userSelect=""},[]),c.jsxs("div",{className:`flex flex-col ${g&&!t?"min-h-0 flex-1":""}`,style:!t&&!g?{flexShrink:0}:void 0,children:[c.jsxs("button",{type:"button",onClick:n,className:"flex h-6 w-full items-center gap-1 border-b border-gray-200 bg-gray-50 px-2 text-[11px] font-semibold uppercase tracking-wide text-gray-600 hover:bg-gray-100 dark:border-gray-700 dark:bg-gray-800/70 dark:text-gray-400 dark:hover:bg-gray-800",children:[c.jsx("span",{className:"inline-block text-[9px] transition-transform duration-150",style:{transform:t?"rotate(-90deg)":"rotate(0deg)"},children:"▼"}),c.jsx("span",{className:"select-none",children:e}),y!==void 0&&c.jsx("span",{className:"ml-1 rounded-sm bg-gray-200 px-1 text-[10px] font-normal text-gray-500 dark:bg-gray-700 dark:text-gray-400",children:y}),f&&c.jsx("span",{className:"ml-auto flex items-center",onClick:j=>j.stopPropagation(),children:f})]}),!t&&c.jsx("div",{ref:p,className:`overflow-y-auto overflow-x-hidden ${g?"min-h-0 flex-1":""}`,style:g?{minHeight:o}:{height:v},children:h}),!t&&c.jsx("div",{onMouseDown:k,className:"group relative z-10 h-1 shrink-0 cursor-ns-resize",children:c.jsx("div",{className:"absolute inset-x-0 -top-0.5 bottom-0 transition-colors group-hover:bg-blue-500/30 group-active:bg-blue-500/50"})})]})}const vw="openclaw-sidebar-layout",bv={metrics:{collapsed:!0,height:null},agents:{collapsed:!1,height:null},subAgents:{collapsed:!1,height:null},detail:{collapsed:!1,height:null},timeline:{collapsed:!1,height:null}};function kL(){try{const e=localStorage.getItem(vw);if(e){const t=JSON.parse(e);return{...bv,...t}}}catch{}return{...bv}}function wL(e){try{localStorage.setItem(vw,JSON.stringify(e))}catch{}}function SL(){const[e,t]=S.useState(kL),n=S.useRef(e);n.current=e,S.useEffect(()=>{wL(e)},[e]);const r=S.useCallback(u=>{t(f=>{var h;return{...f,[u]:{...f[u],collapsed:!((h=f[u])!=null&&h.collapsed)}}})},[]),s=S.useCallback((u,f)=>{t(h=>({...h,[u]:{...h[u],height:f}}))},[]),o=S.useCallback(u=>e[u]??{collapsed:!1,height:null},[e]);return{layout:e,toggleSection:r,setSectionHeight:s,getSection:o}}function vv(){const{t:e}=se("layout"),t=ie(z=>z.agents),n=ie(z=>z.selectedAgentId),r=ie(z=>z.selectAgent),s=ie(z=>z.sidebarCollapsed),o=ie(z=>z.setSidebarCollapsed),{getSection:u,toggleSection:f,setSectionHeight:h}=SL(),[g,y]=S.useState(""),[p,b]=S.useState("all"),v=S.useMemo(()=>{let z=Array.from(t.values()).filter(L=>!L.isPlaceholder);if(g){const L=g.toLowerCase();z=z.filter(G=>G.name.toLowerCase().includes(L))}return p==="active"?z=z.filter(L=>L.status!=="idle"&&L.status!=="offline"):p==="idle"?z=z.filter(L=>L.status==="idle"):p==="error"&&(z=z.filter(L=>L.status==="error")),z},[t,g,p]),k=S.useMemo(()=>Array.from(t.values()).filter(z=>z.isSubAgent&&!z.isPlaceholder),[t]),j=[{key:"all",label:e("sidebar.filters.all")},{key:"active",label:e("sidebar.filters.active")},{key:"idle",label:e("sidebar.filters.idle")},{key:"error",label:e("sidebar.filters.error")}];if(s)return c.jsx("aside",{className:"flex w-12 flex-col items-center border-l border-gray-200 bg-white py-3 dark:border-gray-700 dark:bg-gray-900",children:c.jsx("button",{onClick:()=>o(!1),className:"text-gray-400 hover:text-gray-700 dark:hover:text-gray-200",title:e("sidebar.expand"),children:"◀"})});const N=u("metrics"),C=u("agents"),E=u("subAgents"),R=u("detail"),H=u("timeline");return c.jsxs("aside",{className:"flex w-80 flex-col border-l border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900",children:[c.jsxs("div",{className:"flex h-8 shrink-0 items-center justify-between border-b border-gray-200 px-3 dark:border-gray-700",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400",children:e("sidebar.agents")}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(CL,{}),c.jsx("button",{onClick:()=>o(!0),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-200",title:e("sidebar.collapse"),children:"▶"})]})]}),c.jsx(Ws,{id:"metrics",title:e("sidebar.metricsTitle"),collapsed:N.collapsed,onToggle:()=>f("metrics"),height:N.height,onHeightChange:z=>h("metrics",z),minHeight:120,maxHeight:400,children:c.jsx(pL,{})}),c.jsxs(Ws,{id:"agents",title:e("sidebar.agentList"),collapsed:C.collapsed,onToggle:()=>f("agents"),height:C.height,onHeightChange:z=>h("agents",z),minHeight:100,maxHeight:600,flex:!0,badge:v.length,headerExtra:c.jsx(jL,{filter:p,filterTags:j}),children:[c.jsxs("div",{className:"border-b border-gray-100 px-3 py-1.5 dark:border-gray-800",children:[c.jsx("input",{type:"text",placeholder:e("sidebar.searchPlaceholder"),value:g,onChange:z=>y(z.target.value),className:"w-full rounded border border-gray-200 bg-gray-50 px-2 py-1 text-sm text-gray-800 placeholder-gray-400 outline-none focus:border-blue-400 focus:ring-1 focus:ring-blue-400 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 dark:placeholder-gray-500"}),c.jsx("div",{className:"mt-1.5 flex gap-1",children:j.map(z=>c.jsx("button",{onClick:()=>b(z.key),className:`rounded px-2 py-0.5 text-xs transition-colors ${p===z.key?"bg-blue-600 text-white":"bg-gray-100 text-gray-500 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700"}`,children:z.label},z.key))})]}),c.jsxs("div",{children:[v.map(z=>c.jsxs("button",{onClick:()=>r(z.id),className:`flex w-full items-center gap-3 border-b border-gray-50 px-3 py-2 text-left transition-colors hover:bg-gray-50 dark:border-gray-800 dark:hover:bg-gray-800 ${n===z.id?"bg-blue-50 dark:bg-blue-950":""}`,children:[c.jsx(bw,{agentId:z.id,size:24}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"truncate text-xs font-medium text-gray-800 dark:text-gray-200",children:z.name}),c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full",style:{backgroundColor:Ml[z.status]}}),c.jsx("span",{className:"text-[10px] text-gray-500 dark:text-gray-400",children:e(`common:agent.statusLabels.${z.status}`)}),c.jsxs("span",{className:"text-[10px] text-gray-400 dark:text-gray-500",children:["· ",NL(e,z.lastActiveAt)]})]})]})]},z.id)),v.length===0&&c.jsx("div",{className:"px-3 py-4 text-center text-xs text-gray-400 dark:text-gray-500",children:e("common:empty.noMatchingAgents")})]})]}),k.length>0&&c.jsx(Ws,{id:"subAgents",title:e("sidebar.subAgents"),collapsed:E.collapsed,onToggle:()=>f("subAgents"),height:E.height,onHeightChange:z=>h("subAgents",z),minHeight:60,maxHeight:300,badge:k.length,children:c.jsx(bL,{})}),n&&c.jsx(Ws,{id:"detail",title:e("sidebar.agentDetail"),collapsed:R.collapsed,onToggle:()=>f("detail"),height:R.height,onHeightChange:z=>h("detail",z),minHeight:80,maxHeight:400,children:c.jsx(oL,{})}),c.jsx(Ws,{id:"timeline",title:e("sidebar.eventTimeline"),collapsed:H.collapsed,onToggle:()=>f("timeline"),height:H.height,onHeightChange:z=>h("timeline",z),minHeight:150,maxHeight:600,flex:!0,children:c.jsx(dL,{})})]})}function jL({filter:e,filterTags:t}){var r;if(e==="all")return null;const n=((r=t.find(s=>s.key===e))==null?void 0:r.label)??e;return c.jsx("span",{className:"rounded bg-blue-100 px-1 text-[9px] text-blue-700 dark:bg-blue-900/50 dark:text-blue-300",children:n})}function CL(){const{t:e}=se("layout"),t=$i(),r=Zt().pathname==="/living-office";return c.jsxs("button",{onClick:()=>t(r?"/":"/living-office"),className:`flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] font-semibold transition-colors ${r?"bg-violet-100 text-violet-700 dark:bg-violet-900/40 dark:text-violet-300":"text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300"}`,title:e("sidebar.livingOffice"),children:[e("sidebar.livingOffice"),c.jsx("span",{className:"rounded bg-violet-500/20 px-1 text-[8px] text-violet-500 dark:text-violet-400",children:e("sidebar.livingOfficeBeta")})]})}function NL(e,t){const n=Math.max(0,Math.floor((Date.now()-t)/1e3));return n<5?e("common:time.justNow"):n<60?e("common:time.secondsAgo",{count:n}):n<3600?e("common:time.minutesAgo",{count:Math.floor(n/60)}):e("common:time.hoursAgo",{count:Math.floor(n/3600)})}function AL(){var u;const{i18n:e,t}=se("layout"),n=(u=e.language)==null?void 0:u.startsWith("zh"),r=n?"中文":"EN",s=t(n?"topbar.language.switchToEn":"topbar.language.switchToZh"),o=()=>{e.changeLanguage(n?"en":"zh")};return c.jsx("button",{onClick:o,"aria-label":s,title:s,className:"ml-1 flex h-7 w-7 items-center justify-center rounded-md text-xs font-semibold transition-colors hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-400",children:r})}function EL(){try{const e=document.createElement("canvas");return(e.getContext("webgl2")??e.getContext("webgl"))!==null}catch{return!1}}const TL="2026.3.21";function DL(e){return{connecting:{color:"#eab308",pulse:!0,label:e("common:status.connecting")},connected:{color:"#22c55e",pulse:!1,label:e("common:status.connected")},reconnecting:{color:"#f97316",pulse:!0,label:e("common:status.reconnecting")},disconnected:{color:"#6b7280",pulse:!1,label:e("common:status.disconnected")},error:{color:"#ef4444",pulse:!1,label:e("common:status.error")}}}function kw({isMobile:e=!1}){const{t}=se("layout"),n=ie(v=>v.connectionStatus),r=ie(v=>v.connectionError),s=ie(v=>v.globalMetrics),o=ie(v=>v.viewMode),u=ie(v=>v.setViewMode),f=ie(v=>v.theme),h=ie(v=>v.setTheme),g=ie(v=>v.currentPage),y=S.useMemo(()=>EL(),[]),p=DL(t)[n],b=g==="office";return c.jsxs("header",{className:"flex h-12 shrink-0 items-center border-b border-gray-200 bg-white px-4 shadow-sm dark:border-gray-700 dark:bg-gray-900",children:[b?c.jsx(RL,{viewMode:o,setViewMode:u,metrics:s,webglAvailable:y,isMobile:e}):c.jsx(ML,{currentPage:g}),c.jsxs("div",{className:"ml-auto flex items-center gap-3",children:[c.jsx(OL,{currentPage:g}),c.jsx(zL,{theme:f,setTheme:h}),c.jsx(AL,{}),c.jsx(_L,{statusCfg:p,connectionError:r,connectionStatus:n})]})]})}function RL({viewMode:e,setViewMode:t,metrics:n,webglAvailable:r,isMobile:s}){const{t:o}=se("layout");return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("h1",{className:"text-lg font-semibold tracking-tight text-gray-800 dark:text-gray-100",children:"OpenClaw Office"}),c.jsxs("span",{className:"rounded-full bg-gray-100 px-2 py-0.5 text-xs text-gray-500 dark:bg-gray-800 dark:text-gray-400",children:["v",TL]})]}),c.jsx(LL,{viewMode:e,setViewMode:t,webglAvailable:r,isMobile:s}),c.jsxs("div",{className:"mx-8 flex items-center gap-6 text-sm text-gray-500 dark:text-gray-400",children:[c.jsxs("span",{children:[o("topbar.activeCountText")," ",c.jsxs("strong",{className:"text-gray-800 dark:text-gray-200",children:[n.activeAgents,"/",n.totalAgents]})]}),c.jsxs("span",{children:[o("topbar.tokensLabel")," ",c.jsx("strong",{className:"text-gray-800 dark:text-gray-200",children:IL(n.totalTokens)})]})]})]})}function ML({currentPage:e}){const{t}=se("layout");return c.jsx("div",{className:"flex items-center gap-3",children:c.jsx("h1",{className:"text-lg font-semibold text-gray-800 dark:text-gray-100",children:t(`topbar.pageTitles.${e}`,{defaultValue:t("topbar.pageTitles.fallback")})})})}function OL({currentPage:e}){const{t}=se("layout"),n=$i(),r=Zt(),s=e!=="office",o=r.pathname==="/living-office";return c.jsx("div",{className:"flex items-center gap-1",children:c.jsx("button",{onClick:()=>n(s?o?"/living-office":"/":"/dashboard"),className:`flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-sm font-medium transition-colors ${s?"bg-blue-50 text-blue-600 dark:bg-blue-900/30 dark:text-blue-400":"text-gray-600 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-800"}`,children:s?c.jsxs(c.Fragment,{children:[c.jsx(E1,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden sm:inline",children:t("topbar.office")})]}):c.jsxs(c.Fragment,{children:[c.jsx(d4,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden sm:inline",children:t("topbar.console")})]})})})}function _L({statusCfg:e,connectionError:t,connectionStatus:n}){return c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("div",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:e.color,animation:e.pulse?"pulse 1.5s ease-in-out infinite":"none"}}),c.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:t&&n==="error"?t:e.label})]})}function LL({viewMode:e,setViewMode:t,webglAvailable:n,isMobile:r}){const{t:s}=se("layout"),o=[{key:"2d",label:"2D"},{key:"3d",label:"3D"}];return c.jsx("div",{className:"ml-6 flex items-center rounded-md bg-gray-100 p-0.5 dark:bg-gray-800",children:o.map(({key:u,label:f})=>{const h=e===u,g=u==="3d"&&(!n||r),y=g?s(r?"topbar.viewMode.mobileNotSupported":"topbar.viewMode.webglNotSupported"):s("topbar.viewMode.switchTo",{mode:f});return c.jsx("button",{onClick:()=>!g&&t(u),disabled:g,title:y,className:`rounded px-3 py-1 text-xs font-medium transition-colors ${h?"bg-blue-600 text-white shadow-sm":g?"cursor-not-allowed text-gray-300 dark:text-gray-600":"text-gray-500 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200"}`,children:f},u)})})}function zL({theme:e,setTheme:t}){const{t:n}=se("layout");return c.jsx("button",{onClick:()=>t(e==="light"?"dark":"light"),title:n(e==="light"?"topbar.theme.switchToDark":"topbar.theme.switchToLight"),className:"ml-2 flex h-7 w-7 items-center justify-center rounded-md text-base transition-colors hover:bg-gray-200 dark:hover:bg-gray-700",children:e==="light"?"🌙":"☀️"})}function IL(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function HL({children:e,wsClient:t,isMobile:n=!1}){const{t:r}=se("layout"),s=ie(j=>j.sidebarCollapsed),o=ie(j=>j.setSidebarCollapsed),u=Qe(j=>j.initEventListeners),f=Qe(j=>j.setTargetAgent),h=ie(j=>j.connectionStatus),g=ie(j=>j.agents),y=ie(j=>j.selectedAgentId),p=ie(j=>j.initEventHistory),v=Zt().pathname==="/living-office";S.useEffect(()=>{n&&o(!0)},[n,o]),S.useEffect(()=>{p()},[p]),S.useEffect(()=>{if(h!=="connected")return;const j=(t==null?void 0:t.current)??null;return j?u(j):void 0},[h,t,u]),S.useEffect(()=>{if(h==="connected"&&g.size>0&&!Qe.getState().targetAgentId){const N=Array.from(g.values()).find(C=>!C.isSubAgent);N&&f(N.id)}},[h,g,f]),S.useEffect(()=>{if(!y)return;const j=g.get(y);if(!j||j.isSubAgent)return;Qe.getState().targetAgentId!==y&&f(y)},[y,g,f]);const k=e??c.jsx(d1,{});return c.jsxs("div",{className:"flex h-screen w-screen flex-col bg-gray-50 text-gray-900 dark:bg-gray-950 dark:text-gray-100",children:[c.jsx(yw,{}),c.jsx(kw,{isMobile:n}),c.jsx(nL,{}),c.jsxs("div",{className:"relative flex flex-1 overflow-hidden",children:[c.jsxs("main",{className:"relative flex flex-1 flex-col overflow-hidden",children:[c.jsx("div",{className:"relative flex-1 overflow-hidden",children:k}),c.jsx(Y_,{}),c.jsx(Q_,{})]}),!v&&(n?c.jsxs(c.Fragment,{children:[c.jsx("button",{type:"button",onClick:()=>o(!s),className:"fixed bottom-0 left-1/2 z-20 flex h-10 w-full max-w-xs -translate-x-1/2 items-center justify-center border-t border-gray-200 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-900","aria-label":r(s?"sidebar.expandSidebar":"sidebar.collapseSidebar"),children:c.jsx("div",{className:"h-1 w-12 rounded-full bg-gray-300 dark:bg-gray-600"})}),!s&&c.jsxs(c.Fragment,{children:[c.jsx("div",{role:"button",tabIndex:0,onClick:()=>o(!0),onKeyDown:j=>j.key==="Escape"&&o(!0),className:"fixed inset-0 z-30 bg-black/30","aria-label":r("sidebar.closeSidebar")}),c.jsx("aside",{className:"fixed inset-x-0 bottom-10 top-12 z-40 overflow-hidden rounded-t-xl border-t border-gray-200 bg-white shadow-xl dark:border-gray-700 dark:bg-gray-900",children:c.jsx(vv,{})})]})]}):c.jsx(vv,{}))]})]})}function BL(){const{t:e}=se("layout"),t=Zt(),n=$i(),r=[{path:"/dashboard",labelKey:"consoleNav.dashboard",icon:i4},{path:"/agents",labelKey:"consoleNav.agents",icon:T1},{path:"/channels",labelKey:"consoleNav.channels",icon:Tl},{path:"/skills",labelKey:"consoleNav.skills",icon:O1},{path:"/cron",labelKey:"consoleNav.cron",icon:Ki},{path:"/settings",labelKey:"consoleNav.settings",icon:Cg}];return c.jsxs("div",{className:"flex h-screen w-screen flex-col bg-gray-50 text-gray-900 dark:bg-gray-950 dark:text-gray-100",children:[c.jsx(yw,{}),c.jsx(kw,{}),c.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[c.jsx("nav",{className:"flex w-52 shrink-0 flex-col border-r border-gray-200 bg-white py-3 dark:border-gray-700 dark:bg-gray-900",children:r.map(s=>{const o=t.pathname===s.path,u=s.icon;return c.jsxs("button",{onClick:()=>n(s.path),className:`mx-2 flex items-center gap-2.5 rounded-md px-3 py-2 text-sm transition-colors ${o?"bg-blue-50 font-medium text-blue-600 dark:bg-blue-900/30 dark:text-blue-400":"text-gray-600 hover:bg-gray-100 hover:text-gray-800 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-200"}`,children:[c.jsx(u,{className:"h-4 w-4"}),c.jsx("span",{children:e(s.labelKey)})]},s.path)})}),c.jsx("main",{className:"flex-1 overflow-auto",children:c.jsx("div",{className:"mx-auto max-w-6xl p-6",children:c.jsx(d1,{})})})]})]})}var Tt=(e=>(e[e.L0=0]="L0",e[e.L1=1]="L1",e[e.L2=2]="L2",e[e.L3=3]="L3",e[e.L4=4]="L4",e))(Tt||{});const UL={0:0,1:800,2:1500,3:2500,4:4e3},$L=6e3,qL=3e3,jh=300,KL=800,kv=7,PL={0:1,1:3,2:5,3:7,4:10};W1();const FL={ARRIVE:"INCOMING",DISPATCH:"WORKING",ACK:"ACK",FOCUS:"WORKING",CALL_TOOL:"TOOL_CALL",WAIT:"WAITING",SPAWN_SUBAGENT:"COLLABORATING",COLLAB:"COLLABORATING",RETURN:"DONE",BROADCAST_CRON:"IDLE",POLL_HEARTBEAT:"IDLE",BLOCK:"BLOCKED",RECOVER:"RECOVERED"},GL=5;function VL(){return{gatewayStream:[{label:"WebSocket",detail:we.t("office:livingOffice.gateway.connecting"),active:!1},{label:"Event Bus",detail:we.t("office:livingOffice.gateway.ready"),active:!1},{label:"RPC",detail:we.t("office:livingOffice.gateway.ready"),active:!1},{label:"Health",detail:we.t("office:livingOffice.gateway.normal"),active:!0}],cronTasks:[],memoryItems:[],projectTasks:[],opsRules:[]}}function fc(e,t,n,r=GL){const s=e.findIndex(o=>n(o,t));s>=0&&e.splice(s,1),e.push(t),e.length>r&&e.splice(0,e.length-r)}function YL(e){return e.actors.length===0?"system":e.actors.length===1?e.actors[0]:`${e.actors[0]} +${e.actors.length-1}`}function QL(e){switch(e.kind){case"BROADCAST_CRON":return"cron";case"BLOCK":return"incident";case"RECOVER":return"recovery";case"CALL_TOOL":return"tool";case"SPAWN_SUBAGENT":return"project";default:return e.area}}function WL(e,t){if(t.summary&&t.kind!=="POLL_HEARTBEAT"&&fc(e.memoryItems,{text:t.summary,tag:QL(t)},(n,r)=>n.text===r.text),(t.kind==="SPAWN_SUBAGENT"||t.kind==="COLLAB")&&fc(e.projectTasks,{title:t.summary,subtitle:`active · ${YL(t)}`},(n,r)=>n.title===r.title),(t.kind==="BLOCK"||t.kind==="RECOVER")&&fc(e.opsRules,{text:t.summary,tag:t.kind==="BLOCK"?"incident":"recovery"},(n,r)=>n.text===r.text),t.kind==="BROADCAST_CRON"&&fc(e.cronTasks,{time:new Date(t.startTs).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),name:t.summary,status:"running"},(n,r)=>n.name===r.name&&n.time===r.time),t.kind==="ARRIVE"||t.kind==="DISPATCH"){const n=e.gatewayStream.find(o=>o.label==="WebSocket");n&&(n.detail=we.t("office:livingOffice.gateway.streaming"),n.active=!0);const r=e.gatewayStream.find(o=>o.label==="Event Bus");r&&(r.detail=t.summary.slice(0,30),r.active=!0);const s=e.gatewayStream.find(o=>o.label==="RPC");s&&(s.detail=`actors ${t.actors.length||1}`,s.active=!0)}if(t.kind==="BLOCK"||t.kind==="RECOVER"){const n=e.gatewayStream.find(r=>r.label==="Health");n&&(n.detail=t.kind==="BLOCK"?we.t("office:livingOffice.gateway.alert"):we.t("office:livingOffice.gateway.recovered"),n.active=t.kind!=="BLOCK")}}const Dn=Mn()(X1((e,t)=>({agents:new Map,narrativeLogs:[],sceneArea:VL(),initAgent:(n,r,s)=>{e(o=>{o.agents.set(n,{agentId:n,role:r,state:"IDLE",deskId:s,load:0,lastHeartbeatAt:Date.now(),health:"ok"})})},initAgentsBatch:n=>{e(r=>{for(const{agentId:s,role:o,deskId:u}of n)r.agents.set(s,{agentId:s,role:o,state:"IDLE",deskId:u,load:0,lastHeartbeatAt:Date.now(),health:"ok"})})},applyPerceivedEvent:n=>{e(r=>{const s=FL[n.kind]??"IDLE";for(const o of n.actors){let u=r.agents.get(o);u||(u={agentId:o,role:o,state:"IDLE",deskId:o,load:0,lastHeartbeatAt:Date.now(),health:"ok"},r.agents.set(o,u)),u.state=s,n.kind==="CALL_TOOL"?u.tool=n.summary:u.tool=void 0,n.kind==="BLOCK"?u.health="error":n.kind==="RECOVER"&&(u.health="ok"),u.taskSummary=n.summary}n.summary&&n.kind!=="POLL_HEARTBEAT"&&(r.narrativeLogs.push({ts:n.startTs,text:n.summary,level:n.level,kind:n.kind}),r.narrativeLogs.length>kv&&r.narrativeLogs.splice(0,r.narrativeLogs.length-kv)),WL(r.sceneArea,n)})},resetAgent:n=>{e(r=>{const s=r.agents.get(n);s&&(s.state="IDLE",s.tool=void 0,s.taskSummary=void 0,s.sessionId=void 0)})},getSnapshot:()=>{const n=t();return{agents:new Map(n.agents),narrativeLogs:[...n.narrativeLogs],sceneArea:{...n.sceneArea}}}}))),Vc=Mn((e,t)=>({tasks:[],isLoading:!1,error:null,dialogOpen:!1,editingTask:null,fetchTasks:async()=>{e({isLoading:!0,error:null});try{await Pe();const n=await Oe().cronList();e({tasks:n,isLoading:!1})}catch(n){e({error:String(n),isLoading:!1})}},addTask:async n=>{try{const r=await Oe().cronAdd(n);e(s=>({tasks:[...s.tasks,r],dialogOpen:!1,editingTask:null})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")}catch(r){e({error:String(r)})}},updateTask:async(n,r)=>{try{const s=await Oe().cronUpdate(n,r);e(o=>({tasks:o.tasks.map(u=>u.id===n?s:u),dialogOpen:!1,editingTask:null})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")}catch(s){e({error:String(s)})}},removeTask:async n=>{try{await Oe().cronRemove(n),e(r=>({tasks:r.tasks.filter(s=>s.id!==n)})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")}catch(r){e({error:String(r)})}},runTask:async n=>{try{await Oe().cronRun(n),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")}catch(r){e({error:String(r)})}},openDialog:n=>e({dialogOpen:!0,editingTask:n??null}),closeDialog:()=>e({dialogOpen:!1,editingTask:null}),handleCronEvent:n=>{!n.jobId||!n.state||e(r=>({tasks:r.tasks.map(s=>s.id===n.jobId?{...s,state:{...s.state,...n.state}}:s)}))},initEventListeners:()=>{const n=(o,u)=>{o==="cron"&&t().handleCronEvent(u)};let r=!1,s=()=>{};return Pe().then(()=>{r||(s=Oe().onEvent(n))}).catch(()=>{s=()=>{}}),()=>{r=!0,s()}}})),XL={IDLE:new Set(["INCOMING"]),INCOMING:new Set(["ACK"]),ACK:new Set(["WORKING"]),WORKING:new Set(["TOOL_CALL","WAITING","COLLABORATING","DONE","BLOCKED"]),TOOL_CALL:new Set(["WORKING","WAITING","DONE","BLOCKED"]),WAITING:new Set(["WORKING","DONE","BLOCKED"]),COLLABORATING:new Set(["RETURNING","BLOCKED"]),RETURNING:new Set(["DONE"]),DONE:new Set(["IDLE"]),BLOCKED:new Set(["RECOVERED"]),RECOVERED:new Set(["WORKING","IDLE"])},ZL={ARRIVE:"INCOMING",DISPATCH:"WORKING",ACK:"ACK",FOCUS:"WORKING",CALL_TOOL:"TOOL_CALL",WAIT:"WAITING",SPAWN_SUBAGENT:"COLLABORATING",COLLAB:"COLLABORATING",RETURN:"RETURNING",BROADCAST_CRON:"IDLE",POLL_HEARTBEAT:"IDLE",BLOCK:"BLOCKED",RECOVER:"RECOVERED"},Nr={IDLE:{cssClass:"idle",shouldMove:!1,holdMs:0},INCOMING:{cssClass:"incoming",shouldMove:!1,holdMs:1e3},ACK:{cssClass:"ack",shouldMove:!1,holdMs:1200},WORKING:{cssClass:"working",shouldMove:!1,holdMs:2500},TOOL_CALL:{cssClass:"tool-call",shouldMove:!1,holdMs:2e3},WAITING:{cssClass:"waiting",shouldMove:!1,holdMs:2500},COLLABORATING:{cssClass:"collaborating",shouldMove:!0,holdMs:5e3},RETURNING:{cssClass:"returning",shouldMove:!0,holdMs:1500},DONE:{cssClass:"done",shouldMove:!1,holdMs:1200},BLOCKED:{cssClass:"blocked",shouldMove:!1,holdMs:5e3},RECOVERED:{cssClass:"recovered",shouldMove:!1,holdMs:2500}},wv=new Set(["DISPATCH","COLLAB","SPAWN_SUBAGENT","RETURN","BLOCK"]),JL={RETURNING:"DONE"};function e8(e,t){const n=ZL[t];if(!n)return{nextState:e,visual:{...Nr[e]}};if(n==="IDLE")return{nextState:"IDLE",visual:{...Nr.IDLE}};if(e===n){const f=JL[e];return f?{nextState:f,visual:{...Nr[f],shouldMove:Nr[f].shouldMove&&wv.has(t)}}:{nextState:e,visual:{...Nr[e]}}}XL[e].has(n)||console.warn(`[StateMachine] Illegal transition: ${e} → ${n} (event: ${t}). Accepting with degradation.`);const o=Nr[n],u=o.shouldMove&&wv.has(t);return{nextState:n,visual:{...o,shouldMove:u}}}function t8(){return{nextState:"IDLE",visual:{...Nr.IDLE}}}const Xa={position:"absolute",top:-28,left:"50%",transform:"translateX(-50%)",fontSize:10,fontWeight:700,whiteSpace:"nowrap",pointerEvents:"none",zIndex:10,lineHeight:"16px"};function n8({state:e,toolName:t}){const{t:n}=se("office");switch(e){case"WORKING":return c.jsxs("div",{className:"lo-status-indicator lo-status-working",style:{...Xa,display:"flex",alignItems:"center",gap:3},children:[c.jsx("span",{className:"lo-status-gear",children:"⚙"}),c.jsx("span",{style:{color:"#7dd5ff",fontSize:9},children:n("livingOffice.status.working")})]});case"TOOL_CALL":return c.jsxs("div",{className:"lo-status-indicator lo-status-tool",style:{...Xa,background:"rgba(251, 191, 36, 0.15)",border:"1px solid rgba(251, 191, 36, 0.4)",borderRadius:6,padding:"1px 6px",color:"#fbbf24"},children:["🔧 ",t??n("livingOffice.status.tool")]});case"WAITING":return c.jsx("div",{className:"lo-status-indicator lo-status-waiting",style:{...Xa,color:"#94a3b8"},children:c.jsx("span",{className:"lo-status-hourglass",children:"⏳"})});case"BLOCKED":return c.jsx("div",{className:"lo-status-indicator lo-status-blocked",style:{...Xa,color:"#ff667a",fontSize:14,fontWeight:900},children:c.jsx("span",{className:"lo-status-alert",children:"❗"})});case"COLLABORATING":return c.jsxs("div",{className:"lo-status-indicator lo-status-collab",style:{...Xa,display:"flex",alignItems:"center",gap:3,color:"#a78bfa"},children:[c.jsx("span",{className:"lo-status-collab-icon",children:"🤝"}),c.jsx("span",{style:{fontSize:9},children:n("livingOffice.status.collaborating")})]});case"INCOMING":return c.jsx("div",{className:"lo-status-indicator lo-status-incoming",style:{...Xa,color:"#5cc8ff"},children:c.jsx("span",{className:"lo-status-incoming-icon",children:"📨"})});case"RETURNING":return c.jsxs("div",{className:"lo-status-indicator lo-status-returning",style:{...Xa,color:"#34d399",fontSize:9},children:["✅ ",n("livingOffice.status.returning")]});case"RECOVERED":return c.jsxs("div",{className:"lo-status-indicator lo-status-recovered",style:{...Xa,color:"#34d399",fontSize:9},children:["🔄 ",n("livingOffice.status.recovered")]});default:return null}}const tr=40,Ri=16,hc=24,Sv=12,Mi=3,jv=5,Cv=4,Nv=10,a8="#ffd8b4",Av="#2c3e50",r8="rgba(0, 0, 0, 0.35)",i8="rgba(11, 18, 32, 0.75)",s8="#e8f1ff",Ev=[["#7dd5ff","#5c8dff"],["#ff9a76","#e85d4a"],["#a78bfa","#7c3aed"],["#34d399","#059669"],["#fbbf24","#d97706"],["#f472b6","#db2777"],["#67e8f9","#06b6d4"],["#fb923c","#ea580c"]];function l8(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Ev[Math.abs(t)%Ev.length]}const o8=18,c8=3e3,u8=8e3,d8=2e3,f8=5e3,ww=1200,Sw=18,Xs=64,Zs=-8,h8={"desk-gm":{left:110+Xs,top:360+Zs},"desk-sales":{left:330+Xs,top:360+Zs},"desk-ops":{left:550+Xs,top:360+Zs},"desk-fin":{left:770+Xs,top:360+Zs},"desk-it":{left:440+Xs,top:500+Zs}},g8=[{left:1140,top:370},{left:1240,top:430},{left:1340,top:370}],m8=[{left:120,top:730},{left:340,top:730},{left:560,top:730},{left:780,top:730},{left:1e3,top:730},{left:1220,top:730},{left:230,top:810},{left:450,top:810},{left:670,top:810},{left:890,top:810},{left:1110,top:810}],Ch=900,p8="cubic-bezier(.25, .9, .2, 1)";function jw({name:e,agentId:t,cssClass:n,gazeDirection:r,state:s,toolName:o}){const[u,f]=l8(t),h=r*1.5;return c.jsxs("div",{className:`lo-char-body ${n}`,style:{position:"relative",width:tr,height:tr+20,display:"flex",flexDirection:"column",alignItems:"center"},children:[c.jsx(n8,{state:s,toolName:o}),c.jsx("div",{className:"lo-char-tag",style:{position:"absolute",top:-14,left:"50%",transform:"translateX(-50%) translateZ(18px)",fontSize:9,fontWeight:600,color:s8,background:i8,borderRadius:8,padding:"1px 6px",whiteSpace:"nowrap",pointerEvents:"none",lineHeight:"14px",border:"1px solid rgba(255,255,255,0.08)"},children:e}),c.jsxs("div",{className:"lo-char-head",style:{width:Ri,height:Ri,borderRadius:"50%",background:a8,boxShadow:"inset 0 -2px 4px rgba(0,0,0,0.15), 0 2px 6px rgba(0,0,0,0.2)",flexShrink:0,zIndex:2,position:"relative"},children:[c.jsx("div",{className:"lo-char-eye lo-char-eye-left",style:{position:"absolute",width:Mi,height:Mi,borderRadius:"50%",background:Av,top:Ri*.38,left:Ri/2-jv/2-Mi/2+h,transition:"left 0.4s ease"}}),c.jsx("div",{className:"lo-char-eye lo-char-eye-right",style:{position:"absolute",width:Mi,height:Mi,borderRadius:"50%",background:Av,top:Ri*.38,left:Ri/2+jv/2-Mi/2+h,transition:"left 0.4s ease"}})]}),c.jsxs("div",{style:{position:"relative",marginTop:-3,zIndex:1,display:"flex",alignItems:"flex-start"},children:[c.jsx("div",{className:"lo-char-arm lo-char-arm-left",style:{width:Cv,height:Nv,borderRadius:"3px 3px 2px 2px",background:`linear-gradient(180deg, ${u}cc, ${f}cc)`,marginRight:-1,marginTop:2,transformOrigin:"top center"}}),c.jsx("div",{className:"lo-char-torso",style:{width:hc,height:hc,borderRadius:`${Sv}px ${Sv}px 6px 6px`,background:`linear-gradient(180deg, ${u}, ${f})`,boxShadow:`0 0 12px ${u}40, 0 4px 12px rgba(0,0,0,0.3)`}}),c.jsx("div",{className:"lo-char-arm lo-char-arm-right",style:{width:Cv,height:Nv,borderRadius:"3px 3px 2px 2px",background:`linear-gradient(180deg, ${u}cc, ${f}cc)`,marginLeft:-1,marginTop:2,transformOrigin:"top center"}})]}),c.jsx("div",{className:"lo-char-shadow",style:{width:hc+10,height:6,borderRadius:"50%",background:r8,filter:"blur(4px)",marginTop:2,zIndex:0}}),s!=="IDLE"&&s!=="DONE"&&c.jsx("div",{className:"lo-char-status-ring",style:{position:"absolute",bottom:0,left:"50%",transform:"translateX(-50%)",width:hc+14,height:8,borderRadius:"50%",background:y8(s),filter:"blur(5px)",opacity:.6,zIndex:0}})]})}function y8(e){switch(e){case"WORKING":case"TOOL_CALL":return"rgba(92, 200, 255, 0.6)";case"BLOCKED":return"rgba(255, 102, 122, 0.7)";case"COLLABORATING":return"rgba(167, 139, 250, 0.6)";case"WAITING":return"rgba(148, 163, 184, 0.4)";case"INCOMING":case"ACK":return"rgba(92, 200, 255, 0.4)";case"RETURNING":case"RECOVERED":return"rgba(52, 211, 153, 0.5)";default:return"transparent"}}function Tv(e,t){return e+Math.random()*(t-e)}function x8(e,t){const[n,r]=S.useState({left:0,top:0}),[s,o]=S.useState(0),[u,f]=S.useState(!1),h=S.useRef(void 0),g=S.useRef(void 0),y=e==="IDLE"||e==="DONE",p=S.useCallback(()=>{h.current=setTimeout(()=>{if(!y)return;const v=Math.random()*Math.PI*2,k=Math.random()*o8;f(!0),r({left:Math.cos(v)*k,top:Math.sin(v)*k}),setTimeout(()=>{f(!1),Math.random()<.3&&r({left:0,top:0}),p()},ww)},Tv(c8,u8))},[y]),b=S.useCallback(()=>{g.current=setTimeout(()=>{y&&(o(Math.floor(Math.random()*3)-1),b())},Tv(d8,f8))},[y]);return S.useEffect(()=>{if(y){const v=Math.random()*3e3,k=setTimeout(()=>{p(),b()},v);return()=>{clearTimeout(k),clearTimeout(h.current),clearTimeout(g.current)}}r({left:0,top:0}),o(0),f(!1),clearTimeout(h.current),clearTimeout(g.current)},[y,p,b]),{wanderOffset:n,gazeDirection:s,isWandering:u}}function b8({agentId:e,deskId:t,name:n,perceivedState:r,eventKind:s,targetPosition:o,toolName:u}){const f=h8[t]??{left:0,top:0},[h,g]=S.useState("IDLE"),[y,p]=S.useState("idle"),[b,v]=S.useState(!1),[k,j]=S.useState(f),N=S.useRef("IDLE"),C=S.useRef(void 0),E=x8(h);S.useEffect(()=>{if(!s)return;const M=e8(N.current,s);N.current=M.nextState,g(M.nextState),p(M.visual.cssClass),M.visual.shouldMove&&o&&(v(!0),j(o),clearTimeout(C.current),C.current=setTimeout(()=>{v(!1)},Ch))},[s,o]),S.useEffect(()=>{r!==h&&!s&&(N.current=r,g(r),p(v8(r)))},[r,h,s]),S.useEffect(()=>{if(h!=="DONE")return;const M=setTimeout(()=>{const $=t8();N.current=$.nextState,g($.nextState),p($.visual.cssClass),j(f)},1200);return()=>clearTimeout(M)},[h,f]),S.useEffect(()=>{if(h!=="RETURNING")return;v(!0),j(f);const M=setTimeout(()=>{v(!1)},Ch);return()=>clearTimeout(M)},[h,f]),S.useEffect(()=>()=>clearTimeout(C.current),[]);const R=h==="IDLE",H=k.left+(R?E.wanderOffset.left:0),z=k.top+(R?E.wanderOffset.top:0),L=b||E.isWandering,G=b?Ch:ww,W=b?p8:"ease-in-out",P=[`lo-char-state-${y}`,L?"lo-char-walking":""].filter(Boolean).join(" ");return c.jsx("div",{"data-agent-id":e,"data-agent-state":h,className:`lo-character ${P}`,style:{position:"absolute",left:H-tr/2,top:z-tr/2,width:tr,transform:`translateZ(${Sw}px)`,transition:L?`left ${G}ms ${W}, top ${G}ms ${W}`:"left 0.3s ease, top 0.3s ease",zIndex:100,pointerEvents:"none"},children:c.jsx(jw,{name:n,agentId:e,cssClass:P,gazeDirection:E.gazeDirection,state:h,toolName:u})})}function v8(e){return{IDLE:"idle",INCOMING:"incoming",ACK:"ack",WORKING:"working",TOOL_CALL:"tool-call",WAITING:"waiting",COLLABORATING:"collaborating",RETURNING:"returning",DONE:"done",BLOCKED:"blocked",RECOVERED:"recovered"}[e]}function k8({agentId:e,name:t,position:n,active:r}){const[s,o]=S.useState(!1),[u,f]=S.useState(!1);return S.useEffect(()=>{if(r)f(!1),requestAnimationFrame(()=>o(!0));else{o(!1);const h=setTimeout(()=>f(!0),600);return()=>clearTimeout(h)}},[r]),u&&!r?null:c.jsx("div",{"data-agent-id":e,"data-subagent":!0,className:`lo-subagent-ghost ${s?"lo-subagent-visible":""}`,style:{position:"absolute",left:n.left-tr/2,top:n.top-tr/2,width:tr,transform:`translateZ(${Sw}px)`,zIndex:99,pointerEvents:"none"},children:c.jsx(jw,{name:`tmp:${t}`,agentId:e,cssClass:"lo-subagent-body",gazeDirection:0,state:"COLLABORATING"})})}const w8=3;function S8(e){return e.slice(0,w8).map((t,n)=>({agentId:t.agentId,name:t.name,slotIndex:n}))}const j8=1600,C8=920,Ir={gateway:{id:"gateway-zone",label:"Gateway Hall",position:{left:30,top:20},size:{width:440,height:250}},ops:{id:"ops-zone",label:"Operations Board",position:{left:490,top:20},size:{width:540,height:250}},cron:{id:"cron-zone",label:"Cron Broadcast",position:{left:1050,top:20},size:{width:380,height:250}},staff:{id:"staff-zone",label:"Staff Floor",position:{left:30,top:290},size:{width:1e3,height:350}},lounge:{id:"lounge-zone",label:"Lounge",position:{left:30,top:660},size:{width:1400,height:230}},project:{id:"project-zone",label:"Project Room",position:{left:1050,top:290},size:{width:380,height:230}},memory:{id:"memory-zone",label:"Memory Wall",position:{left:1050,top:540},size:{width:380,height:100}}},hl=[{id:"desk-gm",agentName:"General Manager",role:"orchestrator",position:{left:110,top:360}},{id:"desk-sales",agentName:"Sales Agent",role:"discovery",position:{left:330,top:360}},{id:"desk-ops",agentName:"Ops Agent",role:"execution",position:{left:550,top:360}},{id:"desk-fin",agentName:"Finance Agent",role:"payment",position:{left:770,top:360}},{id:"desk-it",agentName:"IT Agent",role:"tooling",position:{left:440,top:500}}];function N8(e,t){if(!e)return t;try{const n=localStorage.getItem(e);if(n==="1")return!0;if(n==="0")return!1}catch{}return t}const gc=34;function am({children:e,style:t,tag:n,title:r,collapsedContent:s,headerExtra:o,storageKey:u,defaultCollapsed:f=!1}){const[h,g]=S.useState(()=>N8(u,f)),y=!!r,p=()=>{const b=!h;if(g(b),u)try{localStorage.setItem(u,b?"1":"0")}catch{}};return c.jsxs("div",{style:{background:"var(--lo-glass-bg)",backdropFilter:"var(--lo-glass-blur)",WebkitBackdropFilter:"var(--lo-glass-blur)",border:"var(--lo-glass-border)",borderRadius:h?10:"var(--lo-glass-radius)",padding:h?"0 10px":"10px 14px",height:h?gc:void 0,minHeight:h?gc:void 0,position:"relative",overflow:"hidden",minWidth:0,display:"flex",flexDirection:"column",transition:"padding 0.18s ease, border-radius 0.18s ease, height 0.18s ease",...t},children:[n&&!h&&c.jsx("div",{style:{position:"absolute",top:8,right:10,fontSize:9,fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--lo-muted)",opacity:.6},children:n}),y&&c.jsxs("div",{onClick:p,role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&p()},style:{display:"flex",alignItems:"center",gap:5,cursor:"pointer",userSelect:"none",height:h?gc:"auto",minHeight:h?gc:void 0},children:[c.jsx("span",{style:{display:"inline-flex",width:10,height:10,alignItems:"center",justifyContent:"center",fontSize:7,color:"var(--lo-muted)",opacity:.6,transition:"transform 0.18s ease",transform:h?"rotate(-90deg)":"rotate(0deg)",flexShrink:0},children:"▼"}),c.jsx("span",{style:{fontSize:h?11:13,fontWeight:600,color:"var(--lo-text)",flexShrink:0,whiteSpace:"nowrap",transition:"font-size 0.15s ease"},children:r}),h&&s&&c.jsx("div",{style:{flex:1,minWidth:0,overflow:"hidden",display:"flex",alignItems:"center"},onClick:b=>b.stopPropagation(),children:s}),o&&c.jsx("div",{style:{marginLeft:h&&!s?"auto":0,flexShrink:0},children:o}),n&&h&&c.jsx("span",{style:{marginLeft:o?4:"auto",fontSize:7,fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--lo-muted)",opacity:.4,flexShrink:0},children:n})]}),!h&&c.jsx("div",{style:{marginTop:y?4:0,flex:1,minHeight:0},children:e})]})}function A8(e){const t=new Date(e),n=we.language==="zh"?"zh-CN":"en-US";return t.toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function E8({count:e}){const{t}=se("office");return c.jsx("span",{style:{fontSize:9,color:"var(--lo-muted)",opacity:.8},children:t("livingOffice.hud.eventLogCount",{count:e})})}function T8({text:e}){return c.jsx("span",{style:{fontSize:9,color:"var(--lo-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})}function D8(){const{t:e}=se("office"),t=Dn(s=>s.narrativeLogs),n=S.useRef(null);S.useEffect(()=>{n.current&&(n.current.scrollTop=n.current.scrollHeight)},[t]);const r=t.length>0?t[t.length-1].text:e("livingOffice.hud.eventLogWaiting");return c.jsx(am,{tag:e("livingOffice.hud.eventLogTag"),title:e("livingOffice.hud.eventLogTitle"),headerExtra:c.jsx(E8,{count:t.length}),storageKey:"lo-hud-log",defaultCollapsed:!0,collapsedContent:c.jsx(T8,{text:r}),children:c.jsx("div",{ref:n,style:{maxHeight:42,overflowY:"auto",display:"flex",flexDirection:"column",gap:2,scrollbarWidth:"none"},children:t.length===0?c.jsx("div",{style:{fontSize:10,color:"var(--lo-muted)",opacity:.5,fontStyle:"italic"},children:e("livingOffice.hud.eventLogWaiting")}):t.map((s,o)=>c.jsxs("div",{style:{display:"flex",gap:8,fontSize:10,lineHeight:1.4},children:[c.jsx("span",{style:{color:"var(--lo-muted)",opacity:.6,flexShrink:0,fontFamily:"monospace",fontSize:9},children:A8(s.ts)}),c.jsx("span",{style:{color:"var(--lo-text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.text})]},`${String(s.ts)}-${String(o)}`))})})}function R8({isOnline:e}){const{t}=se("office");return c.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,padding:"2px 8px",borderRadius:10,background:e?"rgba(41, 211, 145, 0.15)":"rgba(255, 102, 122, 0.15)",fontSize:10,fontWeight:500,color:e?"var(--lo-good)":"var(--lo-bad)"},children:[c.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:e?"var(--lo-good)":"var(--lo-bad)",boxShadow:e?"0 0 6px rgba(41,211,145,0.6)":"0 0 6px rgba(255,102,122,0.6)"}}),t(e?"livingOffice.hud.wsOnline":"livingOffice.hud.wsOffline")]})}function M8({lines:e}){const t=e.filter(r=>r.active),n=t.length>0?t:e.slice(-2);return c.jsx("div",{style:{display:"flex",gap:8,overflow:"hidden",maskImage:"linear-gradient(90deg, #000 80%, transparent 100%)",WebkitMaskImage:"linear-gradient(90deg, #000 80%, transparent 100%)"},children:n.map(r=>c.jsxs("span",{style:{fontSize:9,color:r.active?"var(--lo-cyan)":"var(--lo-muted)",whiteSpace:"nowrap",flexShrink:0},children:[r.label,c.jsx("span",{style:{opacity:.6,marginLeft:3},children:r.detail})]},r.label))})}function O8(){const{t:e}=se("office"),t=ie(s=>s.connectionStatus),n=Dn(s=>s.sceneArea.gatewayStream),r=t==="connected";return c.jsxs(am,{title:e("livingOffice.hud.gatewayTitle"),headerExtra:c.jsx(R8,{isOnline:r}),storageKey:"lo-hud-gateway",defaultCollapsed:!0,collapsedContent:c.jsx(M8,{lines:n}),children:[c.jsx("div",{style:{fontSize:10,color:"var(--lo-muted)",marginBottom:6},children:e("livingOffice.hud.gatewaySubtitle")}),c.jsx("div",{style:{display:"flex",flexDirection:"column",gap:3},children:n.map(s=>c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:10,color:s.active?"var(--lo-cyan)":"var(--lo-muted)"},children:[c.jsx("span",{style:{fontWeight:500},children:s.label}),c.jsx("span",{style:{opacity:.75},children:s.detail})]},s.label))})]})}function _8({left:e,center:t,right:n}){return c.jsxs("div",{className:"lo-hud-bar",style:{position:"absolute",top:8,left:8,right:8,zIndex:20,display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr)",gap:8,pointerEvents:"none",alignItems:"start"},children:[e&&c.jsx("div",{style:{pointerEvents:"auto",minWidth:0,overflow:"hidden"},children:e}),t&&c.jsx("div",{style:{pointerEvents:"auto",minWidth:0,overflow:"hidden"},children:t}),n&&c.jsx("div",{style:{pointerEvents:"auto",minWidth:0,overflow:"hidden"},children:n})]})}const Cw=S.createContext(null);function L8(){const e=S.useContext(Cw);return(e==null?void 0:e.current)??null}function z8({stats:e}){return c.jsx("div",{style:{display:"flex",gap:10,alignItems:"center"},children:e.map(t=>c.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3},children:[c.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:t.color,flexShrink:0}}),c.jsx("span",{style:{fontSize:9,color:"var(--lo-muted)"},children:t.label}),c.jsx("span",{style:{fontSize:10,fontWeight:700,color:t.color},children:t.value})]},t.label))})}function I8(){const{t:e}=se("office"),t=Dn(u=>u.agents),n=Dn(u=>u.sceneArea.cronTasks),r=S.useMemo(()=>{let u=0;for(const f of t.values())f.state!=="IDLE"&&f.state!=="DONE"&&u++;return u},[t]),s=S.useMemo(()=>{let u=0;for(const f of t.values())f.taskSummary&&u++;return u},[t]),o=[{label:e("livingOffice.hud.statsActive"),value:r,color:"var(--lo-cyan)"},{label:e("livingOffice.hud.statsPending"),value:s,color:"var(--lo-warn)"},{label:e("livingOffice.hud.statsCron"),value:n.length,color:"var(--lo-violet)"}];return c.jsx(am,{title:e("livingOffice.hud.statsTitle"),storageKey:"lo-hud-stats",defaultCollapsed:!0,collapsedContent:c.jsx(z8,{stats:o}),children:c.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:4},children:o.map(u=>c.jsxs("div",{style:{textAlign:"center"},children:[c.jsx("div",{style:{fontSize:22,fontWeight:700,color:u.color,lineHeight:1.1},children:u.value}),c.jsx("div",{style:{fontSize:9,color:"var(--lo-muted)",marginTop:2},children:u.label})]},u.label))})})}const H8=34;function B8(){const e=S.useMemo(()=>{const t=[];for(let n=0;n<H8;n++)t.push({left:`${mc(n,0)*100}vw`,top:`${mc(n,1)*100}vh`,duration:`${20+mc(n,2)*30}s`,delay:`${-mc(n,3)*40}s`});return t},[]);return c.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",overflow:"hidden"},children:e.map((t,n)=>c.jsx("i",{style:{position:"absolute",width:2,height:2,borderRadius:"50%",background:"rgba(255,255,255,.45)",boxShadow:"0 0 12px rgba(255,255,255,.3)",left:t.left,top:t.top,animation:`lo-float-star ${t.duration} linear infinite`,animationDelay:t.delay,opacity:.45}},n))})}function mc(e,t){const n=Math.sin(e*9301+t*49297+233280)*49297;return n-Math.floor(n)}function U8(){return c.jsx("div",{style:{position:"absolute",inset:0,backgroundImage:["linear-gradient(to right, rgba(255,255,255,.03) 1px, transparent 1px)","linear-gradient(to bottom, rgba(255,255,255,.03) 1px, transparent 1px)"].join(", "),backgroundSize:"60px 60px",opacity:.18}})}function $8(){return c.jsx("div",{className:"lo-floor",style:{position:"absolute",inset:0,borderRadius:34,border:"1px solid var(--lo-line)",boxShadow:"var(--lo-shadow)"}})}function q8({children:e}){return c.jsxs("div",{className:"lo-world",children:[c.jsx(U8,{}),c.jsxs("div",{className:"lo-office",children:[c.jsx($8,{}),e]}),c.jsx(B8,{})]})}function K8({text:e,duration:t=2600}){const[n,r]=S.useState(!1),[s,o]=S.useState(!1);return S.useEffect(()=>{if(!e){r(!1);return}r(!0),o(!1);const u=setTimeout(()=>o(!0),t-350),f=setTimeout(()=>r(!1),t);return()=>{clearTimeout(u),clearTimeout(f)}},[e,t]),!n||!e?null:c.jsx("div",{style:{position:"absolute",left:"50%",top:-22,transform:"translateX(-50%) translateZ(20px) translateY(-6px)",padding:"7px 10px",borderRadius:999,whiteSpace:"nowrap",fontSize:11,color:"#eef7ff",background:"rgba(8, 18, 32, .85)",border:"1px solid rgba(255,255,255,.08)",boxShadow:"0 14px 30px rgba(0,0,0,.28)",animation:s?"lo-bubble-out 0.35s ease forwards":"lo-bubble-in 0.35s ease forwards",pointerEvents:"none"},children:e})}const P8={idle:"var(--lo-good)",busy:"var(--lo-warn)",blocked:"var(--lo-bad)",heartbeat:"var(--lo-cyan)"};function F8({status:e}){const t=P8[e],n=e==="busy"||e==="blocked";return c.jsx("div",{className:n?"lo-desk-ring-active":"lo-desk-ring-idle",style:{position:"absolute",right:10,top:10,width:14,height:14,borderRadius:"50%",background:t,boxShadow:`0 0 12px ${t}`}})}function G8({config:e,status:t="idle",bubble:n=""}){const r=t==="heartbeat";return c.jsxs("div",{"data-desk-id":e.id,style:{position:"absolute",left:e.position.left,top:e.position.top,width:160,height:108,transform:"translateZ(12px)"},children:[r&&c.jsx("div",{style:{position:"absolute",inset:-8,borderRadius:24,border:"2px solid rgba(92,200,255,.16)",animation:"lo-pulse 1.6s ease-out infinite",pointerEvents:"none"}}),c.jsx("div",{style:{position:"absolute",inset:0,background:"var(--lo-glass-bg)",borderRadius:20,border:"var(--lo-glass-border)",boxShadow:"var(--lo-shadow)"}}),c.jsx("div",{className:t==="busy"?"lo-desk-monitor-active":"lo-desk-monitor-idle",style:{position:"absolute",left:46,top:18,width:68,height:30,borderRadius:8,background:t==="busy"?"linear-gradient(180deg, color-mix(in srgb, var(--lo-cyan) 50%, transparent), color-mix(in srgb, var(--lo-cyan) 15%, transparent))":"linear-gradient(180deg, color-mix(in srgb, var(--lo-cyan) 35%, transparent), color-mix(in srgb, var(--lo-cyan) 8%, transparent))",border:"1px solid color-mix(in srgb, var(--lo-cyan) 25%, transparent)",boxShadow:t==="busy"?"0 0 30px color-mix(in srgb, var(--lo-cyan) 25%, transparent)":"0 0 24px color-mix(in srgb, var(--lo-cyan) 14%, transparent)",transition:"background 0.5s ease, box-shadow 0.5s ease"}}),c.jsx(F8,{status:t}),c.jsx("div",{style:{position:"absolute",left:10,bottom:10,fontSize:11,color:"var(--lo-text)",fontWeight:700},children:e.agentName}),c.jsx("div",{style:{position:"absolute",right:10,bottom:10,fontSize:10,color:"var(--lo-muted)"},children:e.role}),c.jsx(K8,{text:n})]})}function V8(){return c.jsxs("div",{style:{position:"absolute",left:1240,top:258,width:30,height:30,borderRadius:"50%",transform:"translateZ(12px)",background:"radial-gradient(circle, rgba(247,185,85,.95), rgba(247,185,85,.25))",boxShadow:"0 0 24px rgba(247,185,85,.35)"},children:[c.jsx(Dv,{delay:"0s"}),c.jsx(Dv,{delay:"1.1s"})]})}function Dv({delay:e}){return c.jsx("div",{style:{position:"absolute",inset:-8,borderRadius:"50%",border:"2px solid rgba(247,185,85,.22)",animation:"lo-rings 2.2s ease-out infinite",animationDelay:e}})}function mu({children:e,className:t="",style:n}){return c.jsx("div",{className:t,style:{borderRadius:22,background:"linear-gradient(180deg, rgba(9,16,30,.95), rgba(8,13,25,.88))",border:"1px solid rgba(255,255,255,.07)",boxShadow:"var(--lo-glow)",overflow:"hidden",...n},children:e})}function pu({title:e,subtitle:t}){return c.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 14px 8px"},children:[c.jsx("b",{style:{fontSize:13,color:"#e9f2ff"},children:e}),t&&c.jsx("span",{style:{fontSize:11,color:"var(--lo-muted)"},children:t})]})}function Y8({tasks:e}){const{t}=se("office"),n=Vc(u=>u.tasks),r=e??[{name:"09:20 订单看板汇总",status:"scheduled"},{name:"10:00 线索清洗广播",status:"scheduled"},{name:"11:30 回款提醒",status:"scheduled"}],s=S.useMemo(()=>n.map(u=>({name:u.name,status:u.state.runningAtMs?"running":u.enabled?u.state.lastRunStatus??"scheduled":"paused"})),[n]),o=s.length>0?s:r;return c.jsxs(mu,{style:{position:"absolute",left:1068,top:38,width:344,height:214,transform:"translateZ(16px)"},children:[c.jsx(pu,{title:t("livingOffice.panels.cronTitle"),subtitle:t("livingOffice.panels.cronSubtitle")}),c.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7,padding:"0 14px 14px"},children:o.slice(0,3).map(u=>c.jsx(Q8,{left:u.name,right:u.status},u.name))})]})}function Q8({left:e,right:t}){return c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,fontSize:11,padding:"7px 9px",background:"rgba(255,255,255,.04)",borderRadius:10},children:[c.jsx("span",{style:{color:"#e6eefc"},children:e}),c.jsx("span",{style:{color:"var(--lo-muted)"},children:t})]})}function Hr({config:e,children:t,className:n="",style:r}){return c.jsx("div",{className:n,style:{position:"absolute",left:e.position.left,top:e.position.top,width:e.size.width,height:e.size.height,borderRadius:26,border:"1px solid rgba(255,255,255,.06)",background:"linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.015))",boxShadow:"inset 0 1px 0 rgba(255,255,255,.05), 0 16px 40px rgba(0,0,0,.28)",transform:"translateZ(4px)",...r},children:t})}function W8(){const e=Ir.cron;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:e}),c.jsx(Y8,{}),c.jsx(V8,{})]})}function X8(){var h,g,y;const{t:e}=se("office"),[t,n]=S.useState(()=>Rv()),r=ie(p=>p.connectionStatus),s=ie(p=>p.operatorScopes),o=ie(p=>p.globalMetrics),u=Dn(p=>p.sceneArea.gatewayStream);S.useEffect(()=>{const p=setInterval(()=>n(Rv()),1e3);return()=>clearInterval(p)},[]);const f=[{title:e("livingOffice.panels.busWebSocket"),detail:((h=u.find(p=>p.label==="WebSocket"))==null?void 0:h.detail)??r},{title:e("livingOffice.panels.busEventSpine"),detail:((g=u.find(p=>p.label==="Event Bus"))==null?void 0:g.detail)??`active ${o.activeAgents}/${o.totalAgents}`},{title:e("livingOffice.panels.busRpcScope"),detail:((y=u.find(p=>p.label==="RPC"))==null?void 0:y.detail)??s[0]??"operator"}];return c.jsxs("div",{style:{position:"absolute",left:48,top:38,width:404,height:214,transform:"translateZ(20px)",borderRadius:24,background:"linear-gradient(180deg, rgba(12, 30, 55, .96), rgba(8,16,30,.96))",border:"1px solid rgba(92,200,255,.24)",boxShadow:"0 18px 40px rgba(0,0,0,.28), 0 0 35px rgba(92,200,255,.12), inset 0 1px 0 rgba(255,255,255,.08)",overflow:"hidden"},children:[c.jsx("div",{style:{position:"absolute",inset:0,background:"linear-gradient(90deg, transparent, rgba(92,200,255,.18), transparent)",transform:"translateX(-100%)",animation:"lo-scan 6s linear infinite"}}),c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"14px 16px 6px",position:"relative"},children:[c.jsx("b",{style:{fontSize:15,color:"#e9f2ff"},children:e("livingOffice.panels.gatewayHeader")}),c.jsx("span",{style:{fontSize:11,color:"var(--lo-muted)"},children:t})]}),c.jsx("div",{style:{position:"absolute",left:16,right:16,bottom:14,height:64,display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:10},children:f.map(p=>c.jsxs("div",{style:{borderRadius:14,background:"rgba(255,255,255,.04)",border:"1px solid rgba(255,255,255,.05)",padding:10,fontSize:11},children:[c.jsx("b",{style:{display:"block",marginBottom:3,color:"#e9f2ff"},children:p.title}),c.jsx("small",{style:{color:"var(--lo-muted)"},children:p.detail})]},p.title))})]})}function Rv(){const e=we.language==="zh"?"zh-CN":"en-US";return new Date().toLocaleTimeString(e,{hour12:!1})}function Z8(){const e=Ir.gateway;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:e}),c.jsx(X8,{}),c.jsx(J8,{})]})}function J8(){return c.jsx("div",{style:{position:"absolute",left:48,top:258,width:404,height:18,transform:"translateZ(6px)",overflow:"hidden",borderRadius:999,background:"rgba(255,255,255,.04)",border:"1px solid rgba(255,255,255,.06)"},children:c.jsx("div",{style:{position:"absolute",left:-120,top:1,width:120,height:14,borderRadius:999,background:"linear-gradient(90deg, rgba(92,200,255,.2), rgba(92,200,255,.85), rgba(255,255,255,.15))",boxShadow:"0 0 22px rgba(92,200,255,.35)",animation:"lo-belt 8s linear infinite"}})})}function ez({left:e,top:t}){return c.jsxs("div",{style:{position:"absolute",left:e,top:t,width:72,height:38,transform:"translateZ(8px)"},children:[c.jsx("div",{style:{position:"absolute",left:4,top:10,width:64,height:24,borderRadius:12,background:"linear-gradient(180deg, rgba(143,125,255,.18), rgba(92,200,255,.08))",border:"1px solid rgba(143,125,255,.15)",boxShadow:"0 4px 12px rgba(0,0,0,.2), inset 0 1px 0 rgba(255,255,255,.06)"}}),c.jsx("div",{style:{position:"absolute",left:8,top:2,width:56,height:12,borderRadius:"10px 10px 4px 4px",background:"linear-gradient(180deg, rgba(143,125,255,.25), rgba(143,125,255,.12))",border:"1px solid rgba(143,125,255,.12)"}}),c.jsx("div",{style:{position:"absolute",left:0,top:8,width:8,height:22,borderRadius:"6px 0 0 6px",background:"rgba(143,125,255,.14)",border:"1px solid rgba(143,125,255,.10)"}}),c.jsx("div",{style:{position:"absolute",right:0,top:8,width:8,height:22,borderRadius:"0 6px 6px 0",background:"rgba(143,125,255,.14)",border:"1px solid rgba(143,125,255,.10)"}})]})}function Js({left:e,top:t}){return c.jsx("div",{style:{position:"absolute",left:e,top:t,width:32,height:20,transform:"translateZ(6px)",borderRadius:8,background:"linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02))",border:"1px solid rgba(255,255,255,.06)",boxShadow:"0 4px 10px rgba(0,0,0,.15)"},children:c.jsx("div",{style:{position:"absolute",left:10,top:4,width:12,height:12,borderRadius:"50%",background:"rgba(247,185,85,.2)",border:"1px solid rgba(247,185,85,.15)"}})})}function pc({left:e,top:t}){return c.jsxs("div",{style:{position:"absolute",left:e,top:t,width:22,height:30,transform:"translateZ(10px)"},children:[c.jsx("div",{style:{position:"absolute",left:4,bottom:0,width:14,height:12,borderRadius:"3px 3px 6px 6px",background:"rgba(180,120,70,.3)",border:"1px solid rgba(180,120,70,.2)"}}),c.jsx("div",{style:{position:"absolute",left:2,top:0,width:18,height:18,borderRadius:"50%",background:"radial-gradient(circle, rgba(52,211,153,.35), rgba(22,163,74,.15))"}})]})}function tz(){return c.jsxs(c.Fragment,{children:[m8.map((e,t)=>c.jsx(ez,{left:e.left,top:e.top},`sofa-${String(t)}`)),c.jsx(Js,{left:240,top:755}),c.jsx(Js,{left:680,top:755}),c.jsx(Js,{left:1100,top:755}),c.jsx(Js,{left:360,top:835}),c.jsx(Js,{left:800,top:835}),c.jsx(pc,{left:60,top:710}),c.jsx(pc,{left:1350,top:710}),c.jsx(pc,{left:500,top:845}),c.jsx(pc,{left:960,top:845})]})}function nz(){const{t:e}=se("office"),t=Ir.lounge;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:t,children:c.jsx("div",{style:{position:"absolute",left:14,top:10,fontSize:11,fontWeight:600,letterSpacing:"0.06em",color:"var(--lo-muted)",opacity:.7,transform:"translateZ(8px)"},children:e("livingOffice.zones.lounge")})}),c.jsx(tz,{})]})}const az=[];function rz({entries:e=az}){const{t}=se("office"),n=Dn(s=>s.sceneArea.memoryItems),r=n.length>0?n:e;return c.jsxs(mu,{style:{position:"absolute",left:1068,top:556,width:344,height:68,transform:"translateZ(16px)"},children:[c.jsx(pu,{title:t("livingOffice.panels.memoryTitle"),subtitle:t("livingOffice.panels.memorySubtitle")}),c.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7,padding:"0 14px 14px"},children:r.length>0?r.slice(-3).reverse().map(s=>c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,fontSize:11,padding:"7px 9px",background:"rgba(255,255,255,.04)",borderRadius:10},children:[c.jsx("span",{style:{color:"#e6eefc"},children:s.text}),c.jsx("span",{style:{color:"var(--lo-muted)"},children:s.tag})]},s.text)):c.jsx("div",{style:{fontSize:11,padding:"7px 9px",background:"rgba(255,255,255,.04)",borderRadius:10,color:"var(--lo-muted)"},children:t("livingOffice.panels.memoryEmpty")})})]})}function iz(){const e=Ir.memory;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:e}),c.jsx(rz,{})]})}function sz({rules:e=[]}){const{t}=se("office"),n=Dn(b=>b.sceneArea.opsRules),r=ie(b=>b.agents),s=ie(b=>b.links),o=ie(b=>b.maxSubAgents),u=ie(b=>b.agentToAgentConfig),f=Array.from(r.values()).filter(b=>b.status==="error").length,h=Array.from(r.values()).filter(b=>b.isSubAgent&&!b.isPlaceholder).length,g=u.enabled?t("livingOffice.panels.opsEnabled"):t("livingOffice.panels.opsDisabled"),y=n.length>0?n.slice(-4).reverse().map(b=>`${b.tag} · ${b.text}`):[`${t("livingOffice.panels.opsErrorAgents")} · ${f}`,`${t("livingOffice.panels.opsCollabLinks")} · ${s.length}`,`${t("livingOffice.panels.opsAgentToAgent")} · ${g}`,`${t("livingOffice.panels.opsSubCapacity")} · ${h}/${o}`],p=y.length>0?y:e;return c.jsxs(mu,{style:{position:"absolute",left:508,top:38,width:504,height:214,transform:"translateZ(16px)"},children:[c.jsx(pu,{title:t("livingOffice.panels.opsTitle"),subtitle:t("livingOffice.panels.opsSubtitle")}),c.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7,padding:"0 14px 14px"},children:p.slice(0,4).map(b=>c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,fontSize:11,padding:"7px 9px",background:"rgba(255,255,255,.04)",borderRadius:10},children:[c.jsx("span",{style:{color:"#e6eefc"},children:b}),c.jsx("span",{style:{color:"var(--lo-muted)"},children:t("livingOffice.panels.opsLive")})]},b))})]})}function lz(){const e=Ir.ops;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:e}),c.jsx(sz,{})]})}function oz({tasks:e}){const{t}=se("office"),n=e??[{title:t("livingOffice.panels.projectEmpty"),subtitle:t("livingOffice.panels.projectEmptySub")}],r=ie(h=>h.lastSessionsSnapshot),s=Dn(h=>h.sceneArea.projectTasks),o=r==null?void 0:r.sessions,u=o&&o.length>0?o.map(h=>({title:h.label||h.agentId,subtitle:h.task||h.requesterSessionKey})):s,f=S.useMemo(()=>u.length>0?u:n,[u,n]);return c.jsxs(mu,{style:{position:"absolute",left:1068,top:308,width:344,height:194,transform:"translateZ(16px)"},children:[c.jsx(pu,{title:t("livingOffice.panels.projectTitle"),subtitle:t("livingOffice.panels.projectSubtitle")}),c.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:"0 14px 14px"},children:f.slice(0,3).map(h=>c.jsxs("div",{style:{padding:"8px 10px",borderRadius:12,background:"rgba(255,255,255,.04)",border:"1px solid rgba(255,255,255,.05)",fontSize:11,color:"#e6eefc"},children:[h.title,c.jsx("small",{style:{color:"var(--lo-muted)",display:"block",marginTop:3},children:h.subtitle})]},h.title))})]})}function cz(){const e=Ir.project;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:e}),c.jsx(oz,{})]})}function uz(){const{t:e}=se("office"),t=Ir.staff;return c.jsx(Hr,{config:t,children:c.jsx("div",{style:{position:"absolute",left:14,top:10,fontSize:11,fontWeight:600,letterSpacing:"0.06em",color:"var(--lo-muted)",opacity:.7,transform:"translateZ(8px)"},children:e("livingOffice.zones.staffFloor")})})}function Nw(e){switch(e){case"WORKING":case"TOOL_CALL":case"COLLABORATING":case"INCOMING":case"ACK":return"busy";case"BLOCKED":return"blocked";default:return"idle"}}const el={left:30,top:290,width:1e3,height:350},Nh=160,Mv=108,yc=30,Ov=50;function dz(e){const[t,n]=S.useState("0.92"),r=S.useCallback(()=>{const s=e.current;if(!s)return;const{width:o,height:u}=s.getBoundingClientRect(),f=o/j8,h=u/C8,g=Math.min(f,h,1.05);n(g.toFixed(3))},[e]);return S.useEffect(()=>{r();const s=new ResizeObserver(r);return e.current&&s.observe(e.current),()=>s.disconnect()},[r,e]),t}function fz(e){if(e<=hl.length)return hl.slice(0,Math.max(e,hl.length));const t=Math.min(e,Math.floor((el.width+yc)/(Nh+yc))),n=Math.ceil(e/t),r=t*Nh+(t-1)*yc,s=n*Mv+(n-1)*Ov,o=el.left+Math.max(0,(el.width-r)/2),u=el.top+Math.max(0,(el.height-s)/2),f=[];for(let h=0;h<e;h++){const g=h%t,y=Math.floor(h/t);f.push({id:`desk-dyn-${h}`,agentName:`Agent ${h+1}`,role:"",position:{left:o+g*(Nh+yc),top:u+y*(Mv+Ov)}})}return f}function hz(e){const t=Array.from(e.values());return(t.length>hl.length?fz(t.length):hl).map((r,s)=>{const o=t[s];return o?{desk:{...r,agentName:o.role!==o.agentId?o.role:o.agentId,role:o.role,status:Nw(o.state)},agent:o}:{desk:r,agent:void 0}})}function gz(){const e=Dn(h=>h.agents),t=ie(h=>h.connectionStatus),n=L8();S.useRef(null);const r=S.useRef(null),s=dz(r),o=S.useMemo(()=>hz(e),[e]),u=Array.from(e.values()).filter(h=>h.state==="COLLABORATING"),f=S8(u.map(h=>({agentId:h.agentId,name:h.role})));return S.useEffect(()=>{},[n]),S.useEffect(()=>{if(t!=="connected")return;const h=Vc.getState();h.fetchTasks();const g=h.initEventListeners(),y=setInterval(()=>{Vc.getState().fetchTasks()},3e4);return()=>{clearInterval(y),g()}},[t]),c.jsxs("div",{className:"living-office",style:{position:"relative",width:"100%",height:"100%",overflow:"hidden",background:"var(--lo-app-bg)",fontFamily:'Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif',color:"var(--lo-text)"},children:[c.jsx("div",{style:{position:"absolute",inset:0,background:"var(--lo-app-overlay)",pointerEvents:"none"}}),c.jsx(_8,{left:c.jsx(O8,{}),center:c.jsx(D8,{}),right:c.jsx(I8,{})}),c.jsx("div",{ref:r,style:{position:"absolute",inset:"46px 8px 6px 8px","--lo-stage-scale":s,"--lo-stage-scale-sm":s},children:c.jsxs(q8,{children:[c.jsx(Z8,{}),c.jsx(lz,{}),c.jsx(W8,{}),c.jsx(uz,{}),c.jsx(nz,{}),c.jsx(cz,{}),c.jsx(iz,{}),o.map(({desk:h,agent:g})=>c.jsx(G8,{config:h,status:g?Nw(g.state):"idle",bubble:(g==null?void 0:g.taskSummary)??""},h.id)),o.map(({desk:h,agent:g})=>c.jsx(b8,{agentId:(g==null?void 0:g.agentId)??h.id,deskId:h.id,name:(g==null?void 0:g.role)??h.agentName,perceivedState:(g==null?void 0:g.state)??"IDLE",toolName:g==null?void 0:g.tool},`char-${h.id}`)),f.map(h=>{const g=g8[h.slotIndex];return g?c.jsx(k8,{agentId:h.agentId,name:h.name,position:g,active:!0},`sub-${h.agentId}`):null})]})})]})}const mz=2,pz=8,il=S.memo(function({agent:t}){const{t:n}=se("common"),r=ie(P=>P.selectedAgentId),s=ie(P=>P.selectAgent),o=ie(P=>P.tickMovement),u=ie(P=>P.theme),[f,h]=S.useState(!1),g=S.useRef(null),y=S.useRef(0),p=S.useRef(0),b=r===t.id,v=b?rl.selectedRadius:rl.radius,k=t.isPlaceholder,j=!t.confirmed,N=t.movement!==null,C=k||j?"#6b7280":Ml[t.status],E=u==="dark",R=xw(t.id),H=`avatar-clip-${t.id}`,z=k?.3:j?.5:1,L=t.name.length>rl.nameLabelMaxChars?`${t.name.slice(0,rl.nameLabelMaxChars)}…`:t.name,G=S.useRef(t.id);G.current=t.id;const W=S.useCallback(P=>{if(!g.current)return;const M=p.current?(P-p.current)/1e3:.016;p.current=P,o(G.current,M);const V=ie.getState().agents.get(G.current);if(!V)return;let ae=0,J=1;if(V.movement){const Z=V.movement.progress,U=(Date.now()-V.movement.startTime)/1e3;if(ae=Math.sin(U*pz*Math.PI*2)*mz,Z<.1)J=.9+Z;else if(Z>.9){const ee=(Z-.9)/.1;J=1-.05*Math.sin(ee*Math.PI)}}g.current.setAttribute("transform",`translate(${V.position.x}, ${V.position.y+ae}) scale(${J})`),V.movement&&(y.current=requestAnimationFrame(W))},[o]);return S.useEffect(()=>(N&&(p.current=0,y.current=requestAnimationFrame(W)),()=>{y.current&&cancelAnimationFrame(y.current)}),[N,W]),c.jsxs("g",{ref:g,transform:`translate(${t.position.x}, ${t.position.y})`,style:{cursor:k?"default":"pointer"},opacity:z,onClick:()=>!k&&s(t.id),onMouseEnter:()=>!k&&h(!0),onMouseLeave:()=>h(!1),children:[b&&c.jsx("circle",{r:v+8,fill:C,opacity:.18,style:{filter:`drop-shadow(0 0 10px ${C})`}}),c.jsx(yz,{status:t.status,r:v,color:C,isWalking:N,isPlaceholder:k}),c.jsx("defs",{children:c.jsx("clipPath",{id:H,children:c.jsx("circle",{r:v-2})})}),c.jsx("circle",{r:v-2,fill:E?"#1e293b":"#f8fafc"}),c.jsx("g",{clipPath:`url(#${H})`,children:c.jsx(kz,{data:R,size:v*2-4})}),t.isSubAgent&&c.jsxs("g",{transform:`translate(${v*.6}, ${v*.5})`,children:[c.jsx("circle",{r:7,fill:E?"#1e293b":"#fff",stroke:C,strokeWidth:1.2}),c.jsx("text",{textAnchor:"middle",dy:"3.5",fontSize:"9",fill:C,fontWeight:"bold",children:"S"})]}),t.status==="thinking"&&c.jsx(bz,{r:v}),t.status==="error"&&c.jsxs("g",{transform:`translate(${v*.65}, ${-v*.65})`,children:[c.jsx("circle",{r:7,fill:"#ef4444"}),c.jsx("text",{textAnchor:"middle",dy:"4",fontSize:"10",fill:"#fff",fontWeight:"bold",children:"!"})]}),t.status==="speaking"&&c.jsx(vz,{r:v}),t.status==="tool_calling"&&t.currentTool&&c.jsx("foreignObject",{x:-50,y:v+2,width:100,height:20,style:{pointerEvents:"none"},children:c.jsx("div",{style:{display:"flex",justifyContent:"center"},children:c.jsx("span",{style:{fontSize:"9px",fontWeight:600,color:"#fff",backgroundColor:"#f97316",borderRadius:"4px",padding:"1px 6px",whiteSpace:"nowrap",maxWidth:"90px",overflow:"hidden",textOverflow:"ellipsis"},children:t.currentTool.name})})}),c.jsx("foreignObject",{x:-60,y:v+(t.status==="tool_calling"&&t.currentTool?18:4),width:120,height:22,style:{pointerEvents:"none"},children:c.jsx("div",{style:{display:"flex",justifyContent:"center"},children:c.jsx("span",{title:t.name,style:{fontSize:"11px",fontWeight:500,color:E?"#cbd5e1":"#475569",backgroundColor:E?"rgba(30,41,59,0.7)":"rgba(255,255,255,0.75)",backdropFilter:"blur(6px)",borderRadius:"6px",padding:"1px 8px",whiteSpace:"nowrap",border:`1px solid ${E?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)"}`},children:L})})}),f&&c.jsx("foreignObject",{x:-80,y:-v-38,width:160,height:32,style:{pointerEvents:"none"},children:c.jsx("div",{style:{display:"flex",justifyContent:"center"},children:c.jsxs("span",{style:{fontSize:"11px",fontWeight:500,color:E?"#e2e8f0":"#374151",backgroundColor:E?"rgba(30,41,59,0.85)":"rgba(255,255,255,0.9)",backdropFilter:"blur(8px)",borderRadius:"8px",padding:"4px 10px",whiteSpace:"nowrap",boxShadow:E?"0 4px 8px rgba(0,0,0,0.3)":"0 4px 8px rgba(0,0,0,0.1)",border:`1px solid ${E?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}`},children:[t.name," · ",n(`agent.statusLabels.${t.status}`)]})})})]})});function yz({status:e,r:t,color:n,isWalking:r,isPlaceholder:s}){const o=r||s?{}:xz(e),u=r?"4 3":s?"6 3":void 0,f=r?"#3b82f6":n;return c.jsx("circle",{r:t,fill:"none",stroke:f,strokeWidth:rl.strokeWidth,strokeDasharray:u,style:{transition:"stroke 300ms ease",...o}})}function xz(e){switch(e){case"thinking":return{animation:"agent-pulse 1.5s ease-in-out infinite"};case"tool_calling":return{animation:"agent-pulse 2s ease-in-out infinite",strokeDasharray:"6 3"};case"speaking":return{animation:"agent-pulse 1s ease-in-out infinite"};case"error":return{animation:"agent-blink 0.8s ease-in-out infinite"};case"spawning":return{animation:"agent-spawn 0.5s ease-out forwards"};default:return{}}}function bz({r:e}){return c.jsx("g",{transform:`translate(${e*.55}, ${-e*.7})`,children:[0,1,2].map(t=>c.jsx("circle",{cx:t*5,cy:0,r:2,fill:"#3b82f6",style:{animation:`thinking-dots 1.2s ease-in-out ${t*.15}s infinite`}},t))})}function vz({r:e}){return c.jsxs("g",{transform:`translate(${e*.55}, ${-e*.75})`,children:[c.jsxs("circle",{r:7,fill:"#a855f7",opacity:.9,children:[c.jsx("animate",{attributeName:"r",values:"6;8;6",dur:"1.5s",repeatCount:"indefinite"}),c.jsx("animate",{attributeName:"opacity",values:"0.9;0.5;0.9",dur:"1.5s",repeatCount:"indefinite"})]}),c.jsx("g",{transform:"translate(-4.5,-4.5) scale(0.45)",children:c.jsx("path",{fill:"#fff",fillRule:"evenodd",d:"M3.43 2.524A41.29 41.29 0 0110 2c2.236 0 4.43.18 6.57.524 1.437.231 2.43 1.49 2.43 2.902v5.148c0 1.413-.993 2.67-2.43 2.902a41.102 41.102 0 01-3.55.414c-.28.02-.521.18-.643.413l-1.712 3.293a.75.75 0 01-1.33 0l-1.713-3.293a.783.783 0 00-.642-.413 41.108 41.108 0 01-3.55-.414C1.993 13.245 1 11.986 1 10.574V5.426c0-1.413.993-2.67 2.43-2.902z",clipRule:"evenodd"})})]})}function kz({data:e,size:t}){const n=t/2,r=e.faceShape==="round"?n*.8:e.faceShape==="oval"?n*.7:n*.75,s=e.faceShape==="oval"?n*.9:r;return c.jsxs("g",{children:[c.jsx("rect",{x:-n,y:n*.4,width:t,height:n*1.2,fill:e.shirtColor}),c.jsx("ellipse",{cx:0,cy:-n*.05,rx:r,ry:s,fill:e.skinColor}),c.jsx(wz,{style:e.hairStyle,color:e.hairColor,s:n,faceRx:r}),c.jsx(Sz,{style:e.eyeStyle,s:n})]})}function wz({style:e,color:t,s:n,faceRx:r}){switch(e){case"short":return c.jsx("ellipse",{cx:0,cy:-n*.55,rx:r*.95,ry:n*.45,fill:t});case"spiky":return c.jsxs("g",{children:[c.jsx("ellipse",{cx:0,cy:-n*.55,rx:r*.9,ry:n*.4,fill:t}),[-.4,-.15,.1,.35].map(s=>c.jsx("polygon",{points:`${s*n*2},-${n*.85} ${s*n*2-3},-${n*.5} ${s*n*2+3},-${n*.5}`,fill:t},s))]});case"side-part":return c.jsxs("g",{children:[c.jsx("ellipse",{cx:-n*.1,cy:-n*.55,rx:r,ry:n*.45,fill:t}),c.jsx("rect",{x:r*.3,y:-n*.9,width:r*.5,height:n*.3,rx:3,fill:t})]});case"curly":return c.jsx("g",{children:[[-.35,-.7],[0,-.78],[.35,-.7],[-.5,-.45],[.5,-.45]].map(([s,o],u)=>c.jsx("circle",{cx:s*n,cy:o*n,r:n*.22,fill:t},u))});case"buzz":return c.jsx("ellipse",{cx:0,cy:-n*.45,rx:r*.85,ry:n*.35,fill:t,opacity:.7});default:return null}}function Sz({style:e,s:t}){const n=-t*.08,r=t*.28;switch(e){case"dot":return c.jsxs("g",{children:[c.jsx("circle",{cx:-r,cy:n,r:2,fill:"#333"}),c.jsx("circle",{cx:r,cy:n,r:2,fill:"#333"})]});case"line":return c.jsxs("g",{children:[c.jsx("line",{x1:-r-3,y1:n,x2:-r+3,y2:n,stroke:"#333",strokeWidth:1.5,strokeLinecap:"round"}),c.jsx("line",{x1:r-3,y1:n,x2:r+3,y2:n,stroke:"#333",strokeWidth:1.5,strokeLinecap:"round"})]});case"wide":return c.jsxs("g",{children:[c.jsx("ellipse",{cx:-r,cy:n,rx:3,ry:2.5,fill:"#fff",stroke:"#333",strokeWidth:.8}),c.jsx("circle",{cx:-r,cy:n,r:1.2,fill:"#333"}),c.jsx("ellipse",{cx:r,cy:n,rx:3,ry:2.5,fill:"#fff",stroke:"#333",strokeWidth:.8}),c.jsx("circle",{cx:r,cy:n,r:1.2,fill:"#333"})]});default:return null}}function jz({x1:e,y1:t,x2:n,y2:r,strength:s}){const o=(e+n)/2,u=(t+r)/2,f=n-e,h=r-t,g=Math.sqrt(f*f+h*h),y=Math.min(g*.2,50),p=o-h/g*y,b=u+f/g*y,v=`M ${e} ${t} Q ${p} ${b} ${n} ${r}`,k=s>=.5,j=k?3:1.5,N=Math.max(.2,s);return c.jsxs("g",{children:[c.jsx("path",{d:v,fill:"none",stroke:"#60a5fa",strokeWidth:j+2,opacity:Math.max(.03,s*.15),style:{filter:"blur(3px)"}}),c.jsx("path",{d:v,fill:"none",stroke:"#60a5fa",strokeWidth:j,strokeDasharray:k?"12,6":"6,4",opacity:N,style:{animation:k?"connection-pulse 0.8s linear infinite":"dash-flow 1.5s linear infinite",filter:k?"drop-shadow(0 0 4px rgba(96,165,250,0.8))":void 0}})]})}const Cz=S.memo(function({x:t,y:n,isDark:r=!1}){const s=r?"#334155":"#dfe5ed",o=r?"#283548":"#c8d0dc",u=r?"#1e293b":"#f1f5f9",f=r?"#475569":"#94a3b8";return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx("rect",{x:-50,y:-6,width:100,height:60,rx:6,fill:s,stroke:o,strokeWidth:1}),c.jsx("path",{d:"M -50 54 L -50 60 Q -50 66 -44 66 L 44 66 Q 50 66 50 60 L 50 54",fill:o,opacity:.6}),c.jsx("rect",{x:-20,y:4,width:40,height:26,rx:3,fill:u,stroke:f,strokeWidth:.8}),c.jsx("rect",{x:-16,y:36,width:32,height:12,rx:2,fill:r?"#475569":"#cbd5e1",opacity:.6})]})}),hg=S.memo(function({x:t,y:n,isDark:r=!1}){const s=r?"#475569":"#94a3b8",o=r?"#334155":"#7c8ba0";return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx("path",{d:"M -12 -14 Q 0 -20 12 -14",fill:"none",stroke:o,strokeWidth:4,strokeLinecap:"round"}),c.jsx("circle",{r:14,fill:s,opacity:.85})]})}),Nz=S.memo(function({x:t,y:n,radius:r=80,isDark:s=!1}){const o=`mt-grad-${t}-${n}`,u=s?"#334155":"#bfcbda",f=s?"#3d4f66":"#dbe4ef";return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx("defs",{children:c.jsxs("radialGradient",{id:o,children:[c.jsx("stop",{offset:"0%",stopColor:f}),c.jsx("stop",{offset:"100%",stopColor:u})]})}),c.jsx("circle",{r,fill:`url(#${o})`,stroke:s?"#475569":"#94a3b8",strokeWidth:1.5,style:{filter:"drop-shadow(0 3px 6px rgba(0,0,0,0.10))"}})]})}),xc=S.memo(function({x:t,y:n,rotation:r=0,isDark:s=!1}){const o=s?"#475569":"#a5b4c8",u=s?"#334155":"#8494a7",f=s?"#5b6b80":"#c8d5e3";return c.jsxs("g",{transform:`translate(${t}, ${n}) rotate(${r})`,children:[c.jsx("rect",{x:-55,y:-22,width:110,height:44,rx:10,fill:u}),c.jsx("rect",{x:-48,y:-16,width:96,height:32,rx:6,fill:o}),c.jsx("circle",{cx:-30,cy:0,r:8,fill:f,opacity:.7}),c.jsx("circle",{cx:30,cy:0,r:8,fill:f,opacity:.7}),c.jsx("rect",{x:-52,y:-25,width:104,height:8,rx:4,fill:u,opacity:.7})]})}),bc=S.memo(function({x:t,y:n}){return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx("path",{d:"M -8 6 L -10 18 Q -10 22 -6 22 L 6 22 Q 10 22 10 18 L 8 6 Z",fill:"#a07050"}),c.jsx("ellipse",{cx:0,cy:-2,rx:12,ry:10,fill:"#4ade80",opacity:.85}),c.jsx("ellipse",{cx:-6,cy:-8,rx:8,ry:6,fill:"#22c55e",opacity:.7}),c.jsx("ellipse",{cx:6,cy:-6,rx:7,ry:5,fill:"#16a34a",opacity:.6})]})}),_v=S.memo(function({x:t,y:n}){return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx("ellipse",{cx:0,cy:4,rx:9,ry:3,fill:"#d1d5db",opacity:.5}),c.jsx("rect",{x:-5,y:-4,width:10,height:10,rx:2,fill:"#f5f5f4",stroke:"#d1d5db",strokeWidth:.6}),c.jsx("ellipse",{cx:0,cy:-2,rx:4,ry:1.5,fill:"#92400e",opacity:.7}),c.jsx("path",{d:"M 5 -1 Q 9 -1 9 3 Q 9 6 5 6",fill:"none",stroke:"#d1d5db",strokeWidth:1}),c.jsx("path",{d:"M -1 -7 Q 0 -10 1 -7",fill:"none",stroke:"#94a3b8",strokeWidth:.5,opacity:.4})]})}),Aw=S.memo(function({x:t,y:n,agent:r}){const s=ie(o=>o.theme)==="dark";return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx(Cz,{x:0,y:30,isDark:s}),c.jsx(hg,{x:0,y:-12,isDark:s}),r&&c.jsx(il,{agent:{...r,position:{x:0,y:-12}}})]})},(e,t)=>{var n,r,s,o;return e.x!==t.x||e.y!==t.y?!1:e.agent===null&&t.agent===null?!0:e.agent===null||t.agent===null?!1:e.agent.id===t.agent.id&&e.agent.status===t.agent.status&&e.agent.name===t.agent.name&&((n=e.agent.currentTool)==null?void 0:n.name)===((r=t.agent.currentTool)==null?void 0:r.name)&&e.agent.isSubAgent===t.agent.isSubAgent&&((s=e.agent.speechBubble)==null?void 0:s.text)===((o=t.agent.speechBubble)==null?void 0:o.text)});function Az({zone:e,zoneKey:t}){const{t:n}=se("common"),o=ie(u=>u.theme)==="dark"?"#64748b":"#94a3b8";return c.jsx("text",{x:e.x+14,y:e.y+22,fill:o,fontSize:11,fontWeight:600,fontFamily:"system-ui, sans-serif",letterSpacing:"0.05em",children:n(`zones.${t}`)})}function Ez(){const e=ie(E=>E.agents),t=ie(E=>E.links),n=ie(E=>E.theme),r=Array.from(e.values()),s=n==="dark",o=s?zg:Lg,u=S.useMemo(()=>r.filter(E=>E.zone==="desk"&&!E.isSubAgent&&!E.movement&&E.confirmed),[r]),f=S.useMemo(()=>r.filter(E=>E.zone==="hotDesk"&&!E.movement),[r]),h=S.useMemo(()=>r.filter(E=>E.zone==="lounge"&&!E.movement&&!E.isPlaceholder),[r]),g=S.useMemo(()=>r.filter(E=>E.zone==="meeting"&&!E.movement&&!E.isPlaceholder),[r]),y=S.useMemo(()=>r.filter(E=>E.movement!==null&&!E.isPlaceholder),[r]),p=S.useMemo(()=>r.filter(E=>E.zone==="corridor"&&!E.movement&&!E.isPlaceholder),[r]),b=ie(E=>E.maxSubAgents),v=S.useMemo(()=>hb(Me.desk,u.length,Math.max(u.length,4)),[u.length]),k=S.useMemo(()=>hb(Me.hotDesk,f.length,Math.max(f.length,b)),[f.length,b]),j={x:Me.meeting.x+Me.meeting.width/2,y:Me.meeting.y+Me.meeting.height/2},N=Math.min(60+g.length*8,Math.min(Me.meeting.width,Me.meeting.height)/2-40),C=S.useMemo(()=>IE(g.length,j,N+36),[g.length,j.x,j.y,N]);return c.jsx("div",{className:"relative h-full w-full bg-gray-100 dark:bg-gray-950",children:c.jsxs("svg",{viewBox:`0 0 ${Og} ${_g}`,className:"h-full w-full",preserveAspectRatio:"xMidYMid meet",children:[c.jsxs("defs",{children:[c.jsx("filter",{id:"building-shadow",x:"-3%",y:"-3%",width:"106%",height:"106%",children:c.jsx("feDropShadow",{dx:"0",dy:"3",stdDeviation:"6",floodOpacity:s?.5:.12})}),c.jsxs("pattern",{id:"corridor-tiles",width:"28",height:"28",patternUnits:"userSpaceOnUse",children:[c.jsx("rect",{width:"28",height:"28",fill:o.corridor}),c.jsx("rect",{x:"0.5",y:"0.5",width:"27",height:"27",fill:"none",stroke:s?"#1f2937":"#d5dbe3",strokeWidth:"0.3",rx:"1"})]}),c.jsxs("pattern",{id:"lounge-carpet",width:"6",height:"6",patternUnits:"userSpaceOnUse",children:[c.jsx("rect",{width:"6",height:"6",fill:o.lounge}),c.jsx("circle",{cx:"3",cy:"3",r:"0.5",fill:s?"#2d2540":"#e5e0ed",opacity:"0.4"})]})]}),c.jsx("rect",{x:ue.x,y:ue.y,width:ue.width,height:ue.height,rx:ue.cornerRadius,fill:o.corridor,stroke:o.wall,strokeWidth:ue.wallThickness,filter:"url(#building-shadow)"}),c.jsx(Tz,{isDark:s}),Object.entries(Me).map(([E,R])=>c.jsx("rect",{x:R.x,y:R.y,width:R.width,height:R.height,fill:E==="lounge"?"url(#lounge-carpet)":o[E]},`floor-${E}`)),c.jsx(Dz,{isDark:s}),c.jsx(Rz,{isDark:s}),Object.entries(Me).map(([E,R])=>c.jsx(Az,{zone:R,zoneKey:E},`label-${E}`)),c.jsx(Mz,{deskSlots:v,deskAgents:u}),c.jsx(Nz,{x:j.x,y:j.y,radius:N,isDark:s}),c.jsx(_z,{seats:C,meetingAgentCount:g.length,isDark:s}),c.jsx(Oz,{slots:k,agents:f}),c.jsx(Lz,{isDark:s}),h.map(E=>c.jsx(il,{agent:E},`lounge-${E.id}`)),c.jsx(zz,{isDark:s}),t.map(E=>{const R=e.get(E.sourceId),H=e.get(E.targetId);return!R||!H?null:c.jsx(jz,{x1:R.position.x,y1:R.position.y,x2:H.position.x,y2:H.position.y,strength:E.strength},`${E.sourceId}-${E.targetId}`)}),g.map((E,R)=>{const H=C[R];return H?c.jsx(il,{agent:{...E,position:H}},E.id):null}),p.map(E=>c.jsx(il,{agent:E},`corridor-${E.id}`)),y.map(E=>c.jsx(il,{agent:E},`walk-${E.id}`))]})})}function Tz({isDark:e}){const t=ue.corridorWidth,n=ue.x,r=ue.y+(ue.height-t)/2,s=ue.x+(ue.width-t)/2,o=ue.y;return c.jsxs("g",{children:[c.jsx("rect",{x:n,y:r,width:ue.width,height:t,fill:"url(#corridor-tiles)"}),c.jsx("rect",{x:s,y:o,width:t,height:ue.height,fill:"url(#corridor-tiles)"}),c.jsx("line",{x1:n,y1:r+t/2,x2:n+ue.width,y2:r+t/2,stroke:e?"#334155":"#c8d0dc",strokeWidth:.5,strokeDasharray:"8 6",opacity:.6}),c.jsx("line",{x1:s+t/2,y1:o,x2:s+t/2,y2:o+ue.height,stroke:e?"#334155":"#c8d0dc",strokeWidth:.5,strokeDasharray:"8 6",opacity:.6})]})}function Dz({isDark:e}){const t=e?"#475569":"#8b9bb0",n=e?"#334155":"#c8d0dc",r=4,s=ue.corridorWidth,o=ue.x+(ue.width-s)/2,u=ue.y+(ue.height-s)/2,f=[{x:o-r/2,y:ue.y,w:r,h:u-ue.y},{x:o-r/2,y:u+s,w:r,h:ue.y+ue.height-u-s},{x:o+s-r/2,y:ue.y,w:r,h:u-ue.y},{x:o+s-r/2,y:u+s,w:r,h:ue.y+ue.height-u-s},{x:ue.x,y:u-r/2,w:o-ue.x,h:r},{x:o+s,y:u-r/2,w:ue.x+ue.width-o-s,h:r},{x:ue.x,y:u+s-r/2,w:o-ue.x,h:r},{x:o+s,y:u+s-r/2,w:ue.x+ue.width-o-s,h:r}];return c.jsx("g",{children:f.map((h,g)=>c.jsx("rect",{x:h.x,y:h.y,width:h.w,height:h.h,fill:n,stroke:t,strokeWidth:.5},`wall-${g}`))})}function Rz({isDark:e}){const t=ue.corridorWidth,n=ue.x+(ue.width-t)/2,r=ue.y+(ue.height-t)/2,s=40,o=e?zg.corridor:Lg.corridor,u=e?"#64748b":"#94a3b8",f=[{cx:(ue.x+n)/2,cy:r,horizontal:!0},{cx:(n+t+ue.x+ue.width)/2,cy:r,horizontal:!0},{cx:(ue.x+n)/2,cy:r+t,horizontal:!0},{cx:(n+t+ue.x+ue.width)/2,cy:r+t,horizontal:!0},{cx:n,cy:(ue.y+r)/2,horizontal:!1},{cx:n+t,cy:(ue.y+r)/2,horizontal:!1},{cx:n,cy:(r+t+ue.y+ue.height)/2,horizontal:!1},{cx:n+t,cy:(r+t+ue.y+ue.height)/2,horizontal:!1}];return c.jsx("g",{children:f.map((h,g)=>{const y=s/2;return h.horizontal?c.jsxs("g",{children:[c.jsx("rect",{x:h.cx-y,y:h.cy-3,width:s,height:6,fill:o}),c.jsx("path",{d:`M ${h.cx-y} ${h.cy} A ${y} ${y} 0 0 1 ${h.cx+y} ${h.cy}`,fill:"none",stroke:u,strokeWidth:.8,strokeDasharray:"3 2",opacity:.5})]},`door-${g}`):c.jsxs("g",{children:[c.jsx("rect",{x:h.cx-3,y:h.cy-y,width:6,height:s,fill:o}),c.jsx("path",{d:`M ${h.cx} ${h.cy-y} A ${y} ${y} 0 0 1 ${h.cx} ${h.cy+y}`,fill:"none",stroke:u,strokeWidth:.8,strokeDasharray:"3 2",opacity:.5})]},`door-${g}`)})})}function Mz({deskSlots:e,deskAgents:t}){const n=S.useMemo(()=>{const r=new Map;for(const s of t){let o=0;for(let h=0;h<s.id.length;h++)o=(o<<5)-o+s.id.charCodeAt(h)|0;let f=Math.abs(o)%e.length;for(;r.has(f);)f=(f+1)%e.length;r.set(f,s)}return r},[t,e.length]);return c.jsx("g",{children:e.map((r,s)=>c.jsx(Aw,{x:r.unitX,y:r.unitY,agent:n.get(s)??null},`desk-${s}`))})}function Oz({slots:e,agents:t}){return c.jsx("g",{children:e.map((n,r)=>c.jsx(Aw,{x:n.unitX,y:n.unitY,agent:t[r]??null},`hotdesk-${r}`))})}function _z({seats:e,meetingAgentCount:t,isDark:n}){const r={x:Me.meeting.x+Me.meeting.width/2,y:Me.meeting.y+Me.meeting.height/2};if(t>0)return c.jsx("g",{children:e.map((u,f)=>c.jsx(hg,{x:u.x,y:u.y,isDark:n},`mc-${f}`))});const s=6,o=100;return c.jsx("g",{children:Array.from({length:s},(u,f)=>{const h=2*Math.PI*f/s-Math.PI/2;return c.jsx(hg,{x:Math.round(r.x+Math.cos(h)*o),y:Math.round(r.y+Math.sin(h)*o),isDark:n},`mc-empty-${f}`)})})}function Lz({isDark:e}){const t=Me.lounge,n=t.x+t.width/2,r=e?"#334155":"#5a6878",s=e?"#475569":"#8494a7",o=e?"#64748b":"#a5b4c8",u=e?"#94a3b8":"#ffffff",f=e?"#1e293b":"#3b4f6b",h=200,g=36,y=t.y+t.height*.52,p=160,b=24,v=y+g+14;return c.jsxs("g",{children:[c.jsx(xc,{x:t.x+100,y:t.y+60,rotation:0,isDark:e}),c.jsx(xc,{x:t.x+280,y:t.y+60,rotation:0,isDark:e}),c.jsx(xc,{x:t.x+100,y:t.y+140,rotation:180,isDark:e}),c.jsx(_v,{x:t.x+190,y:t.y+100}),c.jsx(_v,{x:t.x+100,y:t.y+100}),c.jsx(xc,{x:t.x+440,y:t.y+100,rotation:90,isDark:e}),c.jsx("rect",{x:n-h/2,y,width:h,height:g,rx:4,fill:f}),c.jsx("rect",{x:n-h/2,y,width:h,height:3,rx:1.5,fill:e?"#64748b":"#7a9bc0"}),c.jsx("text",{x:n,y:y+g/2+5,textAnchor:"middle",fill:u,fontSize:14,fontWeight:700,fontFamily:"system-ui, sans-serif",letterSpacing:"0.12em",children:"OpenClaw"}),c.jsx("rect",{x:n-p/2,y:v,width:p,height:b,rx:12,fill:s,stroke:r,strokeWidth:1}),c.jsx("rect",{x:n-p/2+4,y:v+3,width:p-8,height:b-6,rx:9,fill:o,opacity:.5}),c.jsx(bc,{x:n-h/2-30,y:y+g/2}),c.jsx(bc,{x:n+h/2+30,y:y+g/2}),c.jsx(bc,{x:t.x+40,y:t.y+t.height-50}),c.jsx(bc,{x:t.x+t.width-40,y:t.y+t.height-50})]})}function zz({isDark:e}){const t=Me.lounge,n=t.x+t.width/2,r=ue.y+ue.height,s=70,o=s/2,u=e?zg.lounge:Lg.lounge,f=e?"#64748b":"#8b9bb0",h=e?"#374151":"#b0a090",g=e?"#64748b":"#94a3b8";return c.jsxs("g",{children:[c.jsx("rect",{x:n-o-2,y:r-ue.wallThickness-1,width:s+4,height:ue.wallThickness+4,fill:u}),c.jsx("rect",{x:n-o-3,y:r-10,width:3,height:12,rx:1,fill:f}),c.jsx("rect",{x:n+o,y:r-10,width:3,height:12,rx:1,fill:f}),c.jsx("path",{d:`M ${n-o} ${r} A ${o} ${o} 0 0 0 ${n} ${r-o}`,fill:"none",stroke:f,strokeWidth:.8,strokeDasharray:"4 3",opacity:.5}),c.jsx("path",{d:`M ${n+o} ${r} A ${o} ${o} 0 0 1 ${n} ${r-o}`,fill:"none",stroke:f,strokeWidth:.8,strokeDasharray:"4 3",opacity:.5}),c.jsx("rect",{x:n-30,y:r-18,width:60,height:12,rx:3,fill:h,opacity:.5}),c.jsx("text",{x:n,y:r+14,textAnchor:"middle",fill:g,fontSize:9,fontWeight:600,fontFamily:"system-ui, sans-serif",letterSpacing:"0.15em",children:"ENTRANCE"})]})}function Yc(e,t){const n=e.agents;if(!n)return;const r=n.list;if(Array.isArray(r))return r.find(s=>s.id===t)}function Ew(e){return JSON.parse(JSON.stringify(e))}async function Iz(e,t,n,r){try{const s=await e.configGet(),o=s.config;if(!Yc(o,t))return{ok:!1,error:"agent_not_found"};const f=Ew(o),g=f.agents.list,y=g.findIndex(b=>b.id===t);if(y<0)return{ok:!1,error:"agent_not_found"};g[y]={...g[y],tools:n};const p=await e.configSet(JSON.stringify(f),r??s.hash);return p.ok?{ok:!0,restart:p.restart??void 0}:{ok:!1,error:p.error??"conflict"}}catch(s){return{ok:!1,error:String(s)}}}async function Hz(e,t,n,r){try{const s=await e.configGet(),o=s.config;if(!Yc(o,t))return{ok:!1,error:"agent_not_found"};const f=Ew(o),g=f.agents.list,y=g.findIndex(b=>b.id===t);if(y<0)return{ok:!1,error:"agent_not_found"};if(n===null){const{skills:b,...v}=g[y];g[y]=v}else g[y]={...g[y],skills:n};const p=await e.configSet(JSON.stringify(f),r??s.hash);return p.ok?{ok:!0,restart:p.restart??void 0}:{ok:!1,error:p.error??"conflict"}}catch(s){return{ok:!1,error:String(s)}}}const Bz=["feishu","dingtalk","telegram","discord","slack","whatsapp","signal","imessage","matrix","line","msteams","googlechat","mattermost","irc","nostr","nextcloud-talk","bluebubbles","synology-chat","zalo","zalouser","tlon"];function Uz(e,t){const n=e.trim(),r=`agent:${t}:`;if(!n.startsWith(r))return!1;const s=n.slice(r.length);return Bz.some(o=>s.startsWith(`${o}:`))}async function $z(e,t){const r=(await e.sessionsList()).map(s=>s.key).filter(s=>Uz(s,t));for(const s of r)await e.sessionsDelete(s);return r.length}const Lv={agentTools:[],agentToolsLoading:!1,agentToolsConfig:null,configHash:null,agentSkills:[],agentSkillsLoading:!1,agentSkillsAllowlist:null,agentChannels:[],agentChannelsLoading:!1,agentCronJobs:[],agentCronJobsLoading:!1,cronDialogOpen:!1,cronEditingTask:null},On=Mn((e,t)=>({agents:[],defaultAgentId:"",selectedAgentId:null,activeTab:"overview",isLoading:!1,error:null,searchQuery:"",files:[],filesLoading:!1,selectedFileName:null,fileContent:null,originalFileContent:null,isFileDirty:!1,fileSaving:!1,createDialogOpen:!1,deleteDialogOpen:!1,systemModels:[],agentModelConfigs:{},...Lv,fetchSystemModels:async()=>{var n;try{await Pe();const r=Oe(),[s,o]=await Promise.all([r.configGet(),r.modelsList().catch(()=>[])]),u=s.config,f=new Set,h=[],g=new Map;for(const k of o){const j=`${k.provider}/${k.id}`;f.has(j)||(f.add(j),h.push({id:j,label:k.name??k.id,provider:k.provider}),g.has(k.provider)||g.set(k.provider,[]),g.get(k.provider).push(k))}const y=u==null?void 0:u.models,p=y==null?void 0:y.providers;if(p)for(const[k,j]of Object.entries(p)){const N=j.models;if(N)for(const C of N){const E=`${k}/${C.id}`;f.has(E)||(f.add(E),h.push({id:E,label:C.name??C.id,provider:k}))}}const b={},v=(n=u==null?void 0:u.agents)==null?void 0:n.list;if(v)for(const k of v){const j=k.id;if(!j)continue;const N=k.model;if(typeof N=="string")b[j]={primary:N,fallbacks:[]};else if(N&&typeof N=="object"&&!Array.isArray(N)){const C=N;b[j]={primary:C.primary??"",fallbacks:C.fallbacks??[]}}}e({systemModels:h,agentModelConfigs:b})}catch{}},fetchAgents:async()=>{e({isLoading:!0,error:null});try{await Pe();const n=await Oe().agentsList(),r=n.agents.map(u=>({...u,default:u.id===n.defaultId})),{selectedAgentId:s}=t(),o=s??n.defaultId;e({agents:r,defaultAgentId:n.defaultId,selectedAgentId:o,isLoading:!1})}catch(n){e({error:String(n),isLoading:!1})}},selectAgent:n=>{e({selectedAgentId:n,activeTab:"overview",files:[],selectedFileName:null,fileContent:null,originalFileContent:null,isFileDirty:!1,...Lv})},setActiveTab:n=>e({activeTab:n}),setSearchQuery:n=>e({searchQuery:n}),fetchFiles:async n=>{e({filesLoading:!0,files:[]});try{await Pe();const r=await Oe().agentsFilesList(n);e({files:r.files,filesLoading:!1})}catch{e({filesLoading:!1})}},fetchFileContent:async(n,r)=>{e({selectedFileName:r,fileContent:null,originalFileContent:null,isFileDirty:!1});try{await Pe();const s=await Oe().agentsFilesGet(n,r);e({fileContent:s.file.content,originalFileContent:s.file.content,isFileDirty:!1})}catch{e({fileContent:"",originalFileContent:""})}},setFileContent:n=>{const{originalFileContent:r}=t();e({fileContent:n,isFileDirty:n!==r})},resetFileContent:()=>{const{originalFileContent:n}=t();e({fileContent:n,isFileDirty:!1})},saveFileContent:async(n,r,s)=>{e({fileSaving:!0});try{return await Pe(),await Oe().agentsFilesSet(n,r,s),e({fileSaving:!1,originalFileContent:s,isFileDirty:!1}),!0}catch{return e({fileSaving:!1}),!1}},createAgent:async n=>{try{await Pe();const r=await Oe().agentsCreate(n);return r.ok?(await t().fetchAgents(),r.agentId):null}catch{return null}},updateAgentModel:async(n,r)=>{try{await Pe();const s=Oe(),o=await s.agentsUpdate({agentId:n,model:r});if(o.ok){let u="configLifecycle.runtimeAgentModel";try{await $z(s,n)>0&&(u="configLifecycle.runtimeAgentModelSessionsReset")}catch{}Ee.getState().setRuntimeApplied(u)}return o.ok}catch{return!1}},deleteAgent:async(n,r)=>{try{return await Pe(),(await Oe().agentsDelete({agentId:n,deleteFiles:r})).ok?(e({selectedAgentId:null}),await t().fetchAgents(),!0):!1}catch{return!1}},setCreateDialogOpen:n=>e({createDialogOpen:n}),setDeleteDialogOpen:n=>e({deleteDialogOpen:n}),fetchAgentTools:async n=>{e({agentToolsLoading:!0});try{await Pe();const r=Oe(),[s,o]=await Promise.all([r.toolsCatalog(n),r.configGet()]),u=Yc(o.config,n),f=u==null?void 0:u.tools;e({agentTools:s.tools,agentToolsConfig:f??null,configHash:o.hash??null,agentToolsLoading:!1})}catch{e({agentToolsLoading:!1})}},saveAgentToolsConfig:async(n,r)=>{try{await Pe();const s=Oe(),{configHash:o}=t(),u=await Iz(s,n,r,o??void 0);if(u.ok){const f=await s.configGet();e({agentToolsConfig:r,configHash:f.hash??null}),Ee.getState().setLifecycleFromWriteResult({...u,config:f.config},"save")}return u}catch{return{ok:!1,error:"unknown"}}},fetchAgentSkills:async n=>{e({agentSkillsLoading:!0});try{await Pe();const r=Oe(),[s,o]=await Promise.all([r.skillsStatus(n),r.configGet()]),u=Yc(o.config,n),f=(u==null?void 0:u.skills)??null;e({agentSkills:s,agentSkillsAllowlist:f,configHash:o.hash??null,agentSkillsLoading:!1})}catch{e({agentSkillsLoading:!1})}},saveAgentSkillsAllowlist:async(n,r)=>{try{await Pe();const s=Oe(),{configHash:o}=t(),u=await Hz(s,n,r,o??void 0);if(u.ok){const f=await s.configGet();e({agentSkillsAllowlist:r,configHash:f.hash??null}),Ee.getState().setLifecycleFromWriteResult({...u,config:f.config},"save")}return u}catch{return{ok:!1,error:"unknown"}}},fetchAgentChannels:async()=>{e({agentChannelsLoading:!0});try{await Pe();const n=await Oe().channelsStatus();e({agentChannels:n,agentChannelsLoading:!1})}catch{e({agentChannelsLoading:!1})}},fetchAgentCronJobs:async n=>{e({agentCronJobsLoading:!0});try{await Pe();const r=await Oe().cronList();e({agentCronJobs:r.filter(s=>s.agentId===n),agentCronJobsLoading:!1})}catch{e({agentCronJobsLoading:!1})}},addAgentCronJob:async(n,r)=>{await Pe();const s=await Oe().cronAdd({...r,agentId:n});e(o=>({agentCronJobs:[...o.agentCronJobs,s]})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")},updateAgentCronJob:async(n,r)=>{await Pe();const s=await Oe().cronUpdate(n,r);e(o=>({agentCronJobs:o.agentCronJobs.map(u=>u.id===n?s:u)})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")},removeAgentCronJob:async n=>{await Pe(),await Oe().cronRemove(n),e(r=>({agentCronJobs:r.agentCronJobs.filter(s=>s.id!==n)})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")},runAgentCronJob:async n=>{await Pe(),await Oe().cronRun(n),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")},toggleAgentCronJob:async(n,r)=>{await Pe();const s=await Oe().cronUpdate(n,{enabled:r});e(o=>({agentCronJobs:o.agentCronJobs.map(u=>u.id===n?s:u)})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")},openAgentCronDialog:n=>{e({cronDialogOpen:!0,cronEditingTask:n??null})},closeAgentCronDialog:()=>{e({cronDialogOpen:!1,cronEditingTask:null})}}));function qz({agent:e}){var f,h,g;const{t}=se("console"),n=On(y=>y.defaultAgentId),r=((f=e.identity)==null?void 0:f.name)??e.name??e.id,s=(h=e.identity)==null?void 0:h.emoji,o=(g=e.identity)==null?void 0:g.avatarUrl,u=e.id===n;return c.jsxs("div",{className:"flex items-start gap-4 rounded-2xl border border-gray-200 bg-white p-5 dark:border-gray-700 dark:bg-gray-900",children:[c.jsx("div",{className:"flex h-14 w-14 shrink-0 items-center justify-center rounded-xl bg-gray-100 text-2xl dark:bg-gray-800",children:o?c.jsx("img",{src:o,alt:r,className:"h-14 w-14 rounded-xl object-cover"}):c.jsx("span",{children:s??r.charAt(0).toLowerCase()})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-gray-100",children:r})}),c.jsx("p",{className:"mt-0.5 text-sm text-gray-500 dark:text-gray-400",children:t("agents.detailDescription",{id:e.id})})]}),c.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-1",children:[c.jsx("span",{className:"text-sm font-mono text-gray-500 dark:text-gray-400",children:e.id}),u&&c.jsx("span",{className:"rounded-md bg-gray-200 px-2 py-0.5 text-xs font-semibold uppercase text-gray-600 dark:bg-gray-700 dark:text-gray-300",children:t("agents.defaultBadge")})]})]})}const Kz={connected:"bg-green-500",disconnected:"bg-gray-400",connecting:"bg-yellow-500",error:"bg-red-500"},Pz={telegram:"TG",discord:"DC",whatsapp:"WA",signal:"SG",feishu:"FS",imessage:"iM",matrix:"MX",line:"LN",msteams:"MS",googlechat:"GC",mattermost:"MM"};function Fz({agent:e}){const{t}=se("console"),{agentChannels:n,agentChannelsLoading:r,fetchAgentChannels:s}=On();S.useEffect(()=>{s()},[e.id,s]);const o=n??[];return r?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-5 w-5 animate-spin text-gray-400"})}):c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.channels.title")}),c.jsx("button",{onClick:()=>s(),className:"rounded p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300",title:t("agents.refresh"),children:c.jsx(Rn,{className:"h-4 w-4"})})]}),c.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-blue-200 bg-blue-50 px-4 py-3 dark:border-blue-800 dark:bg-blue-900/20",children:[c.jsx(ru,{className:"mt-0.5 h-4 w-4 shrink-0 text-blue-600 dark:text-blue-400"}),c.jsx("p",{className:"text-xs text-blue-700 dark:text-blue-300",children:t("agents.channels.gatewayInfo")})]}),o.length===0?c.jsxs("div",{className:"py-8 text-center",children:[c.jsx(Tl,{className:"mx-auto mb-2 h-8 w-8 text-gray-300 dark:text-gray-600"}),c.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500",children:t("agents.channels.noBindings")})]}):c.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:o.map(u=>c.jsx(Gz,{channel:u},u.id))})]})}function Gz({channel:e}){const{t}=se("console"),n=Pz[e.type]??e.type.slice(0,2).toUpperCase(),r=Kz[e.status]??"bg-gray-400",s=t(`agents.channels.${e.status}`);return c.jsx("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-gray-100 text-sm font-bold text-gray-600 dark:bg-gray-700 dark:text-gray-300",children:n}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{className:"truncate text-sm font-medium text-gray-900 dark:text-gray-100",children:e.name||e.type})}),c.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[c.jsx("span",{className:`inline-block h-2 w-2 rounded-full ${r}`}),c.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:s}),e.configured&&c.jsx("span",{className:"rounded bg-green-100 px-1.5 py-0.5 text-[10px] font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:t("agents.channels.configured")})]}),e.error&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:e.error})]})]})})}function Vz(e){const t=Yz(e.schedule),n=e.payload.kind==="agentTurn"?e.payload.message:e.payload.kind==="systemEvent"?e.payload.text:"";return{id:e.id,name:e.name,schedule:t,scheduleLabel:Qz(t),enabled:e.enabled,lastRunAt:e.state.lastRunAtMs??null,nextRunAt:e.state.nextRunAtMs??null,lastRunStatus:e.state.lastRunStatus??null,message:n,statusLabel:e.enabled?we.t("console:viewModels.taskStatus.active"):we.t("console:viewModels.taskStatus.paused")}}function Yz(e){return e.kind==="cron"&&e.expr?e.expr:e.kind==="every"&&e.everyMs?we.t("console:viewModels.schedule.every",{minutes:Math.round(e.everyMs/6e4)}):e.kind==="at"&&e.at?we.t("console:viewModels.schedule.at",{time:e.at}):we.t("console:viewModels.schedule.unknown")}function Qz(e){const t=e.split(" ");if(t.length!==5)return e;const[n,r,s,o,u]=t;return s==="*"&&u==="*"&&r!=="*"&&n!=="*"?we.t("console:viewModels.schedule.daily",{time:`${r}:${n.padStart(2,"0")}`}):u!=="*"&&s==="*"?we.t("console:viewModels.schedule.weekly",{day:u,time:`${r}:${n.padStart(2,"0")}`}):e}const Wz={ok:c.jsx(Tr,{className:"h-3.5 w-3.5 text-green-500"}),error:c.jsx(tu,{className:"h-3.5 w-3.5 text-red-500"}),skipped:c.jsx(S4,{className:"h-3.5 w-3.5 text-gray-400"})};function Tw({task:e,onToggle:t,onRun:n,onEdit:r,onDelete:s}){const{t:o}=se("console"),u=Vz(e),f=e.payload.kind==="agentTurn"?e.payload.message:e.payload.kind==="systemEvent"?e.payload.text:"",h=u.lastRunAt?new Date(u.lastRunAt).toLocaleString():"—",g=u.nextRunAt?new Date(u.nextRunAt).toLocaleString():"—";return c.jsx("div",{className:`rounded-lg border border-gray-200 bg-white p-4 transition-opacity dark:border-gray-700 dark:bg-gray-800 ${e.enabled?"":"opacity-60"}`,children:c.jsxs("div",{className:"flex items-start justify-between gap-4",children:[c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsxs("label",{className:"relative mt-0.5 inline-flex cursor-pointer items-center",children:[c.jsx("input",{type:"checkbox",checked:e.enabled,onChange:()=>t(e.id,!e.enabled),className:"peer sr-only"}),c.jsx("div",{className:"peer h-5 w-9 rounded-full bg-gray-200 after:absolute after:left-[2px] after:top-[2px] after:h-4 after:w-4 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:bg-blue-600 peer-checked:after:translate-x-full peer-checked:after:border-white dark:bg-gray-700 dark:peer-checked:bg-blue-500"})]}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"font-medium text-gray-900 dark:text-gray-100",children:e.name}),c.jsx("span",{className:"rounded bg-gray-100 px-1.5 py-0.5 text-[10px] text-gray-500 dark:bg-gray-700 dark:text-gray-400",children:u.scheduleLabel})]}),f&&c.jsx("p",{className:"mt-1 line-clamp-1 text-sm text-gray-500 dark:text-gray-400",children:f}),c.jsxs("div",{className:"mt-2 flex items-center gap-4 text-xs text-gray-400 dark:text-gray-500",children:[c.jsxs("span",{className:"flex items-center gap-1",children:[o("cron.card.lastRun"),": ",h,e.state.lastRunStatus&&c.jsx("span",{className:"ml-1",children:Wz[e.state.lastRunStatus]??null})]}),c.jsxs("span",{children:[o("cron.card.nextRun"),": ",g]})]}),e.state.lastError&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:e.state.lastError})]})]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("button",{type:"button",onClick:()=>n(e.id),className:"rounded p-1.5 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300 transition-colors",title:o("cron.card.runNow"),children:c.jsx(M4,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>r(e),className:"rounded p-1.5 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300 transition-colors",title:o("common:actions.edit"),children:c.jsx(M1,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>s(e.id),className:"rounded p-1.5 text-gray-400 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20 dark:hover:text-red-400 transition-colors",title:o("common:actions.delete"),children:c.jsx(Dl,{className:"h-4 w-4"})})]})]})})}const zv=[{labelKey:"console:cron.presets.everyHour",schedule:{kind:"cron",expr:"0 * * * *"}},{labelKey:"console:cron.presets.daily9am",schedule:{kind:"cron",expr:"0 9 * * *"}},{labelKey:"console:cron.presets.daily6pm",schedule:{kind:"cron",expr:"0 18 * * *"}},{labelKey:"console:cron.presets.weeklyMon",schedule:{kind:"cron",expr:"0 9 * * 1"}},{labelKey:"console:cron.presets.monthlyFirst",schedule:{kind:"cron",expr:"0 9 1 * *"}},{labelKey:"console:cron.presets.every30min",schedule:{kind:"every",everyMs:18e5}}];function Iv(e){return e.kind==="cron"?e.expr:e.kind==="every"?`every ${Math.round(e.everyMs/6e4)}m`:e.kind==="at"?`at ${e.at}`:""}function Xz(e){const t=e.payloadKind??"agentTurn",n=t==="systemEvent"?{kind:"systemEvent",text:e.message.trim()}:{kind:"agentTurn",message:e.message.trim()};return{name:e.name.trim(),description:e.description.trim()||void 0,schedule:e.schedule,sessionTarget:t==="systemEvent"?"main":"isolated",wakeMode:"now",payload:n}}function Dw({open:e,editingTask:t,onSave:n,onUpdate:r,onClose:s}){const{t:o}=se("console"),u=S.useRef(null),[f,h]=S.useState(""),[g,y]=S.useState(""),[p,b]=S.useState({kind:"cron",expr:"0 18 * * *"}),[v,k]=S.useState("0 18 * * *"),[j,N]=S.useState(""),[C,E]=S.useState(null),[R,H]=S.useState({});S.useEffect(()=>{const W=u.current;W&&(e&&!W.open?(t?(h(t.name),y(t.description??""),b(t.schedule),k(Iv(t.schedule)),N(t.payload.kind==="agentTurn"?t.payload.message:t.payload.kind==="systemEvent"?t.payload.text:""),E(null)):(h(""),y(""),b({kind:"cron",expr:"0 18 * * *"}),k("0 18 * * *"),N(""),E(null)),H({}),W.showModal()):!e&&W.open&&W.close())},[e,t]);const z=W=>{const P=zv[W];E(W),b(P.schedule),k(Iv(P.schedule))},L=W=>{k(W),E(null),b({kind:"cron",expr:W})},G=()=>{const W={};if(f.trim()||(W.name=!0),j.trim()||(W.message=!0),v.trim()||(W.cronExpr=!0),H(W),Object.keys(W).length>0)return;const P=Xz({name:f,description:g,schedule:p,message:j,payloadKind:(t==null?void 0:t.payload.kind)==="systemEvent"?"systemEvent":"agentTurn"});t?r(t.id,P):n(P)};return c.jsx("dialog",{ref:u,onClose:s,className:"fixed inset-0 z-50 m-auto max-w-lg rounded-lg border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"max-h-[80vh] overflow-y-auto p-6",children:[c.jsx("h3",{className:"mb-4 text-lg font-semibold text-gray-900 dark:text-gray-100",children:o(t?"cron.dialog.editTitle":"cron.dialog.createTitle")}),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:[o("cron.dialog.name")," ",c.jsx("span",{className:"text-red-500",children:"*"})]}),c.jsx("input",{type:"text",value:f,onChange:W=>h(W.target.value),placeholder:o("cron.dialog.namePlaceholder"),className:`w-full rounded-md border bg-white px-3 py-2 text-sm dark:bg-gray-700 dark:text-gray-100 ${R.name?"border-red-500":"border-gray-300 dark:border-gray-600"}`}),R.name&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:o("cron.dialog.required")})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:o("cron.dialog.description")}),c.jsx("input",{type:"text",value:g,onChange:W=>y(W.target.value),placeholder:o("cron.dialog.descriptionPlaceholder"),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300",children:o("cron.dialog.schedule")}),c.jsx("div",{className:"mb-3 flex flex-wrap gap-2",children:zv.map((W,P)=>c.jsx("button",{type:"button",onClick:()=>z(P),className:`rounded-md border px-3 py-1.5 text-xs font-medium transition-colors ${C===P?"border-blue-500 bg-blue-50 text-blue-700 dark:border-blue-400 dark:bg-blue-900/20 dark:text-blue-400":"border-gray-300 text-gray-600 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700"}`,children:o(W.labelKey)},P))}),c.jsx("input",{type:"text",value:v,onChange:W=>L(W.target.value),placeholder:"0 * * * *",className:`w-full rounded-md border bg-white px-3 py-2 text-sm font-mono dark:bg-gray-700 dark:text-gray-100 ${R.cronExpr?"border-red-500":"border-gray-300 dark:border-gray-600"}`}),c.jsx("p",{className:"mt-1 text-xs text-gray-400",children:o("cron.dialog.cronHelp")})]}),c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:[o("cron.dialog.message")," ",c.jsx("span",{className:"text-red-500",children:"*"})]}),c.jsx("textarea",{value:j,onChange:W=>N(W.target.value),placeholder:o("cron.dialog.messagePlaceholder"),rows:3,className:`w-full rounded-md border bg-white px-3 py-2 text-sm dark:bg-gray-700 dark:text-gray-100 ${R.message?"border-red-500":"border-gray-300 dark:border-gray-600"}`}),R.message&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:o("cron.dialog.required")})]})]}),c.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:s,className:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:o("common:actions.cancel")}),c.jsx("button",{type:"button",onClick:G,className:"rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:o(t?"common:actions.save":"common:actions.create")})]})]})})}function Zz({agent:e}){const{t}=se("console"),{agentCronJobs:n,agentCronJobsLoading:r,cronDialogOpen:s,cronEditingTask:o,fetchAgentCronJobs:u,addAgentCronJob:f,updateAgentCronJob:h,removeAgentCronJob:g,runAgentCronJob:y,toggleAgentCronJob:p,openAgentCronDialog:b,closeAgentCronDialog:v}=On();S.useEffect(()=>{u(e.id)},[e.id,u]);const k=n??[],j=k.length,N=k.filter(H=>H.enabled).length,C=k.filter(H=>H.state.lastRunStatus==="error").length,E=H=>{f(e.id,H)},R=(H,z)=>{h(H,z)};return r?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-5 w-5 animate-spin text-gray-400"})}):c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.cronJobs.title")}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{onClick:()=>b(),className:"flex items-center gap-1 rounded-lg bg-blue-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-blue-700",children:[c.jsx(En,{className:"h-3.5 w-3.5"}),t("agents.cronJobs.addTask")]}),c.jsx("button",{onClick:()=>u(e.id),className:"rounded p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300",title:t("agents.refresh"),children:c.jsx(Rn,{className:"h-4 w-4"})})]})]}),c.jsxs("div",{className:"flex gap-4",children:[c.jsx(Ah,{label:t("agents.cronJobs.total"),value:j}),c.jsx(Ah,{label:t("agents.cronJobs.enabled"),value:N,color:"green"}),c.jsx(Ah,{label:t("agents.cronJobs.errors"),value:C,color:"red"})]}),k.length===0?c.jsxs("div",{className:"py-8 text-center",children:[c.jsx(Ki,{className:"mx-auto mb-2 h-8 w-8 text-gray-300 dark:text-gray-600"}),c.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500",children:t("agents.cronJobs.noCronJobs")}),c.jsx("button",{onClick:()=>b(),className:"mt-2 text-xs text-blue-600 hover:text-blue-700 dark:text-blue-400",children:t("cron.empty.createFirst")})]}):c.jsx("div",{className:"space-y-2",children:k.map(H=>c.jsx(Tw,{task:H,onToggle:(z,L)=>p(z,L),onRun:z=>y(z),onEdit:z=>b(z),onDelete:z=>g(z)},H.id))}),c.jsx(Dw,{open:s,editingTask:o,onSave:E,onUpdate:R,onClose:v})]})}function Ah({label:e,value:t,color:n}){const r=n==="green"?"text-green-600 dark:text-green-400":n==="red"?"text-red-600 dark:text-red-400":"text-gray-900 dark:text-gray-100";return c.jsxs("div",{className:"rounded-lg border border-gray-200 px-3 py-2 dark:border-gray-700",children:[c.jsx("div",{className:`text-lg font-semibold ${r}`,children:t}),c.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:e})]})}function Jz(e){return e<1024?`${e} B`:`${(e/1024).toFixed(1)} KB`}function e9(e,t){const n=typeof e=="number"?e:new Date(e).getTime();if(Number.isNaN(n)||n===0)return"—";const r=Date.now()-n;if(r<0)return t("agents.files.justNow");const s=Math.floor(r/36e5);if(s<1)return t("agents.files.justNow");if(s<24)return t("agents.files.hoursAgo",{count:s});const o=Math.floor(s/24);return t("agents.files.daysAgo",{count:o})}function t9({agent:e}){const{t}=se("console"),{files:n,filesLoading:r,selectedFileName:s,fileContent:o,isFileDirty:u,fileSaving:f,fetchFiles:h,fetchFileContent:g,setFileContent:y,resetFileContent:p,saveFileContent:b}=On();S.useEffect(()=>{h(e.id)},[e.id,h]);const v=n.find(j=>j.name===s),k=async()=>{s&&o!=null&&await b(e.id,s,o)};return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.files.title")}),c.jsx("p",{className:"mt-0.5 text-xs text-gray-500 dark:text-gray-400",children:t("agents.files.description")})]}),c.jsx("button",{onClick:()=>h(e.id),disabled:r,className:"rounded-md p-1.5 text-gray-500 transition-colors hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-800",children:c.jsx(Rn,{className:`h-4 w-4 ${r?"animate-spin":""}`})})]}),c.jsxs("div",{className:"flex gap-4",children:[c.jsx("div",{className:"w-56 shrink-0 space-y-2",children:n.map(j=>c.jsxs("button",{onClick:()=>g(e.id,j.name),className:`w-full rounded-xl border px-3 py-2.5 text-left transition-colors ${s===j.name?"border-red-400 bg-red-50 dark:border-red-600 dark:bg-red-900/20":"border-gray-200 hover:border-gray-300 hover:bg-gray-50 dark:border-gray-700 dark:hover:border-gray-600 dark:hover:bg-gray-800"}`,children:[c.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:j.name}),c.jsxs("p",{className:"mt-0.5 text-xs text-gray-500 dark:text-gray-400",children:[Jz(j.size)," · ",e9(j.modifiedAt,t)]})]},j.name))}),c.jsx("div",{className:"min-w-0 flex-1",children:v&&o!=null?c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{children:c.jsx("h4",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:v.name})}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{onClick:p,disabled:!u,className:"rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-800",children:t("agents.files.reset")}),c.jsx("button",{onClick:k,disabled:!u||f,className:"rounded-md bg-red-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-red-600 disabled:opacity-50",children:t(f?"agents.files.saving":"agents.files.save")})]})]}),c.jsxs("div",{children:[c.jsx("p",{className:"mb-1 text-xs font-medium text-gray-500 dark:text-gray-400",children:t("agents.files.content")}),c.jsx("textarea",{value:o,onChange:j=>y(j.target.value),className:"h-80 w-full resize-y rounded-lg border border-gray-200 bg-gray-50 p-3 font-mono text-xs text-gray-900 focus:border-blue-500 focus:outline-none dark:border-gray-700 dark:bg-gray-800 dark:text-gray-200"})]})]}):c.jsx("div",{className:"flex h-64 items-center justify-center text-sm text-gray-400 dark:text-gray-500",children:t("agents.files.selectFile")})})]})]})}function n9({agent:e}){var L;const{t}=se("console"),{defaultAgentId:n,updateAgentModel:r,setDeleteDialogOpen:s,systemModels:o,fetchSystemModels:u,agentModelConfigs:f}=On(),h=e.id===n,g=f[e.id],[y,p]=S.useState((g==null?void 0:g.primary)??""),[b,v]=S.useState((g==null?void 0:g.fallbacks)??[]),[k,j]=S.useState(!1),[N,C]=S.useState("idle");S.useEffect(()=>{o.length===0&&u()},[o.length,u]),S.useEffect(()=>{const G=f[e.id];p((G==null?void 0:G.primary)??""),v((G==null?void 0:G.fallbacks)??[]),C("idle")},[e.id,f]);const E=async()=>{j(!0),C("idle");const G=b.filter(M=>M.length>0),W=G.length>0?{primary:y||void 0,fallbacks:G}:y||"",P=await r(e.id,W);j(!1),C(P?"success":"error"),P&&(await u(),setTimeout(()=>C("idle"),2e3))},R=()=>v([...b,""]),H=G=>v(b.filter((W,P)=>P!==G)),z=(G,W)=>{const P=[...b];P[G]=W,v(P)};return c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{children:[c.jsx("h3",{className:"mb-3 text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.overview.title")}),c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsx(Eh,{label:t("agents.overview.agentId"),value:e.id,mono:!0}),c.jsx(Eh,{label:t("agents.overview.name"),value:((L=e.identity)==null?void 0:L.name)??e.name??e.id}),c.jsx(Eh,{label:t("agents.overview.isDefault"),value:t(h?"agents.overview.yes":"agents.overview.no")})]})]}),c.jsxs("div",{className:"border-t border-gray-200 pt-5 dark:border-gray-700",children:[c.jsx("h3",{className:"mb-3 text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.overview.modelConfig")}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-xs font-medium text-gray-600 dark:text-gray-400",children:t("agents.overview.primaryModel")}),c.jsx(Hv,{value:y,onChange:p,models:o,placeholder:t("agents.overview.primaryModelPlaceholder")})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-xs font-medium text-gray-600 dark:text-gray-400",children:t("agents.overview.fallbackModels")}),b.map((G,W)=>c.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[c.jsx(Hv,{value:G,onChange:P=>z(W,P),models:o,placeholder:t("agents.overview.fallbackPlaceholder")}),c.jsx("button",{onClick:()=>H(W),className:"shrink-0 rounded-md p-1.5 text-gray-400 hover:bg-gray-100 hover:text-red-500 dark:hover:bg-gray-800",children:c.jsx(An,{className:"h-4 w-4"})})]},W)),c.jsxs("button",{onClick:R,className:"flex items-center gap-1 text-xs text-blue-600 hover:text-blue-700 dark:text-blue-400",children:[c.jsx(En,{className:"h-3 w-3"}),t("agents.overview.addFallback")]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{onClick:E,disabled:k,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50",children:t(k?"agents.overview.saving":"agents.overview.save")}),N==="success"&&c.jsx("span",{className:"text-xs text-green-600",children:t("agents.overview.saveSuccess")}),N==="error"&&c.jsx("span",{className:"text-xs text-red-600",children:t("agents.overview.saveError")})]}),c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:t("agents.overview.runtimeHint")})]})]}),c.jsxs("div",{className:"border-t border-gray-200 pt-5 dark:border-gray-700",children:[c.jsxs("button",{onClick:()=>s(!0),disabled:h,className:"flex items-center gap-2 rounded-lg border border-red-200 px-4 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-50 disabled:cursor-not-allowed disabled:opacity-50 dark:border-red-800 dark:text-red-400 dark:hover:bg-red-900/20",title:h?t("agents.overview.cannotDeleteDefault"):void 0,children:[c.jsx(Dl,{className:"h-4 w-4"}),t("agents.overview.deleteAgent")]}),h&&c.jsx("p",{className:"mt-1 text-xs text-gray-400",children:t("agents.overview.cannotDeleteDefault")})]})]})}function Eh({label:e,value:t,mono:n}){return c.jsxs("div",{children:[c.jsx("dt",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:e}),c.jsx("dd",{className:`mt-0.5 text-sm text-gray-900 dark:text-gray-100 ${n?"font-mono":""}`,children:t})]})}function Hv({value:e,onChange:t,models:n,placeholder:r}){const s=[...new Set(n.map(u=>u.provider))],o=n.some(u=>u.id===e);return c.jsxs("div",{className:"relative w-full",children:[c.jsxs("select",{value:o?e:"",onChange:u=>t(u.target.value),className:"w-full appearance-none rounded-lg border border-gray-300 bg-white px-3 py-2 pr-8 text-sm text-gray-900 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200",children:[c.jsx("option",{value:"",children:r}),!o&&e&&c.jsx("option",{value:e,children:e}),s.map(u=>c.jsx("optgroup",{label:u,children:n.filter(f=>f.provider===u).map(f=>c.jsxs("option",{value:f.id,children:[f.label," (",f.id,")"]},f.id))},u))]}),c.jsx(qn,{className:"pointer-events-none absolute right-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"})]})}function a9({agent:e}){const{t}=se("console"),{agentSkills:n,agentSkillsLoading:r,agentSkillsAllowlist:s,fetchAgentSkills:o,saveAgentSkillsAllowlist:u}=On(),[f,h]=S.useState("all"),[g,y]=S.useState([]),[p,b]=S.useState(!1),[v,k]=S.useState("idle");S.useEffect(()=>{o(e.id)},[e.id,o]),S.useEffect(()=>{s==null?(h("all"),y([])):(h("selected"),y(s)),k("idle")},[s]);const j=$=>{if(h($),$==="all")y([]);else{const V=(n==null?void 0:n.filter(ae=>ae.enabled).map(ae=>ae.slug))??[];y(V)}},N=($,V)=>{y(ae=>V?[...ae,$]:ae.filter(J=>J!==$))},C=n??[],E=S.useMemo(()=>C.filter($=>!vc($)),[C]),R=()=>{y(C.map($=>$.slug))},H=()=>{const $=C.filter(V=>vc(V)).map(V=>V.slug);y($)},z=S.useCallback(async()=>{b(!0),k("idle");const $=await u(e.id,f==="all"?null:g);b(!1),k($.ok?"success":"error"),$.ok&&setTimeout(()=>k("idle"),2e3)},[e.id,f,g,u]),{totalCount:L,enabledCount:G,blockedCount:W}=S.useMemo(()=>{const $=C.length;if(f==="all")return{totalCount:$,enabledCount:C.filter(J=>J.enabled).length,blockedCount:C.filter(J=>J.blockedByAllowlist).length};const V=new Set(g),ae=C.filter(J=>vc(J)||V.has(J.slug)).length;return{totalCount:$,enabledCount:ae,blockedCount:$-ae}},[C,f,g]),P=f==="selected"&&E.every($=>g.includes($.slug)),M=f==="selected"&&E.every($=>!g.includes($.slug));return r?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-5 w-5 animate-spin text-gray-400"})}):c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.skills.title")}),c.jsx("button",{onClick:()=>o(e.id),className:"rounded p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300",title:t("agents.refresh"),children:c.jsx(Rn,{className:"h-4 w-4"})})]}),c.jsxs("div",{className:"flex gap-4",children:[c.jsx(Th,{label:t("agents.skills.total"),value:L}),c.jsx(Th,{label:t("agents.skills.enabled"),value:G,color:"green"}),c.jsx(Th,{label:t("agents.skills.blocked"),value:W,color:"red"})]}),c.jsx("div",{className:"rounded-lg border border-gray-200 p-4 dark:border-gray-700",children:c.jsxs("div",{className:"flex items-center gap-4",children:[c.jsxs("label",{className:"flex cursor-pointer items-center gap-2",children:[c.jsx("input",{type:"radio",name:"skillMode",checked:f==="all",onChange:()=>j("all"),className:"h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500"}),c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:t("agents.skills.modeAll")})]}),c.jsxs("label",{className:"flex cursor-pointer items-center gap-2",children:[c.jsx("input",{type:"radio",name:"skillMode",checked:f==="selected",onChange:()=>j("selected"),className:"h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500"}),c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:t("agents.skills.modeSelected")})]})]})}),f==="selected"&&C.length>0&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{onClick:R,disabled:P,className:"inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:opacity-40 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700",children:[c.jsx(Q4,{className:"h-3.5 w-3.5"}),t("agents.skills.selectAll")]}),c.jsxs("button",{onClick:H,disabled:M,className:"inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:opacity-40 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700",children:[c.jsx(Ng,{className:"h-3.5 w-3.5"}),t("agents.skills.deselectAll")]})]}),c.jsx("div",{className:"space-y-1",children:C.length===0?c.jsx("div",{className:"py-8 text-center text-sm text-gray-400 dark:text-gray-500",children:t("agents.skills.noRestriction")}):C.map($=>c.jsx(i9,{skill:$,selectable:f==="selected",checked:r9($,f,g),locked:vc($),onToggle:V=>N($.slug,V)},$.id))}),c.jsxs("div",{className:"flex items-center gap-2 border-t border-gray-200 pt-4 dark:border-gray-700",children:[c.jsx("button",{onClick:z,disabled:p,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50",children:t(p?"agents.skills.saving":"agents.skills.save")}),v==="success"&&c.jsx("span",{className:"text-xs text-green-600",children:t("agents.skills.saveSuccess")}),v==="error"&&c.jsx("span",{className:"text-xs text-red-600",children:t("agents.skills.saveError")})]})]})}function r9(e,t,n){return t==="all"?e.enabled:e.isCore&&e.always?!0:n.includes(e.slug)}function vc(e){return!!(e.isCore&&e.always)}function Th({label:e,value:t,color:n}){const r=n==="green"?"text-green-600 dark:text-green-400":n==="red"?"text-red-600 dark:text-red-400":"text-gray-900 dark:text-gray-100";return c.jsxs("div",{className:"rounded-lg border border-gray-200 px-3 py-2 dark:border-gray-700",children:[c.jsx("div",{className:`text-lg font-semibold ${r}`,children:t}),c.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:e})]})}function i9({skill:e,selectable:t,checked:n,locked:r,onToggle:s}){var p,b;const{t:o}=se("console"),u=((p=e.missing)==null?void 0:p.bins)&&e.missing.bins.length>0||((b=e.missing)==null?void 0:b.env)&&e.missing.env.length>0,f=e.isCore||e.isBundled?o("agents.skills.sourceBuiltIn"):o("agents.skills.sourceMarketplace"),h=e.isCore||e.isBundled?"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",g=t?o(n?"skills.detail.enabled":"skills.detail.disabled"):e.enabled?o("skills.detail.enabled"):o("skills.detail.disabled"),y=t?n?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-500 dark:bg-gray-700 dark:text-gray-400":e.enabled?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-500 dark:bg-gray-700 dark:text-gray-400";return c.jsxs("div",{className:"flex items-center gap-3 rounded-md px-3 py-2.5 hover:bg-gray-50 dark:hover:bg-gray-800/50",children:[t&&c.jsx("input",{type:"checkbox",checked:n,disabled:r,onChange:v=>s(v.target.checked),"aria-label":e.name,className:"h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500 disabled:opacity-50"}),c.jsx("span",{className:"text-lg",children:e.icon||c.jsx(V4,{className:"h-4 w-4 text-gray-400"})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:e.name}),c.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] font-medium ${y}`,children:g}),c.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] font-medium ${h}`,children:f})]}),e.description&&c.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs text-gray-500 dark:text-gray-400",children:e.description})]}),u&&c.jsx("span",{title:o("agents.skills.missingDeps"),children:c.jsx(Pi,{className:"h-4 w-4 shrink-0 text-amber-500"})})]})}const s9=["full","minimal","custom",""];function l9({agent:e}){const{t}=se("console"),{agentTools:n,agentToolsLoading:r,agentToolsConfig:s,fetchAgentTools:o,saveAgentToolsConfig:u}=On(),[f,h]=S.useState(""),[g,y]=S.useState([]),[p,b]=S.useState([]),[v,k]=S.useState(""),[j,N]=S.useState(""),[C,E]=S.useState(!1),[R,H]=S.useState("idle");S.useEffect(()=>{o(e.id)},[e.id,o]),S.useEffect(()=>{s&&(h(s.profile??""),y(s.alsoAllow??[]),b(s.deny??[])),H("idle")},[s]);const z=S.useCallback(async()=>{E(!0),H("idle");const $=await u(e.id,{profile:f||void 0,alsoAllow:g.length>0?g:void 0,deny:p.length>0?p:void 0});E(!1),H($.ok?"success":"error"),$.ok&&setTimeout(()=>H("idle"),2e3)},[e.id,f,g,p,u]),L=($,V,ae)=>{const J=ae.trim();J&&!$.includes(J)&&V([...$,J])},G=($,V,ae)=>{V($.filter((J,Z)=>Z!==ae))},W=u9(n??[]),P=(n==null?void 0:n.filter($=>$.enabled!==!1).length)??0,M=(n==null?void 0:n.length)??0;return r?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-5 w-5 animate-spin text-gray-400"})}):c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.tools.title")}),c.jsx("button",{onClick:()=>o(e.id),className:"rounded p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300",title:t("agents.refresh"),children:c.jsx(Rn,{className:"h-4 w-4"})})]}),c.jsx("div",{className:"rounded-lg border border-gray-200 bg-gray-50 p-4 dark:border-gray-700 dark:bg-gray-800/50",children:c.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[t("agents.tools.profile"),":"]}),c.jsx("span",{className:"font-medium text-gray-900 dark:text-gray-100",children:f||t("agents.tools.profileDefault")}),c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"|"}),c.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:t("agents.tools.enabledCount",{enabled:P,total:M})})]})}),c.jsxs("div",{className:"space-y-4 border-t border-gray-200 pt-5 dark:border-gray-700",children:[c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-xs font-medium text-gray-600 dark:text-gray-400",children:t("agents.tools.profile")}),c.jsxs("div",{className:"relative w-full max-w-xs",children:[c.jsx("select",{value:f,onChange:$=>h($.target.value),"aria-label":t("agents.tools.profile"),className:"w-full appearance-none rounded-lg border border-gray-300 bg-white px-3 py-2 pr-8 text-sm text-gray-900 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200",children:s9.map($=>c.jsx("option",{value:$,children:$||t("agents.tools.profileDefault")},$))}),c.jsx(qn,{className:"pointer-events-none absolute right-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"})]})]}),c.jsx(Bv,{label:t("agents.tools.alsoAllow"),tags:g,inputValue:v,onInputChange:k,onAdd:$=>{L(g,y,$),k("")},onRemove:$=>G(g,y,$),placeholder:t("agents.tools.addTool")}),c.jsx(Bv,{label:t("agents.tools.deny"),tags:p,inputValue:j,onInputChange:N,onAdd:$=>{L(p,b,$),N("")},onRemove:$=>G(p,b,$),placeholder:t("agents.tools.addTool")}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{onClick:z,disabled:C,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50",children:t(C?"agents.tools.saving":"agents.tools.save")}),R==="success"&&c.jsx("span",{className:"text-xs text-green-600",children:t("agents.tools.saveSuccess")}),R==="error"&&c.jsx("span",{className:"text-xs text-red-600",children:t("agents.tools.saveError")})]})]}),c.jsxs("div",{className:"border-t border-gray-200 pt-5 dark:border-gray-700",children:[c.jsx("h3",{className:"mb-3 text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.tools.catalogTitle")}),M===0?c.jsx(c9,{message:t("agents.tools.noTools")}):c.jsx("div",{className:"space-y-4",children:Object.entries(W).map(([$,V])=>c.jsxs("div",{children:[c.jsx("h4",{className:"mb-2 text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400",children:$}),c.jsx("div",{className:"space-y-1",children:V.map(ae=>c.jsx(o9,{tool:ae},ae.name))})]},$))})]})]})}function Bv({label:e,tags:t,inputValue:n,onInputChange:r,onAdd:s,onRemove:o,placeholder:u}){return c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-xs font-medium text-gray-600 dark:text-gray-400",children:e}),c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[t.map((f,h)=>c.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-gray-100 px-2 py-1 text-xs text-gray-700 dark:bg-gray-700 dark:text-gray-300",children:[f,c.jsx("button",{onClick:()=>o(h),className:"rounded-sm text-gray-400 hover:text-red-500",title:f,children:c.jsx(An,{className:"h-3 w-3"})})]},`${f}-${h}`)),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("input",{type:"text",value:n,onChange:f=>r(f.target.value),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),s(n))},placeholder:u,className:"w-36 rounded-md border border-gray-300 bg-white px-2 py-1 text-xs dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"}),c.jsx("button",{onClick:()=>s(n),className:"rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-blue-600 dark:hover:bg-gray-700",title:e,children:c.jsx(En,{className:"h-3.5 w-3.5"})})]})]})]})}function o9({tool:e}){const t=e.source==="built-in"?"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":e.source==="plugin"?"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400":"bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-400";return c.jsxs("div",{className:"flex items-center gap-3 rounded-md px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-800/50",children:[c.jsx(iu,{className:"h-4 w-4 shrink-0 text-gray-400"}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:e.name}),e.description&&c.jsx("p",{className:"line-clamp-1 text-xs text-gray-500 dark:text-gray-400",children:e.description})]}),e.source&&c.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium ${t}`,children:e.source})]})}function c9({message:e}){return c.jsx("div",{className:"py-8 text-center text-sm text-gray-400 dark:text-gray-500",children:e})}function u9(e){const t={};for(const n of e){const r=n.source??"other";t[r]||(t[r]=[]),t[r].push(n)}return t}const d9=["overview","files","tools","skills","channels","cronJobs"];function f9({agent:e}){const{t}=se("console"),{activeTab:n,setActiveTab:r}=On();return c.jsxs("div",{className:"rounded-2xl border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900",children:[c.jsx("div",{className:"flex border-b border-gray-200 px-4 dark:border-gray-700",children:d9.map(s=>c.jsxs("button",{onClick:()=>r(s),className:`relative px-4 py-3 text-sm font-medium transition-colors ${n===s?"text-red-600 dark:text-red-400":"text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"}`,children:[t(`agents.tabs.${s}`),n===s&&c.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-red-500"})]},s))}),c.jsxs("div",{className:"p-5",children:[n==="overview"&&c.jsx(n9,{agent:e},e.id),n==="files"&&c.jsx(t9,{agent:e},e.id),n==="tools"&&c.jsx(l9,{agent:e},e.id),n==="skills"&&c.jsx(a9,{agent:e},e.id),n==="channels"&&c.jsx(Fz,{agent:e},e.id),n==="cronJobs"&&c.jsx(Zz,{agent:e},e.id)]})]})}function h9({agent:e,isSelected:t,isDefault:n,onSelect:r}){var h,g,y;const{t:s}=se("console"),o=((h=e.identity)==null?void 0:h.name)??e.name??e.id,u=(g=e.identity)==null?void 0:g.emoji,f=(y=e.identity)==null?void 0:y.avatarUrl;return c.jsxs("button",{onClick:r,className:`flex w-full items-center gap-3 rounded-xl px-3 py-2.5 text-left transition-colors ${t?"border-l-2 border-blue-500 bg-blue-50 dark:bg-blue-900/20":"hover:bg-gray-50 dark:hover:bg-gray-800"}`,children:[c.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-gray-100 text-lg dark:bg-gray-800",children:f?c.jsx("img",{src:f,alt:o,className:"h-9 w-9 rounded-lg object-cover"}):c.jsx("span",{children:u??o.charAt(0).toLowerCase()})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"truncate text-sm font-medium text-gray-900 dark:text-gray-100",children:o}),n&&c.jsx("span",{className:"shrink-0 rounded-md bg-gray-200 px-1.5 py-0.5 text-[10px] font-semibold uppercase text-gray-600 dark:bg-gray-700 dark:text-gray-300",children:s("agents.defaultBadge")})]}),c.jsx("p",{className:"truncate text-xs text-gray-500 dark:text-gray-400",children:e.id})]})]})}function g9(){const{t:e}=se("console"),{agents:t,isLoading:n,selectedAgentId:r,searchQuery:s,defaultAgentId:o,fetchAgents:u,selectAgent:f,setSearchQuery:h,setCreateDialogOpen:g}=On(),y=t.filter(p=>{var k;if(!s)return!0;const b=s.toLowerCase();return(((k=p.identity)==null?void 0:k.name)??p.name??p.id).toLowerCase().includes(b)||p.id.toLowerCase().includes(b)});return c.jsxs("div",{className:"flex w-72 shrink-0 flex-col rounded-2xl border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900",children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-gray-200 px-4 py-3 dark:border-gray-700",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:e("agents.panelTitle")}),c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:e("agents.configured",{count:t.length})})]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("button",{onClick:()=>g(!0),className:"rounded-md p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-200",title:e("agents.addAgent"),children:c.jsx(En,{className:"h-4 w-4"})}),c.jsx("button",{onClick:()=>u(),disabled:n,className:"rounded-md p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700 disabled:opacity-50 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-200",title:e("agents.refresh"),children:c.jsx(Rn,{className:`h-4 w-4 ${n?"animate-spin":""}`})})]})]}),c.jsx("div",{className:"px-3 py-2",children:c.jsxs("div",{className:"relative",children:[c.jsx(Ph,{className:"absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-gray-400"}),c.jsx("input",{type:"text",value:s,onChange:p=>h(p.target.value),placeholder:e("agents.searchPlaceholder"),className:"w-full rounded-lg border border-gray-200 bg-gray-50 py-1.5 pl-8 pr-3 text-xs text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 dark:placeholder:text-gray-500"})]})}),c.jsx("div",{className:"flex-1 overflow-auto px-2 pb-2",children:y.length===0?c.jsx("div",{className:"flex flex-col items-center py-8 text-center",children:c.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500",children:e("agents.noAgents")})}):c.jsx("div",{className:"space-y-1",children:y.map(p=>c.jsx(h9,{agent:p,isSelected:r===p.id,isDefault:p.id===o,onSelect:()=>f(p.id)},p.id))})})]})}function m9(){const{t:e}=se("console"),{createDialogOpen:t,setCreateDialogOpen:n,createAgent:r,selectAgent:s}=On(),[o,u]=S.useState(""),[f,h]=S.useState(""),[g,y]=S.useState(""),[p,b]=S.useState(!1),[v,k]=S.useState("");if(!t)return null;const j=()=>{n(!1),u(""),h(""),y(""),k("")},N=async()=>{if(!o.trim()){k(e("agents.createDialog.nameRequired"));return}const C=f.trim()||`~/.openclaw/workspace-${o.trim().toLowerCase().replace(/\s+/g,"-")}`;b(!0),k("");const E=await r({name:o.trim(),workspace:C,emoji:g.trim()||void 0});b(!1),E?(s(E),j()):k(e("agents.overview.saveError"))};return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",children:c.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-gray-200 bg-white p-6 shadow-xl dark:border-gray-700 dark:bg-gray-900",children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:e("agents.createDialog.title")}),c.jsx("button",{onClick:j,className:"rounded-md p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800",children:c.jsx(An,{className:"h-5 w-5"})})]}),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:[e("agents.createDialog.name")," *"]}),c.jsx("input",{type:"text",value:o,onChange:C=>u(C.target.value),placeholder:e("agents.createDialog.namePlaceholder"),className:"w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200",autoFocus:!0})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:e("agents.createDialog.workspace")}),c.jsx("input",{type:"text",value:f,onChange:C=>h(C.target.value),placeholder:e("agents.createDialog.workspacePlaceholder"),className:"w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:e("agents.createDialog.emoji")}),c.jsx("input",{type:"text",value:g,onChange:C=>y(C.target.value),placeholder:e("agents.createDialog.emojiPlaceholder"),className:"w-24 rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"})]}),v&&c.jsx("p",{className:"text-sm text-red-600",children:v}),c.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[c.jsx("button",{onClick:j,className:"rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-800",children:e("agents.createDialog.cancel")}),c.jsx("button",{onClick:N,disabled:p,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50",children:e(p?"agents.createDialog.creating":"agents.createDialog.create")})]})]})]})})}function p9(){var k;const{t:e}=se("console"),{deleteDialogOpen:t,setDeleteDialogOpen:n,selectedAgentId:r,agents:s,deleteAgent:o}=On(),[u,f]=S.useState(!1),[h,g]=S.useState(!1),y=s.find(j=>j.id===r);if(!t||!y)return null;const p=((k=y.identity)==null?void 0:k.name)??y.name??y.id,b=()=>{n(!1),f(!1)},v=async()=>{g(!0),await o(y.id,u),g(!1),b()};return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",children:c.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-gray-200 bg-white p-6 shadow-xl dark:border-gray-700 dark:bg-gray-900",children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Pi,{className:"h-5 w-5 text-red-500"}),c.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:e("agents.deleteDialog.title")})]}),c.jsx("button",{onClick:b,className:"rounded-md p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800",children:c.jsx(An,{className:"h-5 w-5"})})]}),c.jsx("p",{className:"mb-4 text-sm text-gray-600 dark:text-gray-400",children:e("agents.deleteDialog.confirm",{name:p})}),c.jsxs("label",{className:"mb-4 flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300",children:[c.jsx("input",{type:"checkbox",checked:u,onChange:j=>f(j.target.checked),className:"rounded border-gray-300 text-red-600 focus:ring-red-500"}),e("agents.deleteDialog.deleteFiles")]}),c.jsxs("div",{className:"flex justify-end gap-3",children:[c.jsx("button",{onClick:b,className:"rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-800",children:e("agents.deleteDialog.cancel")}),c.jsx("button",{onClick:v,disabled:h,className:"rounded-lg bg-red-600 px-4 py-2 text-sm font-medium text-white hover:bg-red-700 disabled:opacity-50",children:e(h?"agents.deleteDialog.deleting":"agents.deleteDialog.delete")})]})]})})}function y9(){const{t:e}=se("console"),{selectedAgentId:t,agents:n,fetchAgents:r}=On(),s=n.find(o=>o.id===t)??null;return S.useEffect(()=>{r()},[r]),c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e("agents.title")}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:e("agents.description")})]}),c.jsxs("div",{className:"flex gap-6",children:[c.jsx(g9,{}),c.jsx("div",{className:"min-w-0 flex-1",children:s?c.jsxs("div",{className:"space-y-4",children:[c.jsx(qz,{agent:s}),c.jsx(f9,{agent:s})]}):c.jsxs("div",{className:"flex h-96 flex-col items-center justify-center rounded-2xl border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900",children:[c.jsx(T1,{className:"mb-3 h-12 w-12 text-gray-300 dark:text-gray-600"}),c.jsx("p",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:e("agents.selectAgent")}),c.jsx("p",{className:"mt-1 text-xs text-gray-400 dark:text-gray-500",children:e("agents.selectAgentDesc")})]})})]}),c.jsx(m9,{}),c.jsx(p9,{})]})}const yu={telegram:{type:"telegram",nameKey:"console:channels.types.telegram",icon:"✈️",fields:[{key:"botToken",labelKey:"console:channels.fields.botToken",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.botToken"}]},discord:{type:"discord",nameKey:"console:channels.types.discord",icon:"🎮",fields:[{key:"botToken",labelKey:"console:channels.fields.botToken",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.botToken"},{key:"applicationId",labelKey:"console:channels.fields.applicationId",type:"text",required:!0,placeholderKey:"console:channels.placeholders.applicationId"}]},whatsapp:{type:"whatsapp",nameKey:"console:channels.types.whatsapp",icon:"📱",fields:[],hasQrFlow:!0},signal:{type:"signal",nameKey:"console:channels.types.signal",icon:"🔒",fields:[{key:"phoneNumber",labelKey:"console:channels.fields.phoneNumber",type:"text",required:!0,placeholderKey:"console:channels.placeholders.phoneNumber"}]},feishu:{type:"feishu",nameKey:"console:channels.types.feishu",icon:"🐦",fields:[{key:"appId",labelKey:"console:channels.fields.appId",type:"text",required:!0,placeholderKey:"console:channels.placeholders.appId"},{key:"appSecret",labelKey:"console:channels.fields.appSecret",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.appSecret"}]},imessage:{type:"imessage",nameKey:"console:channels.types.imessage",icon:"💬",fields:[]},matrix:{type:"matrix",nameKey:"console:channels.types.matrix",icon:"🔗",fields:[{key:"homeserver",labelKey:"console:channels.fields.homeserver",type:"text",required:!0,placeholderKey:"console:channels.placeholders.homeserver"},{key:"accessToken",labelKey:"console:channels.fields.accessToken",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.accessToken"}]},line:{type:"line",nameKey:"console:channels.types.line",icon:"🟢",fields:[{key:"channelAccessToken",labelKey:"console:channels.fields.channelAccessToken",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.channelAccessToken"},{key:"channelSecret",labelKey:"console:channels.fields.channelSecret",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.channelSecret"}]},msteams:{type:"msteams",nameKey:"console:channels.types.msteams",icon:"👔",fields:[{key:"appId",labelKey:"console:channels.fields.appId",type:"text",required:!0,placeholderKey:"console:channels.placeholders.appId"},{key:"appPassword",labelKey:"console:channels.fields.appPassword",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.appPassword"}]},googlechat:{type:"googlechat",nameKey:"console:channels.types.googlechat",icon:"💭",fields:[{key:"serviceAccountJson",labelKey:"console:channels.fields.serviceAccount",type:"textarea",required:!0,placeholderKey:"console:channels.placeholders.serviceAccount"}]},mattermost:{type:"mattermost",nameKey:"console:channels.types.mattermost",icon:"💠",fields:[{key:"serverUrl",labelKey:"console:channels.fields.serverUrl",type:"text",required:!0,placeholderKey:"console:channels.placeholders.serverUrl"},{key:"botToken",labelKey:"console:channels.fields.botToken",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.botToken"}]}},x9=Object.keys(yu);function b9({channels:e,onSelect:t}){const{t:n}=se("console"),r=new Set(e.map(s=>s.type));return c.jsxs("div",{children:[c.jsx("h3",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:n("channels.available.title")}),c.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4",children:x9.map(s=>{const o=yu[s],u=r.has(s);return c.jsxs("button",{type:"button",onClick:()=>t(s),className:"flex flex-col items-center gap-2 rounded-lg border border-gray-200 bg-white p-4 transition-colors hover:border-blue-300 hover:bg-blue-50/50 dark:border-gray-700 dark:bg-gray-800 dark:hover:border-blue-600 dark:hover:bg-blue-900/10",children:[c.jsx("span",{className:"text-2xl",children:o.icon}),c.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-300",children:n(o.nameKey)}),u?c.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-green-100 px-2 py-0.5 text-[10px] font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:[c.jsx(Tr,{className:"h-3 w-3"}),n("channels.available.configured")]}):c.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-gray-100 px-2 py-0.5 text-[10px] font-medium text-gray-500 dark:bg-gray-700 dark:text-gray-400",children:[c.jsx(En,{className:"h-3 w-3"}),n("channels.available.add")]})]},s)})})]})}const v9={connected:"bg-green-500",active:"bg-green-500",ok:"bg-green-500",disconnected:"bg-gray-400",paused:"bg-gray-400",disabled:"bg-gray-400",connecting:"bg-yellow-500",pending:"bg-yellow-500",running:"bg-yellow-500",error:"bg-red-500",failed:"bg-red-500"};function Rw({status:e,className:t=""}){const{t:n}=se("common"),r=v9[e]??"bg-gray-400",s=n(`status.${e}`,{defaultValue:e});return c.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs ${t}`,children:[c.jsx("span",{className:`inline-block h-2 w-2 rounded-full ${r}`}),c.jsx("span",{className:"text-gray-600 dark:text-gray-400",children:s})]})}const k9={connected:"border-l-green-500",error:"border-l-red-500",connecting:"border-l-yellow-500",disconnected:"border-l-gray-300 dark:border-l-gray-600"};function w9({channel:e,onLogout:t,onDetail:n}){const{t:r}=se("console"),s=yu[e.type],o=k9[e.status]??"border-l-gray-300",u=e.lastConnectedAt?new Date(e.lastConnectedAt).toLocaleString():null;return c.jsxs("div",{className:`flex items-center justify-between rounded-lg border border-l-4 bg-white p-4 dark:bg-gray-800 ${o} border-gray-200 dark:border-gray-700`,children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("span",{className:"text-2xl",children:(s==null?void 0:s.icon)??"📡"}),c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"font-medium text-gray-900 dark:text-gray-100",children:e.name}),c.jsx("span",{className:"rounded bg-gray-100 px-1.5 py-0.5 text-xs text-gray-500 dark:bg-gray-700 dark:text-gray-400",children:e.type})]}),c.jsxs("div",{className:"mt-1 flex items-center gap-3",children:[c.jsx(Rw,{status:e.status}),u&&c.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:r("channels.card.lastConnected",{time:u})})]}),e.error&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:e.error})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{type:"button",onClick:()=>n(e),className:"rounded p-1.5 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300 transition-colors",title:r("channels.card.details"),children:c.jsx(ru,{className:"h-4 w-4"})}),e.status==="connected"&&c.jsx("button",{type:"button",onClick:()=>t(e),className:"rounded p-1.5 text-gray-400 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20 dark:hover:text-red-400 transition-colors",title:r("channels.card.logout"),children:c.jsx(m4,{className:"h-4 w-4"})})]})]})}const Mw=Mn((e,t)=>({channels:[],isLoading:!1,error:null,selectedChannel:null,configDialogOpen:!1,configDialogChannelType:null,qrState:"idle",qrDataUrl:null,qrError:null,fetchChannels:async()=>{e({isLoading:!0,error:null});try{await Pe();const n=await Oe().channelsStatus();e({channels:n,isLoading:!1})}catch(n){e({error:String(n),isLoading:!1})}},logoutChannel:async(n,r)=>{try{await Oe().channelsLogout(n,r),await t().fetchChannels()}catch(s){e({error:String(s)})}},openConfigDialog:(n,r)=>{e({configDialogOpen:!0,configDialogChannelType:n,selectedChannel:r??null,qrState:"idle",qrDataUrl:null,qrError:null})},closeConfigDialog:()=>{e({configDialogOpen:!1,configDialogChannelType:null,selectedChannel:null,qrState:"idle",qrDataUrl:null,qrError:null})},startQrPairing:async()=>{e({qrState:"loading",qrError:null});try{const n=await Oe().webLoginStart(!0);e({qrState:"qr",qrDataUrl:n.qrDataUrl??null}),e({qrState:"scanning"});const r=await Oe().webLoginWait();r.connected?(e({qrState:"success"}),await t().fetchChannels()):e({qrState:"error",qrError:r.message})}catch(n){e({qrState:"error",qrError:String(n)})}},cancelQrPairing:()=>{e({qrState:"idle",qrDataUrl:null,qrError:null})}}));function S9({onClose:e}){const{t}=se("console"),{qrState:n,qrDataUrl:r,qrError:s,startQrPairing:o,cancelQrPairing:u}=Mw();return n==="idle"||n==="cancel"?c.jsxs("div",{className:"flex flex-col items-center gap-4 py-6",children:[c.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:t("channels.qr.description")}),c.jsx("button",{type:"button",onClick:o,className:"rounded-md bg-green-600 px-6 py-2 text-sm font-medium text-white hover:bg-green-700 transition-colors",children:t("channels.qr.startPairing")})]}):n==="loading"?c.jsxs("div",{className:"flex flex-col items-center gap-3 py-8",children:[c.jsx(Mt,{className:"h-8 w-8 animate-spin text-green-500"}),c.jsx("p",{className:"text-sm text-gray-500",children:t("channels.qr.loading")})]}):n==="qr"||n==="scanning"?c.jsxs("div",{className:"flex flex-col items-center gap-4 py-4",children:[r&&c.jsx("img",{src:r,alt:"WhatsApp QR Code",className:"h-48 w-48 rounded-lg border border-gray-200 dark:border-gray-700"}),c.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:t(n==="scanning"?"channels.qr.waitingScan":"channels.qr.scanPrompt")}),n==="scanning"&&c.jsx(Mt,{className:"h-5 w-5 animate-spin text-green-500"}),c.jsx("button",{type:"button",onClick:u,className:"text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",children:t("common:actions.cancel")})]}):n==="success"?c.jsxs("div",{className:"flex flex-col items-center gap-3 py-8",children:[c.jsx(qi,{className:"h-10 w-10 text-green-500"}),c.jsx("p",{className:"font-medium text-green-600",children:t("channels.qr.success")}),c.jsx("button",{type:"button",onClick:e,className:"rounded-md border border-gray-300 px-4 py-1.5 text-sm text-gray-600 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:t("common:actions.close")})]}):c.jsxs("div",{className:"flex flex-col items-center gap-3 py-8",children:[c.jsx(tu,{className:"h-10 w-10 text-red-500"}),c.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:s??t("channels.qr.error")}),c.jsx("button",{type:"button",onClick:o,className:"rounded-md border border-red-300 px-4 py-1.5 text-sm text-red-600 hover:bg-red-50 dark:border-red-700 dark:text-red-400 dark:hover:bg-red-900/20 transition-colors",children:t("common:actions.retry")})]})}function j9({open:e,channelType:t,onClose:n}){const{t:r}=se("console"),s=S.useRef(null),[o,u]=S.useState({}),[f,h]=S.useState({}),[g,y]=S.useState(new Set),p=t?yu[t]:null;if(S.useEffect(()=>{const k=s.current;k&&(e&&!k.open?(u({}),h({}),y(new Set),k.showModal()):!e&&k.open&&k.close())},[e]),!p)return null;if(p.hasQrFlow)return c.jsx("dialog",{ref:s,onClose:n,className:"fixed inset-0 z-50 m-auto max-w-md rounded-lg border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-6",children:[c.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[c.jsx("span",{className:"text-xl",children:p.icon}),c.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:r(p.nameKey)})]}),c.jsx(S9,{onClose:n})]})});const b=()=>{var N;const k={};let j=!1;for(const C of p.fields)C.required&&!((N=o[C.key])!=null&&N.trim())&&(k[C.key]=!0,j=!0);h(k),j||n()},v=k=>{y(j=>{const N=new Set(j);return N.has(k)?N.delete(k):N.add(k),N})};return c.jsx("dialog",{ref:s,onClose:n,className:"fixed inset-0 z-50 m-auto max-w-md rounded-lg border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-6",children:[c.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[c.jsx("span",{className:"text-xl",children:p.icon}),c.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:r(p.nameKey)})]}),c.jsx("div",{className:"space-y-4",children:p.fields.map(k=>c.jsx(C9,{field:k,value:o[k.key]??"",onChange:j=>u(N=>({...N,[k.key]:j})),hasError:f[k.key]??!1,isSecretVisible:g.has(k.key),onToggleSecret:()=>v(k.key)},k.key))}),c.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:n,className:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:r("channels.configDialog.cancel",{defaultValue:r("common:actions.cancel")})}),c.jsx("button",{type:"button",onClick:b,className:"rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:r("channels.configDialog.save",{defaultValue:r("common:actions.save")})})]})]})})}function C9({field:e,value:t,onChange:n,hasError:r,isSecretVisible:s,onToggleSecret:o}){const{t:u}=se("console"),f=r?"border-red-500":"border-gray-300 dark:border-gray-600";return e.type==="textarea"?c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:[u(e.labelKey)," ",e.required&&c.jsx("span",{className:"text-red-500",children:"*"})]}),c.jsx("textarea",{value:t,onChange:h=>n(h.target.value),placeholder:u(e.placeholderKey),rows:4,className:`w-full rounded-md border bg-white px-3 py-2 text-sm dark:bg-gray-700 dark:text-gray-100 ${f}`}),r&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:u("channels.configDialog.required")})]}):c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:[u(e.labelKey)," ",e.required&&c.jsx("span",{className:"text-red-500",children:"*"})]}),c.jsxs("div",{className:"relative",children:[c.jsx("input",{type:e.type==="secret"&&!s?"password":"text",value:t,onChange:h=>n(h.target.value),placeholder:u(e.placeholderKey),className:`w-full rounded-md border bg-white px-3 py-2 text-sm dark:bg-gray-700 dark:text-gray-100 ${f} ${e.type==="secret"?"pr-10":""}`}),e.type==="secret"&&c.jsx("button",{type:"button",onClick:o,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:s?c.jsx(nu,{className:"h-4 w-4"}):c.jsx(au,{className:"h-4 w-4"})})]}),r&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:u("channels.configDialog.required")})]})}function N9({channels:e}){const{t}=se("console"),n=e.filter(s=>s.status==="connected").length,r=e.filter(s=>s.status==="error").length;return c.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[t("channels.stats.total")," ",c.jsx("strong",{className:"text-gray-900 dark:text-gray-100",children:e.length})]}),c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"·"}),c.jsxs("span",{className:"text-green-600 dark:text-green-400",children:[t("channels.stats.connected")," ",c.jsx("strong",{children:n})]}),r>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"·"}),c.jsxs("span",{className:"text-red-600 dark:text-red-400",children:[t("channels.stats.errors")," ",c.jsx("strong",{children:r})]})]})]})}function jl({open:e,title:t,description:n,confirmLabel:r,onConfirm:s,onCancel:o,variant:u="default"}){const{t:f}=se("common"),h=S.useRef(null);S.useEffect(()=>{const y=h.current;y&&(e&&!y.open?y.showModal():!e&&y.open&&y.close())},[e]);const g=u==="danger"?"bg-red-600 hover:bg-red-700 text-white":"bg-blue-600 hover:bg-blue-700 text-white";return c.jsx("dialog",{ref:h,onClose:o,className:"fixed inset-0 z-50 m-auto max-w-md rounded-lg border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-6",children:[c.jsx("h3",{className:"mb-2 text-lg font-semibold text-gray-900 dark:text-gray-100",children:t}),c.jsx("p",{className:"mb-6 text-sm text-gray-600 dark:text-gray-400",children:n}),c.jsxs("div",{className:"flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:o,className:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:f("actions.cancel")}),c.jsx("button",{type:"button",onClick:s,className:`rounded-md px-4 py-2 text-sm font-medium transition-colors ${g}`,children:r??f("actions.confirm")})]})]})})}function Er({icon:e,title:t,description:n,action:r}){return c.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[c.jsx(e,{className:"mb-4 h-12 w-12 text-gray-300 dark:text-gray-600",strokeWidth:1.5}),c.jsx("h3",{className:"mb-1 text-base font-medium text-gray-700 dark:text-gray-300",children:t}),n&&c.jsx("p",{className:"mb-4 max-w-sm text-sm text-gray-500 dark:text-gray-400",children:n}),r&&c.jsx("button",{type:"button",onClick:r.onClick,className:"rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:r.label})]})}function xu({message:e,onRetry:t}){const{t:n}=se("common");return c.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[c.jsx(Sg,{className:"mb-3 h-10 w-10 text-red-500"}),c.jsx("p",{className:"mb-4 text-sm text-red-600 dark:text-red-400",children:e}),t&&c.jsx("button",{type:"button",onClick:t,className:"rounded-md border border-red-300 px-4 py-2 text-sm font-medium text-red-600 hover:bg-red-50 dark:border-red-700 dark:text-red-400 dark:hover:bg-red-900/20 transition-colors",children:n("actions.retry")})]})}function zl({message:e}){return c.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[c.jsx(Mt,{className:"mb-3 h-8 w-8 animate-spin text-blue-500"}),e&&c.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:e})]})}function A9(){const{t:e}=se("console"),{channels:t,isLoading:n,error:r,fetchChannels:s,logoutChannel:o,configDialogOpen:u,configDialogChannelType:f,openConfigDialog:h,closeConfigDialog:g}=Mw(),[y,p]=S.useState(null);S.useEffect(()=>{s()},[s]);const b=async()=>{y&&(await o(y.type,y.accountId),p(null))};return n&&t.length===0?c.jsxs("div",{className:"space-y-6",children:[c.jsx(Dh,{title:e("channels.title"),description:e("channels.description"),onRefresh:s}),c.jsx(zl,{})]}):r&&t.length===0?c.jsxs("div",{className:"space-y-6",children:[c.jsx(Dh,{title:e("channels.title"),description:e("channels.description"),onRefresh:s}),c.jsx(xu,{message:r,onRetry:s})]}):c.jsxs("div",{className:"space-y-6",children:[c.jsx(Dh,{title:e("channels.title"),description:e("channels.description"),onRefresh:s,loading:n}),c.jsx(N9,{channels:t}),t.length===0?c.jsx(Er,{icon:o4,title:e("channels.empty.title"),description:e("channels.empty.description")}):c.jsx("div",{className:"space-y-3",children:t.map(v=>c.jsx(w9,{channel:v,onLogout:p,onDetail:k=>h(k.type,k)},v.id))}),c.jsx(b9,{channels:t,onSelect:v=>h(v)}),c.jsx(j9,{open:u,channelType:f,onClose:g}),c.jsx(jl,{open:y!==null,title:e("channels.logout.title"),description:e("channels.logout.description",{name:(y==null?void 0:y.name)??""}),onConfirm:b,onCancel:()=>p(null),variant:"danger"})]})}function Dh({title:e,description:t,onRefresh:n,loading:r}){const{t:s}=se("common");return c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:t})]}),c.jsxs("button",{type:"button",onClick:n,disabled:r,className:"flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:[c.jsx(Rn,{className:`h-3.5 w-3.5 ${r?"animate-spin":""}`}),s("actions.refresh")]})]})}function E9({tasks:e}){const{t}=se("console"),n=e.filter(o=>o.enabled&&o.state.lastRunStatus!=="error").length,r=e.filter(o=>!o.enabled).length,s=e.filter(o=>o.state.lastRunStatus==="error").length;return c.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[t("cron.stats.total")," ",c.jsx("strong",{className:"text-gray-900 dark:text-gray-100",children:e.length})]}),c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"·"}),c.jsxs("span",{className:"text-green-600 dark:text-green-400",children:[t("cron.stats.active")," ",c.jsx("strong",{children:n})]}),c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"·"}),c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[t("cron.stats.paused")," ",c.jsx("strong",{children:r})]}),s>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"·"}),c.jsxs("span",{className:"text-red-600 dark:text-red-400",children:[t("cron.stats.failed")," ",c.jsx("strong",{children:s})]})]})]})}function T9(){const{t:e}=se("console"),{tasks:t,isLoading:n,error:r,dialogOpen:s,editingTask:o,fetchTasks:u,addTask:f,updateTask:h,removeTask:g,runTask:y,openDialog:p,closeDialog:b,initEventListeners:v}=Vc(),[k,j]=S.useState(null),[N,C]=S.useState(null);S.useEffect(()=>(u(),v()),[u,v]);const E=(L,G)=>{h(L,{enabled:G})},R=async()=>{k&&(await g(k),j(null))},H=async()=>{N&&(await y(N),C(null),await u())};if(n&&t.length===0)return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Rh,{title:e("cron.title"),description:e("cron.description"),onRefresh:u,onCreate:()=>p()}),c.jsx(zl,{})]});if(r&&t.length===0)return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Rh,{title:e("cron.title"),description:e("cron.description"),onRefresh:u,onCreate:()=>p()}),c.jsx(xu,{message:r,onRetry:u})]});const z=[...t].sort((L,G)=>{const W=L.state.nextRunAtMs??1/0,P=G.state.nextRunAtMs??1/0;return W-P});return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Rh,{title:e("cron.title"),description:e("cron.description"),onRefresh:u,loading:n,onCreate:()=>p()}),c.jsx(E9,{tasks:t}),t.length===0?c.jsx(Er,{icon:Ki,title:e("cron.empty.title"),action:{label:e("cron.empty.createFirst"),onClick:()=>p()}}):c.jsx("div",{className:"space-y-3",children:z.map(L=>c.jsx(Tw,{task:L,onToggle:E,onRun:C,onEdit:p,onDelete:j},L.id))}),c.jsx(Dw,{open:s,editingTask:o,onSave:f,onUpdate:h,onClose:b}),c.jsx(jl,{open:k!==null,title:e("cron.delete.title"),description:e("cron.delete.description"),onConfirm:R,onCancel:()=>j(null),variant:"danger"}),c.jsx(jl,{open:N!==null,title:e("cron.run.title"),description:e("cron.run.description"),onConfirm:H,onCancel:()=>C(null)})]})}function Rh({title:e,description:t,onRefresh:n,loading:r,onCreate:s}){const{t:o}=se("common");return c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:t})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{type:"button",onClick:s,className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-blue-700 transition-colors",children:[c.jsx(En,{className:"h-3.5 w-3.5"}),o("actions.create")]}),c.jsxs("button",{type:"button",onClick:n,disabled:r,className:"flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:[c.jsx(Rn,{className:`h-3.5 w-3.5 ${r?"animate-spin":""}`}),o("actions.refresh")]})]})]})}const D9={warning:"border-amber-300 bg-amber-50 text-amber-800 dark:border-amber-700 dark:bg-amber-900/20 dark:text-amber-300",error:"border-red-300 bg-red-50 text-red-800 dark:border-red-700 dark:bg-red-900/20 dark:text-red-300"};function Uv({variant:e,message:t,actionLabel:n,onAction:r}){const s=e==="warning"?Pi:tu;return c.jsxs("div",{className:`flex items-center gap-3 rounded-lg border px-4 py-3 text-sm ${D9[e]}`,children:[c.jsx(s,{className:"h-4 w-4 flex-shrink-0"}),c.jsx("span",{className:"flex-1",children:t}),n&&r&&c.jsx("button",{type:"button",onClick:r,className:"text-xs font-medium underline hover:no-underline",children:n})]})}const R9={whatsapp:"📱",telegram:"✈️",discord:"🎮",signal:"🔒",feishu:"🐦",imessage:"💬",matrix:"🔗",line:"🟢",msteams:"👔",googlechat:"💭",mattermost:"💠"};function M9({channels:e}){const{t}=se("console"),n=e.filter(r=>r.status==="connected");return n.length===0?c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:t("dashboard.channelOverview.title")}),c.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-400",children:[c.jsx(Tl,{className:"h-4 w-4"}),c.jsx("span",{children:t("dashboard.channelOverview.empty")})]})]}):c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:t("dashboard.channelOverview.title")}),c.jsx("div",{className:"flex flex-wrap gap-3",children:n.map(r=>c.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-50 px-3 py-1.5 dark:bg-gray-700/50",children:[c.jsx("span",{className:"text-base",children:R9[r.type]??"📡"}),c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:r.name}),c.jsx(Rw,{status:r.status})]},r.id))})]})}const O9=[{path:"/channels",icon:Tl,titleKey:"console:channels.title",descKey:"console:channels.description"},{path:"/skills",icon:iu,titleKey:"console:skills.title",descKey:"console:skills.description"},{path:"/cron",icon:Ki,titleKey:"console:cron.title",descKey:"console:cron.description"},{path:"/settings",icon:Cg,titleKey:"console:settings.title",descKey:"console:settings.description"}];function _9(){const e=$i(),{t}=se();return c.jsx("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-4",children:O9.map(n=>c.jsxs("button",{type:"button",onClick:()=>e(n.path),className:"flex flex-col items-start gap-2 rounded-lg border border-gray-200 bg-white p-4 text-left transition-colors hover:border-blue-300 hover:bg-blue-50/50 dark:border-gray-700 dark:bg-gray-800 dark:hover:border-blue-600 dark:hover:bg-blue-900/10",children:[c.jsx(n.icon,{className:"h-5 w-5 text-gray-500 dark:text-gray-400"}),c.jsxs("div",{children:[c.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:t(n.titleKey)}),c.jsx("div",{className:"mt-0.5 text-xs text-gray-500 dark:text-gray-400 line-clamp-2",children:t(n.descKey)})]})]},n.path))})}function L9({skills:e}){const{t}=se("console"),n=e.filter(r=>r.enabled);return n.length===0?c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:t("dashboard.skillOverview.title")}),c.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-400",children:[c.jsx(iu,{className:"h-4 w-4"}),c.jsx("span",{children:t("dashboard.skillOverview.empty")})]})]}):c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:t("dashboard.skillOverview.title")}),c.jsx("div",{className:"flex flex-wrap gap-3",children:n.map(r=>c.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-50 px-3 py-1.5 dark:bg-gray-700/50",children:[c.jsx("span",{className:"text-base",children:r.icon||"📦"}),c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:r.name})]},r.id))})]})}function kc({icon:e,title:t,value:n,subtitle:r,progress:s,color:o="text-blue-500"}){return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:[c.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[c.jsx(e,{className:`h-5 w-5 ${o}`}),c.jsx("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:t})]}),c.jsx("div",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:n}),r&&c.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:r}),s!=null&&c.jsx("div",{className:"mt-2 h-1.5 w-full overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700",children:c.jsx("div",{className:"h-full rounded-full bg-blue-500 transition-all",style:{width:`${Math.min(100,Math.max(0,s))}%`}})})]})}const z9=Mn(e=>({channelsSummary:[],skillsSummary:[],usage:null,uptime:0,isLoading:!1,error:null,refresh:async()=>{e({isLoading:!0,error:null});try{const t=await Pe(),n=await Promise.allSettled([t.channelsStatus(),t.skillsStatus(),t.usageStatus()]),r=n[0].status==="fulfilled"?n[0].value:[],s=n[1].status==="fulfilled"?n[1].value:[],o=n[2].status==="fulfilled"?n[2].value:null,u=[];n[0].status==="rejected"&&u.push(`channels: ${n[0].reason}`),n[1].status==="rejected"&&u.push(`skills: ${n[1].reason}`),n[2].status==="rejected"&&u.push(`usage: ${n[2].reason}`),e({channelsSummary:r,skillsSummary:s,usage:o,isLoading:!1,error:u.length>0?u.join("; "):null})}catch(t){e({error:String(t),isLoading:!1})}}}));function I9(){const{t:e}=se("console"),{channelsSummary:t,skillsSummary:n,usage:r,isLoading:s,error:o,refresh:u}=z9(),f=ie(k=>k.connectionStatus);if(S.useEffect(()=>{u()},[u]),s&&t.length===0){const k=f!=="connected"&&f!=="connecting";return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Mh,{title:e("dashboard.title"),description:e("dashboard.description"),onRefresh:u}),k?c.jsx($v,{status:f,onRetry:u}):c.jsx(zl,{message:e("dashboard.loading")})]})}if(o&&t.length===0&&n.length===0){const k=f!=="connected";return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Mh,{title:e("dashboard.title"),description:e("dashboard.description"),onRefresh:u}),k?c.jsx($v,{status:f,onRetry:u}):c.jsx(xu,{message:o,onRetry:u})]})}const h=t.filter(k=>k.status==="connected").length,g=t.filter(k=>k.status==="error").length,y=n.filter(k=>k.enabled).length,p=r==null?void 0:r.providers[0],b=p==null?void 0:p.windows[0],v=p?`${p.displayName}: ${(b==null?void 0:b.usedPercent)??0}%`:"—";return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Mh,{title:e("dashboard.title"),description:e("dashboard.description"),onRefresh:u,loading:s}),f!=="connected"&&c.jsx(Uv,{variant:"warning",message:e("dashboard.alerts.gatewayDisconnected")}),g>0&&c.jsx(Uv,{variant:"error",message:e("dashboard.alerts.channelErrors",{count:g})}),c.jsxs("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-4",children:[c.jsx(kc,{icon:Tl,title:e("dashboard.stats.channels"),value:`${h} / ${t.length}`,color:"text-green-500"}),c.jsx(kc,{icon:iu,title:e("dashboard.stats.skills"),value:`${y} / ${n.length}`,color:"text-purple-500"}),c.jsx(kc,{icon:I1,title:e("dashboard.stats.usage"),value:v,progress:b==null?void 0:b.usedPercent,color:"text-blue-500"}),c.jsx(kc,{icon:Ki,title:e("dashboard.stats.uptime"),value:f==="connected"?e("dashboard.stats.uptimeOnline"):"—",color:"text-amber-500"})]}),c.jsxs("div",{children:[c.jsx("h2",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:e("dashboard.quickNav.title")}),c.jsx(_9,{})]}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[c.jsx(M9,{channels:t}),c.jsx(L9,{skills:n})]})]})}function $v({status:e,onRetry:t}){const{t:n}=se("console"),{t:r}=se("common"),s=e==="reconnecting";return c.jsx("div",{className:"flex flex-col items-center justify-center py-12",children:c.jsxs("div",{className:"w-full max-w-md rounded-lg border border-amber-500/30 bg-amber-500/5 p-6",children:[c.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[s?c.jsx(Mt,{className:"h-8 w-8 animate-spin text-amber-500"}):c.jsx(Ag,{className:"h-8 w-8 text-amber-500"}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:n("dashboard.connectionGuide.title")}),c.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:n(s?"dashboard.connectionGuide.reconnecting":"dashboard.connectionGuide.subtitle")})]})]}),c.jsxs("ol",{className:"mb-5 space-y-2.5 text-sm text-gray-600 dark:text-gray-300",children:[c.jsxs("li",{className:"flex items-start gap-2",children:[c.jsx("span",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-amber-500/20 text-xs font-bold text-amber-600 dark:text-amber-400",children:"1"}),c.jsx("span",{children:n("dashboard.connectionGuide.step1")})]}),c.jsxs("li",{className:"flex items-start gap-2",children:[c.jsx("span",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-amber-500/20 text-xs font-bold text-amber-600 dark:text-amber-400",children:"2"}),c.jsx("span",{children:n("dashboard.connectionGuide.step2")})]}),c.jsxs("li",{className:"flex items-start gap-2",children:[c.jsx("span",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-amber-500/20 text-xs font-bold text-amber-600 dark:text-amber-400",children:"3"}),c.jsx("span",{children:n("dashboard.connectionGuide.step3")})]})]}),c.jsxs("div",{className:"mb-4 rounded-md bg-gray-900/60 px-3 py-2 font-mono text-xs text-gray-300",children:[c.jsxs("p",{className:"text-gray-500",children:["# ",n("dashboard.connectionGuide.cmdComment")]}),c.jsx("p",{children:"openclaw-office --token <your-token>"})]}),c.jsx("button",{type:"button",onClick:t,className:"w-full rounded-md bg-amber-500/90 px-4 py-2 text-sm font-medium text-white hover:bg-amber-500 transition-colors",children:r("actions.retry")})]})})}function Mh({title:e,description:t,onRefresh:n,loading:r}){const{t:s}=se("common");return c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:t})]}),c.jsxs("button",{type:"button",onClick:n,disabled:r,className:"flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:[c.jsx(Rn,{className:`h-3.5 w-3.5 ${r?"animate-spin":""}`}),s("actions.refresh")]})]})}function H9(){const{t:e}=se("console"),t=Ee(n=>n.status);return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-4 text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.about.title")}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"text-center py-2",children:[c.jsx("p",{className:"text-lg font-bold text-gray-900 dark:text-gray-100",children:e("settings.about.appName")}),c.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:e("settings.about.tagline")}),(t==null?void 0:t.version)&&c.jsxs("p",{className:"mt-1 text-xs text-gray-400 dark:text-gray-500",children:[e("settings.about.version"),": ",t.version]})]}),c.jsxs("div",{className:"flex justify-center gap-4 pt-2",children:[c.jsxs("a",{href:"https://docs.openclaw.ai",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-blue-600 hover:underline dark:text-blue-400",children:[c.jsx(Oc,{className:"h-3.5 w-3.5"}),e("settings.about.docs")]}),c.jsxs("a",{href:"https://github.com/openclaw/openclaw",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-blue-600 hover:underline dark:text-blue-400",children:[c.jsx(Oc,{className:"h-3.5 w-3.5"}),e("settings.about.github")]})]})]})]})}const qv="openclaw-console-theme",Kv="openclaw-console-lang",Pv="openclaw-console-dev-mode";function Fv(e,t){return typeof window>"u"?t:localStorage.getItem(e)??t}function B9(e,t){if(typeof window>"u")return t;const n=localStorage.getItem(e);return n===null?t:n==="true"}const Cl=Mn(e=>({theme:Fv(qv,"system"),language:Fv(Kv,"zh"),devModeUnlocked:B9(Pv,!1),setTheme:t=>{localStorage.setItem(qv,t),e({theme:t})},setLanguage:t=>{localStorage.setItem(Kv,t),e({language:t})},setDevModeUnlocked:t=>{localStorage.setItem(Pv,String(t)),e({devModeUnlocked:t})}}));function U9(){const{t:e}=se("console"),t=Cl(r=>r.devModeUnlocked),n=Cl(r=>r.setDevModeUnlocked);return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-4 text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.advanced.title")}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:e("settings.advanced.devMode")}),c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:e("settings.advanced.devModeHint")})]}),c.jsx("button",{type:"button",role:"switch","aria-checked":t,onClick:()=>n(!t),className:`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors ${t?"bg-blue-600":"bg-gray-300 dark:bg-gray-600"}`,children:c.jsx("span",{className:`inline-block h-4 w-4 rounded-full bg-white shadow transition-transform ${t?"translate-x-6":"translate-x-1"}`})})]})]})}const $9=[{value:"light",icon:J4,labelKey:"settings.appearance.themeLight"},{value:"dark",icon:A4,labelKey:"settings.appearance.themeDark"},{value:"system",icon:C4,labelKey:"settings.appearance.themeSystem"}],q9=[{value:"zh",labelKey:"settings.appearance.langZh"},{value:"en",labelKey:"settings.appearance.langEn"}];function K9(){return typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function P9(){const{t:e,i18n:t}=se("console"),n=Cl(u=>u.theme),r=Cl(u=>u.setTheme),s=ie(u=>u.setTheme),o=u=>{r(u);const f=u==="system"?K9():u;s(f)};return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-4 text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.appearance.title")}),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:e("settings.appearance.theme")}),c.jsx("div",{className:"flex gap-1 rounded-lg border border-gray-200 p-1 dark:border-gray-600",children:$9.map(({value:u,icon:f,labelKey:h})=>c.jsxs("button",{type:"button",onClick:()=>o(u),className:`flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors ${n===u?"bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300":"text-gray-600 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"}`,children:[c.jsx(f,{className:"h-3.5 w-3.5"}),e(h)]},u))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:e("settings.appearance.language")}),c.jsx("div",{className:"flex gap-1 rounded-lg border border-gray-200 p-1 dark:border-gray-600",children:q9.map(({value:u,labelKey:f})=>c.jsx("button",{type:"button",onClick:()=>t.changeLanguage(u),className:`rounded-md px-3 py-1.5 text-xs font-medium transition-colors ${t.language===u?"bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300":"text-gray-600 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"}`,children:e(f)},u))})]})]})]})}const rm=["openai-completions","openai-responses","openai-codex-responses","anthropic-messages","google-generative-ai","github-copilot","bedrock-converse-stream","ollama"],F9=["text","image"],G9=["openai","zai","qwen"],V9=["max_completion_tokens","max_tokens"];function Y9(){return{id:"",name:"",reasoning:!1,input:["text"],cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:128e3,maxTokens:8192}}const Xt=[{id:"anthropic",name:"Anthropic",icon:"🤖",defaultBaseUrl:"https://api.anthropic.com",defaultApi:"anthropic-messages",requiresApiKey:!0,placeholder:"sk-ant-..."},{id:"openai",name:"OpenAI",icon:"🧠",defaultBaseUrl:"https://api.openai.com/v1",defaultApi:"openai-responses",requiresApiKey:!0,placeholder:"sk-..."},{id:"openai-codex",name:"OpenAI Codex",icon:"🧬",defaultBaseUrl:"https://api.openai.com/v1",defaultApi:"openai-codex-responses",requiresApiKey:!1},{id:"google",name:"Google AI",icon:"🔮",defaultBaseUrl:"https://generativelanguage.googleapis.com",defaultApi:"google-generative-ai",requiresApiKey:!0},{id:"openrouter",name:"OpenRouter",icon:"🔀",defaultBaseUrl:"https://openrouter.ai/api/v1",defaultApi:"openai-completions",requiresApiKey:!0,placeholder:"sk-or-..."},{id:"deepseek",name:"DeepSeek",icon:"🔍",defaultBaseUrl:"https://api.deepseek.com/v1",defaultApi:"openai-completions",requiresApiKey:!0,placeholder:"sk-..."},{id:"moonshot",name:"Moonshot (CN)",icon:"🌙",defaultBaseUrl:"https://api.moonshot.cn/v1",defaultApi:"openai-completions",requiresApiKey:!0,placeholder:"sk-..."},{id:"qwen",name:"通义千问 (CN)",icon:"🌐",defaultBaseUrl:"https://dashscope.aliyuncs.com/compatible-mode/v1",defaultApi:"openai-completions",requiresApiKey:!0,placeholder:"sk-..."},{id:"siliconflow",name:"SiliconFlow (CN)",icon:"⚡",defaultBaseUrl:"https://api.siliconflow.cn/v1",defaultApi:"openai-completions",requiresApiKey:!0,placeholder:"sk-..."},{id:"ollama",name:"Ollama",icon:"🦙",defaultBaseUrl:"http://localhost:11434",defaultApi:"ollama",requiresApiKey:!1},{id:"bedrock",name:"AWS Bedrock",icon:"☁️",defaultBaseUrl:"",defaultApi:"bedrock-converse-stream",requiresApiKey:!1},{id:"github-copilot",name:"GitHub Copilot",icon:"🐙",defaultBaseUrl:"",defaultApi:"github-copilot",requiresApiKey:!1},{id:"custom",name:"Custom",icon:"⚙️",defaultBaseUrl:"",defaultApi:"openai-completions",requiresApiKey:!0}];function im(e,t,n){const r=Xt.find(s=>s.id===e);if(r)return r;if(t){const s=Xt.find(o=>o.defaultApi===t);if(s)return s}if(n){if(n.includes("anthropic.com"))return Xt[0];if(n.includes("openai.com"))return Xt[1];if(n.includes("googleapis.com"))return Xt[2];if(n.includes("openrouter.ai"))return Xt[3];if(n.includes("deepseek.com"))return Xt[4];if(n.includes("moonshot.cn"))return Xt[5];if(n.includes("dashscope.aliyuncs.com"))return Xt[6];if(n.includes("siliconflow.cn"))return Xt[7];if(n.includes("localhost:11434"))return Xt[8]}return Xt[Xt.length-1]}const sm="__OPENCLAW_REDACTED__";function Q9(e){return Array.isArray(e)?e.map(t=>({id:String(t.id??""),name:String(t.name??""),api:t.api,reasoning:t.reasoning===!0,input:Array.isArray(t.input)?t.input:["text"],cost:t.cost?{input:Number(t.cost.input??0),output:Number(t.cost.output??0),cacheRead:Number(t.cost.cacheRead??0),cacheWrite:Number(t.cost.cacheWrite??0)}:void 0,contextWindow:typeof t.contextWindow=="number"?t.contextWindow:void 0,maxTokens:typeof t.maxTokens=="number"?t.maxTokens:void 0,compat:t.compat})):[]}function Ow(e){const t={id:e.id,name:e.name,reasoning:e.reasoning??!1,input:e.input??["text"]};return e.api&&(t.api=e.api),e.cost&&(t.cost=e.cost),e.contextWindow&&(t.contextWindow=e.contextWindow),e.maxTokens&&(t.maxTokens=e.maxTokens),e.compat&&(t.compat=e.compat),e.headers&&(t.headers=e.headers),t}function W9(){var j;const{t:e}=se("console"),t=Ee(N=>N.config),n=Ee(N=>N.configPath),r=Ee(N=>N.status),s=Ee(N=>N.configRaw),o=(r==null?void 0:r.configPath)??n,[u,f]=S.useState(!1),[h,g]=S.useState(null),y=(j=t==null?void 0:t.gateway)==null?void 0:j.auth,p=(y==null?void 0:y.token)===sm,b="/gateway-ws",v=b.startsWith("/")?`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}${b}`:b,k=(N,C)=>{navigator.clipboard.writeText(N),g(C),setTimeout(()=>g(null),2e3)};return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-4 text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.developer.title")}),c.jsxs("div",{className:"space-y-3",children:[c.jsx(Oh,{label:e("settings.developer.gatewayToken"),value:p?e("settings.developer.tokenConfigured"):"—",hint:e("settings.developer.tokenHint")}),c.jsx(Oh,{label:e("settings.developer.configPath"),value:o??"—",copyable:!0,onCopy:()=>o&&k(o,"path"),copied:h==="path",copiedLabel:e("settings.developer.copied")}),c.jsx(Oh,{label:e("settings.developer.wsUrl"),value:v,copyable:!0,onCopy:()=>k(v,"ws"),copied:h==="ws",copiedLabel:e("settings.developer.copied")}),s&&c.jsxs("div",{children:[c.jsxs("button",{type:"button",onClick:()=>f(!u),className:"flex items-center gap-1.5 text-sm text-blue-600 hover:underline dark:text-blue-400",children:[u?c.jsx(wg,{className:"h-4 w-4"}):c.jsx(qn,{className:"h-4 w-4"}),e(u?"settings.developer.hideConfig":"settings.developer.showConfig")," ",e("settings.developer.rawConfig")]}),u&&c.jsx("pre",{className:"mt-2 max-h-64 overflow-auto rounded-md bg-gray-100 p-3 text-xs text-gray-800 dark:bg-gray-900 dark:text-gray-300",children:s})]})]})]})}function Oh({label:e,value:t,hint:n,copyable:r,onCopy:s,copied:o,copiedLabel:u}){return c.jsxs("div",{className:"flex items-center justify-between rounded-md bg-gray-50 px-3 py-2 dark:bg-gray-700/50",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:e}),c.jsx("p",{className:"text-sm font-mono text-gray-900 dark:text-gray-100 truncate",children:t}),n&&c.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 mt-0.5",children:n})]}),r&&s&&c.jsx("button",{type:"button",onClick:s,className:"shrink-0 rounded p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors",title:u,children:o?c.jsx(Tr,{className:"h-4 w-4 text-green-500"}):c.jsx(jg,{className:"h-4 w-4"})})]})}function X9(){const{t:e}=se("console"),t=Ee(f=>f.status),n=Ee(f=>f.statusLoading),r=Ee(f=>f.statusError),s=Ee(f=>f.fetchStatus),o=t!=null&&t.uptime?Math.floor(t.uptime/3600):0,u=t!=null&&t.uptime?Math.floor(t.uptime%3600/60):0;return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsx("h3",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.gateway.title")}),c.jsxs("button",{type:"button",onClick:s,disabled:n,className:"flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:[c.jsx(Rn,{className:`h-3.5 w-3.5 ${n?"animate-spin":""}`}),e("settings.gateway.refresh")]})]}),r?c.jsxs("div",{className:"flex items-center gap-3 rounded-lg bg-amber-50 px-4 py-3 dark:bg-amber-900/20",children:[c.jsx(Ag,{className:"h-5 w-5 text-amber-500 shrink-0"}),c.jsxs("div",{children:[c.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-300",children:e("settings.gateway.notConnected")}),c.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:e("settings.gateway.notConnectedHint")})]})]}):t?c.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-3",children:[c.jsx(Oi,{label:e("settings.gateway.version"),value:t.version??"—"}),c.jsx(Oi,{label:e("settings.gateway.port"),value:t.port!=null?String(t.port):"—"}),c.jsx(Oi,{label:e("settings.gateway.uptime"),value:t.uptime!=null?e("settings.gateway.uptimeFormat",{hours:o,minutes:u}):"—"}),c.jsx(Oi,{label:e("settings.gateway.mode"),value:t.mode??"—"}),c.jsx(Oi,{label:e("settings.gateway.nodeVersion"),value:t.nodeVersion??"—"}),c.jsx(Oi,{label:e("settings.gateway.platform"),value:t.platform??"—"})]}):null]})}function Oi({label:e,value:t}){return c.jsxs("div",{className:"rounded-md bg-gray-50 px-3 py-2 dark:bg-gray-700/50",children:[c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:e}),c.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:t})]})}function Z9({model:e,onChange:t,onRemove:n,defaultCollapsed:r=!1}){var k,j,N;const{t:s}=se("console"),[o,u]=S.useState(r),[f,h]=S.useState(!1),g=C=>t({...e,...C}),y=(C,E)=>{const R=e.cost??{input:0,output:0,cacheRead:0,cacheWrite:0};t({...e,cost:{...R,[C]:E}})},p=C=>{const E=e.input??["text"],R=E.includes(C)?E.filter(H=>H!==C):[...E,C];R.length!==0&&g({input:R})},b=C=>{t({...e,compat:{...e.compat??{},...C}})},v=e.name||e.id||s("settings.providers.models.untitled");return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50/50 dark:border-gray-600 dark:bg-gray-700/30",children:[c.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[c.jsxs("button",{type:"button",onClick:()=>u(!o),className:"flex items-center gap-2 text-sm font-medium text-gray-800 dark:text-gray-200",children:[o?c.jsx(qn,{className:"h-4 w-4"}):c.jsx(wg,{className:"h-4 w-4"}),c.jsx("span",{className:"truncate max-w-xs",children:v}),e.reasoning&&c.jsx("span",{title:"reasoning",children:c.jsx(Mc,{className:"h-3.5 w-3.5 text-purple-500"})}),((k=e.input)==null?void 0:k.includes("image"))&&c.jsx("span",{title:"image",children:c.jsx(_c,{className:"h-3.5 w-3.5 text-green-500"})})]}),c.jsx("button",{type:"button",onClick:n,className:"rounded p-1 text-gray-400 hover:bg-red-100 hover:text-red-500 dark:hover:bg-red-900/30 transition-colors",title:s("settings.providers.models.remove"),children:c.jsx(Dl,{className:"h-4 w-4"})})]}),!o&&c.jsxs("div",{className:"space-y-4 border-t border-gray-200 px-4 py-4 dark:border-gray-600",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsx(Yn,{label:s("settings.providers.models.id"),children:c.jsx("input",{type:"text",value:e.id,onChange:C=>g({id:C.target.value}),className:tl,placeholder:"gpt-4o"})}),c.jsx(Yn,{label:s("settings.providers.models.name"),children:c.jsx("input",{type:"text",value:e.name,onChange:C=>g({name:C.target.value}),className:tl,placeholder:"GPT-4o"})})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsx(Yn,{label:s("settings.providers.models.reasoning"),children:c.jsx(Gv,{active:e.reasoning===!0,onClick:()=>g({reasoning:!e.reasoning}),icon:c.jsx(Mc,{className:"h-4 w-4"}),label:e.reasoning?s("settings.providers.models.yes"):s("settings.providers.models.no")})}),c.jsx(Yn,{label:s("settings.providers.models.inputTypes"),children:c.jsx("div",{className:"flex gap-2",children:F9.map(C=>c.jsx(Gv,{active:(e.input??["text"]).includes(C),onClick:()=>p(C),icon:C==="text"?c.jsx(s3,{className:"h-4 w-4"}):c.jsx(_c,{className:"h-4 w-4"}),label:s(`settings.providers.models.input_${C}`)},C))})})]}),c.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[c.jsx(Yn,{label:s("settings.providers.models.apiOverride"),children:c.jsxs("div",{className:"relative",children:[c.jsxs("select",{value:e.api??"",onChange:C=>g({api:C.target.value?C.target.value:void 0}),className:_h,"aria-label":s("settings.providers.models.apiOverride"),children:[c.jsx("option",{value:"",children:s("settings.providers.models.inheritProvider")}),rm.map(C=>c.jsx("option",{value:C,children:C},C))]}),c.jsx(Lh,{})]})}),c.jsx(Yn,{label:s("settings.providers.models.contextWindow"),children:c.jsx("input",{type:"number",value:e.contextWindow??"",onChange:C=>g({contextWindow:C.target.value?Number(C.target.value):void 0}),className:tl,placeholder:"128000",min:1})}),c.jsx(Yn,{label:s("settings.providers.models.maxTokens"),children:c.jsx("input",{type:"number",value:e.maxTokens??"",onChange:C=>g({maxTokens:C.target.value?Number(C.target.value):void 0}),className:tl,placeholder:"8192",min:1})})]}),c.jsxs(Yn,{label:s("settings.providers.models.cost"),children:[c.jsx("p",{className:"mb-2 text-xs text-gray-500 dark:text-gray-400",children:s("settings.providers.models.costHint")}),c.jsx("div",{className:"grid grid-cols-4 gap-3",children:["input","output","cacheRead","cacheWrite"].map(C=>{var E;return c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-xs text-gray-500 dark:text-gray-400",children:s(`settings.providers.models.cost_${C}`)}),c.jsx("input",{type:"number",value:((E=e.cost)==null?void 0:E[C])??"",onChange:R=>y(C,R.target.value?Number(R.target.value):0),className:tl,placeholder:"0",min:0,step:"0.01"})]},C)})})]}),c.jsxs("div",{children:[c.jsxs("button",{type:"button",onClick:()=>h(!f),className:"flex items-center gap-1 text-xs text-blue-600 hover:underline dark:text-blue-400",children:[c.jsx(I1,{className:"h-3 w-3"}),s(f?"settings.providers.models.hideAdvanced":"settings.providers.models.showAdvanced")]}),f&&c.jsxs("div",{className:"mt-3 space-y-3 rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-600 dark:bg-gray-800",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsx(Yn,{label:s("settings.providers.models.thinkingFormat"),children:c.jsxs("div",{className:"relative",children:[c.jsxs("select",{value:((j=e.compat)==null?void 0:j.thinkingFormat)??"",onChange:C=>b({thinkingFormat:C.target.value?C.target.value:void 0}),className:_h,"aria-label":s("settings.providers.models.thinkingFormat"),children:[c.jsx("option",{value:"",children:s("settings.providers.models.default")}),G9.map(C=>c.jsx("option",{value:C,children:C},C))]}),c.jsx(Lh,{})]})}),c.jsx(Yn,{label:s("settings.providers.models.maxTokensField"),children:c.jsxs("div",{className:"relative",children:[c.jsxs("select",{value:((N=e.compat)==null?void 0:N.maxTokensField)??"",onChange:C=>b({maxTokensField:C.target.value?C.target.value:void 0}),className:_h,"aria-label":s("settings.providers.models.maxTokensField"),children:[c.jsx("option",{value:"",children:s("settings.providers.models.default")}),V9.map(C=>c.jsx("option",{value:C,children:C},C))]}),c.jsx(Lh,{})]})})]}),c.jsx("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2",children:["supportsStore","supportsDeveloperRole","supportsReasoningEffort","supportsUsageInStreaming","supportsStrictMode","requiresToolResultName","requiresAssistantAfterToolResult","requiresThinkingAsText","requiresMistralToolIds"].map(C=>{var E;return c.jsxs("label",{className:"flex items-center gap-2 text-xs text-gray-700 dark:text-gray-300",children:[c.jsx("input",{type:"checkbox",checked:((E=e.compat)==null?void 0:E[C])===!0,onChange:R=>b({[C]:R.target.checked||void 0}),className:"rounded border-gray-300 text-blue-600 focus:ring-blue-500"}),s(`settings.providers.models.compat_${C}`)]},C)})})]})]})]})]})}function _w({models:e,onChange:t}){const{t:n}=se("console"),r=()=>{t([...e,Y9()])},s=(u,f)=>{const h=[...e];h[u]=f,t(h)},o=u=>{t(e.filter((f,h)=>h!==u))};return c.jsxs("div",{children:[c.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[c.jsxs("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[n("settings.providers.models.title")," (",e.length,")"]}),c.jsxs("button",{type:"button",onClick:r,className:"flex items-center gap-1 rounded-lg border border-dashed border-gray-300 px-3 py-1.5 text-xs text-gray-600 hover:border-blue-400 hover:text-blue-600 dark:border-gray-500 dark:text-gray-400 dark:hover:border-blue-400 dark:hover:text-blue-400 transition-colors",children:[c.jsx(En,{className:"h-3.5 w-3.5"}),n("settings.providers.models.add")]})]}),e.length===0?c.jsx("div",{className:"rounded-lg border border-dashed border-gray-300 px-4 py-6 text-center text-sm text-gray-400 dark:border-gray-600",children:n("settings.providers.models.empty")}):c.jsx("div",{className:"space-y-2",children:e.map((u,f)=>c.jsx(Z9,{model:u,onChange:h=>s(f,h),onRemove:()=>o(f),defaultCollapsed:u.id.length>0},f))})]})}const tl="w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors",_h="w-full appearance-none rounded-lg border border-gray-300 bg-white px-3 py-2 pr-8 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors";function Lh(){return c.jsx(qn,{className:"pointer-events-none absolute right-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"})}function Yn({label:e,children:t}){return c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-xs font-medium text-gray-600 dark:text-gray-400",children:e}),t]})}function Gv({active:e,onClick:t,icon:n,label:r}){return c.jsxs("button",{type:"button",onClick:t,className:`flex items-center gap-1.5 rounded-lg border px-3 py-2 text-xs font-medium transition-colors ${e?"border-blue-500 bg-blue-50 text-blue-700 dark:border-blue-400 dark:bg-blue-900/30 dark:text-blue-300":"border-gray-300 bg-white text-gray-500 hover:border-gray-400 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-400"}`,children:[n,r]})}function J9({open:e,existingIds:t,onSave:n,onCancel:r}){const{t:s}=se("console"),o=S.useRef(null),[u,f]=S.useState(1),[h,g]=S.useState(null),[y,p]=S.useState(""),[b,v]=S.useState(""),[k,j]=S.useState(""),[N,C]=S.useState("openai-completions"),[E,R]=S.useState(!1),[H,z]=S.useState([]);S.useEffect(()=>{const M=o.current;M&&(e&&!M.open?(M.showModal(),f(1),g(null),p(""),v(""),j(""),C("openai-completions"),R(!1),z([])):!e&&M.open&&M.close())},[e]);const L=M=>{g(M),p(M.id==="custom"?"":M.id),v(M.defaultBaseUrl),C(M.defaultApi),f(2)},G=t.includes(y),W=y.length>0&&!G,P=M=>{if(!W)return;const $={baseUrl:b,api:N,models:H.filter(V=>V.id.length>0).map(Ow)};k&&($.apiKey=k),n(y,$,M)};return c.jsx("dialog",{ref:o,onClose:r,className:"fixed inset-0 z-50 m-auto w-[92vw] max-w-3xl max-h-[90vh] overflow-y-auto rounded-xl border border-gray-200 bg-white p-0 shadow-2xl backdrop:bg-black/50 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-8",children:[u===1&&c.jsxs("div",{children:[c.jsx("h3",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:s("settings.providers.addDialog.title")}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:s("settings.providers.addDialog.selectType")}),c.jsx("div",{className:"mt-6 grid grid-cols-3 gap-3 sm:grid-cols-4",children:Xt.map(M=>c.jsxs("button",{type:"button",onClick:()=>L(M),className:"flex flex-col items-center gap-2 rounded-xl border border-gray-200 px-4 py-5 text-center hover:border-blue-400 hover:bg-blue-50/80 dark:border-gray-600 dark:hover:border-blue-500 dark:hover:bg-blue-900/20 transition-all",children:[c.jsx("span",{className:"text-2xl",children:M.icon}),c.jsx("span",{className:"text-sm font-medium text-gray-800 dark:text-gray-200",children:M.name})]},M.id))}),c.jsx("div",{className:"mt-6 flex justify-end",children:c.jsx("button",{type:"button",onClick:r,className:"rounded-lg border border-gray-300 px-5 py-2.5 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:s("settings.providers.addDialog.cancel")})})]}),u===2&&h&&c.jsxs("div",{children:[c.jsxs("div",{className:"mb-6 flex items-center gap-3",children:[c.jsx("button",{type:"button",onClick:()=>f(1),className:"rounded-lg p-2 text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors",children:c.jsx(E1,{className:"h-5 w-5"})}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-2xl",children:h.icon}),c.jsxs("h3",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:[s("settings.providers.addDialog.title")," — ",h.name]})]})]}),c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:s("settings.providers.addDialog.providerId")}),c.jsx("input",{type:"text",value:y,onChange:M=>p(M.target.value.replace(/\s/g,"-").toLowerCase()),className:zh,placeholder:h.id}),c.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:s("settings.providers.addDialog.providerIdHint")}),G&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:s("settings.providers.addDialog.idConflict")})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:s("settings.providers.addDialog.apiType")}),c.jsxs("div",{className:"relative",children:[c.jsx("select",{value:N,onChange:M=>C(M.target.value),className:e7,children:rm.map(M=>c.jsx("option",{value:M,children:M},M))}),c.jsx(qn,{className:"pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"})]})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:s("settings.providers.addDialog.baseUrl")}),c.jsx("input",{type:"text",value:b,onChange:M=>v(M.target.value),className:zh,placeholder:"https://api.example.com/v1"})]}),h.requiresApiKey&&c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:s("settings.providers.addDialog.apiKey")}),c.jsxs("div",{className:"relative",children:[c.jsx("input",{type:E?"text":"password",value:k,onChange:M=>j(M.target.value),className:`${zh} pr-11`,placeholder:h.placeholder??"sk-..."}),c.jsx("button",{type:"button",onClick:()=>R(!E),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors",children:E?c.jsx(nu,{className:"h-4 w-4"}):c.jsx(au,{className:"h-4 w-4"})})]})]}),c.jsx("hr",{className:"border-gray-200 dark:border-gray-600"}),c.jsx(_w,{models:H,onChange:z})]}),c.jsxs("div",{className:"mt-8 flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:r,className:"rounded-lg border border-gray-300 px-5 py-2.5 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:s("settings.providers.addDialog.cancel")}),c.jsx("button",{type:"button",onClick:()=>P("save"),disabled:!W,className:"rounded-lg bg-blue-600 px-5 py-2.5 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:s("settings.providers.addDialog.save")}),c.jsx("button",{type:"button",onClick:()=>P("apply"),disabled:!W,className:"rounded-lg border border-blue-200 px-5 py-2.5 text-sm font-medium text-blue-700 hover:bg-blue-50 disabled:opacity-50 disabled:cursor-not-allowed transition-colors dark:border-blue-800 dark:text-blue-300 dark:hover:bg-blue-900/20",children:s("settings.providers.addDialog.saveAndRestart")})]})]})]})})}const zh="w-full rounded-lg border border-gray-300 bg-white px-4 py-2.5 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors",e7="w-full appearance-none rounded-lg border border-gray-300 bg-white px-4 py-2.5 pr-10 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors";function t7({providerId:e,models:t}){const{t:n}=se("console"),r=im(e),s=t.filter(u=>u.reasoning===!0).length,o=t.filter(u=>{var f;return(f=u.input)==null?void 0:f.includes("image")}).length;return c.jsx("div",{className:"rounded-lg border border-dashed border-emerald-300 bg-emerald-50/50 px-4 py-3 dark:border-emerald-700 dark:bg-emerald-900/10",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[c.jsx("span",{className:"text-xl",title:r.name,children:r.icon}),c.jsxs("div",{className:"min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 truncate",children:e}),r.id!==e&&c.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["(",r.name,")"]}),c.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-emerald-100 px-2 py-0.5 text-xs font-medium text-emerald-700 dark:bg-emerald-800/40 dark:text-emerald-300",children:[c.jsx(F4,{className:"h-3 w-3"}),n("settings.providers.systemDiscovered")]})]}),c.jsx("div",{className:"mt-0.5 flex flex-wrap gap-1.5",children:t.map(u=>c.jsx("span",{className:"inline-block rounded bg-gray-100 px-1.5 py-0.5 text-xs text-gray-600 dark:bg-gray-700 dark:text-gray-300",title:`${e}/${u.id}`,children:u.name||u.id},u.id))})]})]}),c.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[t.length>0&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:n("settings.providers.modelCount",{count:t.length})}),s>0&&c.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-purple-600 dark:text-purple-400",title:n("settings.providers.models.reasoning"),children:[c.jsx(Mc,{className:"h-3 w-3"}),s]}),o>0&&c.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-green-600 dark:text-green-400",title:n("settings.providers.models.input_image"),children:[c.jsx(_c,{className:"h-3 w-3"}),o]})]}),c.jsx("span",{className:"flex items-center gap-1 text-xs text-emerald-600 dark:text-emerald-400",children:r.requiresApiKey?"OAuth":n("settings.providers.apiKeyConfigured")})]})]})})}function n7({open:e,providerId:t,config:n,onSave:r,onCancel:s}){const{t:o}=se("console"),u=S.useRef(null),f=im(t,n.api,n.baseUrl),[h,g]=S.useState(String(n.baseUrl??"")),[y,p]=S.useState(""),[b,v]=S.useState(n.api??"openai-completions"),[k,j]=S.useState(!1),[N,C]=S.useState(()=>Q9(n.models));S.useEffect(()=>{const z=u.current;z&&(e&&!z.open?z.showModal():!e&&z.open&&z.close())},[e]);const E=z=>{const L={baseUrl:h,api:b,models:N.filter(G=>G.id.length>0).map(Ow)};y.length>0&&(L.apiKey=y),r(L,z)},H=typeof n.auth=="string"&&n.auth.length>0||n.apiKey===sm||typeof n.apiKey=="string"&&n.apiKey.length>0;return c.jsx("dialog",{ref:u,onClose:s,className:"fixed inset-0 z-50 m-auto w-[92vw] max-w-3xl max-h-[90vh] overflow-y-auto rounded-xl border border-gray-200 bg-white p-0 shadow-2xl backdrop:bg-black/50 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-8",children:[c.jsxs("div",{className:"mb-6 flex items-center gap-3",children:[c.jsx("span",{className:"text-2xl",children:f.icon}),c.jsxs("div",{children:[c.jsxs("h3",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:[o("settings.providers.editDialog.title")," — ",t]}),f.id!==t&&c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:f.name})]})]}),c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:o("settings.providers.addDialog.apiType")}),c.jsxs("div",{className:"relative",children:[c.jsx("select",{value:b,onChange:z=>v(z.target.value),className:a7,children:rm.map(z=>c.jsx("option",{value:z,children:z},z))}),c.jsx(qn,{className:"pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:o("settings.providers.addDialog.baseUrl")}),c.jsx("input",{type:"text",value:h,onChange:z=>g(z.target.value),className:Vv})]})]}),f.requiresApiKey&&c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:o("settings.providers.addDialog.apiKey")}),c.jsxs("div",{className:"relative",children:[c.jsx("input",{type:k?"text":"password",value:y,onChange:z=>p(z.target.value),className:`${Vv} pr-11`,placeholder:H?o("settings.providers.editDialog.apiKeyPlaceholder"):f.placeholder}),c.jsx("button",{type:"button",onClick:()=>j(!k),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors",children:k?c.jsx(nu,{className:"h-4 w-4"}):c.jsx(au,{className:"h-4 w-4"})})]}),H&&!y&&c.jsx("p",{className:"mt-1 text-xs text-green-600 dark:text-green-400",children:o("settings.providers.apiKeyConfigured")})]}),c.jsx("hr",{className:"border-gray-200 dark:border-gray-600"}),c.jsx(_w,{models:N,onChange:C})]}),c.jsxs("div",{className:"mt-8 flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:s,className:"rounded-lg border border-gray-300 px-5 py-2.5 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:o("settings.providers.editDialog.cancel")}),c.jsx("button",{type:"button",onClick:()=>E("save"),className:"rounded-lg bg-blue-600 px-5 py-2.5 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:o("settings.providers.editDialog.save")}),c.jsx("button",{type:"button",onClick:()=>E("apply"),className:"rounded-lg border border-blue-200 px-5 py-2.5 text-sm font-medium text-blue-700 hover:bg-blue-50 transition-colors dark:border-blue-800 dark:text-blue-300 dark:hover:bg-blue-900/20",children:o("settings.providers.editDialog.saveAndRestart")})]})]})})}const Vv="w-full rounded-lg border border-gray-300 bg-white px-4 py-2.5 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors",a7="w-full appearance-none rounded-lg border border-gray-300 bg-white px-4 py-2.5 pr-10 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors";function r7({providerId:e,config:t,onEdit:n,onDelete:r}){const{t:s}=se("console"),o=im(e,t.api,t.baseUrl),f=typeof t.auth=="string"&&t.auth.length>0||t.apiKey===sm||typeof t.apiKey=="string"&&t.apiKey.length>0,h=Array.isArray(t.models)?t.models:[],g=h.filter(p=>p.reasoning===!0).length,y=h.filter(p=>Array.isArray(p.input)&&p.input.includes("image")).length;return c.jsx("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-4 py-3 dark:border-gray-600 dark:bg-gray-700/50",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[c.jsx("span",{className:"text-xl",title:o.name,children:o.icon}),c.jsxs("div",{className:"min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 truncate",children:e}),o.id!==e&&c.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["(",o.name,")"]})]}),c.jsxs("div",{className:"flex items-center gap-3 text-xs text-gray-500 dark:text-gray-400",children:[typeof t.baseUrl=="string"&&t.baseUrl&&c.jsx("span",{className:"truncate max-w-48",title:t.baseUrl,children:t.baseUrl}),typeof t.api=="string"&&c.jsx("span",{children:t.api})]})]})]}),c.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[h.length>0&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:s("settings.providers.modelCount",{count:h.length})}),g>0&&c.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-purple-600 dark:text-purple-400",title:s("settings.providers.models.reasoning"),children:[c.jsx(Mc,{className:"h-3 w-3"}),g]}),y>0&&c.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-green-600 dark:text-green-400",title:s("settings.providers.models.input_image"),children:[c.jsx(_c,{className:"h-3 w-3"}),y]})]}),o.requiresApiKey&&c.jsx("span",{className:"flex items-center gap-1 text-xs",children:f?c.jsxs(c.Fragment,{children:[c.jsx(qi,{className:"h-3.5 w-3.5 text-green-500"}),c.jsx("span",{className:"text-green-600 dark:text-green-400",children:s("settings.providers.apiKeyConfigured")})]}):c.jsxs(c.Fragment,{children:[c.jsx(tu,{className:"h-3.5 w-3.5 text-amber-500"}),c.jsx("span",{className:"text-amber-600 dark:text-amber-400",children:s("settings.providers.apiKeyNotConfigured")})]})}),c.jsx("button",{type:"button",onClick:n,className:"rounded p-1.5 text-gray-500 hover:bg-gray-200 hover:text-gray-700 dark:hover:bg-gray-600 dark:hover:text-gray-300 transition-colors",title:"Edit",children:c.jsx(M1,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:r,className:"rounded p-1.5 text-gray-500 hover:bg-red-100 hover:text-red-600 dark:hover:bg-red-900/30 dark:hover:text-red-400 transition-colors",title:"Delete",children:c.jsx(Dl,{className:"h-4 w-4"})})]})]})})}function i7(e){if(!e)return{};const t=e.models;return(t==null?void 0:t.providers)??{}}function s7(e,t){const n=new Map;for(const r of e)t.has(r.provider)||(n.has(r.provider)||n.set(r.provider,[]),n.get(r.provider).push(r));return n}function l7(){const{t:e}=se("console"),t=Ee(H=>H.config),n=Ee(H=>H.saveConfig),r=Ee(H=>H.applyConfig),s=Ee(H=>H.catalogModels),o=Ee(H=>H.fetchCatalogModels),[u,f]=S.useState(!1),[h,g]=S.useState(null),[y,p]=S.useState(null);S.useEffect(()=>{s.length===0&&o()},[s.length,o]);const b=i7(t),v=Object.entries(b),k=new Set(Object.keys(b)),j=s7(s,k),N=async(H,z,L)=>{await(L==="apply"?r:n)(W=>{const P=W,M=P.models??{},$=M.providers??{};return P.models={...M,providers:{...$,[H]:z}},P}),f(!1)},C=async(H,z)=>{if(!h)return;await(z==="apply"?r:n)(G=>{const W=G,P=W.models??{},M=P.providers??{};return W.models={...P,providers:{...M,[h.id]:H}},W}),g(null)},E=async()=>{y&&(await n(H=>{const z=H,L=z.models??{},G={...L.providers??{}};return delete G[y],z.models={...L,providers:G},z}),p(null))},R=v.length>0||j.size>0;return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("h3",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.providers.title")}),c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:e("settings.providers.description")})]}),c.jsxs("button",{type:"button",onClick:()=>f(!0),className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:[c.jsx(En,{className:"h-4 w-4"}),e("settings.providers.add")]})]}),R?c.jsxs("div",{className:"space-y-2",children:[v.map(([H,z])=>c.jsx(r7,{providerId:H,config:z,onEdit:()=>g({id:H,config:z}),onDelete:()=>p(H)},H)),Array.from(j.entries()).map(([H,z])=>c.jsx(t7,{providerId:H,models:z},`catalog-${H}`))]}):c.jsx(Er,{icon:UA,title:e("settings.providers.empty"),description:e("settings.providers.emptyHint")}),c.jsx(J9,{open:u,existingIds:Object.keys(b),onSave:N,onCancel:()=>f(!1)}),h&&c.jsx(n7,{open:!!h,providerId:h.id,config:h.config,onSave:C,onCancel:()=>g(null)},h.id),c.jsx(jl,{open:!!y,title:e("settings.providers.deleteTitle"),description:e("settings.providers.deleteDescription",{name:y??""}),variant:"danger",onConfirm:E,onCancel:()=>p(null)})]})}function o7(){var y;const{t:e}=se("console"),t=Ee(p=>p.status),n=Ee(p=>p.config),r=Ee(p=>p.updateResult),s=Ee(p=>p.updateLoading),o=Ee(p=>p.runUpdate),[u,f]=S.useState(!1),h=(y=n==null?void 0:n.update)==null?void 0:y.channel,g=async()=>{f(!1),await o({restartDelayMs:3e3})};return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-4 text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.update.title")}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:e("settings.update.currentVersion")}),c.jsx("span",{className:"text-sm font-mono font-medium text-gray-900 dark:text-gray-100",children:(t==null?void 0:t.version)??"—"})]}),h&&c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:e("settings.update.channel")}),c.jsx("span",{className:"rounded-full bg-gray-100 px-2.5 py-0.5 text-xs font-medium text-gray-700 dark:bg-gray-700 dark:text-gray-300",children:h})]}),c.jsx("div",{className:"pt-2",children:c.jsx("button",{type:"button",onClick:()=>f(!0),disabled:s,className:"flex items-center gap-2 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50 transition-colors",children:s?c.jsxs(c.Fragment,{children:[c.jsx(Mt,{className:"h-4 w-4 animate-spin"}),e("settings.update.updating")]}):c.jsxs(c.Fragment,{children:[c.jsx(pl,{className:"h-4 w-4"}),e("settings.update.checkUpdate")]})})}),r&&c.jsxs("div",{className:`mt-3 flex items-start gap-2 rounded-lg px-4 py-3 text-sm ${r.result.status==="ok"?"bg-green-50 text-green-800 dark:bg-green-900/20 dark:text-green-300":r.result.status==="noop"?"bg-blue-50 text-blue-800 dark:bg-blue-900/20 dark:text-blue-300":"bg-red-50 text-red-800 dark:bg-red-900/20 dark:text-red-300"}`,children:[r.result.status==="ok"&&c.jsx(qi,{className:"mt-0.5 h-4 w-4 shrink-0"}),r.result.status==="noop"&&c.jsx(ru,{className:"mt-0.5 h-4 w-4 shrink-0"}),r.result.status==="error"&&c.jsx(Pi,{className:"mt-0.5 h-4 w-4 shrink-0"}),c.jsxs("span",{children:[r.result.status==="ok"&&e("settings.update.resultOk",{before:r.result.before??"?",after:r.result.after??"?"}),r.result.status==="noop"&&e("settings.update.resultNoop"),r.result.status==="error"&&e("settings.update.resultError",{reason:r.result.reason??"Unknown error"})]})]})]}),c.jsx(jl,{open:u,title:e("settings.update.confirmTitle"),description:e("settings.update.confirmDescription"),onConfirm:g,onCancel:()=>f(!1)})]})}function c7(){const{t:e}=se("console"),t=Ee(o=>o.loading),n=Ee(o=>o.fetchConfig),r=Ee(o=>o.fetchStatus),s=Cl(o=>o.devModeUnlocked);return S.useEffect(()=>{n(),r()},[n,r]),c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e("settings.title")}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:e("settings.description")})]}),t?c.jsx(zl,{}):c.jsxs("div",{className:"space-y-4",children:[c.jsx(P9,{}),c.jsx(l7,{}),c.jsx(X9,{}),c.jsx(o7,{}),c.jsx(U9,{}),s&&c.jsx(W9,{}),c.jsx(H9,{})]})]})}class er extends Error{constructor(t,n){super(n),this.code=t,this.name="ClawHubError"}}const gg=new Map;function Lw(e){const t=gg.get(e);return t?Date.now()>t.expiresAt?(gg.delete(e),null):t.data:null}function zw(e,t,n){gg.set(e,{data:t,expiresAt:Date.now()+n})}let Iw=0;function u7(){return Date.now()<Iw}const d7=6e4,f7=3e5,h7=5e3;function g7(){return"https://clawhub.ai"}async function lm(e,t){if(u7())throw new er(429,"Rate limited, please wait before retrying");const n=new URL(e,g7());if(t)for(const[s,o]of Object.entries(t))o!==void 0&&o!==""&&n.searchParams.set(s,o);let r;try{r=await fetch(n.toString())}catch(s){throw new er(0,`Network error: ${s instanceof Error?s.message:String(s)}`)}if(r.status===429)throw Iw=Date.now()+h7,new er(429,"Search service is busy, please try again later");if(!r.ok){const s=await r.text().catch(()=>"");throw new er(r.status,s||`HTTP ${r.status}`)}return r.json()}async function m7(e,t=20){return(await lm("/api/v1/search",{q:e,limit:String(t)})).results??[]}async function p7(e){const t=e==null?void 0:e.limit,n=e==null?void 0:e.cursor,r=`explore:${t}:${n??""}`,s=Lw(r);if(s)return s;const o={limit:String(t)};n&&(o.cursor=n);const u=await lm("/api/v1/skills",o),f={items:u.items??[],nextCursor:u.nextCursor??null};return zw(r,f,d7),f}async function y7(e){const t=`detail:${e}`,n=Lw(t);if(n)return n;const r=await lm(`/api/v1/skills/${encodeURIComponent(e)}`);return zw(t,r,f7),r}let ba=null;const sl=Mn((e,t)=>({searchResults:[],exploreItems:[],searchQuery:"",isSearching:!1,isExploring:!1,searchError:null,exploreError:null,nextCursor:null,selectedDetail:null,detailLoading:!1,offlineMode:!1,search:async n=>{if(e({searchQuery:n}),!n.trim()){e({searchResults:[],searchError:null});return}ba&&clearTimeout(ba),ba=setTimeout(()=>{t().searchImmediate(n)},300)},searchImmediate:async n=>{ba&&(clearTimeout(ba),ba=null);const r=n.trim();if(r){e({isSearching:!0,searchError:null,searchQuery:r});try{const s=await m7(r,30);e({searchResults:s,isSearching:!1,offlineMode:!1})}catch(s){const o=s instanceof er?s.message:String(s),u=s instanceof er&&s.code===0;e({searchError:o,isSearching:!1,offlineMode:u})}}},explore:async(n=!1)=>{const r=t();if(!r.isExploring&&!(n&&!r.nextCursor)){e({isExploring:!0,exploreError:null});try{const s=n?r.nextCursor??void 0:void 0,o=await p7({limit:20,cursor:s});e(u=>({exploreItems:n?[...u.exploreItems,...o.items]:o.items,nextCursor:o.nextCursor,isExploring:!1,offlineMode:!1}))}catch(s){const o=s instanceof er?s.message:String(s),u=s instanceof er&&s.code===0;e({exploreError:o,isExploring:!1,offlineMode:u})}}},fetchDetail:async n=>{e({detailLoading:!0});try{const r=await y7(n);e({selectedDetail:r,detailLoading:!1})}catch{e({detailLoading:!1})}},clearSearch:()=>{ba&&(clearTimeout(ba),ba=null),e({searchQuery:"",searchResults:[],searchError:null})},clearDetail:()=>e({selectedDetail:null}),setOfflineMode:n=>e({offlineMode:n})}));function x7({slug:e,onClose:t,onInstall:n,isInstalled:r}){const{t:s}=se("console"),o=sl(b=>b.fetchDetail),u=sl(b=>b.selectedDetail),f=sl(b=>b.detailLoading),h=sl(b=>b.clearDetail);if(S.useEffect(()=>(e&&o(e),()=>{h()}),[e,o,h]),!e)return null;const g=u==null?void 0:u.skill,y=u==null?void 0:u.latestVersion,p=u==null?void 0:u.owner;return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:t,children:c.jsxs("div",{className:"relative mx-4 w-full max-w-lg rounded-2xl border border-gray-200 bg-white shadow-2xl dark:border-gray-700 dark:bg-gray-900",onClick:b=>b.stopPropagation(),children:[c.jsx("button",{type:"button",onClick:t,className:"absolute right-3 top-3 rounded-lg p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",children:c.jsx(An,{className:"h-5 w-5"})}),f?c.jsx("div",{className:"flex h-48 items-center justify-center",children:c.jsx(Mt,{className:"h-6 w-6 animate-spin text-gray-400"})}):g?c.jsxs("div",{className:"p-6",children:[c.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-gray-100",children:g.displayName}),g.summary&&c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:g.summary}),p&&p.handle&&c.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[p.image?c.jsx("img",{src:p.image,alt:"",className:"h-6 w-6 rounded-full"}):c.jsx(o3,{className:"h-5 w-5 text-gray-400"}),c.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-300",children:p.displayName??p.handle})]}),c.jsxs("div",{className:"mt-4 flex flex-wrap gap-4 text-sm text-gray-500 dark:text-gray-400",children:[g.stats.downloads>0&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(pl,{className:"h-4 w-4"}),g.stats.downloads.toLocaleString()," ",s("clawhub.downloads")]}),g.stats.stars>0&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(L1,{className:"h-4 w-4"}),g.stats.stars," ",s("clawhub.stars")]})]}),y&&c.jsxs("div",{className:"mt-4 rounded-xl border border-gray-100 bg-gray-50 p-3 dark:border-gray-700 dark:bg-gray-800",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("span",{className:"text-xs font-medium text-gray-600 dark:text-gray-300",children:["v",y.version]}),c.jsx("span",{className:"text-xs text-gray-400",children:new Date(y.createdAt).toLocaleDateString()})]}),y.changelog&&c.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400 line-clamp-3",children:y.changelog})]}),c.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[r?c.jsx("span",{className:"inline-flex items-center gap-1.5 rounded-lg bg-green-100 px-4 py-2 text-sm font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:s("skills.marketplace.installed")}):c.jsxs("button",{type:"button",onClick:()=>n(g.slug,g.displayName),className:"inline-flex items-center gap-1.5 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:[c.jsx(pl,{className:"h-4 w-4"}),s("skills.card.install")]}),c.jsxs("a",{href:`https://clawhub.ai/skills/${g.slug}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-sm text-blue-600 hover:underline dark:text-blue-400",children:[c.jsx(Oc,{className:"h-3.5 w-3.5"}),s("clawhub.viewOnClawHub")]})]})]}):c.jsx("div",{className:"flex h-48 items-center justify-center text-sm text-gray-500",children:s("clawhub.notFound")})]})})}function b7({open:e,slug:t,displayName:n,onClose:r,onConfirmDone:s}){const{t:o}=se("console"),[u,f]=S.useState(!1);if(!e)return null;const h=`clawhub install ${t}`,g=async()=>{await navigator.clipboard.writeText(h),f(!0),setTimeout(()=>f(!1),2e3)};return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:r,children:c.jsxs("div",{className:"relative mx-4 w-full max-w-md rounded-2xl border border-gray-200 bg-white p-6 shadow-2xl dark:border-gray-700 dark:bg-gray-900",onClick:y=>y.stopPropagation(),children:[c.jsx("button",{type:"button",onClick:r,className:"absolute right-3 top-3 rounded-lg p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",children:c.jsx(An,{className:"h-5 w-5"})}),c.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-gray-100",children:o("clawhub.installTitle",{name:n})}),c.jsx("div",{className:"mt-3 rounded-xl border border-yellow-200 bg-yellow-50 p-3 dark:border-yellow-800 dark:bg-yellow-900/20",children:c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsx($4,{className:"mt-0.5 h-4 w-4 shrink-0 text-yellow-600 dark:text-yellow-400"}),c.jsx("p",{className:"text-xs text-yellow-700 dark:text-yellow-300",children:o("clawhub.securityWarning")})]})}),c.jsxs("div",{className:"mt-4",children:[c.jsx("p",{className:"mb-2 text-xs font-medium text-gray-600 dark:text-gray-400",children:o("clawhub.installCommand")}),c.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-gray-900 px-3 py-2 dark:bg-gray-800",children:[c.jsx(z1,{className:"h-4 w-4 shrink-0 text-gray-400"}),c.jsx("code",{className:"flex-1 text-sm text-green-400",children:h}),c.jsx("button",{type:"button",onClick:g,className:"shrink-0 rounded p-1 text-gray-400 hover:bg-gray-700 hover:text-gray-200",children:u?c.jsx(Tr,{className:"h-4 w-4 text-green-400"}):c.jsx(jg,{className:"h-4 w-4"})})]})]}),c.jsxs("div",{className:"mt-5 flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:r,className:"rounded-lg border border-gray-300 px-4 py-2 text-sm text-gray-600 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-800",children:o("clawhub.cancel")}),c.jsx("button",{type:"button",onClick:s,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700",children:o("clawhub.installDone")})]})]})})}function Ih(e){return"score"in e}function v7(e){const t=Date.now()-e,n=Math.floor(t/6e4);if(n<60)return`${n}m ago`;const r=Math.floor(n/60);if(r<24)return`${r}h ago`;const s=Math.floor(r/24);return s<30?`${s}d ago`:`${Math.floor(s/30)}mo ago`}function Yv({item:e,isInstalled:t,onInstall:n,onOpenDetail:r}){var b;const{t:s}=se("console"),o=e.slug,u=e.displayName,f=e.summary,h=e.updatedAt,g=Ih(e)?e.version:(b=e.latestVersion)==null?void 0:b.version,y=Ih(e)?e.score:null,p=Ih(e)?null:e.stats;return c.jsxs("div",{className:"group relative flex flex-col justify-between rounded-2xl border border-gray-200 bg-white p-4 transition-all hover:border-blue-300 hover:shadow-md dark:border-gray-700 dark:bg-gray-800/80 dark:hover:border-blue-600",children:[c.jsx("button",{type:"button",onClick:()=>r(o),className:"absolute inset-0 rounded-2xl focus:outline-none","aria-label":u}),c.jsxs("div",{className:"relative z-10 pointer-events-none",children:[c.jsxs("div",{className:"flex items-start justify-between gap-3",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 truncate",children:u}),f&&c.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-gray-500 dark:text-gray-400",children:f})]}),c.jsx("div",{className:"pointer-events-auto shrink-0",children:t?c.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:[c.jsx(qi,{className:"h-3 w-3"}),s("skills.marketplace.installed")]}):c.jsxs("button",{type:"button",onClick:v=>{v.stopPropagation(),n(o,u)},className:"inline-flex items-center gap-1 rounded-lg bg-blue-600 px-2.5 py-1 text-xs font-medium text-white hover:bg-blue-700 transition-colors",children:[c.jsx(pl,{className:"h-3 w-3"}),s("skills.card.install")]})})]}),c.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3 text-xs text-gray-400 dark:text-gray-500",children:[g&&c.jsxs("span",{className:"flex items-center gap-1",children:["v",g]}),h&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(Ki,{className:"h-3 w-3"}),v7(h)]}),y!=null&&c.jsxs("span",{className:"flex items-center gap-1 text-blue-500 dark:text-blue-400",children:[c.jsx(a3,{className:"h-3 w-3"}),y.toFixed(1)]}),p&&p.downloads>0&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(pl,{className:"h-3 w-3"}),p.downloads.toLocaleString()]}),p&&p.stars>0&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(L1,{className:"h-3 w-3"}),p.stars]})]})]})]})}function k7({open:e,skillName:t,options:n,onSelect:r,onCancel:s}){const{t:o}=se("console"),u=S.useRef(null);return S.useEffect(()=>{const f=u.current;f&&(e&&!f.open?f.showModal():!e&&f.open&&f.close())},[e]),c.jsx("dialog",{ref:u,onClose:s,className:"fixed inset-0 z-50 m-auto max-w-sm rounded-lg border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-6",children:[c.jsx("h3",{className:"mb-4 text-lg font-semibold text-gray-900 dark:text-gray-100",children:o("skills.install.title",{name:t})}),c.jsx("div",{className:"space-y-2",children:n.map(f=>c.jsxs("button",{type:"button",onClick:()=>r(f.id),className:"flex w-full items-center gap-3 rounded-lg border border-gray-200 p-3 text-left transition-colors hover:border-blue-300 hover:bg-blue-50/50 dark:border-gray-700 dark:hover:border-blue-600 dark:hover:bg-blue-900/10",children:[c.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:f.label}),c.jsxs("span",{className:"text-xs text-gray-400",children:["(",f.kind,")"]})]},f.id))}),c.jsx("div",{className:"mt-4 flex justify-end",children:c.jsx("button",{type:"button",onClick:s,className:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:o("common:actions.cancel")})})]})})}function Qv({skill:e,onToggle:t,onConfigure:n,isInstalling:r,onInstall:s}){var g,y,p,b;const{t:o}=se("console"),u=e.isCore&&e.always,f=((y=(g=e.missing)==null?void 0:g.bins)==null?void 0:y.length)||((b=(p=e.missing)==null?void 0:p.env)==null?void 0:b.length),h=e.isBundled?o("skills.source.builtIn"):o("skills.source.marketplace");return c.jsx("div",{className:`rounded-2xl border p-4 transition-colors dark:bg-gray-800 ${e.enabled?"border-blue-200 bg-blue-50/40 dark:border-blue-900/40":"border-gray-200 bg-white opacity-75 dark:border-gray-700"}`,children:c.jsxs("div",{className:"flex items-start justify-between gap-4",children:[c.jsxs("button",{type:"button",onClick:()=>n(e),className:"flex min-w-0 flex-1 items-start gap-3 text-left",children:[c.jsx("span",{className:"text-2xl",children:e.icon||"📦"}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100",children:e.name}),c.jsx("span",{className:`rounded-md px-2 py-0.5 text-[10px] font-medium ${e.isBundled?"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400"}`,children:h}),e.isCore?c.jsx(D1,{className:"h-3.5 w-3.5 text-gray-400"}):e.isBundled?c.jsx(O1,{className:"h-3.5 w-3.5 text-blue-500/70"}):c.jsx(a4,{className:"h-3.5 w-3.5 text-purple-500/70"}),e.version&&c.jsxs("span",{className:"text-[10px] text-gray-400",children:["v",e.version]})]}),c.jsx("p",{className:"mt-2 line-clamp-2 text-sm text-gray-500 dark:text-gray-400",children:e.description}),f&&c.jsxs("div",{className:"mt-2 flex items-center gap-1 text-xs text-amber-600 dark:text-amber-400",children:[c.jsx(Pi,{className:"h-3.5 w-3.5"}),o("skills.card.missingDeps")]})]})]}),c.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[c.jsx("button",{type:"button",onClick:()=>n(e),className:"rounded p-1.5 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300 transition-colors",title:o("skills.card.configure"),children:c.jsx(Cg,{className:"h-4 w-4"})}),!e.eligible&&s&&c.jsx("button",{type:"button",onClick:()=>s(e),disabled:r,className:"rounded-xl bg-blue-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-blue-700 disabled:opacity-50 transition-colors",children:o(r?"skills.card.installing":"skills.card.install")}),c.jsxs("label",{className:"relative inline-flex cursor-pointer items-center",title:u?o("skills.card.coreProtected"):void 0,children:[c.jsx("input",{type:"checkbox",checked:e.enabled,onChange:()=>t(e.id,!e.enabled),disabled:u,className:"peer sr-only"}),c.jsx("div",{className:"peer h-5 w-9 rounded-full bg-gray-200 after:absolute after:left-[2px] after:top-[2px] after:h-4 after:w-4 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:bg-blue-600 peer-checked:after:translate-x-full peer-checked:after:border-white peer-disabled:cursor-not-allowed peer-disabled:opacity-50 dark:bg-gray-700 dark:peer-checked:bg-blue-500"})]})]})]})})}function w7({open:e,skill:t,onClose:n,onSaved:r}){var W;const{t:s}=se("console"),o=S.useRef(null),[u,f]=S.useState(""),[h,g]=S.useState(!1),[y,p]=S.useState([]),[b,v]=S.useState("info"),[k,j]=S.useState(!0),[N,C]=S.useState(!1);if(S.useEffect(()=>{const P=o.current;P&&(e&&!P.open?(v("info"),g(!1),P.showModal()):!e&&P.open&&P.close())},[e]),S.useEffect(()=>{var M,$;if(!t)return;f(typeof((M=t.config)==null?void 0:M.apiKey)=="string"?t.config.apiKey:"");const P=($=t.config)==null?void 0:$.env;p(P&&typeof P=="object"?Object.entries(P).map(([V,ae])=>({key:V,value:String(ae)})):[])},[t]),!t)return null;const E=t.primaryEnv||t.configChecks&&t.configChecks.length>0,R=t.isCore&&t.always,H=async()=>{C(!0);try{const P=y.reduce((M,$)=>{const V=$.key.trim();return V&&(M[V]=$.value.trim()),M},{});await Oe().skillsUpdate(t.id,{apiKey:u||void 0,env:Object.keys(P).length>0?P:void 0}),Ee.getState().setRuntimeApplied("configLifecycle.runtimeSkill"),r(),n()}catch{}finally{C(!1)}},z=()=>p(P=>[...P,{key:"",value:""}]),L=P=>{p(M=>M.filter(($,V)=>V!==P))},G=(P,M,$)=>{p(V=>V.map((ae,J)=>J===P?{...ae,[M]:$}:ae))};return c.jsx("dialog",{ref:o,onClose:n,className:"fixed inset-0 z-50 m-auto max-h-[90vh] w-[min(760px,calc(100vw-2rem))] rounded-xl border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"flex max-h-[90vh] flex-col",children:[c.jsx("div",{className:"border-b border-gray-200 p-6 dark:border-gray-700",children:c.jsxs("div",{className:"flex items-start justify-between gap-4",children:[c.jsxs("div",{className:"flex items-start gap-4",children:[c.jsx("span",{className:"text-3xl",children:t.icon||"📦"}),c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("h3",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:t.name}),R&&c.jsx(D1,{className:"h-4 w-4 text-gray-400"})]}),c.jsxs("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:[t.version||"—"," · ",t.author??"—"]}),c.jsxs("div",{className:"mt-3 flex gap-2",children:[c.jsx("button",{type:"button",onClick:()=>v("info"),className:`rounded-lg px-3 py-1.5 text-sm font-medium ${b==="info"?"bg-gray-900 text-white dark:bg-gray-100 dark:text-gray-900":"bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300"}`,children:s("skills.detail.info")}),c.jsx("button",{type:"button",onClick:()=>v("config"),disabled:!E,className:`rounded-lg px-3 py-1.5 text-sm font-medium ${b==="config"?"bg-gray-900 text-white dark:bg-gray-100 dark:text-gray-900":"bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300"} disabled:cursor-not-allowed disabled:opacity-50`,children:s("skills.detail.config")})]})]})]}),c.jsx("button",{type:"button",onClick:n,className:"rounded-full p-2 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700",children:c.jsx(An,{className:"h-4 w-4"})})]})}),c.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:b==="info"?c.jsxs("div",{className:"space-y-5",children:[c.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:t.description}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[c.jsx(wc,{label:s("skills.detail.source"),value:t.source??"—"}),c.jsx(wc,{label:s("skills.detail.version"),value:t.version||"—"}),c.jsx(wc,{label:s("skills.detail.author"),value:t.author??"—"}),c.jsx(wc,{label:s("skills.detail.primaryEnv"),value:t.primaryEnv??"—"})]}),t.homepage&&c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[s("skills.detail.homepage"),":"]}),c.jsxs("a",{href:t.homepage,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-blue-600 hover:underline dark:text-blue-400",children:[t.homepage,c.jsx(Oc,{className:"h-3 w-3"})]})]}),t.requirements&&c.jsxs("div",{children:[c.jsx("h4",{className:"mb-2 text-sm font-medium text-gray-700 dark:text-gray-300",children:s("skills.detail.requirements")}),c.jsx("div",{className:"space-y-2",children:(W=t.requirements.bins)==null?void 0:W.map(P=>{var $,V;const M=(V=($=t.missing)==null?void 0:$.bins)==null?void 0:V.includes(P);return c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[M?c.jsx(An,{className:"h-4 w-4 text-red-500"}):c.jsx(Tr,{className:"h-4 w-4 text-green-500"}),c.jsx("code",{className:"text-xs",children:P})]},P)})})]})]}):E?c.jsxs("div",{className:"space-y-5",children:[t.primaryEnv&&c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-xs text-gray-500 dark:text-gray-400",children:["API Key (",t.primaryEnv,")"]}),c.jsxs("div",{className:"relative",children:[c.jsx("input",{type:h?"text":"password",value:u,onChange:P=>f(P.target.value),placeholder:s("skills.detail.apiKeyPlaceholder"),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 pr-10 text-sm dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100"}),c.jsx("button",{type:"button",onClick:()=>g(!h),className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600",children:h?c.jsx(nu,{className:"h-4 w-4"}):c.jsx(au,{className:"h-4 w-4"})})]})]}),c.jsxs("div",{className:"rounded-xl border border-gray-200 p-4 dark:border-gray-700",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("button",{type:"button",onClick:()=>j(P=>!P),className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300",children:[k?c.jsx(qn,{className:"h-4 w-4"}):c.jsx(FA,{className:"h-4 w-4"}),s("skills.detail.envVars")]}),c.jsxs("button",{type:"button",onClick:z,className:"inline-flex items-center gap-1 rounded-md border border-gray-300 px-2 py-1 text-xs font-medium text-gray-600 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700",children:[c.jsx(En,{className:"h-3 w-3"}),s("skills.detail.addVariable")]})]}),k&&c.jsx("div",{className:"mt-4 space-y-3",children:y.length===0?c.jsx("p",{className:"text-xs italic text-gray-400",children:s("skills.detail.noEnvVars")}):y.map((P,M)=>c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{value:P.key,onChange:$=>G(M,"key",$.target.value),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-xs font-mono dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100",placeholder:s("skills.detail.keyPlaceholder")}),c.jsx("span",{className:"text-gray-400",children:"="}),c.jsx("input",{value:P.value,onChange:$=>G(M,"value",$.target.value),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-xs font-mono dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100",placeholder:s("skills.detail.valuePlaceholder")}),c.jsx("button",{type:"button",onClick:()=>L(M),className:"rounded-md p-2 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20",children:c.jsx(Dl,{className:"h-4 w-4"})})]},`${P.key}-${M}`))})]}),t.configChecks&&t.configChecks.length>0&&c.jsxs("div",{children:[c.jsx("label",{className:"mb-2 block text-xs text-gray-500 dark:text-gray-400",children:s("skills.detail.configChecks")}),c.jsx("div",{className:"space-y-1",children:t.configChecks.map(P=>c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[P.satisfied?c.jsx(Tr,{className:"h-4 w-4 text-green-500"}):c.jsx(An,{className:"h-4 w-4 text-red-500"}),c.jsx("code",{className:"text-xs",children:P.path})]},P.path))})]}),c.jsx("div",{className:"flex justify-end",children:c.jsx("button",{type:"button",onClick:H,disabled:N,className:"rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50 transition-colors",children:s(N?"skills.detail.saving":"common:actions.save")})})]}):c.jsx("p",{className:"text-sm text-gray-400",children:s("skills.detail.noConfig")})}),c.jsxs("div",{className:"flex items-center justify-between border-t border-gray-200 px-6 py-4 dark:border-gray-700",children:[c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[t.enabled?c.jsx(Tr,{className:"h-4 w-4 text-green-500"}):c.jsx(An,{className:"h-4 w-4 text-gray-400"}),c.jsx("span",{className:t.enabled?"text-green-600 dark:text-green-400":"text-gray-500 dark:text-gray-400",children:t.enabled?s("skills.detail.enabled"):s("skills.detail.disabled")})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("button",{type:"button",onClick:n,className:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:s("common:actions.close")}),c.jsxs("label",{className:"relative inline-flex cursor-pointer items-center",title:R?s("skills.card.coreProtected"):void 0,children:[c.jsx("input",{type:"checkbox",checked:t.enabled,onChange:()=>{Oe().skillsUpdate(t.id,{enabled:!t.enabled}).then(()=>{Ee.getState().setRuntimeApplied("configLifecycle.runtimeSkill"),r()})},disabled:R,className:"peer sr-only"}),c.jsx("div",{className:"peer h-5 w-9 rounded-full bg-gray-200 after:absolute after:left-[2px] after:top-[2px] after:h-4 after:w-4 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:bg-blue-600 peer-checked:after:translate-x-full peer-checked:after:border-white peer-disabled:cursor-not-allowed peer-disabled:opacity-50 dark:bg-gray-700 dark:peer-checked:bg-blue-500"})]})]})]})]})})}function wc({label:e,value:t}){return c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[e,":"]}),c.jsx("span",{className:"text-gray-900 dark:text-gray-100",children:t})]})}const S7=["installed","marketplace"];function j7({activeTab:e,onTabChange:t}){const{t:n}=se("console");return c.jsx("div",{className:"flex gap-1 rounded-xl bg-gray-100 p-1 dark:bg-gray-800",children:S7.map(r=>c.jsx("button",{type:"button",onClick:()=>t(r),className:`rounded-lg px-5 py-2 text-sm font-semibold transition-colors ${e===r?"bg-white text-gray-900 shadow-sm dark:bg-gray-700 dark:text-gray-100":"text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"}`,children:n(`skills.tabs.${r}`)},r))})}function C7(e,t){return e.enabled&&!t.enabled?-1:!e.enabled&&t.enabled?1:e.isCore&&!t.isCore?-1:!e.isCore&&t.isCore?1:e.name.localeCompare(t.name)}function N7(e){return new Set(e.map(t=>t.id))}function A7(e,t,n){const r=t.trim().toLowerCase();return e.filter(s=>s.isBundled||s.eligible).filter(s=>r?[s.name,s.description,s.slug,s.source].filter(Boolean).join(" ").toLowerCase().includes(r):!0).filter(s=>n==="built-in"?!!s.isBundled:n==="marketplace"?!s.isBundled:!0).sort(C7)}function E7(e,t){const n=t.trim().toLowerCase();return e.filter(r=>!r.isBundled).filter(r=>n?[r.name,r.description,r.slug,r.author,r.source].filter(Boolean).join(" ").toLowerCase().includes(n):!0).sort((r,s)=>r.name.localeCompare(s.name))}const T7=Mn((e,t)=>({skills:[],isLoading:!1,error:null,activeTab:"installed",sourceFilter:"all",selectedSkill:null,detailDialogOpen:!1,installing:new Set,fetchSkills:async()=>{e({isLoading:!0,error:null});try{await Pe();const n=await Oe().skillsStatus();e({skills:n,isLoading:!1})}catch(n){e({error:String(n),isLoading:!1})}},setTab:n=>e({activeTab:n}),setSourceFilter:n=>e({sourceFilter:n}),openDetail:n=>e({selectedSkill:n,detailDialogOpen:!0}),closeDetail:()=>e({selectedSkill:null,detailDialogOpen:!1}),toggleSkill:async(n,r)=>{try{if((await Oe().skillsUpdate(n,{enabled:r})).ok){e(f=>({skills:f.skills.map(h=>h.id===n?{...h,enabled:r}:h)})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeSkill");const o=t().skills.find(f=>f.id===n),u=(o==null?void 0:o.name)??n;hv(r?we.t("console:skills.toast.enabled",{name:u}):we.t("console:skills.toast.disabled",{name:u}))}}catch(s){uc(we.t("console:skills.toast.toggleFailed"),String(s)),e({error:String(s)})}},installSkill:async(n,r)=>{var o;const s=new Set(t().installing);s.add(n),e({installing:s});try{const u=await Oe().skillsInstall(n,r);if(u.ok)await t().fetchSkills(),hv(we.t("console:skills.toast.installSuccess",{name:n}));else{const f=[u.stdout,u.stderr].filter(Boolean).join(`
|
|
460
|
+
`):""}function Y_(){const{t:e}=se("chat"),t=Qe(T=>T.dockExpanded),n=Qe(T=>T.messages),r=Qe(T=>T.isStreaming),s=Qe(T=>T.streamingMessage),o=Qe(T=>T.isHistoryLoading),u=Qe(T=>T.setDockExpanded),f=Qe(T=>T.sendMessage),h=Qe(T=>T.abort),g=Qe(T=>T.error),y=Qe(T=>T.clearError),p=S.useRef(null),b=S.useRef(null),[v,k]=S.useState(!0),[j,N]=S.useState(G_),[C,E]=S.useState(!1),[R,H]=S.useState(!1),[z,L]=S.useState(""),[G,W]=S.useState(!1),P=S.useRef(0),M=S.useRef(0),$=S.useRef(!1),V=V_(s),ae=z.trim().length>0&&!r;S.useEffect(()=>{if(t&&!$.current){H(!0);const T=setTimeout(()=>H(!1),200);return $.current=!0,()=>clearTimeout(T)}if(!t&&$.current){H(!0);const T=setTimeout(()=>{H(!1),$.current=!1},150);return()=>clearTimeout(T)}},[t]),S.useEffect(()=>{if(t&&b.current){const T=setTimeout(()=>{var O;return(O=b.current)==null?void 0:O.focus()},220);return()=>clearTimeout(T)}},[t]),S.useEffect(()=>{v&&p.current&&(p.current.scrollTop=p.current.scrollHeight)},[n,V,v]);const J=S.useCallback(()=>{if(!p.current)return;const{scrollTop:T,scrollHeight:O,clientHeight:Q}=p.current,D=O-T-Q<40;k(D)},[]),Z=S.useCallback(()=>{p.current&&(p.current.scrollTop=p.current.scrollHeight,k(!0))},[]);S.useEffect(()=>{if(!t)return;const T=O=>{O.key==="Escape"&&u(!1)};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[t,u]);const U=S.useCallback(T=>{T.preventDefault(),E(!0),P.current=T.clientY,M.current=j},[j]);S.useEffect(()=>{if(!C)return;const T=Q=>{const D=P.current-Q.clientY,ce=window.innerHeight*P_,me=Math.max(pw,Math.min(ce,M.current+D));N(me)},O=()=>{E(!1);try{localStorage.setItem(fg,String(j))}catch{}};return document.addEventListener("mousemove",T),document.addEventListener("mouseup",O),()=>{document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",O)}},[C,j]),S.useEffect(()=>{if(!C)try{localStorage.setItem(fg,String(j))}catch{}},[j,C]);const ee=S.useCallback(()=>{const T=z.trim();!T||r||(f(T),L(""))},[z,r,f]),de=S.useCallback(T=>{T.key==="Enter"&&!T.shiftKey&&!G&&(T.preventDefault(),ee()),T.key==="Escape"&&u(!1)},[ee,G,u]);if(!t&&!R)return null;const ke=[...n];return c.jsxs("div",{className:`absolute inset-x-0 bottom-0 z-30 mx-auto flex w-full max-w-2xl flex-col overflow-hidden rounded-t-xl border border-b-0 border-gray-200 bg-white shadow-2xl dark:border-gray-700 dark:bg-gray-900 ${t?"animate-slide-up":"animate-slide-down"}`,style:{height:`${j}px`,transition:C?"none":void 0},children:[c.jsx("div",{className:"flex h-3 shrink-0 cursor-ns-resize items-center justify-center hover:bg-gray-100 dark:hover:bg-gray-800",onMouseDown:U,children:c.jsx("div",{className:"h-0.5 w-8 rounded-full bg-gray-300 dark:bg-gray-600"})}),c.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-gray-100 px-3 py-1 dark:border-gray-800",children:[c.jsx(K_,{}),c.jsx("button",{type:"button",onClick:()=>u(!1),className:"flex h-7 w-7 items-center justify-center rounded-md text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:e("dock.collapseDock"),children:c.jsx(k4,{className:"h-4 w-4"})})]}),o&&c.jsxs("div",{className:"flex shrink-0 items-center justify-center gap-2 py-3 text-sm text-gray-400",children:[c.jsx(Mt,{className:"h-4 w-4 animate-spin"}),c.jsx("span",{children:e("chatDialog.loadingHistory")})]}),c.jsxs("div",{ref:p,onScroll:J,className:"relative min-h-0 flex-1 overflow-y-auto px-4 py-2",children:[ke.length===0&&!r&&!o?c.jsx("div",{className:"flex h-full items-center justify-center text-sm text-gray-400",children:e("dock.startNewChat")}):c.jsxs(c.Fragment,{children:[ke.map(T=>c.jsx($_,{message:T},T.id)),r&&V&&c.jsx("div",{className:"mb-3 flex justify-start",children:c.jsxs("div",{className:"max-w-[80%] rounded-lg bg-gray-100 px-3 py-2 text-sm text-gray-900 dark:bg-gray-800 dark:text-gray-100",children:[c.jsx(gw,{content:V}),c.jsx(mw,{})]})}),r&&!V&&c.jsx("div",{className:"mb-3 flex justify-start",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-gray-100 px-3 py-2 text-sm text-gray-400 dark:bg-gray-800",children:[c.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-blue-500 border-t-transparent"}),c.jsx("span",{children:e("dock.thinkingStatus")})]})})]}),!v&&c.jsx("button",{type:"button",onClick:Z,title:e("chatDialog.scrollToBottom"),className:"sticky bottom-2 left-full z-10 -mr-2 flex h-8 w-8 items-center justify-center rounded-full border border-gray-200 bg-white shadow-md hover:bg-gray-50 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700",children:c.jsx(zA,{className:"h-4 w-4 text-gray-500"})})]}),g&&c.jsxs("div",{className:"flex shrink-0 items-center justify-between bg-red-50 px-3 py-1.5 text-xs text-red-600 dark:bg-red-900/20 dark:text-red-400",children:[c.jsx("span",{className:"truncate",children:g}),c.jsx("button",{type:"button",onClick:y,className:"ml-2 text-red-500 hover:text-red-700",children:"✕"})]}),c.jsx("div",{className:"shrink-0 border-t border-gray-200 bg-white px-3 py-2 dark:border-gray-700 dark:bg-gray-900",children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx(ok,{}),c.jsx("button",{type:"button",className:"rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:e("dock.attachmentWip"),children:c.jsx(R1,{className:"h-4 w-4"})}),c.jsx(H1,{ref:b,value:z,onChange:T=>L(T.target.value),onKeyDown:de,onCompositionStart:()=>W(!0),onCompositionEnd:()=>W(!1),placeholder:e("dock.placeholder"),maxRows:4,className:"flex-1 resize-none rounded-lg border border-gray-200 bg-gray-50 px-3 py-1.5 text-sm outline-none transition-colors placeholder:text-gray-400 focus:border-blue-400 focus:bg-white dark:border-gray-700 dark:bg-gray-800 dark:placeholder:text-gray-500 dark:focus:border-blue-500 dark:focus:bg-gray-900"}),r?c.jsx("button",{type:"button",onClick:()=>h(),className:"rounded-lg bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:e("common:actions.stop"),children:c.jsx(Ng,{className:"h-4 w-4"})}):c.jsx("button",{type:"button",onClick:ee,disabled:!ae,className:`rounded-lg p-1.5 transition-colors ${ae?"bg-blue-600 text-white hover:bg-blue-700":"bg-gray-200 text-gray-400 dark:bg-gray-700"}`,title:e("common:actions.send"),children:c.jsx(_1,{className:"h-4 w-4"})})]})})]})}function Q_(){const{t:e}=se("chat"),[t,n]=S.useState(""),[r,s]=S.useState(!1),o=S.useRef(null),u=Qe(N=>N.sendMessage),f=Qe(N=>N.abort),h=Qe(N=>N.isStreaming),g=Qe(N=>N.dockExpanded),y=Qe(N=>N.setDockExpanded),p=Qe(N=>N.error),b=Qe(N=>N.clearError),v=t.trim().length>0&&!h,k=S.useCallback(()=>{const N=t.trim();!N||h||(u(N),n(""))},[t,h,u]),j=S.useCallback(N=>{N.key==="Enter"&&!N.shiftKey&&!r&&(N.preventDefault(),k())},[k,r]);return g?null:c.jsxs("div",{className:"border-t border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900",children:[p&&c.jsxs("div",{className:"flex items-center justify-between bg-red-50 px-3 py-1.5 text-xs text-red-600 dark:bg-red-900/20 dark:text-red-400",children:[c.jsx("span",{className:"truncate",children:p}),c.jsx("button",{type:"button",onClick:b,className:"ml-2 text-red-500 hover:text-red-700",children:"✕"})]}),c.jsxs("div",{className:"flex items-end gap-2 px-3 py-2",children:[c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx(ok,{}),c.jsx("button",{type:"button",onClick:()=>y(!0),className:"rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:e("dock.expandDock"),children:c.jsx(y4,{className:"h-4 w-4"})})]}),c.jsx("button",{type:"button",className:"rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",title:e("dock.attachmentWip"),onClick:()=>{},children:c.jsx(R1,{className:"h-4 w-4"})}),c.jsx(H1,{ref:o,value:t,onChange:N=>n(N.target.value),onKeyDown:j,onFocus:()=>y(!0),onCompositionStart:()=>s(!0),onCompositionEnd:()=>s(!1),placeholder:e("dock.placeholder"),maxRows:4,className:"flex-1 resize-none rounded-lg border border-gray-200 bg-gray-50 px-3 py-1.5 text-sm outline-none transition-colors placeholder:text-gray-400 focus:border-blue-400 focus:bg-white dark:border-gray-700 dark:bg-gray-800 dark:placeholder:text-gray-500 dark:focus:border-blue-500 dark:focus:bg-gray-900"}),h?c.jsx("button",{type:"button",onClick:()=>f(),className:"rounded-lg bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:e("common:actions.stop"),children:c.jsx(Ng,{className:"h-4 w-4"})}):c.jsx("button",{type:"button",onClick:k,disabled:!v,className:`rounded-lg p-1.5 transition-colors ${v?"bg-blue-600 text-white hover:bg-blue-700":"bg-gray-200 text-gray-400 dark:bg-gray-700"}`,title:e("common:actions.send"),children:c.jsx(_1,{className:"h-4 w-4"})})]})]})}const Ee=Mn((e,t)=>({config:null,hash:null,configPath:null,configRaw:null,configValid:!0,loading:!1,error:null,schemaHints:null,status:null,statusLoading:!1,statusError:null,updateResult:null,updateLoading:!1,catalogModels:[],catalogLoading:!1,restartState:null,lifecycleState:null,setRestartPending:n=>e({restartState:{status:"pending",startedAt:Date.now(),estimatedDelayMs:n}}),setRestartReconnecting:()=>e(n=>n.restartState?{restartState:{...n.restartState,status:"reconnecting"}}:{}),setRestartComplete:()=>e(n=>n.restartState?{restartState:{...n.restartState,status:"complete"}}:{}),clearRestart:()=>e({restartState:null}),setLifecycleState:n=>e({lifecycleState:n}),setLifecycleFromWriteResult:(n,r,s)=>{var u;const o=Date.now();if((u=n.restart)!=null&&u.scheduled){e({lifecycleState:{status:r==="apply"?"apply-restarting":"saved-restart-required",source:r,startedAt:o,estimatedDelayMs:n.restart.delayMs},restartState:r==="apply"?{status:"pending",startedAt:o,estimatedDelayMs:n.restart.delayMs}:null});return}e({lifecycleState:s?{status:"saved-cli-restart-required",source:"cli",startedAt:o,command:s}:{status:"saved-hot-reload",source:r,startedAt:o},restartState:null})},setRuntimeApplied:n=>e({lifecycleState:{status:"effective-now",source:"runtime",startedAt:Date.now(),messageKey:n},restartState:null}),setLifecycleDisconnected:()=>e(n=>n.lifecycleState?{lifecycleState:{...n.lifecycleState,status:"disconnected"},restartState:n.restartState?{...n.restartState,status:"disconnected"}:n.restartState}:{}),setLifecycleReconnecting:()=>e(n=>n.lifecycleState?{lifecycleState:{...n.lifecycleState,status:"reconnecting"},restartState:n.restartState?{...n.restartState,status:"reconnecting"}:n.restartState}:{}),setLifecycleComplete:()=>e(n=>n.lifecycleState?{lifecycleState:{...n.lifecycleState,status:"complete"},restartState:n.restartState?{...n.restartState,status:"complete"}:n.restartState}:{}),clearLifecycle:()=>e({lifecycleState:null,restartState:null}),fetchConfig:async()=>{e({loading:!0,error:null});try{const r=await(await Pe()).configGet();e({config:r.config,hash:r.hash??null,configPath:r.path??null,configRaw:r.raw??null,configValid:r.valid,loading:!1})}catch(n){e({loading:!1,error:String(n)})}},saveConfig:async(n,r)=>{const s=t().config,o=t().hash??void 0;if(!s)return{ok:!1,config:{},error:"config not loaded"};try{const u=await Pe(),f=n(structuredClone(s)),h=await u.configSet(JSON.stringify(f),o);if(h.ok)e({config:h.config,error:null}),t().setLifecycleFromWriteResult(h,"save",r==null?void 0:r.fallbackCommand),await t().fetchConfig();else{const g=h.error??"config set failed";e({error:g}),g.includes("config changed")&&await t().fetchConfig()}return h}catch(u){const f=String(u);return e({error:f}),{ok:!1,config:s,error:f}}},applyConfig:async(n,r)=>{const s=t().config,o=t().hash??void 0;if(!s)return{ok:!1,config:{},error:"config not loaded"};try{const u=await Pe(),f=n(structuredClone(s)),h=await u.configApply(JSON.stringify(f),o,r);if(h.ok)e({config:h.config,error:null}),t().setLifecycleFromWriteResult(h,"apply"),await t().fetchConfig();else{const g=h.error??"config apply failed";e({error:g}),g.includes("config changed")&&await t().fetchConfig()}return h}catch(u){const f=String(u);return e({error:f}),{ok:!1,config:s,error:f}}},patchConfig:async n=>{var s;const{hash:r}=t();try{const o=await Pe(),u=JSON.stringify(n),f=await o.configPatch(u,r??void 0);if(f.ok)e({config:f.config,error:null}),(s=f.restart)!=null&&s.scheduled&&t().setRestartPending(f.restart.delayMs),await t().fetchConfig();else{const h=f.error??"config patch failed";e({error:h}),h.includes("config changed")&&await t().fetchConfig()}return f}catch(o){const u=String(o);return e({error:u}),{ok:!1,config:t().config??{},error:u}}},fetchSchema:async()=>{try{const r=await(await Pe()).configSchema();e({schemaHints:r})}catch{}},fetchStatus:async()=>{e({statusLoading:!0,statusError:null});try{const r=await(await Pe()).statusSummary();e({status:r,statusLoading:!1})}catch(n){e({statusLoading:!1,statusError:String(n)})}},fetchCatalogModels:async()=>{e({catalogLoading:!0});try{const r=await(await Pe()).modelsList();e({catalogModels:r,catalogLoading:!1})}catch{e({catalogLoading:!1})}},runUpdate:async n=>{e({updateLoading:!0,updateResult:null});try{const s=await(await Pe()).updateRun(n);return e({updateResult:s,updateLoading:!1}),s}catch(r){const s={ok:!1,result:{status:"error",mode:"unknown",reason:String(r),steps:[],durationMs:0},restart:null};return e({updateResult:s,updateLoading:!1}),s}}})),W_=2500;function yw(){const{t:e}=se("console"),t=Ee(j=>j.lifecycleState),n=Ee(j=>j.clearLifecycle),r=Ee(j=>j.setLifecycleDisconnected),s=Ee(j=>j.setLifecycleReconnecting),o=Ee(j=>j.setLifecycleComplete),u=ie(j=>j.connectionStatus),[f,h]=S.useState(null),[g,y]=S.useState(!1);S.useEffect(()=>{if(!(t!=null&&t.estimatedDelayMs)){h(null);return}const j=()=>{const C=Math.max(0,t.estimatedDelayMs-(Date.now()-t.startedAt));h(Math.ceil(C/1e3))};j();const N=setInterval(j,1e3);return()=>clearInterval(N)},[t]),S.useEffect(()=>{if(t){if(t.status==="apply-restarting"){u==="disconnected"||u==="error"?r():u==="connecting"||u==="reconnecting"?s():u==="connected"&&o();return}(t.status==="disconnected"||t.status==="reconnecting")&&(u==="connected"?o():(u==="connecting"||u==="reconnecting")&&t.status!=="reconnecting"?s():(u==="disconnected"||u==="error")&&t.status!=="disconnected"&&r())}},[u,t,o,r,s]),S.useEffect(()=>{if(t&&(t.status==="complete"||t.status==="effective-now"||t.status==="saved-hot-reload")){const j=setTimeout(()=>n(),W_);return()=>clearTimeout(j)}},[n,t]);const p=S.useMemo(()=>{if(!t)return null;const j=t.messageKey??X_(t.status),N=t.status==="apply-restarting"?e(j,{seconds:f??0}):e(j);switch(t.status){case"effective-now":case"saved-hot-reload":case"complete":return{icon:qi,className:"border-green-200 bg-green-50 text-green-800 dark:border-green-800 dark:bg-green-900/20 dark:text-green-300",message:N,animate:""};case"saved-restart-required":case"saved-cli-restart-required":return{icon:Rn,className:"border-amber-200 bg-amber-50 text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300",message:N,animate:""};case"apply-restarting":case"disconnected":case"reconnecting":return{icon:Mt,className:"border-blue-200 bg-blue-50 text-blue-800 dark:border-blue-800 dark:bg-blue-900/20 dark:text-blue-300",message:N,animate:"animate-spin"};default:return null}},[f,t,e]);if(!t||!p)return null;const b=p.icon,v=!!t.command,k=async()=>{!t.command||!navigator.clipboard||(await navigator.clipboard.writeText(t.command),y(!0),setTimeout(()=>y(!1),1500))};return c.jsx("div",{className:`border-b px-4 py-3 text-sm ${p.className}`,children:c.jsxs("div",{className:"mx-auto flex max-w-7xl items-start gap-3",children:[c.jsx(b,{className:`mt-0.5 h-4 w-4 shrink-0 ${p.animate}`}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("p",{className:"font-medium",children:p.message}),v&&c.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[c.jsxs("div",{className:"inline-flex items-center gap-2 rounded-md border border-current/20 bg-black/5 px-3 py-1.5 font-mono text-xs dark:bg-white/5",children:[c.jsx(z1,{className:"h-3.5 w-3.5"}),t.command]}),c.jsxs("button",{type:"button",onClick:()=>void k(),className:"inline-flex items-center gap-1 rounded-md border border-current/20 px-2.5 py-1 text-xs font-medium hover:bg-black/5 dark:hover:bg-white/5",children:[c.jsx(jg,{className:"h-3.5 w-3.5"}),e(g?"configLifecycle.copiedCommand":"configLifecycle.copyCommand")]})]})]})]})})}function X_(e){switch(e){case"effective-now":return"configLifecycle.effectiveNow";case"saved-hot-reload":return"configLifecycle.savedHotReload";case"saved-restart-required":return"configLifecycle.savedRestartRequired";case"saved-cli-restart-required":return"configLifecycle.savedCliRestartRequired";case"apply-restarting":return"configLifecycle.applyRestarting";case"disconnected":return"configLifecycle.disconnected";case"reconnecting":return"configLifecycle.reconnecting";case"complete":return"configLifecycle.complete"}}const Z_=5,gu=Mn(e=>({toasts:[],addToast:t=>{const n=`toast-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,r={id:n,type:t.type,title:t.title,message:t.message,detail:t.detail,duration:t.duration??5e3,createdAt:Date.now()};return e(s=>{const o=[...s.toasts,r];return o.length>Z_&&o.shift(),{toasts:o}}),n},removeToast:t=>e(n=>({toasts:n.toasts.filter(r=>r.id!==t)})),clearAll:()=>e({toasts:[]})}));function hv(e,t){return gu.getState().addToast({type:"success",title:e,message:t})}function uc(e,t,n){return gu.getState().addToast({type:"error",title:e,message:t,detail:n,duration:0})}const J_={success:qi,error:Sg,warning:Pi,info:ru},eL={success:{border:"border-green-300 dark:border-green-700",icon:"text-green-500",bg:"bg-green-50 dark:bg-green-900/20"},error:{border:"border-red-300 dark:border-red-700",icon:"text-red-500",bg:"bg-red-50 dark:bg-red-900/20"},warning:{border:"border-yellow-300 dark:border-yellow-700",icon:"text-yellow-500",bg:"bg-yellow-50 dark:bg-yellow-900/20"},info:{border:"border-blue-300 dark:border-blue-700",icon:"text-blue-500",bg:"bg-blue-50 dark:bg-blue-900/20"}};function tL({toast:e}){const{t}=se("console"),n=gu(b=>b.removeToast),[r,s]=S.useState(!1),[o,u]=S.useState(!1),f=S.useRef(null),h=S.useCallback(()=>{f.current&&(clearTimeout(f.current),f.current=null)},[]),g=S.useCallback(()=>{h(),e.duration>0&&!r&&(f.current=setTimeout(()=>n(e.id),e.duration))},[e.duration,e.id,r,n,h]);S.useEffect(()=>(o?h():g(),h),[o,g,h]);const y=J_[e.type],p=eL[e.type];return c.jsx("div",{onMouseEnter:()=>u(!0),onMouseLeave:()=>u(!1),className:`pointer-events-auto w-80 rounded-xl border ${p.border} ${p.bg} p-3 shadow-lg backdrop-blur-sm animate-in slide-in-from-right-5 fade-in duration-200`,children:c.jsxs("div",{className:"flex items-start gap-2.5",children:[c.jsx(y,{className:`mt-0.5 h-4 w-4 shrink-0 ${p.icon}`}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:e.title}),e.message&&c.jsx("p",{className:"mt-0.5 text-xs text-gray-600 dark:text-gray-400",children:e.message}),e.detail&&c.jsxs(c.Fragment,{children:[c.jsxs("button",{type:"button",onClick:()=>s(!r),className:"mt-1 flex items-center gap-1 text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",children:[r?c.jsx(wg,{className:"h-3 w-3"}):c.jsx(qn,{className:"h-3 w-3"}),t(r?"toast.hideDetail":"toast.showDetail")]}),r&&c.jsx("pre",{className:"mt-1.5 max-h-[200px] overflow-auto rounded-lg bg-gray-900 p-2 text-xs text-gray-200 dark:bg-gray-800",children:e.detail})]})]}),c.jsx("button",{type:"button",onClick:()=>n(e.id),className:"shrink-0 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:c.jsx(An,{className:"h-3.5 w-3.5"})})]})})}function nL(){const e=gu(t=>t.toasts);return e.length===0?null:c.jsx("div",{className:"pointer-events-none fixed right-4 top-4 z-50 flex flex-col gap-2",children:e.map(t=>c.jsx(tL,{toast:t},t.id))})}const Hi=["#ef4444","#f97316","#f59e0b","#84cc16","#22c55e","#14b8a6","#06b6d4","#3b82f6","#6366f1","#8b5cf6","#a855f7","#ec4899"];function nm(e){let t=0;for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);t=(t<<5)-t+r|0}return Math.abs(t)}function aL(e){const t=parseInt(e.slice(1,3),16)/255,n=parseInt(e.slice(3,5),16)/255,r=parseInt(e.slice(5,7),16)/255;return .299*t+.587*n+.114*r}function rL(e,t){const n=nm(e),r=Hi[n%Hi.length],s=aL(r)>.5?"#000000":"#ffffff",u=(t??e).charAt(0).toUpperCase()||"?";return{backgroundColor:r,textColor:s,initial:u}}function jI(e){const t=nm(e);return Hi[t%Hi.length]}const gv=["round","square","oval"],mv=["short","spiky","side-part","curly","buzz"],pv=["dot","line","wide"],yv=["#fde2c8","#f5c5a0","#d4956b","#a0714f","#6b4226","#ffe0bd"],xv=["#2c1b0e","#5a3214","#c2884a","#e8c068"];function xw(e){const t=nm(e),n=(r,s)=>(t>>>r)%s;return{faceShape:gv[n(0,gv.length)],hairStyle:mv[n(3,mv.length)],eyeStyle:pv[n(6,pv.length)],skinColor:yv[n(8,yv.length)],hairColor:xv[n(11,xv.length)],shirtColor:Hi[t%Hi.length]}}function iL({shape:e,color:t}){switch(e){case"round":return c.jsx("circle",{cx:"24",cy:"20",r:"12",fill:t});case"square":return c.jsx("rect",{x:"12",y:"8",width:"24",height:"24",rx:"4",fill:t});case"oval":return c.jsx("ellipse",{cx:"24",cy:"20",rx:"11",ry:"14",fill:t})}}function sL({style:e,color:t}){switch(e){case"short":return c.jsx("path",{d:"M12 16 Q12 6 24 6 Q36 6 36 16 L36 12 Q36 4 24 4 Q12 4 12 12 Z",fill:t});case"spiky":return c.jsx("path",{d:"M14 14 L16 4 L20 12 L24 2 L28 12 L32 4 L34 14 Q34 6 24 6 Q14 6 14 14 Z",fill:t});case"side-part":return c.jsx("path",{d:"M12 16 Q12 5 24 5 Q36 5 36 16 L36 11 Q36 3 24 3 Q14 3 10 10 Z",fill:t});case"curly":return c.jsx("path",{d:"M12 18 Q10 8 16 5 Q20 2 24 4 Q28 2 32 5 Q38 8 36 18 L36 12 Q36 4 24 4 Q12 4 12 12 Z",fill:t});case"buzz":return c.jsx("path",{d:"M13 15 Q13 6 24 6 Q35 6 35 15 L35 13 Q35 5 24 5 Q13 5 13 13 Z",fill:t})}}function lL({style:e}){switch(e){case"dot":return c.jsxs(c.Fragment,{children:[c.jsx("circle",{cx:"19",cy:"19",r:"1.5",fill:"#333"}),c.jsx("circle",{cx:"29",cy:"19",r:"1.5",fill:"#333"})]});case"line":return c.jsxs(c.Fragment,{children:[c.jsx("line",{x1:"17",y1:"19",x2:"21",y2:"19",stroke:"#333",strokeWidth:"1.5",strokeLinecap:"round"}),c.jsx("line",{x1:"27",y1:"19",x2:"31",y2:"19",stroke:"#333",strokeWidth:"1.5",strokeLinecap:"round"})]});case"wide":return c.jsxs(c.Fragment,{children:[c.jsx("ellipse",{cx:"19",cy:"19",rx:"2.5",ry:"2",fill:"white"}),c.jsx("circle",{cx:"19",cy:"19",r:"1.2",fill:"#333"}),c.jsx("ellipse",{cx:"29",cy:"19",rx:"2.5",ry:"2",fill:"white"}),c.jsx("circle",{cx:"29",cy:"19",r:"1.2",fill:"#333"})]})}}function bw({agentId:e,size:t=40,className:n}){const r=xw(e);return c.jsxs("svg",{viewBox:"0 0 48 48",width:t,height:t,className:n,style:{borderRadius:"50%",overflow:"hidden"},children:[c.jsx("rect",{width:"48",height:"48",fill:r.shirtColor,rx:"24"}),c.jsx("path",{d:"M8 42 Q8 34 24 34 Q40 34 40 42 L40 48 L8 48 Z",fill:r.shirtColor}),c.jsx(iL,{shape:r.faceShape,color:r.skinColor}),c.jsx(sL,{style:r.hairStyle,color:r.hairColor}),c.jsx(lL,{style:r.eyeStyle}),c.jsx("path",{d:"M21 24 Q24 26 27 24",stroke:"#333",strokeWidth:"0.8",fill:"none",strokeLinecap:"round"})]})}function oL(){const{t:e}=se("panels"),t=ie(o=>o.selectedAgentId),n=ie(o=>o.agents),r=ie(o=>o.selectAgent);if(!t)return null;const s=n.get(t);return s?c.jsxs("div",{className:"px-3 py-2",children:[c.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[c.jsx(bw,{agentId:s.id,size:32}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"truncate text-sm font-medium text-gray-800 dark:text-gray-200",children:s.name}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:Ml[s.status]}}),c.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:e(`common:agent.statusLabels.${s.status}`)})]})]}),c.jsx("button",{onClick:()=>r(null),className:"shrink-0 text-xs text-gray-400 hover:text-gray-600 dark:hover:text-gray-200",title:e("agentDetail.deselect"),children:"✕"})]}),s.currentTool&&c.jsx("div",{className:"mb-2 rounded bg-orange-50 px-2 py-1.5 text-xs dark:bg-orange-950/50",children:c.jsxs("div",{className:"text-orange-600 dark:text-orange-400",children:["🔧 ",s.currentTool.name]})}),s.speechBubble&&c.jsx("div",{className:"mb-2 rounded bg-white px-2 py-1.5 text-xs leading-relaxed text-gray-700 shadow-sm dark:bg-gray-800 dark:text-gray-300",children:c.jsx(Pk,{children:s.speechBubble.text})}),s.toolCallHistory.length>0&&c.jsxs("div",{className:"mt-2",children:[c.jsx("div",{className:"mb-1 text-xs font-medium text-gray-400 dark:text-gray-500",children:e("agentDetail.toolCallHistory")}),s.toolCallHistory.map((o,u)=>c.jsxs("div",{className:"flex items-center justify-between border-b border-gray-100 py-1 text-xs text-gray-500 dark:border-gray-700 dark:text-gray-400",children:[c.jsx("span",{children:o.name}),c.jsx("span",{className:"text-gray-400",children:new Date(o.timestamp).toLocaleTimeString()})]},`${o.name}-${o.timestamp}-${u}`))]})]}):null}const cL={lifecycle:"●",tool:"🔧",assistant:"💬",error:"⚠"},uL={lifecycle:"生命周期",tool:"工具调用",assistant:"对话输出",error:"异常"};function dL(){const{t:e}=se("panels"),t=ie(b=>b.eventHistory),n=ie(b=>b.selectAgent),r=S.useRef(null),[s,o]=S.useState(!0),u=S.useRef(0),[f,h]=S.useState(null),g=t.slice(-50);S.useEffect(()=>{s&&r.current&&t.length>u.current&&(r.current.scrollTop=r.current.scrollHeight),u.current=t.length},[t.length,s]);const y=S.useCallback(()=>{if(!r.current)return;const{scrollTop:b,scrollHeight:v,clientHeight:k}=r.current,j=v-b-k<30;o(j)},[]),p=S.useCallback((b,v)=>{f===b?h(null):(h(b),n(v))},[f,n]);return c.jsxs("div",{ref:r,onScroll:y,className:"flex-1 overflow-y-auto",children:[!s&&t.length>0&&c.jsx("div",{className:"sticky top-0 z-10 flex justify-end bg-white/80 px-2 py-0.5 backdrop-blur-sm dark:bg-gray-900/80",children:c.jsx("button",{onClick:()=>{o(!0),r.current&&(r.current.scrollTop=r.current.scrollHeight)},className:"rounded bg-blue-600 px-1.5 py-0.5 text-[10px] text-white",children:e("eventTimeline.newEvents")})}),g.map((b,v)=>{const k=f===v;return c.jsxs("div",{children:[c.jsxs("button",{onClick:()=>p(v,b.agentId),className:`flex w-full items-start gap-1.5 border-b border-gray-100 px-3 py-1.5 text-left text-xs transition-colors hover:bg-gray-50 dark:border-gray-800 dark:hover:bg-gray-800 ${k?"bg-blue-50/50 dark:bg-blue-950/30":""}`,children:[c.jsx("span",{className:"mt-0.5 shrink-0 text-gray-400",children:new Date(b.timestamp).toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})}),c.jsx("span",{className:"shrink-0",children:cL[b.stream]??"·"}),c.jsx("span",{className:"shrink-0 font-medium",style:{color:Ml[b.stream==="error"?"error":"thinking"]},children:b.agentName}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-gray-500 dark:text-gray-400",children:b.summary}),c.jsx("span",{className:"shrink-0 text-[10px] text-gray-300 dark:text-gray-600",children:k?"▼":"▶"})]}),k&&c.jsx("div",{className:"border-b border-gray-100 bg-gray-50/50 px-3 py-2 dark:border-gray-800 dark:bg-gray-800/50",children:c.jsxs("div",{className:"space-y-1 text-[11px]",children:[c.jsx(Sh,{label:"类型",value:uL[b.stream]??b.stream}),c.jsx(Sh,{label:"Agent",value:`${b.agentName} (${b.agentId})`}),c.jsx(Sh,{label:"时间",value:new Date(b.timestamp).toLocaleString("zh-CN",{hour12:!1})}),c.jsxs("div",{className:"pt-1",children:[c.jsx("div",{className:"text-gray-400 dark:text-gray-500",children:"详情"}),c.jsx("div",{className:"mt-0.5 whitespace-pre-wrap break-all rounded bg-white/60 p-1.5 text-gray-700 dark:bg-gray-900/60 dark:text-gray-300",children:b.summary||"—"})]})]})})]},`${b.timestamp}-${b.agentId}-${v}`)}),g.length===0&&c.jsx("div",{className:"py-3 text-center text-xs text-gray-400 dark:text-gray-500",children:e("common:empty.noEvents")})]})}function Sh({label:e,value:t}){return c.jsxs("div",{className:"flex gap-2",children:[c.jsx("span",{className:"w-10 shrink-0 text-gray-400 dark:text-gray-500",children:e}),c.jsx("span",{className:"min-w-0 break-all text-gray-600 dark:text-gray-300",children:t})]})}const fL=S.lazy(()=>El(()=>import("./TokenLineChart-PcKKH8m7.js"),__vite__mapDeps([0,1])).then(e=>({default:e.TokenLineChart}))),hL=S.lazy(()=>El(()=>import("./CostPieChart-CO-ieeMV.js"),__vite__mapDeps([2,1])).then(e=>({default:e.CostPieChart}))),gL=S.lazy(()=>El(()=>import("./NetworkGraph-B7rKNCND.js"),[]).then(e=>({default:e.NetworkGraph}))),mL=S.lazy(()=>El(()=>import("./ActivityHeatmap-D0IyZYFP.js"),[]).then(e=>({default:e.ActivityHeatmap})));function dc(){return c.jsx("div",{className:"flex min-h-[140px] items-center justify-center",children:c.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-blue-500 border-t-transparent"})})}function pL(){const{t:e}=se("panels"),[t,n]=S.useState("overview"),r=ie(u=>u.globalMetrics),s=[{id:"overview",label:e("metrics.tabs.overview")},{id:"trend",label:e("metrics.tabs.trend")},{id:"topology",label:e("metrics.tabs.topology")},{id:"activity",label:e("metrics.tabs.activity")}],o=[{label:e("metrics.activeAgents"),value:`${r.activeAgents}/${r.totalAgents}`,color:"#3b82f6"},{label:e("metrics.totalTokens"),value:yL(r.totalTokens),color:"#22c55e"},{label:e("metrics.collaboration"),value:`${Math.round(r.collaborationHeat)}%`,color:"#f97316"},{label:e("metrics.tokenRate"),value:`${r.tokenRate.toFixed(0)}${e("metrics.tokenRateUnit")}`,color:"#a855f7"}];return c.jsxs("div",{className:"flex flex-col",children:[c.jsx("div",{className:"grid grid-cols-4 gap-1 p-2",children:o.map(u=>c.jsxs("div",{className:"rounded-lg bg-gray-50 px-1 py-1 text-center dark:bg-gray-800",children:[c.jsx("div",{className:"text-xs font-bold leading-tight",style:{color:u.color},children:u.value}),c.jsx("div",{className:"text-[8px] text-gray-500 dark:text-gray-400",children:u.label})]},u.label))}),c.jsx("div",{className:"flex gap-1 border-t border-gray-100 px-2 py-1 dark:border-gray-800",children:s.map(u=>c.jsx("button",{type:"button",onClick:()=>n(u.id),className:`rounded px-2 py-0.5 text-[10px] ${t===u.id?"bg-gray-200 font-medium dark:bg-gray-700 dark:text-gray-200":"text-gray-600 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-800"}`,children:u.label},u.id))}),c.jsxs("div",{className:"p-2",children:[t==="overview"&&c.jsx(S.Suspense,{fallback:c.jsx(dc,{}),children:c.jsx(hL,{})}),t==="trend"&&c.jsx(S.Suspense,{fallback:c.jsx(dc,{}),children:c.jsx(fL,{})}),t==="topology"&&c.jsx(S.Suspense,{fallback:c.jsx(dc,{}),children:c.jsx(gL,{})}),t==="activity"&&c.jsx(S.Suspense,{fallback:c.jsx(dc,{}),children:c.jsx(mL,{})})]})]})}function yL(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function xL({agentId:e,agentName:t,size:n=32}){const{backgroundColor:r,textColor:s,initial:o}=rL(e,t);return c.jsx("div",{className:"flex shrink-0 items-center justify-center rounded-full font-bold",style:{width:n,height:n,backgroundColor:r,color:s,fontSize:n*.45},children:o})}function bL(){const{t:e}=se(),t=ie(s=>s.agents),n=ie(s=>s.selectAgent),r=Array.from(t.values()).filter(s=>s.isSubAgent);return r.length===0?c.jsx("div",{className:"py-2 text-center text-xs text-gray-400 dark:text-gray-500",children:e("empty.noSubAgents")}):c.jsx("div",{children:r.map(s=>{const o=s.parentAgentId?t.get(s.parentAgentId):null,u=vL(s.lastActiveAt,e);return c.jsxs("button",{onClick:()=>n(s.id),className:"flex w-full items-start gap-2 border-b border-gray-50 px-3 py-2 text-left transition-colors hover:bg-blue-50 dark:border-gray-800 dark:hover:bg-blue-950",children:[c.jsx(xL,{agentId:s.id,agentName:s.name,size:24}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsx("span",{className:"truncate text-xs font-medium text-gray-800 dark:text-gray-200",children:s.name}),c.jsx("span",{className:"inline-flex items-center rounded px-1 py-0.5 text-[9px] font-medium text-white",style:{backgroundColor:Ml[s.status]},children:e(`agent.statusLabels.${s.status}`)})]}),o&&c.jsxs("span",{role:"link",tabIndex:0,onClick:f=>{f.stopPropagation(),n(o.id)},onKeyDown:f=>{f.key==="Enter"&&(f.stopPropagation(),n(o.id))},className:"cursor-pointer text-[10px] text-blue-500 hover:underline",children:["← ",o.name]}),s.speechBubble&&c.jsx("div",{className:"mt-0.5 truncate text-[10px] text-gray-400",children:s.speechBubble.text.slice(0,80)}),c.jsx("div",{className:"text-[10px] text-gray-400",children:u})]})]},s.id)})})}function vL(e,t){const n=Math.max(0,Math.floor((Date.now()-e)/1e3));if(n<60)return t("time.running",{seconds:n});const r=Math.floor(n/60),s=n%60;return t("time.runningMinutes",{minutes:r,seconds:s})}function Ws({title:e,collapsed:t,onToggle:n,height:r,onHeightChange:s,minHeight:o=60,maxHeight:u=600,headerExtra:f,children:h,flex:g=!1,badge:y}){const p=S.useRef(null),b=S.useRef(null),v=t?0:r??o,k=S.useCallback(j=>{var R;if(t)return;j.preventDefault();const N=((R=p.current)==null?void 0:R.offsetHeight)??v;b.current={startY:j.clientY,startHeight:N};const C=H=>{if(!b.current)return;const z=H.clientY-b.current.startY,L=Math.max(o,Math.min(u,b.current.startHeight+z));s(L)},E=()=>{b.current=null,document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",E),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="ns-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",C),document.addEventListener("mouseup",E)},[t,v,o,u,s]);return S.useEffect(()=>()=>{document.body.style.cursor="",document.body.style.userSelect=""},[]),c.jsxs("div",{className:`flex flex-col ${g&&!t?"min-h-0 flex-1":""}`,style:!t&&!g?{flexShrink:0}:void 0,children:[c.jsxs("button",{type:"button",onClick:n,className:"flex h-6 w-full items-center gap-1 border-b border-gray-200 bg-gray-50 px-2 text-[11px] font-semibold uppercase tracking-wide text-gray-600 hover:bg-gray-100 dark:border-gray-700 dark:bg-gray-800/70 dark:text-gray-400 dark:hover:bg-gray-800",children:[c.jsx("span",{className:"inline-block text-[9px] transition-transform duration-150",style:{transform:t?"rotate(-90deg)":"rotate(0deg)"},children:"▼"}),c.jsx("span",{className:"select-none",children:e}),y!==void 0&&c.jsx("span",{className:"ml-1 rounded-sm bg-gray-200 px-1 text-[10px] font-normal text-gray-500 dark:bg-gray-700 dark:text-gray-400",children:y}),f&&c.jsx("span",{className:"ml-auto flex items-center",onClick:j=>j.stopPropagation(),children:f})]}),!t&&c.jsx("div",{ref:p,className:`overflow-y-auto overflow-x-hidden ${g?"min-h-0 flex-1":""}`,style:g?{minHeight:o}:{height:v},children:h}),!t&&c.jsx("div",{onMouseDown:k,className:"group relative z-10 h-1 shrink-0 cursor-ns-resize",children:c.jsx("div",{className:"absolute inset-x-0 -top-0.5 bottom-0 transition-colors group-hover:bg-blue-500/30 group-active:bg-blue-500/50"})})]})}const vw="openclaw-sidebar-layout",bv={metrics:{collapsed:!0,height:null},agents:{collapsed:!1,height:null},subAgents:{collapsed:!1,height:null},detail:{collapsed:!1,height:null},timeline:{collapsed:!1,height:null}};function kL(){try{const e=localStorage.getItem(vw);if(e){const t=JSON.parse(e);return{...bv,...t}}}catch{}return{...bv}}function wL(e){try{localStorage.setItem(vw,JSON.stringify(e))}catch{}}function SL(){const[e,t]=S.useState(kL),n=S.useRef(e);n.current=e,S.useEffect(()=>{wL(e)},[e]);const r=S.useCallback(u=>{t(f=>{var h;return{...f,[u]:{...f[u],collapsed:!((h=f[u])!=null&&h.collapsed)}}})},[]),s=S.useCallback((u,f)=>{t(h=>({...h,[u]:{...h[u],height:f}}))},[]),o=S.useCallback(u=>e[u]??{collapsed:!1,height:null},[e]);return{layout:e,toggleSection:r,setSectionHeight:s,getSection:o}}function vv(){const{t:e}=se("layout"),t=ie(z=>z.agents),n=ie(z=>z.selectedAgentId),r=ie(z=>z.selectAgent),s=ie(z=>z.sidebarCollapsed),o=ie(z=>z.setSidebarCollapsed),{getSection:u,toggleSection:f,setSectionHeight:h}=SL(),[g,y]=S.useState(""),[p,b]=S.useState("all"),v=S.useMemo(()=>{let z=Array.from(t.values()).filter(L=>!L.isPlaceholder);if(g){const L=g.toLowerCase();z=z.filter(G=>G.name.toLowerCase().includes(L))}return p==="active"?z=z.filter(L=>L.status!=="idle"&&L.status!=="offline"):p==="idle"?z=z.filter(L=>L.status==="idle"):p==="error"&&(z=z.filter(L=>L.status==="error")),z},[t,g,p]),k=S.useMemo(()=>Array.from(t.values()).filter(z=>z.isSubAgent&&!z.isPlaceholder),[t]),j=[{key:"all",label:e("sidebar.filters.all")},{key:"active",label:e("sidebar.filters.active")},{key:"idle",label:e("sidebar.filters.idle")},{key:"error",label:e("sidebar.filters.error")}];if(s)return c.jsx("aside",{className:"flex w-12 flex-col items-center border-l border-gray-200 bg-white py-3 dark:border-gray-700 dark:bg-gray-900",children:c.jsx("button",{onClick:()=>o(!1),className:"text-gray-400 hover:text-gray-700 dark:hover:text-gray-200",title:e("sidebar.expand"),children:"◀"})});const N=u("metrics"),C=u("agents"),E=u("subAgents"),R=u("detail"),H=u("timeline");return c.jsxs("aside",{className:"flex w-80 flex-col border-l border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900",children:[c.jsxs("div",{className:"flex h-8 shrink-0 items-center justify-between border-b border-gray-200 px-3 dark:border-gray-700",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400",children:e("sidebar.agents")}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(CL,{}),c.jsx("button",{onClick:()=>o(!0),className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-200",title:e("sidebar.collapse"),children:"▶"})]})]}),c.jsx(Ws,{id:"metrics",title:e("sidebar.metricsTitle"),collapsed:N.collapsed,onToggle:()=>f("metrics"),height:N.height,onHeightChange:z=>h("metrics",z),minHeight:120,maxHeight:400,children:c.jsx(pL,{})}),c.jsxs(Ws,{id:"agents",title:e("sidebar.agentList"),collapsed:C.collapsed,onToggle:()=>f("agents"),height:C.height,onHeightChange:z=>h("agents",z),minHeight:100,maxHeight:600,flex:!0,badge:v.length,headerExtra:c.jsx(jL,{filter:p,filterTags:j}),children:[c.jsxs("div",{className:"border-b border-gray-100 px-3 py-1.5 dark:border-gray-800",children:[c.jsx("input",{type:"text",placeholder:e("sidebar.searchPlaceholder"),value:g,onChange:z=>y(z.target.value),className:"w-full rounded border border-gray-200 bg-gray-50 px-2 py-1 text-sm text-gray-800 placeholder-gray-400 outline-none focus:border-blue-400 focus:ring-1 focus:ring-blue-400 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 dark:placeholder-gray-500"}),c.jsx("div",{className:"mt-1.5 flex gap-1",children:j.map(z=>c.jsx("button",{onClick:()=>b(z.key),className:`rounded px-2 py-0.5 text-xs transition-colors ${p===z.key?"bg-blue-600 text-white":"bg-gray-100 text-gray-500 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700"}`,children:z.label},z.key))})]}),c.jsxs("div",{children:[v.map(z=>c.jsxs("button",{onClick:()=>r(z.id),className:`flex w-full items-center gap-3 border-b border-gray-50 px-3 py-2 text-left transition-colors hover:bg-gray-50 dark:border-gray-800 dark:hover:bg-gray-800 ${n===z.id?"bg-blue-50 dark:bg-blue-950":""}`,children:[c.jsx(bw,{agentId:z.id,size:24}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"truncate text-xs font-medium text-gray-800 dark:text-gray-200",children:z.name}),c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full",style:{backgroundColor:Ml[z.status]}}),c.jsx("span",{className:"text-[10px] text-gray-500 dark:text-gray-400",children:e(`common:agent.statusLabels.${z.status}`)}),c.jsxs("span",{className:"text-[10px] text-gray-400 dark:text-gray-500",children:["· ",NL(e,z.lastActiveAt)]})]})]})]},z.id)),v.length===0&&c.jsx("div",{className:"px-3 py-4 text-center text-xs text-gray-400 dark:text-gray-500",children:e("common:empty.noMatchingAgents")})]})]}),k.length>0&&c.jsx(Ws,{id:"subAgents",title:e("sidebar.subAgents"),collapsed:E.collapsed,onToggle:()=>f("subAgents"),height:E.height,onHeightChange:z=>h("subAgents",z),minHeight:60,maxHeight:300,badge:k.length,children:c.jsx(bL,{})}),n&&c.jsx(Ws,{id:"detail",title:e("sidebar.agentDetail"),collapsed:R.collapsed,onToggle:()=>f("detail"),height:R.height,onHeightChange:z=>h("detail",z),minHeight:80,maxHeight:400,children:c.jsx(oL,{})}),c.jsx(Ws,{id:"timeline",title:e("sidebar.eventTimeline"),collapsed:H.collapsed,onToggle:()=>f("timeline"),height:H.height,onHeightChange:z=>h("timeline",z),minHeight:150,maxHeight:600,flex:!0,children:c.jsx(dL,{})})]})}function jL({filter:e,filterTags:t}){var r;if(e==="all")return null;const n=((r=t.find(s=>s.key===e))==null?void 0:r.label)??e;return c.jsx("span",{className:"rounded bg-blue-100 px-1 text-[9px] text-blue-700 dark:bg-blue-900/50 dark:text-blue-300",children:n})}function CL(){const{t:e}=se("layout"),t=$i(),r=Zt().pathname==="/living-office";return c.jsxs("button",{onClick:()=>t(r?"/":"/living-office"),className:`flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] font-semibold transition-colors ${r?"bg-violet-100 text-violet-700 dark:bg-violet-900/40 dark:text-violet-300":"text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300"}`,title:e("sidebar.livingOffice"),children:[e("sidebar.livingOffice"),c.jsx("span",{className:"rounded bg-violet-500/20 px-1 text-[8px] text-violet-500 dark:text-violet-400",children:e("sidebar.livingOfficeBeta")})]})}function NL(e,t){const n=Math.max(0,Math.floor((Date.now()-t)/1e3));return n<5?e("common:time.justNow"):n<60?e("common:time.secondsAgo",{count:n}):n<3600?e("common:time.minutesAgo",{count:Math.floor(n/60)}):e("common:time.hoursAgo",{count:Math.floor(n/3600)})}function AL(){var u;const{i18n:e,t}=se("layout"),n=(u=e.language)==null?void 0:u.startsWith("zh"),r=n?"中文":"EN",s=t(n?"topbar.language.switchToEn":"topbar.language.switchToZh"),o=()=>{e.changeLanguage(n?"en":"zh")};return c.jsx("button",{onClick:o,"aria-label":s,title:s,className:"ml-1 flex h-7 w-7 items-center justify-center rounded-md text-xs font-semibold transition-colors hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-400",children:r})}function EL(){try{const e=document.createElement("canvas");return(e.getContext("webgl2")??e.getContext("webgl"))!==null}catch{return!1}}const TL="2026.3.23";function DL(e){return{connecting:{color:"#eab308",pulse:!0,label:e("common:status.connecting")},connected:{color:"#22c55e",pulse:!1,label:e("common:status.connected")},reconnecting:{color:"#f97316",pulse:!0,label:e("common:status.reconnecting")},disconnected:{color:"#6b7280",pulse:!1,label:e("common:status.disconnected")},error:{color:"#ef4444",pulse:!1,label:e("common:status.error")}}}function kw({isMobile:e=!1}){const{t}=se("layout"),n=ie(v=>v.connectionStatus),r=ie(v=>v.connectionError),s=ie(v=>v.globalMetrics),o=ie(v=>v.viewMode),u=ie(v=>v.setViewMode),f=ie(v=>v.theme),h=ie(v=>v.setTheme),g=ie(v=>v.currentPage),y=S.useMemo(()=>EL(),[]),p=DL(t)[n],b=g==="office";return c.jsxs("header",{className:"flex h-12 shrink-0 items-center border-b border-gray-200 bg-white px-4 shadow-sm dark:border-gray-700 dark:bg-gray-900",children:[b?c.jsx(RL,{viewMode:o,setViewMode:u,metrics:s,webglAvailable:y,isMobile:e}):c.jsx(ML,{currentPage:g}),c.jsxs("div",{className:"ml-auto flex items-center gap-3",children:[c.jsx(OL,{currentPage:g}),c.jsx(zL,{theme:f,setTheme:h}),c.jsx(AL,{}),c.jsx(_L,{statusCfg:p,connectionError:r,connectionStatus:n})]})]})}function RL({viewMode:e,setViewMode:t,metrics:n,webglAvailable:r,isMobile:s}){const{t:o}=se("layout");return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("h1",{className:"text-lg font-semibold tracking-tight text-gray-800 dark:text-gray-100",children:"OpenClaw Office"}),c.jsxs("span",{className:"rounded-full bg-gray-100 px-2 py-0.5 text-xs text-gray-500 dark:bg-gray-800 dark:text-gray-400",children:["v",TL]})]}),c.jsx(LL,{viewMode:e,setViewMode:t,webglAvailable:r,isMobile:s}),c.jsxs("div",{className:"mx-8 flex items-center gap-6 text-sm text-gray-500 dark:text-gray-400",children:[c.jsxs("span",{children:[o("topbar.activeCountText")," ",c.jsxs("strong",{className:"text-gray-800 dark:text-gray-200",children:[n.activeAgents,"/",n.totalAgents]})]}),c.jsxs("span",{children:[o("topbar.tokensLabel")," ",c.jsx("strong",{className:"text-gray-800 dark:text-gray-200",children:IL(n.totalTokens)})]})]})]})}function ML({currentPage:e}){const{t}=se("layout");return c.jsx("div",{className:"flex items-center gap-3",children:c.jsx("h1",{className:"text-lg font-semibold text-gray-800 dark:text-gray-100",children:t(`topbar.pageTitles.${e}`,{defaultValue:t("topbar.pageTitles.fallback")})})})}function OL({currentPage:e}){const{t}=se("layout"),n=$i(),r=Zt(),s=e!=="office",o=r.pathname==="/living-office";return c.jsx("div",{className:"flex items-center gap-1",children:c.jsx("button",{onClick:()=>n(s?o?"/living-office":"/":"/dashboard"),className:`flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-sm font-medium transition-colors ${s?"bg-blue-50 text-blue-600 dark:bg-blue-900/30 dark:text-blue-400":"text-gray-600 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-800"}`,children:s?c.jsxs(c.Fragment,{children:[c.jsx(E1,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden sm:inline",children:t("topbar.office")})]}):c.jsxs(c.Fragment,{children:[c.jsx(d4,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden sm:inline",children:t("topbar.console")})]})})})}function _L({statusCfg:e,connectionError:t,connectionStatus:n}){return c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("div",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:e.color,animation:e.pulse?"pulse 1.5s ease-in-out infinite":"none"}}),c.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:t&&n==="error"?t:e.label})]})}function LL({viewMode:e,setViewMode:t,webglAvailable:n,isMobile:r}){const{t:s}=se("layout"),o=[{key:"2d",label:"2D"},{key:"3d",label:"3D"}];return c.jsx("div",{className:"ml-6 flex items-center rounded-md bg-gray-100 p-0.5 dark:bg-gray-800",children:o.map(({key:u,label:f})=>{const h=e===u,g=u==="3d"&&(!n||r),y=g?s(r?"topbar.viewMode.mobileNotSupported":"topbar.viewMode.webglNotSupported"):s("topbar.viewMode.switchTo",{mode:f});return c.jsx("button",{onClick:()=>!g&&t(u),disabled:g,title:y,className:`rounded px-3 py-1 text-xs font-medium transition-colors ${h?"bg-blue-600 text-white shadow-sm":g?"cursor-not-allowed text-gray-300 dark:text-gray-600":"text-gray-500 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200"}`,children:f},u)})})}function zL({theme:e,setTheme:t}){const{t:n}=se("layout");return c.jsx("button",{onClick:()=>t(e==="light"?"dark":"light"),title:n(e==="light"?"topbar.theme.switchToDark":"topbar.theme.switchToLight"),className:"ml-2 flex h-7 w-7 items-center justify-center rounded-md text-base transition-colors hover:bg-gray-200 dark:hover:bg-gray-700",children:e==="light"?"🌙":"☀️"})}function IL(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function HL({children:e,wsClient:t,isMobile:n=!1}){const{t:r}=se("layout"),s=ie(j=>j.sidebarCollapsed),o=ie(j=>j.setSidebarCollapsed),u=Qe(j=>j.initEventListeners),f=Qe(j=>j.setTargetAgent),h=ie(j=>j.connectionStatus),g=ie(j=>j.agents),y=ie(j=>j.selectedAgentId),p=ie(j=>j.initEventHistory),v=Zt().pathname==="/living-office";S.useEffect(()=>{n&&o(!0)},[n,o]),S.useEffect(()=>{p()},[p]),S.useEffect(()=>{if(h!=="connected")return;const j=(t==null?void 0:t.current)??null;return j?u(j):void 0},[h,t,u]),S.useEffect(()=>{if(h==="connected"&&g.size>0&&!Qe.getState().targetAgentId){const N=Array.from(g.values()).find(C=>!C.isSubAgent);N&&f(N.id)}},[h,g,f]),S.useEffect(()=>{if(!y)return;const j=g.get(y);if(!j||j.isSubAgent)return;Qe.getState().targetAgentId!==y&&f(y)},[y,g,f]);const k=e??c.jsx(d1,{});return c.jsxs("div",{className:"flex h-screen w-screen flex-col bg-gray-50 text-gray-900 dark:bg-gray-950 dark:text-gray-100",children:[c.jsx(yw,{}),c.jsx(kw,{isMobile:n}),c.jsx(nL,{}),c.jsxs("div",{className:"relative flex flex-1 overflow-hidden",children:[c.jsxs("main",{className:"relative flex flex-1 flex-col overflow-hidden",children:[c.jsx("div",{className:"relative flex-1 overflow-hidden",children:k}),c.jsx(Y_,{}),c.jsx(Q_,{})]}),!v&&(n?c.jsxs(c.Fragment,{children:[c.jsx("button",{type:"button",onClick:()=>o(!s),className:"fixed bottom-0 left-1/2 z-20 flex h-10 w-full max-w-xs -translate-x-1/2 items-center justify-center border-t border-gray-200 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-900","aria-label":r(s?"sidebar.expandSidebar":"sidebar.collapseSidebar"),children:c.jsx("div",{className:"h-1 w-12 rounded-full bg-gray-300 dark:bg-gray-600"})}),!s&&c.jsxs(c.Fragment,{children:[c.jsx("div",{role:"button",tabIndex:0,onClick:()=>o(!0),onKeyDown:j=>j.key==="Escape"&&o(!0),className:"fixed inset-0 z-30 bg-black/30","aria-label":r("sidebar.closeSidebar")}),c.jsx("aside",{className:"fixed inset-x-0 bottom-10 top-12 z-40 overflow-hidden rounded-t-xl border-t border-gray-200 bg-white shadow-xl dark:border-gray-700 dark:bg-gray-900",children:c.jsx(vv,{})})]})]}):c.jsx(vv,{}))]})]})}function BL(){const{t:e}=se("layout"),t=Zt(),n=$i(),r=[{path:"/dashboard",labelKey:"consoleNav.dashboard",icon:i4},{path:"/agents",labelKey:"consoleNav.agents",icon:T1},{path:"/channels",labelKey:"consoleNav.channels",icon:Tl},{path:"/skills",labelKey:"consoleNav.skills",icon:O1},{path:"/cron",labelKey:"consoleNav.cron",icon:Ki},{path:"/settings",labelKey:"consoleNav.settings",icon:Cg}];return c.jsxs("div",{className:"flex h-screen w-screen flex-col bg-gray-50 text-gray-900 dark:bg-gray-950 dark:text-gray-100",children:[c.jsx(yw,{}),c.jsx(kw,{}),c.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[c.jsx("nav",{className:"flex w-52 shrink-0 flex-col border-r border-gray-200 bg-white py-3 dark:border-gray-700 dark:bg-gray-900",children:r.map(s=>{const o=t.pathname===s.path,u=s.icon;return c.jsxs("button",{onClick:()=>n(s.path),className:`mx-2 flex items-center gap-2.5 rounded-md px-3 py-2 text-sm transition-colors ${o?"bg-blue-50 font-medium text-blue-600 dark:bg-blue-900/30 dark:text-blue-400":"text-gray-600 hover:bg-gray-100 hover:text-gray-800 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-200"}`,children:[c.jsx(u,{className:"h-4 w-4"}),c.jsx("span",{children:e(s.labelKey)})]},s.path)})}),c.jsx("main",{className:"flex-1 overflow-auto",children:c.jsx("div",{className:"mx-auto max-w-6xl p-6",children:c.jsx(d1,{})})})]})]})}var Tt=(e=>(e[e.L0=0]="L0",e[e.L1=1]="L1",e[e.L2=2]="L2",e[e.L3=3]="L3",e[e.L4=4]="L4",e))(Tt||{});const UL={0:0,1:800,2:1500,3:2500,4:4e3},$L=6e3,qL=3e3,jh=300,KL=800,kv=7,PL={0:1,1:3,2:5,3:7,4:10};W1();const FL={ARRIVE:"INCOMING",DISPATCH:"WORKING",ACK:"ACK",FOCUS:"WORKING",CALL_TOOL:"TOOL_CALL",WAIT:"WAITING",SPAWN_SUBAGENT:"COLLABORATING",COLLAB:"COLLABORATING",RETURN:"DONE",BROADCAST_CRON:"IDLE",POLL_HEARTBEAT:"IDLE",BLOCK:"BLOCKED",RECOVER:"RECOVERED"},GL=5;function VL(){return{gatewayStream:[{label:"WebSocket",detail:we.t("office:livingOffice.gateway.connecting"),active:!1},{label:"Event Bus",detail:we.t("office:livingOffice.gateway.ready"),active:!1},{label:"RPC",detail:we.t("office:livingOffice.gateway.ready"),active:!1},{label:"Health",detail:we.t("office:livingOffice.gateway.normal"),active:!0}],cronTasks:[],memoryItems:[],projectTasks:[],opsRules:[]}}function fc(e,t,n,r=GL){const s=e.findIndex(o=>n(o,t));s>=0&&e.splice(s,1),e.push(t),e.length>r&&e.splice(0,e.length-r)}function YL(e){return e.actors.length===0?"system":e.actors.length===1?e.actors[0]:`${e.actors[0]} +${e.actors.length-1}`}function QL(e){switch(e.kind){case"BROADCAST_CRON":return"cron";case"BLOCK":return"incident";case"RECOVER":return"recovery";case"CALL_TOOL":return"tool";case"SPAWN_SUBAGENT":return"project";default:return e.area}}function WL(e,t){if(t.summary&&t.kind!=="POLL_HEARTBEAT"&&fc(e.memoryItems,{text:t.summary,tag:QL(t)},(n,r)=>n.text===r.text),(t.kind==="SPAWN_SUBAGENT"||t.kind==="COLLAB")&&fc(e.projectTasks,{title:t.summary,subtitle:`active · ${YL(t)}`},(n,r)=>n.title===r.title),(t.kind==="BLOCK"||t.kind==="RECOVER")&&fc(e.opsRules,{text:t.summary,tag:t.kind==="BLOCK"?"incident":"recovery"},(n,r)=>n.text===r.text),t.kind==="BROADCAST_CRON"&&fc(e.cronTasks,{time:new Date(t.startTs).toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}),name:t.summary,status:"running"},(n,r)=>n.name===r.name&&n.time===r.time),t.kind==="ARRIVE"||t.kind==="DISPATCH"){const n=e.gatewayStream.find(o=>o.label==="WebSocket");n&&(n.detail=we.t("office:livingOffice.gateway.streaming"),n.active=!0);const r=e.gatewayStream.find(o=>o.label==="Event Bus");r&&(r.detail=t.summary.slice(0,30),r.active=!0);const s=e.gatewayStream.find(o=>o.label==="RPC");s&&(s.detail=`actors ${t.actors.length||1}`,s.active=!0)}if(t.kind==="BLOCK"||t.kind==="RECOVER"){const n=e.gatewayStream.find(r=>r.label==="Health");n&&(n.detail=t.kind==="BLOCK"?we.t("office:livingOffice.gateway.alert"):we.t("office:livingOffice.gateway.recovered"),n.active=t.kind!=="BLOCK")}}const Dn=Mn()(X1((e,t)=>({agents:new Map,narrativeLogs:[],sceneArea:VL(),initAgent:(n,r,s)=>{e(o=>{o.agents.set(n,{agentId:n,role:r,state:"IDLE",deskId:s,load:0,lastHeartbeatAt:Date.now(),health:"ok"})})},initAgentsBatch:n=>{e(r=>{for(const{agentId:s,role:o,deskId:u}of n)r.agents.set(s,{agentId:s,role:o,state:"IDLE",deskId:u,load:0,lastHeartbeatAt:Date.now(),health:"ok"})})},applyPerceivedEvent:n=>{e(r=>{const s=FL[n.kind]??"IDLE";for(const o of n.actors){let u=r.agents.get(o);u||(u={agentId:o,role:o,state:"IDLE",deskId:o,load:0,lastHeartbeatAt:Date.now(),health:"ok"},r.agents.set(o,u)),u.state=s,n.kind==="CALL_TOOL"?u.tool=n.summary:u.tool=void 0,n.kind==="BLOCK"?u.health="error":n.kind==="RECOVER"&&(u.health="ok"),u.taskSummary=n.summary}n.summary&&n.kind!=="POLL_HEARTBEAT"&&(r.narrativeLogs.push({ts:n.startTs,text:n.summary,level:n.level,kind:n.kind}),r.narrativeLogs.length>kv&&r.narrativeLogs.splice(0,r.narrativeLogs.length-kv)),WL(r.sceneArea,n)})},resetAgent:n=>{e(r=>{const s=r.agents.get(n);s&&(s.state="IDLE",s.tool=void 0,s.taskSummary=void 0,s.sessionId=void 0)})},getSnapshot:()=>{const n=t();return{agents:new Map(n.agents),narrativeLogs:[...n.narrativeLogs],sceneArea:{...n.sceneArea}}}}))),Vc=Mn((e,t)=>({tasks:[],isLoading:!1,error:null,dialogOpen:!1,editingTask:null,fetchTasks:async()=>{e({isLoading:!0,error:null});try{await Pe();const n=await Oe().cronList();e({tasks:n,isLoading:!1})}catch(n){e({error:String(n),isLoading:!1})}},addTask:async n=>{try{const r=await Oe().cronAdd(n);e(s=>({tasks:[...s.tasks,r],dialogOpen:!1,editingTask:null})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")}catch(r){e({error:String(r)})}},updateTask:async(n,r)=>{try{const s=await Oe().cronUpdate(n,r);e(o=>({tasks:o.tasks.map(u=>u.id===n?s:u),dialogOpen:!1,editingTask:null})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")}catch(s){e({error:String(s)})}},removeTask:async n=>{try{await Oe().cronRemove(n),e(r=>({tasks:r.tasks.filter(s=>s.id!==n)})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")}catch(r){e({error:String(r)})}},runTask:async n=>{try{await Oe().cronRun(n),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")}catch(r){e({error:String(r)})}},openDialog:n=>e({dialogOpen:!0,editingTask:n??null}),closeDialog:()=>e({dialogOpen:!1,editingTask:null}),handleCronEvent:n=>{!n.jobId||!n.state||e(r=>({tasks:r.tasks.map(s=>s.id===n.jobId?{...s,state:{...s.state,...n.state}}:s)}))},initEventListeners:()=>{const n=(o,u)=>{o==="cron"&&t().handleCronEvent(u)};let r=!1,s=()=>{};return Pe().then(()=>{r||(s=Oe().onEvent(n))}).catch(()=>{s=()=>{}}),()=>{r=!0,s()}}})),XL={IDLE:new Set(["INCOMING"]),INCOMING:new Set(["ACK"]),ACK:new Set(["WORKING"]),WORKING:new Set(["TOOL_CALL","WAITING","COLLABORATING","DONE","BLOCKED"]),TOOL_CALL:new Set(["WORKING","WAITING","DONE","BLOCKED"]),WAITING:new Set(["WORKING","DONE","BLOCKED"]),COLLABORATING:new Set(["RETURNING","BLOCKED"]),RETURNING:new Set(["DONE"]),DONE:new Set(["IDLE"]),BLOCKED:new Set(["RECOVERED"]),RECOVERED:new Set(["WORKING","IDLE"])},ZL={ARRIVE:"INCOMING",DISPATCH:"WORKING",ACK:"ACK",FOCUS:"WORKING",CALL_TOOL:"TOOL_CALL",WAIT:"WAITING",SPAWN_SUBAGENT:"COLLABORATING",COLLAB:"COLLABORATING",RETURN:"RETURNING",BROADCAST_CRON:"IDLE",POLL_HEARTBEAT:"IDLE",BLOCK:"BLOCKED",RECOVER:"RECOVERED"},Nr={IDLE:{cssClass:"idle",shouldMove:!1,holdMs:0},INCOMING:{cssClass:"incoming",shouldMove:!1,holdMs:1e3},ACK:{cssClass:"ack",shouldMove:!1,holdMs:1200},WORKING:{cssClass:"working",shouldMove:!1,holdMs:2500},TOOL_CALL:{cssClass:"tool-call",shouldMove:!1,holdMs:2e3},WAITING:{cssClass:"waiting",shouldMove:!1,holdMs:2500},COLLABORATING:{cssClass:"collaborating",shouldMove:!0,holdMs:5e3},RETURNING:{cssClass:"returning",shouldMove:!0,holdMs:1500},DONE:{cssClass:"done",shouldMove:!1,holdMs:1200},BLOCKED:{cssClass:"blocked",shouldMove:!1,holdMs:5e3},RECOVERED:{cssClass:"recovered",shouldMove:!1,holdMs:2500}},wv=new Set(["DISPATCH","COLLAB","SPAWN_SUBAGENT","RETURN","BLOCK"]),JL={RETURNING:"DONE"};function e8(e,t){const n=ZL[t];if(!n)return{nextState:e,visual:{...Nr[e]}};if(n==="IDLE")return{nextState:"IDLE",visual:{...Nr.IDLE}};if(e===n){const f=JL[e];return f?{nextState:f,visual:{...Nr[f],shouldMove:Nr[f].shouldMove&&wv.has(t)}}:{nextState:e,visual:{...Nr[e]}}}XL[e].has(n)||console.warn(`[StateMachine] Illegal transition: ${e} → ${n} (event: ${t}). Accepting with degradation.`);const o=Nr[n],u=o.shouldMove&&wv.has(t);return{nextState:n,visual:{...o,shouldMove:u}}}function t8(){return{nextState:"IDLE",visual:{...Nr.IDLE}}}const Xa={position:"absolute",top:-28,left:"50%",transform:"translateX(-50%)",fontSize:10,fontWeight:700,whiteSpace:"nowrap",pointerEvents:"none",zIndex:10,lineHeight:"16px"};function n8({state:e,toolName:t}){const{t:n}=se("office");switch(e){case"WORKING":return c.jsxs("div",{className:"lo-status-indicator lo-status-working",style:{...Xa,display:"flex",alignItems:"center",gap:3},children:[c.jsx("span",{className:"lo-status-gear",children:"⚙"}),c.jsx("span",{style:{color:"#7dd5ff",fontSize:9},children:n("livingOffice.status.working")})]});case"TOOL_CALL":return c.jsxs("div",{className:"lo-status-indicator lo-status-tool",style:{...Xa,background:"rgba(251, 191, 36, 0.15)",border:"1px solid rgba(251, 191, 36, 0.4)",borderRadius:6,padding:"1px 6px",color:"#fbbf24"},children:["🔧 ",t??n("livingOffice.status.tool")]});case"WAITING":return c.jsx("div",{className:"lo-status-indicator lo-status-waiting",style:{...Xa,color:"#94a3b8"},children:c.jsx("span",{className:"lo-status-hourglass",children:"⏳"})});case"BLOCKED":return c.jsx("div",{className:"lo-status-indicator lo-status-blocked",style:{...Xa,color:"#ff667a",fontSize:14,fontWeight:900},children:c.jsx("span",{className:"lo-status-alert",children:"❗"})});case"COLLABORATING":return c.jsxs("div",{className:"lo-status-indicator lo-status-collab",style:{...Xa,display:"flex",alignItems:"center",gap:3,color:"#a78bfa"},children:[c.jsx("span",{className:"lo-status-collab-icon",children:"🤝"}),c.jsx("span",{style:{fontSize:9},children:n("livingOffice.status.collaborating")})]});case"INCOMING":return c.jsx("div",{className:"lo-status-indicator lo-status-incoming",style:{...Xa,color:"#5cc8ff"},children:c.jsx("span",{className:"lo-status-incoming-icon",children:"📨"})});case"RETURNING":return c.jsxs("div",{className:"lo-status-indicator lo-status-returning",style:{...Xa,color:"#34d399",fontSize:9},children:["✅ ",n("livingOffice.status.returning")]});case"RECOVERED":return c.jsxs("div",{className:"lo-status-indicator lo-status-recovered",style:{...Xa,color:"#34d399",fontSize:9},children:["🔄 ",n("livingOffice.status.recovered")]});default:return null}}const tr=40,Ri=16,hc=24,Sv=12,Mi=3,jv=5,Cv=4,Nv=10,a8="#ffd8b4",Av="#2c3e50",r8="rgba(0, 0, 0, 0.35)",i8="rgba(11, 18, 32, 0.75)",s8="#e8f1ff",Ev=[["#7dd5ff","#5c8dff"],["#ff9a76","#e85d4a"],["#a78bfa","#7c3aed"],["#34d399","#059669"],["#fbbf24","#d97706"],["#f472b6","#db2777"],["#67e8f9","#06b6d4"],["#fb923c","#ea580c"]];function l8(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Ev[Math.abs(t)%Ev.length]}const o8=18,c8=3e3,u8=8e3,d8=2e3,f8=5e3,ww=1200,Sw=18,Xs=64,Zs=-8,h8={"desk-gm":{left:110+Xs,top:360+Zs},"desk-sales":{left:330+Xs,top:360+Zs},"desk-ops":{left:550+Xs,top:360+Zs},"desk-fin":{left:770+Xs,top:360+Zs},"desk-it":{left:440+Xs,top:500+Zs}},g8=[{left:1140,top:370},{left:1240,top:430},{left:1340,top:370}],m8=[{left:120,top:730},{left:340,top:730},{left:560,top:730},{left:780,top:730},{left:1e3,top:730},{left:1220,top:730},{left:230,top:810},{left:450,top:810},{left:670,top:810},{left:890,top:810},{left:1110,top:810}],Ch=900,p8="cubic-bezier(.25, .9, .2, 1)";function jw({name:e,agentId:t,cssClass:n,gazeDirection:r,state:s,toolName:o}){const[u,f]=l8(t),h=r*1.5;return c.jsxs("div",{className:`lo-char-body ${n}`,style:{position:"relative",width:tr,height:tr+20,display:"flex",flexDirection:"column",alignItems:"center"},children:[c.jsx(n8,{state:s,toolName:o}),c.jsx("div",{className:"lo-char-tag",style:{position:"absolute",top:-14,left:"50%",transform:"translateX(-50%) translateZ(18px)",fontSize:9,fontWeight:600,color:s8,background:i8,borderRadius:8,padding:"1px 6px",whiteSpace:"nowrap",pointerEvents:"none",lineHeight:"14px",border:"1px solid rgba(255,255,255,0.08)"},children:e}),c.jsxs("div",{className:"lo-char-head",style:{width:Ri,height:Ri,borderRadius:"50%",background:a8,boxShadow:"inset 0 -2px 4px rgba(0,0,0,0.15), 0 2px 6px rgba(0,0,0,0.2)",flexShrink:0,zIndex:2,position:"relative"},children:[c.jsx("div",{className:"lo-char-eye lo-char-eye-left",style:{position:"absolute",width:Mi,height:Mi,borderRadius:"50%",background:Av,top:Ri*.38,left:Ri/2-jv/2-Mi/2+h,transition:"left 0.4s ease"}}),c.jsx("div",{className:"lo-char-eye lo-char-eye-right",style:{position:"absolute",width:Mi,height:Mi,borderRadius:"50%",background:Av,top:Ri*.38,left:Ri/2+jv/2-Mi/2+h,transition:"left 0.4s ease"}})]}),c.jsxs("div",{style:{position:"relative",marginTop:-3,zIndex:1,display:"flex",alignItems:"flex-start"},children:[c.jsx("div",{className:"lo-char-arm lo-char-arm-left",style:{width:Cv,height:Nv,borderRadius:"3px 3px 2px 2px",background:`linear-gradient(180deg, ${u}cc, ${f}cc)`,marginRight:-1,marginTop:2,transformOrigin:"top center"}}),c.jsx("div",{className:"lo-char-torso",style:{width:hc,height:hc,borderRadius:`${Sv}px ${Sv}px 6px 6px`,background:`linear-gradient(180deg, ${u}, ${f})`,boxShadow:`0 0 12px ${u}40, 0 4px 12px rgba(0,0,0,0.3)`}}),c.jsx("div",{className:"lo-char-arm lo-char-arm-right",style:{width:Cv,height:Nv,borderRadius:"3px 3px 2px 2px",background:`linear-gradient(180deg, ${u}cc, ${f}cc)`,marginLeft:-1,marginTop:2,transformOrigin:"top center"}})]}),c.jsx("div",{className:"lo-char-shadow",style:{width:hc+10,height:6,borderRadius:"50%",background:r8,filter:"blur(4px)",marginTop:2,zIndex:0}}),s!=="IDLE"&&s!=="DONE"&&c.jsx("div",{className:"lo-char-status-ring",style:{position:"absolute",bottom:0,left:"50%",transform:"translateX(-50%)",width:hc+14,height:8,borderRadius:"50%",background:y8(s),filter:"blur(5px)",opacity:.6,zIndex:0}})]})}function y8(e){switch(e){case"WORKING":case"TOOL_CALL":return"rgba(92, 200, 255, 0.6)";case"BLOCKED":return"rgba(255, 102, 122, 0.7)";case"COLLABORATING":return"rgba(167, 139, 250, 0.6)";case"WAITING":return"rgba(148, 163, 184, 0.4)";case"INCOMING":case"ACK":return"rgba(92, 200, 255, 0.4)";case"RETURNING":case"RECOVERED":return"rgba(52, 211, 153, 0.5)";default:return"transparent"}}function Tv(e,t){return e+Math.random()*(t-e)}function x8(e,t){const[n,r]=S.useState({left:0,top:0}),[s,o]=S.useState(0),[u,f]=S.useState(!1),h=S.useRef(void 0),g=S.useRef(void 0),y=e==="IDLE"||e==="DONE",p=S.useCallback(()=>{h.current=setTimeout(()=>{if(!y)return;const v=Math.random()*Math.PI*2,k=Math.random()*o8;f(!0),r({left:Math.cos(v)*k,top:Math.sin(v)*k}),setTimeout(()=>{f(!1),Math.random()<.3&&r({left:0,top:0}),p()},ww)},Tv(c8,u8))},[y]),b=S.useCallback(()=>{g.current=setTimeout(()=>{y&&(o(Math.floor(Math.random()*3)-1),b())},Tv(d8,f8))},[y]);return S.useEffect(()=>{if(y){const v=Math.random()*3e3,k=setTimeout(()=>{p(),b()},v);return()=>{clearTimeout(k),clearTimeout(h.current),clearTimeout(g.current)}}r({left:0,top:0}),o(0),f(!1),clearTimeout(h.current),clearTimeout(g.current)},[y,p,b]),{wanderOffset:n,gazeDirection:s,isWandering:u}}function b8({agentId:e,deskId:t,name:n,perceivedState:r,eventKind:s,targetPosition:o,toolName:u}){const f=h8[t]??{left:0,top:0},[h,g]=S.useState("IDLE"),[y,p]=S.useState("idle"),[b,v]=S.useState(!1),[k,j]=S.useState(f),N=S.useRef("IDLE"),C=S.useRef(void 0),E=x8(h);S.useEffect(()=>{if(!s)return;const M=e8(N.current,s);N.current=M.nextState,g(M.nextState),p(M.visual.cssClass),M.visual.shouldMove&&o&&(v(!0),j(o),clearTimeout(C.current),C.current=setTimeout(()=>{v(!1)},Ch))},[s,o]),S.useEffect(()=>{r!==h&&!s&&(N.current=r,g(r),p(v8(r)))},[r,h,s]),S.useEffect(()=>{if(h!=="DONE")return;const M=setTimeout(()=>{const $=t8();N.current=$.nextState,g($.nextState),p($.visual.cssClass),j(f)},1200);return()=>clearTimeout(M)},[h,f]),S.useEffect(()=>{if(h!=="RETURNING")return;v(!0),j(f);const M=setTimeout(()=>{v(!1)},Ch);return()=>clearTimeout(M)},[h,f]),S.useEffect(()=>()=>clearTimeout(C.current),[]);const R=h==="IDLE",H=k.left+(R?E.wanderOffset.left:0),z=k.top+(R?E.wanderOffset.top:0),L=b||E.isWandering,G=b?Ch:ww,W=b?p8:"ease-in-out",P=[`lo-char-state-${y}`,L?"lo-char-walking":""].filter(Boolean).join(" ");return c.jsx("div",{"data-agent-id":e,"data-agent-state":h,className:`lo-character ${P}`,style:{position:"absolute",left:H-tr/2,top:z-tr/2,width:tr,transform:`translateZ(${Sw}px)`,transition:L?`left ${G}ms ${W}, top ${G}ms ${W}`:"left 0.3s ease, top 0.3s ease",zIndex:100,pointerEvents:"none"},children:c.jsx(jw,{name:n,agentId:e,cssClass:P,gazeDirection:E.gazeDirection,state:h,toolName:u})})}function v8(e){return{IDLE:"idle",INCOMING:"incoming",ACK:"ack",WORKING:"working",TOOL_CALL:"tool-call",WAITING:"waiting",COLLABORATING:"collaborating",RETURNING:"returning",DONE:"done",BLOCKED:"blocked",RECOVERED:"recovered"}[e]}function k8({agentId:e,name:t,position:n,active:r}){const[s,o]=S.useState(!1),[u,f]=S.useState(!1);return S.useEffect(()=>{if(r)f(!1),requestAnimationFrame(()=>o(!0));else{o(!1);const h=setTimeout(()=>f(!0),600);return()=>clearTimeout(h)}},[r]),u&&!r?null:c.jsx("div",{"data-agent-id":e,"data-subagent":!0,className:`lo-subagent-ghost ${s?"lo-subagent-visible":""}`,style:{position:"absolute",left:n.left-tr/2,top:n.top-tr/2,width:tr,transform:`translateZ(${Sw}px)`,zIndex:99,pointerEvents:"none"},children:c.jsx(jw,{name:`tmp:${t}`,agentId:e,cssClass:"lo-subagent-body",gazeDirection:0,state:"COLLABORATING"})})}const w8=3;function S8(e){return e.slice(0,w8).map((t,n)=>({agentId:t.agentId,name:t.name,slotIndex:n}))}const j8=1600,C8=920,Ir={gateway:{id:"gateway-zone",label:"Gateway Hall",position:{left:30,top:20},size:{width:440,height:250}},ops:{id:"ops-zone",label:"Operations Board",position:{left:490,top:20},size:{width:540,height:250}},cron:{id:"cron-zone",label:"Cron Broadcast",position:{left:1050,top:20},size:{width:380,height:250}},staff:{id:"staff-zone",label:"Staff Floor",position:{left:30,top:290},size:{width:1e3,height:350}},lounge:{id:"lounge-zone",label:"Lounge",position:{left:30,top:660},size:{width:1400,height:230}},project:{id:"project-zone",label:"Project Room",position:{left:1050,top:290},size:{width:380,height:230}},memory:{id:"memory-zone",label:"Memory Wall",position:{left:1050,top:540},size:{width:380,height:100}}},hl=[{id:"desk-gm",agentName:"General Manager",role:"orchestrator",position:{left:110,top:360}},{id:"desk-sales",agentName:"Sales Agent",role:"discovery",position:{left:330,top:360}},{id:"desk-ops",agentName:"Ops Agent",role:"execution",position:{left:550,top:360}},{id:"desk-fin",agentName:"Finance Agent",role:"payment",position:{left:770,top:360}},{id:"desk-it",agentName:"IT Agent",role:"tooling",position:{left:440,top:500}}];function N8(e,t){if(!e)return t;try{const n=localStorage.getItem(e);if(n==="1")return!0;if(n==="0")return!1}catch{}return t}const gc=34;function am({children:e,style:t,tag:n,title:r,collapsedContent:s,headerExtra:o,storageKey:u,defaultCollapsed:f=!1}){const[h,g]=S.useState(()=>N8(u,f)),y=!!r,p=()=>{const b=!h;if(g(b),u)try{localStorage.setItem(u,b?"1":"0")}catch{}};return c.jsxs("div",{style:{background:"var(--lo-glass-bg)",backdropFilter:"var(--lo-glass-blur)",WebkitBackdropFilter:"var(--lo-glass-blur)",border:"var(--lo-glass-border)",borderRadius:h?10:"var(--lo-glass-radius)",padding:h?"0 10px":"10px 14px",height:h?gc:void 0,minHeight:h?gc:void 0,position:"relative",overflow:"hidden",minWidth:0,display:"flex",flexDirection:"column",transition:"padding 0.18s ease, border-radius 0.18s ease, height 0.18s ease",...t},children:[n&&!h&&c.jsx("div",{style:{position:"absolute",top:8,right:10,fontSize:9,fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--lo-muted)",opacity:.6},children:n}),y&&c.jsxs("div",{onClick:p,role:"button",tabIndex:0,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&p()},style:{display:"flex",alignItems:"center",gap:5,cursor:"pointer",userSelect:"none",height:h?gc:"auto",minHeight:h?gc:void 0},children:[c.jsx("span",{style:{display:"inline-flex",width:10,height:10,alignItems:"center",justifyContent:"center",fontSize:7,color:"var(--lo-muted)",opacity:.6,transition:"transform 0.18s ease",transform:h?"rotate(-90deg)":"rotate(0deg)",flexShrink:0},children:"▼"}),c.jsx("span",{style:{fontSize:h?11:13,fontWeight:600,color:"var(--lo-text)",flexShrink:0,whiteSpace:"nowrap",transition:"font-size 0.15s ease"},children:r}),h&&s&&c.jsx("div",{style:{flex:1,minWidth:0,overflow:"hidden",display:"flex",alignItems:"center"},onClick:b=>b.stopPropagation(),children:s}),o&&c.jsx("div",{style:{marginLeft:h&&!s?"auto":0,flexShrink:0},children:o}),n&&h&&c.jsx("span",{style:{marginLeft:o?4:"auto",fontSize:7,fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--lo-muted)",opacity:.4,flexShrink:0},children:n})]}),!h&&c.jsx("div",{style:{marginTop:y?4:0,flex:1,minHeight:0},children:e})]})}function A8(e){const t=new Date(e),n=we.language==="zh"?"zh-CN":"en-US";return t.toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function E8({count:e}){const{t}=se("office");return c.jsx("span",{style:{fontSize:9,color:"var(--lo-muted)",opacity:.8},children:t("livingOffice.hud.eventLogCount",{count:e})})}function T8({text:e}){return c.jsx("span",{style:{fontSize:9,color:"var(--lo-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})}function D8(){const{t:e}=se("office"),t=Dn(s=>s.narrativeLogs),n=S.useRef(null);S.useEffect(()=>{n.current&&(n.current.scrollTop=n.current.scrollHeight)},[t]);const r=t.length>0?t[t.length-1].text:e("livingOffice.hud.eventLogWaiting");return c.jsx(am,{tag:e("livingOffice.hud.eventLogTag"),title:e("livingOffice.hud.eventLogTitle"),headerExtra:c.jsx(E8,{count:t.length}),storageKey:"lo-hud-log",defaultCollapsed:!0,collapsedContent:c.jsx(T8,{text:r}),children:c.jsx("div",{ref:n,style:{maxHeight:42,overflowY:"auto",display:"flex",flexDirection:"column",gap:2,scrollbarWidth:"none"},children:t.length===0?c.jsx("div",{style:{fontSize:10,color:"var(--lo-muted)",opacity:.5,fontStyle:"italic"},children:e("livingOffice.hud.eventLogWaiting")}):t.map((s,o)=>c.jsxs("div",{style:{display:"flex",gap:8,fontSize:10,lineHeight:1.4},children:[c.jsx("span",{style:{color:"var(--lo-muted)",opacity:.6,flexShrink:0,fontFamily:"monospace",fontSize:9},children:A8(s.ts)}),c.jsx("span",{style:{color:"var(--lo-text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.text})]},`${String(s.ts)}-${String(o)}`))})})}function R8({isOnline:e}){const{t}=se("office");return c.jsxs("div",{style:{display:"flex",alignItems:"center",gap:5,padding:"2px 8px",borderRadius:10,background:e?"rgba(41, 211, 145, 0.15)":"rgba(255, 102, 122, 0.15)",fontSize:10,fontWeight:500,color:e?"var(--lo-good)":"var(--lo-bad)"},children:[c.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:e?"var(--lo-good)":"var(--lo-bad)",boxShadow:e?"0 0 6px rgba(41,211,145,0.6)":"0 0 6px rgba(255,102,122,0.6)"}}),t(e?"livingOffice.hud.wsOnline":"livingOffice.hud.wsOffline")]})}function M8({lines:e}){const t=e.filter(r=>r.active),n=t.length>0?t:e.slice(-2);return c.jsx("div",{style:{display:"flex",gap:8,overflow:"hidden",maskImage:"linear-gradient(90deg, #000 80%, transparent 100%)",WebkitMaskImage:"linear-gradient(90deg, #000 80%, transparent 100%)"},children:n.map(r=>c.jsxs("span",{style:{fontSize:9,color:r.active?"var(--lo-cyan)":"var(--lo-muted)",whiteSpace:"nowrap",flexShrink:0},children:[r.label,c.jsx("span",{style:{opacity:.6,marginLeft:3},children:r.detail})]},r.label))})}function O8(){const{t:e}=se("office"),t=ie(s=>s.connectionStatus),n=Dn(s=>s.sceneArea.gatewayStream),r=t==="connected";return c.jsxs(am,{title:e("livingOffice.hud.gatewayTitle"),headerExtra:c.jsx(R8,{isOnline:r}),storageKey:"lo-hud-gateway",defaultCollapsed:!0,collapsedContent:c.jsx(M8,{lines:n}),children:[c.jsx("div",{style:{fontSize:10,color:"var(--lo-muted)",marginBottom:6},children:e("livingOffice.hud.gatewaySubtitle")}),c.jsx("div",{style:{display:"flex",flexDirection:"column",gap:3},children:n.map(s=>c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:10,color:s.active?"var(--lo-cyan)":"var(--lo-muted)"},children:[c.jsx("span",{style:{fontWeight:500},children:s.label}),c.jsx("span",{style:{opacity:.75},children:s.detail})]},s.label))})]})}function _8({left:e,center:t,right:n}){return c.jsxs("div",{className:"lo-hud-bar",style:{position:"absolute",top:8,left:8,right:8,zIndex:20,display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr)",gap:8,pointerEvents:"none",alignItems:"start"},children:[e&&c.jsx("div",{style:{pointerEvents:"auto",minWidth:0,overflow:"hidden"},children:e}),t&&c.jsx("div",{style:{pointerEvents:"auto",minWidth:0,overflow:"hidden"},children:t}),n&&c.jsx("div",{style:{pointerEvents:"auto",minWidth:0,overflow:"hidden"},children:n})]})}const Cw=S.createContext(null);function L8(){const e=S.useContext(Cw);return(e==null?void 0:e.current)??null}function z8({stats:e}){return c.jsx("div",{style:{display:"flex",gap:10,alignItems:"center"},children:e.map(t=>c.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:3},children:[c.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:t.color,flexShrink:0}}),c.jsx("span",{style:{fontSize:9,color:"var(--lo-muted)"},children:t.label}),c.jsx("span",{style:{fontSize:10,fontWeight:700,color:t.color},children:t.value})]},t.label))})}function I8(){const{t:e}=se("office"),t=Dn(u=>u.agents),n=Dn(u=>u.sceneArea.cronTasks),r=S.useMemo(()=>{let u=0;for(const f of t.values())f.state!=="IDLE"&&f.state!=="DONE"&&u++;return u},[t]),s=S.useMemo(()=>{let u=0;for(const f of t.values())f.taskSummary&&u++;return u},[t]),o=[{label:e("livingOffice.hud.statsActive"),value:r,color:"var(--lo-cyan)"},{label:e("livingOffice.hud.statsPending"),value:s,color:"var(--lo-warn)"},{label:e("livingOffice.hud.statsCron"),value:n.length,color:"var(--lo-violet)"}];return c.jsx(am,{title:e("livingOffice.hud.statsTitle"),storageKey:"lo-hud-stats",defaultCollapsed:!0,collapsedContent:c.jsx(z8,{stats:o}),children:c.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:4},children:o.map(u=>c.jsxs("div",{style:{textAlign:"center"},children:[c.jsx("div",{style:{fontSize:22,fontWeight:700,color:u.color,lineHeight:1.1},children:u.value}),c.jsx("div",{style:{fontSize:9,color:"var(--lo-muted)",marginTop:2},children:u.label})]},u.label))})})}const H8=34;function B8(){const e=S.useMemo(()=>{const t=[];for(let n=0;n<H8;n++)t.push({left:`${mc(n,0)*100}vw`,top:`${mc(n,1)*100}vh`,duration:`${20+mc(n,2)*30}s`,delay:`${-mc(n,3)*40}s`});return t},[]);return c.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",overflow:"hidden"},children:e.map((t,n)=>c.jsx("i",{style:{position:"absolute",width:2,height:2,borderRadius:"50%",background:"rgba(255,255,255,.45)",boxShadow:"0 0 12px rgba(255,255,255,.3)",left:t.left,top:t.top,animation:`lo-float-star ${t.duration} linear infinite`,animationDelay:t.delay,opacity:.45}},n))})}function mc(e,t){const n=Math.sin(e*9301+t*49297+233280)*49297;return n-Math.floor(n)}function U8(){return c.jsx("div",{style:{position:"absolute",inset:0,backgroundImage:["linear-gradient(to right, rgba(255,255,255,.03) 1px, transparent 1px)","linear-gradient(to bottom, rgba(255,255,255,.03) 1px, transparent 1px)"].join(", "),backgroundSize:"60px 60px",opacity:.18}})}function $8(){return c.jsx("div",{className:"lo-floor",style:{position:"absolute",inset:0,borderRadius:34,border:"1px solid var(--lo-line)",boxShadow:"var(--lo-shadow)"}})}function q8({children:e}){return c.jsxs("div",{className:"lo-world",children:[c.jsx(U8,{}),c.jsxs("div",{className:"lo-office",children:[c.jsx($8,{}),e]}),c.jsx(B8,{})]})}function K8({text:e,duration:t=2600}){const[n,r]=S.useState(!1),[s,o]=S.useState(!1);return S.useEffect(()=>{if(!e){r(!1);return}r(!0),o(!1);const u=setTimeout(()=>o(!0),t-350),f=setTimeout(()=>r(!1),t);return()=>{clearTimeout(u),clearTimeout(f)}},[e,t]),!n||!e?null:c.jsx("div",{style:{position:"absolute",left:"50%",top:-22,transform:"translateX(-50%) translateZ(20px) translateY(-6px)",padding:"7px 10px",borderRadius:999,whiteSpace:"nowrap",fontSize:11,color:"#eef7ff",background:"rgba(8, 18, 32, .85)",border:"1px solid rgba(255,255,255,.08)",boxShadow:"0 14px 30px rgba(0,0,0,.28)",animation:s?"lo-bubble-out 0.35s ease forwards":"lo-bubble-in 0.35s ease forwards",pointerEvents:"none"},children:e})}const P8={idle:"var(--lo-good)",busy:"var(--lo-warn)",blocked:"var(--lo-bad)",heartbeat:"var(--lo-cyan)"};function F8({status:e}){const t=P8[e],n=e==="busy"||e==="blocked";return c.jsx("div",{className:n?"lo-desk-ring-active":"lo-desk-ring-idle",style:{position:"absolute",right:10,top:10,width:14,height:14,borderRadius:"50%",background:t,boxShadow:`0 0 12px ${t}`}})}function G8({config:e,status:t="idle",bubble:n=""}){const r=t==="heartbeat";return c.jsxs("div",{"data-desk-id":e.id,style:{position:"absolute",left:e.position.left,top:e.position.top,width:160,height:108,transform:"translateZ(12px)"},children:[r&&c.jsx("div",{style:{position:"absolute",inset:-8,borderRadius:24,border:"2px solid rgba(92,200,255,.16)",animation:"lo-pulse 1.6s ease-out infinite",pointerEvents:"none"}}),c.jsx("div",{style:{position:"absolute",inset:0,background:"var(--lo-glass-bg)",borderRadius:20,border:"var(--lo-glass-border)",boxShadow:"var(--lo-shadow)"}}),c.jsx("div",{className:t==="busy"?"lo-desk-monitor-active":"lo-desk-monitor-idle",style:{position:"absolute",left:46,top:18,width:68,height:30,borderRadius:8,background:t==="busy"?"linear-gradient(180deg, color-mix(in srgb, var(--lo-cyan) 50%, transparent), color-mix(in srgb, var(--lo-cyan) 15%, transparent))":"linear-gradient(180deg, color-mix(in srgb, var(--lo-cyan) 35%, transparent), color-mix(in srgb, var(--lo-cyan) 8%, transparent))",border:"1px solid color-mix(in srgb, var(--lo-cyan) 25%, transparent)",boxShadow:t==="busy"?"0 0 30px color-mix(in srgb, var(--lo-cyan) 25%, transparent)":"0 0 24px color-mix(in srgb, var(--lo-cyan) 14%, transparent)",transition:"background 0.5s ease, box-shadow 0.5s ease"}}),c.jsx(F8,{status:t}),c.jsx("div",{style:{position:"absolute",left:10,bottom:10,fontSize:11,color:"var(--lo-text)",fontWeight:700},children:e.agentName}),c.jsx("div",{style:{position:"absolute",right:10,bottom:10,fontSize:10,color:"var(--lo-muted)"},children:e.role}),c.jsx(K8,{text:n})]})}function V8(){return c.jsxs("div",{style:{position:"absolute",left:1240,top:258,width:30,height:30,borderRadius:"50%",transform:"translateZ(12px)",background:"radial-gradient(circle, rgba(247,185,85,.95), rgba(247,185,85,.25))",boxShadow:"0 0 24px rgba(247,185,85,.35)"},children:[c.jsx(Dv,{delay:"0s"}),c.jsx(Dv,{delay:"1.1s"})]})}function Dv({delay:e}){return c.jsx("div",{style:{position:"absolute",inset:-8,borderRadius:"50%",border:"2px solid rgba(247,185,85,.22)",animation:"lo-rings 2.2s ease-out infinite",animationDelay:e}})}function mu({children:e,className:t="",style:n}){return c.jsx("div",{className:t,style:{borderRadius:22,background:"linear-gradient(180deg, rgba(9,16,30,.95), rgba(8,13,25,.88))",border:"1px solid rgba(255,255,255,.07)",boxShadow:"var(--lo-glow)",overflow:"hidden",...n},children:e})}function pu({title:e,subtitle:t}){return c.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 14px 8px"},children:[c.jsx("b",{style:{fontSize:13,color:"#e9f2ff"},children:e}),t&&c.jsx("span",{style:{fontSize:11,color:"var(--lo-muted)"},children:t})]})}function Y8({tasks:e}){const{t}=se("office"),n=Vc(u=>u.tasks),r=e??[{name:"09:20 订单看板汇总",status:"scheduled"},{name:"10:00 线索清洗广播",status:"scheduled"},{name:"11:30 回款提醒",status:"scheduled"}],s=S.useMemo(()=>n.map(u=>({name:u.name,status:u.state.runningAtMs?"running":u.enabled?u.state.lastRunStatus??"scheduled":"paused"})),[n]),o=s.length>0?s:r;return c.jsxs(mu,{style:{position:"absolute",left:1068,top:38,width:344,height:214,transform:"translateZ(16px)"},children:[c.jsx(pu,{title:t("livingOffice.panels.cronTitle"),subtitle:t("livingOffice.panels.cronSubtitle")}),c.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7,padding:"0 14px 14px"},children:o.slice(0,3).map(u=>c.jsx(Q8,{left:u.name,right:u.status},u.name))})]})}function Q8({left:e,right:t}){return c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,fontSize:11,padding:"7px 9px",background:"rgba(255,255,255,.04)",borderRadius:10},children:[c.jsx("span",{style:{color:"#e6eefc"},children:e}),c.jsx("span",{style:{color:"var(--lo-muted)"},children:t})]})}function Hr({config:e,children:t,className:n="",style:r}){return c.jsx("div",{className:n,style:{position:"absolute",left:e.position.left,top:e.position.top,width:e.size.width,height:e.size.height,borderRadius:26,border:"1px solid rgba(255,255,255,.06)",background:"linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.015))",boxShadow:"inset 0 1px 0 rgba(255,255,255,.05), 0 16px 40px rgba(0,0,0,.28)",transform:"translateZ(4px)",...r},children:t})}function W8(){const e=Ir.cron;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:e}),c.jsx(Y8,{}),c.jsx(V8,{})]})}function X8(){var h,g,y;const{t:e}=se("office"),[t,n]=S.useState(()=>Rv()),r=ie(p=>p.connectionStatus),s=ie(p=>p.operatorScopes),o=ie(p=>p.globalMetrics),u=Dn(p=>p.sceneArea.gatewayStream);S.useEffect(()=>{const p=setInterval(()=>n(Rv()),1e3);return()=>clearInterval(p)},[]);const f=[{title:e("livingOffice.panels.busWebSocket"),detail:((h=u.find(p=>p.label==="WebSocket"))==null?void 0:h.detail)??r},{title:e("livingOffice.panels.busEventSpine"),detail:((g=u.find(p=>p.label==="Event Bus"))==null?void 0:g.detail)??`active ${o.activeAgents}/${o.totalAgents}`},{title:e("livingOffice.panels.busRpcScope"),detail:((y=u.find(p=>p.label==="RPC"))==null?void 0:y.detail)??s[0]??"operator"}];return c.jsxs("div",{style:{position:"absolute",left:48,top:38,width:404,height:214,transform:"translateZ(20px)",borderRadius:24,background:"linear-gradient(180deg, rgba(12, 30, 55, .96), rgba(8,16,30,.96))",border:"1px solid rgba(92,200,255,.24)",boxShadow:"0 18px 40px rgba(0,0,0,.28), 0 0 35px rgba(92,200,255,.12), inset 0 1px 0 rgba(255,255,255,.08)",overflow:"hidden"},children:[c.jsx("div",{style:{position:"absolute",inset:0,background:"linear-gradient(90deg, transparent, rgba(92,200,255,.18), transparent)",transform:"translateX(-100%)",animation:"lo-scan 6s linear infinite"}}),c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"14px 16px 6px",position:"relative"},children:[c.jsx("b",{style:{fontSize:15,color:"#e9f2ff"},children:e("livingOffice.panels.gatewayHeader")}),c.jsx("span",{style:{fontSize:11,color:"var(--lo-muted)"},children:t})]}),c.jsx("div",{style:{position:"absolute",left:16,right:16,bottom:14,height:64,display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:10},children:f.map(p=>c.jsxs("div",{style:{borderRadius:14,background:"rgba(255,255,255,.04)",border:"1px solid rgba(255,255,255,.05)",padding:10,fontSize:11},children:[c.jsx("b",{style:{display:"block",marginBottom:3,color:"#e9f2ff"},children:p.title}),c.jsx("small",{style:{color:"var(--lo-muted)"},children:p.detail})]},p.title))})]})}function Rv(){const e=we.language==="zh"?"zh-CN":"en-US";return new Date().toLocaleTimeString(e,{hour12:!1})}function Z8(){const e=Ir.gateway;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:e}),c.jsx(X8,{}),c.jsx(J8,{})]})}function J8(){return c.jsx("div",{style:{position:"absolute",left:48,top:258,width:404,height:18,transform:"translateZ(6px)",overflow:"hidden",borderRadius:999,background:"rgba(255,255,255,.04)",border:"1px solid rgba(255,255,255,.06)"},children:c.jsx("div",{style:{position:"absolute",left:-120,top:1,width:120,height:14,borderRadius:999,background:"linear-gradient(90deg, rgba(92,200,255,.2), rgba(92,200,255,.85), rgba(255,255,255,.15))",boxShadow:"0 0 22px rgba(92,200,255,.35)",animation:"lo-belt 8s linear infinite"}})})}function ez({left:e,top:t}){return c.jsxs("div",{style:{position:"absolute",left:e,top:t,width:72,height:38,transform:"translateZ(8px)"},children:[c.jsx("div",{style:{position:"absolute",left:4,top:10,width:64,height:24,borderRadius:12,background:"linear-gradient(180deg, rgba(143,125,255,.18), rgba(92,200,255,.08))",border:"1px solid rgba(143,125,255,.15)",boxShadow:"0 4px 12px rgba(0,0,0,.2), inset 0 1px 0 rgba(255,255,255,.06)"}}),c.jsx("div",{style:{position:"absolute",left:8,top:2,width:56,height:12,borderRadius:"10px 10px 4px 4px",background:"linear-gradient(180deg, rgba(143,125,255,.25), rgba(143,125,255,.12))",border:"1px solid rgba(143,125,255,.12)"}}),c.jsx("div",{style:{position:"absolute",left:0,top:8,width:8,height:22,borderRadius:"6px 0 0 6px",background:"rgba(143,125,255,.14)",border:"1px solid rgba(143,125,255,.10)"}}),c.jsx("div",{style:{position:"absolute",right:0,top:8,width:8,height:22,borderRadius:"0 6px 6px 0",background:"rgba(143,125,255,.14)",border:"1px solid rgba(143,125,255,.10)"}})]})}function Js({left:e,top:t}){return c.jsx("div",{style:{position:"absolute",left:e,top:t,width:32,height:20,transform:"translateZ(6px)",borderRadius:8,background:"linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02))",border:"1px solid rgba(255,255,255,.06)",boxShadow:"0 4px 10px rgba(0,0,0,.15)"},children:c.jsx("div",{style:{position:"absolute",left:10,top:4,width:12,height:12,borderRadius:"50%",background:"rgba(247,185,85,.2)",border:"1px solid rgba(247,185,85,.15)"}})})}function pc({left:e,top:t}){return c.jsxs("div",{style:{position:"absolute",left:e,top:t,width:22,height:30,transform:"translateZ(10px)"},children:[c.jsx("div",{style:{position:"absolute",left:4,bottom:0,width:14,height:12,borderRadius:"3px 3px 6px 6px",background:"rgba(180,120,70,.3)",border:"1px solid rgba(180,120,70,.2)"}}),c.jsx("div",{style:{position:"absolute",left:2,top:0,width:18,height:18,borderRadius:"50%",background:"radial-gradient(circle, rgba(52,211,153,.35), rgba(22,163,74,.15))"}})]})}function tz(){return c.jsxs(c.Fragment,{children:[m8.map((e,t)=>c.jsx(ez,{left:e.left,top:e.top},`sofa-${String(t)}`)),c.jsx(Js,{left:240,top:755}),c.jsx(Js,{left:680,top:755}),c.jsx(Js,{left:1100,top:755}),c.jsx(Js,{left:360,top:835}),c.jsx(Js,{left:800,top:835}),c.jsx(pc,{left:60,top:710}),c.jsx(pc,{left:1350,top:710}),c.jsx(pc,{left:500,top:845}),c.jsx(pc,{left:960,top:845})]})}function nz(){const{t:e}=se("office"),t=Ir.lounge;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:t,children:c.jsx("div",{style:{position:"absolute",left:14,top:10,fontSize:11,fontWeight:600,letterSpacing:"0.06em",color:"var(--lo-muted)",opacity:.7,transform:"translateZ(8px)"},children:e("livingOffice.zones.lounge")})}),c.jsx(tz,{})]})}const az=[];function rz({entries:e=az}){const{t}=se("office"),n=Dn(s=>s.sceneArea.memoryItems),r=n.length>0?n:e;return c.jsxs(mu,{style:{position:"absolute",left:1068,top:556,width:344,height:68,transform:"translateZ(16px)"},children:[c.jsx(pu,{title:t("livingOffice.panels.memoryTitle"),subtitle:t("livingOffice.panels.memorySubtitle")}),c.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7,padding:"0 14px 14px"},children:r.length>0?r.slice(-3).reverse().map(s=>c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,fontSize:11,padding:"7px 9px",background:"rgba(255,255,255,.04)",borderRadius:10},children:[c.jsx("span",{style:{color:"#e6eefc"},children:s.text}),c.jsx("span",{style:{color:"var(--lo-muted)"},children:s.tag})]},s.text)):c.jsx("div",{style:{fontSize:11,padding:"7px 9px",background:"rgba(255,255,255,.04)",borderRadius:10,color:"var(--lo-muted)"},children:t("livingOffice.panels.memoryEmpty")})})]})}function iz(){const e=Ir.memory;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:e}),c.jsx(rz,{})]})}function sz({rules:e=[]}){const{t}=se("office"),n=Dn(b=>b.sceneArea.opsRules),r=ie(b=>b.agents),s=ie(b=>b.links),o=ie(b=>b.maxSubAgents),u=ie(b=>b.agentToAgentConfig),f=Array.from(r.values()).filter(b=>b.status==="error").length,h=Array.from(r.values()).filter(b=>b.isSubAgent&&!b.isPlaceholder).length,g=u.enabled?t("livingOffice.panels.opsEnabled"):t("livingOffice.panels.opsDisabled"),y=n.length>0?n.slice(-4).reverse().map(b=>`${b.tag} · ${b.text}`):[`${t("livingOffice.panels.opsErrorAgents")} · ${f}`,`${t("livingOffice.panels.opsCollabLinks")} · ${s.length}`,`${t("livingOffice.panels.opsAgentToAgent")} · ${g}`,`${t("livingOffice.panels.opsSubCapacity")} · ${h}/${o}`],p=y.length>0?y:e;return c.jsxs(mu,{style:{position:"absolute",left:508,top:38,width:504,height:214,transform:"translateZ(16px)"},children:[c.jsx(pu,{title:t("livingOffice.panels.opsTitle"),subtitle:t("livingOffice.panels.opsSubtitle")}),c.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7,padding:"0 14px 14px"},children:p.slice(0,4).map(b=>c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,fontSize:11,padding:"7px 9px",background:"rgba(255,255,255,.04)",borderRadius:10},children:[c.jsx("span",{style:{color:"#e6eefc"},children:b}),c.jsx("span",{style:{color:"var(--lo-muted)"},children:t("livingOffice.panels.opsLive")})]},b))})]})}function lz(){const e=Ir.ops;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:e}),c.jsx(sz,{})]})}function oz({tasks:e}){const{t}=se("office"),n=e??[{title:t("livingOffice.panels.projectEmpty"),subtitle:t("livingOffice.panels.projectEmptySub")}],r=ie(h=>h.lastSessionsSnapshot),s=Dn(h=>h.sceneArea.projectTasks),o=r==null?void 0:r.sessions,u=o&&o.length>0?o.map(h=>({title:h.label||h.agentId,subtitle:h.task||h.requesterSessionKey})):s,f=S.useMemo(()=>u.length>0?u:n,[u,n]);return c.jsxs(mu,{style:{position:"absolute",left:1068,top:308,width:344,height:194,transform:"translateZ(16px)"},children:[c.jsx(pu,{title:t("livingOffice.panels.projectTitle"),subtitle:t("livingOffice.panels.projectSubtitle")}),c.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:"0 14px 14px"},children:f.slice(0,3).map(h=>c.jsxs("div",{style:{padding:"8px 10px",borderRadius:12,background:"rgba(255,255,255,.04)",border:"1px solid rgba(255,255,255,.05)",fontSize:11,color:"#e6eefc"},children:[h.title,c.jsx("small",{style:{color:"var(--lo-muted)",display:"block",marginTop:3},children:h.subtitle})]},h.title))})]})}function cz(){const e=Ir.project;return c.jsxs(c.Fragment,{children:[c.jsx(Hr,{config:e}),c.jsx(oz,{})]})}function uz(){const{t:e}=se("office"),t=Ir.staff;return c.jsx(Hr,{config:t,children:c.jsx("div",{style:{position:"absolute",left:14,top:10,fontSize:11,fontWeight:600,letterSpacing:"0.06em",color:"var(--lo-muted)",opacity:.7,transform:"translateZ(8px)"},children:e("livingOffice.zones.staffFloor")})})}function Nw(e){switch(e){case"WORKING":case"TOOL_CALL":case"COLLABORATING":case"INCOMING":case"ACK":return"busy";case"BLOCKED":return"blocked";default:return"idle"}}const el={left:30,top:290,width:1e3,height:350},Nh=160,Mv=108,yc=30,Ov=50;function dz(e){const[t,n]=S.useState("0.92"),r=S.useCallback(()=>{const s=e.current;if(!s)return;const{width:o,height:u}=s.getBoundingClientRect(),f=o/j8,h=u/C8,g=Math.min(f,h,1.05);n(g.toFixed(3))},[e]);return S.useEffect(()=>{r();const s=new ResizeObserver(r);return e.current&&s.observe(e.current),()=>s.disconnect()},[r,e]),t}function fz(e){if(e<=hl.length)return hl.slice(0,Math.max(e,hl.length));const t=Math.min(e,Math.floor((el.width+yc)/(Nh+yc))),n=Math.ceil(e/t),r=t*Nh+(t-1)*yc,s=n*Mv+(n-1)*Ov,o=el.left+Math.max(0,(el.width-r)/2),u=el.top+Math.max(0,(el.height-s)/2),f=[];for(let h=0;h<e;h++){const g=h%t,y=Math.floor(h/t);f.push({id:`desk-dyn-${h}`,agentName:`Agent ${h+1}`,role:"",position:{left:o+g*(Nh+yc),top:u+y*(Mv+Ov)}})}return f}function hz(e){const t=Array.from(e.values());return(t.length>hl.length?fz(t.length):hl).map((r,s)=>{const o=t[s];return o?{desk:{...r,agentName:o.role!==o.agentId?o.role:o.agentId,role:o.role,status:Nw(o.state)},agent:o}:{desk:r,agent:void 0}})}function gz(){const e=Dn(h=>h.agents),t=ie(h=>h.connectionStatus),n=L8();S.useRef(null);const r=S.useRef(null),s=dz(r),o=S.useMemo(()=>hz(e),[e]),u=Array.from(e.values()).filter(h=>h.state==="COLLABORATING"),f=S8(u.map(h=>({agentId:h.agentId,name:h.role})));return S.useEffect(()=>{},[n]),S.useEffect(()=>{if(t!=="connected")return;const h=Vc.getState();h.fetchTasks();const g=h.initEventListeners(),y=setInterval(()=>{Vc.getState().fetchTasks()},3e4);return()=>{clearInterval(y),g()}},[t]),c.jsxs("div",{className:"living-office",style:{position:"relative",width:"100%",height:"100%",overflow:"hidden",background:"var(--lo-app-bg)",fontFamily:'Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif',color:"var(--lo-text)"},children:[c.jsx("div",{style:{position:"absolute",inset:0,background:"var(--lo-app-overlay)",pointerEvents:"none"}}),c.jsx(_8,{left:c.jsx(O8,{}),center:c.jsx(D8,{}),right:c.jsx(I8,{})}),c.jsx("div",{ref:r,style:{position:"absolute",inset:"46px 8px 6px 8px","--lo-stage-scale":s,"--lo-stage-scale-sm":s},children:c.jsxs(q8,{children:[c.jsx(Z8,{}),c.jsx(lz,{}),c.jsx(W8,{}),c.jsx(uz,{}),c.jsx(nz,{}),c.jsx(cz,{}),c.jsx(iz,{}),o.map(({desk:h,agent:g})=>c.jsx(G8,{config:h,status:g?Nw(g.state):"idle",bubble:(g==null?void 0:g.taskSummary)??""},h.id)),o.map(({desk:h,agent:g})=>c.jsx(b8,{agentId:(g==null?void 0:g.agentId)??h.id,deskId:h.id,name:(g==null?void 0:g.role)??h.agentName,perceivedState:(g==null?void 0:g.state)??"IDLE",toolName:g==null?void 0:g.tool},`char-${h.id}`)),f.map(h=>{const g=g8[h.slotIndex];return g?c.jsx(k8,{agentId:h.agentId,name:h.name,position:g,active:!0},`sub-${h.agentId}`):null})]})})]})}const mz=2,pz=8,il=S.memo(function({agent:t}){const{t:n}=se("common"),r=ie(P=>P.selectedAgentId),s=ie(P=>P.selectAgent),o=ie(P=>P.tickMovement),u=ie(P=>P.theme),[f,h]=S.useState(!1),g=S.useRef(null),y=S.useRef(0),p=S.useRef(0),b=r===t.id,v=b?rl.selectedRadius:rl.radius,k=t.isPlaceholder,j=!t.confirmed,N=t.movement!==null,C=k||j?"#6b7280":Ml[t.status],E=u==="dark",R=xw(t.id),H=`avatar-clip-${t.id}`,z=k?.3:j?.5:1,L=t.name.length>rl.nameLabelMaxChars?`${t.name.slice(0,rl.nameLabelMaxChars)}…`:t.name,G=S.useRef(t.id);G.current=t.id;const W=S.useCallback(P=>{if(!g.current)return;const M=p.current?(P-p.current)/1e3:.016;p.current=P,o(G.current,M);const V=ie.getState().agents.get(G.current);if(!V)return;let ae=0,J=1;if(V.movement){const Z=V.movement.progress,U=(Date.now()-V.movement.startTime)/1e3;if(ae=Math.sin(U*pz*Math.PI*2)*mz,Z<.1)J=.9+Z;else if(Z>.9){const ee=(Z-.9)/.1;J=1-.05*Math.sin(ee*Math.PI)}}g.current.setAttribute("transform",`translate(${V.position.x}, ${V.position.y+ae}) scale(${J})`),V.movement&&(y.current=requestAnimationFrame(W))},[o]);return S.useEffect(()=>(N&&(p.current=0,y.current=requestAnimationFrame(W)),()=>{y.current&&cancelAnimationFrame(y.current)}),[N,W]),c.jsxs("g",{ref:g,transform:`translate(${t.position.x}, ${t.position.y})`,style:{cursor:k?"default":"pointer"},opacity:z,onClick:()=>!k&&s(t.id),onMouseEnter:()=>!k&&h(!0),onMouseLeave:()=>h(!1),children:[b&&c.jsx("circle",{r:v+8,fill:C,opacity:.18,style:{filter:`drop-shadow(0 0 10px ${C})`}}),c.jsx(yz,{status:t.status,r:v,color:C,isWalking:N,isPlaceholder:k}),c.jsx("defs",{children:c.jsx("clipPath",{id:H,children:c.jsx("circle",{r:v-2})})}),c.jsx("circle",{r:v-2,fill:E?"#1e293b":"#f8fafc"}),c.jsx("g",{clipPath:`url(#${H})`,children:c.jsx(kz,{data:R,size:v*2-4})}),t.isSubAgent&&c.jsxs("g",{transform:`translate(${v*.6}, ${v*.5})`,children:[c.jsx("circle",{r:7,fill:E?"#1e293b":"#fff",stroke:C,strokeWidth:1.2}),c.jsx("text",{textAnchor:"middle",dy:"3.5",fontSize:"9",fill:C,fontWeight:"bold",children:"S"})]}),t.status==="thinking"&&c.jsx(bz,{r:v}),t.status==="error"&&c.jsxs("g",{transform:`translate(${v*.65}, ${-v*.65})`,children:[c.jsx("circle",{r:7,fill:"#ef4444"}),c.jsx("text",{textAnchor:"middle",dy:"4",fontSize:"10",fill:"#fff",fontWeight:"bold",children:"!"})]}),t.status==="speaking"&&c.jsx(vz,{r:v}),t.status==="tool_calling"&&t.currentTool&&c.jsx("foreignObject",{x:-50,y:v+2,width:100,height:20,style:{pointerEvents:"none"},children:c.jsx("div",{style:{display:"flex",justifyContent:"center"},children:c.jsx("span",{style:{fontSize:"9px",fontWeight:600,color:"#fff",backgroundColor:"#f97316",borderRadius:"4px",padding:"1px 6px",whiteSpace:"nowrap",maxWidth:"90px",overflow:"hidden",textOverflow:"ellipsis"},children:t.currentTool.name})})}),c.jsx("foreignObject",{x:-60,y:v+(t.status==="tool_calling"&&t.currentTool?18:4),width:120,height:22,style:{pointerEvents:"none"},children:c.jsx("div",{style:{display:"flex",justifyContent:"center"},children:c.jsx("span",{title:t.name,style:{fontSize:"11px",fontWeight:500,color:E?"#cbd5e1":"#475569",backgroundColor:E?"rgba(30,41,59,0.7)":"rgba(255,255,255,0.75)",backdropFilter:"blur(6px)",borderRadius:"6px",padding:"1px 8px",whiteSpace:"nowrap",border:`1px solid ${E?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)"}`},children:L})})}),f&&c.jsx("foreignObject",{x:-80,y:-v-38,width:160,height:32,style:{pointerEvents:"none"},children:c.jsx("div",{style:{display:"flex",justifyContent:"center"},children:c.jsxs("span",{style:{fontSize:"11px",fontWeight:500,color:E?"#e2e8f0":"#374151",backgroundColor:E?"rgba(30,41,59,0.85)":"rgba(255,255,255,0.9)",backdropFilter:"blur(8px)",borderRadius:"8px",padding:"4px 10px",whiteSpace:"nowrap",boxShadow:E?"0 4px 8px rgba(0,0,0,0.3)":"0 4px 8px rgba(0,0,0,0.1)",border:`1px solid ${E?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}`},children:[t.name," · ",n(`agent.statusLabels.${t.status}`)]})})})]})});function yz({status:e,r:t,color:n,isWalking:r,isPlaceholder:s}){const o=r||s?{}:xz(e),u=r?"4 3":s?"6 3":void 0,f=r?"#3b82f6":n;return c.jsx("circle",{r:t,fill:"none",stroke:f,strokeWidth:rl.strokeWidth,strokeDasharray:u,style:{transition:"stroke 300ms ease",...o}})}function xz(e){switch(e){case"thinking":return{animation:"agent-pulse 1.5s ease-in-out infinite"};case"tool_calling":return{animation:"agent-pulse 2s ease-in-out infinite",strokeDasharray:"6 3"};case"speaking":return{animation:"agent-pulse 1s ease-in-out infinite"};case"error":return{animation:"agent-blink 0.8s ease-in-out infinite"};case"spawning":return{animation:"agent-spawn 0.5s ease-out forwards"};default:return{}}}function bz({r:e}){return c.jsx("g",{transform:`translate(${e*.55}, ${-e*.7})`,children:[0,1,2].map(t=>c.jsx("circle",{cx:t*5,cy:0,r:2,fill:"#3b82f6",style:{animation:`thinking-dots 1.2s ease-in-out ${t*.15}s infinite`}},t))})}function vz({r:e}){return c.jsxs("g",{transform:`translate(${e*.55}, ${-e*.75})`,children:[c.jsxs("circle",{r:7,fill:"#a855f7",opacity:.9,children:[c.jsx("animate",{attributeName:"r",values:"6;8;6",dur:"1.5s",repeatCount:"indefinite"}),c.jsx("animate",{attributeName:"opacity",values:"0.9;0.5;0.9",dur:"1.5s",repeatCount:"indefinite"})]}),c.jsx("g",{transform:"translate(-4.5,-4.5) scale(0.45)",children:c.jsx("path",{fill:"#fff",fillRule:"evenodd",d:"M3.43 2.524A41.29 41.29 0 0110 2c2.236 0 4.43.18 6.57.524 1.437.231 2.43 1.49 2.43 2.902v5.148c0 1.413-.993 2.67-2.43 2.902a41.102 41.102 0 01-3.55.414c-.28.02-.521.18-.643.413l-1.712 3.293a.75.75 0 01-1.33 0l-1.713-3.293a.783.783 0 00-.642-.413 41.108 41.108 0 01-3.55-.414C1.993 13.245 1 11.986 1 10.574V5.426c0-1.413.993-2.67 2.43-2.902z",clipRule:"evenodd"})})]})}function kz({data:e,size:t}){const n=t/2,r=e.faceShape==="round"?n*.8:e.faceShape==="oval"?n*.7:n*.75,s=e.faceShape==="oval"?n*.9:r;return c.jsxs("g",{children:[c.jsx("rect",{x:-n,y:n*.4,width:t,height:n*1.2,fill:e.shirtColor}),c.jsx("ellipse",{cx:0,cy:-n*.05,rx:r,ry:s,fill:e.skinColor}),c.jsx(wz,{style:e.hairStyle,color:e.hairColor,s:n,faceRx:r}),c.jsx(Sz,{style:e.eyeStyle,s:n})]})}function wz({style:e,color:t,s:n,faceRx:r}){switch(e){case"short":return c.jsx("ellipse",{cx:0,cy:-n*.55,rx:r*.95,ry:n*.45,fill:t});case"spiky":return c.jsxs("g",{children:[c.jsx("ellipse",{cx:0,cy:-n*.55,rx:r*.9,ry:n*.4,fill:t}),[-.4,-.15,.1,.35].map(s=>c.jsx("polygon",{points:`${s*n*2},-${n*.85} ${s*n*2-3},-${n*.5} ${s*n*2+3},-${n*.5}`,fill:t},s))]});case"side-part":return c.jsxs("g",{children:[c.jsx("ellipse",{cx:-n*.1,cy:-n*.55,rx:r,ry:n*.45,fill:t}),c.jsx("rect",{x:r*.3,y:-n*.9,width:r*.5,height:n*.3,rx:3,fill:t})]});case"curly":return c.jsx("g",{children:[[-.35,-.7],[0,-.78],[.35,-.7],[-.5,-.45],[.5,-.45]].map(([s,o],u)=>c.jsx("circle",{cx:s*n,cy:o*n,r:n*.22,fill:t},u))});case"buzz":return c.jsx("ellipse",{cx:0,cy:-n*.45,rx:r*.85,ry:n*.35,fill:t,opacity:.7});default:return null}}function Sz({style:e,s:t}){const n=-t*.08,r=t*.28;switch(e){case"dot":return c.jsxs("g",{children:[c.jsx("circle",{cx:-r,cy:n,r:2,fill:"#333"}),c.jsx("circle",{cx:r,cy:n,r:2,fill:"#333"})]});case"line":return c.jsxs("g",{children:[c.jsx("line",{x1:-r-3,y1:n,x2:-r+3,y2:n,stroke:"#333",strokeWidth:1.5,strokeLinecap:"round"}),c.jsx("line",{x1:r-3,y1:n,x2:r+3,y2:n,stroke:"#333",strokeWidth:1.5,strokeLinecap:"round"})]});case"wide":return c.jsxs("g",{children:[c.jsx("ellipse",{cx:-r,cy:n,rx:3,ry:2.5,fill:"#fff",stroke:"#333",strokeWidth:.8}),c.jsx("circle",{cx:-r,cy:n,r:1.2,fill:"#333"}),c.jsx("ellipse",{cx:r,cy:n,rx:3,ry:2.5,fill:"#fff",stroke:"#333",strokeWidth:.8}),c.jsx("circle",{cx:r,cy:n,r:1.2,fill:"#333"})]});default:return null}}function jz({x1:e,y1:t,x2:n,y2:r,strength:s}){const o=(e+n)/2,u=(t+r)/2,f=n-e,h=r-t,g=Math.sqrt(f*f+h*h),y=Math.min(g*.2,50),p=o-h/g*y,b=u+f/g*y,v=`M ${e} ${t} Q ${p} ${b} ${n} ${r}`,k=s>=.5,j=k?3:1.5,N=Math.max(.2,s);return c.jsxs("g",{children:[c.jsx("path",{d:v,fill:"none",stroke:"#60a5fa",strokeWidth:j+2,opacity:Math.max(.03,s*.15),style:{filter:"blur(3px)"}}),c.jsx("path",{d:v,fill:"none",stroke:"#60a5fa",strokeWidth:j,strokeDasharray:k?"12,6":"6,4",opacity:N,style:{animation:k?"connection-pulse 0.8s linear infinite":"dash-flow 1.5s linear infinite",filter:k?"drop-shadow(0 0 4px rgba(96,165,250,0.8))":void 0}})]})}const Cz=S.memo(function({x:t,y:n,isDark:r=!1}){const s=r?"#334155":"#dfe5ed",o=r?"#283548":"#c8d0dc",u=r?"#1e293b":"#f1f5f9",f=r?"#475569":"#94a3b8";return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx("rect",{x:-50,y:-6,width:100,height:60,rx:6,fill:s,stroke:o,strokeWidth:1}),c.jsx("path",{d:"M -50 54 L -50 60 Q -50 66 -44 66 L 44 66 Q 50 66 50 60 L 50 54",fill:o,opacity:.6}),c.jsx("rect",{x:-20,y:4,width:40,height:26,rx:3,fill:u,stroke:f,strokeWidth:.8}),c.jsx("rect",{x:-16,y:36,width:32,height:12,rx:2,fill:r?"#475569":"#cbd5e1",opacity:.6})]})}),hg=S.memo(function({x:t,y:n,isDark:r=!1}){const s=r?"#475569":"#94a3b8",o=r?"#334155":"#7c8ba0";return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx("path",{d:"M -12 -14 Q 0 -20 12 -14",fill:"none",stroke:o,strokeWidth:4,strokeLinecap:"round"}),c.jsx("circle",{r:14,fill:s,opacity:.85})]})}),Nz=S.memo(function({x:t,y:n,radius:r=80,isDark:s=!1}){const o=`mt-grad-${t}-${n}`,u=s?"#334155":"#bfcbda",f=s?"#3d4f66":"#dbe4ef";return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx("defs",{children:c.jsxs("radialGradient",{id:o,children:[c.jsx("stop",{offset:"0%",stopColor:f}),c.jsx("stop",{offset:"100%",stopColor:u})]})}),c.jsx("circle",{r,fill:`url(#${o})`,stroke:s?"#475569":"#94a3b8",strokeWidth:1.5,style:{filter:"drop-shadow(0 3px 6px rgba(0,0,0,0.10))"}})]})}),xc=S.memo(function({x:t,y:n,rotation:r=0,isDark:s=!1}){const o=s?"#475569":"#a5b4c8",u=s?"#334155":"#8494a7",f=s?"#5b6b80":"#c8d5e3";return c.jsxs("g",{transform:`translate(${t}, ${n}) rotate(${r})`,children:[c.jsx("rect",{x:-55,y:-22,width:110,height:44,rx:10,fill:u}),c.jsx("rect",{x:-48,y:-16,width:96,height:32,rx:6,fill:o}),c.jsx("circle",{cx:-30,cy:0,r:8,fill:f,opacity:.7}),c.jsx("circle",{cx:30,cy:0,r:8,fill:f,opacity:.7}),c.jsx("rect",{x:-52,y:-25,width:104,height:8,rx:4,fill:u,opacity:.7})]})}),bc=S.memo(function({x:t,y:n}){return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx("path",{d:"M -8 6 L -10 18 Q -10 22 -6 22 L 6 22 Q 10 22 10 18 L 8 6 Z",fill:"#a07050"}),c.jsx("ellipse",{cx:0,cy:-2,rx:12,ry:10,fill:"#4ade80",opacity:.85}),c.jsx("ellipse",{cx:-6,cy:-8,rx:8,ry:6,fill:"#22c55e",opacity:.7}),c.jsx("ellipse",{cx:6,cy:-6,rx:7,ry:5,fill:"#16a34a",opacity:.6})]})}),_v=S.memo(function({x:t,y:n}){return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx("ellipse",{cx:0,cy:4,rx:9,ry:3,fill:"#d1d5db",opacity:.5}),c.jsx("rect",{x:-5,y:-4,width:10,height:10,rx:2,fill:"#f5f5f4",stroke:"#d1d5db",strokeWidth:.6}),c.jsx("ellipse",{cx:0,cy:-2,rx:4,ry:1.5,fill:"#92400e",opacity:.7}),c.jsx("path",{d:"M 5 -1 Q 9 -1 9 3 Q 9 6 5 6",fill:"none",stroke:"#d1d5db",strokeWidth:1}),c.jsx("path",{d:"M -1 -7 Q 0 -10 1 -7",fill:"none",stroke:"#94a3b8",strokeWidth:.5,opacity:.4})]})}),Aw=S.memo(function({x:t,y:n,agent:r}){const s=ie(o=>o.theme)==="dark";return c.jsxs("g",{transform:`translate(${t}, ${n})`,children:[c.jsx(Cz,{x:0,y:30,isDark:s}),c.jsx(hg,{x:0,y:-12,isDark:s}),r&&c.jsx(il,{agent:{...r,position:{x:0,y:-12}}})]})},(e,t)=>{var n,r,s,o;return e.x!==t.x||e.y!==t.y?!1:e.agent===null&&t.agent===null?!0:e.agent===null||t.agent===null?!1:e.agent.id===t.agent.id&&e.agent.status===t.agent.status&&e.agent.name===t.agent.name&&((n=e.agent.currentTool)==null?void 0:n.name)===((r=t.agent.currentTool)==null?void 0:r.name)&&e.agent.isSubAgent===t.agent.isSubAgent&&((s=e.agent.speechBubble)==null?void 0:s.text)===((o=t.agent.speechBubble)==null?void 0:o.text)});function Az({zone:e,zoneKey:t}){const{t:n}=se("common"),o=ie(u=>u.theme)==="dark"?"#64748b":"#94a3b8";return c.jsx("text",{x:e.x+14,y:e.y+22,fill:o,fontSize:11,fontWeight:600,fontFamily:"system-ui, sans-serif",letterSpacing:"0.05em",children:n(`zones.${t}`)})}function Ez(){const e=ie(E=>E.agents),t=ie(E=>E.links),n=ie(E=>E.theme),r=Array.from(e.values()),s=n==="dark",o=s?zg:Lg,u=S.useMemo(()=>r.filter(E=>E.zone==="desk"&&!E.isSubAgent&&!E.movement&&E.confirmed),[r]),f=S.useMemo(()=>r.filter(E=>E.zone==="hotDesk"&&!E.movement),[r]),h=S.useMemo(()=>r.filter(E=>E.zone==="lounge"&&!E.movement&&!E.isPlaceholder),[r]),g=S.useMemo(()=>r.filter(E=>E.zone==="meeting"&&!E.movement&&!E.isPlaceholder),[r]),y=S.useMemo(()=>r.filter(E=>E.movement!==null&&!E.isPlaceholder),[r]),p=S.useMemo(()=>r.filter(E=>E.zone==="corridor"&&!E.movement&&!E.isPlaceholder),[r]),b=ie(E=>E.maxSubAgents),v=S.useMemo(()=>hb(Me.desk,u.length,Math.max(u.length,4)),[u.length]),k=S.useMemo(()=>hb(Me.hotDesk,f.length,Math.max(f.length,b)),[f.length,b]),j={x:Me.meeting.x+Me.meeting.width/2,y:Me.meeting.y+Me.meeting.height/2},N=Math.min(60+g.length*8,Math.min(Me.meeting.width,Me.meeting.height)/2-40),C=S.useMemo(()=>IE(g.length,j,N+36),[g.length,j.x,j.y,N]);return c.jsx("div",{className:"relative h-full w-full bg-gray-100 dark:bg-gray-950",children:c.jsxs("svg",{viewBox:`0 0 ${Og} ${_g}`,className:"h-full w-full",preserveAspectRatio:"xMidYMid meet",children:[c.jsxs("defs",{children:[c.jsx("filter",{id:"building-shadow",x:"-3%",y:"-3%",width:"106%",height:"106%",children:c.jsx("feDropShadow",{dx:"0",dy:"3",stdDeviation:"6",floodOpacity:s?.5:.12})}),c.jsxs("pattern",{id:"corridor-tiles",width:"28",height:"28",patternUnits:"userSpaceOnUse",children:[c.jsx("rect",{width:"28",height:"28",fill:o.corridor}),c.jsx("rect",{x:"0.5",y:"0.5",width:"27",height:"27",fill:"none",stroke:s?"#1f2937":"#d5dbe3",strokeWidth:"0.3",rx:"1"})]}),c.jsxs("pattern",{id:"lounge-carpet",width:"6",height:"6",patternUnits:"userSpaceOnUse",children:[c.jsx("rect",{width:"6",height:"6",fill:o.lounge}),c.jsx("circle",{cx:"3",cy:"3",r:"0.5",fill:s?"#2d2540":"#e5e0ed",opacity:"0.4"})]})]}),c.jsx("rect",{x:ue.x,y:ue.y,width:ue.width,height:ue.height,rx:ue.cornerRadius,fill:o.corridor,stroke:o.wall,strokeWidth:ue.wallThickness,filter:"url(#building-shadow)"}),c.jsx(Tz,{isDark:s}),Object.entries(Me).map(([E,R])=>c.jsx("rect",{x:R.x,y:R.y,width:R.width,height:R.height,fill:E==="lounge"?"url(#lounge-carpet)":o[E]},`floor-${E}`)),c.jsx(Dz,{isDark:s}),c.jsx(Rz,{isDark:s}),Object.entries(Me).map(([E,R])=>c.jsx(Az,{zone:R,zoneKey:E},`label-${E}`)),c.jsx(Mz,{deskSlots:v,deskAgents:u}),c.jsx(Nz,{x:j.x,y:j.y,radius:N,isDark:s}),c.jsx(_z,{seats:C,meetingAgentCount:g.length,isDark:s}),c.jsx(Oz,{slots:k,agents:f}),c.jsx(Lz,{isDark:s}),h.map(E=>c.jsx(il,{agent:E},`lounge-${E.id}`)),c.jsx(zz,{isDark:s}),t.map(E=>{const R=e.get(E.sourceId),H=e.get(E.targetId);return!R||!H?null:c.jsx(jz,{x1:R.position.x,y1:R.position.y,x2:H.position.x,y2:H.position.y,strength:E.strength},`${E.sourceId}-${E.targetId}`)}),g.map((E,R)=>{const H=C[R];return H?c.jsx(il,{agent:{...E,position:H}},E.id):null}),p.map(E=>c.jsx(il,{agent:E},`corridor-${E.id}`)),y.map(E=>c.jsx(il,{agent:E},`walk-${E.id}`))]})})}function Tz({isDark:e}){const t=ue.corridorWidth,n=ue.x,r=ue.y+(ue.height-t)/2,s=ue.x+(ue.width-t)/2,o=ue.y;return c.jsxs("g",{children:[c.jsx("rect",{x:n,y:r,width:ue.width,height:t,fill:"url(#corridor-tiles)"}),c.jsx("rect",{x:s,y:o,width:t,height:ue.height,fill:"url(#corridor-tiles)"}),c.jsx("line",{x1:n,y1:r+t/2,x2:n+ue.width,y2:r+t/2,stroke:e?"#334155":"#c8d0dc",strokeWidth:.5,strokeDasharray:"8 6",opacity:.6}),c.jsx("line",{x1:s+t/2,y1:o,x2:s+t/2,y2:o+ue.height,stroke:e?"#334155":"#c8d0dc",strokeWidth:.5,strokeDasharray:"8 6",opacity:.6})]})}function Dz({isDark:e}){const t=e?"#475569":"#8b9bb0",n=e?"#334155":"#c8d0dc",r=4,s=ue.corridorWidth,o=ue.x+(ue.width-s)/2,u=ue.y+(ue.height-s)/2,f=[{x:o-r/2,y:ue.y,w:r,h:u-ue.y},{x:o-r/2,y:u+s,w:r,h:ue.y+ue.height-u-s},{x:o+s-r/2,y:ue.y,w:r,h:u-ue.y},{x:o+s-r/2,y:u+s,w:r,h:ue.y+ue.height-u-s},{x:ue.x,y:u-r/2,w:o-ue.x,h:r},{x:o+s,y:u-r/2,w:ue.x+ue.width-o-s,h:r},{x:ue.x,y:u+s-r/2,w:o-ue.x,h:r},{x:o+s,y:u+s-r/2,w:ue.x+ue.width-o-s,h:r}];return c.jsx("g",{children:f.map((h,g)=>c.jsx("rect",{x:h.x,y:h.y,width:h.w,height:h.h,fill:n,stroke:t,strokeWidth:.5},`wall-${g}`))})}function Rz({isDark:e}){const t=ue.corridorWidth,n=ue.x+(ue.width-t)/2,r=ue.y+(ue.height-t)/2,s=40,o=e?zg.corridor:Lg.corridor,u=e?"#64748b":"#94a3b8",f=[{cx:(ue.x+n)/2,cy:r,horizontal:!0},{cx:(n+t+ue.x+ue.width)/2,cy:r,horizontal:!0},{cx:(ue.x+n)/2,cy:r+t,horizontal:!0},{cx:(n+t+ue.x+ue.width)/2,cy:r+t,horizontal:!0},{cx:n,cy:(ue.y+r)/2,horizontal:!1},{cx:n+t,cy:(ue.y+r)/2,horizontal:!1},{cx:n,cy:(r+t+ue.y+ue.height)/2,horizontal:!1},{cx:n+t,cy:(r+t+ue.y+ue.height)/2,horizontal:!1}];return c.jsx("g",{children:f.map((h,g)=>{const y=s/2;return h.horizontal?c.jsxs("g",{children:[c.jsx("rect",{x:h.cx-y,y:h.cy-3,width:s,height:6,fill:o}),c.jsx("path",{d:`M ${h.cx-y} ${h.cy} A ${y} ${y} 0 0 1 ${h.cx+y} ${h.cy}`,fill:"none",stroke:u,strokeWidth:.8,strokeDasharray:"3 2",opacity:.5})]},`door-${g}`):c.jsxs("g",{children:[c.jsx("rect",{x:h.cx-3,y:h.cy-y,width:6,height:s,fill:o}),c.jsx("path",{d:`M ${h.cx} ${h.cy-y} A ${y} ${y} 0 0 1 ${h.cx} ${h.cy+y}`,fill:"none",stroke:u,strokeWidth:.8,strokeDasharray:"3 2",opacity:.5})]},`door-${g}`)})})}function Mz({deskSlots:e,deskAgents:t}){const n=S.useMemo(()=>{const r=new Map;for(const s of t){let o=0;for(let h=0;h<s.id.length;h++)o=(o<<5)-o+s.id.charCodeAt(h)|0;let f=Math.abs(o)%e.length;for(;r.has(f);)f=(f+1)%e.length;r.set(f,s)}return r},[t,e.length]);return c.jsx("g",{children:e.map((r,s)=>c.jsx(Aw,{x:r.unitX,y:r.unitY,agent:n.get(s)??null},`desk-${s}`))})}function Oz({slots:e,agents:t}){return c.jsx("g",{children:e.map((n,r)=>c.jsx(Aw,{x:n.unitX,y:n.unitY,agent:t[r]??null},`hotdesk-${r}`))})}function _z({seats:e,meetingAgentCount:t,isDark:n}){const r={x:Me.meeting.x+Me.meeting.width/2,y:Me.meeting.y+Me.meeting.height/2};if(t>0)return c.jsx("g",{children:e.map((u,f)=>c.jsx(hg,{x:u.x,y:u.y,isDark:n},`mc-${f}`))});const s=6,o=100;return c.jsx("g",{children:Array.from({length:s},(u,f)=>{const h=2*Math.PI*f/s-Math.PI/2;return c.jsx(hg,{x:Math.round(r.x+Math.cos(h)*o),y:Math.round(r.y+Math.sin(h)*o),isDark:n},`mc-empty-${f}`)})})}function Lz({isDark:e}){const t=Me.lounge,n=t.x+t.width/2,r=e?"#334155":"#5a6878",s=e?"#475569":"#8494a7",o=e?"#64748b":"#a5b4c8",u=e?"#94a3b8":"#ffffff",f=e?"#1e293b":"#3b4f6b",h=200,g=36,y=t.y+t.height*.52,p=160,b=24,v=y+g+14;return c.jsxs("g",{children:[c.jsx(xc,{x:t.x+100,y:t.y+60,rotation:0,isDark:e}),c.jsx(xc,{x:t.x+280,y:t.y+60,rotation:0,isDark:e}),c.jsx(xc,{x:t.x+100,y:t.y+140,rotation:180,isDark:e}),c.jsx(_v,{x:t.x+190,y:t.y+100}),c.jsx(_v,{x:t.x+100,y:t.y+100}),c.jsx(xc,{x:t.x+440,y:t.y+100,rotation:90,isDark:e}),c.jsx("rect",{x:n-h/2,y,width:h,height:g,rx:4,fill:f}),c.jsx("rect",{x:n-h/2,y,width:h,height:3,rx:1.5,fill:e?"#64748b":"#7a9bc0"}),c.jsx("text",{x:n,y:y+g/2+5,textAnchor:"middle",fill:u,fontSize:14,fontWeight:700,fontFamily:"system-ui, sans-serif",letterSpacing:"0.12em",children:"OpenClaw"}),c.jsx("rect",{x:n-p/2,y:v,width:p,height:b,rx:12,fill:s,stroke:r,strokeWidth:1}),c.jsx("rect",{x:n-p/2+4,y:v+3,width:p-8,height:b-6,rx:9,fill:o,opacity:.5}),c.jsx(bc,{x:n-h/2-30,y:y+g/2}),c.jsx(bc,{x:n+h/2+30,y:y+g/2}),c.jsx(bc,{x:t.x+40,y:t.y+t.height-50}),c.jsx(bc,{x:t.x+t.width-40,y:t.y+t.height-50})]})}function zz({isDark:e}){const t=Me.lounge,n=t.x+t.width/2,r=ue.y+ue.height,s=70,o=s/2,u=e?zg.lounge:Lg.lounge,f=e?"#64748b":"#8b9bb0",h=e?"#374151":"#b0a090",g=e?"#64748b":"#94a3b8";return c.jsxs("g",{children:[c.jsx("rect",{x:n-o-2,y:r-ue.wallThickness-1,width:s+4,height:ue.wallThickness+4,fill:u}),c.jsx("rect",{x:n-o-3,y:r-10,width:3,height:12,rx:1,fill:f}),c.jsx("rect",{x:n+o,y:r-10,width:3,height:12,rx:1,fill:f}),c.jsx("path",{d:`M ${n-o} ${r} A ${o} ${o} 0 0 0 ${n} ${r-o}`,fill:"none",stroke:f,strokeWidth:.8,strokeDasharray:"4 3",opacity:.5}),c.jsx("path",{d:`M ${n+o} ${r} A ${o} ${o} 0 0 1 ${n} ${r-o}`,fill:"none",stroke:f,strokeWidth:.8,strokeDasharray:"4 3",opacity:.5}),c.jsx("rect",{x:n-30,y:r-18,width:60,height:12,rx:3,fill:h,opacity:.5}),c.jsx("text",{x:n,y:r+14,textAnchor:"middle",fill:g,fontSize:9,fontWeight:600,fontFamily:"system-ui, sans-serif",letterSpacing:"0.15em",children:"ENTRANCE"})]})}function Yc(e,t){const n=e.agents;if(!n)return;const r=n.list;if(Array.isArray(r))return r.find(s=>s.id===t)}function Ew(e){return JSON.parse(JSON.stringify(e))}async function Iz(e,t,n,r){try{const s=await e.configGet(),o=s.config;if(!Yc(o,t))return{ok:!1,error:"agent_not_found"};const f=Ew(o),g=f.agents.list,y=g.findIndex(b=>b.id===t);if(y<0)return{ok:!1,error:"agent_not_found"};g[y]={...g[y],tools:n};const p=await e.configSet(JSON.stringify(f),r??s.hash);return p.ok?{ok:!0,restart:p.restart??void 0}:{ok:!1,error:p.error??"conflict"}}catch(s){return{ok:!1,error:String(s)}}}async function Hz(e,t,n,r){try{const s=await e.configGet(),o=s.config;if(!Yc(o,t))return{ok:!1,error:"agent_not_found"};const f=Ew(o),g=f.agents.list,y=g.findIndex(b=>b.id===t);if(y<0)return{ok:!1,error:"agent_not_found"};if(n===null){const{skills:b,...v}=g[y];g[y]=v}else g[y]={...g[y],skills:n};const p=await e.configSet(JSON.stringify(f),r??s.hash);return p.ok?{ok:!0,restart:p.restart??void 0}:{ok:!1,error:p.error??"conflict"}}catch(s){return{ok:!1,error:String(s)}}}const Bz=["feishu","dingtalk","telegram","discord","slack","whatsapp","signal","imessage","matrix","line","msteams","googlechat","mattermost","irc","nostr","nextcloud-talk","bluebubbles","synology-chat","zalo","zalouser","tlon"];function Uz(e,t){const n=e.trim(),r=`agent:${t}:`;if(!n.startsWith(r))return!1;const s=n.slice(r.length);return Bz.some(o=>s.startsWith(`${o}:`))}async function $z(e,t){const r=(await e.sessionsList()).map(s=>s.key).filter(s=>Uz(s,t));for(const s of r)await e.sessionsDelete(s);return r.length}const Lv={agentTools:[],agentToolsLoading:!1,agentToolsConfig:null,configHash:null,agentSkills:[],agentSkillsLoading:!1,agentSkillsAllowlist:null,agentChannels:[],agentChannelsLoading:!1,agentCronJobs:[],agentCronJobsLoading:!1,cronDialogOpen:!1,cronEditingTask:null},On=Mn((e,t)=>({agents:[],defaultAgentId:"",selectedAgentId:null,activeTab:"overview",isLoading:!1,error:null,searchQuery:"",files:[],filesLoading:!1,selectedFileName:null,fileContent:null,originalFileContent:null,isFileDirty:!1,fileSaving:!1,createDialogOpen:!1,deleteDialogOpen:!1,systemModels:[],agentModelConfigs:{},...Lv,fetchSystemModels:async()=>{var n;try{await Pe();const r=Oe(),[s,o]=await Promise.all([r.configGet(),r.modelsList().catch(()=>[])]),u=s.config,f=new Set,h=[],g=new Map;for(const k of o){const j=`${k.provider}/${k.id}`;f.has(j)||(f.add(j),h.push({id:j,label:k.name??k.id,provider:k.provider}),g.has(k.provider)||g.set(k.provider,[]),g.get(k.provider).push(k))}const y=u==null?void 0:u.models,p=y==null?void 0:y.providers;if(p)for(const[k,j]of Object.entries(p)){const N=j.models;if(N)for(const C of N){const E=`${k}/${C.id}`;f.has(E)||(f.add(E),h.push({id:E,label:C.name??C.id,provider:k}))}}const b={},v=(n=u==null?void 0:u.agents)==null?void 0:n.list;if(v)for(const k of v){const j=k.id;if(!j)continue;const N=k.model;if(typeof N=="string")b[j]={primary:N,fallbacks:[]};else if(N&&typeof N=="object"&&!Array.isArray(N)){const C=N;b[j]={primary:C.primary??"",fallbacks:C.fallbacks??[]}}}e({systemModels:h,agentModelConfigs:b})}catch{}},fetchAgents:async()=>{e({isLoading:!0,error:null});try{await Pe();const n=await Oe().agentsList(),r=n.agents.map(u=>({...u,default:u.id===n.defaultId})),{selectedAgentId:s}=t(),o=s??n.defaultId;e({agents:r,defaultAgentId:n.defaultId,selectedAgentId:o,isLoading:!1})}catch(n){e({error:String(n),isLoading:!1})}},selectAgent:n=>{e({selectedAgentId:n,activeTab:"overview",files:[],selectedFileName:null,fileContent:null,originalFileContent:null,isFileDirty:!1,...Lv})},setActiveTab:n=>e({activeTab:n}),setSearchQuery:n=>e({searchQuery:n}),fetchFiles:async n=>{e({filesLoading:!0,files:[]});try{await Pe();const r=await Oe().agentsFilesList(n);e({files:r.files,filesLoading:!1})}catch{e({filesLoading:!1})}},fetchFileContent:async(n,r)=>{e({selectedFileName:r,fileContent:null,originalFileContent:null,isFileDirty:!1});try{await Pe();const s=await Oe().agentsFilesGet(n,r);e({fileContent:s.file.content,originalFileContent:s.file.content,isFileDirty:!1})}catch{e({fileContent:"",originalFileContent:""})}},setFileContent:n=>{const{originalFileContent:r}=t();e({fileContent:n,isFileDirty:n!==r})},resetFileContent:()=>{const{originalFileContent:n}=t();e({fileContent:n,isFileDirty:!1})},saveFileContent:async(n,r,s)=>{e({fileSaving:!0});try{return await Pe(),await Oe().agentsFilesSet(n,r,s),e({fileSaving:!1,originalFileContent:s,isFileDirty:!1}),!0}catch{return e({fileSaving:!1}),!1}},createAgent:async n=>{try{await Pe();const r=await Oe().agentsCreate(n);return r.ok?(await t().fetchAgents(),r.agentId):null}catch{return null}},updateAgentModel:async(n,r)=>{try{await Pe();const s=Oe(),o=await s.agentsUpdate({agentId:n,model:r});if(o.ok){let u="configLifecycle.runtimeAgentModel";try{await $z(s,n)>0&&(u="configLifecycle.runtimeAgentModelSessionsReset")}catch{}Ee.getState().setRuntimeApplied(u)}return o.ok}catch{return!1}},deleteAgent:async(n,r)=>{try{return await Pe(),(await Oe().agentsDelete({agentId:n,deleteFiles:r})).ok?(e({selectedAgentId:null}),await t().fetchAgents(),!0):!1}catch{return!1}},setCreateDialogOpen:n=>e({createDialogOpen:n}),setDeleteDialogOpen:n=>e({deleteDialogOpen:n}),fetchAgentTools:async n=>{e({agentToolsLoading:!0});try{await Pe();const r=Oe(),[s,o]=await Promise.all([r.toolsCatalog(n),r.configGet()]),u=Yc(o.config,n),f=u==null?void 0:u.tools;e({agentTools:s.tools,agentToolsConfig:f??null,configHash:o.hash??null,agentToolsLoading:!1})}catch{e({agentToolsLoading:!1})}},saveAgentToolsConfig:async(n,r)=>{try{await Pe();const s=Oe(),{configHash:o}=t(),u=await Iz(s,n,r,o??void 0);if(u.ok){const f=await s.configGet();e({agentToolsConfig:r,configHash:f.hash??null}),Ee.getState().setLifecycleFromWriteResult({...u,config:f.config},"save")}return u}catch{return{ok:!1,error:"unknown"}}},fetchAgentSkills:async n=>{e({agentSkillsLoading:!0});try{await Pe();const r=Oe(),[s,o]=await Promise.all([r.skillsStatus(n),r.configGet()]),u=Yc(o.config,n),f=(u==null?void 0:u.skills)??null;e({agentSkills:s,agentSkillsAllowlist:f,configHash:o.hash??null,agentSkillsLoading:!1})}catch{e({agentSkillsLoading:!1})}},saveAgentSkillsAllowlist:async(n,r)=>{try{await Pe();const s=Oe(),{configHash:o}=t(),u=await Hz(s,n,r,o??void 0);if(u.ok){const f=await s.configGet();e({agentSkillsAllowlist:r,configHash:f.hash??null}),Ee.getState().setLifecycleFromWriteResult({...u,config:f.config},"save")}return u}catch{return{ok:!1,error:"unknown"}}},fetchAgentChannels:async()=>{e({agentChannelsLoading:!0});try{await Pe();const n=await Oe().channelsStatus();e({agentChannels:n,agentChannelsLoading:!1})}catch{e({agentChannelsLoading:!1})}},fetchAgentCronJobs:async n=>{e({agentCronJobsLoading:!0});try{await Pe();const r=await Oe().cronList();e({agentCronJobs:r.filter(s=>s.agentId===n),agentCronJobsLoading:!1})}catch{e({agentCronJobsLoading:!1})}},addAgentCronJob:async(n,r)=>{await Pe();const s=await Oe().cronAdd({...r,agentId:n});e(o=>({agentCronJobs:[...o.agentCronJobs,s]})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")},updateAgentCronJob:async(n,r)=>{await Pe();const s=await Oe().cronUpdate(n,r);e(o=>({agentCronJobs:o.agentCronJobs.map(u=>u.id===n?s:u)})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")},removeAgentCronJob:async n=>{await Pe(),await Oe().cronRemove(n),e(r=>({agentCronJobs:r.agentCronJobs.filter(s=>s.id!==n)})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")},runAgentCronJob:async n=>{await Pe(),await Oe().cronRun(n),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")},toggleAgentCronJob:async(n,r)=>{await Pe();const s=await Oe().cronUpdate(n,{enabled:r});e(o=>({agentCronJobs:o.agentCronJobs.map(u=>u.id===n?s:u)})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeCron")},openAgentCronDialog:n=>{e({cronDialogOpen:!0,cronEditingTask:n??null})},closeAgentCronDialog:()=>{e({cronDialogOpen:!1,cronEditingTask:null})}}));function qz({agent:e}){var f,h,g;const{t}=se("console"),n=On(y=>y.defaultAgentId),r=((f=e.identity)==null?void 0:f.name)??e.name??e.id,s=(h=e.identity)==null?void 0:h.emoji,o=(g=e.identity)==null?void 0:g.avatarUrl,u=e.id===n;return c.jsxs("div",{className:"flex items-start gap-4 rounded-2xl border border-gray-200 bg-white p-5 dark:border-gray-700 dark:bg-gray-900",children:[c.jsx("div",{className:"flex h-14 w-14 shrink-0 items-center justify-center rounded-xl bg-gray-100 text-2xl dark:bg-gray-800",children:o?c.jsx("img",{src:o,alt:r,className:"h-14 w-14 rounded-xl object-cover"}):c.jsx("span",{children:s??r.charAt(0).toLowerCase()})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-gray-100",children:r})}),c.jsx("p",{className:"mt-0.5 text-sm text-gray-500 dark:text-gray-400",children:t("agents.detailDescription",{id:e.id})})]}),c.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-1",children:[c.jsx("span",{className:"text-sm font-mono text-gray-500 dark:text-gray-400",children:e.id}),u&&c.jsx("span",{className:"rounded-md bg-gray-200 px-2 py-0.5 text-xs font-semibold uppercase text-gray-600 dark:bg-gray-700 dark:text-gray-300",children:t("agents.defaultBadge")})]})]})}const Kz={connected:"bg-green-500",disconnected:"bg-gray-400",connecting:"bg-yellow-500",error:"bg-red-500"},Pz={telegram:"TG",discord:"DC",whatsapp:"WA",signal:"SG",feishu:"FS",imessage:"iM",matrix:"MX",line:"LN",msteams:"MS",googlechat:"GC",mattermost:"MM"};function Fz({agent:e}){const{t}=se("console"),{agentChannels:n,agentChannelsLoading:r,fetchAgentChannels:s}=On();S.useEffect(()=>{s()},[e.id,s]);const o=n??[];return r?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-5 w-5 animate-spin text-gray-400"})}):c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.channels.title")}),c.jsx("button",{onClick:()=>s(),className:"rounded p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300",title:t("agents.refresh"),children:c.jsx(Rn,{className:"h-4 w-4"})})]}),c.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-blue-200 bg-blue-50 px-4 py-3 dark:border-blue-800 dark:bg-blue-900/20",children:[c.jsx(ru,{className:"mt-0.5 h-4 w-4 shrink-0 text-blue-600 dark:text-blue-400"}),c.jsx("p",{className:"text-xs text-blue-700 dark:text-blue-300",children:t("agents.channels.gatewayInfo")})]}),o.length===0?c.jsxs("div",{className:"py-8 text-center",children:[c.jsx(Tl,{className:"mx-auto mb-2 h-8 w-8 text-gray-300 dark:text-gray-600"}),c.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500",children:t("agents.channels.noBindings")})]}):c.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:o.map(u=>c.jsx(Gz,{channel:u},u.id))})]})}function Gz({channel:e}){const{t}=se("console"),n=Pz[e.type]??e.type.slice(0,2).toUpperCase(),r=Kz[e.status]??"bg-gray-400",s=t(`agents.channels.${e.status}`);return c.jsx("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-gray-100 text-sm font-bold text-gray-600 dark:bg-gray-700 dark:text-gray-300",children:n}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{className:"truncate text-sm font-medium text-gray-900 dark:text-gray-100",children:e.name||e.type})}),c.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[c.jsx("span",{className:`inline-block h-2 w-2 rounded-full ${r}`}),c.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:s}),e.configured&&c.jsx("span",{className:"rounded bg-green-100 px-1.5 py-0.5 text-[10px] font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:t("agents.channels.configured")})]}),e.error&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:e.error})]})]})})}function Vz(e){const t=Yz(e.schedule),n=e.payload.kind==="agentTurn"?e.payload.message:e.payload.kind==="systemEvent"?e.payload.text:"";return{id:e.id,name:e.name,schedule:t,scheduleLabel:Qz(t),enabled:e.enabled,lastRunAt:e.state.lastRunAtMs??null,nextRunAt:e.state.nextRunAtMs??null,lastRunStatus:e.state.lastRunStatus??null,message:n,statusLabel:e.enabled?we.t("console:viewModels.taskStatus.active"):we.t("console:viewModels.taskStatus.paused")}}function Yz(e){return e.kind==="cron"&&e.expr?e.expr:e.kind==="every"&&e.everyMs?we.t("console:viewModels.schedule.every",{minutes:Math.round(e.everyMs/6e4)}):e.kind==="at"&&e.at?we.t("console:viewModels.schedule.at",{time:e.at}):we.t("console:viewModels.schedule.unknown")}function Qz(e){const t=e.split(" ");if(t.length!==5)return e;const[n,r,s,o,u]=t;return s==="*"&&u==="*"&&r!=="*"&&n!=="*"?we.t("console:viewModels.schedule.daily",{time:`${r}:${n.padStart(2,"0")}`}):u!=="*"&&s==="*"?we.t("console:viewModels.schedule.weekly",{day:u,time:`${r}:${n.padStart(2,"0")}`}):e}const Wz={ok:c.jsx(Tr,{className:"h-3.5 w-3.5 text-green-500"}),error:c.jsx(tu,{className:"h-3.5 w-3.5 text-red-500"}),skipped:c.jsx(S4,{className:"h-3.5 w-3.5 text-gray-400"})};function Tw({task:e,onToggle:t,onRun:n,onEdit:r,onDelete:s}){const{t:o}=se("console"),u=Vz(e),f=e.payload.kind==="agentTurn"?e.payload.message:e.payload.kind==="systemEvent"?e.payload.text:"",h=u.lastRunAt?new Date(u.lastRunAt).toLocaleString():"—",g=u.nextRunAt?new Date(u.nextRunAt).toLocaleString():"—";return c.jsx("div",{className:`rounded-lg border border-gray-200 bg-white p-4 transition-opacity dark:border-gray-700 dark:bg-gray-800 ${e.enabled?"":"opacity-60"}`,children:c.jsxs("div",{className:"flex items-start justify-between gap-4",children:[c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsxs("label",{className:"relative mt-0.5 inline-flex cursor-pointer items-center",children:[c.jsx("input",{type:"checkbox",checked:e.enabled,onChange:()=>t(e.id,!e.enabled),className:"peer sr-only"}),c.jsx("div",{className:"peer h-5 w-9 rounded-full bg-gray-200 after:absolute after:left-[2px] after:top-[2px] after:h-4 after:w-4 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:bg-blue-600 peer-checked:after:translate-x-full peer-checked:after:border-white dark:bg-gray-700 dark:peer-checked:bg-blue-500"})]}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"font-medium text-gray-900 dark:text-gray-100",children:e.name}),c.jsx("span",{className:"rounded bg-gray-100 px-1.5 py-0.5 text-[10px] text-gray-500 dark:bg-gray-700 dark:text-gray-400",children:u.scheduleLabel})]}),f&&c.jsx("p",{className:"mt-1 line-clamp-1 text-sm text-gray-500 dark:text-gray-400",children:f}),c.jsxs("div",{className:"mt-2 flex items-center gap-4 text-xs text-gray-400 dark:text-gray-500",children:[c.jsxs("span",{className:"flex items-center gap-1",children:[o("cron.card.lastRun"),": ",h,e.state.lastRunStatus&&c.jsx("span",{className:"ml-1",children:Wz[e.state.lastRunStatus]??null})]}),c.jsxs("span",{children:[o("cron.card.nextRun"),": ",g]})]}),e.state.lastError&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:e.state.lastError})]})]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("button",{type:"button",onClick:()=>n(e.id),className:"rounded p-1.5 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300 transition-colors",title:o("cron.card.runNow"),children:c.jsx(M4,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>r(e),className:"rounded p-1.5 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300 transition-colors",title:o("common:actions.edit"),children:c.jsx(M1,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>s(e.id),className:"rounded p-1.5 text-gray-400 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20 dark:hover:text-red-400 transition-colors",title:o("common:actions.delete"),children:c.jsx(Dl,{className:"h-4 w-4"})})]})]})})}const zv=[{labelKey:"console:cron.presets.everyHour",schedule:{kind:"cron",expr:"0 * * * *"}},{labelKey:"console:cron.presets.daily9am",schedule:{kind:"cron",expr:"0 9 * * *"}},{labelKey:"console:cron.presets.daily6pm",schedule:{kind:"cron",expr:"0 18 * * *"}},{labelKey:"console:cron.presets.weeklyMon",schedule:{kind:"cron",expr:"0 9 * * 1"}},{labelKey:"console:cron.presets.monthlyFirst",schedule:{kind:"cron",expr:"0 9 1 * *"}},{labelKey:"console:cron.presets.every30min",schedule:{kind:"every",everyMs:18e5}}];function Iv(e){return e.kind==="cron"?e.expr:e.kind==="every"?`every ${Math.round(e.everyMs/6e4)}m`:e.kind==="at"?`at ${e.at}`:""}function Xz(e){const t=e.payloadKind??"agentTurn",n=t==="systemEvent"?{kind:"systemEvent",text:e.message.trim()}:{kind:"agentTurn",message:e.message.trim()};return{name:e.name.trim(),description:e.description.trim()||void 0,schedule:e.schedule,sessionTarget:t==="systemEvent"?"main":"isolated",wakeMode:"now",payload:n}}function Dw({open:e,editingTask:t,onSave:n,onUpdate:r,onClose:s}){const{t:o}=se("console"),u=S.useRef(null),[f,h]=S.useState(""),[g,y]=S.useState(""),[p,b]=S.useState({kind:"cron",expr:"0 18 * * *"}),[v,k]=S.useState("0 18 * * *"),[j,N]=S.useState(""),[C,E]=S.useState(null),[R,H]=S.useState({});S.useEffect(()=>{const W=u.current;W&&(e&&!W.open?(t?(h(t.name),y(t.description??""),b(t.schedule),k(Iv(t.schedule)),N(t.payload.kind==="agentTurn"?t.payload.message:t.payload.kind==="systemEvent"?t.payload.text:""),E(null)):(h(""),y(""),b({kind:"cron",expr:"0 18 * * *"}),k("0 18 * * *"),N(""),E(null)),H({}),W.showModal()):!e&&W.open&&W.close())},[e,t]);const z=W=>{const P=zv[W];E(W),b(P.schedule),k(Iv(P.schedule))},L=W=>{k(W),E(null),b({kind:"cron",expr:W})},G=()=>{const W={};if(f.trim()||(W.name=!0),j.trim()||(W.message=!0),v.trim()||(W.cronExpr=!0),H(W),Object.keys(W).length>0)return;const P=Xz({name:f,description:g,schedule:p,message:j,payloadKind:(t==null?void 0:t.payload.kind)==="systemEvent"?"systemEvent":"agentTurn"});t?r(t.id,P):n(P)};return c.jsx("dialog",{ref:u,onClose:s,className:"fixed inset-0 z-50 m-auto max-w-lg rounded-lg border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"max-h-[80vh] overflow-y-auto p-6",children:[c.jsx("h3",{className:"mb-4 text-lg font-semibold text-gray-900 dark:text-gray-100",children:o(t?"cron.dialog.editTitle":"cron.dialog.createTitle")}),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:[o("cron.dialog.name")," ",c.jsx("span",{className:"text-red-500",children:"*"})]}),c.jsx("input",{type:"text",value:f,onChange:W=>h(W.target.value),placeholder:o("cron.dialog.namePlaceholder"),className:`w-full rounded-md border bg-white px-3 py-2 text-sm dark:bg-gray-700 dark:text-gray-100 ${R.name?"border-red-500":"border-gray-300 dark:border-gray-600"}`}),R.name&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:o("cron.dialog.required")})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:o("cron.dialog.description")}),c.jsx("input",{type:"text",value:g,onChange:W=>y(W.target.value),placeholder:o("cron.dialog.descriptionPlaceholder"),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300",children:o("cron.dialog.schedule")}),c.jsx("div",{className:"mb-3 flex flex-wrap gap-2",children:zv.map((W,P)=>c.jsx("button",{type:"button",onClick:()=>z(P),className:`rounded-md border px-3 py-1.5 text-xs font-medium transition-colors ${C===P?"border-blue-500 bg-blue-50 text-blue-700 dark:border-blue-400 dark:bg-blue-900/20 dark:text-blue-400":"border-gray-300 text-gray-600 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700"}`,children:o(W.labelKey)},P))}),c.jsx("input",{type:"text",value:v,onChange:W=>L(W.target.value),placeholder:"0 * * * *",className:`w-full rounded-md border bg-white px-3 py-2 text-sm font-mono dark:bg-gray-700 dark:text-gray-100 ${R.cronExpr?"border-red-500":"border-gray-300 dark:border-gray-600"}`}),c.jsx("p",{className:"mt-1 text-xs text-gray-400",children:o("cron.dialog.cronHelp")})]}),c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:[o("cron.dialog.message")," ",c.jsx("span",{className:"text-red-500",children:"*"})]}),c.jsx("textarea",{value:j,onChange:W=>N(W.target.value),placeholder:o("cron.dialog.messagePlaceholder"),rows:3,className:`w-full rounded-md border bg-white px-3 py-2 text-sm dark:bg-gray-700 dark:text-gray-100 ${R.message?"border-red-500":"border-gray-300 dark:border-gray-600"}`}),R.message&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:o("cron.dialog.required")})]})]}),c.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:s,className:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:o("common:actions.cancel")}),c.jsx("button",{type:"button",onClick:G,className:"rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:o(t?"common:actions.save":"common:actions.create")})]})]})})}function Zz({agent:e}){const{t}=se("console"),{agentCronJobs:n,agentCronJobsLoading:r,cronDialogOpen:s,cronEditingTask:o,fetchAgentCronJobs:u,addAgentCronJob:f,updateAgentCronJob:h,removeAgentCronJob:g,runAgentCronJob:y,toggleAgentCronJob:p,openAgentCronDialog:b,closeAgentCronDialog:v}=On();S.useEffect(()=>{u(e.id)},[e.id,u]);const k=n??[],j=k.length,N=k.filter(H=>H.enabled).length,C=k.filter(H=>H.state.lastRunStatus==="error").length,E=H=>{f(e.id,H)},R=(H,z)=>{h(H,z)};return r?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-5 w-5 animate-spin text-gray-400"})}):c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.cronJobs.title")}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{onClick:()=>b(),className:"flex items-center gap-1 rounded-lg bg-blue-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-blue-700",children:[c.jsx(En,{className:"h-3.5 w-3.5"}),t("agents.cronJobs.addTask")]}),c.jsx("button",{onClick:()=>u(e.id),className:"rounded p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300",title:t("agents.refresh"),children:c.jsx(Rn,{className:"h-4 w-4"})})]})]}),c.jsxs("div",{className:"flex gap-4",children:[c.jsx(Ah,{label:t("agents.cronJobs.total"),value:j}),c.jsx(Ah,{label:t("agents.cronJobs.enabled"),value:N,color:"green"}),c.jsx(Ah,{label:t("agents.cronJobs.errors"),value:C,color:"red"})]}),k.length===0?c.jsxs("div",{className:"py-8 text-center",children:[c.jsx(Ki,{className:"mx-auto mb-2 h-8 w-8 text-gray-300 dark:text-gray-600"}),c.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500",children:t("agents.cronJobs.noCronJobs")}),c.jsx("button",{onClick:()=>b(),className:"mt-2 text-xs text-blue-600 hover:text-blue-700 dark:text-blue-400",children:t("cron.empty.createFirst")})]}):c.jsx("div",{className:"space-y-2",children:k.map(H=>c.jsx(Tw,{task:H,onToggle:(z,L)=>p(z,L),onRun:z=>y(z),onEdit:z=>b(z),onDelete:z=>g(z)},H.id))}),c.jsx(Dw,{open:s,editingTask:o,onSave:E,onUpdate:R,onClose:v})]})}function Ah({label:e,value:t,color:n}){const r=n==="green"?"text-green-600 dark:text-green-400":n==="red"?"text-red-600 dark:text-red-400":"text-gray-900 dark:text-gray-100";return c.jsxs("div",{className:"rounded-lg border border-gray-200 px-3 py-2 dark:border-gray-700",children:[c.jsx("div",{className:`text-lg font-semibold ${r}`,children:t}),c.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:e})]})}function Jz(e){return e<1024?`${e} B`:`${(e/1024).toFixed(1)} KB`}function e9(e,t){const n=typeof e=="number"?e:new Date(e).getTime();if(Number.isNaN(n)||n===0)return"—";const r=Date.now()-n;if(r<0)return t("agents.files.justNow");const s=Math.floor(r/36e5);if(s<1)return t("agents.files.justNow");if(s<24)return t("agents.files.hoursAgo",{count:s});const o=Math.floor(s/24);return t("agents.files.daysAgo",{count:o})}function t9({agent:e}){const{t}=se("console"),{files:n,filesLoading:r,selectedFileName:s,fileContent:o,isFileDirty:u,fileSaving:f,fetchFiles:h,fetchFileContent:g,setFileContent:y,resetFileContent:p,saveFileContent:b}=On();S.useEffect(()=>{h(e.id)},[e.id,h]);const v=n.find(j=>j.name===s),k=async()=>{s&&o!=null&&await b(e.id,s,o)};return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.files.title")}),c.jsx("p",{className:"mt-0.5 text-xs text-gray-500 dark:text-gray-400",children:t("agents.files.description")})]}),c.jsx("button",{onClick:()=>h(e.id),disabled:r,className:"rounded-md p-1.5 text-gray-500 transition-colors hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-800",children:c.jsx(Rn,{className:`h-4 w-4 ${r?"animate-spin":""}`})})]}),c.jsxs("div",{className:"flex gap-4",children:[c.jsx("div",{className:"w-56 shrink-0 space-y-2",children:n.map(j=>c.jsxs("button",{onClick:()=>g(e.id,j.name),className:`w-full rounded-xl border px-3 py-2.5 text-left transition-colors ${s===j.name?"border-red-400 bg-red-50 dark:border-red-600 dark:bg-red-900/20":"border-gray-200 hover:border-gray-300 hover:bg-gray-50 dark:border-gray-700 dark:hover:border-gray-600 dark:hover:bg-gray-800"}`,children:[c.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:j.name}),c.jsxs("p",{className:"mt-0.5 text-xs text-gray-500 dark:text-gray-400",children:[Jz(j.size)," · ",e9(j.modifiedAt,t)]})]},j.name))}),c.jsx("div",{className:"min-w-0 flex-1",children:v&&o!=null?c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{children:c.jsx("h4",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:v.name})}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{onClick:p,disabled:!u,className:"rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-800",children:t("agents.files.reset")}),c.jsx("button",{onClick:k,disabled:!u||f,className:"rounded-md bg-red-500 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-red-600 disabled:opacity-50",children:t(f?"agents.files.saving":"agents.files.save")})]})]}),c.jsxs("div",{children:[c.jsx("p",{className:"mb-1 text-xs font-medium text-gray-500 dark:text-gray-400",children:t("agents.files.content")}),c.jsx("textarea",{value:o,onChange:j=>y(j.target.value),className:"h-80 w-full resize-y rounded-lg border border-gray-200 bg-gray-50 p-3 font-mono text-xs text-gray-900 focus:border-blue-500 focus:outline-none dark:border-gray-700 dark:bg-gray-800 dark:text-gray-200"})]})]}):c.jsx("div",{className:"flex h-64 items-center justify-center text-sm text-gray-400 dark:text-gray-500",children:t("agents.files.selectFile")})})]})]})}function n9({agent:e}){var L;const{t}=se("console"),{defaultAgentId:n,updateAgentModel:r,setDeleteDialogOpen:s,systemModels:o,fetchSystemModels:u,agentModelConfigs:f}=On(),h=e.id===n,g=f[e.id],[y,p]=S.useState((g==null?void 0:g.primary)??""),[b,v]=S.useState((g==null?void 0:g.fallbacks)??[]),[k,j]=S.useState(!1),[N,C]=S.useState("idle");S.useEffect(()=>{o.length===0&&u()},[o.length,u]),S.useEffect(()=>{const G=f[e.id];p((G==null?void 0:G.primary)??""),v((G==null?void 0:G.fallbacks)??[]),C("idle")},[e.id,f]);const E=async()=>{j(!0),C("idle");const G=b.filter(M=>M.length>0),W=G.length>0?{primary:y||void 0,fallbacks:G}:y||"",P=await r(e.id,W);j(!1),C(P?"success":"error"),P&&(await u(),setTimeout(()=>C("idle"),2e3))},R=()=>v([...b,""]),H=G=>v(b.filter((W,P)=>P!==G)),z=(G,W)=>{const P=[...b];P[G]=W,v(P)};return c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{children:[c.jsx("h3",{className:"mb-3 text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.overview.title")}),c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsx(Eh,{label:t("agents.overview.agentId"),value:e.id,mono:!0}),c.jsx(Eh,{label:t("agents.overview.name"),value:((L=e.identity)==null?void 0:L.name)??e.name??e.id}),c.jsx(Eh,{label:t("agents.overview.isDefault"),value:t(h?"agents.overview.yes":"agents.overview.no")})]})]}),c.jsxs("div",{className:"border-t border-gray-200 pt-5 dark:border-gray-700",children:[c.jsx("h3",{className:"mb-3 text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.overview.modelConfig")}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-xs font-medium text-gray-600 dark:text-gray-400",children:t("agents.overview.primaryModel")}),c.jsx(Hv,{value:y,onChange:p,models:o,placeholder:t("agents.overview.primaryModelPlaceholder")})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-xs font-medium text-gray-600 dark:text-gray-400",children:t("agents.overview.fallbackModels")}),b.map((G,W)=>c.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[c.jsx(Hv,{value:G,onChange:P=>z(W,P),models:o,placeholder:t("agents.overview.fallbackPlaceholder")}),c.jsx("button",{onClick:()=>H(W),className:"shrink-0 rounded-md p-1.5 text-gray-400 hover:bg-gray-100 hover:text-red-500 dark:hover:bg-gray-800",children:c.jsx(An,{className:"h-4 w-4"})})]},W)),c.jsxs("button",{onClick:R,className:"flex items-center gap-1 text-xs text-blue-600 hover:text-blue-700 dark:text-blue-400",children:[c.jsx(En,{className:"h-3 w-3"}),t("agents.overview.addFallback")]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{onClick:E,disabled:k,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50",children:t(k?"agents.overview.saving":"agents.overview.save")}),N==="success"&&c.jsx("span",{className:"text-xs text-green-600",children:t("agents.overview.saveSuccess")}),N==="error"&&c.jsx("span",{className:"text-xs text-red-600",children:t("agents.overview.saveError")})]}),c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:t("agents.overview.runtimeHint")})]})]}),c.jsxs("div",{className:"border-t border-gray-200 pt-5 dark:border-gray-700",children:[c.jsxs("button",{onClick:()=>s(!0),disabled:h,className:"flex items-center gap-2 rounded-lg border border-red-200 px-4 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-50 disabled:cursor-not-allowed disabled:opacity-50 dark:border-red-800 dark:text-red-400 dark:hover:bg-red-900/20",title:h?t("agents.overview.cannotDeleteDefault"):void 0,children:[c.jsx(Dl,{className:"h-4 w-4"}),t("agents.overview.deleteAgent")]}),h&&c.jsx("p",{className:"mt-1 text-xs text-gray-400",children:t("agents.overview.cannotDeleteDefault")})]})]})}function Eh({label:e,value:t,mono:n}){return c.jsxs("div",{children:[c.jsx("dt",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:e}),c.jsx("dd",{className:`mt-0.5 text-sm text-gray-900 dark:text-gray-100 ${n?"font-mono":""}`,children:t})]})}function Hv({value:e,onChange:t,models:n,placeholder:r}){const s=[...new Set(n.map(u=>u.provider))],o=n.some(u=>u.id===e);return c.jsxs("div",{className:"relative w-full",children:[c.jsxs("select",{value:o?e:"",onChange:u=>t(u.target.value),className:"w-full appearance-none rounded-lg border border-gray-300 bg-white px-3 py-2 pr-8 text-sm text-gray-900 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200",children:[c.jsx("option",{value:"",children:r}),!o&&e&&c.jsx("option",{value:e,children:e}),s.map(u=>c.jsx("optgroup",{label:u,children:n.filter(f=>f.provider===u).map(f=>c.jsxs("option",{value:f.id,children:[f.label," (",f.id,")"]},f.id))},u))]}),c.jsx(qn,{className:"pointer-events-none absolute right-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"})]})}function a9({agent:e}){const{t}=se("console"),{agentSkills:n,agentSkillsLoading:r,agentSkillsAllowlist:s,fetchAgentSkills:o,saveAgentSkillsAllowlist:u}=On(),[f,h]=S.useState("all"),[g,y]=S.useState([]),[p,b]=S.useState(!1),[v,k]=S.useState("idle");S.useEffect(()=>{o(e.id)},[e.id,o]),S.useEffect(()=>{s==null?(h("all"),y([])):(h("selected"),y(s)),k("idle")},[s]);const j=$=>{if(h($),$==="all")y([]);else{const V=(n==null?void 0:n.filter(ae=>ae.enabled).map(ae=>ae.slug))??[];y(V)}},N=($,V)=>{y(ae=>V?[...ae,$]:ae.filter(J=>J!==$))},C=n??[],E=S.useMemo(()=>C.filter($=>!vc($)),[C]),R=()=>{y(C.map($=>$.slug))},H=()=>{const $=C.filter(V=>vc(V)).map(V=>V.slug);y($)},z=S.useCallback(async()=>{b(!0),k("idle");const $=await u(e.id,f==="all"?null:g);b(!1),k($.ok?"success":"error"),$.ok&&setTimeout(()=>k("idle"),2e3)},[e.id,f,g,u]),{totalCount:L,enabledCount:G,blockedCount:W}=S.useMemo(()=>{const $=C.length;if(f==="all")return{totalCount:$,enabledCount:C.filter(J=>J.enabled).length,blockedCount:C.filter(J=>J.blockedByAllowlist).length};const V=new Set(g),ae=C.filter(J=>vc(J)||V.has(J.slug)).length;return{totalCount:$,enabledCount:ae,blockedCount:$-ae}},[C,f,g]),P=f==="selected"&&E.every($=>g.includes($.slug)),M=f==="selected"&&E.every($=>!g.includes($.slug));return r?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-5 w-5 animate-spin text-gray-400"})}):c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.skills.title")}),c.jsx("button",{onClick:()=>o(e.id),className:"rounded p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300",title:t("agents.refresh"),children:c.jsx(Rn,{className:"h-4 w-4"})})]}),c.jsxs("div",{className:"flex gap-4",children:[c.jsx(Th,{label:t("agents.skills.total"),value:L}),c.jsx(Th,{label:t("agents.skills.enabled"),value:G,color:"green"}),c.jsx(Th,{label:t("agents.skills.blocked"),value:W,color:"red"})]}),c.jsx("div",{className:"rounded-lg border border-gray-200 p-4 dark:border-gray-700",children:c.jsxs("div",{className:"flex items-center gap-4",children:[c.jsxs("label",{className:"flex cursor-pointer items-center gap-2",children:[c.jsx("input",{type:"radio",name:"skillMode",checked:f==="all",onChange:()=>j("all"),className:"h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500"}),c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:t("agents.skills.modeAll")})]}),c.jsxs("label",{className:"flex cursor-pointer items-center gap-2",children:[c.jsx("input",{type:"radio",name:"skillMode",checked:f==="selected",onChange:()=>j("selected"),className:"h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500"}),c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:t("agents.skills.modeSelected")})]})]})}),f==="selected"&&C.length>0&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{onClick:R,disabled:P,className:"inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:opacity-40 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700",children:[c.jsx(Q4,{className:"h-3.5 w-3.5"}),t("agents.skills.selectAll")]}),c.jsxs("button",{onClick:H,disabled:M,className:"inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:opacity-40 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700",children:[c.jsx(Ng,{className:"h-3.5 w-3.5"}),t("agents.skills.deselectAll")]})]}),c.jsx("div",{className:"space-y-1",children:C.length===0?c.jsx("div",{className:"py-8 text-center text-sm text-gray-400 dark:text-gray-500",children:t("agents.skills.noRestriction")}):C.map($=>c.jsx(i9,{skill:$,selectable:f==="selected",checked:r9($,f,g),locked:vc($),onToggle:V=>N($.slug,V)},$.id))}),c.jsxs("div",{className:"flex items-center gap-2 border-t border-gray-200 pt-4 dark:border-gray-700",children:[c.jsx("button",{onClick:z,disabled:p,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50",children:t(p?"agents.skills.saving":"agents.skills.save")}),v==="success"&&c.jsx("span",{className:"text-xs text-green-600",children:t("agents.skills.saveSuccess")}),v==="error"&&c.jsx("span",{className:"text-xs text-red-600",children:t("agents.skills.saveError")})]})]})}function r9(e,t,n){return t==="all"?e.enabled:e.isCore&&e.always?!0:n.includes(e.slug)}function vc(e){return!!(e.isCore&&e.always)}function Th({label:e,value:t,color:n}){const r=n==="green"?"text-green-600 dark:text-green-400":n==="red"?"text-red-600 dark:text-red-400":"text-gray-900 dark:text-gray-100";return c.jsxs("div",{className:"rounded-lg border border-gray-200 px-3 py-2 dark:border-gray-700",children:[c.jsx("div",{className:`text-lg font-semibold ${r}`,children:t}),c.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:e})]})}function i9({skill:e,selectable:t,checked:n,locked:r,onToggle:s}){var p,b;const{t:o}=se("console"),u=((p=e.missing)==null?void 0:p.bins)&&e.missing.bins.length>0||((b=e.missing)==null?void 0:b.env)&&e.missing.env.length>0,f=e.isCore||e.isBundled?o("agents.skills.sourceBuiltIn"):o("agents.skills.sourceMarketplace"),h=e.isCore||e.isBundled?"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",g=t?o(n?"skills.detail.enabled":"skills.detail.disabled"):e.enabled?o("skills.detail.enabled"):o("skills.detail.disabled"),y=t?n?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-500 dark:bg-gray-700 dark:text-gray-400":e.enabled?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-gray-100 text-gray-500 dark:bg-gray-700 dark:text-gray-400";return c.jsxs("div",{className:"flex items-center gap-3 rounded-md px-3 py-2.5 hover:bg-gray-50 dark:hover:bg-gray-800/50",children:[t&&c.jsx("input",{type:"checkbox",checked:n,disabled:r,onChange:v=>s(v.target.checked),"aria-label":e.name,className:"h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500 disabled:opacity-50"}),c.jsx("span",{className:"text-lg",children:e.icon||c.jsx(V4,{className:"h-4 w-4 text-gray-400"})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:e.name}),c.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] font-medium ${y}`,children:g}),c.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] font-medium ${h}`,children:f})]}),e.description&&c.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs text-gray-500 dark:text-gray-400",children:e.description})]}),u&&c.jsx("span",{title:o("agents.skills.missingDeps"),children:c.jsx(Pi,{className:"h-4 w-4 shrink-0 text-amber-500"})})]})}const s9=["full","minimal","custom",""];function l9({agent:e}){const{t}=se("console"),{agentTools:n,agentToolsLoading:r,agentToolsConfig:s,fetchAgentTools:o,saveAgentToolsConfig:u}=On(),[f,h]=S.useState(""),[g,y]=S.useState([]),[p,b]=S.useState([]),[v,k]=S.useState(""),[j,N]=S.useState(""),[C,E]=S.useState(!1),[R,H]=S.useState("idle");S.useEffect(()=>{o(e.id)},[e.id,o]),S.useEffect(()=>{s&&(h(s.profile??""),y(s.alsoAllow??[]),b(s.deny??[])),H("idle")},[s]);const z=S.useCallback(async()=>{E(!0),H("idle");const $=await u(e.id,{profile:f||void 0,alsoAllow:g.length>0?g:void 0,deny:p.length>0?p:void 0});E(!1),H($.ok?"success":"error"),$.ok&&setTimeout(()=>H("idle"),2e3)},[e.id,f,g,p,u]),L=($,V,ae)=>{const J=ae.trim();J&&!$.includes(J)&&V([...$,J])},G=($,V,ae)=>{V($.filter((J,Z)=>Z!==ae))},W=u9(n??[]),P=(n==null?void 0:n.filter($=>$.enabled!==!1).length)??0,M=(n==null?void 0:n.length)??0;return r?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-5 w-5 animate-spin text-gray-400"})}):c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.tools.title")}),c.jsx("button",{onClick:()=>o(e.id),className:"rounded p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300",title:t("agents.refresh"),children:c.jsx(Rn,{className:"h-4 w-4"})})]}),c.jsx("div",{className:"rounded-lg border border-gray-200 bg-gray-50 p-4 dark:border-gray-700 dark:bg-gray-800/50",children:c.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[t("agents.tools.profile"),":"]}),c.jsx("span",{className:"font-medium text-gray-900 dark:text-gray-100",children:f||t("agents.tools.profileDefault")}),c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"|"}),c.jsx("span",{className:"text-gray-500 dark:text-gray-400",children:t("agents.tools.enabledCount",{enabled:P,total:M})})]})}),c.jsxs("div",{className:"space-y-4 border-t border-gray-200 pt-5 dark:border-gray-700",children:[c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-xs font-medium text-gray-600 dark:text-gray-400",children:t("agents.tools.profile")}),c.jsxs("div",{className:"relative w-full max-w-xs",children:[c.jsx("select",{value:f,onChange:$=>h($.target.value),"aria-label":t("agents.tools.profile"),className:"w-full appearance-none rounded-lg border border-gray-300 bg-white px-3 py-2 pr-8 text-sm text-gray-900 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200",children:s9.map($=>c.jsx("option",{value:$,children:$||t("agents.tools.profileDefault")},$))}),c.jsx(qn,{className:"pointer-events-none absolute right-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"})]})]}),c.jsx(Bv,{label:t("agents.tools.alsoAllow"),tags:g,inputValue:v,onInputChange:k,onAdd:$=>{L(g,y,$),k("")},onRemove:$=>G(g,y,$),placeholder:t("agents.tools.addTool")}),c.jsx(Bv,{label:t("agents.tools.deny"),tags:p,inputValue:j,onInputChange:N,onAdd:$=>{L(p,b,$),N("")},onRemove:$=>G(p,b,$),placeholder:t("agents.tools.addTool")}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{onClick:z,disabled:C,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50",children:t(C?"agents.tools.saving":"agents.tools.save")}),R==="success"&&c.jsx("span",{className:"text-xs text-green-600",children:t("agents.tools.saveSuccess")}),R==="error"&&c.jsx("span",{className:"text-xs text-red-600",children:t("agents.tools.saveError")})]})]}),c.jsxs("div",{className:"border-t border-gray-200 pt-5 dark:border-gray-700",children:[c.jsx("h3",{className:"mb-3 text-sm font-semibold text-gray-900 dark:text-gray-100",children:t("agents.tools.catalogTitle")}),M===0?c.jsx(c9,{message:t("agents.tools.noTools")}):c.jsx("div",{className:"space-y-4",children:Object.entries(W).map(([$,V])=>c.jsxs("div",{children:[c.jsx("h4",{className:"mb-2 text-xs font-medium uppercase tracking-wide text-gray-500 dark:text-gray-400",children:$}),c.jsx("div",{className:"space-y-1",children:V.map(ae=>c.jsx(o9,{tool:ae},ae.name))})]},$))})]})]})}function Bv({label:e,tags:t,inputValue:n,onInputChange:r,onAdd:s,onRemove:o,placeholder:u}){return c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-xs font-medium text-gray-600 dark:text-gray-400",children:e}),c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[t.map((f,h)=>c.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-gray-100 px-2 py-1 text-xs text-gray-700 dark:bg-gray-700 dark:text-gray-300",children:[f,c.jsx("button",{onClick:()=>o(h),className:"rounded-sm text-gray-400 hover:text-red-500",title:f,children:c.jsx(An,{className:"h-3 w-3"})})]},`${f}-${h}`)),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("input",{type:"text",value:n,onChange:f=>r(f.target.value),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),s(n))},placeholder:u,className:"w-36 rounded-md border border-gray-300 bg-white px-2 py-1 text-xs dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"}),c.jsx("button",{onClick:()=>s(n),className:"rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-blue-600 dark:hover:bg-gray-700",title:e,children:c.jsx(En,{className:"h-3.5 w-3.5"})})]})]})]})}function o9({tool:e}){const t=e.source==="built-in"?"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":e.source==="plugin"?"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400":"bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-400";return c.jsxs("div",{className:"flex items-center gap-3 rounded-md px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-800/50",children:[c.jsx(iu,{className:"h-4 w-4 shrink-0 text-gray-400"}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:e.name}),e.description&&c.jsx("p",{className:"line-clamp-1 text-xs text-gray-500 dark:text-gray-400",children:e.description})]}),e.source&&c.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium ${t}`,children:e.source})]})}function c9({message:e}){return c.jsx("div",{className:"py-8 text-center text-sm text-gray-400 dark:text-gray-500",children:e})}function u9(e){const t={};for(const n of e){const r=n.source??"other";t[r]||(t[r]=[]),t[r].push(n)}return t}const d9=["overview","files","tools","skills","channels","cronJobs"];function f9({agent:e}){const{t}=se("console"),{activeTab:n,setActiveTab:r}=On();return c.jsxs("div",{className:"rounded-2xl border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900",children:[c.jsx("div",{className:"flex border-b border-gray-200 px-4 dark:border-gray-700",children:d9.map(s=>c.jsxs("button",{onClick:()=>r(s),className:`relative px-4 py-3 text-sm font-medium transition-colors ${n===s?"text-red-600 dark:text-red-400":"text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"}`,children:[t(`agents.tabs.${s}`),n===s&&c.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-red-500"})]},s))}),c.jsxs("div",{className:"p-5",children:[n==="overview"&&c.jsx(n9,{agent:e},e.id),n==="files"&&c.jsx(t9,{agent:e},e.id),n==="tools"&&c.jsx(l9,{agent:e},e.id),n==="skills"&&c.jsx(a9,{agent:e},e.id),n==="channels"&&c.jsx(Fz,{agent:e},e.id),n==="cronJobs"&&c.jsx(Zz,{agent:e},e.id)]})]})}function h9({agent:e,isSelected:t,isDefault:n,onSelect:r}){var h,g,y;const{t:s}=se("console"),o=((h=e.identity)==null?void 0:h.name)??e.name??e.id,u=(g=e.identity)==null?void 0:g.emoji,f=(y=e.identity)==null?void 0:y.avatarUrl;return c.jsxs("button",{onClick:r,className:`flex w-full items-center gap-3 rounded-xl px-3 py-2.5 text-left transition-colors ${t?"border-l-2 border-blue-500 bg-blue-50 dark:bg-blue-900/20":"hover:bg-gray-50 dark:hover:bg-gray-800"}`,children:[c.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-gray-100 text-lg dark:bg-gray-800",children:f?c.jsx("img",{src:f,alt:o,className:"h-9 w-9 rounded-lg object-cover"}):c.jsx("span",{children:u??o.charAt(0).toLowerCase()})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"truncate text-sm font-medium text-gray-900 dark:text-gray-100",children:o}),n&&c.jsx("span",{className:"shrink-0 rounded-md bg-gray-200 px-1.5 py-0.5 text-[10px] font-semibold uppercase text-gray-600 dark:bg-gray-700 dark:text-gray-300",children:s("agents.defaultBadge")})]}),c.jsx("p",{className:"truncate text-xs text-gray-500 dark:text-gray-400",children:e.id})]})]})}function g9(){const{t:e}=se("console"),{agents:t,isLoading:n,selectedAgentId:r,searchQuery:s,defaultAgentId:o,fetchAgents:u,selectAgent:f,setSearchQuery:h,setCreateDialogOpen:g}=On(),y=t.filter(p=>{var k;if(!s)return!0;const b=s.toLowerCase();return(((k=p.identity)==null?void 0:k.name)??p.name??p.id).toLowerCase().includes(b)||p.id.toLowerCase().includes(b)});return c.jsxs("div",{className:"flex w-72 shrink-0 flex-col rounded-2xl border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900",children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-gray-200 px-4 py-3 dark:border-gray-700",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:e("agents.panelTitle")}),c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:e("agents.configured",{count:t.length})})]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("button",{onClick:()=>g(!0),className:"rounded-md p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-200",title:e("agents.addAgent"),children:c.jsx(En,{className:"h-4 w-4"})}),c.jsx("button",{onClick:()=>u(),disabled:n,className:"rounded-md p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700 disabled:opacity-50 dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-200",title:e("agents.refresh"),children:c.jsx(Rn,{className:`h-4 w-4 ${n?"animate-spin":""}`})})]})]}),c.jsx("div",{className:"px-3 py-2",children:c.jsxs("div",{className:"relative",children:[c.jsx(Ph,{className:"absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-gray-400"}),c.jsx("input",{type:"text",value:s,onChange:p=>h(p.target.value),placeholder:e("agents.searchPlaceholder"),className:"w-full rounded-lg border border-gray-200 bg-gray-50 py-1.5 pl-8 pr-3 text-xs text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200 dark:placeholder:text-gray-500"})]})}),c.jsx("div",{className:"flex-1 overflow-auto px-2 pb-2",children:y.length===0?c.jsx("div",{className:"flex flex-col items-center py-8 text-center",children:c.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500",children:e("agents.noAgents")})}):c.jsx("div",{className:"space-y-1",children:y.map(p=>c.jsx(h9,{agent:p,isSelected:r===p.id,isDefault:p.id===o,onSelect:()=>f(p.id)},p.id))})})]})}function m9(){const{t:e}=se("console"),{createDialogOpen:t,setCreateDialogOpen:n,createAgent:r,selectAgent:s}=On(),[o,u]=S.useState(""),[f,h]=S.useState(""),[g,y]=S.useState(""),[p,b]=S.useState(!1),[v,k]=S.useState("");if(!t)return null;const j=()=>{n(!1),u(""),h(""),y(""),k("")},N=async()=>{if(!o.trim()){k(e("agents.createDialog.nameRequired"));return}const C=f.trim()||`~/.openclaw/workspace-${o.trim().toLowerCase().replace(/\s+/g,"-")}`;b(!0),k("");const E=await r({name:o.trim(),workspace:C,emoji:g.trim()||void 0});b(!1),E?(s(E),j()):k(e("agents.overview.saveError"))};return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",children:c.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-gray-200 bg-white p-6 shadow-xl dark:border-gray-700 dark:bg-gray-900",children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:e("agents.createDialog.title")}),c.jsx("button",{onClick:j,className:"rounded-md p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800",children:c.jsx(An,{className:"h-5 w-5"})})]}),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:[e("agents.createDialog.name")," *"]}),c.jsx("input",{type:"text",value:o,onChange:C=>u(C.target.value),placeholder:e("agents.createDialog.namePlaceholder"),className:"w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200",autoFocus:!0})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:e("agents.createDialog.workspace")}),c.jsx("input",{type:"text",value:f,onChange:C=>h(C.target.value),placeholder:e("agents.createDialog.workspacePlaceholder"),className:"w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:e("agents.createDialog.emoji")}),c.jsx("input",{type:"text",value:g,onChange:C=>y(C.target.value),placeholder:e("agents.createDialog.emojiPlaceholder"),className:"w-24 rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"})]}),v&&c.jsx("p",{className:"text-sm text-red-600",children:v}),c.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[c.jsx("button",{onClick:j,className:"rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-800",children:e("agents.createDialog.cancel")}),c.jsx("button",{onClick:N,disabled:p,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50",children:e(p?"agents.createDialog.creating":"agents.createDialog.create")})]})]})]})})}function p9(){var k;const{t:e}=se("console"),{deleteDialogOpen:t,setDeleteDialogOpen:n,selectedAgentId:r,agents:s,deleteAgent:o}=On(),[u,f]=S.useState(!1),[h,g]=S.useState(!1),y=s.find(j=>j.id===r);if(!t||!y)return null;const p=((k=y.identity)==null?void 0:k.name)??y.name??y.id,b=()=>{n(!1),f(!1)},v=async()=>{g(!0),await o(y.id,u),g(!1),b()};return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",children:c.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-gray-200 bg-white p-6 shadow-xl dark:border-gray-700 dark:bg-gray-900",children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Pi,{className:"h-5 w-5 text-red-500"}),c.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:e("agents.deleteDialog.title")})]}),c.jsx("button",{onClick:b,className:"rounded-md p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800",children:c.jsx(An,{className:"h-5 w-5"})})]}),c.jsx("p",{className:"mb-4 text-sm text-gray-600 dark:text-gray-400",children:e("agents.deleteDialog.confirm",{name:p})}),c.jsxs("label",{className:"mb-4 flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300",children:[c.jsx("input",{type:"checkbox",checked:u,onChange:j=>f(j.target.checked),className:"rounded border-gray-300 text-red-600 focus:ring-red-500"}),e("agents.deleteDialog.deleteFiles")]}),c.jsxs("div",{className:"flex justify-end gap-3",children:[c.jsx("button",{onClick:b,className:"rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-800",children:e("agents.deleteDialog.cancel")}),c.jsx("button",{onClick:v,disabled:h,className:"rounded-lg bg-red-600 px-4 py-2 text-sm font-medium text-white hover:bg-red-700 disabled:opacity-50",children:e(h?"agents.deleteDialog.deleting":"agents.deleteDialog.delete")})]})]})})}function y9(){const{t:e}=se("console"),{selectedAgentId:t,agents:n,fetchAgents:r}=On(),s=n.find(o=>o.id===t)??null;return S.useEffect(()=>{r()},[r]),c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e("agents.title")}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:e("agents.description")})]}),c.jsxs("div",{className:"flex gap-6",children:[c.jsx(g9,{}),c.jsx("div",{className:"min-w-0 flex-1",children:s?c.jsxs("div",{className:"space-y-4",children:[c.jsx(qz,{agent:s}),c.jsx(f9,{agent:s})]}):c.jsxs("div",{className:"flex h-96 flex-col items-center justify-center rounded-2xl border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900",children:[c.jsx(T1,{className:"mb-3 h-12 w-12 text-gray-300 dark:text-gray-600"}),c.jsx("p",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:e("agents.selectAgent")}),c.jsx("p",{className:"mt-1 text-xs text-gray-400 dark:text-gray-500",children:e("agents.selectAgentDesc")})]})})]}),c.jsx(m9,{}),c.jsx(p9,{})]})}const yu={telegram:{type:"telegram",nameKey:"console:channels.types.telegram",icon:"✈️",fields:[{key:"botToken",labelKey:"console:channels.fields.botToken",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.botToken"}]},discord:{type:"discord",nameKey:"console:channels.types.discord",icon:"🎮",fields:[{key:"botToken",labelKey:"console:channels.fields.botToken",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.botToken"},{key:"applicationId",labelKey:"console:channels.fields.applicationId",type:"text",required:!0,placeholderKey:"console:channels.placeholders.applicationId"}]},whatsapp:{type:"whatsapp",nameKey:"console:channels.types.whatsapp",icon:"📱",fields:[],hasQrFlow:!0},signal:{type:"signal",nameKey:"console:channels.types.signal",icon:"🔒",fields:[{key:"phoneNumber",labelKey:"console:channels.fields.phoneNumber",type:"text",required:!0,placeholderKey:"console:channels.placeholders.phoneNumber"}]},feishu:{type:"feishu",nameKey:"console:channels.types.feishu",icon:"🐦",fields:[{key:"appId",labelKey:"console:channels.fields.appId",type:"text",required:!0,placeholderKey:"console:channels.placeholders.appId"},{key:"appSecret",labelKey:"console:channels.fields.appSecret",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.appSecret"}]},imessage:{type:"imessage",nameKey:"console:channels.types.imessage",icon:"💬",fields:[]},matrix:{type:"matrix",nameKey:"console:channels.types.matrix",icon:"🔗",fields:[{key:"homeserver",labelKey:"console:channels.fields.homeserver",type:"text",required:!0,placeholderKey:"console:channels.placeholders.homeserver"},{key:"accessToken",labelKey:"console:channels.fields.accessToken",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.accessToken"}]},line:{type:"line",nameKey:"console:channels.types.line",icon:"🟢",fields:[{key:"channelAccessToken",labelKey:"console:channels.fields.channelAccessToken",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.channelAccessToken"},{key:"channelSecret",labelKey:"console:channels.fields.channelSecret",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.channelSecret"}]},msteams:{type:"msteams",nameKey:"console:channels.types.msteams",icon:"👔",fields:[{key:"appId",labelKey:"console:channels.fields.appId",type:"text",required:!0,placeholderKey:"console:channels.placeholders.appId"},{key:"appPassword",labelKey:"console:channels.fields.appPassword",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.appPassword"}]},googlechat:{type:"googlechat",nameKey:"console:channels.types.googlechat",icon:"💭",fields:[{key:"serviceAccountJson",labelKey:"console:channels.fields.serviceAccount",type:"textarea",required:!0,placeholderKey:"console:channels.placeholders.serviceAccount"}]},mattermost:{type:"mattermost",nameKey:"console:channels.types.mattermost",icon:"💠",fields:[{key:"serverUrl",labelKey:"console:channels.fields.serverUrl",type:"text",required:!0,placeholderKey:"console:channels.placeholders.serverUrl"},{key:"botToken",labelKey:"console:channels.fields.botToken",type:"secret",required:!0,placeholderKey:"console:channels.placeholders.botToken"}]}},x9=Object.keys(yu);function b9({channels:e,onSelect:t}){const{t:n}=se("console"),r=new Set(e.map(s=>s.type));return c.jsxs("div",{children:[c.jsx("h3",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:n("channels.available.title")}),c.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4",children:x9.map(s=>{const o=yu[s],u=r.has(s);return c.jsxs("button",{type:"button",onClick:()=>t(s),className:"flex flex-col items-center gap-2 rounded-lg border border-gray-200 bg-white p-4 transition-colors hover:border-blue-300 hover:bg-blue-50/50 dark:border-gray-700 dark:bg-gray-800 dark:hover:border-blue-600 dark:hover:bg-blue-900/10",children:[c.jsx("span",{className:"text-2xl",children:o.icon}),c.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-300",children:n(o.nameKey)}),u?c.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-green-100 px-2 py-0.5 text-[10px] font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:[c.jsx(Tr,{className:"h-3 w-3"}),n("channels.available.configured")]}):c.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-gray-100 px-2 py-0.5 text-[10px] font-medium text-gray-500 dark:bg-gray-700 dark:text-gray-400",children:[c.jsx(En,{className:"h-3 w-3"}),n("channels.available.add")]})]},s)})})]})}const v9={connected:"bg-green-500",active:"bg-green-500",ok:"bg-green-500",disconnected:"bg-gray-400",paused:"bg-gray-400",disabled:"bg-gray-400",connecting:"bg-yellow-500",pending:"bg-yellow-500",running:"bg-yellow-500",error:"bg-red-500",failed:"bg-red-500"};function Rw({status:e,className:t=""}){const{t:n}=se("common"),r=v9[e]??"bg-gray-400",s=n(`status.${e}`,{defaultValue:e});return c.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs ${t}`,children:[c.jsx("span",{className:`inline-block h-2 w-2 rounded-full ${r}`}),c.jsx("span",{className:"text-gray-600 dark:text-gray-400",children:s})]})}const k9={connected:"border-l-green-500",error:"border-l-red-500",connecting:"border-l-yellow-500",disconnected:"border-l-gray-300 dark:border-l-gray-600"};function w9({channel:e,onLogout:t,onDetail:n}){const{t:r}=se("console"),s=yu[e.type],o=k9[e.status]??"border-l-gray-300",u=e.lastConnectedAt?new Date(e.lastConnectedAt).toLocaleString():null;return c.jsxs("div",{className:`flex items-center justify-between rounded-lg border border-l-4 bg-white p-4 dark:bg-gray-800 ${o} border-gray-200 dark:border-gray-700`,children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("span",{className:"text-2xl",children:(s==null?void 0:s.icon)??"📡"}),c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"font-medium text-gray-900 dark:text-gray-100",children:e.name}),c.jsx("span",{className:"rounded bg-gray-100 px-1.5 py-0.5 text-xs text-gray-500 dark:bg-gray-700 dark:text-gray-400",children:e.type})]}),c.jsxs("div",{className:"mt-1 flex items-center gap-3",children:[c.jsx(Rw,{status:e.status}),u&&c.jsx("span",{className:"text-xs text-gray-400 dark:text-gray-500",children:r("channels.card.lastConnected",{time:u})})]}),e.error&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:e.error})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{type:"button",onClick:()=>n(e),className:"rounded p-1.5 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300 transition-colors",title:r("channels.card.details"),children:c.jsx(ru,{className:"h-4 w-4"})}),e.status==="connected"&&c.jsx("button",{type:"button",onClick:()=>t(e),className:"rounded p-1.5 text-gray-400 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20 dark:hover:text-red-400 transition-colors",title:r("channels.card.logout"),children:c.jsx(m4,{className:"h-4 w-4"})})]})]})}const Mw=Mn((e,t)=>({channels:[],isLoading:!1,error:null,selectedChannel:null,configDialogOpen:!1,configDialogChannelType:null,qrState:"idle",qrDataUrl:null,qrError:null,fetchChannels:async()=>{e({isLoading:!0,error:null});try{await Pe();const n=await Oe().channelsStatus();e({channels:n,isLoading:!1})}catch(n){e({error:String(n),isLoading:!1})}},logoutChannel:async(n,r)=>{try{await Oe().channelsLogout(n,r),await t().fetchChannels()}catch(s){e({error:String(s)})}},openConfigDialog:(n,r)=>{e({configDialogOpen:!0,configDialogChannelType:n,selectedChannel:r??null,qrState:"idle",qrDataUrl:null,qrError:null})},closeConfigDialog:()=>{e({configDialogOpen:!1,configDialogChannelType:null,selectedChannel:null,qrState:"idle",qrDataUrl:null,qrError:null})},startQrPairing:async()=>{e({qrState:"loading",qrError:null});try{const n=await Oe().webLoginStart(!0);e({qrState:"qr",qrDataUrl:n.qrDataUrl??null}),e({qrState:"scanning"});const r=await Oe().webLoginWait();r.connected?(e({qrState:"success"}),await t().fetchChannels()):e({qrState:"error",qrError:r.message})}catch(n){e({qrState:"error",qrError:String(n)})}},cancelQrPairing:()=>{e({qrState:"idle",qrDataUrl:null,qrError:null})}}));function S9({onClose:e}){const{t}=se("console"),{qrState:n,qrDataUrl:r,qrError:s,startQrPairing:o,cancelQrPairing:u}=Mw();return n==="idle"||n==="cancel"?c.jsxs("div",{className:"flex flex-col items-center gap-4 py-6",children:[c.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:t("channels.qr.description")}),c.jsx("button",{type:"button",onClick:o,className:"rounded-md bg-green-600 px-6 py-2 text-sm font-medium text-white hover:bg-green-700 transition-colors",children:t("channels.qr.startPairing")})]}):n==="loading"?c.jsxs("div",{className:"flex flex-col items-center gap-3 py-8",children:[c.jsx(Mt,{className:"h-8 w-8 animate-spin text-green-500"}),c.jsx("p",{className:"text-sm text-gray-500",children:t("channels.qr.loading")})]}):n==="qr"||n==="scanning"?c.jsxs("div",{className:"flex flex-col items-center gap-4 py-4",children:[r&&c.jsx("img",{src:r,alt:"WhatsApp QR Code",className:"h-48 w-48 rounded-lg border border-gray-200 dark:border-gray-700"}),c.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:t(n==="scanning"?"channels.qr.waitingScan":"channels.qr.scanPrompt")}),n==="scanning"&&c.jsx(Mt,{className:"h-5 w-5 animate-spin text-green-500"}),c.jsx("button",{type:"button",onClick:u,className:"text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",children:t("common:actions.cancel")})]}):n==="success"?c.jsxs("div",{className:"flex flex-col items-center gap-3 py-8",children:[c.jsx(qi,{className:"h-10 w-10 text-green-500"}),c.jsx("p",{className:"font-medium text-green-600",children:t("channels.qr.success")}),c.jsx("button",{type:"button",onClick:e,className:"rounded-md border border-gray-300 px-4 py-1.5 text-sm text-gray-600 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:t("common:actions.close")})]}):c.jsxs("div",{className:"flex flex-col items-center gap-3 py-8",children:[c.jsx(tu,{className:"h-10 w-10 text-red-500"}),c.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:s??t("channels.qr.error")}),c.jsx("button",{type:"button",onClick:o,className:"rounded-md border border-red-300 px-4 py-1.5 text-sm text-red-600 hover:bg-red-50 dark:border-red-700 dark:text-red-400 dark:hover:bg-red-900/20 transition-colors",children:t("common:actions.retry")})]})}function j9({open:e,channelType:t,onClose:n}){const{t:r}=se("console"),s=S.useRef(null),[o,u]=S.useState({}),[f,h]=S.useState({}),[g,y]=S.useState(new Set),p=t?yu[t]:null;if(S.useEffect(()=>{const k=s.current;k&&(e&&!k.open?(u({}),h({}),y(new Set),k.showModal()):!e&&k.open&&k.close())},[e]),!p)return null;if(p.hasQrFlow)return c.jsx("dialog",{ref:s,onClose:n,className:"fixed inset-0 z-50 m-auto max-w-md rounded-lg border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-6",children:[c.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[c.jsx("span",{className:"text-xl",children:p.icon}),c.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:r(p.nameKey)})]}),c.jsx(S9,{onClose:n})]})});const b=()=>{var N;const k={};let j=!1;for(const C of p.fields)C.required&&!((N=o[C.key])!=null&&N.trim())&&(k[C.key]=!0,j=!0);h(k),j||n()},v=k=>{y(j=>{const N=new Set(j);return N.has(k)?N.delete(k):N.add(k),N})};return c.jsx("dialog",{ref:s,onClose:n,className:"fixed inset-0 z-50 m-auto max-w-md rounded-lg border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-6",children:[c.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[c.jsx("span",{className:"text-xl",children:p.icon}),c.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:r(p.nameKey)})]}),c.jsx("div",{className:"space-y-4",children:p.fields.map(k=>c.jsx(C9,{field:k,value:o[k.key]??"",onChange:j=>u(N=>({...N,[k.key]:j})),hasError:f[k.key]??!1,isSecretVisible:g.has(k.key),onToggleSecret:()=>v(k.key)},k.key))}),c.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:n,className:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:r("channels.configDialog.cancel",{defaultValue:r("common:actions.cancel")})}),c.jsx("button",{type:"button",onClick:b,className:"rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:r("channels.configDialog.save",{defaultValue:r("common:actions.save")})})]})]})})}function C9({field:e,value:t,onChange:n,hasError:r,isSecretVisible:s,onToggleSecret:o}){const{t:u}=se("console"),f=r?"border-red-500":"border-gray-300 dark:border-gray-600";return e.type==="textarea"?c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:[u(e.labelKey)," ",e.required&&c.jsx("span",{className:"text-red-500",children:"*"})]}),c.jsx("textarea",{value:t,onChange:h=>n(h.target.value),placeholder:u(e.placeholderKey),rows:4,className:`w-full rounded-md border bg-white px-3 py-2 text-sm dark:bg-gray-700 dark:text-gray-100 ${f}`}),r&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:u("channels.configDialog.required")})]}):c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-sm font-medium text-gray-700 dark:text-gray-300",children:[u(e.labelKey)," ",e.required&&c.jsx("span",{className:"text-red-500",children:"*"})]}),c.jsxs("div",{className:"relative",children:[c.jsx("input",{type:e.type==="secret"&&!s?"password":"text",value:t,onChange:h=>n(h.target.value),placeholder:u(e.placeholderKey),className:`w-full rounded-md border bg-white px-3 py-2 text-sm dark:bg-gray-700 dark:text-gray-100 ${f} ${e.type==="secret"?"pr-10":""}`}),e.type==="secret"&&c.jsx("button",{type:"button",onClick:o,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:s?c.jsx(nu,{className:"h-4 w-4"}):c.jsx(au,{className:"h-4 w-4"})})]}),r&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:u("channels.configDialog.required")})]})}function N9({channels:e}){const{t}=se("console"),n=e.filter(s=>s.status==="connected").length,r=e.filter(s=>s.status==="error").length;return c.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[t("channels.stats.total")," ",c.jsx("strong",{className:"text-gray-900 dark:text-gray-100",children:e.length})]}),c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"·"}),c.jsxs("span",{className:"text-green-600 dark:text-green-400",children:[t("channels.stats.connected")," ",c.jsx("strong",{children:n})]}),r>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"·"}),c.jsxs("span",{className:"text-red-600 dark:text-red-400",children:[t("channels.stats.errors")," ",c.jsx("strong",{children:r})]})]})]})}function jl({open:e,title:t,description:n,confirmLabel:r,onConfirm:s,onCancel:o,variant:u="default"}){const{t:f}=se("common"),h=S.useRef(null);S.useEffect(()=>{const y=h.current;y&&(e&&!y.open?y.showModal():!e&&y.open&&y.close())},[e]);const g=u==="danger"?"bg-red-600 hover:bg-red-700 text-white":"bg-blue-600 hover:bg-blue-700 text-white";return c.jsx("dialog",{ref:h,onClose:o,className:"fixed inset-0 z-50 m-auto max-w-md rounded-lg border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-6",children:[c.jsx("h3",{className:"mb-2 text-lg font-semibold text-gray-900 dark:text-gray-100",children:t}),c.jsx("p",{className:"mb-6 text-sm text-gray-600 dark:text-gray-400",children:n}),c.jsxs("div",{className:"flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:o,className:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:f("actions.cancel")}),c.jsx("button",{type:"button",onClick:s,className:`rounded-md px-4 py-2 text-sm font-medium transition-colors ${g}`,children:r??f("actions.confirm")})]})]})})}function Er({icon:e,title:t,description:n,action:r}){return c.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[c.jsx(e,{className:"mb-4 h-12 w-12 text-gray-300 dark:text-gray-600",strokeWidth:1.5}),c.jsx("h3",{className:"mb-1 text-base font-medium text-gray-700 dark:text-gray-300",children:t}),n&&c.jsx("p",{className:"mb-4 max-w-sm text-sm text-gray-500 dark:text-gray-400",children:n}),r&&c.jsx("button",{type:"button",onClick:r.onClick,className:"rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:r.label})]})}function xu({message:e,onRetry:t}){const{t:n}=se("common");return c.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[c.jsx(Sg,{className:"mb-3 h-10 w-10 text-red-500"}),c.jsx("p",{className:"mb-4 text-sm text-red-600 dark:text-red-400",children:e}),t&&c.jsx("button",{type:"button",onClick:t,className:"rounded-md border border-red-300 px-4 py-2 text-sm font-medium text-red-600 hover:bg-red-50 dark:border-red-700 dark:text-red-400 dark:hover:bg-red-900/20 transition-colors",children:n("actions.retry")})]})}function zl({message:e}){return c.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[c.jsx(Mt,{className:"mb-3 h-8 w-8 animate-spin text-blue-500"}),e&&c.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:e})]})}function A9(){const{t:e}=se("console"),{channels:t,isLoading:n,error:r,fetchChannels:s,logoutChannel:o,configDialogOpen:u,configDialogChannelType:f,openConfigDialog:h,closeConfigDialog:g}=Mw(),[y,p]=S.useState(null);S.useEffect(()=>{s()},[s]);const b=async()=>{y&&(await o(y.type,y.accountId),p(null))};return n&&t.length===0?c.jsxs("div",{className:"space-y-6",children:[c.jsx(Dh,{title:e("channels.title"),description:e("channels.description"),onRefresh:s}),c.jsx(zl,{})]}):r&&t.length===0?c.jsxs("div",{className:"space-y-6",children:[c.jsx(Dh,{title:e("channels.title"),description:e("channels.description"),onRefresh:s}),c.jsx(xu,{message:r,onRetry:s})]}):c.jsxs("div",{className:"space-y-6",children:[c.jsx(Dh,{title:e("channels.title"),description:e("channels.description"),onRefresh:s,loading:n}),c.jsx(N9,{channels:t}),t.length===0?c.jsx(Er,{icon:o4,title:e("channels.empty.title"),description:e("channels.empty.description")}):c.jsx("div",{className:"space-y-3",children:t.map(v=>c.jsx(w9,{channel:v,onLogout:p,onDetail:k=>h(k.type,k)},v.id))}),c.jsx(b9,{channels:t,onSelect:v=>h(v)}),c.jsx(j9,{open:u,channelType:f,onClose:g}),c.jsx(jl,{open:y!==null,title:e("channels.logout.title"),description:e("channels.logout.description",{name:(y==null?void 0:y.name)??""}),onConfirm:b,onCancel:()=>p(null),variant:"danger"})]})}function Dh({title:e,description:t,onRefresh:n,loading:r}){const{t:s}=se("common");return c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:t})]}),c.jsxs("button",{type:"button",onClick:n,disabled:r,className:"flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:[c.jsx(Rn,{className:`h-3.5 w-3.5 ${r?"animate-spin":""}`}),s("actions.refresh")]})]})}function E9({tasks:e}){const{t}=se("console"),n=e.filter(o=>o.enabled&&o.state.lastRunStatus!=="error").length,r=e.filter(o=>!o.enabled).length,s=e.filter(o=>o.state.lastRunStatus==="error").length;return c.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[t("cron.stats.total")," ",c.jsx("strong",{className:"text-gray-900 dark:text-gray-100",children:e.length})]}),c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"·"}),c.jsxs("span",{className:"text-green-600 dark:text-green-400",children:[t("cron.stats.active")," ",c.jsx("strong",{children:n})]}),c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"·"}),c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[t("cron.stats.paused")," ",c.jsx("strong",{children:r})]}),s>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-gray-300 dark:text-gray-600",children:"·"}),c.jsxs("span",{className:"text-red-600 dark:text-red-400",children:[t("cron.stats.failed")," ",c.jsx("strong",{children:s})]})]})]})}function T9(){const{t:e}=se("console"),{tasks:t,isLoading:n,error:r,dialogOpen:s,editingTask:o,fetchTasks:u,addTask:f,updateTask:h,removeTask:g,runTask:y,openDialog:p,closeDialog:b,initEventListeners:v}=Vc(),[k,j]=S.useState(null),[N,C]=S.useState(null);S.useEffect(()=>(u(),v()),[u,v]);const E=(L,G)=>{h(L,{enabled:G})},R=async()=>{k&&(await g(k),j(null))},H=async()=>{N&&(await y(N),C(null),await u())};if(n&&t.length===0)return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Rh,{title:e("cron.title"),description:e("cron.description"),onRefresh:u,onCreate:()=>p()}),c.jsx(zl,{})]});if(r&&t.length===0)return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Rh,{title:e("cron.title"),description:e("cron.description"),onRefresh:u,onCreate:()=>p()}),c.jsx(xu,{message:r,onRetry:u})]});const z=[...t].sort((L,G)=>{const W=L.state.nextRunAtMs??1/0,P=G.state.nextRunAtMs??1/0;return W-P});return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Rh,{title:e("cron.title"),description:e("cron.description"),onRefresh:u,loading:n,onCreate:()=>p()}),c.jsx(E9,{tasks:t}),t.length===0?c.jsx(Er,{icon:Ki,title:e("cron.empty.title"),action:{label:e("cron.empty.createFirst"),onClick:()=>p()}}):c.jsx("div",{className:"space-y-3",children:z.map(L=>c.jsx(Tw,{task:L,onToggle:E,onRun:C,onEdit:p,onDelete:j},L.id))}),c.jsx(Dw,{open:s,editingTask:o,onSave:f,onUpdate:h,onClose:b}),c.jsx(jl,{open:k!==null,title:e("cron.delete.title"),description:e("cron.delete.description"),onConfirm:R,onCancel:()=>j(null),variant:"danger"}),c.jsx(jl,{open:N!==null,title:e("cron.run.title"),description:e("cron.run.description"),onConfirm:H,onCancel:()=>C(null)})]})}function Rh({title:e,description:t,onRefresh:n,loading:r,onCreate:s}){const{t:o}=se("common");return c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:t})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{type:"button",onClick:s,className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-blue-700 transition-colors",children:[c.jsx(En,{className:"h-3.5 w-3.5"}),o("actions.create")]}),c.jsxs("button",{type:"button",onClick:n,disabled:r,className:"flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:[c.jsx(Rn,{className:`h-3.5 w-3.5 ${r?"animate-spin":""}`}),o("actions.refresh")]})]})]})}const D9={warning:"border-amber-300 bg-amber-50 text-amber-800 dark:border-amber-700 dark:bg-amber-900/20 dark:text-amber-300",error:"border-red-300 bg-red-50 text-red-800 dark:border-red-700 dark:bg-red-900/20 dark:text-red-300"};function Uv({variant:e,message:t,actionLabel:n,onAction:r}){const s=e==="warning"?Pi:tu;return c.jsxs("div",{className:`flex items-center gap-3 rounded-lg border px-4 py-3 text-sm ${D9[e]}`,children:[c.jsx(s,{className:"h-4 w-4 flex-shrink-0"}),c.jsx("span",{className:"flex-1",children:t}),n&&r&&c.jsx("button",{type:"button",onClick:r,className:"text-xs font-medium underline hover:no-underline",children:n})]})}const R9={whatsapp:"📱",telegram:"✈️",discord:"🎮",signal:"🔒",feishu:"🐦",imessage:"💬",matrix:"🔗",line:"🟢",msteams:"👔",googlechat:"💭",mattermost:"💠"};function M9({channels:e}){const{t}=se("console"),n=e.filter(r=>r.status==="connected");return n.length===0?c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:t("dashboard.channelOverview.title")}),c.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-400",children:[c.jsx(Tl,{className:"h-4 w-4"}),c.jsx("span",{children:t("dashboard.channelOverview.empty")})]})]}):c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:t("dashboard.channelOverview.title")}),c.jsx("div",{className:"flex flex-wrap gap-3",children:n.map(r=>c.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-50 px-3 py-1.5 dark:bg-gray-700/50",children:[c.jsx("span",{className:"text-base",children:R9[r.type]??"📡"}),c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:r.name}),c.jsx(Rw,{status:r.status})]},r.id))})]})}const O9=[{path:"/channels",icon:Tl,titleKey:"console:channels.title",descKey:"console:channels.description"},{path:"/skills",icon:iu,titleKey:"console:skills.title",descKey:"console:skills.description"},{path:"/cron",icon:Ki,titleKey:"console:cron.title",descKey:"console:cron.description"},{path:"/settings",icon:Cg,titleKey:"console:settings.title",descKey:"console:settings.description"}];function _9(){const e=$i(),{t}=se();return c.jsx("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-4",children:O9.map(n=>c.jsxs("button",{type:"button",onClick:()=>e(n.path),className:"flex flex-col items-start gap-2 rounded-lg border border-gray-200 bg-white p-4 text-left transition-colors hover:border-blue-300 hover:bg-blue-50/50 dark:border-gray-700 dark:bg-gray-800 dark:hover:border-blue-600 dark:hover:bg-blue-900/10",children:[c.jsx(n.icon,{className:"h-5 w-5 text-gray-500 dark:text-gray-400"}),c.jsxs("div",{children:[c.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:t(n.titleKey)}),c.jsx("div",{className:"mt-0.5 text-xs text-gray-500 dark:text-gray-400 line-clamp-2",children:t(n.descKey)})]})]},n.path))})}function L9({skills:e}){const{t}=se("console"),n=e.filter(r=>r.enabled);return n.length===0?c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:t("dashboard.skillOverview.title")}),c.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-400",children:[c.jsx(iu,{className:"h-4 w-4"}),c.jsx("span",{children:t("dashboard.skillOverview.empty")})]})]}):c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:t("dashboard.skillOverview.title")}),c.jsx("div",{className:"flex flex-wrap gap-3",children:n.map(r=>c.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-50 px-3 py-1.5 dark:bg-gray-700/50",children:[c.jsx("span",{className:"text-base",children:r.icon||"📦"}),c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:r.name})]},r.id))})]})}function kc({icon:e,title:t,value:n,subtitle:r,progress:s,color:o="text-blue-500"}){return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800",children:[c.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[c.jsx(e,{className:`h-5 w-5 ${o}`}),c.jsx("span",{className:"text-xs font-medium text-gray-500 dark:text-gray-400",children:t})]}),c.jsx("div",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:n}),r&&c.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:r}),s!=null&&c.jsx("div",{className:"mt-2 h-1.5 w-full overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700",children:c.jsx("div",{className:"h-full rounded-full bg-blue-500 transition-all",style:{width:`${Math.min(100,Math.max(0,s))}%`}})})]})}const z9=Mn(e=>({channelsSummary:[],skillsSummary:[],usage:null,uptime:0,isLoading:!1,error:null,refresh:async()=>{e({isLoading:!0,error:null});try{const t=await Pe(),n=await Promise.allSettled([t.channelsStatus(),t.skillsStatus(),t.usageStatus()]),r=n[0].status==="fulfilled"?n[0].value:[],s=n[1].status==="fulfilled"?n[1].value:[],o=n[2].status==="fulfilled"?n[2].value:null,u=[];n[0].status==="rejected"&&u.push(`channels: ${n[0].reason}`),n[1].status==="rejected"&&u.push(`skills: ${n[1].reason}`),n[2].status==="rejected"&&u.push(`usage: ${n[2].reason}`),e({channelsSummary:r,skillsSummary:s,usage:o,isLoading:!1,error:u.length>0?u.join("; "):null})}catch(t){e({error:String(t),isLoading:!1})}}}));function I9(){const{t:e}=se("console"),{channelsSummary:t,skillsSummary:n,usage:r,isLoading:s,error:o,refresh:u}=z9(),f=ie(k=>k.connectionStatus);if(S.useEffect(()=>{u()},[u]),s&&t.length===0){const k=f!=="connected"&&f!=="connecting";return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Mh,{title:e("dashboard.title"),description:e("dashboard.description"),onRefresh:u}),k?c.jsx($v,{status:f,onRetry:u}):c.jsx(zl,{message:e("dashboard.loading")})]})}if(o&&t.length===0&&n.length===0){const k=f!=="connected";return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Mh,{title:e("dashboard.title"),description:e("dashboard.description"),onRefresh:u}),k?c.jsx($v,{status:f,onRetry:u}):c.jsx(xu,{message:o,onRetry:u})]})}const h=t.filter(k=>k.status==="connected").length,g=t.filter(k=>k.status==="error").length,y=n.filter(k=>k.enabled).length,p=r==null?void 0:r.providers[0],b=p==null?void 0:p.windows[0],v=p?`${p.displayName}: ${(b==null?void 0:b.usedPercent)??0}%`:"—";return c.jsxs("div",{className:"space-y-6",children:[c.jsx(Mh,{title:e("dashboard.title"),description:e("dashboard.description"),onRefresh:u,loading:s}),f!=="connected"&&c.jsx(Uv,{variant:"warning",message:e("dashboard.alerts.gatewayDisconnected")}),g>0&&c.jsx(Uv,{variant:"error",message:e("dashboard.alerts.channelErrors",{count:g})}),c.jsxs("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-4",children:[c.jsx(kc,{icon:Tl,title:e("dashboard.stats.channels"),value:`${h} / ${t.length}`,color:"text-green-500"}),c.jsx(kc,{icon:iu,title:e("dashboard.stats.skills"),value:`${y} / ${n.length}`,color:"text-purple-500"}),c.jsx(kc,{icon:I1,title:e("dashboard.stats.usage"),value:v,progress:b==null?void 0:b.usedPercent,color:"text-blue-500"}),c.jsx(kc,{icon:Ki,title:e("dashboard.stats.uptime"),value:f==="connected"?e("dashboard.stats.uptimeOnline"):"—",color:"text-amber-500"})]}),c.jsxs("div",{children:[c.jsx("h2",{className:"mb-3 text-sm font-medium text-gray-700 dark:text-gray-300",children:e("dashboard.quickNav.title")}),c.jsx(_9,{})]}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[c.jsx(M9,{channels:t}),c.jsx(L9,{skills:n})]})]})}function $v({status:e,onRetry:t}){const{t:n}=se("console"),{t:r}=se("common"),s=e==="reconnecting";return c.jsx("div",{className:"flex flex-col items-center justify-center py-12",children:c.jsxs("div",{className:"w-full max-w-md rounded-lg border border-amber-500/30 bg-amber-500/5 p-6",children:[c.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[s?c.jsx(Mt,{className:"h-8 w-8 animate-spin text-amber-500"}):c.jsx(Ag,{className:"h-8 w-8 text-amber-500"}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:n("dashboard.connectionGuide.title")}),c.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:n(s?"dashboard.connectionGuide.reconnecting":"dashboard.connectionGuide.subtitle")})]})]}),c.jsxs("ol",{className:"mb-5 space-y-2.5 text-sm text-gray-600 dark:text-gray-300",children:[c.jsxs("li",{className:"flex items-start gap-2",children:[c.jsx("span",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-amber-500/20 text-xs font-bold text-amber-600 dark:text-amber-400",children:"1"}),c.jsx("span",{children:n("dashboard.connectionGuide.step1")})]}),c.jsxs("li",{className:"flex items-start gap-2",children:[c.jsx("span",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-amber-500/20 text-xs font-bold text-amber-600 dark:text-amber-400",children:"2"}),c.jsx("span",{children:n("dashboard.connectionGuide.step2")})]}),c.jsxs("li",{className:"flex items-start gap-2",children:[c.jsx("span",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-amber-500/20 text-xs font-bold text-amber-600 dark:text-amber-400",children:"3"}),c.jsx("span",{children:n("dashboard.connectionGuide.step3")})]})]}),c.jsxs("div",{className:"mb-4 rounded-md bg-gray-900/60 px-3 py-2 font-mono text-xs text-gray-300",children:[c.jsxs("p",{className:"text-gray-500",children:["# ",n("dashboard.connectionGuide.cmdComment")]}),c.jsx("p",{children:"openclaw-office --token <your-token>"})]}),c.jsx("button",{type:"button",onClick:t,className:"w-full rounded-md bg-amber-500/90 px-4 py-2 text-sm font-medium text-white hover:bg-amber-500 transition-colors",children:r("actions.retry")})]})})}function Mh({title:e,description:t,onRefresh:n,loading:r}){const{t:s}=se("common");return c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:t})]}),c.jsxs("button",{type:"button",onClick:n,disabled:r,className:"flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:[c.jsx(Rn,{className:`h-3.5 w-3.5 ${r?"animate-spin":""}`}),s("actions.refresh")]})]})}function H9(){const{t:e}=se("console"),t=Ee(n=>n.status);return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-4 text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.about.title")}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"text-center py-2",children:[c.jsx("p",{className:"text-lg font-bold text-gray-900 dark:text-gray-100",children:e("settings.about.appName")}),c.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:e("settings.about.tagline")}),(t==null?void 0:t.version)&&c.jsxs("p",{className:"mt-1 text-xs text-gray-400 dark:text-gray-500",children:[e("settings.about.version"),": ",t.version]})]}),c.jsxs("div",{className:"flex justify-center gap-4 pt-2",children:[c.jsxs("a",{href:"https://docs.openclaw.ai",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-blue-600 hover:underline dark:text-blue-400",children:[c.jsx(Oc,{className:"h-3.5 w-3.5"}),e("settings.about.docs")]}),c.jsxs("a",{href:"https://github.com/openclaw/openclaw",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-blue-600 hover:underline dark:text-blue-400",children:[c.jsx(Oc,{className:"h-3.5 w-3.5"}),e("settings.about.github")]})]})]})]})}const qv="openclaw-console-theme",Kv="openclaw-console-lang",Pv="openclaw-console-dev-mode";function Fv(e,t){return typeof window>"u"?t:localStorage.getItem(e)??t}function B9(e,t){if(typeof window>"u")return t;const n=localStorage.getItem(e);return n===null?t:n==="true"}const Cl=Mn(e=>({theme:Fv(qv,"system"),language:Fv(Kv,"zh"),devModeUnlocked:B9(Pv,!1),setTheme:t=>{localStorage.setItem(qv,t),e({theme:t})},setLanguage:t=>{localStorage.setItem(Kv,t),e({language:t})},setDevModeUnlocked:t=>{localStorage.setItem(Pv,String(t)),e({devModeUnlocked:t})}}));function U9(){const{t:e}=se("console"),t=Cl(r=>r.devModeUnlocked),n=Cl(r=>r.setDevModeUnlocked);return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-4 text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.advanced.title")}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:e("settings.advanced.devMode")}),c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:e("settings.advanced.devModeHint")})]}),c.jsx("button",{type:"button",role:"switch","aria-checked":t,onClick:()=>n(!t),className:`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors ${t?"bg-blue-600":"bg-gray-300 dark:bg-gray-600"}`,children:c.jsx("span",{className:`inline-block h-4 w-4 rounded-full bg-white shadow transition-transform ${t?"translate-x-6":"translate-x-1"}`})})]})]})}const $9=[{value:"light",icon:J4,labelKey:"settings.appearance.themeLight"},{value:"dark",icon:A4,labelKey:"settings.appearance.themeDark"},{value:"system",icon:C4,labelKey:"settings.appearance.themeSystem"}],q9=[{value:"zh",labelKey:"settings.appearance.langZh"},{value:"en",labelKey:"settings.appearance.langEn"}];function K9(){return typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function P9(){const{t:e,i18n:t}=se("console"),n=Cl(u=>u.theme),r=Cl(u=>u.setTheme),s=ie(u=>u.setTheme),o=u=>{r(u);const f=u==="system"?K9():u;s(f)};return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-4 text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.appearance.title")}),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:e("settings.appearance.theme")}),c.jsx("div",{className:"flex gap-1 rounded-lg border border-gray-200 p-1 dark:border-gray-600",children:$9.map(({value:u,icon:f,labelKey:h})=>c.jsxs("button",{type:"button",onClick:()=>o(u),className:`flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors ${n===u?"bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300":"text-gray-600 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"}`,children:[c.jsx(f,{className:"h-3.5 w-3.5"}),e(h)]},u))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:e("settings.appearance.language")}),c.jsx("div",{className:"flex gap-1 rounded-lg border border-gray-200 p-1 dark:border-gray-600",children:q9.map(({value:u,labelKey:f})=>c.jsx("button",{type:"button",onClick:()=>t.changeLanguage(u),className:`rounded-md px-3 py-1.5 text-xs font-medium transition-colors ${t.language===u?"bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300":"text-gray-600 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"}`,children:e(f)},u))})]})]})]})}const rm=["openai-completions","openai-responses","openai-codex-responses","anthropic-messages","google-generative-ai","github-copilot","bedrock-converse-stream","ollama"],F9=["text","image"],G9=["openai","zai","qwen"],V9=["max_completion_tokens","max_tokens"];function Y9(){return{id:"",name:"",reasoning:!1,input:["text"],cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:128e3,maxTokens:8192}}const Xt=[{id:"anthropic",name:"Anthropic",icon:"🤖",defaultBaseUrl:"https://api.anthropic.com",defaultApi:"anthropic-messages",requiresApiKey:!0,placeholder:"sk-ant-..."},{id:"openai",name:"OpenAI",icon:"🧠",defaultBaseUrl:"https://api.openai.com/v1",defaultApi:"openai-responses",requiresApiKey:!0,placeholder:"sk-..."},{id:"openai-codex",name:"OpenAI Codex",icon:"🧬",defaultBaseUrl:"https://api.openai.com/v1",defaultApi:"openai-codex-responses",requiresApiKey:!1},{id:"google",name:"Google AI",icon:"🔮",defaultBaseUrl:"https://generativelanguage.googleapis.com",defaultApi:"google-generative-ai",requiresApiKey:!0},{id:"openrouter",name:"OpenRouter",icon:"🔀",defaultBaseUrl:"https://openrouter.ai/api/v1",defaultApi:"openai-completions",requiresApiKey:!0,placeholder:"sk-or-..."},{id:"deepseek",name:"DeepSeek",icon:"🔍",defaultBaseUrl:"https://api.deepseek.com/v1",defaultApi:"openai-completions",requiresApiKey:!0,placeholder:"sk-..."},{id:"moonshot",name:"Moonshot (CN)",icon:"🌙",defaultBaseUrl:"https://api.moonshot.cn/v1",defaultApi:"openai-completions",requiresApiKey:!0,placeholder:"sk-..."},{id:"qwen",name:"通义千问 (CN)",icon:"🌐",defaultBaseUrl:"https://dashscope.aliyuncs.com/compatible-mode/v1",defaultApi:"openai-completions",requiresApiKey:!0,placeholder:"sk-..."},{id:"siliconflow",name:"SiliconFlow (CN)",icon:"⚡",defaultBaseUrl:"https://api.siliconflow.cn/v1",defaultApi:"openai-completions",requiresApiKey:!0,placeholder:"sk-..."},{id:"ollama",name:"Ollama",icon:"🦙",defaultBaseUrl:"http://localhost:11434",defaultApi:"ollama",requiresApiKey:!1},{id:"bedrock",name:"AWS Bedrock",icon:"☁️",defaultBaseUrl:"",defaultApi:"bedrock-converse-stream",requiresApiKey:!1},{id:"github-copilot",name:"GitHub Copilot",icon:"🐙",defaultBaseUrl:"",defaultApi:"github-copilot",requiresApiKey:!1},{id:"custom",name:"Custom",icon:"⚙️",defaultBaseUrl:"",defaultApi:"openai-completions",requiresApiKey:!0}];function im(e,t,n){const r=Xt.find(s=>s.id===e);if(r)return r;if(t){const s=Xt.find(o=>o.defaultApi===t);if(s)return s}if(n){if(n.includes("anthropic.com"))return Xt[0];if(n.includes("openai.com"))return Xt[1];if(n.includes("googleapis.com"))return Xt[2];if(n.includes("openrouter.ai"))return Xt[3];if(n.includes("deepseek.com"))return Xt[4];if(n.includes("moonshot.cn"))return Xt[5];if(n.includes("dashscope.aliyuncs.com"))return Xt[6];if(n.includes("siliconflow.cn"))return Xt[7];if(n.includes("localhost:11434"))return Xt[8]}return Xt[Xt.length-1]}const sm="__OPENCLAW_REDACTED__";function Q9(e){return Array.isArray(e)?e.map(t=>({id:String(t.id??""),name:String(t.name??""),api:t.api,reasoning:t.reasoning===!0,input:Array.isArray(t.input)?t.input:["text"],cost:t.cost?{input:Number(t.cost.input??0),output:Number(t.cost.output??0),cacheRead:Number(t.cost.cacheRead??0),cacheWrite:Number(t.cost.cacheWrite??0)}:void 0,contextWindow:typeof t.contextWindow=="number"?t.contextWindow:void 0,maxTokens:typeof t.maxTokens=="number"?t.maxTokens:void 0,compat:t.compat})):[]}function Ow(e){const t={id:e.id,name:e.name,reasoning:e.reasoning??!1,input:e.input??["text"]};return e.api&&(t.api=e.api),e.cost&&(t.cost=e.cost),e.contextWindow&&(t.contextWindow=e.contextWindow),e.maxTokens&&(t.maxTokens=e.maxTokens),e.compat&&(t.compat=e.compat),e.headers&&(t.headers=e.headers),t}function W9(){var j;const{t:e}=se("console"),t=Ee(N=>N.config),n=Ee(N=>N.configPath),r=Ee(N=>N.status),s=Ee(N=>N.configRaw),o=(r==null?void 0:r.configPath)??n,[u,f]=S.useState(!1),[h,g]=S.useState(null),y=(j=t==null?void 0:t.gateway)==null?void 0:j.auth,p=(y==null?void 0:y.token)===sm,b="/gateway-ws",v=b.startsWith("/")?`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}${b}`:b,k=(N,C)=>{navigator.clipboard.writeText(N),g(C),setTimeout(()=>g(null),2e3)};return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-4 text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.developer.title")}),c.jsxs("div",{className:"space-y-3",children:[c.jsx(Oh,{label:e("settings.developer.gatewayToken"),value:p?e("settings.developer.tokenConfigured"):"—",hint:e("settings.developer.tokenHint")}),c.jsx(Oh,{label:e("settings.developer.configPath"),value:o??"—",copyable:!0,onCopy:()=>o&&k(o,"path"),copied:h==="path",copiedLabel:e("settings.developer.copied")}),c.jsx(Oh,{label:e("settings.developer.wsUrl"),value:v,copyable:!0,onCopy:()=>k(v,"ws"),copied:h==="ws",copiedLabel:e("settings.developer.copied")}),s&&c.jsxs("div",{children:[c.jsxs("button",{type:"button",onClick:()=>f(!u),className:"flex items-center gap-1.5 text-sm text-blue-600 hover:underline dark:text-blue-400",children:[u?c.jsx(wg,{className:"h-4 w-4"}):c.jsx(qn,{className:"h-4 w-4"}),e(u?"settings.developer.hideConfig":"settings.developer.showConfig")," ",e("settings.developer.rawConfig")]}),u&&c.jsx("pre",{className:"mt-2 max-h-64 overflow-auto rounded-md bg-gray-100 p-3 text-xs text-gray-800 dark:bg-gray-900 dark:text-gray-300",children:s})]})]})]})}function Oh({label:e,value:t,hint:n,copyable:r,onCopy:s,copied:o,copiedLabel:u}){return c.jsxs("div",{className:"flex items-center justify-between rounded-md bg-gray-50 px-3 py-2 dark:bg-gray-700/50",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:e}),c.jsx("p",{className:"text-sm font-mono text-gray-900 dark:text-gray-100 truncate",children:t}),n&&c.jsx("p",{className:"text-xs text-gray-400 dark:text-gray-500 mt-0.5",children:n})]}),r&&s&&c.jsx("button",{type:"button",onClick:s,className:"shrink-0 rounded p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors",title:u,children:o?c.jsx(Tr,{className:"h-4 w-4 text-green-500"}):c.jsx(jg,{className:"h-4 w-4"})})]})}function X9(){const{t:e}=se("console"),t=Ee(f=>f.status),n=Ee(f=>f.statusLoading),r=Ee(f=>f.statusError),s=Ee(f=>f.fetchStatus),o=t!=null&&t.uptime?Math.floor(t.uptime/3600):0,u=t!=null&&t.uptime?Math.floor(t.uptime%3600/60):0;return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsx("h3",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.gateway.title")}),c.jsxs("button",{type:"button",onClick:s,disabled:n,className:"flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:[c.jsx(Rn,{className:`h-3.5 w-3.5 ${n?"animate-spin":""}`}),e("settings.gateway.refresh")]})]}),r?c.jsxs("div",{className:"flex items-center gap-3 rounded-lg bg-amber-50 px-4 py-3 dark:bg-amber-900/20",children:[c.jsx(Ag,{className:"h-5 w-5 text-amber-500 shrink-0"}),c.jsxs("div",{children:[c.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-300",children:e("settings.gateway.notConnected")}),c.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:e("settings.gateway.notConnectedHint")})]})]}):t?c.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-3",children:[c.jsx(Oi,{label:e("settings.gateway.version"),value:t.version??"—"}),c.jsx(Oi,{label:e("settings.gateway.port"),value:t.port!=null?String(t.port):"—"}),c.jsx(Oi,{label:e("settings.gateway.uptime"),value:t.uptime!=null?e("settings.gateway.uptimeFormat",{hours:o,minutes:u}):"—"}),c.jsx(Oi,{label:e("settings.gateway.mode"),value:t.mode??"—"}),c.jsx(Oi,{label:e("settings.gateway.nodeVersion"),value:t.nodeVersion??"—"}),c.jsx(Oi,{label:e("settings.gateway.platform"),value:t.platform??"—"})]}):null]})}function Oi({label:e,value:t}){return c.jsxs("div",{className:"rounded-md bg-gray-50 px-3 py-2 dark:bg-gray-700/50",children:[c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:e}),c.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:t})]})}function Z9({model:e,onChange:t,onRemove:n,defaultCollapsed:r=!1}){var k,j,N;const{t:s}=se("console"),[o,u]=S.useState(r),[f,h]=S.useState(!1),g=C=>t({...e,...C}),y=(C,E)=>{const R=e.cost??{input:0,output:0,cacheRead:0,cacheWrite:0};t({...e,cost:{...R,[C]:E}})},p=C=>{const E=e.input??["text"],R=E.includes(C)?E.filter(H=>H!==C):[...E,C];R.length!==0&&g({input:R})},b=C=>{t({...e,compat:{...e.compat??{},...C}})},v=e.name||e.id||s("settings.providers.models.untitled");return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50/50 dark:border-gray-600 dark:bg-gray-700/30",children:[c.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[c.jsxs("button",{type:"button",onClick:()=>u(!o),className:"flex items-center gap-2 text-sm font-medium text-gray-800 dark:text-gray-200",children:[o?c.jsx(qn,{className:"h-4 w-4"}):c.jsx(wg,{className:"h-4 w-4"}),c.jsx("span",{className:"truncate max-w-xs",children:v}),e.reasoning&&c.jsx("span",{title:"reasoning",children:c.jsx(Mc,{className:"h-3.5 w-3.5 text-purple-500"})}),((k=e.input)==null?void 0:k.includes("image"))&&c.jsx("span",{title:"image",children:c.jsx(_c,{className:"h-3.5 w-3.5 text-green-500"})})]}),c.jsx("button",{type:"button",onClick:n,className:"rounded p-1 text-gray-400 hover:bg-red-100 hover:text-red-500 dark:hover:bg-red-900/30 transition-colors",title:s("settings.providers.models.remove"),children:c.jsx(Dl,{className:"h-4 w-4"})})]}),!o&&c.jsxs("div",{className:"space-y-4 border-t border-gray-200 px-4 py-4 dark:border-gray-600",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsx(Yn,{label:s("settings.providers.models.id"),children:c.jsx("input",{type:"text",value:e.id,onChange:C=>g({id:C.target.value}),className:tl,placeholder:"gpt-4o"})}),c.jsx(Yn,{label:s("settings.providers.models.name"),children:c.jsx("input",{type:"text",value:e.name,onChange:C=>g({name:C.target.value}),className:tl,placeholder:"GPT-4o"})})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsx(Yn,{label:s("settings.providers.models.reasoning"),children:c.jsx(Gv,{active:e.reasoning===!0,onClick:()=>g({reasoning:!e.reasoning}),icon:c.jsx(Mc,{className:"h-4 w-4"}),label:e.reasoning?s("settings.providers.models.yes"):s("settings.providers.models.no")})}),c.jsx(Yn,{label:s("settings.providers.models.inputTypes"),children:c.jsx("div",{className:"flex gap-2",children:F9.map(C=>c.jsx(Gv,{active:(e.input??["text"]).includes(C),onClick:()=>p(C),icon:C==="text"?c.jsx(s3,{className:"h-4 w-4"}):c.jsx(_c,{className:"h-4 w-4"}),label:s(`settings.providers.models.input_${C}`)},C))})})]}),c.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[c.jsx(Yn,{label:s("settings.providers.models.apiOverride"),children:c.jsxs("div",{className:"relative",children:[c.jsxs("select",{value:e.api??"",onChange:C=>g({api:C.target.value?C.target.value:void 0}),className:_h,"aria-label":s("settings.providers.models.apiOverride"),children:[c.jsx("option",{value:"",children:s("settings.providers.models.inheritProvider")}),rm.map(C=>c.jsx("option",{value:C,children:C},C))]}),c.jsx(Lh,{})]})}),c.jsx(Yn,{label:s("settings.providers.models.contextWindow"),children:c.jsx("input",{type:"number",value:e.contextWindow??"",onChange:C=>g({contextWindow:C.target.value?Number(C.target.value):void 0}),className:tl,placeholder:"128000",min:1})}),c.jsx(Yn,{label:s("settings.providers.models.maxTokens"),children:c.jsx("input",{type:"number",value:e.maxTokens??"",onChange:C=>g({maxTokens:C.target.value?Number(C.target.value):void 0}),className:tl,placeholder:"8192",min:1})})]}),c.jsxs(Yn,{label:s("settings.providers.models.cost"),children:[c.jsx("p",{className:"mb-2 text-xs text-gray-500 dark:text-gray-400",children:s("settings.providers.models.costHint")}),c.jsx("div",{className:"grid grid-cols-4 gap-3",children:["input","output","cacheRead","cacheWrite"].map(C=>{var E;return c.jsxs("div",{children:[c.jsx("label",{className:"mb-1 block text-xs text-gray-500 dark:text-gray-400",children:s(`settings.providers.models.cost_${C}`)}),c.jsx("input",{type:"number",value:((E=e.cost)==null?void 0:E[C])??"",onChange:R=>y(C,R.target.value?Number(R.target.value):0),className:tl,placeholder:"0",min:0,step:"0.01"})]},C)})})]}),c.jsxs("div",{children:[c.jsxs("button",{type:"button",onClick:()=>h(!f),className:"flex items-center gap-1 text-xs text-blue-600 hover:underline dark:text-blue-400",children:[c.jsx(I1,{className:"h-3 w-3"}),s(f?"settings.providers.models.hideAdvanced":"settings.providers.models.showAdvanced")]}),f&&c.jsxs("div",{className:"mt-3 space-y-3 rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-600 dark:bg-gray-800",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsx(Yn,{label:s("settings.providers.models.thinkingFormat"),children:c.jsxs("div",{className:"relative",children:[c.jsxs("select",{value:((j=e.compat)==null?void 0:j.thinkingFormat)??"",onChange:C=>b({thinkingFormat:C.target.value?C.target.value:void 0}),className:_h,"aria-label":s("settings.providers.models.thinkingFormat"),children:[c.jsx("option",{value:"",children:s("settings.providers.models.default")}),G9.map(C=>c.jsx("option",{value:C,children:C},C))]}),c.jsx(Lh,{})]})}),c.jsx(Yn,{label:s("settings.providers.models.maxTokensField"),children:c.jsxs("div",{className:"relative",children:[c.jsxs("select",{value:((N=e.compat)==null?void 0:N.maxTokensField)??"",onChange:C=>b({maxTokensField:C.target.value?C.target.value:void 0}),className:_h,"aria-label":s("settings.providers.models.maxTokensField"),children:[c.jsx("option",{value:"",children:s("settings.providers.models.default")}),V9.map(C=>c.jsx("option",{value:C,children:C},C))]}),c.jsx(Lh,{})]})})]}),c.jsx("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2",children:["supportsStore","supportsDeveloperRole","supportsReasoningEffort","supportsUsageInStreaming","supportsStrictMode","requiresToolResultName","requiresAssistantAfterToolResult","requiresThinkingAsText","requiresMistralToolIds"].map(C=>{var E;return c.jsxs("label",{className:"flex items-center gap-2 text-xs text-gray-700 dark:text-gray-300",children:[c.jsx("input",{type:"checkbox",checked:((E=e.compat)==null?void 0:E[C])===!0,onChange:R=>b({[C]:R.target.checked||void 0}),className:"rounded border-gray-300 text-blue-600 focus:ring-blue-500"}),s(`settings.providers.models.compat_${C}`)]},C)})})]})]})]})]})}function _w({models:e,onChange:t}){const{t:n}=se("console"),r=()=>{t([...e,Y9()])},s=(u,f)=>{const h=[...e];h[u]=f,t(h)},o=u=>{t(e.filter((f,h)=>h!==u))};return c.jsxs("div",{children:[c.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[c.jsxs("h4",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[n("settings.providers.models.title")," (",e.length,")"]}),c.jsxs("button",{type:"button",onClick:r,className:"flex items-center gap-1 rounded-lg border border-dashed border-gray-300 px-3 py-1.5 text-xs text-gray-600 hover:border-blue-400 hover:text-blue-600 dark:border-gray-500 dark:text-gray-400 dark:hover:border-blue-400 dark:hover:text-blue-400 transition-colors",children:[c.jsx(En,{className:"h-3.5 w-3.5"}),n("settings.providers.models.add")]})]}),e.length===0?c.jsx("div",{className:"rounded-lg border border-dashed border-gray-300 px-4 py-6 text-center text-sm text-gray-400 dark:border-gray-600",children:n("settings.providers.models.empty")}):c.jsx("div",{className:"space-y-2",children:e.map((u,f)=>c.jsx(Z9,{model:u,onChange:h=>s(f,h),onRemove:()=>o(f),defaultCollapsed:u.id.length>0},f))})]})}const tl="w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors",_h="w-full appearance-none rounded-lg border border-gray-300 bg-white px-3 py-2 pr-8 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors";function Lh(){return c.jsx(qn,{className:"pointer-events-none absolute right-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"})}function Yn({label:e,children:t}){return c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-xs font-medium text-gray-600 dark:text-gray-400",children:e}),t]})}function Gv({active:e,onClick:t,icon:n,label:r}){return c.jsxs("button",{type:"button",onClick:t,className:`flex items-center gap-1.5 rounded-lg border px-3 py-2 text-xs font-medium transition-colors ${e?"border-blue-500 bg-blue-50 text-blue-700 dark:border-blue-400 dark:bg-blue-900/30 dark:text-blue-300":"border-gray-300 bg-white text-gray-500 hover:border-gray-400 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-400"}`,children:[n,r]})}function J9({open:e,existingIds:t,onSave:n,onCancel:r}){const{t:s}=se("console"),o=S.useRef(null),[u,f]=S.useState(1),[h,g]=S.useState(null),[y,p]=S.useState(""),[b,v]=S.useState(""),[k,j]=S.useState(""),[N,C]=S.useState("openai-completions"),[E,R]=S.useState(!1),[H,z]=S.useState([]);S.useEffect(()=>{const M=o.current;M&&(e&&!M.open?(M.showModal(),f(1),g(null),p(""),v(""),j(""),C("openai-completions"),R(!1),z([])):!e&&M.open&&M.close())},[e]);const L=M=>{g(M),p(M.id==="custom"?"":M.id),v(M.defaultBaseUrl),C(M.defaultApi),f(2)},G=t.includes(y),W=y.length>0&&!G,P=M=>{if(!W)return;const $={baseUrl:b,api:N,models:H.filter(V=>V.id.length>0).map(Ow)};k&&($.apiKey=k),n(y,$,M)};return c.jsx("dialog",{ref:o,onClose:r,className:"fixed inset-0 z-50 m-auto w-[92vw] max-w-3xl max-h-[90vh] overflow-y-auto rounded-xl border border-gray-200 bg-white p-0 shadow-2xl backdrop:bg-black/50 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-8",children:[u===1&&c.jsxs("div",{children:[c.jsx("h3",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:s("settings.providers.addDialog.title")}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:s("settings.providers.addDialog.selectType")}),c.jsx("div",{className:"mt-6 grid grid-cols-3 gap-3 sm:grid-cols-4",children:Xt.map(M=>c.jsxs("button",{type:"button",onClick:()=>L(M),className:"flex flex-col items-center gap-2 rounded-xl border border-gray-200 px-4 py-5 text-center hover:border-blue-400 hover:bg-blue-50/80 dark:border-gray-600 dark:hover:border-blue-500 dark:hover:bg-blue-900/20 transition-all",children:[c.jsx("span",{className:"text-2xl",children:M.icon}),c.jsx("span",{className:"text-sm font-medium text-gray-800 dark:text-gray-200",children:M.name})]},M.id))}),c.jsx("div",{className:"mt-6 flex justify-end",children:c.jsx("button",{type:"button",onClick:r,className:"rounded-lg border border-gray-300 px-5 py-2.5 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:s("settings.providers.addDialog.cancel")})})]}),u===2&&h&&c.jsxs("div",{children:[c.jsxs("div",{className:"mb-6 flex items-center gap-3",children:[c.jsx("button",{type:"button",onClick:()=>f(1),className:"rounded-lg p-2 text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors",children:c.jsx(E1,{className:"h-5 w-5"})}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-2xl",children:h.icon}),c.jsxs("h3",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:[s("settings.providers.addDialog.title")," — ",h.name]})]})]}),c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:s("settings.providers.addDialog.providerId")}),c.jsx("input",{type:"text",value:y,onChange:M=>p(M.target.value.replace(/\s/g,"-").toLowerCase()),className:zh,placeholder:h.id}),c.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:s("settings.providers.addDialog.providerIdHint")}),G&&c.jsx("p",{className:"mt-1 text-xs text-red-500",children:s("settings.providers.addDialog.idConflict")})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:s("settings.providers.addDialog.apiType")}),c.jsxs("div",{className:"relative",children:[c.jsx("select",{value:N,onChange:M=>C(M.target.value),className:e7,children:rm.map(M=>c.jsx("option",{value:M,children:M},M))}),c.jsx(qn,{className:"pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"})]})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:s("settings.providers.addDialog.baseUrl")}),c.jsx("input",{type:"text",value:b,onChange:M=>v(M.target.value),className:zh,placeholder:"https://api.example.com/v1"})]}),h.requiresApiKey&&c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:s("settings.providers.addDialog.apiKey")}),c.jsxs("div",{className:"relative",children:[c.jsx("input",{type:E?"text":"password",value:k,onChange:M=>j(M.target.value),className:`${zh} pr-11`,placeholder:h.placeholder??"sk-..."}),c.jsx("button",{type:"button",onClick:()=>R(!E),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors",children:E?c.jsx(nu,{className:"h-4 w-4"}):c.jsx(au,{className:"h-4 w-4"})})]})]}),c.jsx("hr",{className:"border-gray-200 dark:border-gray-600"}),c.jsx(_w,{models:H,onChange:z})]}),c.jsxs("div",{className:"mt-8 flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:r,className:"rounded-lg border border-gray-300 px-5 py-2.5 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:s("settings.providers.addDialog.cancel")}),c.jsx("button",{type:"button",onClick:()=>P("save"),disabled:!W,className:"rounded-lg bg-blue-600 px-5 py-2.5 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:s("settings.providers.addDialog.save")}),c.jsx("button",{type:"button",onClick:()=>P("apply"),disabled:!W,className:"rounded-lg border border-blue-200 px-5 py-2.5 text-sm font-medium text-blue-700 hover:bg-blue-50 disabled:opacity-50 disabled:cursor-not-allowed transition-colors dark:border-blue-800 dark:text-blue-300 dark:hover:bg-blue-900/20",children:s("settings.providers.addDialog.saveAndRestart")})]})]})]})})}const zh="w-full rounded-lg border border-gray-300 bg-white px-4 py-2.5 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors",e7="w-full appearance-none rounded-lg border border-gray-300 bg-white px-4 py-2.5 pr-10 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors";function t7({providerId:e,models:t}){const{t:n}=se("console"),r=im(e),s=t.filter(u=>u.reasoning===!0).length,o=t.filter(u=>{var f;return(f=u.input)==null?void 0:f.includes("image")}).length;return c.jsx("div",{className:"rounded-lg border border-dashed border-emerald-300 bg-emerald-50/50 px-4 py-3 dark:border-emerald-700 dark:bg-emerald-900/10",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[c.jsx("span",{className:"text-xl",title:r.name,children:r.icon}),c.jsxs("div",{className:"min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 truncate",children:e}),r.id!==e&&c.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["(",r.name,")"]}),c.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-emerald-100 px-2 py-0.5 text-xs font-medium text-emerald-700 dark:bg-emerald-800/40 dark:text-emerald-300",children:[c.jsx(F4,{className:"h-3 w-3"}),n("settings.providers.systemDiscovered")]})]}),c.jsx("div",{className:"mt-0.5 flex flex-wrap gap-1.5",children:t.map(u=>c.jsx("span",{className:"inline-block rounded bg-gray-100 px-1.5 py-0.5 text-xs text-gray-600 dark:bg-gray-700 dark:text-gray-300",title:`${e}/${u.id}`,children:u.name||u.id},u.id))})]})]}),c.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[t.length>0&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:n("settings.providers.modelCount",{count:t.length})}),s>0&&c.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-purple-600 dark:text-purple-400",title:n("settings.providers.models.reasoning"),children:[c.jsx(Mc,{className:"h-3 w-3"}),s]}),o>0&&c.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-green-600 dark:text-green-400",title:n("settings.providers.models.input_image"),children:[c.jsx(_c,{className:"h-3 w-3"}),o]})]}),c.jsx("span",{className:"flex items-center gap-1 text-xs text-emerald-600 dark:text-emerald-400",children:r.requiresApiKey?"OAuth":n("settings.providers.apiKeyConfigured")})]})]})})}function n7({open:e,providerId:t,config:n,onSave:r,onCancel:s}){const{t:o}=se("console"),u=S.useRef(null),f=im(t,n.api,n.baseUrl),[h,g]=S.useState(String(n.baseUrl??"")),[y,p]=S.useState(""),[b,v]=S.useState(n.api??"openai-completions"),[k,j]=S.useState(!1),[N,C]=S.useState(()=>Q9(n.models));S.useEffect(()=>{const z=u.current;z&&(e&&!z.open?z.showModal():!e&&z.open&&z.close())},[e]);const E=z=>{const L={baseUrl:h,api:b,models:N.filter(G=>G.id.length>0).map(Ow)};y.length>0&&(L.apiKey=y),r(L,z)},H=typeof n.auth=="string"&&n.auth.length>0||n.apiKey===sm||typeof n.apiKey=="string"&&n.apiKey.length>0;return c.jsx("dialog",{ref:u,onClose:s,className:"fixed inset-0 z-50 m-auto w-[92vw] max-w-3xl max-h-[90vh] overflow-y-auto rounded-xl border border-gray-200 bg-white p-0 shadow-2xl backdrop:bg-black/50 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-8",children:[c.jsxs("div",{className:"mb-6 flex items-center gap-3",children:[c.jsx("span",{className:"text-2xl",children:f.icon}),c.jsxs("div",{children:[c.jsxs("h3",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:[o("settings.providers.editDialog.title")," — ",t]}),f.id!==t&&c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:f.name})]})]}),c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:o("settings.providers.addDialog.apiType")}),c.jsxs("div",{className:"relative",children:[c.jsx("select",{value:b,onChange:z=>v(z.target.value),className:a7,children:rm.map(z=>c.jsx("option",{value:z,children:z},z))}),c.jsx(qn,{className:"pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:o("settings.providers.addDialog.baseUrl")}),c.jsx("input",{type:"text",value:h,onChange:z=>g(z.target.value),className:Vv})]})]}),f.requiresApiKey&&c.jsxs("div",{children:[c.jsx("label",{className:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300",children:o("settings.providers.addDialog.apiKey")}),c.jsxs("div",{className:"relative",children:[c.jsx("input",{type:k?"text":"password",value:y,onChange:z=>p(z.target.value),className:`${Vv} pr-11`,placeholder:H?o("settings.providers.editDialog.apiKeyPlaceholder"):f.placeholder}),c.jsx("button",{type:"button",onClick:()=>j(!k),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors",children:k?c.jsx(nu,{className:"h-4 w-4"}):c.jsx(au,{className:"h-4 w-4"})})]}),H&&!y&&c.jsx("p",{className:"mt-1 text-xs text-green-600 dark:text-green-400",children:o("settings.providers.apiKeyConfigured")})]}),c.jsx("hr",{className:"border-gray-200 dark:border-gray-600"}),c.jsx(_w,{models:N,onChange:C})]}),c.jsxs("div",{className:"mt-8 flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:s,className:"rounded-lg border border-gray-300 px-5 py-2.5 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:o("settings.providers.editDialog.cancel")}),c.jsx("button",{type:"button",onClick:()=>E("save"),className:"rounded-lg bg-blue-600 px-5 py-2.5 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:o("settings.providers.editDialog.save")}),c.jsx("button",{type:"button",onClick:()=>E("apply"),className:"rounded-lg border border-blue-200 px-5 py-2.5 text-sm font-medium text-blue-700 hover:bg-blue-50 transition-colors dark:border-blue-800 dark:text-blue-300 dark:hover:bg-blue-900/20",children:o("settings.providers.editDialog.saveAndRestart")})]})]})})}const Vv="w-full rounded-lg border border-gray-300 bg-white px-4 py-2.5 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors",a7="w-full appearance-none rounded-lg border border-gray-300 bg-white px-4 py-2.5 pr-10 text-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 transition-colors";function r7({providerId:e,config:t,onEdit:n,onDelete:r}){const{t:s}=se("console"),o=im(e,t.api,t.baseUrl),f=typeof t.auth=="string"&&t.auth.length>0||t.apiKey===sm||typeof t.apiKey=="string"&&t.apiKey.length>0,h=Array.isArray(t.models)?t.models:[],g=h.filter(p=>p.reasoning===!0).length,y=h.filter(p=>Array.isArray(p.input)&&p.input.includes("image")).length;return c.jsx("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-4 py-3 dark:border-gray-600 dark:bg-gray-700/50",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[c.jsx("span",{className:"text-xl",title:o.name,children:o.icon}),c.jsxs("div",{className:"min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100 truncate",children:e}),o.id!==e&&c.jsxs("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["(",o.name,")"]})]}),c.jsxs("div",{className:"flex items-center gap-3 text-xs text-gray-500 dark:text-gray-400",children:[typeof t.baseUrl=="string"&&t.baseUrl&&c.jsx("span",{className:"truncate max-w-48",title:t.baseUrl,children:t.baseUrl}),typeof t.api=="string"&&c.jsx("span",{children:t.api})]})]})]}),c.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[h.length>0&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:s("settings.providers.modelCount",{count:h.length})}),g>0&&c.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-purple-600 dark:text-purple-400",title:s("settings.providers.models.reasoning"),children:[c.jsx(Mc,{className:"h-3 w-3"}),g]}),y>0&&c.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-green-600 dark:text-green-400",title:s("settings.providers.models.input_image"),children:[c.jsx(_c,{className:"h-3 w-3"}),y]})]}),o.requiresApiKey&&c.jsx("span",{className:"flex items-center gap-1 text-xs",children:f?c.jsxs(c.Fragment,{children:[c.jsx(qi,{className:"h-3.5 w-3.5 text-green-500"}),c.jsx("span",{className:"text-green-600 dark:text-green-400",children:s("settings.providers.apiKeyConfigured")})]}):c.jsxs(c.Fragment,{children:[c.jsx(tu,{className:"h-3.5 w-3.5 text-amber-500"}),c.jsx("span",{className:"text-amber-600 dark:text-amber-400",children:s("settings.providers.apiKeyNotConfigured")})]})}),c.jsx("button",{type:"button",onClick:n,className:"rounded p-1.5 text-gray-500 hover:bg-gray-200 hover:text-gray-700 dark:hover:bg-gray-600 dark:hover:text-gray-300 transition-colors",title:"Edit",children:c.jsx(M1,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:r,className:"rounded p-1.5 text-gray-500 hover:bg-red-100 hover:text-red-600 dark:hover:bg-red-900/30 dark:hover:text-red-400 transition-colors",title:"Delete",children:c.jsx(Dl,{className:"h-4 w-4"})})]})]})})}function i7(e){if(!e)return{};const t=e.models;return(t==null?void 0:t.providers)??{}}function s7(e,t){const n=new Map;for(const r of e)t.has(r.provider)||(n.has(r.provider)||n.set(r.provider,[]),n.get(r.provider).push(r));return n}function l7(){const{t:e}=se("console"),t=Ee(H=>H.config),n=Ee(H=>H.saveConfig),r=Ee(H=>H.applyConfig),s=Ee(H=>H.catalogModels),o=Ee(H=>H.fetchCatalogModels),[u,f]=S.useState(!1),[h,g]=S.useState(null),[y,p]=S.useState(null);S.useEffect(()=>{s.length===0&&o()},[s.length,o]);const b=i7(t),v=Object.entries(b),k=new Set(Object.keys(b)),j=s7(s,k),N=async(H,z,L)=>{await(L==="apply"?r:n)(W=>{const P=W,M=P.models??{},$=M.providers??{};return P.models={...M,providers:{...$,[H]:z}},P}),f(!1)},C=async(H,z)=>{if(!h)return;await(z==="apply"?r:n)(G=>{const W=G,P=W.models??{},M=P.providers??{};return W.models={...P,providers:{...M,[h.id]:H}},W}),g(null)},E=async()=>{y&&(await n(H=>{const z=H,L=z.models??{},G={...L.providers??{}};return delete G[y],z.models={...L,providers:G},z}),p(null))},R=v.length>0||j.size>0;return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("h3",{className:"text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.providers.title")}),c.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:e("settings.providers.description")})]}),c.jsxs("button",{type:"button",onClick:()=>f(!0),className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:[c.jsx(En,{className:"h-4 w-4"}),e("settings.providers.add")]})]}),R?c.jsxs("div",{className:"space-y-2",children:[v.map(([H,z])=>c.jsx(r7,{providerId:H,config:z,onEdit:()=>g({id:H,config:z}),onDelete:()=>p(H)},H)),Array.from(j.entries()).map(([H,z])=>c.jsx(t7,{providerId:H,models:z},`catalog-${H}`))]}):c.jsx(Er,{icon:UA,title:e("settings.providers.empty"),description:e("settings.providers.emptyHint")}),c.jsx(J9,{open:u,existingIds:Object.keys(b),onSave:N,onCancel:()=>f(!1)}),h&&c.jsx(n7,{open:!!h,providerId:h.id,config:h.config,onSave:C,onCancel:()=>g(null)},h.id),c.jsx(jl,{open:!!y,title:e("settings.providers.deleteTitle"),description:e("settings.providers.deleteDescription",{name:y??""}),variant:"danger",onConfirm:E,onCancel:()=>p(null)})]})}function o7(){var y;const{t:e}=se("console"),t=Ee(p=>p.status),n=Ee(p=>p.config),r=Ee(p=>p.updateResult),s=Ee(p=>p.updateLoading),o=Ee(p=>p.runUpdate),[u,f]=S.useState(!1),h=(y=n==null?void 0:n.update)==null?void 0:y.channel,g=async()=>{f(!1),await o({restartDelayMs:3e3})};return c.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white p-6 dark:border-gray-700 dark:bg-gray-800",children:[c.jsx("h3",{className:"mb-4 text-base font-semibold text-gray-900 dark:text-gray-100",children:e("settings.update.title")}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:e("settings.update.currentVersion")}),c.jsx("span",{className:"text-sm font-mono font-medium text-gray-900 dark:text-gray-100",children:(t==null?void 0:t.version)??"—"})]}),h&&c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:e("settings.update.channel")}),c.jsx("span",{className:"rounded-full bg-gray-100 px-2.5 py-0.5 text-xs font-medium text-gray-700 dark:bg-gray-700 dark:text-gray-300",children:h})]}),c.jsx("div",{className:"pt-2",children:c.jsx("button",{type:"button",onClick:()=>f(!0),disabled:s,className:"flex items-center gap-2 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50 transition-colors",children:s?c.jsxs(c.Fragment,{children:[c.jsx(Mt,{className:"h-4 w-4 animate-spin"}),e("settings.update.updating")]}):c.jsxs(c.Fragment,{children:[c.jsx(pl,{className:"h-4 w-4"}),e("settings.update.checkUpdate")]})})}),r&&c.jsxs("div",{className:`mt-3 flex items-start gap-2 rounded-lg px-4 py-3 text-sm ${r.result.status==="ok"?"bg-green-50 text-green-800 dark:bg-green-900/20 dark:text-green-300":r.result.status==="noop"?"bg-blue-50 text-blue-800 dark:bg-blue-900/20 dark:text-blue-300":"bg-red-50 text-red-800 dark:bg-red-900/20 dark:text-red-300"}`,children:[r.result.status==="ok"&&c.jsx(qi,{className:"mt-0.5 h-4 w-4 shrink-0"}),r.result.status==="noop"&&c.jsx(ru,{className:"mt-0.5 h-4 w-4 shrink-0"}),r.result.status==="error"&&c.jsx(Pi,{className:"mt-0.5 h-4 w-4 shrink-0"}),c.jsxs("span",{children:[r.result.status==="ok"&&e("settings.update.resultOk",{before:r.result.before??"?",after:r.result.after??"?"}),r.result.status==="noop"&&e("settings.update.resultNoop"),r.result.status==="error"&&e("settings.update.resultError",{reason:r.result.reason??"Unknown error"})]})]})]}),c.jsx(jl,{open:u,title:e("settings.update.confirmTitle"),description:e("settings.update.confirmDescription"),onConfirm:g,onCancel:()=>f(!1)})]})}function c7(){const{t:e}=se("console"),t=Ee(o=>o.loading),n=Ee(o=>o.fetchConfig),r=Ee(o=>o.fetchStatus),s=Cl(o=>o.devModeUnlocked);return S.useEffect(()=>{n(),r()},[n,r]),c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e("settings.title")}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:e("settings.description")})]}),t?c.jsx(zl,{}):c.jsxs("div",{className:"space-y-4",children:[c.jsx(P9,{}),c.jsx(l7,{}),c.jsx(X9,{}),c.jsx(o7,{}),c.jsx(U9,{}),s&&c.jsx(W9,{}),c.jsx(H9,{})]})]})}class er extends Error{constructor(t,n){super(n),this.code=t,this.name="ClawHubError"}}const gg=new Map;function Lw(e){const t=gg.get(e);return t?Date.now()>t.expiresAt?(gg.delete(e),null):t.data:null}function zw(e,t,n){gg.set(e,{data:t,expiresAt:Date.now()+n})}let Iw=0;function u7(){return Date.now()<Iw}const d7=6e4,f7=3e5,h7=5e3;function g7(){return"https://clawhub.ai"}async function lm(e,t){if(u7())throw new er(429,"Rate limited, please wait before retrying");const n=new URL(e,g7());if(t)for(const[s,o]of Object.entries(t))o!==void 0&&o!==""&&n.searchParams.set(s,o);let r;try{r=await fetch(n.toString())}catch(s){throw new er(0,`Network error: ${s instanceof Error?s.message:String(s)}`)}if(r.status===429)throw Iw=Date.now()+h7,new er(429,"Search service is busy, please try again later");if(!r.ok){const s=await r.text().catch(()=>"");throw new er(r.status,s||`HTTP ${r.status}`)}return r.json()}async function m7(e,t=20){return(await lm("/api/v1/search",{q:e,limit:String(t)})).results??[]}async function p7(e){const t=e==null?void 0:e.limit,n=e==null?void 0:e.cursor,r=`explore:${t}:${n??""}`,s=Lw(r);if(s)return s;const o={limit:String(t)};n&&(o.cursor=n);const u=await lm("/api/v1/skills",o),f={items:u.items??[],nextCursor:u.nextCursor??null};return zw(r,f,d7),f}async function y7(e){const t=`detail:${e}`,n=Lw(t);if(n)return n;const r=await lm(`/api/v1/skills/${encodeURIComponent(e)}`);return zw(t,r,f7),r}let ba=null;const sl=Mn((e,t)=>({searchResults:[],exploreItems:[],searchQuery:"",isSearching:!1,isExploring:!1,searchError:null,exploreError:null,nextCursor:null,selectedDetail:null,detailLoading:!1,offlineMode:!1,search:async n=>{if(e({searchQuery:n}),!n.trim()){e({searchResults:[],searchError:null});return}ba&&clearTimeout(ba),ba=setTimeout(()=>{t().searchImmediate(n)},300)},searchImmediate:async n=>{ba&&(clearTimeout(ba),ba=null);const r=n.trim();if(r){e({isSearching:!0,searchError:null,searchQuery:r});try{const s=await m7(r,30);e({searchResults:s,isSearching:!1,offlineMode:!1})}catch(s){const o=s instanceof er?s.message:String(s),u=s instanceof er&&s.code===0;e({searchError:o,isSearching:!1,offlineMode:u})}}},explore:async(n=!1)=>{const r=t();if(!r.isExploring&&!(n&&!r.nextCursor)){e({isExploring:!0,exploreError:null});try{const s=n?r.nextCursor??void 0:void 0,o=await p7({limit:20,cursor:s});e(u=>({exploreItems:n?[...u.exploreItems,...o.items]:o.items,nextCursor:o.nextCursor,isExploring:!1,offlineMode:!1}))}catch(s){const o=s instanceof er?s.message:String(s),u=s instanceof er&&s.code===0;e({exploreError:o,isExploring:!1,offlineMode:u})}}},fetchDetail:async n=>{e({detailLoading:!0});try{const r=await y7(n);e({selectedDetail:r,detailLoading:!1})}catch{e({detailLoading:!1})}},clearSearch:()=>{ba&&(clearTimeout(ba),ba=null),e({searchQuery:"",searchResults:[],searchError:null})},clearDetail:()=>e({selectedDetail:null}),setOfflineMode:n=>e({offlineMode:n})}));function x7({slug:e,onClose:t,onInstall:n,isInstalled:r}){const{t:s}=se("console"),o=sl(b=>b.fetchDetail),u=sl(b=>b.selectedDetail),f=sl(b=>b.detailLoading),h=sl(b=>b.clearDetail);if(S.useEffect(()=>(e&&o(e),()=>{h()}),[e,o,h]),!e)return null;const g=u==null?void 0:u.skill,y=u==null?void 0:u.latestVersion,p=u==null?void 0:u.owner;return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:t,children:c.jsxs("div",{className:"relative mx-4 w-full max-w-lg rounded-2xl border border-gray-200 bg-white shadow-2xl dark:border-gray-700 dark:bg-gray-900",onClick:b=>b.stopPropagation(),children:[c.jsx("button",{type:"button",onClick:t,className:"absolute right-3 top-3 rounded-lg p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",children:c.jsx(An,{className:"h-5 w-5"})}),f?c.jsx("div",{className:"flex h-48 items-center justify-center",children:c.jsx(Mt,{className:"h-6 w-6 animate-spin text-gray-400"})}):g?c.jsxs("div",{className:"p-6",children:[c.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-gray-100",children:g.displayName}),g.summary&&c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:g.summary}),p&&p.handle&&c.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[p.image?c.jsx("img",{src:p.image,alt:"",className:"h-6 w-6 rounded-full"}):c.jsx(o3,{className:"h-5 w-5 text-gray-400"}),c.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-300",children:p.displayName??p.handle})]}),c.jsxs("div",{className:"mt-4 flex flex-wrap gap-4 text-sm text-gray-500 dark:text-gray-400",children:[g.stats.downloads>0&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(pl,{className:"h-4 w-4"}),g.stats.downloads.toLocaleString()," ",s("clawhub.downloads")]}),g.stats.stars>0&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(L1,{className:"h-4 w-4"}),g.stats.stars," ",s("clawhub.stars")]})]}),y&&c.jsxs("div",{className:"mt-4 rounded-xl border border-gray-100 bg-gray-50 p-3 dark:border-gray-700 dark:bg-gray-800",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("span",{className:"text-xs font-medium text-gray-600 dark:text-gray-300",children:["v",y.version]}),c.jsx("span",{className:"text-xs text-gray-400",children:new Date(y.createdAt).toLocaleDateString()})]}),y.changelog&&c.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400 line-clamp-3",children:y.changelog})]}),c.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[r?c.jsx("span",{className:"inline-flex items-center gap-1.5 rounded-lg bg-green-100 px-4 py-2 text-sm font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:s("skills.marketplace.installed")}):c.jsxs("button",{type:"button",onClick:()=>n(g.slug,g.displayName),className:"inline-flex items-center gap-1.5 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 transition-colors",children:[c.jsx(pl,{className:"h-4 w-4"}),s("skills.card.install")]}),c.jsxs("a",{href:`https://clawhub.ai/skills/${g.slug}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-sm text-blue-600 hover:underline dark:text-blue-400",children:[c.jsx(Oc,{className:"h-3.5 w-3.5"}),s("clawhub.viewOnClawHub")]})]})]}):c.jsx("div",{className:"flex h-48 items-center justify-center text-sm text-gray-500",children:s("clawhub.notFound")})]})})}function b7({open:e,slug:t,displayName:n,onClose:r,onConfirmDone:s}){const{t:o}=se("console"),[u,f]=S.useState(!1);if(!e)return null;const h=`clawhub install ${t}`,g=async()=>{await navigator.clipboard.writeText(h),f(!0),setTimeout(()=>f(!1),2e3)};return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:r,children:c.jsxs("div",{className:"relative mx-4 w-full max-w-md rounded-2xl border border-gray-200 bg-white p-6 shadow-2xl dark:border-gray-700 dark:bg-gray-900",onClick:y=>y.stopPropagation(),children:[c.jsx("button",{type:"button",onClick:r,className:"absolute right-3 top-3 rounded-lg p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-800 dark:hover:text-gray-300",children:c.jsx(An,{className:"h-5 w-5"})}),c.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-gray-100",children:o("clawhub.installTitle",{name:n})}),c.jsx("div",{className:"mt-3 rounded-xl border border-yellow-200 bg-yellow-50 p-3 dark:border-yellow-800 dark:bg-yellow-900/20",children:c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsx($4,{className:"mt-0.5 h-4 w-4 shrink-0 text-yellow-600 dark:text-yellow-400"}),c.jsx("p",{className:"text-xs text-yellow-700 dark:text-yellow-300",children:o("clawhub.securityWarning")})]})}),c.jsxs("div",{className:"mt-4",children:[c.jsx("p",{className:"mb-2 text-xs font-medium text-gray-600 dark:text-gray-400",children:o("clawhub.installCommand")}),c.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-gray-900 px-3 py-2 dark:bg-gray-800",children:[c.jsx(z1,{className:"h-4 w-4 shrink-0 text-gray-400"}),c.jsx("code",{className:"flex-1 text-sm text-green-400",children:h}),c.jsx("button",{type:"button",onClick:g,className:"shrink-0 rounded p-1 text-gray-400 hover:bg-gray-700 hover:text-gray-200",children:u?c.jsx(Tr,{className:"h-4 w-4 text-green-400"}):c.jsx(jg,{className:"h-4 w-4"})})]})]}),c.jsxs("div",{className:"mt-5 flex justify-end gap-3",children:[c.jsx("button",{type:"button",onClick:r,className:"rounded-lg border border-gray-300 px-4 py-2 text-sm text-gray-600 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-800",children:o("clawhub.cancel")}),c.jsx("button",{type:"button",onClick:s,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700",children:o("clawhub.installDone")})]})]})})}function Ih(e){return"score"in e}function v7(e){const t=Date.now()-e,n=Math.floor(t/6e4);if(n<60)return`${n}m ago`;const r=Math.floor(n/60);if(r<24)return`${r}h ago`;const s=Math.floor(r/24);return s<30?`${s}d ago`:`${Math.floor(s/30)}mo ago`}function Yv({item:e,isInstalled:t,onInstall:n,onOpenDetail:r}){var b;const{t:s}=se("console"),o=e.slug,u=e.displayName,f=e.summary,h=e.updatedAt,g=Ih(e)?e.version:(b=e.latestVersion)==null?void 0:b.version,y=Ih(e)?e.score:null,p=Ih(e)?null:e.stats;return c.jsxs("div",{className:"group relative flex flex-col justify-between rounded-2xl border border-gray-200 bg-white p-4 transition-all hover:border-blue-300 hover:shadow-md dark:border-gray-700 dark:bg-gray-800/80 dark:hover:border-blue-600",children:[c.jsx("button",{type:"button",onClick:()=>r(o),className:"absolute inset-0 rounded-2xl focus:outline-none","aria-label":u}),c.jsxs("div",{className:"relative z-10 pointer-events-none",children:[c.jsxs("div",{className:"flex items-start justify-between gap-3",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("h3",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100 truncate",children:u}),f&&c.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-gray-500 dark:text-gray-400",children:f})]}),c.jsx("div",{className:"pointer-events-auto shrink-0",children:t?c.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:[c.jsx(qi,{className:"h-3 w-3"}),s("skills.marketplace.installed")]}):c.jsxs("button",{type:"button",onClick:v=>{v.stopPropagation(),n(o,u)},className:"inline-flex items-center gap-1 rounded-lg bg-blue-600 px-2.5 py-1 text-xs font-medium text-white hover:bg-blue-700 transition-colors",children:[c.jsx(pl,{className:"h-3 w-3"}),s("skills.card.install")]})})]}),c.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3 text-xs text-gray-400 dark:text-gray-500",children:[g&&c.jsxs("span",{className:"flex items-center gap-1",children:["v",g]}),h&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(Ki,{className:"h-3 w-3"}),v7(h)]}),y!=null&&c.jsxs("span",{className:"flex items-center gap-1 text-blue-500 dark:text-blue-400",children:[c.jsx(a3,{className:"h-3 w-3"}),y.toFixed(1)]}),p&&p.downloads>0&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(pl,{className:"h-3 w-3"}),p.downloads.toLocaleString()]}),p&&p.stars>0&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(L1,{className:"h-3 w-3"}),p.stars]})]})]})]})}function k7({open:e,skillName:t,options:n,onSelect:r,onCancel:s}){const{t:o}=se("console"),u=S.useRef(null);return S.useEffect(()=>{const f=u.current;f&&(e&&!f.open?f.showModal():!e&&f.open&&f.close())},[e]),c.jsx("dialog",{ref:u,onClose:s,className:"fixed inset-0 z-50 m-auto max-w-sm rounded-lg border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"p-6",children:[c.jsx("h3",{className:"mb-4 text-lg font-semibold text-gray-900 dark:text-gray-100",children:o("skills.install.title",{name:t})}),c.jsx("div",{className:"space-y-2",children:n.map(f=>c.jsxs("button",{type:"button",onClick:()=>r(f.id),className:"flex w-full items-center gap-3 rounded-lg border border-gray-200 p-3 text-left transition-colors hover:border-blue-300 hover:bg-blue-50/50 dark:border-gray-700 dark:hover:border-blue-600 dark:hover:bg-blue-900/10",children:[c.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:f.label}),c.jsxs("span",{className:"text-xs text-gray-400",children:["(",f.kind,")"]})]},f.id))}),c.jsx("div",{className:"mt-4 flex justify-end",children:c.jsx("button",{type:"button",onClick:s,className:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:o("common:actions.cancel")})})]})})}function Qv({skill:e,onToggle:t,onConfigure:n,isInstalling:r,onInstall:s}){var g,y,p,b;const{t:o}=se("console"),u=e.isCore&&e.always,f=((y=(g=e.missing)==null?void 0:g.bins)==null?void 0:y.length)||((b=(p=e.missing)==null?void 0:p.env)==null?void 0:b.length),h=e.isBundled?o("skills.source.builtIn"):o("skills.source.marketplace");return c.jsx("div",{className:`rounded-2xl border p-4 transition-colors dark:bg-gray-800 ${e.enabled?"border-blue-200 bg-blue-50/40 dark:border-blue-900/40":"border-gray-200 bg-white opacity-75 dark:border-gray-700"}`,children:c.jsxs("div",{className:"flex items-start justify-between gap-4",children:[c.jsxs("button",{type:"button",onClick:()=>n(e),className:"flex min-w-0 flex-1 items-start gap-3 text-left",children:[c.jsx("span",{className:"text-2xl",children:e.icon||"📦"}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100",children:e.name}),c.jsx("span",{className:`rounded-md px-2 py-0.5 text-[10px] font-medium ${e.isBundled?"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400"}`,children:h}),e.isCore?c.jsx(D1,{className:"h-3.5 w-3.5 text-gray-400"}):e.isBundled?c.jsx(O1,{className:"h-3.5 w-3.5 text-blue-500/70"}):c.jsx(a4,{className:"h-3.5 w-3.5 text-purple-500/70"}),e.version&&c.jsxs("span",{className:"text-[10px] text-gray-400",children:["v",e.version]})]}),c.jsx("p",{className:"mt-2 line-clamp-2 text-sm text-gray-500 dark:text-gray-400",children:e.description}),f&&c.jsxs("div",{className:"mt-2 flex items-center gap-1 text-xs text-amber-600 dark:text-amber-400",children:[c.jsx(Pi,{className:"h-3.5 w-3.5"}),o("skills.card.missingDeps")]})]})]}),c.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[c.jsx("button",{type:"button",onClick:()=>n(e),className:"rounded p-1.5 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700 dark:hover:text-gray-300 transition-colors",title:o("skills.card.configure"),children:c.jsx(Cg,{className:"h-4 w-4"})}),!e.eligible&&s&&c.jsx("button",{type:"button",onClick:()=>s(e),disabled:r,className:"rounded-xl bg-blue-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-blue-700 disabled:opacity-50 transition-colors",children:o(r?"skills.card.installing":"skills.card.install")}),c.jsxs("label",{className:"relative inline-flex cursor-pointer items-center",title:u?o("skills.card.coreProtected"):void 0,children:[c.jsx("input",{type:"checkbox",checked:e.enabled,onChange:()=>t(e.id,!e.enabled),disabled:u,className:"peer sr-only"}),c.jsx("div",{className:"peer h-5 w-9 rounded-full bg-gray-200 after:absolute after:left-[2px] after:top-[2px] after:h-4 after:w-4 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:bg-blue-600 peer-checked:after:translate-x-full peer-checked:after:border-white peer-disabled:cursor-not-allowed peer-disabled:opacity-50 dark:bg-gray-700 dark:peer-checked:bg-blue-500"})]})]})]})})}function w7({open:e,skill:t,onClose:n,onSaved:r}){var W;const{t:s}=se("console"),o=S.useRef(null),[u,f]=S.useState(""),[h,g]=S.useState(!1),[y,p]=S.useState([]),[b,v]=S.useState("info"),[k,j]=S.useState(!0),[N,C]=S.useState(!1);if(S.useEffect(()=>{const P=o.current;P&&(e&&!P.open?(v("info"),g(!1),P.showModal()):!e&&P.open&&P.close())},[e]),S.useEffect(()=>{var M,$;if(!t)return;f(typeof((M=t.config)==null?void 0:M.apiKey)=="string"?t.config.apiKey:"");const P=($=t.config)==null?void 0:$.env;p(P&&typeof P=="object"?Object.entries(P).map(([V,ae])=>({key:V,value:String(ae)})):[])},[t]),!t)return null;const E=t.primaryEnv||t.configChecks&&t.configChecks.length>0,R=t.isCore&&t.always,H=async()=>{C(!0);try{const P=y.reduce((M,$)=>{const V=$.key.trim();return V&&(M[V]=$.value.trim()),M},{});await Oe().skillsUpdate(t.id,{apiKey:u||void 0,env:Object.keys(P).length>0?P:void 0}),Ee.getState().setRuntimeApplied("configLifecycle.runtimeSkill"),r(),n()}catch{}finally{C(!1)}},z=()=>p(P=>[...P,{key:"",value:""}]),L=P=>{p(M=>M.filter(($,V)=>V!==P))},G=(P,M,$)=>{p(V=>V.map((ae,J)=>J===P?{...ae,[M]:$}:ae))};return c.jsx("dialog",{ref:o,onClose:n,className:"fixed inset-0 z-50 m-auto max-h-[90vh] w-[min(760px,calc(100vw-2rem))] rounded-xl border border-gray-200 bg-white p-0 shadow-xl backdrop:bg-black/40 dark:border-gray-700 dark:bg-gray-800",children:c.jsxs("div",{className:"flex max-h-[90vh] flex-col",children:[c.jsx("div",{className:"border-b border-gray-200 p-6 dark:border-gray-700",children:c.jsxs("div",{className:"flex items-start justify-between gap-4",children:[c.jsxs("div",{className:"flex items-start gap-4",children:[c.jsx("span",{className:"text-3xl",children:t.icon||"📦"}),c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("h3",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:t.name}),R&&c.jsx(D1,{className:"h-4 w-4 text-gray-400"})]}),c.jsxs("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:[t.version||"—"," · ",t.author??"—"]}),c.jsxs("div",{className:"mt-3 flex gap-2",children:[c.jsx("button",{type:"button",onClick:()=>v("info"),className:`rounded-lg px-3 py-1.5 text-sm font-medium ${b==="info"?"bg-gray-900 text-white dark:bg-gray-100 dark:text-gray-900":"bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300"}`,children:s("skills.detail.info")}),c.jsx("button",{type:"button",onClick:()=>v("config"),disabled:!E,className:`rounded-lg px-3 py-1.5 text-sm font-medium ${b==="config"?"bg-gray-900 text-white dark:bg-gray-100 dark:text-gray-900":"bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300"} disabled:cursor-not-allowed disabled:opacity-50`,children:s("skills.detail.config")})]})]})]}),c.jsx("button",{type:"button",onClick:n,className:"rounded-full p-2 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-gray-700",children:c.jsx(An,{className:"h-4 w-4"})})]})}),c.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:b==="info"?c.jsxs("div",{className:"space-y-5",children:[c.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:t.description}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[c.jsx(wc,{label:s("skills.detail.source"),value:t.source??"—"}),c.jsx(wc,{label:s("skills.detail.version"),value:t.version||"—"}),c.jsx(wc,{label:s("skills.detail.author"),value:t.author??"—"}),c.jsx(wc,{label:s("skills.detail.primaryEnv"),value:t.primaryEnv??"—"})]}),t.homepage&&c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[s("skills.detail.homepage"),":"]}),c.jsxs("a",{href:t.homepage,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-blue-600 hover:underline dark:text-blue-400",children:[t.homepage,c.jsx(Oc,{className:"h-3 w-3"})]})]}),t.requirements&&c.jsxs("div",{children:[c.jsx("h4",{className:"mb-2 text-sm font-medium text-gray-700 dark:text-gray-300",children:s("skills.detail.requirements")}),c.jsx("div",{className:"space-y-2",children:(W=t.requirements.bins)==null?void 0:W.map(P=>{var $,V;const M=(V=($=t.missing)==null?void 0:$.bins)==null?void 0:V.includes(P);return c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[M?c.jsx(An,{className:"h-4 w-4 text-red-500"}):c.jsx(Tr,{className:"h-4 w-4 text-green-500"}),c.jsx("code",{className:"text-xs",children:P})]},P)})})]})]}):E?c.jsxs("div",{className:"space-y-5",children:[t.primaryEnv&&c.jsxs("div",{children:[c.jsxs("label",{className:"mb-1 block text-xs text-gray-500 dark:text-gray-400",children:["API Key (",t.primaryEnv,")"]}),c.jsxs("div",{className:"relative",children:[c.jsx("input",{type:h?"text":"password",value:u,onChange:P=>f(P.target.value),placeholder:s("skills.detail.apiKeyPlaceholder"),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 pr-10 text-sm dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100"}),c.jsx("button",{type:"button",onClick:()=>g(!h),className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600",children:h?c.jsx(nu,{className:"h-4 w-4"}):c.jsx(au,{className:"h-4 w-4"})})]})]}),c.jsxs("div",{className:"rounded-xl border border-gray-200 p-4 dark:border-gray-700",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("button",{type:"button",onClick:()=>j(P=>!P),className:"flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300",children:[k?c.jsx(qn,{className:"h-4 w-4"}):c.jsx(FA,{className:"h-4 w-4"}),s("skills.detail.envVars")]}),c.jsxs("button",{type:"button",onClick:z,className:"inline-flex items-center gap-1 rounded-md border border-gray-300 px-2 py-1 text-xs font-medium text-gray-600 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700",children:[c.jsx(En,{className:"h-3 w-3"}),s("skills.detail.addVariable")]})]}),k&&c.jsx("div",{className:"mt-4 space-y-3",children:y.length===0?c.jsx("p",{className:"text-xs italic text-gray-400",children:s("skills.detail.noEnvVars")}):y.map((P,M)=>c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{value:P.key,onChange:$=>G(M,"key",$.target.value),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-xs font-mono dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100",placeholder:s("skills.detail.keyPlaceholder")}),c.jsx("span",{className:"text-gray-400",children:"="}),c.jsx("input",{value:P.value,onChange:$=>G(M,"value",$.target.value),className:"w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-xs font-mono dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100",placeholder:s("skills.detail.valuePlaceholder")}),c.jsx("button",{type:"button",onClick:()=>L(M),className:"rounded-md p-2 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20",children:c.jsx(Dl,{className:"h-4 w-4"})})]},`${P.key}-${M}`))})]}),t.configChecks&&t.configChecks.length>0&&c.jsxs("div",{children:[c.jsx("label",{className:"mb-2 block text-xs text-gray-500 dark:text-gray-400",children:s("skills.detail.configChecks")}),c.jsx("div",{className:"space-y-1",children:t.configChecks.map(P=>c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[P.satisfied?c.jsx(Tr,{className:"h-4 w-4 text-green-500"}):c.jsx(An,{className:"h-4 w-4 text-red-500"}),c.jsx("code",{className:"text-xs",children:P.path})]},P.path))})]}),c.jsx("div",{className:"flex justify-end",children:c.jsx("button",{type:"button",onClick:H,disabled:N,className:"rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-700 disabled:opacity-50 transition-colors",children:s(N?"skills.detail.saving":"common:actions.save")})})]}):c.jsx("p",{className:"text-sm text-gray-400",children:s("skills.detail.noConfig")})}),c.jsxs("div",{className:"flex items-center justify-between border-t border-gray-200 px-6 py-4 dark:border-gray-700",children:[c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[t.enabled?c.jsx(Tr,{className:"h-4 w-4 text-green-500"}):c.jsx(An,{className:"h-4 w-4 text-gray-400"}),c.jsx("span",{className:t.enabled?"text-green-600 dark:text-green-400":"text-gray-500 dark:text-gray-400",children:t.enabled?s("skills.detail.enabled"):s("skills.detail.disabled")})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("button",{type:"button",onClick:n,className:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors",children:s("common:actions.close")}),c.jsxs("label",{className:"relative inline-flex cursor-pointer items-center",title:R?s("skills.card.coreProtected"):void 0,children:[c.jsx("input",{type:"checkbox",checked:t.enabled,onChange:()=>{Oe().skillsUpdate(t.id,{enabled:!t.enabled}).then(()=>{Ee.getState().setRuntimeApplied("configLifecycle.runtimeSkill"),r()})},disabled:R,className:"peer sr-only"}),c.jsx("div",{className:"peer h-5 w-9 rounded-full bg-gray-200 after:absolute after:left-[2px] after:top-[2px] after:h-4 after:w-4 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:bg-blue-600 peer-checked:after:translate-x-full peer-checked:after:border-white peer-disabled:cursor-not-allowed peer-disabled:opacity-50 dark:bg-gray-700 dark:peer-checked:bg-blue-500"})]})]})]})]})})}function wc({label:e,value:t}){return c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("span",{className:"text-gray-500 dark:text-gray-400",children:[e,":"]}),c.jsx("span",{className:"text-gray-900 dark:text-gray-100",children:t})]})}const S7=["installed","marketplace"];function j7({activeTab:e,onTabChange:t}){const{t:n}=se("console");return c.jsx("div",{className:"flex gap-1 rounded-xl bg-gray-100 p-1 dark:bg-gray-800",children:S7.map(r=>c.jsx("button",{type:"button",onClick:()=>t(r),className:`rounded-lg px-5 py-2 text-sm font-semibold transition-colors ${e===r?"bg-white text-gray-900 shadow-sm dark:bg-gray-700 dark:text-gray-100":"text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"}`,children:n(`skills.tabs.${r}`)},r))})}function C7(e,t){return e.enabled&&!t.enabled?-1:!e.enabled&&t.enabled?1:e.isCore&&!t.isCore?-1:!e.isCore&&t.isCore?1:e.name.localeCompare(t.name)}function N7(e){return new Set(e.map(t=>t.id))}function A7(e,t,n){const r=t.trim().toLowerCase();return e.filter(s=>s.isBundled||s.eligible).filter(s=>r?[s.name,s.description,s.slug,s.source].filter(Boolean).join(" ").toLowerCase().includes(r):!0).filter(s=>n==="built-in"?!!s.isBundled:n==="marketplace"?!s.isBundled:!0).sort(C7)}function E7(e,t){const n=t.trim().toLowerCase();return e.filter(r=>!r.isBundled).filter(r=>n?[r.name,r.description,r.slug,r.author,r.source].filter(Boolean).join(" ").toLowerCase().includes(n):!0).sort((r,s)=>r.name.localeCompare(s.name))}const T7=Mn((e,t)=>({skills:[],isLoading:!1,error:null,activeTab:"installed",sourceFilter:"all",selectedSkill:null,detailDialogOpen:!1,installing:new Set,fetchSkills:async()=>{e({isLoading:!0,error:null});try{await Pe();const n=await Oe().skillsStatus();e({skills:n,isLoading:!1})}catch(n){e({error:String(n),isLoading:!1})}},setTab:n=>e({activeTab:n}),setSourceFilter:n=>e({sourceFilter:n}),openDetail:n=>e({selectedSkill:n,detailDialogOpen:!0}),closeDetail:()=>e({selectedSkill:null,detailDialogOpen:!1}),toggleSkill:async(n,r)=>{try{if((await Oe().skillsUpdate(n,{enabled:r})).ok){e(f=>({skills:f.skills.map(h=>h.id===n?{...h,enabled:r}:h)})),Ee.getState().setRuntimeApplied("configLifecycle.runtimeSkill");const o=t().skills.find(f=>f.id===n),u=(o==null?void 0:o.name)??n;hv(r?we.t("console:skills.toast.enabled",{name:u}):we.t("console:skills.toast.disabled",{name:u}))}}catch(s){uc(we.t("console:skills.toast.toggleFailed"),String(s)),e({error:String(s)})}},installSkill:async(n,r)=>{var o;const s=new Set(t().installing);s.add(n),e({installing:s});try{const u=await Oe().skillsInstall(n,r);if(u.ok)await t().fetchSkills(),hv(we.t("console:skills.toast.installSuccess",{name:n}));else{const f=[u.stdout,u.stderr].filter(Boolean).join(`
|
|
461
461
|
|
|
462
|
-
`);uc(we.t("console:skills.toast.installFailed",{name:n}),u.message,f||void 0)}if((o=u.warnings)!=null&&o.length)for(const f of u.warnings)uc(we.t("console:skills.toast.installWarning"),f);return u}catch(u){return uc(we.t("console:skills.toast.installFailed",{name:n}),String(u)),{ok:!1,message:String(u)}}finally{const u=new Set(t().installing);u.delete(n),e({installing:u})}}}));function D7(){const{t:e}=se("console"),{skills:t,isLoading:n,error:r,activeTab:s,sourceFilter:o,selectedSkill:u,detailDialogOpen:f,installing:h,fetchSkills:g,setTab:y,setSourceFilter:p,openDetail:b,closeDetail:v,toggleSkill:k,installSkill:j}=T7(),{searchResults:N,exploreItems:C,searchQuery:E,isSearching:R,isExploring:H,searchError:z,exploreError:L,nextCursor:G,offlineMode:W,search:P,searchImmediate:M,explore:$,clearSearch:V}=sl(),[ae,J]=S.useState(null),[Z,U]=S.useState(""),[ee,de]=S.useState(null),[ke,T]=S.useState(null);S.useEffect(()=>{g()},[g]),S.useEffect(()=>{s==="marketplace"&&C.length===0&&!W&&$()},[s,C.length,W,$]);const O=S.useMemo(()=>A7(t,Z,o),[t,Z,o]),Q=S.useMemo(()=>E7(t,E),[t,E]),D=S.useMemo(()=>N7(t),[t]),ce=S.useMemo(()=>({all:t.filter(pe=>pe.isBundled||pe.eligible).length,"built-in":t.filter(pe=>pe.isBundled).length,marketplace:t.filter(pe=>!pe.isBundled).length}),[t]),me=pe=>{pe.installOptions&&pe.installOptions.length>1?J(pe):pe.installOptions&&pe.installOptions.length===1&&j(pe.id,pe.installOptions[0].id)},ye=async pe=>{ae&&(await j(ae.id,pe),J(null))},Re=S.useCallback((pe,hn)=>{de({slug:pe,displayName:hn})},[]),rt=S.useCallback(()=>{de(null),g()},[g]),Ge=S.useCallback(pe=>{P(pe)},[P]),Lt=S.useCallback(()=>{E.trim()&&M(E)},[E,M]),_n=S.useCallback(()=>{V()},[V]),ar=E.trim().length>0,rr=z||L;return n&&t.length===0?c.jsxs("div",{className:"space-y-6",children:[c.jsx(Hh,{title:e("skills.title"),description:e("skills.description"),onRefresh:g}),c.jsx(zl,{})]}):r&&t.length===0?c.jsxs("div",{className:"space-y-6",children:[c.jsx(Hh,{title:e("skills.title"),description:e("skills.description"),onRefresh:g}),c.jsx(xu,{message:r,onRetry:g})]}):c.jsxs("div",{className:"space-y-6",children:[c.jsx(Hh,{title:e("skills.title"),description:e("skills.description"),onRefresh:g,loading:n}),c.jsx(j7,{activeTab:s,onTabChange:y}),s==="installed"?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[c.jsxs("div",{className:"relative w-full lg:max-w-md",children:[c.jsx(Ph,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),c.jsx("input",{value:Z,onChange:pe=>U(pe.target.value),placeholder:e("skills.installed.searchPlaceholder"),className:"w-full rounded-xl border border-gray-300 bg-white py-2 pl-10 pr-4 text-sm text-gray-700 outline-none transition-colors focus:border-blue-500 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"})]}),c.jsx("div",{className:"flex flex-wrap gap-2",children:["all","built-in","marketplace"].map(pe=>c.jsx("button",{type:"button",onClick:()=>p(pe),className:`rounded-xl px-3 py-2 text-sm font-medium transition-colors ${o===pe?"bg-blue-600 text-white":"border border-gray-300 bg-white text-gray-600 hover:bg-gray-50 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700"}`,children:e(`skills.filters.${pe}`,{count:ce[pe]})},pe))})]}),O.length===0?c.jsx(Er,{icon:rc,title:e("skills.empty.title"),description:e("skills.empty.description")}):c.jsx("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-2",children:O.map(pe=>c.jsx(Qv,{skill:pe,onToggle:k,onConfigure:b,onInstall:me,isInstalling:h.has(pe.id)},pe.id))})]}):c.jsxs("div",{className:"space-y-5",children:[c.jsx("div",{className:"rounded-2xl border border-gray-200 bg-gray-50/80 p-4 dark:border-gray-700 dark:bg-gray-800/60",children:c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx(K4,{className:"mt-0.5 h-5 w-5 text-gray-500"}),c.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-300",children:e("skills.marketplace.securityNote")})]})}),W&&c.jsx("div",{className:"rounded-xl border border-orange-200 bg-orange-50 px-4 py-3 dark:border-orange-800 dark:bg-orange-900/20",children:c.jsxs("div",{className:"flex items-center gap-2 text-sm text-orange-600 dark:text-orange-400",children:[c.jsx(Ag,{className:"h-4 w-4"}),e("clawhub.offlineNotice")]})}),c.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row",children:[c.jsxs("div",{className:"relative flex-1",children:[c.jsx(Ph,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),c.jsx("input",{value:E,onChange:pe=>Ge(pe.target.value),onKeyDown:pe=>pe.key==="Enter"&&Lt(),placeholder:e("clawhub.searchPlaceholder"),className:"w-full rounded-xl border border-gray-300 bg-white py-2 pl-10 pr-10 text-sm text-gray-700 outline-none transition-colors focus:border-blue-500 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"}),E&&c.jsx("button",{type:"button",onClick:_n,className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:c.jsx(An,{className:"h-4 w-4"})})]}),c.jsx("button",{type:"button",onClick:Lt,disabled:R||!E.trim(),className:"rounded-xl bg-blue-600 px-4 py-2 text-sm font-semibold text-white hover:bg-blue-700 disabled:opacity-50",children:R?c.jsx(Mt,{className:"mx-auto h-4 w-4 animate-spin"}):e("skills.marketplace.searchButton")})]}),rr&&c.jsx("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-600 dark:border-red-900/50 dark:bg-red-900/10 dark:text-red-400",children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Sg,{className:"h-4 w-4"}),rr]})}),W?Q.length===0?c.jsx(Er,{icon:rc,title:e("skills.marketplace.emptyTitle"),description:e("skills.marketplace.emptyDescription")}):c.jsx("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-2",children:Q.map(pe=>c.jsx(Qv,{skill:pe,onToggle:k,onConfigure:b,onInstall:me,isInstalling:h.has(pe.id)},pe.id))}):ar?R?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-6 w-6 animate-spin text-gray-400"})}):N.length===0?c.jsx(Er,{icon:rc,title:e("clawhub.noSearchResults"),description:e("clawhub.tryDifferentQuery")}):c.jsx("div",{className:"grid grid-cols-1 gap-3 xl:grid-cols-2",children:N.map(pe=>c.jsx(Yv,{item:pe,isInstalled:D.has(pe.slug),onInstall:Re,onOpenDetail:hn=>T(hn)},pe.slug))}):c.jsx(c.Fragment,{children:H&&C.length===0?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-6 w-6 animate-spin text-gray-400"})}):C.length===0?c.jsx(Er,{icon:rc,title:e("clawhub.noSkills"),description:e("clawhub.noSkillsDescription")}):c.jsxs("div",{className:"space-y-4",children:[c.jsx("div",{className:"grid grid-cols-1 gap-3 xl:grid-cols-2",children:C.map(pe=>c.jsx(Yv,{item:pe,isInstalled:D.has(pe.slug),onInstall:Re,onOpenDetail:hn=>T(hn)},pe.slug))}),G&&c.jsx("div",{className:"flex justify-center",children:c.jsx("button",{type:"button",onClick:()=>$(!0),disabled:H,className:"rounded-xl border border-gray-300 px-6 py-2 text-sm font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-800",children:H?c.jsx(Mt,{className:"mx-auto h-4 w-4 animate-spin"}):e("clawhub.loadMore")})})]})})]}),c.jsx(w7,{open:f,skill:u,onClose:v,onSaved:g}),c.jsx(k7,{open:ae!==null,skillName:(ae==null?void 0:ae.name)??"",options:(ae==null?void 0:ae.installOptions)??[],onSelect:ye,onCancel:()=>J(null)}),c.jsx(x7,{slug:ke,onClose:()=>T(null),onInstall:Re,isInstalled:ke?D.has(ke):!1}),c.jsx(b7,{open:ee!==null,slug:(ee==null?void 0:ee.slug)??"",displayName:(ee==null?void 0:ee.displayName)??"",onClose:()=>de(null),onConfirmDone:rt})]})}function Hh({title:e,description:t,onRefresh:n,loading:r}){const{t:s}=se("common");return c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:t})]}),c.jsxs("button",{type:"button",onClick:n,disabled:r,className:"flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:[c.jsx(Rn,{className:`h-3.5 w-3.5 ${r?"animate-spin":""}`}),s("actions.refresh")]})]})}const R7=500,Wv=200;function M7(e){if(e.stream==="error")return!0;if(e.stream==="lifecycle"){const t=e.data.phase;return t==="start"||t==="end"}return!1}class O7{constructor(){je(this,"queue",[]);je(this,"rafId",null);je(this,"handler",null);je(this,"immediateHandler",null)}onBatch(t){this.handler=t}onImmediate(t){this.immediateHandler=t}push(t){var n;if(M7(t)){(n=this.immediateHandler)==null||n.call(this,t);return}this.queue.push(t),this.queue.length>R7&&(console.warn(`[EventThrottle] Queue overflow: ${this.queue.length} events, trimming to ${Wv}`),this.queue=this.queue.slice(-Wv)),this.scheduleFlush()}scheduleFlush(){this.rafId===null&&(this.rafId=requestAnimationFrame(()=>{this.flush()}))}flush(){var n;if(this.rafId=null,this.queue.length===0)return;const t=this.queue;this.queue=[],(n=this.handler)==null||n.call(this,t)}destroy(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.queue=[]}}function _7(e){switch(e.stream){case"error":return Tt.L4;case"lifecycle":return L7(e);case"tool":return z7(e);case"assistant":return I7(e);default:return Tt.L0}}function L7(e){const t=e.data.phase,n=e.data.trigger,r=!!e.data.isSubAgent;switch(t){case"start":return r||n==="external"||n==="message"?Tt.L4:Tt.L2;case"end":return Tt.L2;case"thinking":return Tt.L1;case"fallback":return Tt.L4;default:return Tt.L1}}function z7(e){return e.data.phase==="start"?Tt.L3:Tt.L1}function I7(e){const t=e.data.text??"";return t.length>100?Tt.L3:t.length>20?Tt.L2:Tt.L1}let H7=0;function B7(){return`pe-${Date.now()}-${++H7}`}class U7{constructor(){je(this,"windows",new Map);je(this,"flushCallback",null)}onFlush(t){this.flushCallback=t}push(t){const n=this.resolveKey(t),r=_7(t);if(r===Tt.L0)return;const s=Date.now(),o=this.windows.get(n);if(o&&s<o.deadline){o.events.push(t),o.levels.push(r);const u=Math.min(o.openedAt+KL,s+jh);u>o.deadline&&(o.deadline=u,o.timer!==null&&clearTimeout(o.timer),o.timer=setTimeout(()=>this.closeWindow(n),u-s))}else{(o==null?void 0:o.timer)!==null&&o&&clearTimeout(o.timer);const u=s+jh,f={key:n,events:[t],levels:[r],openedAt:s,deadline:u,timer:setTimeout(()=>this.closeWindow(n),jh)};this.windows.set(n,f)}}closeWindow(t){var s;const n=this.windows.get(t);if(!n)return;this.windows.delete(t),n.timer=null;const r=this.aggregate(n);(s=this.flushCallback)==null||s.call(this,r)}aggregate(t){const n=Math.max(...t.levels),r=this.resolveKind(t.events,n),s=this.resolveActors(t.events),o=this.resolveArea(r),u=this.resolveHoldMs(r,n);return{id:B7(),startTs:t.events[0].ts,endTs:t.events[t.events.length-1].ts,kind:r,level:n,actors:s,area:o,summary:"",displayPriority:PL[n],holdMs:u,debugRefs:t.events.map(f=>`${f.runId}:${f.seq}`)}}resolveKind(t,n){return t.some(b=>b.stream==="error")?t.some(v=>v.stream==="lifecycle"&&v.data.phase==="start")?"RECOVER":"BLOCK":t.some(b=>b.stream==="lifecycle"&&b.data.phase==="start"&&!!b.data.isSubAgent)?"SPAWN_SUBAGENT":t.some(b=>b.stream==="lifecycle"&&b.data.phase==="start"&&(b.data.trigger==="external"||b.data.trigger==="message"))?"ARRIVE":t.some(b=>b.stream==="lifecycle"&&b.data.phase==="start"&&b.data.trigger==="cron")?"BROADCAST_CRON":t.find(b=>b.stream==="tool"&&b.data.phase==="start")?"CALL_TOOL":t.find(b=>b.stream==="tool"&&b.data.phase!=="start")?"WAIT":t.find(b=>b.stream==="lifecycle"&&b.data.phase==="end")?"RETURN":t.find(b=>b.stream==="lifecycle"&&b.data.phase==="start")?"DISPATCH":t.find(b=>b.stream==="assistant")?"FOCUS":n<=Tt.L1?"POLL_HEARTBEAT":"ACK"}resolveActors(t){const n=new Set;for(const r of t){if(r.sessionKey){const s=r.sessionKey.split(":");s.length>=2&&n.add(s[1])}typeof r.data.agentId=="string"&&n.add(r.data.agentId)}return Array.from(n)}resolveArea(t){switch(t){case"ARRIVE":case"DISPATCH":return"gateway";case"BROADCAST_CRON":return"cron";case"SPAWN_SUBAGENT":case"COLLAB":return"project";case"BLOCK":case"RECOVER":return"ops";default:return"staff"}}resolveHoldMs(t,n){return t==="BLOCK"?$L:t==="RECOVER"?qL:UL[n]}resolveKey(t){return t.sessionKey?`session:${t.sessionKey}`:`run:${t.runId}`}destroy(){for(const t of this.windows.values())t.timer!==null&&clearTimeout(t.timer);this.windows.clear(),this.flushCallback=null}}class $7{constructor(){je(this,"slots",new Map);je(this,"emitCallback",null)}onEmit(t){this.emitCallback=t}submit(t){const n=this.resolveKey(t),r=this.slots.get(n);if(!r){this.emitNow(n,t);return}r.queue.push(t)}emitNow(t,n){var f;const r=Math.max(n.holdMs,0);if((f=this.emitCallback)==null||f.call(this,n),r===0)return;const o=Date.now()+r,u={current:n,expiresAt:o,timer:setTimeout(()=>this.onSlotExpired(t),r),queue:[]};this.slots.set(t,u)}onSlotExpired(t){const n=this.slots.get(t);if(!n)return;const r=n.queue;this.slots.delete(t);const s=r.shift();if(s){this.emitNow(t,s);const o=this.slots.get(t);o&&o.queue.push(...r)}}getCurrentForAgent(t){var n;return((n=this.slots.get(t))==null?void 0:n.current)??null}getQueueLength(t){var n;return((n=this.slots.get(t))==null?void 0:n.queue.length)??0}resolveKey(t){return t.actors[0]??t.area}destroy(){for(const t of this.slots.values())clearTimeout(t.timer);this.slots.clear(),this.emitCallback=null}}const q7={ARRIVE:e=>`客户消息到达,Gateway 完成分发,${e[0]??"Agent"} 开始接单。`,DISPATCH:e=>`${e[0]??"Agent"} 接到主线任务,开始处理。`,ACK:e=>`${e[0]??"Agent"} 确认接单。`,FOCUS:e=>`${e[0]??"Agent"} 专注处理中。`,CALL_TOOL:(e,t)=>`${e[0]??"Agent"} 调用 ${t.tool??"工具"} 工具。`,WAIT:e=>`${e[0]??"Agent"} 等待外部返回。`,SPAWN_SUBAGENT:()=>"临时协作者被拉入项目室。",COLLAB:e=>`${e.join("、")||"多个 Agent"} 进入协作模式。`,RETURN:e=>`${e[0]??"Agent"} 完成处理,结果回到主线。`,BROADCAST_CRON:(e,t)=>`Cron 广播触发:${t.taskName??"定时任务"}。`,POLL_HEARTBEAT:()=>"Heartbeat 巡检扫过工位。",BLOCK:(e,t)=>`${e[0]??"Agent"} 进入阻塞态${t.reason?`:${t.reason}`:"。"}`,RECOVER:e=>`${e[0]??"Agent"} 从阻塞中恢复。`},K7="系统处理中...";function P7(e){const t=q7[e.kind];if(!t)return K7;const n=F7(e);return t(e.actors,n)}function F7(e){const t={};return e.area==="cron"&&(t.taskName="定时任务"),t}class G7{constructor(){je(this,"aggregator");je(this,"holdController");je(this,"listeners",[]);this.aggregator=new U7,this.holdController=new $7,this.aggregator.onFlush(t=>{const n={...t,summary:P7(t)};this.holdController.submit(n)}),this.holdController.onEmit(t=>{for(const n of this.listeners)n(t)})}ingest(t){this.aggregator.push(t)}onPerceived(t){return this.listeners.push(t),()=>{const n=this.listeners.indexOf(t);n>=0&&this.listeners.splice(n,1)}}destroy(){this.aggregator.destroy(),this.holdController.destroy(),this.listeners.length=0}}const V7=3e3,Y7=5*6e4;function Q7(e,t){const n=new Set(e.map(u=>u.sessionKey)),r=new Set(t.map(u=>u.sessionKey)),s=t.filter(u=>!n.has(u.sessionKey)),o=e.filter(u=>!r.has(u.sessionKey));return{added:s,removed:o}}function W7(e){const t=":subagent:",n=e.indexOf(t);return n>=0?e.slice(n+t.length):null}function X7(e){return e.filter(t=>t.requesterSessionKey).map(t=>{const n=W7(t.sessionKey),r=n??t.agentId;return{sessionKey:t.sessionKey,agentId:r,label:t.label??(n?`Sub-${n.slice(0,6)}`:t.agentId),task:t.task??"",requesterSessionKey:t.requesterSessionKey,startedAt:t.startedAt??Date.now()}})}function Z7(e){const t=S.useRef(null),n=ie(s=>s.connectionStatus);S.useEffect(()=>{if(n!=="connected"||!e.current){t.current&&(clearInterval(t.current),t.current=null);return}const s=async()=>{const o=e.current;if(o)try{const u=await o.request("sessions.list"),f=X7(u.sessions??[]),h=ie.getState().lastSessionsSnapshot,g=(h==null?void 0:h.sessions)??[],{added:y,removed:p}=Q7(g,f);for(const k of y){const j=r(k.requesterSessionKey);j&&ie.getState().addSubAgent(j,k)}for(const k of p)ie.getState().agents.has(k.agentId)&&ie.getState().retireSubAgent(k.agentId);ie.getState().setSessionsSnapshot({sessions:f,fetchedAt:Date.now()});const b=Date.now(),v=new Set(f.map(k=>k.agentId));for(const[k,j]of ie.getState().agents)j.isSubAgent&&!j.isPlaceholder&&!j.pendingRetire&&j.status==="idle"&&!v.has(k)&&b-j.lastActiveAt>Y7&&ie.getState().retireSubAgent(k)}catch{}};return t.current=setInterval(s,V7),s(),()=>{t.current&&(clearInterval(t.current),t.current=null)}},[n]);function r(s){const u=ie.getState().sessionKeyMap.get(s);if(u&&u.length>0)return u[0];for(const[f,h]of ie.getState().agents)if(!h.isSubAgent)return f;return null}}const J7=6e4,eI=3;function tI(e){const t=S.useRef(null),n=S.useRef(0),r=ie(u=>u.connectionStatus),s=ie(u=>u.pushTokenSnapshot),o=ie(u=>u.setAgentCosts);S.useEffect(()=>{if(r!=="connected"||!e.current){t.current&&(clearInterval(t.current),t.current=null);return}const u=async()=>{const f=e.current;if(f)try{const[h,g,y]=await Promise.all([f.request("sessions.list"),f.request("sessions.usage").catch(()=>null),f.request("usage.cost").catch(()=>null)]);n.current=0;const p=nI((h==null?void 0:h.sessions)??[]);p&&s(p);const b=rI(g)??(y==null?void 0:y.byAgent)??(y==null?void 0:y.costs)??{};Object.keys(b).length>0&&o(b)}catch{if(n.current+=1,n.current>=eI){const h=ie.getState().eventHistory,g=iI(h);g&&s(g)}}};return t.current=setInterval(u,J7),u(),()=>{t.current&&(clearInterval(t.current),t.current=null)}},[r,s,o])}function nI(e){const t={};let n=0;for(const r of e){if(r.totalTokensFresh===!1||typeof r.totalTokens!="number"||!Number.isFinite(r.totalTokens))continue;const s=aI(r.key);s&&(t[s]=(t[s]??0)+r.totalTokens,n+=r.totalTokens)}return n===0?null:{timestamp:Date.now(),total:n,byAgent:t}}function aI(e){const t=/^agent:([^:]+):/.exec(e??"");return(t==null?void 0:t[1])??null}function rI(e){var r,s;const t=(r=e==null?void 0:e.aggregates)==null?void 0:r.byAgent;if(!Array.isArray(t)||t.length===0)return null;const n={};for(const o of t){if(!(o!=null&&o.agentId))continue;const u=(s=o.totals)==null?void 0:s.totalCost;typeof u!="number"||!Number.isFinite(u)||u<=0||(n[o.agentId]=u)}return Object.keys(n).length>0?n:null}function iI(e){const t={};let n=0;for(const r of e){if(r.stream!=="tool")continue;const s=100;t[r.agentId]=(t[r.agentId]??0)+s,n+=s}return n===0?null:{timestamp:Date.now(),total:n,byAgent:t}}function sI({url:e,token:t}){const n=S.useRef(null),r=S.useRef(null),s=S.useRef(null),o=S.useRef(null),u=ie(v=>v.setConnectionStatus),f=ie(v=>v.initAgents),h=ie(v=>v.syncMainAgents),g=ie(v=>v.processAgentEvent),y=ie(v=>v.setOperatorScopes),p=ie(v=>v.setMaxSubAgents),b=ie(v=>v.setAgentToAgentConfig);return S.useEffect(()=>{if(!e)return;const v=new P1,k=new U1(v),j=new O7,N=new G7;n.current=v,r.current=k,s.current=j,o.current=N;const C=Dn.getState().applyPerceivedEvent;return N.onPerceived(E=>{C(E)}),j.onBatch(E=>{for(const R of E)g(R)}),j.onImmediate(E=>{g(E)}),v.onStatusChange((E,R)=>{if(u(E,R),E==="connected"){oI(v,f),cI(v);const H=v.getSnapshot(),z=H==null?void 0:H.scopes;y(Array.isArray(z)?z:["operator"]),Z3("ws",{wsClient:v,rpcClient:k}),dI(k,p,b),uI(k,h)}}),v.onEvent("agent",E=>{const R=E.payload;j.push(R),N.ingest(R)}),v.onEvent("health",E=>{const R=E.payload;if(R!=null&&R.agents){const H=Bw(R);h(H)}}),v.connect(e,t),()=>{j.destroy(),N.destroy(),v.disconnect(),n.current=null,r.current=null,s.current=null,o.current=null}},[e,t,u,f,h,g,y,p,b]),Z7(r),tI(r),{wsClient:n,rpcClient:r,perceptionEngine:o}}const om=new Map;function lI(e){var t;for(const n of e)om.set(n.id,{name:((t=n.identity)==null?void 0:t.name)??n.name??n.id,identity:n.identity})}function Hw(e){var t;return((t=om.get(e))==null?void 0:t.name)??e}function Bw(e){return e.agents?e.agents.map(t=>{var n;return{id:t.agentId,name:Hw(t.agentId),identity:(n=om.get(t.agentId))==null?void 0:n.identity}}):[]}function oI(e,t){const n=e.getSnapshot(),r=n==null?void 0:n.health;r!=null&&r.agents&&t(Bw(r))}function cI(e){const t=e.getSnapshot(),n=t==null?void 0:t.health;if(n!=null&&n.agents){const r=n.agents.map(s=>({agentId:s.agentId,role:Hw(s.agentId),deskId:s.agentId}));Dn.getState().initAgentsBatch(r)}}async function uI(e,t){try{const n=await e.request("agents.list");if(n!=null&&n.agents){lI(n.agents),t(n.agents);const r=n.agents.map(s=>{var o;return{agentId:s.id,role:((o=s.identity)==null?void 0:o.name)??s.name??s.id,deskId:s.id}});Dn.getState().initAgentsBatch(r)}}catch{}}async function dI(e,t,n){try{const s=(await e.request("config.get",{keys:["agents.defaults.subagents","tools.agentToAgent"]})).value;if(s){const o=s["agents.defaults.subagents"];o!=null&&o.maxConcurrent&&o.maxConcurrent>=1&&o.maxConcurrent<=50&&t(o.maxConcurrent);const u=s["tools.agentToAgent"];u&&n({enabled:u.enabled??!1,allow:Array.isArray(u.allow)?u.allow:[]})}}catch{}}function fI(){const[e,t]=S.useState(()=>Xv());return S.useEffect(()=>{const n=matchMedia("(max-width: 767px)"),r=matchMedia("(min-width: 768px) and (max-width: 1023px)");function s(){t(Xv())}return n.addEventListener("change",s),r.addEventListener("change",s),()=>{n.removeEventListener("change",s),r.removeEventListener("change",s)}},[]),e}function Xv(){if(typeof window>"u")return{isMobile:!1,isTablet:!1,isDesktop:!0};const e=window.innerWidth;return{isMobile:e<768,isTablet:e>=768&&e<1024,isDesktop:e>=1024}}const hI=S.lazy(()=>El(()=>import("./Scene3D-DC1g2KU1.js"),[]));function gI(){const{t:e}=se("office");return c.jsx("div",{className:"flex h-full w-full items-center justify-center bg-gray-50 dark:bg-gray-950",children:c.jsxs("div",{className:"flex flex-col items-center gap-3",children:[c.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-blue-500 border-t-transparent"}),c.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:e("loading3D")})]})})}function mI(){const e=ie(o=>o.viewMode),[t,n]=S.useState(!1),[r,s]=S.useState(e);return S.useEffect(()=>{if(e!==r){n(!0);const o=setTimeout(()=>{s(e),n(!1)},150);return()=>clearTimeout(o)}},[e,r]),c.jsx("div",{className:"h-full w-full transition-opacity duration-300",style:{opacity:t?0:1,position:"relative"},children:r==="2d"?c.jsx(Ez,{}):c.jsx(S.Suspense,{fallback:c.jsx(gI,{}),children:c.jsx(hI,{})})})}function pI(){const e=ie(t=>t.theme);return S.useEffect(()=>{document.documentElement.setAttribute("data-theme",e),e==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[e]),null}const yI={"/":"office","/living-office":"office","/dashboard":"dashboard","/agents":"agents","/channels":"channels","/skills":"skills","/cron":"cron","/settings":"settings"};function xI(e,t){const n=e.trim();if(n.startsWith("ws://")||n.startsWith("wss://"))return n;if(n.startsWith("http://")||n.startsWith("https://")){const r=new URL(n);return r.protocol=r.protocol==="https:"?"wss:":"ws:",r.toString()}return n.startsWith("/")?`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}${n}`:t}function bI(){const e=Zt(),t=ie(n=>n.setCurrentPage);return S.useEffect(()=>{const n=yI[e.pathname]??"office";t(n)},[e.pathname,t]),null}function vI(){const e=window.__OPENCLAW_CONFIG__,t=(e==null?void 0:e.gatewayUrl)||"ws://localhost:18789",n=xI((e==null?void 0:e.gatewayWsPath)||void 0||"/gateway-ws",t),r=(e==null?void 0:e.gatewayToken)||"5qd1bnvCHA2JwLn5NUBwUqKS7ZWMY37Vo2TO7pvZHc9sgL0U",{isMobile:s}=fI(),o=ie(h=>h.setViewMode),{wsClient:u,perceptionEngine:f}=sI({url:n,token:r});return S.useEffect(()=>{s&&o("2d")},[s,o]),c.jsxs(Cw,{value:f,children:[c.jsx(pI,{}),c.jsx(bI,{}),c.jsxs(dC,{children:[c.jsxs(jn,{element:c.jsx(HL,{wsClient:u,isMobile:s}),children:[c.jsx(jn,{path:"/",element:c.jsx(mI,{})}),c.jsx(jn,{path:"/living-office",element:c.jsx(gz,{})})]}),c.jsxs(jn,{element:c.jsx(BL,{}),children:[c.jsx(jn,{path:"/dashboard",element:c.jsx(I9,{})}),c.jsx(jn,{path:"/agents",element:c.jsx(y9,{})}),c.jsx(jn,{path:"/channels",element:c.jsx(A9,{})}),c.jsx(jn,{path:"/skills",element:c.jsx(D7,{})}),c.jsx(jn,{path:"/cron",element:c.jsx(T9,{})}),c.jsx(jn,{path:"/settings",element:c.jsx(c7,{})})]}),c.jsx(jn,{path:"*",element:c.jsx(cC,{to:"/",replace:!0})})]})]})}dj.createRoot(document.getElementById("root")).render(c.jsx(S.StrictMode,{children:c.jsx(LC,{children:c.jsx(vI,{})})}));export{Hi as P,Ml as S,Me as Z,Fh as _,KN as a,sj as b,T3 as c,S as d,Ar as e,dj as f,mg as g,ie as h,jI as i,c as j,ZE as k,wI as l,SI as p,Wc as r,se as u};
|
|
462
|
+
`);uc(we.t("console:skills.toast.installFailed",{name:n}),u.message,f||void 0)}if((o=u.warnings)!=null&&o.length)for(const f of u.warnings)uc(we.t("console:skills.toast.installWarning"),f);return u}catch(u){return uc(we.t("console:skills.toast.installFailed",{name:n}),String(u)),{ok:!1,message:String(u)}}finally{const u=new Set(t().installing);u.delete(n),e({installing:u})}}}));function D7(){const{t:e}=se("console"),{skills:t,isLoading:n,error:r,activeTab:s,sourceFilter:o,selectedSkill:u,detailDialogOpen:f,installing:h,fetchSkills:g,setTab:y,setSourceFilter:p,openDetail:b,closeDetail:v,toggleSkill:k,installSkill:j}=T7(),{searchResults:N,exploreItems:C,searchQuery:E,isSearching:R,isExploring:H,searchError:z,exploreError:L,nextCursor:G,offlineMode:W,search:P,searchImmediate:M,explore:$,clearSearch:V}=sl(),[ae,J]=S.useState(null),[Z,U]=S.useState(""),[ee,de]=S.useState(null),[ke,T]=S.useState(null);S.useEffect(()=>{g()},[g]),S.useEffect(()=>{s==="marketplace"&&C.length===0&&!W&&$()},[s,C.length,W,$]);const O=S.useMemo(()=>A7(t,Z,o),[t,Z,o]),Q=S.useMemo(()=>E7(t,E),[t,E]),D=S.useMemo(()=>N7(t),[t]),ce=S.useMemo(()=>({all:t.filter(pe=>pe.isBundled||pe.eligible).length,"built-in":t.filter(pe=>pe.isBundled).length,marketplace:t.filter(pe=>!pe.isBundled).length}),[t]),me=pe=>{pe.installOptions&&pe.installOptions.length>1?J(pe):pe.installOptions&&pe.installOptions.length===1&&j(pe.id,pe.installOptions[0].id)},ye=async pe=>{ae&&(await j(ae.id,pe),J(null))},Re=S.useCallback((pe,hn)=>{de({slug:pe,displayName:hn})},[]),rt=S.useCallback(()=>{de(null),g()},[g]),Ge=S.useCallback(pe=>{P(pe)},[P]),Lt=S.useCallback(()=>{E.trim()&&M(E)},[E,M]),_n=S.useCallback(()=>{V()},[V]),ar=E.trim().length>0,rr=z||L;return n&&t.length===0?c.jsxs("div",{className:"space-y-6",children:[c.jsx(Hh,{title:e("skills.title"),description:e("skills.description"),onRefresh:g}),c.jsx(zl,{})]}):r&&t.length===0?c.jsxs("div",{className:"space-y-6",children:[c.jsx(Hh,{title:e("skills.title"),description:e("skills.description"),onRefresh:g}),c.jsx(xu,{message:r,onRetry:g})]}):c.jsxs("div",{className:"space-y-6",children:[c.jsx(Hh,{title:e("skills.title"),description:e("skills.description"),onRefresh:g,loading:n}),c.jsx(j7,{activeTab:s,onTabChange:y}),s==="installed"?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[c.jsxs("div",{className:"relative w-full lg:max-w-md",children:[c.jsx(Ph,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),c.jsx("input",{value:Z,onChange:pe=>U(pe.target.value),placeholder:e("skills.installed.searchPlaceholder"),className:"w-full rounded-xl border border-gray-300 bg-white py-2 pl-10 pr-4 text-sm text-gray-700 outline-none transition-colors focus:border-blue-500 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"})]}),c.jsx("div",{className:"flex flex-wrap gap-2",children:["all","built-in","marketplace"].map(pe=>c.jsx("button",{type:"button",onClick:()=>p(pe),className:`rounded-xl px-3 py-2 text-sm font-medium transition-colors ${o===pe?"bg-blue-600 text-white":"border border-gray-300 bg-white text-gray-600 hover:bg-gray-50 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700"}`,children:e(`skills.filters.${pe}`,{count:ce[pe]})},pe))})]}),O.length===0?c.jsx(Er,{icon:rc,title:e("skills.empty.title"),description:e("skills.empty.description")}):c.jsx("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-2",children:O.map(pe=>c.jsx(Qv,{skill:pe,onToggle:k,onConfigure:b,onInstall:me,isInstalling:h.has(pe.id)},pe.id))})]}):c.jsxs("div",{className:"space-y-5",children:[c.jsx("div",{className:"rounded-2xl border border-gray-200 bg-gray-50/80 p-4 dark:border-gray-700 dark:bg-gray-800/60",children:c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx(K4,{className:"mt-0.5 h-5 w-5 text-gray-500"}),c.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-300",children:e("skills.marketplace.securityNote")})]})}),W&&c.jsx("div",{className:"rounded-xl border border-orange-200 bg-orange-50 px-4 py-3 dark:border-orange-800 dark:bg-orange-900/20",children:c.jsxs("div",{className:"flex items-center gap-2 text-sm text-orange-600 dark:text-orange-400",children:[c.jsx(Ag,{className:"h-4 w-4"}),e("clawhub.offlineNotice")]})}),c.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row",children:[c.jsxs("div",{className:"relative flex-1",children:[c.jsx(Ph,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),c.jsx("input",{value:E,onChange:pe=>Ge(pe.target.value),onKeyDown:pe=>pe.key==="Enter"&&Lt(),placeholder:e("clawhub.searchPlaceholder"),className:"w-full rounded-xl border border-gray-300 bg-white py-2 pl-10 pr-10 text-sm text-gray-700 outline-none transition-colors focus:border-blue-500 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-200"}),E&&c.jsx("button",{type:"button",onClick:_n,className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:c.jsx(An,{className:"h-4 w-4"})})]}),c.jsx("button",{type:"button",onClick:Lt,disabled:R||!E.trim(),className:"rounded-xl bg-blue-600 px-4 py-2 text-sm font-semibold text-white hover:bg-blue-700 disabled:opacity-50",children:R?c.jsx(Mt,{className:"mx-auto h-4 w-4 animate-spin"}):e("skills.marketplace.searchButton")})]}),rr&&c.jsx("div",{className:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-600 dark:border-red-900/50 dark:bg-red-900/10 dark:text-red-400",children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Sg,{className:"h-4 w-4"}),rr]})}),W?Q.length===0?c.jsx(Er,{icon:rc,title:e("skills.marketplace.emptyTitle"),description:e("skills.marketplace.emptyDescription")}):c.jsx("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-2",children:Q.map(pe=>c.jsx(Qv,{skill:pe,onToggle:k,onConfigure:b,onInstall:me,isInstalling:h.has(pe.id)},pe.id))}):ar?R?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-6 w-6 animate-spin text-gray-400"})}):N.length===0?c.jsx(Er,{icon:rc,title:e("clawhub.noSearchResults"),description:e("clawhub.tryDifferentQuery")}):c.jsx("div",{className:"grid grid-cols-1 gap-3 xl:grid-cols-2",children:N.map(pe=>c.jsx(Yv,{item:pe,isInstalled:D.has(pe.slug),onInstall:Re,onOpenDetail:hn=>T(hn)},pe.slug))}):c.jsx(c.Fragment,{children:H&&C.length===0?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(Mt,{className:"h-6 w-6 animate-spin text-gray-400"})}):C.length===0?c.jsx(Er,{icon:rc,title:e("clawhub.noSkills"),description:e("clawhub.noSkillsDescription")}):c.jsxs("div",{className:"space-y-4",children:[c.jsx("div",{className:"grid grid-cols-1 gap-3 xl:grid-cols-2",children:C.map(pe=>c.jsx(Yv,{item:pe,isInstalled:D.has(pe.slug),onInstall:Re,onOpenDetail:hn=>T(hn)},pe.slug))}),G&&c.jsx("div",{className:"flex justify-center",children:c.jsx("button",{type:"button",onClick:()=>$(!0),disabled:H,className:"rounded-xl border border-gray-300 px-6 py-2 text-sm font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-800",children:H?c.jsx(Mt,{className:"mx-auto h-4 w-4 animate-spin"}):e("clawhub.loadMore")})})]})})]}),c.jsx(w7,{open:f,skill:u,onClose:v,onSaved:g}),c.jsx(k7,{open:ae!==null,skillName:(ae==null?void 0:ae.name)??"",options:(ae==null?void 0:ae.installOptions)??[],onSelect:ye,onCancel:()=>J(null)}),c.jsx(x7,{slug:ke,onClose:()=>T(null),onInstall:Re,isInstalled:ke?D.has(ke):!1}),c.jsx(b7,{open:ee!==null,slug:(ee==null?void 0:ee.slug)??"",displayName:(ee==null?void 0:ee.displayName)??"",onClose:()=>de(null),onConfirmDone:rt})]})}function Hh({title:e,description:t,onRefresh:n,loading:r}){const{t:s}=se("common");return c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:e}),c.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:t})]}),c.jsxs("button",{type:"button",onClick:n,disabled:r,className:"flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-600 dark:text-gray-400 dark:hover:bg-gray-700 transition-colors",children:[c.jsx(Rn,{className:`h-3.5 w-3.5 ${r?"animate-spin":""}`}),s("actions.refresh")]})]})}const R7=500,Wv=200;function M7(e){if(e.stream==="error")return!0;if(e.stream==="lifecycle"){const t=e.data.phase;return t==="start"||t==="end"}return!1}class O7{constructor(){je(this,"queue",[]);je(this,"rafId",null);je(this,"handler",null);je(this,"immediateHandler",null)}onBatch(t){this.handler=t}onImmediate(t){this.immediateHandler=t}push(t){var n;if(M7(t)){(n=this.immediateHandler)==null||n.call(this,t);return}this.queue.push(t),this.queue.length>R7&&(console.warn(`[EventThrottle] Queue overflow: ${this.queue.length} events, trimming to ${Wv}`),this.queue=this.queue.slice(-Wv)),this.scheduleFlush()}scheduleFlush(){this.rafId===null&&(this.rafId=requestAnimationFrame(()=>{this.flush()}))}flush(){var n;if(this.rafId=null,this.queue.length===0)return;const t=this.queue;this.queue=[],(n=this.handler)==null||n.call(this,t)}destroy(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.queue=[]}}function _7(e){switch(e.stream){case"error":return Tt.L4;case"lifecycle":return L7(e);case"tool":return z7(e);case"assistant":return I7(e);default:return Tt.L0}}function L7(e){const t=e.data.phase,n=e.data.trigger,r=!!e.data.isSubAgent;switch(t){case"start":return r||n==="external"||n==="message"?Tt.L4:Tt.L2;case"end":return Tt.L2;case"thinking":return Tt.L1;case"fallback":return Tt.L4;default:return Tt.L1}}function z7(e){return e.data.phase==="start"?Tt.L3:Tt.L1}function I7(e){const t=e.data.text??"";return t.length>100?Tt.L3:t.length>20?Tt.L2:Tt.L1}let H7=0;function B7(){return`pe-${Date.now()}-${++H7}`}class U7{constructor(){je(this,"windows",new Map);je(this,"flushCallback",null)}onFlush(t){this.flushCallback=t}push(t){const n=this.resolveKey(t),r=_7(t);if(r===Tt.L0)return;const s=Date.now(),o=this.windows.get(n);if(o&&s<o.deadline){o.events.push(t),o.levels.push(r);const u=Math.min(o.openedAt+KL,s+jh);u>o.deadline&&(o.deadline=u,o.timer!==null&&clearTimeout(o.timer),o.timer=setTimeout(()=>this.closeWindow(n),u-s))}else{(o==null?void 0:o.timer)!==null&&o&&clearTimeout(o.timer);const u=s+jh,f={key:n,events:[t],levels:[r],openedAt:s,deadline:u,timer:setTimeout(()=>this.closeWindow(n),jh)};this.windows.set(n,f)}}closeWindow(t){var s;const n=this.windows.get(t);if(!n)return;this.windows.delete(t),n.timer=null;const r=this.aggregate(n);(s=this.flushCallback)==null||s.call(this,r)}aggregate(t){const n=Math.max(...t.levels),r=this.resolveKind(t.events,n),s=this.resolveActors(t.events),o=this.resolveArea(r),u=this.resolveHoldMs(r,n);return{id:B7(),startTs:t.events[0].ts,endTs:t.events[t.events.length-1].ts,kind:r,level:n,actors:s,area:o,summary:"",displayPriority:PL[n],holdMs:u,debugRefs:t.events.map(f=>`${f.runId}:${f.seq}`)}}resolveKind(t,n){return t.some(b=>b.stream==="error")?t.some(v=>v.stream==="lifecycle"&&v.data.phase==="start")?"RECOVER":"BLOCK":t.some(b=>b.stream==="lifecycle"&&b.data.phase==="start"&&!!b.data.isSubAgent)?"SPAWN_SUBAGENT":t.some(b=>b.stream==="lifecycle"&&b.data.phase==="start"&&(b.data.trigger==="external"||b.data.trigger==="message"))?"ARRIVE":t.some(b=>b.stream==="lifecycle"&&b.data.phase==="start"&&b.data.trigger==="cron")?"BROADCAST_CRON":t.find(b=>b.stream==="tool"&&b.data.phase==="start")?"CALL_TOOL":t.find(b=>b.stream==="tool"&&b.data.phase!=="start")?"WAIT":t.find(b=>b.stream==="lifecycle"&&b.data.phase==="end")?"RETURN":t.find(b=>b.stream==="lifecycle"&&b.data.phase==="start")?"DISPATCH":t.find(b=>b.stream==="assistant")?"FOCUS":n<=Tt.L1?"POLL_HEARTBEAT":"ACK"}resolveActors(t){const n=new Set;for(const r of t){if(r.sessionKey){const s=r.sessionKey.split(":");s.length>=2&&n.add(s[1])}typeof r.data.agentId=="string"&&n.add(r.data.agentId)}return Array.from(n)}resolveArea(t){switch(t){case"ARRIVE":case"DISPATCH":return"gateway";case"BROADCAST_CRON":return"cron";case"SPAWN_SUBAGENT":case"COLLAB":return"project";case"BLOCK":case"RECOVER":return"ops";default:return"staff"}}resolveHoldMs(t,n){return t==="BLOCK"?$L:t==="RECOVER"?qL:UL[n]}resolveKey(t){return t.sessionKey?`session:${t.sessionKey}`:`run:${t.runId}`}destroy(){for(const t of this.windows.values())t.timer!==null&&clearTimeout(t.timer);this.windows.clear(),this.flushCallback=null}}class $7{constructor(){je(this,"slots",new Map);je(this,"emitCallback",null)}onEmit(t){this.emitCallback=t}submit(t){const n=this.resolveKey(t),r=this.slots.get(n);if(!r){this.emitNow(n,t);return}r.queue.push(t)}emitNow(t,n){var f;const r=Math.max(n.holdMs,0);if((f=this.emitCallback)==null||f.call(this,n),r===0)return;const o=Date.now()+r,u={current:n,expiresAt:o,timer:setTimeout(()=>this.onSlotExpired(t),r),queue:[]};this.slots.set(t,u)}onSlotExpired(t){const n=this.slots.get(t);if(!n)return;const r=n.queue;this.slots.delete(t);const s=r.shift();if(s){this.emitNow(t,s);const o=this.slots.get(t);o&&o.queue.push(...r)}}getCurrentForAgent(t){var n;return((n=this.slots.get(t))==null?void 0:n.current)??null}getQueueLength(t){var n;return((n=this.slots.get(t))==null?void 0:n.queue.length)??0}resolveKey(t){return t.actors[0]??t.area}destroy(){for(const t of this.slots.values())clearTimeout(t.timer);this.slots.clear(),this.emitCallback=null}}const q7={ARRIVE:e=>`客户消息到达,Gateway 完成分发,${e[0]??"Agent"} 开始接单。`,DISPATCH:e=>`${e[0]??"Agent"} 接到主线任务,开始处理。`,ACK:e=>`${e[0]??"Agent"} 确认接单。`,FOCUS:e=>`${e[0]??"Agent"} 专注处理中。`,CALL_TOOL:(e,t)=>`${e[0]??"Agent"} 调用 ${t.tool??"工具"} 工具。`,WAIT:e=>`${e[0]??"Agent"} 等待外部返回。`,SPAWN_SUBAGENT:()=>"临时协作者被拉入项目室。",COLLAB:e=>`${e.join("、")||"多个 Agent"} 进入协作模式。`,RETURN:e=>`${e[0]??"Agent"} 完成处理,结果回到主线。`,BROADCAST_CRON:(e,t)=>`Cron 广播触发:${t.taskName??"定时任务"}。`,POLL_HEARTBEAT:()=>"Heartbeat 巡检扫过工位。",BLOCK:(e,t)=>`${e[0]??"Agent"} 进入阻塞态${t.reason?`:${t.reason}`:"。"}`,RECOVER:e=>`${e[0]??"Agent"} 从阻塞中恢复。`},K7="系统处理中...";function P7(e){const t=q7[e.kind];if(!t)return K7;const n=F7(e);return t(e.actors,n)}function F7(e){const t={};return e.area==="cron"&&(t.taskName="定时任务"),t}class G7{constructor(){je(this,"aggregator");je(this,"holdController");je(this,"listeners",[]);this.aggregator=new U7,this.holdController=new $7,this.aggregator.onFlush(t=>{const n={...t,summary:P7(t)};this.holdController.submit(n)}),this.holdController.onEmit(t=>{for(const n of this.listeners)n(t)})}ingest(t){this.aggregator.push(t)}onPerceived(t){return this.listeners.push(t),()=>{const n=this.listeners.indexOf(t);n>=0&&this.listeners.splice(n,1)}}destroy(){this.aggregator.destroy(),this.holdController.destroy(),this.listeners.length=0}}const V7=3e3,Y7=5*6e4;function Q7(e,t){const n=new Set(e.map(u=>u.sessionKey)),r=new Set(t.map(u=>u.sessionKey)),s=t.filter(u=>!n.has(u.sessionKey)),o=e.filter(u=>!r.has(u.sessionKey));return{added:s,removed:o}}function W7(e){const t=":subagent:",n=e.indexOf(t);return n>=0?e.slice(n+t.length):null}function X7(e){return e.filter(t=>t.requesterSessionKey).map(t=>{const n=W7(t.sessionKey),r=n??t.agentId;return{sessionKey:t.sessionKey,agentId:r,label:t.label??(n?`Sub-${n.slice(0,6)}`:t.agentId),task:t.task??"",requesterSessionKey:t.requesterSessionKey,startedAt:t.startedAt??Date.now()}})}function Z7(e){const t=S.useRef(null),n=ie(s=>s.connectionStatus);S.useEffect(()=>{if(n!=="connected"||!e.current){t.current&&(clearInterval(t.current),t.current=null);return}const s=async()=>{const o=e.current;if(o)try{const u=await o.request("sessions.list"),f=X7(u.sessions??[]),h=ie.getState().lastSessionsSnapshot,g=(h==null?void 0:h.sessions)??[],{added:y,removed:p}=Q7(g,f);for(const k of y){const j=r(k.requesterSessionKey);j&&ie.getState().addSubAgent(j,k)}for(const k of p)ie.getState().agents.has(k.agentId)&&ie.getState().retireSubAgent(k.agentId);ie.getState().setSessionsSnapshot({sessions:f,fetchedAt:Date.now()});const b=Date.now(),v=new Set(f.map(k=>k.agentId));for(const[k,j]of ie.getState().agents)j.isSubAgent&&!j.isPlaceholder&&!j.pendingRetire&&j.status==="idle"&&!v.has(k)&&b-j.lastActiveAt>Y7&&ie.getState().retireSubAgent(k)}catch{}};return t.current=setInterval(s,V7),s(),()=>{t.current&&(clearInterval(t.current),t.current=null)}},[n]);function r(s){const u=ie.getState().sessionKeyMap.get(s);if(u&&u.length>0)return u[0];for(const[f,h]of ie.getState().agents)if(!h.isSubAgent)return f;return null}}const J7=6e4,eI=3;function tI(e){const t=S.useRef(null),n=S.useRef(0),r=ie(u=>u.connectionStatus),s=ie(u=>u.pushTokenSnapshot),o=ie(u=>u.setAgentCosts);S.useEffect(()=>{if(r!=="connected"||!e.current){t.current&&(clearInterval(t.current),t.current=null);return}const u=async()=>{const f=e.current;if(f)try{const[h,g,y]=await Promise.all([f.request("sessions.list"),f.request("sessions.usage").catch(()=>null),f.request("usage.cost").catch(()=>null)]);n.current=0;const p=nI((h==null?void 0:h.sessions)??[]);p&&s(p);const b=rI(g)??(y==null?void 0:y.byAgent)??(y==null?void 0:y.costs)??{};Object.keys(b).length>0&&o(b)}catch{if(n.current+=1,n.current>=eI){const h=ie.getState().eventHistory,g=iI(h);g&&s(g)}}};return t.current=setInterval(u,J7),u(),()=>{t.current&&(clearInterval(t.current),t.current=null)}},[r,s,o])}function nI(e){const t={};let n=0;for(const r of e){if(r.totalTokensFresh===!1||typeof r.totalTokens!="number"||!Number.isFinite(r.totalTokens))continue;const s=aI(r.key);s&&(t[s]=(t[s]??0)+r.totalTokens,n+=r.totalTokens)}return n===0?null:{timestamp:Date.now(),total:n,byAgent:t}}function aI(e){const t=/^agent:([^:]+):/.exec(e??"");return(t==null?void 0:t[1])??null}function rI(e){var r,s;const t=(r=e==null?void 0:e.aggregates)==null?void 0:r.byAgent;if(!Array.isArray(t)||t.length===0)return null;const n={};for(const o of t){if(!(o!=null&&o.agentId))continue;const u=(s=o.totals)==null?void 0:s.totalCost;typeof u!="number"||!Number.isFinite(u)||u<=0||(n[o.agentId]=u)}return Object.keys(n).length>0?n:null}function iI(e){const t={};let n=0;for(const r of e){if(r.stream!=="tool")continue;const s=100;t[r.agentId]=(t[r.agentId]??0)+s,n+=s}return n===0?null:{timestamp:Date.now(),total:n,byAgent:t}}function sI({url:e,token:t}){const n=S.useRef(null),r=S.useRef(null),s=S.useRef(null),o=S.useRef(null),u=ie(v=>v.setConnectionStatus),f=ie(v=>v.initAgents),h=ie(v=>v.syncMainAgents),g=ie(v=>v.processAgentEvent),y=ie(v=>v.setOperatorScopes),p=ie(v=>v.setMaxSubAgents),b=ie(v=>v.setAgentToAgentConfig);return S.useEffect(()=>{if(!e)return;const v=new P1,k=new U1(v),j=new O7,N=new G7;n.current=v,r.current=k,s.current=j,o.current=N;const C=Dn.getState().applyPerceivedEvent;return N.onPerceived(E=>{C(E)}),j.onBatch(E=>{for(const R of E)g(R)}),j.onImmediate(E=>{g(E)}),v.onStatusChange((E,R)=>{var H;if(u(E,R),E==="connected"){oI(v,f),cI(v);const z=(H=v.getAuthInfo())==null?void 0:H.scopes;y(Array.isArray(z)?z:["operator.admin","operator.read"]),Z3("ws",{wsClient:v,rpcClient:k}),dI(k,p,b),uI(k,h)}}),v.onEvent("agent",E=>{const R=E.payload;j.push(R),N.ingest(R)}),v.onEvent("health",E=>{const R=E.payload;if(R!=null&&R.agents){const H=Bw(R);h(H)}}),v.connect(e,t),()=>{j.destroy(),N.destroy(),v.disconnect(),n.current=null,r.current=null,s.current=null,o.current=null}},[e,t,u,f,h,g,y,p,b]),Z7(r),tI(r),{wsClient:n,rpcClient:r,perceptionEngine:o}}const om=new Map;function lI(e){var t;for(const n of e)om.set(n.id,{name:((t=n.identity)==null?void 0:t.name)??n.name??n.id,identity:n.identity})}function Hw(e){var t;return((t=om.get(e))==null?void 0:t.name)??e}function Bw(e){return e.agents?e.agents.map(t=>{var n;return{id:t.agentId,name:Hw(t.agentId),identity:(n=om.get(t.agentId))==null?void 0:n.identity}}):[]}function oI(e,t){const n=e.getSnapshot(),r=n==null?void 0:n.health;r!=null&&r.agents&&t(Bw(r))}function cI(e){const t=e.getSnapshot(),n=t==null?void 0:t.health;if(n!=null&&n.agents){const r=n.agents.map(s=>({agentId:s.agentId,role:Hw(s.agentId),deskId:s.agentId}));Dn.getState().initAgentsBatch(r)}}async function uI(e,t){try{const n=await e.request("agents.list");if(n!=null&&n.agents){lI(n.agents),t(n.agents);const r=n.agents.map(s=>{var o;return{agentId:s.id,role:((o=s.identity)==null?void 0:o.name)??s.name??s.id,deskId:s.id}});Dn.getState().initAgentsBatch(r)}}catch{}}async function dI(e,t,n){try{const s=(await e.request("config.get",{keys:["agents.defaults.subagents","tools.agentToAgent"]})).value;if(s){const o=s["agents.defaults.subagents"];o!=null&&o.maxConcurrent&&o.maxConcurrent>=1&&o.maxConcurrent<=50&&t(o.maxConcurrent);const u=s["tools.agentToAgent"];u&&n({enabled:u.enabled??!1,allow:Array.isArray(u.allow)?u.allow:[]})}}catch{}}function fI(){const[e,t]=S.useState(()=>Xv());return S.useEffect(()=>{const n=matchMedia("(max-width: 767px)"),r=matchMedia("(min-width: 768px) and (max-width: 1023px)");function s(){t(Xv())}return n.addEventListener("change",s),r.addEventListener("change",s),()=>{n.removeEventListener("change",s),r.removeEventListener("change",s)}},[]),e}function Xv(){if(typeof window>"u")return{isMobile:!1,isTablet:!1,isDesktop:!0};const e=window.innerWidth;return{isMobile:e<768,isTablet:e>=768&&e<1024,isDesktop:e>=1024}}const hI=S.lazy(()=>El(()=>import("./Scene3D-DEX7kPiS.js"),[]));function gI(){const{t:e}=se("office");return c.jsx("div",{className:"flex h-full w-full items-center justify-center bg-gray-50 dark:bg-gray-950",children:c.jsxs("div",{className:"flex flex-col items-center gap-3",children:[c.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-blue-500 border-t-transparent"}),c.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:e("loading3D")})]})})}function mI(){const e=ie(o=>o.viewMode),[t,n]=S.useState(!1),[r,s]=S.useState(e);return S.useEffect(()=>{if(e!==r){n(!0);const o=setTimeout(()=>{s(e),n(!1)},150);return()=>clearTimeout(o)}},[e,r]),c.jsx("div",{className:"h-full w-full transition-opacity duration-300",style:{opacity:t?0:1,position:"relative"},children:r==="2d"?c.jsx(Ez,{}):c.jsx(S.Suspense,{fallback:c.jsx(gI,{}),children:c.jsx(hI,{})})})}function pI(){const e=ie(t=>t.theme);return S.useEffect(()=>{document.documentElement.setAttribute("data-theme",e),e==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")},[e]),null}const yI={"/":"office","/living-office":"office","/dashboard":"dashboard","/agents":"agents","/channels":"channels","/skills":"skills","/cron":"cron","/settings":"settings"};function xI(e,t){const n=e.trim();if(n.startsWith("ws://")||n.startsWith("wss://"))return n;if(n.startsWith("http://")||n.startsWith("https://")){const r=new URL(n);return r.protocol=r.protocol==="https:"?"wss:":"ws:",r.toString()}return n.startsWith("/")?`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}${n}`:t}function bI(){const e=Zt(),t=ie(n=>n.setCurrentPage);return S.useEffect(()=>{const n=yI[e.pathname]??"office";t(n)},[e.pathname,t]),null}function vI(){const e=window.__OPENCLAW_CONFIG__,t=(e==null?void 0:e.gatewayUrl)||"ws://localhost:18789",n=xI((e==null?void 0:e.gatewayWsPath)||void 0||"/gateway-ws",t),r=(e==null?void 0:e.gatewayToken)||"5qd1bnvCHA2JwLn5NUBwUqKS7ZWMY37Vo2TO7pvZHc9sgL0U",{isMobile:s}=fI(),o=ie(h=>h.setViewMode),{wsClient:u,perceptionEngine:f}=sI({url:n,token:r});return S.useEffect(()=>{s&&o("2d")},[s,o]),c.jsxs(Cw,{value:f,children:[c.jsx(pI,{}),c.jsx(bI,{}),c.jsxs(dC,{children:[c.jsxs(jn,{element:c.jsx(HL,{wsClient:u,isMobile:s}),children:[c.jsx(jn,{path:"/",element:c.jsx(mI,{})}),c.jsx(jn,{path:"/living-office",element:c.jsx(gz,{})})]}),c.jsxs(jn,{element:c.jsx(BL,{}),children:[c.jsx(jn,{path:"/dashboard",element:c.jsx(I9,{})}),c.jsx(jn,{path:"/agents",element:c.jsx(y9,{})}),c.jsx(jn,{path:"/channels",element:c.jsx(A9,{})}),c.jsx(jn,{path:"/skills",element:c.jsx(D7,{})}),c.jsx(jn,{path:"/cron",element:c.jsx(T9,{})}),c.jsx(jn,{path:"/settings",element:c.jsx(c7,{})})]}),c.jsx(jn,{path:"*",element:c.jsx(cC,{to:"/",replace:!0})})]})]})}dj.createRoot(document.getElementById("root")).render(c.jsx(S.StrictMode,{children:c.jsx(LC,{children:c.jsx(vI,{})})}));export{Hi as P,Ml as S,Me as Z,Fh as _,KN as a,sj as b,T3 as c,S as d,Ar as e,dj as f,mg as g,ie as h,jI as i,c as j,ZE as k,wI as l,SI as p,Wc as r,se as u};
|