@teammy/server 0.1.17 → 0.1.18

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.
@@ -0,0 +1 @@
1
+ import{C as e,E as t,F as n,I as r,J as i,M as a,N as o,P as s,Q as c,S as l,Z as u,a as d,g as f,i as p,it as ee,j as m,m as te,n as h,o as g,r as ne,rt as _,t as re,w as ie}from"./index-BRdnk3k3.js";import{t as v}from"./Markdown-2LnVpzw0.js";var y=_(),b=s(),x=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),S=e=>e.replace(/[#*_`>]/g,``).replace(/\s+/g,` `).trim();function ae({mine:e=!1,author:t,time:n,children:r}){return(0,b.jsx)(`div`,{className:`assistant-bubble-row ${e?`mine`:``}`,children:(0,b.jsxs)(`div`,{className:`assistant-bubble`,children:[(0,b.jsxs)(`div`,{className:`assistant-bubble-meta`,children:[(0,b.jsx)(`span`,{children:t}),(0,b.jsx)(`time`,{dateTime:n,children:x(n)})]}),r]})})}function C({me:s}){let{projectId:_,request:C}=te(),w=o(),se=a(_,s,`assistant-selection`),T=a(_,s,`assistant-drafts`),ce=(0,y.useCallback)(e=>C(`agents/outbox`,d,{signal:e}),[C]),E=m(ce,3e3,a(_,s,`outbox`)),le=(0,y.useCallback)(e=>C(`agents/chats`,re,{signal:e}),[C]),D=m(le,3e3,a(_,s,`chats`)),[O,ue]=(0,y.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`chat`);return t?`chat:${t}`:e.get(`message`)??w?.get(se)??``}),k=O.startsWith(`chat:`)?O.slice(5):``,A=!O||!!k,[j,M]=(0,y.useState)(()=>w?.get(a(_,s,`chat`,k))),N=j?.id===k?j:w?.get(a(_,s,`chat`,k)),de=D.data?.chats.find(e=>e.id===k),[fe,P]=(0,y.useState)(),[F,I]=(0,y.useState)(()=>w?.get(T)??{}),L=F[O]??``,R=e=>I(t=>({...t,[O]:e})),[z,B]=(0,y.useState)(!1),[V,H]=(0,y.useState)(!1),[pe,U]=(0,y.useState)(``),[W,G]=(0,y.useState)(``),K=(0,y.useRef)(new Map),me=(0,y.useRef)(null),q=(0,y.useRef)(!0),J=(0,y.useRef)(O);J.current=O,(0,y.useEffect)(()=>{j&&w?.set(a(_,s,`chat`,j.id),j)},[w,_,s,j]),(0,y.useEffect)(()=>{w?.set(T,F)},[w,T,F]);function Y(e){J.current=e,ue(e),w?.set(se,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,y.useEffect)(()=>{!O&&D.data?.chats.length&&Y(`chat:${D.data.chats[0].id}`)},[O,D.data]);let X=(E.data?.messages??[]).filter(e=>e.box===`debug`).reverse(),Z=E.data?.messages.find(e=>e.id===(O===`debug`?fe:O));(0,y.useEffect)(()=>{O!==`debug`&&Z?.conversationId&&Y(`chat:${Z.conversationId}`)},[O,Z?.conversationId]);let Q=X.filter(e=>!e.readAt).map(e=>e.id).join(`,`);(0,y.useEffect)(()=>{Z&&!Z.readAt&&O!==`debug`&&C(`agents/outbox/${Z.id}/read`,g,{method:`POST`}).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>U(r(e)))},[Z?.id,Z?.readAt,O,C,E.reload]),(0,y.useEffect)(()=>{O===`debug`&&Q&&Promise.all(Q.split(`,`).map(e=>C(`agents/outbox/${e}/read`,g,{method:`POST`}))).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>U(r(e)))},[O,Q,C,E.reload]),(0,y.useEffect)(()=>{if(G(``),!k)return;let e=!0,t=-1,i=!1,o=new AbortController,l=n=>{!e||n.id!==k||n.cursor<t||(t=n.cursor,i=!0,n.redirect?Y(`chat:${n.redirect}`):(M(n),G(``)))};C(`agents/chats/${k}`,h,{signal:o.signal}).then(l).catch(t=>{e&&!o.signal.aborted&&(t instanceof n&&[401,403,404].includes(t.status)&&(w?.delete(a(_,s,`chat`,k)),M(e=>e?.id===k?void 0:e)),i||G(r(t)))});let d=n=>{let r=Number(n.lastEventId);return!e||!Number.isSafeInteger(r)||r<=t?!1:(t=r,!0)},f=new EventSource(ee(`/api/v1/projects/${encodeURIComponent(_)}/agents/chats/${encodeURIComponent(k)}/events`));f.addEventListener(`snapshot`,t=>{if(e)try{l(h.parse(JSON.parse(t.data)))}catch(e){G(r(e))}}),f.onerror=()=>{e&&G(`对话连接中断,正在重新连接…`)},f.addEventListener(`context`,e=>{if(!d(e))return;let n=h.pick({kind:!0,title:!0,status:!0,visibility:!0,participants:!0,pending:!0,hold:!0,redirect:!0}).parse(JSON.parse(e.data));n.redirect?Y(`chat:${n.redirect}`):M(e=>e?.id===k?{...e,...n,cursor:t}:e)}),f.addEventListener(`message`,e=>{if(!d(e))return;let t=ne.parse(JSON.parse(e.data));M(n=>n?.id===k?{...n,readCursor:Math.max(n.readCursor,t.seq),cursor:Math.max(n.cursor,Number(e.lastEventId)||0),messages:[...n.messages.filter(e=>e.id!==t.id),t].sort((e,t)=>e.seq-t.seq)}:n)}),f.addEventListener(`message_removed`,e=>{if(!d(e))return;let{id:n}=u({id:c()}).parse(JSON.parse(e.data));M(e=>e?.id===k?{...e,cursor:t,messages:e.messages.filter(e=>e.id!==n)}:e)}),f.addEventListener(`run`,e=>{if(!d(e))return;let t=p.parse(JSON.parse(e.data));M(n=>n?.id===k?{...n,cursor:Math.max(n.cursor,Number(e.lastEventId)||0),runs:n.runs.some(e=>e.id===t.id)?n.runs:[...n.runs,t]}:n)});for(let e of[`delta`,`reset`,`state`])f.addEventListener(e,t=>{if(!d(t))return;let n=JSON.parse(t.data);M(r=>r?.id===k?{...r,cursor:Math.max(r.cursor,Number(t.lastEventId)||0),messages:r.messages.map(t=>t.runId!==n.id||t.role!==`assistant`?t:{...t,body:e===`delta`?t.body+(n.text??``):e===`reset`?``:n.answer??t.body,state:n.state??t.state}),runs:r.runs.map(t=>t.id===n.id?{...t,answer:e===`delta`?t.answer+(n.text??``):e===`reset`?``:n.answer??t.answer,state:n.state??t.state,error:n.error===void 0?t.error:n.error}:t)}:r)});return()=>{e=!1,o.abort(),f.close()}},[_,k,s,C,w]),(0,y.useEffect)(()=>{if(!N?.kind||N.id!==k)return;let e=()=>{document.visibilityState===`visible`&&C(`agents/chats/${k}/read`,u({ok:i()}),{method:`POST`,body:{cursor:N.readCursor}}).then(()=>{D.reload(),window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>U(r(e)))},t=setTimeout(e,300);return document.addEventListener(`visibilitychange`,e),()=>{clearTimeout(t),document.removeEventListener(`visibilitychange`,e)}},[k,N?.readCursor,N?.kind,C]),(0,y.useEffect)(()=>{q.current&&me.current?.scrollIntoView({block:`end`})},[O,j?.messages,Z?.recipients,X.length]);function he(){window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}async function $(e){if(q.current=!0,Y(e),U(``),P(void 0),e.startsWith(`chat:`)||e===`debug`)return;let t=E.data?.messages.find(t=>t.id===e)?.conversationId;if(t)Y(`chat:${t}`);else try{await C(`agents/outbox/${e}/read`,g,{method:`POST`}),he()}catch(e){U(r(e))}}async function ge(){if(!V){H(!0),U(``);try{let e=await C(`agents/chats`,h,{method:`POST`});M(e),await $(`chat:${e.id}`),D.reload()}catch(e){U(r(e))}finally{H(!1)}}}async function _e(e){e.preventDefault();let t=L.trim();if(!t||z||V)return;B(!0),U(``);let n=K.current.get(O);n&&n.text===t||(n={text:t,id:crypto.randomUUID()},K.current.set(O,n));try{if(A){let e=n.target??k;if(!e){let r=await C(`agents/chats`,h,{method:`POST`});e=r.id,n.target=e,K.current.set(`chat:${e}`,n),I(n=>({...n,[`chat:${e}`]:t})),J.current===O&&(M(r),Y(`chat:${e}`))}let r=await C(`agents/chats/${e}`,p.extend({conversationId:c().optional()}),{method:`POST`,body:{text:t,requestId:n.id}});r.conversationId&&r.conversationId!==e&&(J.current===O||J.current===`chat:${e}`)&&Y(`chat:${r.conversationId}`),M(t=>t?.id===e?{...t,runs:t.runs.some(e=>e.id===r.id)?t.runs:[...t.runs,r]}:t),D.reload()}else{let e=await C(`agents/outbox/${Z.id}/reply`,u({conversationId:c()}),{method:`POST`,body:{body:t,requestId:n.id}});he(),J.current===O&&Y(`chat:${e.conversationId}`),D.reload(),P(void 0)}K.current.delete(O),n.target&&K.current.delete(`chat:${n.target}`),I(e=>({...e,[O]:``,...n.target?{[`chat:${n.target}`]:``}:{}}))}catch(e){U(r(e))}finally{B(!1)}}let ve=A||!!Z&&!Z.archivedAt,ye=A&&!N&&(!!k||!D.data);return(0,b.jsxs)(`div`,{className:`split-layout assistant-layout`,"data-testid":`assistant-page`,children:[(0,b.jsxs)(`aside`,{className:`assistant-list`,"aria-label":`消息列表`,children:[(0,b.jsxs)(`header`,{className:`assistant-list-heading`,children:[(0,b.jsx)(`h1`,{children:`消息`}),(0,b.jsx)(e,{className:`assistant-new-chat`,icon:`plus`,label:`新建对话`,disabled:V,onClick:()=>void ge(),"data-testid":`assistant-launcher`})]}),(0,b.jsxs)(`div`,{className:`assistant-message-scroll`,children:[D.loading&&!D.data&&(0,b.jsx)(`p`,{className:`assistant-list-status`,role:`status`,children:`加载中…`}),D.data?.chats.map(e=>(0,b.jsxs)(`button`,{type:`button`,"data-testid":`assistant-chat-${e.id}`,className:`assistant-message-item assistant-chat-item ${k===e.id?`selected`:``}`,"aria-pressed":k===e.id,onClick:()=>void $(`chat:${e.id}`),children:[(0,b.jsx)(`span`,{className:`assistant-message-dot ${e.unread||e.state===`running`||e.state===`queued`?`unread`:``}`}),(0,b.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,b.jsx)(f,{selected:k===e.id,children:(0,b.jsx)(`strong`,{children:e.title})}),(0,b.jsxs)(`time`,{dateTime:e.updatedAt,children:[new Date(e.updatedAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,x(e.updatedAt)]})]})]},e.id)),!!X.length&&(0,b.jsxs)(`button`,{type:`button`,"data-testid":`debug-outbox`,className:`assistant-message-item ${O===`debug`?`selected`:``}`,onClick:()=>void $(`debug`),children:[(0,b.jsx)(`span`,{className:`assistant-message-dot ${Q?`unread`:``}`}),(0,b.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,b.jsx)(f,{selected:O===`debug`,children:(0,b.jsx)(`strong`,{children:`运行提醒`})}),(0,b.jsx)(`span`,{children:S(X.at(-1).body)})]})]}),E.data?.messages.filter(e=>e.box!==`debug`&&!e.conversationId).sort((e,t)=>Number(!!e.archivedAt)-Number(!!t.archivedAt)).map(e=>(0,b.jsxs)(`button`,{type:`button`,"data-testid":`outbox-${e.id}`,className:`assistant-message-item ${e.archivedAt?`archived`:``} ${O===e.id?`selected`:``}`,onClick:()=>void $(e.id),children:[(0,b.jsx)(`span`,{className:`assistant-message-dot ${e.readAt?``:`unread`}`}),(0,b.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,b.jsx)(f,{selected:O===e.id,children:(0,b.jsx)(`strong`,{children:S(e.body)})}),(0,b.jsxs)(`time`,{dateTime:e.createdAt,children:[new Date(e.createdAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,x(e.createdAt)]})]})]},e.id))]}),(0,b.jsx)(t,{error:!0,children:E.error||D.error})]}),(0,b.jsxs)(`section`,{className:`assistant-thread`,"aria-label":A?`Tim对话`:`消息内容`,children:[(0,b.jsxs)(`header`,{className:`assistant-thread-heading`,children:[(0,b.jsx)(`h2`,{children:A?de?.title??N?.title??(k?`无标题`:`Tim`):O===`debug`?`运行提醒`:`项目消息`}),N?.kind===`matter`&&(0,b.jsxs)(`span`,{className:`assistant-participants`,title:N.participants?.join(`、`),children:[N.visibility===`project`?`项目共享 · `:``,N.participants?.join(`、`)]})]}),N?.kind===`matter`&&(N.hold||N.pending||N.status===`completed`)&&(0,b.jsx)(`div`,{className:`assistant-matter-state`,role:`status`,children:N.hold?`${N.hold.scope===`all`?`已暂停`:`暂缓修改`} · ${N.hold.reason}`:N.pending?`待确认 · ${N.pending.members.join(`、`)}:${N.pending.question}`:`已完成`}),(0,b.jsxs)(`div`,{className:`assistant-transcript`,role:`log`,"aria-live":`polite`,"data-testid":`assistant-transcript`,onScroll:e=>{let t=e.currentTarget;q.current=t.scrollHeight-t.scrollTop-t.clientHeight<100},children:[A?ye?(0,b.jsxs)(`div`,{className:`assistant-empty`,"data-testid":`assistant-loading`,children:[(0,b.jsx)(ie,{}),(0,b.jsx)(`p`,{role:`status`,children:W||D.error?`暂时无法加载对话`:`加载中…`})]}):N?.messages.length?N.messages.filter(e=>e.body||[`queued`,`running`,`failed`].includes(e.state)).map(e=>(0,b.jsx)(`div`,{className:`assistant-turn`,children:(0,b.jsxs)(ae,{mine:e.role===`user`&&e.author===s,author:`${e.role===`assistant`?`Tim`:e.author}${e.source===`wecom`?` · 企业微信`:``}`,time:e.createdAt,children:[e.body&&(0,b.jsx)(`div`,{className:`markdown`,children:(0,b.jsx)(v,{children:e.body})}),e.role===`assistant`&&[`queued`,`running`].includes(e.state)&&(0,b.jsxs)(`span`,{className:`assistant-typing`,"aria-label":`正在回答`,children:[(0,b.jsx)(`i`,{}),(0,b.jsx)(`i`,{}),(0,b.jsx)(`i`,{})]}),e.state===`failed`&&(0,b.jsx)(t,{error:!0,children:N.runs.find(t=>t.id===e.runId)?.error||`本次回答未完成。`})]})},e.id)):(0,b.jsxs)(`div`,{className:`assistant-empty`,children:[(0,b.jsx)(ie,{}),(0,b.jsx)(`p`,{children:`有什么项目问题想聊聊?`})]}):!E.data&&E.loading?(0,b.jsx)(`div`,{className:`assistant-empty`,children:(0,b.jsx)(`p`,{role:`status`,children:`加载中…`})}):O===`debug`?X.map(e=>(0,b.jsx)(oe,{item:e,onReply:e.archivedAt?void 0:()=>{P(e.id),R(``),U(``)}},e.id)):Z&&(0,b.jsx)(oe,{item:Z}),(0,b.jsx)(`div`,{ref:me})]}),(0,b.jsx)(t,{error:!0,children:pe||(A?W:``)}),ve?(0,b.jsxs)(`form`,{className:`assistant-composer`,onSubmit:e=>void _e(e),children:[(0,b.jsx)(`textarea`,{value:L,disabled:V,onChange:e=>R(e.target.value),"aria-label":A?`向Tim提问`:`回复消息`,placeholder:A?`问问Tim…`:`回复…`,rows:2,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())}}),(0,b.jsx)(`button`,{className:`primary assistant-send`,type:`submit`,disabled:z||V||ye||!L.trim(),"aria-label":`发送`,children:(0,b.jsx)(l,{name:`send`})})]}):O!==`debug`&&Z&&(0,b.jsxs)(`div`,{className:`assistant-archived`,children:[(0,b.jsx)(l,{name:`archive`}),`已归档`]})]})]})}function oe({item:e,onReply:t}){return(0,b.jsx)(`div`,{"data-testid":`outbox-thread-${e.id}`,children:(0,b.jsxs)(ae,{author:e.box===`debug`?`运行提醒`:`Tim`,time:e.createdAt,children:[(0,b.jsx)(`div`,{className:`markdown`,children:(0,b.jsx)(v,{children:e.body})}),t&&(0,b.jsx)(`button`,{type:`button`,className:`assistant-debug-reply`,onClick:t,children:`回复`})]})})}export{C as Assistant};
@@ -0,0 +1 @@
1
+ import{A as e,C as t,D as n,E as r,I as i,M as a,P as o,S as s,T as c,_ as l,it as u,j as d,k as f,m as p,rt as m,v as h,x as g,y as _}from"./index-BRdnk3k3.js";import{t as v}from"./project-links-Dy6-B89_.js";import"./file-links-DhXbS2mn.js";var y=m(),b=o(),x=[{status:`planned`,label:`计划`},{status:`in_progress`,label:`进行中`},{status:`in_review`,label:`待验收`},{status:`completed`,label:`已完成`},{status:null,label:`未明确`}];function S({members:e,project:t}){let{request:i,projectId:o}=p(),s=(0,y.useCallback)(e=>i(`tasks`,l,{signal:e}),[i]),c=d(s,3e3,a(o,`tasks`)),[u,f]=(0,y.useState)(),m=c.data,h=new Map(e.map(e=>[e.id,e.displayName||e.id]));return(0,b.jsxs)(`div`,{className:`task-board`,children:[(0,b.jsx)(n,{title:t?.projectName.trim()?`${t.projectName.trim()}|工作看板`:`工作看板`,description:t?.description.trim()||``}),(0,b.jsx)(r,{error:!0,children:c.error}),(0,b.jsx)(`section`,{className:`task-board-lanes`,"aria-label":`任务进度`,"data-testid":`progress-board`,children:x.filter(e=>e.status!==null||m?.tasks.some(e=>e.status===null)).map(e=>{let t=m?.tasks.filter(t=>t.status===e.status)??[];return(0,b.jsxs)(`section`,{className:`task-lane`,"aria-label":e.label,"data-stage":e.status??`unknown`,children:[(0,b.jsxs)(`h2`,{children:[(0,b.jsx)(`span`,{className:`lane-dot`}),e.label,(0,b.jsx)(_,{children:m?t.length:`—`})]}),(0,b.jsx)(`div`,{className:`task-lane-content`,children:t.length?t.map(e=>(0,b.jsx)(C,{task:e,names:h,onEdit:()=>f(e),onSaved:()=>void c.reload()},e.id)):(0,b.jsx)(`p`,{className:`task-lane-empty`,children:c.error&&!m?`读取失败`:m?`暂无任务`:`读取中…`})})]},e.label)})}),u&&(0,b.jsx)(T,{task:u,onClose:()=>f(void 0),onSaved:()=>{f(void 0),c.reload()}},u.id)]})}function C({task:n,names:a,onEdit:o,onSaved:c}){let{projectId:l,request:d}=p(),m=e(),[g,_]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``);async function C(){if(!g){_(!0),S(``);try{await d(`tasks/${n.id}/correction`,h,{method:`PATCH`,signal:m,body:{needsConfirmation:!1,expectedRevision:n.revision}}),m.aborted||c()}catch(e){m.aborted||S(i(e))}finally{_(!1)}}}return(0,b.jsxs)(`details`,{className:`task-card`,"data-testid":`task-card`,"data-task-id":n.id,"data-owner":n.owner,"data-status":n.status??`unknown`,children:[(0,b.jsxs)(`summary`,{className:`task-card-heading`,"data-testid":`task-toggle`,children:[(0,b.jsx)(`h3`,{children:n.title}),(0,b.jsxs)(`span`,{className:`task-card-meta`,children:[(0,b.jsx)(`small`,{children:a.get(n.owner)??n.owner}),n.needsConfirmation&&(0,b.jsxs)(`span`,{className:`task-confirmation`,"data-testid":`task-confirmation`,children:[(0,b.jsx)(s,{name:`attention`,size:`small`}),`需要确认`]})]})]}),(0,b.jsx)(t,{icon:`edit`,className:`task-card-edit`,label:`纠正任务:${n.title}`,"data-testid":`task-correct`,disabled:g,onClick:o}),(0,b.jsxs)(`div`,{className:`task-card-details`,children:[(0,b.jsx)(`h4`,{children:`目标`}),(0,b.jsx)(`p`,{children:n.goal?(0,b.jsx)(w,{value:n.goal,names:a}):`目标未明确`}),(0,b.jsx)(`h4`,{children:`当前进展`}),(0,b.jsx)(`p`,{className:`task-progress`,children:(0,b.jsx)(w,{value:n.progress,names:a})}),(0,b.jsx)(`div`,{className:`task-card-sources`,children:n.sources.map(e=>(0,b.jsxs)(`a`,{"data-testid":`task-source`,href:u(e.kind===`material`?`/projects/${l}/materials?id=${e.materialId}&revision=${e.revision}`:v(l,n.owner,e.path)),children:[(0,b.jsx)(s,{name:`file`,size:`small`}),(0,b.jsx)(`span`,{children:e.path})]},e.path))}),n.syncedAt&&(0,b.jsxs)(`small`,{children:[`资料同步于 `,(0,b.jsx)(f,{value:n.syncedAt})]}),n.needsConfirmation&&(0,b.jsxs)(`div`,{className:`task-card-confirm`,children:[(0,b.jsx)(r,{error:!0,children:x}),(0,b.jsx)(`button`,{className:`primary`,"data-testid":`task-confirm-save`,disabled:g,onClick:()=>void C(),children:g?`正在保存…`:`保存`})]})]})]})}function w({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 T({task:t,onClose:n,onSaved:a}){let{request:o}=p(),s=e(),[l,u]=(0,y.useState)(t.title),[d,f]=(0,y.useState)(t.status??``),[m,_]=(0,y.useState)(t.goal??``),[v,S]=(0,y.useState)(t.progress),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(``),D={...l===t.title?{}:{title:l},...d===(t.status??``)?{}:{status:d||null},...m===(t.goal??``)?{}:{goal:m||null},...v===t.progress?{}:{progress:v},...t.needsConfirmation?{needsConfirmation:!1}:{}};async function O(){if(!C&&Object.keys(D).length){w(!0),E(``);try{await o(`tasks/${t.id}/correction`,h,{method:`PATCH`,signal:s,body:{...D,expectedRevision:t.revision}}),s.aborted||a()}catch(e){s.aborted||E(i(e))}finally{w(!1)}}}return(0,b.jsx)(c,{id:`task-correction`,title:`纠正任务`,onClose:n,children:(0,b.jsxs)(`form`,{className:`stack`,"aria-busy":C,onSubmit:e=>{e.preventDefault(),O()},children:[(0,b.jsx)(g,{id:`task-title`,label:`标题`,children:(0,b.jsx)(`input`,{value:l,required:!0,onChange:e=>u(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:d===e.status,onChange:()=>f(e.status)}),(0,b.jsx)(`span`,{children:e.label})]},e.status))}),(0,b.jsx)(`small`,{children:`待验收:任务成果已提交,等待验收或最终确认。`})]}),(0,b.jsx)(g,{id:`task-goal`,label:`目标`,children:(0,b.jsx)(`textarea`,{value:m,onChange:e=>_(e.target.value)})}),(0,b.jsx)(g,{id:`task-progress`,label:`当前进展`,children:(0,b.jsx)(`textarea`,{value:v,onChange:e=>S(e.target.value)})}),(0,b.jsx)(r,{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 E({members:e,config:t}){return(0,b.jsx)(S,{members:e,project:t})}export{E as Dashboard};
@@ -0,0 +1 @@
1
+ .memory-page{flex:1;width:100%;max-width:1000px;min-height:0;margin:0 auto;padding:0 8px 24px 0;overflow-y:auto}.memory-cards{gap:14px;display:grid}.memory-card{background:var(--color-surface,white);border:1px solid var(--color-line);border-radius:14px;align-items:flex-start;gap:16px;min-width:0;padding:20px 22px;display:flex}.memory-status{color:var(--color-muted);flex:none;padding-top:7px;display:flex}.memory-status.is-kept{color:var(--brand-orange)}.memory-content{flex:1;min-width:0}.memory-text{text-align:left;width:100%;font:inherit;overflow-wrap:anywhere;color:inherit;background:0 0;border:0;border-radius:0;padding:4px 0;line-height:1.7;display:block}.memory-text:hover{background:0 0}.memory-content textarea{resize:vertical;width:100%;min-height:64px;font:inherit;line-height:1.7;display:block}.memory-actions{flex-shrink:0;gap:4px;display:flex}.memory-empty{color:var(--color-muted);margin:24px 0}@media (width<=680px){.memory-card{gap:8px;padding:14px 12px}.memory-actions{gap:0}.memory-actions .icon-button{width:32px;height:32px;padding:4px}}
@@ -0,0 +1 @@
1
+ import{C as e,D as t,E as n,F as r,I as i,J as a,K as o,L as s,M as c,O as l,P as u,Q as d,S as f,V as p,X as m,Z as h,b as g,c as _,d as v,f as y,it as b,j as x,l as S,m as C,p as w,q as T,rt as E,tt as D,u as O,z as k}from"./index-BRdnk3k3.js";import{t as A}from"./Markdown-2LnVpzw0.js";import{t as j}from"./project-links-Dy6-B89_.js";import{t as M}from"./file-links-DhXbS2mn.js";import{n as N,t as P}from"./WorkspaceTree-CU784GTC.js";import{t as F}from"./HtmlPreview-C4jbdvbl.js";var I=E(),L=d().trim().min(1).max(120).refine(e=>!/[\r\n]/.test(e),`请使用一句简短的项目记忆。`),R=h({id:D(),text:L,state:o([`draft`,`kept`]),revision:m().int().positive(),createdAt:d(),updatedAt:d()}),z=h({cards:T(R)});h({id:D(),text:L}).strict(),h({expectedRevision:m().int().positive(),text:L.optional(),action:o([`keep`,`discard`,`delete`]).optional()}).strict().refine(e=>e.text!==void 0||e.action!==void 0,`没有需要保存的修改。`),h({text:L}).strict();var B=u();function V(){let{request:r,projectId:i}=C(),a=(0,I.useCallback)(e=>r(`memory`,z,{signal:e}),[r]),o=x(a,5e3,c(i,`memory`)),[l,u]=(0,I.useState)(null),[d,f]=(0,I.useState)({}),p=(0,I.useRef)(null),m=[...o.data?.cards??[]];for(let e of Object.values(d))m.some(t=>t.id===e.id)||m.push(e);if(o.data&&!p.current&&(p.current=[...m].sort((e,t)=>Number(t.state===`kept`)-Number(e.state===`kept`)).map(e=>e.id)),p.current){let e=new Map(p.current.map((e,t)=>[e,t]));for(let t of m)e.has(t.id)||(e.set(t.id,p.current.length),p.current.push(t.id));m.sort((t,n)=>e.get(t.id)-e.get(n.id))}return(0,B.jsxs)(`section`,{className:`memory-page`,children:[(0,B.jsx)(t,{title:`记忆`,children:(0,B.jsx)(e,{icon:`plus`,label:`新增记忆`,disabled:!!l,onClick:()=>u(s())})}),(0,B.jsx)(n,{error:!0,children:o.error}),!o.data&&o.loading&&(0,B.jsx)(`p`,{role:`status`,children:`加载中…`}),(0,B.jsxs)(`div`,{className:`memory-cards`,children:[l&&(0,B.jsx)(H,{id:l,onDone:()=>u(null),reload:o.reload},l),m.map(e=>(0,B.jsx)(H,{id:e.id,card:e,reload:o.reload,onEditing:t=>f(n=>{let r={...n};return t?r[e.id]=e:delete r[e.id],r})},e.id))]}),o.data&&m.length===0&&!l&&(0,B.jsx)(`p`,{className:`memory-empty`,children:`暂无记忆`})]})}function H({id:t,card:r,reload:o,onDone:s,onEditing:c}){let{request:l}=C(),[u,d]=(0,I.useState)(!r),[p,m]=(0,I.useState)(r?.text??``),[g,_]=(0,I.useState)(r?.revision),[v,y]=(0,I.useState)(!1),[b,x]=(0,I.useState)(``),S=(0,I.useRef)(!1),w=(0,I.useRef)(!1);function T(){w.current=!1,c?.(!0),m(r?.text??``),_(r?.revision),x(``),d(!0)}function E(){w.current=!0,d(!1),x(``),c?.(!1),s?.()}async function D(e){if(!S.current){if(!e&&r&&p===r.text)d(!1),c?.(!1);else if((!e||e===`keep`)&&!L.safeParse(u?p:r?.text).success)x(`请填写一句记忆,最多 120 个字符。`);else{S.current=!0,y(!0),x(``);try{r?await l(`memory/${t}`,h({saved:a()}),{method:`PATCH`,body:{expectedRevision:u?g:r.revision,...e?{action:e}:{},...u&&e!==`discard`&&e!==`delete`?{text:p}:{}}}):await l(`memory`,R,{method:`POST`,body:{id:t,text:p}}),d(!1),await o(),c?.(!1),s?.()}catch(e){x(i(e)),await o()}finally{S.current=!1,y(!1)}}}}return(0,B.jsxs)(`article`,{className:`memory-card`,"data-testid":`memory-card`,"data-memory-id":t,children:[(0,B.jsx)(`span`,{className:`memory-status ${r?.state===`kept`?`is-kept`:``}`,role:`img`,"aria-label":r?.state===`kept`?`已保留`:`待确认`,children:(0,B.jsx)(f,{name:r?.state===`kept`?`check`:`question`})}),(0,B.jsxs)(`div`,{className:`memory-content`,children:[u?(0,B.jsx)(`textarea`,{autoFocus:!0,"aria-label":`记忆内容`,value:p,maxLength:120,rows:2,disabled:v,onChange:e=>m(e.target.value.replace(/[\r\n]+/g,` `)),onBlur:e=>{w.current?w.current=!1:e.relatedTarget instanceof Element&&e.relatedTarget.closest(`.memory-actions`)||b||D()},onKeyDown:e=>{e.nativeEvent.isComposing||(e.key===`Escape`&&(e.preventDefault(),E()),e.key===`Enter`&&(e.preventDefault(),D()))}}):(0,B.jsx)(`button`,{type:`button`,className:`memory-text`,"aria-label":`编辑记忆:${r?.text??``}`,onClick:T,children:r?.text}),(0,B.jsx)(n,{error:!0,children:b})]}),(0,B.jsxs)(`div`,{className:`memory-actions`,onMouseDown:e=>{u&&e.preventDefault()},children:[(!r||r.state===`draft`)&&(0,B.jsx)(e,{icon:`check`,label:r?`保留记忆`:`保存记忆`,disabled:v,onClick:()=>void D(r?`keep`:void 0)}),u&&r?.state===`kept`&&(0,B.jsx)(e,{icon:`check`,label:`保存记忆`,disabled:v,onClick:()=>void D()}),(0,B.jsx)(e,{icon:`close`,label:r?r.state===`draft`?`舍弃记忆`:`删除记忆`:`取消新增`,disabled:v,onClick:()=>{r?D(r.state===`draft`?`discard`:`delete`):E()}})]})]})}function U(e,t){let n=t.split(`/`).slice(0,-1);return n.map((t,r)=>N(e,n.slice(0,r+1).join(`/`))).concat(N(e,``))}function W({members:t,me:i,onRefresh:a}){let{api:o,projectId:s}=C(),[c,l]=(0,I.useState)(()=>{let e=new URLSearchParams(location.search),n=e.get(`owner`),r=p.safeParse(e.get(`path`));return n&&(y(n)||t.some(e=>e.id===n))&&r.success&&!v(r.data)?{owner:n,path:r.data}:void 0}),[u,d]=(0,I.useState)(()=>new Set(c?U(c.owner,c.path):[N(i,``)])),[f,m]=(0,I.useState)(()=>c?{...c,kind:`file`}:void 0),[h,T]=(0,I.useState)(0),[E,D]=(0,I.useState)(()=>{let e=new URLSearchParams(location.search);return!c&&(e.has(`owner`)||e.has(`path`))?`文件链接不完整或目标已不可用。`:``}),A=(0,I.useCallback)(async e=>{if(c)try{return{owner:c.owner,...await o.file(c.owner,c.path,void 0,e)}}catch(e){throw e instanceof r&&e.code===`FILE_NOT_FOUND`?Error(`找不到这个文件,可能已被删除或移动。`):e}},[c?.owner,c?.path,h]),F=x(A),L=F.data?.owner===c?.owner&&F.data?.file.path===c?.path?F.data:void 0;function R(e,t){let n=t.split(`/`).filter(Boolean);d(t=>{let r=new Set(t);for(let t=0;t<=n.length;t++)r.add(N(e,n.slice(0,t).join(`/`)));return r})}function z(e,t){D(``),R(e,t.split(`/`).slice(0,-1).join(`/`)),l({owner:e,path:t}),m({owner:e,path:t,kind:`file`}),history.replaceState(null,``,b(j(s,e,t)))}function H(e){if(!c)return!1;let n=M(y(c.owner)?c.path:`${c.owner}/${c.path}`,e);if(!n)return!/^[a-z][a-z0-9+.-]*:/i.test(e)&&!e.startsWith(`//`)&&(D(`该链接超出工作区,请在原仓库查看。`),!0);if(v(n.path))return D(`配置文件不在文件浏览中显示。`),!0;let[r,...i]=n.path.split(`/`),a=t.some(e=>e.id===r),o=a?r:O(n.path)?S:_,s=a?i.join(`/`):n.path;return D(``),n.directory?(R(o,s),m({owner:o,path:s,kind:`directory`})):o===c.owner&&s===c.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`}):z(o,s),!0}return(0,B.jsxs)(`div`,{className:`split-layout file-explorer`,"data-testid":`file-browser`,children:[(0,B.jsxs)(`aside`,{className:`file-tree-pane`,"aria-label":`文件资源管理器`,children:[(0,B.jsx)(w,{title:`工作区`,icon:`files`,children:(0,B.jsx)(e,{icon:`refresh`,label:`刷新文件`,"data-testid":`files-refresh`,onClick:()=>{D(``),T(e=>e+1),a()}})}),(0,B.jsx)(P,{members:t,expanded:u,selected:f,revealed:!F.loading&&!F.error&&L?{owner:L.owner,path:L.file.path,file:L.file}:void 0,onSelect:z,onToggle:(e,t)=>{m({owner:e,path:t,kind:`directory`}),d(n=>{let r=new Set(n),i=N(e,t);return r.has(i)?r.delete(i):r.add(i),r})}},h)]}),(0,B.jsx)(`section`,{className:`file-detail`,"data-testid":`file-preview`,"data-owner-id":c?.owner,"data-file-path":c?.path,"aria-label":k.filePreview,children:c?.owner===`_resources`&&c.path===`_memory/MEMORY.md`?(0,B.jsx)(V,{}):c?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(n,{error:!0,children:E||!F.loading&&F.error}),F.error&&(0,B.jsx)(`button`,{className:`file-entry-retry`,"data-testid":`files-retry`,onClick:()=>void F.reload(),children:k.retry}),F.loading?(0,B.jsx)(`p`,{className:`preview-body`,role:`status`,children:k.loading}):!F.error&&L&&(0,B.jsx)(G,{owner:L.owner,file:L.file,onLink:H},`${L.owner}:${L.file.path}:${L.file.sha256}`)]}):E?(0,B.jsx)(n,{error:!0,children:E}):(0,B.jsx)(g,{mascot:!0,title:`查看工作区文件`,description:k.pickFile})})]})}function G({owner:t,file:r,onLink:i}){let{readTextBlob:a,blobUrl:o,projectId:s}=C(),[u,d]=(0,I.useState)(!1),p=r.size>524288,m=/\.(md|markdown)$/i.test(r.path),h=/\.html?$/i.test(r.path),g=(0,I.useCallback)(e=>p?Promise.resolve(void 0):a(r,e),[r.sha256,r.size,p]),_=x(g,!1,c(s,`file-body`,r.sha256));return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)(`header`,{className:`file-detail-header`,children:[(0,B.jsxs)(`span`,{className:`file-detail-path`,title:`${y(t)?`workspaces`:t}/${r.path}`,children:[(0,B.jsxs)(`span`,{children:[y(t)?`workspaces`:t,` / `]}),r.path]}),(0,B.jsxs)(l,{label:`文件操作`,children:[(m||h)&&(0,B.jsx)(e,{icon:u?`preview`:`code`,label:u?`切换为预览`:`切换为原文`,"data-testid":`file-toggle-raw`,"aria-pressed":u,onClick:()=>d(!u)}),(0,B.jsx)(`a`,{className:`icon-button`,"data-testid":`file-download`,"aria-label":k.download,title:k.download,href:o(r.sha256),download:r.path.split(`/`).at(-1),children:(0,B.jsx)(f,{name:`download`})})]})]}),p?(0,B.jsx)(`div`,{className:`empty`,children:(0,B.jsx)(`p`,{children:k.previewLarge})}):_.error?(0,B.jsxs)(`div`,{className:`preview-body`,children:[(0,B.jsx)(n,{error:!0,children:_.error}),(0,B.jsx)(`button`,{"data-testid":`file-preview-retry`,onClick:()=>void _.reload(),children:k.retry})]}):_.loading?(0,B.jsx)(`p`,{className:`preview-body`,role:`status`,children:k.loading}):(0,B.jsx)(`div`,{className:`preview-body${h&&!u?` preview-body-html`:``}`,children:h&&!u?(0,B.jsx)(F,{url:o(r.sha256),name:r.path.split(`/`).at(-1)}):m&&!u?(0,B.jsx)(`article`,{className:`markdown`,"data-testid":`file-content`,"data-format":`markdown`,children:(0,B.jsx)(A,{onLink:i,children:_.data??``})}):(0,B.jsx)(`pre`,{className:`raw`,"data-testid":`file-content`,"data-format":`text`,children:_.data})})]})}export{W as Files};
@@ -1 +1 @@
1
- import{A as e}from"./index-BANjviDF.js";var t=e();function n({url:e,name:n}){return(0,t.jsx)(`iframe`,{className:`html-preview`,title:`${n} 预览`,src:`${e}${e.includes(`?`)?`&`:`?`}view=html`,sandbox:``,referrerPolicy:`no-referrer`})}export{n as t};
1
+ import{P as e}from"./index-BRdnk3k3.js";var t=e();function n({url:e,name:n}){return(0,t.jsx)(`iframe`,{className:`html-preview`,title:`${n} 预览`,src:`${e}${e.includes(`?`)?`&`:`?`}view=html`,sandbox:``,referrerPolicy:`no-referrer`})}export{n as t};