import {z} from 'zod' export type GetApiV1AccountIdProjectIdConversationsConcurrencyArgs = {account_id: string, project_id: string, start_time: string, end_time: string, client_env?: ('sandbox' | 'pre-release' | 'live') | undefined, variant_name?: string | undefined, variant_id?: string | undefined, language?: string | undefined, phone_number?: string | undefined, slice_by?: string | undefined}; export type GetApiV1AccountIdProjectIdConversationsConcurrencyOptions = {baseUrl?: string | undefined, polyApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1AccountIdProjectIdConversationsConcurrencyResponse = z.object({account_id: z.string(), project_id: z.string(), intervals: z.array(z.object({time: z.string(), max_concurrent_conversations: z.number().int(), variant_id: z.string().optional(), variant_name: z.string().optional(), language: z.string().optional(), phone_number: z.string().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 }; /** * Get distribution of the maximum number of concurrent conversations * * GET /v1/{account_id}/{project_id}/conversations/concurrency */ export const getApiV1AccountIdProjectIdConversationsConcurrency = async (args: GetApiV1AccountIdProjectIdConversationsConcurrencyArgs, options?: GetApiV1AccountIdProjectIdConversationsConcurrencyOptions) => { const {baseUrl = "https://api.us.poly.ai", fetch: fetchFn = fetch, polyApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (args.client_env != null) query.append("client_env", String(args.client_env)) if (args.variant_name != null) query.append("variant_name", String(args.variant_name)) if (args.variant_id != null) query.append("variant_id", String(args.variant_id)) if (args.language != null) query.append("language", String(args.language)) if (args.phone_number != null) query.append("phone_number", String(args.phone_number)) if (args.slice_by != null) query.append("slice_by", String(args.slice_by)) if (polyApiKey !== undefined) headers.set("X-API-KEY", polyApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.account_id))}/${encodeURIComponent(String(args.project_id))}/conversations/concurrency${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1AccountIdProjectIdConversationsConcurrencyResponse, await res.json()) };