File size: 1,004 Bytes
f0743f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { createContext, useContext, useMemo } from 'react';
import { Constants } from 'librechat-data-provider';
import { useChatContext } from './ChatContext';

interface MCPPanelContextValue {
  conversationId: string;
}

const MCPPanelContext = createContext<MCPPanelContextValue | undefined>(undefined);

export function MCPPanelProvider({ children }: { children: React.ReactNode }) {
  const { conversation } = useChatContext();

  /** Context value only created when conversationId changes */
  const contextValue = useMemo<MCPPanelContextValue>(
    () => ({
      conversationId: conversation?.conversationId ?? Constants.NEW_CONVO,
    }),
    [conversation?.conversationId],
  );

  return <MCPPanelContext.Provider value={contextValue}>{children}</MCPPanelContext.Provider>;
}

export function useMCPPanelContext() {
  const context = useContext(MCPPanelContext);
  if (!context) {
    throw new Error('useMCPPanelContext must be used within MCPPanelProvider');
  }
  return context;
}