From eb48bcde537e9fc9fc957ff09093bada086759ae Mon Sep 17 00:00:00 2001 From: Anthony Nguyen Date: Fri, 20 Jun 2025 14:17:57 -0500 Subject: [PATCH] Add agentic tools for Usage Based Billing --- modelcontextprotocol/src/index.ts | 27 ++ typescript/package.json | 4 +- typescript/src/shared/api.ts | 76 +++- typescript/src/shared/client.ts | 2 +- typescript/src/shared/functions.ts | 618 +++++++++++++++++++++++++++- typescript/src/shared/parameters.ts | 211 ++++++++++ typescript/src/shared/prompts.ts | 267 ++++++++++++ typescript/src/shared/tools.ts | 315 ++++++++++++++ 8 files changed, 1516 insertions(+), 4 deletions(-) diff --git a/modelcontextprotocol/src/index.ts b/modelcontextprotocol/src/index.ts index 4e9f674..86dc74a 100644 --- a/modelcontextprotocol/src/index.ts +++ b/modelcontextprotocol/src/index.ts @@ -1,6 +1,8 @@ #!/usr/bin/env node import {PayPalAgentToolkit} from '@paypal/agent-toolkit/mcp'; +// If you are developing mcp tools locally, you can update this import to point to your local mcp changes +// import {PayPalAgentToolkit} from '../../typescript/mcp'; import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; import {green, red, yellow} from 'colors'; @@ -50,6 +52,31 @@ const ACCEPTED_TOOLS = [ 'transactions.list', 'payments.createRefund', 'payments.getRefunds', + // UBB tools + 'ubbMetrics.list', + 'ubbMetrics.create', + 'ubbMetrics.get', + 'ubbMetrics.update', + 'ubbMetrics.delete', + 'ubbPlans.list', + 'ubbPlans.create', + 'ubbPlans.get', + 'ubbPlans.update', + 'ubbCustomers.list', + 'ubbCustomers.create', + 'ubbCustomers.get', + 'ubbCustomers.update', + 'ubbCustomers.delete', + 'ubbCustomerUsage.getCurrent', + 'ubbCustomerUsage.getPast', + 'ubbSubscriptions.list', + 'ubbSubscriptions.create', + 'ubbSubscriptions.get', + 'ubbSubscriptions.update', + 'ubbSubscriptions.cancel', + 'ubbEvents.list', + 'ubbEvents.create', + 'ubbEvents.createBatch', ]; export function parseArgs(args: string[]): Options { diff --git a/typescript/package.json b/typescript/package.json index 7b1ba95..7f32da0 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -6,7 +6,8 @@ "clean": "rm -rf dist ai-sdk mcp", "test": "echo \"Error: no test specified\" && exit 1", "build": "npm i && tsup", - "build:debug": "TSUP_DEBUG=true npm run build" + "build:debug": "TSUP_DEBUG=true npm run build", + "dev": "npm run build && node ./mcp/index.js" }, "exports": { "./ai-sdk": { @@ -40,6 +41,7 @@ "dependencies": { "@dotenvx/dotenvx": "^1.32.0", "@modelcontextprotocol/sdk": "^1.6.1", + "@paypal/agent-toolkit": "^1.3.5", "@paypal/paypal-server-sdk": "^1.0.0", "ai": "^4.0.23", "axios": "^1.8.4", diff --git a/typescript/src/shared/api.ts b/typescript/src/shared/api.ts index 54f834b..df84887 100644 --- a/typescript/src/shared/api.ts +++ b/typescript/src/shared/api.ts @@ -26,7 +26,32 @@ import { updatePlan, createRefund, getRefund, - updateSubscription + updateSubscription, + // UBB function imports + getUBBMetrics, + createUBBMetric, + getUBBMetricById, + updateUBBMetric, + deleteUBBMetric, + getUBBPlans, + createUBBPlan, + getUBBPlanById, + updateUBBPlan, + getUBBCustomers, + createUBBCustomer, + getUBBCustomerById, + updateUBBCustomer, + deleteUBBCustomer, + getUBBCustomerCurrentUsage, + getUBBCustomerPastUsage, + getUBBSubscriptions, + createUBBSubscription, + getUBBSubscriptionById, + updateUBBSubscription, + cancelUBBSubscription, + getUBBEvents, + createUBBEvent, + createUBBEventsBatch } from './functions'; import type { Context } from './configuration'; @@ -132,6 +157,55 @@ class PayPalAPI { return createRefund(this.paypalClient, this.context, arg); case 'get_refund': return getRefund(this.paypalClient, this.context, arg); + // UBB method cases + case 'get_ubb_metrics': + return getUBBMetrics(this.paypalClient, this.context, arg); + case 'create_ubb_metric': + return createUBBMetric(this.paypalClient, this.context, arg); + case 'get_ubb_metric_by_id': + return getUBBMetricById(this.paypalClient, this.context, arg); + case 'update_ubb_metric': + return updateUBBMetric(this.paypalClient, this.context, arg); + case 'delete_ubb_metric': + return deleteUBBMetric(this.paypalClient, this.context, arg); + case 'get_ubb_plans': + return getUBBPlans(this.paypalClient, this.context, arg); + case 'create_ubb_plan': + return createUBBPlan(this.paypalClient, this.context, arg); + case 'get_ubb_plan_by_id': + return getUBBPlanById(this.paypalClient, this.context, arg); + case 'update_ubb_plan': + return updateUBBPlan(this.paypalClient, this.context, arg); + case 'get_ubb_customers': + return getUBBCustomers(this.paypalClient, this.context, arg); + case 'create_ubb_customer': + return createUBBCustomer(this.paypalClient, this.context, arg); + case 'get_ubb_customer_by_id': + return getUBBCustomerById(this.paypalClient, this.context, arg); + case 'update_ubb_customer': + return updateUBBCustomer(this.paypalClient, this.context, arg); + case 'delete_ubb_customer': + return deleteUBBCustomer(this.paypalClient, this.context, arg); + case 'get_ubb_customer_current_usage': + return getUBBCustomerCurrentUsage(this.paypalClient, this.context, arg); + case 'get_ubb_customer_past_usage': + return getUBBCustomerPastUsage(this.paypalClient, this.context, arg); + case 'get_ubb_subscriptions': + return getUBBSubscriptions(this.paypalClient, this.context, arg); + case 'create_ubb_subscription': + return createUBBSubscription(this.paypalClient, this.context, arg); + case 'get_ubb_subscription_by_id': + return getUBBSubscriptionById(this.paypalClient, this.context, arg); + case 'update_ubb_subscription': + return updateUBBSubscription(this.paypalClient, this.context, arg); + case 'cancel_ubb_subscription': + return cancelUBBSubscription(this.paypalClient, this.context, arg); + case 'get_ubb_events': + return getUBBEvents(this.paypalClient, this.context, arg); + case 'create_ubb_event': + return createUBBEvent(this.paypalClient, this.context, arg); + case 'create_ubb_events_batch': + return createUBBEventsBatch(this.paypalClient, this.context, arg); default: throw new Error(`Invalid method: ${method}`); } diff --git a/typescript/src/shared/client.ts b/typescript/src/shared/client.ts index 98f21ee..40c04ec 100644 --- a/typescript/src/shared/client.ts +++ b/typescript/src/shared/client.ts @@ -47,7 +47,7 @@ class PayPalClient { } this._baseUrl = this._isSandbox - ? 'https://api.sandbox.paypal.com' + ? 'https://api-m.sandbox.paypal.com' : 'https://api.paypal.com'; logger(`[PayPal Setttings] Environment: ${this._isSandbox ? "Sandbox" : "Live"}`); diff --git a/typescript/src/shared/functions.ts b/typescript/src/shared/functions.ts index 8ab9b58..207016a 100644 --- a/typescript/src/shared/functions.ts +++ b/typescript/src/shared/functions.ts @@ -29,7 +29,31 @@ import { getRefundParameters, createRefundParameters, updateSubscriptionParameters, - updatePlanParameters + updatePlanParameters, + getUBBMetricsParameters, + createUBBMetricParameters, + getUBBMetricByIdParameters, + updateUBBMetricParameters, + deleteUBBMetricParameters, + getUBBPlansParameters, + createUBBPlanParameters, + getUBBPlanByIdParameters, + updateUBBPlanParameters, + getUBBCustomersParameters, + createUBBCustomerParameters, + getUBBCustomerByIdParameters, + updateUBBCustomerParameters, + deleteUBBCustomerParameters, + getUBBCustomerCurrentUsageParameters, + getUBBCustomerPastUsageParameters, + getUBBSubscriptionsParameters, + createUBBSubscriptionParameters, + getUBBSubscriptionByIdParameters, + updateUBBSubscriptionParameters, + cancelUBBSubscriptionParameters, + getUBBEventsParameters, + createUBBEventParameters, + createUBBEventsBatchParameters } from "./parameters"; import {parseOrderDetails, parseUpdateSubscriptionPayload, toQueryString} from "./payloadUtils"; import { TypeOf } from "zod"; @@ -979,6 +1003,598 @@ export async function updatePlan( } } +// === USAGE BASED BILLING API FUNCTIONS === +export async function getUBBMetrics( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[getUBBMetrics] Starting to list metrics'); + + const headers = await client.getHeaders(); + logger('[getUBBMetrics] Headers obtained'); + + const queryParams = new URLSearchParams(); + if (params.per_page) queryParams.append('per_page', params.per_page.toString()); + if (params.page) queryParams.append('page', params.page.toString()); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/metrics${queryParams.toString() ? '?' + queryParams.toString() : ''}`; + logger(`[getUBBMetrics] API URL: ${url}`); + try { + logger('[getUBBMetrics] Sending request to UBB API'); + const response = await axios.get(url, { headers }); + logger(`[getUBBMetrics] Metrics retrieved successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[getUBBMetrics] Error listing metrics:', error.message); + handleAxiosError(error); + } +} + +export async function createUBBMetric( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[createUBBMetric] Starting metric creation process'); + + const headers = await client.getHeaders(); + logger('[createUBBMetric] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/metrics`; + + try { + logger('[createUBBMetric] Sending request to UBB API'); + const response = await axios.post(url, params, { headers }); + logger(`[createUBBMetric] Metric created successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[createUBBMetric] Error creating metric:', error.message); + handleAxiosError(error); + } +} + +export async function getUBBMetricById( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[getUBBMetricById] Starting to get metric'); + + const headers = await client.getHeaders(); + logger('[getUBBMetricById] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/metrics/${params.id}`; + + try { + logger('[getUBBMetricById] Sending request to UBB API'); + const response = await axios.get(url, { headers }); + logger(`[getUBBMetricById] Metric retrieved successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[getUBBMetricById] Error getting metric:', error.message); + handleAxiosError(error); + } +} + +export async function updateUBBMetric( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[updateUBBMetric] Starting to update metric'); + + const headers = await client.getHeaders(); + logger('[updateUBBMetric] Headers obtained'); + + const { id, ...updateData } = params; + const url = `${client.getBaseUrl()}/v1/commerce/billing/metrics/${id}`; + + try { + logger('[updateUBBMetric] Sending request to UBB API'); + const response = await axios.put(url, updateData, { headers }); + logger(`[updateUBBMetric] Metric updated successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[updateUBBMetric] Error updating metric:', error.message); + handleAxiosError(error); + } +} + +export async function deleteUBBMetric( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[deleteUBBMetric] Starting to delete metric'); + + const headers = await client.getHeaders(); + logger('[deleteUBBMetric] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/metrics/${params.id}`; + + try { + logger('[deleteUBBMetric] Sending request to UBB API'); + const response = await axios.delete(url, { headers }); + logger(`[deleteUBBMetric] Metric deleted successfully. Status: ${response.status}`); + return response.status === 204 ? { success: true, id: params.id } : response.data; + } catch (error: any) { + logger('[deleteUBBMetric] Error deleting metric:', error.message); + handleAxiosError(error); + } +} + +export async function getUBBPlans( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[getUBBPlans] Starting to list plans'); + + const headers = await client.getHeaders(); + logger('[getUBBPlans] Headers obtained'); + + const queryParams = new URLSearchParams(); + if (params.per_page) queryParams.append('per_page', params.per_page.toString()); + if (params.page) queryParams.append('page', params.page.toString()); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/plans${queryParams.toString() ? '?' + queryParams.toString() : ''}`; + + try { + logger('[getUBBPlans] Sending request to UBB API'); + const response = await axios.get(url, { headers }); + logger(`[getUBBPlans] Plans retrieved successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[getUBBPlans] Error listing plans:', error.message); + handleAxiosError(error); + } +} + +export async function createUBBPlan( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[createUBBPlan] Starting plan creation process'); + + const headers = await client.getHeaders(); + logger('[createUBBPlan] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/plans`; + + try { + logger('[createUBBPlan] Sending request to UBB API'); + const response = await axios.post(url, params, { headers }); + logger(`[createUBBPlan] Plan created successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[createUBBPlan] Error creating plan:', error.message); + handleAxiosError(error); + } +} + +export async function getUBBPlanById( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[getUBBPlanById] Starting to get plan'); + + const headers = await client.getHeaders(); + logger('[getUBBPlanById] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/plans/${params.id}`; + + try { + logger('[getUBBPlanById] Sending request to UBB API'); + const response = await axios.get(url, { headers }); + logger(`[getUBBPlanById] Plan retrieved successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[getUBBPlanById] Error getting plan:', error.message); + handleAxiosError(error); + } +} + +export async function updateUBBPlan( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[updateUBBPlan] Starting to update plan'); + + const headers = await client.getHeaders(); + logger('[updateUBBPlan] Headers obtained'); + + const { id, ...updateData } = params; + const url = `${client.getBaseUrl()}/v1/commerce/billing/plans/${id}`; + + try { + logger('[updateUBBPlan] Sending request to UBB API'); + const response = await axios.put(url, updateData, { headers }); + logger(`[updateUBBPlan] Plan updated successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[updateUBBPlan] Error updating plan:', error.message); + handleAxiosError(error); + } +} + +export async function getUBBCustomers( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[getUBBCustomers] Starting to list customers'); + + const headers = await client.getHeaders(); + logger('[getUBBCustomers] Headers obtained'); + + const queryParams = new URLSearchParams(); + if (params.per_page) queryParams.append('per_page', params.per_page.toString()); + if (params.page) queryParams.append('page', params.page.toString()); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/customers${queryParams.toString() ? '?' + queryParams.toString() : ''}`; + + try { + logger('[getUBBCustomers] Sending request to UBB API'); + const response = await axios.get(url, { headers }); + logger(`[getUBBCustomers] Customers retrieved successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[getUBBCustomers] Error listing customers:', error.message); + handleAxiosError(error); + } +} + +export async function createUBBCustomer( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[createUBBCustomer] Starting customer creation process'); + + const headers = await client.getHeaders(); + logger('[createUBBCustomer] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/customers`; + + try { + logger('[createUBBCustomer] Sending request to UBB API'); + const response = await axios.post(url, params, { headers }); + logger(`[createUBBCustomer] Customer created successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[createUBBCustomer] Error creating customer:', error.message); + handleAxiosError(error); + } +} + +export async function getUBBCustomerById( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[getUBBCustomerById] Starting to get customer'); + + const headers = await client.getHeaders(); + logger('[getUBBCustomerById] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/customers/${params.id}`; + logger(`[getUBBCustomerById] API URL: ${url}`); + try { + logger('[getUBBCustomerById] Sending request to UBB API'); + const response = await axios.get(url, { headers }); + logger(`[getUBBCustomerById] Customer retrieved successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[getUBBCustomerById] Error getting customer:', error.message); + handleAxiosError(error); + } +} + +export async function updateUBBCustomer( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[updateUBBCustomer] Starting to update customer'); + + const headers = await client.getHeaders(); + logger('[updateUBBCustomer] Headers obtained'); + + const { id, ...updateData } = params; + const url = `${client.getBaseUrl()}/v1/commerce/billing/customers/${id}`; + + try { + logger('[updateUBBCustomer] Sending request to UBB API'); + const response = await axios.put(url, updateData, { headers }); + logger(`[updateUBBCustomer] Customer updated successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[updateUBBCustomer] Error updating customer:', error.message); + handleAxiosError(error); + } +} + +export async function deleteUBBCustomer( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[deleteUBBCustomer] Starting to delete customer'); + + const headers = await client.getHeaders(); + logger('[deleteUBBCustomer] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/customers/${params.id}`; + + try { + logger('[deleteUBBCustomer] Sending request to UBB API'); + const response = await axios.delete(url, { headers }); + logger(`[deleteUBBCustomer] Customer deleted successfully. Status: ${response.status}`); + return response.status === 204 ? { success: true, id: params.id } : response.data; + } catch (error: any) { + logger('[deleteUBBCustomer] Error deleting customer:', error.message); + handleAxiosError(error); + } +} + +export async function getUBBCustomerCurrentUsage( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[getUBBCustomerCurrentUsage] Starting to get customer current usage'); + + const headers = await client.getHeaders(); + logger('[getUBBCustomerCurrentUsage] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/customers/${params.id}/current_usage?subscription_id=${params.subscription_id}`; + + try { + logger('[getUBBCustomerCurrentUsage] Sending request to UBB API'); + const response = await axios.get(url, { headers }); + logger(`[getUBBCustomerCurrentUsage] Customer current usage retrieved successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[getUBBCustomerCurrentUsage] Error getting customer current usage:', error.message); + handleAxiosError(error); + } +} + +export async function getUBBCustomerPastUsage( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[getUBBCustomerPastUsage] Starting to get customer past usage'); + + const headers = await client.getHeaders(); + logger('[getUBBCustomerPastUsage] Headers obtained'); + + const queryParams = new URLSearchParams(); + queryParams.append('subscription_id', params.subscription_id); + if (params.per_page) queryParams.append('per_page', params.per_page.toString()); + if (params.page) queryParams.append('page', params.page.toString()); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/customers/${params.id}/past_usage?${queryParams.toString()}`; + + try { + logger('[getUBBCustomerPastUsage] Sending request to UBB API'); + const response = await axios.get(url, { headers }); + logger(`[getUBBCustomerPastUsage] Customer past usage retrieved successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[getUBBCustomerPastUsage] Error getting customer past usage:', error.message); + handleAxiosError(error); + } +} + +export async function getUBBSubscriptions( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[getUBBSubscriptions] Starting to list subscriptions'); + + const headers = await client.getHeaders(); + logger('[getUBBSubscriptions] Headers obtained'); + + const queryParams = new URLSearchParams(); + if (params.per_page) queryParams.append('per_page', params.per_page.toString()); + if (params.page) queryParams.append('page', params.page.toString()); + if (params.customer_id) queryParams.append('customer_id', params.customer_id); + if (params.external_customer_id) queryParams.append('external_customer_id', params.external_customer_id); + if (params.plan_code) queryParams.append('plan_code', params.plan_code); + if (params.status) queryParams.append('status', params.status); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/subscriptions${queryParams.toString() ? '?' + queryParams.toString() : ''}`; + + try { + logger('[getUBBSubscriptions] Sending request to UBB API'); + const response = await axios.get(url, { headers }); + logger(`[getUBBSubscriptions] Subscriptions retrieved successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[getUBBSubscriptions] Error listing subscriptions:', error.message); + handleAxiosError(error); + } +} + +export async function createUBBSubscription( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[createUBBSubscription] Starting subscription creation process'); + + const headers = await client.getHeaders(); + logger('[createUBBSubscription] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/subscriptions`; + + try { + logger('[createUBBSubscription] Sending request to UBB API'); + const response = await axios.post(url, params, { headers }); + logger(`[createUBBSubscription] Subscription created successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[createUBBSubscription] Error creating subscription:', error.message); + handleAxiosError(error); + } +} + +export async function getUBBSubscriptionById( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[getUBBSubscriptionById] Starting to get subscription'); + + const headers = await client.getHeaders(); + logger('[getUBBSubscriptionById] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/subscriptions/${params.id}`; + logger("getUBBSubscriptionById url: ", url); + try { + logger('[getUBBSubscriptionById] Sending request to UBB API'); + const response = await axios.get(url, { headers }); + logger(`[getUBBSubscriptionById] Subscription retrieved successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[getUBBSubscriptionById] Error getting subscription:', error.message); + handleAxiosError(error); + } +} + +export async function updateUBBSubscription( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[updateUBBSubscription] Starting to update subscription'); + + const headers = await client.getHeaders(); + logger('[updateUBBSubscription] Headers obtained'); + + const { id, ...updateData } = params; + const url = `${client.getBaseUrl()}/v1/commerce/billing/subscriptions/${id}`; + + try { + logger('[updateUBBSubscription] Sending request to UBB API'); + const response = await axios.put(url, updateData, { headers }); + logger(`[updateUBBSubscription] Subscription updated successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[updateUBBSubscription] Error updating subscription:', error.message); + handleAxiosError(error); + } +} + +export async function cancelUBBSubscription( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[cancelUBBSubscription] Starting to cancel subscription'); + + const headers = await client.getHeaders(); + logger('[cancelUBBSubscription] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/subscriptions/${params.id}/cancel`; + + const payload = params.cancel_option ? { cancel_option: params.cancel_option } : {}; + + try { + logger('[cancelUBBSubscription] Sending request to UBB API'); + const response = await axios.post(url, payload, { headers }); + logger(`[cancelUBBSubscription] Subscription canceled successfully. Status: ${response.status}`); + return response.data || { success: true, id: params.id }; + } catch (error: any) { + logger('[cancelUBBSubscription] Error canceling subscription:', error.message); + handleAxiosError(error); + } +} + +export async function getUBBEvents( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[getUBBEvents] Starting to list events'); + + const headers = await client.getHeaders(); + logger('[getUBBEvents] Headers obtained'); + + const queryParams = new URLSearchParams(); + if (params.external_subscription_id) queryParams.append('external_subscription_id', params.external_subscription_id); + if (params.metric_code) queryParams.append('metric_code', params.metric_code); + if (params.from_date) queryParams.append('from_date', params.from_date); + if (params.to_date) queryParams.append('to_date', params.to_date); + if (params.per_page) queryParams.append('per_page', params.per_page.toString()); + if (params.page) queryParams.append('page', params.page.toString()); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/events${queryParams.toString() ? '?' + queryParams.toString() : ''}`; + + try { + logger('[getUBBEvents] Sending request to UBB API'); + const response = await axios.get(url, { headers }); + logger(`[getUBBEvents] Events retrieved successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[getUBBEvents] Error listing events:', error.message); + handleAxiosError(error); + } +} + +export async function createUBBEvent( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[createUBBEvent] Starting event creation process'); + + const headers = await client.getHeaders(); + logger('[createUBBEvent] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/events`; + + try { + logger('[createUBBEvent] Sending request to UBB API'); + const response = await axios.post(url, params, { headers }); + logger(`[createUBBEvent] Event created successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[createUBBEvent] Error creating event:', error.message); + handleAxiosError(error); + } +} + +export async function createUBBEventsBatch( + client: PayPalClient, + context: Context, + params: TypeOf> +) { + logger('[createUBBEventsBatch] Starting batch event creation process'); + + const headers = await client.getHeaders(); + logger('[createUBBEventsBatch] Headers obtained'); + + const url = `${client.getBaseUrl()}/v1/commerce/billing/events/batch`; + + try { + logger('[createUBBEventsBatch] Sending request to UBB API'); + const response = await axios.post(url, params, { headers }); + logger(`[createUBBEventsBatch] Batch events created successfully. Status: ${response.status}`); + return response.data; + } catch (error: any) { + logger('[createUBBEventsBatch] Error creating batch events:', error.message); + handleAxiosError(error); + } +} + // Helper function to handle Axios errors function handleAxiosError(error: any): never { logger('[handleAxiosError] Processing error from PayPal API'); diff --git a/typescript/src/shared/parameters.ts b/typescript/src/shared/parameters.ts index b762e8b..4db26d5 100644 --- a/typescript/src/shared/parameters.ts +++ b/typescript/src/shared/parameters.ts @@ -406,4 +406,215 @@ export const createRefundParameters = (context: Context) => z.object({ note_to_payer: z.string().optional().describe('A note to the payer.'), }); +// === USAGE BASED BILLING API PARAMETERS === +export const getUBBMetricsParameters = (context: Context) => z.object({ + per_page: z.number().optional().describe("Number of records per page"), + page: z.number().optional().describe("Page number") +}); + +export const createUBBMetricParameters = (context: Context) => z.object({ + name: z.string().describe("Name of the metric"), + code: z.string().describe("A unique code to be passed with an event to associate with this metric"), + type: z.enum(["metered", "recurring"]).default("metered").describe("Type of metric (metered or recurring)"), + description: z.string().optional().describe("Description of the metric"), + aggregation_type: z.enum(["count", "count_unique", "sum", "max"]).describe("How event values should be aggregated"), + aggregation_field: z.string().optional().describe("The field in event properties to use for aggregation"), + field_filters: z.array(z.object({ + key: z.string().describe("The name of the field to filter on"), + values: z.array(z.string()).describe("List of values to filter by") + })).optional().describe("Filters to apply when counting events") +}); + +export const getUBBMetricByIdParameters = (context: Context) => z.object({ + id: z.string().describe("Metric ID") +}); + +export const updateUBBMetricParameters = (context: Context) => z.object({ + id: z.string().describe("Metric ID"), + name: z.string().optional().describe("Updated name of the metric"), + description: z.string().optional().describe("Updated description of the metric"), + field_filters: z.array(z.object({ + key: z.string().describe("The name of the field to filter on"), + values: z.array(z.string()).describe("List of values to filter by") + })).optional().describe("Updated filters to apply when counting events") +}); + +export const deleteUBBMetricParameters = (context: Context) => z.object({ + id: z.string().describe("Metric ID to delete") +}); + +export const getUBBPlansParameters = (context: Context) => z.object({ + page: z.number().optional().describe("Page number"), + per_page: z.number().optional().describe("Number of records per page") +}); + +export const createUBBPlanParameters = (context: Context) => z.object({ + name: z.string().describe("Name of the plan"), + code: z.string().describe("Unique code used to identify the plan"), + billing_cycle: z.enum(["weekly", "monthly", "quarterly", "yearly"]).describe("The interval used for recurring billing"), + description: z.string().optional().describe("Description of the plan"), + amount: z.object({ + value: z.string().describe("The amount value, represented as a string"), + currency_code: z.string().describe("ISO 4217 currency code (e.g., USD, EUR)") + }).describe("The amount charged for the plan"), + trial_period: z.number().optional().describe("Trial period in days before the first charge"), + pay_in_advance: z.boolean().optional().default(false).describe("Whether the base cost is due at beginning of billing period"), + usage_based_charges: z.array(z.object({ + metric_id: z.string().describe("Unique identifier for the metric"), + charge_model: z.enum(["tiered"]).describe("The model used to calculate charges"), + properties: z.object({}).passthrough().describe("Additional properties specific to the charge model"), + min_amount: z.object({ + value: z.string().optional().describe("Minimum amount value"), + currency_code: z.string().describe("Currency code") + }).optional().describe("Minimum amount that can be charged") + })).optional().describe("Additional usage-based charges for this plan") +}); + +export const getUBBPlanByIdParameters = (context: Context) => z.object({ + id: z.string().describe("Plan ID") +}); + +export const updateUBBPlanParameters = (context: Context) => z.object({ + id: z.string().describe("Plan ID"), + name: z.string().optional().describe("Updated name of the plan"), + description: z.string().optional().describe("Updated description of the plan"), + amount: z.object({ + value: z.string().describe("The amount value"), + currency_code: z.string().describe("ISO 4217 currency code") + }).optional().describe("Updated amount charged for the plan"), + trial_period: z.number().optional().describe("Updated trial period in days"), + pay_in_advance: z.boolean().optional().describe("Updated setting for whether to charge at beginning of billing period"), + usage_based_charges: z.array(z.object({ + metric_id: z.string().describe("Unique identifier for the metric"), + charge_model: z.enum(["tiered"]).describe("The model used to calculate charges"), + properties: z.object({}).passthrough().describe("Additional properties specific to the charge model"), + min_amount: z.object({ + value: z.string().optional().describe("Minimum amount value"), + currency_code: z.string().describe("Currency code") + }).optional().describe("Minimum amount that can be charged") + })).optional().describe("Updated usage-based charges for this plan") +}); + +export const getUBBCustomersParameters = (context: Context) => z.object({ + per_page: z.number().optional().describe("Number of records per page"), + page: z.number().optional().describe("Page number") +}); + +export const createUBBCustomerParameters = (context: Context) => z.object({ + external_customer_id: z.string().describe("External identifier for the customer in your system"), + name: z.string().describe("Full name or business name of the customer"), + email: z.string().optional().describe("Email address of the customer"), + address: z.object({ + line1: z.string().optional().describe("The first line of the address"), + line2: z.string().optional().describe("The second line of the address"), + city: z.string().optional().describe("City of the customer's address"), + state: z.string().optional().describe("State or province of the customer's address"), + postal_code: z.string().optional().describe("The postal code or zip code"), + country: z.string().optional().describe("The two-character ISO 3166-1 code for the country") + }).optional().describe("Customer's address information"), + phone: z.string().optional().describe("Customer's phone number in E.164 format"), + metadata: z.object({}).passthrough().optional().describe("Additional customer metadata") +}); + +export const getUBBCustomerByIdParameters = (context: Context) => z.object({ + id: z.string().describe("Customer ID") +}); + +export const updateUBBCustomerParameters = (context: Context) => z.object({ + id: z.string().describe("Customer ID"), + name: z.string().optional().describe("Updated name of the customer"), + email: z.string().optional().describe("Updated email address"), + address: z.object({ + line1: z.string().optional().describe("The first line of the address"), + line2: z.string().optional().describe("The second line of the address"), + city: z.string().optional().describe("City of the customer's address"), + state: z.string().optional().describe("State or province of the customer's address"), + postal_code: z.string().optional().describe("The postal code or zip code"), + country: z.string().optional().describe("The two-character ISO 3166-1 code for the country") + }).optional().describe("Updated address information"), + phone: z.string().optional().describe("Updated phone number"), + metadata: z.object({}).passthrough().optional().describe("Updated metadata") +}); + +export const deleteUBBCustomerParameters = (context: Context) => z.object({ + id: z.string().describe("Customer ID to delete") +}); + +export const getUBBCustomerCurrentUsageParameters = (context: Context) => z.object({ + id: z.string().describe("Customer ID"), + subscription_id: z.string().describe("Subscription ID to filter by") +}); + +export const getUBBCustomerPastUsageParameters = (context: Context) => z.object({ + id: z.string().describe("Customer ID"), + subscription_id: z.string().describe("Subscription ID to filter by"), + per_page: z.number().optional().describe("Number of records per page"), + page: z.number().optional().describe("Page number") +}); + +export const getUBBSubscriptionsParameters = (context: Context) => z.object({ + per_page: z.number().optional().describe("Number of records per page"), + page: z.number().optional().describe("Page number"), + customer_id: z.string().optional().describe("Filter by customer ID"), + external_customer_id: z.string().optional().describe("Filter by external customer ID"), + plan_code: z.string().optional().describe("Filter by plan code"), + status: z.enum(["active", "pending", "canceled", "terminated"]).optional().describe("Filter by subscription status") +}); + +export const createUBBSubscriptionParameters = (context: Context) => z.object({ + external_customer_id: z.string().describe("External customer ID to subscribe"), + plan_code: z.string().describe("Code of the plan to subscribe to"), + name: z.string().optional().describe("Name for the subscription"), + billing_time: z.enum(["calendar", "anniversary"]).optional().describe("When billing should occur"), + subscription_date: z.string().optional().describe("When the subscription should start"), + auto_renew: z.boolean().optional().describe("Whether the subscription should automatically renew"), + payment_method_token: z.string().optional().describe("Token identifying the payment method to use"), + payment_method_type: z.string().optional().describe("Type of payment method (card, paypal, venmo, apple_pay)"), + metadata: z.object({}).passthrough().optional().describe("Additional subscription metadata") +}); + +export const getUBBSubscriptionByIdParameters = (context: Context) => z.object({ + id: z.string().describe("Subscription ID") +}); + +export const updateUBBSubscriptionParameters = (context: Context) => z.object({ + id: z.string().describe("Subscription ID"), + name: z.string().optional().describe("Updated name for the subscription"), + ending_at: z.string().optional().describe("Date when the subscription should end (for scheduled cancellations)"), + payment_method_token: z.string().optional().describe("Token identifying a new payment method to use"), + payment_method_type: z.string().optional().describe("Type of payment method (card, paypal, venmo, apple_pay)"), + metadata: z.object({}).passthrough().optional().describe("Updated additional subscription metadata") +}); + +export const cancelUBBSubscriptionParameters = (context: Context) => z.object({ + id: z.string().describe("Subscription ID to cancel"), + cancel_option: z.enum(["end_of_period", "immediate"]).default("end_of_period").optional().describe("How the subscription should be canceled") +}); + +export const getUBBEventsParameters = (context: Context) => z.object({ + external_subscription_id: z.string().optional().describe("Filter events by external subscription ID"), + metric_code: z.string().optional().describe("Filter events by metric code"), + from_date: z.string().optional().describe("Start date for filtering events (ISO format)"), + to_date: z.string().optional().describe("End date for filtering events (ISO format)"), + per_page: z.number().optional().describe("Number of records per page"), + page: z.number().optional().describe("Page number") +}); + +export const createUBBEventParameters = (context: Context) => z.object({ + transaction_id: z.string().describe("Unique identifier for the event to prevent duplicates"), + external_subscription_id: z.string().optional().describe("External ID of the subscription"), + code: z.string().describe("Code of the metric this event applies to"), + timestamp: z.string().optional().describe("When the event occurred (ISO format)"), + properties: z.object({}).passthrough().optional().describe("Additional properties specific to the event") +}); + +export const createUBBEventsBatchParameters = (context: Context) => z.object({ + events: z.array(z.object({ + transaction_id: z.string().describe("Unique identifier for the event"), + external_subscription_id: z.string().optional().describe("External ID of the subscription"), + code: z.string().describe("Code of the metric this event applies to"), + timestamp: z.string().optional().describe("When the event occurred (ISO format)"), + properties: z.object({}).passthrough().optional().describe("Additional properties specific to the event") + })).describe("Array of events to process in batch") +}); \ No newline at end of file diff --git a/typescript/src/shared/prompts.ts b/typescript/src/shared/prompts.ts index d2c4b0d..7e6991f 100644 --- a/typescript/src/shared/prompts.ts +++ b/typescript/src/shared/prompts.ts @@ -268,3 +268,270 @@ Response details include: - Refunded amount and currency `; + +// === BEGIN USAGE BASED BILLING API PROMPTS === + +export const getUBBMetricsPrompt = (context: Context) => ` +From the Usage Based Billing(UBB) system, list all available billing metrics with pagination support. + +This function retrieves a list of all metrics configured in your UBB system. You can specify the number of records per page and the page number to navigate through results. +Metrics represent measurable quantities that you track and bill for (like API calls, storage usage, etc.). +`; + +export const createUBBMetricPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, create a new billing metric for usage tracking. + +This function creates a new metric to track and bill for specific usage. A metric represents a measurable quantity like API calls, storage usage, etc. +Required parameters are: name, code, type, and aggregation_type. +- name: The display name of the metric (e.g., "API Calls") +- code: A unique identifier for the metric (e.g., "api_calls") +- type: Whether the metric is "metered" (resets each billing period) or "recurring" (carries over) +- aggregation_type: How event values should be aggregated (count, sum, max, count_unique) +`; + +export const getUBBMetricByIdPrompt = (context: Context) => ` +From the Usage Based Billing(UBB) system, get detailed information about a specific billing metric. + +This function retrieves complete details about a metric using its unique identifier. +Required parameter: id (the unique identifier of the metric). +`; + +export const updateUBBMetricPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, update an existing billing metric's properties. + +This function allows you to modify properties of an existing metric. +Required parameter: id (the unique identifier of the metric). +Optional parameters for updating: +- name: New display name for the metric +- description: Updated description of the metric +- field_filters: Updated filters to apply when counting events for this metric +`; + +export const deleteUBBMetricPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, delete a billing metric from the system. + +This function permanently removes a metric from your UBB configuration. +Required parameter: id (the unique identifier of the metric to delete). +Caution: This action cannot be undone and may affect billing for any plans using this metric. +`; + +export const getUBBPlansPrompt = (context: Context) => ` +From the Usage Based Billing(UBB) system, list all billing plans with pagination support. + +This function retrieves a list of all billing plans configured in your UBB system. Plans define the pricing structure for your services. +You can specify the number of records per page and the page number to navigate through results. +`; + +export const createUBBPlanPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, create a new billing plan. + +This function creates a new billing plan that specifies the pricing structure including base price, billing cycle, and any usage-based charges. +Required parameters are: +- name: Display name of the plan +- code: Unique identifier for the plan +- billing_cycle: The interval for recurring billing (weekly, monthly, quarterly, yearly) +- amount: The base amount charged for the plan (includes value and currency_code) + +Optional parameters: +- description: Text description of the plan +- trial_period: Number of days before the first charge is applied +- pay_in_advance: Whether the base cost is due at beginning of billing period +- usage_based_charges: Additional charges based on usage metrics +`; + +export const getUBBPlanByIdPrompt = (context: Context) => ` +From the Usage Based Billing(UBB) system, get detailed information about a specific billing plan. + +This function retrieves complete details about a plan using its unique identifier. +Required parameter: id (the unique identifier of the plan). +`; + +export const updateUBBPlanPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, update an existing billing plan's properties. + +This function allows you to modify properties of an existing billing plan. +Required parameter: id (the unique identifier of the plan). +Optional parameters for updating: +- name: New display name for the plan +- description: Updated description of the plan +- amount: Updated base amount charged for the plan +- trial_period: Updated trial period in days +- pay_in_advance: Updated setting for whether to charge at the beginning of billing period +- usage_based_charges: Updated additional charges based on usage metrics +`; + +export const getUBBCustomersPrompt = (context: Context) => ` +From the Usage Based Billing(UBB) system, list all customers with pagination support. + +This function retrieves a list of all customers in your UBB system. +You can specify the number of records per page and the page number to navigate through results. +`; + +export const createUBBCustomerPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, create a new customer record for billing purposes. + +This function creates a new customer that can be subscribed to billing plans. +Required parameters are: +- external_customer_id: Your identifier for the customer in your system +- name: Full name or business name of the customer + +Optional parameters: +- email: Email address of the customer +- address: Customer's address information (with line1, line2, city, state, postal_code, country) +- phone: Customer's phone number in E.164 format +- metadata: Additional customer data as key-value pairs +`; + +export const getUBBCustomerByIdPrompt = (context: Context) => ` +From the Usage Based Billing(UBB) system, get detailed information about a specific customer. + +This function retrieves complete details about a customer using their unique identifier. +Required parameter: id (the unique identifier of the customer). +`; + +export const updateUBBCustomerPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, update an existing customer's information. + +This function allows you to modify properties of an existing customer record. +Required parameter: id (the unique identifier of the customer). +Optional parameters for updating: +- name: Updated name for the customer +- email: Updated email address +- address: Updated address information +- phone: Updated phone number +- metadata: Updated additional customer data +`; + +export const deleteUBBCustomerPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, delete a customer record from the system. + +This function permanently removes a customer from your UBB system. +Required parameter: id (the unique identifier of the customer to delete). +Caution: This action cannot be undone and will affect any active subscriptions for this customer. +`; + +export const getUBBCustomerCurrentUsagePrompt = (context: Context) => ` +From the Usage Based Billing(UBB) system, get current usage information for a specific customer. + +This function retrieves detailed usage data for a customer in the current billing period. +Required parameters: +- id: The unique identifier of the customer +- subscription_id: The subscription to get usage data for +`; + +export const getUBBCustomerPastUsagePrompt = (context: Context) => ` +From the Usage Based Billing(UBB) system, get historical usage information for a specific customer. + +This function retrieves usage data for a customer across previous billing periods. +Required parameters: +- id: The unique identifier of the customer +- subscription_id: The subscription to get historical usage data for + +Optional parameters: +- per_page: Number of records per page +- page: Page number for pagination +`; + +export const getUBBSubscriptionsPrompt = (context: Context) => ` +From the Usage Based Billing(UBB) system, list subscriptions with filtering and pagination support. + +This function retrieves a list of subscriptions with optional filtering by customer, plan, and status. +Optional parameters: +- customer_id: Filter by internal customer ID +- external_customer_id: Filter by your external customer ID +- plan_code: Filter by plan code +- status: Filter by subscription status (active, pending, canceled, terminated) +- per_page: Number of records per page +- page: Page number for pagination +`; + +export const createUBBSubscriptionPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, create a new subscription for a customer to a billing plan. + +This function subscribes a customer to a specific billing plan. +Required parameters: +- external_customer_id: Your identifier for the customer in your system +- plan_code: The code of the plan to subscribe to + +Optional parameters: +- name: A name for this subscription +- billing_time: When billing should occur (calendar or anniversary) +- subscription_date: When the subscription should start (ISO format) +- auto_renew: Whether the subscription should automatically renew +- payment_method_token: Token identifying the payment method to use +- payment_method_type: Type of payment method (card, paypal, venmo, apple_pay) +- metadata: Additional subscription data as key-value pairs +`; + +export const getUBBSubscriptionByIdPrompt = (context: Context) => ` +From the Usage Based Billing(UBB) system, get detailed information about a specific subscription. + +This function retrieves complete details about a subscription using its unique identifier. +Required parameter: id (the unique identifier of the subscription). +`; + +export const updateUBBSubscriptionPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, update an existing subscription's details. + +This function allows you to modify properties of an active subscription. +Required parameter: id (the unique identifier of the subscription). +Optional parameters for updating: +- name: Updated name for the subscription +- ending_at: Date when the subscription should end (for scheduled cancellations) +- payment_method_token: Token identifying a new payment method to use +- payment_method_type: Updated payment method type +- metadata: Updated additional subscription data +`; + +export const cancelUBBSubscriptionPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, cancel a subscription. + +This function cancels an active subscription. +Required parameter: id (the unique identifier of the subscription). +Optional parameter: +- cancel_option: How the subscription should be canceled ("end_of_period" or "immediate") + +The default behavior cancels at the end of the current billing period. +`; + +export const getUBBEventsPrompt = (context: Context) => ` +From the Usage Based Billing(UBB) system, query usage events with filtering and pagination support. + +This function retrieves events that represent recorded usage data for billing metrics. +Optional parameters: +- external_subscription_id: Filter events by external subscription ID +- metric_code: Filter events by metric code +- from_date: Start date for filtering events (ISO format) +- to_date: End date for filtering events (ISO format) +- per_page: Number of records per page +- page: Page number for pagination +`; + +export const createUBBEventPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, create a new usage event for tracking billable activities. + +This function records a usage event that will be used for billing calculations. +Required parameters: +- transaction_id: Unique identifier for the event to prevent duplicates +- code: Code of the metric this event applies to + +Optional parameters: +- external_subscription_id: External ID of the subscription this event applies to +- timestamp: When the event occurred (ISO format) +- properties: Additional event-specific properties, which might include quantities or other measurable values +`; + +export const createUBBEventsBatchPrompt = (context: Context) => ` +In the Usage Based Billing(UBB) system, create multiple usage events in a single batch request. + +This function allows you to record multiple usage events in one API call, which is more efficient than creating events individually. +Required parameter: +- events: An array of event objects, each containing: + * transaction_id: Unique identifier for the event + * code: Code of the metric this event applies to + * external_subscription_id: (optional) External ID of the subscription + * timestamp: (optional) When the event occurred + * properties: (optional) Additional event-specific properties +`; + +// === END USAGE BASED BILLING API PROMPTS === \ No newline at end of file diff --git a/typescript/src/shared/tools.ts b/typescript/src/shared/tools.ts index c47e7e5..deaba1c 100644 --- a/typescript/src/shared/tools.ts +++ b/typescript/src/shared/tools.ts @@ -31,6 +31,31 @@ import { updateSubscriptionPrompt, getRefundPrompt, createRefundPrompt, + // UBB prompts + getUBBMetricsPrompt, + createUBBMetricPrompt, + getUBBMetricByIdPrompt, + updateUBBMetricPrompt, + deleteUBBMetricPrompt, + getUBBPlansPrompt, + createUBBPlanPrompt, + getUBBPlanByIdPrompt, + updateUBBPlanPrompt, + getUBBCustomersPrompt, + createUBBCustomerPrompt, + getUBBCustomerByIdPrompt, + updateUBBCustomerPrompt, + deleteUBBCustomerPrompt, + getUBBCustomerCurrentUsagePrompt, + getUBBCustomerPastUsagePrompt, + getUBBSubscriptionsPrompt, + createUBBSubscriptionPrompt, + getUBBSubscriptionByIdPrompt, + updateUBBSubscriptionPrompt, + cancelUBBSubscriptionPrompt, + getUBBEventsPrompt, + createUBBEventPrompt, + createUBBEventsBatchPrompt, } from './prompts'; import { @@ -64,6 +89,31 @@ import { updateSubscriptionParameters, getRefundParameters, createRefundParameters, + // UBB parameters + getUBBMetricsParameters, + createUBBMetricParameters, + getUBBMetricByIdParameters, + updateUBBMetricParameters, + deleteUBBMetricParameters, + getUBBPlansParameters, + createUBBPlanParameters, + getUBBPlanByIdParameters, + updateUBBPlanParameters, + getUBBCustomersParameters, + createUBBCustomerParameters, + getUBBCustomerByIdParameters, + updateUBBCustomerParameters, + deleteUBBCustomerParameters, + getUBBCustomerCurrentUsageParameters, + getUBBCustomerPastUsageParameters, + getUBBSubscriptionsParameters, + createUBBSubscriptionParameters, + getUBBSubscriptionByIdParameters, + updateUBBSubscriptionParameters, + cancelUBBSubscriptionParameters, + getUBBEventsParameters, + createUBBEventParameters, + createUBBEventsBatchParameters, } from './parameters'; import type { Context } from './configuration'; @@ -410,6 +460,271 @@ const tools = (context: Context): Tool[] => [ getRefunds: true, }, }, + }, + // UBB tools + { + method: 'get_ubb_metrics', + name: 'Get UBB Metrics', + description: getUBBMetricsPrompt(context), + parameters: getUBBMetricsParameters(context), + actions: { + ubbMetrics: { + list: true, + }, + }, + }, + { + method: 'create_ubb_metric', + name: 'Create UBB Metric', + description: createUBBMetricPrompt(context), + parameters: createUBBMetricParameters(context), + actions: { + ubbMetrics: { + create: true, + }, + }, + }, + { + method: 'get_ubb_metric_by_id', + name: 'Get UBB Metric By ID', + description: getUBBMetricByIdPrompt(context), + parameters: getUBBMetricByIdParameters(context), + actions: { + ubbMetrics: { + get: true, + }, + }, + }, + { + method: 'update_ubb_metric', + name: 'Update UBB Metric', + description: updateUBBMetricPrompt(context), + parameters: updateUBBMetricParameters(context), + actions: { + ubbMetrics: { + update: true, + }, + }, + }, + { + method: 'delete_ubb_metric', + name: 'Delete UBB Metric', + description: deleteUBBMetricPrompt(context), + parameters: deleteUBBMetricParameters(context), + actions: { + ubbMetrics: { + delete: true, + }, + }, + }, + { + method: 'get_ubb_plans', + name: 'Get UBB Plans', + description: getUBBPlansPrompt(context), + parameters: getUBBPlansParameters(context), + actions: { + ubbPlans: { + list: true, + }, + }, + }, + { + method: 'create_ubb_plan', + name: 'Create UBB Plan', + description: createUBBPlanPrompt(context), + parameters: createUBBPlanParameters(context), + actions: { + ubbPlans: { + create: true, + }, + }, + }, + { + method: 'get_ubb_plan_by_id', + name: 'Get UBB Plan By ID', + description: getUBBPlanByIdPrompt(context), + parameters: getUBBPlanByIdParameters(context), + actions: { + ubbPlans: { + get: true, + }, + }, + }, + { + method: 'update_ubb_plan', + name: 'Update UBB Plan', + description: updateUBBPlanPrompt(context), + parameters: updateUBBPlanParameters(context), + actions: { + ubbPlans: { + update: true, + }, + }, + }, + { + method: 'get_ubb_customers', + name: 'Get UBB Customers', + description: getUBBCustomersPrompt(context), + parameters: getUBBCustomersParameters(context), + actions: { + ubbCustomers: { + list: true, + }, + }, + }, + { + method: 'create_ubb_customer', + name: 'Create UBB Customer', + description: createUBBCustomerPrompt(context), + parameters: createUBBCustomerParameters(context), + actions: { + ubbCustomers: { + create: true, + }, + }, + }, + { + method: 'get_ubb_customer_by_id', + name: 'Get UBB Customer By ID', + description: getUBBCustomerByIdPrompt(context), + parameters: getUBBCustomerByIdParameters(context), + actions: { + ubbCustomers: { + get: true, + }, + }, + }, + { + method: 'update_ubb_customer', + name: 'Update UBB Customer', + description: updateUBBCustomerPrompt(context), + parameters: updateUBBCustomerParameters(context), + actions: { + ubbCustomers: { + update: true, + }, + }, + }, + { + method: 'delete_ubb_customer', + name: 'Delete UBB Customer', + description: deleteUBBCustomerPrompt(context), + parameters: deleteUBBCustomerParameters(context), + actions: { + ubbCustomers: { + delete: true, + }, + }, + }, + { + method: 'get_ubb_customer_current_usage', + name: 'Get UBB Customer Current Usage', + description: getUBBCustomerCurrentUsagePrompt(context), + parameters: getUBBCustomerCurrentUsageParameters(context), + actions: { + ubbCustomerUsage: { + getCurrent: true, + }, + }, + }, + { + method: 'get_ubb_customer_past_usage', + name: 'Get UBB Customer Past Usage', + description: getUBBCustomerPastUsagePrompt(context), + parameters: getUBBCustomerPastUsageParameters(context), + actions: { + ubbCustomerUsage: { + getPast: true, + }, + }, + }, + { + method: 'get_ubb_subscriptions', + name: 'Get UBB Subscriptions', + description: getUBBSubscriptionsPrompt(context), + parameters: getUBBSubscriptionsParameters(context), + actions: { + ubbSubscriptions: { + list: true, + }, + }, + }, + { + method: 'create_ubb_subscription', + name: 'Create UBB Subscription', + description: createUBBSubscriptionPrompt(context), + parameters: createUBBSubscriptionParameters(context), + actions: { + ubbSubscriptions: { + create: true, + }, + }, + }, + { + method: 'get_ubb_subscription_by_id', + name: 'Get UBB Subscription By ID', + description: getUBBSubscriptionByIdPrompt(context), + parameters: getUBBSubscriptionByIdParameters(context), + actions: { + ubbSubscriptions: { + get: true, + }, + }, + }, + { + method: 'update_ubb_subscription', + name: 'Update UBB Subscription', + description: updateUBBSubscriptionPrompt(context), + parameters: updateUBBSubscriptionParameters(context), + actions: { + ubbSubscriptions: { + update: true, + }, + }, + }, + { + method: 'cancel_ubb_subscription', + name: 'Cancel UBB Subscription', + description: cancelUBBSubscriptionPrompt(context), + parameters: cancelUBBSubscriptionParameters(context), + actions: { + ubbSubscriptions: { + cancel: true, + }, + }, + }, + { + method: 'get_ubb_events', + name: 'Get UBB Events', + description: getUBBEventsPrompt(context), + parameters: getUBBEventsParameters(context), + actions: { + ubbEvents: { + list: true, + }, + }, + }, + { + method: 'create_ubb_event', + name: 'Create UBB Event', + description: createUBBEventPrompt(context), + parameters: createUBBEventParameters(context), + actions: { + ubbEvents: { + create: true, + }, + }, + }, + { + method: 'create_ubb_events_batch', + name: 'Create UBB Events Batch', + description: createUBBEventsBatchPrompt(context), + parameters: createUBBEventsBatchParameters(context), + actions: { + ubbEvents: { + createBatch: true, + }, + }, } ]; const allActions = tools({}).reduce((acc, tool) => {