From v1 to v2
ant-design-x-vue@2.10.0 aligns with the 2.x data flow of React @ant-design/x@2.10.0. When installing the main package, the same version of @ant-design-x-vue/x-sdk and @ant-design-x-vue/x-markdown will be brought.
pnpm add ant-design-x-vue@2.10.0import { useXChat, XRequest, XStream, useXConversations } from 'ant-design-x-vue' gets the SDK. XMarkdown is imported from @ant-design-x-vue/x-markdown.
Data flow
useXAgentis no longer the model scheduling method in 2.0. It is still exported from the main package and is only reserved for old examples. UsecreateOpenAIChatProvider({ baseURL, model, dangerouslyApiKey })for new code, or usenew OpenAIChatProvider({ request })yourself.useXChatacceptsproviderinstead. When there is no provider,onRequest/abortwill throwprovider is required. Return values includeonRequest,messages,parsedMessages,setMessages,setMessage,removeMessage,abort,isRequesting,isDefaultMessagesRequesting,onReload,queueRequest.isRequesting/isDefaultMessagesRequestingare reactive (computed / ref).- Use
XRequest(baseURL, options)to create a request instance, which must bemanual: truewhen passing it to Provider. 1.x'sXRequest({ baseURL, model, dangerouslyApiKey })was renamed toXRequestLegacy. useXChat({ agent })in 1.x is renamed touseLegacyXChat. Old documentation examples have been renamed to avoid collision with 2.0 hooks.useXConversationsmanages the conversation list. It anduseXChatshare messages via session key.- The calling form of
XStream({ readableStream })is the same as 1.x, and the implementation is changed to SDK.
<script setup lang="ts">
import {
OpenAIChatProvider,
useXChat,
useXConversations,
XRequest,
} from 'ant-design-x-vue';
const { activeConversationKey } = useXConversations({
defaultConversations: [{ key: '1', label: '新对话' }],
defaultActiveConversationKey: '1',
});
const provider = new OpenAIChatProvider({
request: XRequest('https://api.example.com/v1/chat/completions', {
manual: true,
headers: { Authorization: 'Bearer YOUR_KEY' },
}),
});
const { messages, onRequest, abort, isRequesting } = useXChat({
provider,
conversationKey: activeConversationKey,
});
</script>The built-in Provider also includes DeepSeekChatProvider and DefaultChatProvider. When customizing the protocol, inherit AbstractChatProvider and implement transformParams, transformLocalMessage, and transformMessage.
For a more complete field description, see SDK Data Flow.
Publish order
The main package, SDK, and Markdown are all version 2.10.0:
- Publish
@ant-design-x-vue/x-sdkfirst. It has no runtime dependencies. - Re-release
ant-design-x-vueand@ant-design-x-vue/x-markdown. The main package depends on2.10.0of the latter two, and Markdown depends on2.10.0of the main package. @ant-design-x-vue/x-cardand@ant-design-x-vue/x-skillare outside this dependency chain and can be published independently in the same batch.
npm publish itself does not check whether the dependency is already on the registry. Before the user executes pnpm add ant-design-x-vue@2.10.0, the main package, SDK, and Markdown must all have been published. The dependency version in the release package is 2.10.0, and workspace:* cannot be left.
Intentional differences from React 2.10
These are Vue adaptations, not leaky implementations:
- Root class name is Vue’s
class. If the component declaresclassNamein addition (such as XMarkdown, Actions), both can be used. - The stable identifier of
FileCard.Listis placed on thekeyof the list item, notFileCard’s own props. Vue leaveskeyto list rendering. Bubble.Listaccepts bothrolesandrole. Useroleswhen passing from both sides. The implementation of React 2.10 only hasrole.
Components
- Bubble:
messageRenderchanged tocontentRender.messageRenderremains a deprecated entry.Bubble.Listrequires an explicit height when scrolling the hosted list. - Sender: Use
suffixin the operation area. Set tofalsewhen the default button is not required. WhatonPasteFilereceives isFileList. - Use separate
FileCardfor file cards. The number of bytes in the file isbyte, and the card sizesizeis'small' | 'default'. - ThoughtChain’s
itemsno longer usesextra.
Legacy pages
useXAgent, useXChat, XRequest These three pages are in 1.x documentation site. New code is written according to SDK data flow.