cx-chat 0.0.1
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/.cursor/rules/i18n-cn-gloss-comments.mdc +31 -0
- package/.cursor/rules/list-page-view-pageconfig.mdc +32 -0
- package/.cursor/rules/no-over-defensive-programming.mdc +90 -0
- package/.cursor/rules/requirement-description-for-agent.mdc +33 -0
- package/.cursor/rules/use-showToast-not-antd-message.mdc +28 -0
- package/.docker/Dockerfile +7 -0
- package/.env +9 -0
- package/.env.development +7 -0
- package/.env.production +7 -0
- package/.gitlab-ci/docker-build.yaml +28 -0
- package/.gitlab-ci/k8s-deploy-dev-master.yaml +42 -0
- package/.gitlab-ci/npm-build.yaml +17 -0
- package/.gitlab-ci.yml +8 -0
- package/.k8s/0-namespace.yaml +6 -0
- package/.k8s/1-configmap-web.yaml +7 -0
- package/.k8s/1-nginx-conf-dev.yaml +110 -0
- package/.k8s/2-deployment.yaml +27 -0
- package/.k8s/3-service.yaml +16 -0
- package/.k8s/4-ingress-dev.yaml +30 -0
- package/.lingma/rules/use-showToast-not-antd-message.md +34 -0
- package/.nginx/nginx.conf +52 -0
- package/.prettierrc +9 -0
- package/README.md +1 -0
- package/eslint.config.js +32 -0
- package/index.html +13 -0
- package/package.json +67 -0
- package/postcss.config.js +6 -0
- package/public/favicon.ico +0 -0
- package/public/vite.svg +1 -0
- package/src/App.tsx +96 -0
- package/src/_doc/0.docs-overview.md +28 -0
- package/src/_doc/cx-ui/0.docs-overview.md +30 -0
- package/src/_doc/cx-ui/comp.1.cx-ui-overview.md +82 -0
- package/src/_doc/cx-ui/comp.2.cx-modal.md +82 -0
- package/src/_doc/cx-ui/comp.3.cx-button.md +89 -0
- package/src/_doc/cx-ui/comp.4.cx-form.md +72 -0
- package/src/_doc/cx-ui/comp.5.cx-fields.md +76 -0
- package/src/_doc/cx-ui/comp.6.cx-tag.md +57 -0
- package/src/_doc/cx-ui/comp.7.cx-empty-state.md +29 -0
- package/src/_doc/meta/0.docs-overview.md +24 -0
- package/src/_doc/meta/comp.1.enum-runtime.md +33 -0
- package/src/_doc/meta/comp.2.dict-runtime.md +39 -0
- package/src/_doc/router/0.docs-overview.md +14 -0
- package/src/_doc/router/guide.1.menu-component-config.md +181 -0
- package/src/_doc/router/guide.2.router-auto-registration.md +114 -0
- package/src/_doc/table-view/0.docs-overview.md +30 -0
- package/src/_doc/table-view/comp.1.table-view.md +542 -0
- package/src/_doc/table-view/props.1.create-table-view-config.md +193 -0
- package/src/_doc/table-view/props.2.table-view-search-fields.md +106 -0
- package/src/api/_mock/README.md +340 -0
- package/src/api/_mock/api.ts +1642 -0
- package/src/api/_mock/bundle-shim.ts +16 -0
- package/src/api/_mock/handler-shim.ts +6 -0
- package/src/api/_mock/handler.ts +458 -0
- package/src/api/_mock/index.ts +711 -0
- package/src/api/_mock/interceptor.ts +15 -0
- package/src/api/_mock/mod.ts +12 -0
- package/src/api/_mock/utils.ts +65 -0
- package/src/api/base/memory.js +24 -0
- package/src/api/chat.js +210 -0
- package/src/api/common/auth.js +70 -0
- package/src/api/menus/business-rules.js +76 -0
- package/src/api/menus/feedback.js +102 -0
- package/src/api/menus/knowledge.js +159 -0
- package/src/api/menus/model-metadata/manage.js +70 -0
- package/src/api/menus/model-metadata/role.js +50 -0
- package/src/api/menus/model-metadata/training-detail-mock-data.js +569 -0
- package/src/api/menus/model-metadata/training.js +28 -0
- package/src/api/menus/skill.js +40 -0
- package/src/api/system/agent-config.js +16 -0
- package/src/api/system/department.js +94 -0
- package/src/api/system/dict.js +86 -0
- package/src/api/system/menu.js +37 -0
- package/src/api/system/permission.js +26 -0
- package/src/api/system/role.js +34 -0
- package/src/api/system/sys-config.js +16 -0
- package/src/api/system/sys-log.js +17 -0
- package/src/api/system/user.js +75 -0
- package/src/api/upload.js +39 -0
- package/src/assets/react.svg +1 -0
- package/src/components/auth/current-user-avatar.tsx +77 -0
- package/src/components/common/code-view.tsx +149 -0
- package/src/components/common/detail-link.tsx +67 -0
- package/src/components/common/error-boundary.tsx +98 -0
- package/src/components/common/language-switcher.tsx +91 -0
- package/src/components/common/lite-table/index.tsx +135 -0
- package/src/components/common/md-editor.tsx +126 -0
- package/src/components/common/modal/confirm-dialog.tsx +113 -0
- package/src/components/common/modal/dep-user-select-multi.tsx +324 -0
- package/src/components/common/modal/dep-user-select.tsx +249 -0
- package/src/components/common/modal/user-select-multi.tsx +266 -0
- package/src/components/common/pagination.tsx +472 -0
- package/src/components/common/path.tsx +175 -0
- package/src/components/common/system-logo-mark.tsx +48 -0
- package/src/components/cx-ui/button/index.less +208 -0
- package/src/components/cx-ui/button/index.tsx +611 -0
- package/src/components/cx-ui/checkbox/index.tsx +78 -0
- package/src/components/cx-ui/date-picker/index.less +17 -0
- package/src/components/cx-ui/date-picker/index.tsx +193 -0
- package/src/components/cx-ui/drawer/index.tsx +47 -0
- package/src/components/cx-ui/empty-state/index.tsx +20 -0
- package/src/components/cx-ui/floating-shell/CxFloatingShell.tsx +89 -0
- package/src/components/cx-ui/floating-shell/cx-floating-shell.less +283 -0
- package/src/components/cx-ui/floating-shell/has-floating-value.ts +41 -0
- package/src/components/cx-ui/form/CxForm.tsx +15 -0
- package/src/components/cx-ui/form/index.tsx +20 -0
- package/src/components/cx-ui/form-item/index.less +26 -0
- package/src/components/cx-ui/form-item/index.tsx +36 -0
- package/src/components/cx-ui/index.ts +70 -0
- package/src/components/cx-ui/input/auto-complete.tsx +134 -0
- package/src/components/cx-ui/input/index.tsx +259 -0
- package/src/components/cx-ui/input-number/index.jsx +66 -0
- package/src/components/cx-ui/modal/index.jsx +212 -0
- package/src/components/cx-ui/modal/index.less +144 -0
- package/src/components/cx-ui/modal/useCxModal.ts +125 -0
- package/src/components/cx-ui/multi-select/index.jsx +74 -0
- package/src/components/cx-ui/multi-select/index.less +40 -0
- package/src/components/cx-ui/multi-select/index2.tsx +361 -0
- package/src/components/cx-ui/radio/index.tsx +33 -0
- package/src/components/cx-ui/range-picker/index.less +65 -0
- package/src/components/cx-ui/range-picker/index.tsx +219 -0
- package/src/components/cx-ui/select/index.less +34 -0
- package/src/components/cx-ui/select/index.tsx +196 -0
- package/src/components/cx-ui/skeleton/index.tsx +12 -0
- package/src/components/cx-ui/steps/index.tsx +14 -0
- package/src/components/cx-ui/styles/_tokens.less +79 -0
- package/src/components/cx-ui/styles/index.less +246 -0
- package/src/components/cx-ui/switch/index.less +106 -0
- package/src/components/cx-ui/switch/index.tsx +120 -0
- package/src/components/cx-ui/table/index.less +160 -0
- package/src/components/cx-ui/table/index.tsx +152 -0
- package/src/components/cx-ui/tabs/index.less +15 -0
- package/src/components/cx-ui/tabs/index.tsx +34 -0
- package/src/components/cx-ui/tag/index.less +51 -0
- package/src/components/cx-ui/tag/index.tsx +140 -0
- package/src/components/cx-ui/timeline/index.tsx +14 -0
- package/src/components/cx-ui/tooltip/index.tsx +67 -0
- package/src/components/cx-ui/tree/index.tsx +193 -0
- package/src/components/cx-ui/tree-select/index.jsx +91 -0
- package/src/components/cx-ui/tree-select/index.less +27 -0
- package/src/components/cx-ui/upload-file/index.less +223 -0
- package/src/components/cx-ui/upload-file/index.tsx +640 -0
- package/src/components/cx-ui/upload-img/index.tsx +291 -0
- package/src/components/layout/components/Header.tsx +216 -0
- package/src/components/layout/components/Sidebar.tsx +717 -0
- package/src/components/layout/index.tsx +95 -0
- package/src/components/table-view/components/search-area.tsx +411 -0
- package/src/components/table-view/components/table-view-config.tsx +528 -0
- package/src/components/table-view/components/table-view.types.ts +478 -0
- package/src/components/table-view/components/tree-api-normalize.ts +38 -0
- package/src/components/table-view/components/tree-data-annotate.ts +31 -0
- package/src/components/table-view/components/tree-sidebar.tsx +74 -0
- package/src/components/table-view/index.tsx +61 -0
- package/src/components/table-view/list-page-view.tsx +1049 -0
- package/src/components/table-view/select-table-view.tsx +1094 -0
- package/src/components/table-view/styles/select-table-view.less +51 -0
- package/src/config/default-system-name.ts +9 -0
- package/src/config/system.ts +165 -0
- package/src/constants/countryCodes.ts +3 -0
- package/src/contexts/AuthContext.tsx +256 -0
- package/src/contexts/ChatContext.tsx +839 -0
- package/src/contexts/MenuContext.tsx +62 -0
- package/src/contexts/ToastContext.tsx +181 -0
- package/src/hooks/useCopyToClipboard.ts +47 -0
- package/src/hooks/useModalSubmit.ts +104 -0
- package/src/hooks/useRouter.ts +240 -0
- package/src/hooks/useStepForm.ts +46 -0
- package/src/hooks/useStickyHeader.ts +42 -0
- package/src/hooks/useThreadActions.ts +105 -0
- package/src/hooks/useUserPreferences.ts +101 -0
- package/src/http/axios.js +372 -0
- package/src/http/mock.interceptor.ts +9 -0
- package/src/http/obfuscationKey.ts +41 -0
- package/src/i18n.ts +60 -0
- package/src/index.js +1 -0
- package/src/index.less +169 -0
- package/src/locales/en/auth.ts +70 -0
- package/src/locales/en/base/memory.ts +28 -0
- package/src/locales/en/base/settings.ts +41 -0
- package/src/locales/en/chat.ts +40 -0
- package/src/locales/en/common.ts +173 -0
- package/src/locales/en/enum.ts +27 -0
- package/src/locales/en/menus/business-rules.ts +48 -0
- package/src/locales/en/menus/feedback.ts +62 -0
- package/src/locales/en/menus/knowledge.ts +120 -0
- package/src/locales/en/menus/model-metadata/index.ts +10 -0
- package/src/locales/en/menus/model-metadata/manage.ts +151 -0
- package/src/locales/en/menus/model-metadata/role.ts +48 -0
- package/src/locales/en/menus/model-metadata/training.ts +65 -0
- package/src/locales/en/menus/skill.ts +34 -0
- package/src/locales/en/system/agent-config.ts +34 -0
- package/src/locales/en/system/department.ts +68 -0
- package/src/locales/en/system/dict.ts +44 -0
- package/src/locales/en/system/menu.ts +45 -0
- package/src/locales/en/system/permission.ts +89 -0
- package/src/locales/en/system/role.ts +25 -0
- package/src/locales/en/system/sys-config.ts +33 -0
- package/src/locales/en/system/sys-log.ts +38 -0
- package/src/locales/en/system/user.ts +113 -0
- package/src/locales/en.ts +68 -0
- package/src/locales/zh/auth.ts +70 -0
- package/src/locales/zh/base/memory.ts +29 -0
- package/src/locales/zh/base/settings.ts +41 -0
- package/src/locales/zh/chat.ts +47 -0
- package/src/locales/zh/common.ts +178 -0
- package/src/locales/zh/enum.ts +28 -0
- package/src/locales/zh/menus/business-rules.ts +47 -0
- package/src/locales/zh/menus/feedback.ts +62 -0
- package/src/locales/zh/menus/knowledge.ts +117 -0
- package/src/locales/zh/menus/model-metadata/index.ts +10 -0
- package/src/locales/zh/menus/model-metadata/manage.ts +151 -0
- package/src/locales/zh/menus/model-metadata/role.ts +47 -0
- package/src/locales/zh/menus/model-metadata/training.ts +64 -0
- package/src/locales/zh/menus/skill.ts +34 -0
- package/src/locales/zh/system/agent-config.ts +33 -0
- package/src/locales/zh/system/department.ts +69 -0
- package/src/locales/zh/system/dict.ts +44 -0
- package/src/locales/zh/system/menu.ts +47 -0
- package/src/locales/zh/system/permission.ts +94 -0
- package/src/locales/zh/system/role.ts +25 -0
- package/src/locales/zh/system/sys-config.ts +32 -0
- package/src/locales/zh/system/sys-log.ts +38 -0
- package/src/locales/zh/system/user.ts +114 -0
- package/src/locales/zh.ts +67 -0
- package/src/main.tsx +50 -0
- package/src/meta/const/index.ts +40 -0
- package/src/meta/index-dict.ts +56 -0
- package/src/meta/index-enum.ts +95 -0
- package/src/meta/index.ts +14 -0
- package/src/meta/module/dict-data/runtime.ts +199 -0
- package/src/meta/module/dict-data/types.ts +17 -0
- package/src/meta/module/enum-data/runtime.ts +75 -0
- package/src/meta/module/enum-data/types.ts +18 -0
- package/src/router/index.tsx +312 -0
- package/src/styles/AntdThemeProvider.tsx +40 -0
- package/src/styles/antd-theme.ts +20 -0
- package/src/styles/global.less +107 -0
- package/src/styles/variable.less +103 -0
- package/src/types/feedback.ts +43 -0
- package/src/types/index.ts +85 -0
- package/src/types/menu.ts +43 -0
- package/src/utils/aesUtil.ts +123 -0
- package/src/utils/chatUtils.ts +524 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/crypto.ts +164 -0
- package/src/utils/date.ts +72 -0
- package/src/utils/file-icons.tsx +79 -0
- package/src/utils/index.ts +168 -0
- package/src/utils/markdown-math-plugins.ts +21 -0
- package/src/utils/menuI18n.ts +305 -0
- package/src/utils/menuRouteRegistry.ts +78 -0
- package/src/utils/permission-crud.ts +147 -0
- package/src/utils/routeConfig.ts +350 -0
- package/src/utils/storage.ts +135 -0
- package/src/utils/toastBridge.ts +26 -0
- package/src/utils/url.ts +38 -0
- package/src/utils/validation.ts +16 -0
- package/src/views/auth/auth-code/index.less +169 -0
- package/src/views/auth/auth-code/index.module.less +174 -0
- package/src/views/auth/auth-code/index.tsx +233 -0
- package/src/views/auth/login.tsx +498 -0
- package/src/views/auth/register.tsx +388 -0
- package/src/views/base/memory/index.tsx +136 -0
- package/src/views/base/memory/modal/detail-modal.tsx +89 -0
- package/src/views/base/memory/modal/submit-modal.tsx +134 -0
- package/src/views/base/settings/index.tsx +657 -0
- package/src/views/chat/chat.less +323 -0
- package/src/views/chat/components/chat-input.tsx +298 -0
- package/src/views/chat/components/header-thread-title.tsx +210 -0
- package/src/views/chat/components/message-list/content-answer.tsx +100 -0
- package/src/views/chat/components/message-list/content-question.tsx +18 -0
- package/src/views/chat/components/message-list/index.tsx +520 -0
- package/src/views/chat/components/message-list/message-item.tsx +199 -0
- package/src/views/chat/components/message-list/preparation-demo-items.ts +147 -0
- package/src/views/chat/components/message-list/preparation-steps.tsx +506 -0
- package/src/views/chat/components/message-list/suggestion-list.tsx +36 -0
- package/src/views/chat/components/message-list/thinking-process.tsx +49 -0
- package/src/views/chat/components/message-list/toolbar.tsx +224 -0
- package/src/views/chat/components/message-list/use-message-list-scroll.ts +214 -0
- package/src/views/chat/components/references-knowledge/context.tsx +57 -0
- package/src/views/chat/components/references-knowledge/index.ts +9 -0
- package/src/views/chat/components/references-knowledge/modal/knowledge-detail-drawer.tsx +556 -0
- package/src/views/chat/components/references-knowledge/modal/knowledge-doc-detail-drawer.tsx +529 -0
- package/src/views/chat/components/references-knowledge/panel.tsx +115 -0
- package/src/views/chat/hooks/use-chat-common.ts +19 -0
- package/src/views/chat/index-session.tsx +647 -0
- package/src/views/chat/index.tsx +127 -0
- package/src/views/page-error/401.tsx +56 -0
- package/src/views/page-error/404.tsx +56 -0
- package/src/views/page-menus/business-rules/index.tsx +376 -0
- package/src/views/page-menus/business-rules/modal/detail-modal.tsx +186 -0
- package/src/views/page-menus/business-rules/modal/scope-modal.tsx +272 -0
- package/src/views/page-menus/business-rules/modal/submit-modal.tsx +142 -0
- package/src/views/page-menus/feedback/components/feedback-dataset-list.tsx +471 -0
- package/src/views/page-menus/feedback/index.tsx +166 -0
- package/src/views/page-menus/feedback/modal/export-feedback-modal.tsx +367 -0
- package/src/views/page-menus/knowledge/components/doc-editor-by-type.tsx +32 -0
- package/src/views/page-menus/knowledge/components/doc-editor-type-file.tsx +330 -0
- package/src/views/page-menus/knowledge/detail.tsx +600 -0
- package/src/views/page-menus/knowledge/index.tsx +337 -0
- package/src/views/page-menus/knowledge/modal/detail-modal.tsx +618 -0
- package/src/views/page-menus/knowledge/modal/doc-detail-modal.tsx +550 -0
- package/src/views/page-menus/knowledge/modal/doc-parse.ts +99 -0
- package/src/views/page-menus/knowledge/modal/doc-submit-modal.tsx +349 -0
- package/src/views/page-menus/knowledge/modal/doc-type-picker-modal.tsx +88 -0
- package/src/views/page-menus/knowledge/modal/knowledge-user-select-modal.tsx +283 -0
- package/src/views/page-menus/knowledge/modal/submit-modal.tsx +179 -0
- package/src/views/page-menus/model-metadata/manage/components/metadata-detail-schema-tab.tsx +114 -0
- package/src/views/page-menus/model-metadata/manage/components/step1-basic-info.tsx +232 -0
- package/src/views/page-menus/model-metadata/manage/components/step2-schema.tsx +316 -0
- package/src/views/page-menus/model-metadata/manage/components/step3-permissions.tsx +134 -0
- package/src/views/page-menus/model-metadata/manage/components/step4-documents.tsx +134 -0
- package/src/views/page-menus/model-metadata/manage/components/step5-example-sql.tsx +101 -0
- package/src/views/page-menus/model-metadata/manage/components/submit-add.tsx +338 -0
- package/src/views/page-menus/model-metadata/manage/components/submit-edit.tsx +276 -0
- package/src/views/page-menus/model-metadata/manage/detail.tsx +298 -0
- package/src/views/page-menus/model-metadata/manage/hooks/model-metadata-submit-shared.ts +113 -0
- package/src/views/page-menus/model-metadata/manage/hooks/use-model-metadata-item-state.ts +20 -0
- package/src/views/page-menus/model-metadata/manage/index.tsx +304 -0
- package/src/views/page-menus/model-metadata/manage/modal/components/table-schema.ts +374 -0
- package/src/views/page-menus/model-metadata/manage/modal/components/use-table-detail-tabs.tsx +151 -0
- package/src/views/page-menus/model-metadata/manage/modal/components/use-table-submit-tabs.tsx +423 -0
- package/src/views/page-menus/model-metadata/manage/modal/detail-modal.tsx +218 -0
- package/src/views/page-menus/model-metadata/manage/modal/submit-modal.tsx +261 -0
- package/src/views/page-menus/model-metadata/manage/modal/table-detail-modal.tsx +196 -0
- package/src/views/page-menus/model-metadata/manage/modal/table-submit-modal.tsx +229 -0
- package/src/views/page-menus/model-metadata/manage/submit.tsx +31 -0
- package/src/views/page-menus/model-metadata/role/index.tsx +207 -0
- package/src/views/page-menus/model-metadata/role/modal/detail-modal.tsx +97 -0
- package/src/views/page-menus/model-metadata/role/modal/role-assign-users-modal.tsx +254 -0
- package/src/views/page-menus/model-metadata/role/modal/role-assign-users-panel.tsx +393 -0
- package/src/views/page-menus/model-metadata/role/modal/role-assign-users-utils.ts +120 -0
- package/src/views/page-menus/model-metadata/role/modal/role-permission-assign-panel.tsx +698 -0
- package/src/views/page-menus/model-metadata/role/modal/role-permission-modal.tsx +237 -0
- package/src/views/page-menus/model-metadata/role/modal/submit-modal.tsx +135 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/index.ts +4 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/node-card.tsx +72 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/summary-lines.ts +196 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/summary-list.tsx +153 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/timeline.tsx +103 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/types.ts +82 -0
- package/src/views/page-menus/model-metadata/training/detail.tsx +159 -0
- package/src/views/page-menus/model-metadata/training/index.tsx +236 -0
- package/src/views/page-menus/model-metadata/training/modal/update-detail-modal.tsx +154 -0
- package/src/views/page-menus/skill/index.tsx +201 -0
- package/src/views/page-menus/skill/modal/detail-modal.tsx +156 -0
- package/src/views/page-menus/skill/modal/submit-modal.tsx +214 -0
- package/src/views/page-system/agent-config/index.tsx +370 -0
- package/src/views/page-system/department/departmentFormShared.ts +36 -0
- package/src/views/page-system/department/index.tsx +541 -0
- package/src/views/page-system/department/modal/detail-modal.tsx +94 -0
- package/src/views/page-system/department/modal/member-role-modal.tsx +128 -0
- package/src/views/page-system/department/modal/submit-modal.tsx +265 -0
- package/src/views/page-system/dict/index.tsx +440 -0
- package/src/views/page-system/dict/modal/cate-submit-modal.tsx +315 -0
- package/src/views/page-system/dict/modal/submit-modal.tsx +184 -0
- package/src/views/page-system/logs/components/index.ts +3 -0
- package/src/views/page-system/logs/components/log-message-demo.tsx +30 -0
- package/src/views/page-system/logs/components/log-message-stream.ts +184 -0
- package/src/views/page-system/logs/components/message-list/content-answer.tsx +100 -0
- package/src/views/page-system/logs/components/message-list/content-question.tsx +18 -0
- package/src/views/page-system/logs/components/message-list/index.tsx +515 -0
- package/src/views/page-system/logs/components/message-list/message-item.tsx +193 -0
- package/src/views/page-system/logs/components/message-list/preparation-demo-items.ts +147 -0
- package/src/views/page-system/logs/components/message-list/preparation-steps.tsx +506 -0
- package/src/views/page-system/logs/components/message-list/suggestion-list.tsx +36 -0
- package/src/views/page-system/logs/components/message-list/thinking-process.tsx +49 -0
- package/src/views/page-system/logs/components/message-list/toolbar.tsx +134 -0
- package/src/views/page-system/logs/components/message-list/use-message-list-scroll.ts +214 -0
- package/src/views/page-system/logs/components/message-modal.tsx +239 -0
- package/src/views/page-system/logs/index.tsx +132 -0
- package/src/views/page-system/logs/modal/detail-modal.tsx +157 -0
- package/src/views/page-system/menu/components/menuFormShared.ts +283 -0
- package/src/views/page-system/menu/index.less +12 -0
- package/src/views/page-system/menu/index.tsx +410 -0
- package/src/views/page-system/menu/modal/icon-modal.less +51 -0
- package/src/views/page-system/menu/modal/icon-modal.tsx +87 -0
- package/src/views/page-system/menu/modal/submit-modal.tsx +263 -0
- package/src/views/page-system/permission/index.tsx +562 -0
- package/src/views/page-system/permission/modal/detail-modal.tsx +179 -0
- package/src/views/page-system/permission/modal/submit-modal.less +146 -0
- package/src/views/page-system/permission/modal/submit-modal.tsx +650 -0
- package/src/views/page-system/role/index.tsx +163 -0
- package/src/views/page-system/role/modal/detail-modal.tsx +127 -0
- package/src/views/page-system/role/modal/permission-assign-group-rules.ts +86 -0
- package/src/views/page-system/role/modal/permission-modal.tsx +111 -0
- package/src/views/page-system/role/modal/role-modal-shell-styles.ts +21 -0
- package/src/views/page-system/role/modal/role-permission-assign-panel.tsx +916 -0
- package/src/views/page-system/role/modal/role-permission-assign-shared.ts +1047 -0
- package/src/views/page-system/role/modal/submit-modal.tsx +193 -0
- package/src/views/page-system/sys-config/index.tsx +294 -0
- package/src/views/page-system/user/components/user-role-column.tsx +87 -0
- package/src/views/page-system/user/index.tsx +439 -0
- package/src/views/page-system/user/modal/assign-roles-modal.tsx +389 -0
- package/src/views/page-system/user/modal/detail-modal.tsx +72 -0
- package/src/views/page-system/user/modal/modal-style/submit-modal.less +40 -0
- package/src/views/page-system/user/modal/submit-modal.less +40 -0
- package/src/views/page-system/user/modal/submit-modal.tsx +287 -0
- package/src/views/page-system/user/userFormShared.ts +51 -0
- package/tailwind.config.js +17 -0
- package/tsconfig.app.json +48 -0
- package/tsconfig.json +11 -0
- package/tsconfig.node.json +26 -0
- package/vite.config.ts +264 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Spin } from 'antd'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { useTranslation } from 'react-i18next'
|
|
4
|
+
|
|
5
|
+
export const ThinkingProcess: React.FC<{
|
|
6
|
+
thoughts: string[]
|
|
7
|
+
isContentVisible: boolean
|
|
8
|
+
}> = ({ thoughts, isContentVisible }) => {
|
|
9
|
+
const { t } = useTranslation()
|
|
10
|
+
const currentThought =
|
|
11
|
+
thoughts && thoughts.length > 0 ? thoughts[thoughts.length - 1] : ''
|
|
12
|
+
|
|
13
|
+
const displayThought = React.useMemo(() => {
|
|
14
|
+
if (!currentThought) return ''
|
|
15
|
+
let text = currentThought
|
|
16
|
+
try {
|
|
17
|
+
if (currentThought.trim().startsWith('{')) {
|
|
18
|
+
const parsed = JSON.parse(currentThought)
|
|
19
|
+
text = parsed.thought || parsed.action || parsed.status || currentThought
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
// ignore
|
|
23
|
+
}
|
|
24
|
+
return text.replace(/\.{3}$|…$/, '')
|
|
25
|
+
}, [currentThought])
|
|
26
|
+
|
|
27
|
+
if (isContentVisible) return null
|
|
28
|
+
if (!thoughts || thoughts.length === 0) return null
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div className="mb-2">
|
|
32
|
+
<div className="flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400">
|
|
33
|
+
<span
|
|
34
|
+
key={displayThought}
|
|
35
|
+
className="font-mono animate-fade-in"
|
|
36
|
+
>
|
|
37
|
+
{displayThought}
|
|
38
|
+
</span>
|
|
39
|
+
<div
|
|
40
|
+
className="flex h-6 shrink-0 items-center [&_.ant-spin-nested-loading]:!p-0"
|
|
41
|
+
role="status"
|
|
42
|
+
aria-label={t('common.loading')}
|
|
43
|
+
>
|
|
44
|
+
<Spin size="small" />
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Check, Copy } from 'lucide-react'
|
|
3
|
+
import clsx from 'clsx'
|
|
4
|
+
import { useTranslation } from 'react-i18next'
|
|
5
|
+
import { useCopyToClipboard } from '@/hooks/useCopyToClipboard'
|
|
6
|
+
import type { Message } from '@/types'
|
|
7
|
+
import { CxButton } from '@cx-ui'
|
|
8
|
+
|
|
9
|
+
/** 日志弹窗消息列表:暂不展示删除 */
|
|
10
|
+
const LOG_MESSAGE_LIST_DELETE_ENABLED = false
|
|
11
|
+
/** 日志弹窗消息列表:暂不展示好评、不满意 */
|
|
12
|
+
const LOG_MESSAGE_LIST_FEEDBACK_ENABLED = false
|
|
13
|
+
/** 日志弹窗消息列表:暂不展示重新生成 */
|
|
14
|
+
const LOG_MESSAGE_LIST_REGENERATE_ENABLED = false
|
|
15
|
+
|
|
16
|
+
function CopyButton({ content }: { content: string }) {
|
|
17
|
+
const { copy, isCopying } = useCopyToClipboard()
|
|
18
|
+
const { t } = useTranslation()
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<CxButton.Icon
|
|
22
|
+
type={isCopying ? 'success' : 'primary'}
|
|
23
|
+
icon={
|
|
24
|
+
isCopying ? (
|
|
25
|
+
<Check size={14} className="animate-pop" />
|
|
26
|
+
) : (
|
|
27
|
+
<Copy size={14} />
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
tooltipTitle={isCopying ? t('common.copied') : t('common.copy')}
|
|
31
|
+
tooltipTone={isCopying ? 'success' : 'default'}
|
|
32
|
+
disabled={isCopying}
|
|
33
|
+
onClick={() => void copy(content)}
|
|
34
|
+
className={clsx(isCopying && 'scale-110')}
|
|
35
|
+
/>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type ToolbarQuestionProps = {
|
|
40
|
+
content: string
|
|
41
|
+
turnId: string
|
|
42
|
+
messageSelectMode: boolean
|
|
43
|
+
enableMessageDelete: boolean
|
|
44
|
+
hasDeleteApi: boolean
|
|
45
|
+
userMessageDeleteHidden: boolean
|
|
46
|
+
onEnterSelectMode: (turnId?: string) => void
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 用户消息气泡下方:复制(删除已关闭,见 LOG_MESSAGE_LIST_DELETE_ENABLED) */
|
|
50
|
+
export function ToolbarQuestion({
|
|
51
|
+
content,
|
|
52
|
+
messageSelectMode,
|
|
53
|
+
}: ToolbarQuestionProps) {
|
|
54
|
+
if (!content || messageSelectMode) return null
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div className="mt-1 flex justify-end">
|
|
58
|
+
<div className="flex items-center gap-1 opacity-0 transition-opacity duration-200 group-hover:opacity-100">
|
|
59
|
+
<CopyButton content={content} />
|
|
60
|
+
{/*
|
|
61
|
+
删除:日志弹窗不开放。恢复示例:
|
|
62
|
+
{LOG_MESSAGE_LIST_DELETE_ENABLED && enableMessageDelete && hasDeleteApi && !userMessageDeleteHidden && (
|
|
63
|
+
<CxButton.IconDelete ... onClick={() => onEnterSelectMode(turnId)} />
|
|
64
|
+
)}
|
|
65
|
+
*/}
|
|
66
|
+
{LOG_MESSAGE_LIST_DELETE_ENABLED ? null : null}
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type ToolbarAnswerProps = {
|
|
73
|
+
message: Message
|
|
74
|
+
turnId: string
|
|
75
|
+
isLastAssistantMessage: boolean
|
|
76
|
+
messageSelectMode: boolean
|
|
77
|
+
enableMessageDelete: boolean
|
|
78
|
+
hasDeleteApi: boolean
|
|
79
|
+
onEnterSelectMode: (turnId?: string) => void
|
|
80
|
+
onFeedback?: (messageId: string, score: number) => void
|
|
81
|
+
onRegenerate?: (message: Message) => void | Promise<void>
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 助手消息下方:复制(好评/不满意/重新生成/删除已关闭,见顶部开关常量) */
|
|
85
|
+
export function ToolbarAnswer({
|
|
86
|
+
message,
|
|
87
|
+
isLastAssistantMessage,
|
|
88
|
+
messageSelectMode,
|
|
89
|
+
}: ToolbarAnswerProps) {
|
|
90
|
+
if (message.role !== 'assistant') return null
|
|
91
|
+
if (!(message.content || message.is_streaming)) return null
|
|
92
|
+
/** 仅有 preparation、尚无正文时不再显示工具栏占位 loading,避免与步骤条重复 */
|
|
93
|
+
if (
|
|
94
|
+
message.is_streaming &&
|
|
95
|
+
!message.content &&
|
|
96
|
+
(message.preparation_items?.length ?? 0) > 0
|
|
97
|
+
) {
|
|
98
|
+
return null
|
|
99
|
+
}
|
|
100
|
+
if (messageSelectMode) return null
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<div
|
|
104
|
+
className={clsx(
|
|
105
|
+
'ml-0 mt-1 flex items-center gap-1 transition-opacity duration-200',
|
|
106
|
+
isLastAssistantMessage
|
|
107
|
+
? 'opacity-100'
|
|
108
|
+
: 'opacity-0 group-hover:opacity-100',
|
|
109
|
+
)}
|
|
110
|
+
>
|
|
111
|
+
{!message.is_streaming && message.content && (
|
|
112
|
+
<CopyButton content={message.content} />
|
|
113
|
+
)}
|
|
114
|
+
|
|
115
|
+
{/*
|
|
116
|
+
好评 / 不满意:日志弹窗不开放。恢复时将 LOG_MESSAGE_LIST_FEEDBACK_ENABLED 置 true,
|
|
117
|
+
并从 chat message-list/toolbar 拷回 ThumbsUp / ThumbsDown 与 onFeedback 逻辑。
|
|
118
|
+
*/}
|
|
119
|
+
{LOG_MESSAGE_LIST_FEEDBACK_ENABLED ? null : null}
|
|
120
|
+
|
|
121
|
+
{/*
|
|
122
|
+
重新生成:日志弹窗不开放。恢复时将 LOG_MESSAGE_LIST_REGENERATE_ENABLED 置 true,
|
|
123
|
+
并接回 onRegenerate、RefreshCw 按钮。
|
|
124
|
+
*/}
|
|
125
|
+
{LOG_MESSAGE_LIST_REGENERATE_ENABLED ? null : null}
|
|
126
|
+
|
|
127
|
+
{/*
|
|
128
|
+
删除:日志弹窗不开放。恢复时将 LOG_MESSAGE_LIST_DELETE_ENABLED 置 true,
|
|
129
|
+
并接回 CxButton.IconDelete 与 onEnterSelectMode。
|
|
130
|
+
*/}
|
|
131
|
+
{LOG_MESSAGE_LIST_DELETE_ENABLED ? null : null}
|
|
132
|
+
</div>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import type { Message } from '@/types';
|
|
3
|
+
import { CHAT_MESSAGE_LIST_PREP_LAYOUT_EVENT } from './preparation-steps';
|
|
4
|
+
|
|
5
|
+
/** 最后一条助手消息 preparation 变化时驱动列表滚底(与 messages 引用未必同步变) */
|
|
6
|
+
function preparationItemsScrollSignature(msg: Message | undefined): string {
|
|
7
|
+
const items = msg?.preparation_items
|
|
8
|
+
if (!items?.length) return ''
|
|
9
|
+
return items
|
|
10
|
+
.map((x) => `${x.code}\t${x.name}\t${x.phase}\t${x.description ?? ''}`)
|
|
11
|
+
.join('\n')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function useMessageListScroll(opts: {
|
|
15
|
+
messages: Message[];
|
|
16
|
+
isLoading: boolean;
|
|
17
|
+
hasMore?: boolean;
|
|
18
|
+
isLoadingMore?: boolean;
|
|
19
|
+
onLoadMore?: () => void;
|
|
20
|
+
}) {
|
|
21
|
+
const { messages, isLoading, hasMore, isLoadingMore, onLoadMore } = opts;
|
|
22
|
+
|
|
23
|
+
const prepScrollKey = useMemo(() => {
|
|
24
|
+
const last = messages[messages.length - 1]
|
|
25
|
+
if (!last || last.role !== 'assistant') return ''
|
|
26
|
+
return preparationItemsScrollSignature(last)
|
|
27
|
+
}, [messages])
|
|
28
|
+
|
|
29
|
+
const topRef = useRef<HTMLDivElement>(null);
|
|
30
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
31
|
+
|
|
32
|
+
const prevLastMessageId = useRef<string | null>(null);
|
|
33
|
+
const prevMessagesLength = useRef(messages.length);
|
|
34
|
+
const prevIsLoadingRef = useRef(isLoading);
|
|
35
|
+
const isInitialLoad = useRef(true);
|
|
36
|
+
/** 流式 / Markdown 绘制后高度仍会变化:防抖 + rAF 避免与 useLayoutEffect、scrollIntoView smooth 打架导致上下跳 */
|
|
37
|
+
const stickScrollTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
38
|
+
|
|
39
|
+
const clearStickScrollTimer = () => {
|
|
40
|
+
if (stickScrollTimerRef.current) {
|
|
41
|
+
clearTimeout(stickScrollTimerRef.current);
|
|
42
|
+
stickScrollTimerRef.current = null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const scrollMessagesContainerToEnd = (
|
|
47
|
+
mode: 'immediate' | 'afterPaint' | 'debounced',
|
|
48
|
+
) => {
|
|
49
|
+
const el = containerRef.current;
|
|
50
|
+
if (!el) return;
|
|
51
|
+
|
|
52
|
+
const apply = () => {
|
|
53
|
+
el.scrollTop = el.scrollHeight - el.clientHeight;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (mode === 'immediate') {
|
|
57
|
+
apply();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (mode === 'afterPaint') {
|
|
62
|
+
requestAnimationFrame(() => {
|
|
63
|
+
requestAnimationFrame(apply);
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
clearStickScrollTimer();
|
|
69
|
+
stickScrollTimerRef.current = setTimeout(() => {
|
|
70
|
+
stickScrollTimerRef.current = null;
|
|
71
|
+
requestAnimationFrame(() => {
|
|
72
|
+
requestAnimationFrame(apply);
|
|
73
|
+
});
|
|
74
|
+
}, 80);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
return () => clearStickScrollTimer();
|
|
79
|
+
}, []);
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const onPrepLayout = () => {
|
|
83
|
+
const el = containerRef.current;
|
|
84
|
+
if (!el) return;
|
|
85
|
+
const gap =
|
|
86
|
+
el.scrollHeight - el.scrollTop - el.clientHeight;
|
|
87
|
+
if (gap < 140) {
|
|
88
|
+
scrollMessagesContainerToEnd('debounced');
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
window.addEventListener(CHAT_MESSAGE_LIST_PREP_LAYOUT_EVENT, onPrepLayout);
|
|
92
|
+
return () =>
|
|
93
|
+
window.removeEventListener(CHAT_MESSAGE_LIST_PREP_LAYOUT_EVENT, onPrepLayout);
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (messages.length === 0) return;
|
|
98
|
+
|
|
99
|
+
const last = messages[messages.length - 1];
|
|
100
|
+
const currentLastId = last?.id ?? null;
|
|
101
|
+
const prevLastId = prevLastMessageId.current;
|
|
102
|
+
|
|
103
|
+
const prepPhaseNoAnswer =
|
|
104
|
+
last?.role === 'assistant' &&
|
|
105
|
+
(last.preparation_items?.length ?? 0) > 0 &&
|
|
106
|
+
!(typeof last.content === 'string' && last.content.trim());
|
|
107
|
+
|
|
108
|
+
if (isInitialLoad.current && messages.length > 0) {
|
|
109
|
+
scrollMessagesContainerToEnd('immediate');
|
|
110
|
+
isInitialLoad.current = false;
|
|
111
|
+
} else if (currentLastId && currentLastId !== prevLastId) {
|
|
112
|
+
scrollMessagesContainerToEnd('afterPaint');
|
|
113
|
+
} else {
|
|
114
|
+
const stick =
|
|
115
|
+
isLoading ||
|
|
116
|
+
(last?.role === 'assistant' && Boolean(last.is_streaming)) ||
|
|
117
|
+
prepPhaseNoAnswer;
|
|
118
|
+
if (stick && currentLastId && currentLastId === prevLastId) {
|
|
119
|
+
const container = containerRef.current;
|
|
120
|
+
if (container) {
|
|
121
|
+
const gap =
|
|
122
|
+
container.scrollHeight -
|
|
123
|
+
container.scrollTop -
|
|
124
|
+
container.clientHeight;
|
|
125
|
+
if (gap < 140) {
|
|
126
|
+
scrollMessagesContainerToEnd('debounced');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
prevLastMessageId.current = currentLastId;
|
|
133
|
+
prevMessagesLength.current = messages.length;
|
|
134
|
+
}, [messages, isLoading, prepScrollKey]);
|
|
135
|
+
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (messages.length === 0) {
|
|
138
|
+
isInitialLoad.current = true;
|
|
139
|
+
}
|
|
140
|
+
}, [messages.length]);
|
|
141
|
+
|
|
142
|
+
/** 仅首屏拉取结束滚底;勿在向上加载更多导致 length 增加时滚底 */
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
const wasLoading = prevIsLoadingRef.current;
|
|
145
|
+
prevIsLoadingRef.current = isLoading;
|
|
146
|
+
if (wasLoading && !isLoading && messages.length > 0) {
|
|
147
|
+
scrollMessagesContainerToEnd('afterPaint');
|
|
148
|
+
}
|
|
149
|
+
}, [isLoading, messages.length]);
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
const observer = new IntersectionObserver(
|
|
153
|
+
(entries) => {
|
|
154
|
+
if (entries[0].isIntersecting && hasMore && !isLoadingMore) {
|
|
155
|
+
const container = containerRef.current;
|
|
156
|
+
if (container && onLoadMore) {
|
|
157
|
+
onLoadMore();
|
|
158
|
+
requestAnimationFrame(() => {});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
{ threshold: 0.1 },
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
if (topRef.current) {
|
|
166
|
+
observer.observe(topRef.current);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return () => observer.disconnect();
|
|
170
|
+
}, [hasMore, isLoadingMore, onLoadMore]);
|
|
171
|
+
|
|
172
|
+
/** 向上加载更多:记录 prepend 前滚动位置,内容插入顶部后补偿 scrollTop */
|
|
173
|
+
const loadMoreScrollSnapshotRef = useRef<{
|
|
174
|
+
scrollHeight: number;
|
|
175
|
+
scrollTop: number;
|
|
176
|
+
} | null>(null);
|
|
177
|
+
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
if (isLoadingMore && containerRef.current) {
|
|
180
|
+
loadMoreScrollSnapshotRef.current = {
|
|
181
|
+
scrollHeight: containerRef.current.scrollHeight,
|
|
182
|
+
scrollTop: containerRef.current.scrollTop,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}, [isLoadingMore]);
|
|
186
|
+
|
|
187
|
+
useLayoutEffect(() => {
|
|
188
|
+
const container = containerRef.current;
|
|
189
|
+
const snap = loadMoreScrollSnapshotRef.current;
|
|
190
|
+
|
|
191
|
+
if (snap && container && !isLoadingMore) {
|
|
192
|
+
const heightDiff = container.scrollHeight - snap.scrollHeight;
|
|
193
|
+
if (heightDiff > 0) {
|
|
194
|
+
container.scrollTop = snap.scrollTop + heightDiff;
|
|
195
|
+
loadMoreScrollSnapshotRef.current = null;
|
|
196
|
+
}
|
|
197
|
+
} else if (
|
|
198
|
+
!snap &&
|
|
199
|
+
messages.length > prevMessagesLength.current &&
|
|
200
|
+
container
|
|
201
|
+
) {
|
|
202
|
+
const isNearBottom =
|
|
203
|
+
container.scrollHeight - container.scrollTop - container.clientHeight <
|
|
204
|
+
100;
|
|
205
|
+
if (isNearBottom || messages.length <= 1) {
|
|
206
|
+
scrollMessagesContainerToEnd('afterPaint');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
prevMessagesLength.current = messages.length;
|
|
210
|
+
}, [messages, isLoadingMore]);
|
|
211
|
+
|
|
212
|
+
return { topRef, containerRef };
|
|
213
|
+
}
|
|
214
|
+
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CHAT_STREAM_HANDLED_JSON_ERROR,
|
|
3
|
+
getChatSessionIdAPI,
|
|
4
|
+
postChatStreamRequest,
|
|
5
|
+
} from '@/api/chat'
|
|
6
|
+
import { useAuth } from '@/contexts/AuthContext'
|
|
7
|
+
import { clampChatStreamFeatureFlags } from '@/contexts/ChatContext'
|
|
8
|
+
import { useToast } from '@/contexts/ToastContext'
|
|
9
|
+
import type { Message } from '@/types'
|
|
10
|
+
import {
|
|
11
|
+
markMessagePreparationDone,
|
|
12
|
+
omitMessagePreparationForPersist,
|
|
13
|
+
parseNewSessionId,
|
|
14
|
+
} from '@/utils/chatUtils'
|
|
15
|
+
import {
|
|
16
|
+
getChatEnableDataAnalysis,
|
|
17
|
+
getChatEnableKnowledgeBase,
|
|
18
|
+
getChatEnableNetwork,
|
|
19
|
+
} from '@/utils/storage'
|
|
20
|
+
import MessageList from './message-list'
|
|
21
|
+
import '@/views/chat/chat.less'
|
|
22
|
+
import { CxModal } from '@cx-ui'
|
|
23
|
+
import {
|
|
24
|
+
forwardRef,
|
|
25
|
+
useImperativeHandle,
|
|
26
|
+
useMemo,
|
|
27
|
+
useRef,
|
|
28
|
+
useState,
|
|
29
|
+
} from 'react'
|
|
30
|
+
import { useTranslation } from 'react-i18next'
|
|
31
|
+
import { readLogMessageSseStream } from './log-message-stream'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 日志消息弹窗:消息列表仅保留复制。
|
|
35
|
+
* 好评 / 不满意 / 重新生成 / 删除 已在 `./message-list/toolbar.tsx` 关闭,
|
|
36
|
+
* 批量删除栏在 `./message-list/index.tsx` 关闭(见 LOG_MESSAGE_LIST_BATCH_DELETE_ENABLED),
|
|
37
|
+
* 引导式提问在 `./message-list/message-item.tsx` 关闭(见 LOG_MESSAGE_LIST_SUGGESTION_ENABLED)。
|
|
38
|
+
*/
|
|
39
|
+
const FIXED_OPEN_MESSAGE = '今天上海天气如何?'
|
|
40
|
+
|
|
41
|
+
/** 生成消息列表用的临时 id。 */
|
|
42
|
+
function createMessageId(prefix: string) {
|
|
43
|
+
if (typeof crypto.randomUUID === 'function') {
|
|
44
|
+
return `${prefix}-${crypto.randomUUID()}`
|
|
45
|
+
}
|
|
46
|
+
return `${prefix}-${Date.now()}`
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const MessageModal = forwardRef(function MessageModal(_props: unknown, ref) {
|
|
50
|
+
const { t } = useTranslation()
|
|
51
|
+
const { showToast } = useToast()
|
|
52
|
+
const { hasPermission } = useAuth()
|
|
53
|
+
const [open, setOpen] = useState(false)
|
|
54
|
+
const [modalKey, setModalKey] = useState(0)
|
|
55
|
+
const [messages, setMessages] = useState<Message[]>([])
|
|
56
|
+
const [streamingContent, setStreamingContent] = useState<Message | null>(null)
|
|
57
|
+
const [isStreaming, setIsStreaming] = useState(false)
|
|
58
|
+
const [booting, setBooting] = useState(false)
|
|
59
|
+
|
|
60
|
+
const abortRef = useRef<AbortController | null>(null)
|
|
61
|
+
const streamGenRef = useRef(0)
|
|
62
|
+
const streamingRef = useRef<Message | null>(null)
|
|
63
|
+
|
|
64
|
+
const displayMessages = useMemo(() => {
|
|
65
|
+
if (streamingContent) return [...messages, streamingContent]
|
|
66
|
+
return messages
|
|
67
|
+
}, [messages, streamingContent])
|
|
68
|
+
|
|
69
|
+
/** 中止当前流式请求。 */
|
|
70
|
+
const abortStream = () => {
|
|
71
|
+
streamGenRef.current += 1
|
|
72
|
+
if (abortRef.current) {
|
|
73
|
+
abortRef.current.abort()
|
|
74
|
+
abortRef.current = null
|
|
75
|
+
}
|
|
76
|
+
setIsStreaming(false)
|
|
77
|
+
setStreamingContent(null)
|
|
78
|
+
streamingRef.current = null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 新会话并发送固定提问。 */
|
|
82
|
+
const startFreshChat = async () => {
|
|
83
|
+
abortStream()
|
|
84
|
+
const thisGen = streamGenRef.current
|
|
85
|
+
|
|
86
|
+
setMessages([])
|
|
87
|
+
setStreamingContent(null)
|
|
88
|
+
streamingRef.current = null
|
|
89
|
+
setBooting(true)
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const raw = await getChatSessionIdAPI()
|
|
93
|
+
const sessionId = parseNewSessionId(raw)
|
|
94
|
+
const streamFlags = clampChatStreamFeatureFlags(
|
|
95
|
+
{
|
|
96
|
+
enableNetwork: getChatEnableNetwork(),
|
|
97
|
+
enableKnowledgeBase: getChatEnableKnowledgeBase(),
|
|
98
|
+
enableDataAnalysis: getChatEnableDataAnalysis(),
|
|
99
|
+
},
|
|
100
|
+
hasPermission,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
const optimisticUserMessage: Message = {
|
|
104
|
+
id: createMessageId('u'),
|
|
105
|
+
role: 'user',
|
|
106
|
+
content: FIXED_OPEN_MESSAGE,
|
|
107
|
+
created_at: new Date().toISOString(),
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const initialStreamingMessage: Message = {
|
|
111
|
+
id: createMessageId('temp'),
|
|
112
|
+
role: 'assistant',
|
|
113
|
+
content: '',
|
|
114
|
+
thoughts: [],
|
|
115
|
+
options: [],
|
|
116
|
+
preparation_items: [],
|
|
117
|
+
is_streaming: true,
|
|
118
|
+
created_at: new Date().toISOString(),
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
setMessages([optimisticUserMessage])
|
|
122
|
+
setStreamingContent(initialStreamingMessage)
|
|
123
|
+
streamingRef.current = initialStreamingMessage
|
|
124
|
+
setIsStreaming(true)
|
|
125
|
+
|
|
126
|
+
const controller = new AbortController()
|
|
127
|
+
abortRef.current = controller
|
|
128
|
+
|
|
129
|
+
const response = await postChatStreamRequest(
|
|
130
|
+
{
|
|
131
|
+
message: FIXED_OPEN_MESSAGE,
|
|
132
|
+
session_id: sessionId,
|
|
133
|
+
enableNetwork: streamFlags.enableNetwork,
|
|
134
|
+
enableKnowledgeBase: streamFlags.enableKnowledgeBase,
|
|
135
|
+
enableDataAnalysis: streamFlags.enableDataAnalysis,
|
|
136
|
+
},
|
|
137
|
+
{ signal: controller.signal },
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
await readLogMessageSseStream(response, {
|
|
141
|
+
thisStreamGen: thisGen,
|
|
142
|
+
streamGenerationRef: streamGenRef,
|
|
143
|
+
setStreamingContent,
|
|
144
|
+
setIsStreaming,
|
|
145
|
+
streamingContentRef: streamingRef,
|
|
146
|
+
syncLastUserMessageTurnId: (turnKey: string) => {
|
|
147
|
+
setMessages((prev) => {
|
|
148
|
+
for (let i = prev.length - 1; i >= 0; i--) {
|
|
149
|
+
if (prev[i].role === 'user') {
|
|
150
|
+
const u = prev[i]
|
|
151
|
+
const next = [...prev]
|
|
152
|
+
next[i] = {
|
|
153
|
+
...u,
|
|
154
|
+
id: `${turnKey}-10`,
|
|
155
|
+
turn_id: turnKey,
|
|
156
|
+
}
|
|
157
|
+
return next
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return prev
|
|
161
|
+
})
|
|
162
|
+
},
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
if (thisGen === streamGenRef.current && streamingRef.current) {
|
|
166
|
+
const raw = markMessagePreparationDone({
|
|
167
|
+
...streamingRef.current,
|
|
168
|
+
is_streaming: false,
|
|
169
|
+
})
|
|
170
|
+
const hasAnswer =
|
|
171
|
+
typeof raw.content === 'string' && raw.content.trim().length > 0
|
|
172
|
+
const finalMsg = hasAnswer
|
|
173
|
+
? omitMessagePreparationForPersist(raw)
|
|
174
|
+
: raw
|
|
175
|
+
setMessages((prev) => {
|
|
176
|
+
const exists = prev.some((m) => m.id === finalMsg.id)
|
|
177
|
+
if (!exists) return [...prev, finalMsg]
|
|
178
|
+
return prev.map((m) => (m.id === finalMsg.id ? finalMsg : m))
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
} catch (err: any) {
|
|
182
|
+
if (thisGen !== streamGenRef.current) return
|
|
183
|
+
if (err?.name === 'AbortError') return
|
|
184
|
+
if (err?.message === CHAT_STREAM_HANDLED_JSON_ERROR) return
|
|
185
|
+
showToast(t('chat.send_failed'), 'error') // 发送消息失败
|
|
186
|
+
} finally {
|
|
187
|
+
if (thisGen === streamGenRef.current) {
|
|
188
|
+
setIsStreaming(false)
|
|
189
|
+
setStreamingContent(null)
|
|
190
|
+
streamingRef.current = null
|
|
191
|
+
if (abortRef.current) {
|
|
192
|
+
abortRef.current = null
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
setBooting(false)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** 关闭消息弹窗并重置展示状态。 */
|
|
200
|
+
const close = () => {
|
|
201
|
+
abortStream()
|
|
202
|
+
setOpen(false)
|
|
203
|
+
setMessages([])
|
|
204
|
+
setBooting(false)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
useImperativeHandle(ref, () => ({
|
|
208
|
+
/** 打开新弹窗并自动发送固定消息。 */
|
|
209
|
+
open: () => {
|
|
210
|
+
setModalKey((k) => k + 1)
|
|
211
|
+
setOpen(true)
|
|
212
|
+
void startFreshChat()
|
|
213
|
+
},
|
|
214
|
+
close,
|
|
215
|
+
}))
|
|
216
|
+
|
|
217
|
+
const listLoading = booting || (isStreaming && messages.length === 0)
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<CxModal
|
|
221
|
+
key={`log-message-modal-${modalKey}`}
|
|
222
|
+
title={t('system.sys_log.message.title')} // 消息
|
|
223
|
+
isOpen={open}
|
|
224
|
+
onClose={close}
|
|
225
|
+
opeType="detail"
|
|
226
|
+
modalConfig={{ width: 'min(920px, 92vw)' }}
|
|
227
|
+
>
|
|
228
|
+
<div className="flex h-[min(70vh,640px)] min-h-[360px] flex-col overflow-hidden rounded-lg bg-white dark:bg-[#131314]">
|
|
229
|
+
<MessageList
|
|
230
|
+
key={modalKey}
|
|
231
|
+
messages={displayMessages}
|
|
232
|
+
isLoading={listLoading}
|
|
233
|
+
/>
|
|
234
|
+
</div>
|
|
235
|
+
</CxModal>
|
|
236
|
+
)
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
export default MessageModal
|