import {z} from 'zod' export type AIAgentTaskPullRequestSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, aiRunId?: boolean | undefined, aiAgentId?: boolean | undefined, codeRepositoryId?: boolean | undefined, title?: boolean | undefined, description?: boolean | undefined, pullRequestUrl?: boolean | undefined, pullRequestId?: boolean | undefined, pullRequestNumber?: boolean | undefined, pullRequestState?: boolean | undefined, ciStatus?: boolean | undefined, ciStatusAt?: boolean | undefined, runnerVerificationStatus?: boolean | undefined, runnerVerificationSummary?: boolean | undefined, mergeCommitSha?: boolean | undefined, mergedAt?: boolean | undefined, productionStatus?: boolean | undefined, productionStatusAt?: boolean | undefined, deployedAt?: boolean | undefined, deployedVersion?: boolean | undefined, deployedCommitSha?: boolean | undefined, productionSummary?: boolean | undefined, productionCheck?: boolean | undefined, headRefName?: boolean | undefined, baseRefName?: boolean | undefined, repoOrganizationName?: boolean | undefined, repoName?: boolean | undefined, createdByUserId?: boolean | undefined}; export type CreateApiAiAgentTaskPullRequestIdGetItemArgs = {id: string, body: {select?: AIAgentTaskPullRequestSelectSchema | undefined}}; export type CreateApiAiAgentTaskPullRequestIdGetItemOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const aIAgentTaskPullRequest = 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(), aiRunId: z.string().optional(), aiAgentId: z.string().optional(), codeRepositoryId: z.string().optional(), title: z.string(), description: z.string().optional(), pullRequestUrl: z.string().optional(), pullRequestId: z.number().optional(), pullRequestNumber: z.number().optional(), pullRequestState: z.enum(["open", "closed", "merged"]), ciStatus: z.enum(["Pending", "Green", "Red", "ExpectedFailureObserved", "NoCiConfigured"]).optional(), ciStatusAt: z.object({}).optional(), runnerVerificationStatus: z.enum(["Passed", "Failed", "Skipped"]).optional(), runnerVerificationSummary: z.string().optional(), mergeCommitSha: z.string().optional(), mergedAt: z.object({}).optional(), productionStatus: z.enum(["AwaitingDeploy", "Watching", "Verified", "Regressed", "Unverifiable"]).optional(), productionStatusAt: z.object({}).optional(), deployedAt: z.object({}).optional(), deployedVersion: z.string().optional(), deployedCommitSha: z.string().optional(), productionSummary: z.string().optional(), productionCheck: z.enum(["Exception", "Performance", "Recurrence", "Telemetry"]).optional(), headRefName: z.string().optional(), baseRefName: z.string().optional(), repoOrganizationName: z.string().optional(), repoName: z.string().optional(), createdByUserId: z.string().optional()}); export const createApiAiAgentTaskPullRequestIdGetItemResponse = z.object({data: aIAgentTaskPullRequest.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 Agent Task Pull Request * * POST /ai-agent-task-pull-request/{id}/get-item */ export const createApiAiAgentTaskPullRequestIdGetItem = async (args: CreateApiAiAgentTaskPullRequestIdGetItemArgs, options?: CreateApiAiAgentTaskPullRequestIdGetItemOptions) => { 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-agent-task-pull-request/${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(createApiAiAgentTaskPullRequestIdGetItemResponse, await res.json()) };