@teammy/server 0.2.15 → 0.2.17

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 (26) hide show
  1. package/dist/main.js +15558 -15381
  2. package/dist/web/assets/{Assistant-CEmXtN1H.js → Assistant-BLsq5HY7.js} +1 -1
  3. package/dist/web/assets/{Computers-ChyEKWzc.js → Computers-Dil0EHja.js} +3 -3
  4. package/dist/web/assets/{Conversation-CSGUsjrV.js → Conversation-Bu7mdJTX.js} +1 -1
  5. package/dist/web/assets/Dashboard-B0Ojad36.js +1 -0
  6. package/dist/web/assets/{Dashboard-CppFmr8a.css → Dashboard-Dt8zIJbB.css} +1 -1
  7. package/dist/web/assets/{Dropdown-D625ln2m.js → Dropdown-ClJ8qPeL.js} +1 -1
  8. package/dist/web/assets/Files-CBGM_Ljm.js +1 -0
  9. package/dist/web/assets/{Help-DgEMyoMA.js → Help-woS0MfLI.js} +101 -7
  10. package/dist/web/assets/Markdown-DJ7qHSXM.js +29 -0
  11. package/dist/web/assets/{MessageComposer-B8Oa9gpY.js → MessageComposer-CkyAV-iI.js} +1 -1
  12. package/dist/web/assets/{ResourceLibrary-C28WAP-Z.js → ResourceLibrary-DPr1LKio.js} +1 -1
  13. package/dist/web/assets/{TerminalPane-DDJO3cDO.js → TerminalPane-qvAQ5u5W.js} +1 -1
  14. package/dist/web/assets/{WorkspaceTree-BHdUglYr.js → WorkspaceTree-Bo35HZpc.js} +1 -1
  15. package/dist/web/assets/{file-links-CVbLZSaw.js → file-links-DlYR_xxD.js} +1 -1
  16. package/dist/web/assets/index-Dj9Jdm4p.js +10 -0
  17. package/dist/web/assets/task-links-zc4fWZyK.js +1 -0
  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/Dashboard-BEZRdw_R.js +0 -1
  23. package/dist/web/assets/Files-DywD1EaD.js +0 -1
  24. package/dist/web/assets/Markdown-Cw4CQNYb.js +0 -29
  25. package/dist/web/assets/index-DjMoKD7A.js +0 -10
  26. package/dist/web/assets/project-links-DI2fBvjw.js +0 -1
