@tbox.cn/app-template-agent 1.0.0-alpha.1 → 1.0.0-alpha.11
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.
- package/._.gitignore +0 -0
- package/._.nvmrc +0 -0
- package/._AGENTS.md +0 -0
- package/._ENV.md +0 -0
- package/._LEGAL.md +0 -0
- package/._LICENSE +0 -0
- package/._README.md +0 -0
- package/._eslint.config.mjs +0 -0
- package/._package.json +0 -0
- package/._pnpm-lock.template.yaml +0 -0
- package/._pnpm-workspace.template.yaml +0 -0
- package/._tsconfig.base.json +0 -0
- package/.gitignore +14 -2
- package/.tbox/._app.json +0 -0
- package/.tbox/._default-modules.json +0 -0
- package/.tbox/._miniapp-containers.json +0 -0
- package/.tbox/app.json +1 -1
- package/.tbox/default-modules.json +1 -1
- package/.tbox/factory/._chat.json +0 -0
- package/.tbox/factory/chat.json +9 -0
- package/.tbox/miniapp-containers.json +1 -1
- package/AGENTS.md +64 -13
- package/ENV.md +4 -4
- package/README.md +24 -20
- package/apps/._AGENTS.md +0 -0
- package/apps/AGENTS.md +0 -4
- package/apps/client/._index.html +0 -0
- package/apps/client/._package.json +0 -0
- package/apps/client/._tsconfig.json +0 -0
- package/apps/client/._vite.config.ts +0 -0
- package/apps/client/index.html +1 -20
- package/apps/client/package.json +4 -3
- package/apps/client/scripts/._acceptance-changes.test.mjs +0 -0
- package/apps/client/scripts/._check-evidence.mjs +0 -0
- package/apps/client/scripts/._color-scan.mjs +0 -0
- package/apps/client/scripts/._color-scan.test.mjs +0 -0
- package/apps/client/scripts/._evidence-gate.mjs +0 -0
- package/apps/client/scripts/._evidence-gate.test.mjs +0 -0
- package/apps/client/scripts/._experience-checks.mjs +0 -0
- package/apps/client/scripts/._geometry-kernel.test.mjs +0 -0
- package/apps/client/scripts/._in-process-checks.mjs +0 -0
- package/apps/client/scripts/._probe-checks.mjs +0 -0
- package/apps/client/scripts/._render-card.mjs +0 -0
- package/apps/client/scripts/._sample-entries.test.mjs +0 -0
- package/apps/client/scripts/._storyboard.test.mjs +0 -0
- package/apps/client/scripts/._surface-css.mjs +0 -0
- package/apps/client/scripts/._theme-kernel.mjs +0 -0
- package/apps/client/scripts/._theme-kernel.test.mjs +0 -0
- package/apps/client/scripts/acceptance-changes.test.mjs +97 -0
- package/apps/client/scripts/check-evidence.mjs +1402 -0
- package/apps/client/scripts/color-scan.mjs +66 -0
- package/apps/client/scripts/color-scan.test.mjs +25 -0
- package/apps/client/scripts/evidence-gate.mjs +337 -0
- package/apps/client/scripts/evidence-gate.test.mjs +135 -0
- package/apps/client/scripts/experience-checks.mjs +163 -0
- package/apps/client/scripts/geometry-kernel.test.mjs +92 -0
- package/apps/client/scripts/in-process-checks.mjs +51 -0
- package/apps/client/scripts/lib/._card-registry.mjs +0 -0
- package/apps/client/scripts/lib/._card-registry.test.mjs +0 -0
- package/apps/client/scripts/lib/._evidence-inputs.mjs +0 -0
- package/apps/client/scripts/lib/._evidence-inputs.test.mjs +0 -0
- package/apps/client/scripts/lib/._static-render.mjs +0 -0
- package/apps/client/scripts/lib/._static-render.test.mjs +0 -0
- package/apps/client/scripts/lib/card-registry.mjs +81 -0
- package/apps/client/scripts/lib/card-registry.test.mjs +59 -0
- package/apps/client/scripts/lib/evidence-inputs.mjs +91 -0
- package/apps/client/scripts/lib/evidence-inputs.test.mjs +27 -0
- package/apps/client/scripts/lib/static-render.mjs +35 -0
- package/apps/client/scripts/lib/static-render.test.mjs +21 -0
- package/apps/client/scripts/probe-checks.mjs +85 -0
- package/apps/client/scripts/render-card.mjs +710 -0
- package/apps/client/scripts/sample-entries.test.mjs +31 -0
- package/apps/client/scripts/storyboard.test.mjs +149 -0
- package/apps/client/scripts/surface-css.mjs +55 -0
- package/apps/client/scripts/theme-kernel.mjs +236 -0
- package/apps/client/scripts/theme-kernel.test.mjs +136 -0
- package/apps/client/src/._app.config.ts +0 -0
- package/apps/client/src/._vite-env.d.ts +0 -0
- package/apps/client/src/app.config.ts +43 -0
- package/apps/client/src/cards/._AGENTS.md +0 -0
- package/apps/client/src/cards/._registry.ts +0 -0
- package/apps/client/src/cards/AGENTS.md +11 -0
- package/apps/client/src/pages/._page.tsx +0 -0
- package/apps/client/src/pages/index/._index.tsx +0 -0
- package/apps/client/src/pages/index/index.tsx +1 -1
- package/apps/client/src/pages/page.tsx +2 -2
- package/apps/client/src/store/._chat.ts +0 -0
- package/apps/client/src/store/chat.ts +7 -3
- package/apps/client/src/styles/._brand.css +0 -0
- package/apps/client/src/styles/._tailwind.css +0 -0
- package/apps/client/src/styles/brand.css +50 -0
- package/apps/client/src/styles/tailwind.css +326 -0
- package/apps/client/src/test/._setup.ts +0 -0
- package/apps/client/src/vite-env.d.ts +0 -2
- package/apps/client/vite.config.ts +8 -23
- package/apps/server/._package.json +0 -0
- package/apps/server/._tsconfig.json +0 -0
- package/apps/server/._tsup.config.ts +0 -0
- package/apps/server/._vitest.config.ts +0 -0
- package/apps/server/scripts/._probe.mjs +0 -0
- package/apps/server/scripts/._scenario-lib.mjs +0 -0
- package/apps/server/scripts/._scenario.mjs +0 -0
- package/apps/server/scripts/probe.mjs +387 -0
- package/apps/server/scripts/scenario-lib.mjs +295 -0
- package/apps/server/scripts/scenario.mjs +67 -0
- package/apps/server/src/._app.ts +0 -0
- package/apps/server/src/._dev.ts +0 -0
- package/apps/server/src/._index.ts +0 -0
- package/apps/server/src/._intent-routes.ts +0 -0
- package/apps/server/src/._pre-tools.ts +0 -0
- package/apps/server/src/app.ts +10 -3
- package/apps/server/src/cards/._AGENTS.md +0 -0
- package/apps/server/src/cards/AGENTS.md +19 -0
- package/apps/server/src/cli/._collect-registry.ts +0 -0
- package/apps/server/src/cli/._plugin-doctor.ts +0 -0
- package/apps/server/src/cli/._plugin-inspect.ts +0 -0
- package/apps/server/src/config/._integration.ts +0 -0
- package/apps/server/src/dev.ts +2 -2
- package/apps/server/src/index.ts +2 -2
- package/apps/server/src/pre-tools.ts +7 -16
- package/apps/server/src/tools/._AGENTS.md +0 -0
- package/apps/server/src/tools/AGENTS.md +23 -0
- package/apps/server/tests/._agent-prompt.test.ts +0 -0
- package/apps/server/tests/._cards-registry.test.ts +0 -0
- package/apps/server/tests/._deployment-loader.test.ts +0 -0
- package/apps/server/tests/._intent-dispatcher.test.ts +0 -0
- package/apps/server/tests/._tool-runtime.test.ts +0 -0
- package/apps/server/tests/helpers/._register.ts +0 -0
- package/apps/server/tests/tool-runtime.test.ts +0 -27
- package/config/._AGENTS.md +0 -0
- package/config/._README.md +0 -0
- package/config/._chat.json +0 -0
- package/config/._integrations.json +0 -0
- package/config/._llm_provider.json +0 -0
- package/config/._plugins.json +0 -0
- package/config/AGENTS.md +14 -0
- package/config/README.md +4 -4
- package/config/chat.json +25 -7
- package/config/integrations.json +1 -1
- package/docs/agent/._agent-prompt.md +0 -0
- package/docs/agent/._card-action.md +0 -0
- package/docs/agent/._card.md +0 -0
- package/docs/agent/._conversation.md +0 -0
- package/docs/agent/._kit.md +0 -0
- package/docs/agent/._shell.md +0 -0
- package/docs/agent/._state.md +0 -0
- package/docs/agent/._style.md +0 -0
- package/docs/agent/._tool-emits-card.md +0 -0
- package/docs/agent/._tool.md +0 -0
- package/docs/agent/._verify.md +0 -0
- package/docs/agent/agent-prompt.md +38 -0
- package/docs/agent/card-action.md +101 -0
- package/docs/agent/card.md +159 -0
- package/docs/agent/conversation.md +52 -0
- package/docs/agent/kit.md +80 -0
- package/docs/agent/shell.md +77 -0
- package/docs/agent/state.md +85 -0
- package/docs/agent/style.md +107 -0
- package/docs/agent/tool-emits-card.md +62 -0
- package/docs/agent/tool.md +71 -0
- package/docs/agent/verify.md +188 -0
- package/eslint.config.mjs +18 -0
- package/modules/provider-custom/._AGENTS.md +0 -0
- package/modules/provider-custom/._INTEGRATION.md +0 -0
- package/modules/provider-custom/._LICENSE +0 -0
- package/modules/provider-custom/._README.md +0 -0
- package/modules/provider-custom/._package.json +0 -0
- package/modules/provider-custom/._tbox.module.json +0 -0
- package/modules/provider-custom/._tsconfig.json +0 -0
- package/modules/provider-custom/._tsup.config.ts +0 -0
- package/modules/provider-custom/AGENTS.md +5 -5
- package/modules/provider-custom/INTEGRATION.md +2 -2
- package/modules/provider-custom/src/._index.ts +0 -0
- package/modules/provider-custom/src/server/._example-adapter.ts +0 -0
- package/modules/provider-custom/src/server/._index.ts +0 -0
- package/modules/provider-custom/src/server/example-adapter.ts +2 -2
- package/modules/provider-custom/src/server/index.ts +1 -1
- package/modules/provider-custom/tests/._provider-custom.test.ts +0 -0
- package/package.json +33 -6
- package/packages/agent-ui-kit/._AGENTS.md +0 -0
- package/packages/agent-ui-kit/._LICENSE +0 -0
- package/packages/agent-ui-kit/._README.md +0 -0
- package/packages/agent-ui-kit/._catalog.json +0 -0
- package/packages/agent-ui-kit/._package.json +0 -0
- package/packages/agent-ui-kit/._tsconfig.json +0 -0
- package/packages/agent-ui-kit/._vitest.config.ts +0 -0
- package/packages/agent-ui-kit/AGENTS.md +8 -0
- package/packages/agent-ui-kit/README.md +59 -6
- package/packages/agent-ui-kit/assets/._keyboard-circle.svg +0 -0
- package/packages/agent-ui-kit/assets/._more-circle.svg +0 -0
- package/packages/agent-ui-kit/assets/._new-chat.svg +0 -0
- package/packages/agent-ui-kit/assets/._quick-command-star.svg +0 -0
- package/packages/agent-ui-kit/assets/._send-gradient.svg +0 -0
- package/packages/agent-ui-kit/assets/._stop@2x.png +0 -0
- package/packages/agent-ui-kit/assets/._voice-circle.svg +0 -0
- package/packages/agent-ui-kit/catalog.json +855 -0
- package/packages/agent-ui-kit/package.json +24 -9
- package/packages/agent-ui-kit/src/._ChatPage.tsx +0 -0
- package/packages/agent-ui-kit/src/._chat-config.test.ts +0 -0
- package/packages/agent-ui-kit/src/._chat-config.ts +0 -0
- package/packages/agent-ui-kit/src/._icons.ts +0 -0
- package/packages/agent-ui-kit/src/._index.ts +0 -0
- package/packages/agent-ui-kit/src/._preview-provider.tsx +0 -0
- package/packages/agent-ui-kit/src/._shell.contract.json +0 -0
- package/packages/agent-ui-kit/src/._shell.test.ts +0 -0
- package/packages/agent-ui-kit/src/._shell.ts +0 -0
- package/packages/agent-ui-kit/src/._store-context.tsx +0 -0
- package/packages/agent-ui-kit/src/._surface.test.tsx +0 -0
- package/packages/agent-ui-kit/src/._surface.tsx +0 -0
- package/packages/agent-ui-kit/src/._types.ts +0 -0
- package/packages/agent-ui-kit/src/._vite-env.d.ts +0 -0
- package/packages/agent-ui-kit/src/ChatPage.tsx +115 -20
- package/packages/agent-ui-kit/src/card/._action-list-pending.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._define-card.test.ts +0 -0
- package/packages/agent-ui-kit/src/card/._define-card.ts +0 -0
- package/packages/agent-ui-kit/src/card/._primitives.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._primitives.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._use-card-actions.ts +0 -0
- package/packages/agent-ui-kit/src/card/._view-card-inline.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._view-card.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._view-card.tsx +0 -0
- package/packages/agent-ui-kit/src/card/action-list-pending.test.tsx +91 -0
- package/packages/agent-ui-kit/src/card/define-card.test.ts +25 -0
- package/packages/agent-ui-kit/src/card/define-card.ts +47 -0
- package/packages/agent-ui-kit/src/card/primitives.test.tsx +157 -0
- package/packages/agent-ui-kit/src/card/primitives.tsx +717 -0
- package/packages/agent-ui-kit/src/card/use-card-actions.ts +86 -0
- package/packages/agent-ui-kit/src/card/view-card-inline.test.tsx +42 -0
- package/packages/agent-ui-kit/src/card/view-card.test.tsx +79 -0
- package/packages/agent-ui-kit/src/card/view-card.tsx +250 -0
- package/packages/agent-ui-kit/src/chat-config.test.ts +35 -71
- package/packages/agent-ui-kit/src/chat-config.ts +29 -7
- package/packages/agent-ui-kit/src/components/._CardRenderer.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ActionBar/._DebugButton.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ActionBar/._DebugButton.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ActionBar/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ActionBar/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.test.tsx +3 -0
- package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.tsx +5 -10
- package/packages/agent-ui-kit/src/components/ActionBar/index.tsx +13 -14
- package/packages/agent-ui-kit/src/components/BottomSheet/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/index.test.tsx +97 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/index.tsx +49 -0
- package/packages/agent-ui-kit/src/components/ChatHeader/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatHeader/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatHeader/index.tsx +19 -17
- package/packages/agent-ui-kit/src/components/ChatInput/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/index.test.tsx +2 -2
- package/packages/agent-ui-kit/src/components/ChatInput/index.tsx +44 -33
- package/packages/agent-ui-kit/src/components/ChatInput/voice/._VoicePressField.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/voice/._VoiceRecordingOverlay.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/voice/._machine.ts +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/voice/._useVoicePress.ts +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/voice/VoicePressField.tsx +12 -3
- package/packages/agent-ui-kit/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +9 -9
- package/packages/agent-ui-kit/src/components/ChatInput/voice/useVoicePress.ts +1 -1
- package/packages/agent-ui-kit/src/components/HistoryEntry/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +4 -4
- package/packages/agent-ui-kit/src/components/MediaList/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/MediaList/index.tsx +42 -28
- package/packages/agent-ui-kit/src/components/MessageBubble/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/MessageBubble/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/MessageBubble/index.tsx +59 -28
- package/packages/agent-ui-kit/src/components/PullDownIndicator/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/PullDownIndicator/index.tsx +3 -4
- package/packages/agent-ui-kit/src/components/QuickCommands/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/QuickCommands/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/QuickCommands/index.test.tsx +3 -1
- package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +33 -10
- package/packages/agent-ui-kit/src/components/ReasoningBlock/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ReasoningBlock/index.tsx +14 -9
- package/packages/agent-ui-kit/src/components/ScrollToBottomButton/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.tsx +7 -5
- package/packages/agent-ui-kit/src/components/ToolCallBlock/._detail.test.ts +0 -0
- package/packages/agent-ui-kit/src/components/ToolCallBlock/._detail.ts +0 -0
- package/packages/agent-ui-kit/src/components/ToolCallBlock/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ToolCallBlock/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ToolCallBlock/._titles.ts +0 -0
- package/packages/agent-ui-kit/src/components/ToolCallBlock/index.tsx +58 -38
- package/packages/agent-ui-kit/src/hooks/._use-drag-gesture.test.ts +0 -0
- package/packages/agent-ui-kit/src/hooks/._use-drag-gesture.ts +0 -0
- package/packages/agent-ui-kit/src/hooks/._use-pull-down-history.ts +0 -0
- package/packages/agent-ui-kit/src/hooks/._use-pull-down-wheel-native.test.ts +0 -0
- package/packages/agent-ui-kit/src/hooks/._useMediaUpload.ts +0 -0
- package/packages/agent-ui-kit/src/hooks/._useTTSAutoPlay.ts +0 -0
- package/packages/agent-ui-kit/src/icons.ts +39 -0
- package/packages/agent-ui-kit/src/index.ts +76 -2
- package/packages/agent-ui-kit/src/overlay/._Overlay.tsx +0 -0
- package/packages/agent-ui-kit/src/overlay/._focus.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._index.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._inert.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._layers.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._overlay.ssr.test.tsx +0 -0
- package/packages/agent-ui-kit/src/overlay/._overlay.test.tsx +0 -0
- package/packages/agent-ui-kit/src/overlay/._presence.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._scroll-lock.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._stack.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/._use-overlay.ts +0 -0
- package/packages/agent-ui-kit/src/overlay/Overlay.tsx +154 -0
- package/packages/agent-ui-kit/src/overlay/focus.ts +53 -0
- package/packages/agent-ui-kit/src/overlay/index.ts +16 -0
- package/packages/agent-ui-kit/src/overlay/inert.ts +27 -0
- package/packages/agent-ui-kit/src/overlay/layers.ts +21 -0
- package/packages/agent-ui-kit/src/overlay/overlay.ssr.test.tsx +27 -0
- package/packages/agent-ui-kit/src/overlay/overlay.test.tsx +209 -0
- package/packages/agent-ui-kit/src/overlay/presence.ts +86 -0
- package/packages/agent-ui-kit/src/overlay/scroll-lock.ts +62 -0
- package/packages/agent-ui-kit/src/overlay/stack.ts +111 -0
- package/packages/agent-ui-kit/src/overlay/use-overlay.ts +80 -0
- package/packages/agent-ui-kit/src/preview-provider.tsx +47 -0
- package/packages/agent-ui-kit/src/shell.contract.json +75 -0
- package/packages/agent-ui-kit/src/shell.test.ts +72 -0
- package/packages/agent-ui-kit/src/shell.ts +60 -0
- package/packages/agent-ui-kit/src/surface.test.tsx +35 -0
- package/packages/agent-ui-kit/src/surface.tsx +44 -0
- package/packages/agent-ui-kit/src/test/._setup.ts +0 -0
- package/packages/agent-ui-kit/src/theme/._base.css +0 -0
- package/packages/agent-ui-kit/src/theme/._contract.json +0 -0
- package/packages/agent-ui-kit/src/theme/._motion.css +0 -0
- package/packages/agent-ui-kit/src/theme/._theme-contract.test.ts +0 -0
- package/packages/agent-ui-kit/src/theme/._theme.ts +0 -0
- package/packages/agent-ui-kit/src/theme/._tokens.css +0 -0
- package/packages/agent-ui-kit/src/theme/base.css +167 -0
- package/packages/agent-ui-kit/src/theme/contract.json +123 -2
- package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +19 -3
- package/packages/agent-ui-kit/src/theme/{tokens.less → tokens.css} +19 -20
- package/packages/agent-ui-kit/src/utils/._copyText.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._haptics.test.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._haptics.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._image-preview-host.tsx +0 -0
- package/packages/agent-ui-kit/src/utils/._imagePreview.test.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._imagePreview.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._pull-down-machine.test.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._pull-down-machine.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._session-error.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._toast.test.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._toast.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._tool-call-display.test.ts +0 -0
- package/packages/agent-ui-kit/src/utils/._tool-call-display.ts +0 -0
- package/packages/agent-ui-kit/src/utils/image-preview-host.tsx +95 -0
- package/packages/agent-ui-kit/src/utils/imagePreview.test.ts +32 -0
- package/packages/agent-ui-kit/src/utils/imagePreview.ts +14 -5
- package/packages/agent-ui-kit/src/utils/toast.test.ts +64 -0
- package/packages/agent-ui-kit/src/utils/toast.ts +100 -7
- package/packages/contracts-mall/._package.json +0 -0
- package/packages/contracts-mall/._tsconfig.json +0 -0
- package/packages/contracts-mall/src/._index.ts +0 -0
- package/packages/contracts-mall/src/._runtime.ts +0 -0
- package/packages/contracts-mall/src/server/._index.ts +0 -0
- package/packages/shared/._AGENTS.md +0 -0
- package/packages/shared/._package.json +0 -0
- package/packages/shared/._tsconfig.json +0 -0
- package/packages/shared/AGENTS.md +4 -2
- package/packages/shared/package.json +7 -0
- package/packages/shared/src/._index.ts +0 -0
- package/pnpm-lock.template.yaml +712 -779
- package/pnpm-workspace.template.yaml +19 -13
- package/profiles/._mall.json +0 -0
- package/profiles/mall/._TEMPLATE.md +0 -0
- package/profiles/mall/._chat.overrides.json +0 -0
- package/profiles/mall/chat.overrides.json +12 -0
- package/profiles/mall/config/._agent.jsonc +0 -0
- package/profiles/mall/config/._chat.json +0 -0
- package/profiles/mall/config/._knowledge.json +0 -0
- package/profiles/mall/config/chat.json +14 -6
- package/profiles/mall.json +2 -2
- package/scenarios/._README.md +0 -0
- package/scenarios/README.md +7 -0
- package/scripts/._assert-pack.mjs +0 -0
- package/scripts/._build.sh +0 -0
- package/scripts/._check-css-target.mjs +0 -0
- package/scripts/._check-fast.mjs +0 -0
- package/scripts/._check-workspace.mjs +0 -0
- package/scripts/._checks.json +0 -0
- package/scripts/._deliver.mjs +0 -0
- package/scripts/._dev-alipay.mjs +0 -0
- package/scripts/._dev.sh +0 -0
- package/scripts/._generate.mjs +0 -0
- package/scripts/._prepare.sh +0 -0
- package/scripts/._shell-probe.mjs +0 -0
- package/scripts/._smoke.mjs +0 -0
- package/scripts/._start.sh +0 -0
- package/scripts/._stop.sh +0 -0
- package/scripts/._storyboard.mjs +0 -0
- package/scripts/._verify-generated.mjs +0 -0
- package/scripts/assert-pack.mjs +48 -0
- package/scripts/check-css-target.mjs +54 -0
- package/scripts/check-fast.mjs +119 -0
- package/scripts/check-workspace.mjs +68 -19
- package/scripts/checks.json +627 -0
- package/scripts/deliver.mjs +183 -0
- package/scripts/dev-alipay.mjs +1 -1
- package/scripts/lib/._chrome-pipe.mjs +0 -0
- package/scripts/lib/._geometry-kernel.mjs +0 -0
- package/scripts/lib/chrome-pipe.mjs +95 -0
- package/scripts/lib/geometry-kernel.mjs +137 -0
- package/scripts/shell-probe.mjs +280 -0
- package/scripts/storyboard.mjs +350 -0
- package/tsconfig.base.json +1 -0
- package/apps/client/.tbox-gen/app-kind.ts +0 -1
- package/apps/client/.tbox-gen/documents/_tbox/card-preview.html +0 -38
- package/apps/client/.tbox-gen/documents/index.html +0 -39
- package/apps/client/.tbox-gen/entries/card-preview.tsx +0 -18
- package/apps/client/.tbox-gen/entries/index.tsx +0 -18
- package/apps/client/.tbox-gen/manifest.json +0 -17
- package/apps/client/.tbox-gen/registry.client.ts +0 -6
- package/apps/client/.tbox-gen/registry.server.ts +0 -15
- package/apps/client/STYLE_GUIDE.md +0 -81
- package/apps/client/VISUAL_RESTORE.md +0 -90
- package/apps/client/src/platform/AgentChatApp.tsx +0 -6
- package/apps/client/src/platform/AppShell.tsx +0 -42
- package/apps/client/src/platform/agent-runtime.ts +0 -16
- package/apps/client/src/platform/bootstrap.ts +0 -55
- package/apps/client/src/platform/card-preview-page.tsx +0 -10
- package/apps/client/src/platform/mount-page.tsx +0 -20
- package/apps/client/src/platform/state/createPersistedStore.ts +0 -19
- package/apps/server/src/tools/clock.tool.ts +0 -24
- package/apps/server/src/tools/translate.tool.ts +0 -47
- package/packages/agent-ui-kit/src/ChatPage.less +0 -62
- package/packages/agent-ui-kit/src/components/ActionBar/index.less +0 -123
- package/packages/agent-ui-kit/src/components/ChatHeader/index.less +0 -148
- package/packages/agent-ui-kit/src/components/ChatInput/index.less +0 -394
- package/packages/agent-ui-kit/src/components/HistoryEntry/index.less +0 -49
- package/packages/agent-ui-kit/src/components/MediaList/index.less +0 -241
- package/packages/agent-ui-kit/src/components/MessageBubble/index.less +0 -325
- package/packages/agent-ui-kit/src/components/PullDownIndicator/index.less +0 -32
- package/packages/agent-ui-kit/src/components/QuickCommands/index.less +0 -63
- package/packages/agent-ui-kit/src/components/ReasoningBlock/index.less +0 -90
- package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.less +0 -32
- package/packages/agent-ui-kit/src/components/ToolCallBlock/index.less +0 -312
- package/packages/agent-ui-kit/src/theme/global.less +0 -99
- package/profiles/mall/config/llm_provider.json +0 -5
- package/profiles/mall/config/plugins.json +0 -3
- /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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
expect(
|
|
32
|
-
expect(
|
|
33
|
-
expect(
|
|
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('
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -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 = () => {
|