import {z} from 'zod' export type CreateApiApiPreviewTypesArgs = {body: {ai_settings_policy?: ({allow_all: boolean, allowed_classes: Array<'limits' | 'structure' | 'identity' | 'lifecycle' | 'behavior'>}) | undefined, color?: ('violet' | 'sage' | 'ocean' | 'amber' | 'rose' | 'slate' | 'teal' | 'plum') | undefined, content_md_max?: number | undefined, default_project_id?: (string | null) | undefined, expire_after_days?: number | undefined, field_body_template?: string | undefined, field_content_max?: number | undefined, field_count_max?: number | undefined, field_count_min?: number | undefined, field_mode?: ('structured' | 'freeform') | undefined, field_schema?: (Array<{columns?: (Array<{enum_values?: Array | undefined, name: string, precision?: number | undefined, required?: boolean | undefined, required_message?: string | undefined, rules?: (Array<{kind: 'min_length' | 'max_length' | 'min_words' | 'max_words', message?: string | undefined, value: number} | {kind: 'min' | 'max', message?: string | undefined, value: number} | {format: 'url' | 'email' | 'slug', kind: 'format', message?: string | undefined} | {kind: 'forbidden', message?: string | undefined, substrings: Array} | {kind: 'min_items' | 'max_items', message?: string | undefined, value: number} | {kind: 'unique_items', message?: string | undefined}>) | undefined, type: 'text' | 'number' | 'date' | 'datetime' | 'enum' | 'boolean', unit?: string | undefined}>) | undefined, derived?: ({column: string, op: 'sum' | 'avg' | 'min' | 'max' | 'count', source: string}) | undefined, enum_values?: Array | undefined, item_rules?: (Array<{kind: 'min_length' | 'max_length' | 'min_words' | 'max_words', message?: string | undefined, value: number} | {kind: 'min' | 'max', message?: string | undefined, value: number} | {format: 'url' | 'email' | 'slug', kind: 'format', message?: string | undefined} | {kind: 'forbidden', message?: string | undefined, substrings: Array} | {kind: 'min_items' | 'max_items', message?: string | undefined, value: number} | {kind: 'unique_items', message?: string | undefined}>) | undefined, name: string, precision?: number | undefined, reference_type_slug?: string | undefined, required?: boolean | undefined, required_message?: string | undefined, rules?: (Array<{kind: 'min_length' | 'max_length' | 'min_words' | 'max_words', message?: string | undefined, value: number} | {kind: 'min' | 'max', message?: string | undefined, value: number} | {format: 'url' | 'email' | 'slug', kind: 'format', message?: string | undefined} | {kind: 'forbidden', message?: string | undefined, substrings: Array} | {kind: 'min_items' | 'max_items', message?: string | undefined, value: number} | {kind: 'unique_items', message?: string | undefined}>) | undefined, type: 'text' | 'paragraph' | 'number' | 'datetime' | 'date' | 'boolean' | 'enum' | 'multi_enum' | 'reference' | 'multi_reference' | 'list' | 'table' | 'image' | 'file', unit?: string | undefined}>) | undefined, format?: 'markdown' | undefined, freeform_schema?: (Array<{item_rules?: (Array<{kind: 'min_length' | 'max_length' | 'min_words' | 'max_words', message?: string | undefined, value: number} | {kind: 'min' | 'max', message?: string | undefined, value: number} | {format: 'url' | 'email' | 'slug', kind: 'format', message?: string | undefined} | {kind: 'forbidden', message?: string | undefined, substrings: Array} | {kind: 'min_items' | 'max_items', message?: string | undefined, value: number} | {kind: 'unique_items', message?: string | undefined}>) | undefined, rules?: (Array<{kind: 'min_length' | 'max_length' | 'min_words' | 'max_words', message?: string | undefined, value: number} | {kind: 'min' | 'max', message?: string | undefined, value: number} | {format: 'url' | 'email' | 'slug', kind: 'format', message?: string | undefined} | {kind: 'forbidden', message?: string | undefined, substrings: Array} | {kind: 'min_items' | 'max_items', message?: string | undefined, value: number} | {kind: 'unique_items', message?: string | undefined}>) | undefined, type: 'text' | 'paragraph' | 'list'}>) | undefined, guidance?: string | undefined, guidance_max?: number | undefined, hide_orphan_warning?: boolean | undefined, icon?: ('building' | 'tower' | 'briefcase' | 'landmark' | 'store' | 'users' | 'rocket' | 'box' | 'layers' | 'globe' | 'sparkles' | 'code' | 'book' | 'file-text' | 'notebook' | 'lightbulb' | 'flask' | 'palette' | 'music' | 'camera' | 'image' | 'map-pin' | 'calendar' | 'clipboard' | 'message' | 'heart' | 'star' | 'flag' | 'tag' | 'bookmark' | 'graduation' | 'leaf' | 'compass' | 'puzzle' | 'target' | 'wand') | undefined, is_encrypted?: boolean | undefined, log_entry_order?: ('newest_first' | 'oldest_first') | undefined, log_mode?: ('period' | 'owned') | undefined, log_target_type_id?: (string | null) | undefined, log_timezone?: string | undefined, name: string, output_template?: string | undefined, package_as?: ('standard' | 'skill' | 'agent') | undefined, paragraph_rendering?: ('plain' | 'markdown') | undefined, prompt_default?: boolean | undefined, rollover?: ('daily' | 'weekly' | 'monthly' | 'manual') | undefined, share_template?: ('article' | 'prompt' | 'showcase') | undefined, slug: string, slug_source?: (string | null) | undefined, stale_after_days?: number | undefined, structure?: ('standard' | 'log') | undefined, summary?: string | undefined, workspace_id?: (string | null) | undefined}}; export type CreateApiApiPreviewTypesOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiPreviewTypesResponse = z.object({ai_settings_policy: z.record(z.string(), z.unknown()).nullable().optional(), capsule_count: z.number().int().gte(-9007199254740991).lte(9007199254740991).optional(), color: z.string().max(128).nullable().optional(), content_bytes: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable().optional(), content_md_max: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable().optional(), created_at: z.string().max(64).optional(), created_by: z.string().max(128).optional(), default_project_id: z.string().max(128).nullable().optional(), evicted_version_nums: z.array(z.number().int().gte(-9007199254740991).lte(9007199254740991)).optional(), expire_after_days: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable().optional(), field_content_max: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable().optional(), field_count_max: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable().optional(), field_count_min: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable().optional(), field_mode: z.string().max(128).nullable().optional(), field_schema: z.array(z.record(z.string(), z.unknown())).nullable().optional(), form_packaged_at: z.string().max(64).nullable().optional(), format: z.string().max(128).nullable().optional(), freeform_schema: z.array(z.record(z.string(), z.unknown())).nullable().optional(), guidance: z.string().max(90000).nullable().optional(), guidance_author_pass: z.string().max(128).optional(), guidance_checks: z.array(z.object({check: z.string().max(400), prompt: z.string().max(1000)}).and(z.record(z.string(), z.unknown()))).optional(), guidance_hash: z.string().max(128).nullable().optional(), guidance_max: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable().optional(), guidance_token: z.string().max(4096).nullable().optional(), guidance_token_status: z.enum(["ok", "not_required", "unavailable"]).optional(), guidance_updated_at: z.string().max(64).nullable().optional(), hide_orphan_warning: z.boolean().optional(), icon: z.string().max(128).nullable().optional(), id: z.string().max(36), inbound_ref_count: z.number().int().gte(-9007199254740991).lte(9007199254740991).optional(), is_encrypted: z.boolean().optional(), last_capsule_at: z.string().max(64).nullable().optional(), log_addressing: z.record(z.string(), z.unknown()).nullable().optional(), log_entry_order: z.string().max(128).nullable().optional(), log_mode: z.string().max(128).nullable().optional(), log_owner_types: z.array(z.string().max(128)).nullable().optional(), log_target: z.record(z.string(), z.unknown()).nullable().optional(), log_target_type_id: z.string().max(128).nullable().optional(), log_timezone: z.string().max(128).nullable().optional(), name: z.string().max(200).optional(), output_template: z.string().max(100000).nullable().optional(), package_as: z.string().max(128).nullable().optional(), paragraph_rendering: z.string().max(128).nullable().optional(), prompt_default: z.boolean().optional(), protection: z.object({checked_at: z.string().max(64).nullable(), enforced_by_organization: z.boolean().nullable(), freshness: z.enum(["live", "cached", "unknown"]), organization_set_at: z.string().max(64).nullable(), own: z.boolean().nullable(), protected: z.boolean().nullable(), publication_default_applies: z.boolean().nullable(), released_at: z.string().max(64).nullable(), set_at: z.string().max(64).nullable(), source: z.enum(["owner", "publication_default", "organization"]).nullable()}).optional(), revision_history_available: z.boolean().optional(), rollover: z.string().max(128).nullable().optional(), share_template: z.string().max(128).nullable().optional(), skill_renames_pending: z.array(z.object({capsule_id: z.string().max(36), next: z.string().max(200), served: z.string().max(200)})).optional(), slug: z.string().max(200).optional(), slug_rename: z.object({new_slug: z.string().max(200), old_slug: z.string().max(200), repointed_types: z.array(z.object({id: z.string().max(36), name: z.string().max(200), slug: z.string().max(200)}))}).optional(), slug_source: z.string().max(128).nullable().optional(), stale_after_days: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable().optional(), structure: z.string().max(128).nullable().optional(), summary: z.string().max(2000).nullable().optional(), updated_at: z.string().max(64).optional(), version_skip_reason: z.string().max(128).nullable().optional(), version_skipped: z.boolean().optional(), version_written: z.boolean().optional(), viewer_can_write: z.boolean().optional(), warnings: z.array(z.string().max(4000)).optional(), workspace_id: z.string().max(128).nullable().optional(), workspace_name: z.string().max(200).nullable().optional()}).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 }; /** * Create a type * * POST /api/preview/types * * Also accepts auth: cookieAuth, oauth2 */ export const createApiApiPreviewTypes = async (args: CreateApiApiPreviewTypesArgs, options: CreateApiApiPreviewTypesOptions) => { 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/preview/types${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(createApiApiPreviewTypesResponse, await res.json()) };