create-quote.tool.ts•2.06 kB
import { z } from "zod";
import { createXeroQuote } from "../../handlers/create-xero-quote.handler.js";
import { DeepLinkType, getDeepLink } from "../../helpers/get-deeplink.js";
import { CreateXeroTool } from "../../helpers/create-xero-tool.js";
const lineItemSchema = z.object({
description: z.string(),
quantity: z.number(),
unitAmount: z.number(),
accountCode: z.string(),
taxType: z.string(),
});
const CreateQuoteTool = CreateXeroTool(
"create-quote",
"Create a quote in Xero.\
When a quote is created, a deep link to the quote in Xero is returned. \
This deep link can be used to view the quote in Xero directly. \
This link should be displayed to the user.",
{
contactId: z.string(),
lineItems: z.array(lineItemSchema),
reference: z.string().optional(),
quoteNumber: z.string().optional(),
terms: z.string().optional(),
title: z.string().optional(),
summary: z.string().optional(),
},
async ({
contactId,
lineItems,
reference,
quoteNumber,
terms,
title,
summary,
}) => {
const result = await createXeroQuote(
contactId,
lineItems,
reference,
quoteNumber,
terms,
title,
summary,
);
if (result.isError) {
return {
content: [
{
type: "text" as const,
text: `Error creating quote: ${result.error}`,
},
],
};
}
const quote = result.result;
const deepLink = quote.quoteID
? await getDeepLink(DeepLinkType.QUOTE, quote.quoteID)
: null;
return {
content: [
{
type: "text" as const,
text: [
"Quote created successfully:",
`ID: ${quote?.quoteID}`,
`Contact: ${quote?.contact?.name}`,
`Total: ${quote?.total}`,
`Status: ${quote?.status}`,
deepLink ? `Link to view: ${deepLink}` : null,
]
.filter(Boolean)
.join("\n"),
},
],
};
},
);
export default CreateQuoteTool;