import {z} from 'zod' export type IToolFunctionTypeEnum = 'sdk' | 'curl' | 'query_index'; export type IToolFunctionUpdate = {name?: (string | null) | undefined, description?: (string | null) | undefined, tool_function_type?: (IToolFunctionTypeEnum | null) | undefined, details?: ({[key: string]: unknown} | null) | undefined, tool_id?: (string | null) | undefined, is_enabled?: (boolean | null) | undefined}; export type UpdateApiApiV1ToolfunctionToolfunctionIdArgs = {toolfunction_id: string, body: IToolFunctionUpdate}; export type UpdateApiApiV1ToolfunctionToolfunctionIdOptions = {baseUrl: string, YourAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const iToolFunctionTypeEnum = z.enum(["sdk", "curl", "query_index"]); export const iToolFunctionUpdate = z.object({name: z.string().nullable().optional(), description: z.string().nullable().optional(), tool_function_type: iToolFunctionTypeEnum.nullable().optional(), details: z.record(z.string(), z.unknown()).nullable().optional(), tool_id: z.string().nullable().optional(), is_enabled: z.boolean().nullable().optional()}); export const iPutResponseBaseIToolFunctionUpdate = z.object({message: z.string().nullable().optional(), meta: z.union([z.record(z.string(), z.unknown()), z.unknown()]).nullable().optional(), data: iToolFunctionUpdate.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 Toolfunction By Id * * PUT /api/v1/toolfunction/{toolfunction_id} * * Also accepts auth: HTTPBearer */ export const updateApiApiV1ToolfunctionToolfunctionId = async (args: UpdateApiApiV1ToolfunctionToolfunctionIdArgs, options: UpdateApiApiV1ToolfunctionToolfunctionIdOptions) => { 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/toolfunction/${encodeURIComponent(String(args.toolfunction_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(iPutResponseBaseIToolFunctionUpdate, await res.json()) };