import {z} from 'zod' export type GetApiApiRegistryAgentsEncodedUrlStoryboardStatusArgs = {encodedUrl: string}; export type GetApiApiRegistryAgentsEncodedUrlStoryboardStatusOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const storyboardSkippedStep = z.object({step_id: z.string().nullable(), title: z.string().nullable(), task: z.string().nullable(), reason: z.string().nullable(), detail: z.string().nullable(), blocked_by_step_id: z.string().nullable(), blocked_by_step_title: z.string().nullable(), blocked_by_reason: z.string().nullable()}); export const storyboardStatus = z.object({storyboard_id: z.string(), requested_compliance_target: z.string().nullable().optional(), adcp_version: z.string().nullable().optional(), title: z.string(), category: z.string().nullable(), track: z.string().nullable(), status: z.enum(["passing", "failing", "partial", "untested"]), steps_passed: z.number().int(), steps_total: z.number().int(), failure_count: z.number().int(), skipped_count: z.number().int(), first_failed_step_id: z.string().nullable(), first_failed_step_title: z.string().nullable(), first_failed_step_task: z.string().nullable(), first_failure_message: z.string().nullable(), skipped_steps: z.array(storyboardSkippedStep), last_tested_at: z.string().nullable(), last_passed_at: z.string().nullable()}); export const getApiApiRegistryAgentsEncodedUrlStoryboardStatusResponse = z.object({agent_url: z.string(), storyboards: z.array(storyboardStatus), passing_count: z.number().int(), total_count: 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 agent storyboard status * * GET /api/registry/agents/{encodedUrl}/storyboard-status * * Also accepts auth: oauth2 */ export const getApiApiRegistryAgentsEncodedUrlStoryboardStatus = async (args: GetApiApiRegistryAgentsEncodedUrlStoryboardStatusArgs, options?: GetApiApiRegistryAgentsEncodedUrlStoryboardStatusOptions) => { const {baseUrl = "https://agenticadvertising.org", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/registry/agents/${encodeURIComponent(String(args.encodedUrl))}/storyboard-status${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(getApiApiRegistryAgentsEncodedUrlStoryboardStatusResponse, await res.json()) };