import {z} from 'zod' export type GetApiAdminTranscriptsTranscriptIdSpeakersArgs = {transcript_id: string}; export type GetApiAdminTranscriptsTranscriptIdSpeakersOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const callRequestPosition = z.enum(["NONE", "BEAR", "BULL", "SKEPTIC"]); export const stanceSource = z.enum(["CALL_REQUEST", "LLM_INFERRED", "ADMIN_MANUAL"]); export const stanceResponse = z.object({stance_id: z.string(), association_id: z.string(), ticker: z.string(), stance: callRequestPosition, stance_source: stanceSource, is_high_conviction: z.boolean(), llm_stance: callRequestPosition.nullable()}); export const speakerResponse = z.object({association_id: z.string(), transcript_id: z.string(), user_id: z.string().nullable(), guest_name: z.string().nullable(), speaker_label: z.string().nullable(), stances: z.array(stanceResponse)}); export const getApiAdminTranscriptsTranscriptIdSpeakersResponse = z.array(speakerResponse); 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 Transcript Speakers * * GET /admin/transcripts/{transcript_id}/speakers */ export const getApiAdminTranscriptsTranscriptIdSpeakers = async (args: GetApiAdminTranscriptsTranscriptIdSpeakersArgs, options: GetApiAdminTranscriptsTranscriptIdSpeakersOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/admin/transcripts/${encodeURIComponent(String(args.transcript_id))}/speakers${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(getApiAdminTranscriptsTranscriptIdSpeakersResponse, await res.json()) };