@zeniai/client-epic-state 5.0.81-betaRR0 → 5.0.81-betaRR08

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 (130) hide show
  1. package/lib/common/aiCfo/aiCfoSuggestedQuestionsPageContext.d.ts +1 -1
  2. package/lib/entity/aiCfo/aiCfoPayload.d.ts +1 -171
  3. package/lib/entity/aiCfo/aiCfoReducer.d.ts +2 -22
  4. package/lib/entity/aiCfo/aiCfoReducer.js +4 -291
  5. package/lib/entity/aiCfo/aiCfoSelector.d.ts +1 -3
  6. package/lib/entity/aiCfo/aiCfoSelector.js +1 -11
  7. package/lib/entity/aiCfo/aiCfoState.d.ts +4 -186
  8. package/lib/entity/aiCfo/aiCfoState.js +1 -23
  9. package/lib/entity/jeSchedules/jeSchedulesTypes.d.ts +1 -1
  10. package/lib/entity/monthEndCloseChecks/monthEndCloseChecksState.d.ts +1 -1
  11. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  12. package/lib/entity/snackbar/snackbarTypes.js +0 -2
  13. package/lib/entity/tenant/clearAllEpic.d.ts +2 -6
  14. package/lib/entity/tenant/clearAllEpic.js +0 -8
  15. package/lib/epic.d.ts +1 -11
  16. package/lib/epic.js +1 -11
  17. package/lib/esm/entity/aiCfo/aiCfoReducer.js +4 -291
  18. package/lib/esm/entity/aiCfo/aiCfoSelector.js +1 -10
  19. package/lib/esm/entity/aiCfo/aiCfoState.js +0 -20
  20. package/lib/esm/entity/snackbar/snackbarTypes.js +0 -2
  21. package/lib/esm/entity/tenant/clearAllEpic.js +0 -8
  22. package/lib/esm/epic.js +1 -11
  23. package/lib/esm/index.js +7 -22
  24. package/lib/esm/reducer.js +0 -12
  25. package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +3 -6
  26. package/lib/esm/view/aiCfoView/epics/createSessionAndSubmitEpic.js +2 -5
  27. package/lib/esm/view/aiCfoView/epics/createSessionEpic.js +1 -2
  28. package/lib/esm/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +2 -12
  29. package/lib/esm/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +0 -25
  30. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.js +2 -2
  31. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.js +4 -16
  32. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.js +0 -38
  33. package/lib/index.d.ts +7 -20
  34. package/lib/index.js +10 -124
  35. package/lib/reducer.d.ts +0 -12
  36. package/lib/reducer.js +0 -12
  37. package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +2 -11
  38. package/lib/view/aiCfoView/aiCfoViewReducer.js +3 -6
  39. package/lib/view/aiCfoView/epics/createSessionAndSubmitEpic.js +2 -5
  40. package/lib/view/aiCfoView/epics/createSessionEpic.js +1 -2
  41. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.d.ts +1 -8
  42. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +2 -12
  43. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  44. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +1 -1
  45. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +2 -2
  46. package/lib/view/expenseAutomationView/types/reconciliationViewState.d.ts +1 -1
  47. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +1 -1
  48. package/lib/view/people/peopleTypes.d.ts +1 -1
  49. package/lib/view/scheduleView/scheduleListView/scheduleListTypes.d.ts +1 -1
  50. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  51. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.d.ts +0 -14
  52. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +1 -27
  53. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.d.ts +2 -2
  54. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.js +1 -1
  55. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.d.ts +1 -5
  56. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.js +5 -17
  57. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.d.ts +0 -27
  58. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.js +1 -43
  59. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardState.d.ts +0 -2
  60. package/lib/view/taskManager/taskListView/taskListReducer.d.ts +1 -1
  61. package/package.json +1 -1
  62. package/lib/entity/cardPolicy/cardPolicyPayload.d.ts +0 -277
  63. package/lib/entity/cardPolicy/cardPolicyPayload.js +0 -143
  64. package/lib/entity/cardPolicy/cardPolicyReducer.d.ts +0 -19
  65. package/lib/entity/cardPolicy/cardPolicyReducer.js +0 -256
  66. package/lib/entity/cardPolicy/cardPolicySelector.d.ts +0 -32
  67. package/lib/entity/cardPolicy/cardPolicySelector.js +0 -103
  68. package/lib/entity/cardPolicy/cardPolicyState.d.ts +0 -205
  69. package/lib/entity/cardPolicy/cardPolicyState.js +0 -14
  70. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.d.ts +0 -18
  71. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.js +0 -54
  72. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.d.ts +0 -26
  73. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +0 -47
  74. package/lib/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.d.ts +0 -25
  75. package/lib/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.js +0 -39
  76. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.d.ts +0 -23
  77. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.js +0 -92
  78. package/lib/esm/entity/cardPolicy/cardPolicyPayload.js +0 -130
  79. package/lib/esm/entity/cardPolicy/cardPolicyReducer.js +0 -252
  80. package/lib/esm/entity/cardPolicy/cardPolicySelector.js +0 -79
  81. package/lib/esm/entity/cardPolicy/cardPolicyState.js +0 -9
  82. package/lib/esm/entity/cardPolicy/extractPolicyDocumentEpic.js +0 -50
  83. package/lib/esm/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +0 -43
  84. package/lib/esm/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.js +0 -35
  85. package/lib/esm/entity/cardPolicy/policyRecommendationFromUploadEpic.js +0 -88
  86. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +0 -70
  87. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +0 -22
  88. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +0 -1
  89. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +0 -56
  90. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +0 -49
  91. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +0 -42
  92. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +0 -72
  93. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +0 -21
  94. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +0 -1
  95. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +0 -56
  96. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +0 -62
  97. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +0 -39
  98. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +0 -1
  99. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +0 -53
  100. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +0 -25
  101. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.d.ts +0 -14
  102. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +0 -74
  103. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.d.ts +0 -21
  104. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +0 -28
  105. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.d.ts +0 -25
  106. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +0 -2
  107. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.d.ts +0 -19
  108. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +0 -60
  109. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.d.ts +0 -18
  110. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +0 -53
  111. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.d.ts +0 -16
  112. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +0 -46
  113. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.d.ts +0 -15
  114. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +0 -76
  115. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.d.ts +0 -21
  116. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +0 -27
  117. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.d.ts +0 -19
  118. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +0 -2
  119. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.d.ts +0 -19
  120. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +0 -60
  121. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.d.ts +0 -13
  122. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +0 -66
  123. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.d.ts +0 -32
  124. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +0 -46
  125. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.d.ts +0 -45
  126. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +0 -2
  127. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.d.ts +0 -25
  128. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +0 -57
  129. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.d.ts +0 -15
  130. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +0 -29
