@teammy/server 0.2.23 → 0.2.25

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 (166) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -7
  3. package/dist/main.js +21235 -13704
  4. package/dist/native-pi-entry.js +815 -19
  5. package/dist/project-pi-entry.js +818 -22
  6. package/dist/runtime/en/shared/system.md +9 -0
  7. package/dist/runtime/en/shared/tools.json +22 -0
  8. package/dist/runtime/en/workflows/directory-analysis/prompt.md +11 -0
  9. package/dist/runtime/en/workflows/file-summary/prompt.md +7 -0
  10. package/dist/runtime/en/workflows/session-handoff/prompt.md +31 -0
  11. package/dist/runtime/en/workflows/session-overview/prompt.md +26 -0
  12. package/dist/runtime/en/workflows/task-bootstrap/prompt.md +84 -0
  13. package/dist/runtime/shared/system.md +1 -1
  14. package/dist/runtime/workflows/session-handoff/prompt.md +1 -1
  15. package/dist/runtime/workflows/session-overview/prompt.md +1 -1
  16. package/dist/web/THIRD-PARTY-LICENSES.md +2025 -0
  17. package/dist/web/assets/Assistant-C-GBv5St.js +1 -0
  18. package/dist/web/assets/Computers-B-FvcufX.js +14 -0
  19. package/dist/web/assets/{Computers-BtcIsnDD.css → Computers-BJKv9oJv.css} +1 -1
  20. package/dist/web/assets/Conversation-Dzr18Rmq.js +1 -0
  21. package/dist/web/assets/Dashboard-5ksfc6l9.js +1 -0
  22. package/dist/web/assets/Files-DqrIDBJI.js +1 -0
  23. package/dist/web/assets/Help-JsdkpQ8l.js +2413 -0
  24. package/dist/web/assets/MessageComposer-DOJ1PYXg.js +1 -0
  25. package/dist/web/assets/MessageComposer-DqcbXBIG.css +1 -0
  26. package/dist/web/assets/ResourceLibrary--aVsAt6m.js +6 -0
  27. package/dist/web/assets/TerminalPane-jJa53g04.js +22 -0
  28. package/dist/web/assets/WorkspaceTree-CuwIu3vj.js +1 -0
  29. package/dist/web/assets/file-links-BnaVOi2G.js +1 -0
  30. package/dist/web/assets/index-B9gF6reY.css +1 -0
  31. package/dist/web/assets/index-Ck_8bv0N.js +40 -0
  32. package/dist/web/assets/project-links-CodATITq.js +105 -0
  33. package/dist/web/assets/workflow-DR-M8YZx.svg +111 -0
  34. package/dist/web/downloads/teammy-inbox-skill.zip +0 -0
  35. package/dist/web/downloads/teammy-skill.zip +0 -0
  36. package/dist/web/index.html +4 -4
  37. package/dist/web/notification-worker.js +2 -10
  38. package/node_modules/i18next/LICENSE +21 -0
  39. package/node_modules/i18next/README.md +77 -0
  40. package/node_modules/i18next/dist/cjs/i18next.js +2495 -0
  41. package/node_modules/i18next/dist/esm/i18next.js +2505 -0
  42. package/node_modules/i18next/dist/esm/package.json +1 -0
  43. package/node_modules/i18next/dist/umd/i18next.js +2501 -0
  44. package/node_modules/i18next/dist/umd/i18next.min.js +1 -0
  45. package/node_modules/i18next/i18next.js +2501 -0
  46. package/node_modules/i18next/i18next.min.js +1 -0
  47. package/node_modules/i18next/index.d.mts +71 -0
  48. package/node_modules/i18next/index.d.ts +739 -0
  49. package/node_modules/i18next/package.json +125 -0
  50. package/node_modules/i18next/typescript/helpers.d.ts +73 -0
  51. package/node_modules/i18next/typescript/options.d.ts +871 -0
  52. package/node_modules/i18next/typescript/t.d.ts +1449 -0
  53. package/node_modules/jose/LICENSE.md +21 -0
  54. package/node_modules/jose/README.md +150 -0
  55. package/node_modules/jose/dist/types/index.d.ts +55 -0
  56. package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +25 -0
  57. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +40 -0
  58. package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +25 -0
  59. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +46 -0
  60. package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +29 -0
  61. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +51 -0
  62. package/node_modules/jose/dist/types/jwk/embedded.d.ts +10 -0
  63. package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +15 -0
  64. package/node_modules/jose/dist/types/jwks/local.d.ts +17 -0
  65. package/node_modules/jose/dist/types/jwks/remote.d.ts +94 -0
  66. package/node_modules/jose/dist/types/jws/compact/sign.d.ts +21 -0
  67. package/node_modules/jose/dist/types/jws/compact/verify.d.ts +25 -0
  68. package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +23 -0
  69. package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +26 -0
  70. package/node_modules/jose/dist/types/jws/general/sign.d.ts +41 -0
  71. package/node_modules/jose/dist/types/jws/general/verify.d.ts +31 -0
  72. package/node_modules/jose/dist/types/jwt/decrypt.d.ts +38 -0
  73. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +57 -0
  74. package/node_modules/jose/dist/types/jwt/sign.d.ts +21 -0
  75. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +21 -0
  76. package/node_modules/jose/dist/types/jwt/verify.d.ts +36 -0
  77. package/node_modules/jose/dist/types/key/export.d.ts +19 -0
  78. package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +33 -0
  79. package/node_modules/jose/dist/types/key/generate_secret.d.ts +30 -0
  80. package/node_modules/jose/dist/types/key/import.d.ts +67 -0
  81. package/node_modules/jose/dist/types/types.d.ts +802 -0
  82. package/node_modules/jose/dist/types/util/base64url.d.ts +16 -0
  83. package/node_modules/jose/dist/types/util/decode_jwt.d.ts +9 -0
  84. package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +10 -0
  85. package/node_modules/jose/dist/types/util/errors.d.ts +182 -0
  86. package/node_modules/jose/dist/webapi/index.js +70 -0
  87. package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +7 -0
  88. package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +26 -0
  89. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +15 -0
  90. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +35 -0
  91. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +41 -0
  92. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +105 -0
  93. package/node_modules/jose/dist/webapi/jwk/embedded.js +30 -0
  94. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +55 -0
  95. package/node_modules/jose/dist/webapi/jwks/local.js +60 -0
  96. package/node_modules/jose/dist/webapi/jwks/remote.js +103 -0
  97. package/node_modules/jose/dist/webapi/jws/compact/sign.js +20 -0
  98. package/node_modules/jose/dist/webapi/jws/compact/verify.js +8 -0
  99. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +23 -0
  100. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +12 -0
  101. package/node_modules/jose/dist/webapi/jws/general/sign.js +58 -0
  102. package/node_modules/jose/dist/webapi/jws/general/verify.js +42 -0
  103. package/node_modules/jose/dist/webapi/jwt/decrypt.js +13 -0
  104. package/node_modules/jose/dist/webapi/jwt/encrypt.js +42 -0
  105. package/node_modules/jose/dist/webapi/jwt/sign.js +19 -0
  106. package/node_modules/jose/dist/webapi/jwt/unsecured.js +34 -0
  107. package/node_modules/jose/dist/webapi/jwt/verify.js +13 -0
  108. package/node_modules/jose/dist/webapi/key/export.js +35 -0
  109. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +35 -0
  110. package/node_modules/jose/dist/webapi/key/generate_secret.js +36 -0
  111. package/node_modules/jose/dist/webapi/key/import.js +53 -0
  112. package/node_modules/jose/dist/webapi/lib/asn1.js +138 -0
  113. package/node_modules/jose/dist/webapi/lib/buffer_utils.js +75 -0
  114. package/node_modules/jose/dist/webapi/lib/content_encryption.js +90 -0
  115. package/node_modules/jose/dist/webapi/lib/deflate.js +41 -0
  116. package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +116 -0
  117. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +190 -0
  118. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +75 -0
  119. package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +74 -0
  120. package/node_modules/jose/dist/webapi/lib/jws_sign.js +46 -0
  121. package/node_modules/jose/dist/webapi/lib/jws_verify.js +89 -0
  122. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +150 -0
  123. package/node_modules/jose/dist/webapi/lib/key.js +157 -0
  124. package/node_modules/jose/dist/webapi/lib/key_algorithm.js +15 -0
  125. package/node_modules/jose/dist/webapi/lib/key_descriptor.js +9 -0
  126. package/node_modules/jose/dist/webapi/lib/key_management.js +195 -0
  127. package/node_modules/jose/dist/webapi/lib/validate.js +122 -0
  128. package/node_modules/jose/dist/webapi/util/base64url.js +16 -0
  129. package/node_modules/jose/dist/webapi/util/decode_jwt.js +33 -0
  130. package/node_modules/jose/dist/webapi/util/decode_protected_header.js +19 -0
  131. package/node_modules/jose/dist/webapi/util/errors.js +109 -0
  132. package/node_modules/jose/package.json +134 -0
  133. package/node_modules/oauth4webapi/LICENSE.md +21 -0
  134. package/node_modules/oauth4webapi/README.md +104 -0
  135. package/node_modules/oauth4webapi/build/index.d.ts +3046 -0
  136. package/node_modules/oauth4webapi/build/index.js +2530 -0
  137. package/node_modules/oauth4webapi/build/index.js.map +1 -0
  138. package/node_modules/oauth4webapi/package.json +112 -0
  139. package/node_modules/openid-client/LICENSE.md +21 -0
  140. package/node_modules/openid-client/README.md +258 -0
  141. package/node_modules/openid-client/build/index.d.ts +2478 -0
  142. package/node_modules/openid-client/build/index.js +1347 -0
  143. package/node_modules/openid-client/build/index.js.map +1 -0
  144. package/node_modules/openid-client/build/passport.d.ts +258 -0
  145. package/node_modules/openid-client/build/passport.js +264 -0
  146. package/node_modules/openid-client/build/passport.js.map +1 -0
  147. package/node_modules/openid-client/package.json +130 -0
  148. package/package.json +5 -1
  149. package/dist/web/assets/Assistant-Dks48Y5w.js +0 -1
  150. package/dist/web/assets/Computers-CaCzZeCc.js +0 -13
  151. package/dist/web/assets/Conversation-kAMzKADw.js +0 -1
  152. package/dist/web/assets/Dashboard-ComNJNOg.js +0 -1
  153. package/dist/web/assets/Dropdown-DGFI68Vd.js +0 -55
  154. package/dist/web/assets/Files-Blsq_C-B.js +0 -1
  155. package/dist/web/assets/Help-BM23uS-t.js +0 -1079
  156. package/dist/web/assets/Markdown-CXnZDm5J.js +0 -29
  157. package/dist/web/assets/MessageComposer-BoOgfyPA.js +0 -1
  158. package/dist/web/assets/MessageComposer-hKEluJsT.css +0 -1
  159. package/dist/web/assets/ResourceLibrary-C12_47kE.js +0 -6
  160. package/dist/web/assets/TerminalPane-BTRM-36z.js +0 -22
  161. package/dist/web/assets/WorkspaceTree-Co7XG2RG.js +0 -1
  162. package/dist/web/assets/file-links-CoVqmrXg.js +0 -1
  163. package/dist/web/assets/index-CeKzFsxV.css +0 -1
  164. package/dist/web/assets/index-mhJ33-bH.js +0 -10
  165. package/dist/web/assets/task-links-BE36-8mc.js +0 -1
  166. /package/dist/web/assets/{Dropdown-ktgqMqAD.css → project-links-ktgqMqAD.css} +0 -0
@@ -0,0 +1,130 @@
1
+ {
2
+ "name": "openid-client",
3
+ "version": "6.9.1",
4
+ "description": "OAuth 2 / OpenID Connect Client API for JavaScript Runtimes",
5
+ "keywords": [
6
+ "access token",
7
+ "auth",
8
+ "authentication",
9
+ "authorization",
10
+ "basic",
11
+ "browser",
12
+ "bun",
13
+ "certified",
14
+ "ciba",
15
+ "client",
16
+ "cloudflare",
17
+ "deno",
18
+ "edge",
19
+ "electron",
20
+ "fapi",
21
+ "javascript",
22
+ "jwt",
23
+ "netlify",
24
+ "next",
25
+ "nextjs",
26
+ "node",
27
+ "nodejs",
28
+ "oauth",
29
+ "oauth2",
30
+ "oidc",
31
+ "openid-connect",
32
+ "openid",
33
+ "passport",
34
+ "strategy",
35
+ "vercel",
36
+ "workerd",
37
+ "workers"
38
+ ],
39
+ "homepage": "https://github.com/panva/openid-client",
40
+ "repository": "panva/openid-client",
41
+ "funding": {
42
+ "url": "https://github.com/sponsors/panva"
43
+ },
44
+ "license": "MIT",
45
+ "author": "Filip Skokan <panva.ip@gmail.com>",
46
+ "sideEffects": false,
47
+ "type": "module",
48
+ "exports": {
49
+ ".": {
50
+ "types": "./build/index.d.ts",
51
+ "default": "./build/index.js"
52
+ },
53
+ "./passport": {
54
+ "types": "./build/passport.d.ts",
55
+ "default": "./build/passport.js"
56
+ },
57
+ "./package.json": "./package.json"
58
+ },
59
+ "main": "./build/index.js",
60
+ "types": "./build/index.d.ts",
61
+ "files": [
62
+ "build/index.js",
63
+ "build/index.js.map",
64
+ "build/index.d.ts",
65
+ "build/passport.js",
66
+ "build/passport.js.map",
67
+ "build/passport.d.ts"
68
+ ],
69
+ "scripts": {
70
+ "_format": "find src test test-d examples tap conformance tools -type f -name '*.ts' -o -name '*.js' -o -name '*.mjs' -o -name '*.cjs' | xargs prettier --check",
71
+ "build": "npm run generate-build && tsc -p test && npm run --silent check-build && npx --yes jsr publish --dry-run --allow-dirty",
72
+ "check:packaging": "publint --strict && node tools/attw-check.js",
73
+ "check-build": "tsc --noEmit --types node --lib ES2022.Error && tsc -p conformance && tsc -p tap && tsc -p examples",
74
+ "conformance": "bash -c 'source .node_flags.sh && node --enable-source-maps conformance/run.ts \"$@\"' --",
75
+ "docs": "patch-package && typedoc",
76
+ "docs-check": "./check-examples.sh",
77
+ "format": "npm run _format -- --write",
78
+ "format-check": "npm run _format",
79
+ "generate-build": "rm -rf build && tsc && tsc --removeComments false --declaration --emitDeclarationOnly && tsc -p tsconfig.passport.json && tsc -p tsconfig.passport.json --removeComments false --declaration --emitDeclarationOnly",
80
+ "tap:browsers": "./tap/.browsers.sh",
81
+ "tap:bun": "./tap/.bun.sh",
82
+ "tap:deno": "./tap/.deno.sh",
83
+ "tap:electron": "./tap/.electron.sh",
84
+ "tap:node": "bash -c './tap/.node.sh'",
85
+ "tap:workerd": "./tap/.workerd.sh",
86
+ "test": "bash -c 'source .node_flags.sh && node --enable-source-maps --test \"$@\" test/*.test.ts' --",
87
+ "test:dist": "node tools/test-dist.js",
88
+ "typecheck:dist": "./tools/typecheck-dist.sh",
89
+ "typecheck:types": "tsc -p test-d && tsc -p test-d/tsconfig.node.json && tsc -p test-d/tsconfig.fallback.json && tsc -p test-d/tsconfig.fallback.const.json && tsc -p test-d/tsconfig.fallback.let.json"
90
+ },
91
+ "dependencies": {
92
+ "jose": "^6.2.18",
93
+ "oauth4webapi": "^3.8.9"
94
+ },
95
+ "devDependencies": {
96
+ "@arethetypeswrong/cli": "0.18.5",
97
+ "@koa/cors": "^5.0.0",
98
+ "@playwright/test": "^1.65.0",
99
+ "@types/connect-ensure-login": "^0.1.9",
100
+ "@types/cookie-parser": "^1.4.10",
101
+ "@types/express": "^5.0.6",
102
+ "@types/express-session": "^1.19.0",
103
+ "@types/koa__cors": "^5.0.1",
104
+ "@types/node": "^26.6.6",
105
+ "@types/passport": "^1.0.17",
106
+ "@types/qunit": "^2.19.14",
107
+ "@typescript/native": "npm:typescript@^7.0.2",
108
+ "archiver": "^8.0.0",
109
+ "esbuild": "^0.28.2",
110
+ "fast-check": "^4.10.2",
111
+ "happy-dom": "^21.0.4",
112
+ "http-cookie-agent": "^8.0.0",
113
+ "ky": "^2.2.0",
114
+ "oidc-provider": "^9.15.1",
115
+ "patch-package": "^8.0.1",
116
+ "prettier": "^3.10.1",
117
+ "prettier-plugin-jsdoc": "^1.8.1",
118
+ "publint": "0.3.23",
119
+ "qunit": "^3.0.0",
120
+ "raw-body": "^4.0.0",
121
+ "selfsigned": "^5.5.0",
122
+ "tough-cookie": "^6.1.0",
123
+ "ts-blank-space": "^0.9.0",
124
+ "typedoc": "^0.28.20",
125
+ "typedoc-plugin-markdown": "^4.14.1",
126
+ "typedoc-plugin-mdn-links": "^5.1.1",
127
+ "typescript": "npm:@typescript/typescript6@6.0.2",
128
+ "undici": "^8.12.4"
129
+ }
130
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teammy/server",
3
- "version": "0.2.23",
3
+ "version": "0.2.25",
4
4
  "description": "The centralized Teammy collaboration hub server.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -31,8 +31,10 @@
31
31
  "cron-parser",
32
32
  "diff",
33
33
  "fastify",
34
+ "i18next",
34
35
  "ignore",
35
36
  "minimatch",
37
+ "openid-client",
36
38
  "ws",
37
39
  "zod"
38
40
  ],
