forked from sanbuphy/learn-coding-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseIdeLogging.ts
More file actions
41 lines (38 loc) · 1.17 KB
/
useIdeLogging.ts
File metadata and controls
41 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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])
}