import {z} from 'zod' export type GetApiApiMyWorkflowsWorkflowIdRunsArgs = {workflowId: string, Authorization?: string | undefined, 'Credimi-Api-Key'?: string | undefined}; export type GetApiApiMyWorkflowsWorkflowIdRunsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const handlersWorkflowIdentifier = z.object({runId: z.string().optional(), workflowId: z.string().optional()}); export const handlersWorkflowQueueSummary = z.object({device_ids: z.array(z.string()).optional(), line_len: z.number().int().optional(), position: z.number().int().optional(), ticket_id: z.string().optional()}); export const pipelineResultsPipelineResults = z.object({log: z.string().optional(), screenshot: z.string().optional(), timeline: z.string().optional(), video: z.string().optional()}); export const handlersWorkflowType = z.object({name: z.string().optional()}); export const handlersWorkflowExecutionSummary: z.ZodType = z.object({attempt: z.number().int().optional(), children: z.array(z.lazy(() => handlersWorkflowExecutionSummary)).optional(), displayName: z.string().optional(), duration: z.string().optional(), endTime: z.string().optional(), enqueuedAt: z.string().optional(), execution: handlersWorkflowIdentifier.optional(), failure_reason: z.string().nullable().optional(), fcaf_report: z.string().optional(), fcaf_report_pdf: z.string().optional(), has_logs: z.boolean().optional(), has_qr: z.boolean().optional(), maestro_screenshots: z.array(z.string()).optional(), max_attempts: z.number().int().optional(), queue: handlersWorkflowQueueSummary.optional(), report: z.string().optional(), results: z.array(pipelineResultsPipelineResults).optional(), startTime: z.string().optional(), status: z.string().optional(), type: handlersWorkflowType.optional()}); export const handlersListMyWorkflowRunsResponse = z.object({executions: z.array(handlersWorkflowExecutionSummary).nullable().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 a list of all runs for a specific workflow * * GET /api/my/workflows/{workflowId}/runs */ export const getApiApiMyWorkflowsWorkflowIdRuns = async (args: GetApiApiMyWorkflowsWorkflowIdRunsArgs, options?: GetApiApiMyWorkflowsWorkflowIdRunsOptions) => { const {baseUrl = "https://credimi.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args['Credimi-Api-Key'] != null) headers.set("Credimi-Api-Key", String(args['Credimi-Api-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/my/workflows/${encodeURIComponent(String(args.workflowId))}/runs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(handlersListMyWorkflowRunsResponse, await res.json()) };