From 015f354427d09c193e681107b032c418db695575 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 03:37:37 +0000 Subject: [PATCH 1/5] feat(spec): blueprint field declares multiple, accept and maxSize The AI blueprint field and its strict mirror gain the three keys the field contract already declares, with FieldSchema's own value shapes (strict side nullable). `multiple: true` is refused by name at the key on every type outside FieldSchema's declarable set, now exported as multiDeclarableFieldTypes(), and on radio as FieldSchema refuses it. A multi-value select takes no blueprint defaultValue, since the built field judges its default against the list contract. accept / maxSize follow FieldSchema and are not refused outside the media family; the describes say they are read only there. Claude-Session: https://claude.ai/code/session_01ADHkmTKhm2Pn8ghVWNkBbH Co-authored-by: Claude --- .../spec/src/ai/solution-blueprint.test.ts | 194 +++++++++++++++++- .../spec/src/ai/solution-blueprint.zod.ts | 111 +++++++++- packages/spec/src/data/field.zod.ts | 17 +- 3 files changed, 299 insertions(+), 23 deletions(-) diff --git a/packages/spec/src/ai/solution-blueprint.test.ts b/packages/spec/src/ai/solution-blueprint.test.ts index b6f3be1dbcd..7af6e8cc295 100644 --- a/packages/spec/src/ai/solution-blueprint.test.ts +++ b/packages/spec/src/ai/solution-blueprint.test.ts @@ -10,7 +10,8 @@ import { } from './solution-blueprint.zod'; import { ViewFilterRuleSchema } from '../ui/view.zod'; import { SortItemSchema } from '../shared/enums.zod'; -import { FieldSchema, FieldType, SelectOptionSchema } from '../data/field.zod'; +import { FieldSchema, FieldType, SelectOptionSchema, multiDeclarableFieldTypes } from '../data/field.zod'; +import { FILE_REFERENCE_TYPES } from '../data/field-value.zod'; import { ObjectSchema } from '../data/object.zod'; import { VIRTUAL_FIELD_AGGREGATE_REMEDY } from '../data/aggregate-field-type-compatibility'; @@ -598,7 +599,7 @@ describe('SolutionBlueprintStrictSchema (OpenAI strict mirror)', () => { nameField: null, stageField: null, fields: [ - { name: 'name', label: null, type: 'text', required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null }, + { name: 'name', label: null, type: 'text', required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null }, ], }, ], @@ -637,7 +638,7 @@ describe('SolutionBlueprintStrictSchema (OpenAI strict mirror)', () => { const badField = { ...strictBp, objects: [ - { name: 'x', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'f', type: 'text', required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null }] }, + { name: 'x', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'f', type: 'text', required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null }] }, ], }; // `f` is missing the (nullable, required) `label` key. @@ -664,11 +665,11 @@ describe('SolutionBlueprintStrictSchema (OpenAI strict mirror)', () => { stageField: null, fields: [ { - name: 'task_total', label: '任务总数', type: 'summary', required: null, reference: null, options: null, expression: null, defaultValue: null, + name: 'task_total', label: '任务总数', type: 'summary', required: null, reference: null, options: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null, summaryOperations: { object: 'task', function: 'count', field: 'id', relationshipField: null, conditions: null }, }, { - name: 'completed_task_count', label: '已完成任务数', type: 'summary', required: null, reference: null, options: null, expression: null, defaultValue: null, + name: 'completed_task_count', label: '已完成任务数', type: 'summary', required: null, reference: null, options: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null, summaryOperations: { object: 'task', function: 'count', field: 'id', relationshipField: null, conditions: [{ field: 'status', op: 'eq', value: 'completed' }], @@ -740,7 +741,7 @@ describe('SolutionBlueprintStrictSchema (OpenAI strict mirror)', () => { describe('stageField + option kind (the model names the stage field and states each option\'s kind, or says null)', () => { const statusField = (options: Array>) => ({ - name: 'status', label: null, type: 'select', required: null, reference: null, options, summaryOperations: null, expression: null, defaultValue: null, + name: 'status', label: null, type: 'select', required: null, reference: null, options, summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null, }); const STAGES = [ { label: 'New', value: 'new', kind: 'open' }, @@ -1299,6 +1300,9 @@ describe('strict mirror ↔ lenient schema — VALUE parity', () => { summaryOperations: null, expression: null, defaultValue: null, + multiple: null, + accept: null, + maxSize: null, }], }], views: null, @@ -1326,7 +1330,7 @@ describe('blueprint widget `aggregate` and calendar view `startDateField`', () = name: 'interview', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'score', label: null, type: 'number', required: null, reference: null, options: null, - summaryOperations: null, expression: null, defaultValue: null, + summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null, }], }], views: null, @@ -1506,7 +1510,7 @@ describe('blueprint field `defaultValue`', () => { name: 'task', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'flag', label: null, required: null, reference: null, options: null, summaryOperations: null, - expression: null, defaultValue: null, ...field, + expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null, ...field, }], }], views: null, @@ -1614,7 +1618,7 @@ describe('blueprint field `defaultValue`', () => { name: 'task', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, fields: [{ name: 'flag', label: null, type: 'boolean', required: null, reference: null, options: null, - summaryOperations: null, expression: null, + summaryOperations: null, expression: null, multiple: null, accept: null, maxSize: null, }], }], }); @@ -1712,7 +1716,7 @@ describe('blueprint field `expression` — the stored computed value', () => { objects: [{ name: 'order_line', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, fields: [{ - ...STORED, label: null, required: null, reference: null, options: null, summaryOperations: null, defaultValue: null, + ...STORED, label: null, required: null, reference: null, options: null, summaryOperations: null, defaultValue: null, multiple: null, accept: null, maxSize: null, }], }], views: null, @@ -1800,7 +1804,7 @@ describe('blueprint object `icon`', () => { it('is required-but-nullable on the strict mirror (OpenAI strict: every key in `required`)', () => { const object = { name: 'invoice', label: null, description: null, icon: 'receipt', sharingModel: null, nameField: null, stageField: null, - fields: [{ name: 'title', label: null, type: 'text', required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null }], + fields: [{ name: 'title', label: null, type: 'text', required: null, reference: null, options: null, summaryOperations: null, expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null }], }; const bp = (o: Record) => ({ summary: 's', assumptions: [], questions: null, objects: [o], views: null, dashboards: null, app: null }); expect(SolutionBlueprintStrictSchema.parse(bp(object)).objects[0].icon).toBe('receipt'); @@ -1862,3 +1866,171 @@ describe('blueprint view `name` — bare, or qualified with its own object', () .toEqual([{ path: ['name'], code: 'custom' }]); }); }); + +// --------------------------------------------------------------------------- +// The field contract's `multiple`, `accept` and `maxSize`, on the blueprint +// field and its strict mirror (the `defaultValue` precedent, ruling B on +// cloud#3619). An AI build of "an expense claim with its e-invoices" names one +// file field holding several invoices; without these keys the blueprint could +// not say "several", which file types, or how large. +// --------------------------------------------------------------------------- +describe('blueprint field `multiple`, `accept` and `maxSize`', () => { + const KEYS = ['multiple', 'accept', 'maxSize'] as const; + const OPTIONS = [{ label: 'Open', value: 'open' }, { label: 'Done', value: 'done' }]; + const lenientField = (field: Record) => SolutionBlueprintSchema.safeParse({ + summary: 's', + objects: [{ name: 'claim', fields: [{ name: 'invoices', ...field }] }], + }); + const strictField = (field: Record) => SolutionBlueprintStrictSchema.safeParse({ + summary: 's', assumptions: [], questions: null, views: null, dashboards: null, app: null, + objects: [{ + name: 'claim', label: null, description: null, icon: null, sharingModel: null, nameField: null, stageField: null, + fields: [{ + name: 'invoices', label: null, required: null, reference: null, options: null, summaryOperations: null, + expression: null, defaultValue: null, multiple: null, accept: null, maxSize: null, ...field, + }], + }], + }); + /** What the field needs besides `type` for the BUILT field's schema to judge only the key under test. */ + const builtExtras = (type: string): Record => { + if (type === 'select' || type === 'radio') return { options: OPTIONS }; + if (type === 'lookup' || type === 'master_detail') return { reference: 'contact' }; + return {}; + }; + const lenientShape = () => (SolutionBlueprintSchema as any).shape.objects.element.shape.fields.element.shape; + const strictShape = () => (SolutionBlueprintStrictSchema as any).shape.objects.element.shape.fields.element.shape; + const MULTIPLE_PATH = ['objects', 0, 'fields', 0, 'multiple']; + const issuesAt = (result: { error?: { issues: Array<{ path: PropertyKey[]; code: string; message: string }> } }, path: PropertyKey[]) => + (result.error?.issues ?? []).filter((i) => JSON.stringify(i.path) === JSON.stringify(path)); + + it('both sides carry the three keys (key parity)', () => { + for (const key of KEYS) { + expect({ key, lenient: key in lenientShape(), strict: key in strictShape() }) + .toEqual({ key, lenient: true, strict: true }); + } + }); + + it('each key takes exactly the values the built field\'s own key takes (VALUE parity with FieldSchema)', () => { + const fieldShape = (FieldSchema as any).shape; + const BATTERY: Record<(typeof KEYS)[number], unknown[]> = { + multiple: [true, false, 'true', 1, 0, [], {}], + accept: [[], ['application/pdf', 'image/*', '.ofd'], [''], 'image/*', [1], [null], {}], + maxSize: [1, 10485760, 0, -1, 1.5, '1024', Number.NaN, Number.POSITIVE_INFINITY, true], + }; + for (const key of KEYS) { + for (const value of BATTERY[key]) { + const built = fieldShape[key].safeParse(value).success; + expect({ key, value, lenient: lenientShape()[key].safeParse(value).success, strict: strictShape()[key].safeParse(value).success }) + .toEqual({ key, value, lenient: built, strict: built }); + } + // Absence: optional on the lenient side, null on the strict mirror. + expect({ key, absent: lenientShape()[key].safeParse(undefined).success }).toEqual({ key, absent: true }); + expect({ key, nulled: strictShape()[key].safeParse(null).success, absent: strictShape()[key].safeParse(undefined).success }) + .toEqual({ key, nulled: true, absent: false }); + } + }); + + it('CONTROL: a field that declares none of them parses as before, and gains no key', () => { + const parsed = lenientField({ type: 'file' }); + expect(parsed.success).toBe(true); + for (const key of KEYS) expect({ key, present: key in parsed.data!.objects[0].fields[0] }).toEqual({ key, present: false }); + const strict = strictField({ type: 'file' }); + expect(strict.success).toBe(true); + for (const key of KEYS) expect(strict.data!.objects[0].fields[0][key]).toBeNull(); + }); + + it('carries a multi-file field with its accept and maxSize through both sides, into a field the built schema accepts', () => { + const invoices = { type: 'file', multiple: true, accept: ['application/pdf', 'image/*', '.ofd'], maxSize: 10485760 }; + const lenient = lenientField(invoices); + expect(lenient.success).toBe(true); + expect(lenient.data!.objects[0].fields[0]).toMatchObject(invoices); + const strict = strictField(invoices); + expect(strict.success).toBe(true); + expect(strict.data!.objects[0].fields[0]).toMatchObject(invoices); + const built = FieldSchema.safeParse({ name: 'invoices', label: 'Invoices', ...invoices }); + expect(built.success).toBe(true); + expect(built.data).toMatchObject(invoices); + }); + + it('accepts `accept` and `maxSize` on file, lookup and select alike, as the built field does (read only on media)', () => { + for (const type of ['file', 'lookup', 'select']) { + const field = { type, ...builtExtras(type), accept: ['.pdf'], maxSize: 1024 }; + const lenient = lenientField(field); + expect({ type, lenient: lenient.success }).toEqual({ type, lenient: true }); + expect(lenient.data!.objects[0].fields[0]).toMatchObject({ accept: ['.pdf'], maxSize: 1024 }); + const strictOptions = type === 'select' ? { options: OPTIONS.map((o) => ({ ...o, kind: null })) } : {}; + expect({ type, strict: strictField({ ...field, ...strictOptions }).success }).toEqual({ type, strict: true }); + expect({ type, built: FieldSchema.safeParse({ name: 'invoices', label: 'Invoices', ...field }).success }) + .toEqual({ type, built: true }); + } + }); + + it('refuses `multiple: true` on a "text" field by name at the key, naming the declarable types', () => { + const result = lenientField({ type: 'text', multiple: true }); + expect(result.success).toBe(false); + const named = issuesAt(result, MULTIPLE_PATH); + expect(result.error!.issues).toHaveLength(1); + expect(named.map((i) => i.code)).toEqual(['custom']); + expect(named[0].message).toContain('"invoices" (text)'); + for (const type of multiDeclarableFieldTypes()) { + if (type !== 'radio') expect(named[0].message).toContain(`"${type}"`); + } + }); + + it('refuses `multiple: true` on a "radio" field by name at the key, as the built field does', () => { + const result = lenientField({ type: 'radio', options: OPTIONS, multiple: true }); + expect(result.success).toBe(false); + expect(result.error!.issues).toHaveLength(1); + const named = issuesAt(result, MULTIPLE_PATH); + expect(named.map((i) => i.code)).toEqual(['custom']); + expect(named[0].message).toContain('"invoices" (radio)'); + expect(named[0].message).toContain('"checkboxes"'); + const built = FieldSchema.safeParse({ name: 'invoices', label: 'Invoices', type: 'radio', options: OPTIONS, multiple: true }); + expect(built.error?.issues.map((i) => i.path)).toEqual([['multiple']]); + }); + + it('refuses `multiple: true` on exactly the types the built field refuses it on (FieldSchema\'s own set)', () => { + for (const type of FieldType.options) { + const blueprint = issuesAt(lenientField({ type, ...builtExtras(type), multiple: true }), MULTIPLE_PATH).length; + const built = FieldSchema.safeParse({ name: 'invoices', label: 'Invoices', type, ...builtExtras(type), multiple: true }); + const builtRefused = (built.error?.issues ?? []).filter((i) => JSON.stringify(i.path) === '["multiple"]').length; + expect({ type, blueprint, built: builtRefused }).toEqual({ type, blueprint: builtRefused, built: builtRefused }); + expect({ type, refused: blueprint === 1 }) + .toEqual({ type, refused: type === 'radio' || !multiDeclarableFieldTypes().has(type) }); + // `false` is never refused, on any type. + expect({ type, falseRefused: issuesAt(lenientField({ type, ...builtExtras(type), multiple: false }), MULTIPLE_PATH).length }) + .toEqual({ type, falseRefused: 0 }); + } + }); + + it('refuses a defaultValue on a multi-value "select", as the built field does, and keeps it on a single-value one', () => { + const multi = lenientField({ type: 'select', options: OPTIONS, multiple: true, defaultValue: 'open' }); + expect(multi.success).toBe(false); + expect(multi.error!.issues).toHaveLength(1); + const named = issuesAt(multi, ['objects', 0, 'fields', 0, 'defaultValue']); + expect(named).toHaveLength(1); + expect(named[0].message).toContain('"invoices" (select)'); + expect(named[0].message).toContain('`multiple: true`'); + // The built field judges the default against the list contract and refuses the scalar. + const built = FieldSchema.safeParse({ name: 'invoices', label: 'Invoices', type: 'select', options: OPTIONS, multiple: true, defaultValue: 'open' }); + expect(built.success).toBe(false); + expect(lenientField({ type: 'select', options: OPTIONS, multiple: true }).success).toBe(true); + expect(lenientField({ type: 'select', options: OPTIONS, multiple: false, defaultValue: 'open' }).success).toBe(true); + }); + + it('the describes name where each key applies, pinned against the built field\'s own sets, and promise no build', () => { + for (const shape of [lenientShape(), strictShape()]) { + const multiple: string = shape.multiple.description; + for (const type of multiDeclarableFieldTypes()) expect({ type, named: multiple.includes(`"${type}"`) }).toEqual({ type, named: true }); + for (const key of ['accept', 'maxSize'] as const) { + const text: string = shape[key].description; + for (const type of FILE_REFERENCE_TYPES) expect({ key, type, named: text.includes(`"${type}"`) }).toEqual({ key, type, named: true }); + expect(text).toContain('Read only on the media family'); + } + for (const key of KEYS) { + expect(shape[key].description).toContain('Carried into the built field by the applier'); + expect(shape[key].description).not.toMatch(/is built with/); + } + } + }); +}); diff --git a/packages/spec/src/ai/solution-blueprint.zod.ts b/packages/spec/src/ai/solution-blueprint.zod.ts index fd02b481987..2f99112682f 100644 --- a/packages/spec/src/ai/solution-blueprint.zod.ts +++ b/packages/spec/src/ai/solution-blueprint.zod.ts @@ -2,7 +2,7 @@ import { z } from 'zod'; import { lazySchema } from '../shared/lazy-schema'; -import { FieldType, SelectOptionSchema } from '../data/field.zod'; +import { FieldType, SelectOptionSchema, multiDeclarableFieldTypes } from '../data/field.zod'; import { checkLiteralDefaultValue } from '../data/default-value-shape'; import { isRuntimeDefaultToken } from '../data/default-value-tokens'; import { FilterConditionSchema } from '../data/filter.zod'; @@ -211,8 +211,8 @@ const BLUEPRINT_DEFAULT_VALUE_ADMITTED = (() => { /** Which types take a default and what each takes, read by both describes. */ const DEFAULT_VALUE_TYPE_RULE = `It must fit \`type\`, and only these types take one: ${BLUEPRINT_DEFAULT_VALUE_ADMITTED}. ` - + 'Every other type is refused by name: a date is fixed at design time, a reference or file names no record yet, a ' - + 'multi-value field stores a list, a formula / summary / autonumber is computed, and a credential, signature or ' + + 'Every other type is refused by name, and so is a "select" with `multiple: true`: a date is fixed at design time, a ' + + 'reference or file names no record yet, a multi-value field stores a list, a formula / summary / autonumber is computed, and a credential, signature or ' + 'structured value has no one value right for every record.'; /** @@ -274,7 +274,7 @@ const STORED_EXPRESSION_RULE = */ function refuseUnfitDefaultValue(field: unknown, ctx: z.RefinementCtx): void { if (typeof field !== 'object' || field === null) return; - const { name, type, options, defaultValue } = field as Record; + const { name, type, options, defaultValue, multiple } = field as Record; // Absence. The strict mirror's null is stripped before this schema reads it, // and a lenient null is refused by the key's own union. if (defaultValue === undefined || defaultValue === null) return; @@ -284,6 +284,19 @@ function refuseUnfitDefaultValue(field: unknown, ctx: z.RefinementCtx): void { const shown = JSON.stringify(defaultValue) ?? String(defaultValue); const refuse = (message: string) => ctx.addIssue({ code: 'custom', path: ['defaultValue'], message }); + // An admitted type that `multiple: true` makes multi-value ("select") stores + // a list, which this scalar key cannot carry, and the built field judges its + // default against the list contract. True of a token as of a literal, so it is + // judged first. `radio` is left to the `multiple` refusal: dropping the flag + // is its remedy, and the single-value default is then judged as on any radio. + // A type that takes no default keeps its own reason. + if (multiple === true && 'takes' in rule && type !== 'radio' && multiDeclarableFieldTypes().has(type)) { + refuse(`${subject}: a "${type}" field with \`multiple: true\` takes no defaultValue in a blueprint, because it stores a ` + + 'list of values, and a blueprint default is one value. Remove defaultValue, or drop `multiple` for a ' + + 'single-value field.'); + return; + } + // A token is judged before the type. On a type that takes no default, that // type's reason is false of a token (`current_user` names no record, `NOW()` // is not frozen), and an author steered by it writes a record id or a fixed day. @@ -315,6 +328,73 @@ function refuseUnfitDefaultValue(field: unknown, ctx: z.RefinementCtx): void { } } +/** + * The refusal of `multiple: true` on a type that cannot hold several values, + * judged against `FieldSchema`'s own declarable set + * ({@link multiDeclarableFieldTypes}), so a blueprint can propose no + * `multiple` the built field refuses and miss none it accepts. `radio` is in + * that set and is refused by its own branch, as `FieldSchema` refuses it: a + * radio group is single-choice. Each issue lands on the field's `multiple`. + * + * Guarded like the `defaultValue` refusal: it runs on every parse, so a + * `type` outside `FieldType` is left to that key's own issue. + */ +function refuseUndeclarableMultiple(field: unknown, ctx: z.RefinementCtx): void { + if (typeof field !== 'object' || field === null) return; + const { name, type, multiple } = field as Record; + if (multiple !== true || typeof type !== 'string' || !(FieldType.options as readonly string[]).includes(type)) return; + const subject = `Field "${typeof name === 'string' ? name : ''}" (${type})`; + const declarable = multiDeclarableFieldTypes(); + const remedies = [...declarable].filter((t) => t !== 'radio').map((t) => `"${t}"`).join(' / '); + const refuse = (message: string) => ctx.addIssue({ code: 'custom', path: ['multiple'], message }); + if (type === 'radio') { + refuse(`${subject}: a "radio" field cannot take \`multiple: true\`, because a radio group is single-choice: the ` + + 'built field refuses the pair. For several chosen options use "checkboxes" (all options visible), ' + + '"multiselect" (dropdown) or "tags" (free-form values); for one, drop `multiple`.'); + return; + } + if (declarable.has(type)) return; + refuse(`${subject}: \`multiple: true\` is declarable only on ${remedies}, and a "${type}" field holds one value: ` + + 'the built field refuses the pair. For several related records use a "lookup" with `multiple: true`, for ' + + 'several files a "file" or "image" with `multiple: true`, for several option codes a "multiselect" / ' + + '"checkboxes" / "tags" field. For a single value, drop `multiple`.'); +} + +/** Both cross-key rules of a blueprint field, in one refinement. */ +function refineBlueprintField(field: unknown, ctx: z.RefinementCtx): void { + refuseUnfitDefaultValue(field, ctx); + refuseUndeclarableMultiple(field, ctx); +} + +/** + * Where the three media / multi-value keys apply and what they do on the built + * field, read by both describes so the lenient field and the strict mirror + * teach the same thing. The type lists are pinned against `FieldSchema`'s own + * sets (`multiDeclarableFieldTypes`, `FILE_REFERENCE_TYPES`) by the blueprint + * test, not imported: the strict mirror is built when this module loads, and + * the declarable set is computed on first use (see its docblock). + * + * No describe says the field "is built with" the key: nothing in this + * repository turns a blueprint field into an object field, so the wording is + * the one `defaultValue`'s describe uses, "carried into the built field by the + * applier". + */ +const MULTIPLE_RULE = + 'Several values in one field: true makes the built field hold a list — several related records on a "lookup" / ' + + '"user", several files on a "file" / "image", several chosen options on a "select". Declarable only on "select" / ' + + '"lookup" / "user" / "file" / "image" (and redundantly on "multiselect" / "checkboxes" / "tags", which are ' + + 'lists already); `multiple: true` on any other type, "radio" included, is refused by name. A multi-value ' + + '"select" takes no defaultValue. Carried into the built field by the applier as its `multiple`.'; +const MEDIA_TYPES_PHRASE = 'a media field ("file" / "image" / "avatar" / "video" / "audio")'; +const ACCEPT_RULE = + `The upload types ${MEDIA_TYPES_PHRASE} permits, as MIME types or extensions, e.g. ["application/pdf", "image/*", ` + + '".ofd"]. Read only on the media family: on any other type it parses and nothing reads it. Carried into the ' + + 'built field by the applier as its `accept`, which the built field offers to the file picker and checks on write.'; +const MAX_SIZE_RULE = + `The largest file ${MEDIA_TYPES_PHRASE} takes, in BYTES (a positive integer: 10485760 for 10 MB). Read only on the ` + + 'media family: on any other type it parses and nothing reads it. Carried into the built field by the applier as ' + + 'its `maxSize`, which the built field checks on write against the stored file size.'; + /** * A proposed field on a blueprint object. `reference` carries the target * object for `lookup` / `master_detail` types — relationships are expressed @@ -347,7 +427,18 @@ export const BlueprintFieldSchema = lazySchema(() => z.object({ // rule across `type` / `options` and this key, so it is the refinement below. defaultValue: z.union([z.boolean(), z.number(), z.string()]).optional() .describe(`The built field's default: the value a new record gets when it is created without one, carried into the object field as its \`defaultValue\` and stored as written. ${DEFAULT_VALUE_TYPE_RULE} ${booleanFlagRule('omit `required` or set it false')} Omit it for a field with no default.`), -}).superRefine(refuseUnfitDefaultValue, { when: () => true })); + // ⛔ The three keys below must stay in lockstep with the strict + // `StrictField` keys of the same names, and their value shapes with + // `FieldSchema`'s (`multiple` without its `.default(false)`, so a field that + // omits it parses as before). The field key-parity pin and the FieldSchema + // value-parity pin fail if either side drifts. + multiple: z.boolean().optional() + .describe(`${MULTIPLE_RULE} Omit it for a single value.`), + accept: z.array(z.string()).optional() + .describe(`${ACCEPT_RULE} Omit it to permit any type.`), + maxSize: z.number().int().positive().optional() + .describe(`${MAX_SIZE_RULE} Omit it to set no limit on the field.`), +}).superRefine(refineBlueprintField, { when: () => true })); export type BlueprintField = z.input; /** @@ -760,6 +851,16 @@ const StrictField = z.object({ // if either side drops the key. defaultValue: z.union([z.boolean(), z.number(), z.string()]).nullable() .describe(`The built field's default, or null for none: the value a new record gets when it is created without one, carried into the object field as its \`defaultValue\` and stored as written. ${DEFAULT_VALUE_TYPE_RULE} Null on every other type. ${booleanFlagRule('`required` null or false')}`), + // ⛔ Must stay in lockstep with the lenient `BlueprintFieldSchema` keys of the + // same names. Strict mode makes each key required, so the model decides on + // every field; the cross-key rule (`multiple` by type) is the lenient field's + // refinement, run when `apply_blueprint` parses, and refuses BY NAME. + multiple: z.boolean().nullable() + .describe(`${MULTIPLE_RULE} Null (or false) for a single value.`), + accept: z.array(z.string()).nullable() + .describe(`${ACCEPT_RULE} Null to permit any type, and null on every non-media field.`), + maxSize: z.number().int().positive().nullable() + .describe(`${MAX_SIZE_RULE} Null to set no limit, and null on every non-media field.`), }); const StrictObject = z.object({ diff --git a/packages/spec/src/data/field.zod.ts b/packages/spec/src/data/field.zod.ts index 5acb2adaa7f..1cd656ec4be 100644 --- a/packages/spec/src/data/field.zod.ts +++ b/packages/spec/src/data/field.zod.ts @@ -192,10 +192,13 @@ export const VALUE_DOMAIN_FIELD_TYPES: ReadonlySet = new Set([ * (#12017 two-copies failure shape; the #11875 lesson that a hand-written * enumeration goes one revision stale). * - * Package-internal on purpose: it is the superRefine's membership test, not a - * third answer to "is this field multi-valued". That question has exactly one - * answer — `isMultiValueField` (`field-value.zod.ts`) — and both of the sets - * this one unions stay untouched. + * Exported for ONE reader beside this file's superRefine: the AI blueprint + * field (`ai/solution-blueprint.zod.ts`), which refuses `multiple: true` on the + * same types so that a blueprint can never propose a declaration the built + * field refuses. It answers "may an author DECLARE `multiple: true` here", and + * is not a third answer to "is this field multi-valued". That question has + * exactly one answer — `isMultiValueField` (`field-value.zod.ts`) — and both of + * the sets this one unions stay untouched. * * ⚠️ Computed on FIRST USE, never at module top level. `field-value.zod` reaches * back into this module through `shared/strict-object` → `shared/suggestions.zod`, @@ -206,7 +209,7 @@ export const VALUE_DOMAIN_FIELD_TYPES: ReadonlySet = new Set([ * module has settled) is the same discipline `lazySchema` applies above. */ let multiDeclarableTypes: ReadonlySet | undefined; -function multiDeclarableTypeSet(): ReadonlySet { +export function multiDeclarableFieldTypes(): ReadonlySet { return (multiDeclarableTypes ??= new Set([...MULTI_CAPABLE_TYPES, ...MULTI_OPTION_TYPES])); } @@ -221,7 +224,7 @@ function multiDeclarableTypeSet(): ReadonlySet { */ let multiDeclarableRemedyTypes: readonly string[] | undefined; function multiDeclarableRemedyTypeList(): readonly string[] { - return (multiDeclarableRemedyTypes ??= [...multiDeclarableTypeSet()].filter((t) => t !== 'radio')); + return (multiDeclarableRemedyTypes ??= [...multiDeclarableFieldTypes()].filter((t) => t !== 'radio')); } /** @@ -3199,7 +3202,7 @@ export const FieldSchema = lazySchema(() => { // // `radio` is INSIDE the set and is therefore never refused here — its own // narrower #11437 check above owns that pair, so the two never double-fire. - if (field.multiple === true && !multiDeclarableTypeSet().has(field.type)) { + if (field.multiple === true && !multiDeclarableFieldTypes().has(field.type)) { const alternative = REFERENCE_VALUE_TYPES.has(field.type) ? 'a `lookup` with `reference` naming the same object (`multiple: true` there stores several related records)' : FILE_REFERENCE_TYPES.has(field.type) From dbb037a8603a91ad571a0b3a3a4b64c4a3505c93 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 03:43:19 +0000 Subject: [PATCH 2/5] chore(spec): regenerate artifacts and add changeset for blueprint field keys Claude-Session: https://claude.ai/code/session_01ADHkmTKhm2Pn8ghVWNkBbH Co-authored-by: Claude --- ...blueprint-field-multiple-accept-maxsize.md | 20 +++++++++++++++++++ .../docs/references/ai/solution-blueprint.mdx | 10 ++++++++-- packages/spec/api-surface/data.json | 1 + packages/spec/authorable-surface/ai.json | 3 +++ packages/spec/export-origins/data.json | 1 + 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 .changeset/34275-blueprint-field-multiple-accept-maxsize.md diff --git a/.changeset/34275-blueprint-field-multiple-accept-maxsize.md b/.changeset/34275-blueprint-field-multiple-accept-maxsize.md new file mode 100644 index 00000000000..cd16caa92a7 --- /dev/null +++ b/.changeset/34275-blueprint-field-multiple-accept-maxsize.md @@ -0,0 +1,20 @@ +--- +'@objectstack/spec': minor +--- + +feat(spec): an AI blueprint field can declare `multiple`, `accept` and `maxSize` + +Clause-②: yes (widening) — a blueprint field carrying `multiple` on a type that can hold several values, or `accept` / `maxSize`, parses where it was refused as an unrecognized key; the strict mirror gains the same three keys, nullable. `@objectstack/spec/data` gains one export, `multiDeclarableFieldTypes()`. Nothing is removed or narrowed. +Metadata-protocol: added +Skills-docs: none — `skills/**` teaches no blueprint field key; the blueprint guide the design model reads lives with the applier in cloud, which carries the keys next. + +`BlueprintFieldSchema` (what `apply_blueprint` parses) and its strict mirror (what the in-app design model generates against) now declare three keys the object field contract already had, with `FieldSchema`'s own value shapes: + +- **`multiple`** (boolean): several values in one field — several related records on a `lookup` / `user`, several files on a `file` / `image`, several chosen options on a `select`. "An expense claim with its e-invoices attached" is now one blueprint field, `{ name: 'invoices', type: 'file', multiple: true }`. +- **`accept`** (array of MIME types or extensions) and **`maxSize`** (a positive integer, in bytes): the upload types and the size limit of a media field. + +FROM → TO for an author: before, `{ type: 'file', multiple: true }` in a blueprint was refused with `unrecognized_keys` at the field's `multiple`; now it parses, and the applier carries the key into the built field. Nothing an author wrote before parses differently: a field that declares none of the three keys parses exactly as before, and gains no key. + +- **`multiple: true` is refused by name where the built field refuses it.** The blueprint field judges it against `FieldSchema`'s own declarable set, exported as `multiDeclarableFieldTypes()` rather than copied, so the blueprint can propose no `multiple` the built field refuses. A `radio` field is refused as on `FieldSchema`: a radio group is single-choice. The refusal lands on the field's `multiple` and names the types that take it. +- **A multi-value `select` takes no blueprint `defaultValue`.** It stores a list, and a blueprint default is one value; the built field would refuse the scalar too. The refusal lands on the field's `defaultValue`. +- **`accept` / `maxSize` outside the media family** parse and are read by nothing, as on `FieldSchema`; the describes say so. diff --git a/content/docs/references/ai/solution-blueprint.mdx b/content/docs/references/ai/solution-blueprint.mdx index 10a773ebf8a..c7c35ac6763 100644 --- a/content/docs/references/ai/solution-blueprint.mdx +++ b/content/docs/references/ai/solution-blueprint.mdx @@ -113,7 +113,10 @@ const result = BlueprintAppSchema.parse(data); | **options** | `{ label: string; value: string; kind?: Enum<'open' \| 'won' \| 'lost'> }[]` | optional | Choices for select / multiselect / radio fields | | **summaryOperations** | `{ object: string; function: Enum<'count' \| 'sum' \| 'avg' \| 'min' \| 'max'>; field?: string; relationshipField?: string; … }` | optional | REQUIRED when `type` is "summary" (a roll-up of child records: 任务总数 / 报名人数 / 合计金额 / 已完成任务数). Names the child object, the aggregation, and — for a qualified count/sum — the condition. A "summary" field without it materializes runtime-dead. | | **expression** | `string` | optional | The CEL body a computed field computes. Two uses. First, REQUIRED when `type` is "formula", e.g. "record.quantity * record.unit_price", or "record.order_no + ' · ' + record.customer.name" for a composed title. A formula reads a lookup / master_detail field's related record ONE hop through it — `record..`, as `record.customer.name` above; the bare `record.customer` is the stored id, and a second hop (`record.customer.owner.name`) is refused at build. A "formula" field without it materializes runtime-dead: the engine builds its formula plan only from fields that HAVE an expression, so the field reads null everywhere, forever. Same failure shape as a "summary" with no `summaryOperations`. Note `nameField` on the object recommends a formula for numbered entities (invoice/ticket) — that formula needs THIS key, or the record title is blank on every card, lookup chip and breadcrumb. A "formula" is computed on read and stored nowhere: it is shown everywhere, but a list cannot sort by it, search does not scan it, and a `sum` / `avg` over it is refused with the one remedy every such refusal prints: "Computed on read, the field stores no value: make it a field of its return type with the same `expression` (computed and stored on write) and aggregate that. Counting records is a different question." Second, the stored computed value that remedy names: the same `expression` on a field of the value's own return type, never a "formula" (`number` / `currency` / `percent` for a quantity or an amount, `date` for a date). The engine computes it from the record on every write and keeps it in a column, so `sum` / `avg` and sort work on it as on any stored field of that type. Use it whenever the value is totalled, averaged or charted: 销售额 = 销量 × 单价 is a "currency" field with "record.quantity * record.unit_price". Name the return type, not "number" for every value: a date expression on a "number" field is refused at every write. A stored expression reads only this record's own fields: a value from a related record stays a "formula" (shown, not totalled) or is a snapshot field written by a flow on the related object when that value changes, and an input that changes over time (the current date, the acting user) is frozen at the write. Omit it on a field that is neither a formula nor a stored computed value. | -| **defaultValue** | `boolean \| number \| string` | optional | The built field's default: the value a new record gets when it is created without one, carried into the object field as its `defaultValue` and stored as written. It must fit `type`, and only these types take one: "boolean" / "toggle" → true or false; "number" / "currency" / "percent" / "rating" / "slider" / "progress" → a number; "text" / "textarea" / "email" / "url" / "phone" / "markdown" / "html" / "richtext" / "code" / "color" → a string; "time" → a time of day, "HH:MM"; "select" / "radio" → the `value` of one of the field's own `options`, never its label. Every other type is refused by name: a date is fixed at design time, a reference or file names no record yet, a multi-value field stores a list, a formula / summary / autonumber is computed, and a credential, signature or structured value has no one value right for every record. A yes/no flag (是否完成 / 已付款 / is_active) is a "boolean" field that is never `required` (omit `required` or set it false) and carries defaultValue false: a required flag refuses the unchecked switch, and a flag with no default is empty, not false, on every record created without it, so a filter on false misses those records. Omit it for a field with no default. | +| **defaultValue** | `boolean \| number \| string` | optional | The built field's default: the value a new record gets when it is created without one, carried into the object field as its `defaultValue` and stored as written. It must fit `type`, and only these types take one: "boolean" / "toggle" → true or false; "number" / "currency" / "percent" / "rating" / "slider" / "progress" → a number; "text" / "textarea" / "email" / "url" / "phone" / "markdown" / "html" / "richtext" / "code" / "color" → a string; "time" → a time of day, "HH:MM"; "select" / "radio" → the `value` of one of the field's own `options`, never its label. Every other type is refused by name, and so is a "select" with `multiple: true`: a date is fixed at design time, a reference or file names no record yet, a multi-value field stores a list, a formula / summary / autonumber is computed, and a credential, signature or structured value has no one value right for every record. A yes/no flag (是否完成 / 已付款 / is_active) is a "boolean" field that is never `required` (omit `required` or set it false) and carries defaultValue false: a required flag refuses the unchecked switch, and a flag with no default is empty, not false, on every record created without it, so a filter on false misses those records. Omit it for a field with no default. | +| **multiple** | `boolean` | optional | Several values in one field: true makes the built field hold a list — several related records on a "lookup" / "user", several files on a "file" / "image", several chosen options on a "select". Declarable only on "select" / "lookup" / "user" / "file" / "image" (and redundantly on "multiselect" / "checkboxes" / "tags", which are lists already); `multiple: true` on any other type, "radio" included, is refused by name. A multi-value "select" takes no defaultValue. Carried into the built field by the applier as its `multiple`. Omit it for a single value. | +| **accept** | `string[]` | optional | The upload types a media field ("file" / "image" / "avatar" / "video" / "audio") permits, as MIME types or extensions, e.g. ["application/pdf", "image/*", ".ofd"]. Read only on the media family: on any other type it parses and nothing reads it. Carried into the built field by the applier as its `accept`, which the built field offers to the file picker and checks on write. Omit it to permit any type. | +| **maxSize** | `integer` | optional | The largest file a media field ("file" / "image" / "avatar" / "video" / "audio") takes, in BYTES (a positive integer: 10485760 for 10 MB). Read only on the media family: on any other type it parses and nothing reads it. Carried into the built field by the applier as its `maxSize`, which the built field checks on write against the stored file size. Omit it to set no limit on the field. | ### Allowed Values: `BlueprintField.type` @@ -231,7 +234,10 @@ const result = BlueprintAppSchema.parse(data); | **options** | `{ label: string; value: string; kind?: Enum<'open' \| 'won' \| 'lost'> }[]` | optional | Choices for select / multiselect / radio fields | | **summaryOperations** | `{ object: string; function: Enum<'count' \| 'sum' \| 'avg' \| 'min' \| 'max'>; field?: string; relationshipField?: string; … }` | optional | REQUIRED when `type` is "summary" (a roll-up of child records: 任务总数 / 报名人数 / 合计金额 / 已完成任务数). Names the child object, the aggregation, and — for a qualified count/sum — the condition. A "summary" field without it materializes runtime-dead. | | **expression** | `string` | optional | The CEL body a computed field computes. Two uses. First, REQUIRED when `type` is "formula", e.g. "record.quantity * record.unit_price", or "record.order_no + ' · ' + record.customer.name" for a composed title. A formula reads a lookup / master_detail field's related record ONE hop through it — `record..`, as `record.customer.name` above; the bare `record.customer` is the stored id, and a second hop (`record.customer.owner.name`) is refused at build. A "formula" field without it materializes runtime-dead: the engine builds its formula plan only from fields that HAVE an expression, so the field reads null everywhere, forever. Same failure shape as a "summary" with no `summaryOperations`. Note `nameField` on the object recommends a formula for numbered entities (invoice/ticket) — that formula needs THIS key, or the record title is blank on every card, lookup chip and breadcrumb. A "formula" is computed on read and stored nowhere: it is shown everywhere, but a list cannot sort by it, search does not scan it, and a `sum` / `avg` over it is refused with the one remedy every such refusal prints: "Computed on read, the field stores no value: make it a field of its return type with the same `expression` (computed and stored on write) and aggregate that. Counting records is a different question." Second, the stored computed value that remedy names: the same `expression` on a field of the value's own return type, never a "formula" (`number` / `currency` / `percent` for a quantity or an amount, `date` for a date). The engine computes it from the record on every write and keeps it in a column, so `sum` / `avg` and sort work on it as on any stored field of that type. Use it whenever the value is totalled, averaged or charted: 销售额 = 销量 × 单价 is a "currency" field with "record.quantity * record.unit_price". Name the return type, not "number" for every value: a date expression on a "number" field is refused at every write. A stored expression reads only this record's own fields: a value from a related record stays a "formula" (shown, not totalled) or is a snapshot field written by a flow on the related object when that value changes, and an input that changes over time (the current date, the acting user) is frozen at the write. Omit it on a field that is neither a formula nor a stored computed value. | -| **defaultValue** | `boolean \| number \| string` | optional | The built field's default: the value a new record gets when it is created without one, carried into the object field as its `defaultValue` and stored as written. It must fit `type`, and only these types take one: "boolean" / "toggle" → true or false; "number" / "currency" / "percent" / "rating" / "slider" / "progress" → a number; "text" / "textarea" / "email" / "url" / "phone" / "markdown" / "html" / "richtext" / "code" / "color" → a string; "time" → a time of day, "HH:MM"; "select" / "radio" → the `value` of one of the field's own `options`, never its label. Every other type is refused by name: a date is fixed at design time, a reference or file names no record yet, a multi-value field stores a list, a formula / summary / autonumber is computed, and a credential, signature or structured value has no one value right for every record. A yes/no flag (是否完成 / 已付款 / is_active) is a "boolean" field that is never `required` (omit `required` or set it false) and carries defaultValue false: a required flag refuses the unchecked switch, and a flag with no default is empty, not false, on every record created without it, so a filter on false misses those records. Omit it for a field with no default. | +| **defaultValue** | `boolean \| number \| string` | optional | The built field's default: the value a new record gets when it is created without one, carried into the object field as its `defaultValue` and stored as written. It must fit `type`, and only these types take one: "boolean" / "toggle" → true or false; "number" / "currency" / "percent" / "rating" / "slider" / "progress" → a number; "text" / "textarea" / "email" / "url" / "phone" / "markdown" / "html" / "richtext" / "code" / "color" → a string; "time" → a time of day, "HH:MM"; "select" / "radio" → the `value` of one of the field's own `options`, never its label. Every other type is refused by name, and so is a "select" with `multiple: true`: a date is fixed at design time, a reference or file names no record yet, a multi-value field stores a list, a formula / summary / autonumber is computed, and a credential, signature or structured value has no one value right for every record. A yes/no flag (是否完成 / 已付款 / is_active) is a "boolean" field that is never `required` (omit `required` or set it false) and carries defaultValue false: a required flag refuses the unchecked switch, and a flag with no default is empty, not false, on every record created without it, so a filter on false misses those records. Omit it for a field with no default. | +| **multiple** | `boolean` | optional | Several values in one field: true makes the built field hold a list — several related records on a "lookup" / "user", several files on a "file" / "image", several chosen options on a "select". Declarable only on "select" / "lookup" / "user" / "file" / "image" (and redundantly on "multiselect" / "checkboxes" / "tags", which are lists already); `multiple: true` on any other type, "radio" included, is refused by name. A multi-value "select" takes no defaultValue. Carried into the built field by the applier as its `multiple`. Omit it for a single value. | +| **accept** | `string[]` | optional | The upload types a media field ("file" / "image" / "avatar" / "video" / "audio") permits, as MIME types or extensions, e.g. ["application/pdf", "image/*", ".ofd"]. Read only on the media family: on any other type it parses and nothing reads it. Carried into the built field by the applier as its `accept`, which the built field offers to the file picker and checks on write. Omit it to permit any type. | +| **maxSize** | `integer` | optional | The largest file a media field ("file" / "image" / "avatar" / "video" / "audio") takes, in BYTES (a positive integer: 10485760 for 10 MB). Read only on the media family: on any other type it parses and nothing reads it. Carried into the built field by the applier as its `maxSize`, which the built field checks on write against the stored file size. Omit it to set no limit on the field. | --- diff --git a/packages/spec/api-surface/data.json b/packages/spec/api-surface/data.json index a14e75f2736..27548dce14f 100644 --- a/packages/spec/api-surface/data.json +++ b/packages/spec/api-surface/data.json @@ -1046,6 +1046,7 @@ "matchesLikePattern (function)", "materializeTreeSelfReferences (function)", "missingFieldValues (function)", + "multiDeclarableFieldTypes (function)", "nextUtcCalendarDay (function)", "normalizeFilterComparandTypes (function)", "numberComparandDoorVerdict (function)", diff --git a/packages/spec/authorable-surface/ai.json b/packages/spec/authorable-surface/ai.json index 8f844315fcb..ea7e73ed41a 100644 --- a/packages/spec/authorable-surface/ai.json +++ b/packages/spec/authorable-surface/ai.json @@ -46,9 +46,12 @@ "ai/BlueprintDashboard:label", "ai/BlueprintDashboard:name", "ai/BlueprintDashboard:widgets", + "ai/BlueprintField:accept", "ai/BlueprintField:defaultValue", "ai/BlueprintField:expression", "ai/BlueprintField:label", + "ai/BlueprintField:maxSize", + "ai/BlueprintField:multiple", "ai/BlueprintField:name", "ai/BlueprintField:options", "ai/BlueprintField:reference", diff --git a/packages/spec/export-origins/data.json b/packages/spec/export-origins/data.json index 8a5ab84bb69..55638e65884 100644 --- a/packages/spec/export-origins/data.json +++ b/packages/spec/export-origins/data.json @@ -1032,6 +1032,7 @@ "matchesLikePattern": "src/data/filter.zod.ts#matchesLikePattern (function)", "materializeTreeSelfReferences": "src/data/object.zod.ts#materializeTreeSelfReferences (function)", "missingFieldValues": "src/data/autonumber-format.ts#missingFieldValues (function)", + "multiDeclarableFieldTypes": "src/data/field.zod.ts#multiDeclarableFieldTypes (function)", "nextUtcCalendarDay": "src/data/calendar-day.ts#nextUtcCalendarDay (function)", "normalizeFilterComparandTypes": "src/data/filter-comparand-type.ts#normalizeFilterComparandTypes (function)", "numberComparandDoorVerdict": "src/data/filter-number-comparand-declared-type.ts#numberComparandDoorVerdict (function)", From c45556bf1d8658ddddb07a2010019fcf06675e26 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 04:38:19 +0000 Subject: [PATCH 3/5] fix(spec): refuse option kind on a multi-value blueprint select A select with `multiple: true` holds no single option code per record, so the built field refuses an option `kind` there; the blueprint field now refuses it too, one issue per option at its `kind`, in FieldSchema's wording. The describe, the docblocks and the changeset claim only what the pins measure, and the changeset states what a direct parse now judges instead of stripping. Claude-Session: https://claude.ai/code/session_01ADHkmTKhm2Pn8ghVWNkBbH Co-authored-by: Claude --- ...blueprint-field-multiple-accept-maxsize.md | 5 +- .../spec/src/ai/solution-blueprint.test.ts | 40 ++++++++++++++++ .../spec/src/ai/solution-blueprint.zod.ts | 46 ++++++++++++++++--- packages/spec/src/data/field.zod.ts | 6 +-- 4 files changed, 86 insertions(+), 11 deletions(-) diff --git a/.changeset/34275-blueprint-field-multiple-accept-maxsize.md b/.changeset/34275-blueprint-field-multiple-accept-maxsize.md index cd16caa92a7..7cfa9c1cbf8 100644 --- a/.changeset/34275-blueprint-field-multiple-accept-maxsize.md +++ b/.changeset/34275-blueprint-field-multiple-accept-maxsize.md @@ -13,8 +13,9 @@ Skills-docs: none — `skills/**` teaches no blueprint field key; the blueprint - **`multiple`** (boolean): several values in one field — several related records on a `lookup` / `user`, several files on a `file` / `image`, several chosen options on a `select`. "An expense claim with its e-invoices attached" is now one blueprint field, `{ name: 'invoices', type: 'file', multiple: true }`. - **`accept`** (array of MIME types or extensions) and **`maxSize`** (a positive integer, in bytes): the upload types and the size limit of a media field. -FROM → TO for an author: before, `{ type: 'file', multiple: true }` in a blueprint was refused with `unrecognized_keys` at the field's `multiple`; now it parses, and the applier carries the key into the built field. Nothing an author wrote before parses differently: a field that declares none of the three keys parses exactly as before, and gains no key. +FROM → TO for an author: before, `{ type: 'file', multiple: true }` in a blueprint was refused with `unrecognized_keys` at the field's `multiple`; now it parses, and the applier carries the key into the built field. At the `apply_blueprint` door nothing an author wrote before parses differently: the door refused the three keys, and a field that declares none of them parses exactly as before and gains no key. A direct `BlueprintFieldSchema.parse` (or `SolutionBlueprintSchema.parse`) is different, because it used to strip an undeclared key: FROM `{ type: 'text', multiple: true }`, `{ type: 'file', maxSize: 0 }` or `{ type: 'select', options, multiple: true, defaultValue: 'open' }` parsing with the key silently dropped, TO each refused at that key (`multiple`, `maxSize`, `defaultValue`). The fix is the one the message names: drop the key, or give it a value the field takes. -- **`multiple: true` is refused by name where the built field refuses it.** The blueprint field judges it against `FieldSchema`'s own declarable set, exported as `multiDeclarableFieldTypes()` rather than copied, so the blueprint can propose no `multiple` the built field refuses. A `radio` field is refused as on `FieldSchema`: a radio group is single-choice. The refusal lands on the field's `multiple` and names the types that take it. +- **`multiple: true` is refused by name where the built field refuses it.** The blueprint field judges it against `FieldSchema`'s own declarable set, exported as `multiDeclarableFieldTypes()` rather than copied, so `multiple: true` is refused on exactly the types the built field refuses it on. A `radio` field is refused as on `FieldSchema`: a radio group is single-choice. The refusal lands on the field's `multiple` and names the types that take it. - **A multi-value `select` takes no blueprint `defaultValue`.** It stores a list, and a blueprint default is one value; the built field would refuse the scalar too. The refusal lands on the field's `defaultValue`. +- **A multi-value `select`'s options take no `kind`.** A lifecycle kind says where one record stands, and the field holds no single option code per record; the built field refuses it too. One refusal per option, at that option's `kind`. Such a field is never an object's `stageField` either: the object's stage-field rule refuses it at `stageField`. - **`accept` / `maxSize` outside the media family** parse and are read by nothing, as on `FieldSchema`; the describes say so. diff --git a/packages/spec/src/ai/solution-blueprint.test.ts b/packages/spec/src/ai/solution-blueprint.test.ts index 7af6e8cc295..1f095ec280a 100644 --- a/packages/spec/src/ai/solution-blueprint.test.ts +++ b/packages/spec/src/ai/solution-blueprint.test.ts @@ -2018,6 +2018,46 @@ describe('blueprint field `multiple`, `accept` and `maxSize`', () => { expect(lenientField({ type: 'select', options: OPTIONS, multiple: false, defaultValue: 'open' }).success).toBe(true); }); + it('refuses an option `kind` on a multi-value "select", one issue per option at its `kind`, as the built field does', () => { + const KINDED = [{ label: 'Open', value: 'open', kind: 'open' }, { label: 'Plain', value: 'plain' }, { label: 'Won', value: 'won', kind: 'won' }]; + const result = lenientField({ type: 'select', options: KINDED, multiple: true }); + expect(result.success).toBe(false); + const refused = result.error!.issues.map((i) => ({ path: i.path, code: i.code })); + expect(refused).toEqual([ + { path: ['objects', 0, 'fields', 0, 'options', 0, 'kind'], code: 'custom' }, + { path: ['objects', 0, 'fields', 0, 'options', 2, 'kind'], code: 'custom' }, + ]); + expect(result.error!.issues[0].message).toContain('"invoices" (select)'); + expect(result.error!.issues[0].message).toContain('with `multiple: true`'); + // The built field refuses the same options at the same paths. + const built = FieldSchema.safeParse({ name: 'invoices', label: 'Invoices', type: 'select', options: KINDED, multiple: true }); + expect((built.error?.issues ?? []).map((i) => i.path)).toEqual([['options', 0, 'kind'], ['options', 2, 'kind']]); + // CONTROL: the same kinds on a single-value select parse on both, and so does a multi-value select without kinds. + expect(lenientField({ type: 'select', options: KINDED }).success).toBe(true); + expect(lenientField({ type: 'select', options: KINDED, multiple: false }).success).toBe(true); + expect(FieldSchema.safeParse({ name: 'invoices', label: 'Invoices', type: 'select', options: KINDED }).success).toBe(true); + expect(lenientField({ type: 'select', options: OPTIONS, multiple: true }).success).toBe(true); + // The strict mirror's null kind is absence: no refusal. + const nulled = strictField({ type: 'select', multiple: true, options: OPTIONS.map((o) => ({ ...o, kind: null })) }); + expect(nulled.success).toBe(true); + }); + + it('refuses an object whose stageField names a multi-value "select", at `stageField`', () => { + const object = (multiple: boolean) => SolutionBlueprintSchema.safeParse({ + summary: 's', + objects: [{ + name: 'claim', + stageField: 'status', + fields: [{ name: 'status', type: 'select', multiple, options: [{ label: 'Open', value: 'open' }, { label: 'Paid', value: 'paid' }] }], + }], + }); + const refused = object(true); + expect(refused.success).toBe(false); + expect(refused.error!.issues.map((i) => i.path)).toEqual([['objects', 0, 'stageField']]); + // CONTROL: the single-value select is a stage field (its options still owe a kind, refused at the options). + expect(object(false).error!.issues.map((i) => i.path).some((p) => p.at(-1) === 'stageField')).toBe(false); + }); + it('the describes name where each key applies, pinned against the built field\'s own sets, and promise no build', () => { for (const shape of [lenientShape(), strictShape()]) { const multiple: string = shape.multiple.description; diff --git a/packages/spec/src/ai/solution-blueprint.zod.ts b/packages/spec/src/ai/solution-blueprint.zod.ts index 2f99112682f..0dbf86fe996 100644 --- a/packages/spec/src/ai/solution-blueprint.zod.ts +++ b/packages/spec/src/ai/solution-blueprint.zod.ts @@ -331,10 +331,13 @@ function refuseUnfitDefaultValue(field: unknown, ctx: z.RefinementCtx): void { /** * The refusal of `multiple: true` on a type that cannot hold several values, * judged against `FieldSchema`'s own declarable set - * ({@link multiDeclarableFieldTypes}), so a blueprint can propose no - * `multiple` the built field refuses and miss none it accepts. `radio` is in - * that set and is refused by its own branch, as `FieldSchema` refuses it: a - * radio group is single-choice. Each issue lands on the field's `multiple`. + * ({@link multiDeclarableFieldTypes}), so `multiple: true` is refused here on + * exactly the types `FieldSchema` refuses it on (the blueprint test pins every + * `FieldType`). `radio` is in that set and is refused by its own branch, as + * `FieldSchema` refuses it: a radio group is single-choice. Each issue lands + * on the field's `multiple`. What `multiple: true` rules out on the REST of a + * field is judged by the two rules beside it (a `defaultValue`, an option + * `kind`), each pinned against `FieldSchema` on its own. * * Guarded like the `defaultValue` refusal: it runs on every parse, so a * `type` outside `FieldType` is left to that key's own issue. @@ -360,10 +363,40 @@ function refuseUndeclarableMultiple(field: unknown, ctx: z.RefinementCtx): void + '"checkboxes" / "tags" field. For a single value, drop `multiple`.'); } -/** Both cross-key rules of a blueprint field, in one refinement. */ +/** + * The refusal of an option `kind` on a `select` with `multiple: true` + * (`FieldSchema`'s #23809 rule, in its wording): a lifecycle kind says where + * ONE record stands, and a multi-value select holds no single option code per + * record, so the built field refuses it. One issue per option that declares a + * kind, at that option's `kind`. `radio` with `multiple: true` is left to the + * `multiple` refusal, whose remedy (drop the flag) makes the kinds legal; the + * `multiselect` / `checkboxes` / `tags` kind case is outside this rule. + */ +function refuseKindOnMultiValueSelect(field: unknown, ctx: z.RefinementCtx): void { + if (typeof field !== 'object' || field === null) return; + const { name, type, options, multiple } = field as Record; + if (type !== 'select' || multiple !== true || !Array.isArray(options)) return; + const subject = `Field "${typeof name === 'string' ? name : ''}" (select)`; + options.forEach((option: unknown, index: number) => { + if (typeof option !== 'object' || option === null) return; + const { value, kind } = option as Record; + if (kind === undefined || kind === null) return; + ctx.addIssue({ + code: 'custom', + path: ['options', index, 'kind'], + message: `${subject}: option '${String(value)}' declares \`kind: '${String(kind)}'\`, but \`kind\` is only valid on ` + + 'the options of a single-value `select` or `radio` field (this field is `select` with `multiple: true`): it ' + + 'says where one record stands in its lifecycle, and this field holds no single option code per record. ' + + 'Delete `kind`, or make the field a single-value `select`.', + }); + }); +} + +/** The cross-key rules of a blueprint field, in one refinement. */ function refineBlueprintField(field: unknown, ctx: z.RefinementCtx): void { refuseUnfitDefaultValue(field, ctx); refuseUndeclarableMultiple(field, ctx); + refuseKindOnMultiValueSelect(field, ctx); } /** @@ -384,7 +417,8 @@ const MULTIPLE_RULE = + '"user", several files on a "file" / "image", several chosen options on a "select". Declarable only on "select" / ' + '"lookup" / "user" / "file" / "image" (and redundantly on "multiselect" / "checkboxes" / "tags", which are ' + 'lists already); `multiple: true` on any other type, "radio" included, is refused by name. A multi-value ' - + '"select" takes no defaultValue. Carried into the built field by the applier as its `multiple`.'; + + '"select" takes no defaultValue, and its options take no `kind` (a lifecycle is one value per record, so it is ' + + 'never an object\'s stage field). Carried into the built field by the applier as its `multiple`.'; const MEDIA_TYPES_PHRASE = 'a media field ("file" / "image" / "avatar" / "video" / "audio")'; const ACCEPT_RULE = `The upload types ${MEDIA_TYPES_PHRASE} permits, as MIME types or extensions, e.g. ["application/pdf", "image/*", ` diff --git a/packages/spec/src/data/field.zod.ts b/packages/spec/src/data/field.zod.ts index 1cd656ec4be..08db72289f4 100644 --- a/packages/spec/src/data/field.zod.ts +++ b/packages/spec/src/data/field.zod.ts @@ -193,9 +193,9 @@ export const VALUE_DOMAIN_FIELD_TYPES: ReadonlySet = new Set([ * enumeration goes one revision stale). * * Exported for ONE reader beside this file's superRefine: the AI blueprint - * field (`ai/solution-blueprint.zod.ts`), which refuses `multiple: true` on the - * same types so that a blueprint can never propose a declaration the built - * field refuses. It answers "may an author DECLARE `multiple: true` here", and + * field (`ai/solution-blueprint.zod.ts`), which refuses `multiple: true` on + * exactly the types this file refuses it on, reading this set rather than a + * copy. It answers "may an author DECLARE `multiple: true` here", and * is not a third answer to "is this field multi-valued". That question has * exactly one answer — `isMultiValueField` (`field-value.zod.ts`) — and both of * the sets this one unions stay untouched. From 2f073725bd923a1629f6e30b2798e5e5084e6a27 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 04:43:47 +0000 Subject: [PATCH 4/5] chore(spec): regenerate the blueprint reference page Claude-Session: https://claude.ai/code/session_01ADHkmTKhm2Pn8ghVWNkBbH Co-authored-by: Claude --- content/docs/references/ai/solution-blueprint.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/docs/references/ai/solution-blueprint.mdx b/content/docs/references/ai/solution-blueprint.mdx index c7c35ac6763..026d0e26861 100644 --- a/content/docs/references/ai/solution-blueprint.mdx +++ b/content/docs/references/ai/solution-blueprint.mdx @@ -114,7 +114,7 @@ const result = BlueprintAppSchema.parse(data); | **summaryOperations** | `{ object: string; function: Enum<'count' \| 'sum' \| 'avg' \| 'min' \| 'max'>; field?: string; relationshipField?: string; … }` | optional | REQUIRED when `type` is "summary" (a roll-up of child records: 任务总数 / 报名人数 / 合计金额 / 已完成任务数). Names the child object, the aggregation, and — for a qualified count/sum — the condition. A "summary" field without it materializes runtime-dead. | | **expression** | `string` | optional | The CEL body a computed field computes. Two uses. First, REQUIRED when `type` is "formula", e.g. "record.quantity * record.unit_price", or "record.order_no + ' · ' + record.customer.name" for a composed title. A formula reads a lookup / master_detail field's related record ONE hop through it — `record..`, as `record.customer.name` above; the bare `record.customer` is the stored id, and a second hop (`record.customer.owner.name`) is refused at build. A "formula" field without it materializes runtime-dead: the engine builds its formula plan only from fields that HAVE an expression, so the field reads null everywhere, forever. Same failure shape as a "summary" with no `summaryOperations`. Note `nameField` on the object recommends a formula for numbered entities (invoice/ticket) — that formula needs THIS key, or the record title is blank on every card, lookup chip and breadcrumb. A "formula" is computed on read and stored nowhere: it is shown everywhere, but a list cannot sort by it, search does not scan it, and a `sum` / `avg` over it is refused with the one remedy every such refusal prints: "Computed on read, the field stores no value: make it a field of its return type with the same `expression` (computed and stored on write) and aggregate that. Counting records is a different question." Second, the stored computed value that remedy names: the same `expression` on a field of the value's own return type, never a "formula" (`number` / `currency` / `percent` for a quantity or an amount, `date` for a date). The engine computes it from the record on every write and keeps it in a column, so `sum` / `avg` and sort work on it as on any stored field of that type. Use it whenever the value is totalled, averaged or charted: 销售额 = 销量 × 单价 is a "currency" field with "record.quantity * record.unit_price". Name the return type, not "number" for every value: a date expression on a "number" field is refused at every write. A stored expression reads only this record's own fields: a value from a related record stays a "formula" (shown, not totalled) or is a snapshot field written by a flow on the related object when that value changes, and an input that changes over time (the current date, the acting user) is frozen at the write. Omit it on a field that is neither a formula nor a stored computed value. | | **defaultValue** | `boolean \| number \| string` | optional | The built field's default: the value a new record gets when it is created without one, carried into the object field as its `defaultValue` and stored as written. It must fit `type`, and only these types take one: "boolean" / "toggle" → true or false; "number" / "currency" / "percent" / "rating" / "slider" / "progress" → a number; "text" / "textarea" / "email" / "url" / "phone" / "markdown" / "html" / "richtext" / "code" / "color" → a string; "time" → a time of day, "HH:MM"; "select" / "radio" → the `value` of one of the field's own `options`, never its label. Every other type is refused by name, and so is a "select" with `multiple: true`: a date is fixed at design time, a reference or file names no record yet, a multi-value field stores a list, a formula / summary / autonumber is computed, and a credential, signature or structured value has no one value right for every record. A yes/no flag (是否完成 / 已付款 / is_active) is a "boolean" field that is never `required` (omit `required` or set it false) and carries defaultValue false: a required flag refuses the unchecked switch, and a flag with no default is empty, not false, on every record created without it, so a filter on false misses those records. Omit it for a field with no default. | -| **multiple** | `boolean` | optional | Several values in one field: true makes the built field hold a list — several related records on a "lookup" / "user", several files on a "file" / "image", several chosen options on a "select". Declarable only on "select" / "lookup" / "user" / "file" / "image" (and redundantly on "multiselect" / "checkboxes" / "tags", which are lists already); `multiple: true` on any other type, "radio" included, is refused by name. A multi-value "select" takes no defaultValue. Carried into the built field by the applier as its `multiple`. Omit it for a single value. | +| **multiple** | `boolean` | optional | Several values in one field: true makes the built field hold a list — several related records on a "lookup" / "user", several files on a "file" / "image", several chosen options on a "select". Declarable only on "select" / "lookup" / "user" / "file" / "image" (and redundantly on "multiselect" / "checkboxes" / "tags", which are lists already); `multiple: true` on any other type, "radio" included, is refused by name. A multi-value "select" takes no defaultValue, and its options take no `kind` (a lifecycle is one value per record, so it is never an object's stage field). Carried into the built field by the applier as its `multiple`. Omit it for a single value. | | **accept** | `string[]` | optional | The upload types a media field ("file" / "image" / "avatar" / "video" / "audio") permits, as MIME types or extensions, e.g. ["application/pdf", "image/*", ".ofd"]. Read only on the media family: on any other type it parses and nothing reads it. Carried into the built field by the applier as its `accept`, which the built field offers to the file picker and checks on write. Omit it to permit any type. | | **maxSize** | `integer` | optional | The largest file a media field ("file" / "image" / "avatar" / "video" / "audio") takes, in BYTES (a positive integer: 10485760 for 10 MB). Read only on the media family: on any other type it parses and nothing reads it. Carried into the built field by the applier as its `maxSize`, which the built field checks on write against the stored file size. Omit it to set no limit on the field. | @@ -235,7 +235,7 @@ const result = BlueprintAppSchema.parse(data); | **summaryOperations** | `{ object: string; function: Enum<'count' \| 'sum' \| 'avg' \| 'min' \| 'max'>; field?: string; relationshipField?: string; … }` | optional | REQUIRED when `type` is "summary" (a roll-up of child records: 任务总数 / 报名人数 / 合计金额 / 已完成任务数). Names the child object, the aggregation, and — for a qualified count/sum — the condition. A "summary" field without it materializes runtime-dead. | | **expression** | `string` | optional | The CEL body a computed field computes. Two uses. First, REQUIRED when `type` is "formula", e.g. "record.quantity * record.unit_price", or "record.order_no + ' · ' + record.customer.name" for a composed title. A formula reads a lookup / master_detail field's related record ONE hop through it — `record..`, as `record.customer.name` above; the bare `record.customer` is the stored id, and a second hop (`record.customer.owner.name`) is refused at build. A "formula" field without it materializes runtime-dead: the engine builds its formula plan only from fields that HAVE an expression, so the field reads null everywhere, forever. Same failure shape as a "summary" with no `summaryOperations`. Note `nameField` on the object recommends a formula for numbered entities (invoice/ticket) — that formula needs THIS key, or the record title is blank on every card, lookup chip and breadcrumb. A "formula" is computed on read and stored nowhere: it is shown everywhere, but a list cannot sort by it, search does not scan it, and a `sum` / `avg` over it is refused with the one remedy every such refusal prints: "Computed on read, the field stores no value: make it a field of its return type with the same `expression` (computed and stored on write) and aggregate that. Counting records is a different question." Second, the stored computed value that remedy names: the same `expression` on a field of the value's own return type, never a "formula" (`number` / `currency` / `percent` for a quantity or an amount, `date` for a date). The engine computes it from the record on every write and keeps it in a column, so `sum` / `avg` and sort work on it as on any stored field of that type. Use it whenever the value is totalled, averaged or charted: 销售额 = 销量 × 单价 is a "currency" field with "record.quantity * record.unit_price". Name the return type, not "number" for every value: a date expression on a "number" field is refused at every write. A stored expression reads only this record's own fields: a value from a related record stays a "formula" (shown, not totalled) or is a snapshot field written by a flow on the related object when that value changes, and an input that changes over time (the current date, the acting user) is frozen at the write. Omit it on a field that is neither a formula nor a stored computed value. | | **defaultValue** | `boolean \| number \| string` | optional | The built field's default: the value a new record gets when it is created without one, carried into the object field as its `defaultValue` and stored as written. It must fit `type`, and only these types take one: "boolean" / "toggle" → true or false; "number" / "currency" / "percent" / "rating" / "slider" / "progress" → a number; "text" / "textarea" / "email" / "url" / "phone" / "markdown" / "html" / "richtext" / "code" / "color" → a string; "time" → a time of day, "HH:MM"; "select" / "radio" → the `value` of one of the field's own `options`, never its label. Every other type is refused by name, and so is a "select" with `multiple: true`: a date is fixed at design time, a reference or file names no record yet, a multi-value field stores a list, a formula / summary / autonumber is computed, and a credential, signature or structured value has no one value right for every record. A yes/no flag (是否完成 / 已付款 / is_active) is a "boolean" field that is never `required` (omit `required` or set it false) and carries defaultValue false: a required flag refuses the unchecked switch, and a flag with no default is empty, not false, on every record created without it, so a filter on false misses those records. Omit it for a field with no default. | -| **multiple** | `boolean` | optional | Several values in one field: true makes the built field hold a list — several related records on a "lookup" / "user", several files on a "file" / "image", several chosen options on a "select". Declarable only on "select" / "lookup" / "user" / "file" / "image" (and redundantly on "multiselect" / "checkboxes" / "tags", which are lists already); `multiple: true` on any other type, "radio" included, is refused by name. A multi-value "select" takes no defaultValue. Carried into the built field by the applier as its `multiple`. Omit it for a single value. | +| **multiple** | `boolean` | optional | Several values in one field: true makes the built field hold a list — several related records on a "lookup" / "user", several files on a "file" / "image", several chosen options on a "select". Declarable only on "select" / "lookup" / "user" / "file" / "image" (and redundantly on "multiselect" / "checkboxes" / "tags", which are lists already); `multiple: true` on any other type, "radio" included, is refused by name. A multi-value "select" takes no defaultValue, and its options take no `kind` (a lifecycle is one value per record, so it is never an object's stage field). Carried into the built field by the applier as its `multiple`. Omit it for a single value. | | **accept** | `string[]` | optional | The upload types a media field ("file" / "image" / "avatar" / "video" / "audio") permits, as MIME types or extensions, e.g. ["application/pdf", "image/*", ".ofd"]. Read only on the media family: on any other type it parses and nothing reads it. Carried into the built field by the applier as its `accept`, which the built field offers to the file picker and checks on write. Omit it to permit any type. | | **maxSize** | `integer` | optional | The largest file a media field ("file" / "image" / "avatar" / "video" / "audio") takes, in BYTES (a positive integer: 10485760 for 10 MB). Read only on the media family: on any other type it parses and nothing reads it. Carried into the built field by the applier as its `maxSize`, which the built field checks on write against the stored file size. Omit it to set no limit on the field. | From b8cd61943af04da53e3c3645e77eb28d90b2616e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 04:44:31 +0000 Subject: [PATCH 5/5] chore(spec): regenerate authorable surface after merging main Claude-Session: https://claude.ai/code/session_01ADHkmTKhm2Pn8ghVWNkBbH Co-authored-by: Claude --- packages/spec/authorable-surface/ai.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/spec/authorable-surface/ai.json b/packages/spec/authorable-surface/ai.json index ea7e73ed41a..6ed947a9101 100644 --- a/packages/spec/authorable-surface/ai.json +++ b/packages/spec/authorable-surface/ai.json @@ -379,6 +379,7 @@ "ai/Skill:description", "ai/Skill:instructions", "ai/Skill:label", + "ai/Skill:mcpPrompt", "ai/Skill:name", "ai/Skill:protection", "ai/Skill:surface",