@opentabs-dev/opentabs-plugin-ynab 0.0.84 → 0.0.86
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/dist/adapter.iife.js +870 -523
- package/dist/adapter.iife.js.map +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -16
- package/dist/index.js.map +1 -1
- package/dist/tools/create-transaction.d.ts +2 -2
- package/dist/tools/create-transaction.d.ts.map +1 -1
- package/dist/tools/create-transaction.js +63 -22
- package/dist/tools/create-transaction.js.map +1 -1
- package/dist/tools/delete-transaction.d.ts.map +1 -1
- package/dist/tools/delete-transaction.js +22 -7
- package/dist/tools/delete-transaction.js.map +1 -1
- package/dist/tools/get-account.d.ts.map +1 -1
- package/dist/tools/get-account.js +3 -3
- package/dist/tools/get-account.js.map +1 -1
- package/dist/tools/get-month.d.ts +2 -1
- package/dist/tools/get-month.d.ts.map +1 -1
- package/dist/tools/get-month.js +10 -33
- package/dist/tools/get-month.js.map +1 -1
- package/dist/tools/get-plan.d.ts.map +1 -1
- package/dist/tools/get-plan.js +12 -5
- package/dist/tools/get-plan.js.map +1 -1
- package/dist/tools/get-transaction.d.ts +2 -2
- package/dist/tools/get-transaction.d.ts.map +1 -1
- package/dist/tools/get-transaction.js +5 -4
- package/dist/tools/get-transaction.js.map +1 -1
- package/dist/tools/list-accounts.d.ts.map +1 -1
- package/dist/tools/list-accounts.js +4 -4
- package/dist/tools/list-accounts.js.map +1 -1
- package/dist/tools/list-categories.d.ts.map +1 -1
- package/dist/tools/list-categories.js +9 -29
- package/dist/tools/list-categories.js.map +1 -1
- package/dist/tools/list-months.d.ts +1 -1
- package/dist/tools/list-months.d.ts.map +1 -1
- package/dist/tools/list-months.js +5 -14
- package/dist/tools/list-months.js.map +1 -1
- package/dist/tools/list-payees.d.ts.map +1 -1
- package/dist/tools/list-payees.js +3 -3
- package/dist/tools/list-payees.js.map +1 -1
- package/dist/tools/list-scheduled-transactions.d.ts.map +1 -1
- package/dist/tools/list-scheduled-transactions.js +7 -5
- package/dist/tools/list-scheduled-transactions.js.map +1 -1
- package/dist/tools/list-transactions.d.ts +4 -2
- package/dist/tools/list-transactions.d.ts.map +1 -1
- package/dist/tools/list-transactions.js +40 -8
- package/dist/tools/list-transactions.js.map +1 -1
- package/dist/tools/move-category-budget.d.ts +24 -0
- package/dist/tools/move-category-budget.d.ts.map +1 -0
- package/dist/tools/move-category-budget.js +105 -0
- package/dist/tools/move-category-budget.js.map +1 -0
- package/dist/tools/schemas.d.ts +105 -27
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +176 -27
- package/dist/tools/schemas.js.map +1 -1
- package/dist/tools/update-category-budget.d.ts.map +1 -1
- package/dist/tools/update-category-budget.js +55 -27
- package/dist/tools/update-category-budget.js.map +1 -1
- package/dist/tools/update-transaction.d.ts +3 -2
- package/dist/tools/update-transaction.d.ts.map +1 -1
- package/dist/tools/update-transaction.js +84 -31
- package/dist/tools/update-transaction.js.map +1 -1
- package/dist/tools.json +192 -43
- package/dist/ynab-api.d.ts +4 -1
- package/dist/ynab-api.d.ts.map +1 -1
- package/dist/ynab-api.js +47 -26
- package/dist/ynab-api.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { defineTool } from '@opentabs-dev/plugin-sdk';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import { categoryGroupSchema, categorySchema,
|
|
3
|
+
import { getPlanId, syncBudget } from '../ynab-api.js';
|
|
4
|
+
import { buildSubcategoryBudgetMap, buildSubcategoryCalcMap, categoryGroupSchema, categorySchema, currentMonthKey, mapCategoryForMonth, mapCategoryGroup, notTombstone, } from './schemas.js';
|
|
5
5
|
export const listCategories = defineTool({
|
|
6
6
|
name: 'list_categories',
|
|
7
7
|
displayName: 'List Categories',
|
|
8
|
-
description: 'List
|
|
8
|
+
description: 'List category groups and categories in the active YNAB plan. Returns budgeted amounts, activity, and available balances for the current month. Hidden and deleted categories are excluded by default — pass include_hidden=true to also see hidden categories (useful for editing budgets on hidden categories).',
|
|
9
9
|
summary: 'List budget categories with balances',
|
|
10
10
|
icon: 'tags',
|
|
11
11
|
group: 'Categories',
|
|
@@ -20,33 +20,13 @@ export const listCategories = defineTool({
|
|
|
20
20
|
const planId = getPlanId();
|
|
21
21
|
const result = await syncBudget(planId);
|
|
22
22
|
const entities = result.changed_entities;
|
|
23
|
-
const rawGroups = (entities?.be_master_categories ?? []).filter(
|
|
24
|
-
const rawCategories = (entities?.be_subcategories ?? []).filter(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const calcMap = new Map();
|
|
29
|
-
for (const calc of calcs) {
|
|
30
|
-
const entityId = calc.entities_monthly_subcategory_budget_id;
|
|
31
|
-
if (entityId) {
|
|
32
|
-
const parts = entityId.split('/');
|
|
33
|
-
const categoryId = parts.length >= 3 ? parts.slice(2).join('/') : entityId;
|
|
34
|
-
calcMap.set(categoryId, calc);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
23
|
+
const rawGroups = (entities?.be_master_categories ?? []).filter(notTombstone);
|
|
24
|
+
const rawCategories = (entities?.be_subcategories ?? []).filter(notTombstone);
|
|
25
|
+
const budgetMap = buildSubcategoryBudgetMap(entities?.be_monthly_subcategory_budgets ?? []);
|
|
26
|
+
const calcMap = buildSubcategoryCalcMap(entities?.be_monthly_subcategory_budget_calculations ?? []);
|
|
27
|
+
const currentMonth = currentMonthKey();
|
|
37
28
|
let groups = rawGroups.map(mapCategoryGroup);
|
|
38
|
-
let categories = rawCategories.map(c =>
|
|
39
|
-
const calc = calcMap.get(c.id ?? '');
|
|
40
|
-
return mapCategory({
|
|
41
|
-
...c,
|
|
42
|
-
budgeted: calc?.budgeted ?? c.budgeted,
|
|
43
|
-
activity: calc?.activity ?? c.activity,
|
|
44
|
-
balance: calc?.balance ?? c.balance,
|
|
45
|
-
goal_type: calc?.goal_type ?? c.goal_type,
|
|
46
|
-
goal_target: calc?.goal_target ?? c.goal_target,
|
|
47
|
-
goal_percentage_complete: calc?.goal_percentage_complete ?? c.goal_percentage_complete,
|
|
48
|
-
});
|
|
49
|
-
});
|
|
29
|
+
let categories = rawCategories.map(c => mapCategoryForMonth(c, budgetMap, calcMap, currentMonth));
|
|
50
30
|
if (!params.include_hidden) {
|
|
51
31
|
groups = groups.filter(g => !g.hidden);
|
|
52
32
|
categories = categories.filter(c => !c.hidden);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-categories.js","sourceRoot":"","sources":["../../src/tools/list-categories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"list-categories.js","sourceRoot":"","sources":["../../src/tools/list-categories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,GACb,MAAM,cAAc,CAAC;AAEtB,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;IACvC,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,iBAAiB;IAC9B,WAAW,EACT,kTAAkT;IACpT,OAAO,EAAE,sCAAsC;IAC/C,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,YAAY;IACnB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ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C,CAAC,CAAC,MAAM,CAAC,CAAC;YACvC,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IAChC,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -10,7 +10,7 @@ export declare const listMonths: import("@opentabs-dev/plugin-sdk").ToolDefiniti
|
|
|
10
10
|
budgeted_milliunits: z.ZodNumber;
|
|
11
11
|
activity_milliunits: z.ZodNumber;
|
|
12
12
|
to_be_budgeted_milliunits: z.ZodNumber;
|
|
13
|
-
age_of_money: z.ZodNumber
|
|
13
|
+
age_of_money: z.ZodNullable<z.ZodNumber>;
|
|
14
14
|
}, z.core.$strip>>;
|
|
15
15
|
}, z.core.$strip>>;
|
|
16
16
|
//# sourceMappingURL=list-months.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-months.d.ts","sourceRoot":"","sources":["../../src/tools/list-months.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"list-months.d.ts","sourceRoot":"","sources":["../../src/tools/list-months.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,UAAU;;;;;;;;;;;;;kBA2BrB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineTool } from '@opentabs-dev/plugin-sdk';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import { mapMonth, monthSchema } from './schemas.js';
|
|
3
|
+
import { getPlanId, syncBudget } from '../ynab-api.js';
|
|
4
|
+
import { buildMonthlyBudgetCalcMap, mapMonth, monthSchema, notTombstone } from './schemas.js';
|
|
5
5
|
export const listMonths = defineTool({
|
|
6
6
|
name: 'list_months',
|
|
7
7
|
displayName: 'List Months',
|
|
@@ -18,19 +18,10 @@ export const listMonths = defineTool({
|
|
|
18
18
|
const result = await syncBudget(planId);
|
|
19
19
|
const entities = result.changed_entities;
|
|
20
20
|
const rawMonths = entities?.be_monthly_budgets ?? [];
|
|
21
|
-
const
|
|
22
|
-
// Map calculation data by month (entities_monthly_budget_id format: mb/YYYY-MM-DD)
|
|
23
|
-
const calcMap = new Map();
|
|
24
|
-
for (const calc of rawCalcs) {
|
|
25
|
-
const budgetId = calc.entities_monthly_budget_id;
|
|
26
|
-
if (budgetId) {
|
|
27
|
-
const month = budgetId.replace('mb/', '');
|
|
28
|
-
calcMap.set(month, calc);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
21
|
+
const calcMap = buildMonthlyBudgetCalcMap(entities?.be_monthly_budget_calculations ?? []);
|
|
31
22
|
const months = rawMonths
|
|
32
|
-
.filter(
|
|
33
|
-
.map(m => mapMonth(m, calcMap.get(m.month ?? '')))
|
|
23
|
+
.filter(notTombstone)
|
|
24
|
+
.map(m => mapMonth(m, calcMap.get((m.month ?? '').substring(0, 7))))
|
|
34
25
|
.sort((a, b) => b.month.localeCompare(a.month));
|
|
35
26
|
return { months };
|
|
36
27
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-months.js","sourceRoot":"","sources":["../../src/tools/list-months.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"list-months.js","sourceRoot":"","sources":["../../src/tools/list-months.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,yBAA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AC;CACF,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-payees.d.ts","sourceRoot":"","sources":["../../src/tools/list-payees.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"list-payees.d.ts","sourceRoot":"","sources":["../../src/tools/list-payees.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,UAAU;;;;;;kBAqBrB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineTool } from '@opentabs-dev/plugin-sdk';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import { mapPayee, payeeSchema } from './schemas.js';
|
|
3
|
+
import { getPlanId, syncBudget } from '../ynab-api.js';
|
|
4
|
+
import { mapPayee, notTombstone, payeeSchema } from './schemas.js';
|
|
5
5
|
export const listPayees = defineTool({
|
|
6
6
|
name: 'list_payees',
|
|
7
7
|
displayName: 'List Payees',
|
|
@@ -17,7 +17,7 @@ export const listPayees = defineTool({
|
|
|
17
17
|
const planId = getPlanId();
|
|
18
18
|
const result = await syncBudget(planId);
|
|
19
19
|
const raw = result.changed_entities?.be_payees ?? [];
|
|
20
|
-
const payees = raw.filter(
|
|
20
|
+
const payees = raw.filter(notTombstone).map(mapPayee);
|
|
21
21
|
return { payees };
|
|
22
22
|
},
|
|
23
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-payees.js","sourceRoot":"","sources":["../../src/tools/list-payees.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"list-payees.js","sourceRoot":"","sources":["../../src/tools/list-payees.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEnE,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;IACnC,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,aAAa;IAC1B,WAAW,EACT,+HAA+H;IACjI,OAAO,EAAE,iBAAiB;IAC1B,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACnB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,gBAAgB,CAAC;KACxD,CAAC;IACF,MAAM,EAAE,KAAK,IAAI,EAAE;QACjB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,MAAM,UAAU,CAAiB,MAAM,CAAC,CAAC;QAExD,MAAM,GAAG,GAAG,MAAM,CAAC,gBAAgB,EAAE,SAAS,IAAI,EAAE,CAAC;QACrD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAEtD,OAAO,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-scheduled-transactions.d.ts","sourceRoot":"","sources":["../../src/tools/list-scheduled-transactions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"list-scheduled-transactions.d.ts","sourceRoot":"","sources":["../../src/tools/list-scheduled-transactions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;kBA2BpC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineTool } from '@opentabs-dev/plugin-sdk';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import { mapScheduledTransaction, scheduledTransactionSchema } from './schemas.js';
|
|
3
|
+
import { getPlanId, syncBudget } from '../ynab-api.js';
|
|
4
|
+
import { buildLookups, mapScheduledTransaction, notTombstone, scheduledTransactionSchema } from './schemas.js';
|
|
5
5
|
export const listScheduledTransactions = defineTool({
|
|
6
6
|
name: 'list_scheduled_transactions',
|
|
7
7
|
displayName: 'List Scheduled Transactions',
|
|
@@ -16,10 +16,12 @@ export const listScheduledTransactions = defineTool({
|
|
|
16
16
|
handle: async () => {
|
|
17
17
|
const planId = getPlanId();
|
|
18
18
|
const result = await syncBudget(planId);
|
|
19
|
-
const
|
|
19
|
+
const entities = result.changed_entities;
|
|
20
|
+
const raw = entities?.be_scheduled_transactions ?? [];
|
|
21
|
+
const lookups = buildLookups(entities ?? {});
|
|
20
22
|
const scheduledTransactions = raw
|
|
21
|
-
.filter(
|
|
22
|
-
.map(mapScheduledTransaction)
|
|
23
|
+
.filter(notTombstone)
|
|
24
|
+
.map(s => mapScheduledTransaction(s, lookups))
|
|
23
25
|
.sort((a, b) => a.date_next.localeCompare(b.date_next));
|
|
24
26
|
return { scheduled_transactions: scheduledTransactions };
|
|
25
27
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-scheduled-transactions.js","sourceRoot":"","sources":["../../src/tools/list-scheduled-transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB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AC,CAAC;aAC7C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QAE1D,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,CAAC;IAC3D,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -2,6 +2,8 @@ import { z } from 'zod';
|
|
|
2
2
|
export declare const listTransactions: import("@opentabs-dev/plugin-sdk").ToolDefinition<z.ZodObject<{
|
|
3
3
|
account_id: z.ZodOptional<z.ZodString>;
|
|
4
4
|
since_date: z.ZodOptional<z.ZodString>;
|
|
5
|
+
until_date: z.ZodOptional<z.ZodString>;
|
|
6
|
+
payee_search: z.ZodOptional<z.ZodString>;
|
|
5
7
|
}, z.core.$strip>, z.ZodObject<{
|
|
6
8
|
transactions: z.ZodArray<z.ZodObject<{
|
|
7
9
|
id: z.ZodString;
|
|
@@ -12,7 +14,6 @@ export declare const listTransactions: import("@opentabs-dev/plugin-sdk").ToolDe
|
|
|
12
14
|
cleared: z.ZodString;
|
|
13
15
|
approved: z.ZodBoolean;
|
|
14
16
|
flag_color: z.ZodString;
|
|
15
|
-
flag_name: z.ZodString;
|
|
16
17
|
account_id: z.ZodString;
|
|
17
18
|
account_name: z.ZodString;
|
|
18
19
|
payee_id: z.ZodString;
|
|
@@ -20,7 +21,8 @@ export declare const listTransactions: import("@opentabs-dev/plugin-sdk").ToolDe
|
|
|
20
21
|
category_id: z.ZodString;
|
|
21
22
|
category_name: z.ZodString;
|
|
22
23
|
transfer_account_id: z.ZodString;
|
|
23
|
-
|
|
24
|
+
imported_payee: z.ZodString;
|
|
25
|
+
original_imported_payee: z.ZodString;
|
|
24
26
|
deleted: z.ZodBoolean;
|
|
25
27
|
}, z.core.$strip>>;
|
|
26
28
|
}, z.core.$strip>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-transactions.d.ts","sourceRoot":"","sources":["../../src/tools/list-transactions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"list-transactions.d.ts","sourceRoot":"","sources":["../../src/tools/list-transactions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;kBA0E3B,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineTool } from '@opentabs-dev/plugin-sdk';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import { mapTransaction, transactionSchema } from './schemas.js';
|
|
3
|
+
import { getPlanId, syncBudget } from '../ynab-api.js';
|
|
4
|
+
import { buildLookups, mapTransaction, notTombstone, transactionSchema } from './schemas.js';
|
|
5
5
|
export const listTransactions = defineTool({
|
|
6
6
|
name: 'list_transactions',
|
|
7
7
|
displayName: 'List Transactions',
|
|
@@ -15,6 +15,14 @@ export const listTransactions = defineTool({
|
|
|
15
15
|
.string()
|
|
16
16
|
.optional()
|
|
17
17
|
.describe('Only return transactions on or after this date (YYYY-MM-DD). Omit for all transactions.'),
|
|
18
|
+
until_date: z
|
|
19
|
+
.string()
|
|
20
|
+
.optional()
|
|
21
|
+
.describe('Only return transactions on or before this date (YYYY-MM-DD). Combine with since_date for a date range.'),
|
|
22
|
+
payee_search: z
|
|
23
|
+
.string()
|
|
24
|
+
.optional()
|
|
25
|
+
.describe('Case-insensitive substring match against payee_name, imported_payee, and original_imported_payee. Useful for finding all transactions for a merchant without knowing the exact payee ID.'),
|
|
18
26
|
}),
|
|
19
27
|
output: z.object({
|
|
20
28
|
transactions: z.array(transactionSchema).describe('List of transactions'),
|
|
@@ -22,17 +30,41 @@ export const listTransactions = defineTool({
|
|
|
22
30
|
handle: async (params) => {
|
|
23
31
|
const planId = getPlanId();
|
|
24
32
|
const result = await syncBudget(planId);
|
|
25
|
-
const
|
|
26
|
-
|
|
33
|
+
const entities = result.changed_entities;
|
|
34
|
+
const raw = entities?.be_transactions ?? [];
|
|
35
|
+
const lookups = buildLookups(entities ?? {});
|
|
36
|
+
let filtered = raw.filter(notTombstone);
|
|
27
37
|
if (params.account_id) {
|
|
28
|
-
|
|
38
|
+
filtered = filtered.filter(t => t.entities_account_id === params.account_id);
|
|
29
39
|
}
|
|
30
40
|
if (params.since_date) {
|
|
31
41
|
const sinceDate = params.since_date;
|
|
32
|
-
|
|
42
|
+
filtered = filtered.filter(t => (t.date ?? '') >= sinceDate);
|
|
43
|
+
}
|
|
44
|
+
if (params.until_date) {
|
|
45
|
+
const untilDate = params.until_date;
|
|
46
|
+
filtered = filtered.filter(t => (t.date ?? '') <= untilDate);
|
|
47
|
+
}
|
|
48
|
+
if (params.payee_search) {
|
|
49
|
+
const needle = params.payee_search.toLowerCase();
|
|
50
|
+
// Resolve which payee IDs match the search up front so we only do the
|
|
51
|
+
// string compare once per payee instead of once per transaction.
|
|
52
|
+
const matchingPayeeIds = new Set();
|
|
53
|
+
for (const [id, name] of lookups.payees) {
|
|
54
|
+
if (name.toLowerCase().includes(needle))
|
|
55
|
+
matchingPayeeIds.add(id);
|
|
56
|
+
}
|
|
57
|
+
filtered = filtered.filter(t => {
|
|
58
|
+
if (t.entities_payee_id && matchingPayeeIds.has(t.entities_payee_id))
|
|
59
|
+
return true;
|
|
60
|
+
if (t.imported_payee?.toLowerCase().includes(needle))
|
|
61
|
+
return true;
|
|
62
|
+
if (t.original_imported_payee?.toLowerCase().includes(needle))
|
|
63
|
+
return true;
|
|
64
|
+
return false;
|
|
65
|
+
});
|
|
33
66
|
}
|
|
34
|
-
|
|
35
|
-
transactions.sort((a, b) => b.date.localeCompare(a.date));
|
|
67
|
+
const transactions = filtered.map(t => mapTransaction(t, lookups)).sort((a, b) => b.date.localeCompare(a.date));
|
|
36
68
|
return { transactions };
|
|
37
69
|
},
|
|
38
70
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-transactions.js","sourceRoot":"","sources":["../../src/tools/list-transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"list-transactions.js","sourceRoot":"","sources":["../../src/tools/list-transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAE7F,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC;IACzC,IAAI,EAAE,mBAAmB;IACzB,WAAW,EAAE,mBAAmB;IAChC,WAAW,EACT,wMAAwM;IAC1M,OAAO,EAAE,0BAA0B;IACnC,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,sDAAsD,CAAC;QAClG,UAAU,EAAE,CAAC;aACV,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CAAC,yFAAyF,CAAC;QACtG,UAAU,EAAE,CAAC;aACV,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CACP,yGAAyG,CAC1G;QACH,YAAY,EAAE,CAAC;aACZ,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CACP,0LAA0L,CAC3L;KACJ,CAAC;IACF,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,YAAY,EAAE,CAAC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|
4
|
+
amount: z.ZodNumber;
|
|
5
|
+
from_category_id: z.ZodOptional<z.ZodString>;
|
|
6
|
+
to_category_id: z.ZodOptional<z.ZodString>;
|
|
7
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
8
|
+
categories: z.ZodArray<z.ZodObject<{
|
|
9
|
+
id: z.ZodString;
|
|
10
|
+
category_group_id: z.ZodString;
|
|
11
|
+
name: z.ZodString;
|
|
12
|
+
hidden: z.ZodBoolean;
|
|
13
|
+
budgeted: z.ZodString;
|
|
14
|
+
activity: z.ZodString;
|
|
15
|
+
balance: z.ZodString;
|
|
16
|
+
budgeted_milliunits: z.ZodNumber;
|
|
17
|
+
activity_milliunits: z.ZodNumber;
|
|
18
|
+
balance_milliunits: z.ZodNumber;
|
|
19
|
+
goal_type: z.ZodString;
|
|
20
|
+
goal_target: z.ZodString;
|
|
21
|
+
goal_percentage_complete: z.ZodNumber;
|
|
22
|
+
}, z.core.$strip>>;
|
|
23
|
+
}, z.core.$strip>>;
|
|
24
|
+
//# sourceMappingURL=move-category-budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"move-category-budget.d.ts","sourceRoot":"","sources":["../../src/tools/move-category-budget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgBxB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;kBA2G7B,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { defineTool, ToolError } from '@opentabs-dev/plugin-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getPlanId, getUserId, syncBudget, syncWrite } from '../ynab-api.js';
|
|
4
|
+
import { buildSubcategoryBudgetMap, buildSubcategoryCalcMap, categorySchema, formatMonthlyBudgetId, formatSubcategoryBudgetId, MONEY_MOVEMENT_SOURCE, mapCategoryForMonth, notTombstone, toMilliunits, toMonthKey, } from './schemas.js';
|
|
5
|
+
export const moveCategoryBudget = defineTool({
|
|
6
|
+
name: 'move_category_budget',
|
|
7
|
+
displayName: 'Move Category Budget',
|
|
8
|
+
description: 'Move budgeted money between categories or to/from Ready to Assign for a specific month. Omit from_category_id to move money out of Ready to Assign; omit to_category_id to move money back to Ready to Assign. Both null is invalid.',
|
|
9
|
+
summary: 'Move money between budget categories',
|
|
10
|
+
icon: 'arrow-left-right',
|
|
11
|
+
group: 'Categories',
|
|
12
|
+
input: z
|
|
13
|
+
.object({
|
|
14
|
+
month: z
|
|
15
|
+
.string()
|
|
16
|
+
.regex(/^\d{4}-\d{2}(-\d{2})?$/, 'Month must be YYYY-MM or YYYY-MM-DD')
|
|
17
|
+
.describe('Month in YYYY-MM format (e.g. 2026-03)'),
|
|
18
|
+
amount: z.number().positive().describe('Amount to move in currency units (e.g. 50 for $50)'),
|
|
19
|
+
from_category_id: z.string().optional().describe('Source category ID. Omit to move from Ready to Assign.'),
|
|
20
|
+
to_category_id: z.string().optional().describe('Destination category ID. Omit to move to Ready to Assign.'),
|
|
21
|
+
})
|
|
22
|
+
.refine(p => p.from_category_id || p.to_category_id, {
|
|
23
|
+
message: 'At least one of from_category_id or to_category_id must be provided',
|
|
24
|
+
})
|
|
25
|
+
.refine(p => !p.from_category_id || !p.to_category_id || p.from_category_id !== p.to_category_id, {
|
|
26
|
+
message: 'from_category_id and to_category_id must differ',
|
|
27
|
+
}),
|
|
28
|
+
output: z.object({
|
|
29
|
+
categories: z
|
|
30
|
+
.array(categorySchema)
|
|
31
|
+
.describe('Updated categories (1 if RTA is involved, 2 for category-to-category)'),
|
|
32
|
+
}),
|
|
33
|
+
handle: async (params) => {
|
|
34
|
+
const planId = getPlanId();
|
|
35
|
+
const userId = getUserId();
|
|
36
|
+
const milliunits = toMilliunits(params.amount);
|
|
37
|
+
const monthKey = toMonthKey(params.month);
|
|
38
|
+
const monthlyBudgetId = formatMonthlyBudgetId(monthKey, planId);
|
|
39
|
+
const budget = await syncBudget(planId);
|
|
40
|
+
const serverKnowledge = budget.current_server_knowledge ?? 0;
|
|
41
|
+
const subcategories = budget.changed_entities?.be_subcategories ?? [];
|
|
42
|
+
const existingBudgets = budget.changed_entities?.be_monthly_subcategory_budgets ?? [];
|
|
43
|
+
const findCategory = (id) => {
|
|
44
|
+
const c = subcategories.find(s => s.id === id && notTombstone(s));
|
|
45
|
+
if (!c?.id)
|
|
46
|
+
throw ToolError.notFound(`Category not found: ${id}`);
|
|
47
|
+
return { ...c, id: c.id };
|
|
48
|
+
};
|
|
49
|
+
const fromCategory = params.from_category_id ? findCategory(params.from_category_id) : null;
|
|
50
|
+
const toCategory = params.to_category_id ? findCategory(params.to_category_id) : null;
|
|
51
|
+
const fromBudgetId = fromCategory ? formatSubcategoryBudgetId(monthKey, fromCategory.id) : null;
|
|
52
|
+
const toBudgetId = toCategory ? formatSubcategoryBudgetId(monthKey, toCategory.id) : null;
|
|
53
|
+
const buildEntry = (categoryId, budgetId, signedDelta) => {
|
|
54
|
+
const current = existingBudgets.find(b => b.id === budgetId && notTombstone(b))?.budgeted ?? 0;
|
|
55
|
+
return {
|
|
56
|
+
id: budgetId,
|
|
57
|
+
is_tombstone: false,
|
|
58
|
+
entities_monthly_budget_id: monthlyBudgetId,
|
|
59
|
+
entities_subcategory_id: categoryId,
|
|
60
|
+
budgeted: current + signedDelta,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const budgetEntries = [];
|
|
64
|
+
if (fromCategory && fromBudgetId)
|
|
65
|
+
budgetEntries.push(buildEntry(fromCategory.id, fromBudgetId, -milliunits));
|
|
66
|
+
if (toCategory && toBudgetId)
|
|
67
|
+
budgetEntries.push(buildEntry(toCategory.id, toBudgetId, milliunits));
|
|
68
|
+
const source = fromCategory && toCategory ? MONEY_MOVEMENT_SOURCE.MOVEMENT : MONEY_MOVEMENT_SOURCE.ASSIGN;
|
|
69
|
+
const result = await syncWrite(planId, {
|
|
70
|
+
be_monthly_subcategory_budgets: budgetEntries,
|
|
71
|
+
be_money_movements: [
|
|
72
|
+
{
|
|
73
|
+
id: crypto.randomUUID(),
|
|
74
|
+
is_tombstone: false,
|
|
75
|
+
from_entities_monthly_subcategory_budget_id: fromBudgetId,
|
|
76
|
+
to_entities_monthly_subcategory_budget_id: toBudgetId,
|
|
77
|
+
entities_money_movement_group_id: null,
|
|
78
|
+
amount: milliunits,
|
|
79
|
+
performed_by_user_id: userId,
|
|
80
|
+
note: null,
|
|
81
|
+
source,
|
|
82
|
+
move_started_at: new Date().toISOString(),
|
|
83
|
+
move_accepted_at: null,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
}, serverKnowledge);
|
|
87
|
+
const calcMap = buildSubcategoryCalcMap(result.changed_entities?.be_monthly_subcategory_budget_calculations ?? []);
|
|
88
|
+
// Prefer the server's echoed values — if a concurrent update from another
|
|
89
|
+
// client merged in, that change shows up here. Fall back to our local
|
|
90
|
+
// entries for any that the server didn't echo.
|
|
91
|
+
const budgetMap = buildSubcategoryBudgetMap(result.changed_entities?.be_monthly_subcategory_budgets ?? []);
|
|
92
|
+
for (const e of budgetEntries) {
|
|
93
|
+
const key = `${monthKey}/${e.entities_subcategory_id}`;
|
|
94
|
+
if (!budgetMap.has(key))
|
|
95
|
+
budgetMap.set(key, e);
|
|
96
|
+
}
|
|
97
|
+
const categories = [];
|
|
98
|
+
if (fromCategory)
|
|
99
|
+
categories.push(mapCategoryForMonth(fromCategory, budgetMap, calcMap, monthKey));
|
|
100
|
+
if (toCategory)
|
|
101
|
+
categories.push(mapCategoryForMonth(toCategory, budgetMap, calcMap, monthKey));
|
|
102
|
+
return { categories };
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=move-category-budget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"move-category-budget.js","sourceRoot":"","sources":["../../src/tools/move-category-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAA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