@vedangiitb/qwintly-core 1.4.7 → 1.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/ai/prompts/codegen.prompt.js +2 -2
  2. package/dist/ai/prompts/codegen.prompt.js.map +1 -1
  3. package/dist/ai/prompts/examples/codegen.examples.d.ts.map +1 -1
  4. package/dist/ai/prompts/examples/codegen.examples.js +40 -22
  5. package/dist/ai/prompts/examples/codegen.examples.js.map +1 -1
  6. package/dist/ai/toolLoop/toolLoopRunner.d.ts.map +1 -1
  7. package/dist/ai/toolLoop/toolLoopRunner.js +1 -4
  8. package/dist/ai/toolLoop/toolLoopRunner.js.map +1 -1
  9. package/dist/ai/tools/implementations/factories.d.ts +39 -2
  10. package/dist/ai/tools/implementations/factories.d.ts.map +1 -1
  11. package/dist/ai/tools/implementations/insertElement.impl.d.ts +39 -3
  12. package/dist/ai/tools/implementations/insertElement.impl.d.ts.map +1 -1
  13. package/dist/ai/tools/implementations/insertElement.impl.js +54 -9
  14. package/dist/ai/tools/implementations/insertElement.impl.js.map +1 -1
  15. package/dist/ai/tools/schemas/insertElement.schema.d.ts +107 -2
  16. package/dist/ai/tools/schemas/insertElement.schema.d.ts.map +1 -1
  17. package/dist/ai/tools/schemas/insertElement.schema.js +35 -42
  18. package/dist/ai/tools/schemas/insertElement.schema.js.map +1 -1
  19. package/dist/ai/tools/validators/builderElement.zod.d.ts +88 -2
  20. package/dist/ai/tools/validators/builderElement.zod.d.ts.map +1 -1
  21. package/dist/ai/tools/validators/builderElement.zod.js +22 -21
  22. package/dist/ai/tools/validators/builderElement.zod.js.map +1 -1
  23. package/dist/tests/insertUpdate.impl.test.js +122 -10
  24. package/dist/tests/insertUpdate.impl.test.js.map +1 -1
  25. package/dist/tests/toolLoopRunner.routes.test.js +3 -1
  26. package/dist/tests/toolLoopRunner.routes.test.js.map +1 -1
  27. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"insertElement.impl.js","sourceRoot":"","sources":["../../../../src/ai/tools/implementations/insertElement.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAE/E,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,GAChB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAG3E,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,IAAmB,EAAE,EAAE;IAC7D,MAAM,EAAE,aAAa,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC;IAEnC,OAAO,KAAK,EACV,WAA6C,EAC7C,QAAiB,EACjB,OAAwB,EACxB,QAAiB,EACjB,EAAE;QACF,MAAM,OAAO,GACX,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,IAAI;YACrD,CAAC,CAAE,WAAuC;YAC1C,CAAC,CAAC;gBACE,KAAK,EAAE,WAAW;gBAClB,SAAS,EAAE,QAAQ;gBACnB,SAAS,EAAE,QAAQ;gBACnB,OAAO;aACR,CAAC;QAER,MAAM,UAAU,GAAG,oBAAoB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC3D,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YACxB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,cAAc;gBACrB,YAAY,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE;aACzC,CAAC;QACJ,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACjE,IAAI,CAAC,SAAS;YAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC;QAEtE,MAAM,SAA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AC;QACH,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;QAED,MAAM,KAAK,GAAG,uBAAuB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC;YACH,MAAM,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;YACzC,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,IAAI;gBACb,WAAW,EAAG,QAAgB,CAAC,EAAE;aAClC,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aACxD,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { resolveUnsplashImagesDeep } from \"../../../image/unsplash.service.js\";\nimport type { BuilderElement } from \"../../../types/elements.js\";\nimport {\n ensureElementIds,\n extractAllIdsDeep,\n findElementById,\n resolvePageConfigJsonPath,\n parsePageConfigJson,\n stringifyPageConfigJson,\n writeFileAtomic,\n} from \"../helpers/pageConfigJson.helpers.js\";\nimport { InsertElementArgsZod } from \"../validators/builderElement.zod.js\";\nimport { type WorkspaceDeps } from \"./workspaceDeps.js\";\n\nexport const createInsertElementImpl = (deps: WorkspaceDeps) => {\n const { workspaceRoot, fs } = deps;\n\n return async (\n routeOrArgs: string | Record<string, unknown>,\n parentId?: string,\n element?: BuilderElement,\n beforeId?: string,\n ) => {\n const rawArgs =\n typeof routeOrArgs === \"object\" && routeOrArgs !== null\n ? (routeOrArgs as Record<string, unknown>)\n : {\n route: routeOrArgs,\n parent_id: parentId,\n before_id: beforeId,\n element,\n };\n\n const parsedArgs = InsertElementArgsZod.safeParse(rawArgs);\n if (!parsedArgs.success) {\n return {\n success: false,\n error: \"invalid args\",\n error_detail: parsedArgs.error.flatten(),\n };\n }\n\n const parent_id = String(parsedArgs.data.parent_id ?? \"\").trim();\n if (!parent_id) return { success: false, error: \"invalid parent_id\" };\n\n const before_id = String(parsedArgs.data.before_id ?? \"\").trim();\n\n let configPath: string;\n try {\n configPath = await resolvePageConfigJsonPath(workspaceRoot, parsedArgs.data.route, fs);\n } catch (err) {\n return {\n success: false,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n\n let before = \"\";\n try {\n before = await fs.readFile(configPath);\n } catch (err) {\n const code = (err as NodeJS.ErrnoException | null)?.code;\n if (code === \"ENOENT\") return { success: false, error: \"not found\" };\n return {\n success: false,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n\n let parsed: ReturnType<typeof parsePageConfigJson>;\n try {\n parsed = parsePageConfigJson(before);\n } catch (err) {\n return {\n success: false,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n\n const elements = parsed.elements ?? [];\n const existingIds = extractAllIdsDeep(elements);\n ensureElementIds(elements, existingIds);\n\n // Clone + inject ids for the inserted element subtree.\n const toInsert = JSON.parse(\n JSON.stringify(parsedArgs.data.element ?? null),\n ) as BuilderElement;\n await resolveUnsplashImagesDeep(toInsert);\n ensureElementIds([toInsert], existingIds);\n\n const parent = findElementById(elements, parent_id);\n if (!parent) return { success: false, error: \"parent not found\" };\n\n const anyParent = parent as any;\n if (!anyParent.children || !Array.isArray(anyParent.children))\n anyParent.children = [];\n\n const children = anyParent.children as BuilderElement[];\n if (before_id) {\n const idx = children.findIndex((c: any) => String(c?.id ?? \"\") === before_id);\n if (idx >= 0) {\n children.splice(idx, 0, toInsert);\n } else {\n children.push(toInsert);\n }\n } else {\n children.push(toInsert);\n }\n\n const after = stringifyPageConfigJson({ elements });\n try {\n await writeFileAtomic(configPath, after);\n return {\n success: true,\n changed: true,\n inserted_id: (toInsert as any).id,\n };\n } catch (err) {\n return {\n success: false,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n };\n};\n"]}
