import {z} from 'zod' export type GetApiV1AccountIdProjectIdHandoffStateArgs = {account_id: string, project_id: string, id?: string | undefined, shared_id?: string | undefined}; export type GetApiV1AccountIdProjectIdHandoffStateOptions = {baseUrl?: string | undefined, polyApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const handoffState = z.object({id: z.string(), shared_id: z.string().optional(), data: z.object({})}); 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 handoff state information for a call. * * GET /v1/{account_id}/{project_id}/handoff_state */ export const getApiV1AccountIdProjectIdHandoffState = async (args: GetApiV1AccountIdProjectIdHandoffStateArgs, options?: GetApiV1AccountIdProjectIdHandoffStateOptions) => { 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.id != null) query.append("id", String(args.id)) if (args.shared_id != null) query.append("shared_id", String(args.shared_id)) if (polyApiKey !== undefined) headers.set("X-API-KEY", polyApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/${encodeURIComponent(String(args.account_id))}/${encodeURIComponent(String(args.project_id))}/handoff_state${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(handoffState, await res.json()) };