create-bill.tool.ts•1.7 kB
import { createQuickbooksBill } from "../handlers/create-quickbooks-bill.handler.js";
import { ToolDefinition } from "../types/tool-definition.js";
import { z } from "zod";
const toolName = "create-bill";
const toolTitle = "Create-bill";
const toolDescription = "Create a bill in QuickBooks Online.";
const inputSchema = {
bill: z.object({
Line: z.array(z.object({
Amount: z.number(),
DetailType: z.string(),
Description: z.string(),
AccountRef: z.object({
value: z.string(),
name: z.string().optional(),
}),
})),
VendorRef: z.object({
value: z.string(),
name: z.string().optional(),
}),
DueDate: z.string(),
Balance: z.number(),
TotalAmt: z.number(),
}),
};
const outputSchema = {
success: z.boolean().describe("Whether the operation was successful"),
data: z.any().optional().describe("The result data"),
error: z.string().optional().describe("Error message if operation failed"),
};
const toolHandler = async (args: { [x: string]: any }) => {
const response = await createQuickbooksBill(args.bill);
if (response.isError) {
return {
content: [
{
type: "text" as const,
text: `Error creating bill: ${response.error}`,
},
],
};
}
const bill = response.result;
return {
content: [
{
type: "text" as const,
text: JSON.stringify(bill),
}
],
};
};
export const CreateBillTool: ToolDefinition<typeof inputSchema, typeof outputSchema> = {
name: toolName,
title: toolTitle,
description: toolDescription,
inputSchema: inputSchema,
outputSchema: outputSchema,
handler: toolHandler,
};