Download src/hooks/useIdeLogging.ts from chenbhao/codev: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/chenbhao/codev/resolve/afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/hooks/useIdeLogging.ts
- Command line
-
hf download hf://chenbhao/codev@afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/hooks/useIdeLogging.ts
-
curl -L -o useIdeLogging.ts https://huggingface.co/chenbhao/codev/resolve/afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/hooks/useIdeLogging.ts
1.2 kB
| import { useEffect } from 'react' | |
| import { logEvent } from 'src/services/analytics/index.js' | |
| import { z } from 'zod/v4' | |
| import type { MCPServerConnection } from '../services/mcp/types.js' | |
| import { getConnectedIdeClient } from '../utils/ide.js' | |
| import { lazySchema } from '../utils/lazySchema.js' | |
| const LogEventSchema = lazySchema(() => | |
| z.object({ | |
| method: z.literal('log_event'), | |
| params: z.object({ | |
| eventName: z.string(), | |
| eventData: z.object({}).passthrough(), | |
| }), | |
| }), | |
| ) | |
| export function useIdeLogging(mcpClients: MCPServerConnection[]): void { | |
| useEffect(() => { | |
| // Skip if there are no clients | |
| if (!mcpClients.length) { | |
| return | |
| } | |
| // Find the IDE client from the MCP clients list | |
| const ideClient = getConnectedIdeClient(mcpClients) | |
| if (ideClient) { | |
| // Register the log event handler | |
| ideClient.client.setNotificationHandler( | |
| LogEventSchema(), | |
| notification => { | |
| const { eventName, eventData } = notification.params | |
| logEvent( | |
| `tengu_ide_${eventName}`, | |
| eventData as { [key: string]: boolean | number | undefined }, | |
| ) | |
| }, | |
| ) | |
| } | |
| }, [mcpClients]) | |
| } | |