@@ -16,4 +16,4 @@
16
16
  *
17
17
  * @see README.md in this directory for maintenance expectations.
18
18
  */
19
- export type AiCfoSuggestedQuestionsPageContext = 'balance_sheet' | 'profit_loss' | 'vendors' | 'transactions' | 'cash_flow' | 'accounts_receivable' | 'accounts_payable' | 'transaction_details' | 'dashboard' | 'cash_balance' | 'card_balance' | 'cash_in_cash_out' | 'net_burn_or_income' | 'cash_position' | 'top_expenses' | 'revenue' | 'operating_expenses' | 'command_centre' | 'je_schedules' | 'reconciliation' | 'flux_analysis' | 'receipts' | 'mei' | 'task_checklist' | 'performance' | 'bills_list' | 'bills_details' | 'reimbursement_list' | 'reimbursement_details' | 'vendors_summary' | 'opex_by_vendor' | 'prepaid_expenses' | 'fixed_assets' | 'form_1099' | 'accrued_expenses' | 'forecast' | 'checking' | 'checking_details' | 'treasury' | 'cards' | 'cards_creation' | 'cards_detail' | 'card_policy' | 'card_policy_detail' | 'people' | 'rewards' | 'notifications';
19
+ export type AiCfoSuggestedQuestionsPageContext = 'balance_sheet' | 'profit_loss' | 'vendors' | 'transactions' | 'cash_flow' | 'accounts_receivable' | 'accounts_payable' | 'transaction_details' | 'dashboard' | 'cash_balance' | 'card_balance' | 'cash_in_cash_out' | 'net_burn_or_income' | 'cash_position' | 'top_expenses' | 'revenue' | 'operating_expenses' | 'command_centre' | 'je_schedules' | 'reconciliation' | 'flux_analysis' | 'receipts' | 'mei' | 'task_checklist' | 'performance' | 'bills_list' | 'bills_details' | 'reimbursement_list' | 'reimbursement_details' | 'vendors_summary' | 'opex_by_vendor' | 'prepaid_expenses' | 'fixed_assets' | 'form_1099' | 'accrued_expenses' | 'forecast' | 'checking' | 'checking_details' | 'treasury' | 'cards' | 'cards_detail' | 'people' | 'rewards' | 'notifications';
@@ -20,178 +20,8 @@ export interface ChartVisualizationPayload {
20
20
  lines?: string[] | null;
21
21
  y_format?: YFormatPayload;
22
22
  }
