@zeniai/client-epic-state 5.3.18 → 5.3.20

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.
Files changed (78) hide show
  1. package/lib/commonStateTypes/coaBalance/coaBalance.d.ts +9 -0
  2. package/lib/commonStateTypes/coaBalance/coaBalance.js +11 -0
  3. package/lib/entity/tenant/epic/fetchAllTenantsEpic.d.ts +2 -4
  4. package/lib/entity/tenant/epic/fetchAllTenantsEpic.js +50 -42
  5. package/lib/entity/tenant/tenantPayload.d.ts +17 -1
  6. package/lib/entity/tenant/tenantReducer.d.ts +7 -2
  7. package/lib/entity/tenant/tenantReducer.js +48 -19
  8. package/lib/entity/tenant/tenantSelector.d.ts +26 -6
  9. package/lib/entity/tenant/tenantSelector.js +116 -93
  10. package/lib/entity/tenant/tenantState.d.ts +10 -0
  11. package/lib/epic.d.ts +2 -1
  12. package/lib/epic.js +3 -0
  13. package/lib/esm/commonStateTypes/coaBalance/coaBalance.js +10 -0
  14. package/lib/esm/entity/tenant/epic/fetchAllTenantsEpic.js +53 -45
  15. package/lib/esm/entity/tenant/tenantReducer.js +46 -17
  16. package/lib/esm/entity/tenant/tenantSelector.js +112 -92
  17. package/lib/esm/epic.js +4 -1
  18. package/lib/esm/index.js +7 -7
  19. package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +65 -3
  20. package/lib/esm/view/aiCfoView/aiCfoViewSelector.js +25 -0
  21. package/lib/esm/view/aiCfoView/epics/transcribeAudioEpic.js +60 -0
  22. package/lib/esm/view/balanceSheet/balanceSheetForTimeframeEpic.js +9 -4
  23. package/lib/esm/view/balanceSheet/balanceSheetReducer.js +2 -0
  24. package/lib/esm/view/cashFlow/cashFlowForTimeframeEpic.js +11 -5
  25. package/lib/esm/view/cashFlow/cashFlowReducer.js +2 -0
  26. package/lib/esm/view/dashboard/dashboardEpic.js +0 -4
  27. package/lib/esm/view/dashboard/dashboardSelector.js +2 -3
  28. package/lib/esm/view/financeStatement/financeStatementEpic.js +1 -5
  29. package/lib/esm/view/financeStatement/financeStatementSelector.js +18 -0
  30. package/lib/esm/view/people/peoplePageEpic.js +0 -4
  31. package/lib/esm/view/profitAndLoss/profitAndLossForTimeframeEpic.js +9 -4
  32. package/lib/esm/view/profitAndLoss/profitAndLossReducer.js +5 -1
  33. package/lib/esm/view/spendManagement/reimbursement/editRemiView/editRemiViewReducer.js +23 -3
  34. package/lib/esm/view/spendManagement/reimbursement/editRemiView/epics/fetchRemiAndInitializeLocalStoreEpic.js +17 -4
  35. package/lib/esm/view/spendManagement/reimbursement/remiDetailView/epics/fetchRemiDetailEpic.js +1 -1
  36. package/lib/esm/view/transactionList/filterTransactionsByTimePeriod.js +18 -0
  37. package/lib/esm/view/transactionList/transactionListByAccountSelector.js +2 -1
  38. package/lib/esm/view/transactionList/transactionListByCategoryTypeSelector.js +2 -1
  39. package/lib/esm/view/transactionList/transactionListByClassSelector.js +2 -1
  40. package/lib/esm/view/transactionList/transactionListByProjectSelector.js +2 -1
  41. package/lib/index.d.ts +8 -8
  42. package/lib/index.js +56 -46
  43. package/lib/view/aiCfoView/aiCfoViewPayload.d.ts +20 -0
  44. package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +2 -2
  45. package/lib/view/aiCfoView/aiCfoViewReducer.js +66 -4
  46. package/lib/view/aiCfoView/aiCfoViewSelector.d.ts +8 -1
  47. package/lib/view/aiCfoView/aiCfoViewSelector.js +27 -0
  48. package/lib/view/aiCfoView/aiCfoViewState.d.ts +9 -0
  49. package/lib/view/aiCfoView/epics/transcribeAudioEpic.d.ts +19 -0
  50. package/lib/view/aiCfoView/epics/transcribeAudioEpic.js +64 -0
  51. package/lib/view/balanceSheet/balanceSheetForTimeframeEpic.js +8 -3
  52. package/lib/view/balanceSheet/balanceSheetReducer.js +2 -0
  53. package/lib/view/balanceSheet/balanceSheetState.d.ts +2 -0
  54. package/lib/view/cashFlow/cashFlowForTimeframeEpic.js +10 -4
  55. package/lib/view/cashFlow/cashFlowReducer.js +2 -0
  56. package/lib/view/cashFlow/cashFlowState.d.ts +2 -0
  57. package/lib/view/dashboard/dashboardEpic.js +0 -4
  58. package/lib/view/dashboard/dashboardSelector.d.ts +0 -2
  59. package/lib/view/dashboard/dashboardSelector.js +1 -2
  60. package/lib/view/financeStatement/financeStatementEpic.js +1 -5
  61. package/lib/view/financeStatement/financeStatementSelector.d.ts +8 -0
  62. package/lib/view/financeStatement/financeStatementSelector.js +18 -0
  63. package/lib/view/people/peoplePageEpic.js +0 -4
  64. package/lib/view/profitAndLoss/profitAndLossForTimeframeEpic.js +8 -3
  65. package/lib/view/profitAndLoss/profitAndLossReducer.js +5 -1
  66. package/lib/view/profitAndLoss/profitAndLossState.d.ts +2 -1
  67. package/lib/view/spendManagement/reimbursement/editRemiView/editRemiViewReducer.d.ts +7 -2
  68. package/lib/view/spendManagement/reimbursement/editRemiView/editRemiViewReducer.js +24 -4
  69. package/lib/view/spendManagement/reimbursement/editRemiView/epics/fetchRemiAndInitializeLocalStoreEpic.d.ts +7 -4
  70. package/lib/view/spendManagement/reimbursement/editRemiView/epics/fetchRemiAndInitializeLocalStoreEpic.js +15 -1
  71. package/lib/view/spendManagement/reimbursement/remiDetailView/epics/fetchRemiDetailEpic.js +1 -1
  72. package/lib/view/transactionList/filterTransactionsByTimePeriod.d.ts +15 -0
  73. package/lib/view/transactionList/filterTransactionsByTimePeriod.js +22 -0
  74. package/lib/view/transactionList/transactionListByAccountSelector.js +2 -1
  75. package/lib/view/transactionList/transactionListByCategoryTypeSelector.js +2 -1
  76. package/lib/view/transactionList/transactionListByClassSelector.js +2 -1
  77. package/lib/view/transactionList/transactionListByProjectSelector.js +2 -1
  78. package/package.json +1 -1
@@ -12,6 +12,26 @@ export interface SubmitFeedbackPayload {
12
12
  model?: string;
13
13
  questionText?: string;
14
14
  }
15
+ export interface TranscribeAudioPayload {
16
+ /** Recorded audio, already in a format the transcription model accepts. */
17
+ audio: Blob;
18
+ /**
19
+ * Session the recording was made in. Epics outlive the component, so without
20
+ * this a transcript that lands after the user switches sessions would append
21
+ * to whichever composer is open by then.
22
+ */
23
+ chatSessionId?: ID;
24
+ /** BCP-47 dictation language. Omitted means the model auto-detects. */
25
+ language?: string;
26
+ }
27
+ export interface TranscribeAudioSuccessPayload {
28
+ transcript: string;
29
+ chatSessionId?: ID;
30
+ }
31
+ /** Shape of the /1.0/transcriptions response body. */
32
+ export interface TranscriptionResponseData {
33
+ transcript: string;
34
+ }
15
35
  export type ContextStatus = 'NONE' | 'NOT_FOUND' | 'PERMISSION_DENIED' | 'SUCCESS';
