import {z} from 'zod' export type GetApiV1WorkspacesWorkspaceTriggersTriggerIdExecutionsArgs = {trigger_id: string, workspace: string, page?: number | undefined, page_size?: number | undefined, status?: (string | null) | undefined, start_time?: (string | null) | undefined, end_time?: (string | null) | undefined}; export type GetApiV1WorkspacesWorkspaceTriggersTriggerIdExecutionsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const triggerExecutionResponse = z.object({cost_usd: z.number().nullable().optional(), error_message: z.string().nullable().optional(), executed_at: z.string(), execution_time_ms: z.number().int(), fired_by: z.string().nullable().optional(), id: z.string(), run_id: z.string().nullable().optional(), status: z.string(), task_id: z.string().nullable().optional(), trigger_data: z.record(z.string(), z.unknown()), trigger_id: z.string(), workflow_id: z.string().nullable().optional()}); export const executionHistoryResponse = z.object({executions: z.array(triggerExecutionResponse), has_next: z.boolean(), page: z.number().int(), page_size: z.number().int(), total: z.number().int()}); 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 Execution History * * GET /v1/workspaces/{workspace}/triggers/{trigger_id}/executions */ export const getApiV1WorkspacesWorkspaceTriggersTriggerIdExecutions = async (args: GetApiV1WorkspacesWorkspaceTriggersTriggerIdExecutionsArgs, options: GetApiV1WorkspacesWorkspaceTriggersTriggerIdExecutionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = 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.page_size != null) query.append("page_size", String(args.page_size)) if (args.status != null) query.append("status", String(args.status)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.workspace))}/triggers/${encodeURIComponent(String(args.trigger_id))}/executions${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(executionHistoryResponse, await res.json()) };