@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,86 @@
1
+ /**
2
+ * 卡片内交互:把「点按钮之后发生什么」收敛成两种意图,避免每张卡重写门控。
3
+ *
4
+ * - `send`:把一句话作为用户消息发回,走模型(信息不足、需要模型再判断时用);
5
+ * - `invoke`:触发卡片上声明的确定性动作(moduleAction),不过模型;
6
+ * - `disabled`:历史卡片与生成中一律禁用,两者文案不同——历史卡只读,生成中提示等待。
7
+ *
8
+ * 门控与 toast 文案集中在实现处;卡片组件只消费 `disabled` 与两个动作函数。
9
+ */
10
+ import { useCallback } from 'react';
11
+ import { toast } from '../utils/toast';
12
+ import { useChatStore } from '../store-context';
13
+
14
+ export interface UseCardActionsOptions {
15
+ /** 卡片实例 id(协议字段名 surfaceId 的历史别名) */
16
+ cardId: string;
17
+ /** 历史消息里的卡片:只读 */
18
+ isHistory?: boolean;
19
+ /** 卡片携带的动作令牌(`payload.actionTokens`,仅 moduleAction 有) */
20
+ actionTokens?: Record<string, string>;
21
+ }
22
+
23
+ export interface CardActions {
24
+ /** 发一句话给模型;`displayText` 是气泡展示文本,缺省同 `text` */
25
+ send(text: string, opts?: { displayText?: string }): void;
26
+ /**
27
+ * 触发卡片上的确定性动作(需该动作已签发令牌)。
28
+ * `input` 作为该次调用的入参(UI_ACTION 的 formData 通道),由服务端 `inputSchema` 校验;
29
+ * 不传时按空对象校验——无参动作写 `z.object({})`。
30
+ */
31
+ invoke(actionId: string, input?: Record<string, unknown>): void;
32
+ /** 历史卡或生成中为 true——按钮应据此置灰 */
33
+ disabled: boolean;
34
+ isHistory: boolean;
35
+ isGenerating: boolean;
36
+ }
37
+
38
+ export function useCardActions(opts: UseCardActionsOptions): CardActions {
39
+ const sendUiAction = useChatStore((s) => s.sendUiAction);
40
+ const isGenerating = useChatStore((s) => s.isGenerating);
41
+ const isHistory = opts.isHistory === true;
42
+ const disabled = isHistory || isGenerating;
43
+
44
+ const send = useCallback(
45
+ (text: string, o?: { displayText?: string }) => {
46
+ if (!text) return;
47
+ if (isHistory) {
48
+ void toast('历史卡片仅供查看', 'info');
49
+ return;
50
+ }
51
+ if (isGenerating) {
52
+ void toast('正在处理上一条消息,请稍候', 'info');
53
+ return;
54
+ }
55
+ sendUiAction(opts.cardId, {
56
+ type: 'sendMessage',
57
+ value: text,
58
+ displayText: o?.displayText ?? text,
59
+ visible: true,
60
+ });
61
+ },
62
+ [opts.cardId, isHistory, isGenerating, sendUiAction],
63
+ );
64
+
65
+ const invoke = useCallback(
66
+ (actionId: string, input?: Record<string, unknown>) => {
67
+ if (isHistory) {
68
+ void toast('历史卡片仅供查看', 'info');
69
+ return;
70
+ }
71
+ if (isGenerating) {
72
+ void toast('正在处理上一条消息,请稍候', 'info');
73
+ return;
74
+ }
75
+ const contextToken = opts.actionTokens?.[actionId];
76
+ if (!contextToken) {
77
+ void toast('该操作不可用', 'info');
78
+ return;
79
+ }
80
+ sendUiAction(opts.cardId, { type: 'moduleAction', actionId, contextToken }, input);
81
+ },
82
+ [opts.cardId, opts.actionTokens, isHistory, isGenerating, sendUiAction],
83
+ );
84
+
85
+ return { send, invoke, disabled, isHistory, isGenerating };
86
+ }
@@ -0,0 +1,42 @@
1
+ // @vitest-environment happy-dom
2
+ import { act } from 'react';
3
+ import { createRoot } from 'react-dom/client';
4
+ import { afterEach, describe, expect, it } from 'vitest';
5
+ import type { CardView } from '@tbox.cn/app-contracts';
6
+ import { createSurfaceHarness } from '../surface';
7
+ import { ViewCard } from './view-card';
8
+
9
+ const view: CardView = {
10
+ header: { title: '活动' },
11
+ blocks: [
12
+ {
13
+ kind: 'list',
14
+ items: [{ title: '亲子手作', action: { label: '报名', invoke: { id: 'register' } } }],
15
+ },
16
+ ],
17
+ };
18
+
19
+ const roots: ReturnType<typeof createRoot>[] = [];
20
+ afterEach(async () => {
21
+ await act(async () => {
22
+ for (const root of roots) root.unmount();
23
+ });
24
+ roots.length = 0;
25
+ document.body.innerHTML = '';
26
+ });
27
+
28
+ describe('ViewCard 列表内联动作', () => {
29
+ it('点击后进入单飞状态,按钮禁用', async () => {
30
+ const harness = createSurfaceHarness({});
31
+ const el = document.createElement('div');
32
+ document.body.appendChild(el);
33
+ const root = createRoot(el);
34
+ roots.push(root);
35
+ act(() => root.render(harness.wrap(<ViewCard view={view} cardId="c1" actionTokens={{ register: 'token' }} />)));
36
+ const button = [...el.querySelectorAll('button')].find((item) => item.textContent?.includes('报名'))!;
37
+ await act(async () => {
38
+ button.click();
39
+ });
40
+ expect(el.querySelector('button')!.disabled).toBe(true);
41
+ });
42
+ });
@@ -0,0 +1,79 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createElement } from 'react';
3
+ import { renderToStaticMarkup } from 'react-dom/server';
4
+ import type { CardView } from '@tbox.cn/app-contracts';
5
+ import { createSurfaceHarness } from '../surface';
6
+ import { ViewCard } from './view-card';
7
+
8
+ const parking: CardView = {
9
+ header: { title: '停车订单', eyebrow: 'PARKING', status: { text: '待支付', tone: 'warning' } },
10
+ blocks: [
11
+ { kind: 'facts', items: [['车牌', '浙A·12345'], ['停车时长', '2 小时 20 分钟']] },
12
+ { kind: 'bill', lines: [['停车费', '¥15'], ['停车券', '-¥10', true]], total: ['应付', '¥5'] },
13
+ { kind: 'notice', text: '已为你选好停车券', tone: 'info' },
14
+ ],
15
+ actions: [
16
+ { label: '确认支付 ¥5', invoke: { id: 'pay-parking', input: { plate: '浙A·12345' } }, confirm: { title: '确认支付?' } },
17
+ { label: '用积分换停车券', send: '用积分兑换停车券' },
18
+ ],
19
+ };
20
+
21
+ const activity: CardView = {
22
+ header: { title: '近期活动', status: { text: '2 个推荐', tone: 'info' } },
23
+ blocks: [
24
+ {
25
+ kind: 'list',
26
+ items: [
27
+ { title: '亲子手作', meta: '今天 15:00 · L2 连廊', tags: ['亲子'], description: '剩 8 组名额', action: { label: '报名', invoke: { id: 'register' } } },
28
+ { title: '积分加倍', meta: '今天 10:00 · L1 中庭' },
29
+ ],
30
+ },
31
+ ],
32
+ actions: [{ label: '看第一个详情', send: '第一个活动的详情', style: 'secondary' }],
33
+ };
34
+
35
+ const harness = createSurfaceHarness({});
36
+ const render = (view: CardView, isHistory = false) =>
37
+ renderToStaticMarkup(harness.wrap(createElement(ViewCard, { view, cardId: 'c1', isHistory })));
38
+
39
+ describe('ViewCard', () => {
40
+ it('积木与动作渲染一次,标题/明细/提示都在', () => {
41
+ const html = render(parking);
42
+ expect(html).toContain('停车订单');
43
+ expect(html).toContain('浙A·12345');
44
+ expect(html).toContain('应付');
45
+ expect(html).toContain('已为你选好停车券');
46
+ expect(html.match(/确认支付 ¥5/g)?.length).toBe(1);
47
+ expect(html.match(/用积分换停车券/g)?.length).toBe(1);
48
+ expect(html).toContain('tbox-btn');
49
+ });
50
+
51
+ it('列表积木渲染实体与内联动作', () => {
52
+ const html = render(activity);
53
+ expect(html).toContain('亲子手作');
54
+ expect(html).toContain('报名');
55
+ expect(html).toContain('2 个推荐');
56
+ });
57
+
58
+ it('渲染前归一化:超预算积木只渲染前 4 个', () => {
59
+ const over = {
60
+ header: { title: '超预算' },
61
+ blocks: Array.from({ length: 5 }, (_, index) => ({ kind: 'tags' as const, tags: ['tag-' + index] })),
62
+ } as unknown as CardView;
63
+ const html = render(over);
64
+ expect(html).toContain('tag-0');
65
+ expect(html).toContain('tag-3');
66
+ expect(html).not.toContain('tag-4');
67
+ });
68
+
69
+ it('坏数据回退为可读提示,不抛错', () => {
70
+ const broken = { header: { title: '坏卡' }, blocks: null } as unknown as CardView;
71
+ const html = render(broken);
72
+ expect(html).toContain('卡片数据不可用');
73
+ });
74
+
75
+ it('历史态禁用动作', () => {
76
+ const html = render(parking, true);
77
+ expect(html).toContain('disabled');
78
+ });
79
+ });
@@ -0,0 +1,250 @@
1
+ /**
2
+ * ViewCard:视图卡的通用渲染器(L1)。
3
+ *
4
+ * 一张卡 = 一份 CardView JSON;版式、动作路径、确认弹层、历史禁用都由平台实现一次。
5
+ * 应用只写 view(data) 函数(服务端),客户端不再有手写 tsx。
6
+ */
7
+ import { useEffect, useRef, useState, type ReactNode } from 'react';
8
+ import { normalizeCardView } from '@tbox.cn/app-contracts';
9
+ import type { CardView, CardViewAction, CardViewBlock } from '@tbox.cn/app-contracts';
10
+ import {
11
+ ActionList,
12
+ Bill,
13
+ Card,
14
+ CardButton,
15
+ CardHeader,
16
+ ConfirmSheet,
17
+ EmptyState,
18
+ EntityRow,
19
+ Hero,
20
+ KeyValueList,
21
+ Notice,
22
+ StatusTag,
23
+ Steps,
24
+ TagList,
25
+ Ticket,
26
+ Timeline,
27
+ } from './primitives';
28
+ import type { CardActionSpec } from './primitives';
29
+ import { useCardActions } from './use-card-actions';
30
+
31
+ type Api = ReturnType<typeof useCardActions>;
32
+
33
+ function toSpec(action: CardViewAction): CardActionSpec {
34
+ return {
35
+ label: action.label,
36
+ ...(action.send !== undefined ? { send: action.send } : {}),
37
+ ...(action.invoke ? { invoke: action.invoke } : {}),
38
+ ...(action.confirm ? { confirm: action.confirm } : {}),
39
+ ...(action.style ? { style: action.style } : {}),
40
+ };
41
+ }
42
+
43
+ /** 列表项内联动作:与卡级动作共用确认弹层语义,但不占整行。 */
44
+ function useInlineRunner(api: Api) {
45
+ const [pending, setPending] = useState<CardViewAction | null>(null);
46
+ const [running, setRunning] = useState(false);
47
+ const runningRef = useRef(false);
48
+ const wasGenerating = useRef(false);
49
+ useEffect(() => {
50
+ if (!running) return undefined;
51
+ const timer = setTimeout(() => {
52
+ runningRef.current = false;
53
+ setRunning(false);
54
+ }, 20000);
55
+ return () => clearTimeout(timer);
56
+ }, [running]);
57
+ useEffect(() => {
58
+ if (api.isGenerating) {
59
+ wasGenerating.current = true;
60
+ return;
61
+ }
62
+ if (!wasGenerating.current) return;
63
+ wasGenerating.current = false;
64
+ if (runningRef.current) {
65
+ runningRef.current = false;
66
+ setRunning(false);
67
+ }
68
+ }, [api.isGenerating]);
69
+ const run = (action: CardViewAction) => {
70
+ if (!action.invoke && !action.send) return;
71
+ runningRef.current = true;
72
+ setRunning(true);
73
+ if (action.invoke) {
74
+ api.invoke(action.invoke.id, action.invoke.input);
75
+ return;
76
+ }
77
+ if (action.send) {
78
+ if (typeof action.send === 'string') api.send(action.send);
79
+ else api.send(action.send.text, { displayText: action.send.displayText });
80
+ }
81
+ };
82
+ const trigger = (action: CardViewAction) => {
83
+ if (api.disabled || runningRef.current || pending !== null) return;
84
+ if (action.confirm) {
85
+ setPending(action);
86
+ return;
87
+ }
88
+ run(action);
89
+ };
90
+ const sheet =
91
+ pending && pending.confirm ? (
92
+ <ConfirmSheet
93
+ open
94
+ title={pending.confirm.title}
95
+ {...(pending.confirm.description ? { description: pending.confirm.description } : {})}
96
+ {...(pending.confirm.confirmText ? { confirmText: pending.confirm.confirmText } : {})}
97
+ {...(pending.confirm.cancelText ? { cancelText: pending.confirm.cancelText } : {})}
98
+ onConfirm={() => {
99
+ const action = pending;
100
+ setPending(null);
101
+ run(action);
102
+ }}
103
+ onCancel={() => setPending(null)}
104
+ />
105
+ ) : null;
106
+ return { trigger, sheet, busy: api.disabled || running || pending !== null };
107
+ }
108
+
109
+ function renderBlock(
110
+ block: CardViewBlock,
111
+ trigger: (action: CardViewAction) => void,
112
+ disabled: boolean,
113
+ ): ReactNode {
114
+ switch (block.kind) {
115
+ case 'hero':
116
+ return (
117
+ <Hero
118
+ {...(block.eyebrow ? { eyebrow: block.eyebrow } : {})}
119
+ title={block.title}
120
+ {...(block.value ? { value: block.value } : {})}
121
+ {...(block.unit ? { unit: block.unit } : {})}
122
+ {...(block.footnote ? { footnote: block.footnote } : {})}
123
+ {...(block.tone ? { tone: block.tone } : {})}
124
+ />
125
+ );
126
+ case 'facts':
127
+ return <KeyValueList items={block.items.map(([label, value]) => ({ label, value }))} />;
128
+ case 'bill':
129
+ return (
130
+ <Bill
131
+ lines={block.lines.map(([label, value, muted]) => ({ label, value, ...(muted ? { muted: true } : {}) }))}
132
+ {...(block.total ? { total: { label: block.total[0], value: block.total[1] } } : {})}
133
+ />
134
+ );
135
+ case 'notice':
136
+ return <Notice {...(block.tone ? { tone: block.tone } : {})}>{block.text}</Notice>;
137
+ case 'tags':
138
+ return <TagList tags={block.tags} {...(block.tone ? { tone: block.tone } : {})} />;
139
+ case 'steps':
140
+ return <Steps steps={block.steps} />;
141
+ case 'ticket':
142
+ return (
143
+ <Ticket
144
+ amount={block.amount}
145
+ {...(block.condition ? { condition: block.condition } : {})}
146
+ {...(block.meta ? { meta: block.meta } : {})}
147
+ {...(block.status ? { status: block.status } : {})}
148
+ {...(block.tone ? { tone: block.tone } : {})}
149
+ />
150
+ );
151
+ case 'timeline':
152
+ return (
153
+ <Timeline
154
+ items={block.items.map((item) => ({
155
+ label: item.label,
156
+ ...(item.amount ? { amount: item.amount } : {}),
157
+ ...(item.time ? { time: item.time } : {}),
158
+ ...(item.tone ? { tone: item.tone } : {}),
159
+ }))}
160
+ />
161
+ );
162
+ case 'empty':
163
+ return <EmptyState title={block.title} {...(block.description ? { description: block.description } : {})} />;
164
+ case 'list':
165
+ return (
166
+ <div className="tbox-view-list flex flex-col gap-2.5">
167
+ {block.items.map((item, index) => (
168
+ <EntityRow
169
+ key={item.title + '-' + index}
170
+ title={item.title}
171
+ {...(item.meta ? { meta: item.meta } : {})}
172
+ {...(item.price ? { price: item.price } : {})}
173
+ {...(item.description ? { description: item.description } : {})}
174
+ {...(item.tags && item.tags.length > 0 ? { tags: <TagList tags={item.tags} /> } : {})}
175
+ {...(item.action
176
+ ? {
177
+ action: (
178
+ <CardButton
179
+ variant={item.action.style === 'primary' ? 'primary' : 'secondary'}
180
+ disabled={disabled}
181
+ onClick={() => trigger(item.action as CardViewAction)}
182
+ >
183
+ {item.action.label}
184
+ </CardButton>
185
+ ),
186
+ }
187
+ : {})}
188
+ />
189
+ ))}
190
+ </div>
191
+ );
192
+ default: {
193
+ const unknown = block as { kind?: string };
194
+ console.warn('[ViewCard] 未知积木,已跳过:' + String(unknown.kind));
195
+ return null;
196
+ }
197
+ }
198
+ }
199
+
200
+ export function ViewCard({
201
+ view,
202
+ cardId,
203
+ isHistory,
204
+ actionTokens,
205
+ }: {
206
+ view: CardView;
207
+ cardId: string;
208
+ isHistory?: boolean;
209
+ actionTokens?: Record<string, string>;
210
+ }) {
211
+ let safeView: CardView;
212
+ try {
213
+ safeView = normalizeCardView(view);
214
+ } catch {
215
+ return (
216
+ <Card>
217
+ <Notice tone="error">卡片数据不可用,请重新触发一次</Notice>
218
+ </Card>
219
+ );
220
+ }
221
+ const api = useCardActions({
222
+ cardId,
223
+ isHistory: isHistory === true,
224
+ ...(actionTokens ? { actionTokens } : {}),
225
+ });
226
+ const inline = useInlineRunner(api);
227
+ return (
228
+ <Card>
229
+ <CardHeader
230
+ title={safeView.header.title}
231
+ {...(safeView.header.eyebrow ? { eyebrow: safeView.header.eyebrow } : {})}
232
+ {...(safeView.header.status
233
+ ? { status: <StatusTag tone={safeView.header.status.tone ?? 'neutral'}>{safeView.header.status.text}</StatusTag> }
234
+ : {})}
235
+ />
236
+ {safeView.blocks.map((block, index) => (
237
+ <div key={block.kind + '-' + index}>{renderBlock(block, inline.trigger, inline.busy)}</div>
238
+ ))}
239
+ {safeView.actions && safeView.actions.length > 0 ? (
240
+ <ActionList
241
+ api={api}
242
+ actions={safeView.actions.map((action, index) =>
243
+ toSpec(index === 0 ? { ...action, style: action.style ?? 'primary' } : { ...action, style: 'secondary' }),
244
+ )}
245
+ />
246
+ ) : null}
247
+ {inline.sheet}
248
+ </Card>
249
+ );
250
+ }
@@ -1,82 +1,46 @@
1
- /**
2
- * chat-config store 水合 action(chat settings 服务端下发真源):
3
- * applyServerSettings 五键整组语义——undefined 键保留构建期快照,禁部分水合。
4
- */
5
- import { describe, it, expect, beforeEach } from 'vitest';
1
+ import { describe, expect, it } from 'vitest';
6
2
  import { configureChatConfigDefaults, useChatConfigStore } from './chat-config';
