-
Notifications
You must be signed in to change notification settings - Fork 58
fix(agent-builder): don't auto-send prompt when opening the dock #3486
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,13 @@ import { | |
| import type { AcpMessage } from "@posthog/shared"; | ||
| import { ThreadView } from "@posthog/ui/features/sessions/components/ThreadView"; | ||
| import { Flex, Text, Tooltip } from "@radix-ui/themes"; | ||
| import { type KeyboardEvent, type ReactNode, useState } from "react"; | ||
| import { | ||
| type KeyboardEvent, | ||
| type ReactNode, | ||
| useEffect, | ||
| useRef, | ||
| useState, | ||
| } from "react"; | ||
|
|
||
| /** | ||
| * The conversation + composer half of a deployed-agent chat, shared by the | ||
|
|
@@ -28,6 +34,7 @@ export function AgentChatSurface({ | |
| composerDisabledReason, | ||
| scrollX = true, | ||
| placeholder = "Message this agent…", | ||
| draft, | ||
| onSend, | ||
| onCancel, | ||
| }: { | ||
|
|
@@ -50,6 +57,10 @@ export function AgentChatSurface({ | |
| scrollX?: boolean; | ||
| /** Composer placeholder. */ | ||
| placeholder?: string; | ||
| /** When set, prefills the composer with `text` (without sending). Bump | ||
| * `token` each time a new draft should repopulate the input — the same text | ||
| * re-applies on a fresh token so re-triggering a seeded prompt works. */ | ||
| draft?: { text: string; token: number }; | ||
| onSend: (text: string) => void; | ||
| onCancel: () => void; | ||
| }) { | ||
|
|
@@ -84,6 +95,7 @@ export function AgentChatSurface({ | |
| isStreaming={isStreaming} | ||
| placeholder={placeholder} | ||
| disabledReason={composerDisabledReason} | ||
| draft={draft} | ||
| onSend={onSend} | ||
| onCancel={onCancel} | ||
| /> | ||
|
|
@@ -95,17 +107,31 @@ function Composer({ | |
| isStreaming, | ||
| placeholder, | ||
| disabledReason, | ||
| draft, | ||
| onSend, | ||
| onCancel, | ||
| }: { | ||
| isStreaming: boolean; | ||
| placeholder: string; | ||
| disabledReason?: string; | ||
| draft?: { text: string; token: number }; | ||
| onSend: (text: string) => void; | ||
| onCancel: () => void; | ||
| }) { | ||
| const [text, setText] = useState(""); | ||
| const parked = !!disabledReason; | ||
| const textareaRef = useRef<HTMLTextAreaElement>(null); | ||
|
|
||
| // Prefill (but don't send) when a new draft lands — a seeded prompt drops into | ||
| // the composer for the user to review, edit, and send. Keyed on `token` so the | ||
| // same prompt re-applies on a fresh trigger. | ||
| const lastDraftToken = useRef<number | null>(null); | ||
| useEffect(() => { | ||
| if (!draft || draft.token === lastDraftToken.current) return; | ||
| lastDraftToken.current = draft.token; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the dock is already open and the user has typed an unsent message, clicking a contextual header action creates a new draft token and this unconditional |
||
| setText(draft.text); | ||
| textareaRef.current?.focus(); | ||
| }, [draft]); | ||
|
|
||
| function submit() { | ||
| if (parked) return; | ||
|
|
@@ -132,6 +158,7 @@ function Composer({ | |
| <div className="shrink-0 px-3 pt-2 pb-3"> | ||
| <InputGroup className="h-auto cursor-text bg-card focus-within:ring-1 focus-within:ring-purple-9"> | ||
| <InputGroupTextarea | ||
| ref={textareaRef} | ||
| value={text} | ||
| onChange={(e) => setText(e.target.value)} | ||
| onKeyDown={onKeyDown} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have context on how vigilant this project is against useEffect, but I do wonder if there's a tidier means of solving it