Skip to content

Commit 25e2aa4

Browse files
committed
fix(schema): ensure valid default items for Array, ref target for Ref, and fields for Object in AI bulk creation
1 parent 22912f6 commit 25e2aa4

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎apps/dashboard-api/src/controllers/ai.controller.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,10 @@ const collectionCreator = async (req, res, next) => {
260260
type: f.type,
261261
required: !!f.required
262262
};
263-
if (f.type === 'Ref' && f.ref) {
264-
fieldDef.ref = f.ref;
263+
if (f.type === 'Ref') {
264+
fieldDef.ref = f.ref || 'users';
265+
} else if (f.type === 'Array') {
266+
fieldDef.items = f.items || { type: 'String' };
265267
}
266268
return fieldDef;
267269
});

‎apps/python-service/routers/ai.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ async def collection_creator(request: CollectionCreatorRequest, req: Request):
171171
Rules:
172172
1. If the description is vague, ask 2-3 specific clarifying questions and set type: "clarify". You MUST set "schema": null. NEVER ask more than 3 at once.
173173
2. Once you have enough context, propose a schema and set type: "schema".
174-
3. Only use these field types: String, Number, Boolean, Date, Object, Array, Ref.
174+
3. Only use these field types: String, Number, Boolean, Date, Ref, Array. (For Ref, ALWAYS set 'ref' to the referenced collection name e.g. 'users'. Avoid empty Object types).
175175
4. ALWAYS include "createdAt" (type: Date, required: true) in EVERY collection.
176-
5. Suggest Ref to "users" where ownership applies (ownerId, authorId, userId, etc.).
176+
5. Suggest Ref to "users" where ownership applies (ownerId, authorId, userId, etc.) with 'ref': 'users'.
177177
6. NEVER generate a collection named "users" — it is reserved for auth.
178178
7. When the developer confirms satisfaction ("looks good", "yes", "create it", "perfect") -> set type: "complete", set "schema": null, and in your message, clearly tell the developer that their schema is finalized and guide them to click the "Insert All" button in the Schema Preview panel on the right to create the collections in their database. NEVER claim that you have already created the collections yourself.
179179
8. The "schema" field MUST ALWAYS BE AN ARRAY (LIST) OF OBJECTS. Even if you are proposing a single collection, you must wrap it in an array like: `"schema": [ { "collection": "...", "fields": [...] } ]`. If `type` is "clarify" or "complete", you MUST set `"schema": null`.

‎apps/web-dashboard/src/components/CollectionCreatorAgent.jsx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,16 @@ export default function CollectionCreatorAgent({ projectId, onInsertAll }) {
8383
type: f.type,
8484
required: !!f.required
8585
};
86-
if (f.unique !== undefined) fieldDef.unique = !!f.unique;
87-
if (f.ref) fieldDef.ref = f.ref;
88-
if (f.fields) fieldDef.fields = mapSchemaFields(f.fields);
89-
if (f.items) fieldDef.items = mapSchemaFields(f.items);
86+
if (f.type === 'Array') {
87+
fieldDef.items = f.items ? (typeof f.items === 'object' ? f.items : { type: f.items }) : { type: 'String' };
88+
} else if (f.type === 'Object') {
89+
fieldDef.fields = f.fields?.length ? mapSchemaFields(f.fields) : [{ key: 'data', type: 'String', required: false }];
90+
} else if (f.type === 'Ref') {
91+
fieldDef.ref = f.ref || 'users';
92+
}
93+
if (f.unique !== undefined && !['Array', 'Object', 'Ref'].includes(f.type)) {
94+
fieldDef.unique = !!f.unique;
95+
}
9096
return fieldDef;
9197
});
9298
};

0 commit comments

Comments
 (0)