1
+ {"version":3,"file":"insertElement.impl.js","sourceRoot":"","sources":["../../../../src/ai/tools/implementations/insertElement.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAE/E,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,GAChB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAG3E,SAAS,eAAe,CAAC,YAAmB;IAC1C,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;IACxE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAe,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE;YACpB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;YACtE,QAAQ,EAAE,EAAE;SACb,CAAC,CAAC;IACL,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC/B,SAAS;QACX,CAAC;QACD,MAAM,UAAU,GAAG,QAAQ,CAA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ACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { resolveUnsplashImagesDeep } from \"../../../image/unsplash.service.js\";\nimport type { BuilderElement } from \"../../../types/elements.js\";\nimport {\n ensureElementIds,\n extractAllIdsDeep,\n findElementById,\n resolvePageConfigJsonPath,\n parsePageConfigJson,\n stringifyPageConfigJson,\n writeFileAtomic,\n} from \"../helpers/pageConfigJson.helpers.js\";\nimport { InsertElementArgsZod } from \"../validators/builderElement.zod.js\";\nimport { type WorkspaceDeps } from \"./workspaceDeps.js\";\n\nfunction reconstructTree(flatElements: any[]): BuilderElement[] {\n const rootFlats = flatElements.filter((el) => el.parentId === \"parent\");\n if (rootFlats.length === 0) {\n throw new Error(\"No root element found with parentId 'parent'\");\n }\n\n const buildMap = new Map<string, any>();\n for (const flat of flatElements) {\n buildMap.set(flat.id, {\n type: flat.type,\n className: flat.className,\n visible: flat.visible,\n props: flat.props ? JSON.parse(JSON.stringify(flat.props)) : undefined,\n children: [],\n });\n }\n\n for (const flat of flatElements) {\n if (flat.parentId === \"parent\") {\n continue;\n }\n const parentNode = buildMap.get(flat.parentId);\n if (!parentNode) {\n throw new Error(\n `Parent element with id '${flat.parentId}' not found in the list`,\n );\n }\n const currentNode = buildMap.get(flat.id);\n if (currentNode) {\n if (!parentNode.children) {\n parentNode.children = [];\n }\n parentNode.children.push(currentNode);\n }\n }\n\n return rootFlats.map((rootFlat) => buildMap.get(rootFlat.id));\n}\n\nexport const createInsertElementImpl = (deps: WorkspaceDeps) => {\n const { workspaceRoot, fs } = deps;\n\n return async (\n routeOrArgs: string | Record<string, unknown>,\n parentId?: string,\n inputElements?: any[],\n beforeId?: string,\n ) => {\n const rawArgs =\n typeof routeOrArgs === \"object\" && routeOrArgs !== null\n ? (routeOrArgs as Record<string, unknown>)\n : {\n route: routeOrArgs,\n parent_id: parentId,\n before_id: beforeId,\n elements: inputElements,\n };\n\n const parsedArgs = InsertElementArgsZod.safeParse(rawArgs);\n if (!parsedArgs.success) {\n return {\n success: false,\n error: \"invalid args\",\n error_detail: parsedArgs.error.flatten(),\n };\n }\n\n const parent_id = String(parsedArgs.data.parent_id ?? \"\").trim();\n if (!parent_id) return { success: false, error: \"invalid parent_id\" };\n\n const before_id = String(parsedArgs.data.before_id ?? \"\").trim();\n\n let configPath: string;\n try {\n configPath = await resolvePageConfigJsonPath(workspaceRoot, parsedArgs.data.route, fs);\n } catch (err) {\n return {\n success: false,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n\n let before = \"\";\n try {\n before = await fs.readFile(configPath);\n } catch (err) {\n const code = (err as NodeJS.ErrnoException | null)?.code;\n if (code === \"ENOENT\") return { success: false, error: \"not found\" };\n return {\n success: false,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n\n let parsed: ReturnType<typeof parsePageConfigJson>;\n try {\n parsed = parsePageConfigJson(before);\n } catch (err) {\n return {\n success: false,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n\n const elements = parsed.elements ?? [];\n const existingIds = extractAllIdsDeep(elements);\n ensureElementIds(elements, existingIds);\n\n // Clone + inject ids for the inserted element subtree.\n let toInsert: BuilderElement[];\n try {\n toInsert = reconstructTree(parsedArgs.data.elements);\n } catch (err) {\n return {\n success: false,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n\n for (const el of toInsert) {\n await resolveUnsplashImagesDeep(el);\n }\n ensureElementIds(toInsert, existingIds);\n\n const parent = findElementById(elements, parent_id);\n if (!parent) return { success: false, error: \"parent not found\" };\n\n const anyParent = parent as any;\n if (!anyParent.children || !Array.isArray(anyParent.children))\n anyParent.children = [];\n\n const children = anyParent.children as BuilderElement[];\n if (before_id) {\n const idx = children.findIndex((c: any) => String(c?.id ?? \"\") === before_id);\n if (idx >= 0) {\n children.splice(idx, 0, ...toInsert);\n } else {\n children.push(...toInsert);\n }\n } else {\n children.push(...toInsert);\n }\n\n const after = stringifyPageConfigJson({ elements });\n try {\n await writeFileAtomic(configPath, after);\n return {\n success: true,\n changed: true,\n inserted_id: (toInsert[0] as any).id,\n inserted_ids: toInsert.map((el: any) => el.id),\n };\n } catch (err) {\n return {\n success: false,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n };\n};\n"]}
@@ -1,6 +1,5 @@
1
1
  import { Type } from "@google/genai";
2
2
  export declare const ELEMENT_TYPES: readonly ["fragment", "div", "text", "image", "button", "input", "textarea", "link", "icon"];
