import {z} from 'zod' export type OnJoinMessage = {type: 'text', content: string, send_after_ms: number}; export type OnParticipantJoinMessage = {type: 'text', content: string, debounce_ms: number}; export type Messages = {on_join?: Array | undefined, on_participant_join?: Array | undefined}; export type VideoOutput = {file_key?: string | undefined, media_type?: ('image/png' | 'image/jpeg' | 'image/webp') | undefined, data?: string | undefined, size?: number | undefined, preview_url?: string | undefined, preview_url_expires_at?: number | undefined}; export type NotetakerSettings = {name?: string | undefined, recording_type?: ('audio_video' | 'audio') | undefined, transcription?: boolean | undefined, transcription_settings?: ({expected_languages?: Array | undefined, fallback_language?: string | undefined, keywords?: Array | undefined, use_speaker_names_as_keywords?: boolean | undefined} | null) | undefined, summary?: boolean | undefined, summary_settings?: ({custom_instructions?: string | undefined}) | undefined, action_items?: boolean | undefined, action_items_settings?: ({custom_instructions?: string | undefined}) | undefined, leave_after_silence_seconds?: number | undefined, messages?: Messages | undefined, video_output?: VideoOutput | undefined, retention_time?: number | undefined}; export type CreateApiV3NotetakersConfigsArgs = {body: {application_id?: string | undefined, workspace_id?: string | undefined, grant_id?: string | undefined, display_name?: string | undefined, notetaker_settings?: NotetakerSettings | undefined, deduplication_policy?: ('active' | 'inactive') | undefined, dispatch_disabled_until?: (string | null) | undefined}}; export type CreateApiV3NotetakersConfigsOptions = {baseUrl?: string | undefined, NYLASAPIKEY?: string | undefined, fetch?: typeof fetch | undefined}; export const onJoinMessage = z.object({type: z.literal("text"), content: z.string().min(1).max(1000), send_after_ms: z.number().int().gte(1).lte(600000)}); export const onParticipantJoinMessage = z.object({type: z.literal("text"), content: z.string().min(1).max(1000), debounce_ms: z.number().int().gte(1).lte(600000)}); export const messages = z.object({on_join: z.array(onJoinMessage).optional(), on_participant_join: z.array(onParticipantJoinMessage).optional()}); export const videoOutput = z.object({file_key: z.string().optional(), media_type: z.enum(["image/png", "image/jpeg", "image/webp"]).optional(), data: z.string().optional(), size: z.number().int().optional(), preview_url: z.string().optional(), preview_url_expires_at: z.number().int().optional()}); export const notetakerSettings = z.object({name: z.string().optional(), recording_type: z.enum(["audio_video", "audio"]).optional(), transcription: z.boolean().optional(), transcription_settings: z.object({expected_languages: z.array(z.string()).optional(), fallback_language: z.string().optional(), keywords: z.array(z.string().max(200)).optional(), use_speaker_names_as_keywords: z.boolean().optional()}).nullable().optional(), summary: z.boolean().optional(), summary_settings: z.object({custom_instructions: z.string().max(3000).optional()}).optional(), action_items: z.boolean().optional(), action_items_settings: z.object({custom_instructions: z.string().max(3000).optional()}).optional(), leave_after_silence_seconds: z.number().int().gte(10).lte(3600).optional(), messages: messages.optional(), video_output: videoOutput.optional(), retention_time: z.number().int().gte(300).lte(2592000).optional()}); export const createApiV3NotetakersConfigsResponse = z.object({request_id: z.string().optional(), data: z.object({config_id: z.string().optional(), application_id: z.string().optional(), scope: z.enum(["application", "workspace", "grant"]).optional(), display_name: z.string().optional(), notetaker_settings: notetakerSettings.optional(), deduplication_policy: z.enum(["active", "inactive", "inherit", "disable"]).optional(), dispatch_disabled_until: z.string().nullable().optional(), version: z.number().int().optional(), created_at: z.number().int().optional(), updated_at: z.number().int().optional()}).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 }; /** * Create a Notetaker Configuration * * POST /v3/notetakers/configs */ export const createApiV3NotetakersConfigs = async (args: CreateApiV3NotetakersConfigsArgs, options?: CreateApiV3NotetakersConfigsOptions) => { const {baseUrl = "https://api.us.nylas.com", fetch: fetchFn = fetch, NYLASAPIKEY} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (NYLASAPIKEY !== undefined) headers.set('authorization', `Bearer ${NYLASAPIKEY}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/notetakers/configs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiV3NotetakersConfigsResponse, await res.json()) };