Skip to content

Commit d460343

Browse files
authored
fix: wf step test (keephq#3593)
1 parent 667cc7c commit d460343

File tree

4 files changed

+81
-12
lines changed

4 files changed

+81
-12
lines changed

keep-ui/features/workflows/builder/ui/BuilderChat/builder-chat.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,5 @@ export function BuilderChatSafe({
562562
return null;
563563
}
564564

565-
return (
566-
<CopilotKit runtimeUrl="/api/copilotkit">
567-
<BuilderChat definition={definition} {...props} />
568-
</CopilotKit>
569-
);
565+
return <BuilderChat definition={definition} {...props} />;
570566
}

keep-ui/features/workflows/builder/ui/Editor/StepEditor.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,11 @@ export function StepEditorV2({
560560
const { data: { providers, installed_providers: installedProviders } = {} } =
561561
useProviders();
562562

563+
const installedProvider = installedProviders?.find(
564+
(p) => p.type === providerType && p.details?.name === providerConfig
565+
);
566+
const providerId = installedProvider?.id;
567+
563568
const providerNameError = validateProviderConfig(
564569
providerType,
565570
providerConfig ?? "",
@@ -720,7 +725,7 @@ export function StepEditorV2({
720725
<TabPanel className="flex-1">
721726
<TestRunStepForm
722727
providerInfo={{
723-
provider_id: providerConfig ?? "",
728+
provider_id: providerId || providerConfig || "",
724729
provider_type: providerType ?? "",
725730
}}
726731
method={method}

keep-ui/features/workflows/builder/ui/Editor/StepTest.tsx

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { Callout, Text } from "@tremor/react";
55
import { useMemo, useState } from "react";
66
import { EditorLayout } from "./StepEditor";
77
import { Editor } from "@monaco-editor/react";
8+
import { SparklesIcon } from "@heroicons/react/24/outline";
9+
import { useCopilotChat } from "@copilotkit/react-core";
10+
import { Role } from "@copilotkit/runtime-client-gql";
11+
import { TextMessage } from "@copilotkit/runtime-client-gql";
812

913
export function useTestStep() {
1014
const api = useApi();
@@ -28,6 +32,50 @@ export function useTestStep() {
2832
return testStep;
2933
}
3034

35+
const WFDebugWithAI = ({
36+
errors,
37+
description,
38+
}: {
39+
errors: { [key: string]: string };
40+
description: string;
41+
}) => {
42+
const { appendMessage } = useCopilotChat();
43+
return (
44+
<Button
45+
variant="secondary"
46+
color="orange"
47+
size="xs"
48+
icon={SparklesIcon}
49+
onClick={() => {
50+
appendMessage(
51+
new TextMessage({
52+
content: `Help me debug this error ${description}: ${JSON.stringify(
53+
errors
54+
)}. If you propose a fix, make it concise and to the point.`,
55+
role: Role.User,
56+
})
57+
);
58+
}}
59+
>
60+
Debug with AI
61+
</Button>
62+
);
63+
};
64+
65+
const WFDebugWithAIButton = ({
66+
errors,
67+
description,
68+
}: {
69+
errors: { [key: string]: string };
70+
description: string;
71+
}) => {
72+
try {
73+
return <WFDebugWithAI errors={errors} description={description} />;
74+
} catch (e) {
75+
return null;
76+
}
77+
};
78+
3179
const variablesRegex = /{{[\s]*.*?[\s]*}}/g;
3280

3381
export function TestRunStepForm({
@@ -218,18 +266,26 @@ export function TestRunStepForm({
218266
{errors &&
219267
Object.values(errors).length > 0 &&
220268
Object.entries(errors).map(([key, error]) => (
221-
<Callout
269+
<div
222270
key={key}
223-
title={key}
224-
color="red"
271+
className="flex flex-col gap-2 items-end"
225272
ref={(el) => {
226273
if (el) {
227274
el.scrollIntoView({ behavior: "smooth", block: "start" });
228275
}
229276
}}
230277
>
231-
{error}
232-
</Callout>
278+
<Callout title={key} color="red">
279+
{error}
280+
<div className="mt-2"></div>
281+
</Callout>
282+
<WFDebugWithAIButton
283+
errors={errors}
284+
description={`in step test run ${providerInfo.provider_type}, with parameters ${JSON.stringify(
285+
resultingParameters
286+
)}`}
287+
/>
288+
</div>
233289
))}
234290
</EditorLayout>
235291
<div className="sticky flex justify-end bottom-0 px-4 py-2.5 bg-white border-t border-gray-200">

keep-ui/widgets/workflow-builder/builder.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { BuilderChatSafe } from "@/features/workflows/builder/ui/BuilderChat/bui
2424
import clsx from "clsx";
2525
import { ResizableColumns } from "@/shared/ui";
2626
import { useConfig } from "@/utils/hooks/useConfig";
27+
import { CopilotKit } from "@copilotkit/react-core";
2728

2829
interface Props {
2930
loadedAlertFile: string | null;
@@ -309,4 +310,15 @@ function Builder({
309310
);
310311
}
311312

312-
export default Builder;
313+
export default function BuilderWrapper(props: Props) {
314+
const { data: configData } = useConfig();
315+
const isAIEnabled = configData?.OPEN_AI_API_KEY_SET;
316+
if (!isAIEnabled) {
317+
return <Builder {...props} />;
318+
}
319+
return (
320+
<CopilotKit runtimeUrl="/api/copilotkit">
321+
<Builder {...props} />
322+
</CopilotKit>
323+
);
324+
}

0 commit comments

Comments
 (0)