setupNotificationHandler configures handlers for session events and RPC requests.
()
| 2041 | |
| 2042 | // setupNotificationHandler configures handlers for session events and RPC requests. |
| 2043 | func (c *Client) setupNotificationHandler() { |
| 2044 | c.client.SetRequestHandler("session.event", jsonrpc2.NotificationHandlerFor(c.handleSessionEvent)) |
| 2045 | c.client.SetRequestHandler("session.lifecycle", jsonrpc2.NotificationHandlerFor(c.handleLifecycleEvent)) |
| 2046 | c.client.SetRequestHandler("userInput.request", jsonrpc2.RequestHandlerFor(c.handleUserInputRequest)) |
| 2047 | c.client.SetRequestHandler("exitPlanMode.request", jsonrpc2.RequestHandlerFor(c.handleExitPlanModeRequest)) |
| 2048 | c.client.SetRequestHandler("autoModeSwitch.request", jsonrpc2.RequestHandlerFor(c.handleAutoModeSwitchRequest)) |
| 2049 | c.client.SetRequestHandler("hooks.invoke", jsonrpc2.RequestHandlerFor(c.handleHooksInvoke)) |
| 2050 | c.client.SetRequestHandler("systemMessage.transform", jsonrpc2.RequestHandlerFor(c.handleSystemMessageTransform)) |
| 2051 | rpc.RegisterClientSessionAPIHandlers(c.client, func(sessionID string) *rpc.ClientSessionAPIHandlers { |
| 2052 | c.sessionsMux.Lock() |
| 2053 | defer c.sessionsMux.Unlock() |
| 2054 | session := c.sessions[sessionID] |
| 2055 | if session == nil { |
| 2056 | return nil |
| 2057 | } |
| 2058 | return session.clientSessionAPIs |
| 2059 | }) |
| 2060 | if c.options.RequestHandler != nil { |
| 2061 | adapter := newCopilotRequestAdapter(c.options.RequestHandler, func() *rpc.ServerLlmInferenceAPI { |
| 2062 | if c.RPC == nil { |
| 2063 | return nil |
| 2064 | } |
| 2065 | return c.RPC.LlmInference |
| 2066 | }) |
| 2067 | rpc.RegisterClientGlobalAPIHandlers(c.client, &rpc.ClientGlobalAPIHandlers{LlmInference: adapter}) |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | func (c *Client) handleSessionEvent(req sessionEventRequest) { |
| 2072 | if req.SessionID == "" { |
no test coverage detected