victor HF Staff commited on
Commit
4809989
·
1 Parent(s): 7a0420c

Strip <think> blocks from copied chat message content

Browse files

Updated clipboard copy functionality to remove <think> blocks from chat message content using a case-insensitive regex. This ensures that only the main message text is copied, regardless of autodetection.

src/lib/components/chat/ChatMessage.svelte CHANGED
@@ -68,9 +68,14 @@
68
  let editFormEl: HTMLFormElement | undefined = $state();
69
 
70
  // Zero-config reasoning autodetection: detect <think> blocks in content
71
- const THINK_BLOCK_REGEX = /(<think>[\s\S]*?(?:<\/think>|$))/g;
72
  let hasClientThink = $derived(message.content.split(THINK_BLOCK_REGEX).length > 1);
73
 
 
 
 
 
 
74
  $effect(() => {
75
  if (isCopied) {
76
  setTimeout(() => {
@@ -214,7 +219,7 @@
214
  isCopied = true;
215
  }}
216
  classNames="btn rounded-sm p-1 text-sm text-gray-400 hover:text-gray-500 focus:ring-0 dark:text-gray-400 dark:hover:text-gray-300"
217
- value={message.content}
218
  iconClassNames="text-xs"
219
  />
220
  <button
 
68
  let editFormEl: HTMLFormElement | undefined = $state();
69
 
70
  // Zero-config reasoning autodetection: detect <think> blocks in content
71
+ const THINK_BLOCK_REGEX = /(<think>[\s\S]*?(?:<\/think>|$))/gi;
72
  let hasClientThink = $derived(message.content.split(THINK_BLOCK_REGEX).length > 1);
73
 
74
+ // Strip think blocks for clipboard copy (always, regardless of detection)
75
+ let contentWithoutThink = $derived.by(() =>
76
+ message.content.replace(THINK_BLOCK_REGEX, "").trim()
77
+ );
78
+
79
  $effect(() => {
80
  if (isCopied) {
81
  setTimeout(() => {
 
219
  isCopied = true;
220
  }}
221
  classNames="btn rounded-sm p-1 text-sm text-gray-400 hover:text-gray-500 focus:ring-0 dark:text-gray-400 dark:hover:text-gray-300"
222
+ value={contentWithoutThink}
223
  iconClassNames="text-xs"
224
  />
225
  <button