@piagent/platform 1.40.0 → 1.42.0

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 (124) hide show
  1. package/CHANGELOG.md +1012 -2035
  2. package/CONTRIBUTING.md +2 -0
  3. package/README.md +128 -325
  4. package/README.vi.md +149 -143
  5. package/architecture/layers.json +10 -0
  6. package/docs/command-reference-vietnamese.md +2 -2
  7. package/docs/distribution-standard.md +6 -6
  8. package/docs/en/architecture.md +1 -0
  9. package/docs/languages.json +4 -4
  10. package/docs/operator-manual-vietnamese.md +7 -7
  11. package/docs/publishing-for-teams.md +2 -0
  12. package/docs/release-install-policy.md +3 -3
  13. package/docs/team-onboarding.md +2 -2
  14. package/docs/vi/architecture.md +1 -0
  15. package/docs-site/architecture.html +71 -63
  16. package/docs-site/assets/docs.css +2736 -1030
  17. package/docs-site/assets/docs.js +451 -43
  18. package/docs-site/assets/og.png +0 -0
  19. package/docs-site/assets/piagent-logo.svg +9 -31
  20. package/docs-site/assets/search-en.json +1 -0
  21. package/docs-site/assets/search-vi.json +1 -0
  22. package/docs-site/benchmark.html +71 -63
  23. package/docs-site/commands.html +72 -64
  24. package/docs-site/content/en/index.html +220 -131
  25. package/docs-site/content/en/quickstart.html +74 -90
  26. package/docs-site/content/en/update.html +80 -0
  27. package/docs-site/content/en/whats-new.html +1 -678
  28. package/docs-site/content/index.html +220 -131
  29. package/docs-site/content/quickstart.html +73 -108
  30. package/docs-site/content/update.html +80 -0
  31. package/docs-site/content/whats-new.html +1 -678
  32. package/docs-site/context-engine.html +73 -65
  33. package/docs-site/ecosystem.html +73 -65
  34. package/docs-site/en/architecture.html +67 -59
  35. package/docs-site/en/benchmark.html +67 -59
  36. package/docs-site/en/commands.html +68 -60
  37. package/docs-site/en/context-engine.html +68 -60
  38. package/docs-site/en/ecosystem.html +68 -60
  39. package/docs-site/en/index.html +281 -220
  40. package/docs-site/en/mcp-approval.html +67 -59
  41. package/docs-site/en/mcp-auth.html +67 -59
  42. package/docs-site/en/mcp-servers.html +68 -60
  43. package/docs-site/en/mcp.html +64 -56
  44. package/docs-site/en/permissions.html +68 -60
  45. package/docs-site/en/profiles.html +68 -60
  46. package/docs-site/en/quickstart.html +142 -150
  47. package/docs-site/en/runtime.html +67 -59
  48. package/docs-site/en/scope.html +68 -60
  49. package/docs-site/en/security.html +64 -56
  50. package/docs-site/en/team.html +67 -59
  51. package/docs-site/en/update.html +228 -0
  52. package/docs-site/en/whats-new.html +1601 -719
  53. package/docs-site/en/windows.html +71 -63
  54. package/docs-site/en/workflows.html +68 -60
  55. package/docs-site/favicon.svg +9 -14
  56. package/docs-site/index.html +281 -220
  57. package/docs-site/mcp-approval.html +70 -62
  58. package/docs-site/mcp-auth.html +70 -62
  59. package/docs-site/mcp-servers.html +71 -63
  60. package/docs-site/mcp.html +70 -62
  61. package/docs-site/permissions.html +72 -64
  62. package/docs-site/profiles.html +72 -64
  63. package/docs-site/quickstart.html +145 -172
  64. package/docs-site/releases.json +4449 -0
  65. package/docs-site/runtime.html +73 -65
  66. package/docs-site/scope.html +73 -65
  67. package/docs-site/security.html +73 -65
  68. package/docs-site/team.html +71 -63
  69. package/docs-site/update.html +228 -0
  70. package/docs-site/whats-new.html +1605 -723
  71. package/docs-site/windows.html +75 -67
  72. package/docs-site/workflows.html +73 -65
  73. package/evals/fixtures/piagent-webui/document-asset-v1.invalid.json +12 -0
  74. package/evals/fixtures/piagent-webui/document-asset-v1.valid.json +12 -0
  75. package/evals/private-holdout-v1/public-exposure.v2.json +2 -2
  76. package/package.json +1 -1
  77. package/packages/piagent-core/package.json +1 -1
  78. package/packages/piagent-core/runtime/inspection/document-workspace-projection.ts +78 -15
  79. package/packages/piagent-core/skills/fe-change-report/SKILL.md +175 -0
  80. package/packages/piagent-core/skills/fe-change-report/scripts/build-report.mjs +183 -0
  81. package/packages/piagent-core/skills/fe-change-report/scripts/capture.mjs +150 -0
  82. package/packages/piagent-core/skills/fe-change-report/scripts/diff-regions.mjs +110 -0
  83. package/packages/piagent-webui/dist/client/assets/App-DBx4BU3F.js +5 -0
  84. package/packages/piagent-webui/dist/client/assets/LineReview-DzonwD-g.js +3 -0
  85. package/packages/piagent-webui/dist/client/assets/{MarkdownMessage-BpoF2k2-.js → MarkdownMessage-DchODuO7.js} +2 -2
  86. package/packages/piagent-webui/dist/client/assets/SessionInspectorDrawer-BHHNlct3.js +1 -0
  87. package/packages/piagent-webui/dist/client/assets/SettingsPage-DX28MsZA.js +1 -0
  88. package/packages/piagent-webui/dist/client/assets/TerminalPanel-C--BiN0p.js +2 -0
  89. package/packages/piagent-webui/dist/client/assets/{TerminalView-Dw9xqakv.js → TerminalView-BML7uS6R.js} +3 -3
  90. package/packages/piagent-webui/dist/client/assets/WorkspaceCodeEditor-B7ieqDnt.js +2 -0
  91. package/packages/piagent-webui/dist/client/assets/WorkspaceExplorer-BOafuPU-.js +5 -0
  92. package/packages/piagent-webui/dist/client/assets/WorkspaceQuickOpen-CGoGfUPk.js +1 -0
  93. package/packages/piagent-webui/dist/client/assets/api-BUjrtT1B.js +1 -0
  94. package/packages/piagent-webui/dist/client/assets/index-C7Azrwpq.js +132 -0
  95. package/packages/piagent-webui/dist/client/assets/index-Dqb2hNan.css +1 -0
  96. package/packages/piagent-webui/dist/client/assets/tab-close-Crj8vsUq.js +1 -0
  97. package/packages/piagent-webui/dist/client/assets/ui-preferences-B3UfDp-5.js +1 -0
  98. package/packages/piagent-webui/dist/client/assets/vendor-Ch5hIe0W.js +136 -0
  99. package/packages/piagent-webui/dist/client/index.html +5 -8
  100. package/packages/piagent-webui/extension/piagent-webui.ts +1 -0
  101. package/packages/piagent-webui/server/core-inspection-provider.ts +5 -0
  102. package/packages/piagent-webui/server/ipc-read-model-client.ts +1 -0
  103. package/packages/piagent-webui/server/read-model-provider.ts +1 -0
  104. package/packages/piagent-webui/server/read-only-router.ts +6 -0
  105. package/schemas/piagent-webui/catalog-v1.json +9 -0
  106. package/schemas/piagent-webui/document-asset-v1.schema.json +57 -0
  107. package/scripts/build-docs-site.mjs +205 -348
  108. package/scripts/check-public-wording.mjs +2 -1
  109. package/scripts/docs-site-icons.mjs +84 -0
  110. package/scripts/docs-site-nav.mjs +302 -0
  111. package/scripts/docs-site-releases.mjs +227 -0
  112. package/packages/piagent-webui/dist/client/assets/Alert-DGWhP2MM.js +0 -1
  113. package/packages/piagent-webui/dist/client/assets/Button-QItfZUNj.js +0 -1
  114. package/packages/piagent-webui/dist/client/assets/DialogTitle-CyaFPaiW.js +0 -3
  115. package/packages/piagent-webui/dist/client/assets/TerminalPanel-Dg3eghy4.js +0 -2
  116. package/packages/piagent-webui/dist/client/assets/Typography-B9om7Evq.js +0 -1
  117. package/packages/piagent-webui/dist/client/assets/WorkspaceCodeEditor-DtwXZAgK.js +0 -2
  118. package/packages/piagent-webui/dist/client/assets/WorkspaceExplorer-WS-yLlnb.js +0 -5
  119. package/packages/piagent-webui/dist/client/assets/WorkspaceQuickOpen-CYCY-s44.js +0 -1
  120. package/packages/piagent-webui/dist/client/assets/index-BgJgso6j.js +0 -102
  121. package/packages/piagent-webui/dist/client/assets/index-Brs_HjIo.css +0 -1
  122. package/packages/piagent-webui/dist/client/assets/tab-close-CqPDs-w5.js +0 -1
  123. package/packages/piagent-webui/dist/client/assets/ui-preferences-BO3AV7QE.js +0 -10
  124. package/packages/piagent-webui/dist/client/assets/useId-DEefKUAT.js +0 -124
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-C2TMLUTo.js","assets/rolldown-runtime-hePW80VL.js","assets/dist-D6i5SpQu.js","assets/dist-IRUjhd1P.js","assets/dist-sNhoSseW.js","assets/dist-BM_LL1o9.js","assets/dist-DfjUS8LS.js","assets/dist-CqL3udNu.js","assets/dist-D4df0jLQ.js","assets/dist-B5MCHZv5.js"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Bt as t,Dn as n,In as r,Ut as i,ln as a,yn as o}from"./vendor-Ch5hIe0W.js";import{i as s,n as c,r as l}from"./ui-preferences-B3UfDp-5.js";import{P as u}from"./index-C7Azrwpq.js";import{C as d,D as f,E as p,G as m,N as h,O as g,S as _,T as v,j as y,k as b,t as x,w as S,x as C,y as w,z as T}from"./dist-D6i5SpQu.js";var E=class extends S{lines;label;comment;constructor(e,t,n){super(),this.lines=e,this.label=t,this.comment=n}toDOM(){let e=document.createElement(`div`);e.className=`cm-agent-deleted`;for(let t of this.lines){let n=document.createElement(`div`),r=document.createElement(`span`);if(r.textContent=`− ${t.text}`,n.append(r),this.comment){let e=document.createElement(`button`);e.type=`button`,e.textContent=this.label,e.setAttribute(`aria-label`,`${this.label} ${t.line}`),e.addEventListener(`click`,()=>this.comment?.(t.line,t.text,`old`)),n.append(e)}e.append(n)}return e}},D=class extends S{ref;label;keep;revertLabel;revert;constructor(e,t,n,r,i){super(),this.ref=e,this.label=t,this.keep=n,this.revertLabel=r,this.revert=i}toDOM(){let e=document.createElement(`div`);e.className=`cm-agent-actions`;let t=document.createElement(`button`);if(t.type=`button`,t.textContent=this.label,t.addEventListener(`click`,()=>this.keep(this.ref)),e.append(t),this.revert){let t=document.createElement(`button`);t.type=`button`,t.textContent=this.revertLabel,t.addEventListener(`click`,()=>this.revert?.(this.ref)),e.append(t)}return e}},O=new class extends d{toDOM(){let e=document.createElement(`span`);return e.textContent=`▎`,e.className=`cm-agent-marker`,e}};function k(e,t,n,r,i,a,o=``,s){let c=e.state.doc.toString(),l=[],u=[],d=t=>e.state.doc.line(Math.max(1,Math.min(e.state.doc.lines,t))).from;for(let e of t){let t=d(e.newStart+ +(e.newLineCount===0));u.push(t),l.push(C.widget({widget:new D(e.hunkRef,n,r,i,a),block:!0,side:-1}).range(t));let c=e.newStart+ +(e.newLineCount===0),f=[],p=()=>{f.length&&(l.push(C.widget({widget:new E(f,o,s),block:!0,side:-1}).range(d(c))),f=[])};for(let t of e.lines){if(t.kind===`deleted`){t.oldLineNumber!==null&&f.push({line:t.oldLineNumber,text:t.text});continue}p(),t.newLineNumber!==null&&(c=t.newLineNumber+1,t.kind===`added`&&l.push(C.line({class:`cm-agent-added`}).range(d(t.newLineNumber))))}p()}let f=T.define({create:()=>C.set(l,!0),update:(e,t)=>t.docChanged?C.none:e,provide:e=>_.decorations.from(e)}),p=e=>t=>{if(!u.length||t.state.doc.toString()!==c)return!1;let n=t.state.selection.main.head,r=e>0?u.find(e=>e>n)??u[0]:[...u].reverse().find(e=>e<n)??u.at(-1);return t.dispatch({selection:{anchor:r},effects:_.scrollIntoView(r,{y:`center`})}),!0};return[f,t.length?v({class:`cm-agent-gutter`,lineMarker:(e,t)=>e.state.field(f).size&&u.includes(t.from)?O:null}):[],g.of([{key:`Alt-ArrowDown`,run:p(1)},{key:`Alt-ArrowUp`,run:p(-1)}]),_.theme({".cm-agent-added":{backgroundColor:`color-mix(in srgb, #2e9d55 15%, transparent)`},".cm-agent-deleted":{margin:`0`,padding:`2px 8px`,whiteSpace:`pre-wrap`,backgroundColor:`color-mix(in srgb, #df4545 15%, transparent)`,fontFamily:`monospace`},".cm-agent-marker":{color:`#2e9d55`},".cm-agent-actions":{padding:`2px 8px`},".cm-agent-actions button":{color:`inherit`,background:`transparent`,border:`1px solid currentColor`,borderRadius:`4px`,cursor:`pointer`}})]}var A=e(r(),1),j=n();function M({syntax:e}){return x.define([{tag:[m.keyword,m.controlKeyword,m.moduleKeyword,m.definitionKeyword,m.modifier,m.self,m.null,m.bool,m.atom],color:e.keyword},{tag:[m.string,m.special(m.string),m.regexp,m.character],color:e.string},{tag:[m.number,m.integer,m.float,m.unit],color:e.number},{tag:[m.comment,m.lineComment,m.blockComment,m.docComment,m.meta],color:e.comment,fontStyle:`italic`},{tag:[m.function(m.variableName),m.function(m.propertyName),m.macroName],color:e.function},{tag:[m.typeName,m.className,m.namespace,m.tagName,m.standard(m.tagName)],color:e.type},{tag:[m.propertyName,m.attributeName,m.labelName],color:e.property},{tag:[m.operator,m.punctuation,m.bracket,m.derefOperator],color:e.operator},{tag:[m.heading,m.heading1,m.heading2,m.heading3],color:e.heading,fontWeight:`600`},{tag:[m.link,m.url],color:e.link,textDecoration:`underline`},{tag:m.emphasis,fontStyle:`italic`},{tag:m.strong,fontWeight:`600`},{tag:m.invalid,color:e.keyword,textDecoration:`underline wavy`}])}async function N(e){let t=e.split(`.`).at(-1)?.toLowerCase();switch(t){case`js`:case`mjs`:case`cjs`:case`jsx`:case`ts`:case`tsx`:return(await u(async()=>{let{javascript:e}=await import(`./dist-C2TMLUTo.js`).then(e=>e.t);return{javascript:e}},__vite__mapDeps([0,1,2,3,4]))).javascript({typescript:t===`ts`||t===`tsx`,jsx:t===`jsx`||t===`tsx`});case`json`:return(await u(async()=>{let{json:e}=await import(`./dist-BM_LL1o9.js`);return{json:e}},__vite__mapDeps([5,2,3]))).json();case`md`:return(await u(async()=>{let{markdown:e}=await import(`./dist-DfjUS8LS.js`);return{markdown:e}},__vite__mapDeps([6,2,4,7,3,8,1,0]))).markdown();case`py`:return(await u(async()=>{let{python:e}=await import(`./dist-B5MCHZv5.js`);return{python:e}},__vite__mapDeps([9,2,3,4]))).python();case`html`:return(await u(async()=>{let{html:e}=await import(`./dist-CqL3udNu.js`);return{html:e}},__vite__mapDeps([7,2,3,8,1,0,4]))).html();case`css`:return(await u(async()=>{let{css:e}=await import(`./dist-D4df0jLQ.js`).then(e=>e.r);return{css:e}},__vite__mapDeps([8,1,2,3]))).css();default:return[]}}var P=[],F=e=>{};function I({content:e,path:n,line:r=1,readOnly:u=!0,onChange:d,onSave:m,hunks:v=P,onKeep:x=F,onRevert:S,onComment:C}){let T=(0,A.useRef)(null),E=(0,A.useRef)(null),D=a(),O=(0,A.useRef)({onChange:d,onSave:m,onComment:C});O.current={onChange:d,onSave:m,onComment:C};let I=(0,A.useRef)(e);I.current=e;let L=(0,A.useRef)(new y),R=(0,A.useRef)(new y),{locale:z}=s(),B=l();return(0,A.useEffect)(()=>{if(!T.current)return;let e=document.querySelector(`meta[name="csp-nonce"]`)?.content,t=new y,r=!1,i=new _({parent:T.current,state:h.create({doc:I.current,extensions:[R.current.of([]),_.cspNonce.of(e??``),L.current.of([h.readOnly.of(u),_.editable.of(!u)]),g.of([{key:`Mod-Shift-m`,run:e=>{let t=e.state.doc.lineAt(e.state.selection.main.head);return O.current.onComment?.(t.number,t.text),!!O.current.onComment}}]),g.of([`Ctrl-s`,`Meta-s`].map(e=>({key:e,run:()=>(O.current.onSave?.(),!0)}))),_.updateListener.of(e=>{e.docChanged&&O.current.onChange?.(e.state.doc.toString())}),b(),p(),f(),w(M(B)),t.of([]),_.contentAttributes.of({"aria-label":n,tabindex:`0`}),_.theme({"&":{height:`100%`,color:D.palette.text.primary,backgroundColor:D.palette.background.paper},".cm-scroller":{overflow:`auto`,fontFamily:`ui-monospace, SFMono-Regular, Menlo, Consolas, monospace`,fontSize:`13px`,lineHeight:1.55},".cm-content":{caretColor:D.palette.primary.main},".cm-cursor, .cm-dropCursor":{borderLeftColor:D.palette.primary.main},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:o(D.palette.primary.main,.25)},".cm-activeLine":{backgroundColor:o(D.palette.text.primary,.04)},".cm-gutters":{backgroundColor:D.palette.background.paper,color:D.palette.text.secondary,borderRight:`1px solid ${D.palette.divider}`},".cm-activeLineGutter":{backgroundColor:o(D.palette.text.primary,.06),color:D.palette.text.primary}},{dark:D.palette.mode===`dark`})]})});return E.current=i,N(n).then(e=>{r||i.dispatch({effects:t.reconfigure(e)})}).catch(()=>{}),()=>{r=!0,E.current=null,i.destroy()}},[n,D]),(0,A.useEffect)(()=>{let t=E.current;t&&t.state.doc.toString()!==e&&t.dispatch({changes:{from:0,to:t.state.doc.length,insert:e}})},[e,n,D]),(0,A.useEffect)(()=>{let e=E.current;e&&e.dispatch({effects:R.current.reconfigure(k(e,v,c(z,`Giữ`,`Keep`),x,c(z,`Hoàn tác`,`Revert`),S,c(z,`Comment dòng đã xóa`,`Comment on removed line`),C))})},[v,x,S,C,e,n,D,z]),(0,A.useEffect)(()=>{E.current?.dispatch({effects:L.current.reconfigure([h.readOnly.of(u),_.editable.of(!u)])})},[u,n,D]),(0,A.useEffect)(()=>{let e=E.current;if(!e)return;let t=e.state.doc.line(Math.max(1,Math.min(e.state.doc.lines,r))).from;e.dispatch({selection:{anchor:t},effects:_.scrollIntoView(t,{y:`center`})})},[r,n,D]),(0,j.jsxs)(i,{sx:{height:`100%`,display:`flex`,flexDirection:`column`},children:[C&&(0,j.jsx)(t,{size:`small`,onClick:()=>{let e=E.current;if(!e)return;let t=e.state.doc.lineAt(e.state.selection.main.head);C(t.number,t.text)},children:c(z,`Comment dòng hiện tại`,`Comment on current line`)}),(0,j.jsx)(i,{ref:T,sx:{flex:1,minHeight:240,overflow:`hidden`}})]})}export{I as default};
@@ -0,0 +1,5 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/WorkspaceCodeEditor-B7ieqDnt.js","assets/rolldown-runtime-hePW80VL.js","assets/vendor-Ch5hIe0W.js","assets/ui-preferences-B3UfDp-5.js","assets/index-C7Azrwpq.js","assets/bootstrap-CedkNtRG.js","assets/api-BUjrtT1B.js","assets/index-Dqb2hNan.css","assets/dist-D6i5SpQu.js"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{At as t,Bt as n,Ct as r,Dn as i,Fn as a,G as o,In as s,It as c,Jt as l,Kt as u,L as d,Rt as f,St as p,U as m,Ut as h,Vt as g,W as _,Wt as v,_t as y,t as b,zt as ee}from"./vendor-Ch5hIe0W.js";import{i as x,n as S}from"./ui-preferences-B3UfDp-5.js";import{i as C,n as w,o as T}from"./bootstrap-CedkNtRG.js";import{W as E,ct as te}from"./api-BUjrtT1B.js";import{L as D,P as O,l as k}from"./index-C7Azrwpq.js";import{a as A,c as j,d as M,f as N,i as P,l as F,o as I,s as L,t as ne,u as re}from"./LineReview-DzonwD-g.js";import{t as ie}from"./tab-close-Crj8vsUq.js";import{i as ae,r as R,t as z}from"./workspace-api-O7auv_td.js";var B=e(s(),1),V=i();function oe(e,t,n,i=[]){let{locale:a}=x(),[o,s]=(0,B.useState)(()=>j(e)),[c,l]=(0,B.useState)();(0,B.useEffect)(()=>{s(j(e)),l(void 0);let t=t=>{t.detail===e&&s(j(e))};return window.addEventListener(I,t),()=>window.removeEventListener(I,t)},[e]),(0,B.useEffect)(()=>l(void 0),[t]);let u=t=>{s(t),M(e,t)},d={locale:a,comments:o,editing:c?L(c.path,c.side,c.line):null,open:(e,t,n,r)=>l({path:e,line:n,code:r,side:t}),cancel:()=>l(void 0),save:t=>{c&&u(re(j(e),{...c,text:t})),l(void 0)},remove:t=>u(j(e).filter(e=>L(e.path,e.side,e.line)!==t))},f=new Map(n.split(`
3
+ `).map((e,n)=>[L(t??``,`new`,n+1),e.slice(0,400)]));for(let e of i)for(let n of e.lines)n.oldLineNumber!==null&&f.set(L(t??``,`old`,n.oldLineNumber),n.text.slice(0,400));return{open:(e,n,r=`new`)=>{t&&l({path:t,line:e,code:n,side:r})},dialog:(0,V.jsxs)(r,{open:!!c,onClose:()=>l(void 0),fullWidth:!0,children:[(0,V.jsxs)(m,{children:[S(a,`Comment theo dòng`,`Line comment`),` · `,c?.path,`:`,c?.line]}),(0,V.jsx)(_,{children:(0,V.jsx)(A.Provider,{value:d,children:c&&(0,V.jsx)(P,{path:c.path,side:c.side,line:c.line})})})]}),bar:(0,V.jsx)(ne,{comments:o,lines:f,linesPath:t,locale:a,onClear:()=>u([]),onSend:()=>{let t=j(e);t.length&&k(e,F(t,a===`en`)),u([])}})}}var H=new Map;function se(e,i,a,s,c){let{locale:l}=x(),u=`${e}\0${i??``}`,d=`${u}\0${a}\0${s}`,p=(0,B.useRef)(d);p.current=d;let g=(0,B.useRef)(u);g.current=u;let v=(0,B.useRef)(!1),[y,b]=(0,B.useState)(!1),[ee,C]=(0,B.useState)(!1),[w,T]=(0,B.useState)(),[D,O]=(0,B.useState)(),[k,A]=(0,B.useState)(!1);(0,B.useEffect)(()=>{C(!1),T(void 0),O(void 0),A(H.has(u))},[u]);let j=async t=>{if(!(v.current||!s||!c||c.file.path!==i||c.file.currentDigest!==`sha256:${a}`)&&(C(!0),O(void 0),T(void 0),A(H.has(u)),!H.has(u))){v.current=!0,b(!0);try{let n=await E(e,c.file.fileRef,t);if(p.current!==d)return;if(n.state!==`ready`||!n.target||n.target.path!==i||n.target.fileRef!==c.file.fileRef||n.target.fileRevision!==c.file.fileRevision||!n.target.hunkRefs.some(e=>e===t))throw Error(`preview-unavailable`);T({value:n,scope:d})}catch{p.current===d&&O(S(l,`Chưa thể hoàn tác an toàn. Tải lại diff và thử lại.`,`Safe revert is unavailable. Refresh the diff and try again.`))}finally{v.current=!1,b(!1)}}},M=async()=>{if(!(v.current||!s||!H.has(u)&&(!w||w.scope!==d))){v.current=!0,b(!0),O(void 0);try{let t=H.get(u)??await N(w.value);if(p.current!==d)return;if(!H.has(u)&&H.size>=128){O(S(l,`Có quá nhiều lệnh chưa rõ kết quả. Kiểm tra lại các lệnh trước trước khi hoàn tác thêm.`,`Too many commands still need their results checked. Check earlier commands before reverting more.`));return}H.set(u,t),A(!0);let n=await te(t,void 0,e);if(n.phase!==`uncertain`&&H.delete(u),g.current===u&&A(H.has(u)),window.dispatchEvent(new CustomEvent(`piagent-workspace-changed`,{detail:{sessionRef:e}})),p.current!==d)return;A(H.has(u)),n.phase===`settled`?(C(!1),T(void 0)):(n.phase===`rejected`&&T(void 0),O(n.phase===`uncertain`?S(l,`Chưa xác định được kết quả. Kiểm tra tệp; kiểm tra lại sẽ dùng đúng lệnh cũ.`,`The result is uncertain. Inspect the file; checking again uses the same command.`):S(l,`Tệp hoặc quyền đã thay đổi. Hãy đóng và xem preview mới.`,`The file or permission changed. Close this dialog and request a new preview.`)))}catch{p.current===d&&O(S(l,`Chưa nhận được kết quả. Kiểm tra lại dùng cùng lệnh, không tạo lần hoàn tác mới.`,`No result received. Checking again reuses the same command.`))}finally{v.current=!1,b(!1)}}},P=w&&w.scope!==d;return{request:j,dialog:(0,V.jsxs)(r,{open:ee,onClose:()=>{y||C(!1)},fullWidth:!0,maxWidth:`md`,children:[(0,V.jsx)(m,{children:S(l,`Hoàn tác thay đổi của agent`,`Revert agent changes`)}),(0,V.jsxs)(_,{children:[(0,V.jsx)(f,{children:i}),(0,V.jsx)(f,{children:S(l,`Các dòng dưới đây sẽ được hoàn tác. Git index được giữ nguyên.`,`The changes below will be reverted. The Git index is preserved.`)}),D&&(0,V.jsx)(t,{severity:`warning`,children:D}),P&&(0,V.jsx)(t,{severity:`warning`,children:S(l,`Nội dung editor đã đổi. Mở lại preview trước khi hoàn tác.`,`Editor contents changed. Open a new preview before reverting.`)}),k&&!w&&(0,V.jsx)(t,{severity:`info`,children:S(l,`Có lệnh chưa xác nhận kết quả cho tệp này.`,`A command for this file still needs its result confirmed.`)}),w?.value.preview?.hunks.map(e=>(0,V.jsxs)(h,{component:`pre`,sx:{whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:[e.header,`
4
+ `,e.lines.map(e=>`${e.marker}${e.text}`).join(`
5
+ `)]},e.hunkRef))]}),(0,V.jsxs)(o,{children:[(0,V.jsx)(n,{disabled:y,onClick:()=>C(!1),children:S(l,`Đóng`,`Close`)}),(0,V.jsx)(n,{color:`error`,disabled:y||!s||!k&&(!w||!!P),onClick:()=>void M(),children:k?S(l,`Kiểm tra lại`,`Check again`):S(l,`Xác nhận hoàn tác`,`Confirm revert`)})]})]}),hasPending:k,checkPending:()=>{A(H.has(u)),C(!0)}}}async function U(e,t,n){let r=await fetch(`/api/v1/sessions/${encodeURIComponent(e)}/source-review${t?`/${encodeURIComponent(t)}`:``}`,{credentials:`same-origin`,headers:{Accept:`application/json`},signal:n});if(r.status===401&&T(),!r.ok)throw Error(`source-review-unavailable`);return r.json()}var W=(e,t)=>U(e,void 0,t),ce=(e,t,n)=>U(e,t,n);function le(e,t,n,r,i){if(!e||!r||!n||e.file.path!==t||e.file.currentDigest!==`sha256:${n}`||e.availability.state!==`current`||e.truncation.truncated||e.redaction.applied)return[];let a=new Set(e.agentHunkRefs??[]);return e.hunks.filter(e=>a.has(e.hunkRef)&&!i.has(`${t}:${n}:${e.hunkRef}`))}var G=new Set,K=new Map,q=new Set,J=`piagent.kept-hunks.`,Y=`piagent.kept-hunks`;function X(e){try{let t=JSON.parse(localStorage.getItem(J+e)??`[]`);return Array.isArray(t)?new Set(t.filter(e=>typeof e==`string`).slice(-4096)):G}catch{return G}}function ue(e,t){try{let n=[...JSON.parse(localStorage.getItem(Y)??`[]`).filter(t=>t!==e),e];for(let e of n.splice(0,Math.max(0,n.length-64)))localStorage.removeItem(J+e);localStorage.setItem(J+e,JSON.stringify([...t])),localStorage.setItem(Y,JSON.stringify(n))}catch{}}var de=e=>(K.has(e)||K.set(e,X(e)),K.get(e)??G);function fe(e,t,n,r){let i=new Set([...de(e),`${t}:${n}:${r}`].slice(-4096));for(K.delete(e),K.set(e,i);K.size>64;)K.delete(K.keys().next().value);ue(e,i);for(let e of q)e()}function pe(e){return(0,B.useSyncExternalStore)(e=>(q.add(e),()=>{q.delete(e)}),()=>de(e))}function me(e,t,n){let[r,i]=(0,B.useState)(),a=pe(e),o=JSON.stringify(t.map(e=>e.file.path).sort());(0,B.useEffect)(()=>{let t=JSON.parse(o);if(!t.length){i(void 0);return}let n=new AbortController,r=!1,a=!1,s=async()=>{if(!n.signal.aborted){if(r){a=!0;return}r=!0;try{let r=await W(e,n.signal),a=new Map;for(let i of t){if(n.signal.aborted)return;let t=r.files.find(e=>e.path===i&&e.pathDisplay===`exact-safe`);if(t)try{a.set(i,await ce(e,t.fileRef,n.signal))}catch{}}n.signal.aborted||i({session:e,diffs:a})}catch{n.signal.aborted||i(void 0)}finally{r=!1,a&&!n.signal.aborted&&(a=!1,s())}}};s();let c=window.setInterval(()=>void s(),3e3),l=t=>{t.detail?.sessionRef===e&&s()};return window.addEventListener(`piagent-workspace-saved`,l),window.addEventListener(`piagent-workspace-changed`,l),()=>{n.abort(),clearInterval(c),window.removeEventListener(`piagent-workspace-saved`,l),window.removeEventListener(`piagent-workspace-changed`,l)}},[e,o]);let s=r?.session===e?r.diffs:void 0,c=e=>le(s?.get(e.file.path),e.file.path,e.file.digest,!e.fresh&&!e.pending&&e.draft===(e.file.content??``),a),l=t.find(e=>e.file.path===n),u=l?c(l):[];return{diff:n?s?.get(n):void 0,hunks:u,counts:new Map(t.map(e=>[e.file.path,c(e).length])),keep:t=>{l?.file.digest&&u.some(e=>e.hunkRef===t)&&fe(e,l.file.path,l.file.digest,t)}}}var Z=new Map,he=new Set,ge={tabs:[]},Q=e=>e.fresh||e.draft!==(e.file.content??``);window.addEventListener(`beforeunload`,e=>{[...Z.values()].some(e=>e.tabs.some(Q))&&(e.preventDefault(),e.returnValue=``)});var _e=e=>Z.get(e)??ge;function ve(e){let t=(0,B.useSyncExternalStore)(e=>(he.add(e),()=>{he.delete(e)}),()=>Z.get(e)??ge),n=t=>{Z.set(e,t(Z.get(e)??ge));for(let e of he)e()};return{...t,update:n}}function ye(e,t,n){return e.file!==t||e.file.path!==n.path||e.pending||e.fresh||e.file.digest===n.digest&&e.file.protected===n.protected&&e.file.readOnly===n.readOnly?{tab:e}:e.draft===(e.file.content??``)?{tab:{...e,file:n,draft:n.content??``}}:{tab:e,conflict:n}}function be(e,t,n){let{update:r}=ve(e),i=(0,B.useRef)({update:r,conflict:n});i.current={update:r,conflict:n},(0,B.useEffect)(()=>{let n=new AbortController,r=new Map,a=!1,o=!1,s,c=async()=>{if(!(n.signal.aborted||t.current)){if(a){o=!0;return}a=!0;try{for(let a of _e(e).tabs)if(!(a.fresh||a.pending||t.current))try{let o=await z(e,a.file.path,n.signal);if(n.signal.aborted||t.current)return;let s;if(i.current.update(e=>({...e,tabs:e.tabs.map(t=>{if(t.file.path!==a.file.path)return t;let n=ye(t,a.file,o);return n.conflict&&e.active===t.file.path&&(s=n.conflict),n.tab})})),s){let e=`${s.digest}:${s.protected}:${s.readOnly}`;r.get(s.path)!==e&&(r.set(s.path,e),i.current.conflict(s))}}catch{}}finally{a=!1,o&&!n.signal.aborted&&(o=!1,l())}}},l=()=>{s||=setTimeout(()=>{s=void 0,c()},100)},u=t=>{t.detail?.sessionRef===e&&l()};window.addEventListener(`piagent-workspace-changed`,u),window.addEventListener(`piagent-workspace-saved`,u);let d=setInterval(l,5e3);return l(),()=>{n.abort(),clearTimeout(s),clearInterval(d),window.removeEventListener(`piagent-workspace-changed`,u),window.removeEventListener(`piagent-workspace-saved`,u)}},[e,t])}var xe=e=>`/api/v1/sessions/${encodeURIComponent(e)}/workspace/write`;function $(e){return Array.isArray(e)?`[${e.map($).join(`,`)}]`:e&&typeof e==`object`?`{${Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>`${JSON.stringify(e)}:${$(t)}`).join(`,`)}}`:JSON.stringify(e)}async function Se(e,t){let n=await fetch(xe(e),{credentials:`same-origin`,signal:t,headers:{Accept:`application/json`}});if(n.status===401&&T(),!n.ok)throw Error(`workspace-write-unavailable`);return await n.json()}async function Ce(e,t){let n=Date.now(),r=`workspace.write`,i=e.identity,a=e.revisions,o=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode($({action:r,identity:i,expectedRevisions:a,payload:t})));return{schemaVersion:1,version:`piagent-webui-workspace-write-v1`,messageType:`command`,action:r,identity:i,expectedRevisions:a,payload:t,commandId:crypto.randomUUID(),idempotencyKey:crypto.randomUUID(),requestedAt:new Date(n).toISOString(),expiresAt:new Date(n+6e4).toISOString(),actionDigest:`sha256:${[...new Uint8Array(o)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`}}async function we(e,t){let n=w();if(!n)throw Error(`workspace-write-unavailable`);let r=await C(xe(e),{method:`POST`,credentials:`same-origin`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":n},body:JSON.stringify(t)});if(r.status===401&&T(),!r.ok)throw Error(`workspace-write-unavailable`);let i=await r.json(),a=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(t.idempotencyKey)),o=`sha256:${[...new Uint8Array(a)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}`;if(i.schemaVersion!==1||i.version!==t.version||i.messageType!==`receipt`||i.path!==t.payload.path||i.commandId!==t.commandId||i.action!==t.action||i.actionDigest!==t.actionDigest||i.idempotencyKeyDigest!==o||$(i.identity)!==$(t.identity)||![`settled`,`rejected`,`uncertain`].includes(i.phase)||i.phase===`settled`&&(i.resultCode!==`saved`||!/^[a-f0-9]{64}$/.test(i.digest??``)))throw Error(`workspace-write-receipt-invalid`);return i}function Te(e){let{locale:t}=x(),n=ve(e),[r,i]=(0,B.useState)(),[a,o]=(0,B.useState)(!1),s=(0,B.useRef)(!1),[c,l]=(0,B.useState)(),[u,d]=(0,B.useState)();be(e,s,d),(0,B.useEffect)(()=>{let t=new AbortController,n=!1,r=()=>{n||(n=!0,Se(e,t.signal).then(i).catch(()=>{t.signal.aborted||i(void 0)}).finally(()=>{n=!1}))};r();let a=window.setInterval(r,5e3);return()=>{t.abort(),clearInterval(a)}},[e]);let f=(e,t=1,r=!1)=>n.update(n=>({active:e.path,tabs:[...n.tabs.filter(t=>t.file.path!==e.path),{file:e,line:t,fresh:r,draft:e.content??``}]})),p=(e,t)=>n.update(n=>({...n,active:e,tabs:n.tabs.map(n=>n.file.path===e&&t!==void 0?{...n,line:t}:n)})),m=(e,t)=>n.update(n=>({...n,tabs:n.tabs.map(n=>n.file.path===e?{...n,draft:t}:n)})),h=r=>{let i=_e(e).tabs.find(e=>e.file.path===r);i&&(Q(i)||i.pending)&&!window.confirm(S(t,`Bỏ thay đổi chưa lưu và đóng tệp?`,`Discard unsaved changes and close this file?`))||n.update(e=>({tabs:e.tabs.filter(e=>e.file.path!==r),active:e.active===r?e.tabs.find(e=>e.file.path!==r)?.file.path:e.active}))},g=async n=>{try{f(await z(e,n)),d(void 0),l(void 0)}catch{l(S(t,`Chưa tải lại được tệp. Bản sửa của bạn vẫn được giữ.`,`Could not reload the file. Your draft is preserved.`))}},_=async(r,a)=>{let c=_e(e).tabs.find(e=>e.file.path===r);if(!(!c||s.current||!Q(c)&&!c.pending||c.file.protected||c.file.readOnly)&&!(a&&!window.confirm(S(t,`Ghi đè phiên bản trên đĩa bằng bản sửa của bạn?`,`Replace the version on disk with your draft?`)))){s.current=!0,o(!0),l(void 0);try{let o=await Se(e);if(i(o),!o.writable)throw Error(`read-only`);let s=a?.digest??(c.fresh?`absent`:c.file.digest);if(!s)throw Error(`unavailable`);let u=c.pending??await Ce(o,{path:r,content:c.draft,expectedDigest:s});n.update(e=>({...e,tabs:e.tabs.map(e=>e.file.path===r?{...e,pending:u}:e)}));let f=await we(e,u);if(f.phase===`uncertain`){l(S(t,`Chưa xác định được kết quả lưu. Tải lại để kiểm tra trước khi lưu tiếp.`,`The save result is uncertain. Reload to check before saving again.`));return}n.update(e=>({...e,tabs:e.tabs.map(e=>e.file.path===r?{...e,pending:void 0}:e)})),f.phase===`settled`&&f.resultCode===`saved`?(n.update(e=>({...e,tabs:e.tabs.map(e=>e.file.path===r?{...e,fresh:!1,file:{...e.file,content:u.payload.content,digest:f.digest,revision:f.observedRevisionsAfter.workspaceRevision}}:e)})),d(void 0),window.dispatchEvent(new CustomEvent(`piagent-workspace-saved`,{detail:{sessionRef:e,path:r}}))):f.resultCode===`stale-content`||f.resultCode===`stale-revision`?d(await z(e,r)):l(S(t,`Chưa lưu được tệp. Kiểm tra quyền ghi và thử lại.`,`Could not save the file. Check write access and try again.`))}catch{l(S(t,`Chưa lưu được tệp. Bản sửa vẫn được giữ; thử lưu lại hoặc tải lại để kiểm tra.`,`Could not confirm the save. Your draft is preserved; retry the save or reload to check.`))}finally{s.current=!1,o(!1)}}},v=async(r,a)=>{let c=_e(e).tabs.find(e=>e.file.path===r);if(s.current||c&&(Q(c)||c.pending))return l(S(t,`Lưu hoặc bỏ thay đổi trước khi đổi tên hay xóa tệp.`,`Save or discard your changes before renaming or deleting the file.`)),!1;s.current=!0,o(!0),l(void 0);try{let o=await Se(e);i(o);let s=c?.file.digest??(await z(e,r)).digest;if(!o.writable||!s)throw Error(`unavailable`);let u=await we(e,await Ce(o,a?{path:r,content:``,expectedDigest:s,operation:`rename`,destination:a}:{path:r,content:``,expectedDigest:s,operation:`delete`}));return u.phase===`settled`&&u.resultCode===`saved`?(n.update(e=>({tabs:e.tabs.filter(e=>e.file.path!==r),active:e.active===r?void 0:e.active})),a&&f(await z(e,a)),window.dispatchEvent(new CustomEvent(`piagent-workspace-saved`,{detail:{sessionRef:e,path:r}})),!0):(l(u.phase===`uncertain`?S(t,`Chưa xác định được kết quả. Tải lại danh sách tệp để kiểm tra.`,`The result is uncertain. Reload the file list to check.`):u.resultCode===`stale-content`?S(t,`Tệp đã thay đổi trên đĩa hoặc tên mới đã có. Tải lại rồi thử lại.`,`The file changed on disk or the new name exists. Reload and try again.`):S(t,`Không thực hiện được. Kiểm tra quyền ghi và tên tệp.`,`This could not be done. Check write access and the file name.`)),!1)}catch{return l(S(t,`Chưa xác nhận được thao tác. Tải lại danh sách tệp để kiểm tra.`,`Could not confirm the action. Reload the file list to check.`)),!1}finally{s.current=!1,o(!1)}};return{...n,authority:r,saving:a,message:c,conflict:u,setConflict:d,load:f,select:p,change:m,close:h,reload:g,save:_,move:v}}var Ee=e(a(),1);function De({sessionRef:e,onOpen:r}){let{locale:i}=x(),[a,o]=(0,B.useState)(``),[s,c]=(0,B.useState)(),[l,u]=(0,B.useState)(!1),[d,m]=(0,B.useState)(!1);return(0,B.useEffect)(()=>{let t=new AbortController;if(c(void 0),m(!1),u(!1),!a.trim())return()=>t.abort();u(!0);let n=setTimeout(()=>{ae(e,a,t.signal).then(e=>{t.signal.aborted||c(e)}).catch(()=>{t.signal.aborted||m(!0)}).finally(()=>{t.signal.aborted||u(!1)})},250);return()=>{clearTimeout(n),t.abort()}},[a,e]),(0,V.jsxs)(p,{spacing:1,sx:{p:1},children:[(0,V.jsx)(y,{size:`small`,label:S(i,`Tìm nội dung`,`Search contents`),value:a,onChange:e=>o(e.target.value),slotProps:{htmlInput:{maxLength:512}}}),l&&(0,V.jsx)(g,{size:18}),(d||s?.available===!1)&&(0,V.jsx)(t,{severity:`warning`,children:S(i,`Chưa tìm được nội dung trong project này.`,`Content search is unavailable for this project.`)}),s?.available&&s.backend===`fts`&&(0,V.jsx)(f,{variant:`caption`,children:S(i,`Tìm trong các tệp đã lập chỉ mục.`,`Searching indexed files.`)}),s?.matches.map(e=>(0,V.jsxs)(n,{onClick:()=>r(e.path,e.line),sx:{textTransform:`none`,display:`block`,textAlign:`left`,overflowWrap:`anywhere`},children:[(0,V.jsxs)(f,{variant:`caption`,component:`span`,children:[e.path,`:`,e.line,`:`,e.column]}),(0,V.jsx)(f,{variant:`body2`,component:`span`,sx:{display:`block`},children:e.preview})]},`${e.path}:${e.line}:${e.column}`)),s?.truncated&&(0,V.jsx)(f,{variant:`caption`,children:S(i,`Đã giới hạn kết quả. Hãy tìm cụ thể hơn.`,`Results were limited. Refine your search.`)}),s?.available&&!s.matches.length&&!s.truncated&&(0,V.jsx)(f,{variant:`caption`,children:S(i,`Không tìm thấy.`,`No matches.`)})]})}var Oe=u((0,V.jsx)(`path`,{d:`M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z`}),`ChevronRight`),ke=u((0,V.jsx)(`path`,{d:`M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z`}),`ExpandMore`),Ae=u((0,V.jsx)(`path`,{d:`M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8zM6 20V4h7v5h5v11z`}),`InsertDriveFileOutlined`),je=e=>e.split(`/`).slice(0,-1).map((e,t,n)=>n.slice(0,t+1).join(`/`));function Me({sessionRef:e,refresh:t,active:r,onOpen:i,onFolder:a}){let{locale:o}=x(),[s,l]=(0,B.useState)(()=>new Set([``])),[u,p]=(0,B.useState)(()=>new Map),[m,_]=(0,B.useState)(),v=(t,n)=>{p(e=>new Map(e).set(t,e.get(t)??`loading`)),R(e,t,n).then(e=>{n?.aborted||p(n=>new Map(n).set(t,e))}).catch(()=>{n?.aborted||p(e=>new Map(e).set(t,`error`))})};(0,B.useEffect)(()=>{p(new Map),l(new Set([``]))},[e]),(0,B.useEffect)(()=>{let e=new AbortController;for(let t of s)v(t,e.signal);return()=>e.abort()},[e,t]),(0,B.useEffect)(()=>{if(!r)return;let e=je(r).filter(e=>!s.has(e));if(e.length){l(t=>new Set([...t,...e]));for(let t of e)u.has(t)||v(t)}},[r]);let y=e=>{if(_(e),a(e),s.has(e)){l(t=>{let n=new Set(t);return n.delete(e),n});return}l(t=>new Set(t).add(e)),(!u.has(e)||u.get(e)===`error`)&&v(e)},b=(e,t)=>{let a=u.get(e);return!a||a===`loading`?(0,V.jsx)(g,{size:14,sx:{ml:1.5+t*1.5,my:.5}}):a===`error`?(0,V.jsx)(f,{variant:`caption`,color:`warning.main`,sx:{pl:1.5+t*1.5},children:S(o,`Chưa đọc được thư mục này.`,`This folder could not be read.`)}):(0,V.jsxs)(V.Fragment,{children:[a.entries.map(e=>{let a=e.kind===`directory`,l=a&&s.has(e.path),u=a?m===e.path:r===e.path,f=a?(0,V.jsxs)(V.Fragment,{children:[l?(0,V.jsx)(ke,{sx:{fontSize:16}}):(0,V.jsx)(Oe,{sx:{fontSize:16}}),l?(0,V.jsx)(d,{sx:{fontSize:16}}):(0,V.jsx)(c,{sx:{fontSize:16}})]}):(0,V.jsx)(Ae,{sx:{fontSize:16,ml:`16px`}});return(0,V.jsxs)(h,{children:[(0,V.jsxs)(n,{fullWidth:!0,size:`small`,disabled:e.protected||e.kind===`symlink`||e.kind===`other`,"aria-label":e.protected?`${e.name} (${S(o,`được bảo vệ`,`protected`)})`:e.name,"aria-expanded":a?l:void 0,"aria-current":!a&&r===e.path?`true`:void 0,onClick:()=>a?y(e.path):(_(void 0),i(e.path)),sx:{justifyContent:`flex-start`,textTransform:`none`,gap:.5,minHeight:24,py:0,pl:.5+t*1.5,pr:1,color:`text.primary`,fontWeight:400,whiteSpace:`nowrap`,bgcolor:u?`action.selected`:void 0},children:[f,(0,V.jsxs)(h,{component:`span`,sx:{overflow:`hidden`,textOverflow:`ellipsis`},children:[e.name,e.protected?` 🔒`:``]})]}),l&&b(e.path,t+1)]},e.path)}),a.truncated&&(0,V.jsx)(f,{variant:`caption`,sx:{pl:1.5+t*1.5},children:S(o,`Danh sách đã được giới hạn.`,`Listing limit reached.`)})]})};return(0,V.jsx)(h,{role:`group`,"aria-label":S(o,`Cây thư mục`,`Folder tree`),sx:{py:.5},children:b(``,0)})}var Ne=(0,B.lazy)(()=>O(()=>import(`./WorkspaceCodeEditor-B7ieqDnt.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8])));function Pe({sessionRef:e,target:i,navigationHost:a,sidebarMode:s,onHide:c,fill:u}){let{locale:d}=x(),[C,w]=(0,B.useState)(`files`),[T,E]=(0,B.useState)(!1),[te,O]=(0,B.useState)(``),[k,A]=(0,B.useState)(!1),[j,M]=(0,B.useState)(),[N,P]=(0,B.useState)(``),F=Te(e),{tabs:I,active:L}=F,[ne,re]=(0,B.useState)(``),[ae,R]=(0,B.useState)(!1),[H,U]=(0,B.useState)(!1),W=(0,B.useRef)(null),[ce,le]=(0,B.useState)(0);(0,B.useEffect)(()=>{let t=t=>{t.detail?.sessionRef===e&&le(e=>e+1)};return window.addEventListener(`piagent-workspace-saved`,t),()=>window.removeEventListener(`piagent-workspace-saved`,t)},[e]),(0,B.useEffect)(()=>()=>W.current?.abort(),[]);let G=async(t,n=1)=>{if(W.current?.abort(),U(!1),I.find(e=>e.file.path===t)){F.select(t,n);return}W.current?.abort();let r=new AbortController;W.current=r,U(!0),R(!1);try{let i=await z(e,t,r.signal);if(r.signal.aborted)return;if(i.protected){R(!0);return}F.load(i,n)}catch{r.signal.aborted||R(!0)}finally{r.signal.aborted||U(!1)}};(0,B.useEffect)(()=>{i&&G(i.path,i.line??1)},[i]),(0,B.useEffect)(()=>{s&&s!==`sessions`&&w(s)},[s]);let K=I.find(e=>e.file.path===L),q=K?.file,J=me(e,I,L),Y=se(e,q?.path,q?.digest??null,!!K&&!Q(K),J.diff),X=oe(e,q?.path,K?.draft??``,J.hunks),ue=I.find(e=>e.file.path===F.conflict?.path),de=(0,V.jsxs)(h,{component:`nav`,"aria-label":S(d,`Tệp dự án`,`Project files`),sx:{width:a?`100%`:{xs:136,sm:200},flexShrink:0,overflow:`auto`,borderRight:1,borderColor:`divider`},children:[!a&&(0,V.jsxs)(v,{value:C,onChange:(e,t)=>w(t),"aria-label":S(d,`Khám phá project`,`Explore project`),children:[(0,V.jsx)(l,{value:`files`,label:S(d,`Tệp`,`Files`)}),(0,V.jsx)(l,{value:`search`,label:S(d,`Tìm kiếm`,`Search`)})]}),C===`search`?(0,V.jsx)(De,{sessionRef:e,onOpen:(e,t)=>void G(e,t)}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(n,{disabled:!F.authority?.writable,onClick:()=>{O(ne?`${ne}/`:``),E(!0)},children:S(d,`Tệp mới`,`New file`)}),(0,V.jsx)(Me,{sessionRef:e,refresh:ce,active:L,onOpen:e=>{re(e.split(`/`).slice(0,-1).join(`/`)),G(e)},onFolder:re})]})]});return(0,V.jsxs)(V.Fragment,{children:[Y.dialog,X.dialog,(0,V.jsxs)(p,{direction:`row`,sx:{height:u?`100%`:`calc(100vh - 150px)`,minHeight:u?160:320},children:[a?(0,Ee.createPortal)(de,a):de,(0,V.jsxs)(h,{sx:{minWidth:0,flex:1,display:`flex`,flexDirection:`column`},children:[ae&&(0,V.jsx)(t,{severity:`warning`,children:S(d,`Chưa đọc được tệp hoặc thư mục này.`,`This file or folder could not be read.`)}),X.bar,F.message&&(0,V.jsx)(t,{severity:`warning`,children:F.message}),F.authority?.agentRunning&&(0,V.jsx)(t,{severity:`info`,children:S(d,`Agent đang chạy và có thể sửa tệp này.`,`The agent is running and may change this file.`)}),(0,V.jsxs)(p,{direction:`row`,sx:{alignItems:`center`,borderBottom:1,borderColor:`divider`,minHeight:36},children:[(0,V.jsx)(v,{value:L??!1,onChange:(e,t)=>F.select(t),variant:`scrollable`,scrollButtons:`auto`,"aria-label":S(d,`Các tệp đang mở`,`Open files`),sx:{flex:1,minWidth:0,minHeight:36},children:I.map(e=>(0,V.jsx)(l,{value:e.file.path,sx:{minHeight:36,py:0},"aria-label":`${e.file.path}${Q(e)?` ●`:``}${J.counts.get(e.file.path)?` (${J.counts.get(e.file.path)})`:``}`,label:ie(`${e.file.path}${Q(e)?` ●`:``}${J.counts.get(e.file.path)?` (${J.counts.get(e.file.path)})`:``}`,S(d,`Đóng ${e.file.path}`,`Close ${e.file.path}`),()=>F.close(e.file.path))},e.file.path))}),c&&(0,V.jsx)(ee,{size:`small`,"aria-label":S(d,`Ẩn khung tệp`,`Hide files panel`),title:S(d,`Ẩn khung tệp (tệp đang mở vẫn giữ)`,`Hide files panel (open files are kept)`),onClick:c,children:(0,V.jsx)(b,{fontSize:`small`})})]}),H&&(0,V.jsx)(g,{size:20}),q&&(0,V.jsxs)(p,{direction:`row`,sx:{flexShrink:0,overflowX:`auto`,"& .MuiButton-root":{whiteSpace:`nowrap`,flexShrink:0}},children:[Y.hasPending&&(0,V.jsx)(n,{onClick:Y.checkPending,children:S(d,`Kiểm tra hoàn tác`,`Check revert`)}),(0,V.jsx)(n,{size:`small`,disabled:!F.authority?.writable||q.readOnly||!K||!Q(K)&&!K.pending||F.saving,onClick:()=>void F.save(q.path),children:S(d,`Lưu`,`Save`)}),(0,V.jsx)(n,{size:`small`,onClick:()=>F.close(q.path),children:S(d,`Đóng tệp`,`Close file`)}),(0,V.jsx)(n,{size:`small`,disabled:!F.authority?.writable||q.readOnly||!q.digest||F.saving,onClick:()=>{P(q.path),M(q.path)},children:S(d,`Đổi tên`,`Rename`)}),(0,V.jsx)(n,{size:`small`,color:`error`,disabled:!F.authority?.writable||q.readOnly||!q.digest||F.saving,onClick:()=>{window.confirm(S(d,`Xóa ${q.path}? Có thể khôi phục bằng Git nếu tệp đã commit.`,`Delete ${q.path}? Git can restore it if it was committed.`))&&F.move(q.path)},children:S(d,`Xóa`,`Delete`)}),(0,V.jsx)(n,{size:`small`,onClick:()=>{(!K||!Q(K)||window.confirm(S(d,`Bỏ thay đổi chưa lưu và tải lại?`,`Discard unsaved changes and reload?`)))&&F.reload(q.path)},children:S(d,`Tải lại`,`Reload`)})]}),q?.binary||q?.oversized?(0,V.jsx)(t,{severity:`info`,children:S(d,`Tệp nhị phân hoặc quá lớn để hiển thị.`,`This file is binary or too large to display.`)}):q?.content!==null&&q?.content!==void 0?(0,V.jsx)(h,{sx:{flex:1,minHeight:0},children:(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(g,{size:20}),children:(0,V.jsx)(Ne,{onComment:X.open,hunks:J.hunks,onKeep:J.keep,onRevert:F.authority?.writable?e=>void Y.request(e):void 0,content:K?.draft??q.content,path:q.path,line:K?.line??1,readOnly:!F.authority?.writable||q.readOnly,onChange:e=>F.change(q.path,e),onSave:()=>void F.save(q.path)})})}):(0,V.jsx)(f,{sx:{p:2},children:S(d,`Chọn một tệp để mở.`,`Select a file to open.`)})]})]}),(0,V.jsxs)(r,{open:T,onClose:()=>E(!1),fullWidth:!0,children:[(0,V.jsx)(m,{children:S(d,`Tạo tệp mới`,`Create a new file`)}),(0,V.jsx)(_,{children:(0,V.jsx)(y,{autoFocus:!0,fullWidth:!0,label:S(d,`Đường dẫn trong project`,`Path in project`),value:te,onChange:e=>O(e.target.value)})}),(0,V.jsxs)(o,{children:[(0,V.jsx)(n,{onClick:()=>E(!1),children:S(d,`Hủy`,`Cancel`)}),(0,V.jsx)(n,{disabled:!D(te)||!F.authority?.writable,onClick:()=>{let e=D(te);!e||!F.authority||(I.some(t=>t.file.path===e.path)?F.select(e.path):F.load({schemaVersion:1,version:`piagent-webui-workspace-file-v1`,generatedAt:new Date().toISOString(),identity:F.authority.identity,path:e.path,language:`text`,protected:!1,readOnly:!1,binary:!1,oversized:!1,content:``,digest:null,revision:null},1,!0),E(!1))},children:S(d,`Tạo`,`Create`)})]})]}),(0,V.jsxs)(r,{open:!!j,onClose:()=>M(void 0),fullWidth:!0,children:[(0,V.jsx)(m,{children:S(d,`Đổi tên tệp`,`Rename file`)}),(0,V.jsx)(_,{children:(0,V.jsx)(y,{autoFocus:!0,fullWidth:!0,label:S(d,`Đường dẫn mới trong project`,`New path in project`),value:N,onChange:e=>P(e.target.value)})}),(0,V.jsxs)(o,{children:[(0,V.jsx)(n,{onClick:()=>M(void 0),children:S(d,`Hủy`,`Cancel`)}),(0,V.jsx)(n,{disabled:!D(N)||D(N)?.path===j||F.saving,onClick:()=>{let e=D(N);!e||!j||F.move(j,e.path).then(e=>{e&&M(void 0)})},children:S(d,`Đổi tên`,`Rename`)})]})]}),(0,V.jsxs)(r,{open:!!F.conflict,onClose:()=>{F.setConflict(void 0),A(!1)},fullWidth:!0,maxWidth:k?`lg`:`sm`,children:[(0,V.jsx)(m,{children:S(d,`Tệp đã thay đổi trên đĩa`,`The file changed on disk`)}),(0,V.jsxs)(_,{children:[(0,V.jsx)(f,{children:F.conflict?.path}),(0,V.jsx)(f,{children:S(d,`Bản sửa của bạn vẫn được giữ. Chọn cách xử lý xung đột.`,`Your draft is preserved. Choose how to resolve the conflict.`)}),k&&F.conflict&&ue&&(0,V.jsxs)(p,{direction:`row`,spacing:1,children:[(0,V.jsxs)(h,{sx:{width:`50%`,height:360},children:[(0,V.jsx)(f,{children:S(d,`Trên đĩa`,`On disk`)}),(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(g,{size:20}),children:(0,V.jsx)(Ne,{path:F.conflict.path,content:F.conflict.content??``})})]}),(0,V.jsxs)(h,{sx:{width:`50%`,height:360},children:[(0,V.jsx)(f,{children:S(d,`Bản sửa của bạn`,`Your draft`)}),(0,V.jsx)(B.Suspense,{fallback:(0,V.jsx)(g,{size:20}),children:(0,V.jsx)(Ne,{path:ue.file.path,content:ue.draft})})]})]})]}),(0,V.jsxs)(o,{children:[(0,V.jsx)(n,{onClick:()=>{F.setConflict(void 0),A(!1)},children:S(d,`Để sau`,`Later`)}),(0,V.jsx)(n,{onClick:()=>{F.conflict&&(F.load(F.conflict),F.setConflict(void 0),A(!1))},children:S(d,`Tải lại`,`Reload`)}),(0,V.jsx)(n,{onClick:()=>A(!0),children:S(d,`Xem khác biệt`,`Compare`)}),(0,V.jsx)(n,{disabled:F.saving||!F.conflict?.digest||F.conflict.protected||F.conflict.readOnly,onClick:()=>{F.conflict&&F.save(F.conflict.path,F.conflict)},children:S(d,`Ghi đè`,`Overwrite`)})]})]})]})}export{Pe as default};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{At as t,Ct as n,Dn as r,In as i,U as a,W as o,_t as s,ot as c,xt as l}from"./vendor-Ch5hIe0W.js";import{i as u,n as d}from"./ui-preferences-B3UfDp-5.js";import{n as f}from"./workspace-api-O7auv_td.js";var p=e(i(),1),m=r();function h({sessionRef:e,onClose:r,onOpen:i}){let{locale:h}=u(),[g,_]=(0,p.useState)(``),[v,y]=(0,p.useState)([]),[b,x]=(0,p.useState)(0),[S,C]=(0,p.useState)(!1);return(0,p.useEffect)(()=>{let t=new AbortController;C(!1),y([]),x(0);let n=setTimeout(()=>{f(e,g,t.signal).then(e=>{t.signal.aborted||y(e.suggestions.filter(e=>e.kind===`file`).map(e=>e.value))}).catch(()=>{t.signal.aborted||C(!0)})},120);return()=>{clearTimeout(n),t.abort()}},[e,g]),(0,m.jsxs)(n,{open:!0,onClose:r,fullWidth:!0,maxWidth:`sm`,children:[(0,m.jsx)(a,{children:d(h,`Mở nhanh`,`Quick open`)}),(0,m.jsxs)(o,{children:[(0,m.jsx)(s,{autoFocus:!0,fullWidth:!0,value:g,label:d(h,`Tên tệp`,`File name`),onChange:e=>_(e.target.value),onKeyDown:e=>{e.key===`ArrowDown`&&(e.preventDefault(),x(e=>Math.min(v.length-1,e+1))),e.key===`ArrowUp`&&(e.preventDefault(),x(e=>Math.max(0,e-1))),e.key===`Enter`&&v[b]&&(e.preventDefault(),i(v[b]))}}),S&&(0,m.jsx)(t,{severity:`warning`,children:d(h,`Chưa tìm được tệp.`,`Files could not be searched.`)}),(0,m.jsx)(l,{"aria-label":d(h,`Tệp tìm thấy`,`Matching files`),children:v.map((e,t)=>(0,m.jsx)(c,{selected:t===b,onClick:()=>i(e),children:e},e))})]})]})}export{h as default};
@@ -0,0 +1 @@
1
+ import{i as e,n as t,o as n}from"./bootstrap-CedkNtRG.js";var r=class extends Error{status;code;constructor(e,t=null){super(`webui-request-${e}`),this.status=e,this.code=t}};async function i(e){try{let t=await e.json();return typeof t.error?.code==`string`?t.error.code:null}catch{return null}}async function a(e){let t=await fetch(`/api/v1/snapshot`,{credentials:`same-origin`,headers:{Accept:`application/json`},signal:e});if(!t.ok)throw new r(t.status);return await t.json()}function o(e){return h(`/api/v1/session-catalog`,e)}function s(e){return h(`/api/v1/session-live-state`,e)}function c(e){return h(`/api/v1/session-creation-options`,e)}function l(e){return h(`/api/v1/provider-auth`,e)}function u(e,t){return h(`/api/v1/provider-auth/jobs/${encodeURIComponent(e)}`,t)}async function d(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/provider-auth`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}function ee(e,t){return d({action:`provider-auth.start`,providerRef:e},t)}function te(e,t,n,r){return d({action:`provider-auth.respond`,jobRef:e,promptRef:t,value:n},r)}function ne(e,t){return d({action:`provider-auth.cancel`,jobRef:e},t)}async function f(n){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/projects/import`,{method:`POST`,credentials:`same-origin`,signal:n,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify({action:`project.import`})});if(!o.ok)throw new r(o.status,await i(o));return await o.json()}async function p(e){try{return await h(`/api/v1/managed`,e)}catch(e){if(e instanceof r&&e.status===404)return null;throw e}}async function m(n){let i=t();if(!i)throw new r(403);let a=await e(`/api/v1/managed/connect`,{method:`POST`,credentials:`same-origin`,signal:n,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":i},body:JSON.stringify({action:`managed.connect`})});if(!a.ok)throw new r(a.status);return await a.json()}async function h(e,t){let i=await fetch(e,{credentials:`same-origin`,headers:{Accept:`application/json`},signal:t});if(i.status===401&&n(),!i.ok)throw new r(i.status);return await i.json()}function g(e,t){if(!t.startsWith(`/api/v1/`))throw Error(`invalid-inspection-path`);return`/api/v1/sessions/${encodeURIComponent(e)}/inspection/${t.slice(8)}`}function _(e,t){return h(g(e,`/api/v1/snapshot`),t)}function v(e,t=null,n=50,r){let i=new URLSearchParams({limit:String(n)});return t&&i.set(`before`,t),h(g(e,`/api/v1/transcript?${i}`),r)}function y(e,t,n){return h(g(e,`/api/v1/approvals/${encodeURIComponent(t)}`),n)}function b(e,t,n){return h(g(e,`/api/v1/source-changes?view=${encodeURIComponent(t)}`),n)}function x(e,t,n,r){return h(g(e,`/api/v1/diffs/${encodeURIComponent(n)}?view=${encodeURIComponent(t)}`),r)}function S(e,t,n,r){return h(g(e,`/api/v1/reviews/${encodeURIComponent(n)}?view=${encodeURIComponent(t)}`),r)}function C(e,t,n,r){return h(g(e,`/api/v1/source-mutations/${encodeURIComponent(n)}?action=${encodeURIComponent(t)}`),r)}function w(e,t,n=null,r){let i=n?`?hunkRef=${encodeURIComponent(n)}`:``;return h(`/api/v1/sessions/${encodeURIComponent(e)}/source-reverts/${encodeURIComponent(t)}${i}`,r)}function T(e,t){return h(g(e,`/api/v1/commit-summary`),t)}function E(e,t,n){return h(g(e,`/api/v1/log-previews/${encodeURIComponent(t)}`),n)}function D(e,t){return h(g(e,`/api/v1/connections`),t)}async function O(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/session-connections`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}function k(e,t){return h(`/api/v1/mcp-auth/jobs/${encodeURIComponent(e)}`,t)}async function A(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/runtime-commands`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}async function j(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/mcp-auth/jobs/${encodeURIComponent(n)}/cancel`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"X-Piagent-CSRF":a}});if(!o.ok)throw new r(o.status);return await o.json()}function M(e,t){return h(`/api/v1/source-changes?view=${encodeURIComponent(e)}`,t)}function N(e,t,n){return h(`/api/v1/diffs/${encodeURIComponent(t)}?view=${encodeURIComponent(e)}`,n)}function P(e,t,n){return h(`/api/v1/reviews/${encodeURIComponent(t)}?view=${encodeURIComponent(e)}`,n)}function F(e,t,n){return h(`/api/v1/source-mutations/${encodeURIComponent(t)}?action=${encodeURIComponent(e)}`,n)}function I(e,t=null,n){let r=t?`?hunkRef=${encodeURIComponent(t)}`:``;return h(`/api/v1/source-reverts/${encodeURIComponent(e)}${r}`,n)}function L(e){return h(`/api/v1/commit-summary`,e)}function R(e){return h(`/api/v1/tasks`,e)}function z(e,t){return h(`/api/v1/tasks/${encodeURIComponent(e)}/timeline`,t)}function re(e,t){return h(`/api/v1/tasks/${encodeURIComponent(e)}/recovery-history`,t)}function B(e,t){return h(`/api/v1/tasks/${encodeURIComponent(e)}/handoff-history`,t)}function V(e,t){return h(`/api/v1/tasks/${encodeURIComponent(e)}/subagent-tree`,t)}function H(e){return h(`/api/v1/monitoring/release`,e)}function U(e,t){return h(`/api/v1/log-previews/${encodeURIComponent(e)}`,t)}function W(e=null,t=50,n){let r=new URLSearchParams({limit:String(t)});return e&&r.set(`before`,e),h(`/api/v1/transcript?${r}`,n)}function G(e){return h(`/api/v1/chat/queue`,e)}function K(e){return h(`/api/v1/session-options/models`,e)}function q(e,t){return h(`/api/v1/approvals/${encodeURIComponent(e)}`,t)}async function J(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/approvals/${encodeURIComponent(n.approvalRef)}/decision`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}async function Y(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/chat/messages`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}async function X(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/session-options`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}async function ie(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/lifecycle`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}async function ae(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/control/resume-and-continue`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}async function oe(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/reviews`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}async function se(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/source-mutations`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}async function ce(n,i,a){let o=t();if(!o)throw new r(403);let s=await e(a?`/api/v1/sessions/${encodeURIComponent(a)}/source-reverts`:`/api/v1/source-mutations`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":o},body:JSON.stringify(n)});if(!s.ok)throw new r(s.status);return await s.json()}async function le(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/source-handoffs`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}async function ue(n,i,a){let o=t();if(!o)throw new r(403);let s=await e(`/api/v1/sessions/${encodeURIComponent(n)}/attachments`,{method:`POST`,credentials:`same-origin`,signal:a,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":o},body:JSON.stringify(i)});if(!s.ok)throw new r(s.status);return await s.json()}function Z(e,t,n){return h(e?g(e,t):t,n)}var de=(e,t)=>Z(e,`/api/v1/documents`,t),fe=(e,t,n)=>Z(e,`/api/v1/documents/${encodeURIComponent(t)}`,n);async function pe(n,i){let a=t();if(!a)throw new r(403);let o=await e(`/api/v1/attachments`,{method:`POST`,credentials:`same-origin`,signal:i,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":a},body:JSON.stringify(n)});if(!o.ok)throw new r(o.status);return await o.json()}function me(e,t,n){return h(`/api/v1/projects/${encodeURIComponent(e)}/paths?query=${encodeURIComponent(t)}`,n)}function Q(e,t){return h(`/api/v1/projects/${encodeURIComponent(e)}/commands`,t)}function he(e,t){return h(`/api/v1/sessions/${encodeURIComponent(e)}/questions`,t)}async function ge(n,i,a,o){let s=t();if(!s)throw new r(403);let c=await e(`/api/v1/sessions/${encodeURIComponent(n)}/questions/${encodeURIComponent(i)}/answer`,{method:`POST`,credentials:`same-origin`,signal:o,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":s},body:JSON.stringify(a)});if(!c.ok)throw new r(c.status)}var $=class extends Error{status;code;detail;constructor(e,t,n){super(t),this.status=e,this.code=t,this.detail=n}};function _e(e,t=null,n){return h(`/api/v1/projects/${encodeURIComponent(e)}/branches${t===null?``:`?repository=${encodeURIComponent(t)}`}`,n)}async function ve(r,i,a){let o=t();if(!o)throw new $(403,`mutation-authority-rejected`,null);let s=await e(`/api/v1/projects/${encodeURIComponent(r)}/branches/switch`,{method:`POST`,credentials:`same-origin`,signal:a,headers:{Accept:`application/json`,"Content-Type":`application/json`,"X-Piagent-CSRF":o},body:JSON.stringify(i)});if(s.status===401&&n(),!s.ok){let e=`branch-request-${s.status}`,t=null;try{let n=await s.json();typeof n.error?.code==`string`&&(e=n.error.code),typeof n.error?.detail==`string`&&(t=n.error.detail)}catch{}throw new $(s.status,e,t)}return await s.json()}export{W as $,P as A,he as B,me as C,u as D,l as E,c as F,v as G,b as H,x as I,F as J,a as K,_ as L,o as M,T as N,re as O,D as P,z as Q,s as R,K as S,Q as T,C as U,S as V,w as W,V as X,I as Y,R as Z,B as _,ne as a,X as at,U as b,A as c,ce as ct,q as d,ee as dt,te as et,L as f,ve as ft,N as g,de as h,j as i,oe as it,y as j,H as k,O as l,pe as lt,fe as m,r as n,ie as nt,m as o,se as ot,p,M as q,ge as r,ae as rt,J as s,le as st,$ as t,Y as tt,f as u,ue as ut,G as v,_e as w,k as x,Z as y,E as z};