import {z} from 'zod' export type GetApiApiWorkflowExecuteNameArgs = {name: string, version?: number | undefined, requestId?: string | undefined, waitUntilTaskRef?: string | undefined, waitForSeconds?: number | undefined, 'X-Idempotency-key'?: string | undefined, 'X-on-conflict'?: ('FAIL' | 'RETURN_EXISTING' | 'FAIL_ON_RUNNING') | undefined}; export type GetApiApiWorkflowExecuteNameOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiWorkflowExecuteNameResponse = z.record(z.string(), z.object({})); 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 }; /** * Execute a workflow synchronously with input and outputs using get api * * GET /api/workflow/execute/{name} */ export const getApiApiWorkflowExecuteName = async (args: GetApiApiWorkflowExecuteNameArgs, options?: GetApiApiWorkflowExecuteNameOptions) => { const {baseUrl = "https://developer.orkescloud.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.version != null) query.append("version", String(args.version)) if (args.requestId != null) headers.set("requestId", String(args.requestId)) if (args.waitUntilTaskRef != null) headers.set("waitUntilTaskRef", String(args.waitUntilTaskRef)) if (args.waitForSeconds != null) query.append("waitForSeconds", String(args.waitForSeconds)) if (args['X-Idempotency-key'] != null) headers.set("X-Idempotency-key", String(args['X-Idempotency-key'])) if (args['X-on-conflict'] != null) headers.set("X-on-conflict", String(args['X-on-conflict'])) if (apiKey !== undefined) headers.set("X-Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/workflow/execute/${encodeURIComponent(String(args.name))}${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(getApiApiWorkflowExecuteNameResponse, await res.json()) };