import {z} from 'zod' export type GetApiApiV1WorkflowWorkflowIdRunsArgs = {workflow_id: string, page?: number | undefined, size?: number | undefined}; export type GetApiApiV1WorkflowWorkflowIdRunsOptions = {baseUrl: string, YourAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const iWorkflowRunStatusEnum = z.enum(["running", "waiting", "done", "failed", "cancelled"]); export const iWorkflowRunRead = z.object({workflow_id: z.string(), workflow_version: z.number().int().optional(), trigger_payload: z.record(z.string(), z.unknown()).optional(), context: z.record(z.string(), z.unknown()).optional(), current_node_id: z.string().nullable().optional(), status: iWorkflowRunStatusEnum.optional(), started_at: z.string().nullable().optional(), finished_at: z.string().nullable().optional(), error: z.string().nullable().optional(), id: z.string(), created_at: z.string().nullable().optional()}); export const pageBaseIWorkflowRunRead = z.object({items: z.array(iWorkflowRunRead), total: z.number().int().gte(0).nullable(), page: z.number().int().gte(1).nullable(), size: z.number().int().gte(1).nullable(), pages: z.number().int().gte(0).nullable().optional(), previous_page: z.number().int().nullable().optional(), next_page: z.number().int().nullable().optional()}); export const iGetResponsePaginatedIWorkflowRunRead = z.object({message: z.string().nullable().optional(), meta: z.record(z.string(), z.unknown()).optional(), data: pageBaseIWorkflowRunRead}); 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 Runs * * GET /api/v1/workflow/{workflow_id}/runs * * Also accepts auth: HTTPBearer */ export const getApiApiV1WorkflowWorkflowIdRuns = async (args: GetApiApiV1WorkflowWorkflowIdRunsArgs, options: GetApiApiV1WorkflowWorkflowIdRunsOptions) => { const {baseUrl, fetch: fetchFn = fetch, YourAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (YourAPIKey !== undefined) query.set("api_key", YourAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/workflow/${encodeURIComponent(String(args.workflow_id))}/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(iGetResponsePaginatedIWorkflowRunRead, await res.json()) };