@teammy/server 0.2.20 → 0.2.21

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 (94) hide show
  1. package/dist/main.js +4030 -3035
  2. package/dist/web/assets/{Assistant-By7rPMl2.js → Assistant-3mdmSDTD.js} +1 -1
  3. package/dist/web/assets/Computers-6l6HpFis.js +13 -0
  4. package/dist/web/assets/{Conversation-BjRCD81A.js → Conversation-C5pZE7z5.js} +1 -1
  5. package/dist/web/assets/{Dashboard-DmtWx-WI.js → Dashboard-yaqwUqGh.js} +1 -1
  6. package/dist/web/assets/{Files-4IxSFpqk.js → Files-1vHzvDD3.js} +1 -1
  7. package/dist/web/assets/{Help-BeJ09zt7.js → Help-6fa7XqA5.js} +61 -22
  8. package/dist/web/assets/Markdown-nuwEQZ64.js +29 -0
  9. package/dist/web/assets/{ResourceLibrary-rlrdDWGo.js → ResourceLibrary-Cs01blNf.js} +1 -1
  10. package/dist/web/assets/{TerminalPane-CEaXud0k.js → TerminalPane-B0w1stXs.js} +1 -1
  11. package/dist/web/assets/{WorkspaceTree-CwGvdfr0.js → WorkspaceTree-DmSApj8i.js} +1 -1
  12. package/dist/web/assets/{index-Cr9kdjwc.js → index-Rry2cw7w.js} +2 -2
  13. package/dist/web/assets/{task-links-B7fExlHK.js → task-links-BJwIQ3SE.js} +1 -1
  14. package/dist/web/downloads/teammy-inbox-skill.zip +0 -0
  15. package/dist/web/downloads/teammy-skill.zip +0 -0
  16. package/dist/web/index.html +1 -1
  17. package/node_modules/cron-parser/LICENSE +21 -0
  18. package/node_modules/cron-parser/README.md +437 -0
  19. package/node_modules/cron-parser/dist/CronDate.js +558 -0
  20. package/node_modules/cron-parser/dist/CronExpression.js +531 -0
  21. package/node_modules/cron-parser/dist/CronExpressionParser.js +482 -0
  22. package/node_modules/cron-parser/dist/CronFieldCollection.js +380 -0
  23. package/node_modules/cron-parser/dist/CronFileParser.js +92 -0
  24. package/node_modules/cron-parser/dist/fields/CronDayOfMonth.js +60 -0
  25. package/node_modules/cron-parser/dist/fields/CronDayOfWeek.js +57 -0
  26. package/node_modules/cron-parser/dist/fields/CronField.js +222 -0
  27. package/node_modules/cron-parser/dist/fields/CronHour.js +40 -0
  28. package/node_modules/cron-parser/dist/fields/CronMinute.js +40 -0
  29. package/node_modules/cron-parser/dist/fields/CronMonth.js +44 -0
  30. package/node_modules/cron-parser/dist/fields/CronSecond.js +40 -0
  31. package/node_modules/cron-parser/dist/fields/index.js +24 -0
  32. package/node_modules/cron-parser/dist/fields/types.js +2 -0
  33. package/node_modules/cron-parser/dist/index.js +31 -0
  34. package/node_modules/cron-parser/dist/types/CronDate.d.ts +293 -0
  35. package/node_modules/cron-parser/dist/types/CronExpression.d.ts +118 -0
  36. package/node_modules/cron-parser/dist/types/CronExpressionParser.d.ts +65 -0
  37. package/node_modules/cron-parser/dist/types/CronFieldCollection.d.ts +153 -0
  38. package/node_modules/cron-parser/dist/types/CronFileParser.d.ts +30 -0
  39. package/node_modules/cron-parser/dist/types/fields/CronDayOfMonth.d.ts +33 -0
  40. package/node_modules/cron-parser/dist/types/fields/CronDayOfWeek.d.ts +31 -0
  41. package/node_modules/cron-parser/dist/types/fields/CronField.d.ts +136 -0
  42. package/node_modules/cron-parser/dist/types/fields/CronHour.d.ts +23 -0
  43. package/node_modules/cron-parser/dist/types/fields/CronMinute.d.ts +23 -0
  44. package/node_modules/cron-parser/dist/types/fields/CronMonth.d.ts +24 -0
  45. package/node_modules/cron-parser/dist/types/fields/CronSecond.d.ts +23 -0
  46. package/node_modules/cron-parser/dist/types/fields/index.d.ts +8 -0
  47. package/node_modules/cron-parser/dist/types/fields/types.d.ts +18 -0
  48. package/node_modules/cron-parser/dist/types/index.d.ts +8 -0
  49. package/node_modules/cron-parser/dist/types/utils/random.d.ts +10 -0
  50. package/node_modules/cron-parser/dist/utils/random.js +38 -0
  51. package/node_modules/cron-parser/package.json +117 -0
  52. package/node_modules/luxon/LICENSE.md +7 -0
  53. package/node_modules/luxon/README.md +55 -0
  54. package/node_modules/luxon/build/amd/luxon.js +8741 -0
  55. package/node_modules/luxon/build/amd/luxon.js.map +1 -0
  56. package/node_modules/luxon/build/cjs-browser/luxon.js +8739 -0
  57. package/node_modules/luxon/build/cjs-browser/luxon.js.map +1 -0
  58. package/node_modules/luxon/build/es6/luxon.mjs +8133 -0
  59. package/node_modules/luxon/build/es6/luxon.mjs.map +1 -0
  60. package/node_modules/luxon/build/global/luxon.js +8744 -0
  61. package/node_modules/luxon/build/global/luxon.js.map +1 -0
  62. package/node_modules/luxon/build/global/luxon.min.js +1 -0
  63. package/node_modules/luxon/build/global/luxon.min.js.map +1 -0
  64. package/node_modules/luxon/build/node/luxon.js +7792 -0
  65. package/node_modules/luxon/build/node/luxon.js.map +1 -0
  66. package/node_modules/luxon/package.json +87 -0
  67. package/node_modules/luxon/src/datetime.js +2603 -0
  68. package/node_modules/luxon/src/duration.js +1009 -0
  69. package/node_modules/luxon/src/errors.js +61 -0
  70. package/node_modules/luxon/src/impl/conversions.js +206 -0
  71. package/node_modules/luxon/src/impl/diff.js +95 -0
  72. package/node_modules/luxon/src/impl/digits.js +94 -0
  73. package/node_modules/luxon/src/impl/english.js +233 -0
  74. package/node_modules/luxon/src/impl/formats.js +176 -0
  75. package/node_modules/luxon/src/impl/formatter.js +434 -0
  76. package/node_modules/luxon/src/impl/invalid.js +14 -0
  77. package/node_modules/luxon/src/impl/locale.js +569 -0
  78. package/node_modules/luxon/src/impl/regexParser.js +335 -0
  79. package/node_modules/luxon/src/impl/tokenParser.js +505 -0
  80. package/node_modules/luxon/src/impl/util.js +330 -0
  81. package/node_modules/luxon/src/impl/zoneUtil.js +34 -0
  82. package/node_modules/luxon/src/info.js +205 -0
  83. package/node_modules/luxon/src/interval.js +669 -0
  84. package/node_modules/luxon/src/luxon.js +26 -0
  85. package/node_modules/luxon/src/package.json +4 -0
  86. package/node_modules/luxon/src/settings.js +180 -0
  87. package/node_modules/luxon/src/zone.js +97 -0
  88. package/node_modules/luxon/src/zones/IANAZone.js +235 -0
  89. package/node_modules/luxon/src/zones/fixedOffsetZone.js +150 -0
  90. package/node_modules/luxon/src/zones/invalidZone.js +53 -0
  91. package/node_modules/luxon/src/zones/systemZone.js +61 -0
  92. package/package.json +3 -1
  93. package/dist/web/assets/Computers-B4ZMJ8tu.js +0 -13
  94. package/dist/web/assets/Markdown-DGF8VSqv.js +0 -29
