blade-code 0.10.81 → 0.10.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/blade.js +2 -2
  2. package/dist/{chunk-shq0pkxq.js → chunk-01zar8q6.js} +1 -1
  3. package/dist/{chunk-33bpwkyk.js → chunk-0q5bz3nm.js} +2 -2
  4. package/dist/{chunk-0b9jdzbq.js → chunk-1htd858b.js} +2 -2
  5. package/dist/{chunk-zkhb55jz.js → chunk-272swnyr.js} +1 -1
  6. package/dist/chunk-2b7zryg3.js +118 -0
  7. package/dist/chunk-3p808rrt.js +1 -0
  8. package/dist/{chunk-mygw13zd.js → chunk-44dzrn0p.js} +1 -1
  9. package/dist/chunk-4pksah0q.js +1 -0
  10. package/dist/{chunk-60esv83q.js → chunk-4rq0jhf4.js} +3 -3
  11. package/dist/{chunk-wra4tbhz.js → chunk-69rpb78b.js} +1 -1
  12. package/dist/{chunk-h0fh3j9w.js → chunk-6jsmac0q.js} +1 -1
  13. package/dist/{chunk-42p755yz.js → chunk-73j10ezs.js} +2 -2
  14. package/dist/chunk-7jp7e0zj.js +1 -0
  15. package/dist/{chunk-pfvgkexe.js → chunk-7m5q8vxf.js} +1 -1
  16. package/dist/{chunk-b9nhnzaj.js → chunk-7rfhmbqw.js} +1 -1
  17. package/dist/{chunk-c22vqgah.js → chunk-8215sm79.js} +12 -11
  18. package/dist/{chunk-sj0k8cdf.js → chunk-83caxxbt.js} +1 -1
  19. package/dist/{chunk-5gqqenv1.js → chunk-a14vnxrf.js} +1 -1
  20. package/dist/{chunk-kkzynnnn.js → chunk-aqkexfag.js} +1 -1
  21. package/dist/{chunk-seamt0j3.js → chunk-b2p9qm6j.js} +2 -2
  22. package/dist/chunk-bd5e1n5z.js +1 -0
  23. package/dist/{chunk-gbjtfgck.js → chunk-cchk5xrs.js} +1 -1
  24. package/dist/{chunk-skw3b17a.js → chunk-d2pwwdab.js} +1 -1
  25. package/dist/chunk-d4k4v959.js +1 -0
  26. package/dist/{chunk-091qx62q.js → chunk-e1ry8aj5.js} +1 -1
  27. package/dist/{chunk-b9vm7gns.js → chunk-ffa6hhee.js} +2 -2
  28. package/dist/{chunk-yyt14et5.js → chunk-fkwfymb6.js} +4 -4
  29. package/dist/{chunk-n2hqr6st.js → chunk-fs9j9gas.js} +2 -2
  30. package/dist/{chunk-jdb2mwbn.js → chunk-fv8b98tz.js} +2 -2
  31. package/dist/{chunk-7wf1gb3e.js → chunk-g832dwdm.js} +2 -2
  32. package/dist/{chunk-c9e0fbyh.js → chunk-g9xjcfrf.js} +1 -1
  33. package/dist/{chunk-1mc7nfb4.js → chunk-gd2sw9zm.js} +1 -1
  34. package/dist/chunk-hg8d4vhj.js +2 -0
  35. package/dist/{chunk-eeb2945p.js → chunk-hjr9r44k.js} +1 -1
  36. package/dist/chunk-hqsqk5dp.js +1 -0
  37. package/dist/{chunk-fsm3fb2m.js → chunk-jf4bxxyf.js} +1 -1
  38. package/dist/{chunk-gre57x9m.js → chunk-jndq361v.js} +1 -1
  39. package/dist/chunk-js3j00ka.js +1 -0
  40. package/dist/{chunk-aa4n9nbw.js → chunk-k50z8903.js} +1 -1
  41. package/dist/{chunk-90057qj6.js → chunk-m0a75642.js} +1 -1
  42. package/dist/{chunk-h6a0nct6.js → chunk-m5f934fh.js} +1 -1
  43. package/dist/chunk-mbt25rs5.js +1 -0
  44. package/dist/{chunk-xjr6y8s4.js → chunk-mgtcjwhy.js} +2 -2
  45. package/dist/{chunk-99hhpms5.js → chunk-mq2nx77s.js} +2 -2
  46. package/dist/{chunk-xyncta62.js → chunk-p9a3d507.js} +1 -1
  47. package/dist/{chunk-wjjapjhe.js → chunk-q14mgye7.js} +2 -2
  48. package/dist/chunk-qb242y47.js +1 -0
  49. package/dist/{chunk-pt97sfr3.js → chunk-r4mjdkzv.js} +1 -1
  50. package/dist/{chunk-b9bk43pk.js → chunk-r51ds5qw.js} +2 -2
  51. package/dist/{chunk-jwx10h5z.js → chunk-r77pcb0f.js} +2 -2
  52. package/dist/chunk-rmqksw1e.js +1 -0
  53. package/dist/{chunk-0a0sj79a.js → chunk-rwvaapta.js} +2 -2
  54. package/dist/{chunk-0141jad7.js → chunk-sb84vdcf.js} +1 -1
  55. package/dist/{chunk-0ra945vt.js → chunk-shr5cg46.js} +2 -2
  56. package/dist/{chunk-qxn5bg5k.js → chunk-sk8h4m9m.js} +1 -1
  57. package/dist/{chunk-h3w814js.js → chunk-skg520wq.js} +2 -2
  58. package/dist/{chunk-jzvbjn6e.js → chunk-sr4zv59p.js} +1 -1
  59. package/dist/{chunk-5nezhmnq.js → chunk-t1633e8m.js} +2 -2
  60. package/dist/{chunk-2vyfsby0.js → chunk-t5ysd5z8.js} +1 -1
  61. package/dist/{chunk-3cd753fb.js → chunk-t6phsb5h.js} +2 -2
  62. package/dist/{chunk-ky9q53m7.js → chunk-tpxs85cg.js} +1 -1
  63. package/dist/chunk-w2sb1hy9.js +1 -0
  64. package/dist/{chunk-7nx0pzfk.js → chunk-ww51801m.js} +1 -1
  65. package/dist/chunk-x2rraka3.js +1 -0
  66. package/dist/{chunk-30y6med4.js → chunk-xepdd9yj.js} +1 -1
  67. package/dist/chunk-xj65p2sn.js +1 -0
  68. package/dist/chunk-xp3ad15c.js +10 -0
  69. package/dist/{chunk-m1xmc7kh.js → chunk-xy67pj74.js} +325 -320
  70. package/dist/chunk-xzgqyzmy.js +171 -0
  71. package/dist/chunk-znhjr51w.js +1 -0
  72. package/dist/chunk-zp27f256.js +6 -0
  73. package/dist/web/assets/{ChatView-tu6nu0Yw.js → ChatView-DRn47Y3l.js} +3 -3
  74. package/dist/web/assets/{CodeBlockHighlighter-DFj0ZWq6.js → CodeBlockHighlighter-DxATdO6i.js} +1 -1
  75. package/dist/web/assets/{FilePreview-CLJNHlXO.js → FilePreview-D21mo4fn.js} +1 -1
  76. package/dist/web/assets/{KanbanBoard-B63UlcNr.js → KanbanBoard-DEUuLh0H.js} +1 -1
  77. package/dist/web/assets/{MarkdownRenderer-D7ap0LLK.js → MarkdownRenderer-BA9VgOyM.js} +3 -3
  78. package/dist/web/assets/{SettingsModal-B8Gp0bXw.js → SettingsModal-CXq3qDgQ.js} +1 -1
  79. package/dist/web/assets/{TaskSwitcher-gxALR-zu.js → TaskSwitcher-CUcZEUQH.js} +1 -1
  80. package/dist/web/assets/{TerminalPanel-dnC4oh4w.js → TerminalPanel-CcC6f3H_.js} +1 -1
  81. package/dist/web/assets/{index-Dn4vZglG.js → index-CfVQVVVI.js} +3 -3
  82. package/dist/web/assets/{teamService-CoJLtqAq.js → teamService-BX1zdQBb.js} +1 -1
  83. package/dist/web/index.html +1 -1
  84. package/package.json +1 -1
  85. package/dist/chunk-523kette.js +0 -1
  86. package/dist/chunk-6adxyred.js +0 -1
  87. package/dist/chunk-8g00qcv6.js +0 -171
  88. package/dist/chunk-bhwxskbf.js +0 -1
  89. package/dist/chunk-cwhxx0kj.js +0 -112
  90. package/dist/chunk-daca5tet.js +0 -1
  91. package/dist/chunk-etjw6np8.js +0 -1
  92. package/dist/chunk-ex3zfc8d.js +0 -1
  93. package/dist/chunk-g1e92rmg.js +0 -10
  94. package/dist/chunk-gn6ftvjy.js +0 -1
  95. package/dist/chunk-h9xayrwp.js +0 -1
  96. package/dist/chunk-reakyamv.js +0 -2
  97. package/dist/chunk-rpbyc2k4.js +0 -1
  98. package/dist/chunk-tkhbf34n.js +0 -1
  99. package/dist/chunk-twdw0c2p.js +0 -1
  100. package/dist/chunk-w7a801g0.js +0 -1
  101. package/dist/chunk-x5cya3gg.js +0 -6
  102. package/dist/chunk-zb79xdyv.js +0 -1
  103. package/dist/chunk-zd2zhy2t.js +0 -1
