Skip to content

Commit 8fe7e2d

Browse files
authored
Merge pull request #289 from ClayPulse/dev
Enhance AgentChat and DiagramBlock with theme-aware features and onboarding
2 parents 659c492 + 5b69a64 commit 8fe7e2d

21 files changed

Lines changed: 2263 additions & 243 deletions

package-lock.json

Lines changed: 155 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/app/(main-layout)/globals.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@ body {
148148
input {
149149
@apply text-default-foreground;
150150
}
151-
}
151+
}

web/components/agent-chat/agent-chat.tsx

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
parseBlockFromToolMessage,
66
} from "@/components/agent-chat/chat-blocks/utils";
77
import HomeScreen from "@/components/agent-chat/chat-screens/home-screen";
8-
import ProjectScreen from "@/components/agent-chat/chat-screens/project-screen";
98
import { type ChatUpload } from "@/components/agent-chat/input/chat-input-bar";
109
import QuickPillButtons from "@/components/agent-chat/input/quick-pill-buttons";
1110
import { AgentChatLayout } from "@/components/agent-chat/layouts/agent-chat-layouts";
@@ -23,7 +22,7 @@ import type {
2322
import { fetchWorkflowRunStatus } from "@/lib/workflow/fetch-workflow-run-status";
2423
import { AIMessage } from "@langchain/core/messages";
2524
import { ViewModeEnum } from "@pulse-editor/shared-utils";
26-
import { useContext, useEffect, useMemo, useRef, useState } from "react";
25+
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
2726
import { AgentChatPanelLayout } from "./layouts/agent-chat-panel-layout";
2827
import RunningTasksPanel from "./panels/running-tasks-panel";
2928

@@ -83,7 +82,9 @@ export default function AgentChat({
8382
workflowBuilds,
8483
saveWorkflowBuild,
8584
activeInterrupt,
85+
activeQAForm,
8686
resume,
87+
resumeQAForm,
8788
} = useChatContext();
8889

8990
const { allowed: agentChatAllowed, isLoading: isLoadingAccess } =
@@ -611,10 +612,31 @@ export default function AgentChat({
611612
const isEmptyConversation =
612613
messages.length === 0 && !isLoading && !isLoadingSession;
613614

614-
const emptyState = activeProject ? (
615-
<ProjectScreen onSend={handleSend} project={activeProject} />
616-
) : (
617-
<HomeScreen onSend={handleSend} projects={projects ?? []} />
615+
const [isOnboardingAnalyzing, setIsOnboardingAnalyzing] = useState(false);
616+
617+
const handleOnboardingComplete = useCallback(
618+
(analysis: import("@/lib/types").ProjectAnalysisInfo) => {
619+
setIsOnboardingAnalyzing(false);
620+
editorContext?.setEditorStates((prev) => ({
621+
...prev,
622+
projectsInfo: prev.projectsInfo?.map((p) =>
623+
p.id === activeProject?.id
624+
? { ...p, projectAnalysis: analysis }
625+
: p,
626+
),
627+
}));
628+
},
629+
[editorContext, activeProject?.id],
630+
);
631+
632+
const emptyState = (
633+
<HomeScreen
634+
onSend={handleSend}
635+
projects={projects ?? []}
636+
activeProject={activeProject}
637+
onOnboardingComplete={handleOnboardingComplete}
638+
onAnalyzingChange={setIsOnboardingAnalyzing}
639+
/>
618640
);
619641

620642
// Build a map of tool_call_id -> tool name from AIMessages
@@ -675,6 +697,7 @@ export default function AgentChat({
675697
const inlinedTaskIds = new Set<string>();
676698

677699
const messageList: ChatBlockData[] = [];
700+
const messageSourceMap = new Map<number, typeof messages[number]>();
678701
for (let i = 0; i < messages.length; i++) {
679702
const msg = messages[i];
680703
const isHuman = msg._getType() === "human";
@@ -790,7 +813,49 @@ export default function AgentChat({
790813
isTerminatingTask: workflowTask
791814
? terminatingTaskIds?.has(workflowTask.taskId)
792815
: undefined,
816+
chosenSuggestion: msg.additional_kwargs?.chosenSuggestion as
817+
| string
818+
| undefined,
793819
});
820+
messageSourceMap.set(messageList.length - 1, msg);
821+
}
822+
}
823+
824+
// Append active interrupt / QA form blocks so they render at the bottom
825+
if (activeInterrupt) {
826+
messageList.push({
827+
type: "interrupt",
828+
interrupt: activeInterrupt,
829+
onReply: resume,
830+
isLoading,
831+
});
832+
}
833+
if (activeQAForm) {
834+
messageList.push({
835+
type: "qa-form",
836+
form: activeQAForm,
837+
onSubmit: resumeQAForm,
838+
isLoading,
839+
});
840+
}
841+
842+
// Attach suggestion click handler to the last AI message only
843+
if (!isLoading && !activeInterrupt && !activeQAForm) {
844+
for (let i = messageList.length - 1; i >= 0; i--) {
845+
if (messageList[i].type === "ai-message") {
846+
const sourceMsg = messageSourceMap.get(i);
847+
(messageList[i] as any).onSuggestionClick = (text: string) => {
848+
// Persist chosen suggestion into the AI message's additional_kwargs
849+
if (sourceMsg) {
850+
sourceMsg.additional_kwargs = {
851+
...sourceMsg.additional_kwargs,
852+
chosenSuggestion: text,
853+
};
854+
}
855+
handleSend(text);
856+
};
857+
break;
858+
}
794859
}
795860
}
796861

@@ -870,6 +935,7 @@ export default function AgentChat({
870935
onOpenTasks: () => setIsTasksOpen(true),
871936
onNewChat: handleNewChat,
872937
onShare: () => setShareSessionId(currentSessionIdRef.current),
938+
hideInput: isEmptyConversation && isOnboardingAnalyzing,
873939
};
874940

875941
if (isPage) {

0 commit comments

Comments
 (0)