import {z} from 'zod' export type CompleteRequest = {status: 'ready' | 'partial' | 'needs_review', provider: string, provider_version?: (string | null) | undefined, provider_request_id?: (string | null) | undefined, data?: {[key: string]: unknown} | undefined, citations?: Array<{[key: string]: unknown}> | undefined, cost_usd?: (number | string) | undefined, claim_token: string}; export type CreateApiV1InternalDiligenceJobsJobIdStepsStepCompleteArgs = {job_id: string, step: string, authorization?: (string | null) | undefined, 'X-Tenant'?: (string | null) | undefined, body: CompleteRequest}; export type CreateApiV1InternalDiligenceJobsJobIdStepsStepCompleteOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiV1InternalDiligenceJobsJobIdStepsStepCompleteResponse = z.record(z.string(), z.unknown()); 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 }; /** * Complete * * POST /v1/internal/diligence/jobs/{job_id}/steps/{step}/complete */ export const createApiV1InternalDiligenceJobsJobIdStepsStepComplete = async (args: CreateApiV1InternalDiligenceJobsJobIdStepsStepCompleteArgs, options: CreateApiV1InternalDiligenceJobsJobIdStepsStepCompleteOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.authorization != null) headers.set("authorization", String(args.authorization)) if (args['X-Tenant'] != null) headers.set("X-Tenant", String(args['X-Tenant'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/internal/diligence/jobs/${encodeURIComponent(String(args.job_id))}/steps/${encodeURIComponent(String(args.step))}/complete${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(createApiV1InternalDiligenceJobsJobIdStepsStepCompleteResponse, await res.json()) };