Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

refactor(frontend/builder): extract getActionKey helper, wire textareaRef

Zamil Majdy2897550d217e
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/BuilderChatPanel.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/BuilderChatPanel.tsx
index bba7188859..ae6e293497 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/BuilderChatPanel.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/BuilderChatPanel.tsx
@@ -12,7 +12,7 @@ import {
import { KeyboardEvent, useEffect, useRef, useState } from "react";
import ReactMarkdown from "react-markdown";
import type { CustomNode } from "../FlowEditor/nodes/CustomNode/CustomNode";
-import { GraphAction, extractTextFromParts } from "./helpers";
+import { GraphAction, extractTextFromParts, getActionKey } from "./helpers";
import { useBuilderChatPanel } from "./useBuilderChatPanel";
interface Props {
@@ -38,6 +38,7 @@ export function BuilderChatPanel({ className, isGraphLoaded }: Props) {
const [inputValue, setInputValue] = useState("");
const messagesEndRef = useRef<HTMLDivElement>(null);
+ const textareaRef = useRef<HTMLTextAreaElement>(null);
const isStreaming = status === "streaming" || status === "submitted";
const canSend =
Boolean(sessionId) && !isCreatingSession && !sessionError && !isStreaming;
@@ -46,6 +47,13 @@ export function BuilderChatPanel({ className, isGraphLoaded }: Props) {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
}, [messages.length]);
+ // Move focus to the textarea when the panel opens so keyboard users can type immediately.
+ useEffect(() => {
+ if (isOpen) {
+ textareaRef.current?.focus();
+ }
+ }, [isOpen]);
+
function handleSend() {
const text = inputValue.trim();
if (!text || !canSend) return;
@@ -93,6 +101,7 @@ export function BuilderChatPanel({ className, isGraphLoaded }: Props) {
onStop={stop}
isStreaming={isStreaming}
isDisabled={!canSend}
+ textareaRef={textareaRef}
/>
</div>
)}
@@ -235,11 +244,13 @@ function MessageList({
AI applied these changes
</p>
{parsedActions.map((action) => {
- const key =
- action.type === "update_node_input"
- ? `${action.nodeId}:${action.key}`
- : `${action.source}:${action.sourceHandle}->${action.target}:${action.targetHandle}`;
- return <ActionItem key={key} action={action} nodes={nodes} />;
+ return (
+ <ActionItem
+ key={getActionKey(action)}
+ action={action}
+ nodes={nodes}
+ />
+ );
})}
</div>
)}
@@ -284,6 +295,7 @@ interface PanelInputProps {
onStop: () => void;
isStreaming: boolean;
isDisabled: boolean;
+ textareaRef?: React.RefObject<HTMLTextAreaElement>;
}
function PanelInput({
@@ -294,11 +306,13 @@ function PanelInput({
onStop,
isStreaming,
isDisabled,
+ textareaRef,
}: PanelInputProps) {
return (
<div className="border-t border-slate-100 p-3">
<div className="flex items-end gap-2">
<textarea
+ ref={textareaRef}
value={value}
disabled={isDisabled}
onChange={(e) => onChange(e.target.value)}
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/__tests__/BuilderChatPanel.test.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/__tests__/BuilderChatPanel.test.tsx
index b9591da912..8ff705ef56 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/__tests__/BuilderChatPanel.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/__tests__/BuilderChatPanel.test.tsx
@@ -6,7 +6,11 @@ import {
} from "@/tests/integrations/test-utils";
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
import { BuilderChatPanel } from "../BuilderChatPanel";
-import { serializeGraphForChat, parseGraphActions } from "../helpers";
+import {
+ serializeGraphForChat,
+ parseGraphActions,
+ getActionKey,
+} from "../helpers";
import type { CustomNode } from "../../FlowEditor/nodes/CustomNode/CustomNode";
import type { CustomEdge } from "../../FlowEditor/edges/CustomEdge";
@@ -447,3 +451,28 @@ Here are the changes:
);
});
});
+
+describe("getActionKey", () => {
+ it("returns nodeId:key for update_node_input", () => {
+ expect(
+ getActionKey({
+ type: "update_node_input",
+ nodeId: "1",
+ key: "query",
+ value: "test",
+ }),
+ ).toBe("1:query");
+ });
+
+ it("returns source:handle->target:handle for connect_nodes", () => {
+ expect(
+ getActionKey({
+ type: "connect_nodes",
+ source: "1",
+ target: "2",
+ sourceHandle: "result",
+ targetHandle: "input",
+ }),
+ ).toBe("1:result->2:input");
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/helpers.ts
index 92ec31d21d..7fd30108a7 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/helpers.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/helpers.ts
@@ -97,6 +97,16 @@ export function buildSeedPrompt(summary: string): string {
);
}
+/**
+ * Returns a stable deduplication key for a GraphAction.
+ * Used for both React list keys and seen-set deduplication in the hook.
+ */
+export function getActionKey(action: GraphAction): string {
+ return action.type === "update_node_input"
+ ? `${action.nodeId}:${action.key}`
+ : `${action.source}:${action.sourceHandle}->${action.target}:${action.targetHandle}`;
+}
+
/**
* Extracts the concatenated plain-text content from a message's parts array.
* Reused in both the hook (action parsing) and the component (rendering).
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/useBuilderChatPanel.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/useBuilderChatPanel.ts
index 12b9c4929b..73d25e258e 100644
--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/useBuilderChatPanel.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/useBuilderChatPanel.ts
@@ -14,6 +14,7 @@ import {
GraphAction,
buildSeedPrompt,
extractTextFromParts,
+ getActionKey,
parseGraphActions,
serializeGraphForChat,
} from "./helpers";
@@ -134,10 +135,7 @@ export function useBuilderChatPanel({
const parsed = parseGraphActions(text);
const seen = new Set<string>();
return parsed.filter((action) => {
- const key =
- action.type === "update_node_input"
- ? `${action.nodeId}:${action.key}`
- : `${action.source}:${action.sourceHandle}->${action.target}:${action.targetHandle}`;
+ const key = getActionKey(action);
if (seen.has(key)) return false;
seen.add(key);
return true;