import {z} from 'zod' export type SourceCodeUpload = {files: {[key: string]: string}, entry_point?: string | undefined, framework?: string | undefined, agent_name?: (string | null) | undefined, model_name?: (string | null) | undefined, description?: (string | null) | undefined, system_prompt?: (string | null) | undefined, tools?: (Array | null) | undefined}; export type UnifiedImportRequest = {agent_url?: (string | null) | undefined, agent_card?: ({[key: string]: unknown} | null) | undefined, source_code?: (SourceCodeUpload | null) | undefined, framework?: (string | null) | undefined, entry_point?: (string | null) | undefined, override_name?: (string | null) | undefined, rate_limit_requests_per_minute?: number | undefined, api_key?: (string | null) | undefined, external_id?: (string | null) | undefined, identity_provider?: (string | null) | undefined, idp_metadata?: ({[key: string]: unknown} | null) | undefined}; export type CreateApiV1AgentConfigurationsImportValidateArgs = {body: UnifiedImportRequest}; export type CreateApiV1AgentConfigurationsImportValidateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const unifiedValidationResponse = z.object({valid: z.boolean(), access_level: z.string().nullable().optional(), agent_card: z.record(z.string(), z.unknown()).nullable().optional(), errors: z.array(z.string()).optional(), warnings: z.array(z.string()).optional(), external_id: z.string().nullable().optional(), identity_provider: z.string().nullable().optional()}); 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 }; /** * Validate Agent Import * * POST /v1/agent-configurations/import/validate */ export const createApiV1AgentConfigurationsImportValidate = async (args: CreateApiV1AgentConfigurationsImportValidateArgs, options: CreateApiV1AgentConfigurationsImportValidateOptions) => { 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") const url = `${baseUrl.replace(/\/+$/, '')}/v1/agent-configurations/import/validate${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(unifiedValidationResponse, await res.json()) };