@teammy/server 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +1 -1
  2. package/dist/main.js +3285 -1855
  3. package/dist/runtime/shared/tools.json +1 -1
  4. package/dist/runtime/workflows/task-bootstrap/prompt.md +3 -3
  5. package/dist/web/assets/Assistant-DUNdPkOm.js +1 -0
  6. package/dist/web/assets/Computers-BDZ0gAvQ.js +3 -0
  7. package/dist/web/assets/Computers-Dc45R6Gl.css +1 -0
  8. package/dist/web/assets/{Conversation-B-uSxDxY.css → Conversation-CNmGkVy7.css} +1 -1
  9. package/dist/web/assets/{Conversation-CZ8mOF1T.js → Conversation-DF1cdAgS.js} +1 -1
  10. package/dist/web/assets/Dashboard-D3aSwRnd.js +1 -0
  11. package/dist/web/assets/Files-iHjpLSD-.js +1 -0
  12. package/dist/web/assets/{Help-DGI26Qe5.js → Help-Xc5lgpqr.js} +106 -113
  13. package/dist/web/assets/{HtmlPreview-TOlZ7wbO.js → HtmlPreview-DUPprW5l.js} +1 -1
  14. package/dist/web/assets/{Markdown-Drn0H2RJ.js → Markdown-BF2STz99.js} +4 -4
  15. package/dist/web/assets/{MessageComposer-SftlQB1e.js → MessageComposer-CcA3P4oJ.js} +1 -1
  16. package/dist/web/assets/ResourceLibrary-DfE9icSj.js +6 -0
  17. package/dist/web/assets/WorkspaceTree-Bg3hPNzQ.js +1 -0
  18. package/dist/web/assets/{file-links-BYBi3BDP.js → file-links-DWut-bRr.js} +1 -1
  19. package/dist/web/assets/index-BQV0j0VG.js +66 -0
  20. package/dist/web/downloads/teammy-skill.zip +0 -0
  21. package/dist/web/index.html +1 -1
  22. package/package.json +1 -1
  23. package/dist/web/assets/Assistant-ZM9at-n8.js +0 -1
  24. package/dist/web/assets/Computers-B9XbkIvb.css +0 -1
  25. package/dist/web/assets/Computers-CV-4FaxZ.js +0 -3
  26. package/dist/web/assets/Dashboard-wZpQ1Qxb.js +0 -1
  27. package/dist/web/assets/Files-DD-tWR-r.js +0 -1
  28. package/dist/web/assets/ResourceLibrary-RyTep8PC.js +0 -6
  29. package/dist/web/assets/WorkspaceTree-BEiahyEL.js +0 -1
  30. package/dist/web/assets/index-BQicHl1a.js +0 -66
Binary file
@@ -6,7 +6,7 @@
6
6
  <meta name="theme-color" content="#161615" />
7
7
  <title>Teammy 工作台</title>
8
8
  <link rel="icon" type="image/png" href="./assets/teammy-favicon-BiDvlPj2.png" />
9
- <script type="module" crossorigin src="./assets/index-BQicHl1a.js"></script>
9
+ <script type="module" crossorigin src="./assets/index-BQV0j0VG.js"></script>
10
10
  <link rel="stylesheet" crossorigin href="./assets/index-6PvvMCD7.css">
11
11
  </head>
