diff --git a/package.json b/package.json index bce3485c4a..6c0a86d2da 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "test:coverage": "vitest run --coverage", "prebuild": "rimraf packages/tdesign-react/es/* packages/tdesign-react/lib/* packages/tdesign-react/dist/* packages/tdesign-react/esm/* packages/tdesign-react/cjs/*", "build": "cross-env NODE_ENV=production rollup -c script/rollup.config.js && node script/utils/bundle-override.js && pnpm run build:tsc", + "prebuild:aigc": "rimraf packages/tdesign-react-aigc/es", "build:aigc": "cross-env NODE_ENV=production rollup -c script/rollup.aigc.config.js && tsc -p ./tsconfig.aigc.build.json --outDir packages/tdesign-react-aigc/es/", "build:tsc": "run-p build:tsc-*", "build:tsc-es": "tsc -p ./tsconfig.build.json --outDir packages/tdesign-react/es/", diff --git a/packages/ai-core b/packages/ai-core index 7e277aa55c..6de96a8cec 160000 --- a/packages/ai-core +++ b/packages/ai-core @@ -1 +1 @@ -Subproject commit 7e277aa55cfbfffd481f0149eb2e30edc8b4d8ee +Subproject commit 6de96a8cec654ca554d8d13ac0842d697f2470e8 diff --git a/packages/pro-components/chat/_util/reactify.tsx b/packages/pro-components/chat/_util/reactify.tsx index cf1f82f9e0..67c30aaa08 100644 --- a/packages/pro-components/chat/_util/reactify.tsx +++ b/packages/pro-components/chat/_util/reactify.tsx @@ -440,8 +440,18 @@ const reactify = ( render() { const { children, className, ...rest } = this.props; - - return createElement(WC, { class: className, ...rest, ref: this.ref }, children); + // 仅将基本类型作为 attribute 传递,其余复杂类型(object/function/ReactNode) + // 在 update() 中按需处理为 property / slot / event,避免 React 19 把非基本类型 + // 通过 JSX 写成异常 attribute,进而干扰 omi 组件的 defaultProps 合并流程 + // (典型症状:t-chat-list 的 autoScroll / defaultScrollTo 默认值失效导致自动滚动失效) + const filteredProps: Record = {}; + Object.keys(rest).forEach((key) => { + const val = (rest as Record)[key]; + if (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean') { + filteredProps[key] = val; + } + }); + return createElement(WC, { class: className, ...filteredProps, ref: this.ref }, children); } } diff --git a/packages/pro-components/chat/chat-engine/hooks/useAgentState.ts b/packages/pro-components/chat/chat-engine/hooks/useAgentState.ts index 6682ad36f8..77470872e9 100644 --- a/packages/pro-components/chat/chat-engine/hooks/useAgentState.ts +++ b/packages/pro-components/chat/chat-engine/hooks/useAgentState.ts @@ -2,6 +2,8 @@ import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react'; import { stateManager } from '@tdesign/ai-chat-engine'; +import type { ChatJSONObject } from '@tdesign/ai-chat-engine'; + /** * 状态订阅相关类型定义 */ @@ -41,7 +43,7 @@ export interface UseStateActionReturn { getStateByKey: (key: string) => any; } -export const useAgentState = (options: StateActionOptions = {}): UseStateActionReturn => { +export const useAgentState = (options: StateActionOptions = {}): UseStateActionReturn => { const { initialState, subscribeKey } = options; const [stateMap, setStateMap] = useState>(initialState || {}); const [currentStateKey, setCurrentStateKey] = useState(null); @@ -52,7 +54,7 @@ export const useAgentState = (options: StateActionOptions = {}): UseSta useEffect( () => - stateManager.subscribeToLatest((newState: T, newStateKey: string) => { + stateManager.subscribeToLatest((newState: ChatJSONObject, newStateKey: string) => { // 如果指定了 subscribeKey,只有匹配时才更新状态 if (subscribeKey && newStateKey !== subscribeKey) { // 仍然更新内部状态,但不触发重新渲染 diff --git a/packages/pro-components/chat/chat-message/index.ts b/packages/pro-components/chat/chat-message/index.ts index 2dd39dbac1..fc28558dd5 100644 --- a/packages/pro-components/chat/chat-message/index.ts +++ b/packages/pro-components/chat/chat-message/index.ts @@ -2,12 +2,24 @@ import 'tdesign-web-components/lib/chat-message'; import reactify from '../_util/reactify'; -import type { TdChatMessageProps } from 'tdesign-web-components'; +import type { ChatMessagesData } from '@tdesign/ai-chat-engine'; +import type { TdChatMessageProps as WCTdChatMessageProps } from 'tdesign-web-components'; + +/** + * TdChatMessageProps 的 `message` 字段来源修正: + * - `tdesign-web-components` 里的 `ChatMessagesData` 与 `@tdesign/ai-chat-engine` + * 里的 `ChatMessagesData` 暂时是同构但不同源的两份类型(前者是历史内部定义, + * 后者是新架构的规范来源),下游 `useChat` 返回的 messages 走的是 chat-engine, + * 桥接组件如果直接用 web-components 的类型会导致 TS 无法互赋值。 + * - 这里用 `Omit + &` 覆盖 `message` 字段的类型来源,运行时不变;组件底层是 + * web component,只关心属性值,不感知 TS 类型。 + */ +export type TdChatMessageProps = Omit & { + message?: ChatMessagesData; +}; export const ChatMessage: React.ForwardRefExoticComponent< Omit & React.RefAttributes > = reactify('t-chat-item', 'ChatMessage'); export default ChatMessage; - -export type { TdChatMessageProps } from 'tdesign-web-components'; diff --git a/packages/tdesign-react-aigc/package.json b/packages/tdesign-react-aigc/package.json index 801cf7af80..7a9616e713 100644 --- a/packages/tdesign-react-aigc/package.json +++ b/packages/tdesign-react-aigc/package.json @@ -55,6 +55,7 @@ }, "dependencies": { "@babel/runtime": "~7.26.7", + "@tdesign/ai-chat-engine": "^0.0.2", "classnames": "~2.5.1", "lodash-es": "^4.17.21", "react-fast-compare": "^3.2.2", diff --git a/script/rollup.aigc.config.js b/script/rollup.aigc.config.js index 609144cdae..15e25254ca 100644 --- a/script/rollup.aigc.config.js +++ b/script/rollup.aigc.config.js @@ -1,16 +1,17 @@ -import url from '@rollup/plugin-url'; -import json from '@rollup/plugin-json'; -import babel from '@rollup/plugin-babel'; -import styles from 'rollup-plugin-styles'; +import { resolve } from 'path'; + +import analyzer from 'rollup-plugin-analyzer'; import esbuild from 'rollup-plugin-esbuild'; -import replace from '@rollup/plugin-replace'; +import multiInput from 'rollup-plugin-multi-input'; +import styles from 'rollup-plugin-styles'; import { terser } from 'rollup-plugin-terser'; -import commonjs from '@rollup/plugin-commonjs'; import { DEFAULT_EXTENSIONS } from '@babel/core'; -import multiInput from 'rollup-plugin-multi-input'; +import babel from '@rollup/plugin-babel'; +import commonjs from '@rollup/plugin-commonjs'; +import json from '@rollup/plugin-json'; import nodeResolve from '@rollup/plugin-node-resolve'; -import analyzer from 'rollup-plugin-analyzer'; -import { resolve } from 'path'; +import replace from '@rollup/plugin-replace'; +import url from '@rollup/plugin-url'; import pkg from '../packages/tdesign-react-aigc/package.json';