@teammy/server 0.2.18 → 0.2.19

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 (25) hide show
  1. package/dist/main.js +461 -233
  2. package/dist/web/assets/Assistant-BAhJ1B8n.js +1 -0
  3. package/dist/web/assets/{Computers-DAf8sobH.css → Computers-CBnQX-2p.css} +1 -1
  4. package/dist/web/assets/Computers-hHQYztG9.js +13 -0
  5. package/dist/web/assets/{Conversation-DN9pVRsf.js → Conversation-Bdsoobmv.js} +1 -1
  6. package/dist/web/assets/{Dashboard-B0Dj-KMg.js → Dashboard-De-8jlcE.js} +1 -1
  7. package/dist/web/assets/Dropdown-Dh9Q9fSi.js +55 -0
  8. package/dist/web/assets/{Files-B-iLyRvj.js → Files-DYc1q61J.js} +1 -1
  9. package/dist/web/assets/{Help-B21pS1RH.js → Help-DHZAzK6c.js} +13 -6
  10. package/dist/web/assets/{Markdown-Bh1l6OQM.js → Markdown-Gk89fXoh.js} +2 -2
  11. package/dist/web/assets/{MessageComposer-D9vqKUX5.js → MessageComposer-DFvWZibH.js} +1 -1
  12. package/dist/web/assets/{ResourceLibrary-qg568G4m.js → ResourceLibrary-DYwZzWyh.js} +3 -3
  13. package/dist/web/assets/{TerminalPane-hEQVsy4e.js → TerminalPane-ZhM38vie.js} +1 -1
  14. package/dist/web/assets/{WorkspaceTree-BMZWhAXJ.js → WorkspaceTree-yST2ByxM.js} +1 -1
  15. package/dist/web/assets/{file-links-DvISesr0.js → file-links-CtHFx6cd.js} +1 -1
  16. package/dist/web/assets/index-CWjsEUUy.js +10 -0
  17. package/dist/web/assets/{task-links-BeRoF5ff.js → task-links-ArhNpuGG.js} +1 -1
  18. package/dist/web/downloads/teammy-inbox-skill.zip +0 -0
  19. package/dist/web/downloads/teammy-skill.zip +0 -0
  20. package/dist/web/index.html +2 -2
  21. package/package.json +1 -1
  22. package/dist/web/assets/Assistant-CfsrbTdh.js +0 -1
  23. package/dist/web/assets/Computers-CdwUaH3q.js +0 -13
  24. package/dist/web/assets/Dropdown-Cz5xKbpV.js +0 -55
  25. package/dist/web/assets/index-_W-pw3aC.js +0 -10
