@zeniai/client-epic-state 4.17.9 → 4.17.11
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.
- package/lib/entity/accountRecon/accountReconPayload.d.ts +0 -2
- package/lib/entity/accountRecon/accountReconPayload.js +1 -6
- package/lib/entity/accountRecon/accountReconState.d.ts +0 -2
- package/lib/entity/{aiCfo/aiCfoPayload.d.ts → aiController/aiControllerPayload.d.ts} +3 -3
- package/lib/entity/aiController/aiControllerReducer.d.ts +46 -0
- package/lib/entity/{aiCfo/aiCfoReducer.js → aiController/aiControllerReducer.js} +42 -40
- package/lib/entity/aiController/aiControllerSelector.d.ts +14 -0
- package/lib/entity/{aiCfo/aiCfoSelector.js → aiController/aiControllerSelector.js} +6 -6
- package/lib/entity/aiController/aiControllerState.d.ts +88 -0
- package/lib/entity/aiController/aiControllerState.js +49 -0
- package/lib/entity/chargeCard/chargeCard.d.ts +1 -1
- package/lib/entity/chargeCard/chargeCard.js +0 -1
- package/lib/entity/tenant/clearAllEpic.d.ts +4 -4
- package/lib/entity/tenant/clearAllEpic.js +4 -4
- package/lib/epic.d.ts +7 -7
- package/lib/epic.js +7 -7
- package/lib/index.d.ts +10 -9
- package/lib/index.js +57 -55
- package/lib/reducer.d.ts +6 -6
- package/lib/reducer.js +6 -6
- package/lib/view/{aiCfoView/aiCfoViewPayload.d.ts → aiControllerView/aiControllerViewPayload.d.ts} +2 -2
- package/lib/view/aiControllerView/aiControllerViewReducer.d.ts +73 -0
- package/lib/view/{aiCfoView/aiCfoViewReducer.js → aiControllerView/aiControllerViewReducer.js} +10 -10
- package/lib/view/{aiCfoView/aiCfoViewSelector.d.ts → aiControllerView/aiControllerViewSelector.d.ts} +5 -5
- package/lib/view/{aiCfoView/aiCfoViewSelector.js → aiControllerView/aiControllerViewSelector.js} +6 -6
- package/lib/view/{aiCfoView/aiCfoViewState.d.ts → aiControllerView/aiControllerViewState.d.ts} +3 -3
- package/lib/view/{aiCfoView → aiControllerView}/epics/createSessionAndSubmitEpic.d.ts +2 -2
- package/lib/view/{aiCfoView → aiControllerView}/epics/createSessionAndSubmitEpic.js +9 -9
- package/lib/view/{aiCfoView → aiControllerView}/epics/createSessionEpic.d.ts +2 -2
- package/lib/view/{aiCfoView → aiControllerView}/epics/createSessionEpic.js +8 -8
- package/lib/view/{aiCfoView → aiControllerView}/epics/fetchChatHistoryEpic.d.ts +2 -2
- package/lib/view/{aiCfoView → aiControllerView}/epics/fetchChatHistoryEpic.js +9 -9
- package/lib/view/{aiCfoView → aiControllerView}/epics/fetchChatSessionsForUserEpic.d.ts +2 -2
- package/lib/view/{aiCfoView → aiControllerView}/epics/fetchChatSessionsForUserEpic.js +9 -8
- package/lib/view/{aiCfoView → aiControllerView}/epics/stopSubmitEpic.d.ts +2 -2
- package/lib/view/{aiCfoView → aiControllerView}/epics/stopSubmitEpic.js +11 -11
- package/lib/view/{aiCfoView → aiControllerView}/epics/stopSubmitQuestionEpic.d.ts +2 -2
- package/lib/view/{aiCfoView → aiControllerView}/epics/stopSubmitQuestionEpic.js +8 -8
- package/lib/view/{aiCfoView → aiControllerView}/epics/submitQuestionEpic.d.ts +2 -2
- package/lib/view/{aiCfoView → aiControllerView}/epics/submitQuestionEpic.js +10 -10
- package/lib/view/expenseAutomationView/epics/accountRecon/saveReconciliationReviewEpic.js +0 -2
- package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.d.ts +1 -1
- package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +5 -4
- package/lib/zeniAPI.d.ts +1 -1
- package/package.json +1 -1
- package/lib/entity/aiCfo/aiCfoReducer.d.ts +0 -45
- package/lib/entity/aiCfo/aiCfoSelector.d.ts +0 -14
- package/lib/entity/aiCfo/aiCfoState.d.ts +0 -88
- package/lib/entity/aiCfo/aiCfoState.js +0 -46
- package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +0 -73
- /package/lib/entity/{aiCfo/aiCfoPayload.js → aiController/aiControllerPayload.js} +0 -0
- /package/lib/view/{aiCfoView/aiCfoViewPayload.js → aiControllerView/aiControllerViewPayload.js} +0 -0
- /package/lib/view/{aiCfoView/aiCfoViewState.js → aiControllerView/aiControllerViewState.js} +0 -0
|
@@ -56,8 +56,6 @@ interface RecommendedActionPayload {
|
|
|
56
56
|
recommended_actions: string;
|
|
57
57
|
recommended_action_description: string;
|
|
58
58
|
recommended_transactions: RecommendedReviewTransactionPayload[];
|
|
59
|
-
plaid_confidence_score?: string | null;
|
|
60
|
-
zeni_confidence_score?: number | null;
|
|
61
59
|
}
|
|
62
60
|
export interface TransactionsToReviewPayload {
|
|
63
61
|
amount: number;
|
|
@@ -7,7 +7,7 @@ const zeniDayJS_1 = require("../../zeniDayJS");
|
|
|
7
7
|
const reconciliationTransaction_1 = require("../transaction/stateTypes/reconciliationTransaction");
|
|
8
8
|
const accountReconState_1 = require("./accountReconState");
|
|
9
9
|
const toTransactionsToReview = (payload, currencyPayload) => {
|
|
10
|
-
var _a, _b
|
|
10
|
+
var _a, _b;
|
|
11
11
|
return {
|
|
12
12
|
transactionId: payload.transaction_id,
|
|
13
13
|
transactionDirection: (0, reconciliationTransaction_1.toTransactionDirectionType)(payload.transaction_direction),
|
|
@@ -26,8 +26,6 @@ const toTransactionsToReview = (payload, currencyPayload) => {
|
|
|
26
26
|
: undefined,
|
|
27
27
|
recommendedAction: {
|
|
28
28
|
action: (0, accountReconState_1.toRecommendedActionCodeType)(payload.recommended_action.recommended_actions),
|
|
29
|
-
plaidConfidenceScore: (_c = payload.recommended_action.plaid_confidence_score) !== null && _c !== void 0 ? _c : null,
|
|
30
|
-
zeniConfidenceScore: (_d = payload.recommended_action.zeni_confidence_score) !== null && _d !== void 0 ? _d : null,
|
|
31
29
|
reason: payload.recommended_action.recommended_action_description,
|
|
32
30
|
recommendedTransactions: payload.recommended_action.recommended_transactions.map((transaction) => (0, exports.toRecommendedReviewTransaction)(transaction, currencyPayload)),
|
|
33
31
|
},
|
|
@@ -35,7 +33,6 @@ const toTransactionsToReview = (payload, currencyPayload) => {
|
|
|
35
33
|
};
|
|
36
34
|
exports.toTransactionsToReview = toTransactionsToReview;
|
|
37
35
|
const toTransactionsToReviewPayload = (payload) => {
|
|
38
|
-
var _a, _b;
|
|
39
36
|
return {
|
|
40
37
|
transaction_id: payload.transactionId,
|
|
41
38
|
transaction_direction: (0, reconciliationTransaction_1.toTransactionDirectionType)(payload.transactionDirection),
|
|
@@ -47,8 +44,6 @@ const toTransactionsToReviewPayload = (payload) => {
|
|
|
47
44
|
recommended_actions: (0, accountReconState_1.toRecommendedActionCodeType)(payload.recommendedAction.action),
|
|
48
45
|
recommended_action_description: payload.recommendedAction.reason,
|
|
49
46
|
recommended_transactions: payload.recommendedAction.recommendedTransactions.map((transaction) => (0, exports.toRecommendedReviewTransactionPayload)(transaction)),
|
|
50
|
-
plaid_confidence_score: (_a = payload.recommendedAction.plaidConfidenceScore) !== null && _a !== void 0 ? _a : null,
|
|
51
|
-
zeni_confidence_score: (_b = payload.recommendedAction.zeniConfidenceScore) !== null && _b !== void 0 ? _b : null,
|
|
52
47
|
},
|
|
53
48
|
};
|
|
54
49
|
};
|
|
@@ -78,8 +78,6 @@ export interface RecommendedAction {
|
|
|
78
78
|
action: RecommendedActionCodeType;
|
|
79
79
|
reason: string;
|
|
80
80
|
recommendedTransactions: RecommendedReviewTransaction[];
|
|
81
|
-
plaidConfidenceScore: string | null;
|
|
82
|
-
zeniConfidenceScore: number | null;
|
|
83
81
|
}
|
|
84
82
|
export interface RecommendedReviewTransaction {
|
|
85
83
|
confidenceScore: number;
|
|
@@ -13,15 +13,15 @@ export interface ChartVisualizationPayload {
|
|
|
13
13
|
y: string | string[];
|
|
14
14
|
lines?: string[] | null;
|
|
15
15
|
}
|
|
16
|
-
export interface
|
|
16
|
+
export interface AIControllerVisualizationPayload {
|
|
17
17
|
type: string | null;
|
|
18
18
|
data: TableVisualizationPayload | ChartVisualizationPayload | null;
|
|
19
19
|
}
|
|
20
|
-
export interface
|
|
20
|
+
export interface AIControllerAnswerPayload {
|
|
21
21
|
text: string;
|
|
22
22
|
state: string;
|
|
23
23
|
type: string;
|
|
24
|
-
visualization:
|
|
24
|
+
visualization: AIControllerVisualizationPayload | null;
|
|
25
25
|
metadata: Record<string, string>;
|
|
26
26
|
assumptions: string | null;
|
|
27
27
|
insights: string | null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ID } from '../../commonStateTypes/common';
|
|
2
|
+
import { ZeniDate } from '../../zeniDayJS';
|
|
3
|
+
import { AIControllerVisualizationPayload, ChatSessionPayload } from './aiControllerPayload';
|
|
4
|
+
import { AIControllerAnswerPayload, MessagePayload } from './aiControllerPayload';
|
|
5
|
+
import { AIControllerState, AIControllerVisualization } from './aiControllerState';
|
|
6
|
+
export declare const initialAIControllerState: AIControllerState;
|
|
7
|
+
export declare const toAIControllerVisualization: (visualization: AIControllerVisualizationPayload) => AIControllerVisualization | undefined;
|
|
8
|
+
export declare const setNewSession: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
9
|
+
chatSessionId: ID;
|
|
10
|
+
userId: ID;
|
|
11
|
+
createdAt: ZeniDate;
|
|
12
|
+
}, "aiController/setNewSession">, clearSession: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "aiController/clearSession">, setSessions: import("@reduxjs/toolkit").ActionCreatorWithPayload<ChatSessionPayload[], "aiController/setSessions">, setChatHistory: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
13
|
+
chatSessionId: ID;
|
|
14
|
+
history: MessagePayload[];
|
|
15
|
+
isPaginationComplete?: boolean;
|
|
16
|
+
}, "aiController/setChatHistory">, upsertAnswerPayload: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
17
|
+
chatSessionId: ID;
|
|
18
|
+
answerPayload: AIControllerAnswerPayload;
|
|
19
|
+
userId: ID;
|
|
20
|
+
questionAnswerId?: ID;
|
|
21
|
+
}, "aiController/upsertAnswerPayload">, upsertOrAddQuestionAnswerPayload: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
22
|
+
chatSessionId: ID;
|
|
23
|
+
questionAnswerId: ID;
|
|
24
|
+
question: {
|
|
25
|
+
questionId: ID;
|
|
26
|
+
text: string;
|
|
27
|
+
createdAt: ZeniDate;
|
|
28
|
+
};
|
|
29
|
+
answerPayload: AIControllerAnswerPayload;
|
|
30
|
+
userId: ID;
|
|
31
|
+
insertQuestionAnswer?: boolean;
|
|
32
|
+
}, "aiController/upsertOrAddQuestionAnswerPayload">, addQuestionPayload: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
33
|
+
chatSessionId: ID;
|
|
34
|
+
questionAnswerId: ID;
|
|
35
|
+
question: {
|
|
36
|
+
questionId: ID;
|
|
37
|
+
text: string;
|
|
38
|
+
createdAt: ZeniDate;
|
|
39
|
+
};
|
|
40
|
+
userId: ID;
|
|
41
|
+
}, "aiController/addQuestionPayload">, clearAIController: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"aiController/clearAIController">, deleteQuestion: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
42
|
+
chatSessionId: ID;
|
|
43
|
+
questionAnswerId: ID;
|
|
44
|
+
}, "aiController/deleteQuestion">;
|
|
45
|
+
declare const _default: import("redux").Reducer<AIControllerState>;
|
|
46
|
+
export default _default;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.deleteQuestion = exports.
|
|
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
|
-
const
|
|
8
|
-
exports.
|
|
9
|
-
|
|
7
|
+
const aiControllerState_1 = require("./aiControllerState");
|
|
8
|
+
exports.initialAIControllerState = {
|
|
9
|
+
aiControllerByChatSessionId: {},
|
|
10
10
|
partialQuestionAnswers: {},
|
|
11
11
|
};
|
|
12
12
|
// Utility: Merge two arrays of Q&A pairs, combining responses for the same question
|
|
@@ -32,7 +32,7 @@ function mergeQuestionAnswerPairs(existing, newQAs) {
|
|
|
32
32
|
// Convert back to array and sort by question creation time
|
|
33
33
|
return Array.from(merged.values()).sort((a, b) => a.question.createdAt.valueOf() - b.question.createdAt.valueOf());
|
|
34
34
|
}
|
|
35
|
-
// Utility: Convert chat history (array of MessagePayload) to
|
|
35
|
+
// Utility: Convert chat history (array of MessagePayload) to AIControllerQuestionWithAnswer[]
|
|
36
36
|
function chatHistoryToQA(history) {
|
|
37
37
|
var _a, _b, _c;
|
|
38
38
|
const questionGroups = new Map();
|
|
@@ -58,7 +58,7 @@ function chatHistoryToQA(history) {
|
|
|
58
58
|
group.responses.push(message);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
// Convert groups to
|
|
61
|
+
// Convert groups to AIControllerQuestionWithAnswer
|
|
62
62
|
const questionAnswerPairs = [];
|
|
63
63
|
for (const [messageId, group] of questionGroups.entries()) {
|
|
64
64
|
// Skip groups that don't have a question
|
|
@@ -69,7 +69,7 @@ function chatHistoryToQA(history) {
|
|
|
69
69
|
messageId: group.question.message_id,
|
|
70
70
|
chatSessionId: group.question.chat_session_id,
|
|
71
71
|
userId: group.question.user_id,
|
|
72
|
-
sender: (0,
|
|
72
|
+
sender: (0, aiControllerState_1.toMessageSender)(group.question.sender),
|
|
73
73
|
state: 'complete',
|
|
74
74
|
questionText: group.question.content,
|
|
75
75
|
createdAt: (0, zeniDayJS_1.date)(group.question.created_at),
|
|
@@ -78,7 +78,7 @@ function chatHistoryToQA(history) {
|
|
|
78
78
|
// Process each response for this question
|
|
79
79
|
for (const agentMessage of group.responses) {
|
|
80
80
|
try {
|
|
81
|
-
const parsedAgentMessage = (0,
|
|
81
|
+
const parsedAgentMessage = (0, aiControllerState_1.toMessageType)(agentMessage.message_type) === 'json'
|
|
82
82
|
? JSON.parse(agentMessage.content)
|
|
83
83
|
: {
|
|
84
84
|
text: agentMessage.content,
|
|
@@ -87,21 +87,21 @@ function chatHistoryToQA(history) {
|
|
|
87
87
|
visualization: null,
|
|
88
88
|
follow_up_questions: [],
|
|
89
89
|
};
|
|
90
|
-
const responseType = (0,
|
|
91
|
-
const responseState = (0,
|
|
90
|
+
const responseType = (0, aiControllerState_1.toAIControllerAnswerResponseType)(parsedAgentMessage.type);
|
|
91
|
+
const responseState = (0, aiControllerState_1.toAIControllerAnswerStateType)(parsedAgentMessage.state);
|
|
92
92
|
if (typeof parsedAgentMessage.text === 'string' &&
|
|
93
|
-
|
|
93
|
+
aiControllerState_1.ALL_AI_CONTROLLER_ANSWER_RESPONSE_TYPES.includes(responseType)) {
|
|
94
94
|
responses[responseType] = {
|
|
95
95
|
messageId: agentMessage.message_id,
|
|
96
96
|
chatSessionId: agentMessage.chat_session_id,
|
|
97
97
|
userId: agentMessage.user_id,
|
|
98
|
-
sender: (0,
|
|
98
|
+
sender: (0, aiControllerState_1.toMessageSender)(agentMessage.sender),
|
|
99
99
|
type: responseType,
|
|
100
100
|
state: responseState,
|
|
101
101
|
content: {
|
|
102
102
|
text: parsedAgentMessage.text,
|
|
103
103
|
visualization: parsedAgentMessage.visualization
|
|
104
|
-
? (0, exports.
|
|
104
|
+
? (0, exports.toAIControllerVisualization)(parsedAgentMessage.visualization)
|
|
105
105
|
: undefined,
|
|
106
106
|
followUpQuestions: Array.isArray(parsedAgentMessage.follow_up_questions)
|
|
107
107
|
? parsedAgentMessage.follow_up_questions
|
|
@@ -127,18 +127,18 @@ function chatHistoryToQA(history) {
|
|
|
127
127
|
// Sort by question creation time (oldest first)
|
|
128
128
|
return questionAnswerPairs.sort((a, b) => a.question.createdAt.valueOf() - b.question.createdAt.valueOf());
|
|
129
129
|
}
|
|
130
|
-
const
|
|
130
|
+
const toAIControllerVisualization = (visualization) => {
|
|
131
131
|
var _a;
|
|
132
132
|
if (visualization.type == null || visualization.data == null) {
|
|
133
133
|
return undefined;
|
|
134
134
|
}
|
|
135
135
|
return {
|
|
136
|
-
type: (_a = (0,
|
|
137
|
-
data:
|
|
136
|
+
type: (_a = (0, aiControllerState_1.toAIControllerVisualizationTypeStrict)(visualization.type)) !== null && _a !== void 0 ? _a : 'table',
|
|
137
|
+
data: toAIControllerVisualizationData(visualization.data),
|
|
138
138
|
};
|
|
139
139
|
};
|
|
140
|
-
exports.
|
|
141
|
-
const
|
|
140
|
+
exports.toAIControllerVisualization = toAIControllerVisualization;
|
|
141
|
+
const toAIControllerVisualizationData = (data) => {
|
|
142
142
|
var _a, _b;
|
|
143
143
|
if ('x' in data && 'y' in data) {
|
|
144
144
|
// Normalize y to always be an array
|
|
@@ -178,11 +178,13 @@ const toResponseBlockType = (answer, userId) => {
|
|
|
178
178
|
chatSessionId: chat_session_id,
|
|
179
179
|
userId,
|
|
180
180
|
sender: 'agent',
|
|
181
|
-
state: (0,
|
|
182
|
-
type: (0,
|
|
181
|
+
state: (0, aiControllerState_1.toAIControllerAnswerStateType)(state),
|
|
182
|
+
type: (0, aiControllerState_1.toAIControllerAnswerResponseType)(type),
|
|
183
183
|
content: {
|
|
184
184
|
text: text,
|
|
185
|
-
visualization: visualization != null
|
|
185
|
+
visualization: visualization != null
|
|
186
|
+
? (0, exports.toAIControllerVisualization)(visualization)
|
|
187
|
+
: undefined,
|
|
186
188
|
followUpQuestions: follow_up_questions !== null && follow_up_questions !== void 0 ? follow_up_questions : [],
|
|
187
189
|
assumptions: assumptions !== null && assumptions !== void 0 ? assumptions : '',
|
|
188
190
|
insights: insights !== null && insights !== void 0 ? insights : '',
|
|
@@ -191,13 +193,13 @@ const toResponseBlockType = (answer, userId) => {
|
|
|
191
193
|
createdAt: (0, zeniDayJS_1.date)(timestamp),
|
|
192
194
|
};
|
|
193
195
|
};
|
|
194
|
-
const
|
|
195
|
-
name: '
|
|
196
|
-
initialState: exports.
|
|
196
|
+
const aiController = (0, toolkit_1.createSlice)({
|
|
197
|
+
name: 'aiController',
|
|
198
|
+
initialState: exports.initialAIControllerState,
|
|
197
199
|
reducers: {
|
|
198
200
|
setNewSession(draft, action) {
|
|
199
201
|
const { chatSessionId, userId, createdAt } = action.payload;
|
|
200
|
-
draft.
|
|
202
|
+
draft.aiControllerByChatSessionId[chatSessionId] = {
|
|
201
203
|
chatSession: {
|
|
202
204
|
chatSessionId,
|
|
203
205
|
userId,
|
|
@@ -213,8 +215,8 @@ const aiCfo = (0, toolkit_1.createSlice)({
|
|
|
213
215
|
action.payload.forEach((chatSessionPayload) => {
|
|
214
216
|
const { chat_session_id } = chatSessionPayload;
|
|
215
217
|
// This is to prevent overwriting the session if it is already in state
|
|
216
|
-
if (draft.
|
|
217
|
-
draft.
|
|
218
|
+
if (draft.aiControllerByChatSessionId[chat_session_id] == null) {
|
|
219
|
+
draft.aiControllerByChatSessionId[chat_session_id] = {
|
|
218
220
|
chatSession: toChatSession(chatSessionPayload),
|
|
219
221
|
questionAnswers: [],
|
|
220
222
|
};
|
|
@@ -225,11 +227,11 @@ const aiCfo = (0, toolkit_1.createSlice)({
|
|
|
225
227
|
},
|
|
226
228
|
setChatHistory(draft, action) {
|
|
227
229
|
const { chatSessionId, history, isPaginationComplete = false, } = action.payload;
|
|
228
|
-
if (draft.
|
|
230
|
+
if (draft.aiControllerByChatSessionId[chatSessionId] == null) {
|
|
229
231
|
console.warn(`session with id ${chatSessionId} not found in setChatHistory`);
|
|
230
232
|
return;
|
|
231
233
|
}
|
|
232
|
-
const session = draft.
|
|
234
|
+
const session = draft.aiControllerByChatSessionId[chatSessionId];
|
|
233
235
|
// Check if we have an existing partial Q&A pair for this session
|
|
234
236
|
const existingPartialQA = draft.partialQuestionAnswers[chatSessionId];
|
|
235
237
|
// Process new messages into Q&A pairs
|
|
@@ -364,13 +366,13 @@ const aiCfo = (0, toolkit_1.createSlice)({
|
|
|
364
366
|
*/
|
|
365
367
|
upsertOrAddQuestionAnswerPayload(draft, action) {
|
|
366
368
|
const { chatSessionId, questionAnswerId, question: { questionId, createdAt, text }, answerPayload, userId, insertQuestionAnswer, } = action.payload;
|
|
367
|
-
const session = draft.
|
|
369
|
+
const session = draft.aiControllerByChatSessionId[chatSessionId];
|
|
368
370
|
if (session == null) {
|
|
369
371
|
console.warn(`session with id ${chatSessionId} not found `);
|
|
370
372
|
return;
|
|
371
373
|
}
|
|
372
374
|
let qa = session.questionAnswers.find((qa) => qa.questionAnswerId === questionAnswerId);
|
|
373
|
-
const responseType = (0,
|
|
375
|
+
const responseType = (0, aiControllerState_1.toAIControllerAnswerResponseTypeStrict)(answerPayload.type);
|
|
374
376
|
if (insertQuestionAnswer === true && qa == null) {
|
|
375
377
|
// Add new Q/A
|
|
376
378
|
qa = {
|
|
@@ -397,7 +399,7 @@ const aiCfo = (0, toolkit_1.createSlice)({
|
|
|
397
399
|
},
|
|
398
400
|
upsertAnswerPayload(draft, action) {
|
|
399
401
|
const { chatSessionId, answerPayload, questionAnswerId, userId } = action.payload;
|
|
400
|
-
const session = draft.
|
|
402
|
+
const session = draft.aiControllerByChatSessionId[chatSessionId];
|
|
401
403
|
if (session == null) {
|
|
402
404
|
console.warn(`session with id ${chatSessionId} not found in upsertAnswerPayload`);
|
|
403
405
|
return;
|
|
@@ -405,7 +407,7 @@ const aiCfo = (0, toolkit_1.createSlice)({
|
|
|
405
407
|
const latestQA = questionAnswerId != null
|
|
406
408
|
? session.questionAnswers.find((questionAnswer) => questionAnswer.questionAnswerId === questionAnswerId)
|
|
407
409
|
: session.questionAnswers.slice(-1)[0];
|
|
408
|
-
const responseType = (0,
|
|
410
|
+
const responseType = (0, aiControllerState_1.toAIControllerAnswerResponseTypeStrict)(answerPayload.type);
|
|
409
411
|
if (latestQA != null && responseType != null) {
|
|
410
412
|
// Directly mutate the responses property
|
|
411
413
|
latestQA.responses[responseType] = toResponseBlockType(answerPayload, userId);
|
|
@@ -413,7 +415,7 @@ const aiCfo = (0, toolkit_1.createSlice)({
|
|
|
413
415
|
},
|
|
414
416
|
addQuestionPayload(draft, action) {
|
|
415
417
|
const { chatSessionId, questionAnswerId, question: { questionId, createdAt, text }, userId, } = action.payload;
|
|
416
|
-
const session = draft.
|
|
418
|
+
const session = draft.aiControllerByChatSessionId[chatSessionId];
|
|
417
419
|
if (session == null) {
|
|
418
420
|
console.warn(`session with id ${chatSessionId} not found in addQuestionPayload`);
|
|
419
421
|
return;
|
|
@@ -440,19 +442,19 @@ const aiCfo = (0, toolkit_1.createSlice)({
|
|
|
440
442
|
clearSession(draft, action) {
|
|
441
443
|
var _a;
|
|
442
444
|
const sessionId = action.payload;
|
|
443
|
-
delete draft.
|
|
445
|
+
delete draft.aiControllerByChatSessionId[sessionId];
|
|
444
446
|
// Clear partial Q&A if it belongs to the cleared session
|
|
445
447
|
if (((_a = draft.partialQuestionAnswers) === null || _a === void 0 ? void 0 : _a[sessionId]) != null) {
|
|
446
448
|
draft.partialQuestionAnswers[sessionId] = undefined;
|
|
447
449
|
}
|
|
448
450
|
},
|
|
449
|
-
|
|
450
|
-
draft.
|
|
451
|
+
clearAIController(draft) {
|
|
452
|
+
draft.aiControllerByChatSessionId = {};
|
|
451
453
|
draft.partialQuestionAnswers = {};
|
|
452
454
|
},
|
|
453
455
|
deleteQuestion(draft, action) {
|
|
454
456
|
const { chatSessionId, questionAnswerId } = action.payload;
|
|
455
|
-
const session = draft.
|
|
457
|
+
const session = draft.aiControllerByChatSessionId[chatSessionId];
|
|
456
458
|
if (session == null) {
|
|
457
459
|
console.warn(`session with id ${chatSessionId} not found in deleteQuestion`);
|
|
458
460
|
return;
|
|
@@ -473,5 +475,5 @@ const toChatSession = (chatSessionPayload) => {
|
|
|
473
475
|
createdAt: (0, zeniDayJS_1.date)(created_at),
|
|
474
476
|
};
|
|
475
477
|
};
|
|
476
|
-
_a =
|
|
477
|
-
exports.default =
|
|
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;
|
|
479
|
+
exports.default = aiController.reducer;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ID } from '../../commonStateTypes/common';
|
|
2
|
+
import { AIControllerQuestionWithAnswer, AIControllerState } from './aiControllerState';
|
|
3
|
+
import { ChatSession } from './aiControllerState';
|
|
4
|
+
export declare function getAllQuestionAnswersForChatSession(state: AIControllerState, chatSessionId: ID): AIControllerQuestionWithAnswer[];
|
|
5
|
+
export declare function getQuestionAnswerByIdForChatSession(state: AIControllerState, chatSessionId: ID, questionAnswerId: ID): AIControllerQuestionWithAnswer | undefined;
|
|
6
|
+
export declare function getAllQuestionsForChatSession(state: AIControllerState, chatSessionId: ID): string[];
|
|
7
|
+
export interface AIControllerSelectorView {
|
|
8
|
+
allSessionsWithOrderedQuestionAnswers: ChatSessionWithOrderedQuestionAnswers[];
|
|
9
|
+
}
|
|
10
|
+
export interface ChatSessionWithOrderedQuestionAnswers {
|
|
11
|
+
chatSession: ChatSession;
|
|
12
|
+
questionAnswers: AIControllerQuestionWithAnswer[];
|
|
13
|
+
}
|
|
14
|
+
export declare function getAIControllerSelectorView(state: AIControllerState): AIControllerSelectorView;
|
|
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getAllQuestionAnswersForChatSession = getAllQuestionAnswersForChatSession;
|
|
4
4
|
exports.getQuestionAnswerByIdForChatSession = getQuestionAnswerByIdForChatSession;
|
|
5
5
|
exports.getAllQuestionsForChatSession = getAllQuestionsForChatSession;
|
|
6
|
-
exports.
|
|
6
|
+
exports.getAIControllerSelectorView = getAIControllerSelectorView;
|
|
7
7
|
function getAllQuestionAnswersForChatSession(state, chatSessionId) {
|
|
8
8
|
var _a, _b;
|
|
9
|
-
const arr = (_b = (_a = state.
|
|
9
|
+
const arr = (_b = (_a = state.aiControllerByChatSessionId[chatSessionId]) === null || _a === void 0 ? void 0 : _a.questionAnswers) !== null && _b !== void 0 ? _b : [];
|
|
10
10
|
return arr
|
|
11
11
|
.slice()
|
|
12
12
|
.sort((a, b) => a.question.createdAt.valueOf() - b.question.createdAt.valueOf());
|
|
13
13
|
}
|
|
14
14
|
function getQuestionAnswerByIdForChatSession(state, chatSessionId, questionAnswerId) {
|
|
15
15
|
var _a;
|
|
16
|
-
const arr = (_a = state.
|
|
16
|
+
const arr = (_a = state.aiControllerByChatSessionId[chatSessionId]) === null || _a === void 0 ? void 0 : _a.questionAnswers;
|
|
17
17
|
if (arr == null) {
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
@@ -21,7 +21,7 @@ function getQuestionAnswerByIdForChatSession(state, chatSessionId, questionAnswe
|
|
|
21
21
|
}
|
|
22
22
|
function getAllQuestionsForChatSession(state, chatSessionId) {
|
|
23
23
|
var _a;
|
|
24
|
-
const arr = (_a = state.
|
|
24
|
+
const arr = (_a = state.aiControllerByChatSessionId[chatSessionId]) === null || _a === void 0 ? void 0 : _a.questionAnswers;
|
|
25
25
|
if (arr == null) {
|
|
26
26
|
return [];
|
|
27
27
|
}
|
|
@@ -30,8 +30,8 @@ function getAllQuestionsForChatSession(state, chatSessionId) {
|
|
|
30
30
|
.sort((first, second) => first.question.createdAt.valueOf() - second.question.createdAt.valueOf())
|
|
31
31
|
.map((qa) => qa.question.questionText);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
const allSessionsWithOrderedQuestionAnswers = Object.values(state.
|
|
33
|
+
function getAIControllerSelectorView(state) {
|
|
34
|
+
const allSessionsWithOrderedQuestionAnswers = Object.values(state.aiControllerByChatSessionId)
|
|
35
35
|
.map((sessionWithQAs) => (Object.assign(Object.assign({}, sessionWithQAs), { questionAnswers: Array.isArray(sessionWithQAs.questionAnswers)
|
|
36
36
|
? sessionWithQAs.questionAnswers
|
|
37
37
|
.slice()
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ID } from '../../commonStateTypes/common';
|
|
2
|
+
import { ZeniDate } from '../../zeniDayJS';
|
|
3
|
+
export interface AIControllerAnswerParagraph {
|
|
4
|
+
text: string;
|
|
5
|
+
orderedList?: Array<{
|
|
6
|
+
text: string;
|
|
7
|
+
subText?: string;
|
|
8
|
+
unorderedList?: string[];
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export declare const ALL_AI_CONTROLLER_CHARTS_TYPES: readonly ["bar_chart", "pie_chart", "line_chart"];
|
|
12
|
+
export declare const ALL_AI_CONTROLLER_VISUALIZATION_TYPES: readonly ["bar_chart", "pie_chart", "line_chart", "table"];
|
|
13
|
+
export declare const toAIControllerVisualizationType: (v: string) => "bar_chart" | "pie_chart" | "line_chart" | "table";
|
|
14
|
+
export declare const toAIControllerVisualizationTypeStrict: (v: string) => "bar_chart" | "pie_chart" | "line_chart" | "table" | undefined;
|
|
15
|
+
export type AIControllerVisualizationType = ReturnType<typeof toAIControllerVisualizationType>;
|
|
16
|
+
export declare const toAIControllerChartType: (v: string) => "bar_chart" | "pie_chart" | "line_chart";
|
|
17
|
+
export declare const toAIControllerChartTypeStrict: (v: string) => "bar_chart" | "pie_chart" | "line_chart" | undefined;
|
|
18
|
+
export type AIControllerChartType = ReturnType<typeof toAIControllerChartType>;
|
|
19
|
+
export declare const ALL_AI_CONTROLLER_ANSWER_STATE_TYPES: readonly ["complete", "partial"];
|
|
20
|
+
export declare const ALL_AI_CONTROLLER_ANSWER_RESPONSE_TYPES: readonly ["analysis", "answer", "reasoning", "thought"];
|
|
21
|
+
export declare const toAIControllerAnswerStateType: (v: string) => "complete" | "partial";
|
|
22
|
+
export declare const toAIControllerAnswerResponseType: (v: string) => "analysis" | "answer" | "reasoning" | "thought";
|
|
23
|
+
export declare const toAIControllerAnswerStateTypeStrict: (v: string) => "complete" | "partial" | undefined;
|
|
24
|
+
export declare const toAIControllerAnswerResponseTypeStrict: (v: string) => "analysis" | "answer" | "reasoning" | "thought" | undefined;
|
|
25
|
+
export type AIControllerAnswerStateType = ReturnType<typeof toAIControllerAnswerStateType>;
|
|
26
|
+
export type AIControllerAnswerResponseType = ReturnType<typeof toAIControllerAnswerResponseType>;
|
|
27
|
+
export interface TableVisualization {
|
|
28
|
+
rows: string[][];
|
|
29
|
+
columns: string[];
|
|
30
|
+
}
|
|
31
|
+
export interface ChartVisualization {
|
|
32
|
+
values: Array<Record<string, string | number>>;
|
|
33
|
+
x: string;
|
|
34
|
+
y: string[];
|
|
35
|
+
lines?: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface AIControllerVisualization {
|
|
38
|
+
type: AIControllerVisualizationType;
|
|
39
|
+
data: TableVisualization | ChartVisualization;
|
|
40
|
+
}
|
|
41
|
+
export declare const toMessageSender: (v: string) => "user" | "agent";
|
|
42
|
+
export declare const toMessageType: (v: string) => "plain_text" | "json";
|
|
43
|
+
export declare const toMessageSenderStrict: (v: string) => "user" | "agent" | undefined;
|
|
44
|
+
export declare const toMessageTypeStrict: (v: string) => "plain_text" | "json" | undefined;
|
|
45
|
+
export type MessageSender = ReturnType<typeof toMessageSender>;
|
|
46
|
+
export type MessageType = ReturnType<typeof toMessageType>;
|
|
47
|
+
export interface ResponseBlockBase {
|
|
48
|
+
messageId: ID;
|
|
49
|
+
state: AIControllerAnswerStateType;
|
|
50
|
+
createdAt: ZeniDate;
|
|
51
|
+
chatSessionId: ID;
|
|
52
|
+
userId: ID;
|
|
53
|
+
sender: MessageSender;
|
|
54
|
+
}
|
|
55
|
+
export interface AnswerContentBlockBase {
|
|
56
|
+
text: string;
|
|
57
|
+
followUpQuestions: string[];
|
|
58
|
+
assumptions: string;
|
|
59
|
+
insights: string;
|
|
60
|
+
summarizedTitle?: string;
|
|
61
|
+
visualization?: AIControllerVisualization;
|
|
62
|
+
}
|
|
63
|
+
export interface QuestionContentBlockBase extends ResponseBlockBase {
|
|
64
|
+
questionText: string;
|
|
65
|
+
}
|
|
66
|
+
export interface ResponseBlockType extends ResponseBlockBase {
|
|
67
|
+
content: AnswerContentBlockBase;
|
|
68
|
+
type: AIControllerAnswerResponseType;
|
|
69
|
+
}
|
|
70
|
+
export interface AIControllerQuestionWithAnswer {
|
|
71
|
+
questionAnswerId: ID;
|
|
72
|
+
question: QuestionContentBlockBase;
|
|
73
|
+
responses: Partial<Record<AIControllerAnswerResponseType, ResponseBlockType>>;
|
|
74
|
+
}
|
|
75
|
+
export interface ChatSession {
|
|
76
|
+
chatSessionId: ID;
|
|
77
|
+
userId: ID;
|
|
78
|
+
createdAt: ZeniDate;
|
|
79
|
+
chatSessionSummary?: string;
|
|
80
|
+
}
|
|
81
|
+
export interface ChatSessionWithMessages {
|
|
82
|
+
chatSession: ChatSession;
|
|
83
|
+
questionAnswers: AIControllerQuestionWithAnswer[];
|
|
84
|
+
}
|
|
85
|
+
export interface AIControllerState {
|
|
86
|
+
aiControllerByChatSessionId: Record<ID, ChatSessionWithMessages>;
|
|
87
|
+
partialQuestionAnswers: Record<ID, AIControllerQuestionWithAnswer | undefined>;
|
|
88
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toMessageTypeStrict = exports.toMessageSenderStrict = exports.toMessageType = exports.toMessageSender = exports.toAIControllerAnswerResponseTypeStrict = exports.toAIControllerAnswerStateTypeStrict = exports.toAIControllerAnswerResponseType = exports.toAIControllerAnswerStateType = exports.ALL_AI_CONTROLLER_ANSWER_RESPONSE_TYPES = exports.ALL_AI_CONTROLLER_ANSWER_STATE_TYPES = exports.toAIControllerChartTypeStrict = exports.toAIControllerChartType = exports.toAIControllerVisualizationTypeStrict = exports.toAIControllerVisualizationType = exports.ALL_AI_CONTROLLER_VISUALIZATION_TYPES = exports.ALL_AI_CONTROLLER_CHARTS_TYPES = void 0;
|
|
4
|
+
const stringToUnion_1 = require("../../commonStateTypes/stringToUnion");
|
|
5
|
+
exports.ALL_AI_CONTROLLER_CHARTS_TYPES = [
|
|
6
|
+
'bar_chart',
|
|
7
|
+
'pie_chart',
|
|
8
|
+
'line_chart',
|
|
9
|
+
];
|
|
10
|
+
exports.ALL_AI_CONTROLLER_VISUALIZATION_TYPES = [
|
|
11
|
+
...exports.ALL_AI_CONTROLLER_CHARTS_TYPES,
|
|
12
|
+
'table',
|
|
13
|
+
];
|
|
14
|
+
const toAIControllerVisualizationType = (v) => (0, stringToUnion_1.stringToUnion)(v, exports.ALL_AI_CONTROLLER_VISUALIZATION_TYPES);
|
|
15
|
+
exports.toAIControllerVisualizationType = toAIControllerVisualizationType;
|
|
16
|
+
const toAIControllerVisualizationTypeStrict = (v) => (0, stringToUnion_1.stringToUnionStrict)(v, exports.ALL_AI_CONTROLLER_VISUALIZATION_TYPES);
|
|
17
|
+
exports.toAIControllerVisualizationTypeStrict = toAIControllerVisualizationTypeStrict;
|
|
18
|
+
const toAIControllerChartType = (v) => (0, stringToUnion_1.stringToUnion)(v, exports.ALL_AI_CONTROLLER_CHARTS_TYPES);
|
|
19
|
+
exports.toAIControllerChartType = toAIControllerChartType;
|
|
20
|
+
const toAIControllerChartTypeStrict = (v) => (0, stringToUnion_1.stringToUnionStrict)(v, exports.ALL_AI_CONTROLLER_CHARTS_TYPES);
|
|
21
|
+
exports.toAIControllerChartTypeStrict = toAIControllerChartTypeStrict;
|
|
22
|
+
exports.ALL_AI_CONTROLLER_ANSWER_STATE_TYPES = [
|
|
23
|
+
'complete',
|
|
24
|
+
'partial',
|
|
25
|
+
];
|
|
26
|
+
exports.ALL_AI_CONTROLLER_ANSWER_RESPONSE_TYPES = [
|
|
27
|
+
'analysis',
|
|
28
|
+
'answer',
|
|
29
|
+
'reasoning',
|
|
30
|
+
'thought',
|
|
31
|
+
];
|
|
32
|
+
const toAIControllerAnswerStateType = (v) => (0, stringToUnion_1.stringToUnion)(v, exports.ALL_AI_CONTROLLER_ANSWER_STATE_TYPES);
|
|
33
|
+
exports.toAIControllerAnswerStateType = toAIControllerAnswerStateType;
|
|
34
|
+
const toAIControllerAnswerResponseType = (v) => (0, stringToUnion_1.stringToUnion)(v, exports.ALL_AI_CONTROLLER_ANSWER_RESPONSE_TYPES);
|
|
35
|
+
exports.toAIControllerAnswerResponseType = toAIControllerAnswerResponseType;
|
|
36
|
+
const toAIControllerAnswerStateTypeStrict = (v) => (0, stringToUnion_1.stringToUnionStrict)(v, exports.ALL_AI_CONTROLLER_ANSWER_STATE_TYPES);
|
|
37
|
+
exports.toAIControllerAnswerStateTypeStrict = toAIControllerAnswerStateTypeStrict;
|
|
38
|
+
const toAIControllerAnswerResponseTypeStrict = (v) => (0, stringToUnion_1.stringToUnionStrict)(v, exports.ALL_AI_CONTROLLER_ANSWER_RESPONSE_TYPES);
|
|
39
|
+
exports.toAIControllerAnswerResponseTypeStrict = toAIControllerAnswerResponseTypeStrict;
|
|
40
|
+
const ALL_MESSAGE_SENDERS = ['user', 'agent'];
|
|
41
|
+
const ALL_MESSAGE_TYPES = ['plain_text', 'json'];
|
|
42
|
+
const toMessageSender = (v) => (0, stringToUnion_1.stringToUnion)(v, ALL_MESSAGE_SENDERS);
|
|
43
|
+
exports.toMessageSender = toMessageSender;
|
|
44
|
+
const toMessageType = (v) => (0, stringToUnion_1.stringToUnion)(v, ALL_MESSAGE_TYPES);
|
|
45
|
+
exports.toMessageType = toMessageType;
|
|
46
|
+
const toMessageSenderStrict = (v) => (0, stringToUnion_1.stringToUnionStrict)(v, ALL_MESSAGE_SENDERS);
|
|
47
|
+
exports.toMessageSenderStrict = toMessageSenderStrict;
|
|
48
|
+
const toMessageTypeStrict = (v) => (0, stringToUnion_1.stringToUnionStrict)(v, ALL_MESSAGE_TYPES);
|
|
49
|
+
exports.toMessageTypeStrict = toMessageTypeStrict;
|
|
@@ -66,7 +66,7 @@ interface CardStatus {
|
|
|
66
66
|
code: CardStatusCodeType;
|
|
67
67
|
name: string;
|
|
68
68
|
}
|
|
69
|
-
export declare const toCardStatusCodeType: (v: string) => "
|
|
69
|
+
export declare const toCardStatusCodeType: (v: string) => "active" | "inactive" | "stolen" | "lost" | "frozen" | "closed_by_customer" | "suspected_fraud" | "request_on_hold";
|
|
70
70
|
export type CardStatusCodeType = ReturnType<typeof toCardStatusCodeType>;
|
|
71
71
|
export interface ValidThru {
|
|
72
72
|
month: number;
|
|
@@ -26,7 +26,6 @@ const ALL_CARD_STATUS_CODE = [
|
|
|
26
26
|
'closed_by_customer',
|
|
27
27
|
'suspected_fraud',
|
|
28
28
|
'request_on_hold',
|
|
29
|
-
'pending',
|
|
30
29
|
];
|
|
31
30
|
const toCardStatusCodeType = (v) => (0, stringToUnion_1.stringToUnion)(v, ALL_CARD_STATUS_CODE);
|
|
32
31
|
exports.toCardStatusCodeType = toCardStatusCodeType;
|