Skip to content

Commit

Permalink
Global agents are loaded from getAgetnConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph committed Nov 28, 2023
1 parent 573027d commit 10d62aa
Showing 1 changed file with 56 additions and 66 deletions.
122 changes: 56 additions & 66 deletions front/lib/api/assistant/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 10d62aa

Please sign in to comment.