import {z} from 'zod' export type RunnerRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, lastAlive?: boolean | undefined, connectionStatus?: boolean | undefined, isGlobalRunner?: boolean | undefined}; export type MonitorRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, monitorTemplateId?: boolean | undefined, autoProvisionedNetworkDeviceId?: boolean | undefined, networkAlertPolicyId?: boolean | undefined, monitorType?: boolean | undefined, currentMonitorStatusId?: boolean | undefined, monitorSteps?: boolean | undefined}; export type IncidentSeverityRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, color?: boolean | undefined, order?: boolean | undefined, isArchived?: boolean | undefined}; export type AlertSeverityRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, color?: boolean | undefined, order?: boolean | undefined, isArchived?: boolean | undefined}; export type LabelRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, name?: boolean | undefined, projectId?: boolean | undefined, color?: boolean | undefined, isArchived?: boolean | undefined}; export type ServiceRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, description?: boolean | undefined, serviceColor?: boolean | undefined, serviceLanguage?: boolean | undefined, techStack?: boolean | undefined, lastSeenAt?: boolean | undefined, serviceVersion?: boolean | undefined, deploymentEnvironment?: boolean | undefined, serviceNamespace?: boolean | undefined, runtimeName?: boolean | undefined, runtimeVersion?: boolean | undefined, telemetrySdkLanguage?: boolean | undefined, cloudProvider?: boolean | undefined, cloudPlatform?: boolean | undefined, cloudRegion?: boolean | undefined, cloudAccountId?: boolean | undefined}; export type RunbookRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined}; export type ExternalMcpServerRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, isEnabled?: boolean | undefined}; export type CodeRepositoryRelationSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, repositoryHostedAt?: boolean | undefined, organizationName?: boolean | undefined, repositoryName?: boolean | undefined, mainBranchName?: boolean | undefined, runnerId?: boolean | undefined, productionReviewLlmProviderId?: boolean | undefined, repositoryUrl?: boolean | undefined}; export type AutoRemediationRuleSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, criteria?: boolean | undefined, projectId?: boolean | undefined, name?: boolean | undefined, description?: boolean | undefined, isEnabled?: boolean | undefined, triggerEntityType?: boolean | undefined, investigates?: boolean | undefined, onlyIfOpenAfterMinutes?: boolean | undefined, fixes?: boolean | undefined, executionMode?: boolean | undefined, remediationAction?: boolean | undefined, aiSelectsRunbook?: boolean | undefined, aiComposesCommands?: boolean | undefined, commandAllowlist?: boolean | undefined, commandRunners?: RunnerRelationSelectSchema | undefined, monitors?: MonitorRelationSelectSchema | undefined, incidentSeverities?: IncidentSeverityRelationSelectSchema | undefined, alertSeverities?: AlertSeverityRelationSelectSchema | undefined, labels?: LabelRelationSelectSchema | undefined, monitorLabels?: LabelRelationSelectSchema | undefined, titlePattern?: boolean | undefined, descriptionPattern?: boolean | undefined, services?: ServiceRelationSelectSchema | undefined, serviceLabels?: LabelRelationSelectSchema | undefined, serviceNamePattern?: boolean | undefined, runbooks?: RunbookRelationSelectSchema | undefined, externalMcpServers?: ExternalMcpServerRelationSelectSchema | undefined, runnerId?: boolean | undefined, codeRepositories?: CodeRepositoryRelationSelectSchema | undefined, llmProviderId?: boolean | undefined, aiContext?: boolean | undefined, openCodeFixPullRequests?: boolean | undefined, openTelemetryPullRequests?: boolean | undefined, verificationWindowMinutes?: boolean | undefined, autoResolveOnVerifiedRecovery?: boolean | undefined, createdByUserId?: boolean | undefined}; export type CreateApiAutoRemediationRuleIdGetItemArgs = {id: string, body: {select?: AutoRemediationRuleSelectSchema | undefined}}; export type CreateApiAutoRemediationRuleIdGetItemOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const autoRemediationRule = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), version: z.number().optional(), criteria: z.object({}).optional(), projectId: z.string(), name: z.string(), description: z.string().optional(), isEnabled: z.boolean(), triggerEntityType: z.enum(["Incident", "Alert", "Profile", "Trace", "Exception", "Log", "Metric"]), investigates: z.boolean(), onlyIfOpenAfterMinutes: z.number().optional(), fixes: z.boolean(), executionMode: z.enum(["Suggest", "FullAuto"]), remediationAction: z.enum(["OneUptimeAI", "Runbooks"]), aiSelectsRunbook: z.boolean(), aiComposesCommands: z.boolean(), commandAllowlist: z.object({}).optional(), commandRunners: z.array(z.object({_id: z.string().optional()})).optional(), monitors: z.array(z.object({_id: z.string().optional()})).optional(), incidentSeverities: z.array(z.object({_id: z.string().optional()})).optional(), alertSeverities: z.array(z.object({_id: z.string().optional()})).optional(), labels: z.array(z.object({_id: z.string().optional()})).optional(), monitorLabels: z.array(z.object({_id: z.string().optional()})).optional(), titlePattern: z.string().optional(), descriptionPattern: z.string().optional(), services: z.array(z.object({_id: z.string().optional()})).optional(), serviceLabels: z.array(z.object({_id: z.string().optional()})).optional(), serviceNamePattern: z.string().optional(), runbooks: z.array(z.object({_id: z.string().optional()})).optional(), externalMcpServers: z.array(z.object({_id: z.string().optional()})).optional(), runnerId: z.string().optional(), codeRepositories: z.array(z.object({_id: z.string().optional()})).optional(), llmProviderId: z.string().optional(), aiContext: z.string().optional(), openCodeFixPullRequests: z.boolean(), openTelemetryPullRequests: z.boolean(), verificationWindowMinutes: z.number().optional(), autoResolveOnVerifiedRecovery: z.boolean(), createdByUserId: z.string().optional()}); export const createApiAutoRemediationRuleIdGetItemResponse = z.object({data: autoRemediationRule.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 Rule * * POST /auto-remediation-rule/{id}/get-item */ export const createApiAutoRemediationRuleIdGetItem = async (args: CreateApiAutoRemediationRuleIdGetItemArgs, options?: CreateApiAutoRemediationRuleIdGetItemOptions) => { 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(/\/+$/, '')}/auto-remediation-rule/${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(createApiAutoRemediationRuleIdGetItemResponse, await res.json()) };