@piagent/platform 1.44.3 → 1.44.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +1 -1
  3. package/README.vi.md +1 -1
  4. package/docs/command-reference-vietnamese.md +2 -2
  5. package/docs/distribution-standard.md +6 -6
  6. package/docs/en/windows.md +2 -0
  7. package/docs/herdr-workflow.md +13 -1
  8. package/docs/languages.json +4 -4
  9. package/docs/operator-manual-vietnamese.md +7 -7
  10. package/docs/publishing-for-teams.md +1 -0
  11. package/docs/quickstart-vietnamese.md +1 -1
  12. package/docs/release-install-policy.md +2 -2
  13. package/docs/team-onboarding.md +2 -2
  14. package/docs/vi/windows.md +2 -0
  15. package/docs-site/architecture.html +1 -1
  16. package/docs-site/assets/search-en.json +1 -1
  17. package/docs-site/assets/search-vi.json +1 -1
  18. package/docs-site/benchmark.html +1 -1
  19. package/docs-site/commands.html +1 -1
  20. package/docs-site/content/en/quickstart.html +1 -1
  21. package/docs-site/content/quickstart.html +1 -1
  22. package/docs-site/context-engine.html +1 -1
  23. package/docs-site/ecosystem.html +1 -1
  24. package/docs-site/en/architecture.html +1 -1
  25. package/docs-site/en/benchmark.html +1 -1
  26. package/docs-site/en/commands.html +1 -1
  27. package/docs-site/en/context-engine.html +1 -1
  28. package/docs-site/en/ecosystem.html +1 -1
  29. package/docs-site/en/index.html +9 -9
  30. package/docs-site/en/mcp-approval.html +1 -1
  31. package/docs-site/en/mcp-auth.html +1 -1
  32. package/docs-site/en/mcp-servers.html +1 -1
  33. package/docs-site/en/mcp.html +1 -1
  34. package/docs-site/en/permissions.html +1 -1
  35. package/docs-site/en/profiles.html +1 -1
  36. package/docs-site/en/quickstart.html +2 -2
  37. package/docs-site/en/runtime.html +1 -1
  38. package/docs-site/en/scope.html +1 -1
  39. package/docs-site/en/security.html +1 -1
  40. package/docs-site/en/team.html +1 -1
  41. package/docs-site/en/update.html +3 -3
  42. package/docs-site/en/whats-new.html +27 -16
  43. package/docs-site/en/windows.html +1 -1
  44. package/docs-site/en/workflows.html +1 -1
  45. package/docs-site/index.html +9 -9
  46. package/docs-site/mcp-approval.html +1 -1
  47. package/docs-site/mcp-auth.html +1 -1
  48. package/docs-site/mcp-servers.html +1 -1
  49. package/docs-site/mcp.html +1 -1
  50. package/docs-site/permissions.html +1 -1
  51. package/docs-site/profiles.html +1 -1
  52. package/docs-site/quickstart.html +2 -2
  53. package/docs-site/releases.json +31 -0
  54. package/docs-site/runtime.html +1 -1
  55. package/docs-site/scope.html +1 -1
  56. package/docs-site/security.html +1 -1
  57. package/docs-site/team.html +1 -1
  58. package/docs-site/update.html +3 -3
  59. package/docs-site/whats-new.html +27 -16
  60. package/docs-site/windows.html +1 -1
  61. package/docs-site/workflows.html +1 -1
  62. package/evals/private-holdout-v1/public-exposure.v2.json +2 -2
  63. package/package.json +1 -1
  64. package/packages/piagent-core/extensions/company-session-guard.ts +4 -2
  65. package/packages/piagent-core/managed/herdr-reporter.mjs +85 -0
  66. package/packages/piagent-core/managed/store.d.mts +1 -0
  67. package/packages/piagent-core/managed/store.mjs +13 -0
  68. package/packages/piagent-core/package.json +1 -1
  69. package/packages/piagent-webui/dist/client/assets/{App-DcaqK-_s.js → App-CiwY9VpU.js} +1 -1
  70. package/packages/piagent-webui/dist/client/assets/{GatewayApp-5DVdNIyr.js → GatewayApp-DrNJW3v_.js} +3 -3
  71. package/packages/piagent-webui/dist/client/assets/{InspectionApp-CBPHxuqj.js → InspectionApp-BBiwSaV0.js} +1 -1
  72. package/packages/piagent-webui/dist/client/assets/{SessionAgentWorkspace-DmD9Qt4f.js → SessionAgentWorkspace-DwyPebIX.js} +1 -1
  73. package/packages/piagent-webui/dist/client/assets/{SessionInspectorDrawer-CK5ujmH3.js → SessionInspectorDrawer-CpVzaf_G.js} +2 -2
  74. package/packages/piagent-webui/dist/client/assets/SettingsNavigation-C-tO5iXn.js +3 -0
  75. package/packages/piagent-webui/dist/client/assets/{SettingsPage-Dda8GW2a.js → SettingsPage-Ca-qRSZa.js} +1 -1
  76. package/packages/piagent-webui/dist/client/assets/{TerminalPanel-X2389XHl.js → TerminalPanel-B8j_r6-y.js} +1 -1
  77. package/packages/piagent-webui/dist/client/assets/{WorkspaceCodeEditor-Dt3dS_QG.js → WorkspaceCodeEditor-BDTPvq-0.js} +1 -1
  78. package/packages/piagent-webui/dist/client/assets/{WorkspaceExplorer-CBHwY4BN.js → WorkspaceExplorer-DVsNU0eu.js} +3 -3
  79. package/packages/piagent-webui/dist/client/assets/{index-BMQo9OEq.js → index-uhJMXxqD.js} +2 -2
  80. package/packages/piagent-webui/dist/client/index.html +1 -1
  81. package/packages/piagent-webui/shared/company-copy.ts +1 -0
  82. package/scripts/piagent-studio.mjs +16 -6
  83. package/packages/piagent-webui/dist/client/assets/SettingsNavigation-BnorH-l_.js +0 -3
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownMessage-DGt5B-6D.js","assets/rolldown-runtime-hePW80VL.js","assets/vendor-CSDKB7mU.js","assets/workspace-navigation-DkVobhwg.js","assets/ui-preferences-0waeSO-S.js","assets/api-BQS4Dtrr.js","assets/bootstrap-CedkNtRG.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bt as t,Ct as n,D as r,Dn as i,Dt as a,Fn as o,Ft as s,Lt as c,Nt as l,Ot as u,Rt as d,St as f,Tt as p,Ut as m,Vt as h,Wt as g,Yt as _,_t as v,a as y,c as b,ct as x,d as S,gt as C,i as w,it as T,j as E,jt as D,l as O,mt as ee,n as k,o as te,ot as A,r as ne,rt as re,s as j,st as ie,u as ae,v as oe,wt as M,xt as se,zt as ce}from"./vendor-CSDKB7mU.js";import{i as N,n as P}from"./ui-preferences-0waeSO-S.js";import{t as le}from"./index-BMQo9OEq.js";import{$ as ue,A as F,C as de,G as fe,H as pe,J as me,L as he,P as ge,Q as _e,U as ve,W as ye,X as be,Y as xe,Z as Se,_ as Ce,at as we,ct as Te,dt as Ee,et as De,f as Oe,g as ke,h as Ae,it as je,j as Me,k as Ne,lt as Pe,m as Fe,nt as Ie,ot as Le,rt as Re,st as ze,v as Be,y as Ve}from"./api-BQS4Dtrr.js";import{t as He}from"./ActivityPanel-DxQ3_dyT.js";import{a as I,c as Ue,i as We,n as Ge,o as Ke,r as L,s as qe,t as Je}from"./view-model-CWNiS4JN.js";import{n as Ye}from"./workspace-navigation-DkVobhwg.js";import{A as Xe,D as Ze,E as Qe,O as R,S as $e,f as et,g as tt,h as nt,j as rt,k as it,l as z,m as at,n as ot,u as B,v as V,y as H}from"./transcript-view-model-Bq0nkxyu.js";import{a as st,c as ct,d as lt,i as U,l as ut,n as dt,o as ft,p as pt,r as mt,s as ht,t as gt,u as _t}from"./LineReview-C_0ZpgCH.js";var W=e(o(),1);function vt(e){return Array.isArray(e)?`[${e.map(vt).join(`,`)}]`:e&&typeof e==`object`?`{${Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>`${JSON.stringify(e)}:${vt(t)}`).join(`,`)}}`:JSON.stringify(e)}async function yt(e){let t=new TextEncoder().encode(vt(e)),n=await crypto.subtle.digest(`SHA-256`,t);return`sha256:${[...new Uint8Array(n)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}async function bt(e,t,n){if(!t.target||t.state===`unavailable`)throw Error(`review-target-unavailable`);let r=new Date,i=new Date(r.getTime()+3e5),a=t.target,o={...structuredClone(e.identity),agentOperationId:null,toolCallId:null},s={runtimeRevision:e.revision.runtimeRevision,taskRevision:a.taskRevision,controlRevision:e.revision.controlRevision,workspaceRevision:a.workspaceRevision,indexRevision:a.indexRevision,approvalRevision:e.revision.approvalRevision,sessionOptionRevision:e.revision.sessionOptionRevision,queueRevision:e.revision.queueRevision,workspacePreimage:null,indexPreimage:null,patchPreimage:a.patchPreimage},c={view:a.view,fileRef:a.fileRef,diffRef:a.diffRef,reviewState:n,contentDigest:a.contentDigest},l={schemaVersion:1,version:`piagent-webui-control-v1`,messageType:`command`,commandId:`review-command.${crypto.randomUUID()}`,idempotencyKey:crypto.randomUUID(),requestedAt:r.toISOString(),expiresAt:i.toISOString(),capabilityScope:`reviewActions`,action:`review.mark`,actionDigest:``,identity:o,expectedRevisions:s,payload:c};return l.actionDigest=await yt({action:l.action,identity:o,expectedRevisions:s,payload:c}),l}function xt(e){return Array.isArray(e)?`[${e.map(xt).join(`,`)}]`:e&&typeof e==`object`?`{${Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>`${JSON.stringify(e)}:${xt(t)}`).join(`,`)}}`:JSON.stringify(e)}async function G(e){let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(xt(e)));return`sha256:${[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}async function St(e,t,n=[]){if(t.state!==`ready`||!t.target)throw Error(`source-mutation-preview-unavailable`);let r=new Date,i=t.target,a={...structuredClone(e.identity),agentOperationId:null,toolCallId:null};if(n.length>128||new Set(n).size!==n.length||n.some(e=>!i.hunkRefs.includes(e))||xt(n)!==xt(i.hunkRefs.filter(e=>n.includes(e))))throw Error(`source-mutation-hunk-unavailable`);let o={runtimeRevision:e.revision.runtimeRevision,taskRevision:i.taskRevision,controlRevision:e.revision.controlRevision,workspaceRevision:i.workspaceRevision,indexRevision:i.indexRevision,approvalRevision:e.revision.approvalRevision,sessionOptionRevision:e.revision.sessionOptionRevision,queueRevision:e.revision.queueRevision,workspacePreimage:i.workspacePreimage,indexPreimage:i.indexPreimage,patchPreimage:i.patchPreimage},s={fileRef:i.fileRef,hunkRefs:[...n],contentDigest:i.contentDigest},c={schemaVersion:1,version:`piagent-webui-control-v1`,messageType:`command`,commandId:`source-mutation.${crypto.randomUUID()}`,idempotencyKey:crypto.randomUUID(),requestedAt:r.toISOString(),expiresAt:new Date(r.getTime()+3e5).toISOString(),capabilityScope:`reviewActions`,action:t.action,actionDigest:``,identity:a,expectedRevisions:o,payload:s};return c.actionDigest=await G({action:c.action,identity:a,expectedRevisions:o,payload:s}),c}function Ct(e){return Array.isArray(e)?`[${e.map(Ct).join(`,`)}]`:e&&typeof e==`object`?`{${Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>`${JSON.stringify(e)}:${Ct(t)}`).join(`,`)}}`:JSON.stringify(e)}async function wt(e){let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(Ct(e)));return`sha256:${[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}async function Tt(e,t,n=null,r=null){if(!e.identity.taskId||!e.identity.taskRunId||!e.revision.taskRevision||!e.revision.workspaceRevision)throw Error(`source-open-task-authority-unavailable`);if(r!==null&&n===null)throw Error(`source-open-location-invalid`);let i=new Date,a={...structuredClone(e.identity),agentOperationId:null,toolCallId:null},o={runtimeRevision:e.revision.runtimeRevision,taskRevision:e.revision.taskRevision,controlRevision:e.revision.controlRevision,workspaceRevision:e.revision.workspaceRevision,indexRevision:e.revision.indexRevision,approvalRevision:e.revision.approvalRevision,sessionOptionRevision:e.revision.sessionOptionRevision,queueRevision:e.revision.queueRevision,workspacePreimage:null,indexPreimage:null,patchPreimage:null},s={fileRef:t,line:n,column:r},c={schemaVersion:1,version:`piagent-webui-control-v1`,messageType:`command`,commandId:`source-open.${crypto.randomUUID()}`,idempotencyKey:crypto.randomUUID(),requestedAt:i.toISOString(),expiresAt:new Date(i.getTime()+3e5).toISOString(),capabilityScope:`reviewActions`,action:`source.open-in-vscode`,actionDigest:``,identity:a,expectedRevisions:o,payload:s};return c.actionDigest=await wt({action:c.action,identity:a,expectedRevisions:o,payload:s}),c}var Et=new Set(`as.async.await.break.case.catch.class.const.continue.def.delete.do.else.enum.export.extends.finally.for.from.function.if.implements.import.in.interface.let.new.of.package.private.protected.public.return.static.struct.switch.throw.try.type.var.while.with.yield`.split(`.`)),Dt=new Set([`false`,`nil`,`null`,`None`,`true`,`undefined`]),Ot=new Set([`py`,`rb`,`sh`,`bash`,`zsh`,`yaml`,`yml`,`toml`]);function kt(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n<0?``:t.slice(n+1).toLowerCase()}function At(e){return/[A-Za-z_$]/.test(e)}function jt(e){return/[A-Za-z0-9_$-]/.test(e)}function Mt(e){return e>=`0`&&e<=`9`}function Nt(e,t,n){if(!n)return;let r=e[e.length-1];r?.kind===t?r.text+=n:e.push({kind:t,text:n})}function Pt(e,t){let n=[],r=kt(t),i=0;for(;i<e.length;){if(e.startsWith(`//`,i)||e.startsWith(`/*`,i)||e[i]===`#`&&Ot.has(r)){Nt(n,`comment`,e.slice(i));break}let t=e[i]??``;if(t===`"`||t===`'`||t==="`"){let r=t,a=i+1;for(;a<e.length;){if(e[a]===`\\`){a+=2;continue}if(e[a]===r){a+=1;break}a+=1}let o=e.slice(i,a);Nt(n,e.slice(a).match(/^\s*:/)&&r===`"`?`property`:`string`,o),i=a;continue}if(Mt(t)||t===`.`&&Mt(e[i+1]??``)){let t=i+1;for(;t<e.length&&/[0-9A-Fa-f_xXob.+-]/.test(e[t]??``);)t+=1;Nt(n,`number`,e.slice(i,t)),i=t;continue}if(At(t)){let t=i+1;for(;t<e.length&&jt(e[t]??``);)t+=1;let r=e.slice(i,t);Nt(n,Et.has(r)?`keyword`:Dt.has(r)?`literal`:`plain`,r),i=t;continue}Nt(n,`plain`,t),i+=1}return n}var Ft=[{view:`task`,label:`Thay đổi của task`,shortLabel:`Task`},{view:`working-tree`,label:`Toàn bộ working tree`,shortLabel:`Working Tree`},{view:`staged`,label:`Đã chuẩn bị commit`,shortLabel:`Staged`}];function It(e){return e===`vi`?Ft:[{view:`task`,label:`Task Changes`,shortLabel:`Task`},{view:`working-tree`,label:`Full Working Tree`,shortLabel:`Working Tree`},{view:`staged`,label:`Staged Changes`,shortLabel:`Staged`}]}var Lt={"pre-existing-user":`Có sẵn trước task`,"runtime-observed-agent":`Pi runtime đã chạm`,"post-baseline-unattributed":`Thay đổi sau baseline · chưa rõ nguồn`,mixed:`Trộn thay đổi người dùng và runtime`};function Rt(e,t=`vi`){return t===`vi`?Lt[e.provenance.classification]:{"pre-existing-user":`Pre-existing user change`,"runtime-observed-agent":`Runtime-observed agent touch`,"post-baseline-unattributed":`Post-baseline · unattributed`,mixed:`Mixed user and runtime change`}[e.provenance.classification]}function zt(e,t=`vi`){return e.stats.state===`exact`?`+${e.stats.additions??0} −${e.stats.deletions??0}`:t===`vi`?`Dòng thay đổi chưa xác định`:`Line changes unavailable`}function Bt(e,t=`vi`){let n=e.page.total;return e.availability.state===`stale`?t===`vi`?`Đang đồng bộ lại…`:`Resynchronizing…`:e.availability.state===`unavailable`?e.availability.message??(t===`vi`?`Nguồn thay đổi chưa sẵn sàng`:`Source changes unavailable`):n===0?t===`vi`?`Không có file thay đổi`:`No changed files`:t===`vi`?`${n} file${e.page.truncated?` · danh sách đã rút gọn`:``}`:`${n} file${n===1?``:`s`}${e.page.truncated?` · list truncated`:``}`}function K(e,t=`vi`){return t===`vi`?`${e.criterionIds.length} tiêu chí · ${e.verifierAttemptIds.length} verifier`:`${e.criterionIds.length} criteria · ${e.verifierAttemptIds.length} verifiers`}function Vt(e,t){return[t.projectRef,t.runtimeInstanceId,t.sessionRef,t.taskId??`no-task`,t.taskRunId??`no-run`,e.sourceProjectionRevision??`no-source-projection-revision`,e.taskViewRevision??`no-task-view-revision`,e.workspaceRevision??`no-workspace-revision`,e.indexRevision??`no-index-revision`].join(``)}function Ht(e,t,n,r){if(!e||e.view!==t||e.availability.state===`stale`||e.identity.projectRef!==r.projectRef||e.identity.runtimeInstanceId!==r.runtimeInstanceId||e.identity.sessionRef!==r.sessionRef||e.identity.taskId!==r.taskId||e.identity.taskRunId!==r.taskRunId)return!1;let i=t===`task`?n.taskViewRevision:t===`working-tree`?n.workspaceRevision:n.indexRevision;if(!(i===null?e.availability.state===`unavailable`:e.viewRevision===i))return!1;let a=e.snapshotBinding;return a?n.sourceProjectionRevision!==null&&a.sourceProjectionRevision===n.sourceProjectionRevision&&a.taskViewRevision===n.taskViewRevision&&a.workspaceRevision===n.workspaceRevision&&a.indexRevision===n.indexRevision:n.sourceProjectionRevision===null}function Ut(e,t){if(!e||e.state!==`unavailable`||e.target!==null||!e.reasonCode)return!1;let n=t?.availability.state===`current`&&t.fallback.kind===`none`;return e.reasonCode===`review-target-unavailable`?n:e.reasonCode===`no-unstaged-change`||e.reasonCode===`no-staged-change`?n&&t.hunks.length>0:[`-target-stale`,`-preview-incomplete`,`-preimage-unavailable`,`-authority-unavailable`].some(t=>e.reasonCode.endsWith(t))}function Wt(e,t,n,r,i,a){return t===n&&Ht(e,a,r,i)?e??null:null}function Gt(e,t,n,r,i,a){let o=e?.identity;return!!(e&&o&&o.projectRef===a.identity.projectRef&&o.runtimeInstanceId===a.identity.runtimeInstanceId&&o.sessionRef===a.identity.sessionRef&&o.taskId===a.identity.taskId&&o.taskRunId===a.identity.taskRunId&&e.view===t&&e.file.fileRef===n&&e.file.fileRevision===i&&e.precondition.expectedViewRevision===r&&e.precondition.expectedFileRevision===i&&e.observed.viewRevision===r&&e.observed.fileRevision===i&&e.availability.state!==`stale`&&e.fallback.kind!==`stale`)}function Kt(e,t){return t&&e.some(e=>e.fileRef===t)?t:e[0]?.fileRef??null}var q=i();function qt(e){let t=e?.target;return t?[t.view,t.fileRef,t.diffRef,t.taskRevision,t.workspaceRevision,t.indexRevision??``,t.viewRevision,t.fileRevision,t.patchPreimage,t.contentDigest].join(``):`no-target`}function Jt(e){return e?[qt(e),e.state,e.recordedState??``,e.recordedAt??``,e.evidenceRef??``].join(``):`no-review-state`}function Yt(e,t){return e.identity.projectRef===t.identity.projectRef&&e.identity.runtimeInstanceId===t.identity.runtimeInstanceId&&e.identity.sessionRef===t.identity.sessionRef&&e.identity.taskId===t.identity.taskId&&e.identity.taskRunId===t.identity.taskRunId&&e.identity.agentOperationId===t.identity.agentOperationId&&e.identity.toolCallId===t.identity.toolCallId}function Xt(e,t,n,r){return t.phase===`settled`&&t.resultCode===n&&t.action===`review.mark`&&t.commandId===e.commandId&&t.actionDigest===e.actionDigest&&t.idempotencyKeyDigest===r&&Yt(e,t)&&typeof t.settledAt==`string`&&typeof t.settlementEvidenceRef==`string`}function Zt(e,t){return!!(e&&e.projectRef===t.projectRef&&e.runtimeInstanceId===t.runtimeInstanceId&&e.sessionRef===t.sessionRef&&e.taskId===t.taskId&&e.taskRunId===t.taskRunId)}function Qt(e,t,n,r,i,a){return e.view===t&&e.fileRef===n&&e.taskRevision===a.revision.taskRevision&&e.workspaceRevision===a.sourceChanges.workingTree.revision&&e.indexRevision===a.sourceChanges.staged.revision&&e.viewRevision===r&&e.fileRevision===i}function $t(e,t,n,r,i,a,o){return!e||!Zt(e.identity,a.identity)?!1:e.target?Qt(e.target,t,n,r,i,a):e.state===`unavailable`&&!Ut(e,o)}async function en(e){let t=new TextEncoder().encode(e),n=await crypto.subtle.digest(`SHA-256`,t);return`sha256:${[...new Uint8Array(n)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}function tn({state:e,busy:t,status:n,deterministicEnabled:r,modelEnabled:i,locale:a,onGenerate:o,onCopy:s,onModel:c}){let l=e.value?.state===`ready`?e.value.summary:null;return(0,q.jsxs)(`section`,{className:`commit-summary-panel`,"aria-labelledby":`commit-summary-title`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Commit summary`}),(0,q.jsx)(`h3`,{id:`commit-summary-title`,children:P(a,`Tóm tắt phần đã stage`,`Staged changes summary`)}),(0,q.jsx)(`span`,{children:P(a,`Bản deterministic dùng 0 model token. Không commit hoặc push.`,`The deterministic version uses 0 model tokens. It does not commit or push.`)})]}),l?(0,q.jsxs)(`div`,{className:`commit-summary-output`,children:[(0,q.jsx)(`strong`,{children:l.title}),l.bodyLines.map((e,t)=>(0,q.jsx)(`code`,{children:e},`${l.summaryRef}.${t}`)),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`button`,{type:`button`,onClick:s,children:`Copy`}),(0,q.jsx)(`button`,{type:`button`,disabled:!i||t,onClick:c,children:P(a,`Nhờ Pi viết lại · tốn model token`,`Ask Pi to rewrite · uses model tokens`)})]})]}):(0,q.jsx)(`button`,{type:`button`,disabled:!r||t,onClick:o,children:t?P(a,`Đang tạo…`,`Generating…`):P(a,`Tạo summary · 0 token`,`Generate summary · 0 tokens`)}),n&&(0,q.jsx)(`p`,{className:`commit-summary-status`,role:`status`,children:n})]})}function nn({file:e,selected:t,onSelect:n,locale:r}){let i=e.path.lastIndexOf(`/`),a=i<0?e.path:e.path.slice(i+1);return(0,q.jsxs)(A,{component:`button`,className:`file-row`,selected:t,"data-selected":t,onClick:n,type:`button`,"aria-label":`${e.status} ${e.path} ${zt(e,r)}`,"aria-pressed":t,children:[(0,q.jsx)(`span`,{className:`file-status status-${e.status}`,children:e.status}),(0,q.jsxs)(`span`,{className:`file-name`,children:[(0,q.jsx)(`strong`,{children:a}),e.oldPath&&(0,q.jsxs)(`small`,{children:[P(r,`từ`,`from`),` `,e.oldPath]})]}),(0,q.jsx)(`span`,{className:`file-provenance`,children:Rt(e,r)}),(0,q.jsx)(`span`,{className:`file-evidence`,children:K(e,r)}),(0,q.jsx)(`span`,{className:`file-stats`,children:zt(e,r)})]})}function rn({text:e,path:t}){return(0,q.jsx)(q.Fragment,{children:Pt(e,t).map((e,t)=>(0,q.jsx)(`span`,{className:`syntax-${e.kind}`,children:e.text},`${t}.${e.kind}`))})}function an({line:e,side:t,path:n}){let r=e.kind===`deleted`?`old`:`new`,i=r===`old`?e.oldLineNumber??null:e.newLineNumber??null,a=r===`old`?(0,q.jsx)(mt,{path:n,side:`old`,line:i,code:e.text}):(0,q.jsx)(`span`,{children:e.oldLineNumber??``}),o=r===`new`?(0,q.jsx)(mt,{path:n,side:`new`,line:i,code:e.text}):(0,q.jsx)(`span`,{children:e.newLineNumber??``}),s=(0,q.jsx)(U,{path:n,side:r,line:i});if(t===`inline`)return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`diff-line diff-${e.kind}`,children:[a,o,(0,q.jsx)(`b`,{children:e.marker}),(0,q.jsx)(`code`,{children:(0,q.jsx)(rn,{text:e.text,path:n})})]}),s]});let c=e.kind===`added`?``:e.text,l=e.kind===`deleted`?``:e.text;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`split-line diff-${e.kind}`,children:[a,(0,q.jsx)(`code`,{children:(0,q.jsx)(rn,{text:c,path:n})}),o,(0,q.jsx)(`code`,{children:(0,q.jsx)(rn,{text:l,path:n})})]}),s]})}function on({state:e,review:t,mutation:n,revert:r,reviewEnabled:i,reviewBusy:a,reviewError:o,mutationEnabled:s,mutationBusy:c,mutationError:l,revertEnabled:u,revertBusy:d,openEnabled:f,openBusy:p,openStatus:m,detailError:g,mode:_,onMode:v,onReview:y,onMutation:b,onRevert:x,onOpen:C,onRetry:w,locale:T}){if(e.state===`idle`)return(0,q.jsx)(`div`,{className:`diff-empty`,children:(0,q.jsx)(`p`,{children:P(T,`Chọn một file để xem diff và bằng chứng liên quan.`,`Select a file to inspect its diff and related evidence.`)})});if(e.state===`loading`)return(0,q.jsx)(`div`,{className:`diff-empty`,children:(0,q.jsx)(`p`,{children:P(T,`Đang dựng diff từ Git và task baseline…`,`Building the diff from Git and the task baseline…`)})});if(e.state===`error`||!e.value)return(0,q.jsxs)(`div`,{className:`diff-empty error-state`,children:[(0,q.jsx)(`p`,{children:P(T,`Diff chưa thể đồng bộ với revision hiện tại.`,`The diff could not be reconciled with the current revision.`)}),w&&(0,q.jsx)(`button`,{type:`button`,onClick:w,children:P(T,`Thử đồng bộ lại`,`Retry reconciliation`)})]});let E=e.value;return(0,q.jsxs)(h,{className:`diff-viewer`,sx:{minWidth:0,bgcolor:`background.paper`},children:[(0,q.jsxs)(h,{component:`header`,className:`diff-toolbar`,sx:{position:`sticky`,top:0,zIndex:2,bgcolor:`background.paper`},children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:E.file.path}),(0,q.jsx)(M,{size:`small`,variant:`outlined`,className:`access-badge tone-${Ue(E.availability.state)}`,label:L(E.availability.state,T)})]}),(0,q.jsxs)(`div`,{className:`diff-actions`,children:[t.state===`ready`&&t.value&&(0,q.jsxs)(`div`,{className:`review-state review-${t.value.state}`,children:[(0,q.jsx)(`span`,{children:t.value.state===`reviewed`?P(T,`Đã review`,`Reviewed`):t.value.state===`stale`?P(T,`Review đã cũ`,`Review stale`):t.value.state===`unavailable`?P(T,`Không thể review`,`Review unavailable`):P(T,`Chưa review`,`Not reviewed`)}),t.value.target&&t.value.state!==`unavailable`&&(0,q.jsx)(`button`,{type:`button`,disabled:!i||a,onClick:()=>y(t.value.state===`reviewed`?`unreviewed`:`reviewed`),children:a?P(T,`Đang ghi…`,`Saving…`):t.value.state===`reviewed`?P(T,`Bỏ dấu review`,`Mark unreviewed`):t.value.state===`stale`?P(T,`Review lại`,`Review again`):P(T,`Đánh dấu đã review`,`Mark reviewed`)})]}),n.state===`ready`&&n.value?.state===`ready`&&n.value.target&&(0,q.jsxs)(`div`,{className:`source-mutation-preview`,children:[(0,q.jsx)(`span`,{children:n.value.action===`source.stage`?P(T,`Chuẩn bị đúng thay đổi file này để commit`,`Prepare this exact file change for commit`):P(T,`Bỏ khỏi vùng commit; giữ nguyên file đang làm việc`,`Remove from commit while keeping the working file`)}),(0,q.jsx)(`button`,{type:`button`,disabled:!s||c,onClick:()=>b([]),children:c?P(T,`Đang cập nhật Git…`,`Updating Git…`):n.value.action===`source.stage`?`Stage file`:`Unstage file`})]}),r.state===`ready`&&r.value?.state===`ready`&&r.value.target&&(0,q.jsxs)(`div`,{className:`source-revert-preview`,children:[(0,q.jsx)(`span`,{children:P(T,`Hoàn tác phần chưa stage; giữ nguyên index`,`Revert unstaged changes while preserving the index`)}),(0,q.jsx)(`button`,{type:`button`,disabled:!u||d,onClick:()=>x(null),children:d?P(T,`Đang dựng preview…`,`Building preview…`):`Revert file`})]}),(0,q.jsx)(Ye,{path:E.file.path}),f&&(0,q.jsx)(`div`,{className:`source-open-action`,children:(0,q.jsx)(`button`,{type:`button`,disabled:p,onClick:C,children:p?P(T,`Đang mở…`,`Opening…`):P(T,`Mở trong VS Code`,`Open in VS Code`)})}),(0,q.jsxs)(ae,{className:`mode-switch`,exclusive:!0,size:`small`,value:_,"aria-label":P(T,`Kiểu hiển thị diff`,`Diff layout`),onChange:(e,t)=>t&&v(t),children:[(0,q.jsx)(S,{value:`inline`,"aria-label":`Inline`,children:`Inline`}),(0,q.jsx)(S,{value:`split`,"aria-label":P(T,`Hai cột`,`Side by side`),children:P(T,`Hai cột`,`Side by side`)})]})]})]}),o&&(0,q.jsx)(`div`,{className:`review-error`,role:`status`,children:o}),l&&(0,q.jsx)(`div`,{className:`review-error`,role:`status`,children:l}),m&&(0,q.jsx)(`div`,{className:`source-open-status`,role:`status`,children:m}),g&&(0,q.jsxs)(`div`,{className:`detail-reconciliation-warning`,role:`status`,children:[(0,q.jsx)(`span`,{children:P(T,`Một thao tác source chưa đồng bộ; diff hiện tại vẫn chính xác.`,`A source action is not reconciled yet; the current diff remains exact.`)}),w&&(0,q.jsx)(`button`,{type:`button`,onClick:w,children:P(T,`Thử đồng bộ lại`,`Retry reconciliation`)})]}),(0,q.jsxs)(`div`,{className:`diff-context`,children:[(0,q.jsx)(`span`,{children:Rt(E.file,T)}),(0,q.jsx)(`span`,{children:K(E.file,T)}),(0,q.jsxs)(`span`,{className:`additions`,children:[`+`,E.file.stats.additions??`?`]}),(0,q.jsxs)(`span`,{className:`deletions`,children:[`−`,E.file.stats.deletions??`?`]})]}),E.fallback.kind!==`none`&&(0,q.jsxs)(`div`,{className:`diff-fallback`,children:[(0,q.jsx)(`strong`,{children:L(E.fallback.kind,T)}),(0,q.jsx)(`span`,{children:E.fallback.message??E.fallback.reasonCode??P(T,`Nội dung diff không sẵn sàng`,`Diff content unavailable`)})]}),E.hunks.map((e,t)=>(0,q.jsxs)(`section`,{className:`diff-hunk`,"aria-label":`${P(T,`Vùng thay đổi`,`Change region`)} ${t+1}`,children:[(0,q.jsxs)(`div`,{className:`hunk-header`,children:[(0,q.jsx)(`span`,{children:e.header}),(0,q.jsxs)(`span`,{className:`hunk-actions`,children:[n.value?.state===`ready`&&n.value.target?.hunkRefs.includes(e.hunkRef)&&(0,q.jsx)(`button`,{type:`button`,disabled:!s||c,onClick:()=>b([e.hunkRef]),children:n.value.action===`source.stage`?`Stage hunk`:`Unstage hunk`}),r.value?.state===`ready`&&r.value.target&&r.value.preview?.hunks.some(t=>t.hunkRef===e.hunkRef)&&(0,q.jsx)(`button`,{className:`revert-action`,type:`button`,disabled:!u||d,onClick:()=>x(e.hunkRef),children:`Revert hunk`})]})]}),(0,q.jsx)(`div`,{className:_===`split`?`split-code`:`inline-code`,children:e.lines.map(e=>(0,q.jsx)(an,{line:e,side:_,path:E.file.path},e.lineRef))}),E.unchangedRegions[t]&&(0,q.jsxs)(`div`,{className:`unchanged-region`,children:[`… `,E.unchangedRegions[t].lineCount,` `,P(T,`dòng không đổi đã thu gọn`,`unchanged lines collapsed`),` …`]})]},e.hunkRef)),(0,q.jsx)(dt,{path:E.file.path,shownLines:new Set(E.hunks.flatMap(e=>e.lines.map(e=>e.newLineNumber).filter(e=>typeof e==`number`)))}),E.truncation.truncated&&(0,q.jsxs)(`div`,{className:`diff-fallback`,children:[(0,q.jsx)(`strong`,{children:P(T,`Diff đã rút gọn`,`Diff truncated`)}),(0,q.jsxs)(`span`,{children:[P(T,`Còn`,`Another`),` `,E.truncation.omittedLines,` `,P(T,`dòng chưa hiển thị.`,`lines are not shown.`)]})]})]})}function sn({snapshot:e,refreshSnapshot:t,sessionRef:n,findings:r,onSendComments:i}){let{locale:a}=N(),[o,s]=(0,W.useState)(()=>n?ct(n):[]),[l,u]=(0,W.useState)(null);(0,W.useEffect)(()=>{s(n?ct(n):[]),u(null)},[n]),(0,W.useEffect)(()=>{let e=e=>{n&&e.detail===n&&s(ct(n))};return window.addEventListener(ft,e),()=>window.removeEventListener(ft,e)},[n]);let p=(0,W.useCallback)(e=>{s(e),n&&lt(n,e)},[n]),m=!!(e.task&&e.sourceChanges.task?.state!==`unavailable`&&e.sourceChanges.task?.revision),g=(0,W.useMemo)(()=>It(a),[a]),[v,y]=(0,W.useState)(()=>m?`task`:`working-tree`),[b,x]=(0,W.useState)({}),[S,C]=(0,W.useState)(null),[w,T]=(0,W.useState)({state:`idle`}),[E,D]=(0,W.useState)({state:`idle`}),[O,ee]=(0,W.useState)({state:`idle`}),[k,te]=(0,W.useState)({state:`idle`}),[A,re]=(0,W.useState)(null),[j,ie]=(0,W.useState)(!1),[ae,oe]=(0,W.useState)(null),[se,le]=(0,W.useState)(!1),[ue,F]=(0,W.useState)(null),[de,_e]=(0,W.useState)(!1),[Se,Ce]=(0,W.useState)(null),[Ee,De]=(0,W.useState)(!1),[Ae,je]=(0,W.useState)(null),[Ne,Fe]=(0,W.useState)(null),[Le,Re]=(0,W.useState)({state:`idle`}),[Be,Ve]=(0,W.useState)(!1),[He,I]=(0,W.useState)(null),[Ue,We]=(0,W.useState)(!1),[Ge,Ke]=(0,W.useState)(0),[L,qe]=(0,W.useState)(`inline`),Je={sourceProjectionRevision:e.sourceChanges.projectionRevision??null,taskViewRevision:e.sourceChanges.task.revision,workspaceRevision:e.sourceChanges.workingTree.revision,indexRevision:e.sourceChanges.staged.revision},Ye=Vt(Je,e.identity),Xe=[Ye,Ge].join(``),Ze=[Ye,e.revision.taskRevision??`no-task-revision`].join(``),R=[n??`default-session`,v,e.identity.projectRef,e.identity.runtimeInstanceId,e.identity.sessionRef,e.identity.taskId??`no-task`,e.identity.taskRunId??`no-run`].join(``),$e=(0,W.useRef)(R);$e.current=R;let et=(0,W.useRef)(0),tt=(0,W.useRef)(R);tt.current!==R&&(tt.current=R,et.current+=1);let nt=et.current,rt=(0,W.useRef)(null),it=b[v],z=it?.state===`ready`?Wt(it.value,it.revisionKey,Xe,Je,e.identity,v):null,at=it?.state===`ready`&&!z?{state:`loading`}:it,ot=z?.files??[],B=Kt(ot,S),V=B?ot.find(e=>e.fileRef===B)??null:null,H=!!(z&&V),U=e.capabilities.capabilities.reviewActions,dt=JSON.stringify(U),mt=v===`working-tree`?`source.stage`:v===`staged`?`source.unstage`:null,vt=U.status===`available`&&U.actions.reviewMark.available,yt=mt===`source.stage`?U.status===`available`&&U.actions.stage.available:mt===`source.unstage`&&U.status===`available`&&U.actions.unstage.available,xt=v===`working-tree`&&U.status===`available`&&U.actions.revert.available,G=H?[n??`default-session`,v,B,z.viewRevision,V.fileRevision,Ze,Ge,dt].join(``):`no-detail-request`,Ct=!!(H&&w.requestKey===G&&w.state===`ready`&&Gt(w.value,v,B,z.viewRevision,V.fileRevision,e)),wt=!!(H&&E.requestKey===G&&E.state===`ready`&&$t(E.value,v,B,z.viewRevision,V.fileRevision,e,Ct?w.value:void 0)),Et=!!(H&&O.requestKey===G&&O.state===`ready`&&$t(O.value,v,B,z.viewRevision,V.fileRevision,e,Ct?w.value:void 0)),Dt=!!(H&&k.requestKey===G&&k.state===`ready`&&$t(k.value,v,B,z.viewRevision,V.fileRevision,e,Ct?w.value:void 0)),Ot=!!(H&&w.requestKey===G&&w.state===`ready`&&!Ct),kt=!!(H&&E.requestKey===G&&E.state===`ready`&&!wt),At=!!(H&&O.requestKey===G&&O.state===`ready`&&!Et),jt=!!(H&&k.requestKey===G&&k.state===`ready`&&!Dt),Mt=!!(H&&w.requestKey===G&&w.state===`error`),Nt=!!(H&&vt&&E.requestKey===G&&E.state===`error`),Pt=!!(H&&yt&&O.requestKey===G&&O.state===`error`),Ft=!!(H&&xt&&k.requestKey===G&&k.state===`error`),Lt=Ot||kt||At||jt||Mt||Nt||Pt||Ft,Rt=!!(H&&Ct&&(!vt||wt)&&(!yt||Et)&&(!xt||Dt)),zt=(0,W.useRef)(null);B&&(zt.current={sourceScope:R,fileRef:B});let K=[R,B??(zt.current?.sourceScope===R?zt.current.fileRef:`no-file`)].join(``),Ut=(0,W.useRef)(K);Ut.current=K;let Yt=(0,W.useRef)(new Set),Zt=(0,W.useRef)(0),rn=(0,W.useRef)(K);rn.current!==K&&(rn.current=K,Zt.current+=1);let an=Zt.current,[sn,cn]=(0,W.useState)(null),J=!!(Lt&&t&&(!Yt.current.has(K)||sn?.scope===K&&sn.generation===an&&sn.requestKey===G)),Y=H?w.requestKey===G?(Ot||Mt)&&J?{state:`loading`}:Ot||Mt?{state:`error`}:w:{state:`loading`}:{state:`idle`},ln=Y.state===`ready`?Y.value:void 0,un=new Map;for(let e of ln?.hunks.flatMap(e=>e.lines)??[]){let t=e.kind===`deleted`?`old`:`new`,n=t===`old`?e.oldLineNumber:e.newLineNumber;typeof n==`number`&&ln&&un.set(ht(ln.file.path,t,n),e.text)}let dn=n&&i?{locale:a,findings:r,comments:o,editing:l?.key??null,open:(e,t,n,r)=>u({key:ht(e,t,n),path:e,side:t,line:n,code:r}),save:e=>{l&&p(_t(o,{path:l.path,side:l.side,line:l.line,code:l.code,text:e})),u(null)},cancel:()=>u(null),remove:e=>p(o.filter(t=>ht(t.path,t.side,t.line)!==e))}:null,fn=H&&vt?E.requestKey===G?J?{state:`loading`}:kt||Nt?{state:`error`}:E:{state:`loading`}:{state:`idle`},X=H&&yt?O.requestKey===G?J?{state:`loading`}:At||Pt?{state:`error`}:O:{state:`loading`}:{state:`idle`},pn=H&&xt?k.requestKey===G?J?{state:`loading`}:jt||Ft?{state:`error`}:k:{state:`loading`}:{state:`idle`},mn=H?[n??`default-session`,v,B,z.viewRevision,V.fileRevision,Ze].join(``):`no-source-authority`,Z=(0,W.useRef)(mn);Z.current=mn;let hn=[mn,e.revision.runtimeRevision,e.revision.controlRevision??`no-control-revision`,e.revision.approvalRevision??`no-approval-revision`,e.revision.sessionOptionRevision??`no-session-option-revision`,e.revision.queueRevision??`no-queue-revision`].join(``),Q=(0,W.useRef)(hn);Q.current=hn;let gn=[n??`default-session`,e.identity.projectRef,e.identity.runtimeInstanceId,e.identity.sessionRef,e.identity.taskId??`no-task`,e.identity.taskRunId??`no-run`,e.revision.taskRevision??`no-task-revision`,e.sourceChanges.staged.revision??`no-index-revision`].join(``),$=(0,W.useRef)(gn);$.current=gn;let _n=(0,W.useRef)(``),vn=(0,W.useRef)(``);_n.current=[mn,qt(fn.value)].join(``),vn.current=Jt(fn.value),(0,W.useEffect)(()=>{Re({state:`idle`}),I(null),We(!1)},[gn]),(0,W.useEffect)(()=>{!m&&v===`task`&&(y(`working-tree`),C(null))},[m,v]),(0,W.useEffect)(()=>{rt.current=null,Fe(null)},[R,nt]),(0,W.useEffect)(()=>{Rt&&(Yt.current.delete(K),cn(e=>e?.scope===K?null:e))},[Rt,K]),(0,W.useEffect)(()=>{let r=new AbortController,i=Xe;return x(e=>({...e,[v]:{state:`loading`,revisionKey:i}})),(n?ve(n,v,r.signal):me(v,r.signal)).then(n=>{if(!n){r.signal.aborted||x(e=>({...e,[v]:{state:`error`,revisionKey:i}}));return}if(!Ht(n,v,Je,e.identity)){if(r.signal.aborted)return;if(!t||rt.current===R){x(e=>({...e,[v]:{state:`error`,revisionKey:i}}));return}rt.current=R,x(e=>({...e,[v]:{state:`loading`,revisionKey:i}})),t().then(e=>{if(!r.signal.aborted){if(!e){x(e=>({...e,[v]:{state:`error`,revisionKey:i}}));return}Ke(e=>e+1)}}).catch(()=>{r.signal.aborted||x(e=>({...e,[v]:{state:`error`,revisionKey:i}}))});return}rt.current=null,r.signal.aborted||x(e=>({...e,[v]:{state:`ready`,value:n,revisionKey:i}}))}).catch(()=>{r.signal.aborted||x(e=>({...e,[v]:{state:`error`,revisionKey:i}}))}),()=>r.abort()},[v,Xe,n]);let yn=(0,W.useCallback)(()=>{let e=R,n=nt,r=Ye;rt.current=null,x(e=>({...e,[v]:{state:`loading`,revisionKey:Xe}})),(async()=>{let i;try{i=await t?.()}catch{}if($e.current!==e||et.current!==n)return;rt.current=e;let a=i?Vt({sourceProjectionRevision:i.sourceChanges.projectionRevision??null,taskViewRevision:i.sourceChanges.task.revision,workspaceRevision:i.sourceChanges.workingTree.revision,indexRevision:i.sourceChanges.staged.revision},i.identity):r;(!i||a===r)&&Ke(e=>e+1)})()},[t,Ye,nt,R,Xe,v]);(0,W.useEffect)(()=>{if(!B){T({state:`idle`}),D({state:`idle`}),ee({state:`idle`}),te({state:`idle`}),oe(null),F(null),Ce(null),re(null),je(null);return}let e=new AbortController,t=G;return T({state:`loading`,requestKey:t}),oe(null),F(null),Ce(null),re(null),je(null),D(vt?{state:`loading`,requestKey:t}:{state:`idle`}),ee(yt?{state:`loading`,requestKey:t}:{state:`idle`}),te(xt?{state:`loading`,requestKey:t}:{state:`idle`}),(n?he(n,v,B,e.signal):ke(v,B,e.signal)).then(n=>{e.signal.aborted||T({state:`ready`,value:n,requestKey:t})}).catch(()=>{e.signal.aborted||T({state:`error`,requestKey:t})}),vt&&(n?pe(n,v,B,e.signal):Me(v,B,e.signal)).then(n=>{e.signal.aborted||D({state:`ready`,value:n,requestKey:t})}).catch(()=>{e.signal.aborted||D({state:`error`,requestKey:t})}),yt&&mt&&(n?ye(n,mt,B,e.signal):xe(mt,B,e.signal)).then(n=>{e.signal.aborted||ee({state:`ready`,value:n,requestKey:t})}).catch(()=>{e.signal.aborted||ee({state:`error`,requestKey:t})}),xt&&(n?fe(n,B,null,e.signal):be(B,null,e.signal)).then(n=>{e.signal.aborted||te({state:`ready`,value:n,requestKey:t})}).catch(()=>{e.signal.aborted||te({state:`error`,requestKey:t})}),()=>e.abort()},[B,v,Ze,Ge,n,dt,G]);let bn=(0,W.useCallback)(e=>{if(!H||!t)return;let n=K,r=an,i=G;!e&&Yt.current.has(n)||(Yt.current.add(n),cn({scope:n,generation:r,requestKey:i}),t().then(e=>{e&&Ut.current===n&&Zt.current===r&&Ke(e=>e+1)}).catch(()=>void 0).finally(()=>{cn(e=>e?.scope===n&&e.generation===r&&e.requestKey===i?null:e)}))},[H,an,K,G,t]);(0,W.useEffect)(()=>{!H||!Lt||!t||Yt.current.has(K)||bn(!1)},[bn,H,Lt,K,t]);let xn=ot,Sn=(0,W.useMemo)(()=>{let e=new Map;for(let t of xn){let n=t.path.lastIndexOf(`/`),r=n<0?P(a,`Gốc project`,`Project root`):t.path.slice(0,n);e.set(r,[...e.get(r)??[],t])}return[...e.entries()]},[xn,a]),Cn=(0,W.useMemo)(()=>{let t={task:e.sourceChanges.task.counts.files,"working-tree":e.sourceChanges.workingTree.counts.files,staged:e.sourceChanges.staged.counts.files},n=n=>{let r=b[n];return(r?.state===`ready`?Wt(r.value,r.revisionKey,Xe,Je,e.identity,n):null)?.page.total??t[n]};return{task:n(`task`),"working-tree":n(`working-tree`),staged:n(`staged`)}},[b,Xe,e.sourceChanges.task.counts.files,e.sourceChanges.workingTree.counts.files,e.sourceChanges.staged.counts.files]),wn=e=>{Fe(null),y(e),C(null)},Tn=U.status===`available`&&U.actions.reviewMark.available,En=X.value?.action===`source.stage`?U.status===`available`&&U.actions.stage.available:X.value?.action===`source.unstage`&&U.status===`available`&&U.actions.unstage.available,Dn=U.status===`available`&&U.actions.revert.available,On=v===`working-tree`&&U.status===`available`&&U.actions.openInVsCode.available&&Y.state===`ready`&&Y.value?.availability.state===`current`&&Y.value.fallback.kind===`none`,kn=v===`staged`&&xn.length>0,An=kn&&U.status===`available`&&U.actions.generateCommitSummaryDeterministic.available,jn=kn&&U.status===`available`&&U.actions.generateCommitSummaryModel.available,Mn=t=>!t||t.identity.projectRef!==e.identity.projectRef||t.identity.runtimeInstanceId!==e.identity.runtimeInstanceId||t.identity.sessionRef!==e.identity.sessionRef||t.identity.taskId!==e.identity.taskId||t.identity.taskRunId!==e.identity.taskRunId?!1:t.summary?t.summary.taskRevision===e.revision.taskRevision&&t.summary.indexRevision===e.sourceChanges.staged.revision:t.state===`unavailable`,Nn=async t=>{if(!B||!fn.value||j)return;let r=fn.value,i=Jt(r),o=_n.current,s=Q.current,c=R,l=nt,u=K,d=an,f=Ye,p=!1;ie(!0),oe(null),Fe(null);try{let m=await bt(e,r,t);if(_n.current!==o||vn.current!==i||Q.current!==s)return;let h=await en(m.idempotencyKey);if(_n.current!==o||vn.current!==i||Q.current!==s)return;p=!0;let g=await we(m);if(!Xt(m,g,t,h)){if(g.phase!==`rejected`){await Pn(c,l,u,d,f,P(a,`Chưa xác nhận được receipt review. Piagent đã đọc lại trạng thái chính thức và sẽ không tự gửi lại lệnh.`,`The review receipt is unconfirmed. Piagent reloaded canonical state and will not resend the command.`));return}_n.current===o&&vn.current===i&&oe(g.error?.message??P(a,`Không xác nhận được trạng thái review chính xác; hãy tải lại diff.`,`The exact review state could not be confirmed; reload the diff.`));return}if(_n.current!==o||vn.current!==i)return;D(e=>_n.current===o&&Jt(e.value)===i?{state:`ready`,requestKey:e.requestKey,value:{...r,generatedAt:g.settledAt,state:g.resultCode,recordedState:g.resultCode,recordedAt:g.settledAt,evidenceRef:g.settlementEvidenceRef,reasonCode:null,health:{state:`ok`,reasonCode:null,message:null}}}:e),(n?pe(n,v,B):Me(v,B)).then(e=>D(t=>_n.current===o&&t.state===`ready`&&t.value?.evidenceRef===g.settlementEvidenceRef?{state:`ready`,value:e,requestKey:t.requestKey}:t)).catch(()=>void 0)}catch{p?await Pn(c,l,u,d,f,P(a,`Mất kết nối khi đang ghi review. Piagent đã đọc lại trạng thái chính thức và sẽ không tự gửi lại lệnh.`,`The connection was lost while saving review. Piagent reloaded canonical state and will not resend the command.`)):_n.current===o&&vn.current===i&&oe(P(a,`Không thể ghi trạng thái review. Nội dung source không bị thay đổi.`,`Unable to save review state. Source content was not changed.`))}finally{ie(!1)}},Pn=async(e,n,r,i,a,o)=>{Ut.current===r&&Zt.current===i&&(T({state:`idle`}),D({state:`idle`}),ee({state:`idle`}),te({state:`idle`}),re(null),oe(null),F(null),Ce(null),je(null),Fe(null));let s;try{s=await t?.()}catch{}if($e.current!==e||et.current!==n)return;let c=s?Vt({sourceProjectionRevision:s.sourceChanges.projectionRevision??null,taskViewRevision:s.sourceChanges.task.revision,workspaceRevision:s.sourceChanges.workingTree.revision,indexRevision:s.sourceChanges.staged.revision},s.identity):a;(!s||c===a)&&Ke(e=>e+1),Fe({scope:e,generation:n,message:o})},Fn=async(n=[])=>{if(!B||!z||!X.value||X.value.state!==`ready`||se)return;let r=Z.current,i=Q.current,o=X.value,s=R,c=nt,l=K,u=an,d=Ye,f=!1;le(!0),F(null),Fe(null);try{let p=await St(e,o,n);if(Z.current!==r||Q.current!==i)return;f=!0;let m=await ze(p);if(m.phase===`uncertain`){await Pn(s,c,l,u,d,P(a,`Chưa xác nhận được trạng thái Git. Piagent đã tải lại Source Changes và sẽ không tự gửi lại lệnh.`,`Git state is unconfirmed. Piagent refreshed Source Changes and will not resend the command.`));return}if(m.phase!==`settled`||![`staged`,`unstaged`].includes(m.resultCode)){Z.current===r&&F(m.error?.message??P(a,`File hoặc Git index đã thay đổi; hãy tải lại preview.`,`The file or Git index changed; reload the preview.`));return}Z.current===r&&C(null),await t?.(),Ke(e=>e+1)}catch{f?await Pn(s,c,l,u,d,P(a,`Mất kết nối khi đang cập nhật Git. Piagent đã tải lại Source Changes và sẽ không tự gửi lại lệnh.`,`The connection was lost while updating Git. Piagent refreshed Source Changes and will not resend the command.`)):Z.current===r&&F(P(a,`Không thể chuẩn bị lệnh cập nhật Git; source chưa bị thay đổi.`,`Unable to prepare the Git update; source was not changed.`))}finally{le(!1)}},In=async e=>{if(!B||!z||!Dn||de)return;let t=Z.current,r=B;_e(!0),Ce(null),Fe(null);try{let i=n?await fe(n,r,e):await be(r,e);if(Z.current!==t)return;if(i.state!==`ready`||!i.target){Ce(P(a,`Không thể hoàn tác an toàn: provenance hoặc diff hiện tại không còn đủ bằng chứng.`,`Safe revert is unavailable because provenance or the current diff lacks evidence.`));return}re(i)}catch{Z.current===t&&Ce(P(a,`Không thể dựng preview hoàn tác. Source chưa bị thay đổi.`,`Unable to build a revert preview. Source was not changed.`))}finally{_e(!1)}},Ln=async()=>{if(!A?.target||!B||!z||!V||de||!Qt(A.target,v,B,z.viewRevision,V.fileRevision,e))return;let r=Z.current,i=Q.current,o=A,s=R,c=nt,l=K,u=an,d=Ye,f=!1;_e(!0),Ce(null),Fe(null);try{let p=await pt(e,o);if(Z.current!==r||Q.current!==i)return;f=!0;let m=await Pe(p,void 0,n);if(m.phase===`uncertain`){await Pn(s,c,l,u,d,P(a,`Chưa xác nhận được kết quả revert. Piagent đã tải lại Source Changes và sẽ không tự gửi lại lệnh.`,`The revert result is unconfirmed. Piagent refreshed Source Changes and will not resend the command.`));return}if(m.phase!==`settled`||m.resultCode!==`reverted`){Z.current===r&&Ce(m.error?.message??P(a,`Preview đã cũ; hãy mở lại trước khi xác nhận.`,`The preview is stale; reopen it before confirming.`));return}Z.current===r&&(re(null),C(null)),await t?.(),Ke(e=>e+1)}catch{f?await Pn(s,c,l,u,d,P(a,`Mất kết nối khi đang revert. Piagent đã tải lại Source Changes và sẽ không tự gửi lại lệnh.`,`The connection was lost during revert. Piagent refreshed Source Changes and will not resend the command.`)):Z.current===r&&Ce(P(a,`Không thể chuẩn bị lệnh revert; source chưa bị thay đổi.`,`Unable to prepare the revert command; source was not changed.`))}finally{_e(!1)}},Rn=async()=>{if(!B||!On||Ee)return;let t=Z.current,n=Q.current,r=B;De(!0),je(null);try{let i=await Tt(e,r);if(Z.current!==t||Q.current!==n)return;let o=await Te(i);if(Z.current!==t)return;o.phase===`settled`&&o.resultCode===`opened`?je(P(a,`VS Code đã nhận yêu cầu mở file.`,`VS Code received the open-file request.`)):je(o.phase===`uncertain`?P(a,`Không xác nhận được VS Code đã nhận file. Piagent sẽ không tự mở lại.`,`It is unknown whether VS Code received the file. Piagent will not retry automatically.`):o.error?.message??P(a,`File hoặc phiên làm việc đã thay đổi; hãy tải lại trước khi mở.`,`The file or session changed; refresh before opening.`))}catch{Z.current===t&&je(P(a,`Không thể mở file trong VS Code. Diff hiện tại vẫn được giữ nguyên.`,`Unable to open the file in VS Code. The current diff remains available.`))}finally{De(!1)}},zn=async()=>{if(!An||Be)return;let e=$.current;Ve(!0),I(null),Re({state:`loading`});try{let t=n?await ge(n):await Oe();if($.current!==e)return;if(!Mn(t)){Re({state:`error`}),I(P(a,`Staged Changes đã đổi trong lúc dựng summary; hãy tạo lại.`,`Staged Changes changed while the summary was generated; generate it again.`));return}Re({state:`ready`,value:t}),t.state!==`ready`&&I(P(a,`Staged Changes đã thay đổi hoặc chưa có dữ liệu để tóm tắt.`,`Staged Changes changed or has no data to summarize.`))}catch{$.current===e&&(Re({state:`error`}),I(P(a,`Không thể dựng commit summary từ index hiện tại.`,`Unable to generate a commit summary from the current index.`)))}finally{Ve(!1)}},Bn=async()=>{let e=Le.value?.summary;if(!e||!Mn(Le.value))return;let t=$.current;try{await navigator.clipboard.writeText([e.title,``,...e.bodyLines].join(`
2
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bt as t,Ct as n,D as r,Dn as i,Dt as a,Fn as o,Ft as s,Lt as c,Nt as l,Ot as u,Rt as d,St as f,Tt as p,Ut as m,Vt as h,Wt as g,Yt as _,_t as v,a as y,c as b,ct as x,d as S,gt as C,i as w,it as T,j as E,jt as D,l as O,mt as ee,n as k,o as te,ot as A,r as ne,rt as re,s as j,st as ie,u as ae,v as oe,wt as M,xt as se,zt as ce}from"./vendor-CSDKB7mU.js";import{i as N,n as P}from"./ui-preferences-0waeSO-S.js";import{t as le}from"./index-uhJMXxqD.js";import{$ as ue,A as F,C as de,G as fe,H as pe,J as me,L as he,P as ge,Q as _e,U as ve,W as ye,X as be,Y as xe,Z as Se,_ as Ce,at as we,ct as Te,dt as Ee,et as De,f as Oe,g as ke,h as Ae,it as je,j as Me,k as Ne,lt as Pe,m as Fe,nt as Ie,ot as Le,rt as Re,st as ze,v as Be,y as Ve}from"./api-BQS4Dtrr.js";import{t as He}from"./ActivityPanel-DxQ3_dyT.js";import{a as I,c as Ue,i as We,n as Ge,o as Ke,r as L,s as qe,t as Je}from"./view-model-CWNiS4JN.js";import{n as Ye}from"./workspace-navigation-DkVobhwg.js";import{A as Xe,D as Ze,E as Qe,O as R,S as $e,f as et,g as tt,h as nt,j as rt,k as it,l as z,m as at,n as ot,u as B,v as V,y as H}from"./transcript-view-model-Bq0nkxyu.js";import{a as st,c as ct,d as lt,i as U,l as ut,n as dt,o as ft,p as pt,r as mt,s as ht,t as gt,u as _t}from"./LineReview-C_0ZpgCH.js";var W=e(o(),1);function vt(e){return Array.isArray(e)?`[${e.map(vt).join(`,`)}]`:e&&typeof e==`object`?`{${Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>`${JSON.stringify(e)}:${vt(t)}`).join(`,`)}}`:JSON.stringify(e)}async function yt(e){let t=new TextEncoder().encode(vt(e)),n=await crypto.subtle.digest(`SHA-256`,t);return`sha256:${[...new Uint8Array(n)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}async function bt(e,t,n){if(!t.target||t.state===`unavailable`)throw Error(`review-target-unavailable`);let r=new Date,i=new Date(r.getTime()+3e5),a=t.target,o={...structuredClone(e.identity),agentOperationId:null,toolCallId:null},s={runtimeRevision:e.revision.runtimeRevision,taskRevision:a.taskRevision,controlRevision:e.revision.controlRevision,workspaceRevision:a.workspaceRevision,indexRevision:a.indexRevision,approvalRevision:e.revision.approvalRevision,sessionOptionRevision:e.revision.sessionOptionRevision,queueRevision:e.revision.queueRevision,workspacePreimage:null,indexPreimage:null,patchPreimage:a.patchPreimage},c={view:a.view,fileRef:a.fileRef,diffRef:a.diffRef,reviewState:n,contentDigest:a.contentDigest},l={schemaVersion:1,version:`piagent-webui-control-v1`,messageType:`command`,commandId:`review-command.${crypto.randomUUID()}`,idempotencyKey:crypto.randomUUID(),requestedAt:r.toISOString(),expiresAt:i.toISOString(),capabilityScope:`reviewActions`,action:`review.mark`,actionDigest:``,identity:o,expectedRevisions:s,payload:c};return l.actionDigest=await yt({action:l.action,identity:o,expectedRevisions:s,payload:c}),l}function xt(e){return Array.isArray(e)?`[${e.map(xt).join(`,`)}]`:e&&typeof e==`object`?`{${Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>`${JSON.stringify(e)}:${xt(t)}`).join(`,`)}}`:JSON.stringify(e)}async function G(e){let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(xt(e)));return`sha256:${[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}async function St(e,t,n=[]){if(t.state!==`ready`||!t.target)throw Error(`source-mutation-preview-unavailable`);let r=new Date,i=t.target,a={...structuredClone(e.identity),agentOperationId:null,toolCallId:null};if(n.length>128||new Set(n).size!==n.length||n.some(e=>!i.hunkRefs.includes(e))||xt(n)!==xt(i.hunkRefs.filter(e=>n.includes(e))))throw Error(`source-mutation-hunk-unavailable`);let o={runtimeRevision:e.revision.runtimeRevision,taskRevision:i.taskRevision,controlRevision:e.revision.controlRevision,workspaceRevision:i.workspaceRevision,indexRevision:i.indexRevision,approvalRevision:e.revision.approvalRevision,sessionOptionRevision:e.revision.sessionOptionRevision,queueRevision:e.revision.queueRevision,workspacePreimage:i.workspacePreimage,indexPreimage:i.indexPreimage,patchPreimage:i.patchPreimage},s={fileRef:i.fileRef,hunkRefs:[...n],contentDigest:i.contentDigest},c={schemaVersion:1,version:`piagent-webui-control-v1`,messageType:`command`,commandId:`source-mutation.${crypto.randomUUID()}`,idempotencyKey:crypto.randomUUID(),requestedAt:r.toISOString(),expiresAt:new Date(r.getTime()+3e5).toISOString(),capabilityScope:`reviewActions`,action:t.action,actionDigest:``,identity:a,expectedRevisions:o,payload:s};return c.actionDigest=await G({action:c.action,identity:a,expectedRevisions:o,payload:s}),c}function Ct(e){return Array.isArray(e)?`[${e.map(Ct).join(`,`)}]`:e&&typeof e==`object`?`{${Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>`${JSON.stringify(e)}:${Ct(t)}`).join(`,`)}}`:JSON.stringify(e)}async function wt(e){let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(Ct(e)));return`sha256:${[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}async function Tt(e,t,n=null,r=null){if(!e.identity.taskId||!e.identity.taskRunId||!e.revision.taskRevision||!e.revision.workspaceRevision)throw Error(`source-open-task-authority-unavailable`);if(r!==null&&n===null)throw Error(`source-open-location-invalid`);let i=new Date,a={...structuredClone(e.identity),agentOperationId:null,toolCallId:null},o={runtimeRevision:e.revision.runtimeRevision,taskRevision:e.revision.taskRevision,controlRevision:e.revision.controlRevision,workspaceRevision:e.revision.workspaceRevision,indexRevision:e.revision.indexRevision,approvalRevision:e.revision.approvalRevision,sessionOptionRevision:e.revision.sessionOptionRevision,queueRevision:e.revision.queueRevision,workspacePreimage:null,indexPreimage:null,patchPreimage:null},s={fileRef:t,line:n,column:r},c={schemaVersion:1,version:`piagent-webui-control-v1`,messageType:`command`,commandId:`source-open.${crypto.randomUUID()}`,idempotencyKey:crypto.randomUUID(),requestedAt:i.toISOString(),expiresAt:new Date(i.getTime()+3e5).toISOString(),capabilityScope:`reviewActions`,action:`source.open-in-vscode`,actionDigest:``,identity:a,expectedRevisions:o,payload:s};return c.actionDigest=await wt({action:c.action,identity:a,expectedRevisions:o,payload:s}),c}var Et=new Set(`as.async.await.break.case.catch.class.const.continue.def.delete.do.else.enum.export.extends.finally.for.from.function.if.implements.import.in.interface.let.new.of.package.private.protected.public.return.static.struct.switch.throw.try.type.var.while.with.yield`.split(`.`)),Dt=new Set([`false`,`nil`,`null`,`None`,`true`,`undefined`]),Ot=new Set([`py`,`rb`,`sh`,`bash`,`zsh`,`yaml`,`yml`,`toml`]);function kt(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n<0?``:t.slice(n+1).toLowerCase()}function At(e){return/[A-Za-z_$]/.test(e)}function jt(e){return/[A-Za-z0-9_$-]/.test(e)}function Mt(e){return e>=`0`&&e<=`9`}function Nt(e,t,n){if(!n)return;let r=e[e.length-1];r?.kind===t?r.text+=n:e.push({kind:t,text:n})}function Pt(e,t){let n=[],r=kt(t),i=0;for(;i<e.length;){if(e.startsWith(`//`,i)||e.startsWith(`/*`,i)||e[i]===`#`&&Ot.has(r)){Nt(n,`comment`,e.slice(i));break}let t=e[i]??``;if(t===`"`||t===`'`||t==="`"){let r=t,a=i+1;for(;a<e.length;){if(e[a]===`\\`){a+=2;continue}if(e[a]===r){a+=1;break}a+=1}let o=e.slice(i,a);Nt(n,e.slice(a).match(/^\s*:/)&&r===`"`?`property`:`string`,o),i=a;continue}if(Mt(t)||t===`.`&&Mt(e[i+1]??``)){let t=i+1;for(;t<e.length&&/[0-9A-Fa-f_xXob.+-]/.test(e[t]??``);)t+=1;Nt(n,`number`,e.slice(i,t)),i=t;continue}if(At(t)){let t=i+1;for(;t<e.length&&jt(e[t]??``);)t+=1;let r=e.slice(i,t);Nt(n,Et.has(r)?`keyword`:Dt.has(r)?`literal`:`plain`,r),i=t;continue}Nt(n,`plain`,t),i+=1}return n}var Ft=[{view:`task`,label:`Thay đổi của task`,shortLabel:`Task`},{view:`working-tree`,label:`Toàn bộ working tree`,shortLabel:`Working Tree`},{view:`staged`,label:`Đã chuẩn bị commit`,shortLabel:`Staged`}];function It(e){return e===`vi`?Ft:[{view:`task`,label:`Task Changes`,shortLabel:`Task`},{view:`working-tree`,label:`Full Working Tree`,shortLabel:`Working Tree`},{view:`staged`,label:`Staged Changes`,shortLabel:`Staged`}]}var Lt={"pre-existing-user":`Có sẵn trước task`,"runtime-observed-agent":`Pi runtime đã chạm`,"post-baseline-unattributed":`Thay đổi sau baseline · chưa rõ nguồn`,mixed:`Trộn thay đổi người dùng và runtime`};function Rt(e,t=`vi`){return t===`vi`?Lt[e.provenance.classification]:{"pre-existing-user":`Pre-existing user change`,"runtime-observed-agent":`Runtime-observed agent touch`,"post-baseline-unattributed":`Post-baseline · unattributed`,mixed:`Mixed user and runtime change`}[e.provenance.classification]}function zt(e,t=`vi`){return e.stats.state===`exact`?`+${e.stats.additions??0} −${e.stats.deletions??0}`:t===`vi`?`Dòng thay đổi chưa xác định`:`Line changes unavailable`}function Bt(e,t=`vi`){let n=e.page.total;return e.availability.state===`stale`?t===`vi`?`Đang đồng bộ lại…`:`Resynchronizing…`:e.availability.state===`unavailable`?e.availability.message??(t===`vi`?`Nguồn thay đổi chưa sẵn sàng`:`Source changes unavailable`):n===0?t===`vi`?`Không có file thay đổi`:`No changed files`:t===`vi`?`${n} file${e.page.truncated?` · danh sách đã rút gọn`:``}`:`${n} file${n===1?``:`s`}${e.page.truncated?` · list truncated`:``}`}function K(e,t=`vi`){return t===`vi`?`${e.criterionIds.length} tiêu chí · ${e.verifierAttemptIds.length} verifier`:`${e.criterionIds.length} criteria · ${e.verifierAttemptIds.length} verifiers`}function Vt(e,t){return[t.projectRef,t.runtimeInstanceId,t.sessionRef,t.taskId??`no-task`,t.taskRunId??`no-run`,e.sourceProjectionRevision??`no-source-projection-revision`,e.taskViewRevision??`no-task-view-revision`,e.workspaceRevision??`no-workspace-revision`,e.indexRevision??`no-index-revision`].join(``)}function Ht(e,t,n,r){if(!e||e.view!==t||e.availability.state===`stale`||e.identity.projectRef!==r.projectRef||e.identity.runtimeInstanceId!==r.runtimeInstanceId||e.identity.sessionRef!==r.sessionRef||e.identity.taskId!==r.taskId||e.identity.taskRunId!==r.taskRunId)return!1;let i=t===`task`?n.taskViewRevision:t===`working-tree`?n.workspaceRevision:n.indexRevision;if(!(i===null?e.availability.state===`unavailable`:e.viewRevision===i))return!1;let a=e.snapshotBinding;return a?n.sourceProjectionRevision!==null&&a.sourceProjectionRevision===n.sourceProjectionRevision&&a.taskViewRevision===n.taskViewRevision&&a.workspaceRevision===n.workspaceRevision&&a.indexRevision===n.indexRevision:n.sourceProjectionRevision===null}function Ut(e,t){if(!e||e.state!==`unavailable`||e.target!==null||!e.reasonCode)return!1;let n=t?.availability.state===`current`&&t.fallback.kind===`none`;return e.reasonCode===`review-target-unavailable`?n:e.reasonCode===`no-unstaged-change`||e.reasonCode===`no-staged-change`?n&&t.hunks.length>0:[`-target-stale`,`-preview-incomplete`,`-preimage-unavailable`,`-authority-unavailable`].some(t=>e.reasonCode.endsWith(t))}function Wt(e,t,n,r,i,a){return t===n&&Ht(e,a,r,i)?e??null:null}function Gt(e,t,n,r,i,a){let o=e?.identity;return!!(e&&o&&o.projectRef===a.identity.projectRef&&o.runtimeInstanceId===a.identity.runtimeInstanceId&&o.sessionRef===a.identity.sessionRef&&o.taskId===a.identity.taskId&&o.taskRunId===a.identity.taskRunId&&e.view===t&&e.file.fileRef===n&&e.file.fileRevision===i&&e.precondition.expectedViewRevision===r&&e.precondition.expectedFileRevision===i&&e.observed.viewRevision===r&&e.observed.fileRevision===i&&e.availability.state!==`stale`&&e.fallback.kind!==`stale`)}function Kt(e,t){return t&&e.some(e=>e.fileRef===t)?t:e[0]?.fileRef??null}var q=i();function qt(e){let t=e?.target;return t?[t.view,t.fileRef,t.diffRef,t.taskRevision,t.workspaceRevision,t.indexRevision??``,t.viewRevision,t.fileRevision,t.patchPreimage,t.contentDigest].join(``):`no-target`}function Jt(e){return e?[qt(e),e.state,e.recordedState??``,e.recordedAt??``,e.evidenceRef??``].join(``):`no-review-state`}function Yt(e,t){return e.identity.projectRef===t.identity.projectRef&&e.identity.runtimeInstanceId===t.identity.runtimeInstanceId&&e.identity.sessionRef===t.identity.sessionRef&&e.identity.taskId===t.identity.taskId&&e.identity.taskRunId===t.identity.taskRunId&&e.identity.agentOperationId===t.identity.agentOperationId&&e.identity.toolCallId===t.identity.toolCallId}function Xt(e,t,n,r){return t.phase===`settled`&&t.resultCode===n&&t.action===`review.mark`&&t.commandId===e.commandId&&t.actionDigest===e.actionDigest&&t.idempotencyKeyDigest===r&&Yt(e,t)&&typeof t.settledAt==`string`&&typeof t.settlementEvidenceRef==`string`}function Zt(e,t){return!!(e&&e.projectRef===t.projectRef&&e.runtimeInstanceId===t.runtimeInstanceId&&e.sessionRef===t.sessionRef&&e.taskId===t.taskId&&e.taskRunId===t.taskRunId)}function Qt(e,t,n,r,i,a){return e.view===t&&e.fileRef===n&&e.taskRevision===a.revision.taskRevision&&e.workspaceRevision===a.sourceChanges.workingTree.revision&&e.indexRevision===a.sourceChanges.staged.revision&&e.viewRevision===r&&e.fileRevision===i}function $t(e,t,n,r,i,a,o){return!e||!Zt(e.identity,a.identity)?!1:e.target?Qt(e.target,t,n,r,i,a):e.state===`unavailable`&&!Ut(e,o)}async function en(e){let t=new TextEncoder().encode(e),n=await crypto.subtle.digest(`SHA-256`,t);return`sha256:${[...new Uint8Array(n)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}function tn({state:e,busy:t,status:n,deterministicEnabled:r,modelEnabled:i,locale:a,onGenerate:o,onCopy:s,onModel:c}){let l=e.value?.state===`ready`?e.value.summary:null;return(0,q.jsxs)(`section`,{className:`commit-summary-panel`,"aria-labelledby":`commit-summary-title`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Commit summary`}),(0,q.jsx)(`h3`,{id:`commit-summary-title`,children:P(a,`Tóm tắt phần đã stage`,`Staged changes summary`)}),(0,q.jsx)(`span`,{children:P(a,`Bản deterministic dùng 0 model token. Không commit hoặc push.`,`The deterministic version uses 0 model tokens. It does not commit or push.`)})]}),l?(0,q.jsxs)(`div`,{className:`commit-summary-output`,children:[(0,q.jsx)(`strong`,{children:l.title}),l.bodyLines.map((e,t)=>(0,q.jsx)(`code`,{children:e},`${l.summaryRef}.${t}`)),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`button`,{type:`button`,onClick:s,children:`Copy`}),(0,q.jsx)(`button`,{type:`button`,disabled:!i||t,onClick:c,children:P(a,`Nhờ Pi viết lại · tốn model token`,`Ask Pi to rewrite · uses model tokens`)})]})]}):(0,q.jsx)(`button`,{type:`button`,disabled:!r||t,onClick:o,children:t?P(a,`Đang tạo…`,`Generating…`):P(a,`Tạo summary · 0 token`,`Generate summary · 0 tokens`)}),n&&(0,q.jsx)(`p`,{className:`commit-summary-status`,role:`status`,children:n})]})}function nn({file:e,selected:t,onSelect:n,locale:r}){let i=e.path.lastIndexOf(`/`),a=i<0?e.path:e.path.slice(i+1);return(0,q.jsxs)(A,{component:`button`,className:`file-row`,selected:t,"data-selected":t,onClick:n,type:`button`,"aria-label":`${e.status} ${e.path} ${zt(e,r)}`,"aria-pressed":t,children:[(0,q.jsx)(`span`,{className:`file-status status-${e.status}`,children:e.status}),(0,q.jsxs)(`span`,{className:`file-name`,children:[(0,q.jsx)(`strong`,{children:a}),e.oldPath&&(0,q.jsxs)(`small`,{children:[P(r,`từ`,`from`),` `,e.oldPath]})]}),(0,q.jsx)(`span`,{className:`file-provenance`,children:Rt(e,r)}),(0,q.jsx)(`span`,{className:`file-evidence`,children:K(e,r)}),(0,q.jsx)(`span`,{className:`file-stats`,children:zt(e,r)})]})}function rn({text:e,path:t}){return(0,q.jsx)(q.Fragment,{children:Pt(e,t).map((e,t)=>(0,q.jsx)(`span`,{className:`syntax-${e.kind}`,children:e.text},`${t}.${e.kind}`))})}function an({line:e,side:t,path:n}){let r=e.kind===`deleted`?`old`:`new`,i=r===`old`?e.oldLineNumber??null:e.newLineNumber??null,a=r===`old`?(0,q.jsx)(mt,{path:n,side:`old`,line:i,code:e.text}):(0,q.jsx)(`span`,{children:e.oldLineNumber??``}),o=r===`new`?(0,q.jsx)(mt,{path:n,side:`new`,line:i,code:e.text}):(0,q.jsx)(`span`,{children:e.newLineNumber??``}),s=(0,q.jsx)(U,{path:n,side:r,line:i});if(t===`inline`)return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`diff-line diff-${e.kind}`,children:[a,o,(0,q.jsx)(`b`,{children:e.marker}),(0,q.jsx)(`code`,{children:(0,q.jsx)(rn,{text:e.text,path:n})})]}),s]});let c=e.kind===`added`?``:e.text,l=e.kind===`deleted`?``:e.text;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`split-line diff-${e.kind}`,children:[a,(0,q.jsx)(`code`,{children:(0,q.jsx)(rn,{text:c,path:n})}),o,(0,q.jsx)(`code`,{children:(0,q.jsx)(rn,{text:l,path:n})})]}),s]})}function on({state:e,review:t,mutation:n,revert:r,reviewEnabled:i,reviewBusy:a,reviewError:o,mutationEnabled:s,mutationBusy:c,mutationError:l,revertEnabled:u,revertBusy:d,openEnabled:f,openBusy:p,openStatus:m,detailError:g,mode:_,onMode:v,onReview:y,onMutation:b,onRevert:x,onOpen:C,onRetry:w,locale:T}){if(e.state===`idle`)return(0,q.jsx)(`div`,{className:`diff-empty`,children:(0,q.jsx)(`p`,{children:P(T,`Chọn một file để xem diff và bằng chứng liên quan.`,`Select a file to inspect its diff and related evidence.`)})});if(e.state===`loading`)return(0,q.jsx)(`div`,{className:`diff-empty`,children:(0,q.jsx)(`p`,{children:P(T,`Đang dựng diff từ Git và task baseline…`,`Building the diff from Git and the task baseline…`)})});if(e.state===`error`||!e.value)return(0,q.jsxs)(`div`,{className:`diff-empty error-state`,children:[(0,q.jsx)(`p`,{children:P(T,`Diff chưa thể đồng bộ với revision hiện tại.`,`The diff could not be reconciled with the current revision.`)}),w&&(0,q.jsx)(`button`,{type:`button`,onClick:w,children:P(T,`Thử đồng bộ lại`,`Retry reconciliation`)})]});let E=e.value;return(0,q.jsxs)(h,{className:`diff-viewer`,sx:{minWidth:0,bgcolor:`background.paper`},children:[(0,q.jsxs)(h,{component:`header`,className:`diff-toolbar`,sx:{position:`sticky`,top:0,zIndex:2,bgcolor:`background.paper`},children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:E.file.path}),(0,q.jsx)(M,{size:`small`,variant:`outlined`,className:`access-badge tone-${Ue(E.availability.state)}`,label:L(E.availability.state,T)})]}),(0,q.jsxs)(`div`,{className:`diff-actions`,children:[t.state===`ready`&&t.value&&(0,q.jsxs)(`div`,{className:`review-state review-${t.value.state}`,children:[(0,q.jsx)(`span`,{children:t.value.state===`reviewed`?P(T,`Đã review`,`Reviewed`):t.value.state===`stale`?P(T,`Review đã cũ`,`Review stale`):t.value.state===`unavailable`?P(T,`Không thể review`,`Review unavailable`):P(T,`Chưa review`,`Not reviewed`)}),t.value.target&&t.value.state!==`unavailable`&&(0,q.jsx)(`button`,{type:`button`,disabled:!i||a,onClick:()=>y(t.value.state===`reviewed`?`unreviewed`:`reviewed`),children:a?P(T,`Đang ghi…`,`Saving…`):t.value.state===`reviewed`?P(T,`Bỏ dấu review`,`Mark unreviewed`):t.value.state===`stale`?P(T,`Review lại`,`Review again`):P(T,`Đánh dấu đã review`,`Mark reviewed`)})]}),n.state===`ready`&&n.value?.state===`ready`&&n.value.target&&(0,q.jsxs)(`div`,{className:`source-mutation-preview`,children:[(0,q.jsx)(`span`,{children:n.value.action===`source.stage`?P(T,`Chuẩn bị đúng thay đổi file này để commit`,`Prepare this exact file change for commit`):P(T,`Bỏ khỏi vùng commit; giữ nguyên file đang làm việc`,`Remove from commit while keeping the working file`)}),(0,q.jsx)(`button`,{type:`button`,disabled:!s||c,onClick:()=>b([]),children:c?P(T,`Đang cập nhật Git…`,`Updating Git…`):n.value.action===`source.stage`?`Stage file`:`Unstage file`})]}),r.state===`ready`&&r.value?.state===`ready`&&r.value.target&&(0,q.jsxs)(`div`,{className:`source-revert-preview`,children:[(0,q.jsx)(`span`,{children:P(T,`Hoàn tác phần chưa stage; giữ nguyên index`,`Revert unstaged changes while preserving the index`)}),(0,q.jsx)(`button`,{type:`button`,disabled:!u||d,onClick:()=>x(null),children:d?P(T,`Đang dựng preview…`,`Building preview…`):`Revert file`})]}),(0,q.jsx)(Ye,{path:E.file.path}),f&&(0,q.jsx)(`div`,{className:`source-open-action`,children:(0,q.jsx)(`button`,{type:`button`,disabled:p,onClick:C,children:p?P(T,`Đang mở…`,`Opening…`):P(T,`Mở trong VS Code`,`Open in VS Code`)})}),(0,q.jsxs)(ae,{className:`mode-switch`,exclusive:!0,size:`small`,value:_,"aria-label":P(T,`Kiểu hiển thị diff`,`Diff layout`),onChange:(e,t)=>t&&v(t),children:[(0,q.jsx)(S,{value:`inline`,"aria-label":`Inline`,children:`Inline`}),(0,q.jsx)(S,{value:`split`,"aria-label":P(T,`Hai cột`,`Side by side`),children:P(T,`Hai cột`,`Side by side`)})]})]})]}),o&&(0,q.jsx)(`div`,{className:`review-error`,role:`status`,children:o}),l&&(0,q.jsx)(`div`,{className:`review-error`,role:`status`,children:l}),m&&(0,q.jsx)(`div`,{className:`source-open-status`,role:`status`,children:m}),g&&(0,q.jsxs)(`div`,{className:`detail-reconciliation-warning`,role:`status`,children:[(0,q.jsx)(`span`,{children:P(T,`Một thao tác source chưa đồng bộ; diff hiện tại vẫn chính xác.`,`A source action is not reconciled yet; the current diff remains exact.`)}),w&&(0,q.jsx)(`button`,{type:`button`,onClick:w,children:P(T,`Thử đồng bộ lại`,`Retry reconciliation`)})]}),(0,q.jsxs)(`div`,{className:`diff-context`,children:[(0,q.jsx)(`span`,{children:Rt(E.file,T)}),(0,q.jsx)(`span`,{children:K(E.file,T)}),(0,q.jsxs)(`span`,{className:`additions`,children:[`+`,E.file.stats.additions??`?`]}),(0,q.jsxs)(`span`,{className:`deletions`,children:[`−`,E.file.stats.deletions??`?`]})]}),E.fallback.kind!==`none`&&(0,q.jsxs)(`div`,{className:`diff-fallback`,children:[(0,q.jsx)(`strong`,{children:L(E.fallback.kind,T)}),(0,q.jsx)(`span`,{children:E.fallback.message??E.fallback.reasonCode??P(T,`Nội dung diff không sẵn sàng`,`Diff content unavailable`)})]}),E.hunks.map((e,t)=>(0,q.jsxs)(`section`,{className:`diff-hunk`,"aria-label":`${P(T,`Vùng thay đổi`,`Change region`)} ${t+1}`,children:[(0,q.jsxs)(`div`,{className:`hunk-header`,children:[(0,q.jsx)(`span`,{children:e.header}),(0,q.jsxs)(`span`,{className:`hunk-actions`,children:[n.value?.state===`ready`&&n.value.target?.hunkRefs.includes(e.hunkRef)&&(0,q.jsx)(`button`,{type:`button`,disabled:!s||c,onClick:()=>b([e.hunkRef]),children:n.value.action===`source.stage`?`Stage hunk`:`Unstage hunk`}),r.value?.state===`ready`&&r.value.target&&r.value.preview?.hunks.some(t=>t.hunkRef===e.hunkRef)&&(0,q.jsx)(`button`,{className:`revert-action`,type:`button`,disabled:!u||d,onClick:()=>x(e.hunkRef),children:`Revert hunk`})]})]}),(0,q.jsx)(`div`,{className:_===`split`?`split-code`:`inline-code`,children:e.lines.map(e=>(0,q.jsx)(an,{line:e,side:_,path:E.file.path},e.lineRef))}),E.unchangedRegions[t]&&(0,q.jsxs)(`div`,{className:`unchanged-region`,children:[`… `,E.unchangedRegions[t].lineCount,` `,P(T,`dòng không đổi đã thu gọn`,`unchanged lines collapsed`),` …`]})]},e.hunkRef)),(0,q.jsx)(dt,{path:E.file.path,shownLines:new Set(E.hunks.flatMap(e=>e.lines.map(e=>e.newLineNumber).filter(e=>typeof e==`number`)))}),E.truncation.truncated&&(0,q.jsxs)(`div`,{className:`diff-fallback`,children:[(0,q.jsx)(`strong`,{children:P(T,`Diff đã rút gọn`,`Diff truncated`)}),(0,q.jsxs)(`span`,{children:[P(T,`Còn`,`Another`),` `,E.truncation.omittedLines,` `,P(T,`dòng chưa hiển thị.`,`lines are not shown.`)]})]})]})}function sn({snapshot:e,refreshSnapshot:t,sessionRef:n,findings:r,onSendComments:i}){let{locale:a}=N(),[o,s]=(0,W.useState)(()=>n?ct(n):[]),[l,u]=(0,W.useState)(null);(0,W.useEffect)(()=>{s(n?ct(n):[]),u(null)},[n]),(0,W.useEffect)(()=>{let e=e=>{n&&e.detail===n&&s(ct(n))};return window.addEventListener(ft,e),()=>window.removeEventListener(ft,e)},[n]);let p=(0,W.useCallback)(e=>{s(e),n&&lt(n,e)},[n]),m=!!(e.task&&e.sourceChanges.task?.state!==`unavailable`&&e.sourceChanges.task?.revision),g=(0,W.useMemo)(()=>It(a),[a]),[v,y]=(0,W.useState)(()=>m?`task`:`working-tree`),[b,x]=(0,W.useState)({}),[S,C]=(0,W.useState)(null),[w,T]=(0,W.useState)({state:`idle`}),[E,D]=(0,W.useState)({state:`idle`}),[O,ee]=(0,W.useState)({state:`idle`}),[k,te]=(0,W.useState)({state:`idle`}),[A,re]=(0,W.useState)(null),[j,ie]=(0,W.useState)(!1),[ae,oe]=(0,W.useState)(null),[se,le]=(0,W.useState)(!1),[ue,F]=(0,W.useState)(null),[de,_e]=(0,W.useState)(!1),[Se,Ce]=(0,W.useState)(null),[Ee,De]=(0,W.useState)(!1),[Ae,je]=(0,W.useState)(null),[Ne,Fe]=(0,W.useState)(null),[Le,Re]=(0,W.useState)({state:`idle`}),[Be,Ve]=(0,W.useState)(!1),[He,I]=(0,W.useState)(null),[Ue,We]=(0,W.useState)(!1),[Ge,Ke]=(0,W.useState)(0),[L,qe]=(0,W.useState)(`inline`),Je={sourceProjectionRevision:e.sourceChanges.projectionRevision??null,taskViewRevision:e.sourceChanges.task.revision,workspaceRevision:e.sourceChanges.workingTree.revision,indexRevision:e.sourceChanges.staged.revision},Ye=Vt(Je,e.identity),Xe=[Ye,Ge].join(``),Ze=[Ye,e.revision.taskRevision??`no-task-revision`].join(``),R=[n??`default-session`,v,e.identity.projectRef,e.identity.runtimeInstanceId,e.identity.sessionRef,e.identity.taskId??`no-task`,e.identity.taskRunId??`no-run`].join(``),$e=(0,W.useRef)(R);$e.current=R;let et=(0,W.useRef)(0),tt=(0,W.useRef)(R);tt.current!==R&&(tt.current=R,et.current+=1);let nt=et.current,rt=(0,W.useRef)(null),it=b[v],z=it?.state===`ready`?Wt(it.value,it.revisionKey,Xe,Je,e.identity,v):null,at=it?.state===`ready`&&!z?{state:`loading`}:it,ot=z?.files??[],B=Kt(ot,S),V=B?ot.find(e=>e.fileRef===B)??null:null,H=!!(z&&V),U=e.capabilities.capabilities.reviewActions,dt=JSON.stringify(U),mt=v===`working-tree`?`source.stage`:v===`staged`?`source.unstage`:null,vt=U.status===`available`&&U.actions.reviewMark.available,yt=mt===`source.stage`?U.status===`available`&&U.actions.stage.available:mt===`source.unstage`&&U.status===`available`&&U.actions.unstage.available,xt=v===`working-tree`&&U.status===`available`&&U.actions.revert.available,G=H?[n??`default-session`,v,B,z.viewRevision,V.fileRevision,Ze,Ge,dt].join(``):`no-detail-request`,Ct=!!(H&&w.requestKey===G&&w.state===`ready`&&Gt(w.value,v,B,z.viewRevision,V.fileRevision,e)),wt=!!(H&&E.requestKey===G&&E.state===`ready`&&$t(E.value,v,B,z.viewRevision,V.fileRevision,e,Ct?w.value:void 0)),Et=!!(H&&O.requestKey===G&&O.state===`ready`&&$t(O.value,v,B,z.viewRevision,V.fileRevision,e,Ct?w.value:void 0)),Dt=!!(H&&k.requestKey===G&&k.state===`ready`&&$t(k.value,v,B,z.viewRevision,V.fileRevision,e,Ct?w.value:void 0)),Ot=!!(H&&w.requestKey===G&&w.state===`ready`&&!Ct),kt=!!(H&&E.requestKey===G&&E.state===`ready`&&!wt),At=!!(H&&O.requestKey===G&&O.state===`ready`&&!Et),jt=!!(H&&k.requestKey===G&&k.state===`ready`&&!Dt),Mt=!!(H&&w.requestKey===G&&w.state===`error`),Nt=!!(H&&vt&&E.requestKey===G&&E.state===`error`),Pt=!!(H&&yt&&O.requestKey===G&&O.state===`error`),Ft=!!(H&&xt&&k.requestKey===G&&k.state===`error`),Lt=Ot||kt||At||jt||Mt||Nt||Pt||Ft,Rt=!!(H&&Ct&&(!vt||wt)&&(!yt||Et)&&(!xt||Dt)),zt=(0,W.useRef)(null);B&&(zt.current={sourceScope:R,fileRef:B});let K=[R,B??(zt.current?.sourceScope===R?zt.current.fileRef:`no-file`)].join(``),Ut=(0,W.useRef)(K);Ut.current=K;let Yt=(0,W.useRef)(new Set),Zt=(0,W.useRef)(0),rn=(0,W.useRef)(K);rn.current!==K&&(rn.current=K,Zt.current+=1);let an=Zt.current,[sn,cn]=(0,W.useState)(null),J=!!(Lt&&t&&(!Yt.current.has(K)||sn?.scope===K&&sn.generation===an&&sn.requestKey===G)),Y=H?w.requestKey===G?(Ot||Mt)&&J?{state:`loading`}:Ot||Mt?{state:`error`}:w:{state:`loading`}:{state:`idle`},ln=Y.state===`ready`?Y.value:void 0,un=new Map;for(let e of ln?.hunks.flatMap(e=>e.lines)??[]){let t=e.kind===`deleted`?`old`:`new`,n=t===`old`?e.oldLineNumber:e.newLineNumber;typeof n==`number`&&ln&&un.set(ht(ln.file.path,t,n),e.text)}let dn=n&&i?{locale:a,findings:r,comments:o,editing:l?.key??null,open:(e,t,n,r)=>u({key:ht(e,t,n),path:e,side:t,line:n,code:r}),save:e=>{l&&p(_t(o,{path:l.path,side:l.side,line:l.line,code:l.code,text:e})),u(null)},cancel:()=>u(null),remove:e=>p(o.filter(t=>ht(t.path,t.side,t.line)!==e))}:null,fn=H&&vt?E.requestKey===G?J?{state:`loading`}:kt||Nt?{state:`error`}:E:{state:`loading`}:{state:`idle`},X=H&&yt?O.requestKey===G?J?{state:`loading`}:At||Pt?{state:`error`}:O:{state:`loading`}:{state:`idle`},pn=H&&xt?k.requestKey===G?J?{state:`loading`}:jt||Ft?{state:`error`}:k:{state:`loading`}:{state:`idle`},mn=H?[n??`default-session`,v,B,z.viewRevision,V.fileRevision,Ze].join(``):`no-source-authority`,Z=(0,W.useRef)(mn);Z.current=mn;let hn=[mn,e.revision.runtimeRevision,e.revision.controlRevision??`no-control-revision`,e.revision.approvalRevision??`no-approval-revision`,e.revision.sessionOptionRevision??`no-session-option-revision`,e.revision.queueRevision??`no-queue-revision`].join(``),Q=(0,W.useRef)(hn);Q.current=hn;let gn=[n??`default-session`,e.identity.projectRef,e.identity.runtimeInstanceId,e.identity.sessionRef,e.identity.taskId??`no-task`,e.identity.taskRunId??`no-run`,e.revision.taskRevision??`no-task-revision`,e.sourceChanges.staged.revision??`no-index-revision`].join(``),$=(0,W.useRef)(gn);$.current=gn;let _n=(0,W.useRef)(``),vn=(0,W.useRef)(``);_n.current=[mn,qt(fn.value)].join(``),vn.current=Jt(fn.value),(0,W.useEffect)(()=>{Re({state:`idle`}),I(null),We(!1)},[gn]),(0,W.useEffect)(()=>{!m&&v===`task`&&(y(`working-tree`),C(null))},[m,v]),(0,W.useEffect)(()=>{rt.current=null,Fe(null)},[R,nt]),(0,W.useEffect)(()=>{Rt&&(Yt.current.delete(K),cn(e=>e?.scope===K?null:e))},[Rt,K]),(0,W.useEffect)(()=>{let r=new AbortController,i=Xe;return x(e=>({...e,[v]:{state:`loading`,revisionKey:i}})),(n?ve(n,v,r.signal):me(v,r.signal)).then(n=>{if(!n){r.signal.aborted||x(e=>({...e,[v]:{state:`error`,revisionKey:i}}));return}if(!Ht(n,v,Je,e.identity)){if(r.signal.aborted)return;if(!t||rt.current===R){x(e=>({...e,[v]:{state:`error`,revisionKey:i}}));return}rt.current=R,x(e=>({...e,[v]:{state:`loading`,revisionKey:i}})),t().then(e=>{if(!r.signal.aborted){if(!e){x(e=>({...e,[v]:{state:`error`,revisionKey:i}}));return}Ke(e=>e+1)}}).catch(()=>{r.signal.aborted||x(e=>({...e,[v]:{state:`error`,revisionKey:i}}))});return}rt.current=null,r.signal.aborted||x(e=>({...e,[v]:{state:`ready`,value:n,revisionKey:i}}))}).catch(()=>{r.signal.aborted||x(e=>({...e,[v]:{state:`error`,revisionKey:i}}))}),()=>r.abort()},[v,Xe,n]);let yn=(0,W.useCallback)(()=>{let e=R,n=nt,r=Ye;rt.current=null,x(e=>({...e,[v]:{state:`loading`,revisionKey:Xe}})),(async()=>{let i;try{i=await t?.()}catch{}if($e.current!==e||et.current!==n)return;rt.current=e;let a=i?Vt({sourceProjectionRevision:i.sourceChanges.projectionRevision??null,taskViewRevision:i.sourceChanges.task.revision,workspaceRevision:i.sourceChanges.workingTree.revision,indexRevision:i.sourceChanges.staged.revision},i.identity):r;(!i||a===r)&&Ke(e=>e+1)})()},[t,Ye,nt,R,Xe,v]);(0,W.useEffect)(()=>{if(!B){T({state:`idle`}),D({state:`idle`}),ee({state:`idle`}),te({state:`idle`}),oe(null),F(null),Ce(null),re(null),je(null);return}let e=new AbortController,t=G;return T({state:`loading`,requestKey:t}),oe(null),F(null),Ce(null),re(null),je(null),D(vt?{state:`loading`,requestKey:t}:{state:`idle`}),ee(yt?{state:`loading`,requestKey:t}:{state:`idle`}),te(xt?{state:`loading`,requestKey:t}:{state:`idle`}),(n?he(n,v,B,e.signal):ke(v,B,e.signal)).then(n=>{e.signal.aborted||T({state:`ready`,value:n,requestKey:t})}).catch(()=>{e.signal.aborted||T({state:`error`,requestKey:t})}),vt&&(n?pe(n,v,B,e.signal):Me(v,B,e.signal)).then(n=>{e.signal.aborted||D({state:`ready`,value:n,requestKey:t})}).catch(()=>{e.signal.aborted||D({state:`error`,requestKey:t})}),yt&&mt&&(n?ye(n,mt,B,e.signal):xe(mt,B,e.signal)).then(n=>{e.signal.aborted||ee({state:`ready`,value:n,requestKey:t})}).catch(()=>{e.signal.aborted||ee({state:`error`,requestKey:t})}),xt&&(n?fe(n,B,null,e.signal):be(B,null,e.signal)).then(n=>{e.signal.aborted||te({state:`ready`,value:n,requestKey:t})}).catch(()=>{e.signal.aborted||te({state:`error`,requestKey:t})}),()=>e.abort()},[B,v,Ze,Ge,n,dt,G]);let bn=(0,W.useCallback)(e=>{if(!H||!t)return;let n=K,r=an,i=G;!e&&Yt.current.has(n)||(Yt.current.add(n),cn({scope:n,generation:r,requestKey:i}),t().then(e=>{e&&Ut.current===n&&Zt.current===r&&Ke(e=>e+1)}).catch(()=>void 0).finally(()=>{cn(e=>e?.scope===n&&e.generation===r&&e.requestKey===i?null:e)}))},[H,an,K,G,t]);(0,W.useEffect)(()=>{!H||!Lt||!t||Yt.current.has(K)||bn(!1)},[bn,H,Lt,K,t]);let xn=ot,Sn=(0,W.useMemo)(()=>{let e=new Map;for(let t of xn){let n=t.path.lastIndexOf(`/`),r=n<0?P(a,`Gốc project`,`Project root`):t.path.slice(0,n);e.set(r,[...e.get(r)??[],t])}return[...e.entries()]},[xn,a]),Cn=(0,W.useMemo)(()=>{let t={task:e.sourceChanges.task.counts.files,"working-tree":e.sourceChanges.workingTree.counts.files,staged:e.sourceChanges.staged.counts.files},n=n=>{let r=b[n];return(r?.state===`ready`?Wt(r.value,r.revisionKey,Xe,Je,e.identity,n):null)?.page.total??t[n]};return{task:n(`task`),"working-tree":n(`working-tree`),staged:n(`staged`)}},[b,Xe,e.sourceChanges.task.counts.files,e.sourceChanges.workingTree.counts.files,e.sourceChanges.staged.counts.files]),wn=e=>{Fe(null),y(e),C(null)},Tn=U.status===`available`&&U.actions.reviewMark.available,En=X.value?.action===`source.stage`?U.status===`available`&&U.actions.stage.available:X.value?.action===`source.unstage`&&U.status===`available`&&U.actions.unstage.available,Dn=U.status===`available`&&U.actions.revert.available,On=v===`working-tree`&&U.status===`available`&&U.actions.openInVsCode.available&&Y.state===`ready`&&Y.value?.availability.state===`current`&&Y.value.fallback.kind===`none`,kn=v===`staged`&&xn.length>0,An=kn&&U.status===`available`&&U.actions.generateCommitSummaryDeterministic.available,jn=kn&&U.status===`available`&&U.actions.generateCommitSummaryModel.available,Mn=t=>!t||t.identity.projectRef!==e.identity.projectRef||t.identity.runtimeInstanceId!==e.identity.runtimeInstanceId||t.identity.sessionRef!==e.identity.sessionRef||t.identity.taskId!==e.identity.taskId||t.identity.taskRunId!==e.identity.taskRunId?!1:t.summary?t.summary.taskRevision===e.revision.taskRevision&&t.summary.indexRevision===e.sourceChanges.staged.revision:t.state===`unavailable`,Nn=async t=>{if(!B||!fn.value||j)return;let r=fn.value,i=Jt(r),o=_n.current,s=Q.current,c=R,l=nt,u=K,d=an,f=Ye,p=!1;ie(!0),oe(null),Fe(null);try{let m=await bt(e,r,t);if(_n.current!==o||vn.current!==i||Q.current!==s)return;let h=await en(m.idempotencyKey);if(_n.current!==o||vn.current!==i||Q.current!==s)return;p=!0;let g=await we(m);if(!Xt(m,g,t,h)){if(g.phase!==`rejected`){await Pn(c,l,u,d,f,P(a,`Chưa xác nhận được receipt review. Piagent đã đọc lại trạng thái chính thức và sẽ không tự gửi lại lệnh.`,`The review receipt is unconfirmed. Piagent reloaded canonical state and will not resend the command.`));return}_n.current===o&&vn.current===i&&oe(g.error?.message??P(a,`Không xác nhận được trạng thái review chính xác; hãy tải lại diff.`,`The exact review state could not be confirmed; reload the diff.`));return}if(_n.current!==o||vn.current!==i)return;D(e=>_n.current===o&&Jt(e.value)===i?{state:`ready`,requestKey:e.requestKey,value:{...r,generatedAt:g.settledAt,state:g.resultCode,recordedState:g.resultCode,recordedAt:g.settledAt,evidenceRef:g.settlementEvidenceRef,reasonCode:null,health:{state:`ok`,reasonCode:null,message:null}}}:e),(n?pe(n,v,B):Me(v,B)).then(e=>D(t=>_n.current===o&&t.state===`ready`&&t.value?.evidenceRef===g.settlementEvidenceRef?{state:`ready`,value:e,requestKey:t.requestKey}:t)).catch(()=>void 0)}catch{p?await Pn(c,l,u,d,f,P(a,`Mất kết nối khi đang ghi review. Piagent đã đọc lại trạng thái chính thức và sẽ không tự gửi lại lệnh.`,`The connection was lost while saving review. Piagent reloaded canonical state and will not resend the command.`)):_n.current===o&&vn.current===i&&oe(P(a,`Không thể ghi trạng thái review. Nội dung source không bị thay đổi.`,`Unable to save review state. Source content was not changed.`))}finally{ie(!1)}},Pn=async(e,n,r,i,a,o)=>{Ut.current===r&&Zt.current===i&&(T({state:`idle`}),D({state:`idle`}),ee({state:`idle`}),te({state:`idle`}),re(null),oe(null),F(null),Ce(null),je(null),Fe(null));let s;try{s=await t?.()}catch{}if($e.current!==e||et.current!==n)return;let c=s?Vt({sourceProjectionRevision:s.sourceChanges.projectionRevision??null,taskViewRevision:s.sourceChanges.task.revision,workspaceRevision:s.sourceChanges.workingTree.revision,indexRevision:s.sourceChanges.staged.revision},s.identity):a;(!s||c===a)&&Ke(e=>e+1),Fe({scope:e,generation:n,message:o})},Fn=async(n=[])=>{if(!B||!z||!X.value||X.value.state!==`ready`||se)return;let r=Z.current,i=Q.current,o=X.value,s=R,c=nt,l=K,u=an,d=Ye,f=!1;le(!0),F(null),Fe(null);try{let p=await St(e,o,n);if(Z.current!==r||Q.current!==i)return;f=!0;let m=await ze(p);if(m.phase===`uncertain`){await Pn(s,c,l,u,d,P(a,`Chưa xác nhận được trạng thái Git. Piagent đã tải lại Source Changes và sẽ không tự gửi lại lệnh.`,`Git state is unconfirmed. Piagent refreshed Source Changes and will not resend the command.`));return}if(m.phase!==`settled`||![`staged`,`unstaged`].includes(m.resultCode)){Z.current===r&&F(m.error?.message??P(a,`File hoặc Git index đã thay đổi; hãy tải lại preview.`,`The file or Git index changed; reload the preview.`));return}Z.current===r&&C(null),await t?.(),Ke(e=>e+1)}catch{f?await Pn(s,c,l,u,d,P(a,`Mất kết nối khi đang cập nhật Git. Piagent đã tải lại Source Changes và sẽ không tự gửi lại lệnh.`,`The connection was lost while updating Git. Piagent refreshed Source Changes and will not resend the command.`)):Z.current===r&&F(P(a,`Không thể chuẩn bị lệnh cập nhật Git; source chưa bị thay đổi.`,`Unable to prepare the Git update; source was not changed.`))}finally{le(!1)}},In=async e=>{if(!B||!z||!Dn||de)return;let t=Z.current,r=B;_e(!0),Ce(null),Fe(null);try{let i=n?await fe(n,r,e):await be(r,e);if(Z.current!==t)return;if(i.state!==`ready`||!i.target){Ce(P(a,`Không thể hoàn tác an toàn: provenance hoặc diff hiện tại không còn đủ bằng chứng.`,`Safe revert is unavailable because provenance or the current diff lacks evidence.`));return}re(i)}catch{Z.current===t&&Ce(P(a,`Không thể dựng preview hoàn tác. Source chưa bị thay đổi.`,`Unable to build a revert preview. Source was not changed.`))}finally{_e(!1)}},Ln=async()=>{if(!A?.target||!B||!z||!V||de||!Qt(A.target,v,B,z.viewRevision,V.fileRevision,e))return;let r=Z.current,i=Q.current,o=A,s=R,c=nt,l=K,u=an,d=Ye,f=!1;_e(!0),Ce(null),Fe(null);try{let p=await pt(e,o);if(Z.current!==r||Q.current!==i)return;f=!0;let m=await Pe(p,void 0,n);if(m.phase===`uncertain`){await Pn(s,c,l,u,d,P(a,`Chưa xác nhận được kết quả revert. Piagent đã tải lại Source Changes và sẽ không tự gửi lại lệnh.`,`The revert result is unconfirmed. Piagent refreshed Source Changes and will not resend the command.`));return}if(m.phase!==`settled`||m.resultCode!==`reverted`){Z.current===r&&Ce(m.error?.message??P(a,`Preview đã cũ; hãy mở lại trước khi xác nhận.`,`The preview is stale; reopen it before confirming.`));return}Z.current===r&&(re(null),C(null)),await t?.(),Ke(e=>e+1)}catch{f?await Pn(s,c,l,u,d,P(a,`Mất kết nối khi đang revert. Piagent đã tải lại Source Changes và sẽ không tự gửi lại lệnh.`,`The connection was lost during revert. Piagent refreshed Source Changes and will not resend the command.`)):Z.current===r&&Ce(P(a,`Không thể chuẩn bị lệnh revert; source chưa bị thay đổi.`,`Unable to prepare the revert command; source was not changed.`))}finally{_e(!1)}},Rn=async()=>{if(!B||!On||Ee)return;let t=Z.current,n=Q.current,r=B;De(!0),je(null);try{let i=await Tt(e,r);if(Z.current!==t||Q.current!==n)return;let o=await Te(i);if(Z.current!==t)return;o.phase===`settled`&&o.resultCode===`opened`?je(P(a,`VS Code đã nhận yêu cầu mở file.`,`VS Code received the open-file request.`)):je(o.phase===`uncertain`?P(a,`Không xác nhận được VS Code đã nhận file. Piagent sẽ không tự mở lại.`,`It is unknown whether VS Code received the file. Piagent will not retry automatically.`):o.error?.message??P(a,`File hoặc phiên làm việc đã thay đổi; hãy tải lại trước khi mở.`,`The file or session changed; refresh before opening.`))}catch{Z.current===t&&je(P(a,`Không thể mở file trong VS Code. Diff hiện tại vẫn được giữ nguyên.`,`Unable to open the file in VS Code. The current diff remains available.`))}finally{De(!1)}},zn=async()=>{if(!An||Be)return;let e=$.current;Ve(!0),I(null),Re({state:`loading`});try{let t=n?await ge(n):await Oe();if($.current!==e)return;if(!Mn(t)){Re({state:`error`}),I(P(a,`Staged Changes đã đổi trong lúc dựng summary; hãy tạo lại.`,`Staged Changes changed while the summary was generated; generate it again.`));return}Re({state:`ready`,value:t}),t.state!==`ready`&&I(P(a,`Staged Changes đã thay đổi hoặc chưa có dữ liệu để tóm tắt.`,`Staged Changes changed or has no data to summarize.`))}catch{$.current===e&&(Re({state:`error`}),I(P(a,`Không thể dựng commit summary từ index hiện tại.`,`Unable to generate a commit summary from the current index.`)))}finally{Ve(!1)}},Bn=async()=>{let e=Le.value?.summary;if(!e||!Mn(Le.value))return;let t=$.current;try{await navigator.clipboard.writeText([e.title,``,...e.bodyLines].join(`
3
3
  `)),$.current===t&&I(P(a,`Đã copy summary. Chưa có commit nào được tạo.`,`Summary copied. No commit was created.`))}catch{$.current===t&&I(P(a,`Trình duyệt không cho phép copy tự động.`,`The browser did not allow automatic copying.`))}},Vn=async()=>{let t=Le.value?.summary;if(!t||!Mn(Le.value)||!jn||Be)return;let n=$.current;Ve(!0),I(null);try{let r=await Qe(e,t.modelPrompt,`new-operation`);if($.current!==n||!Mn(Le.value))return;let i=await Ie(r);if($.current!==n)return;i.phase===`settled`&&i.resultCode===`dispatch-observed`?I(P(a,`Đã gửi yêu cầu sang Chat. Pi sẽ trả commit summary ở hội thoại; chưa commit hoặc push.`,`Request sent to Chat. Pi will return the commit summary in the conversation; nothing was committed or pushed.`)):I(i.phase===`uncertain`?P(a,`Không xác nhận được yêu cầu đã tới Pi; hệ thống sẽ không tự gửi lại.`,`It is unknown whether the request reached Pi; it will not be resent automatically.`):i.error?.message??P(a,`Không thể bắt đầu model work từ session hiện tại.`,`Unable to start model work from the current session.`))}catch{$.current===n&&I(P(a,`Không thể gửi yêu cầu sang Pi session hiện tại.`,`Unable to send the request to the current Pi session.`))}finally{Ve(!1),We(!1)}},Hn=Ne?.scope===R&&Ne.generation===nt?Ne.message:null;return(0,q.jsxs)(_,{component:`section`,variant:`outlined`,className:`source-workspace`,"aria-labelledby":`source-title`,sx:{overflow:`hidden`,minHeight:`calc(100vh - 120px)`,display:`flex`,flexDirection:`column`},children:[(0,q.jsxs)(h,{component:`header`,className:`source-heading`,sx:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,px:{xs:2,sm:2.5},py:1.75,borderBottom:1,borderColor:`divider`},children:[(0,q.jsxs)(h,{children:[(0,q.jsx)(c,{variant:`overline`,color:`primary.main`,sx:{fontWeight:650,letterSpacing:`.14em`,lineHeight:1},children:`Source changes`}),(0,q.jsx)(c,{variant:`h2`,id:`source-title`,sx:{mt:.5},children:P(a,`Thay đổi trong project`,`Project changes`)})]}),(0,q.jsx)(M,{label:`Git + task baseline`,variant:`outlined`,size:`small`})]}),(0,q.jsx)(d,{className:`source-tabs`,value:v,onChange:(e,t)=>wn(t),selectionFollowsFocus:!0,variant:`scrollable`,scrollButtons:`auto`,"aria-label":P(a,`Nguồn thay đổi`,`Change sources`),sx:{borderBottom:1,borderColor:`divider`,minHeight:48},children:g.map(e=>(0,q.jsx)(ce,{id:`source-tab-${e.view}`,value:e.view,"aria-controls":`source-tabpanel`,disabled:e.view===`task`&&!m,title:e.view===`task`&&!m?P(a,`Session này chưa có task baseline`,`This session has no task baseline`):void 0,label:(0,q.jsxs)(f,{direction:`row`,spacing:1,sx:{alignItems:`center`},children:[(0,q.jsx)(`span`,{children:e.label}),Cn[e.view]>0&&(0,q.jsx)(M,{size:`small`,label:Cn[e.view],sx:{height:20,minWidth:24,"& .MuiChip-label":{px:.75}}})]})},e.view))}),v===`staged`&&(0,q.jsx)(tn,{state:Le,busy:Be,status:He,locale:a,deterministicEnabled:An,modelEnabled:jn,onGenerate:()=>{zn()},onCopy:()=>{Bn()},onModel:()=>We(!0)}),dn&&(0,q.jsx)(gt,{comments:o,lines:un,linesPath:ln?.file.path,locale:a,onSend:()=>{i?.(ut(o,a===`en`)),p([])},onClear:()=>p([])}),(0,q.jsxs)(h,{className:`source-body`,sx:{display:`grid`,gridTemplateColumns:{xs:`1fr`,md:`minmax(286px, 330px) minmax(0, 1fr)`},flex:1,minHeight:620},children:[(0,q.jsxs)(h,{className:`file-panel`,id:`source-tabpanel`,role:`tabpanel`,"aria-labelledby":`source-tab-${v}`,sx:{minWidth:0,borderRight:{md:1},borderBottom:{xs:1,md:0},borderColor:`divider`,bgcolor:`background.default`},children:[(0,q.jsxs)(h,{className:`file-panel-meta`,sx:{minHeight:44,display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:1,px:1.5,borderBottom:1,borderColor:`divider`},children:[(0,q.jsx)(`span`,{"aria-live":`polite`,children:at?.state===`ready`&&at.value?Bt(at.value,a):at?.state===`error`?P(a,`Không thể tải danh sách file`,`Unable to load files`):P(a,`Đang tải…`,`Loading…`)}),(0,q.jsxs)(f,{direction:`row`,spacing:1,sx:{alignItems:`center`},children:[at?.state===`error`&&(0,q.jsx)(`button`,{className:`source-list-retry`,type:`button`,onClick:yn,children:P(a,`Thử tải lại`,`Retry`)}),(0,q.jsx)(`small`,{children:g.find(e=>e.view===v)?.shortLabel})]})]}),(0,q.jsxs)(h,{className:`file-list`,sx:{maxHeight:{xs:300,md:`calc(100vh - 270px)`},overflow:`auto`,p:.75},children:[Sn.map(([e,t])=>(0,q.jsxs)(h,{children:[(0,q.jsxs)(f,{direction:`row`,className:`file-group-label`,children:[(0,q.jsx)(ne,{}),(0,q.jsx)(c,{component:`span`,noWrap:!0,children:e})]}),t.map(e=>(0,q.jsx)(nn,{file:e,selected:e.fileRef===B,onSelect:()=>{Fe(null),C(e.fileRef)},locale:a},e.fileRef))]},e)),at?.state===`ready`&&xn.length===0&&(0,q.jsx)(`div`,{className:`files-empty`,children:P(a,`Không có thay đổi trong view này.`,`No changes in this view.`)})]})]}),(0,q.jsx)(st.Provider,{value:dn,children:(0,q.jsx)(on,{state:Y,review:fn,mutation:X,revert:pn,reviewEnabled:Tn,reviewBusy:j,reviewError:ae,mutationEnabled:En,mutationBusy:se,mutationError:ue,revertEnabled:Dn,revertBusy:de,openEnabled:On,openBusy:Ee,openStatus:Ae,detailError:Lt&&!J,mode:L,onMode:qe,onReview:e=>{Nn(e)},onMutation:e=>{Fn(e)},onRevert:e=>{In(e)},onOpen:()=>{Rn()},onRetry:H&&t?()=>bn(!0):void 0,locale:a})})]}),Hn&&(0,q.jsx)(`div`,{className:`source-action-warning`,role:`status`,children:Hn}),Se&&(0,q.jsx)(`div`,{className:`source-revert-error`,role:`status`,children:Se}),A?.target&&B&&z&&V&&Qt(A.target,v,B,z.viewRevision,V.fileRevision,e)&&(0,q.jsx)(`div`,{className:`dialog-backdrop`,role:`presentation`,children:(0,q.jsxs)(`section`,{className:`confirm-dialog`,role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":`revert-dialog-title`,"aria-describedby":`revert-dialog-description`,children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:P(a,`Xác nhận hoàn tác`,`Confirm revert`)}),(0,q.jsxs)(`h3`,{id:`revert-dialog-title`,children:[`Revert `,A.target.hunkRefs.length?`hunk`:`file`,`?`]}),(0,q.jsxs)(`p`,{id:`revert-dialog-description`,children:[P(a,`Thao tác sẽ bỏ`,`This will discard`),` `,(0,q.jsxs)(`strong`,{children:[A.target.summary.additionsDiscarded,` `,P(a,`dòng thêm`,`added lines`)]}),` `,P(a,`và khôi phục`,`and restore`),` `,(0,q.jsxs)(`strong`,{children:[A.target.summary.deletionsRestored,` `,P(a,`dòng xóa`,`deleted lines`)]}),` `,P(a,`trong`,`in`),` `,(0,q.jsx)(`code`,{children:A.target.path}),`.`]}),(0,q.jsx)(`div`,{className:`revert-diff`,"aria-label":P(a,`Các dòng chính xác sẽ được hoàn tác`,`Exact lines to revert`),children:A.preview?.hunks.map(e=>(0,q.jsxs)(`section`,{children:[(0,q.jsx)(`div`,{children:e.header}),e.lines.map((t,n)=>(0,q.jsxs)(`code`,{className:`revert-line revert-${t.kind}`,children:[(0,q.jsx)(`b`,{children:t.marker}),t.text]},`${e.hunkRef}.${n}`))]},e.hunkRef))}),(0,q.jsxs)(`div`,{className:`revert-safety`,children:[(0,q.jsx)(`strong`,{children:P(a,`Phần đã stage được giữ nguyên.`,`Staged content is preserved.`)}),(0,q.jsx)(`span`,{children:P(a,`Không auto-commit. Khả năng khôi phục sau thao tác không được bảo đảm.`,`No auto-commit. Recovery after this action is not guaranteed.`)})]}),(0,q.jsxs)(`div`,{className:`confirm-actions`,children:[(0,q.jsx)(`button`,{type:`button`,disabled:de,onClick:()=>re(null),children:P(a,`Hủy`,`Cancel`)}),(0,q.jsx)(`button`,{className:`danger-action`,type:`button`,disabled:de,onClick:()=>{Ln()},children:de?P(a,`Đang hoàn tác…`,`Reverting…`):P(a,`Xác nhận revert`,`Confirm revert`)})]})]})}),Ue&&Mn(Le.value)&&(0,q.jsx)(`div`,{className:`dialog-backdrop`,role:`presentation`,children:(0,q.jsxs)(`section`,{className:`confirm-dialog model-summary-dialog`,role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":`model-summary-dialog-title`,"aria-describedby":`model-summary-dialog-description`,children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:P(a,`Model work có tính phí`,`Token-consuming model work`)}),(0,q.jsx)(`h3`,{id:`model-summary-dialog-title`,children:P(a,`Nhờ Pi viết lại commit summary?`,`Ask Pi to rewrite the commit summary?`)}),(0,q.jsx)(`p`,{id:`model-summary-dialog-description`,children:P(a,`Thao tác này gửi một message vào đúng Pi session hiện tại, bắt đầu một Pi operation và tiêu token theo model/thinking đang chọn. Chỉ staged summary đã rút gọn được gửi; source text không được đính kèm.`,`This sends a message to the exact current Pi session, starts a Pi operation, and consumes tokens using the selected model and thinking level. Only the bounded staged summary is sent; source text is not attached.`)}),(0,q.jsxs)(`div`,{className:`revert-safety`,children:[(0,q.jsx)(`strong`,{children:P(a,`Không tự commit hoặc push.`,`Does not commit or push.`)}),(0,q.jsx)(`span`,{children:P(a,`Kết quả sẽ xuất hiện trong Chat để review và copy.`,`The result will appear in Chat for review and copying.`)})]}),(0,q.jsxs)(`div`,{className:`confirm-actions`,children:[(0,q.jsx)(`button`,{type:`button`,disabled:Be,onClick:()=>We(!1),children:P(a,`Hủy`,`Cancel`)}),(0,q.jsx)(`button`,{type:`button`,disabled:Be,onClick:()=>{Vn()},children:Be?P(a,`Đang gửi…`,`Sending…`):P(a,`Xác nhận và gửi sang Pi`,`Confirm and send to Pi`)})]})]})})]})}var cn=/^[a-z0-9][a-z0-9-]{0,63}$/,J=e=>Array.isArray(e)?e.slice(0,200):[],Y=e=>typeof e==`string`||typeof e==`number`?String(e):``;function ln(e){try{let t=JSON.parse(e);return t&&typeof t==`object`&&t.kind===`fe-change-report`?t:null}catch{return null}}function un(e){return!!e&&[e.x,e.y,e.w,e.h].every(e=>Number.isFinite(e)&&e>=0)&&e.w>0&&e.h>0}var dn=new Map;function fn(e,t,n){let r=`${e??``}\u0000${t}\u0000${n}`;return dn.has(r)||(dn.set(r,Ve(e,`/api/v1/documents/${encodeURIComponent(t)}/assets/${encodeURIComponent(n)}`).then(async e=>{if(e.state!==`ready`||!e.base64)return{state:`missing`};let t=`data:image/png;base64,${e.base64}`,n=new Image;return n.src=t,await n.decode(),{state:`ready`,src:t,width:n.naturalWidth,height:n.naturalHeight}}).catch(()=>(dn.delete(r),{state:`missing`}))),dn.size>48&&dn.delete(dn.keys().next().value)),dn.get(r)}function X(e,t,n){let[r,i]=(0,W.useState)({state:`loading`});return(0,W.useEffect)(()=>{let r=!0;return i({state:`loading`}),fn(e,t,n).then(e=>{r&&i(e)}),()=>{r=!1}},[e,t,n]),r}var pn=(e,t)=>`${Math.max(0,Math.min(100,e/t*100))}%`;function mn(e,t){let n=Math.min(e.x,t.width-1),r=Math.min(e.y,t.height-1);return{...e,x:n,y:r,w:Math.min(e.w,t.width-n),h:Math.min(e.h,t.height-r)}}function Z({asset:e,label:t,frames:n,locale:r}){return(0,q.jsxs)(`figure`,{className:`change-report-figure`,children:[(0,q.jsx)(`figcaption`,{children:t}),e.state===`ready`?(0,q.jsxs)(`div`,{className:`change-report-shot`,children:[(0,q.jsx)(`img`,{src:e.src,alt:t}),n.map(({n:t,box:n})=>{let r=mn(n,e);return(0,q.jsx)(`span`,{className:`change-report-box`,style:{left:pn(r.x,e.width),top:pn(r.y,e.height),width:pn(r.w,e.width),height:pn(r.h,e.height)},children:(0,q.jsx)(`b`,{children:t})},t)})]}):(0,q.jsx)(`p`,{className:`change-report-missing`,children:e.state===`loading`?P(r,`Đang tải ảnh…`,`Loading the screenshot…`):P(r,`Không có ảnh`,`No screenshot`)})]})}function hn({asset:e,box:t,label:n}){if(e.state!==`ready`)return null;let r=mn(t,e),i=e.width===r.w?0:r.x/(e.width-r.w)*100,a=e.height===r.h?0:r.y/(e.height-r.h)*100;return(0,q.jsxs)(`div`,{className:`change-report-zoom`,children:[(0,q.jsx)(`span`,{children:n}),(0,q.jsx)(`div`,{role:`img`,"aria-label":n,className:`change-report-crop`,style:{maxWidth:Math.round(r.w*2.5),aspectRatio:`${r.w} / ${r.h}`,backgroundImage:`url("${e.src}")`,backgroundSize:`${e.width/r.w*100}% auto`,backgroundPosition:`${i}% ${a}%`}})]})}function Q({section:e,viewports:t,sessionRef:n,documentRef:r,locale:i}){let a=cn.test(Y(e.viewport))?Y(e.viewport):t[0],o=X(n,r,`before-${e.key}-${a}.png`),s=X(n,r,`after-${e.key}-${a}.png`),[c,l]=(0,W.useState)(!1),u=J(e.boxes).filter(un).map((e,t)=>({...e,n:Number.isInteger(e.n)?e.n:t+1})),d=e=>u.map(t=>({n:t.n,box:un(t[e])?t[e]:t})),[f,p]=[P(i,`Cũ`,`Before`),P(i,`Mới`,`After`)];return(0,q.jsxs)(`section`,{className:`change-report-card`,children:[(0,q.jsx)(`h4`,{children:Y(e.title)||e.key}),e.note&&(0,q.jsx)(`p`,{className:`change-report-note`,children:Y(e.note)}),(0,q.jsxs)(`div`,{className:`change-report-pair`,children:[(0,q.jsx)(Z,{asset:o,label:`${f} · ${a}`,frames:d(`before`),locale:i}),(0,q.jsx)(Z,{asset:s,label:`${p} · ${a}`,frames:d(`after`),locale:i})]}),u.length>0&&(0,q.jsx)(`h5`,{children:P(i,`Phóng to theo số`,`Zoom by number`)}),u.map(e=>(0,q.jsxs)(`div`,{className:`change-report-zoom-row`,children:[(0,q.jsxs)(`p`,{children:[(0,q.jsx)(`b`,{className:`change-report-number`,children:e.n}),` `,Y(e.text)]}),(0,q.jsxs)(`div`,{className:`change-report-pair`,children:[(0,q.jsx)(hn,{asset:o,box:un(e.before)?e.before:e,label:f}),(0,q.jsx)(hn,{asset:s,box:un(e.after)?e.after:e,label:p})]})]},e.n)),t.filter(e=>e!==a).map(t=>(0,q.jsx)($,{name:t,section:e,sessionRef:n,documentRef:r,locale:i},t)),(0,q.jsxs)(`details`,{onToggle:e=>l(e.currentTarget.open),children:[(0,q.jsx)(`summary`,{children:P(i,`Pixel khác nhau (tô đỏ trên ảnh mới)`,`Changed pixels (red on the new screenshot)`)}),c&&(0,q.jsx)(gn,{name:`diff-${e.key}-${a}.png`,sessionRef:n,documentRef:r,locale:i})]})]})}function gn({name:e,sessionRef:t,documentRef:n,locale:r}){return(0,q.jsx)(Z,{asset:X(t,n,e),label:P(r,`Khác biệt`,`Difference`),frames:[],locale:r})}function $({name:e,section:t,sessionRef:n,documentRef:r,locale:i}){let[a,o]=(0,W.useState)(!1);return(0,q.jsxs)(`details`,{onToggle:e=>o(e.currentTarget.open),children:[(0,q.jsxs)(`summary`,{children:[P(i,`Khổ khác`,`Other size`),`: `,e]}),a&&(0,q.jsx)(_n,{name:e,section:t,sessionRef:n,documentRef:r,locale:i})]})}function _n({name:e,section:t,sessionRef:n,documentRef:r,locale:i}){let a=X(n,r,`before-${t.key}-${e}.png`),o=X(n,r,`after-${t.key}-${e}.png`),s=J(t.otherBoxes?.[e]).filter(un).map((e,t)=>({n:Number.isInteger(e.n)?e.n:t+1,box:e}));return(0,q.jsxs)(`div`,{className:`change-report-pair narrow`,children:[(0,q.jsx)(Z,{asset:a,label:`${P(i,`Cũ`,`Before`)} · ${e}`,frames:s,locale:i}),(0,q.jsx)(Z,{asset:o,label:`${P(i,`Mới`,`After`)} · ${e}`,frames:s,locale:i})]})}function vn({rows:e,last:t,locale:n}){return(0,q.jsx)(`div`,{className:`change-report-scroll`,children:(0,q.jsxs)(`table`,{className:`change-report-table`,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{children:P(n,`Mục`,`Item`)}),(0,q.jsx)(`th`,{children:P(n,`Cũ`,`Before`)}),(0,q.jsx)(`th`,{children:P(n,`Mới`,`After`)}),(0,q.jsx)(`th`,{children:t===`impact`?P(n,`Ảnh hưởng`,`Impact`):P(n,`File`,`Files`)})]})}),(0,q.jsx)(`tbody`,{children:e.map((e,n)=>(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`td`,{children:(0,q.jsx)(`strong`,{children:Y(e.title)})}),(0,q.jsx)(`td`,{children:Y(e.before)}),(0,q.jsx)(`td`,{children:Y(e.after)}),(0,q.jsx)(`td`,{children:t===`impact`?Y(e.impact):J(e.files).map(e=>(0,q.jsx)(`code`,{children:Y(e)},e))})]},n))})]})})}function yn({value:e,locale:t}){let n=e===`passed`||e===`failed`?e:`skipped`;return(0,q.jsx)(`span`,{className:`change-report-result ${n}`,children:n===`passed`?P(t,`Đạt`,`Passed`):n===`failed`?P(t,`Lỗi`,`Failed`):P(t,`Bỏ qua`,`Skipped`)})}function bn(e){let{locale:r}=N(),[i,a]=(0,W.useState)(!1);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`change-report-actions`,children:(0,q.jsx)(t,{size:`small`,variant:`outlined`,startIcon:(0,q.jsx)(k,{fontSize:`small`}),onClick:()=>a(!0),children:P(r,`Xem toàn màn hình`,`Full screen`)})}),!i&&(0,q.jsx)(xn,{...e}),(0,q.jsx)(n,{fullScreen:!0,open:i,onClose:()=>a(!1),"aria-label":P(r,`Báo cáo thay đổi giao diện`,`Front-end change report`),children:(0,q.jsxs)(`div`,{className:`change-report-full`,children:[(0,q.jsx)(m,{className:`change-report-close`,onClick:()=>a(!1),"aria-label":P(r,`Đóng toàn màn hình`,`Close full screen`),children:(0,q.jsx)(s,{})}),i&&(0,q.jsx)(xn,{...e})]})})]})}function xn({report:e,sessionRef:t,documentRef:n}){let{locale:r}=N(),i=J(e.viewports).filter(e=>cn.test(Y(e)));i.length===0&&i.push(`desktop`,`mobile`);let a=J(e.sections).filter(e=>cn.test(Y(e?.key))),o=e.e2e,s=[...o?[{name:`E2E${o.command?` · ${Y(o.command)}`:``}`,result:o.result,detail:[o.passed!==void 0&&`${Y(o.passed)} ${P(r,`đạt`,`passed`)}`,o.failed&&`${Y(o.failed)} ${P(r,`lỗi`,`failed`)}`,o.skipped&&`${Y(o.skipped)} ${P(r,`bỏ qua`,`skipped`)}`,Y(o.duration),...J(o.notes).map(Y)].filter(Boolean).join(` · `)}]:[],...J(e.checks)],c=(e,t,n)=>n&&(0,q.jsxs)(`section`,{className:`change-report-block`,children:[(0,q.jsx)(`h3`,{children:e}),t]});return(0,q.jsxs)(`div`,{className:`change-report`,children:[(0,q.jsxs)(`header`,{children:[(0,q.jsx)(`h2`,{children:Y(e.title)||P(r,`Báo cáo thay đổi giao diện`,`Front-end change report`)}),e.lede&&(0,q.jsx)(`p`,{className:`change-report-note`,children:Y(e.lede)}),(0,q.jsxs)(`div`,{className:`change-report-chips`,children:[e.base&&(0,q.jsxs)(`span`,{children:[P(r,`Cũ`,`Before`),`: `,Y(e.base)]}),e.head&&(0,q.jsxs)(`span`,{children:[P(r,`Mới`,`After`),`: `,Y(e.head)]})]})]}),c(P(r,`Tóm tắt`,`Summary`),(0,q.jsx)(`ul`,{children:J(e.summary).map((e,t)=>(0,q.jsx)(`li`,{children:Y(e)},t))}),J(e.summary).length>0),c(P(r,`Business thay đổi`,`Business changes`),(0,q.jsx)(vn,{rows:J(e.business),last:`impact`,locale:r}),J(e.business).length>0),c(P(r,`Logic thay đổi`,`Logic changes`),(0,q.jsx)(vn,{rows:J(e.logic),last:`files`,locale:r}),J(e.logic).length>0),c(P(r,`UI/UX cũ và mới`,`UI/UX before and after`),a.map(e=>(0,q.jsx)(Q,{section:e,viewports:i,sessionRef:t,documentRef:n,locale:r},e.key)),a.length>0),c(P(r,`Kiểm thử`,`Verification`),(0,q.jsx)(`div`,{className:`change-report-scroll`,children:(0,q.jsx)(`table`,{className:`change-report-table`,children:(0,q.jsx)(`tbody`,{children:s.map((e,t)=>(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`td`,{children:Y(e.name)}),(0,q.jsx)(`td`,{children:(0,q.jsx)(yn,{value:e.result,locale:r})}),(0,q.jsx)(`td`,{children:Y(e.detail)})]},t))})})}),s.length>0),c(P(r,`File đã đổi`,`Changed files`),(0,q.jsx)(`div`,{className:`change-report-scroll`,children:(0,q.jsx)(`table`,{className:`change-report-table`,children:(0,q.jsx)(`tbody`,{children:J(e.files).map((e,t)=>(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`td`,{children:(0,q.jsx)(`code`,{children:Y(e.path)})}),(0,q.jsx)(`td`,{children:Y(e.kind)}),(0,q.jsx)(`td`,{children:Y(e.summary)})]},t))})})}),J(e.files).length>0),c(P(r,`Rủi ro và việc còn lại`,`Risks and follow-ups`),(0,q.jsx)(`ul`,{children:J(e.risks).map((e,t)=>(0,q.jsx)(`li`,{children:Y(e)},t))}),J(e.risks).length>0)]})}var Sn=(0,W.lazy)(async()=>({default:(await le(async()=>{let{MarkdownMessage:e}=await import(`./MarkdownMessage-DGt5B-6D.js`);return{MarkdownMessage:e}},__vite__mapDeps([0,1,2,3,4,5,6]))).MarkdownMessage})),Cn=new Set([`md`,`markdown`]),wn=new Set([`csv`,`tsv`]);function Tn(e){return e>=1048576?`${(e/1024/1024).toFixed(1)} MB`:`${Math.max(1,Math.round(e/1024))} KB`}function En(e,t){return e.source===`project`?P(t,`Project`,`Project`):P(t,`Thư mục đã cấp quyền`,`Granted directory`)}function Dn(e,t){let n=[],r=[],i=``,a=!1,o=0,s=()=>{r.length<40&&r.push(i),i=``},c=()=>{s(),r.some(e=>e.length>0)&&n.push(r),r=[]};for(;o<e.length&&n.length<500;){let n=e[o];if(a){if(n===`"`&&e[o+1]===`"`){i+=`"`,o+=2;continue}if(n===`"`){a=!1,o+=1;continue}i+=n,o+=1;continue}if(n===`"`&&i.length===0){a=!0,o+=1;continue}if(n===t){s(),o+=1;continue}if(n===`
4
4
  `||n===`\r`){c(),n===`\r`&&e[o+1]===`
5
5
  `&&(o+=1),o+=1;continue}i+=n,o+=1}return n.length<500&&(i.length>0||r.length>0)&&c(),n}function On({text:e,separator:t}){let n=(0,W.useMemo)(()=>Dn(e,t),[e,t]);if(n.length===0)return null;let[r,...i]=n,a=Math.min(Math.max(...n.map(e=>e.length)),40);return(0,q.jsx)(h,{sx:{overflowX:`auto`},children:(0,q.jsxs)(h,{component:`table`,className:`document-table`,children:[(0,q.jsx)(h,{component:`thead`,children:(0,q.jsx)(h,{component:`tr`,children:Array.from({length:a},(e,t)=>(0,q.jsx)(h,{component:`th`,children:r[t]??``},t))})}),(0,q.jsx)(h,{component:`tbody`,children:i.map((e,t)=>(0,q.jsx)(h,{component:`tr`,children:Array.from({length:a},(t,n)=>(0,q.jsx)(h,{component:`td`,children:e[n]??``},n))},t))})]})})}function kn({document:e,extension:t,sessionRef:n}){let r=e.text??``,i=e.name===`report.json`&&!e.truncated?ln(r):null;return i?(0,q.jsx)(bn,{report:i,sessionRef:n,documentRef:e.documentRef}):Cn.has(t??``)?(0,q.jsx)(W.Suspense,{fallback:(0,q.jsx)(h,{component:`pre`,className:`document-plain`,children:r}),children:(0,q.jsx)(Sn,{children:r})}):wn.has(t??``)?(0,q.jsx)(On,{text:r,separator:t===`tsv`?` `:`,`}):(0,q.jsx)(h,{component:`pre`,className:`document-plain`,children:r})}function An({sessionRef:e=null}){let{locale:t}=N(),[n,i]=(0,W.useState)({state:`idle`}),[a,o]=(0,W.useState)(null),[s,l]=(0,W.useState)({state:`idle`}),[u,d]=(0,W.useState)(``),f=(0,W.useRef)(null);(0,W.useEffect)(()=>{let t=new AbortController;return i({state:`loading`}),o(null),l({state:`idle`}),Ae(e,t.signal).then(e=>i({state:`ready`,value:e})).catch(()=>{t.signal.aborted||i({state:`error`})}),()=>t.abort()},[e]),(0,W.useEffect)(()=>{if(!a){l({state:`idle`});return}let t=new AbortController;return l({state:`loading`}),Fe(e,a,t.signal).then(e=>{l({state:`ready`,value:e}),f.current?.scrollTo({top:0})}).catch(()=>{t.signal.aborted||l({state:`error`})}),()=>t.abort()},[e,a]);let p=n.value,m=u.trim().toLowerCase(),h=(0,W.useMemo)(()=>(p?.documents??[]).filter(e=>!m||e.relativePath.toLowerCase().includes(m)),[p,m]),g=(0,W.useMemo)(()=>(p?.roots??[]).map(e=>({root:e,entries:h.filter(t=>t.rootRef===e.rootRef)})).filter(e=>e.entries.length>0),[p,h]),_=h.find(e=>e.documentRef===a)??p?.documents.find(e=>e.documentRef===a);return(0,q.jsxs)(`section`,{className:`document-workspace surface`,"aria-labelledby":`documents-heading`,children:[(0,q.jsxs)(`header`,{className:`document-heading`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:P(t,`Chỉ đọc · không sửa file`,`Read only · never writes`)}),(0,q.jsx)(`h2`,{id:`documents-heading`,children:P(t,`Tài liệu`,`Documents`)})]}),(0,q.jsx)(`span`,{children:p?`${p.documents.length}${p.truncated?`+`:``} ${P(t,`tài liệu`,`documents`)}`:`—`})]}),(0,q.jsxs)(`div`,{className:`document-body`,children:[(0,q.jsxs)(`aside`,{className:`document-list`,"aria-label":P(t,`Danh sách tài liệu`,`Document list`),children:[(0,q.jsx)(v,{size:`small`,fullWidth:!0,value:u,onChange:e=>d(e.target.value),placeholder:P(t,`Lọc theo tên hoặc thư mục…`,`Filter by name or folder…`),slotProps:{htmlInput:{"aria-label":P(t,`Lọc tài liệu`,`Filter documents`)},input:{startAdornment:(0,q.jsx)(oe,{position:`start`,children:(0,q.jsx)(r,{fontSize:`small`})})}}}),n.state===`loading`&&(0,q.jsx)(`p`,{className:`document-empty`,children:P(t,`Đang quét tài liệu…`,`Scanning for documents…`)}),n.state===`error`&&(0,q.jsx)(`p`,{className:`document-empty`,children:P(t,`Không đọc được danh sách tài liệu.`,`The document list could not be read.`)}),p?.state===`unavailable`&&(0,q.jsx)(`p`,{className:`document-empty`,children:L(p.reasonCode,t)}),n.state===`ready`&&p?.state===`ready`&&g.length===0&&(0,q.jsx)(`p`,{className:`document-empty`,children:m?P(t,`Không có tài liệu nào khớp bộ lọc.`,`No document matches the filter.`):P(t,`Chưa tìm thấy tài liệu nào.`,`No documents were found.`)}),g.map(e=>(0,q.jsxs)(`div`,{className:`document-group`,children:[(0,q.jsxs)(`div`,{className:`document-group-heading`,children:[(0,q.jsx)(`strong`,{children:En(e.root,t)}),(0,q.jsx)(`span`,{title:e.root.path,children:e.root.path})]}),e.entries.map(e=>(0,q.jsxs)(A,{component:`button`,type:`button`,className:`document-row`,selected:e.documentRef===a,onClick:()=>o(e.documentRef),children:[(0,q.jsx)(j,{fontSize:`small`,"aria-hidden":`true`}),(0,q.jsxs)(`span`,{className:`document-row-copy`,children:[(0,q.jsx)(`strong`,{children:e.name}),(0,q.jsx)(`small`,{children:e.relativePath})]}),(0,q.jsxs)(`span`,{className:`document-row-meta`,children:[e.extension,` · `,Tn(e.sizeBytes)]})]},e.documentRef))]},e.root.rootRef)),p?.truncated&&(0,q.jsx)(`p`,{className:`document-empty`,children:P(t,`Danh sách đã đạt giới hạn; dùng bộ lọc để thu hẹp.`,`The list reached its limit; use the filter to narrow it.`)})]}),(0,q.jsxs)(`div`,{className:`document-viewer`,ref:f,children:[!a&&(0,q.jsxs)(`div`,{className:`document-placeholder`,children:[(0,q.jsx)(j,{"aria-hidden":`true`}),(0,q.jsx)(c,{variant:`body2`,children:P(t,`Chọn một tài liệu để đọc nội dung tại đây.`,`Pick a document to read it here.`)}),(0,q.jsx)(c,{variant:`caption`,color:`text.disabled`,children:P(t,`Hỗ trợ .md .txt .csv .json .yaml .docx .pdf .xlsx .pptx .odt .ods .odp .rtf`,`Supports .md .txt .csv .json .yaml .docx .pdf .xlsx .pptx .odt .ods .odp .rtf`)})]}),a&&s.state===`loading`&&(0,q.jsx)(`p`,{className:`document-empty`,children:P(t,`Đang mở tài liệu…`,`Opening the document…`)}),a&&s.state===`error`&&(0,q.jsx)(`p`,{className:`document-empty`,children:P(t,`Không mở được tài liệu này.`,`This document could not be opened.`)}),s.state===`ready`&&s.value&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`document-toolbar`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:s.value.name??_?.name??`—`}),(0,q.jsx)(`small`,{children:s.value.relativePath??_?.relativePath??``})]}),(0,q.jsxs)(`div`,{className:`document-badges`,children:[s.value.format&&(0,q.jsx)(M,{size:`small`,variant:`outlined`,label:s.value.format}),s.value.truncated&&(0,q.jsx)(M,{size:`small`,color:`warning`,variant:`outlined`,label:P(t,`Đã cắt bớt`,`Truncated`)}),s.value.redacted&&(0,q.jsx)(M,{size:`small`,color:`warning`,variant:`outlined`,label:P(t,`Đã che dữ liệu nhạy cảm`,`Sensitive data redacted`)})]})]}),s.value.state===`unavailable`?(0,q.jsx)(`p`,{className:`document-empty`,children:L(s.value.reasonCode,t)}):(0,q.jsx)(`article`,{className:`document-content`,children:(0,q.jsx)(kn,{document:s.value,extension:_?.extension,sessionRef:e})})]})]})]})]})}function jn(e,t=`vi`){return e===null||!Number.isFinite(e)?t===`vi`?`Không có dữ liệu`:`No data`:Math.abs(e)<1e3?String(Math.round(e)):Math.abs(e)<1e6?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:`${(e/1e6).toFixed(1)}m`}function Mn(e,t=`vi`){return e.state!==`known`||e.tokens===null||e.percent===null?t===`vi`?`Context chưa xác định`:`Unknown context`:`${jn(e.tokens,t)} / ${jn(e.contextWindow,t)} · ${e.percent.toFixed(1)}%`}function Nn(e,t=`vi`){return e.state===`known`?`↑ ${jn(e.input,t)} · ↓ ${jn(e.output,t)}`:t===`vi`?`Không có dữ liệu`:`No data`}function Pn(e,t=`vi`){return e?e.state===`passed`?e.exitCodeExact?`Pass · exit ${e.exitCode??0}`:t===`vi`?`Pass · exit chưa xác định`:`Pass · unknown exit`:e.state===`failed`?e.exitCodeExact?`Fail · exit ${e.exitCode??`?`}`:t===`vi`?`Fail · exit chưa xác định`:`Fail · unknown exit`:e.state===`stale`?e.staleFilesKnown?`Stale · ${e.staleByPaths.length} file`:t===`vi`?`Stale · file chưa xác định`:`Stale · unknown files`:e.state.replaceAll(`-`,` `):t===`vi`?`Chưa có verifier gần nhất`:`No recent verifier`}function Fn(e,t=`vi`){return e.task?.blocker??e.task?.reasonCode??e.verification.reasonCode??e.health.issues.find(e=>e.severity===`error`)?.message??(t===`vi`?`Không có blocker được ghi nhận`:`No recorded blocker`)}function In({kicker:e,title:t,children:n}){return(0,q.jsxs)(`section`,{className:`evidence-card surface`,children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:e}),(0,q.jsx)(`h3`,{children:t}),n]})}function Ln({snapshot:e}){let{locale:t}=N(),n=e.verification.latest,r=e.usage.context,i=e.continuation,a=e.handoff,o=r.state===`known`&&r.percent!==null?Math.max(0,Math.min(100,r.percent)):0;return(0,q.jsxs)(`section`,{className:`evidence-section`,"aria-labelledby":`evidence-title`,children:[(0,q.jsxs)(`header`,{className:`section-title-row`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Completion evidence`}),(0,q.jsx)(`h2`,{id:`evidence-title`,children:P(t,`Verifier, usage và handoff`,`Verifier, usage, and handoff`)})]}),(0,q.jsx)(`span`,{children:Fn(e,t)})]}),(0,q.jsxs)(`div`,{className:`evidence-grid`,children:[(0,q.jsx)(In,{kicker:P(t,`Verifier gần nhất`,`Latest verifier`),title:Pn(n,t),children:n?(0,q.jsxs)(`dl`,{className:`evidence-list`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Command`}),(0,q.jsx)(`dd`,{title:n.command,children:n.command})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Exact`}),(0,q.jsx)(`dd`,{children:n.exact?P(t,`Có`,`Yes`):P(t,`Không`,`No`)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Tree digest`}),(0,q.jsx)(`dd`,{title:n.treeDigest??void 0,children:Je(n.treeDigest)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:P(t,`File làm stale`,`Stale files`)}),(0,q.jsx)(`dd`,{children:n.staleFilesKnown?n.staleByPaths.length:P(t,`Chưa biết`,`Unknown`)})]})]}):(0,q.jsx)(`p`,{className:`card-empty`,children:e.verification.reasonCode?L(e.verification.reasonCode,t):P(t,`Task chưa chạy verifier.`,`The task has not run a verifier.`)})}),(0,q.jsxs)(In,{kicker:`Token & context`,title:Mn(r,t),children:[(0,q.jsx)(`div`,{className:`context-meter`,role:`progressbar`,"aria-label":P(t,`Mức sử dụng context`,`Context usage`),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":o,children:(0,q.jsx)(`span`,{style:{width:`${o}%`}})}),(0,q.jsxs)(`dl`,{className:`evidence-list`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:P(t,`Turn gần nhất`,`Latest turn`)}),(0,q.jsx)(`dd`,{children:Nn(e.usage.latestTurn,t)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Task total`}),(0,q.jsx)(`dd`,{children:Nn(e.usage.taskTotal,t)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Session total`}),(0,q.jsx)(`dd`,{children:Nn(e.usage.sessionTotal,t)})]})]})]}),(0,q.jsxs)(In,{kicker:`Continuation budget`,title:L(i.state,t),children:[(0,q.jsxs)(`dl`,{className:`budget-grid`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:P(t,`Còn lại`,`Remaining`)}),(0,q.jsx)(`dd`,{children:jn(i.remaining,t)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:P(t,`Đã dùng`,`Used`)}),(0,q.jsx)(`dd`,{children:jn(i.consumed,t)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:P(t,`Tối đa`,`Maximum`)}),(0,q.jsx)(`dd`,{children:jn(i.maximum,t)})]})]}),i.reasonCode&&(0,q.jsx)(`p`,{className:`card-note`,children:L(i.reasonCode,t)})]}),(0,q.jsx)(In,{kicker:`Handoff`,title:a?L(a.state,t):P(t,`Chưa có handoff`,`No handoff`),children:a?(0,q.jsxs)(`div`,{className:`handoff-copy`,children:[(0,q.jsx)(`p`,{children:a.summary}),a.blocker&&(0,q.jsxs)(`div`,{className:`handoff-blocker`,children:[(0,q.jsx)(`strong`,{children:`Blocker`}),(0,q.jsx)(`span`,{children:a.blocker})]}),a.nextSafeAction&&(0,q.jsxs)(`div`,{className:`next-action`,children:[(0,q.jsx)(`strong`,{children:P(t,`Bước an toàn tiếp theo`,`Next safe action`)}),(0,q.jsx)(`span`,{children:a.nextSafeAction})]})]}):(0,q.jsx)(`p`,{className:`card-empty`,children:P(t,`Handoff sẽ xuất hiện khi runtime ghi nhận trạng thái chuyển giao.`,`A handoff will appear when the runtime records a transfer state.`)})})]})]})}function Rn({snapshot:e,events:t,refreshSnapshot:n}){let{locale:r}=N(),[i,a]=(0,W.useState)(),[o,s]=(0,W.useState)(!0),[c,l]=(0,W.useState)(``),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(),[g,_]=(0,W.useState)(null),[v,y]=(0,W.useState)(``),[b,x]=(0,W.useState)(()=>`message-request.${crypto.randomUUID()}`),[S,C]=(0,W.useState)([]),[w,T]=(0,W.useState)(!1),[E,D]=(0,W.useState)(!1),O=(0,W.useRef)(0),ee=(0,W.useMemo)(()=>z(t),[t]),k=[...t].reverse().find(e=>[`message.completed`,`message.failed`,`agent-operation.settled`].includes(String(e.kind)))?.eventCursor??null;(0,W.useEffect)(()=>{let e=new AbortController;return s(!0),a(void 0),De(null,50,e.signal).then(e=>a(e)).catch(()=>void 0).finally(()=>s(!1)),()=>e.abort()},[e.identity.sessionRef]),(0,W.useEffect)(()=>{C([]),x(`message-request.${crypto.randomUUID()}`)},[e.identity.sessionRef]),(0,W.useEffect)(()=>{let e=e=>{e.dataTransfer&&[...e.dataTransfer.types].includes(`Files`)&&e.preventDefault()};return window.addEventListener(`dragover`,e),window.addEventListener(`drop`,e),()=>{window.removeEventListener(`dragover`,e),window.removeEventListener(`drop`,e)}},[]),(0,W.useEffect)(()=>{if(!k)return;let e=new AbortController,t=window.setTimeout(()=>{De(null,50,e.signal).then(e=>a(e)).catch(()=>void 0)},80);return()=>{window.clearTimeout(t),e.abort()}},[k]);let te=async()=>{try{let e=await Be();return h(e),e}catch{return}};(0,W.useEffect)(()=>{let e=new AbortController;return Be(e.signal).then(h).catch(()=>void 0),()=>e.abort()},[e.identity.sessionRef,e.revision.queueRevision]);let A=async()=>{let e=i?.page.nextBeforeCursor;if(e)try{let t=await De(e,i.page.limit);a(e=>e?{...e,items:B(e.items,t.items),page:t.page}:t)}catch{}},ne=(0,W.useMemo)(()=>i?.state===`ready`?ot(i.items):[],[i]),re=e.capabilities.capabilities[`control.chat`],j=re.status===`available`?re.actions:null,ie=!!j?.send.available,ae=e.capabilities.capabilities[`control.resumeAndContinue`].status===`available`,oe=ie||ae,M=e.capabilities.capabilities.attachments,se=M.status===`available`,ce=(0,W.useMemo)(()=>new Set(M.status===`available`?M.mimeTypes:[]),[M]),le=(0,W.useMemo)(()=>at(ce),[ce]),ue=se&&!u&&!w&&S.length<4,F=e.session.operation.liveness===`running`,de=async()=>{await n?.(),await te()},fe=async t=>{let n=c.trim();if(!(!n||u||(t===`resume-and-continue`?!ae:!ie))){d(!0),p(null);try{let i=S.length?{messageRequestId:b,attachmentRefs:S.map(e=>e.attachmentRef)}:void 0,a=t===`resume-and-continue`?await je(await it(e,n,i)):await Ie(await Qe(e,n,t,i));[`dispatch-observed`,`dispatch-requested`].includes(a.resultCode)?(l(``),C([]),x(`message-request.${crypto.randomUUID()}`),p(a.resultCode===`dispatch-observed`?P(r,`Đã gửi vào Pi session`,`Sent to the Pi session`):P(r,`Pi đã nhận yêu cầu`,`Pi received the request`))):a.resultCode===`held`?(l(``),p(P(r,`Đã giữ trong hàng đợi`,`Held in the queue`))):a.resultCode===`resumed-not-dispatched`?p(P(r,`Task đã mở lại nhưng tin nhắn chưa được gửi; nội dung vẫn được giữ để kiểm tra lại.`,`The task resumed but the message was not sent; the content remains for review.`)):p(`${P(r,`Chưa gửi`,`Not sent`)} · ${L(a.resultCode,r)}`),await de()}catch{p(P(r,`Không thể gửi; trạng thái Pi có thể đã thay đổi.`,`Unable to send; Pi state may have changed.`))}finally{d(!1)}}},pe=async t=>{if(!(!t?.length||!se||w)){T(!0),p(null);try{let n=await $e({files:t,snapshot:e,messageRequestId:b,existing:S,allowed:ce,locale:r,stage:Ee});C(n.attachments),p(n.status)}catch{p(P(r,`Không thể đính kèm; file không được gửi vào Pi.`,`Unable to attach the file; it was not sent to Pi.`))}finally{T(!1)}}},me=()=>{O.current=0,D(!1)},he=e=>{H(e.dataTransfer)&&(e.preventDefault(),me(),ue&&pe(e.dataTransfer.files))},ge=async t=>{if(!(u||w)){T(!0),p(null);try{let n=await V({snapshot:e,messageRequestId:b,attachmentRef:t,locale:r,stage:Ee});n.discarded?C(e=>e.filter(e=>e.attachmentRef!==t)):p(n.status)}catch{p(P(r,`Không thể bỏ file; trạng thái Pi có thể đã thay đổi.`,`Unable to remove the file; Pi state may have changed.`))}finally{T(!1)}}},_e=async(t,n,i)=>{if(!u){d(!0),p(null);try{let a=t===`queue.update`?await rt(n,i?.trim()??``):t===`queue.delete`?{queueItemRef:n}:{queueItemRef:n,messageRequestId:`message-request.${crypto.randomUUID()}`},o=await Ie(await R(e,t,a));[`updated`,`deleted`,`dispatch-observed`,`dispatch-requested`].includes(o.resultCode)?(_(null),y(``),p(L(o.resultCode,r))):p(`${P(r,`Chưa thay đổi`,`Not changed`)} · ${L(o.resultCode,r)}`),await de()}catch{p(P(r,`Hàng đợi đã thay đổi; đã tải lại trạng thái mới nhất.`,`The queue changed; the latest state has been reloaded.`)),await de()}finally{d(!1)}}};return(0,q.jsxs)(`section`,{className:`chat-panel surface`,"aria-labelledby":`chat-heading`,"data-dragging":E||void 0,onDragEnter:e=>{H(e.dataTransfer)&&(O.current+=1,D(!0))},onDragOver:e=>{H(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer.dropEffect=ue?`copy`:`none`)},onDragLeave:e=>{H(e.dataTransfer)&&(--O.current,O.current<=0&&me())},onDrop:he,children:[E&&(0,q.jsxs)(`div`,{className:`chat-drop-overlay`,role:`status`,children:[(0,q.jsx)(`strong`,{children:ue?P(r,`Thả tài liệu vào đây`,`Drop documents here`):S.length>=4?P(r,`Đã đủ 4 file cho tin nhắn này`,`This message already holds 4 files`):P(r,`Chưa nhận file lúc này`,`Files cannot be attached right now`)}),ue&&(0,q.jsx)(`small`,{children:tt(r)})]}),(0,q.jsxs)(`header`,{className:`chat-heading`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:P(r,`Đúng Pi session hiện tại`,`Exact current Pi session`)}),(0,q.jsx)(`h2`,{id:`chat-heading`,children:`Chat`})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`span`,{children:[ne.length,` `,P(r,`message gần nhất`,`recent messages`)]}),(0,q.jsx)(`span`,{className:`chat-read-state`,children:P(r,`Streaming trực tiếp`,`Live streaming`)})]})]}),(0,q.jsxs)(`div`,{className:`chat-body`,"aria-live":`polite`,children:[i?.page.hasOlder&&(0,q.jsx)(`button`,{type:`button`,className:`load-older`,onClick:()=>void A(),children:P(r,`Tải message cũ hơn`,`Load older messages`)}),o&&(0,q.jsx)(`p`,{className:`chat-empty`,children:P(r,`Đang tải transcript hiện tại…`,`Loading the current transcript…`)}),!o&&i?.state===`unavailable`&&(0,q.jsxs)(`p`,{className:`chat-empty`,children:[P(r,`Transcript cần đồng bộ lại`,`Transcript needs resync`),` · `,L(i.reasonCode,r)]}),!o&&i?.state===`ready`&&ne.length===0&&ee.assistants.length===0&&(0,q.jsx)(`p`,{className:`chat-empty`,children:P(r,`Chưa có message trong Pi session này.`,`There are no messages in this Pi session.`)}),ne.map(e=>e.role===`tool-result`?(0,q.jsxs)(`article`,{className:`chat-tool-result`,children:[(0,q.jsx)(`strong`,{children:e.toolCalls[0]?.toolName??`Tool`}),(0,q.jsx)(`span`,{children:P(r,`Kết quả chi tiết nằm trong Activity`,`Detailed output is available in Activity`)})]},e.messageRef):(0,q.jsxs)(`article`,{className:`chat-message chat-${e.role}`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:e.role===`user`?P(r,`Anh`,`You`):e.role===`custom`?P(r,`Biên nhận Piagent`,`Piagent receipt`):`Pi`}),(0,q.jsx)(`time`,{children:new Date(e.recordedAt).toLocaleTimeString(r===`vi`?`vi-VN`:`en-US`,{hour:`2-digit`,minute:`2-digit`})})]}),(0,q.jsx)(`p`,{children:e.content.text||(e.content.imageCount?`${e.content.imageCount} ${P(r,`ảnh đính kèm`,`attached images`)}`:P(r,`Message trống`,`Empty message`))}),(e.content.redacted||e.content.truncated)&&(0,q.jsx)(`small`,{children:e.content.redacted?P(r,`Đã che dữ liệu nhạy cảm`,`Sensitive data redacted`):P(r,`Nội dung đã rút gọn`,`Content truncated`)})]},e.messageRef)),ee.assistants.map(e=>(0,q.jsxs)(`article`,{className:`chat-message chat-assistant chat-streaming`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:`Pi`}),(0,q.jsx)(`span`,{className:`stream-indicator`,children:P(r,`Đang trả lời`,`Responding`)})]}),(0,q.jsx)(`p`,{children:e.text||(e.thinking?P(r,`Đang suy nghĩ…`,`Thinking…`):P(r,`Đang chuẩn bị câu trả lời…`,`Preparing a response…`))}),e.truncated&&(0,q.jsx)(`small`,{children:P(r,`Live preview đã đạt giới hạn`,`Live preview limit reached`)})]},e.messageRef)),ee.tools.filter(e=>[`started`,`progress`].includes(e.state)).map(e=>(0,q.jsxs)(`article`,{className:`chat-tool-live`,children:[(0,q.jsx)(`span`,{className:`tool-spinner`,"aria-hidden":`true`}),(0,q.jsx)(`strong`,{children:e.toolName}),(0,q.jsx)(`span`,{children:L(e.state,r)})]},e.toolCallId))]}),m?.state===`ready`&&m.items.length>0&&(0,q.jsxs)(`section`,{className:`held-queue`,"aria-label":P(r,`Tin nhắn đang giữ`,`Held messages`),children:[(0,q.jsxs)(`div`,{className:`held-queue-heading`,children:[(0,q.jsx)(`strong`,{children:P(r,`Đang giữ ${m.heldCount} tin`,`${m.heldCount} held messages`)}),m.quarantinedCount>0&&(0,q.jsxs)(`span`,{children:[m.quarantinedCount,` `,P(r,`tin cần kiểm tra`,`need review`)]})]}),(0,q.jsx)(`ol`,{children:m.items.map(e=>(0,q.jsxs)(`li`,{"data-state":e.state,children:[g===e.queueItemRef?(0,q.jsx)(`textarea`,{"aria-label":P(r,`Sửa tin nhắn đang giữ`,`Edit held message`),rows:2,maxLength:65536,value:v,onChange:e=>y(e.target.value)}):(0,q.jsx)(`p`,{children:e.preview}),(0,q.jsx)(`div`,{children:g===e.queueItemRef?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,disabled:u||!v.trim(),onClick:()=>void _e(`queue.update`,e.queueItemRef,v),children:P(r,`Lưu`,`Save`)}),(0,q.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>{_(null),y(``)},children:P(r,`Hủy`,`Cancel`)})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,disabled:u||e.state!==`held`||!j?.dispatchHeld.available,onClick:()=>void _e(`queue.dispatch`,e.queueItemRef),children:P(r,`Gửi`,`Send`)}),(0,q.jsx)(`button`,{type:`button`,disabled:u||e.state!==`held`||e.redacted||e.truncated||!j?.editHeld.available,title:e.redacted||e.truncated?P(r,`Không sửa từ preview đã che hoặc rút gọn`,`Redacted or truncated previews cannot be edited`):void 0,onClick:()=>{_(e.queueItemRef),y(e.preview)},children:P(r,`Sửa`,`Edit`)}),(0,q.jsx)(`button`,{type:`button`,disabled:u||!j?.deleteHeld.available,onClick:()=>void _e(`queue.delete`,e.queueItemRef),children:P(r,`Xóa`,`Delete`)})]})}),(e.redacted||e.truncated||e.state===`quarantined`)&&(0,q.jsx)(`small`,{children:e.state===`quarantined`?P(r,`Lần gửi trước chưa xác định; không tự gửi lại`,`The previous dispatch is uncertain; it will not be resent automatically`):e.redacted?P(r,`Preview đã che dữ liệu nhạy cảm`,`Sensitive data is redacted in the preview`):P(r,`Preview đã rút gọn`,`Preview truncated`)})]},e.queueItemRef))})]}),(0,q.jsxs)(`footer`,{className:`chat-composer-preview`,children:[S.length>0&&(0,q.jsx)(`ul`,{className:`attachment-list`,"aria-label":P(r,`File sẽ gửi cùng message`,`Files to send with the message`),children:S.map(e=>(0,q.jsxs)(`li`,{"data-kind":e.kind,children:[(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`strong`,{children:e.displayName}),(0,q.jsx)(`small`,{children:nt(e,r)})]}),(0,q.jsx)(`button`,{type:`button`,disabled:u||w,"aria-label":`${P(r,`Bỏ`,`Remove`)} ${e.displayName}`,onClick:()=>void ge(e.attachmentRef),children:P(r,`Bỏ`,`Remove`)})]},e.attachmentRef))}),(0,q.jsx)(`textarea`,{"aria-label":P(r,`Nội dung chat`,`Chat message`),placeholder:ae?P(r,`Nhập việc cần Pi làm ngay sau khi mở lại task…`,`Enter work for Pi immediately after the task resumes…`):ie?P(r,`Nhắn vào đúng Pi session này…`,`Message this exact Pi session…`):P(r,`Chat control chưa khả dụng.`,`Chat control is unavailable.`),disabled:!oe||u,maxLength:65536,rows:2,value:c,onChange:e=>l(e.target.value),onPaste:e=>{e.clipboardData?.files.length&&(e.preventDefault(),ue&&pe(e.clipboardData.files))}}),(0,q.jsxs)(`div`,{className:`composer-actions`,children:[(0,q.jsx)(`button`,{type:`button`,disabled:!oe||u||!c.trim(),onClick:()=>void fe(ae?`resume-and-continue`:F?`follow-up`:`new-operation`),children:u?P(r,`Đang gửi…`,`Sending…`):ae?P(r,`Tiếp tục & gửi`,`Resume & send`):F?P(r,`Gửi sau`,`Send next`):P(r,`Gửi`,`Send`)}),(0,q.jsx)(`button`,{type:`button`,disabled:!ie||u||!c.trim()||S.length>0||!j?.hold.available,title:S.length?P(r,`Bản này chưa giữ file trong hàng đợi`,`This version does not hold attachments in the queue`):void 0,onClick:()=>void fe(`hold`),children:P(r,`Giữ lại`,`Hold`)}),F&&(0,q.jsx)(`button`,{type:`button`,className:`interrupt-send`,disabled:!ie||u||!c.trim()||!j?.interruptAndSend.available,onClick:()=>void fe(`steer`),children:P(r,`Ngắt & gửi`,`Interrupt & send`)})]}),(0,q.jsxs)(`label`,{className:`attachment-picker ${ue?``:`disabled`}`,title:P(r,`Chọn file, hoặc kéo thả / dán thẳng vào khung chat`,`Pick a file, or drag and drop / paste straight into the chat`),children:[(0,q.jsx)(`input`,{type:`file`,multiple:!0,disabled:!ue,accept:le||void 0,onChange:e=>{pe(e.target.files),e.currentTarget.value=``}}),w?P(r,`Đang đọc tài liệu…`,`Reading documents…`):`${P(r,`Đính kèm hoặc kéo thả`,`Attach or drop`)} (${S.length}/4)`]}),f&&(0,q.jsx)(`small`,{role:`status`,children:f})]})]})}function zn({snapshot:e,refreshSnapshot:t}){let{locale:n}=N(),[r,i]=(0,W.useState)(),[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(``),[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(null),[p,m]=(0,W.useState)(null),h=(0,W.useRef)(0),g=(0,W.useRef)({revision:0,modelDirty:!1,thinkingDirty:!1}),_=e.capabilities.capabilities[`control.sessionOptions`],v=_.status===`available`?_.actions:null,y=async e=>{let t=++h.current,n=g.current.revision;try{let r=await de(e);return t===h.current?(i(r),r.state===`ready`&&n===g.current.revision&&(g.current.modelDirty||o(r.activeModelRef??``),g.current.thinkingDirty||c(r.activeThinkingLevel??`off`)),r):r}catch{!e?.aborted&&t===h.current&&i(void 0);return}};(0,W.useEffect)(()=>{let e=new AbortController;return y(e.signal),()=>e.abort()},[e.identity.sessionRef,e.revision.sessionOptionRevision]);let b=(0,W.useMemo)(()=>r?.models.find(e=>e.modelRef===r.activeModelRef),[r]),x=async i=>{if(!l||d||!r||r.state!==`ready`)return;let o=i===`model`?`session-options.set-model`:`session-options.set-thinking`,c=i===`model`?a:s;f(i),m(null);try{let r=await Le(await Xe(e,o,c));m(r.resultCode===`changed`?P(n,`Đã cập nhật trong Pi và mặc định người dùng`,`Updated in Pi and user defaults`):r.resultCode===`unchanged`?P(n,`Giá trị này đang được dùng`,`This value is already active`):r.resultCode===`effect-unknown`?P(n,`Pi chưa xác nhận được hậu trạng thái; hãy tải lại trước khi thử tiếp`,`Pi could not confirm the resulting state; refresh before trying again`):`${P(n,`Chưa thay đổi`,`Not changed`)} · ${L(r.resultCode,n)}`),u(!1),g.current.revision+=1,i===`model`?g.current.modelDirty=!1:g.current.thinkingDirty=!1,await t?.(),await y()}catch{m(P(n,`Không thể đổi; trạng thái Pi có thể đã thay đổi.`,`Unable to change the setting; Pi state may have changed.`))}finally{f(null)}};return(0,q.jsxs)(`section`,{className:`session-options surface`,"aria-labelledby":`session-options-title`,children:[(0,q.jsxs)(`div`,{className:`session-options-copy`,children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Model & thinking`}),(0,q.jsx)(`h2`,{id:`session-options-title`,children:P(n,`Thiết lập cho Pi session`,`Pi session settings`)}),(0,q.jsx)(`p`,{children:P(n,`Chỉ thay đổi khi Pi đang chờ. Thao tác này không gọi model, nhưng Pi cũng cập nhật mặc định người dùng.`,`Settings can only change while Pi is idle. This does not call the model, but Pi also updates user defaults.`)})]}),r?.state===`ready`?(0,q.jsxs)(`div`,{className:`session-options-controls`,children:[(0,q.jsxs)(`label`,{children:[(0,q.jsx)(`span`,{children:`Model`}),(0,q.jsx)(`select`,{"aria-label":P(n,`Chọn model`,`Select model`),value:a,disabled:d!==null||!v?.setModel.available,onChange:e=>{g.current.revision+=1,g.current.modelDirty=!0,o(e.target.value),u(!1),m(null)},children:r.models.map(e=>(0,q.jsxs)(`option`,{value:e.modelRef,children:[e.displayName,` · `,e.provider]},e.modelRef))})]}),(0,q.jsxs)(`label`,{children:[(0,q.jsx)(`span`,{children:`Thinking`}),(0,q.jsx)(`select`,{"aria-label":P(n,`Chọn thinking`,`Select thinking`),value:s,disabled:d!==null||!v?.setThinking.available,onChange:e=>{g.current.revision+=1,g.current.thinkingDirty=!0,c(e.target.value),u(!1),m(null)},children:(b?.supportedThinkingLevels??[]).map(e=>(0,q.jsx)(`option`,{value:e,children:L(e,n)},e))})]}),(0,q.jsxs)(`label`,{className:`effect-ack`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:l,disabled:d!==null||!v,onChange:e=>u(e.target.checked)}),(0,q.jsx)(`span`,{children:P(n,`Tôi hiểu thay đổi này áp dụng cho session và mặc định người dùng.`,`I understand this applies to the session and user defaults.`)})]}),(0,q.jsxs)(`div`,{className:`session-option-actions`,children:[(0,q.jsx)(`button`,{type:`button`,disabled:!l||d!==null||!v?.setModel.available||a===r.activeModelRef,onClick:()=>void x(`model`),children:d===`model`?P(n,`Đang đổi…`,`Changing…`):P(n,`Đổi model`,`Change model`)}),(0,q.jsx)(`button`,{type:`button`,disabled:!l||d!==null||!v?.setThinking.available||s===r.activeThinkingLevel,onClick:()=>void x(`thinking`),children:d===`thinking`?P(n,`Đang đổi…`,`Changing…`):P(n,`Đổi thinking`,`Change thinking`)})]}),p&&(0,q.jsx)(`small`,{role:`status`,children:p}),!v?.setModel.available&&(0,q.jsxs)(`small`,{children:[P(n,`Đang khóa thay đổi`,`Changes locked`),` · `,L(v?.setModel.reasonCode??(_.status===`unavailable`?_.reason?.code:`unavailable`),n)]})]}):(0,q.jsxs)(`div`,{className:`session-options-unavailable`,children:[(0,q.jsx)(`strong`,{children:P(n,`Catalog model chưa sẵn sàng`,`Model catalog unavailable`)}),(0,q.jsx)(`span`,{children:L(r?.reasonCode??`authenticated-model-catalog-unavailable`,n)})]})]})}var Bn={stopped:`Đã dừng lượt Pi hiện tại; task vẫn được giữ lại.`,"emergency-stop":`Đã dừng lượt Pi hiện tại.`,"stop-requested":`Đang chờ Pi xác nhận lượt hiện tại đã dừng.`,"already-idle":`Pi đang chờ, không có lượt nào cần dừng.`,"pause-requested":`Đang chờ tool hiện tại kết thúc tại điểm an toàn.`,paused:`Task đã tạm dừng an toàn.`,"already-pausing":`Task đang chờ điểm tạm dừng an toàn.`,"already-paused":`Task đang được tạm dừng.`,resumed:`Task đã hoạt động lại; chưa gửi thêm tin nhắn cho model.`,"pause-cancelled":`Đã hủy yêu cầu tạm dừng; chưa gọi model.`,"already-active":`Task đang hoạt động.`,"resume-rejected":`Chưa thể tiếp tục vì bằng chứng khôi phục chưa đủ an toàn.`,"settlement-unknown":`Chưa xác nhận được Pi đã dừng. Hãy xem trạng thái mới trước khi thử lại.`,"pause-unconfirmed":`Chưa đủ bằng chứng để xác nhận task đã tạm dừng.`},Vn={stopped:`Stopped the current Pi turn; the task remains intact.`,"emergency-stop":`Stopped the current Pi turn.`,"stop-requested":`Waiting for Pi to confirm the current turn has stopped.`,"already-idle":`Pi is idle; there is no turn to stop.`,"pause-requested":`Waiting for the current tool to finish at a safe point.`,paused:`The task is safely paused.`,"already-pausing":`The task is waiting for a safe pause point.`,"already-paused":`The task is paused.`,resumed:`The task is active again; no model message was sent.`,"pause-cancelled":`Cancelled the pause request; no model call was made.`,"already-active":`The task is active.`,"resume-rejected":`Resume is blocked because recovery evidence is not yet safe.`,"settlement-unknown":`Pi stop is unconfirmed. Refresh status before trying again.`,"pause-unconfirmed":`There is not enough evidence to confirm the task is paused.`};function Hn(e,t){return(t===`vi`?Bn:Vn)[e.resultCode]??(e.error?.message||`${P(t,`Chưa thực hiện`,`Not executed`)} · ${L(e.resultCode,t)}`)}function Un({snapshot:e,refreshSnapshot:t}){let{locale:n}=N(),r=e.capabilities.capabilities[`control.lifecycle`],[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(null),c=r.status===`available`,l=c?r.currentPhase:`unknown`,u=c?r.stopPhaseSupport[l]:null,d=!!(u?.stop===`supported`&&e.identity.agentOperationId),f=!!(c&&r.actions.pause.available),p=!!(c&&r.actions.resume.available);(0,W.useEffect)(()=>{o?.resultCode===`pause-requested`&&e.session.controlState===`paused`&&s({action:`lifecycle.pause`,resultCode:`paused`,text:(n===`vi`?Bn:Vn).paused}),o?.resultCode===`stop-requested`&&e.session.operation.liveness===`idle`&&s({action:`lifecycle.stop`,resultCode:`stopped`,text:(n===`vi`?Bn:Vn).stopped})},[o?.resultCode,n,e.session.controlState,e.session.operation.liveness]);let m=async r=>{if(!i){a(r),s(null);try{let i=await Re(await Ze(e,r));s({action:r,resultCode:i.resultCode,text:Hn(i,n)}),await t?.()}catch{s({action:r,resultCode:`request-failed`,text:P(n,`Trạng thái Pi đã thay đổi hoặc kết nối local bị gián đoạn. Hãy tải trạng thái mới rồi thử lại.`,`Pi state changed or the local connection was interrupted. Refresh status before trying again.`)})}finally{a(null)}}};return(0,q.jsxs)(`section`,{className:`lifecycle-panel surface`,"aria-labelledby":`lifecycle-title`,children:[(0,q.jsxs)(`div`,{className:`lifecycle-copy`,children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:P(n,`Điều khiển task`,`Task controls`)}),(0,q.jsx)(`h2`,{id:`lifecycle-title`,children:`Stop, pause & resume`}),(0,q.jsx)(`p`,{children:P(n,`Stop dừng lượt Pi đang chạy. Pause chờ tool hiện tại kết thúc rồi giữ task. Resume chỉ mở lại task, không tự gọi model. Muốn mở lại và giao việc ngay, dùng “Tiếp tục & gửi” trong Chat.`,`Stop ends the running Pi turn. Pause waits for the current tool to reach a safe point and holds the task. Resume reopens the task without calling the model. Use “Resume & send” in Chat to continue with new work.`)})]}),(0,q.jsxs)(`div`,{className:`lifecycle-state`,children:[(0,q.jsx)(`span`,{children:P(n,`Trạng thái`,`Status`)}),(0,q.jsx)(`strong`,{children:L(e.session.controlState,n)}),(0,q.jsxs)(`small`,{children:[`Pi: `,L(e.session.operation.liveness,n),` · phase: `,L(l,n)]})]}),(0,q.jsxs)(`div`,{className:`lifecycle-actions`,children:[(0,q.jsx)(`button`,{type:`button`,className:`danger-action`,disabled:i!==null||!d,onClick:()=>void m(`lifecycle.stop`),title:d?void 0:L(u?.reasonCode??`no-current-operation`,n),children:i===`lifecycle.stop`?P(n,`Đang dừng…`,`Stopping…`):P(n,`Dừng lượt hiện tại`,`Stop current turn`)}),(0,q.jsx)(`button`,{type:`button`,className:`secondary-action`,disabled:i!==null||!f,onClick:()=>void m(`lifecycle.pause`),title:!f&&c?L(r.actions.pause.reasonCode,n):void 0,children:i===`lifecycle.pause`?P(n,`Đang yêu cầu…`,`Requesting…`):P(n,`Tạm dừng task`,`Pause task`)}),(0,q.jsx)(`button`,{type:`button`,className:`primary-action`,disabled:i!==null||!p,onClick:()=>void m(`lifecycle.resume`),title:!p&&c?L(r.actions.resume.reasonCode,n):void 0,children:i===`lifecycle.resume`?P(n,`Đang mở lại…`,`Resuming…`):P(n,`Tiếp tục task`,`Resume task`)})]}),o&&(0,q.jsx)(`p`,{className:`lifecycle-result result-${o.resultCode===`request-failed`||o.resultCode.includes(`unknown`)||o.resultCode.includes(`unconfirmed`)||o.resultCode===`resume-rejected`?`warning`:`ok`}`,role:`status`,children:o.text}),!c&&(0,q.jsxs)(`p`,{className:`lifecycle-result result-warning`,children:[P(n,`Điều khiển chưa sẵn sàng`,`Controls unavailable`),` · `,L(r.reason?.code,n)]})]})}function Wn(e,t){try{return new Intl.DateTimeFormat(t===`vi`?`vi-VN`:`en-US`,{dateStyle:`short`,timeStyle:`short`}).format(new Date(e))}catch{return e}}function Gn({value:e,locale:t}){return(0,q.jsxs)(`span`,{className:`status-pill tone-${Ue(e)}`,children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,className:`status-dot`}),L(e,t)]})}function Kn({snapshot:e}){let{locale:t}=N(),[n,r]=(0,W.useState)(),[i,a]=(0,W.useState)(`loading`),[o,s]=(0,W.useState)(`all`),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(),[f,p]=(0,W.useState)(`idle`),[m,h]=(0,W.useState)(),[g,_]=(0,W.useState)(`idle`),[v,y]=(0,W.useState)(),[b,x]=(0,W.useState)(`idle`),[S,C]=(0,W.useState)(),[w,T]=(0,W.useState)(`idle`);(0,W.useEffect)(()=>{let e=new AbortController;return a(`loading`),_e(e.signal).then(t=>{e.signal.aborted||(r(t),a(`ready`),l(e=>e&&t.runs.some(t=>t.runRef===e)?e:t.activeRunRef??t.runs[0]?.runRef??null))}).catch(()=>{e.signal.aborted||a(`error`)}),()=>e.abort()},[e.revision.taskRevision,e.revision.eventCursor]);let E=(0,W.useMemo)(()=>(n?.runs??[]).filter(e=>o===`all`||o===`current`&&e.isCurrentSession||o===`terminal`&&e.terminal),[n,o]);return(0,W.useEffect)(()=>{if(!c){d(void 0),p(`idle`);return}let e=new AbortController;return p(`loading`),ue(c,e.signal).then(t=>{e.signal.aborted||(d(t),p(`ready`))}).catch(()=>{e.signal.aborted||p(`error`)}),()=>e.abort()},[c,e.revision.eventCursor]),(0,W.useEffect)(()=>{if(!c){y(void 0),x(`idle`);return}let e=new AbortController;return x(`loading`),Ce(c,e.signal).then(t=>{e.signal.aborted||(y(t),x(`ready`))}).catch(()=>{e.signal.aborted||x(`error`)}),()=>e.abort()},[c,e.revision.eventCursor]),(0,W.useEffect)(()=>{if(!c){h(void 0),_(`idle`);return}let e=new AbortController;return _(`loading`),Ne(c,e.signal).then(t=>{e.signal.aborted||(h(t),_(`ready`))}).catch(()=>{e.signal.aborted||_(`error`)}),()=>e.abort()},[c,e.revision.eventCursor]),(0,W.useEffect)(()=>{if(!c){C(void 0),T(`idle`);return}let e=new AbortController;return T(`loading`),Se(c,e.signal).then(t=>{e.signal.aborted||(C(t),T(`ready`))}).catch(()=>{e.signal.aborted||T(`error`)}),()=>e.abort()},[c,e.revision.eventCursor]),(0,q.jsxs)(`section`,{className:`task-run-index surface`,"aria-labelledby":`task-run-index-title`,children:[(0,q.jsxs)(`header`,{className:`source-heading`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Long-task dashboard`}),(0,q.jsx)(`h2`,{id:`task-run-index-title`,children:P(t,`Task và các lần chạy gần đây`,`Tasks and recent runs`)})]}),(0,q.jsxs)(`span`,{children:[n?.page.total??0,` `,P(t,`run từ local state`,`runs from local state`)]})]}),(0,q.jsx)(`div`,{className:`task-index-controls`,role:`group`,"aria-label":P(t,`Lọc task run`,`Filter task runs`),children:[[`all`,P(t,`Tất cả`,`All`)],[`current`,P(t,`Session này`,`This session`)],[`terminal`,P(t,`Đã kết thúc`,`Finished`)]].map(([e,t])=>(0,q.jsx)(`button`,{type:`button`,"aria-pressed":o===e,onClick:()=>s(e),children:t},e))}),i===`loading`&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Đang đọc task state bền vững…`,`Reading durable task state…`)}),(i===`error`||n?.state===`unavailable`)&&(0,q.jsx)(`p`,{className:`task-index-empty error-state`,children:P(t,`Task history chưa sẵn sàng; Pi session hiện tại không bị ảnh hưởng.`,`Task history is unavailable; the current Pi session is unaffected.`)}),i===`ready`&&n?.state===`ready`&&(0,q.jsxs)(`div`,{className:`task-run-list`,children:[E.map(e=>(0,q.jsxs)(`article`,{className:`task-run-card`,"data-active":e.isActive,"data-selected":e.runRef===c,children:[(0,q.jsxs)(`div`,{className:`task-run-main`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:e.summary||e.taskId}),e.isActive&&(0,q.jsx)(`span`,{className:`active-run-tag`,children:P(t,`Đang hoạt động`,`Active`)})]}),(0,q.jsxs)(`small`,{children:[e.taskId,` · `,P(t,`lần`,`attempt`),` `,e.attempt,`/`,e.maxAttempts,` · `,P(t,`cập nhật`,`updated`),` `,Wn(e.updatedAt,t)]})]}),(0,q.jsxs)(`div`,{className:`task-run-meta`,children:[(0,q.jsx)(Gn,{value:e.outcome,locale:t}),(0,q.jsx)(`span`,{children:e.progress.total?`${e.progress.completed}/${e.progress.total} ${P(t,`bước`,`steps`)}`:P(t,`Chưa có work plan`,`No work plan`)}),(0,q.jsx)(`span`,{children:e.sessionLabel??(e.isCurrentSession?P(t,`Session hiện tại`,`Current session`):P(t,`Session khác`,`Other session`))}),(0,q.jsx)(`button`,{type:`button`,"aria-pressed":e.runRef===c,onClick:()=>l(e.runRef),children:P(t,`Xem timeline`,`View timeline`)})]})]},e.runRef)),E.length===0&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Không có task run trong bộ lọc này.`,`No task runs match this filter.`)})]}),n?.warnings.map(e=>(0,q.jsx)(`p`,{className:`task-index-warning`,role:`status`,children:e.message},e.code)),n?.page.truncated&&(0,q.jsxs)(`p`,{className:`task-index-warning`,children:[P(t,`Danh sách đã rút gọn;`,`The list is truncated;`),` `,n.page.total-n.page.returned,` `,P(t,`run cũ chưa hiển thị.`,`older runs are not shown.`)]}),(0,q.jsxs)(`section`,{className:`task-timeline`,"aria-labelledby":`task-timeline-title`,children:[(0,q.jsxs)(`header`,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Recovery timeline`}),(0,q.jsx)(`h3`,{id:`task-timeline-title`,children:P(t,`Crash, resume, pause và checkpoint`,`Crash, resume, pause, and checkpoints`)})]}),u?.state===`ready`&&(0,q.jsx)(Gn,{value:u.continuity.recoveryDecision,locale:t})]}),f===`idle`&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Chọn một run để xem timeline.`,`Select a run to view its timeline.`)}),f===`loading`&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Đang xác minh chuỗi Task Journal…`,`Verifying the Task Journal chain…`)}),(f===`error`||u?.state===`unavailable`)&&(0,q.jsx)(`p`,{className:`task-index-empty error-state`,children:P(t,`Timeline không đủ bằng chứng tin cậy; task hiện tại không bị ảnh hưởng.`,`The timeline lacks trustworthy evidence; the current task is unaffected.`)}),f===`ready`&&u?.state===`ready`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`timeline-continuity`,children:[(0,q.jsxs)(`span`,{children:[`Crash evidence: `,(0,q.jsx)(`strong`,{children:L(u.continuity.crashEvidence,t)})]}),(0,q.jsxs)(`span`,{children:[`Recovery: `,(0,q.jsx)(`strong`,{children:L(u.continuity.recoveryDecision,t)})]})]}),(0,q.jsx)(`ol`,{className:`timeline-events`,children:u.events.map(e=>(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`timeline-dot tone-${Ue(e.state)}`,"aria-hidden":`true`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:e.title}),(0,q.jsxs)(`small`,{children:[`#`,e.sequence,` · `,Wn(e.recordedAt,t)]}),e.detail&&(0,q.jsx)(`p`,{children:e.detail})]}),(0,q.jsx)(Gn,{value:e.state,locale:t})]},e.eventRef))}),u.events.length===0&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Run này chưa có fact timeline bền vững.`,`This run has no durable timeline facts.`)})]}),u?.warnings.map(e=>(0,q.jsx)(`p`,{className:`task-index-warning`,role:`status`,children:e.message},e.code))]}),(0,q.jsxs)(`section`,{className:`task-timeline recovery-history`,"aria-labelledby":`recovery-history-title`,children:[(0,q.jsxs)(`header`,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Compaction & recovery`}),(0,q.jsx)(`h3`,{id:`recovery-history-title`,children:P(t,`Lịch sử rút gọn và phục hồi`,`Compaction and recovery history`)})]}),m?.state===`ready`&&(0,q.jsx)(Gn,{value:m.completeness,locale:t})]}),g===`idle`&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Chọn một run để xem lịch sử rút gọn.`,`Select a run to view compaction history.`)}),g===`loading`&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Đang đọc metadata compaction an toàn…`,`Reading safe compaction metadata…`)}),(g===`error`||m?.state===`unavailable`)&&(0,q.jsx)(`p`,{className:`task-index-empty error-state`,children:P(t,`Lịch sử compaction chưa đủ bằng chứng tin cậy; task hiện tại không bị ảnh hưởng.`,`Compaction history lacks trustworthy evidence; the current task is unaffected.`)}),g===`ready`&&m?.state===`ready`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`timeline-continuity recovery-summary`,children:[(0,q.jsxs)(`span`,{children:[`Context compact: `,(0,q.jsx)(`strong`,{children:m.summary.contextCompactions})]}),(0,q.jsxs)(`span`,{children:[`Tool result: `,(0,q.jsx)(`strong`,{children:m.summary.toolResultCompactions})]}),(0,q.jsxs)(`span`,{children:[`Recovery: `,(0,q.jsx)(`strong`,{children:L(m.recovery.decision,t)})]}),(0,q.jsxs)(`span`,{children:[`Verifier: `,(0,q.jsx)(`strong`,{children:L(m.recovery.verifierState,t)})]})]}),(0,q.jsx)(`p`,{className:`retained-content-note`,children:P(t,`Nội dung capture được giữ trong private runtime state và không gửi vào trình duyệt.`,`Captured content stays in private runtime state and is not sent to the browser.`)}),(0,q.jsx)(`ol`,{className:`timeline-events`,children:m.events.map(e=>(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`timeline-dot tone-${Ue(e.kind)}`,"aria-hidden":`true`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:e.title}),(0,q.jsxs)(`small`,{children:[`#`,e.sequence,` · `,Wn(e.recordedAt,t)]}),e.kind===`tool-result-compaction`&&(0,q.jsxs)(`p`,{children:[e.toolName,` · `,e.originalLines??`?`,` `,P(t,`dòng`,`lines`),` · `,e.captureCount,` capture`]}),e.detail&&(0,q.jsx)(`p`,{children:e.detail})]}),(0,q.jsx)(Gn,{value:`observed`,locale:t})]},e.eventRef))}),m.events.length===0&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Run này chưa có metadata compaction đã quan sát.`,`This run has no observed compaction metadata.`)})]}),m?.warnings.map(e=>(0,q.jsx)(`p`,{className:`task-index-warning`,role:`status`,children:e.message},e.code))]}),(0,q.jsxs)(`section`,{className:`task-timeline handoff-history`,"aria-labelledby":`handoff-history-title`,children:[(0,q.jsxs)(`header`,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Handoff`}),(0,q.jsx)(`h3`,{id:`handoff-history-title`,children:P(t,`Bàn giao và việc cần làm tiếp theo`,`Handoff and next work`)})]}),v?.state===`ready`&&(0,q.jsx)(Gn,{value:v.completeness,locale:t})]}),b===`idle`&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Chọn một run để xem handoff.`,`Select a run to view its handoff.`)}),b===`loading`&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Đang xác minh handoff và next action…`,`Verifying the handoff and next action…`)}),(b===`error`||v?.state===`unavailable`)&&(0,q.jsx)(`p`,{className:`task-index-empty error-state`,children:P(t,`Handoff không đủ bằng chứng tin cậy; WebUI không đề xuất hành động.`,`The handoff lacks trustworthy evidence; WebUI will not suggest an action.`)}),b===`ready`&&v?.state===`ready`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`next-action-card`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{children:P(t,`Việc tiếp theo`,`Next work`)}),(0,q.jsx)(`strong`,{children:L(v.nextAction.action,t)})]}),(0,q.jsx)(`p`,{children:v.nextAction.reason}),(0,q.jsxs)(`small`,{children:[v.nextAction.exactCommandCount,` verifier command · `,P(t,`chỉ xem, không tự chạy`,`read-only, never auto-run`)]})]}),v.current&&(0,q.jsxs)(`div`,{className:`timeline-continuity handoff-summary`,children:[(0,q.jsxs)(`span`,{children:[`Outcome: `,(0,q.jsx)(`strong`,{children:L(v.current.taskOutcome,t)})]}),(0,q.jsxs)(`span`,{children:[`Gate: `,(0,q.jsx)(`strong`,{children:L(v.current.gateDecision,t)})]}),(0,q.jsxs)(`span`,{children:[`Authority: `,(0,q.jsx)(`strong`,{children:L(v.current.requiredAuthority,t)})]}),(0,q.jsxs)(`span`,{children:[`Tree evidence: `,(0,q.jsx)(`strong`,{children:v.current.treeEvidenceCurrent?`current`:`not current`})]})]}),(0,q.jsx)(`ol`,{className:`timeline-events`,children:v.events.map(e=>(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`timeline-dot tone-${Ue(e.completionApproved?`completed`:`handoff`)}`,"aria-hidden":`true`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:P(t,`Handoff projection đã được ghi`,`Handoff projection recorded`)}),(0,q.jsxs)(`small`,{children:[`#`,e.sequence,` · `,Wn(e.recordedAt,t)]}),(0,q.jsxs)(`p`,{children:[e.phase??`unknown`,` · `,L(e.projectedAction,t)]})]}),(0,q.jsx)(Gn,{value:e.completionApproved?`completed`:`observed`,locale:t})]},e.eventRef))}),!v.current&&v.events.length===0&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Run này chưa có handoff đã quan sát.`,`This run has no observed handoff.`)})]}),v?.warnings.map(e=>(0,q.jsx)(`p`,{className:`task-index-warning`,role:`status`,children:e.message},e.code))]}),(0,q.jsxs)(`section`,{className:`task-timeline subagent-tree`,"aria-labelledby":`subagent-tree-title`,children:[(0,q.jsxs)(`header`,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Helper / subagent tree`}),(0,q.jsx)(`h3`,{id:`subagent-tree-title`,children:P(t,`Quyền sở hữu và vòng đời helper`,`Helper ownership and lifecycle`)})]}),S?.state===`ready`&&(0,q.jsx)(Gn,{value:S.evidenceState,locale:t})]}),w===`idle`&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Chọn một run để xem helper/subagent.`,`Select a run to view helpers and subagents.`)}),w===`loading`&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Đang xác minh helper ledger bền vững…`,`Verifying the durable helper ledger…`)}),(w===`error`||S?.state===`unavailable`)&&(0,q.jsx)(`p`,{className:`task-index-empty error-state`,children:P(t,`Helper ledger không đủ tin cậy; WebUI không suy đoán cây subagent.`,`The helper ledger lacks trustworthy evidence; WebUI will not infer a subagent tree.`)}),w===`ready`&&S?.state===`ready`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`next-action-card`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{children:P(t,`Quyết định điều phối`,`Delegation decision`)}),(0,q.jsx)(`strong`,{children:S.delegation.action===`dispatch`?P(t,`Gửi 1 helper chỉ đọc`,`Dispatch one read-only helper`):P(t,`Parent tự làm`,`Parent works directly`)})]}),(0,q.jsx)(`p`,{children:S.delegation.reasonCodes.map(e=>L(e,t)).join(` · `)}),(0,q.jsxs)(`small`,{children:[P(t,`Tiết kiệm token dự kiến`,`Projected net token saving`),`: `,S.delegation.projectedNetSavingsRatio===null?P(t,`chưa được chứng minh`,`not proven`):`${Math.round(S.delegation.projectedNetSavingsRatio*100)}%`,` · `,P(t,`ngưỡng`,`threshold`),` `,Math.round(S.delegation.minimumRequiredNetSavingsRatio*100),`% · `,P(t,`tối đa 1 helper, 0 retry, 0 writer`,`max 1 helper, 0 retries, 0 writers`)]})]}),(0,q.jsxs)(`div`,{className:`timeline-continuity subagent-summary`,children:[(0,q.jsxs)(`span`,{children:[P(t,`Tổng helper`,`Total helpers`),`: `,(0,q.jsx)(`strong`,{children:S.summary.total})]}),(0,q.jsxs)(`span`,{children:[P(t,`Đang chạy`,`Running`),`: `,(0,q.jsx)(`strong`,{children:S.summary.active})]}),(0,q.jsxs)(`span`,{children:[P(t,`Kết quả stale`,`Stale results`),`: `,(0,q.jsx)(`strong`,{children:S.summary.staleResults})]}),(0,q.jsxs)(`span`,{children:[P(t,`Writer hiện tại`,`Current writer`),`: `,(0,q.jsx)(`strong`,{children:L(S.writer.state,t)})]})]}),(0,q.jsx)(`p`,{className:`retained-content-note`,children:P(t,`Prompt, output, model và session ID của helper không được gửi vào trình duyệt.`,`Helper prompts, outputs, models, and session IDs are not sent to the browser.`)}),(0,q.jsx)(`ol`,{className:`timeline-events`,children:S.children.map(e=>(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`timeline-dot tone-${Ue(e.lifecycleState)}`,"aria-hidden":`true`}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`strong`,{children:[L(e.role,t),` · `,L(e.authority,t)]}),(0,q.jsxs)(`small`,{children:[Wn(e.reservedAt,t),` → `,e.completedAt?Wn(e.completedAt,t):P(t,`đang giữ lease`,`lease active`)]}),(0,q.jsxs)(`p`,{children:[e.result.disposition?L(e.result.disposition,t):P(t,`Chưa có result evidence`,`No result evidence`),e.result.calls===null?``:` · ${e.result.calls} calls · ${e.result.tokens??0} tokens`]})]}),(0,q.jsx)(Gn,{value:e.result.state===`not-recorded`?e.lifecycleState:e.result.state,locale:t})]},e.nodeRef))}),S.children.length===0&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Không có lifecycle helper chi tiết cho run này.`,`No detailed helper lifecycle is available for this run.`)}),(0,q.jsx)(`p`,{className:`retained-content-note`,children:P(t,`Cây lồng nhiều tầng: chưa có durable lineage; WebUI chỉ hiển thị quan hệ task cha → helper trực tiếp.`,`Nested trees: durable lineage is not yet available, so WebUI only shows parent task → direct helper relationships.`)})]}),S?.warnings.map(e=>(0,q.jsx)(`p`,{className:`task-index-warning`,role:`status`,children:e.message},e.code))]})]})}function qn(e,t){if(!e)return P(t,`Chưa có`,`Not available`);try{return new Intl.DateTimeFormat(t===`vi`?`vi-VN`:`en-US`,{dateStyle:`short`,timeStyle:`short`}).format(new Date(e))}catch{return e}}function Jn({value:e,locale:t}){return(0,q.jsxs)(`span`,{className:`status-pill tone-${Ue(e)}`,children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,className:`status-dot`}),L(e,t)]})}function Yn({snapshot:e}){let{locale:t}=N(),[n,r]=(0,W.useState)(),[i,a]=(0,W.useState)(`loading`),o=(0,W.useRef)(null),s=(0,W.useCallback)(()=>{o.current?.abort();let e=new AbortController;o.current=e,a(`loading`),F(e.signal).then(t=>{e.signal.aborted||(r(t),a(`ready`))}).catch(()=>{e.signal.aborted||a(`error`)})},[]);return(0,W.useEffect)(()=>(s(),()=>o.current?.abort()),[s,e.identity.projectRef,e.identity.runtimeInstanceId]),(0,q.jsxs)(`section`,{className:`release-monitor surface`,"aria-labelledby":`release-monitor-title`,children:[(0,q.jsxs)(`header`,{className:`source-heading`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Benchmark & release`}),(0,q.jsx)(`h2`,{id:`release-monitor-title`,children:P(t,`Theo dõi chất lượng và mức sẵn sàng phát hành`,`Quality and release readiness`)})]}),(0,q.jsx)(`button`,{type:`button`,onClick:s,disabled:i===`loading`,children:i===`loading`?P(t,`Đang đọc…`,`Loading…`):P(t,`Làm mới`,`Refresh`)})]}),(0,q.jsx)(`p`,{className:`retained-content-note`,children:P(t,`Màn hình chỉ đọc bằng chứng local; không tự chạy benchmark, resume, commit, tag, publish hay push.`,`This screen only reads local evidence; it never runs benchmarks, resumes, commits, tags, publishes, or pushes.`)}),(i===`error`||n?.state===`unavailable`)&&(0,q.jsx)(`p`,{className:`task-index-empty error-state`,children:P(t,`Bằng chứng benchmark/release chưa sẵn sàng; Pi session hiện tại không bị ảnh hưởng.`,`Benchmark and release evidence is unavailable; the current Pi session is unaffected.`)}),i===`loading`&&!n&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Đang xác minh report, manifest và ledger…`,`Verifying reports, manifests, and ledgers…`)}),n&&(0,q.jsxs)(`div`,{className:`release-monitor-grid`,children:[(0,q.jsxs)(`section`,{className:`release-monitor-column`,"aria-labelledby":`benchmark-monitor-title`,children:[(0,q.jsxs)(`header`,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Benchmark runs`}),(0,q.jsx)(`h3`,{id:`benchmark-monitor-title`,children:P(t,`Các lần đo gần đây`,`Recent runs`)})]}),(0,q.jsx)(Jn,{value:n.benchmark.state,locale:t})]}),n.benchmark.runs.map(e=>(0,q.jsxs)(`article`,{className:`benchmark-run-card`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`strong`,{children:e.suiteId}),(0,q.jsx)(Jn,{value:e.lifecycle,locale:t})]}),(0,q.jsxs)(`small`,{children:[qn(e.updatedAt,t),` · `,e.completedRuns,`/`,e.expectedRuns,` `,P(t,`lượt`,`runs`),` · `,P(t,`nguồn`,`source`),` `,L(e.sourceState,t)]}),(0,q.jsxs)(`div`,{className:`benchmark-run-facts`,children:[(0,q.jsxs)(`span`,{children:[`Gate `,(0,q.jsx)(`b`,{children:L(e.releaseGate,t)})]}),(0,q.jsxs)(`span`,{children:[P(t,`Điểm`,`Score`),` `,(0,q.jsx)(`b`,{children:e.scores.overall??`—`})]}),(0,q.jsxs)(`span`,{children:[`Claim `,(0,q.jsx)(`b`,{children:L(e.claimTier,t)})]})]})]},e.runRef)),n.benchmark.runs.length===0&&(0,q.jsx)(`p`,{className:`task-index-empty`,children:P(t,`Chưa có run thuộc repo hiện tại với bằng chứng đủ tin cậy.`,`No trustworthy runs are available for the current repository.`)}),n.benchmark.warnings.map(e=>(0,q.jsx)(`p`,{className:`task-index-warning`,role:`status`,children:e.message},e.code)),n.benchmark.page.truncated&&(0,q.jsx)(`p`,{className:`task-index-warning`,children:P(t,`Danh sách được giới hạn để giữ WebUI nhẹ và ổn định.`,`The list is bounded to keep WebUI fast and stable.`)})]}),(0,q.jsxs)(`section`,{className:`release-monitor-column`,"aria-labelledby":`release-readiness-title`,children:[(0,q.jsxs)(`header`,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Release readiness`}),(0,q.jsx)(`h3`,{id:`release-readiness-title`,children:P(t,`RC hiện tại`,`Current RC`)})]}),(0,q.jsx)(Jn,{value:n.release.state,locale:t})]}),(0,q.jsxs)(`dl`,{className:`release-readiness-facts`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Local safe gate`}),(0,q.jsx)(`dd`,{children:(0,q.jsx)(Jn,{value:n.release.localSafeGate,locale:t})})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`RC assembly`}),(0,q.jsx)(`dd`,{children:L(n.release.rcAssembly,t)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Beta`}),(0,q.jsx)(`dd`,{children:L(n.release.beta,t)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`GA`}),(0,q.jsx)(`dd`,{children:L(n.release.gaRelease,t)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:P(t,`Báo cáo`,`Report`)}),(0,q.jsx)(`dd`,{children:qn(n.release.generatedAt,t)})]})]}),n.release.sourceState===`stale`&&(0,q.jsx)(`p`,{className:`task-index-warning`,children:P(t,`Báo cáo RC thuộc phiên bản source cũ; không dùng để xác nhận tree hiện tại.`,`The RC report belongs to an older source revision and cannot validate the current tree.`)}),n.release.blockers.length>0&&(0,q.jsxs)(`div`,{className:`release-blockers`,children:[(0,q.jsxs)(`strong`,{children:[n.release.blockerCount,` blocker`]}),(0,q.jsx)(`ul`,{children:n.release.blockers.map((e,t)=>(0,q.jsx)(`li`,{children:e},`${t}-${e}`))})]}),(0,q.jsx)(`p`,{className:`retained-content-note`,children:P(t,`Mọi quyền phát hành đều tắt. Việc phát hành vẫn cần operator phê duyệt ngoài màn hình này.`,`All release authority is disabled. Release still requires operator approval outside this screen.`)})]})]})]})}var Xn=264,Zn={overview:{vi:[`Tổng quan`,`Task contract, tiến độ và bằng chứng hoàn thành`],en:[`Overview`,`Task contract, progress, and completion evidence`]},chat:{vi:[`Chat & điều khiển`,`Đúng Pi session hiện tại, không tạo runtime thứ hai`],en:[`Chat & controls`,`The exact current Pi session, without a second runtime`]},documents:{vi:[`Tài liệu`,`Mở .md, .docx, .pdf, .csv trong project và thư mục đã cấp quyền`],en:[`Documents`,`Open .md, .docx, .pdf, and .csv from the project and granted directories`]},source:{vi:[`Source Changes`,`Review thay đổi theo task baseline, working tree và staged`],en:[`Source Changes`,`Review task baseline, working tree, and staged changes`]},activity:{vi:[`Activity`,`Tool call, command, verifier và log preview`],en:[`Activity`,`Tool calls, commands, verifiers, and bounded log previews`]},history:{vi:[`Lịch sử task`,`Crash, resume, checkpoint, handoff và helper`],en:[`Task history`,`Crash, resume, checkpoints, handoffs, and helpers`]},release:{vi:[`Release`,`Benchmark evidence và mức sẵn sàng phát hành`],en:[`Release`,`Benchmark evidence and release readiness`]}};function Qn({value:e,text:t,locale:n=`vi`}){return(0,q.jsxs)(`span`,{className:`status-pill tone-${Ue(e)}`,children:[(0,q.jsx)(`span`,{"aria-hidden":`true`,className:`status-dot`}),t??L(e,n)]})}function $n({locale:e}){return(0,q.jsxs)(`section`,{className:`task-empty surface`,"aria-labelledby":`task-title`,children:[(0,q.jsx)(`div`,{className:`empty-mark`,"aria-hidden":`true`,children:`π`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Task contract`}),(0,q.jsx)(`h2`,{id:`task-title`,children:P(e,`Chưa có task đang chạy`,`No active task`)}),(0,q.jsx)(`p`,{children:P(e,`WebUI đang theo dõi đúng Pi session. Khi task bắt đầu, mục tiêu, tiêu chí và tiến độ sẽ xuất hiện tại đây.`,`WebUI is observing the exact Pi session. Objectives, criteria, and progress will appear here when a task begins.`)})]})]})}function er({snapshot:e,locale:t}){let n=e.task;if(!n)return(0,q.jsx)($n,{locale:t});let r=Ke(e,t);return(0,q.jsxs)(`section`,{className:`task-dashboard surface`,"aria-labelledby":`task-title`,children:[(0,q.jsxs)(`header`,{className:`task-heading`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:P(t,`Task hiện tại`,`Current task`)}),(0,q.jsx)(`h2`,{id:`task-title`,children:n.summary}),(0,q.jsxs)(`div`,{className:`task-meta`,children:[(0,q.jsx)(Qn,{value:n.outcome,locale:t}),(0,q.jsx)(`span`,{children:L(n.changeMode,t)}),(0,q.jsx)(`span`,{children:L(n.riskLane,t)})]})]}),(0,q.jsxs)(`div`,{className:`progress-number`,"aria-label":`${P(t,`Tiến độ`,`Progress`)} ${r.percent}%`,children:[(0,q.jsxs)(`strong`,{children:[r.percent,`%`]}),(0,q.jsx)(`span`,{children:r.text})]})]}),(0,q.jsx)(`div`,{className:`progress-track`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":r.percent,"aria-label":P(t,`Tiến độ tiêu chí`,`Criteria progress`),children:(0,q.jsx)(`span`,{style:{width:`${r.percent}%`}})}),n.blocker&&(0,q.jsxs)(`div`,{className:`blocker`,role:`status`,children:[(0,q.jsx)(`span`,{children:`Blocker`}),(0,q.jsx)(`p`,{children:n.blocker})]}),(0,q.jsxs)(`div`,{className:`criteria-heading`,children:[(0,q.jsx)(`h2`,{children:P(t,`Tiêu chí hoàn thành`,`Completion criteria`)}),(0,q.jsxs)(`span`,{children:[n.criteria.length,` `,P(t,`tiêu chí`,`criteria`)]})]}),(0,q.jsx)(`ol`,{className:`criteria-list`,children:n.criteria.map((e,n)=>(0,q.jsxs)(`li`,{className:`criterion-card`,children:[(0,q.jsx)(`span`,{className:`criterion-index tone-${Ue(e.state)}`,children:String(n+1).padStart(2,`0`)}),(0,q.jsxs)(`div`,{className:`criterion-copy`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{children:e.obligation}),e.priority===`critical`&&(0,q.jsx)(`span`,{className:`critical-tag`,children:P(t,`Quan trọng`,`Critical`)})]}),(0,q.jsx)(`small`,{children:Ge(e,t)})]}),(0,q.jsx)(Qn,{value:e.state,locale:t})]},e.criterionId))}),n.workPlan.length>0&&(0,q.jsxs)(`details`,{className:`work-plan`,children:[(0,q.jsxs)(`summary`,{children:[P(t,`Kế hoạch thực hiện`,`Work plan`),` · `,n.workPlan.length,` `,P(t,`bước`,`steps`)]}),(0,q.jsx)(`ol`,{children:n.workPlan.map(e=>(0,q.jsxs)(`li`,{children:[(0,q.jsx)(Qn,{value:e.status,locale:t}),(0,q.jsx)(`span`,{children:e.summary})]},e.stepId))})]})]})}function tr({snapshot:e,locale:t}){return(0,q.jsxs)(`aside`,{className:`context-rail`,"aria-label":P(t,`Tóm tắt phiên`,`Session summary`),children:[(0,q.jsxs)(`section`,{className:`surface compact-panel`,children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:`Task contract`}),(0,q.jsxs)(`dl`,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Task ID`}),(0,q.jsx)(`dd`,{title:e.identity.taskId??void 0,children:Je(e.identity.taskId)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Run ID`}),(0,q.jsx)(`dd`,{title:e.identity.taskRunId??void 0,children:Je(e.identity.taskRunId)})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Verifier`}),(0,q.jsx)(`dd`,{children:(0,q.jsx)(Qn,{value:e.verification.state,locale:t})})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`dt`,{children:`Queue`}),(0,q.jsx)(`dd`,{children:e.session.queue.state===`known`?`${e.session.queue.heldCount??0} ${P(t,`đang giữ`,`held`)}`:L(e.session.queue.state,t)})]})]})]}),(0,q.jsxs)(`section`,{className:`surface compact-panel`,children:[(0,q.jsx)(`p`,{className:`section-kicker`,children:P(t,`Sức khỏe`,`Health`)}),(0,q.jsxs)(`div`,{className:`health-line`,children:[(0,q.jsx)(Qn,{value:e.health.state,locale:t}),(0,q.jsxs)(`span`,{children:[e.health.issues.length,` `,P(t,`lưu ý`,`issues`)]})]}),e.health.issues.slice(0,3).map(e=>(0,q.jsx)(`p`,{className:`health-issue`,children:e.message},e.issueRef))]})]})}function nr({snapshot:e,locale:t}){let n=[[`Runtime`,(0,q.jsx)(Qn,{value:e.session.operation.liveness,locale:t})],[`Task`,(0,q.jsx)(Qn,{value:e.session.controlState,locale:t})],[`Model`,(0,q.jsx)(`strong`,{children:We(e,t)})],[`Thinking`,(0,q.jsx)(`strong`,{children:qe(e,t)})],[P(t,`Quyền`,`Permission`),(0,q.jsx)(`strong`,{children:I(e,t)})],[`Approval`,(0,q.jsx)(Qn,{value:e.session.approvalState,locale:t})]];return(0,q.jsx)(_,{variant:`outlined`,className:`runtime-overview`,"aria-label":P(t,`Trạng thái Pi session`,`Pi session status`),sx:{display:`grid`,gridTemplateColumns:{xs:`repeat(2, minmax(0,1fr))`,sm:`repeat(3, minmax(0,1fr))`,xl:`repeat(6, minmax(0,1fr))`},overflow:`hidden`},children:n.map(([e,t])=>(0,q.jsxs)(h,{sx:{minWidth:0,minHeight:72,px:2,py:1.5,display:`flex`,flexDirection:`column`,justifyContent:`center`,gap:.75,borderRight:1,borderBottom:{xs:1,xl:0},borderColor:`divider`,"&:last-child":{borderRight:0}},children:[(0,q.jsx)(c,{variant:`caption`,color:`text.disabled`,sx:{fontWeight:650,letterSpacing:`.11em`,textTransform:`uppercase`},children:e}),t]},e))})}function rr({active:e,snapshot:t,events:n,refreshSnapshot:r,locale:i}){return e===`overview`?(0,q.jsxs)(f,{className:`workspace-stack`,spacing:2.25,children:[(0,q.jsx)(nr,{snapshot:t,locale:i}),(0,q.jsxs)(h,{sx:{display:`grid`,gridTemplateColumns:{xs:`1fr`,lg:`minmax(0,1fr) 300px`},alignItems:`start`,gap:2.25},children:[(0,q.jsx)(er,{snapshot:t,locale:i}),(0,q.jsx)(tr,{snapshot:t,locale:i})]}),(0,q.jsx)(Ln,{snapshot:t})]}):e===`chat`?(0,q.jsxs)(f,{className:`workspace-stack`,spacing:2.25,children:[(0,q.jsx)(Un,{snapshot:t,refreshSnapshot:r}),(0,q.jsx)(zn,{snapshot:t,refreshSnapshot:r}),(0,q.jsx)(Rn,{snapshot:t,events:n,refreshSnapshot:r})]}):e===`documents`?(0,q.jsx)(An,{}):e===`source`?(0,q.jsx)(sn,{snapshot:t,refreshSnapshot:r}):e===`activity`?(0,q.jsx)(He,{snapshot:t}):e===`history`?(0,q.jsx)(Kn,{snapshot:t}):(0,q.jsx)(Yn,{snapshot:t})}function ir({snapshot:e,connection:t=`connecting`,events:n=[],refreshSnapshot:r}){let{locale:i,colorMode:o,setLocale:s,setColorMode:d}=N(),[_,v]=(0,W.useState)(`overview`),[k,ne]=(0,W.useState)(!1);if(!e)return(0,q.jsxs)(h,{className:`loading-shell`,children:[(0,q.jsx)(h,{className:`brand-mark`,"aria-hidden":`true`,children:`π`}),(0,q.jsx)(`p`,{className:`section-kicker`,children:`Piagent WebUI · local`}),(0,q.jsx)(c,{variant:`h1`,children:t===`failed`?P(i,`Không thể nối vào Pi session`,`Unable to connect to the Pi session`):P(i,`Đang mở không gian làm việc`,`Opening the workspace`)}),(0,q.jsx)(c,{color:`text.secondary`,children:t===`failed`?P(i,`Hãy mở lại WebUI từ Pi terminal để tạo phiên local mới.`,`Reopen WebUI from the Pi terminal to create a new local session.`):P(i,`Đang tải task contract và trạng thái runtime hiện tại…`,`Loading the task contract and current runtime state…`)}),t!==`failed`&&(0,q.jsx)(g,{size:22}),(0,q.jsx)(Qn,{value:t,locale:i})]});let oe=Zn[_][i],ce=(e.sourceChanges.task?.counts.files??0)+e.sourceChanges.workingTree.counts.files+e.sourceChanges.staged.counts.files,le=[{id:`overview`,label:P(i,`Tổng quan`,`Overview`),icon:(0,q.jsx)(O,{})},{id:`chat`,label:P(i,`Chat & Task`,`Chat & Task`),icon:(0,q.jsx)(b,{}),count:e.session.queue.heldCount??0},{id:`documents`,label:P(i,`Tài liệu`,`Documents`),icon:(0,q.jsx)(j,{})},{id:`source`,label:`Source Changes`,icon:(0,q.jsx)(u,{}),count:ce},{id:`activity`,label:`Activity`,icon:(0,q.jsx)(l,{}),count:e.activity.running.length},{id:`history`,label:P(i,`Lịch sử`,`History`),icon:(0,q.jsx)(E,{})},{id:`release`,label:`Release`,icon:(0,q.jsx)(te,{})}],ue=e=>{v(e),ne(!1)},F=(0,q.jsxs)(h,{sx:{height:`100%`,display:`flex`,flexDirection:`column`},children:[(0,q.jsxs)(C,{sx:{minHeight:`72px !important`,px:`18px !important`,gap:1.25},children:[(0,q.jsx)(h,{className:`brand-mark`,"aria-hidden":`true`,children:`π`}),(0,q.jsxs)(h,{sx:{minWidth:0},children:[(0,q.jsx)(c,{sx:{fontWeight:650,lineHeight:1.15},children:`Piagent`}),(0,q.jsx)(c,{variant:`caption`,color:`text.disabled`,children:`WebUI · local`})]})]}),(0,q.jsxs)(h,{sx:{mx:1.5,mb:1.25,p:1.35,border:1,borderColor:`divider`,borderRadius:1,bgcolor:`action.hover`},children:[(0,q.jsx)(c,{variant:`caption`,color:`text.disabled`,sx:{display:`block`,textTransform:`uppercase`,letterSpacing:`.09em`},children:P(i,`Pi session hiện tại`,`Current Pi session`)}),(0,q.jsx)(c,{variant:`body2`,noWrap:!0,title:e.session.displayName??void 0,sx:{mt:.45,fontWeight:650},children:e.session.displayName??`Pi session`}),(0,q.jsx)(c,{variant:`caption`,color:`text.secondary`,title:e.identity.sessionRef,children:Je(e.identity.sessionRef)})]}),(0,q.jsx)(c,{variant:`caption`,color:`text.disabled`,sx:{px:2.5,pt:1,pb:.5,fontWeight:650,letterSpacing:`.1em`,textTransform:`uppercase`},children:P(i,`Không gian làm việc`,`Workspaces`)}),(0,q.jsx)(se,{component:`nav`,"aria-label":P(i,`Điều hướng WebUI`,`WebUI navigation`),sx:{py:.5},children:le.map(e=>(0,q.jsxs)(A,{selected:_===e.id,"aria-current":_===e.id?`page`:void 0,onClick:()=>ue(e.id),children:[(0,q.jsx)(T,{sx:{minWidth:36,color:`inherit`,"& .MuiSvgIcon-root":{fontSize:19}},children:e.icon}),(0,q.jsx)(re,{primary:e.label,slotProps:{primary:{sx:{fontSize:13,fontWeight:_===e.id?750:600}}}}),!!e.count&&(0,q.jsx)(x,{badgeContent:e.count,color:e.id===`activity`?`secondary`:`primary`,max:99,sx:{mr:1}})]},e.id))}),(0,q.jsxs)(h,{sx:{mt:`auto`,p:1.5},children:[(0,q.jsx)(ie,{sx:{mb:1.5}}),(0,q.jsxs)(f,{direction:`row`,spacing:1,sx:{alignItems:`center`},children:[(0,q.jsxs)(ae,{exclusive:!0,size:`small`,value:i,"aria-label":P(i,`Ngôn ngữ`,`Language`),onChange:(e,t)=>t&&s(t),sx:{flex:1},children:[(0,q.jsx)(S,{value:`vi`,"aria-label":`Tiếng Việt`,sx:{flex:1},children:`VI`}),(0,q.jsx)(S,{value:`en`,"aria-label":`English`,sx:{flex:1},children:`EN`})]}),(0,q.jsx)(ee,{title:o===`dark`?P(i,`Chuyển sang giao diện sáng`,`Use light mode`):P(i,`Chuyển sang giao diện tối`,`Use dark mode`),children:(0,q.jsx)(m,{"aria-label":o===`dark`?P(i,`Dùng giao diện sáng`,`Use light mode`):P(i,`Dùng giao diện tối`,`Use dark mode`),onClick:()=>d(o===`dark`?`light`:`dark`),sx:{border:1,borderColor:`divider`,borderRadius:1},children:o===`dark`?(0,q.jsx)(y,{fontSize:`small`}):(0,q.jsx)(w,{fontSize:`small`})})})]})]})]});return(0,q.jsxs)(h,{className:`app-shell`,"data-contract":`snapshot-v1`,children:[(0,q.jsx)(`a`,{className:`skip-link`,href:`#main-content`,children:P(i,`Bỏ qua điều hướng`,`Skip navigation`)}),(0,q.jsx)(p,{position:`fixed`,color:`transparent`,elevation:0,sx:{width:{md:`calc(100% - ${Xn}px)`},ml:{md:`${Xn}px`},borderBottom:1,borderColor:`divider`,bgcolor:`rgba(var(--piagent-palette-background-defaultChannel) / .88)`,backdropFilter:`blur(18px)`},children:(0,q.jsxs)(C,{sx:{minHeight:`72px !important`,gap:1.5},children:[(0,q.jsx)(m,{edge:`start`,"aria-label":P(i,`Mở menu`,`Open menu`),onClick:()=>ne(!0),sx:{display:{md:`none`}},children:(0,q.jsx)(a,{})}),(0,q.jsxs)(h,{sx:{minWidth:0,flex:1},children:[(0,q.jsx)(c,{component:`h1`,variant:`h2`,noWrap:!0,children:oe[0]}),(0,q.jsx)(c,{variant:`caption`,color:`text.secondary`,noWrap:!0,sx:{display:{xs:`none`,sm:`block`}},children:oe[1]})]}),(0,q.jsxs)(f,{direction:`row`,spacing:1,sx:{alignItems:`center`},"aria-live":`polite`,children:[(0,q.jsx)(M,{variant:`outlined`,size:`small`,color:t===`connected`?`success`:`default`,label:t===`connected`?`Live`:L(t,i)}),e.approvals.pending.length>0&&(0,q.jsx)(M,{color:`warning`,size:`small`,label:`${e.approvals.pending.length} approval`}),(0,q.jsx)(M,{variant:`outlined`,size:`small`,sx:{display:{xs:`none`,sm:`flex`}},label:e.capabilities.capabilities[`control.chat`].status===`available`?P(i,`Chat bật`,`Chat enabled`):P(i,`Chỉ xem`,`Read only`)})]})]})}),(0,q.jsxs)(h,{component:`nav`,"aria-label":P(i,`Sidebar chính`,`Primary sidebar`),sx:{width:{md:Xn},flexShrink:{md:0}},children:[(0,q.jsx)(D,{variant:`temporary`,open:k,onClose:()=>ne(!1),ModalProps:{keepMounted:!0},sx:{display:{xs:`block`,md:`none`},"& .MuiDrawer-paper":{width:Xn}},children:F}),(0,q.jsx)(D,{variant:`permanent`,open:!0,sx:{display:{xs:`none`,md:`block`},"& .MuiDrawer-paper":{width:Xn,borderRight:1,borderColor:`divider`,bgcolor:`background.paper`}},children:F})]}),(0,q.jsx)(h,{component:`main`,id:`main-content`,sx:{ml:{md:`${Xn}px`},minWidth:0,pt:`72px`},children:(0,q.jsxs)(h,{className:`workspace-view workspace-${_}`,sx:{width:`100%`,maxWidth:_===`source`?`none`:1580,mx:`auto`,p:{xs:1.5,sm:2.5,lg:3}},children:[e.approvals.pending.length>0&&(0,q.jsx)(h,{sx:{mb:2.25},children:(0,q.jsx)(et,{snapshot:e,refreshSnapshot:r})}),(0,q.jsx)(rr,{active:_,snapshot:e,events:n,refreshSnapshot:r,locale:i})]})})]})}export{An as a,Ln as i,nr as n,sn as o,er as r,ir as t};