import {z} from 'zod' export type CreateApiV2ArtifactsArtifactIdStopArgs = {artifactId: string, body: {partial_text?: string | undefined}}; export type CreateApiV2ArtifactsArtifactIdStopOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2ArtifactsArtifactIdStopResponse = z.object({artifact: z.object({id: z.string(), team_id: z.string(), created_by_user_id: z.string(), title: z.string().nullable(), html_code_present: z.boolean(), status: z.enum(["not_started", "pending", "running", "completed", "failed", "interrupted"]), visibility: z.enum(["private", "team", "organization", "teams"]), publish_permission: z.enum(["view", "edit"]), thumbnail_url: z.string().nullable().optional(), refresh_frequency: z.enum(["every_15_minutes", "every_30_minutes", "hourly", "every_6_hours", "daily", "weekly"]).nullable().optional(), last_refresh_at: z.string().nullable().optional(), next_refresh_at: z.string().nullable().optional(), 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 }; /** * Stop Pulse Dashboard Message * * POST /v2/artifacts/{artifactId}/stop */ export const createApiV2ArtifactsArtifactIdStop = async (args: CreateApiV2ArtifactsArtifactIdStopArgs, options?: CreateApiV2ArtifactsArtifactIdStopOptions) => { 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/artifacts/${encodeURIComponent(String(args.artifactId))}/stop${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(createApiV2ArtifactsArtifactIdStopResponse, await res.json()) };