@@ -1 +1 @@
1
- import{A as e,C as t,E as n,St as r,T as i,_t as a,c as o,ct as s,d as c,dt as l,ft as u,ht as d,k as f,l as p,p as m,pt as h,st as g,u as ee,w as te,x as ne,xt as _}from"./Dropdown-D625ln2m.js";import{A as re,D as ie,E as ae,F as v,M as oe,O as se,R as ce,T as y,i as le,k as b,w as ue}from"./index-DjMoKD7A.js";import{t as de}from"./Markdown-Cw4CQNYb.js";import{i as fe,n as pe,r as me,t as he}from"./Conversation-CSGUsjrV.js";import{t as ge}from"./MessageComposer-B8Oa9gpY.js";var x=_(),S=i(),_e=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()})}))}),ve=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),C=e=>e.replace(/[#*_`>]/g,``).replace(/\s+/g,` `).trim();function w({me:i,mode:u=`messages`}){let{projectId:g,request:_}=ce(),w=te(),be=t(g,i,`${u}-selection`),T=t(g,i,`${u}-drafts`),xe=(0,x.useCallback)(e=>_(`agents/outbox`,se,{signal:e}),[_]),E=ne(xe,3e3,t(g,i,`outbox`)),Se=(0,x.useCallback)(async e=>u===`messages`?_(`agents/chats`,ue,{signal:e}):{chats:(await _(`channels/topics`,_e,{signal:e})).topics.map(e=>({...e,kind:`matter`,state:null}))},[_,u]),D=ne(Se,3e3,t(g,i,u,`chats`)),[O,Ce]=(0,x.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`chat`);return t?`chat:${t}`:e.get(`message`)??w?.get(be)??``}),k=O.startsWith(`chat:`)?O.slice(5):``,A=!O||!!k,[j,M]=(0,x.useState)(()=>w?.get(t(g,i,`chat`,k))),N=j?.id===k?j:w?.get(t(g,i,`chat`,k)),P=D.data?.chats.find(e=>e.id===k),F=P&&`delivery`in P?P.delivery:void 0,[we,I]=(0,x.useState)(),[L,R]=(0,x.useState)(()=>w?.get(T)??{}),Te=L[O]??``,Ee=e=>R(t=>({...t,[O]:e})),[z,B]=(0,x.useState)(!1),[V,De]=(0,x.useState)(!1),[Oe,ke]=(0,x.useState)(!1),[Ae,H]=(0,x.useState)(!1),[U,je]=(0,x.useState)(``),[Me,Ne]=(0,x.useState)(``),Pe=(0,x.useRef)(e()),[Fe,W]=(0,x.useState)(``),[Ie,G]=(0,x.useState)(``),K=(0,x.useRef)(new Map),Le=(0,x.useRef)(null),q=(0,x.useRef)(!0),J=(0,x.useRef)(O);J.current=O,(0,x.useEffect)(()=>{j&&w?.set(t(g,i,`chat`,j.id),j)},[w,g,i,j]),(0,x.useEffect)(()=>{w?.set(T,L)},[w,T,L]);function Y(e){J.current=e,Ce(e),w?.set(be,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,x.useEffect)(()=>{!O&&D.data?.chats.length&&Y(`chat:${D.data.chats[0].id}`)},[O,D.data]);let X=(E.data?.messages??[]).filter(e=>u===`messages`&&e.box===`debug`).reverse(),Z=E.data?.messages.find(e=>e.id===(O===`debug`?we:O));(0,x.useEffect)(()=>{O!==`debug`&&Z?.conversationId&&Y(`chat:${Z.conversationId}`)},[O,Z?.conversationId]);let Q=X.filter(e=>!e.readAt).map(e=>e.id).join(`,`);(0,x.useEffect)(()=>{Z&&!Z.readAt&&O!==`debug`&&_(`agents/outbox/${Z.id}/read`,b,{method:`POST`}).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>W(f(e)))},[Z?.id,Z?.readAt,O,_,E.reload]),(0,x.useEffect)(()=>{O===`debug`&&Q&&Promise.all(Q.split(`,`).map(e=>_(`agents/outbox/${e}/read`,b,{method:`POST`}))).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>W(f(e)))},[O,Q,_,E.reload]),(0,x.useEffect)(()=>{if(G(``),!k)return;let e=!0,a=-1,o=!1,s=new AbortController,c=t=>{!e||t.id!==k||t.cursor<a||(a=t.cursor,o=!0,t.redirect?Y(`chat:${t.redirect}`):t.entry===`channel`&&u!==`channels`?location.replace(r(`/projects/${g}/channels?chat=${t.id}`)):(M(t),G(``)))};_(`agents/chats/${k}`,y,{signal:s.signal}).then(c).catch(r=>{e&&!s.signal.aborted&&(r instanceof n&&[401,403,404].includes(r.status)&&(w?.delete(t(g,i,`chat`,k)),M(e=>e?.id===k?void 0:e)),o||G(f(r)))});let l=t=>{let n=Number(t.lastEventId);return!e||!Number.isSafeInteger(n)||n<=a?!1:(a=n,!0)},p=new EventSource(r(`/api/v1/projects/${encodeURIComponent(g)}/agents/chats/${encodeURIComponent(k)}/events`));p.addEventListener(`snapshot`,t=>{if(e)try{c(y.parse(JSON.parse(t.data)))}catch(e){G(f(e))}}),p.onerror=()=>{e&&G(`对话连接中断,正在重新连接…`)},p.addEventListener(`context`,e=>{if(!l(e))return;let t=y.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}`):M(e=>e?.id===k?{...e,...t,cursor:a}:e)}),p.addEventListener(`message`,e=>{if(!l(e))return;let t=ae.parse(JSON.parse(e.data));M(n=>n?.id===k?{...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)}),p.addEventListener(`message_removed`,e=>{if(!l(e))return;let{id:t}=h({id:d()}).parse(JSON.parse(e.data));M(e=>e?.id===k?{...e,cursor:a,messages:e.messages.filter(e=>e.id!==t)}:e)}),p.addEventListener(`run`,e=>{if(!l(e))return;let t=ie.parse(JSON.parse(e.data));M(n=>n?.id===k?{...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`])p.addEventListener(e,t=>{if(!l(t))return;let n=JSON.parse(t.data);M(r=>r?.id===k?{...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,s.abort(),p.close()}},[g,k,i,_,w]),(0,x.useEffect)(()=>{if(!N||N.id!==k)return;let e=()=>{document.visibilityState===`visible`&&_(`agents/chats/${k}/read`,h({ok:s()}),{method:`POST`,body:{cursor:N.readCursor}}).then(()=>{D.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)}},[k,N?.readCursor,N?.kind,_]),(0,x.useEffect)(()=>{q.current&&Le.current?.scrollIntoView({block:`end`})},[O,j?.messages,Z?.recipients,X.length]);function Re(){window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}async function $(e){if(q.current=!0,Y(e),W(``),I(void 0),e.startsWith(`chat:`)||e===`debug`)return;let t=E.data?.messages.find(t=>t.id===e)?.conversationId;if(t)Y(`chat:${t}`);else try{await _(`agents/outbox/${e}/read`,b,{method:`POST`}),Re()}catch(e){W(f(e))}}async function ze(){if(!V){De(!0),W(``);try{let e=await _(`agents/chats`,y,{method:`POST`});M(e),await $(`chat:${e.id}`),D.reload()}catch(e){W(f(e))}finally{De(!1)}}}async function Be(t){t.preventDefault();let n=Te.trim();if(!n||z||V)return;B(!0),W(``);let r=K.current.get(O);r&&r.text===n||(r={text:n,id:e()},K.current.set(O,r));try{if(A){let e=r.target??k;if(!e){let t=await _(`agents/chats`,y,{method:`POST`});e=t.id,r.target=e,K.current.set(`chat:${e}`,r),R(t=>({...t,[`chat:${e}`]:n})),J.current===O&&(M(t),Y(`chat:${e}`))}let t=await _(`agents/chats/${e}`,ie.extend({conversationId:d().optional()}),{method:`POST`,body:{text:n,requestId:r.id}});t.conversationId&&t.conversationId!==e&&(J.current===O||J.current===`chat:${e}`)&&Y(`chat:${t.conversationId}`),M(n=>n?.id===e?{...n,runs:n.runs.some(e=>e.id===t.id)?n.runs:[...n.runs,t]}:n),D.reload()}else{let e=await _(`agents/outbox/${Z.id}/reply`,h({conversationId:d()}),{method:`POST`,body:{body:n,requestId:r.id}});Re(),J.current===O&&Y(`chat:${e.conversationId}`),D.reload(),I(void 0)}K.current.delete(O),r.target&&K.current.delete(`chat:${r.target}`),R(e=>({...e,[O]:``,...r.target?{[`chat:${r.target}`]:``}:{}}))}catch(e){W(f(e))}finally{B(!1)}}let Ve=u===`channels`?me:he,He=A&&!N?.closed&&(u!==`channels`||!!k)||!!Z&&!Z.archivedAt,Ue=A&&!N&&(!!k||!D.data);return(0,S.jsxs)(pe,{className:u===`channels`?`channel-layout`:``,testId:`assistant-page`,label:A?`Tim对话`:`消息内容`,navigation:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(oe,{title:u===`channels`?`频道`:`对话`,children:(0,S.jsxs)(`div`,{className:`assistant-list-actions`,children:[(0,S.jsx)(p,{className:`assistant-new-chat`,icon:`clear`,label:`清除未读`,disabled:Oe,onClick:()=>{ke(!0),W(``),_(`communication/read`,h({ok:l(!0)}),{method:`POST`,body:{scope:u}}).then(async()=>{window.dispatchEvent(new Event(`teammy:outbox`)),await Promise.all([D.reload(),E.reload()])}).catch(e=>W(f(e))).finally(()=>ke(!1))}}),(0,S.jsx)(p,{className:`assistant-new-chat`,icon:`plus`,label:u===`channels`?`发表话题`:`新建对话`,disabled:V,onClick:()=>u===`channels`?H(!0):void ze(),"data-testid":`assistant-launcher`})]})}),(0,S.jsxs)(`div`,{className:`assistant-message-scroll`,children:[D.loading&&!D.data&&(0,S.jsx)(`p`,{className:`assistant-list-status`,role:`status`,children:`加载中…`}),D.data?.chats.map(e=>(0,S.jsxs)(`button`,{type:`button`,"data-testid":`assistant-chat-${e.id}`,className:`assistant-message-item assistant-chat-item ${k===e.id?`selected`:``}`,"aria-pressed":k===e.id,onClick:()=>void $(`chat:${e.id}`),children:[(0,S.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,S.jsx)(v,{selected:k===e.id,children:(0,S.jsx)(`strong`,{children:e.title})}),u===`channels`&&`summary`in e&&(0,S.jsx)(`span`,{className:`topic-preview`,children:C(String(e.summary)).slice(0,140)}),(0,S.jsxs)(`time`,{dateTime:e.updatedAt,children:[new Date(e.updatedAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,ve(e.updatedAt)]})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${e.unread||u!==`channels`&&(e.state===`running`||e.state===`queued`)?`unread`:``}`})]},e.id)),!!X.length&&(0,S.jsxs)(`button`,{type:`button`,"data-testid":`debug-outbox`,className:`assistant-message-item ${O===`debug`?`selected`:``}`,onClick:()=>void $(`debug`),children:[(0,S.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,S.jsx)(v,{selected:O===`debug`,children:(0,S.jsx)(`strong`,{children:`运行提醒`})}),(0,S.jsx)(`span`,{children:C(X.at(-1).body)})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${Q?`unread`:``}`})]}),E.data?.messages.filter(e=>u===`messages`&&e.box!==`debug`&&!e.conversationId).sort((e,t)=>Number(!!e.archivedAt)-Number(!!t.archivedAt)).map(e=>(0,S.jsxs)(`button`,{type:`button`,"data-testid":`outbox-${e.id}`,className:`assistant-message-item ${e.archivedAt?`archived`:``} ${O===e.id?`selected`:``}`,onClick:()=>void $(e.id),children:[(0,S.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,S.jsx)(v,{selected:O===e.id,children:(0,S.jsx)(`strong`,{children:C(e.body)})}),(0,S.jsxs)(`time`,{dateTime:e.createdAt,children:[new Date(e.createdAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,ve(e.createdAt)]})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${e.readAt?``:`unread`}`})]},e.id))]}),(0,S.jsx)(m,{error:!0,children:E.error||D.error})]}),children:[Ae&&(0,S.jsxs)(c,{id:`new-topic`,title:`发表话题`,onClose:()=>H(!1),children:[(0,S.jsx)(ge,{inset:!0,plain:!0,value:Me,onChange:Ne,label:`正文`,placeholder:`开始一个话题…`,sendLabel:`发表话题`,sendDisabled:z||!U.trim(),heading:(0,S.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(``),_(`channels/topics`,y,{method:`POST`,body:{id:Pe.current,title:U,body:Me}}).then(t=>{M(t),Y(`chat:${t.id}`),H(!1),je(``),Ne(``),Pe.current=e(),D.reload()}).catch(e=>W(f(e))).finally(()=>B(!1))}}),(0,S.jsx)(m,{error:!0,children:Fe})]}),(0,S.jsx)(re,{title:(0,S.jsx)(`h2`,{children:A?P?.title??N?.title??(k?`无标题`:`Tim`):O===`debug`?`运行提醒`:`项目消息`}),actions:(0,S.jsxs)(S.Fragment,{children:[u===`channels`&&k&&(0,S.jsx)(le,{conversation:k}),u!==`channels`&&N?.kind===`matter`&&(0,S.jsxs)(`span`,{className:`assistant-participants`,title:N.participants?.join(`、`),children:[N.visibility===`project`?`项目共享 · `:``,N.participants?.join(`、`)]}),u===`channels`&&F?.available&&(F.state===`web`||F.state===`cancelled`||!F.connected)&&(0,S.jsx)(p,{icon:`send`,label:`发布到企业微信频道`,disabled:z,onClick:()=>{B(!0),_(`channels/topics/${k}/publish`,a(),{method:`POST`}).then(()=>D.reload()).catch(e=>W(f(e))).finally(()=>B(!1))}})]})}),u===`channels`&&(0,S.jsx)(m,{error:!0,children:F?.error}),u!==`channels`&&N?.kind===`matter`&&(N.hold||N.pending||N.status===`completed`)&&(0,S.jsx)(`div`,{className:`assistant-matter-state`,role:`status`,children:N.hold?`${N.hold.scope===`all`?`已暂停`:`暂缓修改`} · ${N.hold.reason}`:N.pending?`待确认 · ${N.pending.members.join(`、`)}:${N.pending.question}`:`已完成`}),(0,S.jsxs)(fe,{"data-testid":`assistant-transcript`,onScroll:e=>{let t=e.currentTarget;q.current=t.scrollHeight-t.scrollTop-t.clientHeight<100},children:[A?Ue?(0,S.jsxs)(`div`,{className:`assistant-empty`,"data-testid":`assistant-loading`,children:[(0,S.jsx)(ee,{}),(0,S.jsx)(`p`,{role:`status`,children:Ie||D.error?`暂时无法加载对话`:`加载中…`})]}):N?.messages.length?N.messages.filter(e=>e.body||[`queued`,`running`,`failed`].includes(e.state)).map(e=>(0,S.jsx)(`div`,{className:`assistant-turn`,children:(0,S.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,S.jsx)(`div`,{className:`markdown`,children:(0,S.jsx)(de,{children:e.body})}),e.role===`assistant`&&[`queued`,`running`].includes(e.state)&&(0,S.jsxs)(`span`,{className:`assistant-typing`,"aria-label":`正在回答`,children:[(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{})]}),e.state===`failed`&&(0,S.jsx)(m,{error:!0,children:N.runs.find(t=>t.id===e.runId)?.error||`本次回答未完成。`})]})},e.id)):(0,S.jsxs)(`div`,{className:`assistant-empty`,children:[(0,S.jsx)(ee,{}),(0,S.jsx)(`p`,{children:`有什么项目问题想聊聊?`})]}):!E.data&&E.loading?(0,S.jsx)(`div`,{className:`assistant-empty`,children:(0,S.jsx)(`p`,{role:`status`,children:`加载中…`})}):O===`debug`?X.map(e=>(0,S.jsx)(ye,{item:e,onReply:e.archivedAt?void 0:()=>{I(e.id),Ee(``),W(``)}},e.id)):Z&&(0,S.jsx)(ye,{item:Z}),(0,S.jsx)(`div`,{ref:Le})]}),(0,S.jsx)(m,{error:!0,children:Fe||(A?Ie:``)}),He?(0,S.jsx)(ge,{value:Te,onChange:Ee,onSubmit:e=>void Be(e),disabled:V,sendDisabled:z||Ue,label:A?`向Tim提问`:`回复消息`}):O!==`debug`&&Z&&(0,S.jsxs)(`div`,{className:`assistant-archived`,children:[(0,S.jsx)(o,{name:`archive`}),`已归档`]})]})}function ye({item:e,onReply:t}){return(0,S.jsx)(`div`,{"data-testid":`outbox-thread-${e.id}`,children:(0,S.jsxs)(he,{author:e.box===`debug`?`运行提醒`:`Tim`,time:e.createdAt,children:[(0,S.jsx)(`div`,{className:`markdown`,children:(0,S.jsx)(de,{children:e.body})}),t&&(0,S.jsx)(`button`,{type:`button`,className:`assistant-debug-reply`,onClick:t,children:`回复`})]})})}export{w as Assistant};
1
+ import{A as e,C as t,E as n,St as r,T as i,_t as a,c as o,ct as s,d as c,dt as l,ft as u,ht as d,k as f,l as p,p as m,pt as h,st as g,u as ee,w as te,x as ne,xt as _}from"./Dropdown-ClJ8qPeL.js";import{A as re,D as ie,E as ae,F as v,M as oe,O as se,R as ce,T as y,i as le,k as b,w as ue}from"./index-Dj9Jdm4p.js";import{t as de}from"./Markdown-DJ7qHSXM.js";import{i as fe,n as pe,r as me,t as he}from"./Conversation-Bu7mdJTX.js";import{t as ge}from"./MessageComposer-CkyAV-iI.js";var x=_(),S=i(),_e=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()})}))}),ve=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),C=e=>e.replace(/[#*_`>]/g,``).replace(/\s+/g,` `).trim();function w({me:i,mode:u=`messages`}){let{projectId:g,request:_}=ce(),w=te(),be=t(g,i,`${u}-selection`),T=t(g,i,`${u}-drafts`),xe=(0,x.useCallback)(e=>_(`agents/outbox`,se,{signal:e}),[_]),E=ne(xe,3e3,t(g,i,`outbox`)),Se=(0,x.useCallback)(async e=>u===`messages`?_(`agents/chats`,ue,{signal:e}):{chats:(await _(`channels/topics`,_e,{signal:e})).topics.map(e=>({...e,kind:`matter`,state:null}))},[_,u]),D=ne(Se,3e3,t(g,i,u,`chats`)),[O,Ce]=(0,x.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`chat`);return t?`chat:${t}`:e.get(`message`)??w?.get(be)??``}),k=O.startsWith(`chat:`)?O.slice(5):``,A=!O||!!k,[j,M]=(0,x.useState)(()=>w?.get(t(g,i,`chat`,k))),N=j?.id===k?j:w?.get(t(g,i,`chat`,k)),P=D.data?.chats.find(e=>e.id===k),F=P&&`delivery`in P?P.delivery:void 0,[we,I]=(0,x.useState)(),[L,R]=(0,x.useState)(()=>w?.get(T)??{}),Te=L[O]??``,Ee=e=>R(t=>({...t,[O]:e})),[z,B]=(0,x.useState)(!1),[V,De]=(0,x.useState)(!1),[Oe,ke]=(0,x.useState)(!1),[Ae,H]=(0,x.useState)(!1),[U,je]=(0,x.useState)(``),[Me,Ne]=(0,x.useState)(``),Pe=(0,x.useRef)(e()),[Fe,W]=(0,x.useState)(``),[Ie,G]=(0,x.useState)(``),K=(0,x.useRef)(new Map),Le=(0,x.useRef)(null),q=(0,x.useRef)(!0),J=(0,x.useRef)(O);J.current=O,(0,x.useEffect)(()=>{j&&w?.set(t(g,i,`chat`,j.id),j)},[w,g,i,j]),(0,x.useEffect)(()=>{w?.set(T,L)},[w,T,L]);function Y(e){J.current=e,Ce(e),w?.set(be,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,x.useEffect)(()=>{!O&&D.data?.chats.length&&Y(`chat:${D.data.chats[0].id}`)},[O,D.data]);let X=(E.data?.messages??[]).filter(e=>u===`messages`&&e.box===`debug`).reverse(),Z=E.data?.messages.find(e=>e.id===(O===`debug`?we:O));(0,x.useEffect)(()=>{O!==`debug`&&Z?.conversationId&&Y(`chat:${Z.conversationId}`)},[O,Z?.conversationId]);let Q=X.filter(e=>!e.readAt).map(e=>e.id).join(`,`);(0,x.useEffect)(()=>{Z&&!Z.readAt&&O!==`debug`&&_(`agents/outbox/${Z.id}/read`,b,{method:`POST`}).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>W(f(e)))},[Z?.id,Z?.readAt,O,_,E.reload]),(0,x.useEffect)(()=>{O===`debug`&&Q&&Promise.all(Q.split(`,`).map(e=>_(`agents/outbox/${e}/read`,b,{method:`POST`}))).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>W(f(e)))},[O,Q,_,E.reload]),(0,x.useEffect)(()=>{if(G(``),!k)return;let e=!0,a=-1,o=!1,s=new AbortController,c=t=>{!e||t.id!==k||t.cursor<a||(a=t.cursor,o=!0,t.redirect?Y(`chat:${t.redirect}`):t.entry===`channel`&&u!==`channels`?location.replace(r(`/projects/${g}/channels?chat=${t.id}`)):(M(t),G(``)))};_(`agents/chats/${k}`,y,{signal:s.signal}).then(c).catch(r=>{e&&!s.signal.aborted&&(r instanceof n&&[401,403,404].includes(r.status)&&(w?.delete(t(g,i,`chat`,k)),M(e=>e?.id===k?void 0:e)),o||G(f(r)))});let l=t=>{let n=Number(t.lastEventId);return!e||!Number.isSafeInteger(n)||n<=a?!1:(a=n,!0)},p=new EventSource(r(`/api/v1/projects/${encodeURIComponent(g)}/agents/chats/${encodeURIComponent(k)}/events`));p.addEventListener(`snapshot`,t=>{if(e)try{c(y.parse(JSON.parse(t.data)))}catch(e){G(f(e))}}),p.onerror=()=>{e&&G(`对话连接中断,正在重新连接…`)},p.addEventListener(`context`,e=>{if(!l(e))return;let t=y.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}`):M(e=>e?.id===k?{...e,...t,cursor:a}:e)}),p.addEventListener(`message`,e=>{if(!l(e))return;let t=ae.parse(JSON.parse(e.data));M(n=>n?.id===k?{...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)}),p.addEventListener(`message_removed`,e=>{if(!l(e))return;let{id:t}=h({id:d()}).parse(JSON.parse(e.data));M(e=>e?.id===k?{...e,cursor:a,messages:e.messages.filter(e=>e.id!==t)}:e)}),p.addEventListener(`run`,e=>{if(!l(e))return;let t=ie.parse(JSON.parse(e.data));M(n=>n?.id===k?{...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`])p.addEventListener(e,t=>{if(!l(t))return;let n=JSON.parse(t.data);M(r=>r?.id===k?{...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,s.abort(),p.close()}},[g,k,i,_,w]),(0,x.useEffect)(()=>{if(!N||N.id!==k)return;let e=()=>{document.visibilityState===`visible`&&_(`agents/chats/${k}/read`,h({ok:s()}),{method:`POST`,body:{cursor:N.readCursor}}).then(()=>{D.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)}},[k,N?.readCursor,N?.kind,_]),(0,x.useEffect)(()=>{q.current&&Le.current?.scrollIntoView({block:`end`})},[O,j?.messages,Z?.recipients,X.length]);function Re(){window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}async function $(e){if(q.current=!0,Y(e),W(``),I(void 0),e.startsWith(`chat:`)||e===`debug`)return;let t=E.data?.messages.find(t=>t.id===e)?.conversationId;if(t)Y(`chat:${t}`);else try{await _(`agents/outbox/${e}/read`,b,{method:`POST`}),Re()}catch(e){W(f(e))}}async function ze(){if(!V){De(!0),W(``);try{let e=await _(`agents/chats`,y,{method:`POST`});M(e),await $(`chat:${e.id}`),D.reload()}catch(e){W(f(e))}finally{De(!1)}}}async function Be(t){t.preventDefault();let n=Te.trim();if(!n||z||V)return;B(!0),W(``);let r=K.current.get(O);r&&r.text===n||(r={text:n,id:e()},K.current.set(O,r));try{if(A){let e=r.target??k;if(!e){let t=await _(`agents/chats`,y,{method:`POST`});e=t.id,r.target=e,K.current.set(`chat:${e}`,r),R(t=>({...t,[`chat:${e}`]:n})),J.current===O&&(M(t),Y(`chat:${e}`))}let t=await _(`agents/chats/${e}`,ie.extend({conversationId:d().optional()}),{method:`POST`,body:{text:n,requestId:r.id}});t.conversationId&&t.conversationId!==e&&(J.current===O||J.current===`chat:${e}`)&&Y(`chat:${t.conversationId}`),M(n=>n?.id===e?{...n,runs:n.runs.some(e=>e.id===t.id)?n.runs:[...n.runs,t]}:n),D.reload()}else{let e=await _(`agents/outbox/${Z.id}/reply`,h({conversationId:d()}),{method:`POST`,body:{body:n,requestId:r.id}});Re(),J.current===O&&Y(`chat:${e.conversationId}`),D.reload(),I(void 0)}K.current.delete(O),r.target&&K.current.delete(`chat:${r.target}`),R(e=>({...e,[O]:``,...r.target?{[`chat:${r.target}`]:``}:{}}))}catch(e){W(f(e))}finally{B(!1)}}let Ve=u===`channels`?me:he,He=A&&!N?.closed&&(u!==`channels`||!!k)||!!Z&&!Z.archivedAt,Ue=A&&!N&&(!!k||!D.data);return(0,S.jsxs)(pe,{className:u===`channels`?`channel-layout`:``,testId:`assistant-page`,label:A?`Tim对话`:`消息内容`,navigation:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(oe,{title:u===`channels`?`频道`:`对话`,children:(0,S.jsxs)(`div`,{className:`assistant-list-actions`,children:[(0,S.jsx)(p,{className:`assistant-new-chat`,icon:`clear`,label:`清除未读`,disabled:Oe,onClick:()=>{ke(!0),W(``),_(`communication/read`,h({ok:l(!0)}),{method:`POST`,body:{scope:u}}).then(async()=>{window.dispatchEvent(new Event(`teammy:outbox`)),await Promise.all([D.reload(),E.reload()])}).catch(e=>W(f(e))).finally(()=>ke(!1))}}),(0,S.jsx)(p,{className:`assistant-new-chat`,icon:`plus`,label:u===`channels`?`发表话题`:`新建对话`,disabled:V,onClick:()=>u===`channels`?H(!0):void ze(),"data-testid":`assistant-launcher`})]})}),(0,S.jsxs)(`div`,{className:`assistant-message-scroll`,children:[D.loading&&!D.data&&(0,S.jsx)(`p`,{className:`assistant-list-status`,role:`status`,children:`加载中…`}),D.data?.chats.map(e=>(0,S.jsxs)(`button`,{type:`button`,"data-testid":`assistant-chat-${e.id}`,className:`assistant-message-item assistant-chat-item ${k===e.id?`selected`:``}`,"aria-pressed":k===e.id,onClick:()=>void $(`chat:${e.id}`),children:[(0,S.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,S.jsx)(v,{selected:k===e.id,children:(0,S.jsx)(`strong`,{children:e.title})}),u===`channels`&&`summary`in e&&(0,S.jsx)(`span`,{className:`topic-preview`,children:C(String(e.summary)).slice(0,140)}),(0,S.jsxs)(`time`,{dateTime:e.updatedAt,children:[new Date(e.updatedAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,ve(e.updatedAt)]})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${e.unread||u!==`channels`&&(e.state===`running`||e.state===`queued`)?`unread`:``}`})]},e.id)),!!X.length&&(0,S.jsxs)(`button`,{type:`button`,"data-testid":`debug-outbox`,className:`assistant-message-item ${O===`debug`?`selected`:``}`,onClick:()=>void $(`debug`),children:[(0,S.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,S.jsx)(v,{selected:O===`debug`,children:(0,S.jsx)(`strong`,{children:`运行提醒`})}),(0,S.jsx)(`span`,{children:C(X.at(-1).body)})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${Q?`unread`:``}`})]}),E.data?.messages.filter(e=>u===`messages`&&e.box!==`debug`&&!e.conversationId).sort((e,t)=>Number(!!e.archivedAt)-Number(!!t.archivedAt)).map(e=>(0,S.jsxs)(`button`,{type:`button`,"data-testid":`outbox-${e.id}`,className:`assistant-message-item ${e.archivedAt?`archived`:``} ${O===e.id?`selected`:``}`,onClick:()=>void $(e.id),children:[(0,S.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,S.jsx)(v,{selected:O===e.id,children:(0,S.jsx)(`strong`,{children:C(e.body)})}),(0,S.jsxs)(`time`,{dateTime:e.createdAt,children:[new Date(e.createdAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,ve(e.createdAt)]})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${e.readAt?``:`unread`}`})]},e.id))]}),(0,S.jsx)(m,{error:!0,children:E.error||D.error})]}),children:[Ae&&(0,S.jsxs)(c,{id:`new-topic`,title:`发表话题`,onClose:()=>H(!1),children:[(0,S.jsx)(ge,{inset:!0,plain:!0,value:Me,onChange:Ne,label:`正文`,placeholder:`开始一个话题…`,sendLabel:`发表话题`,sendDisabled:z||!U.trim(),heading:(0,S.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(``),_(`channels/topics`,y,{method:`POST`,body:{id:Pe.current,title:U,body:Me}}).then(t=>{M(t),Y(`chat:${t.id}`),H(!1),je(``),Ne(``),Pe.current=e(),D.reload()}).catch(e=>W(f(e))).finally(()=>B(!1))}}),(0,S.jsx)(m,{error:!0,children:Fe})]}),(0,S.jsx)(re,{title:(0,S.jsx)(`h2`,{children:A?P?.title??N?.title??(k?`无标题`:`Tim`):O===`debug`?`运行提醒`:`项目消息`}),actions:(0,S.jsxs)(S.Fragment,{children:[u===`channels`&&k&&(0,S.jsx)(le,{conversation:k}),u!==`channels`&&N?.kind===`matter`&&(0,S.jsxs)(`span`,{className:`assistant-participants`,title:N.participants?.join(`、`),children:[N.visibility===`project`?`项目共享 · `:``,N.participants?.join(`、`)]}),u===`channels`&&F?.available&&(F.state===`web`||F.state===`cancelled`||!F.connected)&&(0,S.jsx)(p,{icon:`send`,label:`发布到企业微信频道`,disabled:z,onClick:()=>{B(!0),_(`channels/topics/${k}/publish`,a(),{method:`POST`}).then(()=>D.reload()).catch(e=>W(f(e))).finally(()=>B(!1))}})]})}),u===`channels`&&(0,S.jsx)(m,{error:!0,children:F?.error}),u!==`channels`&&N?.kind===`matter`&&(N.hold||N.pending||N.status===`completed`)&&(0,S.jsx)(`div`,{className:`assistant-matter-state`,role:`status`,children:N.hold?`${N.hold.scope===`all`?`已暂停`:`暂缓修改`} · ${N.hold.reason}`:N.pending?`待确认 · ${N.pending.members.join(`、`)}:${N.pending.question}`:`已完成`}),(0,S.jsxs)(fe,{"data-testid":`assistant-transcript`,onScroll:e=>{let t=e.currentTarget;q.current=t.scrollHeight-t.scrollTop-t.clientHeight<100},children:[A?Ue?(0,S.jsxs)(`div`,{className:`assistant-empty`,"data-testid":`assistant-loading`,children:[(0,S.jsx)(ee,{}),(0,S.jsx)(`p`,{role:`status`,children:Ie||D.error?`暂时无法加载对话`:`加载中…`})]}):N?.messages.length?N.messages.filter(e=>e.body||[`queued`,`running`,`failed`].includes(e.state)).map(e=>(0,S.jsx)(`div`,{className:`assistant-turn`,children:(0,S.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,S.jsx)(`div`,{className:`markdown`,children:(0,S.jsx)(de,{children:e.body})}),e.role===`assistant`&&[`queued`,`running`].includes(e.state)&&(0,S.jsxs)(`span`,{className:`assistant-typing`,"aria-label":`正在回答`,children:[(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{})]}),e.state===`failed`&&(0,S.jsx)(m,{error:!0,children:N.runs.find(t=>t.id===e.runId)?.error||`本次回答未完成。`})]})},e.id)):(0,S.jsxs)(`div`,{className:`assistant-empty`,children:[(0,S.jsx)(ee,{}),(0,S.jsx)(`p`,{children:`有什么项目问题想聊聊?`})]}):!E.data&&E.loading?(0,S.jsx)(`div`,{className:`assistant-empty`,children:(0,S.jsx)(`p`,{role:`status`,children:`加载中…`})}):O===`debug`?X.map(e=>(0,S.jsx)(ye,{item:e,onReply:e.archivedAt?void 0:()=>{I(e.id),Ee(``),W(``)}},e.id)):Z&&(0,S.jsx)(ye,{item:Z}),(0,S.jsx)(`div`,{ref:Le})]}),(0,S.jsx)(m,{error:!0,children:Fe||(A?Ie:``)}),He?(0,S.jsx)(ge,{value:Te,onChange:Ee,onSubmit:e=>void Be(e),disabled:V,sendDisabled:z||Ue,label:A?`向Tim提问`:`回复消息`}):O!==`debug`&&Z&&(0,S.jsxs)(`div`,{className:`assistant-archived`,children:[(0,S.jsx)(o,{name:`archive`}),`已归档`]})]})}function ye({item:e,onReply:t}){return(0,S.jsx)(`div`,{"data-testid":`outbox-thread-${e.id}`,children:(0,S.jsxs)(he,{author:e.box===`debug`?`运行提醒`:`Tim`,time:e.createdAt,children:[(0,S.jsx)(`div`,{className:`markdown`,children:(0,S.jsx)(de,{children:e.body})}),t&&(0,S.jsx)(`button`,{type:`button`,className:`assistant-debug-reply`,onClick:t,children:`回复`})]})})}export{w as Assistant};
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./TerminalPane-DDJO3cDO.js","./Dropdown-D625ln2m.js","./index-DjMoKD7A.js","./index-u6KD7Soy.css","./Markdown-Cw4CQNYb.js","./project-links-DI2fBvjw.js","./TerminalPane-BrSy-0jI.css"])))=>i.map(i=>d[i]);
2
- import{A as e,C as t,E as n,Q as r,St as i,T as a,_t as o,c as s,ct as c,d as l,dt as u,ft as d,ht 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,w as S,x as C,xt as w}from"./Dropdown-D625ln2m.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 I,z as fe}from"./index-DjMoKD7A.js";import{i as pe,t as me}from"./Markdown-Cw4CQNYb.js";import{a as he,i as ge,n as _e,t as L}from"./Conversation-CSGUsjrV.js";import{n as R,t as ve}from"./MessageComposer-B8Oa9gpY.js";import{l as ye,r as be}from"./WorkspaceTree-BHdUglYr.js";var z=w(),B=a();function xe({title:e,busy:t,onSave:n}){let[r,i]=(0,z.useState)(!1),[a,o]=(0,z.useState)(e);return r?(0,B.jsx)(`form`,{className:`session-title-form`,onSubmit:t=>{t.preventDefault(),a.trim()&&a.trim()!==e&&n(a.trim()),i(!1)},children:(0,B.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,B.jsx)(`h2`,{children:(0,B.jsx)(`button`,{type:`button`,className:`session-rename`,title:`重命名会话`,"aria-label":`重命名会话:${e}`,onClick:()=>{o(e),i(!0)},children:e})})}var Se=v({id:f().uuid(),directory:f(),title:f(),cwd:f(),createdAt:f(),state:g([`running`,`exited`]),exitCode:d().nullable()}),V={id:f().uuid(),directory:f().min(1).max(200)},Ce={cols:d().int().min(2).max(500),rows:d().int().min(1).max(300)};h(`type`,[v({type:u(`create`),...V,...Ce,title:f().trim().min(1).max(160)}),v({type:u(`attach`),...V}),v({type:u(`detach`),...V}),v({type:u(`input`),...V,data:f().max(65536)}),v({type:u(`resize`),...V,...Ce}),v({type:u(`rename`),...V,title:f().trim().min(1).max(160)}),v({type:u(`close`),...V})]);var we=h(`type`,[v({type:u(`size`),id:f(),...Ce}),v({type:u(`inventory`),directories:y(f()),terminals:y(Se)}),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 Te(e,t){let n=(0,z.useRef)(null),r=(0,z.useRef)(new Set),[a,o]=(0,z.useState)(!1),[s,c]=(0,z.useState)([]),[l,u]=(0,z.useState)([]);(0,z.useEffect)(()=>{if(!t)return;let a=!1,s,l,d=()=>{let t=new URL(i(`/api/v1/projects/${encodeURIComponent(e)}/web/terminals`),location.origin);t.protocol=t.protocol===`https:`?`wss:`:`ws:`,l=new WebSocket(t),n.current=l,l.onmessage=e=>{let t=we.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 r.current)e(n)},l.onclose=()=>{o(!1),c([]),a||(s=setTimeout(d,2e3))}};return d(),()=>{a=!0,clearTimeout(s),l?.close(),n.current=null}},[e,t]);let d=(0,z.useCallback)(e=>(r.current.add(e),()=>{r.current.delete(e)}),[]),f=(0,z.useCallback)(e=>{if(n.current?.readyState!==WebSocket.OPEN)throw Error(`终端连接已断开,输入未发送。`);n.current.send(JSON.stringify(e))},[]);return{connected:a,directories:s,terminals:l,subscribe:d,send:f,request:(0,z.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 Ee=v({id:F,title:f(),cwd:f(),updatedAt:f().datetime().nullable(),active:c().default(!1)}),De=v({sessions:y(Ee),nextCursor:f().nullable()}),Oe=v({command:P,history:De.nullable()});function ke(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 Ae({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,z.useState)(!1),[f,p]=(0,z.useState)(``),[h,g]=(0,z.useState)(),_=(0,z.useRef)(null),v=(0,z.useRef)(null),y=(0,z.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,z.useEffect)(()=>p(``),[n]),(0,z.useEffect)(()=>{if(!u)return;let e=e=>{_.current?.contains(e.target)||d(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[u]),(0,z.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,z.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,B.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,B.jsxs)(`div`,{className:`combobox-field`,ref:v,children:[(0,B.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,B.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,B.jsxs)(`div`,{className:`combobox-popup`,style:h,children:[(0,B.jsxs)(`div`,{id:`${e}-list`,role:`listbox`,"aria-label":t,"aria-busy":o,children:[S.map((t,r)=>(0,B.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,B.jsxs)(`span`,{className:`combobox-option-copy`,children:[(0,B.jsx)(`span`,{children:t.label}),t.description&&(0,B.jsx)(`small`,{children:t.description})]}),t.detail&&(0,B.jsx)(`span`,{className:`combobox-option-detail`,children:t.detail})]},t.value)),o&&(0,B.jsx)(`p`,{className:`combobox-message`,role:`status`,children:`正在读取…`}),!o&&!S.length&&(0,B.jsx)(`p`,{className:`combobox-message`,children:c})]}),l&&(0,B.jsx)(`div`,{className:`combobox-footer`,children:l})]})]})}function je({directory:t,provider:n,providers:r,sessions:i,request:a,onClose:o,onImport:s}){let[c,u]=(0,z.useState)(n),[d,f]=(0,z.useState)([]),[h,g]=(0,z.useState)(null),[v,y]=(0,z.useState)(``),[b,x]=(0,z.useState)(null),[S,C]=(0,z.useState)(``),w=(0,z.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}`,Oe,{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,z.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,B.jsx)(l,{id:`computer-import-session`,title:`导入历史会话`,onClose:o,children:(0,B.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,B.jsx)(oe,{label:`历史会话 Agent`,value:c,onChange:u,providers:[n,...r],disabled:j}),(0,B.jsxs)(`div`,{className:`field`,children:[(0,B.jsx)(`label`,{htmlFor:`native-history-session`,children:`Session`}),(0,B.jsxs)(`div`,{className:`native-history-input-row`,children:[(0,B.jsx)(Ae,{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?`工作中`:ke(e.updatedAt),disabled:e.active&&!T(e.id)})),footer:(0,B.jsxs)(B.Fragment,{children:[h&&(0,B.jsx)(`button`,{className:`native-history-more`,type:`button`,disabled:!!b,onClick:()=>void k(h),children:`加载更多`}),(0,B.jsx)(m,{icon:`refresh`,label:`刷新历史会话`,disabled:!!b,onClick:()=>void k()})]})},c),(0,B.jsx)(`button`,{type:`submit`,disabled:j||!F.safeParse(v.trim()).success||!!A?.active&&!T(A.id),children:j?`正在导入…`:T(v.trim())?`打开`:`导入`})]})]}),(0,B.jsx)(_,{error:!0,children:S}),(0,B.jsx)(`small`,{className:`muted`,children:`请先退出原终端会话。`})]})})}var H={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 Me(e,t){let n=e.toLowerCase().split(`.`).at(-1)??``;return t&&Object.values(H).includes(t)?t:Object.hasOwn(H,n)?H[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 Ne(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 Pe(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 Ne(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 Fe({file:e,onClose:t,gallery:n}){let[r,i]=(0,z.useState)(),[a,o]=(0,z.useState)(``),[c,u]=(0,z.useState)(!1),d=(0,z.useRef)(null),f=(0,z.useRef)(null),h=Me(e.name,e.mimeType),{name:g,url:v,previewUrl:y,size:b}=e;(0,z.useEffect)(()=>{let e=new AbortController,t;return i(void 0),o(``),u(!1),Pe({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,z.useEffect)(()=>{f.current?.scrollIntoView({block:`center`})},[r,e.line]);let x=e.line&&r?.text!==void 0?r.text.split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./TerminalPane-qvAQ5u5W.js","./Dropdown-ClJ8qPeL.js","./index-Dj9Jdm4p.js","./index-u6KD7Soy.css","./Markdown-DJ7qHSXM.js","./task-links-zc4fWZyK.js","./TerminalPane-BrSy-0jI.css"])))=>i.map(i=>d[i]);
2
+ import{A as e,C as t,E as n,Q as r,St as i,T as a,_t as o,c as s,ct as c,d as l,dt as u,ft as d,ht 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,w as S,x as C,xt as w}from"./Dropdown-ClJ8qPeL.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 I,z as fe}from"./index-Dj9Jdm4p.js";import{i as pe,t as me}from"./Markdown-DJ7qHSXM.js";import{a as he,i as ge,n as _e,t as L}from"./Conversation-Bu7mdJTX.js";import{n as R,t as ve}from"./MessageComposer-CkyAV-iI.js";import{l as ye,r as be}from"./WorkspaceTree-Bo35HZpc.js";var z=w(),B=a();function xe({title:e,busy:t,onSave:n}){let[r,i]=(0,z.useState)(!1),[a,o]=(0,z.useState)(e);return r?(0,B.jsx)(`form`,{className:`session-title-form`,onSubmit:t=>{t.preventDefault(),a.trim()&&a.trim()!==e&&n(a.trim()),i(!1)},children:(0,B.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,B.jsx)(`h2`,{children:(0,B.jsx)(`button`,{type:`button`,className:`session-rename`,title:`重命名会话`,"aria-label":`重命名会话:${e}`,onClick:()=>{o(e),i(!0)},children:e})})}var Se=v({id:f().uuid(),directory:f(),title:f(),cwd:f(),createdAt:f(),state:g([`running`,`exited`]),exitCode:d().nullable()}),V={id:f().uuid(),directory:f().min(1).max(200)},Ce={cols:d().int().min(2).max(500),rows:d().int().min(1).max(300)};h(`type`,[v({type:u(`create`),...V,...Ce,title:f().trim().min(1).max(160)}),v({type:u(`attach`),...V}),v({type:u(`detach`),...V}),v({type:u(`input`),...V,data:f().max(65536)}),v({type:u(`resize`),...V,...Ce}),v({type:u(`rename`),...V,title:f().trim().min(1).max(160)}),v({type:u(`close`),...V})]);var we=h(`type`,[v({type:u(`size`),id:f(),...Ce}),v({type:u(`inventory`),directories:y(f()),terminals:y(Se)}),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 Te(e,t){let n=(0,z.useRef)(null),r=(0,z.useRef)(new Set),[a,o]=(0,z.useState)(!1),[s,c]=(0,z.useState)([]),[l,u]=(0,z.useState)([]);(0,z.useEffect)(()=>{if(!t)return;let a=!1,s,l,d=()=>{let t=new URL(i(`/api/v1/projects/${encodeURIComponent(e)}/web/terminals`),location.origin);t.protocol=t.protocol===`https:`?`wss:`:`ws:`,l=new WebSocket(t),n.current=l,l.onmessage=e=>{let t=we.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 r.current)e(n)},l.onclose=()=>{o(!1),c([]),a||(s=setTimeout(d,2e3))}};return d(),()=>{a=!0,clearTimeout(s),l?.close(),n.current=null}},[e,t]);let d=(0,z.useCallback)(e=>(r.current.add(e),()=>{r.current.delete(e)}),[]),f=(0,z.useCallback)(e=>{if(n.current?.readyState!==WebSocket.OPEN)throw Error(`终端连接已断开,输入未发送。`);n.current.send(JSON.stringify(e))},[]);return{connected:a,directories:s,terminals:l,subscribe:d,send:f,request:(0,z.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 Ee=v({id:F,title:f(),cwd:f(),updatedAt:f().datetime().nullable(),active:c().default(!1)}),De=v({sessions:y(Ee),nextCursor:f().nullable()}),Oe=v({command:P,history:De.nullable()});function ke(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 Ae({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,z.useState)(!1),[f,p]=(0,z.useState)(``),[h,g]=(0,z.useState)(),_=(0,z.useRef)(null),v=(0,z.useRef)(null),y=(0,z.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,z.useEffect)(()=>p(``),[n]),(0,z.useEffect)(()=>{if(!u)return;let e=e=>{_.current?.contains(e.target)||d(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[u]),(0,z.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,z.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,B.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,B.jsxs)(`div`,{className:`combobox-field`,ref:v,children:[(0,B.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,B.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,B.jsxs)(`div`,{className:`combobox-popup`,style:h,children:[(0,B.jsxs)(`div`,{id:`${e}-list`,role:`listbox`,"aria-label":t,"aria-busy":o,children:[S.map((t,r)=>(0,B.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,B.jsxs)(`span`,{className:`combobox-option-copy`,children:[(0,B.jsx)(`span`,{children:t.label}),t.description&&(0,B.jsx)(`small`,{children:t.description})]}),t.detail&&(0,B.jsx)(`span`,{className:`combobox-option-detail`,children:t.detail})]},t.value)),o&&(0,B.jsx)(`p`,{className:`combobox-message`,role:`status`,children:`正在读取…`}),!o&&!S.length&&(0,B.jsx)(`p`,{className:`combobox-message`,children:c})]}),l&&(0,B.jsx)(`div`,{className:`combobox-footer`,children:l})]})]})}function je({directory:t,provider:n,providers:r,sessions:i,request:a,onClose:o,onImport:s}){let[c,u]=(0,z.useState)(n),[d,f]=(0,z.useState)([]),[h,g]=(0,z.useState)(null),[v,y]=(0,z.useState)(``),[b,x]=(0,z.useState)(null),[S,C]=(0,z.useState)(``),w=(0,z.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}`,Oe,{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,z.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,B.jsx)(l,{id:`computer-import-session`,title:`导入历史会话`,onClose:o,children:(0,B.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,B.jsx)(oe,{label:`历史会话 Agent`,value:c,onChange:u,providers:[n,...r],disabled:j}),(0,B.jsxs)(`div`,{className:`field`,children:[(0,B.jsx)(`label`,{htmlFor:`native-history-session`,children:`Session`}),(0,B.jsxs)(`div`,{className:`native-history-input-row`,children:[(0,B.jsx)(Ae,{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?`工作中`:ke(e.updatedAt),disabled:e.active&&!T(e.id)})),footer:(0,B.jsxs)(B.Fragment,{children:[h&&(0,B.jsx)(`button`,{className:`native-history-more`,type:`button`,disabled:!!b,onClick:()=>void k(h),children:`加载更多`}),(0,B.jsx)(m,{icon:`refresh`,label:`刷新历史会话`,disabled:!!b,onClick:()=>void k()})]})},c),(0,B.jsx)(`button`,{type:`submit`,disabled:j||!F.safeParse(v.trim()).success||!!A?.active&&!T(A.id),children:j?`正在导入…`:T(v.trim())?`打开`:`导入`})]})]}),(0,B.jsx)(_,{error:!0,children:S}),(0,B.jsx)(`small`,{className:`muted`,children:`请先退出原终端会话。`})]})})}var H={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 Me(e,t){let n=e.toLowerCase().split(`.`).at(-1)??``;return t&&Object.values(H).includes(t)?t:Object.hasOwn(H,n)?H[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 Ne(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 Pe(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 Ne(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 Fe({file:e,onClose:t,gallery:n}){let[r,i]=(0,z.useState)(),[a,o]=(0,z.useState)(``),[c,u]=(0,z.useState)(!1),d=(0,z.useRef)(null),f=(0,z.useRef)(null),h=Me(e.name,e.mimeType),{name:g,url:v,previewUrl:y,size:b}=e;(0,z.useEffect)(()=>{let e=new AbortController,t;return i(void 0),o(``),u(!1),Pe({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,z.useEffect)(()=>{f.current?.scrollIntoView({block:`center`})},[r,e.line]);let x=e.line&&r?.text!==void 0?r.text.split(`
3
3
  `):null,S=(e.line??1)-1,C=h.startsWith(`image/`);return(0,B.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,B.jsxs)(B.Fragment,{children:[n&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(m,{icon:`chevron`,className:`session-image-previous`,label:`上一张图片`,onClick:()=>n.move(-1)}),(0,B.jsxs)(`small`,{children:[n.index+1,` / `,n.count]}),(0,B.jsx)(m,{icon:`chevron`,label:`下一张图片`,onClick:()=>n.move(1)})]}),C&&r?.format&&(0,B.jsx)(m,{icon:c?`zoomOut`:`zoomIn`,label:c?`适合窗口`:`原始尺寸`,"aria-pressed":c,onClick:()=>u(!c)}),(0,B.jsx)(`a`,{className:`icon-button`,href:a?void 0:r?.download??e.url,"aria-disabled":!!a,download:e.name,"aria-label":`下载文件`,title:`下载文件`,children:(0,B.jsx)(s,{name:`download`})})]}),children:(0,B.jsx)(`div`,{ref:d,tabIndex:-1,className:`session-image-viewer`,children:a?(0,B.jsx)(_,{error:!0,children:a}):r?r.format?C?(0,B.jsx)(`div`,{className:`session-image-stage`+(c?` original-size`:``),children:(0,B.jsx)(`img`,{src:r.preview,alt:e.name,onError:()=>i({format:``,download:r.download})})}):r.format===`application/pdf`?(0,B.jsx)(`iframe`,{className:`file-preview-document`,src:r.preview,title:e.name+` 预览`}):r.format===`text/html`&&!e.line?(0,B.jsx)(ye,{name:e.name,url:e.url}):(0,B.jsxs)(`div`,{className:`file-preview-text`,children:[r.format===`text/markdown`&&!e.line?(0,B.jsx)(`article`,{className:`markdown`,children:(0,B.jsx)(me,{children:r.text??``})}):(0,B.jsx)(`pre`,{className:`raw`,children:x&&S<x.length?(0,B.jsxs)(B.Fragment,{children:[S>0&&x.slice(0,S).join(`
