From b54e8af0e4ecbbddbd8e9c1bace4c06d0ec8e4d7 Mon Sep 17 00:00:00 2001 From: gaobinlong Date: Tue, 5 Dec 2023 18:00:49 +0800 Subject: [PATCH] Use update_time returned by backend API to set the attribute updatedTimeMs of session (#40) Signed-off-by: gaobinlong --- .../agent_framework_storage_service.ts | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/server/services/storage/agent_framework_storage_service.ts b/server/services/storage/agent_framework_storage_service.ts index 18aafd40..27d62043 100644 --- a/server/services/storage/agent_framework_storage_service.ts +++ b/server/services/storage/agent_framework_storage_service.ts @@ -67,10 +67,11 @@ export class AgentFrameworkStorageService implements StorageService { }; } - // TODO: return real update_time in the response once the agent framework supports update_time field async getSessions(query: GetSessionsSchema): Promise { let sortField = ''; if (query.sortField === 'updatedTimeMs') { + sortField = 'updated_time'; + } else if (query.sortField === 'createTimeMs') { sortField = 'create_time'; } let searchFields: string[] = []; @@ -111,18 +112,23 @@ export class AgentFrameworkStorageService implements StorageService { objects: sessions.body.hits.hits .filter( (hit: { - _source: { name: string; create_time: string }; + _source: { name: string; create_time: string; updated_time: string }; }): hit is RequiredKey => hit._source !== null && hit._source !== undefined ) - .map((item: { _id: string; _source: { name: string; create_time: string } }) => ({ - id: item._id, - title: item._source.name, - version: 1, - createdTimeMs: Date.parse(item._source.create_time), - updatedTimeMs: Date.parse(item._source.create_time), - messages: [] as IMessage[], - })), + .map( + (item: { + _id: string; + _source: { name: string; create_time: string; updated_time: string }; + }) => ({ + id: item._id, + title: item._source.name, + version: 1, + createdTimeMs: Date.parse(item._source.create_time), + updatedTimeMs: Date.parse(item._source.updated_time), + messages: [] as IMessage[], + }) + ), total: typeof sessions.body.hits.total === 'number' ? sessions.body.hits.total