import {z} from 'zod' export type GetApiPublicV2ProjectsProjectIdAnnotationTemplatesTemplateIdArgs = {project_id: unknown, template_id: unknown}; export type GetApiPublicV2ProjectsProjectIdAnnotationTemplatesTemplateIdOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const apiSchemasAnnotationLikeDislikeConstraints = z.object({annotation_type: z.literal("like_dislike")}); export const apiSchemasAnnotationStarConstraints = z.object({annotation_type: z.literal("star")}); export const apiSchemasAnnotationScoreConstraints = z.object({annotation_type: z.literal("score"), min: z.number().int().gte(0), max: z.number().int().gte(0)}); export const apiSchemasAnnotationTagsConstraints = z.object({annotation_type: z.literal("tags"), tags: z.array(z.string().min(1).max(255)), allow_other: z.boolean().optional()}); export const apiSchemasAnnotationTextConstraints = z.object({annotation_type: z.literal("text")}); export const apiSchemasAnnotationChoiceConstraints = z.object({annotation_type: z.literal("choice"), choices: z.array(z.string().min(1).max(255)), allow_other: z.boolean().optional()}); export const apiSchemasAnnotationTreeChoiceNodeOutput: z.ZodType = z.object({label: z.string().min(1).max(255), id: z.string().min(1).max(255), children: z.array(z.lazy(() => apiSchemasAnnotationTreeChoiceNodeOutput)).optional()}); export const treeChoiceDBConstraints = z.object({annotation_type: z.literal("tree_choice"), choices_tree: z.array(apiSchemasAnnotationTreeChoiceNodeOutput), choices_tree_yaml: z.string().min(1).max(10000)}); export const annotationTemplateDB = z.object({name: z.string().min(1).max(255), include_explanation: z.boolean(), criteria: z.string().min(1).nullable().optional(), constraints: z.discriminatedUnion("annotation_type", [apiSchemasAnnotationLikeDislikeConstraints, apiSchemasAnnotationStarConstraints, apiSchemasAnnotationScoreConstraints, apiSchemasAnnotationTagsConstraints, apiSchemasAnnotationTextConstraints, apiSchemasAnnotationChoiceConstraints, treeChoiceDBConstraints]), id: z.string(), created_at: z.string(), created_by: z.string().nullable(), position: z.number().int(), usage_count: z.number().int()}); 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 Annotation Template * * GET /public/v2/projects/{project_id}/annotation/templates/{template_id} * * Also accepts auth: ClassicAPIKeyHeader, OAuth2PasswordBearer, HTTPBasic */ export const getApiPublicV2ProjectsProjectIdAnnotationTemplatesTemplateId = async (args: GetApiPublicV2ProjectsProjectIdAnnotationTemplatesTemplateIdArgs, options?: GetApiPublicV2ProjectsProjectIdAnnotationTemplatesTemplateIdOptions) => { 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))}/annotation/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(annotationTemplateDB, await res.json()) };