23
- export interface CardsCardOptionPayload {
24
- id: string;
25
- label: string;
26
- description?: string | null;
27
- }
28
- /**
29
- * Single AI-suggested card on the wire. The controller ships an array of
30
- * these mixing vendor and department entries; entries with
31
- * `is_suggested: true` seed step 1 of the form pre-checked, while entries
32
- * with `is_suggested: false` are available in the step-2 Card dropdown and
33
- * step-1 search but don't appear as initial rows.
34
- */
35
- export interface SuggestedCardPayload {
36
- avg_spend: number;
37
- card_name: string;
38
- card_name_id: string;
39
- card_type: 'vendor' | 'department';
40
- credit_limit: number;
41
- is_suggested: boolean;
42
- owner_id: string;
43
- }
44
- /**
45
- * Discriminated payload for the AI Card Creation interactive form. The wire
46
- * format mirrors the FE-side `CardsCreationInitialData` field-for-field
47
- * (with snake_case field names converted to camelCase by the reducer).
48
- *
49
- * - `review` (default): the AI suggests rows (vendors + departments);
50
- * user reviews them in step 1, then configures cards in step 2. The wire
51
- * format ships a flat `suggested_cards` array. Both suggested and
52
- * not-suggested entries are included; the reducer splits them into seed
53
- * rows vs. dropdown options. The legacy `team_rows` /
54
- * `suggested_owner_user_id_by_team_id` shape is also accepted for
55
- * backward compatibility with mocks and tests.
56
- * - `create` (1-step): the AI has already chosen cards; user lands
57
- * directly on the editable card table for confirmation.
58
- */
59
- export type CardsCreationInitialDataPayload = {
60
- card_options: CardsCardOptionPayload[];
61
- mode: 'review';
62
- /**
63
- * Preferred wire format: flat list of vendor/department cards with an
64
- * `is_suggested` discriminator. The reducer derives `team_rows`,
65
- * `suggested_owner_user_id_by_team_id`, and the full `cardNameOptions`
66
- * universe from this single array.
67
- */
68
- suggested_cards?: SuggestedCardPayload[];
69
- /**
70
- * Legacy/test shape — pre-shaped seed rows. Mutually exclusive with
71
- * `suggested_cards`; when both are present, `suggested_cards` wins.
72
- */
73
- suggested_owner_user_id_by_team_id?: Record<string, string | null>;
74
- team_rows?: Array<{
75
- avg_monthly_spend: string;
76
- id: string;
77
- label: string;
78
- recommended_limit: string;
79
- card_kind?: 'vendor' | 'class' | null;
80
- recommended_limit_cadence?: string | null;
81
- }>;
82
- } | {
83
- card_options: CardsCardOptionPayload[];
84
- card_rows: Array<{
85
- card_option_id: string;
86
- id: string;
87
- /**
88
- * Optional team-derived display label rendered in the card cell
89
- * trigger (e.g. "Engineering"). Drives the row's first-letter avatar
90
- * in step 2.
91
- */
92
- label?: string | null;
93
- recommended_limit?: number | null;
94
- suggested_owner_user_id?: string | null;
95
- }>;
96
- mode: 'create';
97
- };
98
- /**
99
- * Per-policy allow / block bucket on the wire. The two arrays are
100
- * independent (a draft policy may populate both, only one, or neither).
101
- */
102
- export interface DraftPolicyEntityPayload {
103
- category_codes: string[];
104
- merchant_names: string[];
105
- }
106
- /**
107
- * Spend-limit bucket per policy. `transaction` is the only cadence the
108
- * BE ships today; left open-ended for future cadences (e.g.
109
- * `monthly`, `quarterly`).
110
- */
111
- export interface DraftPolicySpendLimitsPayload {
112
- transaction: number;
113
- [cadence: string]: number | undefined;
114
- }
115
- /**
116
- * Single draft policy on the wire. The controller emits one of these
117
- * per recommended policy in `step_5_review.draft_policies`. Identity is
118
- * positional (no stable `id` from the BE); the FE synthesizes one on
119
- * decode.
120
- */
121
- export interface DraftPolicyPayload {
122
- allowed_entity: DraftPolicyEntityPayload;
123
- apply_to_cards: string[];
124
- blocked_entity: DraftPolicyEntityPayload;
125
- description: string;
126
- /** Enforcement mode for the policy (e.g. `"strict"`). Carried into
127
- * state for guided submit; ignored for `auto` / `upload`. */
128
- mode: string;
129
- name: string;
130
- required_receipt_threshold: number;
131
- spend_limits: DraftPolicySpendLimitsPayload;
132
- }
133
- /**
134
- * `step_5_review` block — the only step in `wizard_plan` the FE reads.
135
- * Steps 1–4 are intentionally not modeled.
136
- */
137
- export interface CardPolicyStep5ReviewPayload {
138
- draft_policies: DraftPolicyPayload[];
139
- /** Header text shown above the review list / wizard. */
140
- prompt: string;
141
- /** How the BE grouped the suggested policies. `"none"` today; may
142
- * surface as a header banner in a future iteration. */
143
- grouping_source?: string;
144
- }
145
- export interface CardPolicyWizardPlanPayload {
146
- step_5_review: CardPolicyStep5ReviewPayload;
147
- }
148
- /**
149
- * Upload-mode metadata that the `policy-recommendation-from-upload` API
150
- * returns alongside the wizard plan. Absent on the initial controller
151
- * response; populated after the file upload + recommendation chain.
152
- */
153
- export interface CardPolicyUploadSourcePayload {
154
- confidence_score: number;
155
- file_name: string;
156
- low_confidence_fields: string[];
157
- }
158
- /**
159
- * Discriminated payload for the AI Card Policy interactive form.
160
- * All three modes share the same `wizard_plan.step_5_review.draft_policies`
161
- * envelope; the FE renders different forms based on `mode`.
162
- *
163
- * - `auto` (1-step review): user reviews suggested policies and submits.
164
- * - `guided` (5-step wizard): Steps 1–4 seeded from `draft_policies[0]`,
165
- * Step 5 lists every draft policy.
166
- * - `upload` (3-step): upload doc → pick cards → review. Controller
167
- * responses for `mode === "upload"` arrive *before* the user uploads,
168
- * so `wizard_plan` is optional; populated after the upload-recommendation
169
- * API returns.
170
- */
171
- export type CardPolicyInitialDataPayload = {
172
- mode: 'auto';
173
- wizard_plan: CardPolicyWizardPlanPayload;
174
- } | {
175
- mode: 'guided';
176
- wizard_plan: CardPolicyWizardPlanPayload;
177
- } | {
178
- mode: 'upload';
179
- source?: CardPolicyUploadSourcePayload;
180
- wizard_plan?: CardPolicyWizardPlanPayload;
181
- };
182
- /**
183
- * Discriminated visualization payload. The FE narrows on `form_type` and
184
- * casts `payload` to the matching shape.
185
- */
186
- export type InteractiveFormVisualizationPayload = {
187
- form_type: 'cards_creation';
188
- payload: CardsCreationInitialDataPayload;
189
- } | {
190
- form_type: 'card_policy';
191
- payload: CardPolicyInitialDataPayload;
192
- };
193
23
  export interface AiCfoVisualizationPayload {
194
- data: TableVisualizationPayload | ChartVisualizationPayload | InteractiveFormVisualizationPayload | null;
24
+ data: TableVisualizationPayload | ChartVisualizationPayload | null;
195
25
  type: string | null;
196
26
  }
197
27
  export interface AiCfoAnswerPayload {
@@ -1,8 +1,7 @@
1
1
  import { ID } from '../../commonStateTypes/common';
2
2
  import { ZeniDate } from '../../zeniDayJS';
3
3
  import { AiCfoAnswerPayload, AiCfoVisualizationPayload, ChatSessionPayload, MessagePayload } from './aiCfoPayload';
4
- import { AiCfoState, AiCfoVisualization, FileAttachmentMetadata, SyntheticAiCfoAnswerKind } from './aiCfoState';
5
- import type { CardPolicyUploadSource, CardPolicyWizardPlan } from './aiCfoState';
4
+ import { AiCfoState, AiCfoVisualization, FileAttachmentMetadata } from './aiCfoState';
6
5
  export declare const initialAiCfoState: AiCfoState;
7
6
  export declare const toAiCfoVisualization: (visualization: AiCfoVisualizationPayload) => AiCfoVisualization | undefined;
8
7
  export declare const setNewSession: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
@@ -42,25 +41,6 @@ export declare const setNewSession: import("@reduxjs/toolkit").ActionCreatorWith
42
41
  }, "aiCfo/addQuestionPayload">, clearAiCfo: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"aiCfo/clearAiCfo">, deleteQuestion: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
43
42
  chatSessionId: ID;
44
43
  questionAnswerId: ID;
45
- }, "aiCfo/deleteQuestion">, updateAiCfoAnswerCardPolicyWizardPlan: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
46
- answerId: ID;
47
- chatSessionId: ID;
48
- wizardPlan: CardPolicyWizardPlan;
49
- source?: CardPolicyUploadSource;
50
- }, "aiCfo/updateAiCfoAnswerCardPolicyWizardPlan">, appendSyntheticAiCfoAnswer: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
51
- chatSessionId: ID;
52
- createdAt: ZeniDate;
53
- id: ID;
54
- kind: SyntheticAiCfoAnswerKind;
55
- entityIds?: ID[];
56
- }, "aiCfo/appendSyntheticAiCfoAnswer">, updateSyntheticAiCfoAnswer: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
57
- chatSessionId: ID;
58
- id: ID;
59
- kind: SyntheticAiCfoAnswerKind;
60
- entityIds?: ID[];
61
- }, "aiCfo/updateSyntheticAiCfoAnswer">, removeSyntheticAiCfoAnswer: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
62
- chatSessionId: ID;
63
- id: ID;
64
- }, "aiCfo/removeSyntheticAiCfoAnswer">, clearSyntheticAiCfoAnswers: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "aiCfo/clearSyntheticAiCfoAnswers">;
44
+ }, "aiCfo/deleteQuestion">;
65
45
  declare const _default: import("redux").Reducer<AiCfoState>;
