import {z} from 'zod' export type GetApiApiV1SessionsSessionIdInsightsConfigsArgs = {session_id: string, include_prebuilts?: boolean | undefined}; export type GetApiApiV1SessionsSessionIdInsightsConfigsOptions = {baseUrl: string, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const savedRunClusteringJobRequest = z.object({name: z.string().nullable(), last_n_hours: z.number().int().nullable().optional(), start_time: z.string().nullable().optional(), end_time: z.string().nullable().optional(), hierarchy: z.array(z.number().int()).nullable(), partitions: z.record(z.string(), z.string()).nullable(), sample: z.union([z.number(), z.number().int()]).nullable(), summary_prompt: z.string().nullable(), filter: z.string().nullable(), attribute_schemas: z.record(z.string(), z.unknown()).nullable(), user_context: z.record(z.string(), z.string()).nullable().optional(), model: z.enum(["openai", "anthropic"]), cluster_model: z.string().nullable().optional(), summary_model: z.string().nullable().optional()}); export const clusteringJobConfigResponse = z.object({id: z.union([z.string(), z.string()]), name: z.string(), description: z.string().nullable().optional(), config: savedRunClusteringJobRequest, prebuilt: z.boolean(), schedule_cron: z.string().nullable().optional()}); export const getClusteringJobConfigsResponse = z.object({configs: z.array(clusteringJobConfigResponse)}); 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 }; /** * [Beta] Get Insights Job Configs * * GET /api/v1/sessions/{session_id}/insights/configs * * Also accepts auth: Tenant ID, Bearer Auth */ export const getApiApiV1SessionsSessionIdInsightsConfigs = async (args: GetApiApiV1SessionsSessionIdInsightsConfigsArgs, options: GetApiApiV1SessionsSessionIdInsightsConfigsOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include_prebuilts != null) query.append("include_prebuilts", String(args.include_prebuilts)) if (APIKey !== undefined) headers.set("X-API-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/sessions/${encodeURIComponent(String(args.session_id))}/insights/configs${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(getClusteringJobConfigsResponse, await res.json()) };