@teammy/server 0.2.21 → 0.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/main.js +212 -24
  2. package/dist/web/assets/Assistant-Dm68Y4gs.js +1 -0
  3. package/dist/web/assets/Computers-BtcIsnDD.css +1 -0
  4. package/dist/web/assets/Computers-mf4P8Wjw.js +13 -0
  5. package/dist/web/assets/{Conversation-C5pZE7z5.js → Conversation-ClLZZ3fG.js} +1 -1
  6. package/dist/web/assets/{Dashboard-yaqwUqGh.js → Dashboard-pokwbwJV.js} +1 -1
  7. package/dist/web/assets/{Dropdown-DXEtBxVr.js → Dropdown-DGFI68Vd.js} +1 -1
  8. package/dist/web/assets/Files-CtxaCO6n.js +1 -0
  9. package/dist/web/assets/{Help-6fa7XqA5.js → Help-B_1p7Xir.js} +43 -20
  10. package/dist/web/assets/{Markdown-nuwEQZ64.js → Markdown-gPLWRWEJ.js} +4 -4
  11. package/dist/web/assets/{MessageComposer-0eprbRl2.js → MessageComposer-BoOgfyPA.js} +1 -1
  12. package/dist/web/assets/ResourceLibrary-Cr_Emgq2.js +6 -0
  13. package/dist/web/assets/{TerminalPane-B0w1stXs.js → TerminalPane-5Gw9ZNxq.js} +2 -2
  14. package/dist/web/assets/WorkspaceTree-DZ6DN_OX.js +1 -0
  15. package/dist/web/assets/{file-links-Bo7XBz3i.js → file-links-CoVqmrXg.js} +1 -1
  16. package/dist/web/assets/index-BZEKT27U.js +10 -0
  17. package/dist/web/assets/task-links-DTqf18C2.js +1 -0
  18. package/dist/web/downloads/teammy-inbox-skill.zip +0 -0
  19. package/dist/web/downloads/teammy-skill.zip +0 -0
  20. package/dist/web/index.html +2 -2
  21. package/dist/web/notification-worker.js +126 -0
  22. package/package.json +1 -1
  23. package/dist/web/assets/Assistant-3mdmSDTD.js +0 -1
  24. package/dist/web/assets/Computers-6l6HpFis.js +0 -13
  25. package/dist/web/assets/Computers-CBnQX-2p.css +0 -1
  26. package/dist/web/assets/Files-1vHzvDD3.js +0 -1
  27. package/dist/web/assets/ResourceLibrary-Cs01blNf.js +0 -6
  28. package/dist/web/assets/WorkspaceTree-DmSApj8i.js +0 -1
  29. package/dist/web/assets/index-Rry2cw7w.js +0 -10
  30. package/dist/web/assets/task-links-BJwIQ3SE.js +0 -1
