@tbox.cn/app-template-agent 0.10.37 → 1.0.0-alpha.10

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 (455) hide show
  1. package/._.gitignore +0 -0
  2. package/._.nvmrc +0 -0
  3. package/._AGENTS.md +0 -0
  4. package/._ENV.md +0 -0
  5. package/._LEGAL.md +0 -0
  6. package/._LICENSE +0 -0
  7. package/._README.md +0 -0
  8. package/._eslint.config.mjs +0 -0
  9. package/._package.json +0 -0
  10. package/._pnpm-lock.template.yaml +0 -0
  11. package/._pnpm-workspace.template.yaml +0 -0
  12. package/._tsconfig.base.json +0 -0
  13. package/.gitignore +14 -2
  14. package/.tbox/._app.json +0 -0
  15. package/.tbox/._default-modules.json +0 -0
  16. package/.tbox/._miniapp-containers.json +0 -0
  17. package/.tbox/app.json +3 -19
  18. package/.tbox/default-modules.json +4 -1
  19. package/.tbox/factory/._chat.json +0 -0
  20. package/.tbox/factory/chat.json +9 -0
  21. package/.tbox/miniapp-containers.json +1 -1
  22. package/AGENTS.md +96 -148
  23. package/ENV.md +4 -4
  24. package/README.md +31 -27
  25. package/apps/._AGENTS.md +0 -0
  26. package/apps/AGENTS.md +9 -0
  27. package/apps/client/._index.html +0 -0
  28. package/apps/client/._package.json +0 -0
  29. package/apps/client/._tsconfig.json +0 -0
  30. package/apps/client/._vite.config.ts +0 -0
  31. package/apps/client/index.html +1 -20
  32. package/apps/client/package.json +7 -5
  33. package/apps/client/scripts/._acceptance-changes.test.mjs +0 -0
  34. package/apps/client/scripts/._check-evidence.mjs +0 -0
  35. package/apps/client/scripts/._color-scan.mjs +0 -0
  36. package/apps/client/scripts/._color-scan.test.mjs +0 -0
  37. package/apps/client/scripts/._evidence-gate.mjs +0 -0
  38. package/apps/client/scripts/._evidence-gate.test.mjs +0 -0
  39. package/apps/client/scripts/._experience-checks.mjs +0 -0
  40. package/apps/client/scripts/._geometry-kernel.test.mjs +0 -0
  41. package/apps/client/scripts/._in-process-checks.mjs +0 -0
  42. package/apps/client/scripts/._probe-checks.mjs +0 -0
  43. package/apps/client/scripts/._render-card.mjs +0 -0
  44. package/apps/client/scripts/._sample-entries.test.mjs +0 -0
  45. package/apps/client/scripts/._storyboard.test.mjs +0 -0
  46. package/apps/client/scripts/._surface-css.mjs +0 -0
  47. package/apps/client/scripts/._theme-kernel.mjs +0 -0
  48. package/apps/client/scripts/._theme-kernel.test.mjs +0 -0
  49. package/apps/client/scripts/acceptance-changes.test.mjs +97 -0
  50. package/apps/client/scripts/check-evidence.mjs +1402 -0
  51. package/apps/client/scripts/color-scan.mjs +66 -0
  52. package/apps/client/scripts/color-scan.test.mjs +25 -0
  53. package/apps/client/scripts/evidence-gate.mjs +337 -0
  54. package/apps/client/scripts/evidence-gate.test.mjs +135 -0
  55. package/apps/client/scripts/experience-checks.mjs +163 -0
  56. package/apps/client/scripts/geometry-kernel.test.mjs +92 -0
  57. package/apps/client/scripts/in-process-checks.mjs +51 -0
  58. package/apps/client/scripts/lib/._card-registry.mjs +0 -0
  59. package/apps/client/scripts/lib/._card-registry.test.mjs +0 -0
  60. package/apps/client/scripts/lib/._evidence-inputs.mjs +0 -0
  61. package/apps/client/scripts/lib/._evidence-inputs.test.mjs +0 -0
  62. package/apps/client/scripts/lib/._static-render.mjs +0 -0
  63. package/apps/client/scripts/lib/._static-render.test.mjs +0 -0
  64. package/apps/client/scripts/lib/card-registry.mjs +81 -0
  65. package/apps/client/scripts/lib/card-registry.test.mjs +59 -0
  66. package/apps/client/scripts/lib/evidence-inputs.mjs +91 -0
  67. package/apps/client/scripts/lib/evidence-inputs.test.mjs +27 -0
  68. package/apps/client/scripts/lib/static-render.mjs +35 -0
  69. package/apps/client/scripts/lib/static-render.test.mjs +21 -0
  70. package/apps/client/scripts/probe-checks.mjs +85 -0
  71. package/apps/client/scripts/render-card.mjs +710 -0
  72. package/apps/client/scripts/sample-entries.test.mjs +31 -0
  73. package/apps/client/scripts/storyboard.test.mjs +149 -0
  74. package/apps/client/scripts/surface-css.mjs +55 -0
  75. package/apps/client/scripts/theme-kernel.mjs +236 -0
  76. package/apps/client/scripts/theme-kernel.test.mjs +136 -0
  77. package/apps/client/src/._app.config.ts +0 -0
  78. package/apps/client/src/._vite-env.d.ts +0 -0
  79. package/apps/client/src/app.config.ts +43 -0
  80. package/apps/client/src/cards/._AGENTS.md +0 -0
  81. package/apps/client/src/cards/._registry.ts +0 -0
  82. package/apps/client/src/cards/AGENTS.md +11 -0
  83. package/apps/client/src/cards/registry.ts +6 -19
  84. package/apps/client/src/pages/._page.tsx +0 -0
  85. package/apps/client/src/pages/index/._index.tsx +0 -0
  86. package/apps/client/src/pages/index/index.tsx +1 -1
  87. package/apps/client/src/pages/page.tsx +11 -0
  88. package/apps/client/src/store/._chat.ts +0 -0
  89. package/apps/client/src/store/chat.ts +7 -3
  90. package/apps/client/src/styles/._brand.css +0 -0
  91. package/apps/client/src/styles/._tailwind.css +0 -0
  92. package/apps/client/src/styles/brand.css +50 -0
  93. package/apps/client/src/styles/tailwind.css +326 -0
  94. package/apps/client/src/test/._setup.ts +0 -0
  95. package/apps/client/src/vite-env.d.ts +0 -2
  96. package/apps/client/vite.config.ts +7 -53
  97. package/apps/server/._package.json +0 -0
  98. package/apps/server/._tsconfig.json +0 -0
  99. package/apps/server/._tsup.config.ts +0 -0
  100. package/apps/server/._vitest.config.ts +0 -0
  101. package/apps/server/package.json +1 -1
  102. package/apps/server/scripts/._probe.mjs +0 -0
  103. package/apps/server/scripts/._scenario-lib.mjs +0 -0
  104. package/apps/server/scripts/._scenario.mjs +0 -0
  105. package/apps/server/scripts/probe.mjs +387 -0
  106. package/apps/server/scripts/scenario-lib.mjs +295 -0
  107. package/apps/server/scripts/scenario.mjs +67 -0
  108. package/apps/server/src/._app.ts +0 -0
  109. package/apps/server/src/._dev.ts +0 -0
  110. package/apps/server/src/._index.ts +0 -0
  111. package/apps/server/src/._intent-routes.ts +0 -0
  112. package/apps/server/src/._pre-tools.ts +0 -0
  113. package/apps/server/src/app.ts +17 -17
  114. package/apps/server/src/cards/._AGENTS.md +0 -0
  115. package/apps/server/src/cards/AGENTS.md +19 -0
  116. package/apps/server/src/cli/._collect-registry.ts +0 -0
  117. package/apps/server/src/cli/._plugin-doctor.ts +0 -0
  118. package/apps/server/src/cli/._plugin-inspect.ts +0 -0
  119. package/apps/server/src/cli/collect-registry.ts +7 -11
  120. package/apps/server/src/config/._integration.ts +0 -0
  121. package/apps/server/src/dev.ts +38 -64
  122. package/apps/server/src/index.ts +27 -45
  123. package/apps/server/src/pre-tools.ts +7 -16
  124. package/apps/server/src/tools/._AGENTS.md +0 -0
  125. package/apps/server/src/tools/AGENTS.md +23 -0
  126. package/apps/server/tests/._agent-prompt.test.ts +0 -0
  127. package/apps/server/tests/._cards-registry.test.ts +0 -0
  128. package/apps/server/tests/._deployment-loader.test.ts +0 -0
  129. package/apps/server/tests/._intent-dispatcher.test.ts +0 -0
  130. package/apps/server/tests/._tool-runtime.test.ts +0 -0
  131. package/apps/server/tests/cards-registry.test.ts +1 -1
  132. package/apps/server/tests/helpers/._register.ts +0 -0
  133. package/apps/server/tests/helpers/register.ts +10 -0
  134. package/apps/server/tests/tool-runtime.test.ts +1 -28
  135. package/apps/server/tsconfig.json +1 -1
  136. package/apps/server/tsup.config.ts +6 -3
  137. package/config/._AGENTS.md +0 -0
  138. package/config/._README.md +0 -0
  139. package/config/._chat.json +0 -0
  140. package/config/._integrations.json +0 -0
  141. package/config/._llm_provider.json +0 -0
  142. package/config/._plugins.json +0 -0
  143. package/config/AGENTS.md +14 -0
  144. package/config/README.md +4 -4
  145. package/config/chat.json +25 -7
  146. package/config/integrations.json +1 -1
  147. package/docs/agent/._agent-prompt.md +0 -0
  148. package/docs/agent/._card-action.md +0 -0
  149. package/docs/agent/._card.md +0 -0
  150. package/docs/agent/._conversation.md +0 -0
  151. package/docs/agent/._kit.md +0 -0
  152. package/docs/agent/._shell.md +0 -0
  153. package/docs/agent/._state.md +0 -0
  154. package/docs/agent/._style.md +0 -0
  155. package/docs/agent/._tool-emits-card.md +0 -0
  156. package/docs/agent/._tool.md +0 -0
  157. package/docs/agent/._verify.md +0 -0
  158. package/docs/agent/agent-prompt.md +38 -0
  159. package/docs/agent/card-action.md +101 -0
  160. package/docs/agent/card.md +159 -0
  161. package/docs/agent/conversation.md +52 -0
  162. package/docs/agent/kit.md +80 -0
  163. package/docs/agent/shell.md +77 -0
  164. package/docs/agent/state.md +85 -0
  165. package/docs/agent/style.md +107 -0
  166. package/docs/agent/tool-emits-card.md +62 -0
  167. package/docs/agent/tool.md +71 -0
  168. package/docs/agent/verify.md +188 -0
  169. package/eslint.config.mjs +18 -0
  170. package/modules/provider-custom/._AGENTS.md +0 -0
  171. package/modules/provider-custom/._INTEGRATION.md +0 -0
  172. package/modules/provider-custom/._LICENSE +0 -0
  173. package/modules/provider-custom/._README.md +0 -0
  174. package/modules/provider-custom/._package.json +0 -0
  175. package/modules/provider-custom/._tbox.module.json +0 -0
  176. package/modules/provider-custom/._tsconfig.json +0 -0
  177. package/modules/provider-custom/._tsup.config.ts +0 -0
  178. package/{packages → modules}/provider-custom/AGENTS.md +6 -6
  179. package/modules/provider-custom/INTEGRATION.md +10 -0
  180. package/{packages → modules}/provider-custom/package.json +1 -0
  181. package/modules/provider-custom/src/._index.ts +0 -0
  182. package/modules/provider-custom/src/server/._example-adapter.ts +0 -0
  183. package/modules/provider-custom/src/server/._index.ts +0 -0
  184. package/{packages → modules}/provider-custom/src/server/example-adapter.ts +2 -2
  185. package/{packages → modules}/provider-custom/src/server/index.ts +1 -1
  186. package/modules/provider-custom/tests/._provider-custom.test.ts +0 -0
  187. package/package.json +38 -7
  188. package/packages/agent-ui-kit/._AGENTS.md +0 -0
  189. package/packages/agent-ui-kit/._LICENSE +0 -0
  190. package/packages/agent-ui-kit/._README.md +0 -0
  191. package/packages/agent-ui-kit/._catalog.json +0 -0
  192. package/packages/agent-ui-kit/._package.json +0 -0
  193. package/packages/agent-ui-kit/._tsconfig.json +0 -0
  194. package/packages/agent-ui-kit/._vitest.config.ts +0 -0
  195. package/packages/agent-ui-kit/AGENTS.md +8 -0
  196. package/packages/agent-ui-kit/README.md +59 -6
  197. package/packages/agent-ui-kit/assets/._keyboard-circle.svg +0 -0
  198. package/packages/agent-ui-kit/assets/._more-circle.svg +0 -0
  199. package/packages/agent-ui-kit/assets/._new-chat.svg +0 -0
  200. package/packages/agent-ui-kit/assets/._quick-command-star.svg +0 -0
  201. package/packages/agent-ui-kit/assets/._send-gradient.svg +0 -0
  202. package/packages/agent-ui-kit/assets/._stop@2x.png +0 -0
  203. package/packages/agent-ui-kit/assets/._voice-circle.svg +0 -0
  204. package/packages/agent-ui-kit/catalog.json +855 -0
  205. package/packages/agent-ui-kit/package.json +24 -9
  206. package/packages/agent-ui-kit/src/._ChatPage.tsx +0 -0
  207. package/packages/agent-ui-kit/src/._chat-config.test.ts +0 -0
  208. package/packages/agent-ui-kit/src/._chat-config.ts +0 -0
  209. package/packages/agent-ui-kit/src/._icons.ts +0 -0
  210. package/packages/agent-ui-kit/src/._index.ts +0 -0
  211. package/packages/agent-ui-kit/src/._preview-provider.tsx +0 -0
  212. package/packages/agent-ui-kit/src/._shell.contract.json +0 -0
  213. package/packages/agent-ui-kit/src/._shell.test.ts +0 -0
  214. package/packages/agent-ui-kit/src/._shell.ts +0 -0
  215. package/packages/agent-ui-kit/src/._store-context.tsx +0 -0
  216. package/packages/agent-ui-kit/src/._surface.test.tsx +0 -0
  217. package/packages/agent-ui-kit/src/._surface.tsx +0 -0
  218. package/packages/agent-ui-kit/src/._types.ts +0 -0
  219. package/packages/agent-ui-kit/src/._vite-env.d.ts +0 -0
  220. package/packages/agent-ui-kit/src/ChatPage.tsx +115 -20
  221. package/packages/agent-ui-kit/src/card/._action-list-pending.test.tsx +0 -0
  222. package/packages/agent-ui-kit/src/card/._define-card.test.ts +0 -0
  223. package/packages/agent-ui-kit/src/card/._define-card.ts +0 -0
  224. package/packages/agent-ui-kit/src/card/._primitives.test.tsx +0 -0
  225. package/packages/agent-ui-kit/src/card/._primitives.tsx +0 -0
  226. package/packages/agent-ui-kit/src/card/._use-card-actions.ts +0 -0
  227. package/packages/agent-ui-kit/src/card/._view-card-inline.test.tsx +0 -0
  228. package/packages/agent-ui-kit/src/card/._view-card.test.tsx +0 -0
  229. package/packages/agent-ui-kit/src/card/._view-card.tsx +0 -0
  230. package/packages/agent-ui-kit/src/card/action-list-pending.test.tsx +91 -0
  231. package/packages/agent-ui-kit/src/card/define-card.test.ts +25 -0
  232. package/packages/agent-ui-kit/src/card/define-card.ts +47 -0
  233. package/packages/agent-ui-kit/src/card/primitives.test.tsx +157 -0
  234. package/packages/agent-ui-kit/src/card/primitives.tsx +717 -0
  235. package/packages/agent-ui-kit/src/card/use-card-actions.ts +86 -0
  236. package/packages/agent-ui-kit/src/card/view-card-inline.test.tsx +42 -0
  237. package/packages/agent-ui-kit/src/card/view-card.test.tsx +79 -0
  238. package/packages/agent-ui-kit/src/card/view-card.tsx +250 -0
  239. package/packages/agent-ui-kit/src/chat-config.test.ts +35 -71
  240. package/packages/agent-ui-kit/src/chat-config.ts +29 -7
  241. package/packages/agent-ui-kit/src/components/._CardRenderer.tsx +0 -0
  242. package/packages/agent-ui-kit/src/components/ActionBar/._DebugButton.test.tsx +0 -0
  243. package/packages/agent-ui-kit/src/components/ActionBar/._DebugButton.tsx +0 -0
  244. package/packages/agent-ui-kit/src/components/ActionBar/._index.test.tsx +0 -0
  245. package/packages/agent-ui-kit/src/components/ActionBar/._index.tsx +0 -0
  246. package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.test.tsx +3 -0
  247. package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.tsx +5 -10
  248. package/packages/agent-ui-kit/src/components/ActionBar/index.tsx +13 -14
  249. package/packages/agent-ui-kit/src/components/BottomSheet/._index.test.tsx +0 -0
  250. package/packages/agent-ui-kit/src/components/BottomSheet/._index.tsx +0 -0
  251. package/packages/agent-ui-kit/src/components/BottomSheet/index.test.tsx +97 -0
  252. package/packages/agent-ui-kit/src/components/BottomSheet/index.tsx +49 -0
  253. package/packages/agent-ui-kit/src/components/ChatHeader/._index.test.tsx +0 -0
  254. package/packages/agent-ui-kit/src/components/ChatHeader/._index.tsx +0 -0
  255. package/packages/agent-ui-kit/src/components/ChatHeader/index.tsx +19 -17
  256. package/packages/agent-ui-kit/src/components/ChatInput/._index.test.tsx +0 -0
  257. package/packages/agent-ui-kit/src/components/ChatInput/._index.tsx +0 -0
  258. package/packages/agent-ui-kit/src/components/ChatInput/index.test.tsx +2 -2
  259. package/packages/agent-ui-kit/src/components/ChatInput/index.tsx +44 -33
  260. package/packages/agent-ui-kit/src/components/ChatInput/voice/._VoicePressField.tsx +0 -0
  261. package/packages/agent-ui-kit/src/components/ChatInput/voice/._VoiceRecordingOverlay.tsx +0 -0
  262. package/packages/agent-ui-kit/src/components/ChatInput/voice/._machine.ts +0 -0
  263. package/packages/agent-ui-kit/src/components/ChatInput/voice/._useVoicePress.ts +0 -0
  264. package/packages/agent-ui-kit/src/components/ChatInput/voice/VoicePressField.tsx +12 -3
  265. package/packages/agent-ui-kit/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +9 -9
  266. package/packages/agent-ui-kit/src/components/ChatInput/voice/useVoicePress.ts +1 -1
  267. package/packages/agent-ui-kit/src/components/HistoryEntry/._index.tsx +0 -0
  268. package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +4 -4
  269. package/packages/agent-ui-kit/src/components/MediaList/._index.tsx +0 -0
  270. package/packages/agent-ui-kit/src/components/MediaList/index.tsx +42 -28
  271. package/packages/agent-ui-kit/src/components/MessageBubble/._index.test.tsx +0 -0
  272. package/packages/agent-ui-kit/src/components/MessageBubble/._index.tsx +0 -0
  273. package/packages/agent-ui-kit/src/components/MessageBubble/index.tsx +59 -28
  274. package/packages/agent-ui-kit/src/components/PullDownIndicator/._index.tsx +0 -0
  275. package/packages/agent-ui-kit/src/components/PullDownIndicator/index.tsx +3 -4
  276. package/packages/agent-ui-kit/src/components/QuickCommands/._index.test.tsx +0 -0
  277. package/packages/agent-ui-kit/src/components/QuickCommands/._index.tsx +0 -0
  278. package/packages/agent-ui-kit/src/components/QuickCommands/index.test.tsx +3 -1
  279. package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +33 -10
  280. package/packages/agent-ui-kit/src/components/ReasoningBlock/._index.tsx +0 -0
  281. package/packages/agent-ui-kit/src/components/ReasoningBlock/index.tsx +14 -9
  282. package/packages/agent-ui-kit/src/components/ScrollToBottomButton/._index.tsx +0 -0
  283. package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.tsx +7 -5
  284. package/packages/agent-ui-kit/src/components/ToolCallBlock/._detail.test.ts +0 -0
  285. package/packages/agent-ui-kit/src/components/ToolCallBlock/._detail.ts +0 -0
  286. package/packages/agent-ui-kit/src/components/ToolCallBlock/._index.test.tsx +0 -0
  287. package/packages/agent-ui-kit/src/components/ToolCallBlock/._index.tsx +0 -0
  288. package/packages/agent-ui-kit/src/components/ToolCallBlock/._titles.ts +0 -0
  289. package/packages/agent-ui-kit/src/components/ToolCallBlock/index.tsx +58 -38
  290. package/packages/agent-ui-kit/src/hooks/._use-drag-gesture.test.ts +0 -0
  291. package/packages/agent-ui-kit/src/hooks/._use-drag-gesture.ts +0 -0
  292. package/packages/agent-ui-kit/src/hooks/._use-pull-down-history.ts +0 -0
  293. package/packages/agent-ui-kit/src/hooks/._use-pull-down-wheel-native.test.ts +0 -0
  294. package/packages/agent-ui-kit/src/hooks/._useMediaUpload.ts +0 -0
  295. package/packages/agent-ui-kit/src/hooks/._useTTSAutoPlay.ts +0 -0
  296. package/packages/agent-ui-kit/src/icons.ts +39 -0
  297. package/packages/agent-ui-kit/src/index.ts +76 -2
  298. package/packages/agent-ui-kit/src/overlay/._Overlay.tsx +0 -0
  299. package/packages/agent-ui-kit/src/overlay/._focus.ts +0 -0
  300. package/packages/agent-ui-kit/src/overlay/._index.ts +0 -0
  301. package/packages/agent-ui-kit/src/overlay/._inert.ts +0 -0
  302. package/packages/agent-ui-kit/src/overlay/._layers.ts +0 -0
  303. package/packages/agent-ui-kit/src/overlay/._overlay.ssr.test.tsx +0 -0
  304. package/packages/agent-ui-kit/src/overlay/._overlay.test.tsx +0 -0
  305. package/packages/agent-ui-kit/src/overlay/._presence.ts +0 -0
  306. package/packages/agent-ui-kit/src/overlay/._scroll-lock.ts +0 -0
  307. package/packages/agent-ui-kit/src/overlay/._stack.ts +0 -0
  308. package/packages/agent-ui-kit/src/overlay/._use-overlay.ts +0 -0
  309. package/packages/agent-ui-kit/src/overlay/Overlay.tsx +154 -0
  310. package/packages/agent-ui-kit/src/overlay/focus.ts +53 -0
  311. package/packages/agent-ui-kit/src/overlay/index.ts +16 -0
  312. package/packages/agent-ui-kit/src/overlay/inert.ts +27 -0
  313. package/packages/agent-ui-kit/src/overlay/layers.ts +21 -0
  314. package/packages/agent-ui-kit/src/overlay/overlay.ssr.test.tsx +27 -0
  315. package/packages/agent-ui-kit/src/overlay/overlay.test.tsx +209 -0
  316. package/packages/agent-ui-kit/src/overlay/presence.ts +86 -0
  317. package/packages/agent-ui-kit/src/overlay/scroll-lock.ts +62 -0
  318. package/packages/agent-ui-kit/src/overlay/stack.ts +111 -0
  319. package/packages/agent-ui-kit/src/overlay/use-overlay.ts +80 -0
  320. package/packages/agent-ui-kit/src/preview-provider.tsx +47 -0
  321. package/packages/agent-ui-kit/src/shell.contract.json +75 -0
  322. package/packages/agent-ui-kit/src/shell.test.ts +72 -0
  323. package/packages/agent-ui-kit/src/shell.ts +60 -0
  324. package/packages/agent-ui-kit/src/surface.test.tsx +35 -0
  325. package/packages/agent-ui-kit/src/surface.tsx +44 -0
  326. package/packages/agent-ui-kit/src/test/._setup.ts +0 -0
  327. package/packages/agent-ui-kit/src/theme/._base.css +0 -0
  328. package/packages/agent-ui-kit/src/theme/._contract.json +0 -0
  329. package/packages/agent-ui-kit/src/theme/._motion.css +0 -0
  330. package/packages/agent-ui-kit/src/theme/._theme-contract.test.ts +0 -0
  331. package/packages/agent-ui-kit/src/theme/._theme.ts +0 -0
  332. package/packages/agent-ui-kit/src/theme/._tokens.css +0 -0
  333. package/packages/agent-ui-kit/src/theme/base.css +167 -0
  334. package/packages/agent-ui-kit/src/theme/contract.json +123 -2
  335. package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +19 -3
  336. package/packages/agent-ui-kit/src/theme/{tokens.less → tokens.css} +19 -20
  337. package/packages/agent-ui-kit/src/utils/._copyText.ts +0 -0
  338. package/packages/agent-ui-kit/src/utils/._haptics.test.ts +0 -0
  339. package/packages/agent-ui-kit/src/utils/._haptics.ts +0 -0
  340. package/packages/agent-ui-kit/src/utils/._image-preview-host.tsx +0 -0
  341. package/packages/agent-ui-kit/src/utils/._imagePreview.test.ts +0 -0
  342. package/packages/agent-ui-kit/src/utils/._imagePreview.ts +0 -0
  343. package/packages/agent-ui-kit/src/utils/._pull-down-machine.test.ts +0 -0
  344. package/packages/agent-ui-kit/src/utils/._pull-down-machine.ts +0 -0
  345. package/packages/agent-ui-kit/src/utils/._session-error.ts +0 -0
  346. package/packages/agent-ui-kit/src/utils/._toast.test.ts +0 -0
  347. package/packages/agent-ui-kit/src/utils/._toast.ts +0 -0
  348. package/packages/agent-ui-kit/src/utils/._tool-call-display.test.ts +0 -0
  349. package/packages/agent-ui-kit/src/utils/._tool-call-display.ts +0 -0
  350. package/packages/agent-ui-kit/src/utils/image-preview-host.tsx +95 -0
  351. package/packages/agent-ui-kit/src/utils/imagePreview.test.ts +32 -0
  352. package/packages/agent-ui-kit/src/utils/imagePreview.ts +14 -5
  353. package/packages/agent-ui-kit/src/utils/toast.test.ts +64 -0
  354. package/packages/agent-ui-kit/src/utils/toast.ts +100 -7
  355. package/packages/contracts-mall/._package.json +0 -0
  356. package/packages/contracts-mall/._tsconfig.json +0 -0
  357. package/packages/contracts-mall/src/._index.ts +0 -0
  358. package/packages/contracts-mall/src/._runtime.ts +0 -0
  359. package/packages/contracts-mall/src/server/._index.ts +0 -0
  360. package/packages/shared/._AGENTS.md +0 -0
  361. package/packages/shared/._package.json +0 -0
  362. package/packages/shared/._tsconfig.json +0 -0
  363. package/packages/shared/AGENTS.md +13 -0
  364. package/packages/shared/package.json +20 -0
  365. package/packages/shared/src/._index.ts +0 -0
  366. package/packages/shared/src/index.ts +8 -0
  367. package/packages/shared/tsconfig.json +7 -0
  368. package/pnpm-lock.template.yaml +781 -846
  369. package/pnpm-workspace.template.yaml +19 -11
  370. package/profiles/._mall.json +0 -0
  371. package/profiles/mall/._TEMPLATE.md +0 -0
  372. package/profiles/mall/._chat.overrides.json +0 -0
  373. package/profiles/mall/chat.overrides.json +12 -0
  374. package/profiles/mall/config/._agent.jsonc +0 -0
  375. package/profiles/mall/config/._chat.json +0 -0
  376. package/profiles/mall/config/._knowledge.json +0 -0
  377. package/profiles/mall/config/chat.json +14 -6
  378. package/profiles/mall.json +2 -2
  379. package/scenarios/._README.md +0 -0
  380. package/scenarios/README.md +7 -0
  381. package/scripts/._assert-pack.mjs +0 -0
  382. package/scripts/._build.sh +0 -0
  383. package/scripts/._check-css-target.mjs +0 -0
  384. package/scripts/._check-fast.mjs +0 -0
  385. package/scripts/._check-workspace.mjs +0 -0
  386. package/scripts/._checks.json +0 -0
  387. package/scripts/._deliver.mjs +0 -0
  388. package/scripts/._dev-alipay.mjs +0 -0
  389. package/scripts/._dev.sh +0 -0
  390. package/scripts/._generate.mjs +0 -0
  391. package/scripts/._prepare.sh +0 -0
  392. package/scripts/._shell-probe.mjs +0 -0
  393. package/scripts/._smoke.mjs +0 -0
  394. package/scripts/._start.sh +0 -0
  395. package/scripts/._stop.sh +0 -0
  396. package/scripts/._storyboard.mjs +0 -0
  397. package/scripts/._verify-generated.mjs +0 -0
  398. package/scripts/assert-pack.mjs +48 -0
  399. package/scripts/check-css-target.mjs +54 -0
  400. package/scripts/check-fast.mjs +119 -0
  401. package/scripts/check-workspace.mjs +68 -19
  402. package/scripts/checks.json +627 -0
  403. package/scripts/deliver.mjs +183 -0
  404. package/scripts/dev-alipay.mjs +1 -1
  405. package/scripts/generate.mjs +3 -0
  406. package/scripts/lib/._chrome-pipe.mjs +0 -0
  407. package/scripts/lib/._geometry-kernel.mjs +0 -0
  408. package/scripts/lib/chrome-pipe.mjs +95 -0
  409. package/scripts/lib/geometry-kernel.mjs +137 -0
  410. package/scripts/shell-probe.mjs +280 -0
  411. package/scripts/storyboard.mjs +350 -0
  412. package/scripts/verify-generated.mjs +22 -127
  413. package/tsconfig.base.json +1 -0
  414. package/apps/client/STYLE_GUIDE.md +0 -81
  415. package/apps/client/VISUAL_RESTORE.md +0 -90
  416. package/apps/client/src/app.tsx +0 -11
  417. package/apps/client/src/business/App.tsx +0 -11
  418. package/apps/client/src/business/README.md +0 -99
  419. package/apps/client/src/business/routes.json +0 -3
  420. package/apps/client/src/main.tsx +0 -17
  421. package/apps/client/src/modules.ts +0 -33
  422. package/apps/client/src/platform/AgentChatApp.tsx +0 -14
  423. package/apps/client/src/platform/AppShell.tsx +0 -42
  424. package/apps/client/src/platform/agent-runtime.ts +0 -16
  425. package/apps/client/src/platform/bootstrap.ts +0 -55
  426. package/apps/client/src/platform/card-preview-page.tsx +0 -12
  427. package/apps/client/src/platform/mount-page.tsx +0 -25
  428. package/apps/client/src/platform/state/createPersistedStore.ts +0 -19
  429. package/apps/server/src/app-tools.ts +0 -14
  430. package/apps/server/src/modules.ts +0 -38
  431. package/apps/server/src/tools/clock.ts +0 -24
  432. package/apps/server/src/tools/translate.ts +0 -47
  433. package/packages/agent-ui-kit/src/ChatPage.less +0 -66
  434. package/packages/agent-ui-kit/src/components/ActionBar/index.less +0 -123
  435. package/packages/agent-ui-kit/src/components/ChatHeader/index.less +0 -148
  436. package/packages/agent-ui-kit/src/components/ChatInput/index.less +0 -394
  437. package/packages/agent-ui-kit/src/components/HistoryEntry/index.less +0 -49
  438. package/packages/agent-ui-kit/src/components/MediaList/index.less +0 -241
  439. package/packages/agent-ui-kit/src/components/MessageBubble/index.less +0 -325
  440. package/packages/agent-ui-kit/src/components/PullDownIndicator/index.less +0 -32
  441. package/packages/agent-ui-kit/src/components/QuickCommands/index.less +0 -63
  442. package/packages/agent-ui-kit/src/components/ReasoningBlock/index.less +0 -90
  443. package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.less +0 -32
  444. package/packages/agent-ui-kit/src/components/ToolCallBlock/index.less +0 -312
  445. package/packages/agent-ui-kit/src/theme/global.less +0 -99
  446. package/profiles/mall/config/llm_provider.json +0 -5
  447. package/profiles/mall/config/plugins.json +0 -3
  448. /package/{packages → modules}/provider-custom/LICENSE +0 -0
  449. /package/{packages → modules}/provider-custom/README.md +0 -0
  450. /package/{packages → modules}/provider-custom/src/index.ts +0 -0
  451. /package/{packages → modules}/provider-custom/tbox.module.json +0 -0
  452. /package/{packages → modules}/provider-custom/tests/provider-custom.test.ts +0 -0
  453. /package/{packages → modules}/provider-custom/tsconfig.json +0 -0
  454. /package/{packages → modules}/provider-custom/tsup.config.ts +0 -0
  455. /package/packages/agent-ui-kit/src/theme/{motion.less → motion.css} +0 -0