@@ -0,0 +1 @@
1
+ import{ud as a,vd as b}from"./chunk-mq2nx77s.js";import"./chunk-fs9j9gas.js";import"./chunk-6jsmac0q.js";export{a as globalOptions,b as cliConfig};
@@ -0,0 +1,6 @@
1
+ import{m as SH,n as TH,o as bH,p as IH,q as RH,r as gH}from"./chunk-m0a75642.js";import{A as VH,v as yH,w as HH,x as JH,y as KH,z as d}from"./chunk-69rpb78b.js";import{Q as _H,S as GH,T as PH,V as qH,Y as FH}from"./chunk-xy67pj74.js";import"./chunk-p9a3d507.js";import"./chunk-tpxs85cg.js";import{Eb as UH,jb as o,vb as xH}from"./chunk-xzgqyzmy.js";import"./chunk-r8wbvxn7.js";import{Cc as jH,Nc as O,Yc as i,yc as WH}from"./chunk-2b7zryg3.js";import"./chunk-d2pwwdab.js";import"./chunk-r77pcb0f.js";import{ud as AH}from"./chunk-mq2nx77s.js";import{wd as MH,xd as fH,yd as zH}from"./chunk-mgtcjwhy.js";import{zd as EH}from"./chunk-fv8b98tz.js";import"./chunk-skg520wq.js";import{Zd as LH}from"./chunk-q14mgye7.js";import"./chunk-v508x7cg.js";import"./chunk-g9xjcfrf.js";import"./chunk-b2p9qm6j.js";import"./chunk-0q5bz3nm.js";import"./chunk-44dzrn0p.js";import"./chunk-73j10ezs.js";import"./chunk-g832dwdm.js";import{kf as $H}from"./chunk-sr4zv59p.js";import"./chunk-ww51801m.js";import"./chunk-7rfhmbqw.js";import"./chunk-4rq0jhf4.js";import"./chunk-272swnyr.js";import"./chunk-t6phsb5h.js";import{Dg as QH}from"./chunk-7m5q8vxf.js";import{Fg as DH,Hg as H,Ig as ZH,Kg as N}from"./chunk-sk8h4m9m.js";import{Og as a,Pg as s}from"./chunk-hg8d4vhj.js";import{Tg as g}from"./chunk-sb84vdcf.js";import"./chunk-hjr9r44k.js";import"./chunk-ffa6hhee.js";import"./chunk-t1633e8m.js";import"./chunk-m5f934fh.js";import"./chunk-fs9j9gas.js";import"./chunk-rwvaapta.js";import"./chunk-83caxxbt.js";import"./chunk-shr5cg46.js";import"./chunk-6jsmac0q.js";import SJ from"yargs";import{hideBin as TJ}from"yargs/helpers";function p(K,V,Q){if(K.off){K.off(V,Q);return}K.removeListener?.(V,Q)}function uH(K,V){if(!K.once&&!K.on||!K.off&&!K.removeListener)throw Error("Writable returned false without an observable drain contract");return new Promise((Q,q)=>{let J=!1,Z=()=>{p(K,"drain",x),p(K,"error",j),V.removeEventListener("abort",P)},W=(F)=>{if(J)return;J=!0,Z(),F()},x=()=>W(Q),j=(F)=>W(()=>q(F??Error("Writable emitted an error"))),P=()=>W(()=>q(V.reason??Error("Writable drain aborted")));if(V.aborted){P();return}let y=K.once?.bind(K)??K.on?.bind(K);y?.("drain",x),y?.("error",j),V.addEventListener("abort",P,{once:!0})})}async function dH(K,V,Q){if(K.destroyed||K.writableEnded)throw Error("Writable is already closed");if(K.write(V)===!1)await uH(K,Q)}class v{options;queues;sinkErrorListeners=[];failed=!1;closing=!1;handleAbort=()=>{this.fail(new d("aborted","Headless output was aborted",{cause:this.options.signal?.reason}))};constructor(K,V={}){this.options=V;let Q=(q)=>new VH({maxPendingItems:V.maxPendingItems??HH,maxPendingBytes:V.maxPendingBytes??JH,writeTimeoutMs:V.writeTimeoutMs??KH,sizeOf:(J)=>Buffer.byteLength(J),write:(J,Z)=>dH(K[q],J,Z),onFailure:(J)=>this.fail(J)});if(this.queues={stdout:Q("stdout"),stderr:Q("stderr")},this.observeSinkErrors(K.stdout),K.stderr!==K.stdout)this.observeSinkErrors(K.stderr);if(V.signal?.addEventListener("abort",this.handleAbort,{once:!0}),V.signal?.aborted)this.handleAbort()}write(K,V){return this.queues[K].offer(V).accepted}async flush(){await Promise.all([this.queues.stdout.flush(),this.queues.stderr.flush()])}close(K){if(this.closing||this.failed)return;this.closing=!0,this.options.signal?.removeEventListener("abort",this.handleAbort),this.removeSinkErrorListeners(),this.queues.stdout.close(K),this.queues.stderr.close(K)}stats(){return{stdout:this.queues.stdout.stats(),stderr:this.queues.stderr.stats()}}observeSinkErrors(K){if(!K.on||!K.off&&!K.removeListener)return;let V=(Q)=>{this.fail(new d("write_failed","Headless writable failed",{cause:Q??Error("Writable emitted an error")}))};K.on("error",V),this.sinkErrorListeners.push({writer:K,listener:V})}fail(K){if(this.closing||this.failed)return;this.failed=!0,this.options.signal?.removeEventListener("abort",this.handleAbort),this.removeSinkErrorListeners(),this.queues.stdout.close(K),this.queues.stderr.close(K),this.options.onFailure?.(K)}removeSinkErrorListeners(){for(let{writer:K,listener:V}of this.sinkErrorListeners.splice(0))p(K,"error",V)}}var XH=1;function D(K){return H.Object({event_version:H.Literal(XH),...K})}var pH=D({type:H.Literal("content_delta"),delta:H.String()}),vH=D({type:H.Literal("thinking_delta"),delta:H.String()}),lH=D({type:H.Literal("thinking"),content:H.String()}),aH=D({type:H.Literal("stream_end")}),sH=D({type:H.Literal("content"),content:H.String()}),iH=D({type:H.Literal("structured_output"),output:H.Record(H.String(),H.Unknown()),schema_digest:H.String({pattern:"^[a-f0-9]{64}$"})}),l=N(["readonly","write","execute"]),oH=H.Object({kind:l,scope:N(["global","session"]),queue_position:H.Integer({minimum:1}),in_flight:H.Integer({minimum:0}),limit:H.Integer({minimum:1})}),rH=D({type:H.Literal("tool_start"),tool_name:H.String(),summary:H.String(),target:H.Optional(H.String()),tool_kind:H.Optional(l)}),nH=D({type:H.Literal("tool_progress"),tool_name:H.String(),message:H.String(),progress:H.Optional(H.Number()),total:H.Optional(H.Number()),admission:H.Optional(oH)}),tH=H.Object({auto_backgrounded:H.Literal(!0),background_reason:H.Literal("foreground_budget"),foreground_budget_ms:H.Integer({minimum:1}),shell_id:H.String({minLength:1,maxLength:128,pattern:"^bash_[A-Za-z0-9-]+$"}),pid:H.Optional(H.Integer({minimum:1})),terminal_transport:N(["local","acp"])}),eH=D({type:H.Literal("tool_result"),tool_name:H.String(),summary:H.String(),target:H.Optional(H.String()),tool_kind:H.Optional(l),success:H.Optional(H.Boolean()),error_type:H.Optional(H.String()),error_message:H.Optional(H.String()),background:H.Optional(tH)}),HJ=D({type:H.Literal("mcp_catalog_changed"),revision:H.Integer({minimum:1}),server_name:H.String(),added:H.Array(H.String()),removed:H.Array(H.String()),updated:H.Array(H.String())}),JJ=D({type:H.Literal("mcp_content_changed"),revision:H.Integer({minimum:1}),server_name:H.String(),content_kind:N(["resources","resource_templates","prompts"]),added:H.Array(H.String()),removed:H.Array(H.String()),updated:H.Array(H.String())}),KJ=D({type:H.Literal("mcp_resource_updated"),revision:H.Integer({minimum:1}),server_name:H.String(),uri:H.String()}),VJ=D({type:H.Literal("mcp_connection_changed"),revision:H.Integer({minimum:1}),server_name:H.String(),phase:N(["reconnecting","recovered","failed"]),reason:H.String(),attempt:H.Integer({minimum:0}),max_attempts:H.Integer({minimum:0}),next_retry_at:H.Optional(H.Integer({minimum:0})),error:H.Optional(H.String())}),ZJ=D({type:H.Literal("mcp_log"),revision:H.Integer({minimum:1}),server_name:H.String(),level:N(["debug","info","notice","warning","error","critical","alert","emergency"]),logger:H.Optional(H.String()),message:H.String(),projected_bytes:H.Integer({minimum:0}),data_sha256:H.String(),truncated:H.Boolean(),details_omitted:H.Boolean(),timestamp:H.Integer({minimum:0}),synthetic:H.Optional(H.Boolean())}),$J=D({type:H.Literal("mcp_instructions_changed"),revision:H.Integer({minimum:0}),server_name:H.String(),action:N(["added","removed"]),reason:N(["snapshot","connection","disconnection"]),text:H.Optional(H.String()),source_bytes:H.Optional(H.Integer({minimum:0})),projected_bytes:H.Optional(H.Integer({minimum:0})),sha256:H.Optional(H.String()),truncated:H.Optional(H.Boolean()),details_omitted:H.Optional(H.Boolean())}),qJ=D({type:H.Literal("mcp_task_changed"),revision:H.Integer({minimum:0}),task_id:H.String(),server_name:H.String(),tool_name:H.String(),status:N(["working","input_required","interrupted","completed","failed","cancelled"]),status_message:H.Optional(H.String()),created_at:H.Integer({minimum:0}),updated_at:H.Integer({minimum:0}),completed_at:H.Optional(H.Integer({minimum:0})),has_result:H.Boolean(),error:H.Optional(H.String())}),XJ=D({type:H.Literal("project_rules_loaded"),files:H.Array(H.Object({id:H.String(),relative_path:H.String(),source:N(["project","local"]),conditional:H.Boolean(),content_sha256:H.String({pattern:"^[a-f0-9]{64}$"})})),trigger_paths:H.Array(H.String()),blocked_write:H.Boolean()}),YJ=D({type:H.Literal("user_shell_started"),execution_id:H.String(),command:H.String(),auxiliary:H.Boolean()}),BJ=D({type:H.Literal("user_shell_output"),execution_id:H.String(),stream:N(["stdout","stderr"]),chunk:H.String(),stream_truncated:H.Boolean()}),NJ=D({type:H.Literal("user_shell_completed"),execution_id:H.String(),message_id:H.String(),status:N(["completed","failed","aborted","timed_out","spawn_error"]),exit_code:H.Union([H.Integer(),H.Null()]),duration_ms:H.Number({minimum:0}),stdout:H.String(),stderr:H.String(),truncated:H.Boolean(),auxiliary:H.Boolean()}),QJ=D({type:H.Literal("phase"),phase:N(["turn","searching","inspecting","target_hit","executing","completed"]),status:N(["ongoing","hit","done"]),message:H.String(),turn:H.Optional(H.Number()),tool_name:H.Optional(H.String()),target:H.Optional(H.String())}),DJ=D({type:H.Literal("tool_detail"),tool_name:H.String(),detail:H.String()}),LJ=D({type:H.Literal("task_update"),tasks:H.Array(qH)}),WJ=D({type:H.Literal("goal"),state:N(["updated","cleared"]),goal_id:H.Optional(H.String()),status:H.Optional(N(["active","verifying","paused","blocked","usage_limited","budget_limited","complete"])),verification_attempt:H.Optional(H.Integer({minimum:1})),verification_status:H.Optional(N(["pending","pass","fail","partial"])),verifier_session_id:H.Optional(H.String()),verification_evidence_sha256:H.Optional(H.String({pattern:"^[a-f0-9]{64}$"})),verification_summary:H.Optional(H.String()),verification_stall_count:H.Optional(H.Integer({minimum:1})),premature_stop_pattern:H.Optional(N($H)),premature_stop_count:H.Optional(H.Integer({minimum:1}))}),jJ=D({type:H.Literal("subagent"),state:N(["spawned","completed"]),session_id:H.String(),subagent_type:H.Optional(H.String()),success:H.Optional(H.Boolean()),summary:H.Optional(H.String()),verification_verdict:H.Optional(N(["pass","fail","partial"])),resumed_from:H.Optional(H.String()),root_agent_id:H.Optional(H.String()),resume_depth:H.Optional(H.Integer({minimum:0}))}),xJ=D({type:H.Literal("token_usage"),input_tokens:H.Number(),output_tokens:H.Number(),total_tokens:H.Number(),max_context_tokens:H.Number(),cache_read_tokens:H.Optional(H.Number()),cache_write_tokens:H.Optional(H.Number()),prompt_cache_break:H.Optional(H.Object({reason:N(["model_changed","system_prompt_changed","tools_changed","request_policy_changed","ttl_expired","server_side"]),previous_cache_read_tokens:H.Number(),cache_read_tokens:H.Number(),cache_write_tokens:H.Number(),token_drop:H.Number(),elapsed_ms:H.Number(),call_number:H.Number(),system_prompt_changed:H.Boolean(),system_char_delta:H.Number(),tools_changed:H.Boolean(),added_tool_count:H.Number(),removed_tool_count:H.Number(),changed_tool_count:H.Number(),model_changed:H.Boolean(),request_policy_changed:H.Boolean()})),cost_usd:H.Optional(H.Number())}),UJ=D({type:H.Literal("compacting"),state:N(["started","completed"]),reason:H.Optional(N(["threshold","context_limit","turn_limit","manual"])),strategy:H.Optional(N(["llm","fallback","snip"])),outcome:H.Optional(N(["completed","fallback","failed"])),pre_tokens:H.Optional(H.Number({minimum:0})),pre_token_source:H.Optional(N(["provider","provider_plus_estimate","local_estimate"])),estimated_pending_tokens:H.Optional(H.Number({minimum:0})),post_tokens:H.Optional(H.Number({minimum:0})),sample_attempts:H.Optional(H.Integer({minimum:0})),input_reductions:H.Optional(H.Integer({minimum:0})),messages_omitted:H.Optional(H.Integer({minimum:0})),files_omitted:H.Optional(H.Integer({minimum:0})),images_omitted:H.Optional(H.Integer({minimum:0})),fallback_target_tokens:H.Optional(H.Integer({minimum:0})),fallback_messages_omitted:H.Optional(H.Integer({minimum:0})),fallback_messages_truncated:H.Optional(H.Integer({minimum:0})),failure_reason:H.Optional(N(["circuit_open","context_exhausted","deterministic","empty_exhausted","insufficient_reduction","transient_exhausted"]))}),_J=D({type:H.Literal("provider_retry"),phase:N(["scheduled","waiting","attempt","recovered","exhausted"]),attempt:H.Integer({minimum:0}),max_retries:H.Integer({minimum:0}),reason:N(["rate_limit","server_error","timeout","transport","stream_closed"]),status_code:H.Optional(H.Integer({minimum:100,maximum:599})),delay_ms:H.Optional(H.Integer({minimum:0})),next_retry_at:H.Optional(H.Integer({minimum:0})),mode:H.Optional(N(["standard","bounded_foreground"])),recovery_budget_ms:H.Optional(H.Integer({minimum:0})),recovery_elapsed_ms:H.Optional(H.Integer({minimum:0})),recovery_remaining_ms:H.Optional(H.Integer({minimum:0})),exhausted_by:H.Optional(N(["attempt_limit","recovery_budget"]))}),GJ=D({type:H.Literal("provider_admission"),phase:N(["queued","admitted","rejected"]),request_class:N(["foreground","background","internal"]),resource:N(["stream","pending_count","pending_bytes"]),scope:N(["global","domain","owner","class"]),reason:H.Optional(N(["capacity","queue_full","wait_timeout","closed"])),queue_position:H.Integer({minimum:0}),queue_depth:H.Integer({minimum:0}),in_flight:H.Integer({minimum:0}),limit:H.Integer({minimum:0}),wait_ms:H.Integer({minimum:0}),max_wait_ms:H.Integer({minimum:0}),recovery_remaining_ms:H.Optional(H.Integer({minimum:0}))}),PJ=D({type:H.Literal("provider_circuit"),phase:N(["opened","waiting","probe","closed","reopened","rejected"]),reason:N(["rate_limit","server_error","transport","stream_closed"]),status_code:H.Optional(H.Integer({minimum:100,maximum:599})),retry_after_ms:H.Optional(H.Integer({minimum:0})),next_probe_at:H.Optional(H.Integer({minimum:0})),open_duration_ms:H.Integer({minimum:0}),sample_count:H.Optional(H.Integer({minimum:0})),failure_count:H.Optional(H.Integer({minimum:0})),recovery_remaining_ms:H.Optional(H.Integer({minimum:0}))}),FJ=D({type:H.Literal("provider_stall"),phase:N(["detected","recovered"]),stall_count:H.Integer({minimum:1}),duration_ms:H.Integer({minimum:0}),warning_after_ms:H.Integer({minimum:1}),timeout_ms:H.Integer({minimum:1}),output_started:H.Boolean()}),EJ=D({type:H.Literal("action_stationarity"),phase:N(["detected","recovered","halted"]),tool_name:H.String(),run_length:H.Integer({minimum:1}),nudge_threshold:H.Integer({minimum:1}),halt_threshold:H.Integer({minimum:1}),progress_aware:H.Boolean()}),AJ=D({type:H.Literal("turn_limit"),turns_count:H.Number(),action:H.Literal("continue")}),MJ=D({type:H.Literal("task_session"),session_id:H.String(),project_path:H.String(),source_project_path:H.String(),isolation:N(["local","worktree"]),worktree_branch:H.Optional(H.String()),base_commit:H.Optional(H.String())}),fJ=D({type:H.Literal("task_admission"),state:N(["queued","running"]),queue_position:H.Optional(H.Integer({minimum:1})),queue_depth:H.Integer({minimum:0}),in_flight:H.Integer({minimum:0}),max_concurrent_tasks:H.Integer({minimum:1})}),zJ=D({type:H.Literal("output"),content:H.String(),exit_code:H.Number()}),yJ=D({type:H.Literal("error"),message:H.String()}),rJ=ZH(H.Union([pH,vH,lH,aH,sH,iH,rH,nH,eH,HJ,JJ,KJ,VJ,ZJ,$J,qJ,XJ,YJ,BJ,NJ,QJ,DJ,LJ,WJ,jJ,xJ,UJ,GJ,PJ,_J,FJ,EJ,AJ,MJ,fJ,zJ,yJ]));function YH(K,V){return{event_version:XH,type:K,...V}}function bJ(K){if(!K||typeof K!=="object"||Array.isArray(K))return;let V=K;if(V.auto_backgrounded!==!0||V.background_reason!=="foreground_budget"||!Number.isSafeInteger(V.foreground_budget_ms)||V.foreground_budget_ms<=0||typeof V.shell_id!=="string"||!/^bash_[A-Za-z0-9-]+$/.test(V.shell_id)||V.shell_id.length>128||V.terminal_transport!=="local"&&V.terminal_transport!=="acp"||V.pid!==void 0&&(!Number.isSafeInteger(V.pid)||V.pid<=0))return;return{auto_backgrounded:!0,background_reason:"foreground_budget",foreground_budget_ms:V.foreground_budget_ms,shell_id:V.shell_id,...V.pid===void 0?{}:{pid:V.pid},terminal_transport:V.terminal_transport}}function IJ(K){let V=new AbortController,Q=(Z)=>{if(!V.signal.aborted)V.abort(Z)},q=()=>Q("interrupt"),J=()=>Q(K?.signal?.reason);if(K?.signal){if(K.signal.addEventListener("abort",J,{once:!0}),K.signal.aborted)J()}else process.once("SIGINT",q),process.once("SIGTERM",q);return{signal:V.signal,abort:Q,dispose:()=>{K?.signal?.removeEventListener("abort",J),process.removeListener("SIGINT",q),process.removeListener("SIGTERM",q)}}}var RJ=N(["text","jsonl"]),gJ=H.Object({headless:H.Optional(H.Boolean()),message:H.Optional(H.String()),_:H.Optional(H.Array(H.Union([H.String(),H.Number()]))),model:H.Optional(H.String()),systemPrompt:H.Optional(H.String()),appendSystemPrompt:H.Optional(H.String()),verificationAgent:H.Optional(H.Boolean()),maxTurns:H.Optional(H.Refine(H.Integer(),(K)=>K===-1||K>0,()=>"must be -1 (unlimited) or a positive integer")),permissionMode:H.Optional(H.Enum(QH)),mcpConfig:H.Optional(H.Array(H.String())),strictMcpConfig:H.Optional(H.Boolean()),sessionId:H.Optional(H.String()),allowedTools:H.Optional(H.Array(H.String())),disallowedTools:H.Optional(H.Array(H.String())),agents:H.Optional(H.String()),continue:H.Optional(H.Boolean()),resume:H.Optional(H.Union([H.String(),H.Boolean()])),forkSession:H.Optional(H.Boolean()),taskIsolation:H.Optional(N(["local","worktree"])),outputFormat:H.Optional(RJ),jsonSchema:H.Optional(H.String()),outputSchema:H.Optional(H.String())});class CH{openedThinking=!1;wroteAssistantContent=!1;markAssistantContent(){this.wroteAssistantContent=!0}setThinkingOpened(K){this.openedThinking=K}hasOpenThinking(){return this.openedThinking}completeStream(){let K={openedThinking:this.openedThinking,wroteAssistantContent:this.wroteAssistantContent};return this.openedThinking=!1,this.wroteAssistantContent=!1,K}}function CJ(K){return K.issues.map((V)=>`${V.path.join(".")||"options"}: ${V.message}`).join("; ")}function kJ(K){let V=DH(gJ,K);if(!V.success)throw Error(`Invalid headless options: ${CJ(V.error)}`);return V.data}function hJ(K){return K.command("* [message]","Run full agent loop without Ink UI and print events to the terminal",(V)=>V.positional("message",{describe:"Message to process",type:"string"}).option("headless",{type:"boolean",describe:"Run full agent loop without Ink UI and print events to the terminal"}).option("model",{describe:"Model ID for this run",type:"string"}).option("system-prompt",{describe:"Replace the default system prompt",type:"string"}).option("append-system-prompt",{describe:"Append a system prompt to the default system prompt",type:"string"}).option("verification-agent",{describe:"Run the built-in independent verification agent after non-trivial changes",type:"boolean",default:!0}).option("max-turns",{alias:["maxTurns"],describe:"Maximum conversation turns (-1: unlimited, N>0: limit to N turns)",type:"number"}).option("output-format",{alias:["outputFormat"],choices:["text","jsonl"],describe:"Headless output format",type:"string"}).option("json-schema",{alias:["jsonSchema"],describe:"Inline JSON Schema for the structured final response",type:"string"}).option("output-schema",{alias:["outputSchema"],describe:"Path to a JSON Schema file for the structured final response",type:"string"}).option("task-isolation",{alias:["taskIsolation"],choices:["local","worktree"],describe:"Dispatch a new durable task in the selected workspace mode",type:"string"}),async(V)=>{if(!V.headless)return;let Q=await dJ(V);process.exit(Q)})}function L(K,V=""){K.write(`${V}
2
+ `)}function OJ(K){return`[task] [${K.status}] ${K.subject}`}function wJ(){return{requestConfirmation:async(K)=>K.type==="mcpElicitation"?{approved:!1,reason:"headless-mcp-elicitation-unavailable",elicitation:{action:"cancel"}}:K.type==="mcpSampling"?{approved:!1,reason:"headless-mcp-sampling-unavailable"}:{approved:!0,reason:"headless-auto-approved",scope:"session"}}}function mJ(K){if(!(K instanceof Error))return"Unknown error";let q=K.lastError??K;if(q.responseBody)try{let W=JSON.parse(q.responseBody)?.error?.message;if(W)return q.statusCode?`${W} (HTTP ${q.statusCode})`:W}catch{}let J=K.message.match(/Last error:\s*(.+)$/);if(J)return J[1];return K.message}function cJ(K){return K==="jsonl"?"jsonl":"text"}function BH(K,V){let Q=(...q)=>{for(let J of q){let Z=V[J];if(typeof Z==="string"&&Z.trim()!=="")return Z}return};switch(K){case"Read":case"Edit":case"Write":case"UndoEdit":return Q("file_path");case"ApplyPatch":return"multi-file patch";case"NotebookEdit":return Q("notebook_path");case"Grep":return Q("path","pattern");case"Glob":return Q("pattern");case"WebFetch":return Q("url");case"WebSearch":return Q("query");case"Bash":return Q("command","description");case"Task":return Q("description");case"LSP":return Q("filePath","operation");case"EnterWorktree":return Q("name");case"ExitWorktree":return Q("action");default:return}}function uJ(K,V,Q,q){let J=new Set(["Glob","Grep","WebSearch","LS"]),Z=new Set(["Read","WebFetch"]);if(new Set(["Edit","Write","ApplyPatch","NotebookEdit","Bash","LSP","UndoEdit","EnterWorktree","ExitWorktree"]).has(K)&&!q.targetLocked)return{phase:"target_hit",status:"hit",message:`Target locked: ${V}`,shouldLockTarget:!0};if(q.targetLocked)return{phase:"executing",status:"hit",message:Q?`Working within target: ${V}`:`Executing: ${V}`,shouldLockTarget:!1};if(J.has(K))return{phase:"searching",status:"ongoing",message:`Still searching: ${V}`,shouldLockTarget:!1};if(Z.has(K))return{phase:"inspecting",status:"ongoing",message:`Inspecting candidate: ${V}`,shouldLockTarget:!1};return{phase:"executing",status:q.targetLocked?"hit":"ongoing",message:`Executing: ${V}`,shouldLockTarget:!1}}function NH(K,V,Q=!1){let q=(J,Z)=>{K.stdout.write(`${JSON.stringify(YH(J,Z))}
3
+ `)};return{contentDelta(J){if(V==="jsonl"){q("content_delta",{delta:J});return}if(Q)return;K.stdout.write(J)},thinkingDelta(J,Z){if(V==="jsonl")return q("thinking_delta",{delta:J}),Z;if(!Z)K.stderr.write("[thinking] ");return K.stderr.write(J),!0},thinking(J){if(V==="jsonl"){q("thinking",{content:J});return}L(K.stderr,`[thinking] ${J}`)},streamEnd(J,Z){if(V==="jsonl"){q("stream_end",{});return}if(Z)K.stderr.write(`
4
+ `);if(J)K.stdout.write(`
5
+ `)},content(J){if(V==="jsonl"){q("content",{content:J});return}L(K.stdout,J)},structuredOutput(J){if(V==="jsonl"){q("structured_output",{output:J.output,schema_digest:J.schemaDigest});return}L(K.stdout,JSON.stringify(J.output))},toolStart(J,Z,W,x){if(V==="jsonl"){q("tool_start",{tool_name:J,summary:Z,target:W,tool_kind:x});return}L(K.stderr,`[tool:start] ${Z}`)},toolProgress(J,Z,W,x,j){if(V==="jsonl"){q("tool_progress",{tool_name:J,message:Z,progress:W,total:x,admission:j?{kind:j.kind,scope:j.scope,queue_position:j.queuePosition,in_flight:j.inFlight,limit:j.limit}:void 0});return}L(K.stderr,`[tool:progress] ${J}: ${Z}`)},toolResult(J,Z,W,x,j){if(V==="jsonl"){q("tool_result",{tool_name:J,summary:Z,target:W,tool_kind:x,success:j?.success,error_type:j?.errorType,error_message:j?.errorMessage,background:j?.background});return}L(K.stderr,`[tool:result] ${Z}`)},mcpCatalogChanged(J){if(V==="jsonl"){q("mcp_catalog_changed",{revision:J.revision,server_name:J.serverName,added:J.added,removed:J.removed,updated:J.updated});return}L(K.stderr,`[mcp:catalog] r${J.revision} ${J.serverName} +${J.added.length} -${J.removed.length} ~${J.updated.length}`)},mcpContentChanged(J){if(V==="jsonl"){q("mcp_content_changed",{revision:J.revision,server_name:J.serverName,content_kind:J.contentKind==="resourceTemplates"?"resource_templates":J.contentKind,added:J.added,removed:J.removed,updated:J.updated});return}L(K.stderr,`[mcp:${J.contentKind}] r${J.revision} ${J.serverName} +${J.added.length} -${J.removed.length} ~${J.updated.length}`)},mcpResourceUpdated(J){if(V==="jsonl"){q("mcp_resource_updated",{revision:J.revision,server_name:J.serverName,uri:J.uri});return}L(K.stderr,`[mcp:resource] r${J.revision} ${J.serverName} updated ${J.uri}`)},mcpConnectionChanged(J){if(V==="jsonl"){q("mcp_connection_changed",{revision:J.revision,server_name:J.serverName,phase:J.phase,reason:J.reason,attempt:J.attempt,max_attempts:J.maxAttempts,...J.nextRetryAt!==void 0?{next_retry_at:J.nextRetryAt}:{},...J.error?{error:J.error}:{}});return}L(K.stderr,`[mcp:connection] r${J.revision} ${J.serverName} ${J.phase} ${J.attempt}/${J.maxAttempts}`)},mcpLog(J){if(V==="jsonl"){q("mcp_log",{revision:J.revision,server_name:J.serverName,level:J.level,logger:J.logger,message:J.message,projected_bytes:J.projectedBytes,data_sha256:J.dataSha256,truncated:J.truncated,details_omitted:J.detailsOmitted,timestamp:J.timestamp,synthetic:J.synthetic});return}L(K.stderr,`[mcp:log] ${J.level} ${J.serverName}${J.logger?` logger=${J.logger}`:""}: ${J.message}`)},mcpInstructionsChanged(J){if(V==="jsonl"){q("mcp_instructions_changed",{revision:J.revision,server_name:J.serverName,action:J.action,reason:J.reason,text:J.text,source_bytes:J.sourceBytes,projected_bytes:J.projectedBytes,sha256:J.sha256,truncated:J.truncated,details_omitted:J.detailsOmitted});return}L(K.stderr,`[mcp:instructions] ${J.action} ${J.serverName}${J.truncated?" (truncated)":""}`)},mcpTaskChanged(J){if(V==="jsonl"){q("mcp_task_changed",{revision:J.revision,task_id:J.taskId,server_name:J.serverName,tool_name:J.toolName,status:J.status,status_message:J.statusMessage,created_at:J.createdAt,updated_at:J.updatedAt,completed_at:J.completedAt,has_result:J.hasResult,error:J.error});return}L(K.stderr,`[mcp:task] ${J.taskId} ${J.serverName}/${J.toolName} `+J.status)},projectRulesLoaded(J){if(V==="jsonl"){q("project_rules_loaded",{files:J.files.map((Z)=>({id:Z.id,relative_path:Z.relativePath,source:Z.source,conditional:Z.conditional,content_sha256:Z.contentSha256})),trigger_paths:J.triggerPaths,blocked_write:J.blockedWrite});return}L(K.stderr,`[project-rules] loaded ${J.files.length} file(s)${J.blockedWrite?" before write":""}`)},userShellStarted(J,Z,W){if(V==="jsonl"){q("user_shell_started",{execution_id:J,command:Z,auxiliary:W});return}L(K.stderr,`[user-shell:start] ${Z}`)},userShellOutput(J,Z,W,x){if(V==="jsonl"){q("user_shell_output",{execution_id:J,stream:Z,chunk:W,stream_truncated:x});return}(Z==="stderr"?K.stderr:K.stdout).write(W)},userShellCompleted(J){if(V==="jsonl"){q("user_shell_completed",{execution_id:J.executionId,message_id:J.messageId,status:J.record.status,exit_code:J.record.exitCode,duration_ms:J.record.durationMs,stdout:J.record.stdout,stderr:J.record.stderr,truncated:J.record.truncated,auxiliary:J.auxiliary});return}L(K.stderr,`[user-shell:${J.record.status}] exit=${J.record.exitCode??"null"} ${J.record.durationMs}ms`)},phase(J,Z,W,x={}){if(V==="jsonl"){q("phase",{phase:J,status:Z,message:W,turn:x.turn,tool_name:x.toolName,target:x.target});return}L(K.stderr,`[phase:${J}] ${W}`)},toolDetail(J,Z){if(V==="jsonl"){q("tool_detail",{tool_name:J,detail:Z});return}L(K.stderr,Z)},taskUpdate(J){if(V==="jsonl"){q("task_update",{tasks:J});return}for(let Z of J)L(K.stderr,OJ(Z))},goal(J){if(V==="jsonl"){q("goal",{state:J.goal?"updated":"cleared",goal_id:J.goal?.goalId,status:J.goal?.status,verification_attempt:J.goal?.completionVerification?.attempt,verification_status:J.goal?.completionVerification?.status,verifier_session_id:J.goal?.completionVerification?.verifierSessionId,verification_evidence_sha256:J.goal?.completionVerification?.evidenceSha256,verification_summary:J.goal?.completionVerification?.summary,verification_stall_count:J.goal?.verificationStall?.consecutiveCount,premature_stop_pattern:J.goal?.prematureStop?.pattern,premature_stop_count:J.goal?.prematureStop?.consecutiveCount});return}if(J.goal)L(K.stderr,`[goal:${J.goal.status}] ${J.goal.objective}`);else L(K.stderr,"[goal:cleared]")},subagent(J){let Z=J.kind==="subagent_spawned";if(V==="jsonl"){q("subagent",{state:Z?"spawned":"completed",session_id:J.sessionId,subagent_type:J.type,success:Z?void 0:J.success,summary:Z?void 0:J.summary,verification_verdict:Z?void 0:J.verificationVerdict,resumed_from:J.resumedFrom,root_agent_id:J.rootAgentId,resume_depth:J.resumeDepth});return}L(K.stderr,`[subagent:${Z?"spawned":"completed"}] ${J.sessionId}${J.resumedFrom?` resumed from ${J.resumedFrom}`:""}`)},tokenUsage(J){if(V==="jsonl"){q("token_usage",{input_tokens:J.inputTokens,output_tokens:J.outputTokens,total_tokens:J.totalTokens,max_context_tokens:J.maxContextTokens,cache_read_tokens:J.cacheReadTokens,cache_write_tokens:J.cacheWriteTokens,prompt_cache_break:J.cacheBreak?{reason:J.cacheBreak.reason,previous_cache_read_tokens:J.cacheBreak.previousCacheReadTokens,cache_read_tokens:J.cacheBreak.cacheReadTokens,cache_write_tokens:J.cacheBreak.cacheWriteTokens,token_drop:J.cacheBreak.tokenDrop,elapsed_ms:J.cacheBreak.elapsedMs,call_number:J.cacheBreak.callNumber,system_prompt_changed:J.cacheBreak.systemPromptChanged,system_char_delta:J.cacheBreak.systemCharDelta,tools_changed:J.cacheBreak.toolsChanged,added_tool_count:J.cacheBreak.addedToolCount,removed_tool_count:J.cacheBreak.removedToolCount,changed_tool_count:J.cacheBreak.changedToolCount,model_changed:J.cacheBreak.modelChanged,request_policy_changed:J.cacheBreak.requestPolicyChanged}:void 0,cost_usd:J.costUsd});return}L(K.stderr,`[tokens] in=${J.inputTokens} out=${J.outputTokens} total=${J.totalTokens} / ${J.maxContextTokens}`)},compacting(J){let Z=J.phase==="start";if(V==="jsonl"){q("compacting",{state:Z?"started":"completed",reason:J.reason,strategy:J.strategy,outcome:J.outcome,pre_tokens:J.preTokens,pre_token_source:J.preTokenSource,estimated_pending_tokens:J.estimatedPendingTokens,post_tokens:J.postTokens,sample_attempts:J.sampleAttempts,input_reductions:J.inputReductions,messages_omitted:J.messagesOmitted,files_omitted:J.filesOmitted,images_omitted:J.imagesOmitted,fallback_target_tokens:J.fallbackTargetTokens,fallback_messages_omitted:J.fallbackMessagesOmitted,fallback_messages_truncated:J.fallbackMessagesTruncated,failure_reason:J.failureReason});return}L(K.stderr,Z?`[context] compacting started${J.reason?` (${J.reason})`:""}`:`[context] compacting ${J.outcome??"completed"}${J.sampleAttempts!==void 0?` after ${J.sampleAttempts} sample attempt${J.sampleAttempts===1?"":"s"}`:""}${J.inputReductions?` with ${J.inputReductions} input reduction${J.inputReductions===1?"":"s"}`:""}${J.imagesOmitted?` and ${J.imagesOmitted} image${J.imagesOmitted===1?"":"s"} omitted`:""}${J.fallbackTargetTokens!==void 0?`; fallback target ${J.fallbackTargetTokens} tokens, ${J.fallbackMessagesOmitted??0} messages omitted, ${J.fallbackMessagesTruncated??0} truncated`:""}`)},providerAdmission(J){if(V==="jsonl"){q("provider_admission",{phase:J.phase,request_class:J.requestClass,resource:J.resource,scope:J.scope,reason:J.reason,queue_position:J.queuePosition,queue_depth:J.queueDepth,in_flight:J.inFlight,limit:J.limit,wait_ms:J.waitMs,max_wait_ms:J.maxWaitMs,recovery_remaining_ms:J.recoveryRemainingMs});return}L(K.stderr,`[provider-admission:${J.phase}] ${J.resource}/${J.scope} ${J.inFlight}/${J.limit} queue=${J.queuePosition}/${J.queueDepth}`)},providerRetry(J){if(V==="jsonl"){q("provider_retry",{phase:J.phase,attempt:J.attempt,max_retries:J.maxRetries,reason:J.reason,status_code:J.statusCode,delay_ms:J.delayMs,next_retry_at:J.nextRetryAt,mode:J.mode,recovery_budget_ms:J.recoveryBudgetMs,recovery_elapsed_ms:J.recoveryElapsedMs,recovery_remaining_ms:J.recoveryRemainingMs,exhausted_by:J.exhaustedBy});return}let Z=J.delayMs!==void 0?` in ${Math.max(0,Math.ceil(J.delayMs/1000))}s`:"";L(K.stderr,`[provider-retry:${J.phase}] ${J.attempt}/${J.maxRetries} ${J.reason}${Z}`)},providerCircuit(J){if(V==="jsonl"){q("provider_circuit",{phase:J.phase,reason:J.reason,status_code:J.statusCode,retry_after_ms:J.retryAfterMs,next_probe_at:J.nextProbeAt,open_duration_ms:J.openDurationMs,sample_count:J.sampleCount,failure_count:J.failureCount,recovery_remaining_ms:J.recoveryRemainingMs});return}let Z=J.retryAfterMs!==void 0?` retry in ${Math.max(0,Math.ceil(J.retryAfterMs/1000))}s`:"";L(K.stderr,`[provider-circuit:${J.phase}] ${J.reason}${Z}`)},providerStall(J){if(V==="jsonl"){q("provider_stall",{phase:J.phase,stall_count:J.stallCount,duration_ms:J.durationMs,warning_after_ms:J.warningAfterMs,timeout_ms:J.timeoutMs,output_started:J.outputStarted});return}L(K.stderr,`[provider-stall:${J.phase}] ${J.durationMs}ms / ${J.timeoutMs}ms`)},actionStationarity(J){if(V==="jsonl"){q("action_stationarity",{phase:J.phase,tool_name:J.toolName,run_length:J.runLength,nudge_threshold:J.nudgeThreshold,halt_threshold:J.haltThreshold,progress_aware:J.progressAware});return}L(K.stderr,`[action-stationarity:${J.phase}] ${J.toolName} ${J.runLength}/${J.haltThreshold}`)},turnLimit(J){if(V==="jsonl"){q("turn_limit",{turns_count:J,action:"continue"});return}L(K.stderr,`[turn-limit] continuing after ${J} turns`)},taskSession(J){if(V==="jsonl"){q("task_session",{session_id:J.sessionId,project_path:J.projectPath,source_project_path:J.sourceProjectPath,isolation:J.isolation,worktree_branch:J.worktreeBranch,base_commit:J.baseCommit});return}L(K.stderr,`[task:${J.isolation}] ${J.sessionId} ${J.sourceProjectPath} -> ${J.projectPath}${J.worktreeBranch?` (${J.worktreeBranch})`:""}`)},taskAdmission(J){if(V==="jsonl"){q("task_admission",{state:J.state,queue_position:J.queuePosition,queue_depth:J.queueDepth,in_flight:J.inFlight,max_concurrent_tasks:J.maxConcurrentTasks});return}L(K.stderr,J.state==="queued"?`[task:queued] position ${J.queuePosition??1}/${J.queueDepth} (running ${J.inFlight}/${J.maxConcurrentTasks})`:`[task:running] admitted (running ${J.inFlight}/${J.maxConcurrentTasks})`)},output(J,Z=0){if(V==="jsonl"){q("output",{content:J,exit_code:Z});return}L(Z===0?K.stdout:K.stderr,J)},error(J){if(V==="jsonl"){q("error",{message:J});return}L(K.stderr,J)}}}async function dJ(K,V={stdout:process.stdout,stderr:process.stderr},Q){let q="text",J=new CH,Z={targetLocked:!1},W,x,j,P=IJ(Q),y=!1,F=new v(V,{signal:P.signal,onFailure:(Y)=>{y=!0,P.abort(Y)}}),w={stdout:{write:(Y)=>F.write("stdout",Y)},stderr:{write:(Y)=>F.write("stderr",Y)}},B=NH(w,q),m=async()=>{try{return await F.flush(),!y}catch{return!1}},S=async(Y)=>{return x?.(),x=void 0,j?.(),j=void 0,await m()?Y:1};try{let Y=kJ(K);q=cJ(Y.outputFormat);let T=await RH(Y);B=NH(w,q,Boolean(T)),await SH();let r=Y.forkSession!==!0&&(Y.continue===!0||typeof Y.resume==="string"&&Y.resume.length>0)?await bH({message:Y.message,_:Y._,stdin:Q?.stdin}):await TH({...Y,stdin:Q?.stdin}),f=r===void 0,_=f?{mode:"agent",content:""}:await IH(r);if(_.mode==="output"){if(_.content)B.output(_.content,_.exitCode??0);return await S(_.exitCode??0)}if(!f&&_.content.length>a)throw Error(`User prompt exceeds the ${a}-character durable input limit`);if(!f&&Buffer.byteLength(_.content,"utf8")>s)throw Error(`User prompt exceeds the ${s}-byte durable input limit`);let C=_.content.trimStart().startsWith("!")?_.content.trimStart().slice(1).trim():void 0;if(C!==void 0&&Y.taskIsolation)throw Error("User shell commands cannot be combined with --task-isolation");if(C!==void 0&&T)throw Error("Output schemas cannot be combined with user shell commands");if(Y.taskIsolation&&(Y.continue||Y.resume||Y.forkSession))throw Error("--task-isolation cannot be combined with --continue, --resume, or --fork-session");let{sessionId:G,messages:n,metadata:t}=await gH({sessionId:Y.sessionId,continue:Y.continue,resume:Y.resume,forkSession:Y.forkSession,fallbackSessionPrefix:"headless"}),R=Y.permissionMode??t?.permissionMode??"yolo",e=Y.model&&Y.model!=="inherit"?Y.model:LH()?.id,U=Y.taskIsolation?await yH.createSessionTask({sessionId:G,prompt:_.content,sourceProjectPath:g(),isolation:Y.taskIsolation,dispatch:{version:1,prompt:_.content,sourceProjectPath:g(),isolation:Y.taskIsolation,permissionMode:R,...e?{modelId:e}:{},...T?{outputSchema:T}:{}}}):void 0,E=U?.metadata.projectPath??t?.projectPath??g();if(j=o.subscribe((X)=>{if(X.type!=="subagent.provider.admission"||X.sessionId!==G||X.projectPath!==E)return;let $=X.properties,A=["queued","admitted","rejected"],M=["foreground","background","internal"],z=["stream","pending_count","pending_bytes"],I=["global","domain","owner","class"],cH=["capacity","queue_full","wait_timeout","closed"];if(!A.includes($.phase)||!M.includes($.requestClass)||!z.includes($.resource)||!I.includes($.scope)||$.reason!==void 0&&!cH.includes($.reason)||typeof $.queuePosition!=="number"||typeof $.queueDepth!=="number"||typeof $.inFlight!=="number"||typeof $.limit!=="number"||typeof $.waitMs!=="number"||typeof $.maxWaitMs!=="number"||$.recoveryRemainingMs!==void 0&&typeof $.recoveryRemainingMs!=="number")return;B.providerAdmission({kind:"provider_admission",phase:$.phase,requestClass:$.requestClass,resource:$.resource,scope:$.scope,...$.reason!==void 0?{reason:$.reason}:{},queuePosition:$.queuePosition,queueDepth:$.queueDepth,inFlight:$.inFlight,limit:$.limit,waitMs:$.waitMs,maxWaitMs:$.maxWaitMs,...$.recoveryRemainingMs!==void 0?{recoveryRemainingMs:$.recoveryRemainingMs}:{}})}),!U)await i.setSessionPermissionMode(G,E,R);let kH=U?!1:await UH.cancelPendingNonInteractive(E,G);if(U)B.taskSession({sessionId:G,projectPath:E,sourceProjectPath:U.metadata.taskSourceProjectPath??g(),isolation:Y.taskIsolation,worktreeBranch:U.metadata.taskWorktreeBranch,baseCommit:U.metadata.taskBaseCommit}),x=o.subscribe((X)=>{if(X.type!=="task.status"||X.sessionId!==G||X.projectPath!==E||!["queued","running"].includes(String(X.properties.taskStatus))||typeof X.properties.taskQueueDepth!=="number"||typeof X.properties.taskInFlight!=="number"||typeof X.properties.taskConcurrencyLimit!=="number")return;B.taskAdmission({state:X.properties.taskStatus,queuePosition:typeof X.properties.taskQueuePosition==="number"?X.properties.taskQueuePosition:void 0,queueDepth:X.properties.taskQueueDepth,inFlight:X.properties.taskInFlight,maxConcurrentTasks:X.properties.taskConcurrencyLimit})});let hH={messages:kH?await i.loadSessionModelContext(G,E):[...n],userId:"cli-user",sessionId:G,workspaceRoot:E,permissionMode:R,signal:P.signal,...U?.taskWorktree?{worktreeActive:!0}:{},confirmationHandler:wJ()};W=await _H.create({sessionId:G,workspaceRoot:E,modelId:Y.model,permissionMode:R,mcpConfig:Y.mcpConfig,strictMcpConfig:Y.strictMcpConfig,agents:Y.agents?EH(Y.agents):void 0,...U?.taskWorktree?{taskWorktree:U.taskWorktree}:{},...U?.metadata.taskIsolation?{taskIsolation:U.metadata.taskIsolation}:{},...n.length>0?{sessionStart:{isResume:!0,resumeSessionId:G}}:{}});let k=f&&W.getPendingSteeringCount()>0,h=f&&!k?await W.getGoal():null,c=h?.status==="active"||h?.status==="verifying",b=f&&!k&&!c?await W.getRecoveredFinalResponse():void 0;if(f&&!k&&!c){if(!b)throw Error("No unfinished turn or active goal to resume");if(h)B.goal({kind:"goal_updated",goal:h});if(b.structuredOutput&&b.structuredOutputSchemaDigest)B.structuredOutput({kind:"structured_output",output:b.structuredOutput,schemaDigest:b.structuredOutputSchemaDigest});else B.content(b.content);return B.phase("completed","done","Recovered headless run completed"),await S(0)}if(C!==void 0){let X=await W.executeUserShellCommand(C,{signal:P.signal,onEvent:async($)=>{if($.type==="started")B.userShellStarted($.executionId,$.command,$.auxiliary);else if($.type==="output")B.userShellOutput($.executionId,$.stream,$.chunk,$.streamTruncated);await m()}});return B.userShellCompleted(X),await S(X.record.status==="completed"?0:X.record.status==="aborted"?130:X.record.exitCode??1)}let OH=Y.maxTurns??W.getConfig().maxTurns,wH=U?.taskWorktree?[...new Set([...Y.disallowedTools??[],"EnterWorktree","ExitWorktree"])]:Y.disallowedTools,mH=await FH.createWithRuntime(W,{sessionId:G,systemPrompt:Y.systemPrompt,appendSystemPrompt:Y.appendSystemPrompt,maxTurns:Y.maxTurns,modelId:Y.model,permissionMode:R,toolWhitelist:Y.allowedTools,toolBlacklist:wH,mcpConfig:Y.mcpConfig,strictMcpConfig:Y.strictMcpConfig}),u=await xH(mH.chatStream(_.content,hH,{stream:!0,signal:P.signal,maxTurns:Y.maxTurns,builtinVerification:Y.verificationAgent!==!1,outputSchema:T,pendingInputOnly:k,goalContinuationOnly:c,...OH===-1?{onTurnLimitReached:async(X)=>{return B.turnLimit(X.turnsCount),{continue:!0,reason:"headless-auto-continue"}}}:{}}),async(X)=>{switch(X.kind){case"content_delta":if(!T||q==="jsonl")J.markAssistantContent();B.contentDelta(X.delta);break;case"thinking_delta":J.setThinkingOpened(B.thinkingDelta(X.delta,J.hasOpenThinking()));break;case"stream_end":{let $=J.completeStream();B.streamEnd($.wroteAssistantContent,$.openedThinking);break}case"tool_start":{let $=X.toolCall;if(!("function"in $))break;if($.function.name===O)break;if(["TaskCreate","TaskUpdate","TaskList"].includes($.function.name))break;try{let A=JSON.parse($.function.arguments),M=GH($.function.name,A),z=BH($.function.name,A),I=uJ($.function.name,M,z,Z);if(I.shouldLockTarget)Z.targetLocked=!0;B.phase(I.phase,I.status,I.message,{toolName:$.function.name,target:z}),B.toolStart($.function.name,M,z,X.toolKind)}catch{B.phase(Z.targetLocked?"executing":"searching",Z.targetLocked?"hit":"ongoing",Z.targetLocked?`Working within target: ${$.function.name}`:`Still searching: ${$.function.name}`,{toolName:$.function.name}),B.toolStart($.function.name,$.function.name,void 0,X.toolKind)}break}case"tool_progress":{let $=X.toolCall;if(!("function"in $))break;if($.function.name===O)break;B.toolProgress($.function.name,X.update.message,X.update.progress,X.update.total,X.update.admission);break}case"tool_result":{let $=X.toolCall;if(!("function"in $))break;if($.function.name===O)break;let A;try{let z=JSON.parse($.function.arguments);A=BH($.function.name,z)}catch{A=void 0}let M=jH(PH($.function.name,X.result),WH);if(B.toolResult($.function.name,M.summary,A,void 0,{success:X.result.success,errorType:X.result.error?.type,errorMessage:X.result.error?.message,background:bJ(X.result.metadata)}),M.detail)B.toolDetail($.function.name,M.detail);break}case"token_usage":B.tokenUsage(X.usage);break;case"compaction":B.compacting(X);break;case"task_update":B.taskUpdate(X.tasks);break;case"structured_output":B.structuredOutput(X);break;case"mcp_catalog_changed":B.mcpCatalogChanged(X);break;case"mcp_content_changed":B.mcpContentChanged(X);break;case"mcp_resource_updated":B.mcpResourceUpdated(X);break;case"mcp_connection_changed":B.mcpConnectionChanged(X);break;case"mcp_log":B.mcpLog(X);break;case"mcp_instructions_changed":B.mcpInstructionsChanged(X);break;case"mcp_task_changed":B.mcpTaskChanged(X);break;case"project_rules_loaded":B.projectRulesLoaded(X);break;case"steering_applied":case"follow_up_started":case"goal_continuation_started":break;case"goal_updated":B.goal(X);break;case"subagent_spawned":case"subagent_completed":B.subagent(X);break;case"model_fallback":break;case"provider_admission":B.providerAdmission(X);break;case"provider_retry":B.providerRetry(X);break;case"provider_circuit":B.providerCircuit(X);break;case"provider_stall":B.providerStall(X);break;case"action_stationarity":B.actionStationarity(X);break;case"turn_start":if(X.turn===1)Z.targetLocked=!1;B.phase("turn",Z.targetLocked?"hit":"ongoing",`Turn ${X.turn} started`,{turn:X.turn});break;default:{let $=X}}await m()});if(u.metadata?.outputTruncated)B.error("[warning] 输出因达到 token 上限被截断,部分内容可能不完整。");if(!u.success)return B.error(`Error: ${u.error?.message??"Agent execution failed"}`),await S(1);return B.phase("completed","done","Headless run completed"),await S(0)}catch(Y){if(!y){if(J.hasOpenThinking()&&q==="text")w.stderr.write(`
6
+ `);B.error(`Error: ${mJ(Y)}`)}return await S(1)}finally{x?.(),j?.();try{await W?.dispose()}finally{F.close(),P.dispose()}}}async function AK(){if(!process.argv.slice(2).includes("--headless"))return!1;let{headless:Q,"output-format":q,"system-prompt":J,"append-system-prompt":Z,"max-turns":W,...x}=AH,j=SJ(TJ(process.argv)).scriptName("blade").strict(!1).options(x).middleware([fH,MH,zH]);return hJ(j),await j.parse(),!0}export{dJ as runHeadless,AK as handleHeadlessMode,gJ as HeadlessOptionsSchema};
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-D7ap0LLK.js","assets/index-Dn4vZglG.js","assets/vendor-react-DG5dkZ_t.js","assets/vendor-radix-DXRuAJHH.js","assets/vendor-icons-DovdPN7M.js","assets/session-events-Bgir_Gl_.js","assets/index-8G4ejlcH.css"])))=>i.map(i=>d[i]);
2
- import{r as f,j as e}from"./vendor-react-DG5dkZ_t.js";import{u as D,a as y,b as je,s as Be,c as Xe,d as X,D as Ie,e as _e,f as Ze,g as Pe,h as Ve,i as Le,j as M,k as z,B as be,_ as Oe,S as et,l as Ue,m as tt,n as st,C as at,o as rt}from"./index-Dn4vZglG.js";import{U as Se,Q as nt,G as He,Z as it,L as $,E as Ke,T as Z,C as ce,_ as ot,w as lt,$ as ct,B as dt,a0 as qe,z as ee,n as de,R as ie,t as ut,H as mt,a1 as ze,V as ht,a2 as xt,a3 as pt,a4 as ft,P as Ge,a5 as bt,X as We,a6 as vt,a7 as gt,f as ye,a8 as kt,a9 as jt,aa as yt,ab as wt,W as Nt,a as St}from"./vendor-icons-DovdPN7M.js";import{k as Ct,g as Et,l as Tt,e as Mt,t as At,j as Rt}from"./session-events-Bgir_Gl_.js";import{j as Ft,k as $t,l as Dt,m as Qe}from"./vendor-radix-DXRuAJHH.js";import{t as F}from"./team-QZ9byb3E.js";import{teamService as Ce}from"./teamService-CoJLtqAq.js";function Ee(t){return t.split("/").filter(Boolean).at(-1)||t}function Bt(){const t=D(),s=y(w=>w.sessions),a=y(w=>w.currentSessionRef),r=y(w=>w.taskDeliveryActions),o=y(w=>w.deliverTask),i=je(w=>w.openFilePreview),[u,b]=f.useState(!1),d=s.find(w=>Be({sessionId:w.sessionId,projectPath:w.projectPath},a));if(!(d!=null&&d.taskIsolation))return null;const c=d.taskDiffStat,k=d.taskIsolation==="worktree",l=Xe(d),p=r[X(l)],x=d.taskDelivery,j=(x==null?void 0:x.status)==="conflicted",S=!!(c&&(c.changedFiles>0||c.commits>0)),h=!["queued","running"].includes(d.taskStatus),N=(x==null?void 0:x.status)==="applied"||(x==null?void 0:x.status)==="discarded",v=k&&S&&h&&!N,n=c?c.additions+c.deletions:0,m=n>0&&c?c.additions/n*100:0,E=w=>{o(l,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(Se,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate text-[hsl(var(--deck-ink))]",children:Ee(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:[k?e.jsx(nt,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-accent))]"}):e.jsx(Se,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:k?"text-[hsl(var(--deck-accent))]":void 0,children:t(k?"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(He,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate",children:d.taskWorktreeBranch})]})]})]}),c&&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(it,{className:"h-3 w-3 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"tabular-nums",children:c.changedFiles})]}),n>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:`${m}%`}}),e.jsx("span",{className:"h-full bg-red-500/80",style:{width:`${100-m}%`}})]}),e.jsxs("span",{className:"tabular-nums text-[hsl(var(--deck-accent))]",children:["+",c.additions]}),e.jsxs("span",{className:"tabular-nums text-red-600 dark:text-red-400",children:["-",c.deletions]}),c.commits>0&&e.jsx("span",{className:"hidden tabular-nums text-[hsl(var(--deck-ink-faint))] sm:inline",children:t("artifact.commits",{count:c.commits})}),S&&(x==null?void 0:x.status)!=="discarded"&&e.jsx("button",{type:"button",onClick:()=>i({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")}),v&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!!p,onClick:()=>E("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:[p==="apply"?e.jsx($,{className:"h-3 w-3 animate-spin"}):e.jsx(Ke,{className:"h-3 w-3"}),t(p==="apply"?"artifact.applying":j?"artifact.retryApply":"artifact.apply")]}),e.jsx("button",{type:"button",disabled:!!p,onClick:()=>b(!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:p==="discard"?e.jsx($,{className:"h-3 w-3 animate-spin"}):e.jsx(Z,{className:"h-3 w-3"})})]}),(x==null?void 0:x.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(ce,{className:"h-3 w-3"}),t("artifact.applied")]}),(x==null?void 0:x.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(Z,{className:"h-3 w-3"}),t("artifact.discarded")]})]}),(x==null?void 0:x.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(ot,{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:x.message||t("artifact.conflict")}),e.jsx("span",{className:"block text-[hsl(var(--deck-ink-faint))]",children:t("artifact.conflictHint")})]})]})]}),e.jsx(Ie,{open:u,onOpenChange:b,children:e.jsxs(_e,{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(Ze,{children:[e.jsx(Pe,{children:t("artifact.discardDialog.title")}),e.jsx(Ve,{className:"text-[hsl(var(--deck-ink-muted))]",children:t("artifact.discardDialog.description",{project:Ee(d.taskSourceProjectPath||d.projectPath),count:(c==null?void 0:c.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(Le,{className:"gap-2 sm:space-x-0",children:[e.jsx("button",{type:"button",onClick:()=>b(!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:()=>{b(!1),E("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(Z,{className:"h-3.5 w-3.5"}),t("artifact.discardDialog.confirm")]})]})]})})]})}const It=new Set(["completed","stale","failed","aborted","interrupted"]),_t={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"},Pt={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 oe(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}function Vt(t){const s=oe(t),a=oe(s==null?void 0:s.codeLocation),r=s==null?void 0:s.priority,o=s==null?void 0:s.confidenceScore,i=a==null?void 0:a.lineStart,u=a==null?void 0:a.lineEnd;if(!(typeof(s==null?void 0:s.title)!="string"||typeof s.body!="string"||r!==0&&r!==1&&r!==2&&r!==3||typeof o!="number"||!Number.isFinite(o)||typeof(a==null?void 0:a.path)!="string"||!Number.isInteger(i)||!Number.isInteger(u)))return{title:s.title,body:s.body,priority:r,confidenceScore:o,codeLocation:{path:a.path,lineStart:i,lineEnd:u}}}function Lt(t){const s=oe(t),a=oe(s==null?void 0:s.target);if((s==null?void 0:s.phase)!=="completed"||typeof s.status!="string"||!It.has(s.status)||typeof(a==null?void 0:a.label)!="string"||a.kind!=="uncommitted"&&a.kind!=="base"&&a.kind!=="commit"||typeof s.overallExplanation!="string"||!Array.isArray(s.findings))return;const r=s.findings.map(Vt);if(!r.some(o=>o===void 0))return{status:s.status,target:{kind:a.kind,label:a.label,...typeof a.reference=="string"?{reference:a.reference}:{}},overallExplanation:s.overallExplanation,findings:r,...typeof s.error=="string"?{error:s.error}:{}}}function Ot(t){const{path:s,lineStart:a,lineEnd:r}=t.codeLocation;return a===r?`${s}:L${a}`:`${s}:L${a}-${r}`}function Ut({report:t}){const s=D(),a=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"),": ",a]})]}),e.jsxs("span",{className:M("rounded-full border px-2.5 py-1 font-mono text-[10.5px] font-medium",Pt[t.status]),children:[s("chat.review.status"),": ",s(_t[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((r,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:r.title}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.confidence",{value:r.confidenceScore.toFixed(2)})})]}),e.jsx("code",{className:"mt-1 block text-[10.5px] text-[hsl(var(--deck-accent))]",children:Ot(r)}),e.jsx("p",{className:"mt-1.5 whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:r.body})]},`${r.codeLocation.path}:${r.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 Ht({elicitation:t,messageId:s}){const a=D(),r=y(v=>v.currentSessionRef),o=y(v=>v.setElicitation),[i,u]=f.useState(()=>qt(t.details.fields??[])),[b,d]=f.useState(()=>zt(t.details.fields??[])),[c,k]=f.useState(!1),[l,p]=f.useState(),x=t.details.fields??[],j=f.useMemo(()=>x.every(v=>{var m;if(!v.required)return!0;if(ue(v))return!!((m=b[v.name])!=null&&m.trim()||v.defaultValue!==void 0);const n=i[v.name]??v.defaultValue;return Array.isArray(n)?n.length>0:n!==void 0}),[x,b,i]);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:a(t.status==="cancelled"?"interaction.elicitation.cancelled":"interaction.elicitation.responded")});const S=async(v,n)=>{if(!(!r||c)){k(!0),p(void 0);try{await z.respondToElicitation(r,t.toolCallId,{action:v,...n?{content:n}:{}}),o(s,{...t,status:"responded"})}catch(m){p(m instanceof Error?m.message:a("interaction.elicitation.failed"))}finally{k(!1)}}},h=async()=>{try{await S("accept",Gt(x,i,b))}catch(v){p(v instanceof Error?v.message:String(v))}},N=()=>{const v=t.details.url;if(!v){p("MCP URL is unavailable");return}if(!window.open(v,"_blank","noopener,noreferrer")){p("The browser blocked the external window");return}S("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(lt,{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:[a("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:a("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(W,{onClick:N,disabled:c,primary:!0,label:a("interaction.elicitation.open"),icon:e.jsx(ct,{className:"h-3.5 w-3.5"})}),e.jsx(W,{onClick:()=>void S("decline"),disabled:c,label:a("interaction.elicitation.decline")}),e.jsx(W,{onClick:()=>void S("cancel"),disabled:c,label:a("interaction.elicitation.cancel")})]})]}):e.jsxs("div",{className:"space-y-4",children:[x.map(v=>e.jsx(Kt,{field:v,value:i[v.name],rawValue:b[v.name]??"",onValueChange:n=>u(m=>({...m,[v.name]:n})),onRawChange:n=>d(m=>({...m,[v.name]:n}))},v.name)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(W,{onClick:()=>void h(),disabled:c||!j,primary:!0,label:a("interaction.elicitation.submit"),icon:c?e.jsx($,{className:"h-3.5 w-3.5 animate-spin"}):null}),e.jsx(W,{onClick:()=>void S("decline"),disabled:c,label:a("interaction.elicitation.decline")}),e.jsx(W,{onClick:()=>void S("cancel"),disabled:c,label:a("interaction.elicitation.cancel")})]})]}),l&&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:l})]})}function Kt({field:t,value:s,rawValue:a,onValueChange:r,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:Wt(t).map(i=>{const u=Array.isArray(s)?s.includes(i.value):s===i.typedValue;return e.jsx("button",{type:"button","aria-pressed":u,onClick:()=>{if(t.type==="multi-select"){const b=Array.isArray(s)?s:[];r(b.includes(i.value)?b.filter(d=>d!==i.value):[...b,i.value])}else r(i.typedValue)},className:M("rounded-md border px-3 py-2 font-mono text-[12px] transition-colors",u?"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:i.label},i.value)})}):e.jsx("input",{id:`mcp-elicitation-${t.name}`,type:Qt(t),value:a,onChange:i=>o(i.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 W({onClick:t,disabled:s,primary:a=!1,label:r,icon:o}){return e.jsxs("button",{type:"button",onClick:t,disabled:s,className:M("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",a?"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,r]})}function qt(t){return Object.fromEntries(t.filter(s=>!ue(s)&&s.defaultValue!==void 0).map(s=>[s.name,Array.isArray(s.defaultValue)?[...s.defaultValue]:s.defaultValue]))}function zt(t){return Object.fromEntries(t.filter(s=>ue(s)&&s.defaultValue!==void 0).map(s=>[s.name,String(s.defaultValue)]))}function Gt(t,s,a){var o;const r={};for(const i of t){if(ue(i)){const b=((o=a[i.name])==null?void 0:o.trim())??"";if(!b){if(i.defaultValue!==void 0)r[i.name]=i.defaultValue;else if(i.required)throw new Error(`${i.title} is required`);continue}if(i.type==="number"||i.type==="integer"){const d=Number(b);if(!Number.isFinite(d))throw new Error(`${i.title} must be a finite number`);if(i.type==="integer"&&!Number.isSafeInteger(d))throw new Error(`${i.title} must be a safe integer`);r[i.name]=d}else r[i.name]=b;continue}const u=s[i.name]??i.defaultValue;if(u===void 0){if(i.required)throw new Error(`${i.title} is required`);continue}if(Array.isArray(u)){if(i.minItems!==void 0&&u.length<i.minItems)throw new Error(`${i.title} requires at least ${i.minItems} choices`);if(i.maxItems!==void 0&&u.length>i.maxItems)throw new Error(`${i.title} allows at most ${i.maxItems} choices`)}r[i.name]=u}return r}function Wt(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 ue(t){return t.type==="string"||t.type==="number"||t.type==="integer"}function Qt(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 Jt(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 Yt({report:t}){const s=D(),[a,r]=f.useState(!1),o=JSON.stringify(t.output,null,2),i=async()=>{try{await navigator.clipboard.writeText(o),r(!0),window.setTimeout(()=>r(!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(dt,{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:i,"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:a?e.jsx(ce,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(qe,{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 Xt=f.lazy(()=>Oe(()=>import("./MarkdownRenderer-D7ap0LLK.js").then(t=>t.M),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.MarkdownRenderer})));function Te({text:t,label:s}){const[a,r]=f.useState(!1);if(!t.trim())return null;const o=async()=>{try{await navigator.clipboard.writeText(t),r(!0),window.setTimeout(()=>r(!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:a?e.jsx(ce,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(qe,{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(be,{size:20,pulse:!1})})}function es(){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 Me(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 ts(t){if(typeof t=="string")return{text:Me(t),images:[]};const s=t.filter(r=>r.type==="text").map(r=>r.text).join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-BA9VgOyM.js","assets/index-CfVQVVVI.js","assets/vendor-react-DG5dkZ_t.js","assets/vendor-radix-DXRuAJHH.js","assets/vendor-icons-DovdPN7M.js","assets/session-events-Bgir_Gl_.js","assets/index-8G4ejlcH.css"])))=>i.map(i=>d[i]);
2
+ import{r as f,j as e}from"./vendor-react-DG5dkZ_t.js";import{u as D,a as y,b as je,s as Be,c as Xe,d as X,D as Ie,e as _e,f as Ze,g as Pe,h as Ve,i as Le,j as M,k as z,B as be,_ as Oe,S as et,l as Ue,m as tt,n as st,C as at,o as rt}from"./index-CfVQVVVI.js";import{U as Se,Q as nt,G as He,Z as it,L as $,E as Ke,T as Z,C as ce,_ as ot,w as lt,$ as ct,B as dt,a0 as qe,z as ee,n as de,R as ie,t as ut,H as mt,a1 as ze,V as ht,a2 as xt,a3 as pt,a4 as ft,P as Ge,a5 as bt,X as We,a6 as vt,a7 as gt,f as ye,a8 as kt,a9 as jt,aa as yt,ab as wt,W as Nt,a as St}from"./vendor-icons-DovdPN7M.js";import{k as Ct,g as Et,l as Tt,e as Mt,t as At,j as Rt}from"./session-events-Bgir_Gl_.js";import{j as Ft,k as $t,l as Dt,m as Qe}from"./vendor-radix-DXRuAJHH.js";import{t as F}from"./team-QZ9byb3E.js";import{teamService as Ce}from"./teamService-BX1zdQBb.js";function Ee(t){return t.split("/").filter(Boolean).at(-1)||t}function Bt(){const t=D(),s=y(w=>w.sessions),a=y(w=>w.currentSessionRef),r=y(w=>w.taskDeliveryActions),o=y(w=>w.deliverTask),i=je(w=>w.openFilePreview),[u,b]=f.useState(!1),d=s.find(w=>Be({sessionId:w.sessionId,projectPath:w.projectPath},a));if(!(d!=null&&d.taskIsolation))return null;const c=d.taskDiffStat,k=d.taskIsolation==="worktree",l=Xe(d),p=r[X(l)],x=d.taskDelivery,j=(x==null?void 0:x.status)==="conflicted",S=!!(c&&(c.changedFiles>0||c.commits>0)),h=!["queued","running"].includes(d.taskStatus),N=(x==null?void 0:x.status)==="applied"||(x==null?void 0:x.status)==="discarded",v=k&&S&&h&&!N,n=c?c.additions+c.deletions:0,m=n>0&&c?c.additions/n*100:0,E=w=>{o(l,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(Se,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate text-[hsl(var(--deck-ink))]",children:Ee(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:[k?e.jsx(nt,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-accent))]"}):e.jsx(Se,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:k?"text-[hsl(var(--deck-accent))]":void 0,children:t(k?"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(He,{className:"h-3 w-3 shrink-0 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"truncate",children:d.taskWorktreeBranch})]})]})]}),c&&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(it,{className:"h-3 w-3 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{className:"tabular-nums",children:c.changedFiles})]}),n>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:`${m}%`}}),e.jsx("span",{className:"h-full bg-red-500/80",style:{width:`${100-m}%`}})]}),e.jsxs("span",{className:"tabular-nums text-[hsl(var(--deck-accent))]",children:["+",c.additions]}),e.jsxs("span",{className:"tabular-nums text-red-600 dark:text-red-400",children:["-",c.deletions]}),c.commits>0&&e.jsx("span",{className:"hidden tabular-nums text-[hsl(var(--deck-ink-faint))] sm:inline",children:t("artifact.commits",{count:c.commits})}),S&&(x==null?void 0:x.status)!=="discarded"&&e.jsx("button",{type:"button",onClick:()=>i({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")}),v&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!!p,onClick:()=>E("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:[p==="apply"?e.jsx($,{className:"h-3 w-3 animate-spin"}):e.jsx(Ke,{className:"h-3 w-3"}),t(p==="apply"?"artifact.applying":j?"artifact.retryApply":"artifact.apply")]}),e.jsx("button",{type:"button",disabled:!!p,onClick:()=>b(!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:p==="discard"?e.jsx($,{className:"h-3 w-3 animate-spin"}):e.jsx(Z,{className:"h-3 w-3"})})]}),(x==null?void 0:x.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(ce,{className:"h-3 w-3"}),t("artifact.applied")]}),(x==null?void 0:x.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(Z,{className:"h-3 w-3"}),t("artifact.discarded")]})]}),(x==null?void 0:x.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(ot,{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:x.message||t("artifact.conflict")}),e.jsx("span",{className:"block text-[hsl(var(--deck-ink-faint))]",children:t("artifact.conflictHint")})]})]})]}),e.jsx(Ie,{open:u,onOpenChange:b,children:e.jsxs(_e,{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(Ze,{children:[e.jsx(Pe,{children:t("artifact.discardDialog.title")}),e.jsx(Ve,{className:"text-[hsl(var(--deck-ink-muted))]",children:t("artifact.discardDialog.description",{project:Ee(d.taskSourceProjectPath||d.projectPath),count:(c==null?void 0:c.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(Le,{className:"gap-2 sm:space-x-0",children:[e.jsx("button",{type:"button",onClick:()=>b(!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:()=>{b(!1),E("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(Z,{className:"h-3.5 w-3.5"}),t("artifact.discardDialog.confirm")]})]})]})})]})}const It=new Set(["completed","stale","failed","aborted","interrupted"]),_t={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"},Pt={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 oe(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}function Vt(t){const s=oe(t),a=oe(s==null?void 0:s.codeLocation),r=s==null?void 0:s.priority,o=s==null?void 0:s.confidenceScore,i=a==null?void 0:a.lineStart,u=a==null?void 0:a.lineEnd;if(!(typeof(s==null?void 0:s.title)!="string"||typeof s.body!="string"||r!==0&&r!==1&&r!==2&&r!==3||typeof o!="number"||!Number.isFinite(o)||typeof(a==null?void 0:a.path)!="string"||!Number.isInteger(i)||!Number.isInteger(u)))return{title:s.title,body:s.body,priority:r,confidenceScore:o,codeLocation:{path:a.path,lineStart:i,lineEnd:u}}}function Lt(t){const s=oe(t),a=oe(s==null?void 0:s.target);if((s==null?void 0:s.phase)!=="completed"||typeof s.status!="string"||!It.has(s.status)||typeof(a==null?void 0:a.label)!="string"||a.kind!=="uncommitted"&&a.kind!=="base"&&a.kind!=="commit"||typeof s.overallExplanation!="string"||!Array.isArray(s.findings))return;const r=s.findings.map(Vt);if(!r.some(o=>o===void 0))return{status:s.status,target:{kind:a.kind,label:a.label,...typeof a.reference=="string"?{reference:a.reference}:{}},overallExplanation:s.overallExplanation,findings:r,...typeof s.error=="string"?{error:s.error}:{}}}function Ot(t){const{path:s,lineStart:a,lineEnd:r}=t.codeLocation;return a===r?`${s}:L${a}`:`${s}:L${a}-${r}`}function Ut({report:t}){const s=D(),a=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"),": ",a]})]}),e.jsxs("span",{className:M("rounded-full border px-2.5 py-1 font-mono text-[10.5px] font-medium",Pt[t.status]),children:[s("chat.review.status"),": ",s(_t[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((r,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:r.title}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:s("chat.review.confidence",{value:r.confidenceScore.toFixed(2)})})]}),e.jsx("code",{className:"mt-1 block text-[10.5px] text-[hsl(var(--deck-accent))]",children:Ot(r)}),e.jsx("p",{className:"mt-1.5 whitespace-pre-wrap text-[12px] leading-5 text-[hsl(var(--deck-ink-muted))]",children:r.body})]},`${r.codeLocation.path}:${r.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 Ht({elicitation:t,messageId:s}){const a=D(),r=y(v=>v.currentSessionRef),o=y(v=>v.setElicitation),[i,u]=f.useState(()=>qt(t.details.fields??[])),[b,d]=f.useState(()=>zt(t.details.fields??[])),[c,k]=f.useState(!1),[l,p]=f.useState(),x=t.details.fields??[],j=f.useMemo(()=>x.every(v=>{var m;if(!v.required)return!0;if(ue(v))return!!((m=b[v.name])!=null&&m.trim()||v.defaultValue!==void 0);const n=i[v.name]??v.defaultValue;return Array.isArray(n)?n.length>0:n!==void 0}),[x,b,i]);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:a(t.status==="cancelled"?"interaction.elicitation.cancelled":"interaction.elicitation.responded")});const S=async(v,n)=>{if(!(!r||c)){k(!0),p(void 0);try{await z.respondToElicitation(r,t.toolCallId,{action:v,...n?{content:n}:{}}),o(s,{...t,status:"responded"})}catch(m){p(m instanceof Error?m.message:a("interaction.elicitation.failed"))}finally{k(!1)}}},h=async()=>{try{await S("accept",Gt(x,i,b))}catch(v){p(v instanceof Error?v.message:String(v))}},N=()=>{const v=t.details.url;if(!v){p("MCP URL is unavailable");return}if(!window.open(v,"_blank","noopener,noreferrer")){p("The browser blocked the external window");return}S("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(lt,{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:[a("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:a("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(W,{onClick:N,disabled:c,primary:!0,label:a("interaction.elicitation.open"),icon:e.jsx(ct,{className:"h-3.5 w-3.5"})}),e.jsx(W,{onClick:()=>void S("decline"),disabled:c,label:a("interaction.elicitation.decline")}),e.jsx(W,{onClick:()=>void S("cancel"),disabled:c,label:a("interaction.elicitation.cancel")})]})]}):e.jsxs("div",{className:"space-y-4",children:[x.map(v=>e.jsx(Kt,{field:v,value:i[v.name],rawValue:b[v.name]??"",onValueChange:n=>u(m=>({...m,[v.name]:n})),onRawChange:n=>d(m=>({...m,[v.name]:n}))},v.name)),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(W,{onClick:()=>void h(),disabled:c||!j,primary:!0,label:a("interaction.elicitation.submit"),icon:c?e.jsx($,{className:"h-3.5 w-3.5 animate-spin"}):null}),e.jsx(W,{onClick:()=>void S("decline"),disabled:c,label:a("interaction.elicitation.decline")}),e.jsx(W,{onClick:()=>void S("cancel"),disabled:c,label:a("interaction.elicitation.cancel")})]})]}),l&&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:l})]})}function Kt({field:t,value:s,rawValue:a,onValueChange:r,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:Wt(t).map(i=>{const u=Array.isArray(s)?s.includes(i.value):s===i.typedValue;return e.jsx("button",{type:"button","aria-pressed":u,onClick:()=>{if(t.type==="multi-select"){const b=Array.isArray(s)?s:[];r(b.includes(i.value)?b.filter(d=>d!==i.value):[...b,i.value])}else r(i.typedValue)},className:M("rounded-md border px-3 py-2 font-mono text-[12px] transition-colors",u?"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:i.label},i.value)})}):e.jsx("input",{id:`mcp-elicitation-${t.name}`,type:Qt(t),value:a,onChange:i=>o(i.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 W({onClick:t,disabled:s,primary:a=!1,label:r,icon:o}){return e.jsxs("button",{type:"button",onClick:t,disabled:s,className:M("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",a?"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,r]})}function qt(t){return Object.fromEntries(t.filter(s=>!ue(s)&&s.defaultValue!==void 0).map(s=>[s.name,Array.isArray(s.defaultValue)?[...s.defaultValue]:s.defaultValue]))}function zt(t){return Object.fromEntries(t.filter(s=>ue(s)&&s.defaultValue!==void 0).map(s=>[s.name,String(s.defaultValue)]))}function Gt(t,s,a){var o;const r={};for(const i of t){if(ue(i)){const b=((o=a[i.name])==null?void 0:o.trim())??"";if(!b){if(i.defaultValue!==void 0)r[i.name]=i.defaultValue;else if(i.required)throw new Error(`${i.title} is required`);continue}if(i.type==="number"||i.type==="integer"){const d=Number(b);if(!Number.isFinite(d))throw new Error(`${i.title} must be a finite number`);if(i.type==="integer"&&!Number.isSafeInteger(d))throw new Error(`${i.title} must be a safe integer`);r[i.name]=d}else r[i.name]=b;continue}const u=s[i.name]??i.defaultValue;if(u===void 0){if(i.required)throw new Error(`${i.title} is required`);continue}if(Array.isArray(u)){if(i.minItems!==void 0&&u.length<i.minItems)throw new Error(`${i.title} requires at least ${i.minItems} choices`);if(i.maxItems!==void 0&&u.length>i.maxItems)throw new Error(`${i.title} allows at most ${i.maxItems} choices`)}r[i.name]=u}return r}function Wt(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 ue(t){return t.type==="string"||t.type==="number"||t.type==="integer"}function Qt(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 Jt(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 Yt({report:t}){const s=D(),[a,r]=f.useState(!1),o=JSON.stringify(t.output,null,2),i=async()=>{try{await navigator.clipboard.writeText(o),r(!0),window.setTimeout(()=>r(!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(dt,{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:i,"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:a?e.jsx(ce,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(qe,{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 Xt=f.lazy(()=>Oe(()=>import("./MarkdownRenderer-BA9VgOyM.js").then(t=>t.M),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.MarkdownRenderer})));function Te({text:t,label:s}){const[a,r]=f.useState(!1);if(!t.trim())return null;const o=async()=>{try{await navigator.clipboard.writeText(t),r(!0),window.setTimeout(()=>r(!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:a?e.jsx(ce,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}):e.jsx(qe,{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(be,{size:20,pulse:!1})})}function es(){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 Me(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 ts(t){if(typeof t=="string")return{text:Me(t),images:[]};const s=t.filter(r=>r.type==="text").map(r=>r.text).join(`
3
3
  `),a=t.filter(r=>r.type==="image_url").map(r=>r.image_url.url);return{text:Me(s),images:a}}function we(t){return typeof t=="string"?t:t.filter(s=>s.type==="text").map(s=>s.text).join(`
4
4
  `)}function ss(t){const s=t.agentContent;return s?Ct(s):we(t.content)}function Ae({content:t,syntaxHighlight:s=!0}){return e.jsx(f.Suspense,{fallback:e.jsx("pre",{className:"text-[14px] text-[hsl(var(--deck-ink))] font-mono whitespace-pre-wrap",children:t}),children:e.jsx(Xt,{content:t,syntaxHighlight:s})})}function Ne({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]"},a={running:"Running",success:"Success",error:"Error",pending:"Pending",info:"Info"};return e.jsx("span",{className:M("text-[11px] px-2 py-0.5 rounded-full font-mono",s[t]),children:a[t]})}function as(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 Re=500;function Je(t,s){if(t.length<=s)return t;let a=Math.max(0,s);return a>0&&/[\uD800-\uDBFF]/.test(t.charAt(a-1))&&(a-=1),t.slice(0,a)}function Fe(t,s){if(t.length<=s)return t;let a=Math.max(0,t.length-s);return/[\uDC00-\uDFFF]/.test(t.charAt(a))&&(a+=1),t.slice(a)}function he(t,s){if(t.length<=s)return t;if(s<=0)return"";const a=`
5
5
  ... (display clipped) ...
@@ -14,5 +14,5 @@ stdout:
14
14
  ${he(l,p-x)}`}else c=he(o,u);return{body:Je(c,u),...r?{notice:r}:{},truncated:!!r||t.length>Re}}function ns({tool:t}){const[s,a]=f.useState(!1),r=as(t.arguments),o=t.output?rs(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:()=>a(i=>!i),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(ee,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))] shrink-0"}):e.jsx(de,{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(Ne,{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:[r&&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:r})]}),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
15
  `,e.jsx("span",{"data-tool-truncation-notice":!0,children:o.notice})]})]})]})]})]})}function Ye({toolCalls:t}){return t.length===0?null:e.jsx("div",{className:"space-y-2",children:t.map(s=>e.jsx(ns,{tool:s},s.toolCallId))})}function is({toolCalls:t,toolCallIds:s}){const a=D(),[r,o]=f.useState(!1),i=f.useMemo(()=>new Map(t.map(l=>[l.toolCallId,l])),[t]),u=s.flatMap(l=>{const p=i.get(l);return p?[p]:[]});if(u.length===0)return null;const b=u.filter(l=>l.status==="running").length,d=u.filter(l=>l.status==="error").length,c=[...u].reverse().find(l=>l.status==="running"&&!!l.progressMessage),k=b>0?a(u.length===1?"chat.timeline.tools.runningOne":"chat.timeline.tools.running",{count:u.length}):d>0?a(u.length===1?"chat.timeline.tools.completedOneWithError":"chat.timeline.tools.completedWithErrors",{count:u.length,errors:d}):a(u.length===1?"chat.timeline.tools.completedOne":"chat.timeline.tools.completed",{count:u.length});return e.jsxs("div",{"data-agent-tool-group":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":r,onClick:()=>o(l=>!l),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:[r?e.jsx(ee,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(de,{className:"h-3.5 w-3.5 shrink-0"}),b>0&&e.jsx($,{className:"h-3 w-3 shrink-0 animate-spin text-[hsl(var(--deck-accent))]"}),e.jsx("span",{children:k}),(c==null?void 0:c.progressMessage)&&e.jsxs("span",{className:"min-w-0 truncate text-[10.5px] text-[hsl(var(--deck-ink-muted))]",children:[c.progressMessage,c.progress!==void 0&&c.progressTotal!==void 0&&` · ${Math.max(0,Math.min(100,Math.round(c.progress/c.progressTotal*100)))}%`]})]}),(c==null?void 0:c.progress)!==void 0&&c.progressTotal!==void 0&&e.jsx("div",{role:"progressbar","aria-label":`${c.toolName} progress`,"aria-valuemin":0,"aria-valuemax":c.progressTotal,"aria-valuenow":Math.min(c.progress,c.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,c.progress/c.progressTotal*100))}%`}})}),r&&e.jsx("div",{"data-agent-tool-group-details":!0,className:"mt-2 space-y-2 pl-1",children:e.jsx(Ye,{toolCalls:u})})]})}function os({content:t}){const s=D(),[a,r]=f.useState(!1);return t?e.jsxs("div",{"data-agent-thinking":!0,className:"py-0.5",children:[e.jsxs("button",{type:"button","aria-expanded":a,onClick:()=>r(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:[a?e.jsx(ee,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}):e.jsx(de,{className:"h-4 w-4 text-[hsl(var(--deck-ink-faint))]"}),e.jsx("span",{children:s("chat.timeline.thinking")})]}),a&&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 ls({tasks:t}){if(t.length===0)return null;const s=t.filter(r=>r.status==="completed").length,a=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:a?"✓ All tasks done":`Tasks: ${s}/${t.length}`})})})}function cs({toolCalls:t}){const s=je(r=>r.openFilePreview),a=f.useMemo(()=>{const r=new Map,o=["Write","SearchReplace","Edit","ApplyPatch"];for(const i of t){if(i.status!=="success")continue;const u=i.metadata;if(i.toolName==="ApplyPatch"&&Array.isArray(u==null?void 0:u.changes)){for(const d of u.changes)d&&typeof d=="object"&&"path"in d&&typeof d.path=="string"&&r.set(d.path,{path:d.path,toolName:i.toolName});continue}const b=u==null?void 0:u.file_path;b&&o.includes(i.toolName)&&r.set(b,{path:b,toolName:i.toolName})}return Array.from(r.values())},[t]);return a.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 (",a.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.map(({path:r})=>{const o=r.split("/").pop()||r;return e.jsxs("button",{onClick:()=>s({tab:"diff",targetPath:r}),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:r,children:[e.jsx(ut,{className:"w-3 h-3"}),o]},r)})})]})}function ds({subagent:t}){var Q,G,te,se;const s=D(),[a,r]=f.useState(null),[o,i]=f.useState(!1),[u,b]=f.useState(null),[d,c]=f.useState(!1),[k,l]=f.useState(""),[p,x]=f.useState(!1),[j,S]=f.useState(null),[h,N]=f.useState(null),[v,n]=f.useState(null),m=y(A=>A.currentSessionRef),E=y(A=>A.isStreaming),w=y(A=>A.isTemporarySession);if(!t)return null;const C=t.status==="running",R=a!==null?a:C,K=t.toolCalls||u||[],O=t.output||t.thinking||K.length>0||t.sessionId,B=h&&h.status!=="running"?h:v,V=(B==null?void 0:B.id)??t.sessionId,L=((Q=B==null?void 0:B.restartRecovery)==null?void 0:Q.outcome)==="failed",T=!C&&!E&&!w&&!L&&(h==null?void 0:h.status)!=="running"&&!!(V&&m);f.useEffect(()=>{if(!R||C||!t.sessionId||!(m!=null&&m.projectPath)||u!==null||t.toolCalls&&t.toolCalls.length>0)return;let A=!0;return i(!0),z.getMessages({sessionId:t.sessionId,projectPath:m.projectPath}).then(U=>{var _,I;if(!A)return;const H=Mt(U),g=new Map;for(const J of H)if((I=(_=J.agentContent)==null?void 0:_.toolCalls)!=null&&I.length)for(const me of J.agentContent.toolCalls)g.has(me.toolCallId)||g.set(me.toolCallId,me);b(Array.from(g.values()))}).finally(()=>{A&&i(!1)}),()=>{A=!1}},[R,C,t.sessionId,t.toolCalls,u,m==null?void 0:m.projectPath]),f.useEffect(()=>{if(!t.sessionId||!m)return;let A=!0;const U=t.rootAgentId??t.sessionId,H=t.resumeDepth??0;return z.listSubagents(m).then(g=>{if(!A)return;n(g.find(I=>I.id===t.sessionId)??null);const _=g.filter(I=>I.id!==t.sessionId&&I.rootAgentId===U&&I.resumeDepth>H).sort((I,J)=>J.resumeDepth-I.resumeDepth||J.lastActiveAt-I.lastActiveAt)[0];_&&N(_)}).catch(()=>{}),()=>{A=!1}},[m==null?void 0:m.sessionId,m==null?void 0:m.projectPath,t.sessionId,t.rootAgentId,t.resumeDepth]),f.useEffect(()=>{if(!h||h.status!=="running"||!m)return;let A=!0;const U=async()=>{try{const _=(await z.listSubagents(m)).find(I=>I.id===h.id);A&&_&&N(_)}catch{}},H=window.setInterval(()=>{U()},1e3);return()=>{A=!1,window.clearInterval(H)}},[m,h==null?void 0:h.id,h==null?void 0:h.status]);const P=async()=>{if(!(!m||!V||!k.trim()||p)){x(!0),S(null);try{const A=await z.resumeSubagent(m,V,k.trim());N(A.session),l(""),c(!1),r(!0)}catch(A){S(A instanceof Error?A.message:s("chat.subagent.resumeFailed"))}finally{x(!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:()=>r(!R),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:[C&&e.jsx($,{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(Ne,{status:t.status==="completed"?"success":t.status==="failed"?"error":"running"}),t.type==="verification"&&t.verificationVerdict&&e.jsx("span",{"data-verification-verdict":t.verificationVerdict,className:M("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})})]}),O&&e.jsx(ee,{className:M("h-3.5 w-3.5 text-[hsl(var(--deck-ink-muted))] transition-transform",R&&"rotate-180")})]}),!R&&!C&&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}),R&&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($,{className:"w-3 h-3 animate-spin"}),s("chat.subagent.loadingLogs")]}),!o&&K.length>0&&e.jsx(Ye,{toolCalls:K}),h&&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:h.id,status:h.status,depth:h.resumeDepth??1})}),(((G=h.result)==null?void 0:G.message)||((te=h.result)==null?void 0:te.error))&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap text-[hsl(var(--deck-ink))]",children:h.result.message||h.result.error})]}),L&&((se=B==null?void 0:B.result)==null?void 0:se.error)&&e.jsx("div",{role:"alert",className:"text-[11px] text-red-600",children:B.result.error}),T&&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:k,onChange:A=>l(A.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:()=>{c(!1),S(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 P(),disabled:!k.trim()||p,className:"flex items-center gap-1 rounded bg-[#7C3AED] px-2 py-1 text-[11px] font-medium text-white disabled:opacity-50",children:[p&&e.jsx($,{className:"w-3 h-3 animate-spin"}),s("chat.subagent.resumeAgent")]})]})]}):e.jsxs("button",{type:"button","aria-label":s("chat.subagent.resumeAria"),onClick:()=>c(!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(ie,{className:"w-3 h-3"}),s("chat.subagent.resume")]}),j&&e.jsx("div",{role:"alert",className:"text-[11px] text-red-600",children:j})]})]})]})}function us({confirmation:t,messageId:s}){const a=D(),[r,o]=f.useState(!1),[i,u]=f.useState(null),b=y(k=>k.currentSessionRef),d=y(k=>k.setConfirmation);if(!t)return null;const c=async(k,l)=>{if(!(!b||r)){o(!0),u(null);try{await z.respondPermission(b,t.toolCallId,{approved:k,scope:l}),d(s,{...t,status:k?"approved":"denied"})}catch(p){u(p instanceof Error?p.message:a("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:a("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}),i&&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:i}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>void c(!0,"once"),disabled:r,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:r?e.jsx($,{className:"h-3.5 w-3.5 animate-spin"}):a("interaction.permission.once")}),t.allowRemember!==!1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>void c(!0,"session"),disabled:r,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:a("interaction.permission.session")}),e.jsx("button",{type:"button",onClick:()=>void c(!0,"project"),disabled:r,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:a("interaction.permission.project")})]}),e.jsx("button",{type:"button",onClick:()=>void c(!1),disabled:r,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:a("interaction.permission.deny")})]})]})}function ms({question:t,messageId:s}){const a=D(),[r,o]=f.useState({}),[i,u]=f.useState({}),[b,d]=f.useState(!1),[c,k]=f.useState(null),l=y(h=>h.currentSessionRef),p=y(h=>h.setQuestion),x=f.useMemo(()=>t?t.questions.reduce((h,N)=>{var E;const v=(E=i[N.header])==null?void 0:E.trim(),n=r[N.header];if(N.multiSelect){const w=Array.isArray(n)?[...n]:[];return v&&w.push(v),w.length>0&&(h[N.header]=w),h}const m=v||(typeof n=="string"?n:"");return m&&(h[N.header]=m),h},{}):{},[r,i,t]),j=(t==null?void 0:t.questions.every(h=>h.header in x))??!1;if(!t)return null;const S=async()=>{if(!(!l||b||!j)){d(!0),k(null);try{await z.respondToQuestion(l,t.toolCallId,x),p(s,{...t,status:"answered",answers:x})}catch(h){k(h instanceof Error?h.message:a("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:a("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((h,N)=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[13px] text-[hsl(var(--deck-ink))] font-mono",children:h.question}),e.jsxs("div",{className:"space-y-1",children:[h.options.map((v,n)=>e.jsxs("button",{type:"button",onClick:()=>{if(h.multiSelect){const m=r[h.header]||[],E=m.includes(v.label)?m.filter(w=>w!==v.label):[...m,v.label];o({...r,[h.header]:E})}else o({...r,[h.header]:v.label}),u({...i,[h.header]:""})},className:M("w-full text-left px-3 py-2 rounded-md border text-[12px] font-mono transition-colors","border-[hsl(var(--deck-border))]",(h.multiSelect?(r[h.header]||[]).includes(v.label):r[h.header]===v.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:v.label}),e.jsx("div",{className:"text-[11px] text-[hsl(var(--deck-ink-faint))] mt-1",children:v.description})]},n)),e.jsx("input",{"aria-label":`${h.header} other response`,value:i[h.header]??"",onChange:v=>u({...i,[h.header]:v.target.value}),placeholder:a("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]"})]})]},N)),c&&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:c}),e.jsxs("button",{type:"button",onClick:()=>void S(),disabled:b||!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:[b&&e.jsx($,{className:"h-3.5 w-3.5 animate-spin"}),a("interaction.question.submit")]})]})}function hs({message:t}){const s=t.agentContent,a=y(j=>j.isStreaming&&j.currentAssistantMessageId===t.id);if(!s){const j=we(t.content);return j?e.jsx(Ae,{content:j}):null}const{toolCalls:r,tasks:o,confirmation:i,question:u,elicitation:b}=s,d=Et(s),c=Tt(s);if(!(c.length>0||o.length>0||d.length>0||i||u||b)&&a)return e.jsxs("div",{className:"flex items-center gap-2 text-[hsl(var(--deck-ink-muted))]",children:[e.jsx($,{className:"w-4 h-4 animate-spin"}),e.jsx("span",{className:"text-[12px] font-mono",children:"Thinking..."})]});const p=r.length>0&&r.every(j=>j.status==="success"||j.status==="error")&&!a,x=!a;return e.jsxs("div",{className:"space-y-3",children:[c.map(j=>j.type==="thinking"?e.jsx("div",{"data-agent-timeline-block":"thinking",children:e.jsx(os,{content:j.content})},j.id):j.type==="text"?e.jsx("div",{"data-agent-timeline-block":"text",children:e.jsx(Ae,{content:j.content,syntaxHighlight:x})},j.id):e.jsx("div",{"data-agent-timeline-block":"tool_group",children:e.jsx(is,{toolCalls:r,toolCallIds:j.toolCallIds})},j.id)),o.length>0&&e.jsx(ls,{tasks:o}),d.map(j=>e.jsx(ds,{subagent:j},j.id)),i&&e.jsx(us,{confirmation:i,messageId:t.id}),u&&e.jsx(ms,{question:u,messageId:t.id}),b&&e.jsx(Ht,{elicitation:b,messageId:t.id}),p&&e.jsx(cs,{toolCalls:r})]})}function xs({message:t,showAvatar:s=!0}){var b,d,c,k;const a=t.role==="user";if(t.role==="system"){const l=we(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:l})})}if(a){const l=(b=t.metadata)!=null&&b.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(l){const j=typeof l.command=="string"?l.command:"",S=l.status==="running"?"running":l.status==="completed"?"success":"error",h=typeof l.output=="string"?l.output:[typeof l.stdout=="string"?l.stdout:"",typeof l.stderr=="string"&&l.stderr?`stderr:
16
16
  ${l.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(Ne,{status:S})]}),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:h||"(no output)"}),typeof l.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 ",l.exitCode,typeof l.durationMs=="number"?` · ${(l.durationMs/1e3).toFixed(3)}s`:"",l.truncated===!0?" · truncated":""]})]})})}const{text:p,images:x}=ts(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(Te,{text:p,label:"Copy message"})}),e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] rounded-lg px-4 py-3 max-w-[85%]",children:[p&&e.jsx("p",{className:"text-[14px] text-[hsl(var(--deck-ink))] font-mono leading-relaxed whitespace-pre-wrap",children:p}),x.length>0&&e.jsx("div",{className:M("grid gap-2",x.length===1?"grid-cols-1 mt-0":"grid-cols-2 mt-3"),children:x.map((j,S)=>e.jsx("img",{src:j,alt:`attachment-${S+1}`,className:"object-cover w-full max-h-64 rounded-md"},`${j}-${S}`))})]}),e.jsx(es,{})]})}const o=ss(t),i=Lt((c=t.metadata)==null?void 0:c.codeReview),u=Jt((k=t.metadata)==null?void 0:k.structuredOutput);return e.jsxs("div",{"data-chat-message-id":t.id,"data-chat-role":"assistant",className:M("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:[i?e.jsx(Ut,{report:i}):u?e.jsx(Yt,{report:u}):e.jsx(hs,{message:t}),!u&&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(Te,{text:o,label:"Copy response"})})]})]})}const ps=f.memo(xs);function fs(t,s,a){return Math.max(0,t+(a-s))}function bs(t,s,a){return Math.min(s,Math.max(0,t)+Math.max(0,a))}function $e(t,s){return t?t.querySelector(`[data-chat-message-id="${CSS.escape(s)}"]`):null}function vs({turns:t,viewportRef:s,containerRef:a,onRevealTurn:r}){const o=D(),[i,u]=f.useState(null),[b,d]=f.useState(!1),c=f.useRef(null),k=f.useCallback(()=>{var h;const p=s.current,x=a.current;if(!p||!x||t.length===0)return;const j=p.getBoundingClientRect().top;let S=((h=t[0])==null?void 0:h.id)??null;for(const N of t){const v=$e(x,N.id);if(v)if(v.getBoundingClientRect().top-j<=24)S=N.id;else break}u(S)},[t,s,a]);f.useEffect(()=>{const p=s.current;if(!p)return;const x=()=>{c.current===null&&(c.current=window.requestAnimationFrame(()=>{c.current=null,k()}))};return k(),p.addEventListener("scroll",x,{passive:!0}),()=>{p.removeEventListener("scroll",x),c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null)}},[k,s]);const l=f.useCallback(p=>{const x=()=>{const S=$e(a.current,p.id);S&&(S.scrollIntoView({behavior:"smooth",block:"start"}),u(p.id))};r(p.index)?x():window.requestAnimationFrame(()=>window.requestAnimationFrame(x))},[a,r]);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:p=>{p.currentTarget.contains(p.relatedTarget)||d(!1)},children:e.jsxs("div",{className:"relative flex items-center justify-end",children:[e.jsx("ul",{className:M("flex flex-col items-center gap-2 py-2 transition-opacity",b?"opacity-0":"opacity-100"),"aria-hidden":b,children:t.map(p=>e.jsx("li",{children:e.jsx("span",{className:M("block rounded-full transition-all",p.id===i?"h-2 w-2 bg-[hsl(var(--deck-accent))]":"h-1.5 w-1.5 bg-[hsl(var(--deck-ink-faint))]/40")})},p.id))}),e.jsx("div",{className:M("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",b?"pointer-events-auto translate-x-0 opacity-100":"pointer-events-none translate-x-2 opacity-0"),children:t.map((p,x)=>e.jsxs("button",{type:"button",onClick:()=>l(p),className:M("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors",p.id===i?"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:M("mt-1 h-1.5 w-1.5 shrink-0 rounded-full",p.id===i?"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:x+1})}),e.jsx("span",{className:"line-clamp-2 text-[12px] leading-4",children:p.preview})]})]},p.id))})]})})}const De=80;function gs(t){return typeof t=="string"?t:Array.isArray(t)?t.filter(s=>s.type==="text").map(s=>s.text).join(" "):""}function ks(t){const s=gs(t).replace(/\s+/g," ").trim();return s?s.length>De?`${s.slice(0,De-1)}…`:s:""}function js(t){const s=[];for(let a=0;a<t.length;a+=1){const r=t[a];if(r.role!=="user"||!r.id)continue;const o=ks(r.content);o&&s.push({id:r.id,index:a,preview:o})}return s}const xe=120,pe=80,ys=96;function Y(t){return(t==null?void 0:t.querySelector("[data-radix-scroll-area-viewport]"))??null}function ws({messages:t,isLoading:s}){const a=D(),r=f.useRef(null),o=f.useRef(null),i=f.useRef(!0),u=f.useRef(t.length),b=f.useRef(null),[d,c]=f.useState(xe),[k,l]=f.useState(!1);f.useEffect(()=>{const n=Y(r.current);if(!n||!i.current)return;const m=window.requestAnimationFrame(()=>{n.scrollTop=n.scrollHeight});return()=>window.cancelAnimationFrame(m)},[t]),f.useEffect(()=>{const n=Y(r.current);if(!n)return;o.current=n;const m=()=>{const w=n.scrollHeight-n.scrollTop-n.clientHeight<=ys;i.current=w,l(!w)};return m(),n.addEventListener("scroll",m,{passive:!0}),()=>n.removeEventListener("scroll",m)},[]),f.useEffect(()=>{const n=u.current;u.current=t.length,c(m=>m>=n&&t.length>n?t.length:Math.min(Math.max(m,xe),t.length||xe))},[t.length]);const p=Math.max(t.length-d,0),x=p,j=f.useMemo(()=>t.slice(x),[t,x]),S=f.useMemo(()=>js(t),[t]);if(f.useLayoutEffect(()=>{var E;const n=b.current;if(!n)return;const m=Y(r.current);if(b.current=null,!!m){if((E=n.element)!=null&&E.isConnected){const w=n.element.getBoundingClientRect().top-n.viewportTop;m.scrollTop+=w;return}m.scrollTop=fs(n.scrollTop,n.scrollHeight,m.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(be,{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(mt,{className:"w-3 h-3"}),a("chat.list.loading.eyebrow")]}),e.jsx("h2",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:a("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:a("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((n,m)=>e.jsxs("div",{className:M("flex gap-3",m%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:`${n}%`,animationDelay:`${m*120}ms`}})]},n))})]})});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(be,{size:44}),e.jsxs("div",{children:[e.jsx("div",{className:"deck-eyebrow text-[hsl(var(--deck-accent))]",children:a("chat.list.empty.eyebrow")}),e.jsx("div",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:a("chat.list.empty.title")}),e.jsx("div",{className:"mt-1 max-w-xs text-[12px] text-[hsl(var(--deck-ink-muted))]",children:a("chat.list.empty.hint")})]})]})});const h=()=>{const n=Y(r.current);n&&(i.current=!0,l(!1),n.scrollTo({top:n.scrollHeight,behavior:"smooth"}))},N=()=>{var m;const n=Y(r.current);if(n){const E=((m=r.current)==null?void 0:m.querySelector("[data-chat-message-id]"))??null;b.current={element:E,viewportTop:(E==null?void 0:E.getBoundingClientRect().top)??0,scrollHeight:n.scrollHeight,scrollTop:n.scrollTop}}c(E=>bs(E,t.length,pe))},v=n=>n>=x?!0:(c(t.length),!1);return e.jsxs("div",{ref:r,className:"relative flex-1 min-h-0",children:[e.jsx(et,{className:"h-full",children:e.jsxs("div",{className:"flex flex-col px-4 pb-4 w-full md:px-6",children:[p>0&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx("button",{type:"button",onClick:N,"aria-label":a("chat.list.showEarlierWithRemaining",{count:Math.min(p,pe),remaining:p}),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:a("chat.list.showEarlier",{count:Math.min(p,pe)})})}),j.map((n,m)=>{const E=x+m,w=E>0?t[E-1]:null,C=!w||w.role!==n.role||w.role==="user";return e.jsx(ps,{message:n,showAvatar:C},n.id||`msg-${E}`)})]})}),e.jsx(vs,{turns:S,viewportRef:o,containerRef:r,onRevealTurn:v}),k&&e.jsxs("button",{type:"button",onClick:h,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(ze,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}),a("chat.list.jumpLatest")]})]})}const Ns=f.memo(ws),ve=Ft,ge=$t,ke=Dt,le=f.forwardRef(({className:t,sideOffset:s=4,...a},r)=>e.jsx(Qe,{ref:r,sideOffset:s,className:M("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),...a}));le.displayName=Qe.displayName;const Ss={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 ae(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function Cs(t){if(t<60)return`${t}s`;const s=Math.floor(t/60),a=t%60;return a===0?`${s}m`:`${s}m ${a}s`}function Es(){var O,B,V,L;const t=D(),{locale:s}=Ue(),a=y(T=>T.goal),r=y(T=>T.pauseGoal),o=y(T=>T.resumeGoal),i=y(T=>T.editGoal),u=y(T=>T.clearGoal),[b,d]=f.useState(!1),[c,k]=f.useState(!1),[l,p]=f.useState(""),[x,j]=f.useState(null),[S,h]=f.useState(!1);if(f.useEffect(()=>{d(!1),k(!1),p((a==null?void 0:a.objective)??""),h(!1)},[a==null?void 0:a.goalId]),!a)return null;const N=Ss[a.status],v=["active","verifying","paused","blocked"].includes(a.status),n=a.status==="active"||a.status==="verifying",m=a.status==="paused"||a.status==="blocked",E=x!==null,w=async(T,P)=>{j(T);try{await P()}finally{j(null)}},C=()=>{p(a.objective),k(!0),d(!0)},R=async T=>{T.preventDefault();const P=l.trim();if(!P||P===a.objective){k(!1);return}await w("edit",()=>i(P)),k(!1)},K=async()=>{await w("delete",u),h(!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":a.status,"data-blade-goal-recovery":(O=a.prematureStop)==null?void 0:O.consecutiveCount,"data-blade-goal-recovery-pattern":(B=a.prematureStop)==null?void 0:B.pattern,"data-blade-goal-verification-stall":(V=a.verificationStall)==null?void 0:V.consecutiveCount,children:[e.jsxs("div",{className:M("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",b&&"rounded-b-none border-b-0"),children:[a.status==="complete"?e.jsx(ht,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):e.jsx(xt,{className:M("h-3.5 w-3.5 shrink-0",N.accent)}),e.jsx("span",{className:M("h-1.5 w-1.5 shrink-0 rounded-full",N.dot)}),e.jsx("span",{className:M("shrink-0 text-[10px] font-medium leading-none",N.accent),children:a.status==="verifying"?s==="zh"?"验证中":"Verifying":t(N.labelKey)}),e.jsx("span",{className:"h-3 w-px shrink-0 bg-[hsl(var(--deck-hairline))]"}),e.jsx("button",{type:"button","aria-label":t(b?"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(T=>!T),"aria-expanded":b,title:a.objective,children:a.objective}),a.tokensUsed>0&&e.jsxs("span",{className:"hidden shrink-0 text-[10px] tabular-nums text-[hsl(var(--deck-ink-muted))] sm:inline",children:[ae(a.tokensUsed),a.tokenBudget!==void 0&&`/${ae(a.tokenBudget)}`]}),e.jsxs("div",{className:"flex shrink-0 items-center",children:[n&&e.jsx(re,{label:t("goal.action.pause"),disabled:E,onClick:()=>void w("pause",r),children:x==="pause"?e.jsx($,{className:"animate-spin"}):e.jsx(pt,{})}),m&&e.jsx(re,{label:t("goal.action.resume"),disabled:E,onClick:()=>void w("resume",o),children:x==="resume"?e.jsx($,{className:"animate-spin"}):e.jsx(ft,{})}),e.jsx(re,{label:t(v?"goal.action.edit":"goal.action.expand"),disabled:!v&&!b,onClick:v?C:()=>d(T=>!T),children:v?e.jsx(Ge,{}):e.jsx(bt,{})}),e.jsx(re,{label:t("goal.action.delete"),disabled:E,destructive:!0,onClick:()=>h(!0),children:e.jsx(Z,{})})]})]}),b&&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:c?e.jsxs("form",{onSubmit:R,children:[e.jsx("textarea",{id:"goal-objective",value:l,onChange:T=>p(T.target.value),onKeyDown:T=>{T.key==="Escape"&&k(!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:()=>k(!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(We,{className:"h-3 w-3"}),t("goal.action.cancel")]}),e.jsxs("button",{type:"submit",disabled:!l.trim()||x==="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:[x==="edit"?e.jsx($,{className:"h-3 w-3 animate-spin"}):e.jsx(ce,{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:a.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(vt,{className:"h-3 w-3"}),ae(a.tokensUsed),a.tokenBudget!==void 0&&` / ${ae(a.tokenBudget)}`," ",t("goal.metrics.tokens")]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(gt,{className:"h-3 w-3"}),Cs(a.timeUsedSeconds)]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ie,{className:"h-3 w-3"}),a.continuationCount===1?t("goal.metrics.continuationOne",{n:a.continuationCount}):t("goal.metrics.continuationMany",{n:a.continuationCount})]})]}),a.prematureStop&&e.jsxs("div",{className:"mt-2 inline-flex items-center gap-1.5 font-mono text-[10px] text-amber-700 dark:text-amber-300",children:[e.jsx(ie,{className:"h-3 w-3"}),s==="zh"?"恢复提示":"Recovery nudge"," ",a.prematureStop.consecutiveCount," ·"," ",a.prematureStop.pattern.replaceAll("_"," ")]}),a.completionVerification&&e.jsxs("div",{"data-goal-verification":a.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:["#",a.completionVerification.attempt," ·"," ",a.completionVerification.status.toUpperCase()," ·"," ",((L=a.completionVerification.verifierSessionId)==null?void 0:L.slice(0,12))??"-",a.verificationStall?s==="zh"?` · 重复 ${a.verificationStall.consecutiveCount}/3`:` · repeat ${a.verificationStall.consecutiveCount}/3`:""]}),a.completionVerification.summary&&e.jsx("p",{className:"mt-1 line-clamp-3 whitespace-pre-wrap opacity-80",children:a.completionVerification.summary}),a.completionVerification.evidenceSha256&&e.jsxs("p",{className:"mt-1 font-mono text-[10px] opacity-60",children:["sha256:",a.completionVerification.evidenceSha256.slice(0,12)]})]}),a.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:a.statusReason})]})})]})}),e.jsx(Ie,{open:S,onOpenChange:h,children:e.jsxs(_e,{className:"max-w-[400px] border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsx(Pe,{children:t("goal.dialog.title")}),e.jsx(Ve,{children:t("goal.dialog.description")}),e.jsxs(Le,{className:"mt-2",children:[e.jsx("button",{type:"button",onClick:()=>h(!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:x==="delete",onClick:()=>void K(),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:[x==="delete"&&e.jsx($,{className:"w-3.5 h-3.5 animate-spin"}),t("goal.action.delete")]})]})]})})]})}function re({label:t,children:s,disabled:a,destructive:r,onClick:o}){return e.jsxs(ge,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":t,disabled:a,onClick:o,className:M("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",r?"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(le,{side:"top",className:"text-[10px]",children:t})]})}function Ts(){const t=D(),s=y(d=>d.currentSessionRef),a=y(d=>d.sessions),r=y(d=>d.messages),o=f.useMemo(()=>{var c,k,l,p,x;const d=s?(c=tt(a,s))==null?void 0:c.pendingInteraction:void 0;if(d)return d.type;for(let j=r.length-1;j>=0;j-=1){const S=(k=r[j])==null?void 0:k.agentContent;if(((l=S==null?void 0:S.confirmation)==null?void 0:l.status)==="pending")return"permission";if(((p=S==null?void 0:S.question)==null?void 0:p.status)==="pending")return"question";if(((x=S==null?void 0:S.elicitation)==null?void 0:x.status)==="pending")return"elicitation"}return null},[s,r,a]);if(!o)return null;const i=()=>{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)},u=o==="question",b=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(ye,{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(u?"interaction.bar.questionTitle":b?"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(u?"interaction.bar.questionHint":b?"interaction.bar.elicitationHint":"interaction.bar.permissionHint")})]}),e.jsxs("button",{type:"button",onClick:i,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(ze,{className:"h-3 w-3"}),t("interaction.bar.review")]})]})}const Ms=f.lazy(()=>Oe(()=>import("./MarkdownRenderer-D7ap0LLK.js").then(t=>t.M),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.MarkdownRenderer})));function As(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`}function Rs(){const t=D(),s=y(r=>r.sideConversation),a=y(r=>r.dismissSideConversation);return s?e.jsx("section",{"aria-label":t("chat.side.title"),"data-blade-side-conversation":!0,"data-status":s.status,className:"shrink-0 border-y border-[hsl(var(--deck-accent)/0.28)] bg-[hsl(var(--deck-accent-soft)/0.42)]",children:e.jsxs("div",{className:"px-4 py-3 md:px-6",children:[e.jsxs("header",{className:"flex min-h-7 items-start gap-2",children:[e.jsx(kt,{"aria-hidden":!0,className:"mt-0.5 h-4 w-4 shrink-0 text-[hsl(var(--deck-accent))]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-1",children:[e.jsx("h2",{className:"font-mono text-[11px] font-semibold uppercase text-[hsl(var(--deck-accent))]",children:t("chat.side.title")}),s.durationMs!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-1 font-mono text-[9.5px] text-[hsl(var(--deck-ink-faint))]",children:[e.jsx(jt,{"aria-hidden":!0,className:"h-3 w-3"}),As(s.durationMs)]})]}),e.jsx("p",{className:"mt-0.5 break-words font-mono text-[11px] leading-4 text-[hsl(var(--deck-ink-muted))]",children:s.question})]}),e.jsx("button",{type:"button",onClick:a,"aria-label":t("chat.side.dismiss"),title:t("chat.side.dismiss"),className:"flex h-7 w-7 shrink-0 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:e.jsx(We,{"aria-hidden":!0,className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{"aria-live":"polite","aria-busy":s.status==="loading",className:"mt-2 max-h-[min(36vh,320px)] overflow-y-auto border-l-2 border-[hsl(var(--deck-accent)/0.42)] pl-3 pr-1",children:[s.status==="loading"&&e.jsxs("div",{role:"status",className:"flex min-h-9 items-center gap-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsx($,{"aria-hidden":!0,className:"h-3.5 w-3.5 animate-spin text-[hsl(var(--deck-accent))]"}),t("chat.side.loading")]}),s.status==="error"&&e.jsxs("div",{role:"alert",className:"flex min-h-9 items-start gap-2 font-mono text-[11px] leading-5 text-red-700 dark:text-red-300",children:[e.jsx(ye,{"aria-hidden":!0,className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"break-words",children:s.error??t("chat.side.failed")})]}),s.status==="completed"&&s.response&&e.jsx(f.Suspense,{fallback:e.jsx("div",{className:"whitespace-pre-wrap break-words font-mono text-[12px] leading-5 text-[hsl(var(--deck-ink))]",children:s.response}),children:e.jsx(Ms,{content:s.response,className:"text-[12px] leading-5 [&_h1]:text-[14px] [&_h2]:text-[13px] [&_h3]:text-[12px]"})})]})]})}):null}function fe(t){return Number.isFinite(t)?Math.max(0,t):0}function Fs(t){const s=fe(t.totalInputTokens),a=fe(t.cacheReadTokens),r=fe(t.cacheWriteTokens),o=Math.min(a,s),i=Math.min(r,Math.max(0,s-o)),u=Math.max(0,s-o-i),b=s>0&&(a>0||r>0);return{totalInputTokens:s,cacheReadTokens:o,cacheWriteTokens:i,uncachedInputTokens:u,...b?{hitRate:o/s}:{}}}function $s(t){return t===void 0||!Number.isFinite(t)?"—":`${Math.round(Math.max(0,Math.min(1,t))*100)}%`}const Ds={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:""},Bs={model_changed:"status.cacheBreak.model",system_prompt_changed:"status.cacheBreak.system",tools_changed:"status.cacheBreak.tools",request_policy_changed:"status.cacheBreak.policy",ttl_expired:"status.cacheBreak.ttl",server_side:"status.cacheBreak.server"},q=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString(),ne=t=>{const s=Math.max(0,Math.ceil(t/1e3)),a=Math.floor(s/60),r=s%60;return a>0?`${a}m ${r}s`:`${r}s`};function Is(){const t=D(),s=y(N=>N.tokenUsage),a=y(N=>N.isStreaming),r=y(N=>N.agentPhase),o=y(N=>N.providerAdmission),i=y(N=>N.providerCircuit),u=y(N=>N.providerRetry),b=y(N=>N.providerStall),d=y(N=>N.actionStationarity),c=Ds[r]??"",k=(u==null?void 0:u.delayMs)!==void 0?` · ${Math.max(0,Math.ceil(u.delayMs/1e3))}s`:"",l=d?`${t(d.phase==="halted"?"status.phase.actionStationarityStopped":"status.phase.actionStationarityRecovering")} · ${d.toolName} · ${d.runLength}/${d.haltThreshold}`:i?i.phase==="probe"?"Provider · Recovery probe":`Provider · Circuit open${i.retryAfterMs!==void 0?` · probe in ${ne(i.retryAfterMs)}`:""}${i.recoveryRemainingMs!==void 0?` · ${ne(i.recoveryRemainingMs)}`:""}`:o?`Provider · Capacity queue ${o.queuePosition}/${Math.max(o.queueDepth,o.queuePosition)} · ${o.scope} · ${ne(o.waitMs)}`:u?u.mode==="bounded_foreground"?`Provider · Bounded recovery · ${u.attempt}/${u.maxRetries} · ${ne(u.recoveryRemainingMs??0)}`:`Provider · ${t("chat.error.action.retryingTask")} · ${u.attempt}/${u.maxRetries}${k}`:b?`${t("status.phase.providerStall")} · ${Math.ceil(b.durationMs/1e3)}s / ${Math.ceil(b.timeoutMs/1e3)}s`:c?t(c):"",p=s.maxContextTokens>0?Math.round(s.totalTokens/s.maxContextTokens*100):0,x=Fs(s),j=$s(x.hitRate),S=Math.min(p,100),h=p>95?"danger":p>80?"warn":"safe";return e.jsxs("div",{className:"flex items-center gap-2 border-t border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/70 px-3 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm sm:gap-4 sm:px-5",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",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:M("text-[12px] font-medium",h==="safe"&&"text-[hsl(var(--deck-ink))]",h==="warn"&&"text-amber-600 dark:text-amber-400",h==="danger"&&"text-red-600 dark:text-red-400"),children:q(s.totalTokens)}),e.jsxs("span",{className:"text-[hsl(var(--deck-ink-faint))]",children:["/ ",q(s.maxContextTokens)]})]}),s.isDefaultMaxTokens&&e.jsx(ve,{children:e.jsxs(ge,{children:[e.jsx(ke,{asChild:!0,children:e.jsx(yt,{className:"h-3 w-3 cursor-help text-[hsl(var(--deck-ink-faint))]"})}),e.jsx(le,{side:"top",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:t("status.tokenLimitTooltip")})})]})}),e.jsxs("div",{className:"relative hidden h-2 w-32 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] sm:block","aria-hidden":"true",children:[e.jsx("div",{className:M("absolute inset-y-0 left-0 transition-[width] duration-300",h==="safe"&&"bg-[hsl(var(--deck-accent))]",h==="warn"&&"bg-amber-500",h==="danger"&&"bg-red-500"),style:{width:`${S}%`}}),e.jsx("div",{className:"flex absolute inset-0 pointer-events-none",children:[25,50,75].map(N=>e.jsx("span",{className:"absolute inset-y-0 w-px bg-[hsl(var(--deck-canvas-veil))]/60",style:{left:`${N}%`}},N))})]}),e.jsxs("span",{className:M("w-10 text-right tabular-nums text-[hsl(var(--deck-ink-faint))]",h==="warn"&&"text-amber-600 dark:text-amber-400",h==="danger"&&"text-red-600 dark:text-red-400"),children:[p,"%"]})]}),e.jsx(ve,{children:e.jsxs(ge,{children:[e.jsx(ke,{asChild:!0,children:e.jsxs("div",{className:"flex shrink-0 cursor-help items-baseline gap-2 border-l border-[hsl(var(--deck-hairline))] pl-2 sm:pl-4","data-testid":"prompt-cache-hit-rate","aria-label":`${t("status.cache")} ${j}`,children:[e.jsx("span",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:t("status.cache")}),e.jsx("span",{className:M("tabular-nums",x.hitRate===void 0?"text-[hsl(var(--deck-ink-faint))]":"font-medium text-[hsl(var(--deck-accent))]"),children:j})]})}),e.jsx(le,{side:"top",className:"max-w-[280px]",children:x.hitRate===void 0?e.jsx("p",{className:"text-xs",children:t("status.cacheUnavailable")}):e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsx("p",{children:t("status.cacheTooltip")}),e.jsx("p",{className:"font-mono tabular-nums",children:t("status.cacheDetails",{read:q(x.cacheReadTokens),write:q(x.cacheWriteTokens),uncached:q(x.uncachedInputTokens)})}),s.cacheBreak&&e.jsx("p",{className:"text-[hsl(var(--deck-accent))]",children:t("status.cacheBreak",{reason:t(Bs[s.cacheBreak.reason]??"status.cacheBreak.server"),previous:q(s.cacheBreak.previousCacheReadTokens),current:q(s.cacheBreak.cacheReadTokens)})})]})})]})}),e.jsx("div",{className:"flex-1"}),a&&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 _s(){const{locale:t}=Ue(),s=st(n=>n.agentTeamsEnabled),a=y(n=>n.teams),r=y(n=>n.currentSessionRef),o=y(n=>n.loadTeams),[i,u]=f.useState({}),[b,d]=f.useState({}),[c,k]=f.useState({}),[l,p]=f.useState(null),[x,j]=f.useState(null),[S,h]=f.useState(null);if(f.useEffect(()=>{o(r??void 0)},[s,r,o]),!s||!r||a.length===0)return null;const N=async n=>{var E;const m=(E=c[n])==null?void 0:E.trim();if(!(!m||l)){p(n),h(null);try{await Ce.sendMessage(r,n,b[n]??"*",m),k(w=>({...w,[n]:""})),await o(r)}catch(w){h(w instanceof Error?w.message:F(t,"actionFailed"))}finally{p(null)}}},v=async n=>{if(!x){j(n),h(null);try{await Ce.delete(r,n),await o(r)}catch(m){h(m instanceof Error?m.message:F(t,"actionFailed"))}finally{j(null)}}};return e.jsxs("section",{"aria-label":F(t,"title"),"data-blade-team-panel":!0,className:"shrink-0 border-y border-emerald-300/50 bg-emerald-50/55 dark:border-emerald-800/55 dark:bg-emerald-950/20",children:[S&&e.jsx("div",{role:"alert",className:"border-b border-red-200 bg-red-50 px-4 py-2 font-mono text-[10px] text-red-700 dark:border-red-900 dark:bg-red-950/30 dark:text-red-300 md:px-6",children:S}),a.filter(n=>n.status!=="deleted").map(n=>{var w;const m=i[n.name]??n.status==="running",E=n.tasks.filter(C=>C.status==="completed").length;return e.jsxs("div",{className:"border-b border-emerald-200/40 last:border-0 dark:border-emerald-900/40",children:[e.jsxs("div",{className:"flex min-h-11 items-center gap-2 px-4 py-2 md:px-6",children:[e.jsx("button",{type:"button",onClick:()=>u(C=>({...C,[n.name]:!m})),"aria-label":m?F(t,"collapse"):F(t,"expand"),className:"flex h-7 w-7 items-center justify-center rounded-md text-emerald-700 hover:bg-emerald-100 dark:text-emerald-300 dark:hover:bg-emerald-900/50",children:m?e.jsx(ee,{className:"h-4 w-4"}):e.jsx(de,{className:"h-4 w-4"})}),e.jsx(wt,{className:"h-4 w-4 shrink-0 text-emerald-700 dark:text-emerald-300"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("h2",{className:"truncate font-mono text-[11px] font-semibold uppercase text-emerald-800 dark:text-emerald-200",children:n.name}),e.jsxs("span",{className:"font-mono text-[9.5px] text-[hsl(var(--deck-ink-faint))]",children:[n.status," · ",n.members.length-1," ",F(t,"members")," · ",E,"/",n.tasks.length," ",F(t,"tasks")]})]}),n.description&&e.jsx("p",{className:"truncate font-mono text-[10px] text-[hsl(var(--deck-ink-muted))]",children:n.description})]}),e.jsx("button",{type:"button",onClick:()=>void v(n.name),disabled:x===n.name,"aria-label":F(t,"delete"),title:F(t,"delete"),className:"flex h-7 w-7 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] hover:bg-red-50 hover:text-red-600 disabled:opacity-40 dark:hover:bg-red-950/40",children:e.jsx(Z,{className:"h-3.5 w-3.5"})})]}),m&&e.jsxs("div",{className:"max-h-[min(40vh,360px)] overflow-y-auto border-t border-emerald-200/40 px-4 py-3 md:px-6 dark:border-emerald-900/40",children:[e.jsxs("div",{className:"grid gap-x-6 gap-y-2 lg:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"mb-1 font-mono text-[9.5px] font-semibold uppercase text-[hsl(var(--deck-ink-faint))]",children:F(t,"members")}),n.members.map(C=>e.jsxs("div",{className:"flex min-h-7 items-center gap-2 border-b border-[hsl(var(--deck-hairline)/0.55)] py-1 last:border-0",children:[e.jsx("span",{"aria-label":C.status,className:`h-1.5 w-1.5 shrink-0 rounded-full ${C.status==="running"?"bg-emerald-500":C.status==="completed"||C.status==="leader"?"bg-sky-500":C.status==="failed"?"bg-red-500":"bg-zinc-400"}`}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[10.5px] text-[hsl(var(--deck-ink))]",children:C.name}),e.jsx("span",{className:"font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:C.subagentType}),C.worktreePath&&e.jsx(He,{className:"h-3 w-3 text-[hsl(var(--deck-ink-faint))]","aria-label":F(t,"worktree")})]},C.id))]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-1 font-mono text-[9.5px] font-semibold uppercase text-[hsl(var(--deck-ink-faint))]",children:F(t,"tasks")}),n.tasks.length===0?e.jsx("p",{className:"font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:F(t,"noTasks")}):n.tasks.map(C=>e.jsxs("div",{className:"flex min-h-7 items-center gap-2 border-b border-[hsl(var(--deck-hairline)/0.55)] py-1 last:border-0",children:[e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:["#",C.id]}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[10.5px] text-[hsl(var(--deck-ink))]",children:C.subject}),e.jsx("span",{className:"font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:C.status})]},C.id))]})]}),n.peerMessagingEnabled&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-emerald-200/40 pt-3 dark:border-emerald-900/40",children:[e.jsxs("select",{"aria-label":F(t,"recipient"),value:b[n.name]??"*",onChange:C=>d(R=>({...R,[n.name]:C.target.value})),className:"h-8 max-w-32 rounded-md border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))] px-2 font-mono text-[10px]",children:[e.jsx("option",{value:"*",children:F(t,"broadcast")}),n.members.filter(C=>C.status!=="leader").map(C=>e.jsx("option",{value:C.name,children:C.name},C.id))]}),e.jsx("input",{value:c[n.name]??"",onChange:C=>k(R=>({...R,[n.name]:C.target.value})),onKeyDown:C=>{C.key==="Enter"&&N(n.name)},placeholder:F(t,"messagePlaceholder"),className:"h-8 min-w-0 flex-1 rounded-md border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))] px-2 font-mono text-[10.5px] outline-none focus:border-emerald-500"}),e.jsx("button",{type:"button",onClick:()=>void N(n.name),disabled:!((w=c[n.name])!=null&&w.trim())||l===n.name,"aria-label":F(t,"send"),title:F(t,"send"),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-emerald-700 text-white hover:bg-emerald-800 disabled:opacity-40 dark:bg-emerald-600",children:e.jsx(Ke,{className:"h-3.5 w-3.5"})})]})]})]},n.name)})]})}function Ps(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 a=s.content.filter(o=>o.type==="text").map(o=>o.text).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(Ne,{status:S})]}),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:h||"(no output)"}),typeof l.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 ",l.exitCode,typeof l.durationMs=="number"?` · ${(l.durationMs/1e3).toFixed(3)}s`:"",l.truncated===!0?" · truncated":""]})]})})}const{text:p,images:x}=ts(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(Te,{text:p,label:"Copy message"})}),e.jsxs("div",{className:"bg-[hsl(var(--deck-surface-2))] rounded-lg px-4 py-3 max-w-[85%]",children:[p&&e.jsx("p",{className:"text-[14px] text-[hsl(var(--deck-ink))] font-mono leading-relaxed whitespace-pre-wrap",children:p}),x.length>0&&e.jsx("div",{className:M("grid gap-2",x.length===1?"grid-cols-1 mt-0":"grid-cols-2 mt-3"),children:x.map((j,S)=>e.jsx("img",{src:j,alt:`attachment-${S+1}`,className:"object-cover w-full max-h-64 rounded-md"},`${j}-${S}`))})]}),e.jsx(es,{})]})}const o=ss(t),i=Lt((c=t.metadata)==null?void 0:c.codeReview),u=Jt((k=t.metadata)==null?void 0:k.structuredOutput);return e.jsxs("div",{"data-chat-message-id":t.id,"data-chat-role":"assistant",className:M("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:[i?e.jsx(Ut,{report:i}):u?e.jsx(Yt,{report:u}):e.jsx(hs,{message:t}),!u&&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(Te,{text:o,label:"Copy response"})})]})]})}const ps=f.memo(xs);function fs(t,s,a){return Math.max(0,t+(a-s))}function bs(t,s,a){return Math.min(s,Math.max(0,t)+Math.max(0,a))}function $e(t,s){return t?t.querySelector(`[data-chat-message-id="${CSS.escape(s)}"]`):null}function vs({turns:t,viewportRef:s,containerRef:a,onRevealTurn:r}){const o=D(),[i,u]=f.useState(null),[b,d]=f.useState(!1),c=f.useRef(null),k=f.useCallback(()=>{var h;const p=s.current,x=a.current;if(!p||!x||t.length===0)return;const j=p.getBoundingClientRect().top;let S=((h=t[0])==null?void 0:h.id)??null;for(const N of t){const v=$e(x,N.id);if(v)if(v.getBoundingClientRect().top-j<=24)S=N.id;else break}u(S)},[t,s,a]);f.useEffect(()=>{const p=s.current;if(!p)return;const x=()=>{c.current===null&&(c.current=window.requestAnimationFrame(()=>{c.current=null,k()}))};return k(),p.addEventListener("scroll",x,{passive:!0}),()=>{p.removeEventListener("scroll",x),c.current!==null&&(window.cancelAnimationFrame(c.current),c.current=null)}},[k,s]);const l=f.useCallback(p=>{const x=()=>{const S=$e(a.current,p.id);S&&(S.scrollIntoView({behavior:"smooth",block:"start"}),u(p.id))};r(p.index)?x():window.requestAnimationFrame(()=>window.requestAnimationFrame(x))},[a,r]);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:p=>{p.currentTarget.contains(p.relatedTarget)||d(!1)},children:e.jsxs("div",{className:"relative flex items-center justify-end",children:[e.jsx("ul",{className:M("flex flex-col items-center gap-2 py-2 transition-opacity",b?"opacity-0":"opacity-100"),"aria-hidden":b,children:t.map(p=>e.jsx("li",{children:e.jsx("span",{className:M("block rounded-full transition-all",p.id===i?"h-2 w-2 bg-[hsl(var(--deck-accent))]":"h-1.5 w-1.5 bg-[hsl(var(--deck-ink-faint))]/40")})},p.id))}),e.jsx("div",{className:M("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",b?"pointer-events-auto translate-x-0 opacity-100":"pointer-events-none translate-x-2 opacity-0"),children:t.map((p,x)=>e.jsxs("button",{type:"button",onClick:()=>l(p),className:M("flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors",p.id===i?"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:M("mt-1 h-1.5 w-1.5 shrink-0 rounded-full",p.id===i?"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:x+1})}),e.jsx("span",{className:"line-clamp-2 text-[12px] leading-4",children:p.preview})]})]},p.id))})]})})}const De=80;function gs(t){return typeof t=="string"?t:Array.isArray(t)?t.filter(s=>s.type==="text").map(s=>s.text).join(" "):""}function ks(t){const s=gs(t).replace(/\s+/g," ").trim();return s?s.length>De?`${s.slice(0,De-1)}…`:s:""}function js(t){const s=[];for(let a=0;a<t.length;a+=1){const r=t[a];if(r.role!=="user"||!r.id)continue;const o=ks(r.content);o&&s.push({id:r.id,index:a,preview:o})}return s}const xe=120,pe=80,ys=96;function Y(t){return(t==null?void 0:t.querySelector("[data-radix-scroll-area-viewport]"))??null}function ws({messages:t,isLoading:s}){const a=D(),r=f.useRef(null),o=f.useRef(null),i=f.useRef(!0),u=f.useRef(t.length),b=f.useRef(null),[d,c]=f.useState(xe),[k,l]=f.useState(!1);f.useEffect(()=>{const n=Y(r.current);if(!n||!i.current)return;const m=window.requestAnimationFrame(()=>{n.scrollTop=n.scrollHeight});return()=>window.cancelAnimationFrame(m)},[t]),f.useEffect(()=>{const n=Y(r.current);if(!n)return;o.current=n;const m=()=>{const w=n.scrollHeight-n.scrollTop-n.clientHeight<=ys;i.current=w,l(!w)};return m(),n.addEventListener("scroll",m,{passive:!0}),()=>n.removeEventListener("scroll",m)},[]),f.useEffect(()=>{const n=u.current;u.current=t.length,c(m=>m>=n&&t.length>n?t.length:Math.min(Math.max(m,xe),t.length||xe))},[t.length]);const p=Math.max(t.length-d,0),x=p,j=f.useMemo(()=>t.slice(x),[t,x]),S=f.useMemo(()=>js(t),[t]);if(f.useLayoutEffect(()=>{var E;const n=b.current;if(!n)return;const m=Y(r.current);if(b.current=null,!!m){if((E=n.element)!=null&&E.isConnected){const w=n.element.getBoundingClientRect().top-n.viewportTop;m.scrollTop+=w;return}m.scrollTop=fs(n.scrollTop,n.scrollHeight,m.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(be,{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(mt,{className:"w-3 h-3"}),a("chat.list.loading.eyebrow")]}),e.jsx("h2",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:a("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:a("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((n,m)=>e.jsxs("div",{className:M("flex gap-3",m%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:`${n}%`,animationDelay:`${m*120}ms`}})]},n))})]})});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(be,{size:44}),e.jsxs("div",{children:[e.jsx("div",{className:"deck-eyebrow text-[hsl(var(--deck-accent))]",children:a("chat.list.empty.eyebrow")}),e.jsx("div",{className:"mt-2 text-[15px] font-medium text-[hsl(var(--deck-ink))]",children:a("chat.list.empty.title")}),e.jsx("div",{className:"mt-1 max-w-xs text-[12px] text-[hsl(var(--deck-ink-muted))]",children:a("chat.list.empty.hint")})]})]})});const h=()=>{const n=Y(r.current);n&&(i.current=!0,l(!1),n.scrollTo({top:n.scrollHeight,behavior:"smooth"}))},N=()=>{var m;const n=Y(r.current);if(n){const E=((m=r.current)==null?void 0:m.querySelector("[data-chat-message-id]"))??null;b.current={element:E,viewportTop:(E==null?void 0:E.getBoundingClientRect().top)??0,scrollHeight:n.scrollHeight,scrollTop:n.scrollTop}}c(E=>bs(E,t.length,pe))},v=n=>n>=x?!0:(c(t.length),!1);return e.jsxs("div",{ref:r,className:"relative flex-1 min-h-0",children:[e.jsx(et,{className:"h-full",children:e.jsxs("div",{className:"flex flex-col px-4 pb-4 w-full md:px-6",children:[p>0&&e.jsx("div",{className:"flex justify-center py-3",children:e.jsx("button",{type:"button",onClick:N,"aria-label":a("chat.list.showEarlierWithRemaining",{count:Math.min(p,pe),remaining:p}),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:a("chat.list.showEarlier",{count:Math.min(p,pe)})})}),j.map((n,m)=>{const E=x+m,w=E>0?t[E-1]:null,C=!w||w.role!==n.role||w.role==="user";return e.jsx(ps,{message:n,showAvatar:C},n.id||`msg-${E}`)})]})}),e.jsx(vs,{turns:S,viewportRef:o,containerRef:r,onRevealTurn:v}),k&&e.jsxs("button",{type:"button",onClick:h,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(ze,{className:"h-3.5 w-3.5 text-[hsl(var(--deck-accent))]"}),a("chat.list.jumpLatest")]})]})}const Ns=f.memo(ws),ve=Ft,ge=$t,ke=Dt,le=f.forwardRef(({className:t,sideOffset:s=4,...a},r)=>e.jsx(Qe,{ref:r,sideOffset:s,className:M("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),...a}));le.displayName=Qe.displayName;const Ss={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 ae(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function Cs(t){if(t<60)return`${t}s`;const s=Math.floor(t/60),a=t%60;return a===0?`${s}m`:`${s}m ${a}s`}function Es(){var O,B,V,L;const t=D(),{locale:s}=Ue(),a=y(T=>T.goal),r=y(T=>T.pauseGoal),o=y(T=>T.resumeGoal),i=y(T=>T.editGoal),u=y(T=>T.clearGoal),[b,d]=f.useState(!1),[c,k]=f.useState(!1),[l,p]=f.useState(""),[x,j]=f.useState(null),[S,h]=f.useState(!1);if(f.useEffect(()=>{d(!1),k(!1),p((a==null?void 0:a.objective)??""),h(!1)},[a==null?void 0:a.goalId]),!a)return null;const N=Ss[a.status],v=["active","verifying","paused","blocked"].includes(a.status),n=a.status==="active"||a.status==="verifying",m=a.status==="paused"||a.status==="blocked",E=x!==null,w=async(T,P)=>{j(T);try{await P()}finally{j(null)}},C=()=>{p(a.objective),k(!0),d(!0)},R=async T=>{T.preventDefault();const P=l.trim();if(!P||P===a.objective){k(!1);return}await w("edit",()=>i(P)),k(!1)},K=async()=>{await w("delete",u),h(!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":a.status,"data-blade-goal-recovery":(O=a.prematureStop)==null?void 0:O.consecutiveCount,"data-blade-goal-recovery-pattern":(B=a.prematureStop)==null?void 0:B.pattern,"data-blade-goal-verification-stall":(V=a.verificationStall)==null?void 0:V.consecutiveCount,children:[e.jsxs("div",{className:M("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",b&&"rounded-b-none border-b-0"),children:[a.status==="complete"?e.jsx(ht,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):e.jsx(xt,{className:M("h-3.5 w-3.5 shrink-0",N.accent)}),e.jsx("span",{className:M("h-1.5 w-1.5 shrink-0 rounded-full",N.dot)}),e.jsx("span",{className:M("shrink-0 text-[10px] font-medium leading-none",N.accent),children:a.status==="verifying"?s==="zh"?"验证中":"Verifying":t(N.labelKey)}),e.jsx("span",{className:"h-3 w-px shrink-0 bg-[hsl(var(--deck-hairline))]"}),e.jsx("button",{type:"button","aria-label":t(b?"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(T=>!T),"aria-expanded":b,title:a.objective,children:a.objective}),a.tokensUsed>0&&e.jsxs("span",{className:"hidden shrink-0 text-[10px] tabular-nums text-[hsl(var(--deck-ink-muted))] sm:inline",children:[ae(a.tokensUsed),a.tokenBudget!==void 0&&`/${ae(a.tokenBudget)}`]}),e.jsxs("div",{className:"flex shrink-0 items-center",children:[n&&e.jsx(re,{label:t("goal.action.pause"),disabled:E,onClick:()=>void w("pause",r),children:x==="pause"?e.jsx($,{className:"animate-spin"}):e.jsx(pt,{})}),m&&e.jsx(re,{label:t("goal.action.resume"),disabled:E,onClick:()=>void w("resume",o),children:x==="resume"?e.jsx($,{className:"animate-spin"}):e.jsx(ft,{})}),e.jsx(re,{label:t(v?"goal.action.edit":"goal.action.expand"),disabled:!v&&!b,onClick:v?C:()=>d(T=>!T),children:v?e.jsx(Ge,{}):e.jsx(bt,{})}),e.jsx(re,{label:t("goal.action.delete"),disabled:E,destructive:!0,onClick:()=>h(!0),children:e.jsx(Z,{})})]})]}),b&&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:c?e.jsxs("form",{onSubmit:R,children:[e.jsx("textarea",{id:"goal-objective",value:l,onChange:T=>p(T.target.value),onKeyDown:T=>{T.key==="Escape"&&k(!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:()=>k(!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(We,{className:"h-3 w-3"}),t("goal.action.cancel")]}),e.jsxs("button",{type:"submit",disabled:!l.trim()||x==="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:[x==="edit"?e.jsx($,{className:"h-3 w-3 animate-spin"}):e.jsx(ce,{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:a.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(vt,{className:"h-3 w-3"}),ae(a.tokensUsed),a.tokenBudget!==void 0&&` / ${ae(a.tokenBudget)}`," ",t("goal.metrics.tokens")]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(gt,{className:"h-3 w-3"}),Cs(a.timeUsedSeconds)]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ie,{className:"h-3 w-3"}),a.continuationCount===1?t("goal.metrics.continuationOne",{n:a.continuationCount}):t("goal.metrics.continuationMany",{n:a.continuationCount})]})]}),a.prematureStop&&e.jsxs("div",{className:"mt-2 inline-flex items-center gap-1.5 font-mono text-[10px] text-amber-700 dark:text-amber-300",children:[e.jsx(ie,{className:"h-3 w-3"}),s==="zh"?"恢复提示":"Recovery nudge"," ",a.prematureStop.consecutiveCount," ·"," ",a.prematureStop.pattern.replaceAll("_"," ")]}),a.completionVerification&&e.jsxs("div",{"data-goal-verification":a.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:["#",a.completionVerification.attempt," ·"," ",a.completionVerification.status.toUpperCase()," ·"," ",((L=a.completionVerification.verifierSessionId)==null?void 0:L.slice(0,12))??"-",a.verificationStall?s==="zh"?` · 重复 ${a.verificationStall.consecutiveCount}/3`:` · repeat ${a.verificationStall.consecutiveCount}/3`:""]}),a.completionVerification.summary&&e.jsx("p",{className:"mt-1 line-clamp-3 whitespace-pre-wrap opacity-80",children:a.completionVerification.summary}),a.completionVerification.evidenceSha256&&e.jsxs("p",{className:"mt-1 font-mono text-[10px] opacity-60",children:["sha256:",a.completionVerification.evidenceSha256.slice(0,12)]})]}),a.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:a.statusReason})]})})]})}),e.jsx(Ie,{open:S,onOpenChange:h,children:e.jsxs(_e,{className:"max-w-[400px] border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))]",children:[e.jsx(Pe,{children:t("goal.dialog.title")}),e.jsx(Ve,{children:t("goal.dialog.description")}),e.jsxs(Le,{className:"mt-2",children:[e.jsx("button",{type:"button",onClick:()=>h(!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:x==="delete",onClick:()=>void K(),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:[x==="delete"&&e.jsx($,{className:"w-3.5 h-3.5 animate-spin"}),t("goal.action.delete")]})]})]})})]})}function re({label:t,children:s,disabled:a,destructive:r,onClick:o}){return e.jsxs(ge,{children:[e.jsx(ke,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":t,disabled:a,onClick:o,className:M("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",r?"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(le,{side:"top",className:"text-[10px]",children:t})]})}function Ts(){const t=D(),s=y(d=>d.currentSessionRef),a=y(d=>d.sessions),r=y(d=>d.messages),o=f.useMemo(()=>{var c,k,l,p,x;const d=s?(c=tt(a,s))==null?void 0:c.pendingInteraction:void 0;if(d)return d.type;for(let j=r.length-1;j>=0;j-=1){const S=(k=r[j])==null?void 0:k.agentContent;if(((l=S==null?void 0:S.confirmation)==null?void 0:l.status)==="pending")return"permission";if(((p=S==null?void 0:S.question)==null?void 0:p.status)==="pending")return"question";if(((x=S==null?void 0:S.elicitation)==null?void 0:x.status)==="pending")return"elicitation"}return null},[s,r,a]);if(!o)return null;const i=()=>{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)},u=o==="question",b=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(ye,{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(u?"interaction.bar.questionTitle":b?"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(u?"interaction.bar.questionHint":b?"interaction.bar.elicitationHint":"interaction.bar.permissionHint")})]}),e.jsxs("button",{type:"button",onClick:i,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(ze,{className:"h-3 w-3"}),t("interaction.bar.review")]})]})}const Ms=f.lazy(()=>Oe(()=>import("./MarkdownRenderer-BA9VgOyM.js").then(t=>t.M),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.MarkdownRenderer})));function As(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(1)}s`}function Rs(){const t=D(),s=y(r=>r.sideConversation),a=y(r=>r.dismissSideConversation);return s?e.jsx("section",{"aria-label":t("chat.side.title"),"data-blade-side-conversation":!0,"data-status":s.status,className:"shrink-0 border-y border-[hsl(var(--deck-accent)/0.28)] bg-[hsl(var(--deck-accent-soft)/0.42)]",children:e.jsxs("div",{className:"px-4 py-3 md:px-6",children:[e.jsxs("header",{className:"flex min-h-7 items-start gap-2",children:[e.jsx(kt,{"aria-hidden":!0,className:"mt-0.5 h-4 w-4 shrink-0 text-[hsl(var(--deck-accent))]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-1",children:[e.jsx("h2",{className:"font-mono text-[11px] font-semibold uppercase text-[hsl(var(--deck-accent))]",children:t("chat.side.title")}),s.durationMs!==void 0&&e.jsxs("span",{className:"inline-flex items-center gap-1 font-mono text-[9.5px] text-[hsl(var(--deck-ink-faint))]",children:[e.jsx(jt,{"aria-hidden":!0,className:"h-3 w-3"}),As(s.durationMs)]})]}),e.jsx("p",{className:"mt-0.5 break-words font-mono text-[11px] leading-4 text-[hsl(var(--deck-ink-muted))]",children:s.question})]}),e.jsx("button",{type:"button",onClick:a,"aria-label":t("chat.side.dismiss"),title:t("chat.side.dismiss"),className:"flex h-7 w-7 shrink-0 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:e.jsx(We,{"aria-hidden":!0,className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{"aria-live":"polite","aria-busy":s.status==="loading",className:"mt-2 max-h-[min(36vh,320px)] overflow-y-auto border-l-2 border-[hsl(var(--deck-accent)/0.42)] pl-3 pr-1",children:[s.status==="loading"&&e.jsxs("div",{role:"status",className:"flex min-h-9 items-center gap-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))]",children:[e.jsx($,{"aria-hidden":!0,className:"h-3.5 w-3.5 animate-spin text-[hsl(var(--deck-accent))]"}),t("chat.side.loading")]}),s.status==="error"&&e.jsxs("div",{role:"alert",className:"flex min-h-9 items-start gap-2 font-mono text-[11px] leading-5 text-red-700 dark:text-red-300",children:[e.jsx(ye,{"aria-hidden":!0,className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"break-words",children:s.error??t("chat.side.failed")})]}),s.status==="completed"&&s.response&&e.jsx(f.Suspense,{fallback:e.jsx("div",{className:"whitespace-pre-wrap break-words font-mono text-[12px] leading-5 text-[hsl(var(--deck-ink))]",children:s.response}),children:e.jsx(Ms,{content:s.response,className:"text-[12px] leading-5 [&_h1]:text-[14px] [&_h2]:text-[13px] [&_h3]:text-[12px]"})})]})]})}):null}function fe(t){return Number.isFinite(t)?Math.max(0,t):0}function Fs(t){const s=fe(t.totalInputTokens),a=fe(t.cacheReadTokens),r=fe(t.cacheWriteTokens),o=Math.min(a,s),i=Math.min(r,Math.max(0,s-o)),u=Math.max(0,s-o-i),b=s>0&&(a>0||r>0);return{totalInputTokens:s,cacheReadTokens:o,cacheWriteTokens:i,uncachedInputTokens:u,...b?{hitRate:o/s}:{}}}function $s(t){return t===void 0||!Number.isFinite(t)?"—":`${Math.round(Math.max(0,Math.min(1,t))*100)}%`}const Ds={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:""},Bs={model_changed:"status.cacheBreak.model",system_prompt_changed:"status.cacheBreak.system",tools_changed:"status.cacheBreak.tools",request_policy_changed:"status.cacheBreak.policy",ttl_expired:"status.cacheBreak.ttl",server_side:"status.cacheBreak.server"},q=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toString(),ne=t=>{const s=Math.max(0,Math.ceil(t/1e3)),a=Math.floor(s/60),r=s%60;return a>0?`${a}m ${r}s`:`${r}s`};function Is(){const t=D(),s=y(N=>N.tokenUsage),a=y(N=>N.isStreaming),r=y(N=>N.agentPhase),o=y(N=>N.providerAdmission),i=y(N=>N.providerCircuit),u=y(N=>N.providerRetry),b=y(N=>N.providerStall),d=y(N=>N.actionStationarity),c=Ds[r]??"",k=(u==null?void 0:u.delayMs)!==void 0?` · ${Math.max(0,Math.ceil(u.delayMs/1e3))}s`:"",l=d?`${t(d.phase==="halted"?"status.phase.actionStationarityStopped":"status.phase.actionStationarityRecovering")} · ${d.toolName} · ${d.runLength}/${d.haltThreshold}`:i?i.phase==="probe"?"Provider · Recovery probe":`Provider · Circuit open${i.retryAfterMs!==void 0?` · probe in ${ne(i.retryAfterMs)}`:""}${i.recoveryRemainingMs!==void 0?` · ${ne(i.recoveryRemainingMs)}`:""}`:o?`Provider · Capacity queue ${o.queuePosition}/${Math.max(o.queueDepth,o.queuePosition)} · ${o.scope} · ${ne(o.waitMs)}`:u?u.mode==="bounded_foreground"?`Provider · Bounded recovery · ${u.attempt}/${u.maxRetries} · ${ne(u.recoveryRemainingMs??0)}`:`Provider · ${t("chat.error.action.retryingTask")} · ${u.attempt}/${u.maxRetries}${k}`:b?`${t("status.phase.providerStall")} · ${Math.ceil(b.durationMs/1e3)}s / ${Math.ceil(b.timeoutMs/1e3)}s`:c?t(c):"",p=s.maxContextTokens>0?Math.round(s.totalTokens/s.maxContextTokens*100):0,x=Fs(s),j=$s(x.hitRate),S=Math.min(p,100),h=p>95?"danger":p>80?"warn":"safe";return e.jsxs("div",{className:"flex items-center gap-2 border-t border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-canvas-veil))]/70 px-3 py-2 font-mono text-[11px] text-[hsl(var(--deck-ink-muted))] backdrop-blur-sm sm:gap-4 sm:px-5",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",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:M("text-[12px] font-medium",h==="safe"&&"text-[hsl(var(--deck-ink))]",h==="warn"&&"text-amber-600 dark:text-amber-400",h==="danger"&&"text-red-600 dark:text-red-400"),children:q(s.totalTokens)}),e.jsxs("span",{className:"text-[hsl(var(--deck-ink-faint))]",children:["/ ",q(s.maxContextTokens)]})]}),s.isDefaultMaxTokens&&e.jsx(ve,{children:e.jsxs(ge,{children:[e.jsx(ke,{asChild:!0,children:e.jsx(yt,{className:"h-3 w-3 cursor-help text-[hsl(var(--deck-ink-faint))]"})}),e.jsx(le,{side:"top",className:"max-w-[220px]",children:e.jsx("p",{className:"text-xs",children:t("status.tokenLimitTooltip")})})]})}),e.jsxs("div",{className:"relative hidden h-2 w-32 overflow-hidden rounded-sm border border-[hsl(var(--deck-border))] bg-[hsl(var(--deck-surface))] sm:block","aria-hidden":"true",children:[e.jsx("div",{className:M("absolute inset-y-0 left-0 transition-[width] duration-300",h==="safe"&&"bg-[hsl(var(--deck-accent))]",h==="warn"&&"bg-amber-500",h==="danger"&&"bg-red-500"),style:{width:`${S}%`}}),e.jsx("div",{className:"flex absolute inset-0 pointer-events-none",children:[25,50,75].map(N=>e.jsx("span",{className:"absolute inset-y-0 w-px bg-[hsl(var(--deck-canvas-veil))]/60",style:{left:`${N}%`}},N))})]}),e.jsxs("span",{className:M("w-10 text-right tabular-nums text-[hsl(var(--deck-ink-faint))]",h==="warn"&&"text-amber-600 dark:text-amber-400",h==="danger"&&"text-red-600 dark:text-red-400"),children:[p,"%"]})]}),e.jsx(ve,{children:e.jsxs(ge,{children:[e.jsx(ke,{asChild:!0,children:e.jsxs("div",{className:"flex shrink-0 cursor-help items-baseline gap-2 border-l border-[hsl(var(--deck-hairline))] pl-2 sm:pl-4","data-testid":"prompt-cache-hit-rate","aria-label":`${t("status.cache")} ${j}`,children:[e.jsx("span",{className:"deck-eyebrow text-[hsl(var(--deck-ink-faint))]",children:t("status.cache")}),e.jsx("span",{className:M("tabular-nums",x.hitRate===void 0?"text-[hsl(var(--deck-ink-faint))]":"font-medium text-[hsl(var(--deck-accent))]"),children:j})]})}),e.jsx(le,{side:"top",className:"max-w-[280px]",children:x.hitRate===void 0?e.jsx("p",{className:"text-xs",children:t("status.cacheUnavailable")}):e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsx("p",{children:t("status.cacheTooltip")}),e.jsx("p",{className:"font-mono tabular-nums",children:t("status.cacheDetails",{read:q(x.cacheReadTokens),write:q(x.cacheWriteTokens),uncached:q(x.uncachedInputTokens)})}),s.cacheBreak&&e.jsx("p",{className:"text-[hsl(var(--deck-accent))]",children:t("status.cacheBreak",{reason:t(Bs[s.cacheBreak.reason]??"status.cacheBreak.server"),previous:q(s.cacheBreak.previousCacheReadTokens),current:q(s.cacheBreak.cacheReadTokens)})})]})})]})}),e.jsx("div",{className:"flex-1"}),a&&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 _s(){const{locale:t}=Ue(),s=st(n=>n.agentTeamsEnabled),a=y(n=>n.teams),r=y(n=>n.currentSessionRef),o=y(n=>n.loadTeams),[i,u]=f.useState({}),[b,d]=f.useState({}),[c,k]=f.useState({}),[l,p]=f.useState(null),[x,j]=f.useState(null),[S,h]=f.useState(null);if(f.useEffect(()=>{o(r??void 0)},[s,r,o]),!s||!r||a.length===0)return null;const N=async n=>{var E;const m=(E=c[n])==null?void 0:E.trim();if(!(!m||l)){p(n),h(null);try{await Ce.sendMessage(r,n,b[n]??"*",m),k(w=>({...w,[n]:""})),await o(r)}catch(w){h(w instanceof Error?w.message:F(t,"actionFailed"))}finally{p(null)}}},v=async n=>{if(!x){j(n),h(null);try{await Ce.delete(r,n),await o(r)}catch(m){h(m instanceof Error?m.message:F(t,"actionFailed"))}finally{j(null)}}};return e.jsxs("section",{"aria-label":F(t,"title"),"data-blade-team-panel":!0,className:"shrink-0 border-y border-emerald-300/50 bg-emerald-50/55 dark:border-emerald-800/55 dark:bg-emerald-950/20",children:[S&&e.jsx("div",{role:"alert",className:"border-b border-red-200 bg-red-50 px-4 py-2 font-mono text-[10px] text-red-700 dark:border-red-900 dark:bg-red-950/30 dark:text-red-300 md:px-6",children:S}),a.filter(n=>n.status!=="deleted").map(n=>{var w;const m=i[n.name]??n.status==="running",E=n.tasks.filter(C=>C.status==="completed").length;return e.jsxs("div",{className:"border-b border-emerald-200/40 last:border-0 dark:border-emerald-900/40",children:[e.jsxs("div",{className:"flex min-h-11 items-center gap-2 px-4 py-2 md:px-6",children:[e.jsx("button",{type:"button",onClick:()=>u(C=>({...C,[n.name]:!m})),"aria-label":m?F(t,"collapse"):F(t,"expand"),className:"flex h-7 w-7 items-center justify-center rounded-md text-emerald-700 hover:bg-emerald-100 dark:text-emerald-300 dark:hover:bg-emerald-900/50",children:m?e.jsx(ee,{className:"h-4 w-4"}):e.jsx(de,{className:"h-4 w-4"})}),e.jsx(wt,{className:"h-4 w-4 shrink-0 text-emerald-700 dark:text-emerald-300"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("h2",{className:"truncate font-mono text-[11px] font-semibold uppercase text-emerald-800 dark:text-emerald-200",children:n.name}),e.jsxs("span",{className:"font-mono text-[9.5px] text-[hsl(var(--deck-ink-faint))]",children:[n.status," · ",n.members.length-1," ",F(t,"members")," · ",E,"/",n.tasks.length," ",F(t,"tasks")]})]}),n.description&&e.jsx("p",{className:"truncate font-mono text-[10px] text-[hsl(var(--deck-ink-muted))]",children:n.description})]}),e.jsx("button",{type:"button",onClick:()=>void v(n.name),disabled:x===n.name,"aria-label":F(t,"delete"),title:F(t,"delete"),className:"flex h-7 w-7 items-center justify-center rounded-md text-[hsl(var(--deck-ink-faint))] hover:bg-red-50 hover:text-red-600 disabled:opacity-40 dark:hover:bg-red-950/40",children:e.jsx(Z,{className:"h-3.5 w-3.5"})})]}),m&&e.jsxs("div",{className:"max-h-[min(40vh,360px)] overflow-y-auto border-t border-emerald-200/40 px-4 py-3 md:px-6 dark:border-emerald-900/40",children:[e.jsxs("div",{className:"grid gap-x-6 gap-y-2 lg:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"mb-1 font-mono text-[9.5px] font-semibold uppercase text-[hsl(var(--deck-ink-faint))]",children:F(t,"members")}),n.members.map(C=>e.jsxs("div",{className:"flex min-h-7 items-center gap-2 border-b border-[hsl(var(--deck-hairline)/0.55)] py-1 last:border-0",children:[e.jsx("span",{"aria-label":C.status,className:`h-1.5 w-1.5 shrink-0 rounded-full ${C.status==="running"?"bg-emerald-500":C.status==="completed"||C.status==="leader"?"bg-sky-500":C.status==="failed"?"bg-red-500":"bg-zinc-400"}`}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[10.5px] text-[hsl(var(--deck-ink))]",children:C.name}),e.jsx("span",{className:"font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:C.subagentType}),C.worktreePath&&e.jsx(He,{className:"h-3 w-3 text-[hsl(var(--deck-ink-faint))]","aria-label":F(t,"worktree")})]},C.id))]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-1 font-mono text-[9.5px] font-semibold uppercase text-[hsl(var(--deck-ink-faint))]",children:F(t,"tasks")}),n.tasks.length===0?e.jsx("p",{className:"font-mono text-[10px] text-[hsl(var(--deck-ink-faint))]",children:F(t,"noTasks")}):n.tasks.map(C=>e.jsxs("div",{className:"flex min-h-7 items-center gap-2 border-b border-[hsl(var(--deck-hairline)/0.55)] py-1 last:border-0",children:[e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:["#",C.id]}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[10.5px] text-[hsl(var(--deck-ink))]",children:C.subject}),e.jsx("span",{className:"font-mono text-[9px] text-[hsl(var(--deck-ink-faint))]",children:C.status})]},C.id))]})]}),n.peerMessagingEnabled&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-emerald-200/40 pt-3 dark:border-emerald-900/40",children:[e.jsxs("select",{"aria-label":F(t,"recipient"),value:b[n.name]??"*",onChange:C=>d(R=>({...R,[n.name]:C.target.value})),className:"h-8 max-w-32 rounded-md border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))] px-2 font-mono text-[10px]",children:[e.jsx("option",{value:"*",children:F(t,"broadcast")}),n.members.filter(C=>C.status!=="leader").map(C=>e.jsx("option",{value:C.name,children:C.name},C.id))]}),e.jsx("input",{value:c[n.name]??"",onChange:C=>k(R=>({...R,[n.name]:C.target.value})),onKeyDown:C=>{C.key==="Enter"&&N(n.name)},placeholder:F(t,"messagePlaceholder"),className:"h-8 min-w-0 flex-1 rounded-md border border-[hsl(var(--deck-hairline))] bg-[hsl(var(--deck-surface))] px-2 font-mono text-[10.5px] outline-none focus:border-emerald-500"}),e.jsx("button",{type:"button",onClick:()=>void N(n.name),disabled:!((w=c[n.name])!=null&&w.trim())||l===n.name,"aria-label":F(t,"send"),title:F(t,"send"),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-emerald-700 text-white hover:bg-emerald-800 disabled:opacity-40 dark:bg-emerald-600",children:e.jsx(Ke,{className:"h-3.5 w-3.5"})})]})]})]},n.name)})]})}function Ps(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 a=s.content.filter(o=>o.type==="text").map(o=>o.text).join(`
18
18
  `),r=s.content.filter(o=>o.type==="image_url").map((o,i)=>{var b;const u=((b=o.image_url.url.match(/^data:([^;,]+)[;,]/))==null?void 0:b[1])??"application/octet-stream";return{id:`recovery-${s.id}-${i}`,name:`attachment-${i+1}`,mimeType:u,dataUrl:o.image_url.url}});return{content:a,attachments:r}}function zs(){var H;const t=D(),s=y(g=>g.messages),a=y(g=>g.currentSessionRef),r=y(g=>g.isStreaming),o=y(g=>g.isStopping),i=y(g=>g.sessionEventConnectionState),u=y(g=>g.pendingSteeringCount),b=y(g=>g.pendingInputDelivery),d=y(g=>g.recoveredSteeringCount),c=y(g=>g.isLoading),k=y(g=>g.error),l=y(g=>g.errorContext),p=y(g=>g.sessions),x=y(g=>g.sendMessage),j=y(g=>g.abortSession),S=y(g=>g.retryTask),h=y(g=>g.retryingTaskKeys),N=je(g=>g.openSettings),v=y(g=>g.reconnectSessionEvents),n=y(g=>g.clearError),[m,E]=f.useState(null),w=a?p.find(g=>g.sessionId===a.sessionId&&g.projectPath===a.projectPath):void 0,C=!!k&&((l==null?void 0:l.kind)==="navigation"||!(l!=null&&l.sessionRef)||Be(l.sessionRef,a)),R=(l==null?void 0:l.failureCode)??((H=w==null?void 0:w.taskFailure)==null?void 0:H.code),K=(l==null?void 0:l.kind)==="execution"&&R?t(At(R)):k==="queue_full"?t("chat.error.queueFull"):k==="turn_unavailable"||k==="turn_active"?t("chat.error.turnChanged"):k,O=i==="connecting"||i==="reconnecting",B=r&&i!=="connected",V=a?`session:${X(a)}`:"session:temporary",L=f.useMemo(()=>Ps(s),[s]),T=a?X(a):"temporary-session",P=!!(a&&(w!=null&&w.taskRetryAvailable)&&(!R||Rt(R)))&&((l==null?void 0:l.kind)==="execution"||(l==null?void 0:l.kind)==="task_action"),Q=(l==null?void 0:l.kind)==="execution"&&(R==="authentication"||R==="permission"||R==="model_unavailable"),G=a?h.includes(X(a)):!1;f.useEffect(()=>{E(null)},[T]);const te=async g=>x({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(_=>({type:"image",content:_.dataUrl,mimeType:_.mimeType,name:_.name}))}),se=()=>j(),A=async()=>{if(Q){n(),N("models");return}if(P&&a){n(),await S(a).catch(()=>{});return}if((l==null?void 0:l.kind)==="execution"&&L){E({...L,revision:Date.now()}),n();return}n(),requestAnimationFrame(()=>rt())},U=P?t(G?"chat.error.action.retryingTask":"chat.error.action.retryTask"):Q?t("chat.error.action.checkModels"):(l==null?void 0:l.kind)==="execution"&&L?t("chat.error.action.editResend"):(l==null?void 0:l.kind)==="submission"?t("chat.error.action.returnDraft"):null;return e.jsxs("div",{className:"flex h-full flex-col bg-[hsl(var(--deck-canvas))]",children:[C&&e.jsxs("div",{role:"alert","data-blade-session-error":!0,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(ye,{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((l==null?void 0:l.kind)==="submission"?"chat.error.title.submission":(l==null?void 0:l.kind)==="execution"?"chat.error.title.execution":(l==null?void 0:l.kind)==="navigation"?"chat.error.title.navigation":"chat.error.title.generic")})," ",K]}),U&&e.jsxs("button",{type:"button",onClick:()=>void A(),disabled:G,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:[P?G?e.jsx($,{className:"h-3 w-3 animate-spin"}):e.jsx(ie,{className:"h-3 w-3"}):e.jsx(Ge,{className:"h-3 w-3"}),U]}),e.jsx("button",{type:"button",onClick:n,"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:"✕"})]}),(O||i==="offline")&&e.jsxs("div",{role:i==="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:[O?e.jsx($,{className:"h-3.5 w-3.5 shrink-0 animate-spin"}):e.jsx(Nt,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:t(O?"chat.connection.reconnecting":"chat.connection.offline")}),i==="offline"&&e.jsxs("button",{type:"button",onClick:()=>void v().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(St,{className:"h-3 w-3"}),t("chat.connection.retry")]})]}),e.jsx(Bt,{}),e.jsx(Ns,{messages:s,isLoading:c},a?X(a):"temporary-session"),e.jsx(_s,{}),e.jsx(Rs,{}),e.jsx(Ts,{}),e.jsx(Es,{}),e.jsx(at,{draftKey:V,draft:m==null?void 0:m.content,draftAttachments:m==null?void 0:m.attachments,draftRevision:m==null?void 0:m.revision,onSend:te,onAbort:se,disabled:c||B,isStreaming:r,isStopping:o,pendingSteeringCount:u,pendingInputDelivery:b,recoveredSteeringCount:d,workspacePath:a==null?void 0:a.projectPath},V),e.jsx(Is,{})]})}export{zs as ChatView};