Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing batchRenderAgentMessage() and batchRenderContentFragment() #4203

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -275,7 +278,7 @@ export async function batchRenderUserMessages(messages: Message[]) {
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 @@ -333,7 +336,7 @@ async function batchRenderAgentMessages(
params: action.params,
runningBlock: null,
output: action.output,
};
} satisfies DustAppRunActionType;
});
})(),
(async () => {
Expand All @@ -352,7 +355,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 @@ -365,23 +368,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 @@ -409,7 +420,7 @@ async function batchRenderAgentMessages(
content: agentMessage.content,
error,
configuration: agentConfiguration,
};
} satisfies AgentMessageType;
return { m, rank: message.rank, version: message.version };
});
}
Expand Down Expand Up @@ -441,7 +452,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
Loading