/** * TASK-0124 — Database AI DTOs (zod; validated by `ZodValidate`). * * Limits (spec §Requirements / §Security): extract text ≤ 50k chars (413), * ≤200 records (422), ≤10 sample records (422), ≤5 sample formula rows (422), * description ≤ 500 chars. The heavy structural validation of the MODEL's tool * call lives in `db-prompts.ts` (shared with the `@factory/ai` zod schemas); * these DTOs gate the CLIENT request only. */ import { z } from "zod"; import { DB_EXTRACT_MAX_TEXT_CHARS, DB_GEN_MAX_SAMPLE_RECORDS, DB_FORMULA_MAX_SAMPLE_ROWS } from "@factory/ai"; /** Generate a database from a prompt (SSE). */ export const AiGenerateDatabaseDto = z.object({ /** The user's free-form description of the database to create. */ prompt: z.string().trim().min(1).max(2000), /** The parent page to nest the new database under (optional). */ parentId: z.string().min(1).optional(), }); export type AiGenerateDatabaseInput = z.infer; /** Extract records from pasted text/markdown into an existing database (SSE). */ export const AiExtractDto = z.object({ databaseId: z.string().min(1), /** Pasted text or a markdown table (≤ 50k chars — the 413 cap). */ text: z.string().min(1).max(DB_EXTRACT_MAX_TEXT_CHARS), }); export type AiExtractInput = z.infer; /** Extract mapping dry-run (JSON, no write). */ export const AiExtractPreviewDto = z.object({ databaseId: z.string().min(1), text: z.string().min(1).max(DB_EXTRACT_MAX_TEXT_CHARS), }); export type AiExtractPreviewInput = z.infer; /** Generate a formula from a description (JSON, non-streamed). */ export const AiGenerateFormulaDto = z.object({ databaseId: z.string().min(1), description: z.string().trim().min(1).max(500), /** The column name for the formula property (defaults to a derived name). */ name: z.string().trim().min(1).max(100).optional(), /** Evaluate (and return) on these specific records (≤ 5; default = first 5). */ sampleRowIds: z.array(z.string().min(1)).max(DB_FORMULA_MAX_SAMPLE_ROWS).optional(), }); export type AiGenerateFormulaInput = z.infer; export { DB_GEN_MAX_SAMPLE_RECORDS };