Repository navigation
MAINT Extract copy and branch workflows from ChatWindow into useConversationCopy - #3812
Julio César Suástegui (juliosuas) wants to merge 2 commits into
Conversation
82069c7 to
ff3869f
Compare
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the extraction of copy and branch workflows into a dedicated hook.
No open issues 🎉
What changed in this PR
Continues #2652’s ChatWindow decomposition by extracting copy and branch workflows into useConversationCopy. Send/recovery orchestration remains in ChatWindow, with existing behavior intended to stay unchanged.
Changes:
- Moves copy/branch orchestration, lock checks, navigation, and error handling into a focused hook.
- Extracts shared prompt-restoration and conversation-signature helpers.
- Adds 10 hook tests covering copy destinations, locking, navigation guards, recovery delegation, and errors.
| File | Description |
|---|---|
frontend/src/utils/promptRestore.ts |
Extracts converter-restoration and conversation-signature helpers. |
frontend/src/hooks/useConversationCopy.ts |
Encapsulates copy and branch workflows behind typed commands. |
frontend/src/hooks/useConversationCopy.test.ts |
Adds focused workflow and guard coverage. |
frontend/src/components/Chat/ChatWindow.tsx |
Composes the new hook instead of inlining copy/branch logic. |
Review effort: Balanced
ff3869f to
7788643
Compare
…rsationCopy Move copy-to-conversation, copy-to-new-attack, use-in-technique and branch orchestration, plus the in-flight copy lock and branch disabled reasons, into a focused hook. ChatWindow keeps the composer, recovery and navigation state and passes them in. Shared prompt-restore helpers move to utils/promptRestore. Part of microsoft#2652.
7788643 to
9428f22
Compare
| if (isFailedPrompt && copiedMessages.length === 0 && !executionReadOnly) { | ||
| const response = await attacksApi.createAttack({ | ||
| target_registry_name: target?.target_registry_name, | ||
| name: objective || undefined, |
There was a problem hiding this comment.
🟡 Keep the objective field when resolving the main conflict
#3990 changed this call on main to send objective. Its failed-prompt branch tests now require that field and explicitly reject name. Resolving the ChatWindow conflict by keeping the extraction would leave the old payload here and fail those tests.
Please carry main's update into this hook when resolving the conflict:
objective: objective || undefined,The backend still accepts name as a deprecated alias, so this is an integration/test concern, not data loss on the current head.
There was a problem hiding this comment.
Roman Lutz (@romanlutz) Sorry for the delayed response I was sick. Thanks for flagging the objective field when resolving the conflict.
Keep useConversationCopy and send objective, not the deprecated name alias, when branching a failed prompt into a new attack. Co-authored-by: Julio César Suástegui <juliosuas@users.noreply.github.com>
Description
Related to #2652. Extracts the copy/branch orchestration from
ChatWindowinto a focused hook. This is the remaining copy/new-conversation/branch part of the issue; loading landed in #3310 and score/objective/export landed in #3369. Send/recovery orchestration is not touched here.frontend/src/hooks/useConversationCopy.ts: new hook owning copy to new conversation, branch conversation and branch attack, including lock checks, navigation and error handling. Returns typed state and commands.frontend/src/utils/promptRestore.ts: small helper for restoring the prompt/attachments from a copied message.ChatWindow.tsx: now composesuseConversationCopyinstead of inlining these workflows. Props, rendered UX, request payloads and navigation behavior are unchanged.Compatibility checked against open #3670: no conflicts in either merge order, and the combined suite passes (360/360) with both applied.
Tests and Documentation
useConversationCopy.test.tswith 10 cases covering copy, branch conversation, branch attack, lock handling and error paths.tsc: 0 errors. Lint: 0 errors.