File size: 1,135 Bytes
5306da4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { v4 as uuidv4 } from "uuid";

interface SessionState {
  sessionId: string;
  thinking: boolean;
  transcribing: boolean;
  connected: boolean;
}

const initialState: SessionState = {
  sessionId: localStorage.getItem("voiceSessionId") || uuidv4(),
  thinking: false,
  transcribing: false,
  connected: false,
};

export const sessionSlice = createSlice({
  name: "session",
  initialState,
  reducers: {
    setSessionId: (state, action: PayloadAction<string>) => {
      state.sessionId = action.payload;
    },
    resetSessionId: (state, action) => {
      state.sessionId = action.payload;
    },
    setTranscribing: (state, action) => {
      state.transcribing = action.payload;
    },
    setConnected: (state, action) => {
      state.connected = action.payload;
    },
    setThinking: (state, action) => {
      state.thinking = action.payload;
      state.transcribing = false;
    },
  },
});

export const { setSessionId, resetSessionId, setTranscribing, setThinking , setConnected } =
  sessionSlice.actions;

export default sessionSlice.reducer;