@@ -0,0 +1,21 @@
1
+ /** 弹层层级:只有三档(同一档内按打开先后叠放——后打开的在上)。 */
2
+ export const OVERLAY_LAYER_Z = {
3
+ modal: 1100,
4
+ preview: 1200,
5
+ toast: 1300,
6
+ } as const;
7
+
8
+ /** 与 `OVERLAY_LAYER_Z` 同值;Tailwind 只认源码里的字面量类名,因此这里保留静态写法。 */
9
+ export const OVERLAY_LAYER_CLASS = {
10
+ modal: 'z-[1100]',
11
+ preview: 'z-[1200]',
12
+ toast: 'z-[1300]',
13
+ } as const;
14
+
15
+ export type OverlayLayer = keyof typeof OVERLAY_LAYER_Z;
16
+
17
+ /** 关闭原因:Escape 或点遮罩(面板内的业务按钮不经过这里)。 */
18
+ export type DismissReason = 'escape' | 'mask';
19
+
20
+ /** 弹层根节点的块级定位:`fixed inset-0` + 层级(调用方的 rootClassName 叠在其后)。 */
21
+ export const OVERLAY_ROOT_CLASS = 'fixed inset-0';
@@ -0,0 +1,27 @@
1
+ // @vitest-environment node
2
+ import { describe, expect, it } from 'vitest';
3
+ import { renderToStaticMarkup } from 'react-dom/server';
4
+ import { Overlay } from './Overlay';
5
+
6
+ describe('Overlay(服务端)', () => {
7
+ it('无 document 时就地渲染(不 portal),保留对话框语义', () => {
8
+ const html = renderToStaticMarkup(
9
+ <Overlay open onDismiss={() => {}} labelledBy="t" rootClassName="probe-sheet">
10
+ <h2 id="t">标题</h2>
11
+ </Overlay>,
12
+ );
13
+ expect(html).toContain('data-tbox-overlay');
14
+ expect(html).toContain('role="dialog"');
15
+ expect(html).toContain('aria-labelledby="t"');
16
+ expect(html).toContain('标题');
17
+ });
18
+
19
+ it('关闭态不渲染任何标记', () => {
20
+ const html = renderToStaticMarkup(
21
+ <Overlay open={false} onDismiss={() => {}} labelledBy="t">
22
+ <h2 id="t">标题</h2>
23
+ </Overlay>,
24
+ );
25
+ expect(html).toBe('');
26
+ });
27
+ });
@@ -0,0 +1,209 @@
1
+ // @vitest-environment happy-dom
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
+ import { act, useState } from 'react';
4
+ import { createRoot } from 'react-dom/client';
5
+ import type { Root } from 'react-dom/client';
6
+ import { Overlay } from './Overlay';
7
+ import { getFocusable } from './focus';
8
+ import { registerScrollHost, scrollLockState } from './scroll-lock';
9
+
10
+ let root: Root | undefined;
11
+
12
+ beforeEach(() => {
13
+ const appRoot = document.createElement('div');
14
+ appRoot.id = 'root';
15
+ document.body.append(appRoot);
16
+ });
17
+
18
+ afterEach(async () => {
19
+ await act(async () => root?.unmount());
20
+ root = undefined;
21
+ document.body.innerHTML = '';
22
+ document.body.style.overflow = '';
23
+ });
24
+
25
+ function mount(node: React.ReactElement) {
26
+ if (!root) {
27
+ const container = document.createElement('div');
28
+ document.body.append(container);
29
+ root = createRoot(container);
30
+ }
31
+ return act(async () => {
32
+ root!.render(node);
33
+ });
34
+ }
35
+
36
+ function Sheet({ onDismiss, children }: { onDismiss: () => void; children?: React.ReactNode }) {
37
+ return (
38
+ <Overlay open onDismiss={onDismiss} labelledBy="t" exitMs={20} rootClassName="probe-sheet">
39
+ <h2 id="t">标题</h2>
40
+ <button type="button">操作</button>
41
+ {children}
42
+ </Overlay>
43
+ );
44
+ }
45
+
46
+ function Nested({ opened, onInner }: { opened: boolean; onInner: () => void }) {
47
+ const [outer, setOuter] = useState(true);
48
+ return (
49
+ <>
50
+ <Overlay open={outer} onDismiss={() => setOuter(false)} labelledBy="outer-t" exitMs={20} rootClassName="outer-sheet">
51
+ <h2 id="outer-t">外层</h2>
52
+ <button type="button" onClick={() => setOuter(false)}>关外层</button>
53
+ </Overlay>
54
+ {opened ? (
55
+ <Overlay open onDismiss={onInner} labelledBy="inner-t" exitMs={20} rootClassName="inner-sheet">
56
+ <h2 id="inner-t">内层</h2>
57
+ <button type="button">内层操作</button>
58
+ </Overlay>
59
+ ) : null}
60
+ </>
61
+ );
62
+ }
63
+
64
+ describe('Overlay', () => {
65
+ it('传送进 body,面板带 role/aria 与题注', async () => {
66
+ await mount(<Sheet onDismiss={vi.fn()} />);
67
+ const dialog = document.querySelector('[role="dialog"]') as HTMLElement;
68
+ expect(dialog).not.toBeNull();
69
+ expect(dialog.getAttribute('aria-modal')).toBe('true');
70
+ expect(document.getElementById(dialog.getAttribute('aria-labelledby')!)?.textContent).toBe('标题');
71
+ expect(document.body.contains(dialog)).toBe(true);
72
+ });
73
+
74
+ it('嵌套时 Escape 只关栈顶,且只有一个 dialog 可交互', async () => {
75
+ const onInner = vi.fn();
76
+ await mount(<Nested opened onInner={onInner} />);
77
+ const outer = document.querySelector('.outer-sheet') as HTMLElement;
78
+ expect(outer.inert).toBe(true);
79
+ await act(async () => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' })));
80
+ expect(onInner).toHaveBeenCalledTimes(1);
81
+ expect(document.querySelector('.outer-sheet')).not.toBeNull();
82
+ });
83
+
84
+ it('滚动锁按计数解锁,锁住已登记的宿主', async () => {
85
+ const host = document.createElement('div');
86
+ document.body.append(host);
87
+ const unregister = registerScrollHost(host);
88
+ expect(scrollLockState().count).toBe(0);
89
+ await mount(<Sheet onDismiss={vi.fn()} />);
90
+ expect(document.body.style.overflow).toBe('hidden');
91
+ expect(host.style.overflow).toBe('hidden');
92
+ expect(host.style.overscrollBehavior).toBe('none');
93
+ await act(async () => root?.unmount());
94
+ root = undefined;
95
+ expect(document.body.style.overflow).toBe('');
96
+ expect(host.style.overflow).toBe('');
97
+ unregister();
98
+ });
99
+
100
+ it('应用根在弹层打开时惰性,关闭后还原', async () => {
101
+ const appRoot = document.getElementById('root') as HTMLElement;
102
+ expect(appRoot.inert).toBe(false);
103
+ await mount(<Sheet onDismiss={vi.fn()} />);
104
+ expect(appRoot.inert).toBe(true);
105
+ expect(appRoot.getAttribute('aria-hidden')).toBe('true');
106
+ await act(async () => root?.unmount());
107
+ root = undefined;
108
+ expect(appRoot.inert).toBe(false);
109
+ expect(appRoot.getAttribute('aria-hidden')).toBeNull();
110
+ });
111
+
112
+ it('初始焦点落在首个可聚焦元素,关闭后回到打开前的元素', async () => {
113
+ const trigger = document.createElement('button');
114
+ document.body.append(trigger);
115
+ trigger.focus();
116
+ await mount(<Sheet onDismiss={vi.fn()} />);
117
+ await act(async () => {
118
+ await new Promise((resolve) => setTimeout(resolve, 0));
119
+ });
120
+ expect(document.activeElement?.textContent).toBe('操作');
121
+ await act(async () => root?.unmount());
122
+ root = undefined;
123
+ expect(document.activeElement).toBe(trigger);
124
+ });
125
+
126
+ it('退出态放弃 dialog 角色并在动画结束后卸载', async () => {
127
+ function Toggle() {
128
+ const [open, setOpen] = useState(true);
129
+ return (
130
+ <>
131
+ <button type="button" onClick={() => setOpen(false)}>关</button>
132
+ <Overlay open={open} onDismiss={() => setOpen(false)} labelledBy="t" exitMs={20} rootClassName="probe-sheet">
133
+ <h2 id="t">标题</h2>
134
+ </Overlay>
135
+ </>
136
+ );
137
+ }
138
+ await mount(<Toggle />);
139
+ await act(async () => (document.querySelector('.probe-sheet [data-tbox-overlay-panel]') as HTMLElement).querySelector('button'));
140
+ await act(async () => (document.querySelector('[data-tbox-overlay-mask]') as HTMLElement).click());
141
+ const rootEl = document.querySelector('.probe-sheet') as HTMLElement;
142
+ expect(rootEl.getAttribute('data-state')).toBe('closed');
143
+ expect(document.querySelector('[role="dialog"]')).toBeNull();
144
+ await act(async () => {
145
+ rootEl.dispatchEvent(new Event('animationend', { bubbles: true }));
146
+ });
147
+ expect(document.querySelector('.probe-sheet')).toBeNull();
148
+ });
149
+
150
+ it('退场期间遮罩继续吞点击且不再触发关闭,面板自身不可点', async () => {
151
+ const onDismiss = vi.fn();
152
+ function Toggle() {
153
+ const [open, setOpen] = useState(true);
154
+ return (
155
+ <Overlay
156
+ open={open}
157
+ onDismiss={() => {
158
+ onDismiss();
159
+ setOpen(false);
160
+ }}
161
+ labelledBy="t"
162
+ rootClassName="probe-sheet"
163
+ >
164
+ <h2 id="t">标题</h2>
165
+ <button type="button">操作</button>
166
+ </Overlay>
167
+ );
168
+ }
169
+ await mount(<Toggle />);
170
+ await act(async () => (document.querySelector('[data-tbox-overlay-mask]') as HTMLElement).click());
171
+ expect(onDismiss).toHaveBeenCalledTimes(1);
172
+ const rootEl = document.querySelector('.probe-sheet') as HTMLElement;
173
+ const panel = rootEl.querySelector('[data-tbox-overlay-panel]') as HTMLElement;
174
+ expect(rootEl.getAttribute('data-state')).toBe('closed');
175
+ // 根(与遮罩)保持可交互挡住背景;面板自身不再接收点击
176
+ expect(rootEl.className).not.toContain('pointer-events-none');
177
+ expect(panel.className).toContain('pointer-events-none');
178
+ await act(async () => (document.querySelector('[data-tbox-overlay-mask]') as HTMLElement).click());
179
+ expect(onDismiss).toHaveBeenCalledTimes(1);
180
+ });
181
+
182
+ it('遮罩 self-pointerdown 只在按下点落在遮罩本身时关闭', async () => {
183
+ const onDismiss = vi.fn();
184
+ await mount(
185
+ <Overlay open onDismiss={onDismiss} maskDismiss="self-pointerdown" labelledBy="t" rootClassName="probe-sheet">
186
+ <h2 id="t">标题</h2>
187
+ </Overlay>,
188
+ );
189
+ const panel = document.querySelector('[data-tbox-overlay-panel]') as HTMLElement;
190
+ await act(async () => {
191
+ panel.dispatchEvent(new Event('pointerdown', { bubbles: true }));
192
+ });
193
+ expect(onDismiss).not.toHaveBeenCalled();
194
+ await act(async () => {
195
+ (document.querySelector('[data-tbox-overlay-mask]') as HTMLElement).dispatchEvent(new Event('pointerdown', { bubbles: true }));
196
+ });
197
+ expect(onDismiss).toHaveBeenCalledWith('mask');
198
+ });
199
+
200
+ it('可聚焦元素查询跳过 aria-hidden 与 inert 区域', () => {
201
+ const host = document.createElement('div');
202
+ host.innerHTML = '<button>a</button><div aria-hidden="true"><button>b</button></div>';
203
+ const inertBox = document.createElement('div');
204
+ inertBox.inert = true;
205
+ inertBox.innerHTML = '<button>c</button>';
206
+ host.append(inertBox);
207
+ expect(getFocusable(host).map((el) => el.textContent)).toEqual(['a']);
208
+ });
209
+ });
@@ -0,0 +1,86 @@
1
+ /**
2
+ * 进出场存在性 hook:`open` 变 false 后先保持挂载放退出动画,动画结束(或超时)再卸载。
3
+ *
4
+ * 两条硬约束决定了这里的写法(都是踩过的坑):
5
+ * 1. **打开方向同步**:`open` 一变 true 当帧就要渲染内容。若靠 effect `setMounted(true)` 补,
6
+ * 父组件保持挂载、只切 `open` 的场景会先渲染 null,面板 ref 为空,初始焦点落不下去。
7
+ * 2. **退出方向也同步**:`open` 变 false 的那一帧必须仍然渲染(否则根节点先被卸载,
8
+ * effect 拿不到 root 就挂不上 animationend,退出态永远收不了尾)。因此用 `wasOpen` ref
9
+ * 在渲染期参与 `mounted` 计算,effect 只负责计时与监听,动画结束/超时才把 ref 放下。
10
+ *
11
+ * 约定:根节点 `data-state="open|closed"`,CSS 用 `data-[state=closed]:animate-[…]` 表达退出;
12
+ * 退出动画的 `animationend`/`transitionend` 从面板冒泡到根,这里只认根内部的事件。
13
+ * 减少动效时直接 0ms 卸载(CSS 侧同时 `motion-reduce:animate-none`)。
14
+ */
15
+ import { useEffect, useRef, useState } from 'react';
16
+ import type { RefObject } from 'react';
17
+
18
+ export type PresenceState = 'open' | 'closed';
19
+
20
+ export interface PresenceOptions {
21
+ /** 退出兜底时长(毫秒);CSS 动画结束后会提前返回。 */
22
+ exitMs?: number;
23
+ rootRef?: RefObject<HTMLElement | null>;
24
+ /** 退出动画结束(卸载前)回调:宿主自己控制挂载时用它把「真正关闭」推迟到动画之后。 */
25
+ onExited?: () => void;
26
+ }
27
+
28
+ export interface PresenceResult {
29
+ mounted: boolean;
30
+ state: PresenceState;
31
+ }
32
+
33
+ function prefersReducedMotion(): boolean {
34
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return false;
35
+ return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
36
+ }
37
+
38
+ export function usePresence(open: boolean, options: PresenceOptions = {}): PresenceResult {
39
+ const exitMs = options.exitMs ?? 200;
40
+ const rootRef = options.rootRef;
41
+ const [exiting, setExiting] = useState(false);
42
+ const wasOpen = useRef(open);
43
+ const optionsRef = useRef(options);
44
+ optionsRef.current = options;
45
+ if (open) wasOpen.current = true;
46
+ const mounted = open || exiting || wasOpen.current;
47
+
48
+ useEffect(() => {
49
+ if (open) {
50
+ setExiting(false); // 关闭中重新打开:取消退出
51
+ return undefined;
52
+ }
53
+ if (!wasOpen.current) return undefined; // 从未打开过:不进入退出
54
+ setExiting(true);
55
+ const root = rootRef?.current ?? null;
56
+ let finished = false;
57
+ const finish = () => {
58
+ if (finished) return;
59
+ finished = true;
60
+ wasOpen.current = false;
61
+ setExiting(false);
62
+ optionsRef.current.onExited?.();
63
+ };
64
+ const timer =
65
+ typeof window === 'undefined' ? undefined : window.setTimeout(finish, prefersReducedMotion() ? 0 : exitMs);
66
+ const onEnd = (event: Event) => {
67
+ const target = event.target;
68
+ if (!(target instanceof Node)) return;
69
+ if (root && !root.contains(target)) return;
70
+ finish();
71
+ };
72
+ if (root) {
73
+ root.addEventListener('animationend', onEnd);
74
+ root.addEventListener('transitionend', onEnd);
75
+ }
76
+ return () => {
77
+ if (timer !== undefined) window.clearTimeout(timer);
78
+ if (root) {
79
+ root.removeEventListener('animationend', onEnd);
80
+ root.removeEventListener('transitionend', onEnd);
81
+ }
82
+ };
83
+ }, [open, exitMs, rootRef]);
84
+
85
+ return { mounted, state: open ? 'open' : 'closed' };
86
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * 弹层滚动锁:计数式(嵌套弹层按最后关闭者的顺序解锁,不会提前放行背景滚动)。
3
+ *
4
+ * 除 `document.body` 外还要锁**应用自己的滚动宿主**(对话壳 `.chat-page__body` 承担滚动,
5
+ * body 本身不滚)。宿主由 ChatPage 经 `registerScrollHost` 登记,模块不再读 kit 内部类名。
6
+ *
7
+ * 不加 touchmove 拦截:本仓兼容基线 = Safari 16.4 / Chromium 105,`overflow:hidden` 与
8
+ * `overscroll-behavior` 已足够;面板内滚动区统一 `overscroll-contain`,遮罩 `touch-none`。
9
+ */
10
+ let lockCount = 0;
11
+ const hosts = new Set<HTMLElement>();
12
+ const saved = new Map<HTMLElement, { overflow: string; overscrollBehavior: string }>();
13
+
14
+ function targets(): HTMLElement[] {
15
+ const out: HTMLElement[] = [];
16
+ if (typeof document !== 'undefined' && document.body) out.push(document.body);
17
+ for (const el of hosts) out.push(el);
18
+ return out;
19
+ }
20
+
21
+ function apply(el: HTMLElement): void {
22
+ if (!saved.has(el)) saved.set(el, { overflow: el.style.overflow, overscrollBehavior: el.style.overscrollBehavior });
23
+ el.style.overflow = 'hidden';
24
+ el.style.overscrollBehavior = 'none';
25
+ }
26
+
27
+ function release(el: HTMLElement): void {
28
+ const previous = saved.get(el);
29
+ if (!previous) return;
30
+ el.style.overflow = previous.overflow;
31
+ el.style.overscrollBehavior = previous.overscrollBehavior;
32
+ saved.delete(el);
33
+ }
34
+
35
+ /** 加锁(计数 +1)。第一次加锁时锁住 body 与全部已登记宿主。 */
36
+ export function lockScroll(): void {
37
+ lockCount += 1;
38
+ if (lockCount === 1) targets().forEach(apply);
39
+ }
40
+
41
+ /** 解锁(计数 -1)。计数归零时才还原所有宿主。 */
42
+ export function unlockScroll(): void {
43
+ if (lockCount === 0) return;
44
+ lockCount -= 1;
45
+ if (lockCount > 0) return;
46
+ for (const el of [...saved.keys()]) release(el);
47
+ }
48
+
49
+ /** 登记应用滚动宿主;返回注销函数。已加锁时立即对新宿主生效。 */
50
+ export function registerScrollHost(el: HTMLElement): () => void {
51
+ hosts.add(el);
52
+ if (lockCount > 0) apply(el);
53
+ return () => {
54
+ release(el);
55
+ hosts.delete(el);
56
+ };
57
+ }
58
+
59
+ /** 只读快照(测试与诊断用)。 */
60
+ export function scrollLockState(): { count: number; locked: HTMLElement[] } {
61
+ return { count: lockCount, locked: [...saved.keys()] };
62
+ }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * 弹层栈:全实例唯一(kit 是宿主唯一副本),只维护顺序与「谁在最上层」。
3
+ *
4
+ * 键盘只挂**一个** document 捕获监听:Escape 与 Tab 焦点循环只分发给栈顶。
5
+ * 这样嵌套弹层不会一起关(旧实现每层各挂 document 监听,stopPropagation 挡不住同节点监听)。
6
+ * 栈非空时恒消费 Escape(即便栈顶 closeOnEscape=false,也不让背景的 Escape 处理器收到)。
7
+ */
8
+ import type { RefObject } from 'react';
9
+ import type { DismissReason } from './layers';
10
+ import { getFocusable } from './focus';
11
+ import { getAppRoot, setElementInert } from './inert';
12
+
13
+ export interface OverlayStackEntry {
14
+ readonly id: symbol;
15
+ onDismiss: (reason: DismissReason) => void;
16
+ closeOnEscape: boolean;
17
+ trapFocus: boolean;
18
+ inertApp: boolean;
19
+ panelRef: RefObject<HTMLElement | null>;
20
+ rootRef: RefObject<HTMLElement | null> | undefined;
21
+ }
22
+
23
+ const stack: OverlayStackEntry[] = [];
24
+ let bound = false;
25
+
26
+ function onKeyDown(event: KeyboardEvent): void {
27
+ const top = stack[stack.length - 1];
28
+ if (!top) return;
29
+ if (event.key === 'Escape') {
30
+ event.preventDefault();
31
+ event.stopPropagation();
32
+ if (top.closeOnEscape) top.onDismiss('escape');
33
+ return;
34
+ }
35
+ if (event.key !== 'Tab' || !top.trapFocus) return;
36
+ const panel = top.panelRef.current;
37
+ if (!panel) return;
38
+ const focusable = getFocusable(panel);
39
+ const first = focusable[0];
40
+ const last = focusable[focusable.length - 1];
41
+ const active = document.activeElement instanceof HTMLElement ? document.activeElement : null;
42
+ if (!first || !last) {
43
+ event.preventDefault();
44
+ panel.focus({ preventScroll: true });
45
+ return;
46
+ }
47
+ if (event.shiftKey) {
48
+ if (active === first || !active || !panel.contains(active)) {
49
+ event.preventDefault();
50
+ last.focus();
51
+ }
52
+ return;
53
+ }
54
+ if (active === last || !active || !panel.contains(active)) {
55
+ event.preventDefault();
56
+ first.focus();
57
+ }
58
+ }
59
+
60
+ function bind(): void {
61
+ if (bound || typeof document === 'undefined') return;
62
+ // document 捕获阶段:真实按键从聚焦元素冒泡上来时最先到这里,能抢先消费 Escape;
63
+ // 测试直接 `document.dispatchEvent(new KeyboardEvent(...))` 也命中(target 自身同样触发捕获监听)。
64
+ document.addEventListener('keydown', onKeyDown, true);
65
+ bound = true;
66
+ }
67
+
68
+ function unbind(): void {
69
+ if (!bound || typeof document === 'undefined') return;
70
+ document.removeEventListener('keydown', onKeyDown, true);
71
+ bound = false;
72
+ }
73
+
74
+ export function pushOverlay(entry: OverlayStackEntry): () => void {
75
+ stack.push(entry);
76
+ bind();
77
+ notifyOverlays();
78
+ return () => {
79
+ const index = stack.indexOf(entry);
80
+ if (index >= 0) stack.splice(index, 1);
81
+ if (stack.length === 0) unbind();
82
+ notifyOverlays();
83
+ };
84
+ }
85
+
86
+ /**
87
+ * 按栈重算惰性:应用根在所有栈顶之外的弹层打开时惰性;每个弹层的根节点除栈顶外一律惰性。
88
+ * 幂等,可在任意栈变化后重复调用。
89
+ */
90
+ export function syncOverlayInert(): void {
91
+ const top = stack[stack.length - 1];
92
+ const appRoot = getAppRoot();
93
+ if (appRoot) {
94
+ // 就地渲染的弹层(无 portal 的宿主)会落在应用根内部:此时给根设 inert 会把弹层自己
95
+ // 一起惰性化,弹层就点不动了。有这种条目时改由逐条根的按层惰性负责。
96
+ const inline = stack.some((entry) => {
97
+ const root = entry.rootRef?.current;
98
+ return Boolean(root && appRoot.contains(root));
99
+ });
100
+ setElementInert(appRoot, !inline && stack.some((entry) => entry.inertApp));
101
+ }
102
+ for (const entry of stack) {
103
+ const root = entry.rootRef?.current;
104
+ if (!root || root.contains(appRoot)) continue;
105
+ setElementInert(root, entry !== top);
106
+ }
107
+ }
108
+
109
+ function notifyOverlays(): void {
110
+ syncOverlayInert();
111
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * 弹层行为总装 hook:入栈 / 滚动锁 / 惰性 / 初始焦点 / 关闭后焦点恢复。
3
+ *
4
+ * 给需要自管 DOM 的复杂弹层用(例如带 FLIP 形变的详情页);常规弹层直接用 `<Overlay>`。
5
+ * `active` 用**逻辑开关**(等于 `open`):退出动画期间即出栈、解锁、恢复焦点,
6
+ * 但组件靠 `usePresence` 继续挂载到动画结束(此时面板已无 `role=dialog`)。
7
+ */
8
+ import { useEffect, useRef } from 'react';
9
+ import type { RefObject } from 'react';
10
+ import type { DismissReason } from './layers';
11
+ import { focusInitial, restoreFocus } from './focus';
12
+ import type { FocusRestore, InitialFocus } from './focus';
13
+ import { lockScroll, unlockScroll } from './scroll-lock';
14
+ import { pushOverlay } from './stack';
15
+ import type { OverlayStackEntry } from './stack';
16
+
17
+ export interface UseOverlayOptions {
18
+ active: boolean;
19
+ onDismiss: (reason: DismissReason) => void;
20
+ panelRef: RefObject<HTMLElement | null>;
21
+ rootRef?: RefObject<HTMLElement | null>;
22
+ initialFocus?: InitialFocus;
23
+ /** 默认 'previous'(打开前的焦点);false = 不恢复。 */
24
+ restoreFocus?: FocusRestore;
25
+ lockScroll?: boolean;
26
+ inertApp?: boolean;
27
+ trapFocus?: boolean;
28
+ closeOnEscape?: boolean;
29
+ }
30
+
31
+ export function useOverlay(options: UseOverlayOptions): void {
32
+ const { active } = options;
33
+ const latest = useRef(options);
34
+ latest.current = options;
35
+ const entryRef = useRef<OverlayStackEntry | null>(null);
36
+ const lockedRef = useRef(false);
37
+ const previousFocusRef = useRef<HTMLElement | null>(null);
38
+
39
+ // 每次渲染同步可变字段(与仓内既有 `onCloseRef.current = onClose` 同款写法)。
40
+ const entry = entryRef.current;
41
+ if (entry) {
42
+ entry.onDismiss = (reason) => latest.current.onDismiss(reason);
43
+ entry.closeOnEscape = latest.current.closeOnEscape ?? true;
44
+ entry.trapFocus = latest.current.trapFocus ?? true;
45
+ entry.inertApp = latest.current.inertApp ?? true;
46
+ }
47
+
48
+ useEffect(() => {
49
+ if (!active) return undefined;
50
+ if (typeof document === 'undefined') return undefined;
51
+ previousFocusRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
52
+ const created: OverlayStackEntry = {
53
+ id: Symbol('tbox-overlay'),
54
+ onDismiss: (reason) => latest.current.onDismiss(reason),
55
+ closeOnEscape: latest.current.closeOnEscape ?? true,
56
+ trapFocus: latest.current.trapFocus ?? true,
57
+ inertApp: latest.current.inertApp ?? true,
58
+ panelRef: latest.current.panelRef,
59
+ rootRef: latest.current.rootRef,
60
+ };
61
+ entryRef.current = created;
62
+ const remove = pushOverlay(created);
63
+ if (latest.current.lockScroll ?? true) {
64
+ lockScroll();
65
+ lockedRef.current = true;
66
+ }
67
+ // 初始焦点就地设置:本 effect 在 DOM 提交后跑到这里,面板已在文档里。
68
+ focusInitial(created.panelRef.current, latest.current.initialFocus);
69
+ return () => {
70
+ remove();
71
+ entryRef.current = null;
72
+ if (lockedRef.current) {
73
+ unlockScroll();
74
+ lockedRef.current = false;
75
+ }
76
+ const restore = latest.current.restoreFocus ?? 'previous';
77
+ if (restore) restoreFocus(restore === 'previous' ? previousFocusRef.current : restore.current);
78
+ };
79
+ }, [active]);
80
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * KitPreviewProvider:卡片预览面的最小装配根。
3
+ *
4
+ * 预览页直接渲染 SDK CardRenderer,没有应用 store——kit 卡片的 `useCardActions`
5
+ * 会因「KitChatProvider 缺席」抛错(预览 7/7 全红)。这里给一个只读预览 store:
6
+ * 动作写通道是空实现(预览页自己的动作通道另经 bindCardActionChannel 接管),
7
+ * 卡片能渲染、按钮能显示、历史/禁用态照常。
8
+ *
9
+ * 应用接线:app.config.ts 的 `wrapPreview` 返回 `createElement(KitPreviewProvider, null, node)`。
10
+ */
11
+ import { useMemo, type ReactNode } from 'react';
12
+ import { useStore } from 'zustand';
13
+ import { createStore } from 'zustand/vanilla';
14
+ import type { CardComponent } from '@tbox.cn/app-contracts';
15
+ import type { CoreChatState, CoreChatStore } from '@tbox.cn/app-agent-sdk-client';
16
+ import { KitChatProvider } from './store-context';
17
+
18
+ /** 预览用 store:只满足壳与卡片的读取(sendUiAction 空实现、不在生成中)。 */
19
+ export function createPreviewStore(state: Partial<CoreChatState> = {}): CoreChatStore {
20
+ const vanilla = createStore<CoreChatState>(() => ({
21
+ sendUiAction: () => {},
22
+ isGenerating: false,
23
+ ...state,
24
+ } as unknown as CoreChatState));
25
+ const hook = ((selector: (state: CoreChatState) => unknown) =>
26
+ useStore(vanilla, selector)) as unknown as CoreChatStore;
27
+ hook.getState = vanilla.getState;
28
+ hook.setState = vanilla.setState;
29
+ hook.subscribe = vanilla.subscribe;
30
+ return hook;
31
+ }
32
+
33
+ export function KitPreviewProvider({
34
+ cards = {},
35
+ children,
36
+ }: {
37
+ /** 预览页的卡片注册表(缺省空表;动作由预览页接管) */
38
+ cards?: Record<string, CardComponent>;
39
+ children: ReactNode;
40
+ }) {
41
+ const store = useMemo(() => createPreviewStore(), []);
42
+ return (
43
+ <KitChatProvider store={store} cards={cards} rawCards={cards}>
44
+ {children}
45
+ </KitChatProvider>
46
+ );
47
+ }