feat: enhance debug API handler to support optional query and histories parameters

This commit is contained in:
sd0ric4
2025-03-24 16:55:21 +08:00
parent 21b5b8ae02
commit 70388f1fde

View File

@@ -18,7 +18,17 @@ async function handler(
req: NextApiRequest, req: NextApiRequest,
res: NextApiResponse res: NextApiResponse
): Promise<PostWorkflowDebugResponse> { ): Promise<PostWorkflowDebugResponse> {
const { nodes = [], edges = [], variables = {}, appId } = req.body as PostWorkflowDebugProps; const {
nodes = [],
edges = [],
variables = {},
appId,
query: requestQuery,
histories: requestHistories
} = req.body as PostWorkflowDebugProps & {
query?: UserChatItemValueItemType[];
histories?: ChatItemType[];
};
if (!nodes) { if (!nodes) {
throw new Error('Prams Error'); throw new Error('Prams Error');
@@ -29,16 +39,8 @@ async function handler(
if (!Array.isArray(edges)) { if (!Array.isArray(edges)) {
throw new Error('Edges is not array'); throw new Error('Edges is not array');
} }
const query: UserChatItemValueItemType[] = [
{
type: ChatItemValueTypeEnum.text,
text: { const query_form_input: UserChatItemValueItemType[] = requestQuery || [
content: 'Cancel'
}
}
];
const query_form_input: UserChatItemValueItemType[] = [
{ {
type: ChatItemValueTypeEnum.text, type: ChatItemValueTypeEnum.text,
text: { text: {
@@ -46,7 +48,7 @@ async function handler(
} }
} }
]; ];
const histories_form_input: ChatItemType[] = [ const histories_form_input: ChatItemType[] = requestHistories || [
{ {
dataId: 'j2ywiLkIbMivBll5fzYvkuGK', dataId: 'j2ywiLkIbMivBll5fzYvkuGK',
obj: ChatRoleEnum.Human, obj: ChatRoleEnum.Human,
@@ -171,7 +173,16 @@ async function handler(
] ]
} }
]; ];
const histories: ChatItemType[] = [ const query: UserChatItemValueItemType[] = requestQuery || [
{
type: ChatItemValueTypeEnum.text,
text: {
content: 'Cancel'
}
}
];
const histories: ChatItemType[] = requestHistories || [
{ {
dataId: 'debug-history-1', dataId: 'debug-history-1',
obj: ChatRoleEnum.Human, obj: ChatRoleEnum.Human,
@@ -318,9 +329,9 @@ async function handler(
runtimeNodes: nodes, runtimeNodes: nodes,
runtimeEdges: edges, runtimeEdges: edges,
variables, variables,
query: query_form_input, query: query,
chatConfig: defaultApp.chatConfig, chatConfig: defaultApp.chatConfig,
histories: histories_form_input, histories: histories,
stream: false, stream: false,
maxRunTimes: WORKFLOW_MAX_RUN_TIMES maxRunTimes: WORKFLOW_MAX_RUN_TIMES
}); });