blade-code 0.10.30 → 0.10.31
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/blade.js +2 -2
- package/dist/{chunk-5m5nxkfs.js → chunk-07t42c40.js} +1 -1
- package/dist/{chunk-9pww3s5m.js → chunk-0ew7vmkb.js} +1 -1
- package/dist/{chunk-4qyhtrhx.js → chunk-0qjzgs1d.js} +1 -1
- package/dist/{chunk-82jdnt03.js → chunk-1905jhyj.js} +2 -2
- package/dist/chunk-1pr72n4c.js +1 -0
- package/dist/{chunk-hdr8bcxt.js → chunk-1v251p73.js} +1 -1
- package/dist/chunk-1y3jpc4s.js +1 -0
- package/dist/{chunk-8gv6hsrf.js → chunk-2nga4tsd.js} +2 -2
- package/dist/{chunk-qs9wwe8d.js → chunk-2q06pq10.js} +1 -1
- package/dist/{chunk-1444wfhr.js → chunk-2rmt821w.js} +2 -2
- package/dist/{chunk-1zpqxjj7.js → chunk-321dpgd3.js} +1 -1
- package/dist/{chunk-4p9cwr9s.js → chunk-3fzevvzm.js} +2 -2
- package/dist/chunk-3gbrc75h.js +1 -0
- package/dist/{chunk-m8jen593.js → chunk-44ep1v89.js} +3 -3
- package/dist/chunk-6pwgtmw3.js +1 -0
- package/dist/chunk-7b81rbkw.js +1 -0
- package/dist/{chunk-heydawsf.js → chunk-7gsqx900.js} +2 -2
- package/dist/{chunk-2d35rmyg.js → chunk-7hs1n09m.js} +2 -2
- package/dist/{chunk-4djps7bz.js → chunk-86phvby9.js} +1 -1
- package/dist/{chunk-fr3kysfm.js → chunk-93zgz6v6.js} +1 -1
- package/dist/{chunk-vx8a7e1j.js → chunk-9afqfajf.js} +2 -2
- package/dist/{chunk-gdp6fg4e.js → chunk-9jkbhaec.js} +1 -1
- package/dist/{chunk-37se34rx.js → chunk-9wy7xryc.js} +1 -1
- package/dist/chunk-a83cdn7b.js +1 -0
- package/dist/{chunk-mbrgz77y.js → chunk-aa4xya8p.js} +2 -2
- package/dist/{chunk-48tz6s0s.js → chunk-anm5phza.js} +2 -2
- package/dist/{chunk-x9940mcy.js → chunk-at2krx3x.js} +2 -2
- package/dist/{chunk-vz0zsct0.js → chunk-ayx03d6y.js} +1 -1
- package/dist/{chunk-d4327k1v.js → chunk-b63dfss4.js} +1 -1
- package/dist/{chunk-64hndcnj.js → chunk-bqmd7hp7.js} +1 -1
- package/dist/{chunk-1sswefqp.js → chunk-byqg8qby.js} +1 -1
- package/dist/{chunk-6kc12pma.js → chunk-c2bgj76r.js} +1 -1
- package/dist/{chunk-btfxa4w8.js → chunk-c913zbnw.js} +2 -2
- package/dist/{chunk-7e7zgzag.js → chunk-d0sej62r.js} +2 -2
- package/dist/{chunk-xr033fd3.js → chunk-fqrt55g3.js} +1 -1
- package/dist/{chunk-ej1z75jf.js → chunk-fs1r9hyz.js} +1 -1
- package/dist/chunk-hev5sqxy.js +1 -0
- package/dist/{chunk-d38t0wa2.js → chunk-hrfdc0dt.js} +1 -1
- package/dist/{chunk-s3zfyy7r.js → chunk-jmyxhygx.js} +1 -1
- package/dist/{chunk-rezjy4mp.js → chunk-khvbwbtv.js} +2 -2
- package/dist/{chunk-1ggxyyar.js → chunk-km155c83.js} +1 -1
- package/dist/{chunk-kk071ywk.js → chunk-ktwp84cv.js} +2 -2
- package/dist/chunk-nnby8asg.js +10 -0
- package/dist/{chunk-rh5g6em4.js → chunk-pgs555fv.js} +2 -2
- package/dist/{chunk-39gb49pv.js → chunk-pqsg5265.js} +1 -1
- package/dist/{chunk-d9gthet1.js → chunk-q1v03abc.js} +2 -2
- package/dist/{chunk-p6s92zj1.js → chunk-qat3ara1.js} +1 -1
- package/dist/{chunk-z5eaph4a.js → chunk-qfd0tees.js} +1 -1
- package/dist/chunk-rj3cmn4b.js +1 -0
- package/dist/{chunk-4qtb8yf6.js → chunk-s4zvf2tf.js} +2 -2
- package/dist/{chunk-kkpxmhjv.js → chunk-s6exb18e.js} +1 -1
- package/dist/{chunk-0rwz7tm0.js → chunk-s8889acm.js} +1 -1
- package/dist/{chunk-h9c7xec5.js → chunk-t857g6s9.js} +1 -1
- package/dist/{chunk-6h9d9ykg.js → chunk-tb1hr6w9.js} +1 -1
- package/dist/chunk-tps0kwhy.js +1 -0
- package/dist/chunk-tsfv04af.js +1 -0
- package/dist/chunk-v0sfs2b6.js +1 -0
- package/dist/{chunk-0prp87ys.js → chunk-v1jxren4.js} +1 -1
- package/dist/chunk-vd17dtg7.js +1 -0
- package/dist/{chunk-j7ebts5c.js → chunk-vw6z3t41.js} +1 -1
- package/dist/chunk-vy59rm9j.js +2 -0
- package/dist/{chunk-n1byt26d.js → chunk-x36dp4pj.js} +1 -1
- package/dist/{chunk-ekv4hpy8.js → chunk-xhxvde2k.js} +2 -2
- package/dist/{chunk-e3qzedvj.js → chunk-xtaq5ck1.js} +1 -1
- package/dist/{chunk-b634n0ts.js → chunk-xv1bz8f4.js} +323 -323
- package/dist/chunk-y7m792w3.js +1 -0
- package/dist/{chunk-q9ghq6jw.js → chunk-y9v884rp.js} +45 -45
- package/dist/chunk-ykjpwdba.js +1 -0
- package/dist/{chunk-qv1v32ts.js → chunk-zfpbkkdh.js} +1 -1
- package/dist/{chunk-9mamc250.js → chunk-zzkzmrjd.js} +2 -2
- package/dist/web/assets/{ChatView-CjEyCR8V.js → ChatView-SgrwGFY6.js} +5 -5
- package/dist/web/assets/{CodeBlockHighlighter-DZxXrhQO.js → CodeBlockHighlighter-BgvTBcCD.js} +1 -1
- package/dist/web/assets/{FilePreview-8fbolCzV.js → FilePreview-D1ZOOgV-.js} +1 -1
- package/dist/web/assets/{MarkdownRenderer-Bfm5TG2z.js → MarkdownRenderer-BdBwdGfs.js} +3 -3
- package/dist/web/assets/{SettingsModal-KATzS3Iy.js → SettingsModal-y7zf5Dbj.js} +1 -1
- package/dist/web/assets/{TaskSwitcher-BrfN6F0-.js → TaskSwitcher-YYFAqV6o.js} +1 -1
- package/dist/web/assets/{TerminalPanel-sbqhmFcK.js → TerminalPanel-BjA-x8tb.js} +1 -1
- package/dist/web/assets/index-7zaeanZL.css +1 -0
- package/dist/web/assets/{index-xB4mFHWl.js → index-B6QL61mx.js} +4 -4
- package/dist/web/assets/{session-events-C2PMff2v.js → session-events-Bgb4zeFL.js} +9 -9
- package/dist/web/index.html +3 -3
- package/package.json +1 -1
- package/dist/chunk-2wdmt91f.js +0 -1
- package/dist/chunk-3y97cpzv.js +0 -1
- package/dist/chunk-56hphybe.js +0 -1
- package/dist/chunk-7brnbdq8.js +0 -10
- package/dist/chunk-a5yd0c77.js +0 -1
- package/dist/chunk-e269454y.js +0 -1
- package/dist/chunk-f90v5vza.js +0 -1
- package/dist/chunk-j3k3xdac.js +0 -1
- package/dist/chunk-m3epqvpc.js +0 -1
- package/dist/chunk-pdkj959x.js +0 -1
- package/dist/chunk-pwwm04bc.js +0 -1
- package/dist/chunk-s6rdv601.js +0 -2
- package/dist/chunk-szmm21q9.js +0 -1
- package/dist/chunk-x96czg8t.js +0 -1
- package/dist/chunk-xh2c6ycd.js +0 -1
- package/dist/chunk-ze8rmhs1.js +0 -1
- package/dist/web/assets/index-BC7ygRH_.css +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Ed as a}from"./chunk-s4zvf2tf.js";import"./chunk-xhxvde2k.js";import"./chunk-2nga4tsd.js";import"./chunk-07t42c40.js";import"./chunk-7gsqx900.js";import"./chunk-9wy7xryc.js";export{a as createChatServiceAsync};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{s as E}from"./chunk-
|
|
1
|
+
import{s as E}from"./chunk-t857g6s9.js";import{t as FJ}from"./chunk-xtaq5ck1.js";import{$ as o,G as l,J as i,K as r,M as a,_ as n,aa as t,ba as s,w as A}from"./chunk-xv1bz8f4.js";import{la as HJ}from"./chunk-byqg8qby.js";import"./chunk-321dpgd3.js";import{Na as v,ab as m,jb as d}from"./chunk-y9v884rp.js";import{sb as T}from"./chunk-fs1r9hyz.js";import{Lb as f,Sb as u,Vb as g,bc as M,cc as c,ec as R,hc as p,mc as _,pc as D}from"./chunk-at2krx3x.js";import"./chunk-86phvby9.js";import"./chunk-khvbwbtv.js";import"./chunk-q1v03abc.js";import"./chunk-aa4xya8p.js";import"./chunk-v508x7cg.js";import{xd as zJ}from"./chunk-c2bgj76r.js";import"./chunk-s4zvf2tf.js";import"./chunk-3fzevvzm.js";import{Id as WJ}from"./chunk-ayx03d6y.js";import"./chunk-pgs555fv.js";import"./chunk-zzkzmrjd.js";import"./chunk-v1jxren4.js";import{ne as YJ}from"./chunk-0ew7vmkb.js";import"./chunk-s8889acm.js";import"./chunk-44ep1v89.js";import"./chunk-jmyxhygx.js";import"./chunk-9afqfajf.js";import"./chunk-9jkbhaec.js";import"./chunk-0qjzgs1d.js";import{vf as I,wf as S,xf as y}from"./chunk-vy59rm9j.js";import{Bf as QJ}from"./chunk-km155c83.js";import{Ff as b}from"./chunk-xhxvde2k.js";import"./chunk-2nga4tsd.js";import{Mf as ZJ,Pf as $J}from"./chunk-07t42c40.js";import"./chunk-d0sej62r.js";import"./chunk-7hs1n09m.js";import"./chunk-b63dfss4.js";import"./chunk-7gsqx900.js";import"./chunk-9wy7xryc.js";import{Readable as KJ,Writable as UJ}from"node:stream";import*as x from"@agentclientprotocol/sdk";import{PROTOCOL_VERSION as wJ}from"@agentclientprotocol/sdk";import JJ from"node:path";import{RequestError as GJ}from"@agentclientprotocol/sdk";import{nanoid as h}from"nanoid";var G=b("Agent");function C(J){if(!J)return{};return Object.fromEntries(J.map((Z)=>[Z.name,Z.value]))}function DJ(J){if("command"in J)return{type:"stdio",command:J.command,args:J.args,env:C(J.env)};if("url"in J)return{type:J.type,url:J.url,headers:C("headers"in J?J.headers:void 0)};return null}function BJ(J){let Z={};for(let Q of J){let Y=DJ(Q);if(Y)Z[Q.name]=Y}return Z}function e(J){if(typeof J==="string")return J?[{type:"text",text:J}]:[];return J.flatMap((Z)=>{if(Z.type==="text")return Z.text?[{type:"text",text:Z.text}]:[];let Q=Z.image_url.url,Y=/^data:([^;,]+);base64,(.+)$/s.exec(Q);if(!Y)return[{type:"text",text:"[Image]"}];return[{type:"image",mimeType:Y[1]??"image/png",data:Y[2]??""}]})}function LJ(J){let Z=c(J.metadata);return Z?[{type:"text",text:M(Z)}]:e(J.content)}function VJ(J){return[`Status: ${J.status}`,`Exit code: ${J.exitCode??"null"}`,`Duration: ${(J.durationMs/1000).toFixed(3)} seconds`].join(`
|
|
2
2
|
`)}class O{id;cwd;connection;clientCapabilities;options;agent=null;runtime=null;pendingPrompt=null;pendingUserShell=null;pendingResumeRequested=!1;availableCommandsTimer=null;taskStatusUnsubscribe;destroyed=!1;messages;contextMessages;mode;constructor(J,Z,Q,Y,H={}){this.id=J;this.cwd=Z;this.connection=Q;this.clientCapabilities=Y;this.options=H;this.messages=[...H.initialMessages??[]],this.contextMessages=[...this.messages],this.mode=this.mapPermissionModeToMode(H.permissionMode)}async refreshPersistedMessages(){let[J,Z]=await Promise.all([D.loadSession(this.id,this.cwd),D.loadSessionModelContext(this.id,this.cwd)]);if(J.length>0)this.messages=J;if(Z.length>0)this.contextMessages=Z}async loadModelContextOr(J){let Z=await D.loadSessionModelContext(this.id,this.cwd);return Z.length>0?Z:[...J]}mapPermissionModeToMode(J){switch(J){case"yolo":return"yolo";case"autoEdit":return"auto-edit";case"plan":return"plan";case"default":default:return"default"}}createAgent(){if(!this.runtime)throw Error("Session runtime is unavailable");return a.createWithRuntime(this.runtime,{sessionId:this.id,...this.options.taskWorktree?{toolBlacklist:["EnterWorktree","ExitWorktree"]}:{}})}async initialize(){if(G.debug(`[AcpSession ${this.id}] Initializing...`),await D.setSessionPermissionMode(this.id,this.cwd,this.mapModeToPermissionMode()??"default"),A.initializeSession(this.connection,this.id,this.clientCapabilities,this.cwd),G.debug(`[AcpSession ${this.id}] ACP service context initialized`),await d.resolvePendingWithHandler(this.cwd,this.id,{requestConfirmation:(z)=>this.requestPermission(z)}))await this.refreshPersistedMessages();else if((this.options.initialMessages?.length??0)>0)this.contextMessages=await this.loadModelContextOr(this.options.initialMessages??[]);let Z=this.options.mcpServers?BJ(this.options.mcpServers):void 0,Q=A.getInstance().getTerminalService(this.id);if(this.runtime=await l.create({sessionId:this.id,workspaceRoot:this.cwd,permissionMode:this.mapModeToPermissionMode(),...Z?{mcpServers:Z}:{},...this.options.taskWorktree?{taskWorktree:this.options.taskWorktree}:{},...this.options.taskIsolation?{taskIsolation:this.options.taskIsolation}:{},userShellExecutor:{execute:async(z,$)=>{let F=await Q.execute(z,{cwd:$.cwd,env:$.env,timeout:$.timeoutMs,signal:$.signal,allowLocalFallback:!1,onOutput:(X)=>$.onOutput?.("stdout",X)});return{exitCode:F.exitCode,stdout:F.stdout,stderr:F.stderr,...F.error?{error:F.error}:{},timedOut:F.failureKind==="timeout",aborted:F.failureKind==="aborted"}}},...(this.options.initialMessages?.length??0)>0?{sessionStart:{isResume:!0,resumeSessionId:this.id}}:{}}),await E.recoverInterrupted(this.cwd,this.id,this.runtime))await this.refreshPersistedMessages();this.agent=await this.createAgent(),await o(this.cwd),G.debug(`[AcpSession ${this.id}] Agent created successfully`),this.taskStatusUnsubscribe?.(),this.taskStatusUnsubscribe=v.subscribe((z)=>{if(z.sessionId!==this.id||z.projectPath!==this.cwd)return;if(z.type==="task.delivery"){if(!z.properties.taskDelivery||typeof z.properties.taskDelivery!=="object")return;this.sendUpdate({sessionUpdate:"session_info_update",updatedAt:typeof z.properties.updatedAt==="string"?z.properties.updatedAt:new Date().toISOString(),_meta:{"blade/taskDelivery":z.properties.taskDelivery,...z.properties.taskWorktreeRemoved===!0?{"blade/taskWorktreeRemoved":!0}:{}}});return}if(z.type!=="task.status")return;this.sendUpdate({sessionUpdate:"session_info_update",updatedAt:typeof z.properties.updatedAt==="string"?z.properties.updatedAt:new Date().toISOString(),_meta:{"blade/taskStatus":z.properties.taskStatus,...typeof z.properties.taskStatusReason==="string"?{"blade/taskStatusReason":z.properties.taskStatusReason}:{},...z.properties.taskFailure&&typeof z.properties.taskFailure==="object"?{"blade/taskFailure":z.properties.taskFailure}:{},...typeof z.properties.taskStartedAt==="string"?{"blade/taskStartedAt":z.properties.taskStartedAt}:{},...typeof z.properties.taskCompletedAt==="string"?{"blade/taskCompletedAt":z.properties.taskCompletedAt}:{},...z.properties.taskDiffStat&&typeof z.properties.taskDiffStat==="object"?{"blade/taskDiffStat":z.properties.taskDiffStat}:{},...typeof z.properties.taskQueuePosition==="number"?{"blade/taskQueuePosition":z.properties.taskQueuePosition}:{},...typeof z.properties.taskQueueDepth==="number"?{"blade/taskQueueDepth":z.properties.taskQueueDepth}:{},...typeof z.properties.taskConcurrencyLimit==="number"?{"blade/taskConcurrencyLimit":z.properties.taskConcurrencyLimit}:{},...typeof z.properties.taskInFlight==="number"?{"blade/taskInFlight":z.properties.taskInFlight}:{}}})});let H=await this.runtime.getGoal();if(this.runtime.getPendingSteeringCount()>0||H?.status==="active"||H?.status==="verifying")if(this.options.initialMessages===void 0)this.schedulePendingResume();else this.pendingResumeRequested=!0}async replayHistory(){for(let Z of this.messages){if(!this.canSendUpdates())return;let Q=Z.role==="user"?"user_message_chunk":Z.role==="assistant"?"agent_message_chunk":void 0;if(!Q)continue;for(let Y of LJ(Z)){if(!this.canSendUpdates())return;if(!await this.sendUpdateAndWait({sessionUpdate:Q,content:Y}))return}}let J=await this.runtime?.getGoal();if(J&&!await this.sendUpdateAndWait(this.goalSessionUpdate(J)))return;if(this.pendingResumeRequested)this.schedulePendingResume()}sendAvailableCommandsDelayed(){if(this.destroyed||this.connection.signal.aborted)return;if(this.availableCommandsTimer!==null)clearTimeout(this.availableCommandsTimer);G.debug(`[AcpSession ${this.id}] Scheduling available commands update (500ms delay)`),this.availableCommandsTimer=setTimeout(()=>{if(this.availableCommandsTimer=null,this.destroyed||this.connection.signal.aborted)return;this.sendAvailableCommands()},500)}async handleSlashCommand(J,Z){try{G.debug(`[AcpSession ${this.id}] Executing slash command: ${J}`);let Q={cwd:this.cwd,surface:"acp",workspaceRoot:this.cwd,sessionId:this.id,messages:[...this.contextMessages],rewind:{listCheckpoints:async()=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.listRewindCheckpoints()},execute:async($)=>{if(!this.runtime)throw Error("Session runtime is unavailable");let F=await this.runtime.rewindSession($);return this.messages=[...F.messages],this.contextMessages=await this.loadModelContextOr(F.messages),await this.agent?.destroy(),this.agent=await this.createAgent(),F}},reasoning:{get:async()=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getReasoningConfiguration()},set:async($)=>{if(await this.setReasoningEffort($),!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getReasoningConfiguration()}},serviceTier:{get:async()=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getServiceTierConfiguration()},set:async($)=>{if(await this.setServiceTier($),!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getServiceTierConfiguration()}},responseVerbosity:{get:async()=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getResponseVerbosityConfiguration()},set:async($)=>{if(await this.setResponseVerbosity($),!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getResponseVerbosityConfiguration()}},communicationStyle:{get:async()=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getCommunicationStyleConfiguration()},set:async($)=>{if(await this.setCommunicationStyle($),!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getCommunicationStyleConfiguration()}},subagents:{list:async()=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.listSubagents()},resume:async($,F)=>{if(!this.runtime)throw Error("Session runtime is unavailable");let X=!1,j,B=(W)=>{this.sendUpdate({sessionUpdate:"tool_call_update",toolCallId:W.id,status:W.status==="completed"?"completed":"failed",content:[{type:"content",content:{type:"text",text:W.result?.message||W.result?.error||`Subagent ${W.status}`}}]})},L=this.runtime.resumeSubagent({agentId:$,prompt:F,onCompleted:(W)=>{if(X)B(W);else j=W}});if(this.sendUpdate({sessionUpdate:"tool_call",toolCallId:L.session.id,status:"in_progress",title:`Resuming ${L.session.subagentType} subagent`,content:[{type:"content",content:{type:"text",text:`Resumed from ${L.source.id} at depth ${L.session.resumeDepth}`}}],kind:this.mapToolKind("readonly")}),X=!0,j)B(j);return L}},mcp:{getCatalog:async()=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getMcpContentCatalog()},refresh:async($)=>{if(!this.runtime)throw Error("Session runtime is unavailable");await this.runtime.refreshMcpContentCatalogs($)},getPrompt:async($,F,X)=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getMcpPrompt($,F,X)},complete:async($,F,X)=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.completeMcpArgument($,F,X)},listTasks:async($)=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.listMcpTasks($)},getTask:async($)=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getMcpTask($)},cancelTask:async($,F)=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.cancelMcpTask($,F)},getLogs:async($,F)=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getMcpLogs($,F)},setLoggingLevel:async($,F)=>{if(!this.runtime)throw Error("Session runtime is unavailable");await this.runtime.setMcpLoggingLevel($,F)},getInstructions:async()=>{if(!this.runtime)throw Error("Session runtime is unavailable");return this.runtime.getMcpInstructions()}},codeReview:{run:async($,F)=>{if(!this.runtime)throw Error("Session runtime is unavailable");let X=await E.start({sessionId:this.id,projectPath:this.cwd,runtime:this.runtime,request:$,signal:F,onEvent:(L)=>{if(L.kind==="tool_start")this.sendUpdate({sessionUpdate:"tool_call",toolCallId:L.toolCall.id,status:"in_progress",title:`Review: ${L.toolCall.function.name}`,content:[],kind:this.mapToolKind(L.toolKind)});else if(L.kind==="tool_result")this.sendUpdate({sessionUpdate:"tool_call_update",toolCallId:L.toolCall.id,status:L.result.success?"completed":"failed",content:[]})}}),j=await X.completion,B=(await E.list(this.cwd,this.id)).find((L)=>L.start.reviewId===X.reviewId);if(!B)throw Error(`Review not found: ${X.reviewId}`);return await this.refreshPersistedMessages(),{reviewId:X.reviewId,status:j.status,findings:j.findings.length,content:f(B.start,j)}}},signal:Z,acp:{sendMessage:($)=>{this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:$}})},sendToolStart:($,F,X)=>{let j=`tool_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,B=this.mapToolKind(X);this.sendUpdate({sessionUpdate:"tool_call",toolCallId:j,status:"in_progress",title:`${$}`,content:[{type:"content",content:{type:"text",text:JSON.stringify(F,null,2)}}],kind:B})},sendToolResult:($,F)=>{if(F.summary)this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:F.summary}})}}},Y=await t(J,Q),H=Y.data?.action;if(H==="start_goal"||H==="resume_goal")this.schedulePendingResume();if(H==="rewind_session"&&Array.isArray(Y.data?.messages))this.messages=[...Y.data.messages],this.contextMessages=await this.loadModelContextOr(Y.data.messages);if((Y.message==="compact_completed"||Y.message==="compact_fallback")&&Y.data?.compactedMessages){this.contextMessages=[...Y.data.compactedMessages];let $=await D.loadSession(this.id,this.cwd);if($.length>0)this.messages=$}let z=Y.content||Y.message;if(z)this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:z}});if(Y.error)this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:`[FAIL] ${Y.error}`}});return{stopReason:Y.success?"end_turn":"cancelled"}}catch(Q){return G.error(`[AcpSession ${this.id}] Slash command error:`,Q),this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:`[FAIL] 命令执行失败: ${Q instanceof Error?Q.message:"未知错误"}`}}),{stopReason:"cancelled"}}}async sendAvailableCommands(){try{let J=s(this.cwd),Z=["model","permissions","theme","config","exit","ide"],Y=J.filter((H)=>!Z.includes(H.name)).map((H)=>{let z;if(H.usage){let $=H.usage.replace(/^\/\w+\s*/,"").trim();if($)z=$}if(H.aliases?.length){let $=`Aliases: ${H.aliases.join(", ")}`;z=z?`${z} | ${$}`:$}return{name:H.name,description:H.description,input:z?{hint:z}:void 0}});G.info(`[AcpSession ${this.id}] Sending available commands: ${JSON.stringify(Y.map((H)=>H.name))}`),this.sendUpdate({sessionUpdate:"available_commands_update",availableCommands:Y}),G.info(`[AcpSession ${this.id}] Sent ${Y.length} available commands`)}catch(J){G.error(`[AcpSession ${this.id}] Failed to send available commands:`,J)}}async prompt(J,Z={}){if(A.setCurrentSession(this.id),!this.agent||!this.runtime)throw Error("Session not initialized");let Q=this.resolvePrompt(J.prompt),Y=Q.content,H=Q.displayText,z=J._meta?.outputSchema??(Z.pendingInputOnly?this.runtime.getPendingSteeringMessages().find((X)=>X.outputSchema)?.outputSchema:void 0),$;if(z!==void 0)$=p(z).schema;if(H.trimStart().startsWith("!")){if($)throw Error("Output schemas cannot be combined with user shell commands");return this.handleUserShellCommand(H)}if(this.pendingPrompt){if($)throw Error("Wait for the active turn to finish before setting an output schema");if(/^\/goal(?:\s|$)/i.test(H.trim()))return this.handleSlashCommand(H,this.pendingPrompt.signal);let X=await this.runtime.enqueueSteering(Y,{allowBeforeTurn:!0});if(!X.accepted)throw Error(X.reason==="queue_full"?"Active turn steering queue is full":"Active turn is no longer steerable");if(G.debug(`[AcpSession ${this.id}] Queued steering for active turn (${X.queued})`),X.delivery==="next_turn")this.schedulePendingResume();return{stopReason:"end_turn"}}let F=new AbortController;this.pendingPrompt=F;try{if(G.debug(`[AcpSession ${this.id}] Received prompt: ${H.slice(0,100)}...`),n(H)){if($)throw Error("Output schemas cannot be combined with slash commands");return await this.handleSlashCommand(H,F.signal)}let X={sessionId:this.id,userId:"acp-user",workspaceRoot:this.cwd,messages:[...this.contextMessages],signal:F.signal,permissionMode:this.mapModeToPermissionMode(),onPermissionModeChange:async(W)=>{this.mode=this.mapPermissionModeToMode(W),this.sendUpdate({sessionUpdate:"current_mode_update",currentModeId:this.mode})},...this.options.taskWorktree?{worktreeActive:!0}:{},confirmationHandler:{requestConfirmation:async(W)=>{return this.requestPermission(W)}}},j=await m(this.agent.chatStream(Y,X,{pendingInputOnly:Z.pendingInputOnly,goalContinuationOnly:Z.goalContinuationOnly,outputSchema:$}),async(W)=>{switch(W.kind){case"content_delta":if($)break;this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:W.delta}});break;case"thinking_delta":this.sendUpdate({sessionUpdate:"agent_thought_chunk",content:{type:"text",text:W.delta}});break;case"tool_start":{let w=W.toolCall,q=w.function.name;if(q===R)break;let N=this.mapToolKind(W.toolKind),V=`Executing ${q}`;if(q==="Task"&&"function"in w)try{let P=JSON.parse(w.function.arguments),K=P.resume_from??P.resume;if(typeof K==="string")V=`Resuming ${String(P.subagent_type||"subagent")} from ${K}`}catch{}this.sendUpdate({sessionUpdate:"tool_call",toolCallId:w.id,status:"in_progress",title:V,content:[],kind:N});break}case"tool_progress":{let w=W.toolCall;if(w.function.name===R)break;this.sendUpdate({sessionUpdate:"tool_call_update",toolCallId:w.id,status:"in_progress",content:[{type:"content",content:{type:"text",text:W.update.message}}]});break}case"tool_result":{let w=W.toolCall;if(w.function.name===R)break;let q=W.result,N=[],V=q.metadata;if(V?.kind==="patch"&&Array.isArray(V.changes))for(let K of V.changes){if(!K||typeof K!=="object"||!("path"in K)||typeof K.path!=="string")continue;N.push({type:"diff",path:K.path,oldText:"oldContent"in K&&typeof K.oldContent==="string"?K.oldContent:null,newText:"newContent"in K&&typeof K.newContent==="string"?K.newContent:null})}else if(V?.kind==="edit"&&typeof V.file_path==="string"&&typeof V.oldContent==="string"&&(typeof V.newContent==="string"||V.newContent===void 0))N.push({type:"diff",path:V.file_path,oldText:V.oldContent,newText:V.newContent??null});else{let K=w.function.name,XJ=r(g(i(K,q),u));N.push({type:"content",content:{type:"text",text:XJ}})}if(w.function.name==="Task"&&(V?.verificationVerdict==="pass"||V?.verificationVerdict==="fail"||V?.verificationVerdict==="partial"))N.unshift({type:"content",content:{type:"text",text:`Verification result: ${V.verificationVerdict.toUpperCase()}`}});let P=q.success?"completed":"failed";this.sendUpdate({sessionUpdate:"tool_call_update",toolCallId:w.id,status:P,content:N});break}case"structured_output":this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:JSON.stringify(W.output)}});break;case"mcp_catalog_changed":this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:`MCP catalog r${W.revision} (${W.serverName}): +${W.added.length} -${W.removed.length} ~${W.updated.length}
|
|
3
3
|
`}});break;case"mcp_content_changed":this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:`MCP ${W.contentKind} r${W.revision} (${W.serverName}): +${W.added.length} -${W.removed.length} ~${W.updated.length}
|
|
4
4
|
`}});break;case"mcp_resource_updated":this.sendUpdate({sessionUpdate:"agent_message_chunk",content:{type:"text",text:`MCP resource updated r${W.revision} (${W.serverName}): ${W.uri}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ie as L1,je as Z0,ke as G1}from"./chunk-v1jxren4.js";import{oe as $O,pe as HO}from"./chunk-0ew7vmkb.js";import{se as Y1}from"./chunk-s8889acm.js";import{te as B0,ve as M0}from"./chunk-44ep1v89.js";import{bf as V0,cf as o1,mf as S0}from"./chunk-9afqfajf.js";import{pf as u,rf as W,uf as R1}from"./chunk-0qjzgs1d.js";import{Bf as b}from"./chunk-km155c83.js";import{Ff as h,Gf as z}from"./chunk-xhxvde2k.js";import{Tf as p0}from"./chunk-d0sej62r.js";import{Yf as w}from"./chunk-7hs1n09m.js";import J1 from"node:path";import Y$ from"node:path";import C0 from"node:fs";import J0 from"node:os";import R from"node:path";import zO from"yaml";var u$={type:"object",properties:{verdict:{type:"string",enum:["pass","fail","partial"]},summary:{type:"string",minLength:1,maxLength:2000},findings:{type:"array",maxItems:50,items:{type:"string",minLength:1,maxLength:1000}}},required:["verdict","summary","findings"],additionalProperties:!1};function c$(O){if(!O||typeof O!=="object"||Array.isArray(O))return;let $=O.verdict;return $==="pass"||$==="fail"||$==="partial"?$:void 0}var UO=`# Goal Completion Verifier
|
|
2
2
|
|
|
3
3
|
You are a fresh, independent, adversarial verifier. The parent Agent has claimed
|
|
4
4
|
that a persisted goal is complete. Your job is to refute that claim unless the
|
|
@@ -707,4 +707,4 @@ ${q.join(`
|
|
|
707
707
|
</${Q}>`:"";return{content:J,files:[...O],references:O.map(k$),triggerPaths:[...$],contentBytes:Buffer.byteLength(J,"utf8"),provenanceSha256:_0(O.map((K)=>`${K.id}:${K.contentSha256}`).join(`
|
|
708
708
|
`))}}function WO(O,$){let Q=$,q=[];for(let Z=O.length-1;Z>=0;Z-=1){let J=O[Z];if(!J)continue;let K=Buffer.byteLength(J.content,"utf8");if(K>Q)continue;q.push(J),Q-=K}return q.reverse()}class d{projectRoot;catalogSha256;definitions;byId;constructor(O,$=[]){this.projectRoot=O;this.projectRoot=O1(O),this.definitions=Object.freeze([...$].sort(Q1).map((Q)=>Object.freeze({...Q}))),this.byId=new Map(this.definitions.map((Q)=>[Q.id,Q])),this.catalogSha256=_0(this.definitions.map((Q)=>`${Q.id}:${Q.contentSha256}`).join(`
|
|
709
709
|
`))}static empty(O){return new d(O)}list(){return this.definitions.map((O)=>({id:O.id,relativePath:O.relativePath,source:O.source,kind:O.kind,conditional:O.conditional,contentSha256:O.contentSha256}))}snapshot(){return new d(this.projectRoot,this.definitions.map((O)=>({...O,patterns:O.patterns?[...O.patterns]:void 0})))}staticRules(O,$=T$){if(this.definitions.length===0)return $0([],[],"project-instructions");let Q=this.relativeSourcePath(O),q=this.definitions.filter((Z)=>!Z.conditional&&$1(Z.scopeDirectory,Q));return $0(WO(q,$),[],"project-instructions")}contextualRules(O,$,Q,q=C$){if(this.definitions.length===0)return $0([],[],"contextual-project-instructions");let Z=this.relativeSourcePath(O),J=[...new Set($.map((G)=>q1(B.relative(this.projectRoot,O1(G)))).filter(Z1))].sort(),K=new Map;for(let G of J)for(let L of this.definitions){if(Q.has(L.id))continue;if(!$1(L.scopeDirectory,G))continue;if(L.conditional){let Y=B.posix.relative(L.scopeDirectory||".",G);if(!L.patterns?.some((V)=>XO(V,{dot:!0})(Y)))continue}else if($1(L.scopeDirectory,Z))continue;K.set(L.id,L)}let X=WO([...K.values()].sort(Q1),q);return $0(X,J,"contextual-project-instructions")}hydrate(O){let $=O.map((Q)=>{let q=this.byId.get(Q.id);if(!q||q.contentSha256!==Q.contentSha256||q.relativePath!==Q.relativePath||q.source!==Q.source)throw Error(`Project rule provenance mismatch: ${Q.relativePath}`);return q});return $0([...new Map($.map((Q)=>[Q.id,Q])).values()].sort(Q1),[],"contextual-project-instructions")}relativeSourcePath(O){let $=q1(B.relative(this.projectRoot,O1(O)));if($&&!Z1($))throw Error("Project instruction source is outside the catalog root");return $}}async function P$(O,$){let Q=await m.lstat($);if(!Q.isFile()||Q.isSymbolicLink())throw Error("Project rule must be a regular file");if(Q.size>ZO)throw Error(`Project rule exceeds ${ZO} bytes`);let q=await m.realpath($),Z=q1(B.relative(O,q));if(!Z1(Z))throw Error("Project rule escapes its repository root");let J=await m.readFile(q,"utf8");if(LO(J))throw Error("Project rule contains hidden control characters");let K=w$(J),X=K.content.trim();if(!X)throw Error("Project rule content must not be empty");let G=f$(K.data.paths),L=h$(Z),Y=_0(JSON.stringify({relativePath:Z,patterns:G??[],content:X}));return{id:`${L.source}:${_0(Z).slice(0,20)}`,relativePath:Z,source:L.source,kind:L.kind,scopeDirectory:L.scopeDirectory,priority:L.priority,conditional:Boolean(G),...G?{patterns:G}:{},content:X,contentSha256:Y}}async function YO(O,$){let Q=E$(O);if(!$.projectTrusted)return d.empty(Q);let q=await m.realpath(Q),Z=_$.stream([...y$],{cwd:q,absolute:!0,dot:!0,deep:D$,onlyFiles:!0,followSymbolicLinks:!1,unique:!0,ignore:[...v$]}),J=[];for await(let L of Z)if(J.push(L.toString()),J.length>qO)throw Error(`Project rule catalog exceeds ${qO} files`);J.sort();let K=new Set(J.filter((L)=>B.basename(L)==="AGENTS.override.md").map((L)=>B.dirname(L))),X=[],G=0;for(let L of J){if(B.basename(L)==="AGENTS.md"&&K.has(B.dirname(L)))continue;try{let Y=await P$(q,L);if(G+=Buffer.byteLength(Y.content,"utf8"),G>JO)throw Error(`Project rule catalog exceeds ${JO} bytes`);X.push(Y)}catch(Y){R$.warn(`[ProjectRules] Ignoring rule: ${Y instanceof Error?Y.message:String(Y)}`)}}return new d(q,X)}var Q0=new Map,FO=[];async function p$(O){let $=await w.getInstance().getStatus(O.workspaceRoot);O.communicationStyles=await e0(O.workspaceRoot,{projectTrusted:$.state==="trusted",plugins:O.plugins.getActive()})}function d$(O){let $={...O};for(let Q of Object.values(B0))$[Q]=(O[Q]??[]).map((q)=>({...q,matcher:q.matcher?{...q.matcher}:void 0,hooks:q.hooks.map((Z)=>({...Z}))}));return $}function f2(O){FO=[...new Set(O.map(($)=>J1.resolve($)))]}async function h2(O,$={}){let Q=J1.resolve(O),q=Q0.get(Q);if(!q)q=(async()=>{let J=await w.getInstance().getStatus(Q),K=i(Q),X=P({cwd:Q}),G=T.getInstance(Q),L=z0(Q);if(K.getAllNames().length===0)K.loadFromStandardLocations(J.state==="trusted");await Promise.all([X.initialize(),G.isInitialized()?void 0:G.initialize(Q),L.isInitialized()?void 0:L.initialize(Q,[...$.cliPluginDirs??FO])]),x0(Q),await a0(Q);let Y=await e0(Q,{projectTrusted:J.state==="trusted",plugins:L.getActive()}),V=await YO(Q,{projectTrusted:J.state==="trusted"});return{workspaceRoot:Q,subagents:K,skills:X,commands:G,plugins:L,communicationStyles:Y,projectRules:V}})().catch((J)=>{throw Q0.delete(Q),J}),Q0.set(Q,q);let Z=await q;if($.reconcilePlugins)x0(Q),await a0(Q),await p$(Z);return Z}function k2(O){let $="projectRoot"in O?O.projectRoot:O.workspaceRoot;return{projectRoot:J1.resolve($),subagents:O.subagents.snapshot(),skills:O.skills.snapshot(),commands:O.commands.snapshot(),communicationStyles:O.communicationStyles?.snapshot()??HO.snapshot(),projectRules:O.projectRules?.snapshot()??d.empty($),hooks:d$("hooks"in O&&O.hooks?O.hooks:M0.getInstance().getConfig($))}}function P2(){for(let O of Q0.keys())x0(O);Q0.clear(),v.resetInstances(),k.resetInstance(),T.resetInstance(),f.resetInstance()}
|
|
710
|
-
export{u$ as
|
|
710
|
+
export{u$ as Nd,c$ as Od,W1 as Pd,i$ as Qd,t$ as Rd,i as Sd,H4 as Td,U1 as Ud,P as Vd,DO as Wd,T as Xd,o0 as Yd,j0 as Zd,f as _d,z0 as $d,a0 as ae,x0 as be,d as ce,p$ as de,f2 as ee,h2 as fe,k2 as ge,P2 as he};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-
|
|
2
|
-
import{r as b,j as e}from"./vendor-react-DG5dkZ_t.js";import{u as D,a as y,b as ue,s as Ee,c as He,d as J,D as Te,e as Ae,f as Ke,g as Fe,h as Me,i as De,j as A,k as O,B as de,_ as ze,S as qe,l as Ge,m as We,C as Je,n as Qe}from"./index-xB4mFHWl.js";import{Q as be,O as Ye,G as Xe,Y as Ze,L as F,z as et,T as ee,C as se,Z as tt,v as st,_ as rt,B as at,$ as Re,y as re,m as me,R as he,s as nt,H as it,a0 as Ie,U as ot,a1 as lt,a2 as ct,a3 as dt,P as $e,a4 as ut,X as mt,a5 as ht,a6 as xt,f as Be,a7 as pt,W as ft,a as bt}from"./vendor-icons-ICv1v-tf.js";import{k as gt,g as vt,l as kt,e as jt,t as yt,j as wt}from"./session-events-C2PMff2v.js";import{j as Nt,k as St,l as Ct,m as _e}from"./vendor-radix-DXRuAJHH.js";function ge(t){return t.split("/").filter(Boolean).at(-1)||t}function Et(){const t=D(),s=y(w=>w.sessions),r=y(w=>w.currentSessionRef),a=y(w=>w.taskDeliveryActions),o=y(w=>w.deliverTask),n=ue(w=>w.openFilePreview),[m,f]=b.useState(!1),d=s.find(w=>Ee({sessionId:w.sessionId,projectPath:w.projectPath},r));if(!(d!=null&&d.taskIsolation))return null;const l=d.taskDiffStat,v=d.taskIsolation==="worktree",i=He(d),u=a[J(i)],c=d.taskDelivery,j=(c==null?void 0:c.status)==="conflicted",N=!!(l&&(l.changedFiles>0||l.commits>0)),p=!["queued","running"].includes(d.taskStatus),E=(c==null?void 0:c.status)==="applied"||(c==null?void 0:c.status)==="discarded",k=v&&N&&p&&!E,x=l?l.additions+l.deletions:0,h=x>0&&l?l.additions/x*100:0,C=w=>{o(i,w).catch(()=>{})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex min-h-10 flex-wrap items-center gap-x-3 gap-y-1.5 border-b border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/60 px-3 py-1.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm sm:px-5",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[e.jsx(be,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate text-[hsl(var(--deck-ink))]",children:ge(d.taskSourceProjectPath||d.projectPath)})]}),e.jsx("span",{className:"text-[hsl(var(--deck-ink-faint))]/60",children:"/"}),e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[v?e.jsx(Ye,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-accent))]"}):e.jsx(be,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:v?"text-[hsl(var(--deck-accent))]":void 0,children:t(v?"artifact.env.isolated":"artifact.env.local")})]}),d.taskWorktreeBranch&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[hsl(var(--deck-ink-faint))]/60",children:"/"}),e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 truncate",title:d.taskWorktreeBranch,children:[e.jsx(Xe,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate",children:d.taskWorktreeBranch})]})]})]}),l&&e.jsxs("div",{className:"ml-auto flex max-w-full items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(Ze,{className:"h-3 w-3 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"tabular-nums",children:l.changedFiles})]}),x>0&&e.jsxs("span",{className:"relative hidden h-1.5 w-14 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] sm:inline-flex","aria-hidden":"true",children:[e.jsx("span",{className:"h-full bg-[hsl(var(--deck-accent))]",style:{width:`${h}%`}}),e.jsx("span",{className:"h-full bg-red-500/80",style:{width:`${100-h}%`}})]}),e.jsxs("span",{className:"tabular-nums text-[hsl(var(--deck-accent))]",children:["+",l.additions]}),e.jsxs("span",{className:"tabular-nums text-red-600 dark:text-red-400",children:["-",l.deletions]}),l.commits>0&&e.jsx("span",{className:"hidden tabular-nums text-[hsl(var(--deck-ink-faint))] sm:inline",children:t("artifact.commits",{count:l.commits})}),N&&(c==null?void 0:c.status)!=="discarded"&&e.jsx("button",{type:"button",onClick:()=>n({tab:"diff"}),className:"inline-flex items-center gap-1 rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] px-2 py-1 text-[hsl(var(--deck-ink))] transition hover:border-[hsl(var(--deck-accent)/0.55)] hover:text-[hsl(var(--deck-accent))]",children:t("artifact.review")}),k&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!!u,onClick:()=>C("apply"),className:"inline-flex items-center gap-1 rounded-md bg-[hsl(var(--deck-accent))] px-2 py-1 font-semibold text-white transition hover:brightness-95 disabled:cursor-wait disabled:opacity-65",children:[u==="apply"?e.jsx(F,{className:"h-3 w-3 animate-spin"}):e.jsx(et,{className:"h-3 w-3"}),t(u==="apply"?"artifact.applying":j?"artifact.retryApply":"artifact.apply")]}),e.jsx("button",{type:"button",disabled:!!u,onClick:()=>f(!0),className:"inline-flex items-center gap-1 rounded-md px-1.5 py-1 text-[hsl(var(--deck-ink-faint))] transition hover:bg-red-500/10 hover:text-red-600 disabled:cursor-wait disabled:opacity-50 dark:hover:text-red-400","aria-label":t("artifact.discard"),title:t("artifact.discard"),children:u==="discard"?e.jsx(F,{className:"h-3 w-3 animate-spin"}):e.jsx(ee,{className:"h-3 w-3"})})]}),(c==null?void 0:c.status)==="applied"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-emerald-500/10 px-2 py-1 font-semibold text-emerald-700 dark:text-emerald-300",children:[e.jsx(se,{className:"h-3 w-3"}),t("artifact.applied")]}),(c==null?void 0:c.status)==="discarded"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-[hsl(var(--deck-surface-2))] px-2 py-1 text-[hsl(var(--deck-ink-faint))]",children:[e.jsx(ee,{className:"h-3 w-3"}),t("artifact.discarded")]})]}),(c==null?void 0:c.status)==="conflicted"&&e.jsxs("div",{className:"flex w-full items-start gap-1.5 border-t border-amber-500/20 pt-1.5 text-amber-700 dark:text-amber-300",role:"alert",children:[e.jsx(tt,{className:"mt-0.5 h-3 w-3 shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsx("span",{className:"block",children:c.message||t("artifact.conflict")}),e.jsx("span",{className:"block text-[hsl(var(--deck-ink-faint))]",children:t("artifact.conflictHint")})]})]})]}),e.jsx(Te,{open:m,onOpenChange:f,children:e.jsxs(Ae,{className:"w-[calc(100%_-_2rem)] max-w-md border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] text-[hsl(var(--deck-ink))]",children:[e.jsxs(Ke,{children:[e.jsx(Fe,{children:t("artifact.discardDialog.title")}),e.jsx(Me,{className:"text-[hsl(var(--deck-ink-muted))]",children:t("artifact.discardDialog.description",{project:ge(d.taskSourceProjectPath||d.projectPath),count:(l==null?void 0:l.changedFiles)??0})})]}),e.jsx("div",{className:"rounded-lg border border-red-500/20 bg-red-500/5 px-3 py-2 text-xs leading-relaxed text-red-700 dark:text-red-300",children:t("artifact.discardDialog.warning")}),e.jsxs(De,{className:"gap-2 sm:space-x-0",children:[e.jsx("button",{type:"button",onClick:()=>f(!1),className:"rounded-md border border-[hsl(var(--deck-border))] px-3 py-2 text-sm hover:bg-[hsl(var(--deck-surface-2))]",children:t("artifact.discardDialog.cancel")}),e.jsxs("button",{type:"button",onClick:()=>{f(!1),C("discard")},className:"inline-flex items-center justify-center gap-1.5 rounded-md bg-red-600 px-3 py-2 text-sm font-semibold text-white hover:bg-red-700",children:[e.jsx(ee,{className:"h-3.5 w-3.5"}),t("artifact.discardDialog.confirm")]})]})]})})]})}const Tt=new Set(["completed","stale","failed","aborted","interrupted"]),At={completed:"chat.review.status.completed",stale:"chat.review.status.stale",failed:"chat.review.status.failed",aborted:"chat.review.status.aborted",interrupted:"chat.review.status.interrupted"},Ft={completed:"bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-500/20",stale:"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/20",failed:"bg-red-500/10 text-red-700 dark:text-red-300 border-red-500/20",aborted:"bg-zinc-500/10 text-zinc-700 dark:text-zinc-300 border-zinc-500/20",interrupted:"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/20"};function te(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}function Mt(t){const s=te(t),r=te(s==null?void 0:s.codeLocation),a=s==null?void 0:s.priority,o=s==null?void 0:s.confidenceScore,n=r==null?void 0:r.lineStart,m=r==null?void 0:r.lineEnd;if(!(typeof(s==null?void 0:s.title)!="string"||typeof s.body!="string"||a!==0&&a!==1&&a!==2&&a!==3||typeof o!="number"||!Number.isFinite(o)||typeof(r==null?void 0:r.path)!="string"||!Number.isInteger(n)||!Number.isInteger(m)))return{title:s.title,body:s.body,priority:a,confidenceScore:o,codeLocation:{path:r.path,lineStart:n,lineEnd:m}}}function Dt(t){const s=te(t),r=te(s==null?void 0:s.target);if((s==null?void 0:s.phase)!=="completed"||typeof s.status!="string"||!Tt.has(s.status)||typeof(r==null?void 0:r.label)!="string"||r.kind!=="uncommitted"&&r.kind!=="base"&&r.kind!=="commit"||typeof s.overallExplanation!="string"||!Array.isArray(s.findings))return;const a=s.findings.map(Mt);if(!a.some(o=>o===void 0))return{status:s.status,target:{kind:r.kind,label:r.label,...typeof r.reference=="string"?{reference:r.reference}:{}},overallExplanation:s.overallExplanation,findings:a,...typeof s.error=="string"?{error:s.error}:{}}}function Rt(t){const{path:s,lineStart:r,lineEnd:a}=t.codeLocation;return r===a?`${s}:L${r}`:`${s}:L${r}-${a}`}function It({report:t}){const s=D(),r=t.target.kind==="uncommitted"?s("chat.review.target.uncommitted"):t.target.kind==="base"?s("chat.review.target.base",{ref:t.target.reference??t.target.label}):s("chat.review.target.commit",{ref:t.target.reference??t.target.label});return e.jsxs("section",{"data-code-review-report":!0,className:"overflow-hidden rounded-xl border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("header",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface-2))]/60 px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[13px] font-semibold text-[hsl(var(--deck-ink))]",children:s("chat.review.title")}),e.jsxs("p",{className:"mt-0.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-faint))]",children:[s("chat.review.target"),": ",r]})]}),e.jsxs("span",{className:A("rounded-full border px-2.5 py-1 font-mono text-[10.5px] font-medium",Ft[t.status]),children:[s("chat.review.status"),": ",s(At[t.status])]})]}),e.jsxs("div",{className:"space-y-4 px-4 py-3.5",children:[e.jsx("p",{className:"whitespace-pre-wrap text-[13px] leading-6 text-[hsl(var(--deck-ink-muted))]",children:t.overallExplanation}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("h4",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.findings")}),e.jsx("span",{className:"font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:t.findings.length})]}),t.findings.length===0?e.jsx("div",{className:"rounded-lg bg-[hsl(var(--deck-surface-2))] px-3 py-2.5 text-[12px] text-[hsl(var(--deck-ink-muted))]",children:s("chat.review.noFindings")}):e.jsx("ol",{className:"space-y-2",children:t.findings.map((a,o)=>e.jsxs("li",{className:"rounded-lg border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))] px-3 py-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsx("h5",{className:"text-[12.5px] font-medium leading-5 text-[hsl(var(--deck-ink))]",children:a.title}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.confidence",{value:a.confidenceScore.toFixed(2)})})]}),e.jsx("code",{className:"mt-1 block text-[10.5px] text-[hsl(var(--deck-accent))]",children:Rt(a)}),e.jsx("p",{className:"mt-1.5 whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:a.body})]},`${a.codeLocation.path}:${a.codeLocation.lineStart}:${o}`))})]}),t.error&&e.jsxs("div",{className:"rounded-lg border border-red-500/20 bg-red-500/5 px-3 py-2 text-[11px] text-red-700 dark:text-red-300",children:[e.jsxs("span",{className:"font-medium",children:[s("chat.review.error"),":"]})," ",t.error]})]})]})}function $t({elicitation:t,messageId:s}){const r=D(),a=y(k=>k.currentSessionRef),o=y(k=>k.setElicitation),[n,m]=b.useState(()=>_t(t.details.fields??[])),[f,d]=b.useState(()=>Pt(t.details.fields??[])),[l,v]=b.useState(!1),[i,u]=b.useState(),c=t.details.fields??[],j=b.useMemo(()=>c.every(k=>{var h;if(!k.required)return!0;if(ae(k))return!!((h=f[k.name])!=null&&h.trim()||k.defaultValue!==void 0);const x=n[k.name]??k.defaultValue;return Array.isArray(x)?x.length>0:x!==void 0}),[c,f,n]);if(t.status!=="pending")return e.jsx("div",{className:"rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2 font-mono text-[12px] text-[hsl(var(--deck-ink-muted))]",children:r(t.status==="cancelled"?"interaction.elicitation.cancelled":"interaction.elicitation.responded")});const N=async(k,x)=>{if(!(!a||l)){v(!0),u(void 0);try{await O.respondToElicitation(a,t.toolCallId,{action:k,...x?{content:x}:{}}),o(s,{...t,status:"responded"})}catch(h){u(h instanceof Error?h.message:r("interaction.elicitation.failed"))}finally{v(!1)}}},p=async()=>{try{await N("accept",Lt(c,n,f))}catch(k){u(k instanceof Error?k.message:String(k))}},E=()=>{const k=t.details.url;if(!k){u("MCP URL is unavailable");return}if(!window.open(k,"_blank","noopener,noreferrer")){u("The browser blocked the external window");return}N("accept")};return e.jsxs("div",{"data-pending-interaction":"elicitation",tabIndex:-1,role:"alert",className:"space-y-4 rounded-lg border border-amber-300/70 bg-amber-50/70 p-4 outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(st,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("div",{className:"font-mono text-[12px] font-semibold text-[hsl(var(--deck-ink))]",children:[r("interaction.elicitation.title")," · ",t.details.serverName]}),e.jsx("div",{className:"font-mono text-[12px] text-[hsl(var(--deck-ink-muted))]",children:t.details.message}),e.jsx("div",{className:"font-mono text-[11px] text-amber-700 dark:text-amber-300",children:r("interaction.elicitation.warning")})]})]}),t.details.mode==="url"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] p-3 font-mono text-[11px]",children:[e.jsx("div",{className:"text-[hsl(var(--deck-ink-muted))]",children:t.details.domain}),e.jsx("div",{className:"mt-1 break-all text-[hsl(var(--deck-ink))]",children:t.details.url})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(K,{onClick:E,disabled:l,primary:!0,label:r("interaction.elicitation.open"),icon:e.jsx(rt,{className:"h-3.5 w-3.5"})}),e.jsx(K,{onClick:()=>void N("decline"),disabled:l,label:r("interaction.elicitation.decline")}),e.jsx(K,{onClick:()=>void N("cancel"),disabled:l,label:r("interaction.elicitation.cancel")})]})]}):e.jsxs("div",{className:"space-y-4",children:[c.map(k=>e.jsx(Bt,{field:k,value:n[k.name],rawValue:f[k.name]??"",onValueChange:x=>m(h=>({...h,[k.name]:x})),onRawChange:x=>d(h=>({...h,[k.name]:x}))},k.name)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(K,{onClick:()=>void p(),disabled:l||!j,primary:!0,label:r("interaction.elicitation.submit"),icon:l?e.jsx(F,{className:"h-3.5 w-3.5 animate-spin"}):null}),e.jsx(K,{onClick:()=>void N("decline"),disabled:l,label:r("interaction.elicitation.decline")}),e.jsx(K,{onClick:()=>void N("cancel"),disabled:l,label:r("interaction.elicitation.cancel")})]})]}),i&&e.jsx("div",{className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:i})]})}function Bt({field:t,value:s,rawValue:r,onValueChange:a,onRawChange:o}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{htmlFor:`mcp-elicitation-${t.name}`,className:"block font-mono text-[12px] font-medium text-[hsl(var(--deck-ink))]",children:[t.title,t.required?" *":""]}),t.description&&e.jsx("div",{className:"font-mono text-[11px] text-[hsl(var(--deck-ink-faint))]",children:t.description}),t.type==="select"||t.type==="multi-select"||t.type==="boolean"?e.jsx("div",{id:`mcp-elicitation-${t.name}`,className:"flex flex-wrap gap-2",children:Vt(t).map(n=>{const m=Array.isArray(s)?s.includes(n.value):s===n.typedValue;return e.jsx("button",{type:"button","aria-pressed":m,onClick:()=>{if(t.type==="multi-select"){const f=Array.isArray(s)?s:[];a(f.includes(n.value)?f.filter(d=>d!==n.value):[...f,n.value])}else a(n.typedValue)},className:A("rounded-md border px-3 py-2 font-mono text-[12px] transition-colors",m?"border-emerald-500 bg-emerald-50 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-200":"border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))] hover:text-[hsl(var(--deck-ink))]"),children:n.label},n.value)})}):e.jsx("input",{id:`mcp-elicitation-${t.name}`,type:Ot(t),value:r,onChange:n=>o(n.target.value),min:t.minimum,max:t.maximum,minLength:t.minLength,maxLength:t.maxLength,required:t.required,placeholder:t.defaultValue===void 0?t.required?"Required":"Optional":String(t.defaultValue),className:"w-full rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2 font-mono text-[12px] text-[hsl(var(--deck-ink))] outline-none transition-colors focus:border-amber-500 focus:ring-1 focus:ring-amber-500"})]})}function K({onClick:t,disabled:s,primary:r=!1,label:a,icon:o}){return e.jsxs("button",{type:"button",onClick:t,disabled:s,className:A("inline-flex min-h-8 items-center gap-1.5 rounded-md px-3 py-1.5 font-mono text-[12px] transition-colors disabled:cursor-wait disabled:opacity-50",r?"bg-amber-600 text-white hover:bg-amber-700":"border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))] hover:text-[hsl(var(--deck-ink))]"),children:[o,a]})}function _t(t){return Object.fromEntries(t.filter(s=>!ae(s)&&s.defaultValue!==void 0).map(s=>[s.name,Array.isArray(s.defaultValue)?[...s.defaultValue]:s.defaultValue]))}function Pt(t){return Object.fromEntries(t.filter(s=>ae(s)&&s.defaultValue!==void 0).map(s=>[s.name,String(s.defaultValue)]))}function Lt(t,s,r){var o;const a={};for(const n of t){if(ae(n)){const f=((o=r[n.name])==null?void 0:o.trim())??"";if(!f){if(n.defaultValue!==void 0)a[n.name]=n.defaultValue;else if(n.required)throw new Error(`${n.title} is required`);continue}if(n.type==="number"||n.type==="integer"){const d=Number(f);if(!Number.isFinite(d))throw new Error(`${n.title} must be a finite number`);if(n.type==="integer"&&!Number.isSafeInteger(d))throw new Error(`${n.title} must be a safe integer`);a[n.name]=d}else a[n.name]=f;continue}const m=s[n.name]??n.defaultValue;if(m===void 0){if(n.required)throw new Error(`${n.title} is required`);continue}if(Array.isArray(m)){if(n.minItems!==void 0&&m.length<n.minItems)throw new Error(`${n.title} requires at least ${n.minItems} choices`);if(n.maxItems!==void 0&&m.length>n.maxItems)throw new Error(`${n.title} allows at most ${n.maxItems} choices`)}a[n.name]=m}return a}function Vt(t){return t.type==="boolean"?[{value:"true",label:"Yes",typedValue:!0},{value:"false",label:"No",typedValue:!1}]:(t.options??[]).map(s=>({...s,typedValue:s.value}))}function ae(t){return t.type==="string"||t.type==="number"||t.type==="integer"}function Ot(t){return t.type==="number"||t.type==="integer"?"number":t.format==="email"?"email":t.format==="uri"?"url":t.format==="date"?"date":t.format==="date-time"?"datetime-local":"text"}function Ut(t){if(!t||typeof t!="object"||Array.isArray(t))return;const s=t;if(!(!s.output||typeof s.output!="object"||Array.isArray(s.output)))return{output:s.output,...typeof s.schemaDigest=="string"?{schemaDigest:s.schemaDigest}:{}}}function Ht({report:t}){const s=D(),[r,a]=b.useState(!1),o=JSON.stringify(t.output,null,2),n=async()=>{try{await navigator.clipboard.writeText(o),a(!0),window.setTimeout(()=>a(!1),1400)}catch{}};return e.jsxs("section",{"data-structured-output":!0,className:"overflow-hidden rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("header",{className:"flex min-h-9 items-center justify-between gap-3 border-b border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(at,{className:"h-3.5 w-3.5 shrink-0 text-[hsl(var(--deck-accent))]"}),e.jsx("span",{className:"font-mono text-[11px] font-semibold text-[hsl(var(--deck-ink))]",children:s("chat.structuredOutput.title")}),t.schemaDigest&&e.jsxs("span",{title:t.schemaDigest,className:"truncate font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:["sha256:",t.schemaDigest.slice(0,10)]})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":s("chat.structuredOutput.copy"),title:s("chat.structuredOutput.copy"),className:"flex h-6 w-6 shrink-0 items-center justify-center rounded text-[hsl(var(--deck-ink-faint))] hover:bg-[hsl(var(--deck-surface))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:r?e.jsx(se,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(Re,{className:"h-3.5 w-3.5"})})]}),e.jsx("pre",{className:"max-h-[440px] overflow-auto whitespace-pre p-3 font-mono text-[11px] leading-5 text-[hsl(var(--deck-ink))]",children:o})]})}const Kt=b.lazy(()=>ze(()=>import("./MarkdownRenderer-Bfm5TG2z.js").then(t=>t.M),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.MarkdownRenderer})));function ve({text:t,label:s}){const[r,a]=b.useState(!1);if(!t.trim())return null;const o=async()=>{try{await navigator.clipboard.writeText(t),a(!0),window.setTimeout(()=>a(!1),1400)}catch{}};return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:o,className:"flex h-6 w-6 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:r?e.jsx(se,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(Re,{className:"h-3.5 w-3.5"})})}function zt(){return e.jsx("div",{className:"flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] shadow-[0_1px_0_hsl(var(--deck-hairline))]",children:e.jsx(de,{size:20,pulse:!1})})}function qt(){return e.jsx("div",{className:"flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-full border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas-veil))]",children:e.jsx("span",{className:"font-mono text-[11px] font-medium text-[hsl(var(--deck-ink))]",children:"U"})})}function ke(t){let s=t;return s=s.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g,""),s=s.replace(/<file path="[^"]*">[\s\S]*?<\/file>/g,""),s=s.replace(/<attached_files>[\s\S]*?<\/attached_files>/g,""),s=s.trim(),s}function Gt(t){if(typeof t=="string")return{text:ke(t),images:[]};const s=t.filter(a=>a.type==="text").map(a=>a.text).join(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-BdBwdGfs.js","assets/index-B6QL61mx.js","assets/vendor-react-DG5dkZ_t.js","assets/vendor-radix-DXRuAJHH.js","assets/vendor-icons-ICv1v-tf.js","assets/session-events-Bgb4zeFL.js","assets/index-7zaeanZL.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as b,j as e}from"./vendor-react-DG5dkZ_t.js";import{u as D,a as y,b as ue,s as Ee,c as He,d as J,D as Te,e as Ae,f as Ke,g as Fe,h as Me,i as De,j as A,k as O,B as de,_ as ze,S as qe,l as Ge,m as We,C as Je,n as Qe}from"./index-B6QL61mx.js";import{Q as be,O as Ye,G as Xe,Y as Ze,L as M,z as et,T as ee,C as se,Z as tt,v as st,_ as rt,B as at,$ as Re,y as re,m as me,R as he,s as nt,H as it,a0 as Ie,U as ot,a1 as lt,a2 as ct,a3 as dt,P as $e,a4 as ut,X as mt,a5 as ht,a6 as xt,f as Be,a7 as pt,W as ft,a as bt}from"./vendor-icons-ICv1v-tf.js";import{k as gt,g as vt,l as kt,e as jt,t as yt,j as wt}from"./session-events-Bgb4zeFL.js";import{j as Nt,k as St,l as Ct,m as _e}from"./vendor-radix-DXRuAJHH.js";function ge(t){return t.split("/").filter(Boolean).at(-1)||t}function Et(){const t=D(),s=y(w=>w.sessions),r=y(w=>w.currentSessionRef),a=y(w=>w.taskDeliveryActions),o=y(w=>w.deliverTask),n=ue(w=>w.openFilePreview),[m,f]=b.useState(!1),d=s.find(w=>Ee({sessionId:w.sessionId,projectPath:w.projectPath},r));if(!(d!=null&&d.taskIsolation))return null;const l=d.taskDiffStat,v=d.taskIsolation==="worktree",i=He(d),u=a[J(i)],c=d.taskDelivery,j=(c==null?void 0:c.status)==="conflicted",N=!!(l&&(l.changedFiles>0||l.commits>0)),p=!["queued","running"].includes(d.taskStatus),E=(c==null?void 0:c.status)==="applied"||(c==null?void 0:c.status)==="discarded",k=v&&N&&p&&!E,x=l?l.additions+l.deletions:0,h=x>0&&l?l.additions/x*100:0,C=w=>{o(i,w).catch(()=>{})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex min-h-10 flex-wrap items-center gap-x-3 gap-y-1.5 border-b border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/60 px-3 py-1.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm sm:px-5",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[e.jsx(be,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate text-[hsl(var(--deck-ink))]",children:ge(d.taskSourceProjectPath||d.projectPath)})]}),e.jsx("span",{className:"text-[hsl(var(--deck-ink-faint))]/60",children:"/"}),e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[v?e.jsx(Ye,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-accent))]"}):e.jsx(be,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:v?"text-[hsl(var(--deck-accent))]":void 0,children:t(v?"artifact.env.isolated":"artifact.env.local")})]}),d.taskWorktreeBranch&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[hsl(var(--deck-ink-faint))]/60",children:"/"}),e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 truncate",title:d.taskWorktreeBranch,children:[e.jsx(Xe,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate",children:d.taskWorktreeBranch})]})]})]}),l&&e.jsxs("div",{className:"ml-auto flex max-w-full items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(Ze,{className:"h-3 w-3 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"tabular-nums",children:l.changedFiles})]}),x>0&&e.jsxs("span",{className:"relative hidden h-1.5 w-14 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] sm:inline-flex","aria-hidden":"true",children:[e.jsx("span",{className:"h-full bg-[hsl(var(--deck-accent))]",style:{width:`${h}%`}}),e.jsx("span",{className:"h-full bg-red-500/80",style:{width:`${100-h}%`}})]}),e.jsxs("span",{className:"tabular-nums text-[hsl(var(--deck-accent))]",children:["+",l.additions]}),e.jsxs("span",{className:"tabular-nums text-red-600 dark:text-red-400",children:["-",l.deletions]}),l.commits>0&&e.jsx("span",{className:"hidden tabular-nums text-[hsl(var(--deck-ink-faint))] sm:inline",children:t("artifact.commits",{count:l.commits})}),N&&(c==null?void 0:c.status)!=="discarded"&&e.jsx("button",{type:"button",onClick:()=>n({tab:"diff"}),className:"inline-flex items-center gap-1 rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] px-2 py-1 text-[hsl(var(--deck-ink))] transition hover:border-[hsl(var(--deck-accent)/0.55)] hover:text-[hsl(var(--deck-accent))]",children:t("artifact.review")}),k&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!!u,onClick:()=>C("apply"),className:"inline-flex items-center gap-1 rounded-md bg-[hsl(var(--deck-accent))] px-2 py-1 font-semibold text-white transition hover:brightness-95 disabled:cursor-wait disabled:opacity-65",children:[u==="apply"?e.jsx(M,{className:"h-3 w-3 animate-spin"}):e.jsx(et,{className:"h-3 w-3"}),t(u==="apply"?"artifact.applying":j?"artifact.retryApply":"artifact.apply")]}),e.jsx("button",{type:"button",disabled:!!u,onClick:()=>f(!0),className:"inline-flex items-center gap-1 rounded-md px-1.5 py-1 text-[hsl(var(--deck-ink-faint))] transition hover:bg-red-500/10 hover:text-red-600 disabled:cursor-wait disabled:opacity-50 dark:hover:text-red-400","aria-label":t("artifact.discard"),title:t("artifact.discard"),children:u==="discard"?e.jsx(M,{className:"h-3 w-3 animate-spin"}):e.jsx(ee,{className:"h-3 w-3"})})]}),(c==null?void 0:c.status)==="applied"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-emerald-500/10 px-2 py-1 font-semibold text-emerald-700 dark:text-emerald-300",children:[e.jsx(se,{className:"h-3 w-3"}),t("artifact.applied")]}),(c==null?void 0:c.status)==="discarded"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-[hsl(var(--deck-surface-2))] px-2 py-1 text-[hsl(var(--deck-ink-faint))]",children:[e.jsx(ee,{className:"h-3 w-3"}),t("artifact.discarded")]})]}),(c==null?void 0:c.status)==="conflicted"&&e.jsxs("div",{className:"flex w-full items-start gap-1.5 border-t border-amber-500/20 pt-1.5 text-amber-700 dark:text-amber-300",role:"alert",children:[e.jsx(tt,{className:"mt-0.5 h-3 w-3 shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsx("span",{className:"block",children:c.message||t("artifact.conflict")}),e.jsx("span",{className:"block text-[hsl(var(--deck-ink-faint))]",children:t("artifact.conflictHint")})]})]})]}),e.jsx(Te,{open:m,onOpenChange:f,children:e.jsxs(Ae,{className:"w-[calc(100%_-_2rem)] max-w-md border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] text-[hsl(var(--deck-ink))]",children:[e.jsxs(Ke,{children:[e.jsx(Fe,{children:t("artifact.discardDialog.title")}),e.jsx(Me,{className:"text-[hsl(var(--deck-ink-muted))]",children:t("artifact.discardDialog.description",{project:ge(d.taskSourceProjectPath||d.projectPath),count:(l==null?void 0:l.changedFiles)??0})})]}),e.jsx("div",{className:"rounded-lg border border-red-500/20 bg-red-500/5 px-3 py-2 text-xs leading-relaxed text-red-700 dark:text-red-300",children:t("artifact.discardDialog.warning")}),e.jsxs(De,{className:"gap-2 sm:space-x-0",children:[e.jsx("button",{type:"button",onClick:()=>f(!1),className:"rounded-md border border-[hsl(var(--deck-border))] px-3 py-2 text-sm hover:bg-[hsl(var(--deck-surface-2))]",children:t("artifact.discardDialog.cancel")}),e.jsxs("button",{type:"button",onClick:()=>{f(!1),C("discard")},className:"inline-flex items-center justify-center gap-1.5 rounded-md bg-red-600 px-3 py-2 text-sm font-semibold text-white hover:bg-red-700",children:[e.jsx(ee,{className:"h-3.5 w-3.5"}),t("artifact.discardDialog.confirm")]})]})]})})]})}const Tt=new Set(["completed","stale","failed","aborted","interrupted"]),At={completed:"chat.review.status.completed",stale:"chat.review.status.stale",failed:"chat.review.status.failed",aborted:"chat.review.status.aborted",interrupted:"chat.review.status.interrupted"},Ft={completed:"bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border-emerald-500/20",stale:"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/20",failed:"bg-red-500/10 text-red-700 dark:text-red-300 border-red-500/20",aborted:"bg-zinc-500/10 text-zinc-700 dark:text-zinc-300 border-zinc-500/20",interrupted:"bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/20"};function te(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}function Mt(t){const s=te(t),r=te(s==null?void 0:s.codeLocation),a=s==null?void 0:s.priority,o=s==null?void 0:s.confidenceScore,n=r==null?void 0:r.lineStart,m=r==null?void 0:r.lineEnd;if(!(typeof(s==null?void 0:s.title)!="string"||typeof s.body!="string"||a!==0&&a!==1&&a!==2&&a!==3||typeof o!="number"||!Number.isFinite(o)||typeof(r==null?void 0:r.path)!="string"||!Number.isInteger(n)||!Number.isInteger(m)))return{title:s.title,body:s.body,priority:a,confidenceScore:o,codeLocation:{path:r.path,lineStart:n,lineEnd:m}}}function Dt(t){const s=te(t),r=te(s==null?void 0:s.target);if((s==null?void 0:s.phase)!=="completed"||typeof s.status!="string"||!Tt.has(s.status)||typeof(r==null?void 0:r.label)!="string"||r.kind!=="uncommitted"&&r.kind!=="base"&&r.kind!=="commit"||typeof s.overallExplanation!="string"||!Array.isArray(s.findings))return;const a=s.findings.map(Mt);if(!a.some(o=>o===void 0))return{status:s.status,target:{kind:r.kind,label:r.label,...typeof r.reference=="string"?{reference:r.reference}:{}},overallExplanation:s.overallExplanation,findings:a,...typeof s.error=="string"?{error:s.error}:{}}}function Rt(t){const{path:s,lineStart:r,lineEnd:a}=t.codeLocation;return r===a?`${s}:L${r}`:`${s}:L${r}-${a}`}function It({report:t}){const s=D(),r=t.target.kind==="uncommitted"?s("chat.review.target.uncommitted"):t.target.kind==="base"?s("chat.review.target.base",{ref:t.target.reference??t.target.label}):s("chat.review.target.commit",{ref:t.target.reference??t.target.label});return e.jsxs("section",{"data-code-review-report":!0,className:"overflow-hidden rounded-xl border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("header",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface-2))]/60 px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[13px] font-semibold text-[hsl(var(--deck-ink))]",children:s("chat.review.title")}),e.jsxs("p",{className:"mt-0.5 font-mono text-[10.5px] text-[hsl(var(--deck-ink-faint))]",children:[s("chat.review.target"),": ",r]})]}),e.jsxs("span",{className:A("rounded-full border px-2.5 py-1 font-mono text-[10.5px] font-medium",Ft[t.status]),children:[s("chat.review.status"),": ",s(At[t.status])]})]}),e.jsxs("div",{className:"space-y-4 px-4 py-3.5",children:[e.jsx("p",{className:"whitespace-pre-wrap text-[13px] leading-6 text-[hsl(var(--deck-ink-muted))]",children:t.overallExplanation}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("h4",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.findings")}),e.jsx("span",{className:"font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:t.findings.length})]}),t.findings.length===0?e.jsx("div",{className:"rounded-lg bg-[hsl(var(--deck-surface-2))] px-3 py-2.5 text-[12px] text-[hsl(var(--deck-ink-muted))]",children:s("chat.review.noFindings")}):e.jsx("ol",{className:"space-y-2",children:t.findings.map((a,o)=>e.jsxs("li",{className:"rounded-lg border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))] px-3 py-2.5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[e.jsx("h5",{className:"text-[12.5px] font-medium leading-5 text-[hsl(var(--deck-ink))]",children:a.title}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.confidence",{value:a.confidenceScore.toFixed(2)})})]}),e.jsx("code",{className:"mt-1 block text-[10.5px] text-[hsl(var(--deck-accent))]",children:Rt(a)}),e.jsx("p",{className:"mt-1.5 whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:a.body})]},`${a.codeLocation.path}:${a.codeLocation.lineStart}:${o}`))})]}),t.error&&e.jsxs("div",{className:"rounded-lg border border-red-500/20 bg-red-500/5 px-3 py-2 text-[11px] text-red-700 dark:text-red-300",children:[e.jsxs("span",{className:"font-medium",children:[s("chat.review.error"),":"]})," ",t.error]})]})]})}function $t({elicitation:t,messageId:s}){const r=D(),a=y(k=>k.currentSessionRef),o=y(k=>k.setElicitation),[n,m]=b.useState(()=>_t(t.details.fields??[])),[f,d]=b.useState(()=>Pt(t.details.fields??[])),[l,v]=b.useState(!1),[i,u]=b.useState(),c=t.details.fields??[],j=b.useMemo(()=>c.every(k=>{var h;if(!k.required)return!0;if(ae(k))return!!((h=f[k.name])!=null&&h.trim()||k.defaultValue!==void 0);const x=n[k.name]??k.defaultValue;return Array.isArray(x)?x.length>0:x!==void 0}),[c,f,n]);if(t.status!=="pending")return e.jsx("div",{className:"rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2 font-mono text-[12px] text-[hsl(var(--deck-ink-muted))]",children:r(t.status==="cancelled"?"interaction.elicitation.cancelled":"interaction.elicitation.responded")});const N=async(k,x)=>{if(!(!a||l)){v(!0),u(void 0);try{await O.respondToElicitation(a,t.toolCallId,{action:k,...x?{content:x}:{}}),o(s,{...t,status:"responded"})}catch(h){u(h instanceof Error?h.message:r("interaction.elicitation.failed"))}finally{v(!1)}}},p=async()=>{try{await N("accept",Lt(c,n,f))}catch(k){u(k instanceof Error?k.message:String(k))}},E=()=>{const k=t.details.url;if(!k){u("MCP URL is unavailable");return}if(!window.open(k,"_blank","noopener,noreferrer")){u("The browser blocked the external window");return}N("accept")};return e.jsxs("div",{"data-pending-interaction":"elicitation",tabIndex:-1,role:"alert",className:"space-y-4 rounded-lg border border-amber-300/70 bg-amber-50/70 p-4 outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(st,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsxs("div",{className:"font-mono text-[12px] font-semibold text-[hsl(var(--deck-ink))]",children:[r("interaction.elicitation.title")," · ",t.details.serverName]}),e.jsx("div",{className:"font-mono text-[12px] text-[hsl(var(--deck-ink-muted))]",children:t.details.message}),e.jsx("div",{className:"font-mono text-[11px] text-amber-700 dark:text-amber-300",children:r("interaction.elicitation.warning")})]})]}),t.details.mode==="url"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] p-3 font-mono text-[11px]",children:[e.jsx("div",{className:"text-[hsl(var(--deck-ink-muted))]",children:t.details.domain}),e.jsx("div",{className:"mt-1 break-all text-[hsl(var(--deck-ink))]",children:t.details.url})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(K,{onClick:E,disabled:l,primary:!0,label:r("interaction.elicitation.open"),icon:e.jsx(rt,{className:"h-3.5 w-3.5"})}),e.jsx(K,{onClick:()=>void N("decline"),disabled:l,label:r("interaction.elicitation.decline")}),e.jsx(K,{onClick:()=>void N("cancel"),disabled:l,label:r("interaction.elicitation.cancel")})]})]}):e.jsxs("div",{className:"space-y-4",children:[c.map(k=>e.jsx(Bt,{field:k,value:n[k.name],rawValue:f[k.name]??"",onValueChange:x=>m(h=>({...h,[k.name]:x})),onRawChange:x=>d(h=>({...h,[k.name]:x}))},k.name)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(K,{onClick:()=>void p(),disabled:l||!j,primary:!0,label:r("interaction.elicitation.submit"),icon:l?e.jsx(M,{className:"h-3.5 w-3.5 animate-spin"}):null}),e.jsx(K,{onClick:()=>void N("decline"),disabled:l,label:r("interaction.elicitation.decline")}),e.jsx(K,{onClick:()=>void N("cancel"),disabled:l,label:r("interaction.elicitation.cancel")})]})]}),i&&e.jsx("div",{className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:i})]})}function Bt({field:t,value:s,rawValue:r,onValueChange:a,onRawChange:o}){return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{htmlFor:`mcp-elicitation-${t.name}`,className:"block font-mono text-[12px] font-medium text-[hsl(var(--deck-ink))]",children:[t.title,t.required?" *":""]}),t.description&&e.jsx("div",{className:"font-mono text-[11px] text-[hsl(var(--deck-ink-faint))]",children:t.description}),t.type==="select"||t.type==="multi-select"||t.type==="boolean"?e.jsx("div",{id:`mcp-elicitation-${t.name}`,className:"flex flex-wrap gap-2",children:Vt(t).map(n=>{const m=Array.isArray(s)?s.includes(n.value):s===n.typedValue;return e.jsx("button",{type:"button","aria-pressed":m,onClick:()=>{if(t.type==="multi-select"){const f=Array.isArray(s)?s:[];a(f.includes(n.value)?f.filter(d=>d!==n.value):[...f,n.value])}else a(n.typedValue)},className:A("rounded-md border px-3 py-2 font-mono text-[12px] transition-colors",m?"border-emerald-500 bg-emerald-50 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-200":"border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))] hover:text-[hsl(var(--deck-ink))]"),children:n.label},n.value)})}):e.jsx("input",{id:`mcp-elicitation-${t.name}`,type:Ot(t),value:r,onChange:n=>o(n.target.value),min:t.minimum,max:t.maximum,minLength:t.minLength,maxLength:t.maxLength,required:t.required,placeholder:t.defaultValue===void 0?t.required?"Required":"Optional":String(t.defaultValue),className:"w-full rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2 font-mono text-[12px] text-[hsl(var(--deck-ink))] outline-none transition-colors focus:border-amber-500 focus:ring-1 focus:ring-amber-500"})]})}function K({onClick:t,disabled:s,primary:r=!1,label:a,icon:o}){return e.jsxs("button",{type:"button",onClick:t,disabled:s,className:A("inline-flex min-h-8 items-center gap-1.5 rounded-md px-3 py-1.5 font-mono text-[12px] transition-colors disabled:cursor-wait disabled:opacity-50",r?"bg-amber-600 text-white hover:bg-amber-700":"border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))] hover:text-[hsl(var(--deck-ink))]"),children:[o,a]})}function _t(t){return Object.fromEntries(t.filter(s=>!ae(s)&&s.defaultValue!==void 0).map(s=>[s.name,Array.isArray(s.defaultValue)?[...s.defaultValue]:s.defaultValue]))}function Pt(t){return Object.fromEntries(t.filter(s=>ae(s)&&s.defaultValue!==void 0).map(s=>[s.name,String(s.defaultValue)]))}function Lt(t,s,r){var o;const a={};for(const n of t){if(ae(n)){const f=((o=r[n.name])==null?void 0:o.trim())??"";if(!f){if(n.defaultValue!==void 0)a[n.name]=n.defaultValue;else if(n.required)throw new Error(`${n.title} is required`);continue}if(n.type==="number"||n.type==="integer"){const d=Number(f);if(!Number.isFinite(d))throw new Error(`${n.title} must be a finite number`);if(n.type==="integer"&&!Number.isSafeInteger(d))throw new Error(`${n.title} must be a safe integer`);a[n.name]=d}else a[n.name]=f;continue}const m=s[n.name]??n.defaultValue;if(m===void 0){if(n.required)throw new Error(`${n.title} is required`);continue}if(Array.isArray(m)){if(n.minItems!==void 0&&m.length<n.minItems)throw new Error(`${n.title} requires at least ${n.minItems} choices`);if(n.maxItems!==void 0&&m.length>n.maxItems)throw new Error(`${n.title} allows at most ${n.maxItems} choices`)}a[n.name]=m}return a}function Vt(t){return t.type==="boolean"?[{value:"true",label:"Yes",typedValue:!0},{value:"false",label:"No",typedValue:!1}]:(t.options??[]).map(s=>({...s,typedValue:s.value}))}function ae(t){return t.type==="string"||t.type==="number"||t.type==="integer"}function Ot(t){return t.type==="number"||t.type==="integer"?"number":t.format==="email"?"email":t.format==="uri"?"url":t.format==="date"?"date":t.format==="date-time"?"datetime-local":"text"}function Ut(t){if(!t||typeof t!="object"||Array.isArray(t))return;const s=t;if(!(!s.output||typeof s.output!="object"||Array.isArray(s.output)))return{output:s.output,...typeof s.schemaDigest=="string"?{schemaDigest:s.schemaDigest}:{}}}function Ht({report:t}){const s=D(),[r,a]=b.useState(!1),o=JSON.stringify(t.output,null,2),n=async()=>{try{await navigator.clipboard.writeText(o),a(!0),window.setTimeout(()=>a(!1),1400)}catch{}};return e.jsxs("section",{"data-structured-output":!0,className:"overflow-hidden rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("header",{className:"flex min-h-9 items-center justify-between gap-3 border-b border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(at,{className:"h-3.5 w-3.5 shrink-0 text-[hsl(var(--deck-accent))]"}),e.jsx("span",{className:"font-mono text-[11px] font-semibold text-[hsl(var(--deck-ink))]",children:s("chat.structuredOutput.title")}),t.schemaDigest&&e.jsxs("span",{title:t.schemaDigest,className:"truncate font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:["sha256:",t.schemaDigest.slice(0,10)]})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":s("chat.structuredOutput.copy"),title:s("chat.structuredOutput.copy"),className:"flex h-6 w-6 shrink-0 items-center justify-center rounded text-[hsl(var(--deck-ink-faint))] hover:bg-[hsl(var(--deck-surface))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:r?e.jsx(se,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(Re,{className:"h-3.5 w-3.5"})})]}),e.jsx("pre",{className:"max-h-[440px] overflow-auto whitespace-pre p-3 font-mono text-[11px] leading-5 text-[hsl(var(--deck-ink))]",children:o})]})}const Kt=b.lazy(()=>ze(()=>import("./MarkdownRenderer-BdBwdGfs.js").then(t=>t.M),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.MarkdownRenderer})));function ve({text:t,label:s}){const[r,a]=b.useState(!1);if(!t.trim())return null;const o=async()=>{try{await navigator.clipboard.writeText(t),a(!0),window.setTimeout(()=>a(!1),1400)}catch{}};return e.jsx("button",{type:"button","aria-label":s,title:s,onClick:o,className:"flex h-6 w-6 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))] hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:r?e.jsx(se,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(Re,{className:"h-3.5 w-3.5"})})}function zt(){return e.jsx("div",{className:"flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] shadow-[0_1px_0_hsl(var(--deck-hairline))]",children:e.jsx(de,{size:20,pulse:!1})})}function qt(){return e.jsx("div",{className:"flex h-8 w-8 shrink-0 select-none items-center justify-center rounded-full border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas-veil))]",children:e.jsx("span",{className:"font-mono text-[11px] font-medium text-[hsl(var(--deck-ink))]",children:"U"})})}function ke(t){let s=t;return s=s.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g,""),s=s.replace(/<file path="[^"]*">[\s\S]*?<\/file>/g,""),s=s.replace(/<attached_files>[\s\S]*?<\/attached_files>/g,""),s=s.trim(),s}function Gt(t){if(typeof t=="string")return{text:ke(t),images:[]};const s=t.filter(a=>a.type==="text").map(a=>a.text).join(`
|
|
3
3
|
`),r=t.filter(a=>a.type==="image_url").map(a=>a.image_url.url);return{text:ke(s),images:r}}function xe(t){return typeof t=="string"?t:t.filter(s=>s.type==="text").map(s=>s.text).join(`
|
|
4
4
|
`)}function Wt(t){const s=t.agentContent;return s?gt(s):xe(t.content)}function je({content:t,syntaxHighlight:s=!0}){return e.jsx(b.Suspense,{fallback:e.jsx("pre",{className:"text-[14px] text-[hsl(var(--deck-ink))] font-mono whitespace-pre-wrap",children:t}),children:e.jsx(Kt,{content:t,syntaxHighlight:s})})}function pe({status:t}){if(!t)return null;const s={running:"bg-[#FEF3C7] text-[#92400E] dark:bg-[#F59E0B]/20 dark:text-[#FBBF24]",success:"bg-[#DCFCE7] text-[#15803D] dark:bg-[#22C55E]/20 dark:text-[#22C55E]",error:"bg-[#FEE2E2] text-[#b91c1c] dark:bg-[#EF4444]/20 dark:text-[#fca5a5]",pending:"bg-[#E5E7EB] text-[#6B7280] dark:bg-[#27272a] dark:text-[#a1a1aa]",info:"bg-[#DBEAFE] text-[#1D4ED8] dark:bg-[#3B82F6]/20 dark:text-[#60A5FA]"},r={running:"Running",success:"Success",error:"Error",pending:"Pending",info:"Info"};return e.jsx("span",{className:A("text-[11px] px-2 py-0.5 rounded-full font-mono",s[t]),children:r[t]})}function Jt(t){if(!t)return"";if(typeof t=="string")try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}return JSON.stringify(t,null,2)}const ye=500;function Pe(t,s){if(t.length<=s)return t;let r=Math.max(0,s);return r>0&&/[\uD800-\uDBFF]/.test(t.charAt(r-1))&&(r-=1),t.slice(0,r)}function we(t,s){if(t.length<=s)return t;let r=Math.max(0,t.length-s);return/[\uDC00-\uDFFF]/.test(t.charAt(r))&&(r+=1),t.slice(r)}function oe(t,s){if(t.length<=s)return t;if(s<=0)return"";const r=`
|
|
5
5
|
... (display clipped) ...
|
|
@@ -12,7 +12,7 @@ stderr:
|
|
|
12
12
|
stdout:
|
|
13
13
|
`)){const v=o.slice(0,d),i=o.slice(d+1),u=Math.max(0,m-1),c=Math.floor(u/2);l=`${oe(v,c)}
|
|
14
14
|
${oe(i,u-c)}`}else l=oe(o,m);return{body:Pe(l,m),...a?{notice:a}:{},truncated:!!a||t.length>ye}}function Yt({tool:t}){const[s,r]=b.useState(!1),a=Jt(t.arguments),o=t.output?Qt(t.output):void 0;return e.jsxs("div",{"data-tool-name":t.toolName,"data-tool-status":t.status,"data-tool-truncated":o!=null&&o.truncated?"true":"false",className:"bg-white dark:bg-[#18181b] border border-[hsl(var(--deck-border))] rounded-lg overflow-hidden",children:[e.jsxs("button",{type:"button","aria-expanded":s,"data-tool-call-id":t.toolCallId,onClick:()=>r(n=>!n),className:"w-full flex items-center justify-between px-3 py-2 bg-[hsl(var(--deck-surface-2))] hover:bg-[hsl(var(--deck-surface))] transition-colors",children:[e.jsxs("div",{className:"flex gap-2 items-center min-w-0",children:[s?e.jsx(re,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))] shrink-0"}):e.jsx(me,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))] shrink-0"}),e.jsx("span",{className:"text-[12px] text-[hsl(var(--deck-ink))] font-mono shrink-0",children:t.toolName}),t.summary&&e.jsx("span",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono truncate",children:t.summary})]}),e.jsx(pe,{status:t.status})]}),t.status==="running"&&t.progressMessage&&e.jsxs("div",{className:"border-t border-[hsl(var(--deck-border))] px-3 py-2 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 font-mono text-[10px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsx("span",{className:"truncate",children:t.progressMessage}),t.progressTotal!==void 0&&t.progress!==void 0&&e.jsxs("span",{className:"shrink-0",children:[Math.max(0,Math.min(100,Math.round(t.progress/t.progressTotal*100))),"%"]})]}),t.progressTotal!==void 0&&t.progress!==void 0&&e.jsx("div",{role:"progressbar","aria-label":`${t.toolName} progress`,"aria-valuemin":0,"aria-valuemax":t.progressTotal,"aria-valuenow":Math.min(t.progress,t.progressTotal),className:"h-1 overflow-hidden rounded-full bg-[hsl(var(--deck-border))]",children:e.jsx("div",{className:"h-full rounded-full bg-amber-500 transition-[width] duration-150",style:{width:`${Math.max(0,Math.min(100,t.progress/t.progressTotal*100))}%`}})})]}),s&&e.jsxs("div",{className:"px-3 py-2 space-y-2 border-t border-[hsl(var(--deck-border))]",children:[a&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono",children:"Arguments"}),e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[120px] overflow-y-auto",children:a})]}),o&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono",children:"Output"}),e.jsxs("pre",{"data-tool-output":!0,className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[120px] overflow-y-auto",children:[o.body,o.notice&&e.jsxs(e.Fragment,{children:[`
|
|
15
|
-
`,e.jsx("span",{"data-tool-truncation-notice":!0,children:o.notice})]})]})]})]})]})}function Le({toolCalls:t}){return t.length===0?null:e.jsx("div",{className:"space-y-2",children:t.map(s=>e.jsx(Yt,{tool:s},s.toolCallId))})}function Xt({toolCalls:t,toolCallIds:s}){const r=D(),[a,o]=b.useState(!1),n=b.useMemo(()=>new Map(t.map(i=>[i.toolCallId,i])),[t]),m=s.flatMap(i=>{const u=n.get(i);return u?[u]:[]});if(m.length===0)return null;const f=m.filter(i=>i.status==="running").length,d=m.filter(i=>i.status==="error").length,l=[...m].reverse().find(i=>i.status==="running"&&!!i.progressMessage),v=f>0?r(m.length===1?"chat.timeline.tools.runningOne":"chat.timeline.tools.running",{count:m.length}):d>0?r(m.length===1?"chat.timeline.tools.completedOneWithError":"chat.timeline.tools.completedWithErrors",{count:m.length,errors:d}):r(m.length===1?"chat.timeline.tools.completedOne":"chat.timeline.tools.completed",{count:m.length});return e.jsxs("div",{"data-agent-tool-group":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":a,onClick:()=>o(i=>!i),className:"group flex min-h-7 w-full items-center gap-1.5 rounded-md px-1.5 text-left font-mono text-[11.5px] text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))]/65 hover:text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[a?e.jsx(re,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(me,{className:"h-3.5 w-3.5 shrink-0"}),f>0&&e.jsx(F,{className:"h-3 w-3 shrink-0 animate-spin text-[hsl(var(--deck-accent))]"}),e.jsx("span",{children:v}),(l==null?void 0:l.progressMessage)&&e.jsxs("span",{className:"min-w-0 truncate text-[10.5px] text-[hsl(var(--deck-ink-muted))]",children:[l.progressMessage,l.progress!==void 0&&l.progressTotal!==void 0&&` · ${Math.max(0,Math.min(100,Math.round(l.progress/l.progressTotal*100)))}%`]})]}),(l==null?void 0:l.progress)!==void 0&&l.progressTotal!==void 0&&e.jsx("div",{role:"progressbar","aria-label":`${l.toolName} progress`,"aria-valuemin":0,"aria-valuemax":l.progressTotal,"aria-valuenow":Math.min(l.progress,l.progressTotal),className:"mx-1.5 h-0.5 overflow-hidden rounded-full bg-[hsl(var(--deck-border))]",children:e.jsx("div",{className:"h-full rounded-full bg-amber-500 transition-[width] duration-150",style:{width:`${Math.max(0,Math.min(100,l.progress/l.progressTotal*100))}%`}})}),a&&e.jsx("div",{"data-agent-tool-group-details":!0,className:"mt-2 space-y-2 pl-1",children:e.jsx(Le,{toolCalls:m})})]})}function Zt({content:t}){const s=D(),[r,a]=b.useState(!1);return t?e.jsxs("div",{"data-agent-thinking":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":r,onClick:()=>a(o=>!o),className:"flex min-h-7 w-full items-center gap-1.5 rounded-md px-1.5 text-left font-mono text-[11.5px] text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))]/65 hover:text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[r?e.jsx(re,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}):e.jsx(me,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{children:s("chat.timeline.thinking")})]}),r&&e.jsx("div",{className:"ml-1 mt-1 border-l border-[hsl(var(--deck-border))] py-1 pl-3",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-[11px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:t})})]}):null}function es({tasks:t}){if(t.length===0)return null;const s=t.filter(a=>a.status==="completed").length,r=s===t.length;return e.jsx("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:e.jsx("div",{className:"flex gap-2 items-center",children:e.jsx("span",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:r?"✓ All tasks done":`Tasks: ${s}/${t.length}`})})})}function ts({toolCalls:t}){const s=ue(a=>a.openFilePreview),r=b.useMemo(()=>{const a=new Map,o=["Write","SearchReplace","Edit","ApplyPatch"];for(const n of t){if(n.status!=="success")continue;const m=n.metadata;if(n.toolName==="ApplyPatch"&&Array.isArray(m==null?void 0:m.changes)){for(const d of m.changes)d&&typeof d=="object"&&"path"in d&&typeof d.path=="string"&&a.set(d.path,{path:d.path,toolName:n.toolName});continue}const f=m==null?void 0:m.file_path;f&&o.includes(n.toolName)&&a.set(f,{path:f,toolName:n.toolName})}return Array.from(a.values())},[t]);return r.length===0?null:e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:[e.jsxs("div",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono mb-1.5",children:["Changed files (",r.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.map(({path:a})=>{const o=a.split("/").pop()||a;return e.jsxs("button",{onClick:()=>s({tab:"diff",targetPath:a}),className:"flex items-center gap-1 px-2 py-1 text-[11px] font-mono bg-[#E5E7EB] dark:bg-[#27272a] text-[hsl(var(--deck-ink))] rounded hover:bg-[#D1D5DB] dark:hover:bg-[#3f3f46] transition-colors",title:a,children:[e.jsx(nt,{className:"w-3 h-3"}),o]},a)})})]})}function ss({subagent:t}){var q,H,Q,Y;const s=D(),[r,a]=b.useState(null),[o,n]=b.useState(!1),[m,f]=b.useState(null),[d,l]=b.useState(!1),[v,i]=b.useState(""),[u,c]=b.useState(!1),[j,N]=b.useState(null),[p,E]=b.useState(null),[k,x]=b.useState(null),h=y(T=>T.currentSessionRef),C=y(T=>T.isStreaming),w=y(T=>T.isTemporarySession);if(!t)return null;const B=t.status==="running",M=r!==null?r:B,V=t.toolCalls||m||[],_=t.output||t.thinking||V.length>0||t.sessionId,S=p&&p.status!=="running"?p:k,I=(S==null?void 0:S.id)??t.sessionId,U=((q=S==null?void 0:S.restartRecovery)==null?void 0:q.outcome)==="failed",ne=!B&&!C&&!w&&!U&&(p==null?void 0:p.status)!=="running"&&!!(I&&h);b.useEffect(()=>{if(!M||B||!t.sessionId||!(h!=null&&h.projectPath)||m!==null||t.toolCalls&&t.toolCalls.length>0)return;let T=!0;return n(!0),O.getMessages({sessionId:t.sessionId,projectPath:h.projectPath}).then(P=>{var $,R;if(!T)return;const L=jt(P),g=new Map;for(const G of L)if((R=($=G.agentContent)==null?void 0:$.toolCalls)!=null&&R.length)for(const ie of G.agentContent.toolCalls)g.has(ie.toolCallId)||g.set(ie.toolCallId,ie);f(Array.from(g.values()))}).finally(()=>{T&&n(!1)}),()=>{T=!1}},[M,B,t.sessionId,t.toolCalls,m,h==null?void 0:h.projectPath]),b.useEffect(()=>{if(!t.sessionId||!h)return;let T=!0;const P=t.rootAgentId??t.sessionId,L=t.resumeDepth??0;return O.listSubagents(h).then(g=>{if(!T)return;x(g.find(R=>R.id===t.sessionId)??null);const $=g.filter(R=>R.id!==t.sessionId&&R.rootAgentId===P&&R.resumeDepth>L).sort((R,G)=>G.resumeDepth-R.resumeDepth||G.lastActiveAt-R.lastActiveAt)[0];$&&E($)}).catch(()=>{}),()=>{T=!1}},[h==null?void 0:h.sessionId,h==null?void 0:h.projectPath,t.sessionId,t.rootAgentId,t.resumeDepth]),b.useEffect(()=>{if(!p||p.status!=="running"||!h)return;let T=!0;const P=async()=>{try{const $=(await O.listSubagents(h)).find(R=>R.id===p.id);T&&$&&E($)}catch{}},L=window.setInterval(()=>{P()},1e3);return()=>{T=!1,window.clearInterval(L)}},[h,p==null?void 0:p.id,p==null?void 0:p.status]);const z=async()=>{if(!(!h||!I||!v.trim()||u)){c(!0),N(null);try{const T=await O.resumeSubagent(h,I,v.trim());E(T.session),i(""),l(!1),a(!0)}catch(T){N(T instanceof Error?T.message:s("chat.subagent.resumeFailed"))}finally{c(!1)}}};return e.jsxs("div",{"data-subagent-id":t.id,className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>a(!M),className:"flex gap-2 justify-between items-center w-full transition-opacity cursor-pointer hover:opacity-80",children:[e.jsxs("div",{className:"flex gap-2 items-center",children:[B&&e.jsx(F,{className:"h-3 w-3 animate-spin text-[hsl(var(--deck-ink-muted))]"}),e.jsxs("span",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:[t.type,": ",t.description]}),e.jsx(pe,{status:t.status==="completed"?"success":t.status==="failed"?"error":"running"}),t.type==="verification"&&t.verificationVerdict&&e.jsx("span",{"data-verification-verdict":t.verificationVerdict,className:A("rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide",t.verificationVerdict==="pass"?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400":t.verificationVerdict==="fail"?"bg-red-500/10 text-red-600 dark:text-red-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400"),children:t.verificationVerdict}),t.resumedFrom&&e.jsx("span",{className:"rounded bg-[#EDE9FE] px-1.5 py-0.5 text-[10px] font-mono text-[#6D28D9] dark:bg-[#2E1065] dark:text-[#C4B5FD]",title:s("chat.subagent.resumedFromTitle",{id:t.resumedFrom}),children:s("chat.subagent.resumedDepth",{depth:t.resumeDepth??1})})]}),_&&e.jsx(re,{className:A("h-3.5 w-3.5 text-[hsl(var(--deck-ink-muted))] transition-transform",M&&"rotate-180")})]}),M&&e.jsxs("div",{className:"mt-2 space-y-2",children:[(t.output||t.thinking)&&e.jsxs(e.Fragment,{children:[t.output&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[160px] overflow-y-auto",children:t.output}),t.thinking&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[120px] overflow-y-auto",children:t.thinking})]}),o&&e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono",children:[e.jsx(F,{className:"w-3 h-3 animate-spin"}),s("chat.subagent.loadingLogs")]}),!o&&V.length>0&&e.jsx(Le,{toolCalls:V}),p&&e.jsxs("div",{className:"rounded-md border border-[#DDD6FE] bg-[#F5F3FF] p-2 text-[11px] font-mono text-[#5B21B6] dark:border-[#4C1D95] dark:bg-[#1E1B4B] dark:text-[#C4B5FD]",children:[e.jsx("div",{children:s("chat.subagent.resumedAs",{id:p.id,status:p.status,depth:p.resumeDepth??1})}),(((H=p.result)==null?void 0:H.message)||((Q=p.result)==null?void 0:Q.error))&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap text-[hsl(var(--deck-ink))]",children:p.result.message||p.result.error})]}),U&&((Y=S==null?void 0:S.result)==null?void 0:Y.error)&&e.jsx("div",{role:"alert",className:"text-[11px] text-red-600",children:S.result.error}),ne&&e.jsxs("div",{className:"space-y-2",children:[d?e.jsxs("div",{className:"space-y-2 rounded-md border border-[#E5E7EB] bg-white p-2 dark:border-[#27272a] dark:bg-[#111113]",children:[e.jsx("textarea",{"aria-label":s("chat.subagent.followUpAria"),value:v,onChange:T=>i(T.target.value),placeholder:s("chat.subagent.followUpPlaceholder"),rows:3,className:"w-full resize-y rounded border border-[#D1D5DB] bg-white p-2 text-[11px] text-[#111827] outline-none focus:border-[#8B5CF6] dark:border-[#3f3f46] dark:bg-[#18181b] dark:text-[#f4f4f5]"}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{type:"button",onClick:()=>{l(!1),N(null)},className:"rounded px-2 py-1 text-[11px] text-[#6B7280] hover:bg-[#F3F4F6] dark:hover:bg-[#27272a]",children:s("chat.subagent.cancel")}),e.jsxs("button",{type:"button",onClick:()=>void z(),disabled:!v.trim()||u,className:"flex items-center gap-1 rounded bg-[#7C3AED] px-2 py-1 text-[11px] font-medium text-white disabled:opacity-50",children:[u&&e.jsx(F,{className:"w-3 h-3 animate-spin"}),s("chat.subagent.resumeAgent")]})]})]}):e.jsxs("button",{type:"button","aria-label":s("chat.subagent.resumeAria"),onClick:()=>l(!0),className:"flex items-center gap-1.5 rounded-md border border-[#D1D5DB] px-2 py-1 text-[11px] font-medium text-[#374151] transition-colors hover:bg-[#F3F4F6] dark:border-[#3f3f46] dark:text-[#d4d4d8] dark:hover:bg-[#27272a]",children:[e.jsx(he,{className:"w-3 h-3"}),s("chat.subagent.resume")]}),j&&e.jsx("div",{role:"alert",className:"text-[11px] text-red-600",children:j})]})]})]})}function rs({confirmation:t,messageId:s}){const r=D(),[a,o]=b.useState(!1),[n,m]=b.useState(null),f=y(v=>v.currentSessionRef),d=y(v=>v.setConfirmation);if(!t)return null;const l=async(v,i)=>{if(!(!f||a)){o(!0),m(null);try{await O.respondPermission(f,t.toolCallId,{approved:v,scope:i}),d(s,{...t,status:v?"approved":"denied"})}catch(u){m(u instanceof Error?u.message:r("interaction.permission.failed"))}finally{o(!1)}}};return t.status!=="pending"?null:e.jsxs("div",{"data-pending-interaction":"permission",tabIndex:-1,role:"alert",className:"space-y-3 rounded-lg border border-amber-300/70 bg-amber-50/70 p-4 outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[e.jsx("div",{className:"text-[13px] text-[hsl(var(--deck-ink))] font-mono",children:r("interaction.permission.title",{tool:t.toolName})}),e.jsx("div",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:t.description}),t.diff&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[200px] overflow-y-auto",children:t.diff}),n&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:n}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void l(!0,"once"),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#22C55E] text-white rounded-md hover:bg-[#16A34A] disabled:cursor-wait disabled:opacity-50",children:a?e.jsx(F,{className:"h-3.5 w-3.5 animate-spin"}):r("interaction.permission.once")}),t.allowRemember!==!1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>void l(!0,"session"),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#3B82F6] text-white rounded-md hover:bg-[#2563EB] disabled:cursor-wait disabled:opacity-50",children:r("interaction.permission.session")}),e.jsx("button",{type:"button",onClick:()=>void l(!0,"project"),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#6366F1] text-white rounded-md hover:bg-[#4F46E5] disabled:cursor-wait disabled:opacity-50",children:r("interaction.permission.project")})]}),e.jsx("button",{type:"button",onClick:()=>void l(!1),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#EF4444] text-white rounded-md hover:bg-[#DC2626] disabled:cursor-wait disabled:opacity-50",children:r("interaction.permission.deny")})]})]})}function as({question:t,messageId:s}){const r=D(),[a,o]=b.useState({}),[n,m]=b.useState({}),[f,d]=b.useState(!1),[l,v]=b.useState(null),i=y(p=>p.currentSessionRef),u=y(p=>p.setQuestion),c=b.useMemo(()=>t?t.questions.reduce((p,E)=>{var C;const k=(C=n[E.header])==null?void 0:C.trim(),x=a[E.header];if(E.multiSelect){const w=Array.isArray(x)?[...x]:[];return k&&w.push(k),w.length>0&&(p[E.header]=w),p}const h=k||(typeof x=="string"?x:"");return h&&(p[E.header]=h),p},{}):{},[a,n,t]),j=(t==null?void 0:t.questions.every(p=>p.header in c))??!1;if(!t)return null;const N=async()=>{if(!(!i||f||!j)){d(!0),v(null);try{await O.respondToQuestion(i,t.toolCallId,c),u(s,{...t,status:"answered",answers:c})}catch(p){v(p instanceof Error?p.message:r("interaction.question.failed"))}finally{d(!1)}}};return t.status!=="pending"?e.jsx("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:e.jsx("div",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:r("interaction.question.answered")})}):e.jsxs("div",{"data-pending-interaction":"question",tabIndex:-1,role:"alert",className:"space-y-4 rounded-lg border border-amber-300/70 bg-amber-50/70 p-4 outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[t.questions.map((p,E)=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[13px] text-[hsl(var(--deck-ink))] font-mono",children:p.question}),e.jsxs("div",{className:"space-y-1",children:[p.options.map((k,x)=>e.jsxs("button",{type:"button",onClick:()=>{if(p.multiSelect){const h=a[p.header]||[],C=h.includes(k.label)?h.filter(w=>w!==k.label):[...h,k.label];o({...a,[p.header]:C})}else o({...a,[p.header]:k.label}),m({...n,[p.header]:""})},className:A("w-full text-left px-3 py-2 rounded-md border text-[12px] font-mono transition-colors","border-[hsl(var(--deck-border))]",(p.multiSelect?(a[p.header]||[]).includes(k.label):a[p.header]===k.label)?"bg-[#DCFCE7] text-[#166534] dark:bg-[#22C55E]/20 dark:text-[#E5E5E5]":"bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))]"),children:[e.jsx("div",{children:k.label}),e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-faint))] mt-1",children:k.description})]},x)),e.jsx("input",{"aria-label":`${p.header} other response`,value:n[p.header]??"",onChange:k=>m({...n,[p.header]:k.target.value}),placeholder:r("interaction.question.other"),className:"w-full rounded-md border border-[#E5E7EB] bg-white px-3 py-2 text-[12px] text-[#111827] outline-none focus:border-[#22C55E] dark:border-[#27272a] dark:bg-[#111113] dark:text-[#E5E5E5]"})]})]},E)),l&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:l}),e.jsxs("button",{type:"button",onClick:()=>void N(),disabled:f||!j,className:"inline-flex min-h-8 items-center gap-1.5 px-3 py-1.5 text-[12px] font-mono bg-[#22C55E] text-white rounded-md hover:bg-[#16A34A] disabled:cursor-wait disabled:opacity-50",children:[f&&e.jsx(F,{className:"h-3.5 w-3.5 animate-spin"}),r("interaction.question.submit")]})]})}function ns({message:t}){const s=t.agentContent,r=y(j=>j.isStreaming&&j.currentAssistantMessageId===t.id);if(!s){const j=xe(t.content);return j?e.jsx(je,{content:j}):null}const{toolCalls:a,tasks:o,confirmation:n,question:m,elicitation:f}=s,d=vt(s),l=kt(s);if(!(l.length>0||o.length>0||d.length>0||n||m||f)&&r)return e.jsxs("div",{className:"flex items-center gap-2 text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(F,{className:"w-4 h-4 animate-spin"}),e.jsx("span",{className:"text-[12px] font-mono",children:"Thinking..."})]});const u=a.length>0&&a.every(j=>j.status==="success"||j.status==="error")&&!r,c=!r;return e.jsxs("div",{className:"space-y-3",children:[l.map(j=>j.type==="thinking"?e.jsx("div",{"data-agent-timeline-block":"thinking",children:e.jsx(Zt,{content:j.content})},j.id):j.type==="text"?e.jsx("div",{"data-agent-timeline-block":"text",children:e.jsx(je,{content:j.content,syntaxHighlight:c})},j.id):e.jsx("div",{"data-agent-timeline-block":"tool_group",children:e.jsx(Xt,{toolCalls:a,toolCallIds:j.toolCallIds})},j.id)),o.length>0&&e.jsx(es,{tasks:o}),d.map(j=>e.jsx(ss,{subagent:j},j.id)),n&&e.jsx(rs,{confirmation:n,messageId:t.id}),m&&e.jsx(as,{question:m,messageId:t.id}),f&&e.jsx($t,{elicitation:f,messageId:t.id}),u&&e.jsx(ts,{toolCalls:a})]})}function is({message:t,showAvatar:s=!0}){var f,d,l,v;const r=t.role==="user";if(t.role==="system"){const i=xe(t.content);return e.jsx("div",{"data-chat-message-id":t.id,"data-chat-role":"system",className:"flex justify-center p-2 w-full",children:e.jsx("div",{className:"text-xs text-[hsl(var(--deck-ink-muted))] bg-[#F3F4F6] dark:bg-[#18181b] px-3 py-1 rounded-full font-mono",children:i})})}if(r){const i=(f=t.metadata)!=null&&f.userShellCommand&&typeof t.metadata.userShellCommand=="object"?t.metadata.userShellCommand:(d=t.metadata)!=null&&d.userShellExecution&&typeof t.metadata.userShellExecution=="object"?t.metadata.userShellExecution:void 0;if(i){const j=typeof i.command=="string"?i.command:"",N=i.status==="running"?"running":i.status==="completed"?"success":"error",p=typeof i.output=="string"?i.output:[typeof i.stdout=="string"?i.stdout:"",typeof i.stderr=="string"&&i.stderr?`stderr:
|
|
15
|
+
`,e.jsx("span",{"data-tool-truncation-notice":!0,children:o.notice})]})]})]})]})]})}function Le({toolCalls:t}){return t.length===0?null:e.jsx("div",{className:"space-y-2",children:t.map(s=>e.jsx(Yt,{tool:s},s.toolCallId))})}function Xt({toolCalls:t,toolCallIds:s}){const r=D(),[a,o]=b.useState(!1),n=b.useMemo(()=>new Map(t.map(i=>[i.toolCallId,i])),[t]),m=s.flatMap(i=>{const u=n.get(i);return u?[u]:[]});if(m.length===0)return null;const f=m.filter(i=>i.status==="running").length,d=m.filter(i=>i.status==="error").length,l=[...m].reverse().find(i=>i.status==="running"&&!!i.progressMessage),v=f>0?r(m.length===1?"chat.timeline.tools.runningOne":"chat.timeline.tools.running",{count:m.length}):d>0?r(m.length===1?"chat.timeline.tools.completedOneWithError":"chat.timeline.tools.completedWithErrors",{count:m.length,errors:d}):r(m.length===1?"chat.timeline.tools.completedOne":"chat.timeline.tools.completed",{count:m.length});return e.jsxs("div",{"data-agent-tool-group":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":a,onClick:()=>o(i=>!i),className:"group flex min-h-7 w-full items-center gap-1.5 rounded-md px-1.5 text-left font-mono text-[11.5px] text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))]/65 hover:text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[a?e.jsx(re,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(me,{className:"h-3.5 w-3.5 shrink-0"}),f>0&&e.jsx(M,{className:"h-3 w-3 shrink-0 animate-spin text-[hsl(var(--deck-accent))]"}),e.jsx("span",{children:v}),(l==null?void 0:l.progressMessage)&&e.jsxs("span",{className:"min-w-0 truncate text-[10.5px] text-[hsl(var(--deck-ink-muted))]",children:[l.progressMessage,l.progress!==void 0&&l.progressTotal!==void 0&&` · ${Math.max(0,Math.min(100,Math.round(l.progress/l.progressTotal*100)))}%`]})]}),(l==null?void 0:l.progress)!==void 0&&l.progressTotal!==void 0&&e.jsx("div",{role:"progressbar","aria-label":`${l.toolName} progress`,"aria-valuemin":0,"aria-valuemax":l.progressTotal,"aria-valuenow":Math.min(l.progress,l.progressTotal),className:"mx-1.5 h-0.5 overflow-hidden rounded-full bg-[hsl(var(--deck-border))]",children:e.jsx("div",{className:"h-full rounded-full bg-amber-500 transition-[width] duration-150",style:{width:`${Math.max(0,Math.min(100,l.progress/l.progressTotal*100))}%`}})}),a&&e.jsx("div",{"data-agent-tool-group-details":!0,className:"mt-2 space-y-2 pl-1",children:e.jsx(Le,{toolCalls:m})})]})}function Zt({content:t}){const s=D(),[r,a]=b.useState(!1);return t?e.jsxs("div",{"data-agent-thinking":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":r,onClick:()=>a(o=>!o),className:"flex min-h-7 w-full items-center gap-1.5 rounded-md px-1.5 text-left font-mono text-[11.5px] text-[hsl(var(--deck-ink-faint))] transition-colors hover:bg-[hsl(var(--deck-surface))]/65 hover:text-[hsl(var(--deck-ink-muted))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[r?e.jsx(re,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}):e.jsx(me,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{children:s("chat.timeline.thinking")})]}),r&&e.jsx("div",{className:"ml-1 mt-1 border-l border-[hsl(var(--deck-border))] py-1 pl-3",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-[11px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:t})})]}):null}function es({tasks:t}){if(t.length===0)return null;const s=t.filter(a=>a.status==="completed").length,r=s===t.length;return e.jsx("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:e.jsx("div",{className:"flex gap-2 items-center",children:e.jsx("span",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:r?"✓ All tasks done":`Tasks: ${s}/${t.length}`})})})}function ts({toolCalls:t}){const s=ue(a=>a.openFilePreview),r=b.useMemo(()=>{const a=new Map,o=["Write","SearchReplace","Edit","ApplyPatch"];for(const n of t){if(n.status!=="success")continue;const m=n.metadata;if(n.toolName==="ApplyPatch"&&Array.isArray(m==null?void 0:m.changes)){for(const d of m.changes)d&&typeof d=="object"&&"path"in d&&typeof d.path=="string"&&a.set(d.path,{path:d.path,toolName:n.toolName});continue}const f=m==null?void 0:m.file_path;f&&o.includes(n.toolName)&&a.set(f,{path:f,toolName:n.toolName})}return Array.from(a.values())},[t]);return r.length===0?null:e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:[e.jsxs("div",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono mb-1.5",children:["Changed files (",r.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:r.map(({path:a})=>{const o=a.split("/").pop()||a;return e.jsxs("button",{onClick:()=>s({tab:"diff",targetPath:a}),className:"flex items-center gap-1 px-2 py-1 text-[11px] font-mono bg-[#E5E7EB] dark:bg-[#27272a] text-[hsl(var(--deck-ink))] rounded hover:bg-[#D1D5DB] dark:hover:bg-[#3f3f46] transition-colors",title:a,children:[e.jsx(nt,{className:"w-3 h-3"}),o]},a)})})]})}function ss({subagent:t}){var q,H,Q,Y;const s=D(),[r,a]=b.useState(null),[o,n]=b.useState(!1),[m,f]=b.useState(null),[d,l]=b.useState(!1),[v,i]=b.useState(""),[u,c]=b.useState(!1),[j,N]=b.useState(null),[p,E]=b.useState(null),[k,x]=b.useState(null),h=y(T=>T.currentSessionRef),C=y(T=>T.isStreaming),w=y(T=>T.isTemporarySession);if(!t)return null;const I=t.status==="running",F=r!==null?r:I,V=t.toolCalls||m||[],_=t.output||t.thinking||V.length>0||t.sessionId,S=p&&p.status!=="running"?p:k,$=(S==null?void 0:S.id)??t.sessionId,U=((q=S==null?void 0:S.restartRecovery)==null?void 0:q.outcome)==="failed",ne=!I&&!C&&!w&&!U&&(p==null?void 0:p.status)!=="running"&&!!($&&h);b.useEffect(()=>{if(!F||I||!t.sessionId||!(h!=null&&h.projectPath)||m!==null||t.toolCalls&&t.toolCalls.length>0)return;let T=!0;return n(!0),O.getMessages({sessionId:t.sessionId,projectPath:h.projectPath}).then(P=>{var B,R;if(!T)return;const L=jt(P),g=new Map;for(const G of L)if((R=(B=G.agentContent)==null?void 0:B.toolCalls)!=null&&R.length)for(const ie of G.agentContent.toolCalls)g.has(ie.toolCallId)||g.set(ie.toolCallId,ie);f(Array.from(g.values()))}).finally(()=>{T&&n(!1)}),()=>{T=!1}},[F,I,t.sessionId,t.toolCalls,m,h==null?void 0:h.projectPath]),b.useEffect(()=>{if(!t.sessionId||!h)return;let T=!0;const P=t.rootAgentId??t.sessionId,L=t.resumeDepth??0;return O.listSubagents(h).then(g=>{if(!T)return;x(g.find(R=>R.id===t.sessionId)??null);const B=g.filter(R=>R.id!==t.sessionId&&R.rootAgentId===P&&R.resumeDepth>L).sort((R,G)=>G.resumeDepth-R.resumeDepth||G.lastActiveAt-R.lastActiveAt)[0];B&&E(B)}).catch(()=>{}),()=>{T=!1}},[h==null?void 0:h.sessionId,h==null?void 0:h.projectPath,t.sessionId,t.rootAgentId,t.resumeDepth]),b.useEffect(()=>{if(!p||p.status!=="running"||!h)return;let T=!0;const P=async()=>{try{const B=(await O.listSubagents(h)).find(R=>R.id===p.id);T&&B&&E(B)}catch{}},L=window.setInterval(()=>{P()},1e3);return()=>{T=!1,window.clearInterval(L)}},[h,p==null?void 0:p.id,p==null?void 0:p.status]);const z=async()=>{if(!(!h||!$||!v.trim()||u)){c(!0),N(null);try{const T=await O.resumeSubagent(h,$,v.trim());E(T.session),i(""),l(!1),a(!0)}catch(T){N(T instanceof Error?T.message:s("chat.subagent.resumeFailed"))}finally{c(!1)}}};return e.jsxs("div",{"data-subagent-id":t.id,"data-subagent-session-id":t.sessionId,className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>a(!F),className:"flex gap-2 justify-between items-center w-full transition-opacity cursor-pointer hover:opacity-80",children:[e.jsxs("div",{className:"flex gap-2 items-center",children:[I&&e.jsx(M,{className:"h-3 w-3 animate-spin text-[hsl(var(--deck-ink-muted))]"}),e.jsxs("span",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:[t.type,": ",t.description]}),e.jsx(pe,{status:t.status==="completed"?"success":t.status==="failed"?"error":"running"}),t.type==="verification"&&t.verificationVerdict&&e.jsx("span",{"data-verification-verdict":t.verificationVerdict,className:A("rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide",t.verificationVerdict==="pass"?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400":t.verificationVerdict==="fail"?"bg-red-500/10 text-red-600 dark:text-red-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400"),children:t.verificationVerdict}),t.resumedFrom&&e.jsx("span",{className:"rounded bg-[#EDE9FE] px-1.5 py-0.5 text-[10px] font-mono text-[#6D28D9] dark:bg-[#2E1065] dark:text-[#C4B5FD]",title:s("chat.subagent.resumedFromTitle",{id:t.resumedFrom}),children:s("chat.subagent.resumedDepth",{depth:t.resumeDepth??1})})]}),_&&e.jsx(re,{className:A("h-3.5 w-3.5 text-[hsl(var(--deck-ink-muted))] transition-transform",F&&"rotate-180")})]}),!F&&!I&&t.output&&e.jsx("div",{"data-subagent-output-summary":!0,className:"mt-2 max-h-10 overflow-hidden whitespace-pre-wrap break-words font-mono text-[11px] text-[hsl(var(--deck-ink))]",children:t.output}),F&&e.jsxs("div",{className:"mt-2 space-y-2",children:[(t.output||t.thinking)&&e.jsxs(e.Fragment,{children:[t.output&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[160px] overflow-y-auto",children:t.output}),t.thinking&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink-muted))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[120px] overflow-y-auto",children:t.thinking})]}),o&&e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-[hsl(var(--deck-ink-muted))] font-mono",children:[e.jsx(M,{className:"w-3 h-3 animate-spin"}),s("chat.subagent.loadingLogs")]}),!o&&V.length>0&&e.jsx(Le,{toolCalls:V}),p&&e.jsxs("div",{className:"rounded-md border border-[#DDD6FE] bg-[#F5F3FF] p-2 text-[11px] font-mono text-[#5B21B6] dark:border-[#4C1D95] dark:bg-[#1E1B4B] dark:text-[#C4B5FD]",children:[e.jsx("div",{children:s("chat.subagent.resumedAs",{id:p.id,status:p.status,depth:p.resumeDepth??1})}),(((H=p.result)==null?void 0:H.message)||((Q=p.result)==null?void 0:Q.error))&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap text-[hsl(var(--deck-ink))]",children:p.result.message||p.result.error})]}),U&&((Y=S==null?void 0:S.result)==null?void 0:Y.error)&&e.jsx("div",{role:"alert",className:"text-[11px] text-red-600",children:S.result.error}),ne&&e.jsxs("div",{className:"space-y-2",children:[d?e.jsxs("div",{className:"space-y-2 rounded-md border border-[#E5E7EB] bg-white p-2 dark:border-[#27272a] dark:bg-[#111113]",children:[e.jsx("textarea",{"aria-label":s("chat.subagent.followUpAria"),value:v,onChange:T=>i(T.target.value),placeholder:s("chat.subagent.followUpPlaceholder"),rows:3,className:"w-full resize-y rounded border border-[#D1D5DB] bg-white p-2 text-[11px] text-[#111827] outline-none focus:border-[#8B5CF6] dark:border-[#3f3f46] dark:bg-[#18181b] dark:text-[#f4f4f5]"}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{type:"button",onClick:()=>{l(!1),N(null)},className:"rounded px-2 py-1 text-[11px] text-[#6B7280] hover:bg-[#F3F4F6] dark:hover:bg-[#27272a]",children:s("chat.subagent.cancel")}),e.jsxs("button",{type:"button",onClick:()=>void z(),disabled:!v.trim()||u,className:"flex items-center gap-1 rounded bg-[#7C3AED] px-2 py-1 text-[11px] font-medium text-white disabled:opacity-50",children:[u&&e.jsx(M,{className:"w-3 h-3 animate-spin"}),s("chat.subagent.resumeAgent")]})]})]}):e.jsxs("button",{type:"button","aria-label":s("chat.subagent.resumeAria"),onClick:()=>l(!0),className:"flex items-center gap-1.5 rounded-md border border-[#D1D5DB] px-2 py-1 text-[11px] font-medium text-[#374151] transition-colors hover:bg-[#F3F4F6] dark:border-[#3f3f46] dark:text-[#d4d4d8] dark:hover:bg-[#27272a]",children:[e.jsx(he,{className:"w-3 h-3"}),s("chat.subagent.resume")]}),j&&e.jsx("div",{role:"alert",className:"text-[11px] text-red-600",children:j})]})]})]})}function rs({confirmation:t,messageId:s}){const r=D(),[a,o]=b.useState(!1),[n,m]=b.useState(null),f=y(v=>v.currentSessionRef),d=y(v=>v.setConfirmation);if(!t)return null;const l=async(v,i)=>{if(!(!f||a)){o(!0),m(null);try{await O.respondPermission(f,t.toolCallId,{approved:v,scope:i}),d(s,{...t,status:v?"approved":"denied"})}catch(u){m(u instanceof Error?u.message:r("interaction.permission.failed"))}finally{o(!1)}}};return t.status!=="pending"?null:e.jsxs("div",{"data-pending-interaction":"permission",tabIndex:-1,role:"alert",className:"space-y-3 rounded-lg border border-amber-300/70 bg-amber-50/70 p-4 outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[e.jsx("div",{className:"text-[13px] text-[hsl(var(--deck-ink))] font-mono",children:r("interaction.permission.title",{tool:t.toolName})}),e.jsx("div",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:t.description}),t.diff&&e.jsx("pre",{className:"text-[11px] text-[hsl(var(--deck-ink))] bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-md p-2 overflow-x-auto whitespace-pre-wrap font-mono max-h-[200px] overflow-y-auto",children:t.diff}),n&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:n}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void l(!0,"once"),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#22C55E] text-white rounded-md hover:bg-[#16A34A] disabled:cursor-wait disabled:opacity-50",children:a?e.jsx(M,{className:"h-3.5 w-3.5 animate-spin"}):r("interaction.permission.once")}),t.allowRemember!==!1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>void l(!0,"session"),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#3B82F6] text-white rounded-md hover:bg-[#2563EB] disabled:cursor-wait disabled:opacity-50",children:r("interaction.permission.session")}),e.jsx("button",{type:"button",onClick:()=>void l(!0,"project"),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#6366F1] text-white rounded-md hover:bg-[#4F46E5] disabled:cursor-wait disabled:opacity-50",children:r("interaction.permission.project")})]}),e.jsx("button",{type:"button",onClick:()=>void l(!1),disabled:a,className:"min-h-8 px-3 py-1.5 text-[12px] font-mono bg-[#EF4444] text-white rounded-md hover:bg-[#DC2626] disabled:cursor-wait disabled:opacity-50",children:r("interaction.permission.deny")})]})]})}function as({question:t,messageId:s}){const r=D(),[a,o]=b.useState({}),[n,m]=b.useState({}),[f,d]=b.useState(!1),[l,v]=b.useState(null),i=y(p=>p.currentSessionRef),u=y(p=>p.setQuestion),c=b.useMemo(()=>t?t.questions.reduce((p,E)=>{var C;const k=(C=n[E.header])==null?void 0:C.trim(),x=a[E.header];if(E.multiSelect){const w=Array.isArray(x)?[...x]:[];return k&&w.push(k),w.length>0&&(p[E.header]=w),p}const h=k||(typeof x=="string"?x:"");return h&&(p[E.header]=h),p},{}):{},[a,n,t]),j=(t==null?void 0:t.questions.every(p=>p.header in c))??!1;if(!t)return null;const N=async()=>{if(!(!i||f||!j)){d(!0),v(null);try{await O.respondToQuestion(i,t.toolCallId,c),u(s,{...t,status:"answered",answers:c})}catch(p){v(p instanceof Error?p.message:r("interaction.question.failed"))}finally{d(!1)}}};return t.status!=="pending"?e.jsx("div",{className:"bg-[hsl(var(--deck-surface-2))] border border-[hsl(var(--deck-border))] rounded-lg px-3 py-2",children:e.jsx("div",{className:"text-[12px] text-[hsl(var(--deck-ink-muted))] font-mono",children:r("interaction.question.answered")})}):e.jsxs("div",{"data-pending-interaction":"question",tabIndex:-1,role:"alert",className:"space-y-4 rounded-lg border border-amber-300/70 bg-amber-50/70 p-4 outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-800/70 dark:bg-amber-950/25",children:[t.questions.map((p,E)=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[13px] text-[hsl(var(--deck-ink))] font-mono",children:p.question}),e.jsxs("div",{className:"space-y-1",children:[p.options.map((k,x)=>e.jsxs("button",{type:"button",onClick:()=>{if(p.multiSelect){const h=a[p.header]||[],C=h.includes(k.label)?h.filter(w=>w!==k.label):[...h,k.label];o({...a,[p.header]:C})}else o({...a,[p.header]:k.label}),m({...n,[p.header]:""})},className:A("w-full text-left px-3 py-2 rounded-md border text-[12px] font-mono transition-colors","border-[hsl(var(--deck-border))]",(p.multiSelect?(a[p.header]||[]).includes(k.label):a[p.header]===k.label)?"bg-[#DCFCE7] text-[#166534] dark:bg-[#22C55E]/20 dark:text-[#E5E5E5]":"bg-[hsl(var(--deck-surface-2))] text-[hsl(var(--deck-ink-muted))]"),children:[e.jsx("div",{children:k.label}),e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-faint))] mt-1",children:k.description})]},x)),e.jsx("input",{"aria-label":`${p.header} other response`,value:n[p.header]??"",onChange:k=>m({...n,[p.header]:k.target.value}),placeholder:r("interaction.question.other"),className:"w-full rounded-md border border-[#E5E7EB] bg-white px-3 py-2 text-[12px] text-[#111827] outline-none focus:border-[#22C55E] dark:border-[#27272a] dark:bg-[#111113] dark:text-[#E5E5E5]"})]})]},E)),l&&e.jsx("div",{role:"alert",className:"rounded-md border border-red-300/70 bg-red-50 px-2.5 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/70 dark:bg-red-950/35 dark:text-red-300",children:l}),e.jsxs("button",{type:"button",onClick:()=>void N(),disabled:f||!j,className:"inline-flex min-h-8 items-center gap-1.5 px-3 py-1.5 text-[12px] font-mono bg-[#22C55E] text-white rounded-md hover:bg-[#16A34A] disabled:cursor-wait disabled:opacity-50",children:[f&&e.jsx(M,{className:"h-3.5 w-3.5 animate-spin"}),r("interaction.question.submit")]})]})}function ns({message:t}){const s=t.agentContent,r=y(j=>j.isStreaming&&j.currentAssistantMessageId===t.id);if(!s){const j=xe(t.content);return j?e.jsx(je,{content:j}):null}const{toolCalls:a,tasks:o,confirmation:n,question:m,elicitation:f}=s,d=vt(s),l=kt(s);if(!(l.length>0||o.length>0||d.length>0||n||m||f)&&r)return e.jsxs("div",{className:"flex items-center gap-2 text-[hsl(var(--deck-ink-muted))]",children:[e.jsx(M,{className:"w-4 h-4 animate-spin"}),e.jsx("span",{className:"text-[12px] font-mono",children:"Thinking..."})]});const u=a.length>0&&a.every(j=>j.status==="success"||j.status==="error")&&!r,c=!r;return e.jsxs("div",{className:"space-y-3",children:[l.map(j=>j.type==="thinking"?e.jsx("div",{"data-agent-timeline-block":"thinking",children:e.jsx(Zt,{content:j.content})},j.id):j.type==="text"?e.jsx("div",{"data-agent-timeline-block":"text",children:e.jsx(je,{content:j.content,syntaxHighlight:c})},j.id):e.jsx("div",{"data-agent-timeline-block":"tool_group",children:e.jsx(Xt,{toolCalls:a,toolCallIds:j.toolCallIds})},j.id)),o.length>0&&e.jsx(es,{tasks:o}),d.map(j=>e.jsx(ss,{subagent:j},j.id)),n&&e.jsx(rs,{confirmation:n,messageId:t.id}),m&&e.jsx(as,{question:m,messageId:t.id}),f&&e.jsx($t,{elicitation:f,messageId:t.id}),u&&e.jsx(ts,{toolCalls:a})]})}function is({message:t,showAvatar:s=!0}){var f,d,l,v;const r=t.role==="user";if(t.role==="system"){const i=xe(t.content);return e.jsx("div",{"data-chat-message-id":t.id,"data-chat-role":"system",className:"flex justify-center p-2 w-full",children:e.jsx("div",{className:"text-xs text-[hsl(var(--deck-ink-muted))] bg-[#F3F4F6] dark:bg-[#18181b] px-3 py-1 rounded-full font-mono",children:i})})}if(r){const i=(f=t.metadata)!=null&&f.userShellCommand&&typeof t.metadata.userShellCommand=="object"?t.metadata.userShellCommand:(d=t.metadata)!=null&&d.userShellExecution&&typeof t.metadata.userShellExecution=="object"?t.metadata.userShellExecution:void 0;if(i){const j=typeof i.command=="string"?i.command:"",N=i.status==="running"?"running":i.status==="completed"?"success":"error",p=typeof i.output=="string"?i.output:[typeof i.stdout=="string"?i.stdout:"",typeof i.stderr=="string"&&i.stderr?`stderr:
|
|
16
16
|
${i.stderr}`:""].filter(Boolean).join(`
|
|
17
|
-
`);return e.jsx("div",{"data-chat-message-id":t.id,"data-chat-role":"user","data-user-shell-command":!0,className:"flex w-full justify-end p-4",children:e.jsxs("div",{className:"w-full max-w-[85%] overflow-hidden rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 truncate font-mono text-[12px] text-[hsl(var(--deck-ink))]",children:[e.jsx("span",{className:"mr-2 text-amber-600 dark:text-amber-400",children:"$"}),j]}),e.jsx(pe,{status:N})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap px-3 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))]",children:p||"(no output)"}),typeof i.exitCode=="number"&&e.jsxs("div",{className:"border-t border-[hsl(var(--deck-border))] px-3 py-1.5 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:["exit ",i.exitCode,typeof i.durationMs=="number"?` · ${(i.durationMs/1e3).toFixed(3)}s`:"",i.truncated===!0?" · truncated":""]})]})})}const{text:u,images:c}=Gt(t.content);return e.jsxs("div",{"data-chat-message-id":t.id,"data-chat-role":"user",className:"group flex gap-2 justify-end p-4 w-full items-start",children:[e.jsx("div",{className:"mt-1 flex shrink-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",children:e.jsx(ve,{text:u,label:"Copy message"})}),e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] rounded-lg px-4 py-3 max-w-[85%]",children:[u&&e.jsx("p",{className:"text-[14px] text-[hsl(var(--deck-ink))] font-mono leading-relaxed whitespace-pre-wrap",children:u}),c.length>0&&e.jsx("div",{className:A("grid gap-2",c.length===1?"grid-cols-1 mt-0":"grid-cols-2 mt-3"),children:c.map((j,N)=>e.jsx("img",{src:j,alt:`attachment-${N+1}`,className:"object-cover w-full max-h-64 rounded-md"},`${j}-${N}`))})]}),e.jsx(qt,{})]})}const o=Wt(t),n=Dt((l=t.metadata)==null?void 0:l.codeReview),m=Ut((v=t.metadata)==null?void 0:v.structuredOutput);return e.jsxs("div",{"data-chat-message-id":t.id,"data-chat-role":"assistant",className:A("group flex gap-4 justify-start w-full",s?"p-4":"px-4 pt-0 pb-3"),children:[s?e.jsx(zt,{}):e.jsx("div",{className:"w-8 shrink-0"}),e.jsxs("div",{className:"overflow-hidden flex-1 min-w-0",children:[n?e.jsx(It,{report:n}):m?e.jsx(Ht,{report:m}):e.jsx(ns,{message:t}),!m&&o.trim()&&e.jsx("div",{className:"mt-1.5 flex opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",children:e.jsx(ve,{text:o,label:"Copy response"})})]})]})}const os=b.memo(is);function ls(t,s,r){return Math.max(0,t+(r-s))}function cs(t,s,r){return Math.min(s,Math.max(0,t)+Math.max(0,r))}function Ne(t,s){return t?t.querySelector(`[data-chat-message-id="${CSS.escape(s)}"]`):null}function ds({turns:t,viewportRef:s,containerRef:r,onRevealTurn:a}){const o=D(),[n,m]=b.useState(null),[f,d]=b.useState(!1),l=b.useRef(null),v=b.useCallback(()=>{var p;const u=s.current,c=r.current;if(!u||!c||t.length===0)return;const j=u.getBoundingClientRect().top;let N=((p=t[0])==null?void 0:p.id)??null;for(const E of t){const k=Ne(c,E.id);if(k)if(k.getBoundingClientRect().top-j<=24)N=E.id;else break}m(N)},[t,s,r]);b.useEffect(()=>{const u=s.current;if(!u)return;const c=()=>{l.current===null&&(l.current=window.requestAnimationFrame(()=>{l.current=null,v()}))};return v(),u.addEventListener("scroll",c,{passive:!0}),()=>{u.removeEventListener("scroll",c),l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null)}},[v,s]);const i=b.useCallback(u=>{const c=()=>{const N=Ne(r.current,u.id);N&&(N.scrollIntoView({behavior:"smooth",block:"start"}),m(u.id))};a(u.index)?c():window.requestAnimationFrame(()=>window.requestAnimationFrame(c))},[r,a]);return t.length<2?null:e.jsx("nav",{"aria-label":o("chat.turns.aria"),className:"absolute right-1 top-1/2 z-20 hidden -translate-y-1/2 sm:block",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),onFocusCapture:()=>d(!0),onBlurCapture:u=>{u.currentTarget.contains(u.relatedTarget)||d(!1)},children:e.jsxs("div",{className:"relative flex items-center justify-end",children:[e.jsx("ul",{className:A("flex flex-col items-center gap-2 py-2 transition-opacity",f?"opacity-0":"opacity-100"),"aria-hidden":f,children:t.map(u=>e.jsx("li",{children:e.jsx("span",{className:A("block rounded-full transition-all",u.id===n?"h-2 w-2 bg-[hsl(var(--deck-accent))]":"h-1.5 w-1.5 bg-[hsl(var(--deck-ink-faint))]/40")})},u.id))}),e.jsx("div",{className:A("absolute right-0 max-h-[min(70vh,520px)] w-[280px] overflow-y-auto rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]/95 p-1 shadow-xl backdrop-blur transition-all",f?"pointer-events-auto translate-x-0 opacity-100":"pointer-events-none translate-x-2 opacity-0"),children:t.map((u,c)=>e.jsxs("button",{type:"button",onClick:()=>i(u),className:A("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u.id===n?"bg-[hsl(var(--deck-hairline))]/70 text-[hsl(var(--deck-ink))]":"text-[hsl(var(--deck-ink-muted))] hover:bg-[hsl(var(--deck-hairline))]/50 hover:text-[hsl(var(--deck-ink))]"),children:[e.jsx("span",{className:A("mt-1 h-1.5 w-1.5 shrink-0 rounded-full",u.id===n?"bg-[hsl(var(--deck-accent))]":"bg-[hsl(var(--deck-ink-faint))]/40")}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-mono text-[9.5px] uppercase tracking-[0.12em] text-[hsl(var(--deck-ink-faint))]",children:o("chat.turns.label",{n:c+1})}),e.jsx("span",{className:"line-clamp-2 text-[12px] leading-4",children:u.preview})]})]},u.id))})]})})}const Se=80;function us(t){return typeof t=="string"?t:Array.isArray(t)?t.filter(s=>s.type==="text").map(s=>s.text).join(" "):""}function ms(t){const s=us(t).replace(/\s+/g," ").trim();return s?s.length>Se?`${s.slice(0,Se-1)}…`:s:""}function hs(t){const s=[];for(let r=0;r<t.length;r+=1){const a=t[r];if(a.role!=="user"||!a.id)continue;const o=ms(a.content);o&&s.push({id:a.id,index:r,preview:o})}return s}const le=120,ce=80,xs=96;function W(t){return(t==null?void 0:t.querySelector("[data-radix-scroll-area-viewport]"))??null}function ps({messages:t,isLoading:s}){const r=D(),a=b.useRef(null),o=b.useRef(null),n=b.useRef(!0),m=b.useRef(t.length),f=b.useRef(null),[d,l]=b.useState(le),[v,i]=b.useState(!1);b.useEffect(()=>{const x=W(a.current);if(!x||!n.current)return;const h=window.requestAnimationFrame(()=>{x.scrollTop=x.scrollHeight});return()=>window.cancelAnimationFrame(h)},[t]),b.useEffect(()=>{const x=W(a.current);if(!x)return;o.current=x;const h=()=>{const w=x.scrollHeight-x.scrollTop-x.clientHeight<=xs;n.current=w,i(!w)};return h(),x.addEventListener("scroll",h,{passive:!0}),()=>x.removeEventListener("scroll",h)},[]),b.useEffect(()=>{const x=m.current;m.current=t.length,l(h=>h>=x&&t.length>x?t.length:Math.min(Math.max(h,le),t.length||le))},[t.length]);const u=Math.max(t.length-d,0),c=u,j=b.useMemo(()=>t.slice(c),[t,c]),N=b.useMemo(()=>hs(t),[t]);if(b.useLayoutEffect(()=>{var C;const x=f.current;if(!x)return;const h=W(a.current);if(f.current=null,!!h){if((C=x.element)!=null&&C.isConnected){const w=x.element.getBoundingClientRect().top-x.viewportTop;h.scrollTop+=w;return}h.scrollTop=ls(x.scrollTop,x.scrollHeight,h.scrollHeight)}},[d]),s)return e.jsx("div",{role:"status","aria-live":"polite","aria-busy":"true",className:"flex overflow-hidden flex-1 justify-center items-center px-5 py-8 min-h-0",children:e.jsxs("div",{className:"w-full max-w-[560px]",children:[e.jsxs("div",{className:"flex flex-col items-center text-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 animate-pulse rounded-full bg-[hsl(var(--deck-accent-soft))] blur-xl"}),e.jsx(de,{size:42,className:"relative"})]}),e.jsxs("div",{className:"mt-4 inline-flex items-center gap-1.5 font-mono text-[10px] uppercase tracking-[0.16em] text-[hsl(var(--deck-accent))]",children:[e.jsx(it,{className:"w-3 h-3"}),r("chat.list.loading.eyebrow")]}),e.jsx("h2",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:r("chat.list.loading.title")}),e.jsx("p",{className:"mt-1 max-w-sm text-[11.5px] leading-5 text-[hsl(var(--deck-ink-faint))]",children:r("chat.list.loading.hint")})]}),e.jsx("div",{"aria-hidden":"true",className:"mt-7 space-y-4 rounded-xl border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))]/45 px-4 py-5",children:[72,88,64].map((x,h)=>e.jsxs("div",{className:A("flex gap-3",h%2===1&&"flex-row-reverse"),children:[e.jsx("span",{className:"h-7 w-7 shrink-0 animate-pulse rounded-md bg-[hsl(var(--deck-surface-2))]"}),e.jsx("span",{className:"h-10 animate-pulse rounded-lg bg-[hsl(var(--deck-surface-2))]",style:{width:`${x}%`,animationDelay:`${h*120}ms`}})]},x))})]})});if(t.length===0&&!s)return e.jsx("div",{className:"flex flex-1 justify-center items-center",children:e.jsxs("div",{className:"flex flex-col gap-4 items-center text-center",children:[e.jsx(de,{size:44}),e.jsxs("div",{children:[e.jsx("div",{className:"deck-eyebrow text-[hsl(var(--deck-accent))]",children:r("chat.list.empty.eyebrow")}),e.jsx("div",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:r("chat.list.empty.title")}),e.jsx("div",{className:"mt-1 max-w-xs text-[12px] text-[hsl(var(--deck-ink-muted))]",children:r("chat.list.empty.hint")})]})]})});const p=()=>{const x=W(a.current);x&&(n.current=!0,i(!1),x.scrollTo({top:x.scrollHeight,behavior:"smooth"}))},E=()=>{var h;const x=W(a.current);if(x){const C=((h=a.current)==null?void 0:h.querySelector("[data-chat-message-id]"))??null;f.current={element:C,viewportTop:(C==null?void 0:C.getBoundingClientRect().top)??0,scrollHeight:x.scrollHeight,scrollTop:x.scrollTop}}l(C=>cs(C,t.length,ce))},k=x=>x>=c?!0:(l(t.length),!1);return e.jsxs("div",{ref:a,className:"relative flex-1 min-h-0",children:[e.jsx(qe,{className:"h-full",children:e.jsxs("div",{className:"flex flex-col px-4 pb-4 w-full md:px-6",children:[u>0&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx("button",{type:"button",onClick:E,"aria-label":r("chat.list.showEarlierWithRemaining",{count:Math.min(u,ce),remaining:u}),className:"rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] px-3 py-1.5 font-mono text-[12px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:border-[hsl(var(--deck-border-strong))] hover:text-[hsl(var(--deck-ink))]",children:r("chat.list.showEarlier",{count:Math.min(u,ce)})})}),j.map((x,h)=>{const C=c+h,w=C>0?t[C-1]:null,B=!w||w.role!==x.role||w.role==="user";return e.jsx(os,{message:x,showAvatar:B},x.id||`msg-${C}`)})]})}),e.jsx(ds,{turns:N,viewportRef:o,containerRef:a,onRevealTurn:k}),v&&e.jsxs("button",{type:"button",onClick:p,className:"absolute bottom-4 left-1/2 z-10 inline-flex -translate-x-1/2 items-center gap-1.5 rounded-full border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))]/95 px-3 py-1.5 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] shadow-lg backdrop-blur transition-colors hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[e.jsx(Ie,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}),r("chat.list.jumpLatest")]})]})}const fs=b.memo(ps),Ve=Nt,Oe=St,Ue=Ct,fe=b.forwardRef(({className:t,sideOffset:s=4,...r},a)=>e.jsx(_e,{ref:a,sideOffset:s,className:A("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",t),...r}));fe.displayName=_e.displayName;const bs={active:{labelKey:"goal.status.active",dot:"bg-[hsl(var(--deck-accent))] shadow-[0_0_6px_hsl(var(--deck-accent-glow)/0.5)]",accent:"text-[hsl(var(--deck-accent))]"},verifying:{labelKey:"goal.status.active",dot:"animate-pulse bg-sky-400",accent:"text-sky-600 dark:text-sky-300"},paused:{labelKey:"goal.status.paused",dot:"bg-amber-400",accent:"text-amber-600 dark:text-amber-300"},blocked:{labelKey:"goal.status.blocked",dot:"bg-rose-500",accent:"text-rose-600 dark:text-rose-300"},usage_limited:{labelKey:"goal.status.usageLimited",dot:"bg-orange-500",accent:"text-orange-600 dark:text-orange-300"},budget_limited:{labelKey:"goal.status.budgetLimited",dot:"bg-orange-500",accent:"text-orange-600 dark:text-orange-300"},complete:{labelKey:"goal.status.complete",dot:"bg-emerald-500",accent:"text-emerald-600 dark:text-emerald-300"}};function X(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function gs(t){if(t<60)return`${t}s`;const s=Math.floor(t/60),r=t%60;return r===0?`${s}m`:`${s}m ${r}s`}function vs(){var _;const t=D(),{locale:s}=Ge(),r=y(S=>S.goal),a=y(S=>S.pauseGoal),o=y(S=>S.resumeGoal),n=y(S=>S.editGoal),m=y(S=>S.clearGoal),[f,d]=b.useState(!1),[l,v]=b.useState(!1),[i,u]=b.useState(""),[c,j]=b.useState(null),[N,p]=b.useState(!1);if(b.useEffect(()=>{d(!1),v(!1),u((r==null?void 0:r.objective)??""),p(!1)},[r==null?void 0:r.goalId]),!r)return null;const E=bs[r.status],k=["active","verifying","paused","blocked"].includes(r.status),x=r.status==="active"||r.status==="verifying",h=r.status==="paused"||r.status==="blocked",C=c!==null,w=async(S,I)=>{j(S);try{await I()}finally{j(null)}},B=()=>{u(r.objective),v(!0),d(!0)},M=async S=>{S.preventDefault();const I=i.trim();if(!I||I===r.objective){v(!1);return}await w("edit",()=>n(I)),v(!1)},V=async()=>{await w("delete",m),p(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{delayDuration:250,children:e.jsxs("section",{"aria-label":t("goal.aria.section"),className:"mx-3 mb-1 shrink-0","data-blade-goal-status":r.status,children:[e.jsxs("div",{className:A("flex h-9 items-center gap-2 rounded-lg border px-3 transition-colors","border-[hsl(var(--deck-border))]/60 bg-[hsl(var(--deck-surface))]/80 backdrop-blur-sm",f&&"rounded-b-none border-b-0"),children:[r.status==="complete"?e.jsx(ot,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):e.jsx(lt,{className:A("h-3.5 w-3.5 shrink-0",E.accent)}),e.jsx("span",{className:A("h-1.5 w-1.5 shrink-0 rounded-full",E.dot)}),e.jsx("span",{className:A("shrink-0 text-[10px] font-medium leading-none",E.accent),children:r.status==="verifying"?s==="zh"?"验证中":"Verifying":t(E.labelKey)}),e.jsx("span",{className:"h-3 w-px shrink-0 bg-[hsl(var(--deck-hairline))]"}),e.jsx("button",{type:"button","aria-label":t(f?"goal.action.collapse":"goal.action.expand"),className:"min-w-0 flex-1 truncate text-left text-[12px] leading-5 text-[hsl(var(--deck-ink))]/85 outline-none transition-colors hover:text-[hsl(var(--deck-ink))]",onClick:()=>d(S=>!S),"aria-expanded":f,title:r.objective,children:r.objective}),r.tokensUsed>0&&e.jsxs("span",{className:"hidden shrink-0 text-[10px] tabular-nums text-[hsl(var(--deck-ink-muted))] sm:inline",children:[X(r.tokensUsed),r.tokenBudget!==void 0&&`/${X(r.tokenBudget)}`]}),e.jsxs("div",{className:"flex shrink-0 items-center",children:[x&&e.jsx(Z,{label:t("goal.action.pause"),disabled:C,onClick:()=>void w("pause",a),children:c==="pause"?e.jsx(F,{className:"animate-spin"}):e.jsx(ct,{})}),h&&e.jsx(Z,{label:t("goal.action.resume"),disabled:C,onClick:()=>void w("resume",o),children:c==="resume"?e.jsx(F,{className:"animate-spin"}):e.jsx(dt,{})}),e.jsx(Z,{label:t(k?"goal.action.edit":"goal.action.expand"),disabled:!k&&!f,onClick:k?B:()=>d(S=>!S),children:k?e.jsx($e,{}):e.jsx(ut,{})}),e.jsx(Z,{label:t("goal.action.delete"),disabled:C,destructive:!0,onClick:()=>p(!0),children:e.jsx(ee,{})})]})]}),f&&e.jsx("div",{className:"rounded-b-lg border border-t-0 border-[hsl(var(--deck-border))]/60 bg-[hsl(var(--deck-surface))]/80 px-4 py-3 backdrop-blur-sm",children:l?e.jsxs("form",{onSubmit:M,children:[e.jsx("textarea",{id:"goal-objective",value:i,onChange:S=>u(S.target.value),onKeyDown:S=>{S.key==="Escape"&&v(!1)},rows:3,autoFocus:!0,className:"w-full resize-none rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas))] px-3 py-2 text-[12px] leading-5 text-[hsl(var(--deck-ink))] outline-none transition-shadow focus:border-[hsl(var(--deck-accent))] focus:ring-1 focus:ring-[hsl(var(--deck-accent-glow))]"}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>v(!1),className:"inline-flex h-7 items-center gap-1 rounded-md px-2.5 text-[11px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:bg-[hsl(var(--deck-hairline))]/60",children:[e.jsx(mt,{className:"h-3 w-3"}),t("goal.action.cancel")]}),e.jsxs("button",{type:"submit",disabled:!i.trim()||c==="edit",className:"inline-flex h-7 items-center gap-1 rounded-md bg-[hsl(var(--deck-accent))] px-2.5 text-[11px] font-medium text-white transition-colors hover:bg-[hsl(var(--deck-accent))]/90 disabled:cursor-not-allowed disabled:opacity-50",children:[c==="edit"?e.jsx(F,{className:"h-3 w-3 animate-spin"}):e.jsx(se,{className:"h-3 w-3"}),t("goal.action.save")]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink))]/90",children:r.objective}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ht,{className:"h-3 w-3"}),X(r.tokensUsed),r.tokenBudget!==void 0&&` / ${X(r.tokenBudget)}`," ",t("goal.metrics.tokens")]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(xt,{className:"h-3 w-3"}),gs(r.timeUsedSeconds)]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(he,{className:"h-3 w-3"}),r.continuationCount===1?t("goal.metrics.continuationOne",{n:r.continuationCount}):t("goal.metrics.continuationMany",{n:r.continuationCount})]})]}),r.completionVerification&&e.jsxs("div",{"data-goal-verification":r.completionVerification.status,className:"mt-2 rounded-md border border-sky-200/50 bg-sky-50/60 px-2.5 py-2 text-[11px] text-sky-900 dark:border-sky-400/15 dark:bg-sky-400/[0.05] dark:text-sky-100",children:[e.jsxs("p",{className:"font-mono font-medium",children:["#",r.completionVerification.attempt," ·"," ",r.completionVerification.status.toUpperCase()," ·"," ",((_=r.completionVerification.verifierSessionId)==null?void 0:_.slice(0,12))??"-"]}),r.completionVerification.summary&&e.jsx("p",{className:"mt-1 line-clamp-3 whitespace-pre-wrap opacity-80",children:r.completionVerification.summary}),r.completionVerification.evidenceSha256&&e.jsxs("p",{className:"mt-1 font-mono text-[10px] opacity-60",children:["sha256:",r.completionVerification.evidenceSha256.slice(0,12)]})]}),r.statusReason&&e.jsx("div",{className:"mt-2 rounded-md border border-amber-200/50 bg-amber-50/60 px-2.5 py-1.5 text-[11px] text-amber-800 dark:border-amber-400/15 dark:bg-amber-400/[0.05] dark:text-amber-200",children:r.statusReason})]})})]})}),e.jsx(Te,{open:N,onOpenChange:p,children:e.jsxs(Ae,{className:"max-w-[400px] border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsx(Fe,{children:t("goal.dialog.title")}),e.jsx(Me,{children:t("goal.dialog.description")}),e.jsxs(De,{className:"mt-2",children:[e.jsx("button",{type:"button",onClick:()=>p(!1),className:"inline-flex h-8 items-center justify-center rounded-md border border-[hsl(var(--deck-border))] px-3 text-[12px] text-[hsl(var(--deck-ink))] hover:bg-[hsl(var(--deck-hairline))]/60",children:t("goal.action.cancel")}),e.jsxs("button",{type:"button",disabled:c==="delete",onClick:()=>void V(),className:"inline-flex gap-1.5 justify-center items-center px-3 h-8 text-[12px] font-medium text-white bg-rose-600 rounded-md hover:bg-rose-500 disabled:opacity-50",children:[c==="delete"&&e.jsx(F,{className:"w-3.5 h-3.5 animate-spin"}),t("goal.action.delete")]})]})]})})]})}function Z({label:t,children:s,disabled:r,destructive:a,onClick:o}){return e.jsxs(Oe,{children:[e.jsx(Ue,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":t,disabled:r,onClick:o,className:A("flex h-6 w-6 items-center justify-center rounded-md text-[hsl(var(--deck-ink-muted))] outline-none transition-colors focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent-glow))]/50 disabled:cursor-not-allowed disabled:opacity-35 [&_svg]:h-3.5 [&_svg]:w-3.5",a?"hover:bg-rose-500/10 hover:text-rose-500":"hover:bg-[hsl(var(--deck-hairline))]/60 hover:text-[hsl(var(--deck-ink))]"),children:s})}),e.jsx(fe,{side:"top",className:"text-[10px]",children:t})]})}function ks(){const t=D(),s=y(d=>d.currentSessionRef),r=y(d=>d.sessions),a=y(d=>d.messages),o=b.useMemo(()=>{var l,v,i,u,c;const d=s?(l=We(r,s))==null?void 0:l.pendingInteraction:void 0;if(d)return d.type;for(let j=a.length-1;j>=0;j-=1){const N=(v=a[j])==null?void 0:v.agentContent;if(((i=N==null?void 0:N.confirmation)==null?void 0:i.status)==="pending")return"permission";if(((u=N==null?void 0:N.question)==null?void 0:u.status)==="pending")return"question";if(((c=N==null?void 0:N.elicitation)==null?void 0:c.status)==="pending")return"elicitation"}return null},[s,a,r]);if(!o)return null;const n=()=>{const d=document.querySelector(`[data-pending-interaction="${o}"]`);d==null||d.scrollIntoView({block:"center",behavior:"smooth"}),window.setTimeout(()=>d==null?void 0:d.focus(),250)},m=o==="question",f=o==="elicitation";return e.jsxs("div",{role:"alert",className:"mx-3 mb-2 flex flex-wrap items-center gap-2 rounded-lg border border-amber-300/80 bg-amber-50/95 px-3 py-2 font-mono text-amber-950 shadow-sm backdrop-blur dark:border-amber-800/80 dark:bg-amber-950/90 dark:text-amber-100 sm:mx-5",children:[e.jsx(Be,{className:"h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"min-w-[180px] flex-1",children:[e.jsx("div",{className:"text-[11.5px] font-semibold",children:t(m?"interaction.bar.questionTitle":f?"interaction.bar.elicitationTitle":"interaction.bar.permissionTitle")}),e.jsx("div",{className:"mt-0.5 text-[10px] leading-4 text-amber-800 dark:text-amber-300",children:t(m?"interaction.bar.questionHint":f?"interaction.bar.elicitationHint":"interaction.bar.permissionHint")})]}),e.jsxs("button",{type:"button",onClick:n,className:"inline-flex min-h-8 shrink-0 items-center gap-1.5 rounded-md border border-amber-400/80 bg-white/80 px-2.5 text-[10.5px] font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-700 dark:bg-amber-950/70 dark:hover:bg-amber-900",children:[e.jsx(Ie,{className:"h-3 w-3"}),t("interaction.bar.review")]})]})}const js={running:"status.phase.running",compacting:"status.phase.compacting",recovering_context:"status.phase.recoveringContext",switching_model:"status.phase.switchingModel",waiting_permission:"status.phase.waitingPermission",error:"status.phase.error",idle:""},Ce=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString();function ys(){const t=D(),s=y(c=>c.tokenUsage),r=y(c=>c.isStreaming),a=y(c=>c.agentPhase),o=y(c=>c.providerRetry),n=y(c=>c.providerStall),m=y(c=>c.actionStationarity),f=js[a]??"",d=(o==null?void 0:o.delayMs)!==void 0?` · ${Math.max(0,Math.ceil(o.delayMs/1e3))}s`:"",l=m?`${t(m.phase==="halted"?"status.phase.actionStationarityStopped":"status.phase.actionStationarityRecovering")} · ${m.toolName} · ${m.runLength}/${m.haltThreshold}`:n?`${t("status.phase.providerStall")} · ${Math.ceil(n.durationMs/1e3)}s / ${Math.ceil(n.timeoutMs/1e3)}s`:o?`Provider · ${t("chat.error.action.retryingTask")} · ${o.attempt}/${o.maxRetries}${d}`:f?t(f):"",v=s.maxContextTokens>0?Math.round(s.totalTokens/s.maxContextTokens*100):0,i=Math.min(v,100),u=v>95?"danger":v>80?"warn":"safe";return e.jsxs("div",{className:"flex items-center gap-4 border-t border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/70 px-5 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm",children:[e.jsxs("div",{className:"flex gap-3 items-center",children:[e.jsx("span",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:t("status.context")}),e.jsxs("span",{className:"flex gap-1 items-baseline tabular-nums",children:[e.jsx("span",{className:A("text-[12px] font-medium",u==="safe"&&"text-[hsl(var(--deck-ink))]",u==="warn"&&"text-amber-600 dark:text-amber-400",u==="danger"&&"text-red-600 dark:text-red-400"),children:Ce(s.totalTokens)}),e.jsxs("span",{className:"text-[hsl(var(--deck-ink-faint))]",children:["/ ",Ce(s.maxContextTokens)]})]}),s.isDefaultMaxTokens&&e.jsx(Ve,{children:e.jsxs(Oe,{children:[e.jsx(Ue,{asChild:!0,children:e.jsx(pt,{className:"h-3 w-3 cursor-help text-[hsl(var(--deck-ink-faint))]"})}),e.jsx(fe,{side:"top",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:t("status.tokenLimitTooltip")})})]})}),e.jsxs("div",{className:"relative h-2 w-32 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]","aria-hidden":"true",children:[e.jsx("div",{className:A("absolute inset-y-0 left-0 transition-[width] duration-300",u==="safe"&&"bg-[hsl(var(--deck-accent))]",u==="warn"&&"bg-amber-500",u==="danger"&&"bg-red-500"),style:{width:`${i}%`}}),e.jsx("div",{className:"flex absolute inset-0 pointer-events-none",children:[25,50,75].map(c=>e.jsx("span",{className:"absolute inset-y-0 w-px bg-[hsl(var(--deck-canvas-veil))]/60",style:{left:`${c}%`}},c))})]}),e.jsxs("span",{className:A("w-10 text-right tabular-nums text-[hsl(var(--deck-ink-faint))]",u==="warn"&&"text-amber-600 dark:text-amber-400",u==="danger"&&"text-red-600 dark:text-red-400"),children:[v,"%"]})]}),e.jsx("div",{className:"flex-1"}),r&&l&&e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("span",{className:"deck-pulse-dot"}),e.jsx("span",{className:"text-[hsl(var(--deck-accent))]",children:l})]})]})}function ws(t){const s=[...t].reverse().find(o=>o.role==="user");if(!s)return null;if(typeof s.content=="string")return{content:s.content,attachments:[]};const r=s.content.filter(o=>o.type==="text").map(o=>o.text).join(`
|
|
18
|
-
`),a=s.content.filter(o=>o.type==="image_url").map((o,n)=>{var f;const m=((f=o.image_url.url.match(/^data:([^;,]+)[;,]/))==null?void 0:f[1])??"application/octet-stream";return{id:`recovery-${s.id}-${n}`,name:`attachment-${n+1}`,mimeType:m,dataUrl:o.image_url.url}});return{content:r,attachments:a}}function As(){var L;const t=D(),s=y(g=>g.messages),r=y(g=>g.currentSessionRef),a=y(g=>g.isStreaming),o=y(g=>g.isStopping),n=y(g=>g.sessionEventConnectionState),m=y(g=>g.pendingSteeringCount),f=y(g=>g.pendingInputDelivery),d=y(g=>g.recoveredSteeringCount),l=y(g=>g.isLoading),v=y(g=>g.error),i=y(g=>g.errorContext),u=y(g=>g.sessions),c=y(g=>g.sendMessage),j=y(g=>g.abortSession),N=y(g=>g.retryTask),p=y(g=>g.retryingTaskKeys),E=ue(g=>g.openSettings),k=y(g=>g.reconnectSessionEvents),x=y(g=>g.clearError),[h,C]=b.useState(null),w=r?u.find(g=>g.sessionId===r.sessionId&&g.projectPath===r.projectPath):void 0,
|
|
17
|
+
`);return e.jsx("div",{"data-chat-message-id":t.id,"data-chat-role":"user","data-user-shell-command":!0,className:"flex w-full justify-end p-4",children:e.jsxs("div",{className:"w-full max-w-[85%] overflow-hidden rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface-2))] px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 truncate font-mono text-[12px] text-[hsl(var(--deck-ink))]",children:[e.jsx("span",{className:"mr-2 text-amber-600 dark:text-amber-400",children:"$"}),j]}),e.jsx(pe,{status:N})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap px-3 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))]",children:p||"(no output)"}),typeof i.exitCode=="number"&&e.jsxs("div",{className:"border-t border-[hsl(var(--deck-border))] px-3 py-1.5 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:["exit ",i.exitCode,typeof i.durationMs=="number"?` · ${(i.durationMs/1e3).toFixed(3)}s`:"",i.truncated===!0?" · truncated":""]})]})})}const{text:u,images:c}=Gt(t.content);return e.jsxs("div",{"data-chat-message-id":t.id,"data-chat-role":"user",className:"group flex gap-2 justify-end p-4 w-full items-start",children:[e.jsx("div",{className:"mt-1 flex shrink-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",children:e.jsx(ve,{text:u,label:"Copy message"})}),e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] rounded-lg px-4 py-3 max-w-[85%]",children:[u&&e.jsx("p",{className:"text-[14px] text-[hsl(var(--deck-ink))] font-mono leading-relaxed whitespace-pre-wrap",children:u}),c.length>0&&e.jsx("div",{className:A("grid gap-2",c.length===1?"grid-cols-1 mt-0":"grid-cols-2 mt-3"),children:c.map((j,N)=>e.jsx("img",{src:j,alt:`attachment-${N+1}`,className:"object-cover w-full max-h-64 rounded-md"},`${j}-${N}`))})]}),e.jsx(qt,{})]})}const o=Wt(t),n=Dt((l=t.metadata)==null?void 0:l.codeReview),m=Ut((v=t.metadata)==null?void 0:v.structuredOutput);return e.jsxs("div",{"data-chat-message-id":t.id,"data-chat-role":"assistant",className:A("group flex gap-4 justify-start w-full",s?"p-4":"px-4 pt-0 pb-3"),children:[s?e.jsx(zt,{}):e.jsx("div",{className:"w-8 shrink-0"}),e.jsxs("div",{className:"overflow-hidden flex-1 min-w-0",children:[n?e.jsx(It,{report:n}):m?e.jsx(Ht,{report:m}):e.jsx(ns,{message:t}),!m&&o.trim()&&e.jsx("div",{className:"mt-1.5 flex opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",children:e.jsx(ve,{text:o,label:"Copy response"})})]})]})}const os=b.memo(is);function ls(t,s,r){return Math.max(0,t+(r-s))}function cs(t,s,r){return Math.min(s,Math.max(0,t)+Math.max(0,r))}function Ne(t,s){return t?t.querySelector(`[data-chat-message-id="${CSS.escape(s)}"]`):null}function ds({turns:t,viewportRef:s,containerRef:r,onRevealTurn:a}){const o=D(),[n,m]=b.useState(null),[f,d]=b.useState(!1),l=b.useRef(null),v=b.useCallback(()=>{var p;const u=s.current,c=r.current;if(!u||!c||t.length===0)return;const j=u.getBoundingClientRect().top;let N=((p=t[0])==null?void 0:p.id)??null;for(const E of t){const k=Ne(c,E.id);if(k)if(k.getBoundingClientRect().top-j<=24)N=E.id;else break}m(N)},[t,s,r]);b.useEffect(()=>{const u=s.current;if(!u)return;const c=()=>{l.current===null&&(l.current=window.requestAnimationFrame(()=>{l.current=null,v()}))};return v(),u.addEventListener("scroll",c,{passive:!0}),()=>{u.removeEventListener("scroll",c),l.current!==null&&(window.cancelAnimationFrame(l.current),l.current=null)}},[v,s]);const i=b.useCallback(u=>{const c=()=>{const N=Ne(r.current,u.id);N&&(N.scrollIntoView({behavior:"smooth",block:"start"}),m(u.id))};a(u.index)?c():window.requestAnimationFrame(()=>window.requestAnimationFrame(c))},[r,a]);return t.length<2?null:e.jsx("nav",{"aria-label":o("chat.turns.aria"),className:"absolute right-1 top-1/2 z-20 hidden -translate-y-1/2 sm:block",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),onFocusCapture:()=>d(!0),onBlurCapture:u=>{u.currentTarget.contains(u.relatedTarget)||d(!1)},children:e.jsxs("div",{className:"relative flex items-center justify-end",children:[e.jsx("ul",{className:A("flex flex-col items-center gap-2 py-2 transition-opacity",f?"opacity-0":"opacity-100"),"aria-hidden":f,children:t.map(u=>e.jsx("li",{children:e.jsx("span",{className:A("block rounded-full transition-all",u.id===n?"h-2 w-2 bg-[hsl(var(--deck-accent))]":"h-1.5 w-1.5 bg-[hsl(var(--deck-ink-faint))]/40")})},u.id))}),e.jsx("div",{className:A("absolute right-0 max-h-[min(70vh,520px)] w-[280px] overflow-y-auto rounded-lg border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]/95 p-1 shadow-xl backdrop-blur transition-all",f?"pointer-events-auto translate-x-0 opacity-100":"pointer-events-none translate-x-2 opacity-0"),children:t.map((u,c)=>e.jsxs("button",{type:"button",onClick:()=>i(u),className:A("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u.id===n?"bg-[hsl(var(--deck-hairline))]/70 text-[hsl(var(--deck-ink))]":"text-[hsl(var(--deck-ink-muted))] hover:bg-[hsl(var(--deck-hairline))]/50 hover:text-[hsl(var(--deck-ink))]"),children:[e.jsx("span",{className:A("mt-1 h-1.5 w-1.5 shrink-0 rounded-full",u.id===n?"bg-[hsl(var(--deck-accent))]":"bg-[hsl(var(--deck-ink-faint))]/40")}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-mono text-[9.5px] uppercase tracking-[0.12em] text-[hsl(var(--deck-ink-faint))]",children:o("chat.turns.label",{n:c+1})}),e.jsx("span",{className:"line-clamp-2 text-[12px] leading-4",children:u.preview})]})]},u.id))})]})})}const Se=80;function us(t){return typeof t=="string"?t:Array.isArray(t)?t.filter(s=>s.type==="text").map(s=>s.text).join(" "):""}function ms(t){const s=us(t).replace(/\s+/g," ").trim();return s?s.length>Se?`${s.slice(0,Se-1)}…`:s:""}function hs(t){const s=[];for(let r=0;r<t.length;r+=1){const a=t[r];if(a.role!=="user"||!a.id)continue;const o=ms(a.content);o&&s.push({id:a.id,index:r,preview:o})}return s}const le=120,ce=80,xs=96;function W(t){return(t==null?void 0:t.querySelector("[data-radix-scroll-area-viewport]"))??null}function ps({messages:t,isLoading:s}){const r=D(),a=b.useRef(null),o=b.useRef(null),n=b.useRef(!0),m=b.useRef(t.length),f=b.useRef(null),[d,l]=b.useState(le),[v,i]=b.useState(!1);b.useEffect(()=>{const x=W(a.current);if(!x||!n.current)return;const h=window.requestAnimationFrame(()=>{x.scrollTop=x.scrollHeight});return()=>window.cancelAnimationFrame(h)},[t]),b.useEffect(()=>{const x=W(a.current);if(!x)return;o.current=x;const h=()=>{const w=x.scrollHeight-x.scrollTop-x.clientHeight<=xs;n.current=w,i(!w)};return h(),x.addEventListener("scroll",h,{passive:!0}),()=>x.removeEventListener("scroll",h)},[]),b.useEffect(()=>{const x=m.current;m.current=t.length,l(h=>h>=x&&t.length>x?t.length:Math.min(Math.max(h,le),t.length||le))},[t.length]);const u=Math.max(t.length-d,0),c=u,j=b.useMemo(()=>t.slice(c),[t,c]),N=b.useMemo(()=>hs(t),[t]);if(b.useLayoutEffect(()=>{var C;const x=f.current;if(!x)return;const h=W(a.current);if(f.current=null,!!h){if((C=x.element)!=null&&C.isConnected){const w=x.element.getBoundingClientRect().top-x.viewportTop;h.scrollTop+=w;return}h.scrollTop=ls(x.scrollTop,x.scrollHeight,h.scrollHeight)}},[d]),s)return e.jsx("div",{role:"status","aria-live":"polite","aria-busy":"true",className:"flex overflow-hidden flex-1 justify-center items-center px-5 py-8 min-h-0",children:e.jsxs("div",{className:"w-full max-w-[560px]",children:[e.jsxs("div",{className:"flex flex-col items-center text-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 animate-pulse rounded-full bg-[hsl(var(--deck-accent-soft))] blur-xl"}),e.jsx(de,{size:42,className:"relative"})]}),e.jsxs("div",{className:"mt-4 inline-flex items-center gap-1.5 font-mono text-[10px] uppercase tracking-[0.16em] text-[hsl(var(--deck-accent))]",children:[e.jsx(it,{className:"w-3 h-3"}),r("chat.list.loading.eyebrow")]}),e.jsx("h2",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:r("chat.list.loading.title")}),e.jsx("p",{className:"mt-1 max-w-sm text-[11.5px] leading-5 text-[hsl(var(--deck-ink-faint))]",children:r("chat.list.loading.hint")})]}),e.jsx("div",{"aria-hidden":"true",className:"mt-7 space-y-4 rounded-xl border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))]/45 px-4 py-5",children:[72,88,64].map((x,h)=>e.jsxs("div",{className:A("flex gap-3",h%2===1&&"flex-row-reverse"),children:[e.jsx("span",{className:"h-7 w-7 shrink-0 animate-pulse rounded-md bg-[hsl(var(--deck-surface-2))]"}),e.jsx("span",{className:"h-10 animate-pulse rounded-lg bg-[hsl(var(--deck-surface-2))]",style:{width:`${x}%`,animationDelay:`${h*120}ms`}})]},x))})]})});if(t.length===0&&!s)return e.jsx("div",{className:"flex flex-1 justify-center items-center",children:e.jsxs("div",{className:"flex flex-col gap-4 items-center text-center",children:[e.jsx(de,{size:44}),e.jsxs("div",{children:[e.jsx("div",{className:"deck-eyebrow text-[hsl(var(--deck-accent))]",children:r("chat.list.empty.eyebrow")}),e.jsx("div",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:r("chat.list.empty.title")}),e.jsx("div",{className:"mt-1 max-w-xs text-[12px] text-[hsl(var(--deck-ink-muted))]",children:r("chat.list.empty.hint")})]})]})});const p=()=>{const x=W(a.current);x&&(n.current=!0,i(!1),x.scrollTo({top:x.scrollHeight,behavior:"smooth"}))},E=()=>{var h;const x=W(a.current);if(x){const C=((h=a.current)==null?void 0:h.querySelector("[data-chat-message-id]"))??null;f.current={element:C,viewportTop:(C==null?void 0:C.getBoundingClientRect().top)??0,scrollHeight:x.scrollHeight,scrollTop:x.scrollTop}}l(C=>cs(C,t.length,ce))},k=x=>x>=c?!0:(l(t.length),!1);return e.jsxs("div",{ref:a,className:"relative flex-1 min-h-0",children:[e.jsx(qe,{className:"h-full",children:e.jsxs("div",{className:"flex flex-col px-4 pb-4 w-full md:px-6",children:[u>0&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx("button",{type:"button",onClick:E,"aria-label":r("chat.list.showEarlierWithRemaining",{count:Math.min(u,ce),remaining:u}),className:"rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] px-3 py-1.5 font-mono text-[12px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:border-[hsl(var(--deck-border-strong))] hover:text-[hsl(var(--deck-ink))]",children:r("chat.list.showEarlier",{count:Math.min(u,ce)})})}),j.map((x,h)=>{const C=c+h,w=C>0?t[C-1]:null,I=!w||w.role!==x.role||w.role==="user";return e.jsx(os,{message:x,showAvatar:I},x.id||`msg-${C}`)})]})}),e.jsx(ds,{turns:N,viewportRef:o,containerRef:a,onRevealTurn:k}),v&&e.jsxs("button",{type:"button",onClick:p,className:"absolute bottom-4 left-1/2 z-10 inline-flex -translate-x-1/2 items-center gap-1.5 rounded-full border border-[hsl(var(--deck-border-strong))] bg-[hsl(var(--deck-surface))]/95 px-3 py-1.5 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] shadow-lg backdrop-blur transition-colors hover:text-[hsl(var(--deck-ink))] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent))]",children:[e.jsx(Ie,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}),r("chat.list.jumpLatest")]})]})}const fs=b.memo(ps),Ve=Nt,Oe=St,Ue=Ct,fe=b.forwardRef(({className:t,sideOffset:s=4,...r},a)=>e.jsx(_e,{ref:a,sideOffset:s,className:A("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",t),...r}));fe.displayName=_e.displayName;const bs={active:{labelKey:"goal.status.active",dot:"bg-[hsl(var(--deck-accent))] shadow-[0_0_6px_hsl(var(--deck-accent-glow)/0.5)]",accent:"text-[hsl(var(--deck-accent))]"},verifying:{labelKey:"goal.status.active",dot:"animate-pulse bg-sky-400",accent:"text-sky-600 dark:text-sky-300"},paused:{labelKey:"goal.status.paused",dot:"bg-amber-400",accent:"text-amber-600 dark:text-amber-300"},blocked:{labelKey:"goal.status.blocked",dot:"bg-rose-500",accent:"text-rose-600 dark:text-rose-300"},usage_limited:{labelKey:"goal.status.usageLimited",dot:"bg-orange-500",accent:"text-orange-600 dark:text-orange-300"},budget_limited:{labelKey:"goal.status.budgetLimited",dot:"bg-orange-500",accent:"text-orange-600 dark:text-orange-300"},complete:{labelKey:"goal.status.complete",dot:"bg-emerald-500",accent:"text-emerald-600 dark:text-emerald-300"}};function X(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function gs(t){if(t<60)return`${t}s`;const s=Math.floor(t/60),r=t%60;return r===0?`${s}m`:`${s}m ${r}s`}function vs(){var _;const t=D(),{locale:s}=Ge(),r=y(S=>S.goal),a=y(S=>S.pauseGoal),o=y(S=>S.resumeGoal),n=y(S=>S.editGoal),m=y(S=>S.clearGoal),[f,d]=b.useState(!1),[l,v]=b.useState(!1),[i,u]=b.useState(""),[c,j]=b.useState(null),[N,p]=b.useState(!1);if(b.useEffect(()=>{d(!1),v(!1),u((r==null?void 0:r.objective)??""),p(!1)},[r==null?void 0:r.goalId]),!r)return null;const E=bs[r.status],k=["active","verifying","paused","blocked"].includes(r.status),x=r.status==="active"||r.status==="verifying",h=r.status==="paused"||r.status==="blocked",C=c!==null,w=async(S,$)=>{j(S);try{await $()}finally{j(null)}},I=()=>{u(r.objective),v(!0),d(!0)},F=async S=>{S.preventDefault();const $=i.trim();if(!$||$===r.objective){v(!1);return}await w("edit",()=>n($)),v(!1)},V=async()=>{await w("delete",m),p(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{delayDuration:250,children:e.jsxs("section",{"aria-label":t("goal.aria.section"),className:"mx-3 mb-1 shrink-0","data-blade-goal-status":r.status,children:[e.jsxs("div",{className:A("flex h-9 items-center gap-2 rounded-lg border px-3 transition-colors","border-[hsl(var(--deck-border))]/60 bg-[hsl(var(--deck-surface))]/80 backdrop-blur-sm",f&&"rounded-b-none border-b-0"),children:[r.status==="complete"?e.jsx(ot,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):e.jsx(lt,{className:A("h-3.5 w-3.5 shrink-0",E.accent)}),e.jsx("span",{className:A("h-1.5 w-1.5 shrink-0 rounded-full",E.dot)}),e.jsx("span",{className:A("shrink-0 text-[10px] font-medium leading-none",E.accent),children:r.status==="verifying"?s==="zh"?"验证中":"Verifying":t(E.labelKey)}),e.jsx("span",{className:"h-3 w-px shrink-0 bg-[hsl(var(--deck-hairline))]"}),e.jsx("button",{type:"button","aria-label":t(f?"goal.action.collapse":"goal.action.expand"),className:"min-w-0 flex-1 truncate text-left text-[12px] leading-5 text-[hsl(var(--deck-ink))]/85 outline-none transition-colors hover:text-[hsl(var(--deck-ink))]",onClick:()=>d(S=>!S),"aria-expanded":f,title:r.objective,children:r.objective}),r.tokensUsed>0&&e.jsxs("span",{className:"hidden shrink-0 text-[10px] tabular-nums text-[hsl(var(--deck-ink-muted))] sm:inline",children:[X(r.tokensUsed),r.tokenBudget!==void 0&&`/${X(r.tokenBudget)}`]}),e.jsxs("div",{className:"flex shrink-0 items-center",children:[x&&e.jsx(Z,{label:t("goal.action.pause"),disabled:C,onClick:()=>void w("pause",a),children:c==="pause"?e.jsx(M,{className:"animate-spin"}):e.jsx(ct,{})}),h&&e.jsx(Z,{label:t("goal.action.resume"),disabled:C,onClick:()=>void w("resume",o),children:c==="resume"?e.jsx(M,{className:"animate-spin"}):e.jsx(dt,{})}),e.jsx(Z,{label:t(k?"goal.action.edit":"goal.action.expand"),disabled:!k&&!f,onClick:k?I:()=>d(S=>!S),children:k?e.jsx($e,{}):e.jsx(ut,{})}),e.jsx(Z,{label:t("goal.action.delete"),disabled:C,destructive:!0,onClick:()=>p(!0),children:e.jsx(ee,{})})]})]}),f&&e.jsx("div",{className:"rounded-b-lg border border-t-0 border-[hsl(var(--deck-border))]/60 bg-[hsl(var(--deck-surface))]/80 px-4 py-3 backdrop-blur-sm",children:l?e.jsxs("form",{onSubmit:F,children:[e.jsx("textarea",{id:"goal-objective",value:i,onChange:S=>u(S.target.value),onKeyDown:S=>{S.key==="Escape"&&v(!1)},rows:3,autoFocus:!0,className:"w-full resize-none rounded-md border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-canvas))] px-3 py-2 text-[12px] leading-5 text-[hsl(var(--deck-ink))] outline-none transition-shadow focus:border-[hsl(var(--deck-accent))] focus:ring-1 focus:ring-[hsl(var(--deck-accent-glow))]"}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>v(!1),className:"inline-flex h-7 items-center gap-1 rounded-md px-2.5 text-[11px] text-[hsl(var(--deck-ink-muted))] transition-colors hover:bg-[hsl(var(--deck-hairline))]/60",children:[e.jsx(mt,{className:"h-3 w-3"}),t("goal.action.cancel")]}),e.jsxs("button",{type:"submit",disabled:!i.trim()||c==="edit",className:"inline-flex h-7 items-center gap-1 rounded-md bg-[hsl(var(--deck-accent))] px-2.5 text-[11px] font-medium text-white transition-colors hover:bg-[hsl(var(--deck-accent))]/90 disabled:cursor-not-allowed disabled:opacity-50",children:[c==="edit"?e.jsx(M,{className:"h-3 w-3 animate-spin"}):e.jsx(se,{className:"h-3 w-3"}),t("goal.action.save")]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink))]/90",children:r.objective}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ht,{className:"h-3 w-3"}),X(r.tokensUsed),r.tokenBudget!==void 0&&` / ${X(r.tokenBudget)}`," ",t("goal.metrics.tokens")]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(xt,{className:"h-3 w-3"}),gs(r.timeUsedSeconds)]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(he,{className:"h-3 w-3"}),r.continuationCount===1?t("goal.metrics.continuationOne",{n:r.continuationCount}):t("goal.metrics.continuationMany",{n:r.continuationCount})]})]}),r.completionVerification&&e.jsxs("div",{"data-goal-verification":r.completionVerification.status,className:"mt-2 rounded-md border border-sky-200/50 bg-sky-50/60 px-2.5 py-2 text-[11px] text-sky-900 dark:border-sky-400/15 dark:bg-sky-400/[0.05] dark:text-sky-100",children:[e.jsxs("p",{className:"font-mono font-medium",children:["#",r.completionVerification.attempt," ·"," ",r.completionVerification.status.toUpperCase()," ·"," ",((_=r.completionVerification.verifierSessionId)==null?void 0:_.slice(0,12))??"-"]}),r.completionVerification.summary&&e.jsx("p",{className:"mt-1 line-clamp-3 whitespace-pre-wrap opacity-80",children:r.completionVerification.summary}),r.completionVerification.evidenceSha256&&e.jsxs("p",{className:"mt-1 font-mono text-[10px] opacity-60",children:["sha256:",r.completionVerification.evidenceSha256.slice(0,12)]})]}),r.statusReason&&e.jsx("div",{className:"mt-2 rounded-md border border-amber-200/50 bg-amber-50/60 px-2.5 py-1.5 text-[11px] text-amber-800 dark:border-amber-400/15 dark:bg-amber-400/[0.05] dark:text-amber-200",children:r.statusReason})]})})]})}),e.jsx(Te,{open:N,onOpenChange:p,children:e.jsxs(Ae,{className:"max-w-[400px] border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsx(Fe,{children:t("goal.dialog.title")}),e.jsx(Me,{children:t("goal.dialog.description")}),e.jsxs(De,{className:"mt-2",children:[e.jsx("button",{type:"button",onClick:()=>p(!1),className:"inline-flex h-8 items-center justify-center rounded-md border border-[hsl(var(--deck-border))] px-3 text-[12px] text-[hsl(var(--deck-ink))] hover:bg-[hsl(var(--deck-hairline))]/60",children:t("goal.action.cancel")}),e.jsxs("button",{type:"button",disabled:c==="delete",onClick:()=>void V(),className:"inline-flex gap-1.5 justify-center items-center px-3 h-8 text-[12px] font-medium text-white bg-rose-600 rounded-md hover:bg-rose-500 disabled:opacity-50",children:[c==="delete"&&e.jsx(M,{className:"w-3.5 h-3.5 animate-spin"}),t("goal.action.delete")]})]})]})})]})}function Z({label:t,children:s,disabled:r,destructive:a,onClick:o}){return e.jsxs(Oe,{children:[e.jsx(Ue,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":t,disabled:r,onClick:o,className:A("flex h-6 w-6 items-center justify-center rounded-md text-[hsl(var(--deck-ink-muted))] outline-none transition-colors focus-visible:ring-1 focus-visible:ring-[hsl(var(--deck-accent-glow))]/50 disabled:cursor-not-allowed disabled:opacity-35 [&_svg]:h-3.5 [&_svg]:w-3.5",a?"hover:bg-rose-500/10 hover:text-rose-500":"hover:bg-[hsl(var(--deck-hairline))]/60 hover:text-[hsl(var(--deck-ink))]"),children:s})}),e.jsx(fe,{side:"top",className:"text-[10px]",children:t})]})}function ks(){const t=D(),s=y(d=>d.currentSessionRef),r=y(d=>d.sessions),a=y(d=>d.messages),o=b.useMemo(()=>{var l,v,i,u,c;const d=s?(l=We(r,s))==null?void 0:l.pendingInteraction:void 0;if(d)return d.type;for(let j=a.length-1;j>=0;j-=1){const N=(v=a[j])==null?void 0:v.agentContent;if(((i=N==null?void 0:N.confirmation)==null?void 0:i.status)==="pending")return"permission";if(((u=N==null?void 0:N.question)==null?void 0:u.status)==="pending")return"question";if(((c=N==null?void 0:N.elicitation)==null?void 0:c.status)==="pending")return"elicitation"}return null},[s,a,r]);if(!o)return null;const n=()=>{const d=document.querySelector(`[data-pending-interaction="${o}"]`);d==null||d.scrollIntoView({block:"center",behavior:"smooth"}),window.setTimeout(()=>d==null?void 0:d.focus(),250)},m=o==="question",f=o==="elicitation";return e.jsxs("div",{role:"alert",className:"mx-3 mb-2 flex flex-wrap items-center gap-2 rounded-lg border border-amber-300/80 bg-amber-50/95 px-3 py-2 font-mono text-amber-950 shadow-sm backdrop-blur dark:border-amber-800/80 dark:bg-amber-950/90 dark:text-amber-100 sm:mx-5",children:[e.jsx(Be,{className:"h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"min-w-[180px] flex-1",children:[e.jsx("div",{className:"text-[11.5px] font-semibold",children:t(m?"interaction.bar.questionTitle":f?"interaction.bar.elicitationTitle":"interaction.bar.permissionTitle")}),e.jsx("div",{className:"mt-0.5 text-[10px] leading-4 text-amber-800 dark:text-amber-300",children:t(m?"interaction.bar.questionHint":f?"interaction.bar.elicitationHint":"interaction.bar.permissionHint")})]}),e.jsxs("button",{type:"button",onClick:n,className:"inline-flex min-h-8 shrink-0 items-center gap-1.5 rounded-md border border-amber-400/80 bg-white/80 px-2.5 text-[10.5px] font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-700 dark:bg-amber-950/70 dark:hover:bg-amber-900",children:[e.jsx(Ie,{className:"h-3 w-3"}),t("interaction.bar.review")]})]})}const js={running:"status.phase.running",compacting:"status.phase.compacting",recovering_context:"status.phase.recoveringContext",switching_model:"status.phase.switchingModel",waiting_permission:"status.phase.waitingPermission",error:"status.phase.error",idle:""},Ce=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString();function ys(){const t=D(),s=y(c=>c.tokenUsage),r=y(c=>c.isStreaming),a=y(c=>c.agentPhase),o=y(c=>c.providerRetry),n=y(c=>c.providerStall),m=y(c=>c.actionStationarity),f=js[a]??"",d=(o==null?void 0:o.delayMs)!==void 0?` · ${Math.max(0,Math.ceil(o.delayMs/1e3))}s`:"",l=m?`${t(m.phase==="halted"?"status.phase.actionStationarityStopped":"status.phase.actionStationarityRecovering")} · ${m.toolName} · ${m.runLength}/${m.haltThreshold}`:n?`${t("status.phase.providerStall")} · ${Math.ceil(n.durationMs/1e3)}s / ${Math.ceil(n.timeoutMs/1e3)}s`:o?`Provider · ${t("chat.error.action.retryingTask")} · ${o.attempt}/${o.maxRetries}${d}`:f?t(f):"",v=s.maxContextTokens>0?Math.round(s.totalTokens/s.maxContextTokens*100):0,i=Math.min(v,100),u=v>95?"danger":v>80?"warn":"safe";return e.jsxs("div",{className:"flex items-center gap-4 border-t border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/70 px-5 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm",children:[e.jsxs("div",{className:"flex gap-3 items-center",children:[e.jsx("span",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:t("status.context")}),e.jsxs("span",{className:"flex gap-1 items-baseline tabular-nums",children:[e.jsx("span",{className:A("text-[12px] font-medium",u==="safe"&&"text-[hsl(var(--deck-ink))]",u==="warn"&&"text-amber-600 dark:text-amber-400",u==="danger"&&"text-red-600 dark:text-red-400"),children:Ce(s.totalTokens)}),e.jsxs("span",{className:"text-[hsl(var(--deck-ink-faint))]",children:["/ ",Ce(s.maxContextTokens)]})]}),s.isDefaultMaxTokens&&e.jsx(Ve,{children:e.jsxs(Oe,{children:[e.jsx(Ue,{asChild:!0,children:e.jsx(pt,{className:"h-3 w-3 cursor-help text-[hsl(var(--deck-ink-faint))]"})}),e.jsx(fe,{side:"top",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:t("status.tokenLimitTooltip")})})]})}),e.jsxs("div",{className:"relative h-2 w-32 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]","aria-hidden":"true",children:[e.jsx("div",{className:A("absolute inset-y-0 left-0 transition-[width] duration-300",u==="safe"&&"bg-[hsl(var(--deck-accent))]",u==="warn"&&"bg-amber-500",u==="danger"&&"bg-red-500"),style:{width:`${i}%`}}),e.jsx("div",{className:"flex absolute inset-0 pointer-events-none",children:[25,50,75].map(c=>e.jsx("span",{className:"absolute inset-y-0 w-px bg-[hsl(var(--deck-canvas-veil))]/60",style:{left:`${c}%`}},c))})]}),e.jsxs("span",{className:A("w-10 text-right tabular-nums text-[hsl(var(--deck-ink-faint))]",u==="warn"&&"text-amber-600 dark:text-amber-400",u==="danger"&&"text-red-600 dark:text-red-400"),children:[v,"%"]})]}),e.jsx("div",{className:"flex-1"}),r&&l&&e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("span",{className:"deck-pulse-dot"}),e.jsx("span",{className:"text-[hsl(var(--deck-accent))]",children:l})]})]})}function ws(t){const s=[...t].reverse().find(o=>o.role==="user");if(!s)return null;if(typeof s.content=="string")return{content:s.content,attachments:[]};const r=s.content.filter(o=>o.type==="text").map(o=>o.text).join(`
|
|
18
|
+
`),a=s.content.filter(o=>o.type==="image_url").map((o,n)=>{var f;const m=((f=o.image_url.url.match(/^data:([^;,]+)[;,]/))==null?void 0:f[1])??"application/octet-stream";return{id:`recovery-${s.id}-${n}`,name:`attachment-${n+1}`,mimeType:m,dataUrl:o.image_url.url}});return{content:r,attachments:a}}function As(){var L;const t=D(),s=y(g=>g.messages),r=y(g=>g.currentSessionRef),a=y(g=>g.isStreaming),o=y(g=>g.isStopping),n=y(g=>g.sessionEventConnectionState),m=y(g=>g.pendingSteeringCount),f=y(g=>g.pendingInputDelivery),d=y(g=>g.recoveredSteeringCount),l=y(g=>g.isLoading),v=y(g=>g.error),i=y(g=>g.errorContext),u=y(g=>g.sessions),c=y(g=>g.sendMessage),j=y(g=>g.abortSession),N=y(g=>g.retryTask),p=y(g=>g.retryingTaskKeys),E=ue(g=>g.openSettings),k=y(g=>g.reconnectSessionEvents),x=y(g=>g.clearError),[h,C]=b.useState(null),w=r?u.find(g=>g.sessionId===r.sessionId&&g.projectPath===r.projectPath):void 0,I=!!v&&((i==null?void 0:i.kind)==="navigation"||!(i!=null&&i.sessionRef)||Ee(i.sessionRef,r)),F=(i==null?void 0:i.failureCode)??((L=w==null?void 0:w.taskFailure)==null?void 0:L.code),V=(i==null?void 0:i.kind)==="execution"&&F?t(yt(F)):v==="queue_full"?t("chat.error.queueFull"):v==="turn_unavailable"||v==="turn_active"?t("chat.error.turnChanged"):v,_=n==="connecting"||n==="reconnecting",S=a&&n!=="connected",$=r?`session:${J(r)}`:"session:temporary",U=b.useMemo(()=>ws(s),[s]),ne=r?J(r):"temporary-session",z=!!(r&&(w!=null&&w.taskRetryAvailable)&&(!F||wt(F)))&&((i==null?void 0:i.kind)==="execution"||(i==null?void 0:i.kind)==="task_action"),q=(i==null?void 0:i.kind)==="execution"&&(F==="authentication"||F==="permission"||F==="model_unavailable"),H=r?p.includes(J(r)):!1;b.useEffect(()=>{C(null)},[ne]);const Q=async g=>c({content:g.content,modelId:g.modelId,reasoningEffort:g.reasoningEffort,serviceTier:g.serviceTier,responseVerbosity:g.responseVerbosity,communicationStyle:g.communicationStyle,...g.outputSchema?{outputSchema:g.outputSchema}:{},attachments:g.attachments.map(B=>({type:"image",content:B.dataUrl,mimeType:B.mimeType,name:B.name}))}),Y=()=>j(),T=async()=>{if(q){x(),E("models");return}if(z&&r){x(),await N(r).catch(()=>{});return}if((i==null?void 0:i.kind)==="execution"&&U){C({...U,revision:Date.now()}),x();return}x(),requestAnimationFrame(()=>Qe())},P=z?t(H?"chat.error.action.retryingTask":"chat.error.action.retryTask"):q?t("chat.error.action.checkModels"):(i==null?void 0:i.kind)==="execution"&&U?t("chat.error.action.editResend"):(i==null?void 0:i.kind)==="submission"?t("chat.error.action.returnDraft"):null;return e.jsxs("div",{className:"flex h-full flex-col bg-[hsl(var(--deck-canvas))]",children:[I&&e.jsxs("div",{role:"alert",className:"flex min-h-11 flex-wrap items-center gap-2 border-b border-red-200/60 bg-red-50/80 px-4 py-2 font-mono text-[11px] text-red-700 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-300 sm:px-5",children:[e.jsx(Be,{className:"h-3.5 w-3.5 shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1 break-words",children:[e.jsx("span",{className:"font-semibold",children:t((i==null?void 0:i.kind)==="submission"?"chat.error.title.submission":(i==null?void 0:i.kind)==="execution"?"chat.error.title.execution":(i==null?void 0:i.kind)==="navigation"?"chat.error.title.navigation":"chat.error.title.generic")})," ",V]}),P&&e.jsxs("button",{type:"button",onClick:()=>void T(),disabled:H,className:"inline-flex min-h-7 shrink-0 items-center gap-1.5 rounded-md border border-red-300/70 bg-white/65 px-2.5 font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-red-500 disabled:cursor-wait disabled:opacity-60 dark:border-red-800 dark:bg-red-950/45 dark:hover:bg-red-900/60",children:[z?H?e.jsx(M,{className:"h-3 w-3 animate-spin"}):e.jsx(he,{className:"h-3 w-3"}):e.jsx($e,{className:"h-3 w-3"}),P]}),e.jsx("button",{type:"button",onClick:x,"aria-label":t("chat.error.dismiss"),className:"p-1 text-red-500 rounded transition-colors hover:bg-red-100/60 hover:text-red-700 dark:hover:bg-red-950/60 dark:hover:text-red-100",children:"✕"})]}),(_||n==="offline")&&e.jsxs("div",{role:n==="offline"?"alert":"status","aria-live":"polite",className:"flex min-h-10 flex-wrap items-center gap-2 border-b border-amber-300/60 bg-amber-50/80 px-4 py-2 font-mono text-[11px] text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/35 dark:text-amber-200 sm:px-5",children:[_?e.jsx(M,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(ft,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:t(_?"chat.connection.reconnecting":"chat.connection.offline")}),n==="offline"&&e.jsxs("button",{type:"button",onClick:()=>void k().catch(()=>{}),className:"inline-flex min-h-7 items-center gap-1.5 rounded-md border border-amber-400/70 bg-white/60 px-2.5 font-medium transition-colors hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:border-amber-700 dark:bg-amber-950/50 dark:hover:bg-amber-900/50",children:[e.jsx(bt,{className:"h-3 w-3"}),t("chat.connection.retry")]})]}),e.jsx(Et,{}),e.jsx(fs,{messages:s,isLoading:l},r?J(r):"temporary-session"),e.jsx(ks,{}),e.jsx(vs,{}),e.jsx(Je,{draftKey:$,draft:h==null?void 0:h.content,draftAttachments:h==null?void 0:h.attachments,draftRevision:h==null?void 0:h.revision,onSend:Q,onAbort:Y,disabled:l||S,isStreaming:a,isStopping:o,pendingSteeringCount:m,pendingInputDelivery:f,recoveredSteeringCount:d,workspacePath:r==null?void 0:r.projectPath},$),e.jsx(ys,{})]})}export{As as ChatView};
|