16
36
  export interface CreateSessionResponseData {
17
37
  chat_session_id: string;
@@ -4,7 +4,7 @@ import { PageToken } from '../../commonStateTypes/viewAndReport/viewAndReport';
4
4
  import { ChatSessionPayload } from '../../entity/aiCfo/aiCfoPayload';
5
5
  import { AiCfoAnswerResponseType } from '../../entity/aiCfo/aiCfoState';
6
6
  import { ZeniAPIStatus } from '../../responsePayload';
7
- import { ContextStatus, FeedbackType, SubmitFeedbackPayload } from './aiCfoViewPayload';
7
+ import { ContextStatus, FeedbackType, SubmitFeedbackPayload, TranscribeAudioPayload, TranscribeAudioSuccessPayload } from './aiCfoViewPayload';
8
8
  import { AiCfoViewState, Routine, RoutineDraft, RoutineRun, Skill, SkillDetail, SkillDraft, SkillVersion, SkillVisibility } from './aiCfoViewState';
9
9
  export declare const initialAiCfoViewState: AiCfoViewState;
10
10
  export declare const acceptMasterTOS: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[userRoleId: string], {
@@ -220,7 +220,7 @@ export declare const acceptMasterTOS: import("@reduxjs/toolkit").ActionCreatorWi
220
220
  }, "aiCfoView/submitQuestion", never, never>, submitQuestionFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
221
221
  error: ZeniAPIStatus;
222
222
  sessionId: ID;
223
- }, "aiCfoView/submitQuestionFailure">, submitQuestionSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "aiCfoView/submitQuestionSuccess">, updateAiCfoViewScrollPosition: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, "aiCfoView/updateAiCfoViewScrollPosition">, updateCotCollapsedState: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
223
+ }, "aiCfoView/submitQuestionFailure">, submitQuestionSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "aiCfoView/submitQuestionSuccess">, transcribeAudio: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[audio: Blob, language?: string | undefined, chatSessionId?: string | undefined], TranscribeAudioPayload, "aiCfoView/transcribeAudio", never, never>, transcribeAudioFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "aiCfoView/transcribeAudioFailure">, transcribeAudioSuccess: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[transcript: string, chatSessionId?: string | undefined], TranscribeAudioSuccessPayload, "aiCfoView/transcribeAudioSuccess", never, never>, updateAiCfoViewScrollPosition: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, "aiCfoView/updateAiCfoViewScrollPosition">, updateCotCollapsedState: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
224
224
  isCollapsed: boolean;
225
225
  questionAnswerId: ID;
226
226
  }, "aiCfoView/updateCotCollapsedState">, updateCurrentInput: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "aiCfoView/updateCurrentInput">, updateResponseState: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
@@ -2,7 +2,7 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.fetchSkillVersionBodySuccess = exports.fetchSkillVersionBodyFailure = exports.fetchSkillVersionBody = exports.fetchSkillsSuccess = exports.fetchSkillsFailure = exports.fetchSkills = exports.fetchSkillDetailSuccess = exports.fetchSkillDetailFailure = exports.fetchSkillDetail = exports.fetchRoutinesSuccess = exports.fetchRoutinesFailure = exports.fetchRoutines = exports.fetchRoutineRunsSuccess = exports.fetchRoutineRunsFailure = exports.fetchRoutineRuns = exports.fetchChatSessionsForUserSuccess = exports.fetchChatSessionsForUserFailure = exports.fetchChatSessionsForUser = exports.fetchChatHistorySuccess = exports.fetchChatHistoryFailure = exports.fetchChatHistory = exports.deleteSkillSuccess = exports.deleteSkillFailure = exports.deleteSkill = exports.deleteRoutineSuccess = exports.deleteRoutineFailure = exports.deleteRoutine = exports.deleteChatSessionSuccess = exports.deleteChatSessionFailure = exports.deleteChatSession = exports.createSessionSuccess = exports.createSessionFailure = exports.createSessionAndSubmitSuccess = exports.createSessionAndSubmitFailure = exports.createSessionAndSubmit = exports.createSession = exports.closeSkillsBrowser = exports.closeRoutinesBrowser = exports.closeRoutineRuns = exports.clearSkillMutation = exports.clearSkillDetail = exports.clearLastContextMessage = exports.clearDeleteChatSessionStatus = exports.clearCurrentSessionId = exports.clearAiCfoSidePanelHostPageContext = exports.applyAiCfoSidePanelHostPageTransition = exports.acceptMasterTOSSuccess = exports.acceptMasterTOSFailure = exports.acceptMasterTOS = exports.initialAiCfoViewState = void 0;
5
- exports.updateResponseState = exports.updateCurrentInput = exports.updateCotCollapsedState = exports.updateAiCfoViewScrollPosition = exports.submitQuestionSuccess = exports.submitQuestionFailure = exports.submitQuestion = exports.submitFeedbackSuccess = exports.submitFeedbackFailure = exports.submitFeedback = exports.stopSubmitSuccess = exports.stopSubmitQuestionSuccess = exports.stopSubmitQuestionFailure = exports.stopSubmitQuestion = exports.stopSubmitFailure = exports.stopSubmit = exports.setSkillVisibilitySuccess = exports.setSkillVisibilityFailure = exports.setSkillVisibility = exports.setSession = exports.setRoutineEnabled = exports.saveSkillSuccess = exports.saveSkillFailure = exports.saveSkill = exports.saveRoutineSuccess = exports.saveRoutineFailure = exports.saveRoutine = exports.runRoutineSuccess = exports.runRoutineFailure = exports.runRoutine = exports.openSkillsBrowser = exports.openRoutinesBrowser = exports.initializeNewSessionState = exports.fetchSuggestedQuestionsSuccess = exports.fetchSuggestedQuestionsFailure = exports.fetchSuggestedQuestions = exports.fetchSkillVersionsSuccess = exports.fetchSkillVersionsFailure = exports.fetchSkillVersions = void 0;
5
+ exports.updateResponseState = exports.updateCurrentInput = exports.updateCotCollapsedState = exports.updateAiCfoViewScrollPosition = exports.transcribeAudioSuccess = exports.transcribeAudioFailure = exports.transcribeAudio = exports.submitQuestionSuccess = exports.submitQuestionFailure = exports.submitQuestion = exports.submitFeedbackSuccess = exports.submitFeedbackFailure = exports.submitFeedback = exports.stopSubmitSuccess = exports.stopSubmitQuestionSuccess = exports.stopSubmitQuestionFailure = exports.stopSubmitQuestion = exports.stopSubmitFailure = exports.stopSubmit = exports.setSkillVisibilitySuccess = exports.setSkillVisibilityFailure = exports.setSkillVisibility = exports.setSession = exports.setRoutineEnabled = exports.saveSkillSuccess = exports.saveSkillFailure = exports.saveSkill = exports.saveRoutineSuccess = exports.saveRoutineFailure = exports.saveRoutine = exports.runRoutineSuccess = exports.runRoutineFailure = exports.runRoutine = exports.openSkillsBrowser = exports.openRoutinesBrowser = exports.initializeNewSessionState = exports.fetchSuggestedQuestionsSuccess = exports.fetchSuggestedQuestionsFailure = exports.fetchSuggestedQuestions = exports.fetchSkillVersionsSuccess = exports.fetchSkillVersionsFailure = exports.fetchSkillVersions = void 0;
6
6
  const toolkit_1 = require("@reduxjs/toolkit");
7
7
  const rootActions_1 = require("../../rootActions");
