import {z} from 'zod' export type AgentAPIKeyType = 'internal' | 'external' | 'github' | 'slack'; export type DeleteApiAgentApiKeysNameApiKeyNameArgs = {api_key_name: string, agent_id?: (string | null) | undefined, agent_name?: (string | null) | undefined, api_key_type?: AgentAPIKeyType | undefined}; export type DeleteApiAgentApiKeysNameApiKeyNameOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const deleteApiAgentApiKeysNameApiKeyNameResponse = z.string(); 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 }; /** * Delete API key by name * * DELETE /agent_api_keys/name/{api_key_name} */ export const deleteApiAgentApiKeysNameApiKeyName = async (args: DeleteApiAgentApiKeysNameApiKeyNameArgs, options: DeleteApiAgentApiKeysNameApiKeyNameOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.agent_id != null) query.append("agent_id", String(args.agent_id)) if (args.agent_name != null) query.append("agent_name", String(args.agent_name)) if (args.api_key_type != null) query.append("api_key_type", String(args.api_key_type)) const url = `${baseUrl.replace(/\/+$/, '')}/agent_api_keys/name/${encodeURIComponent(String(args.api_key_name))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deleteApiAgentApiKeysNameApiKeyNameResponse, await res.json()) };