XChat

Work with agent hook for data management.
Import

When To Use#

Use Agent to manage conversation data and produce data for page rendering.

Examples#

Basic usage.

      Loading...
    

Update content with stream output.

      Loading...
    
Hello, what can I do for you?

Return multiple recommended contents by customizing the ability.

      Loading...
    

Access to cloud service platform, can send messages, process data, abort stream.

      Loading...
    

API#

XChatConfig#

PropertyDescriptionTypeDefault
agentagent parameter is required when using the onRequest method in an agent generated by XAgent.XAgent-
defaultMessagesdefault messages{ status, message }[]-
parserConvert AgentMessage to ParsedMessage for consumption. If not set, AgentMessage will be consumed directly. Supports converting one AgentMessage to multiple ParsedMessages(message: AgentMessage) => BubbleMessage | BubbleMessage[]-
requestFallbackFallback when request fails, not provided will not be displayedAgentMessage | () => AgentMessage-
requestPlaceholderShow the placeholder information when requesting, not provided will not be displayedAgentMessage | () => AgentMessage-
transformMessageThe messages can be converted when updating data, and will also be updated to messages(info: {originMessage?: AgentMessage,chunk: Output,chunks: Output[],status: MessageStatus}) => AgentMessage-
transformStreamOptional transform function for processing stream dataXStreamOptions<Output>['transformStream']-
resolveAbortControllerAbortController,used to control the stream state(abortController: AbortController) => void-

XChatConfigReturnType#

PropertyDescriptionTypeDefault
messagesCurrent managed messages content{id: string | number; message: AgentMessage; status: MessageStatus;}[]-
parsedMessagesParsed messages by parser api{id: string | number; message: ParsedMessage; status: MessageStatus;}[]-
onRequestCreate a message and trigger a request, If there is no data with key as message, the entire data will be processed as a message(requestParams: AgentMessage | RequestParams) => void-
setMessagesModify messages directly without triggering requests(messages: {id: string | number; message: AgentMessage; status: MessageStatus;}[]) => void-

RequestParams#

Extends XRequestParams.

PropertyDescriptionTypeDefault
messageCurrent message contentAgentMessage-