4
4
  `)+`
5
5
  `,(0,B.jsx)(`mark`,{ref:f,children:x[S]||` `}),x.length>S+1?`
@@ -9,4 +9,4 @@ import{A as e,C as t,E as n,Q as r,St as i,T as a,_t as o,c as s,ct as c,d as l,
9
9
  `).filter(Boolean).slice(0,2).join(` · `)).join(` · `),children:(0,B.jsx)(`pre`,{children:t.questions.map(e=>e.text).join(`
10
10
 
11
11
  `)})}),M?(0,B.jsxs)(`div`,{className:`native-approval-options`,children:[(0,B.jsxs)(`button`,{type:`button`,className:`primary`,disabled:h,"aria-label":`允许`,title:k===null?void 0:`倒计时结束后自动允许本次操作`,onClick:()=>void E({body:`允许`,decision:!0}),children:[`允许`,k!==null&&(0,B.jsxs)(`span`,{"aria-hidden":`true`,children:[`(`,k,`s)`]})]}),(0,B.jsx)(`button`,{type:`button`,disabled:h,onClick:()=>void E({body:`拒绝`,decision:!1}),children:`拒绝`})]}):re&&(0,B.jsxs)(`small`,{className:`question-result`,children:[(0,B.jsx)(s,{name:P,size:`small`}),re]})]}):(0,B.jsxs)(B.Fragment,{children:[t.questions.map(e=>(0,B.jsxs)(`div`,{className:`native-question-part`,children:[(0,B.jsx)(`p`,{children:e.text}),M&&(0,B.jsx)(`div`,{className:`question-options ${Object.values(e.descriptions??{}).some(Boolean)?`question-options-described`:``}`,children:e.options.map(t=>(0,B.jsxs)(`button`,{type:`button`,disabled:h,"aria-pressed":e.multiSelect?u[e.id]?.includes(t)??!1:a[e.id]===t,onClick:()=>{if(e.multiSelect){d(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};l(n),F||ie(n)},children:[(0,B.jsxs)(`span`,{className:`question-option-label`,children:[e.multiSelect&&(0,B.jsx)(`span`,{"aria-hidden":`true`,className:`question-check`,children:u[e.id]?.includes(t)&&(0,B.jsx)(s,{name:`check`,size:`small`})}),t]}),e.descriptions?.[t]&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{className:`question-option-separator`,"aria-hidden":`true`,children:`|`}),(0,B.jsx)(`span`,{className:`question-option-description`,title:e.descriptions[t],children:e.descriptions[t]})]})]},t))}),e.freeText&&M&&(0,B.jsx)(Ye,{initialValue:e.initialValue,placeholder:e.placeholder,disabled:h,onSend:async t=>{let n={...a,[e.id]:t};return l(n),F?!0:ie(n)}}),M&&F&&a[e.id]&&!e.options.includes(a[e.id])&&(0,B.jsx)(`small`,{children:a[e.id]}),!M&&!t.approval&&(A?.answers[e.id]||A?.selections?.[e.id]?.length)&&(0,B.jsxs)(`div`,{className:`question-response`,children:[(0,B.jsx)(s,{name:j?`check`:`clock`,size:`small`}),(0,B.jsx)(`span`,{children:[...A.selections?.[e.id]??[],A.answers[e.id]].filter(Boolean).join(`、`)})]})]},e.id)),M&&t.actions?.length&&(0,B.jsx)(`div`,{className:`question-actions`,children:t.actions.map(e=>(0,B.jsx)(`button`,{disabled:h,onClick:()=>void E({body:e.label,actionId:e.id}),children:e.label},e.id))}),M&&F&&(0,B.jsx)(`div`,{className:`question-actions`,children:(0,B.jsx)(`button`,{disabled:h||t.questions.some(e=>!a[e.id]?.trim()&&!u[e.id]?.length),onClick:()=>void ie(),children:`回答`})})]}),re&&(!t.approval||ne)&&(0,B.jsxs)(`small`,{className:`question-result`,children:[(0,B.jsx)(s,{name:P,size:`small`}),re]}),(0,B.jsx)(_,{error:!0,children:f})]})}function Ze({session:t,active:n,commands:r,request:i,refresh:a,onError:o}){let[c,l]=(0,z.useState)(!1),[u,d]=(0,z.useState)(),f=(0,z.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,B.jsxs)(`button`,{type:`button`,className:`message-stop`,"aria-label":h?`正在停止`:`停止当前轮`,title:h?`正在停止`:`停止当前轮`,disabled:!!h,onClick:()=>void g(),children:[(0,B.jsx)(`span`,{className:`message-stop-ring`,"aria-hidden":`true`}),(0,B.jsx)(s,{name:`stop`,size:`small`})]})}var Z={minimal:`极低`,low:`低`,medium:`中`,high:`高`,xhigh:`极高`,max:`最高`,ultra:`极致`,none:`无`,off:`关闭`};function Q({id:e,label:t,current:n,options:r,disabled:i,onSelect:a}){let o=r.find(e=>e.value===n);return(0,B.jsx)(b,{id:`${e}-menu`,triggerId:e,placement:`top`,className:`composer-menu composer-choice`,label:`选择${t}`,disabled:i,routeKey:n,trigger:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`span`,{title:`${t}:${o?.label??n}`,children:o?.shortLabel??o?.label??n}),(0,B.jsx)(s,{name:`chevronDown`,size:`small`})]}),children:e=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`composer-menu-heading`,children:t}),r.map(t=>(0,B.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-label":t.label,onClick:()=>{e(),a(t.value)},children:[(0,B.jsxs)(`span`,{className:`composer-option-copy`,children:[(0,B.jsx)(`span`,{children:t.label}),t.description&&(0,B.jsx)(`small`,{children:t.description})]}),t.value===n&&(0,B.jsx)(s,{name:`check`,size:`small`})]},t.value))]})})}function Qe({session:e,models:t,busy:n,available:r,online:i,commands:a,controls:o,draft:c,onInsert:l,onConfig:u}){let[d,f]=(0,z.useState)(!1);(0,z.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:Z[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,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(b,{id:`session-commands`,triggerId:`session-command-trigger`,label:`命令与 Skills`,placement:`top`,className:`composer-menu composer-commands`,routeKey:e.id,trigger:(0,B.jsx)(s,{name:`command`,size:`small`}),open:d,onOpenChange:f,focusFirst:!1,disabled:h||!i,children:e=>(0,B.jsxs)(B.Fragment,{children:[[...a].sort((e,t)=>e.name.localeCompare(t.name,`en`)).map(t=>(0,B.jsx)(`button`,{type:`button`,role:`menuitem`,title:[t.description,t.path].filter(Boolean).join(`
12
- `),onClick:()=>{e(),l(t)},children:(0,B.jsxs)(`span`,{className:`composer-command-row`,children:[(0,B.jsxs)(`span`,{className:`composer-command-name`,children:[t.prefix??(t.kind===`skill`?`$`:`/`),t.name]}),(0,B.jsx)(`small`,{children:t.description})]})},`${t.kind}:${t.path??t.name}`)),!a.length&&(0,B.jsx)(`div`,{className:`composer-menu-heading`,children:`尚未获取命令`})]})}),(0,B.jsx)(Q,{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,B.jsx)(Q,{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,B.jsx)(Q,{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,B.jsx)(Q,{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 $e=(0,z.lazy)(()=>le(()=>import(`./TerminalPane-DDJO3cDO.js`),__vite__mapDeps([0,1,2,3,4,5,6]),import.meta.url)),et=v({ok:c()}),tt={idle:`空闲`,working:`工作中`,waiting:`等待回答`,queued:`等待执行`,uncertain:`需要核对`,human:`人工处理`,offered:`待本地接收`,accepted:`本地已接手`,human_routed:`未送达本地`,pending:`待投递`,sent:`已发送`,succeeded:`已完成`,running:`进行中`,failed:`失败`};function nt({navigate:e,memberId:t}){let{request:n,projectId:r}=A(),i=(0,z.useCallback)(e=>n(`web/local-agent-settings`,N,{signal:e}),[n]),a=C(i,3e4);return(0,z.useEffect)(()=>{let e=()=>void a.reload();return window.addEventListener(`teammy:local-access`,e),()=>window.removeEventListener(`teammy:local-access`,e)},[a.reload]),a.error?(0,B.jsx)(_,{error:!0,children:a.error}):a.data?(0,B.jsx)(rt,{localAvailable:a.data.accessible,navigate:e,memberId:t},`${r}/${t}`):null}function rt({localAvailable:n,navigate:r,memberId:a}){let c=A(),u=S(),d=t(c.projectId,a,`computer-selection`),f=t(c.projectId,a,`computer-drafts`),h=u?.get(d),[g,v]=(0,z.useState)(()=>new Set),[y,x]=(0,z.useState)(()=>({project:c.projectId,directory:new URLSearchParams(location.search).get(`directory`)??h?.directory??``,session:new URLSearchParams(location.search).get(`session`)??(new URLSearchParams(location.search).has(`terminal`)?``:h?.session??``),terminal:new URLSearchParams(location.search).get(`terminal`)??(new URLSearchParams(location.search).has(`session`)?``:h?.terminal??``)})),[w,E]=(0,z.useState)(``),[j,ee]=(0,z.useState)(!1),[M,N]=(0,z.useState)(!1),[P,F]=(0,z.useState)(()=>u?.get(f)??{}),oe=P[y.session]??``,le=e=>F(t=>({...t,[y.session]:typeof e==`function`?e(t[y.session]??``):e}));(0,z.useEffect)(()=>{u?.set(f,P)},[u,f,P]);let[I,pe]=(0,z.useState)(``),[me,L]=(0,z.useState)(!1),[R,ye]=(0,z.useState)(`codex`),[Se,V]=(0,z.useState)(!1),[Ce,we]=(0,z.useState)(``),[Ee,De]=(0,z.useState)(),[Oe,Ae]=(0,z.useState)(Date.now);(0,z.useEffect)(()=>{let e=setInterval(()=>Ae(Date.now()),6e4);return()=>clearInterval(e)},[]);let H=(0,z.useRef)(null),Ne=(0,z.useRef)(!0),Pe=(0,z.useRef)(void 0),Ie=(0,z.useRef)(e()),Le=(0,z.useCallback)(async e=>n?(await c.request(`web/local-agent-computers`,ie,{signal:e})).computers.map(e=>({...e,project:c.projectId})):[],[c,n]),U=C(Le,3e3),Re=(U.data??[]).flatMap(e=>e.directories.map(t=>({c:e,d:t,label:ue(U.data??[],e,t)}))).sort((e,t)=>e.label.localeCompare(t.label)),W=U.data?.find(e=>e.project===y.project&&e.directories.some(e=>e.id===y.directory)),G=Te(c.projectId,n),Ve=G.terminals.find(e=>e.id===y.terminal),He=(0,z.useRef)(Ve);Ve&&(He.current=Ve);let We=Ve??(He.current?.id===y.terminal?He.current:void 0),Ge=W?.directories.find(e=>e.id===y.directory),K=U.data?.find(e=>e.directories.some(e=>e.id===Ce))??W,q=K?.directories.find(e=>e.id===Ce)??Ge;D(y.project);let J=(0,z.useCallback)((e,t,n)=>D(y.project).request(e,t,n),[y.project]),Y=Be(y.session,y.project,J),Ke=(0,z.useCallback)(e=>y.session&&n?J(`web/local-agent-sessions/${y.session}`,se,{signal:e}):Promise.resolve(null),[J,y.session,n]),X=C(Ke,15e3),[qe,Ye]=(0,z.useState)(),Z=qe?.session.id===y.session&&(!X.data||qe.cursor>=X.data.cursor)?qe:X.data;(0,z.useEffect)(()=>{if(!y.session||!n)return;let e=new EventSource(i(`/api/v1/projects/${encodeURIComponent(y.project)}/web/local-agent-sessions/${encodeURIComponent(y.session)}/events`)),t=!0;return e.addEventListener(`snapshot`,e=>{try{let n=se.parse(JSON.parse(e.data));t&&Ye(e=>e?.session.id===n.session.id&&e.cursor>n.cursor?e:n)}catch(e){E(p(e))}}),()=>{t=!1,e.close()}},[y.project,y.session,n]),(0,z.useEffect)(()=>{Ne.current=!0},[y.project,y.session]),(0,z.useEffect)(()=>{Ne.current&&H.current&&(H.current.scrollTop=H.current.scrollHeight)},[Z?.cursor,Z?.messages.length]);let Q=Z?.session.id===y.session?Z.session:void 0;function nt({path:e,line:t}){let n=e.split(`/`).at(-1),r=/\/\.workspace\/\.teammy-attachments\/([0-9a-f-]{36})\/[^/]+$/i.exec(e);if(!y.terminal&&Q&&r){let e=Z?.messages.flatMap(e=>e.attachments??[]).find(e=>e.id===r[1]);De({...e,name:e?.name??n,line:t,url:ze(y.project,Q.id,r[1],!0)});return}let a=y.terminal?We?.directory:Q?.executionDirectory??Q?.directory;if(!a)return;let o=i(`/api/v1/projects/${encodeURIComponent(y.project)}/web/local-agents/${encodeURIComponent(a)}/file?${new URLSearchParams({path:e})}`),s=Me(n);De({name:n,line:t,url:o,previewUrl:o+(s.startsWith(`text/`)?`&view=text`:s?``:`&view=info`)})}let rt=W?.capabilities.includes(`local-sessions-v1`),$=(e,t,n=``,r=``)=>{De(void 0),x({project:e,directory:t,session:n,terminal:r}),u?.set(d,{directory:t,session:n,terminal:r}),L(!1),V(!1),E(``);let i=new URL(location.href);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===c.projectId&&history.replaceState(null,``,i)};(0,z.useEffect)(()=>{let e=U.data?.find(e=>e.sessions.some(e=>e.id===y.session))??U.data?.find(e=>e.directories.length);if(!y.directory&&e?.directories.length){let t=e.directories[0],n=e.sessions.find(e=>e.id===y.session);$(e.project,n?.directory??t.id,n?.id??t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id)}},[U.data]),(0,z.useEffect)(()=>{if(!Q)return;let e=()=>{document.visibilityState===`visible`&&J(`web/local-agent-sessions/${Q.id}/read`,et,{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 it(e){ee(!0),E(``);try{await e(),await Promise.all([X.reload(),U.reload()])}catch(e){E(p(e))}finally{ee(!1)}}function at(e,t){return it(async()=>{if(await c.request(`web/local-agent-sessions/${e.id}/metadata`,ae,{method:`PUT`,body:{expectedRevision:e.metadataRevision,...t}}),t.hidden&&y.session===e.id){let t=W?.sessions.find(t=>t.directory===e.directory&&t.id!==e.id&&!t.hidden);$(y.project,e.directory,t?.id)}})}function ot(e){let t=new URLSearchParams({tab:`directories`,directory:e,session:y.session});r(`/projects/${c.projectId}/settings?${t}`)}function st(t=y.directory){let n=U.data?.find(e=>e.directories.some(e=>e.id===t))??W,r=n?.directories.find(e=>e.id===t)??n?.directories[0];!r||!n?N(!0):(Ie.current=e(),we(r.id),L(!0),ye(r.provider),E(``))}let[ct,lt]=(0,z.useState)(null);(0,z.useEffect)(()=>lt(null),[Q?.id]);let ut=W?.catalogs.find(e=>e.provider===(Q?.provider??`codex`)&&(Q?.cwd?e.cwd===Q.cwd:e.directory===(Q?.executionDirectory??Q?.directory))),dt=ut?.commands??[],ft=ut?.models??W?.providers.find(e=>e.id===Q?.provider)?.models??(Q?.provider===`codex`?W?.models??[]:[]),pt=ft.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:ft.find(e=>e.isDefault)),mt=!!W?.capabilities.includes(`local-agent-attachments-v1`),ht=!!pt?.images&&!!W?.capabilities.includes(`local-agent-images-v1`),gt=Q?.state===`working`&&!Z?.commands.some(e=>e.kind===`stop`&&[`queued`,`running`].includes(e.state)),_t=Q?.provider===`cursor`&&W?.capabilities.includes(`local-agent-steer-v1`),vt=!W?.capabilities.includes(`local-agent-steer-v1`)&&(Q?.provider===`cursor`||Q?.provider===`claude`);function yt(t){let n=oe.trim();if(!Q||!n&&!Y.files.length)return;let r=Y.files.map(e=>e.id),i=ht?Y.files.filter(e=>e.mimeType!==`application/octet-stream`).map(e=>e.id):[],a=ct?.path&&n.startsWith(`$${ct.name}`)?[{name:ct.name,path:ct.path}]:void 0,s=JSON.stringify({session:Q.id,body:n,skills:a,attachments:r,images:i,delivery:t});Pe.current?.fingerprint!==s&&(Pe.current={fingerprint:s,id:e()});let c=Pe.current;it(async()=>{await J(`web/local-agent-sessions/${Q.id}/messages`,o(),{method:`POST`,body:{id:c.id,body:n,delivery:t,...i.length?{images:i}:{},...r.length?{attachments:r}:{},...a?{skills:a}:{}}}),le(e=>e.trim()===n?``:e),lt(null),Y.clear(),Pe.current===c&&(Pe.current=void 0)})}return(0,B.jsxs)(_e,{className:`computers-layout`,testId:`computers-page`,label:`本地会话`,tree:!0,navigation:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(O,{title:`电脑`}),(0,B.jsx)(`div`,{className:`assistant-message-scroll computer-tree`,role:`tree`,"aria-label":`目录与会话`,onKeyDown:be,children:Re.map(({c:e,d:t,label:n})=>{let r=`${e.project}/${t.id}`,i=!g.has(r);return(0,B.jsxs)(`div`,{role:`none`,children:[(0,B.jsxs)(`div`,{className:`computer-tree-row`,role:`none`,children:[(0,B.jsxs)(k,{className:`tree-item tree-folder`,role:`treeitem`,"aria-level":1,"aria-expanded":i,style:{"--tree-level":1},leading:(0,B.jsx)(`span`,{className:`tree-chevron ${i?`expanded`:``}`,children:(0,B.jsx)(s,{name:`chevron`,size:`small`})}),onClick:()=>{y.directory!==t.id&&$(e.project,t.id,t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id),v(e=>{let t=new Set(e);return i?t.add(r):t.delete(r),t})},children:[(0,B.jsx)(s,{name:`files`}),(0,B.jsx)(`span`,{className:`tree-name`,title:n,children:n})]}),(0,B.jsx)(m,{icon:`plus`,label:`新建会话:${n}`,className:`computer-tree-action`,onClick:()=>st(t.id)})]}),i&&(0,B.jsxs)(`div`,{role:`group`,children:[G.terminals.filter(e=>e.directory===t.id).map(n=>(0,B.jsx)(`div`,{className:`computer-tree-row computer-session-row computer-terminal-row`,role:`none`,children:(0,B.jsxs)(k,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":y.terminal===n.id,style:{"--tree-level":2},leading:(0,B.jsx)(`span`,{className:`tree-chevron`}),onClick:()=>$(e.project,t.id,``,n.id),children:[(0,B.jsx)(s,{name:`command`}),(0,B.jsxs)(`span`,{className:`computer-session-copy`,children:[(0,B.jsx)(`span`,{className:`tree-name`,children:n.title}),(0,B.jsx)(`time`,{dateTime:n.createdAt,children:n.state===`exited`?`已退出`:ke(n.createdAt,Oe)})]})]})},n.id)),e.sessions.filter(e=>e.directory===t.id).map(n=>(0,B.jsxs)(`div`,{className:`computer-tree-row computer-session-row`,role:`none`,children:[(0,B.jsxs)(k,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":y.session===n.id&&y.project===e.project,style:{"--tree-level":2},leading:(0,B.jsx)(`span`,{className:`tree-chevron`,children:(0,B.jsx)(`span`,{className:`assistant-message-dot ${n.unread?`unread`:``}`})}),title:`${n.title} · ${de[n.provider]}`,onClick:()=>$(e.project,t.id,n.id),children:[(0,B.jsx)(ne,{provider:n.provider}),(0,B.jsxs)(`span`,{className:`computer-session-copy`,children:[(0,B.jsx)(`span`,{className:`tree-name`,children:n.title}),(0,B.jsx)(`time`,{dateTime:n.updatedAt,title:new Date(n.updatedAt).toLocaleString(),children:ke(n.updatedAt,Oe)})]})]}),(0,B.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 at(n,{pinned:!n.pinned})}),n.archived?(0,B.jsx)(`span`,{title:`已归档`,role:`img`,"aria-label":`已归档`,children:(0,B.jsx)(s,{name:`archive`,size:`small`})}):n.state!==`idle`&&(0,B.jsx)(he,{state:n.state,label:tt[n.state]??n.state})]},n.id))]})]},t.id)})}),(0,B.jsx)(_,{error:!0,children:U.error})]}),children:[M&&(0,B.jsx)(te,{onClose:()=>N(!1)}),Se&&K&&q&&(0,B.jsx)(je,{directory:q.id,provider:q.provider,providers:K.providers.map(e=>e.id),sessions:K.sessions,request:J,onClose:()=>V(!1),onImport:e=>{$(y.project,e.directory,e.id),U.reload()}}),me&&q&&(0,B.jsx)(l,{id:`computer-new-session`,title:`新建会话`,onClose:()=>L(!1),children:(0,B.jsxs)(`form`,{className:`computer-panel stack`,onSubmit:t=>{t.preventDefault(),it(async()=>{if(R===`terminal`){let t=Ie.current;await G.request({type:`create`,id:t,directory:q.id,title:I.trim(),cols:100,rows:28}),Ie.current=e(),pe(``),$(y.project,q.id,``,t);return}let t=await J(`web/local-agents/${q.id}/sessions`,ae,{method:`POST`,body:{id:Ie.current,title:I,provider:R}});Ie.current=e(),L(!1),pe(``),$(y.project,q.id,t.id)})},children:[Re.length>1?(0,B.jsx)(fe,{title:`执行目录`,children:(0,B.jsx)(`select`,{"aria-label":`执行目录`,disabled:j,value:q.id,onChange:e=>{we(e.target.value),ye(Re.find(({d:t})=>t.id===e.target.value)?.d.provider??`codex`)},children:Re.map(({d:e,label:t})=>(0,B.jsx)(`option`,{value:e.id,children:t},e.id))})}):(0,B.jsxs)(`p`,{className:`muted computer-create-scope`,children:[`目录:`,q.name]}),(0,B.jsxs)(`label`,{children:[`会话名称`,(0,B.jsx)(`input`,{autoFocus:!0,required:!0,disabled:j,placeholder:`会话名称`,value:I,onChange:e=>pe(e.target.value)})]}),(0,B.jsx)(ce,{label:`会话类型`,value:R,onChange:ye,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:G.directories.includes(q.id)}),R===`terminal`&&(0,B.jsx)(`p`,{className:`muted computer-create-scope`,children:`在此目录启动本机 Shell,使用本机用户权限。`}),K?.providers.find(e=>e.id===R)?.error&&(0,B.jsx)(_,{children:K.providers.find(e=>e.id===R).error}),(0,B.jsx)(_,{error:!0,children:w}),(0,B.jsxs)(`div`,{className:`computer-create-options`,children:[R!==`terminal`&&(0,B.jsx)(`button`,{type:`button`,disabled:!K?.online||!K.capabilities.includes(`local-agent-history-v1`),onClick:()=>{L(!1),V(!0)},children:`导入历史会话`}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>{L(!1),N(!0)},children:`接入目录`}),(0,B.jsx)(`button`,{className:`primary`,disabled:j||!I.trim()||(R===`terminal`?!G.directories.includes(q.id):!rt),children:`创建`})]})]})}),Ee&&(0,B.jsx)(Fe,{file:Ee,onClose:()=>De(void 0)},Ee.url),y.terminal?We?(0,B.jsx)(z.Suspense,{fallback:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(T,{title:We.title}),(0,B.jsx)(`div`,{className:`assistant-empty`,children:`正在打开终端…`})]}),children:(0,B.jsx)($e,{terminal:We,onFile:nt,connection:G,onClosed:()=>$(y.project,y.directory)},We.id)}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(T,{title:`终端`}),(0,B.jsx)(`div`,{className:`assistant-empty`,children:G.connected?`终端已结束或电脑已重启,请新建终端。`:`正在连接终端…`})]}):Ge?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(T,{title:Q?(0,B.jsx)(xe,{title:Q.title,busy:j,onSave:e=>at(Q,{title:e})},Q.id):(0,B.jsx)(`h2`,{children:Ge.name}),actions:(0,B.jsx)(B.Fragment,{children:(0,B.jsx)(b,{id:`computer-session-menu`,triggerId:`computer-session-actions`,label:`会话操作`,trigger:(0,B.jsx)(s,{name:`more`}),className:`computer-create-menu`,routeKey:Q?.id??``,disabled:!Q,children:e=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{role:`menuitem`,disabled:j,onClick:()=>{e(),Q&&at(Q,{hidden:!0})},children:`隐藏会话`}),(0,B.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),ot(Ge.id)},children:`连接专用群`}),(0,B.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),ot(Ge.id)},children:`执行位置`})]})})})}),!rt&&(0,B.jsx)(_,{children:`升级客户端后可使用多个会话和网页对话。`}),(0,B.jsxs)(ge,{ref:H,onScroll:e=>{let t=e.currentTarget;Ne.current=t.scrollHeight-t.scrollTop-t.clientHeight<96},"aria-label":`本地会话记录`,children:[(0,B.jsx)(Je,{onFile:nt,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)=>ze(y.project,Q.id,e,t),renderQueue:e=>(0,B.jsx)(Ue,{message:e}),renderQuestion:e=>(0,B.jsx)(Xe,{question:e,session:Q.id,request:J,refresh:X.reload})}),!Z?.messages.length&&(0,B.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,B.jsxs)(`p`,{className:`computer-control-status`,role:`status`,children:[e.kind===`stop`?`停止`:e.kind,` · `,tt[e.state]??e.state,e.error?`:${e.error}`:``]},e.id)),(0,B.jsx)(_,{error:!0,children:w||X.error||Q?.error}),Q&&(0,B.jsx)(ve,{value:oe,onChange:le,label:`向本地 Agent 发送消息`,sendLabel:gt?_t?`中断并发送`:vt?`加入队列`:`插话`:`发送`,onQueue:[`working`,`waiting`].includes(Q.state)&&W?.capabilities.includes(`local-agent-queue-v1`)?()=>yt(`queue`):void 0,placeholder:Q.archived?`会话已归档`:`输入消息…`,disabled:Q.archived||!rt,sendDisabled:j||Y.busy||Y.failed||Y.count>0&&!mt||Z?.commands.some(e=>e.kind===`rewind`&&[`queued`,`running`,`uncertain`].includes(e.state)),attachments:(0,B.jsxs)(B.Fragment,{children:[Y.preview(j),Y.files.some(e=>e.mimeType!==`application/octet-stream`)&&!ht&&(0,B.jsx)(_,{children:`当前模型将通过本地文件路径接收图片。`})]}),hasAttachments:Y.count>0,onFiles:mt&&!j?e=>void Y.add(e):void 0,beforeSend:(0,B.jsx)(Ze,{session:Q.id,active:[`working`,`waiting`].includes(Q.state),commands:Z?.commands??[],request:J,refresh:X.reload,onError:E},Q.id),actions:(0,B.jsxs)(B.Fragment,{children:[mt?Y.picker(j||!rt,ht):ht?(0,B.jsx)(`span`,{title:`更新开发机客户端后可添加附件`,children:(0,B.jsx)(`button`,{type:`button`,className:`icon-button`,disabled:!0,"aria-label":`更新开发机客户端后可添加附件`,children:(0,B.jsx)(s,{name:`attachment`,size:`small`})})}):null,(0,B.jsx)(Qe,{session:Q,models:ft,busy:j,available:!!rt,online:!!W?.online,commands:dt,controls:ut?.controls,draft:oe,onInsert:e=>{lt(e.kind===`skill`?e:null),le(`${e.prefix??(e.kind===`skill`?`$`:`/`)}${e.name} `),requestAnimationFrame(()=>document.querySelector(`.message-composer textarea`)?.focus())},onConfig:e=>{it(()=>J(`web/local-agent-sessions/${Q.id}/settings`,ae,{method:`PUT`,body:{expectedRevision:Q.revision,config:e}}))}})]}),onSubmit:()=>yt(`auto`)})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(T,{title:`本地会话`}),(0,B.jsxs)(`div`,{className:`assistant-empty`,children:[`尚未登记本地执行目录。`,(0,B.jsx)(`button`,{onClick:()=>N(!0),children:`接入目录`})]})]})]})}export{nt as Computers,xe as t};
12
+ `),onClick:()=>{e(),l(t)},children:(0,B.jsxs)(`span`,{className:`composer-command-row`,children:[(0,B.jsxs)(`span`,{className:`composer-command-name`,children:[t.prefix??(t.kind===`skill`?`$`:`/`),t.name]}),(0,B.jsx)(`small`,{children:t.description})]})},`${t.kind}:${t.path??t.name}`)),!a.length&&(0,B.jsx)(`div`,{className:`composer-menu-heading`,children:`尚未获取命令`})]})}),(0,B.jsx)(Q,{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,B.jsx)(Q,{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,B.jsx)(Q,{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,B.jsx)(Q,{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 $e=(0,z.lazy)(()=>le(()=>import(`./TerminalPane-qvAQ5u5W.js`),__vite__mapDeps([0,1,2,3,4,5,6]),import.meta.url)),et=v({ok:c()}),tt={idle:`空闲`,working:`工作中`,waiting:`等待回答`,queued:`等待执行`,uncertain:`需要核对`,human:`人工处理`,offered:`待本地接收`,accepted:`本地已接手`,human_routed:`未送达本地`,pending:`待投递`,sent:`已发送`,succeeded:`已完成`,running:`进行中`,failed:`失败`};function nt({navigate:e,memberId:t}){let{request:n,projectId:r}=A(),i=(0,z.useCallback)(e=>n(`web/local-agent-settings`,N,{signal:e}),[n]),a=C(i,3e4);return(0,z.useEffect)(()=>{let e=()=>void a.reload();return window.addEventListener(`teammy:local-access`,e),()=>window.removeEventListener(`teammy:local-access`,e)},[a.reload]),a.error?(0,B.jsx)(_,{error:!0,children:a.error}):a.data?(0,B.jsx)(rt,{localAvailable:a.data.accessible,navigate:e,memberId:t},`${r}/${t}`):null}function rt({localAvailable:n,navigate:r,memberId:a}){let c=A(),u=S(),d=t(c.projectId,a,`computer-selection`),f=t(c.projectId,a,`computer-drafts`),h=u?.get(d),[g,v]=(0,z.useState)(()=>new Set),[y,x]=(0,z.useState)(()=>({project:c.projectId,directory:new URLSearchParams(location.search).get(`directory`)??h?.directory??``,session:new URLSearchParams(location.search).get(`session`)??(new URLSearchParams(location.search).has(`terminal`)?``:h?.session??``),terminal:new URLSearchParams(location.search).get(`terminal`)??(new URLSearchParams(location.search).has(`session`)?``:h?.terminal??``)})),[w,E]=(0,z.useState)(``),[j,ee]=(0,z.useState)(!1),[M,N]=(0,z.useState)(!1),[P,F]=(0,z.useState)(()=>u?.get(f)??{}),oe=P[y.session]??``,le=e=>F(t=>({...t,[y.session]:typeof e==`function`?e(t[y.session]??``):e}));(0,z.useEffect)(()=>{u?.set(f,P)},[u,f,P]);let[I,pe]=(0,z.useState)(``),[me,L]=(0,z.useState)(!1),[R,ye]=(0,z.useState)(`codex`),[Se,V]=(0,z.useState)(!1),[Ce,we]=(0,z.useState)(``),[Ee,De]=(0,z.useState)(),[Oe,Ae]=(0,z.useState)(Date.now);(0,z.useEffect)(()=>{let e=setInterval(()=>Ae(Date.now()),6e4);return()=>clearInterval(e)},[]);let H=(0,z.useRef)(null),Ne=(0,z.useRef)(!0),Pe=(0,z.useRef)(void 0),Ie=(0,z.useRef)(e()),Le=(0,z.useCallback)(async e=>n?(await c.request(`web/local-agent-computers`,ie,{signal:e})).computers.map(e=>({...e,project:c.projectId})):[],[c,n]),U=C(Le,3e3),Re=(U.data??[]).flatMap(e=>e.directories.map(t=>({c:e,d:t,label:ue(U.data??[],e,t)}))).sort((e,t)=>e.label.localeCompare(t.label)),W=U.data?.find(e=>e.project===y.project&&e.directories.some(e=>e.id===y.directory)),G=Te(c.projectId,n),Ve=G.terminals.find(e=>e.id===y.terminal),He=(0,z.useRef)(Ve);Ve&&(He.current=Ve);let We=Ve??(He.current?.id===y.terminal?He.current:void 0),Ge=W?.directories.find(e=>e.id===y.directory),K=U.data?.find(e=>e.directories.some(e=>e.id===Ce))??W,q=K?.directories.find(e=>e.id===Ce)??Ge;D(y.project);let J=(0,z.useCallback)((e,t,n)=>D(y.project).request(e,t,n),[y.project]),Y=Be(y.session,y.project,J),Ke=(0,z.useCallback)(e=>y.session&&n?J(`web/local-agent-sessions/${y.session}`,se,{signal:e}):Promise.resolve(null),[J,y.session,n]),X=C(Ke,15e3),[qe,Ye]=(0,z.useState)(),Z=qe?.session.id===y.session&&(!X.data||qe.cursor>=X.data.cursor)?qe:X.data;(0,z.useEffect)(()=>{if(!y.session||!n)return;let e=new EventSource(i(`/api/v1/projects/${encodeURIComponent(y.project)}/web/local-agent-sessions/${encodeURIComponent(y.session)}/events`)),t=!0;return e.addEventListener(`snapshot`,e=>{try{let n=se.parse(JSON.parse(e.data));t&&Ye(e=>e?.session.id===n.session.id&&e.cursor>n.cursor?e:n)}catch(e){E(p(e))}}),()=>{t=!1,e.close()}},[y.project,y.session,n]),(0,z.useEffect)(()=>{Ne.current=!0},[y.project,y.session]),(0,z.useEffect)(()=>{Ne.current&&H.current&&(H.current.scrollTop=H.current.scrollHeight)},[Z?.cursor,Z?.messages.length]);let Q=Z?.session.id===y.session?Z.session:void 0;function nt({path:e,line:t}){let n=e.split(`/`).at(-1),r=/\/\.workspace\/\.teammy-attachments\/([0-9a-f-]{36})\/[^/]+$/i.exec(e);if(!y.terminal&&Q&&r){let e=Z?.messages.flatMap(e=>e.attachments??[]).find(e=>e.id===r[1]);De({...e,name:e?.name??n,line:t,url:ze(y.project,Q.id,r[1],!0)});return}let a=y.terminal?We?.directory:Q?.executionDirectory??Q?.directory;if(!a)return;let o=i(`/api/v1/projects/${encodeURIComponent(y.project)}/web/local-agents/${encodeURIComponent(a)}/file?${new URLSearchParams({path:e})}`),s=Me(n);De({name:n,line:t,url:o,previewUrl:o+(s.startsWith(`text/`)?`&view=text`:s?``:`&view=info`)})}let rt=W?.capabilities.includes(`local-sessions-v1`),$=(e,t,n=``,r=``)=>{De(void 0),x({project:e,directory:t,session:n,terminal:r}),u?.set(d,{directory:t,session:n,terminal:r}),L(!1),V(!1),E(``);let i=new URL(location.href);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===c.projectId&&history.replaceState(null,``,i)};(0,z.useEffect)(()=>{let e=U.data?.find(e=>e.sessions.some(e=>e.id===y.session))??U.data?.find(e=>e.directories.length);if(!y.directory&&e?.directories.length){let t=e.directories[0],n=e.sessions.find(e=>e.id===y.session);$(e.project,n?.directory??t.id,n?.id??t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id)}},[U.data]),(0,z.useEffect)(()=>{if(!Q)return;let e=()=>{document.visibilityState===`visible`&&J(`web/local-agent-sessions/${Q.id}/read`,et,{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 it(e){ee(!0),E(``);try{await e(),await Promise.all([X.reload(),U.reload()])}catch(e){E(p(e))}finally{ee(!1)}}function at(e,t){return it(async()=>{if(await c.request(`web/local-agent-sessions/${e.id}/metadata`,ae,{method:`PUT`,body:{expectedRevision:e.metadataRevision,...t}}),t.hidden&&y.session===e.id){let t=W?.sessions.find(t=>t.directory===e.directory&&t.id!==e.id&&!t.hidden);$(y.project,e.directory,t?.id)}})}function ot(e){let t=new URLSearchParams({tab:`directories`,directory:e,session:y.session});r(`/projects/${c.projectId}/settings?${t}`)}function st(t=y.directory){let n=U.data?.find(e=>e.directories.some(e=>e.id===t))??W,r=n?.directories.find(e=>e.id===t)??n?.directories[0];!r||!n?N(!0):(Ie.current=e(),we(r.id),L(!0),ye(r.provider),E(``))}let[ct,lt]=(0,z.useState)(null);(0,z.useEffect)(()=>lt(null),[Q?.id]);let ut=W?.catalogs.find(e=>e.provider===(Q?.provider??`codex`)&&(Q?.cwd?e.cwd===Q.cwd:e.directory===(Q?.executionDirectory??Q?.directory))),dt=ut?.commands??[],ft=ut?.models??W?.providers.find(e=>e.id===Q?.provider)?.models??(Q?.provider===`codex`?W?.models??[]:[]),pt=ft.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:ft.find(e=>e.isDefault)),mt=!!W?.capabilities.includes(`local-agent-attachments-v1`),ht=!!pt?.images&&!!W?.capabilities.includes(`local-agent-images-v1`),gt=Q?.state===`working`&&!Z?.commands.some(e=>e.kind===`stop`&&[`queued`,`running`].includes(e.state)),_t=Q?.provider===`cursor`&&W?.capabilities.includes(`local-agent-steer-v1`),vt=!W?.capabilities.includes(`local-agent-steer-v1`)&&(Q?.provider===`cursor`||Q?.provider===`claude`);function yt(t){let n=oe.trim();if(!Q||!n&&!Y.files.length)return;let r=Y.files.map(e=>e.id),i=ht?Y.files.filter(e=>e.mimeType!==`application/octet-stream`).map(e=>e.id):[],a=ct?.path&&n.startsWith(`$${ct.name}`)?[{name:ct.name,path:ct.path}]:void 0,s=JSON.stringify({session:Q.id,body:n,skills:a,attachments:r,images:i,delivery:t});Pe.current?.fingerprint!==s&&(Pe.current={fingerprint:s,id:e()});let c=Pe.current;it(async()=>{await J(`web/local-agent-sessions/${Q.id}/messages`,o(),{method:`POST`,body:{id:c.id,body:n,delivery:t,...i.length?{images:i}:{},...r.length?{attachments:r}:{},...a?{skills:a}:{}}}),le(e=>e.trim()===n?``:e),lt(null),Y.clear(),Pe.current===c&&(Pe.current=void 0)})}return(0,B.jsxs)(_e,{className:`computers-layout`,testId:`computers-page`,label:`本地会话`,tree:!0,navigation:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(O,{title:`电脑`}),(0,B.jsx)(`div`,{className:`assistant-message-scroll computer-tree`,role:`tree`,"aria-label":`目录与会话`,onKeyDown:be,children:Re.map(({c:e,d:t,label:n})=>{let r=`${e.project}/${t.id}`,i=!g.has(r);return(0,B.jsxs)(`div`,{role:`none`,children:[(0,B.jsxs)(`div`,{className:`computer-tree-row`,role:`none`,children:[(0,B.jsxs)(k,{className:`tree-item tree-folder`,role:`treeitem`,"aria-level":1,"aria-expanded":i,style:{"--tree-level":1},leading:(0,B.jsx)(`span`,{className:`tree-chevron ${i?`expanded`:``}`,children:(0,B.jsx)(s,{name:`chevron`,size:`small`})}),onClick:()=>{y.directory!==t.id&&$(e.project,t.id,t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id),v(e=>{let t=new Set(e);return i?t.add(r):t.delete(r),t})},children:[(0,B.jsx)(s,{name:`files`}),(0,B.jsx)(`span`,{className:`tree-name`,title:n,children:n})]}),(0,B.jsx)(m,{icon:`plus`,label:`新建会话:${n}`,className:`computer-tree-action`,onClick:()=>st(t.id)})]}),i&&(0,B.jsxs)(`div`,{role:`group`,children:[G.terminals.filter(e=>e.directory===t.id).map(n=>(0,B.jsx)(`div`,{className:`computer-tree-row computer-session-row computer-terminal-row`,role:`none`,children:(0,B.jsxs)(k,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":y.terminal===n.id,style:{"--tree-level":2},leading:(0,B.jsx)(`span`,{className:`tree-chevron`}),onClick:()=>$(e.project,t.id,``,n.id),children:[(0,B.jsx)(s,{name:`command`}),(0,B.jsxs)(`span`,{className:`computer-session-copy`,children:[(0,B.jsx)(`span`,{className:`tree-name`,children:n.title}),(0,B.jsx)(`time`,{dateTime:n.createdAt,children:n.state===`exited`?`已退出`:ke(n.createdAt,Oe)})]})]})},n.id)),e.sessions.filter(e=>e.directory===t.id).map(n=>(0,B.jsxs)(`div`,{className:`computer-tree-row computer-session-row`,role:`none`,children:[(0,B.jsxs)(k,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":y.session===n.id&&y.project===e.project,style:{"--tree-level":2},leading:(0,B.jsx)(`span`,{className:`tree-chevron`,children:(0,B.jsx)(`span`,{className:`assistant-message-dot ${n.unread?`unread`:``}`})}),title:`${n.title} · ${de[n.provider]}`,onClick:()=>$(e.project,t.id,n.id),children:[(0,B.jsx)(ne,{provider:n.provider}),(0,B.jsxs)(`span`,{className:`computer-session-copy`,children:[(0,B.jsx)(`span`,{className:`tree-name`,children:n.title}),(0,B.jsx)(`time`,{dateTime:n.updatedAt,title:new Date(n.updatedAt).toLocaleString(),children:ke(n.updatedAt,Oe)})]})]}),(0,B.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 at(n,{pinned:!n.pinned})}),n.archived?(0,B.jsx)(`span`,{title:`已归档`,role:`img`,"aria-label":`已归档`,children:(0,B.jsx)(s,{name:`archive`,size:`small`})}):n.state!==`idle`&&(0,B.jsx)(he,{state:n.state,label:tt[n.state]??n.state})]},n.id))]})]},t.id)})}),(0,B.jsx)(_,{error:!0,children:U.error})]}),children:[M&&(0,B.jsx)(te,{onClose:()=>N(!1)}),Se&&K&&q&&(0,B.jsx)(je,{directory:q.id,provider:q.provider,providers:K.providers.map(e=>e.id),sessions:K.sessions,request:J,onClose:()=>V(!1),onImport:e=>{$(y.project,e.directory,e.id),U.reload()}}),me&&q&&(0,B.jsx)(l,{id:`computer-new-session`,title:`新建会话`,onClose:()=>L(!1),children:(0,B.jsxs)(`form`,{className:`computer-panel stack`,onSubmit:t=>{t.preventDefault(),it(async()=>{if(R===`terminal`){let t=Ie.current;await G.request({type:`create`,id:t,directory:q.id,title:I.trim(),cols:100,rows:28}),Ie.current=e(),pe(``),$(y.project,q.id,``,t);return}let t=await J(`web/local-agents/${q.id}/sessions`,ae,{method:`POST`,body:{id:Ie.current,title:I,provider:R}});Ie.current=e(),L(!1),pe(``),$(y.project,q.id,t.id)})},children:[Re.length>1?(0,B.jsx)(fe,{title:`执行目录`,children:(0,B.jsx)(`select`,{"aria-label":`执行目录`,disabled:j,value:q.id,onChange:e=>{we(e.target.value),ye(Re.find(({d:t})=>t.id===e.target.value)?.d.provider??`codex`)},children:Re.map(({d:e,label:t})=>(0,B.jsx)(`option`,{value:e.id,children:t},e.id))})}):(0,B.jsxs)(`p`,{className:`muted computer-create-scope`,children:[`目录:`,q.name]}),(0,B.jsxs)(`label`,{children:[`会话名称`,(0,B.jsx)(`input`,{autoFocus:!0,required:!0,disabled:j,placeholder:`会话名称`,value:I,onChange:e=>pe(e.target.value)})]}),(0,B.jsx)(ce,{label:`会话类型`,value:R,onChange:ye,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:G.directories.includes(q.id)}),R===`terminal`&&(0,B.jsx)(`p`,{className:`muted computer-create-scope`,children:`在此目录启动本机 Shell,使用本机用户权限。`}),K?.providers.find(e=>e.id===R)?.error&&(0,B.jsx)(_,{children:K.providers.find(e=>e.id===R).error}),(0,B.jsx)(_,{error:!0,children:w}),(0,B.jsxs)(`div`,{className:`computer-create-options`,children:[R!==`terminal`&&(0,B.jsx)(`button`,{type:`button`,disabled:!K?.online||!K.capabilities.includes(`local-agent-history-v1`),onClick:()=>{L(!1),V(!0)},children:`导入历史会话`}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>{L(!1),N(!0)},children:`接入目录`}),(0,B.jsx)(`button`,{className:`primary`,disabled:j||!I.trim()||(R===`terminal`?!G.directories.includes(q.id):!rt),children:`创建`})]})]})}),Ee&&(0,B.jsx)(Fe,{file:Ee,onClose:()=>De(void 0)},Ee.url),y.terminal?We?(0,B.jsx)(z.Suspense,{fallback:(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(T,{title:We.title}),(0,B.jsx)(`div`,{className:`assistant-empty`,children:`正在打开终端…`})]}),children:(0,B.jsx)($e,{terminal:We,onFile:nt,connection:G,onClosed:()=>$(y.project,y.directory)},We.id)}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(T,{title:`终端`}),(0,B.jsx)(`div`,{className:`assistant-empty`,children:G.connected?`终端已结束或电脑已重启,请新建终端。`:`正在连接终端…`})]}):Ge?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(T,{title:Q?(0,B.jsx)(xe,{title:Q.title,busy:j,onSave:e=>at(Q,{title:e})},Q.id):(0,B.jsx)(`h2`,{children:Ge.name}),actions:(0,B.jsx)(B.Fragment,{children:(0,B.jsx)(b,{id:`computer-session-menu`,triggerId:`computer-session-actions`,label:`会话操作`,trigger:(0,B.jsx)(s,{name:`more`}),className:`computer-create-menu`,routeKey:Q?.id??``,disabled:!Q,children:e=>(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`button`,{role:`menuitem`,disabled:j,onClick:()=>{e(),Q&&at(Q,{hidden:!0})},children:`隐藏会话`}),(0,B.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),ot(Ge.id)},children:`连接专用群`}),(0,B.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),ot(Ge.id)},children:`执行位置`})]})})})}),!rt&&(0,B.jsx)(_,{children:`升级客户端后可使用多个会话和网页对话。`}),(0,B.jsxs)(ge,{ref:H,onScroll:e=>{let t=e.currentTarget;Ne.current=t.scrollHeight-t.scrollTop-t.clientHeight<96},"aria-label":`本地会话记录`,children:[(0,B.jsx)(Je,{onFile:nt,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)=>ze(y.project,Q.id,e,t),renderQueue:e=>(0,B.jsx)(Ue,{message:e}),renderQuestion:e=>(0,B.jsx)(Xe,{question:e,session:Q.id,request:J,refresh:X.reload})}),!Z?.messages.length&&(0,B.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,B.jsxs)(`p`,{className:`computer-control-status`,role:`status`,children:[e.kind===`stop`?`停止`:e.kind,` · `,tt[e.state]??e.state,e.error?`:${e.error}`:``]},e.id)),(0,B.jsx)(_,{error:!0,children:w||X.error||Q?.error}),Q&&(0,B.jsx)(ve,{value:oe,onChange:le,label:`向本地 Agent 发送消息`,sendLabel:gt?_t?`中断并发送`:vt?`加入队列`:`插话`:`发送`,onQueue:[`working`,`waiting`].includes(Q.state)&&W?.capabilities.includes(`local-agent-queue-v1`)?()=>yt(`queue`):void 0,placeholder:Q.archived?`会话已归档`:`输入消息…`,disabled:Q.archived||!rt,sendDisabled:j||Y.busy||Y.failed||Y.count>0&&!mt||Z?.commands.some(e=>e.kind===`rewind`&&[`queued`,`running`,`uncertain`].includes(e.state)),attachments:(0,B.jsxs)(B.Fragment,{children:[Y.preview(j),Y.files.some(e=>e.mimeType!==`application/octet-stream`)&&!ht&&(0,B.jsx)(_,{children:`当前模型将通过本地文件路径接收图片。`})]}),hasAttachments:Y.count>0,onFiles:mt&&!j?e=>void Y.add(e):void 0,beforeSend:(0,B.jsx)(Ze,{session:Q.id,active:[`working`,`waiting`].includes(Q.state),commands:Z?.commands??[],request:J,refresh:X.reload,onError:E},Q.id),actions:(0,B.jsxs)(B.Fragment,{children:[mt?Y.picker(j||!rt,ht):ht?(0,B.jsx)(`span`,{title:`更新开发机客户端后可添加附件`,children:(0,B.jsx)(`button`,{type:`button`,className:`icon-button`,disabled:!0,"aria-label":`更新开发机客户端后可添加附件`,children:(0,B.jsx)(s,{name:`attachment`,size:`small`})})}):null,(0,B.jsx)(Qe,{session:Q,models:ft,busy:j,available:!!rt,online:!!W?.online,commands:dt,controls:ut?.controls,draft:oe,onInsert:e=>{lt(e.kind===`skill`?e:null),le(`${e.prefix??(e.kind===`skill`?`$`:`/`)}${e.name} `),requestAnimationFrame(()=>document.querySelector(`.message-composer textarea`)?.focus())},onConfig:e=>{it(()=>J(`web/local-agent-sessions/${Q.id}/settings`,ae,{method:`PUT`,body:{expectedRevision:Q.revision,config:e}}))}})]}),onSubmit:()=>yt(`auto`)})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(T,{title:`本地会话`}),(0,B.jsxs)(`div`,{className:`assistant-empty`,children:[`尚未登记本地执行目录。`,(0,B.jsx)(`button`,{onClick:()=>N(!0),children:`接入目录`})]})]})]})}export{nt as Computers,xe as t};
@@ -1 +1 @@
1
- import{T as e}from"./Dropdown-D625ln2m.js";import{N as t}from"./index-DjMoKD7A.js";var n=e();function r({navigation:e,children:r,className:i=``,tree:a=!1,label:o,testId:s}){return(0,n.jsx)(t,{className:`assistant-layout conversation-layout ${i}`,"data-testid":s,navigation:(0,n.jsx)(`aside`,{className:`assistant-list ${a?`file-tree-pane`:``}`,"aria-label":`${o}列表`,children:e}),children:(0,n.jsx)(`section`,{className:`assistant-thread`,"aria-label":o,children:r})})}function i({mine:e=!1,author:t,time:r,children:i,className:a=``,ref:o,...s}){return(0,n.jsx)(`div`,{...s,ref:o,className:`assistant-bubble-row ${e?`mine`:``} ${a}`,children:(0,n.jsxs)(`div`,{className:`assistant-bubble`,children:[(0,n.jsxs)(`div`,{className:`assistant-bubble-meta`,children:[(0,n.jsx)(`span`,{children:t}),r&&(0,n.jsx)(`time`,{dateTime:r,children:new Date(r).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})})]}),i]})})}function a({label:e,state:t=`idle`}){return(0,n.jsx)(`span`,{className:`conversation-status state-${t}`,role:`img`,"aria-label":e,title:e})}function o({author:e,time:t,children:r}){return(0,n.jsxs)(`article`,{className:`conversation-post assistant-bubble`,children:[(0,n.jsxs)(`header`,{className:`assistant-bubble-meta`,children:[(0,n.jsx)(`strong`,{children:e}),t&&(0,n.jsx)(`time`,{dateTime:t,children:new Date(t).toLocaleString(`zh-CN`,{month:`numeric`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})})]}),r]})}function s({ref:e,...t}){return(0,n.jsx)(`div`,{role:`log`,"aria-live":`polite`,...t,ref:e,className:`assistant-transcript`})}export{a,s as i,r as n,o as r,i as t};
1
+ import{T as e}from"./Dropdown-ClJ8qPeL.js";import{N as t}from"./index-Dj9Jdm4p.js";var n=e();function r({navigation:e,children:r,className:i=``,tree:a=!1,label:o,testId:s}){return(0,n.jsx)(t,{className:`assistant-layout conversation-layout ${i}`,"data-testid":s,navigation:(0,n.jsx)(`aside`,{className:`assistant-list ${a?`file-tree-pane`:``}`,"aria-label":`${o}列表`,children:e}),children:(0,n.jsx)(`section`,{className:`assistant-thread`,"aria-label":o,children:r})})}function i({mine:e=!1,author:t,time:r,children:i,className:a=``,ref:o,...s}){return(0,n.jsx)(`div`,{...s,ref:o,className:`assistant-bubble-row ${e?`mine`:``} ${a}`,children:(0,n.jsxs)(`div`,{className:`assistant-bubble`,children:[(0,n.jsxs)(`div`,{className:`assistant-bubble-meta`,children:[(0,n.jsx)(`span`,{children:t}),r&&(0,n.jsx)(`time`,{dateTime:r,children:new Date(r).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})})]}),i]})})}function a({label:e,state:t=`idle`}){return(0,n.jsx)(`span`,{className:`conversation-status state-${t}`,role:`img`,"aria-label":e,title:e})}function o({author:e,time:t,children:r}){return(0,n.jsxs)(`article`,{className:`conversation-post assistant-bubble`,children:[(0,n.jsxs)(`header`,{className:`assistant-bubble-meta`,children:[(0,n.jsx)(`strong`,{children:e}),t&&(0,n.jsx)(`time`,{dateTime:t,children:new Date(t).toLocaleString(`zh-CN`,{month:`numeric`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})})]}),r]})}function s({ref:e,...t}){return(0,n.jsx)(`div`,{role:`log`,"aria-live":`polite`,...t,ref:e,className:`assistant-transcript`})}export{a,s as i,r as n,o as r,i as t};
@@ -0,0 +1 @@
1
+ import{C as e,Dt as t,Et as n,St as r,T as i,_ as a,a as o,b as s,c,d as l,k as u,kt as d,l as f,m as p,p as m,r as h,s as g,t as _,v,x as y,xt as b,y as x}from"./Dropdown-ClJ8qPeL.js";import{B as S,R as C,V as w}from"./index-Dj9Jdm4p.js";import{n as T,o as E,r as D,t as O}from"./task-links-zc4fWZyK.js";import"./file-links-DlYR_xxD.js";var k=t(((e,t)=>{t.exports=typeof process==`object`&&{}.NODE_DEBUG&&/\bsemver\b/i.test({}.NODE_DEBUG)?(...e)=>console.error(`SEMVER`,...e):()=>{}})),A=t(((e,t)=>{t.exports={MAX_LENGTH:256,MAX_SAFE_COMPONENT_LENGTH:16,MAX_SAFE_BUILD_LENGTH:250,MAX_SAFE_INTEGER:2**53-1||9007199254740991,RELEASE_TYPES:[`major`,`premajor`,`minor`,`preminor`,`patch`,`prepatch`,`prerelease`],SEMVER_SPEC_VERSION:`2.0.0`,FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2}})),j=t(((e,t)=>{var{MAX_SAFE_COMPONENT_LENGTH:n,MAX_SAFE_BUILD_LENGTH:r,MAX_LENGTH:i}=A(),a=k();e=t.exports={};var o=e.re=[],s=e.safeRe=[],c=e.src=[],l=e.safeSrc=[],u=e.t={},d=0,f=`[a-zA-Z0-9-]`,p=[[`\\s`,1],[`\\d`,i],[f,r]],m=e=>{for(let[t,n]of p)e=e.split(`${t}*`).join(`${t}{0,${n}}`).split(`${t}+`).join(`${t}{1,${n}}`);return e},h=(e,t,n)=>{let r=m(t),i=d++;a(e,i,t),u[e]=i,c[i]=t,l[i]=r,o[i]=new RegExp(t,n?`g`:void 0),s[i]=new RegExp(r,n?`g`:void 0)};h(`NUMERICIDENTIFIER`,`0|[1-9]\\d*`),h(`NUMERICIDENTIFIERLOOSE`,`\\d+`),h(`NONNUMERICIDENTIFIER`,`\\d*[a-zA-Z-]${f}*`),h(`MAINVERSION`,`(${c[u.NUMERICIDENTIFIER]})\\.(${c[u.NUMERICIDENTIFIER]})\\.(${c[u.NUMERICIDENTIFIER]})`),h(`MAINVERSIONLOOSE`,`(${c[u.NUMERICIDENTIFIERLOOSE]})\\.(${c[u.NUMERICIDENTIFIERLOOSE]})\\.(${c[u.NUMERICIDENTIFIERLOOSE]})`),h(`PRERELEASEIDENTIFIER`,`(?:${c[u.NONNUMERICIDENTIFIER]}|${c[u.NUMERICIDENTIFIER]})`),h(`PRERELEASEIDENTIFIERLOOSE`,`(?:${c[u.NONNUMERICIDENTIFIER]}|${c[u.NUMERICIDENTIFIERLOOSE]})`),h(`PRERELEASE`,`(?:-(${c[u.PRERELEASEIDENTIFIER]}(?:\\.${c[u.PRERELEASEIDENTIFIER]})*))`),h(`PRERELEASELOOSE`,`(?:-?(${c[u.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${c[u.PRERELEASEIDENTIFIERLOOSE]})*))`),h(`BUILDIDENTIFIER`,`${f}+`),h(`BUILD`,`(?:\\+(${c[u.BUILDIDENTIFIER]}(?:\\.${c[u.BUILDIDENTIFIER]})*))`),h(`FULLPLAIN`,`v?${c[u.MAINVERSION]}${c[u.PRERELEASE]}?${c[u.BUILD]}?`),h(`FULL`,`^${c[u.FULLPLAIN]}$`),h(`LOOSEPLAIN`,`[v=\\s]*${c[u.MAINVERSIONLOOSE]}${c[u.PRERELEASELOOSE]}?${c[u.BUILD]}?`),h(`LOOSE`,`^${c[u.LOOSEPLAIN]}$`),h(`GTLT`,`((?:<|>)?=?)`),h(`XRANGEIDENTIFIERLOOSE`,`${c[u.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`),h(`XRANGEIDENTIFIER`,`${c[u.NUMERICIDENTIFIER]}|x|X|\\*`),h(`XRANGEPLAIN`,`[v=\\s]*(${c[u.XRANGEIDENTIFIER]})(?:\\.(${c[u.XRANGEIDENTIFIER]})(?:\\.(${c[u.XRANGEIDENTIFIER]})(?:${c[u.PRERELEASE]})?${c[u.BUILD]}?)?)?`),h(`XRANGEPLAINLOOSE`,`[v=\\s]*(${c[u.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[u.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[u.XRANGEIDENTIFIERLOOSE]})(?:${c[u.PRERELEASELOOSE]})?${c[u.BUILD]}?)?)?`),h(`XRANGE`,`^${c[u.GTLT]}\\s*${c[u.XRANGEPLAIN]}$`),h(`XRANGELOOSE`,`^${c[u.GTLT]}\\s*${c[u.XRANGEPLAINLOOSE]}$`),h(`COERCEPLAIN`,`(^|[^\\d])(\\d{1,${n}})(?:\\.(\\d{1,${n}}))?(?:\\.(\\d{1,${n}}))?`),h(`COERCE`,`${c[u.COERCEPLAIN]}(?:$|[^\\d])`),h(`COERCEFULL`,c[u.COERCEPLAIN]+`(?:${c[u.PRERELEASE]})?(?:${c[u.BUILD]})?(?:$|[^\\d])`),h(`COERCERTL`,c[u.COERCE],!0),h(`COERCERTLFULL`,c[u.COERCEFULL],!0),h(`LONETILDE`,`(?:~>?)`),h(`TILDETRIM`,`(\\s*)${c[u.LONETILDE]}\\s+`,!0),e.tildeTrimReplace=`$1~`,h(`TILDE`,`^${c[u.LONETILDE]}${c[u.XRANGEPLAIN]}$`),h(`TILDELOOSE`,`^${c[u.LONETILDE]}${c[u.XRANGEPLAINLOOSE]}$`),h(`LONECARET`,`(?:\\^)`),h(`CARETTRIM`,`(\\s*)${c[u.LONECARET]}\\s+`,!0),e.caretTrimReplace=`$1^`,h(`CARET`,`^${c[u.LONECARET]}${c[u.XRANGEPLAIN]}$`),h(`CARETLOOSE`,`^${c[u.LONECARET]}${c[u.XRANGEPLAINLOOSE]}$`),h(`COMPARATORLOOSE`,`^${c[u.GTLT]}\\s*(${c[u.LOOSEPLAIN]})$|^$`),h(`COMPARATOR`,`^${c[u.GTLT]}\\s*(${c[u.FULLPLAIN]})$|^$`),h(`COMPARATORTRIM`,`(\\s*)${c[u.GTLT]}\\s*(${c[u.LOOSEPLAIN]}|${c[u.XRANGEPLAIN]})`,!0),e.comparatorTrimReplace=`$1$2$3`,h(`HYPHENRANGE`,`^\\s*(${c[u.XRANGEPLAIN]})\\s+-\\s+(${c[u.XRANGEPLAIN]})\\s*$`),h(`HYPHENRANGELOOSE`,`^\\s*(${c[u.XRANGEPLAINLOOSE]})\\s+-\\s+(${c[u.XRANGEPLAINLOOSE]})\\s*$`),h(`STAR`,`(<|>)?=?\\s*\\*`),h(`GTE0`,`^\\s*>=\\s*0\\.0\\.0\\s*$`),h(`GTE0PRE`,`^\\s*>=\\s*0\\.0\\.0-0\\s*$`)})),M=t(((e,t)=>{var n=Object.freeze({loose:!0}),r=Object.freeze({});t.exports=e=>e?typeof e==`object`?e:n:r})),N=t(((e,t)=>{var n=/^[0-9]+$/,r=(e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e===t?0:e<t?-1:1;let r=n.test(e),i=n.test(t);return r&&i&&(e=+e,t=+t),e===t?0:r&&!i?-1:i&&!r?1:e<t?-1:1};t.exports={compareIdentifiers:r,rcompareIdentifiers:(e,t)=>r(t,e)}})),P=t(((e,t)=>{var n=k(),{MAX_LENGTH:r,MAX_SAFE_INTEGER:i}=A(),{safeRe:a,t:o}=j(),s=M(),{compareIdentifiers:c}=N(),l=(e,t)=>{let n=t.split(`.`);if(n.length>e.length)return!1;for(let t=0;t<n.length;t++)if(c(e[t],n[t])!==0)return!1;return!0};t.exports=class e{constructor(t,c){if(c=s(c),t instanceof e){if(t.loose===!!c.loose&&t.includePrerelease===!!c.includePrerelease)return t;t=t.version}else if(typeof t!=`string`)throw TypeError(`Invalid version. Must be a string. Got type "${typeof t}".`);if(t.length>r)throw TypeError(`version is longer than ${r} characters`);n(`SemVer`,t,c),this.options=c,this.loose=!!c.loose,this.includePrerelease=!!c.includePrerelease;let l=t.trim().match(c.loose?a[o.LOOSE]:a[o.FULL]);if(!l)throw TypeError(`Invalid Version: ${t}`);if(this.raw=t,this.major=+l[1],this.minor=+l[2],this.patch=+l[3],this.major>i||this.major<0)throw TypeError(`Invalid major version`);if(this.minor>i||this.minor<0)throw TypeError(`Invalid minor version`);if(this.patch>i||this.patch<0)throw TypeError(`Invalid patch version`);this.prerelease=l[4]?l[4].split(`.`).map(e=>{if(/^[0-9]+$/.test(e)){let t=+e;if(t>=0&&t<i)return t}return e}):[],this.build=l[5]?l[5].split(`.`):[],this.format()}format(){return this.version=`${this.major}.${this.minor}.${this.patch}`,this.prerelease.length&&(this.version+=`-${this.prerelease.join(`.`)}`),this.version}toString(){return this.version}compare(t){if(n(`SemVer.compare`,this.version,this.options,t),!(t instanceof e)){if(typeof t==`string`&&t===this.version)return 0;t=new e(t,this.options)}return t.version===this.version?0:this.compareMain(t)||this.comparePre(t)}compareMain(t){return t instanceof e||(t=new e(t,this.options)),this.major<t.major?-1:this.major>t.major?1:this.minor<t.minor?-1:this.minor>t.minor?1:this.patch<t.patch?-1:+(this.patch>t.patch)}comparePre(t){if(t instanceof e||(t=new e(t,this.options)),this.prerelease.length&&!t.prerelease.length)return-1;if(!this.prerelease.length&&t.prerelease.length)return 1;if(!this.prerelease.length&&!t.prerelease.length)return 0;let r=0;do{let e=this.prerelease[r],i=t.prerelease[r];if(n(`prerelease compare`,r,e,i),e===void 0&&i===void 0)return 0;if(i===void 0)return 1;if(e===void 0)return-1;if(e!==i)return c(e,i)}while(++r)}compareBuild(t){t instanceof e||(t=new e(t,this.options));let r=0;do{let e=this.build[r],i=t.build[r];if(n(`build compare`,r,e,i),e===void 0&&i===void 0)return 0;if(i===void 0)return 1;if(e===void 0)return-1;if(e!==i)return c(e,i)}while(++r)}inc(e,t,n){if(e.startsWith(`pre`)){if(!t&&n===!1)throw Error(`invalid increment argument: identifier is empty`);if(t){let e=`-${t}`.match(this.options.loose?a[o.PRERELEASELOOSE]:a[o.PRERELEASE]);if(!e||e[1]!==t)throw Error(`invalid identifier: ${t}`)}}switch(e){case`premajor`:this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc(`pre`,t,n);break;case`preminor`:this.prerelease.length=0,this.patch=0,this.minor++,this.inc(`pre`,t,n);break;case`prepatch`:this.prerelease.length=0,this.inc(`patch`,t,n),this.inc(`pre`,t,n);break;case`prerelease`:this.prerelease.length===0&&this.inc(`patch`,t,n),this.inc(`pre`,t,n);break;case`release`:if(this.prerelease.length===0)throw Error(`version ${this.raw} is not a prerelease`);this.prerelease.length=0;break;case`major`:(this.minor!==0||this.patch!==0||this.prerelease.length===0)&&this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case`minor`:(this.patch!==0||this.prerelease.length===0)&&this.minor++,this.patch=0,this.prerelease=[];break;case`patch`:this.prerelease.length===0&&this.patch++,this.prerelease=[];break;case`pre`:{let e=+!!Number(n);if(this.prerelease.length===0)this.prerelease=[e];else{let r=this.prerelease.length;for(;--r>=0;)typeof this.prerelease[r]==`number`&&(this.prerelease[r]++,r=-2);if(r===-1){if(t===this.prerelease.join(`.`)&&n===!1)throw Error(`invalid increment argument: identifier already exists`);this.prerelease.push(e)}}if(t){let r=[t,e];if(n===!1&&(r=[t]),l(this.prerelease,t)){let e=this.prerelease[t.split(`.`).length];isNaN(e)&&(this.prerelease=r)}else this.prerelease=r}break}default:throw Error(`invalid increment argument: ${e}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(`.`)}`),this}}})),F=t(((e,t)=>{var n=P();t.exports=(e,t,r=!1)=>{if(e instanceof n)return e;try{return new n(e,t)}catch(e){if(!r)return null;throw e}}})),I=b(),L=d(F(),1),R=i();function z({className:e=``,...t}){return(0,R.jsx)(`button`,{type:`button`,...t,className:`pill-control ${e}`})}function B({className:e=``,...t}){return(0,R.jsx)(_,{...t,className:`pill-menu ${e}`})}var V=[{value:`time`,label:`按时间`,icon:`clock`},{value:`owner`,label:`按用户`,icon:`members`}];function H(e){e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),history.pushState(null,``,e.currentTarget.href),window.dispatchEvent(new PopStateEvent(`popstate`)))}var U=[{status:`planned`,label:`计划`},{status:`in_progress`,label:`进行中`},{status:`in_review`,label:`待验收`},{status:`completed`,label:`已完成`},{status:null,label:`未明确`}];function W({members:t,project:n,memberId:i}){let{request:a,projectId:s}=C(),l=`teammy-board-mine:${i}:${s}`,[u,d]=(0,I.useState)(()=>{try{return localStorage.getItem(l)===`true`}catch{return!1}}),f=`teammy-board-order:${i}:${s}`,[g,_]=(0,I.useState)(()=>{try{return localStorage.getItem(f)===`owner`?`owner`:`time`}catch{return`time`}}),v=V.find(e=>e.value===g),b=(0,I.useCallback)(e=>a(`tasks`,S,{signal:e}),[a]),x=y(b,3e3,e(s,`tasks`)),[w,T]=(0,I.useState)(),[E,D]=(0,I.useState)(!1),[k,A]=(0,I.useState)(Date.now);(0,I.useEffect)(()=>{let e=setInterval(()=>A(Date.now()),6e4);return()=>clearInterval(e)},[]);let j=x.data,M=O(location.href),N=j?.tasks.filter(e=>!u||e.owner===i)??[],P=new Set(t.map(e=>e.id));return(0,R.jsxs)(`div`,{className:`task-board`,children:[(0,R.jsx)(p,{title:n?.projectName.trim()?`${n.projectName.trim()}|工作看板`:`工作看板`,description:n?.description.trim()||``,children:(0,R.jsxs)(`div`,{className:`task-board-brand`,children:[(0,R.jsx)(`a`,{className:`task-board-home`,"data-testid":`home-link`,href:r(`/projects`),onClick:H,"aria-label":`项目主页`,"data-tooltip":`项目主页`,children:(0,R.jsx)(h,{})}),t.some(e=>e.id===i&&e.bound)&&(0,R.jsx)(G,{memberId:i})]})}),(0,R.jsxs)(`div`,{className:`task-board-toolbar`,role:`group`,"aria-label":`看板筛选与排序`,children:[(0,R.jsxs)(z,{"aria-pressed":u,"data-testid":`task-board-mine`,onClick:()=>{let e=!u;d(e),D(!1);try{localStorage.setItem(l,String(e))}catch{}},children:[(0,R.jsx)(c,{name:u?`enable`:`account`,size:`small`}),`只看我的`]}),(0,R.jsx)(B,{id:`task-board-sort-menu`,triggerId:`task-board-sort`,label:`任务排序:${v.label}`,routeKey:g,trigger:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(c,{name:v.icon,size:`small`}),(0,R.jsx)(`span`,{children:v.label}),(0,R.jsx)(c,{name:`chevronDown`,size:`small`})]}),children:e=>V.map(t=>(0,R.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-label":t.label,onClick:()=>{e(),_(t.value),D(!1);try{localStorage.setItem(f,t.value)}catch{}},children:[(0,R.jsx)(c,{name:t.icon,size:`small`}),(0,R.jsx)(`span`,{children:t.label}),g===t.value&&(0,R.jsx)(c,{name:`check`,size:`small`})]},t.value))})]}),(0,R.jsx)(m,{error:!0,children:x.error}),(0,R.jsx)(`section`,{className:`task-board-lanes`,"aria-label":`任务进度`,"data-testid":`progress-board`,children:U.filter(e=>e.status!==null||N.some(e=>e.status===null)).map(e=>{let t=N.filter(t=>t.status===e.status);t.sort((t,n)=>(g===`owner`?t.owner.localeCompare(n.owner,`en`,{numeric:!0}):0)||(e.status===`completed`?n.statusSince.localeCompare(t.statusSince):t.statusSince.localeCompare(n.statusSince))||t.id.localeCompare(n.id));let n=e.status===`completed`&&!E?t.slice(0,5):t;return(0,R.jsxs)(`section`,{className:`task-lane`,"aria-label":e.label,"data-stage":e.status??`unknown`,children:[(0,R.jsxs)(`h2`,{children:[(0,R.jsx)(`span`,{className:`lane-dot`}),e.label,(0,R.jsx)(o,{children:j?t.length:`—`})]}),(0,R.jsxs)(`div`,{className:`task-lane-content`,children:[t.length?n.map(e=>(0,R.jsx)(K,{task:e,number:j?.taskNumbers[e.id],memberIds:P,now:k,onEdit:()=>T(e),onSaved:()=>void x.reload()},e.id)):(0,R.jsx)(`p`,{className:`task-lane-empty`,children:x.error&&!j?`读取失败`:j?`暂无任务`:`读取中…`}),e.status===`completed`&&t.length>5&&(0,R.jsxs)(`button`,{type:`button`,className:`task-lane-expand`,"aria-expanded":E,onClick:()=>D(!E),children:[(0,R.jsx)(c,{name:E?`chevronUp`:`chevronDown`,size:`small`}),E?`收起`:`展开其余 ${t.length-5} 项`]})]})]},e.label)})}),M&&(0,R.jsx)(J,{project:s,id:M.id,memberIds:P,onClose:()=>{let e=new URL(location.href);e.searchParams.delete(`task`),history.replaceState(history.state,``,e),window.dispatchEvent(new PopStateEvent(`popstate`))}}),w&&(0,R.jsx)(Z,{task:w,onClose:()=>T(void 0),onSaved:()=>{T(void 0),x.reload()}},w.id)]})}function G({memberId:e}){let{api:t,projectId:r}=C(),i=y(t.devices,!0),a=x();if(!i.data||!a.data||i.error||a.error)return null;let o=(0,L.default)(a.data.version),[s]=i.data.devices.filter(t=>t.memberId===e&&t.bound).map(e=>(0,L.default)(e.status?.clientVersion)).filter(e=>e!==null).sort((e,t)=>e.compare(t));if(!s||!o||s.compare(o)>=0)return null;let l=a.data.versions.filter(e=>{let t=(0,L.default)(e);return t&&(!t.prerelease.length||e===o.raw)&&t.compare(s)>0&&t.compare(o)<=0}).length;return(0,R.jsx)(`p`,{className:`task-board-update${l>5?` overdue`:``}`,children:(0,R.jsxs)(`a`,{href:n(r,`settings/client-maintenance.md`,`#升级与修复`),onClick:H,children:[(0,R.jsx)(c,{name:`attention`,size:`small`}),(0,R.jsxs)(`span`,{children:[`客户端待更新 `,s.raw,` → `,o.raw,l>10&&`,您完全不更新是吗:(`]})]})})}function K({task:e,number:t,memberIds:n,onEdit:r,onSaved:i,now:a}){let{request:o}=C(),l=s(),[d,p]=(0,I.useState)(!1),[h,g]=(0,I.useState)(``);async function _(){if(!d){p(!0),g(``);try{await o(`tasks/${e.id}/correction`,w,{method:`PATCH`,signal:l,body:{needsConfirmation:!1,expectedRevision:e.revision}}),l.aborted||i()}catch(e){l.aborted||g(u(e))}finally{p(!1)}}}return(0,R.jsxs)(`details`,{className:`task-card`,"data-testid":`task-card`,"data-task-id":e.id,"data-owner":e.owner,"data-status":e.status??`unknown`,children:[(0,R.jsxs)(`summary`,{className:`task-card-heading`,"data-testid":`task-toggle`,children:[(0,R.jsxs)(`h3`,{children:[t!==void 0&&(0,R.jsxs)(`span`,{className:`task-card-number`,children:[`#`,t]}),(0,R.jsx)(`span`,{className:`task-card-title`,children:e.title})]}),(0,R.jsxs)(`span`,{className:`task-card-meta`,children:[(0,R.jsx)(`small`,{title:e.owner,children:e.owner}),e.needsConfirmation&&(0,R.jsxs)(`span`,{className:`task-confirmation`,"data-testid":`task-confirmation`,children:[(0,R.jsx)(c,{name:`attention`,size:`small`}),`需要确认`]}),e.status!==`completed`&&(0,R.jsx)(Y,{since:e.statusSince,now:a})]})]}),(0,R.jsx)(f,{icon:`edit`,className:`task-card-edit`,label:`纠正任务:${e.title}`,"data-testid":`task-correct`,disabled:d,onClick:r}),(0,R.jsxs)(`div`,{className:`task-card-details`,children:[(0,R.jsx)(q,{task:e,memberIds:n}),e.needsConfirmation&&(0,R.jsxs)(`div`,{className:`task-card-confirm`,children:[(0,R.jsx)(m,{error:!0,children:h}),(0,R.jsx)(`button`,{className:`primary`,"data-testid":`task-confirm-save`,disabled:d,onClick:()=>void _(),children:d?`正在保存…`:`保存`})]})]})]})}function q({task:e,memberIds:t}){let{projectId:n}=C(),[i,o]=(0,I.useState)(``);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`h4`,{children:`目标`}),(0,R.jsx)(`p`,{children:e.goal?(0,R.jsx)(X,{value:e.goal,memberIds:t}):`目标未明确`}),(0,R.jsx)(`h4`,{children:`当前进展`}),(0,R.jsx)(`p`,{className:`task-progress`,children:(0,R.jsx)(X,{value:e.progress,memberIds:t})}),(0,R.jsx)(`div`,{className:`task-card-sources`,children:e.sources.map(t=>(0,R.jsxs)(`a`,{"data-testid":`task-source`,href:r(t.kind===`material`?`/projects/${n}/materials?id=${t.materialId}&revision=${t.revision}`:D(n,e.owner,t.path)),children:[(0,R.jsx)(c,{name:`file`,size:`small`}),(0,R.jsx)(`span`,{children:t.path})]},t.path))}),(0,R.jsxs)(`div`,{className:`task-card-footer`,children:[e.syncedAt&&(0,R.jsxs)(`small`,{children:[`资料同步于 `,(0,R.jsx)(a,{value:e.syncedAt})]}),(0,R.jsx)(`span`,{role:`status`,children:i}),(0,R.jsx)(f,{icon:`link`,label:`复制任务链接`,onBlur:()=>o(``),onClick:async()=>{try{await v(new URL(r(E(n,e.id)),location.origin).href),o(`已复制`)}catch{o(`复制失败`)}}})]})]})}function J({project:e,id:t,memberIds:n,onClose:r}){let{data:i,error:a}=T(e,t,!0);return(0,R.jsxs)(l,{id:`shared-task`,title:i?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`span`,{className:`task-card-number`,children:[`#`,i.number]}),` `,i.task.title]}):`任务`,onClose:r,children:[(0,R.jsx)(m,{error:!0,children:a}),i?(0,R.jsxs)(`div`,{className:`task-card-details`,children:[(0,R.jsxs)(`small`,{children:[i.task.owner,` · `,U.find(e=>e.status===i.task.status)?.label,!i.active&&` · 已归档`]}),(0,R.jsx)(q,{task:i.task,memberIds:n},t)]}):!a&&(0,R.jsx)(`p`,{role:`status`,children:`读取中…`})]})}function Y({since:e,now:t}){let n=Math.max(0,t-Date.parse(e)),r=Math.floor(n/6e4),i=r<1?`刚刚`:r<60?`${r} 分钟`:r<1440?`${Math.floor(r/60)} 小时`:`${Math.floor(r/1440)} 天`;return(0,R.jsxs)(`span`,{className:`task-age${n>6048e5?` stale`:``}`,"data-testid":`task-age`,title:`进入当前状态:${new Date(e).toLocaleString(`zh-CN`)}`,"aria-label":`当前状态停留 ${i}`,children:[(0,R.jsx)(c,{name:`clock`,size:`small`}),i]})}function X({value:e,memberIds:t}){return e.split(/(@[a-z][a-z0-9_-]*)/gi).map((e,n)=>e.startsWith(`@`)&&t.has(e.slice(1))?(0,R.jsx)(`mark`,{className:`task-mention`,children:e},n):e)}function Z({task:e,onClose:t,onSaved:n}){let{request:r}=C(),i=s(),[a,o]=(0,I.useState)(e.title),[c,d]=(0,I.useState)(e.status??``),[f,p]=(0,I.useState)(e.goal??``),[h,_]=(0,I.useState)(e.progress),[v,y]=(0,I.useState)(!1),[b,x]=(0,I.useState)(``),S={...a===e.title?{}:{title:a},...c===(e.status??``)?{}:{status:c||null},...f===(e.goal??``)?{}:{goal:f||null},...h===e.progress?{}:{progress:h},...e.needsConfirmation?{needsConfirmation:!1}:{}};async function T(){if(!v&&Object.keys(S).length){y(!0),x(``);try{await r(`tasks/${e.id}/correction`,w,{method:`PATCH`,signal:i,body:{...S,expectedRevision:e.revision}}),i.aborted||n()}catch(e){i.aborted||x(u(e))}finally{y(!1)}}}return(0,R.jsx)(l,{id:`task-correction`,title:`纠正任务`,onClose:t,children:(0,R.jsxs)(`form`,{className:`stack`,"aria-busy":v,onSubmit:e=>{e.preventDefault(),T()},children:[(0,R.jsx)(g,{id:`task-title`,label:`标题`,children:(0,R.jsx)(`input`,{value:a,required:!0,onChange:e=>o(e.target.value)})}),(0,R.jsxs)(`fieldset`,{className:`task-status-field`,disabled:v,children:[(0,R.jsx)(`legend`,{children:`状态`}),(0,R.jsx)(`div`,{className:`task-status-options`,"data-testid":`task-status`,children:U.filter(e=>e.status!==null).map(e=>(0,R.jsxs)(`label`,{className:`task-status-choice`,children:[(0,R.jsx)(`input`,{type:`radio`,name:`task-status`,value:e.status,checked:c===e.status,onChange:()=>d(e.status)}),(0,R.jsx)(`span`,{children:e.label})]},e.status))}),(0,R.jsx)(`small`,{children:`待验收:任务成果已提交,等待验收或最终确认。`})]}),(0,R.jsx)(g,{id:`task-goal`,label:`目标`,children:(0,R.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value)})}),(0,R.jsx)(g,{id:`task-progress`,label:`当前进展`,children:(0,R.jsx)(`textarea`,{value:h,onChange:e=>_(e.target.value)})}),(0,R.jsx)(m,{error:!0,children:b}),(0,R.jsx)(`div`,{className:`row wrap`,children:(0,R.jsx)(`button`,{type:`submit`,className:`primary`,disabled:v||!Object.keys(S).length,"data-testid":`task-correction-save`,children:`保存`})})]})})}function Q({members:e,config:t,memberId:n}){return(0,R.jsx)(W,{members:e,project:t,memberId:n})}export{Q as Dashboard};
@@ -1 +1 @@
1
- .task-board{min-width:0}.task-board .page-header{grid-template-columns:minmax(0,1fr) fit-content(50%);align-items:start;display:grid}.task-board .page-header p{overflow-wrap:anywhere}.task-board-brand{flex-direction:column;align-items:flex-end;display:flex}.task-board-update a{align-items:center;gap:var(--space-1);color:inherit;text-decoration:none;display:flex}.task-board-update a:hover{color:var(--color-text)}.task-board-update.overdue a{color:var(--brand-orange)}@media (width<=680px){.task-board .page-header{row-gap:0}.task-board-brand{display:contents}.task-board-update{grid-column:1/-1;justify-self:end}}.task-board-home{height:calc(var(--text-title) * 1.35);border-radius:var(--radius-sm);align-items:center;display:flex}.task-board-home:hover{opacity:.75}.task-board-home .brand img{width:auto;height:calc(var(--text-title) * 1.04)}.task-board-toolbar{flex-wrap:wrap;align-items:center;gap:8px;margin-bottom:24px;display:flex}.task-board-lanes{grid-template-columns:repeat(auto-fit,minmax(min(100%,240px),1fr));align-items:start;gap:24px;margin-bottom:32px;display:grid}.task-lane{min-width:0}.task-lane h2{font-size:var(--text-base);border-bottom:1px solid var(--color-line);align-items:center;gap:10px;padding:0 0 16px;font-weight:600;display:flex}.task-lane .count{margin-left:auto}.task-lane-content{flex-direction:column;gap:12px;padding-top:16px;display:flex}.lane-dot{border:1.5px solid var(--color-muted);border-radius:50%;width:8px;height:8px}.task-lane[data-stage=in_progress] .lane-dot{border-color:var(--brand-orange);background:var(--brand-orange)}.task-lane[data-stage=in_review] .lane-dot{border-color:var(--brand-black);background:var(--brand-black)}.task-lane[data-stage=completed] .lane-dot{border-color:var(--color-muted);background:var(--color-muted)}.task-lane-empty{font-size:var(--text-xs);color:var(--color-muted);padding:44px 0}.task-card{border:1px solid var(--color-line);border-radius:var(--radius-md);background:var(--color-surface);overflow-wrap:anywhere;min-width:0;position:relative}.task-card>.task-card-heading{border-radius:inherit;padding:16px;list-style:none;position:static}.task-age{white-space:nowrap;color:var(--color-muted);font-size:var(--text-xs);flex-shrink:0;align-items:center;gap:4px;margin-left:auto;font-weight:400;display:inline-flex}.task-age .icon{width:13px;height:13px}.task-age.stale{color:var(--brand-orange)}.task-lane-expand{min-height:32px;color:var(--color-muted);font-size:var(--text-xs);background:0 0;border:0;justify-content:center;align-items:center;gap:6px;display:flex}.task-card-heading::-webkit-details-marker{display:none}.task-card-heading:hover{background:var(--color-soft)}.task-card[open]>.task-card-heading h3{padding-right:32px}.task-card-meta{align-items:center;gap:8px;margin-top:8px;display:flex}.task-card-meta>small{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.task-confirmation{border-radius:var(--radius-sm);background:var(--color-accent-soft);color:var(--brand-orange);font-size:calc(var(--text-xs) - 1px);flex-shrink:0;align-items:center;gap:3px;padding:0 4px;font-weight:400;line-height:18px;display:inline-flex}.task-confirmation .icon{width:12px;height:12px}.task-card-confirm{flex-direction:column;align-items:flex-end;gap:8px;margin-top:16px;display:flex}.task-card-confirm button{min-height:32px;font-size:var(--text-xs);padding:4px 12px}.task-status-field legend{font-size:var(--text-sm);margin-bottom:8px;font-weight:600}.task-status-options{grid-template-columns:repeat(4,minmax(0,1fr));gap:8px;display:grid}.task-status-choice{cursor:pointer;position:relative}.task-status-choice input{opacity:0;width:100%;height:100%;min-height:0;cursor:inherit;position:absolute;inset:0}.task-status-choice span{border:1px solid var(--color-line);border-radius:var(--radius-md);background:var(--color-surface);min-height:36px;font-size:var(--text-sm);justify-content:center;align-items:center;font-weight:550;display:flex}.task-status-choice:hover span{background:var(--color-soft)}.task-status-choice input:checked+span{border-color:var(--brand-black);background:var(--brand-black);color:var(--color-on-dark)}.task-status-choice input:focus-visible+span{border-color:var(--color-input-focus)}.task-status-choice input:disabled+span{opacity:.45;cursor:default}.task-card-heading h3{font-size:var(--text-base);font-weight:650;line-height:1.55}.task-card-edit{opacity:0;pointer-events:none;position:absolute;top:10px;right:8px}.task-card[open]:hover>.task-card-edit{opacity:1;pointer-events:auto}.task-card[open]:has(:focus-visible)>.task-card-edit{opacity:1;pointer-events:auto}.task-progress{font-size:var(--text-sm);white-space:pre-wrap;line-height:1.85}.task-card small{color:var(--color-muted);font-size:var(--text-xs)}.task-card-details{padding:0 16px 16px}.task-card-details h4{font-size:var(--text-xs);margin:16px 0 4px;font-weight:600}.task-card-details p{font-size:var(--text-sm);margin:0}.task-card-sources{flex-direction:column;align-items:flex-start;gap:8px;margin:16px 0;display:flex}.task-card-sources a{text-align:left;overflow-wrap:anywhere;max-width:100%;font-size:var(--text-xs);min-height:28px;color:var(--color-muted);justify-content:flex-start;gap:8px;padding:4px 0;text-decoration:none;display:inline-flex}.task-card-sources a:hover{color:var(--color-link);text-decoration:underline}.task-mention{border-radius:var(--radius-sm);background:var(--color-accent-soft);color:inherit;padding:0 2px}button.pill-control,.pill-menu .dropdown-trigger{background:var(--color-soft);min-height:30px;color:var(--color-muted);font-size:var(--text-xs);white-space:nowrap;border:1px solid #0000;border-radius:999px;justify-content:center;align-items:center;gap:6px;padding:5px 11px;font-weight:500;line-height:18px;display:inline-flex}button.pill-control:hover,button.pill-control[aria-pressed=true],.pill-menu .dropdown-trigger:hover,.pill-menu .dropdown-trigger[aria-expanded=true]{background:var(--color-hover);color:var(--color-text)}button.pill-control[aria-pressed=true]{border-color:var(--color-line)}.pill-radio-group{flex-wrap:wrap;gap:6px;display:flex}.pill-radio-group .pill-control{padding:5px 8px}button.pill-control[aria-checked=true]{background:var(--color-accent-soft);color:var(--color-text);border-color:var(--color-danger-line)}button.pill-control[role=radio]:focus-visible{border-color:var(--color-input-focus);outline:none}.pill-radio-group .agent-logo{width:17px;height:17px;padding:0}.pill-control>.icon,.pill-menu .dropdown-trigger>.icon{flex-shrink:0;width:14px;height:14px}.pill-menu .dropdown-menu{border-radius:var(--radius-md);width:168px;padding:5px;top:calc(100% + 6px)}.pill-menu .dropdown-menu [role=menuitem]{min-height:32px;font-size:var(--text-xs);gap:8px;padding:8px;font-weight:500}
1
+ .task-board{min-width:0}.task-board .page-header{grid-template-columns:minmax(0,1fr) fit-content(50%);align-items:start;display:grid}.task-board .page-header p{overflow-wrap:anywhere}.task-board-brand{flex-direction:column;align-items:flex-end;display:flex}.task-board-update a{align-items:center;gap:var(--space-1);color:inherit;text-decoration:none;display:flex}.task-board-update a:hover{color:var(--color-text)}.task-board-update.overdue a{color:var(--brand-orange)}@media (width<=680px){.task-board .page-header{row-gap:0}.task-board-brand{display:contents}.task-board-update{grid-column:1/-1;justify-self:end}}.task-board-home{height:calc(var(--text-title) * 1.35);border-radius:var(--radius-sm);align-items:center;display:flex}.task-board-home:hover{opacity:.75}.task-board-home .brand img{width:auto;height:calc(var(--text-title) * 1.04)}.task-board-toolbar{flex-wrap:wrap;align-items:center;gap:8px;margin-bottom:24px;display:flex}.task-board-lanes{grid-template-columns:repeat(auto-fit,minmax(min(100%,240px),1fr));align-items:start;gap:24px;margin-bottom:32px;display:grid}.task-lane{min-width:0}.task-lane h2{font-size:var(--text-base);border-bottom:1px solid var(--color-line);align-items:center;gap:10px;padding:0 0 16px;font-weight:600;display:flex}.task-lane .count{margin-left:auto}.task-lane-content{flex-direction:column;gap:12px;padding-top:16px;display:flex}.lane-dot{border:1.5px solid var(--color-muted);border-radius:50%;width:8px;height:8px}.task-lane[data-stage=in_progress] .lane-dot{border-color:var(--brand-orange);background:var(--brand-orange)}.task-lane[data-stage=in_review] .lane-dot{border-color:var(--brand-black);background:var(--brand-black)}.task-lane[data-stage=completed] .lane-dot{border-color:var(--color-muted);background:var(--color-muted)}.task-lane-empty{font-size:var(--text-xs);color:var(--color-muted);padding:44px 0}.task-card{border:1px solid var(--color-line);border-radius:var(--radius-md);background:var(--color-surface);overflow-wrap:anywhere;min-width:0;position:relative}.task-card>.task-card-heading{border-radius:inherit;padding:16px;list-style:none;position:static}.task-age{white-space:nowrap;color:var(--color-muted);font-size:var(--text-xs);flex-shrink:0;align-items:center;gap:4px;margin-left:auto;font-weight:400;display:inline-flex}.task-age .icon{width:13px;height:13px}.task-age.stale{color:var(--brand-orange)}.task-lane-expand{min-height:32px;color:var(--color-muted);font-size:var(--text-xs);background:0 0;border:0;justify-content:center;align-items:center;gap:6px;display:flex}.task-card-heading::-webkit-details-marker{display:none}.task-card-heading:hover{background:var(--color-soft)}.task-card[open]>.task-card-heading h3{padding-right:32px}.task-card-meta{align-items:center;gap:8px;margin-top:8px;display:flex}.task-card-meta>small{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.task-confirmation{border-radius:var(--radius-sm);background:var(--color-accent-soft);color:var(--brand-orange);font-size:calc(var(--text-xs) - 1px);flex-shrink:0;align-items:center;gap:3px;padding:0 4px;font-weight:400;line-height:18px;display:inline-flex}.task-confirmation .icon{width:12px;height:12px}.task-card-confirm{flex-direction:column;align-items:flex-end;gap:8px;margin-top:16px;display:flex}.task-card-confirm button{min-height:32px;font-size:var(--text-xs);padding:4px 12px}.task-status-field legend{font-size:var(--text-sm);margin-bottom:8px;font-weight:600}.task-status-options{grid-template-columns:repeat(4,minmax(0,1fr));gap:8px;display:grid}.task-status-choice{cursor:pointer;position:relative}.task-status-choice input{opacity:0;width:100%;height:100%;min-height:0;cursor:inherit;position:absolute;inset:0}.task-status-choice span{border:1px solid var(--color-line);border-radius:var(--radius-md);background:var(--color-surface);min-height:36px;font-size:var(--text-sm);justify-content:center;align-items:center;font-weight:550;display:flex}.task-status-choice:hover span{background:var(--color-soft)}.task-status-choice input:checked+span{border-color:var(--brand-black);background:var(--brand-black);color:var(--color-on-dark)}.task-status-choice input:focus-visible+span{border-color:var(--color-input-focus)}.task-status-choice input:disabled+span{opacity:.45;cursor:default}.task-card-heading h3{font-size:var(--text-base);align-items:baseline;gap:6px;font-weight:650;line-height:1.55;display:flex}.task-card-number{color:var(--color-muted);font-size:var(--text-sm);font-variant-numeric:tabular-nums;white-space:nowrap;flex:none;font-weight:500}.task-card-title{min-width:0}.task-card-edit{opacity:0;pointer-events:none;position:absolute;top:10px;right:8px}.task-card[open]:hover>.task-card-edit{opacity:1;pointer-events:auto}.task-card[open]:has(:focus-visible)>.task-card-edit{opacity:1;pointer-events:auto}.task-progress{font-size:var(--text-sm);white-space:pre-wrap;line-height:1.85}.task-card small,.task-card-details small,.task-card-footer [role=status]{color:var(--color-muted);font-size:var(--text-xs)}.task-card-footer{align-items:center;gap:6px;display:flex}.task-card-footer [role=status]{margin-left:auto}#shared-task .task-card-details{padding:0}.task-card-details{padding:0 16px 16px}.task-card-details h4{font-size:var(--text-xs);margin:16px 0 4px;font-weight:600}.task-card-details p{font-size:var(--text-sm);margin:0}.task-card-sources{flex-direction:column;align-items:flex-start;gap:8px;margin:16px 0;display:flex}.task-card-sources a{text-align:left;overflow-wrap:anywhere;max-width:100%;font-size:var(--text-xs);min-height:28px;color:var(--color-muted);justify-content:flex-start;gap:8px;padding:4px 0;text-decoration:none;display:inline-flex}.task-card-sources a:hover{color:var(--color-link);text-decoration:underline}.task-mention{border-radius:var(--radius-sm);background:var(--color-accent-soft);color:inherit;padding:0 2px}button.pill-control,.pill-menu .dropdown-trigger{background:var(--color-soft);min-height:30px;color:var(--color-muted);font-size:var(--text-xs);white-space:nowrap;border:1px solid #0000;border-radius:999px;justify-content:center;align-items:center;gap:6px;padding:5px 11px;font-weight:500;line-height:18px;display:inline-flex}button.pill-control:hover,button.pill-control[aria-pressed=true],.pill-menu .dropdown-trigger:hover,.pill-menu .dropdown-trigger[aria-expanded=true]{background:var(--color-hover);color:var(--color-text)}button.pill-control[aria-pressed=true]{border-color:var(--color-line)}.pill-radio-group{flex-wrap:wrap;gap:6px;display:flex}.pill-radio-group .pill-control{padding:5px 8px}button.pill-control[aria-checked=true]{background:var(--color-accent-soft);color:var(--color-text);border-color:var(--color-danger-line)}button.pill-control[role=radio]:focus-visible{border-color:var(--color-input-focus);outline:none}.pill-radio-group .agent-logo{width:17px;height:17px;padding:0}.pill-control>.icon,.pill-menu .dropdown-trigger>.icon{flex-shrink:0;width:14px;height:14px}.pill-menu .dropdown-menu{border-radius:var(--radius-md);width:168px;padding:5px;top:calc(100% + 6px)}.pill-menu .dropdown-menu [role=menuitem]{min-height:32px;font-size:var(--text-xs);gap:8px;padding:8px;font-weight:500}