source dump of claude code
at main 41 lines 1.2 kB view raw
1import { useEffect } from 'react' 2import { logEvent } from 'src/services/analytics/index.js' 3import { z } from 'zod/v4' 4import type { MCPServerConnection } from '../services/mcp/types.js' 5import { getConnectedIdeClient } from '../utils/ide.js' 6import { lazySchema } from '../utils/lazySchema.js' 7 8const LogEventSchema = lazySchema(() => 9 z.object({ 10 method: z.literal('log_event'), 11 params: z.object({ 12 eventName: z.string(), 13 eventData: z.object({}).passthrough(), 14 }), 15 }), 16) 17 18export function useIdeLogging(mcpClients: MCPServerConnection[]): void { 19 useEffect(() => { 20 // Skip if there are no clients 21 if (!mcpClients.length) { 22 return 23 } 24 25 // Find the IDE client from the MCP clients list 26 const ideClient = getConnectedIdeClient(mcpClients) 27 if (ideClient) { 28 // Register the log event handler 29 ideClient.client.setNotificationHandler( 30 LogEventSchema(), 31 notification => { 32 const { eventName, eventData } = notification.params 33 logEvent( 34 `tengu_ide_${eventName}`, 35 eventData as { [key: string]: boolean | number | undefined }, 36 ) 37 }, 38 ) 39 } 40 }, [mcpClients]) 41}