7
3
 
8
- const snapshot = () => useChatConfigStore.getState();
9
-
10
- describe('applyServerSettings:HELLO_ACK settings 水合', () => {
11
- beforeEach(() => {
12
- // 重置回构建期快照(快照值来自模板 config/chat.json 静态 import)
13
- useChatConfigStore.setState({
14
- enableImageUpload: true,
15
- enableVideoUpload: true,
16
- enableTTS: true,
17
- enableVoiceInput: true,
18
- defaultInputMode: 'TEXT',
19
- });
4
+ const reset = () => {
5
+ configureChatConfigDefaults({
6
+ enableImageUpload: true,
7
+ enableVideoUpload: true,
8
+ enableTTS: true,
9
+ enableVoiceInput: true,
10
+ defaultInputMode: 'TEXT',
11
+ quickCommands: [],
12
+ retryOnError: true,
20
13
  });
14
+ useChatConfigStore.setState({ identity: undefined, welcome: undefined });
15
+ };
21
16
 
22
- it('五键全覆盖 → 全部覆盖快照值', () => {
23
- snapshot().applyServerSettings({
24
- enableImageUpload: false,
25
- enableVideoUpload: false,
26
- enableTTS: false,
27
- enableVoiceInput: false,
28
- defaultInputMode: 'VOICE',
17
+ describe('chat 设置的构建期快照', () => {
18
+ it('identity / welcome / retryOnError 随快照注入', () => {
19
+ reset();
20
+ configureChatConfigDefaults({
21
+ identity: { name: '悦享里', tagline: '商圈智能助手' },
22
+ welcome: { title: '今天想逛点什么?', subtitle: '会员、停车、优惠都能问我' },
23
+ retryOnError: false,
29
24
  });
30
- expect(snapshot().enableImageUpload).toBe(false);
31
- expect(snapshot().enableVideoUpload).toBe(false);
32
- expect(snapshot().enableTTS).toBe(false);
33
- expect(snapshot().enableVoiceInput).toBe(false);
34
- expect(snapshot().defaultInputMode).toBe('VOICE');
35
- });
36
-
37
- it('部分键(undefined 保留快照值——禁部分水合导致快照丢失)', () => {
38
- snapshot().applyServerSettings({ enableTTS: false });
39
- expect(snapshot().enableTTS).toBe(false);
40
- expect(snapshot().enableImageUpload).toBe(true);
41
- expect(snapshot().enableVideoUpload).toBe(true);
42
- expect(snapshot().enableVoiceInput).toBe(true);
43
- expect(snapshot().defaultInputMode).toBe('TEXT');
44
- });
45
-
46
- it('整包 undefined(旧 server / ack 未达)→ no-op 快照保留', () => {
47
- snapshot().applyServerSettings(undefined);
48
- expect(snapshot().enableImageUpload).toBe(true);
49
- expect(snapshot().enableTTS).toBe(true);
50
- expect(snapshot().defaultInputMode).toBe('TEXT');
25
+ const state = useChatConfigStore.getState();
26
+ expect(state.identity?.name).toBe('悦享里');
27
+ expect(state.welcome?.title).toBe('今天想逛点什么?');
28
+ expect(state.retryOnError).toBe(false);
51
29
  });
52
30
 
53
- it('同值幂等:两次 apply 后五键深等价(防第二次 apply 丢键/翻转)', () => {
54
- const settings = { enableTTS: false, defaultInputMode: 'VOICE' as const };
55
- snapshot().applyServerSettings(settings);
56
- const after1 = snapshot();
57
- snapshot().applyServerSettings(settings);
58
- // toEqual 全状态深比较——单键 toBe 对原始值恒真,钉不住实现回归
59
- expect(snapshot()).toEqual(after1);
60
- expect(snapshot().enableTTS).toBe(false);
61
- expect(snapshot().defaultInputMode).toBe('VOICE');
31
+ it('缺省 retryOnError 为 true,identity 缺省不渲染', () => {
32
+ reset();
33
+ const state = useChatConfigStore.getState();
34
+ expect(state.retryOnError).toBe(true);
35
+ expect(state.identity).toBeUndefined();
62
36
  });
63
- });
64
-
65
- describe('configureChatConfigDefaults:构建期快照注入(W2-1 kit 化)', () => {
66
- it('快照键覆盖内建缺省;缺席键保留;undefined no-op', () => {
67
- configureChatConfigDefaults({
68
- enableTTS: false,
69
- quickCommands: [{ label: 'L', query: 'Q' }],
70
- });
71
- expect(snapshot().enableTTS).toBe(false);
72
- expect(snapshot().quickCommands).toEqual([{ label: 'L', query: 'Q' }]);
73
- // 缺席键保留
74
- expect(snapshot().enableImageUpload).toBe(true);
75
-
76
- configureChatConfigDefaults(undefined);
77
- expect(snapshot().enableTTS).toBe(false); // no-op:不因 undefined 回翻
78
37
 
79
- // 复位(防污染后续用例)
80
- useChatConfigStore.setState({ enableTTS: true, quickCommands: [] });
38
+ it('HELLO_ACK 水合不覆盖展示配置', () => {
39
+ reset();
40
+ configureChatConfigDefaults({ identity: { name: '悦享里' } });
41
+ useChatConfigStore.getState().applyServerSettings({ enableTTS: false } as never);
42
+ const state = useChatConfigStore.getState();
43
+ expect(state.enableTTS).toBe(false);
44
+ expect(state.identity?.name).toBe('悦享里');
81
45
  });
82
46
  });
@@ -15,6 +15,16 @@ export interface QuickCommand {
15
15
  icon?: string;
16
16
  }
17
17
 
18
+ export interface ChatIdentity {
19
+ name: string;
20
+ tagline?: string;
21
+ }
22
+
23
+ export interface ChatWelcome {
24
+ title: string;
25
+ subtitle?: string;
26
+ }
27
+
18
28
  interface ChatConfigStore {
19
29
  enableImageUpload: boolean;
20
30
  enableVideoUpload: boolean;
@@ -22,18 +32,27 @@ interface ChatConfigStore {
22
32
  enableVoiceInput: boolean;
23
33
  defaultInputMode: 'TEXT' | 'VOICE';
24
34
  quickCommands: QuickCommand[];
35
+ /** 身份与欢迎区是构建期展示配置,不经 HELLO_ACK 水合 */
36
+ identity?: ChatIdentity;
37
+ welcome?: ChatWelcome;
38
+ retryOnError: boolean;
25
39
  /** HELLO_ACK settings 水合:服务端单一真源;undefined 键保留构建期快照(五键整组语义,禁部分水合) */
26
40
  applyServerSettings: (settings: ChatUiSettings | undefined) => void;
27
41
  }
28
42
 
43
+ // SSR / 探针注入点:浏览器生产环境不设置,零影响(探针看不到配置会误判)。
44
+ const ssrSnapshot = ((globalThis as { __TBOX_CHAT_CONFIG__?: Record<string, unknown> }).__TBOX_CHAT_CONFIG__ ?? {});
29
45
  export const useChatConfigStore = create<ChatConfigStore>()((set) => ({
30
- // kit 内建缺省(应用快照经 configureChatConfigDefaults 覆盖)
31
- enableImageUpload: true,
32
- enableVideoUpload: true,
33
- enableTTS: true,
34
- enableVoiceInput: true,
35
- defaultInputMode: 'TEXT',
36
- quickCommands: [],
46
+ // kit 内建缺省(应用快照经 configureChatConfigDefaults 覆盖;SSR 探针经 globalThis 注入)
47
+ enableImageUpload: (ssrSnapshot['enableImageUpload'] as boolean | undefined) ?? true,
48
+ enableVideoUpload: (ssrSnapshot['enableVideoUpload'] as boolean | undefined) ?? true,
49
+ enableTTS: (ssrSnapshot['enableTTS'] as boolean | undefined) ?? true,
50
+ enableVoiceInput: (ssrSnapshot['enableVoiceInput'] as boolean | undefined) ?? true,
51
+ defaultInputMode: (ssrSnapshot['defaultInputMode'] as 'TEXT' | 'VOICE' | undefined) ?? 'TEXT',
52
+ quickCommands: (ssrSnapshot['quickCommands'] as QuickCommand[] | undefined) ?? [],
53
+ identity: ssrSnapshot['identity'] as ChatIdentity | undefined,
54
+ welcome: ssrSnapshot['welcome'] as ChatWelcome | undefined,
55
+ retryOnError: true,
37
56
  applyServerSettings: (settings) =>
38
57
  set((cur) => ({
39
58
  enableImageUpload: settings?.enableImageUpload ?? cur.enableImageUpload,
@@ -58,5 +77,8 @@ export function configureChatConfigDefaults(snapshot: Record<string, unknown> |
58
77
  defaultInputMode:
59
78
  (snapshot['defaultInputMode'] as 'TEXT' | 'VOICE' | undefined) ?? cur.defaultInputMode,
60
79
  quickCommands: (snapshot['quickCommands'] as QuickCommand[] | undefined) ?? cur.quickCommands,
80
+ identity: (snapshot['identity'] as ChatIdentity | undefined) ?? cur.identity,
81
+ welcome: (snapshot['welcome'] as ChatWelcome | undefined) ?? cur.welcome,
82
+ retryOnError: (snapshot['retryOnError'] as boolean | undefined) ?? cur.retryOnError,
61
83
  }));
62
84
  }
@@ -22,6 +22,8 @@ describe('DebugButton 平台契约(tbox:debug-trace 载荷锁定)', () => {
22
22
  let postSpy: ReturnType<typeof vi.fn>;
23
23
 
24
24
  beforeEach(() => {
25
+ // 调试入口只在显式 ?debug=1 下渲染(B5:dev 构建与 iframe 预览不再触发)
26
+ window.history.replaceState({}, '', '/?debug=1');
25
27
  host = document.createElement('div');
26
28
  document.body.appendChild(host);
27
29
  root = createRoot(host);
@@ -33,6 +35,7 @@ describe('DebugButton 平台契约(tbox:debug-trace 载荷锁定)', () => {
33
35
  afterEach(() => {
34
36
  act(() => root.unmount());
35
37
  host.remove();
38
+ window.history.replaceState({}, '', '/');
36
39
  });
37
40
 
38
41
  const clickDebug = () => {