import {z} from 'zod' export type TaskTypeEnum = 'post-plan' | 'post-apply'; export type ChangedCodeFilters = {taskId?: Array | undefined, suffix?: Array | undefined, taskType?: Array | undefined, filePath?: Array | undefined}; export type SortConfig = {order?: (-1 | 1) | undefined}; export type ChangedCodeSortField = {taskType?: SortConfig | undefined, suffix?: SortConfig | undefined, updatedAt?: SortConfig | undefined}; export type ListRunChangedCodeRequest = {projection?: Array | undefined, searchValue?: string | undefined, filters?: ({taskId?: Array | undefined, suffix?: Array | undefined, taskType?: Array | undefined, filePath?: Array | undefined, $or?: ChangedCodeFilters | undefined}) | undefined, sort?: ChangedCodeSortField | undefined}; export type CreateApiWorkspacesWorkspaceIdRunsRunIdChangedFilesCodeSearchArgs = {page?: number | undefined, pageSize?: number | undefined, body: ListRunChangedCodeRequest}; export type CreateApiWorkspacesWorkspaceIdRunsRunIdChangedFilesCodeSearchOptions = {baseUrl?: string | undefined, JWTAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const changedFileResponse = z.object({id: z.string().optional(), filePath: z.string().optional(), folderPath: z.string().optional(), fileSuffix: z.string().optional(), content: z.string().optional(), changes: z.object({additions: z.number().int().optional(), deletions: z.number().int().optional(), diff: z.string().optional()}).optional()}); export const listRunChangedCodeResponse = z.record(z.string(), z.array(changedFileResponse)); 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 }; /** * List run changed code * * POST /workspaces/{workspaceId}/runs/{runId}/changed-files-code/search */ export const createApiWorkspacesWorkspaceIdRunsRunIdChangedFilesCodeSearch = async (args: CreateApiWorkspacesWorkspaceIdRunsRunIdChangedFilesCodeSearchArgs, options?: CreateApiWorkspacesWorkspaceIdRunsRunIdChangedFilesCodeSearchOptions) => { const {baseUrl = "https://api.firefly.ai/v2", fetch: fetchFn = fetch, JWTAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (JWTAuth !== undefined) headers.set('authorization', `Bearer ${JWTAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/workspaces/${encodeURIComponent(String(args.workspaceId))}/runs/${encodeURIComponent(String(args.runId))}/changed-files-code/search${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(listRunChangedCodeResponse, await res.json()) };