@tbox.cn/app-template-agent 0.10.37 → 1.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +3 -19
- package/.tbox/default-modules.json +4 -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 +96 -148
- package/ENV.md +4 -4
- package/README.md +31 -27
- package/apps/._AGENTS.md +0 -0
- package/apps/AGENTS.md +9 -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/index.html +1 -20
- package/apps/client/package.json +7 -5
- 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/cards/registry.ts +6 -19
- 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 +11 -0
- 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 +7 -53
- 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/package.json +1 -1
- 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 +17 -17
- 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/cli/collect-registry.ts +7 -11
- package/apps/server/src/config/._integration.ts +0 -0
- package/apps/server/src/dev.ts +38 -64
- package/apps/server/src/index.ts +27 -45
- 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/cards-registry.test.ts +1 -1
- package/apps/server/tests/helpers/._register.ts +0 -0
- package/apps/server/tests/helpers/register.ts +10 -0
- package/apps/server/tests/tool-runtime.test.ts +1 -28
- package/apps/server/tsconfig.json +1 -1
- package/apps/server/tsup.config.ts +6 -3
- 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/{packages → modules}/provider-custom/AGENTS.md +6 -6
- package/modules/provider-custom/INTEGRATION.md +10 -0
- package/{packages → modules}/provider-custom/package.json +1 -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/{packages → modules}/provider-custom/src/server/example-adapter.ts +2 -2
- package/{packages → modules}/provider-custom/src/server/index.ts +1 -1
- package/modules/provider-custom/tests/._provider-custom.test.ts +0 -0
- package/package.json +38 -7
- 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 +13 -0
- package/packages/shared/package.json +20 -0
- package/packages/shared/src/._index.ts +0 -0
- package/packages/shared/src/index.ts +8 -0
- package/packages/shared/tsconfig.json +7 -0
- package/pnpm-lock.template.yaml +781 -846
- package/pnpm-workspace.template.yaml +19 -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/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/generate.mjs +3 -0
- 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/scripts/verify-generated.mjs +22 -127
- package/tsconfig.base.json +1 -0
- package/apps/client/STYLE_GUIDE.md +0 -81
- package/apps/client/VISUAL_RESTORE.md +0 -90
- package/apps/client/src/app.tsx +0 -11
- package/apps/client/src/business/App.tsx +0 -11
- package/apps/client/src/business/README.md +0 -99
- package/apps/client/src/business/routes.json +0 -3
- package/apps/client/src/main.tsx +0 -17
- package/apps/client/src/modules.ts +0 -33
- package/apps/client/src/platform/AgentChatApp.tsx +0 -14
- 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 -12
- package/apps/client/src/platform/mount-page.tsx +0 -25
- package/apps/client/src/platform/state/createPersistedStore.ts +0 -19
- package/apps/server/src/app-tools.ts +0 -14
- package/apps/server/src/modules.ts +0 -38
- package/apps/server/src/tools/clock.ts +0 -24
- package/apps/server/src/tools/translate.ts +0 -47
- package/packages/agent-ui-kit/src/ChatPage.less +0 -66
- 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 → modules}/provider-custom/LICENSE +0 -0
- /package/{packages → modules}/provider-custom/README.md +0 -0
- /package/{packages → modules}/provider-custom/src/index.ts +0 -0
- /package/{packages → modules}/provider-custom/tbox.module.json +0 -0
- /package/{packages → modules}/provider-custom/tests/provider-custom.test.ts +0 -0
- /package/{packages → modules}/provider-custom/tsconfig.json +0 -0
- /package/{packages → modules}/provider-custom/tsup.config.ts +0 -0
- /package/packages/agent-ui-kit/src/theme/{motion.less → motion.css} +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* scenario — 进程内场景执行器(T1)的命令行包装。
|
|
4
|
+
*
|
|
5
|
+
* 读 `scenarios/*.json`,逐步直调应用工具并断言出参与卡片。零端口、零模型、零浏览器:
|
|
6
|
+
* 一次运行就能回答「这条联动链路还通不通」。执行逻辑在 `scenario-lib.mjs`(与 `check:fast` 共用)。
|
|
7
|
+
*
|
|
8
|
+
* 运行:`pnpm scenario [文件或目录…]`(根脚本转发到本文件;SDK 从 apps/server 依赖解析)。
|
|
9
|
+
*/
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import process from 'node:process';
|
|
13
|
+
import { resolveScenarioFiles, runScenarios } from './scenario-lib.mjs';
|
|
14
|
+
|
|
15
|
+
const appDir = path.resolve(import.meta.dirname, '..', '..', '..');
|
|
16
|
+
const files = resolveScenarioFiles(appDir, process.argv.slice(2));
|
|
17
|
+
|
|
18
|
+
if (files.length === 0) {
|
|
19
|
+
console.log(JSON.stringify({ ok: true, scenarios: 0, note: '没有场景文件(scenarios/*.json)' }));
|
|
20
|
+
process.exit(0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const { registry } = await import(path.join(appDir, 'apps/client/.tbox-gen/registry.server.ts'));
|
|
24
|
+
const result = await runScenarios({ appDir, registry, files });
|
|
25
|
+
|
|
26
|
+
// 人读输出有预算:失败优先、整体 ≤2000 字符;完整结果落 .tbox/logs/scenario.log 并给出路径。
|
|
27
|
+
// --json 只出摘要 JSON(机器消费),--full 直出全部失败行。
|
|
28
|
+
const full = process.argv.includes('--full');
|
|
29
|
+
const jsonOnly = process.argv.includes('--json');
|
|
30
|
+
const MAX_CHARS = 2000;
|
|
31
|
+
const summary = { ok: result.ok, scenarios: result.scenarios, failed: result.failed, tools: result.tools, cards: result.cards };
|
|
32
|
+
|
|
33
|
+
const failedResults = result.results.filter((item) => !item.ok);
|
|
34
|
+
const failureLines = [];
|
|
35
|
+
for (const item of failedResults) {
|
|
36
|
+
failureLines.push(`✗ ${item.scenario}(${item.steps} 步)`);
|
|
37
|
+
for (const line of item.failures) failureLines.push(` - ${line}`);
|
|
38
|
+
}
|
|
39
|
+
const allFailures = result.results.flatMap((item) => item.failures.map((line) => `${item.scenario}: ${line}`));
|
|
40
|
+
let logPath;
|
|
41
|
+
if (failureLines.length > 0 || !jsonOnly) {
|
|
42
|
+
try {
|
|
43
|
+
const dir = path.join(appDir, '.tbox/logs');
|
|
44
|
+
mkdirSync(dir, { recursive: true });
|
|
45
|
+
logPath = path.join(dir, 'scenario.log');
|
|
46
|
+
writeFileSync(logPath, JSON.stringify({ summary, results: result.results }, null, 2) + '\n', 'utf8');
|
|
47
|
+
} catch { /* 只读环境不阻断 */ }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!jsonOnly && failureLines.length > 0) {
|
|
51
|
+
const bounded = [];
|
|
52
|
+
let used = 0;
|
|
53
|
+
for (const line of failureLines) {
|
|
54
|
+
if (!full && used + line.length + 1 > MAX_CHARS - 120) {
|
|
55
|
+
bounded.push(' …(还有 ' + (failureLines.length - bounded.length) + ' 行,全文见 ' + (logPath ? path.relative(appDir, logPath) : '上文') + ')');
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
bounded.push(line);
|
|
59
|
+
used += line.length + 1;
|
|
60
|
+
}
|
|
61
|
+
console.error(bounded.join('\n'));
|
|
62
|
+
}
|
|
63
|
+
console.log(JSON.stringify(summary));
|
|
64
|
+
if (!jsonOnly && !full && logPath && failureLines.length > 0) {
|
|
65
|
+
console.log('全文:' + path.relative(appDir, logPath) + '(--full 直出失败行)');
|
|
66
|
+
}
|
|
67
|
+
if (!result.ok) process.exitCode = 1;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/apps/server/src/app.ts
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* 客户端供给由入口决定——静态产物见 index.ts(唯一 tsup entry),vite dev 见 dev.ts(仅 tsx)。
|
|
4
4
|
* import 本模块即完成装配(与旧单文件入口时序等价:listen 仍在 start() 内最后发生)。
|
|
5
5
|
*/
|
|
6
|
-
import express from 'express';
|
|
6
|
+
import express, { type Express } from 'express';
|
|
7
7
|
import { createServer, type IncomingMessage } from 'http';
|
|
8
8
|
import type { Duplex } from 'node:stream';
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import { existsSync } from 'node:fs';
|
|
11
11
|
import { fileURLToPath } from 'url';
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
// ===== 模板日志(@tbox.cn/app-agent-sdk-server createLogger:本地时间 + LEVEL + [tag] + req/conv 尾缀) =====
|
|
14
14
|
import { createLogger } from '@tbox.cn/app-agent-sdk-server';
|
|
15
15
|
const serverLogger = createLogger('server');
|
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
installTboxDev,
|
|
49
49
|
} from '@tbox.cn/app-agent-sdk-server';
|
|
50
50
|
import { installInspector } from '@tbox.cn/app-agent-sdk-server/platform';
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
import { APP_PRE_TOOLS } from './pre-tools.js';
|
|
53
53
|
import { INTENT_ROUTES, createAppIntentDispatcher } from './intent-routes.js';
|
|
54
54
|
import { loadIntegrations } from './config/integration.js';
|
|
@@ -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,
|
|
@@ -264,7 +265,7 @@ if (!isProduction) {
|
|
|
264
265
|
// authExchanges 同引用传递(provider 包 register 期自注册换码器)+ scopeDefaults 中立注入
|
|
265
266
|
// scopeDefaults 静态注入退役——域装配(含 defaultMallId)经 registry 读取视图供给
|
|
266
267
|
// (SDK ctx.scopeDefaults 惰性优先注册表 → provider getter 登录期求值)
|
|
267
|
-
const ctx = createServerContext({
|
|
268
|
+
export const ctx = createServerContext({
|
|
268
269
|
authStrategies,
|
|
269
270
|
authExchanges: auth.exchanges,
|
|
270
271
|
...(memory.store ? { memory: memory.store } : {}),
|
|
@@ -419,8 +420,6 @@ async function createEngine(
|
|
|
419
420
|
return engine;
|
|
420
421
|
}
|
|
421
422
|
|
|
422
|
-
const httpServer = createServer(app);
|
|
423
|
-
|
|
424
423
|
/** dev 态升级扩展点(dev.ts 注册):返回 true = 已认领,app 路由跳过。生产 bundle 恒空。 */
|
|
425
424
|
export type UpgradeDelegate = (request: IncomingMessage, socket: Duplex, head: Buffer) => boolean;
|
|
426
425
|
let upgradeDelegate: UpgradeDelegate | undefined;
|
|
@@ -428,15 +427,10 @@ export function registerUpgradeDelegate(delegate: UpgradeDelegate): void {
|
|
|
428
427
|
upgradeDelegate = delegate;
|
|
429
428
|
}
|
|
430
429
|
|
|
431
|
-
export async function start() {
|
|
432
|
-
|
|
433
|
-
await registerAll(ctx);
|
|
430
|
+
export async function start(serverApp: Express = app) {
|
|
431
|
+
const httpServer = createServer(serverApp);
|
|
434
432
|
|
|
435
|
-
//
|
|
436
|
-
// (010:start() 与 cli/collect-registry.ts 双处同调,防注册面失同步)
|
|
437
|
-
registerAppTools(ctx);
|
|
438
|
-
|
|
439
|
-
// 时序契约:域装配解析必须晚于 registerAll——module-mall-core 在 register 期经
|
|
433
|
+
// 时序契约:域装配解析必须晚于模块注册——module-mall-core 在 register 期经
|
|
440
434
|
// ctx.domainAssemblies 注册装配;解析点置于 start() 头部会查空表(引入回归:
|
|
441
435
|
// 默认商圈兜底/卡片动作授权/enhanceContext 全断——见 Agent Note 2026-09-17-mall-assembly-resolution-order)
|
|
442
436
|
const assembly = mallAssembly();
|
|
@@ -449,14 +443,20 @@ export async function start() {
|
|
|
449
443
|
///E2:mall 装配(条件)——scope 会话 + 动作授权先行(engine attacher 依赖)
|
|
450
444
|
// buildScope 回填 mallName(ChatHeader 品牌区服务端真源;三级回退内聚于域装配)
|
|
451
445
|
// 域装配经查表(assembly 于上方 registerAll 后解析——解析点必须晚于模块注册)
|
|
446
|
+
// 无领域装配时,只要应用注册了卡片动作,就用中立会话(scope 恒 app)——否则动作会被静默丢弃
|
|
447
|
+
const hasCardActions = ctx.cardActions.getAll().size > 0;
|
|
448
|
+
const neutralScopeSessions = !assembly && hasCardActions ? createAppScopeSessionRegistry() : undefined;
|
|
452
449
|
const scopeSessions: ReturnType<typeof createScopeSessionRegistry> | undefined = assembly
|
|
453
450
|
? createScopeSessionRegistry({
|
|
454
451
|
extractScopeKey: (c) => assembly.extractScopeKey(c),
|
|
455
452
|
validateScope: (a) => assembly.validateScope(a),
|
|
456
453
|
buildScope: (a) => assembly.buildScopeWithMallName(a),
|
|
457
454
|
})
|
|
458
|
-
:
|
|
455
|
+
: neutralScopeSessions;
|
|
459
456
|
const grants = scopeSessions ? createActionGrantService({ store: ctx.state }) : undefined;
|
|
457
|
+
if (neutralScopeSessions) {
|
|
458
|
+
actionLogger.info('卡片动作用中立会话(无领域装配)', { actions: ctx.cardActions.getAll().size });
|
|
459
|
+
}
|
|
460
460
|
|
|
461
461
|
// 卡片动作 token 签发(build → attach → send;sessionId 引擎登记、scope 经 sessions 查)
|
|
462
462
|
const cardActionAttacher = grants && scopeSessions
|
|
@@ -479,7 +479,7 @@ export async function start() {
|
|
|
479
479
|
|
|
480
480
|
///E2:模块动作分发(依赖 scopeSessions/grants)
|
|
481
481
|
let moduleActions: ReturnType<typeof createModuleActionDispatcher> | undefined;
|
|
482
|
-
if (
|
|
482
|
+
if (scopeSessions && grants) {
|
|
483
483
|
moduleActions = createModuleActionDispatcher({
|
|
484
484
|
grants,
|
|
485
485
|
sessions: scopeSessions,
|
|
@@ -489,7 +489,7 @@ export async function start() {
|
|
|
489
489
|
// effect 运行时纯投影(payment/authorization 回调补签在 dispatcher step7,
|
|
490
490
|
// 客户端执行在 SDK host-effect-runner——模板零装配效果链)
|
|
491
491
|
effects: createEffectRuntime(),
|
|
492
|
-
extractScopeKey: (c) => assembly.extractScopeKey(c),
|
|
492
|
+
extractScopeKey: assembly ? (c) => assembly.extractScopeKey(c) : () => 'app',
|
|
493
493
|
});
|
|
494
494
|
for (const action of ctx.cardActions.getAll().values()) {
|
|
495
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
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { createServerContext } from '@tbox.cn/app-agent-sdk-server';
|
|
1
|
+
import { createServerContext, registerServerModules } from '@tbox.cn/app-agent-sdk-server';
|
|
2
2
|
import type { ToolCardBinding } from '@tbox.cn/agent-plugin/cards';
|
|
3
|
-
import {
|
|
4
|
-
import { registerAppTools } from '../app-tools.js';
|
|
3
|
+
import { registry } from '../../../client/.tbox-gen/registry.server';
|
|
5
4
|
|
|
6
5
|
export interface RegistryState {
|
|
7
6
|
staticToolIds: string[];
|
|
@@ -10,16 +9,13 @@ export interface RegistryState {
|
|
|
10
9
|
bindings: ToolCardBinding[];
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
/**
|
|
14
|
-
* 从自注册闭环收集当前注册状态(静态工具 id / cardType)。
|
|
15
|
-
* 供 plugin-doctor / plugin-inspect 复用——替代已删除的手写 tools/registry.ts + cards/registry.ts。
|
|
16
|
-
* 与运行时(apps/server/src/index.ts start())保持一致的注册面:registerAll + registerAppTools
|
|
17
|
-
* (010:apps 级演示工具统一注册面,双处同调防失同步)。
|
|
18
|
-
*/
|
|
12
|
+
/** 从生成 registry 收集当前注册状态(与 createApp 同源)。 */
|
|
19
13
|
export async function collectRegistryState(): Promise<RegistryState> {
|
|
20
14
|
const ctx = createServerContext();
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
for (const tool of registry.tools) ctx.tools.register(tool);
|
|
16
|
+
for (const skill of registry.skills) ctx.skills.register(skill);
|
|
17
|
+
for (const card of Object.values(registry.cards)) ctx.cards.register(card as never);
|
|
18
|
+
await registerServerModules(ctx, registry.modules);
|
|
23
19
|
return {
|
|
24
20
|
staticToolIds: Object.keys(ctx.tools.getAll()),
|
|
25
21
|
cardTypes: Object.keys(ctx.cards.getAll()),
|
|
Binary file
|
package/apps/server/src/dev.ts
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* vite dev 入口(仅 tsx
|
|
3
|
-
*
|
|
4
|
-
* 部署形态一律走 dist/index.js(静态产物,零 HMR WS)。
|
|
5
|
-
*
|
|
6
|
-
* 方案 W(沙箱 dev server 鉴权保护):TBOX_DEV_TOKEN 在场 → protected 双面裁决
|
|
7
|
-
* (dev 面 = 凭据 + 导航/同源信号放行 vite;static 面 = 纯 dist + SSE 刷新,零源码泄漏);
|
|
8
|
-
* 缺席 → classic,与历史行为字节级等价。裁决机制真源 = SDK platform/dev-runtime
|
|
9
|
-
* (createTboxDevRuntime),本文件只做装配:vite 实例 + fs.allow 收窄 + 面无关自由区。
|
|
2
|
+
* vite dev 入口(仅 tsx 运行):import 即启动。
|
|
3
|
+
* 单端口:HTTP + HMR;页面由 dev-runtime 的 manifest 页集合交给 Vite/生成 entry。
|
|
10
4
|
*/
|
|
11
|
-
import { createServer } from 'http';
|
|
12
|
-
import path from 'path';
|
|
5
|
+
import { createServer } from 'node:http';
|
|
6
|
+
import path from 'node:path';
|
|
13
7
|
import { existsSync } from 'node:fs';
|
|
14
|
-
import { fileURLToPath } from 'url';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
15
9
|
import { build as viteBuild, createServer as createViteServer, searchForWorkspaceRoot } from 'vite';
|
|
16
10
|
import {
|
|
17
11
|
createTboxDevRuntime,
|
|
@@ -19,46 +13,39 @@ import {
|
|
|
19
13
|
isReady,
|
|
20
14
|
resolveDevTokenFromEnv,
|
|
21
15
|
} from '@tbox.cn/app-agent-sdk-server/platform';
|
|
22
|
-
import { createLogger } from '@tbox.cn/app-agent-sdk-server';
|
|
23
|
-
import {
|
|
16
|
+
import { createApp, createLogger, getRequestContext } from '@tbox.cn/app-agent-sdk-server';
|
|
17
|
+
import { generateApp } from '@tbox.cn/app-build';
|
|
18
|
+
import { app as legacyApp, ctx, registerUpgradeDelegate, setupTboxDev, start } from './app.js';
|
|
24
19
|
|
|
25
20
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
26
21
|
const serverLogger = createLogger('server');
|
|
22
|
+
const root = path.resolve(__dirname, '../../..');
|
|
23
|
+
const clientRoot = path.resolve(__dirname, '../../client');
|
|
27
24
|
|
|
28
|
-
// fail-closed:dev 入口与生产安全姿态互斥——NODE_ENV=production 下 SDK dev 面
|
|
29
|
-
// (dev-login/卡片预览 API)会静默降级,这里显式拒绝启动(生产走 dist/index.js)
|
|
30
25
|
if (process.env.NODE_ENV === 'production') {
|
|
31
26
|
serverLogger.error('dev 入口禁止 NODE_ENV=production——生产请使用 dist/index.js(pnpm start)');
|
|
32
27
|
process.exit(1);
|
|
33
28
|
}
|
|
34
29
|
|
|
35
|
-
const
|
|
36
|
-
const
|
|
30
|
+
const generated = await generateApp({ root });
|
|
31
|
+
const [{ registry }] = await Promise.all([
|
|
32
|
+
import('../../client/.tbox-gen/registry.server.ts'),
|
|
33
|
+
]);
|
|
34
|
+
const { appKind } = generated;
|
|
37
35
|
|
|
38
|
-
// HMR WS 独立路径:dev 基础设施命名空间(双下划线呼应 /@vite/*),与业务命名空间(/ws*)
|
|
39
|
-
// 解耦——upgrade 认领只针对此路径,根路径归还业务路由。协议常量(vite-hmr/vite-ping)、
|
|
40
|
-
// 认领路径 posix.join(base, hmr.path) 与 Spanner 子协议补写均内聚于 SDK handleUpgrade
|
|
41
|
-
// (smoke-dev-hmr.sh 守护该契约面)。
|
|
42
36
|
const HMR_WS_PATH = '/__vite_hmr';
|
|
43
|
-
|
|
44
|
-
// HMR WS hub:永不 listen 的纯事件载体。hmr.server 在场 → vite 不自建独立端口,
|
|
45
|
-
// 客户端按页面同源端口连接。vite 对 hub 仅 on/off('upgrade')(6.4.3 源码实证)。
|
|
46
37
|
const hmrHub = createServer();
|
|
47
|
-
|
|
48
38
|
const tokenState = resolveDevTokenFromEnv(process.env);
|
|
49
39
|
const protectedMode = tokenState.mode === 'protected';
|
|
50
|
-
|
|
51
|
-
// protected 面 fs.allow 收窄(classic 恒默认不传——红线):client 源 + 工作区依赖真源。
|
|
52
|
-
// 模板原地装配(pnpm dev)时模块图经 workspace 链接解析到仓库 packages/,故并入
|
|
53
|
-
// workspace 两目录(filter(existsSync):生成应用无此目录时自动滤除,不影响沙箱半径)。
|
|
54
40
|
const workspaceRoot = searchForWorkspaceRoot(clientRoot);
|
|
55
41
|
const fsAllowNarrowed = protectedMode
|
|
56
42
|
? [
|
|
57
43
|
...new Set(
|
|
58
44
|
[
|
|
59
45
|
clientRoot,
|
|
60
|
-
path.join(
|
|
61
|
-
path.join(
|
|
46
|
+
path.join(root, 'packages'),
|
|
47
|
+
path.join(root, 'modules'),
|
|
48
|
+
path.join(root, 'node_modules'),
|
|
62
49
|
path.join(workspaceRoot, 'packages'),
|
|
63
50
|
path.join(workspaceRoot, 'node_modules'),
|
|
64
51
|
].filter((p) => existsSync(p)),
|
|
@@ -70,24 +57,19 @@ const vite = await createViteServer({
|
|
|
70
57
|
root: clientRoot,
|
|
71
58
|
server: {
|
|
72
59
|
middlewareMode: true,
|
|
73
|
-
// 沙箱域名 Host 透传放行(dev-only;dist 物理不含 vite)。安全边界见 Agent Note
|
|
74
|
-
// 2026-09-09 与方案 W Note(protected 面 /@fs 另有 allow 收窄 + deny 现值保留)
|
|
75
60
|
allowedHosts: true,
|
|
76
61
|
fs: {
|
|
77
62
|
...(fsAllowNarrowed ? { allow: fsAllowNarrowed } : {}),
|
|
78
|
-
// /@fs 加固:默认 deny 不含服务端凭证目录(client 永不需要经 /@fs 读它)
|
|
79
63
|
deny: ['.env', '.env.*', '*.{crt,pem}', '**/.git/**', '**/config/credentials/**'],
|
|
80
64
|
},
|
|
81
65
|
hmr: { server: hmrHub, path: HMR_WS_PATH },
|
|
82
66
|
},
|
|
83
|
-
// custom:不加 Vite 自己的 SPA fallback,HTML 路由由 runtime.final() 统一处理
|
|
84
67
|
appType: 'custom',
|
|
85
68
|
});
|
|
86
69
|
|
|
87
70
|
const runtime = createTboxDevRuntime({
|
|
88
71
|
vite: { middlewares: vite.middlewares, transformIndexHtml: vite.transformIndexHtml, ws: vite.ws },
|
|
89
72
|
hmrHub,
|
|
90
|
-
// 与 vite 同一 resolved config 同式 posix.join 派生——恒等无漂移
|
|
91
73
|
hmrPath: path.posix.join(vite.config.base, HMR_WS_PATH),
|
|
92
74
|
tokenState,
|
|
93
75
|
clientRoot,
|
|
@@ -97,42 +79,20 @@ const runtime = createTboxDevRuntime({
|
|
|
97
79
|
logger: serverLogger,
|
|
98
80
|
fsAllowNarrowed: protectedMode,
|
|
99
81
|
sseKeepaliveMs: process.env.TBOX_DEV_SSE_KEEPALIVE_MS ? Number(process.env.TBOX_DEV_SSE_KEEPALIVE_MS) : undefined,
|
|
100
|
-
// v3.2 严格文档模式(G8 模式开关):routes.json 在场 ⇔ strict(dev 面 entry 替换 +
|
|
101
|
-
// public 目录索引;static 面 dist 文件真源)。缺席 = legacy SPA fallback,零变化。
|
|
102
82
|
pagePolicy: {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// 替换——与业务路由同机制;能力关 = 文件不在 = 404)
|
|
106
|
-
platformPages: [
|
|
107
|
-
{ path: '/_tbox/card-preview', document: '_tbox/card-preview.html', inputName: 'card-preview' },
|
|
108
|
-
],
|
|
83
|
+
mode: 'manifest',
|
|
84
|
+
manifest: path.join(clientRoot, '.tbox-gen', 'manifest.json'),
|
|
109
85
|
},
|
|
110
86
|
});
|
|
111
87
|
|
|
112
|
-
// tbox dev 工具族装配(幂等;先于 gate/final——/_tbox/api 路由序恒胜)。静态入口
|
|
113
|
-
// (index.ts)不调用 → 生产零挂载。
|
|
114
88
|
setupTboxDev();
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
app.use(runtime.gate);
|
|
118
|
-
|
|
119
|
-
// ── 自由区(模板差异 + 应用自定义 middleware;dev/static 两面恒可见)──
|
|
120
|
-
// 探针路由:smoke-dev-protected.sh ⑩ 断言两面可见性(dev 基础设施,dist 物理不含)
|
|
121
|
-
app.get('/__tbox_dev_freezone_probe', (_req, res) => {
|
|
89
|
+
legacyApp.use(runtime.gate);
|
|
90
|
+
legacyApp.get('/__tbox_dev_freezone_probe', (_req, res) => {
|
|
122
91
|
res.type('text/plain').send('freezone-ok');
|
|
123
92
|
});
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
app.use(runtime.final);
|
|
127
|
-
|
|
128
|
-
// 升级委托:唯一 WS 入口 = runtime.handleUpgrade(路径认领 + 子协议补写 + protected
|
|
129
|
-
// token 校验,失败 401;未认领回落 app 路由——业务 /ws、根路径、fail-fast 语义不变)
|
|
93
|
+
legacyApp.use(runtime.final);
|
|
130
94
|
registerUpgradeDelegate(runtime.handleUpgrade);
|
|
131
95
|
|
|
132
|
-
// protected 面构建通知:watch 增量构建 → BUNDLE_START(构建窗口标记:static 面 miss → 503
|
|
133
|
-
// 而非 404 抖动)→ BUNDLE_END → SSE 广播 → static 面 reload。fire-and-forget(不 await、
|
|
134
|
-
// 无显式 close——dev 会话生命周期即进程生命周期);watch 启动 emptyOutDir 清空 dist 为
|
|
135
|
-
// 已定价行为(首建完成前 strict static 面 503 等待页 / legacy 纯 404)。
|
|
136
96
|
if (protectedMode) {
|
|
137
97
|
viteBuild({ root: clientRoot, build: { watch: {}, sourcemap: false } })
|
|
138
98
|
.then((result) => {
|
|
@@ -146,7 +106,21 @@ if (protectedMode) {
|
|
|
146
106
|
.catch((err) => serverLogger.error('[dev] watch build failed:', err));
|
|
147
107
|
}
|
|
148
108
|
|
|
149
|
-
|
|
109
|
+
const app = await createApp({
|
|
110
|
+
ctx,
|
|
111
|
+
manifest: generated.manifest,
|
|
112
|
+
getManifest: () => generated.manifest,
|
|
113
|
+
appKind,
|
|
114
|
+
registry,
|
|
115
|
+
mode: 'dev',
|
|
116
|
+
resolveUser: (req) => getRequestContext(req)?.identity ?? null,
|
|
117
|
+
// CORS / JSON / auth 必须先于 createApp 的 /api/fn RPC。
|
|
118
|
+
beforeRoutes: (base) => {
|
|
119
|
+
base.use(legacyApp);
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
start(app).catch((err) => {
|
|
150
124
|
serverLogger.error('Failed to start:', err);
|
|
151
125
|
process.exit(1);
|
|
152
126
|
});
|
package/apps/server/src/index.ts
CHANGED
|
@@ -1,59 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* dist
|
|
4
|
-
* tsup.config.ts forbid-vite 插件拦截)。NODE_ENV 只影响 SDK 安全姿态(dev-login/密钥链)。
|
|
5
|
-
*
|
|
6
|
-
* strict(routes.json 在场 ⇔ 构建期插件同源判定):dist 文件存在性 = 唯一路由真源,
|
|
7
|
-
* 未知页面 404 是文件系统的自然结果;平台文档表(卡片预览,能力开 = 构建产物在场);
|
|
8
|
-
* 统一 .html 文档管线 + 目录索引/301;dist 未就绪 503。
|
|
9
|
-
* legacy(routes.json 缺席):express.static + SPA catch-all——与历史行为字节等价。
|
|
10
|
-
* 镜像携带全量源码(docker/Dockerfile 全量 COPY),src/dist 平级锚点恒可探测。
|
|
2
|
+
* 静态生产入口:createApp 装配 manifest/registry/页面运行时,业务路由仍由 app.ts 供给。
|
|
3
|
+
* dist 形态恒静态;vite dev 仅存在于 src/dev.ts。
|
|
11
4
|
*/
|
|
12
|
-
import path from 'path';
|
|
13
|
-
import express from 'express';
|
|
5
|
+
import path from 'node:path';
|
|
14
6
|
import { existsSync } from 'node:fs';
|
|
15
|
-
import { fileURLToPath } from 'url';
|
|
16
|
-
import { createLogger } from '@tbox.cn/app-agent-sdk-server';
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { createLogger, createApp, getRequestContext, type AppManifest } from '@tbox.cn/app-agent-sdk-server';
|
|
9
|
+
import { injectScript } from '@tbox.cn/app-agent-sdk-server/platform';
|
|
10
|
+
import manifest from '../../client/.tbox-gen/manifest.json';
|
|
11
|
+
import appMeta from '../../../.tbox/app.json';
|
|
12
|
+
import { registry } from '../../client/.tbox-gen/registry.server';
|
|
13
|
+
import { app as legacyApp, ctx, start } from './app.js';
|
|
19
14
|
|
|
20
15
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
21
16
|
const serverLogger = createLogger('server');
|
|
17
|
+
const clientDir = path.join(__dirname, '../../client/dist');
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
serverLogger.warn(
|
|
26
|
-
`client/dist 缺失(${clientDistPath})——页面将不可用(API/WS 不受影响);请先执行 pnpm build:client`,
|
|
27
|
-
);
|
|
19
|
+
if (!existsSync(path.join(clientDir, 'index.html'))) {
|
|
20
|
+
serverLogger.warn(`client/dist 缺失(${clientDir})——页面将不可用(API/WS 不受影响);请先执行 pnpm build:client`);
|
|
28
21
|
}
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
const app = await createApp({
|
|
24
|
+
ctx,
|
|
25
|
+
manifest: manifest as AppManifest,
|
|
26
|
+
appKind: appMeta.appKind as 'agent',
|
|
27
|
+
registry,
|
|
28
|
+
mode: 'prod',
|
|
29
|
+
clientDir,
|
|
30
|
+
resolveUser: (req) => getRequestContext(req)?.identity ?? null,
|
|
31
|
+
decorateHtml: (html) => injectScript(html),
|
|
32
|
+
// CORS / JSON / auth 必须先于 createApp 的 /api/fn RPC;否则应用级函数可被匿名调用。
|
|
33
|
+
beforeRoutes: (base) => {
|
|
34
|
+
base.use(legacyApp);
|
|
35
|
+
},
|
|
33
36
|
});
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
if (existsSync(routesModule)) {
|
|
37
|
-
serverLogger.info('page_mode', { mode: 'strict-pages' });
|
|
38
|
-
app.use(
|
|
39
|
-
createStrictStaticHandler({
|
|
40
|
-
distDir: clientDistPath,
|
|
41
|
-
platformPages: [
|
|
42
|
-
{ path: '/_tbox/card-preview', document: '_tbox/card-preview.html', inputName: 'card-preview' },
|
|
43
|
-
],
|
|
44
|
-
}),
|
|
45
|
-
);
|
|
46
|
-
} else {
|
|
47
|
-
serverLogger.info('page_mode', { mode: 'legacy-spa' });
|
|
48
|
-
app.use(express.static(clientDistPath));
|
|
49
|
-
app.get('*', (req, res) => {
|
|
50
|
-
if (!req.path.startsWith('/api')) {
|
|
51
|
-
res.sendFile(path.join(clientDistPath, 'index.html'));
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
start().catch((err) => {
|
|
38
|
+
start(app).catch((err) => {
|
|
57
39
|
serverLogger.error('Failed to start:', err);
|
|
58
40
|
process.exit(1);
|
|
59
41
|
});
|
|
@@ -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 { clockTool } from './tools/clock.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
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { describe, it, expect } from 'vitest';
|
|
5
5
|
import { diagnosePlugins } from '@tbox.cn/agent-plugin/doctor';
|
|
6
6
|
import { createServerContext, createPluginIntegration } from '@tbox.cn/app-agent-sdk-server';
|
|
7
|
-
import { registerAll } from '
|
|
7
|
+
import { registerAll } from './helpers/register.js';
|
|
8
8
|
|
|
9
9
|
describe('工具 / 卡片 registry 一致性(自注册闭环)', () => {
|
|
10
10
|
it('C2: ctx.tools 每个 key === tool.id', async () => {
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { registerServerModules, type ServerContext } from '@tbox.cn/app-agent-sdk-server';
|
|
2
|
+
import { registry } from '../../../client/.tbox-gen/registry.server';
|
|
3
|
+
|
|
4
|
+
/** 与 createApp 同源的注册面,供单测复用生成 registry。 */
|
|
5
|
+
export async function registerAll(ctx: ServerContext): Promise<void> {
|
|
6
|
+
for (const tool of registry.tools) ctx.tools.register(tool);
|
|
7
|
+
for (const skill of registry.skills) ctx.skills.register(skill);
|
|
8
|
+
for (const card of Object.values(registry.cards)) ctx.cards.register(card as never);
|
|
9
|
+
await registerServerModules(ctx, registry.modules);
|
|
10
|
+
}
|