使用示例
// 获取历史记录
async getChatRecords() {
const agent = this.getAgent();
if (!agent) return;
const response = await agent.getConversations();
console.log("=== conversations", response);
if (response.code !== 0) {
xhs.showToast({
title: "获取历史记录失败",
icon: "none",
});
return;
}
const conversations = response.data.conversations;
if (conversations && conversations.length > 0) {
const res = await agent.getHistoryMessages({
conversation_id: conversations[0].id,
cursor: 1,
count: 10,
sort: "desc",
});
console.log("=== getHistoryMessages", res);
}
},
const agentInfo = await agent.getHistoryMessages({
conversation_id: conversations[0].id,
cursor: 1,
count: 10,
sort: "desc"
});
属性名 | 类型 | 字段描述及类型 | 最低支持版本 |
|---|---|---|---|
| conversation_id | string | 会话 id | x.x.x |
| cursor | string | 请求的游标 | x.x.x |
| count | number | 分页大小 | x.x.x |
| sort | string | 历史记录排序 | x.x.x |
export interface UserRecord {
content: string;
role: 'user';
}
export interface AssistantRecord {
content: string;
role: 'assistant';
reasoningContent: string;
type: MessageType;
}
export type CreateRecordPairResponse = BaseResponse;
export interface ParticipantInfo {
id: string;
name: string;
desc: string;
avatar_url: string;
}
export interface GetHistoryMessagesData {
message_list: (UserRecord | AssistantRecord)[];
conversation_id: string;
participant_info_map: Record<string, ParticipantInfo>;
next_cursor: number;
has_more: boolean;
}