@tbox.cn/app-template-agent 1.0.0-alpha.20 → 1.0.0-alpha.22
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/{.tbox/cache/._apps-client-strict.tsbuildinfo → ._.ignore} +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/.ignore +9 -0
- 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/cache/{._apps-server-strict.tsbuildinfo → ._.eslintcache} +0 -0
- package/.tbox/cache/._apps-client.tsbuildinfo +0 -0
- package/.tbox/cache/._apps-server.tsbuildinfo +0 -0
- package/.tbox/cache/._packages-agent-ui-kit.tsbuildinfo +0 -0
- package/.tbox/cache/._packages-shared.tsbuildinfo +0 -0
- package/.tbox/cache/.eslintcache +1 -0
- package/.tbox/cache/apps-client.tsbuildinfo +1 -1
- package/.tbox/cache/apps-server.tsbuildinfo +1 -1
- package/.tbox/cache/packages-agent-ui-kit.tsbuildinfo +1 -1
- package/.tbox/default-modules.json +1 -1
- package/.tbox/factory/._chat.json +0 -0
- package/.tbox/miniapp-containers.json +1 -1
- package/AGENTS.md +1 -1
- package/apps/._AGENTS.md +0 -0
- 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/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/._home-preset-wiring.test.ts +0 -0
- package/apps/client/scripts/._home-preset-wiring.ts +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/._static-checks.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/check-evidence.mjs +61 -15
- package/apps/client/scripts/experience-checks.mjs +50 -5
- package/apps/client/scripts/in-process-checks.mjs +52 -2
- 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/{.tbox/cache/._packages-agent-ui-kit-strict.tsbuildinfo → apps/client/scripts/lib/._tool-cards-static.mjs} +0 -0
- package/apps/client/scripts/lib/tool-cards-static.mjs +91 -0
- package/apps/client/scripts/probe-checks.mjs +1 -0
- package/apps/client/src/._app.config.ts +0 -0
- package/apps/client/src/._vite-env.d.ts +0 -0
- package/apps/client/src/cards/._AGENTS.md +0 -0
- package/apps/client/src/cards/._home-preset.test.ts +0 -0
- package/apps/client/src/cards/._home-preset.ts +0 -0
- package/apps/client/src/cards/._registry.ts +0 -0
- package/apps/client/src/pages/._page.tsx +0 -0
- package/apps/client/src/pages/index/._index.tsx +0 -0
- package/apps/client/src/store/._chat.ts +0 -0
- package/apps/client/src/styles/._brand.css +0 -0
- package/apps/client/src/styles/._tailwind.css +0 -0
- package/apps/client/src/test/._setup.ts +0 -0
- 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/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/actions/._AGENTS.md +0 -0
- package/apps/server/src/cards/._AGENTS.md +0 -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/tools/._AGENTS.md +0 -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/config/._AGENTS.md +0 -0
- package/config/._README.md +0 -0
- package/config/._agent.jsonc +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/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/._errors.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/card.md +1 -1
- package/docs/agent/errors.md +4 -1
- package/docs/agent/kit.md +6 -5
- package/docs/agent/shell.md +34 -3
- package/docs/agent/style.md +3 -3
- 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/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/tests/._provider-custom.test.ts +0 -0
- package/package.json +5 -4
- 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/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 +20 -5
- package/packages/agent-ui-kit/package.json +1 -1
- 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/._contract.test.tsx +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 +50 -12
- package/packages/agent-ui-kit/src/card/._action-list-pending.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._confirm-fields.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/primitives.tsx +38 -17
- package/packages/agent-ui-kit/src/card/view-card.tsx +4 -1
- package/packages/agent-ui-kit/src/chat-config.test.ts +19 -1
- package/packages/agent-ui-kit/src/chat-config.ts +23 -1
- package/packages/agent-ui-kit/src/components/._CardRenderer.tsx +0 -0
- package/packages/agent-ui-kit/src/components/._HistoryList.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/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/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/._use-auto-rows.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/._use-auto-rows.ts +0 -0
- package/packages/agent-ui-kit/src/components/ChatInput/index.tsx +1 -1
- 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/HistoryEntry/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +3 -1
- package/packages/agent-ui-kit/src/components/MediaList/._index.tsx +0 -0
- 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/PullDownIndicator/._index.tsx +0 -0
- 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 +55 -0
- package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +72 -11
- package/packages/agent-ui-kit/src/components/ReasoningBlock/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/ScrollToBottomButton/._index.tsx +0 -0
- package/{.tbox/cache/._packages-shared-strict.tsbuildinfo → packages/agent-ui-kit/src/components/StarterQuestions/._index.test.tsx} +0 -0
- package/packages/agent-ui-kit/src/components/StarterQuestions/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/StarterQuestions/index.test.tsx +115 -0
- package/packages/agent-ui-kit/src/components/StarterQuestions/index.tsx +61 -0
- 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/contract.test.tsx +13 -1
- 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/._use-stick-to-bottom.test.tsx +0 -0
- package/packages/agent-ui-kit/src/hooks/._use-stick-to-bottom.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/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/shell.contract.json +11 -4
- package/packages/agent-ui-kit/src/shell.test.ts +9 -5
- 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 +10 -5
- 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/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/src/._index.ts +0 -0
- package/pnpm-lock.template.yaml +241 -245
- package/pnpm-workspace.template.yaml +11 -11
- package/profiles/._mall.json +0 -0
- package/profiles/mall/._TEMPLATE.md +0 -0
- package/profiles/mall/._chat.overrides.json +0 -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.json +14 -3
- package/scenarios/._README.md +0 -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/._interaction-probe.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/check-fast.mjs +3 -1
- package/scripts/checks.json +42 -3
- package/scripts/lib/._chrome-pipe.mjs +0 -0
- package/scripts/lib/._geometry-kernel.mjs +0 -0
- package/scripts/shell-probe.mjs +82 -5
- package/scripts/storyboard.mjs +37 -0
- package/.tbox/cache/apps-client-strict.tsbuildinfo +0 -1
- package/.tbox/cache/apps-server-strict.tsbuildinfo +0 -1
- package/.tbox/cache/packages-agent-ui-kit-strict.tsbuildinfo +0 -1
- package/.tbox/cache/packages-shared-strict.tsbuildinfo +0 -1
|
@@ -203,10 +203,11 @@ const BUTTON_VARIANT = {
|
|
|
203
203
|
link: 'w-auto border-0 bg-transparent font-medium text-primary',
|
|
204
204
|
} as const;
|
|
205
205
|
|
|
206
|
-
/** 尺寸档:`sm` 只压视觉,命中区仍由 `min-h-11` 保证 ≥44px
|
|
206
|
+
/** 尺寸档:`sm` 只压视觉,命中区仍由 `min-h-11 min-w-11` 保证 ≥44×44px;
|
|
207
|
+
* `w-full` 变体宽度天然覆盖;收缩槽(Ticket 右侧等)里 2 字中文按钮也因此不再缩到 40px。 */
|
|
207
208
|
const BUTTON_SIZE = {
|
|
208
|
-
md: 'min-h-11 px-4 py-2.5 text-sm',
|
|
209
|
-
sm: 'min-h-11 px-3 py-1.5 text-xs',
|
|
209
|
+
md: 'min-h-11 min-w-11 px-4 py-2.5 text-sm',
|
|
210
|
+
sm: 'min-h-11 min-w-11 px-3 py-1.5 text-xs',
|
|
210
211
|
} as const;
|
|
211
212
|
|
|
212
213
|
/** `link` 变体的内距单独给:它不是胶囊,用胶囊内距会撑出一大块空白。 */
|
|
@@ -353,20 +354,34 @@ export interface TicketProps {
|
|
|
353
354
|
tone?: 'primary' | 'muted';
|
|
354
355
|
}
|
|
355
356
|
|
|
356
|
-
/**
|
|
357
|
+
/**
|
|
358
|
+
* 票券形:券、凭证、卡包条目。
|
|
359
|
+
*
|
|
360
|
+
* 两层布局(2026-11):左面额竖列(票根虚线分隔)+ 右侧上下两层——顶层「券名(两行截断)+
|
|
361
|
+
* 状态胶囊」、底层「说明 + 动作」。原四栏同排在 320px 宽度下券名仅剩 ~76px(窄屏 9 字
|
|
362
|
+
* 券名必截断、2 字按钮触区缩水);双层把券名行宽让到 status 左侧全量,动作行独立保障命中区。
|
|
363
|
+
*/
|
|
357
364
|
export function Ticket({ amount, title, condition, meta, status, action, tone = 'primary' }: TicketProps) {
|
|
358
365
|
return (
|
|
359
|
-
<div className={`tbox-ticket tbox-ticket--${tone} flex items-
|
|
360
|
-
<div className="tbox-ticket__main flex shrink-0 flex-col gap-
|
|
361
|
-
<span className={`tbox-ticket__amount text-
|
|
362
|
-
{condition ? <span className="tbox-ticket__condition text-xs text-secondary-foreground">{condition}</span> : null}
|
|
366
|
+
<div className={`tbox-ticket tbox-ticket--${tone} flex items-stretch gap-3 rounded-lg border border-dashed p-3 ${TICKET_TONE[tone]}`}>
|
|
367
|
+
<div className="tbox-ticket__main flex shrink-0 flex-col justify-center gap-0.5 border-r border-dashed border-border pr-2.5 text-center">
|
|
368
|
+
<span className={`tbox-ticket__amount whitespace-nowrap text-xl font-bold tabular-nums leading-tight ${tone === 'muted' ? 'text-muted-foreground' : 'text-primary'}`}>{amount}</span>
|
|
369
|
+
{condition ? <span className="tbox-ticket__condition text-xs leading-snug text-secondary-foreground">{condition}</span> : null}
|
|
363
370
|
</div>
|
|
364
|
-
<div className="tbox-ticket__body min-w-0 flex-1">
|
|
365
|
-
{title
|
|
366
|
-
|
|
371
|
+
<div className="tbox-ticket__body flex min-w-0 flex-1 flex-col justify-center gap-1.5">
|
|
372
|
+
{title || status ? (
|
|
373
|
+
<div className="flex items-start justify-between gap-2">
|
|
374
|
+
{title ? <div className="tbox-ticket__title min-w-0 flex-1 line-clamp-2 text-sm font-semibold leading-snug text-foreground">{title}</div> : null}
|
|
375
|
+
{status ? <div className="tbox-ticket__status shrink-0">{status}</div> : null}
|
|
376
|
+
</div>
|
|
377
|
+
) : null}
|
|
378
|
+
{meta || action ? (
|
|
379
|
+
<div className="flex items-center justify-between gap-2">
|
|
380
|
+
{meta ? <div className="tbox-ticket__meta min-w-0 flex-1 text-xs leading-snug text-muted-foreground">{meta}</div> : null}
|
|
381
|
+
{action ? <div className="tbox-ticket__action shrink-0">{action}</div> : null}
|
|
382
|
+
</div>
|
|
383
|
+
) : null}
|
|
367
384
|
</div>
|
|
368
|
-
{status ? <div className="tbox-ticket__status shrink-0">{status}</div> : null}
|
|
369
|
-
{action ? <div className="tbox-ticket__action shrink-0">{action}</div> : null}
|
|
370
385
|
</div>
|
|
371
386
|
);
|
|
372
387
|
}
|
|
@@ -473,13 +488,19 @@ export interface StatItem {
|
|
|
473
488
|
hint?: ReactNode;
|
|
474
489
|
}
|
|
475
490
|
|
|
476
|
-
/**
|
|
491
|
+
/**
|
|
492
|
+
* 并列数值格(两到四格):积分/余额、车位/时长、行程 KPI。
|
|
493
|
+
*
|
|
494
|
+
* 四格在窄视口(<sm)折 2×2:flex 等分下每格内宽仅 ~57px,「¥238/人」这类带单位
|
|
495
|
+
* 数值必折行(真实构建实测);sm 视口起飞回 4 列。数值一律 tabular-nums + 不折行。
|
|
496
|
+
*/
|
|
477
497
|
export function StatGrid({ items }: { items: StatItem[] }) {
|
|
498
|
+
const grid = items.length >= 4 ? 'grid grid-cols-2 gap-1.5 sm:grid-cols-4' : 'flex gap-1.5';
|
|
478
499
|
return (
|
|
479
|
-
<div className=
|
|
500
|
+
<div className={`tbox-stats ${grid}`}>
|
|
480
501
|
{items.map((item, index) => (
|
|
481
|
-
<div className="tbox-stats__item flex flex-1 flex-col gap-1 rounded-md bg-muted p-2.5 text-center" key={index}>
|
|
482
|
-
<span className="tbox-stats__value text-lg font-bold text-foreground">{item.value}</span>
|
|
502
|
+
<div className="tbox-stats__item flex min-w-0 flex-1 flex-col gap-1 rounded-md bg-muted p-2.5 text-center" key={index}>
|
|
503
|
+
<span className="tbox-stats__value whitespace-nowrap tabular-nums text-lg font-bold text-foreground">{item.value}</span>
|
|
483
504
|
<span className="tbox-stats__label text-xs text-muted-foreground">{item.label}</span>
|
|
484
505
|
{item.hint ? <span className="tbox-stats__hint text-xs text-secondary-foreground">{item.hint}</span> : null}
|
|
485
506
|
</div>
|
|
@@ -222,6 +222,9 @@ function renderBlock(
|
|
|
222
222
|
case 'list':
|
|
223
223
|
return (
|
|
224
224
|
<div className="tbox-view-list flex flex-col gap-2.5">
|
|
225
|
+
{block.title ? (
|
|
226
|
+
<div className="tbox-view-list__title text-xs font-medium tracking-wide text-muted-foreground">{block.title}</div>
|
|
227
|
+
) : null}
|
|
225
228
|
{block.items.map((item, index) => (
|
|
226
229
|
<EntityRow
|
|
227
230
|
key={item.title + '-' + index}
|
|
@@ -296,7 +299,7 @@ export function ViewCard({
|
|
|
296
299
|
}) {
|
|
297
300
|
let safeView: CardView;
|
|
298
301
|
try {
|
|
299
|
-
safeView = normalizeCardView(view);
|
|
302
|
+
safeView = normalizeCardView(view, { emptyMode: 'drop' });
|
|
300
303
|
} catch {
|
|
301
304
|
return (
|
|
302
305
|
<Card>
|
|
@@ -11,7 +11,7 @@ const reset = () => {
|
|
|
11
11
|
quickCommands: [],
|
|
12
12
|
retryOnError: true,
|
|
13
13
|
});
|
|
14
|
-
useChatConfigStore.setState({ welcome: undefined });
|
|
14
|
+
useChatConfigStore.setState({ welcome: undefined, starterQuestions: undefined });
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
describe('chat 设置的构建期快照', () => {
|
|
@@ -48,4 +48,22 @@ describe('chat 设置的构建期快照', () => {
|
|
|
48
48
|
const state = useChatConfigStore.getState() as unknown as Record<string, unknown>;
|
|
49
49
|
expect('identity' in state).toBe(false);
|
|
50
50
|
});
|
|
51
|
+
|
|
52
|
+
it('L0 声明式首页:welcome.badge + starterQuestions 随快照注入且不改缺省(2026-11)', () => {
|
|
53
|
+
reset();
|
|
54
|
+
configureChatConfigDefaults({
|
|
55
|
+
welcome: { title: '小满客服', subtitle: '订单物流都能问我', surface: 'brand', badge: '7×24 智能售后' },
|
|
56
|
+
starterQuestions: { title: '猜你想问', pageSize: 3, items: [{ label: '我的订单到哪了?' }, { label: '申请退款', query: '我想申请退款' }] },
|
|
57
|
+
});
|
|
58
|
+
const state = useChatConfigStore.getState();
|
|
59
|
+
expect(state.welcome?.badge).toBe('7×24 智能售后');
|
|
60
|
+
expect(state.starterQuestions?.items).toHaveLength(2);
|
|
61
|
+
expect(state.starterQuestions?.items[0]?.query).toBeUndefined();
|
|
62
|
+
expect(state.starterQuestions?.items[1]?.query).toBe('我想申请退款');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('starterQuestions 缺省为 undefined(无配置零渲染)', () => {
|
|
66
|
+
reset();
|
|
67
|
+
expect(useChatConfigStore.getState().starterQuestions).toBeUndefined();
|
|
68
|
+
});
|
|
51
69
|
});
|
|
@@ -9,17 +9,35 @@ import { create } from 'zustand';
|
|
|
9
9
|
import type { ChatUiSettings } from '@tbox.cn/app-agent-sdk-client';
|
|
10
10
|
|
|
11
11
|
export interface QuickCommand {
|
|
12
|
-
/** 纯文案;前导星标/图标由 QuickCommands 组件渲染,不要写进 label */
|
|
12
|
+
/** 纯文案;前导星标/图标由 QuickCommands 组件渲染,不要写进 label(两列网格建议 2–8 字) */
|
|
13
13
|
label: string;
|
|
14
14
|
query: string;
|
|
15
15
|
icon?: string;
|
|
16
|
+
/**
|
|
17
|
+
* 可选短副文案(≤24 字):空态首屏把快捷项升级为两列服务卡(图标托盘 + 标题 + 副文案),
|
|
18
|
+
* 对话态自动收敛回单行胶囊——同一份配置双态复用,零重复维护(2026-11 L0 声明式首页)。
|
|
19
|
+
*/
|
|
20
|
+
description?: string;
|
|
16
21
|
}
|
|
17
22
|
|
|
23
|
+
/** 空态「猜你想问」条目(chat.json starterQuestions.items) */
|
|
24
|
+
export interface StarterQuestionItem {
|
|
25
|
+
label: string;
|
|
26
|
+
/** 缺省点击发送 label 原文 */
|
|
27
|
+
query?: string;
|
|
28
|
+
}
|
|
18
29
|
|
|
30
|
+
export interface ChatStarterQuestions {
|
|
31
|
+
title?: string;
|
|
32
|
+
pageSize?: number;
|
|
33
|
+
items: StarterQuestionItem[];
|
|
34
|
+
}
|
|
19
35
|
|
|
20
36
|
export interface ChatWelcome {
|
|
21
37
|
title: string;
|
|
22
38
|
subtitle?: string;
|
|
39
|
+
/** 顶部短身份角标(≤16 字) */
|
|
40
|
+
badge?: string;
|
|
23
41
|
/** 欢迎区表面变体(只消费既有主题变量;缺省 default) */
|
|
24
42
|
surface?: 'default' | 'brand' | 'subtle';
|
|
25
43
|
}
|
|
@@ -37,6 +55,8 @@ interface ChatConfigStore {
|
|
|
37
55
|
inputMaxRows: number;
|
|
38
56
|
/** 欢迎区是构建期展示配置,不经 HELLO_ACK 水合 */
|
|
39
57
|
welcome?: ChatWelcome;
|
|
58
|
+
/** 空态「猜你想问」是构建期展示配置(L0 首页),不经 HELLO_ACK 水合 */
|
|
59
|
+
starterQuestions?: ChatStarterQuestions;
|
|
40
60
|
retryOnError: boolean;
|
|
41
61
|
/** HELLO_ACK settings 水合:服务端单一真源;undefined 键保留构建期快照(五键整组语义,禁部分水合) */
|
|
42
62
|
applyServerSettings: (settings: ChatUiSettings | undefined) => void;
|
|
@@ -55,6 +75,7 @@ export const useChatConfigStore = create<ChatConfigStore>()((set) => ({
|
|
|
55
75
|
inputMinRows: 1,
|
|
56
76
|
inputMaxRows: 4,
|
|
57
77
|
welcome: ssrSnapshot['welcome'] as ChatWelcome | undefined,
|
|
78
|
+
starterQuestions: ssrSnapshot['starterQuestions'] as ChatStarterQuestions | undefined,
|
|
58
79
|
retryOnError: true,
|
|
59
80
|
applyServerSettings: (settings) =>
|
|
60
81
|
set((cur) => ({
|
|
@@ -102,6 +123,7 @@ export function configureChatConfigDefaults(snapshot: Record<string, unknown> |
|
|
|
102
123
|
inputMinRows: readRows(snapshot['input'], 'minRows') ?? cur.inputMinRows,
|
|
103
124
|
inputMaxRows: readRows(snapshot['input'], 'maxRows') ?? cur.inputMaxRows,
|
|
104
125
|
welcome: (snapshot['welcome'] as ChatWelcome | undefined) ?? cur.welcome,
|
|
126
|
+
starterQuestions: (snapshot['starterQuestions'] as ChatStarterQuestions | undefined) ?? cur.starterQuestions,
|
|
105
127
|
retryOnError: (snapshot['retryOnError'] as boolean | undefined) ?? cur.retryOnError,
|
|
106
128
|
}));
|
|
107
129
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -295,7 +295,7 @@ export function ChatInput({
|
|
|
295
295
|
</div>
|
|
296
296
|
)}
|
|
297
297
|
|
|
298
|
-
{disclaimer && <div className="tbox-chat-input__disclaimer mt-[5px] text-center
|
|
298
|
+
{disclaimer && <div className="tbox-chat-input__disclaimer mt-[5px] text-center leading-[15px] text-muted-foreground" style={{ fontSize: 10 }}>{disclaimer}</div>}
|
|
299
299
|
|
|
300
300
|
<VoiceRecordingOverlay
|
|
301
301
|
visible={voice.overlayVisible}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -32,7 +32,9 @@ export default function HistoryEntry({
|
|
|
32
32
|
<button
|
|
33
33
|
type="button"
|
|
34
34
|
data-tbox-control="history"
|
|
35
|
-
|
|
35
|
+
// 紧凑胶囊的可见高度为 22px,按钮上下各保留 11px 点击区。
|
|
36
|
+
className={`history-entry__button inline-flex min-h-11 appearance-none items-center gap-[5px] rounded-full border-0 font-normal text-muted-foreground transition-colors duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] [font-family:inherit] disabled:cursor-default ${compact ? 'relative isolate -my-[11px] bg-transparent px-3 leading-4 before:pointer-events-none before:absolute before:inset-x-0 before:inset-y-[11px] before:-z-10 before:rounded-full before:bg-muted active:before:bg-border' : 'bg-muted px-4 py-1 text-sm leading-[18px] active:bg-border'}`}
|
|
37
|
+
style={compact ? { fontSize: 11.5 } : undefined}
|
|
36
38
|
disabled={disabled}
|
|
37
39
|
onClick={onLoad}
|
|
38
40
|
>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -118,4 +118,59 @@ describe('QuickCommands 快捷胶囊', () => {
|
|
|
118
118
|
expect(buttons[1]?.querySelector('img')?.getAttribute('src')).toBe(STATIC_COMMANDS[1].icon);
|
|
119
119
|
expect(buttons[2]?.querySelector('svg[aria-hidden="true"]')).not.toBeNull();
|
|
120
120
|
});
|
|
121
|
+
|
|
122
|
+
it('L0 服务卡模式:带 description 时升级为图标托盘 + 标题/副文案,奇数末项跨两列不落单', () => {
|
|
123
|
+
configureChatConfigDefaults({
|
|
124
|
+
quickCommands: [
|
|
125
|
+
{ label: '查订单物流', query: '帮我查询最近的订单物流', icon: 'icon:receipt', description: '实时轨迹与签收状态' },
|
|
126
|
+
{ label: '申请退换货', query: '我想申请退换货', icon: 'icon:gift', description: '签收后 7 天可退' },
|
|
127
|
+
{ label: '商品咨询', query: '咨询商品规格与库存', icon: 'icon:info', description: '尺寸/材质/发货时效' },
|
|
128
|
+
],
|
|
129
|
+
});
|
|
130
|
+
const onCommand = vi.fn();
|
|
131
|
+
const container = document.createElement('div');
|
|
132
|
+
document.body.appendChild(container);
|
|
133
|
+
renderWithKit(container, <QuickCommands variant="grid" onCommand={onCommand} />);
|
|
134
|
+
|
|
135
|
+
const buttons = [...container.querySelectorAll('button')];
|
|
136
|
+
expect(buttons).toHaveLength(3);
|
|
137
|
+
// 奇数末项(第 3 个)跨两列:col-span-2 不落单。
|
|
138
|
+
expect(buttons[2].className).toContain('col-span-2');
|
|
139
|
+
// 服务卡形态:图标托盘 + 标题 + 副文案同框。
|
|
140
|
+
expect(buttons[0].textContent).toContain('查订单物流');
|
|
141
|
+
expect(buttons[0].textContent).toContain('实时轨迹与签收状态');
|
|
142
|
+
expect(buttons[0].querySelector('svg[aria-hidden="true"]')).not.toBeNull();
|
|
143
|
+
flushSync(() => buttons[0].click());
|
|
144
|
+
expect(onCommand).toHaveBeenCalledWith('帮我查询最近的订单物流');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('单项服务卡不跨列也不报错(oddTail 需要 >=3 条)', () => {
|
|
148
|
+
configureChatConfigDefaults({
|
|
149
|
+
quickCommands: [
|
|
150
|
+
{ label: '唯一服务', query: '唯一的完整问句', icon: 'icon:storefront', description: '只有一项' },
|
|
151
|
+
],
|
|
152
|
+
});
|
|
153
|
+
const container = document.createElement('div');
|
|
154
|
+
document.body.appendChild(container);
|
|
155
|
+
renderWithKit(container, <QuickCommands variant="grid" onCommand={vi.fn()} />);
|
|
156
|
+
const buttons = [...container.querySelectorAll('button')];
|
|
157
|
+
expect(buttons).toHaveLength(1);
|
|
158
|
+
expect(buttons[0].className).not.toContain('col-span-2');
|
|
159
|
+
expect(buttons[0].textContent).toContain('只有一项');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('无 description 的网格保持胶囊形态,不受 L0 服务卡分支影响', () => {
|
|
163
|
+
configureChatConfigDefaults({
|
|
164
|
+
quickCommands: [
|
|
165
|
+
{ label: '停车缴费', query: '查询停车费并缴费' },
|
|
166
|
+
{ label: '碰一下入会', query: '碰一下入会', icon: 'icon:qr-code' },
|
|
167
|
+
],
|
|
168
|
+
});
|
|
169
|
+
const container = document.createElement('div');
|
|
170
|
+
document.body.appendChild(container);
|
|
171
|
+
renderWithKit(container, <QuickCommands variant="grid" onCommand={vi.fn()} />);
|
|
172
|
+
const buttons = [...container.querySelectorAll('button')];
|
|
173
|
+
expect(buttons[0].className).not.toContain('col-span-2');
|
|
174
|
+
expect(buttons[1].querySelector('svg[aria-hidden="true"]')).not.toBeNull();
|
|
175
|
+
});
|
|
121
176
|
});
|
|
@@ -1,20 +1,59 @@
|
|
|
1
1
|
// 服务端 HelloAck.chatConfig.quickCommands 优先;旧服务端缺省 icon 时按 label 合并本地配置。
|
|
2
2
|
// label 只写纯文字;前面的星标由本组件渲染(icon 字段或默认 ✦),不要把 ✦/emoji 写进 label。
|
|
3
3
|
//
|
|
4
|
-
//
|
|
4
|
+
// 欢迎区用两列(条目带 description 时自动升级为「图标托盘 + 标题 + 副文案」服务卡,
|
|
5
|
+
// 奇数末项跨两列不落单——2026-11 L0 声明式首页);主题选择紧凑布局时输入区使用紧凑单行。
|
|
5
6
|
import { useEffect, useRef, useState } from 'react';
|
|
6
7
|
import { useChatConfigStore } from '../../chat-config';
|
|
7
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
Calendar,
|
|
10
|
+
Clock,
|
|
11
|
+
Coins,
|
|
12
|
+
CreditCard,
|
|
13
|
+
Gift,
|
|
14
|
+
Info,
|
|
15
|
+
MapPin,
|
|
16
|
+
MapTrifold,
|
|
17
|
+
QrCode,
|
|
18
|
+
Receipt,
|
|
19
|
+
Sparkle,
|
|
20
|
+
Star,
|
|
21
|
+
Storefront,
|
|
22
|
+
Ticket,
|
|
23
|
+
User,
|
|
24
|
+
Warning,
|
|
25
|
+
} from '../../icons';
|
|
8
26
|
import { useChatStore } from '../../store-context';
|
|
9
27
|
import starIcon from '../../../assets/quick-command-star.svg';
|
|
10
28
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
29
|
+
/** chat.json `icon:*` 内置语义图标白名单(服务端 quickCommands[].icon 与 starter 同源词表)。 */
|
|
30
|
+
const VECTOR_ICONS = {
|
|
31
|
+
'icon:calendar': Calendar,
|
|
32
|
+
'icon:clock': Clock,
|
|
33
|
+
'icon:coins': Coins,
|
|
34
|
+
'icon:credit-card': CreditCard,
|
|
35
|
+
'icon:gift': Gift,
|
|
36
|
+
'icon:info': Info,
|
|
37
|
+
'icon:map-pin': MapPin,
|
|
38
|
+
'icon:map': MapTrifold,
|
|
39
|
+
'icon:qr-code': QrCode,
|
|
40
|
+
'icon:receipt': Receipt,
|
|
41
|
+
'icon:sparkle': Sparkle,
|
|
42
|
+
'icon:star': Star,
|
|
43
|
+
'icon:storefront': Storefront,
|
|
44
|
+
'icon:ticket': Ticket,
|
|
45
|
+
'icon:user': User,
|
|
46
|
+
'icon:warning': Warning,
|
|
47
|
+
} as const;
|
|
48
|
+
|
|
49
|
+
function QuickCommandIcon({ icon, sizePx = 16, tone }: { icon?: string; sizePx?: 4 | 5 | 16 | 20; tone?: string }) {
|
|
50
|
+
const VectorIcon = icon ? VECTOR_ICONS[icon as keyof typeof VECTOR_ICONS] : undefined;
|
|
51
|
+
if (VectorIcon) {
|
|
52
|
+
return <VectorIcon size={sizePx} weight="fill" className={`quick-commands__icon shrink-0 ${tone ?? 'text-secondary-foreground'}`} aria-hidden="true" />;
|
|
14
53
|
}
|
|
15
54
|
return (
|
|
16
55
|
<img
|
|
17
|
-
className=
|
|
56
|
+
className={`quick-commands__icon ${sizePx >= 20 ? 'size-5' : 'size-4'} shrink-0 object-contain`}
|
|
18
57
|
src={icon || starIcon}
|
|
19
58
|
alt=""
|
|
20
59
|
onError={({ currentTarget }) => {
|
|
@@ -43,11 +82,18 @@ export function QuickCommands({
|
|
|
43
82
|
label: command.label,
|
|
44
83
|
query: command.prompt,
|
|
45
84
|
icon: command.icon || staticByLabel.get(command.label)?.icon,
|
|
85
|
+
// description 是构建期展示增强(HELLO_ACK 不投影该字段):按 label 从本地快照兜底。
|
|
86
|
+
description: staticByLabel.get(command.label)?.description,
|
|
46
87
|
}))
|
|
47
88
|
: staticCommands;
|
|
48
89
|
// hooks 必须先于任何 early return(否则空态会触发 hook 数量不一致)。
|
|
49
90
|
const grid = variant === 'grid';
|
|
50
91
|
const compact = variant === 'compact';
|
|
92
|
+
// 服务卡模式(L0 声明式首页,2026-11):任一条目带 description 整网格即升级为
|
|
93
|
+
//「图标托盘 + 标题 + 副文案」两列服务卡;对话态(row/compact)自动收敛回单行胶囊——
|
|
94
|
+
// 同一份 quickCommands 双态复用。奇数末项跨两列(col-span-2),网格不落单。
|
|
95
|
+
const serviceMode = grid && commands.some((command) => typeof command.description === 'string' && command.description.length > 0);
|
|
96
|
+
const oddTail = serviceMode && commands.length >= 3 && commands.length % 2 === 1;
|
|
51
97
|
// 行/紧凑档是横向滚动容器:滚出视口的胶囊没有任何提示。用两侧渐变层给出可滑动暗示
|
|
52
98
|
//(不用 mask-image —— 无前缀写法在 safari 16.4 基线外,会踩兼容门禁)。
|
|
53
99
|
const rowRef = useRef<HTMLDivElement>(null);
|
|
@@ -74,24 +120,39 @@ export function QuickCommands({
|
|
|
74
120
|
if (!commands.length) return null;
|
|
75
121
|
const buttonStyle = {
|
|
76
122
|
grid: 'w-full justify-start gap-1.5 rounded-[22px] border border-border bg-card px-3 py-2 text-left shadow-sm active:border-primary',
|
|
123
|
+
gridService: 'flex flex-col items-start gap-2 rounded-2xl border border-border bg-card px-4 py-3.5 text-left shadow-sm active:border-primary',
|
|
77
124
|
row: 'flex-[1_0_auto] justify-center gap-1.5 rounded-[22px] border border-border bg-card px-3 py-2 shadow-sm active:border-primary',
|
|
78
125
|
compact: 'relative isolate flex-[1_0_auto] justify-center gap-[5px] rounded-full border-0 bg-transparent px-3 before:pointer-events-none before:absolute before:inset-x-0 before:inset-y-[5px] before:-z-10 before:rounded-full before:border before:border-border before:bg-card before:shadow-[0_4px_16px_rgba(38,59,92,0.05)] before:transition-colors active:before:border-primary',
|
|
79
|
-
}[variant];
|
|
126
|
+
}[serviceMode ? 'gridService' : variant];
|
|
80
127
|
// 外层保存 `.quick-commands`(壳契约与紧凑布局的相邻兄弟断言都按它取),
|
|
81
128
|
// 内层 `.quick-commands__scroll` 只负责横向滚动。
|
|
82
129
|
// row 变体的 shadow-sm(0 4px 13px)直接画在 44px 按钮外框上,overflow-x-auto 会隐式裁切垂直溢出:
|
|
83
130
|
// 顶部留 pt-2(8px)防上沿贴边,底部保留 pb-[9px] 容纳下偏移阴影并维持与输入框的原间距;
|
|
84
131
|
// compact 变体靠 before:inset-y-[5px] 已内置 5px 上下缓冲,pb-1 即等价 9px。
|
|
85
132
|
const scrollClass = `quick-commands__scroll flex w-full items-center gap-2 overflow-x-auto px-page [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden ${compact ? 'pb-1' : 'pt-2 pb-[9px]'}`;
|
|
86
|
-
const buttons = commands.map((cmd) => (
|
|
133
|
+
const buttons = commands.map((cmd, index) => (
|
|
87
134
|
<button
|
|
88
135
|
key={cmd.label}
|
|
89
|
-
className={`quick-commands__item inline-flex min-h-11 appearance-none items-center text-foreground transition-colors duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] ${buttonStyle}`}
|
|
136
|
+
className={`quick-commands__item inline-flex min-h-11 appearance-none items-center text-foreground transition-colors duration-[var(--tbox-motion-duration-fast)] ease-[var(--tbox-motion-easing-standard)] ${buttonStyle}${oddTail && index === commands.length - 1 ? ' col-span-2' : ''}`}
|
|
90
137
|
disabled={hidden}
|
|
91
138
|
onClick={() => onCommand(cmd.query)}
|
|
92
139
|
>
|
|
93
|
-
|
|
94
|
-
|
|
140
|
+
{serviceMode ? (
|
|
141
|
+
<>
|
|
142
|
+
<span className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-primary-soft text-primary">
|
|
143
|
+
<QuickCommandIcon icon={cmd.icon} sizePx={20} tone="text-primary" />
|
|
144
|
+
</span>
|
|
145
|
+
<span className="flex min-w-0 flex-col">
|
|
146
|
+
<span className="quick-commands__label truncate text-sm font-medium text-foreground">{cmd.label}</span>
|
|
147
|
+
<span className="mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground">{cmd.description}</span>
|
|
148
|
+
</span>
|
|
149
|
+
</>
|
|
150
|
+
) : (
|
|
151
|
+
<>
|
|
152
|
+
<QuickCommandIcon icon={cmd.icon} />
|
|
153
|
+
<span className={`quick-commands__label text-sm font-medium leading-[18px] text-foreground ${grid ? 'line-clamp-2 text-left' : 'whitespace-nowrap'}`} style={compact ? { fontSize: 13 } : undefined}>{cmd.label}</span>
|
|
154
|
+
</>
|
|
155
|
+
)}
|
|
95
156
|
</button>
|
|
96
157
|
));
|
|
97
158
|
return (
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
/**
|
|
3
|
+
* StarterQuestions 测试(L0 猜你想问,2026-11 评审 P1-4 补齐):
|
|
4
|
+
* 覆盖 default title / query→label 回退 / pageSize clamp / rotate 数学 / canRotate=false。
|
|
5
|
+
*/
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
7
|
+
import { createRoot } from 'react-dom/client';
|
|
8
|
+
import { flushSync } from 'react-dom';
|
|
9
|
+
import type { ReactNode } from 'react';
|
|
10
|
+
import { create } from 'zustand';
|
|
11
|
+
import type { CoreChatStore } from '@tbox.cn/app-agent-sdk-client';
|
|
12
|
+
import { configureChatConfigDefaults, useChatConfigStore } from '../../chat-config';
|
|
13
|
+
import { KitChatProvider } from '../../store-context';
|
|
14
|
+
import { StarterQuestions } from './index';
|
|
15
|
+
|
|
16
|
+
const testStore = create<{ helloAck: unknown }>(() => ({ helloAck: null })) as unknown as CoreChatStore;
|
|
17
|
+
|
|
18
|
+
function renderWithKit(container: HTMLElement, node: ReactNode): void {
|
|
19
|
+
flushSync(() => {
|
|
20
|
+
createRoot(container).render(
|
|
21
|
+
<KitChatProvider store={testStore} cards={{}} rawCards={{}}>
|
|
22
|
+
{node}
|
|
23
|
+
</KitChatProvider>,
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const reset = () => {
|
|
29
|
+
useChatConfigStore.setState({ starterQuestions: undefined });
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
beforeEach(reset);
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
reset();
|
|
35
|
+
document.body.innerHTML = '';
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('StarterQuestions 猜你想问(L0)', () => {
|
|
39
|
+
it('渲染自定义 title,条目点击发送 query;无 query 回退 label 原文', () => {
|
|
40
|
+
configureChatConfigDefaults({
|
|
41
|
+
starterQuestions: {
|
|
42
|
+
title: '常见问题',
|
|
43
|
+
items: [{ label: '订单到哪了?', query: '我的订单到哪了?' }, { label: '怎么申请退款' }],
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
const onCommand = vi.fn();
|
|
47
|
+
const container = document.createElement('div');
|
|
48
|
+
document.body.appendChild(container);
|
|
49
|
+
renderWithKit(container, <StarterQuestions onCommand={onCommand} />);
|
|
50
|
+
|
|
51
|
+
expect(container.textContent).toContain('常见问题');
|
|
52
|
+
expect(container.textContent).toContain('订单到哪了?');
|
|
53
|
+
// 3 条以内无换一换
|
|
54
|
+
expect(container.textContent).not.toContain('换一换');
|
|
55
|
+
const [first, second] = [...container.querySelectorAll('button')];
|
|
56
|
+
flushSync(() => first?.click());
|
|
57
|
+
expect(onCommand).toHaveBeenCalledWith('我的订单到哪了?');
|
|
58
|
+
flushSync(() => second?.click());
|
|
59
|
+
expect(onCommand).toHaveBeenCalledWith('怎么申请退款');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('title 缺省为「猜你想问」;超过 pageSize 出现换一换,循环分页跨条目', () => {
|
|
63
|
+
configureChatConfigDefaults({
|
|
64
|
+
starterQuestions: {
|
|
65
|
+
pageSize: 3,
|
|
66
|
+
items: [{ label: '1' }, { label: '2' }, { label: '3' }, { label: '4' }],
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
const container = document.createElement('div');
|
|
70
|
+
document.body.appendChild(container);
|
|
71
|
+
renderWithKit(container, <StarterQuestions onCommand={vi.fn()} />);
|
|
72
|
+
|
|
73
|
+
expect(container.textContent).toContain('猜你想问');
|
|
74
|
+
expect(container.textContent).toContain('换一换');
|
|
75
|
+
// 首页 1,2,3;换一换后跨条目(cyclic:4,1,2——原组件族的同语义)。
|
|
76
|
+
expect(container.textContent).toContain('1');
|
|
77
|
+
expect(container.textContent).not.toContain('4');
|
|
78
|
+
const rotate = [...container.querySelectorAll('button')].find((b) => b.textContent?.includes('换一换'));
|
|
79
|
+
flushSync(() => rotate?.click());
|
|
80
|
+
expect(container.textContent).toContain('4');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('pageSize clamp:手工注入的越界值夹到 [2,6](SSR 快照通道不经 zod 校验)', () => {
|
|
84
|
+
configureChatConfigDefaults({
|
|
85
|
+
starterQuestions: { pageSize: 99, items: [{ label: 'a' }, { label: 'b' }, { label: 'c' }, { label: 'd' }, { label: 'e' }, { label: 'f' }, { label: 'g' }] },
|
|
86
|
+
} as never);
|
|
87
|
+
const container = document.createElement('div');
|
|
88
|
+
document.body.appendChild(container);
|
|
89
|
+
renderWithKit(container, <StarterQuestions onCommand={vi.fn()} />);
|
|
90
|
+
// clamp 到 6:首页渲染前 6 条(g 不在首页),且出现换一换。
|
|
91
|
+
expect([...container.querySelectorAll('button')].filter((b) => !b.textContent?.includes('换一换'))).toHaveLength(6);
|
|
92
|
+
|
|
93
|
+
useChatConfigStore.setState({ starterQuestions: { pageSize: 1, items: [{ label: 'x' }, { label: 'y' }, { label: 'z' }] } });
|
|
94
|
+
document.body.innerHTML = '';
|
|
95
|
+
const container2 = document.createElement('div');
|
|
96
|
+
document.body.appendChild(container2);
|
|
97
|
+
renderWithKit(container2, <StarterQuestions onCommand={vi.fn()} />);
|
|
98
|
+
// clamp 到 2:每页 2 条。
|
|
99
|
+
expect([...container2.querySelectorAll('button')].filter((b) => !b.textContent?.includes('换一换'))).toHaveLength(2);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('无配置零渲染;canRotate=false 时不渲染换一换按钮', () => {
|
|
103
|
+
const empty = document.createElement('div');
|
|
104
|
+
document.body.appendChild(empty);
|
|
105
|
+
renderWithKit(empty, <StarterQuestions onCommand={vi.fn()} />);
|
|
106
|
+
expect(empty.firstElementChild).toBeNull();
|
|
107
|
+
|
|
108
|
+
configureChatConfigDefaults({ starterQuestions: { items: [{ label: '只有一个' }] } });
|
|
109
|
+
const container = document.createElement('div');
|
|
110
|
+
document.body.appendChild(container);
|
|
111
|
+
renderWithKit(container, <StarterQuestions onCommand={vi.fn()} />);
|
|
112
|
+
expect(container.textContent).toContain('只有一个');
|
|
113
|
+
expect(container.textContent).not.toContain('换一换');
|
|
114
|
+
});
|
|
115
|
+
});
|