import { CLOSEBOT_FOLDER_CREATED_SCHEMA, CLOSEBOT_FOLDER_SCHEMA, CLOSEBOT_ID_SCHEMA, } from "@automate.ax/integration-contracts/closebot" import * as z from "zod" import { defineAction } from "../../../automation/actions" import { CLOSEBOT_ACCOUNT, getCloseBotApi } from "./lib" /** Lists the CloseBot folders that organize bots and personas. */ export const listCloseBotFolders = defineAction("List CloseBot folders") .describe("Lists folders and their bot, persona, and child-folder IDs.") .account(CLOSEBOT_ACCOUNT) .output(CLOSEBOT_FOLDER_SCHEMA.array()) .retry({ replaySafety: "safe" }) .handler(async ({ account }) => getCloseBotApi(account.secret).request("hierarchy", { responseSchema: CLOSEBOT_FOLDER_SCHEMA.array(), }), ) /** Retrieves one CloseBot folder. */ export const getCloseBotFolder = defineAction("Get CloseBot folder") .describe("Retrieves one folder and its contained resource IDs.") .account(CLOSEBOT_ACCOUNT) .input(z.object({ folderId: CLOSEBOT_ID_SCHEMA })) .output(CLOSEBOT_FOLDER_SCHEMA) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => getCloseBotApi(account.secret).request( `hierarchy/${encodeURIComponent(input.folderId)}`, { responseSchema: CLOSEBOT_FOLDER_SCHEMA }, ), ) /** Creates a CloseBot folder. */ export const createCloseBotFolder = defineAction("Create CloseBot folder") .describe("Creates a top-level or nested folder for bots and personas.") .account(CLOSEBOT_ACCOUNT) .input( z.object({ name: z.string().trim().min(1), parentId: CLOSEBOT_ID_SCHEMA.optional(), }), ) .output(CLOSEBOT_FOLDER_CREATED_SCHEMA) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => getCloseBotApi(account.secret).request("hierarchy", { body: input, method: "POST", responseSchema: CLOSEBOT_FOLDER_CREATED_SCHEMA, }), ) /** Renames a CloseBot folder. */ export const updateCloseBotFolder = defineAction("Update CloseBot folder") .describe("Renames one CloseBot folder.") .account(CLOSEBOT_ACCOUNT) .input( z.object({ folderId: CLOSEBOT_ID_SCHEMA, name: z.string().trim().min(1) }), ) .output(z.null()) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => getCloseBotApi(account.secret).request( `hierarchy/${encodeURIComponent(input.folderId)}`, { body: { name: input.name }, method: "PUT", responseSchema: z.null() }, ), ) /** Deletes a CloseBot folder. */ export const deleteCloseBotFolder = defineAction("Delete CloseBot folder") .describe("Deletes one bot and persona folder.") .account(CLOSEBOT_ACCOUNT) .input(z.object({ folderId: CLOSEBOT_ID_SCHEMA })) .output(z.null()) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => getCloseBotApi(account.secret).request( `hierarchy/${encodeURIComponent(input.folderId)}`, { method: "DELETE", responseSchema: z.null() }, ), )