3
- export declare const BuilderElementSchema: any;
4
3
  export declare const InsertElementSchema: {
5
4
  name: string;
6
5
  description: string;
@@ -20,7 +19,113 @@ export declare const InsertElementSchema: {
20
19
  type: Type;
21
20
  description: string;
22
21
  };
23
- element: any;
22
+ elements: {
23
+ type: Type;
24
+ description: string;
25
+ items: {
26
+ type: Type;
27
+ properties: {
28
+ id: {
29
+ type: Type;
30
+ description: string;
31
+ };
32
+ parentId: {
33
+ type: Type;
34
+ description: string;
35
+ };
36
+ type: {
37
+ type: Type;
38
+ enum: readonly ["fragment", "div", "text", "image", "button", "input", "textarea", "link", "icon"];
39
+ description: string;
40
+ };
41
+ className: {
42
+ type: Type;
43
+ description: string;
44
+ };
45
+ visible: {
46
+ type: Type;
47
+ description: string;
48
+ };
49
+ props: {
50
+ type: Type;
51
+ properties: {
52
+ onClick: {
53
+ type: Type;
54
+ properties: {
55
+ kind: {
56
+ type: Type;
57
+ enum: string[];
58
+ description: string;
59
+ };
60
+ href: {
61
+ type: Type;
62
+ description: string;
63
+ };
64
+ replace: {
65
+ type: Type;
66
+ description: string;
67
+ };
68
+ newTab: {
69
+ type: Type;
70
+ description: string;
71
+ };
72
+ };
73
+ required: string[];
74
+ };
75
+ text: {
76
+ type: Type;
77
+ description: string;
78
+ };
79
+ href: {
80
+ type: Type;
81
+ description: string;
82
+ };
83
+ placeholder: {
84
+ type: Type;
85
+ description: string;
86
+ };
87
+ alt: {
88
+ type: Type;
89
+ description: string;
90
+ };
91
+ target: {
92
+ type: Type;
93
+ description: string;
94
+ };
95
+ rel: {
96
+ type: Type;
97
+ description: string;
98
+ };
99
+ value: {
100
+ type: Type;
101
+ description: string;
102
+ };
103
+ type: {
104
+ type: Type;
105
+ description: string;
106
+ };
107
+ name: {
108
+ type: Type;
109
+ description: string;
110
+ };
111
+ size: {
112
+ type: Type;
113
+ description: string;
114
+ };
115
+ color: {
116
+ type: Type;
117
+ description: string;
118
+ };
119
+ strokeWidth: {
120
+ type: Type;
121
+ description: string;
122
+ };
123
+ };
124
+ };
125
+ };
126
+ required: string[];
127
+ };
128
+ };
24
129
  };
25
130
  required: string[];
26
131
  };
@@ -1 +1 @@
1
- {"version":3,"file":"insertElement.schema.d.ts","sourceRoot":"","sources":["../../../../src/ai/tools/schemas/insertElement.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,eAAO,MAAM,aAAa,8FAUhB,CAAC;AA0HX,eAAO,MAAM,oBAAoB,EAAE,GAAkC,CAAC;AAEtE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;CA+B/B,CAAC"}
1
+ {"version":3,"file":"insertElement.schema.d.ts","sourceRoot":"","sources":["../../../../src/ai/tools/schemas/insertElement.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,eAAO,MAAM,aAAa,8FAUhB,CAAC;AAmFX,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6D/B,CAAC"}
@@ -82,44 +82,9 @@ const BuilderElementPropsSchema = {
82
82
  },
83
83
  },
84
84
  };
