@teammy/server 0.2.0 → 0.2.2

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 (42) hide show
  1. package/README.md +3 -1
  2. package/dist/main.js +9204 -6966
  3. package/dist/project-pi-entry.js +60 -18
  4. package/dist/runtime/workflows/task-bootstrap/prompt.md +1 -1
  5. package/dist/web/assets/Assistant-ZM9at-n8.js +1 -0
  6. package/dist/web/assets/Computers-B9XbkIvb.css +1 -0
  7. package/dist/web/assets/Computers-CV-4FaxZ.js +3 -0
  8. package/dist/web/assets/Conversation-B-uSxDxY.css +1 -0
  9. package/dist/web/assets/Conversation-CZ8mOF1T.js +1 -0
  10. package/dist/web/assets/Dashboard-DIunax0h.css +1 -0
  11. package/dist/web/assets/Dashboard-wZpQ1Qxb.js +1 -0
  12. package/dist/web/assets/Files-DD-tWR-r.js +1 -0
  13. package/dist/web/assets/Help-DGI26Qe5.js +616 -0
  14. package/dist/web/assets/Help-DX51vBK7.css +1 -0
  15. package/dist/web/assets/{HtmlPreview-DcbwgS0C.js → HtmlPreview-TOlZ7wbO.js} +1 -1
  16. package/dist/web/assets/{Markdown-hcMXu8Z6.js → Markdown-Drn0H2RJ.js} +4 -4
  17. package/dist/web/assets/MessageComposer-DavJdQPa.css +1 -0
  18. package/dist/web/assets/MessageComposer-SftlQB1e.js +1 -0
  19. package/dist/web/assets/{Materials-CK-mbNmo.css → ResourceLibrary-COmSSC8U.css} +1 -1
  20. package/dist/web/assets/ResourceLibrary-RyTep8PC.js +6 -0
  21. package/dist/web/assets/WorkspaceTree-BEiahyEL.js +1 -0
  22. package/dist/web/assets/file-links-BYBi3BDP.js +1 -0
  23. package/dist/web/assets/index-6PvvMCD7.css +1 -0
  24. package/dist/web/assets/index-BQicHl1a.js +66 -0
  25. package/dist/web/assets/workflow-DM6NUqoB.svg +111 -0
  26. package/dist/web/downloads/teammy-skill.zip +0 -0
  27. package/dist/web/index.html +2 -2
  28. package/package.json +1 -1
  29. package/dist/web/assets/Assistant-C7QfFYLo.css +0 -1
  30. package/dist/web/assets/Assistant-Drm0mOLL.js +0 -1
  31. package/dist/web/assets/Dashboard-C6aBw_W-.css +0 -1
  32. package/dist/web/assets/Dashboard-DRhlMd50.js +0 -1
  33. package/dist/web/assets/Files-BP2rAhTa.js +0 -1
  34. package/dist/web/assets/Materials-CTSi5rOS.js +0 -6
  35. package/dist/web/assets/Memory-C-z-5rpe.css +0 -1
  36. package/dist/web/assets/Memory-H9tRDj1a.js +0 -1
  37. package/dist/web/assets/Sessions-BwXwXx6i.css +0 -1
  38. package/dist/web/assets/Sessions-CvUoOrHZ.js +0 -1
  39. package/dist/web/assets/WorkspaceTree-D52TBZvy.js +0 -1
  40. package/dist/web/assets/file-links-QvRdAx7G.js +0 -1
  41. package/dist/web/assets/index-Bb8MF7Vk.js +0 -66
  42. package/dist/web/assets/index-Swfty9kO.css +0 -1
