From 10d62aacfcc7b3fcccb1ef99edc3ca1eb583053e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daphn=C3=A9=20Popin?= Date: Tue, 28 Nov 2023 13:14:17 +0100 Subject: [PATCH] Global agents are loaded from getAgetnConfiguration --- front/lib/api/assistant/conversation.ts | 122 +++++++++++------------- 1 file changed, 56 insertions(+), 66 deletions(-) diff --git a/front/lib/api/assistant/conversation.ts b/front/lib/api/assistant/conversation.ts index 9ae519044ad02..6d5afbcb69046 100644 --- a/front/lib/api/assistant/conversation.ts +++ b/front/lib/api/assistant/conversation.ts @@ -288,73 +288,63 @@ async function batchRenderAgentMessages( ); } - const [ - localAgentConfigurations, - globalAgentConfigurations, - agentRetrievalActions, - agentDustAppRunActions, - ] = await Promise.all([ - (async () => { - const agentConfigurationIds: string[] = messages.reduce( - (acc: string[], m) => { - const agentId = m.agentMessage?.agentConfigurationId; - if (agentId && !acc.includes(agentId)) { - acc.push(agentId); - } - return acc; - }, - [] - ); - const agents = ( - await Promise.all( - agentConfigurationIds.map((agentConfigId) => { - return getAgentConfiguration(auth, agentConfigId); - }) - ) - ).filter((a) => a !== null) as AgentConfigurationType[]; - return agents; - })(), - getGlobalAgents(auth), - (async () => { - return await Promise.all( - messages - .filter((m) => m.agentMessage?.agentRetrievalActionId) - .map((m) => { - return renderRetrievalActionByModelId( - m.agentMessage?.agentRetrievalActionId as number - ); - }) - ); - })(), - (async () => { - const actions = await AgentDustAppRunAction.findAll({ - where: { - id: { - [Op.in]: messages - .filter((m) => m.agentMessage?.agentDustAppRunActionId) - .map((m) => m.agentMessage?.agentDustAppRunActionId as number), + const [agentConfigurations, agentRetrievalActions, agentDustAppRunActions] = + await Promise.all([ + (async () => { + const agentConfigurationIds: string[] = messages.reduce( + (acc: string[], m) => { + const agentId = m.agentMessage?.agentConfigurationId; + if (agentId && !acc.includes(agentId)) { + acc.push(agentId); + } + return acc; }, - }, - }); - return actions.map((action) => { - return { - id: action.id, - type: "dust_app_run_action", - appWorkspaceId: action.appWorkspaceId, - appId: action.appId, - appName: action.appName, - params: action.params, - runningBlock: null, - output: action.output, - }; - }); - })(), - ]); - - const agentConfigurations = [ - ...localAgentConfigurations, - ...globalAgentConfigurations, - ]; + [] + ); + const agents = ( + await Promise.all( + agentConfigurationIds.map((agentConfigId) => { + return getAgentConfiguration(auth, agentConfigId); + }) + ) + ).filter((a) => a !== null) as AgentConfigurationType[]; + return agents; + })(), + (async () => { + return await Promise.all( + messages + .filter((m) => m.agentMessage?.agentRetrievalActionId) + .map((m) => { + return renderRetrievalActionByModelId( + m.agentMessage?.agentRetrievalActionId as number + ); + }) + ); + })(), + (async () => { + const actions = await AgentDustAppRunAction.findAll({ + where: { + id: { + [Op.in]: messages + .filter((m) => m.agentMessage?.agentDustAppRunActionId) + .map((m) => m.agentMessage?.agentDustAppRunActionId as number), + }, + }, + }); + return actions.map((action) => { + return { + id: action.id, + type: "dust_app_run_action", + appWorkspaceId: action.appWorkspaceId, + appId: action.appId, + appName: action.appName, + params: action.params, + runningBlock: null, + output: action.output, + }; + }); + })(), + ]); return messages.map((message) => { if (!message.agentMessage) {