import {z} from 'zod' export type UpdateApiV2ClarityV2ProcessesProcessIdArtifactChatMessagesMessageIdArgs = {process_id: string, message_id: string, body: {decision: 'accept' | 'decline'}}; export type UpdateApiV2ClarityV2ProcessesProcessIdArtifactChatMessagesMessageIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const artifactChatJsonValue: z.ZodType = z.union([z.boolean(), z.number(), z.string(), z.array(z.lazy(() => artifactChatJsonValue)), z.record(z.string(), z.lazy(() => artifactChatJsonValue))]); export const updateApiV2ClarityV2ProcessesProcessIdArtifactChatMessagesMessageIdResponse = z.object({conversation: z.object({id: z.string(), user_id: z.string(), process_id: z.string(), snapshot_kind: z.enum(["current_process", "transformation_proposal"]), title: z.string().nullable(), sandbox_id: z.string().nullable(), session_id: z.string().nullable(), status: z.enum(["open", "running", "waiting_for_patch", "waiting_for_hitl"]), created_at: z.string(), updated_at: z.string(), deleted_at: z.string().nullable()}), message: z.object({id: z.string(), conversation_id: z.string(), role: z.enum(["user", "assistant", "system"]), kind: z.enum(["text", "patch", "hitl_question", "hitl_answer", "error", "info"]), body: z.union([z.object({kind: z.literal("text"), text: z.string()}), z.object({kind: z.literal("patch"), status: z.enum(["pending", "accepted", "declined", "failed"]), summary: z.string(), patch: z.array(z.union([z.object({op: z.enum(["add", "replace", "test"]), path: z.string(), value: artifactChatJsonValue}), z.object({op: z.literal("remove"), path: z.string()}), z.object({op: z.enum(["move", "copy"]), from: z.string(), path: z.string()})])), draft_snapshot_id: z.string().nullable().optional(), snapshot_id: z.string().nullable()}), z.object({kind: z.literal("hitl_question"), questions: z.array(z.object({question: z.string(), header: z.string(), options: z.array(z.object({label: z.string(), description: z.string()})), multiSelect: z.boolean()}))}), z.object({kind: z.literal("hitl_answer"), answers: z.record(z.string(), z.string())}), z.object({kind: z.literal("error"), text: z.string()}), z.object({kind: z.literal("info"), text: z.string()})]), baseline_snapshot_id: z.string(), created_at: z.string(), updated_at: z.string()})}); 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 }; /** * Accept or decline a persisted artifact-chat patch proposal. * * PUT /v2/clarity-v2/processes/{process_id}/artifact-chat/messages/{message_id} */ export const updateApiV2ClarityV2ProcessesProcessIdArtifactChatMessagesMessageId = async (args: UpdateApiV2ClarityV2ProcessesProcessIdArtifactChatMessagesMessageIdArgs, options?: UpdateApiV2ClarityV2ProcessesProcessIdArtifactChatMessagesMessageIdOptions) => { const {baseUrl = "https://api.duvo.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/clarity-v2/processes/${encodeURIComponent(String(args.process_id))}/artifact-chat/messages/${encodeURIComponent(String(args.message_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiV2ClarityV2ProcessesProcessIdArtifactChatMessagesMessageIdResponse, await res.json()) };