8
8
  function removeSessionIdFromPageKeyMap(draft, sessionId) {
@@ -52,6 +52,8 @@ exports.initialAiCfoViewState = {
52
52
  fetchChatSessionHistoryByChatSessionId: {},
53
53
  responseStateByChatSessionId: {},
54
54
  stopSubmitStateByChatSessionId: {},
55
+ transcriptionState: { fetchState: 'Not-Started', error: undefined },
56
+ transcribingChatSessionId: undefined,
55
57
  suggestedQuestionsByPageContext: {},
56
58
  skillDetail: {
57
59
  fetchState: 'Not-Started',
@@ -152,6 +154,19 @@ function closeSkillsBrowserState(draft) {
152
154
  draft.uiState.isSkillsBrowserOpen = false;
153
155
  clearOpenSkillState(draft);
154
156
  }
157
+ /**
158
+ * Clear a finished dictation attempt when the conversation moves on, so a failed one
159
+ * stops showing "Could not transcribe that recording" in every later chat. A running
160
+ * take keeps its state — the composer is showing a live "Transcribing…" for it.
161
+ */
162
+ function resetFinishedTranscription(draft) {
163
+ if (draft.transcriptionState.fetchState === 'In-Progress') {
164
+ return;
165
+ }
166
+ draft.transcriptionState.fetchState = 'Not-Started';
167
+ draft.transcriptionState.error = undefined;
168
+ draft.transcribingChatSessionId = undefined;
169
+ }
155
170
  const aiCfoView = (0, toolkit_1.createSlice)({
156
171
  name: 'aiCfoView',
157
172
  initialState: exports.initialAiCfoViewState,
@@ -159,6 +174,7 @@ const aiCfoView = (0, toolkit_1.createSlice)({
159
174
  submitQuestion: {
160
175
  reducer(draft, action) {
161
176
  const { sessionId } = action.payload;
177
+ resetFinishedTranscription(draft);
162
178
  // A turn is being sent, so the chat body has to be what the user sees. Doing this
163
179
  // here rather than at each call site is deliberate: the composer, the sample
164
180
  // chips, Run, and the `/` menu all submit, and every one of them was a separate
@@ -304,6 +320,7 @@ const aiCfoView = (0, toolkit_1.createSlice)({
304
320
  setSession(draft, action) {
305
321
  draft.uiState.currentChatSessionId = action.payload.sessionId;
306
322
  draft.uiState.agentId = action.payload.agentId;
323
+ resetFinishedTranscription(draft);
307
324
  // Picking a session means wanting to see that chat, so the browser cannot stay over
308
325
  // it. In the reducer because there are six dispatch sites across three separate
309
326
  // rails, and covering them one at a time missed half of them.
@@ -356,6 +373,7 @@ const aiCfoView = (0, toolkit_1.createSlice)({
356
373
  createSessionAndSubmit: {
357
374
  reducer(draft, action) {
358
375
  draft.uiState.agentId = action.payload.agentId;
376
+ resetFinishedTranscription(draft);
359
377
  draft.createSessionAndSubmitState.fetchState = 'In-Progress';
360
378
  draft.createSessionAndSubmitState.error = undefined;
361
379
  },
@@ -556,7 +574,49 @@ const aiCfoView = (0, toolkit_1.createSlice)({
556
574
  return { payload: { chatMessageId, error } };
557
575
  },
558
576
  },
577
+ transcribeAudio: {
578
+ reducer(draft, action) {
579
+ draft.transcriptionState.fetchState = 'In-Progress';
580
+ draft.transcriptionState.error = undefined;
581
+ draft.transcribingChatSessionId = action.payload.chatSessionId;
582
+ },
583
+ prepare(audio, language, chatSessionId) {
584
+ return { payload: { audio, chatSessionId, language } };
585
+ },
586
+ },
587
+ transcribeAudioSuccess: {
588
+ reducer(draft, action) {
589
+ draft.transcriptionState.fetchState = 'Completed';
590
+ draft.transcriptionState.error = undefined;
591
+ // The user moved to another session while this was in flight — dropping it
592
+ // is the only safe option, since appending would put their words in a
593
+ // conversation they did not dictate into.
594
+ if (action.payload.chatSessionId !== draft.uiState.currentChatSessionId) {
595
+ return;
596
+ }
597
+ const transcript = action.payload.transcript.trim();
598
+ if (transcript === '') {
599
+ // Silence, not a failure: leave the composer untouched so the user can
600
+ // simply speak again rather than hunting for what went wrong.
601
+ return;
602
+ }
603
+ // Append to whatever is in the box now rather than to a snapshot taken when
604
+ // recording began — a take produces exactly one result, so there is nothing
605
+ // to reconcile, and anything typed while transcribing survives.
606
+ const existing = draft.uiState.currentInput.trim();
607
+ draft.uiState.currentInput =
608
+ existing === '' ? transcript : `${existing} ${transcript}`;
609
+ },
610
+ prepare(transcript, chatSessionId) {
611
+ return { payload: { chatSessionId, transcript } };
612
+ },
613
+ },
614
+ transcribeAudioFailure(draft, action) {
615
+ draft.transcriptionState.fetchState = 'Error';
616
+ draft.transcriptionState.error = action.payload;
617
+ },
559
618
  clearCurrentSessionId(draft) {
619
+ resetFinishedTranscription(draft);
560
620
  // New Chat: the empty composer is the point, so the browser cannot stay over it.
561
621
  if (draft.uiState.isSkillsBrowserOpen === true) {
562
622
  closeSkillsBrowserState(draft);
@@ -840,7 +900,8 @@ const aiCfoView = (0, toolkit_1.createSlice)({
840
900
  // The server has it. Nothing it sends from here on will contain this row,
841
901
  // so the tombstone has done its job and holding it any longer is what
842
902
  // makes a routine recreated under the same id invisible forever.
843
- draft.routines.deletedScheduleIds = draft.routines.deletedScheduleIds.filter((id) => id !== action.payload.scheduleId);
903
+ draft.routines.deletedScheduleIds =
904
+ draft.routines.deletedScheduleIds.filter((id) => id !== action.payload.scheduleId);
844
905
  draft.routineMutation = {
845
906
  fetchState: 'Completed',
846
907
  error: undefined,
@@ -852,7 +913,8 @@ const aiCfoView = (0, toolkit_1.createSlice)({
852
913
  // is what lets the refetch put the row back — leaving it hidden would
853
914
  // tell the user they had stopped something they had not, which is the
854
915
  // worst outcome this list can produce.
855
- draft.routines.deletedScheduleIds = draft.routines.deletedScheduleIds.filter((id) => id !== action.payload.scheduleId);
916
+ draft.routines.deletedScheduleIds =
917
+ draft.routines.deletedScheduleIds.filter((id) => id !== action.payload.scheduleId);
856
918
  // Its own slice: the refetch that puts the row back would otherwise wipe
857
919
  // this error, leaving the row silently reappearing with no explanation.
858
920
  draft.routineMutation = {
@@ -1188,5 +1250,5 @@ const aiCfoView = (0, toolkit_1.createSlice)({
1188
1250
  });
1189
1251
  },
1190
1252
  });
1191
- _a = aiCfoView.actions, exports.acceptMasterTOS = _a.acceptMasterTOS, exports.acceptMasterTOSFailure = _a.acceptMasterTOSFailure, exports.acceptMasterTOSSuccess = _a.acceptMasterTOSSuccess, exports.applyAiCfoSidePanelHostPageTransition = _a.applyAiCfoSidePanelHostPageTransition, exports.clearAiCfoSidePanelHostPageContext = _a.clearAiCfoSidePanelHostPageContext, exports.clearCurrentSessionId = _a.clearCurrentSessionId, exports.clearDeleteChatSessionStatus = _a.clearDeleteChatSessionStatus, exports.clearLastContextMessage = _a.clearLastContextMessage, exports.clearSkillDetail = _a.clearSkillDetail, exports.clearSkillMutation = _a.clearSkillMutation, exports.closeRoutineRuns = _a.closeRoutineRuns, exports.closeRoutinesBrowser = _a.closeRoutinesBrowser, exports.closeSkillsBrowser = _a.closeSkillsBrowser, exports.createSession = _a.createSession, exports.createSessionAndSubmit = _a.createSessionAndSubmit, exports.createSessionAndSubmitFailure = _a.createSessionAndSubmitFailure, exports.createSessionAndSubmitSuccess = _a.createSessionAndSubmitSuccess, exports.createSessionFailure = _a.createSessionFailure, exports.createSessionSuccess = _a.createSessionSuccess, exports.deleteChatSession = _a.deleteChatSession, exports.deleteChatSessionFailure = _a.deleteChatSessionFailure, exports.deleteChatSessionSuccess = _a.deleteChatSessionSuccess, exports.deleteRoutine = _a.deleteRoutine, exports.deleteRoutineFailure = _a.deleteRoutineFailure, exports.deleteRoutineSuccess = _a.deleteRoutineSuccess, exports.deleteSkill = _a.deleteSkill, exports.deleteSkillFailure = _a.deleteSkillFailure, exports.deleteSkillSuccess = _a.deleteSkillSuccess, exports.fetchChatHistory = _a.fetchChatHistory, exports.fetchChatHistoryFailure = _a.fetchChatHistoryFailure, exports.fetchChatHistorySuccess = _a.fetchChatHistorySuccess, exports.fetchChatSessionsForUser = _a.fetchChatSessionsForUser, exports.fetchChatSessionsForUserFailure = _a.fetchChatSessionsForUserFailure, exports.fetchChatSessionsForUserSuccess = _a.fetchChatSessionsForUserSuccess, exports.fetchRoutineRuns = _a.fetchRoutineRuns, exports.fetchRoutineRunsFailure = _a.fetchRoutineRunsFailure, exports.fetchRoutineRunsSuccess = _a.fetchRoutineRunsSuccess, exports.fetchRoutines = _a.fetchRoutines, exports.fetchRoutinesFailure = _a.fetchRoutinesFailure, exports.fetchRoutinesSuccess = _a.fetchRoutinesSuccess, exports.fetchSkillDetail = _a.fetchSkillDetail, exports.fetchSkillDetailFailure = _a.fetchSkillDetailFailure, exports.fetchSkillDetailSuccess = _a.fetchSkillDetailSuccess, exports.fetchSkills = _a.fetchSkills, exports.fetchSkillsFailure = _a.fetchSkillsFailure, exports.fetchSkillsSuccess = _a.fetchSkillsSuccess, exports.fetchSkillVersionBody = _a.fetchSkillVersionBody, exports.fetchSkillVersionBodyFailure = _a.fetchSkillVersionBodyFailure, exports.fetchSkillVersionBodySuccess = _a.fetchSkillVersionBodySuccess, exports.fetchSkillVersions = _a.fetchSkillVersions, exports.fetchSkillVersionsFailure = _a.fetchSkillVersionsFailure, exports.fetchSkillVersionsSuccess = _a.fetchSkillVersionsSuccess, exports.fetchSuggestedQuestions = _a.fetchSuggestedQuestions, exports.fetchSuggestedQuestionsFailure = _a.fetchSuggestedQuestionsFailure, exports.fetchSuggestedQuestionsSuccess = _a.fetchSuggestedQuestionsSuccess, exports.initializeNewSessionState = _a.initializeNewSessionState, exports.openRoutinesBrowser = _a.openRoutinesBrowser, exports.openSkillsBrowser = _a.openSkillsBrowser, exports.runRoutine = _a.runRoutine, exports.runRoutineFailure = _a.runRoutineFailure, exports.runRoutineSuccess = _a.runRoutineSuccess, exports.saveRoutine = _a.saveRoutine, exports.saveRoutineFailure = _a.saveRoutineFailure, exports.saveRoutineSuccess = _a.saveRoutineSuccess, exports.saveSkill = _a.saveSkill, exports.saveSkillFailure = _a.saveSkillFailure, exports.saveSkillSuccess = _a.saveSkillSuccess, exports.setRoutineEnabled = _a.setRoutineEnabled, exports.setSession = _a.setSession, exports.setSkillVisibility = _a.setSkillVisibility, exports.setSkillVisibilityFailure = _a.setSkillVisibilityFailure, exports.setSkillVisibilitySuccess = _a.setSkillVisibilitySuccess, exports.stopSubmit = _a.stopSubmit, exports.stopSubmitFailure = _a.stopSubmitFailure, exports.stopSubmitQuestion = _a.stopSubmitQuestion, exports.stopSubmitQuestionFailure = _a.stopSubmitQuestionFailure, exports.stopSubmitQuestionSuccess = _a.stopSubmitQuestionSuccess, exports.stopSubmitSuccess = _a.stopSubmitSuccess, exports.submitFeedback = _a.submitFeedback, exports.submitFeedbackFailure = _a.submitFeedbackFailure, exports.submitFeedbackSuccess = _a.submitFeedbackSuccess, exports.submitQuestion = _a.submitQuestion, exports.submitQuestionFailure = _a.submitQuestionFailure, exports.submitQuestionSuccess = _a.submitQuestionSuccess, exports.updateAiCfoViewScrollPosition = _a.updateAiCfoViewScrollPosition, exports.updateCotCollapsedState = _a.updateCotCollapsedState, exports.updateCurrentInput = _a.updateCurrentInput, exports.updateResponseState = _a.updateResponseState;
1253
+ _a = aiCfoView.actions, exports.acceptMasterTOS = _a.acceptMasterTOS, exports.acceptMasterTOSFailure = _a.acceptMasterTOSFailure, exports.acceptMasterTOSSuccess = _a.acceptMasterTOSSuccess, exports.applyAiCfoSidePanelHostPageTransition = _a.applyAiCfoSidePanelHostPageTransition, exports.clearAiCfoSidePanelHostPageContext = _a.clearAiCfoSidePanelHostPageContext, exports.clearCurrentSessionId = _a.clearCurrentSessionId, exports.clearDeleteChatSessionStatus = _a.clearDeleteChatSessionStatus, exports.clearLastContextMessage = _a.clearLastContextMessage, exports.clearSkillDetail = _a.clearSkillDetail, exports.clearSkillMutation = _a.clearSkillMutation, exports.closeRoutineRuns = _a.closeRoutineRuns, exports.closeRoutinesBrowser = _a.closeRoutinesBrowser, exports.closeSkillsBrowser = _a.closeSkillsBrowser, exports.createSession = _a.createSession, exports.createSessionAndSubmit = _a.createSessionAndSubmit, exports.createSessionAndSubmitFailure = _a.createSessionAndSubmitFailure, exports.createSessionAndSubmitSuccess = _a.createSessionAndSubmitSuccess, exports.createSessionFailure = _a.createSessionFailure, exports.createSessionSuccess = _a.createSessionSuccess, exports.deleteChatSession = _a.deleteChatSession, exports.deleteChatSessionFailure = _a.deleteChatSessionFailure, exports.deleteChatSessionSuccess = _a.deleteChatSessionSuccess, exports.deleteRoutine = _a.deleteRoutine, exports.deleteRoutineFailure = _a.deleteRoutineFailure, exports.deleteRoutineSuccess = _a.deleteRoutineSuccess, exports.deleteSkill = _a.deleteSkill, exports.deleteSkillFailure = _a.deleteSkillFailure, exports.deleteSkillSuccess = _a.deleteSkillSuccess, exports.fetchChatHistory = _a.fetchChatHistory, exports.fetchChatHistoryFailure = _a.fetchChatHistoryFailure, exports.fetchChatHistorySuccess = _a.fetchChatHistorySuccess, exports.fetchChatSessionsForUser = _a.fetchChatSessionsForUser, exports.fetchChatSessionsForUserFailure = _a.fetchChatSessionsForUserFailure, exports.fetchChatSessionsForUserSuccess = _a.fetchChatSessionsForUserSuccess, exports.fetchRoutineRuns = _a.fetchRoutineRuns, exports.fetchRoutineRunsFailure = _a.fetchRoutineRunsFailure, exports.fetchRoutineRunsSuccess = _a.fetchRoutineRunsSuccess, exports.fetchRoutines = _a.fetchRoutines, exports.fetchRoutinesFailure = _a.fetchRoutinesFailure, exports.fetchRoutinesSuccess = _a.fetchRoutinesSuccess, exports.fetchSkillDetail = _a.fetchSkillDetail, exports.fetchSkillDetailFailure = _a.fetchSkillDetailFailure, exports.fetchSkillDetailSuccess = _a.fetchSkillDetailSuccess, exports.fetchSkills = _a.fetchSkills, exports.fetchSkillsFailure = _a.fetchSkillsFailure, exports.fetchSkillsSuccess = _a.fetchSkillsSuccess, exports.fetchSkillVersionBody = _a.fetchSkillVersionBody, exports.fetchSkillVersionBodyFailure = _a.fetchSkillVersionBodyFailure, exports.fetchSkillVersionBodySuccess = _a.fetchSkillVersionBodySuccess, exports.fetchSkillVersions = _a.fetchSkillVersions, exports.fetchSkillVersionsFailure = _a.fetchSkillVersionsFailure, exports.fetchSkillVersionsSuccess = _a.fetchSkillVersionsSuccess, exports.fetchSuggestedQuestions = _a.fetchSuggestedQuestions, exports.fetchSuggestedQuestionsFailure = _a.fetchSuggestedQuestionsFailure, exports.fetchSuggestedQuestionsSuccess = _a.fetchSuggestedQuestionsSuccess, exports.initializeNewSessionState = _a.initializeNewSessionState, exports.openRoutinesBrowser = _a.openRoutinesBrowser, exports.openSkillsBrowser = _a.openSkillsBrowser, exports.runRoutine = _a.runRoutine, exports.runRoutineFailure = _a.runRoutineFailure, exports.runRoutineSuccess = _a.runRoutineSuccess, exports.saveRoutine = _a.saveRoutine, exports.saveRoutineFailure = _a.saveRoutineFailure, exports.saveRoutineSuccess = _a.saveRoutineSuccess, exports.saveSkill = _a.saveSkill, exports.saveSkillFailure = _a.saveSkillFailure, exports.saveSkillSuccess = _a.saveSkillSuccess, exports.setRoutineEnabled = _a.setRoutineEnabled, exports.setSession = _a.setSession, exports.setSkillVisibility = _a.setSkillVisibility, exports.setSkillVisibilityFailure = _a.setSkillVisibilityFailure, exports.setSkillVisibilitySuccess = _a.setSkillVisibilitySuccess, exports.stopSubmit = _a.stopSubmit, exports.stopSubmitFailure = _a.stopSubmitFailure, exports.stopSubmitQuestion = _a.stopSubmitQuestion, exports.stopSubmitQuestionFailure = _a.stopSubmitQuestionFailure, exports.stopSubmitQuestionSuccess = _a.stopSubmitQuestionSuccess, exports.stopSubmitSuccess = _a.stopSubmitSuccess, exports.submitFeedback = _a.submitFeedback, exports.submitFeedbackFailure = _a.submitFeedbackFailure, exports.submitFeedbackSuccess = _a.submitFeedbackSuccess, exports.submitQuestion = _a.submitQuestion, exports.submitQuestionFailure = _a.submitQuestionFailure, exports.submitQuestionSuccess = _a.submitQuestionSuccess, exports.transcribeAudio = _a.transcribeAudio, exports.transcribeAudioFailure = _a.transcribeAudioFailure, exports.transcribeAudioSuccess = _a.transcribeAudioSuccess, exports.updateAiCfoViewScrollPosition = _a.updateAiCfoViewScrollPosition, exports.updateCotCollapsedState = _a.updateCotCollapsedState, exports.updateCurrentInput = _a.updateCurrentInput, exports.updateResponseState = _a.updateResponseState;
1192
1254
  exports.default = aiCfoView.reducer;
@@ -4,7 +4,7 @@ import { FetchStateAndError } from '../../commonStateTypes/common';
4
4
  import { SelectorView } from '../../commonStateTypes/viewAndReport/viewAndReport';
5
5
  import { AiCfoSelectorView } from '../../entity/aiCfo/aiCfoSelector';
6
6
  import { RootState } from '../../rootStateTypes';
7
- import { AiCfoViewUIState, SkillDetailState, SkillMutationState, SkillVersionBodyState, SkillVersionsState, RoutineMutationState, RoutineRunsState, RoutinesState, SkillsState, SuggestedQuestionsForPageContext } from './aiCfoViewState';
7
+ import { AiCfoViewUIState, RoutineMutationState, RoutineRunsState, RoutinesState, SkillDetailState, SkillMutationState, SkillVersionBodyState, SkillVersionsState, SkillsState, SuggestedQuestionsForPageContext } from './aiCfoViewState';
8
8
  export interface AiCfoViewSelector extends SelectorView, AiCfoSelectorView {
9
9
  createSessionAndSubmitState: FetchStateAndError;
10
10
  createSessionState: FetchStateAndError;
@@ -42,3 +42,10 @@ export declare function getSkillVersionBody(state: RootState): SkillVersionBodyS
42
42
  export declare function getSkillMutation(state: RootState): SkillMutationState;
43
43
  /** True only when the server says the feature is on for this tenant. */
44
44
  export declare function getSkillsEnabled(state: RootState): boolean;
45
+ export declare function getIsTranscribing(state: RootState): boolean;
46
+ /**
47
+ * Set when a transcription request failed. Without surfacing this the composer
48
+ * would just drop the "Transcribing…" label and sit there silently, leaving the
49
+ * user with no sign their recording went nowhere.
50
+ */
51
+ export declare function getTranscriptionFailed(state: RootState): boolean;
@@ -13,6 +13,8 @@ exports.getSkillVersions = getSkillVersions;
13
13
  exports.getSkillVersionBody = getSkillVersionBody;
14
14
  exports.getSkillMutation = getSkillMutation;
15
15
  exports.getSkillsEnabled = getSkillsEnabled;
16
+ exports.getIsTranscribing = getIsTranscribing;
17
+ exports.getTranscriptionFailed = getTranscriptionFailed;
16
18
  const aiCfoReducer_1 = require("../../entity/aiCfo/aiCfoReducer");
17
19
  const aiCfoSelector_1 = require("../../entity/aiCfo/aiCfoSelector");
18
20
  const aiCfoViewReducer_1 = require("./aiCfoViewReducer");
@@ -149,3 +151,28 @@ function getSkillMutation(state) {
149
151
  function getSkillsEnabled(state) {
150
152
  return getSkills(state).skillsEnabled;
151
153
  }
154
+ /** True while a finished voice recording is being transcribed server-side. */
155
+ /**
156
+ * A take belongs to the chat it was dictated into. A new chat has no session id yet on
157
+ * either side, which is a match rather than a mismatch.
158
+ */
159
+ function isTranscribingCurrentSession(state) {
160
+ if (state.aiCfoViewState == null) {
161
+ return false;
162
+ }
163
+ return (state.aiCfoViewState.transcribingChatSessionId ===
164
+ state.aiCfoViewState.uiState.currentChatSessionId);
165
+ }
166
+ function getIsTranscribing(state) {
167
+ return (state.aiCfoViewState?.transcriptionState?.fetchState === 'In-Progress' &&
168
+ isTranscribingCurrentSession(state));
169
+ }
170
+ /**
171
+ * Set when a transcription request failed. Without surfacing this the composer
172
+ * would just drop the "Transcribing…" label and sit there silently, leaving the
173
+ * user with no sign their recording went nowhere.
174
+ */
175
+ function getTranscriptionFailed(state) {
176
+ return (state.aiCfoViewState?.transcriptionState?.fetchState === 'Error' &&
177
+ isTranscribingCurrentSession(state));
178
+ }
@@ -378,5 +378,14 @@ export interface AiCfoViewState extends FetchStateAndError {
378
378
  stopSubmitStateByChatSessionId: Record<ID, FetchStateAndError>;
379
379
  /** Keyed by `page_context` query value (e.g. balance_sheet). */
380
380
  suggestedQuestionsByPageContext: Partial<Record<AiCfoSuggestedQuestionsPageContext, SuggestedQuestionsForPageContext>>;
381
+ /** Voice dictation: in-flight while a recording is being transcribed. */
382
+ transcriptionState: FetchStateAndError;
381
383
  uiState: AiCfoViewUIState;
384
+ /**
385
+ * Conversation the take in `transcriptionState` was dictated into. The spinner and
386
+ * the failure message belong to that chat alone — an epic outlives the component, so
387
+ * without this a take started in one session locks the composer, or shows its error,
388
+ * in whichever session the user has moved to.
389
+ */
390
+ transcribingChatSessionId?: ID;
382
391
  }
@@ -0,0 +1,19 @@
1
+ import { ActionsObservable, StateObservable } from 'redux-observable';
2
+ import { Observable } from 'rxjs';
3
+ import { clearAll } from '../../../rootActions';
4
+ import { RootState } from '../../../rootStateTypes';
5
+ import { ZeniAPI } from '../../../zeniAPI';
6
+ import { transcribeAudio, transcribeAudioFailure, transcribeAudioSuccess } from '../aiCfoViewReducer';
7
+ export type ActionType = ReturnType<typeof clearAll> | ReturnType<typeof transcribeAudio> | ReturnType<typeof transcribeAudioSuccess> | ReturnType<typeof transcribeAudioFailure>;
8
+ /**
9
+ * Voice dictation for the AI CFO composer. Dispatch `transcribeAudio(blob, language)` with a
10
+ * finished recording to POST it to the AI CFO micro-service `/1.0/transcriptions` endpoint;
11
+ * on success the transcript is appended to the composer input for the user to edit and send.
12
+ *
13
+ * `switchMap` (not `mergeMap`): a newer recording supersedes an older in-flight one, so a
14
+ * slow response can never append a stale transcript after a fresh one has already landed.
15
+ * The AbortController makes that cancellation real — `fetch` wrapped in a promise ignores
16
+ * an RxJS unsubscribe, so without the signal the superseded request would run to completion
17
+ * and still bill a transcription call whose result nothing wants.
18
+ */
19
+ export declare const transcribeAudioEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transcribeAudioEpic = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const responsePayload_1 = require("../../../responsePayload");
7
+ const rootActions_1 = require("../../../rootActions");
8
+ const aiCfoViewReducer_1 = require("../aiCfoViewReducer");
9
+ const AUDIO_FIELD = 'audio';
10
+ const LANGUAGE_FIELD = 'language';
11
+ /** Extension only has to match the recorded format; the server reads the part's MIME type. */
12
+ const AUDIO_FILE_NAME = 'dictation.wav';
13
+ /**
14
+ * A hung request would otherwise pin `isTranscribing` true forever, and the composer
15
+ * gates both submit and the mic on it — leaving the user unable to send even typed
16
+ * text until something else resolved it.
17
+ */
18
+ const TRANSCRIPTION_TIMEOUT_MS = 30000;
19
+ /**
20
+ * Voice dictation for the AI CFO composer. Dispatch `transcribeAudio(blob, language)` with a
21
+ * finished recording to POST it to the AI CFO micro-service `/1.0/transcriptions` endpoint;
22
+ * on success the transcript is appended to the composer input for the user to edit and send.
23
+ *
24
+ * `switchMap` (not `mergeMap`): a newer recording supersedes an older in-flight one, so a
25
+ * slow response can never append a stale transcript after a fresh one has already landed.
26
+ * The AbortController makes that cancellation real — `fetch` wrapped in a promise ignores
27
+ * an RxJS unsubscribe, so without the signal the superseded request would run to completion
28
+ * and still bill a transcription call whose result nothing wants.
29
+ */
30
+ const transcribeAudioEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(aiCfoViewReducer_1.transcribeAudio.match), (0, operators_1.switchMap)((action) => {
31
+ const { audio, chatSessionId, language } = action.payload;
32
+ const abortController = new AbortController();
33
+ const formData = new FormData();
34
+ formData.append(AUDIO_FIELD, audio, AUDIO_FILE_NAME);
35
+ if (language != null && language !== '') {
36
+ formData.append(LANGUAGE_FIELD, language);
37
+ }
38
+ return zeniAPI
39
+ .postFormData(`${zeniAPI.apiEndPoints.aiCfoMicroServiceBaseUrl}/1.0/transcriptions`, formData, abortController.signal)
40
+ .pipe((0, operators_1.timeout)(TRANSCRIPTION_TIMEOUT_MS),
41
+ // A tenant switch clears the store; a transcript still in flight must not
42
+ // land in the next tenant's composer (both sessions can be `undefined`, so
43
+ // the reducer's session guard would let it through).
44
+ (0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)(rootActions_1.clearAll.match))), (0, operators_1.map)((response) => {
45
+ if (!(0, responsePayload_1.isSuccessResponse)(response)) {
46
+ return (0, aiCfoViewReducer_1.transcribeAudioFailure)(response.status);
47
+ }
48
+ // An EMPTY transcript is a success (the mic caught silence) and the
49
+ // reducer leaves the composer alone. A MISSING one breaks the response
50
+ // contract, so it surfaces as an error rather than being coerced to
51
+ // silence the user cannot distinguish from a quiet room.
52
+ if (response.data?.transcript == null) {
53
+ return (0, aiCfoViewReducer_1.transcribeAudioFailure)((0, responsePayload_1.createZeniAPIStatus)('Transcription succeeded but the response carried no transcript', 'Unexpected Error'));
54
+ }
55
+ // The session id rides along so a transcript that lands after the user
56
+ // switched sessions is dropped rather than misfiled.
57
+ return (0, aiCfoViewReducer_1.transcribeAudioSuccess)(response.data.transcript, chatSessionId);
58
+ }), (0, operators_1.finalize)(() => abortController.abort()), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, aiCfoViewReducer_1.transcribeAudioFailure)((0, responsePayload_1.createZeniAPIStatus)(
59
+ // message (detailed) first, then the short title — per createZeniAPIStatus(message, title).
60
+ // JSON.stringify(Error) drops the (non-enumerable) message — extract it explicitly.
61
+ 'Transcription REST API call errored out: ' +
62
+ (error instanceof Error ? error.message : String(error)), 'Unexpected Error')))));
63
+ }));
64
+ exports.transcribeAudioEpic = transcribeAudioEpic;
@@ -9,7 +9,11 @@ const balanceSheetPayload_1 = require("./balanceSheetPayload");
9
9
  const balanceSheetReducer_1 = require("./balanceSheetReducer");
10
10
  const reportIdUniqueKey = () => 'balance_sheet';
11
11
  exports.reportIdUniqueKey = reportIdUniqueKey;
12
- const fetchBalanceSheetForTimeframeEpic = (actions$, _, zeniAPI) => actions$.pipe((0, operators_1.filter)(balanceSheetReducer_1.fetchBalanceSheetForTimeframe.match), (0, operators_1.mergeMap)((action) => {
12
+ const fetchBalanceSheetForTimeframeEpic = (actions$, _, zeniAPI) => actions$.pipe((0, operators_1.filter)(balanceSheetReducer_1.fetchBalanceSheetForTimeframe.match),
13
+ // One stream per timeframe: a newer request for the same timeframe (e.g. a
14
+ // custom-date-range change, or a dated fetch right after a default one)
15
+ // cancels the older in-flight request so a stale response can't land last.
16
+ (0, operators_1.groupBy)((action) => action.payload.timeframe), (0, operators_1.mergeMap)((group$) => group$.pipe((0, operators_1.switchMap)((action) => {
13
17
  const getTimeSeriesGroup = (timeframe) => {
14
18
  switch (timeframe) {
15
19
  case 'month':
@@ -24,7 +28,8 @@ const fetchBalanceSheetForTimeframeEpic = (actions$, _, zeniAPI) => actions$.pip
24
28
  is_full_response: action.payload.fetchFullReport,
25
29
  time_series_groups: [getTimeSeriesGroup(action.payload.timeframe)],
26
30
  };
27
- if (action.payload.startDate != null && action.payload.endDate != null) {
31
+ if (action.payload.startDate != null &&
32
+ action.payload.endDate != null) {
28
33
  queryValue.custom_start_date = action.payload.startDate;
29
34
  queryValue.custom_end_date = action.payload.endDate;
30
35
  }
@@ -77,5 +82,5 @@ const fetchBalanceSheetForTimeframeEpic = (actions$, _, zeniAPI) => actions$.pip
77
82
  }
78
83
  }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, balanceSheetReducer_1.updateBalanceSheetForTimeframeFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Balance Sheet REST API call errored out' +
79
84
  JSON.stringify(error)), action.payload.timeframe))));
80
- }));
85
+ }))));
81
86
  exports.fetchBalanceSheetForTimeframeEpic = fetchBalanceSheetForTimeframeEpic;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.resetBalanceSheetNodeCollapseState = exports.updateBalanceSheetUIState = exports.updateBalanceSheetForTimeframeFailure = exports.updateBalanceSheetForTimeframe = exports.fetchBalanceSheetForTimeframe = exports.fetchBalanceSheet = exports.initialState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  const viewAndReportPayloadv2_1 = require("../../commonPayloadTypes/v2/viewAndReportPayloadv2");
7
+ const coaBalance_1 = require("../../commonStateTypes/coaBalance/coaBalance");
7
8
  const rootActions_1 = require("../../rootActions");
8
9
  exports.initialState = {
9
10
  bookCloseDate: undefined,
@@ -66,6 +67,7 @@ const balanceSheet = (0, toolkit_1.createSlice)({
66
67
  fetchState: 'In-Progress',
67
68
  error: undefined,
68
69
  };
70
+ draft.customDateRangeByTimeframe = (0, coaBalance_1.withFetchedCustomDateRange)(draft.customDateRangeByTimeframe, timeframe, action.payload.startDate, action.payload.endDate);
69
71
  },
70
72
  },
71
73
  updateBalanceSheetForTimeframe(draft, action) {
@@ -1,3 +1,4 @@
1
+ import { CustomDateRangeByTimeframe } from '../../commonStateTypes/coaBalance/coaBalance';
1
2
  import { FetchStateAndError, ID } from '../../commonStateTypes/common';
2
3
  import { Report } from '../../commonStateTypes/viewAndReport/viewAndReport';
3
4
  export interface BalanceSheetUIState {
@@ -14,4 +15,5 @@ export interface BalanceSheetState extends Report {
14
15
  year: FetchStateAndError;
15
16
  };
16
17
  uiState: BalanceSheetUIState;
18
+ customDateRangeByTimeframe?: CustomDateRangeByTimeframe;
17
19
  }
@@ -9,7 +9,11 @@ const cashFlowPayload_1 = require("./cashFlowPayload");
9
9
  const cashFlowReducer_1 = require("./cashFlowReducer");
10
10
  const reportIdUniqueKey = () => 'cash_flow';
11
11
  exports.reportIdUniqueKey = reportIdUniqueKey;
12
- const fetchCashFlowForTimeframeEpic = (actions$, _, zeniAPI) => actions$.pipe((0, operators_1.filter)(cashFlowReducer_1.fetchCashFlowForTimeframe.match), (0, operators_1.mergeMap)((action) => {
12
+ const fetchCashFlowForTimeframeEpic = (actions$, _, zeniAPI) => actions$.pipe((0, operators_1.filter)(cashFlowReducer_1.fetchCashFlowForTimeframe.match),
13
+ // One stream per timeframe: a newer request for the same timeframe (e.g. a
14
+ // custom-date-range change, or a dated fetch right after a default one)
15
+ // cancels the older in-flight request so a stale response can't land last.
16
+ (0, operators_1.groupBy)((action) => action.payload.timeframe), (0, operators_1.mergeMap)((group$) => group$.pipe((0, operators_1.switchMap)((action) => {
13
17
  const getTimeSeriesGroup = (timeframe) => {
14
18
  switch (timeframe) {
15
19
  case 'month':
@@ -24,7 +28,8 @@ const fetchCashFlowForTimeframeEpic = (actions$, _, zeniAPI) => actions$.pipe((0
24
28
  is_full_response: action.payload.fetchFullReport,
25
29
  time_series_groups: [getTimeSeriesGroup(action.payload.timeframe)],
26
30
  };
27
- if (action.payload.startDate != null && action.payload.endDate != null) {
31
+ if (action.payload.startDate != null &&
32
+ action.payload.endDate != null) {
28
33
  queryValue.custom_start_date = action.payload.startDate;
29
34
  queryValue.custom_end_date = action.payload.endDate;
30
35
  }
@@ -52,6 +57,7 @@ const fetchCashFlowForTimeframeEpic = (actions$, _, zeniAPI) => actions$.pipe((0
52
57
  else {
53
58
  return (0, rxjs_1.of)((0, cashFlowReducer_1.updateCashFlowForTimeframeFailure)(response.status, action.payload.timeframe));
54
59
  }
55
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, cashFlowReducer_1.updateCashFlowForTimeframeFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Cash Flow REST API call errored out' + JSON.stringify(error)), action.payload.timeframe))));
56
- }));
60
+ }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, cashFlowReducer_1.updateCashFlowForTimeframeFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Cash Flow REST API call errored out' +
61
+ JSON.stringify(error)), action.payload.timeframe))));
62
+ }))));
57
63
  exports.fetchCashFlowForTimeframeEpic = fetchCashFlowForTimeframeEpic;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.resetCashFlowNodeCollapseState = exports.updateCashFlowUIState = exports.updateCashFlowForTimeframeFailure = exports.updateCashFlowForTimeframe = exports.fetchCashFlowForTimeframe = exports.fetchCashFlow = exports.initialState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  const viewAndReportPayloadv2_1 = require("../../commonPayloadTypes/v2/viewAndReportPayloadv2");
7
+ const coaBalance_1 = require("../../commonStateTypes/coaBalance/coaBalance");
7
8
  const rootActions_1 = require("../../rootActions");
8
9
  exports.initialState = {
9
10
  fetchState: {
@@ -58,6 +59,7 @@ const cashFlow = (0, toolkit_1.createSlice)({
58
59
  fetchState: 'In-Progress',
59
60
  error: undefined,
60
61
  };
62
+ draft.customDateRangeByTimeframe = (0, coaBalance_1.withFetchedCustomDateRange)(draft.customDateRangeByTimeframe, timeframe, action.payload.startDate, action.payload.endDate);
61
63
  },
62
64
  },
63
65
  updateCashFlowForTimeframe(draft, action) {
@@ -1,3 +1,4 @@
1
+ import { CustomDateRangeByTimeframe } from '../../commonStateTypes/coaBalance/coaBalance';
1
2
  import { ID } from '../../commonStateTypes/common';
2
3
  import { FetchStateAndError } from '../../commonStateTypes/common';
3
4
  import { Report } from '../../commonStateTypes/viewAndReport/viewAndReport';
@@ -8,6 +9,7 @@ export interface CashFlowState extends Report {
8
9
  year: FetchStateAndError;
9
10
  };
10
11
  uiState: CashFlowUIState;
12
+ customDateRangeByTimeframe?: CustomDateRangeByTimeframe;
11
13
  }
12
14
  export interface CashFlowUIState {
13
15
  nodeCollapseState: Record<ID, boolean>;
@@ -91,10 +91,6 @@ const fetchDashboardEpic = (actions$, state$) => actions$.pipe((0, operators_1.f
91
91
  const revenueState = (0, revenueSelector_1.getRevenueReportFetchState)(state.revenueState.uiState.selectedForecast?.id, state.revenueState);
92
92
  const opExState = (0, opExSelector_1.getOperatingExpensesReportFetchState)(state.opExState.uiState.selectedForecast?.id, state.opExState);
93
93
  const netBurnOrIncomeReportFetchState = (0, netBurnOrIncomeSelector_1.getNetBurnOrIncomeReportFetchState)(state.netBurnOrIncomeState.uiState.selectedForecast?.id, state.netBurnOrIncomeState);
94
- if (state.tenantState.fetchState !== 'In-Progress' &&
95
- !state.tenantState.hasValidState()) {
96
- fetchActions.push((0, tenantReducer_1.fetchAllTenants)(userId));
97
- }
98
94
  if (state.cardBalanceState.fetchState !== 'In-Progress' &&
99
95
  !state.cardBalanceState.hasValidState()) {
100
96
  fetchActions.push((0, cardBalanceReducer_1.fetchCardBalance)());
@@ -1,5 +1,4 @@
1
1
  import { ReportID, SelectorReport, SelectorView } from '../../commonStateTypes/viewAndReport/viewAndReport';
2
- import { TenantsOrdered } from '../../entity/tenant/tenantSelector';
3
2
  import { Tenant } from '../../entity/tenant/tenantState';
4
3
  import { RootState } from '../../rootStateTypes';
5
4
  import { CardType } from './dashboardState';
@@ -7,7 +6,6 @@ export interface DashboardReport extends SelectorReport {
7
6
  cardsForDashboardUI: CardType[];
8
7
  cardsOrdered: CardType[];
9
8
  reportsInOrder: (SelectorReport | SelectorView)[];
10
- tenantsOrdered: TenantsOrdered;
11
9
  currentTenant?: Tenant;
12
10
  }
13
11
  export declare const getDashboard: (state: RootState, additionalExcludedReports: ReportID[]) => DashboardReport;
@@ -37,8 +37,7 @@ const getCashInCashOutLast4Periods = (state) => (0, cashInCashOutSelector_1.getC
37
37
  const getNetBurnOrIncomeStoryCard = (state) => (0, netBurnOrIncomeStoryCardSelector_1.getNetBurnOrIncomeStoryCardReport)(state);
38
38
  const apAgingSelector = (state) => (0, apAgingSelector_1.getApAgingReport)(state);
39
39
  const arAgingSelector = (state) => (0, arAgingSelector_1.getArAgingReport)(state);
40
- const tenantSelector = (0, toolkit_1.createSelector)(tenantSelector_1.getTenantsByCheckInDateSelector, tenantSelector_1.getCurrentTenant, (tenantsOrdered, currentTenant) => ({
41
- tenantsOrdered,
40
+ const tenantSelector = (0, toolkit_1.createSelector)(tenantSelector_1.getCurrentTenant, (currentTenant) => ({
42
41
  currentTenant,
43
42
  }));
44
43
  exports.getDashboard = (0, toolkit_1.createSelector)(tenantSelector, cardBalanceSelector_1.getCardBalance, cashBalanceSelector_1.getCashBalance, getOperatingExpensesForLast5Periods, getRevenueForLast4Periods, topExSelector_1.getTop6Expenses, getNetBurnOrIncomeForLast4Periods, getNetBurnOrIncomeStoryCard, getCashPositionLast5Periods, getCashInCashOutLast4Periods, insightsCardSelector_1.getInsights, companyPassportViewSelector_1.getCompanyPassportView, tasksCardSelector_1.getTasksCardReport, billPayCardSelector_1.getBillPayCardReport, reimbursementCardSelector_1.getReimbursementCardReport, apAgingSelector, arAgingSelector, referralSelector_1.getRewardsPlanCard, dashboardLayoutSelector_1.getDashboardCardsOrdered, (state) => {
@@ -18,12 +18,8 @@ const fetchFinanceStatementEpic = (actions$, state$) => actions$.pipe((0, operat
18
18
  return (0, rxjs_1.of)((0, tenantReducer_1.fetchAllTenants)(userId), (0, profitAndLossReducer_1.fetchProfitAndLoss)(), (0, balanceSheetReducer_1.fetchBalanceSheet)(), (0, cashFlowReducer_1.fetchCashFlow)());
19
19
  }
20
20
  else {
21
- const { tenantState, financeStatementState } = state;
21
+ const { financeStatementState } = state;
22
22
  const fetchActions = [];
23
- if (tenantState.fetchState !== 'In-Progress' &&
24
- !tenantState.hasValidState()) {
25
- fetchActions.push((0, tenantReducer_1.fetchAllTenants)(userId));
26
- }
27
23
  const pandLFetchState = (0, profitAndLossSelector_1.getPandLReportFetchState)(undefined, state.profitAndLossState);
28
24
  const balanceSheetFetchState = (0, balanceSheetSelector_1.getBalanceSheetFetchState)(state.balanceSheetState);
29
25
  const cashFlowFetchState = (0, cashFlowSelector_1.getCashFlowReportFetchState)(state.cashFlowState);
@@ -36,5 +36,13 @@ export interface FinanceStatementReport extends SelectorReport {
36
36
  selectedReportAndTimeframeFetchState: FetchStateAndError;
37
37
  selectedReportId: ReportID;
38
38
  dataAvailable?: DataAvailable;
39
+ /**
40
+ * Custom start/end the selected report (Accounts view only) was last fetched with for the
41
+ * selected timeframe; undefined when that fetch used the default periods.
42
+ */
43
+ selectedReportCustomDateRange?: {
44
+ endDate: string;
45
+ startDate: string;
46
+ };
39
47
  }
40
48
  export declare const getFinanceStatement: (state: RootState) => FinanceStatementReport;
@@ -164,6 +164,23 @@ exports.getFinanceStatement = (0, toolkit_1.createSelector)((state) => state.acc
164
164
  default:
165
165
  break;
166
166
  }
167
+ let customDateRangeByTimeframe;
168
+ switch (financeStatementState.selectedReportId) {
169
+ case 'profit_and_loss':
170
+ customDateRangeByTimeframe =
171
+ profitAndLossState.pandL.customDateRangeByTimeframe;
172
+ break;
173
+ case 'balance_sheet':
174
+ customDateRangeByTimeframe =
175
+ balanceSheetState.customDateRangeByTimeframe;
176
+ break;
177
+ case 'cash_flow':
178
+ customDateRangeByTimeframe = cashFlowState.customDateRangeByTimeframe;
179
+ break;
180
+ default:
181
+ break;
182
+ }
183
+ const selectedReportCustomDateRange = customDateRangeByTimeframe?.[financeStatementState.timeframe];
167
184
  return {
168
185
  reportId: 'finance_statement',
169
186
  reportTitle: '',
@@ -173,6 +190,7 @@ exports.getFinanceStatement = (0, toolkit_1.createSelector)((state) => state.acc
173
190
  allTimeframeTicks,
174
191
  balancesInTimeframe,
175
192
  selectedReportAndTimeframeFetchState,
193
+ selectedReportCustomDateRange,
176
194
  displayOrder: financeStatementState.displayOrder,
177
195
  reportFormat: financeStatementState.reportFormat,
178
196
  firstMonthOfFY,
@@ -13,10 +13,6 @@ const fetchPeoplePageEpic = (actions$, state$) => actions$.pipe((0, operators_1.
13
13
  else {
14
14
  const state = state$.value;
15
15
  const fetchActions = [];
16
- if (state.tenantState.fetchState !== 'In-Progress' &&
17
- !state.tenantState.hasValidState()) {
18
- fetchActions.push((0, tenantReducer_1.fetchAllTenants)(userId));
19
- }
20
16
  if (state.peopleState.fetchState != 'In-Progress' &&
21
17
  !state.peopleState.hasValidState()) {
22
18
  fetchActions.push((0, peopleReducer_1.fetchPeople)());