import {z} from 'zod' export type AIInsightSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, insightType?: boolean | undefined, status?: boolean | undefined, severity?: boolean | undefined, classification?: boolean | undefined, fingerprint?: boolean | undefined, title?: boolean | undefined, detailMarkdown?: boolean | undefined, serviceName?: boolean | undefined, telemetryServiceId?: boolean | undefined, telemetryExceptionId?: boolean | undefined, traceId?: boolean | undefined, metricName?: boolean | undefined, evidence?: boolean | undefined, firstSeenAt?: boolean | undefined, lastSeenAt?: boolean | undefined, occurrenceCount?: boolean | undefined, triageAiRunId?: boolean | undefined, fixAiRunId?: boolean | undefined, triageSummaryMarkdown?: boolean | undefined, triageCompletedAt?: boolean | undefined, humanVerdict?: boolean | undefined, humanVerdictAt?: boolean | undefined, humanVerdictByUserId?: boolean | undefined}; export type CreateApiAiInsightIdGetItemArgs = {id: string, body: {select?: AIInsightSelectSchema | undefined}}; export type CreateApiAiInsightIdGetItemOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const aIInsight = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), version: z.number().optional(), projectId: z.string(), insightType: z.enum(["NewException", "ExceptionSpike", "ErrorLogSpike", "TraceLatencyRegression", "MetricDrift", "DataDrift", "DeployRegression", "ProfileHotspot", "TraceSlowOperation", "TraceFailingOperation", "TraceMissingTracing", "ExceptionMissingStackTrace", "LogErrorPattern", "LogMissingLogging", "LogNoisyPattern", "MetricHighCardinality", "MetricHistogramBuckets", "MetricMissingMetrics", "MetricMissingRequestMetrics"]), status: z.enum(["Detected", "ActionRequired", "FixOpened", "Resolved", "Dismissed"]), severity: z.enum(["High", "Medium", "Low"]), classification: z.string().optional(), fingerprint: z.string(), title: z.string(), detailMarkdown: z.string(), serviceName: z.string().optional(), telemetryServiceId: z.string().optional(), telemetryExceptionId: z.string().optional(), traceId: z.string().optional(), metricName: z.string().optional(), evidence: z.object({}).optional(), firstSeenAt: z.object({}), lastSeenAt: z.object({}), occurrenceCount: z.number(), triageAiRunId: z.string().optional(), fixAiRunId: z.string().optional(), triageSummaryMarkdown: z.string().optional(), triageCompletedAt: z.object({}).optional(), humanVerdict: z.enum(["Confirmed", "Dismissed"]).optional(), humanVerdictAt: z.object({}).optional(), humanVerdictByUserId: z.string().optional()}); export const createApiAiInsightIdGetItemResponse = z.object({data: aIInsight.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 AI Insight * * POST /ai-insight/{id}/get-item */ export const createApiAiInsightIdGetItem = async (args: CreateApiAiInsightIdGetItemArgs, options?: CreateApiAiInsightIdGetItemOptions) => { const {baseUrl = "https://oneuptime.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/ai-insight/${encodeURIComponent(String(args.id))}/get-item${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(createApiAiInsightIdGetItemResponse, await res.json()) };