@@ -45,8 +47,10 @@
45
47
  "cron-parser": "5.10.6",
46
48
  "diff": "8.0.4",
47
49
  "fastify": "5.12.7",
50
+ "i18next": "^27.2.6",
48
51
  "ignore": "^7.0.8",
49
52
  "minimatch": "11.0.3",
53
+ "openid-client": "6.9.1",
50
54
  "ws": "8.22.0",
51
55
  "zod": "4.6.7"
52
56
  }
@@ -1 +0,0 @@
1
- import{A as e,At as t,Ct as n,I as r,L as i,M as a,N as ee,O as o,S as s,Tt as c,bt as l,c as u,d,ht as f,j as te,jt as ne,l as p,mt as m,u as re,vt as ie,w as ae,x as oe,y as se,yt as h}from"./Dropdown-DGFI68Vd.js";import{A as g,B as _,F as ce,L as le,M as ue,N as de,P as v,U as fe,i as pe,j as me,k as he,o as ge}from"./index-mhJ33-bH.js";import{t as _e}from"./Markdown-CXnZDm5J.js";import{i as ve,n as ye,r as be,t as xe}from"./Conversation-kAMzKADw.js";import{t as Se}from"./MessageComposer-BoOgfyPA.js";var y=t(),b=a(),Ce=l({topics:m(l({id:n(),title:n(),summary:n(),author:n(),replies:h(),unread:f(),createdAt:n(),updatedAt:n(),delivery:l({available:f(),connected:f(),state:n(),error:n().nullable()})}))}),we=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}),x=e=>e.replace(/[#*_`>]/g,``).replace(/\s+/g,` `).trim();function S({me:t,mode:a=`messages`}){let{projectId:m,request:h}=fe(),S=te(),Ee=e(m,t,`${a}-selection`),C=e(m,t,`${a}-drafts`),De=(0,y.useCallback)(e=>h(`agents/outbox`,de,{signal:e}),[h]),w=o(De,3e3,e(m,t,`outbox`)),Oe=(0,y.useCallback)(async e=>a===`messages`?h(`agents/chats`,he,{signal:e}):{chats:(await h(`channels/topics`,Ce,{signal:e})).topics.map(e=>({...e,kind:`matter`,state:null}))},[h,a]),T=o(Oe,3e3,e(m,t,a,`chats`)),[E,ke]=(0,y.useState)(()=>{let e=new URLSearchParams(location.search),t=e.get(`chat`);return t?`chat:${t}`:e.get(`message`)??S?.get(Ee)??``}),D=E.startsWith(`chat:`)?E.slice(5):``,O=!E||!!D,[k,A]=(0,y.useState)(()=>S?.get(e(m,t,`chat`,D))),j=k?.id===D?k:S?.get(e(m,t,`chat`,D)),M=T.data?.chats.find(e=>e.id===D),N=O?M?.title??j?.title??(D?`无标题`:`Tim`):E===`debug`?`运行提醒`:`项目消息`;pe(E?N:void 0);let P=M&&`delivery`in M?M.delivery:void 0,[Ae,F]=(0,y.useState)(),[I,L]=(0,y.useState)(()=>S?.get(C)??{}),je=I[E]??``,R=e=>L(t=>({...t,[E]:e})),[z,B]=(0,y.useState)(!1),[V,Me]=(0,y.useState)(!1),[Ne,Pe]=(0,y.useState)(!1),[Fe,H]=(0,y.useState)(!1),[U,Ie]=(0,y.useState)(``),[Le,Re]=(0,y.useState)(``),ze=(0,y.useRef)(i()),W=ae(),[Be,G]=(0,y.useState)(``),K=(0,y.useRef)(new Map),Ve=(0,y.useRef)(null),q=(0,y.useRef)(!0),J=(0,y.useRef)(E);J.current=E,(0,y.useEffect)(()=>{k&&S?.set(e(m,t,`chat`,k.id),k)},[S,m,t,k]),(0,y.useEffect)(()=>{S?.set(C,I)},[S,C,I]);function Y(e){J.current=e,ke(e),S?.set(Ee,e);let t=new URL(location.href);e.startsWith(`chat:`)?t.searchParams.set(`chat`,e.slice(5)):t.searchParams.delete(`chat`),e&&!e.startsWith(`chat:`)&&e!==`debug`?t.searchParams.set(`message`,e):t.searchParams.delete(`message`),history.replaceState(history.state,``,t)}(0,y.useEffect)(()=>{!E&&T.data?.chats.length&&Y(`chat:${T.data.chats[0].id}`)},[E,T.data]);let X=(w.data?.messages??[]).filter(e=>a===`messages`&&e.box===`debug`).reverse(),Z=w.data?.messages.find(e=>e.id===(E===`debug`?Ae:E));(0,y.useEffect)(()=>{E!==`debug`&&Z?.conversationId&&Y(`chat:${Z.conversationId}`)},[E,Z?.conversationId]);let Q=X.filter(e=>!e.readAt).map(e=>e.id).join(`,`);(0,y.useEffect)(()=>{Z&&!Z.readAt&&E!==`debug`&&h(`agents/outbox/${Z.id}/read`,v,{method:`POST`}).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),w.reload()}).catch(e=>W(r(e)))},[Z?.id,Z?.readAt,E,h,w.reload]),(0,y.useEffect)(()=>{E===`debug`&&Q&&Promise.all(Q.split(`,`).map(e=>h(`agents/outbox/${e}/read`,v,{method:`POST`}))).then(()=>{window.dispatchEvent(new Event(`teammy:outbox`)),w.reload()}).catch(e=>W(r(e)))},[E,Q,h,w.reload]),(0,y.useEffect)(()=>{if(G(``),!D)return;let i=!0,o=-1,s=!1,c=new AbortController,u=e=>{!i||e.id!==D||e.cursor<o||(o=e.cursor,s=!0,e.redirect?Y(`chat:${e.redirect}`):e.entry===`channel`&&a!==`channels`?location.replace(ne(`/projects/${m}/channels?chat=${e.id}`)):(A(e),G(``)))};h(`agents/chats/${D}`,g,{signal:c.signal}).then(u).catch(n=>{i&&!c.signal.aborted&&(n instanceof ee&&[401,403,404].includes(n.status)&&(S?.delete(e(m,t,`chat`,D)),A(e=>e?.id===D?void 0:e)),s||G(r(n)))});let d=e=>{let t=Number(e.lastEventId);return!i||!Number.isSafeInteger(t)||t<=o?!1:(o=t,!0)},f=new EventSource(ne(`/api/v1/projects/${encodeURIComponent(m)}/agents/chats/${encodeURIComponent(D)}/events`));f.addEventListener(`snapshot`,e=>{if(i)try{u(g.parse(JSON.parse(e.data)))}catch(e){G(r(e))}}),f.onerror=()=>{i&&G(`对话连接中断,正在重新连接…`)},f.addEventListener(`context`,e=>{if(!d(e))return;let t=g.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}`):A(e=>e?.id===D?{...e,...t,cursor:o}:e)}),f.addEventListener(`message`,e=>{if(!d(e))return;let t=me.parse(JSON.parse(e.data));A(n=>n?.id===D?{...n,readCursor:Math.max(n.readCursor,t.seq),cursor:Math.max(n.cursor,Number(e.lastEventId)||0),messages:[...n.messages.filter(e=>e.id!==t.id),t].sort((e,t)=>e.seq-t.seq)}:n)}),f.addEventListener(`message_removed`,e=>{if(!d(e))return;let{id:t}=l({id:n()}).parse(JSON.parse(e.data));A(e=>e?.id===D?{...e,cursor:o,messages:e.messages.filter(e=>e.id!==t)}:e)}),f.addEventListener(`run`,e=>{if(!d(e))return;let t=ue.parse(JSON.parse(e.data));A(n=>n?.id===D?{...n,cursor:Math.max(n.cursor,Number(e.lastEventId)||0),runs:n.runs.some(e=>e.id===t.id)?n.runs:[...n.runs,t]}:n)});for(let e of[`delta`,`reset`,`state`])f.addEventListener(e,t=>{if(!d(t))return;let n=JSON.parse(t.data);A(r=>r?.id===D?{...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()=>{i=!1,c.abort(),f.close()}},[m,D,t,h,S]),(0,y.useEffect)(()=>{if(!j||j.id!==D)return;let e=()=>{document.visibilityState===`visible`&&h(`agents/chats/${D}/read`,l({ok:f()}),{method:`POST`,body:{cursor:j.readCursor}}).then(()=>{T.reload(),window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>W(r(e)))},t=setTimeout(e,300);return document.addEventListener(`visibilitychange`,e),()=>{clearTimeout(t),document.removeEventListener(`visibilitychange`,e)}},[D,j?.readCursor,j?.kind,h]),(0,y.useEffect)(()=>{q.current&&Ve.current?.scrollIntoView({block:`end`})},[E,k?.messages,Z?.recipients,X.length]);function He(){window.dispatchEvent(new Event(`teammy:outbox`)),w.reload()}async function $(e){if(q.current=!0,Y(e),W(``),F(void 0),e.startsWith(`chat:`)||e===`debug`)return;let t=w.data?.messages.find(t=>t.id===e)?.conversationId;if(t)Y(`chat:${t}`);else try{await h(`agents/outbox/${e}/read`,v,{method:`POST`}),He()}catch(e){W(r(e))}}async function Ue(){if(!V){Me(!0),W(``);try{let e=await h(`agents/chats`,g,{method:`POST`});A(e),await $(`chat:${e.id}`),T.reload()}catch(e){W(r(e))}finally{Me(!1)}}}async function We(e){e.preventDefault();let t=je.trim();if(!t||z||V)return;B(!0),W(``);let a=K.current.get(E);a&&a.text===t||(a={text:t,id:i()},K.current.set(E,a));try{if(O){let e=a.target??D;if(!e){let n=await h(`agents/chats`,g,{method:`POST`});e=n.id,a.target=e,K.current.set(`chat:${e}`,a),L(n=>({...n,[`chat:${e}`]:t})),J.current===E&&(A(n),Y(`chat:${e}`))}let r=await h(`agents/chats/${e}`,ue.extend({conversationId:n().optional()}),{method:`POST`,body:{text:t,requestId:a.id}});r.conversationId&&r.conversationId!==e&&(J.current===E||J.current===`chat:${e}`)&&Y(`chat:${r.conversationId}`),A(t=>t?.id===e?{...t,runs:t.runs.some(e=>e.id===r.id)?t.runs:[...t.runs,r]}:t),T.reload()}else{let e=await h(`agents/outbox/${Z.id}/reply`,l({conversationId:n()}),{method:`POST`,body:{body:t,requestId:a.id}});He(),J.current===E&&Y(`chat:${e.conversationId}`),T.reload(),F(void 0)}K.current.delete(E),a.target&&K.current.delete(`chat:${a.target}`),L(e=>({...e,[E]:``,...a.target?{[`chat:${a.target}`]:``}:{}}))}catch(e){W(r(e))}finally{B(!1)}}let Ge=a===`channels`?be:xe,Ke=O&&!j?.closed&&(a!==`channels`||!!D)||!!Z&&!Z.archivedAt,qe=O&&!j&&(!!D||!T.data);return(0,b.jsxs)(ye,{className:a===`channels`?`channel-layout`:``,testId:`assistant-page`,label:O?`Tim对话`:`消息内容`,navigation:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(le,{title:a===`channels`?`频道`:`对话`,children:(0,b.jsxs)(`div`,{className:`assistant-list-actions`,children:[(0,b.jsx)(p,{className:`assistant-new-chat`,icon:`clear`,label:`清除未读`,disabled:Ne,onClick:()=>{Pe(!0),W(``),h(`communication/read`,l({ok:ie(!0)}),{method:`POST`,body:{scope:a}}).then(async()=>{window.dispatchEvent(new Event(`teammy:outbox`)),await Promise.all([T.reload(),w.reload()])}).catch(e=>W(r(e))).finally(()=>Pe(!1))}}),(0,b.jsx)(p,{className:`assistant-new-chat`,icon:`plus`,label:a===`channels`?`发表话题`:`新建对话`,disabled:V,onClick:()=>a===`channels`?H(!0):void Ue(),"data-testid":`assistant-launcher`})]})}),(0,b.jsxs)(`div`,{className:`assistant-message-scroll`,children:[T.loading&&!T.data&&(0,b.jsx)(`p`,{className:`assistant-list-status`,role:`status`,children:`加载中…`}),T.data?.chats.map(e=>(0,b.jsxs)(`button`,{type:`button`,"data-testid":`assistant-chat-${e.id}`,className:`assistant-message-item assistant-chat-item ${D===e.id?`selected`:``}`,"aria-pressed":D===e.id,onClick:()=>void $(`chat:${e.id}`),children:[(0,b.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,b.jsx)(_,{selected:D===e.id,children:(0,b.jsx)(`strong`,{children:e.title})}),a===`channels`&&`summary`in e&&(0,b.jsx)(`span`,{className:`topic-preview`,children:x(String(e.summary)).slice(0,140)}),(0,b.jsxs)(`time`,{dateTime:e.updatedAt,children:[new Date(e.updatedAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,we(e.updatedAt)]})]}),(0,b.jsx)(`span`,{className:`assistant-message-dot ${e.unread||a!==`channels`&&(e.state===`running`||e.state===`queued`)?`unread`:``}`})]},e.id)),!!X.length&&(0,b.jsxs)(`button`,{type:`button`,"data-testid":`debug-outbox`,className:`assistant-message-item ${E===`debug`?`selected`:``}`,onClick:()=>void $(`debug`),children:[(0,b.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,b.jsx)(_,{selected:E===`debug`,children:(0,b.jsx)(`strong`,{children:`运行提醒`})}),(0,b.jsx)(`span`,{children:x(X.at(-1).body)})]}),(0,b.jsx)(`span`,{className:`assistant-message-dot ${Q?`unread`:``}`})]}),w.data?.messages.filter(e=>a===`messages`&&e.box!==`debug`&&!e.conversationId).sort((e,t)=>Number(!!e.archivedAt)-Number(!!t.archivedAt)).map(e=>(0,b.jsxs)(`button`,{type:`button`,"data-testid":`outbox-${e.id}`,className:`assistant-message-item ${e.archivedAt?`archived`:``} ${E===e.id?`selected`:``}`,onClick:()=>void $(e.id),children:[(0,b.jsxs)(`span`,{className:`assistant-message-copy`,children:[(0,b.jsx)(_,{selected:E===e.id,children:(0,b.jsx)(`strong`,{children:x(e.body)})}),(0,b.jsxs)(`time`,{dateTime:e.createdAt,children:[new Date(e.createdAt).toLocaleDateString([],{month:`numeric`,day:`numeric`}),` `,we(e.createdAt)]})]}),(0,b.jsx)(`span`,{className:`assistant-message-dot ${e.readAt?``:`unread`}`})]},e.id))]}),(0,b.jsx)(s,{resource:w}),(0,b.jsx)(s,{resource:T})]}),children:[Fe&&(0,b.jsx)(d,{id:`new-topic`,title:`发表话题`,onClose:()=>H(!1),children:(0,b.jsx)(Se,{inset:!0,plain:!0,value:Le,onChange:Re,label:`正文`,placeholder:`开始一个话题…`,sendLabel:`发表话题`,sendDisabled:z||!U.trim(),heading:(0,b.jsx)(`input`,{className:`topic-title`,"aria-label":`标题`,placeholder:`标题`,required:!0,value:U,onChange:e=>Ie(e.target.value)}),onSubmit:e=>{e.preventDefault(),B(!0),W(``),h(`channels/topics`,g,{method:`POST`,body:{id:ze.current,title:U,body:Le}}).then(e=>{A(e),Y(`chat:${e.id}`),H(!1),Ie(``),Re(``),ze.current=i(),T.reload()}).catch(e=>W(r(e))).finally(()=>B(!1))}})}),(0,b.jsx)(ce,{title:(0,b.jsx)(`h2`,{children:N}),actions:(0,b.jsxs)(b.Fragment,{children:[a===`channels`&&D&&(0,b.jsx)(ge,{conversation:D}),a!==`channels`&&j?.kind===`matter`&&(0,b.jsxs)(`span`,{className:`assistant-participants`,title:j.participants?.join(`、`),children:[j.visibility===`project`?`项目共享 · `:``,j.participants?.join(`、`)]}),a===`channels`&&P?.available&&(P.state===`web`||P.state===`cancelled`||!P.connected)&&(0,b.jsx)(p,{icon:`send`,label:`发布到企业微信频道`,disabled:z,onClick:()=>{B(!0),h(`channels/topics/${D}/publish`,c(),{method:`POST`}).then(()=>T.reload()).catch(e=>W(r(e))).finally(()=>B(!1))}})]})}),a===`channels`&&(0,b.jsx)(se,{children:P?.error}),a!==`channels`&&j?.kind===`matter`&&(j.hold||j.pending||j.status===`completed`)&&(0,b.jsx)(`div`,{className:`assistant-matter-state`,role:`status`,children:j.hold?`${j.hold.scope===`all`?`已暂停`:`暂缓修改`} · ${j.hold.reason}`:j.pending?`待确认 · ${j.pending.members.join(`、`)}:${j.pending.question}`:`已完成`}),(0,b.jsxs)(ve,{"data-testid":`assistant-transcript`,onScroll:e=>{let t=e.currentTarget;q.current=t.scrollHeight-t.scrollTop-t.clientHeight<100},children:[O?qe?(0,b.jsxs)(`div`,{className:`assistant-empty`,"data-testid":`assistant-loading`,children:[(0,b.jsx)(re,{}),(0,b.jsx)(`p`,{role:`status`,children:Be||(T.error?`暂时无法加载对话`:`加载中…`)})]}):j?.messages.length?j.messages.filter(e=>e.body||[`queued`,`running`,`failed`].includes(e.state)).map(e=>(0,b.jsx)(`div`,{className:`assistant-turn`,children:(0,b.jsxs)(Ge,{mine:e.role===`user`&&e.author===t,author:`${e.role===`assistant`?`Tim`:e.author}${e.source===`wecom`?` · 企业微信`:``}`,time:e.createdAt,children:[e.body&&(0,b.jsx)(`div`,{className:`markdown`,children:(0,b.jsx)(_e,{children:e.body})}),e.role===`assistant`&&[`queued`,`running`].includes(e.state)&&(0,b.jsxs)(`span`,{className:`assistant-typing`,"aria-label":`正在回答`,children:[(0,b.jsx)(`i`,{}),(0,b.jsx)(`i`,{}),(0,b.jsx)(`i`,{})]}),e.state===`failed`&&(0,b.jsx)(se,{children:j.runs.find(t=>t.id===e.runId)?.error||`本次回答未完成。`})]})},e.id)):(0,b.jsxs)(`div`,{className:`assistant-empty`,children:[(0,b.jsx)(re,{}),(0,b.jsx)(`p`,{children:`有什么项目问题想聊聊?`})]}):!w.data&&w.loading?(0,b.jsx)(`div`,{className:`assistant-empty`,children:(0,b.jsx)(`p`,{role:`status`,children:`加载中…`})}):E===`debug`?X.map(e=>(0,b.jsx)(Te,{item:e,onReply:e.archivedAt?void 0:()=>{F(e.id),R(``),W(``)}},e.id)):Z&&(0,b.jsx)(Te,{item:Z}),(0,b.jsx)(`div`,{ref:Ve})]}),(0,b.jsx)(oe,{message:O&&j?Be:void 0}),Ke?(0,b.jsx)(Se,{value:je,onChange:R,onSubmit:e=>void We(e),disabled:V,sendDisabled:z||qe,label:O?`向Tim提问`:`回复消息`}):E!==`debug`&&Z&&(0,b.jsxs)(`div`,{className:`assistant-archived`,children:[(0,b.jsx)(u,{name:`archive`}),`已归档`]})]})}function Te({item:e,onReply:t}){return(0,b.jsx)(`div`,{"data-testid":`outbox-thread-${e.id}`,children:(0,b.jsxs)(xe,{author:e.box===`debug`?`运行提醒`:`Tim`,time:e.createdAt,children:[(0,b.jsx)(`div`,{className:`markdown`,children:(0,b.jsx)(_e,{children:e.body})}),t&&(0,b.jsx)(`button`,{type:`button`,className:`assistant-debug-reply`,onClick:t,children:`回复`})]})})}export{S as Assistant};
@@ -1,13 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./TerminalPane-BTRM-36z.js","./Dropdown-DGFI68Vd.js","./Dropdown-ktgqMqAD.css","./index-mhJ33-bH.js","./index-CeKzFsxV.css","./Markdown-CXnZDm5J.js","./task-links-BE36-8mc.js","./TerminalPane-BrSy-0jI.css"])))=>i.map(i=>d[i]);
2
- import{A as e,At as t,Ct as n,I as r,L as i,M as a,N as o,O as s,S as c,T as l,Tt as u,at as d,bt as f,c as p,d as m,gt as h,ht as g,j as _,jt as v,l as y,mt as b,p as x,pt as S,t as C,vt as w,w as T,x as E,y as D,yt as O}from"./Dropdown-DGFI68Vd.js";import{C as k,D as A,F as j,H as ee,L as te,O as M,S as ne,T as N,U as re,W as ie,_ as ae,a as oe,b as se,c as ce,d as le,f as ue,g as de,h as fe,i as pe,l as me,m as he,p as ge,s as _e,t as ve,u as ye,v as be,w as xe,x as Se,y as P,z as Ce}from"./index-mhJ33-bH.js";import{a as we,i as Te,t as Ee}from"./Markdown-CXnZDm5J.js";import{a as De,i as Oe,n as ke,t as Ae}from"./Conversation-kAMzKADw.js";import{n as je,t as Me}from"./MessageComposer-BoOgfyPA.js";import{l as Ne,r as Pe}from"./WorkspaceTree-Co7XG2RG.js";var F=t(),I=a();function Fe({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 Ie=f({id:n().uuid(),directory:n(),title:n(),cwd:n(),createdAt:n(),state:S([`running`,`exited`]),exitCode:O().nullable()}),L={id:n().uuid(),directory:n().min(1).max(200)},Le={cols:O().int().min(2).max(500),rows:O().int().min(1).max(300)};h(`type`,[f({type:w(`create`),...L,...Le,title:n().trim().min(1).max(160)}),f({type:w(`attach`),...L}),f({type:w(`detach`),...L}),f({type:w(`input`),...L,data:n().max(65536)}),f({type:w(`resize`),...L,...Le}),f({type:w(`rename`),...L,title:n().trim().min(1).max(160)}),f({type:w(`close`),...L})]);var Re=h(`type`,[f({type:w(`size`),id:n(),...Le}),f({type:w(`inventory`),directories:b(n()),terminals:b(Ie)}),f({type:w(`snapshot`),id:n(),data:n(),cols:O(),rows:O(),seq:O()}),f({type:w(`output`),id:n(),data:n(),seq:O()}),f({type:w(`result`),id:n(),operation:n(),error:n().optional()})]);function ze(e,t){let n=(0,F.useRef)(null),r=(0,F.useRef)(new Set),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)([]),[c,l]=(0,F.useState)([]);(0,F.useEffect)(()=>{if(!t)return;let i=!1,o,c,u=()=>{let t=new URL(v(`/api/v1/projects/${encodeURIComponent(e)}/web/terminals`),location.origin);t.protocol=t.protocol===`https:`?`wss:`:`ws:`,c=new WebSocket(t),n.current=c,c.onmessage=e=>{let t=Re.safeParse(JSON.parse(e.data));if(!t.success||i)return;let n=t.data;n.type===`inventory`&&(l(n.terminals),s(n.directories),a(!0));for(let e of r.current)e(n)},c.onclose=()=>{a(!1),s([]),i||(o=setTimeout(u,2e3))}};return u(),()=>{i=!0,clearTimeout(o),c?.close(),n.current=null}},[e,t]);let u=(0,F.useCallback)(e=>(r.current.add(e),()=>{r.current.delete(e)}),[]),d=(0,F.useCallback)(e=>{if(n.current?.readyState!==WebSocket.OPEN)throw Error(`终端连接已断开,输入未发送。`);n.current.send(JSON.stringify(e))},[]);return{connected:i,directories:o,terminals:c,subscribe:u,send:d,request:(0,F.useCallback)(e=>new Promise((t,n)=>{let r=setTimeout(()=>{i(),n(Error(`暂未收到结果,请检查连接;操作不会自动重发。`))},15e3),i=u(a=>{a.type===`result`&&a.id===e.id&&a.operation===e.type&&(clearTimeout(r),i(),a.error?n(Error(a.error)):t())});try{d(e)}catch(e){clearTimeout(r),i(),n(e)}}),[d,u])}}f({provider:he,cursor:n().optional(),session:be.optional()});var R=f({id:be,title:n(),cwd:n(),updatedAt:n().datetime().nullable(),active:g().default(!1)}),z=f({sessions:b(R),nextCursor:n().nullable()}),Be=f({command:P,history:z.nullable()});function Ve(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 He({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),v=(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),v.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),v.current?.focus())},children:[(0,I.jsxs)(`div`,{className:`combobox-field`,ref:_,children:[(0,I.jsx)(`input`,{id:e,ref:v,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)(y,{icon:u?`chevronUp`:`chevronDown`,label:`${u?`收起`:`展开`}${t}`,disabled:s,"aria-expanded":u,"aria-controls":`${e}-list`,onClick:()=>{d(!u),v.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 Ue({directory:e,provider:t,providers:n,sessions:a,request:o,onClose:s,onImport:c}){let[l,u]=(0,F.useState)(t),[d,f]=(0,F.useState)([]),[p,h]=(0,F.useState)(null),[g,_]=(0,F.useState)(``),[v,b]=(0,F.useState)(null),x=T(),S=(0,F.useRef)(null),C=e=>a.find(t=>!t.hidden&&t.provider===l&&(t.nativeSession??t.resumeSession)===e);async function w(t,n){let r=i();for(await o(`web/local-agents/${e}/history`,P,{method:`POST`,signal:n,body:{id:r,argument:JSON.stringify({provider:l,...t})}});!n.aborted;){let t=await o(`web/local-agents/${e}/history/${r}`,Be,{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 a=C(t.id)??await o(`web/local-agents/${e}/sessions`,ae,{method:`POST`,signal:r,body:{id:i(),title:t.title,provider:l,resumeSession:t.id,historyRequest:n}});r.aborted||c(a)}async function D(e,t){S.current?.abort();let n=new AbortController;S.current=n,b(e),x(``);try{await t(n.signal)}catch(e){n.signal.aborted||x(r(e))}finally{n.signal.aborted||b(null)}}let O=e=>D(`list`,async t=>{let n=await w(e?{cursor:e}:{},t);t.aborted||(f(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??``))}),h(n.nextCursor))});(0,F.useEffect)(()=>(f([]),h(null),_(``),O(),()=>S.current?.abort()),[l,e,o]);let k=d.find(e=>e.id===g),A=v===`import`;return(0,I.jsx)(m,{id:`computer-import-session`,title:`导入历史会话`,onClose:s,children:(0,I.jsxs)(`form`,{className:`native-history`,onSubmit:e=>{e.preventDefault(),D(`import`,async e=>{let t=g.trim(),n=C(t);if(n)return c(n);if(k)return E(k,k.requestId,e);let r=await w({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)(ce,{label:`历史会话 Agent`,value:l,onChange:u,providers:[t,...n],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)(He,{id:`native-history-session`,label:`历史会话`,value:g,onChange:_,placeholder:`选择会话或输入 ID`,disabled:A,loading:v===`list`,empty:g?`未找到匹配会话,可直接输入 Session ID。`:`此目录暂无历史会话,可输入 Session ID。`,options:d.map(e=>({value:e.id,label:e.title,description:e.id,detail:C(e.id)?`已接入`:e.active?`工作中`:Ve(e.updatedAt),disabled:e.active&&!C(e.id)})),footer:(0,I.jsxs)(I.Fragment,{children:[p&&(0,I.jsx)(`button`,{className:`native-history-more`,type:`button`,disabled:!!v,onClick:()=>void O(p),children:`加载更多`}),(0,I.jsx)(y,{icon:`refresh`,label:`刷新历史会话`,disabled:!!v,onClick:()=>void O()})]})},l),(0,I.jsx)(`button`,{type:`submit`,disabled:A||!be.safeParse(g.trim()).success||!!k?.active&&!C(k.id),children:A?`正在导入…`:C(g.trim())?`打开`:`导入`})]})]}),(0,I.jsx)(`small`,{className:`muted`,children:`请先退出原终端会话。`})]})})}var We={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 Ge(e,t){let n=e.toLowerCase().split(`.`).at(-1)??``;return t&&Object.values(We).includes(t)?t:Object.hasOwn(We,n)?We[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 Ke(e,t){let n=e.body.getReader(),r=[],i=0,a=(t??0)>M;try{for(;;){let{done:e,value:t}=await n.read();if(e)break;let o=Math.min(t.length,M-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 qe(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 Ke(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 Je({file:e,onClose:t,gallery:n}){let[i,a]=(0,F.useState)(),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(0),[u,d]=(0,F.useState)(!1),f=(0,F.useRef)(null),h=(0,F.useRef)(null),g=Ge(e.name,e.mimeType),{name:_,url:v,previewUrl:b,size:x}=e;(0,F.useEffect)(()=>{let e=new AbortController,t;return a(void 0),s(``),d(!1),qe({name:_,url:v,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(r(t))}),f.current?.focus(),()=>{e.abort(),t&&URL.revokeObjectURL(t)}},[v,x,b,_,g,c]),(0,F.useEffect)(()=>{h.current?.scrollIntoView({block:`center`})},[i,e.line]);let S=e.line&&i?.text!==void 0?i.text.split(`
3
- `):null,C=(e.line??1)-1,w=g.startsWith(`image/`);return(0,I.jsx)(m,{id:`session-image-lightbox`,title:e.name,label:w?`图片预览`:`文件预览`,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)(y,{icon:`chevron`,className:`session-image-previous`,label:`上一张图片`,onClick:()=>n.move(-1)}),(0,I.jsxs)(`small`,{children:[n.index+1,` / `,n.count]}),(0,I.jsx)(y,{icon:`chevron`,label:`下一张图片`,onClick:()=>n.move(1)})]}),w&&i?.format&&(0,I.jsx)(y,{icon:u?`zoomOut`:`zoomIn`,label:u?`适合窗口`:`原始尺寸`,"aria-pressed":u,onClick:()=>d(!u)}),(0,I.jsx)(`a`,{className:`icon-button`,href:o?void 0:i?.download??e.url,"aria-disabled":!!o,download:e.name,"aria-label":`下载文件`,title:`下载文件`,children:(0,I.jsx)(p,{name:`download`})})]}),children:(0,I.jsx)(`div`,{ref:f,tabIndex:-1,className:`session-image-viewer`,children:o?(0,I.jsx)(D,{announce:!0,retry:()=>l(e=>e+1),children:o}):i?i.format?w?(0,I.jsx)(`div`,{className:`session-image-stage`+(u?` original-size`:``),children:(0,I.jsx)(`img`,{src:i.preview,alt:e.name,onError:()=>a({format:``,download:i.download})})}):i.format===`application/pdf`?(0,I.jsx)(`iframe`,{className:`file-preview-document`,src:i.preview,title:e.name+` 预览`}):i.format===`text/html`&&!e.line?(0,I.jsx)(Ne,{name:e.name,url:e.url}):(0,I.jsxs)(`div`,{className:`file-preview-text`,children:[i.format===`text/markdown`&&!e.line?(0,I.jsx)(`article`,{className:`markdown`,children:(0,I.jsx)(Ee,{children:i.text??``})}):(0,I.jsx)(`pre`,{className:`raw`,children:S&&C<S.length?(0,I.jsxs)(I.Fragment,{children:[C>0&&S.slice(0,C).join(`
4
- `)+`
5
- `,(0,I.jsx)(`mark`,{ref:h,children:S[C]||` `}),S.length>C+1?`
6
- `+S.slice(C+1).join(`
7
- `):``]}):i.text}),i.truncated&&(0,I.jsx)(`small`,{children:`仅显示文件开头,可下载完整文件。`})]}):(0,I.jsx)(`p`,{className:`file-preview-empty`,children:`暂不支持预览此文件。`}):(0,I.jsx)(`p`,{role:`status`,children:`正在读取文件…`})})})}var B=[];function V(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 Ye=class{sessions=new Map;listeners=new Set;uploads=new Map;get=e=>this.sessions.get(e)??B;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&&(!V(e)||!e.size)||e.size>N))return r?`请选择不超过 2 GB 的 PNG、JPEG 或 WebP 图片。`:`每个附件最多 2 GB。`;let a=Array.from(t,e=>({id:i(),name:e.name.slice(0,200)||`附件`,imageOnly:r,file:e,state:`uploading`}));this.set(e,[...this.get(e),...a]);for(let t of a)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 i=this.get(e).find(e=>e.id===t);if(!i?.file||this.uploads.has(t))return;let a=new AbortController;this.uploads.set(t,a),this.patch(e,t,{state:`uploading`,error:``});try{let r=i.file,o=`web/local-agent-sessions/${e}/attachments/${t}`,s;if(r.size>5242880){for(let s=i.uploaded??0;s<r.size;s+=xe){let i=r.slice(s,s+xe);await n(`${o}/parts/${s/xe}?size=${r.size}`,f({ok:g()}),{method:`POST`,signal:a.signal,timeoutMs:d,body:i}),this.patch(e,t,{uploaded:s+i.size})}s=await n(`${o}/finish`,A,{method:`POST`,signal:a.signal,timeoutMs:d,body:{name:i.name,size:r.size,imageOnly:i.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(r)});if(a.signal.aborted)return;V(r)&&this.patch(e,t,{preview:o}),s=await n(`web/local-agent-sessions/${e}/${i.imageOnly?`images`:`attachments`}`,A,{method:`POST`,signal:a.signal,timeoutMs:d,body:{id:t,name:i.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:r(n),...n instanceof o&&n.code===`ATTACHMENT_INCOMPLETE`?{uploaded:0}:{}})}finally{this.uploads.get(t)===a&&this.uploads.delete(t)}}},Xe=(e,t,n,r=!1)=>v(`/api/v1/projects/${encodeURIComponent(e)}/local-agent/sessions/${encodeURIComponent(t)}/${r?`attachments`:`images`}/${encodeURIComponent(n)}`);function Ze({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)),u=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)(p,{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)(p,{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)(p,{name:`image`})}),e.state===`uploading`&&(0,I.jsx)(`span`,{className:`session-image-status`,role:`status`,"aria-label":`正在上传 ${e.name}`,children:(0,I.jsx)(p,{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)(p,{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)(p,{name:`close`,size:`small`})}),e.state===`failed`&&(0,I.jsx)(`small`,{className:`session-image-error`,children:e.error})]},e.id))}),c&&(0,I.jsx)(Je,{file:c,onClose:()=>a(void 0),gallery:u>=0&&l.length>1?{index:u,count:l.length,move:e=>a(l[(u+e+l.length)%l.length]?.id)}:void 0},c.id)]}):null}function Qe({images:e,url:t}){return(0,I.jsx)(Ze,{images:e.map(e=>({...e,file:e.mimeType===`application/octet-stream`,url:t(e.id)}))})}function $e(t,n,r){let i=_(),a=e(n,`computer-attachment-uploads`),o=(0,F.useMemo)(()=>{let e=i?.get(a)??new Ye;return i?.set(a,e),e},[i,a]),s=(0,F.useSyncExternalStore)(o.subscribe,()=>o.get(t)),c=T(),l=(0,F.useRef)(null),d=(0,F.useRef)(null);(0,F.useEffect)(()=>c(``),[t,n]);let f=s.flatMap(e=>e.attachment?[e.attachment]:[]),m=s.some(e=>e.state===`uploading`),h=e=>Xe(n,t,e,!0),g=(e,n=!1)=>c(o.add(t,e,r,n)??``);return{files:f,busy:m,count:s.length,failed:s.some(e=>e.state===`failed`),add:g,clear:()=>{for(let e of f)o.remove(t,e.id)},picker:(e,t)=>(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`input`,{ref:d,type:`file`,className:`session-image-file`,multiple:!0,"aria-label":`选择附件`,disabled:e,onChange:e=>{e.target.files&&g(e.target.files),e.target.value=``}}),t&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`input`,{ref:l,type:`file`,className:`session-image-file`,accept:`image/png,image/jpeg,image/webp`,multiple:!0,"aria-label":`选择图片`,disabled:e,onChange:e=>{e.target.files&&g(e.target.files,!0),e.target.value=``}}),(0,I.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":`添加图片`,title:`添加图片,也可粘贴或拖入`,disabled:e,onClick:()=>l.current?.click(),children:(0,I.jsx)(p,{name:`image`,size:`small`})})]}),(0,I.jsx)(`button`,{type:`button`,className:`icon-button`,"aria-label":`附件`,title:`添加附件,也可粘贴或拖入`,disabled:e,onClick:()=>d.current?.click(),children:(0,I.jsx)(p,{name:`attachment`,size:`small`})})]}),preview:e=>(0,I.jsx)(Ze,{images:s.map(e=>({id:e.id,name:e.name,mimeType:e.attachment?.mimeType??e.file?.type,url:e.attachment?h(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||!V(e.file)),state:e.state,...e.error?{error:e.error}:{}})),disabled:e,remove:e=>{o.remove(t,e),r(`web/local-agent-sessions/${t}/attachments/${e}`,u(),{method:`DELETE`}).catch(()=>{})},retry:e=>void o.upload(t,e,r)})}}var et={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 H({state:e,error:t}){let n=et[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)(p,{name:n.icon,size:`small`})})}function tt({message:e}){return!e.queue||e.queue.state===`running`?null:(0,I.jsx)(H,{state:e.queue.state,error:e.queue.error})}function nt(e,t,n,i){let[a,s]=(0,F.useState)(),[c,l]=(0,F.useState)(),u=(0,F.useRef)(null);(0,F.useEffect)(()=>{if(!t)return;let a=new AbortController,{signal:c}=a,d=`web/local-agent-sessions/${encodeURIComponent(t)}`,p=new URLSearchParams(location.search).get(`question`),m=new URLSearchParams(location.search).get(`message`),h,_,y=-1,b=``,x=0,S=0,C=(e,n)=>{if(c.aborted||n<y)return;y=n;let r=JSON.stringify(e);r!==b&&(b=r,l({session:t,value:e}))},w=!1,T=!1,E=Promise.resolve(),D=(e=``)=>{c.aborted||s({session:t,...h?{data:h}:{},error:e,loadingOlder:w})},O=e=>n(d+(Object.keys(e).length?`?`+new URLSearchParams(e):``),de,{signal:c}),k=e=>(E=E.then(async()=>{if(!c.aborted)try{await e()}catch(e){e instanceof o&&[401,403,404].includes(e.status)&&(h=void 0,l(void 0)),T=!0,D(r(e))}}),E),A=e=>k(async()=>{if(e!==void 0&&h&&h.cursor>=e&&!T)return;let t=_,n=await O(t===void 0?!h&&p?{question:p}:!h&&m&&/^[1-9]\d*$/.test(m)?{message:m}:{}:{from:String(t)});c.aborted||(h&&!i(!1)&&j(!1),_!==t&&_!==void 0&&n.olderBefore!==null&&n.olderBefore>_&&(n=await O({from:String(_)})),!h&&(p||m)&&(_=n.olderBefore??1),h=n,n.attention&&C(n.attention,n.cursor),T=!1,D())});function j(e){e&&!w?_=void 0:h&&_===void 0&&(_=h.olderBefore??1)}function ee(){h?.olderBefore&&!w&&(j(!1),w=!0,D(),k(async()=>{try{if(!h?.olderBefore)return;let e=await O({before:String(h.olderBefore)}),t=e.olderBefore??1,n=e.cursor===h.cursor?{...h,messages:[...e.messages,...h.messages],olderBefore:e.olderBefore}:await O({from:String(t)});if(c.aborted)return;i(!0),_=t,h=n,T=!1}finally{w=!1,D()}}))}u.current={reload:()=>A(),markRead:e=>(S=Math.max(S,e),k(async()=>{let e=S;e<=x||(await n(d+`/read`,f({ok:g()}),{method:`POST`,body:{through:e},signal:c}),x=e,window.dispatchEvent(new Event(`teammy:outbox`)))})),older:ee,follow:j,reveal:e=>k(async()=>{if(h?.messages.some(t=>t.seq===e))return;let t=Math.min(e,h?.messages[0]?.seq??e),n=await O({from:String(t)});_=t,h=n,T=!1,D()})},A();let te=new EventSource(v(`/api/v1/projects/${encodeURIComponent(e)}/${d}/events?updates=1&attention=1`)),M=e=>{document.hidden||A(Number(e.lastEventId))};te.addEventListener(`change`,M),te.addEventListener(`snapshot`,M),te.addEventListener(`attention`,e=>{C(fe.parse(JSON.parse(e.data)),Number(e.lastEventId))});let ne=setInterval(()=>{!document.hidden&&(T||te.readyState!==EventSource.OPEN)&&A()},15e3),N=()=>{document.hidden||A()};return document.addEventListener(`visibilitychange`,N),()=>{a.abort(),u.current=null,te.close(),clearInterval(ne),document.removeEventListener(`visibilitychange`,N)}},[t,e,n,i]);let d=(0,F.useCallback)(()=>u.current?.reload()??Promise.resolve(),[]),p=(0,F.useCallback)(e=>u.current?.markRead(e)??Promise.resolve(),[]),m=(0,F.useCallback)(()=>u.current?.older(),[]),h=(0,F.useCallback)(e=>u.current?.follow(e),[]),_=(0,F.useCallback)(e=>u.current?.reveal(e)??Promise.resolve(),[]);return{...a?.session===t?a:void 0,attention:c?.session===t?c.value:void 0,reload:d,older:m,follow:h,reveal:_,markRead:p}}function rt({message:e,images:t,status:n,rewind:a,onFile:o}){let s=a?.commands.find(t=>t.kind===`rewind`&&[`queued`,`running`,`uncertain`].includes(t.state)&&JSON.parse(t.argument).messageId===e.id),[c,u]=(0,F.useState)(!!s),[d,f]=(0,F.useState)(s?JSON.parse(s.argument).body:e.body),[m,h]=(0,F.useState)(!1),g=T(),[_,v]=(0,F.useState)(!1),[b,x]=(0,F.useState)(),S=(0,F.useRef)(void 0),C=je(d);(0,F.useLayoutEffect)(()=>{c&&C.current&&(C.current.style.height=`0px`,C.current.style.height=`${C.current.scrollHeight}px`)},[c]);let w=a?.commands.find(e=>e.id===b?.id)??b??s,E=_||w&&[`queued`,`running`].includes(w.state),O=a?.available&&e.source===`web_session`&&e.id.startsWith(`input:`)&&(!e.queue||[`handled`,`interrupted`].includes(e.queue.state));async function k(){if(!a||E||!d.trim())return;let t=JSON.stringify({messageId:e.id,body:d.trim(),expectedLastMessage:a.expectedLastMessage});(w&&[`failed`,`uncertain`].includes(w.state)||S.current?.argument!==t)&&(S.current={id:i(),argument:t}),v(!0),g(``);try{let e=await a.request(`web/local-agent-sessions/${a.session}/commands`,P,{method:`POST`,body:{id:S.current.id,kind:`rewind`,argument:S.current.argument}});x(e),a.refresh()}catch(e){g(r(e))}finally{v(!1)}}return(0,I.jsxs)(`div`,{className:`computer-user-entry${c?` editing`:``}`,children:[(0,I.jsxs)(Ae,{mine:!0,author:`你`,time:e.createdAt,children:[t,c?(0,I.jsxs)(`form`,{className:`computer-message-edit`,onSubmit:e=>{e.preventDefault(),k()},children:[(0,I.jsx)(`textarea`,{ref:C,"aria-label":`编辑历史消息`,value:d,onChange:e=>f(e.target.value),disabled:!!E,autoFocus:!0,rows:1}),(0,I.jsxs)(`div`,{className:`computer-message-edit-footer`,children:[(0,I.jsx)(`small`,{children:`替换此后的对话,保留工作区文件`}),(0,I.jsx)(y,{icon:`close`,label:`取消编辑`,disabled:!!E,onClick:()=>{u(!1),g(``),f(e.body)}}),(0,I.jsx)(`button`,{type:`submit`,className:`message-send primary`,"aria-label":E?`正在回退`:`从此处继续`,title:E?`正在回退`:`从此处继续`,disabled:!!E||!d.trim(),children:(0,I.jsx)(p,{name:E?`loading`:`send`,size:`small`})})]}),(0,I.jsx)(D,{children:w&&[`failed`,`uncertain`].includes(w.state)&&w.error})]}):(0,I.jsx)(`div`,{className:`markdown`,children:(0,I.jsx)(Ee,{onFile:o,children:e.body})}),!c&&n]}),!c&&(0,I.jsxs)(`div`,{className:`computer-message-actions`,children:[(0,I.jsx)(y,{icon:m?`check`:`copy`,label:m?`已复制`:`复制消息`,onClick:()=>{g(``),l(e.body).then(()=>h(!0)).catch(e=>g(r(e)))}}),O&&(0,I.jsx)(y,{icon:`edit`,label:`编辑并从此处继续`,onClick:()=>{f(e.body),u(!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)(p,{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 W(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 it({children:e,readSeq:t}){return(0,I.jsx)(`div`,{className:`computer-divider`,"data-completion-seq":t,children:(0,I.jsx)(`span`,{children:e})})}function at({message:e,readable:t=!1}){let n=e.state===`succeeded`?`已工作`:e.state===`interrupted`?`已停止`:e.state===`failed`?`执行失败`:`需要核对`;return(0,I.jsxs)(it,{readSeq:t?e.seq:void 0,children:[n,e.activity?.durationMs===void 0?``:` · ${W(e.activity.durationMs)}`]})}var G={offered:`待本地接收`,pending:`待投递`,human_routed:`未送达本地`,failed:`失败`,uncertain:`需要核对`};function ot(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 K({text:e,onFile:t}){let n=[],r=0;if(t)for(let{start:i,end:a,link:o}of we(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 q({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)(H,{state:e.state}),e.activity?.durationMs!==void 0&&(0,I.jsx)(`span`,{children:W(e.activity.durationMs)})]}),children:i&&n&&(0,I.jsx)(K,{text:e.body,onFile:t})})}function J({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)(p,{name:`chevron`,size:`small`}),e.length,` 次工具调用`,o&&(0,I.jsx)(H,{state:o}),e.some(e=>e.state===`running`)&&(0,I.jsx)(H,{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)(q,{call:e,onFile:t,visible:!a||r,onOpen:a?void 0:i},e.id))})]})}function st({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=ot(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)(J,{calls:e,onFile:a},`tools:${f.get(e[0].id)}`);let c=e.activity;if(e.role===`system`)return(0,I.jsx)(it,{children:e.body},e.id);if(c?.kind===`turn`)return s.has(c.turnId)?null:(0,I.jsx)(at,{message:e,readable:!0},e.id);if(e.role===`user`)return(0,I.jsx)(rt,{message:e,rewind:i,onFile:a,images:n&&(e.attachments??e.images)?.length?(0,I.jsx)(Qe,{images:e.attachments??e.images,url:t=>n(t,!!e.attachments)}):null,status:e.queue&&r?r(e):G[e.state]&&(0,I.jsx)(De,{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)(at,{message:l}),(0,I.jsx)(`article`,{"data-message-seq":e.seq,"data-completion-seq":l?.seq??(e.source===`agent-final`&&[`sent`,`succeeded`,`failed`,`interrupted`,`uncertain`].includes(e.state)?e.seq:void 0),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)(Ee,{onFile:a,children:e.body})})})]},e.id)})})}function Y({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),u=(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]),d=je(i,u);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:d,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)(p,{name:`send`,size:`small`})})]})}function ct(e,t){let n=new Set,r=()=>{if(document.hidden||!document.hasFocus())return;let e=document.querySelector(`dialog[open]`);for(let r of n){if(e&&!e.contains(r))continue;let n=r.getBoundingClientRect(),i=r.closest(`.assistant-transcript`)?.getBoundingClientRect();n.width>0&&n.height>0&&n.bottom>Math.max(0,i?.top??0)&&n.top<Math.min(innerHeight,i?.bottom??innerHeight)&&t(r)}},i=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&t.intersectionRect.height>0?n.add(t.target):n.delete(t.target);r()});for(let t of e)i.observe(t);return window.addEventListener(`focus`,r),document.addEventListener(`focusin`,r),document.addEventListener(`visibilitychange`,r),()=>{i.disconnect(),window.removeEventListener(`focus`,r),document.removeEventListener(`focusin`,r),document.removeEventListener(`visibilitychange`,r)}}function lt({question:e,session:t,request:n,refresh:a}){let[o,s]=(0,F.useState)({}),[c,l]=(0,F.useState)({}),d=T(),[m,h]=(0,F.useState)(!1),[_,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(``),x=(0,F.useRef)(null),S=(0,F.useRef)(!1),C=(0,F.useRef)(void 0);(0,F.useEffect)(()=>{if(e.state!==`pending`||S.current||!x.current)return;let i=!1;return ct([x.current],()=>{S.current||i||(i=!0,n(`web/local-agent-sessions/${t}/questions/${e.id}/presented`,f({ok:g()}),{method:`POST`}).then(()=>{S.current=!0,window.dispatchEvent(new Event(`teammy:outbox`))}).catch(e=>d(r(e))).finally(()=>{i=!1}))})},[e.id,e.state,t,n]);async function w(o){let s=JSON.stringify(o);C.current?.fingerprint!==s&&(C.current={fingerprint:s,value:{...o,id:i()}}),h(!0),d(``);try{return await n(`web/local-agent-sessions/${t}/questions/${e.id}/answers`,u(),{method:`POST`,body:C.current.value}),C.current=void 0,a(),!0}catch(e){return d(r(e)),!1}finally{h(!1)}}let[E,D]=(0,F.useState)(Date.now);(0,F.useEffect)(()=>{if(!e.approval||e.state!==`pending`||e.autoApproveAt==null)return;D(Date.now());let t=setInterval(()=>D(Date.now()),1e3);return()=>clearInterval(t)},[e.approval,e.state,e.autoApproveAt]);let O=e.autoApprove!==!1&&e.autoApproveAt!=null?Math.max(0,Math.ceil((e.autoApproveAt-E)/1e3)):null,A=e.response,j=e.state===`answered`,ee=[`expired`,`cancelled`].includes(e.state),te=[`human_routed`,`failed`,`handled`].includes(e.submissionState??``)&&!j,M=k(e),ne=e.kind===`plan`,N=e.actions?.find(e=>e.id===A?.actionId),re=ee?`已过期`:e.state===`uncertain`||e.submissionState===`uncertain`?`需核对`:j?ne?N?.label??`已处理`:e.approval?A?.decision===!0?`已允许`:A?.decision===!1?`已拒绝`:`已处理`:N?N.label:A?``:`已回答`:te?`请重新提交`:A?`正在提交`:``,ie=ee||A?.decision===!1||te?`close`:j?`check`:`clock`,ae=e.questions.length>1||e.questions.some(e=>e.multiSelect),oe=(t=o)=>w({body:e.questions.length===1?t[e.questions[0].id]||(c[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:c}:{}});if(e.delivery===`async`&&(j||ee)){let t=j&&A?e.questions.flatMap(e=>[...A.selections?.[e.id]??[],A.answers[e.id]].filter(Boolean)):[];return t.length?(0,I.jsxs)(`div`,{className:`question-response native-async-answer`,children:[(0,I.jsx)(p,{name:`check`,size:`small`}),(0,I.jsx)(`span`,{children:t.join(`
9
- `)})]}):null}return(0,I.jsxs)(`div`,{className:`native-question ${ne?`native-plan`:``} ${M?`native-question-pending`:``}`,ref:x,children:[ne?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`native-plan-heading`,children:[(0,I.jsx)(p,{name:`file`,size:`small`}),(0,I.jsx)(`span`,{children:`实施计划`})]}),M?(0,I.jsx)(`div`,{className:`native-plan-content markdown`,children:(0,I.jsx)(Ee,{children:e.plan??``})}):(0,I.jsxs)(`details`,{className:`native-plan-history markdown`,children:[(0,I.jsx)(`summary`,{children:`查看计划`}),(0,I.jsx)(Ee,{children:e.plan??``})]}),M&&(0,I.jsxs)(I.Fragment,{children:[!_&&(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:m,title:e.description,className:e.id===`implement`?`primary`:``,onClick:()=>e.id===`revise`?v(!0):void w({body:e.label,actionId:e.id}),children:e.label},e.id))}),!_&&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]}),_&&(0,I.jsxs)(`form`,{className:`native-plan-feedback`,onSubmit:e=>{e.preventDefault(),w({body:y,actionId:`revise`})},children:[(0,I.jsxs)(`label`,{children:[`修改意见`,(0,I.jsx)(`textarea`,{autoFocus:!0,value:y,onChange:e=>b(e.target.value),placeholder:`说明希望调整的部分,Agent 将修改后再次请求确认`})]}),(0,I.jsxs)(`div`,{className:`question-actions native-plan-feedback-actions`,children:[(0,I.jsx)(`button`,{className:`primary`,disabled:m||!y.trim(),children:`提交修改意见`}),(0,I.jsx)(`button`,{type:`button`,disabled:m,onClick:()=>v(!1),children:`返回计划`})]})]})]}),!M&&A?.actionId===`revise`&&A.answers.feedback&&(0,I.jsx)(`div`,{className:`question-response`,children:A.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
- `)})}),M?(0,I.jsxs)(`div`,{className:`native-approval-options`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`primary`,disabled:m,"aria-label":`允许`,title:O===null?void 0:`倒计时结束后自动允许本次操作`,onClick:()=>void w({body:`允许`,decision:!0}),children:[`允许`,O!==null&&(0,I.jsxs)(`span`,{"aria-hidden":`true`,children:[`(`,O,`s)`]})]}),(0,I.jsx)(`button`,{type:`button`,disabled:m,onClick:()=>void w({body:`拒绝`,decision:!1}),children:`拒绝`})]}):re&&(0,I.jsxs)(`small`,{className:`question-result`,children:[(0,I.jsx)(p,{name:ie,size:`small`}),re]})]}):(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}),M&&(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:m,"aria-pressed":t.multiSelect?c[t.id]?.includes(e)??!1:o[t.id]===e,onClick:()=>{if(t.multiSelect){l(n=>({...n,[t.id]:n[t.id]?.includes(e)?n[t.id].filter(t=>t!==e):[...n[t.id]??[],e]}));return}let n={...o,[t.id]:e};s(n),ae||oe(n)},children:[(0,I.jsxs)(`span`,{className:`question-option-label`,children:[t.multiSelect&&(0,I.jsx)(`span`,{"aria-hidden":`true`,className:`question-check`,children:c[t.id]?.includes(e)&&(0,I.jsx)(p,{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&&M&&(0,I.jsx)(Y,{initialValue:t.initialValue,placeholder:t.placeholder,disabled:m,onSend:async e=>{let n={...o,[t.id]:e};return s(n),ae?!0:oe(n)}}),M&&ae&&o[t.id]&&!t.options.includes(o[t.id])&&(0,I.jsx)(`small`,{children:o[t.id]}),!M&&!e.approval&&(A?.answers[t.id]||A?.selections?.[t.id]?.length)&&(0,I.jsxs)(`div`,{className:`question-response`,children:[(0,I.jsx)(p,{name:j?`check`:`clock`,size:`small`}),(0,I.jsx)(`span`,{children:[...A.selections?.[t.id]??[],A.answers[t.id]].filter(Boolean).join(`、`)})]})]},t.id)),M&&e.actions?.length&&(0,I.jsx)(`div`,{className:`question-actions`,children:e.actions.map(e=>(0,I.jsx)(`button`,{disabled:m,onClick:()=>void w({body:e.label,actionId:e.id}),children:e.label},e.id))}),M&&ae&&(0,I.jsx)(`div`,{className:`question-actions`,children:(0,I.jsx)(`button`,{disabled:m||e.questions.some(e=>!o[e.id]?.trim()&&!c[e.id]?.length),onClick:()=>void oe(),children:`回答`})})]}),re&&(!e.approval||ne)&&(0,I.jsxs)(`small`,{className:`question-result`,children:[(0,I.jsx)(p,{name:ie,size:`small`}),re]})]})}function ut({session:e,active:t,commands:n,request:a,refresh:o,onError:s}){let[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(),f=(0,F.useRef)(void 0),m=n.find(e=>e.id===u?.id)??u,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){f.current??=i(),l(!0),s(``);try{let t=await a(`web/local-agent-sessions/${e}/commands`,P,{method:`POST`,body:{id:f.current,kind:`stop`}});d(t),f.current=void 0,o()}catch(e){s(r(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)(p,{name:`stop`,size:`small`})]})}var X={minimal:`极低`,low:`低`,medium:`中`,high:`高`,xhigh:`极高`,max:`最高`,ultra:`极致`,none:`无`,off:`关闭`};function dt({id:e,label:t,current:n,options:r,disabled:i,onSelect:a}){let o=r.find(e=>e.value===n);return(0,I.jsx)(C,{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)(p,{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)(p,{name:`check`,size:`small`})]},t.value))]})})}function ft({session:e,models:t,busy:n,available:r,online:i,commands:a,controls:o,draft:s,onInsert:c,onConfig:l}){let[u,d]=(0,F.useState)(!1);(0,F.useEffect)(()=>{/^[/$]([^\s]*)$/.exec(s)?d(!0):d(!1)},[s]);let f=e.config.model??e.effectiveConfig?.model,m=t.find(e=>e.id===f||e.resolvedModel===f)??(e.config.model?void 0:t.find(e=>e.isDefault)),h=n||!r,g=e.provider===`claude`,_=e.provider===`cursor`,v=o??Se(e.provider),y=m?.effortLabel??`思考强度`,b=e=>m?.effortLabel?e:X[e]??e,x=e.appliedRevision===e.revision?e.effectiveConfig?.mode:void 0,S=t.find(e=>e.isDefault)?.id??(e.config.model?null:e.effectiveConfig?.model),w=t.find(e=>e.id===S)?.name??S,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)(C,{id:`session-commands`,triggerId:`session-command-trigger`,label:`命令与 Skills`,placement:`top`,className:`composer-menu composer-commands`,routeKey:e.id,trigger:(0,I.jsx)(p,{name:`command`,size:`small`}),open:u,onOpenChange:d,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)(dt,{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)(dt,{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)(dt,{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)(dt,{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 pt=(0,F.lazy)(()=>ve(()=>import(`./TerminalPane-BTRM-36z.js`),__vite__mapDeps([0,1,2,3,4,5,6,7]),import.meta.url)),mt={idle:`空闲`,working:`工作中`,waiting:`等待回答`,queued:`等待执行`,uncertain:`需要核对`,human:`人工处理`,offered:`待本地接收`,accepted:`本地已接手`,human_routed:`未送达本地`,pending:`待投递`,sent:`已发送`,succeeded:`已完成`,running:`进行中`,failed:`失败`};function ht(e){return{width:e.clientWidth,height:e.clientHeight,top:e.scrollHeight-e.clientHeight}}function Z({navigate:e,memberId:t}){let{request:n,projectId:r}=re(),i=(0,F.useCallback)(e=>n(`web/local-agent-settings`,ge,{signal:e}),[n]),a=s(i,3e4);return(0,F.useEffect)(()=>{let e=()=>void a.reload();return window.addEventListener(`teammy:local-access`,e),()=>window.removeEventListener(`teammy:local-access`,e)},[a.reload]),!a.data&&a.error?(0,I.jsx)(c,{resource:a}):a.data?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(E,{message:a.error}),(0,I.jsx)(Q,{localAvailable:a.data.accessible,navigate:e,memberId:t},`${r}/${t}`)]}):null}function Q({localAvailable:t,navigate:n,memberId:a}){let o=re(),l=_(),d=e(o.projectId,a,`computer-selection`),f=e(o.projectId,a,`computer-drafts`),h=l?.get(d),[g,b]=(0,F.useState)(()=>new Set),[S,w]=(0,F.useState)(()=>({project:o.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??``)})),E=T(),[O,A]=(0,F.useState)(!1),[M,N]=(0,F.useState)(!1),[ce,de]=(0,F.useState)(()=>l?.get(f)??{}),fe=ce[S.session]??``,ge=e=>de(t=>({...t,[S.session]:typeof e==`function`?e(t[S.session]??``):e}));(0,F.useEffect)(()=>{l?.set(f,ce)},[l,f,ce]);let[ve,be]=(0,F.useState)(``),[xe,Se]=(0,F.useState)(!1),[P,we]=(0,F.useState)(`codex`),[Ee,Ae]=(0,F.useState)(!1),[je,Ne]=(0,F.useState)(``),[Ie,L]=(0,F.useState)(),[Le,Re]=(0,F.useState)(Date.now);(0,F.useEffect)(()=>{let e=setInterval(()=>Re(Date.now()),6e4);return()=>clearInterval(e)},[]);let R=(0,F.useRef)(null),z=(0,F.useRef)(!0),Be=(0,F.useRef)(null),He=(0,F.useCallback)(e=>{let t=ht(e),n=Be.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},[]),We=(0,F.useCallback)(e=>{e.scrollTop=e.scrollHeight,Be.current=ht(e)},[]),Ke=(0,F.useRef)(null),qe=(0,F.useCallback)(e=>{let t=R.current;if(!t)return!0;if(He(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 Ke.current={...r?{node:r}:{},offset:r?.getBoundingClientRect().top??0,top:t.scrollTop,height:t.scrollHeight},!1},[He]),B=(0,F.useRef)(new URLSearchParams(location.search).get(`question`)),V=(0,F.useRef)(Number(new URLSearchParams(location.search).get(`message`))||null),Ye=(0,F.useRef)(null),Ze=(0,F.useRef)(void 0),Qe=(0,F.useRef)(i()),et=(0,F.useCallback)(async e=>t?(await o.request(`web/local-agent-computers`,le,{signal:e})).computers.map(e=>({...e,project:o.projectId})):[],[o,t]),H=s(et,3e3),rt=(H.data??[]).flatMap(e=>e.directories.map(t=>({c:e,d:t,label:ue(H.data??[],e,t)}))).sort((e,t)=>e.label.localeCompare(t.label)),U=H.data?.find(e=>e.project===S.project&&e.directories.some(e=>e.id===S.directory)),W=ze(o.projectId,t),it=W.terminals.find(e=>e.id===S.terminal),at=(0,F.useRef)(it);it&&(at.current=it);let G=it??(at.current?.id===S.terminal?at.current:void 0),ot=U?.directories.find(e=>e.id===S.directory),K=H.data?.find(e=>e.directories.some(e=>e.id===je))??U,q=K?.directories.find(e=>e.id===je)??ot;ee(S.project);let J=(0,F.useCallback)((e,t,n)=>ee(S.project).request(e,t,n),[S.project]),Y=$e(S.session,S.project,J),X=nt(S.project,t?S.session:``,J,qe);function dt(e){let t=He(e);return t&&!z.current&&(Be.current=ht(e)),z.current=t,X.follow(t),t}let Z=X.data;(0,F.useLayoutEffect)(()=>{z.current=!0,Be.current=null,Ye.current=null,Ke.current=null},[S.project,S.session]);let Q=Z?.session;oe(S.project,Q?.id??``);let gt=X.attention,_t=gt?.title??Q?.title,vt=gt?.question?{question:`待回答`,approval:`待授权`,plan:`待确认`}[gt.question]:gt?.completion?`完成`:``;pe(S.session&&_t?`${vt?`[${vt}] `:``}${_t}`:void 0);let yt=Z?.pendingQuestions??Z?.messages.flatMap(({question:e,seq:t})=>e?.delivery===`async`&&k(e)?[{id:e.id,seq:t}]:[])??[];function bt(e){let t=R.current,n=document.getElementById(`computer-question-${e}`);return!t||!n||!t.contains(n)||!n.getClientRects().length?!1:(z.current=!1,Ye.current=e,t.scrollTop+=n.getBoundingClientRect().top-t.getBoundingClientRect().top-16,n.focus({preventScroll:!0}),!0)}function xt(e){let t=R.current,n=t?.querySelector(`[data-message-seq="${e}"], [data-completion-seq="${e}"]`);return!t||!n||!n.getClientRects().length?!1:(z.current=!1,t.scrollTop+=n.getBoundingClientRect().top-t.getBoundingClientRect().top-16,!0)}(0,F.useEffect)(()=>{let e=e=>{let t=e.detail;if(t.project!==S.project||t.session!==S.session)return;let n=new URL(location.href);n.searchParams.delete(`question`),n.searchParams.delete(`message`),B.current=t.question??null,V.current=t.question?null:t.sequence,n.searchParams.set(`directory`,S.directory),n.searchParams.set(`session`,S.session),n.searchParams.set(t.question?`question`:`message`,t.question??String(t.sequence)),history.replaceState(null,``,n),(t.question?bt(t.question):xt(t.sequence))?(B.current=null,V.current=null):X.reveal(t.sequence)};return window.addEventListener(`teammy:notification-open`,e),()=>window.removeEventListener(`teammy:notification-open`,e)},[S.project,S.session,S.directory,X.reveal]),(0,F.useLayoutEffect)(()=>{if(!Q||!R.current)return;let e=R.current;if(B.current){let e=B.current;if(bt(e)){B.current=null,Ke.current=null;return}}if(V.current&&xt(V.current)){V.current=null,Ke.current=null;return}let t=Ke.current;Ke.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&&We(e)},[Q?.id,ot?.id,Z,We]),(0,F.useLayoutEffect)(()=>{let e=R.current;if(!e||!Q)return;let t=new ResizeObserver(()=>{z.current&&He(e)&&We(e)});return t.observe(e),()=>t.disconnect()},[Q?.id,ot?.id,He,We]),(0,F.useEffect)(()=>{U?.online===!1&&X.reload()},[U?.online,X.reload]);let St=(0,F.useRef)(Z?.messages);(0,F.useLayoutEffect)(()=>{St.current=Z?.messages},[Z?.messages]);let Ct=(0,F.useCallback)(({path:e,line:t})=>{let n=Te(e,S.terminal?G?.cwd:Q?.cwd);if(!n)return;let r=n.split(`/`).at(-1),i=/\/\.workspace\/\.teammy-attachments\/([0-9a-f-]{36})\/[^/]+$/i.exec(n);if(!S.terminal&&Q&&i){let e=St.current?.flatMap(e=>e.attachments??[]).find(e=>e.id===i[1]);L({...e,name:e?.name??r,line:t,url:Xe(S.project,Q.id,i[1],!0)});return}let a=S.terminal?G?.directory:Q?.executionDirectory??Q?.directory;if(!a)return;let o=v(`/api/v1/projects/${encodeURIComponent(S.project)}/web/local-agents/${encodeURIComponent(a)}/file?${new URLSearchParams({path:n})}`),s=Ge(r);L({name:r,line:t,url:o,previewUrl:o+(s.startsWith(`text/`)?`&view=text`:s?``:`&view=info`)})},[S.project,S.terminal,Q?.directory,Q?.executionDirectory,Q?.id,Q?.cwd,G?.directory,G?.cwd]),wt=U?.capabilities.includes(`local-sessions-v1`),$=(e,t,n=``,r=``)=>{L(void 0),w({project:e,directory:t,session:n,terminal:r}),l?.set(d,{directory:t,session:n,terminal:r}),Se(!1),Ae(!1),E(``);let i=new URL(location.href);(S.session!==n||r)&&(i.searchParams.delete(`question`),i.searchParams.delete(`message`),B.current=null,V.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===o.projectId&&history.replaceState(null,``,i)};(0,F.useEffect)(()=>{let e=H.data?.find(e=>e.sessions.some(e=>e.id===S.session))??H.data?.find(e=>e.directories.length);if(!S.directory&&e?.directories.length){let t=e.directories[0],n=e.sessions.find(e=>e.id===S.session);$(e.project,n?.directory??t.id,n?.id??t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id)}},[H.data]),(0,F.useEffect)(()=>{if(Q&&R.current)return ct([...R.current.querySelectorAll(`[data-completion-seq]`)],e=>void X.markRead(Number(e.getAttribute(`data-completion-seq`))))},[Q?.id,Z?.messages,X.markRead]);async function Tt(e){A(!0),E(``);try{await e(),await Promise.all([X.reload(),H.reload()])}catch(e){E(r(e))}finally{A(!1)}}function Et(e,t){return Tt(async()=>{if(await o.request(`web/local-agent-sessions/${e.id}/metadata`,ae,{method:`PUT`,body:{expectedRevision:e.metadataRevision,...t}}),t.hidden&&S.session===e.id){let t=U?.sessions.find(t=>t.directory===e.directory&&t.id!==e.id&&!t.hidden);$(S.project,e.directory,t?.id)}})}function Dt(e){let t=new URLSearchParams({tab:`connect`,directory:e,session:S.session});n(`/projects/${o.projectId}/settings?${t}`)}function Ot(e){let t=rt.find(({d:t})=>t.id===e),n=t?.d.provider??`codex`;return se(n)&&!t?.c.providers.some(e=>e.id===n&&e.available)?`codex`:n}function kt(e=S.directory){let t=H.data?.find(t=>t.directories.some(t=>t.id===e))??U,n=t?.directories.find(t=>t.id===e)??t?.directories[0];!n||!t?N(!0):(Qe.current=i(),Ne(n.id),Se(!0),we(Ot(n.id)),E(``))}let[At,jt]=(0,F.useState)(null);(0,F.useEffect)(()=>jt(null),[Q?.id]);let Mt=U?.catalogs.find(e=>e.provider===(Q?.provider??`codex`)&&(Q?.cwd?e.cwd===Q.cwd:e.directory===(Q?.executionDirectory??Q?.directory))),Nt=Mt?.commands??[],Pt=Mt?.models??U?.providers.find(e=>e.id===Q?.provider)?.models??(Q?.provider===`codex`?U?.models??[]:[]),Ft=Pt.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:Pt.find(e=>e.isDefault)),It=!!U?.capabilities.includes(`local-agent-attachments-v1`),Lt=!!(Ft?.images??(!Q?.config.model&&U?.providers.find(e=>e.id===Q?.provider)?.defaultImages))&&!!U?.capabilities.includes(`local-agent-images-v1`),Rt=Q?.state===`working`&&!Z?.commands.some(e=>e.kind===`stop`&&[`queued`,`running`].includes(e.state)),zt=(Q?.provider===`cursor`||se(Q?.provider))&&U?.capabilities.includes(`local-agent-steer-v1`),Bt=!U?.capabilities.includes(`local-agent-steer-v1`)&&(Q?.provider===`cursor`||Q?.provider===`claude`);function Vt(e){let t=fe.trim();if(!Q||!t&&!Y.files.length)return;let n=Y.files.map(e=>e.id),r=Lt?Y.files.filter(e=>e.mimeType!==`application/octet-stream`).map(e=>e.id):[],a=At?.path&&t.startsWith(`$${At.name}`)?[{name:At.name,path:At.path}]:void 0,o=JSON.stringify({session:Q.id,body:t,skills:a,attachments:n,images:r,delivery:e});Ze.current?.fingerprint!==o&&(Ze.current={fingerprint:o,id:i()});let s=Ze.current;Tt(async()=>{await J(`web/local-agent-sessions/${Q.id}/messages`,u(),{method:`POST`,body:{id:s.id,body:t,delivery:e,...r.length?{images:r}:{},...n.length?{attachments:n}:{},...a?{skills:a}:{}}}),ge(e=>e.trim()===t?``:e),jt(null),Y.clear(),Ze.current===s&&(Ze.current=void 0)})}let Ht=(0,F.useMemo)(()=>(0,I.jsx)(st,{onFile:Ct,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)=>Xe(S.project,Q.id,e,t),renderQueue:e=>(0,I.jsx)(tt,{message:e}),renderQuestion:e=>(0,I.jsx)(lt,{question:e,session:Q.id,request:J,refresh:X.reload})}),[Q,Z,J,X.reload,S.project,Ct]);return(0,I.jsxs)(ke,{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:Pe,children:rt.map(({c:e,d:t,label:n})=>{let r=`${e.project}/${t.id}`,i=!g.has(r);return(0,I.jsxs)(`div`,{role:`none`,children:[(0,I.jsxs)(`div`,{className:`computer-tree-row`,role:`none`,children:[(0,I.jsxs)(Ce,{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)(p,{name:`chevron`,size:`small`})}),onClick:()=>{S.directory!==t.id&&$(e.project,t.id,t.defaultSession??e.sessions.find(e=>e.directory===t.id)?.id),b(e=>{let t=new Set(e);return i?t.add(r):t.delete(r),t})},children:[(0,I.jsx)(p,{name:`files`}),(0,I.jsx)(`span`,{className:`tree-name`,title:n,children:n})]}),(0,I.jsx)(y,{icon:`plus`,label:`新建会话:${n}`,className:`computer-tree-action`,onClick:()=>kt(t.id)})]}),i&&(0,I.jsxs)(`div`,{role:`group`,children:[W.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)(Ce,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":S.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)(p,{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`?`已退出`:Ve(n.createdAt,Le)})]})]})},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)(Ce,{className:`tree-item`,role:`treeitem`,"aria-level":2,"aria-selected":S.session===n.id&&S.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} · ${ne[n.provider]}`,onClick:()=>$(e.project,t.id,n.id),children:[(0,I.jsx)(ye,{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:Ve(n.updatedAt,Le)})]})]}),(0,I.jsx)(y,{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 Et(n,{pinned:!n.pinned})}),n.archived?(0,I.jsx)(`span`,{title:`已归档`,role:`img`,"aria-label":`已归档`,children:(0,I.jsx)(p,{name:`archive`,size:`small`})}):n.state!==`idle`&&(0,I.jsx)(De,{state:n.state,label:mt[n.state]??n.state})]},n.id))]})]},t.id)})}),(0,I.jsx)(c,{resource:H})]}),children:[M&&(0,I.jsx)(_e,{onClose:()=>N(!1)}),Ee&&K&&q&&(0,I.jsx)(Ue,{directory:q.id,provider:P===`terminal`?q.provider:P,providers:K.providers.filter(e=>!se(e.id)||e.available).map(e=>e.id),sessions:K.sessions,request:J,onClose:()=>Ae(!1),onImport:e=>{$(S.project,e.directory,e.id),H.reload()}}),xe&&q&&(0,I.jsx)(m,{id:`computer-new-session`,title:`新建会话`,onClose:()=>Se(!1),children:(0,I.jsxs)(`form`,{className:`computer-panel stack`,onSubmit:e=>{e.preventDefault(),Tt(async()=>{if(P===`terminal`){let e=Qe.current;await W.request({type:`create`,id:e,directory:q.id,title:ve.trim(),cols:100,rows:28}),Qe.current=i(),be(``),$(S.project,q.id,``,e);return}let e=await J(`web/local-agents/${q.id}/sessions`,ae,{method:`POST`,body:{id:Qe.current,title:ve,provider:P}});Qe.current=i(),Se(!1),be(``),$(S.project,q.id,e.id)})},children:[rt.length>1?(0,I.jsx)(ie,{title:`执行目录`,children:(0,I.jsx)(`select`,{"aria-label":`执行目录`,disabled:O,value:q.id,onChange:e=>{Ne(e.target.value),we(Ot(e.target.value))},children:rt.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:ve,onChange:e=>be(e.target.value)})]}),(0,I.jsx)(me,{label:`会话类型`,value:P,onChange:we,disabled:O,providers:he.options.filter(e=>e===`codex`||(e===`claude`?K?.capabilities.includes(`local-agent-providers-v1`):K?.providers.some(t=>t.id===e&&(!se(e)||t.available)))),terminal:W.directories.includes(q.id)}),P===`terminal`&&(0,I.jsx)(`p`,{className:`muted computer-create-scope`,children:`在此目录启动本机 Shell,使用本机用户权限。`}),(0,I.jsx)(D,{children:K?.providers.find(e=>e.id===P)?.error}),(0,I.jsxs)(`div`,{className:`computer-create-options`,children:[P!==`terminal`&&(0,I.jsx)(`button`,{type:`button`,disabled:!K?.online||!K.capabilities.includes(`local-agent-history-v1`),onClick:()=>{Se(!1),Ae(!0)},children:`导入历史会话`}),(0,I.jsx)(`button`,{type:`button`,onClick:()=>{Se(!1),N(!0)},children:`接入目录`}),(0,I.jsx)(`button`,{className:`primary`,disabled:O||!ve.trim()||(P===`terminal`?!W.directories.includes(q.id):!wt),children:`创建`})]})]})}),Ie&&(0,I.jsx)(Je,{file:Ie,onClose:()=>L(void 0)},Ie.url),S.terminal?G?(0,I.jsx)(F.Suspense,{fallback:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(j,{title:G.title}),(0,I.jsx)(`div`,{className:`assistant-empty`,children:`正在打开终端…`})]}),children:(0,I.jsx)(pt,{terminal:G,onFile:Ct,connection:W,onClosed:()=>$(S.project,S.directory)},G.id)}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(j,{title:`终端`}),(0,I.jsx)(`div`,{className:`assistant-empty`,children:W.connected?`终端已结束或电脑已重启,请新建终端。`:`正在连接终端…`})]}):ot?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(j,{title:Q?(0,I.jsx)(Fe,{title:Q.title,busy:O,onSave:e=>Et(Q,{title:e})},Q.id):(0,I.jsx)(`h2`,{children:ot.name}),actions:(0,I.jsx)(I.Fragment,{children:(0,I.jsx)(C,{id:`computer-session-menu`,triggerId:`computer-session-actions`,label:`会话操作`,trigger:(0,I.jsx)(p,{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&&Et(Q,{hidden:!0})},children:`隐藏会话`}),(0,I.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),Dt(ot.id)},children:`连接专用群`}),(0,I.jsx)(`button`,{role:`menuitem`,onClick:()=>{e(),Dt(ot.id)},children:`执行位置`})]})})})}),!wt&&(0,I.jsx)(x,{children:`升级客户端后可使用多个会话和网页对话。`}),(0,I.jsxs)(Oe,{ref:R,onClickCapture:({target:e,currentTarget:t})=>{e instanceof Element&&e.closest(`.tool-summary`)&&(z.current=!1,requestAnimationFrame(()=>{t===R.current&&t.contains(e)&&dt(t)}))},onWheel:e=>{e.deltaY<0&&e.currentTarget.scrollTop<=0&&Z?.olderBefore&&(z.current=!1,X.older())},onScroll:e=>{let t=e.currentTarget;!dt(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)(c,{resource:X}),Ht,(0,I.jsx)(D,{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,` · `,mt[e.state]??e.state,e.error?`:${e.error}`:``]},e.id)),yt.length>0&&(0,I.jsx)(`div`,{className:`computer-question-shortcut`,children:(0,I.jsxs)(`button`,{type:`button`,onClick:()=>{let e=(yt.findIndex(e=>e.id===Ye.current)+1)%yt.length,t=yt[e];bt(t.id)||(z.current=!1,B.current=t.id,X.reveal(t.seq))},children:[(0,I.jsx)(p,{name:`question`,size:`small`}),`有 `,yt.length,` 个问题等待你的确认`]})}),Q&&(0,I.jsx)(Me,{value:fe,onChange:ge,label:`向本地 Agent 发送消息`,sendLabel:Rt?zt?`中断并发送`:Bt?`加入队列`:`插话`:`发送`,onQueue:[`working`,`waiting`].includes(Q.state)&&U?.capabilities.includes(`local-agent-queue-v1`)?()=>Vt(`queue`):void 0,placeholder:Q.archived?`会话已归档`:`输入消息…`,disabled:Q.archived||!wt,sendDisabled:O||Y.busy||Y.failed||Y.count>0&&!It||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`)&&!Lt&&(0,I.jsx)(x,{children:`当前模型将通过本地文件路径接收图片。`})]}),hasAttachments:Y.count>0,onFiles:It&&!O?e=>void Y.add(e):void 0,beforeSend:(0,I.jsx)(ut,{session:Q.id,active:[`working`,`waiting`].includes(Q.state),commands:Z?.commands??[],request:J,refresh:X.reload,onError:E},Q.id),actions:(0,I.jsxs)(I.Fragment,{children:[It?Y.picker(O||!wt,Lt):Lt?(0,I.jsx)(`span`,{title:`更新开发机客户端后可添加附件`,children:(0,I.jsx)(`button`,{type:`button`,className:`icon-button`,disabled:!0,"aria-label":`更新开发机客户端后可添加附件`,children:(0,I.jsx)(p,{name:`attachment`,size:`small`})})}):null,(0,I.jsx)(ft,{session:Q,models:Pt,busy:O,available:!!wt,online:!!U?.online,commands:Nt,controls:Mt?.controls,draft:fe,onInsert:e=>{jt(e.kind===`skill`?e:null),ge(`${e.prefix??(e.kind===`skill`?`$`:`/`)}${e.name} `),requestAnimationFrame(()=>document.querySelector(`.message-composer textarea`)?.focus())},onConfig:e=>{Tt(()=>J(`web/local-agent-sessions/${Q.id}/settings`,ae,{method:`PUT`,body:{expectedRevision:Q.revision,config:e}}))}})]}),onSubmit:()=>Vt(`auto`)})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(j,{title:`本地会话`}),(0,I.jsxs)(`div`,{className:`assistant-empty`,children:[`尚未登记本地执行目录。`,(0,I.jsx)(`button`,{onClick:()=>N(!0),children:`接入目录`})]})]})]})}export{Z as Computers,Fe as t};
@@ -1 +0,0 @@
1
- import{M as e}from"./Dropdown-DGFI68Vd.js";import{R as t}from"./index-mhJ33-bH.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({ref:e,...t}){return(0,n.jsx)(`div`,{role:`log`,"aria-live":`polite`,...t,ref:e,className:`assistant-transcript`})}export{a,s as i,r as n,o as r,i as t};
@@ -1 +0,0 @@
1
- import{A as e,At as t,D as n,E as r,Ft as i,I as a,It as o,M as s,O as c,Rt as l,S as u,T as d,_ as f,a as p,c as m,d as h,jt as g,l as _,m as v,r as y,s as b,t as x,w as S}from"./Dropdown-DGFI68Vd.js";import{G as C,K as w,U as T}from"./index-mhJ33-bH.js";import{n as E,o as D,r as O,t as k}from"./task-links-BE36-8mc.js";import"./file-links-CoVqmrXg.js";var A=o(((e,t)=>{t.exports=typeof process==`object`&&{}.NODE_DEBUG&&/\bsemver\b/i.test({}.NODE_DEBUG)?(...e)=>console.error(`SEMVER`,...e):()=>{}})),j=o(((e,t)=>{t.exports={MAX_LENGTH:256,MAX_SAFE_COMPONENT_LENGTH:16,MAX_SAFE_BUILD_LENGTH:250,MAX_SAFE_INTEGER:2**53-1||9007199254740991,RELEASE_TYPES:[`major`,`premajor`,`minor`,`preminor`,`patch`,`prepatch`,`prerelease`],SEMVER_SPEC_VERSION:`2.0.0`,FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2}})),M=o(((e,t)=>{var{MAX_SAFE_COMPONENT_LENGTH:n,MAX_SAFE_BUILD_LENGTH:r,MAX_LENGTH:i}=j(),a=A();e=t.exports={};var o=e.re=[],s=e.safeRe=[],c=e.src=[],l=e.safeSrc=[],u=e.t={},d=0,f=`[a-zA-Z0-9-]`,p=[[`\\s`,1],[`\\d`,i],[f,r]],m=e=>{for(let[t,n]of p)e=e.split(`${t}*`).join(`${t}{0,${n}}`).split(`${t}+`).join(`${t}{1,${n}}`);return e},h=(e,t,n)=>{let r=m(t),i=d++;a(e,i,t),u[e]=i,c[i]=t,l[i]=r,o[i]=new RegExp(t,n?`g`:void 0),s[i]=new RegExp(r,n?`g`:void 0)};h(`NUMERICIDENTIFIER`,`0|[1-9]\\d*`),h(`NUMERICIDENTIFIERLOOSE`,`\\d+`),h(`NONNUMERICIDENTIFIER`,`\\d*[a-zA-Z-]${f}*`),h(`MAINVERSION`,`(${c[u.NUMERICIDENTIFIER]})\\.(${c[u.NUMERICIDENTIFIER]})\\.(${c[u.NUMERICIDENTIFIER]})`),h(`MAINVERSIONLOOSE`,`(${c[u.NUMERICIDENTIFIERLOOSE]})\\.(${c[u.NUMERICIDENTIFIERLOOSE]})\\.(${c[u.NUMERICIDENTIFIERLOOSE]})`),h(`PRERELEASEIDENTIFIER`,`(?:${c[u.NONNUMERICIDENTIFIER]}|${c[u.NUMERICIDENTIFIER]})`),h(`PRERELEASEIDENTIFIERLOOSE`,`(?:${c[u.NONNUMERICIDENTIFIER]}|${c[u.NUMERICIDENTIFIERLOOSE]})`),h(`PRERELEASE`,`(?:-(${c[u.PRERELEASEIDENTIFIER]}(?:\\.${c[u.PRERELEASEIDENTIFIER]})*))`),h(`PRERELEASELOOSE`,`(?:-?(${c[u.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${c[u.PRERELEASEIDENTIFIERLOOSE]})*))`),h(`BUILDIDENTIFIER`,`${f}+`),h(`BUILD`,`(?:\\+(${c[u.BUILDIDENTIFIER]}(?:\\.${c[u.BUILDIDENTIFIER]})*))`),h(`FULLPLAIN`,`v?${c[u.MAINVERSION]}${c[u.PRERELEASE]}?${c[u.BUILD]}?`),h(`FULL`,`^${c[u.FULLPLAIN]}$`),h(`LOOSEPLAIN`,`[v=\\s]*${c[u.MAINVERSIONLOOSE]}${c[u.PRERELEASELOOSE]}?${c[u.BUILD]}?`),h(`LOOSE`,`^${c[u.LOOSEPLAIN]}$`),h(`GTLT`,`((?:<|>)?=?)`),h(`XRANGEIDENTIFIERLOOSE`,`${c[u.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`),h(`XRANGEIDENTIFIER`,`${c[u.NUMERICIDENTIFIER]}|x|X|\\*`),h(`XRANGEPLAIN`,`[v=\\s]*(${c[u.XRANGEIDENTIFIER]})(?:\\.(${c[u.XRANGEIDENTIFIER]})(?:\\.(${c[u.XRANGEIDENTIFIER]})(?:${c[u.PRERELEASE]})?${c[u.BUILD]}?)?)?`),h(`XRANGEPLAINLOOSE`,`[v=\\s]*(${c[u.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[u.XRANGEIDENTIFIERLOOSE]})(?:\\.(${c[u.XRANGEIDENTIFIERLOOSE]})(?:${c[u.PRERELEASELOOSE]})?${c[u.BUILD]}?)?)?`),h(`XRANGE`,`^${c[u.GTLT]}\\s*${c[u.XRANGEPLAIN]}$`),h(`XRANGELOOSE`,`^${c[u.GTLT]}\\s*${c[u.XRANGEPLAINLOOSE]}$`),h(`COERCEPLAIN`,`(^|[^\\d])(\\d{1,${n}})(?:\\.(\\d{1,${n}}))?(?:\\.(\\d{1,${n}}))?`),h(`COERCE`,`${c[u.COERCEPLAIN]}(?:$|[^\\d])`),h(`COERCEFULL`,c[u.COERCEPLAIN]+`(?:${c[u.PRERELEASE]})?(?:${c[u.BUILD]})?(?:$|[^\\d])`),h(`COERCERTL`,c[u.COERCE],!0),h(`COERCERTLFULL`,c[u.COERCEFULL],!0),h(`LONETILDE`,`(?:~>?)`),h(`TILDETRIM`,`(\\s*)${c[u.LONETILDE]}\\s+`,!0),e.tildeTrimReplace=`$1~`,h(`TILDE`,`^${c[u.LONETILDE]}${c[u.XRANGEPLAIN]}$`),h(`TILDELOOSE`,`^${c[u.LONETILDE]}${c[u.XRANGEPLAINLOOSE]}$`),h(`LONECARET`,`(?:\\^)`),h(`CARETTRIM`,`(\\s*)${c[u.LONECARET]}\\s+`,!0),e.caretTrimReplace=`$1^`,h(`CARET`,`^${c[u.LONECARET]}${c[u.XRANGEPLAIN]}$`),h(`CARETLOOSE`,`^${c[u.LONECARET]}${c[u.XRANGEPLAINLOOSE]}$`),h(`COMPARATORLOOSE`,`^${c[u.GTLT]}\\s*(${c[u.LOOSEPLAIN]})$|^$`),h(`COMPARATOR`,`^${c[u.GTLT]}\\s*(${c[u.FULLPLAIN]})$|^$`),h(`COMPARATORTRIM`,`(\\s*)${c[u.GTLT]}\\s*(${c[u.LOOSEPLAIN]}|${c[u.XRANGEPLAIN]})`,!0),e.comparatorTrimReplace=`$1$2$3`,h(`HYPHENRANGE`,`^\\s*(${c[u.XRANGEPLAIN]})\\s+-\\s+(${c[u.XRANGEPLAIN]})\\s*$`),h(`HYPHENRANGELOOSE`,`^\\s*(${c[u.XRANGEPLAINLOOSE]})\\s+-\\s+(${c[u.XRANGEPLAINLOOSE]})\\s*$`),h(`STAR`,`(<|>)?=?\\s*\\*`),h(`GTE0`,`^\\s*>=\\s*0\\.0\\.0\\s*$`),h(`GTE0PRE`,`^\\s*>=\\s*0\\.0\\.0-0\\s*$`)})),N=o(((e,t)=>{var n=Object.freeze({loose:!0}),r=Object.freeze({});t.exports=e=>e?typeof e==`object`?e:n:r})),P=o(((e,t)=>{var n=/^[0-9]+$/,r=(e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e===t?0:e<t?-1:1;let r=n.test(e),i=n.test(t);return r&&i&&(e=+e,t=+t),e===t?0:r&&!i?-1:i&&!r?1:e<t?-1:1};t.exports={compareIdentifiers:r,rcompareIdentifiers:(e,t)=>r(t,e)}})),F=o(((e,t)=>{var n=A(),{MAX_LENGTH:r,MAX_SAFE_INTEGER:i}=j(),{safeRe:a,t:o}=M(),s=N(),{compareIdentifiers:c}=P(),l=(e,t)=>{let n=t.split(`.`);if(n.length>e.length)return!1;for(let t=0;t<n.length;t++)if(c(e[t],n[t])!==0)return!1;return!0};t.exports=class e{constructor(t,c){if(c=s(c),t instanceof e){if(t.loose===!!c.loose&&t.includePrerelease===!!c.includePrerelease)return t;t=t.version}else if(typeof t!=`string`)throw TypeError(`Invalid version. Must be a string. Got type "${typeof t}".`);if(t.length>r)throw TypeError(`version is longer than ${r} characters`);n(`SemVer`,t,c),this.options=c,this.loose=!!c.loose,this.includePrerelease=!!c.includePrerelease;let l=t.trim().match(c.loose?a[o.LOOSE]:a[o.FULL]);if(!l)throw TypeError(`Invalid Version: ${t}`);if(this.raw=t,this.major=+l[1],this.minor=+l[2],this.patch=+l[3],this.major>i||this.major<0)throw TypeError(`Invalid major version`);if(this.minor>i||this.minor<0)throw TypeError(`Invalid minor version`);if(this.patch>i||this.patch<0)throw TypeError(`Invalid patch version`);this.prerelease=l[4]?l[4].split(`.`).map(e=>{if(/^[0-9]+$/.test(e)){let t=+e;if(t>=0&&t<i)return t}return e}):[],this.build=l[5]?l[5].split(`.`):[],this.format()}format(){return this.version=`${this.major}.${this.minor}.${this.patch}`,this.prerelease.length&&(this.version+=`-${this.prerelease.join(`.`)}`),this.version}toString(){return this.version}compare(t){if(n(`SemVer.compare`,this.version,this.options,t),!(t instanceof e)){if(typeof t==`string`&&t===this.version)return 0;t=new e(t,this.options)}return t.version===this.version?0:this.compareMain(t)||this.comparePre(t)}compareMain(t){return t instanceof e||(t=new e(t,this.options)),this.major<t.major?-1:this.major>t.major?1:this.minor<t.minor?-1:this.minor>t.minor?1:this.patch<t.patch?-1:+(this.patch>t.patch)}comparePre(t){if(t instanceof e||(t=new e(t,this.options)),this.prerelease.length&&!t.prerelease.length)return-1;if(!this.prerelease.length&&t.prerelease.length)return 1;if(!this.prerelease.length&&!t.prerelease.length)return 0;let r=0;do{let e=this.prerelease[r],i=t.prerelease[r];if(n(`prerelease compare`,r,e,i),e===void 0&&i===void 0)return 0;if(i===void 0)return 1;if(e===void 0)return-1;if(e!==i)return c(e,i)}while(++r)}compareBuild(t){t instanceof e||(t=new e(t,this.options));let r=0;do{let e=this.build[r],i=t.build[r];if(n(`build compare`,r,e,i),e===void 0&&i===void 0)return 0;if(i===void 0)return 1;if(e===void 0)return-1;if(e!==i)return c(e,i)}while(++r)}inc(e,t,n){if(e.startsWith(`pre`)){if(!t&&n===!1)throw Error(`invalid increment argument: identifier is empty`);if(t){let e=`-${t}`.match(this.options.loose?a[o.PRERELEASELOOSE]:a[o.PRERELEASE]);if(!e||e[1]!==t)throw Error(`invalid identifier: ${t}`)}}switch(e){case`premajor`:this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc(`pre`,t,n);break;case`preminor`:this.prerelease.length=0,this.patch=0,this.minor++,this.inc(`pre`,t,n);break;case`prepatch`:this.prerelease.length=0,this.inc(`patch`,t,n),this.inc(`pre`,t,n);break;case`prerelease`:this.prerelease.length===0&&this.inc(`patch`,t,n),this.inc(`pre`,t,n);break;case`release`:if(this.prerelease.length===0)throw Error(`version ${this.raw} is not a prerelease`);this.prerelease.length=0;break;case`major`:(this.minor!==0||this.patch!==0||this.prerelease.length===0)&&this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case`minor`:(this.patch!==0||this.prerelease.length===0)&&this.minor++,this.patch=0,this.prerelease=[];break;case`patch`:this.prerelease.length===0&&this.patch++,this.prerelease=[];break;case`pre`:{let e=+!!Number(n);if(this.prerelease.length===0)this.prerelease=[e];else{let r=this.prerelease.length;for(;--r>=0;)typeof this.prerelease[r]==`number`&&(this.prerelease[r]++,r=-2);if(r===-1){if(t===this.prerelease.join(`.`)&&n===!1)throw Error(`invalid increment argument: identifier already exists`);this.prerelease.push(e)}}if(t){let r=[t,e];if(n===!1&&(r=[t]),l(this.prerelease,t)){let e=this.prerelease[t.split(`.`).length];isNaN(e)&&(this.prerelease=r)}else this.prerelease=r}break}default:throw Error(`invalid increment argument: ${e}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(`.`)}`),this}}})),I=o(((e,t)=>{var n=F();t.exports=(e,t,r=!1)=>{if(e instanceof n)return e;try{return new n(e,t)}catch(e){if(!r)return null;throw e}}})),L=t(),R=l(I(),1),z=s();function B({className:e=``,...t}){return(0,z.jsx)(`button`,{type:`button`,...t,className:`pill-control ${e}`})}function V({className:e=``,...t}){return(0,z.jsx)(x,{...t,className:`pill-menu ${e}`})}var H=[{value:`time`,label:`按时间`,icon:`clock`},{value:`owner`,label:`按用户`,icon:`members`}];function U(e){e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),history.pushState(null,``,e.currentTarget.href),window.dispatchEvent(new PopStateEvent(`popstate`)))}var W=[{status:`planned`,label:`计划`},{status:`in_progress`,label:`进行中`},{status:`in_review`,label:`待验收`},{status:`completed`,label:`已完成`},{status:null,label:`未明确`}];function G({members:t,project:n,memberId:r}){let{request:i,projectId:a}=T(),o=`teammy-board-mine:${r}:${a}`,[s,l]=(0,L.useState)(()=>{try{return localStorage.getItem(o)===`true`}catch{return!1}}),d=`teammy-board-order:${r}:${a}`,[f,h]=(0,L.useState)(()=>{try{return localStorage.getItem(d)===`owner`?`owner`:`time`}catch{return`time`}}),_=H.find(e=>e.value===f),b=(0,L.useCallback)(e=>i(`tasks`,C,{signal:e}),[i]),x=c(b,3e3,e(a,`tasks`)),[S,w]=(0,L.useState)(),[E,D]=(0,L.useState)(!1),[O,A]=(0,L.useState)(Date.now);(0,L.useEffect)(()=>{let e=setInterval(()=>A(Date.now()),6e4);return()=>clearInterval(e)},[]);let j=x.data,M=k(location.href),N=j?.tasks.filter(e=>!s||e.owner===r)??[],P=new Set(t.map(e=>e.id));return(0,z.jsxs)(`div`,{className:`task-board`,children:[(0,z.jsx)(v,{title:n?.projectName.trim()?`${n.projectName.trim()}|工作看板`:`工作看板`,description:n?.description.trim()||``,children:(0,z.jsxs)(`div`,{className:`task-board-brand`,children:[(0,z.jsx)(`a`,{className:`task-board-home`,"data-testid":`home-link`,href:g(`/projects`),onClick:U,"aria-label":`项目主页`,"data-tooltip":`项目主页`,children:(0,z.jsx)(y,{})}),t.some(e=>e.id===r&&e.bound)&&(0,z.jsx)(K,{memberId:r})]})}),(0,z.jsxs)(`div`,{className:`task-board-toolbar`,role:`group`,"aria-label":`看板筛选与排序`,children:[(0,z.jsxs)(B,{"aria-pressed":s,"data-testid":`task-board-mine`,onClick:()=>{let e=!s;l(e),D(!1);try{localStorage.setItem(o,String(e))}catch{}},children:[(0,z.jsx)(m,{name:s?`enable`:`account`,size:`small`}),`只看我的`]}),(0,z.jsx)(V,{id:`task-board-sort-menu`,triggerId:`task-board-sort`,label:`任务排序:${_.label}`,routeKey:f,trigger:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(m,{name:_.icon,size:`small`}),(0,z.jsx)(`span`,{children:_.label}),(0,z.jsx)(m,{name:`chevronDown`,size:`small`})]}),children:e=>H.map(t=>(0,z.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-label":t.label,onClick:()=>{e(),h(t.value),D(!1);try{localStorage.setItem(d,t.value)}catch{}},children:[(0,z.jsx)(m,{name:t.icon,size:`small`}),(0,z.jsx)(`span`,{children:t.label}),f===t.value&&(0,z.jsx)(m,{name:`check`,size:`small`})]},t.value))})]}),(0,z.jsx)(u,{resource:x}),(0,z.jsx)(`section`,{className:`task-board-lanes`,"aria-label":`任务进度`,"data-testid":`progress-board`,children:W.filter(e=>e.status!==null||N.some(e=>e.status===null)).map(e=>{let t=N.filter(t=>t.status===e.status);t.sort((t,n)=>(f===`owner`?t.owner.localeCompare(n.owner,`en`,{numeric:!0}):0)||(e.status===`completed`?n.statusSince.localeCompare(t.statusSince):t.statusSince.localeCompare(n.statusSince))||t.id.localeCompare(n.id));let n=e.status===`completed`&&!E?t.slice(0,5):t;return(0,z.jsxs)(`section`,{className:`task-lane`,"aria-label":e.label,"data-stage":e.status??`unknown`,children:[(0,z.jsxs)(`h2`,{children:[(0,z.jsx)(`span`,{className:`lane-dot`}),e.label,(0,z.jsx)(p,{children:j?t.length:`—`})]}),(0,z.jsxs)(`div`,{className:`task-lane-content`,children:[t.length?n.map(e=>(0,z.jsx)(q,{task:e,number:j?.taskNumbers[e.id],memberIds:P,now:O,onEdit:()=>w(e),onSaved:()=>void x.reload()},e.id)):(0,z.jsx)(`p`,{className:`task-lane-empty`,children:x.error&&!j?`读取失败`:j?`暂无任务`:`读取中…`}),e.status===`completed`&&t.length>5&&(0,z.jsxs)(`button`,{type:`button`,className:`task-lane-expand`,"aria-expanded":E,onClick:()=>D(!E),children:[(0,z.jsx)(m,{name:E?`chevronUp`:`chevronDown`,size:`small`}),E?`收起`:`展开其余 ${t.length-5} 项`]})]})]},e.label)})}),M&&(0,z.jsx)(Y,{project:a,id:M.id,memberIds:P,onClose:()=>{let e=new URL(location.href);e.searchParams.delete(`task`),history.replaceState(history.state,``,e),window.dispatchEvent(new PopStateEvent(`popstate`))}}),S&&(0,z.jsx)(Q,{task:S,onClose:()=>w(void 0),onSaved:()=>{w(void 0),x.reload()}},S.id)]})}function K({memberId:e}){let{api:t,projectId:n}=T(),a=c(t.devices,!0),o=r();if(!a.data||!o.data||a.error||o.error)return null;let s=(0,R.default)(o.data.version),[l]=a.data.devices.filter(t=>t.memberId===e&&t.bound).map(e=>(0,R.default)(e.status?.clientVersion)).filter(e=>e!==null).sort((e,t)=>e.compare(t));if(!l||!s||l.compare(s)>=0)return null;let u=o.data.versions.filter(e=>{let t=(0,R.default)(e);return t&&(!t.prerelease.length||e===s.raw)&&t.compare(l)>0&&t.compare(s)<=0}).length;return(0,z.jsx)(`p`,{className:`task-board-update${u>5?` overdue`:``}`,children:(0,z.jsxs)(`a`,{href:i(n,`settings/client-maintenance.md`,`#升级与修复`),onClick:U,children:[(0,z.jsx)(m,{name:`attention`,size:`small`}),(0,z.jsxs)(`span`,{children:[`客户端待更新 `,l.raw,` → `,s.raw]})]})})}function q({task:e,number:t,memberIds:r,onEdit:i,onSaved:o,now:s}){let{request:c}=T(),l=n(),[u,d]=(0,L.useState)(!1),f=S();async function p(){if(!u){d(!0),f(``);try{await c(`tasks/${e.id}/correction`,w,{method:`PATCH`,signal:l,body:{needsConfirmation:!1,expectedRevision:e.revision}}),l.aborted||o()}catch(e){l.aborted||f(a(e))}finally{d(!1)}}}return(0,z.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,z.jsxs)(`summary`,{className:`task-card-heading`,"data-testid":`task-toggle`,children:[(0,z.jsxs)(`h3`,{children:[t!==void 0&&(0,z.jsxs)(`span`,{className:`task-card-number`,children:[`#`,t]}),(0,z.jsx)(`span`,{className:`task-card-title`,children:e.title})]}),(0,z.jsxs)(`span`,{className:`task-card-meta`,children:[(0,z.jsx)(`small`,{title:e.owner,children:e.owner}),e.needsConfirmation&&(0,z.jsxs)(`span`,{className:`task-confirmation`,"data-testid":`task-confirmation`,children:[(0,z.jsx)(m,{name:`attention`,size:`small`}),`需要确认`]}),e.status!==`completed`&&(0,z.jsx)(X,{since:e.statusSince,now:s})]})]}),(0,z.jsx)(_,{icon:`edit`,className:`task-card-edit`,label:`纠正任务:${e.title}`,"data-testid":`task-correct`,disabled:u,onClick:i}),(0,z.jsxs)(`div`,{className:`task-card-details`,children:[(0,z.jsx)(J,{task:e,memberIds:r}),e.needsConfirmation&&(0,z.jsx)(`div`,{className:`task-card-confirm`,children:(0,z.jsx)(`button`,{className:`primary`,"data-testid":`task-confirm-save`,disabled:u,onClick:()=>void p(),children:u?`正在保存…`:`保存`})})]})]})}function J({task:e,memberIds:t}){let{projectId:n}=T(),[r,i]=(0,L.useState)(``),a=S();return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`h4`,{children:`目标`}),(0,z.jsx)(`p`,{children:e.goal?(0,z.jsx)(Z,{value:e.goal,memberIds:t}):`目标未明确`}),(0,z.jsx)(`h4`,{children:`当前进展`}),(0,z.jsx)(`p`,{className:`task-progress`,children:(0,z.jsx)(Z,{value:e.progress,memberIds:t})}),(0,z.jsx)(`div`,{className:`task-card-sources`,children:e.sources.map(t=>(0,z.jsxs)(`a`,{"data-testid":`task-source`,href:g(t.kind===`material`?`/projects/${n}/materials?id=${t.materialId}&revision=${t.revision}`:O(n,e.owner,t.path)),children:[(0,z.jsx)(m,{name:`file`,size:`small`}),(0,z.jsx)(`span`,{children:t.path})]},t.path))}),(0,z.jsxs)(`div`,{className:`task-card-footer`,children:[e.syncedAt&&(0,z.jsxs)(`small`,{children:[`资料同步于 `,(0,z.jsx)(f,{value:e.syncedAt})]}),(0,z.jsx)(`span`,{role:`status`,children:r}),(0,z.jsx)(_,{icon:`link`,label:`复制任务链接`,onBlur:()=>i(``),onClick:async()=>{a(``);try{await d(new URL(g(D(n,e.id)),location.origin).href),i(`已复制`)}catch{i(``),a(`未能复制任务链接,请重试。`)}}})]})]})}function Y({project:e,id:t,memberIds:n,onClose:r}){let i=E(e,t,!0),{data:a,error:o}=i;return(0,z.jsxs)(h,{id:`shared-task`,title:a?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`span`,{className:`task-card-number`,children:[`#`,a.number]}),` `,a.task.title]}):`任务`,onClose:r,children:[(0,z.jsx)(u,{resource:i}),a?(0,z.jsxs)(`div`,{className:`task-card-details`,children:[(0,z.jsxs)(`small`,{children:[a.task.owner,` · `,W.find(e=>e.status===a.task.status)?.label,!a.active&&` · 已归档`]}),(0,z.jsx)(J,{task:a.task,memberIds:n},t)]}):!o&&(0,z.jsx)(`p`,{role:`status`,children:`读取中…`})]})}function X({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,z.jsxs)(`span`,{className:`task-age${n>6048e5?` stale`:``}`,"data-testid":`task-age`,title:`进入当前状态:${new Date(e).toLocaleString(`zh-CN`)}`,"aria-label":`当前状态停留 ${i}`,children:[(0,z.jsx)(m,{name:`clock`,size:`small`}),i]})}function Z({value:e,memberIds:t}){return e.split(/(@[a-z][a-z0-9_-]*)/gi).map((e,n)=>e.startsWith(`@`)&&t.has(e.slice(1))?(0,z.jsx)(`mark`,{className:`task-mention`,children:e},n):e)}function Q({task:e,onClose:t,onSaved:r}){let{request:i}=T(),o=n(),[s,c]=(0,L.useState)(e.title),[l,u]=(0,L.useState)(e.status??``),[d,f]=(0,L.useState)(e.goal??``),[p,m]=(0,L.useState)(e.progress),[g,_]=(0,L.useState)(!1),v=S(),y={...s===e.title?{}:{title:s},...l===(e.status??``)?{}:{status:l||null},...d===(e.goal??``)?{}:{goal:d||null},...p===e.progress?{}:{progress:p},...e.needsConfirmation?{needsConfirmation:!1}:{}};async function x(){if(!g&&Object.keys(y).length){_(!0),v(``);try{await i(`tasks/${e.id}/correction`,w,{method:`PATCH`,signal:o,body:{...y,expectedRevision:e.revision}}),o.aborted||r()}catch(e){o.aborted||v(a(e))}finally{_(!1)}}}return(0,z.jsx)(h,{id:`task-correction`,title:`纠正任务`,onClose:t,children:(0,z.jsxs)(`form`,{className:`stack`,"aria-busy":g,onSubmit:e=>{e.preventDefault(),x()},children:[(0,z.jsx)(b,{id:`task-title`,label:`标题`,children:(0,z.jsx)(`input`,{value:s,required:!0,onChange:e=>c(e.target.value)})}),(0,z.jsxs)(`fieldset`,{className:`task-status-field`,disabled:g,children:[(0,z.jsx)(`legend`,{children:`状态`}),(0,z.jsx)(`div`,{className:`task-status-options`,"data-testid":`task-status`,children:W.filter(e=>e.status!==null).map(e=>(0,z.jsxs)(`label`,{className:`task-status-choice`,children:[(0,z.jsx)(`input`,{type:`radio`,name:`task-status`,value:e.status,checked:l===e.status,onChange:()=>u(e.status)}),(0,z.jsx)(`span`,{children:e.label})]},e.status))}),(0,z.jsx)(`small`,{children:`待验收:任务成果已提交,等待验收或最终确认。`})]}),(0,z.jsx)(b,{id:`task-goal`,label:`目标`,children:(0,z.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value)})}),(0,z.jsx)(b,{id:`task-progress`,label:`当前进展`,children:(0,z.jsx)(`textarea`,{value:p,onChange:e=>m(e.target.value)})}),(0,z.jsx)(`div`,{className:`row wrap`,children:(0,z.jsx)(`button`,{type:`submit`,className:`primary`,disabled:g||!Object.keys(y).length,"data-testid":`task-correction-save`,children:`保存`})})]})})}function $({members:e,config:t,memberId:n}){return(0,z.jsx)(G,{members:e,project:t,memberId:n})}export{$ as Dashboard};