Skip to content

MAINT Extract copy and branch workflows from ChatWindow into useConversationCopy - #3812

Open
Julio César Suástegui (juliosuas) wants to merge 2 commits into
microsoft:mainfrom
juliosuas:maint/2652-copy-branch-workflow
Open

Julio César Suástegui (juliosuas) wants to merge 2 commits into
microsoft:mainfrom
juliosuas:maint/2652-copy-branch-workflow

Conversation

@juliosuas

Copy link
Copy Markdown
Contributor

Description

Related to #2652. Extracts the copy/branch orchestration from ChatWindow into 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 composes useConversationCopy instead 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

  • New useConversationCopy.test.ts with 10 cases covering copy, branch conversation, branch attack, lock handling and error paths.
  • Frontend jest: 4047/4047 passing.
  • tsc: 0 errors. Lint: 0 errors.
  • pre-commit: 18/18 hooks passing.
  • No documentation changes needed (internal refactor).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

…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.
if (isFailedPrompt && copiedMessages.length === 0 && !executionReadOnly) {
const response = await attacksApi.createAttack({
target_registry_name: target?.target_registry_name,
name: objective || undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants