@firela/api-types 0.0.0-canary.8cbdced0 → 0.0.0-canary.9256c41b

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.
@@ -6,18 +6,12 @@ export const $CreateAccountDto = {
6
6
  path: {
7
7
  type: 'string',
8
8
  description: 'Account path (hierarchical, colon-separated)',
9
- example: 'Assets:CN:Bank:ICBC:Checking'
10
- },
11
- displayName: {
12
- type: 'string',
13
- description:
14
- 'Display name to distinguish accounts at the same path (default: "")',
15
- example: '工资卡'
9
+ example: 'Assets:CN:ICBC:Checking'
16
10
  },
17
11
  openDate: {
18
12
  format: 'date-time',
19
13
  type: 'string',
20
- description: 'Account open date',
14
+ description: 'Account open date (server defaults to today)',
21
15
  example: '2024-01-01'
22
16
  },
23
17
  currencies: {
@@ -45,26 +39,22 @@ export const $CreateAccountDto = {
45
39
  templatePath: {
46
40
  type: 'string',
47
41
  description: 'Reference to account-standards template path',
48
- example: 'Assets:CN:Bank:ICBC:Checking'
42
+ example: 'Assets:CN:Checking'
49
43
  },
50
44
  isCustom: {
51
45
  type: 'boolean',
52
46
  description: 'Whether this is a custom (user-created) account',
53
47
  default: false
54
48
  },
55
- i18nKey: {
56
- type: 'string',
57
- description: 'i18n key for display name (overrides template)',
58
- example: 'account.custom.mybank'
59
- },
60
49
  icon: {
61
50
  type: 'string',
62
51
  description: 'Icon identifier (overrides template)',
63
52
  example: 'bank-custom'
64
53
  },
65
- openMeta: {
54
+ openDirectiveMeta: {
66
55
  type: 'object',
67
- description: 'Additional metadata',
56
+ description:
57
+ 'Open directive metadata (NOT an opening-balance amount — use the opening-balance endpoint)',
68
58
  example: {
69
59
  branch: 'Downtown',
70
60
  accountNumber: '1234'
@@ -76,7 +66,7 @@ export const $CreateAccountDto = {
76
66
  example: 'c98e5d4a-2f71-4a5a-bb3c-92c9f231d5e2'
77
67
  }
78
68
  },
79
- required: ['path', 'openDate']
69
+ required: ['path']
80
70
  } as const;
81
71
 
82
72
  export const $AccountResponseDto = {
@@ -90,13 +80,7 @@ export const $AccountResponseDto = {
90
80
  path: {
91
81
  type: 'string',
92
82
  description: 'Account path (hierarchical, colon-separated)',
93
- example: 'Assets:CN:Bank:ICBC:Checking'
94
- },
95
- displayName: {
96
- type: 'string',
97
- description:
98
- 'Display name distinguishing multiple accounts at the same path',
99
- example: '工资卡'
83
+ example: 'Assets:CN:ICBC:Checking'
100
84
  },
101
85
  type: {
102
86
  type: 'string',
@@ -145,26 +129,26 @@ export const $AccountResponseDto = {
145
129
  templatePath: {
146
130
  type: 'string',
147
131
  description: 'Template path reference',
148
- example: 'Assets:CN:Bank:ICBC:Checking'
132
+ example: 'Assets:CN:Checking'
149
133
  },
150
134
  isCustom: {
151
135
  type: 'boolean',
152
136
  description: 'Whether this is a custom (user-created) account',
153
137
  example: false
154
138
  },
155
- i18nKey: {
139
+ displayName: {
156
140
  type: 'string',
157
- description: 'i18n key for display name',
158
- example: 'account.assets.cn.bank.icbc.checking'
141
+ description: 'Localized display name (ADR-0114, read-time projection)',
142
+ example: 'Checking'
159
143
  },
160
144
  icon: {
161
145
  type: 'string',
162
146
  description: 'Icon identifier',
163
147
  example: 'bank-icbc'
164
148
  },
165
- openMeta: {
149
+ openDirectiveMeta: {
166
150
  type: 'object',
167
- description: 'Account metadata',
151
+ description: 'Open directive metadata (ADR-0115 Decision 9)',
168
152
  example: {
169
153
  branch: 'Downtown'
170
154
  }
@@ -192,7 +176,6 @@ export const $AccountResponseDto = {
192
176
  required: [
193
177
  'id',
194
178
  'path',
195
- 'displayName',
196
179
  'type',
197
180
  'status',
198
181
  'openDate',
@@ -225,11 +208,6 @@ export const $AccountListResponseDto = {
225
208
  export const $UpdateAccountDto = {
226
209
  type: 'object',
227
210
  properties: {
228
- displayName: {
229
- type: 'string',
230
- description: 'Display name to distinguish accounts at the same path',
231
- example: '招行工资卡'
232
- },
233
211
  currencies: {
234
212
  description: 'Allowed currencies (null = no restriction)',
235
213
  example: ['CNY', 'USD'],
@@ -251,19 +229,15 @@ export const $UpdateAccountDto = {
251
229
  'NONE'
252
230
  ]
253
231
  },
254
- i18nKey: {
255
- type: 'string',
256
- description: 'i18n key for display name',
257
- example: 'account.custom.mybank'
258
- },
259
232
  icon: {
260
233
  type: 'string',
261
234
  description: 'Icon identifier',
262
235
  example: 'bank-custom'
263
236
  },
264
- openMeta: {
237
+ openDirectiveMeta: {
265
238
  type: 'object',
266
- description: 'Additional metadata (merged with existing)',
239
+ description:
240
+ 'Open directive metadata (merged with existing; NOT an opening-balance amount)',
267
241
  example: {
268
242
  branch: 'Uptown'
269
243
  }
@@ -310,13 +284,47 @@ export const $ReopenAccountDto = {
310
284
  }
311
285
  } as const;
312
286
 
287
+ export const $CreateOpeningBalanceDto = {
288
+ type: 'object',
289
+ properties: {
290
+ amount: {
291
+ type: 'number',
292
+ description: 'Opening balance amount (non-negative)',
293
+ example: 1000
294
+ },
295
+ currency: {
296
+ type: 'string',
297
+ description: 'Currency code',
298
+ example: 'CNY'
299
+ },
300
+ date: {
301
+ format: 'date-time',
302
+ type: 'string',
303
+ description: 'Opening-balance date (defaults to now)',
304
+ example: '2024-01-01'
305
+ }
306
+ },
307
+ required: ['amount', 'currency']
308
+ } as const;
309
+
310
+ export const $OpeningBalanceResultDto = {
311
+ type: 'object',
312
+ properties: {
313
+ transactionId: {
314
+ type: 'string',
315
+ description: 'Created opening-balance transaction id.'
316
+ }
317
+ },
318
+ required: ['transactionId']
319
+ } as const;
320
+
313
321
  export const $AccountStandardResponseDto = {
314
322
  type: 'object',
315
323
  properties: {
316
324
  path: {
317
325
  type: 'string',
318
326
  description: 'Account path (hierarchical, colon-separated)',
319
- example: 'Assets:CN:Bank:ICBC:Checking'
327
+ example: 'Assets:CN:Checking'
320
328
  },
321
329
  type: {
322
330
  type: 'string',
@@ -324,11 +332,6 @@ export const $AccountStandardResponseDto = {
324
332
  enum: ['Assets', 'Liabilities', 'Income', 'Expenses', 'Equity'],
325
333
  example: 'Assets'
326
334
  },
327
- i18nKey: {
328
- type: 'string',
329
- description: 'i18n key for localized display name',
330
- example: 'account.assets.cn.bank.icbc.checking'
331
- },
332
335
  name: {
333
336
  type: 'string',
334
337
  description: 'Short localized display name',
@@ -353,7 +356,7 @@ export const $AccountStandardResponseDto = {
353
356
  example: 'bank-icbc'
354
357
  }
355
358
  },
356
- required: ['path', 'type', 'i18nKey', 'description', 'tags', 'icon']
359
+ required: ['path', 'type', 'description', 'tags', 'icon']
357
360
  } as const;
358
361
 
359
362
  export const $AccountStandardListResponseDto = {
@@ -383,18 +386,13 @@ export const $AccountStandardListResponseDto = {
383
386
  export const $TemplateMetadataDto = {
384
387
  type: 'object',
385
388
  properties: {
386
- extendable: {
387
- type: 'boolean',
388
- description: 'Whether this path can be extended',
389
- example: true
390
- },
391
389
  rootType: {
392
390
  type: 'string',
393
391
  description: 'Root account type',
394
392
  example: 'Assets'
395
393
  }
396
394
  },
397
- required: ['extendable', 'rootType']
395
+ required: ['rootType']
398
396
  } as const;
399
397
 
400
398
  export const $TemplateMetadataResponseDto = {
@@ -533,7 +531,7 @@ export const $CreatePostingDto = {
533
531
  type: 'string',
534
532
  description:
535
533
  'Account name in Beancount format (must start with uppercase, colon-separated)',
536
- example: 'Assets:Bank:Checking'
534
+ example: 'Assets:Checking'
537
535
  },
538
536
  units: {
539
537
  type: 'string',
@@ -692,7 +690,7 @@ export const $PostingResponseDto = {
692
690
  account: {
693
691
  type: 'string',
694
692
  description: 'Account name',
695
- example: 'Assets:Bank:Checking'
693
+ example: 'Assets:Checking'
696
694
  },
697
695
  units: {
698
696
  type: 'string',
@@ -1058,7 +1056,7 @@ export const $PostingDetailDto = {
1058
1056
  account: {
1059
1057
  type: 'string',
1060
1058
  description: 'Fully-qualified Beancount account path',
1061
- example: 'Assets:Bank:Checking'
1059
+ example: 'Assets:Checking'
1062
1060
  },
1063
1061
  units: {
1064
1062
  type: 'string',
@@ -1247,6 +1245,77 @@ export const $TransactionDetailDto = {
1247
1245
  ]
1248
1246
  } as const;
1249
1247
 
1248
+ export const $BalanceByCurrencyDto = {
1249
+ type: 'object',
1250
+ properties: {
1251
+ currency: {
1252
+ type: 'string',
1253
+ description: 'ISO 4217 currency code',
1254
+ example: 'CNY'
1255
+ },
1256
+ balance: {
1257
+ type: 'string',
1258
+ description: 'Balance amount',
1259
+ example: '50000.00'
1260
+ }
1261
+ },
1262
+ required: ['currency', 'balance']
1263
+ } as const;
1264
+
1265
+ export const $ExchangeRateWarningDto = {
1266
+ type: 'object',
1267
+ properties: {
1268
+ type: {
1269
+ type: 'string',
1270
+ description: 'Warning type',
1271
+ example: 'MISSING_EXCHANGE_RATE'
1272
+ },
1273
+ currency: {
1274
+ type: 'string',
1275
+ description: 'Currency without exchange rate',
1276
+ example: 'EUR'
1277
+ },
1278
+ totalAmount: {
1279
+ type: 'string',
1280
+ description: 'Total amount affected',
1281
+ example: '1000.00'
1282
+ }
1283
+ },
1284
+ required: ['type', 'currency', 'totalAmount']
1285
+ } as const;
1286
+
1287
+ export const $TransactionListSummaryDto = {
1288
+ type: 'object',
1289
+ properties: {
1290
+ totalAmount: {
1291
+ type: 'string',
1292
+ description:
1293
+ 'Partial converted total in base currency (rated currencies only, raw Beancount sign). When warnings is non-empty this excludes currencies missing an FX rate; may be "0.00" if ALL non-base currencies lack a rate. Converted at the dateTo (or current) available rate.',
1294
+ example: '-6000.00'
1295
+ },
1296
+ currency: {
1297
+ type: 'string',
1298
+ description: 'Base currency (ISO 4217)',
1299
+ example: 'CNY'
1300
+ },
1301
+ balanceByCurrency: {
1302
+ description: 'Raw (unconverted) balance per currency',
1303
+ type: 'array',
1304
+ items: {
1305
+ $ref: '#/components/schemas/BalanceByCurrencyDto'
1306
+ }
1307
+ },
1308
+ warnings: {
1309
+ description: 'Currencies missing an FX rate (omitted when empty)',
1310
+ type: 'array',
1311
+ items: {
1312
+ $ref: '#/components/schemas/ExchangeRateWarningDto'
1313
+ }
1314
+ }
1315
+ },
1316
+ required: ['totalAmount', 'currency', 'balanceByCurrency']
1317
+ } as const;
1318
+
1250
1319
  export const $TransactionListResponseDto = {
1251
1320
  type: 'object',
1252
1321
  properties: {
@@ -1271,6 +1340,15 @@ export const $TransactionListResponseDto = {
1271
1340
  type: 'number',
1272
1341
  description: 'Number of items skipped',
1273
1342
  example: 0
1343
+ },
1344
+ summary: {
1345
+ description:
1346
+ 'Amount summary for the full filtered set (#514). Present only when the request has a single account OR category viewpoint; omitted for search-only / plain-list / dual-perspective requests.',
1347
+ allOf: [
1348
+ {
1349
+ $ref: '#/components/schemas/TransactionListSummaryDto'
1350
+ }
1351
+ ]
1274
1352
  }
1275
1353
  },
1276
1354
  required: ['data', 'total', 'limit', 'offset']
@@ -1370,7 +1448,7 @@ export const $BalanceResponseDto = {
1370
1448
  account: {
1371
1449
  type: 'string',
1372
1450
  description: 'Account name',
1373
- example: 'Assets:Bank:Checking'
1451
+ example: 'Assets:Checking'
1374
1452
  },
1375
1453
  balance: {
1376
1454
  type: 'string',
@@ -1397,7 +1475,7 @@ export const $MultiCurrencyBalanceResponseDto = {
1397
1475
  account: {
1398
1476
  type: 'string',
1399
1477
  description: 'Account name',
1400
- example: 'Assets:Bank:Checking'
1478
+ example: 'Assets:Checking'
1401
1479
  },
1402
1480
  balances: {
1403
1481
  type: 'object',
@@ -1453,7 +1531,7 @@ export const $TransactionSummaryDto = {
1453
1531
  accountName: {
1454
1532
  type: 'string',
1455
1533
  description: 'Source account name (first posting)',
1456
- example: 'Assets:Bank:Checking'
1534
+ example: 'Assets:Checking'
1457
1535
  },
1458
1536
  sourceType: {
1459
1537
  type: 'string',
@@ -2745,127 +2823,284 @@ export const $UpdateCommodityDto = {
2745
2823
  }
2746
2824
  } as const;
2747
2825
 
2748
- export const $CreateRecurringRuleDto = {
2826
+ export const $CreateBeanPriceDto = {
2749
2827
  type: 'object',
2750
2828
  properties: {
2751
- name: {
2752
- type: 'string',
2753
- description: 'Rule name (unique per user)',
2754
- maxLength: 100
2755
- },
2756
- icon: {
2757
- type: 'string',
2758
- description: 'Icon emoji',
2759
- maxLength: 10
2760
- },
2761
- frequency: {
2762
- type: 'string',
2763
- description: 'Recurring frequency',
2764
- enum: [
2765
- 'WEEKLY',
2766
- 'BIWEEKLY',
2767
- 'MONTHLY',
2768
- 'BIMONTHLY',
2769
- 'QUARTERLY',
2770
- 'YEARLY',
2771
- 'CUSTOM'
2772
- ]
2773
- },
2774
- expectedAmount: {
2775
- type: 'number',
2776
- description: 'Expected amount (positive number)',
2777
- minimum: 0
2778
- },
2779
- expectedDay: {
2780
- type: 'number',
2781
- description: 'Expected day of month (1-31)',
2782
- minimum: 1,
2783
- maximum: 31
2784
- },
2785
- customIntervalDays: {
2786
- type: 'number',
2787
- description: 'Custom interval in days (required for CUSTOM frequency)',
2788
- minimum: 1
2789
- },
2790
2829
  currency: {
2791
2830
  type: 'string',
2792
- description: 'Currency code',
2793
- default: 'CNY',
2794
- maxLength: 10
2831
+ description: 'Currency being priced (e.g., USD, AAPL, BTC)',
2832
+ example: 'USD'
2795
2833
  },
2796
- matchPayeePattern: {
2834
+ quoteCurrency: {
2797
2835
  type: 'string',
2798
- description: 'Payee matching pattern (supports wildcards)',
2799
- maxLength: 200
2836
+ description: 'Quote currency (pricing currency, e.g., CNY, EUR)',
2837
+ example: 'CNY'
2800
2838
  },
2801
- matchAmountTolerance: {
2839
+ amount: {
2802
2840
  type: 'number',
2803
- description: 'Amount tolerance percentage (0-1)',
2804
- default: 0.075,
2805
- minimum: 0,
2806
- maximum: 1
2807
- },
2808
- defaultExpenseAccount: {
2809
- type: 'string',
2810
- description: 'Default expense account for auto-create',
2811
- maxLength: 200
2812
- },
2813
- defaultPaymentAccount: {
2814
- type: 'string',
2815
- description: 'Default payment account for auto-create',
2816
- maxLength: 200
2817
- },
2818
- defaultPayee: {
2819
- type: 'string',
2820
- description: 'Default payee for auto-create',
2821
- maxLength: 200
2822
- },
2823
- autoCreate: {
2824
- type: 'boolean',
2825
- description: 'Auto-create transaction when expected date arrives',
2826
- default: false
2841
+ description:
2842
+ 'Price amount (MUST be >= 0 per Beancount spec, supports up to 15 decimal places). Zero allowed for conversion entries, negative strictly prohibited.',
2843
+ example: 175.5,
2844
+ minimum: 0
2827
2845
  },
2828
- startDate: {
2846
+ date: {
2829
2847
  type: 'string',
2830
- description: 'Rule start date (ISO format)'
2848
+ description: 'Price date (ISO 8601 format)',
2849
+ example: '2024-11-05'
2831
2850
  },
2832
- endDate: {
2833
- type: 'string',
2834
- description: 'Rule end date (ISO format)'
2851
+ metadata: {
2852
+ type: 'object',
2853
+ description:
2854
+ 'Metadata (validated by Zod schema, max field lengths enforced)',
2855
+ example: {
2856
+ source: 'MANUAL',
2857
+ note: 'Bank valuation report',
2858
+ confidence: 0.95
2859
+ }
2835
2860
  }
2836
2861
  },
2837
- required: [
2838
- 'name',
2839
- 'frequency',
2840
- 'expectedAmount',
2841
- 'currency',
2842
- 'matchAmountTolerance',
2843
- 'autoCreate'
2844
- ]
2862
+ required: ['currency', 'quoteCurrency', 'amount', 'date']
2845
2863
  } as const;
2846
2864
 
2847
- export const $RecurringRuleResponseDto = {
2865
+ export const $PriceResponseDto = {
2848
2866
  type: 'object',
2849
2867
  properties: {
2850
2868
  id: {
2851
2869
  type: 'string',
2852
- description: 'Rule ID'
2870
+ description: 'Unique identifier',
2871
+ example: 'uuid-123-456'
2853
2872
  },
2854
2873
  userId: {
2855
2874
  type: 'string',
2856
- description: 'User ID'
2875
+ description: 'User ID (owner of the price)',
2876
+ example: 'user-123'
2857
2877
  },
2858
- name: {
2878
+ currency: {
2859
2879
  type: 'string',
2860
- description: 'Rule name'
2861
- },
2862
- icon: {
2863
- type: 'object',
2864
- description: 'Icon emoji'
2880
+ description: 'Currency being priced (e.g., USD, AAPL, BTC)',
2881
+ example: 'BTC'
2865
2882
  },
2866
- frequency: {
2883
+ quoteCurrency: {
2867
2884
  type: 'string',
2868
- description: 'Recurring frequency'
2885
+ description: 'Quote currency (pricing currency, e.g., USD, CNY)',
2886
+ example: 'USD'
2887
+ },
2888
+ amount: {
2889
+ type: 'number',
2890
+ description:
2891
+ 'Price amount (corresponds to Beancount Amount.number). Supports up to 15 decimal places.',
2892
+ example: 50000
2893
+ },
2894
+ date: {
2895
+ type: 'string',
2896
+ description:
2897
+ 'Price date (ISO 8601 format). Represents the date this price was valid.',
2898
+ example: '2024-01-01',
2899
+ format: 'date'
2900
+ },
2901
+ meta: {
2902
+ type: 'object',
2903
+ description:
2904
+ 'Metadata (corresponds to Beancount meta field). Contains source, confidence, note, etc.',
2905
+ example: {
2906
+ source: 'MANUAL',
2907
+ note: 'User-defined price',
2908
+ confidence: 1
2909
+ }
2910
+ },
2911
+ createdAt: {
2912
+ format: 'date-time',
2913
+ type: 'string',
2914
+ description: 'Creation timestamp',
2915
+ example: '2024-11-03T10:00:00Z'
2916
+ },
2917
+ updatedAt: {
2918
+ format: 'date-time',
2919
+ type: 'string',
2920
+ description: 'Last update timestamp',
2921
+ example: '2024-11-03T10:00:00Z'
2922
+ }
2923
+ },
2924
+ required: [
2925
+ 'id',
2926
+ 'userId',
2927
+ 'currency',
2928
+ 'quoteCurrency',
2929
+ 'amount',
2930
+ 'date',
2931
+ 'meta',
2932
+ 'createdAt',
2933
+ 'updatedAt'
2934
+ ]
2935
+ } as const;
2936
+
2937
+ export const $PriceListResponseDto = {
2938
+ type: 'object',
2939
+ properties: {
2940
+ items: {
2941
+ description: 'List of prices',
2942
+ type: 'array',
2943
+ items: {
2944
+ $ref: '#/components/schemas/PriceResponseDto'
2945
+ }
2946
+ },
2947
+ total: {
2948
+ type: 'number',
2949
+ description: 'Total number of prices',
2950
+ example: 42
2951
+ }
2952
+ },
2953
+ required: ['items', 'total']
2954
+ } as const;
2955
+
2956
+ export const $UpdateBeanPriceDto = {
2957
+ type: 'object',
2958
+ properties: {
2959
+ currency: {
2960
+ type: 'string',
2961
+ description: 'Currency being priced'
2962
+ },
2963
+ quoteCurrency: {
2964
+ type: 'string',
2965
+ description: 'Quote currency (pricing currency)'
2966
+ },
2967
+ amount: {
2968
+ type: 'number',
2969
+ description: 'Price amount (MUST be >= 0 per Beancount spec)',
2970
+ minimum: 0
2971
+ },
2972
+ date: {
2973
+ type: 'string',
2974
+ description: 'Price date (ISO 8601 format)'
2975
+ },
2976
+ metadata: {
2977
+ type: 'object',
2978
+ description: 'Metadata'
2979
+ }
2980
+ }
2981
+ } as const;
2982
+
2983
+ export const $CreateRecurringRuleDto = {
2984
+ type: 'object',
2985
+ properties: {
2986
+ name: {
2987
+ type: 'string',
2988
+ description: 'Rule name (unique per user)',
2989
+ maxLength: 100
2990
+ },
2991
+ icon: {
2992
+ type: 'string',
2993
+ description: 'Icon emoji',
2994
+ maxLength: 10
2995
+ },
2996
+ frequency: {
2997
+ type: 'string',
2998
+ description: 'Recurring frequency',
2999
+ enum: [
3000
+ 'WEEKLY',
3001
+ 'BIWEEKLY',
3002
+ 'MONTHLY',
3003
+ 'BIMONTHLY',
3004
+ 'QUARTERLY',
3005
+ 'YEARLY',
3006
+ 'CUSTOM'
3007
+ ]
3008
+ },
3009
+ expectedAmount: {
3010
+ type: 'number',
3011
+ description: 'Expected amount (positive number)',
3012
+ minimum: 0
3013
+ },
3014
+ expectedDay: {
3015
+ type: 'number',
3016
+ description: 'Expected day of month (1-31)',
3017
+ minimum: 1,
3018
+ maximum: 31
3019
+ },
3020
+ customIntervalDays: {
3021
+ type: 'number',
3022
+ description: 'Custom interval in days (required for CUSTOM frequency)',
3023
+ minimum: 1
3024
+ },
3025
+ currency: {
3026
+ type: 'string',
3027
+ description: 'Currency code',
3028
+ default: 'CNY',
3029
+ maxLength: 10
3030
+ },
3031
+ matchPayeePattern: {
3032
+ type: 'string',
3033
+ description: 'Payee matching pattern (supports wildcards)',
3034
+ maxLength: 200
3035
+ },
3036
+ matchAmountTolerance: {
3037
+ type: 'number',
3038
+ description: 'Amount tolerance percentage (0-1)',
3039
+ default: 0.075,
3040
+ minimum: 0,
3041
+ maximum: 1
3042
+ },
3043
+ defaultExpenseAccount: {
3044
+ type: 'string',
3045
+ description: 'Default expense account for auto-create',
3046
+ maxLength: 200
3047
+ },
3048
+ defaultPaymentAccount: {
3049
+ type: 'string',
3050
+ description: 'Default payment account for auto-create',
3051
+ maxLength: 200
3052
+ },
3053
+ defaultPayee: {
3054
+ type: 'string',
3055
+ description: 'Default payee for auto-create',
3056
+ maxLength: 200
3057
+ },
3058
+ autoCreate: {
3059
+ type: 'boolean',
3060
+ description: 'Auto-create transaction when expected date arrives',
3061
+ default: false
3062
+ },
3063
+ startDate: {
3064
+ type: 'string',
3065
+ description: 'Rule start date (ISO format)'
3066
+ },
3067
+ endDate: {
3068
+ type: 'string',
3069
+ description: 'Rule end date (ISO format)'
3070
+ }
3071
+ },
3072
+ required: [
3073
+ 'name',
3074
+ 'frequency',
3075
+ 'expectedAmount',
3076
+ 'currency',
3077
+ 'matchAmountTolerance',
3078
+ 'autoCreate'
3079
+ ]
3080
+ } as const;
3081
+
3082
+ export const $RecurringRuleResponseDto = {
3083
+ type: 'object',
3084
+ properties: {
3085
+ id: {
3086
+ type: 'string',
3087
+ description: 'Rule ID'
3088
+ },
3089
+ userId: {
3090
+ type: 'string',
3091
+ description: 'User ID'
3092
+ },
3093
+ name: {
3094
+ type: 'string',
3095
+ description: 'Rule name'
3096
+ },
3097
+ icon: {
3098
+ type: 'object',
3099
+ description: 'Icon emoji'
3100
+ },
3101
+ frequency: {
3102
+ type: 'string',
3103
+ description: 'Recurring frequency'
2869
3104
  },
2870
3105
  expectedAmount: {
2871
3106
  type: 'number',
@@ -4189,6 +4424,27 @@ export const $SignupDto = {
4189
4424
  }
4190
4425
  } as const;
4191
4426
 
4427
+ export const $SignupResponseDto = {
4428
+ type: 'object',
4429
+ properties: {
4430
+ authToken: {
4431
+ type: 'string',
4432
+ description: 'JWT auth token',
4433
+ example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
4434
+ },
4435
+ accessToken: {
4436
+ type: 'string',
4437
+ description: 'Auto-generated access token'
4438
+ },
4439
+ role: {
4440
+ type: 'string',
4441
+ description: 'Assigned user role',
4442
+ enum: ['USER', 'ADMIN', 'DEMO', 'INACTIVE', 'PAID', 'OPS']
4443
+ }
4444
+ },
4445
+ required: ['authToken', 'accessToken', 'role']
4446
+ } as const;
4447
+
4192
4448
  export const $UpdateUserSettingDto = {
4193
4449
  type: 'object',
4194
4450
  properties: {
@@ -4312,446 +4568,1876 @@ export const $UpdatePropertyDto = {
4312
4568
  required: ['value']
4313
4569
  } as const;
4314
4570
 
4315
- export const $FileImportDto = {
4571
+ export const $CreateBeanEventDto = {
4316
4572
  type: 'object',
4317
4573
  properties: {
4318
- file: {
4574
+ date: {
4319
4575
  type: 'string',
4320
- format: 'binary',
4321
- description: 'Bill file to import (CSV, PDF, OFX, etc.)',
4322
- example: 'alipay.csv'
4576
+ description: 'Life event date (ISO 8601)',
4577
+ example: '2024-03-15'
4578
+ },
4579
+ type: {
4580
+ type: 'string',
4581
+ description:
4582
+ 'Life event type (e.g., "employer", "location", "marital-status") — user-defined, no enum constraint at engine layer',
4583
+ example: 'employer'
4584
+ },
4585
+ description: {
4586
+ type: 'string',
4587
+ description:
4588
+ 'Life event description. Empty string is a VALID value (distinct from absence).',
4589
+ example: 'Acme Corp'
4590
+ },
4591
+ meta: {
4592
+ type: 'object',
4593
+ description:
4594
+ 'Product-side metadata (lives in BeanEvent.meta JSON, never in engine Event fields)',
4595
+ example: {
4596
+ note: 'Promotion'
4597
+ }
4323
4598
  }
4324
4599
  },
4325
- required: ['file']
4600
+ required: ['date', 'type', 'description']
4326
4601
  } as const;
4327
4602
 
4328
- export const $ImportErrorDto = {
4603
+ export const $EventResponseDto = {
4329
4604
  type: 'object',
4330
4605
  properties: {
4331
- index: {
4332
- type: 'number',
4333
- description: 'Index of failed transaction in the file',
4334
- example: 5
4606
+ id: {
4607
+ type: 'string',
4608
+ description: 'Unique identifier',
4609
+ example: 'uuid-123-456'
4335
4610
  },
4336
- error: {
4611
+ userId: {
4337
4612
  type: 'string',
4338
- description: 'Error message',
4339
- example: 'Transaction does not balance: -100 USD != 0'
4340
- }
4341
- },
4342
- required: ['index', 'error']
4343
- } as const;
4344
-
4345
- export const $ReviewItemPreviewDto = {
4346
- type: 'object',
4347
- properties: {
4348
- index: {
4349
- type: 'number',
4350
- description: 'Index in the import batch (for tracking)',
4351
- example: 0
4613
+ description: 'User ID (owner of the life event)',
4614
+ example: 'user-123'
4352
4615
  },
4353
4616
  date: {
4354
4617
  type: 'string',
4355
- description: 'Transaction date (ISO format)',
4356
- example: '2026-03-05'
4357
- },
4358
- amount: {
4359
- type: 'number',
4360
- description: 'Transaction amount (absolute value)',
4361
- example: 99
4618
+ description: 'Life event date (ISO 8601 format)',
4619
+ example: '2024-03-15',
4620
+ format: 'date'
4362
4621
  },
4363
- currency: {
4622
+ type: {
4364
4623
  type: 'string',
4365
- description: 'Currency code',
4366
- example: 'CNY'
4624
+ description:
4625
+ 'Life event type (user-defined, e.g., "employer", "location")',
4626
+ example: 'employer'
4367
4627
  },
4368
- narration: {
4628
+ description: {
4369
4629
  type: 'string',
4370
- description: 'Transaction narration/description',
4371
- example: 'Restaurant expense'
4630
+ description:
4631
+ 'Life event description. May be an empty string (a valid value distinct from absence).',
4632
+ example: 'Acme Corp'
4372
4633
  },
4373
- payee: {
4374
- type: 'string',
4375
- description: 'Payee name',
4376
- example: 'Restaurant ABC'
4634
+ meta: {
4635
+ type: 'object',
4636
+ description: 'Product-side metadata (free-form JSON)',
4637
+ example: {
4638
+ note: 'Promotion'
4639
+ }
4377
4640
  },
4378
- category: {
4641
+ createdAt: {
4642
+ format: 'date-time',
4379
4643
  type: 'string',
4380
- description: 'Inferred category from rule matching',
4381
- example: 'food'
4382
- },
4383
- confidence: {
4384
- type: 'number',
4385
- description: 'Confidence score for the match (0-1)',
4386
- example: 0.85
4644
+ description: 'Creation timestamp',
4645
+ example: '2024-03-15T10:00:00Z'
4387
4646
  },
4388
- branchType: {
4647
+ updatedAt: {
4648
+ format: 'date-time',
4389
4649
  type: 'string',
4390
- description: 'Type of branch requiring review',
4391
- enum: [
4392
- 'DUPLICATE',
4393
- 'PAYEE_MATCH',
4394
- 'RULE_MATCH',
4395
- 'ACCOUNT_VALIDATION',
4396
- 'PIPELINE_ERROR'
4397
- ],
4398
- example: 'RULE_MATCH'
4399
- },
4400
- reasons: {
4401
- description: 'Human-readable reasons for requiring review',
4402
- example: ['Moderate confidence rule match', 'Multiple rules matched'],
4403
- type: 'array',
4404
- items: {
4405
- type: 'string'
4406
- }
4650
+ description:
4651
+ 'Last update timestamp. Also emitted as the ETag response header for If-Match optimistic concurrency.',
4652
+ example: '2024-03-15T10:00:00Z'
4407
4653
  }
4408
4654
  },
4409
- required: ['index', 'date', 'narration']
4655
+ required: [
4656
+ 'id',
4657
+ 'userId',
4658
+ 'date',
4659
+ 'type',
4660
+ 'description',
4661
+ 'meta',
4662
+ 'createdAt',
4663
+ 'updatedAt'
4664
+ ]
4410
4665
  } as const;
4411
4666
 
4412
- export const $ImportResultDto = {
4667
+ export const $EventListResponseDto = {
4413
4668
  type: 'object',
4414
4669
  properties: {
4415
- imported: {
4416
- type: 'number',
4417
- description: 'Number of successfully imported transactions',
4418
- example: 45
4419
- },
4420
- failed: {
4421
- type: 'number',
4422
- description: 'Number of failed transactions',
4423
- example: 2
4424
- },
4425
- skipped: {
4426
- type: 'number',
4427
- description:
4428
- 'Number of skipped transactions (high confidence duplicates, auto-skipped)',
4429
- example: 3
4430
- },
4431
- pendingReview: {
4432
- type: 'number',
4433
- description:
4434
- 'Number of transactions pending review (medium confidence duplicates)',
4435
- example: 2
4436
- },
4437
- errors: {
4438
- description: 'Array of error details for failed transactions',
4439
- type: 'array',
4440
- items: {
4441
- $ref: '#/components/schemas/ImportErrorDto'
4442
- }
4443
- },
4444
- reviewItems: {
4445
- description:
4446
- 'Array of transactions pending review with preview data. Contains essential information for displaying in the import preview UI.',
4670
+ items: {
4671
+ description: 'List of life events',
4447
4672
  type: 'array',
4448
4673
  items: {
4449
- $ref: '#/components/schemas/ReviewItemPreviewDto'
4674
+ $ref: '#/components/schemas/EventResponseDto'
4450
4675
  }
4451
4676
  },
4452
- transactions: {
4453
- type: 'object',
4454
- description: 'Array of imported transactions (optional, for debugging)'
4677
+ total: {
4678
+ type: 'number',
4679
+ description: 'Total number of life events matching the query',
4680
+ example: 42
4455
4681
  }
4456
4682
  },
4457
- required: ['imported', 'failed', 'skipped', 'pendingReview', 'errors']
4683
+ required: ['items', 'total']
4458
4684
  } as const;
4459
4685
 
4460
- export const $IdentifyResultDto = {
4686
+ export const $UpdateBeanEventDto = {
4461
4687
  type: 'object',
4462
4688
  properties: {
4463
- identified: {
4464
- type: 'boolean',
4465
- description: 'Whether the file was successfully identified',
4466
- example: true
4467
- },
4468
- importerName: {
4689
+ date: {
4469
4690
  type: 'string',
4470
- description: 'Name of the importer that can handle this file',
4471
- example: 'AlipayImporter'
4691
+ description: 'Life event date (ISO 8601)'
4472
4692
  },
4473
- importerId: {
4693
+ type: {
4474
4694
  type: 'string',
4475
- description: 'Unique identifier of the importer',
4476
- example: 'alipay'
4695
+ description: 'Life event type (user-defined)'
4477
4696
  },
4478
- account: {
4697
+ description: {
4479
4698
  type: 'string',
4480
- description: 'Default account used by this importer',
4481
- example: 'Assets:Alipay:Balance'
4699
+ description:
4700
+ 'Life event description. Empty string is a VALID value (distinct from absence).'
4482
4701
  },
4483
- message: {
4484
- type: 'string',
4485
- description: 'Message when file cannot be identified',
4486
- example: 'No matching importer found'
4702
+ meta: {
4703
+ type: 'object',
4704
+ description: 'Product-side metadata (free-form JSON)'
4487
4705
  }
4488
- },
4489
- required: ['identified']
4706
+ }
4490
4707
  } as const;
4491
4708
 
4492
- export const $MapperDefaultsDto = {
4709
+ export const $OnboardingAccountDto = {
4493
4710
  type: 'object',
4494
4711
  properties: {
4495
- sourceAccount: {
4712
+ path: {
4496
4713
  type: 'string',
4497
- description: 'Source account for transactions (Beancount format)',
4498
- example: 'Assets:Alipay:Balance'
4714
+ description:
4715
+ 'Account path (Assets/Liabilities only; format validated by the account service)',
4716
+ example: 'Assets:Checking'
4499
4717
  },
4500
4718
  currency: {
4501
4719
  type: 'string',
4502
- description: 'Default currency (ISO 4217 code)',
4503
- example: 'CNY'
4720
+ description: 'ISO 4217 currency code (3 letters)',
4721
+ example: 'USD'
4504
4722
  },
4505
- expenseAccount: {
4723
+ openingBalance: {
4506
4724
  type: 'string',
4507
- description: 'Default expense account',
4508
- example: 'Expenses:Unknown'
4725
+ description:
4726
+ 'Opening balance as a non-negative Decimal string (e.g. "1000.00")',
4727
+ example: '1000.00'
4509
4728
  },
4510
- incomeAccount: {
4729
+ platformId: {
4511
4730
  type: 'string',
4512
- description: 'Default income account',
4513
- example: 'Income:Unknown'
4514
- },
4515
- accountMapping: {
4516
- type: 'object',
4517
4731
  description:
4518
- 'Filename prefix to account mapping (for HK importers). Maps filename prefix to Beancount account path.',
4519
- example: {
4520
- One: 'Assets:HSBC:One',
4521
- PULSE: 'Liabilities:CreditCards:HSBC:Pulse'
4732
+ 'Platform ID to bind the account to (references Platform.id); omit for unbound',
4733
+ example: 'c98e5d4a-2f71-4a5a-bb3c-92c9f231d5e2'
4734
+ }
4735
+ },
4736
+ required: ['path', 'currency']
4737
+ } as const;
4738
+
4739
+ export const $OnboardingDto = {
4740
+ type: 'object',
4741
+ properties: {
4742
+ accounts: {
4743
+ description: 'Asset/Liability accounts to register with opening balances',
4744
+ type: 'array',
4745
+ items: {
4746
+ $ref: '#/components/schemas/OnboardingAccountDto'
4522
4747
  }
4523
4748
  },
4524
- useCnh: {
4749
+ skipAssetRegistration: {
4525
4750
  type: 'boolean',
4526
4751
  description:
4527
- 'Convert CNY to CNH (offshore RMB) (for HK importers). Default: false.',
4528
- example: false
4529
- },
4530
- methodAccountMapping: {
4531
- type: 'object',
4532
- description:
4533
- 'Payment method to source account mapping. Maps payment method keywords to Beancount account paths. Used by Alipay/WeChat importers to determine sourceAccount based on payment method (e.g., HuaBei, CreditCard).',
4534
- example: {
4535
- HuaBei: 'Liabilities:Alipay:Huabei',
4536
- CreditCard: 'Liabilities:CreditCard'
4537
- }
4752
+ 'Skip asset registration; only bootstrap the core account set',
4753
+ default: false
4538
4754
  }
4539
- },
4540
- required: ['sourceAccount', 'currency']
4755
+ }
4541
4756
  } as const;
4542
4757
 
4543
- export const $ImporterConfigDataDto = {
4758
+ export const $ActualBalanceDto = {
4544
4759
  type: 'object',
4545
4760
  properties: {
4546
- defaults: {
4547
- description: 'Mapper defaults configuration',
4548
- allOf: [
4549
- {
4550
- $ref: '#/components/schemas/MapperDefaultsDto'
4551
- }
4552
- ]
4761
+ amount: {
4762
+ type: 'string',
4763
+ description:
4764
+ 'Actual balance amount as a decimal string (preserves precision for tolerance inference).',
4765
+ example: '1234.56'
4766
+ },
4767
+ ccy: {
4768
+ type: 'string',
4769
+ description: 'Currency code (ISO 4217 or commodity ticker).',
4770
+ example: 'CNY'
4553
4771
  }
4554
4772
  },
4555
- required: ['defaults']
4773
+ required: ['amount', 'ccy']
4556
4774
  } as const;
4557
4775
 
4558
- export const $VersionedConfigDto = {
4776
+ export const $ComputeReconciliationDto = {
4559
4777
  type: 'object',
4560
4778
  properties: {
4561
- version: {
4779
+ accountId: {
4562
4780
  type: 'string',
4563
- description: 'Configuration version (semver)',
4564
- example: '1.0.0'
4781
+ description: 'BeanAccount id to reconcile.'
4565
4782
  },
4566
- schema: {
4783
+ asOfDate: {
4567
4784
  type: 'string',
4568
- description: 'Configuration schema identifier',
4569
- example: 'importer-config-v1'
4785
+ description: 'Assertion date (ISO 8601, e.g. "2026-07-24").',
4786
+ example: '2026-07-24'
4570
4787
  },
4571
- data: {
4572
- description: 'Configuration data',
4788
+ actualBalance: {
4789
+ description: 'Actual balance from the external statement.',
4573
4790
  allOf: [
4574
4791
  {
4575
- $ref: '#/components/schemas/ImporterConfigDataDto'
4792
+ $ref: '#/components/schemas/ActualBalanceDto'
4576
4793
  }
4577
4794
  ]
4578
4795
  }
4579
4796
  },
4580
- required: ['version', 'schema', 'data']
4797
+ required: ['accountId', 'asOfDate', 'actualBalance']
4581
4798
  } as const;
4582
4799
 
4583
- export const $ImporterConfigDto = {
4800
+ export const $ReconciliationComputeResultDto = {
4584
4801
  type: 'object',
4585
4802
  properties: {
4586
- id: {
4803
+ accountId: {
4804
+ type: 'string'
4805
+ },
4806
+ asOfDate: {
4807
+ type: 'string'
4808
+ },
4809
+ bookBalance: {
4587
4810
  type: 'string',
4588
- description: 'Configuration ID',
4589
- example: 'clx1234567890'
4811
+ description: 'System-computed book balance (decimal string).'
4590
4812
  },
4591
- userId: {
4813
+ actualBalance: {
4592
4814
  type: 'string',
4593
- description: 'User ID',
4594
- example: 'user-abc-123'
4815
+ description: 'User-entered actual balance (decimal string).'
4595
4816
  },
4596
- importerId: {
4817
+ currency: {
4818
+ type: 'string'
4819
+ },
4820
+ diff: {
4597
4821
  type: 'string',
4598
- description: 'Importer identifier',
4599
- example: 'alipay',
4600
- enum: [
4601
- 'alipay',
4602
- 'alipay-web',
4603
- 'alipay-yuebao',
4604
- 'wechat',
4605
- 'wechat-xlsx',
4606
- 'boc',
4607
- 'boc-credit',
4608
- 'ccb',
4609
- 'cmb',
4610
- 'cmbc',
4611
- 'cmbc-credit',
4612
- 'icbc',
4613
- 'icbc-credit',
4614
- 'hsbc-hk-credit',
4615
- 'hsbc-hk-debit'
4616
- ]
4822
+ description: 'Diff = book − actual (decimal string).'
4617
4823
  },
4618
- version: {
4824
+ tolerance: {
4619
4825
  type: 'string',
4620
- description: 'Configuration version (semver)',
4621
- example: '1.0.0'
4826
+ description: 'Applied tolerance (decimal string).'
4622
4827
  },
4623
- schema: {
4828
+ withinTolerance: {
4829
+ type: 'boolean',
4830
+ description: 'true when |diff| ≤ tolerance.'
4831
+ },
4832
+ suggestedAction: {
4624
4833
  type: 'string',
4625
- description: 'Configuration schema identifier',
4626
- example: 'importer-config-v1'
4834
+ enum: ['assert', 'pad'],
4835
+ description:
4836
+ 'Suggested next action: assert when within tolerance, pad otherwise.'
4837
+ }
4838
+ },
4839
+ required: [
4840
+ 'accountId',
4841
+ 'asOfDate',
4842
+ 'bookBalance',
4843
+ 'actualBalance',
4844
+ 'currency',
4845
+ 'diff',
4846
+ 'tolerance',
4847
+ 'withinTolerance',
4848
+ 'suggestedAction'
4849
+ ]
4850
+ } as const;
4851
+
4852
+ export const $AssertReconciliationDto = {
4853
+ type: 'object',
4854
+ properties: {
4855
+ accountId: {
4856
+ type: 'string',
4857
+ description: 'BeanAccount id to reconcile.'
4627
4858
  },
4628
- config: {
4629
- description: 'Configuration data (validated against Zod schema)',
4859
+ asOfDate: {
4860
+ type: 'string',
4861
+ description: 'Assertion date (ISO 8601, e.g. "2026-07-24").',
4862
+ example: '2026-07-24'
4863
+ },
4864
+ actualBalance: {
4865
+ description: 'Actual balance from the external statement.',
4630
4866
  allOf: [
4631
4867
  {
4632
- $ref: '#/components/schemas/VersionedConfigDto'
4868
+ $ref: '#/components/schemas/ActualBalanceDto'
4633
4869
  }
4634
4870
  ]
4635
4871
  },
4636
- createdAt: {
4637
- format: 'date-time',
4872
+ tolerance: {
4638
4873
  type: 'string',
4639
- description: 'Creation timestamp',
4640
- example: '2025-01-27T10:00:00Z'
4874
+ description:
4875
+ 'Optional explicit tolerance override. Omit to infer from amount precision (Beancount default).',
4876
+ example: '0.01'
4877
+ }
4878
+ },
4879
+ required: ['accountId', 'asOfDate', 'actualBalance']
4880
+ } as const;
4881
+
4882
+ export const $ReconciliationRecordDto = {
4883
+ type: 'object',
4884
+ properties: {
4885
+ id: {
4886
+ type: 'string'
4641
4887
  },
4642
- updatedAt: {
4643
- format: 'date-time',
4888
+ accountId: {
4889
+ type: 'string'
4890
+ },
4891
+ date: {
4892
+ type: 'string'
4893
+ },
4894
+ amount: {
4644
4895
  type: 'string',
4645
- description: 'Last update timestamp',
4646
- example: '2025-01-27T10:00:00Z'
4896
+ description: 'Asserted (actual) amount.'
4897
+ },
4898
+ currency: {
4899
+ type: 'string'
4900
+ },
4901
+ tolerance: {
4902
+ type: 'string'
4903
+ },
4904
+ diffAmount: {
4905
+ type: 'string',
4906
+ description: 'book − actual.'
4907
+ },
4908
+ diffCurrency: {
4909
+ type: 'string'
4910
+ },
4911
+ createdAt: {
4912
+ type: 'string'
4647
4913
  }
4648
4914
  },
4649
- required: [
4650
- 'id',
4651
- 'userId',
4652
- 'importerId',
4653
- 'version',
4654
- 'schema',
4655
- 'config',
4656
- 'createdAt',
4657
- 'updatedAt'
4658
- ]
4915
+ required: ['id', 'accountId', 'date', 'amount', 'currency', 'createdAt']
4659
4916
  } as const;
4660
4917
 
4661
- export const $UpdateMapperDefaultsDto = {
4918
+ export const $PadReconciliationDto = {
4662
4919
  type: 'object',
4663
4920
  properties: {
4921
+ accountId: {
4922
+ type: 'string',
4923
+ description: 'BeanAccount id to reconcile.'
4924
+ },
4925
+ asOfDate: {
4926
+ type: 'string',
4927
+ description: 'Assertion date (ISO 8601, e.g. "2026-07-24").',
4928
+ example: '2026-07-24'
4929
+ },
4930
+ actualBalance: {
4931
+ description: 'Actual balance from the external statement.',
4932
+ allOf: [
4933
+ {
4934
+ $ref: '#/components/schemas/ActualBalanceDto'
4935
+ }
4936
+ ]
4937
+ },
4664
4938
  sourceAccount: {
4665
4939
  type: 'string',
4666
- description: 'Source account for transactions (Beancount format)',
4667
- example: 'Assets:Alipay:Balance',
4668
- pattern: '^[A-Z][a-zA-Z0-9-]*:[a-zA-Z0-9-:]+$'
4940
+ description:
4941
+ 'Pad source account. Defaults to Equity:Opening-Balances (official Beancount convention).',
4942
+ example: 'Equity:Opening-Balances',
4943
+ default: 'Equity:Opening-Balances'
4944
+ }
4945
+ },
4946
+ required: ['accountId', 'asOfDate', 'actualBalance']
4947
+ } as const;
4948
+
4949
+ export const $PadResultDto = {
4950
+ type: 'object',
4951
+ properties: {
4952
+ transactionId: {
4953
+ type: 'string',
4954
+ description: 'Created pad adjusting transaction id.'
4955
+ }
4956
+ },
4957
+ required: ['transactionId']
4958
+ } as const;
4959
+
4960
+ export const $FileImportDto = {
4961
+ type: 'object',
4962
+ properties: {
4963
+ file: {
4964
+ type: 'string',
4965
+ format: 'binary',
4966
+ description: 'Bill file to import (CSV, PDF, OFX, etc.)',
4967
+ example: 'alipay.csv'
4968
+ }
4969
+ },
4970
+ required: ['file']
4971
+ } as const;
4972
+
4973
+ export const $ImportErrorDto = {
4974
+ type: 'object',
4975
+ properties: {
4976
+ index: {
4977
+ type: 'number',
4978
+ description: 'Index of failed transaction in the file',
4979
+ example: 5
4980
+ },
4981
+ error: {
4982
+ type: 'string',
4983
+ description: 'Error message',
4984
+ example: 'Transaction does not balance: -100 USD != 0'
4985
+ }
4986
+ },
4987
+ required: ['index', 'error']
4988
+ } as const;
4989
+
4990
+ export const $ReviewItemPreviewDto = {
4991
+ type: 'object',
4992
+ properties: {
4993
+ index: {
4994
+ type: 'number',
4995
+ description: 'Index in the import batch (for tracking)',
4996
+ example: 0
4997
+ },
4998
+ date: {
4999
+ type: 'string',
5000
+ description: 'Transaction date (ISO format)',
5001
+ example: '2026-03-05'
5002
+ },
5003
+ amount: {
5004
+ type: 'number',
5005
+ description: 'Transaction amount (absolute value)',
5006
+ example: 99
4669
5007
  },
4670
5008
  currency: {
4671
5009
  type: 'string',
4672
- description: 'Default currency (ISO 4217 code)',
4673
- example: 'CNY',
4674
- minLength: 3,
4675
- maxLength: 3,
4676
- pattern: '^[A-Z]{3}$'
5010
+ description: 'Currency code',
5011
+ example: 'CNY'
4677
5012
  },
4678
- expenseAccount: {
5013
+ narration: {
4679
5014
  type: 'string',
4680
- description: 'Default expense account (optional)',
4681
- example: 'Expenses:Unknown',
4682
- pattern: '^[A-Z][a-zA-Z0-9-]*:[a-zA-Z0-9-:]+$'
5015
+ description: 'Transaction narration/description',
5016
+ example: 'Restaurant expense'
4683
5017
  },
4684
- incomeAccount: {
5018
+ payee: {
4685
5019
  type: 'string',
4686
- description: 'Default income account (optional)',
4687
- example: 'Income:Unknown',
4688
- pattern: '^[A-Z][a-zA-Z0-9-]*:[a-zA-Z0-9-:]+$'
5020
+ description: 'Payee name',
5021
+ example: 'Restaurant ABC'
4689
5022
  },
4690
- methodAccountMapping: {
4691
- type: 'object',
4692
- description:
4693
- 'Payment method to source account mapping. Maps payment method keywords to Beancount account paths. Used by Alipay/WeChat importers to determine sourceAccount based on payment method (e.g., HuaBei, CreditCard).',
4694
- example: {
4695
- HuaBei: 'Liabilities:Alipay:Huabei',
4696
- CreditCard: 'Liabilities:CreditCard'
5023
+ category: {
5024
+ type: 'string',
5025
+ description: 'Inferred category from rule matching',
5026
+ example: 'food'
5027
+ },
5028
+ confidence: {
5029
+ type: 'number',
5030
+ description: 'Confidence score for the match (0-1)',
5031
+ example: 0.85
5032
+ },
5033
+ branchType: {
5034
+ type: 'string',
5035
+ description: 'Type of branch requiring review',
5036
+ enum: [
5037
+ 'DUPLICATE',
5038
+ 'PAYEE_MATCH',
5039
+ 'RULE_MATCH',
5040
+ 'ACCOUNT_VALIDATION',
5041
+ 'PIPELINE_ERROR'
5042
+ ],
5043
+ example: 'RULE_MATCH'
5044
+ },
5045
+ reasons: {
5046
+ description: 'Human-readable reasons for requiring review',
5047
+ example: ['Moderate confidence rule match', 'Multiple rules matched'],
5048
+ type: 'array',
5049
+ items: {
5050
+ type: 'string'
4697
5051
  }
4698
5052
  }
4699
- }
5053
+ },
5054
+ required: ['index', 'date', 'narration']
4700
5055
  } as const;
4701
5056
 
4702
- export const $UpdateConfigDataDto = {
5057
+ export const $ImportResultDto = {
4703
5058
  type: 'object',
4704
5059
  properties: {
4705
- defaults: {
4706
- description: 'Mapper defaults configuration',
5060
+ imported: {
5061
+ type: 'number',
5062
+ description: 'Number of successfully imported transactions',
5063
+ example: 45
5064
+ },
5065
+ failed: {
5066
+ type: 'number',
5067
+ description: 'Number of failed transactions',
5068
+ example: 2
5069
+ },
5070
+ skipped: {
5071
+ type: 'number',
5072
+ description:
5073
+ 'Number of skipped transactions (high confidence duplicates, auto-skipped)',
5074
+ example: 3
5075
+ },
5076
+ pendingReview: {
5077
+ type: 'number',
5078
+ description:
5079
+ 'Number of transactions pending review (medium confidence duplicates)',
5080
+ example: 2
5081
+ },
5082
+ errors: {
5083
+ description: 'Array of error details for failed transactions',
5084
+ type: 'array',
5085
+ items: {
5086
+ $ref: '#/components/schemas/ImportErrorDto'
5087
+ }
5088
+ },
5089
+ reviewItems: {
5090
+ description:
5091
+ 'Array of transactions pending review with preview data. Contains essential information for displaying in the import preview UI.',
5092
+ type: 'array',
5093
+ items: {
5094
+ $ref: '#/components/schemas/ReviewItemPreviewDto'
5095
+ }
5096
+ },
5097
+ transactions: {
5098
+ type: 'object',
5099
+ description: 'Array of imported transactions (optional, for debugging)'
5100
+ }
5101
+ },
5102
+ required: ['imported', 'failed', 'skipped', 'pendingReview', 'errors']
5103
+ } as const;
5104
+
5105
+ export const $IdentifyResultDto = {
5106
+ type: 'object',
5107
+ properties: {
5108
+ identified: {
5109
+ type: 'boolean',
5110
+ description: 'Whether the file was successfully identified',
5111
+ example: true
5112
+ },
5113
+ importerName: {
5114
+ type: 'string',
5115
+ description: 'Name of the importer that can handle this file',
5116
+ example: 'AlipayImporter'
5117
+ },
5118
+ importerId: {
5119
+ type: 'string',
5120
+ description: 'Unique identifier of the importer',
5121
+ example: 'alipay'
5122
+ },
5123
+ account: {
5124
+ type: 'string',
5125
+ description: 'Default account used by this importer',
5126
+ example: 'Assets:CN:Alipay:Balance'
5127
+ },
5128
+ message: {
5129
+ type: 'string',
5130
+ description: 'Message when file cannot be identified',
5131
+ example: 'No matching importer found'
5132
+ }
5133
+ },
5134
+ required: ['identified']
5135
+ } as const;
5136
+
5137
+ export const $MapperDefaultsDto = {
5138
+ type: 'object',
5139
+ properties: {
5140
+ sourceAccount: {
5141
+ type: 'string',
5142
+ description: 'Source account for transactions (Beancount format)',
5143
+ example: 'Assets:CN:Alipay:Balance'
5144
+ },
5145
+ currency: {
5146
+ type: 'string',
5147
+ description: 'Default currency (ISO 4217 code)',
5148
+ example: 'CNY'
5149
+ },
5150
+ expenseAccount: {
5151
+ type: 'string',
5152
+ description: 'Default expense account',
5153
+ example: 'Expenses:Unknown'
5154
+ },
5155
+ incomeAccount: {
5156
+ type: 'string',
5157
+ description: 'Default income account',
5158
+ example: 'Income:Unknown'
5159
+ },
5160
+ accountMapping: {
5161
+ type: 'object',
5162
+ description:
5163
+ 'Filename prefix to account mapping (for HK importers). Maps filename prefix to Beancount account path.',
5164
+ example: {
5165
+ One: 'Assets:HSBC:One',
5166
+ PULSE: 'Liabilities:CreditCards:HSBC:Pulse'
5167
+ }
5168
+ },
5169
+ useCnh: {
5170
+ type: 'boolean',
5171
+ description:
5172
+ 'Convert CNY to CNH (offshore RMB) (for HK importers). Default: false.',
5173
+ example: false
5174
+ },
5175
+ methodAccountMapping: {
5176
+ type: 'object',
5177
+ description:
5178
+ 'Payment method to source account mapping. Maps payment method keywords to Beancount account paths. Used by Alipay/WeChat importers to determine sourceAccount based on payment method (e.g., HuaBei, CreditCard).',
5179
+ example: {
5180
+ HuaBei: 'Liabilities:CN:CreditLine',
5181
+ CreditCard: 'Liabilities:CreditCard'
5182
+ }
5183
+ }
5184
+ },
5185
+ required: ['sourceAccount', 'currency']
5186
+ } as const;
5187
+
5188
+ export const $ImporterConfigDataDto = {
5189
+ type: 'object',
5190
+ properties: {
5191
+ defaults: {
5192
+ description: 'Mapper defaults configuration',
5193
+ allOf: [
5194
+ {
5195
+ $ref: '#/components/schemas/MapperDefaultsDto'
5196
+ }
5197
+ ]
5198
+ }
5199
+ },
5200
+ required: ['defaults']
5201
+ } as const;
5202
+
5203
+ export const $VersionedConfigDto = {
5204
+ type: 'object',
5205
+ properties: {
5206
+ version: {
5207
+ type: 'string',
5208
+ description: 'Configuration version (semver)',
5209
+ example: '1.0.0'
5210
+ },
5211
+ schema: {
5212
+ type: 'string',
5213
+ description: 'Configuration schema identifier',
5214
+ example: 'importer-config-v1'
5215
+ },
5216
+ data: {
5217
+ description: 'Configuration data',
5218
+ allOf: [
5219
+ {
5220
+ $ref: '#/components/schemas/ImporterConfigDataDto'
5221
+ }
5222
+ ]
5223
+ }
5224
+ },
5225
+ required: ['version', 'schema', 'data']
5226
+ } as const;
5227
+
5228
+ export const $ImporterConfigDto = {
5229
+ type: 'object',
5230
+ properties: {
5231
+ id: {
5232
+ type: 'string',
5233
+ description: 'Configuration ID',
5234
+ example: 'clx1234567890'
5235
+ },
5236
+ userId: {
5237
+ type: 'string',
5238
+ description: 'User ID',
5239
+ example: 'user-abc-123'
5240
+ },
5241
+ importerId: {
5242
+ type: 'string',
5243
+ description: 'Importer identifier',
5244
+ example: 'alipay',
5245
+ enum: [
5246
+ 'alipay',
5247
+ 'alipay-web',
5248
+ 'alipay-yuebao',
5249
+ 'wechat',
5250
+ 'wechat-xlsx',
5251
+ 'boc',
5252
+ 'boc-credit',
5253
+ 'ccb',
5254
+ 'cmb',
5255
+ 'cmbc',
5256
+ 'cmbc-credit',
5257
+ 'icbc',
5258
+ 'icbc-credit',
5259
+ 'hsbc-hk-credit',
5260
+ 'hsbc-hk-debit'
5261
+ ]
5262
+ },
5263
+ version: {
5264
+ type: 'string',
5265
+ description: 'Configuration version (semver)',
5266
+ example: '1.0.0'
5267
+ },
5268
+ schema: {
5269
+ type: 'string',
5270
+ description: 'Configuration schema identifier',
5271
+ example: 'importer-config-v1'
5272
+ },
5273
+ config: {
5274
+ description: 'Configuration data (validated against Zod schema)',
5275
+ allOf: [
5276
+ {
5277
+ $ref: '#/components/schemas/VersionedConfigDto'
5278
+ }
5279
+ ]
5280
+ },
5281
+ createdAt: {
5282
+ format: 'date-time',
5283
+ type: 'string',
5284
+ description: 'Creation timestamp',
5285
+ example: '2025-01-27T10:00:00Z'
5286
+ },
5287
+ updatedAt: {
5288
+ format: 'date-time',
5289
+ type: 'string',
5290
+ description: 'Last update timestamp',
5291
+ example: '2025-01-27T10:00:00Z'
5292
+ }
5293
+ },
5294
+ required: [
5295
+ 'id',
5296
+ 'userId',
5297
+ 'importerId',
5298
+ 'version',
5299
+ 'schema',
5300
+ 'config',
5301
+ 'createdAt',
5302
+ 'updatedAt'
5303
+ ]
5304
+ } as const;
5305
+
5306
+ export const $UpdateMapperDefaultsDto = {
5307
+ type: 'object',
5308
+ properties: {
5309
+ sourceAccount: {
5310
+ type: 'string',
5311
+ description: 'Source account for transactions (Beancount format)',
5312
+ example: 'Assets:CN:Alipay:Balance',
5313
+ pattern: '^[A-Z][a-zA-Z0-9-]*:[a-zA-Z0-9-:]+$'
5314
+ },
5315
+ currency: {
5316
+ type: 'string',
5317
+ description: 'Default currency (ISO 4217 code)',
5318
+ example: 'CNY',
5319
+ minLength: 3,
5320
+ maxLength: 3,
5321
+ pattern: '^[A-Z]{3}$'
5322
+ },
5323
+ expenseAccount: {
5324
+ type: 'string',
5325
+ description: 'Default expense account (optional)',
5326
+ example: 'Expenses:Unknown',
5327
+ pattern: '^[A-Z][a-zA-Z0-9-]*:[a-zA-Z0-9-:]+$'
5328
+ },
5329
+ incomeAccount: {
5330
+ type: 'string',
5331
+ description: 'Default income account (optional)',
5332
+ example: 'Income:Unknown',
5333
+ pattern: '^[A-Z][a-zA-Z0-9-]*:[a-zA-Z0-9-:]+$'
5334
+ },
5335
+ methodAccountMapping: {
5336
+ type: 'object',
5337
+ description:
5338
+ 'Payment method to source account mapping. Maps payment method keywords to Beancount account paths. Used by Alipay/WeChat importers to determine sourceAccount based on payment method (e.g., HuaBei, CreditCard).',
5339
+ example: {
5340
+ HuaBei: 'Liabilities:CN:CreditLine',
5341
+ CreditCard: 'Liabilities:CreditCard'
5342
+ }
5343
+ }
5344
+ }
5345
+ } as const;
5346
+
5347
+ export const $UpdateConfigDataDto = {
5348
+ type: 'object',
5349
+ properties: {
5350
+ defaults: {
5351
+ description: 'Mapper defaults configuration',
5352
+ allOf: [
5353
+ {
5354
+ $ref: '#/components/schemas/UpdateMapperDefaultsDto'
5355
+ }
5356
+ ]
5357
+ }
5358
+ }
5359
+ } as const;
5360
+
5361
+ export const $UpdateImporterConfigDto = {
5362
+ type: 'object',
5363
+ properties: {
5364
+ data: {
5365
+ description: 'Configuration data (v1 schema)',
5366
+ allOf: [
5367
+ {
5368
+ $ref: '#/components/schemas/UpdateConfigDataDto'
5369
+ }
5370
+ ]
5371
+ }
5372
+ }
5373
+ } as const;
5374
+
5375
+ export const $ProviderSyncConfigDto = {
5376
+ type: 'object',
5377
+ properties: {
5378
+ sourceAccount: {
5379
+ type: 'string',
5380
+ description: 'Source account for the first posting',
5381
+ example: 'Assets:US:Chase:Checking'
5382
+ },
5383
+ defaultCurrency: {
5384
+ type: 'string',
5385
+ description: 'Default currency for transactions',
5386
+ example: 'USD'
5387
+ },
5388
+ defaultExpenseAccount: {
5389
+ type: 'string',
5390
+ description: 'Default expense account for the second posting',
5391
+ example: 'Expenses:Unknown'
5392
+ },
5393
+ defaultIncomeAccount: {
5394
+ type: 'string',
5395
+ description: 'Default income account for the second posting',
5396
+ example: 'Income:Unknown'
5397
+ },
5398
+ filterPending: {
5399
+ type: 'boolean',
5400
+ description: 'Filter pending transactions',
5401
+ default: true
5402
+ },
5403
+ externalAccountId: {
5404
+ type: 'string',
5405
+ description:
5406
+ 'External account ID for per-batch providers (e.g. GoCardless). Overrides sourceAccount when an ExternalAccountLink mapping exists.',
5407
+ example: 'acc_gocardless_001'
5408
+ }
5409
+ },
5410
+ required: [
5411
+ 'sourceAccount',
5412
+ 'defaultCurrency',
5413
+ 'defaultExpenseAccount',
5414
+ 'defaultIncomeAccount'
5415
+ ]
5416
+ } as const;
5417
+
5418
+ export const $ProviderSyncDto = {
5419
+ type: 'object',
5420
+ properties: {
5421
+ provider: {
5422
+ type: 'string',
5423
+ description:
5424
+ 'Provider name (already in URL path, optional here for reference)',
5425
+ example: 'plaid'
5426
+ },
5427
+ syncId: {
5428
+ type: 'string',
5429
+ description: 'Unique sync identifier for idempotency',
5430
+ example: 'sync-12345'
5431
+ },
5432
+ config: {
5433
+ description: 'Provider sync configuration',
5434
+ allOf: [
5435
+ {
5436
+ $ref: '#/components/schemas/ProviderSyncConfigDto'
5437
+ }
5438
+ ]
5439
+ },
5440
+ transactions: {
5441
+ type: 'array',
5442
+ description: 'Raw transactions from provider',
5443
+ example: [
5444
+ {
5445
+ transaction_id: 'txn-001',
5446
+ amount: 50,
5447
+ iso_currency_code: 'USD',
5448
+ date: '2024-01-15',
5449
+ merchant_name: 'Starbucks',
5450
+ name: 'STARBUCKS STORE 12345',
5451
+ pending: false,
5452
+ account_id: 'acc-001'
5453
+ }
5454
+ ]
5455
+ }
5456
+ },
5457
+ required: ['config', 'transactions']
5458
+ } as const;
5459
+
5460
+ export const $ProviderSyncResponseDto = {
5461
+ type: 'object',
5462
+ properties: {
5463
+ imported: {
5464
+ type: 'number',
5465
+ description: 'Number of transactions successfully imported',
5466
+ example: 10
5467
+ },
5468
+ skipped: {
5469
+ type: 'number',
5470
+ description: 'Number of transactions skipped (duplicates)',
5471
+ example: 2
5472
+ },
5473
+ pendingReview: {
5474
+ type: 'number',
5475
+ description: 'Number of transactions pending review',
5476
+ example: 3
5477
+ },
5478
+ failed: {
5479
+ type: 'number',
5480
+ description: 'Number of transactions that failed to import',
5481
+ example: 0
5482
+ },
5483
+ importedTransactionIds: {
5484
+ description: 'IDs of successfully imported transactions',
5485
+ example: ['txn-001', 'txn-002'],
5486
+ type: 'array',
5487
+ items: {
5488
+ type: 'string'
5489
+ }
5490
+ },
5491
+ reviewItemIds: {
5492
+ description: 'IDs of review items created for branched transactions',
5493
+ example: ['review-001', 'review-002'],
5494
+ type: 'array',
5495
+ items: {
5496
+ type: 'string'
5497
+ }
5498
+ }
5499
+ },
5500
+ required: ['imported', 'skipped', 'pendingReview', 'failed']
5501
+ } as const;
5502
+
5503
+ export const $SupportedProvidersResponseDto = {
5504
+ type: 'object',
5505
+ properties: {
5506
+ providers: {
5507
+ description: 'List of supported provider names',
5508
+ example: [
5509
+ 'plaid',
5510
+ 'teller',
5511
+ 'truelayer',
5512
+ 'gocardless',
5513
+ 'simplefin',
5514
+ 'yodlee',
5515
+ 'beancount-direct',
5516
+ 'parsed-bill'
5517
+ ],
5518
+ type: 'array',
5519
+ items: {
5520
+ type: 'string'
5521
+ }
5522
+ }
5523
+ },
5524
+ required: ['providers']
5525
+ } as const;
5526
+
5527
+ export const $CreateExternalAccountLinkDto = {
5528
+ type: 'object',
5529
+ properties: {
5530
+ provider: {
5531
+ type: 'string',
5532
+ enum: [
5533
+ 'plaid',
5534
+ 'teller',
5535
+ 'truelayer',
5536
+ 'gocardless',
5537
+ 'simplefin',
5538
+ 'yodlee',
5539
+ 'beancount-direct',
5540
+ 'parsed-bill'
5541
+ ],
5542
+ example: 'plaid',
5543
+ description: 'Open Banking provider (whitelist)'
5544
+ },
5545
+ externalAccountId: {
5546
+ type: 'string',
5547
+ example: 'acc-plaid-001',
5548
+ description: 'External account ID from the provider'
5549
+ },
5550
+ beanAccountId: {
5551
+ type: 'string',
5552
+ example: '550e8400-e29b-41d4-a716-446655440000',
5553
+ description: 'Target BeanAccount ID (must belong to the JWT user)'
5554
+ }
5555
+ },
5556
+ required: ['provider', 'externalAccountId', 'beanAccountId']
5557
+ } as const;
5558
+
5559
+ export const $ExternalAccountLinkResponseDto = {
5560
+ type: 'object',
5561
+ properties: {
5562
+ id: {
5563
+ type: 'string'
5564
+ },
5565
+ provider: {
5566
+ type: 'string'
5567
+ },
5568
+ externalAccountId: {
5569
+ type: 'string'
5570
+ },
5571
+ beanAccountId: {
5572
+ type: 'string'
5573
+ },
5574
+ isActive: {
5575
+ type: 'boolean'
5576
+ },
5577
+ createdAt: {
5578
+ type: 'string'
5579
+ },
5580
+ updatedAt: {
5581
+ type: 'string'
5582
+ }
5583
+ },
5584
+ required: [
5585
+ 'id',
5586
+ 'provider',
5587
+ 'externalAccountId',
5588
+ 'beanAccountId',
5589
+ 'isActive',
5590
+ 'createdAt',
5591
+ 'updatedAt'
5592
+ ]
5593
+ } as const;
5594
+
5595
+ export const $ExternalAccountLinkListResponseDto = {
5596
+ type: 'object',
5597
+ properties: {
5598
+ items: {
5599
+ type: 'array',
5600
+ items: {
5601
+ $ref: '#/components/schemas/ExternalAccountLinkResponseDto'
5602
+ }
5603
+ },
5604
+ total: {
5605
+ type: 'number'
5606
+ },
5607
+ provider: {
5608
+ type: 'string',
5609
+ description: 'Filter by provider (query param)'
5610
+ }
5611
+ },
5612
+ required: ['items', 'total']
5613
+ } as const;
5614
+
5615
+ export const $ParserTelemetryReportDto = {
5616
+ type: 'object',
5617
+ properties: {}
5618
+ } as const;
5619
+
5620
+ export const $UncoveredFormatMissDto = {
5621
+ type: 'object',
5622
+ properties: {}
5623
+ } as const;
5624
+
5625
+ export const $ProcessNlpDto = {
5626
+ type: 'object',
5627
+ properties: {
5628
+ message: {
5629
+ type: 'string',
5630
+ description: 'Natural language text describing a transaction (Chinese)',
5631
+ example: 'yesterday Starbucks spent 35 yuan',
5632
+ maxLength: 500
5633
+ },
5634
+ sessionId: {
5635
+ type: 'string',
5636
+ description:
5637
+ 'Session ID for multi-turn conversation (auto-generated if not provided)',
5638
+ example: 'session_abc123'
5639
+ },
5640
+ parsedData: {
5641
+ type: 'object',
5642
+ description:
5643
+ 'Parsed data from previous NLP response for session recovery. Send back the parsedData received in confirm_payee/confirm responses.',
5644
+ example: {
5645
+ amount: 35,
5646
+ currency: 'CNY',
5647
+ payee: 'Starbucks'
5648
+ }
5649
+ }
5650
+ },
5651
+ required: ['message']
5652
+ } as const;
5653
+
5654
+ export const $NlpTransactionInfoDto = {
5655
+ type: 'object',
5656
+ properties: {
5657
+ id: {
5658
+ type: 'string',
5659
+ description: 'Transaction ID'
5660
+ },
5661
+ date: {
5662
+ type: 'string',
5663
+ description: 'Transaction date (ISO format)'
5664
+ },
5665
+ amount: {
5666
+ type: 'number',
5667
+ description: 'Transaction amount'
5668
+ },
5669
+ currency: {
5670
+ type: 'string',
5671
+ description: 'Currency code'
5672
+ },
5673
+ payee: {
5674
+ type: 'string',
5675
+ description: 'Payee name'
5676
+ },
5677
+ narration: {
5678
+ type: 'string',
5679
+ description: 'Transaction narration'
5680
+ },
5681
+ warning: {
5682
+ type: 'string',
5683
+ description:
5684
+ 'Warning message for special transaction scenarios (e.g., cross-currency settlement)',
5685
+ example: '此交易使用USD账户结算。如需记录CNY支出,请创建货币转换交易。'
5686
+ }
5687
+ },
5688
+ required: ['id', 'date', 'amount', 'currency']
5689
+ } as const;
5690
+
5691
+ export const $NlpParsedDataDto = {
5692
+ type: 'object',
5693
+ properties: {
5694
+ amount: {
5695
+ type: 'number',
5696
+ description: 'Extracted amount'
5697
+ },
5698
+ currency: {
5699
+ type: 'string',
5700
+ description: 'Currency code',
5701
+ default: 'CNY'
5702
+ },
5703
+ date: {
5704
+ type: 'string',
5705
+ description: 'Transaction date (ISO format)'
5706
+ },
5707
+ payee: {
5708
+ type: 'string',
5709
+ description: 'Payee name'
5710
+ },
5711
+ narration: {
5712
+ type: 'string',
5713
+ description: 'Transaction narration'
5714
+ },
5715
+ category: {
5716
+ type: 'string',
5717
+ description: 'Category'
5718
+ },
5719
+ incomeType: {
5720
+ type: 'string',
5721
+ description: 'Income type (e.g., Salary, Bonus, Dividend, Interest)',
5722
+ example: 'Salary'
5723
+ },
5724
+ incomeSource: {
5725
+ type: 'string',
5726
+ description: 'Income source (e.g., company name)',
5727
+ example: 'Anthropic Inc.'
5728
+ },
5729
+ symbol: {
5730
+ type: 'string',
5731
+ description: 'Security symbol code (e.g., 600519, AAPL)',
5732
+ example: '600519'
5733
+ },
5734
+ quantity: {
5735
+ type: 'number',
5736
+ description: 'Quantity of shares/units',
5737
+ example: 100
5738
+ },
5739
+ price: {
5740
+ type: 'number',
5741
+ description: 'Unit price per share/unit',
5742
+ example: 1900
5743
+ },
5744
+ investmentAction: {
5745
+ type: 'string',
5746
+ description: 'Investment action',
5747
+ enum: ['buy', 'sell'],
5748
+ example: 'buy'
5749
+ },
5750
+ paymentSource: {
5751
+ type: 'string',
5752
+ description: 'Payment source: asset (default) or liability (credit card)',
5753
+ enum: ['asset', 'liability'],
5754
+ example: 'asset'
5755
+ },
5756
+ liabilityHint: {
5757
+ type: 'string',
5758
+ description: 'Liability account hint (CreditCard/Huabei/Baitiao)',
5759
+ example: 'CreditCard'
5760
+ },
5761
+ warning: {
5762
+ type: 'string',
5763
+ description:
5764
+ 'Warning message for special scenarios (e.g., cross-currency settlement)',
5765
+ example: '此交易使用USD账户结算。如需记录CNY支出,请创建货币转换交易。'
5766
+ }
5767
+ }
5768
+ } as const;
5769
+
5770
+ export const $NlpSourceTransactionDto = {
5771
+ type: 'object',
5772
+ properties: {
5773
+ date: {
5774
+ type: 'string',
5775
+ description: 'Transaction date (ISO format)'
5776
+ },
5777
+ amount: {
5778
+ type: 'string',
5779
+ description: 'Amount as string'
5780
+ },
5781
+ currency: {
5782
+ type: 'string',
5783
+ description: 'Currency code'
5784
+ },
5785
+ payee: {
5786
+ type: 'string',
5787
+ description: 'Payee name'
5788
+ },
5789
+ narration: {
5790
+ type: 'string',
5791
+ description: 'Transaction narration'
5792
+ }
5793
+ },
5794
+ required: ['date', 'amount', 'currency', 'narration']
5795
+ } as const;
5796
+
5797
+ export const $NlpTargetTransactionDto = {
5798
+ type: 'object',
5799
+ properties: {
5800
+ id: {
5801
+ type: 'string',
5802
+ description: 'Existing transaction ID'
5803
+ },
5804
+ date: {
5805
+ type: 'string',
5806
+ description: 'Transaction date (ISO format)'
5807
+ },
5808
+ amount: {
5809
+ type: 'string',
5810
+ description: 'Amount as string'
5811
+ },
5812
+ currency: {
5813
+ type: 'string',
5814
+ description: 'Currency code'
5815
+ },
5816
+ payee: {
5817
+ type: 'string',
5818
+ description: 'Payee name'
5819
+ },
5820
+ narration: {
5821
+ type: 'string',
5822
+ description: 'Transaction narration'
5823
+ }
5824
+ },
5825
+ required: ['id', 'date', 'amount', 'currency', 'narration']
5826
+ } as const;
5827
+
5828
+ export const $NlpSimilarityDto = {
5829
+ type: 'object',
5830
+ properties: {
5831
+ dateMatch: {
5832
+ type: 'boolean',
5833
+ description: 'Whether dates match'
5834
+ },
5835
+ dateDiff: {
5836
+ type: 'number',
5837
+ description: 'Date difference in days'
5838
+ },
5839
+ amountMatch: {
5840
+ type: 'boolean',
5841
+ description: 'Whether amounts match'
5842
+ },
5843
+ amountDiff: {
5844
+ type: 'string',
5845
+ description: 'Amount difference as decimal string'
5846
+ },
5847
+ payeeMatch: {
5848
+ type: 'boolean',
5849
+ description: 'Whether payees match'
5850
+ },
5851
+ payeeSimilarity: {
5852
+ type: 'number',
5853
+ description: 'Payee similarity score (0-1)'
5854
+ },
5855
+ accountOverlap: {
5856
+ type: 'number',
5857
+ description: 'Account overlap score (0-1)'
5858
+ }
5859
+ },
5860
+ required: [
5861
+ 'dateMatch',
5862
+ 'dateDiff',
5863
+ 'amountMatch',
5864
+ 'amountDiff',
5865
+ 'payeeMatch',
5866
+ 'payeeSimilarity',
5867
+ 'accountOverlap'
5868
+ ]
5869
+ } as const;
5870
+
5871
+ export const $NlpDuplicateConfirmationDataDto = {
5872
+ type: 'object',
5873
+ properties: {
5874
+ confidence: {
5875
+ type: 'number',
5876
+ description: 'Duplicate detection confidence score (0.5-0.89)',
5877
+ example: 0.85
5878
+ },
5879
+ sourceTransaction: {
5880
+ description:
5881
+ 'Source transaction summary (the new transaction being entered)',
5882
+ allOf: [
5883
+ {
5884
+ $ref: '#/components/schemas/NlpSourceTransactionDto'
5885
+ }
5886
+ ]
5887
+ },
5888
+ targetTransaction: {
5889
+ description: 'Target transaction summary (existing potential duplicate)',
5890
+ allOf: [
5891
+ {
5892
+ $ref: '#/components/schemas/NlpTargetTransactionDto'
5893
+ }
5894
+ ]
5895
+ },
5896
+ similarity: {
5897
+ description: 'Detailed similarity information',
5898
+ allOf: [
5899
+ {
5900
+ $ref: '#/components/schemas/NlpSimilarityDto'
5901
+ }
5902
+ ]
5903
+ },
5904
+ reasons: {
5905
+ description: 'Human-readable reasons for duplicate detection',
5906
+ example: ['日期匹配', '金额匹配', '商户相似'],
5907
+ type: 'array',
5908
+ items: {
5909
+ type: 'string'
5910
+ }
5911
+ }
5912
+ },
5913
+ required: [
5914
+ 'confidence',
5915
+ 'sourceTransaction',
5916
+ 'targetTransaction',
5917
+ 'similarity',
5918
+ 'reasons'
5919
+ ]
5920
+ } as const;
5921
+
5922
+ export const $NlpRuleConfirmationDataDto = {
5923
+ type: 'object',
5924
+ properties: {
5925
+ confidence: {
5926
+ type: 'number',
5927
+ description: 'Rule match confidence score (0.5-0.74)',
5928
+ example: 0.65
5929
+ },
5930
+ matchedRule: {
5931
+ type: 'object',
5932
+ description: 'Matched rule information'
5933
+ },
5934
+ suggestedAccounts: {
5935
+ type: 'object',
5936
+ description: 'Suggested accounts from the rule'
5937
+ },
5938
+ alternatives: {
5939
+ type: 'array',
5940
+ description: 'Alternative rules that also match'
5941
+ },
5942
+ reasons: {
5943
+ description: 'Human-readable reasons for the match',
5944
+ example: [
5945
+ 'Moderate confidence (65%)',
5946
+ 'Some keywords matched (OR logic)'
5947
+ ],
5948
+ type: 'array',
5949
+ items: {
5950
+ type: 'string'
5951
+ }
5952
+ }
5953
+ },
5954
+ required: [
5955
+ 'confidence',
5956
+ 'matchedRule',
5957
+ 'suggestedAccounts',
5958
+ 'alternatives',
5959
+ 'reasons'
5960
+ ]
5961
+ } as const;
5962
+
5963
+ export const $NlpAccountConfirmationDataDto = {
5964
+ type: 'object',
5965
+ properties: {
5966
+ invalidAccount: {
5967
+ type: 'string',
5968
+ description: 'The invalid account name',
5969
+ example: 'Expenses:Food:Coffee'
5970
+ },
5971
+ suggestedAccount: {
5972
+ type: 'string',
5973
+ description: 'Suggested replacement account',
5974
+ example: 'Expenses:Food:Drinks'
5975
+ },
5976
+ similarAccounts: {
5977
+ description: 'Similar accounts for user selection',
5978
+ type: 'array',
5979
+ items: {
5980
+ type: 'string'
5981
+ }
5982
+ },
5983
+ errorMessage: {
5984
+ type: 'string',
5985
+ description: 'Error message explaining the issue',
5986
+ example: 'No similar account found'
5987
+ },
5988
+ transactionContext: {
5989
+ type: 'object',
5990
+ description: 'Transaction context for reference'
5991
+ }
5992
+ },
5993
+ required: [
5994
+ 'invalidAccount',
5995
+ 'suggestedAccount',
5996
+ 'similarAccounts',
5997
+ 'errorMessage',
5998
+ 'transactionContext'
5999
+ ]
6000
+ } as const;
6001
+
6002
+ export const $NlpSuggestedPayeeDto = {
6003
+ type: 'object',
6004
+ properties: {
6005
+ id: {
6006
+ type: 'string',
6007
+ description: 'Payee ID',
6008
+ example: 'payee-123'
6009
+ },
6010
+ name: {
6011
+ type: 'string',
6012
+ description: 'Payee name',
6013
+ example: 'Starbucks'
6014
+ },
6015
+ category: {
6016
+ type: 'string',
6017
+ description: 'Payee category',
6018
+ example: 'food'
6019
+ },
6020
+ source: {
6021
+ type: 'string',
6022
+ description: 'Source of the payee',
6023
+ enum: ['user', 'global']
6024
+ },
6025
+ payeeProfileId: {
6026
+ type: 'string',
6027
+ description: 'PayeeProfile ID (if matched from global)',
6028
+ example: 'profile-456'
6029
+ }
6030
+ },
6031
+ required: ['id', 'name']
6032
+ } as const;
6033
+
6034
+ export const $NlpAlternativePayeeDto = {
6035
+ type: 'object',
6036
+ properties: {
6037
+ id: {
6038
+ type: 'string',
6039
+ description: 'Payee ID',
6040
+ example: 'payee-alt-1'
6041
+ },
6042
+ name: {
6043
+ type: 'string',
6044
+ description: 'Payee name',
6045
+ example: 'Starbucks Coffee'
6046
+ },
6047
+ similarity: {
6048
+ type: 'number',
6049
+ description: 'Similarity score (0-1)',
6050
+ example: 0.75
6051
+ }
6052
+ },
6053
+ required: ['id', 'name', 'similarity']
6054
+ } as const;
6055
+
6056
+ export const $NlpPayeeConfirmationDataDto = {
6057
+ type: 'object',
6058
+ properties: {
6059
+ confidence: {
6060
+ type: 'number',
6061
+ description: 'Confidence score for the payee match (0-1)',
6062
+ example: 0.65
6063
+ },
6064
+ originalPayee: {
6065
+ type: 'string',
6066
+ description: 'Original payee string from user input',
6067
+ example: '星巴'
6068
+ },
6069
+ suggestedPayee: {
6070
+ description: 'Suggested payee to use (null when no similar payees found)',
6071
+ nullable: true,
6072
+ allOf: [
6073
+ {
6074
+ $ref: '#/components/schemas/NlpSuggestedPayeeDto'
6075
+ }
6076
+ ]
6077
+ },
6078
+ similarity: {
6079
+ type: 'number',
6080
+ description: 'Similarity score between original and suggested (0-1)',
6081
+ example: 0.85
6082
+ },
6083
+ alternatives: {
6084
+ description: 'Alternative payee options',
6085
+ type: 'array',
6086
+ items: {
6087
+ $ref: '#/components/schemas/NlpAlternativePayeeDto'
6088
+ }
6089
+ },
6090
+ reasons: {
6091
+ description: 'Human-readable reasons for the match',
6092
+ example: ['Moderate similarity (65%)', 'Fuzzy match on name'],
6093
+ type: 'array',
6094
+ items: {
6095
+ type: 'string'
6096
+ }
6097
+ }
6098
+ },
6099
+ required: [
6100
+ 'confidence',
6101
+ 'originalPayee',
6102
+ 'similarity',
6103
+ 'alternatives',
6104
+ 'reasons'
6105
+ ]
6106
+ } as const;
6107
+
6108
+ export const $RecurringMatchInfoDto = {
6109
+ type: 'object',
6110
+ properties: {
6111
+ expectedId: {
6112
+ type: 'string',
6113
+ description: 'Expected transaction ID'
6114
+ },
6115
+ ruleId: {
6116
+ type: 'string',
6117
+ description: 'Recurring rule ID'
6118
+ },
6119
+ ruleName: {
6120
+ type: 'string',
6121
+ description: 'Rule name for display'
6122
+ },
6123
+ ruleIcon: {
6124
+ type: 'string',
6125
+ description: 'Rule icon'
6126
+ },
6127
+ expectedDate: {
6128
+ type: 'string',
6129
+ description: 'Expected date (YYYY-MM-DD)',
6130
+ example: '2026-01-05'
6131
+ },
6132
+ expectedAmount: {
6133
+ type: 'number',
6134
+ description: 'Expected amount',
6135
+ example: 3000
6136
+ },
6137
+ confidence: {
6138
+ type: 'number',
6139
+ description: 'Match confidence score (0-1)',
6140
+ example: 0.88
6141
+ },
6142
+ isAutoMatched: {
6143
+ type: 'boolean',
6144
+ description: 'Whether auto-matched (confidence >= 0.82)'
6145
+ }
6146
+ },
6147
+ required: [
6148
+ 'expectedId',
6149
+ 'ruleId',
6150
+ 'ruleName',
6151
+ 'expectedDate',
6152
+ 'expectedAmount',
6153
+ 'confidence',
6154
+ 'isAutoMatched'
6155
+ ]
6156
+ } as const;
6157
+
6158
+ export const $NlpSuggestedAccountDto = {
6159
+ type: 'object',
6160
+ properties: {
6161
+ account: {
6162
+ type: 'string',
6163
+ description: 'Suggested account path',
6164
+ example: 'Assets:Checking'
6165
+ },
6166
+ confidence: {
6167
+ type: 'number',
6168
+ description: 'Confidence score for this suggestion (0-1)',
6169
+ example: 0.9
6170
+ }
6171
+ },
6172
+ required: ['account']
6173
+ } as const;
6174
+
6175
+ export const $NlpSuggestedAccountsDto = {
6176
+ type: 'object',
6177
+ properties: {
6178
+ source: {
6179
+ description:
6180
+ 'Source account suggestion (where money comes from). For expense: asset/liability account. For income: income account.',
6181
+ allOf: [
6182
+ {
6183
+ $ref: '#/components/schemas/NlpSuggestedAccountDto'
6184
+ }
6185
+ ]
6186
+ },
6187
+ destination: {
6188
+ description:
6189
+ 'Destination account suggestion (where money goes to). For expense: expense account. For income: asset/liability account.',
6190
+ allOf: [
6191
+ {
6192
+ $ref: '#/components/schemas/NlpSuggestedAccountDto'
6193
+ }
6194
+ ]
6195
+ }
6196
+ }
6197
+ } as const;
6198
+
6199
+ export const $NlpDefaultAccountsDto = {
6200
+ type: 'object',
6201
+ properties: {
6202
+ asset: {
6203
+ type: 'string',
6204
+ description: 'Default asset account',
6205
+ example: 'Assets:Checking'
6206
+ },
6207
+ expense: {
6208
+ type: 'string',
6209
+ description: 'Default expense account',
6210
+ example: 'Expenses:Uncategorized'
6211
+ },
6212
+ income: {
6213
+ type: 'string',
6214
+ description: 'Default income account',
6215
+ example: 'Income:Uncategorized'
6216
+ },
6217
+ liability: {
6218
+ type: 'string',
6219
+ description: 'Default liability account',
6220
+ example: 'Liabilities:CreditCard'
6221
+ }
6222
+ },
6223
+ required: ['asset', 'expense', 'income', 'liability']
6224
+ } as const;
6225
+
6226
+ export const $NlpResponseDto = {
6227
+ type: 'object',
6228
+ properties: {
6229
+ status: {
6230
+ type: 'string',
6231
+ description: 'Response status',
6232
+ enum: ['success', 'pending', 'error']
6233
+ },
6234
+ action: {
6235
+ type: 'string',
6236
+ description: 'Action taken or requested',
6237
+ enum: [
6238
+ 'created',
6239
+ 'ask',
6240
+ 'confirm',
6241
+ 'confirm_duplicate',
6242
+ 'confirm_rule',
6243
+ 'confirm_account',
6244
+ 'confirm_payee',
6245
+ 'cancel'
6246
+ ]
6247
+ },
6248
+ intent: {
6249
+ type: 'string',
6250
+ description:
6251
+ 'Transaction intent detected by EntityRouter (v6.0: 5 core intents). Frontend uses this to render scenario-specific form fields.',
6252
+ enum: ['expense', 'asset', 'income', 'liability', 'equity'],
6253
+ example: 'expense'
6254
+ },
6255
+ assetSubType: {
6256
+ type: 'string',
6257
+ description:
6258
+ 'Asset sub-type (only present when intent is "asset"). Determines which asset-related form to render.',
6259
+ enum: ['transfer', 'banking', 'investment'],
6260
+ example: 'investment'
6261
+ },
6262
+ liabilitySubType: {
6263
+ type: 'string',
6264
+ description:
6265
+ 'Liability sub-type (only present when intent is "liability"). borrow: borrowing money (Liabilities → Assets), repay: repaying debt (Assets → Liabilities).',
6266
+ enum: ['borrow', 'repay'],
6267
+ example: 'borrow'
6268
+ },
6269
+ equitySubType: {
6270
+ type: 'string',
6271
+ description:
6272
+ 'Equity sub-type (only present when intent is "equity"). opening: account opening balance (Equity → Assets), adjustment: balance correction.',
6273
+ enum: ['opening', 'adjustment'],
6274
+ example: 'opening'
6275
+ },
6276
+ paymentSource: {
6277
+ type: 'string',
6278
+ description:
6279
+ 'Payment source for expense transactions (v6.1). Indicates whether payment comes from asset or liability account. Only present when intent is "expense".',
6280
+ enum: ['asset', 'liability'],
6281
+ example: 'liability'
6282
+ },
6283
+ liabilityHint: {
6284
+ type: 'string',
6285
+ description:
6286
+ 'Liability account type hint for credit card/BNPL spending (v6.1). Only present when paymentSource is "liability". Values: CreditCard, Huabei, Baitiao',
6287
+ example: 'CreditCard'
6288
+ },
6289
+ message: {
6290
+ type: 'string',
6291
+ description:
6292
+ 'Human-readable message (for ask or error actions). Deprecated: Use messageKey for i18n support.',
6293
+ example: 'How much did you spend?',
6294
+ deprecated: true
6295
+ },
6296
+ messageKey: {
6297
+ type: 'string',
6298
+ description:
6299
+ 'i18n message key for frontend translation. Use this instead of message for internationalization support.',
6300
+ example: 'nlp.slot.prompt'
6301
+ },
6302
+ messageParams: {
6303
+ type: 'object',
6304
+ description:
6305
+ 'Parameters for message interpolation. Used with messageKey for dynamic values in translated messages.',
6306
+ example: {
6307
+ slot: 'amount',
6308
+ name: 'Starbucks',
6309
+ similarity: 85
6310
+ }
6311
+ },
6312
+ sessionId: {
6313
+ type: 'string',
6314
+ description:
6315
+ 'Session ID for multi-turn dialogue. Must be included in subsequent requests to continue the conversation.',
6316
+ example: 'session_abc123'
6317
+ },
6318
+ waitingFor: {
6319
+ type: 'string',
6320
+ description: 'Which slot is waiting for user input',
6321
+ example: 'amount'
6322
+ },
6323
+ transaction: {
6324
+ description: 'Created transaction info (for created action)',
6325
+ allOf: [
6326
+ {
6327
+ $ref: '#/components/schemas/NlpTransactionInfoDto'
6328
+ }
6329
+ ]
6330
+ },
6331
+ parsedData: {
6332
+ description:
6333
+ 'Parsed data for confirmation (when action is "confirm"). Contains extracted fields that user should verify before transaction creation.',
6334
+ allOf: [
6335
+ {
6336
+ $ref: '#/components/schemas/NlpParsedDataDto'
6337
+ }
6338
+ ]
6339
+ },
6340
+ duplicateData: {
6341
+ description:
6342
+ 'Duplicate detection data (when action is "confirm_duplicate"). Contains information about potential duplicate transaction for user confirmation.',
6343
+ allOf: [
6344
+ {
6345
+ $ref: '#/components/schemas/NlpDuplicateConfirmationDataDto'
6346
+ }
6347
+ ]
6348
+ },
6349
+ ruleData: {
6350
+ description:
6351
+ 'Rule match data (when action is "confirm_rule"). Contains information about medium-confidence rule match for user confirmation.',
6352
+ allOf: [
6353
+ {
6354
+ $ref: '#/components/schemas/NlpRuleConfirmationDataDto'
6355
+ }
6356
+ ]
6357
+ },
6358
+ accountData: {
6359
+ description:
6360
+ 'Account validation data (when action is "confirm_account"). Contains information about invalid account for user correction.',
6361
+ allOf: [
6362
+ {
6363
+ $ref: '#/components/schemas/NlpAccountConfirmationDataDto'
6364
+ }
6365
+ ]
6366
+ },
6367
+ payeeData: {
6368
+ description:
6369
+ 'Payee confirmation data (when action is "confirm_payee"). Contains information about medium/low confidence payee match for user confirmation.',
6370
+ allOf: [
6371
+ {
6372
+ $ref: '#/components/schemas/NlpPayeeConfirmationDataDto'
6373
+ }
6374
+ ]
6375
+ },
6376
+ confidence: {
6377
+ type: 'number',
6378
+ description: 'Overall confidence score (0-1)',
6379
+ example: 0.85
6380
+ },
6381
+ confidenceThreshold: {
6382
+ type: 'number',
6383
+ description:
6384
+ 'Confidence threshold for automatic creation (default: 0.75). When confidence < threshold, action will be "confirm" requiring user verification.',
6385
+ example: 0.75
6386
+ },
6387
+ recurringMatch: {
6388
+ description:
6389
+ 'Recurring transaction match info (when action is "created"). Contains match details when transaction matches a pending expected transaction.',
6390
+ allOf: [
6391
+ {
6392
+ $ref: '#/components/schemas/RecurringMatchInfoDto'
6393
+ }
6394
+ ]
6395
+ },
6396
+ recurringSuggestion: {
6397
+ description:
6398
+ 'Recurring rule creation suggestion (when action is "created"). Contains suggestion to create a recurring rule based on detected patterns. Only present when no existing rule matched and similar historical transactions were found.',
4707
6399
  allOf: [
4708
6400
  {
4709
- $ref: '#/components/schemas/UpdateMapperDefaultsDto'
6401
+ $ref: '#/components/schemas/RecurringSuggestionDto'
4710
6402
  }
4711
6403
  ]
4712
- }
4713
- }
4714
- } as const;
4715
-
4716
- export const $UpdateImporterConfigDto = {
4717
- type: 'object',
4718
- properties: {
4719
- data: {
4720
- description: 'Configuration data (v1 schema)',
6404
+ },
6405
+ suggestedAccounts: {
6406
+ description:
6407
+ 'Suggested accounts for this transaction. Contains recommended source and destination accounts based on the detected intent and rules.',
4721
6408
  allOf: [
4722
6409
  {
4723
- $ref: '#/components/schemas/UpdateConfigDataDto'
6410
+ $ref: '#/components/schemas/NlpSuggestedAccountsDto'
6411
+ }
6412
+ ]
6413
+ },
6414
+ defaultAccounts: {
6415
+ description:
6416
+ 'Default accounts for the user/region. These are fallback accounts used when no specific suggestion is available.',
6417
+ allOf: [
6418
+ {
6419
+ $ref: '#/components/schemas/NlpDefaultAccountsDto'
4724
6420
  }
4725
6421
  ]
4726
6422
  }
4727
- }
6423
+ },
6424
+ required: ['status', 'action']
4728
6425
  } as const;
4729
6426
 
4730
- export const $CreatePlatformDto = {
6427
+ export const $PlatformListItemDto = {
4731
6428
  type: 'object',
4732
6429
  properties: {
4733
- name: {
6430
+ id: {
4734
6431
  type: 'string',
4735
- description: 'Platform name',
4736
- example: 'Binance'
6432
+ description: 'Global platform ID'
4737
6433
  },
4738
- canonical: {
6434
+ name: {
4739
6435
  type: 'string',
4740
- description: 'Platform canonical identifier (lowercase, kebab-case)',
4741
- example: 'binance'
4742
- },
4743
- aliases: {
4744
- description: 'Platform aliases (multi-language names for lookup)',
4745
- example: ['Binance', 'Binance Exchange', 'BNB'],
4746
- type: 'array',
4747
- items: {
4748
- type: 'string'
4749
- }
6436
+ description: 'Platform name'
4750
6437
  },
4751
6438
  url: {
4752
6439
  type: 'string',
4753
- description: 'Platform URL',
4754
- example: 'https://www.binance.com'
6440
+ description: 'Platform URL'
4755
6441
  },
4756
6442
  type: {
4757
6443
  type: 'string',
@@ -4764,48 +6450,53 @@ export const $CreatePlatformDto = {
4764
6450
  'INVESTMENT',
4765
6451
  'INSURANCE',
4766
6452
  'OTHER'
4767
- ],
4768
- example: 'CRYPTO_EXCHANGE'
6453
+ ]
6454
+ },
6455
+ canonical: {
6456
+ type: 'string',
6457
+ description: 'Canonical identifier in ACCOUNT_RE format (e.g., "icbc")'
6458
+ },
6459
+ suggestedSegment: {
6460
+ type: 'string',
6461
+ description:
6462
+ 'Suggested path segment — canonical with first char uppercased (ACC_COMP_NAME_RE)'
4769
6463
  },
4770
6464
  logoUrl: {
4771
6465
  type: 'string',
4772
- description: 'Platform logo URL',
4773
- example: 'https://example.com/logos/binance.png'
6466
+ description: 'Logo URL',
6467
+ nullable: true
4774
6468
  },
4775
- isActive: {
6469
+ isBound: {
4776
6470
  type: 'boolean',
4777
- description: 'Whether the platform is active',
4778
- default: true
6471
+ description: 'Whether user has accounts using this platform'
4779
6472
  }
4780
6473
  },
4781
- required: ['name', 'canonical', 'aliases', 'url', 'type']
6474
+ required: [
6475
+ 'id',
6476
+ 'name',
6477
+ 'url',
6478
+ 'type',
6479
+ 'canonical',
6480
+ 'suggestedSegment',
6481
+ 'logoUrl',
6482
+ 'isBound'
6483
+ ]
4782
6484
  } as const;
4783
6485
 
4784
- export const $UpdatePlatformDto = {
6486
+ export const $PlatformMatchResultDto = {
4785
6487
  type: 'object',
4786
6488
  properties: {
4787
- name: {
6489
+ id: {
4788
6490
  type: 'string',
4789
- description: 'Platform name',
4790
- example: 'Binance'
6491
+ description: 'Global platform ID'
4791
6492
  },
4792
- canonical: {
6493
+ name: {
4793
6494
  type: 'string',
4794
- description: 'Platform canonical identifier (lowercase, kebab-case)',
4795
- example: 'binance'
4796
- },
4797
- aliases: {
4798
- description: 'Platform aliases (multi-language names for lookup)',
4799
- example: ['Binance', 'Binance Exchange', 'BNB'],
4800
- type: 'array',
4801
- items: {
4802
- type: 'string'
4803
- }
6495
+ description: 'Platform name (e.g., "ICBC")'
4804
6496
  },
4805
- url: {
6497
+ canonical: {
4806
6498
  type: 'string',
4807
- description: 'Platform URL',
4808
- example: 'https://www.binance.com'
6499
+ description: 'Canonical identifier in ACCOUNT_RE format (e.g., "icbc")'
4809
6500
  },
4810
6501
  type: {
4811
6502
  type: 'string',
@@ -4818,178 +6509,167 @@ export const $UpdatePlatformDto = {
4818
6509
  'INVESTMENT',
4819
6510
  'INSURANCE',
4820
6511
  'OTHER'
4821
- ],
4822
- example: 'CRYPTO_EXCHANGE'
4823
- },
4824
- logoUrl: {
4825
- type: 'string',
4826
- description: 'Platform logo URL',
4827
- example: 'https://example.com/logos/binance.png'
4828
- },
4829
- isActive: {
4830
- type: 'boolean',
4831
- description: 'Whether the platform is active'
4832
- }
4833
- }
4834
- } as const;
4835
-
4836
- export const $ProviderSyncConfigDto = {
4837
- type: 'object',
4838
- properties: {
4839
- sourceAccount: {
4840
- type: 'string',
4841
- description: 'Source account for the first posting',
4842
- example: 'Assets:Bank:Chase'
6512
+ ]
4843
6513
  },
4844
- defaultCurrency: {
6514
+ suggestedSegment: {
4845
6515
  type: 'string',
4846
- description: 'Default currency for transactions',
4847
- example: 'USD'
6516
+ description:
6517
+ 'Suggested path segment — canonical, already in ACCOUNT_RE format'
4848
6518
  },
4849
- defaultExpenseAccount: {
6519
+ logoUrl: {
4850
6520
  type: 'string',
4851
- description: 'Default expense account for the second posting',
4852
- example: 'Expenses:Unknown'
6521
+ description: 'Logo URL',
6522
+ nullable: true
4853
6523
  },
4854
- defaultIncomeAccount: {
6524
+ matchType: {
4855
6525
  type: 'string',
4856
- description: 'Default income account for the second posting',
4857
- example: 'Income:Unknown'
4858
- },
4859
- filterPending: {
4860
- type: 'boolean',
4861
- description: 'Filter pending transactions',
4862
- default: true
6526
+ description: "How this row matched: 'exact' > 'prefix' > 'substring'",
6527
+ enum: ['exact', 'prefix', 'substring']
4863
6528
  }
4864
6529
  },
4865
6530
  required: [
4866
- 'sourceAccount',
4867
- 'defaultCurrency',
4868
- 'defaultExpenseAccount',
4869
- 'defaultIncomeAccount'
6531
+ 'id',
6532
+ 'name',
6533
+ 'canonical',
6534
+ 'type',
6535
+ 'suggestedSegment',
6536
+ 'logoUrl',
6537
+ 'matchType'
4870
6538
  ]
4871
6539
  } as const;
4872
6540
 
4873
- export const $ProviderSyncDto = {
6541
+ export const $PlatformMatchResponseDto = {
4874
6542
  type: 'object',
4875
6543
  properties: {
4876
- provider: {
4877
- type: 'string',
4878
- description:
4879
- 'Provider name (already in URL path, optional here for reference)',
4880
- example: 'plaid'
6544
+ platforms: {
6545
+ description: 'Ranked matches, best tier first (at most 10 rows)',
6546
+ type: 'array',
6547
+ items: {
6548
+ $ref: '#/components/schemas/PlatformMatchResultDto'
6549
+ }
4881
6550
  },
4882
- syncId: {
6551
+ matchType: {
4883
6552
  type: 'string',
4884
- description: 'Unique sync identifier for idempotency',
4885
- example: 'sync-12345'
6553
+ description:
6554
+ "Overall match quality — top row's tier, or 'none' when no hits",
6555
+ enum: ['none', 'exact', 'prefix', 'substring']
4886
6556
  },
4887
- config: {
4888
- description: 'Provider sync configuration',
4889
- allOf: [
4890
- {
4891
- $ref: '#/components/schemas/ProviderSyncConfigDto'
4892
- }
4893
- ]
6557
+ total: {
6558
+ type: 'number',
6559
+ description: 'Total matches before LIMIT (truncation transparency)'
4894
6560
  },
4895
- transactions: {
4896
- type: 'array',
4897
- description: 'Raw transactions from provider',
4898
- example: [
4899
- {
4900
- transaction_id: 'txn-001',
4901
- amount: 50,
4902
- iso_currency_code: 'USD',
4903
- date: '2024-01-15',
4904
- merchant_name: 'Starbucks',
4905
- name: 'STARBUCKS STORE 12345',
4906
- pending: false,
4907
- account_id: 'acc-001'
4908
- }
4909
- ]
6561
+ hasMore: {
6562
+ type: 'boolean',
6563
+ description: 'true when total > platforms.length (more matches exist)'
4910
6564
  }
4911
6565
  },
4912
- required: ['config', 'transactions']
6566
+ required: ['platforms', 'matchType', 'total', 'hasMore']
4913
6567
  } as const;
4914
6568
 
4915
- export const $SupportedProvidersResponseDto = {
6569
+ export const $CreatePlatformDto = {
4916
6570
  type: 'object',
4917
6571
  properties: {
4918
- providers: {
4919
- description: 'List of supported provider names',
4920
- example: [
4921
- 'plaid',
4922
- 'teller',
4923
- 'truelayer',
4924
- 'gocardless',
4925
- 'simplefin',
4926
- 'yodlee',
4927
- 'beancount-direct',
4928
- 'parsed-bill'
4929
- ],
6572
+ name: {
6573
+ type: 'string',
6574
+ description: 'Platform name',
6575
+ example: 'Binance'
6576
+ },
6577
+ canonical: {
6578
+ type: 'string',
6579
+ description: 'Platform canonical identifier (lowercase, kebab-case)',
6580
+ example: 'binance'
6581
+ },
6582
+ aliases: {
6583
+ description: 'Platform aliases (multi-language names for lookup)',
6584
+ example: ['Binance', 'Binance Exchange', 'BNB'],
4930
6585
  type: 'array',
4931
6586
  items: {
4932
6587
  type: 'string'
4933
6588
  }
4934
- }
4935
- },
4936
- required: ['providers']
4937
- } as const;
4938
-
4939
- export const $ParserTelemetryReportDto = {
4940
- type: 'object',
4941
- properties: {}
4942
- } as const;
4943
-
4944
- export const $UncoveredFormatMissDto = {
4945
- type: 'object',
4946
- properties: {}
4947
- } as const;
4948
-
4949
- export const $ProcessNlpDto = {
4950
- type: 'object',
4951
- properties: {
4952
- message: {
6589
+ },
6590
+ url: {
4953
6591
  type: 'string',
4954
- description: 'Natural language text describing a transaction (Chinese)',
4955
- example: 'yesterday Starbucks spent 35 yuan',
4956
- maxLength: 500
6592
+ description: 'Platform URL',
6593
+ example: 'https://www.binance.com'
4957
6594
  },
4958
- sessionId: {
6595
+ type: {
4959
6596
  type: 'string',
4960
- description:
4961
- 'Session ID for multi-turn conversation (auto-generated if not provided)',
4962
- example: 'session_abc123'
6597
+ description: 'Platform type',
6598
+ enum: [
6599
+ 'BANK',
6600
+ 'BROKERAGE',
6601
+ 'CRYPTO_EXCHANGE',
6602
+ 'PAYMENT',
6603
+ 'INVESTMENT',
6604
+ 'INSURANCE',
6605
+ 'OTHER'
6606
+ ],
6607
+ example: 'CRYPTO_EXCHANGE'
4963
6608
  },
4964
- parsedData: {
4965
- type: 'object',
4966
- description:
4967
- 'Parsed data from previous NLP response for session recovery. Send back the parsedData received in confirm_payee/confirm responses.',
4968
- example: {
4969
- amount: 35,
4970
- currency: 'CNY',
4971
- payee: 'Starbucks'
4972
- }
6609
+ logoUrl: {
6610
+ type: 'string',
6611
+ description: 'Platform logo URL',
6612
+ example: 'https://example.com/logos/binance.png'
6613
+ },
6614
+ isActive: {
6615
+ type: 'boolean',
6616
+ description: 'Whether the platform is active',
6617
+ default: true
4973
6618
  }
4974
6619
  },
4975
- required: ['message']
6620
+ required: ['name', 'canonical', 'aliases', 'url', 'type']
4976
6621
  } as const;
4977
6622
 
4978
- export const $BalanceByCurrencyDto = {
6623
+ export const $UpdatePlatformDto = {
4979
6624
  type: 'object',
4980
6625
  properties: {
4981
- currency: {
6626
+ name: {
4982
6627
  type: 'string',
4983
- description: 'ISO 4217 currency code',
4984
- example: 'CNY'
6628
+ description: 'Platform name',
6629
+ example: 'Binance'
4985
6630
  },
4986
- balance: {
6631
+ canonical: {
4987
6632
  type: 'string',
4988
- description: 'Balance amount',
4989
- example: '50000.00'
6633
+ description: 'Platform canonical identifier (lowercase, kebab-case)',
6634
+ example: 'binance'
6635
+ },
6636
+ aliases: {
6637
+ description: 'Platform aliases (multi-language names for lookup)',
6638
+ example: ['Binance', 'Binance Exchange', 'BNB'],
6639
+ type: 'array',
6640
+ items: {
6641
+ type: 'string'
6642
+ }
6643
+ },
6644
+ url: {
6645
+ type: 'string',
6646
+ description: 'Platform URL',
6647
+ example: 'https://www.binance.com'
6648
+ },
6649
+ type: {
6650
+ type: 'string',
6651
+ description: 'Platform type',
6652
+ enum: [
6653
+ 'BANK',
6654
+ 'BROKERAGE',
6655
+ 'CRYPTO_EXCHANGE',
6656
+ 'PAYMENT',
6657
+ 'INVESTMENT',
6658
+ 'INSURANCE',
6659
+ 'OTHER'
6660
+ ],
6661
+ example: 'CRYPTO_EXCHANGE'
6662
+ },
6663
+ logoUrl: {
6664
+ type: 'string',
6665
+ description: 'Platform logo URL',
6666
+ example: 'https://example.com/logos/binance.png'
6667
+ },
6668
+ isActive: {
6669
+ type: 'boolean',
6670
+ description: 'Whether the platform is active'
4990
6671
  }
4991
- },
4992
- required: ['currency', 'balance']
6672
+ }
4993
6673
  } as const;
4994
6674
 
4995
6675
  export const $NetWorthByCurrencyDto = {
@@ -5061,28 +6741,6 @@ export const $ConvertedNetWorthDto = {
5061
6741
  ]
5062
6742
  } as const;
5063
6743
 
5064
- export const $ExchangeRateWarningDto = {
5065
- type: 'object',
5066
- properties: {
5067
- type: {
5068
- type: 'string',
5069
- description: 'Warning type',
5070
- example: 'MISSING_EXCHANGE_RATE'
5071
- },
5072
- currency: {
5073
- type: 'string',
5074
- description: 'Currency without exchange rate',
5075
- example: 'EUR'
5076
- },
5077
- totalAmount: {
5078
- type: 'string',
5079
- description: 'Total amount affected',
5080
- example: '1000.00'
5081
- }
5082
- },
5083
- required: ['type', 'currency', 'totalAmount']
5084
- } as const;
5085
-
5086
6744
  export const $NetWorthResponseDto = {
5087
6745
  type: 'object',
5088
6746
  properties: {
@@ -5168,7 +6826,7 @@ export const $AccountItemDto = {
5168
6826
  name: {
5169
6827
  type: 'string',
5170
6828
  description: 'Full account name',
5171
- example: 'Assets:Bank:CMB:Savings'
6829
+ example: 'Assets:CN:CMB:Savings'
5172
6830
  },
5173
6831
  displayName: {
5174
6832
  type: 'string',
@@ -5184,6 +6842,12 @@ export const $AccountItemDto = {
5184
6842
  type: 'string',
5185
6843
  description: 'Currency code',
5186
6844
  example: 'CNY'
6845
+ },
6846
+ convertedBalance: {
6847
+ type: 'string',
6848
+ description:
6849
+ 'FX-converted balance in base currency; omitted when not convertible',
6850
+ example: '50000.00'
5187
6851
  }
5188
6852
  },
5189
6853
  required: ['id', 'name', 'displayName', 'balance', 'currency']
@@ -5210,11 +6874,66 @@ export const $PlatformGroupDto = {
5210
6874
  },
5211
6875
  totalBalance: {
5212
6876
  type: 'string',
5213
- description: 'Total balance across all accounts in platform',
6877
+ description: 'FX-converted total balance in base currency',
6878
+ example: '100000.00'
6879
+ },
6880
+ balanceByCurrency: {
6881
+ description: 'Raw (unconverted) balances grouped by currency',
6882
+ type: 'array',
6883
+ items: {
6884
+ $ref: '#/components/schemas/BalanceByCurrencyDto'
6885
+ }
6886
+ },
6887
+ convertedBalance: {
6888
+ type: 'string',
6889
+ description:
6890
+ 'Converted balance in base currency (omitted when no currency is convertible)',
5214
6891
  example: '100000.00'
6892
+ },
6893
+ sharePct: {
6894
+ type: 'number',
6895
+ description:
6896
+ 'Share of the grand converted total (0-100); 0 when grand total is 0',
6897
+ example: 42.5
6898
+ }
6899
+ },
6900
+ required: [
6901
+ 'platformId',
6902
+ 'platformName',
6903
+ 'accounts',
6904
+ 'totalBalance',
6905
+ 'balanceByCurrency',
6906
+ 'sharePct'
6907
+ ]
6908
+ } as const;
6909
+
6910
+ export const $AccountExchangeRateWarningDto = {
6911
+ type: 'object',
6912
+ properties: {
6913
+ type: {
6914
+ type: 'string',
6915
+ description: 'Warning type',
6916
+ example: 'MISSING_EXCHANGE_RATE'
6917
+ },
6918
+ currency: {
6919
+ type: 'string',
6920
+ description: 'Currency without exchange rate',
6921
+ example: 'USD'
6922
+ },
6923
+ accounts: {
6924
+ description: 'Affected account paths',
6925
+ type: 'array',
6926
+ items: {
6927
+ type: 'string'
6928
+ }
6929
+ },
6930
+ totalAmount: {
6931
+ type: 'string',
6932
+ description: 'Total amount in this currency',
6933
+ example: '5000.00'
5215
6934
  }
5216
6935
  },
5217
- required: ['platformId', 'platformName', 'accounts', 'totalBalance']
6936
+ required: ['type', 'currency', 'accounts', 'totalAmount']
5218
6937
  } as const;
5219
6938
 
5220
6939
  export const $AccountsSummaryDto = {
@@ -5227,9 +6946,21 @@ export const $AccountsSummaryDto = {
5227
6946
  totalPlatforms: {
5228
6947
  type: 'number',
5229
6948
  description: 'Total number of platforms'
6949
+ },
6950
+ baseCurrency: {
6951
+ type: 'string',
6952
+ description: 'Base currency for conversion',
6953
+ example: 'CNY'
6954
+ },
6955
+ warnings: {
6956
+ description: 'Per-account exchange rate warnings',
6957
+ type: 'array',
6958
+ items: {
6959
+ $ref: '#/components/schemas/AccountExchangeRateWarningDto'
6960
+ }
5230
6961
  }
5231
6962
  },
5232
- required: ['totalAccounts', 'totalPlatforms']
6963
+ required: ['totalAccounts', 'totalPlatforms', 'baseCurrency']
5233
6964
  } as const;
5234
6965
 
5235
6966
  export const $AccountsResponseDto = {
@@ -5264,7 +6995,7 @@ export const $AccountItemWithAssetClassDto = {
5264
6995
  name: {
5265
6996
  type: 'string',
5266
6997
  description: 'Full account name',
5267
- example: 'Assets:Bank:CMB:Savings'
6998
+ example: 'Assets:CN:CMB:Savings'
5268
6999
  },
5269
7000
  displayName: {
5270
7001
  type: 'string',
@@ -5281,6 +7012,12 @@ export const $AccountItemWithAssetClassDto = {
5281
7012
  description: 'Currency code',
5282
7013
  example: 'CNY'
5283
7014
  },
7015
+ convertedBalance: {
7016
+ type: 'string',
7017
+ description:
7018
+ 'FX-converted balance in base currency; omitted when not convertible',
7019
+ example: '50000.00'
7020
+ },
5284
7021
  assetClass: {
5285
7022
  type: 'string',
5286
7023
  description: 'Asset class',
@@ -5360,35 +7097,6 @@ export const $AssetClassGroupDto = {
5360
7097
  required: ['assetClass', 'accounts', 'balanceByCurrency']
5361
7098
  } as const;
5362
7099
 
5363
- export const $AccountExchangeRateWarningDto = {
5364
- type: 'object',
5365
- properties: {
5366
- type: {
5367
- type: 'string',
5368
- description: 'Warning type',
5369
- example: 'MISSING_EXCHANGE_RATE'
5370
- },
5371
- currency: {
5372
- type: 'string',
5373
- description: 'Currency without exchange rate',
5374
- example: 'USD'
5375
- },
5376
- accounts: {
5377
- description: 'Affected account paths',
5378
- type: 'array',
5379
- items: {
5380
- type: 'string'
5381
- }
5382
- },
5383
- totalAmount: {
5384
- type: 'string',
5385
- description: 'Total amount in this currency',
5386
- example: '5000.00'
5387
- }
5388
- },
5389
- required: ['type', 'currency', 'accounts', 'totalAmount']
5390
- } as const;
5391
-
5392
7100
  export const $AssetClassSummaryDto = {
5393
7101
  type: 'object',
5394
7102
  properties: {
@@ -5462,7 +7170,7 @@ export const $HoldingAssetClassAccountSliceDto = {
5462
7170
  accountPath: {
5463
7171
  type: 'string',
5464
7172
  description: 'Full account path',
5465
- example: 'Assets:US:Investments:Brokerage'
7173
+ example: 'Assets:US:Fidelity:Brokerage'
5466
7174
  },
5467
7175
  accountCurrency: {
5468
7176
  type: 'string',
@@ -5646,26 +7354,121 @@ export const $CashFlowResponseDto = {
5646
7354
  description: 'Converted values in base currency',
5647
7355
  allOf: [
5648
7356
  {
5649
- $ref: '#/components/schemas/ConvertedCashFlowDto'
7357
+ $ref: '#/components/schemas/ConvertedCashFlowDto'
7358
+ }
7359
+ ]
7360
+ },
7361
+ warnings: {
7362
+ description: 'Exchange rate warnings',
7363
+ type: 'array',
7364
+ items: {
7365
+ $ref: '#/components/schemas/ExchangeRateWarningDto'
7366
+ }
7367
+ }
7368
+ },
7369
+ required: [
7370
+ 'period',
7371
+ 'income',
7372
+ 'expense',
7373
+ 'netSavings',
7374
+ 'savingsRate',
7375
+ 'currency'
7376
+ ]
7377
+ } as const;
7378
+
7379
+ export const $CategoryGroupDto = {
7380
+ type: 'object',
7381
+ properties: {
7382
+ category: {
7383
+ type: 'string',
7384
+ description:
7385
+ 'Functional category (account-path Group segment); regional and universal account paths merge under it',
7386
+ example: 'Food'
7387
+ },
7388
+ totalExpense: {
7389
+ type: 'string',
7390
+ description:
7391
+ 'Converted total for this category in base currency (expense amount when flow=expense, income amount when flow=income)',
7392
+ example: '1200.00'
7393
+ },
7394
+ sharePct: {
7395
+ type: 'number',
7396
+ description: 'Share of grand total (0-100); 0 when grand total is 0',
7397
+ example: 42.5
7398
+ },
7399
+ balanceByCurrency: {
7400
+ description: 'Raw (unconverted) expense per currency',
7401
+ type: 'array',
7402
+ items: {
7403
+ $ref: '#/components/schemas/BalanceByCurrencyDto'
7404
+ }
7405
+ },
7406
+ convertedBalance: {
7407
+ type: 'string',
7408
+ description:
7409
+ 'Converted total in base currency (omitted when FX missing for all currencies in this category)',
7410
+ example: '1200.00'
7411
+ }
7412
+ },
7413
+ required: ['category', 'totalExpense', 'sharePct', 'balanceByCurrency']
7414
+ } as const;
7415
+
7416
+ export const $ExpensesByCategorySummaryDto = {
7417
+ type: 'object',
7418
+ properties: {
7419
+ totalExpense: {
7420
+ type: 'string',
7421
+ description:
7422
+ 'Total across all categories, converted (convertible categories only); expense totals when flow=expense, income totals when flow=income',
7423
+ example: '5000.00'
7424
+ },
7425
+ categoryCount: {
7426
+ type: 'number',
7427
+ description: 'Number of categories',
7428
+ example: 8
7429
+ }
7430
+ },
7431
+ required: ['totalExpense', 'categoryCount']
7432
+ } as const;
7433
+
7434
+ export const $ExpensesByCategoryResponseDto = {
7435
+ type: 'object',
7436
+ properties: {
7437
+ period: {
7438
+ type: 'string',
7439
+ description: 'Period requested',
7440
+ example: '1m'
7441
+ },
7442
+ baseCurrency: {
7443
+ type: 'string',
7444
+ description: 'Base currency for converted values',
7445
+ example: 'CNY'
7446
+ },
7447
+ groups: {
7448
+ description:
7449
+ 'Expense groups by functional category, sorted by converted total desc',
7450
+ type: 'array',
7451
+ items: {
7452
+ $ref: '#/components/schemas/CategoryGroupDto'
7453
+ }
7454
+ },
7455
+ summary: {
7456
+ description: 'Summary statistics',
7457
+ allOf: [
7458
+ {
7459
+ $ref: '#/components/schemas/ExpensesByCategorySummaryDto'
5650
7460
  }
5651
7461
  ]
5652
7462
  },
5653
7463
  warnings: {
5654
- description: 'Exchange rate warnings',
7464
+ description: 'Exchange rate warnings (e.g. missing rate for a currency)',
5655
7465
  type: 'array',
5656
7466
  items: {
5657
7467
  $ref: '#/components/schemas/ExchangeRateWarningDto'
5658
7468
  }
5659
7469
  }
5660
7470
  },
5661
- required: [
5662
- 'period',
5663
- 'income',
5664
- 'expense',
5665
- 'netSavings',
5666
- 'savingsRate',
5667
- 'currency'
5668
- ]
7471
+ required: ['period', 'baseCurrency', 'groups', 'summary']
5669
7472
  } as const;
5670
7473
 
5671
7474
  export const $MonetaryDto = {
@@ -5957,163 +7760,6 @@ export const $HoldingPnlResponseDto = {
5957
7760
  required: ['asOfDate', 'baseCurrency', 'method', 'rows', 'warnings']
5958
7761
  } as const;
5959
7762
 
5960
- export const $CreateBeanPriceDto = {
5961
- type: 'object',
5962
- properties: {
5963
- currency: {
5964
- type: 'string',
5965
- description: 'Currency being priced (e.g., USD, AAPL, BTC)',
5966
- example: 'USD'
5967
- },
5968
- quoteCurrency: {
5969
- type: 'string',
5970
- description: 'Quote currency (pricing currency, e.g., CNY, EUR)',
5971
- example: 'CNY'
5972
- },
5973
- amount: {
5974
- type: 'number',
5975
- description:
5976
- 'Price amount (MUST be >= 0 per Beancount spec, supports up to 15 decimal places). Zero allowed for conversion entries, negative strictly prohibited.',
5977
- example: 175.5,
5978
- minimum: 0
5979
- },
5980
- date: {
5981
- type: 'string',
5982
- description: 'Price date (ISO 8601 format)',
5983
- example: '2024-11-05'
5984
- },
5985
- metadata: {
5986
- type: 'object',
5987
- description:
5988
- 'Metadata (validated by Zod schema, max field lengths enforced)',
5989
- example: {
5990
- source: 'MANUAL',
5991
- note: 'Bank valuation report',
5992
- confidence: 0.95
5993
- }
5994
- }
5995
- },
5996
- required: ['currency', 'quoteCurrency', 'amount', 'date']
5997
- } as const;
5998
-
5999
- export const $PriceResponseDto = {
6000
- type: 'object',
6001
- properties: {
6002
- id: {
6003
- type: 'string',
6004
- description: 'Unique identifier',
6005
- example: 'uuid-123-456'
6006
- },
6007
- userId: {
6008
- type: 'string',
6009
- description: 'User ID (owner of the price)',
6010
- example: 'user-123'
6011
- },
6012
- currency: {
6013
- type: 'string',
6014
- description: 'Currency being priced (e.g., USD, AAPL, BTC)',
6015
- example: 'BTC'
6016
- },
6017
- quoteCurrency: {
6018
- type: 'string',
6019
- description: 'Quote currency (pricing currency, e.g., USD, CNY)',
6020
- example: 'USD'
6021
- },
6022
- amount: {
6023
- type: 'number',
6024
- description:
6025
- 'Price amount (corresponds to Beancount Amount.number). Supports up to 15 decimal places.',
6026
- example: 50000
6027
- },
6028
- date: {
6029
- type: 'string',
6030
- description:
6031
- 'Price date (ISO 8601 format). Represents the date this price was valid.',
6032
- example: '2024-01-01',
6033
- format: 'date'
6034
- },
6035
- meta: {
6036
- type: 'object',
6037
- description:
6038
- 'Metadata (corresponds to Beancount meta field). Contains source, confidence, note, etc.',
6039
- example: {
6040
- source: 'MANUAL',
6041
- note: 'User-defined price',
6042
- confidence: 1
6043
- }
6044
- },
6045
- createdAt: {
6046
- format: 'date-time',
6047
- type: 'string',
6048
- description: 'Creation timestamp',
6049
- example: '2024-11-03T10:00:00Z'
6050
- },
6051
- updatedAt: {
6052
- format: 'date-time',
6053
- type: 'string',
6054
- description: 'Last update timestamp',
6055
- example: '2024-11-03T10:00:00Z'
6056
- }
6057
- },
6058
- required: [
6059
- 'id',
6060
- 'userId',
6061
- 'currency',
6062
- 'quoteCurrency',
6063
- 'amount',
6064
- 'date',
6065
- 'meta',
6066
- 'createdAt',
6067
- 'updatedAt'
6068
- ]
6069
- } as const;
6070
-
6071
- export const $PriceListResponseDto = {
6072
- type: 'object',
6073
- properties: {
6074
- items: {
6075
- description: 'List of prices',
6076
- type: 'array',
6077
- items: {
6078
- $ref: '#/components/schemas/PriceResponseDto'
6079
- }
6080
- },
6081
- total: {
6082
- type: 'number',
6083
- description: 'Total number of prices',
6084
- example: 42
6085
- }
6086
- },
6087
- required: ['items', 'total']
6088
- } as const;
6089
-
6090
- export const $UpdateBeanPriceDto = {
6091
- type: 'object',
6092
- properties: {
6093
- currency: {
6094
- type: 'string',
6095
- description: 'Currency being priced'
6096
- },
6097
- quoteCurrency: {
6098
- type: 'string',
6099
- description: 'Quote currency (pricing currency)'
6100
- },
6101
- amount: {
6102
- type: 'number',
6103
- description: 'Price amount (MUST be >= 0 per Beancount spec)',
6104
- minimum: 0
6105
- },
6106
- date: {
6107
- type: 'string',
6108
- description: 'Price date (ISO 8601 format)'
6109
- },
6110
- metadata: {
6111
- type: 'object',
6112
- description: 'Metadata'
6113
- }
6114
- }
6115
- } as const;
6116
-
6117
7763
  export const $CurrencyBalanceDto = {
6118
7764
  type: 'object',
6119
7765
  properties: {
@@ -6149,6 +7795,16 @@ export const $TimeSeriesPointDto = {
6149
7795
  description: 'Change from previous point',
6150
7796
  example: '5000.00'
6151
7797
  },
7798
+ assets: {
7799
+ type: 'string',
7800
+ description: 'Total assets at this date (in base currency)',
7801
+ example: '494338.00'
7802
+ },
7803
+ liabilities: {
7804
+ type: 'string',
7805
+ description: 'Total liabilities at this date (in base currency)',
7806
+ example: '310098.00'
7807
+ },
6152
7808
  byCurrency: {
6153
7809
  description: 'Multi-currency breakdown for this point',
6154
7810
  type: 'array',
@@ -6258,6 +7914,111 @@ export const $PortfolioTrendsResponseDto = {
6258
7914
  required: ['series', 'summary', 'period', 'granularity', 'currency']
6259
7915
  } as const;
6260
7916
 
7917
+ export const $CashFlowPointDto = {
7918
+ type: 'object',
7919
+ properties: {
7920
+ month: {
7921
+ type: 'string',
7922
+ description: 'Month key (YYYY-MM)',
7923
+ example: '2024-03'
7924
+ },
7925
+ income: {
7926
+ type: 'string',
7927
+ description: 'Income in base currency (absolute, converted)',
7928
+ example: '10000.00'
7929
+ },
7930
+ expense: {
7931
+ type: 'string',
7932
+ description: 'Expense in base currency (absolute, converted)',
7933
+ example: '5000.00'
7934
+ },
7935
+ netSavings: {
7936
+ type: 'string',
7937
+ description: 'netSavings = income − expense (savings positive)',
7938
+ example: '5000.00'
7939
+ }
7940
+ },
7941
+ required: ['month', 'income', 'expense', 'netSavings']
7942
+ } as const;
7943
+
7944
+ export const $CashFlowTrendSummaryDto = {
7945
+ type: 'object',
7946
+ properties: {
7947
+ totalIncome: {
7948
+ type: 'string',
7949
+ description: 'Total income across the period',
7950
+ example: '60000.00'
7951
+ },
7952
+ totalExpense: {
7953
+ type: 'string',
7954
+ description: 'Total expense across the period',
7955
+ example: '30000.00'
7956
+ },
7957
+ totalNetSavings: {
7958
+ type: 'string',
7959
+ description: 'income − expense across the period',
7960
+ example: '30000.00'
7961
+ },
7962
+ averageMonthlyNetSavings: {
7963
+ type: 'string',
7964
+ description:
7965
+ 'totalNetSavings divided by the window length (N months, incl. zero-filled)',
7966
+ example: '5000.00'
7967
+ }
7968
+ },
7969
+ required: [
7970
+ 'totalIncome',
7971
+ 'totalExpense',
7972
+ 'totalNetSavings',
7973
+ 'averageMonthlyNetSavings'
7974
+ ]
7975
+ } as const;
7976
+
7977
+ export const $CashFlowTrendsResponseDto = {
7978
+ type: 'object',
7979
+ properties: {
7980
+ series: {
7981
+ description:
7982
+ 'Monthly cash-flow series (fixed N-month window, zero-filled)',
7983
+ type: 'array',
7984
+ items: {
7985
+ $ref: '#/components/schemas/CashFlowPointDto'
7986
+ }
7987
+ },
7988
+ summary: {
7989
+ description: 'Period totals',
7990
+ allOf: [
7991
+ {
7992
+ $ref: '#/components/schemas/CashFlowTrendSummaryDto'
7993
+ }
7994
+ ]
7995
+ },
7996
+ period: {
7997
+ type: 'string',
7998
+ description: 'Period requested',
7999
+ example: '6m'
8000
+ },
8001
+ granularity: {
8002
+ type: 'string',
8003
+ description: 'Data granularity (v1 returns month buckets)',
8004
+ example: 'month'
8005
+ },
8006
+ currency: {
8007
+ type: 'string',
8008
+ description: 'Base currency for converted values',
8009
+ example: 'CNY'
8010
+ },
8011
+ warnings: {
8012
+ description: 'Exchange rate warnings (e.g. missing rate for a currency)',
8013
+ type: 'array',
8014
+ items: {
8015
+ $ref: '#/components/schemas/ExchangeRateWarningDto'
8016
+ }
8017
+ }
8018
+ },
8019
+ required: ['series', 'summary', 'period', 'granularity', 'currency']
8020
+ } as const;
8021
+
6261
8022
  export const $GenerateSnapshotBody = {
6262
8023
  type: 'object',
6263
8024
  properties: {}
@@ -6288,3 +8049,15 @@ export const $AnonymousLoginDto = {
6288
8049
  },
6289
8050
  required: ['accessToken']
6290
8051
  } as const;
8052
+
8053
+ export const $AnonymousLoginResponseDto = {
8054
+ type: 'object',
8055
+ properties: {
8056
+ authToken: {
8057
+ type: 'string',
8058
+ description: 'JWT auth token',
8059
+ example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
8060
+ }
8061
+ },
8062
+ required: ['authToken']
8063
+ } as const;