📄 File detail

hooks/useIdeLogging.ts

🧩 .ts📏 42 lines💾 1,201 bytes📝 text
← Back to All Files

🎯 Use case

This file lives under “hooks/”, which covers reusable UI or integration hooks. On the API surface it exposes useIdeLogging — mainly functions, hooks, or classes. Dependencies touch React UI, src, and schema validation. It composes internal code from services and utils (relative imports).

Generated from folder role, exports, dependency roots, and inline comments — not hand-reviewed for every path.

🧠 Inline summary

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'

📤 Exports (heuristic)

  • useIdeLogging

📚 External import roots

Package roots from from "…" (relative paths omitted).

  • react
  • src
  • zod

🖥️ Source preview

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])
}