Skip to content

fix(chat): copy text content instead of raw response JSON#1471

Merged
xieyxclack merged 4 commits intoagentscope-ai:mainfrom
lllcy:fix/chat-copy-reply-text-clean
Mar 14, 2026
Merged

fix(chat): copy text content instead of raw response JSON#1471
xieyxclack merged 4 commits intoagentscope-ai:mainfrom
lllcy:fix/chat-copy-reply-text-clean

Conversation

@lllcy
Copy link
Copy Markdown
Contributor

@lllcy lllcy commented Mar 14, 2026

Summary

  • override the console reply copy action so it copies assistant-readable text instead of the full response JSON payload
  • extract assistant text and refusal content first, and fall back to JSON only when no copyable text exists
  • keep the built-in regenerate action while hardening the clipboard fallback and avoiding stale translation handlers

Fixes #1457

Testing

  • uv tool run --from pre-commit pre-commit run --files console/src/pages/Chat/index.tsx

Copilot AI review requested due to automatic review settings March 14, 2026 05:26
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the user experience in the chat console by refining how chat responses are copied. Instead of exposing complex internal JSON structures, the system now intelligently extracts and presents only the relevant, human-readable text from assistant messages. This change makes interactions more intuitive and efficient for users, ensuring that copied content is directly usable.

Highlights

  • Enhanced Copy Functionality: The chat console's copy action has been overridden to extract and copy assistant-readable text content (including text and refusal messages) instead of the raw JSON response payload.
  • Robust Clipboard Handling: A new utility function ensures cross-browser compatibility for copying text to the clipboard, with a fallback mechanism for insecure contexts or older browsers.
  • Custom Copy Action Integration: A dedicated copy button with an icon has been added to the chat interface, allowing users to easily copy the processed text content of assistant responses.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • console/src/pages/Chat/index.tsx
    • Added message component from antd for displaying user notifications.
    • Imported SparkCopyLine icon for the new copy action.
    • Defined new TypeScript types (CopyableContent, CopyableMessage, CopyableResponse) to model the structure of chat responses for copying.
    • Implemented extractCopyableText function to parse chat responses, prioritizing assistant text and refusal content, and falling back to stringified JSON.
    • Created copyText asynchronous function to handle clipboard operations, supporting modern navigator.clipboard API with a fallback for broader compatibility.
    • Introduced copyResponse useCallback hook to orchestrate the text extraction and copying process, including success and error feedback messages.
    • Integrated a custom copy action button into the IAgentScopeRuntimeWebUIOptions configuration, triggering the copyResponse function on click.
    • Updated the dependency array for the IAgentScopeRuntimeWebUIOptions useMemo hook to include copyResponse.
Activity
  • The author provided specific testing instructions using uv tool run --from pre-commit pre-commit run --files console/src/pages/Chat/index.tsx to verify the changes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a custom copy action to copy readable text from chat responses instead of raw JSON. The implementation includes a robust copyText utility with a fallback for non-secure contexts. My review focuses on improving type definitions for clarity, enhancing error handling, and ensuring the new actions don't unintentionally remove existing functionality. Overall, the changes are a good improvement to the user experience.

Comment thread console/src/pages/Chat/index.tsx
Comment thread console/src/pages/Chat/index.tsx Outdated
Comment thread console/src/pages/Chat/index.tsx
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Chat console’s “copy reply” behavior to copy assistant-readable text extracted from response content (text/refusal) instead of copying the full raw response JSON, with a clipboard fallback for non-secure contexts.

Changes:

  • Added helpers to extract copyable text from a response payload and to copy text with a clipboard API fallback.
  • Wired a custom copy action into AgentScopeRuntimeWebUI actions and added success/error toast feedback.
  • Added an index.module.less import in the Chat page.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread console/src/pages/Chat/index.tsx
Comment thread console/src/pages/Chat/index.tsx Outdated
Comment thread console/src/pages/Chat/index.tsx
@lllcy
Copy link
Copy Markdown
Contributor Author

lllcy commented Mar 14, 2026

Follow-up changes pushed in e913a5e.

  • removed the unused index.module.less side-effect import
  • simplified CopyableContent
  • hardened extractCopyableText so it also handles string content and safely skips non-array/non-string content

I did not change replace: true because the current @agentscope-ai/chat implementation still appends the built-in regenerate action when replace is enabled.

@xieyxclack
Copy link
Copy Markdown
Member

@lllcy Thank you for your contribution!

One suggestion: t("common.copy") — this key doesn't exist in the locale files (en/zh/ja/ru). The copy button tooltip will show the raw key string instead of localized text. Please add a "copy" entry to the common section in each locale file.

Copilot AI review requested due to automatic review settings March 14, 2026 14:51
@lllcy
Copy link
Copy Markdown
Contributor Author

lllcy commented Mar 14, 2026

Thanks for catching that — fixed in cfa41fd.

Added common.copy to the console locale files:

  • console/src/locales/en.json
  • console/src/locales/zh.json
  • console/src/locales/ja.json
  • console/src/locales/ru.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the chat console’s “copy reply” behavior so users copy assistant-readable text (e.g., Markdown) instead of the raw response JSON payload, addressing issue #1457.

Changes:

  • Added response parsing to extract assistant text / refusal blocks for copying, with clipboard fallback support.
  • Overrode the runtime UI action list to provide a custom copy action with success/failure toasts.
  • Added a new common.copy i18n key across supported locales.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
console/src/pages/Chat/index.tsx Adds text extraction + clipboard copy helper and wires a custom copy action into the chat UI options.
console/src/locales/en.json Adds common.copy translation.
console/src/locales/zh.json Adds common.copy translation.
console/src/locales/ru.json Adds common.copy translation.
console/src/locales/ja.json Adds common.copy translation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread console/src/pages/Chat/index.tsx
Comment thread console/src/pages/Chat/index.tsx Outdated
Comment thread console/src/pages/Chat/index.tsx
@lllcy
Copy link
Copy Markdown
Contributor Author

lllcy commented Mar 14, 2026

Follow-up changes pushed in 65b26db.

  • updated CopyableMessage.content to match the handled runtime shape (string | CopyableContent[])
  • restricted the copy fallback so it uses assistant-readable content first and only falls back to raw JSON when no assistant text is available

I still did not change replace: true because the current @agentscope-ai/chat implementation appends the built-in regenerate action when replace is enabled.

Copy link
Copy Markdown
Member

@xieyxclack xieyxclack left a comment

Choose a reason for hiding this comment

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

LGTM

@xieyxclack xieyxclack merged commit 8d61d12 into agentscope-ai:main Mar 14, 2026
3 checks passed
tudan110 pushed a commit to tudan110/QwenPaw that referenced this pull request Apr 4, 2026
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.

[Bug]:点击复制回复内容应为Markdown格式,但现在点击复制回复的内容是Json格式

3 participants