@tbox.cn/app-template-agent 1.0.0-alpha.1 → 1.0.0-alpha.7
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 +7 -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/card-render/._demo.html +0 -0
- package/.tbox/card-render/._demo.png +0 -0
- package/.tbox/card-render/._scale-demo.audit.html +0 -0
- package/.tbox/card-render/._scale-demo.html +0 -0
- package/.tbox/card-render/baseline/._demo.png +0 -0
- package/.tbox/card-render/baseline/demo.png +0 -0
- package/.tbox/card-render/demo.html +342 -0
- package/.tbox/card-render/demo.png +0 -0
- package/.tbox/card-render/scale-demo.audit.html +984 -0
- package/.tbox/card-render/scale-demo.html +939 -0
- package/.tbox/default-modules.json +1 -1
- package/.tbox/evidence/._cards.txt +0 -0
- package/.tbox/evidence/._gate.json +0 -0
- package/.tbox/evidence/._last-gate.json +0 -0
- package/.tbox/evidence/._scenarios.json +0 -0
- package/.tbox/evidence/cards.txt +1 -0
- package/.tbox/evidence/gate.json +1 -0
- package/.tbox/evidence/last-gate.json +1 -0
- package/.tbox/evidence/scenarios.json +1 -0
- package/.tbox/miniapp-containers.json +1 -1
- package/AGENTS.md +59 -13
- package/ENV.md +4 -4
- package/README.md +22 -20
- package/apps/._AGENTS.md +0 -0
- package/apps/AGENTS.md +0 -4
- package/apps/client/._STYLE_GUIDE.md +0 -0
- package/apps/client/._VISUAL_RESTORE.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/.tbox-gen/._app-registry.ts +0 -0
- package/apps/client/.tbox-gen/._manifest.json +0 -0
- package/apps/client/.tbox-gen/._registry.client.ts +0 -0
- package/apps/client/.tbox-gen/._registry.server.ts +0 -0
- package/apps/client/.tbox-gen/app-registry.ts +3 -0
- package/apps/client/.tbox-gen/documents/._index.html +0 -0
- package/apps/client/.tbox-gen/documents/_tbox/._card-preview.html +0 -0
- package/apps/client/.tbox-gen/documents/_tbox/card-preview.html +38 -14
- package/apps/client/.tbox-gen/documents/index.html +38 -14
- package/apps/client/.tbox-gen/entries/._card-preview.tsx +0 -0
- package/apps/client/.tbox-gen/entries/._index.tsx +0 -0
- package/apps/client/.tbox-gen/entries/card-preview.tsx +3 -15
- package/apps/client/.tbox-gen/entries/index.tsx +8 -15
- package/apps/client/.tbox-gen/registry.server.ts +4 -4
- package/apps/client/STYLE_GUIDE.md +31 -64
- package/apps/client/index.html +38 -14
- package/apps/client/package.json +3 -3
- package/apps/client/scripts/._check-evidence.mjs +0 -0
- package/apps/client/scripts/._render-card.mjs +0 -0
- package/apps/client/scripts/check-evidence.mjs +831 -0
- package/apps/client/scripts/render-card.mjs +743 -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 +40 -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 +51 -0
- package/apps/client/src/styles/tailwind.css +307 -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 +5 -22
- 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 +382 -0
- package/apps/server/scripts/scenario-lib.mjs +247 -0
- package/apps/server/scripts/scenario.mjs +33 -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 +13 -0
- package/config/README.md +4 -4
- package/config/chat.json +8 -2
- 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 +96 -0
- package/docs/agent/card.md +116 -0
- package/docs/agent/conversation.md +52 -0
- package/docs/agent/kit.md +79 -0
- package/docs/agent/shell.md +76 -0
- package/docs/agent/state.md +85 -0
- package/docs/agent/style.md +95 -0
- package/docs/agent/tool-emits-card.md +57 -0
- package/docs/agent/tool.md +69 -0
- package/docs/agent/verify.md +145 -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 +13 -5
- 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 +4 -4
- 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 +842 -0
- package/packages/agent-ui-kit/package.json +8 -5
- 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/._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/._types.ts +0 -0
- package/packages/agent-ui-kit/src/._vite-env.d.ts +0 -0
- package/packages/agent-ui-kit/src/ChatPage.tsx +34 -7
- 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/define-card.ts +34 -0
- package/packages/agent-ui-kit/src/card/primitives.test.tsx +147 -0
- package/packages/agent-ui-kit/src/card/primitives.tsx +627 -0
- package/packages/agent-ui-kit/src/card/use-card-actions.ts +86 -0
- package/packages/agent-ui-kit/src/chat-config.test.ts +35 -71
- package/packages/agent-ui-kit/src/chat-config.ts +18 -0
- 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.tsx +3 -3
- package/packages/agent-ui-kit/src/components/ActionBar/index.tsx +13 -14
- 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.tsx +32 -26
- 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/HistoryEntry/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +3 -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 +52 -27
- 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.tsx +6 -6
- 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 +2 -4
- 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 +54 -36
- 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 +55 -2
- package/packages/agent-ui-kit/src/shell.contract.json +59 -0
- package/packages/agent-ui-kit/src/shell.test.ts +61 -0
- package/packages/agent-ui-kit/src/shell.ts +45 -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 +132 -0
- package/packages/agent-ui-kit/src/theme/contract.json +1 -1
- package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +3 -3
- package/packages/agent-ui-kit/src/theme/{tokens.less → tokens.css} +14 -12
- 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/._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.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/AGENTS.md +4 -2
- package/packages/shared/package.json +7 -0
- package/packages/shared/src/._index.ts +0 -0
- package/pnpm-lock.template.yaml +679 -464
- package/pnpm-workspace.template.yaml +16 -11
- package/profiles/._mall.json +0 -0
- package/profiles/mall/._TEMPLATE.md +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/config/._llm_provider.json +0 -0
- package/profiles/mall/config/._plugins.json +0 -0
- package/scenarios/._README.md +0 -0
- package/scenarios/README.md +7 -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/._compat-probe.mjs +0 -0
- package/scripts/._dev-alipay.mjs +0 -0
- package/scripts/._dev.sh +0 -0
- package/scripts/._gen-tailwind-sources.mjs +0 -0
- package/scripts/._generate.mjs +0 -0
- package/scripts/._prepare.sh +0 -0
- package/scripts/._smoke.mjs +0 -0
- package/scripts/._start.sh +0 -0
- package/scripts/._stop.sh +0 -0
- package/scripts/._verify-generated.mjs +0 -0
- package/scripts/check-css-target.mjs +69 -0
- package/scripts/check-fast.mjs +118 -0
- package/scripts/check-workspace.mjs +68 -19
- package/scripts/checks.json +253 -0
- package/scripts/compat-probe.mjs +108 -0
- package/scripts/dev-alipay.mjs +1 -1
- package/scripts/gen-tailwind-sources.mjs +55 -0
- package/tsconfig.base.json +1 -0
- package/apps/client/.tbox-gen/app-kind.ts +0 -1
- 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/packages/agent-ui-kit/src/theme/{motion.less → motion.css} +0 -0
package/apps/server/src/app.ts
CHANGED
|
@@ -60,6 +60,7 @@ import type { MallScopeAssembly } from '@app/contracts-mall';
|
|
|
60
60
|
///mall 装配原语(条件装配——未配置部署文件时零引用)
|
|
61
61
|
import {
|
|
62
62
|
createScopeSessionRegistry,
|
|
63
|
+
createAppScopeSessionRegistry,
|
|
63
64
|
createActionGrantService,
|
|
64
65
|
createModuleActionDispatcher,
|
|
65
66
|
createEffectRuntime,
|
|
@@ -442,14 +443,20 @@ export async function start(serverApp: Express = app) {
|
|
|
442
443
|
///E2:mall 装配(条件)——scope 会话 + 动作授权先行(engine attacher 依赖)
|
|
443
444
|
// buildScope 回填 mallName(ChatHeader 品牌区服务端真源;三级回退内聚于域装配)
|
|
444
445
|
// 域装配经查表(assembly 于上方 registerAll 后解析——解析点必须晚于模块注册)
|
|
446
|
+
// 无领域装配时,只要应用注册了卡片动作,就用中立会话(scope 恒 app)——否则动作会被静默丢弃
|
|
447
|
+
const hasCardActions = ctx.cardActions.getAll().size > 0;
|
|
448
|
+
const neutralScopeSessions = !assembly && hasCardActions ? createAppScopeSessionRegistry() : undefined;
|
|
445
449
|
const scopeSessions: ReturnType<typeof createScopeSessionRegistry> | undefined = assembly
|
|
446
450
|
? createScopeSessionRegistry({
|
|
447
451
|
extractScopeKey: (c) => assembly.extractScopeKey(c),
|
|
448
452
|
validateScope: (a) => assembly.validateScope(a),
|
|
449
453
|
buildScope: (a) => assembly.buildScopeWithMallName(a),
|
|
450
454
|
})
|
|
451
|
-
:
|
|
455
|
+
: neutralScopeSessions;
|
|
452
456
|
const grants = scopeSessions ? createActionGrantService({ store: ctx.state }) : undefined;
|
|
457
|
+
if (neutralScopeSessions) {
|
|
458
|
+
actionLogger.info('卡片动作用中立会话(无领域装配)', { actions: ctx.cardActions.getAll().size });
|
|
459
|
+
}
|
|
453
460
|
|
|
454
461
|
// 卡片动作 token 签发(build → attach → send;sessionId 引擎登记、scope 经 sessions 查)
|
|
455
462
|
const cardActionAttacher = grants && scopeSessions
|
|
@@ -472,7 +479,7 @@ export async function start(serverApp: Express = app) {
|
|
|
472
479
|
|
|
473
480
|
///E2:模块动作分发(依赖 scopeSessions/grants)
|
|
474
481
|
let moduleActions: ReturnType<typeof createModuleActionDispatcher> | undefined;
|
|
475
|
-
if (
|
|
482
|
+
if (scopeSessions && grants) {
|
|
476
483
|
moduleActions = createModuleActionDispatcher({
|
|
477
484
|
grants,
|
|
478
485
|
sessions: scopeSessions,
|
|
@@ -482,7 +489,7 @@ export async function start(serverApp: Express = app) {
|
|
|
482
489
|
// effect 运行时纯投影(payment/authorization 回调补签在 dispatcher step7,
|
|
483
490
|
// 客户端执行在 SDK host-effect-runner——模板零装配效果链)
|
|
484
491
|
effects: createEffectRuntime(),
|
|
485
|
-
extractScopeKey: (c) => assembly.extractScopeKey(c),
|
|
492
|
+
extractScopeKey: assembly ? (c) => assembly.extractScopeKey(c) : () => 'app',
|
|
486
493
|
});
|
|
487
494
|
for (const action of ctx.cardActions.getAll().values()) {
|
|
488
495
|
moduleActions.register(action);
|
|
Binary file
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# apps/server/src/cards
|
|
2
|
+
|
|
3
|
+
每张卡片一个文件,导出 `export const card`,`cardType` 是字符串字面量。必须与
|
|
4
|
+
`apps/client/src/cards/<同名>.card.tsx` 成对;缺一半会在 `pnpm generate` 时报
|
|
5
|
+
`CARD_PAIR_MISSING`。
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
export const card = {
|
|
9
|
+
cardType: 'order-status',
|
|
10
|
+
dataSchema: orderStatusCardSchema, // 与客户端共用 @app/shared/cards/<id>
|
|
11
|
+
displayName: '订单状态',
|
|
12
|
+
description: '一句话说明这张卡展示什么',
|
|
13
|
+
sampleData: { /* 必须能过 dataSchema,供预览与场景断言 */ },
|
|
14
|
+
schemaVersion: 1,
|
|
15
|
+
} satisfies CardMeta<typeof orderStatusCardSchema>;
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- 只有服务端文件、没有客户端文件的卡片不会被注册。
|
|
19
|
+
- 字段形状、样例与注意项见 `docs/agent/card.md`。
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/apps/server/src/dev.ts
CHANGED
|
@@ -28,10 +28,10 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const generated = await generateApp({ root });
|
|
31
|
-
const [{ registry }
|
|
31
|
+
const [{ registry }] = await Promise.all([
|
|
32
32
|
import('../../client/.tbox-gen/registry.server.ts'),
|
|
33
|
-
import('../../client/.tbox-gen/app-kind.ts'),
|
|
34
33
|
]);
|
|
34
|
+
const { appKind } = generated;
|
|
35
35
|
|
|
36
36
|
const HMR_WS_PATH = '/__vite_hmr';
|
|
37
37
|
const hmrHub = createServer();
|
package/apps/server/src/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
8
8
|
import { createLogger, createApp, getRequestContext, type AppManifest } from '@tbox.cn/app-agent-sdk-server';
|
|
9
9
|
import { injectScript } from '@tbox.cn/app-agent-sdk-server/platform';
|
|
10
10
|
import manifest from '../../client/.tbox-gen/manifest.json';
|
|
11
|
-
import
|
|
11
|
+
import appMeta from '../../../.tbox/app.json';
|
|
12
12
|
import { registry } from '../../client/.tbox-gen/registry.server';
|
|
13
13
|
import { app as legacyApp, ctx, start } from './app.js';
|
|
14
14
|
|
|
@@ -23,7 +23,7 @@ if (!existsSync(path.join(clientDir, 'index.html'))) {
|
|
|
23
23
|
const app = await createApp({
|
|
24
24
|
ctx,
|
|
25
25
|
manifest: manifest as AppManifest,
|
|
26
|
-
appKind,
|
|
26
|
+
appKind: appMeta.appKind as 'agent',
|
|
27
27
|
registry,
|
|
28
28
|
mode: 'prod',
|
|
29
29
|
clientDir,
|
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
// 铁律:不直接 import @mastra/core,经 @tbox.cn/app-agent-sdk-server 的 definePreTool 入口(单例铁律)
|
|
2
2
|
import { definePreTool } from '@tbox.cn/app-agent-sdk-server';
|
|
3
|
-
import { tool as clockTool } from './tools/clock.tool.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* 应用级前置工具声明(010):BuildEngineOptions.preTools 通道(与模块声明合并、应用覆盖模块)。
|
|
7
6
|
*
|
|
8
|
-
*
|
|
7
|
+
* 出厂为空:模板不携带演示工具,产物即产品骨架。声明形态(详见 README「前置 Tool 加速执行」节与 `docs/agent/tool.md`):
|
|
9
8
|
* ① tool —— 工具实例引用(单一真源,id/description 派生)
|
|
10
|
-
* ② routing —— 结构化路由:{ mode: 'keywords', terms }
|
|
11
|
-
* 或 { mode: 'always' } 必选候选(decide 门控;慎用防每轮噪音)
|
|
9
|
+
* ② routing —— 结构化路由:{ mode: 'keywords', terms } 宽召回词表,或 { mode: 'always' } 必选候选(慎用防每轮噪音)
|
|
12
10
|
* ③ decide —— 决策即构造:{ decision: 'run', args } = 预执行 / { decision: 'skip' } = 不生效
|
|
13
11
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* 示例(取消注释并按需补 tool 引用):
|
|
13
|
+
* definePreTool(myTool, { routing: { mode: 'keywords', terms: ['几点'] }, decide: () => ({ decision: 'run', args: {} }) })
|
|
14
|
+
*
|
|
15
|
+
* 模块自带的 preTools 走模块声明式通道(如 `--profile mall` 的 mall-info),不在此处登记。
|
|
17
16
|
*/
|
|
18
|
-
export const APP_PRE_TOOLS = [
|
|
19
|
-
definePreTool(clockTool, {
|
|
20
|
-
routing: {
|
|
21
|
-
mode: 'keywords',
|
|
22
|
-
terms: ['几点', '几点了', '现在时间', '日期', '星期几'],
|
|
23
|
-
},
|
|
24
|
-
decide: () => ({ decision: 'run', args: {} }),
|
|
25
|
-
}),
|
|
26
|
-
];
|
|
17
|
+
export const APP_PRE_TOOLS: ReturnType<typeof definePreTool>[] = [];
|
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# apps/server/src/tools
|
|
2
|
+
|
|
3
|
+
每个 `*.tool.ts` 导出 `export const tool = defineTool({...})`:
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { cardOf, defineTool } from '@tbox.cn/app-agent-sdk-server';
|
|
7
|
+
import { card as orderStatusCard } from '../cards/order-status.card';
|
|
8
|
+
|
|
9
|
+
export const tool = defineTool({
|
|
10
|
+
id: 'order-status', // 字符串字面量,扫描器读静态值
|
|
11
|
+
description: '…命中数据时结果附可展示卡片(cards)。',
|
|
12
|
+
inputSchema: z.object({}),
|
|
13
|
+
execute: async (_args, { userId, identity }) => {
|
|
14
|
+
// 用户身份从 execute 第二参取;不要兜底成固定 id。
|
|
15
|
+
const facts = { title: 'order-status', userId, source: identity.source };
|
|
16
|
+
return { ...facts, cards: [cardOf(orderStatusCard, facts, '一句话摘要')] };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- 出卡用 `cardOf(meta, data, note)`:`cardType` 由卡片 meta 推导,不写字符串。
|
|
22
|
+
- 不要声明 `outputSchema`:出参解析会剥掉保留字段 `cards`(详见 `docs/agent/tool-emits-card.md`)。
|
|
23
|
+
- 完整示例见 `docs/agent/tool.md`;新增工具优先 `pnpm exec tbox-app new feature <name>`(连带生成配套卡片)。
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
resolveMemoryStore,
|
|
8
8
|
} from '@tbox.cn/app-agent-sdk-server';
|
|
9
9
|
import { registerAll } from './helpers/register.js';
|
|
10
|
-
import { tool as translateTool } from '../src/tools/translate.tool.js';
|
|
11
10
|
|
|
12
11
|
describe('tool runtime 宿主装配(自注册闭环)', () => {
|
|
13
12
|
it('空装配(mall 模板):无模块工具,app 级工具正常注册', async () => {
|
|
@@ -35,32 +34,6 @@ describe('tool runtime 宿主装配(自注册闭环)', () => {
|
|
|
35
34
|
expect(runtime.tools.notExistedTool).toBeUndefined();
|
|
36
35
|
});
|
|
37
36
|
|
|
38
|
-
describe('translate 参数规范(D11:string 形态 + 工具内 normalize)', () => {
|
|
39
|
-
// mastra Tool.execute 为可选 + 双参签名(input, context)——测试经非空断言直调
|
|
40
|
-
const callExecute = (input: { text: string; targetLang?: string }) =>
|
|
41
|
-
translateTool.execute!(input, {} as never);
|
|
42
|
-
|
|
43
|
-
it('合法 targetLang(zh/en)→ 生效', async () => {
|
|
44
|
-
const r = await callExecute({ text: '你好', targetLang: 'en' });
|
|
45
|
-
expect(r).toMatchObject({ targetLang: 'en' });
|
|
46
|
-
const r2 = await callExecute({ text: 'hello', targetLang: 'zh' });
|
|
47
|
-
expect(r2).toMatchObject({ targetLang: 'zh' });
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('非法 targetLang → 回落自动检测(不抛)', async () => {
|
|
51
|
-
const r = await callExecute({ text: '你好', targetLang: 'fr' });
|
|
52
|
-
expect(r).toMatchObject({ targetLang: 'en' }); // 中文输入 → 自动检测回落英文
|
|
53
|
-
const r2 = await callExecute({ text: 'hello', targetLang: 'xx' });
|
|
54
|
-
expect(r2).toMatchObject({ targetLang: 'zh' }); // 英文输入 → 自动检测回落中文
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('缺省 targetLang → 自动检测', async () => {
|
|
58
|
-
const r = await callExecute({ text: '你好' });
|
|
59
|
-
expect(r).toMatchObject({ targetLang: 'en' });
|
|
60
|
-
const r2 = await callExecute({ text: 'hello' });
|
|
61
|
-
expect(r2).toMatchObject({ targetLang: 'zh' });
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
37
|
});
|
|
65
38
|
|
|
66
39
|
describe('长期记忆装配(017:mall 域默认 inmemory + mallId 隔离 scope)', () => {
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/config/AGENTS.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# config
|
|
2
|
+
|
|
3
|
+
| 文件 | 内容 | 形状查询 |
|
|
4
|
+
|---|---|---|
|
|
5
|
+
| `chat.json` | 对话壳配置:快捷问题、TTS、上传等 | `pnpm exec tbox-app schema config/chat.json` |
|
|
6
|
+
| `agent.jsonc` | 智能体提示词与行为规则(支持注释) | `pnpm exec tbox-app schema config/agent.jsonc` |
|
|
7
|
+
| `integrations.json` | 服务集成槽绑定 | `pnpm exec tbox-app schema config/integrations.json` |
|
|
8
|
+
| `llm_provider.json` | 模型 provider 选择 | `pnpm exec tbox-app schema config/llm_provider.json` |
|
|
9
|
+
| `plugins.json` | 插件开关 | — |
|
|
10
|
+
|
|
11
|
+
- 形状以 schema 命令输出为准,不要照抄文档里的示例字段。
|
|
12
|
+
- 配置在服务启动时读取;改完需重启进程。
|
|
13
|
+
- 提示词写法与常见规则见 `docs/agent/agent-prompt.md`,壳配置见 `docs/agent/shell.md`。
|
package/config/README.md
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
| `knowledge.json` | 知识库资源(按需生成) | fail-soft |
|
|
11
11
|
| `service-slots.json` | 服务词汇引导快照(create 按需生成;可由 module sync 重算) | fail-soft |
|
|
12
12
|
|
|
13
|
-
- 形状查询:`
|
|
14
|
-
- 全部配置面:`
|
|
15
|
-
- 流程知识:`
|
|
16
|
-
- 校验:`
|
|
13
|
+
- 形状查询:`pnpm exec tbox-app schema config/integrations.json`
|
|
14
|
+
- 全部配置面:`pnpm exec tbox-app schema`
|
|
15
|
+
- 流程知识:`pnpm exec tbox-app skills get integration` / `skills get provider-custom`
|
|
16
|
+
- 校验:`pnpm exec tbox-app module doctor`(㉙ config-schema)
|
|
17
17
|
- 密钥真值只放平台凭据/环境变量,**不要写进本目录的 `config.*` 字段**。
|
|
18
18
|
|
|
19
19
|
元键 `$comment` / `$schema` 仅作为文档指针,行为惰性;`agent.jsonc` 与 `plugins.json`
|
package/config/chat.json
CHANGED
|
@@ -5,7 +5,13 @@
|
|
|
5
5
|
"enableVoiceInput": true,
|
|
6
6
|
"defaultInputMode": "TEXT",
|
|
7
7
|
"quickCommands": [
|
|
8
|
-
{
|
|
9
|
-
|
|
8
|
+
{
|
|
9
|
+
"label": "你能做什么",
|
|
10
|
+
"query": "你能帮我做什么?"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"label": "开始对话",
|
|
14
|
+
"query": "你好"
|
|
15
|
+
}
|
|
10
16
|
]
|
|
11
17
|
}
|
package/config/integrations.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$comment": "配置形状:
|
|
2
|
+
"$comment": "配置形状: pnpm exec tbox-app schema config/integrations.json;接入流程: pnpm exec tbox-app skills get integration",
|
|
3
3
|
"services": {}
|
|
4
4
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# 提示词与对话配置
|
|
2
|
+
|
|
3
|
+
> 本页管:`config/agent.jsonc`(提示词)与 `config/chat.json`(壳行为)怎么改、写什么。|不管:壳组件与槽位 → [shell](shell.md)。
|
|
4
|
+
|
|
5
|
+
## 先查形状
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm exec tbox-app schema config/agent.jsonc
|
|
9
|
+
pnpm exec tbox-app schema config/chat.json
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
以命令输出为准,不要照抄本文的字段片段——形状由 schema 定义。
|
|
13
|
+
|
|
14
|
+
## 提示词
|
|
15
|
+
|
|
16
|
+
`config/agent.jsonc` 不存在时新建。要点:
|
|
17
|
+
|
|
18
|
+
- `instructions` 是字符串数组,一行一条,拼接时按换行连接。
|
|
19
|
+
- 平台规则段(出卡协议、消息格式)由 SDK 注入,**你写的是业务段**;与平台协议冲突的指令会被协议压过,写了也没用。
|
|
20
|
+
- 首行写身份句(「你是谁、服务谁」),随后按「服务范围 / 业务规则 / 沟通风格」分段。
|
|
21
|
+
- 数据类问题一律要求「先调工具拿本轮结果再回答」,不要凭历史结论作答。
|
|
22
|
+
- 操作类流程写清楚三类动作:什么时候只给信息、什么时候出确认卡、什么时候执行。
|
|
23
|
+
- 按钮语义要写明:「卡片按钮会把用户意图作为下一条消息发回来,收到即为确认,直接执行、不要重复追问」——否则模型会反复确认。
|
|
24
|
+
|
|
25
|
+
## 对话配置
|
|
26
|
+
|
|
27
|
+
`config/chat.json` 控制壳的行为,常用字段:
|
|
28
|
+
|
|
29
|
+
| 字段 | 作用 |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `quickCommands` | 首屏快捷问题:`[{ label, query }]`,点击即发送 `query` |
|
|
32
|
+
| `enableImageUpload` / `enableVideoUpload` | 上传入口 |
|
|
33
|
+
| `enableTTS` / `enableVoiceInput` | 语音相关 |
|
|
34
|
+
| `defaultInputMode` | `TEXT` / `VOICE` |
|
|
35
|
+
|
|
36
|
+
## 生效方式
|
|
37
|
+
|
|
38
|
+
两个文件都在服务启动时读取,改完重启进程。配置是 fail-soft 的:解析失败不会崩,但该段配置不生效——改完先看启动日志有没有 warn。
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# 卡片上的按钮
|
|
2
|
+
|
|
3
|
+
> 本页管:卡片按钮的两种语义(发消息 / 触发动作)、确认弹层、禁用规则、动作的入参与返回值。|不管:卡片结构 → [card](card.md);工具出卡 → [tool-emits-card](tool-emits-card.md);基元 props → [kit](kit.md)。
|
|
4
|
+
|
|
5
|
+
## 两种按钮
|
|
6
|
+
|
|
7
|
+
`useCardActions()` 给两个方法:
|
|
8
|
+
|
|
9
|
+
| 方法 | 走哪条路 | 什么时候用 |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `send(text, { displayText })` | 作为用户消息发回,模型接管 | 需要模型再判断、或要让对话记住这一步 |
|
|
12
|
+
| `invoke(actionId, input)` | 直接调用卡片动作,不过模型 | 入参确定、结果确定的写操作(领券、支付、报名) |
|
|
13
|
+
|
|
14
|
+
`input` 会作为本次调用的入参(协议里的 `formData` 通道)交给服务端 `inputSchema` 校验;不传按空对象校验。**列表卡的逐项操作靠它**——把条目 id 放进 `input`。
|
|
15
|
+
|
|
16
|
+
`send` 的第二个参数可以给 `displayText`:气泡显示这句话,实际发给模型的 `value` 可以更长。
|
|
17
|
+
|
|
18
|
+
## 门控
|
|
19
|
+
|
|
20
|
+
`disabled` 在两种情况下为 true:
|
|
21
|
+
|
|
22
|
+
- `isHistory`:历史消息里的卡片只读,点击只提示「历史卡片仅供查看」;
|
|
23
|
+
- `isGenerating`:正在生成回复,点击提示稍候。
|
|
24
|
+
|
|
25
|
+
按钮的 `disabled` 一定要接这个值,否则用户会在错误时机触发写操作。
|
|
26
|
+
|
|
27
|
+
## 令牌
|
|
28
|
+
|
|
29
|
+
`invoke` 需要动作令牌:卡片 payload 的 `actionTokens[actionId]`,由服务端在出卡时签发,随卡片数据传给组件(`CardRenderProps.actionTokens`)。没有令牌时 `invoke` 只提示「该操作不可用」——说明这张卡上的该动作没有注册或没有签发。
|
|
30
|
+
|
|
31
|
+
令牌绑定卡片实例与会话:换会话、换卡实例即失效,历史卡片不能重放。
|
|
32
|
+
|
|
33
|
+
## 应用级动作
|
|
34
|
+
|
|
35
|
+
应用自己的动作放在 `apps/server/src/actions/*.action.ts`,用 `defineAction` 声明:
|
|
36
|
+
|
|
37
|
+
<!-- recipe:action ts -->
|
|
38
|
+
```ts
|
|
39
|
+
import { actionResult, defineAction } from '@tbox.cn/app-agent-sdk-server';
|
|
40
|
+
import { z } from 'zod';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* order status 动作:卡片上的确定性入口,点击后直接执行,不过模型。
|
|
44
|
+
*
|
|
45
|
+
* - `id` 全局唯一,卡片里用 `invoke('order-status')` 触发;
|
|
46
|
+
* - `cardType` 决定这张动作挂在哪种卡上(出卡时平台按它签发令牌);
|
|
47
|
+
* - 写操作用 `singleUse: true` 防重复提交;
|
|
48
|
+
* - 结果用 `actionResult.notice` / `updateResult(card, data)` / `cardResult(card, data)` 构造:
|
|
49
|
+
* 本卡状态变了用 update,另一类结果用 card,只要一句提示用 notice;不要同时返回 card 与 update。
|
|
50
|
+
*/
|
|
51
|
+
export const action = defineAction({
|
|
52
|
+
id: 'order-status',
|
|
53
|
+
cardType: 'order-status',
|
|
54
|
+
inputSchema: z.object({}),
|
|
55
|
+
singleUse: true,
|
|
56
|
+
label: 'order status',
|
|
57
|
+
async execute(_input, { userId }) {
|
|
58
|
+
// 幂等判断放在写副作用之前:同一业务键只生效一次
|
|
59
|
+
return actionResult.notice(`已处理(${userId})`);
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- `id` 全局唯一;`cardType` 决定它挂在哪张卡上(数组表示同一操作出现在多张卡上),出卡时平台按被点卡签发令牌;
|
|
65
|
+
- `inputSchema` 校验卡片传入的 `input`;无参动作写 `z.object({})`;
|
|
66
|
+
- `execute(input, ctx)` 的 `ctx` 是 `{ userId, cardId?, cardType? }`——`userId` 来自授权令牌绑定的会话身份,**不要信客户端传上来的 userId**;`cardType` 是被点击那张卡的类型;
|
|
67
|
+
- 返回值三选一:`updateResult(card, data)` 原地更新被点的卡(`data` 必须过该卡 schema)、`cardResult(card, data)` 出一张结果卡、`actionResult.notice(text)` 只给一条提示。`update` 与 `card` 互斥;
|
|
68
|
+
- 写操作用 `singleUse: true` 防重复提交;幂等判断放在副作用之前;
|
|
69
|
+
- 动作结果只回给客户端(`tbox:card-update` / `tbox:notice`),**不进模型上下文**——需要模型知道的事实,让它在下一轮用工具查。
|
|
70
|
+
- 生成:`pnpm exec tbox-app new action <name>`,或 `new feature <name> --action` 一并产出。
|
|
71
|
+
|
|
72
|
+
## 按钮组(描述对象)
|
|
73
|
+
|
|
74
|
+
一个动作一个 `ActionRow`、再自己管确认弹层太啰嗦。用 `ActionList` 一次说清:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
const api = useCardActions({ cardId, isHistory, actionTokens });
|
|
78
|
+
<ActionList
|
|
79
|
+
api={api}
|
|
80
|
+
actions={[
|
|
81
|
+
{ label: '确认支付 ¥5', invoke: { id: 'pay-parking', input: { plate: data.plate } }, confirm: { title: '确认支付 ¥5?' }, style: 'primary' },
|
|
82
|
+
{ label: '先不付', send: '先不付,稍后再说' },
|
|
83
|
+
]}
|
|
84
|
+
/>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`confirm` 会把点击先收进 `ConfirmSheet`,确认后才执行;`api.disabled` 自动接到每个按钮。
|
|
88
|
+
|
|
89
|
+
## 没有动作时的退路
|
|
90
|
+
|
|
91
|
+
如果这张卡只有 `send` 一条路,就用 `send` + 工具内状态机完成确认流程,别在客户端伪造写操作。此时「按钮 → 工具」链路里模型仍是必经环节(每点一次一轮模型调用),提示词要写明「收到这类消息就当作确认,直接执行,不要重复追问」。
|
|
92
|
+
|
|
93
|
+
## 页尾
|
|
94
|
+
|
|
95
|
+
- 卡片结构 → [card](card.md)
|
|
96
|
+
- 工具出卡 → [tool-emits-card](tool-emits-card.md)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# 新增一张卡片
|
|
2
|
+
|
|
3
|
+
> 本页管:卡片的三处落点(数据契约、服务端声明、客户端渲染)与成对规则。|不管:出卡协议 → [tool-emits-card](tool-emits-card.md);按钮 → [card-action](card-action.md)。
|
|
4
|
+
|
|
5
|
+
## 一张卡要有三样东西
|
|
6
|
+
|
|
7
|
+
| 位置 | 文件 | 作用 |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| 数据契约 | `packages/shared/src/cards/<id>.ts` | 两端共用的 zod schema 与类型 |
|
|
10
|
+
| 服务端声明 | `apps/server/src/cards/<id>.card.ts` | `cardType`、schema、展示名、样例 |
|
|
11
|
+
| 客户端渲染 | `apps/client/src/cards/<id>.card.tsx` | 组件 + `defineCard({ type })` |
|
|
12
|
+
|
|
13
|
+
服务端与客户端文件名必须同 base,`cardType` 与 `type` 必须相同——缺一半或对不上,`pnpm generate` 会报 `CARD_PAIR_MISSING` 或 `CARD_TYPE_MISMATCH`。
|
|
14
|
+
|
|
15
|
+
## 数据契约
|
|
16
|
+
|
|
17
|
+
<!-- recipe:card-schema ts -->
|
|
18
|
+
```ts
|
|
19
|
+
import { z } from 'zod';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* order-status 卡片的数据形状:两端共用的唯一声明。
|
|
23
|
+
*
|
|
24
|
+
* - schema 与类型由 `z.infer` 单点推导,不再手写第二份 interface;
|
|
25
|
+
* - 服务端 `apps/server/src/cards/order-status.card.ts` 直接引用本 schema;
|
|
26
|
+
* - 客户端只允许 `import type`,schema 的运行时(zod)不进客户端产物。
|
|
27
|
+
*/
|
|
28
|
+
export const orderStatusCardSchema = z.object({
|
|
29
|
+
title: z.string(),
|
|
30
|
+
status: z.string(),
|
|
31
|
+
rows: z.array(z.object({ label: z.string(), value: z.string() })),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type OrderStatusCardData = z.infer<typeof orderStatusCardSchema>;
|
|
35
|
+
```
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 服务端声明
|
|
39
|
+
|
|
40
|
+
<!-- recipe:card-meta ts -->
|
|
41
|
+
```ts
|
|
42
|
+
import type { CardMeta } from '@tbox.cn/app-contracts';
|
|
43
|
+
import { orderStatusCardSchema } from '@app/shared/cards/order-status';
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* order-status 卡片的服务端声明。三条约束:
|
|
47
|
+
* - `cardType` 必须是字符串字面量(app-build 扫描器读静态值),且与客户端 `defineCard` 的 `type` 相同;
|
|
48
|
+
* - `dataSchema` 直接引用 `@app/shared` 的 schema(形状只写一处,客户端只 import 类型);
|
|
49
|
+
* - `sampleData` / `samples` 必须是静态字面量:`card render` 与场景断言按字面量读取,
|
|
50
|
+
* 引用常量或函数会读不到(doctor 与 check:fast 都会提示)。
|
|
51
|
+
*/
|
|
52
|
+
export const card = {
|
|
53
|
+
cardType: 'order-status',
|
|
54
|
+
dataSchema: orderStatusCardSchema,
|
|
55
|
+
displayName: 'order status',
|
|
56
|
+
description: 'order status 卡片(待补充说明)',
|
|
57
|
+
sampleData: {
|
|
58
|
+
title: 'order status',
|
|
59
|
+
status: '示例状态',
|
|
60
|
+
rows: [{ label: '示例字段', value: '示例值' }],
|
|
61
|
+
},
|
|
62
|
+
schemaVersion: 1,
|
|
63
|
+
} satisfies CardMeta<typeof orderStatusCardSchema>;
|
|
64
|
+
```
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 客户端渲染
|
|
68
|
+
|
|
69
|
+
<!-- recipe:card-client tsx -->
|
|
70
|
+
```tsx
|
|
71
|
+
import type { OrderStatusCardData } from '@app/shared/cards/order-status';
|
|
72
|
+
import { Card, CardHeader, KeyValueList, StatusTag, defineCard } from '@tbox.cn/app-agent-ui-kit';
|
|
73
|
+
import type { CardRenderProps } from '@tbox.cn/app-agent-ui-kit';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* order-status 卡片的客户端渲染。
|
|
77
|
+
* - `type` 与同 base 的服务端 `cardType` 必须相同;
|
|
78
|
+
* - 组件入参由 `defineCard` 固定(data / cardId / isHistory / actionTokens);
|
|
79
|
+
* - 排版用 kit 基元(Card / KeyValueList / StatusTag …),基元表达不了的用工具类,不新建样式文件;
|
|
80
|
+
* - 要加按钮时用 `useCardActions()`:`send` 走模型、`invoke` 走卡片动作、`disabled` 统一门控。
|
|
81
|
+
*/
|
|
82
|
+
function OrderStatusCard({ data }: CardRenderProps<OrderStatusCardData>) {
|
|
83
|
+
return (
|
|
84
|
+
<Card>
|
|
85
|
+
<CardHeader title={data.title} status={<StatusTag tone="info">{data.status}</StatusTag>} />
|
|
86
|
+
<KeyValueList items={data.rows.map((row) => ({ label: row.label, value: row.value }))} />
|
|
87
|
+
</Card>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const card = defineCard({ type: 'order-status' }, OrderStatusCard);
|
|
92
|
+
```
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 视觉基线
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
pnpm card:render --type <cardType> --screenshot --baseline
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
首次运行把截图写到 `.tbox/card-render/baseline/<type>.png`;之后逐像素比对(需 Pillow),差异 >0.5% 失败;没有 Pillow 时退回字节比对。改样式后用 `--baseline` 重跑,确认差异符合预期再删除对应基线、重新生成。
|
|
102
|
+
|
|
103
|
+
`--audit` 同时列出字号分布:每张卡的文字必须落在 12 / 14 / 16 / 18 / 20 五档,越档会单独列一行。
|
|
104
|
+
|
|
105
|
+
## 要点
|
|
106
|
+
|
|
107
|
+
- `sampleData` 必须能过 `dataSchema`:卡片预览页与场景断言都用它。
|
|
108
|
+
- `cardType` / `type` 都写成字符串字面量(扫描器读静态值)。
|
|
109
|
+
- 客户端组件入参固定为 `CardRenderProps<T>`:`data`、`cardId`、`isHistory`、`actionTokens`。
|
|
110
|
+
- 信息类卡片先用 kit 基元拼;确实需要自定义布局再写结构,样式规则见 [style](style.md)。
|
|
111
|
+
|
|
112
|
+
## 校验
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
pnpm check:fast
|
|
116
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# 多轮联动与指代
|
|
2
|
+
|
|
3
|
+
> 本页管:怎么让「第一家」「那就这个」「带孩子呢」「怎么走」这类表达在下一轮接得上,以及跨工具的事实放哪。|不管:工具写法 → [tool](tool.md);按钮与确认 → [card-action](card-action.md);状态 → [state](state.md)。
|
|
4
|
+
|
|
5
|
+
## 原则:指代交给模型,事实交给状态
|
|
6
|
+
|
|
7
|
+
模型能从对话历史里解出「第一家」「那就这个」——前提是上一条工具结果里带着**可引用的条目**。服务端不要维护「上一轮推荐列表」再做二次解析:那是第二份真源,和模型看到的上下文必然漂移。
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// 工具出参:一句结论 + 关键事实 + 可引用条目
|
|
11
|
+
return {
|
|
12
|
+
ok: true,
|
|
13
|
+
message: '按亲子需求推荐 3 家:江南小馆、童梦乐园、茶有间',
|
|
14
|
+
items: [
|
|
15
|
+
{ id: 'jiangnan', name: '江南小馆', floor: 'L1', avg: 80 },
|
|
16
|
+
{ id: 'tongmeng', name: '童梦乐园', floor: 'L3', avg: 68 },
|
|
17
|
+
],
|
|
18
|
+
cards: [/* … */],
|
|
19
|
+
};
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- `items` 用**稳定 id** + 展示名;后续工具按 id 或名字都能定位(详情工具两者都收)。
|
|
23
|
+
- 一句 `message` 让模型不用读整个对象就知道这轮发生了什么。
|
|
24
|
+
- 条目不要超过一屏;要更多就分页,别把上下文塞满。
|
|
25
|
+
|
|
26
|
+
## 跨工具的事实
|
|
27
|
+
|
|
28
|
+
「已成为会员」「已领的券」「当前车牌」这些跨工具事实放 `createUserState`(见 [state](state.md)),每个工具读它再决定怎么做;不要靠模型复述这些事实。
|
|
29
|
+
|
|
30
|
+
## 确认类交互
|
|
31
|
+
|
|
32
|
+
写操作要么走确定性动作 + `confirm`(见 [card-action](card-action.md)),要么在提示词里写明「收到这类消息就当作确认,直接执行,不要重复追问」。两者不要混用:动作走动作,消息走消息。
|
|
33
|
+
|
|
34
|
+
## 出卡与后续引用
|
|
35
|
+
|
|
36
|
+
- 每张卡带 `note`(一句话说明这张卡是什么),模型在后续轮次里引用它更准。
|
|
37
|
+
- 同一轮多张卡时,先给「结论卡」再给「细节卡」;模型倾向引用最后一张。
|
|
38
|
+
- 卡片按钮用 `invoke` 走动作时,入参里带上业务 id(`{ merchantId }`),不要依赖「当前卡片」。
|
|
39
|
+
|
|
40
|
+
## 反例
|
|
41
|
+
|
|
42
|
+
| 写法 | 为什么不行 |
|
|
43
|
+
|---|---|
|
|
44
|
+
| 服务端缓存「上一次推荐列表」并在详情工具里兜底解析 | 与模型上下文双源,指代一变就错;本次真实构建为此花了 77 秒 |
|
|
45
|
+
| 工具只返回一段自然语言 | 模型没有可引用条目,「第一家」无从对齐 |
|
|
46
|
+
| 指代解析写成前端规则 | 绕过模型,卡片与状态不再可用 |
|
|
47
|
+
| 每轮都重新查全量再筛 | 上下文膨胀;用 `items` 收敛 |
|
|
48
|
+
|
|
49
|
+
## 页尾
|
|
50
|
+
|
|
51
|
+
- 工具出参与卡片 → [tool-emits-card](tool-emits-card.md)
|
|
52
|
+
- 状态与身份 → [state](state.md)
|