import {z} from 'zod' export type GetApiPublicV2ProjectsProjectIdFeedbackTemplatesTemplateIdArgs = {project_id: unknown, template_id: unknown}; export type GetApiPublicV2ProjectsProjectIdFeedbackTemplatesTemplateIdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const libsPythonSchemasLogRecordsFeedbackLikeDislikeConstraints = z.object({feedback_type: z.literal("like_dislike")}); export const libsPythonSchemasLogRecordsFeedbackStarConstraints = z.object({feedback_type: z.literal("star")}); export const libsPythonSchemasLogRecordsFeedbackScoreConstraints = z.object({feedback_type: z.literal("score"), min: z.number().int().gte(0), max: z.number().int().gte(0)}); export const libsPythonSchemasLogRecordsFeedbackTagsConstraints = z.object({feedback_type: z.literal("tags"), tags: z.array(z.string().min(1).max(255)), allow_other: z.boolean().optional()}); export const libsPythonSchemasLogRecordsFeedbackTextConstraints = z.object({feedback_type: z.literal("text")}); export const libsPythonSchemasLogRecordsFeedbackChoiceConstraints = z.object({feedback_type: z.literal("choice"), choices: z.array(z.string().min(1).max(255)), allow_other: z.boolean().optional()}); export const libsPythonSchemasLogRecordsFeedbackTreeChoiceNodeOutput: z.ZodType = z.object({label: z.string().min(1).max(255).nullable().optional(), value: z.string().min(1), children: z.array(z.lazy(() => libsPythonSchemasLogRecordsFeedbackTreeChoiceNodeOutput)).optional()}); export const treeChoiceConstraintsOutput = z.object({feedback_type: z.literal("tree_choice"), choices_tree: z.array(libsPythonSchemasLogRecordsFeedbackTreeChoiceNodeOutput)}); export const feedbackTemplateDB = z.object({name: z.string().min(1).max(255), include_explanation: z.boolean(), criteria: z.string().min(1).nullable().optional(), constraints: z.discriminatedUnion("feedback_type", [libsPythonSchemasLogRecordsFeedbackLikeDislikeConstraints, libsPythonSchemasLogRecordsFeedbackStarConstraints, libsPythonSchemasLogRecordsFeedbackScoreConstraints, libsPythonSchemasLogRecordsFeedbackTagsConstraints, libsPythonSchemasLogRecordsFeedbackTextConstraints, libsPythonSchemasLogRecordsFeedbackChoiceConstraints, treeChoiceConstraintsOutput]), id: z.string(), created_at: z.string(), created_by: z.string().nullable(), position: z.number().int(), usage_count: z.number().int().nullable().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 }; /** * Get Feedback Template V2 * * GET /public/v2/projects/{project_id}/feedback/templates/{template_id} * * Also accepts auth: ClassicAPIKeyHeader, OAuth2PasswordBearer, HTTPBasic */ export const getApiPublicV2ProjectsProjectIdFeedbackTemplatesTemplateId = async (args: GetApiPublicV2ProjectsProjectIdFeedbackTemplatesTemplateIdArgs, options?: GetApiPublicV2ProjectsProjectIdFeedbackTemplatesTemplateIdOptions) => { const {baseUrl = "https://api.galileo.ai", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("Splunk-AO-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/public/v2/projects/${encodeURIComponent(String(args.project_id))}/feedback/templates/${encodeURIComponent(String(args.template_id))}${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(feedbackTemplateDB, await res.json()) };