@zeniai/client-epic-state 4.16.97 → 4.16.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,8 +41,6 @@ export declare const setNewSession: import("@reduxjs/toolkit").ActionCreatorWith
41
41
  }, "aiController/addQuestionPayload">, clearAIController: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"aiController/clearAIController">, deleteQuestion: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
42
42
  chatSessionId: ID;
43
43
  questionAnswerId: ID;
44
- }, "aiController/deleteQuestion">, updateNewSession: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
45
- chatSessionId: ID;
46
- }, "aiController/updateNewSession">;
44
+ }, "aiController/deleteQuestion">;
47
45
  declare const _default: import("redux").Reducer<AIControllerState>;
48
46
  export default _default;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.updateNewSession = exports.deleteQuestion = exports.clearAIController = exports.addQuestionPayload = exports.upsertOrAddQuestionAnswerPayload = exports.upsertAnswerPayload = exports.setChatHistory = exports.setSessions = exports.clearSession = exports.setNewSession = exports.toAIControllerVisualization = exports.initialAIControllerState = void 0;
4
+ exports.deleteQuestion = exports.clearAIController = exports.addQuestionPayload = exports.upsertOrAddQuestionAnswerPayload = exports.upsertAnswerPayload = exports.setChatHistory = exports.setSessions = exports.clearSession = exports.setNewSession = exports.toAIControllerVisualization = exports.initialAIControllerState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  const zeniDayJS_1 = require("../../zeniDayJS");
7
7
  const aiControllerState_1 = require("./aiControllerState");
