@teammy/server 0.1.21 → 0.1.23

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.
@@ -1 +1 @@
1
- import{$ as e,A as t,B as n,D as r,G as i,H as a,I as o,J as s,K as c,L as l,M as u,N as d,O as f,P as p,R as m,V as h,W as g,X as _,Y as v,Z as y,b,d as x,f as S,k as C,m as w,nt as T,q as E,tt as D,v as O,w as k,x as A}from"./index-Cp6GL7NO.js";import{n as j,r as M,t as N}from"./Markdown-Dw-7DLy0.js";import{n as P}from"./project-links-Dy6-B89_.js";import{i as F,r as I}from"./WorkspaceTree-CGBdi6OV.js";var L=D(),R=g([`overview`,`handoff`]),z=v({title:_().trim().min(1),summary:_().trim().min(1)}).strict(),B=v({markdown:_().trim().min(1)}).strict(),V=z.extend({sourceRevision:h,sourceHash:n,generatedAt:_(),stale:c()}),H=v({kind:R,status:g([`absent`,`queued`,`running`,`succeeded`,`failed`]),available:c(),currentRevision:h,sourceRevision:h.nullable(),stale:c(),result:y([z,B]).nullable(),generatedAt:_().nullable(),error:_().nullable()}),U=g([`claude-code`,`codex`,`cursor`,`pi`,`dsh`]),W=v({formatVersion:E(1),adapterVersion:E(1),agent:U,nativeId:_().min(1).max(512),cwd:_().min(1).max(4096),messages:i(v({id:_().min(1).max(1024),role:g([`user`,`assistant`]),text:_().min(1),source:_().min(1).max(1024)}).strict())}).strict().refine(e=>new Set(e.messages.map(e=>e.id)).size===e.messages.length,`Duplicate message IDs.`);v({operationId:e(),sessionKey:n,parentRevision:h,blob:m}).strict(),v({revision:h,hash:n.nullable(),cleared:c()});var G=v({owner:a,sessionKey:n,agent:U,nativeId:_(),cwd:_(),title:_(),revision:h,updatedAt:_(),messageCount:s().int().nonnegative(),blob:m,overview:V.optional()}),K=v({sessions:i(G),nextCursor:h.nullable()}),q=v({totalSessions:s().int().nonnegative(),totalMessages:s().int().nonnegative(),memberCount:s().int().nonnegative(),updatedAt:_().nullable()});v({owner:a.optional(),sessionKey:n.optional()}).strict().refine(e=>!e.sessionKey||!!e.owner,`A session scope requires an owner.`);var J=v({matches:i(v({owner:a,sessionKey:n,revision:h,messageId:_(),source:g([`message`,`handoff`]).default(`message`),role:g([`user`,`assistant`]),snippet:_(),title:_()})),nextCursor:h.nullable()}),Y=v({owner:a,key:n,revision:h.refine(e=>e>0).optional(),messageId:_().min(1).optional(),source:g([`message`,`handoff`]).optional()});function X(e){let t=new URLSearchParams(e);if(![`owner`,`sessionKey`,`revision`,`messageId`].some(e=>t.has(e)))return{};let n=Y.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:`对话链接不完整或已损坏。`}}var Z=u();function Q({members:e,refresh:t,selected:n,onOwner:r,onSession:i}){let[a,o]=(0,L.useState)(()=>new Set(n?.key?[n.owner]:[])),[s,c]=(0,L.useState)(e[0]?.id??``);return(0,Z.jsx)(`div`,{role:`tree`,"aria-label":`成员对话`,"data-testid":`session-tree`,onKeyDown:I,children:[...e].sort((e,t)=>F(e.id,t.id)).map(e=>(0,Z.jsxs)(`div`,{role:`none`,children:[(0,Z.jsxs)(S,{type:`button`,role:`treeitem`,"aria-level":1,"aria-expanded":a.has(e.id),"aria-selected":n?.owner===e.id&&!n.key,className:`tree-item tree-folder`,style:{"--tree-level":1},tabIndex:s===e.id?0:-1,"data-testid":`session-owner`,"data-owner-id":e.id,onFocus:()=>c(e.id),onClick:()=>{o(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 ${a.has(e.id)?`expanded`:``}`,children:(0,Z.jsx)(b,{name:`chevron`,size:`small`})}),children:[(0,Z.jsx)(b,{name:`files`}),(0,Z.jsx)(`span`,{className:`tree-name`,title:e.id,children:e.id})]}),a.has(e.id)&&(0,Z.jsx)($,{owner:e.id,selected:n,onSession:i,focused:s,onFocus:c},`${e.id}/${t}`)]},e.id))})}function $({owner:e,selected:n,onSession:r,focused:i,onFocus:a}){let{request:s,projectId:c}=w(),l=(0,L.useCallback)(t=>s(`sessions?${new URLSearchParams({owner:e,limit:`50`,order:`updated`})}`,K,{signal:t}),[e,s]),u=C(l,15e3,t(c,`session-tree`,e)),[d,f]=(0,L.useState)(),[m,h]=(0,L.useState)(!1),[g,_]=(0,L.useState)(``),v=(0,L.useRef)(null);(0,L.useEffect)(()=>()=>v.current?.abort(),[]);let y=d?d.nextCursor:u.data?.nextCursor;return(0,Z.jsxs)(`div`,{role:`group`,"aria-busy":u.loading||m,children:[(0,Z.jsx)(k,{error:!0,children:u.error||g}),u.error&&(0,Z.jsx)(`button`,{onClick:()=>void u.reload(),children:`重试`}),u.loading&&!u.data&&(0,Z.jsx)(`span`,{className:`tree-status`,role:`status`,children:`正在加载…`}),[...new Map([...d?.sessions??[],...u.data?.sessions??[]].map(e=>[e.sessionKey,e])).values()].sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt)||e.sessionKey.localeCompare(t.sessionKey)).map(t=>(0,Z.jsxs)(S,{type:`button`,role:`treeitem`,"aria-level":2,"aria-selected":n?.owner===e&&n.key===t.sessionKey,className:`tree-item`,style:{"--tree-level":2},tabIndex:i===`${e}/${t.sessionKey}`?0:-1,"data-testid":`session-row`,"data-owner-id":e,"data-session-key":t.sessionKey,title:o(t.title||t.nativeId),onFocus:()=>a(`${e}/${t.sessionKey}`),onClick:()=>r({owner:e,key:t.sessionKey,title:t.title||t.nativeId}),leading:(0,Z.jsx)(`span`,{className:`tree-chevron`}),children:[(0,Z.jsx)(b,{name:`sessions`}),(0,Z.jsx)(`span`,{className:`tree-name`,children:o(t.title||t.nativeId)})]},t.sessionKey)),y!=null&&(0,Z.jsx)(`button`,{className:`tree-action`,"data-testid":`session-tree-more`,disabled:m,onClick:async()=>{h(!0),_(``);let t=new AbortController;v.current=t;try{let n=await s(`sessions?${new URLSearchParams({owner:e,after:String(y),limit:`50`,order:`updated`})}`,K,{signal:t.signal});f(e=>({sessions:[...e?.sessions??[],...n.sessions],nextCursor:n.nextCursor}))}catch(e){t.signal.aborted||_(p(e))}finally{t.signal.aborted||h(!1)}},children:`加载更多`})]})}function ee({info:e,targeted:t=!1,highlight:n=``}){let[r,i]=(0,L.useState)(t),a=(0,L.useRef)(null);return(0,L.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)(te,{info:e,revision:t?e.revision:void 0,highlight:n})]})}function te({info:e,revision:t,highlight:n}){let{request:i}=w(),a=`sessions/${encodeURIComponent(e.owner)}/${e.sessionKey}`,o=(0,L.useCallback)(e=>i(`${a}/analysis/handoff${t===void 0?``:`?revision=${t}`}`,H,{signal:e}),[i,a,t]),s=C(o,5e3),c=f(),[l,u]=(0,L.useState)(!1),[d,m]=(0,L.useState)(``),h=s.data,g=l||h?.status===`queued`||h?.status===`running`,_=h?.result&&`markdown`in h.result?h.result.markdown:void 0;return(0,Z.jsxs)(`div`,{className:`stack`,"data-testid":`session-handoff`,children:[(0,Z.jsx)(k,{error:!0,children:d||s.error}),s.loading&&!h&&(0,Z.jsx)(`small`,{role:`status`,children:`正在加载…`}),h&&(0,Z.jsxs)(`div`,{className:`inline-actions`,children:[h.status===`failed`&&t===void 0&&(0,Z.jsx)(`button`,{"data-testid":`session-handoff-generate`,disabled:g||!h.available,onClick:async()=>{u(!0),m(``);try{await i(`${a}/handoff`,H,{method:`POST`,signal:c}),await s.reload()}catch(e){c.aborted||m(p(e))}finally{c.aborted||u(!1)}},children:g?`正在整理…`:`重试`}),!h.available&&(0,Z.jsx)(`small`,{children:`请先配置项目模型接入点`}),h.status===`failed`&&(0,Z.jsx)(`small`,{children:`整理未完成,可重试`}),h.available&&h.status!==`failed`&&(!_||h.stale||g)&&(0,Z.jsx)(`small`,{role:`status`,children:h.status===`running`||l?`正在整理…`:_?`对话已有新内容,等待自动更新…`:`等待自动整理…`}),h.currentRevision!==e.revision&&(0,Z.jsx)(`small`,{children:`交接说明使用最新对话;当前阅读的是历史原文`})]}),_&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`small`,{children:[`基于版本 `,h.sourceRevision,` · `,(0,Z.jsx)(r,{value:h.generatedAt})]}),(0,Z.jsx)(`div`,{className:`markdown`,"data-testid":`session-handoff-body`,children:(0,Z.jsx)(N,{highlight:n,children:_})})]})]})}function ne({members:e}){let{request:n,projectId:r,api:i}=w(),a=(0,L.useCallback)(async e=>{let[t,r]=await Promise.all([n(`sessions/stats`,q,{signal:e}),i.members(e)]);return{...t,members:r.members}},[n,i]),s=C(a,!0,t(r,`session-stats`)),[c,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(``),[p,m]=(0,L.useState)(0),[h]=(0,L.useState)(()=>X(location.search)),[g,_]=(0,L.useState)(h.target),[v,y]=(0,L.useState)(h.target),[b,S]=(0,L.useState)(h.error??``),[E,D]=(0,L.useState)(``),j=(0,L.useRef)(null),M=g?.key?g.title?`搜索对话:${o(g.title)}`:`搜索当前对话`:g?`搜索:${g.owner} 的对话内容`:``,N=()=>{_(void 0),D(``),F(),j.current?.focus()};function F(){if(!v?.messageId)return;let{messageId:e,...t}=v;y(t),history.replaceState(null,``,T(P(r,t.owner,t.key,t)))}let I=(0,L.useCallback)(e=>{_(t=>t?.owner===e.owner&&t.key===e.sessionKey&&t.title!==e.title?{...t,title:e.title}:t)},[]);(0,L.useEffect)(()=>{let e=()=>{let e=X(location.search);y(e.target),_(e.target),S(e.error??``),f(``),u(``),D(``)};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]);let R=(e,t=``)=>{y(e),_(e),f(``),D(t),S(``),history.replaceState(null,``,T(P(r,e.owner,e.key,e)))};return(0,Z.jsxs)(`div`,{className:`split-layout file-explorer session-explorer`,children:[(0,Z.jsxs)(`section`,{className:`file-tree-pane`,"aria-label":`${l.sessions}目录`,children:[(0,Z.jsx)(x,{title:l.sessions,icon:`sessions`,count:(0,Z.jsx)(`span`,{"data-testid":`session-total`,children:s.data?.totalSessions??`—`}),children:(0,Z.jsx)(A,{icon:`refresh`,label:`刷新${l.sessions}`,"data-testid":`sessions-refresh`,disabled:s.loading,onClick:()=>{s.reload(),m(e=>e+1)}})}),(0,Z.jsx)(k,{error:!0,children:s.error}),(0,Z.jsx)(Q,{members:(s.data?.members??e).filter(e=>e.hasSessions),refresh:p,selected:g,onOwner:e=>{_({owner:e}),y(void 0),f(``),D(``),S(``),history.replaceState(null,``,T(`/projects/${encodeURIComponent(r)}/sessions`))},onSession:R})]}),(0,Z.jsxs)(`section`,{className:`session-reader`,"aria-label":`对话内容与搜索`,children:[(0,Z.jsx)(`div`,{className:`session-reader-content`,children:b?(0,Z.jsx)(k,{error:!0,children:b}):d?(0,Z.jsx)(re,{query:d,refresh:p,scope:{...g?{owner:g.owner}:{},...g?.key?{sessionKey:g.key}:{}},onSelect:e=>R(e,d)},`${d}/${g?.owner??``}/${g?.key??``}`):v?(0,Z.jsx)(ie,{selection:v,highlight:E,onLoaded:I,onLatest:()=>R({owner:v.owner,key:v.key})},`${v.owner}/${v.key}/${v.revision}/${v.source}/${p}`):(0,Z.jsx)(O,{mascot:!0,title:`选择对话开始阅读`,description:`也可以在下方搜索会话库内容。`})}),(0,Z.jsxs)(`form`,{className:`session-search-dock`,"data-testid":`session-search-form`,onSubmit:e=>{e.preventDefault(),f(c.trim()),D(``),S(``),m(e=>e+1)},children:[g&&(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:c,maxLength:500,placeholder:`搜索会话库内容`,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Backspace`&&!c&&g&&(e.preventDefault(),N())}}),(d||c||E)&&(0,Z.jsx)(A,{icon:`close`,label:`清空搜索`,"data-testid":`session-search-clear`,onClick:()=>{u(``),f(``),D(``),F(),j.current?.focus()}}),(0,Z.jsx)(A,{icon:`search`,type:`submit`,label:`搜索`,"data-testid":`session-search`,disabled:!c.trim()})]})]})]})]})}function re({query:e,refresh:t,scope:n,onSelect:r}){let{request:i}=w(),[a,s]=(0,L.useState)(0),c=(0,L.useCallback)(t=>i(`sessions/search?${new URLSearchParams({q:e,after:String(a),limit:`30`,order:`updated`,...n.owner?{owner:n.owner}:{},...n.sessionKey?{sessionKey:n.sessionKey}:{}})}`,J,{signal:t}),[i,e,a,t,n.owner,n.sessionKey]),l=C(c);return(0,Z.jsxs)(`section`,{className:`session-results stack`,"aria-label":`搜索结果`,"aria-busy":l.loading,children:[(0,Z.jsx)(k,{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:()=>r({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)(j,{value:M(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:`下一页`}),a>0&&(0,Z.jsx)(`button`,{disabled:l.loading,onClick:()=>s(0),children:`返回第一页`})]})}function ie({selection:e,highlight:t,onLoaded:n,onLatest:r}){let{request:i}=w(),a=(0,L.useCallback)(async t=>{try{return await i(`sessions/${encodeURIComponent(e.owner)}/${e.key}${e.revision===void 0?``:`?revision=${e.revision}`}`,G,{signal:t})}catch(e){throw e instanceof d&&e.code===`SESSION_NOT_FOUND`?Error(`找不到这条对话或引用的版本,原链接可能已失效。`):e}},[i,e.owner,e.key,e.revision]),o=C(a,5e3);return(0,L.useEffect)(()=>{o.data&&n(o.data)},[o.data,n]),(0,Z.jsxs)(`section`,{className:`session-conversation stack`,"data-testid":`session-detail`,children:[(0,Z.jsx)(k,{error:!0,children:o.error}),o.error&&(0,Z.jsx)(`button`,{onClick:()=>void o.reload(),children:`重试`}),o.loading&&!o.data&&(0,Z.jsx)(`p`,{role:`status`,children:`正在读取对话…`}),o.data&&(0,Z.jsx)(ae,{info:o.data,messageId:e.messageId,handoff:e.source===`handoff`,highlight:t,pinned:e.revision!==void 0,onLatest:r},o.data.blob.sha256)]})}function ae({info:e,messageId:t,handoff:n,highlight:i,pinned:a,onLatest:s}){let{readTextBlob:c,projectId:l}=w(),u=(0,L.useCallback)(async t=>W.parse(JSON.parse(await c(e.blob,t))),[e.blob.sha256,e.blob.size]),d=C(u),f=(0,L.useRef)(null);return(0,L.useEffect)(()=>{d.data&&t&&f.current?.scrollIntoView({block:`center`})},[d.data,t]),(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)(r,{value:e.updatedAt}),a&&(0,Z.jsxs)(Z.Fragment,{children:[` `,`· 引用版本 `,e.revision,` ·`,` `,(0,Z.jsx)(`a`,{href:T(P(l,e.owner,e.sessionKey)),onClick:e=>{e.preventDefault(),s()},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)(ee,{info:e,targeted:n,highlight:n?i:``}),(0,Z.jsx)(k,{error:!0,children:d.error}),d.error&&(0,Z.jsx)(`button`,{onClick:()=>void d.reload(),children:`重新读取`}),d.loading&&(0,Z.jsx)(`p`,{role:`status`,children:`正在读取对话…`}),d.data&&(0,Z.jsxs)(Z.Fragment,{children:[t&&!d.data.messages.some(e=>e.id===t)&&(0,Z.jsx)(k,{children:`该版本中找不到引用的消息,已打开对话原文。`}),(0,Z.jsx)(`div`,{className:`session-messages`,children:d.data.messages.map(e=>(0,Z.jsxs)(`article`,{className:`session-message ${e.role} ${e.id===t?`matched`:``}`,"data-testid":`session-message`,"data-message-id":e.id,ref:e.id===t?f:void 0,children:[(0,Z.jsx)(`div`,{className:`message-role`,children:e.role===`user`?`用户`:`助手`}),(0,Z.jsx)(`div`,{className:`markdown`,children:(0,Z.jsx)(N,{highlight:i,children:e.text})})]},e.id))})]})]})}export{ne as Sessions};
1
+ import{$ as e,A as t,B as n,D as r,G as i,H as a,I as o,J as s,K as c,L as l,M as u,N as d,O as f,P as p,R as m,V as h,W as g,X as _,Y as v,Z as y,b,d as x,f as S,k as C,m as w,nt as T,q as E,tt as D,v as O,w as k,x as A}from"./index-DNl0sC00.js";import{n as j,r as M,t as N}from"./Markdown-lH5xxoeb.js";import{n as P}from"./project-links-Dy6-B89_.js";import{i as F,r as I}from"./WorkspaceTree-0faH_Exl.js";var L=D(),R=g([`overview`,`handoff`]),z=v({title:_().trim().min(1),summary:_().trim().min(1)}).strict(),B=v({markdown:_().trim().min(1)}).strict(),V=z.extend({sourceRevision:h,sourceHash:n,generatedAt:_(),stale:c()}),H=v({kind:R,status:g([`absent`,`queued`,`running`,`succeeded`,`failed`]),available:c(),currentRevision:h,sourceRevision:h.nullable(),stale:c(),result:y([z,B]).nullable(),generatedAt:_().nullable(),error:_().nullable()}),U=g([`claude-code`,`codex`,`cursor`,`pi`,`dsh`]),W=v({formatVersion:E(1),adapterVersion:E(1),agent:U,nativeId:_().min(1).max(512),cwd:_().min(1).max(4096),messages:i(v({id:_().min(1).max(1024),role:g([`user`,`assistant`]),text:_().min(1),source:_().min(1).max(1024)}).strict())}).strict().refine(e=>new Set(e.messages.map(e=>e.id)).size===e.messages.length,`Duplicate message IDs.`);v({operationId:e(),sessionKey:n,parentRevision:h,blob:m}).strict(),v({revision:h,hash:n.nullable(),cleared:c()});var G=v({owner:a,sessionKey:n,agent:U,nativeId:_(),cwd:_(),title:_(),revision:h,updatedAt:_(),messageCount:s().int().nonnegative(),blob:m,overview:V.optional()}),K=v({sessions:i(G),nextCursor:h.nullable()}),q=v({totalSessions:s().int().nonnegative(),totalMessages:s().int().nonnegative(),memberCount:s().int().nonnegative(),updatedAt:_().nullable()});v({owner:a.optional(),sessionKey:n.optional()}).strict().refine(e=>!e.sessionKey||!!e.owner,`A session scope requires an owner.`);var J=v({matches:i(v({owner:a,sessionKey:n,revision:h,messageId:_(),source:g([`message`,`handoff`]).default(`message`),role:g([`user`,`assistant`]),snippet:_(),title:_()})),nextCursor:h.nullable()}),Y=v({owner:a,key:n,revision:h.refine(e=>e>0).optional(),messageId:_().min(1).optional(),source:g([`message`,`handoff`]).optional()});function X(e){let t=new URLSearchParams(e);if(![`owner`,`sessionKey`,`revision`,`messageId`].some(e=>t.has(e)))return{};let n=Y.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:`对话链接不完整或已损坏。`}}var Z=u();function Q({members:e,refresh:t,selected:n,onOwner:r,onSession:i}){let[a,o]=(0,L.useState)(()=>new Set(n?.key?[n.owner]:[])),[s,c]=(0,L.useState)(e[0]?.id??``);return(0,Z.jsx)(`div`,{role:`tree`,"aria-label":`成员对话`,"data-testid":`session-tree`,onKeyDown:I,children:[...e].sort((e,t)=>F(e.id,t.id)).map(e=>(0,Z.jsxs)(`div`,{role:`none`,children:[(0,Z.jsxs)(S,{type:`button`,role:`treeitem`,"aria-level":1,"aria-expanded":a.has(e.id),"aria-selected":n?.owner===e.id&&!n.key,className:`tree-item tree-folder`,style:{"--tree-level":1},tabIndex:s===e.id?0:-1,"data-testid":`session-owner`,"data-owner-id":e.id,onFocus:()=>c(e.id),onClick:()=>{o(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 ${a.has(e.id)?`expanded`:``}`,children:(0,Z.jsx)(b,{name:`chevron`,size:`small`})}),children:[(0,Z.jsx)(b,{name:`files`}),(0,Z.jsx)(`span`,{className:`tree-name`,title:e.id,children:e.id})]}),a.has(e.id)&&(0,Z.jsx)($,{owner:e.id,selected:n,onSession:i,focused:s,onFocus:c},`${e.id}/${t}`)]},e.id))})}function $({owner:e,selected:n,onSession:r,focused:i,onFocus:a}){let{request:s,projectId:c}=w(),l=(0,L.useCallback)(t=>s(`sessions?${new URLSearchParams({owner:e,limit:`50`,order:`updated`})}`,K,{signal:t}),[e,s]),u=C(l,15e3,t(c,`session-tree`,e)),[d,f]=(0,L.useState)(),[m,h]=(0,L.useState)(!1),[g,_]=(0,L.useState)(``),v=(0,L.useRef)(null);(0,L.useEffect)(()=>()=>v.current?.abort(),[]);let y=d?d.nextCursor:u.data?.nextCursor;return(0,Z.jsxs)(`div`,{role:`group`,"aria-busy":u.loading||m,children:[(0,Z.jsx)(k,{error:!0,children:u.error||g}),u.error&&(0,Z.jsx)(`button`,{onClick:()=>void u.reload(),children:`重试`}),u.loading&&!u.data&&(0,Z.jsx)(`span`,{className:`tree-status`,role:`status`,children:`正在加载…`}),[...new Map([...d?.sessions??[],...u.data?.sessions??[]].map(e=>[e.sessionKey,e])).values()].sort((e,t)=>t.updatedAt.localeCompare(e.updatedAt)||e.sessionKey.localeCompare(t.sessionKey)).map(t=>(0,Z.jsxs)(S,{type:`button`,role:`treeitem`,"aria-level":2,"aria-selected":n?.owner===e&&n.key===t.sessionKey,className:`tree-item`,style:{"--tree-level":2},tabIndex:i===`${e}/${t.sessionKey}`?0:-1,"data-testid":`session-row`,"data-owner-id":e,"data-session-key":t.sessionKey,title:o(t.title||t.nativeId),onFocus:()=>a(`${e}/${t.sessionKey}`),onClick:()=>r({owner:e,key:t.sessionKey,title:t.title||t.nativeId}),leading:(0,Z.jsx)(`span`,{className:`tree-chevron`}),children:[(0,Z.jsx)(b,{name:`sessions`}),(0,Z.jsx)(`span`,{className:`tree-name`,children:o(t.title||t.nativeId)})]},t.sessionKey)),y!=null&&(0,Z.jsx)(`button`,{className:`tree-action`,"data-testid":`session-tree-more`,disabled:m,onClick:async()=>{h(!0),_(``);let t=new AbortController;v.current=t;try{let n=await s(`sessions?${new URLSearchParams({owner:e,after:String(y),limit:`50`,order:`updated`})}`,K,{signal:t.signal});f(e=>({sessions:[...e?.sessions??[],...n.sessions],nextCursor:n.nextCursor}))}catch(e){t.signal.aborted||_(p(e))}finally{t.signal.aborted||h(!1)}},children:`加载更多`})]})}function ee({info:e,targeted:t=!1,highlight:n=``}){let[r,i]=(0,L.useState)(t),a=(0,L.useRef)(null);return(0,L.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)(te,{info:e,revision:t?e.revision:void 0,highlight:n})]})}function te({info:e,revision:t,highlight:n}){let{request:i}=w(),a=`sessions/${encodeURIComponent(e.owner)}/${e.sessionKey}`,o=(0,L.useCallback)(e=>i(`${a}/analysis/handoff${t===void 0?``:`?revision=${t}`}`,H,{signal:e}),[i,a,t]),s=C(o,5e3),c=f(),[l,u]=(0,L.useState)(!1),[d,m]=(0,L.useState)(``),h=s.data,g=l||h?.status===`queued`||h?.status===`running`,_=h?.result&&`markdown`in h.result?h.result.markdown:void 0;return(0,Z.jsxs)(`div`,{className:`stack`,"data-testid":`session-handoff`,children:[(0,Z.jsx)(k,{error:!0,children:d||s.error}),s.loading&&!h&&(0,Z.jsx)(`small`,{role:`status`,children:`正在加载…`}),h&&(0,Z.jsxs)(`div`,{className:`inline-actions`,children:[h.status===`failed`&&t===void 0&&(0,Z.jsx)(`button`,{"data-testid":`session-handoff-generate`,disabled:g||!h.available,onClick:async()=>{u(!0),m(``);try{await i(`${a}/handoff`,H,{method:`POST`,signal:c}),await s.reload()}catch(e){c.aborted||m(p(e))}finally{c.aborted||u(!1)}},children:g?`正在整理…`:`重试`}),!h.available&&(0,Z.jsx)(`small`,{children:`请先配置项目模型接入点`}),h.status===`failed`&&(0,Z.jsx)(`small`,{children:`整理未完成,可重试`}),h.available&&h.status!==`failed`&&(!_||h.stale||g)&&(0,Z.jsx)(`small`,{role:`status`,children:h.status===`running`||l?`正在整理…`:_?`对话已有新内容,等待自动更新…`:`等待自动整理…`}),h.currentRevision!==e.revision&&(0,Z.jsx)(`small`,{children:`交接说明使用最新对话;当前阅读的是历史原文`})]}),_&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`small`,{children:[`基于版本 `,h.sourceRevision,` · `,(0,Z.jsx)(r,{value:h.generatedAt})]}),(0,Z.jsx)(`div`,{className:`markdown`,"data-testid":`session-handoff-body`,children:(0,Z.jsx)(N,{highlight:n,children:_})})]})]})}function ne({members:e}){let{request:n,projectId:r,api:i}=w(),a=(0,L.useCallback)(async e=>{let[t,r]=await Promise.all([n(`sessions/stats`,q,{signal:e}),i.members(e)]);return{...t,members:r.members}},[n,i]),s=C(a,!0,t(r,`session-stats`)),[c,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(``),[p,m]=(0,L.useState)(0),[h]=(0,L.useState)(()=>X(location.search)),[g,_]=(0,L.useState)(h.target),[v,y]=(0,L.useState)(h.target),[b,S]=(0,L.useState)(h.error??``),[E,D]=(0,L.useState)(``),j=(0,L.useRef)(null),M=g?.key?g.title?`搜索对话:${o(g.title)}`:`搜索当前对话`:g?`搜索:${g.owner} 的对话内容`:``,N=()=>{_(void 0),D(``),F(),j.current?.focus()};function F(){if(!v?.messageId)return;let{messageId:e,...t}=v;y(t),history.replaceState(null,``,T(P(r,t.owner,t.key,t)))}let I=(0,L.useCallback)(e=>{_(t=>t?.owner===e.owner&&t.key===e.sessionKey&&t.title!==e.title?{...t,title:e.title}:t)},[]);(0,L.useEffect)(()=>{let e=()=>{let e=X(location.search);y(e.target),_(e.target),S(e.error??``),f(``),u(``),D(``)};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]);let R=(e,t=``)=>{y(e),_(e),f(``),D(t),S(``),history.replaceState(null,``,T(P(r,e.owner,e.key,e)))};return(0,Z.jsxs)(`div`,{className:`split-layout file-explorer session-explorer`,children:[(0,Z.jsxs)(`section`,{className:`file-tree-pane`,"aria-label":`${l.sessions}目录`,children:[(0,Z.jsx)(x,{title:l.sessions,icon:`sessions`,count:(0,Z.jsx)(`span`,{"data-testid":`session-total`,children:s.data?.totalSessions??`—`}),children:(0,Z.jsx)(A,{icon:`refresh`,label:`刷新${l.sessions}`,"data-testid":`sessions-refresh`,disabled:s.loading,onClick:()=>{s.reload(),m(e=>e+1)}})}),(0,Z.jsx)(k,{error:!0,children:s.error}),(0,Z.jsx)(Q,{members:(s.data?.members??e).filter(e=>e.hasSessions),refresh:p,selected:g,onOwner:e=>{_({owner:e}),y(void 0),f(``),D(``),S(``),history.replaceState(null,``,T(`/projects/${encodeURIComponent(r)}/sessions`))},onSession:R})]}),(0,Z.jsxs)(`section`,{className:`session-reader`,"aria-label":`对话内容与搜索`,children:[(0,Z.jsx)(`div`,{className:`session-reader-content`,children:b?(0,Z.jsx)(k,{error:!0,children:b}):d?(0,Z.jsx)(re,{query:d,refresh:p,scope:{...g?{owner:g.owner}:{},...g?.key?{sessionKey:g.key}:{}},onSelect:e=>R(e,d)},`${d}/${g?.owner??``}/${g?.key??``}`):v?(0,Z.jsx)(ie,{selection:v,highlight:E,onLoaded:I,onLatest:()=>R({owner:v.owner,key:v.key})},`${v.owner}/${v.key}/${v.revision}/${v.source}/${p}`):(0,Z.jsx)(O,{mascot:!0,title:`选择对话开始阅读`,description:`也可以在下方搜索会话库内容。`})}),(0,Z.jsxs)(`form`,{className:`session-search-dock`,"data-testid":`session-search-form`,onSubmit:e=>{e.preventDefault(),f(c.trim()),D(``),S(``),m(e=>e+1)},children:[g&&(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:c,maxLength:500,placeholder:`搜索会话库内容`,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Backspace`&&!c&&g&&(e.preventDefault(),N())}}),(d||c||E)&&(0,Z.jsx)(A,{icon:`close`,label:`清空搜索`,"data-testid":`session-search-clear`,onClick:()=>{u(``),f(``),D(``),F(),j.current?.focus()}}),(0,Z.jsx)(A,{icon:`search`,type:`submit`,label:`搜索`,"data-testid":`session-search`,disabled:!c.trim()})]})]})]})]})}function re({query:e,refresh:t,scope:n,onSelect:r}){let{request:i}=w(),[a,s]=(0,L.useState)(0),c=(0,L.useCallback)(t=>i(`sessions/search?${new URLSearchParams({q:e,after:String(a),limit:`30`,order:`updated`,...n.owner?{owner:n.owner}:{},...n.sessionKey?{sessionKey:n.sessionKey}:{}})}`,J,{signal:t}),[i,e,a,t,n.owner,n.sessionKey]),l=C(c);return(0,Z.jsxs)(`section`,{className:`session-results stack`,"aria-label":`搜索结果`,"aria-busy":l.loading,children:[(0,Z.jsx)(k,{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:()=>r({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)(j,{value:M(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:`下一页`}),a>0&&(0,Z.jsx)(`button`,{disabled:l.loading,onClick:()=>s(0),children:`返回第一页`})]})}function ie({selection:e,highlight:t,onLoaded:n,onLatest:r}){let{request:i}=w(),a=(0,L.useCallback)(async t=>{try{return await i(`sessions/${encodeURIComponent(e.owner)}/${e.key}${e.revision===void 0?``:`?revision=${e.revision}`}`,G,{signal:t})}catch(e){throw e instanceof d&&e.code===`SESSION_NOT_FOUND`?Error(`找不到这条对话或引用的版本,原链接可能已失效。`):e}},[i,e.owner,e.key,e.revision]),o=C(a,5e3);return(0,L.useEffect)(()=>{o.data&&n(o.data)},[o.data,n]),(0,Z.jsxs)(`section`,{className:`session-conversation stack`,"data-testid":`session-detail`,children:[(0,Z.jsx)(k,{error:!0,children:o.error}),o.error&&(0,Z.jsx)(`button`,{onClick:()=>void o.reload(),children:`重试`}),o.loading&&!o.data&&(0,Z.jsx)(`p`,{role:`status`,children:`正在读取对话…`}),o.data&&(0,Z.jsx)(ae,{info:o.data,messageId:e.messageId,handoff:e.source===`handoff`,highlight:t,pinned:e.revision!==void 0,onLatest:r},o.data.blob.sha256)]})}function ae({info:e,messageId:t,handoff:n,highlight:i,pinned:a,onLatest:s}){let{readTextBlob:c,projectId:l}=w(),u=(0,L.useCallback)(async t=>W.parse(JSON.parse(await c(e.blob,t))),[e.blob.sha256,e.blob.size]),d=C(u),f=(0,L.useRef)(null);return(0,L.useEffect)(()=>{d.data&&t&&f.current?.scrollIntoView({block:`center`})},[d.data,t]),(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)(r,{value:e.updatedAt}),a&&(0,Z.jsxs)(Z.Fragment,{children:[` `,`· 引用版本 `,e.revision,` ·`,` `,(0,Z.jsx)(`a`,{href:T(P(l,e.owner,e.sessionKey)),onClick:e=>{e.preventDefault(),s()},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)(ee,{info:e,targeted:n,highlight:n?i:``}),(0,Z.jsx)(k,{error:!0,children:d.error}),d.error&&(0,Z.jsx)(`button`,{onClick:()=>void d.reload(),children:`重新读取`}),d.loading&&(0,Z.jsx)(`p`,{role:`status`,children:`正在读取对话…`}),d.data&&(0,Z.jsxs)(Z.Fragment,{children:[t&&!d.data.messages.some(e=>e.id===t)&&(0,Z.jsx)(k,{children:`该版本中找不到引用的消息,已打开对话原文。`}),(0,Z.jsx)(`div`,{className:`session-messages`,children:d.data.messages.map(e=>(0,Z.jsxs)(`article`,{className:`session-message ${e.role} ${e.id===t?`matched`:``}`,"data-testid":`session-message`,"data-message-id":e.id,ref:e.id===t?f:void 0,children:[(0,Z.jsx)(`div`,{className:`message-role`,children:e.role===`user`?`用户`:`助手`}),(0,Z.jsx)(`div`,{className:`markdown`,children:(0,Z.jsx)(N,{highlight:i,children:e.text})})]},e.id))})]})]})}export{ne as Sessions};
@@ -1 +1 @@
1
- import{A as e,M as t,P as n,b as r,c as i,f as a,k as o,l as s,m as c,s as l,tt as u,u as d,w as f}from"./index-Cp6GL7NO.js";var p=u(),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=t();function _(e){let t=e.target.closest(`[role="treeitem"]`);if(!t)return;let n=[...e.currentTarget.querySelectorAll(`[role="treeitem"]`)],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:l,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 o=i.expanded.has(v(e,t)),s=`folder:${v(e,t)}`;return(0,g.jsxs)(`div`,{role:`none`,children:[(0,g.jsxs)(a,{type:`button`,role:`treeitem`,className:`tree-item tree-folder`,style:y(n),"aria-label":t||e,"aria-level":n,"aria-expanded":o,"aria-selected":i.selected?.kind===`directory`&&i.selected.owner===e&&i.selected.path===t,tabIndex:i.focused===s?0:-1,"data-testid":`directory-row`,"data-owner-id":e,"data-directory-path":t,onFocus:()=>i.onFocus(s),onClick:()=>i.onToggle(e,t),leading:(0,g.jsx)(`span`,{className:`tree-chevron ${o?`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})]}),o&&(0,g.jsx)(S,{owner:e,path:t,level:n+1,context:i})]})}function S({owner:t,path:l,level:u,context:m,members:_=[]}){let{api:b,projectId:S}=c(),C=(0,p.useCallback)(e=>b.tree(t,l,void 0,``,e),[t,l]),w=o(C,!1,e(S,`file-tree`,t,l)),[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 e=new AbortController;j.current=e;try{let n=await b.tree(t,l,w.data.revision,N,e.signal);e.signal.aborted||E({...n,entries:[...M?.entries??[],...n.entries]})}catch(t){e.signal.aborted||A(n(t))}finally{e.signal.aborted||O(!1)}}let F=[...(w.data?.entries??[]).filter(e=>!s(e.path)),...(M?.entries??[]).filter(e=>!s(e.path))],I=m.revealed;if(I?.owner===t&&!s(I.path)&&(!l||I.path.startsWith(l+`/`))){let e=l?I.path.slice(l.length+1):I.path,t=e.indexOf(`/`),n=t<0?I.path:[l,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=>t!==`_project`||!i(e.path)).map(e=>({...e,owner:t})),..._.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(t)?`workspaces`:t,l),"aria-busy":w.loading||D,children:[w.loading&&(0,g.jsx)(`p`,{className:`tree-status`,role:`status`,children:`正在加载…`}),(0,g.jsx)(f,{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)(a,{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===t&&m.selected.path===e.path,tabIndex:m.focused===`file:${v(t,e.path)}`?0:-1,"data-testid":`file-row`,"data-owner-id":t,"data-file-path":e.path,onFocus:()=>m.onFocus(`file:${v(t,e.path)}`),onClick:()=>m.onSelect(t,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
+ import{A as e,M as t,P as n,b as r,c as i,f as a,k as o,l as s,m as c,s as l,tt as u,u as d,w as f}from"./index-DNl0sC00.js";var p=u(),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=t();function _(e){let t=e.target.closest(`[role="treeitem"]`);if(!t)return;let n=[...e.currentTarget.querySelectorAll(`[role="treeitem"]`)],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:l,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 o=i.expanded.has(v(e,t)),s=`folder:${v(e,t)}`;return(0,g.jsxs)(`div`,{role:`none`,children:[(0,g.jsxs)(a,{type:`button`,role:`treeitem`,className:`tree-item tree-folder`,style:y(n),"aria-label":t||e,"aria-level":n,"aria-expanded":o,"aria-selected":i.selected?.kind===`directory`&&i.selected.owner===e&&i.selected.path===t,tabIndex:i.focused===s?0:-1,"data-testid":`directory-row`,"data-owner-id":e,"data-directory-path":t,onFocus:()=>i.onFocus(s),onClick:()=>i.onToggle(e,t),leading:(0,g.jsx)(`span`,{className:`tree-chevron ${o?`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})]}),o&&(0,g.jsx)(S,{owner:e,path:t,level:n+1,context:i})]})}function S({owner:t,path:l,level:u,context:m,members:_=[]}){let{api:b,projectId:S}=c(),C=(0,p.useCallback)(e=>b.tree(t,l,void 0,``,e),[t,l]),w=o(C,!1,e(S,`file-tree`,t,l)),[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 e=new AbortController;j.current=e;try{let n=await b.tree(t,l,w.data.revision,N,e.signal);e.signal.aborted||E({...n,entries:[...M?.entries??[],...n.entries]})}catch(t){e.signal.aborted||A(n(t))}finally{e.signal.aborted||O(!1)}}let F=[...(w.data?.entries??[]).filter(e=>!s(e.path)),...(M?.entries??[]).filter(e=>!s(e.path))],I=m.revealed;if(I?.owner===t&&!s(I.path)&&(!l||I.path.startsWith(l+`/`))){let e=l?I.path.slice(l.length+1):I.path,t=e.indexOf(`/`),n=t<0?I.path:[l,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=>t!==`_project`||!i(e.path)).map(e=>({...e,owner:t})),..._.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(t)?`workspaces`:t,l),"aria-busy":w.loading||D,children:[w.loading&&(0,g.jsx)(`p`,{className:`tree-status`,role:`status`,children:`正在加载…`}),(0,g.jsx)(f,{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)(a,{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===t&&m.selected.path===e.path,tabIndex:m.focused===`file:${v(t,e.path)}`?0:-1,"data-testid":`file-row`,"data-owner-id":t,"data-file-path":e.path,onFocus:()=>m.onFocus(`file:${v(t,e.path)}`),onClick:()=>m.onSelect(t,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{z as e}from"./index-Cp6GL7NO.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};
1
+ import{z as e}from"./index-DNl0sC00.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};