@@ -1 +1 @@
1
- import{A as e,At as t,C as n,D as r,F as i,I as a,M as ee,St as o,_t as s,b as c,c as l,d as te,j as u,k as d,kt as f,l as p,mt as m,pt as h,u as ne,v as re,vt as g,wt as ie,x as ae,yt as _}from"./Dropdown-DXEtBxVr.js";import{A as oe,B as se,D as v,E as ce,L as y,M as le,O as ue,P as de,i as fe,j as b,k as pe}from"./index-Cr9kdjwc.js";import{t as me}from"./Markdown-DGF8VSqv.js";import{i as he,n as ge,r as _e,t as ve}from"./Conversation-BjRCD81A.js";import{t as ye}from"./MessageComposer-0eprbRl2.js";var x=f(),S=u(),be=_({topics:h(_({id:o(),title:o(),summary:o(),author:o(),replies:g(),unread:m(),createdAt:o(),updatedAt:o(),delivery:_({available:m(),connected:m(),state:o(),error:o().nullable()})}))}),xe=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),C=e=>e.replace(/[#*_`>]/g,``).replace(/\s+/g,` `).trim();function w({me:u,mode:f=`messages`}){let{projectId:h,request:g}=se(),w=e(),Ce=d(h,u,`${f}-selection`),T=d(h,u,`${f}-drafts`),we=(0,x.useCallback)(e=>g(`agents/outbox`,oe,{signal:e}),[g]),E=r(we,3e3,d(h,u,`outbox`)),Te=(0,x.useCallback)(async e=>f===`messages`?g(`agents/chats`,ce,{signal:e}):{chats:(await g(`channels/topics`,be,{signal:e})).topics.map(e=>({...e,kind:`matter`,state:null}))},[g,f]),D=r(Te,3e3,d(h,u,f,`chats`)),[O,Ee]=(0,x.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`chat`);return t?`chat:${t}`:e.get(`message`)??w?.get(Ce)??``}),k=O.startsWith(`chat:`)?O.slice(5):``,A=!O||!!k,[j,M]=(0,x.useState)(()=>w?.get(d(h,u,`chat`,k))),N=j?.id===k?j:w?.get(d(h,u,`chat`,k)),P=D.data?.chats.find(e=>e.id===k),F=P&&`delivery`in P?P.delivery:void 0,[De,I]=(0,x.useState)(),[L,R]=(0,x.useState)(()=>w?.get(T)??{}),Oe=L[O]??``,ke=e=>R(t=>({...t,[O]:e})),[z,B]=(0,x.useState)(!1),[V,Ae]=(0,x.useState)(!1),[je,Me]=(0,x.useState)(!1),[Ne,H]=(0,x.useState)(!1),[U,Pe]=(0,x.useState)(``),[Fe,Ie]=(0,x.useState)(``),Le=(0,x.useRef)(a()),W=n(),[Re,G]=(0,x.useState)(``),K=(0,x.useRef)(new Map),ze=(0,x.useRef)(null),q=(0,x.useRef)(!0),J=(0,x.useRef)(O);J.current=O,(0,x.useEffect)(()=>{j&&w?.set(d(h,u,`chat`,j.id),j)},[w,h,u,j]),(0,x.useEffect)(()=>{w?.set(T,L)},[w,T,L]);function Y(e){J.current=e,Ee(e),w?.set(Ce,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=>f===`messages`&&e.box===`debug`).reverse(),Z=E.data?.messages.find(e=>e.id===(O===`debug`?De: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`&&g(`agents/outbox/${Z.id}/read`,b,{method:`POST`}).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>W(i(e)))},[Z?.id,Z?.readAt,O,g,E.reload]),(0,x.useEffect)(()=>{O===`debug`&&Q&&Promise.all(Q.split(`,`).map(e=>g(`agents/outbox/${e}/read`,b,{method:`POST`}))).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>W(i(e)))},[O,Q,g,E.reload]),(0,x.useEffect)(()=>{if(G(``),!k)return;let e=!0,n=-1,r=!1,a=new AbortController,s=i=>{!e||i.id!==k||i.cursor<n||(n=i.cursor,r=!0,i.redirect?Y(`chat:${i.redirect}`):i.entry===`channel`&&f!==`channels`?location.replace(t(`/projects/${h}/channels?chat=${i.id}`)):(M(i),G(``)))};g(`agents/chats/${k}`,v,{signal:a.signal}).then(s).catch(t=>{e&&!a.signal.aborted&&(t instanceof ee&&[401,403,404].includes(t.status)&&(w?.delete(d(h,u,`chat`,k)),M(e=>e?.id===k?void 0:e)),r||G(i(t)))});let c=t=>{let r=Number(t.lastEventId);return!e||!Number.isSafeInteger(r)||r<=n?!1:(n=r,!0)},l=new EventSource(t(`/api/v1/projects/${encodeURIComponent(h)}/agents/chats/${encodeURIComponent(k)}/events`));l.addEventListener(`snapshot`,t=>{if(e)try{s(v.parse(JSON.parse(t.data)))}catch(e){G(i(e))}}),l.onerror=()=>{e&&G(`对话连接中断,正在重新连接…`)},l.addEventListener(`context`,e=>{if(!c(e))return;let t=v.pick({kind:!0,title:!0,status:!0,visibility:!0,participants:!0,pending:!0,hold:!0,redirect:!0}).parse(JSON.parse(e.data));t.redirect?Y(`chat:${t.redirect}`):M(e=>e?.id===k?{...e,...t,cursor:n}:e)}),l.addEventListener(`message`,e=>{if(!c(e))return;let t=ue.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)}),l.addEventListener(`message_removed`,e=>{if(!c(e))return;let{id:t}=_({id:o()}).parse(JSON.parse(e.data));M(e=>e?.id===k?{...e,cursor:n,messages:e.messages.filter(e=>e.id!==t)}:e)}),l.addEventListener(`run`,e=>{if(!c(e))return;let t=pe.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`])l.addEventListener(e,t=>{if(!c(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,a.abort(),l.close()}},[h,k,u,g,w]),(0,x.useEffect)(()=>{if(!N||N.id!==k)return;let e=()=>{document.visibilityState===`visible`&&g(`agents/chats/${k}/read`,_({ok:m()}),{method:`POST`,body:{cursor:N.readCursor}}).then(()=>{D.reload(),window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>W(i(e)))},t=setTimeout(e,300);return document.addEventListener(`visibilitychange`,e),()=>{clearTimeout(t),document.removeEventListener(`visibilitychange`,e)}},[k,N?.readCursor,N?.kind,g]),(0,x.useEffect)(()=>{q.current&&ze.current?.scrollIntoView({block:`end`})},[O,j?.messages,Z?.recipients,X.length]);function Be(){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 g(`agents/outbox/${e}/read`,b,{method:`POST`}),Be()}catch(e){W(i(e))}}async function Ve(){if(!V){Ae(!0),W(``);try{let e=await g(`agents/chats`,v,{method:`POST`});M(e),await $(`chat:${e.id}`),D.reload()}catch(e){W(i(e))}finally{Ae(!1)}}}async function He(e){e.preventDefault();let t=Oe.trim();if(!t||z||V)return;B(!0),W(``);let n=K.current.get(O);n&&n.text===t||(n={text:t,id:a()},K.current.set(O,n));try{if(A){let e=n.target??k;if(!e){let r=await g(`agents/chats`,v,{method:`POST`});e=r.id,n.target=e,K.current.set(`chat:${e}`,n),R(n=>({...n,[`chat:${e}`]:t})),J.current===O&&(M(r),Y(`chat:${e}`))}let r=await g(`agents/chats/${e}`,pe.extend({conversationId:o().optional()}),{method:`POST`,body:{text:t,requestId:n.id}});r.conversationId&&r.conversationId!==e&&(J.current===O||J.current===`chat:${e}`)&&Y(`chat:${r.conversationId}`),M(t=>t?.id===e?{...t,runs:t.runs.some(e=>e.id===r.id)?t.runs:[...t.runs,r]}:t),D.reload()}else{let e=await g(`agents/outbox/${Z.id}/reply`,_({conversationId:o()}),{method:`POST`,body:{body:t,requestId:n.id}});Be(),J.current===O&&Y(`chat:${e.conversationId}`),D.reload(),I(void 0)}K.current.delete(O),n.target&&K.current.delete(`chat:${n.target}`),R(e=>({...e,[O]:``,...n.target?{[`chat:${n.target}`]:``}:{}}))}catch(e){W(i(e))}finally{B(!1)}}let Ue=f===`channels`?_e:ve,We=A&&!N?.closed&&(f!==`channels`||!!k)||!!Z&&!Z.archivedAt,Ge=A&&!N&&(!!k||!D.data);return(0,S.jsxs)(ge,{className:f===`channels`?`channel-layout`:``,testId:`assistant-page`,label:A?`Tim对话`:`消息内容`,navigation:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(de,{title:f===`channels`?`频道`:`对话`,children:(0,S.jsxs)(`div`,{className:`assistant-list-actions`,children:[(0,S.jsx)(p,{className:`assistant-new-chat`,icon:`clear`,label:`清除未读`,disabled:je,onClick:()=>{Me(!0),W(``),g(`communication/read`,_({ok:s(!0)}),{method:`POST`,body:{scope:f}}).then(async()=>{window.dispatchEvent(new Event(`teammy:outbox`)),await Promise.all([D.reload(),E.reload()])}).catch(e=>W(i(e))).finally(()=>Me(!1))}}),(0,S.jsx)(p,{className:`assistant-new-chat`,icon:`plus`,label:f===`channels`?`发表话题`:`新建对话`,disabled:V,onClick:()=>f===`channels`?H(!0):void Ve(),"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)(y,{selected:k===e.id,children:(0,S.jsx)(`strong`,{children:e.title})}),f===`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`}),` `,xe(e.updatedAt)]})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${e.unread||f!==`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)(y,{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=>f===`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)(y,{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`}),` `,xe(e.createdAt)]})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${e.readAt?``:`unread`}`})]},e.id))]}),(0,S.jsx)(ae,{resource:E}),(0,S.jsx)(ae,{resource:D})]}),children:[Ne&&(0,S.jsx)(te,{id:`new-topic`,title:`发表话题`,onClose:()=>H(!1),children:(0,S.jsx)(ye,{inset:!0,plain:!0,value:Fe,onChange:Ie,label:`正文`,placeholder:`开始一个话题…`,sendLabel:`发表话题`,sendDisabled:z||!U.trim(),heading:(0,S.jsx)(`input`,{className:`topic-title`,"aria-label":`标题`,placeholder:`标题`,required:!0,value:U,onChange:e=>Pe(e.target.value)}),onSubmit:e=>{e.preventDefault(),B(!0),W(``),g(`channels/topics`,v,{method:`POST`,body:{id:Le.current,title:U,body:Fe}}).then(e=>{M(e),Y(`chat:${e.id}`),H(!1),Pe(``),Ie(``),Le.current=a(),D.reload()}).catch(e=>W(i(e))).finally(()=>B(!1))}})}),(0,S.jsx)(le,{title:(0,S.jsx)(`h2`,{children:A?P?.title??N?.title??(k?`无标题`:`Tim`):O===`debug`?`运行提醒`:`项目消息`}),actions:(0,S.jsxs)(S.Fragment,{children:[f===`channels`&&k&&(0,S.jsx)(fe,{conversation:k}),f!==`channels`&&N?.kind===`matter`&&(0,S.jsxs)(`span`,{className:`assistant-participants`,title:N.participants?.join(`、`),children:[N.visibility===`project`?`项目共享 · `:``,N.participants?.join(`、`)]}),f===`channels`&&F?.available&&(F.state===`web`||F.state===`cancelled`||!F.connected)&&(0,S.jsx)(p,{icon:`send`,label:`发布到企业微信频道`,disabled:z,onClick:()=>{B(!0),g(`channels/topics/${k}/publish`,ie(),{method:`POST`}).then(()=>D.reload()).catch(e=>W(i(e))).finally(()=>B(!1))}})]})}),f===`channels`&&(0,S.jsx)(re,{children:F?.error}),f!==`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)(he,{"data-testid":`assistant-transcript`,onScroll:e=>{let t=e.currentTarget;q.current=t.scrollHeight-t.scrollTop-t.clientHeight<100},children:[A?Ge?(0,S.jsxs)(`div`,{className:`assistant-empty`,"data-testid":`assistant-loading`,children:[(0,S.jsx)(ne,{}),(0,S.jsx)(`p`,{role:`status`,children:Re||(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)(Ue,{mine:e.role===`user`&&e.author===u,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)(me,{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)(re,{children:N.runs.find(t=>t.id===e.runId)?.error||`本次回答未完成。`})]})},e.id)):(0,S.jsxs)(`div`,{className:`assistant-empty`,children:[(0,S.jsx)(ne,{}),(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)(Se,{item:e,onReply:e.archivedAt?void 0:()=>{I(e.id),ke(``),W(``)}},e.id)):Z&&(0,S.jsx)(Se,{item:Z}),(0,S.jsx)(`div`,{ref:ze})]}),(0,S.jsx)(c,{message:A&&N?Re:void 0}),We?(0,S.jsx)(ye,{value:Oe,onChange:ke,onSubmit:e=>void He(e),disabled:V,sendDisabled:z||Ge,label:A?`向Tim提问`:`回复消息`}):O!==`debug`&&Z&&(0,S.jsxs)(`div`,{className:`assistant-archived`,children:[(0,S.jsx)(l,{name:`archive`}),`已归档`]})]})}function Se({item:e,onReply:t}){return(0,S.jsx)(`div`,{"data-testid":`outbox-thread-${e.id}`,children:(0,S.jsxs)(ve,{author:e.box===`debug`?`运行提醒`:`Tim`,time:e.createdAt,children:[(0,S.jsx)(`div`,{className:`markdown`,children:(0,S.jsx)(me,{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,At as t,C as n,D as r,F as i,I as a,M as ee,St as o,_t as s,b as c,c as l,d as te,j as u,k as d,kt as f,l as p,mt as m,pt as h,u as ne,v as re,vt as g,wt as ie,x as ae,yt as _}from"./Dropdown-DXEtBxVr.js";import{A as oe,B as se,D as v,E as ce,L as y,M as le,O as ue,P as de,i as fe,j as b,k as pe}from"./index-Rry2cw7w.js";import{t as me}from"./Markdown-nuwEQZ64.js";import{i as he,n as ge,r as _e,t as ve}from"./Conversation-C5pZE7z5.js";import{t as ye}from"./MessageComposer-0eprbRl2.js";var x=f(),S=u(),be=_({topics:h(_({id:o(),title:o(),summary:o(),author:o(),replies:g(),unread:m(),createdAt:o(),updatedAt:o(),delivery:_({available:m(),connected:m(),state:o(),error:o().nullable()})}))}),xe=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),C=e=>e.replace(/[#*_`>]/g,``).replace(/\s+/g,` `).trim();function w({me:u,mode:f=`messages`}){let{projectId:h,request:g}=se(),w=e(),Ce=d(h,u,`${f}-selection`),T=d(h,u,`${f}-drafts`),we=(0,x.useCallback)(e=>g(`agents/outbox`,oe,{signal:e}),[g]),E=r(we,3e3,d(h,u,`outbox`)),Te=(0,x.useCallback)(async e=>f===`messages`?g(`agents/chats`,ce,{signal:e}):{chats:(await g(`channels/topics`,be,{signal:e})).topics.map(e=>({...e,kind:`matter`,state:null}))},[g,f]),D=r(Te,3e3,d(h,u,f,`chats`)),[O,Ee]=(0,x.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`chat`);return t?`chat:${t}`:e.get(`message`)??w?.get(Ce)??``}),k=O.startsWith(`chat:`)?O.slice(5):``,A=!O||!!k,[j,M]=(0,x.useState)(()=>w?.get(d(h,u,`chat`,k))),N=j?.id===k?j:w?.get(d(h,u,`chat`,k)),P=D.data?.chats.find(e=>e.id===k),F=P&&`delivery`in P?P.delivery:void 0,[De,I]=(0,x.useState)(),[L,R]=(0,x.useState)(()=>w?.get(T)??{}),Oe=L[O]??``,ke=e=>R(t=>({...t,[O]:e})),[z,B]=(0,x.useState)(!1),[V,Ae]=(0,x.useState)(!1),[je,Me]=(0,x.useState)(!1),[Ne,H]=(0,x.useState)(!1),[U,Pe]=(0,x.useState)(``),[Fe,Ie]=(0,x.useState)(``),Le=(0,x.useRef)(a()),W=n(),[Re,G]=(0,x.useState)(``),K=(0,x.useRef)(new Map),ze=(0,x.useRef)(null),q=(0,x.useRef)(!0),J=(0,x.useRef)(O);J.current=O,(0,x.useEffect)(()=>{j&&w?.set(d(h,u,`chat`,j.id),j)},[w,h,u,j]),(0,x.useEffect)(()=>{w?.set(T,L)},[w,T,L]);function Y(e){J.current=e,Ee(e),w?.set(Ce,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=>f===`messages`&&e.box===`debug`).reverse(),Z=E.data?.messages.find(e=>e.id===(O===`debug`?De: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`&&g(`agents/outbox/${Z.id}/read`,b,{method:`POST`}).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>W(i(e)))},[Z?.id,Z?.readAt,O,g,E.reload]),(0,x.useEffect)(()=>{O===`debug`&&Q&&Promise.all(Q.split(`,`).map(e=>g(`agents/outbox/${e}/read`,b,{method:`POST`}))).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>W(i(e)))},[O,Q,g,E.reload]),(0,x.useEffect)(()=>{if(G(``),!k)return;let e=!0,n=-1,r=!1,a=new AbortController,s=i=>{!e||i.id!==k||i.cursor<n||(n=i.cursor,r=!0,i.redirect?Y(`chat:${i.redirect}`):i.entry===`channel`&&f!==`channels`?location.replace(t(`/projects/${h}/channels?chat=${i.id}`)):(M(i),G(``)))};g(`agents/chats/${k}`,v,{signal:a.signal}).then(s).catch(t=>{e&&!a.signal.aborted&&(t instanceof ee&&[401,403,404].includes(t.status)&&(w?.delete(d(h,u,`chat`,k)),M(e=>e?.id===k?void 0:e)),r||G(i(t)))});let c=t=>{let r=Number(t.lastEventId);return!e||!Number.isSafeInteger(r)||r<=n?!1:(n=r,!0)},l=new EventSource(t(`/api/v1/projects/${encodeURIComponent(h)}/agents/chats/${encodeURIComponent(k)}/events`));l.addEventListener(`snapshot`,t=>{if(e)try{s(v.parse(JSON.parse(t.data)))}catch(e){G(i(e))}}),l.onerror=()=>{e&&G(`对话连接中断,正在重新连接…`)},l.addEventListener(`context`,e=>{if(!c(e))return;let t=v.pick({kind:!0,title:!0,status:!0,visibility:!0,participants:!0,pending:!0,hold:!0,redirect:!0}).parse(JSON.parse(e.data));t.redirect?Y(`chat:${t.redirect}`):M(e=>e?.id===k?{...e,...t,cursor:n}:e)}),l.addEventListener(`message`,e=>{if(!c(e))return;let t=ue.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)}),l.addEventListener(`message_removed`,e=>{if(!c(e))return;let{id:t}=_({id:o()}).parse(JSON.parse(e.data));M(e=>e?.id===k?{...e,cursor:n,messages:e.messages.filter(e=>e.id!==t)}:e)}),l.addEventListener(`run`,e=>{if(!c(e))return;let t=pe.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`])l.addEventListener(e,t=>{if(!c(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,a.abort(),l.close()}},[h,k,u,g,w]),(0,x.useEffect)(()=>{if(!N||N.id!==k)return;let e=()=>{document.visibilityState===`visible`&&g(`agents/chats/${k}/read`,_({ok:m()}),{method:`POST`,body:{cursor:N.readCursor}}).then(()=>{D.reload(),window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>W(i(e)))},t=setTimeout(e,300);return document.addEventListener(`visibilitychange`,e),()=>{clearTimeout(t),document.removeEventListener(`visibilitychange`,e)}},[k,N?.readCursor,N?.kind,g]),(0,x.useEffect)(()=>{q.current&&ze.current?.scrollIntoView({block:`end`})},[O,j?.messages,Z?.recipients,X.length]);function Be(){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 g(`agents/outbox/${e}/read`,b,{method:`POST`}),Be()}catch(e){W(i(e))}}async function Ve(){if(!V){Ae(!0),W(``);try{let e=await g(`agents/chats`,v,{method:`POST`});M(e),await $(`chat:${e.id}`),D.reload()}catch(e){W(i(e))}finally{Ae(!1)}}}async function He(e){e.preventDefault();let t=Oe.trim();if(!t||z||V)return;B(!0),W(``);let n=K.current.get(O);n&&n.text===t||(n={text:t,id:a()},K.current.set(O,n));try{if(A){let e=n.target??k;if(!e){let r=await g(`agents/chats`,v,{method:`POST`});e=r.id,n.target=e,K.current.set(`chat:${e}`,n),R(n=>({...n,[`chat:${e}`]:t})),J.current===O&&(M(r),Y(`chat:${e}`))}let r=await g(`agents/chats/${e}`,pe.extend({conversationId:o().optional()}),{method:`POST`,body:{text:t,requestId:n.id}});r.conversationId&&r.conversationId!==e&&(J.current===O||J.current===`chat:${e}`)&&Y(`chat:${r.conversationId}`),M(t=>t?.id===e?{...t,runs:t.runs.some(e=>e.id===r.id)?t.runs:[...t.runs,r]}:t),D.reload()}else{let e=await g(`agents/outbox/${Z.id}/reply`,_({conversationId:o()}),{method:`POST`,body:{body:t,requestId:n.id}});Be(),J.current===O&&Y(`chat:${e.conversationId}`),D.reload(),I(void 0)}K.current.delete(O),n.target&&K.current.delete(`chat:${n.target}`),R(e=>({...e,[O]:``,...n.target?{[`chat:${n.target}`]:``}:{}}))}catch(e){W(i(e))}finally{B(!1)}}let Ue=f===`channels`?_e:ve,We=A&&!N?.closed&&(f!==`channels`||!!k)||!!Z&&!Z.archivedAt,Ge=A&&!N&&(!!k||!D.data);return(0,S.jsxs)(ge,{className:f===`channels`?`channel-layout`:``,testId:`assistant-page`,label:A?`Tim对话`:`消息内容`,navigation:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(de,{title:f===`channels`?`频道`:`对话`,children:(0,S.jsxs)(`div`,{className:`assistant-list-actions`,children:[(0,S.jsx)(p,{className:`assistant-new-chat`,icon:`clear`,label:`清除未读`,disabled:je,onClick:()=>{Me(!0),W(``),g(`communication/read`,_({ok:s(!0)}),{method:`POST`,body:{scope:f}}).then(async()=>{window.dispatchEvent(new Event(`teammy:outbox`)),await Promise.all([D.reload(),E.reload()])}).catch(e=>W(i(e))).finally(()=>Me(!1))}}),(0,S.jsx)(p,{className:`assistant-new-chat`,icon:`plus`,label:f===`channels`?`发表话题`:`新建对话`,disabled:V,onClick:()=>f===`channels`?H(!0):void Ve(),"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)(y,{selected:k===e.id,children:(0,S.jsx)(`strong`,{children:e.title})}),f===`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`}),` `,xe(e.updatedAt)]})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${e.unread||f!==`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)(y,{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=>f===`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)(y,{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`}),` `,xe(e.createdAt)]})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${e.readAt?``:`unread`}`})]},e.id))]}),(0,S.jsx)(ae,{resource:E}),(0,S.jsx)(ae,{resource:D})]}),children:[Ne&&(0,S.jsx)(te,{id:`new-topic`,title:`发表话题`,onClose:()=>H(!1),children:(0,S.jsx)(ye,{inset:!0,plain:!0,value:Fe,onChange:Ie,label:`正文`,placeholder:`开始一个话题…`,sendLabel:`发表话题`,sendDisabled:z||!U.trim(),heading:(0,S.jsx)(`input`,{className:`topic-title`,"aria-label":`标题`,placeholder:`标题`,required:!0,value:U,onChange:e=>Pe(e.target.value)}),onSubmit:e=>{e.preventDefault(),B(!0),W(``),g(`channels/topics`,v,{method:`POST`,body:{id:Le.current,title:U,body:Fe}}).then(e=>{M(e),Y(`chat:${e.id}`),H(!1),Pe(``),Ie(``),Le.current=a(),D.reload()}).catch(e=>W(i(e))).finally(()=>B(!1))}})}),(0,S.jsx)(le,{title:(0,S.jsx)(`h2`,{children:A?P?.title??N?.title??(k?`无标题`:`Tim`):O===`debug`?`运行提醒`:`项目消息`}),actions:(0,S.jsxs)(S.Fragment,{children:[f===`channels`&&k&&(0,S.jsx)(fe,{conversation:k}),f!==`channels`&&N?.kind===`matter`&&(0,S.jsxs)(`span`,{className:`assistant-participants`,title:N.participants?.join(`、`),children:[N.visibility===`project`?`项目共享 · `:``,N.participants?.join(`、`)]}),f===`channels`&&F?.available&&(F.state===`web`||F.state===`cancelled`||!F.connected)&&(0,S.jsx)(p,{icon:`send`,label:`发布到企业微信频道`,disabled:z,onClick:()=>{B(!0),g(`channels/topics/${k}/publish`,ie(),{method:`POST`}).then(()=>D.reload()).catch(e=>W(i(e))).finally(()=>B(!1))}})]})}),f===`channels`&&(0,S.jsx)(re,{children:F?.error}),f!==`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)(he,{"data-testid":`assistant-transcript`,onScroll:e=>{let t=e.currentTarget;q.current=t.scrollHeight-t.scrollTop-t.clientHeight<100},children:[A?Ge?(0,S.jsxs)(`div`,{className:`assistant-empty`,"data-testid":`assistant-loading`,children:[(0,S.jsx)(ne,{}),(0,S.jsx)(`p`,{role:`status`,children:Re||(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)(Ue,{mine:e.role===`user`&&e.author===u,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)(me,{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)(re,{children:N.runs.find(t=>t.id===e.runId)?.error||`本次回答未完成。`})]})},e.id)):(0,S.jsxs)(`div`,{className:`assistant-empty`,children:[(0,S.jsx)(ne,{}),(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)(Se,{item:e,onReply:e.archivedAt?void 0:()=>{I(e.id),ke(``),W(``)}},e.id)):Z&&(0,S.jsx)(Se,{item:Z}),(0,S.jsx)(`div`,{ref:ze})]}),(0,S.jsx)(c,{message:A&&N?Re:void 0}),We?(0,S.jsx)(ye,{value:Oe,onChange:ke,onSubmit:e=>void He(e),disabled:V,sendDisabled:z||Ge,label:A?`向Tim提问`:`回复消息`}):O!==`debug`&&Z&&(0,S.jsxs)(`div`,{className:`assistant-archived`,children:[(0,S.jsx)(l,{name:`archive`}),`已归档`]})]})}function Se({item:e,onReply:t}){return(0,S.jsx)(`div`,{"data-testid":`outbox-thread-${e.id}`,children:(0,S.jsxs)(ve,{author:e.box===`debug`?`运行提醒`:`Tim`,time:e.createdAt,children:[(0,S.jsx)(`div`,{className:`markdown`,children:(0,S.jsx)(me,{children:e.body})}),t&&(0,S.jsx)(`button`,{type:`button`,className:`assistant-debug-reply`,onClick:t,children:`回复`})]})})}export{w as Assistant};
@@ -0,0 +1,13 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./TerminalPane-B0w1stXs.js","./Dropdown-DXEtBxVr.js","./Dropdown-ktgqMqAD.css","./index-Rry2cw7w.js","./index-CeKzFsxV.css","./Markdown-nuwEQZ64.js","./task-links-BJwIQ3SE.js","./TerminalPane-BrSy-0jI.css"])))=>i.map(i=>d[i]);
2
+ import{A as e,At as t,C as n,D as r,F as i,I as a,M as o,St as s,_t as c,b as l,c as u,d,ft as f,ht as p,it as m,j as h,k as g,kt as _,l as v,mt as y,p as b,pt as x,t as S,v as C,vt as w,w as T,wt as E,x as D,yt as O}from"./Dropdown-DXEtBxVr.js";import{B as k,I as A,M as ee,P as te,S as j,T as ne,V as re,_ as ie,a as ae,b as oe,c as se,d as ce,f as le,g as ue,h as de,l as fe,m as pe,o as me,p as he,s as ge,t as _e,u as ve,v as ye,w as be,x as M,y as xe,z as Se}from"./index-Rry2cw7w.js";import{a as N,i as Ce,t as P}from"./Markdown-nuwEQZ64.js";import{a as we,i as Te,n as Ee,t as De}from"./Conversation-C5pZE7z5.js";import{n as Oe,t as ke}from"./MessageComposer-0eprbRl2.js";import{l as Ae,r as je}from"./WorkspaceTree-DmSApj8i.js";var F=_(),I=h();function Me({title:e,busy:t,onSave:n}){let[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(e);return r?(0,I.jsx)(`form`,{className:`session-title-form`,onSubmit:t=>{t.preventDefault(),a.trim()&&a.trim()!==e&&n(a.trim()),i(!1)},children:(0,I.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,I.jsx)(`h2`,{children:(0,I.jsx)(`button`,{type:`button`,className:`session-rename`,title:`重命名会话`,"aria-label":`重命名会话:${e}`,onClick:()=>{o(e),i(!0)},children:e})})}var Ne=O({id:s().uuid(),directory:s(),title:s(),cwd:s(),createdAt:s(),state:f([`running`,`exited`]),exitCode:w().nullable()}),L={id:s().uuid(),directory:s().min(1).max(200)},Pe={cols:w().int().min(2).max(500),rows:w().int().min(1).max(300)};p(`type`,[O({type:c(`create`),...L,...Pe,title:s().trim().min(1).max(160)}),O({type:c(`attach`),...L}),O({type:c(`detach`),...L}),O({type:c(`input`),...L,data:s().max(65536)}),O({type:c(`resize`),...L,...Pe}),O({type:c(`rename`),...L,title:s().trim().min(1).max(160)}),O({type:c(`close`),...L})]);var Fe=p(`type`,[O({type:c(`size`),id:s(),...Pe}),O({type:c(`inventory`),directories:x(s()),terminals:x(Ne)}),O({type:c(`snapshot`),id:s(),data:s(),cols:w(),rows:w(),seq:w()}),O({type:c(`output`),id:s(),data:s(),seq:w()}),O({type:c(`result`),id:s(),operation:s(),error:s().optional()})]);function Ie(e,n){let r=(0,F.useRef)(null),i=(0,F.useRef)(new Set),[a,o]=(0,F.useState)(!1),[s,c]=(0,F.useState)([]),[l,u]=(0,F.useState)([]);(0,F.useEffect)(()=>{if(!n)return;let a=!1,s,l,d=()=>{let n=new URL(t(`/api/v1/projects/${encodeURIComponent(e)}/web/terminals`),location.origin);n.protocol=n.protocol===`https:`?`wss:`:`ws:`,l=new WebSocket(n),r.current=l,l.onmessage=e=>{let t=Fe.safeParse(JSON.parse(e.data));if(!t.success||a)return;let n=t.data;n.type===`inventory`&&(u(n.terminals),c(n.directories),o(!0));for(let e of i.current)e(n)},l.onclose=()=>{o(!1),c([]),a||(s=setTimeout(d,2e3))}};return d(),()=>{a=!0,clearTimeout(s),l?.close(),r.current=null}},[e,n]);let d=(0,F.useCallback)(e=>(i.current.add(e),()=>{i.current.delete(e)}),[]),f=(0,F.useCallback)(e=>{if(r.current?.readyState!==WebSocket.OPEN)throw Error(`终端连接已断开,输入未发送。`);r.current.send(JSON.stringify(e))},[]);return{connected:a,directories:s,terminals:l,subscribe:d,send:f,request:(0,F.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])}}O({provider:le,cursor:s().optional(),session:de.optional()});var Le=O({id:de,title:s(),cwd:s(),updatedAt:s().datetime().nullable(),active:y().default(!1)}),R=O({sessions:x(Le),nextCursor:s().nullable()}),z=O({command:ue,history:R.nullable()});function Re(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 ze({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,F.useState)(!1),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(),g=(0,F.useRef)(null),_=(0,F.useRef)(null),y=(0,F.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,F.useEffect)(()=>p(``),[n]),(0,F.useEffect)(()=>{if(!u)return;let e=e=>{g.current?.contains(e.target)||d(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[u]),(0,F.useLayoutEffect)(()=>{if(!u)return;let e=()=>{let e=_.current?.getBoundingClientRect();if(!e)return;let t=innerHeight-e.bottom-16,n=e.top-16,r=t<220&&n>t;h({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,F.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,I.jsxs)(`div`,{className:`combobox`,ref:g,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,I.jsxs)(`div`,{className:`combobox-field`,ref:_,children:[(0,I.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,I.jsx)(v,{icon:u?`chevronUp`:`chevronDown`,label:`${u?`收起`:`展开`}${t}`,disabled:s,"aria-expanded":u,"aria-controls":`${e}-list`,onClick:()=>{d(!u),y.current?.focus()}})]}),u&&(0,I.jsxs)(`div`,{className:`combobox-popup`,style:m,children:[(0,I.jsxs)(`div`,{id:`${e}-list`,role:`listbox`,"aria-label":t,"aria-busy":o,children:[S.map((t,r)=>(0,I.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,I.jsxs)(`span`,{className:`combobox-option-copy`,children:[(0,I.jsx)(`span`,{children:t.label}),t.description&&(0,I.jsx)(`small`,{children:t.description})]}),t.detail&&(0,I.jsx)(`span`,{className:`combobox-option-detail`,children:t.detail})]},t.value)),o&&(0,I.jsx)(`p`,{className:`combobox-message`,role:`status`,children:`正在读取…`}),!o&&!S.length&&(0,I.jsx)(`p`,{className:`combobox-message`,children:c})]}),l&&(0,I.jsx)(`div`,{className:`combobox-footer`,children:l})]})]})}function Be({directory:e,provider:t,providers:r,sessions:o,request:s,onClose:c,onImport:l}){let[u,f]=(0,F.useState)(t),[p,m]=(0,F.useState)([]),[h,g]=(0,F.useState)(null),[_,y]=(0,F.useState)(``),[b,x]=(0,F.useState)(null),S=n(),C=(0,F.useRef)(null),w=e=>o.find(t=>!t.hidden&&t.provider===u&&(t.nativeSession??t.resumeSession)===e);async function T(t,n){let r=a();for(await s(`web/local-agents/${e}/history`,ue,{method:`POST`,signal:n,body:{id:r,argument:JSON.stringify({provider:u,...t})}});!n.aborted;){let t=await s(`web/local-agents/${e}/history/${r}`,z,{signal:n});if(t.command.state===`succeeded`&&t.history)return{...t.history,id:r};if(![`queued`,`running`].includes(t.command.state))throw Error(t.command.error||`读取历史会话失败。`);await new Promise(e=>{let t=()=>{clearTimeout(r),n.removeEventListener(`abort`,t),e()},r=setTimeout(t,1e3);n.addEventListener(`abort`,t,{once:!0})})}throw new DOMException(`Aborted`,`AbortError`)}async function E(t,n,r){let i=w(t.id)??await s(`web/local-agents/${e}/sessions`,pe,{method:`POST`,signal:r,body:{id:a(),title:t.title,provider:u,resumeSession:t.id,historyRequest:n}});r.aborted||l(i)}async function D(e,t){C.current?.abort();let n=new AbortController;C.current=n,x(e),S(``);try{await t(n.signal)}catch(e){n.signal.aborted||S(i(e))}finally{n.signal.aborted||x(null)}}let O=e=>D(`list`,async t=>{let n=await T(e?{cursor:e}:{},t);t.aborted||(m(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,F.useEffect)(()=>(m([]),g(null),y(``),O(),()=>C.current?.abort()),[u,e,s]);let k=p.find(e=>e.id===_),A=b===`import`;return(0,I.jsx)(d,{id:`computer-import-session`,title:`导入历史会话`,onClose:c,children:(0,I.jsxs)(`form`,{className:`native-history`,onSubmit:e=>{e.preventDefault(),D(`import`,async e=>{let t=_.trim(),n=w(t);if(n)return l(n);if(k)return E(k,k.requestId,e);let r=await T({session:t},e),i=r.sessions.find(e=>e.id===t);if(!i)throw Error(`找不到此目录中的会话。`);await E(i,r.id,e)})},children:[(0,I.jsx)(me,{label:`历史会话 Agent`,value:u,onChange:f,providers:[t,...r],disabled:A}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{htmlFor:`native-history-session`,children:`Session`}),(0,I.jsxs)(`div`,{className:`native-history-input-row`,children:[(0,I.jsx)(ze,{id:`native-history-session`,label:`历史会话`,value:_,onChange:y,placeholder:`选择会话或输入 ID`,disabled:A,loading:b===`list`,empty:_?`未找到匹配会话,可直接输入 Session ID。`:`此目录暂无历史会话,可输入 Session ID。`,options:p.map(e=>({value:e.id,label:e.title,description:e.id,detail:w(e.id)?`已接入`:e.active?`工作中`:Re(e.updatedAt),disabled:e.active&&!w(e.id)})),footer:(0,I.jsxs)(I.Fragment,{children:[h&&(0,I.jsx)(`button`,{className:`native-history-more`,type:`button`,disabled:!!b,onClick:()=>void O(h),children:`加载更多`}),(0,I.jsx)(v,{icon:`refresh`,label:`刷新历史会话`,disabled:!!b,onClick:()=>void O()})]})},u),(0,I.jsx)(`button`,{type:`submit`,disabled:A||!de.safeParse(_.trim()).success||!!k?.active&&!w(k.id),children:A?`正在导入…`:w(_.trim())?`打开`:`导入`})]})]}),(0,I.jsx)(`small`,{className:`muted`,children:`请先退出原终端会话。`})]})})}var B={png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,webp:`image/webp`,gif:`image/gif`,avif:`image/avif`,bmp:`image/bmp`,ico:`image/x-icon`,svg:`image/svg+xml`};function Ve(e,t){let n=e.toLowerCase().split(`.`).at(-1)??``;return t&&Object.values(B).includes(t)?t:Object.hasOwn(B,n)?B[n]:n===`pdf`?`application/pdf`:/^(md|markdown|mdown)$/.test(n)?`text/markdown`:/^html?$/.test(n)?`text/html`:/^(txt|log|csv|tsv|jsonl?|ndjson|ya?ml|toml|ini|cfg|conf|xml|sql|diff|patch|sh|bash|zsh|fish|py|js|jsx|mjs|cjs|ts|tsx|css|scss|vue|svelte|go|rs|c|cc|cpp|h|hpp|java|kt|swift|rb|lua|r|tex|rst|properties|env|lock)$/.test(n)||/^(readme|license|makefile|dockerfile|cmakelists\.txt|\.gitignore)$/i.test(e)?`text/plain`:``}async function He(e,t){let n=e.body.getReader(),r=[],i=0,a=(t??0)>ne;try{for(;;){let{done:e,value:t}=await n.read();if(e)break;let o=Math.min(t.length,ne-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 Ue(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 He(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 We({file:e,onClose:t,gallery:n}){let[r,a]=(0,F.useState)(),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(0),[f,p]=(0,F.useState)(!1),m=(0,F.useRef)(null),h=(0,F.useRef)(null),g=Ve(e.name,e.mimeType),{name:_,url:y,previewUrl:b,size:x}=e;(0,F.useEffect)(()=>{let e=new AbortController,t;return a(void 0),s(``),p(!1),Ue({name:_,url:y,previewUrl:b,size:x},g,e.signal,n=>(e.signal.throwIfAborted(),t=URL.createObjectURL(n),t)).then(t=>{e.signal.aborted||a(t)}).catch(t=>{e.signal.aborted||s(i(t))}),m.current?.focus(),()=>{e.abort(),t&&URL.revokeObjectURL(t)}},[y,x,b,_,g,c]),(0,F.useEffect)(()=>{h.current?.scrollIntoView({block:`center`})},[r,e.line]);let S=e.line&&r?.text!==void 0?r.text.split(`
3
+ `):null,w=(e.line??1)-1,T=g.startsWith(`image/`);return(0,I.jsx)(d,{id:`session-image-lightbox`,title:e.name,label:T?`图片预览`:`文件预览`,onClose:t,onKeyDown:e=>{n&&[`ArrowLeft`,`ArrowRight`].includes(e.key)&&(e.preventDefault(),n.move(e.key===`ArrowLeft`?-1:1))},actions:(0,I.jsxs)(I.Fragment,{children:[n&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(v,{icon:`chevron`,className:`session-image-previous`,label:`上一张图片`,onClick:()=>n.move(-1)}),(0,I.jsxs)(`small`,{children:[n.index+1,` / `,n.count]}),(0,I.jsx)(v,{icon:`chevron`,label:`下一张图片`,onClick:()=>n.move(1)})]}),T&&r?.format&&(0,I.jsx)(v,{icon:f?`zoomOut`:`zoomIn`,label:f?`适合窗口`:`原始尺寸`,"aria-pressed":f,onClick:()=>p(!f)}),(0,I.jsx)(`a`,{className:`icon-button`,href:o?void 0:r?.download??e.url,"aria-disabled":!!o,download:e.name,"aria-label":`下载文件`,title:`下载文件`,children:(0,I.jsx)(u,{name:`download`})})]}),children:(0,I.jsx)(`div`,{ref:m,tabIndex:-1,className:`session-image-viewer`,children:o?(0,I.jsx)(C,{announce:!0,retry:()=>l(e=>e+1),children:o}):r?r.format?T?(0,I.jsx)(`div`,{className:`session-image-stage`+(f?` original-size`:``),children:(0,I.jsx)(`img`,{src:r.preview,alt:e.name,onError:()=>a({format:``,download:r.download})})}):r.format===`application/pdf`?(0,I.jsx)(`iframe`,{className:`file-preview-document`,src:r.preview,title:e.name+` 预览`}):r.format===`text/html`&&!e.line?(0,I.jsx)(Ae,{name:e.name,url:e.url}):(0,I.jsxs)(`div`,{className:`file-preview-text`,children:[r.format===`text/markdown`&&!e.line?(0,I.jsx)(`article`,{className:`markdown`,children:(0,I.jsx)(P,{children:r.text??``})}):(0,I.jsx)(`pre`,{className:`raw`,children:S&&w<S.length?(0,I.jsxs)(I.Fragment,{children:[w>0&&S.slice(0,w).join(`
4
+ `)+`
5
+ `,(0,I.jsx)(`mark`,{ref:h,children:S[w]||` `}),S.length>w+1?`
6
+ `+S.slice(w+1).join(`
7
+ `):``]}):r.text}),r.truncated&&(0,I.jsx)(`small`,{children:`仅显示文件开头,可下载完整文件。`})]}):(0,I.jsx)(`p`,{className:`file-preview-empty`,children:`暂不支持预览此文件。`}):(0,I.jsx)(`p`,{role:`status`,children:`正在读取文件…`})})})}var Ge=[],Ke=`image/png,image/jpeg,image/webp`;function qe(e){if(`image/png,image/jpeg,image/webp`.split(`,`).includes(e.type))return e.type;if(e.type&&e.type!==`application/octet-stream`)return null;let t=e.name.split(`.`).at(-1)?.toLowerCase();return t===`png`?`image/png`:t===`jpg`||t===`jpeg`?`image/jpeg`:t===`webp`?`image/webp`:null}var Je=class{sessions=new Map;listeners=new Set;uploads=new Map;get=e=>this.sessions.get(e)??Ge;subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));set(e,t){this.sessions.set(e,t);for(let e of this.listeners)e()}patch(e,t,n){this.set(e,this.get(e).map(e=>e.id===t?{...e,...n}:e))}add(e,t,n,r=!1){if(!e||!t.length)return;if(t.length+this.get(e).length>4)return r?`每条消息最多添加 4 张图片。`:`每条消息最多添加 4 个附件。`;if(Array.from(t).some(e=>r&&(!qe(e)||!e.size)||e.size>j))return r?`请选择不超过 2 GB 的 PNG、JPEG 或 WebP 图片。`:`每个附件最多 2 GB。`;let i=Array.from(t,e=>({id:a(),name:e.name.slice(0,200)||`附件`,imageOnly:r,file:e,state:`uploading`}));this.set(e,[...this.get(e),...i]);for(let t of i)this.upload(e,t.id,n)}remove(e,t){this.uploads.get(t)?.abort(),this.uploads.delete(t),this.set(e,this.get(e).filter(e=>e.id!==t))}async upload(e,t,n){let r=this.get(e).find(e=>e.id===t);if(!r?.file||this.uploads.has(t))return;let a=new AbortController;this.uploads.set(t,a),this.patch(e,t,{state:`uploading`,error:``});try{let i=r.file,o=`web/local-agent-sessions/${e}/attachments/${t}`,s;if(i.size>5242880){for(let s=r.uploaded??0;s<i.size;s+=M){let r=i.slice(s,s+M);await n(`${o}/parts/${s/M}?size=${i.size}`,O({ok:y()}),{method:`POST`,signal:a.signal,timeoutMs:m,body:r}),this.patch(e,t,{uploaded:s+r.size})}s=await n(`${o}/finish`,be,{method:`POST`,signal:a.signal,timeoutMs:m,body:{name:r.name,size:i.size,imageOnly:r.imageOnly}})}else{let o=await new Promise((e,t)=>{let n=new FileReader;n.onload=()=>e(String(n.result)),n.onerror=()=>t(Error(`附件读取失败。`)),n.onabort=()=>t(Error(`附件读取已取消。`)),a.signal.addEventListener(`abort`,()=>n.abort(),{once:!0}),n.readAsDataURL(i)});if(a.signal.aborted)return;qe(i)&&this.patch(e,t,{preview:o}),s=await n(`web/local-agent-sessions/${e}/${r.imageOnly?`images`:`attachments`}`,be,{method:`POST`,signal:a.signal,timeoutMs:m,body:{id:t,name:r.name,data:o.split(`,`,2)[1]}})}a.signal.aborted||this.set(e,this.get(e).map(e=>e.id===t?{id:t,name:s.name,state:`ready`,attachment:s,imageOnly:e.imageOnly}:e))}catch(n){a.signal.aborted||this.patch(e,t,{state:`failed`,error:i(n),...n instanceof o&&n.code===`ATTACHMENT_INCOMPLETE`?{uploaded:0}:{}})}finally{this.uploads.get(t)===a&&this.uploads.delete(t)}}},Ye=(e,n,r,i=!1)=>t(`/api/v1/projects/${encodeURIComponent(e)}/local-agent/sessions/${encodeURIComponent(n)}/${i?`attachments`:`images`}/${encodeURIComponent(r)}`);function Xe({images:e,remove:t,retry:n,disabled:r=!1}){let[i,a]=(0,F.useState)(),[o,s]=(0,F.useState)([]),c=e.find(e=>e.id===i),l=e.filter(e=>!e.file&&!o.includes(e.id)),d=l.findIndex(e=>e.id===i);return e.length?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`session-images`,children:e.map(e=>(0,I.jsxs)(`div`,{className:`session-image${e.file?` session-file`:``}`,children:[e.file?(0,I.jsxs)(`button`,{type:`button`,className:`session-file-name`,title:e.name,"aria-label":`预览附件 ${e.name}`,disabled:!e.url||e.state===`uploading`||e.state===`failed`,onClick:()=>a(e.id),children:[(0,I.jsx)(u,{name:`attachment`,size:`small`}),(0,I.jsx)(`span`,{children:e.name})]}):o.includes(e.id)?(0,I.jsxs)(`button`,{type:`button`,className:`session-image-preview session-image-unavailable`,title:`重新读取图片`,onClick:()=>s(t=>t.filter(t=>t!==e.id)),children:[(0,I.jsx)(u,{name:`refresh`,size:`small`}),(0,I.jsx)(`span`,{children:e.name}),(0,I.jsx)(`small`,{children:`图片暂不可用`})]}):(0,I.jsx)(`button`,{type:`button`,className:`session-image-preview`,"aria-label":`预览图片 ${e.name}`,title:e.name,disabled:!e.url,onClick:()=>a(e.id),children:e.url?(0,I.jsx)(`img`,{src:e.url,alt:e.name,loading:`lazy`,onError:()=>s(t=>[...t,e.id])}):(0,I.jsx)(u,{name:`image`})}),e.state===`uploading`&&(0,I.jsx)(`span`,{className:`session-image-status`,role:`status`,"aria-label":`正在上传 ${e.name}`,children:(0,I.jsx)(u,{name:`loading`,size:`small`})}),e.state===`failed`&&(0,I.jsx)(`button`,{type:`button`,className:`session-image-status`,"aria-label":`重试上传 ${e.name}`,title:e.error,disabled:r,onClick:()=>n?.(e.id),children:(0,I.jsx)(u,{name:`refresh`,size:`small`})}),t&&(0,I.jsx)(`button`,{type:`button`,className:`session-image-remove`,"aria-label":`移除${e.file?`附件`:`图片`} ${e.name}`,disabled:r,onClick:()=>t(e.id),children:(0,I.jsx)(u,{name:`close`,size:`small`})}),e.state===`failed`&&(0,I.jsx)(`small`,{className:`session-image-error`,children:e.error})]},e.id))}),c&&(0,I.jsx)(We,{file:c,onClose:()=>a(void 0),gallery:d>=0&&l.length>1?{index:d,count:l.length,move:e=>a(l[(d+e+l.length)%l.length]?.id)}:void 0},c.id)]}):null}function Ze({images:e,url:t}){return(0,I.jsx)(Xe,{images:e.map(e=>({...e,file:e.mimeType===`application/octet-stream`,url:t(e.id)}))})}function Qe(t,r,a){let o=e(),s=g(r,`computer-attachment-uploads`),c=(0,F.useMemo)(()=>{let e=o?.get(s)??new Je;return o?.set(s,e),e},[o,s]),l=(0,F.useSyncExternalStore)(c.subscribe,()=>c.get(t)),d=n(),f=(0,F.useRef)(null),p=(0,F.useRef)(null),m=`${r}:${t}`,h=(0,F.useRef)(m);h.current=m,(0,F.useEffect)(()=>d(``),[t,r]);let _=l.flatMap(e=>e.attachment?[e.attachment]:[]),v=l.some(e=>e.state===`uploading`),y=e=>Ye(r,t,e,!0),b=(e,n=!1)=>d(c.add(t,e,a,n)??``);async function x(){try{let e=await navigator.clipboard.read(),t=[];for(let n of e){let e=n.types.find(e=>Ke.split(`,`).includes(e));if(e){let r=await n.getType(e);t.push(new File([r],`剪贴板-${t.length+1}.${e.split(`/`)[1]}`,{type:e}))}}if(h.current!==m)return;t.length?b(t,!0):d(`剪贴板中没有可用的图片。`)}catch(e){h.current===m&&d(e instanceof DOMException&&e.name===`NotAllowedError`?`无法读取剪贴板,请在输入框中粘贴图片或选择图片文件。`:i(e))}}return{files:_,busy:v,count:l.length,failed:l.some(e=>e.state===`failed`),add:b,clear:()=>{for(let e of _)c.remove(t,e.id)},picker:(e,n)=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`input`,{ref:p,type:`file`,className:`session-image-file`,multiple:!0,"aria-label":`选择附件`,disabled:e,onChange:e=>{e.target.files&&b(e.target.files),e.target.value=``}}),n&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`input`,{ref:f,type:`file`,className:`session-image-file`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,"aria-label":`选择图片`,disabled:e,onChange:e=>{e.target.files&&b(e.target.files,!0),e.target.value=``}}),(0,I.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":`添加图片`,title:`添加图片,也可粘贴或拖入`,disabled:e,onClick:()=>f.current?.click(),children:(0,I.jsx)(u,{name:`image`,size:`small`})})]}),(0,I.jsx)(S,{id:`session-attachments`,triggerId:`session-attachments-trigger`,label:`附件`,placement:`top`,className:`composer-menu composer-attachments`,routeKey:t,disabled:e,trigger:(0,I.jsx)(u,{name:`attachment`,size:`small`}),children:e=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{e(),p.current?.click()},children:[(0,I.jsx)(u,{name:`attachment`,size:`small`}),`选择文件`]}),n&&typeof navigator.clipboard?.read==`function`&&(0,I.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{e(),x()},children:[(0,I.jsx)(u,{name:`paste`,size:`small`}),`粘贴图片`]})]})})]}),preview:e=>(0,I.jsx)(Xe,{images:l.map(e=>({id:e.id,name:e.name,mimeType:e.attachment?.mimeType??e.file?.type,url:e.attachment?y(e.id):e.preview??``,size:e.attachment?.size??e.file?.size??0,file:e.attachment?e.attachment.mimeType===`application/octet-stream`:!!e.file&&(e.file.size>5242880||!qe(e.file)),state:e.state,...e.error?{error:e.error}:{}})),disabled:e,remove:e=>{c.remove(t,e),a(`web/local-agent-sessions/${t}/attachments/${e}`,E(),{method:`DELETE`}).catch(()=>{})},retry:e=>void c.upload(t,e,a)})}}var V={offered:{label:`待本地接收`,icon:`clock`},received:{label:`待本地接收`,icon:`clock`},queued:{label:`排队中`,icon:`clock`},dispatching:{label:`正在连接`,icon:`loading`,spinning:!0},running:{label:`执行中`,icon:`loading`,spinning:!0},cancelled:{label:`已撤回`,icon:`close`},interrupted:{label:`已停止`,icon:`stop`},failed:{label:`未能执行`,icon:`warning`},human_routed:{label:`未送达本地`,icon:`warning`},uncertain:{label:`需要核对`,icon:`warning`}};function $e({state:e,error:t}){let n=V[e];if(!n)return null;let r=t?`${n.label}:${t}`:n.label;return(0,I.jsx)(`span`,{className:`execution-status${n.spinning?` is-spinning`:``}`,role:`img`,"aria-label":r,title:r,children:(0,I.jsx)(u,{name:n.icon,size:`small`})})}function et({message:e}){return!e.queue||e.queue.state===`running`?null:(0,I.jsx)($e,{state:e.queue.state,error:e.queue.error})}function tt(e,n,r,a){let[s,c]=(0,F.useState)(),l=(0,F.useRef)(null);(0,F.useEffect)(()=>{if(!n)return;let s=new AbortController,{signal:u}=s,d=`web/local-agent-sessions/${encodeURIComponent(n)}`,f=new URLSearchParams(location.search).get(`question`),p,m,h=!1,g=!1,_=Promise.resolve(),v=(e=``)=>{u.aborted||c({session:n,...p?{data:p}:{},error:e,loadingOlder:h})},y=e=>r(d+(Object.keys(e).length?`?`+new URLSearchParams(e):``),he,{signal:u}),b=e=>(_=_.then(async()=>{if(!u.aborted)try{await e()}catch(e){e instanceof o&&[401,403,404].includes(e.status)&&(p=void 0),g=!0,v(i(e))}}),_),x=e=>b(async()=>{if(e!==void 0&&p&&p.cursor>=e&&!g)return;let t=m,n=await y(t===void 0?!p&&f?{question:f}:{}:{from:String(t)});u.aborted||(p&&!a(!1)&&S(!1),m!==t&&m!==void 0&&n.olderBefore!==null&&n.olderBefore>m&&(n=await y({from:String(m)})),!p&&f&&(m=n.olderBefore??1),p=n,g=!1,v())});function S(e){e&&!h?m=void 0:p&&m===void 0&&(m=p.olderBefore??1)}function C(){p?.olderBefore&&!h&&(S(!1),h=!0,v(),b(async()=>{try{if(!p?.olderBefore)return;let e=await y({before:String(p.olderBefore)}),t=e.olderBefore??1,n=e.cursor===p.cursor?{...p,messages:[...e.messages,...p.messages],olderBefore:e.olderBefore}:await y({from:String(t)});if(u.aborted)return;a(!0),m=t,p=n,g=!1}finally{h=!1,v()}}))}l.current={reload:()=>x(),older:C,follow:S,reveal:e=>b(async()=>{if(!p?.olderBefore||e>=p.olderBefore)return;let t=await y({from:String(e)});m=e,p=t,g=!1,v()})},x();let w=new EventSource(t(`/api/v1/projects/${encodeURIComponent(e)}/${d}/events?updates=1`)),T=e=>{document.hidden||x(Number(e.lastEventId))};w.addEventListener(`change`,T),w.addEventListener(`snapshot`,T);let E=setInterval(()=>{!document.hidden&&(g||w.readyState!==EventSource.OPEN)&&x()},15e3),D=()=>{document.hidden||x()};return document.addEventListener(`visibilitychange`,D),()=>{s.abort(),l.current=null,w.close(),clearInterval(E),document.removeEventListener(`visibilitychange`,D)}},[n,e,r,a]);let u=(0,F.useCallback)(()=>l.current?.reload()??Promise.resolve(),[]),d=(0,F.useCallback)(()=>l.current?.older(),[]),f=(0,F.useCallback)(e=>l.current?.follow(e),[]),p=(0,F.useCallback)(e=>l.current?.reveal(e)??Promise.resolve(),[]);return{...s?.session===n?s:void 0,reload:u,older:d,follow:f,reveal:p}}function H({message:e,images:t,status:r,rewind:o,onFile:s}){let c=o?.commands.find(t=>t.kind===`rewind`&&[`queued`,`running`,`uncertain`].includes(t.state)&&JSON.parse(t.argument).messageId===e.id),[l,d]=(0,F.useState)(!!c),[f,p]=(0,F.useState)(c?JSON.parse(c.argument).body:e.body),[m,h]=(0,F.useState)(!1),g=n(),[_,y]=(0,F.useState)(!1),[b,x]=(0,F.useState)(),S=(0,F.useRef)(void 0),w=Oe(f);(0,F.useLayoutEffect)(()=>{l&&w.current&&(w.current.style.height=`0px`,w.current.style.height=`${w.current.scrollHeight}px`)},[l]);let E=o?.commands.find(e=>e.id===b?.id)??b??c,D=_||E&&[`queued`,`running`].includes(E.state),O=o?.available&&e.source===`web_session`&&e.id.startsWith(`input:`)&&(!e.queue||[`handled`,`interrupted`].includes(e.queue.state));async function k(){if(!o||D||!f.trim())return;let t=JSON.stringify({messageId:e.id,body:f.trim(),expectedLastMessage:o.expectedLastMessage});(E&&[`failed`,`uncertain`].includes(E.state)||S.current?.argument!==t)&&(S.current={id:a(),argument:t}),y(!0),g(``);try{let e=await o.request(`web/local-agent-sessions/${o.session}/commands`,ue,{method:`POST`,body:{id:S.current.id,kind:`rewind`,argument:S.current.argument}});x(e),o.refresh()}catch(e){g(i(e))}finally{y(!1)}}return(0,I.jsxs)(`div`,{className:`computer-user-entry${l?` editing`:``}`,children:[(0,I.jsxs)(De,{mine:!0,author:`你`,time:e.createdAt,children:[t,l?(0,I.jsxs)(`form`,{className:`computer-message-edit`,onSubmit:e=>{e.preventDefault(),k()},children:[(0,I.jsx)(`textarea`,{ref:w,"aria-label":`编辑历史消息`,value:f,onChange:e=>p(e.target.value),disabled:!!D,autoFocus:!0,rows:1}),(0,I.jsxs)(`div`,{className:`computer-message-edit-footer`,children:[(0,I.jsx)(`small`,{children:`替换此后的对话,保留工作区文件`}),(0,I.jsx)(v,{icon:`close`,label:`取消编辑`,disabled:!!D,onClick:()=>{d(!1),g(``),p(e.body)}}),(0,I.jsx)(`button`,{type:`submit`,className:`message-send primary`,"aria-label":D?`正在回退`:`从此处继续`,title:D?`正在回退`:`从此处继续`,disabled:!!D||!f.trim(),children:(0,I.jsx)(u,{name:D?`loading`:`send`,size:`small`})})]}),(0,I.jsx)(C,{children:E&&[`failed`,`uncertain`].includes(E.state)&&E.error})]}):(0,I.jsx)(`div`,{className:`markdown`,children:(0,I.jsx)(P,{onFile:s,children:e.body})}),!l&&r]}),!l&&(0,I.jsxs)(`div`,{className:`computer-message-actions`,children:[(0,I.jsx)(v,{icon:m?`check`:`copy`,label:m?`已复制`:`复制消息`,onClick:()=>{g(``),T(e.body).then(()=>h(!0)).catch(e=>g(i(e)))}}),O&&(0,I.jsx)(v,{icon:`edit`,label:`编辑并从此处继续`,onClick:()=>{p(e.body),d(!0)}})]})]})}function U({label:e,meta:t,children:n,className:r=``,onToggle:i}){return(0,I.jsxs)(`details`,{className:`tool-details ${r}`,onToggle:i,children:[(0,I.jsxs)(`summary`,{className:`tool-summary`,title:e,children:[(0,I.jsx)(u,{name:`chevron`,size:`small`}),(0,I.jsx)(`span`,{className:`tool-details-label`,children:e}),t&&(0,I.jsx)(`span`,{className:`tool-details-status`,children:t})]}),n]})}function nt(e){if(e<1e3)return`不到 1 秒`;let t=Math.floor(e/1e3),n=Math.floor(t/60),r=Math.floor(n/60);return[r?`${r} 小时`:``,n%60?`${n%60} 分`:``,t%60?`${t%60} 秒`:``].filter(Boolean).join(` `)}function rt({children:e}){return(0,I.jsx)(`div`,{className:`computer-divider`,children:(0,I.jsx)(`span`,{children:e})})}function W({message:e}){let t=e.state===`succeeded`?`已工作`:e.state===`interrupted`?`已停止`:e.state===`failed`?`执行失败`:`需要核对`;return(0,I.jsxs)(rt,{children:[t,e.activity?.durationMs===void 0?``:` · ${nt(e.activity.durationMs)}`]})}var G={offered:`待本地接收`,pending:`待投递`,human_routed:`未送达本地`,failed:`失败`,uncertain:`需要核对`};function K(e){let t=[];for(let n of e)if(n.role===`assistant`&&n.activity?.kind===`tool`&&!n.question){let e=t.at(-1);Array.isArray(e)&&e[0].activity?.turnId===n.activity.turnId?e.push(n):t.push([n])}else t.push(n);return t}function q({text:e,onFile:t}){let n=[],r=0;if(t)for(let{start:i,end:a,link:o}of N(e))n.push(e.slice(r,i),(0,I.jsx)(`button`,{type:`button`,className:`computer-file-link`,onClick:()=>t(o),children:e.slice(i,a)},i)),r=a;return(0,I.jsxs)(`pre`,{children:[n,e.slice(r)]})}function J({call:e,onFile:t,visible:n,onOpen:r}){let[i,a]=(0,F.useState)(!1);return(0,I.jsx)(U,{className:`computer-tool`,onToggle:e=>{let t=e.currentTarget.open;a(t),r?.(t)},label:e.activity?.label??`工具调用`,meta:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)($e,{state:e.state}),e.activity?.durationMs!==void 0&&(0,I.jsx)(`span`,{children:nt(e.activity.durationMs)})]}),children:i&&n&&(0,I.jsx)(q,{text:e.body,onFile:t})})}function Y({calls:e,onFile:t}){let n=(0,F.useId)(),[r,i]=(0,F.useState)(!1),a=e.length>1,o=[`failed`,`uncertain`,`interrupted`].find(t=>e.some(e=>e.state===t));return(0,I.jsxs)(`div`,{className:a?`tool-details computer-tool-group`:void 0,children:[a&&(0,I.jsxs)(`button`,{type:`button`,className:`tool-summary`,"aria-expanded":r,"aria-controls":n,onClick:()=>i(!r),children:[(0,I.jsx)(u,{name:`chevron`,size:`small`}),e.length,` 次工具调用`,o&&(0,I.jsx)($e,{state:o}),e.some(e=>e.state===`running`)&&(0,I.jsx)($e,{state:`running`})]}),(0,I.jsx)(`div`,{id:n,className:a?`computer-tool-list`:void 0,hidden:a&&!r,children:e.map(e=>(0,I.jsx)(J,{call:e,onFile:t,visible:!a||r,onOpen:a?void 0:i},e.id))})]})}function it({messages:e,renderQuestion:t,imageUrl:n,renderQueue:r,rewind:i,onFile:a}){let o=new Map(e.filter(e=>e.activity?.kind===`turn`).map(e=>[e.activity.turnId,e])),s=new Map,c=new Set(e.flatMap(e=>{let t=e.question?.planSource;return t?[JSON.stringify([t.turnId,t.itemId])]:[]})),l=new Set(e.flatMap(e=>{let t=e.activity;return t?.kind===`commentary`&&c.has(JSON.stringify([t.turnId,t.itemId]))?[JSON.stringify([t.turnId,e.body])]:[]}));for(let t of e)t.activity?.kind===`answer`&&s.set(t.activity.turnId,t.id);let u=e.filter(({activity:e,body:t})=>e?.kind!==`commentary`||!c.has(JSON.stringify([e.turnId,e.itemId]))&&!l.has(JSON.stringify([e.turnId,t]))),d=(0,F.useRef)({keys:new Map,next:0}),f=new Map,p=new Set,m=d.current.next,h=K(u);for(let e of h){if(!Array.isArray(e))continue;let t;for(let n of e){if(t=d.current.keys.get(n.id),t!==void 0&&!p.has(t))break;t=void 0}t??=m++,p.add(t);for(let n of e)f.set(n.id,t)}return(0,F.useLayoutEffect)(()=>{d.current={keys:f,next:m}}),(0,I.jsx)(`div`,{className:`computer-messages`,children:h.map(e=>{if(Array.isArray(e))return(0,I.jsx)(Y,{calls:e,onFile:a},`tools:${f.get(e[0].id)}`);let c=e.activity;if(e.role===`system`)return(0,I.jsx)(rt,{children:e.body},e.id);if(c?.kind===`turn`)return s.has(c.turnId)?null:(0,I.jsx)(W,{message:e},e.id);if(e.role===`user`)return(0,I.jsx)(H,{message:e,rewind:i,onFile:a,images:n&&(e.attachments??e.images)?.length?(0,I.jsx)(Ze,{images:e.attachments??e.images,url:t=>n(t,!!e.attachments)}):null,status:e.queue&&r?r(e):G[e.state]&&(0,I.jsx)(we,{label:G[e.state],state:e.state})},e.id);let l=c?.kind===`answer`&&s.get(c.turnId)===e.id?o.get(c.turnId):void 0;return(0,I.jsxs)(F.Fragment,{children:[l&&(0,I.jsx)(W,{message:l}),(0,I.jsx)(`article`,{id:e.question?`computer-question-${e.question.id}`:void 0,tabIndex:e.question?-1:void 0,className:`computer-agent-message ${c?.kind===`commentary`?`computer-commentary`:``} ${e.question?`question-bubble`:``}`,children:e.question?t(e.question):(0,I.jsx)(`div`,{className:`markdown`,children:(0,I.jsx)(P,{onFile:a,children:e.body})})})]},e.id)})})}function X({disabled:e,onSend:t,initialValue:n=``,placeholder:r}){let[i,a]=(0,F.useState)(n),[o,s]=(0,F.useState)(!!n),c=`其他回答`,l=(0,F.useRef)(null),d=(0,F.useCallback)(e=>{if(!l.current)return;let t=document.createElement(`canvas`).getContext(`2d`);if(!t)return;t.font=getComputedStyle(e).font;let n=Math.max(...(i||`${c}…`).split(`
8
+ `).map(e=>t.measureText(e).width));l.current.style.setProperty(`--reply-width`,`${Math.ceil(n+(o?52:26))}px`)},[i,o,c]),f=Oe(i,d);return(0,I.jsxs)(`form`,{ref:l,className:`inline-reply${o?` active`:``}`,onFocus:()=>s(!0),onBlur:e=>{!i&&!e.currentTarget.contains(e.relatedTarget)&&s(!1)},onSubmit:n=>{n.preventDefault(),!e&&i.trim()&&t(i.trim()).then(e=>{e&&a(``)})},children:[(0,I.jsx)(`textarea`,{ref:f,rows:1,"aria-label":`自定义回答`,placeholder:r??`${c}…`,value:i,disabled:e,onChange:e=>a(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&!t.nativeEvent.isComposing&&(t.preventDefault(),!e&&i.trim()&&t.currentTarget.form?.requestSubmit())}}),o&&(0,I.jsx)(`button`,{className:`inline-reply-send`,type:`submit`,disabled:e||!i.trim(),"aria-label":`发送${c}`,title:`发送${c}`,children:(0,I.jsx)(u,{name:`send`,size:`small`})})]})}function at({question:e,session:t,request:r,refresh:o}){let[s,c]=(0,F.useState)({}),[l,d]=(0,F.useState)({}),f=n(),[p,m]=(0,F.useState)(!1),[h,g]=(0,F.useState)(!1),[_,v]=(0,F.useState)(``),b=(0,F.useRef)(null),x=(0,F.useRef)(!1),S=(0,F.useRef)(void 0);(0,F.useEffect)(()=>{if(e.state!==`pending`||x.current||!b.current)return;let n=!1,a=()=>{if(!n||document.visibilityState!==`visible`||!b.current)return;let a=b.current.getBoundingClientRect();a.bottom>0&&a.top<innerHeight&&r(`web/local-agent-sessions/${t}/questions/${e.id}/presented`,O({ok:y()}),{method:`POST`}).then(()=>{x.current=!0,window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>f(i(e)))},o=new IntersectionObserver(e=>{n=e.some(e=>e.isIntersecting),a()});return o.observe(b.current),document.addEventListener(`visibilitychange`,a),()=>{o.disconnect(),document.removeEventListener(`visibilitychange`,a)}},[e.id,e.state,t,r]);async function C(n){let s=JSON.stringify(n);S.current?.fingerprint!==s&&(S.current={fingerprint:s,value:{...n,id:a()}}),m(!0),f(``);try{return await r(`web/local-agent-sessions/${t}/questions/${e.id}/answers`,E(),{method:`POST`,body:S.current.value}),S.current=void 0,o(),!0}catch(e){return f(i(e)),!1}finally{m(!1)}}let[w,T]=(0,F.useState)(Date.now);(0,F.useEffect)(()=>{if(!e.approval||e.state!==`pending`||e.autoApproveAt==null)return;T(Date.now());let t=setInterval(()=>T(Date.now()),1e3);return()=>clearInterval(t)},[e.approval,e.state,e.autoApproveAt]);let D=e.autoApprove!==!1&&e.autoApproveAt!=null?Math.max(0,Math.ceil((e.autoApproveAt-w)/1e3)):null,k=e.response,A=e.state===`answered`,ee=[`expired`,`cancelled`].includes(e.state),te=[`human_routed`,`failed`,`handled`].includes(e.submissionState??``)&&!A,j=oe(e),ne=e.kind===`plan`,re=e.actions?.find(e=>e.id===k?.actionId),ie=ee?`已过期`:e.state===`uncertain`||e.submissionState===`uncertain`?`需核对`:A?ne?re?.label??`已处理`:e.approval?k?.decision===!0?`已允许`:k?.decision===!1?`已拒绝`:`已处理`:re?re.label:k?``:`已回答`:te?`请重新提交`:k?`正在提交`:``,ae=ee||k?.decision===!1||te?`close`:A?`check`:`clock`,se=e.questions.length>1||e.questions.some(e=>e.multiSelect),ce=(t=s)=>C({body:e.questions.length===1?t[e.questions[0].id]||(l[e.questions[0].id]??[]).join(`、`):JSON.stringify(t),...e.kind||e.questions.some(e=>e.multiSelect)?{answers:t}:{},...e.questions.some(e=>e.multiSelect)?{selections:l}:{}});if(e.delivery===`async`&&(A||ee)){let t=A&&k?e.questions.flatMap(e=>[...k.selections?.[e.id]??[],k.answers[e.id]].filter(Boolean)):[];return t.length?(0,I.jsxs)(`div`,{className:`question-response native-async-answer`,children:[(0,I.jsx)(u,{name:`check`,size:`small`}),(0,I.jsx)(`span`,{children:t.join(`
9
+ `)})]}):null}return(0,I.jsxs)(`div`,{className:`native-question ${ne?`native-plan`:``} ${j?`native-question-pending`:``}`,ref:b,children:[ne?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`native-plan-heading`,children:[(0,I.jsx)(u,{name:`file`,size:`small`}),(0,I.jsx)(`span`,{children:`实施计划`})]}),j?(0,I.jsx)(`div`,{className:`native-plan-content markdown`,children:(0,I.jsx)(P,{children:e.plan??``})}):(0,I.jsxs)(`details`,{className:`native-plan-history markdown`,children:[(0,I.jsx)(`summary`,{children:`查看计划`}),(0,I.jsx)(P,{children:e.plan??``})]}),j&&(0,I.jsxs)(I.Fragment,{children:[!h&&(0,I.jsx)(`div`,{className:`question-actions native-plan-actions ${e.actions&&e.actions.length>3?`native-plan-actions-expanded`:``}`,children:e.actions?.map(e=>(0,I.jsx)(`button`,{type:`button`,disabled:p,title:e.description,className:e.id===`implement`?`primary`:``,onClick:()=>e.id===`revise`?g(!0):void C({body:e.label,actionId:e.id}),children:e.label},e.id))}),!h&&e.actions?.find(e=>e.id===`implement`)?.description&&(0,I.jsxs)(`small`,{className:`native-plan-note muted`,children:[`开始实施:`,e.actions.find(e=>e.id===`implement`).description]}),h&&(0,I.jsxs)(`form`,{className:`native-plan-feedback`,onSubmit:e=>{e.preventDefault(),C({body:_,actionId:`revise`})},children:[(0,I.jsxs)(`label`,{children:[`修改意见`,(0,I.jsx)(`textarea`,{autoFocus:!0,value:_,onChange:e=>v(e.target.value),placeholder:`说明希望调整的部分,Agent 将修改后再次请求确认`})]}),(0,I.jsxs)(`div`,{className:`question-actions native-plan-feedback-actions`,children:[(0,I.jsx)(`button`,{className:`primary`,disabled:p||!_.trim(),children:`提交修改意见`}),(0,I.jsx)(`button`,{type:`button`,disabled:p,onClick:()=>g(!1),children:`返回计划`})]})]})]}),!j&&k?.actionId===`revise`&&k.answers.feedback&&(0,I.jsx)(`div`,{className:`question-response`,children:k.answers.feedback})]}):e.approval?(0,I.jsxs)(`div`,{className:`native-approval-row`,children:[(0,I.jsx)(U,{className:`native-approval-details`,label:e.questions.map(e=>e.text.split(`
10
+ `).filter(Boolean).slice(0,2).join(` · `)).join(` · `),children:(0,I.jsx)(`pre`,{children:e.questions.map(e=>e.text).join(`
11
+
12
+ `)})}),j?(0,I.jsxs)(`div`,{className:`native-approval-options`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`primary`,disabled:p,"aria-label":`允许`,title:D===null?void 0:`倒计时结束后自动允许本次操作`,onClick:()=>void C({body:`允许`,decision:!0}),children:[`允许`,D!==null&&(0,I.jsxs)(`span`,{"aria-hidden":`true`,children:[`(`,D,`s)`]})]}),(0,I.jsx)(`button`,{type:`button`,disabled:p,onClick:()=>void C({body:`拒绝`,decision:!1}),children:`拒绝`})]}):ie&&(0,I.jsxs)(`small`,{className:`question-result`,children:[(0,I.jsx)(u,{name:ae,size:`small`}),ie]})]}):(0,I.jsxs)(I.Fragment,{children:[e.questions.map(t=>(0,I.jsxs)(`div`,{className:`native-question-part`,children:[(0,I.jsx)(`p`,{children:t.text}),j&&(0,I.jsx)(`div`,{className:`question-options ${Object.values(t.descriptions??{}).some(Boolean)?`question-options-described`:``}`,children:t.options.map(e=>(0,I.jsxs)(`button`,{type:`button`,disabled:p,"aria-pressed":t.multiSelect?l[t.id]?.includes(e)??!1:s[t.id]===e,onClick:()=>{if(t.multiSelect){d(n=>({...n,[t.id]:n[t.id]?.includes(e)?n[t.id].filter(t=>t!==e):[...n[t.id]??[],e]}));return}let n={...s,[t.id]:e};c(n),se||ce(n)},children:[(0,I.jsxs)(`span`,{className:`question-option-label`,children:[t.multiSelect&&(0,I.jsx)(`span`,{"aria-hidden":`true`,className:`question-check`,children:l[t.id]?.includes(e)&&(0,I.jsx)(u,{name:`check`,size:`small`})}),e]}),t.descriptions?.[e]&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`span`,{className:`question-option-separator`,"aria-hidden":`true`,children:`|`}),(0,I.jsx)(`span`,{className:`question-option-description`,title:t.descriptions[e],children:t.descriptions[e]})]})]},e))}),t.freeText&&j&&(0,I.jsx)(X,{initialValue:t.initialValue,placeholder:t.placeholder,disabled:p,onSend:async e=>{let n={...s,[t.id]:e};return c(n),se?!0:ce(n)}}),j&&se&&s[t.id]&&!t.options.includes(s[t.id])&&(0,I.jsx)(`small`,{children:s[t.id]}),!j&&!e.approval&&(k?.answers[t.id]||k?.selections?.[t.id]?.length)&&(0,I.jsxs)(`div`,{className:`question-response`,children:[(0,I.jsx)(u,{name:A?`check`:`clock`,size:`small`}),(0,I.jsx)(`span`,{children:[...k.selections?.[t.id]??[],k.answers[t.id]].filter(Boolean).join(`、`)})]})]},t.id)),j&&e.actions?.length&&(0,I.jsx)(`div`,{className:`question-actions`,children:e.actions.map(e=>(0,I.jsx)(`button`,{disabled:p,onClick:()=>void C({body:e.label,actionId:e.id}),children:e.label},e.id))}),j&&se&&(0,I.jsx)(`div`,{className:`question-actions`,children:(0,I.jsx)(`button`,{disabled:p||e.questions.some(e=>!s[e.id]?.trim()&&!l[e.id]?.length),onClick:()=>void ce(),children:`回答`})})]}),ie&&(!e.approval||ne)&&(0,I.jsxs)(`small`,{className:`question-result`,children:[(0,I.jsx)(u,{name:ae,size:`small`}),ie]})]})}function ot({session:e,active:t,commands:n,request:r,refresh:o,onError:s}){let[c,l]=(0,F.useState)(!1),[d,f]=(0,F.useState)(),p=(0,F.useRef)(void 0),m=n.find(e=>e.id===d?.id)??d,h=c||m&&[`queued`,`running`].includes(m.state)||n.some(e=>e.kind===`stop`&&[`queued`,`running`].includes(e.state));if(!t&&!h)return null;async function g(){if(!h){p.current??=a(),l(!0),s(``);try{let t=await r(`web/local-agent-sessions/${e}/commands`,ue,{method:`POST`,body:{id:p.current,kind:`stop`}});f(t),p.current=void 0,o()}catch(e){s(i(e))}finally{l(!1)}}}return(0,I.jsxs)(`button`,{type:`button`,className:`message-stop`,"aria-label":h?`正在停止`:`停止当前轮`,title:h?`正在停止`:`停止当前轮`,disabled:!!h,onClick:()=>void g(),children:[(0,I.jsx)(`span`,{className:`message-stop-ring`,"aria-hidden":`true`}),(0,I.jsx)(u,{name:`stop`,size:`small`})]})}var st={minimal:`极低`,low:`低`,medium:`中`,high:`高`,xhigh:`极高`,max:`最高`,ultra:`极致`,none:`无`,off:`关闭`};function Z({id:e,label:t,current:n,options:r,disabled:i,onSelect:a}){let o=r.find(e=>e.value===n);return(0,I.jsx)(S,{id:`${e}-menu`,triggerId:e,placement:`top`,className:`composer-menu composer-choice`,label:`选择${t}`,disabled:i,routeKey:n,trigger:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`span`,{title:`${t}:${o?.label??n}`,children:o?.shortLabel??o?.label??n}),(0,I.jsx)(u,{name:`chevronDown`,size:`small`})]}),children:e=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`composer-menu-heading`,children:t}),r.map(t=>(0,I.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-label":t.label,onClick:()=>{e(),a(t.value)},children:[(0,I.jsxs)(`span`,{className:`composer-option-copy`,children:[(0,I.jsx)(`span`,{children:t.label}),t.description&&(0,I.jsx)(`small`,{children:t.description})]}),t.value===n&&(0,I.jsx)(u,{name:`check`,size:`small`})]},t.value))]})})}function ct({session:e,models:t,busy:n,available:r,online:i,commands:a,controls:o,draft:s,onInsert:c,onConfig:l}){let[d,f]=(0,F.useState)(!1);(0,F.useEffect)(()=>{/^[/$]([^\s]*)$/.exec(s)?f(!0):f(!1)},[s]);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=o??ye(e.provider),y=m?.effortLabel??`思考强度`,b=e=>m?.effortLabel?e:st[e]??e,x=e.appliedRevision===e.revision?e.effectiveConfig?.mode:void 0,C=t.find(e=>e.isDefault)?.id??(e.config.model?null:e.effectiveConfig?.model),w=t.find(e=>e.id===C)?.name??C,T=e=>g?e.replace(/^Claude\s+/,``):e,E=[{value:``,label:w?`默认 · ${w}`:t.length?`默认模型`:`模型未获取`,shortLabel:w?T(w):t.length?`默认模型`:`模型`},...t.map(e=>({value:e.id,label:e.name,shortLabel:T(e.name)}))];e.config.model&&!t.some(t=>t.id===e.config.model)&&E.push({value:e.config.model,label:e.config.model,shortLabel:T(e.config.model)});let D=m?.id===e.effectiveConfig?.model?e.effectiveConfig?.effort:m?.defaultEffort,O=[{value:``,label:D?`默认 · ${b(D)}`:`默认${y}`,shortLabel:D?b(D):m?.effortLabel??`强度`},...(m?.efforts??[]).map(e=>({value:e,label:b(e)}))];return e.config.effort&&!O.some(t=>t.value===e.config.effort)&&O.push({value:e.config.effort,label:b(e.config.effort)}),(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(S,{id:`session-commands`,triggerId:`session-command-trigger`,label:`命令与 Skills`,placement:`top`,className:`composer-menu composer-commands`,routeKey:e.id,trigger:(0,I.jsx)(u,{name:`command`,size:`small`}),open:d,onOpenChange:f,focusFirst:!1,disabled:h||!i,children:e=>(0,I.jsxs)(I.Fragment,{children:[[...a].sort((e,t)=>e.name.localeCompare(t.name,`en`)).map(t=>(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,title:[t.description,t.path].filter(Boolean).join(`
13
+ `),onClick:()=>{e(),c(t)},children:(0,I.jsxs)(`span`,{className:`composer-command-row`,children:[(0,I.jsxs)(`span`,{className:`composer-command-name`,children:[t.prefix??(t.kind===`skill`?`$`:`/`),t.name]}),(0,I.jsx)(`small`,{children:t.description})]})},`${t.kind}:${t.path??t.name}`)),!a.length&&(0,I.jsx)(`div`,{className:`composer-menu-heading`,children:`尚未获取命令`})]})}),(0,I.jsx)(Z,{id:`session-model`,label:`模型`,current:e.config.model??``,options:E,disabled:h,onSelect:n=>{let r=t.find(e=>e.id===n);l({...e.config,model:n||null,..._?{options:{}}:{},effort:e.config.effort&&r?.efforts.includes(e.config.effort)?e.config.effort:null})}}),(e.provider===`codex`||g||(m?.efforts.length??0)>0||!!e.config.effort)&&(0,I.jsx)(Z,{id:`session-effort`,label:y,current:e.config.effort??``,options:O,disabled:h,onSelect:t=>l({...e.config,effort:t||null})}),m?.options?.map(t=>(0,I.jsx)(Z,{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],l({...e.config,options:r})}},t.id)),v.map(t=>(0,I.jsx)(Z,{id:t.key===`mode`&&!g?`session-mode`:`session-permission`,label:t.label,current:t.key===`mode`?x??e.config.mode??t.defaultValue:e.config.permission,options:t.choices,disabled:h,onSelect:n=>l(t.key===`mode`?{...e.config,mode:n||void 0}:{...e.config,permission:n})},t.key))]})}var lt=(0,F.lazy)(()=>_e(()=>import(`./TerminalPane-B0w1stXs.js`),__vite__mapDeps([0,1,2,3,4,5,6,7]),import.meta.url)),ut=O({ok:y()}),dt={idle:`空闲`,working:`工作中`,waiting:`等待回答`,queued:`等待执行`,uncertain:`需要核对`,human:`人工处理`,offered:`待本地接收`,accepted:`本地已接手`,human_routed:`未送达本地`,pending:`待投递`,sent:`已发送`,succeeded:`已完成`,running:`进行中`,failed:`失败`};function ft(e){return{width:e.clientWidth,height:e.clientHeight,top:e.scrollHeight-e.clientHeight}}function Q({navigate:e,memberId:t}){let{request:n,projectId:i}=k(),a=(0,F.useCallback)(e=>n(`web/local-agent-settings`,ce,{signal:e}),[n]),o=r(a,3e4);return(0,F.useEffect)(()=>{let e=()=>void o.reload();return window.addEventListener(`teammy:local-access`,e),()=>window.removeEventListener(`teammy:local-access`,e)},[o.reload]),!o.data&&o.error?(0,I.jsx)(D,{resource:o}):o.data?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(l,{message:o.error}),(0,I.jsx)(pt,{localAvailable:o.data.accessible,navigate:e,memberId:t},`${i}/${t}`)]}):null}function pt({localAvailable:o,navigate:s,memberId:c}){let l=k(),f=e(),p=g(l.projectId,c,`computer-selection`),m=g(l.projectId,c,`computer-drafts`),h=f?.get(p),[_,y]=(0,F.useState)(()=>new Set),[x,w]=(0,F.useState)(()=>({project:l.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??``)})),T=n(),[O,j]=(0,F.useState)(!1),[ne,ce]=(0,F.useState)(!1),[ue,de]=(0,F.useState)(()=>f?.get(m)??{}),me=ue[x.session]??``,he=e=>de(t=>({...t,[x.session]:typeof e==`function`?e(t[x.session]??``):e}));(0,F.useEffect)(()=>{f?.set(m,ue)},[f,m,ue]);let[_e,ye]=(0,F.useState)(``),[be,M]=(0,F.useState)(!1),[N,P]=(0,F.useState)(`codex`),[De,Oe]=(0,F.useState)(!1),[Ae,Ne]=(0,F.useState)(``),[L,Pe]=(0,F.useState)(),[Fe,Le]=(0,F.useState)(Date.now);(0,F.useEffect)(()=>{let e=setInterval(()=>Le(Date.now()),6e4);return()=>clearInterval(e)},[]);let R=(0,F.useRef)(null),z=(0,F.useRef)(!0),ze=(0,F.useRef)(null),B=(0,F.useCallback)(e=>{let t=ft(e),n=ze.current,r=n&&(t.width!==n.width||t.height!==n.height);return(z.current&&r?Math.min(n.top,t.top):t.top)-e.scrollTop<96},[]),He=(0,F.useCallback)(e=>{e.scrollTop=e.scrollHeight,ze.current=ft(e)},[]),Ue=(0,F.useRef)(null),Ge=(0,F.useCallback)(e=>{let t=R.current;if(!t)return!0;if(B(t)||(z.current=!1),!e||z.current)return z.current;let n=t.getBoundingClientRect().top,r=Array.from(t.querySelectorAll(`.computer-messages > :not(.computer-tool-group), .computer-tool-group > .tool-summary, .computer-tool-group .computer-tool`)).find(e=>{let t=e.getBoundingClientRect();return t.height>0&&t.bottom>n});return Ue.current={...r?{node:r}:{},offset:r?.getBoundingClientRect().top??0,top:t.scrollTop,height:t.scrollHeight},!1},[B]),Ke=(0,F.useRef)(new URLSearchParams(location.search).get(`question`)),qe=(0,F.useRef)(null),Je=(0,F.useRef)(void 0),Xe=(0,F.useRef)(a()),Ze=(0,F.useCallback)(async e=>o?(await l.request(`web/local-agent-computers`,fe,{signal:e})).computers.map(e=>({...e,project:l.projectId})):[],[l,o]),V=r(Ze,3e3),$e=(V.data??[]).flatMap(e=>e.directories.map(t=>({c:e,d:t,label:ve(V.data??[],e,t)}))).sort((e,t)=>e.label.localeCompare(t.label)),H=V.data?.find(e=>e.project===x.project&&e.directories.some(e=>e.id===x.directory)),U=Ie(l.projectId,o),nt=U.terminals.find(e=>e.id===x.terminal),rt=(0,F.useRef)(nt);nt&&(rt.current=nt);let W=nt??(rt.current?.id===x.terminal?rt.current:void 0),G=H?.directories.find(e=>e.id===x.directory),K=V.data?.find(e=>e.directories.some(e=>e.id===Ae))??H,q=K?.directories.find(e=>e.id===Ae)??G;Se(x.project);let J=(0,F.useCallback)((e,t,n)=>Se(x.project).request(e,t,n),[x.project]),Y=Qe(x.session,x.project,J),X=tt(x.project,o?x.session:``,J,Ge);function st(e){let t=B(e);return t&&!z.current&&(ze.current=ft(e)),z.current=t,X.follow(t),t}let Z=X.data;(0,F.useLayoutEffect)(()=>{z.current=!0,ze.current=null,qe.current=null,Ue.current=null},[x.project,x.session]);let Q=Z?.session,pt=Z?.pendingQuestions??Z?.messages.flatMap(({question:e,seq:t})=>e?.delivery===`async`&&oe(e)?[{id:e.id,seq:t}]:[])??[];function mt(e){let t=R.current,n=document.getElementById(`computer-question-${e}`);return!t||!n||!t.contains(n)||!n.getClientRects().length?!1:(z.current=!1,qe.current=e,t.scrollTop+=n.getBoundingClientRect().top-t.getBoundingClientRect().top-16,n.focus({preventScroll:!0}),!0)}(0,F.useLayoutEffect)(()=>{if(!Q||!R.current)return;let e=R.current;if(Ke.current){let e=Ke.current;if(mt(e)){Ke.current=null,Ue.current=null;return}}let t=Ue.current;Ue.current=null,t&&!z.current?t.node&&e.contains(t.node)?e.scrollTop+=t.node.getBoundingClientRect().top-t.offset:e.scrollTop=t.top+e.scrollHeight-t.height:z.current&&He(e)},[Q?.id,G?.id,Z,He]),(0,F.useLayoutEffect)(()=>{let e=R.current;if(!e||!Q)return;let t=new ResizeObserver(()=>{z.current&&B(e)&&He(e)});return t.observe(e),()=>t.disconnect()},[Q?.id,G?.id,B,He]),(0,F.useEffect)(()=>{H?.online===!1&&X.reload()},[H?.online,X.reload]);let ht=(0,F.useRef)(Z?.messages);(0,F.useLayoutEffect)(()=>{ht.current=Z?.messages},[Z?.messages]);let gt=(0,F.useCallback)(({path:e,line:n})=>{let r=Ce(e,x.terminal?W?.cwd:Q?.cwd);if(!r)return;let i=r.split(`/`).at(-1),a=/\/\.workspace\/\.teammy-attachments\/([0-9a-f-]{36})\/[^/]+$/i.exec(r);if(!x.terminal&&Q&&a){let e=ht.current?.flatMap(e=>e.attachments??[]).find(e=>e.id===a[1]);Pe({...e,name:e?.name??i,line:n,url:Ye(x.project,Q.id,a[1],!0)});return}let o=x.terminal?W?.directory:Q?.executionDirectory??Q?.directory;if(!o)return;let s=t(`/api/v1/projects/${encodeURIComponent(x.project)}/web/local-agents/${encodeURIComponent(o)}/file?${new URLSearchParams({path:r})}`),c=Ve(i);Pe({name:i,line:n,url:s,previewUrl:s+(c.startsWith(`text/`)?`&view=text`:c?``:`&view=info`)})},[x.project,x.terminal,Q?.directory,Q?.executionDirectory,Q?.id,Q?.cwd,W?.directory,W?.cwd]),_t=H?.capabilities.includes(`local-sessions-v1`),$=(e,t,n=``,r=``)=>{Pe(void 0),w({project:e,directory:t,session:n,terminal:r}),f?.set(p,{directory:t,session:n,terminal:r}),M(!1),Oe(!1),T(``);let i=new URL(location.href);(x.session!==n||r)&&(i.searchParams.delete(`question`),Ke.current=null),i.searchParams.delete(`view`),i.searchParams.delete(`section`),i.searchParams.set(`directory`,t),r?i.searchParams.set(`terminal`,r):i.searchParams.delete(`terminal`),n?i.searchParams.set(`session`,n):i.searchParams.delete(`session`),e===l.projectId&&history.replaceState(null,``,i)};(0,F.useEffect)(()=>{let e=V.data?.find(e=>e.sessions.some(e=>e.id===x.session))??V.data?.find(e=>e.directories.length);if(!x.directory&&e?.directories.length){let t=e.directories[0],n=e.sessions.find(e=>e.id===x.session);$(e.project,n?.directory??t.id,n?.id??t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id)}},[V.data]),(0,F.useEffect)(()=>{if(!Q)return;let e=()=>{document.visibilityState===`visible`&&J(`web/local-agent-sessions/${Q.id}/read`,ut,{method:`POST`}).catch(e=>T(i(e)))};return e(),document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Q?.id,Z?.messages.at(-1)?.seq,J]);async function vt(e){j(!0),T(``);try{await e(),await Promise.all([X.reload(),V.reload()])}catch(e){T(i(e))}finally{j(!1)}}function yt(e,t){return vt(async()=>{if(await l.request(`web/local-agent-sessions/${e.id}/metadata`,pe,{method:`PUT`,body:{expectedRevision:e.metadataRevision,...t}}),t.hidden&&x.session===e.id){let t=H?.sessions.find(t=>t.directory===e.directory&&t.id!==e.id&&!t.hidden);$(x.project,e.directory,t?.id)}})}function bt(e){let t=new URLSearchParams({tab:`connect`,directory:e,session:x.session});s(`/projects/${l.projectId}/settings?${t}`)}function xt(e){let t=$e.find(({d:t})=>t.id===e),n=t?.d.provider??`codex`;return ie(n)&&!t?.c.providers.some(e=>e.id===n&&e.available)?`codex`:n}function St(e=x.directory){let t=V.data?.find(t=>t.directories.some(t=>t.id===e))??H,n=t?.directories.find(t=>t.id===e)??t?.directories[0];!n||!t?ce(!0):(Xe.current=a(),Ne(n.id),M(!0),P(xt(n.id)),T(``))}let[Ct,wt]=(0,F.useState)(null);(0,F.useEffect)(()=>wt(null),[Q?.id]);let Tt=H?.catalogs.find(e=>e.provider===(Q?.provider??`codex`)&&(Q?.cwd?e.cwd===Q.cwd:e.directory===(Q?.executionDirectory??Q?.directory))),Et=Tt?.commands??[],Dt=Tt?.models??H?.providers.find(e=>e.id===Q?.provider)?.models??(Q?.provider===`codex`?H?.models??[]:[]),Ot=Dt.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:Dt.find(e=>e.isDefault)),kt=!!H?.capabilities.includes(`local-agent-attachments-v1`),At=!!(Ot?.images??(!Q?.config.model&&H?.providers.find(e=>e.id===Q?.provider)?.defaultImages))&&!!H?.capabilities.includes(`local-agent-images-v1`),jt=Q?.state===`working`&&!Z?.commands.some(e=>e.kind===`stop`&&[`queued`,`running`].includes(e.state)),Mt=(Q?.provider===`cursor`||ie(Q?.provider))&&H?.capabilities.includes(`local-agent-steer-v1`),Nt=!H?.capabilities.includes(`local-agent-steer-v1`)&&(Q?.provider===`cursor`||Q?.provider===`claude`);function Pt(e){let t=me.trim();if(!Q||!t&&!Y.files.length)return;let n=Y.files.map(e=>e.id),r=At?Y.files.filter(e=>e.mimeType!==`application/octet-stream`).map(e=>e.id):[],i=Ct?.path&&t.startsWith(`$${Ct.name}`)?[{name:Ct.name,path:Ct.path}]:void 0,o=JSON.stringify({session:Q.id,body:t,skills:i,attachments:n,images:r,delivery:e});Je.current?.fingerprint!==o&&(Je.current={fingerprint:o,id:a()});let s=Je.current;vt(async()=>{await J(`web/local-agent-sessions/${Q.id}/messages`,E(),{method:`POST`,body:{id:s.id,body:t,delivery:e,...r.length?{images:r}:{},...n.length?{attachments:n}:{},...i?{skills:i}:{}}}),he(e=>e.trim()===t?``:e),wt(null),Y.clear(),Je.current===s&&(Je.current=void 0)})}let Ft=(0,F.useMemo)(()=>(0,I.jsx)(it,{onFile:gt,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)=>Ye(x.project,Q.id,e,t),renderQueue:e=>(0,I.jsx)(et,{message:e}),renderQuestion:e=>(0,I.jsx)(at,{question:e,session:Q.id,request:J,refresh:X.reload})}),[Q,Z,J,X.reload,x.project,gt]);return(0,I.jsxs)(Ee,{className:`computers-layout`,testId:`computers-page`,label:`本地会话`,tree:!0,navigation:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(te,{title:`电脑`}),(0,I.jsx)(`div`,{className:`assistant-message-scroll computer-tree`,role:`tree`,"aria-label":`目录与会话`,onKeyDown:je,children:$e.map(({c:e,d:t,label:n})=>{let r=`${e.project}/${t.id}`,i=!_.has(r);return(0,I.jsxs)(`div`,{role:`none`,children:[(0,I.jsxs)(`div`,{className:`computer-tree-row`,role:`none`,children:[(0,I.jsxs)(A,{className:`tree-item tree-folder`,role:`treeitem`,"aria-level":1,"aria-expanded":i,style:{"--tree-level":1},leading:(0,I.jsx)(`span`,{className:`tree-chevron ${i?`expanded`:``}`,children:(0,I.jsx)(u,{name:`chevron`,size:`small`})}),onClick:()=>{x.directory!==t.id&&$(e.project,t.id,t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id),y(e=>{let t=new Set(e);return i?t.add(r):t.delete(r),t})},children:[(0,I.jsx)(u,{name:`files`}),(0,I.jsx)(`span`,{className:`tree-name`,title:n,children:n})]}),(0,I.jsx)(v,{icon:`plus`,label:`新建会话:${n}`,className:`computer-tree-action`,onClick:()=>St(t.id)})]}),i&&(0,I.jsxs)(`div`,{role:`group`,children:[U.terminals.filter(e=>e.directory===t.id).map(n=>(0,I.jsx)(`div`,{className:`computer-tree-row computer-session-row computer-terminal-row`,role:`none`,children:(0,I.jsxs)(A,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":x.terminal===n.id,style:{"--tree-level":2},leading:(0,I.jsx)(`span`,{className:`tree-chevron`}),onClick:()=>$(e.project,t.id,``,n.id),children:[(0,I.jsx)(u,{name:`command`}),(0,I.jsxs)(`span`,{className:`computer-session-copy`,children:[(0,I.jsx)(`span`,{className:`tree-name`,children:n.title}),(0,I.jsx)(`time`,{dateTime:n.createdAt,children:n.state===`exited`?`已退出`:Re(n.createdAt,Fe)})]})]})},n.id)),e.sessions.filter(e=>e.directory===t.id).map(n=>(0,I.jsxs)(`div`,{className:`computer-tree-row computer-session-row`,role:`none`,children:[(0,I.jsxs)(A,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":x.session===n.id&&x.project===e.project,style:{"--tree-level":2},leading:(0,I.jsx)(`span`,{className:`tree-chevron`,children:(0,I.jsx)(`span`,{className:`assistant-message-dot ${n.unread?`unread`:``}`})}),title:`${n.title} · ${xe[n.provider]}`,onClick:()=>$(e.project,t.id,n.id),children:[(0,I.jsx)(se,{provider:n.provider}),(0,I.jsxs)(`span`,{className:`computer-session-copy`,children:[(0,I.jsx)(`span`,{className:`tree-name`,children:n.title}),(0,I.jsx)(`time`,{dateTime:n.updatedAt,title:new Date(n.updatedAt).toLocaleString(),children:Re(n.updatedAt,Fe)})]})]}),(0,I.jsx)(v,{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:O||n.archived,onClick:()=>void yt(n,{pinned:!n.pinned})}),n.archived?(0,I.jsx)(`span`,{title:`已归档`,role:`img`,"aria-label":`已归档`,children:(0,I.jsx)(u,{name:`archive`,size:`small`})}):n.state!==`idle`&&(0,I.jsx)(we,{state:n.state,label:dt[n.state]??n.state})]},n.id))]})]},t.id)})}),(0,I.jsx)(D,{resource:V})]}),children:[ne&&(0,I.jsx)(ae,{onClose:()=>ce(!1)}),De&&K&&q&&(0,I.jsx)(Be,{directory:q.id,provider:N===`terminal`?q.provider:N,providers:K.providers.filter(e=>!ie(e.id)||e.available).map(e=>e.id),sessions:K.sessions,request:J,onClose:()=>Oe(!1),onImport:e=>{$(x.project,e.directory,e.id),V.reload()}}),be&&q&&(0,I.jsx)(d,{id:`computer-new-session`,title:`新建会话`,onClose:()=>M(!1),children:(0,I.jsxs)(`form`,{className:`computer-panel stack`,onSubmit:e=>{e.preventDefault(),vt(async()=>{if(N===`terminal`){let e=Xe.current;await U.request({type:`create`,id:e,directory:q.id,title:_e.trim(),cols:100,rows:28}),Xe.current=a(),ye(``),$(x.project,q.id,``,e);return}let e=await J(`web/local-agents/${q.id}/sessions`,pe,{method:`POST`,body:{id:Xe.current,title:_e,provider:N}});Xe.current=a(),M(!1),ye(``),$(x.project,q.id,e.id)})},children:[$e.length>1?(0,I.jsx)(re,{title:`执行目录`,children:(0,I.jsx)(`select`,{"aria-label":`执行目录`,disabled:O,value:q.id,onChange:e=>{Ne(e.target.value),P(xt(e.target.value))},children:$e.map(({d:e,label:t})=>(0,I.jsx)(`option`,{value:e.id,children:t},e.id))})}):(0,I.jsxs)(`p`,{className:`muted computer-create-scope`,children:[`目录:`,q.name]}),(0,I.jsxs)(`label`,{children:[`会话名称`,(0,I.jsx)(`input`,{autoFocus:!0,required:!0,disabled:O,placeholder:`会话名称`,value:_e,onChange:e=>ye(e.target.value)})]}),(0,I.jsx)(ge,{label:`会话类型`,value:N,onChange:P,disabled:O,providers:le.options.filter(e=>e===`codex`||(e===`claude`?K?.capabilities.includes(`local-agent-providers-v1`):K?.providers.some(t=>t.id===e&&(!ie(e)||t.available)))),terminal:U.directories.includes(q.id)}),N===`terminal`&&(0,I.jsx)(`p`,{className:`muted computer-create-scope`,children:`在此目录启动本机 Shell,使用本机用户权限。`}),(0,I.jsx)(C,{children:K?.providers.find(e=>e.id===N)?.error}),(0,I.jsxs)(`div`,{className:`computer-create-options`,children:[N!==`terminal`&&(0,I.jsx)(`button`,{type:`button`,disabled:!K?.online||!K.capabilities.includes(`local-agent-history-v1`),onClick:()=>{M(!1),Oe(!0)},children:`导入历史会话`}),(0,I.jsx)(`button`,{type:`button`,onClick:()=>{M(!1),ce(!0)},children:`接入目录`}),(0,I.jsx)(`button`,{className:`primary`,disabled:O||!_e.trim()||(N===`terminal`?!U.directories.includes(q.id):!_t),children:`创建`})]})]})}),L&&(0,I.jsx)(We,{file:L,onClose:()=>Pe(void 0)},L.url),x.terminal?W?(0,I.jsx)(F.Suspense,{fallback:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ee,{title:W.title}),(0,I.jsx)(`div`,{className:`assistant-empty`,children:`正在打开终端…`})]}),children:(0,I.jsx)(lt,{terminal:W,onFile:gt,connection:U,onClosed:()=>$(x.project,x.directory)},W.id)}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ee,{title:`终端`}),(0,I.jsx)(`div`,{className:`assistant-empty`,children:U.connected?`终端已结束或电脑已重启,请新建终端。`:`正在连接终端…`})]}):G?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ee,{title:Q?(0,I.jsx)(Me,{title:Q.title,busy:O,onSave:e=>yt(Q,{title:e})},Q.id):(0,I.jsx)(`h2`,{children:G.name}),actions:(0,I.jsx)(I.Fragment,{children:(0,I.jsx)(S,{id:`computer-session-menu`,triggerId:`computer-session-actions`,label:`会话操作`,trigger:(0,I.jsx)(u,{name:`more`}),className:`computer-create-menu`,routeKey:Q?.id??``,disabled:!Q,children:e=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{role:`menuitem`,disabled:O,onClick:()=>{e(),Q&&yt(Q,{hidden:!0})},children:`隐藏会话`}),(0,I.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),bt(G.id)},children:`连接专用群`}),(0,I.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),bt(G.id)},children:`执行位置`})]})})})}),!_t&&(0,I.jsx)(b,{children:`升级客户端后可使用多个会话和网页对话。`}),(0,I.jsxs)(Te,{ref:R,onClickCapture:({target:e,currentTarget:t})=>{e instanceof Element&&e.closest(`.tool-summary`)&&(z.current=!1,requestAnimationFrame(()=>{t===R.current&&t.contains(e)&&st(t)}))},onWheel:e=>{e.deltaY<0&&e.currentTarget.scrollTop<=0&&Z?.olderBefore&&(z.current=!1,X.older())},onScroll:e=>{let t=e.currentTarget;!st(t)&&t.scrollTop<100&&Z?.olderBefore&&X.older()},"aria-label":`本地会话记录`,children:[Z?.olderBefore&&(0,I.jsx)(`button`,{type:`button`,className:`computer-older`,disabled:X.loadingOlder,onClick:()=>{z.current=!1,X.older()},children:X.loadingOlder?`正在加载…`:`加载更早消息`}),(0,I.jsx)(D,{resource:X}),Ft,(0,I.jsx)(C,{children:Q?.error}),Z&&!Z.messages.length&&!Z.olderBefore&&(0,I.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,I.jsxs)(`p`,{className:`computer-control-status`,role:`status`,children:[e.kind===`stop`?`停止`:e.kind,` · `,dt[e.state]??e.state,e.error?`:${e.error}`:``]},e.id)),pt.length>0&&(0,I.jsx)(`div`,{className:`computer-question-shortcut`,children:(0,I.jsxs)(`button`,{type:`button`,onClick:()=>{let e=(pt.findIndex(e=>e.id===qe.current)+1)%pt.length,t=pt[e];mt(t.id)||(z.current=!1,Ke.current=t.id,X.reveal(t.seq))},children:[(0,I.jsx)(u,{name:`question`,size:`small`}),`有 `,pt.length,` 个问题等待你的确认`]})}),Q&&(0,I.jsx)(ke,{value:me,onChange:he,label:`向本地 Agent 发送消息`,sendLabel:jt?Mt?`中断并发送`:Nt?`加入队列`:`插话`:`发送`,onQueue:[`working`,`waiting`].includes(Q.state)&&H?.capabilities.includes(`local-agent-queue-v1`)?()=>Pt(`queue`):void 0,placeholder:Q.archived?`会话已归档`:`输入消息…`,disabled:Q.archived||!_t,sendDisabled:O||Y.busy||Y.failed||Y.count>0&&!kt||Z?.commands.some(e=>e.kind===`rewind`&&[`queued`,`running`,`uncertain`].includes(e.state)),attachments:(0,I.jsxs)(I.Fragment,{children:[Y.preview(O),Y.files.some(e=>e.mimeType!==`application/octet-stream`)&&!At&&(0,I.jsx)(b,{children:`当前模型将通过本地文件路径接收图片。`})]}),hasAttachments:Y.count>0,onFiles:kt&&!O?e=>void Y.add(e):void 0,beforeSend:(0,I.jsx)(ot,{session:Q.id,active:[`working`,`waiting`].includes(Q.state),commands:Z?.commands??[],request:J,refresh:X.reload,onError:T},Q.id),actions:(0,I.jsxs)(I.Fragment,{children:[kt?Y.picker(O||!_t,At):At?(0,I.jsx)(`span`,{title:`更新开发机客户端后可添加附件`,children:(0,I.jsx)(`button`,{type:`button`,className:`icon-button`,disabled:!0,"aria-label":`更新开发机客户端后可添加附件`,children:(0,I.jsx)(u,{name:`attachment`,size:`small`})})}):null,(0,I.jsx)(ct,{session:Q,models:Dt,busy:O,available:!!_t,online:!!H?.online,commands:Et,controls:Tt?.controls,draft:me,onInsert:e=>{wt(e.kind===`skill`?e:null),he(`${e.prefix??(e.kind===`skill`?`$`:`/`)}${e.name} `),requestAnimationFrame(()=>document.querySelector(`.message-composer textarea`)?.focus())},onConfig:e=>{vt(()=>J(`web/local-agent-sessions/${Q.id}/settings`,pe,{method:`PUT`,body:{expectedRevision:Q.revision,config:e}}))}})]}),onSubmit:()=>Pt(`auto`)})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ee,{title:`本地会话`}),(0,I.jsxs)(`div`,{className:`assistant-empty`,children:[`尚未登记本地执行目录。`,(0,I.jsx)(`button`,{onClick:()=>ce(!0),children:`接入目录`})]})]})]})}export{Q as Computers,Me as t};
@@ -1 +1 @@
1
- import{j as e}from"./Dropdown-DXEtBxVr.js";import{F as t}from"./index-Cr9kdjwc.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{j as e}from"./Dropdown-DXEtBxVr.js";import{F as t}from"./index-Rry2cw7w.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 +1 @@
1
- import{At as e,C as t,D as n,E as r,F as i,Ft as a,Lt as o,Pt as s,T as c,_ as l,a as u,c as d,d as f,j as p,k as m,kt as h,l as g,m as _,r as v,s as y,t as b,w as x,x as S}from"./Dropdown-DXEtBxVr.js";import{B as C,H as w,U as T}from"./index-Cr9kdjwc.js";import{n as E,o as D,r as O,t as k}from"./task-links-B7fExlHK.js";import"./file-links-Bo7XBz3i.js";var A=a(((e,t)=>{t.exports=typeof process==`object`&&{}.NODE_DEBUG&&/\bsemver\b/i.test({}.NODE_DEBUG)?(...e)=>console.error(`SEMVER`,...e):()=>{}})),j=a(((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}})),M=a(((e,t)=>{var{MAX_SAFE_COMPONENT_LENGTH:n,MAX_SAFE_BUILD_LENGTH:r,MAX_LENGTH:i}=j(),a=A();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*$`)})),N=a(((e,t)=>{var n=Object.freeze({loose:!0}),r=Object.freeze({});t.exports=e=>e?typeof e==`object`?e:n:r})),P=a(((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)}})),F=a(((e,t)=>{var n=A(),{MAX_LENGTH:r,MAX_SAFE_INTEGER:i}=j(),{safeRe:a,t:o}=M(),s=N(),{compareIdentifiers:c}=P(),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}}})),I=a(((e,t)=>{var n=F();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}}})),L=h(),R=o(I(),1),z=p();function B({className:e=``,...t}){return(0,z.jsx)(`button`,{type:`button`,...t,className:`pill-control ${e}`})}function V({className:e=``,...t}){return(0,z.jsx)(b,{...t,className:`pill-menu ${e}`})}var H=[{value:`time`,label:`按时间`,icon:`clock`},{value:`owner`,label:`按用户`,icon:`members`}];function U(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 W=[{status:`planned`,label:`计划`},{status:`in_progress`,label:`进行中`},{status:`in_review`,label:`待验收`},{status:`completed`,label:`已完成`},{status:null,label:`未明确`}];function G({members:t,project:r,memberId:i}){let{request:a,projectId:o}=C(),s=`teammy-board-mine:${i}:${o}`,[c,l]=(0,L.useState)(()=>{try{return localStorage.getItem(s)===`true`}catch{return!1}}),f=`teammy-board-order:${i}:${o}`,[p,h]=(0,L.useState)(()=>{try{return localStorage.getItem(f)===`owner`?`owner`:`time`}catch{return`time`}}),g=H.find(e=>e.value===p),y=(0,L.useCallback)(e=>a(`tasks`,w,{signal:e}),[a]),b=n(y,3e3,m(o,`tasks`)),[x,T]=(0,L.useState)(),[E,D]=(0,L.useState)(!1),[O,A]=(0,L.useState)(Date.now);(0,L.useEffect)(()=>{let e=setInterval(()=>A(Date.now()),6e4);return()=>clearInterval(e)},[]);let j=b.data,M=k(location.href),N=j?.tasks.filter(e=>!c||e.owner===i)??[],P=new Set(t.map(e=>e.id));return(0,z.jsxs)(`div`,{className:`task-board`,children:[(0,z.jsx)(_,{title:r?.projectName.trim()?`${r.projectName.trim()}|工作看板`:`工作看板`,description:r?.description.trim()||``,children:(0,z.jsxs)(`div`,{className:`task-board-brand`,children:[(0,z.jsx)(`a`,{className:`task-board-home`,"data-testid":`home-link`,href:e(`/projects`),onClick:U,"aria-label":`项目主页`,"data-tooltip":`项目主页`,children:(0,z.jsx)(v,{})}),t.some(e=>e.id===i&&e.bound)&&(0,z.jsx)(K,{memberId:i})]})}),(0,z.jsxs)(`div`,{className:`task-board-toolbar`,role:`group`,"aria-label":`看板筛选与排序`,children:[(0,z.jsxs)(B,{"aria-pressed":c,"data-testid":`task-board-mine`,onClick:()=>{let e=!c;l(e),D(!1);try{localStorage.setItem(s,String(e))}catch{}},children:[(0,z.jsx)(d,{name:c?`enable`:`account`,size:`small`}),`只看我的`]}),(0,z.jsx)(V,{id:`task-board-sort-menu`,triggerId:`task-board-sort`,label:`任务排序:${g.label}`,routeKey:p,trigger:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(d,{name:g.icon,size:`small`}),(0,z.jsx)(`span`,{children:g.label}),(0,z.jsx)(d,{name:`chevronDown`,size:`small`})]}),children:e=>H.map(t=>(0,z.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-label":t.label,onClick:()=>{e(),h(t.value),D(!1);try{localStorage.setItem(f,t.value)}catch{}},children:[(0,z.jsx)(d,{name:t.icon,size:`small`}),(0,z.jsx)(`span`,{children:t.label}),p===t.value&&(0,z.jsx)(d,{name:`check`,size:`small`})]},t.value))})]}),(0,z.jsx)(S,{resource:b}),(0,z.jsx)(`section`,{className:`task-board-lanes`,"aria-label":`任务进度`,"data-testid":`progress-board`,children:W.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)=>(p===`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,z.jsxs)(`section`,{className:`task-lane`,"aria-label":e.label,"data-stage":e.status??`unknown`,children:[(0,z.jsxs)(`h2`,{children:[(0,z.jsx)(`span`,{className:`lane-dot`}),e.label,(0,z.jsx)(u,{children:j?t.length:`—`})]}),(0,z.jsxs)(`div`,{className:`task-lane-content`,children:[t.length?n.map(e=>(0,z.jsx)(q,{task:e,number:j?.taskNumbers[e.id],memberIds:P,now:O,onEdit:()=>T(e),onSaved:()=>void b.reload()},e.id)):(0,z.jsx)(`p`,{className:`task-lane-empty`,children:b.error&&!j?`读取失败`:j?`暂无任务`:`读取中…`}),e.status===`completed`&&t.length>5&&(0,z.jsxs)(`button`,{type:`button`,className:`task-lane-expand`,"aria-expanded":E,onClick:()=>D(!E),children:[(0,z.jsx)(d,{name:E?`chevronUp`:`chevronDown`,size:`small`}),E?`收起`:`展开其余 ${t.length-5} 项`]})]})]},e.label)})}),M&&(0,z.jsx)(Y,{project:o,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`))}}),x&&(0,z.jsx)(Q,{task:x,onClose:()=>T(void 0),onSaved:()=>{T(void 0),b.reload()}},x.id)]})}function K({memberId:e}){let{api:t,projectId:r}=C(),i=n(t.devices,!0),a=c();if(!i.data||!a.data||i.error||a.error)return null;let o=(0,R.default)(a.data.version),[l]=i.data.devices.filter(t=>t.memberId===e&&t.bound).map(e=>(0,R.default)(e.status?.clientVersion)).filter(e=>e!==null).sort((e,t)=>e.compare(t));if(!l||!o||l.compare(o)>=0)return null;let u=a.data.versions.filter(e=>{let t=(0,R.default)(e);return t&&(!t.prerelease.length||e===o.raw)&&t.compare(l)>0&&t.compare(o)<=0}).length;return(0,z.jsx)(`p`,{className:`task-board-update${u>5?` overdue`:``}`,children:(0,z.jsxs)(`a`,{href:s(r,`settings/client-maintenance.md`,`#升级与修复`),onClick:U,children:[(0,z.jsx)(d,{name:`attention`,size:`small`}),(0,z.jsxs)(`span`,{children:[`客户端待更新 `,l.raw,` → `,o.raw]})]})})}function q({task:e,number:n,memberIds:a,onEdit:o,onSaved:s,now:c}){let{request:l}=C(),u=r(),[f,p]=(0,L.useState)(!1),m=t();async function h(){if(!f){p(!0),m(``);try{await l(`tasks/${e.id}/correction`,T,{method:`PATCH`,signal:u,body:{needsConfirmation:!1,expectedRevision:e.revision}}),u.aborted||s()}catch(e){u.aborted||m(i(e))}finally{p(!1)}}}return(0,z.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,z.jsxs)(`summary`,{className:`task-card-heading`,"data-testid":`task-toggle`,children:[(0,z.jsxs)(`h3`,{children:[n!==void 0&&(0,z.jsxs)(`span`,{className:`task-card-number`,children:[`#`,n]}),(0,z.jsx)(`span`,{className:`task-card-title`,children:e.title})]}),(0,z.jsxs)(`span`,{className:`task-card-meta`,children:[(0,z.jsx)(`small`,{title:e.owner,children:e.owner}),e.needsConfirmation&&(0,z.jsxs)(`span`,{className:`task-confirmation`,"data-testid":`task-confirmation`,children:[(0,z.jsx)(d,{name:`attention`,size:`small`}),`需要确认`]}),e.status!==`completed`&&(0,z.jsx)(X,{since:e.statusSince,now:c})]})]}),(0,z.jsx)(g,{icon:`edit`,className:`task-card-edit`,label:`纠正任务:${e.title}`,"data-testid":`task-correct`,disabled:f,onClick:o}),(0,z.jsxs)(`div`,{className:`task-card-details`,children:[(0,z.jsx)(J,{task:e,memberIds:a}),e.needsConfirmation&&(0,z.jsx)(`div`,{className:`task-card-confirm`,children:(0,z.jsx)(`button`,{className:`primary`,"data-testid":`task-confirm-save`,disabled:f,onClick:()=>void h(),children:f?`正在保存…`:`保存`})})]})]})}function J({task:n,memberIds:r}){let{projectId:i}=C(),[a,o]=(0,L.useState)(``),s=t();return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`h4`,{children:`目标`}),(0,z.jsx)(`p`,{children:n.goal?(0,z.jsx)(Z,{value:n.goal,memberIds:r}):`目标未明确`}),(0,z.jsx)(`h4`,{children:`当前进展`}),(0,z.jsx)(`p`,{className:`task-progress`,children:(0,z.jsx)(Z,{value:n.progress,memberIds:r})}),(0,z.jsx)(`div`,{className:`task-card-sources`,children:n.sources.map(t=>(0,z.jsxs)(`a`,{"data-testid":`task-source`,href:e(t.kind===`material`?`/projects/${i}/materials?id=${t.materialId}&revision=${t.revision}`:O(i,n.owner,t.path)),children:[(0,z.jsx)(d,{name:`file`,size:`small`}),(0,z.jsx)(`span`,{children:t.path})]},t.path))}),(0,z.jsxs)(`div`,{className:`task-card-footer`,children:[n.syncedAt&&(0,z.jsxs)(`small`,{children:[`资料同步于 `,(0,z.jsx)(l,{value:n.syncedAt})]}),(0,z.jsx)(`span`,{role:`status`,children:a}),(0,z.jsx)(g,{icon:`link`,label:`复制任务链接`,onBlur:()=>o(``),onClick:async()=>{s(``);try{await x(new URL(e(D(i,n.id)),location.origin).href),o(`已复制`)}catch{o(``),s(`未能复制任务链接,请重试。`)}}})]})]})}function Y({project:e,id:t,memberIds:n,onClose:r}){let i=E(e,t,!0),{data:a,error:o}=i;return(0,z.jsxs)(f,{id:`shared-task`,title:a?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`span`,{className:`task-card-number`,children:[`#`,a.number]}),` `,a.task.title]}):`任务`,onClose:r,children:[(0,z.jsx)(S,{resource:i}),a?(0,z.jsxs)(`div`,{className:`task-card-details`,children:[(0,z.jsxs)(`small`,{children:[a.task.owner,` · `,W.find(e=>e.status===a.task.status)?.label,!a.active&&` · 已归档`]}),(0,z.jsx)(J,{task:a.task,memberIds:n},t)]}):!o&&(0,z.jsx)(`p`,{role:`status`,children:`读取中…`})]})}function X({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,z.jsxs)(`span`,{className:`task-age${n>6048e5?` stale`:``}`,"data-testid":`task-age`,title:`进入当前状态:${new Date(e).toLocaleString(`zh-CN`)}`,"aria-label":`当前状态停留 ${i}`,children:[(0,z.jsx)(d,{name:`clock`,size:`small`}),i]})}function Z({value:e,memberIds:t}){return e.split(/(@[a-z][a-z0-9_-]*)/gi).map((e,n)=>e.startsWith(`@`)&&t.has(e.slice(1))?(0,z.jsx)(`mark`,{className:`task-mention`,children:e},n):e)}function Q({task:e,onClose:n,onSaved:a}){let{request:o}=C(),s=r(),[c,l]=(0,L.useState)(e.title),[u,d]=(0,L.useState)(e.status??``),[p,m]=(0,L.useState)(e.goal??``),[h,g]=(0,L.useState)(e.progress),[_,v]=(0,L.useState)(!1),b=t(),x={...c===e.title?{}:{title:c},...u===(e.status??``)?{}:{status:u||null},...p===(e.goal??``)?{}:{goal:p||null},...h===e.progress?{}:{progress:h},...e.needsConfirmation?{needsConfirmation:!1}:{}};async function S(){if(!_&&Object.keys(x).length){v(!0),b(``);try{await o(`tasks/${e.id}/correction`,T,{method:`PATCH`,signal:s,body:{...x,expectedRevision:e.revision}}),s.aborted||a()}catch(e){s.aborted||b(i(e))}finally{v(!1)}}}return(0,z.jsx)(f,{id:`task-correction`,title:`纠正任务`,onClose:n,children:(0,z.jsxs)(`form`,{className:`stack`,"aria-busy":_,onSubmit:e=>{e.preventDefault(),S()},children:[(0,z.jsx)(y,{id:`task-title`,label:`标题`,children:(0,z.jsx)(`input`,{value:c,required:!0,onChange:e=>l(e.target.value)})}),(0,z.jsxs)(`fieldset`,{className:`task-status-field`,disabled:_,children:[(0,z.jsx)(`legend`,{children:`状态`}),(0,z.jsx)(`div`,{className:`task-status-options`,"data-testid":`task-status`,children:W.filter(e=>e.status!==null).map(e=>(0,z.jsxs)(`label`,{className:`task-status-choice`,children:[(0,z.jsx)(`input`,{type:`radio`,name:`task-status`,value:e.status,checked:u===e.status,onChange:()=>d(e.status)}),(0,z.jsx)(`span`,{children:e.label})]},e.status))}),(0,z.jsx)(`small`,{children:`待验收:任务成果已提交,等待验收或最终确认。`})]}),(0,z.jsx)(y,{id:`task-goal`,label:`目标`,children:(0,z.jsx)(`textarea`,{value:p,onChange:e=>m(e.target.value)})}),(0,z.jsx)(y,{id:`task-progress`,label:`当前进展`,children:(0,z.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value)})}),(0,z.jsx)(`div`,{className:`row wrap`,children:(0,z.jsx)(`button`,{type:`submit`,className:`primary`,disabled:_||!Object.keys(x).length,"data-testid":`task-correction-save`,children:`保存`})})]})})}function $({members:e,config:t,memberId:n}){return(0,z.jsx)(G,{members:e,project:t,memberId:n})}export{$ as Dashboard};
1
+ import{At as e,C as t,D as n,E as r,F as i,Ft as a,Lt as o,Pt as s,T as c,_ as l,a as u,c as d,d as f,j as p,k as m,kt as h,l as g,m as _,r as v,s as y,t as b,w as x,x as S}from"./Dropdown-DXEtBxVr.js";import{B as C,H as w,U as T}from"./index-Rry2cw7w.js";import{n as E,o as D,r as O,t as k}from"./task-links-BJwIQ3SE.js";import"./file-links-Bo7XBz3i.js";var A=a(((e,t)=>{t.exports=typeof process==`object`&&{}.NODE_DEBUG&&/\bsemver\b/i.test({}.NODE_DEBUG)?(...e)=>console.error(`SEMVER`,...e):()=>{}})),j=a(((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}})),M=a(((e,t)=>{var{MAX_SAFE_COMPONENT_LENGTH:n,MAX_SAFE_BUILD_LENGTH:r,MAX_LENGTH:i}=j(),a=A();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*$`)})),N=a(((e,t)=>{var n=Object.freeze({loose:!0}),r=Object.freeze({});t.exports=e=>e?typeof e==`object`?e:n:r})),P=a(((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)}})),F=a(((e,t)=>{var n=A(),{MAX_LENGTH:r,MAX_SAFE_INTEGER:i}=j(),{safeRe:a,t:o}=M(),s=N(),{compareIdentifiers:c}=P(),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}}})),I=a(((e,t)=>{var n=F();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}}})),L=h(),R=o(I(),1),z=p();function B({className:e=``,...t}){return(0,z.jsx)(`button`,{type:`button`,...t,className:`pill-control ${e}`})}function V({className:e=``,...t}){return(0,z.jsx)(b,{...t,className:`pill-menu ${e}`})}var H=[{value:`time`,label:`按时间`,icon:`clock`},{value:`owner`,label:`按用户`,icon:`members`}];function U(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 W=[{status:`planned`,label:`计划`},{status:`in_progress`,label:`进行中`},{status:`in_review`,label:`待验收`},{status:`completed`,label:`已完成`},{status:null,label:`未明确`}];function G({members:t,project:r,memberId:i}){let{request:a,projectId:o}=C(),s=`teammy-board-mine:${i}:${o}`,[c,l]=(0,L.useState)(()=>{try{return localStorage.getItem(s)===`true`}catch{return!1}}),f=`teammy-board-order:${i}:${o}`,[p,h]=(0,L.useState)(()=>{try{return localStorage.getItem(f)===`owner`?`owner`:`time`}catch{return`time`}}),g=H.find(e=>e.value===p),y=(0,L.useCallback)(e=>a(`tasks`,w,{signal:e}),[a]),b=n(y,3e3,m(o,`tasks`)),[x,T]=(0,L.useState)(),[E,D]=(0,L.useState)(!1),[O,A]=(0,L.useState)(Date.now);(0,L.useEffect)(()=>{let e=setInterval(()=>A(Date.now()),6e4);return()=>clearInterval(e)},[]);let j=b.data,M=k(location.href),N=j?.tasks.filter(e=>!c||e.owner===i)??[],P=new Set(t.map(e=>e.id));return(0,z.jsxs)(`div`,{className:`task-board`,children:[(0,z.jsx)(_,{title:r?.projectName.trim()?`${r.projectName.trim()}|工作看板`:`工作看板`,description:r?.description.trim()||``,children:(0,z.jsxs)(`div`,{className:`task-board-brand`,children:[(0,z.jsx)(`a`,{className:`task-board-home`,"data-testid":`home-link`,href:e(`/projects`),onClick:U,"aria-label":`项目主页`,"data-tooltip":`项目主页`,children:(0,z.jsx)(v,{})}),t.some(e=>e.id===i&&e.bound)&&(0,z.jsx)(K,{memberId:i})]})}),(0,z.jsxs)(`div`,{className:`task-board-toolbar`,role:`group`,"aria-label":`看板筛选与排序`,children:[(0,z.jsxs)(B,{"aria-pressed":c,"data-testid":`task-board-mine`,onClick:()=>{let e=!c;l(e),D(!1);try{localStorage.setItem(s,String(e))}catch{}},children:[(0,z.jsx)(d,{name:c?`enable`:`account`,size:`small`}),`只看我的`]}),(0,z.jsx)(V,{id:`task-board-sort-menu`,triggerId:`task-board-sort`,label:`任务排序:${g.label}`,routeKey:p,trigger:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(d,{name:g.icon,size:`small`}),(0,z.jsx)(`span`,{children:g.label}),(0,z.jsx)(d,{name:`chevronDown`,size:`small`})]}),children:e=>H.map(t=>(0,z.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-label":t.label,onClick:()=>{e(),h(t.value),D(!1);try{localStorage.setItem(f,t.value)}catch{}},children:[(0,z.jsx)(d,{name:t.icon,size:`small`}),(0,z.jsx)(`span`,{children:t.label}),p===t.value&&(0,z.jsx)(d,{name:`check`,size:`small`})]},t.value))})]}),(0,z.jsx)(S,{resource:b}),(0,z.jsx)(`section`,{className:`task-board-lanes`,"aria-label":`任务进度`,"data-testid":`progress-board`,children:W.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)=>(p===`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,z.jsxs)(`section`,{className:`task-lane`,"aria-label":e.label,"data-stage":e.status??`unknown`,children:[(0,z.jsxs)(`h2`,{children:[(0,z.jsx)(`span`,{className:`lane-dot`}),e.label,(0,z.jsx)(u,{children:j?t.length:`—`})]}),(0,z.jsxs)(`div`,{className:`task-lane-content`,children:[t.length?n.map(e=>(0,z.jsx)(q,{task:e,number:j?.taskNumbers[e.id],memberIds:P,now:O,onEdit:()=>T(e),onSaved:()=>void b.reload()},e.id)):(0,z.jsx)(`p`,{className:`task-lane-empty`,children:b.error&&!j?`读取失败`:j?`暂无任务`:`读取中…`}),e.status===`completed`&&t.length>5&&(0,z.jsxs)(`button`,{type:`button`,className:`task-lane-expand`,"aria-expanded":E,onClick:()=>D(!E),children:[(0,z.jsx)(d,{name:E?`chevronUp`:`chevronDown`,size:`small`}),E?`收起`:`展开其余 ${t.length-5} 项`]})]})]},e.label)})}),M&&(0,z.jsx)(Y,{project:o,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`))}}),x&&(0,z.jsx)(Q,{task:x,onClose:()=>T(void 0),onSaved:()=>{T(void 0),b.reload()}},x.id)]})}function K({memberId:e}){let{api:t,projectId:r}=C(),i=n(t.devices,!0),a=c();if(!i.data||!a.data||i.error||a.error)return null;let o=(0,R.default)(a.data.version),[l]=i.data.devices.filter(t=>t.memberId===e&&t.bound).map(e=>(0,R.default)(e.status?.clientVersion)).filter(e=>e!==null).sort((e,t)=>e.compare(t));if(!l||!o||l.compare(o)>=0)return null;let u=a.data.versions.filter(e=>{let t=(0,R.default)(e);return t&&(!t.prerelease.length||e===o.raw)&&t.compare(l)>0&&t.compare(o)<=0}).length;return(0,z.jsx)(`p`,{className:`task-board-update${u>5?` overdue`:``}`,children:(0,z.jsxs)(`a`,{href:s(r,`settings/client-maintenance.md`,`#升级与修复`),onClick:U,children:[(0,z.jsx)(d,{name:`attention`,size:`small`}),(0,z.jsxs)(`span`,{children:[`客户端待更新 `,l.raw,` → `,o.raw]})]})})}function q({task:e,number:n,memberIds:a,onEdit:o,onSaved:s,now:c}){let{request:l}=C(),u=r(),[f,p]=(0,L.useState)(!1),m=t();async function h(){if(!f){p(!0),m(``);try{await l(`tasks/${e.id}/correction`,T,{method:`PATCH`,signal:u,body:{needsConfirmation:!1,expectedRevision:e.revision}}),u.aborted||s()}catch(e){u.aborted||m(i(e))}finally{p(!1)}}}return(0,z.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,z.jsxs)(`summary`,{className:`task-card-heading`,"data-testid":`task-toggle`,children:[(0,z.jsxs)(`h3`,{children:[n!==void 0&&(0,z.jsxs)(`span`,{className:`task-card-number`,children:[`#`,n]}),(0,z.jsx)(`span`,{className:`task-card-title`,children:e.title})]}),(0,z.jsxs)(`span`,{className:`task-card-meta`,children:[(0,z.jsx)(`small`,{title:e.owner,children:e.owner}),e.needsConfirmation&&(0,z.jsxs)(`span`,{className:`task-confirmation`,"data-testid":`task-confirmation`,children:[(0,z.jsx)(d,{name:`attention`,size:`small`}),`需要确认`]}),e.status!==`completed`&&(0,z.jsx)(X,{since:e.statusSince,now:c})]})]}),(0,z.jsx)(g,{icon:`edit`,className:`task-card-edit`,label:`纠正任务:${e.title}`,"data-testid":`task-correct`,disabled:f,onClick:o}),(0,z.jsxs)(`div`,{className:`task-card-details`,children:[(0,z.jsx)(J,{task:e,memberIds:a}),e.needsConfirmation&&(0,z.jsx)(`div`,{className:`task-card-confirm`,children:(0,z.jsx)(`button`,{className:`primary`,"data-testid":`task-confirm-save`,disabled:f,onClick:()=>void h(),children:f?`正在保存…`:`保存`})})]})]})}function J({task:n,memberIds:r}){let{projectId:i}=C(),[a,o]=(0,L.useState)(``),s=t();return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`h4`,{children:`目标`}),(0,z.jsx)(`p`,{children:n.goal?(0,z.jsx)(Z,{value:n.goal,memberIds:r}):`目标未明确`}),(0,z.jsx)(`h4`,{children:`当前进展`}),(0,z.jsx)(`p`,{className:`task-progress`,children:(0,z.jsx)(Z,{value:n.progress,memberIds:r})}),(0,z.jsx)(`div`,{className:`task-card-sources`,children:n.sources.map(t=>(0,z.jsxs)(`a`,{"data-testid":`task-source`,href:e(t.kind===`material`?`/projects/${i}/materials?id=${t.materialId}&revision=${t.revision}`:O(i,n.owner,t.path)),children:[(0,z.jsx)(d,{name:`file`,size:`small`}),(0,z.jsx)(`span`,{children:t.path})]},t.path))}),(0,z.jsxs)(`div`,{className:`task-card-footer`,children:[n.syncedAt&&(0,z.jsxs)(`small`,{children:[`资料同步于 `,(0,z.jsx)(l,{value:n.syncedAt})]}),(0,z.jsx)(`span`,{role:`status`,children:a}),(0,z.jsx)(g,{icon:`link`,label:`复制任务链接`,onBlur:()=>o(``),onClick:async()=>{s(``);try{await x(new URL(e(D(i,n.id)),location.origin).href),o(`已复制`)}catch{o(``),s(`未能复制任务链接,请重试。`)}}})]})]})}function Y({project:e,id:t,memberIds:n,onClose:r}){let i=E(e,t,!0),{data:a,error:o}=i;return(0,z.jsxs)(f,{id:`shared-task`,title:a?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`span`,{className:`task-card-number`,children:[`#`,a.number]}),` `,a.task.title]}):`任务`,onClose:r,children:[(0,z.jsx)(S,{resource:i}),a?(0,z.jsxs)(`div`,{className:`task-card-details`,children:[(0,z.jsxs)(`small`,{children:[a.task.owner,` · `,W.find(e=>e.status===a.task.status)?.label,!a.active&&` · 已归档`]}),(0,z.jsx)(J,{task:a.task,memberIds:n},t)]}):!o&&(0,z.jsx)(`p`,{role:`status`,children:`读取中…`})]})}function X({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,z.jsxs)(`span`,{className:`task-age${n>6048e5?` stale`:``}`,"data-testid":`task-age`,title:`进入当前状态:${new Date(e).toLocaleString(`zh-CN`)}`,"aria-label":`当前状态停留 ${i}`,children:[(0,z.jsx)(d,{name:`clock`,size:`small`}),i]})}function Z({value:e,memberIds:t}){return e.split(/(@[a-z][a-z0-9_-]*)/gi).map((e,n)=>e.startsWith(`@`)&&t.has(e.slice(1))?(0,z.jsx)(`mark`,{className:`task-mention`,children:e},n):e)}function Q({task:e,onClose:n,onSaved:a}){let{request:o}=C(),s=r(),[c,l]=(0,L.useState)(e.title),[u,d]=(0,L.useState)(e.status??``),[p,m]=(0,L.useState)(e.goal??``),[h,g]=(0,L.useState)(e.progress),[_,v]=(0,L.useState)(!1),b=t(),x={...c===e.title?{}:{title:c},...u===(e.status??``)?{}:{status:u||null},...p===(e.goal??``)?{}:{goal:p||null},...h===e.progress?{}:{progress:h},...e.needsConfirmation?{needsConfirmation:!1}:{}};async function S(){if(!_&&Object.keys(x).length){v(!0),b(``);try{await o(`tasks/${e.id}/correction`,T,{method:`PATCH`,signal:s,body:{...x,expectedRevision:e.revision}}),s.aborted||a()}catch(e){s.aborted||b(i(e))}finally{v(!1)}}}return(0,z.jsx)(f,{id:`task-correction`,title:`纠正任务`,onClose:n,children:(0,z.jsxs)(`form`,{className:`stack`,"aria-busy":_,onSubmit:e=>{e.preventDefault(),S()},children:[(0,z.jsx)(y,{id:`task-title`,label:`标题`,children:(0,z.jsx)(`input`,{value:c,required:!0,onChange:e=>l(e.target.value)})}),(0,z.jsxs)(`fieldset`,{className:`task-status-field`,disabled:_,children:[(0,z.jsx)(`legend`,{children:`状态`}),(0,z.jsx)(`div`,{className:`task-status-options`,"data-testid":`task-status`,children:W.filter(e=>e.status!==null).map(e=>(0,z.jsxs)(`label`,{className:`task-status-choice`,children:[(0,z.jsx)(`input`,{type:`radio`,name:`task-status`,value:e.status,checked:u===e.status,onChange:()=>d(e.status)}),(0,z.jsx)(`span`,{children:e.label})]},e.status))}),(0,z.jsx)(`small`,{children:`待验收:任务成果已提交,等待验收或最终确认。`})]}),(0,z.jsx)(y,{id:`task-goal`,label:`目标`,children:(0,z.jsx)(`textarea`,{value:p,onChange:e=>m(e.target.value)})}),(0,z.jsx)(y,{id:`task-progress`,label:`当前进展`,children:(0,z.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value)})}),(0,z.jsx)(`div`,{className:`row wrap`,children:(0,z.jsx)(`button`,{type:`submit`,className:`primary`,disabled:_||!Object.keys(x).length,"data-testid":`task-correction-save`,children:`保存`})})]})})}function $({members:e,config:t,memberId:n}){return(0,z.jsx)(G,{members:e,project:t,memberId:n})}export{$ as Dashboard};
@@ -1 +1 @@
1
- import{At as e,C as t,D as n,M as r,V as i,b as a,c as o,g as s,j as c,k as l,kt as u,l as d,o as f,ot as p,v as m}from"./Dropdown-DXEtBxVr.js";import{B as h,M as g,N as _,P as v}from"./index-Cr9kdjwc.js";import{r as y}from"./task-links-B7fExlHK.js";import{t as b}from"./Markdown-DGF8VSqv.js";import{a as x,i as S,l as C,n as w,o as T,s as E,t as D}from"./WorkspaceTree-CwGvdfr0.js";import{t as O}from"./file-links-Bo7XBz3i.js";var k=u(),A=c();function j(e,t){let n=t.split(`/`).slice(0,-1);return n.map((t,r)=>w(e,n.slice(0,r+1).join(`/`))).concat(w(e,``))}function M({members:o,onRefresh:s}){let{api:c,projectId:l}=h(),[u,g]=(0,k.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`owner`),n=p.safeParse(e.get(`path`));return t&&(E(t)||o.some(e=>e.id===t))&&n.success&&!T(n.data)?{owner:t,path:n.data}:void 0}),[b,C]=(0,k.useState)(()=>new Set(u?j(u.owner,u.path):[])),[M,F]=(0,k.useState)(()=>u?{...u,kind:`file`}:void 0),[I,L]=(0,k.useState)(0),R=t(),[z,B]=(0,k.useState)(()=>{let e=new URLSearchParams(location.search);return!u&&(e.has(`owner`)||e.has(`path`))?`文件链接不完整或目标已不可用。`:``}),V=(0,k.useCallback)(async e=>{if(u)try{return{owner:u.owner,...await c.file(u.owner,u.path,void 0,e)}}catch(e){throw e instanceof r&&e.code===`FILE_NOT_FOUND`?new r(e.code,`找不到这个文件,可能已被删除或移动。`,e.status):e}},[c,u?.owner,u?.path]),H=n(V),U=H.data?.owner===u?.owner&&H.data?.file.path===u?.path?H.data:void 0;function W(e,t){let n=t.split(`/`).filter(Boolean);C(t=>{let r=new Set(t);for(let t=0;t<=n.length;t++)r.add(w(e,n.slice(0,t).join(`/`)));return r})}function G(t,n){R(``),B(``),W(t,n.split(`/`).slice(0,-1).join(`/`)),g({owner:t,path:n}),F({owner:t,path:n,kind:`file`}),history.replaceState(null,``,e(y(l,t,n)))}function K(t){if(!u)return!1;R(``);let n=O(E(u.owner)?u.path:`${u.owner}/${u.path}`,t);if(!n)return!/^[a-z][a-z0-9+.-]*:/i.test(t)&&!t.startsWith(`//`)&&(R(`该链接超出工作区,请在原仓库查看。`),!0);if(T(n.path))return R(`配置文件不在文件浏览中显示。`),!0;if(x(n.path))return location.assign(e(`/projects/${l}/memory`)),!0;let[r,...i]=n.path.split(`/`),a=o.some(e=>e.id===r),s=a?r:S,c=a?i.join(`/`):n.path;return B(``),n.directory?(W(s,c),F({owner:s,path:c,kind:`directory`})):s===u.owner&&c===u.path?n.anchor&&[...document.querySelectorAll(`.markdown h1,.markdown h2,.markdown h3,.markdown h4`)].find(e=>e.textContent?.trim().toLowerCase().replace(/\s+/g,`-`)===n.anchor.toLowerCase())?.scrollIntoView({block:`center`}):G(s,c),!0}return(0,A.jsx)(_,{"data-testid":`file-browser`,label:`文件资源管理器`,navigation:(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(v,{title:`工作区`,children:(0,A.jsx)(d,{icon:`refresh`,label:`刷新文件`,"data-testid":`files-refresh`,onClick:()=>{B(``),L(e=>e+1),H.reload(),s()}})}),(0,A.jsx)(D,{members:o,expanded:b,selected:M,revealed:!H.loading&&!H.error&&U?{owner:U.owner,path:U.file.path,file:U.file}:void 0,onSelect:G,onToggle:(e,t)=>{F({owner:e,path:t,kind:`directory`}),C(n=>{let r=new Set(n),i=w(e,t);return r.has(i)?r.delete(i):r.add(i),r})}},I)]}),children:(0,A.jsxs)(`section`,{className:`file-detail`,"data-testid":`file-preview`,"data-owner-id":u?.owner,"data-file-path":u?.path,"aria-label":i.filePreview,children:[U&&(0,A.jsx)(a,{message:H.error}),U?(0,A.jsx)(P,{owner:U.owner,file:U.file,onLink:K},`${U.owner}:${U.file.path}:${U.file.sha256}`):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(N,{target:u}),(0,A.jsxs)(`div`,{className:`reader-body`,children:[(0,A.jsx)(m,{announce:!0,retry:H.error?H.reload:void 0,children:z||H.error}),u&&H.loading&&(0,A.jsx)(`p`,{className:`preview-body`,role:`status`,children:i.loading}),!u&&!z&&(0,A.jsx)(f,{mascot:!0,title:`查看工作区文件`,description:i.pickFile})]})]})]})})}function N({target:e,children:t}){let n=e&&(E(e.owner)?`teamcontext`:e.owner);return(0,A.jsx)(g,{title:e?(0,A.jsxs)(`h2`,{className:`file-detail-path`,title:`${n}/${e.path}`,children:[(0,A.jsxs)(`span`,{children:[n,` / `]}),e.path]}):i.filePreview,actions:t})}function P({owner:e,file:t,onLink:r}){let{readTextBlob:c,blobUrl:u,projectId:f}=h(),[p,g]=(0,k.useState)(!1),_=t.size>524288,v=/\.(md|markdown)$/i.test(t.path),y=/\.html?$/i.test(t.path),x=(0,k.useCallback)(e=>_?Promise.resolve(void 0):c(t,e),[t.sha256,t.size,_]),S=n(x,!1,l(f,`file-body`,t.sha256));return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(N,{target:{owner:e,path:t.path},children:(0,A.jsxs)(s,{label:`文件操作`,children:[(v||y)&&(0,A.jsx)(d,{icon:p?`preview`:`code`,label:p?`切换为预览`:`切换为原文`,"data-testid":`file-toggle-raw`,"aria-pressed":p,onClick:()=>g(!p)}),(0,A.jsx)(`a`,{className:`icon-button`,"data-testid":`file-download`,"aria-label":i.download,title:i.download,href:u(t.sha256),download:t.path.split(`/`).at(-1),children:(0,A.jsx)(o,{name:`download`})})]})}),(0,A.jsxs)(`div`,{className:`reader-body`,children:[S.data!==void 0&&(0,A.jsx)(a,{message:S.error}),_?(0,A.jsx)(`div`,{className:`empty`,children:(0,A.jsx)(`p`,{children:i.previewLarge})}):S.error&&S.data===void 0?(0,A.jsx)(`div`,{className:`preview-body`,children:(0,A.jsx)(m,{announce:!0,retry:S.reload,children:S.error})}):S.loading&&S.data===void 0?(0,A.jsx)(`p`,{className:`preview-body`,role:`status`,children:i.loading}):(0,A.jsx)(`div`,{className:`preview-body${y&&!p?` preview-body-html`:``}`,children:y&&!p?(0,A.jsx)(C,{url:u(t.sha256),name:t.path.split(`/`).at(-1)}):v&&!p?(0,A.jsx)(`article`,{className:`markdown`,"data-testid":`file-content`,"data-format":`markdown`,children:(0,A.jsx)(b,{onLink:r,children:S.data??``})}):(0,A.jsx)(`pre`,{className:`raw`,"data-testid":`file-content`,"data-format":`text`,children:S.data})})]})]})}export{M as Files};
1
+ import{At as e,C as t,D as n,M as r,V as i,b as a,c as o,g as s,j as c,k as l,kt as u,l as d,o as f,ot as p,v as m}from"./Dropdown-DXEtBxVr.js";import{B as h,M as g,N as _,P as v}from"./index-Rry2cw7w.js";import{r as y}from"./task-links-BJwIQ3SE.js";import{t as b}from"./Markdown-nuwEQZ64.js";import{a as x,i as S,l as C,n as w,o as T,s as E,t as D}from"./WorkspaceTree-DmSApj8i.js";import{t as O}from"./file-links-Bo7XBz3i.js";var k=u(),A=c();function j(e,t){let n=t.split(`/`).slice(0,-1);return n.map((t,r)=>w(e,n.slice(0,r+1).join(`/`))).concat(w(e,``))}function M({members:o,onRefresh:s}){let{api:c,projectId:l}=h(),[u,g]=(0,k.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`owner`),n=p.safeParse(e.get(`path`));return t&&(E(t)||o.some(e=>e.id===t))&&n.success&&!T(n.data)?{owner:t,path:n.data}:void 0}),[b,C]=(0,k.useState)(()=>new Set(u?j(u.owner,u.path):[])),[M,F]=(0,k.useState)(()=>u?{...u,kind:`file`}:void 0),[I,L]=(0,k.useState)(0),R=t(),[z,B]=(0,k.useState)(()=>{let e=new URLSearchParams(location.search);return!u&&(e.has(`owner`)||e.has(`path`))?`文件链接不完整或目标已不可用。`:``}),V=(0,k.useCallback)(async e=>{if(u)try{return{owner:u.owner,...await c.file(u.owner,u.path,void 0,e)}}catch(e){throw e instanceof r&&e.code===`FILE_NOT_FOUND`?new r(e.code,`找不到这个文件,可能已被删除或移动。`,e.status):e}},[c,u?.owner,u?.path]),H=n(V),U=H.data?.owner===u?.owner&&H.data?.file.path===u?.path?H.data:void 0;function W(e,t){let n=t.split(`/`).filter(Boolean);C(t=>{let r=new Set(t);for(let t=0;t<=n.length;t++)r.add(w(e,n.slice(0,t).join(`/`)));return r})}function G(t,n){R(``),B(``),W(t,n.split(`/`).slice(0,-1).join(`/`)),g({owner:t,path:n}),F({owner:t,path:n,kind:`file`}),history.replaceState(null,``,e(y(l,t,n)))}function K(t){if(!u)return!1;R(``);let n=O(E(u.owner)?u.path:`${u.owner}/${u.path}`,t);if(!n)return!/^[a-z][a-z0-9+.-]*:/i.test(t)&&!t.startsWith(`//`)&&(R(`该链接超出工作区,请在原仓库查看。`),!0);if(T(n.path))return R(`配置文件不在文件浏览中显示。`),!0;if(x(n.path))return location.assign(e(`/projects/${l}/memory`)),!0;let[r,...i]=n.path.split(`/`),a=o.some(e=>e.id===r),s=a?r:S,c=a?i.join(`/`):n.path;return B(``),n.directory?(W(s,c),F({owner:s,path:c,kind:`directory`})):s===u.owner&&c===u.path?n.anchor&&[...document.querySelectorAll(`.markdown h1,.markdown h2,.markdown h3,.markdown h4`)].find(e=>e.textContent?.trim().toLowerCase().replace(/\s+/g,`-`)===n.anchor.toLowerCase())?.scrollIntoView({block:`center`}):G(s,c),!0}return(0,A.jsx)(_,{"data-testid":`file-browser`,label:`文件资源管理器`,navigation:(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(v,{title:`工作区`,children:(0,A.jsx)(d,{icon:`refresh`,label:`刷新文件`,"data-testid":`files-refresh`,onClick:()=>{B(``),L(e=>e+1),H.reload(),s()}})}),(0,A.jsx)(D,{members:o,expanded:b,selected:M,revealed:!H.loading&&!H.error&&U?{owner:U.owner,path:U.file.path,file:U.file}:void 0,onSelect:G,onToggle:(e,t)=>{F({owner:e,path:t,kind:`directory`}),C(n=>{let r=new Set(n),i=w(e,t);return r.has(i)?r.delete(i):r.add(i),r})}},I)]}),children:(0,A.jsxs)(`section`,{className:`file-detail`,"data-testid":`file-preview`,"data-owner-id":u?.owner,"data-file-path":u?.path,"aria-label":i.filePreview,children:[U&&(0,A.jsx)(a,{message:H.error}),U?(0,A.jsx)(P,{owner:U.owner,file:U.file,onLink:K},`${U.owner}:${U.file.path}:${U.file.sha256}`):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(N,{target:u}),(0,A.jsxs)(`div`,{className:`reader-body`,children:[(0,A.jsx)(m,{announce:!0,retry:H.error?H.reload:void 0,children:z||H.error}),u&&H.loading&&(0,A.jsx)(`p`,{className:`preview-body`,role:`status`,children:i.loading}),!u&&!z&&(0,A.jsx)(f,{mascot:!0,title:`查看工作区文件`,description:i.pickFile})]})]})]})})}function N({target:e,children:t}){let n=e&&(E(e.owner)?`teamcontext`:e.owner);return(0,A.jsx)(g,{title:e?(0,A.jsxs)(`h2`,{className:`file-detail-path`,title:`${n}/${e.path}`,children:[(0,A.jsxs)(`span`,{children:[n,` / `]}),e.path]}):i.filePreview,actions:t})}function P({owner:e,file:t,onLink:r}){let{readTextBlob:c,blobUrl:u,projectId:f}=h(),[p,g]=(0,k.useState)(!1),_=t.size>524288,v=/\.(md|markdown)$/i.test(t.path),y=/\.html?$/i.test(t.path),x=(0,k.useCallback)(e=>_?Promise.resolve(void 0):c(t,e),[t.sha256,t.size,_]),S=n(x,!1,l(f,`file-body`,t.sha256));return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(N,{target:{owner:e,path:t.path},children:(0,A.jsxs)(s,{label:`文件操作`,children:[(v||y)&&(0,A.jsx)(d,{icon:p?`preview`:`code`,label:p?`切换为预览`:`切换为原文`,"data-testid":`file-toggle-raw`,"aria-pressed":p,onClick:()=>g(!p)}),(0,A.jsx)(`a`,{className:`icon-button`,"data-testid":`file-download`,"aria-label":i.download,title:i.download,href:u(t.sha256),download:t.path.split(`/`).at(-1),children:(0,A.jsx)(o,{name:`download`})})]})}),(0,A.jsxs)(`div`,{className:`reader-body`,children:[S.data!==void 0&&(0,A.jsx)(a,{message:S.error}),_?(0,A.jsx)(`div`,{className:`empty`,children:(0,A.jsx)(`p`,{children:i.previewLarge})}):S.error&&S.data===void 0?(0,A.jsx)(`div`,{className:`preview-body`,children:(0,A.jsx)(m,{announce:!0,retry:S.reload,children:S.error})}):S.loading&&S.data===void 0?(0,A.jsx)(`p`,{className:`preview-body`,role:`status`,children:i.loading}):(0,A.jsx)(`div`,{className:`preview-body${y&&!p?` preview-body-html`:``}`,children:y&&!p?(0,A.jsx)(C,{url:u(t.sha256),name:t.path.split(`/`).at(-1)}):v&&!p?(0,A.jsx)(`article`,{className:`markdown`,"data-testid":`file-content`,"data-format":`markdown`,children:(0,A.jsx)(b,{onLink:r,children:S.data??``})}):(0,A.jsx)(`pre`,{className:`raw`,"data-testid":`file-content`,"data-format":`text`,children:S.data})})]})]})}export{M as Files};