|
| 1 | +import { ErrorExtractorId } from '@/tools/error-extractors' |
| 2 | +import { QUICKBOOKS_MAX_RESPONSE_BYTES } from '@/tools/quickbooks/client' |
| 3 | +import type { |
| 4 | + QuickBooksRunFinancialReportParams, |
| 5 | + QuickBooksRunFinancialReportResponse, |
| 6 | +} from '@/tools/quickbooks/types' |
| 7 | +import { |
| 8 | + QUICKBOOKS_REPORT_COLUMNS_PROPERTIES, |
| 9 | + QUICKBOOKS_REPORT_HEADER_PROPERTIES, |
| 10 | + QUICKBOOKS_REPORT_ROWS_PROPERTIES, |
| 11 | +} from '@/tools/quickbooks/types' |
| 12 | +import { |
| 13 | + buildQuickBooksReportUrl, |
| 14 | + getQuickBooksToolHeaders, |
| 15 | + transformQuickBooksReportResponse, |
| 16 | +} from '@/tools/quickbooks/utils' |
| 17 | +import type { ToolConfig } from '@/tools/types' |
| 18 | + |
| 19 | +export const quickbooksRunFinancialReportTool: ToolConfig< |
| 20 | + QuickBooksRunFinancialReportParams, |
| 21 | + QuickBooksRunFinancialReportResponse |
| 22 | +> = { |
| 23 | + id: 'quickbooks_run_financial_report', |
| 24 | + name: 'QuickBooks Run Financial Report', |
| 25 | + description: 'Run a fixed QuickBooks financial report with verified accountant-focused filters', |
| 26 | + version: '1.0.0', |
| 27 | + params: { |
| 28 | + accessToken: { |
| 29 | + type: 'string', |
| 30 | + required: true, |
| 31 | + visibility: 'hidden', |
| 32 | + description: 'QuickBooks OAuth access token', |
| 33 | + }, |
| 34 | + realmId: { |
| 35 | + type: 'string', |
| 36 | + required: true, |
| 37 | + visibility: 'hidden', |
| 38 | + description: 'QuickBooks company ID derived from the connected credential', |
| 39 | + }, |
| 40 | + reportType: { |
| 41 | + type: 'string', |
| 42 | + required: true, |
| 43 | + visibility: 'user-or-llm', |
| 44 | + description: 'Fixed QuickBooks financial report to run', |
| 45 | + }, |
| 46 | + startDate: { |
| 47 | + type: 'string', |
| 48 | + required: false, |
| 49 | + visibility: 'user-or-llm', |
| 50 | + description: |
| 51 | + 'Report start date in YYYY-MM-DD format; Intuit recommends periods of six months or less for performance', |
| 52 | + }, |
| 53 | + endDate: { |
| 54 | + type: 'string', |
| 55 | + required: false, |
| 56 | + visibility: 'user-or-llm', |
| 57 | + description: 'Report end or as-of date in YYYY-MM-DD format', |
| 58 | + }, |
| 59 | + accountingMethod: { |
| 60 | + type: 'string', |
| 61 | + required: false, |
| 62 | + visibility: 'user-or-llm', |
| 63 | + description: 'Use the QuickBooks default, cash basis, or accrual basis', |
| 64 | + }, |
| 65 | + summarizeBy: { |
| 66 | + type: 'string', |
| 67 | + required: false, |
| 68 | + visibility: 'user-or-llm', |
| 69 | + description: 'Time period or business dimension used to summarize report columns', |
| 70 | + }, |
| 71 | + customerId: { |
| 72 | + type: 'string', |
| 73 | + required: false, |
| 74 | + visibility: 'user-or-llm', |
| 75 | + description: 'Single QuickBooks customer ID filter', |
| 76 | + }, |
| 77 | + vendorId: { |
| 78 | + type: 'string', |
| 79 | + required: false, |
| 80 | + visibility: 'user-or-llm', |
| 81 | + description: 'Single QuickBooks vendor ID filter', |
| 82 | + }, |
| 83 | + accountId: { |
| 84 | + type: 'string', |
| 85 | + required: false, |
| 86 | + visibility: 'user-or-llm', |
| 87 | + description: 'Single QuickBooks account ID filter', |
| 88 | + }, |
| 89 | + itemId: { |
| 90 | + type: 'string', |
| 91 | + required: false, |
| 92 | + visibility: 'user-or-llm', |
| 93 | + description: 'Single QuickBooks item ID filter', |
| 94 | + }, |
| 95 | + classId: { |
| 96 | + type: 'string', |
| 97 | + required: false, |
| 98 | + visibility: 'user-or-llm', |
| 99 | + description: 'Single QuickBooks class ID filter', |
| 100 | + }, |
| 101 | + departmentId: { |
| 102 | + type: 'string', |
| 103 | + required: false, |
| 104 | + visibility: 'user-or-llm', |
| 105 | + description: 'Single QuickBooks department ID filter', |
| 106 | + }, |
| 107 | + agingMethod: { |
| 108 | + type: 'string', |
| 109 | + required: false, |
| 110 | + visibility: 'user-or-llm', |
| 111 | + description: 'Age open balances from the report date or current date', |
| 112 | + }, |
| 113 | + agingDays: { |
| 114 | + type: 'number', |
| 115 | + required: false, |
| 116 | + visibility: 'user-or-llm', |
| 117 | + description: 'Positive number of days in each aging period', |
| 118 | + }, |
| 119 | + }, |
| 120 | + oauth: { |
| 121 | + required: true, |
| 122 | + provider: 'quickbooks', |
| 123 | + requiredScopes: ['com.intuit.quickbooks.accounting'], |
| 124 | + }, |
| 125 | + errorExtractor: ErrorExtractorId.QUICKBOOKS_FAULT, |
| 126 | + request: { |
| 127 | + url: (params) => buildQuickBooksReportUrl(params).toString(), |
| 128 | + method: 'GET', |
| 129 | + headers: (params) => getQuickBooksToolHeaders(params.accessToken), |
| 130 | + retry: { enabled: false }, |
| 131 | + maxResponseBytes: QUICKBOOKS_MAX_RESPONSE_BYTES, |
| 132 | + }, |
| 133 | + transformResponse: async (response, params) => { |
| 134 | + if (!params) throw new Error('QuickBooks report parameters are required') |
| 135 | + return transformQuickBooksReportResponse(response, params.reportType) |
| 136 | + }, |
| 137 | + outputs: { |
| 138 | + reportType: { |
| 139 | + type: 'string', |
| 140 | + description: 'Financial report type that was run', |
| 141 | + }, |
| 142 | + header: { |
| 143 | + type: 'json', |
| 144 | + description: |
| 145 | + 'Native QuickBooks report header with name, periods, basis, currency, summarization, filters, and options', |
| 146 | + properties: QUICKBOOKS_REPORT_HEADER_PROPERTIES, |
| 147 | + }, |
| 148 | + columns: { |
| 149 | + type: 'json', |
| 150 | + description: 'Native QuickBooks report column definitions', |
| 151 | + properties: QUICKBOOKS_REPORT_COLUMNS_PROPERTIES, |
| 152 | + }, |
| 153 | + rows: { |
| 154 | + type: 'json', |
| 155 | + description: 'Native hierarchical QuickBooks report rows and section summaries', |
| 156 | + properties: QUICKBOOKS_REPORT_ROWS_PROPERTIES, |
| 157 | + }, |
| 158 | + time: { |
| 159 | + type: 'string', |
| 160 | + description: 'QuickBooks response timestamp', |
| 161 | + optional: true, |
| 162 | + nullable: true, |
| 163 | + }, |
| 164 | + }, |
| 165 | +} |
0 commit comments