import {z} from 'zod' export type CreateApiApiPreviewMentionsResolveArgs = {ws?: string | undefined, omit_derived_pdf_data?: '1' | undefined, body: {include_files?: boolean | undefined, include_images?: boolean | undefined, mentions?: ({capsules?: Array | undefined, projects?: Array | undefined, types?: Array | undefined}) | undefined, prompt?: string | undefined, shape?: ('mcp' | 'wide') | undefined, type_capsule_limit?: number | undefined, workspaceId?: (string | null) | undefined}}; export type CreateApiApiPreviewMentionsResolveOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiPreviewMentionsResolveResponse = z.object({capsules: z.record(z.string(), z.unknown()), meta: z.record(z.string(), z.unknown()).optional(), parsed: z.record(z.string(), z.unknown()).optional(), projects: z.record(z.string(), z.unknown()).optional(), rejected: z.record(z.string(), z.unknown()).nullable().optional(), types: z.record(z.string(), z.unknown())}).and(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 }; /** * Resolve @slug capsule and Type mentions in a single round-trip * * POST /api/preview/mentions/resolve * * Also accepts auth: cookieAuth, oauth2 */ export const createApiApiPreviewMentionsResolve = async (args: CreateApiApiPreviewMentionsResolveArgs, options: CreateApiApiPreviewMentionsResolveOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.ws != null) query.append("ws", String(args.ws)) if (args.omit_derived_pdf_data != null) query.append("omit_derived_pdf_data", String(args.omit_derived_pdf_data)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/preview/mentions/resolve${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(createApiApiPreviewMentionsResolveResponse, await res.json()) };