@teammy/server 0.2.3 → 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.
- package/README.md +1 -1
- package/dist/main.js +3279 -1855
- package/dist/runtime/shared/tools.json +1 -1
- package/dist/runtime/workflows/task-bootstrap/prompt.md +3 -3
- package/dist/web/assets/Assistant-DUNdPkOm.js +1 -0
- package/dist/web/assets/Computers-BDZ0gAvQ.js +3 -0
- package/dist/web/assets/Computers-Dc45R6Gl.css +1 -0
- package/dist/web/assets/{Conversation-B-uSxDxY.css → Conversation-CNmGkVy7.css} +1 -1
- package/dist/web/assets/{Conversation-1APTn0kq.js → Conversation-DF1cdAgS.js} +1 -1
- package/dist/web/assets/Dashboard-D3aSwRnd.js +1 -0
- package/dist/web/assets/Files-iHjpLSD-.js +1 -0
- package/dist/web/assets/{Help-BXvLax7h.js → Help-Xc5lgpqr.js} +103 -110
- package/dist/web/assets/{HtmlPreview-BcspnVI6.js → HtmlPreview-DUPprW5l.js} +1 -1
- package/dist/web/assets/{Markdown-Bb9dy2Sh.js → Markdown-BF2STz99.js} +4 -4
- package/dist/web/assets/{MessageComposer-B6iTInqD.js → MessageComposer-CcA3P4oJ.js} +1 -1
- package/dist/web/assets/ResourceLibrary-DfE9icSj.js +6 -0
- package/dist/web/assets/WorkspaceTree-Bg3hPNzQ.js +1 -0
- package/dist/web/assets/{file-links-B0q73ekI.js → file-links-DWut-bRr.js} +1 -1
- package/dist/web/assets/index-BQV0j0VG.js +66 -0
- package/dist/web/downloads/teammy-skill.zip +0 -0
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/Assistant-Ceif-ARy.js +0 -1
- package/dist/web/assets/Computers-B9XbkIvb.css +0 -1
- package/dist/web/assets/Computers-B_8KVFSv.js +0 -3
- package/dist/web/assets/Dashboard-B-LuQT0a.js +0 -1
- package/dist/web/assets/Files-BdfIlw8b.js +0 -1
- package/dist/web/assets/ResourceLibrary-CXqTEv7V.js +0 -6
- package/dist/web/assets/WorkspaceTree-D0UUUBtF.js +0 -1
- package/dist/web/assets/index-C5-iSe99.js +0 -66
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{R as e,St as t,X as n}from"./index-BQV0j0VG.js";var r=t(),i=n();function a({value:t,onChange:n,onSubmit:r,label:a,placeholder:s=`输入消息…`,disabled:c=!1,sendDisabled:l=!1,sendLabel:u=`发送`,actions:d,heading:f,inset:p=!1,plain:m=!1}){let h=o(t),g=!c&&!l&&!!t.trim();return(0,i.jsxs)(`form`,{className:`message-composer${p?` message-composer-inset`:``}${m?` message-composer-plain`:``}`,onSubmit:e=>{e.preventDefault(),g&&r(e)},children:[f&&(0,i.jsx)(`div`,{className:`message-composer-heading`,children:f}),(0,i.jsx)(`textarea`,{ref:h,value:t,onChange:e=>n(e.target.value),"aria-label":a,placeholder:s,disabled:c,rows:1,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),g&&e.currentTarget.form?.requestSubmit())}}),(0,i.jsxs)(`div`,{className:`message-composer-footer`,children:[d&&(0,i.jsx)(`div`,{className:`message-composer-actions`,children:d}),(0,i.jsx)(`button`,{type:`submit`,className:`primary message-send`,"aria-label":u,title:u,disabled:!g,children:(0,i.jsx)(e,{name:`send`,size:`small`})})]})]})}function o(e,t){let n=(0,r.useRef)(null);return(0,r.useLayoutEffect)(()=>{let e=n.current;if(!e)return;let r=()=>{t?.(e),e.style.height=`0px`,e.style.height=`${e.scrollHeight}px`};r();let i=e.clientWidth,a=new ResizeObserver(()=>{i!==e.clientWidth&&(i=e.clientWidth,r())});return a.observe(e),()=>a.disconnect()},[e,t]),n}export{o as n,a as t};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{$ as e,Ct as t,G as n,H as r,I as i,J as a,K as o,L as s,R as c,St as l,U as u,V as d,X as f,Z as p,_t as m,bt as h,ct as g,d as _,dt as v,et as y,f as b,ft as x,gt as S,h as C,ht as w,it as T,lt as E,mt as D,nt as O,ot as k,pt as A,q as j,rt as M,st as N,ut as P,wt as ee,xt as F,y as I,yt as L,z as R}from"./index-BQV0j0VG.js";import{n as z,r as B,t as V}from"./Markdown-BF2STz99.js";import{t as H}from"./Conversation-DF1cdAgS.js";import{i as te,r as U}from"./WorkspaceTree-Bg3hPNzQ.js";import{n as W}from"./project-links-Dy6-B89_.js";import{t as G}from"./HtmlPreview-DUPprW5l.js";function K(e){return F(E,e)}var q=l(),ne=S().regex(/^R\d{6,}$/),J=w({name:S().min(1),sha256:k,size:D().int().nonnegative()}),Y=L().refine(e=>/^https?:\/\//i.test(e),`Use an HTTP or HTTPS URL.`);w({operationId:h(),title:S().trim().default(``),text:S().optional(),url:Y.optional(),originals:v(J).default([])}).strict().refine(e=>!!e.text?.trim()||!!e.url||e.originals.length>0,`Provide text, a link or a file.`),w({expectedRevision:N,title:S().trim().min(1).optional(),url:Y.nullable().optional(),content:S().optional(),summary:S().optional(),sourceVersion:S().optional(),contentDate:S().optional(),originals:v(J).optional()}).strict();var X=w({id:ne,projectId:S(),title:S(),submittedBy:S(),createdAt:S(),revision:N,source:w({kind:P([`web`,`chat`,`group`]),url:S().nullable(),groupId:S().optional(),messageId:S().optional(),sourceVersion:S().optional(),contentDate:S().optional()}),originals:v(J),content:S().nullable(),summary:S().nullable(),state:P([`waiting`,`running`,`ready`,`failed`]),error:S().nullable(),url:S()}),re=w({materials:v(X),nextCursor:D().nullable()});w({query:S().trim().min(1),scope:P([`all`,`workspace`,`materials`]).default(`all`),materialId:ne.optional(),originalHash:k.optional(),after:S().default(``),limit:K().int().min(1).max(200).default(30)}).strict();var ie=w({items:v(w({key:S(),kind:P([`workspace`,`materials`]),title:S(),snippet:S(),url:S(),path:S()})),nextCursor:S().nullable()}),Z=f();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:n,onActivate:o,children:s}){let{request:l,projectId:u}=I(),[d,f]=(0,q.useState)(oe),[p,m]=(0,q.useState)(d),[h,g]=(0,q.useState)(()=>new Set(d?[d.id]:[])),[_,v]=(0,q.useState)(!1),[y,b]=(0,q.useState)(``),[x,S]=(0,q.useState)(``),[w,T]=(0,q.useState)(``),[E,D]=(0,q.useState)([]),[O,k]=(0,q.useState)(),[A,M]=(0,q.useState)(!1),[N,P]=(0,q.useState)(``),F=(0,q.useRef)(null),L=(0,q.useCallback)(e=>l(`materials`,re,{signal:e}),[l]),z=j(L,5e3,a(u,`materials`)),B=(0,q.useCallback)(e=>d?l(`materials/${encodeURIComponent(d.id)}${d.revision?`?revision=${encodeURIComponent(d.revision)}`:``}`,X,{signal:e}):Promise.resolve(null),[l,d?.id,d?.revision]),H=j(B,5e3),U=H.data?.id===d?.id?H.data:null,W=[...new Map([...E,...z.data?.materials??[],...U?[U]:[]].map(e=>[e.id,e])).values()].sort((e,t)=>t.createdAt.localeCompare(e.createdAt)||t.id.localeCompare(e.id)),G=O===void 0?z.data?.nextCursor:O;function K(e,n=``){o(),f(e),m(e),S(``),T(n),v(!1),g(t=>new Set([...t,e.id])),history.replaceState(null,``,t(`/projects/${u}/materials?${new URLSearchParams({...e})}`))}(0,q.useEffect)(()=>{let e=()=>{if(!ee().endsWith(`/materials`))return;let e=oe();f(e),m(e),S(``),b(``),T(``),v(!1),e&&g(t=>new Set([...t,e.id]))};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]);async function ne(){if(G&&!A){M(!0),P(``);try{let e=await l(`materials?before=${G}`,re);D(t=>[...t,...e.materials]),k(e.nextCursor)}catch(t){P(e(t))}finally{M(!1)}}}let J=W.find(e=>e.id===p?.id),Y=J?.originals.find(e=>e.sha256===p?.original)?.name??J?.title??`当前资料`;function ie(){m(void 0),T(``),F.current?.focus()}let se=(0,Z.jsx)(R,{icon:`plus`,label:`新增资料`,onClick:()=>{o(),v(!0),P(``)}});return s({tree:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(r,{error:!0,children:z.error||N}),z.data?W.length===0?(0,Z.jsx)(`p`,{className:`tree-status`,children:`暂无资料`}):(0,Z.jsx)(Z.Fragment,{children:W.map(e=>(0,Z.jsxs)(`div`,{role:`none`,children:[(0,Z.jsxs)(C,{role:`treeitem`,"aria-level":1,"aria-expanded":h.has(e.id),"aria-selected":n&&!_&&d?.id===e.id&&!d.original,className:`tree-item tree-folder`,style:{"--tree-level":1},"data-testid":`material-folder`,title:e.title,onClick:()=>{let t=h.has(e.id);K({id:e.id}),t&&g(t=>{let n=new Set(t);return n.delete(e.id),n})},leading:(0,Z.jsx)(`span`,{className:`tree-chevron ${h.has(e.id)?`expanded`:``}`,children:(0,Z.jsx)(c,{name:`chevron`,size:`small`})}),children:[(0,Z.jsx)(c,{name:`files`}),(0,Z.jsx)(`span`,{className:`tree-name`,children:e.title})]}),h.has(e.id)&&(0,Z.jsx)(`div`,{role:`group`,children:[...e.originals].sort((e,t)=>te(e.name,t.name)).map((t,r)=>(0,Z.jsxs)(C,{role:`treeitem`,"aria-level":2,"aria-selected":n&&!_&&d?.id===e.id&&d.original===t.sha256,className:`tree-item`,style:{"--tree-level":2},"data-testid":`material-original`,title:t.name,onClick:()=>K({id:e.id,original:t.sha256,...e.id===d?.id&&d.revision?{revision:d.revision}:{}}),leading:(0,Z.jsx)(`span`,{className:`tree-chevron`}),children:[(0,Z.jsx)(c,{name:`file`}),(0,Z.jsx)(`span`,{className:`tree-name`,children:t.name})]},`${t.sha256}:${r}`))})]},e.id))}):(0,Z.jsx)(`p`,{className:`tree-status`,children:`加载中…`}),G&&(0,Z.jsx)(`button`,{className:`tree-action`,disabled:A,onClick:()=>void ne(),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=>{K({id:e}),z.reload()}}):x?(0,Z.jsx)(ce,{query:x,scope:p,onSelect:e=>K(e,x)},`${x}/${p?.id}/${p?.original}`):d?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(r,{error:!0,children:H.error}),U?d.original?(0,Z.jsx)(le,{material:U,hash:d.original,highlight:w},`${U.id}:${d.original}`):(0,Z.jsxs)(`article`,{className:`material-body`,children:[(0,Z.jsx)(`h1`,{children:U.title}),d.revision&&(0,Z.jsx)(`button`,{className:`material-link`,onClick:()=>K({id:d.id}),children:`查看最新内容`}),!d.revision&&(U.state===`waiting`||U.state===`running`)?(0,Z.jsx)(`p`,{className:`muted`,role:`status`,children:`正在整理…`}):null,(0,Z.jsx)(r,{error:!0,children:U.error??``}),!d.revision&&U.state===`failed`&&(0,Z.jsx)(`button`,{onClick:()=>void l(`materials/${d.id}/retry`,X,{method:`POST`}).then(()=>H.reload()).catch(t=>P(e(t))),children:`重试整理`}),U.content?(0,Z.jsx)(`div`,{className:`markdown`,children:(0,Z.jsx)(V,{highlight:w,children:ae(U)})}):(0,Z.jsx)(`p`,{className:`muted`,children:`正文尚未整理,可以先查看左侧原件。`})]}):(0,Z.jsx)(`p`,{role:`status`,children:`加载中…`})]}):(0,Z.jsx)(i,{mascot:!0,title:`选择资料开始阅读`,description:`也可以在下方搜索资料内容。`})}),!_&&(0,Z.jsxs)(`form`,{className:`session-search-dock`,"data-testid":`material-search-form`,onSubmit:e=>{e.preventDefault(),S(y.trim()),T(``)},children:[p&&(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:F,"aria-label":`搜索资料`,placeholder:`搜索资料内容`,value:y,onChange:e=>b(e.target.value),onKeyDown:e=>{e.key===`Backspace`&&!y&&p&&(e.preventDefault(),ie())}}),(x||y||w)&&(0,Z.jsx)(R,{icon:`close`,label:`清空搜索`,onClick:()=>{b(``),S(``),T(``),F.current?.focus()}}),(0,Z.jsx)(R,{icon:`search`,type:`submit`,label:`搜索`,disabled:!y.trim()})]})]})]}),actions:se,href:`/projects/${u}/materials${d&&!_?`?${new URLSearchParams({...d})}`:``}`})}function ce({query:e,scope:t,onSelect:n}){let{request:i}=I(),[a,o]=(0,q.useState)(``),s=(0,q.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]),c=j(s);return(0,Z.jsxs)(`section`,{className:`session-results stack`,"aria-label":`搜索结果`,children:[(0,Z.jsx)(r,{error:!0,children:c.error}),c.loading?(0,Z.jsx)(`p`,{role:`status`,children:`正在搜索…`}):c.data?.items.length===0?(0,Z.jsx)(`p`,{className:`empty`,children:`没有找到匹配的资料`}):c.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)(z,{value:B(t.snippet,e),query:e})})]},t.key)),c.data?.nextCursor&&(0,Z.jsx)(`button`,{disabled:c.loading,onClick:()=>o(c.data.nextCursor),children:`下一页`})]})}function le({material:e,hash:n,highlight:i}){let{projectId:o}=I(),s=e.originals.find(e=>e.sha256===n),l=t(`/api/v1/projects/${o}/materials/${e.id}/originals/${n}?revision=${e.revision}`),[u,d]=(0,q.useState)(!1),f=(0,q.useCallback)(async e=>{let t=await fetch(l,{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}},[l]),p=j(f,!1,a(o,`material-original`,n));if(!s)return(0,Z.jsx)(r,{error:!0,children:`找不到此原件。`});let m=/\.(md|markdown)$/i.test(s.name),h=/\.html?$/i.test(s.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:s.name}),(0,Z.jsxs)(`div`,{className:`toolbar-actions`,children:[(m||h)&&(0,Z.jsx)(R,{icon:u?`preview`:`code`,label:u?`切换为预览`:`切换为原文`,"aria-pressed":u,onClick:()=>d(!u)}),(0,Z.jsx)(`a`,{className:`icon-button`,"aria-label":`下载原件`,title:`下载原件`,href:l,download:s.name,children:(0,Z.jsx)(c,{name:`download`})})]})]}),(0,Z.jsx)(r,{error:!0,children:p.error}),p.loading?(0,Z.jsx)(`p`,{role:`status`,children:`加载中…`}):p.data===null?(0,Z.jsx)(`p`,{className:`muted`,children:`此格式请下载后查看。`}):p.data!==void 0&&(0,Z.jsx)(`div`,{className:`preview-body${h&&!u?` preview-body-html`:``}`,"data-testid":`material-original-content`,children:h&&!u?(0,Z.jsx)(G,{url:l,name:s.name}):m&&!u?(0,Z.jsx)(`article`,{className:`markdown`,children:(0,Z.jsx)(V,{highlight:i,children:p.data})}):(0,Z.jsx)(`pre`,{className:`raw`,children:(0,Z.jsx)(z,{value:p.data,query:i})})})]})}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:n,onCancel:i}){let{request:a,projectId:o}=I(),[l,u]=(0,q.useState)([]),[f,p]=(0,q.useState)(),[m,h]=(0,q.useState)(!1),[g,_]=(0,q.useState)(``),v=(0,q.useRef)(null),b=(0,q.useRef)(y()),x=(0,q.useRef)(new Map);function S(e){u(e),b.current=y(),_(``)}async function C(){h(!0),_(``);try{let e=[];for(let[n,r]of l.entries()){let i=x.current.get(r.id);if(!i){let e=r.kind===`file`?r.file.name:`${Q(r.text)}.txt`,a=await fetch(t(`/api/v1/projects/${o}/materials/uploads`),{method:`POST`,headers:{"content-type":`application/octet-stream`,"x-teammy-web":`1`},body:r.kind===`file`?r.file:new Blob([r.text],{type:`text/plain`})}),s=await a.json();if(!a.ok)throw Error(s.error?.message??`第 ${n+1} 项上传失败。`);i={name:e,sha256:s.sha256,size:s.size},x.current.set(r.id,i)}e.push(i)}let r=l.length===1&&l[0]?.kind===`text`?l[0].text.trim():``,i;try{let e=new URL(r);[`http:`,`https:`].includes(e.protocol)&&(i=e.href)}catch{}n((await a(`materials`,X,{method:`POST`,body:{operationId:b.current,originals:e,...i?{url:i}:{}}})).id)}catch(t){_(e(t))}finally{h(!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)(r,{error:!0,children:g}),(0,Z.jsxs)(`fieldset`,{disabled:m,children:[(0,Z.jsxs)(`div`,{className:`attachment-grid`,children:[l.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)(c,{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)(c,{name:ue(e)}),(0,Z.jsx)(`span`,{className:`attachment-name`,children:e.file.name})]}),(0,Z.jsx)(R,{className:`attachment-remove`,icon:`close`,label:`移除:${e.kind===`file`?e.file.name:Q(e.text)}`,onClick:()=>{x.current.delete(e.id),S(l.filter(t=>t.id!==e.id))}})]},e.id)),(0,Z.jsxs)(`button`,{type:`button`,className:`attachment-add`,onClick:()=>p({text:``}),children:[(0,Z.jsx)(c,{name:`addText`}),(0,Z.jsx)(`span`,{children:`添加文本/链接`})]}),(0,Z.jsxs)(`button`,{type:`button`,className:`attachment-add`,onClick:()=>v.current?.click(),children:[(0,Z.jsx)(c,{name:`addFile`}),(0,Z.jsx)(`span`,{children:`添加文件`})]})]}),(0,Z.jsx)(`input`,{ref:v,type:`file`,multiple:!0,hidden:!0,"aria-label":`原始文件`,onChange:e=>{S([...l,...[...e.target.files??[]].map(e=>({id:y(),kind:`file`,file:e}))]),e.target.value=``}}),(0,Z.jsxs)(`div`,{className:`actions attachment-actions`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:i,children:`取消`}),(0,Z.jsx)(`button`,{type:`submit`,className:`primary`,disabled:!l.length,children:m?`上传中…`:`提交资料`})]})]})]}),f&&(0,Z.jsx)(d,{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??y(),kind:`text`,text:f.text};x.current.delete(t.id),S(f.id?l.map(e=>e.id===f.id?t:e):[...l,t]),p(void 0)},children:[(0,Z.jsx)(s,{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=P([`overview`,`handoff`]),me=w({title:S().trim().min(1),summary:S().trim().min(1)}).strict(),he=w({markdown:S().trim().min(1)}).strict(),ge=me.extend({sourceRevision:N,sourceHash:k,generatedAt:S(),stale:x()}),_e=w({kind:pe,status:P([`absent`,`queued`,`running`,`succeeded`,`failed`]),available:x(),currentRevision:N,sourceRevision:N.nullable(),stale:x(),result:m([me,he]).nullable(),generatedAt:S().nullable(),error:S().nullable()}),ve=P([`claude-code`,`codex`,`cursor`,`pi`,`dsh`]),ye=w({formatVersion:A(1),adapterVersion:A(1),agent:ve,nativeId:S().min(1).max(512),cwd:S().min(1).max(4096),messages:v(w({id:S().min(1).max(1024),role:P([`user`,`assistant`]),text:S().min(1),source:S().min(1).max(1024)}).strict())}).strict().refine(e=>new Set(e.messages.map(e=>e.id)).size===e.messages.length,`Duplicate message IDs.`);w({operationId:h(),sessionKey:k,parentRevision:N,blob:T}).strict(),w({revision:N,hash:k.nullable(),cleared:x()});var be=w({owner:g,sessionKey:k,agent:ve,nativeId:S(),cwd:S(),title:S(),revision:N,updatedAt:S(),messageCount:D().int().nonnegative(),blob:T,overview:ge.optional()}),xe=w({sessions:v(be),nextCursor:N.nullable()}),Se=w({totalSessions:D().int().nonnegative(),totalMessages:D().int().nonnegative(),memberCount:D().int().nonnegative(),updatedAt:S().nullable()});w({owner:g.optional(),sessionKey:k.optional()}).strict().refine(e=>!e.sessionKey||!!e.owner,`A session scope requires an owner.`);var Ce=w({matches:v(w({owner:g,sessionKey:k,revision:N,messageId:S(),source:P([`message`,`handoff`]).default(`message`),role:P([`user`,`assistant`]),snippet:S(),title:S()})),nextCursor:N.nullable()}),we=w({owner:g,key:k,revision:N.refine(e=>e>0).optional(),messageId:S().min(1).optional(),source:P([`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,q.useState)(()=>new Set(n?.key?[n.owner]:[])),[l,u]=(0,q.useState)(e[0]?.id??``);return(0,Z.jsx)(`div`,{role:a===1?`tree`:`group`,"aria-label":`成员对话`,"data-testid":`session-tree`,onKeyDown:a===1?U:void 0,children:[...e].sort((e,t)=>te(e.id,t.id)).map(e=>(0,Z.jsxs)(`div`,{role:`none`,children:[(0,Z.jsxs)(C,{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:l===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)(c,{name:`chevron`,size:`small`})}),children:[(0,Z.jsx)(c,{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:l,onFocus:u},`${e.id}/${t}`)]},e.id))})}function De({level:t,owner:n,selected:i,onSession:o,focused:s,onFocus:l}){let{request:u,projectId:d}=I(),f=(0,q.useCallback)(e=>u(`sessions?${new URLSearchParams({owner:n,limit:`50`,order:`updated`})}`,xe,{signal:e}),[n,u]),p=j(f,15e3,a(d,`session-tree`,n)),[m,h]=(0,q.useState)(),[g,_]=(0,q.useState)(!1),[v,y]=(0,q.useState)(``),b=(0,q.useRef)(null);(0,q.useEffect)(()=>()=>b.current?.abort(),[]);let x=m?m.nextCursor:p.data?.nextCursor;return(0,Z.jsxs)(`div`,{role:`group`,"aria-busy":p.loading||g,children:[(0,Z.jsx)(r,{error:!0,children:p.error||v}),p.error&&(0,Z.jsx)(`button`,{onClick:()=>void p.reload(),children:`重试`}),p.loading&&!p.data&&(0,Z.jsx)(`span`,{className:`tree-status`,role:`status`,children:`正在加载…`}),[...new Map([...m?.sessions??[],...p.data?.sessions??[]].map(e=>[e.sessionKey,e])).values()].sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt)||e.sessionKey.localeCompare(t.sessionKey)).map(e=>(0,Z.jsxs)(C,{type:`button`,role:`treeitem`,"aria-level":t,"aria-selected":i?.owner===n&&i.key===e.sessionKey,className:`tree-item`,style:{"--tree-level":t},tabIndex:s===`${n}/${e.sessionKey}`?0:-1,"data-testid":`session-row`,"data-owner-id":n,"data-session-key":e.sessionKey,title:O(e.title||e.nativeId),onFocus:()=>l(`${n}/${e.sessionKey}`),onClick:()=>o({owner:n,key:e.sessionKey,title:e.title||e.nativeId}),leading:(0,Z.jsx)(`span`,{className:`tree-chevron`}),children:[(0,Z.jsx)(c,{name:`sessions`}),(0,Z.jsx)(`span`,{className:`tree-name`,children:O(e.title||e.nativeId)})]},e.sessionKey)),x!=null&&(0,Z.jsx)(`button`,{className:`tree-action`,"data-testid":`session-tree-more`,disabled:g,onClick:async()=>{_(!0),y(``);let t=new AbortController;b.current=t;try{let e=await u(`sessions?${new URLSearchParams({owner:n,after:String(x),limit:`50`,order:`updated`})}`,xe,{signal:t.signal});h(t=>({sessions:[...t?.sessions??[],...e.sessions],nextCursor:e.nextCursor}))}catch(n){t.signal.aborted||y(e(n))}finally{t.signal.aborted||_(!1)}},children:`加载更多`})]})}function Oe({info:e,targeted:t=!1,highlight:n=``}){let[r,i]=(0,q.useState)(t),a=(0,q.useRef)(null);return(0,q.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:t,revision:i,highlight:a}){let{request:s}=I(),c=`sessions/${encodeURIComponent(t.owner)}/${t.sessionKey}`,l=(0,q.useCallback)(e=>s(`${c}/analysis/handoff${i===void 0?``:`?revision=${i}`}`,_e,{signal:e}),[s,c,i]),u=j(l,5e3),d=o(),[f,p]=(0,q.useState)(!1),[m,h]=(0,q.useState)(``),g=u.data,_=f||g?.status===`queued`||g?.status===`running`,v=g?.result&&`markdown`in g.result?g.result.markdown:void 0;return(0,Z.jsxs)(`div`,{className:`stack`,"data-testid":`session-handoff`,children:[(0,Z.jsx)(r,{error:!0,children:m||u.error}),u.loading&&!g&&(0,Z.jsx)(`small`,{role:`status`,children:`正在加载…`}),g&&(0,Z.jsxs)(`div`,{className:`inline-actions`,children:[g.status===`failed`&&i===void 0&&(0,Z.jsx)(`button`,{"data-testid":`session-handoff-generate`,disabled:_||!g.available,onClick:async()=>{p(!0),h(``);try{await s(`${c}/handoff`,_e,{method:`POST`,signal:d}),await u.reload()}catch(t){d.aborted||h(e(t))}finally{d.aborted||p(!1)}},children:_?`正在整理…`:`重试`}),!g.available&&(0,Z.jsx)(`small`,{children:`请先配置项目模型接入点`}),g.status===`failed`&&(0,Z.jsx)(`small`,{children:`整理未完成,可重试`}),g.available&&g.status!==`failed`&&(!v||g.stale||_)&&(0,Z.jsx)(`small`,{role:`status`,children:g.status===`running`||f?`正在整理…`:v?`对话已有新内容,等待自动更新…`:`等待自动整理…`}),g.currentRevision!==t.revision&&(0,Z.jsx)(`small`,{children:`交接说明使用最新对话;当前阅读的是历史原文`})]}),v&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`small`,{children:[`基于版本 `,g.sourceRevision,` · `,(0,Z.jsx)(n,{value:g.generatedAt})]}),(0,Z.jsx)(`div`,{className:`markdown`,"data-testid":`session-handoff-body`,children:(0,Z.jsx)(V,{highlight:a,children:v})})]})]})}function Ae({members:e,active:n,onActivate:o,children:s}){let{request:c,projectId:l,api:u}=I(),d=(0,q.useCallback)(async e=>{let[t,n]=await Promise.all([c(`sessions/stats`,Se,{signal:e}),u.members(e)]);return{...t,members:n.members}},[c,u]),f=j(d,!0,a(l,`session-stats`)),[p,m]=(0,q.useState)(``),[h,g]=(0,q.useState)(``),[v,y]=(0,q.useState)(0),[b]=(0,q.useState)(()=>Te(location.search)),[x,S]=(0,q.useState)(b.target),[C,w]=(0,q.useState)(b.target),[T,E]=(0,q.useState)(b.error??``),[D,k]=(0,q.useState)(``),A=(0,q.useRef)(null),N=x?.key?x.title?`搜索对话:${O(x.title)}`:`搜索当前对话`:x?`搜索:${x.owner} 的对话内容`:``,P=()=>{S(void 0),k(``),F(),A.current?.focus()};function F(){if(!C?.messageId)return;let{messageId:e,...n}=C;w(n),history.replaceState(null,``,t(W(l,n.owner,n.key,n)))}let L=(0,q.useCallback)(e=>{S(t=>t?.owner===e.owner&&t.key===e.sessionKey&&t.title!==e.title?{...t,title:e.title}:t)},[]);(0,q.useEffect)(()=>{let e=()=>{if(!ee().endsWith(`/sessions`))return;let e=Te(location.search);w(e.target),S(e.target),E(e.error??``),g(``),m(``),k(``)};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]);let z=(e,n=``)=>{o(),w(e),S(e),g(``),k(n),E(``),history.replaceState(null,``,t(W(l,e.owner,e.key,e)))},B=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(r,{error:!0,children:f.error}),(0,Z.jsx)(Ee,{members:(f.data?.members??e).filter(e=>e.hasSessions),refresh:v,selected:n?x:void 0,level:2,onOwner:e=>{o(),S({owner:e}),w(void 0),g(``),k(``),E(``),history.replaceState(null,``,t(`/projects/${encodeURIComponent(l)}/sessions`))},onSession:z})]}),V=(0,Z.jsxs)(`section`,{className:`session-reader`,"aria-label":`对话内容与搜索`,children:[(0,Z.jsx)(_,{title:M.sessions,icon:`sessions`,count:(0,Z.jsx)(`span`,{"data-testid":`session-total`,children:f.data?.totalSessions??`—`}),children:(0,Z.jsx)(R,{icon:`refresh`,label:`刷新${M.sessions}`,"data-testid":`sessions-refresh`,disabled:f.loading,onClick:()=>{f.reload(),y(e=>e+1)}})}),(0,Z.jsx)(`div`,{className:`session-reader-content`,children:T?(0,Z.jsx)(r,{error:!0,children:T}):h?(0,Z.jsx)(je,{query:h,refresh:v,scope:{...x?{owner:x.owner}:{},...x?.key?{sessionKey:x.key}:{}},onSelect:e=>z(e,h)},`${h}/${x?.owner??``}/${x?.key??``}`):C?(0,Z.jsx)(Me,{selection:C,highlight:D,onLoaded:L,onLatest:()=>z({owner:C.owner,key:C.key})},`${C.owner}/${C.key}/${C.revision}/${C.source}/${v}`):(0,Z.jsx)(i,{mascot:!0,title:`选择对话开始阅读`,description:`也可以在下方搜索会话库内容。`})}),(0,Z.jsxs)(`form`,{className:`session-search-dock`,"data-testid":`session-search-form`,onSubmit:e=>{e.preventDefault(),g(p.trim()),k(``),E(``),y(e=>e+1)},children:[x&&(0,Z.jsxs)(`button`,{type:`button`,className:`search-scope-chip`,"data-testid":`session-search-scope`,title:`清除搜索范围`,"aria-label":`清除范围:${N}`,onClick:P,children:[(0,Z.jsx)(`span`,{className:`scope-label`,children:N}),(0,Z.jsx)(`span`,{"aria-hidden":`true`,children:`×`})]}),(0,Z.jsxs)(`div`,{className:`session-search-input-row`,children:[(0,Z.jsx)(`input`,{ref:A,"aria-label":`搜索对话`,"data-testid":`session-query`,value:p,maxLength:500,placeholder:`搜索会话库内容`,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Backspace`&&!p&&x&&(e.preventDefault(),P())}}),(h||p||D)&&(0,Z.jsx)(R,{icon:`close`,label:`清空搜索`,"data-testid":`session-search-clear`,onClick:()=>{m(``),g(``),k(``),F(),A.current?.focus()}}),(0,Z.jsx)(R,{icon:`search`,type:`submit`,label:`搜索`,"data-testid":`session-search`,disabled:!p.trim()})]})]})]});return s({hasSelection:!!x,tree:B,reader:V,href:C?W(l,C.owner,C.key,C):`/projects/${l}/sessions`})}function je({query:e,refresh:t,scope:n,onSelect:i}){let{request:a}=I(),[o,s]=(0,q.useState)(0),c=(0,q.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]),l=j(c);return(0,Z.jsxs)(`section`,{className:`session-results stack`,"aria-label":`搜索结果`,"aria-busy":l.loading,children:[(0,Z.jsx)(r,{error:!0,children:l.error}),l.error&&(0,Z.jsx)(`button`,{onClick:()=>void l.reload(),children:`重试`}),l.loading&&(0,Z.jsx)(`p`,{role:`status`,children:`正在搜索…`}),!l.loading&&l.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:O(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)(z,{value:B(t.snippet,e),query:e})})]},`${t.owner}:${t.sessionKey}:${t.revision}:${t.source}:${t.messageId}`)),!l.loading&&l.data?.matches.length===0&&(0,Z.jsx)(`p`,{className:`empty`,children:`没有找到匹配的对话`}),l.data?.nextCursor!=null&&(0,Z.jsx)(`button`,{"data-testid":`sessions-next`,disabled:l.loading,onClick:()=>s(l.data.nextCursor),children:`下一页`}),o>0&&(0,Z.jsx)(`button`,{disabled:l.loading,onClick:()=>s(0),children:`返回第一页`})]})}function Me({selection:e,highlight:t,onLoaded:n,onLatest:i}){let{request:a}=I(),o=(0,q.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 p&&e.code===`SESSION_NOT_FOUND`?Error(`找不到这条对话或引用的版本,原链接可能已失效。`):e}},[a,e.owner,e.key,e.revision]),s=j(o,5e3);return(0,q.useEffect)(()=>{s.data&&n(s.data)},[s.data,n]),(0,Z.jsxs)(`section`,{className:`session-conversation stack`,"data-testid":`session-detail`,children:[(0,Z.jsx)(r,{error:!0,children:s.error}),s.error&&(0,Z.jsx)(`button`,{onClick:()=>void s.reload(),children:`重试`}),s.loading&&!s.data&&(0,Z.jsx)(`p`,{role:`status`,children:`正在读取对话…`}),s.data&&(0,Z.jsx)(Ne,{info:s.data,messageId:e.messageId,handoff:e.source===`handoff`,highlight:t,pinned:e.revision!==void 0,onLatest:i},s.data.blob.sha256)]})}function Ne({info:e,messageId:i,handoff:a,highlight:o,pinned:s,onLatest:c}){let{readTextBlob:l,projectId:u}=I(),d=(0,q.useCallback)(async t=>ye.parse(JSON.parse(await l(e.blob,t))),[e.blob.sha256,e.blob.size]),f=j(d),p=(0,q.useRef)(null);return(0,q.useEffect)(()=>{f.data&&i&&p.current?.scrollIntoView({block:`center`})},[f.data,i]),(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`header`,{className:`conversation-header`,children:[(0,Z.jsx)(`h2`,{className:`session-title`,children:O(e.title||e.nativeId)}),(0,Z.jsxs)(`p`,{children:[e.owner,` · `,e.agent,` · `,e.messageCount,` 条消息`]}),(0,Z.jsxs)(`small`,{children:[(0,Z.jsx)(n,{value:e.updatedAt}),s&&(0,Z.jsxs)(Z.Fragment,{children:[` `,`· 引用版本 `,e.revision,` ·`,` `,(0,Z.jsx)(`a`,{href:t(W(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:a,highlight:a?o:``}),(0,Z.jsx)(r,{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:[i&&!f.data.messages.some(e=>e.id===i)&&(0,Z.jsx)(r,{children:`该版本中找不到引用的消息,已打开对话原文。`}),(0,Z.jsx)(`div`,{className:`session-messages`,children:f.data.messages.map(e=>(0,Z.jsx)(H,{mine:e.role===`user`,author:e.role===`user`?`用户`:`助手`,className:`session-message ${e.role} ${e.id===i?`matched`:``}`,"data-testid":`session-message`,"data-message-id":e.id,ref:e.id===i?p:void 0,children:(0,Z.jsx)(`div`,{className:`markdown`,children:(0,Z.jsx)(V,{highlight:o,children:e.text})})},e.id))})]})]})}var $=S().trim().min(1).max(120).refine(e=>!/[\r\n]/.test(e),`请使用一句简短的项目记忆。`),Pe=w({id:h(),text:$,state:P([`draft`,`kept`]),revision:D().int().positive(),createdAt:S(),updatedAt:S()}),Fe=w({cards:v(Pe)});w({id:h(),text:$}).strict(),w({expectedRevision:D().int().positive(),text:$.optional(),action:P([`keep`,`discard`,`delete`]).optional()}).strict().refine(e=>e.text!==void 0||e.action!==void 0,`没有需要保存的修改。`),w({text:$}).strict();function Ie(){let{request:e,projectId:t}=I(),n=(0,q.useCallback)(t=>e(`memory`,Fe,{signal:t}),[e]),i=j(n,5e3,a(t,`memory`)),[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)({}),d=(0,q.useRef)(null),f=[...i.data?.cards??[]];for(let e of Object.values(c))f.some(t=>t.id===e.id)||f.push(e);if(i.data&&!d.current&&(d.current=[...f].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 f)e.has(t.id)||(e.set(t.id,d.current.length),d.current.push(t.id));f.sort((t,n)=>e.get(t.id)-e.get(n.id))}return(0,Z.jsxs)(`section`,{className:`memory-page`,children:[(0,Z.jsx)(u,{title:`记忆`,children:(0,Z.jsx)(R,{icon:`plus`,label:`新增记忆`,disabled:!!o,onClick:()=>s(y())})}),(0,Z.jsx)(r,{error:!0,children:i.error}),!i.data&&i.loading&&(0,Z.jsx)(`p`,{role:`status`,children:`加载中…`}),(0,Z.jsxs)(`div`,{className:`memory-cards`,children:[o&&(0,Z.jsx)(Le,{id:o,onDone:()=>s(null),reload:i.reload},o),f.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&&f.length===0&&!o&&(0,Z.jsx)(`p`,{className:`memory-empty`,children:`暂无记忆`})]})}function Le({id:t,card:n,reload:i,onDone:a,onEditing:o}){let{request:s}=I(),[l,u]=(0,q.useState)(!n),[d,f]=(0,q.useState)(n?.text??``),[p,m]=(0,q.useState)(n?.revision),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(``),y=(0,q.useRef)(!1),b=(0,q.useRef)(!1);function S(){b.current=!1,o?.(!0),f(n?.text??``),m(n?.revision),v(``),u(!0)}function C(){b.current=!0,u(!1),v(``),o?.(!1),a?.()}async function T(r){if(!y.current){if(!r&&n&&d===n.text)u(!1),o?.(!1);else if((!r||r===`keep`)&&!$.safeParse(l?d:n?.text).success)v(`请填写一句记忆,最多 120 个字符。`);else{y.current=!0,g(!0),v(``);try{n?await s(`memory/${t}`,w({saved:x()}),{method:`PATCH`,body:{expectedRevision:l?p:n.revision,...r?{action:r}:{},...l&&r!==`discard`&&r!==`delete`?{text:d}:{}}}):await s(`memory`,Pe,{method:`POST`,body:{id:t,text:d}}),u(!1),await i(),o?.(!1),a?.()}catch(t){v(e(t)),await i()}finally{y.current=!1,g(!1)}}}}return(0,Z.jsxs)(`article`,{className:`memory-card`,"data-testid":`memory-card`,"data-memory-id":t,children:[(0,Z.jsx)(`span`,{className:`memory-status ${n?.state===`kept`?`is-kept`:``}`,role:`img`,"aria-label":n?.state===`kept`?`已保留`:`待确认`,children:(0,Z.jsx)(c,{name:n?.state===`kept`?`check`:`question`})}),(0,Z.jsxs)(`div`,{className:`memory-content`,children:[l?(0,Z.jsx)(`textarea`,{autoFocus:!0,"aria-label":`记忆内容`,value:d,maxLength:120,rows:2,disabled:h,onChange:e=>f(e.target.value.replace(/[\r\n]+/g,` `)),onBlur:e=>{b.current?b.current=!1:e.relatedTarget instanceof Element&&e.relatedTarget.closest(`.memory-actions`)||_||T()},onKeyDown:e=>{e.nativeEvent.isComposing||(e.key===`Escape`&&(e.preventDefault(),C()),e.key===`Enter`&&(e.preventDefault(),T()))}}):(0,Z.jsx)(`button`,{type:`button`,className:`memory-text`,"aria-label":`编辑记忆:${n?.text??``}`,onClick:S,children:n?.text}),(0,Z.jsx)(r,{error:!0,children:_})]}),(0,Z.jsxs)(`div`,{className:`memory-actions`,onMouseDown:e=>{l&&e.preventDefault()},children:[(!n||n.state===`draft`)&&(0,Z.jsx)(R,{icon:`check`,label:n?`保留记忆`:`保存记忆`,disabled:h,onClick:()=>void T(n?`keep`:void 0)}),l&&n?.state===`kept`&&(0,Z.jsx)(R,{icon:`check`,label:`保存记忆`,disabled:h,onClick:()=>void T()}),(0,Z.jsx)(R,{icon:`close`,label:n?n.state===`draft`?`舍弃记忆`:`删除记忆`:`取消新增`,disabled:h,onClick:()=>{n?T(n.state===`draft`?`discard`:`delete`):C()}})]})]})}function Re({section:e,members:t,navigate:n}){let{projectId:r}=I(),[i,a]=(0,q.useState)(e===`sessions`);(0,q.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)(b,{reading:!0,className:`resource-library`,"data-testid":`materials-page`,label:`资料目录`,navigation:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(_,{title:`资料`,icon:`materials`,children:r.actions}),(0,Z.jsxs)(`div`,{role:`tree`,"aria-label":`项目资料`,onKeyDown:U,style:{"--tree-level":1},children:[(0,Z.jsxs)(C,{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)(c,{name:`files`}),(0,Z.jsx)(`span`,{className:`tree-name`,children:`记忆`})]}),(0,Z.jsxs)(C,{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)(c,{name:`chevron`,size:`small`})}),onClick:()=>{a(!i),e!==`sessions`&&n(t.href)},children:[(0,Z.jsx)(c,{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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$ as e,H as t,J as n,R as r,St as i,X as a,c as o,h as s,l as c,q as l,s as u,u as d,y as f}from"./index-BQV0j0VG.js";var p=i(),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=a();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:i}){let a=i.expanded.has(v(e,t)),o=`folder:${v(e,t)}`;return(0,g.jsxs)(`div`,{role:`none`,children:[(0,g.jsxs)(s,{type:`button`,role:`treeitem`,className:`tree-item tree-folder`,style:y(n),"aria-label":t||e,"aria-level":n,"aria-expanded":a,"aria-selected":i.selected?.kind===`directory`&&i.selected.owner===e&&i.selected.path===t,tabIndex:i.focused===o?0:-1,"data-testid":`directory-row`,"data-owner-id":e,"data-directory-path":t,onFocus:()=>i.onFocus(o),onClick:()=>i.onToggle(e,t),leading:(0,g.jsx)(`span`,{className:`tree-chevron ${a?`expanded`:``}`,children:(0,g.jsx)(r,{name:`chevron`,size:`small`})}),children:[(0,g.jsx)(r,{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:i})]})}function S({owner:i,path:a,level:u,context:m,members:_=[]}){let{api:b,projectId:S}=f(),C=(0,p.useCallback)(e=>b.tree(i,a,void 0,``,e),[i,a]),w=l(C,!1,n(S,`file-tree`,i,a)),[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 e=await b.tree(i,a,w.data.revision,N,t.signal);t.signal.aborted||E({...e,entries:[...M?.entries??[],...e.entries]})}catch(n){t.signal.aborted||A(e(n))}finally{t.signal.aborted||O(!1)}}let F=[...(w.data?.entries??[]).filter(e=>!c(e.path)),...(M?.entries??[]).filter(e=>!c(e.path))],I=m.revealed;if(I?.owner===i&&!c(I.path)&&(!a||I.path.startsWith(a+`/`))){let e=a?I.path.slice(a.length+1):I.path,t=e.indexOf(`/`),n=t<0?I.path:[a,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(e=>i!==`_project`||!o(e.path)).map(e=>({...e,owner:i})),..._.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(i)?`teamcontext`:i,a),"aria-busy":w.loading||D,children:[w.loading&&(0,g.jsx)(`p`,{className:`tree-status`,role:`status`,children:`正在加载…`}),(0,g.jsx)(t,{error:!0,children:w.error||k}),w.error&&(0,g.jsx)(`button`,{className:`tree-action`,onClick:()=>void w.reload(),children:`重试`}),L.map(e=>e.kind===`directory`?(0,g.jsx)(x,{owner:e.owner,path:e.path,level:u,context:m},v(e.owner,e.path)):(0,g.jsxs)(s,{type:`button`,role:`treeitem`,className:`tree-item`,style:y(u),"aria-label":e.path,"aria-level":u,"aria-selected":m.selected?.kind===`file`&&m.selected.owner===i&&m.selected.path===e.path,tabIndex:m.focused===`file:${v(i,e.path)}`?0:-1,"data-testid":`file-row`,"data-owner-id":i,"data-file-path":e.path,onFocus:()=>m.onFocus(`file:${v(i,e.path)}`),onClick:()=>m.onSelect(i,e.path),leading:(0,g.jsx)(`span`,{className:`tree-chevron`}),children:[(0,g.jsx)(r,{name:`file`}),(0,g.jsx)(`span`,{className:`tree-name`,children:e.path.split(`/`).at(-1)})]},e.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{at as e}from"./index-BQV0j0VG.js";function t(t,n){if(!n||/^(?:[a-z][a-z0-9+.-]*:|\/)/i.test(n))return null;try{let r=n.split(/[?#]/,1)[0],i=r?t.split(`/`).slice(0,-1):t.split(`/`);for(let e of r.split(`/`)){let t=decodeURIComponent(e);if(t&&t!==`.`){if(t===`..`){if(!i.length)return null;i.pop()}else{if(t.includes(`/`)||t.includes(`\\`))return null;i.push(t)}}}return{path:i.length?e.parse(i.join(`/`)):``,directory:r.endsWith(`/`),anchor:n.includes(`#`)?decodeURIComponent(n.slice(n.indexOf(`#`)+1)):``}}catch{return null}}export{t};
|