Skip to content

Commit

Permalink
Typing batchRenderAgentMessage() and batchRenderContentFragment() (#4203
Browse files Browse the repository at this point in the history
)

* Typing batchRenderAgentMessage()

* Adding typing for batchRenderContentFragment
  • Loading branch information
lasryaric authored Mar 7, 2024
1 parent f2cff65 commit 71db9ae
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions front/lib/api/assistant/conversation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type {
AgentActionType,
AgentMessageNewEvent,
ConversationTitleEvent,
DustAppParameters,
DustAppRunActionType,
GenerationTokensEvent,
TablesQueryActionType,
UserMessageErrorEvent,
UserMessageNewEvent,
WorkspaceType,
Expand Down Expand Up @@ -278,7 +281,7 @@ export async function batchRenderUserMessages(
async function batchRenderAgentMessages(
auth: Authenticator,
messages: Message[]
) {
): Promise<{ m: AgentMessageType; rank: number; version: number }[]> {
const agentMessages = messages.filter((m) => !!m.agentMessage);

const [
Expand Down Expand Up @@ -336,7 +339,7 @@ async function batchRenderAgentMessages(
params: action.params,
runningBlock: null,
output: action.output,
};
} satisfies DustAppRunActionType;
});
})(),
(async () => {
Expand All @@ -355,7 +358,7 @@ async function batchRenderAgentMessages(
type: "tables_query_action",
params: action.params as DustAppParameters,
output: action.output as Record<string, string | number | boolean>,
};
} satisfies TablesQueryActionType;
});
})(),
]);
Expand All @@ -368,23 +371,31 @@ async function batchRenderAgentMessages(
}
const agentMessage = message.agentMessage;

let action = null;
let action: AgentActionType | null = null;
if (agentMessage.agentRetrievalActionId) {
action = agentRetrievalActions.find(
(a) => a.id === agentMessage.agentRetrievalActionId
);
action =
agentRetrievalActions.find(
(a) => a.id === agentMessage.agentRetrievalActionId
) || null;
} else if (agentMessage.agentDustAppRunActionId) {
action = agentDustAppRunActions.find(
(a) => a.id === agentMessage.agentDustAppRunActionId
);
action =
agentDustAppRunActions.find(
(a) => a.id === agentMessage.agentDustAppRunActionId
) || null;
} else if (agentMessage.agentTablesQueryActionId) {
action = agentTablesQueryActions.find(
(a) => a.id === agentMessage.agentTablesQueryActionId
);
action =
agentTablesQueryActions.find(
(a) => a.id === agentMessage.agentTablesQueryActionId
) || null;
}
const agentConfiguration = agentConfigurations.find(
(a) => a.sId === message.agentMessage?.agentConfigurationId
);
if (!agentConfiguration) {
throw new Error(
"Unreachable: agent configuration must be found for agent message"
);
}

let error: {
code: string;
Expand Down Expand Up @@ -412,7 +423,7 @@ async function batchRenderAgentMessages(
content: agentMessage.content,
error,
configuration: agentConfiguration,
};
} satisfies AgentMessageType;
return { m, rank: message.rank, version: message.version };
});
}
Expand Down Expand Up @@ -444,7 +455,9 @@ function renderContentFragment({
};
}

async function batchRenderContentFragment(messages: Message[]) {
async function batchRenderContentFragment(
messages: Message[]
): Promise<{ m: ContentFragmentType; rank: number; version: number }[]> {
const messagesWithContentFragment = messages.filter(
(m) => !!m.contentFragment
);
Expand Down

0 comments on commit 71db9ae

Please sign in to comment.