All files / webview/lib utils.ts

93.33% Statements 14/15
100% Branches 6/6
75% Functions 3/4
93.33% Lines 14/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53              5x                       10x       48x       5x 1x     4x         4x 4x 4x     4x   3x   3x   1x     4x    
import { type ClassValue, clsx } from 'clsx'
import { twMerge } from 'tailwind-merge'
 
export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}
 
const TOOL_ALIASES: Record<string, string> = {
  'mcp__ide-vs-code__call_bzapi': 'Call Boltz API',
  call_bzapi: 'Call Boltz API',
  'mcp__ide-vs-code__call_anksy_route': 'Call My App API',
  call_anksy_route: 'Call My App API',
  'mcp__ide-vs-code__get_bzapi_spec': 'Fetch Boltz API Spec',
  get_bzapi_spec: 'Fetch Boltz API Spec',
  'mcp__ide-vs-code__build_app': 'Build App',
  build_app: 'Build App',
}
 
export function displayToolName(name: string): string {
  return TOOL_ALIASES[name] ?? name
}
 
export function isHiddenResultTool(name: string): boolean {
  return name in TOOL_ALIASES
}
 
export function parseThinking(content: string): { title?: string; displayContent: string } {
  if (!content) {
    return { displayContent: '' }
  }
 
  let displayContent = content.trimStart()
  let title: string | undefined
 
  // Match "**Some Title**" at the start of any line
  // We use \s*? to optionally consume trailing spaces on that line and \n? to consume the newline
  const regex = /^\*\*([^\n]+?)\*\*\s*?\n?/gm
  for (const match of displayContent.matchAll(regex)) {
    title = match[1].trim()
  }
 
  if (title) {
    // Strip all matched title lines from the content
    displayContent = displayContent.replace(regex, '')
    // Clean up any remaining leading whitespace
    displayContent = displayContent.replace(/^[\r\n\s]+/, '')
  } else {
    displayContent = content
  }
 
  return { title, displayContent }
}