12
12
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teammy/server",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "The centralized Teammy collaboration hub server.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +0,0 @@
1
- import{F as e,G as t,H as n,I as r,J as i,K as ee,L as a,N as o,P as s,U as c,W as l,_t as u,a as te,dt as d,g as f,i as ne,lt as p,n as m,o as h,ot as g,pt as re,r as ie,st as _,t as ae,ut as v,vt as oe,y as se}from"./index-BQicHl1a.js";import{t as y}from"./Markdown-Drn0H2RJ.js";import{a as ce,i as le,n as ue,r as de,t as fe}from"./Conversation-CZ8mOF1T.js";import{t as pe}from"./MessageComposer-SftlQB1e.js";var b=u(),x=t(),me=v({topics:g(v({id:d(),title:d(),summary:d(),author:d(),replies:p(),unread:_(),createdAt:d(),updatedAt:d(),delivery:v({available:_(),connected:_(),state:d(),error:d().nullable()})}))}),he=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),S=e=>e.replace(/[#*_`>]/g,``).replace(/\s+/g,` `).trim();function C({me:t,mode:u=`messages`}){let{projectId:p,request:g}=se(),C=l(),_e=c(p,t,`${u}-selection`),w=c(p,t,`${u}-drafts`),ve=(0,b.useCallback)(e=>g(`agents/outbox`,te,{signal:e}),[g]),T=n(ve,3e3,c(p,t,`outbox`)),ye=(0,b.useCallback)(async e=>u===`messages`?g(`agents/chats`,ae,{signal:e}):{chats:(await g(`channels/topics`,me,{signal:e})).topics.map(e=>({...e,kind:`matter`,state:null}))},[g,u]),E=n(ye,3e3,c(p,t,u,`chats`)),[D,be]=(0,b.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`chat`);return t?`chat:${t}`:e.get(`message`)??C?.get(_e)??``}),O=D.startsWith(`chat:`)?D.slice(5):``,k=!D||!!O,[A,j]=(0,b.useState)(()=>C?.get(c(p,t,`chat`,O))),M=A?.id===O?A:C?.get(c(p,t,`chat`,O)),N=E.data?.chats.find(e=>e.id===O),P=N&&`delivery`in N?N.delivery:void 0,[xe,F]=(0,b.useState)(),[I,L]=(0,b.useState)(()=>C?.get(w)??{}),Se=I[D]??``,Ce=e=>L(t=>({...t,[D]:e})),[R,z]=(0,b.useState)(!1),[B,we]=(0,b.useState)(!1),[Te,V]=(0,b.useState)(!1),[H,Ee]=(0,b.useState)(``),[De,Oe]=(0,b.useState)(``),ke=(0,b.useRef)(crypto.randomUUID()),[Ae,U]=(0,b.useState)(``),[je,W]=(0,b.useState)(``),G=(0,b.useRef)(new Map),Me=(0,b.useRef)(null),K=(0,b.useRef)(!0),q=(0,b.useRef)(D);q.current=D,(0,b.useEffect)(()=>{A&&C?.set(c(p,t,`chat`,A.id),A)},[C,p,t,A]),(0,b.useEffect)(()=>{C?.set(w,I)},[C,w,I]);function J(e){q.current=e,be(e),C?.set(_e,e);let t=new URL(location.href);e.startsWith(`chat:`)?t.searchParams.set(`chat`,e.slice(5)):t.searchParams.delete(`chat`),e&&!e.startsWith(`chat:`)&&e!==`debug`?t.searchParams.set(`message`,e):t.searchParams.delete(`message`),history.replaceState(history.state,``,t)}(0,b.useEffect)(()=>{!D&&E.data?.chats.length&&J(`chat:${E.data.chats[0].id}`)},[D,E.data]);let Y=(T.data?.messages??[]).filter(e=>u===`messages`&&e.box===`debug`).reverse(),X=T.data?.messages.find(e=>e.id===(D===`debug`?xe:D));(0,b.useEffect)(()=>{D!==`debug`&&X?.conversationId&&J(`chat:${X.conversationId}`)},[D,X?.conversationId]);let Z=Y.filter(e=>!e.readAt).map(e=>e.id).join(`,`);(0,b.useEffect)(()=>{X&&!X.readAt&&D!==`debug`&&g(`agents/outbox/${X.id}/read`,h,{method:`POST`}).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),T.reload()}).catch(e=>U(i(e)))},[X?.id,X?.readAt,D,g,T.reload]),(0,b.useEffect)(()=>{D===`debug`&&Z&&Promise.all(Z.split(`,`).map(e=>g(`agents/outbox/${e}/read`,h,{method:`POST`}))).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),T.reload()}).catch(e=>U(i(e)))},[D,Z,g,T.reload]),(0,b.useEffect)(()=>{if(W(``),!O)return;let e=!0,n=-1,r=!1,a=new AbortController,o=t=>{!e||t.id!==O||t.cursor<n||(n=t.cursor,r=!0,t.redirect?J(`chat:${t.redirect}`):t.entry===`channel`&&u!==`channels`?location.replace(oe(`/projects/${p}/channels?chat=${t.id}`)):(j(t),W(``)))};g(`agents/chats/${O}`,m,{signal:a.signal}).then(o).catch(n=>{e&&!a.signal.aborted&&(n instanceof ee&&[401,403,404].includes(n.status)&&(C?.delete(c(p,t,`chat`,O)),j(e=>e?.id===O?void 0:e)),r||W(i(n)))});let s=t=>{let r=Number(t.lastEventId);return!e||!Number.isSafeInteger(r)||r<=n?!1:(n=r,!0)},l=new EventSource(oe(`/api/v1/projects/${encodeURIComponent(p)}/agents/chats/${encodeURIComponent(O)}/events`));l.addEventListener(`snapshot`,t=>{if(e)try{o(m.parse(JSON.parse(t.data)))}catch(e){W(i(e))}}),l.onerror=()=>{e&&W(`对话连接中断,正在重新连接…`)},l.addEventListener(`context`,e=>{if(!s(e))return;let t=m.pick({kind:!0,title:!0,status:!0,visibility:!0,participants:!0,pending:!0,hold:!0,redirect:!0}).parse(JSON.parse(e.data));t.redirect?J(`chat:${t.redirect}`):j(e=>e?.id===O?{...e,...t,cursor:n}:e)}),l.addEventListener(`message`,e=>{if(!s(e))return;let t=ie.parse(JSON.parse(e.data));j(n=>n?.id===O?{...n,readCursor:Math.max(n.readCursor,t.seq),cursor:Math.max(n.cursor,Number(e.lastEventId)||0),messages:[...n.messages.filter(e=>e.id!==t.id),t].sort((e,t)=>e.seq-t.seq)}:n)}),l.addEventListener(`message_removed`,e=>{if(!s(e))return;let{id:t}=v({id:d()}).parse(JSON.parse(e.data));j(e=>e?.id===O?{...e,cursor:n,messages:e.messages.filter(e=>e.id!==t)}:e)}),l.addEventListener(`run`,e=>{if(!s(e))return;let t=ne.parse(JSON.parse(e.data));j(n=>n?.id===O?{...n,cursor:Math.max(n.cursor,Number(e.lastEventId)||0),runs:n.runs.some(e=>e.id===t.id)?n.runs:[...n.runs,t]}:n)});for(let e of[`delta`,`reset`,`state`])l.addEventListener(e,t=>{if(!s(t))return;let n=JSON.parse(t.data);j(r=>r?.id===O?{...r,cursor:Math.max(r.cursor,Number(t.lastEventId)||0),messages:r.messages.map(t=>t.runId!==n.id||t.role!==`assistant`?t:{...t,body:e===`delta`?t.body+(n.text??``):e===`reset`?``:n.answer??t.body,state:n.state??t.state}),runs:r.runs.map(t=>t.id===n.id?{...t,answer:e===`delta`?t.answer+(n.text??``):e===`reset`?``:n.answer??t.answer,state:n.state??t.state,error:n.error===void 0?t.error:n.error}:t)}:r)});return()=>{e=!1,a.abort(),l.close()}},[p,O,t,g,C]),(0,b.useEffect)(()=>{if(!M||M.id!==O)return;let e=()=>{document.visibilityState===`visible`&&g(`agents/chats/${O}/read`,v({ok:_()}),{method:`POST`,body:{cursor:M.readCursor}}).then(()=>{E.reload(),window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>U(i(e)))},t=setTimeout(e,300);return document.addEventListener(`visibilitychange`,e),()=>{clearTimeout(t),document.removeEventListener(`visibilitychange`,e)}},[O,M?.readCursor,M?.kind,g]),(0,b.useEffect)(()=>{K.current&&Me.current?.scrollIntoView({block:`end`})},[D,A?.messages,X?.recipients,Y.length]);function Ne(){window.dispatchEvent(new Event(`teammy:outbox`)),T.reload()}async function Q(e){if(K.current=!0,J(e),U(``),F(void 0),e.startsWith(`chat:`)||e===`debug`)return;let t=T.data?.messages.find(t=>t.id===e)?.conversationId;if(t)J(`chat:${t}`);else try{await g(`agents/outbox/${e}/read`,h,{method:`POST`}),Ne()}catch(e){U(i(e))}}async function Pe(){if(!B){we(!0),U(``);try{let e=await g(`agents/chats`,m,{method:`POST`});j(e),await Q(`chat:${e.id}`),E.reload()}catch(e){U(i(e))}finally{we(!1)}}}async function Fe(e){e.preventDefault();let t=Se.trim();if(!t||R||B)return;z(!0),U(``);let n=G.current.get(D);n&&n.text===t||(n={text:t,id:crypto.randomUUID()},G.current.set(D,n));try{if(k){let e=n.target??O;if(!e){let r=await g(`agents/chats`,m,{method:`POST`});e=r.id,n.target=e,G.current.set(`chat:${e}`,n),L(n=>({...n,[`chat:${e}`]:t})),q.current===D&&(j(r),J(`chat:${e}`))}let r=await g(`agents/chats/${e}`,ne.extend({conversationId:d().optional()}),{method:`POST`,body:{text:t,requestId:n.id}});r.conversationId&&r.conversationId!==e&&(q.current===D||q.current===`chat:${e}`)&&J(`chat:${r.conversationId}`),j(t=>t?.id===e?{...t,runs:t.runs.some(e=>e.id===r.id)?t.runs:[...t.runs,r]}:t),E.reload()}else{let e=await g(`agents/outbox/${X.id}/reply`,v({conversationId:d()}),{method:`POST`,body:{body:t,requestId:n.id}});Ne(),q.current===D&&J(`chat:${e.conversationId}`),E.reload(),F(void 0)}G.current.delete(D),n.target&&G.current.delete(`chat:${n.target}`),L(e=>({...e,[D]:``,...n.target?{[`chat:${n.target}`]:``}:{}}))}catch(e){U(i(e))}finally{z(!1)}}let Ie=u===`channels`?le:fe,Le=k&&!M?.closed&&(u!==`channels`||!!O)||!!X&&!X.archivedAt,$=k&&!M&&(!!O||!E.data);return(0,x.jsxs)(de,{className:u===`channels`?`channel-layout`:``,testId:`assistant-page`,label:k?`Tim对话`:`消息内容`,navigation:(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`header`,{className:`assistant-list-heading`,children:[(0,x.jsx)(`h1`,{children:u===`channels`?`频道`:`对话`}),(0,x.jsx)(s,{className:`assistant-new-chat`,icon:`plus`,label:u===`channels`?`发表话题`:`新建对话`,disabled:B,onClick:()=>u===`channels`?V(!0):void Pe(),"data-testid":`assistant-launcher`})]}),(0,x.jsxs)(`div`,{className:`assistant-message-scroll`,children:[E.loading&&!E.data&&(0,x.jsx)(`p`,{className:`assistant-list-status`,role:`status`,children:`加载中…`}),E.data?.chats.map(e=>(0,x.jsxs)(`button`,{type:`button`,"data-testid":`assistant-chat-${e.id}`,className:`assistant-message-item assistant-chat-item ${O===e.id?`selected`:``}`,"aria-pressed":O===e.id,onClick:()=>void Q(`chat:${e.id}`),children:[(0,x.jsx)(`span`,{className:`assistant-message-dot ${e.unread||e.state===`running`||e.state===`queued`?`unread`:``}`}),(0,x.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,x.jsx)(f,{selected:O===e.id,children:(0,x.jsx)(`strong`,{children:e.title})}),u===`channels`&&`summary`in e&&(0,x.jsx)(`span`,{className:`topic-preview`,children:S(String(e.summary)).slice(0,140)}),(0,x.jsxs)(`time`,{dateTime:e.updatedAt,children:[new Date(e.updatedAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,he(e.updatedAt)]})]})]},e.id)),!!Y.length&&(0,x.jsxs)(`button`,{type:`button`,"data-testid":`debug-outbox`,className:`assistant-message-item ${D===`debug`?`selected`:``}`,onClick:()=>void Q(`debug`),children:[(0,x.jsx)(`span`,{className:`assistant-message-dot ${Z?`unread`:``}`}),(0,x.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,x.jsx)(f,{selected:D===`debug`,children:(0,x.jsx)(`strong`,{children:`运行提醒`})}),(0,x.jsx)(`span`,{children:S(Y.at(-1).body)})]})]}),T.data?.messages.filter(e=>u===`messages`&&e.box!==`debug`&&!e.conversationId).sort((e,t)=>Number(!!e.archivedAt)-Number(!!t.archivedAt)).map(e=>(0,x.jsxs)(`button`,{type:`button`,"data-testid":`outbox-${e.id}`,className:`assistant-message-item ${e.archivedAt?`archived`:``} ${D===e.id?`selected`:``}`,onClick:()=>void Q(e.id),children:[(0,x.jsx)(`span`,{className:`assistant-message-dot ${e.readAt?``:`unread`}`}),(0,x.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,x.jsx)(f,{selected:D===e.id,children:(0,x.jsx)(`strong`,{children:S(e.body)})}),(0,x.jsxs)(`time`,{dateTime:e.createdAt,children:[new Date(e.createdAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,he(e.createdAt)]})]})]},e.id))]}),(0,x.jsx)(a,{error:!0,children:T.error||E.error})]}),children:[Te&&(0,x.jsxs)(r,{id:`new-topic`,title:`发表话题`,onClose:()=>V(!1),children:[(0,x.jsx)(pe,{inset:!0,plain:!0,value:De,onChange:Oe,label:`正文`,placeholder:`开始一个话题…`,sendLabel:`发表话题`,sendDisabled:R||!H.trim(),heading:(0,x.jsx)(`input`,{className:`topic-title`,"aria-label":`标题`,placeholder:`标题`,required:!0,value:H,onChange:e=>Ee(e.target.value)}),onSubmit:e=>{e.preventDefault(),z(!0),U(``),g(`channels/topics`,m,{method:`POST`,body:{id:ke.current,title:H,body:De}}).then(e=>{j(e),J(`chat:${e.id}`),V(!1),Ee(``),Oe(``),ke.current=crypto.randomUUID(),E.reload()}).catch(e=>U(i(e))).finally(()=>z(!1))}}),(0,x.jsx)(a,{error:!0,children:Ae})]}),(0,x.jsx)(ue,{title:(0,x.jsx)(`h2`,{children:k?N?.title??M?.title??(O?`无标题`:`Tim`):D===`debug`?`运行提醒`:`项目消息`}),actions:(0,x.jsxs)(x.Fragment,{children:[u!==`channels`&&M?.kind===`matter`&&(0,x.jsxs)(`span`,{className:`assistant-participants`,title:M.participants?.join(`、`),children:[M.visibility===`project`?`项目共享 · `:``,M.participants?.join(`、`)]}),u===`channels`&&P?.available&&(P.state===`web`||P.state===`cancelled`||!P.connected)&&(0,x.jsx)(s,{icon:`send`,label:`发布到企业微信频道`,disabled:R,onClick:()=>{z(!0),g(`channels/topics/${O}/publish`,re(),{method:`POST`}).then(()=>E.reload()).catch(e=>U(i(e))).finally(()=>z(!1))}})]})}),u===`channels`&&(0,x.jsx)(a,{error:!0,children:P?.error}),u!==`channels`&&M?.kind===`matter`&&(M.hold||M.pending||M.status===`completed`)&&(0,x.jsx)(`div`,{className:`assistant-matter-state`,role:`status`,children:M.hold?`${M.hold.scope===`all`?`已暂停`:`暂缓修改`} · ${M.hold.reason}`:M.pending?`待确认 · ${M.pending.members.join(`、`)}:${M.pending.question}`:`已完成`}),(0,x.jsxs)(ce,{"data-testid":`assistant-transcript`,onScroll:e=>{let t=e.currentTarget;K.current=t.scrollHeight-t.scrollTop-t.clientHeight<100},children:[k?$?(0,x.jsxs)(`div`,{className:`assistant-empty`,"data-testid":`assistant-loading`,children:[(0,x.jsx)(e,{}),(0,x.jsx)(`p`,{role:`status`,children:je||E.error?`暂时无法加载对话`:`加载中…`})]}):M?.messages.length?M.messages.filter(e=>e.body||[`queued`,`running`,`failed`].includes(e.state)).map(e=>(0,x.jsx)(`div`,{className:`assistant-turn`,children:(0,x.jsxs)(Ie,{mine:e.role===`user`&&e.author===t,author:`${e.role===`assistant`?`Tim`:e.author}${e.source===`wecom`?` · 企业微信`:``}`,time:e.createdAt,children:[e.body&&(0,x.jsx)(`div`,{className:`markdown`,children:(0,x.jsx)(y,{children:e.body})}),e.role===`assistant`&&[`queued`,`running`].includes(e.state)&&(0,x.jsxs)(`span`,{className:`assistant-typing`,"aria-label":`正在回答`,children:[(0,x.jsx)(`i`,{}),(0,x.jsx)(`i`,{}),(0,x.jsx)(`i`,{})]}),e.state===`failed`&&(0,x.jsx)(a,{error:!0,children:M.runs.find(t=>t.id===e.runId)?.error||`本次回答未完成。`})]})},e.id)):(0,x.jsxs)(`div`,{className:`assistant-empty`,children:[(0,x.jsx)(e,{}),(0,x.jsx)(`p`,{children:`有什么项目问题想聊聊?`})]}):!T.data&&T.loading?(0,x.jsx)(`div`,{className:`assistant-empty`,children:(0,x.jsx)(`p`,{role:`status`,children:`加载中…`})}):D===`debug`?Y.map(e=>(0,x.jsx)(ge,{item:e,onReply:e.archivedAt?void 0:()=>{F(e.id),Ce(``),U(``)}},e.id)):X&&(0,x.jsx)(ge,{item:X}),(0,x.jsx)(`div`,{ref:Me})]}),(0,x.jsx)(a,{error:!0,children:Ae||(k?je:``)}),Le?(0,x.jsx)(pe,{value:Se,onChange:Ce,onSubmit:e=>void Fe(e),disabled:B,sendDisabled:R||$,label:k?`向Tim提问`:`回复消息`}):D!==`debug`&&X&&(0,x.jsxs)(`div`,{className:`assistant-archived`,children:[(0,x.jsx)(o,{name:`archive`}),`已归档`]})]})}function ge({item:e,onReply:t}){return(0,x.jsx)(`div`,{"data-testid":`outbox-thread-${e.id}`,children:(0,x.jsxs)(fe,{author:e.box===`debug`?`运行提醒`:`Tim`,time:e.createdAt,children:[(0,x.jsx)(`div`,{className:`markdown`,children:(0,x.jsx)(y,{children:e.body})}),t&&(0,x.jsx)(`button`,{type:`button`,className:`assistant-debug-reply`,onClick:t,children:`回复`})]})})}export{C as Assistant};
@@ -1 +0,0 @@
1
- .inline-reply{width:clamp(180px, var(--reply-width,180px), 600px);border:1px solid var(--color-line);border-radius:var(--radius-sm);background:0 0;align-items:flex-end;gap:4px;max-width:100%;padding:3px 6px;display:flex}.inline-reply:focus-within{border-color:var(--color-muted)}.inline-reply textarea{width:100%;min-width:0;min-height:28px;max-height:180px;font-size:var(--text-sm);resize:none;box-shadow:none;background:0 0;border:0;padding:3px 2px;line-height:22px}.inline-reply textarea:focus{box-shadow:none;outline:none}.inline-reply-send{background:0 0;border:0;flex:0 0 26px;place-items:center;width:26px;height:28px;min-height:28px;padding:3px;display:grid}.composer-menu .dropdown-trigger{height:30px;min-height:30px;font-size:var(--text-xs);color:var(--color-muted);background:var(--color-soft);border-radius:18px;align-items:center;gap:4px;max-width:min(190px,100%);padding:5px 9px;display:flex}.composer-menu .dropdown-trigger>span{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.composer-menu .dropdown-trigger:hover,.composer-menu .dropdown-trigger[aria-expanded=true]{color:var(--color-text);background:var(--color-hover)}.composer-commands .dropdown-trigger{background:var(--color-soft);border-radius:50%;justify-content:center;width:30px;padding:6px}.composer-menu .dropdown-menu{--dropdown-max-height:45dvh;width:300px;max-width:calc(100vw - var(--sidebar-width) - 32px);max-height:45dvh;top:auto;bottom:calc(100% + 12px)}.composer-menu .dropdown-menu [role=menuitem]{font-size:var(--text-sm);justify-content:space-between;gap:12px;padding:10px}.composer-option-copy{text-align:left;flex-direction:column;gap:3px;min-width:0;display:flex}.composer-option-copy small,.composer-menu-heading small{font-size:var(--text-xs);color:var(--color-muted);font-weight:400}.composer-menu code{color:var(--color-muted);background:0 0;font-size:11px}.composer-menu-heading{font-size:var(--text-sm);justify-content:space-between;gap:12px;padding:8px 10px;display:flex}@media (width<=600px){.composer-menu .dropdown-menu{width:calc(100vw - var(--sidebar-width) - 16px);max-width:none}.composer-menu .dropdown-trigger{max-width:min(140px,100%)}}.composer-choice{flex:0 auto;min-width:0}.composer-commands{flex-shrink:0}.composer-commands .icon{width:17px;height:17px}.composer-commands .dropdown-menu{width:640px}.composer-commands .dropdown-menu [role=menuitem]{padding:8px 10px}.composer-command-row{align-items:center;gap:20px;width:100%;min-width:0;display:flex}.composer-command-name{flex:0 190px;min-width:0}.composer-command-row small{min-width:0;color:var(--color-muted);font-weight:400;font-size:var(--text-xs);flex:1}.composer-command-row>*{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}@media (width<=600px){.composer-commands .dropdown-menu{width:calc(100vw - var(--sidebar-width) - 16px)}.composer-command-name{flex-basis:42%}.composer-command-row{gap:10px}}.composer-option-copy small{text-overflow:ellipsis;white-space:nowrap;max-width:260px;overflow:hidden}.computer-panel{border-bottom:1px solid var(--color-line);max-height:55vh;padding:16px 24px;overflow:auto}.config-fields{grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:12px;padding:12px 0;display:grid}.config-fields label{flex-direction:column;gap:6px;display:flex}.native-question,.native-question>div{min-width:0}.native-question>div+div{margin-top:12px}.native-question>div>:not(:first-child){margin-top:8px}.native-question p{color:var(--color-text);font-size:var(--text-base);margin:0}.question-response,.question-result{align-items:baseline;gap:6px;margin-top:8px;display:flex}.question-response span{white-space:pre-wrap;overflow-wrap:anywhere}.question-result{color:var(--color-muted);font-size:var(--text-xs)}.question-response .icon,.question-result .icon{width:12px;height:12px;color:var(--color-muted);flex-shrink:0}.question-bubble .assistant-bubble{width:max-content}.question-options button{min-height:32px;font-size:var(--text-sm);background:0 0;padding:6px 10px;font-weight:500}.question-options button[aria-pressed=true]{background:var(--color-accent-soft);color:var(--brand-orange)}.question-options,.question-actions{flex-wrap:wrap;gap:8px;display:flex}.native-question input{width:100%;margin-top:8px}.question-options button[aria-pressed=true]{border-color:var(--brand-orange)}.computer-control-status{margin:0;padding:4px 24px;font-size:12px}@media (width<=760px){.computer-panel{padding:12px}}.computer-tree{padding:4px}.computer-device{font-size:var(--text-sm);align-items:center;gap:8px;margin:0 0 14px;font-weight:600;display:flex}.computer-device>span{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.computer-connection{flex-shrink:0;display:inline-flex}.computer-connection.online .icon rect{fill:var(--brand-orange);fill-opacity:.85}.computer-paths{color:var(--color-muted);font-size:var(--text-xs);overflow-wrap:anywhere;margin:8px 0;display:block}.computer-tree .tree-name{flex:1}.computer-panel{flex-shrink:0}#computer-settings .computer-panel{border:0;max-height:70dvh;padding:0}.computer-create-menu .dropdown-trigger{place-items:center;width:32px;height:32px;padding:4px;display:grid}.computer-create-menu .dropdown-menu{width:180px;left:auto;right:0}.session-rename{font:inherit;font-weight:inherit;text-align:left;text-overflow:ellipsis;white-space:nowrap;background:0 0;border:0;border-radius:0;max-width:100%;padding:0;overflow:hidden}.session-rename:hover{color:var(--color-muted);background:0 0}.session-title-form{flex:1;min-width:0;margin-right:16px}.session-title-form input{width:100%}
@@ -1,3 +0,0 @@
1
- import{C as e,E as t,G as n,H as r,I as i,J as a,L as o,N as s,P as c,S as l,T as u,_t as d,b as f,d as p,dt as m,h,j as g,k as _,m as v,ot as y,pt as b,st as x,ut as S,v as C,vt as w,w as T,x as E,y as D}from"./index-BQicHl1a.js";import{t as O}from"./Markdown-Drn0H2RJ.js";import{a as ee,n as te,o as ne,r as re,t as ie}from"./Conversation-CZ8mOF1T.js";import{n as k,t as ae}from"./MessageComposer-SftlQB1e.js";import{r as oe}from"./WorkspaceTree-BEiahyEL.js";var A=d(),j=n();function M({disabled:e,onSend:t}){let[n,r]=(0,A.useState)(``),[i,a]=(0,A.useState)(!1),o=`其他回答`,c=(0,A.useRef)(null),l=(0,A.useCallback)(e=>{if(!c.current)return;let t=document.createElement(`canvas`).getContext(`2d`);if(!t)return;t.font=getComputedStyle(e).font;let r=Math.max(...(n||`${o}…`).split(`
2
- `).map(e=>t.measureText(e).width));c.current.style.setProperty(`--reply-width`,`${Math.ceil(r+(i?52:26))}px`)},[n,i,o]),u=k(n,l);return(0,j.jsxs)(`form`,{ref:c,className:`inline-reply${i?` active`:``}`,onFocus:()=>a(!0),onBlur:e=>{!n&&!e.currentTarget.contains(e.relatedTarget)&&a(!1)},onSubmit:i=>{i.preventDefault(),!e&&n.trim()&&t(n.trim()).then(e=>{e&&r(``)})},children:[(0,j.jsx)(`textarea`,{ref:u,rows:1,"aria-label":`自定义回答`,placeholder:`${o}…`,value:n,disabled:e,onChange:e=>r(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&!t.nativeEvent.isComposing&&(t.preventDefault(),!e&&n.trim()&&t.currentTarget.form?.requestSubmit())}}),i&&(0,j.jsx)(`button`,{className:`inline-reply-send`,type:`submit`,disabled:e||!n.trim(),"aria-label":`发送${o}`,title:`发送${o}`,children:(0,j.jsx)(s,{name:`send`,size:`small`})})]})}var N={minimal:`极低`,low:`低`,medium:`中`,high:`高`,xhigh:`极高`,max:`最高`,ultra:`极致`,none:`无`},P=[{value:`read-only`,label:`只读`,description:`读取文件,不修改代码`},{value:`workspace-write`,label:`工作区写入`,shortLabel:`工作区`,description:`可修改工作区,额外权限按需审批`},{value:`full-access`,label:`完整访问`,description:`可访问工作区之外,按需审批`}];function F({id:e,label:t,current:n,options:r,disabled:i,onSelect:a}){let o=r.find(e=>e.value===n);return(0,j.jsx)(v,{id:`${e}-menu`,triggerId:e,placement:`top`,className:`composer-menu composer-choice`,label:`选择${t}`,disabled:i,routeKey:n,trigger:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`span`,{title:`${t}:${o?.label??n}`,children:o?.shortLabel??o?.label??n}),(0,j.jsx)(s,{name:`chevronDown`,size:`small`})]}),children:e=>(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`composer-menu-heading`,children:t}),r.map(t=>(0,j.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-label":t.label,onClick:()=>{e(),a(t.value)},children:[(0,j.jsxs)(`span`,{className:`composer-option-copy`,children:[(0,j.jsx)(`span`,{children:t.label}),t.description&&(0,j.jsx)(`small`,{children:t.description})]}),t.value===n&&(0,j.jsx)(s,{name:`check`,size:`small`})]},t.value))]})})}function se({session:e,models:t,busy:n,available:r,online:i,commands:a,draft:o,onInsert:c,onConfig:l}){let[u,d]=(0,A.useState)(!1);(0,A.useEffect)(()=>{/^[/$]([^\s]*)$/.exec(o)?d(!0):d(!1)},[o]);let f=t.find(t=>t.id===(e.config.model??e.effectiveConfig?.model)),p=n||!r,m=t.find(e=>e.isDefault)?.id??(e.config.model?null:e.effectiveConfig?.model),h=t.find(e=>e.id===m)?.name??m,g=[{value:``,label:h?`默认 · ${h}`:`模型未获取`},...t.map(e=>({value:e.id,label:e.name}))];e.config.model&&!t.some(t=>t.id===e.config.model)&&g.push({value:e.config.model,label:e.config.model});let _=f?.id===e.effectiveConfig?.model?e.effectiveConfig?.effort:f?.defaultEffort,y=[{value:``,label:_?`默认 · ${N[_]??_}`:`默认强度`},...(f?.efforts??[]).map(e=>({value:e,label:N[e]??e}))];return e.config.effort&&!y.some(t=>t.value===e.config.effort)&&y.push({value:e.config.effort,label:N[e.config.effort]??e.config.effort}),(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(v,{id:`session-commands`,triggerId:`session-command-trigger`,label:`命令与 Skills`,placement:`top`,className:`composer-menu composer-commands`,routeKey:e.id,trigger:(0,j.jsx)(s,{name:`slash`,size:`small`}),open:u,onOpenChange:d,focusFirst:!1,disabled:p||!i,children:e=>(0,j.jsxs)(j.Fragment,{children:[[...a].sort((e,t)=>e.name.localeCompare(t.name,`en`)).map(t=>(0,j.jsx)(`button`,{type:`button`,role:`menuitem`,title:[t.description,t.path].filter(Boolean).join(`
3
- `),onClick:()=>{e(),c(t)},children:(0,j.jsxs)(`span`,{className:`composer-command-row`,children:[(0,j.jsxs)(`span`,{className:`composer-command-name`,children:[t.kind===`skill`?`$`:`/`,t.name]}),(0,j.jsx)(`small`,{children:t.description})]})},`${t.kind}:${t.path??t.name}`)),!a.length&&(0,j.jsx)(`div`,{className:`composer-menu-heading`,children:`尚未获取命令`})]})}),(0,j.jsx)(F,{id:`session-model`,label:`模型`,current:e.config.model??``,options:g,disabled:p,onSelect:n=>{let r=t.find(e=>e.id===n);l({...e.config,model:n||null,effort:e.config.effort&&r?.efforts.includes(e.config.effort)?e.config.effort:null})}}),(0,j.jsx)(F,{id:`session-effort`,label:`思考强度`,current:e.config.effort??``,options:y,disabled:p,onSelect:t=>l({...e.config,effort:t||null})}),(0,j.jsx)(F,{id:`session-permission`,label:`权限`,current:e.config.permission,options:P,disabled:p,onSelect:t=>l({...e.config,permission:t})})]})}var ce=S({taskRoot:m().nullable().default(null),online:x(),computer:S({id:m(),name:m(),platform:m()}).nullable(),capabilities:y(m()),models:y(u),catalogs:y(T).default([]),directories:y(f),sessions:y(e)}),le=S({ok:x()}),I={idle:`空闲`,working:`工作中`,waiting:`等待回答`,queued:`等待执行`,uncertain:`需要核对`,human:`人工处理`,offered:`待本地接收`,accepted:`本地已接手`,human_routed:`未送达本地`,pending:`待投递`,sent:`已发送`,succeeded:`已完成`,running:`进行中`,failed:`失败`};function ue(){let{request:e}=D(),t=(0,A.useCallback)(t=>e(`web/local-agent-settings`,E,{signal:t}),[e]),n=r(t,3e4);return n.error?(0,j.jsx)(o,{error:!0,children:n.error}):n.data?n.data.accessible?(0,j.jsx)(L,{}):(0,j.jsx)(g,{title:`本项目暂未向你开放本地 Agent 功能`}):null}function L(){let t=D(),[n,u]=(0,A.useState)(()=>new Set),[d,f]=(0,A.useState)(()=>({project:t.projectId,directory:new URLSearchParams(location.search).get(`directory`)??``,session:new URLSearchParams(location.search).get(`session`)??``})),[m,g]=(0,A.useState)(``),[y,x]=(0,A.useState)(!1),[S,T]=(0,A.useState)(!1),[E,k]=(0,A.useState)(!1),[M,N]=(0,A.useState)(``),[P,F]=(0,A.useState)(``),[ue,L]=(0,A.useState)(!1),[fe,he]=(0,A.useState)(``),R=(0,A.useRef)(null),z=(0,A.useRef)(!0),B=(0,A.useRef)(void 0),ge=(0,A.useRef)(crypto.randomUUID()),_e=(0,A.useCallback)(async e=>[{...await t.request(`web/local-agent-computer`,ce,{signal:e}),project:t.projectId}],[t]),V=r(_e,3e3),H=V.data?.find(e=>e.project===d.project),U=H?.directories.find(e=>e.id===d.directory);C(d.project);let W=(0,A.useCallback)((e,t,n)=>C(d.project).request(e,t,n),[d.project]),ve=(0,A.useCallback)(e=>d.session?W(`web/local-agent-sessions/${d.session}`,l,{signal:e}):Promise.resolve(null),[W,d.session]),G=r(ve,15e3),[K,ye]=(0,A.useState)(),q=K?.session.id===d.session&&(!G.data||K.cursor>=G.data.cursor)?K:G.data;(0,A.useEffect)(()=>{if(!d.session)return;let e=new EventSource(w(`/api/v1/projects/${encodeURIComponent(d.project)}/web/local-agent-sessions/${encodeURIComponent(d.session)}/events`)),t=!0;return e.addEventListener(`snapshot`,e=>{try{let n=l.parse(JSON.parse(e.data));t&&ye(e=>e?.session.id===n.session.id&&e.cursor>n.cursor?e:n)}catch(e){g(a(e))}}),()=>{t=!1,e.close()}},[d.project,d.session]),(0,A.useEffect)(()=>{z.current=!0},[d.project,d.session]),(0,A.useEffect)(()=>{z.current&&R.current&&(R.current.scrollTop=R.current.scrollHeight)},[q?.cursor,q?.messages.length]);let J=q?.session,Y=H?.capabilities.includes(`local-sessions-v1`),X=(e,n,r=``)=>{f({project:e,directory:n,session:r}),k(!1),L(!1),he(``),N(``),g(``);let i=new URL(location.href);i.searchParams.set(`directory`,n),r?i.searchParams.set(`session`,r):i.searchParams.delete(`session`),e===t.projectId&&history.replaceState(null,``,i)};(0,A.useEffect)(()=>{if(!d.directory&&V.data?.[0]?.directories[0]){let e=V.data[0],t=e.directories[0],n=e.sessions.find(e=>e.id===d.session);X(e.project,n?.directory??t.id,n?.id??t.defaultSession)}},[V.data]),(0,A.useEffect)(()=>{if(!J)return;let e=()=>{document.visibilityState===`visible`&&W(`web/local-agent-sessions/${J.id}/read`,le,{method:`POST`}).catch(e=>g(a(e)))};return e(),document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[J?.id,q?.messages.at(-1)?.seq,W]);async function Z(e){x(!0),g(``);try{await e(),await Promise.all([G.reload(),V.reload()])}catch(e){g(a(e))}finally{x(!1)}}let[Q,$]=(0,A.useState)(null);(0,A.useEffect)(()=>$(null),[J?.id]);let be=H?.catalogs.find(e=>J?.cwd?e.cwd===J.cwd:e.directory===(J?.executionDirectory??J?.directory))?.commands??[],xe=new Map;for(let e of V.data??[]){let t=e.computer?.id??`unknown:${e.project}`;xe.set(t,[...xe.get(t)??[],e])}return(0,j.jsxs)(re,{className:`computers-layout`,testId:`computers-page`,label:`本地会话`,tree:!0,navigation:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(p,{title:`电脑`,icon:`computers`,children:(0,j.jsx)(v,{id:`computer-create-menu`,triggerId:`computer-create`,label:`新建`,trigger:(0,j.jsx)(s,{name:`plus`}),className:`computer-create-menu`,routeKey:d.directory,children:e=>(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`button`,{type:`button`,role:`menuitem`,disabled:!U||!Y,onClick:()=>{e(),L(!0),T(!1),k(!1)},children:`新建会话`}),(0,j.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{e(),T(!0),L(!1),k(!1)},children:`接入目录`})]})})}),(0,j.jsx)(`div`,{className:`assistant-message-scroll computer-tree`,role:`tree`,"aria-label":`电脑与会话`,onKeyDown:oe,children:[...xe.entries()].map(([e,t])=>(0,j.jsxs)(`div`,{role:`none`,children:[(0,j.jsxs)(`div`,{className:`computer-device`,children:[(0,j.jsx)(`span`,{className:`computer-connection ${t.some(e=>e.online)?`online`:``}`,role:`img`,"aria-label":t.some(e=>e.online)?`在线`:`离线`,title:t.some(e=>e.online)?`在线`:`离线`,children:(0,j.jsx)(s,{name:`device`,size:`small`})}),(0,j.jsx)(`span`,{title:t[0].computer?.name,children:t[0].computer?.name??`已连接客户端`})]}),t.map(e=>(0,j.jsx)(`div`,{role:`none`,children:e.directories.map(t=>{let r=`${e.project}/${t.id}`,i=!n.has(r);return(0,j.jsxs)(`div`,{role:`none`,children:[(0,j.jsxs)(h,{className:`tree-item tree-folder`,role:`treeitem`,"aria-level":1,"aria-expanded":i,style:{"--tree-level":1},leading:(0,j.jsx)(`span`,{className:`tree-chevron ${i?`expanded`:``}`,children:(0,j.jsx)(s,{name:`chevron`,size:`small`})}),onClick:()=>u(e=>{let t=new Set(e);return i?t.add(r):t.delete(r),t}),children:[(0,j.jsx)(s,{name:`files`}),(0,j.jsx)(`span`,{className:`tree-name`,title:t.name,children:t.name})]}),i&&(0,j.jsx)(`div`,{role:`group`,children:e.sessions.filter(e=>e.directory===t.id).map(n=>(0,j.jsxs)(h,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":d.session===n.id&&d.project===e.project,style:{"--tree-level":2},leading:(0,j.jsx)(`span`,{className:`tree-chevron`,children:(0,j.jsx)(`span`,{className:`assistant-message-dot ${n.unread?`unread`:``}`})}),title:n.title,onClick:()=>X(e.project,t.id,n.id),children:[(0,j.jsx)(s,{name:`messages`}),(0,j.jsx)(`span`,{className:`tree-name`,children:n.title}),n.archived?(0,j.jsx)(`span`,{title:`已归档`,role:`img`,"aria-label":`已归档`,children:(0,j.jsx)(s,{name:`archive`,size:`small`})}):n.state!==`idle`&&(0,j.jsx)(ne,{state:n.state,label:I[n.state]??n.state})]},n.id))})]},t.id)})},e.project))]},e))}),(0,j.jsx)(o,{error:!0,children:V.error})]}),children:[S&&(0,j.jsxs)(`div`,{className:`stack computer-panel`,children:[(0,j.jsx)(`h2`,{children:`接入目录`}),(0,j.jsx)(_,{id:`computer-connect`,label:`在目标电脑连接项目`,value:`teammy connect`}),(0,j.jsx)(_,{id:`computer-register`,label:`在该电脑登记执行目录`,value:`teammy agent register --provider codex --cwd .`}),(0,j.jsx)(`p`,{className:`muted`,children:`完成登记后自动显示。会话可直接在网页使用,也可连接专用群。`})]}),U?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(te,{title:J?(0,j.jsx)(me,{title:J.title,busy:y,onSave:t=>Z(()=>W(`web/local-agent-sessions/${J.id}/settings`,e,{method:`PUT`,body:{expectedRevision:J.revision,title:t,config:J.config}}))},J.id):(0,j.jsx)(`h2`,{children:U.name}),actions:(0,j.jsx)(c,{icon:`settings`,label:`会话与目录设置`,disabled:!J,onClick:()=>k(!0)})}),!Y&&(0,j.jsx)(o,{children:`升级客户端后可使用多个会话和网页对话。`}),ue&&(0,j.jsxs)(`form`,{className:`computer-panel inline-form`,onSubmit:t=>{t.preventDefault(),Z(async()=>{let t=await W(`web/local-agents/${U.id}/sessions`,e,{method:`POST`,body:{id:ge.current,title:P}});ge.current=crypto.randomUUID(),L(!1),F(``),X(d.project,U.id,t.id)})},children:[(0,j.jsx)(`input`,{required:!0,"aria-label":`会话名称`,placeholder:`会话名称`,value:P,onChange:e=>F(e.target.value)}),(0,j.jsx)(`button`,{disabled:y||!P.trim(),children:`创建`})]}),E&&J&&H&&(0,j.jsx)(i,{id:`computer-settings`,title:`会话与目录设置`,onClose:()=>k(!1),children:(0,j.jsx)(pe,{session:J,directory:U,entry:H,request:W,busy:y,save:Z,code:fe,setCode:he},`${J.id}:${J.revision}`)}),(0,j.jsxs)(ee,{ref:R,onScroll:e=>{let t=e.currentTarget;z.current=t.scrollHeight-t.scrollTop-t.clientHeight<96},"aria-label":`本地会话记录`,children:[q?.messages.map(e=>e.role===`system`?(0,j.jsx)(`div`,{className:`conversation-system-message`,children:e.body},e.id):(0,j.jsxs)(ie,{className:e.question?`question-bubble`:``,mine:e.role===`user`,author:e.role===`user`?`你`:`本地 Agent`,time:e.createdAt,children:[e.question?(0,j.jsx)(de,{question:e.question,session:J.id,request:W,refresh:G.reload}):(0,j.jsx)(`div`,{className:`markdown`,children:(0,j.jsx)(O,{children:e.body})}),e.role===`user`&&[`offered`,`pending`,`human_routed`,`failed`,`uncertain`].includes(e.state)&&(0,j.jsx)(ne,{label:I[e.state]??e.state,state:e.state})]},e.id)),!q?.messages.length&&(0,j.jsx)(`div`,{className:`assistant-empty`,children:`在当前目录开始一段对话。`})]}),q?.commands.filter(e=>e.state!==`succeeded`).slice(-3).map(e=>(0,j.jsxs)(`p`,{className:`computer-control-status`,role:`status`,children:[e.kind,` · `,I[e.state]??e.state,e.error?`:${e.error}`:``]},e.id)),(0,j.jsx)(o,{error:!0,children:m||G.error||J?.error}),J&&(0,j.jsx)(ae,{value:M,onChange:N,label:`向本地 Agent 发送消息`,placeholder:J.archived?`会话已归档`:`输入消息…`,disabled:J.archived||!Y,sendDisabled:y,actions:(0,j.jsx)(se,{session:J,models:H?.models??[],busy:y,available:!!Y,online:!!H?.online,commands:be,draft:M,onInsert:e=>{$(e.kind===`skill`?e:null),N(`${e.kind===`skill`?`$`:`/`}${e.name} `),requestAnimationFrame(()=>document.querySelector(`.message-composer textarea`)?.focus())},onConfig:t=>{k(!1),Z(()=>W(`web/local-agent-sessions/${J.id}/settings`,e,{method:`PUT`,body:{expectedRevision:J.revision,title:J.title,config:t}}))}}),onSubmit:e=>{e.preventDefault();let t=M.trim();if(!t)return;let n=Q?.path&&t.startsWith(`$${Q.name}`)?[{name:Q.name,path:Q.path}]:void 0,r=JSON.stringify({session:J.id,body:t,skills:n});B.current?.fingerprint!==r&&(B.current={fingerprint:r,id:crypto.randomUUID()});let i=B.current;Z(async()=>{await W(`web/local-agent-sessions/${J.id}/messages`,b(),{method:`POST`,body:{id:i.id,body:t,...n?{skills:n}:{}}}),N(e=>e.trim()===t?``:e),$(null),B.current===i&&(B.current=void 0)})}})]}):(0,j.jsxs)(`div`,{className:`assistant-empty`,children:[`尚未登记本地执行目录。`,(0,j.jsx)(`button`,{onClick:()=>T(!0),children:`接入目录`})]})]})}function de({question:e,session:t,request:n,refresh:r}){let[i,c]=(0,A.useState)({}),[l,u]=(0,A.useState)(``),[d,f]=(0,A.useState)(!1),p=(0,A.useRef)(null),m=(0,A.useRef)(!1),h=(0,A.useRef)(void 0);(0,A.useEffect)(()=>{if(e.state!==`pending`||m.current||!p.current)return;let r=!1,i=()=>{if(r&&document.visibilityState===`visible`&&p.current){let r=p.current.getBoundingClientRect();r.bottom>0&&r.top<innerHeight&&n(`web/local-agent-sessions/${t}/questions/${e.id}/presented`,le,{method:`POST`}).then(()=>{m.current=!0}).catch(e=>u(a(e)))}},o=new IntersectionObserver(e=>{r=e.some(e=>e.isIntersecting),r&&i()});return o.observe(p.current),document.addEventListener(`visibilitychange`,i),()=>{o.disconnect(),document.removeEventListener(`visibilitychange`,i)}},[e.id,e.state,t,n]);async function g(i,o){h.current&&h.current.body===i||(h.current={body:i,id:crypto.randomUUID(),...o===void 0?{}:{decision:o}}),f(!0),u(``);try{return await n(`web/local-agent-sessions/${t}/questions/${e.id}/answers`,b(),{method:`POST`,body:h.current}),h.current=void 0,r(),!0}catch(e){return u(a(e)),!1}finally{f(!1)}}let _=e.response,v=e.state===`answered`,y=[`expired`,`cancelled`].includes(e.state),x=[`human_routed`,`failed`].includes(e.submissionState??``),S=e.state===`pending`&&(!_||x),C=y?`已过期`:e.state===`uncertain`||e.submissionState===`uncertain`?`需核对`:v?e.approval?_?.decision===!0?`已允许`:_?.decision===!1?`已拒绝`:`已处理`:_?``:`已回答`:x?`未送达`:_?`正在提交`:``,w=y||_?.decision===!1||x?`close`:v?`check`:`clock`;return(0,j.jsxs)(`div`,{className:`native-question`,ref:p,children:[e.questions.map(t=>(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`p`,{children:t.text}),S&&(0,j.jsx)(`div`,{className:`question-options`,children:(e.approval?[`允许`,`拒绝`]:t.options).map(n=>(0,j.jsx)(`button`,{disabled:d||e.state!==`pending`,"aria-pressed":i[t.id]===n,onClick:()=>{c(e=>({...e,[t.id]:n})),e.questions.length===1&&g(n,e.approval?n===`允许`:void 0)},children:n},n))}),!e.approval&&t.freeText&&S&&(0,j.jsx)(M,{disabled:d,onSend:async n=>e.questions.length===1?g(n):(c(e=>({...e,[t.id]:n})),!0)}),!S&&!e.approval&&_?.answers[t.id]&&(0,j.jsxs)(`div`,{className:`question-response`,children:[(0,j.jsx)(s,{name:v?`check`:`clock`,size:`small`}),(0,j.jsx)(`span`,{children:_.answers[t.id]})]}),S&&e.questions.length>1&&i[t.id]&&!t.options.includes(i[t.id])&&(0,j.jsx)(`small`,{children:i[t.id]})]},t.id)),S?(0,j.jsxs)(j.Fragment,{children:[!e.approval&&e.questions.length>1&&(0,j.jsx)(`div`,{className:`question-actions`,children:(0,j.jsx)(`button`,{disabled:d||e.questions.some(e=>!i[e.id]?.trim()),onClick:()=>void g(e.questions.length===1?i[e.questions[0].id]:JSON.stringify(i)),children:`回答`})}),e.approval&&(0,j.jsx)(`small`,{className:`muted`,children:`60 秒后自动允许`})]}):null,C&&(0,j.jsxs)(`small`,{className:`question-result`,children:[(0,j.jsx)(s,{name:w,size:`small`}),C]}),(0,j.jsx)(o,{error:!0,children:l})]})}function fe({value:e,onChange:t,models:n}){let r=n.find(t=>t.id===e.model);return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`label`,{children:[`模型`,(0,j.jsxs)(`select`,{value:e.model??``,onChange:n=>t({...e,model:n.target.value||null,effort:null}),children:[(0,j.jsx)(`option`,{value:``,children:`本机默认`}),n.map(e=>(0,j.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,j.jsxs)(`label`,{children:[`思考强度`,(0,j.jsxs)(`select`,{value:e.effort??``,onChange:n=>t({...e,effort:n.target.value||null}),children:[(0,j.jsx)(`option`,{value:``,children:`模型默认`}),r?.efforts.map(e=>(0,j.jsx)(`option`,{children:e},e))]})]}),(0,j.jsxs)(`label`,{children:[`权限`,(0,j.jsxs)(`select`,{value:e.permission,onChange:n=>t({...e,permission:n.target.value}),children:[(0,j.jsx)(`option`,{value:`read-only`,children:`只读 · 禁止提权`}),(0,j.jsx)(`option`,{value:`workspace-write`,children:`工作区写入 · 按需审批`}),(0,j.jsx)(`option`,{value:`full-access`,children:`完整访问 · 按需审批`})]})]})]})}function pe({session:n,directory:r,entry:i,request:a,busy:o,save:s,code:c,setCode:l}){let[u,d]=(0,A.useState)(r.defaults??t.parse({})),[f,p]=(0,A.useState)(r.defaultSession??n.id),[h,g]=(0,A.useState)(r.name),[v,y]=(0,A.useState)(r.responsibilities),[x,C]=(0,A.useState)(r.enabled),[w,T]=(0,A.useState)(n.executionDirectory),[D,O]=(0,A.useState)();return(0,A.useEffect)(()=>{a(`web/local-agent-settings`,E).then(O).catch(()=>{})},[a]),(0,j.jsxs)(`div`,{className:`computer-panel stack`,children:[(0,j.jsxs)(`details`,{open:!0,children:[(0,j.jsx)(`summary`,{children:`执行位置与连接`}),(0,j.jsx)(`div`,{className:`config-fields`,children:(0,j.jsxs)(`label`,{children:[`执行位置`,(0,j.jsxs)(`select`,{value:w??``,onChange:e=>T(e.target.value||null),children:[(0,j.jsx)(`option`,{value:``,children:`原登记目录`}),i.directories.filter(e=>e.id!==r.id).map(e=>(0,j.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})}),n.cwd&&(0,j.jsxs)(`p`,{className:`computer-paths`,children:[`当前执行路径:`,(0,j.jsx)(`code`,{children:n.cwd})]}),(0,j.jsx)(`button`,{disabled:o,onClick:()=>void s(()=>a(`web/local-agent-sessions/${n.id}/settings`,e,{method:`PUT`,body:{expectedRevision:n.revision,title:n.title,config:n.config,executionDirectory:w}})),children:`保存执行位置`}),(0,j.jsx)(`button`,{disabled:o||n.bound,onClick:()=>void s(async()=>{l((await a(`web/local-agent-bindings/codes`,S({code:m()}),{method:`POST`,body:{directory:r.id,session:n.id,expectedRevision:n.bindingRevision}})).code)}),children:n.bound?`已连接专用群`:`连接专用群`}),c&&(0,j.jsx)(_,{id:`session-binding`,label:`在目标群发送`,value:`/bind ${c}`})]}),(0,j.jsxs)(`details`,{children:[(0,j.jsx)(`summary`,{children:`目录默认设置与接单`}),(0,j.jsxs)(`div`,{className:`config-fields`,children:[(0,j.jsxs)(`label`,{children:[`目录名称`,(0,j.jsx)(`input`,{value:h,onChange:e=>g(e.target.value)})]}),(0,j.jsxs)(`label`,{children:[`职责`,(0,j.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value)})]}),(0,j.jsxs)(`label`,{children:[`默认会话`,(0,j.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),children:i.sessions.filter(e=>e.directory===r.id&&!e.archived).map(e=>(0,j.jsx)(`option`,{value:e.id,children:e.title},e.id))})]}),(0,j.jsx)(fe,{value:u,onChange:d,models:i.models})]}),(0,j.jsx)(`p`,{className:`muted`,children:`用于新会话与新派工。`}),(0,j.jsx)(`button`,{disabled:o,onClick:()=>void s(()=>a(`web/local-agents/${r.id}/settings`,b(),{method:`PUT`,body:{defaultSession:f,defaults:u,name:h,responsibilities:v,enabled:x,expectedRevision:r.revision}})),children:`保存目录默认设置`}),(0,j.jsxs)(`label`,{children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:x,onChange:e=>C(e.target.checked)}),`此目录自动接单`]}),(0,j.jsx)(`p`,{children:r.available?`可自动接单`:r.reason}),(0,j.jsxs)(`label`,{children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:D?.enabled??!1,disabled:!D||o,onChange:e=>void s(async()=>O(await a(`web/local-agent-settings`,E,{method:`PUT`,body:{enabled:e.target.checked,expectedRevision:D.revision}})))}),`开启本项目的本地执行`]}),(0,j.jsx)(_,{id:`directory-intake`,label:r.enabled?`暂停此目录新增接单`:`开启此目录自动接单`,value:`teammy agent ${r.enabled?`disable`:`enable`} --id ${r.id}`})]})]})}function me({title:e,busy:t,onSave:n}){let[r,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(e);return r?(0,j.jsx)(`form`,{className:`session-title-form`,onSubmit:t=>{t.preventDefault(),a.trim()&&a.trim()!==e&&n(a.trim()),i(!1)},children:(0,j.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,j.jsx)(`h2`,{children:(0,j.jsx)(`button`,{type:`button`,className:`session-rename`,title:`重命名会话`,"aria-label":`重命名会话:${e}`,onClick:()=>{o(e),i(!0)},children:e})})}export{ue as Computers};
@@ -1 +0,0 @@
1
- import{A as e,B as t,D as n,G as r,H as i,I as a,J as o,L as s,M as c,N as l,O as u,P as d,R as f,U as p,V as m,_t as h,vt as g,y as _}from"./index-BQicHl1a.js";import{t as v}from"./project-links-Dy6-B89_.js";import"./file-links-BYBi3BDP.js";var y=h(),b=r(),x=[{status:`planned`,label:`计划`},{status:`in_progress`,label:`进行中`},{status:`in_review`,label:`待验收`},{status:`completed`,label:`已完成`},{status:null,label:`未明确`}];function S({members:t,project:r,userName:a}){let{request:o,projectId:c}=_(),u=(0,y.useCallback)(e=>o(`tasks`,n,{signal:e}),[o]),d=i(u,3e3,p(c,`tasks`)),[m,h]=(0,y.useState)(),[v,S]=(0,y.useState)(!1),[w,T]=(0,y.useState)(Date.now);(0,y.useEffect)(()=>{let e=setInterval(()=>T(Date.now()),6e4);return()=>clearInterval(e)},[]);let D=d.data,O=new Map(t.map(e=>[e.id,e.displayName||e.id]));return(0,b.jsxs)(`div`,{className:`task-board`,children:[(0,b.jsx)(f,{title:r?.projectName.trim()?`${r.projectName.trim()}|工作看板`:`工作看板`,description:r?.description.trim()||``,children:(0,b.jsx)(`a`,{className:`account-home`,"data-testid":`home-link`,href:g(`/projects`),onClick:e=>{e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),history.pushState(null,``,g(`/projects`)),window.dispatchEvent(new PopStateEvent(`popstate`)))},"aria-label":`项目主页`,"data-tooltip":`项目主页`,children:(0,b.jsx)(`strong`,{children:a})})}),(0,b.jsx)(s,{error:!0,children:d.error}),(0,b.jsx)(`section`,{className:`task-board-lanes`,"aria-label":`任务进度`,"data-testid":`progress-board`,children:x.filter(e=>e.status!==null||D?.tasks.some(e=>e.status===null)).map(t=>{let n=D?.tasks.filter(e=>e.status===t.status)??[];n.sort((e,t)=>e.statusSince.localeCompare(t.statusSince)||e.id.localeCompare(t.id));let r=t.status===`completed`&&!v?n.slice(0,5):n;return(0,b.jsxs)(`section`,{className:`task-lane`,"aria-label":t.label,"data-stage":t.status??`unknown`,children:[(0,b.jsxs)(`h2`,{children:[(0,b.jsx)(`span`,{className:`lane-dot`}),t.label,(0,b.jsx)(e,{children:D?n.length:`—`})]}),(0,b.jsxs)(`div`,{className:`task-lane-content`,children:[n.length?r.map(e=>(0,b.jsx)(C,{task:e,names:O,now:w,onEdit:()=>h(e),onSaved:()=>void d.reload()},e.id)):(0,b.jsx)(`p`,{className:`task-lane-empty`,children:d.error&&!D?`读取失败`:D?`暂无任务`:`读取中…`}),t.status===`completed`&&n.length>5&&(0,b.jsxs)(`button`,{type:`button`,className:`task-lane-expand`,"aria-expanded":v,onClick:()=>S(!v),children:[(0,b.jsx)(l,{name:v?`chevronUp`:`chevronDown`,size:`small`}),v?`收起`:`展开其余 ${n.length-5} 项`]})]})]},t.label)})}),m&&(0,b.jsx)(E,{task:m,onClose:()=>h(void 0),onSaved:()=>{h(void 0),d.reload()}},m.id)]})}function C({task:e,names:n,onEdit:r,onSaved:i,now:a}){let{projectId:c,request:f}=_(),p=m(),[h,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(``);async function E(){if(!h){x(!0),C(``);try{await f(`tasks/${e.id}/correction`,u,{method:`PATCH`,signal:p,body:{needsConfirmation:!1,expectedRevision:e.revision}}),p.aborted||i()}catch(e){p.aborted||C(o(e))}finally{x(!1)}}}return(0,b.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,b.jsxs)(`summary`,{className:`task-card-heading`,"data-testid":`task-toggle`,children:[(0,b.jsx)(`h3`,{children:e.title}),(0,b.jsxs)(`span`,{className:`task-card-meta`,children:[(0,b.jsx)(`small`,{title:n.get(e.owner)??e.owner,children:n.get(e.owner)??e.owner}),e.needsConfirmation&&(0,b.jsxs)(`span`,{className:`task-confirmation`,"data-testid":`task-confirmation`,children:[(0,b.jsx)(l,{name:`attention`,size:`small`}),`需要确认`]}),e.status!==`completed`&&(0,b.jsx)(w,{since:e.statusSince,now:a})]})]}),(0,b.jsx)(d,{icon:`edit`,className:`task-card-edit`,label:`纠正任务:${e.title}`,"data-testid":`task-correct`,disabled:h,onClick:r}),(0,b.jsxs)(`div`,{className:`task-card-details`,children:[(0,b.jsx)(`h4`,{children:`目标`}),(0,b.jsx)(`p`,{children:e.goal?(0,b.jsx)(T,{value:e.goal,names:n}):`目标未明确`}),(0,b.jsx)(`h4`,{children:`当前进展`}),(0,b.jsx)(`p`,{className:`task-progress`,children:(0,b.jsx)(T,{value:e.progress,names:n})}),(0,b.jsx)(`div`,{className:`task-card-sources`,children:e.sources.map(t=>(0,b.jsxs)(`a`,{"data-testid":`task-source`,href:g(t.kind===`material`?`/projects/${c}/materials?id=${t.materialId}&revision=${t.revision}`:v(c,e.owner,t.path)),children:[(0,b.jsx)(l,{name:`file`,size:`small`}),(0,b.jsx)(`span`,{children:t.path})]},t.path))}),e.syncedAt&&(0,b.jsxs)(`small`,{children:[`资料同步于 `,(0,b.jsx)(t,{value:e.syncedAt})]}),e.needsConfirmation&&(0,b.jsxs)(`div`,{className:`task-card-confirm`,children:[(0,b.jsx)(s,{error:!0,children:S}),(0,b.jsx)(`button`,{className:`primary`,"data-testid":`task-confirm-save`,disabled:h,onClick:()=>void E(),children:h?`正在保存…`:`保存`})]})]})]})}function w({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,b.jsxs)(`span`,{className:`task-age${n>6048e5?` stale`:``}`,"data-testid":`task-age`,title:`进入当前状态:${new Date(e).toLocaleString(`zh-CN`)}`,"aria-label":`当前状态停留 ${i}`,children:[(0,b.jsx)(l,{name:`clock`,size:`small`}),i]})}function T({value:e,names:t}){return e.split(/(@[a-z][a-z0-9_-]*)/gi).map((e,n)=>e.startsWith(`@`)&&t.has(e.slice(1))?(0,b.jsx)(`mark`,{className:`task-mention`,children:e},n):e)}function E({task:e,onClose:t,onSaved:n}){let{request:r}=_(),i=m(),[l,d]=(0,y.useState)(e.title),[f,p]=(0,y.useState)(e.status??``),[h,g]=(0,y.useState)(e.goal??``),[v,S]=(0,y.useState)(e.progress),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(``),D={...l===e.title?{}:{title:l},...f===(e.status??``)?{}:{status:f||null},...h===(e.goal??``)?{}:{goal:h||null},...v===e.progress?{}:{progress:v},...e.needsConfirmation?{needsConfirmation:!1}:{}};async function O(){if(!C&&Object.keys(D).length){w(!0),E(``);try{await r(`tasks/${e.id}/correction`,u,{method:`PATCH`,signal:i,body:{...D,expectedRevision:e.revision}}),i.aborted||n()}catch(e){i.aborted||E(o(e))}finally{w(!1)}}}return(0,b.jsx)(a,{id:`task-correction`,title:`纠正任务`,onClose:t,children:(0,b.jsxs)(`form`,{className:`stack`,"aria-busy":C,onSubmit:e=>{e.preventDefault(),O()},children:[(0,b.jsx)(c,{id:`task-title`,label:`标题`,children:(0,b.jsx)(`input`,{value:l,required:!0,onChange:e=>d(e.target.value)})}),(0,b.jsxs)(`fieldset`,{className:`task-status-field`,disabled:C,children:[(0,b.jsx)(`legend`,{children:`状态`}),(0,b.jsx)(`div`,{className:`task-status-options`,"data-testid":`task-status`,children:x.filter(e=>e.status!==null).map(e=>(0,b.jsxs)(`label`,{className:`task-status-choice`,children:[(0,b.jsx)(`input`,{type:`radio`,name:`task-status`,value:e.status,checked:f===e.status,onChange:()=>p(e.status)}),(0,b.jsx)(`span`,{children:e.label})]},e.status))}),(0,b.jsx)(`small`,{children:`待验收:任务成果已提交,等待验收或最终确认。`})]}),(0,b.jsx)(c,{id:`task-goal`,label:`目标`,children:(0,b.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value)})}),(0,b.jsx)(c,{id:`task-progress`,label:`当前进展`,children:(0,b.jsx)(`textarea`,{value:v,onChange:e=>S(e.target.value)})}),(0,b.jsx)(s,{error:!0,children:T}),(0,b.jsx)(`div`,{className:`row wrap`,children:(0,b.jsx)(`button`,{type:`submit`,className:`primary`,disabled:C||!Object.keys(D).length,"data-testid":`task-correction-save`,children:`保存`})})]})})}function D({members:e,config:t,userName:n}){return(0,b.jsx)(S,{members:e,project:t,userName:n})}export{D as Dashboard};
@@ -1 +0,0 @@
1
- import{G as e,H as t,K as n,L as r,N as i,P as a,Q as o,U as s,_t as c,c as l,d as u,et as d,f,j as p,l as m,s as h,u as g,vt as _,y as v,z as y}from"./index-BQicHl1a.js";import{t as b}from"./Markdown-Drn0H2RJ.js";import{n as x,t as S}from"./WorkspaceTree-BEiahyEL.js";import{t as C}from"./project-links-Dy6-B89_.js";import{t as w}from"./file-links-BYBi3BDP.js";import{t as T}from"./HtmlPreview-TOlZ7wbO.js";var E=c(),D=e();function O(e,t){let n=t.split(`/`).slice(0,-1);return n.map((t,r)=>x(e,n.slice(0,r+1).join(`/`))).concat(x(e,``))}function k({members:e,onRefresh:i}){let{api:s,projectId:c}=v(),[y,b]=(0,E.useState)(()=>{let t=new URLSearchParams(location.search),n=t.get(`owner`),r=d.safeParse(t.get(`path`));return n&&(g(n)||e.some(e=>e.id===n))&&r.success&&!m(r.data)?{owner:n,path:r.data}:void 0}),[T,k]=(0,E.useState)(()=>new Set(y?O(y.owner,y.path):[])),[j,M]=(0,E.useState)(()=>y?{...y,kind:`file`}:void 0),[N,P]=(0,E.useState)(0),[F,I]=(0,E.useState)(()=>{let e=new URLSearchParams(location.search);return!y&&(e.has(`owner`)||e.has(`path`))?`文件链接不完整或目标已不可用。`:``}),L=(0,E.useCallback)(async e=>{if(y)try{return{owner:y.owner,...await s.file(y.owner,y.path,void 0,e)}}catch(e){throw e instanceof n&&e.code===`FILE_NOT_FOUND`?Error(`找不到这个文件,可能已被删除或移动。`):e}},[y?.owner,y?.path,N]),R=t(L),z=R.data?.owner===y?.owner&&R.data?.file.path===y?.path?R.data:void 0;function B(e,t){let n=t.split(`/`).filter(Boolean);k(t=>{let r=new Set(t);for(let t=0;t<=n.length;t++)r.add(x(e,n.slice(0,t).join(`/`)));return r})}function V(e,t){I(``),B(e,t.split(`/`).slice(0,-1).join(`/`)),b({owner:e,path:t}),M({owner:e,path:t,kind:`file`}),history.replaceState(null,``,_(C(c,e,t)))}function H(t){if(!y)return!1;let n=w(g(y.owner)?y.path:`${y.owner}/${y.path}`,t);if(!n)return!/^[a-z][a-z0-9+.-]*:/i.test(t)&&!t.startsWith(`//`)&&(I(`该链接超出工作区,请在原仓库查看。`),!0);if(m(n.path))return I(`配置文件不在文件浏览中显示。`),!0;if(l(n.path))return location.assign(_(`/projects/${c}/memory`)),!0;let[r,...i]=n.path.split(`/`),a=e.some(e=>e.id===r),o=a?r:h,s=a?i.join(`/`):n.path;return I(``),n.directory?(B(o,s),M({owner:o,path:s,kind:`directory`})):o===y.owner&&s===y.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`}):V(o,s),!0}return(0,D.jsx)(f,{"data-testid":`file-browser`,label:`文件资源管理器`,navigation:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(u,{title:`工作区`,icon:`files`,children:(0,D.jsx)(a,{icon:`refresh`,label:`刷新文件`,"data-testid":`files-refresh`,onClick:()=>{I(``),P(e=>e+1),i()}})}),(0,D.jsx)(S,{members:e,expanded:T,selected:j,revealed:!R.loading&&!R.error&&z?{owner:z.owner,path:z.file.path,file:z.file}:void 0,onSelect:V,onToggle:(e,t)=>{M({owner:e,path:t,kind:`directory`}),k(n=>{let r=new Set(n),i=x(e,t);return r.has(i)?r.delete(i):r.add(i),r})}},N)]}),children:(0,D.jsx)(`section`,{className:`file-detail`,"data-testid":`file-preview`,"data-owner-id":y?.owner,"data-file-path":y?.path,"aria-label":o.filePreview,children:y?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(r,{error:!0,children:F||!R.loading&&R.error}),R.error&&(0,D.jsx)(`button`,{className:`file-entry-retry`,"data-testid":`files-retry`,onClick:()=>void R.reload(),children:o.retry}),R.loading?(0,D.jsx)(`p`,{className:`preview-body`,role:`status`,children:o.loading}):!R.error&&z&&(0,D.jsx)(A,{owner:z.owner,file:z.file,onLink:H},`${z.owner}:${z.file.path}:${z.file.sha256}`)]}):F?(0,D.jsx)(r,{error:!0,children:F}):(0,D.jsx)(p,{mascot:!0,title:`查看工作区文件`,description:o.pickFile})})})}function A({owner:e,file:n,onLink:c}){let{readTextBlob:l,blobUrl:u,projectId:d}=v(),[f,p]=(0,E.useState)(!1),m=n.size>524288,h=/\.(md|markdown)$/i.test(n.path),_=/\.html?$/i.test(n.path),x=(0,E.useCallback)(e=>m?Promise.resolve(void 0):l(n,e),[n.sha256,n.size,m]),S=t(x,!1,s(d,`file-body`,n.sha256));return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`header`,{className:`file-detail-header`,children:[(0,D.jsxs)(`span`,{className:`file-detail-path`,title:`${g(e)?`teamcontext`:e}/${n.path}`,children:[(0,D.jsxs)(`span`,{children:[g(e)?`teamcontext`:e,` / `]}),n.path]}),(0,D.jsxs)(y,{label:`文件操作`,children:[(h||_)&&(0,D.jsx)(a,{icon:f?`preview`:`code`,label:f?`切换为预览`:`切换为原文`,"data-testid":`file-toggle-raw`,"aria-pressed":f,onClick:()=>p(!f)}),(0,D.jsx)(`a`,{className:`icon-button`,"data-testid":`file-download`,"aria-label":o.download,title:o.download,href:u(n.sha256),download:n.path.split(`/`).at(-1),children:(0,D.jsx)(i,{name:`download`})})]})]}),m?(0,D.jsx)(`div`,{className:`empty`,children:(0,D.jsx)(`p`,{children:o.previewLarge})}):S.error?(0,D.jsxs)(`div`,{className:`preview-body`,children:[(0,D.jsx)(r,{error:!0,children:S.error}),(0,D.jsx)(`button`,{"data-testid":`file-preview-retry`,onClick:()=>void S.reload(),children:o.retry})]}):S.loading?(0,D.jsx)(`p`,{className:`preview-body`,role:`status`,children:o.loading}):(0,D.jsx)(`div`,{className:`preview-body${_&&!f?` preview-body-html`:``}`,children:_&&!f?(0,D.jsx)(T,{url:u(n.sha256),name:n.path.split(`/`).at(-1)}):h&&!f?(0,D.jsx)(`article`,{className:`markdown`,"data-testid":`file-content`,"data-format":`markdown`,children:(0,D.jsx)(b,{onLink:c,children:S.data??``})}):(0,D.jsx)(`pre`,{className:`raw`,"data-testid":`file-content`,"data-format":`text`,children:S.data})})]})}export{k as Files};
@@ -1,6 +0,0 @@
1
- import{$ as e,B as t,G as n,H as r,I as i,J as a,K as o,L as s,M as c,N as l,P as u,Q as d,R as f,U as p,V as m,Y as h,Z as g,_t as _,at as v,ct as y,d as b,dt as x,f as S,ft as C,gt as w,h as T,ht as E,it as D,j as ee,lt as O,mt as k,nt as A,ot as j,rt as M,st as N,tt as P,ut as F,vt as I,y as L,yt as te}from"./index-BQicHl1a.js";import{n as R,r as z,t as B}from"./Markdown-Drn0H2RJ.js";import{t as V}from"./Conversation-CZ8mOF1T.js";import{i as ne,r as H}from"./WorkspaceTree-BEiahyEL.js";import{n as U}from"./project-links-Dy6-B89_.js";import{t as W}from"./HtmlPreview-TOlZ7wbO.js";function G(e){return w(D,e)}var K=_(),q=x().regex(/^R\d{6,}$/),J=F({name:x().min(1),sha256:P,size:O().int().nonnegative()}),Y=k().refine(e=>/^https?:\/\//i.test(e),`Use an HTTP or HTTPS URL.`);F({operationId:E(),title:x().trim().default(``),text:x().optional(),url:Y.optional(),originals:j(J).default([])}).strict().refine(e=>!!e.text?.trim()||!!e.url||e.originals.length>0,`Provide text, a link or a file.`),F({expectedRevision:A,title:x().trim().min(1).optional(),url:Y.nullable().optional(),content:x().optional(),summary:x().optional(),sourceVersion:x().optional(),contentDate:x().optional(),originals:j(J).optional()}).strict();var X=F({id:q,projectId:x(),title:x(),submittedBy:x(),createdAt:x(),revision:A,source:F({kind:v([`web`,`chat`,`group`]),url:x().nullable(),groupId:x().optional(),messageId:x().optional(),sourceVersion:x().optional(),contentDate:x().optional()}),originals:j(J),content:x().nullable(),summary:x().nullable(),state:v([`waiting`,`running`,`ready`,`failed`]),error:x().nullable(),url:x()}),re=F({materials:j(X),nextCursor:O().nullable()});F({query:x().trim().min(1),scope:v([`all`,`workspace`,`materials`]).default(`all`),materialId:q.optional(),originalHash:P.optional(),after:x().default(``),limit:G().int().min(1).max(200).default(30)}).strict();var ie=F({items:j(F({key:x(),kind:v([`workspace`,`materials`]),title:x(),snippet:x(),url:x(),path:x()})),nextCursor:x().nullable()}),Z=n();function ae(e){let t=(e.content??``).trimStart().split(`
2
- `);return t[0]?.replace(/^#\s+/,``).trim()===e.title.trim()&&t[0].startsWith(`# `)&&t.shift(),t.join(`
3
- `).trimStart()}function oe(){let e=new URLSearchParams(location.search),t=e.get(`id`);return t?{id:t,...e.get(`original`)?{original:e.get(`original`)}:{},...e.get(`revision`)?{revision:e.get(`revision`)}:{}}:void 0}function se({active:e,onActivate:t,children:n}){let{request:i,projectId:o}=L(),[c,d]=(0,K.useState)(oe),[f,m]=(0,K.useState)(c),[h,g]=(0,K.useState)(()=>new Set(c?[c.id]:[])),[_,v]=(0,K.useState)(!1),[y,b]=(0,K.useState)(``),[x,S]=(0,K.useState)(``),[C,w]=(0,K.useState)(``),[E,D]=(0,K.useState)([]),[O,k]=(0,K.useState)(),[A,j]=(0,K.useState)(!1),[M,N]=(0,K.useState)(``),P=(0,K.useRef)(null),F=(0,K.useCallback)(e=>i(`materials`,re,{signal:e}),[i]),R=r(F,5e3,p(o,`materials`)),z=(0,K.useCallback)(e=>c?i(`materials/${encodeURIComponent(c.id)}${c.revision?`?revision=${encodeURIComponent(c.revision)}`:``}`,X,{signal:e}):Promise.resolve(null),[i,c?.id,c?.revision]),V=r(z,5e3),H=V.data?.id===c?.id?V.data:null,U=[...new Map([...E,...R.data?.materials??[],...H?[H]:[]].map(e=>[e.id,e])).values()].sort((e,t)=>t.createdAt.localeCompare(e.createdAt)||t.id.localeCompare(e.id)),W=O===void 0?R.data?.nextCursor:O;function G(e,n=``){t(),d(e),m(e),S(``),w(n),v(!1),g(t=>new Set([...t,e.id])),history.replaceState(null,``,I(`/projects/${o}/materials?${new URLSearchParams({...e})}`))}(0,K.useEffect)(()=>{let e=()=>{if(!te().endsWith(`/materials`))return;let e=oe();d(e),m(e),S(``),b(``),w(``),v(!1),e&&g(t=>new Set([...t,e.id]))};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]);async function q(){if(W&&!A){j(!0),N(``);try{let e=await i(`materials?before=${W}`,re);D(t=>[...t,...e.materials]),k(e.nextCursor)}catch(e){N(a(e))}finally{j(!1)}}}let J=U.find(e=>e.id===f?.id),Y=J?.originals.find(e=>e.sha256===f?.original)?.name??J?.title??`当前资料`;function ie(){m(void 0),w(``),P.current?.focus()}let se=(0,Z.jsx)(u,{icon:`plus`,label:`新增资料`,onClick:()=>{t(),v(!0),N(``)}});return n({tree:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(s,{error:!0,children:R.error||M}),R.data?U.length===0?(0,Z.jsx)(`p`,{className:`tree-status`,children:`暂无资料`}):(0,Z.jsx)(Z.Fragment,{children:U.map(t=>(0,Z.jsxs)(`div`,{role:`none`,children:[(0,Z.jsxs)(T,{role:`treeitem`,"aria-level":1,"aria-expanded":h.has(t.id),"aria-selected":e&&!_&&c?.id===t.id&&!c.original,className:`tree-item tree-folder`,style:{"--tree-level":1},"data-testid":`material-folder`,title:t.title,onClick:()=>{let e=h.has(t.id);G({id:t.id}),e&&g(e=>{let n=new Set(e);return n.delete(t.id),n})},leading:(0,Z.jsx)(`span`,{className:`tree-chevron ${h.has(t.id)?`expanded`:``}`,children:(0,Z.jsx)(l,{name:`chevron`,size:`small`})}),children:[(0,Z.jsx)(l,{name:`files`}),(0,Z.jsx)(`span`,{className:`tree-name`,children:t.title})]}),h.has(t.id)&&(0,Z.jsx)(`div`,{role:`group`,children:[...t.originals].sort((e,t)=>ne(e.name,t.name)).map((n,r)=>(0,Z.jsxs)(T,{role:`treeitem`,"aria-level":2,"aria-selected":e&&!_&&c?.id===t.id&&c.original===n.sha256,className:`tree-item`,style:{"--tree-level":2},"data-testid":`material-original`,title:n.name,onClick:()=>G({id:t.id,original:n.sha256,...t.id===c?.id&&c.revision?{revision:c.revision}:{}}),leading:(0,Z.jsx)(`span`,{className:`tree-chevron`}),children:[(0,Z.jsx)(l,{name:`file`}),(0,Z.jsx)(`span`,{className:`tree-name`,children:n.name})]},`${n.sha256}:${r}`))})]},t.id))}):(0,Z.jsx)(`p`,{className:`tree-status`,children:`加载中…`}),W&&(0,Z.jsx)(`button`,{className:`tree-action`,disabled:A,onClick:()=>void q(),children:A?`加载中…`:`加载更多`})]}),reader:(0,Z.jsxs)(`section`,{className:`session-reader`,"aria-label":`资料内容与搜索`,children:[(0,Z.jsx)(`div`,{className:`session-reader-content`,children:_?(0,Z.jsx)(fe,{onCancel:()=>v(!1),onSaved:e=>{G({id:e}),R.reload()}}):x?(0,Z.jsx)(ce,{query:x,scope:f,onSelect:e=>G(e,x)},`${x}/${f?.id}/${f?.original}`):c?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(s,{error:!0,children:V.error}),H?c.original?(0,Z.jsx)(le,{material:H,hash:c.original,highlight:C},`${H.id}:${c.original}`):(0,Z.jsxs)(`article`,{className:`material-body`,children:[(0,Z.jsx)(`h1`,{children:H.title}),c.revision&&(0,Z.jsx)(`button`,{className:`material-link`,onClick:()=>G({id:c.id}),children:`查看最新内容`}),!c.revision&&(H.state===`waiting`||H.state===`running`)?(0,Z.jsx)(`p`,{className:`muted`,role:`status`,children:`正在整理…`}):null,(0,Z.jsx)(s,{error:!0,children:H.error??``}),!c.revision&&H.state===`failed`&&(0,Z.jsx)(`button`,{onClick:()=>void i(`materials/${c.id}/retry`,X,{method:`POST`}).then(()=>V.reload()).catch(e=>N(a(e))),children:`重试整理`}),H.content?(0,Z.jsx)(`div`,{className:`markdown`,children:(0,Z.jsx)(B,{highlight:C,children:ae(H)})}):(0,Z.jsx)(`p`,{className:`muted`,children:`正文尚未整理,可以先查看左侧原件。`})]}):(0,Z.jsx)(`p`,{role:`status`,children:`加载中…`})]}):(0,Z.jsx)(ee,{mascot:!0,title:`选择资料开始阅读`,description:`也可以在下方搜索资料内容。`})}),!_&&(0,Z.jsxs)(`form`,{className:`session-search-dock`,"data-testid":`material-search-form`,onSubmit:e=>{e.preventDefault(),S(y.trim()),w(``)},children:[f&&(0,Z.jsxs)(`button`,{type:`button`,className:`search-scope-chip`,title:`清除搜索范围`,"aria-label":`清除范围:${Y}`,onClick:ie,children:[(0,Z.jsxs)(`span`,{className:`scope-label`,children:[`搜索:`,Y]}),(0,Z.jsx)(`span`,{"aria-hidden":`true`,children:`×`})]}),(0,Z.jsxs)(`div`,{className:`session-search-input-row`,children:[(0,Z.jsx)(`input`,{ref:P,"aria-label":`搜索资料`,placeholder:`搜索资料内容`,value:y,onChange:e=>b(e.target.value),onKeyDown:e=>{e.key===`Backspace`&&!y&&f&&(e.preventDefault(),ie())}}),(x||y||C)&&(0,Z.jsx)(u,{icon:`close`,label:`清空搜索`,onClick:()=>{b(``),S(``),w(``),P.current?.focus()}}),(0,Z.jsx)(u,{icon:`search`,type:`submit`,label:`搜索`,disabled:!y.trim()})]})]})]}),actions:se,href:`/projects/${o}/materials${c&&!_?`?${new URLSearchParams({...c})}`:``}`})}function ce({query:e,scope:t,onSelect:n}){let{request:i}=L(),[a,o]=(0,K.useState)(``),c=(0,K.useCallback)(n=>i(`resources/search?${new URLSearchParams({query:e,scope:`materials`,after:a,...t?{materialId:t.id}:{},...t?.original?{originalHash:t.original}:{}})}`,ie,{signal:n}),[i,e,t?.id,t?.original,a]),l=r(c);return(0,Z.jsxs)(`section`,{className:`session-results stack`,"aria-label":`搜索结果`,children:[(0,Z.jsx)(s,{error:!0,children:l.error}),l.loading?(0,Z.jsx)(`p`,{role:`status`,children:`正在搜索…`}):l.data?.items.length===0?(0,Z.jsx)(`p`,{className:`empty`,children:`没有找到匹配的资料`}):l.data?.items.map(t=>(0,Z.jsxs)(`button`,{className:`session-item`,"data-testid":`material-match`,onClick:()=>{let e=new URL(t.url,location.origin).searchParams;n({id:e.get(`id`),...e.get(`original`)?{original:e.get(`original`)}:{},...e.get(`revision`)?{revision:e.get(`revision`)}:{}})},children:[(0,Z.jsx)(`strong`,{children:t.title.replace(/^R\d+ · /,``)}),(0,Z.jsx)(`span`,{className:`session-excerpt`,children:(0,Z.jsx)(R,{value:z(t.snippet,e),query:e})})]},t.key)),l.data?.nextCursor&&(0,Z.jsx)(`button`,{disabled:l.loading,onClick:()=>o(l.data.nextCursor),children:`下一页`})]})}function le({material:e,hash:t,highlight:n}){let{projectId:i}=L(),a=e.originals.find(e=>e.sha256===t),o=I(`/api/v1/projects/${i}/materials/${e.id}/originals/${t}?revision=${e.revision}`),[c,d]=(0,K.useState)(!1),f=(0,K.useCallback)(async e=>{let t=await fetch(o,{signal:e});if(!t.ok)throw Error(`原件暂时无法读取。`);let n=await t.arrayBuffer();try{let e=new TextDecoder(`utf8`,{fatal:!0}).decode(n);return e.includes(`\0`)?null:e}catch{return null}},[o]),m=r(f,!1,p(i,`material-original`,t));if(!a)return(0,Z.jsx)(s,{error:!0,children:`找不到此原件。`});let h=/\.(md|markdown)$/i.test(a.name),g=/\.html?$/i.test(a.name);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`header`,{className:`file-detail-header`,children:[(0,Z.jsx)(`span`,{className:`file-detail-path`,children:a.name}),(0,Z.jsxs)(`div`,{className:`toolbar-actions`,children:[(h||g)&&(0,Z.jsx)(u,{icon:c?`preview`:`code`,label:c?`切换为预览`:`切换为原文`,"aria-pressed":c,onClick:()=>d(!c)}),(0,Z.jsx)(`a`,{className:`icon-button`,"aria-label":`下载原件`,title:`下载原件`,href:o,download:a.name,children:(0,Z.jsx)(l,{name:`download`})})]})]}),(0,Z.jsx)(s,{error:!0,children:m.error}),m.loading?(0,Z.jsx)(`p`,{role:`status`,children:`加载中…`}):m.data===null?(0,Z.jsx)(`p`,{className:`muted`,children:`此格式请下载后查看。`}):m.data!==void 0&&(0,Z.jsx)(`div`,{className:`preview-body${g&&!c?` preview-body-html`:``}`,"data-testid":`material-original-content`,children:g&&!c?(0,Z.jsx)(W,{url:o,name:a.name}):h&&!c?(0,Z.jsx)(`article`,{className:`markdown`,children:(0,Z.jsx)(B,{highlight:n,children:m.data})}):(0,Z.jsx)(`pre`,{className:`raw`,children:(0,Z.jsx)(R,{value:m.data,query:n})})})]})}function ue(e){if(e.kind===`text`){try{if([`http:`,`https:`].includes(new URL(e.text.trim()).protocol))return`link`}catch{}return`text`}let{name:t,type:n}=e.file;return n.startsWith(`image/`)||/\.(png|jpe?g|gif|webp|svg|heic|avif)$/i.test(t)?`imageFile`:/\.(csv|tsv|xlsx?|ods)$/i.test(t)?`spreadsheetFile`:/\.(json|ya?ml|xml|html?|css|[cm]?[jt]sx?|py|go|rs|sh|sql)$/i.test(t)?`codeFile`:n.startsWith(`text/`)||/\.(pdf|docx?|odt|rtf|md|txt)$/i.test(t)?`file`:`attachment`}function Q(e){try{return new URL(e.trim()).hostname}catch{return e.trim().split(`
4
- `)[0]?.slice(0,80)||`文本`}}function de(e){try{return new URL(e.trim()).href}catch{return e.trim().split(`
5
- `).slice(1).join(`
6
- `)}}function fe({onSaved:e,onCancel:t}){let{request:n,projectId:r}=L(),[o,d]=(0,K.useState)([]),[f,p]=(0,K.useState)(),[m,g]=(0,K.useState)(!1),[_,v]=(0,K.useState)(``),y=(0,K.useRef)(null),b=(0,K.useRef)(h()),x=(0,K.useRef)(new Map);function S(e){d(e),b.current=h(),v(``)}async function C(){g(!0),v(``);try{let t=[];for(let[e,n]of o.entries()){let i=x.current.get(n.id);if(!i){let t=n.kind===`file`?n.file.name:`${Q(n.text)}.txt`,a=await fetch(I(`/api/v1/projects/${r}/materials/uploads`),{method:`POST`,headers:{"content-type":`application/octet-stream`,"x-teammy-web":`1`},body:n.kind===`file`?n.file:new Blob([n.text],{type:`text/plain`})}),o=await a.json();if(!a.ok)throw Error(o.error?.message??`第 ${e+1} 项上传失败。`);i={name:t,sha256:o.sha256,size:o.size},x.current.set(n.id,i)}t.push(i)}let i=o.length===1&&o[0]?.kind===`text`?o[0].text.trim():``,a;try{let e=new URL(i);[`http:`,`https:`].includes(e.protocol)&&(a=e.href)}catch{}e((await n(`materials`,X,{method:`POST`,body:{operationId:b.current,originals:t,...a?{url:a}:{}}})).id)}catch(e){v(a(e))}finally{g(!1)}}return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`form`,{className:`material-form`,onSubmit:e=>{e.preventDefault(),C()},children:[(0,Z.jsx)(`h1`,{children:`新增资料`}),(0,Z.jsx)(`p`,{className:`muted`,children:`上传附件到项目,以便于Tim进行理解`}),(0,Z.jsx)(s,{error:!0,children:_}),(0,Z.jsxs)(`fieldset`,{disabled:m,children:[(0,Z.jsxs)(`div`,{className:`attachment-grid`,children:[o.map(e=>(0,Z.jsxs)(`article`,{className:`attachment-card`,"data-testid":`attachment-card`,children:[e.kind===`text`?(0,Z.jsxs)(`button`,{type:`button`,className:`attachment-content`,"aria-label":`编辑:${Q(e.text)}`,onClick:()=>p({id:e.id,text:e.text}),children:[(0,Z.jsx)(l,{name:ue(e)}),(0,Z.jsx)(`span`,{className:`attachment-name`,children:Q(e.text)}),de(e.text)&&(0,Z.jsx)(`span`,{className:`attachment-excerpt`,children:de(e.text)})]}):(0,Z.jsxs)(`div`,{className:`attachment-content`,children:[(0,Z.jsx)(l,{name:ue(e)}),(0,Z.jsx)(`span`,{className:`attachment-name`,children:e.file.name})]}),(0,Z.jsx)(u,{className:`attachment-remove`,icon:`close`,label:`移除:${e.kind===`file`?e.file.name:Q(e.text)}`,onClick:()=>{x.current.delete(e.id),S(o.filter(t=>t.id!==e.id))}})]},e.id)),(0,Z.jsxs)(`button`,{type:`button`,className:`attachment-add`,onClick:()=>p({text:``}),children:[(0,Z.jsx)(l,{name:`addText`}),(0,Z.jsx)(`span`,{children:`添加文本/链接`})]}),(0,Z.jsxs)(`button`,{type:`button`,className:`attachment-add`,onClick:()=>y.current?.click(),children:[(0,Z.jsx)(l,{name:`addFile`}),(0,Z.jsx)(`span`,{children:`添加文件`})]})]}),(0,Z.jsx)(`input`,{ref:y,type:`file`,multiple:!0,hidden:!0,"aria-label":`原始文件`,onChange:e=>{S([...o,...[...e.target.files??[]].map(e=>({id:h(),kind:`file`,file:e}))]),e.target.value=``}}),(0,Z.jsxs)(`div`,{className:`actions attachment-actions`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:t,children:`取消`}),(0,Z.jsx)(`button`,{type:`submit`,className:`primary`,disabled:!o.length,children:m?`上传中…`:`提交资料`})]})]})]}),f&&(0,Z.jsx)(i,{id:`material-text-editor`,title:`添加文本/链接`,onClose:()=>p(void 0),children:(0,Z.jsxs)(`form`,{className:`stack`,onSubmit:e=>{if(e.preventDefault(),!f.text.trim())return;let t={id:f.id??h(),kind:`text`,text:f.text};x.current.delete(t.id),S(f.id?o.map(e=>e.id===f.id?t:e):[...o,t]),p(void 0)},children:[(0,Z.jsx)(c,{id:`material-attachment-text`,label:`文本或链接`,children:(0,Z.jsx)(`textarea`,{autoFocus:!0,rows:8,value:f.text,onChange:e=>p({...f,text:e.target.value}),placeholder:`粘贴文本或网页链接`})}),(0,Z.jsx)(`div`,{className:`actions`,children:(0,Z.jsx)(`button`,{type:`submit`,className:`primary`,disabled:!f.text.trim(),children:f.id?`保存`:`添加`})})]})})]})}var pe=v([`overview`,`handoff`]),me=F({title:x().trim().min(1),summary:x().trim().min(1)}).strict(),he=F({markdown:x().trim().min(1)}).strict(),ge=me.extend({sourceRevision:A,sourceHash:P,generatedAt:x(),stale:N()}),_e=F({kind:pe,status:v([`absent`,`queued`,`running`,`succeeded`,`failed`]),available:N(),currentRevision:A,sourceRevision:A.nullable(),stale:N(),result:C([me,he]).nullable(),generatedAt:x().nullable(),error:x().nullable()}),ve=v([`claude-code`,`codex`,`cursor`,`pi`,`dsh`]),ye=F({formatVersion:y(1),adapterVersion:y(1),agent:ve,nativeId:x().min(1).max(512),cwd:x().min(1).max(4096),messages:j(F({id:x().min(1).max(1024),role:v([`user`,`assistant`]),text:x().min(1),source:x().min(1).max(1024)}).strict())}).strict().refine(e=>new Set(e.messages.map(e=>e.id)).size===e.messages.length,`Duplicate message IDs.`);F({operationId:E(),sessionKey:P,parentRevision:A,blob:e}).strict(),F({revision:A,hash:P.nullable(),cleared:N()});var be=F({owner:M,sessionKey:P,agent:ve,nativeId:x(),cwd:x(),title:x(),revision:A,updatedAt:x(),messageCount:O().int().nonnegative(),blob:e,overview:ge.optional()}),xe=F({sessions:j(be),nextCursor:A.nullable()}),Se=F({totalSessions:O().int().nonnegative(),totalMessages:O().int().nonnegative(),memberCount:O().int().nonnegative(),updatedAt:x().nullable()});F({owner:M.optional(),sessionKey:P.optional()}).strict().refine(e=>!e.sessionKey||!!e.owner,`A session scope requires an owner.`);var Ce=F({matches:j(F({owner:M,sessionKey:P,revision:A,messageId:x(),source:v([`message`,`handoff`]).default(`message`),role:v([`user`,`assistant`]),snippet:x(),title:x()})),nextCursor:A.nullable()}),we=F({owner:M,key:P,revision:A.refine(e=>e>0).optional(),messageId:x().min(1).optional(),source:v([`message`,`handoff`]).optional()});function Te(e){let t=new URLSearchParams(e);if(![`owner`,`sessionKey`,`revision`,`messageId`].some(e=>t.has(e)))return{};let n=we.safeParse({owner:t.get(`owner`),key:t.get(`sessionKey`),...t.has(`revision`)?{revision:Number(t.get(`revision`))}:{},...t.has(`messageId`)?{messageId:t.get(`messageId`)}:{},...t.has(`source`)?{source:t.get(`source`)}:{}});return n.success?{target:n.data}:{error:`对话链接不完整或已损坏。`}}function Ee({members:e,refresh:t,selected:n,onOwner:r,onSession:i,level:a=1}){let[o,s]=(0,K.useState)(()=>new Set(n?.key?[n.owner]:[])),[c,u]=(0,K.useState)(e[0]?.id??``);return(0,Z.jsx)(`div`,{role:a===1?`tree`:`group`,"aria-label":`成员对话`,"data-testid":`session-tree`,onKeyDown:a===1?H:void 0,children:[...e].sort((e,t)=>ne(e.id,t.id)).map(e=>(0,Z.jsxs)(`div`,{role:`none`,children:[(0,Z.jsxs)(T,{type:`button`,role:`treeitem`,"aria-level":a,"aria-expanded":o.has(e.id),"aria-selected":n?.owner===e.id&&!n.key,className:`tree-item tree-folder`,style:{"--tree-level":a},tabIndex:c===e.id?0:-1,"data-testid":`session-owner`,"data-owner-id":e.id,onFocus:()=>u(e.id),onClick:()=>{s(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),r(e.id)},leading:(0,Z.jsx)(`span`,{className:`tree-chevron ${o.has(e.id)?`expanded`:``}`,children:(0,Z.jsx)(l,{name:`chevron`,size:`small`})}),children:[(0,Z.jsx)(l,{name:`files`}),(0,Z.jsx)(`span`,{className:`tree-name`,title:e.id,children:e.id})]}),o.has(e.id)&&(0,Z.jsx)(De,{level:a+1,owner:e.id,selected:n,onSession:i,focused:c,onFocus:u},`${e.id}/${t}`)]},e.id))})}function De({level:e,owner:t,selected:n,onSession:i,focused:o,onFocus:c}){let{request:u,projectId:d}=L(),f=(0,K.useCallback)(e=>u(`sessions?${new URLSearchParams({owner:t,limit:`50`,order:`updated`})}`,xe,{signal:e}),[t,u]),m=r(f,15e3,p(d,`session-tree`,t)),[h,_]=(0,K.useState)(),[v,y]=(0,K.useState)(!1),[b,x]=(0,K.useState)(``),S=(0,K.useRef)(null);(0,K.useEffect)(()=>()=>S.current?.abort(),[]);let C=h?h.nextCursor:m.data?.nextCursor;return(0,Z.jsxs)(`div`,{role:`group`,"aria-busy":m.loading||v,children:[(0,Z.jsx)(s,{error:!0,children:m.error||b}),m.error&&(0,Z.jsx)(`button`,{onClick:()=>void m.reload(),children:`重试`}),m.loading&&!m.data&&(0,Z.jsx)(`span`,{className:`tree-status`,role:`status`,children:`正在加载…`}),[...new Map([...h?.sessions??[],...m.data?.sessions??[]].map(e=>[e.sessionKey,e])).values()].sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt)||e.sessionKey.localeCompare(t.sessionKey)).map(r=>(0,Z.jsxs)(T,{type:`button`,role:`treeitem`,"aria-level":e,"aria-selected":n?.owner===t&&n.key===r.sessionKey,className:`tree-item`,style:{"--tree-level":e},tabIndex:o===`${t}/${r.sessionKey}`?0:-1,"data-testid":`session-row`,"data-owner-id":t,"data-session-key":r.sessionKey,title:g(r.title||r.nativeId),onFocus:()=>c(`${t}/${r.sessionKey}`),onClick:()=>i({owner:t,key:r.sessionKey,title:r.title||r.nativeId}),leading:(0,Z.jsx)(`span`,{className:`tree-chevron`}),children:[(0,Z.jsx)(l,{name:`sessions`}),(0,Z.jsx)(`span`,{className:`tree-name`,children:g(r.title||r.nativeId)})]},r.sessionKey)),C!=null&&(0,Z.jsx)(`button`,{className:`tree-action`,"data-testid":`session-tree-more`,disabled:v,onClick:async()=>{y(!0),x(``);let e=new AbortController;S.current=e;try{let n=await u(`sessions?${new URLSearchParams({owner:t,after:String(C),limit:`50`,order:`updated`})}`,xe,{signal:e.signal});_(e=>({sessions:[...e?.sessions??[],...n.sessions],nextCursor:n.nextCursor}))}catch(t){e.signal.aborted||x(a(t))}finally{e.signal.aborted||y(!1)}},children:`加载更多`})]})}function Oe({info:e,targeted:t=!1,highlight:n=``}){let[r,i]=(0,K.useState)(t),a=(0,K.useRef)(null);return(0,K.useEffect)(()=>{t&&a.current?.scrollIntoView({block:`center`})},[t]),(0,Z.jsxs)(`details`,{ref:a,open:r,className:`session-handoff`,onToggle:e=>i(e.currentTarget.open),children:[(0,Z.jsx)(`summary`,{children:`交接说明`}),r&&(0,Z.jsx)(ke,{info:e,revision:t?e.revision:void 0,highlight:n})]})}function ke({info:e,revision:n,highlight:i}){let{request:o}=L(),c=`sessions/${encodeURIComponent(e.owner)}/${e.sessionKey}`,l=(0,K.useCallback)(e=>o(`${c}/analysis/handoff${n===void 0?``:`?revision=${n}`}`,_e,{signal:e}),[o,c,n]),u=r(l,5e3),d=m(),[f,p]=(0,K.useState)(!1),[h,g]=(0,K.useState)(``),_=u.data,v=f||_?.status===`queued`||_?.status===`running`,y=_?.result&&`markdown`in _.result?_.result.markdown:void 0;return(0,Z.jsxs)(`div`,{className:`stack`,"data-testid":`session-handoff`,children:[(0,Z.jsx)(s,{error:!0,children:h||u.error}),u.loading&&!_&&(0,Z.jsx)(`small`,{role:`status`,children:`正在加载…`}),_&&(0,Z.jsxs)(`div`,{className:`inline-actions`,children:[_.status===`failed`&&n===void 0&&(0,Z.jsx)(`button`,{"data-testid":`session-handoff-generate`,disabled:v||!_.available,onClick:async()=>{p(!0),g(``);try{await o(`${c}/handoff`,_e,{method:`POST`,signal:d}),await u.reload()}catch(e){d.aborted||g(a(e))}finally{d.aborted||p(!1)}},children:v?`正在整理…`:`重试`}),!_.available&&(0,Z.jsx)(`small`,{children:`请先配置项目模型接入点`}),_.status===`failed`&&(0,Z.jsx)(`small`,{children:`整理未完成,可重试`}),_.available&&_.status!==`failed`&&(!y||_.stale||v)&&(0,Z.jsx)(`small`,{role:`status`,children:_.status===`running`||f?`正在整理…`:y?`对话已有新内容,等待自动更新…`:`等待自动整理…`}),_.currentRevision!==e.revision&&(0,Z.jsx)(`small`,{children:`交接说明使用最新对话;当前阅读的是历史原文`})]}),y&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`small`,{children:[`基于版本 `,_.sourceRevision,` · `,(0,Z.jsx)(t,{value:_.generatedAt})]}),(0,Z.jsx)(`div`,{className:`markdown`,"data-testid":`session-handoff-body`,children:(0,Z.jsx)(B,{highlight:i,children:y})})]})]})}function Ae({members:e,active:t,onActivate:n,children:i}){let{request:a,projectId:o,api:c}=L(),l=(0,K.useCallback)(async e=>{let[t,n]=await Promise.all([a(`sessions/stats`,Se,{signal:e}),c.members(e)]);return{...t,members:n.members}},[a,c]),f=r(l,!0,p(o,`session-stats`)),[m,h]=(0,K.useState)(``),[_,v]=(0,K.useState)(``),[y,x]=(0,K.useState)(0),[S]=(0,K.useState)(()=>Te(location.search)),[C,w]=(0,K.useState)(S.target),[T,E]=(0,K.useState)(S.target),[D,O]=(0,K.useState)(S.error??``),[k,A]=(0,K.useState)(``),j=(0,K.useRef)(null),M=C?.key?C.title?`搜索对话:${g(C.title)}`:`搜索当前对话`:C?`搜索:${C.owner} 的对话内容`:``,N=()=>{w(void 0),A(``),P(),j.current?.focus()};function P(){if(!T?.messageId)return;let{messageId:e,...t}=T;E(t),history.replaceState(null,``,I(U(o,t.owner,t.key,t)))}let F=(0,K.useCallback)(e=>{w(t=>t?.owner===e.owner&&t.key===e.sessionKey&&t.title!==e.title?{...t,title:e.title}:t)},[]);(0,K.useEffect)(()=>{let e=()=>{if(!te().endsWith(`/sessions`))return;let e=Te(location.search);E(e.target),w(e.target),O(e.error??``),v(``),h(``),A(``)};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]);let R=(e,t=``)=>{n(),E(e),w(e),v(``),A(t),O(``),history.replaceState(null,``,I(U(o,e.owner,e.key,e)))},z=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(s,{error:!0,children:f.error}),(0,Z.jsx)(Ee,{members:(f.data?.members??e).filter(e=>e.hasSessions),refresh:y,selected:t?C:void 0,level:2,onOwner:e=>{n(),w({owner:e}),E(void 0),v(``),A(``),O(``),history.replaceState(null,``,I(`/projects/${encodeURIComponent(o)}/sessions`))},onSession:R})]}),B=(0,Z.jsxs)(`section`,{className:`session-reader`,"aria-label":`对话内容与搜索`,children:[(0,Z.jsx)(b,{title:d.sessions,icon:`sessions`,count:(0,Z.jsx)(`span`,{"data-testid":`session-total`,children:f.data?.totalSessions??`—`}),children:(0,Z.jsx)(u,{icon:`refresh`,label:`刷新${d.sessions}`,"data-testid":`sessions-refresh`,disabled:f.loading,onClick:()=>{f.reload(),x(e=>e+1)}})}),(0,Z.jsx)(`div`,{className:`session-reader-content`,children:D?(0,Z.jsx)(s,{error:!0,children:D}):_?(0,Z.jsx)(je,{query:_,refresh:y,scope:{...C?{owner:C.owner}:{},...C?.key?{sessionKey:C.key}:{}},onSelect:e=>R(e,_)},`${_}/${C?.owner??``}/${C?.key??``}`):T?(0,Z.jsx)(Me,{selection:T,highlight:k,onLoaded:F,onLatest:()=>R({owner:T.owner,key:T.key})},`${T.owner}/${T.key}/${T.revision}/${T.source}/${y}`):(0,Z.jsx)(ee,{mascot:!0,title:`选择对话开始阅读`,description:`也可以在下方搜索会话库内容。`})}),(0,Z.jsxs)(`form`,{className:`session-search-dock`,"data-testid":`session-search-form`,onSubmit:e=>{e.preventDefault(),v(m.trim()),A(``),O(``),x(e=>e+1)},children:[C&&(0,Z.jsxs)(`button`,{type:`button`,className:`search-scope-chip`,"data-testid":`session-search-scope`,title:`清除搜索范围`,"aria-label":`清除范围:${M}`,onClick:N,children:[(0,Z.jsx)(`span`,{className:`scope-label`,children:M}),(0,Z.jsx)(`span`,{"aria-hidden":`true`,children:`×`})]}),(0,Z.jsxs)(`div`,{className:`session-search-input-row`,children:[(0,Z.jsx)(`input`,{ref:j,"aria-label":`搜索对话`,"data-testid":`session-query`,value:m,maxLength:500,placeholder:`搜索会话库内容`,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Backspace`&&!m&&C&&(e.preventDefault(),N())}}),(_||m||k)&&(0,Z.jsx)(u,{icon:`close`,label:`清空搜索`,"data-testid":`session-search-clear`,onClick:()=>{h(``),v(``),A(``),P(),j.current?.focus()}}),(0,Z.jsx)(u,{icon:`search`,type:`submit`,label:`搜索`,"data-testid":`session-search`,disabled:!m.trim()})]})]})]});return i({hasSelection:!!C,tree:z,reader:B,href:T?U(o,T.owner,T.key,T):`/projects/${o}/sessions`})}function je({query:e,refresh:t,scope:n,onSelect:i}){let{request:a}=L(),[o,c]=(0,K.useState)(0),l=(0,K.useCallback)(t=>a(`sessions/search?${new URLSearchParams({q:e,after:String(o),limit:`30`,order:`updated`,...n.owner?{owner:n.owner}:{},...n.sessionKey?{sessionKey:n.sessionKey}:{}})}`,Ce,{signal:t}),[a,e,o,t,n.owner,n.sessionKey]),u=r(l);return(0,Z.jsxs)(`section`,{className:`session-results stack`,"aria-label":`搜索结果`,"aria-busy":u.loading,children:[(0,Z.jsx)(s,{error:!0,children:u.error}),u.error&&(0,Z.jsx)(`button`,{onClick:()=>void u.reload(),children:`重试`}),u.loading&&(0,Z.jsx)(`p`,{role:`status`,children:`正在搜索…`}),!u.loading&&u.data?.matches.map(t=>(0,Z.jsxs)(`button`,{className:`session-item`,"data-testid":`session-match`,"data-message-id":t.messageId,onClick:()=>i({owner:t.owner,key:t.sessionKey,revision:t.revision,messageId:t.messageId||void 0,source:t.source,title:t.title}),children:[(0,Z.jsx)(`strong`,{children:g(t.title)}),(0,Z.jsxs)(`small`,{children:[t.owner,` ·`,` `,t.source===`handoff`?`交接说明`:t.role===`user`?`用户`:`助手`]}),(0,Z.jsx)(`span`,{className:`session-excerpt`,children:(0,Z.jsx)(R,{value:z(t.snippet,e),query:e})})]},`${t.owner}:${t.sessionKey}:${t.revision}:${t.source}:${t.messageId}`)),!u.loading&&u.data?.matches.length===0&&(0,Z.jsx)(`p`,{className:`empty`,children:`没有找到匹配的对话`}),u.data?.nextCursor!=null&&(0,Z.jsx)(`button`,{"data-testid":`sessions-next`,disabled:u.loading,onClick:()=>c(u.data.nextCursor),children:`下一页`}),o>0&&(0,Z.jsx)(`button`,{disabled:u.loading,onClick:()=>c(0),children:`返回第一页`})]})}function Me({selection:e,highlight:t,onLoaded:n,onLatest:i}){let{request:a}=L(),c=(0,K.useCallback)(async t=>{try{return await a(`sessions/${encodeURIComponent(e.owner)}/${e.key}${e.revision===void 0?``:`?revision=${e.revision}`}`,be,{signal:t})}catch(e){throw e instanceof o&&e.code===`SESSION_NOT_FOUND`?Error(`找不到这条对话或引用的版本,原链接可能已失效。`):e}},[a,e.owner,e.key,e.revision]),l=r(c,5e3);return(0,K.useEffect)(()=>{l.data&&n(l.data)},[l.data,n]),(0,Z.jsxs)(`section`,{className:`session-conversation stack`,"data-testid":`session-detail`,children:[(0,Z.jsx)(s,{error:!0,children:l.error}),l.error&&(0,Z.jsx)(`button`,{onClick:()=>void l.reload(),children:`重试`}),l.loading&&!l.data&&(0,Z.jsx)(`p`,{role:`status`,children:`正在读取对话…`}),l.data&&(0,Z.jsx)(Ne,{info:l.data,messageId:e.messageId,handoff:e.source===`handoff`,highlight:t,pinned:e.revision!==void 0,onLatest:i},l.data.blob.sha256)]})}function Ne({info:e,messageId:n,handoff:i,highlight:a,pinned:o,onLatest:c}){let{readTextBlob:l,projectId:u}=L(),d=(0,K.useCallback)(async t=>ye.parse(JSON.parse(await l(e.blob,t))),[e.blob.sha256,e.blob.size]),f=r(d),p=(0,K.useRef)(null);return(0,K.useEffect)(()=>{f.data&&n&&p.current?.scrollIntoView({block:`center`})},[f.data,n]),(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`header`,{className:`conversation-header`,children:[(0,Z.jsx)(`h2`,{className:`session-title`,children:g(e.title||e.nativeId)}),(0,Z.jsxs)(`p`,{children:[e.owner,` · `,e.agent,` · `,e.messageCount,` 条消息`]}),(0,Z.jsxs)(`small`,{children:[(0,Z.jsx)(t,{value:e.updatedAt}),o&&(0,Z.jsxs)(Z.Fragment,{children:[` `,`· 引用版本 `,e.revision,` ·`,` `,(0,Z.jsx)(`a`,{href:I(U(u,e.owner,e.sessionKey)),onClick:e=>{e.preventDefault(),c()},children:`查看最新`})]})]}),e.overview&&(0,Z.jsx)(`p`,{"data-testid":`session-summary`,children:e.overview.summary}),e.overview?.stale&&(0,Z.jsx)(`small`,{children:`摘要待更新`})]}),(0,Z.jsx)(Oe,{info:e,targeted:i,highlight:i?a:``}),(0,Z.jsx)(s,{error:!0,children:f.error}),f.error&&(0,Z.jsx)(`button`,{onClick:()=>void f.reload(),children:`重新读取`}),f.loading&&(0,Z.jsx)(`p`,{role:`status`,children:`正在读取对话…`}),f.data&&(0,Z.jsxs)(Z.Fragment,{children:[n&&!f.data.messages.some(e=>e.id===n)&&(0,Z.jsx)(s,{children:`该版本中找不到引用的消息,已打开对话原文。`}),(0,Z.jsx)(`div`,{className:`session-messages`,children:f.data.messages.map(e=>(0,Z.jsx)(V,{mine:e.role===`user`,author:e.role===`user`?`用户`:`助手`,className:`session-message ${e.role} ${e.id===n?`matched`:``}`,"data-testid":`session-message`,"data-message-id":e.id,ref:e.id===n?p:void 0,children:(0,Z.jsx)(`div`,{className:`markdown`,children:(0,Z.jsx)(B,{highlight:a,children:e.text})})},e.id))})]})]})}var $=x().trim().min(1).max(120).refine(e=>!/[\r\n]/.test(e),`请使用一句简短的项目记忆。`),Pe=F({id:E(),text:$,state:v([`draft`,`kept`]),revision:O().int().positive(),createdAt:x(),updatedAt:x()}),Fe=F({cards:j(Pe)});F({id:E(),text:$}).strict(),F({expectedRevision:O().int().positive(),text:$.optional(),action:v([`keep`,`discard`,`delete`]).optional()}).strict().refine(e=>e.text!==void 0||e.action!==void 0,`没有需要保存的修改。`),F({text:$}).strict();function Ie(){let{request:e,projectId:t}=L(),n=(0,K.useCallback)(t=>e(`memory`,Fe,{signal:t}),[e]),i=r(n,5e3,p(t,`memory`)),[a,o]=(0,K.useState)(null),[c,l]=(0,K.useState)({}),d=(0,K.useRef)(null),m=[...i.data?.cards??[]];for(let e of Object.values(c))m.some(t=>t.id===e.id)||m.push(e);if(i.data&&!d.current&&(d.current=[...m].sort((e,t)=>Number(t.state===`kept`)-Number(e.state===`kept`)).map(e=>e.id)),d.current){let e=new Map(d.current.map((e,t)=>[e,t]));for(let t of m)e.has(t.id)||(e.set(t.id,d.current.length),d.current.push(t.id));m.sort((t,n)=>e.get(t.id)-e.get(n.id))}return(0,Z.jsxs)(`section`,{className:`memory-page`,children:[(0,Z.jsx)(f,{title:`记忆`,children:(0,Z.jsx)(u,{icon:`plus`,label:`新增记忆`,disabled:!!a,onClick:()=>o(h())})}),(0,Z.jsx)(s,{error:!0,children:i.error}),!i.data&&i.loading&&(0,Z.jsx)(`p`,{role:`status`,children:`加载中…`}),(0,Z.jsxs)(`div`,{className:`memory-cards`,children:[a&&(0,Z.jsx)(Le,{id:a,onDone:()=>o(null),reload:i.reload},a),m.map(e=>(0,Z.jsx)(Le,{id:e.id,card:e,reload:i.reload,onEditing:t=>l(n=>{let r={...n};return t?r[e.id]=e:delete r[e.id],r})},e.id))]}),i.data&&m.length===0&&!a&&(0,Z.jsx)(`p`,{className:`memory-empty`,children:`暂无记忆`})]})}function Le({id:e,card:t,reload:n,onDone:r,onEditing:i}){let{request:o}=L(),[c,d]=(0,K.useState)(!t),[f,p]=(0,K.useState)(t?.text??``),[m,h]=(0,K.useState)(t?.revision),[g,_]=(0,K.useState)(!1),[v,y]=(0,K.useState)(``),b=(0,K.useRef)(!1),x=(0,K.useRef)(!1);function S(){x.current=!1,i?.(!0),p(t?.text??``),h(t?.revision),y(``),d(!0)}function C(){x.current=!0,d(!1),y(``),i?.(!1),r?.()}async function w(s){if(!b.current){if(!s&&t&&f===t.text)d(!1),i?.(!1);else if((!s||s===`keep`)&&!$.safeParse(c?f:t?.text).success)y(`请填写一句记忆,最多 120 个字符。`);else{b.current=!0,_(!0),y(``);try{t?await o(`memory/${e}`,F({saved:N()}),{method:`PATCH`,body:{expectedRevision:c?m:t.revision,...s?{action:s}:{},...c&&s!==`discard`&&s!==`delete`?{text:f}:{}}}):await o(`memory`,Pe,{method:`POST`,body:{id:e,text:f}}),d(!1),await n(),i?.(!1),r?.()}catch(e){y(a(e)),await n()}finally{b.current=!1,_(!1)}}}}return(0,Z.jsxs)(`article`,{className:`memory-card`,"data-testid":`memory-card`,"data-memory-id":e,children:[(0,Z.jsx)(`span`,{className:`memory-status ${t?.state===`kept`?`is-kept`:``}`,role:`img`,"aria-label":t?.state===`kept`?`已保留`:`待确认`,children:(0,Z.jsx)(l,{name:t?.state===`kept`?`check`:`question`})}),(0,Z.jsxs)(`div`,{className:`memory-content`,children:[c?(0,Z.jsx)(`textarea`,{autoFocus:!0,"aria-label":`记忆内容`,value:f,maxLength:120,rows:2,disabled:g,onChange:e=>p(e.target.value.replace(/[\r\n]+/g,` `)),onBlur:e=>{x.current?x.current=!1:e.relatedTarget instanceof Element&&e.relatedTarget.closest(`.memory-actions`)||v||w()},onKeyDown:e=>{e.nativeEvent.isComposing||(e.key===`Escape`&&(e.preventDefault(),C()),e.key===`Enter`&&(e.preventDefault(),w()))}}):(0,Z.jsx)(`button`,{type:`button`,className:`memory-text`,"aria-label":`编辑记忆:${t?.text??``}`,onClick:S,children:t?.text}),(0,Z.jsx)(s,{error:!0,children:v})]}),(0,Z.jsxs)(`div`,{className:`memory-actions`,onMouseDown:e=>{c&&e.preventDefault()},children:[(!t||t.state===`draft`)&&(0,Z.jsx)(u,{icon:`check`,label:t?`保留记忆`:`保存记忆`,disabled:g,onClick:()=>void w(t?`keep`:void 0)}),c&&t?.state===`kept`&&(0,Z.jsx)(u,{icon:`check`,label:`保存记忆`,disabled:g,onClick:()=>void w()}),(0,Z.jsx)(u,{icon:`close`,label:t?t.state===`draft`?`舍弃记忆`:`删除记忆`:`取消新增`,disabled:g,onClick:()=>{t?w(t.state===`draft`?`discard`:`delete`):C()}})]})]})}function Re({section:e,members:t,navigate:n}){let{projectId:r}=L(),[i,a]=(0,K.useState)(e===`sessions`);(0,K.useEffect)(()=>{e===`sessions`&&a(!0)},[e]);let o=t=>{e!==t&&n(`/projects/${r}/${t}`)};return(0,Z.jsx)(se,{active:e===`materials`,onActivate:()=>o(`materials`),children:r=>(0,Z.jsx)(Ae,{members:t,active:e===`sessions`,onActivate:()=>o(`sessions`),children:t=>(0,Z.jsx)(S,{reading:!0,className:`resource-library`,"data-testid":`materials-page`,label:`资料目录`,navigation:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(b,{title:`资料`,icon:`materials`,children:r.actions}),(0,Z.jsxs)(`div`,{role:`tree`,"aria-label":`项目资料`,onKeyDown:H,style:{"--tree-level":1},children:[(0,Z.jsxs)(T,{role:`treeitem`,"aria-level":1,"aria-selected":e===`memory`,className:`tree-item tree-folder`,"data-testid":`library-memory`,leading:(0,Z.jsx)(`span`,{className:`tree-chevron`}),onClick:()=>o(`memory`),children:[(0,Z.jsx)(l,{name:`files`}),(0,Z.jsx)(`span`,{className:`tree-name`,children:`记忆`})]}),(0,Z.jsxs)(T,{role:`treeitem`,"aria-level":1,"aria-expanded":i,"aria-selected":e===`sessions`&&!t.hasSelection,className:`tree-item tree-folder`,"data-testid":`library-sessions`,leading:(0,Z.jsx)(`span`,{className:`tree-chevron ${i?`expanded`:``}`,children:(0,Z.jsx)(l,{name:`chevron`,size:`small`})}),onClick:()=>{a(!i),e!==`sessions`&&n(t.href)},children:[(0,Z.jsx)(l,{name:`files`}),(0,Z.jsx)(`span`,{className:`tree-name`,children:`会话库`})]}),(0,Z.jsx)(`div`,{hidden:!i,children:t.tree}),r.tree]})]}),children:e===`materials`?r.reader:e===`sessions`?t.reader:(0,Z.jsx)(`section`,{className:`session-reader`,"aria-label":`项目记忆`,children:(0,Z.jsx)(Ie,{})})})})})}export{Re as ResourceLibrary};
@@ -1 +0,0 @@
1
- import{G as e,H as t,J as n,L as r,N as i,U as a,_t as o,c as s,h as c,l,s as u,u as d,y as f}from"./index-BQicHl1a.js";var p=o(),m=new Intl.Collator(`zh-CN`,{numeric:!0,sensitivity:`base`});function h(e,t){return m.compare(e,t)||(e<t?-1:+(e>t))}var g=e();function _(e){let t=e.target.closest(`[role="treeitem"]`);if(!t)return;let n=[...e.currentTarget.querySelectorAll(`[role="treeitem"]`)].filter(e=>!e.closest(`[hidden]`)),r=n.indexOf(t),i=Number(t.getAttribute(`aria-level`)),a;switch(e.key){case`ArrowDown`:a=n[r+1];break;case`ArrowUp`:a=n[r-1];break;case`Home`:a=n[0];break;case`End`:a=n.at(-1);break;case`ArrowRight`:t.getAttribute(`aria-expanded`)===`false`?t.click():Number(n[r+1]?.getAttribute(`aria-level`))>i&&(a=n[r+1]);break;case`ArrowLeft`:t.getAttribute(`aria-expanded`)===`true`?t.click():a=n.slice(0,r).reverse().find(e=>Number(e.getAttribute(`aria-level`))<i);break;default:return}e.preventDefault(),a?.focus()}var v=(e,t)=>`${e}/${t}`,y=e=>({"--tree-level":e});function b({members:e,...t}){let[n,r]=(0,p.useState)(()=>`folder:${v(e.find(e=>e.hasFiles)?.id??`_project`,``)}`);return(0,g.jsx)(`div`,{role:`tree`,"aria-label":`工作区文件`,"data-testid":`workspace-tree`,onKeyDown:_,children:(0,g.jsx)(S,{owner:u,path:``,level:1,members:e.filter(e=>e.hasFiles),context:{...t,focused:n,onFocus:r}})})}function x({owner:e,path:t,level:n,context:r}){let a=r.expanded.has(v(e,t)),o=`folder:${v(e,t)}`;return(0,g.jsxs)(`div`,{role:`none`,children:[(0,g.jsxs)(c,{type:`button`,role:`treeitem`,className:`tree-item tree-folder`,style:y(n),"aria-label":t||e,"aria-level":n,"aria-expanded":a,"aria-selected":r.selected?.kind===`directory`&&r.selected.owner===e&&r.selected.path===t,tabIndex:r.focused===o?0:-1,"data-testid":`directory-row`,"data-owner-id":e,"data-directory-path":t,onFocus:()=>r.onFocus(o),onClick:()=>r.onToggle(e,t),leading:(0,g.jsx)(`span`,{className:`tree-chevron ${a?`expanded`:``}`,children:(0,g.jsx)(i,{name:`chevron`,size:`small`})}),children:[(0,g.jsx)(i,{name:`files`}),(0,g.jsx)(`span`,{className:`tree-name`,children:t.split(`/`).at(-1)||e})]}),a&&(0,g.jsx)(S,{owner:e,path:t,level:n+1,context:r})]})}function S({owner:e,path:o,level:u,context:m,members:_=[]}){let{api:b,projectId:S}=f(),C=(0,p.useCallback)(t=>b.tree(e,o,void 0,``,t),[e,o]),w=t(C,!1,a(S,`file-tree`,e,o)),[T,E]=(0,p.useState)(),[D,O]=(0,p.useState)(!1),[k,A]=(0,p.useState)(``),j=(0,p.useRef)(null);(0,p.useEffect)(()=>()=>j.current?.abort(),[]);let M=T?.revision===w.data?.revision?T:void 0,N=M?M.nextCursor:w.data?.nextCursor;async function P(){if(!N||!w.data||D)return;O(!0),A(``);let t=new AbortController;j.current=t;try{let n=await b.tree(e,o,w.data.revision,N,t.signal);t.signal.aborted||E({...n,entries:[...M?.entries??[],...n.entries]})}catch(e){t.signal.aborted||A(n(e))}finally{t.signal.aborted||O(!1)}}let F=[...(w.data?.entries??[]).filter(e=>!l(e.path)),...(M?.entries??[]).filter(e=>!l(e.path))],I=m.revealed;if(I?.owner===e&&!l(I.path)&&(!o||I.path.startsWith(o+`/`))){let e=o?I.path.slice(o.length+1):I.path,t=e.indexOf(`/`),n=t<0?I.path:[o,e.slice(0,t)].filter(Boolean).join(`/`);F.some(e=>e.path===n)||F.push(t<0?{...I.file,kind:`file`}:{kind:`directory`,path:n})}let L=[...F.filter(t=>e!==`_project`||!s(t.path)).map(t=>({...t,owner:e})),..._.map(e=>({kind:`directory`,path:``,owner:e.id}))].sort((e,t)=>e.kind===t.kind?h(e.path.split(`/`).at(-1)||e.owner,t.path.split(`/`).at(-1)||t.owner):e.kind===`directory`?-1:1);return(0,g.jsxs)(`div`,{role:`group`,"aria-label":v(d(e)?`teamcontext`:e,o),"aria-busy":w.loading||D,children:[w.loading&&(0,g.jsx)(`p`,{className:`tree-status`,role:`status`,children:`正在加载…`}),(0,g.jsx)(r,{error:!0,children:w.error||k}),w.error&&(0,g.jsx)(`button`,{className:`tree-action`,onClick:()=>void w.reload(),children:`重试`}),L.map(t=>t.kind===`directory`?(0,g.jsx)(x,{owner:t.owner,path:t.path,level:u,context:m},v(t.owner,t.path)):(0,g.jsxs)(c,{type:`button`,role:`treeitem`,className:`tree-item`,style:y(u),"aria-label":t.path,"aria-level":u,"aria-selected":m.selected?.kind===`file`&&m.selected.owner===e&&m.selected.path===t.path,tabIndex:m.focused===`file:${v(e,t.path)}`?0:-1,"data-testid":`file-row`,"data-owner-id":e,"data-file-path":t.path,onFocus:()=>m.onFocus(`file:${v(e,t.path)}`),onClick:()=>m.onSelect(e,t.path),leading:(0,g.jsx)(`span`,{className:`tree-chevron`}),children:[(0,g.jsx)(i,{name:`file`}),(0,g.jsx)(`span`,{className:`tree-name`,children:t.path.split(`/`).at(-1)})]},t.path)),N&&(0,g.jsx)(`button`,{className:`tree-action`,"data-testid":`files-load-more`,disabled:D,onClick:()=>void P(),children:D?`正在加载…`:`加载更多`})]})}export{h as i,v as n,_ as r,b as t};