import {z} from 'zod' export type ApiSchemasAnnotationLikeDislikeRating = {annotation_type?: 'like_dislike' | undefined, value: boolean}; export type ApiSchemasAnnotationStarRating = {annotation_type?: 'star' | undefined, value: number}; export type ApiSchemasAnnotationScoreRating = {annotation_type?: 'score' | undefined, value: number}; export type ApiSchemasAnnotationTagsRating = {annotation_type?: 'tags' | undefined, value: Array}; export type ApiSchemasAnnotationTextRating = {annotation_type?: 'text' | undefined, value: string}; export type ApiSchemasAnnotationChoiceRating = {annotation_type?: 'choice' | undefined, value: string}; export type ApiSchemasAnnotationTreeChoiceRating = {annotation_type?: 'tree_choice' | undefined, value: string}; export type BulkAnnotationRatingCreate = {explanation?: (string | null) | undefined, rating: ApiSchemasAnnotationLikeDislikeRating | ApiSchemasAnnotationStarRating | ApiSchemasAnnotationScoreRating | ApiSchemasAnnotationTagsRating | ApiSchemasAnnotationTextRating | ApiSchemasAnnotationChoiceRating | ApiSchemasAnnotationTreeChoiceRating, annotation_template_id: unknown, operation_type?: 'create' | undefined}; export type BulkAnnotationRatingDelete = {annotation_template_id: unknown, operation_type?: 'delete' | undefined}; export type AnnotationTraceSelector = {selector_type?: 'traces' | undefined, traces: Array}; export type BulkAnnotationRequest = {operations: Array, selector: AnnotationTraceSelector}; export type CreateApiPublicV2ProjectsProjectIdAnnotationRatingsArgs = {project_id: unknown, body: BulkAnnotationRequest}; export type CreateApiPublicV2ProjectsProjectIdAnnotationRatingsOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const annotationSelectorType = z.literal("traces"); export const annotationRatingOperationType = z.enum(["create", "delete"]); export const bulkAnnotationRatingStatus = z.object({selector: annotationSelectorType.optional(), index: z.number().int().nullable().optional(), trace: z.string().nullable().optional(), operation: annotationRatingOperationType, success: z.boolean(), message: z.string().nullable()}); export const createApiPublicV2ProjectsProjectIdAnnotationRatingsResponse = z.array(bulkAnnotationRatingStatus); 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 }; /** * Apply Bulk Annotation * * POST /public/v2/projects/{project_id}/annotation/ratings * * Also accepts auth: ClassicAPIKeyHeader, OAuth2PasswordBearer, HTTPBasic */ export const createApiPublicV2ProjectsProjectIdAnnotationRatings = async (args: CreateApiPublicV2ProjectsProjectIdAnnotationRatingsArgs, options?: CreateApiPublicV2ProjectsProjectIdAnnotationRatingsOptions) => { const {baseUrl = "https://api.galileo.ai", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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/ratings${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(createApiPublicV2ProjectsProjectIdAnnotationRatingsResponse, await res.json()) };