claude-code-best/src/hooks/useIdeLogging.ts
claude-code-best a91653a0dd
fix: 删除 edit tool 中的旧逻辑处理, 现在已经不需要这些处理了, 大模型够屌 (#1251)
* refactor: remove tab/quote normalization from FileEditTool

* fix: resolve pre-existing typecheck errors (zod v4 compat + RCS web exclude)
2026-05-28 21:52:31 +08:00

42 lines
1.2 KiB
TypeScript

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() as any,
notification => {
const { eventName, eventData } = notification.params
logEvent(
`tengu_ide_${eventName}`,
eventData as { [key: string]: boolean | number | undefined },
)
},
)
}
}, [mcpClients])
}