该方法无需传入参数,直接调用即可获取会话列表。
属性名 | 类型 | 说明 | 最低支持版本 |
|---|---|---|---|
| conversations | Conversation | 会话列表 | x.x.x |
属性名 | 类型 | 说明 | 最低支持版本 |
|---|---|---|---|
| id | string | 会话 id | x.x.x |
| createAt | string | 会话创建时间 | x.x.x |
export interface Conversation {
id: string;
createAt: string;
}
export interface GetConversationsData {
conversations: Conversation[];
}
const agent = this.getAgent();
if (!agent) return;
const conversations = await agent.getConversations();
console.log("会话列表:", conversations);
console.log("会话数量:", conversations.conversations.length);
const agent = this.getAgent();
if (!agent) return;
const conversations = await agent.getConversations();
// 遍历所有会话
conversations.conversations.forEach((conversation, index) => {
console.log(`会话 ${index + 1}:`);
console.log(` ID: ${conversation.id}`);
console.log(` 创建时间: ${conversation.createAt}`);
});
const agent = this.getAgent();
if (!agent) return;
const conversations = await agent.getConversations();
// 按创建时间排序(最新的在前)
const sortedConversations = conversations.conversations.sort((a, b) =>
new Date(b.createAt).getTime() - new Date(a.createAt).getTime()
);
console.log("按时间排序的会话列表:", sortedConversations);
⚠️ 重要提醒: