useIdeLogging.ts
hooks/useIdeLogging.ts
No strong subsystem tag
42
Lines
1201
Bytes
1
Exports
6
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 42 lines, 6 detected imports, and 1 detected exports.
Important relationships
Detected exports
useIdeLogging
Keywords
mcpclientslazyschemaobjecteventnameeventdataideclientuseeffectlogeventservicesmcpserverconnection
Detected imports
reactsrc/services/analytics/index.jszod/v4../services/mcp/types.js../utils/ide.js../utils/lazySchema.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
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])
}