Skip to content

Commit 28b40bd

Browse files
committed
fix(quickbooks): wand prompt requires itemId, extract coerceJsonArray helper
1 parent fbb16fe commit 28b40bd

4 files changed

Lines changed: 24 additions & 25 deletions

File tree

apps/sim/blocks/blocks/quickbooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export const QuickBooksBlock: BlockConfig<QuickBooksResponse> = {
189189
wandConfig: {
190190
enabled: true,
191191
prompt:
192-
'Generate a JSON array of QuickBooks invoice line items. Each entry must have a numeric `amount` and may include `description`, `quantity`, `itemId`, and `itemName`. Return ONLY the JSON array.',
192+
'Generate a JSON array of QuickBooks invoice line items. Each entry must have a numeric `amount` and a string `itemId` (the QuickBooks Item ID); may include `description`, `quantity`, and `itemName`. Return ONLY the JSON array.',
193193
generationType: 'json-object',
194194
},
195195
},

apps/sim/tools/quickbooks/create_bill.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,13 @@ import type {
55
QuickBooksCreateBillParams,
66
} from '@/tools/quickbooks/types'
77
import { BILL_OUTPUT } from '@/tools/quickbooks/types'
8-
import { buildCompanyUrl, quickbooksAuthHeaders } from '@/tools/quickbooks/utils'
8+
import { buildCompanyUrl, coerceJsonArray, quickbooksAuthHeaders } from '@/tools/quickbooks/utils'
99
import type { ToolConfig } from '@/tools/types'
1010

1111
const logger = createLogger('QuickBooksCreateBill')
1212

13-
function coerceLines(input: QuickBooksCreateBillParams['lines']): QuickBooksBillLine[] {
14-
if (Array.isArray(input)) return input
15-
if (typeof input !== 'string') {
16-
throw new Error('Bill lines must be a JSON array')
17-
}
18-
const parsed = JSON.parse(input)
19-
if (!Array.isArray(parsed)) {
20-
throw new Error('Bill lines must be a JSON array')
21-
}
22-
return parsed as QuickBooksBillLine[]
23-
}
13+
const coerceLines = (input: QuickBooksCreateBillParams['lines']): QuickBooksBillLine[] =>
14+
coerceJsonArray<QuickBooksBillLine>(input, 'Bill lines')
2415

2516
export const quickbooksCreateBillTool: ToolConfig<
2617
QuickBooksCreateBillParams,

apps/sim/tools/quickbooks/create_invoice.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,13 @@ import type {
55
QuickBooksLineItem,
66
} from '@/tools/quickbooks/types'
77
import { INVOICE_OUTPUT } from '@/tools/quickbooks/types'
8-
import { buildCompanyUrl, quickbooksAuthHeaders } from '@/tools/quickbooks/utils'
8+
import { buildCompanyUrl, coerceJsonArray, quickbooksAuthHeaders } from '@/tools/quickbooks/utils'
99
import type { ToolConfig } from '@/tools/types'
1010

1111
const logger = createLogger('QuickBooksCreateInvoice')
1212

13-
function coerceLines(input: QuickBooksCreateInvoiceParams['lines']): QuickBooksLineItem[] {
14-
if (Array.isArray(input)) return input
15-
if (typeof input !== 'string') {
16-
throw new Error('Invoice lines must be a JSON array')
17-
}
18-
const parsed = JSON.parse(input)
19-
if (!Array.isArray(parsed)) {
20-
throw new Error('Invoice lines must be a JSON array')
21-
}
22-
return parsed as QuickBooksLineItem[]
23-
}
13+
const coerceLines = (input: QuickBooksCreateInvoiceParams['lines']): QuickBooksLineItem[] =>
14+
coerceJsonArray<QuickBooksLineItem>(input, 'Invoice lines')
2415

2516
export const quickbooksCreateInvoiceTool: ToolConfig<
2617
QuickBooksCreateInvoiceParams,

apps/sim/tools/quickbooks/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ export function sanitizeWhereClause(where: string | undefined): string | undefin
4141
return trimmed
4242
}
4343

44+
/**
45+
* Coerce a `lines` parameter (already an array, or a JSON-encoded string from
46+
* an LLM/short-input) into a typed array. Throws with a contextual label when
47+
* the value is missing or not an array.
48+
*/
49+
export function coerceJsonArray<T>(input: unknown, label: string): T[] {
50+
if (Array.isArray(input)) return input as T[]
51+
if (typeof input !== 'string') {
52+
throw new Error(`${label} must be a JSON array`)
53+
}
54+
const parsed = JSON.parse(input)
55+
if (!Array.isArray(parsed)) {
56+
throw new Error(`${label} must be a JSON array`)
57+
}
58+
return parsed as T[]
59+
}
60+
4461
export function quickbooksAuthHeaders(accessToken: string | undefined): Record<string, string> {
4562
if (!accessToken) {
4663
throw new Error('Missing QuickBooks access token')

0 commit comments

Comments
 (0)