Skip to content

Commit c777d6c

Browse files
committed
feat(react-client): add mcp zustand store
1 parent b91e776 commit c777d6c

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

libs/react-client/src/store/chat.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ interface ChatState {
2525
setCommands: (commands: ICommand[]) => void;
2626
setSideView: (
2727
sideViewOrSetter?:
28-
| { title: string; elements: IMessageElement[] }
29-
| ((old?: { title: string; elements: IMessageElement[] }) =>
28+
| { title: string; elements: IMessageElement[]; key?: string }
29+
| ((old?: {
30+
title: string;
31+
elements: IMessageElement[];
32+
key?: string;
33+
}) =>
3034
| {
3135
title: string;
3236
elements: IMessageElement[];
37+
key?: string;
3338
}
3439
| undefined)
3540
) => void;
3641
setChatProfile: (chatProfile: string) => void;
42+
setChatSettingsValue: (chatSettingsValue: any) => void;
3743
resetChatSettingsInputs: () => void;
3844
resetChatSettingsValue: () => void;
3945
}
@@ -87,6 +93,10 @@ export const useChatStore = create<ChatState>((set, get) => ({
8793
set({ chatProfile });
8894
},
8995

96+
setChatSettingsValue: (chatSettingsValue) => {
97+
set({ chatSettingsValue });
98+
},
99+
90100
resetChatSettingsInputs: () => {
91101
set({ chatSettingsInputs: [] });
92102
},

libs/react-client/src/store/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './auth';
22
export * from './chat';
33
export * from './config';
4+
export * from './mcp';
45
export * from './messages';
56
export * from './session';
67
export * from './thread';

libs/react-client/src/store/mcp.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { persist } from 'zustand/middleware';
2+
import { create } from 'zustand/react';
3+
4+
import { IMcp } from '../types';
5+
import { stateOrSetter } from './utils';
6+
7+
interface McpState {
8+
mcps: IMcp[];
9+
setMcps: (mcpsOrSetter: ((prev: IMcp[]) => IMcp[]) | IMcp[]) => void;
10+
}
11+
12+
export const useMcpStore = create<McpState>()(
13+
persist(
14+
(set) => ({
15+
mcps: [] as IMcp[],
16+
setMcps: (mcpsOrSetter) => stateOrSetter(set, 'mcps', mcpsOrSetter)
17+
}),
18+
{
19+
name: 'mcp_storage_key'
20+
}
21+
)
22+
);

libs/react-client/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export * from './thread';
99
export * from './history';
1010
export * from './config';
1111
export * from './mcp';
12+
export * from './session';

libs/react-client/src/useChatSession.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
IAction,
77
ICommand,
88
IElement,
9+
IMcp,
910
IMessageElement,
1011
IStep,
1112
ITasklistElement,
@@ -22,6 +23,7 @@ import { OutputAudioChunk } from './types/audio';
2223

2324
import { ChainlitContext } from './context';
2425
import { useChatStore } from './store/chat';
26+
import { useMcpStore } from './store/mcp';
2527
import { useMessagesStore } from './store/messages';
2628
import { useSessionState } from './store/session';
2729
import { useThreadStore } from './store/thread';
@@ -122,7 +124,7 @@ const useChatSession = () => {
122124
socket.on('connect', () => {
123125
socket.emit('connection_successful');
124126
setSession((s) => ({ ...s!, error: false }));
125-
setMcps((prev) =>
127+
setMcps((prev: IMcp[]) =>
126128
prev.map((mcp) => {
127129
const promise =
128130
mcp.clientType === 'sse'

0 commit comments

Comments
 (0)