85
- // NOTE: Gemini tool `parameters` schemas reject `$ref`, so true recursion isn't available here.
86
- // We unroll nesting to a reasonable max depth; for deeper trees, insert in multiple steps.
87
- const buildBuilderElementSchema = (depth) => {
88
- return {
89
- type: Type.OBJECT,
90
- properties: {
91
- type: {
92
- type: Type.STRING,
93
- enum: ELEMENT_TYPES,
94
- description: "Element type to render. Use 'text' for <p>, 'image' forn <img>, 'link' for <a>, 'icon' for Lucide icon, 'fragment' renders children only",
95
- },
96
- className: {
97
- type: Type.STRING,
98
- description: "Tailwind CSS className (Tailwind only)",
99
- },
100
- visible: {
101
- type: Type.BOOLEAN,
102
- description: "Visibility flag",
103
- },
104
- props: BuilderElementPropsSchema,
105
- children: {
106
- type: Type.ARRAY,
107
- description: "Child elements. Each child can itself have children (children[].children[]...)",
108
- items: depth > 0
109
- ? buildBuilderElementSchema(depth - 1)
110
- : {
111
- type: Type.OBJECT,
112
- description: "Max depth reached. Insert deeper children separately using the returned inserted_id as parent_id",
113
- },
114
- },
115
- },
116
- required: ["type"],
117
- };
118
- };
119
- export const BuilderElementSchema = buildBuilderElementSchema(4);
120
85
  export const InsertElementSchema = {
121
86
  name: "insert_element",
122
- description: "Inserts element code. Use element.children to create nested UI. Each child is another BuilderElement and can itself have children.",
87
+ description: "Inserts a tree of UI elements represented as a flat array of elements. One or more elements can have parentId set to 'parent' to be the roots (siblings inserted at the same level). Subsequent children point to their parent using temporary ID references (e.g., parentId set to parent's temporary id).",
123
88
  parameters: {
124
89
  type: Type.OBJECT,
125
90
  properties: {
@@ -131,18 +96,46 @@ export const InsertElementSchema = {
131
96
  },
132
97
  parent_id: {
133
98
  type: Type.STRING,
134
- description: "The parent id to insert the element at.",
99
+ description: "The parent ID to insert the element tree under.",
135
100
  },
136
101
  before_id: {
137
102
  type: Type.STRING,
138
- description: "Optional. If provided, inserts the new element before the existing child element with this id (within parent_id's children list). If not found, appends at the end.",
103
+ description: "Optional. If provided, inserts the new root elements before the existing child element with this id (within parent_id's children list). If not found, appends at the end.",
139
104
  },
140
- element: {
141
- ...BuilderElementSchema,
142
- description: "The element to insert.",
105
+ elements: {
106
+ type: Type.ARRAY,
107
+ description: "Flat array of elements that form a tree. One or more elements can have parentId set to 'parent' to attach directly under the parent_id as siblings. Subsequent child elements should have parentId matching the temporary id of their parent in this array.",
108
+ items: {
109
+ type: Type.OBJECT,
110
+ properties: {
111
+ id: {
112
+ type: Type.STRING,
113
+ description: "A unique temporary ID for this element (e.g. 'root_sec', 'card_bg', 'btn_cta') to refer to it in parentId.",
114
+ },
115
+ parentId: {
116
+ type: Type.STRING,
117
+ description: "The temporary ID of the parent element in this list, or 'parent' to insert directly under the page's parent_id.",
118
+ },
119
+ type: {
120
+ type: Type.STRING,
121
+ enum: ELEMENT_TYPES,
122
+ description: "Element type to render. Use 'text' for <p>, 'image' for <img>, 'link' for <a>, 'icon' for Lucide icon, 'fragment' renders children only",
123
+ },
124
+ className: {
125
+ type: Type.STRING,
126
+ description: "Tailwind CSS className (Tailwind only)",
127
+ },
128
+ visible: {
129
+ type: Type.BOOLEAN,
130
+ description: "Visibility flag",
131
+ },
132
+ props: BuilderElementPropsSchema,
133
+ },
134
+ required: ["id", "parentId", "type"],
135
+ },
143
136
  },
144
137
  },
145
- required: ["route", "parent_id", "element"],
138
+ required: ["route", "parent_id", "elements"],
146
139
  },
147
140
  };
148
141
  //# sourceMappingURL=insertElement.schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"insertElement.schema.js","sourceRoot":"","sources":["../../../../src/ai/tools/schemas/insertElement.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,UAAU;IACV,KAAK;IACL,MAAM;IACN,OAAO;IACP,QAAQ;IACR,OAAO;IACP,UAAU;IACV,MAAM;IACN,MAAM;CACE,CAAC;AAEX,MAAM,mBAAmB,GAAG;IAC1B,IAAI,EAAE,IAAI,CAAC,MAAM;IACjB,UAAU,EAAE;QACV,IAAI,EAAE;YACJ,IAAI,EAAE,IAAI,CAAC,MAAM;YACjB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC;YAC7C,WAAW,EACT,2IAA2I;SAC9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,CAAC,MAAM;QACjB,UAAU,EAAE;YACV,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,0EAA0E;gBAC1E,OAAO,EACL,mHAAmH;gBACrH,WAAW,EACT,qTAAqT;aACxT;YACD,SAAS,EAAE;gBACT,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,WAAW,EAAE,yCAAyC;aACvD;YACD,SAAS,EAAE;gBACT,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,WAAW,EACT,qKAAqK;aACxK;YACD,OAAO,EAAE;gBACP,GAAG,oBAAoB;gBACvB,WAAW,EAAE,wBAAwB;aACtC;SACF;QACD,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,CAAC;KAC5C;CACF,CAAC","sourcesContent":["import { Type } from \"@google/genai\";\r\n\r\nexport const ELEMENT_TYPES = [\r\n \"fragment\",\r\n \"div\",\r\n \"text\",\r\n \"image\",\r\n \"button\",\r\n \"input\",\r\n \"textarea\",\r\n \"link\",\r\n \"icon\",\r\n] as const;\r\n\r\nconst OnClickActionSchema = {\r\n type: Type.OBJECT,\r\n properties: {\r\n kind: {\r\n type: Type.STRING,\r\n enum: [\"route\", \"back\", \"reload\", \"external\"],\r\n description:\r\n \"What happens when the element is clicked. 'route' navigates within the app, 'external' opens a URL, 'back' goes back, 'reload' refreshes.\",\r\n },\r\n href: {\r\n type: Type.STRING,\r\n description:\r\n \"URL to navigate to (used for kind='route' and kind='external').\",\r\n },\r\n replace: {\r\n type: Type.BOOLEAN,\r\n description: \"For kind='route': replace history instead of pushing.\",\r\n },\r\n newTab: {\r\n type: Type.BOOLEAN,\r\n description: \"For kind='external': open link in a new tab.\",\r\n },\r\n },\r\n required: [\"kind\"],\r\n};\r\n\r\nconst BuilderElementPropsSchema = {\r\n type: Type.OBJECT,\r\n properties: {\r\n onClick: OnClickActionSchema,\r\n text: {\r\n type: Type.STRING,\r\n description:\r\n \"Text content used by 'text' (<p>), 'button' (label), and as a fallback for 'link' when it has no children.\",\r\n },\r\n href: {\r\n type: Type.STRING,\r\n description: \"For 'link': the href attribute (defaults to '#').\",\r\n },\r\n placeholder: {\r\n type: Type.STRING,\r\n description: \"For 'input' and 'textarea': placeholder shown when empty.\",\r\n },\r\n alt: {\r\n type: Type.STRING,\r\n description:\r\n \"For 'image': alt text for accessibility AND the query used to fetch a suitable Unsplash image (src is auto-resolved from alt).\",\r\n },\r\n target: {\r\n type: Type.STRING,\r\n description: \"For 'link': target attribute (e.g. '_blank').\",\r\n },\r\n rel: {\r\n type: Type.STRING,\r\n description: \"For 'link': rel attribute (e.g. 'noreferrer').\",\r\n },\r\n value: {\r\n type: Type.STRING,\r\n description:\r\n \"For 'input' and 'textarea': default value (maps to defaultValue).\",\r\n },\r\n type: {\r\n type: Type.STRING,\r\n description:\r\n \"For 'input': input type (e.g. 'text', 'email', 'password'). Defaults to 'text'.\",\r\n },\r\n\r\n // icon\r\n name: {\r\n type: Type.STRING,\r\n description: \"For 'icon': Lucide icon name (e.g. 'ArrowRight', 'Menu').\",\r\n },\r\n size: { type: Type.NUMBER, description: \"For 'icon': size in px.\" },\r\n color: { type: Type.STRING, description: \"For 'icon': stroke color.\" },\r\n strokeWidth: {\r\n type: Type.NUMBER,\r\n description: \"For 'icon': stroke width.\",\r\n },\r\n },\r\n};\r\n\r\n// NOTE: Gemini tool `parameters` schemas reject `$ref`, so true recursion isn't available here.\r\n// We unroll nesting to a reasonable max depth; for deeper trees, insert in multiple steps.\r\nconst buildBuilderElementSchema = (depth: number): any => {\r\n return {\r\n type: Type.OBJECT,\r\n properties: {\r\n type: {\r\n type: Type.STRING,\r\n enum: ELEMENT_TYPES,\r\n description:\r\n \"Element type to render. Use 'text' for <p>, 'image' forn <img>, 'link' for <a>, 'icon' for Lucide icon, 'fragment' renders children only\",\r\n },\r\n className: {\r\n type: Type.STRING,\r\n description: \"Tailwind CSS className (Tailwind only)\",\r\n },\r\n visible: {\r\n type: Type.BOOLEAN,\r\n description: \"Visibility flag\",\r\n },\r\n props: BuilderElementPropsSchema,\r\n children: {\r\n type: Type.ARRAY,\r\n description:\r\n \"Child elements. Each child can itself have children (children[].children[]...)\",\r\n items:\r\n depth > 0\r\n ? buildBuilderElementSchema(depth - 1)\r\n : {\r\n type: Type.OBJECT,\r\n description:\r\n \"Max depth reached. Insert deeper children separately using the returned inserted_id as parent_id\",\r\n },\r\n },\r\n },\r\n required: [\"type\"],\r\n };\r\n};\r\n\r\nexport const BuilderElementSchema: any = buildBuilderElementSchema(4);\r\n\r\nexport const InsertElementSchema = {\n name: \"insert_element\",\n description:\n \"Inserts element code. Use element.children to create nested UI. Each child is another BuilderElement and can itself have children.\",\n parameters: {\n type: Type.OBJECT,\n properties: {\n route: {\n type: Type.STRING,\n // Accept both \"/about\" and \"about\" (caller might omit the leading slash).\n pattern:\n \"^(?:/(?:[A-Za-z0-9_.[\\\\\\\\\\]-]+(?:/[A-Za-z0-9_.[\\\\\\\\\\]-]+)*)?|[A-Za-z0-9_.[\\\\\\\\\\]-]+(?:/[A-Za-z0-9_.[\\\\\\\\\\]-]+)*)$\",\n description:\n \"The route to insert the element at. Use URL paths with forward slashes only. Examples: '/', '/about', '/pricing'. If you forget the leading '/', it will be assumed (e.g. 'about' -> '/about'). Never send Windows-style backslashes (e.g. '\\\\\\\\') or filesystem paths like 'app/pricing'. Never send empty string.\",\n },\n parent_id: {\n type: Type.STRING,\n description: \"The parent id to insert the element at.\",\n },\n before_id: {\n type: Type.STRING,\n description:\n \"Optional. If provided, inserts the new element before the existing child element with this id (within parent_id's children list). If not found, appends at the end.\",\n },\n element: {\n ...BuilderElementSchema,\n description: \"The element to insert.\",\n },\n },\n required: [\"route\", \"parent_id\", \"element\"],\r\n },\r\n};\r\n"]}
1
+ {"version":3,"file":"insertElement.schema.js","sourceRoot":"","sources":["../../../../src/ai/tools/schemas/insertElement.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,MAA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BACV,EAAE,EAAE;4BACF,IAAI,EAAE,IAAI,CAAC,MAAM;4BACjB,WAAW,EAAE,4GAA4G;yBAC1H;wBACD,QAAQ,EAAE;4BACR,IAAI,EAAE,IAAI,CAAC,MAAM;4BACjB,WAAW,EAAE,iHAAiH;yBAC/H;wBACD,IAAI,EAAE;4BACJ,IAAI,EAAE,IAAI,CAAC,MAAM;4BACjB,IAAI,EAAE,aAAa;4BACnB,WAAW,EACT,yIAAyI;yBAC5I;wBACD,SAAS,EAAE;4BACT,IAAI,EAAE,IAAI,CAAC,MAAM;4BACjB,WAAW,EAAE,wCAAwC;yBACtD;wBACD,OAAO,EAAE;4BACP,IAAI,EAAE,IAAI,CAAC,OAAO;4BAClB,WAAW,EAAE,iBAAiB;yBAC/B;wBACD,KAAK,EAAE,yBAAyB;qBACjC;oBACD,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC;iBACrC;aACF;SACF;QACD,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC;KAC7C;CACF,CAAC","sourcesContent":["import { Type } from \"@google/genai\";\n\nexport const ELEMENT_TYPES = [\n \"fragment\",\n \"div\",\n \"text\",\n \"image\",\n \"button\",\n \"input\",\n \"textarea\",\n \"link\",\n \"icon\",\n] as const;\n\nconst OnClickActionSchema = {\n type: Type.OBJECT,\n properties: {\n kind: {\n type: Type.STRING,\n enum: [\"route\", \"back\", \"reload\", \"external\"],\n description:\n \"What happens when the element is clicked. 'route' navigates within the app, 'external' opens a URL, 'back' goes back, 'reload' refreshes.\",\n },\n href: {\n type: Type.STRING,\n description:\n \"URL to navigate to (used for kind='route' and kind='external').\",\n },\n replace: {\n type: Type.BOOLEAN,\n description: \"For kind='route': replace history instead of pushing.\",\n },\n newTab: {\n type: Type.BOOLEAN,\n description: \"For kind='external': open link in a new tab.\",\n },\n },\n required: [\"kind\"],\n};\n\nconst BuilderElementPropsSchema = {\n type: Type.OBJECT,\n properties: {\n onClick: OnClickActionSchema,\n text: {\n type: Type.STRING,\n description:\n \"Text content used by 'text' (<p>), 'button' (label), and as a fallback for 'link' when it has no children.\",\n },\n href: {\n type: Type.STRING,\n description: \"For 'link': the href attribute (defaults to '#').\",\n },\n placeholder: {\n type: Type.STRING,\n description: \"For 'input' and 'textarea': placeholder shown when empty.\",\n },\n alt: {\n type: Type.STRING,\n description:\n \"For 'image': alt text for accessibility AND the query used to fetch a suitable Unsplash image (src is auto-resolved from alt).\",\n },\n target: {\n type: Type.STRING,\n description: \"For 'link': target attribute (e.g. '_blank').\",\n },\n rel: {\n type: Type.STRING,\n description: \"For 'link': rel attribute (e.g. 'noreferrer').\",\n },\n value: {\n type: Type.STRING,\n description:\n \"For 'input' and 'textarea': default value (maps to defaultValue).\",\n },\n type: {\n type: Type.STRING,\n description:\n \"For 'input': input type (e.g. 'text', 'email', 'password'). Defaults to 'text'.\",\n },\n\n // icon\n name: {\n type: Type.STRING,\n description: \"For 'icon': Lucide icon name (e.g. 'ArrowRight', 'Menu').\",\n },\n size: { type: Type.NUMBER, description: \"For 'icon': size in px.\" },\n color: { type: Type.STRING, description: \"For 'icon': stroke color.\" },\n strokeWidth: {\n type: Type.NUMBER,\n description: \"For 'icon': stroke width.\",\n },\n },\n};\n\nexport const InsertElementSchema = {\n name: \"insert_element\",\n description:\n \"Inserts a tree of UI elements represented as a flat array of elements. One or more elements can have parentId set to 'parent' to be the roots (siblings inserted at the same level). Subsequent children point to their parent using temporary ID references (e.g., parentId set to parent's temporary id).\",\n parameters: {\n type: Type.OBJECT,\n properties: {\n route: {\n type: Type.STRING,\n // Accept both \"/about\" and \"about\" (caller might omit the leading slash).\n pattern:\n \"^(?:/(?:[A-Za-z0-9_.[\\\\\\\\\\]-]+(?:/[A-Za-z0-9_.[\\\\\\\\\\]-]+)*)?|[A-Za-z0-9_.[\\\\\\\\\\]-]+(?:/[A-Za-z0-9_.[\\\\\\\\\\]-]+)*)$\",\n description:\n \"The route to insert the element at. Use URL paths with forward slashes only. Examples: '/', '/about', '/pricing'. If you forget the leading '/', it will be assumed (e.g. 'about' -> '/about'). Never send Windows-style backslashes (e.g. '\\\\\\\\') or filesystem paths like 'app/pricing'. Never send empty string.\",\n },\n parent_id: {\n type: Type.STRING,\n description: \"The parent ID to insert the element tree under.\",\n },\n before_id: {\n type: Type.STRING,\n description:\n \"Optional. If provided, inserts the new root elements before the existing child element with this id (within parent_id's children list). If not found, appends at the end.\",\n },\n elements: {\n type: Type.ARRAY,\n description:\n \"Flat array of elements that form a tree. One or more elements can have parentId set to 'parent' to attach directly under the parent_id as siblings. Subsequent child elements should have parentId matching the temporary id of their parent in this array.\",\n items: {\n type: Type.OBJECT,\n properties: {\n id: {\n type: Type.STRING,\n description: \"A unique temporary ID for this element (e.g. 'root_sec', 'card_bg', 'btn_cta') to refer to it in parentId.\",\n },\n parentId: {\n type: Type.STRING,\n description: \"The temporary ID of the parent element in this list, or 'parent' to insert directly under the page's parent_id.\",\n },\n type: {\n type: Type.STRING,\n enum: ELEMENT_TYPES,\n description:\n \"Element type to render. Use 'text' for <p>, 'image' for <img>, 'link' for <a>, 'icon' for Lucide icon, 'fragment' renders children only\",\n },\n className: {\n type: Type.STRING,\n description: \"Tailwind CSS className (Tailwind only)\",\n },\n visible: {\n type: Type.BOOLEAN,\n description: \"Visibility flag\",\n },\n props: BuilderElementPropsSchema,\n },\n required: [\"id\", \"parentId\", \"type\"],\n },\n },\n },\n required: [\"route\", \"parent_id\", \"elements\"],\n },\n};\n"]}
@@ -13,11 +13,97 @@ export declare const OnClickActionZod: z.ZodDiscriminatedUnion<[z.ZodObject<{
13
13
  href: z.ZodString;
14
14
  newTab: z.ZodOptional<z.ZodBoolean>;
15
15
  }, z.core.$strip>], "kind">;
16
- export declare const BuilderElementZod: z.ZodType<any>;
16
+ export declare const FlatBuilderElementZod: z.ZodObject<{
17
+ id: z.ZodString;
18
+ parentId: z.ZodString;
19
+ type: z.ZodEnum<{
20
+ input: "input";
21
+ fragment: "fragment";
22
+ div: "div";
23
+ text: "text";
24
+ image: "image";
25
+ button: "button";
26
+ textarea: "textarea";
27
+ link: "link";
28
+ icon: "icon";
29
+ }>;
30
+ className: z.ZodOptional<z.ZodString>;
31
+ visible: z.ZodOptional<z.ZodBoolean>;
32
+ props: z.ZodOptional<z.ZodObject<{
33
+ onClick: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
34
+ kind: z.ZodLiteral<"route">;
35
+ href: z.ZodPipe<z.ZodTransform<string, unknown>, z.ZodString>;
36
+ replace: z.ZodOptional<z.ZodBoolean>;
37
+ }, z.core.$strip>, z.ZodObject<{
38
+ kind: z.ZodLiteral<"back">;
39
+ }, z.core.$strip>, z.ZodObject<{
40
+ kind: z.ZodLiteral<"reload">;
41
+ }, z.core.$strip>, z.ZodObject<{
42
+ kind: z.ZodLiteral<"external">;
43
+ href: z.ZodString;
44
+ newTab: z.ZodOptional<z.ZodBoolean>;
45
+ }, z.core.$strip>], "kind">>;
46
+ text: z.ZodOptional<z.ZodString>;
47
+ href: z.ZodOptional<z.ZodString>;
48
+ placeholder: z.ZodOptional<z.ZodString>;
49
+ alt: z.ZodOptional<z.ZodString>;
50
+ target: z.ZodOptional<z.ZodString>;
51
+ rel: z.ZodOptional<z.ZodString>;
52
+ value: z.ZodOptional<z.ZodString>;
53
+ type: z.ZodOptional<z.ZodString>;
54
+ name: z.ZodOptional<z.ZodString>;
55
+ size: z.ZodOptional<z.ZodNumber>;
56
+ color: z.ZodOptional<z.ZodString>;
57
+ strokeWidth: z.ZodOptional<z.ZodNumber>;
58
+ }, z.core.$loose>>;
59
+ }, z.core.$strip>;
17
60
  export declare const InsertElementArgsZod: z.ZodObject<{
18
61
  route: z.ZodPipe<z.ZodTransform<string, unknown>, z.ZodString>;
19
62
  parent_id: z.ZodString;
20
63
  before_id: z.ZodOptional<z.ZodString>;
21
- element: z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>;
64
+ elements: z.ZodArray<z.ZodObject<{
65
+ id: z.ZodString;
66
+ parentId: z.ZodString;
67
+ type: z.ZodEnum<{
68
+ input: "input";
69
+ fragment: "fragment";
70
+ div: "div";
71
+ text: "text";
72
+ image: "image";
73
+ button: "button";
74
+ textarea: "textarea";
75
+ link: "link";
76
+ icon: "icon";
77
+ }>;
78
+ className: z.ZodOptional<z.ZodString>;
79
+ visible: z.ZodOptional<z.ZodBoolean>;
80
+ props: z.ZodOptional<z.ZodObject<{
81
+ onClick: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
82
+ kind: z.ZodLiteral<"route">;
83
+ href: z.ZodPipe<z.ZodTransform<string, unknown>, z.ZodString>;
84
+ replace: z.ZodOptional<z.ZodBoolean>;
85
+ }, z.core.$strip>, z.ZodObject<{
86
+ kind: z.ZodLiteral<"back">;
87
+ }, z.core.$strip>, z.ZodObject<{
88
+ kind: z.ZodLiteral<"reload">;
89
+ }, z.core.$strip>, z.ZodObject<{
90
+ kind: z.ZodLiteral<"external">;
91
+ href: z.ZodString;
92
+ newTab: z.ZodOptional<z.ZodBoolean>;
93
+ }, z.core.$strip>], "kind">>;
94
+ text: z.ZodOptional<z.ZodString>;
95
+ href: z.ZodOptional<z.ZodString>;
96
+ placeholder: z.ZodOptional<z.ZodString>;
97
+ alt: z.ZodOptional<z.ZodString>;
98
+ target: z.ZodOptional<z.ZodString>;
99
+ rel: z.ZodOptional<z.ZodString>;
100
+ value: z.ZodOptional<z.ZodString>;
101
+ type: z.ZodOptional<z.ZodString>;
102
+ name: z.ZodOptional<z.ZodString>;
103
+ size: z.ZodOptional<z.ZodNumber>;
104
+ color: z.ZodOptional<z.ZodString>;
105
+ strokeWidth: z.ZodOptional<z.ZodNumber>;
106
+ }, z.core.$loose>>;
107
+ }, z.core.$strip>>;
22
108
  }, z.core.$strip>;
