import {z} from 'zod' export type IToolTypeEnum = 'system' | 'user'; export type IChannelProviderEnum = 'leadconnector' | 'hubspot' | 'google_calendar' | 'google_sheets' | 'zoho' | 'freshdesk' | 'insighto' | 'modmed' | 'twilio' | 'custom' | 'fb_messenger' | 'instagram' | 'paypal' | 'postgres' | 'plivo' | 'telnyx' | 'telegram' | 'calendar_pool'; export type IToolCategoryEnum = 'Calendar' | 'CRM' | 'EHR' | 'Support' | 'Communication' | 'System' | 'HRMS' | 'Social' | 'Others' | 'Payment' | 'Database' | 'MCP'; export type IToolUpdate = {name?: (string | null) | undefined, description?: (string | null) | undefined, org_id?: (string | null) | undefined, tool_type?: (IToolTypeEnum | null) | undefined, authentication?: ({[key: string]: unknown} | null) | undefined, sdk?: ({[key: string]: unknown} | null) | undefined, base_url?: (string | null) | undefined, logo_url?: (string | null) | undefined, tool_provider?: (IChannelProviderEnum | null) | undefined, enabled?: (boolean | null) | undefined, attributes?: ({[key: string]: unknown} | null) | undefined, category?: (IToolCategoryEnum | null) | undefined, requires_feature?: (string | null) | undefined}; export type UpdateApiApiV1ToolToolIdArgs = {tool_id: string, body: IToolUpdate}; export type UpdateApiApiV1ToolToolIdOptions = {baseUrl: string, YourAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const iToolTypeEnum = z.enum(["system", "user"]); export const iChannelProviderEnum = z.enum(["leadconnector", "hubspot", "google_calendar", "google_sheets", "zoho", "freshdesk", "insighto", "modmed", "twilio", "custom", "fb_messenger", "instagram", "paypal", "postgres", "plivo", "telnyx", "telegram", "calendar_pool"]); export const iToolCategoryEnum = z.enum(["Calendar", "CRM", "EHR", "Support", "Communication", "System", "HRMS", "Social", "Others", "Payment", "Database", "MCP"]); export const iToolUpdate = z.object({name: z.string().nullable().optional(), description: z.string().nullable().optional(), org_id: z.string().nullable().optional(), tool_type: iToolTypeEnum.nullable().optional(), authentication: z.record(z.string(), z.unknown()).nullable().optional(), sdk: z.record(z.string(), z.unknown()).nullable().optional(), base_url: z.string().nullable().optional(), logo_url: z.string().nullable().optional(), tool_provider: iChannelProviderEnum.nullable().optional(), enabled: z.boolean().nullable().optional(), attributes: z.record(z.string(), z.unknown()).nullable().optional(), category: iToolCategoryEnum.nullable().optional(), requires_feature: z.string().nullable().optional()}); export const iPutResponseBaseIToolUpdate = z.object({message: z.string().nullable().optional(), meta: z.union([z.record(z.string(), z.unknown()), z.unknown()]).nullable().optional(), data: iToolUpdate.nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update Tool By Id * * PUT /api/v1/tool/{tool_id} * * Also accepts auth: HTTPBearer */ export const updateApiApiV1ToolToolId = async (args: UpdateApiApiV1ToolToolIdArgs, options: UpdateApiApiV1ToolToolIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, YourAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (YourAPIKey !== undefined) query.set("api_key", YourAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/tool/${encodeURIComponent(String(args.tool_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(iPutResponseBaseIToolUpdate, await res.json()) };