@@ -1,8 +1,42 @@
1
+ // packages/transport/result-files.ts
2
+ import { createHash } from "node:crypto";
3
+ import { mkdir, writeFile } from "node:fs/promises";
4
+ import { join } from "node:path";
5
+ async function materializeToolFiles(value, directory) {
6
+ if (Array.isArray(value))
7
+ return Promise.all(value.map((item) => materializeToolFiles(item, directory)));
8
+ if (!value || typeof value !== "object") return value;
9
+ const object = value;
10
+ if (object.format === "teammy-text-file" && typeof object.content === "string") {
11
+ const content = object.content, hash = createHash("sha256").update(content).digest("hex");
12
+ const path = join(directory, `${hash}.md`);
13
+ await mkdir(directory, { recursive: true, mode: 448 });
14
+ await writeFile(path, content, { mode: 384 });
15
+ const lines = content.split("\n");
16
+ return {
17
+ path,
18
+ bytes: Buffer.byteLength(content),
19
+ lines: lines.length,
20
+ headings: lines.flatMap(
21
+ (line, index) => /^(#{1,6})\s+/.test(line) ? [{ title: line.replace(/^#+\s+/, ""), line: index + 1 }] : []
22
+ )
23
+ };
24
+ }
25
+ return Object.fromEntries(
26
+ await Promise.all(
27
+ Object.entries(object).map(async ([key, item]) => [
28
+ key,
29
+ await materializeToolFiles(item, directory)
30
+ ])
31
+ )
32
+ );
33
+ }
34
+
1
35
  // apps/server/agents/pi-entry.ts
2
36
  import { spawn } from "node:child_process";
3
37
  import { existsSync as existsSync2 } from "node:fs";
4
- import { mkdir as mkdir2, readFile as readFile2 } from "node:fs/promises";
5
- import { join as join2, basename } from "node:path";
38
+ import { mkdir as mkdir3, readFile as readFile2 } from "node:fs/promises";
39
+ import { join as join3, basename } from "node:path";
6
40
  import { InMemoryCredentialStore, InMemoryModelsStore, Type as Type3 } from "@earendil-works/pi-ai";
7
41
  import { createAssistantMessageEventStream } from "@earendil-works/pi-ai/utils/event-stream";
8
42
  import {
@@ -118,9 +152,9 @@ function loadAgentSkills(directory = `${agentResourcesPath}/skills`) {
118
152
  }
119
153
 
120
154
  // apps/server/ai/context-content.ts
121
- import { createHash, randomUUID } from "node:crypto";
122
- import { link, mkdir, readFile, rm, writeFile } from "node:fs/promises";
123
- import { join } from "node:path";
155
+ import { createHash as createHash2, randomUUID } from "node:crypto";
156
+ import { link, mkdir as mkdir2, readFile, rm, writeFile as writeFile2 } from "node:fs/promises";
157
+ import { join as join2 } from "node:path";
124
158
  import { z } from "zod";
125
159
  var CONTENT_BYTES = 32 * 1024;
126
160
  var CONTENT_LINES = 500;
@@ -166,13 +200,13 @@ var ContextContent = class {
166
200
  directory;
167
201
  async present(value, source) {
168
202
  if (contentFits(value)) return value;
169
- const body = json({ source, value }), id = createHash("sha256").update(body).digest("hex");
170
- await mkdir(this.directory, { recursive: true, mode: 448 });
171
- const temporary = join(this.directory, randomUUID() + ".tmp");
203
+ const body = json({ source, value }), id = createHash2("sha256").update(body).digest("hex");
204
+ await mkdir2(this.directory, { recursive: true, mode: 448 });
205
+ const temporary = join2(this.directory, randomUUID() + ".tmp");
172
206
  try {
173
- await writeFile(temporary, body, { flag: "wx", mode: 384 });
207
+ await writeFile2(temporary, body, { flag: "wx", mode: 384 });
174
208
  try {
175
- await link(temporary, join(this.directory, id + ".json"));
209
+ await link(temporary, join2(this.directory, id + ".json"));
176
210
  } catch (error) {
177
211
  if (error.code !== "EEXIST") throw error;
178
212
  }
@@ -197,7 +231,7 @@ var ContextContent = class {
197
231
  const { id, path, offset, limit } = ReadToolResultSchema.parse(input);
198
232
  let body;
199
233
  try {
200
- body = await readFile(join(this.directory, id + ".json"), "utf8");
234
+ body = await readFile(join2(this.directory, id + ".json"), "utf8");
201
235
  } catch {
202
236
  throw new HubError(
203
237
  404,
@@ -205,7 +239,7 @@ var ContextContent = class {
205
239
  "\u6B64\u7ED3\u679C\u4E0D\u5728\u5F53\u524D\u4F1A\u8BDD\u6216\u5DF2\u4E0D\u53EF\u7528\uFF0C\u8BF7\u91CD\u65B0\u67E5\u8BE2\u539F\u59CB\u8D44\u6599\u3002"
206
240
  );
207
241
  }
208
- if (createHash("sha256").update(body).digest("hex") !== id)
242
+ if (createHash2("sha256").update(body).digest("hex") !== id)
209
243
  throw new HubError(409, "TOOL_RESULT_CHANGED", "\u7ED3\u679C\u5FEB\u7167\u5DF2\u6539\u53D8\uFF0C\u8BF7\u91CD\u65B0\u67E5\u8BE2\u539F\u59CB\u8D44\u6599\u3002");
210
244
  const saved = JSON.parse(body);
211
245
  let value = saved.value;
@@ -354,7 +388,7 @@ async function piChild() {
354
388
  ]);
355
389
  if (session && key === configKey) return;
356
390
  session?.dispose();
357
- await mkdir2(input.sessionDir, { recursive: true });
391
+ await mkdir3(input.sessionDir, { recursive: true });
358
392
  manager = input.transient ? SessionManager.inMemory(input.cwd ?? "/project") : input.sessionFile && existsSync2(input.sessionFile) ? SessionManager.open(input.sessionFile, input.sessionDir, input.cwd ?? "/project") : SessionManager.create(input.cwd ?? "/project", input.sessionDir);
359
393
  const modelRuntime = await ModelRuntime.create({
360
394
  credentials: new InMemoryCredentialStore(),
@@ -396,7 +430,8 @@ async function piChild() {
396
430
  reload: async () => {
397
431
  }
398
432
  };
399
- const content = new ContextContent(join2(input.sessionDir, "content"));
433
+ const content = new ContextContent(join3(input.sessionDir, "content"));
434
+ const inputRunScope = input.sessionDir.split("/").at(-1);
400
435
  const customTools = input.tools.map((tool) => ({
401
436
  name: tool.name,
402
437
  label: tool.label,
@@ -404,7 +439,11 @@ async function piChild() {
404
439
  parameters: Type3.Unsafe(tool.schema),
405
440
  execute: async (_id, params) => {
406
441
  let input2 = params;
407
- if (tool.name === "save_material") {
442
+ if ([
443
+ "create_project_material",
444
+ "update_project_material",
445
+ "save_project_material_content"
446
+ ].includes(tool.name)) {
408
447
  const source = params;
409
448
  const originals = source.originals ?? source.appendOriginals;
410
449
  input2 = {
@@ -420,13 +459,16 @@ async function piChild() {
420
459
  } : {}
421
460
  };
422
461
  }
423
- const value = await rpc(tool.name, input2);
462
+ const value = await materializeToolFiles(
463
+ await rpc(tool.name, input2),
464
+ "/tmp/teammy-files/" + inputRunScope
465
+ );
424
466
  return { content: [{ type: "text", text: JSON.stringify(value) }], details: value };
425
467
  }
426
468
  }));
427
469
  const created = await createAgentSession({
428
470
  cwd: input.cwd ?? "/project",
429
- agentDir: join2(input.sessionDir, "agent"),
471
+ agentDir: join3(input.sessionDir, "agent"),
430
472
  modelRuntime,
431
473
  model: input.model,
432
474
  thinkingLevel: "off",
@@ -546,7 +588,7 @@ async function piChild() {
546
588
  });
547
589
  try {
548
590
  await native.prompt(
549
- await new ContextContent(join2(input.sessionDir, "content")).input(
591
+ await new ContextContent(join3(input.sessionDir, "content")).input(
550
592
  interrupted ? `\u6B64\u524D\u8FD9\u4E00\u8F6E\u6267\u884C\u4E2D\u65AD\u6216\u672A\u6210\u529F\uFF0C\u8BF7\u7ED3\u5408\u5DF2\u4FDD\u5B58\u7684\u4E0A\u4E0B\u6587\u7EE7\u7EED\u3002\u5DF2\u63D0\u4EA4\u64CD\u4F5C\u7684\u56DE\u6267\u4ECD\u6709\u6548\uFF0C\u4E0D\u8981\u91CD\u590D\u53D1\u9001\uFF1B\u6682\u5B58\u56DE\u7B54\u548C\u5B8C\u6210\u62A5\u544A\u5C1A\u672A\u63D0\u4EA4\uFF0C\u8BF7\u91CD\u65B0\u6838\u5BF9\u540E\u7ED9\u51FA\u672C\u8F6E\u7ED3\u8BBA\u3002\u539F\u8F93\u5165\uFF1A
551
593
  ${input.text}` : input.text
552
594
  )
@@ -50,7 +50,7 @@ query_tasks 返回任务的当前内容,已经包含用户保存的修改,
50
50
 
51
51
  成员目录也可能包含 Tim 根据用户确认新建或修订的工作文件,与用户本地文件按实际内容共同理解;创建文件不代表已经创建卡片,不要求一文件一卡片。先查询已有任务和来源,修订已有任务文件时继续相关任务,避免重复。query_tasks 的 movedSources 说明系统为避让同名文件而迁移的来源路径,可沿新路径继续核对原任务,不把换名本身当成新增工作。
52
52
 
53
- `_task_update/` 保存关联已有任务的进展和人工修正。query_tasks 的 updates 给出对应的当前文件及版本,可按需读取;这些记录用于维护原任务,不单独生成新任务,其 README 只是目录说明。网页人工修正已即时进入当前任务,补充文件用于保留依据;仅重新读到旧内容不得撤销当前判断,后续有新的实质证据仍可更新。Agent 新增的补充记录只表达文件中的事实,需本轮分析后才更新卡片。不要根据记录日期机械判断状态优先级。
53
+ 任务目录内的 `_task_update/` 保存关联已有任务的进展和人工修正。query_tasks 的 updates 给出对应的当前文件及版本,可按需读取;这些记录用于维护原任务,不单独生成新任务,其 README 只是目录说明。网页人工修正已即时进入当前任务,补充文件用于保留依据;仅重新读到旧内容不得撤销当前判断,后续有新的实质证据仍可更新。Agent 新增的补充记录只表达文件中的事实,需本轮分析后才更新卡片。不要根据记录日期机械判断状态优先级。
54
54
 
55
55
  ## 分析范围与复核
56
56
 
@@ -0,0 +1 @@
1
+ import{F as e,G as t,H as n,I as r,J as i,K as ee,L as a,N as o,P as s,U as c,W as l,_t as u,a as te,dt as d,g as f,i as ne,lt as p,n as m,o as h,ot as g,pt as re,r as ie,st as _,t as ae,ut as v,vt as oe,y as se}from"./index-BQicHl1a.js";import{t as y}from"./Markdown-Drn0H2RJ.js";import{a as ce,i as le,n as ue,r as de,t as fe}from"./Conversation-CZ8mOF1T.js";import{t as pe}from"./MessageComposer-SftlQB1e.js";var b=u(),x=t(),me=v({topics:g(v({id:d(),title:d(),summary:d(),author:d(),replies:p(),unread:_(),createdAt:d(),updatedAt:d(),delivery:v({available:_(),connected:_(),state:d(),error:d().nullable()})}))}),he=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),S=e=>e.replace(/[#*_`>]/g,``).replace(/\s+/g,` `).trim();function C({me:t,mode:u=`messages`}){let{projectId:p,request:g}=se(),C=l(),_e=c(p,t,`${u}-selection`),w=c(p,t,`${u}-drafts`),ve=(0,b.useCallback)(e=>g(`agents/outbox`,te,{signal:e}),[g]),T=n(ve,3e3,c(p,t,`outbox`)),ye=(0,b.useCallback)(async e=>u===`messages`?g(`agents/chats`,ae,{signal:e}):{chats:(await g(`channels/topics`,me,{signal:e})).topics.map(e=>({...e,kind:`matter`,state:null}))},[g,u]),E=n(ye,3e3,c(p,t,u,`chats`)),[D,be]=(0,b.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`chat`);return t?`chat:${t}`:e.get(`message`)??C?.get(_e)??``}),O=D.startsWith(`chat:`)?D.slice(5):``,k=!D||!!O,[A,j]=(0,b.useState)(()=>C?.get(c(p,t,`chat`,O))),M=A?.id===O?A:C?.get(c(p,t,`chat`,O)),N=E.data?.chats.find(e=>e.id===O),P=N&&`delivery`in N?N.delivery:void 0,[xe,F]=(0,b.useState)(),[I,L]=(0,b.useState)(()=>C?.get(w)??{}),Se=I[D]??``,Ce=e=>L(t=>({...t,[D]:e})),[R,z]=(0,b.useState)(!1),[B,we]=(0,b.useState)(!1),[Te,V]=(0,b.useState)(!1),[H,Ee]=(0,b.useState)(``),[De,Oe]=(0,b.useState)(``),ke=(0,b.useRef)(crypto.randomUUID()),[Ae,U]=(0,b.useState)(``),[je,W]=(0,b.useState)(``),G=(0,b.useRef)(new Map),Me=(0,b.useRef)(null),K=(0,b.useRef)(!0),q=(0,b.useRef)(D);q.current=D,(0,b.useEffect)(()=>{A&&C?.set(c(p,t,`chat`,A.id),A)},[C,p,t,A]),(0,b.useEffect)(()=>{C?.set(w,I)},[C,w,I]);function J(e){q.current=e,be(e),C?.set(_e,e);let t=new URL(location.href);e.startsWith(`chat:`)?t.searchParams.set(`chat`,e.slice(5)):t.searchParams.delete(`chat`),e&&!e.startsWith(`chat:`)&&e!==`debug`?t.searchParams.set(`message`,e):t.searchParams.delete(`message`),history.replaceState(history.state,``,t)}(0,b.useEffect)(()=>{!D&&E.data?.chats.length&&J(`chat:${E.data.chats[0].id}`)},[D,E.data]);let Y=(T.data?.messages??[]).filter(e=>u===`messages`&&e.box===`debug`).reverse(),X=T.data?.messages.find(e=>e.id===(D===`debug`?xe:D));(0,b.useEffect)(()=>{D!==`debug`&&X?.conversationId&&J(`chat:${X.conversationId}`)},[D,X?.conversationId]);let Z=Y.filter(e=>!e.readAt).map(e=>e.id).join(`,`);(0,b.useEffect)(()=>{X&&!X.readAt&&D!==`debug`&&g(`agents/outbox/${X.id}/read`,h,{method:`POST`}).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),T.reload()}).catch(e=>U(i(e)))},[X?.id,X?.readAt,D,g,T.reload]),(0,b.useEffect)(()=>{D===`debug`&&Z&&Promise.all(Z.split(`,`).map(e=>g(`agents/outbox/${e}/read`,h,{method:`POST`}))).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),T.reload()}).catch(e=>U(i(e)))},[D,Z,g,T.reload]),(0,b.useEffect)(()=>{if(W(``),!O)return;let e=!0,n=-1,r=!1,a=new AbortController,o=t=>{!e||t.id!==O||t.cursor<n||(n=t.cursor,r=!0,t.redirect?J(`chat:${t.redirect}`):t.entry===`channel`&&u!==`channels`?location.replace(oe(`/projects/${p}/channels?chat=${t.id}`)):(j(t),W(``)))};g(`agents/chats/${O}`,m,{signal:a.signal}).then(o).catch(n=>{e&&!a.signal.aborted&&(n instanceof ee&&[401,403,404].includes(n.status)&&(C?.delete(c(p,t,`chat`,O)),j(e=>e?.id===O?void 0:e)),r||W(i(n)))});let s=t=>{let r=Number(t.lastEventId);return!e||!Number.isSafeInteger(r)||r<=n?!1:(n=r,!0)},l=new EventSource(oe(`/api/v1/projects/${encodeURIComponent(p)}/agents/chats/${encodeURIComponent(O)}/events`));l.addEventListener(`snapshot`,t=>{if(e)try{o(m.parse(JSON.parse(t.data)))}catch(e){W(i(e))}}),l.onerror=()=>{e&&W(`对话连接中断,正在重新连接…`)},l.addEventListener(`context`,e=>{if(!s(e))return;let t=m.pick({kind:!0,title:!0,status:!0,visibility:!0,participants:!0,pending:!0,hold:!0,redirect:!0}).parse(JSON.parse(e.data));t.redirect?J(`chat:${t.redirect}`):j(e=>e?.id===O?{...e,...t,cursor:n}:e)}),l.addEventListener(`message`,e=>{if(!s(e))return;let t=ie.parse(JSON.parse(e.data));j(n=>n?.id===O?{...n,readCursor:Math.max(n.readCursor,t.seq),cursor:Math.max(n.cursor,Number(e.lastEventId)||0),messages:[...n.messages.filter(e=>e.id!==t.id),t].sort((e,t)=>e.seq-t.seq)}:n)}),l.addEventListener(`message_removed`,e=>{if(!s(e))return;let{id:t}=v({id:d()}).parse(JSON.parse(e.data));j(e=>e?.id===O?{...e,cursor:n,messages:e.messages.filter(e=>e.id!==t)}:e)}),l.addEventListener(`run`,e=>{if(!s(e))return;let t=ne.parse(JSON.parse(e.data));j(n=>n?.id===O?{...n,cursor:Math.max(n.cursor,Number(e.lastEventId)||0),runs:n.runs.some(e=>e.id===t.id)?n.runs:[...n.runs,t]}:n)});for(let e of[`delta`,`reset`,`state`])l.addEventListener(e,t=>{if(!s(t))return;let n=JSON.parse(t.data);j(r=>r?.id===O?{...r,cursor:Math.max(r.cursor,Number(t.lastEventId)||0),messages:r.messages.map(t=>t.runId!==n.id||t.role!==`assistant`?t:{...t,body:e===`delta`?t.body+(n.text??``):e===`reset`?``:n.answer??t.body,state:n.state??t.state}),runs:r.runs.map(t=>t.id===n.id?{...t,answer:e===`delta`?t.answer+(n.text??``):e===`reset`?``:n.answer??t.answer,state:n.state??t.state,error:n.error===void 0?t.error:n.error}:t)}:r)});return()=>{e=!1,a.abort(),l.close()}},[p,O,t,g,C]),(0,b.useEffect)(()=>{if(!M||M.id!==O)return;let e=()=>{document.visibilityState===`visible`&&g(`agents/chats/${O}/read`,v({ok:_()}),{method:`POST`,body:{cursor:M.readCursor}}).then(()=>{E.reload(),window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>U(i(e)))},t=setTimeout(e,300);return document.addEventListener(`visibilitychange`,e),()=>{clearTimeout(t),document.removeEventListener(`visibilitychange`,e)}},[O,M?.readCursor,M?.kind,g]),(0,b.useEffect)(()=>{K.current&&Me.current?.scrollIntoView({block:`end`})},[D,A?.messages,X?.recipients,Y.length]);function Ne(){window.dispatchEvent(new Event(`teammy:outbox`)),T.reload()}async function Q(e){if(K.current=!0,J(e),U(``),F(void 0),e.startsWith(`chat:`)||e===`debug`)return;let t=T.data?.messages.find(t=>t.id===e)?.conversationId;if(t)J(`chat:${t}`);else try{await g(`agents/outbox/${e}/read`,h,{method:`POST`}),Ne()}catch(e){U(i(e))}}async function Pe(){if(!B){we(!0),U(``);try{let e=await g(`agents/chats`,m,{method:`POST`});j(e),await Q(`chat:${e.id}`),E.reload()}catch(e){U(i(e))}finally{we(!1)}}}async function Fe(e){e.preventDefault();let t=Se.trim();if(!t||R||B)return;z(!0),U(``);let n=G.current.get(D);n&&n.text===t||(n={text:t,id:crypto.randomUUID()},G.current.set(D,n));try{if(k){let e=n.target??O;if(!e){let r=await g(`agents/chats`,m,{method:`POST`});e=r.id,n.target=e,G.current.set(`chat:${e}`,n),L(n=>({...n,[`chat:${e}`]:t})),q.current===D&&(j(r),J(`chat:${e}`))}let r=await g(`agents/chats/${e}`,ne.extend({conversationId:d().optional()}),{method:`POST`,body:{text:t,requestId:n.id}});r.conversationId&&r.conversationId!==e&&(q.current===D||q.current===`chat:${e}`)&&J(`chat:${r.conversationId}`),j(t=>t?.id===e?{...t,runs:t.runs.some(e=>e.id===r.id)?t.runs:[...t.runs,r]}:t),E.reload()}else{let e=await g(`agents/outbox/${X.id}/reply`,v({conversationId:d()}),{method:`POST`,body:{body:t,requestId:n.id}});Ne(),q.current===D&&J(`chat:${e.conversationId}`),E.reload(),F(void 0)}G.current.delete(D),n.target&&G.current.delete(`chat:${n.target}`),L(e=>({...e,[D]:``,...n.target?{[`chat:${n.target}`]:``}:{}}))}catch(e){U(i(e))}finally{z(!1)}}let Ie=u===`channels`?le:fe,Le=k&&!M?.closed&&(u!==`channels`||!!O)||!!X&&!X.archivedAt,$=k&&!M&&(!!O||!E.data);return(0,x.jsxs)(de,{className:u===`channels`?`channel-layout`:``,testId:`assistant-page`,label:k?`Tim对话`:`消息内容`,navigation:(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`header`,{className:`assistant-list-heading`,children:[(0,x.jsx)(`h1`,{children:u===`channels`?`频道`:`对话`}),(0,x.jsx)(s,{className:`assistant-new-chat`,icon:`plus`,label:u===`channels`?`发表话题`:`新建对话`,disabled:B,onClick:()=>u===`channels`?V(!0):void Pe(),"data-testid":`assistant-launcher`})]}),(0,x.jsxs)(`div`,{className:`assistant-message-scroll`,children:[E.loading&&!E.data&&(0,x.jsx)(`p`,{className:`assistant-list-status`,role:`status`,children:`加载中…`}),E.data?.chats.map(e=>(0,x.jsxs)(`button`,{type:`button`,"data-testid":`assistant-chat-${e.id}`,className:`assistant-message-item assistant-chat-item ${O===e.id?`selected`:``}`,"aria-pressed":O===e.id,onClick:()=>void Q(`chat:${e.id}`),children:[(0,x.jsx)(`span`,{className:`assistant-message-dot ${e.unread||e.state===`running`||e.state===`queued`?`unread`:``}`}),(0,x.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,x.jsx)(f,{selected:O===e.id,children:(0,x.jsx)(`strong`,{children:e.title})}),u===`channels`&&`summary`in e&&(0,x.jsx)(`span`,{className:`topic-preview`,children:S(String(e.summary)).slice(0,140)}),(0,x.jsxs)(`time`,{dateTime:e.updatedAt,children:[new Date(e.updatedAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,he(e.updatedAt)]})]})]},e.id)),!!Y.length&&(0,x.jsxs)(`button`,{type:`button`,"data-testid":`debug-outbox`,className:`assistant-message-item ${D===`debug`?`selected`:``}`,onClick:()=>void Q(`debug`),children:[(0,x.jsx)(`span`,{className:`assistant-message-dot ${Z?`unread`:``}`}),(0,x.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,x.jsx)(f,{selected:D===`debug`,children:(0,x.jsx)(`strong`,{children:`运行提醒`})}),(0,x.jsx)(`span`,{children:S(Y.at(-1).body)})]})]}),T.data?.messages.filter(e=>u===`messages`&&e.box!==`debug`&&!e.conversationId).sort((e,t)=>Number(!!e.archivedAt)-Number(!!t.archivedAt)).map(e=>(0,x.jsxs)(`button`,{type:`button`,"data-testid":`outbox-${e.id}`,className:`assistant-message-item ${e.archivedAt?`archived`:``} ${D===e.id?`selected`:``}`,onClick:()=>void Q(e.id),children:[(0,x.jsx)(`span`,{className:`assistant-message-dot ${e.readAt?``:`unread`}`}),(0,x.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,x.jsx)(f,{selected:D===e.id,children:(0,x.jsx)(`strong`,{children:S(e.body)})}),(0,x.jsxs)(`time`,{dateTime:e.createdAt,children:[new Date(e.createdAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,he(e.createdAt)]})]})]},e.id))]}),(0,x.jsx)(a,{error:!0,children:T.error||E.error})]}),children:[Te&&(0,x.jsxs)(r,{id:`new-topic`,title:`发表话题`,onClose:()=>V(!1),children:[(0,x.jsx)(pe,{inset:!0,plain:!0,value:De,onChange:Oe,label:`正文`,placeholder:`开始一个话题…`,sendLabel:`发表话题`,sendDisabled:R||!H.trim(),heading:(0,x.jsx)(`input`,{className:`topic-title`,"aria-label":`标题`,placeholder:`标题`,required:!0,value:H,onChange:e=>Ee(e.target.value)}),onSubmit:e=>{e.preventDefault(),z(!0),U(``),g(`channels/topics`,m,{method:`POST`,body:{id:ke.current,title:H,body:De}}).then(e=>{j(e),J(`chat:${e.id}`),V(!1),Ee(``),Oe(``),ke.current=crypto.randomUUID(),E.reload()}).catch(e=>U(i(e))).finally(()=>z(!1))}}),(0,x.jsx)(a,{error:!0,children:Ae})]}),(0,x.jsx)(ue,{title:(0,x.jsx)(`h2`,{children:k?N?.title??M?.title??(O?`无标题`:`Tim`):D===`debug`?`运行提醒`:`项目消息`}),actions:(0,x.jsxs)(x.Fragment,{children:[u!==`channels`&&M?.kind===`matter`&&(0,x.jsxs)(`span`,{className:`assistant-participants`,title:M.participants?.join(`、`),children:[M.visibility===`project`?`项目共享 · `:``,M.participants?.join(`、`)]}),u===`channels`&&P?.available&&(P.state===`web`||P.state===`cancelled`||!P.connected)&&(0,x.jsx)(s,{icon:`send`,label:`发布到企业微信频道`,disabled:R,onClick:()=>{z(!0),g(`channels/topics/${O}/publish`,re(),{method:`POST`}).then(()=>E.reload()).catch(e=>U(i(e))).finally(()=>z(!1))}})]})}),u===`channels`&&(0,x.jsx)(a,{error:!0,children:P?.error}),u!==`channels`&&M?.kind===`matter`&&(M.hold||M.pending||M.status===`completed`)&&(0,x.jsx)(`div`,{className:`assistant-matter-state`,role:`status`,children:M.hold?`${M.hold.scope===`all`?`已暂停`:`暂缓修改`} · ${M.hold.reason}`:M.pending?`待确认 · ${M.pending.members.join(`、`)}:${M.pending.question}`:`已完成`}),(0,x.jsxs)(ce,{"data-testid":`assistant-transcript`,onScroll:e=>{let t=e.currentTarget;K.current=t.scrollHeight-t.scrollTop-t.clientHeight<100},children:[k?$?(0,x.jsxs)(`div`,{className:`assistant-empty`,"data-testid":`assistant-loading`,children:[(0,x.jsx)(e,{}),(0,x.jsx)(`p`,{role:`status`,children:je||E.error?`暂时无法加载对话`:`加载中…`})]}):M?.messages.length?M.messages.filter(e=>e.body||[`queued`,`running`,`failed`].includes(e.state)).map(e=>(0,x.jsx)(`div`,{className:`assistant-turn`,children:(0,x.jsxs)(Ie,{mine:e.role===`user`&&e.author===t,author:`${e.role===`assistant`?`Tim`:e.author}${e.source===`wecom`?` · 企业微信`:``}`,time:e.createdAt,children:[e.body&&(0,x.jsx)(`div`,{className:`markdown`,children:(0,x.jsx)(y,{children:e.body})}),e.role===`assistant`&&[`queued`,`running`].includes(e.state)&&(0,x.jsxs)(`span`,{className:`assistant-typing`,"aria-label":`正在回答`,children:[(0,x.jsx)(`i`,{}),(0,x.jsx)(`i`,{}),(0,x.jsx)(`i`,{})]}),e.state===`failed`&&(0,x.jsx)(a,{error:!0,children:M.runs.find(t=>t.id===e.runId)?.error||`本次回答未完成。`})]})},e.id)):(0,x.jsxs)(`div`,{className:`assistant-empty`,children:[(0,x.jsx)(e,{}),(0,x.jsx)(`p`,{children:`有什么项目问题想聊聊?`})]}):!T.data&&T.loading?(0,x.jsx)(`div`,{className:`assistant-empty`,children:(0,x.jsx)(`p`,{role:`status`,children:`加载中…`})}):D===`debug`?Y.map(e=>(0,x.jsx)(ge,{item:e,onReply:e.archivedAt?void 0:()=>{F(e.id),Ce(``),U(``)}},e.id)):X&&(0,x.jsx)(ge,{item:X}),(0,x.jsx)(`div`,{ref:Me})]}),(0,x.jsx)(a,{error:!0,children:Ae||(k?je:``)}),Le?(0,x.jsx)(pe,{value:Se,onChange:Ce,onSubmit:e=>void Fe(e),disabled:B,sendDisabled:R||$,label:k?`向Tim提问`:`回复消息`}):D!==`debug`&&X&&(0,x.jsxs)(`div`,{className:`assistant-archived`,children:[(0,x.jsx)(o,{name:`archive`}),`已归档`]})]})}function ge({item:e,onReply:t}){return(0,x.jsx)(`div`,{"data-testid":`outbox-thread-${e.id}`,children:(0,x.jsxs)(fe,{author:e.box===`debug`?`运行提醒`:`Tim`,time:e.createdAt,children:[(0,x.jsx)(`div`,{className:`markdown`,children:(0,x.jsx)(y,{children:e.body})}),t&&(0,x.jsx)(`button`,{type:`button`,className:`assistant-debug-reply`,onClick:t,children:`回复`})]})})}export{C as Assistant};
@@ -0,0 +1 @@
1
+ .inline-reply{width:clamp(180px, var(--reply-width,180px), 600px);border:1px solid var(--color-line);border-radius:var(--radius-sm);background:0 0;align-items:flex-end;gap:4px;max-width:100%;padding:3px 6px;display:flex}.inline-reply:focus-within{border-color:var(--color-muted)}.inline-reply textarea{width:100%;min-width:0;min-height:28px;max-height:180px;font-size:var(--text-sm);resize:none;box-shadow:none;background:0 0;border:0;padding:3px 2px;line-height:22px}.inline-reply textarea:focus{box-shadow:none;outline:none}.inline-reply-send{background:0 0;border:0;flex:0 0 26px;place-items:center;width:26px;height:28px;min-height:28px;padding:3px;display:grid}.composer-menu .dropdown-trigger{height:30px;min-height:30px;font-size:var(--text-xs);color:var(--color-muted);background:var(--color-soft);border-radius:18px;align-items:center;gap:4px;max-width:min(190px,100%);padding:5px 9px;display:flex}.composer-menu .dropdown-trigger>span{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.composer-menu .dropdown-trigger:hover,.composer-menu .dropdown-trigger[aria-expanded=true]{color:var(--color-text);background:var(--color-hover)}.composer-commands .dropdown-trigger{background:var(--color-soft);border-radius:50%;justify-content:center;width:30px;padding:6px}.composer-menu .dropdown-menu{--dropdown-max-height:45dvh;width:300px;max-width:calc(100vw - var(--sidebar-width) - 32px);max-height:45dvh;top:auto;bottom:calc(100% + 12px)}.composer-menu .dropdown-menu [role=menuitem]{font-size:var(--text-sm);justify-content:space-between;gap:12px;padding:10px}.composer-option-copy{text-align:left;flex-direction:column;gap:3px;min-width:0;display:flex}.composer-option-copy small,.composer-menu-heading small{font-size:var(--text-xs);color:var(--color-muted);font-weight:400}.composer-menu code{color:var(--color-muted);background:0 0;font-size:11px}.composer-menu-heading{font-size:var(--text-sm);justify-content:space-between;gap:12px;padding:8px 10px;display:flex}@media (width<=600px){.composer-menu .dropdown-menu{width:calc(100vw - var(--sidebar-width) - 16px);max-width:none}.composer-menu .dropdown-trigger{max-width:min(140px,100%)}}.composer-choice{flex:0 auto;min-width:0}.composer-commands{flex-shrink:0}.composer-commands .icon{width:17px;height:17px}.composer-commands .dropdown-menu{width:640px}.composer-commands .dropdown-menu [role=menuitem]{padding:8px 10px}.composer-command-row{align-items:center;gap:20px;width:100%;min-width:0;display:flex}.composer-command-name{flex:0 190px;min-width:0}.composer-command-row small{min-width:0;color:var(--color-muted);font-weight:400;font-size:var(--text-xs);flex:1}.composer-command-row>*{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}@media (width<=600px){.composer-commands .dropdown-menu{width:calc(100vw - var(--sidebar-width) - 16px)}.composer-command-name{flex-basis:42%}.composer-command-row{gap:10px}}.composer-option-copy small{text-overflow:ellipsis;white-space:nowrap;max-width:260px;overflow:hidden}.computer-panel{border-bottom:1px solid var(--color-line);max-height:55vh;padding:16px 24px;overflow:auto}.config-fields{grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:12px;padding:12px 0;display:grid}.config-fields label{flex-direction:column;gap:6px;display:flex}.native-question,.native-question>div{min-width:0}.native-question>div+div{margin-top:12px}.native-question>div>:not(:first-child){margin-top:8px}.native-question p{color:var(--color-text);font-size:var(--text-base);margin:0}.question-response,.question-result{align-items:baseline;gap:6px;margin-top:8px;display:flex}.question-response span{white-space:pre-wrap;overflow-wrap:anywhere}.question-result{color:var(--color-muted);font-size:var(--text-xs)}.question-response .icon,.question-result .icon{width:12px;height:12px;color:var(--color-muted);flex-shrink:0}.question-bubble .assistant-bubble{width:max-content}.question-options button{min-height:32px;font-size:var(--text-sm);background:0 0;padding:6px 10px;font-weight:500}.question-options button[aria-pressed=true]{background:var(--color-accent-soft);color:var(--brand-orange)}.question-options,.question-actions{flex-wrap:wrap;gap:8px;display:flex}.native-question input{width:100%;margin-top:8px}.question-options button[aria-pressed=true]{border-color:var(--brand-orange)}.computer-control-status{margin:0;padding:4px 24px;font-size:12px}@media (width<=760px){.computer-panel{padding:12px}}.computer-tree{padding:4px}.computer-device{font-size:var(--text-sm);align-items:center;gap:8px;margin:0 0 14px;font-weight:600;display:flex}.computer-device>span{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.computer-connection{flex-shrink:0;display:inline-flex}.computer-connection.online .icon rect{fill:var(--brand-orange);fill-opacity:.85}.computer-paths{color:var(--color-muted);font-size:var(--text-xs);overflow-wrap:anywhere;margin:8px 0;display:block}.computer-tree .tree-name{flex:1}.computer-panel{flex-shrink:0}#computer-settings .computer-panel{border:0;max-height:70dvh;padding:0}.computer-create-menu .dropdown-trigger{place-items:center;width:32px;height:32px;padding:4px;display:grid}.computer-create-menu .dropdown-menu{width:180px;left:auto;right:0}.session-rename{font:inherit;font-weight:inherit;text-align:left;text-overflow:ellipsis;white-space:nowrap;background:0 0;border:0;border-radius:0;max-width:100%;padding:0;overflow:hidden}.session-rename:hover{color:var(--color-muted);background:0 0}.session-title-form{flex:1;min-width:0;margin-right:16px}.session-title-form input{width:100%}
@@ -0,0 +1,3 @@
1
+ import{C as e,E as t,G as n,H as r,I as i,J as a,L as o,N as s,P as c,S as l,T as u,_t as d,b as f,d as p,dt as m,h,j as g,k as _,m as v,ot as y,pt as b,st as x,ut as S,v as C,vt as w,w as T,x as E,y as D}from"./index-BQicHl1a.js";import{t as O}from"./Markdown-Drn0H2RJ.js";import{a as ee,n as te,o as ne,r as re,t as ie}from"./Conversation-CZ8mOF1T.js";import{n as k,t as ae}from"./MessageComposer-SftlQB1e.js";import{r as oe}from"./WorkspaceTree-BEiahyEL.js";var A=d(),j=n();function M({disabled:e,onSend:t}){let[n,r]=(0,A.useState)(``),[i,a]=(0,A.useState)(!1),o=`其他回答`,c=(0,A.useRef)(null),l=(0,A.useCallback)(e=>{if(!c.current)return;let t=document.createElement(`canvas`).getContext(`2d`);if(!t)return;t.font=getComputedStyle(e).font;let r=Math.max(...(n||`${o}…`).split(`
2
+ `).map(e=>t.measureText(e).width));c.current.style.setProperty(`--reply-width`,`${Math.ceil(r+(i?52:26))}px`)},[n,i,o]),u=k(n,l);return(0,j.jsxs)(`form`,{ref:c,className:`inline-reply${i?` active`:``}`,onFocus:()=>a(!0),onBlur:e=>{!n&&!e.currentTarget.contains(e.relatedTarget)&&a(!1)},onSubmit:i=>{i.preventDefault(),!e&&n.trim()&&t(n.trim()).then(e=>{e&&r(``)})},children:[(0,j.jsx)(`textarea`,{ref:u,rows:1,"aria-label":`自定义回答`,placeholder:`${o}…`,value:n,disabled:e,onChange:e=>r(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&!t.nativeEvent.isComposing&&(t.preventDefault(),!e&&n.trim()&&t.currentTarget.form?.requestSubmit())}}),i&&(0,j.jsx)(`button`,{className:`inline-reply-send`,type:`submit`,disabled:e||!n.trim(),"aria-label":`发送${o}`,title:`发送${o}`,children:(0,j.jsx)(s,{name:`send`,size:`small`})})]})}var N={minimal:`极低`,low:`低`,medium:`中`,high:`高`,xhigh:`极高`,max:`最高`,ultra:`极致`,none:`无`},P=[{value:`read-only`,label:`只读`,description:`读取文件,不修改代码`},{value:`workspace-write`,label:`工作区写入`,shortLabel:`工作区`,description:`可修改工作区,额外权限按需审批`},{value:`full-access`,label:`完整访问`,description:`可访问工作区之外,按需审批`}];function F({id:e,label:t,current:n,options:r,disabled:i,onSelect:a}){let o=r.find(e=>e.value===n);return(0,j.jsx)(v,{id:`${e}-menu`,triggerId:e,placement:`top`,className:`composer-menu composer-choice`,label:`选择${t}`,disabled:i,routeKey:n,trigger:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`span`,{title:`${t}:${o?.label??n}`,children:o?.shortLabel??o?.label??n}),(0,j.jsx)(s,{name:`chevronDown`,size:`small`})]}),children:e=>(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`composer-menu-heading`,children:t}),r.map(t=>(0,j.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-label":t.label,onClick:()=>{e(),a(t.value)},children:[(0,j.jsxs)(`span`,{className:`composer-option-copy`,children:[(0,j.jsx)(`span`,{children:t.label}),t.description&&(0,j.jsx)(`small`,{children:t.description})]}),t.value===n&&(0,j.jsx)(s,{name:`check`,size:`small`})]},t.value))]})})}function se({session:e,models:t,busy:n,available:r,online:i,commands:a,draft:o,onInsert:c,onConfig:l}){let[u,d]=(0,A.useState)(!1);(0,A.useEffect)(()=>{/^[/$]([^\s]*)$/.exec(o)?d(!0):d(!1)},[o]);let f=t.find(t=>t.id===(e.config.model??e.effectiveConfig?.model)),p=n||!r,m=t.find(e=>e.isDefault)?.id??(e.config.model?null:e.effectiveConfig?.model),h=t.find(e=>e.id===m)?.name??m,g=[{value:``,label:h?`默认 · ${h}`:`模型未获取`},...t.map(e=>({value:e.id,label:e.name}))];e.config.model&&!t.some(t=>t.id===e.config.model)&&g.push({value:e.config.model,label:e.config.model});let _=f?.id===e.effectiveConfig?.model?e.effectiveConfig?.effort:f?.defaultEffort,y=[{value:``,label:_?`默认 · ${N[_]??_}`:`默认强度`},...(f?.efforts??[]).map(e=>({value:e,label:N[e]??e}))];return e.config.effort&&!y.some(t=>t.value===e.config.effort)&&y.push({value:e.config.effort,label:N[e.config.effort]??e.config.effort}),(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(v,{id:`session-commands`,triggerId:`session-command-trigger`,label:`命令与 Skills`,placement:`top`,className:`composer-menu composer-commands`,routeKey:e.id,trigger:(0,j.jsx)(s,{name:`slash`,size:`small`}),open:u,onOpenChange:d,focusFirst:!1,disabled:p||!i,children:e=>(0,j.jsxs)(j.Fragment,{children:[[...a].sort((e,t)=>e.name.localeCompare(t.name,`en`)).map(t=>(0,j.jsx)(`button`,{type:`button`,role:`menuitem`,title:[t.description,t.path].filter(Boolean).join(`
3
+ `),onClick:()=>{e(),c(t)},children:(0,j.jsxs)(`span`,{className:`composer-command-row`,children:[(0,j.jsxs)(`span`,{className:`composer-command-name`,children:[t.kind===`skill`?`$`:`/`,t.name]}),(0,j.jsx)(`small`,{children:t.description})]})},`${t.kind}:${t.path??t.name}`)),!a.length&&(0,j.jsx)(`div`,{className:`composer-menu-heading`,children:`尚未获取命令`})]})}),(0,j.jsx)(F,{id:`session-model`,label:`模型`,current:e.config.model??``,options:g,disabled:p,onSelect:n=>{let r=t.find(e=>e.id===n);l({...e.config,model:n||null,effort:e.config.effort&&r?.efforts.includes(e.config.effort)?e.config.effort:null})}}),(0,j.jsx)(F,{id:`session-effort`,label:`思考强度`,current:e.config.effort??``,options:y,disabled:p,onSelect:t=>l({...e.config,effort:t||null})}),(0,j.jsx)(F,{id:`session-permission`,label:`权限`,current:e.config.permission,options:P,disabled:p,onSelect:t=>l({...e.config,permission:t})})]})}var ce=S({taskRoot:m().nullable().default(null),online:x(),computer:S({id:m(),name:m(),platform:m()}).nullable(),capabilities:y(m()),models:y(u),catalogs:y(T).default([]),directories:y(f),sessions:y(e)}),le=S({ok:x()}),I={idle:`空闲`,working:`工作中`,waiting:`等待回答`,queued:`等待执行`,uncertain:`需要核对`,human:`人工处理`,offered:`待本地接收`,accepted:`本地已接手`,human_routed:`未送达本地`,pending:`待投递`,sent:`已发送`,succeeded:`已完成`,running:`进行中`,failed:`失败`};function ue(){let{request:e}=D(),t=(0,A.useCallback)(t=>e(`web/local-agent-settings`,E,{signal:t}),[e]),n=r(t,3e4);return n.error?(0,j.jsx)(o,{error:!0,children:n.error}):n.data?n.data.accessible?(0,j.jsx)(L,{}):(0,j.jsx)(g,{title:`本项目暂未向你开放本地 Agent 功能`}):null}function L(){let t=D(),[n,u]=(0,A.useState)(()=>new Set),[d,f]=(0,A.useState)(()=>({project:t.projectId,directory:new URLSearchParams(location.search).get(`directory`)??``,session:new URLSearchParams(location.search).get(`session`)??``})),[m,g]=(0,A.useState)(``),[y,x]=(0,A.useState)(!1),[S,T]=(0,A.useState)(!1),[E,k]=(0,A.useState)(!1),[M,N]=(0,A.useState)(``),[P,F]=(0,A.useState)(``),[ue,L]=(0,A.useState)(!1),[fe,he]=(0,A.useState)(``),R=(0,A.useRef)(null),z=(0,A.useRef)(!0),B=(0,A.useRef)(void 0),ge=(0,A.useRef)(crypto.randomUUID()),_e=(0,A.useCallback)(async e=>[{...await t.request(`web/local-agent-computer`,ce,{signal:e}),project:t.projectId}],[t]),V=r(_e,3e3),H=V.data?.find(e=>e.project===d.project),U=H?.directories.find(e=>e.id===d.directory);C(d.project);let W=(0,A.useCallback)((e,t,n)=>C(d.project).request(e,t,n),[d.project]),ve=(0,A.useCallback)(e=>d.session?W(`web/local-agent-sessions/${d.session}`,l,{signal:e}):Promise.resolve(null),[W,d.session]),G=r(ve,15e3),[K,ye]=(0,A.useState)(),q=K?.session.id===d.session&&(!G.data||K.cursor>=G.data.cursor)?K:G.data;(0,A.useEffect)(()=>{if(!d.session)return;let e=new EventSource(w(`/api/v1/projects/${encodeURIComponent(d.project)}/web/local-agent-sessions/${encodeURIComponent(d.session)}/events`)),t=!0;return e.addEventListener(`snapshot`,e=>{try{let n=l.parse(JSON.parse(e.data));t&&ye(e=>e?.session.id===n.session.id&&e.cursor>n.cursor?e:n)}catch(e){g(a(e))}}),()=>{t=!1,e.close()}},[d.project,d.session]),(0,A.useEffect)(()=>{z.current=!0},[d.project,d.session]),(0,A.useEffect)(()=>{z.current&&R.current&&(R.current.scrollTop=R.current.scrollHeight)},[q?.cursor,q?.messages.length]);let J=q?.session,Y=H?.capabilities.includes(`local-sessions-v1`),X=(e,n,r=``)=>{f({project:e,directory:n,session:r}),k(!1),L(!1),he(``),N(``),g(``);let i=new URL(location.href);i.searchParams.set(`directory`,n),r?i.searchParams.set(`session`,r):i.searchParams.delete(`session`),e===t.projectId&&history.replaceState(null,``,i)};(0,A.useEffect)(()=>{if(!d.directory&&V.data?.[0]?.directories[0]){let e=V.data[0],t=e.directories[0],n=e.sessions.find(e=>e.id===d.session);X(e.project,n?.directory??t.id,n?.id??t.defaultSession)}},[V.data]),(0,A.useEffect)(()=>{if(!J)return;let e=()=>{document.visibilityState===`visible`&&W(`web/local-agent-sessions/${J.id}/read`,le,{method:`POST`}).catch(e=>g(a(e)))};return e(),document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[J?.id,q?.messages.at(-1)?.seq,W]);async function Z(e){x(!0),g(``);try{await e(),await Promise.all([G.reload(),V.reload()])}catch(e){g(a(e))}finally{x(!1)}}let[Q,$]=(0,A.useState)(null);(0,A.useEffect)(()=>$(null),[J?.id]);let be=H?.catalogs.find(e=>J?.cwd?e.cwd===J.cwd:e.directory===(J?.executionDirectory??J?.directory))?.commands??[],xe=new Map;for(let e of V.data??[]){let t=e.computer?.id??`unknown:${e.project}`;xe.set(t,[...xe.get(t)??[],e])}return(0,j.jsxs)(re,{className:`computers-layout`,testId:`computers-page`,label:`本地会话`,tree:!0,navigation:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(p,{title:`电脑`,icon:`computers`,children:(0,j.jsx)(v,{id:`computer-create-menu`,triggerId:`computer-create`,label:`新建`,trigger:(0,j.jsx)(s,{name:`plus`}),className:`computer-create-menu`,routeKey:d.directory,children:e=>(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`button`,{type:`button`,role:`menuitem`,disabled:!U||!Y,onClick:()=>{e(),L(!0),T(!1),k(!1)},children:`新建会话`}),(0,j.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{e(),T(!0),L(!1),k(!1)},children:`接入目录`})]})})}),(0,j.jsx)(`div`,{className:`assistant-message-scroll computer-tree`,role:`tree`,"aria-label":`电脑与会话`,onKeyDown:oe,children:[...xe.entries()].map(([e,t])=>(0,j.jsxs)(`div`,{role:`none`,children:[(0,j.jsxs)(`div`,{className:`computer-device`,children:[(0,j.jsx)(`span`,{className:`computer-connection ${t.some(e=>e.online)?`online`:``}`,role:`img`,"aria-label":t.some(e=>e.online)?`在线`:`离线`,title:t.some(e=>e.online)?`在线`:`离线`,children:(0,j.jsx)(s,{name:`device`,size:`small`})}),(0,j.jsx)(`span`,{title:t[0].computer?.name,children:t[0].computer?.name??`已连接客户端`})]}),t.map(e=>(0,j.jsx)(`div`,{role:`none`,children:e.directories.map(t=>{let r=`${e.project}/${t.id}`,i=!n.has(r);return(0,j.jsxs)(`div`,{role:`none`,children:[(0,j.jsxs)(h,{className:`tree-item tree-folder`,role:`treeitem`,"aria-level":1,"aria-expanded":i,style:{"--tree-level":1},leading:(0,j.jsx)(`span`,{className:`tree-chevron ${i?`expanded`:``}`,children:(0,j.jsx)(s,{name:`chevron`,size:`small`})}),onClick:()=>u(e=>{let t=new Set(e);return i?t.add(r):t.delete(r),t}),children:[(0,j.jsx)(s,{name:`files`}),(0,j.jsx)(`span`,{className:`tree-name`,title:t.name,children:t.name})]}),i&&(0,j.jsx)(`div`,{role:`group`,children:e.sessions.filter(e=>e.directory===t.id).map(n=>(0,j.jsxs)(h,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":d.session===n.id&&d.project===e.project,style:{"--tree-level":2},leading:(0,j.jsx)(`span`,{className:`tree-chevron`,children:(0,j.jsx)(`span`,{className:`assistant-message-dot ${n.unread?`unread`:``}`})}),title:n.title,onClick:()=>X(e.project,t.id,n.id),children:[(0,j.jsx)(s,{name:`messages`}),(0,j.jsx)(`span`,{className:`tree-name`,children:n.title}),n.archived?(0,j.jsx)(`span`,{title:`已归档`,role:`img`,"aria-label":`已归档`,children:(0,j.jsx)(s,{name:`archive`,size:`small`})}):n.state!==`idle`&&(0,j.jsx)(ne,{state:n.state,label:I[n.state]??n.state})]},n.id))})]},t.id)})},e.project))]},e))}),(0,j.jsx)(o,{error:!0,children:V.error})]}),children:[S&&(0,j.jsxs)(`div`,{className:`stack computer-panel`,children:[(0,j.jsx)(`h2`,{children:`接入目录`}),(0,j.jsx)(_,{id:`computer-connect`,label:`在目标电脑连接项目`,value:`teammy connect`}),(0,j.jsx)(_,{id:`computer-register`,label:`在该电脑登记执行目录`,value:`teammy agent register --provider codex --cwd .`}),(0,j.jsx)(`p`,{className:`muted`,children:`完成登记后自动显示。会话可直接在网页使用,也可连接专用群。`})]}),U?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(te,{title:J?(0,j.jsx)(me,{title:J.title,busy:y,onSave:t=>Z(()=>W(`web/local-agent-sessions/${J.id}/settings`,e,{method:`PUT`,body:{expectedRevision:J.revision,title:t,config:J.config}}))},J.id):(0,j.jsx)(`h2`,{children:U.name}),actions:(0,j.jsx)(c,{icon:`settings`,label:`会话与目录设置`,disabled:!J,onClick:()=>k(!0)})}),!Y&&(0,j.jsx)(o,{children:`升级客户端后可使用多个会话和网页对话。`}),ue&&(0,j.jsxs)(`form`,{className:`computer-panel inline-form`,onSubmit:t=>{t.preventDefault(),Z(async()=>{let t=await W(`web/local-agents/${U.id}/sessions`,e,{method:`POST`,body:{id:ge.current,title:P}});ge.current=crypto.randomUUID(),L(!1),F(``),X(d.project,U.id,t.id)})},children:[(0,j.jsx)(`input`,{required:!0,"aria-label":`会话名称`,placeholder:`会话名称`,value:P,onChange:e=>F(e.target.value)}),(0,j.jsx)(`button`,{disabled:y||!P.trim(),children:`创建`})]}),E&&J&&H&&(0,j.jsx)(i,{id:`computer-settings`,title:`会话与目录设置`,onClose:()=>k(!1),children:(0,j.jsx)(pe,{session:J,directory:U,entry:H,request:W,busy:y,save:Z,code:fe,setCode:he},`${J.id}:${J.revision}`)}),(0,j.jsxs)(ee,{ref:R,onScroll:e=>{let t=e.currentTarget;z.current=t.scrollHeight-t.scrollTop-t.clientHeight<96},"aria-label":`本地会话记录`,children:[q?.messages.map(e=>e.role===`system`?(0,j.jsx)(`div`,{className:`conversation-system-message`,children:e.body},e.id):(0,j.jsxs)(ie,{className:e.question?`question-bubble`:``,mine:e.role===`user`,author:e.role===`user`?`你`:`本地 Agent`,time:e.createdAt,children:[e.question?(0,j.jsx)(de,{question:e.question,session:J.id,request:W,refresh:G.reload}):(0,j.jsx)(`div`,{className:`markdown`,children:(0,j.jsx)(O,{children:e.body})}),e.role===`user`&&[`offered`,`pending`,`human_routed`,`failed`,`uncertain`].includes(e.state)&&(0,j.jsx)(ne,{label:I[e.state]??e.state,state:e.state})]},e.id)),!q?.messages.length&&(0,j.jsx)(`div`,{className:`assistant-empty`,children:`在当前目录开始一段对话。`})]}),q?.commands.filter(e=>e.state!==`succeeded`).slice(-3).map(e=>(0,j.jsxs)(`p`,{className:`computer-control-status`,role:`status`,children:[e.kind,` · `,I[e.state]??e.state,e.error?`:${e.error}`:``]},e.id)),(0,j.jsx)(o,{error:!0,children:m||G.error||J?.error}),J&&(0,j.jsx)(ae,{value:M,onChange:N,label:`向本地 Agent 发送消息`,placeholder:J.archived?`会话已归档`:`输入消息…`,disabled:J.archived||!Y,sendDisabled:y,actions:(0,j.jsx)(se,{session:J,models:H?.models??[],busy:y,available:!!Y,online:!!H?.online,commands:be,draft:M,onInsert:e=>{$(e.kind===`skill`?e:null),N(`${e.kind===`skill`?`$`:`/`}${e.name} `),requestAnimationFrame(()=>document.querySelector(`.message-composer textarea`)?.focus())},onConfig:t=>{k(!1),Z(()=>W(`web/local-agent-sessions/${J.id}/settings`,e,{method:`PUT`,body:{expectedRevision:J.revision,title:J.title,config:t}}))}}),onSubmit:e=>{e.preventDefault();let t=M.trim();if(!t)return;let n=Q?.path&&t.startsWith(`$${Q.name}`)?[{name:Q.name,path:Q.path}]:void 0,r=JSON.stringify({session:J.id,body:t,skills:n});B.current?.fingerprint!==r&&(B.current={fingerprint:r,id:crypto.randomUUID()});let i=B.current;Z(async()=>{await W(`web/local-agent-sessions/${J.id}/messages`,b(),{method:`POST`,body:{id:i.id,body:t,...n?{skills:n}:{}}}),N(e=>e.trim()===t?``:e),$(null),B.current===i&&(B.current=void 0)})}})]}):(0,j.jsxs)(`div`,{className:`assistant-empty`,children:[`尚未登记本地执行目录。`,(0,j.jsx)(`button`,{onClick:()=>T(!0),children:`接入目录`})]})]})}function de({question:e,session:t,request:n,refresh:r}){let[i,c]=(0,A.useState)({}),[l,u]=(0,A.useState)(``),[d,f]=(0,A.useState)(!1),p=(0,A.useRef)(null),m=(0,A.useRef)(!1),h=(0,A.useRef)(void 0);(0,A.useEffect)(()=>{if(e.state!==`pending`||m.current||!p.current)return;let r=!1,i=()=>{if(r&&document.visibilityState===`visible`&&p.current){let r=p.current.getBoundingClientRect();r.bottom>0&&r.top<innerHeight&&n(`web/local-agent-sessions/${t}/questions/${e.id}/presented`,le,{method:`POST`}).then(()=>{m.current=!0}).catch(e=>u(a(e)))}},o=new IntersectionObserver(e=>{r=e.some(e=>e.isIntersecting),r&&i()});return o.observe(p.current),document.addEventListener(`visibilitychange`,i),()=>{o.disconnect(),document.removeEventListener(`visibilitychange`,i)}},[e.id,e.state,t,n]);async function g(i,o){h.current&&h.current.body===i||(h.current={body:i,id:crypto.randomUUID(),...o===void 0?{}:{decision:o}}),f(!0),u(``);try{return await n(`web/local-agent-sessions/${t}/questions/${e.id}/answers`,b(),{method:`POST`,body:h.current}),h.current=void 0,r(),!0}catch(e){return u(a(e)),!1}finally{f(!1)}}let _=e.response,v=e.state===`answered`,y=[`expired`,`cancelled`].includes(e.state),x=[`human_routed`,`failed`].includes(e.submissionState??``),S=e.state===`pending`&&(!_||x),C=y?`已过期`:e.state===`uncertain`||e.submissionState===`uncertain`?`需核对`:v?e.approval?_?.decision===!0?`已允许`:_?.decision===!1?`已拒绝`:`已处理`:_?``:`已回答`:x?`未送达`:_?`正在提交`:``,w=y||_?.decision===!1||x?`close`:v?`check`:`clock`;return(0,j.jsxs)(`div`,{className:`native-question`,ref:p,children:[e.questions.map(t=>(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`p`,{children:t.text}),S&&(0,j.jsx)(`div`,{className:`question-options`,children:(e.approval?[`允许`,`拒绝`]:t.options).map(n=>(0,j.jsx)(`button`,{disabled:d||e.state!==`pending`,"aria-pressed":i[t.id]===n,onClick:()=>{c(e=>({...e,[t.id]:n})),e.questions.length===1&&g(n,e.approval?n===`允许`:void 0)},children:n},n))}),!e.approval&&t.freeText&&S&&(0,j.jsx)(M,{disabled:d,onSend:async n=>e.questions.length===1?g(n):(c(e=>({...e,[t.id]:n})),!0)}),!S&&!e.approval&&_?.answers[t.id]&&(0,j.jsxs)(`div`,{className:`question-response`,children:[(0,j.jsx)(s,{name:v?`check`:`clock`,size:`small`}),(0,j.jsx)(`span`,{children:_.answers[t.id]})]}),S&&e.questions.length>1&&i[t.id]&&!t.options.includes(i[t.id])&&(0,j.jsx)(`small`,{children:i[t.id]})]},t.id)),S?(0,j.jsxs)(j.Fragment,{children:[!e.approval&&e.questions.length>1&&(0,j.jsx)(`div`,{className:`question-actions`,children:(0,j.jsx)(`button`,{disabled:d||e.questions.some(e=>!i[e.id]?.trim()),onClick:()=>void g(e.questions.length===1?i[e.questions[0].id]:JSON.stringify(i)),children:`回答`})}),e.approval&&(0,j.jsx)(`small`,{className:`muted`,children:`60 秒后自动允许`})]}):null,C&&(0,j.jsxs)(`small`,{className:`question-result`,children:[(0,j.jsx)(s,{name:w,size:`small`}),C]}),(0,j.jsx)(o,{error:!0,children:l})]})}function fe({value:e,onChange:t,models:n}){let r=n.find(t=>t.id===e.model);return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`label`,{children:[`模型`,(0,j.jsxs)(`select`,{value:e.model??``,onChange:n=>t({...e,model:n.target.value||null,effort:null}),children:[(0,j.jsx)(`option`,{value:``,children:`本机默认`}),n.map(e=>(0,j.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,j.jsxs)(`label`,{children:[`思考强度`,(0,j.jsxs)(`select`,{value:e.effort??``,onChange:n=>t({...e,effort:n.target.value||null}),children:[(0,j.jsx)(`option`,{value:``,children:`模型默认`}),r?.efforts.map(e=>(0,j.jsx)(`option`,{children:e},e))]})]}),(0,j.jsxs)(`label`,{children:[`权限`,(0,j.jsxs)(`select`,{value:e.permission,onChange:n=>t({...e,permission:n.target.value}),children:[(0,j.jsx)(`option`,{value:`read-only`,children:`只读 · 禁止提权`}),(0,j.jsx)(`option`,{value:`workspace-write`,children:`工作区写入 · 按需审批`}),(0,j.jsx)(`option`,{value:`full-access`,children:`完整访问 · 按需审批`})]})]})]})}function pe({session:n,directory:r,entry:i,request:a,busy:o,save:s,code:c,setCode:l}){let[u,d]=(0,A.useState)(r.defaults??t.parse({})),[f,p]=(0,A.useState)(r.defaultSession??n.id),[h,g]=(0,A.useState)(r.name),[v,y]=(0,A.useState)(r.responsibilities),[x,C]=(0,A.useState)(r.enabled),[w,T]=(0,A.useState)(n.executionDirectory),[D,O]=(0,A.useState)();return(0,A.useEffect)(()=>{a(`web/local-agent-settings`,E).then(O).catch(()=>{})},[a]),(0,j.jsxs)(`div`,{className:`computer-panel stack`,children:[(0,j.jsxs)(`details`,{open:!0,children:[(0,j.jsx)(`summary`,{children:`执行位置与连接`}),(0,j.jsx)(`div`,{className:`config-fields`,children:(0,j.jsxs)(`label`,{children:[`执行位置`,(0,j.jsxs)(`select`,{value:w??``,onChange:e=>T(e.target.value||null),children:[(0,j.jsx)(`option`,{value:``,children:`原登记目录`}),i.directories.filter(e=>e.id!==r.id).map(e=>(0,j.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})}),n.cwd&&(0,j.jsxs)(`p`,{className:`computer-paths`,children:[`当前执行路径:`,(0,j.jsx)(`code`,{children:n.cwd})]}),(0,j.jsx)(`button`,{disabled:o,onClick:()=>void s(()=>a(`web/local-agent-sessions/${n.id}/settings`,e,{method:`PUT`,body:{expectedRevision:n.revision,title:n.title,config:n.config,executionDirectory:w}})),children:`保存执行位置`}),(0,j.jsx)(`button`,{disabled:o||n.bound,onClick:()=>void s(async()=>{l((await a(`web/local-agent-bindings/codes`,S({code:m()}),{method:`POST`,body:{directory:r.id,session:n.id,expectedRevision:n.bindingRevision}})).code)}),children:n.bound?`已连接专用群`:`连接专用群`}),c&&(0,j.jsx)(_,{id:`session-binding`,label:`在目标群发送`,value:`/bind ${c}`})]}),(0,j.jsxs)(`details`,{children:[(0,j.jsx)(`summary`,{children:`目录默认设置与接单`}),(0,j.jsxs)(`div`,{className:`config-fields`,children:[(0,j.jsxs)(`label`,{children:[`目录名称`,(0,j.jsx)(`input`,{value:h,onChange:e=>g(e.target.value)})]}),(0,j.jsxs)(`label`,{children:[`职责`,(0,j.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value)})]}),(0,j.jsxs)(`label`,{children:[`默认会话`,(0,j.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),children:i.sessions.filter(e=>e.directory===r.id&&!e.archived).map(e=>(0,j.jsx)(`option`,{value:e.id,children:e.title},e.id))})]}),(0,j.jsx)(fe,{value:u,onChange:d,models:i.models})]}),(0,j.jsx)(`p`,{className:`muted`,children:`用于新会话与新派工。`}),(0,j.jsx)(`button`,{disabled:o,onClick:()=>void s(()=>a(`web/local-agents/${r.id}/settings`,b(),{method:`PUT`,body:{defaultSession:f,defaults:u,name:h,responsibilities:v,enabled:x,expectedRevision:r.revision}})),children:`保存目录默认设置`}),(0,j.jsxs)(`label`,{children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:x,onChange:e=>C(e.target.checked)}),`此目录自动接单`]}),(0,j.jsx)(`p`,{children:r.available?`可自动接单`:r.reason}),(0,j.jsxs)(`label`,{children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:D?.enabled??!1,disabled:!D||o,onChange:e=>void s(async()=>O(await a(`web/local-agent-settings`,E,{method:`PUT`,body:{enabled:e.target.checked,expectedRevision:D.revision}})))}),`开启本项目的本地执行`]}),(0,j.jsx)(_,{id:`directory-intake`,label:r.enabled?`暂停此目录新增接单`:`开启此目录自动接单`,value:`teammy agent ${r.enabled?`disable`:`enable`} --id ${r.id}`})]})]})}function me({title:e,busy:t,onSave:n}){let[r,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(e);return r?(0,j.jsx)(`form`,{className:`session-title-form`,onSubmit:t=>{t.preventDefault(),a.trim()&&a.trim()!==e&&n(a.trim()),i(!1)},children:(0,j.jsx)(`input`,{autoFocus:!0,"aria-label":`会话标题`,value:a,disabled:t,onChange:e=>o(e.target.value),onBlur:()=>i(!1),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),i(!1))}})}):(0,j.jsx)(`h2`,{children:(0,j.jsx)(`button`,{type:`button`,className:`session-rename`,title:`重命名会话`,"aria-label":`重命名会话:${e}`,onClick:()=>{o(e),i(!0)},children:e})})}export{ue as Computers};
@@ -0,0 +1 @@
1
+ main#main:has(.conversation-layout){height:100dvh;padding:0;overflow:hidden}.assistant-layout{grid-template-columns:var(--pane-width) minmax(0, 1fr);height:100%;min-height:0;overflow:hidden}.assistant-list{border-right:1px solid var(--color-line);background:var(--color-surface);flex-direction:column;min-height:0;display:flex}.assistant-list-heading,.assistant-thread-heading{border-bottom:1px solid var(--color-line);flex:0 0 76px;justify-content:space-between;align-items:center;padding:0 24px;display:flex}.assistant-list-heading h1{margin:0;font-size:20px}.assistant-thread-heading h2{text-overflow:ellipsis;white-space:nowrap;margin:0;font-size:17px;overflow:hidden}.assistant-message-scroll{flex:1;min-height:0;overflow-y:auto}.assistant-list-status{color:var(--color-muted);font-size:var(--text-sm);margin:20px 24px}.assistant-message-item{border:0;border-bottom:1px solid var(--color-line);text-align:left;width:100%;color:var(--color-text);background:0 0;border-radius:0;align-items:center;gap:12px;padding:20px 24px;display:flex}.assistant-message-item:hover{background:var(--color-hover)}.assistant-message-item.selected{background:var(--color-soft)}.assistant-message-item.archived{color:var(--color-muted)}.assistant-message-item.archived strong{font-weight:400}.assistant-new-chat{width:32px;height:32px;min-height:32px;color:var(--brand-orange);background:var(--color-accent-soft);padding:6px}.assistant-new-chat .icon{width:20px;height:20px}.assistant-new-chat:after{top:calc(100% + 6px);bottom:auto}.assistant-message-copy{flex-direction:column;flex:1;gap:6px;min-width:0;display:flex}.assistant-message-copy>.selection-content{width:fit-content;max-width:100%;color:var(--color-text);margin:-5px -8px;padding:5px 8px;display:block;overflow:visible}.assistant-message-item.archived .selection-content{color:inherit}.assistant-message-copy .selection-inner{min-width:0;display:block}.assistant-message-copy .selection-inner strong{display:block}.assistant-message-copy strong,.assistant-message-copy>span{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.assistant-message-copy strong{font-size:var(--text-base);font-weight:600}.assistant-message-copy>span,.assistant-message-copy time{font-size:var(--text-xs);color:var(--color-muted)}.assistant-message-dot{border-radius:50%;flex:0 0 7px;width:7px;height:7px}.assistant-message-dot.unread{background:var(--brand-orange)}.assistant-thread{background:var(--color-canvas);flex-direction:column;min-width:0;min-height:0;display:flex;overflow:hidden}.assistant-transcript{flex:1;min-height:0;padding:28px clamp(20px,4vw,64px);overflow-y:auto}.assistant-matter-state{border-bottom:1px solid var(--color-line);color:var(--color-muted);font-size:var(--text-xs);overflow-wrap:anywhere;padding:10px 28px;line-height:1.6}.assistant-bubble-row{margin:0 0 24px;display:flex}.assistant-bubble-row.mine{justify-content:flex-end}.assistant-bubble{border-radius:4px var(--radius-lg) var(--radius-lg);background:var(--color-soft);overflow-wrap:anywhere;min-width:100px;max-width:min(88%,800px);padding:14px 18px}.assistant-bubble-row.mine .assistant-bubble{background:var(--color-accent-soft);border-radius:var(--radius-lg) 4px var(--radius-lg) var(--radius-lg)}.assistant-bubble-meta{font-size:var(--text-xs);color:var(--color-muted);align-items:baseline;gap:16px;margin-bottom:8px;display:flex}.assistant-debug-reply{font-size:var(--text-xs);background:var(--color-surface);margin-top:12px;padding:4px 10px}.assistant-bubble .markdown>:first-child{margin-top:0}.assistant-bubble .markdown>:last-child{margin-bottom:0}.assistant-bubble .markdown{font-size:var(--text-base);line-height:1.75}.assistant-bubble .markdown h1,.assistant-bubble .markdown h2{font-size:18px}.assistant-bubble .markdown h3,.assistant-bubble .markdown h4,.assistant-bubble .markdown h5,.assistant-bubble .markdown h6{font-size:var(--text-base)}.assistant-bubble .markdown :is(h1,h2,h3,h4,h5,h6){margin:18px 0 8px;line-height:1.5}.assistant-bubble .markdown :is(p,ul,ol){margin:10px 0}.assistant-bubble .markdown :is(ul,ol){padding-left:1.5em}.assistant-bubble .markdown li+li{margin-top:4px}.assistant-bubble .markdown li>:is(ul,ol){margin:4px 0}.assistant-bubble pre{max-width:100%;overflow-x:auto}.assistant-reply-hint{font-size:var(--text-xs);color:var(--color-muted);margin:0 28px 10px;line-height:1.7}.assistant-empty{height:100%;min-height:240px;color:var(--color-muted);flex-direction:column;justify-content:center;align-items:center;gap:20px;display:flex}.assistant-empty .mascot{width:96px;height:144px}.assistant-empty p{margin:0}.assistant-archived{color:var(--color-muted);font-size:var(--text-sm);justify-content:center;align-items:center;gap:8px;padding:24px;display:flex}.assistant-thread>.notice{margin:0 28px 12px}.assistant-typing{gap:5px;padding:8px 0;display:inline-flex}.assistant-typing i{background:var(--color-muted);border-radius:50%;width:5px;height:5px;animation:1.4s infinite assistant-pulse}.assistant-typing i:nth-child(2){animation-delay:.15s}.assistant-typing i:nth-child(3){animation-delay:.3s}@keyframes assistant-pulse{0%,70%,to{opacity:.35}35%{opacity:1}}@media (prefers-reduced-motion:reduce){.assistant-typing i{animation:none}}@media (width<=900px){.assistant-layout{grid-template-columns:240px minmax(0,1fr)}.assistant-message-item{padding:16px}.assistant-reply-hint{margin:0 16px 10px}.assistant-bubble{max-width:96%}}@media (width<=600px){.assistant-layout{grid-template-columns:150px minmax(0,1fr)}.assistant-list-heading,.assistant-thread-heading{padding:0 12px}.assistant-transcript{padding:16px 10px}.assistant-reply-hint{margin:0 8px 10px}}.assistant-participants{text-overflow:ellipsis;white-space:nowrap;min-width:0;max-width:45%;color:var(--color-muted);font-size:var(--text-sm);margin-left:16px;overflow:hidden}.assistant-thread-heading>div{min-width:0}.assistant-list.file-tree-pane{overflow:hidden}@media (width<=600px){.conversation-layout{grid-template-rows:minmax(130px,26dvh) minmax(0,1fr);grid-template-columns:minmax(0,1fr)}.conversation-layout .assistant-list{border-right:0;border-bottom:1px solid var(--color-line)}.conversation-layout .assistant-list-heading{flex-basis:52px}.conversation-layout .assistant-thread-heading{flex-basis:56px}.conversation-layout .assistant-list.file-tree-pane{padding:12px 16px}.conversation-layout .explorer-heading{min-height:32px;margin-bottom:12px}.conversation-layout .explorer-heading h1{font-size:20px}.conversation-layout .assistant-list.file-tree-pane{grid-template-rows:36px minmax(0,1fr);grid-template-columns:minmax(0,1fr);gap:8px;display:grid}.conversation-layout .assistant-list.file-tree-pane .explorer-heading{margin:0}.conversation-layout .computer-tree{grid-column:1/-1}.conversation-layout .computer-device{margin-top:0}}.conversation-status{background:var(--color-muted);vertical-align:middle;border-radius:50%;flex:0 0 6px;width:6px;height:6px;display:inline-block}.conversation-status.state-online,.conversation-status:is(.state-working,.state-running,.state-waiting,.state-queued,.state-offered,.state-pending){background:var(--brand-orange)}.conversation-status:is(.state-failed,.state-human_routed,.state-uncertain){background:var(--color-danger)}.conversation-status.state-offline{opacity:.45}.conversation-title{flex:1;min-width:0}.topic-preview{font-size:var(--text-xs);color:var(--color-muted);display:block;overflow:hidden}.conversation-system-message{text-align:center;color:var(--color-muted);font-size:var(--text-xs);margin:16px 0;line-height:1.6}.conversation-post.assistant-bubble{border:1px solid var(--color-line);border-radius:var(--radius-md);background:var(--color-surface);width:100%;max-width:none;margin:0 0 16px;padding:20px 24px}.conversation-post .assistant-bubble-meta{justify-content:space-between}.channel-layout .assistant-message-item{gap:8px;padding:12px 18px}.channel-layout .assistant-message-copy{gap:4px}.channel-layout .assistant-message-copy>span{font-size:var(--text-xs)}@media (width<=600px){.conversation-post.assistant-bubble{padding:14px}}
@@ -0,0 +1 @@
1
+ import{G as e,p as t}from"./index-BQicHl1a.js";var n=e();function r({navigation:e,children:r,className:i=``,tree:a=!1,label:o,testId:s}){return(0,n.jsx)(t,{className:`assistant-layout conversation-layout ${i}`,"data-testid":s,navigation:(0,n.jsx)(`aside`,{className:`assistant-list ${a?`file-tree-pane`:``}`,"aria-label":`${o}列表`,children:e}),children:(0,n.jsx)(`section`,{className:`assistant-thread`,"aria-label":o,children:r})})}function i({mine:e=!1,author:t,time:r,children:i,className:a=``,ref:o,...s}){return(0,n.jsx)(`div`,{...s,ref:o,className:`assistant-bubble-row ${e?`mine`:``} ${a}`,children:(0,n.jsxs)(`div`,{className:`assistant-bubble`,children:[(0,n.jsxs)(`div`,{className:`assistant-bubble-meta`,children:[(0,n.jsx)(`span`,{children:t}),r&&(0,n.jsx)(`time`,{dateTime:r,children:new Date(r).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})})]}),i]})})}function a({label:e,state:t=`idle`}){return(0,n.jsx)(`span`,{className:`conversation-status state-${t}`,role:`img`,"aria-label":e,title:e})}function o({author:e,time:t,children:r}){return(0,n.jsxs)(`article`,{className:`conversation-post assistant-bubble`,children:[(0,n.jsxs)(`header`,{className:`assistant-bubble-meta`,children:[(0,n.jsx)(`strong`,{children:e}),t&&(0,n.jsx)(`time`,{dateTime:t,children:new Date(t).toLocaleString(`zh-CN`,{month:`numeric`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})})]}),r]})}function s({title:e,actions:t}){return(0,n.jsxs)(`header`,{className:`assistant-thread-heading`,children:[(0,n.jsx)(`div`,{className:`conversation-title`,children:e}),t]})}function c({ref:e,...t}){return(0,n.jsx)(`div`,{role:`log`,"aria-live":`polite`,...t,ref:e,className:`assistant-transcript`})}export{c as a,o as i,s as n,a as o,r,i as t};
@@ -0,0 +1 @@
1
+ .task-board{min-width:0}.task-board .page-header{align-items:flex-start;margin-bottom:40px}.task-board .page-header>div{min-width:0}.task-board .page-header h1,.task-board .page-header p{overflow-wrap:anywhere}.task-board-lanes{grid-template-columns:repeat(auto-fit,minmax(min(100%,240px),1fr));align-items:start;gap:24px;margin-bottom:32px;display:grid}.task-lane{min-width:0}.task-lane h2{font-size:var(--text-base);border-bottom:1px solid var(--color-line);align-items:center;gap:10px;padding:0 0 16px;font-weight:600;display:flex}.task-lane .count{margin-left:auto}.task-lane-content{flex-direction:column;gap:12px;padding-top:16px;display:flex}.lane-dot{border:1.5px solid var(--color-muted);border-radius:50%;width:8px;height:8px}.task-lane[data-stage=in_progress] .lane-dot{border-color:var(--brand-orange);background:var(--brand-orange)}.task-lane[data-stage=in_review] .lane-dot{border-color:var(--brand-black);background:var(--brand-black)}.task-lane[data-stage=completed] .lane-dot{border-color:var(--color-muted);background:var(--color-muted)}.task-lane-empty{font-size:var(--text-xs);color:var(--color-muted);padding:44px 0}.task-card{border:1px solid var(--color-line);border-radius:var(--radius-md);background:var(--color-surface);overflow-wrap:anywhere;min-width:0;position:relative}.task-card>.task-card-heading{border-radius:inherit;padding:16px;list-style:none;position:static}.task-age{white-space:nowrap;color:var(--color-muted);font-size:var(--text-xs);flex-shrink:0;align-items:center;gap:4px;margin-left:auto;font-weight:400;display:inline-flex}.task-age .icon{width:13px;height:13px}.task-age.stale{color:var(--brand-orange)}.task-lane-expand{min-height:32px;color:var(--color-muted);font-size:var(--text-xs);background:0 0;border:0;justify-content:center;align-items:center;gap:6px;display:flex}.task-card-heading::-webkit-details-marker{display:none}.task-card-heading:hover{background:var(--color-soft)}.task-card[open]>.task-card-heading h3{padding-right:32px}.task-card-meta{align-items:center;gap:8px;margin-top:8px;display:flex}.task-card-meta>small{text-overflow:ellipsis;white-space:nowrap;min-width:0;overflow:hidden}.task-confirmation{border-radius:var(--radius-sm);background:var(--color-accent-soft);color:var(--brand-orange);font-size:calc(var(--text-xs) - 1px);flex-shrink:0;align-items:center;gap:3px;padding:0 4px;font-weight:400;line-height:18px;display:inline-flex}.task-confirmation .icon{width:12px;height:12px}.task-card-confirm{flex-direction:column;align-items:flex-end;gap:8px;margin-top:16px;display:flex}.task-card-confirm button{min-height:32px;font-size:var(--text-xs);padding:4px 12px}.task-status-field legend{font-size:var(--text-sm);margin-bottom:8px;font-weight:600}.task-status-options{grid-template-columns:repeat(4,minmax(0,1fr));gap:8px;display:grid}.task-status-choice{cursor:pointer;position:relative}.task-status-choice input{opacity:0;width:100%;height:100%;min-height:0;cursor:inherit;position:absolute;inset:0}.task-status-choice span{border:1px solid var(--color-line);border-radius:var(--radius-md);background:var(--color-surface);min-height:36px;font-size:var(--text-sm);justify-content:center;align-items:center;font-weight:550;display:flex}.task-status-choice:hover span{background:var(--color-soft)}.task-status-choice input:checked+span{border-color:var(--brand-black);background:var(--brand-black);color:var(--color-on-dark)}.task-status-choice input:focus-visible+span{outline:2px solid var(--brand-orange);outline-offset:3px}.task-status-choice input:disabled+span{opacity:.45;cursor:default}.task-card-heading h3{font-size:var(--text-base);font-weight:650;line-height:1.55}.task-card-edit{opacity:0;pointer-events:none;position:absolute;top:10px;right:8px}.task-card[open]:hover>.task-card-edit{opacity:1;pointer-events:auto}.task-card[open]:has(:focus-visible)>.task-card-edit{opacity:1;pointer-events:auto}.task-progress{font-size:var(--text-sm);white-space:pre-wrap;line-height:1.85}.task-card small{color:var(--color-muted);font-size:var(--text-xs)}.task-card-details{padding:0 16px 16px}.task-card-details h4{font-size:var(--text-xs);margin:16px 0 4px;font-weight:600}.task-card-details p{font-size:var(--text-sm);margin:0}.task-card-sources{flex-direction:column;align-items:flex-start;gap:8px;margin:16px 0;display:flex}.task-card-sources a{text-align:left;overflow-wrap:anywhere;max-width:100%;font-size:var(--text-xs);min-height:28px;color:var(--color-muted);justify-content:flex-start;gap:8px;padding:4px 0;text-decoration:none;display:inline-flex}.task-card-sources a:hover{color:var(--color-link);text-decoration:underline}.task-mention{border-radius:var(--radius-sm);background:var(--color-accent-soft);color:inherit;padding:0 2px}
@@ -0,0 +1 @@
1
+ import{A as e,B as t,D as n,G as r,H as i,I as a,J as o,L as s,M as c,N as l,O as u,P as d,R as f,U as p,V as m,_t as h,vt as g,y as _}from"./index-BQicHl1a.js";import{t as v}from"./project-links-Dy6-B89_.js";import"./file-links-BYBi3BDP.js";var y=h(),b=r(),x=[{status:`planned`,label:`计划`},{status:`in_progress`,label:`进行中`},{status:`in_review`,label:`待验收`},{status:`completed`,label:`已完成`},{status:null,label:`未明确`}];function S({members:t,project:r,userName:a}){let{request:o,projectId:c}=_(),u=(0,y.useCallback)(e=>o(`tasks`,n,{signal:e}),[o]),d=i(u,3e3,p(c,`tasks`)),[m,h]=(0,y.useState)(),[v,S]=(0,y.useState)(!1),[w,T]=(0,y.useState)(Date.now);(0,y.useEffect)(()=>{let e=setInterval(()=>T(Date.now()),6e4);return()=>clearInterval(e)},[]);let D=d.data,O=new Map(t.map(e=>[e.id,e.displayName||e.id]));return(0,b.jsxs)(`div`,{className:`task-board`,children:[(0,b.jsx)(f,{title:r?.projectName.trim()?`${r.projectName.trim()}|工作看板`:`工作看板`,description:r?.description.trim()||``,children:(0,b.jsx)(`a`,{className:`account-home`,"data-testid":`home-link`,href:g(`/projects`),onClick:e=>{e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),history.pushState(null,``,g(`/projects`)),window.dispatchEvent(new PopStateEvent(`popstate`)))},"aria-label":`项目主页`,"data-tooltip":`项目主页`,children:(0,b.jsx)(`strong`,{children:a})})}),(0,b.jsx)(s,{error:!0,children:d.error}),(0,b.jsx)(`section`,{className:`task-board-lanes`,"aria-label":`任务进度`,"data-testid":`progress-board`,children:x.filter(e=>e.status!==null||D?.tasks.some(e=>e.status===null)).map(t=>{let n=D?.tasks.filter(e=>e.status===t.status)??[];n.sort((e,t)=>e.statusSince.localeCompare(t.statusSince)||e.id.localeCompare(t.id));let r=t.status===`completed`&&!v?n.slice(0,5):n;return(0,b.jsxs)(`section`,{className:`task-lane`,"aria-label":t.label,"data-stage":t.status??`unknown`,children:[(0,b.jsxs)(`h2`,{children:[(0,b.jsx)(`span`,{className:`lane-dot`}),t.label,(0,b.jsx)(e,{children:D?n.length:`—`})]}),(0,b.jsxs)(`div`,{className:`task-lane-content`,children:[n.length?r.map(e=>(0,b.jsx)(C,{task:e,names:O,now:w,onEdit:()=>h(e),onSaved:()=>void d.reload()},e.id)):(0,b.jsx)(`p`,{className:`task-lane-empty`,children:d.error&&!D?`读取失败`:D?`暂无任务`:`读取中…`}),t.status===`completed`&&n.length>5&&(0,b.jsxs)(`button`,{type:`button`,className:`task-lane-expand`,"aria-expanded":v,onClick:()=>S(!v),children:[(0,b.jsx)(l,{name:v?`chevronUp`:`chevronDown`,size:`small`}),v?`收起`:`展开其余 ${n.length-5} 项`]})]})]},t.label)})}),m&&(0,b.jsx)(E,{task:m,onClose:()=>h(void 0),onSaved:()=>{h(void 0),d.reload()}},m.id)]})}function C({task:e,names:n,onEdit:r,onSaved:i,now:a}){let{projectId:c,request:f}=_(),p=m(),[h,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(``);async function E(){if(!h){x(!0),C(``);try{await f(`tasks/${e.id}/correction`,u,{method:`PATCH`,signal:p,body:{needsConfirmation:!1,expectedRevision:e.revision}}),p.aborted||i()}catch(e){p.aborted||C(o(e))}finally{x(!1)}}}return(0,b.jsxs)(`details`,{className:`task-card`,"data-testid":`task-card`,"data-task-id":e.id,"data-owner":e.owner,"data-status":e.status??`unknown`,children:[(0,b.jsxs)(`summary`,{className:`task-card-heading`,"data-testid":`task-toggle`,children:[(0,b.jsx)(`h3`,{children:e.title}),(0,b.jsxs)(`span`,{className:`task-card-meta`,children:[(0,b.jsx)(`small`,{title:n.get(e.owner)??e.owner,children:n.get(e.owner)??e.owner}),e.needsConfirmation&&(0,b.jsxs)(`span`,{className:`task-confirmation`,"data-testid":`task-confirmation`,children:[(0,b.jsx)(l,{name:`attention`,size:`small`}),`需要确认`]}),e.status!==`completed`&&(0,b.jsx)(w,{since:e.statusSince,now:a})]})]}),(0,b.jsx)(d,{icon:`edit`,className:`task-card-edit`,label:`纠正任务:${e.title}`,"data-testid":`task-correct`,disabled:h,onClick:r}),(0,b.jsxs)(`div`,{className:`task-card-details`,children:[(0,b.jsx)(`h4`,{children:`目标`}),(0,b.jsx)(`p`,{children:e.goal?(0,b.jsx)(T,{value:e.goal,names:n}):`目标未明确`}),(0,b.jsx)(`h4`,{children:`当前进展`}),(0,b.jsx)(`p`,{className:`task-progress`,children:(0,b.jsx)(T,{value:e.progress,names:n})}),(0,b.jsx)(`div`,{className:`task-card-sources`,children:e.sources.map(t=>(0,b.jsxs)(`a`,{"data-testid":`task-source`,href:g(t.kind===`material`?`/projects/${c}/materials?id=${t.materialId}&revision=${t.revision}`:v(c,e.owner,t.path)),children:[(0,b.jsx)(l,{name:`file`,size:`small`}),(0,b.jsx)(`span`,{children:t.path})]},t.path))}),e.syncedAt&&(0,b.jsxs)(`small`,{children:[`资料同步于 `,(0,b.jsx)(t,{value:e.syncedAt})]}),e.needsConfirmation&&(0,b.jsxs)(`div`,{className:`task-card-confirm`,children:[(0,b.jsx)(s,{error:!0,children:S}),(0,b.jsx)(`button`,{className:`primary`,"data-testid":`task-confirm-save`,disabled:h,onClick:()=>void E(),children:h?`正在保存…`:`保存`})]})]})]})}function w({since:e,now:t}){let n=Math.max(0,t-Date.parse(e)),r=Math.floor(n/6e4),i=r<1?`刚刚`:r<60?`${r} 分钟`:r<1440?`${Math.floor(r/60)} 小时`:`${Math.floor(r/1440)} 天`;return(0,b.jsxs)(`span`,{className:`task-age${n>6048e5?` stale`:``}`,"data-testid":`task-age`,title:`进入当前状态:${new Date(e).toLocaleString(`zh-CN`)}`,"aria-label":`当前状态停留 ${i}`,children:[(0,b.jsx)(l,{name:`clock`,size:`small`}),i]})}function T({value:e,names:t}){return e.split(/(@[a-z][a-z0-9_-]*)/gi).map((e,n)=>e.startsWith(`@`)&&t.has(e.slice(1))?(0,b.jsx)(`mark`,{className:`task-mention`,children:e},n):e)}function E({task:e,onClose:t,onSaved:n}){let{request:r}=_(),i=m(),[l,d]=(0,y.useState)(e.title),[f,p]=(0,y.useState)(e.status??``),[h,g]=(0,y.useState)(e.goal??``),[v,S]=(0,y.useState)(e.progress),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(``),D={...l===e.title?{}:{title:l},...f===(e.status??``)?{}:{status:f||null},...h===(e.goal??``)?{}:{goal:h||null},...v===e.progress?{}:{progress:v},...e.needsConfirmation?{needsConfirmation:!1}:{}};async function O(){if(!C&&Object.keys(D).length){w(!0),E(``);try{await r(`tasks/${e.id}/correction`,u,{method:`PATCH`,signal:i,body:{...D,expectedRevision:e.revision}}),i.aborted||n()}catch(e){i.aborted||E(o(e))}finally{w(!1)}}}return(0,b.jsx)(a,{id:`task-correction`,title:`纠正任务`,onClose:t,children:(0,b.jsxs)(`form`,{className:`stack`,"aria-busy":C,onSubmit:e=>{e.preventDefault(),O()},children:[(0,b.jsx)(c,{id:`task-title`,label:`标题`,children:(0,b.jsx)(`input`,{value:l,required:!0,onChange:e=>d(e.target.value)})}),(0,b.jsxs)(`fieldset`,{className:`task-status-field`,disabled:C,children:[(0,b.jsx)(`legend`,{children:`状态`}),(0,b.jsx)(`div`,{className:`task-status-options`,"data-testid":`task-status`,children:x.filter(e=>e.status!==null).map(e=>(0,b.jsxs)(`label`,{className:`task-status-choice`,children:[(0,b.jsx)(`input`,{type:`radio`,name:`task-status`,value:e.status,checked:f===e.status,onChange:()=>p(e.status)}),(0,b.jsx)(`span`,{children:e.label})]},e.status))}),(0,b.jsx)(`small`,{children:`待验收:任务成果已提交,等待验收或最终确认。`})]}),(0,b.jsx)(c,{id:`task-goal`,label:`目标`,children:(0,b.jsx)(`textarea`,{value:h,onChange:e=>g(e.target.value)})}),(0,b.jsx)(c,{id:`task-progress`,label:`当前进展`,children:(0,b.jsx)(`textarea`,{value:v,onChange:e=>S(e.target.value)})}),(0,b.jsx)(s,{error:!0,children:T}),(0,b.jsx)(`div`,{className:`row wrap`,children:(0,b.jsx)(`button`,{type:`submit`,className:`primary`,disabled:C||!Object.keys(D).length,"data-testid":`task-correction-save`,children:`保存`})})]})})}function D({members:e,config:t,userName:n}){return(0,b.jsx)(S,{members:e,project:t,userName:n})}export{D as Dashboard};
@@ -0,0 +1 @@
1
+ import{G as e,H as t,K as n,L as r,N as i,P as a,Q as o,U as s,_t as c,c as l,d as u,et as d,f,j as p,l as m,s as h,u as g,vt as _,y as v,z as y}from"./index-BQicHl1a.js";import{t as b}from"./Markdown-Drn0H2RJ.js";import{n as x,t as S}from"./WorkspaceTree-BEiahyEL.js";import{t as C}from"./project-links-Dy6-B89_.js";import{t as w}from"./file-links-BYBi3BDP.js";import{t as T}from"./HtmlPreview-TOlZ7wbO.js";var E=c(),D=e();function O(e,t){let n=t.split(`/`).slice(0,-1);return n.map((t,r)=>x(e,n.slice(0,r+1).join(`/`))).concat(x(e,``))}function k({members:e,onRefresh:i}){let{api:s,projectId:c}=v(),[y,b]=(0,E.useState)(()=>{let t=new URLSearchParams(location.search),n=t.get(`owner`),r=d.safeParse(t.get(`path`));return n&&(g(n)||e.some(e=>e.id===n))&&r.success&&!m(r.data)?{owner:n,path:r.data}:void 0}),[T,k]=(0,E.useState)(()=>new Set(y?O(y.owner,y.path):[])),[j,M]=(0,E.useState)(()=>y?{...y,kind:`file`}:void 0),[N,P]=(0,E.useState)(0),[F,I]=(0,E.useState)(()=>{let e=new URLSearchParams(location.search);return!y&&(e.has(`owner`)||e.has(`path`))?`文件链接不完整或目标已不可用。`:``}),L=(0,E.useCallback)(async e=>{if(y)try{return{owner:y.owner,...await s.file(y.owner,y.path,void 0,e)}}catch(e){throw e instanceof n&&e.code===`FILE_NOT_FOUND`?Error(`找不到这个文件,可能已被删除或移动。`):e}},[y?.owner,y?.path,N]),R=t(L),z=R.data?.owner===y?.owner&&R.data?.file.path===y?.path?R.data:void 0;function B(e,t){let n=t.split(`/`).filter(Boolean);k(t=>{let r=new Set(t);for(let t=0;t<=n.length;t++)r.add(x(e,n.slice(0,t).join(`/`)));return r})}function V(e,t){I(``),B(e,t.split(`/`).slice(0,-1).join(`/`)),b({owner:e,path:t}),M({owner:e,path:t,kind:`file`}),history.replaceState(null,``,_(C(c,e,t)))}function H(t){if(!y)return!1;let n=w(g(y.owner)?y.path:`${y.owner}/${y.path}`,t);if(!n)return!/^[a-z][a-z0-9+.-]*:/i.test(t)&&!t.startsWith(`//`)&&(I(`该链接超出工作区,请在原仓库查看。`),!0);if(m(n.path))return I(`配置文件不在文件浏览中显示。`),!0;if(l(n.path))return location.assign(_(`/projects/${c}/memory`)),!0;let[r,...i]=n.path.split(`/`),a=e.some(e=>e.id===r),o=a?r:h,s=a?i.join(`/`):n.path;return I(``),n.directory?(B(o,s),M({owner:o,path:s,kind:`directory`})):o===y.owner&&s===y.path?n.anchor&&[...document.querySelectorAll(`.markdown h1,.markdown h2,.markdown h3,.markdown h4`)].find(e=>e.textContent?.trim().toLowerCase().replace(/\s+/g,`-`)===n.anchor.toLowerCase())?.scrollIntoView({block:`center`}):V(o,s),!0}return(0,D.jsx)(f,{"data-testid":`file-browser`,label:`文件资源管理器`,navigation:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(u,{title:`工作区`,icon:`files`,children:(0,D.jsx)(a,{icon:`refresh`,label:`刷新文件`,"data-testid":`files-refresh`,onClick:()=>{I(``),P(e=>e+1),i()}})}),(0,D.jsx)(S,{members:e,expanded:T,selected:j,revealed:!R.loading&&!R.error&&z?{owner:z.owner,path:z.file.path,file:z.file}:void 0,onSelect:V,onToggle:(e,t)=>{M({owner:e,path:t,kind:`directory`}),k(n=>{let r=new Set(n),i=x(e,t);return r.has(i)?r.delete(i):r.add(i),r})}},N)]}),children:(0,D.jsx)(`section`,{className:`file-detail`,"data-testid":`file-preview`,"data-owner-id":y?.owner,"data-file-path":y?.path,"aria-label":o.filePreview,children:y?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(r,{error:!0,children:F||!R.loading&&R.error}),R.error&&(0,D.jsx)(`button`,{className:`file-entry-retry`,"data-testid":`files-retry`,onClick:()=>void R.reload(),children:o.retry}),R.loading?(0,D.jsx)(`p`,{className:`preview-body`,role:`status`,children:o.loading}):!R.error&&z&&(0,D.jsx)(A,{owner:z.owner,file:z.file,onLink:H},`${z.owner}:${z.file.path}:${z.file.sha256}`)]}):F?(0,D.jsx)(r,{error:!0,children:F}):(0,D.jsx)(p,{mascot:!0,title:`查看工作区文件`,description:o.pickFile})})})}function A({owner:e,file:n,onLink:c}){let{readTextBlob:l,blobUrl:u,projectId:d}=v(),[f,p]=(0,E.useState)(!1),m=n.size>524288,h=/\.(md|markdown)$/i.test(n.path),_=/\.html?$/i.test(n.path),x=(0,E.useCallback)(e=>m?Promise.resolve(void 0):l(n,e),[n.sha256,n.size,m]),S=t(x,!1,s(d,`file-body`,n.sha256));return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`header`,{className:`file-detail-header`,children:[(0,D.jsxs)(`span`,{className:`file-detail-path`,title:`${g(e)?`teamcontext`:e}/${n.path}`,children:[(0,D.jsxs)(`span`,{children:[g(e)?`teamcontext`:e,` / `]}),n.path]}),(0,D.jsxs)(y,{label:`文件操作`,children:[(h||_)&&(0,D.jsx)(a,{icon:f?`preview`:`code`,label:f?`切换为预览`:`切换为原文`,"data-testid":`file-toggle-raw`,"aria-pressed":f,onClick:()=>p(!f)}),(0,D.jsx)(`a`,{className:`icon-button`,"data-testid":`file-download`,"aria-label":o.download,title:o.download,href:u(n.sha256),download:n.path.split(`/`).at(-1),children:(0,D.jsx)(i,{name:`download`})})]})]}),m?(0,D.jsx)(`div`,{className:`empty`,children:(0,D.jsx)(`p`,{children:o.previewLarge})}):S.error?(0,D.jsxs)(`div`,{className:`preview-body`,children:[(0,D.jsx)(r,{error:!0,children:S.error}),(0,D.jsx)(`button`,{"data-testid":`file-preview-retry`,onClick:()=>void S.reload(),children:o.retry})]}):S.loading?(0,D.jsx)(`p`,{className:`preview-body`,role:`status`,children:o.loading}):(0,D.jsx)(`div`,{className:`preview-body${_&&!f?` preview-body-html`:``}`,children:_&&!f?(0,D.jsx)(T,{url:u(n.sha256),name:n.path.split(`/`).at(-1)}):h&&!f?(0,D.jsx)(`article`,{className:`markdown`,"data-testid":`file-content`,"data-format":`markdown`,children:(0,D.jsx)(b,{onLink:c,children:S.data??``})}):(0,D.jsx)(`pre`,{className:`raw`,"data-testid":`file-content`,"data-format":`text`,children:S.data})})]})}export{k as Files};