@@ -1 +1 @@
1
- import{C as e,Ct as t,M as n,St as r,Tt as i,x as a}from"./Dropdown-Cz5xKbpV.js";import{H as o,V as s}from"./index-_W-pw3aC.js";function c(e){return/^(?:\/[^/?#]+)*\/(?:projects\/[^/?#]+\/(?:dashboard|assistant|messages|channels|computers|files|materials|help|memory|sessions|members|settings)(?:[?#]|$)|api\/v1\/projects\/|downloads\/teammy(?:-inbox)?-skill\.zip(?:[?#]|$))/.test(e)}function l(e,t,n){return`/projects/${encodeURIComponent(e)}/files?${new URLSearchParams({owner:t,path:n})}`}function u(e,t){return`/projects/${encodeURIComponent(e)}/dashboard?${new URLSearchParams({task:t})}`}function d(e,t,n,r={}){let i=new URLSearchParams({owner:t,sessionKey:n});return r.revision!==void 0&&i.set(`revision`,String(r.revision)),r.source===`handoff`?i.set(`source`,`handoff`):r.messageId&&i.set(`messageId`,r.messageId),`/projects/${encodeURIComponent(e)}/sessions?${i}`}var f=r();function p(e){if(!e.startsWith(`/`)&&!/^https?:\/\//i.test(e))return;let n=URL.parse(t(e),location.origin);if(!n||n.origin!==location.origin||n.username||n.password)return;let r=i();if(!n.pathname.startsWith(r+`/projects/`))return;let a=/^\/projects\/([a-z][a-z0-9_-]{0,63})\/dashboard$/.exec(n.pathname.slice(r.length)),o=s.shape.id.safeParse(n.searchParams.get(`task`));if(a&&o.success)return{project:a[1],id:o.data}}function m(t,r,i=!1){let s=(0,f.useCallback)(e=>n(`projects/${encodeURIComponent(t)}/tasks/${encodeURIComponent(r)}`,o,{signal:e}),[t,r]);return a(s,i?3e3:!1,e(t,`task`,r))}export{d as a,c as i,m as n,u as o,l as r,p as t};
1
+ import{C as e,Ct as t,M as n,St as r,Tt as i,x as a}from"./Dropdown-Dh9Q9fSi.js";import{H as o,U as s}from"./index-CWjsEUUy.js";function c(e){return/^(?:\/[^/?#]+)*\/(?:projects\/[^/?#]+\/(?:dashboard|assistant|messages|channels|computers|files|materials|help|memory|sessions|members|settings)(?:[?#]|$)|api\/v1\/projects\/|downloads\/teammy(?:-inbox)?-skill\.zip(?:[?#]|$))/.test(e)}function l(e,t,n){return`/projects/${encodeURIComponent(e)}/files?${new URLSearchParams({owner:t,path:n})}`}function u(e,t){return`/projects/${encodeURIComponent(e)}/dashboard?${new URLSearchParams({task:t})}`}function d(e,t,n,r={}){let i=new URLSearchParams({owner:t,sessionKey:n});return r.revision!==void 0&&i.set(`revision`,String(r.revision)),r.source===`handoff`?i.set(`source`,`handoff`):r.messageId&&i.set(`messageId`,r.messageId),`/projects/${encodeURIComponent(e)}/sessions?${i}`}var f=r();function p(e){if(!e.startsWith(`/`)&&!/^https?:\/\//i.test(e))return;let n=URL.parse(t(e),location.origin);if(!n||n.origin!==location.origin||n.username||n.password)return;let r=i();if(!n.pathname.startsWith(r+`/projects/`))return;let a=/^\/projects\/([a-z][a-z0-9_-]{0,63})\/dashboard$/.exec(n.pathname.slice(r.length)),s=o.shape.id.safeParse(n.searchParams.get(`task`));if(a&&s.success)return{project:a[1],id:s.data}}function m(t,r,i=!1){let o=(0,f.useCallback)(e=>n(`projects/${encodeURIComponent(t)}/tasks/${encodeURIComponent(r)}`,s,{signal:e}),[t,r]);return a(o,i?3e3:!1,e(t,`task`,r))}export{d as a,c as i,m as n,u as o,l as r,p as t};
Binary file
@@ -12,8 +12,8 @@
12
12
  href="./assets/teammy-y-standard-dark-C4LRaRpE.svg"
13
13
  media="(prefers-color-scheme: dark)"
14
14
  />
15
- <script type="module" crossorigin src="./assets/index-_W-pw3aC.js"></script>
16
- <link rel="modulepreload" crossorigin href="./assets/Dropdown-Cz5xKbpV.js">
15
+ <script type="module" crossorigin src="./assets/index-CWjsEUUy.js"></script>
16
+ <link rel="modulepreload" crossorigin href="./assets/Dropdown-Dh9Q9fSi.js">
17
17
  <link rel="stylesheet" crossorigin href="./assets/index-u6KD7Soy.css">
18
18
  </head>
19
19
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teammy/server",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "The centralized Teammy collaboration hub server.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +0,0 @@
1
- import{A as e,C as t,Ct as n,E as r,St as i,T as a,c as o,ct as s,d as c,dt as l,ft as u,gt as d,k as f,l as p,p as m,pt as h,st as g,u as ee,vt as te,w as ne,x as re}from"./Dropdown-Cz5xKbpV.js";import{A as ie,D as ae,E as oe,F as _,M as se,O as ce,R as le,T as v,i as ue,k as y,w as de}from"./index-_W-pw3aC.js";import{t as fe}from"./Markdown-Bh1l6OQM.js";import{i as pe,n as me,r as he,t as ge}from"./Conversation-DN9pVRsf.js";import{t as _e}from"./MessageComposer-D9vqKUX5.js";var b=i(),x=a(),ve=h({topics:g(h({id:d(),title:d(),summary:d(),author:d(),replies:u(),unread:s(),createdAt:d(),updatedAt:d(),delivery:h({available:s(),connected:s(),state:d(),error:d().nullable()})}))}),ye=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),S=e=>e.replace(/[#*_`>]/g,``).replace(/\s+/g,` `).trim();function C({me:i,mode:a=`messages`}){let{projectId:u,request:g}=le(),C=ne(),xe=t(u,i,`${a}-selection`),w=t(u,i,`${a}-drafts`),Se=(0,b.useCallback)(e=>g(`agents/outbox`,ce,{signal:e}),[g]),T=re(Se,3e3,t(u,i,`outbox`)),Ce=(0,b.useCallback)(async e=>a===`messages`?g(`agents/chats`,de,{signal:e}):{chats:(await g(`channels/topics`,ve,{signal:e})).topics.map(e=>({...e,kind:`matter`,state:null}))},[g,a]),E=re(Ce,3e3,t(u,i,a,`chats`)),[D,we]=(0,b.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`chat`);return t?`chat:${t}`:e.get(`message`)??C?.get(xe)??``}),O=D.startsWith(`chat:`)?D.slice(5):``,k=!D||!!O,[A,j]=(0,b.useState)(()=>C?.get(t(u,i,`chat`,O))),M=A?.id===O?A:C?.get(t(u,i,`chat`,O)),N=E.data?.chats.find(e=>e.id===O),P=N&&`delivery`in N?N.delivery:void 0,[Te,F]=(0,b.useState)(),[I,L]=(0,b.useState)(()=>C?.get(w)??{}),R=I[D]??``,Ee=e=>L(t=>({...t,[D]:e})),[z,B]=(0,b.useState)(!1),[V,De]=(0,b.useState)(!1),[Oe,ke]=(0,b.useState)(!1),[Ae,H]=(0,b.useState)(!1),[U,je]=(0,b.useState)(``),[Me,Ne]=(0,b.useState)(``),Pe=(0,b.useRef)(e()),[Fe,W]=(0,b.useState)(``),[Ie,G]=(0,b.useState)(``),K=(0,b.useRef)(new Map),Le=(0,b.useRef)(null),q=(0,b.useRef)(!0),J=(0,b.useRef)(D);J.current=D,(0,b.useEffect)(()=>{A&&C?.set(t(u,i,`chat`,A.id),A)},[C,u,i,A]),(0,b.useEffect)(()=>{C?.set(w,I)},[C,w,I]);function Y(e){J.current=e,we(e),C?.set(xe,e);let t=new URL(location.href);e.startsWith(`chat:`)?t.searchParams.set(`chat`,e.slice(5)):t.searchParams.delete(`chat`),e&&!e.startsWith(`chat:`)&&e!==`debug`?t.searchParams.set(`message`,e):t.searchParams.delete(`message`),history.replaceState(history.state,``,t)}(0,b.useEffect)(()=>{!D&&E.data?.chats.length&&Y(`chat:${E.data.chats[0].id}`)},[D,E.data]);let X=(T.data?.messages??[]).filter(e=>a===`messages`&&e.box===`debug`).reverse(),Z=T.data?.messages.find(e=>e.id===(D===`debug`?Te:D));(0,b.useEffect)(()=>{D!==`debug`&&Z?.conversationId&&Y(`chat:${Z.conversationId}`)},[D,Z?.conversationId]);let Q=X.filter(e=>!e.readAt).map(e=>e.id).join(`,`);(0,b.useEffect)(()=>{Z&&!Z.readAt&&D!==`debug`&&g(`agents/outbox/${Z.id}/read`,y,{method:`POST`}).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),T.reload()}).catch(e=>W(f(e)))},[Z?.id,Z?.readAt,D,g,T.reload]),(0,b.useEffect)(()=>{D===`debug`&&Q&&Promise.all(Q.split(`,`).map(e=>g(`agents/outbox/${e}/read`,y,{method:`POST`}))).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),T.reload()}).catch(e=>W(f(e)))},[D,Q,g,T.reload]),(0,b.useEffect)(()=>{if(G(``),!O)return;let e=!0,o=-1,s=!1,c=new AbortController,l=t=>{!e||t.id!==O||t.cursor<o||(o=t.cursor,s=!0,t.redirect?Y(`chat:${t.redirect}`):t.entry===`channel`&&a!==`channels`?location.replace(n(`/projects/${u}/channels?chat=${t.id}`)):(j(t),G(``)))};g(`agents/chats/${O}`,v,{signal:c.signal}).then(l).catch(n=>{e&&!c.signal.aborted&&(n instanceof r&&[401,403,404].includes(n.status)&&(C?.delete(t(u,i,`chat`,O)),j(e=>e?.id===O?void 0:e)),s||G(f(n)))});let p=t=>{let n=Number(t.lastEventId);return!e||!Number.isSafeInteger(n)||n<=o?!1:(o=n,!0)},m=new EventSource(n(`/api/v1/projects/${encodeURIComponent(u)}/agents/chats/${encodeURIComponent(O)}/events`));m.addEventListener(`snapshot`,t=>{if(e)try{l(v.parse(JSON.parse(t.data)))}catch(e){G(f(e))}}),m.onerror=()=>{e&&G(`对话连接中断,正在重新连接…`)},m.addEventListener(`context`,e=>{if(!p(e))return;let t=v.pick({kind:!0,title:!0,status:!0,visibility:!0,participants:!0,pending:!0,hold:!0,redirect:!0}).parse(JSON.parse(e.data));t.redirect?Y(`chat:${t.redirect}`):j(e=>e?.id===O?{...e,...t,cursor:o}:e)}),m.addEventListener(`message`,e=>{if(!p(e))return;let t=oe.parse(JSON.parse(e.data));j(n=>n?.id===O?{...n,readCursor:Math.max(n.readCursor,t.seq),cursor:Math.max(n.cursor,Number(e.lastEventId)||0),messages:[...n.messages.filter(e=>e.id!==t.id),t].sort((e,t)=>e.seq-t.seq)}:n)}),m.addEventListener(`message_removed`,e=>{if(!p(e))return;let{id:t}=h({id:d()}).parse(JSON.parse(e.data));j(e=>e?.id===O?{...e,cursor:o,messages:e.messages.filter(e=>e.id!==t)}:e)}),m.addEventListener(`run`,e=>{if(!p(e))return;let t=ae.parse(JSON.parse(e.data));j(n=>n?.id===O?{...n,cursor:Math.max(n.cursor,Number(e.lastEventId)||0),runs:n.runs.some(e=>e.id===t.id)?n.runs:[...n.runs,t]}:n)});for(let e of[`delta`,`reset`,`state`])m.addEventListener(e,t=>{if(!p(t))return;let n=JSON.parse(t.data);j(r=>r?.id===O?{...r,cursor:Math.max(r.cursor,Number(t.lastEventId)||0),messages:r.messages.map(t=>t.runId!==n.id||t.role!==`assistant`?t:{...t,body:e===`delta`?t.body+(n.text??``):e===`reset`?``:n.answer??t.body,state:n.state??t.state}),runs:r.runs.map(t=>t.id===n.id?{...t,answer:e===`delta`?t.answer+(n.text??``):e===`reset`?``:n.answer??t.answer,state:n.state??t.state,error:n.error===void 0?t.error:n.error}:t)}:r)});return()=>{e=!1,c.abort(),m.close()}},[u,O,i,g,C]),(0,b.useEffect)(()=>{if(!M||M.id!==O)return;let e=()=>{document.visibilityState===`visible`&&g(`agents/chats/${O}/read`,h({ok:s()}),{method:`POST`,body:{cursor:M.readCursor}}).then(()=>{E.reload(),window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>W(f(e)))},t=setTimeout(e,300);return document.addEventListener(`visibilitychange`,e),()=>{clearTimeout(t),document.removeEventListener(`visibilitychange`,e)}},[O,M?.readCursor,M?.kind,g]),(0,b.useEffect)(()=>{q.current&&Le.current?.scrollIntoView({block:`end`})},[D,A?.messages,Z?.recipients,X.length]);function Re(){window.dispatchEvent(new Event(`teammy:outbox`)),T.reload()}async function $(e){if(q.current=!0,Y(e),W(``),F(void 0),e.startsWith(`chat:`)||e===`debug`)return;let t=T.data?.messages.find(t=>t.id===e)?.conversationId;if(t)Y(`chat:${t}`);else try{await g(`agents/outbox/${e}/read`,y,{method:`POST`}),Re()}catch(e){W(f(e))}}async function ze(){if(!V){De(!0),W(``);try{let e=await g(`agents/chats`,v,{method:`POST`});j(e),await $(`chat:${e.id}`),E.reload()}catch(e){W(f(e))}finally{De(!1)}}}async function Be(t){t.preventDefault();let n=R.trim();if(!n||z||V)return;B(!0),W(``);let r=K.current.get(D);r&&r.text===n||(r={text:n,id:e()},K.current.set(D,r));try{if(k){let e=r.target??O;if(!e){let t=await g(`agents/chats`,v,{method:`POST`});e=t.id,r.target=e,K.current.set(`chat:${e}`,r),L(t=>({...t,[`chat:${e}`]:n})),J.current===D&&(j(t),Y(`chat:${e}`))}let t=await g(`agents/chats/${e}`,ae.extend({conversationId:d().optional()}),{method:`POST`,body:{text:n,requestId:r.id}});t.conversationId&&t.conversationId!==e&&(J.current===D||J.current===`chat:${e}`)&&Y(`chat:${t.conversationId}`),j(n=>n?.id===e?{...n,runs:n.runs.some(e=>e.id===t.id)?n.runs:[...n.runs,t]}:n),E.reload()}else{let e=await g(`agents/outbox/${Z.id}/reply`,h({conversationId:d()}),{method:`POST`,body:{body:n,requestId:r.id}});Re(),J.current===D&&Y(`chat:${e.conversationId}`),E.reload(),F(void 0)}K.current.delete(D),r.target&&K.current.delete(`chat:${r.target}`),L(e=>({...e,[D]:``,...r.target?{[`chat:${r.target}`]:``}:{}}))}catch(e){W(f(e))}finally{B(!1)}}let Ve=a===`channels`?he:ge,He=k&&!M?.closed&&(a!==`channels`||!!O)||!!Z&&!Z.archivedAt,Ue=k&&!M&&(!!O||!E.data);return(0,x.jsxs)(me,{className:a===`channels`?`channel-layout`:``,testId:`assistant-page`,label:k?`Tim对话`:`消息内容`,navigation:(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(se,{title:a===`channels`?`频道`:`对话`,children:(0,x.jsxs)(`div`,{className:`assistant-list-actions`,children:[(0,x.jsx)(p,{className:`assistant-new-chat`,icon:`clear`,label:`清除未读`,disabled:Oe,onClick:()=>{ke(!0),W(``),g(`communication/read`,h({ok:l(!0)}),{method:`POST`,body:{scope:a}}).then(async()=>{window.dispatchEvent(new Event(`teammy:outbox`)),await Promise.all([E.reload(),T.reload()])}).catch(e=>W(f(e))).finally(()=>ke(!1))}}),(0,x.jsx)(p,{className:`assistant-new-chat`,icon:`plus`,label:a===`channels`?`发表话题`:`新建对话`,disabled:V,onClick:()=>a===`channels`?H(!0):void ze(),"data-testid":`assistant-launcher`})]})}),(0,x.jsxs)(`div`,{className:`assistant-message-scroll`,children:[E.loading&&!E.data&&(0,x.jsx)(`p`,{className:`assistant-list-status`,role:`status`,children:`加载中…`}),E.data?.chats.map(e=>(0,x.jsxs)(`button`,{type:`button`,"data-testid":`assistant-chat-${e.id}`,className:`assistant-message-item assistant-chat-item ${O===e.id?`selected`:``}`,"aria-pressed":O===e.id,onClick:()=>void $(`chat:${e.id}`),children:[(0,x.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,x.jsx)(_,{selected:O===e.id,children:(0,x.jsx)(`strong`,{children:e.title})}),a===`channels`&&`summary`in e&&(0,x.jsx)(`span`,{className:`topic-preview`,children:S(String(e.summary)).slice(0,140)}),(0,x.jsxs)(`time`,{dateTime:e.updatedAt,children:[new Date(e.updatedAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,ye(e.updatedAt)]})]}),(0,x.jsx)(`span`,{className:`assistant-message-dot ${e.unread||a!==`channels`&&(e.state===`running`||e.state===`queued`)?`unread`:``}`})]},e.id)),!!X.length&&(0,x.jsxs)(`button`,{type:`button`,"data-testid":`debug-outbox`,className:`assistant-message-item ${D===`debug`?`selected`:``}`,onClick:()=>void $(`debug`),children:[(0,x.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,x.jsx)(_,{selected:D===`debug`,children:(0,x.jsx)(`strong`,{children:`运行提醒`})}),(0,x.jsx)(`span`,{children:S(X.at(-1).body)})]}),(0,x.jsx)(`span`,{className:`assistant-message-dot ${Q?`unread`:``}`})]}),T.data?.messages.filter(e=>a===`messages`&&e.box!==`debug`&&!e.conversationId).sort((e,t)=>Number(!!e.archivedAt)-Number(!!t.archivedAt)).map(e=>(0,x.jsxs)(`button`,{type:`button`,"data-testid":`outbox-${e.id}`,className:`assistant-message-item ${e.archivedAt?`archived`:``} ${D===e.id?`selected`:``}`,onClick:()=>void $(e.id),children:[(0,x.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,x.jsx)(_,{selected:D===e.id,children:(0,x.jsx)(`strong`,{children:S(e.body)})}),(0,x.jsxs)(`time`,{dateTime:e.createdAt,children:[new Date(e.createdAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,ye(e.createdAt)]})]}),(0,x.jsx)(`span`,{className:`assistant-message-dot ${e.readAt?``:`unread`}`})]},e.id))]}),(0,x.jsx)(m,{error:!0,children:T.error||E.error})]}),children:[Ae&&(0,x.jsxs)(c,{id:`new-topic`,title:`发表话题`,onClose:()=>H(!1),children:[(0,x.jsx)(_e,{inset:!0,plain:!0,value:Me,onChange:Ne,label:`正文`,placeholder:`开始一个话题…`,sendLabel:`发表话题`,sendDisabled:z||!U.trim(),heading:(0,x.jsx)(`input`,{className:`topic-title`,"aria-label":`标题`,placeholder:`标题`,required:!0,value:U,onChange:e=>je(e.target.value)}),onSubmit:t=>{t.preventDefault(),B(!0),W(``),g(`channels/topics`,v,{method:`POST`,body:{id:Pe.current,title:U,body:Me}}).then(t=>{j(t),Y(`chat:${t.id}`),H(!1),je(``),Ne(``),Pe.current=e(),E.reload()}).catch(e=>W(f(e))).finally(()=>B(!1))}}),(0,x.jsx)(m,{error:!0,children:Fe})]}),(0,x.jsx)(ie,{title:(0,x.jsx)(`h2`,{children:k?N?.title??M?.title??(O?`无标题`:`Tim`):D===`debug`?`运行提醒`:`项目消息`}),actions:(0,x.jsxs)(x.Fragment,{children:[a===`channels`&&O&&(0,x.jsx)(ue,{conversation:O}),a!==`channels`&&M?.kind===`matter`&&(0,x.jsxs)(`span`,{className:`assistant-participants`,title:M.participants?.join(`、`),children:[M.visibility===`project`?`项目共享 · `:``,M.participants?.join(`、`)]}),a===`channels`&&P?.available&&(P.state===`web`||P.state===`cancelled`||!P.connected)&&(0,x.jsx)(p,{icon:`send`,label:`发布到企业微信频道`,disabled:z,onClick:()=>{B(!0),g(`channels/topics/${O}/publish`,te(),{method:`POST`}).then(()=>E.reload()).catch(e=>W(f(e))).finally(()=>B(!1))}})]})}),a===`channels`&&(0,x.jsx)(m,{error:!0,children:P?.error}),a!==`channels`&&M?.kind===`matter`&&(M.hold||M.pending||M.status===`completed`)&&(0,x.jsx)(`div`,{className:`assistant-matter-state`,role:`status`,children:M.hold?`${M.hold.scope===`all`?`已暂停`:`暂缓修改`} · ${M.hold.reason}`:M.pending?`待确认 · ${M.pending.members.join(`、`)}:${M.pending.question}`:`已完成`}),(0,x.jsxs)(pe,{"data-testid":`assistant-transcript`,onScroll:e=>{let t=e.currentTarget;q.current=t.scrollHeight-t.scrollTop-t.clientHeight<100},children:[k?Ue?(0,x.jsxs)(`div`,{className:`assistant-empty`,"data-testid":`assistant-loading`,children:[(0,x.jsx)(ee,{}),(0,x.jsx)(`p`,{role:`status`,children:Ie||E.error?`暂时无法加载对话`:`加载中…`})]}):M?.messages.length?M.messages.filter(e=>e.body||[`queued`,`running`,`failed`].includes(e.state)).map(e=>(0,x.jsx)(`div`,{className:`assistant-turn`,children:(0,x.jsxs)(Ve,{mine:e.role===`user`&&e.author===i,author:`${e.role===`assistant`?`Tim`:e.author}${e.source===`wecom`?` · 企业微信`:``}`,time:e.createdAt,children:[e.body&&(0,x.jsx)(`div`,{className:`markdown`,children:(0,x.jsx)(fe,{children:e.body})}),e.role===`assistant`&&[`queued`,`running`].includes(e.state)&&(0,x.jsxs)(`span`,{className:`assistant-typing`,"aria-label":`正在回答`,children:[(0,x.jsx)(`i`,{}),(0,x.jsx)(`i`,{}),(0,x.jsx)(`i`,{})]}),e.state===`failed`&&(0,x.jsx)(m,{error:!0,children:M.runs.find(t=>t.id===e.runId)?.error||`本次回答未完成。`})]})},e.id)):(0,x.jsxs)(`div`,{className:`assistant-empty`,children:[(0,x.jsx)(ee,{}),(0,x.jsx)(`p`,{children:`有什么项目问题想聊聊?`})]}):!T.data&&T.loading?(0,x.jsx)(`div`,{className:`assistant-empty`,children:(0,x.jsx)(`p`,{role:`status`,children:`加载中…`})}):D===`debug`?X.map(e=>(0,x.jsx)(be,{item:e,onReply:e.archivedAt?void 0:()=>{F(e.id),Ee(``),W(``)}},e.id)):Z&&(0,x.jsx)(be,{item:Z}),(0,x.jsx)(`div`,{ref:Le})]}),(0,x.jsx)(m,{error:!0,children:Fe||(k?Ie:``)}),He?(0,x.jsx)(_e,{value:R,onChange:Ee,onSubmit:e=>void Be(e),disabled:V,sendDisabled:z||Ue,label:k?`向Tim提问`:`回复消息`}):D!==`debug`&&Z&&(0,x.jsxs)(`div`,{className:`assistant-archived`,children:[(0,x.jsx)(o,{name:`archive`}),`已归档`]})]})}function be({item:e,onReply:t}){return(0,x.jsx)(`div`,{"data-testid":`outbox-thread-${e.id}`,children:(0,x.jsxs)(ge,{author:e.box===`debug`?`运行提醒`:`Tim`,time:e.createdAt,children:[(0,x.jsx)(`div`,{className:`markdown`,children:(0,x.jsx)(fe,{children:e.body})}),t&&(0,x.jsx)(`button`,{type:`button`,className:`assistant-debug-reply`,onClick:t,children:`回复`})]})})}export{C as Assistant};
@@ -1,13 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./TerminalPane-hEQVsy4e.js","./Dropdown-Cz5xKbpV.js","./index-_W-pw3aC.js","./index-u6KD7Soy.css","./Markdown-Bh1l6OQM.js","./task-links-BeRoF5ff.js","./TerminalPane-BrSy-0jI.css"])))=>i.map(i=>d[i]);
2
- import{A as e,C as t,Ct as n,E as r,Q as i,St as a,T as o,c as s,ct as c,d as l,dt as u,ft as d,gt as f,k as p,l as m,lt as h,ot as g,p as _,pt as v,st as y,t as b,v as x,vt as S,w as C,x as w}from"./Dropdown-Cz5xKbpV.js";import{A as T,C as E,L as D,M as O,P as k,R as A,S as j,_ as ee,a as te,b as M,c as ne,d as N,f as re,g as P,h as F,l as ie,m as ae,o as oe,p as se,s as ce,t as le,u as ue,v as de,y as fe,z as pe}from"./index-_W-pw3aC.js";import{i as me,t as he}from"./Markdown-Bh1l6OQM.js";import{a as ge,i as _e,n as ve,t as ye}from"./Conversation-DN9pVRsf.js";import{n as I,t as be}from"./MessageComposer-D9vqKUX5.js";import{l as xe,r as Se}from"./WorkspaceTree-BMZWhAXJ.js";var L=a(),R=o();function Ce({title:e,busy:t,onSave:n}){let[r,i]=(0,L.useState)(!1),[a,o]=(0,L.useState)(e);return r?(0,R.jsx)(`form`,{className:`session-title-form`,onSubmit:t=>{t.preventDefault(),a.trim()&&a.trim()!==e&&n(a.trim()),i(!1)},children:(0,R.jsx)(`input`,{autoFocus:!0,"aria-label":`会话标题`,value:a,disabled:t,onChange:e=>o(e.target.value),onBlur:()=>i(!1),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),i(!1))}})}):(0,R.jsx)(`h2`,{children:(0,R.jsx)(`button`,{type:`button`,className:`session-rename`,title:`重命名会话`,"aria-label":`重命名会话:${e}`,onClick:()=>{o(e),i(!0)},children:e})})}var we=v({id:f().uuid(),directory:f(),title:f(),cwd:f(),createdAt:f(),state:g([`running`,`exited`]),exitCode:d().nullable()}),z={id:f().uuid(),directory:f().min(1).max(200)},Te={cols:d().int().min(2).max(500),rows:d().int().min(1).max(300)};h(`type`,[v({type:u(`create`),...z,...Te,title:f().trim().min(1).max(160)}),v({type:u(`attach`),...z}),v({type:u(`detach`),...z}),v({type:u(`input`),...z,data:f().max(65536)}),v({type:u(`resize`),...z,...Te}),v({type:u(`rename`),...z,title:f().trim().min(1).max(160)}),v({type:u(`close`),...z})]);var Ee=h(`type`,[v({type:u(`size`),id:f(),...Te}),v({type:u(`inventory`),directories:y(f()),terminals:y(we)}),v({type:u(`snapshot`),id:f(),data:f(),cols:d(),rows:d(),seq:d()}),v({type:u(`output`),id:f(),data:f(),seq:d()}),v({type:u(`result`),id:f(),operation:f(),error:f().optional()})]);function De(e,t){let r=(0,L.useRef)(null),i=(0,L.useRef)(new Set),[a,o]=(0,L.useState)(!1),[s,c]=(0,L.useState)([]),[l,u]=(0,L.useState)([]);(0,L.useEffect)(()=>{if(!t)return;let a=!1,s,l,d=()=>{let t=new URL(n(`/api/v1/projects/${encodeURIComponent(e)}/web/terminals`),location.origin);t.protocol=t.protocol===`https:`?`wss:`:`ws:`,l=new WebSocket(t),r.current=l,l.onmessage=e=>{let t=Ee.safeParse(JSON.parse(e.data));if(!t.success||a)return;let n=t.data;n.type===`inventory`&&(u(n.terminals),c(n.directories),o(!0));for(let e of i.current)e(n)},l.onclose=()=>{o(!1),c([]),a||(s=setTimeout(d,2e3))}};return d(),()=>{a=!0,clearTimeout(s),l?.close(),r.current=null}},[e,t]);let d=(0,L.useCallback)(e=>(i.current.add(e),()=>{i.current.delete(e)}),[]),f=(0,L.useCallback)(e=>{if(r.current?.readyState!==WebSocket.OPEN)throw Error(`终端连接已断开,输入未发送。`);r.current.send(JSON.stringify(e))},[]);return{connected:a,directories:s,terminals:l,subscribe:d,send:f,request:(0,L.useCallback)(e=>new Promise((t,n)=>{let r=setTimeout(()=>{i(),n(Error(`暂未收到结果,请检查连接;操作不会自动重发。`))},15e3),i=d(a=>{a.type===`result`&&a.id===e.id&&a.operation===e.type&&(clearTimeout(r),i(),a.error?n(Error(a.error)):t())});try{f(e)}catch(e){clearTimeout(r),i(),n(e)}}),[f,d])}}v({provider:re,cursor:f().optional(),session:F.optional()});var Oe=v({id:F,title:f(),cwd:f(),updatedAt:f().datetime().nullable(),active:c().default(!1)}),ke=v({sessions:y(Oe),nextCursor:f().nullable()}),Ae=v({command:P,history:ke.nullable()});function je(e,t=Date.now()){if(!e)return``;let n=new Date(e),r=Math.max(0,t-n.getTime());return Number.isFinite(r)?r<36e5?`${Math.floor(r/6e4)}min`:r<864e5?`${Math.floor(r/36e5)}h`:r<=6048e5?`${Math.floor(r/864e5)}day`:`${String(n.getFullYear()).slice(-2)}/${String(n.getMonth()+1).padStart(2,`0`)}/${String(n.getDate()).padStart(2,`0`)}`:``}function Me({id:e,label:t,value:n,onChange:r,options:i,placeholder:a,loading:o=!1,disabled:s=!1,empty:c=`没有匹配的选项。`,footer:l}){let[u,d]=(0,L.useState)(!1),[f,p]=(0,L.useState)(``),[h,g]=(0,L.useState)(),_=(0,L.useRef)(null),v=(0,L.useRef)(null),y=(0,L.useRef)(null),b=i.find(e=>e.value===n),x=b?``:n.trim().toLocaleLowerCase(),S=i.filter(e=>`${e.label} ${e.value}`.toLocaleLowerCase().includes(x)),C=S.filter(e=>!e.disabled),w=S.findIndex(e=>e.value===f);(0,L.useEffect)(()=>p(``),[n]),(0,L.useEffect)(()=>{if(!u)return;let e=e=>{_.current?.contains(e.target)||d(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[u]),(0,L.useLayoutEffect)(()=>{if(!u)return;let e=()=>{let e=v.current?.getBoundingClientRect();if(!e)return;let t=innerHeight-e.bottom-16,n=e.top-16,r=t<220&&n>t;g({left:e.left,width:e.width,top:r?void 0:e.bottom+6,bottom:r?innerHeight-e.top+6:void 0,maxHeight:Math.min(320,r?n:t)})};return e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[u]),(0,L.useEffect)(()=>{u&&w>=0&&document.getElementById(`${e}-option-${w}`)?.scrollIntoView({block:`nearest`})},[u,w,e]);function T(e){e.disabled||(r(e.value),d(!1),y.current?.focus())}return(0,R.jsxs)(`div`,{className:`combobox`,ref:_,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||d(!1)},onKeyDown:e=>{e.key===`Escape`&&u&&(e.preventDefault(),e.stopPropagation(),d(!1),y.current?.focus())},children:[(0,R.jsxs)(`div`,{className:`combobox-field`,ref:v,children:[(0,R.jsx)(`input`,{id:e,ref:y,role:`combobox`,"aria-label":t,"aria-autocomplete":`list`,"aria-expanded":u,"aria-controls":`${e}-list`,"aria-activedescendant":u&&w>=0?`${e}-option-${w}`:void 0,autoComplete:`off`,disabled:s,value:b?.label??n,title:b?.value,placeholder:a,onClick:()=>d(!0),onChange:e=>{r(e.target.value),d(!0)},onKeyDown:e=>{if([`ArrowDown`,`ArrowUp`].includes(e.key)){e.preventDefault(),d(!0);let t=C.findIndex(e=>e.value===f),n=t<0?e.key===`ArrowDown`?0:C.length-1:(t+(e.key===`ArrowDown`?1:-1)+C.length)%C.length;p(C[n]?.value??``)}else e.key===`Enter`&&u&&w>=0?(e.preventDefault(),T(S[w])):e.key===`Tab`&&d(!1)}}),(0,R.jsx)(m,{icon:u?`chevronUp`:`chevronDown`,label:`${u?`收起`:`展开`}${t}`,disabled:s,"aria-expanded":u,"aria-controls":`${e}-list`,onClick:()=>{d(!u),y.current?.focus()}})]}),u&&(0,R.jsxs)(`div`,{className:`combobox-popup`,style:h,children:[(0,R.jsxs)(`div`,{id:`${e}-list`,role:`listbox`,"aria-label":t,"aria-busy":o,children:[S.map((t,r)=>(0,R.jsxs)(`button`,{id:`${e}-option-${r}`,type:`button`,role:`option`,"aria-selected":t.value===n,disabled:t.disabled,tabIndex:-1,className:`combobox-option ${t.value===f?`active`:``}`,title:`${t.label} · ${t.value}`,onMouseDown:e=>e.preventDefault(),onClick:()=>T(t),children:[(0,R.jsxs)(`span`,{className:`combobox-option-copy`,children:[(0,R.jsx)(`span`,{children:t.label}),t.description&&(0,R.jsx)(`small`,{children:t.description})]}),t.detail&&(0,R.jsx)(`span`,{className:`combobox-option-detail`,children:t.detail})]},t.value)),o&&(0,R.jsx)(`p`,{className:`combobox-message`,role:`status`,children:`正在读取…`}),!o&&!S.length&&(0,R.jsx)(`p`,{className:`combobox-message`,children:c})]}),l&&(0,R.jsx)(`div`,{className:`combobox-footer`,children:l})]})]})}function Ne({directory:t,provider:n,providers:r,sessions:i,request:a,onClose:o,onImport:s}){let[c,u]=(0,L.useState)(n),[d,f]=(0,L.useState)([]),[h,g]=(0,L.useState)(null),[v,y]=(0,L.useState)(``),[b,x]=(0,L.useState)(null),[S,C]=(0,L.useState)(``),w=(0,L.useRef)(null),T=e=>i.find(t=>!t.hidden&&t.provider===c&&(t.nativeSession??t.resumeSession)===e);async function E(n,r){let i=e();for(await a(`web/local-agents/${t}/history`,P,{method:`POST`,signal:r,body:{id:i,argument:JSON.stringify({provider:c,...n})}});!r.aborted;){let e=await a(`web/local-agents/${t}/history/${i}`,Ae,{signal:r});if(e.command.state===`succeeded`&&e.history)return{...e.history,id:i};if(![`queued`,`running`].includes(e.command.state))throw Error(e.command.error||`读取历史会话失败。`);await new Promise(e=>{let t=()=>{clearTimeout(n),r.removeEventListener(`abort`,t),e()},n=setTimeout(t,1e3);r.addEventListener(`abort`,t,{once:!0})})}throw new DOMException(`Aborted`,`AbortError`)}async function D(n,r,i){let o=T(n.id)??await a(`web/local-agents/${t}/sessions`,ae,{method:`POST`,signal:i,body:{id:e(),title:n.title,provider:c,resumeSession:n.id,historyRequest:r}});i.aborted||s(o)}async function O(e,t){w.current?.abort();let n=new AbortController;w.current=n,x(e),C(``);try{await t(n.signal)}catch(e){n.signal.aborted||C(p(e))}finally{n.signal.aborted||x(null)}}let k=e=>O(`list`,async t=>{let n=await E(e?{cursor:e}:{},t);t.aborted||(f(t=>{let r=[...e?t:[],...n.sessions.map(e=>({...e,requestId:n.id}))];return[...new Map(r.map(e=>[e.id,e])).values()].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``))}),g(n.nextCursor))});(0,L.useEffect)(()=>(f([]),g(null),y(``),k(),()=>w.current?.abort()),[c,t,a]);let A=d.find(e=>e.id===v),j=b===`import`;return(0,R.jsx)(l,{id:`computer-import-session`,title:`导入历史会话`,onClose:o,children:(0,R.jsxs)(`form`,{className:`native-history`,onSubmit:e=>{e.preventDefault(),O(`import`,async e=>{let t=v.trim(),n=T(t);if(n)return s(n);if(A)return D(A,A.requestId,e);let r=await E({session:t},e),i=r.sessions.find(e=>e.id===t);if(!i)throw Error(`找不到此目录中的会话。`);await D(i,r.id,e)})},children:[(0,R.jsx)(oe,{label:`历史会话 Agent`,value:c,onChange:u,providers:[n,...r],disabled:j}),(0,R.jsxs)(`div`,{className:`field`,children:[(0,R.jsx)(`label`,{htmlFor:`native-history-session`,children:`Session`}),(0,R.jsxs)(`div`,{className:`native-history-input-row`,children:[(0,R.jsx)(Me,{id:`native-history-session`,label:`历史会话`,value:v,onChange:y,placeholder:`选择会话或输入 ID`,disabled:j,loading:b===`list`,empty:v?`未找到匹配会话,可直接输入 Session ID。`:`此目录暂无历史会话,可输入 Session ID。`,options:d.map(e=>({value:e.id,label:e.title,description:e.id,detail:T(e.id)?`已接入`:e.active?`工作中`:je(e.updatedAt),disabled:e.active&&!T(e.id)})),footer:(0,R.jsxs)(R.Fragment,{children:[h&&(0,R.jsx)(`button`,{className:`native-history-more`,type:`button`,disabled:!!b,onClick:()=>void k(h),children:`加载更多`}),(0,R.jsx)(m,{icon:`refresh`,label:`刷新历史会话`,disabled:!!b,onClick:()=>void k()})]})},c),(0,R.jsx)(`button`,{type:`submit`,disabled:j||!F.safeParse(v.trim()).success||!!A?.active&&!T(A.id),children:j?`正在导入…`:T(v.trim())?`打开`:`导入`})]})]}),(0,R.jsx)(_,{error:!0,children:S}),(0,R.jsx)(`small`,{className:`muted`,children:`请先退出原终端会话。`})]})})}var B={png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,webp:`image/webp`,gif:`image/gif`,avif:`image/avif`,bmp:`image/bmp`,ico:`image/x-icon`,svg:`image/svg+xml`};function Pe(e,t){let n=e.toLowerCase().split(`.`).at(-1)??``;return t&&Object.values(B).includes(t)?t:Object.hasOwn(B,n)?B[n]:n===`pdf`?`application/pdf`:/^(md|markdown|mdown)$/.test(n)?`text/markdown`:/^html?$/.test(n)?`text/html`:/^(txt|log|csv|tsv|jsonl?|ndjson|ya?ml|toml|ini|cfg|conf|xml|sql|diff|patch|sh|bash|zsh|fish|py|js|jsx|mjs|cjs|ts|tsx|css|scss|vue|svelte|go|rs|c|cc|cpp|h|hpp|java|kt|swift|rb|lua|r|tex|rst|properties|env|lock)$/.test(n)||/^(readme|license|makefile|dockerfile|cmakelists\.txt|\.gitignore)$/i.test(e)?`text/plain`:``}async function Fe(e,t){let n=e.body.getReader(),r=[],i=0,a=(t??0)>E;try{for(;;){let{done:e,value:t}=await n.read();if(e)break;let o=Math.min(t.length,E-i);if(r.push(t.slice(0,o)),i+=o,o<t.length||a&&i===524288){a=!0;break}}}finally{await n.cancel(),n.releaseLock()}return{blob:new Blob(r),truncated:a}}async function Ie(e,t,n,r){let i=e.previewUrl??e.url;if(i.startsWith(`data:`)&&t.startsWith(`image/`))return{format:t,preview:i,download:i};if(!t&&!e.previewUrl)return{format:``};let a=await fetch(i,{credentials:`same-origin`,cache:`no-store`,signal:n});if(!a.ok)throw Error((await a.json().catch(()=>null))?.error?.message??`文件暂不可用。`);if(!t)return await a.body?.cancel(),{format:``};if(t.startsWith(`text/`)){let n=a.headers.get(`X-Teammy-File-Size`)??a.headers.get(`Content-Length`),{blob:i,truncated:o}=await Fe(a,n===null?e.size:Number(n)),s=o?void 0:r(i.slice(0,i.size,`application/octet-stream`)),c;try{c=new TextDecoder(`utf-8`,{fatal:!0}).decode(await i.arrayBuffer(),{stream:o})}catch{return{format:``,download:s}}return c.includes(`\0`)?{format:``,download:s}:{format:t,text:c,truncated:o,download:s}}let o=await a.blob();if(t===`image/svg+xml`)return{format:t,preview:`data:image/svg+xml;charset=utf-8,`+encodeURIComponent(await o.text()),download:r(o.slice(0,o.size,`application/octet-stream`))};if(t===`application/pdf`&&(navigator.pdfViewerEnabled===!1||await o.slice(0,5).text()!==`%PDF-`))return{format:``,download:r(o.slice(0,o.size,`application/octet-stream`))};let s=r(o.slice(0,o.size,t));return{format:t,preview:s,download:s}}function Le({file:e,onClose:t,gallery:n}){let[r,i]=(0,L.useState)(),[a,o]=(0,L.useState)(``),[c,u]=(0,L.useState)(!1),d=(0,L.useRef)(null),f=(0,L.useRef)(null),h=Pe(e.name,e.mimeType),{name:g,url:v,previewUrl:y,size:b}=e;(0,L.useEffect)(()=>{let e=new AbortController,t;return i(void 0),o(``),u(!1),Ie({name:g,url:v,previewUrl:y,size:b},h,e.signal,n=>(e.signal.throwIfAborted(),t=URL.createObjectURL(n),t)).then(t=>{e.signal.aborted||i(t)}).catch(t=>{e.signal.aborted||o(p(t))}),d.current?.focus(),()=>{e.abort(),t&&URL.revokeObjectURL(t)}},[v,b,y,g,h]),(0,L.useEffect)(()=>{f.current?.scrollIntoView({block:`center`})},[r,e.line]);let x=e.line&&r?.text!==void 0?r.text.split(`
3
- `):null,S=(e.line??1)-1,C=h.startsWith(`image/`);return(0,R.jsx)(l,{id:`session-image-lightbox`,title:e.name,label:C?`图片预览`:`文件预览`,onClose:t,onKeyDown:e=>{n&&[`ArrowLeft`,`ArrowRight`].includes(e.key)&&(e.preventDefault(),n.move(e.key===`ArrowLeft`?-1:1))},actions:(0,R.jsxs)(R.Fragment,{children:[n&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(m,{icon:`chevron`,className:`session-image-previous`,label:`上一张图片`,onClick:()=>n.move(-1)}),(0,R.jsxs)(`small`,{children:[n.index+1,` / `,n.count]}),(0,R.jsx)(m,{icon:`chevron`,label:`下一张图片`,onClick:()=>n.move(1)})]}),C&&r?.format&&(0,R.jsx)(m,{icon:c?`zoomOut`:`zoomIn`,label:c?`适合窗口`:`原始尺寸`,"aria-pressed":c,onClick:()=>u(!c)}),(0,R.jsx)(`a`,{className:`icon-button`,href:a?void 0:r?.download??e.url,"aria-disabled":!!a,download:e.name,"aria-label":`下载文件`,title:`下载文件`,children:(0,R.jsx)(s,{name:`download`})})]}),children:(0,R.jsx)(`div`,{ref:d,tabIndex:-1,className:`session-image-viewer`,children:a?(0,R.jsx)(_,{error:!0,children:a}):r?r.format?C?(0,R.jsx)(`div`,{className:`session-image-stage`+(c?` original-size`:``),children:(0,R.jsx)(`img`,{src:r.preview,alt:e.name,onError:()=>i({format:``,download:r.download})})}):r.format===`application/pdf`?(0,R.jsx)(`iframe`,{className:`file-preview-document`,src:r.preview,title:e.name+` 预览`}):r.format===`text/html`&&!e.line?(0,R.jsx)(xe,{name:e.name,url:e.url}):(0,R.jsxs)(`div`,{className:`file-preview-text`,children:[r.format===`text/markdown`&&!e.line?(0,R.jsx)(`article`,{className:`markdown`,children:(0,R.jsx)(he,{children:r.text??``})}):(0,R.jsx)(`pre`,{className:`raw`,children:x&&S<x.length?(0,R.jsxs)(R.Fragment,{children:[S>0&&x.slice(0,S).join(`
4
- `)+`
5
- `,(0,R.jsx)(`mark`,{ref:f,children:x[S]||` `}),x.length>S+1?`
6
- `+x.slice(S+1).join(`
7
- `):``]}):r.text}),r.truncated&&(0,R.jsx)(`small`,{children:`仅显示文件开头,可下载完整文件。`})]}):(0,R.jsx)(`p`,{className:`file-preview-empty`,children:`暂不支持预览此文件。`}):(0,R.jsx)(`p`,{role:`status`,children:`正在读取文件…`})})})}var Re=[],ze=`image/png,image/jpeg,image/webp`;function V(e){if(`image/png,image/jpeg,image/webp`.split(`,`).includes(e.type))return e.type;if(e.type&&e.type!==`application/octet-stream`)return null;let t=e.name.split(`.`).at(-1)?.toLowerCase();return t===`png`?`image/png`:t===`jpg`||t===`jpeg`?`image/jpeg`:t===`webp`?`image/webp`:null}var Be=class{sessions=new Map;listeners=new Set;uploads=new Map;get=e=>this.sessions.get(e)??Re;subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));set(e,t){this.sessions.set(e,t);for(let e of this.listeners)e()}patch(e,t,n){this.set(e,this.get(e).map(e=>e.id===t?{...e,...n}:e))}add(t,n,r,i=!1){if(!t||!n.length)return;if(n.length+this.get(t).length>4)return i?`每条消息最多添加 4 张图片。`:`每条消息最多添加 4 个附件。`;if(Array.from(n).some(e=>i&&(!V(e)||!e.size)||e.size>M))return i?`请选择不超过 2 GB 的 PNG、JPEG 或 WebP 图片。`:`每个附件最多 2 GB。`;let a=Array.from(n,t=>({id:e(),name:t.name.slice(0,200)||`附件`,imageOnly:i,file:t,state:`uploading`}));this.set(t,[...this.get(t),...a]);for(let e of a)this.upload(t,e.id,r)}remove(e,t){this.uploads.get(t)?.abort(),this.uploads.delete(t),this.set(e,this.get(e).filter(e=>e.id!==t))}async upload(e,t,n){let a=this.get(e).find(e=>e.id===t);if(!a?.file||this.uploads.has(t))return;let o=new AbortController;this.uploads.set(t,o),this.patch(e,t,{state:`uploading`,error:``});try{let r=a.file,s=`web/local-agent-sessions/${e}/attachments/${t}`,l;if(r.size>5242880){for(let l=a.uploaded??0;l<r.size;l+=fe){let a=r.slice(l,l+fe);await n(`${s}/parts/${l/fe}?size=${r.size}`,v({ok:c()}),{method:`POST`,signal:o.signal,timeoutMs:i,body:a}),this.patch(e,t,{uploaded:l+a.size})}l=await n(`${s}/finish`,j,{method:`POST`,signal:o.signal,timeoutMs:i,body:{name:a.name,size:r.size,imageOnly:a.imageOnly}})}else{let s=await new Promise((e,t)=>{let n=new FileReader;n.onload=()=>e(String(n.result)),n.onerror=()=>t(Error(`附件读取失败。`)),n.onabort=()=>t(Error(`附件读取已取消。`)),o.signal.addEventListener(`abort`,()=>n.abort(),{once:!0}),n.readAsDataURL(r)});if(o.signal.aborted)return;V(r)&&this.patch(e,t,{preview:s}),l=await n(`web/local-agent-sessions/${e}/${a.imageOnly?`images`:`attachments`}`,j,{method:`POST`,signal:o.signal,timeoutMs:i,body:{id:t,name:a.name,data:s.split(`,`,2)[1]}})}o.signal.aborted||this.set(e,this.get(e).map(e=>e.id===t?{id:t,name:l.name,state:`ready`,attachment:l,imageOnly:e.imageOnly}:e))}catch(n){o.signal.aborted||this.patch(e,t,{state:`failed`,error:p(n),...n instanceof r&&n.code===`ATTACHMENT_INCOMPLETE`?{uploaded:0}:{}})}finally{this.uploads.get(t)===o&&this.uploads.delete(t)}}},Ve=(e,t,r,i=!1)=>n(`/api/v1/projects/${encodeURIComponent(e)}/local-agent/sessions/${encodeURIComponent(t)}/${i?`attachments`:`images`}/${encodeURIComponent(r)}`);function H({images:e,remove:t,retry:n,disabled:r=!1}){let[i,a]=(0,L.useState)(),[o,c]=(0,L.useState)([]),l=e.find(e=>e.id===i),u=e.filter(e=>!e.file&&!o.includes(e.id)),d=u.findIndex(e=>e.id===i);return e.length?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`session-images`,children:e.map(e=>(0,R.jsxs)(`div`,{className:`session-image${e.file?` session-file`:``}`,children:[e.file?(0,R.jsxs)(`button`,{type:`button`,className:`session-file-name`,title:e.name,"aria-label":`预览附件 ${e.name}`,disabled:!e.url||e.state===`uploading`||e.state===`failed`,onClick:()=>a(e.id),children:[(0,R.jsx)(s,{name:`attachment`,size:`small`}),(0,R.jsx)(`span`,{children:e.name})]}):o.includes(e.id)?(0,R.jsxs)(`button`,{type:`button`,className:`session-image-preview session-image-unavailable`,title:`重新读取图片`,onClick:()=>c(t=>t.filter(t=>t!==e.id)),children:[(0,R.jsx)(s,{name:`refresh`,size:`small`}),(0,R.jsx)(`span`,{children:e.name}),(0,R.jsx)(`small`,{children:`图片暂不可用`})]}):(0,R.jsx)(`button`,{type:`button`,className:`session-image-preview`,"aria-label":`预览图片 ${e.name}`,title:e.name,disabled:!e.url,onClick:()=>a(e.id),children:e.url?(0,R.jsx)(`img`,{src:e.url,alt:e.name,loading:`lazy`,onError:()=>c(t=>[...t,e.id])}):(0,R.jsx)(s,{name:`image`})}),e.state===`uploading`&&(0,R.jsx)(`span`,{className:`session-image-status`,role:`status`,"aria-label":`正在上传 ${e.name}`,children:(0,R.jsx)(s,{name:`loading`,size:`small`})}),e.state===`failed`&&(0,R.jsx)(`button`,{type:`button`,className:`session-image-status`,"aria-label":`重试上传 ${e.name}`,title:e.error,disabled:r,onClick:()=>n?.(e.id),children:(0,R.jsx)(s,{name:`refresh`,size:`small`})}),t&&(0,R.jsx)(`button`,{type:`button`,className:`session-image-remove`,"aria-label":`移除${e.file?`附件`:`图片`} ${e.name}`,disabled:r,onClick:()=>t(e.id),children:(0,R.jsx)(s,{name:`close`,size:`small`})}),e.state===`failed`&&(0,R.jsx)(`small`,{className:`session-image-error`,children:e.error})]},e.id))}),l&&(0,R.jsx)(Le,{file:l,onClose:()=>a(void 0),gallery:d>=0&&u.length>1?{index:d,count:u.length,move:e=>a(u[(d+e+u.length)%u.length]?.id)}:void 0},l.id)]}):null}function He({images:e,url:t}){return(0,R.jsx)(H,{images:e.map(e=>({...e,file:e.mimeType===`application/octet-stream`,url:t(e.id)}))})}function Ue(e,n,r){let i=C(),a=t(n,`computer-attachment-uploads`),o=(0,L.useMemo)(()=>{let e=i?.get(a)??new Be;return i?.set(a,e),e},[i,a]),c=(0,L.useSyncExternalStore)(o.subscribe,()=>o.get(e)),[l,u]=(0,L.useState)(``),d=(0,L.useRef)(null),f=(0,L.useRef)(null),m=`${n}:${e}`,h=(0,L.useRef)(m);h.current=m,(0,L.useEffect)(()=>u(``),[e,n]);let g=c.flatMap(e=>e.attachment?[e.attachment]:[]),v=c.some(e=>e.state===`uploading`),y=t=>Ve(n,e,t,!0),x=(t,n=!1)=>u(o.add(e,t,r,n)??``);async function w(){try{let e=await navigator.clipboard.read(),t=[];for(let n of e){let e=n.types.find(e=>ze.split(`,`).includes(e));if(e){let r=await n.getType(e);t.push(new File([r],`剪贴板-${t.length+1}.${e.split(`/`)[1]}`,{type:e}))}}if(h.current!==m)return;t.length?x(t,!0):u(`剪贴板中没有可用的图片。`)}catch(e){h.current===m&&u(e instanceof DOMException&&e.name===`NotAllowedError`?`无法读取剪贴板,请在输入框中粘贴图片或选择图片文件。`:p(e))}}return{files:g,busy:v,count:c.length,failed:c.some(e=>e.state===`failed`),add:x,clear:()=>{for(let t of g)o.remove(e,t.id)},picker:(t,n)=>(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`input`,{ref:f,type:`file`,className:`session-image-file`,multiple:!0,"aria-label":`选择附件`,disabled:t,onChange:e=>{e.target.files&&x(e.target.files),e.target.value=``}}),n&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`input`,{ref:d,type:`file`,className:`session-image-file`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,"aria-label":`选择图片`,disabled:t,onChange:e=>{e.target.files&&x(e.target.files,!0),e.target.value=``}}),(0,R.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":`添加图片`,title:`添加图片,也可粘贴或拖入`,disabled:t,onClick:()=>d.current?.click(),children:(0,R.jsx)(s,{name:`image`,size:`small`})})]}),(0,R.jsx)(b,{id:`session-attachments`,triggerId:`session-attachments-trigger`,label:`附件`,placement:`top`,className:`composer-menu composer-attachments`,routeKey:e,disabled:t,trigger:(0,R.jsx)(s,{name:`attachment`,size:`small`}),children:e=>(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{e(),f.current?.click()},children:[(0,R.jsx)(s,{name:`attachment`,size:`small`}),`选择文件`]}),n&&typeof navigator.clipboard?.read==`function`&&(0,R.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{e(),w()},children:[(0,R.jsx)(s,{name:`paste`,size:`small`}),`粘贴图片`]})]})})]}),preview:t=>(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(H,{images:c.map(e=>({id:e.id,name:e.name,mimeType:e.attachment?.mimeType??e.file?.type,url:e.attachment?y(e.id):e.preview??``,size:e.attachment?.size??e.file?.size??0,file:e.attachment?e.attachment.mimeType===`application/octet-stream`:!!e.file&&(e.file.size>5242880||!V(e.file)),state:e.state,...e.error?{error:e.error}:{}})),disabled:t,remove:t=>{o.remove(e,t),r(`web/local-agent-sessions/${e}/attachments/${t}`,S(),{method:`DELETE`}).catch(()=>{})},retry:t=>void o.upload(e,t,r)}),(0,R.jsx)(_,{error:!0,children:l})]})}}var U={offered:{label:`待本地接收`,icon:`clock`},received:{label:`待本地接收`,icon:`clock`},queued:{label:`排队中`,icon:`clock`},dispatching:{label:`正在连接`,icon:`loading`,spinning:!0},running:{label:`执行中`,icon:`loading`,spinning:!0},cancelled:{label:`已撤回`,icon:`close`},interrupted:{label:`已停止`,icon:`stop`},failed:{label:`未能执行`,icon:`warning`},human_routed:{label:`未送达本地`,icon:`warning`},uncertain:{label:`需要核对`,icon:`warning`}};function W({state:e,error:t}){let n=U[e];if(!n)return null;let r=t?`${n.label}:${t}`:n.label;return(0,R.jsx)(`span`,{className:`execution-status${n.spinning?` is-spinning`:``}`,role:`img`,"aria-label":r,title:r,children:(0,R.jsx)(s,{name:n.icon,size:`small`})})}function We({message:e}){return!e.queue||e.queue.state===`running`?null:(0,R.jsx)(W,{state:e.queue.state,error:e.queue.error})}function Ge({message:t,images:n,status:r,rewind:i,onFile:a}){let o=i?.commands.find(e=>e.kind===`rewind`&&[`queued`,`running`,`uncertain`].includes(e.state)&&JSON.parse(e.argument).messageId===t.id),[c,l]=(0,L.useState)(!!o),[u,d]=(0,L.useState)(o?JSON.parse(o.argument).body:t.body),[f,h]=(0,L.useState)(!1),[g,v]=(0,L.useState)(``),[y,b]=(0,L.useState)(!1),[S,C]=(0,L.useState)(),w=(0,L.useRef)(void 0),T=I(u);(0,L.useLayoutEffect)(()=>{c&&T.current&&(T.current.style.height=`0px`,T.current.style.height=`${T.current.scrollHeight}px`)},[c]);let E=i?.commands.find(e=>e.id===S?.id)??S??o,D=y||E&&[`queued`,`running`].includes(E.state),O=i?.available&&t.source===`web_session`&&t.id.startsWith(`input:`)&&(!t.queue||[`handled`,`interrupted`].includes(t.queue.state));async function k(){if(!i||D||!u.trim())return;let n=JSON.stringify({messageId:t.id,body:u.trim(),expectedLastMessage:i.expectedLastMessage});(E&&[`failed`,`uncertain`].includes(E.state)||w.current?.argument!==n)&&(w.current={id:e(),argument:n}),b(!0),v(``);try{let e=await i.request(`web/local-agent-sessions/${i.session}/commands`,P,{method:`POST`,body:{id:w.current.id,kind:`rewind`,argument:w.current.argument}});C(e),i.refresh()}catch(e){v(p(e))}finally{b(!1)}}return(0,R.jsxs)(`div`,{className:`computer-user-entry${c?` editing`:``}`,children:[(0,R.jsxs)(ye,{mine:!0,author:`你`,time:t.createdAt,children:[n,c?(0,R.jsxs)(`form`,{className:`computer-message-edit`,onSubmit:e=>{e.preventDefault(),k()},children:[(0,R.jsx)(`textarea`,{ref:T,"aria-label":`编辑历史消息`,value:u,onChange:e=>d(e.target.value),disabled:!!D,autoFocus:!0,rows:1}),(0,R.jsxs)(`div`,{className:`computer-message-edit-footer`,children:[(0,R.jsx)(`small`,{children:`替换此后的对话,保留工作区文件`}),(0,R.jsx)(m,{icon:`close`,label:`取消编辑`,disabled:!!D,onClick:()=>{l(!1),v(``),d(t.body)}}),(0,R.jsx)(`button`,{type:`submit`,className:`message-send primary`,"aria-label":D?`正在回退`:`从此处继续`,title:D?`正在回退`:`从此处继续`,disabled:!!D||!u.trim(),children:(0,R.jsx)(s,{name:D?`loading`:`send`,size:`small`})})]}),(0,R.jsx)(_,{error:!0,children:g||(E&&[`failed`,`uncertain`].includes(E.state)?E.error:``)})]}):(0,R.jsx)(`div`,{className:`markdown`,children:(0,R.jsx)(he,{onFile:a,children:t.body})}),!c&&r]}),!c&&(0,R.jsxs)(`div`,{className:`computer-message-actions`,children:[(0,R.jsx)(m,{icon:f?`check`:`copy`,label:f?`已复制`:`复制消息`,onClick:()=>{x(t.body).then(()=>h(!0)).catch(e=>v(p(e)))}}),O&&(0,R.jsx)(m,{icon:`edit`,label:`编辑并从此处继续`,onClick:()=>{d(t.body),l(!0)}})]}),!c&&(0,R.jsx)(_,{error:!0,children:g})]})}function Ke({label:e,meta:t,children:n,className:r=``,onToggle:i}){return(0,R.jsxs)(`details`,{className:`tool-details ${r}`,onToggle:i,children:[(0,R.jsxs)(`summary`,{className:`tool-summary`,title:e,children:[(0,R.jsx)(s,{name:`chevron`,size:`small`}),(0,R.jsx)(`span`,{className:`tool-details-label`,children:e}),t&&(0,R.jsx)(`span`,{className:`tool-details-status`,children:t})]}),n]})}function qe(e){if(e<1e3)return`不到 1 秒`;let t=Math.floor(e/1e3),n=Math.floor(t/60),r=Math.floor(n/60);return[r?`${r} 小时`:``,n%60?`${n%60} 分`:``,t%60?`${t%60} 秒`:``].filter(Boolean).join(` `)}function G({children:e}){return(0,R.jsx)(`div`,{className:`computer-divider`,children:(0,R.jsx)(`span`,{children:e})})}function K({message:e}){let t=e.state===`succeeded`?`已工作`:e.state===`interrupted`?`已停止`:e.state===`failed`?`执行失败`:`需要核对`;return(0,R.jsxs)(G,{children:[t,e.activity?.durationMs===void 0?``:` · ${qe(e.activity.durationMs)}`]})}var q={offered:`待本地接收`,pending:`待投递`,human_routed:`未送达本地`,failed:`失败`,uncertain:`需要核对`};function J(e){let t=[];for(let n of e)if(n.role===`assistant`&&n.activity?.kind===`tool`&&!n.question){let e=t.at(-1);Array.isArray(e)&&e[0].activity?.turnId===n.activity.turnId?e.push(n):t.push([n])}else t.push(n);return t}function Y({text:e,onFile:t}){let n=[],r=0;if(t)for(let{start:i,end:a,link:o}of me(e))n.push(e.slice(r,i),(0,R.jsx)(`button`,{type:`button`,className:`computer-file-link`,onClick:()=>t(o),children:e.slice(i,a)},i)),r=a;return(0,R.jsxs)(`pre`,{children:[n,e.slice(r)]})}function Je({calls:e,onFile:t}){let n=(0,L.useId)(),[r,i]=(0,L.useState)(!1),a=e.length>1,o=[`failed`,`uncertain`,`interrupted`].find(t=>e.some(e=>e.state===t));return(0,R.jsxs)(`div`,{className:a?`tool-details computer-tool-group`:void 0,children:[a&&(0,R.jsxs)(`button`,{type:`button`,className:`tool-summary`,"aria-expanded":r,"aria-controls":n,onClick:()=>i(!r),children:[(0,R.jsx)(s,{name:`chevron`,size:`small`}),e.length,` 次工具调用`,o&&(0,R.jsx)(W,{state:o}),e.some(e=>e.state===`running`)&&(0,R.jsx)(W,{state:`running`})]}),(0,R.jsx)(`div`,{id:n,className:a?`computer-tool-list`:void 0,hidden:a&&!r,children:e.map(e=>(0,R.jsx)(Ke,{className:`computer-tool`,onToggle:a?void 0:e=>i(e.currentTarget.open),label:e.activity?.label??`工具调用`,meta:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(W,{state:e.state}),e.activity?.durationMs!==void 0&&(0,R.jsx)(`span`,{children:qe(e.activity.durationMs)})]}),children:(0,R.jsx)(Y,{text:e.body,onFile:t})},e.id))})]})}function Ye({messages:e,renderQuestion:t,imageUrl:n,renderQueue:r,rewind:i,onFile:a}){let o=new Map(e.filter(e=>e.activity?.kind===`turn`).map(e=>[e.activity.turnId,e])),s=new Map,c=new Set(e.flatMap(e=>{let t=e.question?.planSource;return t?[JSON.stringify([t.turnId,t.itemId])]:[]})),l=new Set(e.flatMap(e=>{let t=e.activity;return t?.kind===`commentary`&&c.has(JSON.stringify([t.turnId,t.itemId]))?[JSON.stringify([t.turnId,e.body])]:[]}));for(let t of e)t.activity?.kind===`answer`&&s.set(t.activity.turnId,t.id);let u=e.filter(({activity:e,body:t})=>e?.kind!==`commentary`||!c.has(JSON.stringify([e.turnId,e.itemId]))&&!l.has(JSON.stringify([e.turnId,t])));return(0,R.jsx)(`div`,{className:`computer-messages`,children:J(u).map(e=>{if(Array.isArray(e))return(0,R.jsx)(Je,{calls:e,onFile:a},e[0].id);let c=e.activity;if(e.role===`system`)return(0,R.jsx)(G,{children:e.body},e.id);if(c?.kind===`turn`)return s.has(c.turnId)?null:(0,R.jsx)(K,{message:e},e.id);if(e.role===`user`)return(0,R.jsx)(Ge,{message:e,rewind:i,onFile:a,images:n&&(e.attachments??e.images)?.length?(0,R.jsx)(He,{images:e.attachments??e.images,url:t=>n(t,!!e.attachments)}):null,status:e.queue&&r?r(e):q[e.state]&&(0,R.jsx)(ge,{label:q[e.state],state:e.state})},e.id);let l=c?.kind===`answer`&&s.get(c.turnId)===e.id?o.get(c.turnId):void 0;return(0,R.jsxs)(L.Fragment,{children:[l&&(0,R.jsx)(K,{message:l}),(0,R.jsx)(`article`,{id:e.question?`computer-question-${e.question.id}`:void 0,tabIndex:e.question?-1:void 0,className:`computer-agent-message ${c?.kind===`commentary`?`computer-commentary`:``} ${e.question?`question-bubble`:``}`,children:e.question?t(e.question):(0,R.jsx)(`div`,{className:`markdown`,children:(0,R.jsx)(he,{onFile:a,children:e.body})})})]},e.id)})})}function X({disabled:e,onSend:t,initialValue:n=``,placeholder:r}){let[i,a]=(0,L.useState)(n),[o,c]=(0,L.useState)(!!n),l=`其他回答`,u=(0,L.useRef)(null),d=(0,L.useCallback)(e=>{if(!u.current)return;let t=document.createElement(`canvas`).getContext(`2d`);if(!t)return;t.font=getComputedStyle(e).font;let n=Math.max(...(i||`${l}…`).split(`
8
- `).map(e=>t.measureText(e).width));u.current.style.setProperty(`--reply-width`,`${Math.ceil(n+(o?52:26))}px`)},[i,o,l]),f=I(i,d);return(0,R.jsxs)(`form`,{ref:u,className:`inline-reply${o?` active`:``}`,onFocus:()=>c(!0),onBlur:e=>{!i&&!e.currentTarget.contains(e.relatedTarget)&&c(!1)},onSubmit:n=>{n.preventDefault(),!e&&i.trim()&&t(i.trim()).then(e=>{e&&a(``)})},children:[(0,R.jsx)(`textarea`,{ref:f,rows:1,"aria-label":`自定义回答`,placeholder:r??`${l}…`,value:i,disabled:e,onChange:e=>a(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&!t.nativeEvent.isComposing&&(t.preventDefault(),!e&&i.trim()&&t.currentTarget.form?.requestSubmit())}}),o&&(0,R.jsx)(`button`,{className:`inline-reply-send`,type:`submit`,disabled:e||!i.trim(),"aria-label":`发送${l}`,title:`发送${l}`,children:(0,R.jsx)(s,{name:`send`,size:`small`})})]})}function Xe(e){return e.state===`pending`&&(!e.response||[`human_routed`,`failed`,`handled`].includes(e.submissionState??``))}function Ze({question:t,session:n,request:r,refresh:i}){let[a,o]=(0,L.useState)({}),[l,u]=(0,L.useState)({}),[d,f]=(0,L.useState)(``),[m,h]=(0,L.useState)(!1),[g,y]=(0,L.useState)(!1),[b,x]=(0,L.useState)(``),C=(0,L.useRef)(null),w=(0,L.useRef)(!1),T=(0,L.useRef)(void 0);(0,L.useEffect)(()=>{if(t.state!==`pending`||w.current||!C.current)return;let e=!1,i=()=>{if(!e||document.visibilityState!==`visible`||!C.current)return;let i=C.current.getBoundingClientRect();i.bottom>0&&i.top<innerHeight&&r(`web/local-agent-sessions/${n}/questions/${t.id}/presented`,v({ok:c()}),{method:`POST`}).then(()=>{w.current=!0,window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>f(p(e)))},a=new IntersectionObserver(t=>{e=t.some(e=>e.isIntersecting),i()});return a.observe(C.current),document.addEventListener(`visibilitychange`,i),()=>{a.disconnect(),document.removeEventListener(`visibilitychange`,i)}},[t.id,t.state,n,r]);async function E(a){let o=JSON.stringify(a);T.current?.fingerprint!==o&&(T.current={fingerprint:o,value:{...a,id:e()}}),h(!0),f(``);try{return await r(`web/local-agent-sessions/${n}/questions/${t.id}/answers`,S(),{method:`POST`,body:T.current.value}),T.current=void 0,i(),!0}catch(e){return f(p(e)),!1}finally{h(!1)}}let[D,O]=(0,L.useState)(Date.now);(0,L.useEffect)(()=>{if(!t.approval||t.state!==`pending`||t.autoApproveAt==null)return;O(Date.now());let e=setInterval(()=>O(Date.now()),1e3);return()=>clearInterval(e)},[t.approval,t.state,t.autoApproveAt]);let k=t.autoApprove!==!1&&t.autoApproveAt!=null?Math.max(0,Math.ceil((t.autoApproveAt-D)/1e3)):null,A=t.response,j=t.state===`answered`,ee=[`expired`,`cancelled`].includes(t.state),te=[`human_routed`,`failed`,`handled`].includes(t.submissionState??``)&&!j,M=Xe(t),ne=t.kind===`plan`,N=t.actions?.find(e=>e.id===A?.actionId),re=ee?`已过期`:t.state===`uncertain`||t.submissionState===`uncertain`?`需核对`:j?ne?N?.label??`已处理`:t.approval?A?.decision===!0?`已允许`:A?.decision===!1?`已拒绝`:`已处理`:N?N.label:A?``:`已回答`:te?`请重新提交`:A?`正在提交`:``,P=ee||A?.decision===!1||te?`close`:j?`check`:`clock`,F=t.questions.length>1||t.questions.some(e=>e.multiSelect),ie=(e=a)=>E({body:t.questions.length===1?e[t.questions[0].id]||(l[t.questions[0].id]??[]).join(`、`):JSON.stringify(e),...t.kind||t.questions.some(e=>e.multiSelect)?{answers:e}:{},...t.questions.some(e=>e.multiSelect)?{selections:l}:{}});if(t.delivery===`async`&&(j||ee)){let e=j&&A?t.questions.flatMap(e=>[...A.selections?.[e.id]??[],A.answers[e.id]].filter(Boolean)):[];return e.length?(0,R.jsxs)(`div`,{className:`question-response native-async-answer`,children:[(0,R.jsx)(s,{name:`check`,size:`small`}),(0,R.jsx)(`span`,{children:e.join(`
9
- `)})]}):null}return(0,R.jsxs)(`div`,{className:`native-question ${ne?`native-plan`:``} ${M?`native-question-pending`:``}`,ref:C,children:[ne?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`native-plan-heading`,children:[(0,R.jsx)(s,{name:`file`,size:`small`}),(0,R.jsx)(`span`,{children:`实施计划`})]}),M?(0,R.jsx)(`div`,{className:`native-plan-content markdown`,children:(0,R.jsx)(he,{children:t.plan??``})}):(0,R.jsxs)(`details`,{className:`native-plan-history markdown`,children:[(0,R.jsx)(`summary`,{children:`查看计划`}),(0,R.jsx)(he,{children:t.plan??``})]}),M&&(0,R.jsxs)(R.Fragment,{children:[!g&&(0,R.jsx)(`div`,{className:`question-actions native-plan-actions ${t.actions&&t.actions.length>3?`native-plan-actions-expanded`:``}`,children:t.actions?.map(e=>(0,R.jsx)(`button`,{type:`button`,disabled:m,title:e.description,className:e.id===`implement`?`primary`:``,onClick:()=>e.id===`revise`?y(!0):void E({body:e.label,actionId:e.id}),children:e.label},e.id))}),!g&&t.actions?.find(e=>e.id===`implement`)?.description&&(0,R.jsxs)(`small`,{className:`native-plan-note muted`,children:[`开始实施:`,t.actions.find(e=>e.id===`implement`).description]}),g&&(0,R.jsxs)(`form`,{className:`native-plan-feedback`,onSubmit:e=>{e.preventDefault(),E({body:b,actionId:`revise`})},children:[(0,R.jsxs)(`label`,{children:[`修改意见`,(0,R.jsx)(`textarea`,{autoFocus:!0,value:b,onChange:e=>x(e.target.value),placeholder:`说明希望调整的部分,Agent 将修改后再次请求确认`})]}),(0,R.jsxs)(`div`,{className:`question-actions native-plan-feedback-actions`,children:[(0,R.jsx)(`button`,{className:`primary`,disabled:m||!b.trim(),children:`提交修改意见`}),(0,R.jsx)(`button`,{type:`button`,disabled:m,onClick:()=>y(!1),children:`返回计划`})]})]})]}),!M&&A?.actionId===`revise`&&A.answers.feedback&&(0,R.jsx)(`div`,{className:`question-response`,children:A.answers.feedback})]}):t.approval?(0,R.jsxs)(`div`,{className:`native-approval-row`,children:[(0,R.jsx)(Ke,{className:`native-approval-details`,label:t.questions.map(e=>e.text.split(`
10
- `).filter(Boolean).slice(0,2).join(` · `)).join(` · `),children:(0,R.jsx)(`pre`,{children:t.questions.map(e=>e.text).join(`
11
-
12
- `)})}),M?(0,R.jsxs)(`div`,{className:`native-approval-options`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`primary`,disabled:m,"aria-label":`允许`,title:k===null?void 0:`倒计时结束后自动允许本次操作`,onClick:()=>void E({body:`允许`,decision:!0}),children:[`允许`,k!==null&&(0,R.jsxs)(`span`,{"aria-hidden":`true`,children:[`(`,k,`s)`]})]}),(0,R.jsx)(`button`,{type:`button`,disabled:m,onClick:()=>void E({body:`拒绝`,decision:!1}),children:`拒绝`})]}):re&&(0,R.jsxs)(`small`,{className:`question-result`,children:[(0,R.jsx)(s,{name:P,size:`small`}),re]})]}):(0,R.jsxs)(R.Fragment,{children:[t.questions.map(e=>(0,R.jsxs)(`div`,{className:`native-question-part`,children:[(0,R.jsx)(`p`,{children:e.text}),M&&(0,R.jsx)(`div`,{className:`question-options ${Object.values(e.descriptions??{}).some(Boolean)?`question-options-described`:``}`,children:e.options.map(t=>(0,R.jsxs)(`button`,{type:`button`,disabled:m,"aria-pressed":e.multiSelect?l[e.id]?.includes(t)??!1:a[e.id]===t,onClick:()=>{if(e.multiSelect){u(n=>({...n,[e.id]:n[e.id]?.includes(t)?n[e.id].filter(e=>e!==t):[...n[e.id]??[],t]}));return}let n={...a,[e.id]:t};o(n),F||ie(n)},children:[(0,R.jsxs)(`span`,{className:`question-option-label`,children:[e.multiSelect&&(0,R.jsx)(`span`,{"aria-hidden":`true`,className:`question-check`,children:l[e.id]?.includes(t)&&(0,R.jsx)(s,{name:`check`,size:`small`})}),t]}),e.descriptions?.[t]&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`question-option-separator`,"aria-hidden":`true`,children:`|`}),(0,R.jsx)(`span`,{className:`question-option-description`,title:e.descriptions[t],children:e.descriptions[t]})]})]},t))}),e.freeText&&M&&(0,R.jsx)(X,{initialValue:e.initialValue,placeholder:e.placeholder,disabled:m,onSend:async t=>{let n={...a,[e.id]:t};return o(n),F?!0:ie(n)}}),M&&F&&a[e.id]&&!e.options.includes(a[e.id])&&(0,R.jsx)(`small`,{children:a[e.id]}),!M&&!t.approval&&(A?.answers[e.id]||A?.selections?.[e.id]?.length)&&(0,R.jsxs)(`div`,{className:`question-response`,children:[(0,R.jsx)(s,{name:j?`check`:`clock`,size:`small`}),(0,R.jsx)(`span`,{children:[...A.selections?.[e.id]??[],A.answers[e.id]].filter(Boolean).join(`、`)})]})]},e.id)),M&&t.actions?.length&&(0,R.jsx)(`div`,{className:`question-actions`,children:t.actions.map(e=>(0,R.jsx)(`button`,{disabled:m,onClick:()=>void E({body:e.label,actionId:e.id}),children:e.label},e.id))}),M&&F&&(0,R.jsx)(`div`,{className:`question-actions`,children:(0,R.jsx)(`button`,{disabled:m||t.questions.some(e=>!a[e.id]?.trim()&&!l[e.id]?.length),onClick:()=>void ie(),children:`回答`})})]}),re&&(!t.approval||ne)&&(0,R.jsxs)(`small`,{className:`question-result`,children:[(0,R.jsx)(s,{name:P,size:`small`}),re]}),(0,R.jsx)(_,{error:!0,children:d})]})}function Qe({session:t,active:n,commands:r,request:i,refresh:a,onError:o}){let[c,l]=(0,L.useState)(!1),[u,d]=(0,L.useState)(),f=(0,L.useRef)(void 0),m=r.find(e=>e.id===u?.id)??u,h=c||m&&[`queued`,`running`].includes(m.state)||r.some(e=>e.kind===`stop`&&[`queued`,`running`].includes(e.state));if(!n&&!h)return null;async function g(){if(!h){f.current??=e(),l(!0),o(``);try{let e=await i(`web/local-agent-sessions/${t}/commands`,P,{method:`POST`,body:{id:f.current,kind:`stop`}});d(e),f.current=void 0,a()}catch(e){o(p(e))}finally{l(!1)}}}return(0,R.jsxs)(`button`,{type:`button`,className:`message-stop`,"aria-label":h?`正在停止`:`停止当前轮`,title:h?`正在停止`:`停止当前轮`,disabled:!!h,onClick:()=>void g(),children:[(0,R.jsx)(`span`,{className:`message-stop-ring`,"aria-hidden":`true`}),(0,R.jsx)(s,{name:`stop`,size:`small`})]})}var $e={minimal:`极低`,low:`低`,medium:`中`,high:`高`,xhigh:`极高`,max:`最高`,ultra:`极致`,none:`无`,off:`关闭`};function et({id:e,label:t,current:n,options:r,disabled:i,onSelect:a}){let o=r.find(e=>e.value===n);return(0,R.jsx)(b,{id:`${e}-menu`,triggerId:e,placement:`top`,className:`composer-menu composer-choice`,label:`选择${t}`,disabled:i,routeKey:n,trigger:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{title:`${t}:${o?.label??n}`,children:o?.shortLabel??o?.label??n}),(0,R.jsx)(s,{name:`chevronDown`,size:`small`})]}),children:e=>(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`composer-menu-heading`,children:t}),r.map(t=>(0,R.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-label":t.label,onClick:()=>{e(),a(t.value)},children:[(0,R.jsxs)(`span`,{className:`composer-option-copy`,children:[(0,R.jsx)(`span`,{children:t.label}),t.description&&(0,R.jsx)(`small`,{children:t.description})]}),t.value===n&&(0,R.jsx)(s,{name:`check`,size:`small`})]},t.value))]})})}function tt({session:e,models:t,busy:n,available:r,online:i,commands:a,controls:o,draft:c,onInsert:l,onConfig:u}){let[d,f]=(0,L.useState)(!1);(0,L.useEffect)(()=>{/^[/$]([^\s]*)$/.exec(c)?f(!0):f(!1)},[c]);let p=e.config.model??e.effectiveConfig?.model,m=t.find(e=>e.id===p||e.resolvedModel===p)??(e.config.model?void 0:t.find(e=>e.isDefault)),h=n||!r,g=e.provider===`claude`,_=e.provider===`cursor`,v=e.provider===`pi`,y=o??ee(e.provider),x=m?.effortLabel??`思考强度`,S=e=>m?.effortLabel?e:$e[e]??e,C=e.appliedRevision===e.revision?e.effectiveConfig?.mode:void 0,w=t.find(e=>e.isDefault)?.id??(e.config.model?null:e.effectiveConfig?.model),T=t.find(e=>e.id===w)?.name??w,E=e=>g?e.replace(/^Claude\s+/,``):e,D=[{value:``,label:T?`默认 · ${T}`:t.length?`默认模型`:`模型未获取`,shortLabel:T?E(T):t.length?`默认模型`:`模型`},...t.map(e=>({value:e.id,label:e.name,shortLabel:E(e.name)}))];e.config.model&&!t.some(t=>t.id===e.config.model)&&D.push({value:e.config.model,label:e.config.model,shortLabel:E(e.config.model)});let O=m?.id===e.effectiveConfig?.model?e.effectiveConfig?.effort:m?.defaultEffort,k=[{value:``,label:O?`默认 · ${S(O)}`:`默认${x}`,shortLabel:O?S(O):m?.effortLabel??`强度`},...(m?.efforts??[]).map(e=>({value:e,label:S(e)}))];return e.config.effort&&!k.some(t=>t.value===e.config.effort)&&k.push({value:e.config.effort,label:S(e.config.effort)}),(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(b,{id:`session-commands`,triggerId:`session-command-trigger`,label:`命令与 Skills`,placement:`top`,className:`composer-menu composer-commands`,routeKey:e.id,trigger:(0,R.jsx)(s,{name:`command`,size:`small`}),open:d,onOpenChange:f,focusFirst:!1,disabled:h||!i,children:e=>(0,R.jsxs)(R.Fragment,{children:[[...a].sort((e,t)=>e.name.localeCompare(t.name,`en`)).map(t=>(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,title:[t.description,t.path].filter(Boolean).join(`
13
- `),onClick:()=>{e(),l(t)},children:(0,R.jsxs)(`span`,{className:`composer-command-row`,children:[(0,R.jsxs)(`span`,{className:`composer-command-name`,children:[t.prefix??(t.kind===`skill`?`$`:`/`),t.name]}),(0,R.jsx)(`small`,{children:t.description})]})},`${t.kind}:${t.path??t.name}`)),!a.length&&(0,R.jsx)(`div`,{className:`composer-menu-heading`,children:`尚未获取命令`})]})}),(0,R.jsx)(et,{id:`session-model`,label:`模型`,current:e.config.model??``,options:D,disabled:h,onSelect:n=>{let r=t.find(e=>e.id===n);u({...e.config,model:n||null,..._?{options:{}}:{},effort:e.config.effort&&r?.efforts.includes(e.config.effort)?e.config.effort:null})}}),(!_&&!v&&e.provider!==`opencode`||(m?.efforts.length??0)>0||!!e.config.effort)&&(0,R.jsx)(et,{id:`session-effort`,label:x,current:e.config.effort??``,options:k,disabled:h,onSelect:t=>u({...e.config,effort:t||null})}),m?.options?.map(t=>(0,R.jsx)(et,{id:`session-option-${t.id}`,label:t.name,current:e.config.options?.[t.id]??``,options:[{value:``,label:`默认 · ${t.choices.find(e=>e.value===t.defaultValue)?.label??t.defaultValue}`},...t.choices],disabled:h,onSelect:n=>{let r={...e.config.options};n?r[t.id]=n:delete r[t.id],u({...e.config,options:r})}},t.id)),y.map(t=>(0,R.jsx)(et,{id:t.key===`mode`&&!g?`session-mode`:`session-permission`,label:t.label,current:t.key===`mode`?C??e.config.mode??t.defaultValue:e.config.permission,options:t.choices,disabled:h,onSelect:n=>u(t.key===`mode`?{...e.config,mode:n||void 0}:{...e.config,permission:n})},t.key))]})}var nt=(0,L.lazy)(()=>le(()=>import(`./TerminalPane-hEQVsy4e.js`),__vite__mapDeps([0,1,2,3,4,5,6]),import.meta.url)),rt=v({ok:c()}),it={idle:`空闲`,working:`工作中`,waiting:`等待回答`,queued:`等待执行`,uncertain:`需要核对`,human:`人工处理`,offered:`待本地接收`,accepted:`本地已接手`,human_routed:`未送达本地`,pending:`待投递`,sent:`已发送`,succeeded:`已完成`,running:`进行中`,failed:`失败`};function Z({navigate:e,memberId:t}){let{request:n,projectId:r}=A(),i=(0,L.useCallback)(e=>n(`web/local-agent-settings`,N,{signal:e}),[n]),a=w(i,3e4);return(0,L.useEffect)(()=>{let e=()=>void a.reload();return window.addEventListener(`teammy:local-access`,e),()=>window.removeEventListener(`teammy:local-access`,e)},[a.reload]),a.error?(0,R.jsx)(_,{error:!0,children:a.error}):a.data?(0,R.jsx)(Q,{localAvailable:a.data.accessible,navigate:e,memberId:t},`${r}/${t}`):null}function Q({localAvailable:r,navigate:i,memberId:a}){let o=A(),c=C(),u=t(o.projectId,a,`computer-selection`),d=t(o.projectId,a,`computer-drafts`),f=c?.get(u),[h,g]=(0,L.useState)(()=>new Set),[v,y]=(0,L.useState)(()=>({project:o.projectId,directory:new URLSearchParams(location.search).get(`directory`)??f?.directory??``,session:new URLSearchParams(location.search).get(`session`)??(new URLSearchParams(location.search).has(`terminal`)?``:f?.session??``),terminal:new URLSearchParams(location.search).get(`terminal`)??(new URLSearchParams(location.search).has(`session`)?``:f?.terminal??``)})),[x,E]=(0,L.useState)(``),[j,ee]=(0,L.useState)(!1),[M,N]=(0,L.useState)(!1),[P,F]=(0,L.useState)(()=>c?.get(d)??{}),oe=P[v.session]??``,le=e=>F(t=>({...t,[v.session]:typeof e==`function`?e(t[v.session]??``):e}));(0,L.useEffect)(()=>{c?.set(d,P)},[c,d,P]);let[fe,me]=(0,L.useState)(``),[he,ye]=(0,L.useState)(!1),[I,xe]=(0,L.useState)(`codex`),[we,z]=(0,L.useState)(!1),[Te,Ee]=(0,L.useState)(``),[Oe,ke]=(0,L.useState)(),[Ae,Me]=(0,L.useState)(Date.now);(0,L.useEffect)(()=>{let e=setInterval(()=>Me(Date.now()),6e4);return()=>clearInterval(e)},[]);let B=(0,L.useRef)(null),Fe=(0,L.useRef)(!0),Ie=(0,L.useRef)(new URLSearchParams(location.search).get(`question`)),Re=(0,L.useRef)(null),ze=(0,L.useRef)(void 0),V=(0,L.useRef)(e()),Be=(0,L.useCallback)(async e=>r?(await o.request(`web/local-agent-computers`,ie,{signal:e})).computers.map(e=>({...e,project:o.projectId})):[],[o,r]),H=w(Be,3e3),He=(H.data??[]).flatMap(e=>e.directories.map(t=>({c:e,d:t,label:ue(H.data??[],e,t)}))).sort((e,t)=>e.label.localeCompare(t.label)),U=H.data?.find(e=>e.project===v.project&&e.directories.some(e=>e.id===v.directory)),W=De(o.projectId,r),Ge=W.terminals.find(e=>e.id===v.terminal),Ke=(0,L.useRef)(Ge);Ge&&(Ke.current=Ge);let qe=Ge??(Ke.current?.id===v.terminal?Ke.current:void 0),G=U?.directories.find(e=>e.id===v.directory),K=H.data?.find(e=>e.directories.some(e=>e.id===Te))??U,q=K?.directories.find(e=>e.id===Te)??G;D(v.project);let J=(0,L.useCallback)((e,t,n)=>D(v.project).request(e,t,n),[v.project]),Y=Ue(v.session,v.project,J),Je=(0,L.useCallback)(e=>v.session&&r?J(`web/local-agent-sessions/${v.session}`,se,{signal:e}):Promise.resolve(null),[J,v.session,r]),X=w(Je,15e3),[$e,et]=(0,L.useState)(),Z=$e?.session.id===v.session&&(!X.data||$e.cursor>=X.data.cursor)?$e:X.data;(0,L.useEffect)(()=>{if(!v.session||!r)return;let e=new EventSource(n(`/api/v1/projects/${encodeURIComponent(v.project)}/web/local-agent-sessions/${encodeURIComponent(v.session)}/events`)),t=!0;return e.addEventListener(`snapshot`,e=>{try{let n=se.parse(JSON.parse(e.data));t&&et(e=>e?.session.id===n.session.id&&e.cursor>n.cursor?e:n)}catch(e){E(p(e))}}),()=>{t=!1,e.close()}},[v.project,v.session,r]),(0,L.useEffect)(()=>{Fe.current=!0,Re.current=null},[v.project,v.session]);let Q=Z?.session.id===v.session?Z.session:void 0,at=Q?Z.messages.flatMap(({question:e})=>e?.delivery===`async`&&Xe(e)?[e.id]:[]):[];function ot(e){let t=B.current,n=document.getElementById(`computer-question-${e}`);return!t||!n||!t.contains(n)||!n.getClientRects().length?!1:(Fe.current=!1,Re.current=e,t.scrollTop+=n.getBoundingClientRect().top-t.getBoundingClientRect().top-16,n.focus({preventScroll:!0}),!0)}(0,L.useEffect)(()=>{if(Q&&B.current){if(Ie.current){let e=Ie.current;if(Ie.current=null,ot(e))return}Fe.current&&(B.current.scrollTop=B.current.scrollHeight)}},[Q?.id,G?.id,Z?.cursor,Z?.messages.length]);function st({path:e,line:t}){let r=e.split(`/`).at(-1),i=/\/\.workspace\/\.teammy-attachments\/([0-9a-f-]{36})\/[^/]+$/i.exec(e);if(!v.terminal&&Q&&i){let e=Z?.messages.flatMap(e=>e.attachments??[]).find(e=>e.id===i[1]);ke({...e,name:e?.name??r,line:t,url:Ve(v.project,Q.id,i[1],!0)});return}let a=v.terminal?qe?.directory:Q?.executionDirectory??Q?.directory;if(!a)return;let o=n(`/api/v1/projects/${encodeURIComponent(v.project)}/web/local-agents/${encodeURIComponent(a)}/file?${new URLSearchParams({path:e})}`),s=Pe(r);ke({name:r,line:t,url:o,previewUrl:o+(s.startsWith(`text/`)?`&view=text`:s?``:`&view=info`)})}let ct=U?.capabilities.includes(`local-sessions-v1`),$=(e,t,n=``,r=``)=>{ke(void 0),y({project:e,directory:t,session:n,terminal:r}),c?.set(u,{directory:t,session:n,terminal:r}),ye(!1),z(!1),E(``);let i=new URL(location.href);(v.session!==n||r)&&(i.searchParams.delete(`question`),Ie.current=null),i.searchParams.delete(`view`),i.searchParams.delete(`section`),i.searchParams.set(`directory`,t),r?i.searchParams.set(`terminal`,r):i.searchParams.delete(`terminal`),n?i.searchParams.set(`session`,n):i.searchParams.delete(`session`),e===o.projectId&&history.replaceState(null,``,i)};(0,L.useEffect)(()=>{let e=H.data?.find(e=>e.sessions.some(e=>e.id===v.session))??H.data?.find(e=>e.directories.length);if(!v.directory&&e?.directories.length){let t=e.directories[0],n=e.sessions.find(e=>e.id===v.session);$(e.project,n?.directory??t.id,n?.id??t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id)}},[H.data]),(0,L.useEffect)(()=>{if(!Q)return;let e=()=>{document.visibilityState===`visible`&&J(`web/local-agent-sessions/${Q.id}/read`,rt,{method:`POST`}).catch(e=>E(p(e)))};return e(),document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Q?.id,Z?.messages.at(-1)?.seq,J]);async function lt(e){ee(!0),E(``);try{await e(),await Promise.all([X.reload(),H.reload()])}catch(e){E(p(e))}finally{ee(!1)}}function ut(e,t){return lt(async()=>{if(await o.request(`web/local-agent-sessions/${e.id}/metadata`,ae,{method:`PUT`,body:{expectedRevision:e.metadataRevision,...t}}),t.hidden&&v.session===e.id){let t=U?.sessions.find(t=>t.directory===e.directory&&t.id!==e.id&&!t.hidden);$(v.project,e.directory,t?.id)}})}function dt(e){let t=new URLSearchParams({tab:`connect`,directory:e,session:v.session});i(`/projects/${o.projectId}/settings?${t}`)}function ft(t=v.directory){let n=H.data?.find(e=>e.directories.some(e=>e.id===t))??U,r=n?.directories.find(e=>e.id===t)??n?.directories[0];!r||!n?N(!0):(V.current=e(),Ee(r.id),ye(!0),xe(r.provider),E(``))}let[pt,mt]=(0,L.useState)(null);(0,L.useEffect)(()=>mt(null),[Q?.id]);let ht=U?.catalogs.find(e=>e.provider===(Q?.provider??`codex`)&&(Q?.cwd?e.cwd===Q.cwd:e.directory===(Q?.executionDirectory??Q?.directory))),gt=ht?.commands??[],_t=ht?.models??U?.providers.find(e=>e.id===Q?.provider)?.models??(Q?.provider===`codex`?U?.models??[]:[]),vt=_t.find(e=>e.id===(Q?.config.model??Q?.effectiveConfig?.model)||!!e.resolvedModel&&e.resolvedModel===(Q?.config.model??Q?.effectiveConfig?.model))??(Q?.config.model?void 0:_t.find(e=>e.isDefault)),yt=!!U?.capabilities.includes(`local-agent-attachments-v1`),bt=!!vt?.images&&!!U?.capabilities.includes(`local-agent-images-v1`),xt=Q?.state===`working`&&!Z?.commands.some(e=>e.kind===`stop`&&[`queued`,`running`].includes(e.state)),St=Q?.provider===`cursor`&&U?.capabilities.includes(`local-agent-steer-v1`),Ct=!U?.capabilities.includes(`local-agent-steer-v1`)&&(Q?.provider===`cursor`||Q?.provider===`claude`);function wt(t){let n=oe.trim();if(!Q||!n&&!Y.files.length)return;let r=Y.files.map(e=>e.id),i=bt?Y.files.filter(e=>e.mimeType!==`application/octet-stream`).map(e=>e.id):[],a=pt?.path&&n.startsWith(`$${pt.name}`)?[{name:pt.name,path:pt.path}]:void 0,o=JSON.stringify({session:Q.id,body:n,skills:a,attachments:r,images:i,delivery:t});ze.current?.fingerprint!==o&&(ze.current={fingerprint:o,id:e()});let s=ze.current;lt(async()=>{await J(`web/local-agent-sessions/${Q.id}/messages`,S(),{method:`POST`,body:{id:s.id,body:n,delivery:t,...i.length?{images:i}:{},...r.length?{attachments:r}:{},...a?{skills:a}:{}}}),le(e=>e.trim()===n?``:e),mt(null),Y.clear(),ze.current===s&&(ze.current=void 0)})}return(0,R.jsxs)(ve,{className:`computers-layout`,testId:`computers-page`,label:`本地会话`,tree:!0,navigation:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(O,{title:`电脑`}),(0,R.jsx)(`div`,{className:`assistant-message-scroll computer-tree`,role:`tree`,"aria-label":`目录与会话`,onKeyDown:Se,children:He.map(({c:e,d:t,label:n})=>{let r=`${e.project}/${t.id}`,i=!h.has(r);return(0,R.jsxs)(`div`,{role:`none`,children:[(0,R.jsxs)(`div`,{className:`computer-tree-row`,role:`none`,children:[(0,R.jsxs)(k,{className:`tree-item tree-folder`,role:`treeitem`,"aria-level":1,"aria-expanded":i,style:{"--tree-level":1},leading:(0,R.jsx)(`span`,{className:`tree-chevron ${i?`expanded`:``}`,children:(0,R.jsx)(s,{name:`chevron`,size:`small`})}),onClick:()=>{v.directory!==t.id&&$(e.project,t.id,t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id),g(e=>{let t=new Set(e);return i?t.add(r):t.delete(r),t})},children:[(0,R.jsx)(s,{name:`files`}),(0,R.jsx)(`span`,{className:`tree-name`,title:n,children:n})]}),(0,R.jsx)(m,{icon:`plus`,label:`新建会话:${n}`,className:`computer-tree-action`,onClick:()=>ft(t.id)})]}),i&&(0,R.jsxs)(`div`,{role:`group`,children:[W.terminals.filter(e=>e.directory===t.id).map(n=>(0,R.jsx)(`div`,{className:`computer-tree-row computer-session-row computer-terminal-row`,role:`none`,children:(0,R.jsxs)(k,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":v.terminal===n.id,style:{"--tree-level":2},leading:(0,R.jsx)(`span`,{className:`tree-chevron`}),onClick:()=>$(e.project,t.id,``,n.id),children:[(0,R.jsx)(s,{name:`command`}),(0,R.jsxs)(`span`,{className:`computer-session-copy`,children:[(0,R.jsx)(`span`,{className:`tree-name`,children:n.title}),(0,R.jsx)(`time`,{dateTime:n.createdAt,children:n.state===`exited`?`已退出`:je(n.createdAt,Ae)})]})]})},n.id)),e.sessions.filter(e=>e.directory===t.id).map(n=>(0,R.jsxs)(`div`,{className:`computer-tree-row computer-session-row`,role:`none`,children:[(0,R.jsxs)(k,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":v.session===n.id&&v.project===e.project,style:{"--tree-level":2},leading:(0,R.jsx)(`span`,{className:`tree-chevron`,children:(0,R.jsx)(`span`,{className:`assistant-message-dot ${n.unread?`unread`:``}`})}),title:`${n.title} · ${de[n.provider]}`,onClick:()=>$(e.project,t.id,n.id),children:[(0,R.jsx)(ne,{provider:n.provider}),(0,R.jsxs)(`span`,{className:`computer-session-copy`,children:[(0,R.jsx)(`span`,{className:`tree-name`,children:n.title}),(0,R.jsx)(`time`,{dateTime:n.updatedAt,title:new Date(n.updatedAt).toLocaleString(),children:je(n.updatedAt,Ae)})]})]}),(0,R.jsx)(m,{icon:`link`,className:`computer-tree-action computer-session-pin${n.pinned?` pinned`:``}`,label:`${n.pinned?`取消自动接单`:`开启自动接单`}:${n.title}`,"aria-pressed":n.pinned,tooltip:n.pinned?`取消自动接单`:`开启自动接单`,disabled:j||n.archived,onClick:()=>void ut(n,{pinned:!n.pinned})}),n.archived?(0,R.jsx)(`span`,{title:`已归档`,role:`img`,"aria-label":`已归档`,children:(0,R.jsx)(s,{name:`archive`,size:`small`})}):n.state!==`idle`&&(0,R.jsx)(ge,{state:n.state,label:it[n.state]??n.state})]},n.id))]})]},t.id)})}),(0,R.jsx)(_,{error:!0,children:H.error})]}),children:[M&&(0,R.jsx)(te,{onClose:()=>N(!1)}),we&&K&&q&&(0,R.jsx)(Ne,{directory:q.id,provider:q.provider,providers:K.providers.map(e=>e.id),sessions:K.sessions,request:J,onClose:()=>z(!1),onImport:e=>{$(v.project,e.directory,e.id),H.reload()}}),he&&q&&(0,R.jsx)(l,{id:`computer-new-session`,title:`新建会话`,onClose:()=>ye(!1),children:(0,R.jsxs)(`form`,{className:`computer-panel stack`,onSubmit:t=>{t.preventDefault(),lt(async()=>{if(I===`terminal`){let t=V.current;await W.request({type:`create`,id:t,directory:q.id,title:fe.trim(),cols:100,rows:28}),V.current=e(),me(``),$(v.project,q.id,``,t);return}let t=await J(`web/local-agents/${q.id}/sessions`,ae,{method:`POST`,body:{id:V.current,title:fe,provider:I}});V.current=e(),ye(!1),me(``),$(v.project,q.id,t.id)})},children:[He.length>1?(0,R.jsx)(pe,{title:`执行目录`,children:(0,R.jsx)(`select`,{"aria-label":`执行目录`,disabled:j,value:q.id,onChange:e=>{Ee(e.target.value),xe(He.find(({d:t})=>t.id===e.target.value)?.d.provider??`codex`)},children:He.map(({d:e,label:t})=>(0,R.jsx)(`option`,{value:e.id,children:t},e.id))})}):(0,R.jsxs)(`p`,{className:`muted computer-create-scope`,children:[`目录:`,q.name]}),(0,R.jsxs)(`label`,{children:[`会话名称`,(0,R.jsx)(`input`,{autoFocus:!0,required:!0,disabled:j,placeholder:`会话名称`,value:fe,onChange:e=>me(e.target.value)})]}),(0,R.jsx)(ce,{label:`会话类型`,value:I,onChange:xe,disabled:j,providers:re.options.filter(e=>e===`codex`||(e===`claude`?K?.capabilities.includes(`local-agent-providers-v1`):K?.providers.some(t=>t.id===e))),terminal:W.directories.includes(q.id)}),I===`terminal`&&(0,R.jsx)(`p`,{className:`muted computer-create-scope`,children:`在此目录启动本机 Shell,使用本机用户权限。`}),K?.providers.find(e=>e.id===I)?.error&&(0,R.jsx)(_,{children:K.providers.find(e=>e.id===I).error}),(0,R.jsx)(_,{error:!0,children:x}),(0,R.jsxs)(`div`,{className:`computer-create-options`,children:[I!==`terminal`&&(0,R.jsx)(`button`,{type:`button`,disabled:!K?.online||!K.capabilities.includes(`local-agent-history-v1`),onClick:()=>{ye(!1),z(!0)},children:`导入历史会话`}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>{ye(!1),N(!0)},children:`接入目录`}),(0,R.jsx)(`button`,{className:`primary`,disabled:j||!fe.trim()||(I===`terminal`?!W.directories.includes(q.id):!ct),children:`创建`})]})]})}),Oe&&(0,R.jsx)(Le,{file:Oe,onClose:()=>ke(void 0)},Oe.url),v.terminal?qe?(0,R.jsx)(L.Suspense,{fallback:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(T,{title:qe.title}),(0,R.jsx)(`div`,{className:`assistant-empty`,children:`正在打开终端…`})]}),children:(0,R.jsx)(nt,{terminal:qe,onFile:st,connection:W,onClosed:()=>$(v.project,v.directory)},qe.id)}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(T,{title:`终端`}),(0,R.jsx)(`div`,{className:`assistant-empty`,children:W.connected?`终端已结束或电脑已重启,请新建终端。`:`正在连接终端…`})]}):G?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(T,{title:Q?(0,R.jsx)(Ce,{title:Q.title,busy:j,onSave:e=>ut(Q,{title:e})},Q.id):(0,R.jsx)(`h2`,{children:G.name}),actions:(0,R.jsx)(R.Fragment,{children:(0,R.jsx)(b,{id:`computer-session-menu`,triggerId:`computer-session-actions`,label:`会话操作`,trigger:(0,R.jsx)(s,{name:`more`}),className:`computer-create-menu`,routeKey:Q?.id??``,disabled:!Q,children:e=>(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`button`,{role:`menuitem`,disabled:j,onClick:()=>{e(),Q&&ut(Q,{hidden:!0})},children:`隐藏会话`}),(0,R.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),dt(G.id)},children:`连接专用群`}),(0,R.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),dt(G.id)},children:`执行位置`})]})})})}),!ct&&(0,R.jsx)(_,{children:`升级客户端后可使用多个会话和网页对话。`}),(0,R.jsxs)(_e,{ref:B,onScroll:e=>{let t=e.currentTarget;Fe.current=t.scrollHeight-t.scrollTop-t.clientHeight<96},"aria-label":`本地会话记录`,children:[(0,R.jsx)(Ye,{onFile:st,messages:Q?Z.messages:[],rewind:Q?{session:Q.id,available:!!Z?.canRewind&&Q.state===`idle`&&!Q.archived,expectedLastMessage:Z?.messages.at(-1)?.id??``,commands:Z?.commands??[],request:J,refresh:X.reload}:void 0,imageUrl:(e,t)=>Ve(v.project,Q.id,e,t),renderQueue:e=>(0,R.jsx)(We,{message:e}),renderQuestion:e=>(0,R.jsx)(Ze,{question:e,session:Q.id,request:J,refresh:X.reload})}),!Z?.messages.length&&(0,R.jsx)(`div`,{className:`assistant-empty`,children:Q?.resumeSession?`已接入原生会话,发送消息继续。`:`在当前目录开始一段对话。`})]}),Z?.commands.filter(e=>e.state!==`succeeded`&&![`diff`,`history`,`rewind`].includes(e.kind)&&!(e.kind===`stop`&&[`queued`,`running`].includes(e.state))).slice(-3).map(e=>(0,R.jsxs)(`p`,{className:`computer-control-status`,role:`status`,children:[e.kind===`stop`?`停止`:e.kind,` · `,it[e.state]??e.state,e.error?`:${e.error}`:``]},e.id)),(0,R.jsx)(_,{error:!0,children:x||X.error||Q?.error}),at.length>0&&(0,R.jsx)(`div`,{className:`computer-question-shortcut`,children:(0,R.jsxs)(`button`,{type:`button`,onClick:()=>{let e=(at.indexOf(Re.current??``)+1)%at.length;ot(at[e])},children:[(0,R.jsx)(s,{name:`question`,size:`small`}),`有 `,at.length,` 个问题等待你的确认`]})}),Q&&(0,R.jsx)(be,{value:oe,onChange:le,label:`向本地 Agent 发送消息`,sendLabel:xt?St?`中断并发送`:Ct?`加入队列`:`插话`:`发送`,onQueue:[`working`,`waiting`].includes(Q.state)&&U?.capabilities.includes(`local-agent-queue-v1`)?()=>wt(`queue`):void 0,placeholder:Q.archived?`会话已归档`:`输入消息…`,disabled:Q.archived||!ct,sendDisabled:j||Y.busy||Y.failed||Y.count>0&&!yt||Z?.commands.some(e=>e.kind===`rewind`&&[`queued`,`running`,`uncertain`].includes(e.state)),attachments:(0,R.jsxs)(R.Fragment,{children:[Y.preview(j),Y.files.some(e=>e.mimeType!==`application/octet-stream`)&&!bt&&(0,R.jsx)(_,{children:`当前模型将通过本地文件路径接收图片。`})]}),hasAttachments:Y.count>0,onFiles:yt&&!j?e=>void Y.add(e):void 0,beforeSend:(0,R.jsx)(Qe,{session:Q.id,active:[`working`,`waiting`].includes(Q.state),commands:Z?.commands??[],request:J,refresh:X.reload,onError:E},Q.id),actions:(0,R.jsxs)(R.Fragment,{children:[yt?Y.picker(j||!ct,bt):bt?(0,R.jsx)(`span`,{title:`更新开发机客户端后可添加附件`,children:(0,R.jsx)(`button`,{type:`button`,className:`icon-button`,disabled:!0,"aria-label":`更新开发机客户端后可添加附件`,children:(0,R.jsx)(s,{name:`attachment`,size:`small`})})}):null,(0,R.jsx)(tt,{session:Q,models:_t,busy:j,available:!!ct,online:!!U?.online,commands:gt,controls:ht?.controls,draft:oe,onInsert:e=>{mt(e.kind===`skill`?e:null),le(`${e.prefix??(e.kind===`skill`?`$`:`/`)}${e.name} `),requestAnimationFrame(()=>document.querySelector(`.message-composer textarea`)?.focus())},onConfig:e=>{lt(()=>J(`web/local-agent-sessions/${Q.id}/settings`,ae,{method:`PUT`,body:{expectedRevision:Q.revision,config:e}}))}})]}),onSubmit:()=>wt(`auto`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(T,{title:`本地会话`}),(0,R.jsxs)(`div`,{className:`assistant-empty`,children:[`尚未登记本地执行目录。`,(0,R.jsx)(`button`,{onClick:()=>N(!0),children:`接入目录`})]})]})]})}export{Z as Computers,Ce as t};