66
46
  export default _default;
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.clearSyntheticAiCfoAnswers = exports.removeSyntheticAiCfoAnswer = exports.updateSyntheticAiCfoAnswer = exports.appendSyntheticAiCfoAnswer = exports.updateAiCfoAnswerCardPolicyWizardPlan = exports.deleteQuestion = exports.clearAiCfo = exports.addQuestionPayload = exports.upsertOrAddQuestionAnswerPayload = exports.upsertAnswerPayload = exports.setChatHistory = exports.setSessions = exports.clearSession = exports.setNewSession = exports.toAiCfoVisualization = exports.initialAiCfoState = void 0;
4
+ exports.deleteQuestion = exports.clearAiCfo = exports.addQuestionPayload = exports.upsertOrAddQuestionAnswerPayload = exports.upsertAnswerPayload = exports.setChatHistory = exports.setSessions = exports.clearSession = exports.setNewSession = exports.toAiCfoVisualization = exports.initialAiCfoState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  const zeniDayJS_1 = require("../../zeniDayJS");
7
7
  const aiCfoState_1 = require("./aiCfoState");
8
8
  exports.initialAiCfoState = {
9
9
  aiCfoByChatSessionId: {},
10
10
  partialQuestionAnswers: {},
11
- syntheticAnswersByChatSessionId: {},
12
11
  };
13
12
  // Utility: Merge two arrays of Q&A pairs, combining responses for the same question
