import {z} from 'zod' export type AIAgentTaskPullRequestCreateSchema = {projectId?: string | undefined, aiRunId?: string | undefined, aiAgentId?: string | undefined, codeRepositoryId?: string | undefined, title: string, description?: string | undefined, pullRequestUrl?: string | undefined, pullRequestId?: number | undefined, pullRequestNumber?: number | undefined, pullRequestState: 'open' | 'closed' | 'merged', headRefName?: string | undefined, baseRefName?: string | undefined, repoOrganizationName?: string | undefined, repoName?: string | undefined}; export type CreateApiAiAgentTaskPullRequestArgs = {body: {data: AIAgentTaskPullRequestCreateSchema}}; export type CreateApiAiAgentTaskPullRequestOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const aIAgentTaskPullRequestReadSchema = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), projectId: z.string().optional(), 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 createApiAiAgentTaskPullRequestResponse = z.object({data: aIAgentTaskPullRequestReadSchema.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 }; /** * Create AI Agent Task Pull Request * * POST /ai-agent-task-pull-request */ export const createApiAiAgentTaskPullRequest = async (args: CreateApiAiAgentTaskPullRequestArgs, options?: CreateApiAiAgentTaskPullRequestOptions) => { 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${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(createApiAiAgentTaskPullRequestResponse, await res.json()) };