@dizzlkheinz/ynab-mcpb 0.18.4 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +87 -8
- package/bin/ynab-mcp-server.cjs +2 -2
- package/bin/ynab-mcp-server.js +3 -3
- package/biome.json +39 -0
- package/dist/bundle/index.cjs +67 -67
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -27
- package/dist/server/YNABMCPServer.d.ts +3 -4
- package/dist/server/YNABMCPServer.js +111 -116
- package/dist/server/budgetResolver.d.ts +6 -5
- package/dist/server/budgetResolver.js +46 -36
- package/dist/server/cacheKeys.js +6 -6
- package/dist/server/cacheManager.js +14 -11
- package/dist/server/completions.d.ts +2 -2
- package/dist/server/completions.js +20 -15
- package/dist/server/config.d.ts +10 -5
- package/dist/server/config.js +24 -7
- package/dist/server/deltaCache.d.ts +2 -2
- package/dist/server/deltaCache.js +22 -16
- package/dist/server/deltaCache.merge.d.ts +2 -2
- package/dist/server/diagnostics.d.ts +4 -4
- package/dist/server/diagnostics.js +38 -32
- package/dist/server/errorHandler.d.ts +5 -12
- package/dist/server/errorHandler.js +219 -217
- package/dist/server/prompts.d.ts +2 -2
- package/dist/server/prompts.js +45 -45
- package/dist/server/rateLimiter.js +4 -4
- package/dist/server/requestLogger.d.ts +1 -1
- package/dist/server/requestLogger.js +40 -35
- package/dist/server/resources.d.ts +3 -3
- package/dist/server/resources.js +55 -52
- package/dist/server/responseFormatter.js +6 -6
- package/dist/server/securityMiddleware.d.ts +2 -2
- package/dist/server/securityMiddleware.js +22 -20
- package/dist/server/serverKnowledgeStore.js +1 -1
- package/dist/server/toolRegistry.d.ts +3 -3
- package/dist/server/toolRegistry.js +47 -40
- package/dist/tools/__tests__/deltaTestUtils.d.ts +3 -3
- package/dist/tools/__tests__/deltaTestUtils.js +2 -2
- package/dist/tools/accountTools.d.ts +9 -8
- package/dist/tools/accountTools.js +47 -47
- package/dist/tools/adapters.d.ts +13 -8
- package/dist/tools/adapters.js +21 -11
- package/dist/tools/budgetTools.d.ts +8 -7
- package/dist/tools/budgetTools.js +22 -22
- package/dist/tools/categoryTools.d.ts +9 -8
- package/dist/tools/categoryTools.js +68 -59
- package/dist/tools/compareTransactions/formatter.d.ts +3 -3
- package/dist/tools/compareTransactions/formatter.js +9 -9
- package/dist/tools/compareTransactions/index.d.ts +6 -6
- package/dist/tools/compareTransactions/index.js +58 -43
- package/dist/tools/compareTransactions/matcher.d.ts +1 -1
- package/dist/tools/compareTransactions/matcher.js +28 -15
- package/dist/tools/compareTransactions/parser.d.ts +2 -2
- package/dist/tools/compareTransactions/parser.js +144 -138
- package/dist/tools/compareTransactions/types.d.ts +4 -4
- package/dist/tools/compareTransactions.d.ts +1 -1
- package/dist/tools/compareTransactions.js +1 -1
- package/dist/tools/deltaFetcher.d.ts +2 -2
- package/dist/tools/deltaFetcher.js +16 -15
- package/dist/tools/deltaSupport.d.ts +4 -4
- package/dist/tools/deltaSupport.js +35 -41
- package/dist/tools/exportTransactions.d.ts +5 -4
- package/dist/tools/exportTransactions.js +61 -59
- package/dist/tools/monthTools.d.ts +7 -6
- package/dist/tools/monthTools.js +31 -29
- package/dist/tools/payeeTools.d.ts +7 -6
- package/dist/tools/payeeTools.js +28 -28
- package/dist/tools/reconcileAdapter.d.ts +2 -2
- package/dist/tools/reconcileAdapter.js +19 -12
- package/dist/tools/reconciliation/analyzer.d.ts +4 -4
- package/dist/tools/reconciliation/analyzer.js +73 -59
- package/dist/tools/reconciliation/csvParser.d.ts +3 -3
- package/dist/tools/reconciliation/csvParser.js +128 -104
- package/dist/tools/reconciliation/executor.d.ts +4 -4
- package/dist/tools/reconciliation/executor.js +148 -109
- package/dist/tools/reconciliation/index.d.ts +10 -10
- package/dist/tools/reconciliation/index.js +96 -83
- package/dist/tools/reconciliation/matcher.d.ts +3 -3
- package/dist/tools/reconciliation/matcher.js +17 -16
- package/dist/tools/reconciliation/payeeNormalizer.js +19 -8
- package/dist/tools/reconciliation/recommendationEngine.d.ts +1 -1
- package/dist/tools/reconciliation/recommendationEngine.js +40 -40
- package/dist/tools/reconciliation/reportFormatter.d.ts +2 -2
- package/dist/tools/reconciliation/reportFormatter.js +59 -58
- package/dist/tools/reconciliation/signDetector.d.ts +1 -1
- package/dist/tools/reconciliation/types.d.ts +16 -16
- package/dist/tools/reconciliation/ynabAdapter.d.ts +2 -2
- package/dist/tools/schemas/common.d.ts +1 -1
- package/dist/tools/schemas/common.js +1 -1
- package/dist/tools/schemas/outputs/accountOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/accountOutputs.js +24 -18
- package/dist/tools/schemas/outputs/budgetOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/budgetOutputs.js +14 -11
- package/dist/tools/schemas/outputs/categoryOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/categoryOutputs.js +49 -29
- package/dist/tools/schemas/outputs/comparisonOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/comparisonOutputs.js +12 -12
- package/dist/tools/schemas/outputs/index.d.ts +14 -14
- package/dist/tools/schemas/outputs/index.js +14 -14
- package/dist/tools/schemas/outputs/monthOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/monthOutputs.js +56 -41
- package/dist/tools/schemas/outputs/payeeOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/payeeOutputs.js +10 -10
- package/dist/tools/schemas/outputs/reconciliationOutputs.d.ts +2 -2
- package/dist/tools/schemas/outputs/reconciliationOutputs.js +45 -45
- package/dist/tools/schemas/outputs/transactionMutationOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/transactionMutationOutputs.js +28 -22
- package/dist/tools/schemas/outputs/transactionOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/transactionOutputs.js +43 -35
- package/dist/tools/schemas/outputs/utilityOutputs.d.ts +1 -1
- package/dist/tools/schemas/outputs/utilityOutputs.js +5 -3
- package/dist/tools/schemas/shared/commonOutputs.d.ts +1 -1
- package/dist/tools/schemas/shared/commonOutputs.js +15 -9
- package/dist/tools/transactionReadTools.d.ts +11 -0
- package/dist/tools/transactionReadTools.js +202 -0
- package/dist/tools/transactionSchemas.d.ts +7 -7
- package/dist/tools/transactionSchemas.js +77 -57
- package/dist/tools/transactionTools.d.ts +6 -24
- package/dist/tools/transactionTools.js +7 -1499
- package/dist/tools/transactionUtils.d.ts +6 -6
- package/dist/tools/transactionUtils.js +78 -63
- package/dist/tools/transactionWriteTools.d.ts +20 -0
- package/dist/tools/transactionWriteTools.js +1342 -0
- package/dist/tools/utilityTools.d.ts +5 -4
- package/dist/tools/utilityTools.js +11 -11
- package/dist/types/index.d.ts +7 -7
- package/dist/types/index.js +6 -6
- package/dist/types/reconciliation.d.ts +1 -1
- package/dist/types/toolRegistration.d.ts +14 -12
- package/dist/utils/amountUtils.js +1 -1
- package/dist/utils/dateUtils.js +4 -4
- package/dist/utils/errors.d.ts +3 -3
- package/dist/utils/errors.js +4 -4
- package/dist/utils/money.d.ts +2 -2
- package/dist/utils/money.js +8 -8
- package/dist/utils/validationError.d.ts +1 -1
- package/dist/utils/validationError.js +1 -1
- package/docs/assets/examples/reconciliation-with-recommendations.json +66 -66
- package/docs/assets/schemas/reconciliation-v2.json +360 -336
- package/esbuild.config.mjs +53 -50
- package/meta.json +12548 -12548
- package/package.json +98 -111
- package/scripts/analyze-bundle.mjs +33 -30
- package/scripts/create-pr-description.js +169 -120
- package/scripts/run-all-tests.js +178 -169
- package/scripts/run-domain-integration-tests.js +28 -18
- package/scripts/run-generate-mcpb.js +19 -17
- package/scripts/run-throttled-integration-tests.js +92 -83
- package/scripts/test-delta-params.mjs +149 -120
- package/scripts/test-recommendations.ts +36 -32
- package/scripts/tmpTransaction.ts +80 -43
- package/scripts/validate-env.js +98 -91
- package/scripts/verify-build.js +78 -76
- package/src/__tests__/comprehensive.integration.test.ts +1281 -1154
- package/src/__tests__/performance.test.ts +723 -671
- package/src/__tests__/setup.ts +442 -395
- package/src/__tests__/smoke.e2e.test.ts +41 -39
- package/src/__tests__/testRunner.ts +314 -295
- package/src/__tests__/testUtils.ts +456 -364
- package/src/__tests__/tools/reconciliation/csvParser.integration.test.ts +109 -107
- package/src/__tests__/tools/reconciliation/real-world.integration.test.ts +41 -41
- package/src/index.ts +68 -59
- package/src/server/CLAUDE.md +480 -0
- package/src/server/YNABMCPServer.ts +821 -794
- package/src/server/__tests__/YNABMCPServer.integration.test.ts +929 -893
- package/src/server/__tests__/YNABMCPServer.test.ts +903 -899
- package/src/server/__tests__/budgetResolver.test.ts +466 -423
- package/src/server/__tests__/cacheManager.test.ts +891 -874
- package/src/server/__tests__/completions.integration.test.ts +115 -106
- package/src/server/__tests__/completions.test.ts +334 -313
- package/src/server/__tests__/config.test.ts +98 -86
- package/src/server/__tests__/deltaCache.merge.test.ts +774 -703
- package/src/server/__tests__/deltaCache.swr.test.ts +198 -153
- package/src/server/__tests__/deltaCache.test.ts +946 -759
- package/src/server/__tests__/diagnostics.test.ts +825 -792
- package/src/server/__tests__/errorHandler.integration.test.ts +512 -462
- package/src/server/__tests__/errorHandler.test.ts +402 -397
- package/src/server/__tests__/prompts.test.ts +424 -347
- package/src/server/__tests__/rateLimiter.test.ts +313 -309
- package/src/server/__tests__/requestLogger.test.ts +443 -403
- package/src/server/__tests__/resources.template.test.ts +196 -185
- package/src/server/__tests__/resources.test.ts +294 -288
- package/src/server/__tests__/security.integration.test.ts +487 -421
- package/src/server/__tests__/securityMiddleware.test.ts +519 -444
- package/src/server/__tests__/server-startup.integration.test.ts +509 -490
- package/src/server/__tests__/serverKnowledgeStore.test.ts +174 -173
- package/src/server/__tests__/toolRegistration.test.ts +239 -210
- package/src/server/__tests__/toolRegistry.test.ts +907 -845
- package/src/server/budgetResolver.ts +221 -181
- package/src/server/cacheKeys.ts +6 -6
- package/src/server/cacheManager.ts +498 -484
- package/src/server/completions.ts +267 -243
- package/src/server/config.ts +35 -14
- package/src/server/deltaCache.merge.ts +146 -128
- package/src/server/deltaCache.ts +352 -309
- package/src/server/diagnostics.ts +257 -242
- package/src/server/errorHandler.ts +747 -744
- package/src/server/prompts.ts +181 -176
- package/src/server/rateLimiter.ts +131 -129
- package/src/server/requestLogger.ts +350 -322
- package/src/server/resources.ts +442 -374
- package/src/server/responseFormatter.ts +41 -37
- package/src/server/securityMiddleware.ts +223 -205
- package/src/server/serverKnowledgeStore.ts +67 -67
- package/src/server/toolRegistry.ts +508 -474
- package/src/tools/CLAUDE.md +604 -0
- package/src/tools/__tests__/accountTools.delta.integration.test.ts +128 -111
- package/src/tools/__tests__/accountTools.integration.test.ts +129 -111
- package/src/tools/__tests__/accountTools.test.ts +685 -638
- package/src/tools/__tests__/adapters.test.ts +142 -108
- package/src/tools/__tests__/budgetTools.delta.integration.test.ts +73 -73
- package/src/tools/__tests__/budgetTools.integration.test.ts +132 -124
- package/src/tools/__tests__/budgetTools.test.ts +442 -413
- package/src/tools/__tests__/categoryTools.delta.integration.test.ts +76 -68
- package/src/tools/__tests__/categoryTools.integration.test.ts +314 -288
- package/src/tools/__tests__/categoryTools.test.ts +656 -625
- package/src/tools/__tests__/compareTransactions/formatter.test.ts +535 -462
- package/src/tools/__tests__/compareTransactions/index.test.ts +378 -358
- package/src/tools/__tests__/compareTransactions/matcher.test.ts +497 -398
- package/src/tools/__tests__/compareTransactions/parser.test.ts +765 -747
- package/src/tools/__tests__/compareTransactions.test.ts +352 -332
- package/src/tools/__tests__/compareTransactions.window.test.ts +150 -146
- package/src/tools/__tests__/deltaFetcher.scheduled.integration.test.ts +69 -65
- package/src/tools/__tests__/deltaFetcher.test.ts +325 -265
- package/src/tools/__tests__/deltaSupport.test.ts +211 -184
- package/src/tools/__tests__/deltaTestUtils.ts +37 -33
- package/src/tools/__tests__/exportTransactions.test.ts +205 -200
- package/src/tools/__tests__/monthTools.delta.integration.test.ts +68 -68
- package/src/tools/__tests__/monthTools.integration.test.ts +178 -166
- package/src/tools/__tests__/monthTools.test.ts +561 -512
- package/src/tools/__tests__/payeeTools.delta.integration.test.ts +68 -68
- package/src/tools/__tests__/payeeTools.integration.test.ts +158 -142
- package/src/tools/__tests__/payeeTools.test.ts +486 -434
- package/src/tools/__tests__/transactionSchemas.test.ts +1202 -1186
- package/src/tools/__tests__/transactionTools.integration.test.ts +875 -825
- package/src/tools/__tests__/transactionTools.test.ts +4923 -4366
- package/src/tools/__tests__/transactionUtils.test.ts +1004 -977
- package/src/tools/__tests__/utilityTools.integration.test.ts +32 -32
- package/src/tools/__tests__/utilityTools.test.ts +68 -58
- package/src/tools/accountTools.ts +293 -271
- package/src/tools/adapters.ts +120 -63
- package/src/tools/budgetTools.ts +121 -116
- package/src/tools/categoryTools.ts +379 -339
- package/src/tools/compareTransactions/formatter.ts +131 -119
- package/src/tools/compareTransactions/index.ts +249 -214
- package/src/tools/compareTransactions/matcher.ts +259 -209
- package/src/tools/compareTransactions/parser.ts +517 -487
- package/src/tools/compareTransactions/types.ts +38 -38
- package/src/tools/compareTransactions.ts +1 -1
- package/src/tools/deltaFetcher.ts +281 -260
- package/src/tools/deltaSupport.ts +264 -259
- package/src/tools/exportTransactions.ts +230 -218
- package/src/tools/monthTools.ts +180 -165
- package/src/tools/payeeTools.ts +152 -140
- package/src/tools/reconcileAdapter.ts +297 -252
- package/src/tools/reconciliation/CLAUDE.md +506 -0
- package/src/tools/reconciliation/__tests__/adapter.causes.test.ts +133 -124
- package/src/tools/reconciliation/__tests__/adapter.test.ts +249 -230
- package/src/tools/reconciliation/__tests__/analyzer.test.ts +408 -400
- package/src/tools/reconciliation/__tests__/csvParser.test.ts +71 -69
- package/src/tools/reconciliation/__tests__/executor.integration.test.ts +348 -323
- package/src/tools/reconciliation/__tests__/executor.progress.test.ts +503 -457
- package/src/tools/reconciliation/__tests__/executor.test.ts +898 -831
- package/src/tools/reconciliation/__tests__/matcher.test.ts +667 -663
- package/src/tools/reconciliation/__tests__/payeeNormalizer.test.ts +296 -276
- package/src/tools/reconciliation/__tests__/recommendationEngine.integration.test.ts +692 -624
- package/src/tools/reconciliation/__tests__/recommendationEngine.test.ts +1008 -989
- package/src/tools/reconciliation/__tests__/reconciliation.delta.integration.test.ts +187 -146
- package/src/tools/reconciliation/__tests__/reportFormatter.test.ts +583 -533
- package/src/tools/reconciliation/__tests__/scenarios/adapterCurrency.scenario.test.ts +75 -74
- package/src/tools/reconciliation/__tests__/scenarios/extremes.scenario.test.ts +70 -62
- package/src/tools/reconciliation/__tests__/scenarios/repeatAmount.scenario.test.ts +102 -88
- package/src/tools/reconciliation/__tests__/schemaUrl.test.ts +56 -55
- package/src/tools/reconciliation/__tests__/signDetector.test.ts +209 -206
- package/src/tools/reconciliation/__tests__/ynabAdapter.test.ts +66 -60
- package/src/tools/reconciliation/analyzer.ts +564 -504
- package/src/tools/reconciliation/csvParser.ts +656 -609
- package/src/tools/reconciliation/executor.ts +1290 -1128
- package/src/tools/reconciliation/index.ts +580 -528
- package/src/tools/reconciliation/matcher.ts +256 -240
- package/src/tools/reconciliation/payeeNormalizer.ts +92 -78
- package/src/tools/reconciliation/recommendationEngine.ts +357 -345
- package/src/tools/reconciliation/reportFormatter.ts +343 -307
- package/src/tools/reconciliation/signDetector.ts +89 -83
- package/src/tools/reconciliation/types.ts +164 -159
- package/src/tools/reconciliation/ynabAdapter.ts +17 -15
- package/src/tools/schemas/CLAUDE.md +546 -0
- package/src/tools/schemas/common.ts +1 -1
- package/src/tools/schemas/outputs/__tests__/accountOutputs.test.ts +410 -409
- package/src/tools/schemas/outputs/__tests__/budgetOutputs.test.ts +305 -299
- package/src/tools/schemas/outputs/__tests__/categoryOutputs.test.ts +431 -430
- package/src/tools/schemas/outputs/__tests__/comparisonOutputs.test.ts +510 -495
- package/src/tools/schemas/outputs/__tests__/dateValidation.test.ts +179 -153
- package/src/tools/schemas/outputs/__tests__/discrepancyDirection.test.ts +293 -254
- package/src/tools/schemas/outputs/__tests__/monthOutputs.test.ts +457 -457
- package/src/tools/schemas/outputs/__tests__/payeeOutputs.test.ts +362 -356
- package/src/tools/schemas/outputs/__tests__/reconciliationOutputs.test.ts +402 -399
- package/src/tools/schemas/outputs/__tests__/transactionMutationSchemas.test.ts +225 -211
- package/src/tools/schemas/outputs/__tests__/transactionOutputs.test.ts +457 -454
- package/src/tools/schemas/outputs/__tests__/utilityOutputs.test.ts +316 -315
- package/src/tools/schemas/outputs/accountOutputs.ts +40 -34
- package/src/tools/schemas/outputs/budgetOutputs.ts +24 -19
- package/src/tools/schemas/outputs/categoryOutputs.ts +76 -56
- package/src/tools/schemas/outputs/comparisonOutputs.ts +192 -169
- package/src/tools/schemas/outputs/index.ts +163 -163
- package/src/tools/schemas/outputs/monthOutputs.ts +95 -80
- package/src/tools/schemas/outputs/payeeOutputs.ts +18 -18
- package/src/tools/schemas/outputs/reconciliationOutputs.ts +386 -373
- package/src/tools/schemas/outputs/transactionMutationOutputs.ts +259 -231
- package/src/tools/schemas/outputs/transactionOutputs.ts +81 -71
- package/src/tools/schemas/outputs/utilityOutputs.ts +90 -84
- package/src/tools/schemas/shared/commonOutputs.ts +27 -19
- package/src/tools/toolCategories.ts +114 -114
- package/src/tools/transactionReadTools.ts +327 -0
- package/src/tools/transactionSchemas.ts +322 -291
- package/src/tools/transactionTools.ts +84 -2246
- package/src/tools/transactionUtils.ts +507 -422
- package/src/tools/transactionWriteTools.ts +2110 -0
- package/src/tools/utilityTools.ts +46 -41
- package/src/types/CLAUDE.md +477 -0
- package/src/types/__tests__/index.test.ts +51 -51
- package/src/types/index.ts +43 -39
- package/src/types/integration-tests.d.ts +26 -26
- package/src/types/reconciliation.ts +29 -29
- package/src/types/toolAnnotations.ts +30 -30
- package/src/types/toolRegistration.ts +43 -32
- package/src/utils/CLAUDE.md +508 -0
- package/src/utils/__tests__/dateUtils.test.ts +174 -168
- package/src/utils/__tests__/money.test.ts +193 -187
- package/src/utils/amountUtils.ts +5 -5
- package/src/utils/baseError.ts +5 -5
- package/src/utils/dateUtils.ts +29 -26
- package/src/utils/errors.ts +14 -14
- package/src/utils/money.ts +66 -52
- package/src/utils/validationError.ts +1 -1
- package/tsconfig.json +29 -29
- package/tsconfig.prod.json +16 -16
- package/vitest-reporters/split-json-reporter.ts +247 -204
- package/vitest.config.ts +99 -95
- package/.prettierignore +0 -10
- package/.prettierrc.json +0 -10
- package/eslint.config.js +0 -49
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
import { randomUUID } from
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
fromMilli,
|
|
4
|
+
toMoneyValue,
|
|
5
|
+
toMoneyValueFromDecimal,
|
|
6
|
+
} from "../../utils/money.js";
|
|
2
7
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const RECOMMENDATION_VERSION = '1.0';
|
|
8
|
+
ActionableRecommendation,
|
|
9
|
+
BankTransaction,
|
|
10
|
+
CreateTransactionRecommendation,
|
|
11
|
+
ManualReviewRecommendation,
|
|
12
|
+
RecommendationContext,
|
|
13
|
+
ReconciliationInsight,
|
|
14
|
+
ReviewDuplicateRecommendation,
|
|
15
|
+
TransactionMatch,
|
|
16
|
+
UpdateClearedRecommendation,
|
|
17
|
+
YNABTransaction,
|
|
18
|
+
} from "./types.js";
|
|
19
|
+
|
|
20
|
+
const RECOMMENDATION_VERSION = "1.0";
|
|
17
21
|
|
|
18
22
|
/**
|
|
19
23
|
* Confidence scores for different recommendation types
|
|
20
24
|
*/
|
|
21
25
|
const CONFIDENCE = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
CREATE_EXACT_MATCH: 0.95,
|
|
27
|
+
NEAR_MATCH_REVIEW: 0.7,
|
|
28
|
+
REPEAT_AMOUNT: 0.75,
|
|
29
|
+
ANOMALY_REVIEW: 0.5,
|
|
30
|
+
UNMATCHED_BANK: 0.8,
|
|
31
|
+
UPDATE_CLEARED: 0.6,
|
|
28
32
|
} as const;
|
|
29
33
|
|
|
30
34
|
/**
|
|
@@ -56,44 +60,44 @@ const PRIORITY_ORDER = { high: 3, medium: 2, low: 1 } as const;
|
|
|
56
60
|
* // Returns recommendations like create_transaction, update_cleared, etc.
|
|
57
61
|
*/
|
|
58
62
|
export function generateRecommendations(
|
|
59
|
-
|
|
63
|
+
context: RecommendationContext,
|
|
60
64
|
): ActionableRecommendation[] {
|
|
61
|
-
|
|
65
|
+
const recommendations: ActionableRecommendation[] = [];
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
// Process insights from analyzer
|
|
68
|
+
for (const insight of context.analysis.insights) {
|
|
69
|
+
const recs = processInsight(insight, context);
|
|
70
|
+
recommendations.push(...recs);
|
|
71
|
+
}
|
|
68
72
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
// Process unmatched transactions
|
|
74
|
+
const unmatchedRecs = processUnmatchedTransactions(context);
|
|
75
|
+
recommendations.push(...unmatchedRecs);
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
// Sort by priority and confidence
|
|
78
|
+
return sortRecommendations(recommendations);
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
/**
|
|
78
82
|
* Process a single insight into recommendations
|
|
79
83
|
*/
|
|
80
84
|
function processInsight(
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
insight: ReconciliationInsight,
|
|
86
|
+
context: RecommendationContext,
|
|
83
87
|
): ActionableRecommendation[] {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
switch (insight.type) {
|
|
89
|
+
case "near_match":
|
|
90
|
+
return [createNearMatchRecommendation(insight, context)];
|
|
87
91
|
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
case "repeat_amount":
|
|
93
|
+
return createRepeatAmountRecommendations(insight, context);
|
|
90
94
|
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
case "anomaly":
|
|
96
|
+
return [createManualReviewRecommendation(insight, context)];
|
|
93
97
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
default:
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
/**
|
|
@@ -136,274 +140,281 @@ function processInsight(
|
|
|
136
140
|
* ); // Returns: create_transaction
|
|
137
141
|
*/
|
|
138
142
|
function createSuggestedMatchRecommendation(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
):
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
143
|
+
match: TransactionMatch,
|
|
144
|
+
context: RecommendationContext,
|
|
145
|
+
):
|
|
146
|
+
| CreateTransactionRecommendation
|
|
147
|
+
| ReviewDuplicateRecommendation
|
|
148
|
+
| ManualReviewRecommendation {
|
|
149
|
+
const bankTxn = match.bankTransaction;
|
|
150
|
+
|
|
151
|
+
// If there's a suggested YNAB transaction, review as possible duplicate
|
|
152
|
+
if (match.ynabTransaction && match.confidence !== "none") {
|
|
153
|
+
return {
|
|
154
|
+
id: randomUUID(),
|
|
155
|
+
action_type: "review_duplicate",
|
|
156
|
+
priority: "high",
|
|
157
|
+
confidence: Math.max(0, Math.min(1, match.confidenceScore / 100)),
|
|
158
|
+
message: `Review possible match: ${bankTxn.payee}`,
|
|
159
|
+
reason: match.matchReason,
|
|
160
|
+
estimated_impact: toMoneyValueFromDecimal(
|
|
161
|
+
0,
|
|
162
|
+
context.analysis.balance_info.current_cleared.currency,
|
|
163
|
+
),
|
|
164
|
+
account_id: context.account_id,
|
|
165
|
+
metadata: {
|
|
166
|
+
version: RECOMMENDATION_VERSION,
|
|
167
|
+
created_at: new Date().toISOString(),
|
|
168
|
+
},
|
|
169
|
+
parameters: {
|
|
170
|
+
candidate_ids: [match.ynabTransaction.id],
|
|
171
|
+
bank_transaction: bankTxn,
|
|
172
|
+
suggested_match_id: match.ynabTransaction.id,
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Check for combination matches (multiple YNAB transactions that together match the bank transaction)
|
|
178
|
+
const isCombinationMatch = (match.candidates?.length ?? 0) > 1;
|
|
179
|
+
|
|
180
|
+
if (isCombinationMatch) {
|
|
181
|
+
return createCombinationReviewRecommendation(match, context);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Otherwise suggest creating new transaction
|
|
185
|
+
const parameters: CreateTransactionRecommendation["parameters"] = {
|
|
186
|
+
account_id: context.account_id,
|
|
187
|
+
date: bankTxn.date,
|
|
188
|
+
amount: bankTxn.amount, // Amount is already milliunits
|
|
189
|
+
payee_name: bankTxn.payee,
|
|
190
|
+
cleared: "cleared",
|
|
191
|
+
approved: true,
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
if (bankTxn.memo) {
|
|
195
|
+
parameters.memo = bankTxn.memo;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
id: randomUUID(),
|
|
200
|
+
action_type: "create_transaction",
|
|
201
|
+
priority: "high",
|
|
202
|
+
confidence: CONFIDENCE.CREATE_EXACT_MATCH,
|
|
203
|
+
message: `Create transaction for ${bankTxn.payee}`,
|
|
204
|
+
reason: "This transaction exactly matches your discrepancy",
|
|
205
|
+
estimated_impact: toMoneyValue(
|
|
206
|
+
bankTxn.amount,
|
|
207
|
+
context.analysis.balance_info.current_cleared.currency,
|
|
208
|
+
),
|
|
209
|
+
account_id: context.account_id,
|
|
210
|
+
metadata: {
|
|
211
|
+
version: RECOMMENDATION_VERSION,
|
|
212
|
+
created_at: new Date().toISOString(),
|
|
213
|
+
},
|
|
214
|
+
parameters,
|
|
215
|
+
};
|
|
209
216
|
}
|
|
210
217
|
|
|
211
218
|
/**
|
|
212
219
|
* Create recommendation for combination match (multiple YNAB transactions matching one bank transaction)
|
|
213
220
|
*/
|
|
214
221
|
function createCombinationReviewRecommendation(
|
|
215
|
-
|
|
216
|
-
|
|
222
|
+
match: TransactionMatch,
|
|
223
|
+
context: RecommendationContext,
|
|
217
224
|
): ManualReviewRecommendation {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
225
|
+
const bankTxn = match.bankTransaction;
|
|
226
|
+
const candidateIds =
|
|
227
|
+
match.candidates?.map((candidate) => candidate.ynab_transaction.id) ?? [];
|
|
228
|
+
|
|
229
|
+
// Calculate total amount from candidates for context (convert from milliunits to decimal)
|
|
230
|
+
const candidateTotalAmount =
|
|
231
|
+
match.candidates?.reduce((sum, candidate) => {
|
|
232
|
+
const amount = candidate.ynab_transaction.amount;
|
|
233
|
+
if (!Number.isFinite(amount)) {
|
|
234
|
+
console.warn(`Invalid candidate amount: ${amount}`);
|
|
235
|
+
return sum;
|
|
236
|
+
}
|
|
237
|
+
return sum + fromMilli(amount);
|
|
238
|
+
}, 0) ?? 0;
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
id: randomUUID(),
|
|
242
|
+
action_type: "manual_review",
|
|
243
|
+
priority: "medium",
|
|
244
|
+
confidence: CONFIDENCE.NEAR_MATCH_REVIEW,
|
|
245
|
+
message: `Review combination match: ${bankTxn.payee}`,
|
|
246
|
+
reason:
|
|
247
|
+
match.recommendation ??
|
|
248
|
+
"Multiple YNAB transactions appear to match this bank transaction. Review before creating anything new.",
|
|
249
|
+
estimated_impact: toMoneyValueFromDecimal(
|
|
250
|
+
0,
|
|
251
|
+
context.analysis.balance_info.current_cleared.currency,
|
|
252
|
+
),
|
|
253
|
+
account_id: context.account_id,
|
|
254
|
+
metadata: {
|
|
255
|
+
version: RECOMMENDATION_VERSION,
|
|
256
|
+
created_at: new Date().toISOString(),
|
|
257
|
+
bank_transaction_amount: toMoneyValue(
|
|
258
|
+
bankTxn.amount,
|
|
259
|
+
context.analysis.balance_info.current_cleared.currency,
|
|
260
|
+
),
|
|
261
|
+
candidate_total_amount: toMoneyValueFromDecimal(
|
|
262
|
+
candidateTotalAmount,
|
|
263
|
+
context.analysis.balance_info.current_cleared.currency,
|
|
264
|
+
),
|
|
265
|
+
candidate_count: match.candidates?.length ?? 0,
|
|
266
|
+
},
|
|
267
|
+
parameters: {
|
|
268
|
+
issue_type: "complex_match",
|
|
269
|
+
related_transactions: [
|
|
270
|
+
{
|
|
271
|
+
source: "bank",
|
|
272
|
+
id: bankTxn.id,
|
|
273
|
+
description: bankTxn.payee,
|
|
274
|
+
},
|
|
275
|
+
...candidateIds.map((id) => ({
|
|
276
|
+
source: "ynab" as const,
|
|
277
|
+
id,
|
|
278
|
+
description:
|
|
279
|
+
match.candidates?.find((c) => c.ynab_transaction.id === id)
|
|
280
|
+
?.ynab_transaction.payee ?? "Unknown",
|
|
281
|
+
})),
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
};
|
|
277
285
|
}
|
|
278
286
|
|
|
279
287
|
/**
|
|
280
288
|
* Create recommendation for near match insight (possible duplicate)
|
|
281
289
|
*/
|
|
282
290
|
function createNearMatchRecommendation(
|
|
283
|
-
|
|
284
|
-
|
|
291
|
+
insight: ReconciliationInsight,
|
|
292
|
+
context: RecommendationContext,
|
|
285
293
|
): ManualReviewRecommendation {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
294
|
+
return {
|
|
295
|
+
id: randomUUID(),
|
|
296
|
+
action_type: "manual_review",
|
|
297
|
+
priority: "medium",
|
|
298
|
+
confidence: CONFIDENCE.NEAR_MATCH_REVIEW,
|
|
299
|
+
message: `Review: ${insight.title}`,
|
|
300
|
+
reason: insight.description,
|
|
301
|
+
estimated_impact: toMoneyValueFromDecimal(
|
|
302
|
+
0,
|
|
303
|
+
context.analysis.balance_info.current_cleared.currency,
|
|
304
|
+
),
|
|
305
|
+
account_id: context.account_id,
|
|
306
|
+
source_insight_id: insight.id,
|
|
307
|
+
metadata: {
|
|
308
|
+
version: RECOMMENDATION_VERSION,
|
|
309
|
+
created_at: new Date().toISOString(),
|
|
310
|
+
current_discrepancy: context.analysis.balance_info.discrepancy,
|
|
311
|
+
insight_severity: insight.severity,
|
|
312
|
+
},
|
|
313
|
+
parameters: {
|
|
314
|
+
issue_type: "complex_match",
|
|
315
|
+
},
|
|
316
|
+
};
|
|
309
317
|
}
|
|
310
318
|
|
|
311
319
|
/**
|
|
312
320
|
* Create recommendations for repeat amount pattern
|
|
313
321
|
*/
|
|
314
322
|
function createRepeatAmountRecommendations(
|
|
315
|
-
|
|
316
|
-
|
|
323
|
+
insight: ReconciliationInsight,
|
|
324
|
+
context: RecommendationContext,
|
|
317
325
|
): ManualReviewRecommendation[] {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
326
|
+
// For repeat amounts, suggest manual review since we need to identify the specific transactions
|
|
327
|
+
return [
|
|
328
|
+
{
|
|
329
|
+
id: randomUUID(),
|
|
330
|
+
action_type: "manual_review",
|
|
331
|
+
priority: "medium",
|
|
332
|
+
confidence: CONFIDENCE.REPEAT_AMOUNT,
|
|
333
|
+
message: `Review recurring pattern: ${insight.title}`,
|
|
334
|
+
reason: insight.description,
|
|
335
|
+
estimated_impact: toMoneyValueFromDecimal(
|
|
336
|
+
0,
|
|
337
|
+
context.analysis.balance_info.current_cleared.currency,
|
|
338
|
+
),
|
|
339
|
+
account_id: context.account_id,
|
|
340
|
+
source_insight_id: insight.id,
|
|
341
|
+
metadata: {
|
|
342
|
+
version: RECOMMENDATION_VERSION,
|
|
343
|
+
created_at: new Date().toISOString(),
|
|
344
|
+
current_discrepancy: context.analysis.balance_info.discrepancy,
|
|
345
|
+
insight_severity: insight.severity,
|
|
346
|
+
},
|
|
347
|
+
parameters: {
|
|
348
|
+
issue_type: "complex_match",
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
];
|
|
344
352
|
}
|
|
345
353
|
|
|
346
354
|
/**
|
|
347
355
|
* Create manual review recommendation (fallback)
|
|
348
356
|
*/
|
|
349
357
|
function createManualReviewRecommendation(
|
|
350
|
-
|
|
351
|
-
|
|
358
|
+
insight: ReconciliationInsight,
|
|
359
|
+
context: RecommendationContext,
|
|
352
360
|
): ManualReviewRecommendation {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
361
|
+
return {
|
|
362
|
+
id: randomUUID(),
|
|
363
|
+
action_type: "manual_review",
|
|
364
|
+
priority: "low",
|
|
365
|
+
confidence: CONFIDENCE.ANOMALY_REVIEW,
|
|
366
|
+
message: `Review: ${insight.title}`,
|
|
367
|
+
reason: insight.description,
|
|
368
|
+
estimated_impact: toMoneyValueFromDecimal(
|
|
369
|
+
0,
|
|
370
|
+
context.analysis.balance_info.current_cleared.currency,
|
|
371
|
+
),
|
|
372
|
+
account_id: context.account_id,
|
|
373
|
+
source_insight_id: insight.id,
|
|
374
|
+
metadata: {
|
|
375
|
+
version: RECOMMENDATION_VERSION,
|
|
376
|
+
created_at: new Date().toISOString(),
|
|
377
|
+
current_discrepancy: context.analysis.balance_info.discrepancy,
|
|
378
|
+
insight_severity: insight.severity,
|
|
379
|
+
},
|
|
380
|
+
parameters: {
|
|
381
|
+
issue_type:
|
|
382
|
+
insight.severity === "critical" ? "large_discrepancy" : "unknown",
|
|
383
|
+
},
|
|
384
|
+
};
|
|
376
385
|
}
|
|
377
386
|
|
|
378
387
|
/**
|
|
379
388
|
* Process unmatched transactions into recommendations
|
|
380
389
|
*/
|
|
381
|
-
function processUnmatchedTransactions(
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
390
|
+
function processUnmatchedTransactions(
|
|
391
|
+
context: RecommendationContext,
|
|
392
|
+
): ActionableRecommendation[] {
|
|
393
|
+
const recommendations: ActionableRecommendation[] = [];
|
|
394
|
+
|
|
395
|
+
// Unmatched bank transactions → create_transaction
|
|
396
|
+
for (const bankTxn of context.analysis.unmatched_bank) {
|
|
397
|
+
recommendations.push(createUnmatchedBankRecommendation(bankTxn, context));
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Suggested matches → review as potential duplicates or auto-match
|
|
401
|
+
const matchesForReview = [
|
|
402
|
+
...context.analysis.suggested_matches,
|
|
403
|
+
...context.analysis.auto_matches,
|
|
404
|
+
];
|
|
405
|
+
|
|
406
|
+
for (const match of matchesForReview) {
|
|
407
|
+
recommendations.push(createSuggestedMatchRecommendation(match, context));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Unmatched YNAB uncleared → update_cleared (lower priority)
|
|
411
|
+
for (const ynabTxn of context.analysis.unmatched_ynab) {
|
|
412
|
+
if (ynabTxn.cleared === "uncleared") {
|
|
413
|
+
recommendations.push(createUpdateClearedRecommendation(ynabTxn, context));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return recommendations;
|
|
407
418
|
}
|
|
408
419
|
|
|
409
420
|
/**
|
|
@@ -418,40 +429,40 @@ function processUnmatchedTransactions(context: RecommendationContext): Actionabl
|
|
|
418
429
|
* @returns create_transaction recommendation with medium priority and 0.8 confidence
|
|
419
430
|
*/
|
|
420
431
|
function createUnmatchedBankRecommendation(
|
|
421
|
-
|
|
422
|
-
|
|
432
|
+
txn: BankTransaction,
|
|
433
|
+
context: RecommendationContext,
|
|
423
434
|
): CreateTransactionRecommendation {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
435
|
+
const parameters: CreateTransactionRecommendation["parameters"] = {
|
|
436
|
+
account_id: context.account_id,
|
|
437
|
+
date: txn.date,
|
|
438
|
+
amount: txn.amount, // Amount is already milliunits
|
|
439
|
+
payee_name: txn.payee,
|
|
440
|
+
cleared: "cleared",
|
|
441
|
+
approved: true,
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
if (txn.memo) {
|
|
445
|
+
parameters.memo = txn.memo;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return {
|
|
449
|
+
id: randomUUID(),
|
|
450
|
+
action_type: "create_transaction",
|
|
451
|
+
priority: "medium",
|
|
452
|
+
confidence: CONFIDENCE.UNMATCHED_BANK,
|
|
453
|
+
message: `Create missing transaction: ${txn.payee}`,
|
|
454
|
+
reason: "Transaction appears on bank statement but not in YNAB",
|
|
455
|
+
estimated_impact: toMoneyValue(
|
|
456
|
+
txn.amount,
|
|
457
|
+
context.analysis.balance_info.current_cleared.currency,
|
|
458
|
+
),
|
|
459
|
+
account_id: context.account_id,
|
|
460
|
+
metadata: {
|
|
461
|
+
version: RECOMMENDATION_VERSION,
|
|
462
|
+
created_at: new Date().toISOString(),
|
|
463
|
+
},
|
|
464
|
+
parameters,
|
|
465
|
+
};
|
|
455
466
|
}
|
|
456
467
|
|
|
457
468
|
/**
|
|
@@ -467,44 +478,45 @@ function createUnmatchedBankRecommendation(
|
|
|
467
478
|
* @returns update_cleared recommendation with low priority and 0.6 confidence
|
|
468
479
|
*/
|
|
469
480
|
function createUpdateClearedRecommendation(
|
|
470
|
-
|
|
471
|
-
|
|
481
|
+
txn: YNABTransaction,
|
|
482
|
+
context: RecommendationContext,
|
|
472
483
|
): UpdateClearedRecommendation {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
484
|
+
return {
|
|
485
|
+
id: randomUUID(),
|
|
486
|
+
action_type: "update_cleared",
|
|
487
|
+
priority: "low",
|
|
488
|
+
confidence: CONFIDENCE.UPDATE_CLEARED,
|
|
489
|
+
message: `Mark transaction as cleared: ${txn.payee || "Unknown"}`,
|
|
490
|
+
reason: "Transaction exists in YNAB but not yet cleared",
|
|
491
|
+
estimated_impact: toMoneyValueFromDecimal(
|
|
492
|
+
0,
|
|
493
|
+
context.analysis.balance_info.current_cleared.currency,
|
|
494
|
+
),
|
|
495
|
+
account_id: context.account_id,
|
|
496
|
+
metadata: {
|
|
497
|
+
version: RECOMMENDATION_VERSION,
|
|
498
|
+
created_at: new Date().toISOString(),
|
|
499
|
+
},
|
|
500
|
+
parameters: {
|
|
501
|
+
transaction_id: txn.id,
|
|
502
|
+
cleared: "cleared",
|
|
503
|
+
},
|
|
504
|
+
};
|
|
494
505
|
}
|
|
495
506
|
|
|
496
507
|
/**
|
|
497
508
|
* Sort recommendations by priority and confidence
|
|
498
509
|
*/
|
|
499
510
|
function sortRecommendations(
|
|
500
|
-
|
|
511
|
+
recommendations: ActionableRecommendation[],
|
|
501
512
|
): ActionableRecommendation[] {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
513
|
+
return recommendations.sort((a, b) => {
|
|
514
|
+
// Sort by priority first
|
|
515
|
+
const priorityDiff =
|
|
516
|
+
PRIORITY_ORDER[b.priority] - PRIORITY_ORDER[a.priority];
|
|
517
|
+
if (priorityDiff !== 0) return priorityDiff;
|
|
518
|
+
|
|
519
|
+
// Then by confidence
|
|
520
|
+
return b.confidence - a.confidence;
|
|
521
|
+
});
|
|
510
522
|
}
|