23
109
  //# sourceMappingURL=builderElement.zod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builderElement.zod.d.ts","sourceRoot":"","sources":["../../../../src/ai/tools/validators/builderElement.zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,aAAa,8FAUhB,CAAC;AAoBX,eAAO,MAAM,gBAAgB;;;;;;;;;;;;2BAsB3B,CAAC;AAEH,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAuB3C,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;iBAc/B,CAAC"}
1
+ {"version":3,"file":"builderElement.zod.d.ts","sourceRoot":"","sources":["../../../../src/ai/tools/validators/builderElement.zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,aAAa,8FAUhB,CAAC;AAoBX,eAAO,MAAM,gBAAgB;;;;;;;;;;;;2BAsB3B,CAAC;AAoBH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAOhC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAc/B,CAAC"}
@@ -50,29 +50,30 @@ export const OnClickActionZod = z.discriminatedUnion("kind", [
50
50
  newTab: z.boolean().optional(),
51
51
  }),
52
52
  ]);
53
- export const BuilderElementZod = z.object({
53
+ const BuilderElementPropsZod = z
54
+ .object({
55
+ onClick: OnClickActionZod.optional(),
56
+ text: z.string().optional(),
57
+ href: z.string().optional(),
58
+ placeholder: z.string().optional(),
59
+ alt: z.string().optional(),
60
+ target: z.string().optional(),
61
+ rel: z.string().optional(),
62
+ value: z.string().optional(),
63
+ type: z.string().optional(),
64
+ name: z.string().optional(),
65
+ size: z.number().optional(),
66
+ color: z.string().optional(),
67
+ strokeWidth: z.number().optional(),
68
+ })
69
+ .passthrough();
70
+ export const FlatBuilderElementZod = z.object({
71
+ id: z.string().min(1),
72
+ parentId: z.string().min(1),
54
73
  type: z.enum(ELEMENT_TYPES),
55
74
  className: z.string().optional(),
56
75
  visible: z.boolean().optional(),
57
- props: z
58
- .object({
59
- onClick: OnClickActionZod.optional(),
60
- text: z.string().optional(),
61
- href: z.string().optional(),
62
- placeholder: z.string().optional(),
63
- alt: z.string().optional(),
64
- target: z.string().optional(),
65
- rel: z.string().optional(),
66
- value: z.string().optional(),
67
- type: z.string().optional(),
68
- name: z.string().optional(),
69
- size: z.number().optional(),
70
- color: z.string().optional(),
71
- strokeWidth: z.number().optional(),
72
- })
73
- .passthrough()
74
- .optional(),
75
- children: z.array(z.lazy(() => BuilderElementZod)).optional(),
76
+ props: BuilderElementPropsZod.optional(),
76
77
  });
77
78
  export const InsertElementArgsZod = z.object({
78
79
  route: z.preprocess(normalizeInternalRoutePath, z
@@ -83,6 +84,6 @@ export const InsertElementArgsZod = z.object({
83
84
  })),
84
85
  parent_id: z.string().min(1),
85
86
  before_id: z.string().min(1).optional(),
86
- element: BuilderElementZod,
87
+ elements: z.array(FlatBuilderElementZod).min(1),
87
88
  });
88
89
  //# sourceMappingURL=builderElement.zod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"builderElement.zod.js","sourceRoot":"","sources":["../../../../src/ai/tools/validators/builderElement.zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,UAAU;IACV,KAAK;IACL,MAAM;IACN,OAAO;IACP,QAAQ;IACR,OAAO;IACP,UAAU;IACV,MAAM;IACN,MAAM;CACE,CAAC;AAEX,MAAM,0BAA0B,GAAG,CAAC,KAAc,EAAE,EAAE;IACpD,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACvC,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5C,I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W,EAAE;SACb,QAAQ,EAAE;IACb,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC9D,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,KAAK,EAAE,CAAC,CAAC,UAAU,CACjB,0BAA0B,EAC1B,CAAC;SACE,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,MAAM,CAAC,mBAAmB,EAAE;QAC3B,OAAO,EACL,2EAA2E;KAC9E,CAAC,CACL;IACD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACvC,OAAO,EAAE,iBAAiB;CAC3B,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\n\nexport const ELEMENT_TYPES = [\n \"fragment\",\n \"div\",\n \"text\",\n \"image\",\n \"button\",\n \"input\",\n \"textarea\",\n \"link\",\n \"icon\",\n] as const;\n\nconst normalizeInternalRoutePath = (value: unknown) => {\n const raw = String(value ?? \"\").trim();\n if (!raw) return \"\";\n const forwardOnly = raw.replace(/\\\\/g, \"/\");\n if (forwardOnly === \"/\") return \"/\";\n if (forwardOnly.startsWith(\"/\")) return forwardOnly;\n // Fallback: if caller forgot the leading slash, assume they meant an app route.\n return `/${forwardOnly}`;\n};\n\nconst isInternalRoutePath = (value: string) => {\n const s = normalizeInternalRoutePath(value);\n if (!s) return false;\n if (s.includes(\"\\\\\")) return false;\n // Allow \"/\" or \"/a\" or \"/a/b-c_d\" or \"/product/[id]\" or \"/blog/[...slug]\" or \"/blog/[[...slug]]\"\n return /^\\/(?:[A-Za-z0-9_.[\\]-]+(?:\\/[A-Za-z0-9_.[\\]-]+)*)?$/.test(s);\n};\n\nexport const OnClickActionZod = z.discriminatedUnion(\"kind\", [\n z.object({\n kind: z.literal(\"route\"),\n href: z.preprocess(\n normalizeInternalRoutePath,\n z\n .string()\n .min(1)\n .refine(isInternalRoutePath, {\n message:\n \"href must be an internal route path like '/' or '/pricing' (forward slashes only; no backslashes)\",\n }),\n ),\n replace: z.boolean().optional(),\n }),\n z.object({ kind: z.literal(\"back\") }),\n z.object({ kind: z.literal(\"reload\") }),\n z.object({\n kind: z.literal(\"external\"),\n href: z.string().min(1),\n newTab: z.boolean().optional(),\n }),\n]);\n\nexport const BuilderElementZod: z.ZodType<any> = z.object({\n type: z.enum(ELEMENT_TYPES),\n className: z.string().optional(),\n visible: z.boolean().optional(),\n props: z\n .object({\n onClick: OnClickActionZod.optional(),\n text: z.string().optional(),\n href: z.string().optional(),\n placeholder: z.string().optional(),\n alt: z.string().optional(),\n target: z.string().optional(),\n rel: z.string().optional(),\n value: z.string().optional(),\n type: z.string().optional(),\n name: z.string().optional(),\n size: z.number().optional(),\n color: z.string().optional(),\n strokeWidth: z.number().optional(),\n })\n .passthrough()\n .optional(),\n children: z.array(z.lazy(() => BuilderElementZod)).optional(),\n});\n\nexport const InsertElementArgsZod = z.object({\n route: z.preprocess(\n normalizeInternalRoutePath,\n z\n .string()\n .min(1)\n .refine(isInternalRoutePath, {\n message:\n \"route must be like '/' or '/about' (forward slashes only; no backslashes)\",\n }),\n ),\n parent_id: z.string().min(1),\n before_id: z.string().min(1).optional(),\n element: BuilderElementZod,\n});\n"]}
1
+ {"version":3,"file":"builderElement.zod.js","sourceRoot":"","sources":["../../../../src/ai/tools/validators/builderElement.zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,UAAU;IACV,KAAK;IACL,MAAM;IACN,OAAO;IACP,QAAQ;IACR,OAAO;IACP,UAAU;IACV,MAAM;IACN,MAAM;CACE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AAE,CAAC,QAAQ,EAAE;CACnC,CAAC;KACD,WAAW,EAAE,CAAC;AAEjB,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;IAC3B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC/B,KAAK,EAAE,sBAAsB,CAAC,QAAQ,EAAE;CACzC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,KAAK,EAAE,CAAC,CAAC,UAAU,CACjB,0BAA0B,EAC1B,CAAC;SACE,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,MAAM,CAAC,mBAAmB,EAAE;QAC3B,OAAO,EACL,2EAA2E;KAC9E,CAAC,CACL;IACD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACvC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CAChD,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\n\nexport const ELEMENT_TYPES = [\n \"fragment\",\n \"div\",\n \"text\",\n \"image\",\n \"button\",\n \"input\",\n \"textarea\",\n \"link\",\n \"icon\",\n] as const;\n\nconst normalizeInternalRoutePath = (value: unknown) => {\n const raw = String(value ?? \"\").trim();\n if (!raw) return \"\";\n const forwardOnly = raw.replace(/\\\\/g, \"/\");\n if (forwardOnly === \"/\") return \"/\";\n if (forwardOnly.startsWith(\"/\")) return forwardOnly;\n // Fallback: if caller forgot the leading slash, assume they meant an app route.\n return `/${forwardOnly}`;\n};\n\nconst isInternalRoutePath = (value: string) => {\n const s = normalizeInternalRoutePath(value);\n if (!s) return false;\n if (s.includes(\"\\\\\")) return false;\n // Allow \"/\" or \"/a\" or \"/a/b-c_d\" or \"/product/[id]\" or \"/blog/[...slug]\" or \"/blog/[[...slug]]\"\n return /^\\/(?:[A-Za-z0-9_.[\\]-]+(?:\\/[A-Za-z0-9_.[\\]-]+)*)?$/.test(s);\n};\n\nexport const OnClickActionZod = z.discriminatedUnion(\"kind\", [\n z.object({\n kind: z.literal(\"route\"),\n href: z.preprocess(\n normalizeInternalRoutePath,\n z\n .string()\n .min(1)\n .refine(isInternalRoutePath, {\n message:\n \"href must be an internal route path like '/' or '/pricing' (forward slashes only; no backslashes)\",\n }),\n ),\n replace: z.boolean().optional(),\n }),\n z.object({ kind: z.literal(\"back\") }),\n z.object({ kind: z.literal(\"reload\") }),\n z.object({\n kind: z.literal(\"external\"),\n href: z.string().min(1),\n newTab: z.boolean().optional(),\n }),\n]);\n\nconst BuilderElementPropsZod = z\n .object({\n onClick: OnClickActionZod.optional(),\n text: z.string().optional(),\n href: z.string().optional(),\n placeholder: z.string().optional(),\n alt: z.string().optional(),\n target: z.string().optional(),\n rel: z.string().optional(),\n value: z.string().optional(),\n type: z.string().optional(),\n name: z.string().optional(),\n size: z.number().optional(),\n color: z.string().optional(),\n strokeWidth: z.number().optional(),\n })\n .passthrough();\n\nexport const FlatBuilderElementZod = z.object({\n id: z.string().min(1),\n parentId: z.string().min(1),\n type: z.enum(ELEMENT_TYPES),\n className: z.string().optional(),\n visible: z.boolean().optional(),\n props: BuilderElementPropsZod.optional(),\n});\n\nexport const InsertElementArgsZod = z.object({\n route: z.preprocess(\n normalizeInternalRoutePath,\n z\n .string()\n .min(1)\n .refine(isInternalRoutePath, {\n message:\n \"route must be like '/' or '/about' (forward slashes only; no backslashes)\",\n }),\n ),\n parent_id: z.string().min(1),\n before_id: z.string().min(1).optional(),\n elements: z.array(FlatBuilderElementZod).min(1),\n});\n"]}