14
13
  function mergeQuestionAnswerPairs(existing, newQAs) {
@@ -140,188 +139,12 @@ const toAiCfoVisualization = (visualization) => {
140
139
  if (visualization.type == null || visualization.data == null) {
141
140
  return undefined;
142
141
  }
143
- const normalizedType = (0, aiCfoState_1.toAiCfoVisualizationTypeStrict)(visualization.type) ?? 'table';
144
142
  return {
145
- type: normalizedType,
146
- data: normalizedType === 'interactive_form'
147
- ? toInteractiveFormVisualization(visualization.data)
148
- : toAiCfoVisualizationData(visualization.data),
143
+ type: (0, aiCfoState_1.toAiCfoVisualizationTypeStrict)(visualization.type) ?? 'table',
144
+ data: toAiCfoVisualizationData(visualization.data),
149
145
  };
150
146
  };
151
147
  exports.toAiCfoVisualization = toAiCfoVisualization;
152
- const toInteractiveFormVisualization = (data) => {
153
- const formType = (0, aiCfoState_1.toInteractiveFormTypeStrict)(data.form_type) ?? 'cards_creation';
154
- if (formType === 'card_policy') {
155
- return {
156
- formType: 'card_policy',
157
- payload: toCardPolicyInitialData(data.payload),
158
- };
159
- }
160
- return {
161
- formType: 'cards_creation',
162
- payload: toCardsCreationInitialData(data.payload),
163
- };
164
- };
165
- const toCardsCreationInitialData = (payload) => {
166
- const cardOptions = (payload.card_options ?? []).map((option) => ({
167
- id: option.id,
168
- label: option.label,
169
- description: option.description ?? undefined,
170
- }));
171
- if (payload.mode === 'create') {
172
- return {
173
- mode: 'create',
174
- cardOptions,
175
- cardRows: (payload.card_rows ?? []).map((row) => ({
176
- cardOptionId: row.card_option_id,
177
- id: row.id,
178
- label: row.label ?? undefined,
179
- recommendedLimit: row.recommended_limit ?? undefined,
180
- suggestedOwnerUserId: row.suggested_owner_user_id ?? undefined,
181
- })),
182
- };
183
- }
184
- // Preferred wire format: a flat `suggested_cards` array with an
185
- // `is_suggested` discriminator. The adapter splits it into seed rows,
186
- // owner map, and the full dropdown universe.
187
- if (payload.suggested_cards != null) {
188
- return fromSuggestedCards(payload.suggested_cards, cardOptions);
189
- }
190
- // Legacy / test shape: backend already pre-shapes seeds. Synthesize an
191
- // empty `cardNameOptions` (step 2 dropdown still works via row-self ids).
192
- const teamRows = (payload.team_rows ?? []).map((row) => ({
193
- avgMonthlySpend: row.avg_monthly_spend,
194
- cardKind: (row.card_kind ?? 'vendor'),
195
- id: row.id,
196
- label: row.label,
197
- recommendedLimit: row.recommended_limit,
198
- recommendedLimitCadence: row.recommended_limit_cadence ?? undefined,
199
- }));
200
- return {
201
- mode: 'review',
202
- cardOptions,
203
- cardNameOptions: teamRows.map((row) => ({
204
- id: row.id,
205
- kind: row.cardKind,
206
- label: row.label,
207
- })),
208
- suggestedOwnerUserIdByTeamId: Object.fromEntries(Object.entries(payload.suggested_owner_user_id_by_team_id ?? {}).map(([teamId, userId]) => [teamId, userId ?? undefined])),
209
- teamRows,
210
- };
211
- };
212
- const CURRENCY_FORMATTER = new Intl.NumberFormat('en-US', {
213
- style: 'currency',
214
- currency: 'USD',
215
- maximumFractionDigits: 0,
216
- });
217
- const fromSuggestedCards = (suggestedCards, cardOptions) => {
218
- const ordered = [...suggestedCards].sort((a, b) => {
219
- if (a.card_type === b.card_type) {
220
- return 0;
221
- }
222
- return a.card_type === 'vendor' ? -1 : 1;
223
- });
224
- const withUniqueIds = withSynthesizedIds(ordered);
225
- const teamRows = withUniqueIds
226
- .filter(({ card }) => card.is_suggested)
227
- .map(({ card, uniqueId }) => ({
228
- avgMonthlySpend: CURRENCY_FORMATTER.format(card.avg_spend),
229
- cardKind: card.card_type === 'department'
230
- ? 'class'
231
- : 'vendor',
232
- id: uniqueId,
233
- label: card.card_name,
234
- recommendedLimit: CURRENCY_FORMATTER.format(card.credit_limit),
235
- recommendedLimitCadence: 'Monthly',
236
- }));
237
- const suggestedOwnerUserIdByTeamId = Object.fromEntries(withUniqueIds
238
- .filter(({ card }) => card.is_suggested)
239
- .map(({ card, uniqueId }) => [uniqueId, card.owner_id]));
240
- const cardNameOptions = withUniqueIds.map(({ card, uniqueId }) => ({
241
- id: uniqueId,
242
- kind: card.card_type === 'department'
243
- ? 'class'
244
- : 'vendor',
245
- label: card.card_name,
246
- }));
247
- return {
248
- mode: 'review',
249
- cardOptions,
250
- cardNameOptions,
251
- suggestedOwnerUserIdByTeamId,
252
- teamRows,
253
- };
254
- };
255
- /**
256
- * Stamp each suggested card with a stable unique id derived from its
257
- * `card_name_id`. If two cards in the same payload share the same
258
- * `card_name_id` (which happens in the current sample payload where
259
- * `card_name_id` is the literal `"vendor_uuid"`), fall back to a
260
- * synthesized id `${kind}__${card_name_id}__${index}` so RHF row keying
261
- * stays unique.
262
- */
263
- const withSynthesizedIds = (cards) => {
264
- const seen = new Set();
265
- return cards.map((card, index) => {
266
- const preferred = card.card_name_id;
267
- if (preferred != null && preferred !== '' && !seen.has(preferred)) {
268
- seen.add(preferred);
269
- return { card, uniqueId: preferred };
270
- }
271
- const synthesized = `${card.card_type}__${preferred ?? 'unknown'}__${index}`;
272
- seen.add(synthesized);
273
- return { card, uniqueId: synthesized };
274
- });
275
- };
276
- const toCardPolicyDraftPolicy = (payload, index) => ({
277
- id: `draft-${index}`,
278
- name: payload.name,
279
- description: payload.description ?? '',
280
- mode: payload.mode,
281
- allowedEntity: {
282
- categoryCodes: payload.allowed_entity?.category_codes ?? [],
283
- merchantNames: payload.allowed_entity?.merchant_names ?? [],
284
- },
285
- blockedEntity: {
286
- categoryCodes: payload.blocked_entity?.category_codes ?? [],
287
- merchantNames: payload.blocked_entity?.merchant_names ?? [],
288
- },
289
- applyToCards: payload.apply_to_cards ?? [],
290
- requiredReceiptThreshold: payload.required_receipt_threshold ?? 0,
291
- spendLimits: {
292
- transaction: payload.spend_limits?.transaction ?? 0,
293
- },
294
- });
295
- const toCardPolicyStep5Review = (payload) => ({
296
- draftPolicies: (payload.draft_policies ?? []).map(toCardPolicyDraftPolicy),
297
- groupingSource: payload.grouping_source ?? 'none',
298
- prompt: payload.prompt ?? '',
299
- });
300
- const toCardPolicyWizardPlan = (payload) => ({
301
- step5Review: toCardPolicyStep5Review(payload.step_5_review),
302
- });
303
- const toCardPolicyUploadSource = (payload) => ({
304
- confidenceScore: payload.confidence_score,
305
- fileName: payload.file_name,
306
- lowConfidenceFields: payload.low_confidence_fields ?? [],
307
- });
308
- const toCardPolicyInitialData = (payload) => {
309
- if (payload.mode === 'upload') {
310
- return {
311
- policyKind: 'upload',
312
- wizardPlan: payload.wizard_plan != null
313
- ? toCardPolicyWizardPlan(payload.wizard_plan)
314
- : undefined,
315
- source: payload.source != null
316
- ? toCardPolicyUploadSource(payload.source)
317
- : undefined,
318
- };
319
- }
320
- return {
321
- policyKind: payload.mode,
322
- wizardPlan: toCardPolicyWizardPlan(payload.wizard_plan),
323
- };
324
- };
325
148
  const toAiCfoVisualizationData = (data) => {
326
149
  if ('x' in data && 'y' in data) {
327
150
  // Normalize y to always be an array
@@ -635,118 +458,9 @@ const aiCfo = (0, toolkit_1.createSlice)({
635
458
  session.questionAnswers.push(qa);
636
459
  }
637
460
  },
638
- /**
639
- * Patch the `card_policy` interactive-form payload for a specific
640
- * answer in a chat session to merge in the wizard plan + upload
641
- * source metadata returned by
642
- * `POST /cards/1.0/ai-cfo/policy-recommendation-from-upload`.
643
- *
644
- * Dispatched by the recommendation epic after a successful response;
645
- * the wizard re-renders Steps 2 + 3 of the upload variant once the
646
- * payload becomes a populated `CardPolicyInitialData` with
647
- * `policyKind: "upload"` + `wizardPlan` + `source`.
648
- *
649
- * No-op when the target answer / chat session / form payload is
650
- * missing or isn't an upload-mode card-policy interactive form —
651
- * the bridge epic is best-effort and silently drops in edge cases
652
- * (e.g. the user closed the chat before recommendation returned).
653
- */
654
- updateAiCfoAnswerCardPolicyWizardPlan(draft, action) {
655
- const { answerId, chatSessionId, source, wizardPlan } = action.payload;
656
- const session = draft.aiCfoByChatSessionId[chatSessionId];
657
- if (session == null) {
658
- return;
659
- }
660
- const qa = session.questionAnswers.find((entry) => entry.questionAnswerId === answerId);
661
- if (qa == null) {
662
- return;
663
- }
664
- for (const response of Object.values(qa.responses)) {
665
- const visualization = response?.content.visualization;
666
- if (visualization == null ||
667
- visualization.type !== 'interactive_form') {
668
- continue;
669
- }
670
- const data = visualization.data;
671
- if (data.formType !== 'card_policy' ||
672
- data.payload.policyKind !== 'upload') {
673
- continue;
674
- }
675
- data.payload = {
676
- ...data.payload,
677
- wizardPlan,
678
- source: source ?? data.payload.source,
679
- };
680
- }
681
- },
682
- /**
683
- * Append a client-synthesized answer bubble to a chat session. Used by
684
- * the AI CFO cards/policy create flow to render a "Creating…" placeholder
685
- * in the drawer while the underlying mutation runs.
686
- *
687
- * The caller is responsible for generating a stable `id` (so the same
688
- * bubble can later be updated in place via `updateSyntheticAiCfoAnswer`
689
- * once the mutation completes) and a `createdAt` timestamp so the
690
- * renderer can interleave synthetic bubbles with streamed Q&A pairs in
691
- * chronological order.
692
- */
693
- appendSyntheticAiCfoAnswer(draft, action) {
694
- const { chatSessionId, id, kind, createdAt, entityIds } = action.payload;
695
- if (draft.syntheticAnswersByChatSessionId[chatSessionId] == null) {
696
- draft.syntheticAnswersByChatSessionId[chatSessionId] = [];
697
- }
698
- draft.syntheticAnswersByChatSessionId[chatSessionId].push({
699
- id,
700
- kind,
701
- entityIds: entityIds ?? [],
702
- createdAt,
703
- });
704
- },
705
- /**
706
- * Update an existing synthetic answer bubble in place. Typically called
707
- * when the create mutation completes: the screen transitions the bubble
708
- * from `creating_*` to `created_*` and populates `entityIds` with the
709
- * newly created cards / policy templates.
710
- *
711
- * No-op when the target bubble is missing (e.g. the session was cleared
712
- * before the mutation returned).
713
- */
714
- updateSyntheticAiCfoAnswer(draft, action) {
715
- const { chatSessionId, id, kind, entityIds } = action.payload;
716
- const list = draft.syntheticAnswersByChatSessionId[chatSessionId];
717
- if (list == null) {
718
- return;
719
- }
720
- const entry = list.find((item) => item.id === id);
721
- if (entry == null) {
722
- return;
723
- }
724
- entry.kind = kind;
725
- if (entityIds != null) {
726
- entry.entityIds = entityIds;
727
- }
728
- },
729
- /**
730
- * Remove a single synthetic answer bubble (e.g. when the user manually
731
- * dismisses it or the mutation errors out and we want to fall back to
732
- * an inline error snackbar).
733
- */
734
- removeSyntheticAiCfoAnswer(draft, action) {
735
- const { chatSessionId, id } = action.payload;
736
- const list = draft.syntheticAnswersByChatSessionId[chatSessionId];
737
- if (list == null) {
738
- return;
739
- }
740
- draft.syntheticAnswersByChatSessionId[chatSessionId] = list.filter((item) => item.id !== id);
741
- },
742
- /** Clear every synthetic bubble for a session. */
743
- clearSyntheticAiCfoAnswers(draft, action) {
744
- delete draft.syntheticAnswersByChatSessionId[action.payload];
745
- },
746
461
  clearSession(draft, action) {
747
462
  const sessionId = action.payload;
748
463
  delete draft.aiCfoByChatSessionId[sessionId];
749
- delete draft.syntheticAnswersByChatSessionId[sessionId];
750
464
  // Clear partial Q&A if it belongs to the cleared session
751
465
  if (draft.partialQuestionAnswers?.[sessionId] != null) {
752
466
  draft.partialQuestionAnswers[sessionId] = undefined;
@@ -755,7 +469,6 @@ const aiCfo = (0, toolkit_1.createSlice)({
755
469
  clearAiCfo(draft) {
756
470
  draft.aiCfoByChatSessionId = {};
757
471
  draft.partialQuestionAnswers = {};
758
- draft.syntheticAnswersByChatSessionId = {};
759
472
  },
760
473
  deleteQuestion(draft, action) {
761
474
  const { chatSessionId, questionAnswerId } = action.payload;
@@ -780,5 +493,5 @@ const toChatSession = (chatSessionPayload) => {
780
493
  createdAt: (0, zeniDayJS_1.date)(created_at),
781
494
  };
782
495
  };
783
- _a = aiCfo.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.clearAiCfo = _a.clearAiCfo, exports.deleteQuestion = _a.deleteQuestion, exports.updateAiCfoAnswerCardPolicyWizardPlan = _a.updateAiCfoAnswerCardPolicyWizardPlan, exports.appendSyntheticAiCfoAnswer = _a.appendSyntheticAiCfoAnswer, exports.updateSyntheticAiCfoAnswer = _a.updateSyntheticAiCfoAnswer, exports.removeSyntheticAiCfoAnswer = _a.removeSyntheticAiCfoAnswer, exports.clearSyntheticAiCfoAnswers = _a.clearSyntheticAiCfoAnswers;
496
+ _a = aiCfo.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.clearAiCfo = _a.clearAiCfo, exports.deleteQuestion = _a.deleteQuestion;
784
497
  exports.default = aiCfo.reducer;
@@ -1,15 +1,13 @@
1
1
  import { ID } from '../../commonStateTypes/common';
2
- import { AiCfoQuestionWithAnswer, AiCfoState, ChatSession, SyntheticAiCfoAnswer } from './aiCfoState';
2
+ import { AiCfoQuestionWithAnswer, AiCfoState, ChatSession } from './aiCfoState';
3
3
  export declare function getAllQuestionAnswersForChatSession(state: AiCfoState, chatSessionId: ID): AiCfoQuestionWithAnswer[];
4
4
  export declare function getQuestionAnswerByIdForChatSession(state: AiCfoState, chatSessionId: ID, questionAnswerId: ID): AiCfoQuestionWithAnswer | undefined;
5
5
  export declare function getAllQuestionsForChatSession(state: AiCfoState, chatSessionId: ID): string[];
6
6
  export interface AiCfoSelectorView {
7
7
  allSessionsWithOrderedQuestionAnswers: ChatSessionWithOrderedQuestionAnswers[];
8
- syntheticAnswersByChatSessionId: Record<ID, SyntheticAiCfoAnswer[]>;
9
8
  }
10
9
  export interface ChatSessionWithOrderedQuestionAnswers {
11
10
  chatSession: ChatSession;
12
11
  questionAnswers: AiCfoQuestionWithAnswer[];
13
12
  }
14
13
  export declare function getAiCfoSelectorView(state: AiCfoState): AiCfoSelectorView;
15
- export declare function getSyntheticAiCfoAnswersForChatSession(state: AiCfoState, chatSessionId: ID): SyntheticAiCfoAnswer[];
@@ -4,7 +4,6 @@ exports.getAllQuestionAnswersForChatSession = getAllQuestionAnswersForChatSessio
4
4
  exports.getQuestionAnswerByIdForChatSession = getQuestionAnswerByIdForChatSession;
5
5
  exports.getAllQuestionsForChatSession = getAllQuestionsForChatSession;
6
6
  exports.getAiCfoSelectorView = getAiCfoSelectorView;
7
- exports.getSyntheticAiCfoAnswersForChatSession = getSyntheticAiCfoAnswersForChatSession;
8
7
  function getAllQuestionAnswersForChatSession(state, chatSessionId) {
9
8
  const arr = state.aiCfoByChatSessionId[chatSessionId]?.questionAnswers ?? [];
10
9
  return arr
@@ -39,14 +38,5 @@ function getAiCfoSelectorView(state) {
39
38
  : [],
40
39
  }))
41
40
  .sort((a, b) => b.chatSession.createdAt.valueOf() - a.chatSession.createdAt.valueOf());
42
- return {
43
- allSessionsWithOrderedQuestionAnswers,
44
- syntheticAnswersByChatSessionId: state.syntheticAnswersByChatSessionId ?? {},
45
- };
46
- }
47
- function getSyntheticAiCfoAnswersForChatSession(state, chatSessionId) {
48
- const arr = state.syntheticAnswersByChatSessionId?.[chatSessionId] ?? [];
49
- return arr
50
- .slice()
51
- .sort((a, b) => a.createdAt.valueOf() - b.createdAt.valueOf());
41
+ return { allSessionsWithOrderedQuestionAnswers };
52
42
  }