@surething/cockpit 1.0.258 → 1.0.259
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next-prod/BUILD_ID +1 -1
- package/.next-prod/app-path-routes-manifest.json +3 -3
- package/.next-prod/build-manifest.json +2 -2
- package/.next-prod/cockpit-build.json +1 -1
- package/.next-prod/prerender-manifest.json +3 -3
- package/.next-prod/server/app/_global-error/page.js.nft.json +1 -1
- package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_global-error.html +1 -1
- package/.next-prod/server/app/_global-error.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found/page.js +1 -1
- package/.next-prod/server/app/_not-found/page.js.nft.json +1 -1
- package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_not-found.html +2 -2
- package/.next-prod/server/app/_not-found.rsc +3 -3
- package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +3 -3
- package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +3 -3
- package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next-prod/server/app/api/agent/test/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/bash/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/codex/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/deepseek/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/glm/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/kimi/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/ollama/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/chat/stop/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/claude-stats/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/commands/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/comments/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/columns/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/export/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/query/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/db/schemas/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/deepseek/balance/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/deepseek/credentials/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/deepseek/models/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/dev/spans/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/extension/version/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/file/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/blame/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/clipboard/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/copy/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/delete/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/expanded/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/index/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/init/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/paste/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/read/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/readdir/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/recent/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/save/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/search/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/stat/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/files/text/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/branch-diff/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/branches/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/commit-diff/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/commits/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/current-branch/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/diff/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/discard/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/stage/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/status/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/unstage/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/git/worktree/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/glm/credentials/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/glm/models/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/glm/usage/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/global-state/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/health/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/html-apps/[id]/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/html-apps/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/jupyter/load/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/jupyter/save/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/jupyter/shutdown/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/kimi/credentials/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/kimi/models/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/kimi/usage/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/definition/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/hover/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/references/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/status/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/lsp/warmup/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/columns/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/export/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/query/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/mysql/schemas/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/query/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/neo4j/schema/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/note/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/ollama/config/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/ollama/models/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/ollama/start/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/open-cursor/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/open-vscode/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/pick-folder/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/pinned-sessions/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/project-settings/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/project-state/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/affected/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/callees/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/callers/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/coedit/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/context/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/file/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/file-functions/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/impact/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/related/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/risk/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projectGraph/search/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/projects/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/prompts/config/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/push/public-key/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/push/subscribe/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/push/unsubscribe/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/command/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/connect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/delete/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/disconnect/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/get/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/keys/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/redis/set/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/[id]/comments/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/[id]/replies/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/[id]/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/identify/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/order/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/share-info/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/review/users/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/scheduled-tasks/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/services/config/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/services/scripts/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/fork/route.js +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/fork/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/session/[sessionId]/history/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/session-by-path/route.js +1 -1
- package/.next-prod/server/app/api/session-by-path/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/sessions/projects/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/sessions/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/settings/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/skills/[id]/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/skills/content/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/skills/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/snapshots/diff/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/snapshots/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/aliases/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/autocomplete/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/bubble-order/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/env/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/terminal/history/route.js.nft.json +1 -1
- package/.next-prod/server/app/api/version/route.js.nft.json +1 -1
- package/.next-prod/server/app/apps/[...path]/route.js.nft.json +1 -1
- package/.next-prod/server/app/favicon.ico/route.js.nft.json +1 -1
- package/.next-prod/server/app/m/page.js +1 -1
- package/.next-prod/server/app/m/page.js.nft.json +1 -1
- package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/manifest.webmanifest/route.js.nft.json +1 -1
- package/.next-prod/server/app/page.js +1 -1
- package/.next-prod/server/app/page.js.nft.json +1 -1
- package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/project/page.js +1 -1
- package/.next-prod/server/app/project/page.js.nft.json +1 -1
- package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/review/[id]/page.js +1 -1
- package/.next-prod/server/app/review/[id]/page.js.nft.json +1 -1
- package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app-paths-manifest.json +3 -3
- package/.next-prod/server/chunks/151.js +1 -0
- package/.next-prod/server/chunks/3286.js +42 -24
- package/.next-prod/server/chunks/5750.js +6 -5
- package/.next-prod/server/chunks/6495.js +1 -1
- package/.next-prod/server/chunks/6548.js +1 -1
- package/.next-prod/server/chunks/{8557.js → 9004.js} +5 -5
- package/.next-prod/server/middleware-build-manifest.js +1 -1
- package/.next-prod/server/pages/404.html +2 -2
- package/.next-prod/server/pages/500.html +1 -1
- package/.next-prod/server/server-reference-manifest.json +1 -1
- package/.next-prod/static/chunks/{1372-cc9afa045dc4eb5e.js → 1372-d94b8f9ed5cd2713.js} +1 -1
- package/.next-prod/static/chunks/{9592-a657fb9eb995b64d.js → 2653-3f8bfa49727caa72.js} +4 -4
- package/.next-prod/static/chunks/6784-ec12c61b77c64dc0.js +381 -0
- package/.next-prod/static/chunks/7482-3ffe7da02d3e7f45.js +26 -0
- package/.next-prod/static/chunks/app/{layout-bec1cf218bc88d81.js → layout-fef0d44c94fcb415.js} +1 -1
- package/.next-prod/static/chunks/app/{page-5e6dbc9731415743.js → page-824be00a023f34d7.js} +1 -1
- package/.next-prod/static/chunks/app/project/{page-5e6dbc9731415743.js → page-824be00a023f34d7.js} +1 -1
- package/.next-prod/static/css/a82580b2376d7cae.css +1 -0
- package/.next-prod/trace +14 -14
- package/.next-prod/trace-build +1 -1
- package/dist/scheduledTasks.mjs +44 -24
- package/package.json +1 -1
- package/.next-prod/static/chunks/6784-500e233d3e8f6b41.js +0 -381
- package/.next-prod/static/chunks/7482-8478af06d5aa0972.js +0 -25
- package/.next-prod/static/css/2334aed02a409f57.css +0 -1
- /package/.next-prod/static/{ZFNy0XuBWptMqEQGi7GTy → F9dxCcbBY_bNPY4fxWaWe}/_buildManifest.js +0 -0
- /package/.next-prod/static/{ZFNy0XuBWptMqEQGi7GTy → F9dxCcbBY_bNPY4fxWaWe}/_ssgManifest.js +0 -0
|
@@ -12,4 +12,4 @@ ${t}`:e+t:t:e}function s(e,t,n=!1){let r=e||[];if(!t)return r;let l=r[r.length-1
|
|
|
12
12
|
`:"")+(e.status?`<status>${e.status}</status>
|
|
13
13
|
`:"")+(e.summary?`<summary>${e.summary}</summary>
|
|
14
14
|
`:"")+(e.output_file?`<output-file>${e.output_file}</output-file>
|
|
15
|
-
`:"")+"</task-notification>";t(t=>[...t,{id:n,role:"system",content:e.summary||"",systemEvent:{kind:"task-notification",...e.status?{status:e.status}:{},detail:r}}])}return}if("user"===e.type&&e._human){let n=e.message?.content,r="string"==typeof n?n:Array.isArray(n)?n.map(e=>e?.text||"").join(""):"",s="string"==typeof e._turnId?e._turnId:null,l="number"==typeof e._ts?e._ts:null,o=s?`live-user-${s}`:`live-user-${++c.current}`;t(e=>{if(s&&e.some(e=>e.id===o))return e;for(let t=e.length-1;t>=0;t--){if("user"!==e[t].role)continue;let n=e[t].timestamp?Date.parse(e[t].timestamp):NaN;if(null===l||Number.isNaN(n)){if(e[t].content===r)return e}else if(n>=l)return e;break}return[...e,{id:o,role:"user",content:r}]});return}"result"===e.type&&(d.current=!1);let n=i.current??u();t(t=>(0,l.F)(t,e,{engine:o,assistantId:n}))};(0,s.h)({url:e?`/ws/session-stream?sessionId=${encodeURIComponent(e)}`:"/ws/session-stream",enabled:n&&!!e,onMessage:e=>{if("run-snapshot"===e.type&&Array.isArray(e.events)){if("running"!==e.status)return void a?.onRunningChange?.(!1);let n=e.events.find(e=>e?.type==="user"&&e?._human),r=n?.message?.content,s="string"==typeof r?r:"",l=new Set,o=new Set;for(let t of e.events){let e=t?.uuid;if("string"==typeof e&&l.add(e),t?.type==="assistant"&&Array.isArray(t.message?.content))for(let e of t.message.content)e?.name&&"string"==typeof e.id&&o.add(e.id)}let u="number"==typeof e.startedAt?e.startedAt:null;for(let n of(t(e=>{let t=e.filter(e=>!("string"==typeof e.id&&e.id.startsWith("live-"))),n=t[t.length-1],r=n?.timestamp?Date.parse(n.timestamp):NaN;if(null!==u&&!Number.isNaN(r)){let e=t.length;for(;e>0;){let n=t[e-1],r=n.timestamp?Date.parse(n.timestamp):NaN;if(!Number.isNaN(r)&&r>=u)e--;else break}return e<t.length?t.slice(0,e):t}if(!s)return t;let a=-1;for(let e=t.length-1;e>=0;e--)if("user"===t[e].role){t[e].content===s&&(a=e);break}return -1===a?t:t.slice(a+1).every(e=>"assistant"===e.role&&("string"==typeof e.id&&l.has(e.id)||!!e.toolCalls?.length&&e.toolCalls.every(e=>o.has(e.id))))?t.slice(0,a):t}),i.current=null,c.current=0,d.current=!1,e.events))h(n);a?.onRunningChange?.(!0)}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type){a?.onRunningChange?.(!1),a?.onComplete?.();return}h(e.message),a?.onRunningChange?.(!0)}else"run-idle"===e.type&&a?.onRunningChange?.(!1)}})}},67589:(e,t,n)=>{n.d(t,{z:()=>a,m:()=>c});var r=n(12115),s=n(49433),l=n(86957),o=n(82680);let a=e=>s.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new o.uV({message:"session-by-path failed",cause:e})}),i=new Map;function c(e,t,n,{cwd:d,initialSessionId:u,onSessionId:h,onTitleChange:m,onTokenUsage:f,liveRunningRef:x}){let[p,g]=(0,r.useState)(!1),[b,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1),[k,j]=(0,r.useState)(void 0),[C,N]=(0,r.useState)(0),[S,L]=(0,r.useState)(null),[E,M]=(0,r.useState)(null),[R,T]=(0,r.useState)(null),$=(0,r.useRef)(m);$.current=m;let P=(0,r.useRef)(f);P.current=f;let I=(0,r.useRef)(void 0),A=(0,r.useRef)(0),_=(0,r.useCallback)(async(e,n,r=!1,s,o,c=!1)=>{if(r){let e=Date.now();if(!c&&e-A.current<5e3)return;A.current=e}let d=(e,r)=>{var s;e.fingerprint&&(I.current=e.fingerprint),void 0!==e.totalTurns&&N(e.totalTurns),void 0!==e.hasMore&&w(e.hasMore),e.messages&&e.messages.length>0&&(r?t(t=>(function(e,t){if(0===t.length)return e;let n=0;if(e.length>0&&e[0].id!==t[0].id){n=-1;for(let r=e.length-1;r>=0;r--)if(e[r].id===t[0].id){n=r;break}}if(n<0)return t;let r=e.slice(n),s=0;for(let e=0;e<Math.min(r.length,t.length)&&r[e].id===t[e].id&&r[e].content===t[e].content;e++)s=e+1;return s===r.length&&s===t.length?e:s===r.length&&s<t.length?[...e,...t.slice(s)]:[...e.slice(0,n),...r.slice(0,s),...t.slice(s)]})(t,e.messages)):x?.current||t(e.messages),L(n)),e.sessionId&&h(e.sessionId),e.engine&&M(e.engine),e.mode&&T((s=e.mode)?"builtin"===s?"builtin":"sdk":null),e.title&&$.current?.(e.title),e.usage&&P.current?.({inputTokens:e.usage.input_tokens||0,outputTokens:e.usage.output_tokens||0,cacheCreationInputTokens:e.usage.cache_creation_input_tokens||0,cacheReadInputTokens:e.usage.cache_read_input_tokens||0,totalCostUsd:0})},u=`${e}::${n}`,m=!r&&void 0===o,f=m?i.get(u):void 0;r||(f?d(f.data,!1):g(!0));try{let t={cwd:e,sessionId:n,limit:s,beforeTurnIndex:o};r&&I.current?t.ifFingerprint=I.current:f&&(t.ifFingerprint=f.fingerprint);let c=await l.t4.runPromiseExit(a(t));if("Success"===c._tag&&c.value){let e=c.value;if(e.notModified)return;if(d(e,r),m&&e.fingerprint&&e.messages&&e.messages.length>0&&(i.delete(u),i.set(u,{data:e,fingerprint:e.fingerprint}),i.size>20)){let e=i.keys().next().value;void 0!==e&&i.delete(e)}}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{r||g(!1)}},[t,h]),F=(0,r.useCallback)(async()=>{if(d&&n&&!b&&y){v(!0);try{let r=void 0!==k?k:C-Math.ceil(e.filter(e=>"user"===e.role).length),s=await l.t4.runPromiseExit(a({cwd:d,sessionId:n,limit:10,beforeTurnIndex:r>0?r:void 0}));if("Success"===s._tag&&s.value){let e=s.value;if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let s=e.messages.filter(e=>"user"===e.role).length;j(r-s),L(n)}void 0!==e.hasMore&&w(e.hasMore),e.fingerprint&&(I.current=e.fingerprint)}else"Failure"===s._tag&&console.error("Failed to load more history:",s.cause)}finally{v(!1)}}},[d,n,b,y,k,C,e,t]),D=(0,r.useCallback)(async e=>{g(!0);let n=s.tryPromise({try:async()=>{let t=await fetch(`/api/session/${e}/history`);return t.ok?await t.json():null},catch:e=>new o.uV({message:"load session history failed",cause:e})}),r=await l.t4.runPromiseExit(n);"Success"===r._tag&&r.value?.messages&&r.value.messages.length>0?(t(r.value.messages),L(e)):"Failure"===r._tag&&console.error("Failed to load history:",r.cause),g(!1)},[t]);return(0,r.useEffect)(()=>{d&&u&&_(d,u,!1,10)},[]),{isLoadingHistory:p,isLoadingMore:b,hasMoreHistory:y,loadMoreHistory:F,loadHistory:D,loadHistoryByCwdAndSessionId:_,loadedSessionId:S,loadedEngine:E,loadedMode:R}}},70188:(e,t,n)=>{n.d(t,{Ee:()=>h,SU:()=>c,ft:()=>u,iN:()=>d});var r=n(95155),s=n(12115),l=n(79114),o=n(47650),a=n(34075);let i=(0,s.createContext)(null);function c({container:e,children:t}){return(0,r.jsx)(i.Provider,{value:e,children:t})}function d(){return(0,s.useContext)(i)}function u({x:e,y:t,path:n,cwd:c,isDirectory:d,onClose:h,onCreateFile:m,onDelete:f,onRefresh:x,onCopyFile:p,onPaste:g,onExplain:b,explainDisabled:v}){let{t:y}=(0,l.Bd)(),w=(0,s.useRef)(null),k=(0,s.useContext)(i),j=n.split("/").pop()||n,C=`${c}/${n}`,N=n.includes("/")?n.substring(0,n.lastIndexOf("/")):"",S=N?`${c}/${N}`:c,L=d?n:N,E=d?C:S;(0,s.useEffect)(()=>{let e=e=>{w.current&&!w.current.contains(e.target)&&h()},t=e=>{"Escape"===e.key&&h()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[h]);let[M,R]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(w.current&&k){let n=k.getBoundingClientRect(),r=w.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s=Math.min(s,n.width-r.width-8),l=Math.min(l,n.height-r.height-8),R({x:s=Math.max(8,s),y:l=Math.max(8,l)})}else if(w.current){let n=w.current.getBoundingClientRect();R({x:Math.max(8,Math.min(e,window.innerWidth-n.width-8)),y:Math.max(8,Math.min(t,window.innerHeight-n.height-8))})}},[e,t,k]);let T=(0,s.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(e),(0,a.oR)(y("toast.copiedName",{name:t}),"success")}catch{(0,a.oR)(y("toast.copyFailed"),"error")}h()},[h,y]),$=d?n:N,P=!!b&&!d,I=[{label:y("fileContextMenu.copyRelativePath"),value:n},{label:y("fileContextMenu.copyAbsolutePath"),value:C},{label:y("fileContextMenu.copyRelativeDirPath"),value:L||"."},{label:y("fileContextMenu.copyAbsoluteDirPath"),value:E},{label:d?y("fileContextMenu.copyFolderName"):y("fileContextMenu.copyFileName"),value:j}],A=(0,r.jsxs)("div",{ref:w,className:"absolute z-[200] bg-card border border-border rounded-lg shadow-lg py-1 w-fit whitespace-nowrap",style:{left:M.x,top:M.y},children:[P&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent",disabled:v,title:v?y("comments.aiResponding"):void 0,onClick:()=>{h(),b(n)},children:y("explain.action")}),P&&(0,r.jsx)("div",{className:"my-1 border-t border-border"}),m&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{h(),m($)},children:y("fileContextMenu.createFile")}),p&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{h(),p(n)},children:d?y("fileContextMenu.copyFolder"):y("fileContextMenu.copyFile")}),g&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{h(),g($)},children:y("fileContextMenu.pasteHere")}),f&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-destructive hover:bg-accent transition-colors",onClick:()=>{h(),f(n,d,j)},children:d?y("fileContextMenu.deleteFolder"):y("fileContextMenu.deleteFile")}),!!(m||p||g||f)&&(0,r.jsx)("div",{className:"my-1 border-t border-border"}),I.map((e,t)=>(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>T(e.value,e.label),children:e.label},t))]});return k?(0,o.createPortal)(A,k):A}function h(){let[e,t]=(0,s.useState)(null);return{contextMenu:e,showContextMenu:(0,s.useCallback)((e,n,r)=>{e.preventDefault(),e.stopPropagation(),t({x:e.clientX,y:e.clientY,path:n,isDirectory:r})},[]),hideContextMenu:(0,s.useCallback)(()=>{t(null)},[])}}},73013:(e,t,n)=>{n.d(t,{M:()=>ef});var r=n(95155),s=n(12115),l=n(83897),o=n(64428),a=n(34075),i=n(54731),c=n(1709),d=n(12651),u=n(81165),h=n(16950),m=n(11019),f=n(12612),x=n(79114),p=n(86957),g=n(67589);function b({cwd:e,sessionId:t,toolCall:n,workflowRef:l,onClose:a}){let{t:i}=(0,x.Bd)(),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(null),[m,f]=(0,s.useState)(!1),v=(0,s.useRef)(void 0),y=l?!!l.running:!n?.result,w=(0,s.useCallback)(async()=>{let r=await p.t4.runPromiseExit((0,g.z)({cwd:e,sessionId:t,...l?{workflowId:l.runId,workflowAgentId:l.agentId}:{toolUseId:n?.id},ifFingerprint:v.current}));if(f(!0),"Success"!==r._tag||!r.value)return;let s=r.value;s.fingerprint&&(v.current=s.fingerprint),!s.notModified&&(s.messages&&d(s.messages),s.subagent&&h(s.subagent))},[e,t,n?.id,l?.runId,l?.agentId]);(0,s.useEffect)(()=>{if(w(),!y)return;let e=setInterval(w,5e3);return()=>clearInterval(e)},[y,w]);let k=(0,s.useRef)(null),j=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let e=k.current;e&&j.current&&(e.scrollTop=e.scrollHeight)},[c]);let C="string"==typeof n?.input?.description?n.input.description:"",N=l?l.label||"":[u?.agentType,C].filter(Boolean).join(" \xb7 ");return(0,r.jsx)(o.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:a,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-base",children:"\uD83E\uDD16"}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:i("chat.subagent")}),N&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0","data-tooltip":N,children:N}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[y&&(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("button",{onClick:a,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{ref:k,onScroll:()=>{let e=k.current;e&&(j.current=e.scrollTop+e.clientHeight>=e.scrollHeight-40)},className:"flex-1 overflow-y-auto px-4 py-3",children:null===c?(0,r.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:i(m?"chat.subagentEmpty":"common.loading")}):c.map(t=>(0,r.jsx)(ea,{message:t,cwd:e},t.id))})]})})})}function v(e){return e?e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e):"0"}function y(e){if(!e)return"–";let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return`${n}m${t%60}s`}let w={done:"text-green-9",running:"text-brand",queued:"text-muted-foreground",error:"text-red-9",failed:"text-red-9"};function k({cwd:e,sessionId:t,runId:n,isRunning:l,onClose:a}){let{t:i}=(0,x.Bd)(),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(!1),[m,f]=(0,s.useState)(null),w=(0,s.useRef)(void 0),C=l||null!=c&&"completed"!==c.status&&"failed"!==c.status,N=(0,s.useCallback)(async()=>{let r=await p.t4.runPromiseExit((0,g.z)({cwd:e,sessionId:t,workflowId:n,ifFingerprint:w.current}));if(h(!0),"Success"!==r._tag||!r.value)return;let s=r.value;s.fingerprint&&(w.current=s.fingerprint),!s.notModified&&s.workflow&&d(s.workflow)},[e,t,n]);(0,s.useEffect)(()=>{if(N(),!C)return;let e=setInterval(N,5e3);return()=>clearInterval(e)},[C,N]);let S=[];if(c?.agents){let e=new Map;for(let t of c.agents){let n=t.phaseTitle||i("chat.workflowUngrouped");e.has(n)||e.set(n,[]),e.get(n).push(t)}for(let[t,n]of e)S.push({title:t,agents:n})}let L=c?[c.workflowName,c.status,`${c.agentCount??c.agents?.length??0} ${i("chat.workflowAgents")}`,`${v(c.totalTokens)} tok`,y(c.durationMs)].filter(Boolean).join(" \xb7 "):"";return(0,r.jsxs)(o.ZL,{children:[(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:a,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-base",children:"\uD83E\uDDE9"}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:i("chat.workflowRun")}),L&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0","data-tooltip":L,children:L}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[C&&(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("button",{onClick:a,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:null===c?(0,r.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:i(u?"chat.workflowEmpty":"common.loading")}):(0,r.jsxs)(r.Fragment,{children:[c.summary&&(0,r.jsx)("div",{className:"mb-3 text-xs text-muted-foreground whitespace-pre-wrap",children:c.summary}),S.map(e=>(0,r.jsxs)(s.Fragment,{children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-foreground/80 mt-3 mb-1 sticky top-0 bg-card py-1",children:e.title}),e.agents.map(e=>(0,r.jsx)(j,{agent:e,onOpen:()=>e.agentId&&f({runId:n,agentId:e.agentId,label:e.label,running:"done"!==e.state&&C})},`${e.index}-${e.agentId}`))]},e.title))]})})]})}),m&&(0,r.jsx)(b,{cwd:e,sessionId:t,workflowRef:m,onClose:()=>f(null)})]})}function j({agent:e,onOpen:t}){let{t:n}=(0,x.Bd)(),[l,o]=(0,s.useState)(!1),a=e.state&&w[e.state]||"text-muted-foreground",i=e.resultPreview||e.promptPreview||"";return(0,r.jsxs)("div",{className:"border border-border rounded-md mb-1 bg-secondary/50",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5",children:[(0,r.jsx)("button",{onClick:()=>o(e=>!e),className:"text-slate-9 text-xs flex-shrink-0",title:n(l?"chat.collapse":"chat.expand"),children:l?"▲":"▼"}),(0,r.jsx)("span",{className:"text-xs text-foreground truncate flex-1 min-w-0","data-tooltip":e.label||"",children:e.label||e.agentId}),(0,r.jsx)("span",{className:`text-[10px] flex-shrink-0 ${a}`,children:e.state}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[v(e.tokens)," tok \xb7 ",y(e.durationMs)]}),e.agentId&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:t,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&t()},className:"text-xs text-brand hover:text-teal-10 cursor-pointer flex-shrink-0",title:n("chat.subagentViewTitle"),children:n("chat.workflowViewAgent")})]}),l&&i&&(0,r.jsx)("pre",{className:"text-[11px] bg-secondary px-2 py-1.5 rounded-b overflow-x-auto max-h-32 overflow-y-auto text-muted-foreground whitespace-pre-wrap border-t border-border",children:i})]})}var C=n(60938),N=n(53377),S=n(38408),L=n(13219),E=n(47176),M=n(97251),R=n(34582),T=n(56045),$=n(50860),P=n(47215);function I({filePath:e}){let[t,n]=(0,s.useState)(null),[l,o]=(0,s.useState)(!0),[a,i]=(0,s.useState)(null),c=(0,s.useRef)(!1),d=(0,P.e$)(e),u=(0,P.u)(e);return((0,s.useEffect)(()=>{u?o(!1):c.current||(c.current=!0,(async()=>{o(!0),i(null);let t=await p.t4.runPromiseExit((0,C.nM)(e));if("Success"===t._tag)n(t.value.content??null);else{let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause;i(n instanceof Error?n.message:"Failed to load file")}o(!1),c.current=!1})())},[e,u]),a)?(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("div",{className:"text-xs text-red-11",children:a})}):l?(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:"Loading..."})}):(0,P.u)(e)?(0,r.jsx)($.I,{absPath:e,className:"flex items-center justify-center h-full overflow-auto",imgClassName:"max-w-full max-h-full object-contain",alt:e.split("/").pop()||"image"}):t?d?(0,r.jsx)(_,{content:t,filePath:e}):(0,r.jsx)(S.Cv,{content:t,filePath:e,showLineNumbers:!0,showSearch:!0,className:"h-full"}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:"No content"})})}let A=[M.W];function _({content:e,filePath:t}){let n=(0,s.useRef)(null),l=(0,s.useMemo)(()=>(0,R.J4)(t),[t]);return(0,r.jsxs)("div",{className:"h-full flex",children:[(0,r.jsx)(E.l,{content:e,containerRef:n}),(0,r.jsx)("div",{ref:n,className:"flex-1 overflow-auto p-4",children:(0,r.jsx)(L.T,{content:e,basePath:l,rehypePlugins:A})})]})}function F({title:e,content:t,toolName:n,onClose:l}){let{t:i}=(0,x.Bd)(),c=(0,P.jU)(t),d=(0,P.zs)(t),u=(0,P.oK)(t),h=!!d,m=!!u,[f,p]=(0,s.useState)(("Read"===n||"Write"===n)&&m?"file":h?"diff-unified":c?"readable":"json"),g=(0,s.useRef)(null),b=(0,T.o)(g);(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&"readable"===f&&c){e.preventDefault(),b.open();return}if("Escape"===e.key){if(b.isVisible)return void b.close();document.activeElement instanceof HTMLElement&&document.activeElement.blur(),l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[l,f,c,b]);let v=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:l,children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full max-w-[90%] h-full md:h-[90vh] rounded-none md:rounded-lg flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:e}),u&&(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(u),(0,a.oR)(i("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.copyAbsPath"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[c&&(0,r.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[h&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:()=>p("diff-split"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-split"===f?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.sideBySide"),children:"Split"}),(0,r.jsx)("button",{onClick:()=>p("diff-unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-unified"===f?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.unified"),children:"Unified"})]}),m&&(0,r.jsx)("button",{onClick:()=>p("file"),className:`px-2 py-1 text-xs rounded transition-colors ${"file"===f?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.previewFile"),children:"File"}),(0,r.jsx)("button",{onClick:()=>p("readable"),className:`px-2 py-1 text-xs rounded transition-colors ${"readable"===f?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("common.readable")}),(0,r.jsx)("button",{onClick:()=>p("json"),className:`px-2 py-1 text-xs rounded transition-colors ${"json"===f?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"JSON"})]}),(0,r.jsx)("button",{onClick:l,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-auto p-4",children:"file"===f&&u?(0,r.jsx)(I,{filePath:u}):"diff-unified"===f&&d?(0,r.jsx)(N.xU,{oldContent:d.old_string,newContent:d.new_string,filePath:d.file_path}):"diff-split"===f&&d?(0,r.jsx)(N.xZ,{oldContent:d.old_string,newContent:d.new_string,filePath:d.file_path}):"readable"===f&&c?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(T._,{search:b}),(0,r.jsx)("pre",{ref:g,className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:(0,P.xb)(t)})]}):(0,r.jsx)("pre",{className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:c?(0,P.C6)(t):t})})]})});return(0,r.jsx)(o.ZL,{children:v})}let D={Read:"\uD83D\uDCC4",Write:"✏️",Edit:"\uD83D\uDCDD",ApplyPatch:"\uD83E\uDDE9",Bash:"\uD83D\uDCBB",Glob:"\uD83D\uDD0D",Grep:"\uD83D\uDD0E",WebFetch:"\uD83C\uDF10",WebSearch:"\uD83D\uDD0D",Workflow:"\uD83E\uDDE9",Skill:"\uD83D\uDEE0️"};function B(e){return"object"==typeof e&&null!==e}function W({toolCall:e,cwd:t,sessionId:n}){var l;let{t:o}=(0,x.Bd)(),[i,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)(null),[h,m]=(0,s.useState)(!1),[f,p]=(0,s.useState)(!1),g=D[e.name]||"\uD83D\uDD27",v="Agent"===e.name||"Task"===e.name,y=v&&!!t&&!!n,w="Workflow"===e.name,j=w&&(l=e.result)?l.match(/subagents\/workflows\/(wf_[A-Za-z0-9_-]+)/)?.[1]??null:null,C=w&&!!j&&!!t&&!!n,N="Skill"===e.name,S="ApplyPatch"===e.name||v||w||N,L=e=>{if(t&&e.startsWith(t)){let n=e.slice(t.length);return n.startsWith("/")?n.slice(1):n}let n=e.split("/");return n.length>2?".../"+n.slice(-2).join("/"):e},E=(()=>{let t=e.input;if("Bash"===e.name&&t.command&&"string"==typeof t.command)return t.command;if("ApplyPatch"===e.name&&Array.isArray(t.changes)){let e=t.changes.filter(B).flatMap(e=>{let t="string"==typeof e.path?e.path:"";if(!t)return[];let n="string"==typeof e.kind&&e.kind?e.kind:"update";return`${n} ${L(t)}`});if(e.length>0)return e.join(" \xb7 ")}if(v&&t.description&&"string"==typeof t.description)return t.description;if(w){let e=["string"==typeof t.name?t.name:"","string"==typeof t.args?t.args:"string"==typeof t.resumeFromRunId?t.resumeFromRunId:""].filter(Boolean).join(" \xb7 ");if(e)return e}if(N&&"string"==typeof t.skill){let e="string"==typeof t.args?t.args:"";return[t.skill,e].filter(Boolean).join(" \xb7 ")}return"Glob"===e.name&&t.pattern&&"string"==typeof t.pattern||"Grep"===e.name&&t.pattern&&"string"==typeof t.pattern?t.pattern:"ToolSearch"===e.name&&t.query&&"string"==typeof t.query?t.query:"TaskCreate"===e.name&&t.subject&&"string"==typeof t.subject?t.subject:t.file_path&&"string"==typeof t.file_path?t.file_path:t.path&&"string"==typeof t.path?t.path:null})(),M="Glob"===e.name||"Grep"===e.name||"Bash"===e.name||"ApplyPatch"===e.name||v||w||N,R=E?M?E:L(E):null,T=t=>{let n="input"===t?o("toolCall.inputParams"):o("toolCall.resultLabel"),r="input"===t?JSON.stringify(e.input,null,2):"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2);u({title:`${e.name}${R?` ${R}`:""} - ${n}`,content:r,toolName:e.name})};return(0,r.jsxs)("div",{className:"my-1 border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("button",{onClick:()=>c(!i),className:"w-full px-3 py-1.5 flex items-center gap-2 text-left hover:bg-accent transition-colors",children:[(0,r.jsx)("span",{className:"text-sm",children:g}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:e.name}),R&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0","data-tooltip":E||"",children:R}),!S&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),E&&(navigator.clipboard.writeText(E),(0,a.oR)(o("common.copiedPath")))},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),E&&(navigator.clipboard.writeText(E),(0,a.oR)(o("common.copiedPath"))))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0 cursor-pointer",title:o("common.copyAbsPath"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2",children:[y&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),m(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),m(!0))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:o("chat.subagentViewTitle"),children:o("chat.subagent")}),C&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),p(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),p(!0))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:o("chat.workflowViewTitle"),children:o("chat.workflowRun")}),i&&!e.isLoading&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),T("input")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),T("input"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:o("toolCall.inputParamsTitle"),children:o("toolCall.input")}),e.result&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),T("result")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),T("result"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:o("toolCall.resultTitle"),children:o("toolCall.result")})]}),e.isLoading?(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}):(0,r.jsx)("span",{className:"text-slate-9 text-xs",children:i?"▲":"▼"})]})]}),i&&(0,r.jsxs)("div",{className:"border-t border-border",children:[(0,r.jsxs)("div",{className:"px-3 py-2",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[o("toolCall.inputParams"),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:JSON.stringify(e.input,null,2)})]}),e.result&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[o("toolCall.resultLabel"),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2)})]}),e.skillContent&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[o("toolCall.skillContent",{defaultValue:"Skill content"}),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-60 overflow-y-auto text-foreground whitespace-pre-wrap",children:e.skillContent})]})]}),d&&(0,r.jsx)(F,{title:d.title,content:d.content,toolName:d.toolName,onClose:()=>u(null)}),h&&t&&n&&(0,r.jsx)(b,{cwd:t,sessionId:n,toolCall:e,onClose:()=>m(!1)}),f&&t&&n&&j&&(0,r.jsx)(k,{cwd:t,sessionId:n,runId:j,isRunning:!!e.isLoading,onClose:()=>p(!1)})]})}var V=n(62111),O=n(56204),z=n(67635),H=n(33210),q=n(58515),U=n(36201),K=n(55804),Z=n(37618);function J(e){let t=e.input?.questions||[],n=e.input?.answers||{},r={};if(e.result)try{let t=JSON.parse(e.result);t?.answers&&(r=t.answers)}catch{}return{questions:t,answers:{...n,...r}}}function X(e,t){return`${e}-${t}`}function G({toolCalls:e,onClose:t}){let{t:n}=(0,x.Bd)(),i=(0,l.nH)(),[c,d]=(0,s.useState)({}),[u,h]=(0,s.useState)({}),[m,f]=(0,s.useState)({}),[p,g]=(0,s.useState)({});(0,s.useEffect)(()=>{let t={};e.forEach((e,n)=>{let{questions:r,answers:s}=J(e);r.forEach((e,r)=>{let l=s[e.question];if(l){let s=X(n,r);t[s]=l,e.options.some(e=>e.label===l)||(h(e=>({...e,[s]:!0})),f(e=>({...e,[s]:l})))}})}),queueMicrotask(()=>d(t))},[e]),(0,V.E)(t);let b=e.reduce((e,t)=>{let{questions:n}=J(t);return e+n.length},0),v=Object.values(p).filter(Boolean).length,y=(0,s.useCallback)((e,t)=>{d(n=>({...n,[e]:t})),h(t=>({...t,[e]:!1}))},[]),w=(0,s.useCallback)(e=>{h(t=>{let n=!t[e];if(n){let t=m[e]||"";t&&d(n=>({...n,[e]:t}))}return{...t,[e]:n}})},[m]),k=(0,s.useCallback)((e,t)=>{f(n=>({...n,[e]:t})),t&&d(n=>({...n,[e]:t}))},[]),j=(0,s.useCallback)(e=>{g(t=>({...t,[e]:!t[e]}))},[]),C=(0,s.useCallback)(()=>{let t=v>0,r=[];return e.forEach((e,s)=>{let{questions:l}=J(e);l.forEach((e,l)=>{let o=X(s,l);if(t&&!p[o])return;let a=c[o];r.push(`Q: ${e.question}`),r.push(`A: ${a||n("askQuestion.notSelected")}`),r.push("")})}),r.join("\n").trim()},[e,c,p,v,n]),N=(0,s.useCallback)(()=>{navigator.clipboard.writeText(C()),(0,a.oR)(v>0?n("toast.copiedQA",{count:v}):n("toast.copiedAllQA"))},[C,v,n]),S=(0,s.useCallback)(()=>{i?(i.sendMessage(C()),(0,a.oR)(n("toast.sentQA")),t()):(0,a.oR)(n("askQuestion.sendNoChat"))},[i,C,t,n]),L=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:n("askQuestion.title")}),(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[n("askQuestion.nQuestions",{count:b}),v>0&&` \xb7 ${n("askQuestion.checkedN",{count:v})}`]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:S,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v>0?n("askQuestion.sendChecked",{count:v}):n("askQuestion.sendAll"),children:(0,r.jsx)(O.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{onClick:N,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v>0?n("askQuestion.copyChecked",{count:v}):n("askQuestion.copyAll"),children:(0,r.jsx)(z.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)(H.A,{className:"w-5 h-5"})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-6",children:e.map((t,s)=>{let{questions:l}=J(t);return l.map((t,o)=>{let a=X(s,o),i=c[a],d=u[a]||!1,h=p[a]||!1;return(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-start gap-2",children:[(0,r.jsx)("button",{onClick:()=>j(a),className:"mt-0.5 flex-shrink-0 p-0.5 rounded hover:bg-accent transition-colors",title:n("askQuestion.checkToCopy"),children:h?(0,r.jsx)(q.A,{className:"w-4 h-4 text-brand"}):(0,r.jsx)(U.A,{className:"w-4 h-4 text-muted-foreground"})}),t.header&&(0,r.jsx)("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-brand/10 text-brand flex-shrink-0 mt-0.5",children:t.header}),(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:t.question})]}),(0,r.jsxs)("div",{className:"space-y-1 ml-7",children:[t.options.map((e,t)=>{let n=i===e.label&&!d;return(0,r.jsxs)("button",{onClick:()=>y(a,e.label),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${n?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,r.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:n?(0,r.jsx)(K.A,{className:"w-3.5 h-3.5 text-brand"}):(0,r.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("div",{className:`text-sm ${n?"text-foreground font-medium":"text-foreground"}`,children:e.label}),e.description&&(0,r.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.description})]})]},t)}),(0,r.jsxs)("button",{onClick:()=>w(a),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${d?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,r.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:d?(0,r.jsx)(K.A,{className:"w-3.5 h-3.5 text-brand"}):(0,r.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(Z.A,{className:"w-3.5 h-3.5 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:n("askQuestion.custom")})]})]}),d&&(0,r.jsx)("div",{className:"ml-6 mt-1",children:(0,r.jsx)("input",{type:"text",autoFocus:!0,value:m[a]||"",onChange:e=>k(a,e.target.value),placeholder:n("askQuestion.customPlaceholder"),className:"w-full px-3 py-1.5 text-sm bg-background border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-brand text-foreground"})})]}),(s!==e.length-1||o!==l.length-1)&&(0,r.jsx)("div",{className:"border-b border-border/50 mt-3"})]},a)})})})]})});return(0,r.jsx)(o.ZL,{children:L})}var Q=n(38987),Y=n(9573),ee=n(4055),et=n(24602),en=n(95686),er=n(83448);function es({image:e,onClose:t}){let{t:n}=(0,x.Bd)(),s=(0,r.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,r.jsx)("button",{onClick:t,className:"absolute top-4 right-4 w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",children:(0,r.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:n("chat.imagePreview"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,r.jsx)(o.ZL,{children:s})}function el({filePath:e,onClose:t}){return(0,r.jsx)(o.ZL,{children:(0,r.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,r.jsx)("button",{onClick:t,className:"absolute top-4 right-4 w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",children:(0,r.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,r.jsx)("img",{src:`/api/file?path=${encodeURIComponent(e)}&raw=true`,alt:e.split("/").pop(),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]})})}let eo=(0,s.memo)(function({text:e,isAside:t,isUser:n,isStreaming:l,onOpenFileLink:o,cwd:a}){let c=(0,s.useMemo)(()=>{if(!n&&o)return e=>{let t=function(e,t){let n;if(!e||e.startsWith("#")||/^[a-z][a-z0-9+.-]*:/i.test(e)&&!e.startsWith("file:"))return null;let r=e;try{r=decodeURIComponent(e)}catch{}r.startsWith("file://")&&(r=r.slice(7));let s=r.indexOf("#"),l=s>=0?r.slice(s+1):"",o=s>=0?r.slice(0,s):r,a=o.indexOf("?"),i=a>=0?o.slice(a+1):"";o=a>=0?o.slice(0,a):o;let c=l.match(/^L?(\d+)(?:-L?\d+)?$/i)?.[1],d=i.match(/(?:^|[&;])(?:line|L)=(\d+)(?:$|[&;])/i)?.[1],u=o.match(/:(\d+)(?::\d+)?$/),h=c||d||u?.[1];if(h&&(n=Number(h),u&&(o=o.slice(0,-u[0].length))),!(o=o.trim()))return null;if(t&&o.startsWith(t+"/"))o=o.slice(t.length+1);else{if(t&&o===t)return null;o.startsWith("/")&&(o=o.slice(1))}return o.startsWith("./")||o.startsWith("../")||o.includes("/")||/\.[A-Za-z0-9][A-Za-z0-9_-]*$/.test(o)?{path:(0,P.WU)("",o),...n&&n>0?{lineNumber:n}:{}}:null}(e,a);return!!t&&(o(t),!0)}},[a,n,o]),d=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(L.T,{content:e,isUser:n,isStreaming:l,enableMath:!1,onLinkClick:c}),l&&(0,r.jsx)("span",{className:"inline-block w-2 h-4 ml-1 bg-current animate-pulse"})]});return t?(0,r.jsxs)("div",{className:"flex gap-1.5 break-words opacity-65",children:[(0,r.jsx)(i.A,{className:"w-3 h-3 mt-[5px] shrink-0 text-muted-foreground","aria-hidden":!0}),(0,r.jsx)("div",{className:"flex-1 min-w-0",children:d})]}):(0,r.jsx)("div",{className:"break-words",children:d})}),ea=(0,s.memo)(function({message:e,cwd:t,sessionId:n,onFork:l,forkSupported:i=!0,onApprovePlan:g,isLoading:b,onContentSearch:v,onShowFileDiff:y,onOpenFileLink:w}){let k,j,C,N,{t:S}=(0,x.Bd)(),[E,M]=(0,s.useState)(null),[R,T]=(0,s.useState)(()=>1===(e.toolCalls?.length||0)),[$,I]=(0,s.useState)(!1),[A,_]=(0,s.useState)(!1),[F,D]=(0,s.useState)(!1),B="user"===e.role,V=e.images&&e.images.length>0,O=e.toolCalls?.length||0,z=!!n&&!!t&&!!l&&i,H=(0,s.useMemo)(()=>e.toolCalls?.some(e=>(0,ee.h)(e.name))||!1,[e.toolCalls]),q=(0,s.useMemo)(()=>{let t=e.parts;if(!t?.length)return e.content?[{text:e.content,isAside:!1}]:[];let n=-1;t.forEach((e,t)=>{"tool"===e.type&&(n=t)});let r=[];return t.forEach((e,t)=>{"text"===e.type&&r.push({text:e.text,isAside:t<n})}),r},[e.parts,e.content]),U=(0,s.useMemo)(()=>(0,Q.vP)([],e.toolCalls??[],t).length>0,[e.toolCalls,t]),[K,Z]=(0,s.useState)(!1),J=U||K;(0,s.useEffect)(()=>{if(!H||U||!t)return;let r=(e.toolCalls??[]).map(e=>e.id).filter(Boolean);if(0===r.length)return;let s=(e.toolCalls??[]).filter(e=>(0,ee.h)(e.name)).map(e=>e.id),l=!1,o=null,a=0,i=()=>{p.t4.runPromiseExit((0,Y.xK)(t,r,n??void 0)).then(e=>{if(l)return;let t="Success"===e._tag?e.value:[];if(t.length>0)return void Z(!0);let n=new Set(t.map(e=>e.toolId));s.some(e=>!n.has(e))&&a<2&&(a+=1,o=setTimeout(i,2e3))})};return i(),()=>{l=!0,o&&clearTimeout(o)}},[H,U,t,n,e.toolCalls]);let X=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("TodoWrite"===e.toolCalls[t].name)return e.toolCalls[t];return null},[e.toolCalls]),ea=(0,s.useMemo)(()=>e.toolCalls?e.toolCalls.filter(e=>"AskUserQuestion"===e.name):[],[e.toolCalls]),ei=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("ExitPlanMode"===e.toolCalls[t].name){let n=e.toolCalls[t].input?.plan;return"string"==typeof n&&n?n:null}return null},[e.toolCalls]),ec=(0,s.useMemo)(()=>e.toolCalls?.filter(e=>"ExitPlanMode"!==e.name)??[],[e.toolCalls]),ed=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=new Set,n=[];for(let r of e.toolCalls)if("Read"===r.name||"Edit"===r.name||"Write"===r.name){let e=r.input.file_path;e&&((0,P.e$)(e)||(0,P.aR)(e)||(0,P.u)(e))&&!t.has(e)&&(t.add(e),n.push(e))}return n},[e.toolCalls]),eu=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=[];for(let n of e.toolCalls){let e=n.input?.thought;if(e&&"string"==typeof e){let r=e.match(/PREVIOUS:\s*(.*?)\s*→\s*THIS:\s*(.*?)\s*→\s*EXPECT:\s*(.*)/i);r?t.push({previous:r[1].trim(),current:r[2].trim(),expect:r[3].trim(),raw:e,toolName:n.name}):t.push({previous:"",current:e,expect:"",raw:e,toolName:n.name})}}return t},[e.toolCalls]),[eh,em]=(0,s.useState)(null),[ef,ex]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!eh||(0,P.u)(eh))return void queueMicrotask(()=>ex(null));let e=!1;return p.t4.runPromiseExit((0,er.an)(eh)).then(t=>{e||("Success"===t._tag&&void 0!==t.value.content?ex(t.value.content):((0,a.oR)(S("toast.readFileFailed"),"error"),em(null)))}),()=>{e=!0}},[eh,S]);let ep=()=>{e.content&&(navigator.clipboard.writeText(e.content),(0,a.oR)(S("toast.copiedMessage")))},eg=()=>{z&&l(e.id,"prefix")},eb=()=>{z&&l(e.id,"single")},ev=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),l=String(t.getMinutes()).padStart(2,"0");return`${n}-${r} ${s}:${l}`})(e.timestamp);if("system"===e.role){let t=e.systemEvent,n=t?.kind==="task-notification"?"failed"===t.status?"⚠️":"stopped"===t.status?"⏹️":"\uD83D\uDD14":"ℹ️",s=t?.detail||e.content;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"flex justify-center my-2 px-2","data-role":"system",children:(0,r.jsxs)("button",{type:"button",onClick:()=>D(!0),className:"flex items-center gap-1.5 max-w-[85%] text-[11px] text-muted-foreground bg-secondary/40 border border-border/50 rounded-full px-3 py-1 hover:bg-secondary hover:text-foreground transition-colors cursor-pointer",title:S("chat.viewDetails",{defaultValue:"Click for details"}),children:[(0,r.jsx)("span",{className:"flex-shrink-0",children:n}),(0,r.jsx)("span",{className:"truncate",children:e.content})]})}),F&&(0,r.jsx)(o.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:()=>D(!1),children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full max-w-4xl max-h-[80vh] rounded-lg flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,r.jsxs)("span",{className:"text-sm text-foreground flex items-center gap-1.5",children:[(0,r.jsx)("span",{children:n}),t?.kind==="task-notification"?S("chat.taskNotification",{defaultValue:"Task notification"}):S("chat.systemNotice",{defaultValue:"Notice"})]}),(0,r.jsx)("button",{onClick:()=>D(!1),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-accent transition-colors",children:"✕"})]}),(0,r.jsx)("pre",{className:"flex-1 overflow-auto px-4 py-3 text-xs text-foreground whitespace-pre-wrap break-words",children:s})]})})})]})}return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:`flex flex-col ${B?"items-end":"items-start"} mb-4 group`,"data-role":e.role,children:[ev&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity mb-0.5 px-1",children:ev}),(0,r.jsxs)("div",{className:`flex items-start ${B?"justify-end":"justify-start"} w-full`,children:[B&&(0,r.jsxs)("div",{className:"self-start mt-2 mr-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,r.jsx)("button",{onClick:ep,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.copyMessage"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),z&&(0,r.jsx)("button",{onClick:eg,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.forkSession"),children:(0,r.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,r.jsx)("path",{d:"M12 12v3"})]})}),z&&(0,r.jsx)("button",{onClick:eb,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.excerptTurn"),children:(0,r.jsx)(c.A,{className:"w-4 h-4"})})]}),(0,r.jsxs)("div",{className:`max-w-[80%] ${B?"bg-accent text-foreground border border-brand rounded-2xl rounded-br-md":"bg-accent text-foreground dark:text-slate-11 rounded-2xl rounded-bl-md"} px-4 py-2`,children:[V&&(0,r.jsx)("div",{className:`flex flex-wrap gap-2 ${e.content?"mb-2":""}`,children:e.images.map((e,t)=>(0,r.jsx)("div",{className:"relative w-16 h-16 rounded-lg overflow-hidden border border-white/20 cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>M(e),children:(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:S("chat.imageN",{index:t+1}),className:"w-full h-full object-cover"})},t))}),q.length>0&&(0,r.jsx)("div",{className:"space-y-3",children:q.map((n,s)=>(0,r.jsx)(eo,{text:n.text,isAside:n.isAside,isUser:B,isStreaming:!!e.isStreaming&&s===q.length-1,onOpenFileLink:w,cwd:t},s))}),X&&(C=(j=Array.isArray(k=X.input?.todos)?k:[]).filter(e=>"completed"===e.status).length,N=j.length,(0,r.jsx)("div",{className:`${e.content||V?"mt-2":""}`,children:(0,r.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,r.jsx)("div",{className:"flex-1 h-1 bg-secondary rounded-full overflow-hidden",children:(0,r.jsx)("div",{className:"h-full bg-green-500 rounded-full transition-all duration-300",style:{width:`${N>0?C/N*100:0}%`}})}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[C,"/",N]})]}),j.map((e,t)=>(0,r.jsxs)("div",{className:`flex items-center gap-1.5 ${"completed"===e.status?"opacity-50":""}`,children:["completed"===e.status?(0,r.jsx)(d.A,{className:"w-3 h-3 text-green-500 flex-shrink-0"}):"in_progress"===e.status?(0,r.jsx)(u.A,{className:"w-3 h-3 text-brand flex-shrink-0 animate-spin"}):(0,r.jsx)(h.A,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),(0,r.jsx)("span",{className:`text-xs truncate ${"completed"===e.status?"text-muted-foreground":"text-foreground"}`,children:"in_progress"===e.status&&e.activeForm?e.activeForm:e.content})]},t))]})})),ei&&(0,r.jsx)("div",{className:`${e.content||V||X?"mt-2":""}`,children:(0,r.jsxs)("div",{className:"border border-brand/40 rounded-lg overflow-hidden bg-secondary/50",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-b border-border bg-brand/10",children:[(0,r.jsx)("span",{className:"text-sm",children:"\uD83D\uDCCB"}),(0,r.jsx)("span",{className:"text-xs font-medium text-foreground",children:S("chat.planTitle",{defaultValue:"Plan (awaiting your review)"})})]}),(0,r.jsx)("div",{className:"px-3 py-2",children:(0,r.jsx)(L.T,{content:ei,isUser:!1,enableMath:!1})}),g&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:S("chat.planApproveHint",{defaultValue:"本环境无审批弹窗,点此退出 Plan 并执行"})}),(0,r.jsxs)("button",{onClick:()=>g(),disabled:b,className:"flex items-center gap-1.5 px-3 py-1 rounded-md bg-brand text-white text-xs font-medium hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex-shrink-0",children:[(0,r.jsx)("span",{children:"✓"}),(0,r.jsx)("span",{children:S("chat.approvePlan",{defaultValue:"批准并执行"})})]})]})]})}),ed.length>0&&(0,r.jsx)("div",{className:`${e.content||V||X?"mt-2":""}`,children:(0,r.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-0.5",children:ed.map(e=>(0,r.jsxs)("button",{onClick:()=>em(e),className:"flex items-center gap-1.5 w-full text-left hover:bg-accent rounded px-1 py-0.5 transition-colors group/md",children:[(0,P.u)(e)?(0,r.jsxs)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 5a1 1 0 011-1h14a1 1 0 011 1v14a1 1 0 01-1 1H5a1 1 0 01-1-1V5z"}),(0,r.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5",fill:"currentColor",stroke:"none"}),(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4-4 3 3 4-4 5 5"})]}):(0,P.aR)(e)?(0,r.jsx)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})}):(0,r.jsx)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground group-hover/md:text-foreground truncate",children:e.split("/").pop()})]},e))})}),eu.length>0&&(0,r.jsx)("div",{className:`${e.content||V||X||ed.length>0?"mt-2":""}`,children:(0,r.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50",children:(0,r.jsxs)("table",{className:"w-full text-xs",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border text-muted-foreground",children:[(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium w-[60px]",children:"Tool"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Previous"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Action"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Expect"})]})}),(0,r.jsx)("tbody",{children:eu.map((e,t)=>(0,r.jsxs)("tr",{className:t<eu.length-1?"border-b border-border/50":"",children:[(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground font-mono",children:e.toolName}),(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.previous||"—"}),(0,r.jsx)("td",{className:"px-2 py-1 text-foreground",children:e.current}),(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.expect||"—"})]},t))})]})})}),ec.length>0&&(0,r.jsx)("div",{className:`${e.content||V?"mt-2":""}`,children:O>0?(0,r.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsxs)("button",{onClick:()=>T(!R),className:"flex-1 px-3 py-1.5 flex items-center gap-2 text-left hover:bg-accent transition-colors active:bg-muted",children:[(0,r.jsx)("span",{className:"text-sm",children:"\uD83D\uDD27"}),(0,r.jsx)("span",{className:"font-medium text-foreground",children:S("chat.toolCalls",{count:ec.length})}),(0,r.jsx)("span",{className:"ml-auto text-muted-foreground text-sm",children:R?S("chat.collapse"):S("chat.expand")})]}),ea.length>0&&(0,r.jsx)("button",{onClick:()=>_(!0),className:"px-3 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:S("chat.viewQuestions"),children:(0,r.jsx)(m.A,{className:"w-4 h-4"})}),J&&(0,r.jsx)("button",{onClick:()=>{y&&e.toolCalls?y(e.toolCalls,t,n??void 0):I(!0)},className:"px-3 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:S("chat.viewAllFileChanges"),children:(0,r.jsx)(f.A,{className:"w-4 h-4"})})]}),R&&(0,r.jsx)("div",{className:"border-t border-border p-2 space-y-1",children:ec.map((e,s)=>(0,r.jsx)(W,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}):ec.map((e,s)=>(0,r.jsx)(W,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}),!B&&(0,r.jsxs)("div",{className:"self-start mt-2 ml-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,r.jsx)("button",{onClick:ep,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.copyMessage"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),z&&(0,r.jsx)("button",{onClick:eg,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.forkSession"),children:(0,r.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,r.jsx)("path",{d:"M12 12v3"})]})}),z&&(0,r.jsx)("button",{onClick:eb,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.excerptTurn"),children:(0,r.jsx)(c.A,{className:"w-4 h-4"})})]})]})]}),E&&(0,r.jsx)(es,{image:E,onClose:()=>M(null)}),$&&e.toolCalls&&(0,r.jsx)(Q.zB,{toolCalls:e.toolCalls,cwd:t,sessionId:n??void 0,onClose:()=>I(!1),onContentSearch:v}),A&&ea.length>0&&(0,r.jsx)(G,{toolCalls:ea,onClose:()=>_(!1)}),eh&&(0,P.u)(eh)&&(0,r.jsx)(el,{filePath:eh,onClose:()=>em(null)}),eh&&!(0,P.u)(eh)&&null!==ef&&((0,P.aR)(eh)?(0,r.jsx)(et.N,{filePath:eh,content:ef,cwd:t,onClose:()=>em(null),onContentSearch:v}):(0,r.jsx)(en.x,{filePath:eh,content:ef,cwd:t||"",onClose:()=>em(null)}))]})});var ei=n(1058),ec=n(90717),ed=n(89109),eu=n(7320);let eh=/[,,]/;function em({initialRows:e,lang:t,isCustomized:n,onSave:l,onRestoreDefault:a,onClose:i}){let{t:c}=(0,x.Bd)(),[d,u]=(0,s.useState)(()=>e.map(e=>e.join("zh"===t?",":", ")).join("\n"));(0,V.E)(i);let h=(0,s.useCallback)(()=>{l(d.split("\n").map(e=>e.split(eh).map(e=>e.trim().slice(0,200)).filter(Boolean).slice(0,8)).filter(e=>e.length>0).slice(0,12)),i()},[d,l,i]),m=(0,s.useCallback)(()=>{a(),i()},[a,i]);return(0,r.jsx)(o.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50 p-4",onClick:i,children:(0,r.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-xl w-full max-w-md flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-foreground",children:c("quickReply.editTitle")}),(0,r.jsx)("button",{onClick:i,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors","aria-label":c("quickReply.cancel"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,r.jsxs)("div",{className:"px-4 py-3 flex flex-col gap-2",children:[(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:c("quickReply.editHint")}),(0,r.jsx)("textarea",{autoFocus:!0,value:d,onChange:e=>u(e.target.value),placeholder:c("quickReply.editPlaceholder"),rows:6,spellCheck:!1,className:"w-full px-2 py-1.5 text-xs font-mono bg-background border border-border rounded text-foreground focus:outline-none focus:border-brand resize-y"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:c("quickReply.customizedFor",{lang:c("zh"===t?"quickReply.langZh":"quickReply.langEn")})})]}),(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-t border-border",children:[(0,r.jsx)("button",{onClick:m,disabled:!n,className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:c("quickReply.restoreDefault")}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:i,className:"px-3 py-1.5 text-xs border border-border text-foreground rounded-md hover:bg-accent transition-colors",children:c("quickReply.cancel")}),(0,r.jsx)("button",{onClick:h,className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",children:c("quickReply.save")})]})]})]})})})}let ef=(0,s.forwardRef)(function({messages:e,isLoading:t,cwd:n,sessionId:o,engine:a,apiRetryInfo:i,hasMoreHistory:c,isLoadingMore:d,onLoadMore:u,onFork:h,isActive:m=!0,onContentSearch:f,onShowFileDiff:g,onOpenFileLink:b,onApprovePlan:v},y){let w,{t:k,i18n:j}=(0,x.Bd)(),C="codex"!==a,N=(0,s.useRef)(null),S=(0,s.useRef)(null),L=(0,s.useRef)(null),E=(0,s.useRef)(null),[M,R]=(0,s.useState)(null),[T,$]=(0,s.useState)(!0),[P,I]=(0,s.useState)(!1),[A,_]=(0,s.useState)(!1);(0,s.useEffect)(()=>{R(E.current)},[]);let{isSearchVisible:F,searchQuery:D,setSearchQuery:B,matches:W,currentMatchIndex:V,goToNextMatch:O,goToPrevMatch:z,closeSearch:H,searchInputRef:q,handleSearchKeyDown:U}=function(e){let[t,n]=(0,s.useState)(!1),[r,l]=(0,s.useState)(""),[o,a]=(0,s.useState)([]),[i,c]=(0,s.useState)(0),d=(0,s.useRef)(null),u=(0,s.useRef)([]),h=(0,s.useCallback)(()=>{let t=e.current;t&&(t.querySelectorAll("mark.chat-search-match, mark.chat-search-current").forEach(e=>{let t=e.parentNode;t&&(t.replaceChild(document.createTextNode(e.textContent||""),e),t.normalize())}),u.current=[])},[e]),m=(0,s.useCallback)(t=>{if(h(),!t||!e.current){a([]),c(0);return}let n=[],r=[],s=t.toLowerCase();e.current.querySelectorAll("[data-message-id]").forEach(e=>{let l,o=e.getAttribute("data-message-id")||"",a=0,i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),c=[];for(;l=i.nextNode();)c.push(l);for(let e of c){let l=(e.textContent||"").toLowerCase(),i=0,c=[];for(;;){let e=l.indexOf(s,i);if(-1===e)break;c.push({start:e,end:e+t.length}),i=e+1}if(0!==c.length)for(let t=c.length-1;t>=0;t--){let s=c[t];e.splitText(s.end);let l=e.splitText(s.start),i=document.createElement("mark");i.className="chat-search-match",i.textContent=l.textContent,l.parentNode.replaceChild(i,l),n.push({messageId:o,markIndex:a}),r.push(i),a++}}}),n.reverse(),r.reverse(),u.current=r,a(n),c(n.length>0?0:-1)},[e,h]);(0,s.useEffect)(()=>{queueMicrotask(()=>m(r))},[r,m]),(0,s.useEffect)(()=>{let e=u.current;e.forEach((e,t)=>{e.className=t===i?"chat-search-current":"chat-search-match"}),i>=0&&i<e.length&&e[i].scrollIntoView({behavior:"smooth",block:"center"})},[i,o]);let f=(0,s.useCallback)(()=>{0!==o.length&&c(e=>(e+1)%o.length)},[o.length]),x=(0,s.useCallback)(()=>{0!==o.length&&c(e=>(e-1+o.length)%o.length)},[o.length]),p=(0,s.useCallback)(()=>{n(!0),setTimeout(()=>d.current?.focus(),0)},[]),g=(0,s.useCallback)(()=>{n(!1),l(""),h(),a([]),c(0)},[h]),b=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?x():f()),"Escape"===e.key&&g()},[f,x,g]);return(0,s.useEffect)(()=>{let t=e.current;if(!t)return;let n=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),e.stopPropagation(),p())};return t.addEventListener("keydown",n),()=>t.removeEventListener("keydown",n)},[e,p]),{isSearchVisible:t,searchQuery:r,setSearchQuery:l,matches:o,currentMatchIndex:i,goToNextMatch:f,goToPrevMatch:x,openSearch:p,closeSearch:g,searchInputRef:d,handleSearchKeyDown:b}}(E),K=(0,l.nH)(),Z=(0,s.useRef)(null),J=(0,s.useRef)(()=>{}),{addComment:X,refresh:G}=(0,ei._)({cwd:n||"",filePath:ec.Un}),[Q,Y]=(0,s.useState)(null),[ee,et]=(0,s.useState)(null),en=(0,s.useCallback)(e=>{if(Q||ee)return;let t=window.getSelection();if(!t||t.isCollapsed||!t.rangeCount){Z.current=null,J.current();return}let n=t.toString().trim();if(!n){Z.current=null,J.current();return}let r=t.anchorNode instanceof HTMLElement?t.anchorNode:t.anchorNode?.parentElement;if(r?.closest('[data-role="user"]')){Z.current=null,J.current();return}Z.current={x:e.clientX,y:e.clientY,range:{start:0,end:0},selectedText:n,lineSnapshot:n},J.current()},[Q,ee]),es=(0,s.useCallback)(e=>{let t=e.target;!(t.closest(".floating-toolbar")||t.closest('[class*="z-[200]"]'))&&Z.current&&(Z.current=null,J.current())},[]),el=(0,s.useCallback)(()=>{let e=Z.current;e&&(Y({x:e.x,y:e.y,text:e.selectedText}),Z.current=null,J.current(),window.getSelection()?.removeAllRanges())},[]),eo=(0,s.useCallback)(()=>{let e=Z.current;e&&(et({x:e.x,y:e.y,text:e.selectedText}),Z.current=null,J.current(),window.getSelection()?.removeAllRanges())},[]),eh=(0,s.useCallback)(()=>{let e=Z.current;e&&K&&(Z.current=null,J.current(),window.getSelection()?.removeAllRanges(),(0,ec.Ff)(K.sendMessage,{filePath:ec.Un,startLine:0,endLine:0,codeContent:e.selectedText},k("explain.selectionMessage")))},[K,k]),ef=(0,s.useCallback)(()=>{let e=Z.current;if(!e||!f)return;let t=e.selectedText.trim();Z.current=null,J.current(),window.getSelection()?.removeAllRanges(),t&&f(t)},[f]),ex=(0,s.useCallback)(async e=>{Q&&(await X(0,0,e,Q.text),Y(null))},[Q,X]),ep=(0,s.useCallback)(async(e,t)=>{if(K&&n)try{let r=(await (0,ec.$3)(n)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));r.push({filePath:ec.Un,startLine:0,endLine:0,codeContent:e});let s=(0,ec.Gw)(r,t);K.sendMessage(s),await (0,ec.RP)(n),G()}catch(e){console.error("Failed to send to AI:",e)}},[K,n,G]),eg=(0,s.useCallback)((e,t)=>{let n=Z.current;if(!n)return;let r=n.selectedText;Z.current=null,J.current(),window.getSelection()?.removeAllRanges(),"comment"===e?X(0,0,t,r):ep(r,t)},[X,ep]),eb=(w=j.language,w?.toLowerCase().startsWith("zh")?"zh":"en"),[ev,ey]=(0,s.useState)(null),[ew,ek]=(0,s.useState)(!1);(0,s.useEffect)(()=>{let e=!1;return p.t4.runPromiseExit((0,er.td)()).then(t=>{e||ey("Success"===t._tag?((e,t)=>{if(!e||"object"!=typeof e)return null;let n=e.quickReplies;return n&&"object"==typeof n?(e=>{if(!Array.isArray(e))return null;let t=[];for(let n of e.slice(0,12)){if(!Array.isArray(n))continue;let e=[];for(let t of n.slice(0,8)){if("string"!=typeof t)continue;let n=t.trim().slice(0,200);n&&e.push(n)}e.length&&t.push(e)}return t.length?t:null})(n[t]):null})(t.value,eb):null)}),()=>{e=!0}},[eb]);let ej=(0,s.useCallback)(e=>{p.t4.runPromiseExit((0,er.td)()).then(t=>{let n={..."Success"===t._tag?t.value.quickReplies??{}:{}};return e?n[eb]=e:delete n[eb],p.t4.runPromiseExit((0,er.em)({quickReplies:n})).then(t=>{"Success"===t._tag?ey(e):console.error("Failed to save quick replies:",t.cause)})})},[eb]),eC=(0,s.useCallback)(()=>{Z.current=null,J.current(),window.getSelection()?.removeAllRanges(),ek(!0)},[]),eN=(0,s.useMemo)(()=>ev??ed.SZ.map(e=>e.map(e=>k(e))),[ev,k]),eS=(0,s.useCallback)(e=>{ee&&ep(ee.text,e)},[ee,ep]),eL=(0,s.useCallback)(e=>{Q&&ep(Q.text,e)},[Q,ep]),eE=(0,s.useMemo)(()=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),"assistant"!==e.role||!!e.isStreaming||!!e.content||!!e.images?.length||!!e.toolCalls?.length||!!e.parts?.length))},[e]),eM=(0,s.useRef)(0),eR=(0,s.useRef)(!1),eT=(0,s.useCallback)(()=>{let e=L.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[]),e$=(0,s.useCallback)(()=>{let e=L.current;return!e||e.scrollTop<50},[]),eP=(0,s.useCallback)(()=>{let e=eT(),t=e$();if($(e),I(!t),_(!e),t&&c&&!d&&u){let e=L.current;e&&(eM.current=e.scrollHeight,eR.current=!0),u()}},[eT,e$,c,d,u]),eI=(0,s.useCallback)(()=>{S.current?.scrollIntoView({behavior:"smooth"})},[]),eA=(0,s.useCallback)(()=>{N.current?.scrollIntoView({behavior:"smooth"})},[]),e_=(0,s.useCallback)(e=>{let t=L.current;if(!t)return;let n=t.querySelector(`[data-message-id="${e}"]`);n&&(n.scrollIntoView({behavior:"smooth",block:"center"}),n.classList.add("ring-2","ring-brand","ring-offset-2"),setTimeout(()=>{n.classList.remove("ring-2","ring-brand","ring-offset-2")},2e3))},[]);(0,s.useImperativeHandle)(y,()=>({scrollToMessage:e_}),[e_]);let eF=(0,s.useRef)(0),eD=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let t=eF.current,n=e.length;eF.current=n,!eD.current&&T&&n>t&&N.current?.scrollIntoView({behavior:"smooth"})},[e,T]),(0,s.useEffect)(()=>{T&&t&&N.current?.scrollIntoView({behavior:"smooth"})},[t,T]),(0,s.useEffect)(()=>{if(eR.current&&!d){let e=L.current;if(e){let t=e.scrollHeight-eM.current;e.scrollTop=t,eR.current=!1}}},[e,d]);let eB=(0,s.useRef)(!1);return(0,s.useEffect)(()=>{m&&eB.current&&e.length>0&&(eB.current=!1,N.current?.scrollIntoView({behavior:"instant"}))},[m,e.length]),(0,s.useEffect)(()=>{eD.current&&e.length>0&&(eD.current=!1,m?N.current?.scrollIntoView({behavior:"instant"}):eB.current=!0)},[e.length,m]),(0,r.jsxs)("div",{ref:E,className:"relative flex-1 min-h-0 overflow-hidden flex flex-col outline-none",tabIndex:-1,onMouseUp:en,onMouseDown:es,children:[F&&(0,r.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,r.jsx)("input",{ref:q,type:"text",value:D,onChange:e=>B(e.target.value),onKeyDown:U,placeholder:k("codeViewer.searchChat"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:W.length>0?`${V+1}/${W.length}`:k("common.noMatch")}),(0,r.jsx)("button",{onClick:z,disabled:0===W.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:k("codeViewer.prevShiftEnter"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,r.jsx)("button",{onClick:O,disabled:0===W.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:k("codeViewer.nextEnter"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,r.jsx)("button",{onClick:H,className:"p-1 rounded hover:bg-accent",title:k("codeViewer.closeEsc"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,r.jsx)("div",{ref:L,onScroll:eP,className:"relative flex-1 min-h-0 overflow-y-auto p-4",children:0!==e.length||t?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{ref:S}),c&&(0,r.jsx)("div",{className:"flex justify-center py-3",children:d?(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("span",{children:k("chat.loadMoreHistory")})]}):(0,r.jsx)("button",{onClick:u,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:k("chat.scrollUpForMore")})}),eE.map(e=>(0,r.jsx)("div",{"data-message-id":e.id,className:"transition-[box-shadow] duration-300",children:(0,r.jsx)(ea,{message:e,cwd:n,sessionId:o,onFork:h,forkSupported:C,onApprovePlan:v,isLoading:t,onContentSearch:f,onShowFileDiff:g,onOpenFileLink:b})},e.id)),t&&(0,r.jsx)("div",{className:"flex justify-start mb-4",children:(0,r.jsxs)("div",{className:"bg-accent rounded-2xl rounded-bl-md px-4 py-3 max-w-[90%]",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,r.jsx)("span",{className:"inline-block w-5 h-5 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("span",{className:"text-sm",children:"codex"===a?"Codex is thinking...":"kimi"===a?"Kimi is thinking...":"ollama"===a?"Ollama is thinking...":"deepseek"===a?"DeepSeek is thinking...":"glm"===a?"GLM is thinking...":k("chat.claudeThinking")})]}),i&&(0,r.jsxs)("div",{className:"mt-2 flex items-start gap-2 text-xs text-amber-400 border-t border-border/50 pt-2",children:[(0,r.jsx)("svg",{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsxs)("div",{children:["Retrying API call (attempt ",i.attempt,i.maxRetries>0?`/${i.maxRetries}`:"",i.delayMs>0?`, delay ${(i.delayMs/1e3).toFixed(1)}s`:"",")"]}),(i.errorStatus||i.error)&&(0,r.jsxs)("div",{className:"text-muted-foreground/80 break-words",children:[i.errorStatus?`${i.errorStatus}`:"",i.errorStatus&&i.error?" \xb7 ":"",i.error||""]})]})]})]})}),(0,r.jsx)("div",{ref:N})]}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full text-slate-9",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("div",{className:"text-4xl mb-4",children:"\uD83D\uDCAC"}),(0,r.jsx)("div",{children:k("chat.startConversation")})]})})}),P&&e.length>0&&(0,r.jsx)("button",{onClick:eI,className:"absolute top-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:k("chat.jumpToStart"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),A&&e.length>0&&(0,r.jsx)("button",{onClick:eA,className:"absolute bottom-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:k("chat.jumpToLatest"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),M&&(0,r.jsx)(ed.fS,{floatingToolbarRef:Z,bumpRef:J,container:M,onAddComment:el,onSendToAI:eo,onSearch:f?ef:void 0,onExplain:K?eh:void 0,onQuickReply:eg,quickReplyRows:eN,onEditQuickReplies:eC,isChatLoading:K?.isLoading}),ew&&(0,r.jsx)(em,{initialRows:eN,lang:eb,isCustomized:null!==ev,onSave:e=>ej(e.length?e:null),onRestoreDefault:()=>ej(null),onClose:()=>ek(!1)}),Q&&M&&(0,r.jsx)(eu.t,{x:Q.x,y:Q.y,range:{start:0,end:0},lineSnapshot:Q.text,container:M,onSubmit:ex,onSendToAI:K?eL:void 0,onClose:()=>Y(null),isChatLoading:K?.isLoading}),ee&&M&&(0,r.jsx)(eu.G,{x:ee.x,y:ee.y,range:{start:0,end:0},lineSnapshot:ee.text,container:M,onSubmit:eS,onClose:()=>et(null),isChatLoading:K?.isLoading})]})})},75346:(e,t,n)=>{n.d(t,{n:()=>s});var r=n(88292);let s={SessionChange:(0,r.R)("session-change"),ViewChange:(0,r.R)("view-change"),OpenNote:(0,r.R)("open-note"),LangChange:(0,r.R)("lang-change"),TabAdd:(0,r.R)("tab-add"),TabClose:(0,r.R)("tab-close"),SwitchSession:(0,r.R)("switch-session"),ProjectChange:(0,r.R)("project-change"),OpenProject:(0,r.R)("open-project"),SessionComplete:(0,r.R)("session-complete"),OpenTokenStats:(0,r.R)("open-token-stats"),PinnedSessionsChanged:(0,r.R)("pinned-sessions-changed"),ScheduledTasksChanged:(0,r.R)("scheduled-tasks-changed"),ScreenshotPrepare:(0,r.R)("screenshot-prepare"),ScreenshotDone:(0,r.R)("screenshot-done")}},77725:(e,t,n)=>{n.d(t,{Z:()=>d});var r=n(12115),s=n(10592),l=n(86359),o=n(80905),a=n(49433),i=n(80286),c=n(86957);function d(e,t){let[n,d]=(0,r.useState)({status:"loading"});return(0,r.useEffect)(()=>{d({status:"loading"});let t=c.t4.runFork(e);return t.addObserver(e=>{s.YW(e,{onSuccess:e=>d({status:"success",data:e}),onFailure:e=>{if(l.t9(e))return;let t=l.od(e);d({status:"error",error:o.Ru(t)?t.value:e})}})}),()=>{a.runFork(i.G(t))}},t),n}},82292:(e,t,n)=>{function r(e,t){for(let n of e){if(n.path===t)return n;if(n.children){let e=r(n.children,t);if(e)return e}}return null}function s(e,t){if(!e)return"";let n=r(t,e);if(n?.isDirectory)return e;let s=e.split("/");return s.pop(),s.join("/")}function l(e){let t=[];for(let n of e){let e=n.split("/"),r=t;for(let t=0;t<e.length;t++){let n=e[t],s=t===e.length-1,l=e.slice(0,t+1).join("/"),o=r.find(e=>e.name===n);o||(o={name:n,path:l,isDirectory:!s,children:s?void 0:[]},r.push(o)),!s&&o.children&&(r=o.children)}}let n=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>{e.children&&n(e.children)})};return n(t),t}function o(e){let t=[],n=e=>{for(let r of e)r.isDirectory&&(t.push(r.path),r.children&&n(r.children))};return n(e),t}n.d(t,{B_:()=>f,HR:()=>function e(t,n){if(0===n.length)return t;let r=new Map(n.map(e=>[e.path,e]));return t.map(t=>{let n=r.get(t.path);return n&&t.isDirectory?void 0===t.children&&void 0!==n.children?{...t,children:n.children}:void 0!==t.children&&void 0!==n.children?{...t,children:e(t.children,n.children)}:t:t})},KH:()=>d,MB:()=>r,S7:()=>s,fw:()=>u,q3:()=>c,r6:()=>h,tE:()=>m,tW:()=>o,u:()=>i,v3:()=>l});let a=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function i(e){let t=e.split(".").pop()?.toLowerCase();return a.has(t||"")}function c(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase(),l=e=>{if(r.add(e.path),e.children)for(let t of e.children)l(t)},o=(e,t)=>{let a=e.name.toLowerCase(),i=n?a===s:a.includes(s);if(i&&e.children)return l(e),t.forEach(e=>r.add(e)),!0;let c=!1;if(e.children)for(let n of e.children)o(n,[...t,e.path])&&(c=!0);return(!!i||!!c)&&(r.add(e.path),t.forEach(e=>r.add(e)),!0)};for(let t of e)o(t,[]);return r}function d(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase();for(let t of e){let e=t.split("/");for(let t=0;t<e.length;t++){let l=e[t].toLowerCase();if(n?l===s:l.includes(s)){for(let t=0;t<=e.length-1;t++)r.add(e.slice(0,t+1).join("/"));break}}}return r}function u(e){let t=Math.floor(Math.floor((Date.now()-1e3*e)/1e3)/60),n=Math.floor(t/60),r=Math.floor(n/24),s=Math.floor(r/30),l=Math.floor(r/365);return l>0?`${l}y ago`:s>0?`${s}mo ago`:r>0?`${r}d ago`:n>0?`${n}h ago`:t>0?`${t}m ago`:"just now"}function h(e){let t=new Date(e),n=new Date,r=t.getFullYear()===n.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0"),o=String(t.getHours()).padStart(2,"0"),a=String(t.getMinutes()).padStart(2,"0");return r?`${s}-${l} ${o}:${a}`:`${t.getFullYear()}-${s}-${l} ${o}:${a}`}let m=()=>{},f=50},83448:(e,t,n)=>{n.d(t,{Cr:()=>E,F4:()=>p,Fi:()=>m,Hw:()=>d,JC:()=>y,M5:()=>b,Ny:()=>u,QW:()=>j,XO:()=>M,Zr:()=>k,an:()=>L,dM:()=>x,dQ:()=>h,em:()=>c,he:()=>f,l1:()=>v,n_:()=>w,qD:()=>S,tY:()=>T,td:()=>i,tf:()=>R,yS:()=>g,z2:()=>C});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),o=(e,t)=>l(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=(e,t)=>l(e,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),i=()=>l("/api/settings"),c=e=>a("/api/settings",e),d=e=>l(`/api/${e}/credentials`),u=e=>l(`/api/${e}/credentials?reveal=1`),h=(e,t)=>a(`/api/${e}/credentials`,{apiKey:t}),m=e=>l(`/api/${e}/models`),f=()=>l("/api/deepseek/balance"),x=e=>l(`/api/${e}/usage`),p=()=>l("/api/ollama/config"),g=e=>a("/api/ollama/config",e),b=()=>l("/api/commands"),v=()=>l("/api/skills"),y=e=>o("/api/bash",e),w=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new s.uV({message:"POST /api/session-by-path failed",cause:e})}),k=(e,t)=>o(`/api/session/${encodeURIComponent(e)}/fork`,t),j=e=>l(`/api/sessions/projects/${encodeURIComponent(e)}`),C=()=>l("/api/global-state").pipe(r.map(e=>e.sessions??[])),N=()=>r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/models");return 503===e.status?{_tag:"not-running"}:e.ok?{_tag:"ok",models:(await e.json()).models??[]}:{_tag:"error",message:"Failed to fetch models"}},catch:e=>new s.uV({message:"fetch ollama models failed",cause:e})}),S=e=>r.gen(function*(){let t=yield*N();if("not-running"!==t._tag)return t;e&&(yield*r.sync(e));let n=yield*r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/start",{method:"POST"}),t=await e.json().catch(()=>({}));return 404===e.status?{_tag:"not-installed",message:t.message||"Ollama is not installed"}:e.ok?{_tag:"started"}:{_tag:"error",message:"Failed to start Ollama"}},catch:e=>new s.uV({message:"start ollama failed",cause:e})});if("not-installed"===n._tag)return{_tag:"not-installed",message:n.message};if("error"===n._tag)return{_tag:"error",message:n.message};let l=yield*N();return"not-running"===l._tag?{_tag:"error",message:"Ollama started but cannot fetch models"}:l}),L=e=>l(`/api/file?path=${encodeURIComponent(e)}`),E=()=>l("/api/claude-stats"),M=()=>l("/api/prompts/config?scope=global"),R=e=>l(`/api/prompts/config?cwd=${encodeURIComponent(e)}`),T=e=>o("/api/prompts/config",e)},83897:(e,t,n)=>{n.d(t,{k_:()=>a,nH:()=>i});var r=n(95155),s=n(12115),l=n(48347);let o=(0,s.createContext)(null);function a({children:e}){let t=(0,s.useRef)(new Map),n=(0,s.useRef)(null),[i,c]=(0,s.useState)(!1),d=(0,s.useCallback)((e,n)=>{t.current.set(n,e)},[]),u=(0,s.useCallback)(e=>{t.current.delete(e)},[]),h=(0,s.useCallback)(e=>{n.current=e},[]),m=(0,s.useCallback)(e=>{let r=n.current;if(!r)return void console.warn("No active tab to send message");let s=t.current.get(r);s?s(e):console.warn(`No chat sender registered for tab ${r}`)},[]),f=(0,s.useMemo)(()=>({sendMessage:m,isLoading:i,registerChat:d,unregisterChat:u,setActiveTab:h,setIsLoading:c}),[m,i,d,u,h]),x=(0,s.useMemo)(()=>({sendMessage:m,isLoading:i}),[m,i]);return(0,r.jsx)(o.Provider,{value:f,children:(0,r.jsx)(l.H,{value:x,children:e})})}function i(){return(0,s.useContext)(o)}},86304:(e,t,n)=>{n.d(t,{P:()=>c});var r=n(12115),s=n(79114),l=n(34075),o=n(86957),a=n(98036),i=n(63563);function c(){let{t:e}=(0,s.Bd)();return(0,r.useCallback)(async t=>{let n=await o.t4.runPromiseExit((0,a.ot)(t));if("Success"===n._tag)n.value.alreadyExists?(0,l.oR)(e("htmlApps.alreadyAdded"),"info"):((0,l.oR)(e("htmlApps.added"),"success"),(0,i.N)());else{let t="Fail"===n.cause._tag?n.cause.error:null,r=t?.cause,s=r instanceof Error?r.message:e("htmlApps.addFailed");(0,l.oR)(s,"error")}},[e])}},88780:(e,t,n)=>{n.d(t,{Do:()=>u,Sz:()=>h,VO:()=>d,wI:()=>m});var r=n(95155),s=n(12115),l=n(79114),o=n(70188),a=n(14575);function i({status:e}){let{label:t,className:n}={added:{label:"A",className:"text-green-11"},untracked:{label:"A",className:"text-green-11"},modified:{label:"M",className:"text-amber-11"},deleted:{label:"D",className:"text-red-11"},renamed:{label:"R",className:"text-brand"}}[e]||{label:"?",className:"text-muted-foreground"};return(0,r.jsx)("span",{className:`text-xs font-bold ${n}`,children:t})}let c=s.memo(function e({node:t,level:n,selectedPath:l,expandedPaths:o,onSelect:c,onToggle:d,onContextMenu:u,showChanges:h=!1,renderActions:m}){let f=l===t.path,x=o.has(t.path),p=(0,s.useCallback)(()=>{t.isDirectory?d(t.path):c(t)},[t,c,d]),g=(0,s.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),u(e,t.path,t.isDirectory)},[t.path,t.isDirectory,u]);return t.isDirectory?(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 py-0.5 px-2 pr-3 hover:bg-accent cursor-pointer whitespace-nowrap group",style:{paddingLeft:`${12*n+8}px`},onClick:p,onContextMenu:g,children:[(0,r.jsx)("span",{className:"text-slate-9 text-xs",children:x?"▼":"▶"}),(0,r.jsx)("span",{className:"text-sm text-foreground flex-1 truncate","data-tooltip":t.path,children:t.name}),m&&m(t)]}),x&&t.children.map(t=>(0,r.jsx)(e,{node:t,level:n+1,selectedPath:l,expandedPaths:o,onSelect:c,onToggle:d,onContextMenu:u,showChanges:h,renderActions:m},t.path))]}):(0,r.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 pr-3 cursor-pointer whitespace-nowrap group ${f?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*n+8}px`},onClick:p,onContextMenu:g,children:[(0,r.jsx)(a.o,{name:t.name,size:16,className:"flex-shrink-0"}),(0,r.jsx)("span",{className:`text-sm flex-1 truncate ${f?"text-brand":"text-foreground"}`,"data-tooltip":t.path,children:t.name}),t.status&&(0,r.jsx)(i,{status:t.status}),h&&void 0!==t.additions&&void 0!==t.deletions&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("span",{className:"text-xs text-green-11",children:["+",t.additions]}),(0,r.jsxs)("span",{className:"text-xs text-red-11",children:["-",t.deletions]})]}),m&&m(t)]})});function d({files:e,selectedPath:t,expandedPaths:n,onSelect:s,onToggle:a,cwd:i,showChanges:u=!1,renderActions:h,emptyMessage:m,className:f,onExplain:x,explainDisabled:p}){let{t:g}=(0,l.Bd)(),b=m??g("gitFileTree.noFiles"),{contextMenu:v,showContextMenu:y,hideContextMenu:w}=(0,o.Ee)();return 0===e.length?(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:b}):(0,r.jsxs)("div",{className:f||"py-1",children:[e.map(e=>(0,r.jsx)(c,{node:e,level:0,selectedPath:t,expandedPaths:n,onSelect:s,onToggle:a,onContextMenu:y,showChanges:u,renderActions:h},e.path)),v&&(0,r.jsx)(o.ft,{x:v.x,y:v.y,path:v.path,cwd:i,isDirectory:v.isDirectory,onClose:w,onExplain:x,explainDisabled:p})]})}function u(e){let t=[];for(let n of e){let e=n.path.split("/"),r=t;for(let t=0;t<e.length;t++){let s=e[t],l=t===e.length-1,o=e.slice(0,t+1).join("/"),a=r.find(e=>e.name===s);a||(a={name:s,path:o,isDirectory:!l,children:[],...l&&{status:n.status,additions:n.additions,deletions:n.deletions,oldPath:n.oldPath,file:n}},r.push(a)),l||(r=a.children)}}let n=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>n(e.children))};return n(t),t}function h(e){let t=[],n=e=>{for(let r of e)r.isDirectory&&(t.push(r.path),n(r.children))};return n(e),t}function m(e){let t=[],n=e=>{if(e.isDirectory)for(let t of e.children)n(t);else t.push(e)};return n(e),t}},89109:(e,t,n)=>{n.d(t,{SZ:()=>o,fS:()=>c});var r=n(95155),s=n(12115),l=n(79114);let o=[["quickReply.optionA","quickReply.optionB","quickReply.optionC","quickReply.optionD"],["quickReply.allRecommended","quickReply.thisOne","quickReply.notThis"],["quickReply.why","quickReply.elaborate","quickReply.example"],["quickReply.start","quickReply.continue","quickReply.ok","quickReply.done"]];function a({rows:e,placeAbove:t,onHeight:n,onPick:o,onEdit:i,onMouseEnter:c,onMouseLeave:d}){let{t:u}=(0,l.Bd)(),h=(0,s.useRef)(null);return(0,s.useEffect)(()=>{h.current&&n(h.current.getBoundingClientRect().height)},[n,e]),(0,r.jsxs)("div",{ref:h,className:`absolute ${t?"bottom-full mb-1":"top-full mt-1"} left-0 z-[201] flex flex-col gap-1 bg-card border border-border rounded-lg shadow-xl p-1.5`,onMouseEnter:c,onMouseLeave:d,children:[i&&(0,r.jsx)("button",{className:"absolute top-0.5 right-0.5 p-1 text-muted-foreground hover:text-brand transition-colors",onClick:i,title:u("quickReply.edit"),"aria-label":u("quickReply.edit"),children:(0,r.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),e.map((e,t)=>(0,r.jsx)("div",{className:`flex items-center gap-1${i&&0===t?" pr-5":""}`,children:e.map((e,n)=>(0,r.jsx)("button",{className:"px-2 py-1 text-xs whitespace-nowrap border border-border text-foreground rounded hover:border-brand hover:bg-accent transition-colors",onClick:()=>o(e),children:e},`${t}:${n}:${e}`))},t))]})}function i({x:e,y:t,visible:n,container:c,onAddComment:d,onSendToAI:u,onSearch:h,onExplain:m,onQuickReply:f,quickReplyRows:x,onEditQuickReplies:p,isChatLoading:g}){let{t:b}=(0,l.Bd)(),v=(0,s.useRef)(null),[y,w]=(0,s.useState)({w:0,h:0}),[k,j]=(0,s.useState)(0),[C,N]=(0,s.useState)(null),S=(0,s.useRef)(null);(0,s.useLayoutEffect)(()=>{let e=v.current;if(!e)return;let{width:t,height:n}=e.getBoundingClientRect();w(e=>e.w===t&&e.h===n?e:{w:t,h:n})});let L=(0,s.useCallback)(e=>{j(t=>t===e?t:e)},[]);(0,s.useEffect)(()=>{n||N(null)},[n]);let E=(0,s.useCallback)(()=>{S.current&&(clearTimeout(S.current),S.current=null)},[]),M=(0,s.useCallback)(e=>{E(),N(e)},[E]),R=(0,s.useCallback)(()=>{E(),S.current=setTimeout(()=>N(null),150)},[E]);(0,s.useEffect)(()=>E,[E]);let T=c.getBoundingClientRect(),$=e-T.left,P=Math.max(0,t-T.top-40),I=Math.max(0,Math.min($+8,T.width-y.w-8)),A=k>0&&P+y.h+8+k>T.height,_=(0,s.useMemo)(()=>x??o.map(e=>e.map(e=>b(e))),[x,b]),F=e=>f&&C===e?(0,r.jsx)(a,{rows:_,onEdit:p,placeAbove:A,onHeight:L,onPick:t=>{N(null),f(e,t)},onMouseEnter:E,onMouseLeave:R}):null;return(0,r.jsxs)("div",{ref:v,className:"floating-toolbar absolute z-[200] flex items-center gap-1.5 bg-card border border-border rounded-lg shadow-xl p-1.5",style:{left:I,top:P,visibility:n?"visible":"hidden",pointerEvents:n?"auto":"none"},children:[(0,r.jsxs)("div",{className:"relative",onMouseEnter:()=>M("comment"),onMouseLeave:R,children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:d,children:b("floatingToolbar.addComment")}),F("comment")]}),(0,r.jsxs)("div",{className:"relative",onMouseEnter:()=>{g||M("ai")},onMouseLeave:R,children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",onClick:u,disabled:g,title:g?b("comments.aiResponding"):void 0,children:b("floatingToolbar.sendToAI")}),F("ai")]}),m&&(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",onClick:m,disabled:g,title:g?b("comments.aiResponding"):void 0,children:b("explain.action")}),h&&(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:h,children:b("floatingToolbar.search")})]})}let c=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:n,onAddComment:l,onSendToAI:o,onSearch:a,onExplain:c,onQuickReply:d,quickReplyRows:u,onEditQuickReplies:h,isChatLoading:m}){let[f,x]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>x(e=>e+1)},[t]);let p=(0,s.useMemo)(()=>e.current,[f]);return(0,r.jsx)(i,{x:p?.x??0,y:p?.y??0,visible:!!p,container:n,onAddComment:l,onSendToAI:o,onSearch:a,onExplain:c,onQuickReply:d,quickReplyRows:u,onEditQuickReplies:h,isChatLoading:m})})},90717:(e,t,n)=>{n.d(t,{$3:()=>u,Cm:()=>d,Ff:()=>x,Gw:()=>f,RP:()=>h,Un:()=>m,zL:()=>c});var r=n(69809),s=n(49433),l=n(86957),o=n(82680),a=n(46456);let i=new Set;function c(e){return i.add(e),()=>i.delete(e)}function d(){i.forEach(e=>e())}async function u(e){let t=await l.t4.runPromiseExit((0,a.lb)(e));if("Success"!==t._tag)throw Error("Failed to fetch comments");let n=t.value.comments??[];if(0===n.length)return[];let r=new Map;for(let e of n)e.selectedText||(r.has(e.filePath)||r.set(e.filePath,[]),r.get(e.filePath).push(e));let i=new Map;await Promise.all(Array.from(r.keys()).map(async t=>{let n=await l.t4.runPromiseExit(s.tryPromise({try:async()=>{let n=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null},catch:e=>new o.uV({message:`read file text ${t} failed`,cause:e})}));"Success"===n._tag&&n.value&&"string"==typeof n.value.content?i.set(t,n.value.content.split("\n")):"Failure"===n._tag&&console.error(`Failed to read file ${t}:`,n.cause)}));let c=[];for(let e of n){if(e.selectedText){c.push({...e,codeContent:e.selectedText});continue}let t=i.get(e.filePath),n="";if(t){let r=Math.max(0,e.startLine-1),s=Math.min(t.length,e.endLine);n=t.slice(r,s).join("\n")}c.push({...e,codeContent:n})}return c}async function h(e){let t=await l.t4.runPromiseExit((0,a.tj)(e));return"Success"===t._tag?(d(),!0):(console.error("Failed to clear comments:",t.cause),!1)}let m="__chat__";function f(e,t){let n=e.filter(e=>e.filePath===m),s=e.filter(e=>e.filePath!==m),l=[];for(let e of(s.length>0&&(l.push(`${r.A.t("comments.codeRef")}`,""),s.forEach((e,t)=>{let n=e.startLine>0||e.endLine>0?`:${e.startLine}-${e.endLine}`:"";l.push(`[${t+1}] ${e.filePath}${n}`),l.push("```"),l.push(e.codeContent),l.push("```"),e.note&&l.push(r.A.t("comments.note",{content:e.note})),l.push("")})),n)){let t=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");l.push(t),e.note&&l.push(e.note),l.push("")}if(t.trim()){for(;l.length>0&&""===l[l.length-1];)l.pop();l.push(t.trim())}return l.join("\n").trim()}function x(e,t,n){e(f([t],n))}},95045:(e,t,n)=>{n.d(t,{F:()=>o});var r=n(49433),s=n(88292),l=n(86957);let o=(e,t)=>{l.t4.runFork(r.flatMap(s.d,n=>n.publish(e,t)))}},95686:(e,t,n)=>{n.d(t,{x:()=>i});var r=n(95155),s=n(12115),l=n(64428),o=n(70188),a=n(5135);function i({filePath:e,content:t,cwd:n,onClose:c,zClassName:d="z-50"}){let[u,h]=(0,s.useState)(null);return(0,r.jsx)(l.ZL,{children:(0,r.jsx)("div",{className:`fixed inset-0 ${d} flex items-center justify-center bg-black/50 p-0 md:p-4`,onClick:c,children:(0,r.jsx)("div",{ref:h,className:"bg-card shadow-xl w-full h-full rounded-none md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col relative",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(o.SU,{container:u,children:(0,r.jsx)(a.M,{content:t,filePath:e,cwd:n,onClose:c})})})})})}},96497:(e,t,n)=>{function r(e,t){let n,r=document.caretRangeFromPoint(e.clientX,e.clientY);if(!r||!t.contains(r.startContainer))return 1;let s=r.startContainer,l=r.startOffset,o=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),a=1;for(;n=o.nextNode();){if(n===s){a+=l;break}a+=n.textContent?.length||0}return a}function s(e,t){if(0!==e.buttons)return null;let n=window.getSelection();if(n&&!n.isCollapsed)return null;let s=e.target;if("SPAN"!==s.tagName||!s.style.color)return null;let l=s.getBoundingClientRect();return{column:r(e,t),rect:{x:l.left,y:l.bottom+4}}}n.d(t,{A:()=>s,j:()=>r})},98036:(e,t,n)=>{n.d(t,{m3:()=>i,mi:()=>o,ot:()=>a});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok){let e;try{e=(await n.json()).error}catch{}throw Error(e||`HTTP ${n.status}`)}return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),o=()=>l("/api/html-apps"),a=e=>l("/api/html-apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})}),i=e=>l(`/api/html-apps/${encodeURIComponent(e)}`,{method:"DELETE"})}}]);
|
|
15
|
+
`:"")+"</task-notification>";t(t=>[...t,{id:n,role:"system",content:e.summary||"",systemEvent:{kind:"task-notification",...e.status?{status:e.status}:{},detail:r}}])}return}if("user"===e.type&&e._human){let n=e.message?.content,r="string"==typeof n?n:Array.isArray(n)?n.map(e=>e?.text||"").join(""):"",s="string"==typeof e._turnId?e._turnId:null,l="number"==typeof e._ts?e._ts:null,o=s?`live-user-${s}`:`live-user-${++c.current}`;t(e=>{if(s&&e.some(e=>e.id===o))return e;for(let t=e.length-1;t>=0;t--){if("user"!==e[t].role)continue;let n=e[t].timestamp?Date.parse(e[t].timestamp):NaN;if(null===l||Number.isNaN(n)){if(e[t].content===r)return e}else if(n>=l)return e;break}return[...e,{id:o,role:"user",content:r}]});return}"result"===e.type&&(d.current=!1);let n=i.current??u();t(t=>(0,l.F)(t,e,{engine:o,assistantId:n}))};(0,s.h)({url:e?`/ws/session-stream?sessionId=${encodeURIComponent(e)}`:"/ws/session-stream",enabled:n&&!!e,onMessage:e=>{if("run-snapshot"===e.type&&Array.isArray(e.events)){if("running"!==e.status)return void a?.onRunningChange?.(!1);let n=e.events.find(e=>e?.type==="user"&&e?._human),r=n?.message?.content,s="string"==typeof r?r:"",l=new Set,o=new Set;for(let t of e.events){let e=t?.uuid;if("string"==typeof e&&l.add(e),t?.type==="assistant"&&Array.isArray(t.message?.content))for(let e of t.message.content)e?.name&&"string"==typeof e.id&&o.add(e.id)}let u="number"==typeof e.startedAt?e.startedAt:null;for(let n of(t(e=>{let t=e.filter(e=>!("string"==typeof e.id&&e.id.startsWith("live-"))),n=t[t.length-1],r=n?.timestamp?Date.parse(n.timestamp):NaN;if(null!==u&&!Number.isNaN(r)){let e=t.length;for(;e>0;){let n=t[e-1],r=n.timestamp?Date.parse(n.timestamp):NaN;if(!Number.isNaN(r)&&r>=u)e--;else break}return e<t.length?t.slice(0,e):t}if(!s)return t;let a=-1;for(let e=t.length-1;e>=0;e--)if("user"===t[e].role){t[e].content===s&&(a=e);break}return -1===a?t:t.slice(a+1).every(e=>"assistant"===e.role&&("string"==typeof e.id&&l.has(e.id)||!!e.toolCalls?.length&&e.toolCalls.every(e=>o.has(e.id))))?t.slice(0,a):t}),i.current=null,c.current=0,d.current=!1,e.events))h(n);a?.onRunningChange?.(!0)}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type){a?.onRunningChange?.(!1),a?.onComplete?.();return}h(e.message),a?.onRunningChange?.(!0)}else"run-idle"===e.type&&a?.onRunningChange?.(!1)}})}},67589:(e,t,n)=>{n.d(t,{z:()=>a,m:()=>c});var r=n(12115),s=n(49433),l=n(86957),o=n(82680);let a=e=>s.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new o.uV({message:"session-by-path failed",cause:e})}),i=new Map;function c(e,t,n,{cwd:d,initialSessionId:u,onSessionId:h,onTitleChange:m,onTokenUsage:f,liveRunningRef:x}){let[p,g]=(0,r.useState)(!1),[b,v]=(0,r.useState)(!1),[y,w]=(0,r.useState)(!1),[k,j]=(0,r.useState)(void 0),[C,N]=(0,r.useState)(0),[S,L]=(0,r.useState)(null),[E,M]=(0,r.useState)(null),[R,T]=(0,r.useState)(null),$=(0,r.useRef)(m);$.current=m;let P=(0,r.useRef)(f);P.current=f;let I=(0,r.useRef)(void 0),A=(0,r.useRef)(0),_=(0,r.useCallback)(async(e,n,r=!1,s,o,c=!1)=>{if(r){let e=Date.now();if(!c&&e-A.current<5e3)return;A.current=e}let d=(e,r)=>{var s;e.fingerprint&&(I.current=e.fingerprint),void 0!==e.totalTurns&&N(e.totalTurns),void 0!==e.hasMore&&w(e.hasMore),e.messages&&e.messages.length>0&&(r?t(t=>(function(e,t){if(0===t.length)return e;let n=0;if(e.length>0&&e[0].id!==t[0].id){n=-1;for(let r=e.length-1;r>=0;r--)if(e[r].id===t[0].id){n=r;break}}if(n<0)return t;let r=e.slice(n),s=0;for(let e=0;e<Math.min(r.length,t.length)&&r[e].id===t[e].id&&r[e].content===t[e].content;e++)s=e+1;return s===r.length&&s===t.length?e:s===r.length&&s<t.length?[...e,...t.slice(s)]:[...e.slice(0,n),...r.slice(0,s),...t.slice(s)]})(t,e.messages)):x?.current||t(e.messages),L(n)),e.sessionId&&h(e.sessionId),e.engine&&M(e.engine),e.mode&&T((s=e.mode)?"builtin"===s?"builtin":"sdk":null),e.title&&$.current?.(e.title),e.usage&&P.current?.({inputTokens:e.usage.input_tokens||0,outputTokens:e.usage.output_tokens||0,cacheCreationInputTokens:e.usage.cache_creation_input_tokens||0,cacheReadInputTokens:e.usage.cache_read_input_tokens||0,totalCostUsd:0})},u=`${e}::${n}`,m=!r&&void 0===o,f=m?i.get(u):void 0;r||(f?d(f.data,!1):g(!0));try{let t={cwd:e,sessionId:n,limit:s,beforeTurnIndex:o};r&&I.current?t.ifFingerprint=I.current:f&&(t.ifFingerprint=f.fingerprint);let c=await l.t4.runPromiseExit(a(t));if("Success"===c._tag&&c.value){let e=c.value;if(e.notModified)return;if(d(e,r),m&&e.fingerprint&&e.messages&&e.messages.length>0&&(i.delete(u),i.set(u,{data:e,fingerprint:e.fingerprint}),i.size>20)){let e=i.keys().next().value;void 0!==e&&i.delete(e)}}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{r||g(!1)}},[t,h]),F=(0,r.useCallback)(async()=>{if(d&&n&&!b&&y){v(!0);try{let r=void 0!==k?k:C-Math.ceil(e.filter(e=>"user"===e.role).length),s=await l.t4.runPromiseExit(a({cwd:d,sessionId:n,limit:10,beforeTurnIndex:r>0?r:void 0}));if("Success"===s._tag&&s.value){let e=s.value;if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let s=e.messages.filter(e=>"user"===e.role).length;j(r-s),L(n)}void 0!==e.hasMore&&w(e.hasMore),e.fingerprint&&(I.current=e.fingerprint)}else"Failure"===s._tag&&console.error("Failed to load more history:",s.cause)}finally{v(!1)}}},[d,n,b,y,k,C,e,t]),D=(0,r.useCallback)(async e=>{g(!0);let n=s.tryPromise({try:async()=>{let t=await fetch(`/api/session/${e}/history`);return t.ok?await t.json():null},catch:e=>new o.uV({message:"load session history failed",cause:e})}),r=await l.t4.runPromiseExit(n);"Success"===r._tag&&r.value?.messages&&r.value.messages.length>0?(t(r.value.messages),L(e)):"Failure"===r._tag&&console.error("Failed to load history:",r.cause),g(!1)},[t]);return(0,r.useEffect)(()=>{d&&u&&_(d,u,!1,10)},[]),{isLoadingHistory:p,isLoadingMore:b,hasMoreHistory:y,loadMoreHistory:F,loadHistory:D,loadHistoryByCwdAndSessionId:_,loadedSessionId:S,loadedEngine:E,loadedMode:R}}},70188:(e,t,n)=>{n.d(t,{Ee:()=>h,SU:()=>c,ft:()=>u,iN:()=>d});var r=n(95155),s=n(12115),l=n(79114),o=n(47650),a=n(34075);let i=(0,s.createContext)(null);function c({container:e,children:t}){return(0,r.jsx)(i.Provider,{value:e,children:t})}function d(){return(0,s.useContext)(i)}function u({x:e,y:t,path:n,cwd:c,isDirectory:d,onClose:h,onCreateFile:m,onDelete:f,onRefresh:x,onCopyFile:p,onPaste:g,onExplain:b,explainDisabled:v}){let{t:y}=(0,l.Bd)(),w=(0,s.useRef)(null),k=(0,s.useContext)(i),j=n.split("/").pop()||n,C=`${c}/${n}`,N=n.includes("/")?n.substring(0,n.lastIndexOf("/")):"",S=N?`${c}/${N}`:c,L=d?n:N,E=d?C:S;(0,s.useEffect)(()=>{let e=e=>{w.current&&!w.current.contains(e.target)&&h()},t=e=>{"Escape"===e.key&&h()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[h]);let[M,R]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(w.current&&k){let n=k.getBoundingClientRect(),r=w.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s=Math.min(s,n.width-r.width-8),l=Math.min(l,n.height-r.height-8),R({x:s=Math.max(8,s),y:l=Math.max(8,l)})}else if(w.current){let n=w.current.getBoundingClientRect();R({x:Math.max(8,Math.min(e,window.innerWidth-n.width-8)),y:Math.max(8,Math.min(t,window.innerHeight-n.height-8))})}},[e,t,k]);let T=(0,s.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(e),(0,a.oR)(y("toast.copiedName",{name:t}),"success")}catch{(0,a.oR)(y("toast.copyFailed"),"error")}h()},[h,y]),$=d?n:N,P=!!b&&!d,I=[{label:y("fileContextMenu.copyRelativePath"),value:n},{label:y("fileContextMenu.copyAbsolutePath"),value:C},{label:y("fileContextMenu.copyRelativeDirPath"),value:L||"."},{label:y("fileContextMenu.copyAbsoluteDirPath"),value:E},{label:d?y("fileContextMenu.copyFolderName"):y("fileContextMenu.copyFileName"),value:j}],A=(0,r.jsxs)("div",{ref:w,className:"absolute z-[200] bg-card border border-border rounded-lg shadow-lg py-1 w-fit whitespace-nowrap",style:{left:M.x,top:M.y},children:[P&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent",disabled:v,title:v?y("comments.aiResponding"):void 0,onClick:()=>{h(),b(n)},children:y("explain.action")}),P&&(0,r.jsx)("div",{className:"my-1 border-t border-border"}),m&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{h(),m($)},children:y("fileContextMenu.createFile")}),p&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{h(),p(n)},children:d?y("fileContextMenu.copyFolder"):y("fileContextMenu.copyFile")}),g&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{h(),g($)},children:y("fileContextMenu.pasteHere")}),f&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-destructive hover:bg-accent transition-colors",onClick:()=>{h(),f(n,d,j)},children:d?y("fileContextMenu.deleteFolder"):y("fileContextMenu.deleteFile")}),!!(m||p||g||f)&&(0,r.jsx)("div",{className:"my-1 border-t border-border"}),I.map((e,t)=>(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>T(e.value,e.label),children:e.label},t))]});return k?(0,o.createPortal)(A,k):A}function h(){let[e,t]=(0,s.useState)(null);return{contextMenu:e,showContextMenu:(0,s.useCallback)((e,n,r)=>{e.preventDefault(),e.stopPropagation(),t({x:e.clientX,y:e.clientY,path:n,isDirectory:r})},[]),hideContextMenu:(0,s.useCallback)(()=>{t(null)},[])}}},73013:(e,t,n)=>{n.d(t,{M:()=>ef});var r=n(95155),s=n(12115),l=n(83897),o=n(64428),a=n(34075),i=n(54731),c=n(1709),d=n(12651),u=n(81165),h=n(16950),m=n(11019),f=n(12612),x=n(79114),p=n(86957),g=n(67589);function b({cwd:e,sessionId:t,toolCall:n,workflowRef:l,onClose:a}){let{t:i}=(0,x.Bd)(),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(null),[m,f]=(0,s.useState)(!1),v=(0,s.useRef)(void 0),y=l?!!l.running:!n?.result,w=(0,s.useCallback)(async()=>{let r=await p.t4.runPromiseExit((0,g.z)({cwd:e,sessionId:t,...l?{workflowId:l.runId,workflowAgentId:l.agentId}:{toolUseId:n?.id},ifFingerprint:v.current}));if(f(!0),"Success"!==r._tag||!r.value)return;let s=r.value;s.fingerprint&&(v.current=s.fingerprint),!s.notModified&&(s.messages&&d(s.messages),s.subagent&&h(s.subagent))},[e,t,n?.id,l?.runId,l?.agentId]);(0,s.useEffect)(()=>{if(w(),!y)return;let e=setInterval(w,5e3);return()=>clearInterval(e)},[y,w]);let k=(0,s.useRef)(null),j=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let e=k.current;e&&j.current&&(e.scrollTop=e.scrollHeight)},[c]);let C="string"==typeof n?.input?.description?n.input.description:"",N=l?l.label||"":[u?.agentType,C].filter(Boolean).join(" \xb7 ");return(0,r.jsx)(o.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:a,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-base",children:"\uD83E\uDD16"}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:i("chat.subagent")}),N&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0","data-tooltip":N,children:N}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[y&&(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("button",{onClick:a,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{ref:k,onScroll:()=>{let e=k.current;e&&(j.current=e.scrollTop+e.clientHeight>=e.scrollHeight-40)},className:"flex-1 overflow-y-auto px-4 py-3",children:null===c?(0,r.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:i(m?"chat.subagentEmpty":"common.loading")}):c.map(t=>(0,r.jsx)(ea,{message:t,cwd:e},t.id))})]})})})}function v(e){return e?e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e):"0"}function y(e){if(!e)return"–";let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return`${n}m${t%60}s`}let w={done:"text-green-9",running:"text-brand",queued:"text-muted-foreground",error:"text-red-9",failed:"text-red-9"};function k({cwd:e,sessionId:t,runId:n,isRunning:l,onClose:a}){let{t:i}=(0,x.Bd)(),[c,d]=(0,s.useState)(null),[u,h]=(0,s.useState)(!1),[m,f]=(0,s.useState)(null),w=(0,s.useRef)(void 0),C=l||null!=c&&"completed"!==c.status&&"failed"!==c.status,N=(0,s.useCallback)(async()=>{let r=await p.t4.runPromiseExit((0,g.z)({cwd:e,sessionId:t,workflowId:n,ifFingerprint:w.current}));if(h(!0),"Success"!==r._tag||!r.value)return;let s=r.value;s.fingerprint&&(w.current=s.fingerprint),!s.notModified&&s.workflow&&d(s.workflow)},[e,t,n]);(0,s.useEffect)(()=>{if(N(),!C)return;let e=setInterval(N,5e3);return()=>clearInterval(e)},[C,N]);let S=[];if(c?.agents){let e=new Map;for(let t of c.agents){let n=t.phaseTitle||i("chat.workflowUngrouped");e.has(n)||e.set(n,[]),e.get(n).push(t)}for(let[t,n]of e)S.push({title:t,agents:n})}let L=c?[c.workflowName,c.status,`${c.agentCount??c.agents?.length??0} ${i("chat.workflowAgents")}`,`${v(c.totalTokens)} tok`,y(c.durationMs)].filter(Boolean).join(" \xb7 "):"";return(0,r.jsxs)(o.ZL,{children:[(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:a,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsx)("span",{className:"text-base",children:"\uD83E\uDDE9"}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:i("chat.workflowRun")}),L&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0","data-tooltip":L,children:L}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2 flex-shrink-0",children:[C&&(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("button",{onClick:a,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:null===c?(0,r.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:i(u?"chat.workflowEmpty":"common.loading")}):(0,r.jsxs)(r.Fragment,{children:[c.summary&&(0,r.jsx)("div",{className:"mb-3 text-xs text-muted-foreground whitespace-pre-wrap",children:c.summary}),S.map(e=>(0,r.jsxs)(s.Fragment,{children:[(0,r.jsx)("div",{className:"text-xs font-semibold text-foreground/80 mt-3 mb-1 sticky top-0 bg-card py-1",children:e.title}),e.agents.map(e=>(0,r.jsx)(j,{agent:e,onOpen:()=>e.agentId&&f({runId:n,agentId:e.agentId,label:e.label,running:"done"!==e.state&&C})},`${e.index}-${e.agentId}`))]},e.title))]})})]})}),m&&(0,r.jsx)(b,{cwd:e,sessionId:t,workflowRef:m,onClose:()=>f(null)})]})}function j({agent:e,onOpen:t}){let{t:n}=(0,x.Bd)(),[l,o]=(0,s.useState)(!1),a=e.state&&w[e.state]||"text-muted-foreground",i=e.resultPreview||e.promptPreview||"";return(0,r.jsxs)("div",{className:"border border-border rounded-md mb-1 bg-secondary/50",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5",children:[(0,r.jsx)("button",{onClick:()=>o(e=>!e),className:"text-slate-9 text-xs flex-shrink-0",title:n(l?"chat.collapse":"chat.expand"),children:l?"▲":"▼"}),(0,r.jsx)("span",{className:"text-xs text-foreground truncate flex-1 min-w-0","data-tooltip":e.label||"",children:e.label||e.agentId}),(0,r.jsx)("span",{className:`text-[10px] flex-shrink-0 ${a}`,children:e.state}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[v(e.tokens)," tok \xb7 ",y(e.durationMs)]}),e.agentId&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:t,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&t()},className:"text-xs text-brand hover:text-teal-10 cursor-pointer flex-shrink-0",title:n("chat.subagentViewTitle"),children:n("chat.workflowViewAgent")})]}),l&&i&&(0,r.jsx)("pre",{className:"text-[11px] bg-secondary px-2 py-1.5 rounded-b overflow-x-auto max-h-32 overflow-y-auto text-muted-foreground whitespace-pre-wrap border-t border-border",children:i})]})}var C=n(60938),N=n(53377),S=n(38408),L=n(13219),E=n(47176),M=n(97251),R=n(34582),T=n(56045),$=n(50860),P=n(47215);function I({filePath:e}){let[t,n]=(0,s.useState)(null),[l,o]=(0,s.useState)(!0),[a,i]=(0,s.useState)(null),c=(0,s.useRef)(!1),d=(0,P.e$)(e),u=(0,P.u)(e);return((0,s.useEffect)(()=>{u?o(!1):c.current||(c.current=!0,(async()=>{o(!0),i(null);let t=await p.t4.runPromiseExit((0,C.nM)(e));if("Success"===t._tag)n(t.value.content??null);else{let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause;i(n instanceof Error?n.message:"Failed to load file")}o(!1),c.current=!1})())},[e,u]),a)?(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("div",{className:"text-xs text-red-11",children:a})}):l?(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:"Loading..."})}):(0,P.u)(e)?(0,r.jsx)($.I,{absPath:e,className:"flex items-center justify-center h-full overflow-auto",imgClassName:"max-w-full max-h-full object-contain",alt:e.split("/").pop()||"image"}):t?d?(0,r.jsx)(_,{content:t,filePath:e}):(0,r.jsx)(S.Cv,{content:t,filePath:e,showLineNumbers:!0,showSearch:!0,className:"h-full"}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:"No content"})})}let A=[M.W];function _({content:e,filePath:t}){let n=(0,s.useRef)(null),l=(0,s.useMemo)(()=>(0,R.J4)(t),[t]);return(0,r.jsxs)("div",{className:"h-full flex",children:[(0,r.jsx)(E.l,{content:e,containerRef:n}),(0,r.jsx)("div",{ref:n,className:"flex-1 overflow-auto p-4",children:(0,r.jsx)(L.T,{content:e,basePath:l,rehypePlugins:A})})]})}function F({title:e,content:t,toolName:n,onClose:l}){let{t:i}=(0,x.Bd)(),c=(0,P.jU)(t),d=(0,P.zs)(t),u=(0,P.oK)(t),h=!!d,m=!!u,[f,p]=(0,s.useState)(("Read"===n||"Write"===n)&&m?"file":h?"diff-unified":c?"readable":"json"),g=(0,s.useRef)(null),b=(0,T.o)(g);(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&"readable"===f&&c){e.preventDefault(),b.open();return}if("Escape"===e.key){if(b.isVisible)return void b.close();document.activeElement instanceof HTMLElement&&document.activeElement.blur(),l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[l,f,c,b]);let v=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-0 md:p-4",onClick:l,children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full max-w-[90%] h-full md:h-[90vh] rounded-none md:rounded-lg flex flex-col transition-all",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:e}),u&&(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(u),(0,a.oR)(i("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:i("common.copyAbsPath"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[c&&(0,r.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[h&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("button",{onClick:()=>p("diff-split"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-split"===f?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.sideBySide"),children:"Split"}),(0,r.jsx)("button",{onClick:()=>p("diff-unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-unified"===f?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.unified"),children:"Unified"})]}),m&&(0,r.jsx)("button",{onClick:()=>p("file"),className:`px-2 py-1 text-xs rounded transition-colors ${"file"===f?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:i("diffViewer.previewFile"),children:"File"}),(0,r.jsx)("button",{onClick:()=>p("readable"),className:`px-2 py-1 text-xs rounded transition-colors ${"readable"===f?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("common.readable")}),(0,r.jsx)("button",{onClick:()=>p("json"),className:`px-2 py-1 text-xs rounded transition-colors ${"json"===f?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"JSON"})]}),(0,r.jsx)("button",{onClick:l,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-auto p-4",children:"file"===f&&u?(0,r.jsx)(I,{filePath:u}):"diff-unified"===f&&d?(0,r.jsx)(N.xU,{oldContent:d.old_string,newContent:d.new_string,filePath:d.file_path}):"diff-split"===f&&d?(0,r.jsx)(N.xZ,{oldContent:d.old_string,newContent:d.new_string,filePath:d.file_path}):"readable"===f&&c?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(T._,{search:b}),(0,r.jsx)("pre",{ref:g,className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:(0,P.xb)(t)})]}):(0,r.jsx)("pre",{className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:c?(0,P.C6)(t):t})})]})});return(0,r.jsx)(o.ZL,{children:v})}let D={Read:"\uD83D\uDCC4",Write:"✏️",Edit:"\uD83D\uDCDD",ApplyPatch:"\uD83E\uDDE9",Bash:"\uD83D\uDCBB",Glob:"\uD83D\uDD0D",Grep:"\uD83D\uDD0E",WebFetch:"\uD83C\uDF10",WebSearch:"\uD83D\uDD0D",Workflow:"\uD83E\uDDE9",Skill:"\uD83D\uDEE0️"};function B(e){return"object"==typeof e&&null!==e}function W({toolCall:e,cwd:t,sessionId:n}){var l;let{t:o}=(0,x.Bd)(),[i,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)(null),[h,m]=(0,s.useState)(!1),[f,p]=(0,s.useState)(!1),g=D[e.name]||"\uD83D\uDD27",v="Agent"===e.name||"Task"===e.name,y=v&&!!t&&!!n,w="Workflow"===e.name,j=w&&(l=e.result)?l.match(/subagents\/workflows\/(wf_[A-Za-z0-9_-]+)/)?.[1]??null:null,C=w&&!!j&&!!t&&!!n,N="Skill"===e.name,S="ApplyPatch"===e.name||v||w||N,L=e=>{if(t&&e.startsWith(t)){let n=e.slice(t.length);return n.startsWith("/")?n.slice(1):n}let n=e.split("/");return n.length>2?".../"+n.slice(-2).join("/"):e},E=(()=>{let t=e.input;if("Bash"===e.name&&t.command&&"string"==typeof t.command)return t.command;if("ApplyPatch"===e.name&&Array.isArray(t.changes)){let e=t.changes.filter(B).flatMap(e=>{let t="string"==typeof e.path?e.path:"";if(!t)return[];let n="string"==typeof e.kind&&e.kind?e.kind:"update";return`${n} ${L(t)}`});if(e.length>0)return e.join(" \xb7 ")}if(v&&t.description&&"string"==typeof t.description)return t.description;if(w){let e=["string"==typeof t.name?t.name:"","string"==typeof t.args?t.args:"string"==typeof t.resumeFromRunId?t.resumeFromRunId:""].filter(Boolean).join(" \xb7 ");if(e)return e}if(N&&"string"==typeof t.skill){let e="string"==typeof t.args?t.args:"";return[t.skill,e].filter(Boolean).join(" \xb7 ")}return"Glob"===e.name&&t.pattern&&"string"==typeof t.pattern||"Grep"===e.name&&t.pattern&&"string"==typeof t.pattern?t.pattern:"ToolSearch"===e.name&&t.query&&"string"==typeof t.query?t.query:"TaskCreate"===e.name&&t.subject&&"string"==typeof t.subject?t.subject:t.file_path&&"string"==typeof t.file_path?t.file_path:t.path&&"string"==typeof t.path?t.path:null})(),M="Glob"===e.name||"Grep"===e.name||"Bash"===e.name||"ApplyPatch"===e.name||v||w||N,R=E?M?E:L(E):null,T=t=>{let n="input"===t?o("toolCall.inputParams"):o("toolCall.resultLabel"),r="input"===t?JSON.stringify(e.input,null,2):"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2);u({title:`${e.name}${R?` ${R}`:""} - ${n}`,content:r,toolName:e.name})};return(0,r.jsxs)("div",{className:"my-1 border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("button",{onClick:()=>c(!i),className:"w-full px-3 py-1.5 flex items-center gap-2 text-left hover:bg-accent transition-colors",children:[(0,r.jsx)("span",{className:"text-sm",children:g}),(0,r.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:e.name}),R&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0","data-tooltip":E||"",children:R}),!S&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),E&&(navigator.clipboard.writeText(E),(0,a.oR)(o("common.copiedPath")))},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),E&&(navigator.clipboard.writeText(E),(0,a.oR)(o("common.copiedPath"))))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0 cursor-pointer",title:o("common.copyAbsPath"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,r.jsxs)("span",{className:"ml-auto flex items-center gap-2",children:[y&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),m(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),m(!0))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:o("chat.subagentViewTitle"),children:o("chat.subagent")}),C&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),p(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),p(!0))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:o("chat.workflowViewTitle"),children:o("chat.workflowRun")}),i&&!e.isLoading&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),T("input")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),T("input"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:o("toolCall.inputParamsTitle"),children:o("toolCall.input")}),e.result&&(0,r.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),T("result")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),T("result"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:o("toolCall.resultTitle"),children:o("toolCall.result")})]}),e.isLoading?(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}):(0,r.jsx)("span",{className:"text-slate-9 text-xs",children:i?"▲":"▼"})]})]}),i&&(0,r.jsxs)("div",{className:"border-t border-border",children:[(0,r.jsxs)("div",{className:"px-3 py-2",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[o("toolCall.inputParams"),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:JSON.stringify(e.input,null,2)})]}),e.result&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[o("toolCall.resultLabel"),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2)})]}),e.skillContent&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,r.jsx)("div",{className:"mb-1",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[o("toolCall.skillContent",{defaultValue:"Skill content"}),":"]})}),(0,r.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-60 overflow-y-auto text-foreground whitespace-pre-wrap",children:e.skillContent})]})]}),d&&(0,r.jsx)(F,{title:d.title,content:d.content,toolName:d.toolName,onClose:()=>u(null)}),h&&t&&n&&(0,r.jsx)(b,{cwd:t,sessionId:n,toolCall:e,onClose:()=>m(!1)}),f&&t&&n&&j&&(0,r.jsx)(k,{cwd:t,sessionId:n,runId:j,isRunning:!!e.isLoading,onClose:()=>p(!1)})]})}var V=n(62111),O=n(56204),z=n(67635),H=n(33210),q=n(58515),U=n(36201),K=n(55804),Z=n(37618);function J(e){let t=e.input?.questions||[],n=e.input?.answers||{},r={};if(e.result)try{let t=JSON.parse(e.result);t?.answers&&(r=t.answers)}catch{}return{questions:t,answers:{...n,...r}}}function X(e,t){return`${e}-${t}`}function G({toolCalls:e,onClose:t}){let{t:n}=(0,x.Bd)(),i=(0,l.nH)(),[c,d]=(0,s.useState)({}),[u,h]=(0,s.useState)({}),[m,f]=(0,s.useState)({}),[p,g]=(0,s.useState)({});(0,s.useEffect)(()=>{let t={};e.forEach((e,n)=>{let{questions:r,answers:s}=J(e);r.forEach((e,r)=>{let l=s[e.question];if(l){let s=X(n,r);t[s]=l,e.options.some(e=>e.label===l)||(h(e=>({...e,[s]:!0})),f(e=>({...e,[s]:l})))}})}),queueMicrotask(()=>d(t))},[e]),(0,V.E)(t);let b=e.reduce((e,t)=>{let{questions:n}=J(t);return e+n.length},0),v=Object.values(p).filter(Boolean).length,y=(0,s.useCallback)((e,t)=>{d(n=>({...n,[e]:t})),h(t=>({...t,[e]:!1}))},[]),w=(0,s.useCallback)(e=>{h(t=>{let n=!t[e];if(n){let t=m[e]||"";t&&d(n=>({...n,[e]:t}))}return{...t,[e]:n}})},[m]),k=(0,s.useCallback)((e,t)=>{f(n=>({...n,[e]:t})),t&&d(n=>({...n,[e]:t}))},[]),j=(0,s.useCallback)(e=>{g(t=>({...t,[e]:!t[e]}))},[]),C=(0,s.useCallback)(()=>{let t=v>0,r=[];return e.forEach((e,s)=>{let{questions:l}=J(e);l.forEach((e,l)=>{let o=X(s,l);if(t&&!p[o])return;let a=c[o];r.push(`Q: ${e.question}`),r.push(`A: ${a||n("askQuestion.notSelected")}`),r.push("")})}),r.join("\n").trim()},[e,c,p,v,n]),N=(0,s.useCallback)(()=>{navigator.clipboard.writeText(C()),(0,a.oR)(v>0?n("toast.copiedQA",{count:v}):n("toast.copiedAllQA"))},[C,v,n]),S=(0,s.useCallback)(()=>{i?(i.sendMessage(C()),(0,a.oR)(n("toast.sentQA")),t()):(0,a.oR)(n("askQuestion.sendNoChat"))},[i,C,t,n]),L=(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,r.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-foreground",children:n("askQuestion.title")}),(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[n("askQuestion.nQuestions",{count:b}),v>0&&` \xb7 ${n("askQuestion.checkedN",{count:v})}`]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:S,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v>0?n("askQuestion.sendChecked",{count:v}):n("askQuestion.sendAll"),children:(0,r.jsx)(O.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{onClick:N,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v>0?n("askQuestion.copyChecked",{count:v}):n("askQuestion.copyAll"),children:(0,r.jsx)(z.A,{className:"w-4 h-4"})}),(0,r.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,r.jsx)(H.A,{className:"w-5 h-5"})})]})]}),(0,r.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-6",children:e.map((t,s)=>{let{questions:l}=J(t);return l.map((t,o)=>{let a=X(s,o),i=c[a],d=u[a]||!1,h=p[a]||!1;return(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-start gap-2",children:[(0,r.jsx)("button",{onClick:()=>j(a),className:"mt-0.5 flex-shrink-0 p-0.5 rounded hover:bg-accent transition-colors",title:n("askQuestion.checkToCopy"),children:h?(0,r.jsx)(q.A,{className:"w-4 h-4 text-brand"}):(0,r.jsx)(U.A,{className:"w-4 h-4 text-muted-foreground"})}),t.header&&(0,r.jsx)("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-brand/10 text-brand flex-shrink-0 mt-0.5",children:t.header}),(0,r.jsx)("span",{className:"text-sm font-medium text-foreground",children:t.question})]}),(0,r.jsxs)("div",{className:"space-y-1 ml-7",children:[t.options.map((e,t)=>{let n=i===e.label&&!d;return(0,r.jsxs)("button",{onClick:()=>y(a,e.label),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${n?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,r.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:n?(0,r.jsx)(K.A,{className:"w-3.5 h-3.5 text-brand"}):(0,r.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,r.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,r.jsx)("div",{className:`text-sm ${n?"text-foreground font-medium":"text-foreground"}`,children:e.label}),e.description&&(0,r.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.description})]})]},t)}),(0,r.jsxs)("button",{onClick:()=>w(a),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${d?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,r.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:d?(0,r.jsx)(K.A,{className:"w-3.5 h-3.5 text-brand"}):(0,r.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsx)(Z.A,{className:"w-3.5 h-3.5 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-sm text-muted-foreground",children:n("askQuestion.custom")})]})]}),d&&(0,r.jsx)("div",{className:"ml-6 mt-1",children:(0,r.jsx)("input",{type:"text",autoFocus:!0,value:m[a]||"",onChange:e=>k(a,e.target.value),placeholder:n("askQuestion.customPlaceholder"),className:"w-full px-3 py-1.5 text-sm bg-background border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-brand text-foreground"})})]}),(s!==e.length-1||o!==l.length-1)&&(0,r.jsx)("div",{className:"border-b border-border/50 mt-3"})]},a)})})})]})});return(0,r.jsx)(o.ZL,{children:L})}var Q=n(38987),Y=n(9573),ee=n(4055),et=n(24602),en=n(95686),er=n(83448);function es({image:e,onClose:t}){let{t:n}=(0,x.Bd)(),s=(0,r.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,r.jsx)("button",{onClick:t,className:"absolute top-4 right-4 w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",children:(0,r.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:n("chat.imagePreview"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,r.jsx)(o.ZL,{children:s})}function el({filePath:e,onClose:t}){return(0,r.jsx)(o.ZL,{children:(0,r.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,r.jsx)("button",{onClick:t,className:"absolute top-4 right-4 w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",children:(0,r.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),(0,r.jsx)("img",{src:`/api/file?path=${encodeURIComponent(e)}&raw=true`,alt:e.split("/").pop(),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]})})}let eo=(0,s.memo)(function({text:e,isAside:t,isUser:n,isStreaming:l,onOpenFileLink:o,cwd:a}){let c=(0,s.useMemo)(()=>{if(!n&&o)return e=>{let t=function(e,t){let n;if(!e||e.startsWith("#")||/^[a-z][a-z0-9+.-]*:/i.test(e)&&!e.startsWith("file:"))return null;let r=e;try{r=decodeURIComponent(e)}catch{}r.startsWith("file://")&&(r=r.slice(7));let s=r.indexOf("#"),l=s>=0?r.slice(s+1):"",o=s>=0?r.slice(0,s):r,a=o.indexOf("?"),i=a>=0?o.slice(a+1):"";o=a>=0?o.slice(0,a):o;let c=l.match(/^L?(\d+)(?:-L?\d+)?$/i)?.[1],d=i.match(/(?:^|[&;])(?:line|L)=(\d+)(?:$|[&;])/i)?.[1],u=o.match(/:(\d+)(?::\d+)?$/),h=c||d||u?.[1];if(h&&(n=Number(h),u&&(o=o.slice(0,-u[0].length))),!(o=o.trim()))return null;if(t&&o.startsWith(t+"/"))o=o.slice(t.length+1);else{if(t&&o===t)return null;o.startsWith("/")&&(o=o.slice(1))}return o.startsWith("./")||o.startsWith("../")||o.includes("/")||/\.[A-Za-z0-9][A-Za-z0-9_-]*$/.test(o)?{path:(0,P.WU)("",o),...n&&n>0?{lineNumber:n}:{}}:null}(e,a);return!!t&&(o(t),!0)}},[a,n,o]),d=(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(L.T,{content:e,isUser:n,isStreaming:l,enableMath:!1,onLinkClick:c}),l&&(0,r.jsx)("span",{className:"inline-block w-2 h-4 ml-1 bg-current animate-pulse"})]});return t?(0,r.jsxs)("div",{className:"flex gap-1.5 break-words opacity-65",children:[(0,r.jsx)(i.A,{className:"w-3 h-3 mt-[5px] shrink-0 text-muted-foreground","aria-hidden":!0}),(0,r.jsx)("div",{className:"flex-1 min-w-0",children:d})]}):(0,r.jsx)("div",{className:"break-words",children:d})}),ea=(0,s.memo)(function({message:e,cwd:t,sessionId:n,onFork:l,forkSupported:i=!0,onApprovePlan:g,isLoading:b,onContentSearch:v,onShowFileDiff:y,onOpenFileLink:w}){let k,j,C,N,{t:S}=(0,x.Bd)(),[E,M]=(0,s.useState)(null),[R,T]=(0,s.useState)(()=>1===(e.toolCalls?.length||0)),[$,I]=(0,s.useState)(!1),[A,_]=(0,s.useState)(!1),[F,D]=(0,s.useState)(!1),B="user"===e.role,V=e.images&&e.images.length>0,O=e.toolCalls?.length||0,z=!!n&&!!t&&!!l&&i,H=(0,s.useMemo)(()=>e.toolCalls?.some(e=>(0,ee.h)(e.name))||!1,[e.toolCalls]),q=(0,s.useMemo)(()=>{let t=e.parts;if(!t?.length)return e.content?[{text:e.content,isAside:!1}]:[];let n=-1;t.forEach((e,t)=>{"tool"===e.type&&(n=t)});let r=[];return t.forEach((e,t)=>{"text"===e.type&&r.push({text:e.text,isAside:t<n})}),r},[e.parts,e.content]),U=(0,s.useMemo)(()=>(0,Q.vP)([],e.toolCalls??[],t).length>0,[e.toolCalls,t]),[K,Z]=(0,s.useState)(!1),J=U||K;(0,s.useEffect)(()=>{if(!H||U||!t)return;let r=(e.toolCalls??[]).map(e=>e.id).filter(Boolean);if(0===r.length)return;let s=(e.toolCalls??[]).filter(e=>(0,ee.h)(e.name)).map(e=>e.id),l=!1,o=null,a=0,i=()=>{p.t4.runPromiseExit((0,Y.xK)(t,r,n??void 0)).then(e=>{if(l)return;let t="Success"===e._tag?e.value:[];if(t.length>0)return void Z(!0);let n=new Set(t.map(e=>e.toolId));s.some(e=>!n.has(e))&&a<2&&(a+=1,o=setTimeout(i,2e3))})};return i(),()=>{l=!0,o&&clearTimeout(o)}},[H,U,t,n,e.toolCalls]);let X=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("TodoWrite"===e.toolCalls[t].name)return e.toolCalls[t];return null},[e.toolCalls]),ea=(0,s.useMemo)(()=>e.toolCalls?e.toolCalls.filter(e=>"AskUserQuestion"===e.name):[],[e.toolCalls]),ei=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("ExitPlanMode"===e.toolCalls[t].name){let n=e.toolCalls[t].input?.plan;return"string"==typeof n&&n?n:null}return null},[e.toolCalls]),ec=(0,s.useMemo)(()=>e.toolCalls?.filter(e=>"ExitPlanMode"!==e.name)??[],[e.toolCalls]),ed=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=new Set,n=[];for(let r of e.toolCalls)if("Read"===r.name||"Edit"===r.name||"Write"===r.name){let e=r.input.file_path;e&&((0,P.e$)(e)||(0,P.aR)(e)||(0,P.u)(e))&&!t.has(e)&&(t.add(e),n.push(e))}return n},[e.toolCalls]),eu=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=[];for(let n of e.toolCalls){let e=n.input?.thought;if(e&&"string"==typeof e){let r=e.match(/PREVIOUS:\s*(.*?)\s*→\s*THIS:\s*(.*?)\s*→\s*EXPECT:\s*(.*)/i);r?t.push({previous:r[1].trim(),current:r[2].trim(),expect:r[3].trim(),raw:e,toolName:n.name}):t.push({previous:"",current:e,expect:"",raw:e,toolName:n.name})}}return t},[e.toolCalls]),[eh,em]=(0,s.useState)(null),[ef,ex]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!eh||(0,P.u)(eh))return void queueMicrotask(()=>ex(null));let e=!1;return p.t4.runPromiseExit((0,er.an)(eh)).then(t=>{e||("Success"===t._tag&&void 0!==t.value.content?ex(t.value.content):((0,a.oR)(S("toast.readFileFailed"),"error"),em(null)))}),()=>{e=!0}},[eh,S]);let ep=()=>{e.content&&(navigator.clipboard.writeText(e.content),(0,a.oR)(S("toast.copiedMessage")))},eg=()=>{z&&l(e.id,"prefix")},eb=()=>{z&&l(e.id,"single")},ev=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),l=String(t.getMinutes()).padStart(2,"0");return`${n}-${r} ${s}:${l}`})(e.timestamp);if("system"===e.role){let t=e.systemEvent,n=t?.kind==="task-notification"?"failed"===t.status?"⚠️":"stopped"===t.status?"⏹️":"\uD83D\uDD14":"ℹ️",s=t?.detail||e.content;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"flex justify-center my-2 px-2","data-role":"system",children:(0,r.jsxs)("button",{type:"button",onClick:()=>D(!0),className:"flex items-center gap-1.5 max-w-[85%] text-[11px] text-muted-foreground bg-secondary/40 border border-border/50 rounded-full px-3 py-1 hover:bg-secondary hover:text-foreground transition-colors cursor-pointer",title:S("chat.viewDetails",{defaultValue:"Click for details"}),children:[(0,r.jsx)("span",{className:"flex-shrink-0",children:n}),(0,r.jsx)("span",{className:"truncate",children:e.content})]})}),F&&(0,r.jsx)(o.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:()=>D(!1),children:(0,r.jsxs)("div",{className:"bg-card shadow-xl w-full max-w-4xl max-h-[80vh] rounded-lg flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,r.jsxs)("span",{className:"text-sm text-foreground flex items-center gap-1.5",children:[(0,r.jsx)("span",{children:n}),t?.kind==="task-notification"?S("chat.taskNotification",{defaultValue:"Task notification"}):S("chat.systemNotice",{defaultValue:"Notice"})]}),(0,r.jsx)("button",{onClick:()=>D(!1),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-accent transition-colors",children:"✕"})]}),(0,r.jsx)("pre",{className:"flex-1 overflow-auto px-4 py-3 text-xs text-foreground whitespace-pre-wrap break-words",children:s})]})})})]})}return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:`flex flex-col ${B?"items-end":"items-start"} mb-4 group`,"data-role":e.role,children:[ev&&(0,r.jsx)("span",{className:"text-[11px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity mb-0.5 px-1",children:ev}),(0,r.jsxs)("div",{className:`flex items-start ${B?"justify-end":"justify-start"} w-full`,children:[B&&(0,r.jsxs)("div",{className:"self-start mt-2 mr-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,r.jsx)("button",{onClick:ep,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.copyMessage"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),z&&(0,r.jsx)("button",{onClick:eg,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.forkSession"),children:(0,r.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,r.jsx)("path",{d:"M12 12v3"})]})}),z&&(0,r.jsx)("button",{onClick:eb,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.excerptTurn"),children:(0,r.jsx)(c.A,{className:"w-4 h-4"})})]}),(0,r.jsxs)("div",{className:`max-w-[80%] ${B?"bg-accent text-foreground border border-brand rounded-2xl rounded-br-md":"bg-accent text-foreground dark:text-slate-11 rounded-2xl rounded-bl-md"} px-4 py-2`,children:[V&&(0,r.jsx)("div",{className:`flex flex-wrap gap-2 ${e.content?"mb-2":""}`,children:e.images.map((e,t)=>(0,r.jsx)("div",{className:"relative w-16 h-16 rounded-lg overflow-hidden border border-white/20 cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>M(e),children:(0,r.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:S("chat.imageN",{index:t+1}),className:"w-full h-full object-cover"})},t))}),q.length>0&&(0,r.jsx)("div",{className:"space-y-3",children:q.map((n,s)=>(0,r.jsx)(eo,{text:n.text,isAside:n.isAside,isUser:B,isStreaming:!!e.isStreaming&&s===q.length-1,onOpenFileLink:w,cwd:t},s))}),X&&(C=(j=Array.isArray(k=X.input?.todos)?k:[]).filter(e=>"completed"===e.status).length,N=j.length,(0,r.jsx)("div",{className:`${e.content||V?"mt-2":""}`,children:(0,r.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-1",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,r.jsx)("div",{className:"flex-1 h-1 bg-secondary rounded-full overflow-hidden",children:(0,r.jsx)("div",{className:"h-full bg-green-500 rounded-full transition-all duration-300",style:{width:`${N>0?C/N*100:0}%`}})}),(0,r.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[C,"/",N]})]}),j.map((e,t)=>(0,r.jsxs)("div",{className:`flex items-center gap-1.5 ${"completed"===e.status?"opacity-50":""}`,children:["completed"===e.status?(0,r.jsx)(d.A,{className:"w-3 h-3 text-green-500 flex-shrink-0"}):"in_progress"===e.status?(0,r.jsx)(u.A,{className:"w-3 h-3 text-brand flex-shrink-0 animate-spin"}):(0,r.jsx)(h.A,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),(0,r.jsx)("span",{className:`text-xs truncate ${"completed"===e.status?"text-muted-foreground":"text-foreground"}`,children:"in_progress"===e.status&&e.activeForm?e.activeForm:e.content})]},t))]})})),ei&&(0,r.jsx)("div",{className:`${e.content||V||X?"mt-2":""}`,children:(0,r.jsxs)("div",{className:"border border-brand/40 rounded-lg overflow-hidden bg-secondary/50",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-b border-border bg-brand/10",children:[(0,r.jsx)("span",{className:"text-sm",children:"\uD83D\uDCCB"}),(0,r.jsx)("span",{className:"text-xs font-medium text-foreground",children:S("chat.planTitle",{defaultValue:"Plan (awaiting your review)"})})]}),(0,r.jsx)("div",{className:"px-3 py-2",children:(0,r.jsx)(L.T,{content:ei,isUser:!1,enableMath:!1})}),g&&(0,r.jsxs)("div",{className:"px-3 py-2 border-t border-border flex items-center justify-between gap-2",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:S("chat.planApproveHint",{defaultValue:"本环境无审批弹窗,点此退出 Plan 并执行"})}),(0,r.jsxs)("button",{onClick:()=>g(),disabled:b,className:"flex items-center gap-1.5 px-3 py-1 rounded-md bg-brand text-white text-xs font-medium hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex-shrink-0",children:[(0,r.jsx)("span",{children:"✓"}),(0,r.jsx)("span",{children:S("chat.approvePlan",{defaultValue:"批准并执行"})})]})]})]})}),ed.length>0&&(0,r.jsx)("div",{className:`${e.content||V||X?"mt-2":""}`,children:(0,r.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-0.5",children:ed.map(e=>(0,r.jsxs)("button",{onClick:()=>em(e),className:"flex items-center gap-1.5 w-full text-left hover:bg-accent rounded px-1 py-0.5 transition-colors group/md",children:[(0,P.u)(e)?(0,r.jsxs)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 5a1 1 0 011-1h14a1 1 0 011 1v14a1 1 0 01-1 1H5a1 1 0 01-1-1V5z"}),(0,r.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5",fill:"currentColor",stroke:"none"}),(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4-4 3 3 4-4 5 5"})]}):(0,P.aR)(e)?(0,r.jsx)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})}):(0,r.jsx)("svg",{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground group-hover/md:text-foreground truncate",children:e.split("/").pop()})]},e))})}),eu.length>0&&(0,r.jsx)("div",{className:`${e.content||V||X||ed.length>0?"mt-2":""}`,children:(0,r.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50",children:(0,r.jsxs)("table",{className:"w-full text-xs",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b border-border text-muted-foreground",children:[(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium w-[60px]",children:"Tool"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Previous"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Action"}),(0,r.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Expect"})]})}),(0,r.jsx)("tbody",{children:eu.map((e,t)=>(0,r.jsxs)("tr",{className:t<eu.length-1?"border-b border-border/50":"",children:[(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground font-mono",children:e.toolName}),(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.previous||"—"}),(0,r.jsx)("td",{className:"px-2 py-1 text-foreground",children:e.current}),(0,r.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.expect||"—"})]},t))})]})})}),ec.length>0&&(0,r.jsx)("div",{className:`${e.content||V?"mt-2":""}`,children:O>0?(0,r.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,r.jsxs)("div",{className:"flex items-center",children:[(0,r.jsxs)("button",{onClick:()=>T(!R),className:"flex-1 px-3 py-1.5 flex items-center gap-2 text-left hover:bg-accent transition-colors active:bg-muted",children:[(0,r.jsx)("span",{className:"text-sm",children:"\uD83D\uDD27"}),(0,r.jsx)("span",{className:"font-medium text-foreground",children:S("chat.toolCalls",{count:ec.length})}),(0,r.jsx)("span",{className:"ml-auto text-muted-foreground text-sm",children:R?S("chat.collapse"):S("chat.expand")})]}),ea.length>0&&(0,r.jsx)("button",{onClick:()=>_(!0),className:"px-3 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:S("chat.viewQuestions"),children:(0,r.jsx)(m.A,{className:"w-4 h-4"})}),J&&(0,r.jsx)("button",{onClick:()=>{y&&e.toolCalls?y(e.toolCalls,t,n??void 0):I(!0)},className:"px-3 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:S("chat.viewAllFileChanges"),children:(0,r.jsx)(f.A,{className:"w-4 h-4"})})]}),R&&(0,r.jsx)("div",{className:"border-t border-border p-2 space-y-1",children:ec.map((e,s)=>(0,r.jsx)(W,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}):ec.map((e,s)=>(0,r.jsx)(W,{toolCall:e,cwd:t,sessionId:n},`${e.id}-${s}`))})]}),!B&&(0,r.jsxs)("div",{className:"self-start mt-2 ml-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,r.jsx)("button",{onClick:ep,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.copyMessage"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),z&&(0,r.jsx)("button",{onClick:eg,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.forkSession"),children:(0,r.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,r.jsx)("circle",{cx:"12",cy:"18",r:"3"}),(0,r.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,r.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,r.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,r.jsx)("path",{d:"M12 12v3"})]})}),z&&(0,r.jsx)("button",{onClick:eb,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:S("chat.excerptTurn"),children:(0,r.jsx)(c.A,{className:"w-4 h-4"})})]})]})]}),E&&(0,r.jsx)(es,{image:E,onClose:()=>M(null)}),$&&e.toolCalls&&(0,r.jsx)(Q.zB,{toolCalls:e.toolCalls,cwd:t,sessionId:n??void 0,onClose:()=>I(!1),onContentSearch:v}),A&&ea.length>0&&(0,r.jsx)(G,{toolCalls:ea,onClose:()=>_(!1)}),eh&&(0,P.u)(eh)&&(0,r.jsx)(el,{filePath:eh,onClose:()=>em(null)}),eh&&!(0,P.u)(eh)&&null!==ef&&((0,P.aR)(eh)?(0,r.jsx)(et.N,{filePath:eh,content:ef,cwd:t,onClose:()=>em(null),onContentSearch:v}):(0,r.jsx)(en.x,{filePath:eh,content:ef,cwd:t||"",onClose:()=>em(null)}))]})});var ei=n(1058),ec=n(90717),ed=n(89109),eu=n(7320);let eh=/[,,]/;function em({initialRows:e,lang:t,isCustomized:n,onSave:l,onRestoreDefault:a,onClose:i}){let{t:c}=(0,x.Bd)(),[d,u]=(0,s.useState)(()=>e.map(e=>e.join("zh"===t?",":", ")).join("\n"));(0,V.E)(i);let h=(0,s.useCallback)(()=>{l(d.split("\n").map(e=>e.split(eh).map(e=>e.trim().slice(0,200)).filter(Boolean).slice(0,8)).filter(e=>e.length>0).slice(0,12)),i()},[d,l,i]),m=(0,s.useCallback)(()=>{a(),i()},[a,i]);return(0,r.jsx)(o.ZL,{children:(0,r.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50 p-4",onClick:i,children:(0,r.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-xl w-full max-w-md flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,r.jsx)("h2",{className:"text-sm font-medium text-foreground",children:c("quickReply.editTitle")}),(0,r.jsx)("button",{onClick:i,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors","aria-label":c("quickReply.cancel"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,r.jsxs)("div",{className:"px-4 py-3 flex flex-col gap-2",children:[(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:c("quickReply.editHint")}),(0,r.jsx)("textarea",{autoFocus:!0,value:d,onChange:e=>u(e.target.value),placeholder:c("quickReply.editPlaceholder"),rows:6,spellCheck:!1,className:"w-full px-2 py-1.5 text-xs font-mono bg-background border border-border rounded text-foreground focus:outline-none focus:border-brand resize-y"}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:c("quickReply.customizedFor",{lang:c("zh"===t?"quickReply.langZh":"quickReply.langEn")})})]}),(0,r.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-t border-border",children:[(0,r.jsx)("button",{onClick:m,disabled:!n,className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:c("quickReply.restoreDefault")}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:i,className:"px-3 py-1.5 text-xs border border-border text-foreground rounded-md hover:bg-accent transition-colors",children:c("quickReply.cancel")}),(0,r.jsx)("button",{onClick:h,className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",children:c("quickReply.save")})]})]})]})})})}let ef=(0,s.forwardRef)(function({messages:e,isLoading:t,cwd:n,sessionId:o,engine:a,apiRetryInfo:i,hasMoreHistory:c,isLoadingMore:d,onLoadMore:u,onFork:h,isActive:m=!0,onContentSearch:f,onShowFileDiff:g,onOpenFileLink:b,onApprovePlan:v},y){let w,{t:k,i18n:j}=(0,x.Bd)(),C=(0,s.useRef)(null),N=(0,s.useRef)(null),S=(0,s.useRef)(null),L=(0,s.useRef)(null),[E,M]=(0,s.useState)(null),[R,T]=(0,s.useState)(!0),[$,P]=(0,s.useState)(!1),[I,A]=(0,s.useState)(!1);(0,s.useEffect)(()=>{M(L.current)},[]);let{isSearchVisible:_,searchQuery:F,setSearchQuery:D,matches:B,currentMatchIndex:W,goToNextMatch:V,goToPrevMatch:O,closeSearch:z,searchInputRef:H,handleSearchKeyDown:q}=function(e){let[t,n]=(0,s.useState)(!1),[r,l]=(0,s.useState)(""),[o,a]=(0,s.useState)([]),[i,c]=(0,s.useState)(0),d=(0,s.useRef)(null),u=(0,s.useRef)([]),h=(0,s.useCallback)(()=>{let t=e.current;t&&(t.querySelectorAll("mark.chat-search-match, mark.chat-search-current").forEach(e=>{let t=e.parentNode;t&&(t.replaceChild(document.createTextNode(e.textContent||""),e),t.normalize())}),u.current=[])},[e]),m=(0,s.useCallback)(t=>{if(h(),!t||!e.current){a([]),c(0);return}let n=[],r=[],s=t.toLowerCase();e.current.querySelectorAll("[data-message-id]").forEach(e=>{let l,o=e.getAttribute("data-message-id")||"",a=0,i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),c=[];for(;l=i.nextNode();)c.push(l);for(let e of c){let l=(e.textContent||"").toLowerCase(),i=0,c=[];for(;;){let e=l.indexOf(s,i);if(-1===e)break;c.push({start:e,end:e+t.length}),i=e+1}if(0!==c.length)for(let t=c.length-1;t>=0;t--){let s=c[t];e.splitText(s.end);let l=e.splitText(s.start),i=document.createElement("mark");i.className="chat-search-match",i.textContent=l.textContent,l.parentNode.replaceChild(i,l),n.push({messageId:o,markIndex:a}),r.push(i),a++}}}),n.reverse(),r.reverse(),u.current=r,a(n),c(n.length>0?0:-1)},[e,h]);(0,s.useEffect)(()=>{queueMicrotask(()=>m(r))},[r,m]),(0,s.useEffect)(()=>{let e=u.current;e.forEach((e,t)=>{e.className=t===i?"chat-search-current":"chat-search-match"}),i>=0&&i<e.length&&e[i].scrollIntoView({behavior:"smooth",block:"center"})},[i,o]);let f=(0,s.useCallback)(()=>{0!==o.length&&c(e=>(e+1)%o.length)},[o.length]),x=(0,s.useCallback)(()=>{0!==o.length&&c(e=>(e-1+o.length)%o.length)},[o.length]),p=(0,s.useCallback)(()=>{n(!0),setTimeout(()=>d.current?.focus(),0)},[]),g=(0,s.useCallback)(()=>{n(!1),l(""),h(),a([]),c(0)},[h]),b=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?x():f()),"Escape"===e.key&&g()},[f,x,g]);return(0,s.useEffect)(()=>{let t=e.current;if(!t)return;let n=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),e.stopPropagation(),p())};return t.addEventListener("keydown",n),()=>t.removeEventListener("keydown",n)},[e,p]),{isSearchVisible:t,searchQuery:r,setSearchQuery:l,matches:o,currentMatchIndex:i,goToNextMatch:f,goToPrevMatch:x,openSearch:p,closeSearch:g,searchInputRef:d,handleSearchKeyDown:b}}(L),U=(0,l.nH)(),K=(0,s.useRef)(null),Z=(0,s.useRef)(()=>{}),{addComment:J,refresh:X}=(0,ei._)({cwd:n||"",filePath:ec.Un}),[G,Q]=(0,s.useState)(null),[Y,ee]=(0,s.useState)(null),et=(0,s.useCallback)(e=>{if(G||Y)return;let t=window.getSelection();if(!t||t.isCollapsed||!t.rangeCount){K.current=null,Z.current();return}let n=t.toString().trim();if(!n){K.current=null,Z.current();return}let r=t.anchorNode instanceof HTMLElement?t.anchorNode:t.anchorNode?.parentElement;if(r?.closest('[data-role="user"]')){K.current=null,Z.current();return}K.current={x:e.clientX,y:e.clientY,range:{start:0,end:0},selectedText:n,lineSnapshot:n},Z.current()},[G,Y]),en=(0,s.useCallback)(e=>{let t=e.target;!(t.closest(".floating-toolbar")||t.closest('[class*="z-[200]"]'))&&K.current&&(K.current=null,Z.current())},[]),es=(0,s.useCallback)(()=>{let e=K.current;e&&(Q({x:e.x,y:e.y,text:e.selectedText}),K.current=null,Z.current(),window.getSelection()?.removeAllRanges())},[]),el=(0,s.useCallback)(()=>{let e=K.current;e&&(ee({x:e.x,y:e.y,text:e.selectedText}),K.current=null,Z.current(),window.getSelection()?.removeAllRanges())},[]),eo=(0,s.useCallback)(()=>{let e=K.current;e&&U&&(K.current=null,Z.current(),window.getSelection()?.removeAllRanges(),(0,ec.Ff)(U.sendMessage,{filePath:ec.Un,startLine:0,endLine:0,codeContent:e.selectedText},k("explain.selectionMessage")))},[U,k]),eh=(0,s.useCallback)(()=>{let e=K.current;if(!e||!f)return;let t=e.selectedText.trim();K.current=null,Z.current(),window.getSelection()?.removeAllRanges(),t&&f(t)},[f]),ef=(0,s.useCallback)(async e=>{G&&(await J(0,0,e,G.text),Q(null))},[G,J]),ex=(0,s.useCallback)(async(e,t)=>{if(U&&n)try{let r=(await (0,ec.$3)(n)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));r.push({filePath:ec.Un,startLine:0,endLine:0,codeContent:e});let s=(0,ec.Gw)(r,t);U.sendMessage(s),await (0,ec.RP)(n),X()}catch(e){console.error("Failed to send to AI:",e)}},[U,n,X]),ep=(0,s.useCallback)((e,t)=>{let n=K.current;if(!n)return;let r=n.selectedText;K.current=null,Z.current(),window.getSelection()?.removeAllRanges(),"comment"===e?J(0,0,t,r):ex(r,t)},[J,ex]),eg=(w=j.language,w?.toLowerCase().startsWith("zh")?"zh":"en"),[eb,ev]=(0,s.useState)(null),[ey,ew]=(0,s.useState)(!1);(0,s.useEffect)(()=>{let e=!1;return p.t4.runPromiseExit((0,er.td)()).then(t=>{e||ev("Success"===t._tag?((e,t)=>{if(!e||"object"!=typeof e)return null;let n=e.quickReplies;return n&&"object"==typeof n?(e=>{if(!Array.isArray(e))return null;let t=[];for(let n of e.slice(0,12)){if(!Array.isArray(n))continue;let e=[];for(let t of n.slice(0,8)){if("string"!=typeof t)continue;let n=t.trim().slice(0,200);n&&e.push(n)}e.length&&t.push(e)}return t.length?t:null})(n[t]):null})(t.value,eg):null)}),()=>{e=!0}},[eg]);let ek=(0,s.useCallback)(e=>{p.t4.runPromiseExit((0,er.td)()).then(t=>{let n={..."Success"===t._tag?t.value.quickReplies??{}:{}};return e?n[eg]=e:delete n[eg],p.t4.runPromiseExit((0,er.em)({quickReplies:n})).then(t=>{"Success"===t._tag?ev(e):console.error("Failed to save quick replies:",t.cause)})})},[eg]),ej=(0,s.useCallback)(()=>{K.current=null,Z.current(),window.getSelection()?.removeAllRanges(),ew(!0)},[]),eC=(0,s.useMemo)(()=>eb??ed.SZ.map(e=>e.map(e=>k(e))),[eb,k]),eN=(0,s.useCallback)(e=>{Y&&ex(Y.text,e)},[Y,ex]),eS=(0,s.useCallback)(e=>{G&&ex(G.text,e)},[G,ex]),eL=(0,s.useMemo)(()=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),"assistant"!==e.role||!!e.isStreaming||!!e.content||!!e.images?.length||!!e.toolCalls?.length||!!e.parts?.length))},[e]),eE=(0,s.useRef)(0),eM=(0,s.useRef)(!1),eR=(0,s.useCallback)(()=>{let e=S.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[]),eT=(0,s.useCallback)(()=>{let e=S.current;return!e||e.scrollTop<50},[]),e$=(0,s.useCallback)(()=>{let e=eR(),t=eT();if(T(e),P(!t),A(!e),t&&c&&!d&&u){let e=S.current;e&&(eE.current=e.scrollHeight,eM.current=!0),u()}},[eR,eT,c,d,u]),eP=(0,s.useCallback)(()=>{N.current?.scrollIntoView({behavior:"smooth"})},[]),eI=(0,s.useCallback)(()=>{C.current?.scrollIntoView({behavior:"smooth"})},[]),eA=(0,s.useCallback)(e=>{let t=S.current;if(!t)return;let n=t.querySelector(`[data-message-id="${e}"]`);n&&(n.scrollIntoView({behavior:"smooth",block:"center"}),n.classList.add("ring-2","ring-brand","ring-offset-2"),setTimeout(()=>{n.classList.remove("ring-2","ring-brand","ring-offset-2")},2e3))},[]);(0,s.useImperativeHandle)(y,()=>({scrollToMessage:eA}),[eA]);let e_=(0,s.useRef)(!0);(0,s.useLayoutEffect)(()=>{if(e_.current||!R||eM.current)return;let e=S.current;e&&(e.scrollTop=e.scrollHeight)},[e,R]),(0,s.useLayoutEffect)(()=>{if(R&&t){let e=S.current;e&&(e.scrollTop=e.scrollHeight)}},[t,R]),(0,s.useLayoutEffect)(()=>{if(eM.current&&!d){let e=S.current;if(e){let t=e.scrollHeight-eE.current;e.scrollTop=t,eM.current=!1}}},[e,d]);let eF=(0,s.useRef)(!1);return(0,s.useLayoutEffect)(()=>{if(m&&eF.current&&e.length>0){eF.current=!1;let e=S.current;e&&(e.scrollTop=e.scrollHeight)}},[m,e.length]),(0,s.useLayoutEffect)(()=>{if(e_.current&&e.length>0)if(e_.current=!1,m){let e=S.current;e&&(e.scrollTop=e.scrollHeight)}else eF.current=!0},[e.length,m]),(0,r.jsxs)("div",{ref:L,className:"relative flex-1 min-h-0 overflow-hidden flex flex-col outline-none",tabIndex:-1,onMouseUp:et,onMouseDown:en,children:[_&&(0,r.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,r.jsx)("input",{ref:H,type:"text",value:F,onChange:e=>D(e.target.value),onKeyDown:q,placeholder:k("codeViewer.searchChat"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:B.length>0?`${W+1}/${B.length}`:k("common.noMatch")}),(0,r.jsx)("button",{onClick:O,disabled:0===B.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:k("codeViewer.prevShiftEnter"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,r.jsx)("button",{onClick:V,disabled:0===B.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:k("codeViewer.nextEnter"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,r.jsx)("button",{onClick:z,className:"p-1 rounded hover:bg-accent",title:k("codeViewer.closeEsc"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,r.jsx)("div",{ref:S,onScroll:e$,className:"relative flex-1 min-h-0 overflow-y-auto p-4",children:0!==e.length||t?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{ref:N}),c&&(0,r.jsx)("div",{className:"flex justify-center py-3",children:d?(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[(0,r.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("span",{children:k("chat.loadMoreHistory")})]}):(0,r.jsx)("button",{onClick:u,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:k("chat.scrollUpForMore")})}),eL.map(e=>(0,r.jsx)("div",{"data-message-id":e.id,className:"transition-[box-shadow] duration-300",children:(0,r.jsx)(ea,{message:e,cwd:n,sessionId:o,onFork:h,forkSupported:!0,onApprovePlan:v,isLoading:t,onContentSearch:f,onShowFileDiff:g,onOpenFileLink:b})},e.id)),t&&(0,r.jsx)("div",{className:"flex justify-start mb-4",children:(0,r.jsxs)("div",{className:"bg-accent rounded-2xl rounded-bl-md px-4 py-3 max-w-[90%]",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,r.jsx)("span",{className:"inline-block w-5 h-5 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,r.jsx)("span",{className:"text-sm",children:"codex"===a?"Codex is thinking...":"kimi"===a?"Kimi is thinking...":"ollama"===a?"Ollama is thinking...":"deepseek"===a?"DeepSeek is thinking...":"glm"===a?"GLM is thinking...":k("chat.claudeThinking")})]}),i&&(0,r.jsxs)("div",{className:"mt-2 flex items-start gap-2 text-xs text-amber-400 border-t border-border/50 pt-2",children:[(0,r.jsx)("svg",{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsxs)("div",{children:["Retrying API call (attempt ",i.attempt,i.maxRetries>0?`/${i.maxRetries}`:"",i.delayMs>0?`, delay ${(i.delayMs/1e3).toFixed(1)}s`:"",")"]}),(i.errorStatus||i.error)&&(0,r.jsxs)("div",{className:"text-muted-foreground/80 break-words",children:[i.errorStatus?`${i.errorStatus}`:"",i.errorStatus&&i.error?" \xb7 ":"",i.error||""]})]})]})]})}),(0,r.jsx)("div",{ref:C})]}):(0,r.jsx)("div",{className:"flex items-center justify-center h-full text-slate-9",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("div",{className:"text-4xl mb-4",children:"\uD83D\uDCAC"}),(0,r.jsx)("div",{children:k("chat.startConversation")})]})})}),$&&e.length>0&&(0,r.jsx)("button",{onClick:eP,className:"absolute top-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:k("chat.jumpToStart"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),I&&e.length>0&&(0,r.jsx)("button",{onClick:eI,className:"absolute bottom-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95",title:k("chat.jumpToLatest"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),E&&(0,r.jsx)(ed.fS,{floatingToolbarRef:K,bumpRef:Z,container:E,onAddComment:es,onSendToAI:el,onSearch:f?eh:void 0,onExplain:U?eo:void 0,onQuickReply:ep,quickReplyRows:eC,onEditQuickReplies:ej,isChatLoading:U?.isLoading}),ey&&(0,r.jsx)(em,{initialRows:eC,lang:eg,isCustomized:null!==eb,onSave:e=>ek(e.length?e:null),onRestoreDefault:()=>ek(null),onClose:()=>ew(!1)}),G&&E&&(0,r.jsx)(eu.t,{x:G.x,y:G.y,range:{start:0,end:0},lineSnapshot:G.text,container:E,onSubmit:ef,onSendToAI:U?eS:void 0,onClose:()=>Q(null),isChatLoading:U?.isLoading}),Y&&E&&(0,r.jsx)(eu.G,{x:Y.x,y:Y.y,range:{start:0,end:0},lineSnapshot:Y.text,container:E,onSubmit:eN,onClose:()=>ee(null),isChatLoading:U?.isLoading})]})})},75346:(e,t,n)=>{n.d(t,{n:()=>s});var r=n(88292);let s={SessionChange:(0,r.R)("session-change"),ViewChange:(0,r.R)("view-change"),OpenNote:(0,r.R)("open-note"),LangChange:(0,r.R)("lang-change"),TabAdd:(0,r.R)("tab-add"),TabClose:(0,r.R)("tab-close"),SwitchSession:(0,r.R)("switch-session"),ProjectChange:(0,r.R)("project-change"),OpenProject:(0,r.R)("open-project"),SessionComplete:(0,r.R)("session-complete"),OpenTokenStats:(0,r.R)("open-token-stats"),PinnedSessionsChanged:(0,r.R)("pinned-sessions-changed"),ScheduledTasksChanged:(0,r.R)("scheduled-tasks-changed"),ScreenshotPrepare:(0,r.R)("screenshot-prepare"),ScreenshotDone:(0,r.R)("screenshot-done")}},77725:(e,t,n)=>{n.d(t,{Z:()=>d});var r=n(12115),s=n(10592),l=n(86359),o=n(80905),a=n(49433),i=n(80286),c=n(86957);function d(e,t){let[n,d]=(0,r.useState)({status:"loading"});return(0,r.useEffect)(()=>{d({status:"loading"});let t=c.t4.runFork(e);return t.addObserver(e=>{s.YW(e,{onSuccess:e=>d({status:"success",data:e}),onFailure:e=>{if(l.t9(e))return;let t=l.od(e);d({status:"error",error:o.Ru(t)?t.value:e})}})}),()=>{a.runFork(i.G(t))}},t),n}},82292:(e,t,n)=>{function r(e,t){for(let n of e){if(n.path===t)return n;if(n.children){let e=r(n.children,t);if(e)return e}}return null}function s(e,t){if(!e)return"";let n=r(t,e);if(n?.isDirectory)return e;let s=e.split("/");return s.pop(),s.join("/")}function l(e){let t=[];for(let n of e){let e=n.split("/"),r=t;for(let t=0;t<e.length;t++){let n=e[t],s=t===e.length-1,l=e.slice(0,t+1).join("/"),o=r.find(e=>e.name===n);o||(o={name:n,path:l,isDirectory:!s,children:s?void 0:[]},r.push(o)),!s&&o.children&&(r=o.children)}}let n=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>{e.children&&n(e.children)})};return n(t),t}function o(e){let t=[],n=e=>{for(let r of e)r.isDirectory&&(t.push(r.path),r.children&&n(r.children))};return n(e),t}n.d(t,{B_:()=>f,HR:()=>function e(t,n){if(0===n.length)return t;let r=new Map(n.map(e=>[e.path,e]));return t.map(t=>{let n=r.get(t.path);return n&&t.isDirectory?void 0===t.children&&void 0!==n.children?{...t,children:n.children}:void 0!==t.children&&void 0!==n.children?{...t,children:e(t.children,n.children)}:t:t})},KH:()=>d,MB:()=>r,S7:()=>s,fw:()=>u,q3:()=>c,r6:()=>h,tE:()=>m,tW:()=>o,u:()=>i,v3:()=>l});let a=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function i(e){let t=e.split(".").pop()?.toLowerCase();return a.has(t||"")}function c(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase(),l=e=>{if(r.add(e.path),e.children)for(let t of e.children)l(t)},o=(e,t)=>{let a=e.name.toLowerCase(),i=n?a===s:a.includes(s);if(i&&e.children)return l(e),t.forEach(e=>r.add(e)),!0;let c=!1;if(e.children)for(let n of e.children)o(n,[...t,e.path])&&(c=!0);return(!!i||!!c)&&(r.add(e.path),t.forEach(e=>r.add(e)),!0)};for(let t of e)o(t,[]);return r}function d(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase();for(let t of e){let e=t.split("/");for(let t=0;t<e.length;t++){let l=e[t].toLowerCase();if(n?l===s:l.includes(s)){for(let t=0;t<=e.length-1;t++)r.add(e.slice(0,t+1).join("/"));break}}}return r}function u(e){let t=Math.floor(Math.floor((Date.now()-1e3*e)/1e3)/60),n=Math.floor(t/60),r=Math.floor(n/24),s=Math.floor(r/30),l=Math.floor(r/365);return l>0?`${l}y ago`:s>0?`${s}mo ago`:r>0?`${r}d ago`:n>0?`${n}h ago`:t>0?`${t}m ago`:"just now"}function h(e){let t=new Date(e),n=new Date,r=t.getFullYear()===n.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0"),o=String(t.getHours()).padStart(2,"0"),a=String(t.getMinutes()).padStart(2,"0");return r?`${s}-${l} ${o}:${a}`:`${t.getFullYear()}-${s}-${l} ${o}:${a}`}let m=()=>{},f=50},83448:(e,t,n)=>{n.d(t,{Cr:()=>E,F4:()=>p,Fi:()=>m,Hw:()=>d,JC:()=>y,M5:()=>b,Ny:()=>u,QW:()=>j,XO:()=>M,Zr:()=>k,an:()=>L,dM:()=>x,dQ:()=>h,em:()=>c,he:()=>f,l1:()=>v,n_:()=>w,qD:()=>S,tY:()=>T,td:()=>i,tf:()=>R,yS:()=>g,z2:()=>C});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),o=(e,t)=>l(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=(e,t)=>l(e,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),i=()=>l("/api/settings"),c=e=>a("/api/settings",e),d=e=>l(`/api/${e}/credentials`),u=e=>l(`/api/${e}/credentials?reveal=1`),h=(e,t)=>a(`/api/${e}/credentials`,{apiKey:t}),m=e=>l(`/api/${e}/models`),f=()=>l("/api/deepseek/balance"),x=e=>l(`/api/${e}/usage`),p=()=>l("/api/ollama/config"),g=e=>a("/api/ollama/config",e),b=()=>l("/api/commands"),v=()=>l("/api/skills"),y=e=>o("/api/bash",e),w=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new s.uV({message:"POST /api/session-by-path failed",cause:e})}),k=(e,t)=>o(`/api/session/${encodeURIComponent(e)}/fork`,t),j=e=>l(`/api/sessions/projects/${encodeURIComponent(e)}`),C=()=>l("/api/global-state").pipe(r.map(e=>e.sessions??[])),N=()=>r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/models");return 503===e.status?{_tag:"not-running"}:e.ok?{_tag:"ok",models:(await e.json()).models??[]}:{_tag:"error",message:"Failed to fetch models"}},catch:e=>new s.uV({message:"fetch ollama models failed",cause:e})}),S=e=>r.gen(function*(){let t=yield*N();if("not-running"!==t._tag)return t;e&&(yield*r.sync(e));let n=yield*r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/start",{method:"POST"}),t=await e.json().catch(()=>({}));return 404===e.status?{_tag:"not-installed",message:t.message||"Ollama is not installed"}:e.ok?{_tag:"started"}:{_tag:"error",message:"Failed to start Ollama"}},catch:e=>new s.uV({message:"start ollama failed",cause:e})});if("not-installed"===n._tag)return{_tag:"not-installed",message:n.message};if("error"===n._tag)return{_tag:"error",message:n.message};let l=yield*N();return"not-running"===l._tag?{_tag:"error",message:"Ollama started but cannot fetch models"}:l}),L=e=>l(`/api/file?path=${encodeURIComponent(e)}`),E=()=>l("/api/claude-stats"),M=()=>l("/api/prompts/config?scope=global"),R=e=>l(`/api/prompts/config?cwd=${encodeURIComponent(e)}`),T=e=>o("/api/prompts/config",e)},83897:(e,t,n)=>{n.d(t,{k_:()=>a,nH:()=>i});var r=n(95155),s=n(12115),l=n(48347);let o=(0,s.createContext)(null);function a({children:e}){let t=(0,s.useRef)(new Map),n=(0,s.useRef)(null),[i,c]=(0,s.useState)(!1),d=(0,s.useCallback)((e,n)=>{t.current.set(n,e)},[]),u=(0,s.useCallback)(e=>{t.current.delete(e)},[]),h=(0,s.useCallback)(e=>{n.current=e},[]),m=(0,s.useCallback)(e=>{let r=n.current;if(!r)return void console.warn("No active tab to send message");let s=t.current.get(r);s?s(e):console.warn(`No chat sender registered for tab ${r}`)},[]),f=(0,s.useMemo)(()=>({sendMessage:m,isLoading:i,registerChat:d,unregisterChat:u,setActiveTab:h,setIsLoading:c}),[m,i,d,u,h]),x=(0,s.useMemo)(()=>({sendMessage:m,isLoading:i}),[m,i]);return(0,r.jsx)(o.Provider,{value:f,children:(0,r.jsx)(l.H,{value:x,children:e})})}function i(){return(0,s.useContext)(o)}},86304:(e,t,n)=>{n.d(t,{P:()=>c});var r=n(12115),s=n(79114),l=n(34075),o=n(86957),a=n(98036),i=n(63563);function c(){let{t:e}=(0,s.Bd)();return(0,r.useCallback)(async t=>{let n=await o.t4.runPromiseExit((0,a.ot)(t));if("Success"===n._tag)n.value.alreadyExists?(0,l.oR)(e("htmlApps.alreadyAdded"),"info"):((0,l.oR)(e("htmlApps.added"),"success"),(0,i.N)());else{let t="Fail"===n.cause._tag?n.cause.error:null,r=t?.cause,s=r instanceof Error?r.message:e("htmlApps.addFailed");(0,l.oR)(s,"error")}},[e])}},88780:(e,t,n)=>{n.d(t,{Do:()=>u,Sz:()=>h,VO:()=>d,wI:()=>m});var r=n(95155),s=n(12115),l=n(79114),o=n(70188),a=n(14575);function i({status:e}){let{label:t,className:n}={added:{label:"A",className:"text-green-11"},untracked:{label:"A",className:"text-green-11"},modified:{label:"M",className:"text-amber-11"},deleted:{label:"D",className:"text-red-11"},renamed:{label:"R",className:"text-brand"}}[e]||{label:"?",className:"text-muted-foreground"};return(0,r.jsx)("span",{className:`text-xs font-bold ${n}`,children:t})}let c=s.memo(function e({node:t,level:n,selectedPath:l,expandedPaths:o,onSelect:c,onToggle:d,onContextMenu:u,showChanges:h=!1,renderActions:m}){let f=l===t.path,x=o.has(t.path),p=(0,s.useCallback)(()=>{t.isDirectory?d(t.path):c(t)},[t,c,d]),g=(0,s.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),u(e,t.path,t.isDirectory)},[t.path,t.isDirectory,u]);return t.isDirectory?(0,r.jsxs)("div",{children:[(0,r.jsxs)("div",{className:"flex items-center gap-1 py-0.5 px-2 pr-3 hover:bg-accent cursor-pointer whitespace-nowrap group",style:{paddingLeft:`${12*n+8}px`},onClick:p,onContextMenu:g,children:[(0,r.jsx)("span",{className:"text-slate-9 text-xs",children:x?"▼":"▶"}),(0,r.jsx)("span",{className:"text-sm text-foreground flex-1 truncate","data-tooltip":t.path,children:t.name}),m&&m(t)]}),x&&t.children.map(t=>(0,r.jsx)(e,{node:t,level:n+1,selectedPath:l,expandedPaths:o,onSelect:c,onToggle:d,onContextMenu:u,showChanges:h,renderActions:m},t.path))]}):(0,r.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 pr-3 cursor-pointer whitespace-nowrap group ${f?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*n+8}px`},onClick:p,onContextMenu:g,children:[(0,r.jsx)(a.o,{name:t.name,size:16,className:"flex-shrink-0"}),(0,r.jsx)("span",{className:`text-sm flex-1 truncate ${f?"text-brand":"text-foreground"}`,"data-tooltip":t.path,children:t.name}),t.status&&(0,r.jsx)(i,{status:t.status}),h&&void 0!==t.additions&&void 0!==t.deletions&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("span",{className:"text-xs text-green-11",children:["+",t.additions]}),(0,r.jsxs)("span",{className:"text-xs text-red-11",children:["-",t.deletions]})]}),m&&m(t)]})});function d({files:e,selectedPath:t,expandedPaths:n,onSelect:s,onToggle:a,cwd:i,showChanges:u=!1,renderActions:h,emptyMessage:m,className:f,onExplain:x,explainDisabled:p}){let{t:g}=(0,l.Bd)(),b=m??g("gitFileTree.noFiles"),{contextMenu:v,showContextMenu:y,hideContextMenu:w}=(0,o.Ee)();return 0===e.length?(0,r.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:b}):(0,r.jsxs)("div",{className:f||"py-1",children:[e.map(e=>(0,r.jsx)(c,{node:e,level:0,selectedPath:t,expandedPaths:n,onSelect:s,onToggle:a,onContextMenu:y,showChanges:u,renderActions:h},e.path)),v&&(0,r.jsx)(o.ft,{x:v.x,y:v.y,path:v.path,cwd:i,isDirectory:v.isDirectory,onClose:w,onExplain:x,explainDisabled:p})]})}function u(e){let t=[];for(let n of e){let e=n.path.split("/"),r=t;for(let t=0;t<e.length;t++){let s=e[t],l=t===e.length-1,o=e.slice(0,t+1).join("/"),a=r.find(e=>e.name===s);a||(a={name:s,path:o,isDirectory:!l,children:[],...l&&{status:n.status,additions:n.additions,deletions:n.deletions,oldPath:n.oldPath,file:n}},r.push(a)),l||(r=a.children)}}let n=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>n(e.children))};return n(t),t}function h(e){let t=[],n=e=>{for(let r of e)r.isDirectory&&(t.push(r.path),n(r.children))};return n(e),t}function m(e){let t=[],n=e=>{if(e.isDirectory)for(let t of e.children)n(t);else t.push(e)};return n(e),t}},89109:(e,t,n)=>{n.d(t,{SZ:()=>o,fS:()=>c});var r=n(95155),s=n(12115),l=n(79114);let o=[["quickReply.optionA","quickReply.optionB","quickReply.optionC","quickReply.optionD"],["quickReply.allRecommended","quickReply.thisOne","quickReply.notThis"],["quickReply.why","quickReply.elaborate","quickReply.example"],["quickReply.start","quickReply.continue","quickReply.ok","quickReply.done"]];function a({rows:e,placeAbove:t,onHeight:n,onPick:o,onEdit:i,onMouseEnter:c,onMouseLeave:d}){let{t:u}=(0,l.Bd)(),h=(0,s.useRef)(null);return(0,s.useEffect)(()=>{h.current&&n(h.current.getBoundingClientRect().height)},[n,e]),(0,r.jsxs)("div",{ref:h,className:`absolute ${t?"bottom-full mb-1":"top-full mt-1"} left-0 z-[201] flex flex-col gap-1 bg-card border border-border rounded-lg shadow-xl p-1.5`,onMouseEnter:c,onMouseLeave:d,children:[i&&(0,r.jsx)("button",{className:"absolute top-0.5 right-0.5 p-1 text-muted-foreground hover:text-brand transition-colors",onClick:i,title:u("quickReply.edit"),"aria-label":u("quickReply.edit"),children:(0,r.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),e.map((e,t)=>(0,r.jsx)("div",{className:`flex items-center gap-1${i&&0===t?" pr-5":""}`,children:e.map((e,n)=>(0,r.jsx)("button",{className:"px-2 py-1 text-xs whitespace-nowrap border border-border text-foreground rounded hover:border-brand hover:bg-accent transition-colors",onClick:()=>o(e),children:e},`${t}:${n}:${e}`))},t))]})}function i({x:e,y:t,visible:n,container:c,onAddComment:d,onSendToAI:u,onSearch:h,onExplain:m,onQuickReply:f,quickReplyRows:x,onEditQuickReplies:p,isChatLoading:g}){let{t:b}=(0,l.Bd)(),v=(0,s.useRef)(null),[y,w]=(0,s.useState)({w:0,h:0}),[k,j]=(0,s.useState)(0),[C,N]=(0,s.useState)(null),S=(0,s.useRef)(null);(0,s.useLayoutEffect)(()=>{let e=v.current;if(!e)return;let{width:t,height:n}=e.getBoundingClientRect();w(e=>e.w===t&&e.h===n?e:{w:t,h:n})});let L=(0,s.useCallback)(e=>{j(t=>t===e?t:e)},[]);(0,s.useEffect)(()=>{n||N(null)},[n]);let E=(0,s.useCallback)(()=>{S.current&&(clearTimeout(S.current),S.current=null)},[]),M=(0,s.useCallback)(e=>{E(),N(e)},[E]),R=(0,s.useCallback)(()=>{E(),S.current=setTimeout(()=>N(null),150)},[E]);(0,s.useEffect)(()=>E,[E]);let T=c.getBoundingClientRect(),$=e-T.left,P=Math.max(0,t-T.top-40),I=Math.max(0,Math.min($+8,T.width-y.w-8)),A=k>0&&P+y.h+8+k>T.height,_=(0,s.useMemo)(()=>x??o.map(e=>e.map(e=>b(e))),[x,b]),F=e=>f&&C===e?(0,r.jsx)(a,{rows:_,onEdit:p,placeAbove:A,onHeight:L,onPick:t=>{N(null),f(e,t)},onMouseEnter:E,onMouseLeave:R}):null;return(0,r.jsxs)("div",{ref:v,className:"floating-toolbar absolute z-[200] flex items-center gap-1.5 bg-card border border-border rounded-lg shadow-xl p-1.5",style:{left:I,top:P,visibility:n?"visible":"hidden",pointerEvents:n?"auto":"none"},children:[(0,r.jsxs)("div",{className:"relative",onMouseEnter:()=>M("comment"),onMouseLeave:R,children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:d,children:b("floatingToolbar.addComment")}),F("comment")]}),(0,r.jsxs)("div",{className:"relative",onMouseEnter:()=>{g||M("ai")},onMouseLeave:R,children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",onClick:u,disabled:g,title:g?b("comments.aiResponding"):void 0,children:b("floatingToolbar.sendToAI")}),F("ai")]}),m&&(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",onClick:m,disabled:g,title:g?b("comments.aiResponding"):void 0,children:b("explain.action")}),h&&(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:h,children:b("floatingToolbar.search")})]})}let c=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:n,onAddComment:l,onSendToAI:o,onSearch:a,onExplain:c,onQuickReply:d,quickReplyRows:u,onEditQuickReplies:h,isChatLoading:m}){let[f,x]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>x(e=>e+1)},[t]);let p=(0,s.useMemo)(()=>e.current,[f]);return(0,r.jsx)(i,{x:p?.x??0,y:p?.y??0,visible:!!p,container:n,onAddComment:l,onSendToAI:o,onSearch:a,onExplain:c,onQuickReply:d,quickReplyRows:u,onEditQuickReplies:h,isChatLoading:m})})},90717:(e,t,n)=>{n.d(t,{$3:()=>u,Cm:()=>d,Ff:()=>x,Gw:()=>f,RP:()=>h,Un:()=>m,zL:()=>c});var r=n(69809),s=n(49433),l=n(86957),o=n(82680),a=n(46456);let i=new Set;function c(e){return i.add(e),()=>i.delete(e)}function d(){i.forEach(e=>e())}async function u(e){let t=await l.t4.runPromiseExit((0,a.lb)(e));if("Success"!==t._tag)throw Error("Failed to fetch comments");let n=t.value.comments??[];if(0===n.length)return[];let r=new Map;for(let e of n)e.selectedText||(r.has(e.filePath)||r.set(e.filePath,[]),r.get(e.filePath).push(e));let i=new Map;await Promise.all(Array.from(r.keys()).map(async t=>{let n=await l.t4.runPromiseExit(s.tryPromise({try:async()=>{let n=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null},catch:e=>new o.uV({message:`read file text ${t} failed`,cause:e})}));"Success"===n._tag&&n.value&&"string"==typeof n.value.content?i.set(t,n.value.content.split("\n")):"Failure"===n._tag&&console.error(`Failed to read file ${t}:`,n.cause)}));let c=[];for(let e of n){if(e.selectedText){c.push({...e,codeContent:e.selectedText});continue}let t=i.get(e.filePath),n="";if(t){let r=Math.max(0,e.startLine-1),s=Math.min(t.length,e.endLine);n=t.slice(r,s).join("\n")}c.push({...e,codeContent:n})}return c}async function h(e){let t=await l.t4.runPromiseExit((0,a.tj)(e));return"Success"===t._tag?(d(),!0):(console.error("Failed to clear comments:",t.cause),!1)}let m="__chat__";function f(e,t){let n=e.filter(e=>e.filePath===m),s=e.filter(e=>e.filePath!==m),l=[];for(let e of(s.length>0&&(l.push(`${r.A.t("comments.codeRef")}`,""),s.forEach((e,t)=>{let n=e.startLine>0||e.endLine>0?`:${e.startLine}-${e.endLine}`:"";l.push(`[${t+1}] ${e.filePath}${n}`),l.push("```"),l.push(e.codeContent),l.push("```"),e.note&&l.push(r.A.t("comments.note",{content:e.note})),l.push("")})),n)){let t=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");l.push(t),e.note&&l.push(e.note),l.push("")}if(t.trim()){for(;l.length>0&&""===l[l.length-1];)l.pop();l.push(t.trim())}return l.join("\n").trim()}function x(e,t,n){e(f([t],n))}},95045:(e,t,n)=>{n.d(t,{F:()=>o});var r=n(49433),s=n(88292),l=n(86957);let o=(e,t)=>{l.t4.runFork(r.flatMap(s.d,n=>n.publish(e,t)))}},95686:(e,t,n)=>{n.d(t,{x:()=>i});var r=n(95155),s=n(12115),l=n(64428),o=n(70188),a=n(5135);function i({filePath:e,content:t,cwd:n,onClose:c,zClassName:d="z-50"}){let[u,h]=(0,s.useState)(null);return(0,r.jsx)(l.ZL,{children:(0,r.jsx)("div",{className:`fixed inset-0 ${d} flex items-center justify-center bg-black/50 p-0 md:p-4`,onClick:c,children:(0,r.jsx)("div",{ref:h,className:"bg-card shadow-xl w-full h-full rounded-none md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col relative",onClick:e=>e.stopPropagation(),children:(0,r.jsx)(o.SU,{container:u,children:(0,r.jsx)(a.M,{content:t,filePath:e,cwd:n,onClose:c})})})})})}},96497:(e,t,n)=>{function r(e,t){let n,r=document.caretRangeFromPoint(e.clientX,e.clientY);if(!r||!t.contains(r.startContainer))return 1;let s=r.startContainer,l=r.startOffset,o=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),a=1;for(;n=o.nextNode();){if(n===s){a+=l;break}a+=n.textContent?.length||0}return a}function s(e,t){if(0!==e.buttons)return null;let n=window.getSelection();if(n&&!n.isCollapsed)return null;let s=e.target;if("SPAN"!==s.tagName||!s.style.color)return null;let l=s.getBoundingClientRect();return{column:r(e,t),rect:{x:l.left,y:l.bottom+4}}}n.d(t,{A:()=>s,j:()=>r})},98036:(e,t,n)=>{n.d(t,{m3:()=>i,mi:()=>o,ot:()=>a});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok){let e;try{e=(await n.json()).error}catch{}throw Error(e||`HTTP ${n.status}`)}return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),o=()=>l("/api/html-apps"),a=e=>l("/api/html-apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})}),i=e=>l(`/api/html-apps/${encodeURIComponent(e)}`,{method:"DELETE"})}}]);
|