import {z} from 'zod' export type SaladCloudTranscriptionAPIInput = {url: string, language_code?: ('en' | 'zh' | 'de' | 'es' | 'ru' | 'ko' | 'fr' | 'ja' | 'pt' | 'tr' | 'pl' | 'ca' | 'nl' | 'ar' | 'sv' | 'it' | 'id' | 'hi' | 'fi' | 'vi' | 'he' | 'uk' | 'el' | 'ms' | 'cs' | 'ro' | 'da' | 'hu' | 'ta' | 'no' | 'th' | 'ur' | 'hr' | 'bg' | 'lt' | 'la' | 'mi' | 'ml' | 'cy' | 'sk' | 'te' | 'fa' | 'lv' | 'bn' | 'sr' | 'az' | 'sl' | 'kn' | 'et' | 'mk' | 'br' | 'eu' | 'is' | 'hy' | 'ne' | 'mn' | 'bs' | 'kk' | 'sq' | 'sw' | 'gl' | 'mr' | 'pa' | 'si' | 'km' | 'sn' | 'yo' | 'so' | 'af' | 'oc' | 'ka' | 'be' | 'tg' | 'sd' | 'gu' | 'am' | 'yi' | 'lo' | 'uz' | 'fo' | 'ht' | 'ps' | 'tk' | 'nn' | 'mt' | 'sa' | 'lb' | 'my' | 'bo' | 'tl' | 'mg' | 'as' | 'tt' | 'haw' | 'ln' | 'ha' | 'ba' | 'jw' | 'su' | 'yue') | undefined, return_as_file?: boolean | undefined, sentence_level_timestamps?: boolean | undefined, word_level_timestamps?: boolean | undefined, diarization?: boolean | undefined, sentence_diarization?: boolean | undefined, srt?: boolean | undefined, translate?: string | undefined, custom_prompt?: string | undefined, summarize?: number | undefined, llm_translation?: string | undefined, srt_translation?: string | undefined, custom_vocabulary?: string | undefined, classification_labels?: string | undefined, overall_classification?: boolean | undefined, overall_sentiment_analysis?: boolean | undefined}; export type CreateSaladCloudTranscriptionAPIJob = {input: SaladCloudTranscriptionAPIInput, metadata?: (Record | null) | undefined, webhook?: (string | null) | undefined}; export type CreateApiOrganizationsOrganizationNameInferenceEndpointsTranscribeJobsArgs = {body: CreateSaladCloudTranscriptionAPIJob}; export type CreateApiOrganizationsOrganizationNameInferenceEndpointsTranscribeJobsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const saladCloudTranscriptionAPIInput = z.object({url: z.string(), language_code: z.enum(["en", "zh", "de", "es", "ru", "ko", "fr", "ja", "pt", "tr", "pl", "ca", "nl", "ar", "sv", "it", "id", "hi", "fi", "vi", "he", "uk", "el", "ms", "cs", "ro", "da", "hu", "ta", "no", "th", "ur", "hr", "bg", "lt", "la", "mi", "ml", "cy", "sk", "te", "fa", "lv", "bn", "sr", "az", "sl", "kn", "et", "mk", "br", "eu", "is", "hy", "ne", "mn", "bs", "kk", "sq", "sw", "gl", "mr", "pa", "si", "km", "sn", "yo", "so", "af", "oc", "ka", "be", "tg", "sd", "gu", "am", "yi", "lo", "uz", "fo", "ht", "ps", "tk", "nn", "mt", "sa", "lb", "my", "bo", "tl", "mg", "as", "tt", "haw", "ln", "ha", "ba", "jw", "su", "yue"]).optional(), return_as_file: z.boolean().optional(), sentence_level_timestamps: z.boolean().optional(), word_level_timestamps: z.boolean().optional(), diarization: z.boolean().optional(), sentence_diarization: z.boolean().optional(), srt: z.boolean().optional(), translate: z.string().optional(), custom_prompt: z.string().optional(), summarize: z.number().int().optional(), llm_translation: z.string().optional(), srt_translation: z.string().optional(), custom_vocabulary: z.string().optional(), classification_labels: z.string().optional(), overall_classification: z.boolean().optional(), overall_sentiment_analysis: z.boolean().optional()}); export const inferenceEndpointJobEvent = z.object({action: z.enum(["created", "started", "succeeded", "cancelled", "failed"]), time: z.string()}); export const saladCloudTranscriptionAPIOutput = z.object({sentence_level_timestamps: z.array(z.object({text: z.string(), timestamp: z.array(z.number()).optional(), start: z.number(), end: z.number(), speaker: z.string(), sentiment: z.array(z.object({label: z.string().optional(), score: z.number().optional()})).optional(), classification: z.object({label: z.array(z.string()).optional(), scores: z.array(z.number()).optional()}).optional()})).optional(), word_segments: z.array(z.object({word: z.string(), start: z.number(), end: z.number(), score: z.number(), speaker: z.string()})).optional(), srt_content: z.string().optional(), summary: z.string().optional(), llm_translations: z.record(z.string(), z.string()).optional(), srt_translation: z.record(z.string(), z.string()).optional(), llm_result: z.string().optional(), overall_classification: z.string().optional(), overall_sentiment: z.string().optional(), text: z.string(), duration: z.number(), processing_time: z.number()}); export const saladCloudTranscriptionAPIJob = z.object({id: z.string(), input: saladCloudTranscriptionAPIInput, inference_endpoint_name: z.string(), metadata: z.object({}).nullable().optional(), webhook: z.string().nullable().optional(), status: z.enum(["pending", "running", "succeeded", "cancelled", "failed"]), events: z.array(inferenceEndpointJobEvent), organization_name: z.string(), output: saladCloudTranscriptionAPIOutput.optional(), create_time: z.string(), update_time: 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 }; /** * Create a job for Salad Transcription API * * POST /organizations/{organization_name}/inference-endpoints/transcribe/jobs */ export const createApiOrganizationsOrganizationNameInferenceEndpointsTranscribeJobs = async (args: CreateApiOrganizationsOrganizationNameInferenceEndpointsTranscribeJobsArgs, options?: CreateApiOrganizationsOrganizationNameInferenceEndpointsTranscribeJobsOptions) => { const {baseUrl = "https://api.salad.com/api/public", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Salad-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.organization_name))}/inference-endpoints/transcribe/jobs${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(saladCloudTranscriptionAPIJob, await res.json()) };