@@ -204,7 +204,6 @@ const aiController = (0, toolkit_1.createSlice)({
204
204
  chatSessionId,
205
205
  userId,
206
206
  chatSessionSummary: '',
207
- newSession: true,
208
207
  createdAt,
209
208
  },
210
209
  questionAnswers: [],
@@ -212,16 +211,6 @@ const aiController = (0, toolkit_1.createSlice)({
212
211
  // Clear any existing partial Q&A when creating a new session
213
212
  draft.partialQuestionAnswers[chatSessionId] = undefined;
214
213
  },
215
- updateNewSession(draft, action) {
216
- const { chatSessionId } = action.payload;
217
- if (draft.aiControllerByChatSessionId[chatSessionId] == null) {
218
- console.warn(`session with id ${chatSessionId} not found`);
219
- return;
220
- }
221
- if (draft.aiControllerByChatSessionId[chatSessionId].chatSession.newSession) {
222
- draft.aiControllerByChatSessionId[chatSessionId].chatSession.newSession = false;
223
- }
224
- },
225
214
  setSessions(draft, action) {
226
215
  action.payload.forEach((chatSessionPayload) => {
227
216
  const { chat_session_id } = chatSessionPayload;
@@ -482,10 +471,9 @@ const toChatSession = (chatSessionPayload) => {
482
471
  return {
483
472
  chatSessionId: chat_session_id,
484
473
  userId: user_id,
485
- newSession: false,
486
474
  chatSessionSummary: chat_session_summary !== null && chat_session_summary !== void 0 ? chat_session_summary : undefined,
487
475
  createdAt: (0, zeniDayJS_1.date)(created_at),
488
476
  };
489
477
  };
490
- _a = aiController.actions, exports.setNewSession = _a.setNewSession, exports.clearSession = _a.clearSession, exports.setSessions = _a.setSessions, exports.setChatHistory = _a.setChatHistory, exports.upsertAnswerPayload = _a.upsertAnswerPayload, exports.upsertOrAddQuestionAnswerPayload = _a.upsertOrAddQuestionAnswerPayload, exports.addQuestionPayload = _a.addQuestionPayload, exports.clearAIController = _a.clearAIController, exports.deleteQuestion = _a.deleteQuestion, exports.updateNewSession = _a.updateNewSession;
478
+ _a = aiController.actions, exports.setNewSession = _a.setNewSession, exports.clearSession = _a.clearSession, exports.setSessions = _a.setSessions, exports.setChatHistory = _a.setChatHistory, exports.upsertAnswerPayload = _a.upsertAnswerPayload, exports.upsertOrAddQuestionAnswerPayload = _a.upsertOrAddQuestionAnswerPayload, exports.addQuestionPayload = _a.addQuestionPayload, exports.clearAIController = _a.clearAIController, exports.deleteQuestion = _a.deleteQuestion;
491
479
  exports.default = aiController.reducer;
@@ -76,7 +76,6 @@ export interface ChatSession {
76
76
  chatSessionId: ID;
77
77
  userId: ID;
78
78
  createdAt: ZeniDate;
79
- newSession: boolean;
80
79
  chatSessionSummary?: string;
81
80
  }
82
81
  export interface ChatSessionWithMessages {
@@ -5,13 +5,17 @@ import { AIControllerAnswerResponseType } from '../../entity/aiController/aiCont
5
5
  import { ZeniAPIStatus } from '../../responsePayload';
6
6
  import { AIControllerViewState } from './aiControllerViewState';
7
7
  export declare const initialAIControllerViewState: AIControllerViewState;
8
- export declare const submitQuestion: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[questionAnswerId: string, userId: string, questionId: string, createdAt: import("dayjs").Dayjs, question: string], {
8
+ export declare const submitQuestion: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[sessionId: string, questionAnswerId: string, userId: string, questionId: string, createdAt: import("dayjs").Dayjs, question: string], {
9
+ sessionId: string;
9
10
  questionAnswerId: string;
10
11
  userId: string;
11
12
  questionId: string;
12
13
  createdAt: import("dayjs").Dayjs;
13
14
  question: string;
14
- }, "aiControllerView/submitQuestion", never, never>, submitQuestionSuccess: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"aiControllerView/submitQuestionSuccess">, submitQuestionFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "aiControllerView/submitQuestionFailure">, updateResponseState: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
15
+ }, "aiControllerView/submitQuestion", never, never>, submitQuestionSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "aiControllerView/submitQuestionSuccess">, submitQuestionFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
16
+ sessionId: ID;
17
+ error: ZeniAPIStatus;
18
+ }, "aiControllerView/submitQuestionFailure">, updateResponseState: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
15
19
  chatSessionId: ID;
16
20
  responseType: AIControllerAnswerResponseType;
17
21
  fetchState: FetchStateAndError;
@@ -33,19 +33,19 @@ const aiControllerView = (0, toolkit_1.createSlice)({
33
33
  initialState: exports.initialAIControllerViewState,
34
34
  reducers: {
35
35
  submitQuestion: {
36
- reducer(draft) {
37
- if (draft.uiState.currentChatSessionId != null) {
38
- draft.responseStateByChatSessionId[draft.uiState.currentChatSessionId] = {
39
- thought: { fetchState: 'In-Progress', error: undefined },
40
- analysis: { fetchState: 'In-Progress', error: undefined },
41
- reasoning: { fetchState: 'In-Progress', error: undefined },
42
- answer: { fetchState: 'In-Progress', error: undefined },
43
- };
44
- }
36
+ reducer(draft, action) {
37
+ const { sessionId } = action.payload;
38
+ draft.responseStateByChatSessionId[sessionId] = {
39
+ thought: { fetchState: 'In-Progress', error: undefined },
40
+ analysis: { fetchState: 'In-Progress', error: undefined },
41
+ reasoning: { fetchState: 'In-Progress', error: undefined },
42
+ answer: { fetchState: 'In-Progress', error: undefined },
43
+ };
45
44
  },
46
- prepare(questionAnswerId, userId, questionId, createdAt, question) {
45
+ prepare(sessionId, questionAnswerId, userId, questionId, createdAt, question) {
47
46
  return {
48
47
  payload: {
48
+ sessionId,
49
49
  questionAnswerId,
50
50
  userId,
51
51
  questionId,
@@ -55,22 +55,24 @@ const aiControllerView = (0, toolkit_1.createSlice)({
55
55
  };
56
56
  },
57
57
  },
58
- submitQuestionSuccess(draft) {
59
- if (draft.uiState.currentChatSessionId != null &&
60
- draft.responseStateByChatSessionId[draft.uiState.currentChatSessionId] != null) {
61
- draft.responseStateByChatSessionId[draft.uiState.currentChatSessionId] =
62
- {
63
- thought: { fetchState: 'Completed', error: undefined },
64
- analysis: { fetchState: 'Completed', error: undefined },
65
- reasoning: { fetchState: 'Completed', error: undefined },
66
- answer: { fetchState: 'Completed', error: undefined },
67
- };
58
+ submitQuestionSuccess(draft, action) {
59
+ const sessionId = action.payload;
60
+ if (draft.responseStateByChatSessionId[sessionId] != null) {
61
+ draft.responseStateByChatSessionId[sessionId] = {
62
+ thought: { fetchState: 'Completed', error: undefined },
63
+ analysis: { fetchState: 'Completed', error: undefined },
64
+ reasoning: { fetchState: 'Completed', error: undefined },
65
+ answer: { fetchState: 'Completed', error: undefined },
66
+ };
68
67
  }
69
68
  },
70
69
  submitQuestionFailure(draft, action) {
71
- if (draft.uiState.currentChatSessionId != null &&
72
- draft.responseStateByChatSessionId[draft.uiState.currentChatSessionId] != null) {
73
- draft.responseStateByChatSessionId[draft.uiState.currentChatSessionId]['answer'] = { fetchState: 'Error', error: action.payload };
70
+ const { sessionId, error } = action.payload;
71
+ if (draft.responseStateByChatSessionId[sessionId] != null) {
72
+ draft.responseStateByChatSessionId[sessionId]['answer'] = {
73
+ fetchState: 'Error',
74
+ error,
75
+ };
74
76
  }
75
77
  },
76
78
  updateResponseState(draft, action) {
@@ -23,7 +23,7 @@ const createSessionAndSubmitEpic = (actions$, _, zeniAPI) => actions$.pipe((0, o
23
23
  }), (0, aiControllerViewReducer_1.createSessionAndSubmitSuccess)({
24
24
  agentId,
25
25
  sessionId,
26
- }), (0, aiControllerViewReducer_1.submitQuestion)(questionAnswerId, userId, questionId, createdAt, question), (0, aiControllerReducer_1.addQuestionPayload)({
26
+ }), (0, aiControllerViewReducer_1.submitQuestion)(sessionId, questionAnswerId, userId, questionId, createdAt, question), (0, aiControllerReducer_1.addQuestionPayload)({
27
27
  chatSessionId: sessionId,
28
28
  questionAnswerId: questionAnswerId,
29
29
  question: {
@@ -1,8 +1,8 @@
1
1
  import { ActionsObservable, StateObservable } from 'redux-observable';
2
2
  import { Observable } from 'rxjs';
3
- import { updateNewSession, upsertOrAddQuestionAnswerPayload } from '../../../entity/aiController/aiControllerReducer';
3
+ import { upsertOrAddQuestionAnswerPayload } from '../../../entity/aiController/aiControllerReducer';
4
4
  import { RootState } from '../../../reducer';
5
5
  import { ZeniAPI } from '../../../zeniAPI';
6
6
  import { submitQuestion, submitQuestionFailure, submitQuestionSuccess } from '../aiControllerViewReducer';
7
- export type ActionType = ReturnType<typeof submitQuestion> | ReturnType<typeof updateNewSession> | ReturnType<typeof submitQuestionSuccess> | ReturnType<typeof submitQuestionFailure> | ReturnType<typeof upsertOrAddQuestionAnswerPayload>;
7
+ export type ActionType = ReturnType<typeof submitQuestion> | ReturnType<typeof submitQuestionSuccess> | ReturnType<typeof submitQuestionFailure> | ReturnType<typeof upsertOrAddQuestionAnswerPayload>;
8
8
  export declare const submitQuestionEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -7,18 +7,15 @@ const aiControllerReducer_1 = require("../../../entity/aiController/aiController
7
7
  const responsePayload_1 = require("../../../responsePayload");
8
8
  const aiControllerViewReducer_1 = require("../aiControllerViewReducer");
9
9
  const submitQuestionEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(aiControllerViewReducer_1.submitQuestion.match), (0, operators_1.mergeMap)((action) => {
10
- const { questionAnswerId, userId, questionId, createdAt, question } = action.payload;
10
+ const { questionAnswerId, userId, sessionId, questionId, createdAt, question, } = action.payload;
11
11
  const { aiControllerViewState } = state$.value;
12
12
  const { uiState } = aiControllerViewState;
13
13
  const agentId = uiState.agentId;
14
- const sessionId = uiState.currentChatSessionId;
15
14
  const payload = { chat_session_id: sessionId, message: question };
16
- if (agentId == null || sessionId == null || Boolean(question) == false) {
15
+ if (agentId == null || Boolean(question) == false) {
17
16
  throw new Error('Invalid State');
18
17
  }
19
- // First, update the session to mark it as no longer new
20
- const updateSessionAction = (0, aiControllerReducer_1.updateNewSession)({ chatSessionId: sessionId });
21
- return (0, rxjs_1.concat)((0, rxjs_1.of)(updateSessionAction), zeniAPI
18
+ return zeniAPI
22
19
  .postAndGetJSON(`${zeniAPI.apiEndPoints.aiControllerMicroServiceBaseUrl}/1.0/agents/${agentId}`, payload)
23
20
  .pipe((0, operators_1.mergeMap)((response) => {
24
21
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
@@ -34,13 +31,19 @@ const submitQuestionEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, oper
34
31
  answerPayload: response.data,
35
32
  userId,
36
33
  insertQuestionAnswer: false, // Don't insert the Q/A here after stopSubmitSuccess
37
- }), (0, aiControllerViewReducer_1.submitQuestionSuccess)());
34
+ }), (0, aiControllerViewReducer_1.submitQuestionSuccess)(sessionId));
38
35
  return (0, rxjs_1.of)(...actions);
39
36
  }
40
37
  else {
41
- return (0, rxjs_1.of)((0, aiControllerViewReducer_1.submitQuestionFailure)(response.status));
38
+ return (0, rxjs_1.of)((0, aiControllerViewReducer_1.submitQuestionFailure)({
39
+ sessionId,
40
+ error: response.status,
41
+ }));
42
42
  }
43
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, aiControllerViewReducer_1.submitQuestionFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Submit question REST API call errored out' +
44
- JSON.stringify(error)))))));
43
+ }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, aiControllerViewReducer_1.submitQuestionFailure)({
44
+ sessionId,
45
+ error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Submit question REST API call errored out' +
46
+ JSON.stringify(error)),
47
+ }))));
45
48
  }));
46
49
  exports.submitQuestionEpic = submitQuestionEpic;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "4.16.97",
3
+ "version": "4.16.98",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",