cli-claw-kit 0.0.1

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 (295) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +245 -0
  3. package/config/default-groups.json +1 -0
  4. package/config/global-agents-md.template.md +37 -0
  5. package/config/mount-allowlist.json +11 -0
  6. package/container/Dockerfile +160 -0
  7. package/container/agent-runner/dist/.tsbuildinfo +1 -0
  8. package/container/agent-runner/dist/agent-definitions.js +22 -0
  9. package/container/agent-runner/dist/channel-prefixes.js +16 -0
  10. package/container/agent-runner/dist/codex-config.js +29 -0
  11. package/container/agent-runner/dist/image-detector.js +96 -0
  12. package/container/agent-runner/dist/index.js +2587 -0
  13. package/container/agent-runner/dist/mcp-tools.js +1076 -0
  14. package/container/agent-runner/dist/stream-event.types.js +5 -0
  15. package/container/agent-runner/dist/stream-processor.js +867 -0
  16. package/container/agent-runner/dist/types.js +6 -0
  17. package/container/agent-runner/dist/utils.js +115 -0
  18. package/container/agent-runner/package.json +36 -0
  19. package/container/agent-runner/prompts/security-rules.md +31 -0
  20. package/container/agent-runner/src/agent-definitions.ts +27 -0
  21. package/container/agent-runner/src/channel-prefixes.ts +16 -0
  22. package/container/agent-runner/src/codex-config.ts +40 -0
  23. package/container/agent-runner/src/image-detector.ts +116 -0
  24. package/container/agent-runner/src/index.ts +3107 -0
  25. package/container/agent-runner/src/mcp-tools.ts +1295 -0
  26. package/container/agent-runner/src/stream-event.types.ts +10 -0
  27. package/container/agent-runner/src/stream-processor.ts +932 -0
  28. package/container/agent-runner/src/types.ts +75 -0
  29. package/container/agent-runner/src/utils.ts +114 -0
  30. package/container/agent-runner/tsconfig.json +17 -0
  31. package/container/build.sh +28 -0
  32. package/container/entrypoint.sh +64 -0
  33. package/container/skills/agent-browser/SKILL.md +159 -0
  34. package/container/skills/install-skill/SKILL.md +64 -0
  35. package/container/skills/post-test-cleanup/SKILL.md +121 -0
  36. package/dist/.tsbuildinfo +1 -0
  37. package/dist/agent-output-parser.js +459 -0
  38. package/dist/app-root.js +52 -0
  39. package/dist/assistant-meta-footer.js +1 -0
  40. package/dist/auth.js +91 -0
  41. package/dist/billing.js +694 -0
  42. package/dist/channel-prefixes.js +16 -0
  43. package/dist/cli.js +86 -0
  44. package/dist/commands.js +79 -0
  45. package/dist/config.js +120 -0
  46. package/dist/container-runner.js +981 -0
  47. package/dist/daily-summary.js +210 -0
  48. package/dist/db.js +3683 -0
  49. package/dist/dingtalk.js +1347 -0
  50. package/dist/feishu-markdown-style.js +97 -0
  51. package/dist/feishu-streaming-card.js +1875 -0
  52. package/dist/feishu.js +1628 -0
  53. package/dist/file-manager.js +270 -0
  54. package/dist/group-queue.js +1070 -0
  55. package/dist/group-runtime.js +35 -0
  56. package/dist/host-workspace-cwd.js +85 -0
  57. package/dist/im-channel.js +384 -0
  58. package/dist/im-command-utils.js +142 -0
  59. package/dist/im-downloader.js +45 -0
  60. package/dist/im-manager.js +527 -0
  61. package/dist/im-utils.js +53 -0
  62. package/dist/image-detector.js +96 -0
  63. package/dist/index.js +5828 -0
  64. package/dist/logger.js +22 -0
  65. package/dist/mcp-utils.js +66 -0
  66. package/dist/message-attachments.js +69 -0
  67. package/dist/message-notifier.js +36 -0
  68. package/dist/middleware/auth.js +85 -0
  69. package/dist/mount-security.js +315 -0
  70. package/dist/permissions.js +67 -0
  71. package/dist/project-memory.js +6 -0
  72. package/dist/provider-pool.js +189 -0
  73. package/dist/qq.js +826 -0
  74. package/dist/reset-admin.js +42 -0
  75. package/dist/routes/admin.js +543 -0
  76. package/dist/routes/agent-definitions.js +241 -0
  77. package/dist/routes/agents.js +533 -0
  78. package/dist/routes/auth.js +675 -0
  79. package/dist/routes/billing.js +490 -0
  80. package/dist/routes/browse.js +210 -0
  81. package/dist/routes/bug-report.js +387 -0
  82. package/dist/routes/config.js +1868 -0
  83. package/dist/routes/files.js +671 -0
  84. package/dist/routes/groups.js +1367 -0
  85. package/dist/routes/mcp-servers.js +320 -0
  86. package/dist/routes/memory.js +523 -0
  87. package/dist/routes/monitor.js +307 -0
  88. package/dist/routes/skills.js +777 -0
  89. package/dist/routes/tasks.js +509 -0
  90. package/dist/routes/usage.js +64 -0
  91. package/dist/routes/workspace-config.js +458 -0
  92. package/dist/runtime-build.js +112 -0
  93. package/dist/runtime-command-handler.js +189 -0
  94. package/dist/runtime-command-registry.js +1 -0
  95. package/dist/runtime-config.js +1777 -0
  96. package/dist/runtime-identity.js +52 -0
  97. package/dist/schemas.js +590 -0
  98. package/dist/script-runner.js +64 -0
  99. package/dist/sdk-query.js +82 -0
  100. package/dist/skill-utils.js +145 -0
  101. package/dist/sqlite-compat.js +19 -0
  102. package/dist/stream-event.types.js +5 -0
  103. package/dist/streaming-runtime-meta.js +29 -0
  104. package/dist/task-scheduler.js +695 -0
  105. package/dist/task-utils.js +13 -0
  106. package/dist/telegram-pairing.js +59 -0
  107. package/dist/telegram.js +897 -0
  108. package/dist/terminal-manager.js +307 -0
  109. package/dist/tool-step-display.js +1 -0
  110. package/dist/types.js +1 -0
  111. package/dist/utils.js +85 -0
  112. package/dist/web-context.js +161 -0
  113. package/dist/web.js +1377 -0
  114. package/dist/wechat-crypto.js +182 -0
  115. package/dist/wechat.js +589 -0
  116. package/dist/workspace-runtime-reset.js +35 -0
  117. package/package.json +107 -0
  118. package/shared/assistant-meta-footer.ts +127 -0
  119. package/shared/channel-prefixes.ts +16 -0
  120. package/shared/dist/assistant-meta-footer.d.ts +29 -0
  121. package/shared/dist/assistant-meta-footer.js +85 -0
  122. package/shared/dist/channel-prefixes.d.ts +4 -0
  123. package/shared/dist/channel-prefixes.js +16 -0
  124. package/shared/dist/image-detector.d.ts +20 -0
  125. package/shared/dist/image-detector.js +96 -0
  126. package/shared/dist/runtime-command-registry.d.ts +38 -0
  127. package/shared/dist/runtime-command-registry.js +185 -0
  128. package/shared/dist/stream-event.d.ts +65 -0
  129. package/shared/dist/stream-event.js +8 -0
  130. package/shared/dist/tool-step-display.d.ts +4 -0
  131. package/shared/dist/tool-step-display.js +11 -0
  132. package/shared/image-detector.ts +116 -0
  133. package/shared/runtime-command-registry.ts +252 -0
  134. package/shared/stream-event.ts +67 -0
  135. package/shared/tool-step-display.ts +21 -0
  136. package/shared/tsconfig.json +24 -0
  137. package/web/dist/assets/BillingPage-B1wBR_o-.js +52 -0
  138. package/web/dist/assets/ChatPage-6GBZ9nXN.css +32 -0
  139. package/web/dist/assets/ChatPage-BOJcXtaj.js +161 -0
  140. package/web/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  141. package/web/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  142. package/web/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  143. package/web/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  144. package/web/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  145. package/web/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  146. package/web/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  147. package/web/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  148. package/web/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  149. package/web/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  150. package/web/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  151. package/web/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  152. package/web/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  153. package/web/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  154. package/web/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  155. package/web/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  156. package/web/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  157. package/web/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  158. package/web/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  159. package/web/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  160. package/web/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  161. package/web/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  162. package/web/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  163. package/web/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  164. package/web/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  165. package/web/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  166. package/web/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  167. package/web/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  168. package/web/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  169. package/web/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  170. package/web/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  171. package/web/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  172. package/web/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  173. package/web/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  174. package/web/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  175. package/web/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  176. package/web/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  177. package/web/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  178. package/web/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  179. package/web/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  180. package/web/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  181. package/web/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  182. package/web/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  183. package/web/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  184. package/web/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  185. package/web/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  186. package/web/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  187. package/web/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  188. package/web/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  189. package/web/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  190. package/web/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  191. package/web/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  192. package/web/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  193. package/web/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  194. package/web/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  195. package/web/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  196. package/web/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  197. package/web/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  198. package/web/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  199. package/web/dist/assets/SettingsPage-DoY7FoZ_.js +153 -0
  200. package/web/dist/assets/ShareImageDialog-C1ga8b7l.js +22 -0
  201. package/web/dist/assets/TasksPage-CRivnNsx.js +14 -0
  202. package/web/dist/assets/_basePickBy-Bf-bSoS9.js +1 -0
  203. package/web/dist/assets/_baseUniq-zAOaCuKw.js +1 -0
  204. package/web/dist/assets/arc-Dm9mVQ9U.js +1 -0
  205. package/web/dist/assets/architectureDiagram-2XIMDMQ5-BLmzX1wr.js +36 -0
  206. package/web/dist/assets/band-CquvqAHh.js +1 -0
  207. package/web/dist/assets/blockDiagram-WCTKOSBZ-B9pcqm3j.js +132 -0
  208. package/web/dist/assets/c4Diagram-IC4MRINW-Cytx1q3b.js +10 -0
  209. package/web/dist/assets/channel-BOVj73LR.js +1 -0
  210. package/web/dist/assets/channel-meta-CQD0Pei-.js +41 -0
  211. package/web/dist/assets/chunk-4BX2VUAB-0ToDr6RE.js +1 -0
  212. package/web/dist/assets/chunk-55IACEB6-DQDjnXfS.js +1 -0
  213. package/web/dist/assets/chunk-FMBD7UC4-Di8ABm6c.js +15 -0
  214. package/web/dist/assets/chunk-JSJVCQXG-BZQN6rnX.js +1 -0
  215. package/web/dist/assets/chunk-KX2RTZJC-zBbcpaN_.js +1 -0
  216. package/web/dist/assets/chunk-NQ4KR5QH-BCrLoU88.js +220 -0
  217. package/web/dist/assets/chunk-QZHKN3VN-Bqk8juan.js +1 -0
  218. package/web/dist/assets/chunk-WL4C6EOR-D2YX-MHY.js +189 -0
  219. package/web/dist/assets/classDiagram-VBA2DB6C-DUUoMyaK.js +1 -0
  220. package/web/dist/assets/classDiagram-v2-RAHNMMFH-DUUoMyaK.js +1 -0
  221. package/web/dist/assets/clone-BmaCesfa.js +1 -0
  222. package/web/dist/assets/cose-bilkent-S5V4N54A-CTsv6qQA.js +1 -0
  223. package/web/dist/assets/cytoscape.esm-BQaXIfA_.js +331 -0
  224. package/web/dist/assets/dagre-KLK3FWXG-Ci4Jh9nu.js +4 -0
  225. package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
  226. package/web/dist/assets/diagram-E7M64L7V-BFRnfTI2.js +24 -0
  227. package/web/dist/assets/diagram-IFDJBPK2-B7Zhnp0b.js +43 -0
  228. package/web/dist/assets/diagram-P4PSJMXO-BVyP7nwq.js +24 -0
  229. package/web/dist/assets/erDiagram-INFDFZHY-NorKdTOF.js +70 -0
  230. package/web/dist/assets/error-CGD5mp5f.js +1 -0
  231. package/web/dist/assets/flowDiagram-PKNHOUZH-Ch97nABF.js +162 -0
  232. package/web/dist/assets/ganttDiagram-A5KZAMGK-BQ2pLWsy.js +292 -0
  233. package/web/dist/assets/gitGraphDiagram-K3NZZRJ6-bcvnBsD2.js +65 -0
  234. package/web/dist/assets/graph-CeAEckur.js +1 -0
  235. package/web/dist/assets/index-CPnL1_qC.js +768 -0
  236. package/web/dist/assets/index-DVevCbcO.css +10 -0
  237. package/web/dist/assets/infoDiagram-LFFYTUFH-CcsrFdj-.js +2 -0
  238. package/web/dist/assets/init-Dmth1JHB.js +1 -0
  239. package/web/dist/assets/ishikawaDiagram-PHBUUO56-1upyMfHN.js +70 -0
  240. package/web/dist/assets/journeyDiagram-4ABVD52K-CKUi-V0c.js +139 -0
  241. package/web/dist/assets/kanban-definition-K7BYSVSG-DOnQwXfL.js +89 -0
  242. package/web/dist/assets/layout-BmMMqTnJ.js +1 -0
  243. package/web/dist/assets/linear-DiaJloY5.js +1 -0
  244. package/web/dist/assets/mermaid.core-BWLV1B2v.js +254 -0
  245. package/web/dist/assets/mindmap-definition-YRQLILUH-BeAKHVWP.js +68 -0
  246. package/web/dist/assets/ordinal-DILIJJjt.js +1 -0
  247. package/web/dist/assets/pieDiagram-SKSYHLDU-DfiMSfWo.js +30 -0
  248. package/web/dist/assets/quadrantDiagram-337W2JSQ-wZxZOJxd.js +7 -0
  249. package/web/dist/assets/requirementDiagram-Z7DCOOCP-BK4HHm17.js +73 -0
  250. package/web/dist/assets/sankeyDiagram-WA2Y5GQK-BX6t2avX.js +10 -0
  251. package/web/dist/assets/sequenceDiagram-2WXFIKYE-BPQlkbAa.js +145 -0
  252. package/web/dist/assets/sheet-rI0FfB1g.js +6 -0
  253. package/web/dist/assets/sliders-horizontal-CuijWFNK.js +6 -0
  254. package/web/dist/assets/sparkles-BsMYXJoT.js +11 -0
  255. package/web/dist/assets/square-0CqMX1Q3.js +11 -0
  256. package/web/dist/assets/stateDiagram-RAJIS63D-DxkV0Vwd.js +1 -0
  257. package/web/dist/assets/stateDiagram-v2-FVOUBMTO-qLYoiOPe.js +1 -0
  258. package/web/dist/assets/step-D51IIHGA.js +1 -0
  259. package/web/dist/assets/tasks-D8JjBTwx.js +1 -0
  260. package/web/dist/assets/time-O8zIGux3.js +1 -0
  261. package/web/dist/assets/timeline-definition-YZTLITO2-kNp1DyFc.js +61 -0
  262. package/web/dist/assets/treemap-KZPCXAKY-CkrClVhk.js +162 -0
  263. package/web/dist/assets/utils-KGAn0XTg.js +11 -0
  264. package/web/dist/assets/vennDiagram-LZ73GAT5-CgdzEZz4.js +34 -0
  265. package/web/dist/assets/xychartDiagram-JWTSCODW-DfYGPfNB.js +7 -0
  266. package/web/dist/assets/zap-_hKJYy7J.js +6 -0
  267. package/web/dist/favicon.svg +332 -0
  268. package/web/dist/fonts/AlibabaPuHuiTi-3-55-Regular.woff2 +0 -0
  269. package/web/dist/fonts/AlibabaPuHuiTi-3-65-Medium.woff2 +0 -0
  270. package/web/dist/fonts/AlibabaPuHuiTi-3-75-SemiBold.woff2 +0 -0
  271. package/web/dist/fonts/DMSans-latin-ext.woff2 +0 -0
  272. package/web/dist/fonts/DMSans-latin.woff2 +0 -0
  273. package/web/dist/icons/README.md +20 -0
  274. package/web/dist/icons/apple-touch-icon-180.png +0 -0
  275. package/web/dist/icons/icon-128.png +0 -0
  276. package/web/dist/icons/icon-144.png +0 -0
  277. package/web/dist/icons/icon-152.png +0 -0
  278. package/web/dist/icons/icon-192.png +0 -0
  279. package/web/dist/icons/icon-192.svg +332 -0
  280. package/web/dist/icons/icon-384.png +0 -0
  281. package/web/dist/icons/icon-48.png +0 -0
  282. package/web/dist/icons/icon-512-maskable.png +0 -0
  283. package/web/dist/icons/icon-512.png +0 -0
  284. package/web/dist/icons/icon-512.svg +332 -0
  285. package/web/dist/icons/icon-72.png +0 -0
  286. package/web/dist/icons/icon-96.png +0 -0
  287. package/web/dist/icons/loading-logo.svg +332 -0
  288. package/web/dist/icons/logo-1024.png +0 -0
  289. package/web/dist/icons/logo-icon.svg +332 -0
  290. package/web/dist/icons/logo-text.svg +332 -0
  291. package/web/dist/index.html +30 -0
  292. package/web/dist/manifest.webmanifest +1 -0
  293. package/web/dist/registerSW.js +1 -0
  294. package/web/dist/sw.js +1 -0
  295. package/web/dist/workbox-08d6266a.js +1 -0
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Canonical StreamEvent type definitions.
3
+ *
4
+ * This is the single source of truth.
5
+ * Build step compiles this file to shared/dist/stream-event.{js,d.ts},
6
+ * and each runtime consumes those types through thin local wrappers.
7
+ */
8
+
9
+ export type StreamEventType =
10
+ | 'text_delta' | 'thinking_delta'
11
+ | 'tool_use_start' | 'tool_use_end' | 'tool_progress'
12
+ | 'hook_started' | 'hook_progress' | 'hook_response'
13
+ | 'task_start' | 'task_notification'
14
+ | 'todo_update'
15
+ | 'usage'
16
+ | 'status' | 'init';
17
+
18
+ export interface StreamRuntimeIdentity {
19
+ agentType: 'claude' | 'codex';
20
+ model?: string | null;
21
+ reasoningEffort?: string | null;
22
+ supportsReasoningEffort?: boolean | null;
23
+ }
24
+
25
+ export interface StreamEvent {
26
+ eventType: StreamEventType;
27
+ /** Correlates all stream events for a single user turn. */
28
+ turnId?: string;
29
+ /** SDK session identifier if known. */
30
+ sessionId?: string;
31
+ /** SDK message uuid if known. */
32
+ messageUuid?: string;
33
+ /** Reserved — whether this event was synthesized locally rather than emitted directly by SDK semantics. */
34
+ isSynthetic?: boolean;
35
+ text?: string;
36
+ toolName?: string;
37
+ toolUseId?: string;
38
+ parentToolUseId?: string | null;
39
+ isNested?: boolean;
40
+ skillName?: string;
41
+ toolInputSummary?: string;
42
+ elapsedSeconds?: number;
43
+ hookName?: string;
44
+ hookEvent?: string;
45
+ hookOutcome?: string;
46
+ statusText?: string;
47
+ taskDescription?: string;
48
+ taskId?: string;
49
+ taskStatus?: string;
50
+ taskSummary?: string;
51
+ isBackground?: boolean;
52
+ isTeammate?: boolean;
53
+ runtimeIdentity?: StreamRuntimeIdentity | null;
54
+ toolInput?: Record<string, unknown>;
55
+ todos?: Array<{ id: string; content: string; status: 'pending' | 'in_progress' | 'completed' }>;
56
+ /** Token usage data emitted at query completion */
57
+ usage?: {
58
+ inputTokens: number;
59
+ outputTokens: number;
60
+ cacheReadInputTokens: number;
61
+ cacheCreationInputTokens: number;
62
+ costUSD: number;
63
+ durationMs: number;
64
+ numTurns: number;
65
+ modelUsage?: Record<string, { inputTokens: number; outputTokens: number; costUSD: number }>;
66
+ };
67
+ }
@@ -0,0 +1,21 @@
1
+ export interface ToolStepDisplayOptions {
2
+ maxSummaryChars?: number;
3
+ }
4
+
5
+ export function formatToolStepLine(
6
+ toolName: string,
7
+ summary?: string | null,
8
+ options?: ToolStepDisplayOptions,
9
+ ): string {
10
+ const normalizedName = toolName.trim() || 'unknown';
11
+ const normalizedSummary = (summary || '').trim();
12
+ if (!normalizedSummary) return normalizedName;
13
+
14
+ const maxSummaryChars = options?.maxSummaryChars ?? 60;
15
+ const compactSummary =
16
+ normalizedSummary.length > maxSummaryChars
17
+ ? `${normalizedSummary.slice(0, maxSummaryChars)}...`
18
+ : normalizedSummary;
19
+
20
+ return `${normalizedName} · ${compactSummary}`;
21
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": [
7
+ "ES2022"
8
+ ],
9
+ "outDir": "./dist",
10
+ "rootDir": "./",
11
+ "declaration": true,
12
+ "strict": true,
13
+ "esModuleInterop": true,
14
+ "skipLibCheck": true,
15
+ "forceConsistentCasingInFileNames": true,
16
+ "tsBuildInfoFile": "./dist/.tsbuildinfo"
17
+ },
18
+ "include": [
19
+ "*.ts"
20
+ ],
21
+ "exclude": [
22
+ "dist"
23
+ ]
24
+ }
@@ -0,0 +1,52 @@
1
+ import{c as P,u as D,r as m,j as e,V as Y,W as he,Y as pe,Z as W,_ as De,f as X,B as S,z as Te,g as Ee,k as be,$ as je,a0 as _e,a1 as ge,a2 as fe,I as N,a3 as Le,a4 as ae,a5 as Q,a6 as ve,b as ie,o as ye,a7 as $e,Q as ne,U as Me,a8 as Ae,m as Pe,a9 as ce,x as Be,aa as Ie}from"./index-CPnL1_qC.js";import{u as M,f as A,L as Ne,D as Re}from"./utils-KGAn0XTg.js";import{C as ke,S as ze}from"./sparkles-BsMYXJoT.js";import{Z as re}from"./zap-_hKJYy7J.js";import{U as K,S as Fe,a as He,b as Qe,c as Oe}from"./sheet-rI0FfB1g.js";import{S as de,F as we}from"./square-0CqMX1Q3.js";/**
2
+ * @license lucide-react v0.400.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const Ce=P("BarChart3",[["path",{d:"M3 3v18h18",key:"1s2lah"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]]);/**
7
+ * @license lucide-react v0.400.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const Ue=P("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);/**
12
+ * @license lucide-react v0.400.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const Ve=P("ChevronsLeft",[["path",{d:"m11 17-5-5 5-5",key:"13zhaf"}],["path",{d:"m18 17-5-5 5-5",key:"h8a8et"}]]);/**
17
+ * @license lucide-react v0.400.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const We=P("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
22
+ * @license lucide-react v0.400.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */const le=P("CreditCard",[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2",key:"ynyp8z"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10",key:"1b3vmo"}]]);/**
27
+ * @license lucide-react v0.400.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const Se=P("Gift",[["rect",{x:"3",y:"8",width:"18",height:"4",rx:"1",key:"bkv52"}],["path",{d:"M12 8v13",key:"1c76mn"}],["path",{d:"M19 12v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-7",key:"6wjy6b"}],["path",{d:"M7.5 8a2.5 2.5 0 0 1 0-5A4.8 8 0 0 1 12 8a4.8 8 0 0 1 4.5-5 2.5 2.5 0 0 1 0 5",key:"1ihvrl"}]]);/**
32
+ * @license lucide-react v0.400.0 - ISC
33
+ *
34
+ * This source code is licensed under the ISC license.
35
+ * See the LICENSE file in the root directory of this source tree.
36
+ */const qe=P("History",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]);/**
37
+ * @license lucide-react v0.400.0 - ISC
38
+ *
39
+ * This source code is licensed under the ISC license.
40
+ * See the LICENSE file in the root directory of this source tree.
41
+ */const Ye=P("LayoutDashboard",[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]]);/**
42
+ * @license lucide-react v0.400.0 - ISC
43
+ *
44
+ * This source code is licensed under the ISC license.
45
+ * See the LICENSE file in the root directory of this source tree.
46
+ */const oe=P("SquareCheckBig",[["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}],["path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11",key:"1jnkn4"}]]);/**
47
+ * @license lucide-react v0.400.0 - ISC
48
+ *
49
+ * This source code is licensed under the ISC license.
50
+ * See the LICENSE file in the root directory of this source tree.
51
+ */const Ge=P("TrendingUp",[["polyline",{points:"22 7 13.5 15.5 8.5 10.5 2 17",key:"126l90"}],["polyline",{points:"16 7 22 7 22 13",key:"kwv8wd"}]]);function Ze(){const{subscription:s,plan:a,access:i,billingMinStartBalanceUsd:d,loadMySubscription:x,loadMyAccess:t}=D(),o=M();m.useEffect(()=>{x(),t()},[t,x]);const l=(s==null?void 0:s.trial_ends_at)&&new Date(s.trial_ends_at)>new Date,n=(s==null?void 0:s.status)==="cancelled",_=(s==null?void 0:s.status)==="expired",c=s==null?void 0:s.id.startsWith("fallback_");return e.jsxs("div",{className:"bg-white dark:bg-zinc-800 rounded-lg border border-zinc-200 dark:border-zinc-700 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(Y,{className:"w-5 h-5 text-primary"}),e.jsx("h3",{className:"font-semibold",children:"当前套餐"})]}),a?e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-2xl font-bold text-primary",children:a.name}),c&&e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-full bg-zinc-100 text-zinc-600 dark:bg-zinc-700 dark:text-zinc-400",children:"默认"}),n&&e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-full bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300",children:"已取消"}),_&&e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-full bg-zinc-100 text-zinc-600 dark:bg-zinc-700 dark:text-zinc-400",children:"已过期"}),l&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs font-medium rounded-full bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300",children:[e.jsx(ke,{className:"w-3 h-3"}),"试用中"]})]}),a.display_price&&e.jsx("p",{className:"text-sm text-brand-700 dark:text-brand-400 font-medium mb-1",children:a.display_price}),a.description&&e.jsx("p",{className:"text-sm text-zinc-500 mb-3",children:a.description}),a.rate_multiplier!==1&&e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-amber-600 dark:text-amber-400 mb-3",children:[e.jsx(re,{className:"w-4 h-4"}),e.jsxs("span",{children:["费率倍数: ",a.rate_multiplier,"x"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[a.monthly_cost_quota!=null&&e.jsxs("div",{children:[e.jsx("span",{className:"text-zinc-500",children:"月度费用上限"}),e.jsx("div",{className:"font-medium",children:o(a.monthly_cost_quota)})]}),a.monthly_token_quota!=null&&e.jsxs("div",{children:[e.jsx("span",{className:"text-zinc-500",children:"月度 Token 上限"}),e.jsx("div",{className:"font-medium",children:A(a.monthly_token_quota)})]}),a.daily_cost_quota!=null&&e.jsxs("div",{children:[e.jsx("span",{className:"text-zinc-500",children:"日度费用上限"}),e.jsx("div",{className:"font-medium",children:o(a.daily_cost_quota)})]}),a.weekly_cost_quota!=null&&e.jsxs("div",{children:[e.jsx("span",{className:"text-zinc-500",children:"周度费用上限"}),e.jsx("div",{className:"font-medium",children:o(a.weekly_cost_quota)})]}),a.max_groups!=null&&e.jsxs("div",{children:[e.jsx("span",{className:"text-zinc-500",children:"工作区上限"}),e.jsx("div",{className:"font-medium",children:a.max_groups})]}),a.max_im_channels!=null&&e.jsxs("div",{children:[e.jsx("span",{className:"text-zinc-500",children:"IM 通道上限"}),e.jsx("div",{className:"font-medium",children:a.max_im_channels})]})]}),e.jsxs("div",{className:"mt-3 space-y-1",children:[l&&(s==null?void 0:s.trial_ends_at)&&e.jsxs("p",{className:"text-xs text-amber-600 dark:text-amber-400 flex items-center gap-1",children:[e.jsx(he,{className:"w-3 h-3"}),"试用截止: ",new Date(s.trial_ends_at).toLocaleDateString()]}),(s==null?void 0:s.expires_at)&&e.jsxs("p",{className:"text-xs text-zinc-400",children:["到期时间: ",new Date(s.expires_at).toLocaleDateString()]}),e.jsxs("div",{className:"pt-2 border-t border-zinc-100 dark:border-zinc-700 mt-2 space-y-2",children:[e.jsxs("p",{className:"text-xs text-zinc-500 dark:text-zinc-400",children:["钱包优先模式下,套餐决定费率和资源上限;是否可以继续使用,取决于当前余额是否达到 ",o((i==null?void 0:i.minBalanceUsd)??d),"。"]}),!(i!=null&&i.allowed)&&e.jsx("p",{className:"text-xs text-red-600 dark:text-red-400",children:(i==null?void 0:i.reason)||"当前不可用,请联系管理员处理。"})]})]})]}):e.jsx("p",{className:"text-zinc-500",children:"未订阅任何套餐"})]})}function Xe(){const{balance:s,access:a,billingMinStartBalanceUsd:i,loadMyBalance:d,loadMyAccess:x}=D(),t=M(),[o,l]=m.useState(""),[n,_]=m.useState(null),[c,u]=m.useState(!1),h=D(f=>f.redeemCode);m.useEffect(()=>{d(),x()},[x,d]),m.useEffect(()=>{if(n!=null&&n.ok){const f=setTimeout(()=>_(null),3e3);return()=>clearTimeout(f)}},[n]);const r=async()=>{const f=o.trim();if(!(!f||c)){u(!0);try{const k=await h(f);_({ok:k.success,text:k.message}),k.success&&l("")}finally{u(!1)}}};return e.jsxs("div",{className:"bg-white dark:bg-zinc-800 rounded-lg border border-zinc-200 dark:border-zinc-700 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(pe,{className:"w-5 h-5 text-primary"}),e.jsx("h3",{className:"font-semibold",children:"余额"})]}),e.jsx("div",{className:"text-3xl font-bold text-primary mb-1",children:s?t(s.balance_usd):"--"}),s&&e.jsxs("div",{className:"flex gap-4 text-xs text-zinc-400 mb-4",children:[e.jsxs("span",{children:["累计充值 ",t(s.total_deposited_usd)]}),e.jsxs("span",{children:["累计消耗 ",t(s.total_consumed_usd)]})]}),a&&e.jsxs("div",{className:`mb-4 rounded-md border px-3 py-2 text-sm ${a.allowed?"border-green-200 bg-green-50 text-green-700 dark:border-green-900/60 dark:bg-green-950/30 dark:text-green-300":"border-red-200 bg-red-50 text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium",children:[!a.allowed&&e.jsx(W,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:a.allowed?"当前可正常使用":a.reason||"当前余额不足"})]}),e.jsxs("p",{className:"mt-1 text-xs opacity-80",children:["钱包优先模式下,普通用户余额需至少达到 ",t(a.minBalanceUsd||i)," 才能继续使用。"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",placeholder:"输入兑换码",value:o,onChange:f=>l(f.target.value.toUpperCase()),onKeyDown:f=>f.key==="Enter"&&r(),maxLength:64,className:"flex-1 px-3 py-1.5 text-sm border border-zinc-300 dark:border-zinc-600 rounded-md bg-transparent font-mono tracking-wider"}),e.jsx("button",{onClick:r,disabled:c||!o.trim(),className:"px-3 py-1.5 text-sm bg-primary text-white rounded-md hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed",children:c?"...":"兑换"})]}),n&&e.jsxs("div",{className:`flex items-center gap-1.5 text-xs mt-2 ${n.ok?"text-green-600 dark:text-green-400":"text-red-500 dark:text-red-400"}`,children:[n.ok&&e.jsx(De,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:n.text})]})]})}function V({value:s,max:a,className:i}){const d=a>0?Math.min(s/a*100,100):0,x=d>=90?"bg-red-500":d>=70?"bg-yellow-500":"bg-brand-500";return e.jsx("div",{className:`h-2 bg-zinc-200 dark:bg-zinc-700 rounded-full overflow-hidden ${i??""}`,children:e.jsx("div",{className:`h-full ${x} rounded-full transition-all`,style:{width:`${d}%`}})})}const G={daily:"日度",weekly:"周度",monthly:"月度"};function se({label:s,costUsed:a,costQuota:i,tokenUsed:d,tokenQuota:x,fmt:t}){const o=i!=null&&i>0,l=x!=null&&x>0;return!o&&!l?null:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-medium text-zinc-500 uppercase tracking-wider",children:s}),o&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[e.jsx("span",{className:"text-zinc-500",children:"费用"}),e.jsxs("span",{children:[t(a)," / ",t(i)]})]}),e.jsx(V,{value:a,max:i})]}),l&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[e.jsx("span",{className:"text-zinc-500",children:"Token"}),e.jsxs("span",{children:[A(d)," / ",A(x)]})]}),e.jsx(V,{value:d,max:x})]})]})}function Ke(){var q,$;const{currentUsage:s,plan:a,quota:i,access:d,loadMyUsage:x,loadMyQuota:t,loadMyAccess:o}=D(),l=M(),[n,_]=m.useState("monthly");m.useEffect(()=>{x(),t(),o()},[o,t,x]);const c=i==null?void 0:i.usage,u=(q=i==null?void 0:i.usage)==null?void 0:q.daily,h=($=i==null?void 0:i.usage)==null?void 0:$.weekly,r=[],f=(j,w)=>{w!=null&&w>0&&r.push(j/w*100)};f((c==null?void 0:c.costUsed)??0,c==null?void 0:c.costQuota),f((c==null?void 0:c.tokenUsed)??0,c==null?void 0:c.tokenQuota),f((u==null?void 0:u.costUsed)??0,u==null?void 0:u.costQuota),f((u==null?void 0:u.tokenUsed)??0,u==null?void 0:u.tokenQuota),f((h==null?void 0:h.costUsed)??0,h==null?void 0:h.costQuota),f((h==null?void 0:h.tokenUsed)??0,h==null?void 0:h.tokenQuota);const k=r.length>0?Math.max(...r):0,y=(a==null?void 0:a.daily_cost_quota)!=null&&a.daily_cost_quota>0||(a==null?void 0:a.daily_token_quota)!=null&&a.daily_token_quota>0,z=(a==null?void 0:a.weekly_cost_quota)!=null&&a.weekly_cost_quota>0||(a==null?void 0:a.weekly_token_quota)!=null&&a.weekly_token_quota>0,E=(a==null?void 0:a.monthly_cost_quota)!=null&&a.monthly_cost_quota>0||(a==null?void 0:a.monthly_token_quota)!=null&&a.monthly_token_quota>0,p=[];return y&&p.push("daily"),z&&p.push("weekly"),E&&p.push("monthly"),p.length===0&&p.push("monthly"),e.jsxs("div",{className:"bg-white dark:bg-zinc-800 rounded-lg border border-zinc-200 dark:border-zinc-700 p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"w-5 h-5 text-primary"}),e.jsx("h3",{className:"font-semibold",children:"用量"})]}),p.length>1&&e.jsx("div",{className:"flex gap-1",children:p.map(j=>e.jsx("button",{onClick:()=>_(j),className:`px-2 py-0.5 text-xs rounded transition-colors ${n===j?"bg-brand-100 dark:bg-brand-700/30 text-brand-700 dark:text-brand-300":"text-zinc-400 hover:text-zinc-600 dark:hover:text-zinc-300"}`,children:G[j]},j))})]}),d&&!d.allowed&&e.jsxs("div",{className:"flex items-center gap-2 text-sm mb-3 px-3 py-2 rounded-md bg-red-50 dark:bg-red-900/20 text-red-700 dark:text-red-400",children:[e.jsx(W,{className:"w-4 h-4 shrink-0"}),e.jsx("span",{children:d.reason||"当前不可用,请联系管理员处理余额或套餐限制。"})]}),(!d||d.allowed||d.blockType!=="insufficient_balance")&&k>=80&&e.jsxs("div",{className:`flex items-center gap-2 text-sm mb-3 px-3 py-2 rounded-md ${k>=100?"bg-red-50 dark:bg-red-900/20 text-red-700 dark:text-red-400":"bg-yellow-50 dark:bg-yellow-900/20 text-yellow-700 dark:text-yellow-400"}`,children:[e.jsx(W,{className:"w-4 h-4 shrink-0"}),e.jsx("span",{children:k>=100?"配额已用完,请联系管理员调整套餐或额度":`配额已使用 ${Math.round(k)}%,即将达到上限`})]}),e.jsxs("div",{className:"space-y-4",children:[n==="daily"&&e.jsx(se,{label:G.daily,costUsed:(u==null?void 0:u.costUsed)??0,costQuota:(u==null?void 0:u.costQuota)??(a==null?void 0:a.daily_cost_quota)??null,tokenUsed:(u==null?void 0:u.tokenUsed)??0,tokenQuota:(u==null?void 0:u.tokenQuota)??(a==null?void 0:a.daily_token_quota)??null,fmt:l}),n==="weekly"&&e.jsx(se,{label:G.weekly,costUsed:(h==null?void 0:h.costUsed)??0,costQuota:(h==null?void 0:h.costQuota)??(a==null?void 0:a.weekly_cost_quota)??null,tokenUsed:(h==null?void 0:h.tokenUsed)??0,tokenQuota:(h==null?void 0:h.tokenQuota)??(a==null?void 0:a.weekly_token_quota)??null,fmt:l}),n==="monthly"&&e.jsx(se,{label:G.monthly,costUsed:(c==null?void 0:c.costUsed)??(s==null?void 0:s.total_cost_usd)??0,costQuota:(c==null?void 0:c.costQuota)??(a==null?void 0:a.monthly_cost_quota)??null,tokenUsed:(c==null?void 0:c.tokenUsed)??(s?s.total_input_tokens+s.total_output_tokens:0),tokenQuota:(c==null?void 0:c.tokenQuota)??(a==null?void 0:a.monthly_token_quota)??null,fmt:l}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm text-zinc-500",children:[e.jsxs("div",{children:[e.jsx("span",{className:"block text-xs text-zinc-400",children:"本月费用"}),e.jsx("span",{className:"font-medium text-zinc-700 dark:text-zinc-300",children:l((s==null?void 0:s.total_cost_usd)??0)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"block text-xs text-zinc-400",children:"本月 Token"}),e.jsx("span",{className:"font-medium text-zinc-700 dark:text-zinc-300",children:A(((s==null?void 0:s.total_input_tokens)??0)+((s==null?void 0:s.total_output_tokens)??0))})]}),e.jsxs("div",{children:[e.jsx("span",{className:"block text-xs text-zinc-400",children:"消息数"}),e.jsx("span",{className:"font-medium text-zinc-700 dark:text-zinc-300",children:(s==null?void 0:s.message_count)??0})]})]})]})]})}const Z=14;function Je(){const{dailyUsage:s,loadDailyUsage:a}=D(),i=M(),[d,x]=m.useState(null);m.useEffect(()=>{a(Z)},[a]);const t=new Date,o=Array.from({length:Z},(n,_)=>{const c=new Date(t);c.setDate(c.getDate()-(Z-1-_));const u=c.toISOString().slice(0,10),h=s.find(r=>r.date===u);return{date:u,label:`${String(c.getMonth()+1).padStart(2,"0")}-${String(c.getDate()).padStart(2,"0")}`,cost:(h==null?void 0:h.total_cost_usd)??0,inputTokens:(h==null?void 0:h.total_input_tokens)??0,outputTokens:(h==null?void 0:h.total_output_tokens)??0,messages:(h==null?void 0:h.message_count)??0}}),l=Math.max(...o.map(n=>n.cost),.01);return e.jsxs("div",{className:"bg-white dark:bg-zinc-800 rounded-lg border border-zinc-200 dark:border-zinc-700 p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(Ce,{className:"w-5 h-5 text-primary"}),e.jsxs("h3",{className:"font-semibold",children:["近 ",Z," 天用量"]})]}),s.length===0?e.jsx("p",{className:"text-sm text-zinc-500 py-8 text-center",children:"暂无用量数据"}):e.jsxs("div",{className:"relative",children:[d!==null&&e.jsxs("div",{className:"absolute -top-2 left-1/2 -translate-x-1/2 z-10 bg-zinc-900 dark:bg-zinc-700 text-white text-xs rounded-md px-3 py-2 shadow-lg pointer-events-none whitespace-nowrap",children:[e.jsx("div",{className:"font-medium mb-1",children:o[d].date}),e.jsxs("div",{children:["费用: ",i(o[d].cost)]}),e.jsxs("div",{children:["Token: ",A(o[d].inputTokens+o[d].outputTokens)]}),e.jsxs("div",{children:["消息: ",o[d].messages]})]}),e.jsx("div",{className:"flex items-end gap-1 h-40",children:o.map((n,_)=>{const c=l>0?n.cost/l*100:0,u=d===_;return e.jsx("div",{className:"flex-1 flex flex-col items-center justify-end h-full",onMouseEnter:()=>x(_),onMouseLeave:()=>x(null),children:e.jsx("div",{className:`w-full rounded-t transition-all cursor-pointer ${u?"bg-brand-500 dark:bg-brand-400":"bg-brand-400/70 dark:bg-brand-600/70"}`,style:{height:`${Math.max(c,n.cost>0?4:0)}%`,minHeight:n.cost>0?"4px":"0px"}})},n.date)})}),e.jsx("div",{className:"flex gap-1 mt-1.5",children:o.map((n,_)=>e.jsxs("div",{className:`flex-1 text-center text-[10px] leading-tight ${d===_?"text-primary dark:text-brand-400 font-medium":"text-zinc-400"}`,children:[e.jsx("span",{className:"hidden sm:inline",children:n.label}),e.jsx("span",{className:"sm:hidden",children:_%2===0?n.label:""})]},n.date))}),e.jsxs("div",{className:"flex justify-between text-xs text-zinc-400 mt-3 pt-3 border-t border-zinc-100 dark:border-zinc-700",children:[e.jsxs("span",{children:["合计费用: ",i(o.reduce((n,_)=>n+_.cost,0))]}),e.jsxs("span",{children:["合计消息: ",o.reduce((n,_)=>n+_.messages,0)]})]})]})]})}const xe={deposit:"充值",deduction:"扣减",consumption:"消耗",adjustment:"调整",refund:"退款",redeem:"兑换码"},es={admin_manual_recharge:"后台充值",admin_manual_deduct:"后台扣减",usage_charge:"用量扣费",redeem_code:"兑换码",migration_opening:"初始化",refund:"退款"};function ss(){const{transactions:s,transactionsTotal:a,loadMyTransactions:i}=D(),d=M();return m.useEffect(()=>{i()},[i]),e.jsxs("div",{className:"bg-white dark:bg-zinc-800 rounded-lg border border-zinc-200 dark:border-zinc-700 p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"w-5 h-5 text-primary"}),e.jsx("h3",{className:"font-semibold",children:"余额变动记录"})]}),a>0&&e.jsxs("span",{className:"text-xs text-zinc-400",children:["共 ",a," 条"]})]}),s.length===0?e.jsx("p",{className:"text-sm text-zinc-500",children:"暂无记录"}):e.jsx("div",{className:"space-y-2 max-h-64 overflow-y-auto",children:s.map(x=>e.jsxs("div",{className:"flex justify-between items-center py-2 border-b border-zinc-100 dark:border-zinc-700 last:border-0",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm truncate",children:x.description||xe[x.type]||x.type}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-zinc-400",children:[e.jsx("span",{children:new Date(x.created_at).toLocaleString()}),(x.source||x.type)&&e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-zinc-100 dark:bg-zinc-700 text-zinc-500 dark:text-zinc-400",children:es[x.source||""]||xe[x.type]||x.type})]})]}),e.jsxs("div",{className:"flex flex-col items-end ml-3 shrink-0",children:[e.jsxs("span",{className:`text-sm font-medium ${x.amount_usd>0?"text-green-600":"text-red-500"}`,children:[x.amount_usd>0?"+":"",d(x.amount_usd)]}),e.jsxs("span",{className:"text-[11px] text-zinc-400",children:["余额 ",d(x.balance_after)]})]})]},x.id))})]})}function ts({plan:s,isCurrent:a,fmt:i}){const d=s.highlight,x=[];s.max_groups!=null&&x.push({label:"工作区",value:`${s.max_groups}`}),s.max_im_channels!=null&&x.push({label:"IM 通道",value:`${s.max_im_channels}`}),s.max_mcp_servers!=null&&x.push({label:"MCP Server",value:`${s.max_mcp_servers}`}),s.max_concurrent_containers!=null&&x.push({label:"并发容器",value:`${s.max_concurrent_containers}`}),s.max_storage_mb!=null&&x.push({label:"存储",value:`${s.max_storage_mb} MB`});const t=[];return s.monthly_cost_quota!=null&&t.push({label:"月度费用",value:i(s.monthly_cost_quota)}),s.weekly_cost_quota!=null&&t.push({label:"周度费用",value:i(s.weekly_cost_quota)}),s.daily_cost_quota!=null&&t.push({label:"日度费用",value:i(s.daily_cost_quota)}),s.monthly_token_quota!=null&&t.push({label:"月度 Token",value:A(s.monthly_token_quota)}),s.weekly_token_quota!=null&&t.push({label:"周度 Token",value:A(s.weekly_token_quota)}),s.daily_token_quota!=null&&t.push({label:"日度 Token",value:A(s.daily_token_quota)}),e.jsxs("div",{className:`relative rounded-lg border p-5 flex flex-col transition-shadow ${d?"border-brand-500 dark:border-brand-400 shadow-[0_0_12px_rgba(249,115,22,0.25)] dark:shadow-[0_0_12px_rgba(251,146,60,0.2)]":"border-zinc-200 dark:border-zinc-700"} bg-white dark:bg-zinc-800`,children:[d&&e.jsx("div",{className:"absolute -top-3 left-1/2 -translate-x-1/2",children:e.jsxs("span",{className:"inline-flex items-center gap-1 px-3 py-0.5 text-xs font-medium rounded-full bg-brand-600 text-white",children:[e.jsx(ze,{className:"w-3 h-3"}),"推荐"]})}),a&&e.jsx("div",{className:"absolute top-3 right-3",children:e.jsx("span",{className:"px-2 py-0.5 text-xs font-medium rounded-full bg-brand-100 text-brand-700 dark:bg-brand-700/30 dark:text-brand-300",children:"当前"})}),e.jsxs("div",{className:"mb-4",children:[e.jsx("h4",{className:"text-lg font-bold",children:s.name}),s.display_price?e.jsx("p",{className:"text-xl font-bold text-primary dark:text-brand-400 mt-1",children:s.display_price}):e.jsx("p",{className:"text-xl font-bold text-primary dark:text-brand-400 mt-1",children:s.monthly_cost_usd===0?"免费":`${i(s.monthly_cost_usd)}/月`}),s.description&&e.jsx("p",{className:"text-sm text-zinc-500 mt-1",children:s.description})]}),s.rate_multiplier!==1&&e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-amber-600 dark:text-amber-400 mb-3",children:[e.jsx(re,{className:"w-4 h-4"}),e.jsxs("span",{children:["费率倍数: ",s.rate_multiplier,"x"]})]}),s.trial_days!=null&&s.trial_days>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-blue-600 dark:text-blue-400 mb-3",children:[e.jsx(ke,{className:"w-4 h-4"}),e.jsxs("span",{children:[s.trial_days," 天免费试用"]})]}),s.features.length>0&&e.jsx("div",{className:"space-y-1.5 mb-4",children:s.features.map((o,l)=>e.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[e.jsx(X,{className:"w-4 h-4 text-brand-500 mt-0.5 shrink-0"}),e.jsx("span",{children:o})]},l))}),t.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-zinc-500 uppercase tracking-wider mb-2",children:[e.jsx(Ne,{className:"w-3.5 h-3.5"}),"配额"]}),e.jsx("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-sm",children:t.map(o=>e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-zinc-500",children:o.label}),e.jsx("span",{className:"font-medium",children:o.value})]},o.label))})]}),x.length>0&&e.jsx("div",{className:"mt-auto pt-3 border-t border-zinc-100 dark:border-zinc-700",children:e.jsx("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-sm",children:x.map(o=>e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-zinc-400",children:o.label}),e.jsx("span",{className:"text-zinc-600 dark:text-zinc-300",children:o.value})]},o.label))})})]})}function as(){const{plans:s,plan:a,loadPlans:i,loadMySubscription:d}=D(),x=M();m.useEffect(()=>{i(),d()},[i,d]);const t=s.filter(o=>o.is_active).sort((o,l)=>o.sort_order-l.sort_order||o.tier-l.tier);return t.length===0?e.jsxs("div",{className:"bg-white dark:bg-zinc-800 rounded-lg border border-zinc-200 dark:border-zinc-700 p-8 text-center",children:[e.jsx(ze,{className:"w-8 h-8 text-zinc-300 mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-zinc-500",children:"暂无可用套餐"})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:t.map(o=>e.jsx(ts,{plan:o,isCurrent:(a==null?void 0:a.id)===o.id,fmt:x},o.id))})}function U({icon:s,label:a,value:i,sub:d}){return e.jsxs("div",{className:"bg-white dark:bg-zinc-800 rounded-lg border border-zinc-200 dark:border-zinc-700 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-zinc-500 text-sm mb-2",children:[e.jsx(s,{className:"w-4 h-4 text-primary"}),a]}),e.jsx("div",{className:"text-2xl font-bold",children:i}),d&&e.jsx("div",{className:"text-xs text-zinc-400 mt-1",children:d})]})}function ns({data:s}){const a=s.reduce((i,d)=>i+d.count,0)||1;return e.jsxs("div",{className:"bg-white dark:bg-zinc-800 rounded-lg border border-zinc-200 dark:border-zinc-700 p-5",children:[e.jsx("h3",{className:"font-semibold text-sm mb-4",children:"套餐分布"}),s.length===0?e.jsx("p",{className:"text-sm text-zinc-500",children:"暂无数据"}):e.jsx("div",{className:"space-y-3",children:s.map(i=>{const d=Math.round(i.count/a*100);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[e.jsx("span",{children:i.plan_name}),e.jsxs("span",{className:"text-zinc-500",children:[i.count," (",d,"%)"]})]}),e.jsx("div",{className:"h-2 bg-zinc-200 dark:bg-zinc-700 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-brand-500 rounded-full transition-all",style:{width:`${d}%`}})})]},i.plan_name)})})]})}function ls({data:s,fmt:a}){const i=Math.max(...s.map(d=>d.revenue),1);return e.jsxs("div",{className:"bg-white dark:bg-zinc-800 rounded-lg border border-zinc-200 dark:border-zinc-700 p-5",children:[e.jsx("h3",{className:"font-semibold text-sm mb-4",children:"收入趋势"}),s.length===0?e.jsx("p",{className:"text-sm text-zinc-500",children:"暂无数据"}):e.jsx("div",{className:"flex items-end gap-1 h-40",children:s.map(d=>{const x=Math.max(d.revenue/i*100,2),t=d.month.slice(5);return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1 min-w-0",children:[e.jsx("span",{className:"text-[10px] text-zinc-400 truncate w-full text-center",children:a(d.revenue)}),e.jsx("div",{className:"w-full bg-brand-500 rounded-t transition-all hover:bg-brand-400",style:{height:`${x}%`},title:`${d.month}: ${a(d.revenue)} / ${d.users} 用户`}),e.jsx("span",{className:"text-[10px] text-zinc-400 truncate w-full text-center",children:t})]},d.month)})})]})}function rs(){const{dashboardData:s,revenueTrend:a,loadDashboard:i,loadRevenueTrend:d}=D(),x=M();m.useEffect(()=>{i(),d()},[i,d]);const t=s;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 xl:grid-cols-5 gap-3",children:[e.jsx(U,{icon:K,label:"活跃用户",value:`${(t==null?void 0:t.activeUsers)??0} / ${(t==null?void 0:t.totalUsers)??0}`,sub:"活跃 / 总用户"}),e.jsx(U,{icon:le,label:"活跃订阅",value:String((t==null?void 0:t.activeSubscriptions)??0)}),e.jsx(U,{icon:Re,label:"今日费用",value:x((t==null?void 0:t.todayCost)??0)}),e.jsx(U,{icon:Ge,label:"本月费用",value:x((t==null?void 0:t.monthCost)??0)}),e.jsx(U,{icon:K,label:"已阻断用户",value:String((t==null?void 0:t.blockedUsers)??0),sub:"余额不足或套餐限制"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(ns,{data:(t==null?void 0:t.planDistribution)??[]}),e.jsx(ls,{data:a,fmt:x})]})]})}function is({onEditPlan:s,onCreatePlan:a}){const{plans:i,loadAllPlans:d,deletePlan:x}=D(),t=M();m.useEffect(()=>{d()},[d]);const o=async l=>{if(l.is_default)return;const n=l.subscriber_count,_=n?`套餐「${l.name}」下还有 ${n} 个订阅用户,确定删除?`:`确定删除套餐「${l.name}」?`;confirm(_)&&await x(l.id)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"font-semibold flex items-center gap-2",children:[e.jsx(Y,{className:"w-5 h-5 text-primary"}),"套餐管理"]}),e.jsxs(S,{size:"sm",onClick:a,children:[e.jsx(Te,{className:"w-4 h-4"}),"新建套餐"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:i.map(l=>{const n=l.subscriber_count;return e.jsxs("div",{className:`relative bg-white dark:bg-zinc-800 rounded-lg border p-5 ${l.highlight?"border-brand-400 dark:border-brand-600 ring-1 ring-brand-400/30":"border-zinc-200 dark:border-zinc-700"} ${l.is_active?"":"opacity-60"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2 flex-wrap",children:[l.is_default&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 text-xs rounded-full bg-brand-100 text-brand-700 dark:bg-brand-700/30 dark:text-brand-300",children:[e.jsx(he,{className:"w-3 h-3"}),"默认"]}),l.highlight&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 text-xs rounded-full bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300",children:[e.jsx(re,{className:"w-3 h-3"}),"推荐"]}),!l.is_active&&e.jsx("span",{className:"px-1.5 py-0.5 text-xs rounded-full bg-zinc-200 text-zinc-600 dark:bg-zinc-700 dark:text-zinc-400",children:"已禁用"})]}),e.jsx("div",{className:"text-lg font-bold mb-0.5",children:l.name}),e.jsx("div",{className:"text-sm text-zinc-500 mb-3",children:l.display_price??t(l.monthly_cost_usd)+"/月"}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-xs text-zinc-500",children:[e.jsxs("span",{children:["ID: ",l.id]}),e.jsxs("span",{children:["Tier: ",l.tier]}),e.jsxs("span",{children:["排序: ",l.sort_order]}),e.jsxs("span",{children:["费率: ",l.rate_multiplier,"x"]}),l.trial_days!=null&&e.jsxs("span",{children:["试用: ",l.trial_days," 天"]}),n!=null&&e.jsxs("span",{children:["订阅者: ",n]})]}),e.jsxs("div",{className:"mt-3 pt-3 border-t border-zinc-100 dark:border-zinc-700 grid grid-cols-2 gap-1 text-xs text-zinc-500",children:[l.daily_cost_quota!=null&&e.jsxs("span",{children:["日费用: ",t(l.daily_cost_quota)]}),l.daily_token_quota!=null&&e.jsxs("span",{children:["日Token: ",A(l.daily_token_quota)]}),l.weekly_cost_quota!=null&&e.jsxs("span",{children:["周费用: ",t(l.weekly_cost_quota)]}),l.weekly_token_quota!=null&&e.jsxs("span",{children:["周Token: ",A(l.weekly_token_quota)]}),l.monthly_cost_quota!=null&&e.jsxs("span",{children:["月费用: ",t(l.monthly_cost_quota)]}),l.monthly_token_quota!=null&&e.jsxs("span",{children:["月Token: ",A(l.monthly_token_quota)]})]}),e.jsxs("div",{className:"flex gap-1 mt-4",children:[e.jsxs(S,{variant:"outline",size:"xs",onClick:()=>s(l),children:[e.jsx(Ee,{className:"w-3 h-3"}),"编辑"]}),e.jsxs(S,{variant:"ghost",size:"xs",disabled:l.is_default,onClick:()=>o(l),className:"text-zinc-400 hover:text-red-500",children:[e.jsx(be,{className:"w-3 h-3"}),"删除"]})]})]},l.id)})}),i.length===0&&e.jsx("p",{className:"text-sm text-zinc-500 text-center py-8",children:"暂无套餐,点击「新建套餐」创建"})]})}const me={id:"",name:"",description:"",tier:0,sort_order:0,monthly_cost_usd:0,display_price:"",rate_multiplier:1,trial_days:"",monthly_cost_quota:"",monthly_token_quota:"",daily_cost_quota:"",daily_token_quota:"",weekly_cost_quota:"",weekly_token_quota:"",max_groups:"",max_im_channels:"",max_mcp_servers:"",max_concurrent_containers:"",max_storage_mb:"",allow_overage:!1,is_default:!1,is_active:!0,highlight:!1,features:""};function cs(s){return{id:s.id,name:s.name,description:s.description??"",tier:s.tier,sort_order:s.sort_order,monthly_cost_usd:s.monthly_cost_usd,display_price:s.display_price??"",rate_multiplier:s.rate_multiplier,trial_days:s.trial_days!=null?String(s.trial_days):"",monthly_cost_quota:s.monthly_cost_quota!=null?String(s.monthly_cost_quota):"",monthly_token_quota:s.monthly_token_quota!=null?String(s.monthly_token_quota):"",daily_cost_quota:s.daily_cost_quota!=null?String(s.daily_cost_quota):"",daily_token_quota:s.daily_token_quota!=null?String(s.daily_token_quota):"",weekly_cost_quota:s.weekly_cost_quota!=null?String(s.weekly_cost_quota):"",weekly_token_quota:s.weekly_token_quota!=null?String(s.weekly_token_quota):"",max_groups:s.max_groups!=null?String(s.max_groups):"",max_im_channels:s.max_im_channels!=null?String(s.max_im_channels):"",max_mcp_servers:s.max_mcp_servers!=null?String(s.max_mcp_servers):"",max_concurrent_containers:s.max_concurrent_containers!=null?String(s.max_concurrent_containers):"",max_storage_mb:s.max_storage_mb!=null?String(s.max_storage_mb):"",allow_overage:s.allow_overage,is_default:s.is_default,is_active:s.is_active,highlight:s.highlight,features:s.features.join(", ")}}function H({title:s,children:a}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-zinc-500 mb-2",children:s}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:a})]})}function C({label:s,children:a,span:i}){return e.jsxs("div",{className:i?"col-span-2":"",children:[e.jsx("label",{className:"block text-xs text-zinc-500 mb-1",children:s}),a]})}function ds({open:s,onOpenChange:a,plan:i}){const{createPlan:d,updatePlan:x}=D(),[t,o]=m.useState(me),[l,n]=m.useState(!1),_=i!==null;m.useEffect(()=>{s&&o(i?cs(i):me)},[s,i]);const c=(r,f)=>o(k=>({...k,[r]:f})),u=r=>r.trim()===""?null:Number(r),h=async()=>{if(!t.id.trim()||!t.name.trim()){Q.error("套餐 ID 和名称不能为空");return}n(!0);try{const r={id:t.id,name:t.name,description:t.description||null,tier:t.tier,sort_order:t.sort_order,monthly_cost_usd:t.monthly_cost_usd,display_price:t.display_price||null,rate_multiplier:t.rate_multiplier,trial_days:u(t.trial_days),monthly_cost_quota:u(t.monthly_cost_quota),monthly_token_quota:u(t.monthly_token_quota),daily_cost_quota:u(t.daily_cost_quota),daily_token_quota:u(t.daily_token_quota),weekly_cost_quota:u(t.weekly_cost_quota),weekly_token_quota:u(t.weekly_token_quota),max_groups:u(t.max_groups),max_im_channels:u(t.max_im_channels),max_mcp_servers:u(t.max_mcp_servers),max_concurrent_containers:u(t.max_concurrent_containers),max_storage_mb:u(t.max_storage_mb),allow_overage:t.allow_overage,is_default:t.is_default,is_active:t.is_active,highlight:t.highlight,features:t.features.split(",").map(f=>f.trim()).filter(Boolean)};_?await x(i.id,r):await d(r),a(!1)}catch(r){Q.error(r instanceof Error?r.message:String(r))}finally{n(!1)}};return e.jsx(je,{open:s,onOpenChange:a,children:e.jsxs(_e,{className:"sm:max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsx(ge,{children:e.jsx(fe,{children:_?"编辑套餐":"创建套餐"})}),e.jsxs("div",{className:"space-y-5 py-2",children:[e.jsxs(H,{title:"基本信息",children:[e.jsx(C,{label:"套餐 ID",children:e.jsx(N,{value:t.id,onChange:r=>c("id",r.target.value),disabled:_,placeholder:"如 basic"})}),e.jsx(C,{label:"名称",children:e.jsx(N,{value:t.name,onChange:r=>c("name",r.target.value),placeholder:"套餐名称"})}),e.jsx(C,{label:"描述",span:!0,children:e.jsx(N,{value:t.description,onChange:r=>c("description",r.target.value),placeholder:"套餐描述"})}),e.jsx(C,{label:"Tier",children:e.jsx(N,{type:"number",value:t.tier,onChange:r=>c("tier",Number(r.target.value))})}),e.jsx(C,{label:"排序",children:e.jsx(N,{type:"number",value:t.sort_order,onChange:r=>c("sort_order",Number(r.target.value))})})]}),e.jsxs(H,{title:"定价",children:[e.jsx(C,{label:"月费 (USD)",children:e.jsx(N,{type:"number",step:"0.01",value:t.monthly_cost_usd,onChange:r=>c("monthly_cost_usd",Number(r.target.value))})}),e.jsx(C,{label:"展示价格",children:e.jsx(N,{value:t.display_price,onChange:r=>c("display_price",r.target.value),placeholder:"如 ¥99/月"})}),e.jsx(C,{label:"费率倍数",children:e.jsx(N,{type:"number",step:"0.1",value:t.rate_multiplier,onChange:r=>c("rate_multiplier",Number(r.target.value))})}),e.jsx(C,{label:"试用天数",children:e.jsx(N,{type:"number",value:t.trial_days,onChange:r=>c("trial_days",r.target.value),placeholder:"留空=无试用"})})]}),e.jsxs(H,{title:"月度配额(留空=无限)",children:[e.jsx(C,{label:"月度费用上限 (USD)",children:e.jsx(N,{type:"number",step:"0.01",value:t.monthly_cost_quota,onChange:r=>c("monthly_cost_quota",r.target.value)})}),e.jsx(C,{label:"月度 Token 上限",children:e.jsx(N,{type:"number",value:t.monthly_token_quota,onChange:r=>c("monthly_token_quota",r.target.value)})})]}),e.jsxs(H,{title:"日度配额(留空=无限)",children:[e.jsx(C,{label:"日度费用上限 (USD)",children:e.jsx(N,{type:"number",step:"0.01",value:t.daily_cost_quota,onChange:r=>c("daily_cost_quota",r.target.value)})}),e.jsx(C,{label:"日度 Token 上限",children:e.jsx(N,{type:"number",value:t.daily_token_quota,onChange:r=>c("daily_token_quota",r.target.value)})})]}),e.jsxs(H,{title:"周度配额(留空=无限)",children:[e.jsx(C,{label:"周度费用上限 (USD)",children:e.jsx(N,{type:"number",step:"0.01",value:t.weekly_cost_quota,onChange:r=>c("weekly_cost_quota",r.target.value)})}),e.jsx(C,{label:"周度 Token 上限",children:e.jsx(N,{type:"number",value:t.weekly_token_quota,onChange:r=>c("weekly_token_quota",r.target.value)})})]}),e.jsxs(H,{title:"资源限制(留空=无限)",children:[e.jsx(C,{label:"工作区上限",children:e.jsx(N,{type:"number",value:t.max_groups,onChange:r=>c("max_groups",r.target.value)})}),e.jsx(C,{label:"IM 通道上限",children:e.jsx(N,{type:"number",value:t.max_im_channels,onChange:r=>c("max_im_channels",r.target.value)})}),e.jsx(C,{label:"MCP Server 上限",children:e.jsx(N,{type:"number",value:t.max_mcp_servers,onChange:r=>c("max_mcp_servers",r.target.value)})}),e.jsx(C,{label:"并发容器上限",children:e.jsx(N,{type:"number",value:t.max_concurrent_containers,onChange:r=>c("max_concurrent_containers",r.target.value)})}),e.jsx(C,{label:"存储上限 (MB)",children:e.jsx(N,{type:"number",value:t.max_storage_mb,onChange:r=>c("max_storage_mb",r.target.value)})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-zinc-500 mb-2",children:"开关"}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:[["allow_overage","允许超额"],["is_default","默认套餐"],["is_active","启用"],["highlight","高亮推荐"]].map(([r,f])=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:f}),e.jsx(Le,{checked:t[r],onCheckedChange:k=>c(r,k)})]},r))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-zinc-500 mb-2",children:"特性标签"}),e.jsx(N,{value:t.features,onChange:r=>c("features",r.target.value),placeholder:"逗号分隔,如: 高速响应, 无限对话, 自定义 Agent"})]})]}),e.jsxs(ae,{children:[e.jsx(S,{variant:"outline",onClick:()=>a(!1),disabled:l,children:"取消"}),e.jsx(S,{onClick:h,disabled:l,children:l?"保存中...":_?"保存":"创建"})]})]})})}function os({onSelectUser:s}){const{allUsers:a,plans:i,loadAllUsers:d,loadAllPlans:x,batchAssignPlan:t}=D(),o=M(),[l,n]=m.useState(""),[_,c]=m.useState(new Set),[u,h]=m.useState(""),[r,f]=m.useState(!1),[k,y]=m.useState(null);m.useEffect(()=>{d(),x()},[d,x]);const z=m.useMemo(()=>{if(!l.trim())return a;const j=l.toLowerCase();return a.filter(w=>w.username.toLowerCase().includes(j)||w.display_name.toLowerCase().includes(j))},[a,l]),E=j=>{c(w=>{const L=new Set(w);return L.has(j)?L.delete(j):L.add(j),L})},p=()=>{_.size===z.length?c(new Set):c(new Set(z.map(j=>j.user_id)))},q=async()=>{var j;if(!(!u||_.size===0)){f(!0),y(null);try{const w=_.size;await t(Array.from(_),u);const L=((j=i.find(b=>b.id===u))==null?void 0:j.name)??u;y({type:"success",msg:`已为 ${w} 位用户分配「${L}」`}),c(new Set),h(""),setTimeout(()=>y(null),4e3)}catch(w){y({type:"error",msg:`批量分配失败: ${w instanceof Error?w.message:String(w)}`})}finally{f(!1)}}},$=z.length>0&&_.size===z.length;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("h3",{className:"font-semibold flex items-center gap-2",children:[e.jsx(K,{className:"w-5 h-5 text-primary"}),"用户计费管理"]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-zinc-500",children:["共 ",a.length," 人",_.size>0&&` / 已选 ${_.size}`]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ve,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-zinc-400"}),e.jsx(N,{value:l,onChange:j=>n(j.target.value),placeholder:"搜索用户名或显示名",className:"pl-9"})]}),_.size>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("select",{value:u,onChange:j=>h(j.target.value),className:"h-9 px-3 text-sm border border-zinc-300 dark:border-zinc-600 rounded-md bg-transparent",children:[e.jsx("option",{value:"",children:"选择套餐"}),i.map(j=>e.jsx("option",{value:j.id,children:j.name},j.id))]}),e.jsxs(S,{size:"sm",onClick:q,disabled:!u||r,children:[e.jsx(Y,{className:"w-4 h-4"}),"批量分配"]})]})]}),e.jsxs("div",{className:"hidden sm:grid sm:grid-cols-[auto_1fr_120px_100px_100px_80px] gap-2 px-3 py-2 text-xs text-zinc-500 font-medium border-b border-zinc-200 dark:border-zinc-700",children:[e.jsx("button",{onClick:p,className:"p-0.5",children:$?e.jsx(oe,{className:"w-4 h-4 text-primary"}):e.jsx(de,{className:"w-4 h-4"})}),e.jsx("span",{children:"用户"}),e.jsx("span",{children:"套餐"}),e.jsx("span",{className:"text-right",children:"余额"}),e.jsx("span",{className:"text-right",children:"本月费用"}),e.jsx("span",{className:"text-right",children:"操作"})]}),e.jsx("div",{className:"space-y-1",children:z.map(j=>e.jsxs("div",{className:`grid grid-cols-1 sm:grid-cols-[auto_1fr_120px_100px_100px_80px] gap-2 items-center px-3 py-2.5 bg-white dark:bg-zinc-800 rounded-lg border ${j.access_allowed===!1?"border-red-200 dark:border-red-900/60":"border-zinc-200 dark:border-zinc-700"}`,children:[e.jsx("button",{onClick:()=>E(j.user_id),className:"hidden sm:block p-0.5",children:_.has(j.user_id)?e.jsx(oe,{className:"w-4 h-4 text-primary"}):e.jsx(de,{className:"w-4 h-4 text-zinc-400"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"font-medium text-sm truncate block",children:j.display_name||j.username}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-zinc-400",children:["@",j.username]}),j.access_allowed===!1&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-red-50 px-2 py-0.5 text-[10px] font-medium text-red-700 dark:bg-red-950/30 dark:text-red-300",children:[e.jsx(W,{className:"h-3 w-3"}),"已阻断"]})]}),j.access_allowed===!1&&j.access_reason&&e.jsx("span",{className:"mt-1 block text-[11px] text-red-600 dark:text-red-400 truncate",children:j.access_reason})]}),e.jsx("span",{className:"text-sm text-zinc-600 dark:text-zinc-400 truncate",children:j.plan_name?e.jsxs(e.Fragment,{children:[j.plan_name,j.is_fallback&&e.jsx("span",{className:"ml-1 text-[10px] text-zinc-400",children:"(默认)"})]}):e.jsx("span",{className:"text-zinc-400 italic",children:"无套餐"})}),e.jsx("span",{className:"text-sm text-right font-mono",children:o(j.balance_usd)}),e.jsx("span",{className:"text-sm text-right font-mono text-zinc-500",children:o(j.current_month_cost)}),e.jsx("div",{className:"text-right",children:e.jsx(S,{variant:"ghost",size:"xs",onClick:()=>s(j.user_id),children:"详情"})})]},j.user_id))}),z.length===0&&e.jsx("p",{className:"text-sm text-zinc-500 text-center py-8",children:l?"未找到匹配的用户":"暂无用户"}),k&&e.jsx("div",{className:`text-sm px-3 py-2 rounded-md ${k.type==="success"?"bg-green-50 dark:bg-green-900/20 text-green-700 dark:text-green-400":"bg-red-50 dark:bg-red-900/20 text-red-700 dark:text-red-400"}`,children:k.msg})]})}const xs={admin_manual_recharge:"后台充值",admin_manual_deduct:"后台扣减",usage_charge:"用量扣费",redeem_code:"兑换码",migration_opening:"初始化",refund:"退款"};function ms({userId:s,onClose:a}){const{plans:i,assignPlan:d,adjustBalance:x,cancelUserSubscription:t,getUserSubscriptionHistory:o}=D(),l=M(),[n,_]=m.useState(null),[c,u]=m.useState([]),[h,r]=m.useState([]),[f,k]=m.useState(!1),[y,z]=m.useState(""),[E,p]=m.useState(!1),[q,$]=m.useState(""),[j,w]=m.useState(""),[L,b]=m.useState(!1),T=m.useCallback(async v=>{k(!0);try{const[J,ee]=await Promise.all([ie.get(`/api/billing/admin/users/${v}/detail`),ie.get(`/api/billing/admin/users/${v}/transactions?limit=20`)]);_(J),u(ee.transactions);const O=await o(v);r(O)}catch{_(null),u([]),r([])}finally{k(!1)}},[o]);m.useEffect(()=>{s&&(T(s),z(""),$(""),w(""))},[s,T]);const F=async()=>{if(!(!s||!y)){p(!0);try{await d(s,y),await T(s),z("")}finally{p(!1)}}},R=async()=>{if(!s)return;const v=parseFloat(q);if(!(isNaN(v)||v===0||!j.trim())){b(!0);try{await x(s,v,j.trim()),await T(s),$(""),w("")}finally{b(!1)}}},B=async()=>{s&&confirm("确定撤销该用户的订阅?")&&(await t(s),await T(s))};return e.jsx(Fe,{open:!!s,onOpenChange:v=>!v&&a(),children:e.jsxs(He,{className:"overflow-y-auto",children:[e.jsx(Qe,{children:e.jsx(Oe,{children:n?`${n.display_name||n.username} 的账单`:"用户详情"})}),f?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ye,{className:"w-6 h-6 animate-spin text-primary"})}):n?e.jsxs("div",{className:"space-y-6 p-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium mb-2",children:[e.jsx(Y,{className:"w-4 h-4 text-primary"}),"当前套餐"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"text-lg font-bold",children:n.plan_name||"无套餐"}),n.is_fallback&&e.jsx("span",{className:"px-1.5 py-0.5 text-xs rounded bg-zinc-100 dark:bg-zinc-700 text-zinc-500",children:"默认"})]}),n.subscription_status&&n.subscription_status!=="default"&&e.jsxs("span",{className:"text-xs text-zinc-400",children:["状态: ",n.subscription_status]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium mb-2",children:[e.jsx(pe,{className:"w-4 h-4 text-primary"}),"余额"]}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:l(n.balance_usd)}),e.jsxs("div",{className:`mt-2 rounded-md border px-3 py-2 text-xs ${n.access_allowed?"border-green-200 bg-green-50 text-green-700 dark:border-green-900/60 dark:bg-green-950/30 dark:text-green-300":"border-red-200 bg-red-50 text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5 font-medium",children:[n.access_allowed?e.jsx($e,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(W,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{children:n.access_allowed?"当前可用":n.access_reason||"当前被计费阻断"})]}),e.jsxs("p",{className:"mt-1 opacity-80",children:["最低起用余额 ",l(n.min_balance_usd??0)]})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium mb-2",children:"用量进度"}),e.jsxs("div",{className:"space-y-3",children:[n.daily_cost_quota!=null&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs text-zinc-500 mb-1",children:[e.jsx("span",{children:"日度费用"}),e.jsxs("span",{children:[l(n.daily_cost_used??0)," /"," ",l(n.daily_cost_quota)]})]}),e.jsx(V,{value:n.daily_cost_used??0,max:n.daily_cost_quota})]}),n.weekly_cost_quota!=null&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs text-zinc-500 mb-1",children:[e.jsx("span",{children:"周度费用"}),e.jsxs("span",{children:[l(n.weekly_cost_used??0)," /"," ",l(n.weekly_cost_quota)]})]}),e.jsx(V,{value:n.weekly_cost_used??0,max:n.weekly_cost_quota})]}),n.monthly_cost_quota!=null&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs text-zinc-500 mb-1",children:[e.jsx("span",{children:"月度费用"}),e.jsxs("span",{children:[l(n.current_month_cost)," /"," ",l(n.monthly_cost_quota)]})]}),e.jsx(V,{value:n.current_month_cost,max:n.monthly_cost_quota})]})]})]}),e.jsxs("div",{className:"space-y-4 pt-2 border-t border-zinc-200 dark:border-zinc-700",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-zinc-500",children:"分配套餐"}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsxs("select",{value:y,onChange:v=>z(v.target.value),className:"flex-1 h-9 px-3 text-sm border border-zinc-300 dark:border-zinc-600 rounded-md bg-transparent",children:[e.jsx("option",{value:"",children:"选择套餐"}),i.map(v=>e.jsx("option",{value:v.id,children:v.name},v.id))]}),e.jsx(S,{size:"sm",onClick:F,disabled:!y||E,children:"确认"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-zinc-500",children:"充值 / 扣减额度"}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsx(N,{type:"number",placeholder:"金额 (正数充值,负数扣减)",value:q,onChange:v=>$(v.target.value),className:"flex-1"}),e.jsx(N,{placeholder:"备注说明",value:j,onChange:v=>w(v.target.value),className:"flex-1"})]}),e.jsx(S,{size:"sm",className:"mt-1",onClick:R,disabled:L,children:"提交资金调整"})]}),n.has_real_subscription&&e.jsxs(S,{variant:"destructive",size:"sm",onClick:B,children:[e.jsx(We,{className:"w-4 h-4"}),"撤销订阅"]})]}),h.length>0&&e.jsxs("div",{className:"pt-2 border-t border-zinc-200 dark:border-zinc-700",children:[e.jsx("div",{className:"text-sm font-medium mb-2",children:"订阅历史"}),e.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:h.map(v=>e.jsxs("div",{className:"flex justify-between text-xs py-1",children:[e.jsx("span",{children:v.plan_name}),e.jsxs("span",{className:"text-zinc-400",children:[v.status," /"," ",new Date(v.started_at).toLocaleDateString()]})]},v.id))})]}),e.jsxs("div",{className:"pt-2 border-t border-zinc-200 dark:border-zinc-700",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium mb-2",children:[e.jsx(qe,{className:"w-4 h-4 text-primary"}),"交易记录"]}),c.length===0?e.jsx("p",{className:"text-xs text-zinc-500",children:"暂无记录"}):e.jsx("div",{className:"space-y-1 max-h-48 overflow-y-auto",children:c.map(v=>e.jsxs("div",{className:"flex justify-between items-center py-1.5 border-b border-zinc-100 dark:border-zinc-700 last:border-0",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs",children:v.description||v.type}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-zinc-400",children:[new Date(v.created_at).toLocaleString(),(v.source||v.type)&&e.jsx("span",{className:"rounded bg-zinc-100 px-1 py-0.5 text-zinc-500 dark:bg-zinc-700 dark:text-zinc-400",children:xs[v.source||""]||v.type})]})]}),e.jsxs("span",{className:`text-xs font-medium ${v.amount_usd>0?"text-green-600":"text-red-500"}`,children:[v.amount_usd>0?"+":"",l(v.amount_usd)]})]},v.id))})]})]}):e.jsx("p",{className:"text-sm text-zinc-500 p-4",children:"无法加载用户信息"})]})})}const us=[{value:"balance",label:"余额充值"},{value:"subscription",label:"套餐激活"},{value:"trial",label:"试用"}];function hs({open:s,onOpenChange:a}){const{createRedeemCodes:i,plans:d,loadAllPlans:x}=D(),t=M();m.useEffect(()=>{s&&d.length===0&&x()},[s,d.length,x]);const[o,l]=m.useState("balance"),[n,_]=m.useState(10),[c,u]=m.useState(""),[h,r]=m.useState(30),[f,k]=m.useState(1),[y,z]=m.useState(""),[E,p]=m.useState(1),[q,$]=m.useState(""),[j,w]=m.useState(""),[L,b]=m.useState(!1),[T,F]=m.useState([]),[R,B]=m.useState(null),v=async()=>{if(f<1||f>100||!Number.isInteger(f)){Q.error("生成数量须为 1-100 之间的整数");return}if(o==="balance"&&(!n||n<=0)){Q.error("余额充值类型须设置正数面值");return}if(o==="subscription"&&!c){Q.error("套餐激活类型须选择套餐");return}if((o==="subscription"||o==="trial")&&h<1){Q.error("有效天数须至少为 1");return}b(!0);try{const g={type:o,count:f,max_uses:E};o==="balance"&&(g.value_usd=n),o==="subscription"&&(g.plan_id=c||void 0,g.duration_days=h),o==="trial"&&(g.duration_days=h),q.trim()&&(g.expires_in_hours=Number(q)),j.trim()&&(g.notes=j.trim()),y.trim()&&(g.prefix=y.trim());const I=await i(g);F(I)}finally{b(!1)}},J=(g,I)=>{navigator.clipboard.writeText(g),B(I),setTimeout(()=>B(null),2e3)},ee=()=>{const g=T.map(I=>I.code).join(`
52
+ `);navigator.clipboard.writeText(g),B(-1),setTimeout(()=>B(null),2e3)},O=g=>{g||(F([]),B(null)),a(g)};return e.jsx(je,{open:s,onOpenChange:O,children:e.jsxs(_e,{className:"sm:max-w-lg",children:[e.jsx(ge,{children:e.jsx(fe,{children:T.length>0?"生成完成":"创建兑换码"})}),T.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-zinc-500",children:["已生成 ",T.length," 个兑换码"]}),e.jsxs(S,{variant:"outline",size:"xs",onClick:ee,children:[R===-1?e.jsx(X,{className:"w-3 h-3 text-green-500"}):e.jsx(ne,{className:"w-3 h-3"}),"复制全部"]})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:T.map((g,I)=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-zinc-50 dark:bg-zinc-900 rounded-md",children:[e.jsx("code",{className:"text-sm font-mono",children:g.code}),e.jsx("button",{onClick:()=>J(g.code,I),className:"p-1 text-zinc-400 hover:text-primary",children:R===I?e.jsx(X,{className:"w-4 h-4 text-green-500"}):e.jsx(ne,{className:"w-4 h-4"})})]},g.code))}),e.jsx(ae,{children:e.jsx(S,{onClick:()=>O(!1),children:"关闭"})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex gap-1 p-1 bg-zinc-100 dark:bg-zinc-900 rounded-md",children:us.map(g=>e.jsx("button",{onClick:()=>l(g.value),className:`flex-1 px-3 py-1.5 text-sm rounded transition-colors ${o===g.value?"bg-white dark:bg-zinc-800 shadow-sm font-medium":"text-zinc-500 hover:text-zinc-700"}`,children:g.label},g.value))}),o==="balance"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-zinc-500 mb-1",children:"面值 (USD)"}),e.jsx(N,{type:"number",step:"0.01",min:0,value:n,onChange:g=>_(Number(g.target.value))}),e.jsxs("span",{className:"text-xs text-zinc-400 mt-1 block",children:["转换后: ",t(n)]})]}),o==="subscription"&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-zinc-500 mb-1",children:"套餐"}),e.jsxs("select",{value:c,onChange:g=>u(g.target.value),className:"w-full h-9 px-3 text-sm border border-zinc-300 dark:border-zinc-600 rounded-md bg-transparent",children:[e.jsx("option",{value:"",children:"选择套餐"}),d.map(g=>e.jsx("option",{value:g.id,children:g.name},g.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-zinc-500 mb-1",children:"有效天数"}),e.jsx(N,{type:"number",min:1,value:h,onChange:g=>r(Number(g.target.value))})]})]}),o==="trial"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-zinc-500 mb-1",children:"试用天数"}),e.jsx(N,{type:"number",min:1,value:h,onChange:g=>r(Number(g.target.value))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-zinc-500 mb-1",children:"生成数量"}),e.jsx(N,{type:"number",min:1,max:100,value:f,onChange:g=>k(Number(g.target.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-zinc-500 mb-1",children:"每码可用次数"}),e.jsx(N,{type:"number",min:1,value:E,onChange:g=>p(Number(g.target.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-zinc-500 mb-1",children:"前缀(可选)"}),e.jsx(N,{value:y,onChange:g=>z(g.target.value.toUpperCase()),placeholder:"如 VIP"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-zinc-500 mb-1",children:"过期时间(小时,留空=不过期)"}),e.jsx(N,{type:"number",min:1,value:q,onChange:g=>$(g.target.value)})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs text-zinc-500 mb-1",children:"备注(可选)"}),e.jsx(N,{value:j,onChange:g=>w(g.target.value),placeholder:"内部备注"})]}),e.jsxs(ae,{children:[e.jsx(S,{variant:"outline",onClick:()=>O(!1),disabled:L,children:"取消"}),e.jsx(S,{onClick:v,disabled:L,children:L?"生成中...":`生成 ${f} 个`})]})]})]})})}const ps={balance:"余额充值",subscription:"套餐激活",trial:"试用"};function bs(){const{redeemCodes:s,loadRedeemCodes:a,deleteRedeemCode:i,exportRedeemCodesCSV:d,getRedeemCodeUsage:x}=D(),t=M(),[o,l]=m.useState("all"),[n,_]=m.useState(""),[c,u]=m.useState(null),[h,r]=m.useState(null),[f,k]=m.useState([]),[y,z]=m.useState(!1),[E,p]=m.useState(!1);m.useEffect(()=>{a()},[a]);const q=m.useMemo(()=>s.filter(b=>!(o!=="all"&&b.type!==o||n&&!b.code.toLowerCase().includes(n.toLowerCase()))),[s,o,n]),$=b=>{navigator.clipboard.writeText(b),u(b),setTimeout(()=>u(null),2e3)},j=async b=>{confirm(`确定删除兑换码 ${b.code}?`)&&await i(b.code)},w=async b=>{if(h===b){r(null);return}r(b),z(!0);try{const T=await x(b);k(T)}catch{k([])}finally{z(!1)}},L=async()=>{try{await d()}catch{alert("导出失败")}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("h3",{className:"font-semibold flex items-center gap-2",children:[e.jsx(Se,{className:"w-5 h-5 text-primary"}),"兑换码管理"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{size:"sm",onClick:()=>p(!0),children:"创建兑换码"}),e.jsxs(S,{variant:"outline",size:"sm",onClick:L,children:[e.jsx(Me,{className:"w-4 h-4"}),"CSV 导出"]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("select",{value:o,onChange:b=>l(b.target.value),className:"h-9 px-3 text-sm border border-zinc-300 dark:border-zinc-600 rounded-md bg-transparent",children:[e.jsx("option",{value:"all",children:"全部类型"}),e.jsx("option",{value:"balance",children:"余额充值"}),e.jsx("option",{value:"subscription",children:"套餐激活"}),e.jsx("option",{value:"trial",children:"试用"})]}),e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ve,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-zinc-400"}),e.jsx(N,{value:n,onChange:b=>_(b.target.value),placeholder:"搜索码值",className:"pl-9"})]})]}),e.jsx("div",{className:"space-y-2",children:q.map(b=>{const T=b.expires_at&&new Date(b.expires_at)<new Date,F=b.used_count>=b.max_uses;return e.jsxs("div",{children:[e.jsxs("div",{className:`flex items-center justify-between p-3 bg-white dark:bg-zinc-800 rounded-lg border border-zinc-200 dark:border-zinc-700 ${T||F?"opacity-60":""}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("code",{className:"text-sm font-mono",children:b.code}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded-full bg-zinc-100 dark:bg-zinc-700 text-zinc-600 dark:text-zinc-400",children:ps[b.type]??b.type}),T&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded-full bg-red-100 text-red-600 dark:bg-red-900/30 dark:text-red-400",children:"已过期"})]}),e.jsxs("div",{className:"text-xs text-zinc-500 mt-0.5 space-x-2",children:[b.type==="balance"&&e.jsxs("span",{children:["面值: ",t(b.value_usd??0)]}),b.type==="subscription"&&e.jsxs("span",{children:["套餐: ",b.plan_id,b.duration_days!=null&&` / ${b.duration_days}天`]}),b.type==="trial"&&b.duration_days!=null&&e.jsxs("span",{children:["试用: ",b.duration_days,"天"]}),e.jsxs("span",{children:["已用 ",b.used_count,"/",b.max_uses]}),b.expires_at&&e.jsxs("span",{children:["过期"," ",new Date(b.expires_at).toLocaleDateString()]}),b.batch_id&&e.jsxs("span",{children:["批次: ",b.batch_id]})]}),b.notes&&e.jsx("div",{className:"text-[10px] text-zinc-400 mt-0.5",children:b.notes})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-2",children:[e.jsx("button",{onClick:()=>w(b.code),className:"p-1.5 text-zinc-400 hover:text-primary",title:"查看使用明细",children:e.jsx(Ae,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>$(b.code),className:"p-1.5 text-zinc-400 hover:text-primary",title:"复制",children:c===b.code?e.jsx(X,{className:"w-4 h-4 text-green-500"}):e.jsx(ne,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>j(b),className:"p-1.5 text-zinc-400 hover:text-red-500",title:"删除",children:e.jsx(be,{className:"w-4 h-4"})})]})]}),h===b.code&&e.jsx("div",{className:"ml-4 mt-1 p-3 bg-zinc-50 dark:bg-zinc-900 rounded-md border border-zinc-200 dark:border-zinc-700",children:y?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-zinc-500",children:[e.jsx(ye,{className:"w-3 h-3 animate-spin"}),"加载中..."]}):f.length===0?e.jsx("p",{className:"text-xs text-zinc-500",children:"暂无使用记录"}):e.jsx("div",{className:"space-y-1",children:f.map((R,B)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{children:["@",R.username]}),e.jsx("span",{className:"text-zinc-400",children:new Date(R.redeemed_at).toLocaleString()})]},B))})})]},b.code)})}),q.length===0&&e.jsx("p",{className:"text-sm text-zinc-500 text-center py-8",children:n||o!=="all"?"未找到匹配的兑换码":"暂无兑换码"}),e.jsx(hs,{open:E,onOpenChange:p})]})}const ue={plan_created:"创建套餐",plan_updated:"更新套餐",plan_deleted:"删除套餐",subscription_assigned:"分配订阅",subscription_cancelled:"取消订阅",subscription_expired:"订阅过期",balance_adjusted:"调整余额",code_created:"创建兑换码",code_redeemed:"使用兑换码",code_deleted:"删除兑换码"},te=20;function js(){const{auditLogs:s,auditLogsTotal:a,loadAuditLog:i,allUsers:d,loadAllUsers:x}=D(),[t,o]=m.useState(""),[l,n]=m.useState(""),[_,c]=m.useState(0),[u,h]=m.useState(null),r=Math.ceil(a/te),f=m.useMemo(()=>{const p=new Map;for(const q of d)p.set(q.user_id,q.display_name||q.username);return p},[d]);m.useEffect(()=>{d.length===0&&x()},[d.length,x]);const k=m.useCallback(()=>{i(te,_*te,l.trim()||void 0,t||void 0)},[i,_,l,t]);m.useEffect(()=>{k()},[k]),m.useEffect(()=>{c(0)},[t,l]);const y=s,z=p=>ue[p]??p,E=Array.from(new Set([...Object.keys(ue),...s.map(p=>p.event_type)])).sort();return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:"font-semibold flex items-center gap-2",children:[e.jsx(we,{className:"w-5 h-5 text-primary"}),"审计日志"]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("select",{value:t,onChange:p=>o(p.target.value),className:"h-9 px-3 text-sm border border-zinc-300 dark:border-zinc-600 rounded-md bg-transparent",children:[e.jsx("option",{value:"",children:"全部事件类型"}),E.map(p=>e.jsx("option",{value:p,children:z(p)},p))]}),e.jsx(N,{value:l,onChange:p=>n(p.target.value),placeholder:"用户 ID 筛选",className:"sm:max-w-[200px]"}),e.jsxs("div",{className:"flex items-center gap-1 ml-auto text-sm text-zinc-500",children:["共 ",a," 条"]})]}),e.jsx("div",{className:"space-y-1",children:y.map(p=>e.jsxs("div",{className:"bg-white dark:bg-zinc-800 rounded-lg border border-zinc-200 dark:border-zinc-700",children:[e.jsxs("button",{onClick:()=>h(u===p.id?null:p.id),className:"w-full flex items-center gap-2 p-3 text-left",children:[u===p.id?e.jsx(Pe,{className:"w-4 h-4 text-zinc-400 shrink-0"}):e.jsx(ce,{className:"w-4 h-4 text-zinc-400 shrink-0"}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded bg-brand-100 text-brand-700 dark:bg-brand-700/30 dark:text-brand-300 shrink-0",children:z(p.event_type)}),e.jsxs("span",{className:"text-sm text-zinc-600 dark:text-zinc-400 truncate flex-1",children:[p.user_id&&e.jsxs("span",{className:"text-zinc-400",children:["用户 ",f.get(p.user_id)??p.user_id.slice(0,8)]}),p.actor_id&&p.actor_id!==p.user_id&&e.jsxs("span",{className:"text-zinc-400 ml-2",children:["操作者 ",f.get(p.actor_id)??p.actor_id.slice(0,8)]})]}),e.jsx("span",{className:"text-xs text-zinc-400 shrink-0",children:new Date(p.created_at).toLocaleString()})]}),u===p.id&&p.details&&e.jsx("div",{className:"px-3 pb-3",children:e.jsx("pre",{className:"text-xs text-zinc-500 bg-zinc-50 dark:bg-zinc-900 rounded-md p-3 overflow-x-auto max-h-48 overflow-y-auto",children:JSON.stringify(p.details,null,2)})})]},p.id))}),y.length===0&&e.jsx("p",{className:"text-sm text-zinc-500 text-center py-8",children:"暂无审计日志"}),r>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2 pt-2",children:[e.jsx(S,{variant:"outline",size:"icon-xs",onClick:()=>c(0),disabled:_===0,children:e.jsx(Ve,{className:"w-4 h-4"})}),e.jsx(S,{variant:"outline",size:"icon-xs",onClick:()=>c(p=>Math.max(0,p-1)),disabled:_===0,children:e.jsx(Ue,{className:"w-4 h-4"})}),e.jsxs("span",{className:"text-sm text-zinc-500",children:[_+1," / ",r]}),e.jsx(S,{variant:"outline",size:"icon-xs",onClick:()=>c(p=>Math.min(r-1,p+1)),disabled:_>=r-1,children:e.jsx(ce,{className:"w-4 h-4"})})]})]})}function ks(){const s=Be(y=>y.user),a=D(y=>y.billingEnabled),i=D(y=>y.billingStatusLoaded),d=D(y=>y.loadBillingStatus),x=(s==null?void 0:s.role)==="admin",[t,o]=m.useState("overview"),[l,n]=m.useState(!1),[_,c]=m.useState(null),[u,h]=m.useState(null);if(m.useEffect(()=>{i||d()},[i,d]),!i)return e.jsx("div",{className:"h-full p-6 text-sm text-zinc-500",children:"加载账单状态中..."});if(!a)return e.jsx(Ie,{to:"/chat",replace:!0});const r=[{key:"overview",label:"概览",icon:le},{key:"pricing",label:"套餐对比",icon:Ne}],f=x?[{key:"dashboard",label:"仪表盘",icon:Ye},{key:"plans",label:"套餐管理",icon:Y},{key:"users",label:"用户管理",icon:K},{key:"redeem",label:"兑换码",icon:Se},{key:"audit",label:"审计",icon:we}]:[],k=[...r,...f];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white dark:bg-zinc-900 border-b border-zinc-200 dark:border-zinc-800 px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-4 overflow-x-auto",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2 shrink-0",children:[e.jsx(le,{className:"w-5 h-5 text-primary"}),"账单"]}),e.jsx("div",{className:"flex gap-1",children:k.map(({key:y,label:z,icon:E})=>e.jsxs("button",{onClick:()=>o(y),className:`flex cursor-pointer items-center gap-1.5 px-3 py-1.5 text-sm rounded-md transition-colors whitespace-nowrap ${t===y?"bg-brand-50 dark:bg-brand-700/20 text-brand-700 dark:text-brand-300":"text-zinc-500 hover:bg-zinc-100 dark:hover:bg-zinc-800"}`,children:[e.jsx(E,{className:"w-4 h-4"}),z]},y))})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 lg:p-6 space-y-6",children:[t==="overview"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(Xe,{}),e.jsx(Ze,{}),e.jsx(Ke,{})]}),e.jsx(Je,{}),e.jsx(ss,{})]}),t==="pricing"&&e.jsx(as,{}),t==="dashboard"&&x&&e.jsx(rs,{}),t==="plans"&&x&&e.jsx(is,{onEditPlan:y=>{c(y),n(!0)},onCreatePlan:()=>{c(null),n(!0)}}),t==="users"&&x&&e.jsx(os,{onSelectUser:h}),t==="redeem"&&x&&e.jsx(bs,{}),t==="audit"&&x&&e.jsx(js,{})]}),e.jsx(ds,{open:l,onOpenChange:n,plan:_}),e.jsx(ms,{userId:u,onClose:()=>h(null)})]})}export{ks as default};
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright (c) 2014 The xterm.js authors. All rights reserved.
3
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
4
+ * https://github.com/chjj/term.js
5
+ * @license MIT
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ *
25
+ * Originally forked from (with the author's permission):
26
+ * Fabrice Bellard's javascript vt100 for jslinux:
27
+ * http://bellard.org/jslinux/
28
+ * Copyright (c) 2011 Fabrice Bellard
29
+ * The original design remains. The terminal itself
30
+ * has been extended to include xterm CSI codes, among
31
+ * other features.
32
+ */.xterm{cursor:text;position:relative;user-select:none;-ms-user-select:none;-webkit-user-select:none}.xterm.focus,.xterm:focus{outline:none}.xterm .xterm-helpers{position:absolute;top:0;z-index:5}.xterm .xterm-helper-textarea{padding:0;border:0;margin:0;position:absolute;opacity:0;left:-9999em;top:0;width:0;height:0;z-index:-5;white-space:nowrap;overflow:hidden;resize:none}.xterm .composition-view{background:#000;color:#fff;display:none;position:absolute;white-space:nowrap;z-index:1}.xterm .composition-view.active{display:block}.xterm .xterm-viewport{background-color:#000;overflow-y:scroll;cursor:default;position:absolute;right:0;left:0;top:0;bottom:0}.xterm .xterm-screen{position:relative}.xterm .xterm-screen canvas{position:absolute;left:0;top:0}.xterm-char-measure-element{display:inline-block;visibility:hidden;position:absolute;top:0;left:-9999em;line-height:normal}.xterm.enable-mouse-events{cursor:default}.xterm.xterm-cursor-pointer,.xterm .xterm-cursor-pointer{cursor:pointer}.xterm.column-select.focus{cursor:crosshair}.xterm .xterm-accessibility:not(.debug),.xterm .xterm-message{position:absolute;left:0;top:0;bottom:0;right:0;z-index:10;color:transparent;pointer-events:none}.xterm .xterm-accessibility-tree:not(.debug) *::selection{color:transparent}.xterm .xterm-accessibility-tree{font-family:monospace;-webkit-user-select:text;user-select:text;white-space:pre}.xterm .xterm-accessibility-tree>div{transform-origin:left;width:fit-content}.xterm .live-region{position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden}.xterm-dim{opacity:1!important}.xterm-underline-1{text-decoration:underline}.xterm-underline-2{text-decoration:double underline}.xterm-underline-3{text-decoration:wavy underline}.xterm-underline-4{text-decoration:dotted underline}.xterm-underline-5{text-decoration:dashed underline}.xterm-overline{text-decoration:overline}.xterm-overline.xterm-underline-1{text-decoration:overline underline}.xterm-overline.xterm-underline-2{text-decoration:overline double underline}.xterm-overline.xterm-underline-3{text-decoration:overline wavy underline}.xterm-overline.xterm-underline-4{text-decoration:overline dotted underline}.xterm-overline.xterm-underline-5{text-decoration:overline dashed underline}.xterm-strikethrough{text-decoration:line-through}.xterm-screen .xterm-decoration-container .xterm-decoration{z-index:6;position:absolute}.xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer{z-index:7}.xterm-decoration-overview-ruler{z-index:8;position:absolute;top:0;right:0;pointer-events:none}.xterm-decoration-top{z-index:2;position:relative}.xterm .xterm-scrollable-element>.scrollbar{cursor:default}.xterm .xterm-scrollable-element>.scrollbar>.scra{cursor:pointer;font-size:11px!important}.xterm .xterm-scrollable-element>.visible{opacity:1;background:#0000;transition:opacity .1s linear;z-index:11}.xterm .xterm-scrollable-element>.invisible{opacity:0;pointer-events:none}.xterm .xterm-scrollable-element>.invisible.fade{transition:opacity .8s linear}.xterm .xterm-scrollable-element>.shadow{position:absolute;display:none}.xterm .xterm-scrollable-element>.shadow.top{display:block;top:0;left:3px;height:3px;width:100%;box-shadow:var(--vscode-scrollbar-shadow, #000) 0 6px 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.left{display:block;top:3px;left:0;height:100%;width:3px;box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}.xterm .xterm-scrollable-element>.shadow.top-left-corner{display:block;top:0;left:0;height:3px;width:3px}.xterm .xterm-scrollable-element>.shadow.top.left{box-shadow:var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset}