@tpmjs/official-tax-deduction-scan 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2025 TPMJS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,66 @@
1
+ import * as ai from 'ai';
2
+
3
+ /**
4
+ * Tax Deduction Scan Tool for TPMJS
5
+ * Scans expense data for potential tax deductions by category
6
+ */
7
+ /**
8
+ * Expense record
9
+ */
10
+ interface Expense {
11
+ description: string;
12
+ amount: number;
13
+ category: string;
14
+ date?: string;
15
+ vendor?: string;
16
+ }
17
+ /**
18
+ * Entity type for tax treatment
19
+ */
20
+ type EntityType = 'sole-proprietor' | 'partnership' | 'llc' | 's-corp' | 'c-corp' | 'individual';
21
+ /**
22
+ * Deduction category with rules
23
+ */
24
+ interface DeductionCategory {
25
+ category: string;
26
+ totalAmount: number;
27
+ deductibleAmount: number;
28
+ deductionRate: number;
29
+ items: Array<{
30
+ description: string;
31
+ amount: number;
32
+ deductible: number;
33
+ }>;
34
+ notes: string[];
35
+ documentationRequired: string[];
36
+ }
37
+ /**
38
+ * Input interface for tax deduction scan
39
+ */
40
+ interface TaxDeductionScanInput {
41
+ expenses: Expense[];
42
+ entityType: EntityType;
43
+ taxYear?: number;
44
+ }
45
+ /**
46
+ * Output interface for tax deduction scan
47
+ */
48
+ interface TaxDeductionScanResult {
49
+ deductions: DeductionCategory[];
50
+ summary: {
51
+ totalExpenses: number;
52
+ totalDeductible: number;
53
+ totalNonDeductible: number;
54
+ deductionRate: number;
55
+ topDeductionCategory: string;
56
+ topDeductionAmount: number;
57
+ flaggedForReview: string[];
58
+ };
59
+ }
60
+ /**
61
+ * Tax Deduction Scan Tool
62
+ * Scans expenses and identifies potential tax deductions
63
+ */
64
+ declare const taxDeductionScanTool: ai.Tool<TaxDeductionScanInput, TaxDeductionScanResult>;
65
+
66
+ export { type TaxDeductionScanResult, taxDeductionScanTool as default, taxDeductionScanTool };
package/dist/index.js ADDED
@@ -0,0 +1,261 @@
1
+ import { tool, jsonSchema } from 'ai';
2
+
3
+ // src/index.ts
4
+ var DEDUCTION_RULES = {
5
+ "office-supplies": {
6
+ rate: 1,
7
+ notes: ["Fully deductible if used exclusively for business"],
8
+ documentation: ["Receipts", "Purchase records"]
9
+ },
10
+ "home-office": {
11
+ rate: 1,
12
+ notes: ["Must be used exclusively and regularly for business"],
13
+ documentation: ["Square footage calculation", "Utility bills", "Mortgage/rent statements"],
14
+ entitySpecific: {
15
+ individual: {
16
+ rate: 1,
17
+ notes: [
18
+ "Simplified option: $5 per square foot up to 300 sq ft",
19
+ "Regular method: Percentage of home expenses"
20
+ ]
21
+ }
22
+ }
23
+ },
24
+ travel: {
25
+ rate: 1,
26
+ notes: ["Must be ordinary and necessary for business"],
27
+ documentation: ["Travel receipts", "Business purpose documentation", "Itinerary"]
28
+ },
29
+ meals: {
30
+ rate: 0.5,
31
+ notes: ["Generally 50% deductible", "100% deductible for company events (all employees)"],
32
+ documentation: ["Receipts", "Business purpose", "Attendees list"]
33
+ },
34
+ entertainment: {
35
+ rate: 0,
36
+ notes: ["Entertainment expenses are generally NOT deductible (post-TCJA)"],
37
+ documentation: ["N/A - Not deductible"]
38
+ },
39
+ vehicle: {
40
+ rate: 1,
41
+ notes: [
42
+ "Standard mileage rate or actual expenses",
43
+ "2024 rate: $0.67/mile (business use)",
44
+ "Keep detailed mileage log"
45
+ ],
46
+ documentation: ["Mileage log", "Vehicle registration", "Fuel receipts if using actual method"]
47
+ },
48
+ "professional-development": {
49
+ rate: 1,
50
+ notes: ["Training, courses, and conferences related to current business"],
51
+ documentation: ["Course receipts", "Conference registration", "Business relevance"]
52
+ },
53
+ software: {
54
+ rate: 1,
55
+ notes: ["Business software subscriptions fully deductible"],
56
+ documentation: ["Subscription receipts", "Software licenses"]
57
+ },
58
+ advertising: {
59
+ rate: 1,
60
+ notes: ["Marketing and advertising expenses fully deductible"],
61
+ documentation: ["Ad receipts", "Marketing invoices", "Campaign records"]
62
+ },
63
+ "professional-fees": {
64
+ rate: 1,
65
+ notes: ["Legal, accounting, consulting fees for business"],
66
+ documentation: ["Professional service invoices", "Engagement letters"]
67
+ },
68
+ insurance: {
69
+ rate: 1,
70
+ notes: ["Business insurance premiums deductible"],
71
+ documentation: ["Insurance policies", "Premium statements"],
72
+ entitySpecific: {
73
+ "sole-proprietor": {
74
+ rate: 1,
75
+ notes: ["Health insurance may be deductible as self-employed health insurance"]
76
+ }
77
+ }
78
+ },
79
+ utilities: {
80
+ rate: 1,
81
+ notes: ["Business portion of utilities deductible"],
82
+ documentation: ["Utility bills", "Business use percentage calculation"]
83
+ },
84
+ rent: {
85
+ rate: 1,
86
+ notes: ["Business space rent fully deductible"],
87
+ documentation: ["Lease agreement", "Rent receipts"]
88
+ },
89
+ "phone-internet": {
90
+ rate: 1,
91
+ notes: ["Business portion deductible", "Personal use must be excluded"],
92
+ documentation: ["Phone/internet bills", "Business use percentage"]
93
+ },
94
+ depreciation: {
95
+ rate: 1,
96
+ notes: ["Equipment and property depreciation", "Section 179 may allow immediate expensing"],
97
+ documentation: ["Asset purchase records", "Depreciation schedule"]
98
+ },
99
+ "charitable-contributions": {
100
+ rate: 0,
101
+ notes: ["Personal charitable contributions - itemized deduction, not business expense"],
102
+ documentation: ["Donation receipts"],
103
+ entitySpecific: {
104
+ "c-corp": {
105
+ rate: 1,
106
+ notes: ["C-corps can deduct charitable contributions as business expense"]
107
+ }
108
+ }
109
+ },
110
+ other: {
111
+ rate: 0.5,
112
+ notes: ["Review with tax professional", "May be partially deductible"],
113
+ documentation: ["Receipts", "Business purpose documentation"]
114
+ }
115
+ };
116
+ var taxDeductionScanTool = tool({
117
+ description: "Scans expense data for potential tax deductions by category. Applies category-specific deduction rules and identifies documentation requirements.",
118
+ inputSchema: jsonSchema({
119
+ type: "object",
120
+ properties: {
121
+ expenses: {
122
+ type: "array",
123
+ description: "Expense records to scan",
124
+ items: {
125
+ type: "object",
126
+ properties: {
127
+ description: {
128
+ type: "string",
129
+ description: "Expense description"
130
+ },
131
+ amount: {
132
+ type: "number",
133
+ description: "Expense amount"
134
+ },
135
+ category: {
136
+ type: "string",
137
+ description: "Expense category (e.g., office-supplies, travel, meals, vehicle, software)"
138
+ },
139
+ date: {
140
+ type: "string",
141
+ description: "Expense date (ISO format)"
142
+ },
143
+ vendor: {
144
+ type: "string",
145
+ description: "Vendor name"
146
+ }
147
+ },
148
+ required: ["description", "amount", "category"]
149
+ }
150
+ },
151
+ entityType: {
152
+ type: "string",
153
+ enum: ["sole-proprietor", "partnership", "llc", "s-corp", "c-corp", "individual"],
154
+ description: "Business entity type for tax treatment"
155
+ },
156
+ taxYear: {
157
+ type: "number",
158
+ description: "Tax year (default: current year)"
159
+ }
160
+ },
161
+ required: ["expenses", "entityType"],
162
+ additionalProperties: false
163
+ }),
164
+ execute: async ({ expenses, entityType }) => {
165
+ if (!Array.isArray(expenses) || expenses.length === 0) {
166
+ throw new Error("Expenses must be a non-empty array");
167
+ }
168
+ const validEntityTypes = [
169
+ "sole-proprietor",
170
+ "partnership",
171
+ "llc",
172
+ "s-corp",
173
+ "c-corp",
174
+ "individual"
175
+ ];
176
+ if (!validEntityTypes.includes(entityType)) {
177
+ throw new Error(
178
+ `Invalid entity type: ${entityType}. Must be one of: ${validEntityTypes.join(", ")}`
179
+ );
180
+ }
181
+ const categoryMap = /* @__PURE__ */ new Map();
182
+ let totalExpenses = 0;
183
+ for (const expense of expenses) {
184
+ if (!expense.category || typeof expense.amount !== "number" || expense.amount < 0) {
185
+ throw new Error("Each expense must have a category and non-negative amount");
186
+ }
187
+ const normalizedCategory = expense.category.toLowerCase().trim();
188
+ if (!categoryMap.has(normalizedCategory)) {
189
+ categoryMap.set(normalizedCategory, []);
190
+ }
191
+ categoryMap.get(normalizedCategory).push(expense);
192
+ totalExpenses += expense.amount;
193
+ }
194
+ const deductions = [];
195
+ let totalDeductible = 0;
196
+ const flaggedForReview = [];
197
+ for (const [category, categoryExpenses] of categoryMap.entries()) {
198
+ const rules = DEDUCTION_RULES[category] || DEDUCTION_RULES["other"];
199
+ let deductionRate = rules.rate;
200
+ let notes = [...rules.notes];
201
+ if (rules.entitySpecific?.[entityType]) {
202
+ const entityRules = rules.entitySpecific[entityType];
203
+ deductionRate = entityRules.rate;
204
+ if (entityRules.notes) {
205
+ notes = [...entityRules.notes, ...notes];
206
+ }
207
+ }
208
+ const categoryTotal = categoryExpenses.reduce((sum, exp) => sum + exp.amount, 0);
209
+ const deductibleAmount = categoryTotal * deductionRate;
210
+ const items = categoryExpenses.map((exp) => ({
211
+ description: exp.description,
212
+ amount: exp.amount,
213
+ deductible: Math.round(exp.amount * deductionRate * 100) / 100
214
+ }));
215
+ if (deductionRate === 0 && categoryTotal > 0) {
216
+ flaggedForReview.push(
217
+ `${category}: $${categoryTotal.toFixed(2)} - Not deductible, review classification`
218
+ );
219
+ }
220
+ if (category === "meals" && categoryTotal > 1e4) {
221
+ flaggedForReview.push(
222
+ `${category}: High meal expenses - Ensure proper business documentation`
223
+ );
224
+ }
225
+ if (category === "other" && categoryTotal > 5e3) {
226
+ flaggedForReview.push(
227
+ `${category}: Significant uncategorized expenses - Review with tax professional`
228
+ );
229
+ }
230
+ deductions.push({
231
+ category,
232
+ totalAmount: Math.round(categoryTotal * 100) / 100,
233
+ deductibleAmount: Math.round(deductibleAmount * 100) / 100,
234
+ deductionRate,
235
+ items,
236
+ notes,
237
+ documentationRequired: rules.documentation
238
+ });
239
+ totalDeductible += deductibleAmount;
240
+ }
241
+ deductions.sort((a, b) => b.deductibleAmount - a.deductibleAmount);
242
+ const topDeduction = deductions[0];
243
+ const totalNonDeductible = totalExpenses - totalDeductible;
244
+ const overallDeductionRate = totalExpenses > 0 ? totalDeductible / totalExpenses * 100 : 0;
245
+ return {
246
+ deductions,
247
+ summary: {
248
+ totalExpenses: Math.round(totalExpenses * 100) / 100,
249
+ totalDeductible: Math.round(totalDeductible * 100) / 100,
250
+ totalNonDeductible: Math.round(totalNonDeductible * 100) / 100,
251
+ deductionRate: Math.round(overallDeductionRate * 100) / 100,
252
+ topDeductionCategory: topDeduction?.category || "N/A",
253
+ topDeductionAmount: topDeduction?.deductibleAmount || 0,
254
+ flaggedForReview
255
+ }
256
+ };
257
+ }
258
+ });
259
+ var index_default = taxDeductionScanTool;
260
+
261
+ export { index_default as default, taxDeductionScanTool };
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@tpmjs/official-tax-deduction-scan",
3
+ "version": "0.1.0",
4
+ "description": "Scans expense data for potential tax deductions by category",
5
+ "type": "module",
6
+ "keywords": [
7
+ "tpmjs",
8
+ "finance",
9
+ "tax",
10
+ "deductions",
11
+ "expenses"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "devDependencies": {
23
+ "tsup": "^8.3.5",
24
+ "typescript": "^5.9.3",
25
+ "@tpmjs/tsconfig": "0.0.0"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/anthropics/tpmjs.git",
33
+ "directory": "packages/tools/official/tax-deduction-scan"
34
+ },
35
+ "homepage": "https://tpmjs.com",
36
+ "license": "MIT",
37
+ "tpmjs": {
38
+ "category": "finance",
39
+ "frameworks": [
40
+ "vercel-ai"
41
+ ],
42
+ "tools": [
43
+ {
44
+ "name": "taxDeductionScanTool",
45
+ "description": "Scans expense data for potential tax deductions by category",
46
+ "parameters": [
47
+ {
48
+ "name": "expenses",
49
+ "type": "array",
50
+ "description": "Expense records to scan for deductions",
51
+ "required": true
52
+ },
53
+ {
54
+ "name": "entityType",
55
+ "type": "string",
56
+ "description": "Business entity type for tax treatment",
57
+ "required": true
58
+ },
59
+ {
60
+ "name": "taxYear",
61
+ "type": "number",
62
+ "description": "Tax year",
63
+ "required": false
64
+ }
65
+ ],
66
+ "returns": {
67
+ "type": "TaxDeductionScanResult",
68
+ "description": "Deduction analysis with documentation requirements and flags"
69
+ }
70
+ }
71
+ ]
72
+ },
73
+ "dependencies": {
74
+ "ai": "6.0.0-beta.124"
75
+ },
76
+ "scripts": {
77
+ "build": "tsup",
78
+ "dev": "tsup --watch",
79
+ "type-check": "tsc --noEmit",
80
+ "clean": "rm -rf dist .turbo"
81
+ }
82
+ }