@@ -0,0 +1 @@
1
+ import{A as e,At as t,Nt as n,O as r,jt as i,z as a}from"./Dropdown-DGFI68Vd.js";import{K as o,q as s}from"./index-BZEKT27U.js";function c(e){return/^(?:\/[^/?#]+)*\/(?:projects\/[^/?#]+\/(?:dashboard|assistant|messages|channels|computers|files|materials|help|memory|sessions|members|settings)(?:[?#]|$)|api\/v1\/projects\/|downloads\/teammy(?:-inbox)?-skill\.zip(?:[?#]|$))/.test(e)}function l(e,t,n){return`/projects/${encodeURIComponent(e)}/files?${new URLSearchParams({owner:t,path:n})}`}function u(e,t){return`/projects/${encodeURIComponent(e)}/dashboard?${new URLSearchParams({task:t})}`}function d(e,t,n,r={}){let i=new URLSearchParams({owner:t,sessionKey:n});return r.revision!==void 0&&i.set(`revision`,String(r.revision)),r.source===`handoff`?i.set(`source`,`handoff`):r.messageId&&i.set(`messageId`,r.messageId),`/projects/${encodeURIComponent(e)}/sessions?${i}`}var f=t();function p(e){if(!e.startsWith(`/`)&&!/^https?:\/\//i.test(e))return;let t=URL.parse(i(e),location.origin);if(!t||t.origin!==location.origin||t.username||t.password)return;let r=n();if(!t.pathname.startsWith(r+`/projects/`))return;let a=/^\/projects\/([a-z][a-z0-9_-]{0,63})\/dashboard$/.exec(t.pathname.slice(r.length)),s=o.shape.id.safeParse(t.searchParams.get(`task`));if(a&&s.success)return{project:a[1],id:s.data}}function m(t,n,i=!1){let o=(0,f.useCallback)(e=>a(`projects/${encodeURIComponent(t)}/tasks/${encodeURIComponent(n)}`,s,{signal:e}),[t,n]);return r(o,i?3e3:!1,e(t,`task`,n))}export{d as a,c as i,m as n,u as o,l as r,p as t};
Binary file
@@ -12,8 +12,8 @@
12
12
  href="./assets/teammy-y-standard-dark-C4LRaRpE.svg"
13
13
  media="(prefers-color-scheme: dark)"
14
14
  />
15
- <script type="module" crossorigin src="./assets/index-Rry2cw7w.js"></script>
16
- <link rel="modulepreload" crossorigin href="./assets/Dropdown-DXEtBxVr.js">
15
+ <script type="module" crossorigin src="./assets/index-BZEKT27U.js"></script>
16
+ <link rel="modulepreload" crossorigin href="./assets/Dropdown-DGFI68Vd.js">
17
17
  <link rel="stylesheet" crossorigin href="./assets/Dropdown-ktgqMqAD.css">
18
18
  <link rel="stylesheet" crossorigin href="./assets/index-CeKzFsxV.css">
19
19
  </head>
@@ -0,0 +1,126 @@
1
+ // Display and click handling only: no fetch interception, offline cache or Web Push.
2
+ self.addEventListener('install', () => self.skipWaiting());
3
+ self.addEventListener('activate', (event) => event.waitUntil(self.clients.claim()));
4
+
5
+ async function pages() {
6
+ const clients = await self.clients.matchAll({ type: 'window', includeUncontrolled: true });
7
+ return Promise.all(
8
+ clients
9
+ .filter((client) => client.url.startsWith(self.registration.scope))
10
+ .map(async (client) => {
11
+ const state = await new Promise((resolve) => {
12
+ const channel = new MessageChannel();
13
+ const timer = setTimeout(() => {
14
+ channel.port1.close();
15
+ resolve(null);
16
+ }, 500);
17
+ channel.port1.onmessage = ({ data }) => {
18
+ clearTimeout(timer);
19
+ channel.port1.close();
20
+ resolve(data);
21
+ };
22
+ client.postMessage({ type: 'teammy:notification-status' }, [channel.port2]);
23
+ });
24
+ return { client, state };
25
+ }),
26
+ );
27
+ }
28
+ function sameSession(selection, item) {
29
+ return selection?.project === item.project && selection?.session === item.session;
30
+ }
31
+ const labels = {
32
+ completion: '工作已完成',
33
+ question: '有问题等待回答',
34
+ approval: '权限申请等待审批',
35
+ plan: '计划等待确认',
36
+ };
37
+ async function sync({ member, items, notify, icon }) {
38
+ const open = (await self.registration.getNotifications()).filter(
39
+ (notification) => notification.data?.member === member,
40
+ );
41
+ const currentPages = items.length ? await pages() : [];
42
+ const groups = new Map();
43
+ for (const item of items) {
44
+ const tag = JSON.stringify([self.registration.scope, member, item.project, item.session]);
45
+ groups.set(tag, [...(groups.get(tag) ?? []), item]);
46
+ }
47
+ const retained = new Set();
48
+ for (const [tag, group] of groups) {
49
+ const questions = group.filter((item) => item.kind !== 'completion');
50
+ const candidates = questions.length ? questions : group;
51
+ const item = candidates.at(-1);
52
+ if (
53
+ currentPages.some(
54
+ ({ state }) =>
55
+ state?.member === member && state.focused && sameSession(state.selection, item),
56
+ )
57
+ )
58
+ continue;
59
+ const existing = open.find((notification) => notification.tag === tag);
60
+ const newEvent = candidates.some((item) => notify.includes(item.id));
61
+ if (!newEvent && !existing) continue;
62
+ // Clearing a resolved question must not resurrect an older completion notice.
63
+ if (!newEvent && !candidates.some((item) => existing.data.ids.includes(item.id))) continue;
64
+ const title = `${item.title} · ${item.projectName}`;
65
+ const body =
66
+ questions.length > 1
67
+ ? `有 ${questions.length} 个问题等待确认`
68
+ : labels[item.kind] + (item.preview ? `。${item.preview}` : '。');
69
+ retained.add(tag);
70
+ const ids = candidates.map((item) => item.id);
71
+ if (
72
+ !newEvent &&
73
+ existing.title === title &&
74
+ existing.body === body &&
75
+ JSON.stringify(existing.data.ids) === JSON.stringify(ids)
76
+ )
77
+ continue;
78
+ await self.registration.showNotification(title, {
79
+ body,
80
+ tag,
81
+ icon,
82
+ renotify: newEvent,
83
+ silent: !newEvent,
84
+ data: { member, item, ids },
85
+ });
86
+ }
87
+ for (const notification of open) if (!retained.has(notification.tag)) notification.close();
88
+ }
89
+ let queue = Promise.resolve();
90
+ self.addEventListener('message', (event) => {
91
+ if (
92
+ event.data?.type !== 'teammy:notifications' ||
93
+ !event.source?.url?.startsWith(self.registration.scope)
94
+ )
95
+ return;
96
+ queue = queue.catch(() => {}).then(() => sync(event.data));
97
+ event.waitUntil(
98
+ queue.then(
99
+ () => event.ports[0]?.postMessage({ ok: true }),
100
+ () => event.ports[0]?.postMessage({ error: true }),
101
+ ),
102
+ );
103
+ });
104
+ self.addEventListener('notificationclick', (event) => {
105
+ event.notification.close();
106
+ event.waitUntil(
107
+ (async () => {
108
+ const { member, item } = event.notification.data;
109
+ const target = new URL(item.href, self.registration.scope);
110
+ if (!target.href.startsWith(self.registration.scope)) return;
111
+ const existing = (await pages()).find(
112
+ ({ state }) => state?.member === member && sameSession(state.selection, item),
113
+ );
114
+ if (existing) {
115
+ try {
116
+ await existing.client.focus();
117
+ existing.client.postMessage({ type: 'teammy:notification-open', member, item });
118
+ return;
119
+ } catch {
120
+ // The matching tab may have closed after replying to the status query.
121
+ }
122
+ }
123
+ await self.clients.openWindow(target.href);
124
+ })(),
125
+ );
126
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teammy/server",
3
- "version": "0.2.21",
3
+ "version": "0.2.22",
4
4
  "description": "The centralized Teammy collaboration hub server.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +0,0 @@
1
- import{A as e,At as t,C as n,D as r,F as i,I as a,M as ee,St as o,_t as s,b as c,c as l,d as te,j as u,k as d,kt as f,l as p,mt as m,pt as h,u as ne,v as re,vt as g,wt as ie,x as ae,yt as _}from"./Dropdown-DXEtBxVr.js";import{A as oe,B as se,D as v,E as ce,L as y,M as le,O as ue,P as de,i as fe,j as b,k as pe}from"./index-Rry2cw7w.js";import{t as me}from"./Markdown-nuwEQZ64.js";import{i as he,n as ge,r as _e,t as ve}from"./Conversation-C5pZE7z5.js";import{t as ye}from"./MessageComposer-0eprbRl2.js";var x=f(),S=u(),be=_({topics:h(_({id:o(),title:o(),summary:o(),author:o(),replies:g(),unread:m(),createdAt:o(),updatedAt:o(),delivery:_({available:m(),connected:m(),state:o(),error:o().nullable()})}))}),xe=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),C=e=>e.replace(/[#*_`>]/g,``).replace(/\s+/g,` `).trim();function w({me:u,mode:f=`messages`}){let{projectId:h,request:g}=se(),w=e(),Ce=d(h,u,`${f}-selection`),T=d(h,u,`${f}-drafts`),we=(0,x.useCallback)(e=>g(`agents/outbox`,oe,{signal:e}),[g]),E=r(we,3e3,d(h,u,`outbox`)),Te=(0,x.useCallback)(async e=>f===`messages`?g(`agents/chats`,ce,{signal:e}):{chats:(await g(`channels/topics`,be,{signal:e})).topics.map(e=>({...e,kind:`matter`,state:null}))},[g,f]),D=r(Te,3e3,d(h,u,f,`chats`)),[O,Ee]=(0,x.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`chat`);return t?`chat:${t}`:e.get(`message`)??w?.get(Ce)??``}),k=O.startsWith(`chat:`)?O.slice(5):``,A=!O||!!k,[j,M]=(0,x.useState)(()=>w?.get(d(h,u,`chat`,k))),N=j?.id===k?j:w?.get(d(h,u,`chat`,k)),P=D.data?.chats.find(e=>e.id===k),F=P&&`delivery`in P?P.delivery:void 0,[De,I]=(0,x.useState)(),[L,R]=(0,x.useState)(()=>w?.get(T)??{}),Oe=L[O]??``,ke=e=>R(t=>({...t,[O]:e})),[z,B]=(0,x.useState)(!1),[V,Ae]=(0,x.useState)(!1),[je,Me]=(0,x.useState)(!1),[Ne,H]=(0,x.useState)(!1),[U,Pe]=(0,x.useState)(``),[Fe,Ie]=(0,x.useState)(``),Le=(0,x.useRef)(a()),W=n(),[Re,G]=(0,x.useState)(``),K=(0,x.useRef)(new Map),ze=(0,x.useRef)(null),q=(0,x.useRef)(!0),J=(0,x.useRef)(O);J.current=O,(0,x.useEffect)(()=>{j&&w?.set(d(h,u,`chat`,j.id),j)},[w,h,u,j]),(0,x.useEffect)(()=>{w?.set(T,L)},[w,T,L]);function Y(e){J.current=e,Ee(e),w?.set(Ce,e);let t=new URL(location.href);e.startsWith(`chat:`)?t.searchParams.set(`chat`,e.slice(5)):t.searchParams.delete(`chat`),e&&!e.startsWith(`chat:`)&&e!==`debug`?t.searchParams.set(`message`,e):t.searchParams.delete(`message`),history.replaceState(history.state,``,t)}(0,x.useEffect)(()=>{!O&&D.data?.chats.length&&Y(`chat:${D.data.chats[0].id}`)},[O,D.data]);let X=(E.data?.messages??[]).filter(e=>f===`messages`&&e.box===`debug`).reverse(),Z=E.data?.messages.find(e=>e.id===(O===`debug`?De:O));(0,x.useEffect)(()=>{O!==`debug`&&Z?.conversationId&&Y(`chat:${Z.conversationId}`)},[O,Z?.conversationId]);let Q=X.filter(e=>!e.readAt).map(e=>e.id).join(`,`);(0,x.useEffect)(()=>{Z&&!Z.readAt&&O!==`debug`&&g(`agents/outbox/${Z.id}/read`,b,{method:`POST`}).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>W(i(e)))},[Z?.id,Z?.readAt,O,g,E.reload]),(0,x.useEffect)(()=>{O===`debug`&&Q&&Promise.all(Q.split(`,`).map(e=>g(`agents/outbox/${e}/read`,b,{method:`POST`}))).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}).catch(e=>W(i(e)))},[O,Q,g,E.reload]),(0,x.useEffect)(()=>{if(G(``),!k)return;let e=!0,n=-1,r=!1,a=new AbortController,s=i=>{!e||i.id!==k||i.cursor<n||(n=i.cursor,r=!0,i.redirect?Y(`chat:${i.redirect}`):i.entry===`channel`&&f!==`channels`?location.replace(t(`/projects/${h}/channels?chat=${i.id}`)):(M(i),G(``)))};g(`agents/chats/${k}`,v,{signal:a.signal}).then(s).catch(t=>{e&&!a.signal.aborted&&(t instanceof ee&&[401,403,404].includes(t.status)&&(w?.delete(d(h,u,`chat`,k)),M(e=>e?.id===k?void 0:e)),r||G(i(t)))});let c=t=>{let r=Number(t.lastEventId);return!e||!Number.isSafeInteger(r)||r<=n?!1:(n=r,!0)},l=new EventSource(t(`/api/v1/projects/${encodeURIComponent(h)}/agents/chats/${encodeURIComponent(k)}/events`));l.addEventListener(`snapshot`,t=>{if(e)try{s(v.parse(JSON.parse(t.data)))}catch(e){G(i(e))}}),l.onerror=()=>{e&&G(`对话连接中断,正在重新连接…`)},l.addEventListener(`context`,e=>{if(!c(e))return;let t=v.pick({kind:!0,title:!0,status:!0,visibility:!0,participants:!0,pending:!0,hold:!0,redirect:!0}).parse(JSON.parse(e.data));t.redirect?Y(`chat:${t.redirect}`):M(e=>e?.id===k?{...e,...t,cursor:n}:e)}),l.addEventListener(`message`,e=>{if(!c(e))return;let t=ue.parse(JSON.parse(e.data));M(n=>n?.id===k?{...n,readCursor:Math.max(n.readCursor,t.seq),cursor:Math.max(n.cursor,Number(e.lastEventId)||0),messages:[...n.messages.filter(e=>e.id!==t.id),t].sort((e,t)=>e.seq-t.seq)}:n)}),l.addEventListener(`message_removed`,e=>{if(!c(e))return;let{id:t}=_({id:o()}).parse(JSON.parse(e.data));M(e=>e?.id===k?{...e,cursor:n,messages:e.messages.filter(e=>e.id!==t)}:e)}),l.addEventListener(`run`,e=>{if(!c(e))return;let t=pe.parse(JSON.parse(e.data));M(n=>n?.id===k?{...n,cursor:Math.max(n.cursor,Number(e.lastEventId)||0),runs:n.runs.some(e=>e.id===t.id)?n.runs:[...n.runs,t]}:n)});for(let e of[`delta`,`reset`,`state`])l.addEventListener(e,t=>{if(!c(t))return;let n=JSON.parse(t.data);M(r=>r?.id===k?{...r,cursor:Math.max(r.cursor,Number(t.lastEventId)||0),messages:r.messages.map(t=>t.runId!==n.id||t.role!==`assistant`?t:{...t,body:e===`delta`?t.body+(n.text??``):e===`reset`?``:n.answer??t.body,state:n.state??t.state}),runs:r.runs.map(t=>t.id===n.id?{...t,answer:e===`delta`?t.answer+(n.text??``):e===`reset`?``:n.answer??t.answer,state:n.state??t.state,error:n.error===void 0?t.error:n.error}:t)}:r)});return()=>{e=!1,a.abort(),l.close()}},[h,k,u,g,w]),(0,x.useEffect)(()=>{if(!N||N.id!==k)return;let e=()=>{document.visibilityState===`visible`&&g(`agents/chats/${k}/read`,_({ok:m()}),{method:`POST`,body:{cursor:N.readCursor}}).then(()=>{D.reload(),window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>W(i(e)))},t=setTimeout(e,300);return document.addEventListener(`visibilitychange`,e),()=>{clearTimeout(t),document.removeEventListener(`visibilitychange`,e)}},[k,N?.readCursor,N?.kind,g]),(0,x.useEffect)(()=>{q.current&&ze.current?.scrollIntoView({block:`end`})},[O,j?.messages,Z?.recipients,X.length]);function Be(){window.dispatchEvent(new Event(`teammy:outbox`)),E.reload()}async function $(e){if(q.current=!0,Y(e),W(``),I(void 0),e.startsWith(`chat:`)||e===`debug`)return;let t=E.data?.messages.find(t=>t.id===e)?.conversationId;if(t)Y(`chat:${t}`);else try{await g(`agents/outbox/${e}/read`,b,{method:`POST`}),Be()}catch(e){W(i(e))}}async function Ve(){if(!V){Ae(!0),W(``);try{let e=await g(`agents/chats`,v,{method:`POST`});M(e),await $(`chat:${e.id}`),D.reload()}catch(e){W(i(e))}finally{Ae(!1)}}}async function He(e){e.preventDefault();let t=Oe.trim();if(!t||z||V)return;B(!0),W(``);let n=K.current.get(O);n&&n.text===t||(n={text:t,id:a()},K.current.set(O,n));try{if(A){let e=n.target??k;if(!e){let r=await g(`agents/chats`,v,{method:`POST`});e=r.id,n.target=e,K.current.set(`chat:${e}`,n),R(n=>({...n,[`chat:${e}`]:t})),J.current===O&&(M(r),Y(`chat:${e}`))}let r=await g(`agents/chats/${e}`,pe.extend({conversationId:o().optional()}),{method:`POST`,body:{text:t,requestId:n.id}});r.conversationId&&r.conversationId!==e&&(J.current===O||J.current===`chat:${e}`)&&Y(`chat:${r.conversationId}`),M(t=>t?.id===e?{...t,runs:t.runs.some(e=>e.id===r.id)?t.runs:[...t.runs,r]}:t),D.reload()}else{let e=await g(`agents/outbox/${Z.id}/reply`,_({conversationId:o()}),{method:`POST`,body:{body:t,requestId:n.id}});Be(),J.current===O&&Y(`chat:${e.conversationId}`),D.reload(),I(void 0)}K.current.delete(O),n.target&&K.current.delete(`chat:${n.target}`),R(e=>({...e,[O]:``,...n.target?{[`chat:${n.target}`]:``}:{}}))}catch(e){W(i(e))}finally{B(!1)}}let Ue=f===`channels`?_e:ve,We=A&&!N?.closed&&(f!==`channels`||!!k)||!!Z&&!Z.archivedAt,Ge=A&&!N&&(!!k||!D.data);return(0,S.jsxs)(ge,{className:f===`channels`?`channel-layout`:``,testId:`assistant-page`,label:A?`Tim对话`:`消息内容`,navigation:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(de,{title:f===`channels`?`频道`:`对话`,children:(0,S.jsxs)(`div`,{className:`assistant-list-actions`,children:[(0,S.jsx)(p,{className:`assistant-new-chat`,icon:`clear`,label:`清除未读`,disabled:je,onClick:()=>{Me(!0),W(``),g(`communication/read`,_({ok:s(!0)}),{method:`POST`,body:{scope:f}}).then(async()=>{window.dispatchEvent(new Event(`teammy:outbox`)),await Promise.all([D.reload(),E.reload()])}).catch(e=>W(i(e))).finally(()=>Me(!1))}}),(0,S.jsx)(p,{className:`assistant-new-chat`,icon:`plus`,label:f===`channels`?`发表话题`:`新建对话`,disabled:V,onClick:()=>f===`channels`?H(!0):void Ve(),"data-testid":`assistant-launcher`})]})}),(0,S.jsxs)(`div`,{className:`assistant-message-scroll`,children:[D.loading&&!D.data&&(0,S.jsx)(`p`,{className:`assistant-list-status`,role:`status`,children:`加载中…`}),D.data?.chats.map(e=>(0,S.jsxs)(`button`,{type:`button`,"data-testid":`assistant-chat-${e.id}`,className:`assistant-message-item assistant-chat-item ${k===e.id?`selected`:``}`,"aria-pressed":k===e.id,onClick:()=>void $(`chat:${e.id}`),children:[(0,S.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,S.jsx)(y,{selected:k===e.id,children:(0,S.jsx)(`strong`,{children:e.title})}),f===`channels`&&`summary`in e&&(0,S.jsx)(`span`,{className:`topic-preview`,children:C(String(e.summary)).slice(0,140)}),(0,S.jsxs)(`time`,{dateTime:e.updatedAt,children:[new Date(e.updatedAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,xe(e.updatedAt)]})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${e.unread||f!==`channels`&&(e.state===`running`||e.state===`queued`)?`unread`:``}`})]},e.id)),!!X.length&&(0,S.jsxs)(`button`,{type:`button`,"data-testid":`debug-outbox`,className:`assistant-message-item ${O===`debug`?`selected`:``}`,onClick:()=>void $(`debug`),children:[(0,S.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,S.jsx)(y,{selected:O===`debug`,children:(0,S.jsx)(`strong`,{children:`运行提醒`})}),(0,S.jsx)(`span`,{children:C(X.at(-1).body)})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${Q?`unread`:``}`})]}),E.data?.messages.filter(e=>f===`messages`&&e.box!==`debug`&&!e.conversationId).sort((e,t)=>Number(!!e.archivedAt)-Number(!!t.archivedAt)).map(e=>(0,S.jsxs)(`button`,{type:`button`,"data-testid":`outbox-${e.id}`,className:`assistant-message-item ${e.archivedAt?`archived`:``} ${O===e.id?`selected`:``}`,onClick:()=>void $(e.id),children:[(0,S.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,S.jsx)(y,{selected:O===e.id,children:(0,S.jsx)(`strong`,{children:C(e.body)})}),(0,S.jsxs)(`time`,{dateTime:e.createdAt,children:[new Date(e.createdAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,xe(e.createdAt)]})]}),(0,S.jsx)(`span`,{className:`assistant-message-dot ${e.readAt?``:`unread`}`})]},e.id))]}),(0,S.jsx)(ae,{resource:E}),(0,S.jsx)(ae,{resource:D})]}),children:[Ne&&(0,S.jsx)(te,{id:`new-topic`,title:`发表话题`,onClose:()=>H(!1),children:(0,S.jsx)(ye,{inset:!0,plain:!0,value:Fe,onChange:Ie,label:`正文`,placeholder:`开始一个话题…`,sendLabel:`发表话题`,sendDisabled:z||!U.trim(),heading:(0,S.jsx)(`input`,{className:`topic-title`,"aria-label":`标题`,placeholder:`标题`,required:!0,value:U,onChange:e=>Pe(e.target.value)}),onSubmit:e=>{e.preventDefault(),B(!0),W(``),g(`channels/topics`,v,{method:`POST`,body:{id:Le.current,title:U,body:Fe}}).then(e=>{M(e),Y(`chat:${e.id}`),H(!1),Pe(``),Ie(``),Le.current=a(),D.reload()}).catch(e=>W(i(e))).finally(()=>B(!1))}})}),(0,S.jsx)(le,{title:(0,S.jsx)(`h2`,{children:A?P?.title??N?.title??(k?`无标题`:`Tim`):O===`debug`?`运行提醒`:`项目消息`}),actions:(0,S.jsxs)(S.Fragment,{children:[f===`channels`&&k&&(0,S.jsx)(fe,{conversation:k}),f!==`channels`&&N?.kind===`matter`&&(0,S.jsxs)(`span`,{className:`assistant-participants`,title:N.participants?.join(`、`),children:[N.visibility===`project`?`项目共享 · `:``,N.participants?.join(`、`)]}),f===`channels`&&F?.available&&(F.state===`web`||F.state===`cancelled`||!F.connected)&&(0,S.jsx)(p,{icon:`send`,label:`发布到企业微信频道`,disabled:z,onClick:()=>{B(!0),g(`channels/topics/${k}/publish`,ie(),{method:`POST`}).then(()=>D.reload()).catch(e=>W(i(e))).finally(()=>B(!1))}})]})}),f===`channels`&&(0,S.jsx)(re,{children:F?.error}),f!==`channels`&&N?.kind===`matter`&&(N.hold||N.pending||N.status===`completed`)&&(0,S.jsx)(`div`,{className:`assistant-matter-state`,role:`status`,children:N.hold?`${N.hold.scope===`all`?`已暂停`:`暂缓修改`} · ${N.hold.reason}`:N.pending?`待确认 · ${N.pending.members.join(`、`)}:${N.pending.question}`:`已完成`}),(0,S.jsxs)(he,{"data-testid":`assistant-transcript`,onScroll:e=>{let t=e.currentTarget;q.current=t.scrollHeight-t.scrollTop-t.clientHeight<100},children:[A?Ge?(0,S.jsxs)(`div`,{className:`assistant-empty`,"data-testid":`assistant-loading`,children:[(0,S.jsx)(ne,{}),(0,S.jsx)(`p`,{role:`status`,children:Re||(D.error?`暂时无法加载对话`:`加载中…`)})]}):N?.messages.length?N.messages.filter(e=>e.body||[`queued`,`running`,`failed`].includes(e.state)).map(e=>(0,S.jsx)(`div`,{className:`assistant-turn`,children:(0,S.jsxs)(Ue,{mine:e.role===`user`&&e.author===u,author:`${e.role===`assistant`?`Tim`:e.author}${e.source===`wecom`?` · 企业微信`:``}`,time:e.createdAt,children:[e.body&&(0,S.jsx)(`div`,{className:`markdown`,children:(0,S.jsx)(me,{children:e.body})}),e.role===`assistant`&&[`queued`,`running`].includes(e.state)&&(0,S.jsxs)(`span`,{className:`assistant-typing`,"aria-label":`正在回答`,children:[(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{})]}),e.state===`failed`&&(0,S.jsx)(re,{children:N.runs.find(t=>t.id===e.runId)?.error||`本次回答未完成。`})]})},e.id)):(0,S.jsxs)(`div`,{className:`assistant-empty`,children:[(0,S.jsx)(ne,{}),(0,S.jsx)(`p`,{children:`有什么项目问题想聊聊?`})]}):!E.data&&E.loading?(0,S.jsx)(`div`,{className:`assistant-empty`,children:(0,S.jsx)(`p`,{role:`status`,children:`加载中…`})}):O===`debug`?X.map(e=>(0,S.jsx)(Se,{item:e,onReply:e.archivedAt?void 0:()=>{I(e.id),ke(``),W(``)}},e.id)):Z&&(0,S.jsx)(Se,{item:Z}),(0,S.jsx)(`div`,{ref:ze})]}),(0,S.jsx)(c,{message:A&&N?Re:void 0}),We?(0,S.jsx)(ye,{value:Oe,onChange:ke,onSubmit:e=>void He(e),disabled:V,sendDisabled:z||Ge,label:A?`向Tim提问`:`回复消息`}):O!==`debug`&&Z&&(0,S.jsxs)(`div`,{className:`assistant-archived`,children:[(0,S.jsx)(l,{name:`archive`}),`已归档`]})]})}function Se({item:e,onReply:t}){return(0,S.jsx)(`div`,{"data-testid":`outbox-thread-${e.id}`,children:(0,S.jsxs)(ve,{author:e.box===`debug`?`运行提醒`:`Tim`,time:e.createdAt,children:[(0,S.jsx)(`div`,{className:`markdown`,children:(0,S.jsx)(me,{children:e.body})}),t&&(0,S.jsx)(`button`,{type:`button`,className:`assistant-debug-reply`,onClick:t,children:`回复`})]})})}export{w as Assistant};
@@ -1,13 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./TerminalPane-B0w1stXs.js","./Dropdown-DXEtBxVr.js","./Dropdown-ktgqMqAD.css","./index-Rry2cw7w.js","./index-CeKzFsxV.css","./Markdown-nuwEQZ64.js","./task-links-BJwIQ3SE.js","./TerminalPane-BrSy-0jI.css"])))=>i.map(i=>d[i]);
2
- import{A as e,At as t,C as n,D as r,F as i,I as a,M as o,St as s,_t as c,b as l,c as u,d,ft as f,ht as p,it as m,j as h,k as g,kt as _,l as v,mt as y,p as b,pt as x,t as S,v as C,vt as w,w as T,wt as E,x as D,yt as O}from"./Dropdown-DXEtBxVr.js";import{B as k,I as A,M as ee,P as te,S as j,T as ne,V as re,_ as ie,a as ae,b as oe,c as se,d as ce,f as le,g as ue,h as de,l as fe,m as pe,o as me,p as he,s as ge,t as _e,u as ve,v as ye,w as be,x as M,y as xe,z as Se}from"./index-Rry2cw7w.js";import{a as N,i as Ce,t as P}from"./Markdown-nuwEQZ64.js";import{a as we,i as Te,n as Ee,t as De}from"./Conversation-C5pZE7z5.js";import{n as Oe,t as ke}from"./MessageComposer-0eprbRl2.js";import{l as Ae,r as je}from"./WorkspaceTree-DmSApj8i.js";var F=_(),I=h();function Me({title:e,busy:t,onSave:n}){let[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(e);return r?(0,I.jsx)(`form`,{className:`session-title-form`,onSubmit:t=>{t.preventDefault(),a.trim()&&a.trim()!==e&&n(a.trim()),i(!1)},children:(0,I.jsx)(`input`,{autoFocus:!0,"aria-label":`会话标题`,value:a,disabled:t,onChange:e=>o(e.target.value),onBlur:()=>i(!1),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),i(!1))}})}):(0,I.jsx)(`h2`,{children:(0,I.jsx)(`button`,{type:`button`,className:`session-rename`,title:`重命名会话`,"aria-label":`重命名会话:${e}`,onClick:()=>{o(e),i(!0)},children:e})})}var Ne=O({id:s().uuid(),directory:s(),title:s(),cwd:s(),createdAt:s(),state:f([`running`,`exited`]),exitCode:w().nullable()}),L={id:s().uuid(),directory:s().min(1).max(200)},Pe={cols:w().int().min(2).max(500),rows:w().int().min(1).max(300)};p(`type`,[O({type:c(`create`),...L,...Pe,title:s().trim().min(1).max(160)}),O({type:c(`attach`),...L}),O({type:c(`detach`),...L}),O({type:c(`input`),...L,data:s().max(65536)}),O({type:c(`resize`),...L,...Pe}),O({type:c(`rename`),...L,title:s().trim().min(1).max(160)}),O({type:c(`close`),...L})]);var Fe=p(`type`,[O({type:c(`size`),id:s(),...Pe}),O({type:c(`inventory`),directories:x(s()),terminals:x(Ne)}),O({type:c(`snapshot`),id:s(),data:s(),cols:w(),rows:w(),seq:w()}),O({type:c(`output`),id:s(),data:s(),seq:w()}),O({type:c(`result`),id:s(),operation:s(),error:s().optional()})]);function Ie(e,n){let r=(0,F.useRef)(null),i=(0,F.useRef)(new Set),[a,o]=(0,F.useState)(!1),[s,c]=(0,F.useState)([]),[l,u]=(0,F.useState)([]);(0,F.useEffect)(()=>{if(!n)return;let a=!1,s,l,d=()=>{let n=new URL(t(`/api/v1/projects/${encodeURIComponent(e)}/web/terminals`),location.origin);n.protocol=n.protocol===`https:`?`wss:`:`ws:`,l=new WebSocket(n),r.current=l,l.onmessage=e=>{let t=Fe.safeParse(JSON.parse(e.data));if(!t.success||a)return;let n=t.data;n.type===`inventory`&&(u(n.terminals),c(n.directories),o(!0));for(let e of i.current)e(n)},l.onclose=()=>{o(!1),c([]),a||(s=setTimeout(d,2e3))}};return d(),()=>{a=!0,clearTimeout(s),l?.close(),r.current=null}},[e,n]);let d=(0,F.useCallback)(e=>(i.current.add(e),()=>{i.current.delete(e)}),[]),f=(0,F.useCallback)(e=>{if(r.current?.readyState!==WebSocket.OPEN)throw Error(`终端连接已断开,输入未发送。`);r.current.send(JSON.stringify(e))},[]);return{connected:a,directories:s,terminals:l,subscribe:d,send:f,request:(0,F.useCallback)(e=>new Promise((t,n)=>{let r=setTimeout(()=>{i(),n(Error(`暂未收到结果,请检查连接;操作不会自动重发。`))},15e3),i=d(a=>{a.type===`result`&&a.id===e.id&&a.operation===e.type&&(clearTimeout(r),i(),a.error?n(Error(a.error)):t())});try{f(e)}catch(e){clearTimeout(r),i(),n(e)}}),[f,d])}}O({provider:le,cursor:s().optional(),session:de.optional()});var Le=O({id:de,title:s(),cwd:s(),updatedAt:s().datetime().nullable(),active:y().default(!1)}),R=O({sessions:x(Le),nextCursor:s().nullable()}),z=O({command:ue,history:R.nullable()});function Re(e,t=Date.now()){if(!e)return``;let n=new Date(e),r=Math.max(0,t-n.getTime());return Number.isFinite(r)?r<36e5?`${Math.floor(r/6e4)}min`:r<864e5?`${Math.floor(r/36e5)}h`:r<=6048e5?`${Math.floor(r/864e5)}day`:`${String(n.getFullYear()).slice(-2)}/${String(n.getMonth()+1).padStart(2,`0`)}/${String(n.getDate()).padStart(2,`0`)}`:``}function ze({id:e,label:t,value:n,onChange:r,options:i,placeholder:a,loading:o=!1,disabled:s=!1,empty:c=`没有匹配的选项。`,footer:l}){let[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(),g=(0,F.useRef)(null),_=(0,F.useRef)(null),y=(0,F.useRef)(null),b=i.find(e=>e.value===n),x=b?``:n.trim().toLocaleLowerCase(),S=i.filter(e=>`${e.label} ${e.value}`.toLocaleLowerCase().includes(x)),C=S.filter(e=>!e.disabled),w=S.findIndex(e=>e.value===f);(0,F.useEffect)(()=>p(``),[n]),(0,F.useEffect)(()=>{if(!u)return;let e=e=>{g.current?.contains(e.target)||d(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[u]),(0,F.useLayoutEffect)(()=>{if(!u)return;let e=()=>{let e=_.current?.getBoundingClientRect();if(!e)return;let t=innerHeight-e.bottom-16,n=e.top-16,r=t<220&&n>t;h({left:e.left,width:e.width,top:r?void 0:e.bottom+6,bottom:r?innerHeight-e.top+6:void 0,maxHeight:Math.min(320,r?n:t)})};return e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[u]),(0,F.useEffect)(()=>{u&&w>=0&&document.getElementById(`${e}-option-${w}`)?.scrollIntoView({block:`nearest`})},[u,w,e]);function T(e){e.disabled||(r(e.value),d(!1),y.current?.focus())}return(0,I.jsxs)(`div`,{className:`combobox`,ref:g,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||d(!1)},onKeyDown:e=>{e.key===`Escape`&&u&&(e.preventDefault(),e.stopPropagation(),d(!1),y.current?.focus())},children:[(0,I.jsxs)(`div`,{className:`combobox-field`,ref:_,children:[(0,I.jsx)(`input`,{id:e,ref:y,role:`combobox`,"aria-label":t,"aria-autocomplete":`list`,"aria-expanded":u,"aria-controls":`${e}-list`,"aria-activedescendant":u&&w>=0?`${e}-option-${w}`:void 0,autoComplete:`off`,disabled:s,value:b?.label??n,title:b?.value,placeholder:a,onClick:()=>d(!0),onChange:e=>{r(e.target.value),d(!0)},onKeyDown:e=>{if([`ArrowDown`,`ArrowUp`].includes(e.key)){e.preventDefault(),d(!0);let t=C.findIndex(e=>e.value===f),n=t<0?e.key===`ArrowDown`?0:C.length-1:(t+(e.key===`ArrowDown`?1:-1)+C.length)%C.length;p(C[n]?.value??``)}else e.key===`Enter`&&u&&w>=0?(e.preventDefault(),T(S[w])):e.key===`Tab`&&d(!1)}}),(0,I.jsx)(v,{icon:u?`chevronUp`:`chevronDown`,label:`${u?`收起`:`展开`}${t}`,disabled:s,"aria-expanded":u,"aria-controls":`${e}-list`,onClick:()=>{d(!u),y.current?.focus()}})]}),u&&(0,I.jsxs)(`div`,{className:`combobox-popup`,style:m,children:[(0,I.jsxs)(`div`,{id:`${e}-list`,role:`listbox`,"aria-label":t,"aria-busy":o,children:[S.map((t,r)=>(0,I.jsxs)(`button`,{id:`${e}-option-${r}`,type:`button`,role:`option`,"aria-selected":t.value===n,disabled:t.disabled,tabIndex:-1,className:`combobox-option ${t.value===f?`active`:``}`,title:`${t.label} · ${t.value}`,onMouseDown:e=>e.preventDefault(),onClick:()=>T(t),children:[(0,I.jsxs)(`span`,{className:`combobox-option-copy`,children:[(0,I.jsx)(`span`,{children:t.label}),t.description&&(0,I.jsx)(`small`,{children:t.description})]}),t.detail&&(0,I.jsx)(`span`,{className:`combobox-option-detail`,children:t.detail})]},t.value)),o&&(0,I.jsx)(`p`,{className:`combobox-message`,role:`status`,children:`正在读取…`}),!o&&!S.length&&(0,I.jsx)(`p`,{className:`combobox-message`,children:c})]}),l&&(0,I.jsx)(`div`,{className:`combobox-footer`,children:l})]})]})}function Be({directory:e,provider:t,providers:r,sessions:o,request:s,onClose:c,onImport:l}){let[u,f]=(0,F.useState)(t),[p,m]=(0,F.useState)([]),[h,g]=(0,F.useState)(null),[_,y]=(0,F.useState)(``),[b,x]=(0,F.useState)(null),S=n(),C=(0,F.useRef)(null),w=e=>o.find(t=>!t.hidden&&t.provider===u&&(t.nativeSession??t.resumeSession)===e);async function T(t,n){let r=a();for(await s(`web/local-agents/${e}/history`,ue,{method:`POST`,signal:n,body:{id:r,argument:JSON.stringify({provider:u,...t})}});!n.aborted;){let t=await s(`web/local-agents/${e}/history/${r}`,z,{signal:n});if(t.command.state===`succeeded`&&t.history)return{...t.history,id:r};if(![`queued`,`running`].includes(t.command.state))throw Error(t.command.error||`读取历史会话失败。`);await new Promise(e=>{let t=()=>{clearTimeout(r),n.removeEventListener(`abort`,t),e()},r=setTimeout(t,1e3);n.addEventListener(`abort`,t,{once:!0})})}throw new DOMException(`Aborted`,`AbortError`)}async function E(t,n,r){let i=w(t.id)??await s(`web/local-agents/${e}/sessions`,pe,{method:`POST`,signal:r,body:{id:a(),title:t.title,provider:u,resumeSession:t.id,historyRequest:n}});r.aborted||l(i)}async function D(e,t){C.current?.abort();let n=new AbortController;C.current=n,x(e),S(``);try{await t(n.signal)}catch(e){n.signal.aborted||S(i(e))}finally{n.signal.aborted||x(null)}}let O=e=>D(`list`,async t=>{let n=await T(e?{cursor:e}:{},t);t.aborted||(m(t=>{let r=[...e?t:[],...n.sessions.map(e=>({...e,requestId:n.id}))];return[...new Map(r.map(e=>[e.id,e])).values()].sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``))}),g(n.nextCursor))});(0,F.useEffect)(()=>(m([]),g(null),y(``),O(),()=>C.current?.abort()),[u,e,s]);let k=p.find(e=>e.id===_),A=b===`import`;return(0,I.jsx)(d,{id:`computer-import-session`,title:`导入历史会话`,onClose:c,children:(0,I.jsxs)(`form`,{className:`native-history`,onSubmit:e=>{e.preventDefault(),D(`import`,async e=>{let t=_.trim(),n=w(t);if(n)return l(n);if(k)return E(k,k.requestId,e);let r=await T({session:t},e),i=r.sessions.find(e=>e.id===t);if(!i)throw Error(`找不到此目录中的会话。`);await E(i,r.id,e)})},children:[(0,I.jsx)(me,{label:`历史会话 Agent`,value:u,onChange:f,providers:[t,...r],disabled:A}),(0,I.jsxs)(`div`,{className:`field`,children:[(0,I.jsx)(`label`,{htmlFor:`native-history-session`,children:`Session`}),(0,I.jsxs)(`div`,{className:`native-history-input-row`,children:[(0,I.jsx)(ze,{id:`native-history-session`,label:`历史会话`,value:_,onChange:y,placeholder:`选择会话或输入 ID`,disabled:A,loading:b===`list`,empty:_?`未找到匹配会话,可直接输入 Session ID。`:`此目录暂无历史会话,可输入 Session ID。`,options:p.map(e=>({value:e.id,label:e.title,description:e.id,detail:w(e.id)?`已接入`:e.active?`工作中`:Re(e.updatedAt),disabled:e.active&&!w(e.id)})),footer:(0,I.jsxs)(I.Fragment,{children:[h&&(0,I.jsx)(`button`,{className:`native-history-more`,type:`button`,disabled:!!b,onClick:()=>void O(h),children:`加载更多`}),(0,I.jsx)(v,{icon:`refresh`,label:`刷新历史会话`,disabled:!!b,onClick:()=>void O()})]})},u),(0,I.jsx)(`button`,{type:`submit`,disabled:A||!de.safeParse(_.trim()).success||!!k?.active&&!w(k.id),children:A?`正在导入…`:w(_.trim())?`打开`:`导入`})]})]}),(0,I.jsx)(`small`,{className:`muted`,children:`请先退出原终端会话。`})]})})}var B={png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,webp:`image/webp`,gif:`image/gif`,avif:`image/avif`,bmp:`image/bmp`,ico:`image/x-icon`,svg:`image/svg+xml`};function Ve(e,t){let n=e.toLowerCase().split(`.`).at(-1)??``;return t&&Object.values(B).includes(t)?t:Object.hasOwn(B,n)?B[n]:n===`pdf`?`application/pdf`:/^(md|markdown|mdown)$/.test(n)?`text/markdown`:/^html?$/.test(n)?`text/html`:/^(txt|log|csv|tsv|jsonl?|ndjson|ya?ml|toml|ini|cfg|conf|xml|sql|diff|patch|sh|bash|zsh|fish|py|js|jsx|mjs|cjs|ts|tsx|css|scss|vue|svelte|go|rs|c|cc|cpp|h|hpp|java|kt|swift|rb|lua|r|tex|rst|properties|env|lock)$/.test(n)||/^(readme|license|makefile|dockerfile|cmakelists\.txt|\.gitignore)$/i.test(e)?`text/plain`:``}async function He(e,t){let n=e.body.getReader(),r=[],i=0,a=(t??0)>ne;try{for(;;){let{done:e,value:t}=await n.read();if(e)break;let o=Math.min(t.length,ne-i);if(r.push(t.slice(0,o)),i+=o,o<t.length||a&&i===524288){a=!0;break}}}finally{await n.cancel(),n.releaseLock()}return{blob:new Blob(r),truncated:a}}async function Ue(e,t,n,r){let i=e.previewUrl??e.url;if(i.startsWith(`data:`)&&t.startsWith(`image/`))return{format:t,preview:i,download:i};if(!t&&!e.previewUrl)return{format:``};let a=await fetch(i,{credentials:`same-origin`,cache:`no-store`,signal:n});if(!a.ok)throw Error((await a.json().catch(()=>null))?.error?.message??`文件暂不可用。`);if(!t)return await a.body?.cancel(),{format:``};if(t.startsWith(`text/`)){let n=a.headers.get(`X-Teammy-File-Size`)??a.headers.get(`Content-Length`),{blob:i,truncated:o}=await He(a,n===null?e.size:Number(n)),s=o?void 0:r(i.slice(0,i.size,`application/octet-stream`)),c;try{c=new TextDecoder(`utf-8`,{fatal:!0}).decode(await i.arrayBuffer(),{stream:o})}catch{return{format:``,download:s}}return c.includes(`\0`)?{format:``,download:s}:{format:t,text:c,truncated:o,download:s}}let o=await a.blob();if(t===`image/svg+xml`)return{format:t,preview:`data:image/svg+xml;charset=utf-8,`+encodeURIComponent(await o.text()),download:r(o.slice(0,o.size,`application/octet-stream`))};if(t===`application/pdf`&&(navigator.pdfViewerEnabled===!1||await o.slice(0,5).text()!==`%PDF-`))return{format:``,download:r(o.slice(0,o.size,`application/octet-stream`))};let s=r(o.slice(0,o.size,t));return{format:t,preview:s,download:s}}function We({file:e,onClose:t,gallery:n}){let[r,a]=(0,F.useState)(),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(0),[f,p]=(0,F.useState)(!1),m=(0,F.useRef)(null),h=(0,F.useRef)(null),g=Ve(e.name,e.mimeType),{name:_,url:y,previewUrl:b,size:x}=e;(0,F.useEffect)(()=>{let e=new AbortController,t;return a(void 0),s(``),p(!1),Ue({name:_,url:y,previewUrl:b,size:x},g,e.signal,n=>(e.signal.throwIfAborted(),t=URL.createObjectURL(n),t)).then(t=>{e.signal.aborted||a(t)}).catch(t=>{e.signal.aborted||s(i(t))}),m.current?.focus(),()=>{e.abort(),t&&URL.revokeObjectURL(t)}},[y,x,b,_,g,c]),(0,F.useEffect)(()=>{h.current?.scrollIntoView({block:`center`})},[r,e.line]);let S=e.line&&r?.text!==void 0?r.text.split(`
3
- `):null,w=(e.line??1)-1,T=g.startsWith(`image/`);return(0,I.jsx)(d,{id:`session-image-lightbox`,title:e.name,label:T?`图片预览`:`文件预览`,onClose:t,onKeyDown:e=>{n&&[`ArrowLeft`,`ArrowRight`].includes(e.key)&&(e.preventDefault(),n.move(e.key===`ArrowLeft`?-1:1))},actions:(0,I.jsxs)(I.Fragment,{children:[n&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(v,{icon:`chevron`,className:`session-image-previous`,label:`上一张图片`,onClick:()=>n.move(-1)}),(0,I.jsxs)(`small`,{children:[n.index+1,` / `,n.count]}),(0,I.jsx)(v,{icon:`chevron`,label:`下一张图片`,onClick:()=>n.move(1)})]}),T&&r?.format&&(0,I.jsx)(v,{icon:f?`zoomOut`:`zoomIn`,label:f?`适合窗口`:`原始尺寸`,"aria-pressed":f,onClick:()=>p(!f)}),(0,I.jsx)(`a`,{className:`icon-button`,href:o?void 0:r?.download??e.url,"aria-disabled":!!o,download:e.name,"aria-label":`下载文件`,title:`下载文件`,children:(0,I.jsx)(u,{name:`download`})})]}),children:(0,I.jsx)(`div`,{ref:m,tabIndex:-1,className:`session-image-viewer`,children:o?(0,I.jsx)(C,{announce:!0,retry:()=>l(e=>e+1),children:o}):r?r.format?T?(0,I.jsx)(`div`,{className:`session-image-stage`+(f?` original-size`:``),children:(0,I.jsx)(`img`,{src:r.preview,alt:e.name,onError:()=>a({format:``,download:r.download})})}):r.format===`application/pdf`?(0,I.jsx)(`iframe`,{className:`file-preview-document`,src:r.preview,title:e.name+` 预览`}):r.format===`text/html`&&!e.line?(0,I.jsx)(Ae,{name:e.name,url:e.url}):(0,I.jsxs)(`div`,{className:`file-preview-text`,children:[r.format===`text/markdown`&&!e.line?(0,I.jsx)(`article`,{className:`markdown`,children:(0,I.jsx)(P,{children:r.text??``})}):(0,I.jsx)(`pre`,{className:`raw`,children:S&&w<S.length?(0,I.jsxs)(I.Fragment,{children:[w>0&&S.slice(0,w).join(`
4
- `)+`
5
- `,(0,I.jsx)(`mark`,{ref:h,children:S[w]||` `}),S.length>w+1?`
6
- `+S.slice(w+1).join(`
7
- `):``]}):r.text}),r.truncated&&(0,I.jsx)(`small`,{children:`仅显示文件开头,可下载完整文件。`})]}):(0,I.jsx)(`p`,{className:`file-preview-empty`,children:`暂不支持预览此文件。`}):(0,I.jsx)(`p`,{role:`status`,children:`正在读取文件…`})})})}var Ge=[],Ke=`image/png,image/jpeg,image/webp`;function qe(e){if(`image/png,image/jpeg,image/webp`.split(`,`).includes(e.type))return e.type;if(e.type&&e.type!==`application/octet-stream`)return null;let t=e.name.split(`.`).at(-1)?.toLowerCase();return t===`png`?`image/png`:t===`jpg`||t===`jpeg`?`image/jpeg`:t===`webp`?`image/webp`:null}var Je=class{sessions=new Map;listeners=new Set;uploads=new Map;get=e=>this.sessions.get(e)??Ge;subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));set(e,t){this.sessions.set(e,t);for(let e of this.listeners)e()}patch(e,t,n){this.set(e,this.get(e).map(e=>e.id===t?{...e,...n}:e))}add(e,t,n,r=!1){if(!e||!t.length)return;if(t.length+this.get(e).length>4)return r?`每条消息最多添加 4 张图片。`:`每条消息最多添加 4 个附件。`;if(Array.from(t).some(e=>r&&(!qe(e)||!e.size)||e.size>j))return r?`请选择不超过 2 GB 的 PNG、JPEG 或 WebP 图片。`:`每个附件最多 2 GB。`;let i=Array.from(t,e=>({id:a(),name:e.name.slice(0,200)||`附件`,imageOnly:r,file:e,state:`uploading`}));this.set(e,[...this.get(e),...i]);for(let t of i)this.upload(e,t.id,n)}remove(e,t){this.uploads.get(t)?.abort(),this.uploads.delete(t),this.set(e,this.get(e).filter(e=>e.id!==t))}async upload(e,t,n){let r=this.get(e).find(e=>e.id===t);if(!r?.file||this.uploads.has(t))return;let a=new AbortController;this.uploads.set(t,a),this.patch(e,t,{state:`uploading`,error:``});try{let i=r.file,o=`web/local-agent-sessions/${e}/attachments/${t}`,s;if(i.size>5242880){for(let s=r.uploaded??0;s<i.size;s+=M){let r=i.slice(s,s+M);await n(`${o}/parts/${s/M}?size=${i.size}`,O({ok:y()}),{method:`POST`,signal:a.signal,timeoutMs:m,body:r}),this.patch(e,t,{uploaded:s+r.size})}s=await n(`${o}/finish`,be,{method:`POST`,signal:a.signal,timeoutMs:m,body:{name:r.name,size:i.size,imageOnly:r.imageOnly}})}else{let o=await new Promise((e,t)=>{let n=new FileReader;n.onload=()=>e(String(n.result)),n.onerror=()=>t(Error(`附件读取失败。`)),n.onabort=()=>t(Error(`附件读取已取消。`)),a.signal.addEventListener(`abort`,()=>n.abort(),{once:!0}),n.readAsDataURL(i)});if(a.signal.aborted)return;qe(i)&&this.patch(e,t,{preview:o}),s=await n(`web/local-agent-sessions/${e}/${r.imageOnly?`images`:`attachments`}`,be,{method:`POST`,signal:a.signal,timeoutMs:m,body:{id:t,name:r.name,data:o.split(`,`,2)[1]}})}a.signal.aborted||this.set(e,this.get(e).map(e=>e.id===t?{id:t,name:s.name,state:`ready`,attachment:s,imageOnly:e.imageOnly}:e))}catch(n){a.signal.aborted||this.patch(e,t,{state:`failed`,error:i(n),...n instanceof o&&n.code===`ATTACHMENT_INCOMPLETE`?{uploaded:0}:{}})}finally{this.uploads.get(t)===a&&this.uploads.delete(t)}}},Ye=(e,n,r,i=!1)=>t(`/api/v1/projects/${encodeURIComponent(e)}/local-agent/sessions/${encodeURIComponent(n)}/${i?`attachments`:`images`}/${encodeURIComponent(r)}`);function Xe({images:e,remove:t,retry:n,disabled:r=!1}){let[i,a]=(0,F.useState)(),[o,s]=(0,F.useState)([]),c=e.find(e=>e.id===i),l=e.filter(e=>!e.file&&!o.includes(e.id)),d=l.findIndex(e=>e.id===i);return e.length?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`session-images`,children:e.map(e=>(0,I.jsxs)(`div`,{className:`session-image${e.file?` session-file`:``}`,children:[e.file?(0,I.jsxs)(`button`,{type:`button`,className:`session-file-name`,title:e.name,"aria-label":`预览附件 ${e.name}`,disabled:!e.url||e.state===`uploading`||e.state===`failed`,onClick:()=>a(e.id),children:[(0,I.jsx)(u,{name:`attachment`,size:`small`}),(0,I.jsx)(`span`,{children:e.name})]}):o.includes(e.id)?(0,I.jsxs)(`button`,{type:`button`,className:`session-image-preview session-image-unavailable`,title:`重新读取图片`,onClick:()=>s(t=>t.filter(t=>t!==e.id)),children:[(0,I.jsx)(u,{name:`refresh`,size:`small`}),(0,I.jsx)(`span`,{children:e.name}),(0,I.jsx)(`small`,{children:`图片暂不可用`})]}):(0,I.jsx)(`button`,{type:`button`,className:`session-image-preview`,"aria-label":`预览图片 ${e.name}`,title:e.name,disabled:!e.url,onClick:()=>a(e.id),children:e.url?(0,I.jsx)(`img`,{src:e.url,alt:e.name,loading:`lazy`,onError:()=>s(t=>[...t,e.id])}):(0,I.jsx)(u,{name:`image`})}),e.state===`uploading`&&(0,I.jsx)(`span`,{className:`session-image-status`,role:`status`,"aria-label":`正在上传 ${e.name}`,children:(0,I.jsx)(u,{name:`loading`,size:`small`})}),e.state===`failed`&&(0,I.jsx)(`button`,{type:`button`,className:`session-image-status`,"aria-label":`重试上传 ${e.name}`,title:e.error,disabled:r,onClick:()=>n?.(e.id),children:(0,I.jsx)(u,{name:`refresh`,size:`small`})}),t&&(0,I.jsx)(`button`,{type:`button`,className:`session-image-remove`,"aria-label":`移除${e.file?`附件`:`图片`} ${e.name}`,disabled:r,onClick:()=>t(e.id),children:(0,I.jsx)(u,{name:`close`,size:`small`})}),e.state===`failed`&&(0,I.jsx)(`small`,{className:`session-image-error`,children:e.error})]},e.id))}),c&&(0,I.jsx)(We,{file:c,onClose:()=>a(void 0),gallery:d>=0&&l.length>1?{index:d,count:l.length,move:e=>a(l[(d+e+l.length)%l.length]?.id)}:void 0},c.id)]}):null}function Ze({images:e,url:t}){return(0,I.jsx)(Xe,{images:e.map(e=>({...e,file:e.mimeType===`application/octet-stream`,url:t(e.id)}))})}function Qe(t,r,a){let o=e(),s=g(r,`computer-attachment-uploads`),c=(0,F.useMemo)(()=>{let e=o?.get(s)??new Je;return o?.set(s,e),e},[o,s]),l=(0,F.useSyncExternalStore)(c.subscribe,()=>c.get(t)),d=n(),f=(0,F.useRef)(null),p=(0,F.useRef)(null),m=`${r}:${t}`,h=(0,F.useRef)(m);h.current=m,(0,F.useEffect)(()=>d(``),[t,r]);let _=l.flatMap(e=>e.attachment?[e.attachment]:[]),v=l.some(e=>e.state===`uploading`),y=e=>Ye(r,t,e,!0),b=(e,n=!1)=>d(c.add(t,e,a,n)??``);async function x(){try{let e=await navigator.clipboard.read(),t=[];for(let n of e){let e=n.types.find(e=>Ke.split(`,`).includes(e));if(e){let r=await n.getType(e);t.push(new File([r],`剪贴板-${t.length+1}.${e.split(`/`)[1]}`,{type:e}))}}if(h.current!==m)return;t.length?b(t,!0):d(`剪贴板中没有可用的图片。`)}catch(e){h.current===m&&d(e instanceof DOMException&&e.name===`NotAllowedError`?`无法读取剪贴板,请在输入框中粘贴图片或选择图片文件。`:i(e))}}return{files:_,busy:v,count:l.length,failed:l.some(e=>e.state===`failed`),add:b,clear:()=>{for(let e of _)c.remove(t,e.id)},picker:(e,n)=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`input`,{ref:p,type:`file`,className:`session-image-file`,multiple:!0,"aria-label":`选择附件`,disabled:e,onChange:e=>{e.target.files&&b(e.target.files),e.target.value=``}}),n&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`input`,{ref:f,type:`file`,className:`session-image-file`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,"aria-label":`选择图片`,disabled:e,onChange:e=>{e.target.files&&b(e.target.files,!0),e.target.value=``}}),(0,I.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":`添加图片`,title:`添加图片,也可粘贴或拖入`,disabled:e,onClick:()=>f.current?.click(),children:(0,I.jsx)(u,{name:`image`,size:`small`})})]}),(0,I.jsx)(S,{id:`session-attachments`,triggerId:`session-attachments-trigger`,label:`附件`,placement:`top`,className:`composer-menu composer-attachments`,routeKey:t,disabled:e,trigger:(0,I.jsx)(u,{name:`attachment`,size:`small`}),children:e=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{e(),p.current?.click()},children:[(0,I.jsx)(u,{name:`attachment`,size:`small`}),`选择文件`]}),n&&typeof navigator.clipboard?.read==`function`&&(0,I.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{e(),x()},children:[(0,I.jsx)(u,{name:`paste`,size:`small`}),`粘贴图片`]})]})})]}),preview:e=>(0,I.jsx)(Xe,{images:l.map(e=>({id:e.id,name:e.name,mimeType:e.attachment?.mimeType??e.file?.type,url:e.attachment?y(e.id):e.preview??``,size:e.attachment?.size??e.file?.size??0,file:e.attachment?e.attachment.mimeType===`application/octet-stream`:!!e.file&&(e.file.size>5242880||!qe(e.file)),state:e.state,...e.error?{error:e.error}:{}})),disabled:e,remove:e=>{c.remove(t,e),a(`web/local-agent-sessions/${t}/attachments/${e}`,E(),{method:`DELETE`}).catch(()=>{})},retry:e=>void c.upload(t,e,a)})}}var V={offered:{label:`待本地接收`,icon:`clock`},received:{label:`待本地接收`,icon:`clock`},queued:{label:`排队中`,icon:`clock`},dispatching:{label:`正在连接`,icon:`loading`,spinning:!0},running:{label:`执行中`,icon:`loading`,spinning:!0},cancelled:{label:`已撤回`,icon:`close`},interrupted:{label:`已停止`,icon:`stop`},failed:{label:`未能执行`,icon:`warning`},human_routed:{label:`未送达本地`,icon:`warning`},uncertain:{label:`需要核对`,icon:`warning`}};function $e({state:e,error:t}){let n=V[e];if(!n)return null;let r=t?`${n.label}:${t}`:n.label;return(0,I.jsx)(`span`,{className:`execution-status${n.spinning?` is-spinning`:``}`,role:`img`,"aria-label":r,title:r,children:(0,I.jsx)(u,{name:n.icon,size:`small`})})}function et({message:e}){return!e.queue||e.queue.state===`running`?null:(0,I.jsx)($e,{state:e.queue.state,error:e.queue.error})}function tt(e,n,r,a){let[s,c]=(0,F.useState)(),l=(0,F.useRef)(null);(0,F.useEffect)(()=>{if(!n)return;let s=new AbortController,{signal:u}=s,d=`web/local-agent-sessions/${encodeURIComponent(n)}`,f=new URLSearchParams(location.search).get(`question`),p,m,h=!1,g=!1,_=Promise.resolve(),v=(e=``)=>{u.aborted||c({session:n,...p?{data:p}:{},error:e,loadingOlder:h})},y=e=>r(d+(Object.keys(e).length?`?`+new URLSearchParams(e):``),he,{signal:u}),b=e=>(_=_.then(async()=>{if(!u.aborted)try{await e()}catch(e){e instanceof o&&[401,403,404].includes(e.status)&&(p=void 0),g=!0,v(i(e))}}),_),x=e=>b(async()=>{if(e!==void 0&&p&&p.cursor>=e&&!g)return;let t=m,n=await y(t===void 0?!p&&f?{question:f}:{}:{from:String(t)});u.aborted||(p&&!a(!1)&&S(!1),m!==t&&m!==void 0&&n.olderBefore!==null&&n.olderBefore>m&&(n=await y({from:String(m)})),!p&&f&&(m=n.olderBefore??1),p=n,g=!1,v())});function S(e){e&&!h?m=void 0:p&&m===void 0&&(m=p.olderBefore??1)}function C(){p?.olderBefore&&!h&&(S(!1),h=!0,v(),b(async()=>{try{if(!p?.olderBefore)return;let e=await y({before:String(p.olderBefore)}),t=e.olderBefore??1,n=e.cursor===p.cursor?{...p,messages:[...e.messages,...p.messages],olderBefore:e.olderBefore}:await y({from:String(t)});if(u.aborted)return;a(!0),m=t,p=n,g=!1}finally{h=!1,v()}}))}l.current={reload:()=>x(),older:C,follow:S,reveal:e=>b(async()=>{if(!p?.olderBefore||e>=p.olderBefore)return;let t=await y({from:String(e)});m=e,p=t,g=!1,v()})},x();let w=new EventSource(t(`/api/v1/projects/${encodeURIComponent(e)}/${d}/events?updates=1`)),T=e=>{document.hidden||x(Number(e.lastEventId))};w.addEventListener(`change`,T),w.addEventListener(`snapshot`,T);let E=setInterval(()=>{!document.hidden&&(g||w.readyState!==EventSource.OPEN)&&x()},15e3),D=()=>{document.hidden||x()};return document.addEventListener(`visibilitychange`,D),()=>{s.abort(),l.current=null,w.close(),clearInterval(E),document.removeEventListener(`visibilitychange`,D)}},[n,e,r,a]);let u=(0,F.useCallback)(()=>l.current?.reload()??Promise.resolve(),[]),d=(0,F.useCallback)(()=>l.current?.older(),[]),f=(0,F.useCallback)(e=>l.current?.follow(e),[]),p=(0,F.useCallback)(e=>l.current?.reveal(e)??Promise.resolve(),[]);return{...s?.session===n?s:void 0,reload:u,older:d,follow:f,reveal:p}}function H({message:e,images:t,status:r,rewind:o,onFile:s}){let c=o?.commands.find(t=>t.kind===`rewind`&&[`queued`,`running`,`uncertain`].includes(t.state)&&JSON.parse(t.argument).messageId===e.id),[l,d]=(0,F.useState)(!!c),[f,p]=(0,F.useState)(c?JSON.parse(c.argument).body:e.body),[m,h]=(0,F.useState)(!1),g=n(),[_,y]=(0,F.useState)(!1),[b,x]=(0,F.useState)(),S=(0,F.useRef)(void 0),w=Oe(f);(0,F.useLayoutEffect)(()=>{l&&w.current&&(w.current.style.height=`0px`,w.current.style.height=`${w.current.scrollHeight}px`)},[l]);let E=o?.commands.find(e=>e.id===b?.id)??b??c,D=_||E&&[`queued`,`running`].includes(E.state),O=o?.available&&e.source===`web_session`&&e.id.startsWith(`input:`)&&(!e.queue||[`handled`,`interrupted`].includes(e.queue.state));async function k(){if(!o||D||!f.trim())return;let t=JSON.stringify({messageId:e.id,body:f.trim(),expectedLastMessage:o.expectedLastMessage});(E&&[`failed`,`uncertain`].includes(E.state)||S.current?.argument!==t)&&(S.current={id:a(),argument:t}),y(!0),g(``);try{let e=await o.request(`web/local-agent-sessions/${o.session}/commands`,ue,{method:`POST`,body:{id:S.current.id,kind:`rewind`,argument:S.current.argument}});x(e),o.refresh()}catch(e){g(i(e))}finally{y(!1)}}return(0,I.jsxs)(`div`,{className:`computer-user-entry${l?` editing`:``}`,children:[(0,I.jsxs)(De,{mine:!0,author:`你`,time:e.createdAt,children:[t,l?(0,I.jsxs)(`form`,{className:`computer-message-edit`,onSubmit:e=>{e.preventDefault(),k()},children:[(0,I.jsx)(`textarea`,{ref:w,"aria-label":`编辑历史消息`,value:f,onChange:e=>p(e.target.value),disabled:!!D,autoFocus:!0,rows:1}),(0,I.jsxs)(`div`,{className:`computer-message-edit-footer`,children:[(0,I.jsx)(`small`,{children:`替换此后的对话,保留工作区文件`}),(0,I.jsx)(v,{icon:`close`,label:`取消编辑`,disabled:!!D,onClick:()=>{d(!1),g(``),p(e.body)}}),(0,I.jsx)(`button`,{type:`submit`,className:`message-send primary`,"aria-label":D?`正在回退`:`从此处继续`,title:D?`正在回退`:`从此处继续`,disabled:!!D||!f.trim(),children:(0,I.jsx)(u,{name:D?`loading`:`send`,size:`small`})})]}),(0,I.jsx)(C,{children:E&&[`failed`,`uncertain`].includes(E.state)&&E.error})]}):(0,I.jsx)(`div`,{className:`markdown`,children:(0,I.jsx)(P,{onFile:s,children:e.body})}),!l&&r]}),!l&&(0,I.jsxs)(`div`,{className:`computer-message-actions`,children:[(0,I.jsx)(v,{icon:m?`check`:`copy`,label:m?`已复制`:`复制消息`,onClick:()=>{g(``),T(e.body).then(()=>h(!0)).catch(e=>g(i(e)))}}),O&&(0,I.jsx)(v,{icon:`edit`,label:`编辑并从此处继续`,onClick:()=>{p(e.body),d(!0)}})]})]})}function U({label:e,meta:t,children:n,className:r=``,onToggle:i}){return(0,I.jsxs)(`details`,{className:`tool-details ${r}`,onToggle:i,children:[(0,I.jsxs)(`summary`,{className:`tool-summary`,title:e,children:[(0,I.jsx)(u,{name:`chevron`,size:`small`}),(0,I.jsx)(`span`,{className:`tool-details-label`,children:e}),t&&(0,I.jsx)(`span`,{className:`tool-details-status`,children:t})]}),n]})}function nt(e){if(e<1e3)return`不到 1 秒`;let t=Math.floor(e/1e3),n=Math.floor(t/60),r=Math.floor(n/60);return[r?`${r} 小时`:``,n%60?`${n%60} 分`:``,t%60?`${t%60} 秒`:``].filter(Boolean).join(` `)}function rt({children:e}){return(0,I.jsx)(`div`,{className:`computer-divider`,children:(0,I.jsx)(`span`,{children:e})})}function W({message:e}){let t=e.state===`succeeded`?`已工作`:e.state===`interrupted`?`已停止`:e.state===`failed`?`执行失败`:`需要核对`;return(0,I.jsxs)(rt,{children:[t,e.activity?.durationMs===void 0?``:` · ${nt(e.activity.durationMs)}`]})}var G={offered:`待本地接收`,pending:`待投递`,human_routed:`未送达本地`,failed:`失败`,uncertain:`需要核对`};function K(e){let t=[];for(let n of e)if(n.role===`assistant`&&n.activity?.kind===`tool`&&!n.question){let e=t.at(-1);Array.isArray(e)&&e[0].activity?.turnId===n.activity.turnId?e.push(n):t.push([n])}else t.push(n);return t}function q({text:e,onFile:t}){let n=[],r=0;if(t)for(let{start:i,end:a,link:o}of N(e))n.push(e.slice(r,i),(0,I.jsx)(`button`,{type:`button`,className:`computer-file-link`,onClick:()=>t(o),children:e.slice(i,a)},i)),r=a;return(0,I.jsxs)(`pre`,{children:[n,e.slice(r)]})}function J({call:e,onFile:t,visible:n,onOpen:r}){let[i,a]=(0,F.useState)(!1);return(0,I.jsx)(U,{className:`computer-tool`,onToggle:e=>{let t=e.currentTarget.open;a(t),r?.(t)},label:e.activity?.label??`工具调用`,meta:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)($e,{state:e.state}),e.activity?.durationMs!==void 0&&(0,I.jsx)(`span`,{children:nt(e.activity.durationMs)})]}),children:i&&n&&(0,I.jsx)(q,{text:e.body,onFile:t})})}function Y({calls:e,onFile:t}){let n=(0,F.useId)(),[r,i]=(0,F.useState)(!1),a=e.length>1,o=[`failed`,`uncertain`,`interrupted`].find(t=>e.some(e=>e.state===t));return(0,I.jsxs)(`div`,{className:a?`tool-details computer-tool-group`:void 0,children:[a&&(0,I.jsxs)(`button`,{type:`button`,className:`tool-summary`,"aria-expanded":r,"aria-controls":n,onClick:()=>i(!r),children:[(0,I.jsx)(u,{name:`chevron`,size:`small`}),e.length,` 次工具调用`,o&&(0,I.jsx)($e,{state:o}),e.some(e=>e.state===`running`)&&(0,I.jsx)($e,{state:`running`})]}),(0,I.jsx)(`div`,{id:n,className:a?`computer-tool-list`:void 0,hidden:a&&!r,children:e.map(e=>(0,I.jsx)(J,{call:e,onFile:t,visible:!a||r,onOpen:a?void 0:i},e.id))})]})}function it({messages:e,renderQuestion:t,imageUrl:n,renderQueue:r,rewind:i,onFile:a}){let o=new Map(e.filter(e=>e.activity?.kind===`turn`).map(e=>[e.activity.turnId,e])),s=new Map,c=new Set(e.flatMap(e=>{let t=e.question?.planSource;return t?[JSON.stringify([t.turnId,t.itemId])]:[]})),l=new Set(e.flatMap(e=>{let t=e.activity;return t?.kind===`commentary`&&c.has(JSON.stringify([t.turnId,t.itemId]))?[JSON.stringify([t.turnId,e.body])]:[]}));for(let t of e)t.activity?.kind===`answer`&&s.set(t.activity.turnId,t.id);let u=e.filter(({activity:e,body:t})=>e?.kind!==`commentary`||!c.has(JSON.stringify([e.turnId,e.itemId]))&&!l.has(JSON.stringify([e.turnId,t]))),d=(0,F.useRef)({keys:new Map,next:0}),f=new Map,p=new Set,m=d.current.next,h=K(u);for(let e of h){if(!Array.isArray(e))continue;let t;for(let n of e){if(t=d.current.keys.get(n.id),t!==void 0&&!p.has(t))break;t=void 0}t??=m++,p.add(t);for(let n of e)f.set(n.id,t)}return(0,F.useLayoutEffect)(()=>{d.current={keys:f,next:m}}),(0,I.jsx)(`div`,{className:`computer-messages`,children:h.map(e=>{if(Array.isArray(e))return(0,I.jsx)(Y,{calls:e,onFile:a},`tools:${f.get(e[0].id)}`);let c=e.activity;if(e.role===`system`)return(0,I.jsx)(rt,{children:e.body},e.id);if(c?.kind===`turn`)return s.has(c.turnId)?null:(0,I.jsx)(W,{message:e},e.id);if(e.role===`user`)return(0,I.jsx)(H,{message:e,rewind:i,onFile:a,images:n&&(e.attachments??e.images)?.length?(0,I.jsx)(Ze,{images:e.attachments??e.images,url:t=>n(t,!!e.attachments)}):null,status:e.queue&&r?r(e):G[e.state]&&(0,I.jsx)(we,{label:G[e.state],state:e.state})},e.id);let l=c?.kind===`answer`&&s.get(c.turnId)===e.id?o.get(c.turnId):void 0;return(0,I.jsxs)(F.Fragment,{children:[l&&(0,I.jsx)(W,{message:l}),(0,I.jsx)(`article`,{id:e.question?`computer-question-${e.question.id}`:void 0,tabIndex:e.question?-1:void 0,className:`computer-agent-message ${c?.kind===`commentary`?`computer-commentary`:``} ${e.question?`question-bubble`:``}`,children:e.question?t(e.question):(0,I.jsx)(`div`,{className:`markdown`,children:(0,I.jsx)(P,{onFile:a,children:e.body})})})]},e.id)})})}function X({disabled:e,onSend:t,initialValue:n=``,placeholder:r}){let[i,a]=(0,F.useState)(n),[o,s]=(0,F.useState)(!!n),c=`其他回答`,l=(0,F.useRef)(null),d=(0,F.useCallback)(e=>{if(!l.current)return;let t=document.createElement(`canvas`).getContext(`2d`);if(!t)return;t.font=getComputedStyle(e).font;let n=Math.max(...(i||`${c}…`).split(`
8
- `).map(e=>t.measureText(e).width));l.current.style.setProperty(`--reply-width`,`${Math.ceil(n+(o?52:26))}px`)},[i,o,c]),f=Oe(i,d);return(0,I.jsxs)(`form`,{ref:l,className:`inline-reply${o?` active`:``}`,onFocus:()=>s(!0),onBlur:e=>{!i&&!e.currentTarget.contains(e.relatedTarget)&&s(!1)},onSubmit:n=>{n.preventDefault(),!e&&i.trim()&&t(i.trim()).then(e=>{e&&a(``)})},children:[(0,I.jsx)(`textarea`,{ref:f,rows:1,"aria-label":`自定义回答`,placeholder:r??`${c}…`,value:i,disabled:e,onChange:e=>a(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&!t.nativeEvent.isComposing&&(t.preventDefault(),!e&&i.trim()&&t.currentTarget.form?.requestSubmit())}}),o&&(0,I.jsx)(`button`,{className:`inline-reply-send`,type:`submit`,disabled:e||!i.trim(),"aria-label":`发送${c}`,title:`发送${c}`,children:(0,I.jsx)(u,{name:`send`,size:`small`})})]})}function at({question:e,session:t,request:r,refresh:o}){let[s,c]=(0,F.useState)({}),[l,d]=(0,F.useState)({}),f=n(),[p,m]=(0,F.useState)(!1),[h,g]=(0,F.useState)(!1),[_,v]=(0,F.useState)(``),b=(0,F.useRef)(null),x=(0,F.useRef)(!1),S=(0,F.useRef)(void 0);(0,F.useEffect)(()=>{if(e.state!==`pending`||x.current||!b.current)return;let n=!1,a=()=>{if(!n||document.visibilityState!==`visible`||!b.current)return;let a=b.current.getBoundingClientRect();a.bottom>0&&a.top<innerHeight&&r(`web/local-agent-sessions/${t}/questions/${e.id}/presented`,O({ok:y()}),{method:`POST`}).then(()=>{x.current=!0,window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>f(i(e)))},o=new IntersectionObserver(e=>{n=e.some(e=>e.isIntersecting),a()});return o.observe(b.current),document.addEventListener(`visibilitychange`,a),()=>{o.disconnect(),document.removeEventListener(`visibilitychange`,a)}},[e.id,e.state,t,r]);async function C(n){let s=JSON.stringify(n);S.current?.fingerprint!==s&&(S.current={fingerprint:s,value:{...n,id:a()}}),m(!0),f(``);try{return await r(`web/local-agent-sessions/${t}/questions/${e.id}/answers`,E(),{method:`POST`,body:S.current.value}),S.current=void 0,o(),!0}catch(e){return f(i(e)),!1}finally{m(!1)}}let[w,T]=(0,F.useState)(Date.now);(0,F.useEffect)(()=>{if(!e.approval||e.state!==`pending`||e.autoApproveAt==null)return;T(Date.now());let t=setInterval(()=>T(Date.now()),1e3);return()=>clearInterval(t)},[e.approval,e.state,e.autoApproveAt]);let D=e.autoApprove!==!1&&e.autoApproveAt!=null?Math.max(0,Math.ceil((e.autoApproveAt-w)/1e3)):null,k=e.response,A=e.state===`answered`,ee=[`expired`,`cancelled`].includes(e.state),te=[`human_routed`,`failed`,`handled`].includes(e.submissionState??``)&&!A,j=oe(e),ne=e.kind===`plan`,re=e.actions?.find(e=>e.id===k?.actionId),ie=ee?`已过期`:e.state===`uncertain`||e.submissionState===`uncertain`?`需核对`:A?ne?re?.label??`已处理`:e.approval?k?.decision===!0?`已允许`:k?.decision===!1?`已拒绝`:`已处理`:re?re.label:k?``:`已回答`:te?`请重新提交`:k?`正在提交`:``,ae=ee||k?.decision===!1||te?`close`:A?`check`:`clock`,se=e.questions.length>1||e.questions.some(e=>e.multiSelect),ce=(t=s)=>C({body:e.questions.length===1?t[e.questions[0].id]||(l[e.questions[0].id]??[]).join(`、`):JSON.stringify(t),...e.kind||e.questions.some(e=>e.multiSelect)?{answers:t}:{},...e.questions.some(e=>e.multiSelect)?{selections:l}:{}});if(e.delivery===`async`&&(A||ee)){let t=A&&k?e.questions.flatMap(e=>[...k.selections?.[e.id]??[],k.answers[e.id]].filter(Boolean)):[];return t.length?(0,I.jsxs)(`div`,{className:`question-response native-async-answer`,children:[(0,I.jsx)(u,{name:`check`,size:`small`}),(0,I.jsx)(`span`,{children:t.join(`
9
- `)})]}):null}return(0,I.jsxs)(`div`,{className:`native-question ${ne?`native-plan`:``} ${j?`native-question-pending`:``}`,ref:b,children:[ne?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`native-plan-heading`,children:[(0,I.jsx)(u,{name:`file`,size:`small`}),(0,I.jsx)(`span`,{children:`实施计划`})]}),j?(0,I.jsx)(`div`,{className:`native-plan-content markdown`,children:(0,I.jsx)(P,{children:e.plan??``})}):(0,I.jsxs)(`details`,{className:`native-plan-history markdown`,children:[(0,I.jsx)(`summary`,{children:`查看计划`}),(0,I.jsx)(P,{children:e.plan??``})]}),j&&(0,I.jsxs)(I.Fragment,{children:[!h&&(0,I.jsx)(`div`,{className:`question-actions native-plan-actions ${e.actions&&e.actions.length>3?`native-plan-actions-expanded`:``}`,children:e.actions?.map(e=>(0,I.jsx)(`button`,{type:`button`,disabled:p,title:e.description,className:e.id===`implement`?`primary`:``,onClick:()=>e.id===`revise`?g(!0):void C({body:e.label,actionId:e.id}),children:e.label},e.id))}),!h&&e.actions?.find(e=>e.id===`implement`)?.description&&(0,I.jsxs)(`small`,{className:`native-plan-note muted`,children:[`开始实施:`,e.actions.find(e=>e.id===`implement`).description]}),h&&(0,I.jsxs)(`form`,{className:`native-plan-feedback`,onSubmit:e=>{e.preventDefault(),C({body:_,actionId:`revise`})},children:[(0,I.jsxs)(`label`,{children:[`修改意见`,(0,I.jsx)(`textarea`,{autoFocus:!0,value:_,onChange:e=>v(e.target.value),placeholder:`说明希望调整的部分,Agent 将修改后再次请求确认`})]}),(0,I.jsxs)(`div`,{className:`question-actions native-plan-feedback-actions`,children:[(0,I.jsx)(`button`,{className:`primary`,disabled:p||!_.trim(),children:`提交修改意见`}),(0,I.jsx)(`button`,{type:`button`,disabled:p,onClick:()=>g(!1),children:`返回计划`})]})]})]}),!j&&k?.actionId===`revise`&&k.answers.feedback&&(0,I.jsx)(`div`,{className:`question-response`,children:k.answers.feedback})]}):e.approval?(0,I.jsxs)(`div`,{className:`native-approval-row`,children:[(0,I.jsx)(U,{className:`native-approval-details`,label:e.questions.map(e=>e.text.split(`
10
- `).filter(Boolean).slice(0,2).join(` · `)).join(` · `),children:(0,I.jsx)(`pre`,{children:e.questions.map(e=>e.text).join(`
11
-
12
- `)})}),j?(0,I.jsxs)(`div`,{className:`native-approval-options`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`primary`,disabled:p,"aria-label":`允许`,title:D===null?void 0:`倒计时结束后自动允许本次操作`,onClick:()=>void C({body:`允许`,decision:!0}),children:[`允许`,D!==null&&(0,I.jsxs)(`span`,{"aria-hidden":`true`,children:[`(`,D,`s)`]})]}),(0,I.jsx)(`button`,{type:`button`,disabled:p,onClick:()=>void C({body:`拒绝`,decision:!1}),children:`拒绝`})]}):ie&&(0,I.jsxs)(`small`,{className:`question-result`,children:[(0,I.jsx)(u,{name:ae,size:`small`}),ie]})]}):(0,I.jsxs)(I.Fragment,{children:[e.questions.map(t=>(0,I.jsxs)(`div`,{className:`native-question-part`,children:[(0,I.jsx)(`p`,{children:t.text}),j&&(0,I.jsx)(`div`,{className:`question-options ${Object.values(t.descriptions??{}).some(Boolean)?`question-options-described`:``}`,children:t.options.map(e=>(0,I.jsxs)(`button`,{type:`button`,disabled:p,"aria-pressed":t.multiSelect?l[t.id]?.includes(e)??!1:s[t.id]===e,onClick:()=>{if(t.multiSelect){d(n=>({...n,[t.id]:n[t.id]?.includes(e)?n[t.id].filter(t=>t!==e):[...n[t.id]??[],e]}));return}let n={...s,[t.id]:e};c(n),se||ce(n)},children:[(0,I.jsxs)(`span`,{className:`question-option-label`,children:[t.multiSelect&&(0,I.jsx)(`span`,{"aria-hidden":`true`,className:`question-check`,children:l[t.id]?.includes(e)&&(0,I.jsx)(u,{name:`check`,size:`small`})}),e]}),t.descriptions?.[e]&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`span`,{className:`question-option-separator`,"aria-hidden":`true`,children:`|`}),(0,I.jsx)(`span`,{className:`question-option-description`,title:t.descriptions[e],children:t.descriptions[e]})]})]},e))}),t.freeText&&j&&(0,I.jsx)(X,{initialValue:t.initialValue,placeholder:t.placeholder,disabled:p,onSend:async e=>{let n={...s,[t.id]:e};return c(n),se?!0:ce(n)}}),j&&se&&s[t.id]&&!t.options.includes(s[t.id])&&(0,I.jsx)(`small`,{children:s[t.id]}),!j&&!e.approval&&(k?.answers[t.id]||k?.selections?.[t.id]?.length)&&(0,I.jsxs)(`div`,{className:`question-response`,children:[(0,I.jsx)(u,{name:A?`check`:`clock`,size:`small`}),(0,I.jsx)(`span`,{children:[...k.selections?.[t.id]??[],k.answers[t.id]].filter(Boolean).join(`、`)})]})]},t.id)),j&&e.actions?.length&&(0,I.jsx)(`div`,{className:`question-actions`,children:e.actions.map(e=>(0,I.jsx)(`button`,{disabled:p,onClick:()=>void C({body:e.label,actionId:e.id}),children:e.label},e.id))}),j&&se&&(0,I.jsx)(`div`,{className:`question-actions`,children:(0,I.jsx)(`button`,{disabled:p||e.questions.some(e=>!s[e.id]?.trim()&&!l[e.id]?.length),onClick:()=>void ce(),children:`回答`})})]}),ie&&(!e.approval||ne)&&(0,I.jsxs)(`small`,{className:`question-result`,children:[(0,I.jsx)(u,{name:ae,size:`small`}),ie]})]})}function ot({session:e,active:t,commands:n,request:r,refresh:o,onError:s}){let[c,l]=(0,F.useState)(!1),[d,f]=(0,F.useState)(),p=(0,F.useRef)(void 0),m=n.find(e=>e.id===d?.id)??d,h=c||m&&[`queued`,`running`].includes(m.state)||n.some(e=>e.kind===`stop`&&[`queued`,`running`].includes(e.state));if(!t&&!h)return null;async function g(){if(!h){p.current??=a(),l(!0),s(``);try{let t=await r(`web/local-agent-sessions/${e}/commands`,ue,{method:`POST`,body:{id:p.current,kind:`stop`}});f(t),p.current=void 0,o()}catch(e){s(i(e))}finally{l(!1)}}}return(0,I.jsxs)(`button`,{type:`button`,className:`message-stop`,"aria-label":h?`正在停止`:`停止当前轮`,title:h?`正在停止`:`停止当前轮`,disabled:!!h,onClick:()=>void g(),children:[(0,I.jsx)(`span`,{className:`message-stop-ring`,"aria-hidden":`true`}),(0,I.jsx)(u,{name:`stop`,size:`small`})]})}var st={minimal:`极低`,low:`低`,medium:`中`,high:`高`,xhigh:`极高`,max:`最高`,ultra:`极致`,none:`无`,off:`关闭`};function Z({id:e,label:t,current:n,options:r,disabled:i,onSelect:a}){let o=r.find(e=>e.value===n);return(0,I.jsx)(S,{id:`${e}-menu`,triggerId:e,placement:`top`,className:`composer-menu composer-choice`,label:`选择${t}`,disabled:i,routeKey:n,trigger:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`span`,{title:`${t}:${o?.label??n}`,children:o?.shortLabel??o?.label??n}),(0,I.jsx)(u,{name:`chevronDown`,size:`small`})]}),children:e=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`composer-menu-heading`,children:t}),r.map(t=>(0,I.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-label":t.label,onClick:()=>{e(),a(t.value)},children:[(0,I.jsxs)(`span`,{className:`composer-option-copy`,children:[(0,I.jsx)(`span`,{children:t.label}),t.description&&(0,I.jsx)(`small`,{children:t.description})]}),t.value===n&&(0,I.jsx)(u,{name:`check`,size:`small`})]},t.value))]})})}function ct({session:e,models:t,busy:n,available:r,online:i,commands:a,controls:o,draft:s,onInsert:c,onConfig:l}){let[d,f]=(0,F.useState)(!1);(0,F.useEffect)(()=>{/^[/$]([^\s]*)$/.exec(s)?f(!0):f(!1)},[s]);let p=e.config.model??e.effectiveConfig?.model,m=t.find(e=>e.id===p||e.resolvedModel===p)??(e.config.model?void 0:t.find(e=>e.isDefault)),h=n||!r,g=e.provider===`claude`,_=e.provider===`cursor`,v=o??ye(e.provider),y=m?.effortLabel??`思考强度`,b=e=>m?.effortLabel?e:st[e]??e,x=e.appliedRevision===e.revision?e.effectiveConfig?.mode:void 0,C=t.find(e=>e.isDefault)?.id??(e.config.model?null:e.effectiveConfig?.model),w=t.find(e=>e.id===C)?.name??C,T=e=>g?e.replace(/^Claude\s+/,``):e,E=[{value:``,label:w?`默认 · ${w}`:t.length?`默认模型`:`模型未获取`,shortLabel:w?T(w):t.length?`默认模型`:`模型`},...t.map(e=>({value:e.id,label:e.name,shortLabel:T(e.name)}))];e.config.model&&!t.some(t=>t.id===e.config.model)&&E.push({value:e.config.model,label:e.config.model,shortLabel:T(e.config.model)});let D=m?.id===e.effectiveConfig?.model?e.effectiveConfig?.effort:m?.defaultEffort,O=[{value:``,label:D?`默认 · ${b(D)}`:`默认${y}`,shortLabel:D?b(D):m?.effortLabel??`强度`},...(m?.efforts??[]).map(e=>({value:e,label:b(e)}))];return e.config.effort&&!O.some(t=>t.value===e.config.effort)&&O.push({value:e.config.effort,label:b(e.config.effort)}),(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(S,{id:`session-commands`,triggerId:`session-command-trigger`,label:`命令与 Skills`,placement:`top`,className:`composer-menu composer-commands`,routeKey:e.id,trigger:(0,I.jsx)(u,{name:`command`,size:`small`}),open:d,onOpenChange:f,focusFirst:!1,disabled:h||!i,children:e=>(0,I.jsxs)(I.Fragment,{children:[[...a].sort((e,t)=>e.name.localeCompare(t.name,`en`)).map(t=>(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,title:[t.description,t.path].filter(Boolean).join(`
13
- `),onClick:()=>{e(),c(t)},children:(0,I.jsxs)(`span`,{className:`composer-command-row`,children:[(0,I.jsxs)(`span`,{className:`composer-command-name`,children:[t.prefix??(t.kind===`skill`?`$`:`/`),t.name]}),(0,I.jsx)(`small`,{children:t.description})]})},`${t.kind}:${t.path??t.name}`)),!a.length&&(0,I.jsx)(`div`,{className:`composer-menu-heading`,children:`尚未获取命令`})]})}),(0,I.jsx)(Z,{id:`session-model`,label:`模型`,current:e.config.model??``,options:E,disabled:h,onSelect:n=>{let r=t.find(e=>e.id===n);l({...e.config,model:n||null,..._?{options:{}}:{},effort:e.config.effort&&r?.efforts.includes(e.config.effort)?e.config.effort:null})}}),(e.provider===`codex`||g||(m?.efforts.length??0)>0||!!e.config.effort)&&(0,I.jsx)(Z,{id:`session-effort`,label:y,current:e.config.effort??``,options:O,disabled:h,onSelect:t=>l({...e.config,effort:t||null})}),m?.options?.map(t=>(0,I.jsx)(Z,{id:`session-option-${t.id}`,label:t.name,current:e.config.options?.[t.id]??``,options:[{value:``,label:`默认 · ${t.choices.find(e=>e.value===t.defaultValue)?.label??t.defaultValue}`},...t.choices],disabled:h,onSelect:n=>{let r={...e.config.options};n?r[t.id]=n:delete r[t.id],l({...e.config,options:r})}},t.id)),v.map(t=>(0,I.jsx)(Z,{id:t.key===`mode`&&!g?`session-mode`:`session-permission`,label:t.label,current:t.key===`mode`?x??e.config.mode??t.defaultValue:e.config.permission,options:t.choices,disabled:h,onSelect:n=>l(t.key===`mode`?{...e.config,mode:n||void 0}:{...e.config,permission:n})},t.key))]})}var lt=(0,F.lazy)(()=>_e(()=>import(`./TerminalPane-B0w1stXs.js`),__vite__mapDeps([0,1,2,3,4,5,6,7]),import.meta.url)),ut=O({ok:y()}),dt={idle:`空闲`,working:`工作中`,waiting:`等待回答`,queued:`等待执行`,uncertain:`需要核对`,human:`人工处理`,offered:`待本地接收`,accepted:`本地已接手`,human_routed:`未送达本地`,pending:`待投递`,sent:`已发送`,succeeded:`已完成`,running:`进行中`,failed:`失败`};function ft(e){return{width:e.clientWidth,height:e.clientHeight,top:e.scrollHeight-e.clientHeight}}function Q({navigate:e,memberId:t}){let{request:n,projectId:i}=k(),a=(0,F.useCallback)(e=>n(`web/local-agent-settings`,ce,{signal:e}),[n]),o=r(a,3e4);return(0,F.useEffect)(()=>{let e=()=>void o.reload();return window.addEventListener(`teammy:local-access`,e),()=>window.removeEventListener(`teammy:local-access`,e)},[o.reload]),!o.data&&o.error?(0,I.jsx)(D,{resource:o}):o.data?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(l,{message:o.error}),(0,I.jsx)(pt,{localAvailable:o.data.accessible,navigate:e,memberId:t},`${i}/${t}`)]}):null}function pt({localAvailable:o,navigate:s,memberId:c}){let l=k(),f=e(),p=g(l.projectId,c,`computer-selection`),m=g(l.projectId,c,`computer-drafts`),h=f?.get(p),[_,y]=(0,F.useState)(()=>new Set),[x,w]=(0,F.useState)(()=>({project:l.projectId,directory:new URLSearchParams(location.search).get(`directory`)??h?.directory??``,session:new URLSearchParams(location.search).get(`session`)??(new URLSearchParams(location.search).has(`terminal`)?``:h?.session??``),terminal:new URLSearchParams(location.search).get(`terminal`)??(new URLSearchParams(location.search).has(`session`)?``:h?.terminal??``)})),T=n(),[O,j]=(0,F.useState)(!1),[ne,ce]=(0,F.useState)(!1),[ue,de]=(0,F.useState)(()=>f?.get(m)??{}),me=ue[x.session]??``,he=e=>de(t=>({...t,[x.session]:typeof e==`function`?e(t[x.session]??``):e}));(0,F.useEffect)(()=>{f?.set(m,ue)},[f,m,ue]);let[_e,ye]=(0,F.useState)(``),[be,M]=(0,F.useState)(!1),[N,P]=(0,F.useState)(`codex`),[De,Oe]=(0,F.useState)(!1),[Ae,Ne]=(0,F.useState)(``),[L,Pe]=(0,F.useState)(),[Fe,Le]=(0,F.useState)(Date.now);(0,F.useEffect)(()=>{let e=setInterval(()=>Le(Date.now()),6e4);return()=>clearInterval(e)},[]);let R=(0,F.useRef)(null),z=(0,F.useRef)(!0),ze=(0,F.useRef)(null),B=(0,F.useCallback)(e=>{let t=ft(e),n=ze.current,r=n&&(t.width!==n.width||t.height!==n.height);return(z.current&&r?Math.min(n.top,t.top):t.top)-e.scrollTop<96},[]),He=(0,F.useCallback)(e=>{e.scrollTop=e.scrollHeight,ze.current=ft(e)},[]),Ue=(0,F.useRef)(null),Ge=(0,F.useCallback)(e=>{let t=R.current;if(!t)return!0;if(B(t)||(z.current=!1),!e||z.current)return z.current;let n=t.getBoundingClientRect().top,r=Array.from(t.querySelectorAll(`.computer-messages > :not(.computer-tool-group), .computer-tool-group > .tool-summary, .computer-tool-group .computer-tool`)).find(e=>{let t=e.getBoundingClientRect();return t.height>0&&t.bottom>n});return Ue.current={...r?{node:r}:{},offset:r?.getBoundingClientRect().top??0,top:t.scrollTop,height:t.scrollHeight},!1},[B]),Ke=(0,F.useRef)(new URLSearchParams(location.search).get(`question`)),qe=(0,F.useRef)(null),Je=(0,F.useRef)(void 0),Xe=(0,F.useRef)(a()),Ze=(0,F.useCallback)(async e=>o?(await l.request(`web/local-agent-computers`,fe,{signal:e})).computers.map(e=>({...e,project:l.projectId})):[],[l,o]),V=r(Ze,3e3),$e=(V.data??[]).flatMap(e=>e.directories.map(t=>({c:e,d:t,label:ve(V.data??[],e,t)}))).sort((e,t)=>e.label.localeCompare(t.label)),H=V.data?.find(e=>e.project===x.project&&e.directories.some(e=>e.id===x.directory)),U=Ie(l.projectId,o),nt=U.terminals.find(e=>e.id===x.terminal),rt=(0,F.useRef)(nt);nt&&(rt.current=nt);let W=nt??(rt.current?.id===x.terminal?rt.current:void 0),G=H?.directories.find(e=>e.id===x.directory),K=V.data?.find(e=>e.directories.some(e=>e.id===Ae))??H,q=K?.directories.find(e=>e.id===Ae)??G;Se(x.project);let J=(0,F.useCallback)((e,t,n)=>Se(x.project).request(e,t,n),[x.project]),Y=Qe(x.session,x.project,J),X=tt(x.project,o?x.session:``,J,Ge);function st(e){let t=B(e);return t&&!z.current&&(ze.current=ft(e)),z.current=t,X.follow(t),t}let Z=X.data;(0,F.useLayoutEffect)(()=>{z.current=!0,ze.current=null,qe.current=null,Ue.current=null},[x.project,x.session]);let Q=Z?.session,pt=Z?.pendingQuestions??Z?.messages.flatMap(({question:e,seq:t})=>e?.delivery===`async`&&oe(e)?[{id:e.id,seq:t}]:[])??[];function mt(e){let t=R.current,n=document.getElementById(`computer-question-${e}`);return!t||!n||!t.contains(n)||!n.getClientRects().length?!1:(z.current=!1,qe.current=e,t.scrollTop+=n.getBoundingClientRect().top-t.getBoundingClientRect().top-16,n.focus({preventScroll:!0}),!0)}(0,F.useLayoutEffect)(()=>{if(!Q||!R.current)return;let e=R.current;if(Ke.current){let e=Ke.current;if(mt(e)){Ke.current=null,Ue.current=null;return}}let t=Ue.current;Ue.current=null,t&&!z.current?t.node&&e.contains(t.node)?e.scrollTop+=t.node.getBoundingClientRect().top-t.offset:e.scrollTop=t.top+e.scrollHeight-t.height:z.current&&He(e)},[Q?.id,G?.id,Z,He]),(0,F.useLayoutEffect)(()=>{let e=R.current;if(!e||!Q)return;let t=new ResizeObserver(()=>{z.current&&B(e)&&He(e)});return t.observe(e),()=>t.disconnect()},[Q?.id,G?.id,B,He]),(0,F.useEffect)(()=>{H?.online===!1&&X.reload()},[H?.online,X.reload]);let ht=(0,F.useRef)(Z?.messages);(0,F.useLayoutEffect)(()=>{ht.current=Z?.messages},[Z?.messages]);let gt=(0,F.useCallback)(({path:e,line:n})=>{let r=Ce(e,x.terminal?W?.cwd:Q?.cwd);if(!r)return;let i=r.split(`/`).at(-1),a=/\/\.workspace\/\.teammy-attachments\/([0-9a-f-]{36})\/[^/]+$/i.exec(r);if(!x.terminal&&Q&&a){let e=ht.current?.flatMap(e=>e.attachments??[]).find(e=>e.id===a[1]);Pe({...e,name:e?.name??i,line:n,url:Ye(x.project,Q.id,a[1],!0)});return}let o=x.terminal?W?.directory:Q?.executionDirectory??Q?.directory;if(!o)return;let s=t(`/api/v1/projects/${encodeURIComponent(x.project)}/web/local-agents/${encodeURIComponent(o)}/file?${new URLSearchParams({path:r})}`),c=Ve(i);Pe({name:i,line:n,url:s,previewUrl:s+(c.startsWith(`text/`)?`&view=text`:c?``:`&view=info`)})},[x.project,x.terminal,Q?.directory,Q?.executionDirectory,Q?.id,Q?.cwd,W?.directory,W?.cwd]),_t=H?.capabilities.includes(`local-sessions-v1`),$=(e,t,n=``,r=``)=>{Pe(void 0),w({project:e,directory:t,session:n,terminal:r}),f?.set(p,{directory:t,session:n,terminal:r}),M(!1),Oe(!1),T(``);let i=new URL(location.href);(x.session!==n||r)&&(i.searchParams.delete(`question`),Ke.current=null),i.searchParams.delete(`view`),i.searchParams.delete(`section`),i.searchParams.set(`directory`,t),r?i.searchParams.set(`terminal`,r):i.searchParams.delete(`terminal`),n?i.searchParams.set(`session`,n):i.searchParams.delete(`session`),e===l.projectId&&history.replaceState(null,``,i)};(0,F.useEffect)(()=>{let e=V.data?.find(e=>e.sessions.some(e=>e.id===x.session))??V.data?.find(e=>e.directories.length);if(!x.directory&&e?.directories.length){let t=e.directories[0],n=e.sessions.find(e=>e.id===x.session);$(e.project,n?.directory??t.id,n?.id??t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id)}},[V.data]),(0,F.useEffect)(()=>{if(!Q)return;let e=()=>{document.visibilityState===`visible`&&J(`web/local-agent-sessions/${Q.id}/read`,ut,{method:`POST`}).catch(e=>T(i(e)))};return e(),document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[Q?.id,Z?.messages.at(-1)?.seq,J]);async function vt(e){j(!0),T(``);try{await e(),await Promise.all([X.reload(),V.reload()])}catch(e){T(i(e))}finally{j(!1)}}function yt(e,t){return vt(async()=>{if(await l.request(`web/local-agent-sessions/${e.id}/metadata`,pe,{method:`PUT`,body:{expectedRevision:e.metadataRevision,...t}}),t.hidden&&x.session===e.id){let t=H?.sessions.find(t=>t.directory===e.directory&&t.id!==e.id&&!t.hidden);$(x.project,e.directory,t?.id)}})}function bt(e){let t=new URLSearchParams({tab:`connect`,directory:e,session:x.session});s(`/projects/${l.projectId}/settings?${t}`)}function xt(e){let t=$e.find(({d:t})=>t.id===e),n=t?.d.provider??`codex`;return ie(n)&&!t?.c.providers.some(e=>e.id===n&&e.available)?`codex`:n}function St(e=x.directory){let t=V.data?.find(t=>t.directories.some(t=>t.id===e))??H,n=t?.directories.find(t=>t.id===e)??t?.directories[0];!n||!t?ce(!0):(Xe.current=a(),Ne(n.id),M(!0),P(xt(n.id)),T(``))}let[Ct,wt]=(0,F.useState)(null);(0,F.useEffect)(()=>wt(null),[Q?.id]);let Tt=H?.catalogs.find(e=>e.provider===(Q?.provider??`codex`)&&(Q?.cwd?e.cwd===Q.cwd:e.directory===(Q?.executionDirectory??Q?.directory))),Et=Tt?.commands??[],Dt=Tt?.models??H?.providers.find(e=>e.id===Q?.provider)?.models??(Q?.provider===`codex`?H?.models??[]:[]),Ot=Dt.find(e=>e.id===(Q?.config.model??Q?.effectiveConfig?.model)||!!e.resolvedModel&&e.resolvedModel===(Q?.config.model??Q?.effectiveConfig?.model))??(Q?.config.model?void 0:Dt.find(e=>e.isDefault)),kt=!!H?.capabilities.includes(`local-agent-attachments-v1`),At=!!(Ot?.images??(!Q?.config.model&&H?.providers.find(e=>e.id===Q?.provider)?.defaultImages))&&!!H?.capabilities.includes(`local-agent-images-v1`),jt=Q?.state===`working`&&!Z?.commands.some(e=>e.kind===`stop`&&[`queued`,`running`].includes(e.state)),Mt=(Q?.provider===`cursor`||ie(Q?.provider))&&H?.capabilities.includes(`local-agent-steer-v1`),Nt=!H?.capabilities.includes(`local-agent-steer-v1`)&&(Q?.provider===`cursor`||Q?.provider===`claude`);function Pt(e){let t=me.trim();if(!Q||!t&&!Y.files.length)return;let n=Y.files.map(e=>e.id),r=At?Y.files.filter(e=>e.mimeType!==`application/octet-stream`).map(e=>e.id):[],i=Ct?.path&&t.startsWith(`$${Ct.name}`)?[{name:Ct.name,path:Ct.path}]:void 0,o=JSON.stringify({session:Q.id,body:t,skills:i,attachments:n,images:r,delivery:e});Je.current?.fingerprint!==o&&(Je.current={fingerprint:o,id:a()});let s=Je.current;vt(async()=>{await J(`web/local-agent-sessions/${Q.id}/messages`,E(),{method:`POST`,body:{id:s.id,body:t,delivery:e,...r.length?{images:r}:{},...n.length?{attachments:n}:{},...i?{skills:i}:{}}}),he(e=>e.trim()===t?``:e),wt(null),Y.clear(),Je.current===s&&(Je.current=void 0)})}let Ft=(0,F.useMemo)(()=>(0,I.jsx)(it,{onFile:gt,messages:Q?Z.messages:[],rewind:Q?{session:Q.id,available:!!Z?.canRewind&&Q.state===`idle`&&!Q.archived,expectedLastMessage:Z?.messages.at(-1)?.id??``,commands:Z?.commands??[],request:J,refresh:X.reload}:void 0,imageUrl:(e,t)=>Ye(x.project,Q.id,e,t),renderQueue:e=>(0,I.jsx)(et,{message:e}),renderQuestion:e=>(0,I.jsx)(at,{question:e,session:Q.id,request:J,refresh:X.reload})}),[Q,Z,J,X.reload,x.project,gt]);return(0,I.jsxs)(Ee,{className:`computers-layout`,testId:`computers-page`,label:`本地会话`,tree:!0,navigation:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(te,{title:`电脑`}),(0,I.jsx)(`div`,{className:`assistant-message-scroll computer-tree`,role:`tree`,"aria-label":`目录与会话`,onKeyDown:je,children:$e.map(({c:e,d:t,label:n})=>{let r=`${e.project}/${t.id}`,i=!_.has(r);return(0,I.jsxs)(`div`,{role:`none`,children:[(0,I.jsxs)(`div`,{className:`computer-tree-row`,role:`none`,children:[(0,I.jsxs)(A,{className:`tree-item tree-folder`,role:`treeitem`,"aria-level":1,"aria-expanded":i,style:{"--tree-level":1},leading:(0,I.jsx)(`span`,{className:`tree-chevron ${i?`expanded`:``}`,children:(0,I.jsx)(u,{name:`chevron`,size:`small`})}),onClick:()=>{x.directory!==t.id&&$(e.project,t.id,t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id),y(e=>{let t=new Set(e);return i?t.add(r):t.delete(r),t})},children:[(0,I.jsx)(u,{name:`files`}),(0,I.jsx)(`span`,{className:`tree-name`,title:n,children:n})]}),(0,I.jsx)(v,{icon:`plus`,label:`新建会话:${n}`,className:`computer-tree-action`,onClick:()=>St(t.id)})]}),i&&(0,I.jsxs)(`div`,{role:`group`,children:[U.terminals.filter(e=>e.directory===t.id).map(n=>(0,I.jsx)(`div`,{className:`computer-tree-row computer-session-row computer-terminal-row`,role:`none`,children:(0,I.jsxs)(A,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":x.terminal===n.id,style:{"--tree-level":2},leading:(0,I.jsx)(`span`,{className:`tree-chevron`}),onClick:()=>$(e.project,t.id,``,n.id),children:[(0,I.jsx)(u,{name:`command`}),(0,I.jsxs)(`span`,{className:`computer-session-copy`,children:[(0,I.jsx)(`span`,{className:`tree-name`,children:n.title}),(0,I.jsx)(`time`,{dateTime:n.createdAt,children:n.state===`exited`?`已退出`:Re(n.createdAt,Fe)})]})]})},n.id)),e.sessions.filter(e=>e.directory===t.id).map(n=>(0,I.jsxs)(`div`,{className:`computer-tree-row computer-session-row`,role:`none`,children:[(0,I.jsxs)(A,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":x.session===n.id&&x.project===e.project,style:{"--tree-level":2},leading:(0,I.jsx)(`span`,{className:`tree-chevron`,children:(0,I.jsx)(`span`,{className:`assistant-message-dot ${n.unread?`unread`:``}`})}),title:`${n.title} · ${xe[n.provider]}`,onClick:()=>$(e.project,t.id,n.id),children:[(0,I.jsx)(se,{provider:n.provider}),(0,I.jsxs)(`span`,{className:`computer-session-copy`,children:[(0,I.jsx)(`span`,{className:`tree-name`,children:n.title}),(0,I.jsx)(`time`,{dateTime:n.updatedAt,title:new Date(n.updatedAt).toLocaleString(),children:Re(n.updatedAt,Fe)})]})]}),(0,I.jsx)(v,{icon:`link`,className:`computer-tree-action computer-session-pin${n.pinned?` pinned`:``}`,label:`${n.pinned?`取消自动接单`:`开启自动接单`}:${n.title}`,"aria-pressed":n.pinned,tooltip:n.pinned?`取消自动接单`:`开启自动接单`,disabled:O||n.archived,onClick:()=>void yt(n,{pinned:!n.pinned})}),n.archived?(0,I.jsx)(`span`,{title:`已归档`,role:`img`,"aria-label":`已归档`,children:(0,I.jsx)(u,{name:`archive`,size:`small`})}):n.state!==`idle`&&(0,I.jsx)(we,{state:n.state,label:dt[n.state]??n.state})]},n.id))]})]},t.id)})}),(0,I.jsx)(D,{resource:V})]}),children:[ne&&(0,I.jsx)(ae,{onClose:()=>ce(!1)}),De&&K&&q&&(0,I.jsx)(Be,{directory:q.id,provider:N===`terminal`?q.provider:N,providers:K.providers.filter(e=>!ie(e.id)||e.available).map(e=>e.id),sessions:K.sessions,request:J,onClose:()=>Oe(!1),onImport:e=>{$(x.project,e.directory,e.id),V.reload()}}),be&&q&&(0,I.jsx)(d,{id:`computer-new-session`,title:`新建会话`,onClose:()=>M(!1),children:(0,I.jsxs)(`form`,{className:`computer-panel stack`,onSubmit:e=>{e.preventDefault(),vt(async()=>{if(N===`terminal`){let e=Xe.current;await U.request({type:`create`,id:e,directory:q.id,title:_e.trim(),cols:100,rows:28}),Xe.current=a(),ye(``),$(x.project,q.id,``,e);return}let e=await J(`web/local-agents/${q.id}/sessions`,pe,{method:`POST`,body:{id:Xe.current,title:_e,provider:N}});Xe.current=a(),M(!1),ye(``),$(x.project,q.id,e.id)})},children:[$e.length>1?(0,I.jsx)(re,{title:`执行目录`,children:(0,I.jsx)(`select`,{"aria-label":`执行目录`,disabled:O,value:q.id,onChange:e=>{Ne(e.target.value),P(xt(e.target.value))},children:$e.map(({d:e,label:t})=>(0,I.jsx)(`option`,{value:e.id,children:t},e.id))})}):(0,I.jsxs)(`p`,{className:`muted computer-create-scope`,children:[`目录:`,q.name]}),(0,I.jsxs)(`label`,{children:[`会话名称`,(0,I.jsx)(`input`,{autoFocus:!0,required:!0,disabled:O,placeholder:`会话名称`,value:_e,onChange:e=>ye(e.target.value)})]}),(0,I.jsx)(ge,{label:`会话类型`,value:N,onChange:P,disabled:O,providers:le.options.filter(e=>e===`codex`||(e===`claude`?K?.capabilities.includes(`local-agent-providers-v1`):K?.providers.some(t=>t.id===e&&(!ie(e)||t.available)))),terminal:U.directories.includes(q.id)}),N===`terminal`&&(0,I.jsx)(`p`,{className:`muted computer-create-scope`,children:`在此目录启动本机 Shell,使用本机用户权限。`}),(0,I.jsx)(C,{children:K?.providers.find(e=>e.id===N)?.error}),(0,I.jsxs)(`div`,{className:`computer-create-options`,children:[N!==`terminal`&&(0,I.jsx)(`button`,{type:`button`,disabled:!K?.online||!K.capabilities.includes(`local-agent-history-v1`),onClick:()=>{M(!1),Oe(!0)},children:`导入历史会话`}),(0,I.jsx)(`button`,{type:`button`,onClick:()=>{M(!1),ce(!0)},children:`接入目录`}),(0,I.jsx)(`button`,{className:`primary`,disabled:O||!_e.trim()||(N===`terminal`?!U.directories.includes(q.id):!_t),children:`创建`})]})]})}),L&&(0,I.jsx)(We,{file:L,onClose:()=>Pe(void 0)},L.url),x.terminal?W?(0,I.jsx)(F.Suspense,{fallback:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ee,{title:W.title}),(0,I.jsx)(`div`,{className:`assistant-empty`,children:`正在打开终端…`})]}),children:(0,I.jsx)(lt,{terminal:W,onFile:gt,connection:U,onClosed:()=>$(x.project,x.directory)},W.id)}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ee,{title:`终端`}),(0,I.jsx)(`div`,{className:`assistant-empty`,children:U.connected?`终端已结束或电脑已重启,请新建终端。`:`正在连接终端…`})]}):G?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ee,{title:Q?(0,I.jsx)(Me,{title:Q.title,busy:O,onSave:e=>yt(Q,{title:e})},Q.id):(0,I.jsx)(`h2`,{children:G.name}),actions:(0,I.jsx)(I.Fragment,{children:(0,I.jsx)(S,{id:`computer-session-menu`,triggerId:`computer-session-actions`,label:`会话操作`,trigger:(0,I.jsx)(u,{name:`more`}),className:`computer-create-menu`,routeKey:Q?.id??``,disabled:!Q,children:e=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{role:`menuitem`,disabled:O,onClick:()=>{e(),Q&&yt(Q,{hidden:!0})},children:`隐藏会话`}),(0,I.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),bt(G.id)},children:`连接专用群`}),(0,I.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),bt(G.id)},children:`执行位置`})]})})})}),!_t&&(0,I.jsx)(b,{children:`升级客户端后可使用多个会话和网页对话。`}),(0,I.jsxs)(Te,{ref:R,onClickCapture:({target:e,currentTarget:t})=>{e instanceof Element&&e.closest(`.tool-summary`)&&(z.current=!1,requestAnimationFrame(()=>{t===R.current&&t.contains(e)&&st(t)}))},onWheel:e=>{e.deltaY<0&&e.currentTarget.scrollTop<=0&&Z?.olderBefore&&(z.current=!1,X.older())},onScroll:e=>{let t=e.currentTarget;!st(t)&&t.scrollTop<100&&Z?.olderBefore&&X.older()},"aria-label":`本地会话记录`,children:[Z?.olderBefore&&(0,I.jsx)(`button`,{type:`button`,className:`computer-older`,disabled:X.loadingOlder,onClick:()=>{z.current=!1,X.older()},children:X.loadingOlder?`正在加载…`:`加载更早消息`}),(0,I.jsx)(D,{resource:X}),Ft,(0,I.jsx)(C,{children:Q?.error}),Z&&!Z.messages.length&&!Z.olderBefore&&(0,I.jsx)(`div`,{className:`assistant-empty`,children:Q?.resumeSession?`已接入原生会话,发送消息继续。`:`在当前目录开始一段对话。`})]}),Z?.commands.filter(e=>e.state!==`succeeded`&&![`diff`,`history`,`rewind`].includes(e.kind)&&!(e.kind===`stop`&&[`queued`,`running`].includes(e.state))).slice(-3).map(e=>(0,I.jsxs)(`p`,{className:`computer-control-status`,role:`status`,children:[e.kind===`stop`?`停止`:e.kind,` · `,dt[e.state]??e.state,e.error?`:${e.error}`:``]},e.id)),pt.length>0&&(0,I.jsx)(`div`,{className:`computer-question-shortcut`,children:(0,I.jsxs)(`button`,{type:`button`,onClick:()=>{let e=(pt.findIndex(e=>e.id===qe.current)+1)%pt.length,t=pt[e];mt(t.id)||(z.current=!1,Ke.current=t.id,X.reveal(t.seq))},children:[(0,I.jsx)(u,{name:`question`,size:`small`}),`有 `,pt.length,` 个问题等待你的确认`]})}),Q&&(0,I.jsx)(ke,{value:me,onChange:he,label:`向本地 Agent 发送消息`,sendLabel:jt?Mt?`中断并发送`:Nt?`加入队列`:`插话`:`发送`,onQueue:[`working`,`waiting`].includes(Q.state)&&H?.capabilities.includes(`local-agent-queue-v1`)?()=>Pt(`queue`):void 0,placeholder:Q.archived?`会话已归档`:`输入消息…`,disabled:Q.archived||!_t,sendDisabled:O||Y.busy||Y.failed||Y.count>0&&!kt||Z?.commands.some(e=>e.kind===`rewind`&&[`queued`,`running`,`uncertain`].includes(e.state)),attachments:(0,I.jsxs)(I.Fragment,{children:[Y.preview(O),Y.files.some(e=>e.mimeType!==`application/octet-stream`)&&!At&&(0,I.jsx)(b,{children:`当前模型将通过本地文件路径接收图片。`})]}),hasAttachments:Y.count>0,onFiles:kt&&!O?e=>void Y.add(e):void 0,beforeSend:(0,I.jsx)(ot,{session:Q.id,active:[`working`,`waiting`].includes(Q.state),commands:Z?.commands??[],request:J,refresh:X.reload,onError:T},Q.id),actions:(0,I.jsxs)(I.Fragment,{children:[kt?Y.picker(O||!_t,At):At?(0,I.jsx)(`span`,{title:`更新开发机客户端后可添加附件`,children:(0,I.jsx)(`button`,{type:`button`,className:`icon-button`,disabled:!0,"aria-label":`更新开发机客户端后可添加附件`,children:(0,I.jsx)(u,{name:`attachment`,size:`small`})})}):null,(0,I.jsx)(ct,{session:Q,models:Dt,busy:O,available:!!_t,online:!!H?.online,commands:Et,controls:Tt?.controls,draft:me,onInsert:e=>{wt(e.kind===`skill`?e:null),he(`${e.prefix??(e.kind===`skill`?`$`:`/`)}${e.name} `),requestAnimationFrame(()=>document.querySelector(`.message-composer textarea`)?.focus())},onConfig:e=>{vt(()=>J(`web/local-agent-sessions/${Q.id}/settings`,pe,{method:`PUT`,body:{expectedRevision:Q.revision,config:e}}))}})]}),onSubmit:()=>Pt(`auto`)})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ee,{title:`本地会话`}),(0,I.jsxs)(`div`,{className:`assistant-empty`,children:[`尚未登记本地执行目录。`,(0,I.jsx)(`button`,{onClick:()=>ce(!0),children:`接入目录`})]})]})]})}export{Q as Computers,Me as t};
@@ -1 +0,0 @@
1
- .combobox-field{position:relative}.combobox-field input{text-overflow:ellipsis;padding-right:44px}.combobox-field .icon-button{color:var(--color-muted);position:absolute;top:50%;right:6px;transform:translateY(-50%)}.combobox-popup{z-index:10;border:1px solid var(--color-line);border-radius:var(--radius-md);background:var(--color-surface);box-shadow:var(--shadow-menu);flex-direction:column;padding:5px;display:flex;position:fixed}.combobox-popup [role=listbox]{min-height:0;overflow:auto}button.combobox-option{border-radius:var(--radius-sm);text-align:left;border:0;gap:12px;width:100%;min-height:42px;padding:8px 10px;font-weight:400}.combobox-option.active,.combobox-option[aria-selected=true]{background:var(--color-hover)}.combobox-option-copy{flex-direction:column;flex:1;min-width:0;display:flex}.combobox-option-copy>*{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.combobox-option-copy small,.combobox-option-detail,.combobox-message{color:var(--color-muted);font-size:var(--text-xs)}.combobox-option-detail{flex-shrink:0}.combobox-message{margin:0;padding:10px}.combobox-footer{justify-content:flex-end;align-items:center;gap:8px;padding:4px 4px 0;display:flex}.native-history{flex-direction:column;gap:20px;display:flex}.native-history-input-row{align-items:center;gap:10px;display:flex}.native-history>small{font-size:var(--text-xs)}button.native-history-more{min-height:30px;font-size:var(--text-xs);color:var(--color-muted);border:0;padding:3px 8px}.native-history-input-row .combobox{flex:1;min-width:0}.session-images{flex-wrap:wrap;gap:8px;padding:6px 0;display:flex}.session-image{width:112px;position:relative}.session-image-preview{border:1px solid var(--color-line);background:var(--color-soft);width:112px;height:88px;color:var(--color-muted);border-radius:8px;place-items:center;padding:0;display:grid;overflow:hidden}.session-image-preview img{object-fit:cover;width:100%;height:100%;display:block}.session-image-remove,.session-image-status{background:var(--color-surface);width:24px;height:24px;min-height:24px;color:var(--color-muted);border:0;border-radius:50%;place-items:center;padding:3px;display:grid;position:absolute}.session-image-remove{top:4px;right:4px}.session-image-status{top:60px;left:4px}.session-image-status[role=status] .icon{animation:1.2s linear infinite image-upload-spin}@keyframes image-upload-spin{to{transform:rotate(360deg)}}@media (prefers-reduced-motion:reduce){.session-image-status[role=status] .icon{animation:none}}.session-image-error{color:var(--color-muted);font-size:var(--text-xs);overflow-wrap:anywhere;padding-top:4px;display:block}.session-image-file{display:none}.composer-attachments{flex-shrink:0}.composer-menu.composer-attachments .dropdown-trigger{background:0 0;border-radius:50%;width:32px;height:32px;padding:7px}.composer-menu.composer-attachments .dropdown-menu{width:180px}.composer-menu.composer-attachments .dropdown-menu [role=menuitem]{justify-content:flex-start;gap:8px}#session-image-lightbox{width:min(1100px,94vw);max-width:94vw}#session-image-lightbox .dialog-header{margin-bottom:var(--space-3);gap:4px}#session-image-lightbox .dialog-header h2{text-overflow:ellipsis;white-space:nowrap;min-width:0;font-size:var(--text-sm);flex:1;overflow:hidden}.session-image-viewer{outline:none;min-width:0}.file-preview-text,.file-preview-document,.session-image-viewer .html-preview{max-height:70dvh;overflow:auto}.file-preview-document,.session-image-viewer .html-preview{border:0;width:100%;height:70dvh}.file-preview-text{padding:8px}.file-preview-text .raw{white-space:pre-wrap;overflow-wrap:anywhere}.file-preview-text mark{background:var(--color-soft);color:inherit;outline:1px solid var(--color-line)}.file-preview-empty{color:var(--color-muted);text-align:center;padding:32px 0}.computer-file-link,.markdown .computer-file-link{min-height:0;color:inherit;font:inherit;text-align:inherit;text-decoration:underline;-webkit-text-decoration-color:var(--color-muted);text-decoration-color:var(--color-muted);text-underline-offset:3px;overflow-wrap:anywhere;cursor:pointer;background:0 0;border:0;border-radius:0;padding:0;display:inline}#session-image-lightbox .dialog-header small{white-space:nowrap;color:var(--color-muted)}#session-image-lightbox .dialog-header .icon-button{flex-shrink:0;place-items:center;width:30px;height:30px;min-height:30px;padding:6px;display:grid}#session-image-lightbox .dialog-header .icon{stroke-width:1.8px}.session-image-previous .icon{transform:rotate(180deg)}.session-image-stage{background:var(--color-soft);border-radius:8px;justify-content:center;align-items:center;height:min(70dvh,760px);min-height:160px;display:flex;overflow:auto}.session-image-stage img{object-fit:contain;width:auto;max-width:100%;height:auto;max-height:100%}.session-image-stage.original-size{display:block}.session-image-stage.original-size img{max-width:none;max-height:none;margin:auto;display:block}.session-file{width:auto;max-width:100%}.session-file-name{border:1px solid var(--color-line);background:var(--color-soft);max-width:100%;color:inherit;border-radius:8px;align-items:center;gap:6px;padding:6px 10px;display:flex}.session-file-name span,.session-image-unavailable span{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.session-file:has(.session-image-remove) .session-file-name{padding-right:32px}.session-file .session-image-status{top:3px;left:2px}.session-image-unavailable{font-size:var(--text-xs);align-content:center;gap:2px;padding:4px}.execution-status{color:var(--color-muted);vertical-align:middle;align-items:center;display:inline-flex}.execution-status.is-spinning svg{animation:1.2s linear infinite execution-status-spin}@keyframes execution-status-spin{to{transform:rotate(360deg)}}@media (prefers-reduced-motion:reduce){.execution-status.is-spinning svg{animation:none}}.tool-details{min-width:0;color:var(--color-muted);font-size:var(--text-sm);margin:10px 0}.tool-summary{cursor:pointer;align-items:center;gap:8px;min-height:32px;padding:6px 0;list-style:none;display:flex}.tool-details>summary::-webkit-details-marker{display:none}.tool-summary>.icon{flex-shrink:0;width:12px;height:12px}.tool-details[open]>.tool-summary>.icon,.tool-summary[aria-expanded=true]>.icon{transform:rotate(90deg)}.tool-details-label{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.tool-details-status{font-size:var(--text-xs);flex-shrink:0;gap:6px;display:flex}.tool-details pre{border-left:1px solid var(--color-line);background:var(--color-soft);border-radius:0 var(--radius-sm) var(--radius-sm) 0;white-space:pre-wrap;overflow-wrap:anywhere;max-height:320px;font-size:var(--text-xs);margin:4px 0 14px 20px;padding:12px 16px;line-height:1.65;overflow:auto}.computer-messages{width:100%;max-width:820px;margin:0 auto}.computer-user-entry{margin:16px 0}.computer-user-entry .assistant-bubble-row{margin-bottom:0}.computer-message-actions{opacity:0;justify-content:flex-end;gap:4px;padding-top:4px;transition:opacity .12s;display:flex}.computer-user-entry:hover .computer-message-actions,.computer-user-entry:focus-within .computer-message-actions{opacity:1}.computer-message-actions .icon-button,.computer-message-edit-footer .icon-button{width:28px;height:28px;min-height:28px;color:var(--color-muted);padding:6px}.computer-message-actions .icon{width:14px;height:14px}.computer-user-entry.editing .assistant-bubble{width:min(100%,640px)}.computer-message-edit textarea{resize:none;background:var(--color-surface);width:100%;min-height:40px;max-height:240px;line-height:1.7}.computer-message-edit-footer{align-items:center;gap:6px;margin-top:8px;display:flex}.computer-message-edit-footer small{color:var(--color-muted);font-size:var(--text-xs);margin-right:auto}@media (hover:none){.computer-message-actions{opacity:1}}.computer-agent-message{overflow-wrap:anywhere;min-width:0;margin:24px 0}.question-bubble:empty{display:none}.question-bubble{border-radius:var(--radius-lg)}.computer-agent-message .markdown{font-size:var(--text-base);line-height:1.8}.computer-agent-message .markdown>:first-child{margin-top:0}.computer-agent-message .markdown>:last-child{margin-bottom:0}.computer-agent-message .markdown :is(h1,h2){font-size:18px}.computer-agent-message .markdown :is(h3,h4,h5,h6){font-size:var(--text-base)}.computer-agent-message .markdown pre{max-width:100%;overflow-x:auto}.computer-commentary{margin:20px 0}.computer-tool-group>button{width:100%;color:inherit;font:inherit;text-align:start;background:0 0;border:0;justify-content:flex-start}.computer-tool-group>button:hover{color:var(--color-text)}.computer-tool-list{border-inline-start:1px solid var(--color-line);margin-inline-start:6px;padding-inline-start:12px}.computer-tool-list .computer-tool{margin:0}.computer-divider{color:var(--color-muted);font-size:var(--text-xs);text-align:center;align-items:center;gap:14px;margin:28px 0;line-height:1.6;display:flex}.computer-divider:before,.computer-divider:after{content:"";border-top:1px solid var(--color-line);flex:1;min-width:16px}.computer-divider>span{overflow-wrap:anywhere;max-width:80%}.inline-reply{width:clamp(180px, var(--reply-width,180px), 600px);border:1px solid var(--color-line);border-radius:var(--radius-sm);background:0 0;align-items:flex-end;gap:4px;max-width:100%;padding:3px 6px;display:flex}.inline-reply:focus-within{border-color:var(--color-input-focus)}.inline-reply textarea{width:100%;min-width:0;min-height:28px;max-height:180px;font-size:var(--text-sm);resize:none;box-shadow:none;background:0 0;border:0;padding:3px 2px;line-height:22px}.inline-reply textarea:focus{box-shadow:none;outline:none}.inline-reply-send{background:0 0;border:0;flex:0 0 26px;place-items:center;width:26px;height:28px;min-height:28px;padding:3px;display:grid}.native-question{grid-template-columns:minmax(0,1fr);gap:12px;min-width:0;display:grid}.native-question>*{min-width:0}.native-question-pending{border:1px solid color-mix(in srgb, var(--brand-orange) 13%, var(--color-line));border-radius:var(--radius-lg);background:color-mix(in srgb, var(--color-accent-soft) 20%, var(--color-surface));padding:14px 16px;box-shadow:0 2px 7px #16161508}.native-async-answer{color:var(--color-muted);font-size:var(--text-sm)}.native-question-part{grid-template-columns:minmax(0,1fr);justify-items:start;gap:8px;min-width:0;display:grid}.native-question-part>p{color:var(--color-text);font-size:var(--text-base);margin:0}.question-options,.question-actions{flex-wrap:wrap;align-items:stretch;gap:8px;max-width:100%;display:flex}.question-options button,.question-actions>button{min-height:var(--control-height);margin:0;line-height:20px}.question-options button{text-align:left;min-width:0;max-width:100%;height:36px;min-height:36px;font-size:var(--text-sm);white-space:nowrap;flex-shrink:1;justify-content:flex-start;align-items:center;gap:6px;padding:6px 10px;font-weight:400;display:flex}.question-options button[aria-pressed=true]{border-color:var(--brand-orange);background:var(--color-accent-soft);color:var(--color-link)}.question-option-description,.question-option-separator{color:var(--color-muted);font-size:inherit}.question-option-description{text-overflow:ellipsis;min-width:0;overflow:hidden}.question-option-separator{flex-shrink:0}.question-option-label{flex-shrink:0;align-items:center;gap:8px;max-width:100%;display:flex;overflow:hidden}.question-check{border:1px solid;border-radius:3px;flex:0 0 14px;justify-content:center;align-items:center;width:14px;height:14px;display:inline-flex}.question-check .icon{width:12px;height:12px}.question-response,.question-result{align-items:baseline;gap:6px;display:flex}.question-response span{white-space:pre-wrap;overflow-wrap:anywhere}.question-result{color:var(--color-muted);font-size:var(--text-xs)}.question-response .icon,.question-result .icon{width:12px;height:12px;color:var(--color-muted);flex-shrink:0}.native-approval-row{flex-wrap:wrap;align-items:flex-start;gap:8px 16px;display:flex}.native-approval-details{flex:240px;margin:0}.native-approval-options{align-items:center;gap:8px;display:flex}.native-approval-options button{min-width:64px;min-height:32px;font-size:var(--text-xs);white-space:nowrap;border-radius:999px;padding:4px 12px;line-height:22px}.native-approval-options button span{font-variant-numeric:tabular-nums;margin-left:2px}.native-approval-row>.question-result{align-self:center}@media (pointer:coarse){.native-approval-options button{min-height:44px}}.native-plan{border:1px solid var(--color-line);border-radius:12px;gap:16px;padding:18px 20px}.native-plan-heading{color:var(--color-muted);font-size:var(--text-sm);align-items:center;gap:8px;display:flex}.native-plan-content{overscroll-behavior:contain;scrollbar-width:thin;min-height:0;max-height:min(480px,50dvh);overflow:auto}.native-plan .markdown :is(h1,h2){font-size:var(--text-lg);margin:18px 0 10px}.native-plan .markdown>:first-child{margin-top:0}.native-plan-history summary{cursor:pointer;color:var(--color-muted)}.native-plan-history[open] summary{margin-bottom:16px}.native-plan-actions{grid-template-columns:repeat(3,minmax(0,1fr));grid-auto-rows:1fr;width:min(100%,360px);display:grid}.native-plan-actions-expanded{grid-template-columns:repeat(2,minmax(0,1fr))}.native-plan-actions>button{min-width:0;padding:10px 8px}.native-plan-note{font-size:var(--text-xs);margin-top:-8px;line-height:1.6}.native-plan-feedback{gap:10px;display:grid}.native-plan-feedback label{font-size:var(--text-sm);gap:6px;display:grid}.native-plan-feedback textarea{width:100%;min-height:96px;font-size:var(--text-base)}.native-plan-feedback-actions{grid-template-columns:repeat(2,minmax(0,1fr));width:min(100%,280px);display:grid}.native-plan-feedback-actions>button{min-width:0;padding:10px 8px}@media (width<=600px){.native-plan{padding:12px}.native-plan-content{max-height:240px}}.composer-menu .dropdown-trigger{height:30px;min-height:30px;font-size:var(--text-xs);color:var(--color-muted);background:var(--color-soft);border-radius:18px;align-items:center;gap:4px;max-width:min(190px,100%);padding:5px 9px;display:flex}.composer-menu .dropdown-trigger>span{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.composer-menu .dropdown-trigger:hover,.composer-menu .dropdown-trigger[aria-expanded=true]{color:var(--color-text);background:var(--color-hover)}.composer-commands .dropdown-trigger{background:var(--color-soft);border-radius:50%;justify-content:center;width:30px;padding:6px}.composer-menu .dropdown-menu{--dropdown-max-height:45dvh;width:300px;max-width:calc(100vw - var(--sidebar-width) - 32px);max-height:45dvh;top:auto;bottom:calc(100% + 12px)}.composer-menu .dropdown-menu [role=menuitem]{font-size:var(--text-sm);justify-content:space-between;gap:12px;padding:10px}.composer-option-copy{text-align:left;flex-direction:column;gap:3px;min-width:0;display:flex}.composer-option-copy small,.composer-menu-heading small{font-size:var(--text-xs);color:var(--color-muted);font-weight:400}.composer-menu code{color:var(--color-muted);background:0 0;font-size:11px}.composer-menu-heading{font-size:var(--text-sm);justify-content:space-between;gap:12px;padding:8px 10px;display:flex}@media (width<=600px){.composer-menu .dropdown-menu{width:calc(100vw - var(--sidebar-width) - 16px);max-width:none}.composer-menu .dropdown-trigger{max-width:min(140px,100%)}}.composer-choice{flex:0 auto;min-width:0}.composer-commands{flex-shrink:0}.composer-commands .icon{width:17px;height:17px}.composer-commands .dropdown-menu{width:640px}.composer-commands .dropdown-menu [role=menuitem]{padding:8px 10px}.composer-command-row{align-items:center;gap:20px;width:100%;min-width:0;display:flex}.composer-command-name{flex:0 190px;min-width:0}.composer-command-row small{min-width:0;color:var(--color-muted);font-weight:400;font-size:var(--text-xs);flex:1}.composer-command-row>*{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}@media (width<=600px){.composer-commands .dropdown-menu{width:calc(100vw - var(--sidebar-width) - 16px)}.composer-command-name{flex-basis:42%}.composer-command-row{gap:10px}}.composer-option-copy small{text-overflow:ellipsis;white-space:nowrap;max-width:260px;overflow:hidden}@media (width<=600px){.computers-layout .message-composer-actions{flex-wrap:wrap;row-gap:8px}.computers-layout .message-composer-footer{align-items:flex-end}}.computer-panel{border-bottom:1px solid var(--color-line);max-height:55vh;padding:16px 24px;overflow:auto}.computer-control-status{margin:0;padding:4px 24px;font-size:12px}@media (width<=760px){.computer-panel{padding:12px}}.computer-tree .tree-name{flex:1}.computer-panel{flex-shrink:0}.computers-layout dialog .computer-panel{border:0;max-height:70dvh;padding:0}.computer-create-menu .dropdown-trigger{place-items:center;width:32px;height:32px;padding:4px;display:grid}.computer-create-menu .dropdown-menu{width:180px;left:auto;right:0}.session-rename{min-height:0;font:inherit;font-weight:inherit;text-align:left;text-overflow:ellipsis;white-space:nowrap;background:0 0;border:0;border-radius:0;max-width:100%;padding:0;display:block;overflow:hidden}.session-rename:hover{color:var(--color-muted);background:0 0}.session-title-form{flex:1;min-width:0;margin-right:16px}.session-title-form input{width:100%}.computers-layout :is(.message-composer,.computer-question-shortcut){align-self:center;width:calc(100% - 56px);max-width:844px}.computer-question-shortcut{flex:none;margin-bottom:4px}.computer-question-shortcut button{min-height:28px;color:var(--color-muted);font-size:var(--text-xs);background:0 0;border:0;align-items:center;gap:6px;padding:2px 4px;font-weight:400;display:inline-flex}.computer-question-shortcut button:hover{background:var(--color-soft)}.computer-question-shortcut .icon{stroke-width:1.6px;width:14px;height:14px}.computers-layout .message-composer :is(.message-composer-actions,.session-images) .icon>*{vector-effect:non-scaling-stroke;stroke-width:1.6px}@media (width<=900px){.computers-layout :is(.message-composer,.computer-question-shortcut){width:calc(100% - 32px)}}@media (width<=600px){.computers-layout :is(.message-composer,.computer-question-shortcut){width:calc(100% - 16px)}}.computer-session-copy{flex-direction:column;flex:1;align-items:flex-start;gap:3px;min-width:0;padding:3px 0;display:flex}.computer-session-copy .tree-name{max-width:100%}.computer-session-copy time{color:var(--color-muted);font-size:var(--text-xs);font-weight:400;line-height:1.3}.computer-tree-row{align-items:center;min-width:0;display:flex}.computer-tree-row>.tree-item{flex:1;min-width:0}.computer-tree-action.icon-button{opacity:0;width:26px;height:26px;min-height:26px;color:var(--color-muted);margin-right:4px;padding:5px}.computer-tree-action.pinned,.computer-tree-row:hover>.computer-tree-action,.computer-tree-row:focus-within>.computer-tree-action{opacity:1}@media (hover:none){.computer-tree-action.icon-button{opacity:1}}.computer-session-row>.tree-item{flex:0 auto;width:auto;max-width:calc(100% - 28px)}.computer-session-pin.icon-button{align-self:flex-start;width:24px;height:24px;min-height:24px;margin:9px 0 0 -8px;padding:6px}.computer-session-pin .icon{width:12px;height:12px}.computer-session-pin:hover{color:var(--color-text)}.computer-navigation{flex-shrink:0;padding:4px}.computer-create-options{flex-wrap:wrap;align-items:center;gap:8px;display:flex}.computer-create-options>button:not(.primary){color:var(--color-muted);background:0 0;border-color:#0000;padding-inline:8px}.computer-create-options>.primary{margin-left:auto}@media (width<=680px){.computers-layout{grid-template-rows:clamp(140px,32dvh,280px) minmax(0,1fr)}}.computer-create-scope{font-size:var(--text-sm);margin:0}.computer-older{color:var(--color-muted);font:inherit;font-size:var(--text-xs);cursor:pointer;background:0 0;border:0;margin:0 auto 16px;padding:4px 10px;display:block}.computer-older:hover{color:var(--color-text)}
@@ -1 +0,0 @@
1
- import{At as e,C as t,D as n,M as r,V as i,b as a,c as o,g as s,j as c,k as l,kt as u,l as d,o as f,ot as p,v as m}from"./Dropdown-DXEtBxVr.js";import{B as h,M as g,N as _,P as v}from"./index-Rry2cw7w.js";import{r as y}from"./task-links-BJwIQ3SE.js";import{t as b}from"./Markdown-nuwEQZ64.js";import{a as x,i as S,l as C,n as w,o as T,s as E,t as D}from"./WorkspaceTree-DmSApj8i.js";import{t as O}from"./file-links-Bo7XBz3i.js";var k=u(),A=c();function j(e,t){let n=t.split(`/`).slice(0,-1);return n.map((t,r)=>w(e,n.slice(0,r+1).join(`/`))).concat(w(e,``))}function M({members:o,onRefresh:s}){let{api:c,projectId:l}=h(),[u,g]=(0,k.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`owner`),n=p.safeParse(e.get(`path`));return t&&(E(t)||o.some(e=>e.id===t))&&n.success&&!T(n.data)?{owner:t,path:n.data}:void 0}),[b,C]=(0,k.useState)(()=>new Set(u?j(u.owner,u.path):[])),[M,F]=(0,k.useState)(()=>u?{...u,kind:`file`}:void 0),[I,L]=(0,k.useState)(0),R=t(),[z,B]=(0,k.useState)(()=>{let e=new URLSearchParams(location.search);return!u&&(e.has(`owner`)||e.has(`path`))?`文件链接不完整或目标已不可用。`:``}),V=(0,k.useCallback)(async e=>{if(u)try{return{owner:u.owner,...await c.file(u.owner,u.path,void 0,e)}}catch(e){throw e instanceof r&&e.code===`FILE_NOT_FOUND`?new r(e.code,`找不到这个文件,可能已被删除或移动。`,e.status):e}},[c,u?.owner,u?.path]),H=n(V),U=H.data?.owner===u?.owner&&H.data?.file.path===u?.path?H.data:void 0;function W(e,t){let n=t.split(`/`).filter(Boolean);C(t=>{let r=new Set(t);for(let t=0;t<=n.length;t++)r.add(w(e,n.slice(0,t).join(`/`)));return r})}function G(t,n){R(``),B(``),W(t,n.split(`/`).slice(0,-1).join(`/`)),g({owner:t,path:n}),F({owner:t,path:n,kind:`file`}),history.replaceState(null,``,e(y(l,t,n)))}function K(t){if(!u)return!1;R(``);let n=O(E(u.owner)?u.path:`${u.owner}/${u.path}`,t);if(!n)return!/^[a-z][a-z0-9+.-]*:/i.test(t)&&!t.startsWith(`//`)&&(R(`该链接超出工作区,请在原仓库查看。`),!0);if(T(n.path))return R(`配置文件不在文件浏览中显示。`),!0;if(x(n.path))return location.assign(e(`/projects/${l}/memory`)),!0;let[r,...i]=n.path.split(`/`),a=o.some(e=>e.id===r),s=a?r:S,c=a?i.join(`/`):n.path;return B(``),n.directory?(W(s,c),F({owner:s,path:c,kind:`directory`})):s===u.owner&&c===u.path?n.anchor&&[...document.querySelectorAll(`.markdown h1,.markdown h2,.markdown h3,.markdown h4`)].find(e=>e.textContent?.trim().toLowerCase().replace(/\s+/g,`-`)===n.anchor.toLowerCase())?.scrollIntoView({block:`center`}):G(s,c),!0}return(0,A.jsx)(_,{"data-testid":`file-browser`,label:`文件资源管理器`,navigation:(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(v,{title:`工作区`,children:(0,A.jsx)(d,{icon:`refresh`,label:`刷新文件`,"data-testid":`files-refresh`,onClick:()=>{B(``),L(e=>e+1),H.reload(),s()}})}),(0,A.jsx)(D,{members:o,expanded:b,selected:M,revealed:!H.loading&&!H.error&&U?{owner:U.owner,path:U.file.path,file:U.file}:void 0,onSelect:G,onToggle:(e,t)=>{F({owner:e,path:t,kind:`directory`}),C(n=>{let r=new Set(n),i=w(e,t);return r.has(i)?r.delete(i):r.add(i),r})}},I)]}),children:(0,A.jsxs)(`section`,{className:`file-detail`,"data-testid":`file-preview`,"data-owner-id":u?.owner,"data-file-path":u?.path,"aria-label":i.filePreview,children:[U&&(0,A.jsx)(a,{message:H.error}),U?(0,A.jsx)(P,{owner:U.owner,file:U.file,onLink:K},`${U.owner}:${U.file.path}:${U.file.sha256}`):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(N,{target:u}),(0,A.jsxs)(`div`,{className:`reader-body`,children:[(0,A.jsx)(m,{announce:!0,retry:H.error?H.reload:void 0,children:z||H.error}),u&&H.loading&&(0,A.jsx)(`p`,{className:`preview-body`,role:`status`,children:i.loading}),!u&&!z&&(0,A.jsx)(f,{mascot:!0,title:`查看工作区文件`,description:i.pickFile})]})]})]})})}function N({target:e,children:t}){let n=e&&(E(e.owner)?`teamcontext`:e.owner);return(0,A.jsx)(g,{title:e?(0,A.jsxs)(`h2`,{className:`file-detail-path`,title:`${n}/${e.path}`,children:[(0,A.jsxs)(`span`,{children:[n,` / `]}),e.path]}):i.filePreview,actions:t})}function P({owner:e,file:t,onLink:r}){let{readTextBlob:c,blobUrl:u,projectId:f}=h(),[p,g]=(0,k.useState)(!1),_=t.size>524288,v=/\.(md|markdown)$/i.test(t.path),y=/\.html?$/i.test(t.path),x=(0,k.useCallback)(e=>_?Promise.resolve(void 0):c(t,e),[t.sha256,t.size,_]),S=n(x,!1,l(f,`file-body`,t.sha256));return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(N,{target:{owner:e,path:t.path},children:(0,A.jsxs)(s,{label:`文件操作`,children:[(v||y)&&(0,A.jsx)(d,{icon:p?`preview`:`code`,label:p?`切换为预览`:`切换为原文`,"data-testid":`file-toggle-raw`,"aria-pressed":p,onClick:()=>g(!p)}),(0,A.jsx)(`a`,{className:`icon-button`,"data-testid":`file-download`,"aria-label":i.download,title:i.download,href:u(t.sha256),download:t.path.split(`/`).at(-1),children:(0,A.jsx)(o,{name:`download`})})]})}),(0,A.jsxs)(`div`,{className:`reader-body`,children:[S.data!==void 0&&(0,A.jsx)(a,{message:S.error}),_?(0,A.jsx)(`div`,{className:`empty`,children:(0,A.jsx)(`p`,{children:i.previewLarge})}):S.error&&S.data===void 0?(0,A.jsx)(`div`,{className:`preview-body`,children:(0,A.jsx)(m,{announce:!0,retry:S.reload,children:S.error})}):S.loading&&S.data===void 0?(0,A.jsx)(`p`,{className:`preview-body`,role:`status`,children:i.loading}):(0,A.jsx)(`div`,{className:`preview-body${y&&!p?` preview-body-html`:``}`,children:y&&!p?(0,A.jsx)(C,{url:u(t.sha256),name:t.path.split(`/`).at(-1)}):v&&!p?(0,A.jsx)(`article`,{className:`markdown`,"data-testid":`file-content`,"data-format":`markdown`,children:(0,A.jsx)(b,{onLink:r,children:S.data??``})}):(0,A.jsx)(`pre`,{className:`raw`,"data-testid":`file-content`,"data-format":`text`,children:S.data})})]})]})}export{M as Files};
@@ -1,6 +0,0 @@
1
- import{At as e,B as t,C as n,Ct as r,D as i,Dt as a,E as o,Et as s,F as c,I as l,M as u,S as d,St as f,Tt as p,V as m,_ as h,_t as g,a as _,at as v,b as y,c as b,ct as x,d as S,dt as C,ft as w,j as T,jt as ee,k as E,kt as D,l as O,mt as k,o as te,p as A,pt as j,s as M,st as N,ut as P,v as ne,vt as F,x as I,yt as L}from"./Dropdown-DXEtBxVr.js";import{B as R,I as z,M as B,N as V,P as H}from"./index-Rry2cw7w.js";import{a as U}from"./task-links-BJwIQ3SE.js";import{n as W,r as G,t as K}from"./Markdown-nuwEQZ64.js";import{t as re}from"./Conversation-C5pZE7z5.js";import{c as ie,l as ae,r as q}from"./WorkspaceTree-DmSApj8i.js";function oe(e){return a(C,e)}var J=D(),se=f().regex(/^R\d{6,}$/),Y=L({name:f().min(1),sha256:N,size:F().int().nonnegative()}),X=p().refine(e=>/^https?:\/\//i.test(e),`Use an HTTP or HTTPS URL.`);L({operationId:s(),title:f().trim().default(``),text:f().optional(),url:X.optional(),originals:j(Y).default([])}).strict().refine(e=>!!e.text?.trim()||!!e.url||e.originals.length>0,`Provide text, a link or a file.`),L({expectedRevision:x,title:f().trim().min(1).optional(),url:X.nullable().optional(),content:f().optional(),summary:f().optional(),sourceVersion:f().optional(),contentDate:f().optional(),originals:j(Y).optional()}).strict();var Z=L({id:se,projectId:f(),title:f(),submittedBy:f(),createdAt:f(),revision:x,source:L({kind:w([`web`,`chat`,`group`]),url:f().nullable(),groupId:f().optional(),messageId:f().optional(),sourceVersion:f().optional(),contentDate:f().optional()}),originals:j(Y),content:f().nullable(),summary:f().nullable(),state:w([`waiting`,`running`,`ready`,`failed`]),error:f().nullable(),url:f()}),ce=L({materials:j(Z),nextCursor:F().nullable()});L({query:f().trim().min(1),scope:w([`all`,`workspace`,`materials`]).default(`all`),materialId:se.optional(),originalHash:N.optional(),after:f().default(``),limit:oe().int().min(1).max(200).default(30)}).strict();var le=L({items:j(L({key:f(),kind:w([`workspace`,`materials`]),title:f(),snippet:f(),url:f(),path:f()})),nextCursor:f().nullable()}),Q=T();function ue(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 de(){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 fe({active:t,onActivate:r,children:a}){let{request:o,projectId:s}=R(),[l,u]=(0,J.useState)(de),[d,f]=(0,J.useState)(l),[p,m]=(0,J.useState)(()=>new Set(l?[l.id]:[])),[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)(``),[y,x]=(0,J.useState)(``),[S,C]=(0,J.useState)(``),[w,T]=(0,J.useState)([]),[D,k]=(0,J.useState)(),[A,j]=(0,J.useState)(!1),M=n(),N=(0,J.useRef)(null),P=(0,J.useCallback)(e=>o(`materials`,ce,{signal:e}),[o]),F=i(P,5e3,E(s,`materials`)),L=(0,J.useCallback)(e=>l?o(`materials/${encodeURIComponent(l.id)}${l.revision?`?revision=${encodeURIComponent(l.revision)}`:``}`,Z,{signal:e}):Promise.resolve(null),[o,l?.id,l?.revision]),V=i(L,5e3),H=V.data?.id===l?.id?V.data:null,U=[...new Map([...w,...F.data?.materials??[],...H?[H]:[]].map(e=>[e.id,e])).values()].sort((e,t)=>t.createdAt.localeCompare(e.createdAt)||t.id.localeCompare(e.id)),W=D===void 0?F.data?.nextCursor:D;function G(t,n=``){r(),u(t),f(t),x(``),C(n),g(!1),m(e=>new Set([...e,t.id])),history.replaceState(null,``,e(`/projects/${s}/materials?${new URLSearchParams({...t})}`))}(0,J.useEffect)(()=>{let e=()=>{if(!ee().endsWith(`/materials`))return;let e=de();u(e),f(e),x(``),v(``),C(``),g(!1),e&&m(t=>new Set([...t,e.id]))};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]);async function re(){if(W&&!A){j(!0),M(``);try{let e=await o(`materials?before=${W}`,ce);T(t=>[...t,...e.materials]),k(e.nextCursor)}catch(e){M(c(e))}finally{j(!1)}}}let ae=U.find(e=>e.id===d?.id),q=ae?.originals.find(e=>e.sha256===d?.original)?.name??ae?.title??`当前资料`;function oe(){f(void 0),C(``),N.current?.focus()}let se=(0,Q.jsx)(O,{icon:`plus`,label:`新增资料`,onClick:()=>{r(),g(!0),M(``)}}),Y=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(I,{resource:F}),F.data?U.length===0?(0,Q.jsx)(`p`,{className:`tree-status`,children:`暂无资料`}):(0,Q.jsx)(Q.Fragment,{children:U.map(e=>(0,Q.jsxs)(`div`,{role:`none`,children:[(0,Q.jsxs)(z,{role:`treeitem`,"aria-level":1,"aria-expanded":p.has(e.id),"aria-selected":t&&!h&&l?.id===e.id&&!l.original,className:`tree-item tree-folder`,style:{"--tree-level":1},"data-testid":`material-folder`,title:e.title,onClick:()=>{let t=p.has(e.id);G({id:e.id}),t&&m(t=>{let n=new Set(t);return n.delete(e.id),n})},leading:(0,Q.jsx)(`span`,{className:`tree-chevron ${p.has(e.id)?`expanded`:``}`,children:(0,Q.jsx)(b,{name:`chevron`,size:`small`})}),children:[(0,Q.jsx)(b,{name:`files`}),(0,Q.jsx)(`span`,{className:`tree-name`,children:e.title})]}),p.has(e.id)&&(0,Q.jsx)(`div`,{role:`group`,children:[...e.originals].sort((e,t)=>ie(e.name,t.name)).map((n,r)=>(0,Q.jsxs)(z,{role:`treeitem`,"aria-level":2,"aria-selected":t&&!h&&l?.id===e.id&&l.original===n.sha256,className:`tree-item`,style:{"--tree-level":2},"data-testid":`material-original`,title:n.name,onClick:()=>G({id:e.id,original:n.sha256,...e.id===l?.id&&l.revision?{revision:l.revision}:{}}),leading:(0,Q.jsx)(`span`,{className:`tree-chevron`}),children:[(0,Q.jsx)(b,{name:`file`}),(0,Q.jsx)(`span`,{className:`tree-name`,children:n.name})]},`${n.sha256}:${r}`))})]},e.id))}):!F.error&&(0,Q.jsx)(`p`,{className:`tree-status`,children:`加载中…`}),W&&(0,Q.jsx)(`button`,{className:`tree-action`,disabled:A,onClick:()=>void re(),children:A?`加载中…`:`加载更多`})]}),X=!h&&!y&&l?.original,le=h?`新增资料`:y?`搜索结果`:H?.title||`资料预览`;return a({tree:Y,reader:(0,Q.jsxs)(`section`,{className:`session-reader`,"aria-label":`资料内容与搜索`,children:[X&&H?(0,Q.jsx)(me,{material:H,hash:X,highlight:S,error:V.error},`${H.id}:${X}`):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(B,{title:le}),(0,Q.jsx)(`div`,{className:`session-reader-content`,children:h?(0,Q.jsx)(ve,{onCancel:()=>g(!1),onSaved:e=>{G({id:e}),F.reload()}}):y?(0,Q.jsx)(pe,{query:y,scope:d,onSelect:e=>G(e,y)},`${y}/${d?.id}/${d?.original}`):l?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(I,{resource:V}),H?(0,Q.jsxs)(`article`,{className:`material-body`,children:[l.revision&&(0,Q.jsx)(`button`,{className:`material-link`,onClick:()=>G({id:l.id}),children:`查看最新内容`}),!l.revision&&(H.state===`waiting`||H.state===`running`)?(0,Q.jsx)(`p`,{className:`muted`,role:`status`,children:`正在整理…`}):null,(0,Q.jsx)(ne,{children:H.error}),!l.revision&&H.state===`failed`&&(0,Q.jsx)(`button`,{onClick:()=>void o(`materials/${l.id}/retry`,Z,{method:`POST`}).then(()=>V.reload()).catch(e=>M(c(e))),children:`重试整理`}),H.content?(0,Q.jsx)(`div`,{className:`markdown`,children:(0,Q.jsx)(K,{highlight:S,children:ue(H)})}):(0,Q.jsx)(`p`,{className:`muted`,children:`正文尚未整理,可以先查看左侧原件。`})]}):!V.error&&(0,Q.jsx)(`p`,{role:`status`,children:`加载中…`})]}):(0,Q.jsx)(te,{mascot:!0,title:`选择资料开始阅读`,description:`也可以在下方搜索资料内容。`})})]}),!h&&(0,Q.jsxs)(`form`,{className:`session-search-dock`,"data-testid":`material-search-form`,onSubmit:e=>{e.preventDefault(),x(_.trim()),C(``)},children:[d&&(0,Q.jsxs)(`button`,{type:`button`,className:`search-scope-chip`,title:`清除搜索范围`,"aria-label":`清除范围:${q}`,onClick:oe,children:[(0,Q.jsxs)(`span`,{className:`scope-label`,children:[`搜索:`,q]}),(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`×`})]}),(0,Q.jsxs)(`div`,{className:`session-search-input-row`,children:[(0,Q.jsx)(`input`,{ref:N,"aria-label":`搜索资料`,placeholder:`搜索资料内容`,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>{e.key===`Backspace`&&!_&&d&&(e.preventDefault(),oe())}}),(y||_||S)&&(0,Q.jsx)(O,{icon:`close`,label:`清空搜索`,onClick:()=>{v(``),x(``),C(``),N.current?.focus()}}),(0,Q.jsx)(O,{icon:`search`,type:`submit`,label:`搜索`,disabled:!_.trim()})]})]})]}),actions:se,href:`/projects/${s}/materials${l&&!h?`?${new URLSearchParams({...l})}`:``}`})}function pe({query:e,scope:t,onSelect:n}){let{request:r}=R(),[a,o]=(0,J.useState)(``),s=(0,J.useCallback)(n=>r(`resources/search?${new URLSearchParams({query:e,scope:`materials`,after:a,...t?{materialId:t.id}:{},...t?.original?{originalHash:t.original}:{}})}`,le,{signal:n}),[r,e,t?.id,t?.original,a]),c=i(s);return(0,Q.jsxs)(`section`,{className:`session-results stack`,"aria-label":`搜索结果`,children:[(0,Q.jsx)(I,{resource:c}),c.loading?(0,Q.jsx)(`p`,{role:`status`,children:`正在搜索…`}):c.data?.items.length===0?(0,Q.jsx)(`p`,{className:`empty`,children:`没有找到匹配的资料`}):c.data?.items.map(t=>(0,Q.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,Q.jsx)(`strong`,{children:t.title.replace(/^R\d+ · /,``)}),(0,Q.jsx)(`span`,{className:`session-excerpt`,children:(0,Q.jsx)(W,{value:G(t.snippet,e),query:e})})]},t.key)),c.data?.nextCursor&&(0,Q.jsx)(`button`,{disabled:c.loading,onClick:()=>o(c.data.nextCursor),children:`下一页`})]})}function me({material:t,hash:n,highlight:r,error:a}){let{projectId:o}=R(),s=t.originals.find(e=>e.sha256===n),c=e(`/api/v1/projects/${o}/materials/${t.id}/originals/${n}?revision=${t.revision}`),[l,d]=(0,J.useState)(!1),f=(0,J.useCallback)(async e=>{let t=await fetch(c,{signal:e});if(!t.ok)throw new u(`HTTP_ERROR`,`原件暂时无法读取。`,t.status);let n=await t.arrayBuffer();try{let e=new TextDecoder(`utf8`,{fatal:!0}).decode(n);return e.includes(`\0`)?null:e}catch{return null}},[c]),p=i(f,!1,E(o,`material-original`,n));if(!s)return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(B,{title:`资料原件`}),(0,Q.jsx)(`div`,{className:`session-reader-content`,children:(0,Q.jsx)(ne,{announce:!0,children:`找不到此原件。`})})]});let m=/\.(md|markdown)$/i.test(s.name),h=/\.html?$/i.test(s.name);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(B,{title:s.name,actions:(0,Q.jsxs)(`div`,{className:`toolbar-actions`,children:[(m||h)&&(0,Q.jsx)(O,{icon:l?`preview`:`code`,label:l?`切换为预览`:`切换为原文`,"aria-pressed":l,onClick:()=>d(!l)}),(0,Q.jsx)(`a`,{className:`icon-button`,"aria-label":`下载原件`,title:`下载原件`,href:c,download:s.name,children:(0,Q.jsx)(b,{name:`download`})})]})}),(0,Q.jsxs)(`div`,{className:`session-reader-content`,children:[(0,Q.jsx)(y,{message:a}),(0,Q.jsx)(I,{resource:p}),p.loading&&p.data===void 0?(0,Q.jsx)(`p`,{role:`status`,children:`加载中…`}):p.data===null?(0,Q.jsx)(`p`,{className:`muted`,children:`此格式请下载后查看。`}):p.data!==void 0&&(0,Q.jsx)(`div`,{className:`preview-body${h&&!l?` preview-body-html`:``}`,"data-testid":`material-original-content`,children:h&&!l?(0,Q.jsx)(ae,{url:c,name:s.name}):m&&!l?(0,Q.jsx)(`article`,{className:`markdown`,children:(0,Q.jsx)(K,{highlight:r,children:p.data})}):(0,Q.jsx)(`pre`,{className:`raw`,children:(0,Q.jsx)(W,{value:p.data,query:r})})})]})]})}function he(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 ge(e){try{return new URL(e.trim()).hostname}catch{return e.trim().split(`
4
- `)[0]?.slice(0,80)||`文本`}}function _e(e){try{return new URL(e.trim()).href}catch{return e.trim().split(`
5
- `).slice(1).join(`
6
- `)}}function ve({onSaved:t,onCancel:r}){let{request:i,projectId:a}=R(),[o,s]=(0,J.useState)([]),[u,d]=(0,J.useState)(),[f,p]=(0,J.useState)(!1),m=n(),h=(0,J.useRef)(null),g=(0,J.useRef)(l()),_=(0,J.useRef)(new Map);function v(e){s(e),g.current=l(),m(``)}async function y(){p(!0),m(``);try{let n=[];for(let[t,r]of o.entries()){let i=_.current.get(r.id);if(!i){let n=r.kind===`file`?r.file.name:`${ge(r.text)}.txt`,o=await fetch(e(`/api/v1/projects/${a}/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 o.json();if(!o.ok)throw Error(s.error?.message??`第 ${t+1} 项上传失败。`);i={name:n,sha256:s.sha256,size:s.size},_.current.set(r.id,i)}n.push(i)}let r=o.length===1&&o[0]?.kind===`text`?o[0].text.trim():``,s;try{let e=new URL(r);[`http:`,`https:`].includes(e.protocol)&&(s=e.href)}catch{}t((await i(`materials`,Z,{method:`POST`,body:{operationId:g.current,originals:n,...s?{url:s}:{}}})).id)}catch(e){m(c(e))}finally{p(!1)}}return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`form`,{className:`material-form`,onSubmit:e=>{e.preventDefault(),y()},children:[(0,Q.jsx)(`p`,{className:`muted`,children:`上传附件到项目,以便于Tim进行理解`}),(0,Q.jsxs)(`fieldset`,{disabled:f,children:[(0,Q.jsxs)(`div`,{className:`attachment-grid`,children:[o.map(e=>(0,Q.jsxs)(`article`,{className:`attachment-card`,"data-testid":`attachment-card`,children:[e.kind===`text`?(0,Q.jsxs)(`button`,{type:`button`,className:`attachment-content`,"aria-label":`编辑:${ge(e.text)}`,onClick:()=>d({id:e.id,text:e.text}),children:[(0,Q.jsx)(b,{name:he(e)}),(0,Q.jsx)(`span`,{className:`attachment-name`,children:ge(e.text)}),_e(e.text)&&(0,Q.jsx)(`span`,{className:`attachment-excerpt`,children:_e(e.text)})]}):(0,Q.jsxs)(`div`,{className:`attachment-content`,children:[(0,Q.jsx)(b,{name:he(e)}),(0,Q.jsx)(`span`,{className:`attachment-name`,children:e.file.name})]}),(0,Q.jsx)(O,{className:`attachment-remove`,icon:`close`,label:`移除:${e.kind===`file`?e.file.name:ge(e.text)}`,onClick:()=>{_.current.delete(e.id),v(o.filter(t=>t.id!==e.id))}})]},e.id)),(0,Q.jsxs)(`button`,{type:`button`,className:`attachment-add`,onClick:()=>d({text:``}),children:[(0,Q.jsx)(b,{name:`addText`}),(0,Q.jsx)(`span`,{children:`添加文本/链接`})]}),(0,Q.jsxs)(`button`,{type:`button`,className:`attachment-add`,onClick:()=>h.current?.click(),children:[(0,Q.jsx)(b,{name:`addFile`}),(0,Q.jsx)(`span`,{children:`添加文件`})]})]}),(0,Q.jsx)(`input`,{ref:h,type:`file`,multiple:!0,hidden:!0,"aria-label":`原始文件`,onChange:e=>{v([...o,...[...e.target.files??[]].map(e=>({id:l(),kind:`file`,file:e}))]),e.target.value=``}}),(0,Q.jsxs)(`div`,{className:`actions attachment-actions`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:r,children:`取消`}),(0,Q.jsx)(`button`,{type:`submit`,className:`primary`,disabled:!o.length,children:f?`上传中…`:`提交资料`})]})]})]}),u&&(0,Q.jsx)(S,{id:`material-text-editor`,title:`添加文本/链接`,onClose:()=>d(void 0),children:(0,Q.jsxs)(`form`,{className:`stack`,onSubmit:e=>{if(e.preventDefault(),!u.text.trim())return;let t={id:u.id??l(),kind:`text`,text:u.text};_.current.delete(t.id),v(u.id?o.map(e=>e.id===u.id?t:e):[...o,t]),d(void 0)},children:[(0,Q.jsx)(M,{id:`material-attachment-text`,label:`文本或链接`,children:(0,Q.jsx)(`textarea`,{autoFocus:!0,rows:8,value:u.text,onChange:e=>d({...u,text:e.target.value}),placeholder:`粘贴文本或网页链接`})}),(0,Q.jsx)(`div`,{className:`actions`,children:(0,Q.jsx)(`button`,{type:`submit`,className:`primary`,disabled:!u.text.trim(),children:u.id?`保存`:`添加`})})]})})]})}var ye=w([`overview`,`handoff`]),be=L({title:f().trim().min(1),summary:f().trim().min(1)}),xe=L({markdown:f().trim().min(1)}),Se=be.extend({sourceRevision:x,sourceHash:N,generatedAt:f(),stale:k()}),Ce=L({kind:ye,status:w([`absent`,`queued`,`running`,`succeeded`,`failed`]),available:k(),currentRevision:x,sourceRevision:x.nullable(),stale:k(),result:r([be,xe]).nullable(),generatedAt:f().nullable(),error:f().nullable()}),we=w([`claude-code`,`codex`,`cursor`,`pi`,`dsh`]),Te=L({formatVersion:g(1),adapterVersion:g(1),agent:we,nativeId:f().min(1).max(512),cwd:f().min(1).max(4096),messages:j(L({id:f().min(1).max(1024),role:w([`user`,`assistant`]),text:f().min(1),source:f().min(1).max(1024)}).strict())}).strict().refine(e=>new Set(e.messages.map(e=>e.id)).size===e.messages.length,`Duplicate message IDs.`);L({operationId:s(),sessionKey:N,parentRevision:x,blob:v}).strict(),L({revision:x,hash:N.nullable(),cleared:k()});var Ee=L({owner:P,sessionKey:N,agent:we,nativeId:f(),cwd:f(),title:f(),revision:x,updatedAt:f(),messageCount:F().int().nonnegative(),blob:v,overview:Se.optional()}),De=L({sessions:j(Ee),nextCursor:x.nullable()}),Oe=L({totalSessions:F().int().nonnegative(),totalMessages:F().int().nonnegative(),memberCount:F().int().nonnegative(),updatedAt:f().nullable()});L({owner:P.optional(),sessionKey:N.optional()}).strict().refine(e=>!e.sessionKey||!!e.owner,`A session scope requires an owner.`);var ke=L({matches:j(L({owner:P,sessionKey:N,revision:x,messageId:f(),source:w([`message`,`handoff`]).default(`message`),role:w([`user`,`assistant`]),snippet:f(),title:f()})),nextCursor:x.nullable()}),Ae=L({owner:P,key:N,revision:x.refine(e=>e>0).optional(),messageId:f().min(1).optional(),source:w([`message`,`handoff`]).optional()});function je(e){let t=new URLSearchParams(e);if(![`owner`,`sessionKey`,`revision`,`messageId`].some(e=>t.has(e)))return{};let n=Ae.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 Me({members:e,refresh:t,selected:n,onOwner:r,onSession:i,level:a=1}){let[o,s]=(0,J.useState)(()=>new Set(n?.key?[n.owner]:[])),[c,l]=(0,J.useState)(e[0]?.id??``);return(0,Q.jsx)(`div`,{role:a===1?`tree`:`group`,"aria-label":`成员对话`,"data-testid":`session-tree`,onKeyDown:a===1?q:void 0,children:[...e].sort((e,t)=>ie(e.id,t.id)).map(e=>(0,Q.jsxs)(`div`,{role:`none`,children:[(0,Q.jsxs)(z,{type:`button`,role:`treeitem`,"aria-level":a,"aria-expanded":o.has(e.id),"aria-selected":n?.owner===e.id&&!n.key,className:`tree-item tree-folder`,style:{"--tree-level":a},tabIndex:c===e.id?0:-1,"data-testid":`session-owner`,"data-owner-id":e.id,onFocus:()=>l(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,Q.jsx)(`span`,{className:`tree-chevron ${o.has(e.id)?`expanded`:``}`,children:(0,Q.jsx)(b,{name:`chevron`,size:`small`})}),children:[(0,Q.jsx)(b,{name:`files`}),(0,Q.jsx)(`span`,{className:`tree-name`,title:e.id,children:e.id})]}),o.has(e.id)&&(0,Q.jsx)(Ne,{level:a+1,owner:e.id,selected:n,onSession:i,focused:c,onFocus:l},`${e.id}/${t}`)]},e.id))})}function Ne({level:e,owner:r,selected:a,onSession:o,focused:s,onFocus:l}){let{request:u,projectId:d}=R(),f=(0,J.useCallback)(e=>u(`sessions?${new URLSearchParams({owner:r,limit:`50`,order:`updated`})}`,De,{signal:e}),[r,u]),p=i(f,15e3,E(d,`session-tree`,r)),[m,h]=(0,J.useState)(),[g,_]=(0,J.useState)(!1),v=n(),y=(0,J.useRef)(null);(0,J.useEffect)(()=>()=>y.current?.abort(),[]);let x=m?m.nextCursor:p.data?.nextCursor;return(0,Q.jsxs)(`div`,{role:`group`,"aria-busy":p.loading||g,children:[(0,Q.jsx)(I,{resource:p}),p.loading&&!p.data&&(0,Q.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(n=>(0,Q.jsxs)(z,{type:`button`,role:`treeitem`,"aria-level":e,"aria-selected":a?.owner===r&&a.key===n.sessionKey,className:`tree-item`,style:{"--tree-level":e},tabIndex:s===`${r}/${n.sessionKey}`?0:-1,"data-testid":`session-row`,"data-owner-id":r,"data-session-key":n.sessionKey,title:t(n.title||n.nativeId),onFocus:()=>l(`${r}/${n.sessionKey}`),onClick:()=>o({owner:r,key:n.sessionKey,title:n.title||n.nativeId}),leading:(0,Q.jsx)(`span`,{className:`tree-chevron`}),children:[(0,Q.jsx)(b,{name:`sessions`}),(0,Q.jsx)(`span`,{className:`tree-name`,children:t(n.title||n.nativeId)})]},n.sessionKey)),x!=null&&(0,Q.jsx)(`button`,{className:`tree-action`,"data-testid":`session-tree-more`,disabled:g,onClick:async()=>{_(!0),v(``);let e=new AbortController;y.current=e;try{let t=await u(`sessions?${new URLSearchParams({owner:r,after:String(x),limit:`50`,order:`updated`})}`,De,{signal:e.signal});h(e=>({sessions:[...e?.sessions??[],...t.sessions],nextCursor:t.nextCursor}))}catch(t){e.signal.aborted||v(c(t))}finally{e.signal.aborted||_(!1)}},children:`加载更多`})]})}function Pe({info:e,targeted:t=!1,highlight:n=``}){let[r,i]=(0,J.useState)(t),a=(0,J.useRef)(null);return(0,J.useEffect)(()=>{t&&a.current?.scrollIntoView({block:`center`})},[t]),(0,Q.jsxs)(`details`,{ref:a,open:r,className:`session-handoff`,onToggle:e=>i(e.currentTarget.open),children:[(0,Q.jsx)(`summary`,{children:`交接说明`}),r&&(0,Q.jsx)(Fe,{info:e,revision:t?e.revision:void 0,highlight:n})]})}function Fe({info:e,revision:t,highlight:r}){let{request:a}=R(),s=`sessions/${encodeURIComponent(e.owner)}/${e.sessionKey}`,l=(0,J.useCallback)(e=>a(`${s}/analysis/handoff${t===void 0?``:`?revision=${t}`}`,Ce,{signal:e}),[a,s,t]),u=i(l,5e3),d=o(),[f,p]=(0,J.useState)(!1),m=n(),g=u.data,_=f||g?.status===`queued`||g?.status===`running`,v=g?.result&&`markdown`in g.result?g.result.markdown:void 0;return(0,Q.jsxs)(`div`,{className:`stack`,"data-testid":`session-handoff`,children:[(0,Q.jsx)(I,{resource:u}),u.loading&&!g&&(0,Q.jsx)(`small`,{role:`status`,children:`正在加载…`}),g&&(0,Q.jsxs)(`div`,{className:`inline-actions`,children:[g.status===`failed`&&t===void 0&&(0,Q.jsx)(`button`,{"data-testid":`session-handoff-generate`,disabled:_||!g.available,onClick:async()=>{p(!0),m(``);try{await a(`${s}/handoff`,Ce,{method:`POST`,signal:d}),await u.reload()}catch(e){d.aborted||m(c(e))}finally{d.aborted||p(!1)}},children:_?`正在整理…`:`重试`}),!g.available&&(0,Q.jsx)(`small`,{children:`请先配置项目模型接入点`}),g.status===`failed`&&(0,Q.jsx)(`small`,{children:`整理未完成,可重试`}),g.available&&g.status!==`failed`&&(!v||g.stale||_)&&(0,Q.jsx)(`small`,{role:`status`,children:g.status===`running`||f?`正在整理…`:v?`对话已有新内容,等待自动更新…`:`等待自动整理…`}),g.currentRevision!==e.revision&&(0,Q.jsx)(`small`,{children:`交接说明使用最新对话;当前阅读的是历史原文`})]}),v&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`small`,{children:[`基于版本 `,g.sourceRevision,` · `,(0,Q.jsx)(h,{value:g.generatedAt})]}),(0,Q.jsx)(`div`,{className:`markdown`,"data-testid":`session-handoff-body`,children:(0,Q.jsx)(K,{highlight:r,children:v})})]})]})}function Ie({members:n,active:r,onActivate:a,children:o}){let{request:s,projectId:c,api:l}=R(),u=(0,J.useCallback)(async e=>{let[t,n]=await Promise.all([s(`sessions/stats`,Oe,{signal:e}),l.members(e)]);return{...t,members:n.members}},[s,l]),d=i(u,!0,E(c,`session-stats`)),[f,p]=(0,J.useState)(``),[h,g]=(0,J.useState)(``),[v,y]=(0,J.useState)(0),[b]=(0,J.useState)(()=>je(location.search)),[x,S]=(0,J.useState)(b.target),[C,w]=(0,J.useState)(b.target),[T,D]=(0,J.useState)(b.error??``),[k,A]=(0,J.useState)(``),j=(0,J.useRef)(null),M=x?.key?x.title?`搜索对话:${t(x.title)}`:`搜索当前对话`:x?`搜索:${x.owner} 的对话内容`:``,N=()=>{S(void 0),A(``),P(),j.current?.focus()};function P(){if(!C?.messageId)return;let{messageId:t,...n}=C;w(n),history.replaceState(null,``,e(U(c,n.owner,n.key,n)))}let F=(0,J.useCallback)(e=>{S(t=>t?.owner===e.owner&&t.key===e.sessionKey&&t.title!==e.title?{...t,title:e.title}:t)},[]);(0,J.useEffect)(()=>{let e=()=>{if(!ee().endsWith(`/sessions`))return;let e=je(location.search);w(e.target),S(e.target),D(e.error??``),g(``),p(``),A(``)};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]);let L=(t,n=``)=>{a(),w(t),S(t),g(``),A(n),D(``),history.replaceState(null,``,e(U(c,t.owner,t.key,t)))},z=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(I,{resource:d}),(0,Q.jsx)(Me,{members:(d.data?.members??n).filter(e=>e.hasSessions),refresh:v,selected:r?x:void 0,level:2,onOwner:t=>{a(),S({owner:t}),w(void 0),g(``),A(``),D(``),history.replaceState(null,``,e(`/projects/${encodeURIComponent(c)}/sessions`))},onSession:L})]}),V=(0,Q.jsxs)(`section`,{className:`session-reader`,"aria-label":`对话内容与搜索`,children:[(0,Q.jsx)(B,{title:(0,Q.jsxs)(`h1`,{children:[m.sessions,(0,Q.jsx)(_,{children:(0,Q.jsx)(`span`,{"data-testid":`session-total`,children:d.data?.totalSessions??`—`})})]}),actions:(0,Q.jsx)(O,{icon:`refresh`,label:`刷新${m.sessions}`,"data-testid":`sessions-refresh`,disabled:d.loading,onClick:()=>{d.reload(),y(e=>e+1)}})}),(0,Q.jsx)(`div`,{className:`session-reader-content`,children:T?(0,Q.jsx)(ne,{announce:!0,children:T}):h?(0,Q.jsx)(Le,{query:h,refresh:v,scope:{...x?{owner:x.owner}:{},...x?.key?{sessionKey:x.key}:{}},onSelect:e=>L(e,h)},`${h}/${x?.owner??``}/${x?.key??``}`):C?(0,Q.jsx)(Re,{selection:C,highlight:k,onLoaded:F,onLatest:()=>L({owner:C.owner,key:C.key})},`${C.owner}/${C.key}/${C.revision}/${C.source}/${v}`):(0,Q.jsx)(te,{mascot:!0,title:`选择对话开始阅读`,description:`也可以在下方搜索会话库内容。`})}),(0,Q.jsxs)(`form`,{className:`session-search-dock`,"data-testid":`session-search-form`,onSubmit:e=>{e.preventDefault(),g(f.trim()),A(``),D(``),y(e=>e+1)},children:[x&&(0,Q.jsxs)(`button`,{type:`button`,className:`search-scope-chip`,"data-testid":`session-search-scope`,title:`清除搜索范围`,"aria-label":`清除范围:${M}`,onClick:N,children:[(0,Q.jsx)(`span`,{className:`scope-label`,children:M}),(0,Q.jsx)(`span`,{"aria-hidden":`true`,children:`×`})]}),(0,Q.jsxs)(`div`,{className:`session-search-input-row`,children:[(0,Q.jsx)(`input`,{ref:j,"aria-label":`搜索对话`,"data-testid":`session-query`,value:f,maxLength:500,placeholder:`搜索会话库内容`,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Backspace`&&!f&&x&&(e.preventDefault(),N())}}),(h||f||k)&&(0,Q.jsx)(O,{icon:`close`,label:`清空搜索`,"data-testid":`session-search-clear`,onClick:()=>{p(``),g(``),A(``),P(),j.current?.focus()}}),(0,Q.jsx)(O,{icon:`search`,type:`submit`,label:`搜索`,"data-testid":`session-search`,disabled:!f.trim()})]})]})]});return o({hasSelection:!!x,tree:z,reader:V,href:C?U(c,C.owner,C.key,C):`/projects/${c}/sessions`})}function Le({query:e,refresh:n,scope:r,onSelect:a}){let{request:o}=R(),[s,c]=(0,J.useState)(0),l=(0,J.useCallback)(t=>o(`sessions/search?${new URLSearchParams({q:e,after:String(s),limit:`30`,order:`updated`,...r.owner?{owner:r.owner}:{},...r.sessionKey?{sessionKey:r.sessionKey}:{}})}`,ke,{signal:t}),[o,e,s,n,r.owner,r.sessionKey]),u=i(l);return(0,Q.jsxs)(`section`,{className:`session-results stack`,"aria-label":`搜索结果`,"aria-busy":u.loading,children:[(0,Q.jsx)(I,{resource:u}),u.loading&&(0,Q.jsx)(`p`,{role:`status`,children:`正在搜索…`}),!u.loading&&u.data?.matches.map(n=>(0,Q.jsxs)(`button`,{className:`session-item`,"data-testid":`session-match`,"data-message-id":n.messageId,onClick:()=>a({owner:n.owner,key:n.sessionKey,revision:n.revision,messageId:n.messageId||void 0,source:n.source,title:n.title}),children:[(0,Q.jsx)(`strong`,{children:t(n.title)}),(0,Q.jsxs)(`small`,{children:[n.owner,` ·`,` `,n.source===`handoff`?`交接说明`:n.role===`user`?`用户`:`助手`]}),(0,Q.jsx)(`span`,{className:`session-excerpt`,children:(0,Q.jsx)(W,{value:G(n.snippet,e),query:e})})]},`${n.owner}:${n.sessionKey}:${n.revision}:${n.source}:${n.messageId}`)),!u.loading&&u.data?.matches.length===0&&(0,Q.jsx)(`p`,{className:`empty`,children:`没有找到匹配的对话`}),u.data?.nextCursor!=null&&(0,Q.jsx)(`button`,{"data-testid":`sessions-next`,disabled:u.loading,onClick:()=>c(u.data.nextCursor),children:`下一页`}),s>0&&(0,Q.jsx)(`button`,{disabled:u.loading,onClick:()=>c(0),children:`返回第一页`})]})}function Re({selection:e,highlight:t,onLoaded:n,onLatest:r}){let{request:a}=R(),o=(0,J.useCallback)(async t=>{try{return await a(`sessions/${encodeURIComponent(e.owner)}/${e.key}${e.revision===void 0?``:`?revision=${e.revision}`}`,Ee,{signal:t})}catch(e){throw e instanceof u&&e.code===`SESSION_NOT_FOUND`?Error(`找不到这条对话或引用的版本,原链接可能已失效。`):e}},[a,e.owner,e.key,e.revision]),s=i(o,5e3);return(0,J.useEffect)(()=>{s.data&&n(s.data)},[s.data,n]),(0,Q.jsxs)(`section`,{className:`session-conversation stack`,"data-testid":`session-detail`,children:[(0,Q.jsx)(I,{resource:s}),s.loading&&!s.data&&(0,Q.jsx)(`p`,{role:`status`,children:`正在读取对话…`}),s.data&&(0,Q.jsx)(ze,{info:s.data,messageId:e.messageId,handoff:e.source===`handoff`,highlight:t,pinned:e.revision!==void 0,onLatest:r},s.data.blob.sha256)]})}function ze({info:n,messageId:r,handoff:a,highlight:o,pinned:s,onLatest:c}){let{readTextBlob:l,projectId:u}=R(),d=(0,J.useCallback)(async e=>Te.parse(JSON.parse(await l(n.blob,e))),[n.blob.sha256,n.blob.size]),f=i(d),p=(0,J.useRef)(null);return(0,J.useEffect)(()=>{f.data&&r&&p.current?.scrollIntoView({block:`center`})},[f.data,r]),(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`header`,{className:`conversation-header`,children:[(0,Q.jsx)(`h2`,{className:`session-title`,children:t(n.title||n.nativeId)}),(0,Q.jsxs)(`p`,{children:[n.owner,` · `,n.agent,` · `,n.messageCount,` 条消息`]}),(0,Q.jsxs)(`small`,{children:[(0,Q.jsx)(h,{value:n.updatedAt}),s&&(0,Q.jsxs)(Q.Fragment,{children:[` `,`· 引用版本 `,n.revision,` ·`,` `,(0,Q.jsx)(`a`,{href:e(U(u,n.owner,n.sessionKey)),onClick:e=>{e.preventDefault(),c()},children:`查看最新`})]})]}),n.overview&&(0,Q.jsx)(`p`,{"data-testid":`session-summary`,children:n.overview.summary}),n.overview?.stale&&(0,Q.jsx)(`small`,{children:`摘要待更新`})]}),(0,Q.jsx)(Pe,{info:n,targeted:a,highlight:a?o:``}),(0,Q.jsx)(I,{resource:f}),f.loading&&(0,Q.jsx)(`p`,{role:`status`,children:`正在读取对话…`}),f.data&&(0,Q.jsxs)(Q.Fragment,{children:[r&&!f.data.messages.some(e=>e.id===r)&&(0,Q.jsx)(A,{children:`该版本中找不到引用的消息,已打开对话原文。`}),(0,Q.jsx)(`div`,{className:`session-messages`,children:f.data.messages.map(e=>(0,Q.jsx)(re,{mine:e.role===`user`,author:e.role===`user`?`用户`:`助手`,className:`session-message ${e.role} ${e.id===r?`matched`:``}`,"data-testid":`session-message`,"data-message-id":e.id,ref:e.id===r?p:void 0,children:(0,Q.jsx)(`div`,{className:`markdown`,children:(0,Q.jsx)(K,{highlight:o,children:e.text})})},e.id))})]})]})}var $=f().trim().min(1),Be=L({id:s(),text:$,state:w([`draft`,`kept`]),revision:F().int().positive(),createdAt:f(),updatedAt:f()}),Ve=L({cards:j(Be)});L({id:s(),text:$}).strict(),L({expectedRevision:F().int().positive(),text:$.optional(),action:w([`keep`,`discard`,`delete`]).optional()}).strict().refine(e=>e.text!==void 0||e.action!==void 0,`没有需要保存的修改。`),L({text:$}).strict();function He(){let{request:e,projectId:t}=R(),n=(0,J.useCallback)(t=>e(`memory`,Ve,{signal:t}),[e]),r=i(n,5e3,E(t,`memory`)),[a,o]=(0,J.useState)(null),[s,c]=(0,J.useState)({}),u=(0,J.useRef)(null),d=[...r.data?.cards??[]];for(let e of Object.values(s))d.some(t=>t.id===e.id)||d.push(e);if(r.data&&!u.current&&(u.current=[...d].sort((e,t)=>Number(t.state===`kept`)-Number(e.state===`kept`)).map(e=>e.id)),u.current){let e=new Map(u.current.map((e,t)=>[e,t]));for(let t of d)e.has(t.id)||(e.set(t.id,u.current.length),u.current.push(t.id));d.sort((t,n)=>e.get(t.id)-e.get(n.id))}return(0,Q.jsxs)(`section`,{className:`session-reader`,"aria-label":`项目记忆`,children:[(0,Q.jsx)(B,{title:`记忆`,actions:(0,Q.jsx)(O,{icon:`plus`,label:`新增记忆`,disabled:!!a,onClick:()=>o(l())})}),(0,Q.jsxs)(`div`,{className:`memory-page`,children:[(0,Q.jsx)(I,{resource:r}),!r.data&&r.loading&&(0,Q.jsx)(`p`,{role:`status`,children:`加载中…`}),(0,Q.jsxs)(`div`,{className:`memory-cards`,children:[a&&(0,Q.jsx)(Ue,{id:a,onDone:()=>o(null),reload:r.reload},a),d.map(e=>(0,Q.jsx)(Ue,{id:e.id,card:e,reload:r.reload,onEditing:t=>c(n=>{let r={...n};return t?r[e.id]=e:delete r[e.id],r})},e.id))]}),r.data&&d.length===0&&!a&&(0,Q.jsx)(`p`,{className:`memory-empty`,children:`暂无记忆`})]})]})}function Ue({id:e,card:t,reload:r,onDone:i,onEditing:a}){let{request:o}=R(),[s,l]=(0,J.useState)(!t),[u,d]=(0,J.useState)(t?.text??``),[f,p]=(0,J.useState)(t?.revision),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(!1),v=n(),y=(0,J.useRef)(!1),x=(0,J.useRef)(!1),S=(0,J.useRef)(!1);function C(){S.current=!1,a?.(!0),d(t?.text??``),p(t?.revision),y.current=!1,_(!1),v(``),l(!0)}function w(){S.current=!0,l(!1),v(``),_(!1),a?.(!1),i?.()}async function T(n){if(!x.current){if(!n&&t&&u===t.text)l(!1),a?.(!1);else if((!n||n===`keep`)&&!$.safeParse(s?u:t?.text).success)_(!0);else{x.current=!0,h(!0),y.current=!1,_(!1),v(``);try{t?await o(`memory/${e}`,L({saved:k()}),{method:`PATCH`,body:{expectedRevision:s?f:t.revision,...n?{action:n}:{},...s&&n!==`discard`&&n!==`delete`?{text:u}:{}}}):await o(`memory`,Be,{method:`POST`,body:{id:e,text:u}}),l(!1),await r(),a?.(!1),i?.()}catch(e){y.current=!0,v(c(e)),await r()}finally{x.current=!1,h(!1)}}}}return(0,Q.jsxs)(`article`,{className:`memory-card`,"data-testid":`memory-card`,"data-memory-id":e,children:[(0,Q.jsx)(`span`,{className:`memory-status ${t?.state===`kept`?`is-kept`:``}`,role:`img`,"aria-label":t?.state===`kept`?`已保留`:`待确认`,children:(0,Q.jsx)(b,{name:t?.state===`kept`?`check`:`question`})}),(0,Q.jsxs)(`div`,{className:`memory-content`,children:[s?(0,Q.jsx)(`textarea`,{autoFocus:!0,"aria-label":`记忆内容`,"aria-invalid":g||void 0,"aria-describedby":g?`memory-error-${e}`:void 0,value:u,rows:2,disabled:m,onChange:e=>{d(e.target.value),_(!1)},onBlur:e=>{S.current?S.current=!1:e.relatedTarget instanceof Element&&e.relatedTarget.closest(`.memory-actions`)||!g&&!y.current&&T()},onKeyDown:e=>{e.nativeEvent.isComposing||(e.key===`Escape`&&(e.preventDefault(),w()),e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),T()))}}):(0,Q.jsx)(`button`,{type:`button`,className:`memory-text`,"aria-label":`编辑记忆:${t?.text??``}`,onClick:C,children:t?.text}),g&&(0,Q.jsx)(`small`,{id:`memory-error-${e}`,className:`error-detail`,children:`请填写记忆内容。`})]}),(0,Q.jsxs)(`div`,{className:`memory-actions`,onMouseDown:e=>{s&&e.preventDefault()},children:[(!t||t.state===`draft`)&&(0,Q.jsx)(O,{icon:`check`,label:t?`保留记忆`:`保存记忆`,disabled:m,onClick:()=>void T(t?`keep`:void 0)}),s&&t?.state===`kept`&&(0,Q.jsx)(O,{icon:`check`,label:`保存记忆`,disabled:m,onClick:()=>void T()}),(0,Q.jsx)(O,{icon:`close`,label:t?t.state===`draft`?`舍弃记忆`:`删除记忆`:`取消新增`,disabled:m,onClick:()=>{t?T(t.state===`draft`?`discard`:`delete`):w()}})]})]})}function We({section:e,members:t,navigate:n}){let{projectId:r}=R(),[i,a]=(0,J.useState)(e===`sessions`);(0,J.useEffect)(()=>{e===`sessions`&&a(!0)},[e]);let o=t=>{e!==t&&n(`/projects/${r}/${t}`)};return(0,Q.jsx)(fe,{active:e===`materials`,onActivate:()=>o(`materials`),children:r=>(0,Q.jsx)(Ie,{members:t,active:e===`sessions`,onActivate:()=>o(`sessions`),children:t=>(0,Q.jsx)(V,{reading:!0,className:`resource-library`,"data-testid":`materials-page`,label:`资料目录`,navigation:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(H,{title:`资料`,children:r.actions}),(0,Q.jsxs)(`div`,{role:`tree`,"aria-label":`项目资料`,onKeyDown:q,style:{"--tree-level":1},children:[(0,Q.jsxs)(z,{role:`treeitem`,"aria-level":1,"aria-selected":e===`memory`,className:`tree-item tree-folder`,"data-testid":`library-memory`,leading:(0,Q.jsx)(`span`,{className:`tree-chevron`}),onClick:()=>o(`memory`),children:[(0,Q.jsx)(b,{name:`files`}),(0,Q.jsx)(`span`,{className:`tree-name`,children:`记忆`})]}),(0,Q.jsxs)(z,{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,Q.jsx)(`span`,{className:`tree-chevron ${i?`expanded`:``}`,children:(0,Q.jsx)(b,{name:`chevron`,size:`small`})}),onClick:()=>{a(!i),e!==`sessions`&&n(t.href)},children:[(0,Q.jsx)(b,{name:`files`}),(0,Q.jsx)(`span`,{className:`tree-name`,children:`会话库`})]}),(0,Q.jsx)(`div`,{hidden:!i,children:(0,Q.jsx)(d,{visible:i,children:t.tree})}),r.tree]})]}),children:e===`materials`?r.reader:e===`sessions`?t.reader:(0,Q.jsx)(He,{})})})})}export{We as ResourceLibrary};
@@ -1 +0,0 @@
1
- import{C as e,Ct as t,D as n,F as r,St as i,_t as a,c as o,ct as s,j as c,k as l,kt as u,ot as d,pt as f,ut as p,x as m,yt as h}from"./Dropdown-DXEtBxVr.js";import{B as g,I as _}from"./index-Rry2cw7w.js";var v=c();function y({url:e,name:t}){return(0,v.jsx)(`iframe`,{className:`html-preview`,title:`${t} 预览`,src:`${e}${e.includes(`?`)?`&`:`?`}view=html`,sandbox:``,referrerPolicy:`no-referrer`})}var b=u(),x=new Intl.Collator(`zh-CN`,{numeric:!0,sensitivity:`base`});function S(e,t){return x.compare(e,t)||(e<t?-1:+(e>t))}var C=`_project`,w=`_resources`,T=e=>e===`_project`||e===`_resources`,E=e=>/^_memory(?:\/|$)/i.test(e);t([p,a(C),a(w)]);var D=i().max(255).refine(e=>{let t=e.endsWith(`/`),n=t?e.slice(0,-1):e;return d.safeParse(n).success&&!n.includes(`/`)&&!n.startsWith(`.`)&&!/^_?teammy/i.test(n)&&!E(n)&&(t?n.startsWith(`_`):n.includes(`.`))},`Use a root file (README.md) or an underscore-prefixed directory (_template/).`);h({maintainer:p.nullable(),paths:f(D).max(30).refine(e=>new Set(e.map(e=>e.toLowerCase())).size===e.length),revision:s}).strict().omit({revision:!0}).extend({expectedRevision:s}).strict();function O(e){return e.split(`/`).some(e=>/^\.teammy(?:[-.]|$)/i.test(e))}function k(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 A=(e,t)=>`${e}/${t}`,j=e=>({"--tree-level":e});function M({members:e,...t}){let[n,r]=(0,b.useState)(()=>`folder:${A(e.find(e=>e.hasFiles)?.id??`_project`,``)}`);return(0,v.jsx)(`div`,{role:`tree`,"aria-label":`工作区文件`,"data-testid":`workspace-tree`,onKeyDown:k,children:(0,v.jsx)(P,{owner:C,path:``,level:1,members:e.filter(e=>e.hasFiles),context:{...t,focused:n,onFocus:r}})})}function N({owner:e,path:t,level:n,context:r}){let i=r.expanded.has(A(e,t)),a=`folder:${A(e,t)}`;return(0,v.jsxs)(`div`,{role:`none`,children:[(0,v.jsxs)(_,{type:`button`,role:`treeitem`,className:`tree-item tree-folder`,style:j(n),"aria-label":t||e,"aria-level":n,"aria-expanded":i,"aria-selected":r.selected?.kind===`directory`&&r.selected.owner===e&&r.selected.path===t,tabIndex:r.focused===a?0:-1,"data-testid":`directory-row`,"data-owner-id":e,"data-directory-path":t,onFocus:()=>r.onFocus(a),onClick:()=>r.onToggle(e,t),leading:(0,v.jsx)(`span`,{className:`tree-chevron ${i?`expanded`:``}`,children:(0,v.jsx)(o,{name:`chevron`,size:`small`})}),children:[(0,v.jsx)(o,{name:`files`}),(0,v.jsx)(`span`,{className:`tree-name`,children:t.split(`/`).at(-1)||e})]}),i&&(0,v.jsx)(P,{owner:e,path:t,level:n+1,context:r})]})}function P({owner:t,path:i,level:a,context:s,members:c=[]}){let{api:u,projectId:d}=g(),f=(0,b.useCallback)(e=>u.tree(t,i,void 0,``,e),[t,i]),p=n(f,!1,l(d,`file-tree`,t,i)),[h,y]=(0,b.useState)(),[x,C]=(0,b.useState)(!1),w=e(),D=(0,b.useRef)(null);(0,b.useEffect)(()=>()=>D.current?.abort(),[]);let k=h?.revision===p.data?.revision?h:void 0,M=k?k.nextCursor:p.data?.nextCursor;async function P(){if(!M||!p.data||x)return;C(!0),w(``);let e=new AbortController;D.current=e;try{let n=await u.tree(t,i,p.data.revision,M,e.signal);e.signal.aborted||y({...n,entries:[...k?.entries??[],...n.entries]})}catch(t){e.signal.aborted||w(r(t))}finally{e.signal.aborted||C(!1)}}let F=[...(p.data?.entries??[]).filter(e=>!O(e.path)),...(k?.entries??[]).filter(e=>!O(e.path))],I=s.revealed;if(I?.owner===t&&!O(I.path)&&(!i||I.path.startsWith(i+`/`))){let e=i?I.path.slice(i.length+1):I.path,t=e.indexOf(`/`),n=t<0?I.path:[i,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`||!E(e.path)).map(e=>({...e,owner:t})),...c.map(e=>({kind:`directory`,path:``,owner:e.id}))].sort((e,t)=>e.kind===t.kind?S(e.path.split(`/`).at(-1)||e.owner,t.path.split(`/`).at(-1)||t.owner):e.kind===`directory`?-1:1);return(0,v.jsxs)(`div`,{role:`group`,"aria-label":A(T(t)?`teamcontext`:t,i),"aria-busy":p.loading||x,children:[p.loading&&(0,v.jsx)(`p`,{className:`tree-status`,role:`status`,children:`正在加载…`}),(0,v.jsx)(m,{resource:p}),L.map(e=>e.kind===`directory`?(0,v.jsx)(N,{owner:e.owner,path:e.path,level:a,context:s},A(e.owner,e.path)):(0,v.jsxs)(_,{type:`button`,role:`treeitem`,className:`tree-item`,style:j(a),"aria-label":e.path,"aria-level":a,"aria-selected":s.selected?.kind===`file`&&s.selected.owner===t&&s.selected.path===e.path,tabIndex:s.focused===`file:${A(t,e.path)}`?0:-1,"data-testid":`file-row`,"data-owner-id":t,"data-file-path":e.path,onFocus:()=>s.onFocus(`file:${A(t,e.path)}`),onClick:()=>s.onSelect(t,e.path),leading:(0,v.jsx)(`span`,{className:`tree-chevron`}),children:[(0,v.jsx)(o,{name:`file`}),(0,v.jsx)(`span`,{className:`tree-name`,children:e.path.split(`/`).at(-1)})]},e.path)),M&&(0,v.jsx)(`button`,{className:`tree-action`,"data-testid":`files-load-more`,disabled:x,onClick:()=>void P(),children:x?`正在加载…`:`加载更多`})]})}export{E as a,S as c,C as i,y as l,A as n,O as o,k as r,T as s,M as t};