@ikas/code-components-mcp 1.4.0-beta.15 → 1.4.0-beta.150
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.
- package/data/framework.json +88 -11
- package/data/migration.json +10 -4
- package/data/section-templates/add-to-cart/index.tsx +16 -2
- package/data/section-templates/add-to-cart/sub-components/QuantitySelector/index.tsx +11 -3
- package/data/section-templates/add-to-cart/utils/cartLimits.ts +23 -0
- package/data/section-templates/cart-section/sub-components/CartItem/index.tsx +57 -24
- package/data/section-templates/cart-section/sub-components/CartItem/styles.css +14 -0
- package/data/section-templates/cart-section/sub-components/QuantitySelector/index.tsx +11 -3
- package/data/section-templates/header-section/sub-components/CartItem/index.tsx +57 -24
- package/data/section-templates/header-section/sub-components/CartItem/styles.css +14 -0
- package/data/section-templates/header-section/sub-components/QuantitySelector/index.tsx +11 -3
- package/data/section-templates/image-handling/ikas-config-snippet.json +1 -0
- package/data/section-templates/navigation/sub-components/CartItem/index.tsx +57 -24
- package/data/section-templates/navigation/sub-components/CartItem/styles.css +14 -0
- package/data/section-templates/navigation/sub-components/QuantitySelector/index.tsx +11 -3
- package/data/section-templates/product-detail-section/children/ProductDetailAddToCart/index.tsx +16 -2
- package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/components/BackInStockForm/index.tsx +92 -0
- package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/ikas-config-snippet.json +159 -0
- package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/index.tsx +141 -0
- package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/styles.css +47 -0
- package/data/section-templates/product-detail-section/children/ProductDetailBackInStock/types.ts +25 -0
- package/data/section-templates/product-detail-section/ikas-config-snippet.json +1 -0
- package/data/section-templates/product-detail-section/sub-components/Modal/index.tsx +120 -0
- package/data/section-templates/product-detail-section/sub-components/Modal/styles.css +70 -0
- package/data/section-templates/product-detail-section/sub-components/QuantitySelector/index.tsx +11 -3
- package/data/section-templates/product-detail-section/utils/cartLimits.ts +23 -0
- package/data/storefront-api.json +206 -26
- package/data/storefront-types.json +9336 -6021
- package/dist/index.js +1937 -247
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -98,9 +98,16 @@ function loadStorefrontTypes() {
|
|
|
98
98
|
}
|
|
99
99
|
return null;
|
|
100
100
|
}
|
|
101
|
-
const SUBTREE_KINDS = [
|
|
101
|
+
const SUBTREE_KINDS = [
|
|
102
|
+
"children",
|
|
103
|
+
"components",
|
|
104
|
+
"sub-components",
|
|
105
|
+
];
|
|
102
106
|
function normalizeName(value) {
|
|
103
|
-
return value
|
|
107
|
+
return value
|
|
108
|
+
.trim()
|
|
109
|
+
.replace(/^`+|`+$/g, "")
|
|
110
|
+
.trim();
|
|
104
111
|
}
|
|
105
112
|
const storefrontData = loadStorefrontData();
|
|
106
113
|
const frameworkData = loadJsonFile("../data/framework.json");
|
|
@@ -261,7 +268,11 @@ function searchMigrationTopics(query) {
|
|
|
261
268
|
const descScore = matchScore(topic.description, query) * 2;
|
|
262
269
|
const contentScore = matchScore(topic.content, query);
|
|
263
270
|
const tagScore = topic.tags.some((t) => matchScore(t, query) > 0) ? 5 : 0;
|
|
264
|
-
return {
|
|
271
|
+
return {
|
|
272
|
+
key,
|
|
273
|
+
topic,
|
|
274
|
+
score: titleScore + descScore + contentScore + tagScore,
|
|
275
|
+
};
|
|
265
276
|
})
|
|
266
277
|
.filter((item) => item.score > 0)
|
|
267
278
|
.sort((a, b) => b.score - a.score);
|
|
@@ -288,7 +299,7 @@ function analyzeOldTheme(themeJson) {
|
|
|
288
299
|
parts.push(`> **CRITICAL:** The old system (\`@ikas/storefront\`) and the new code-component system (\`@ikas/bp-storefront\`) are **entirely different packages**. Even when type names look the same (e.g., \`IkasImage\`, \`IkasProduct\`), they are different types with different properties. The prop type systems are also completely separate — old theme.json prop types and new ikas.config.json prop types have different semantics even when names match. **Never assume old-system knowledge applies to the new system.** Always use \`get_type_definition\`, \`get_model_guide\`, and \`get_function_doc\` to look up the correct new-system APIs.\n`);
|
|
289
300
|
parts.push(`## Summary Statistics\n`);
|
|
290
301
|
parts.push(`- **Components:** ${components.length}`);
|
|
291
|
-
parts.push(`- **Custom Data Definitions:** ${customData.filter(cd => cd.isRoot).length}`);
|
|
302
|
+
parts.push(`- **Custom Data Definitions:** ${customData.filter((cd) => cd.isRoot).length}`);
|
|
292
303
|
parts.push(`- **Prop Groups:** ${groups.length}`);
|
|
293
304
|
// Component analysis
|
|
294
305
|
parts.push(`\n## Components (${components.length})\n`);
|
|
@@ -327,7 +338,11 @@ function analyzeOldTheme(themeJson) {
|
|
|
327
338
|
const typesSummary = Object.entries(propTypeCounts)
|
|
328
339
|
.map(([t, c]) => `${t}×${c}`)
|
|
329
340
|
.join(", ");
|
|
330
|
-
const headerFooter = comp.isHeader
|
|
341
|
+
const headerFooter = comp.isHeader
|
|
342
|
+
? " [HEADER]"
|
|
343
|
+
: comp.isFooter
|
|
344
|
+
? " [FOOTER]"
|
|
345
|
+
: "";
|
|
331
346
|
parts.push(`### ${comp.displayName || comp.dir || comp.id}${headerFooter}`);
|
|
332
347
|
parts.push(`- **Dir:** \`${comp.dir || "?"}\` | **Props:** ${props.length} (${typesSummary})`);
|
|
333
348
|
parts.push(`- **Recommended new type:** section`);
|
|
@@ -342,7 +357,7 @@ function analyzeOldTheme(themeJson) {
|
|
|
342
357
|
parts.push("");
|
|
343
358
|
}
|
|
344
359
|
// Custom data analysis
|
|
345
|
-
const rootCustomData = customData.filter(cd => cd.isRoot);
|
|
360
|
+
const rootCustomData = customData.filter((cd) => cd.isRoot);
|
|
346
361
|
if (rootCustomData.length > 0) {
|
|
347
362
|
parts.push(`\n## Custom Data Definitions (${rootCustomData.length})\n`);
|
|
348
363
|
for (const cd of rootCustomData) {
|
|
@@ -352,7 +367,9 @@ function analyzeOldTheme(themeJson) {
|
|
|
352
367
|
const describeNested = (items, indent) => {
|
|
353
368
|
const lines = [];
|
|
354
369
|
for (const item of items) {
|
|
355
|
-
const key = item.key
|
|
370
|
+
const key = item.key
|
|
371
|
+
? `\`${item.key}\``
|
|
372
|
+
: item.typescriptName || item.name || "unnamed";
|
|
356
373
|
lines.push(`${indent}- ${key}: ${item.type}${item.isRequired ? " (required)" : ""}`);
|
|
357
374
|
if (item.nestedData && item.nestedData.length > 0) {
|
|
358
375
|
lines.push(...describeNested(item.nestedData, indent + " "));
|
|
@@ -364,7 +381,7 @@ function analyzeOldTheme(themeJson) {
|
|
|
364
381
|
parts.push(...describeNested(cd.nestedData, " "));
|
|
365
382
|
}
|
|
366
383
|
if (cd.enumOptions && cd.enumOptions.length > 0) {
|
|
367
|
-
parts.push(`- **Enum options:** ${cd.enumOptions.map(o => `"${o.value}"`).join(", ")}`);
|
|
384
|
+
parts.push(`- **Enum options:** ${cd.enumOptions.map((o) => `"${o.value}"`).join(", ")}`);
|
|
368
385
|
}
|
|
369
386
|
// Find which components reference this customData
|
|
370
387
|
const referencingComponents = [];
|
|
@@ -446,7 +463,9 @@ function scanSharedSubcomponents(sourceDir) {
|
|
|
446
463
|
const walk = (dir) => {
|
|
447
464
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
448
465
|
if (entry.isDirectory()) {
|
|
449
|
-
if (entry.name === "node_modules" ||
|
|
466
|
+
if (entry.name === "node_modules" ||
|
|
467
|
+
entry.name === "__generated__" ||
|
|
468
|
+
entry.name.startsWith("."))
|
|
450
469
|
continue;
|
|
451
470
|
walk(path.join(dir, entry.name));
|
|
452
471
|
}
|
|
@@ -481,10 +500,14 @@ function scanSharedSubcomponents(sourceDir) {
|
|
|
481
500
|
if (!importPath.startsWith("."))
|
|
482
501
|
continue;
|
|
483
502
|
// Skip imports of generated types, utils, hooks
|
|
484
|
-
if (importPath.includes("__generated__") ||
|
|
503
|
+
if (importPath.includes("__generated__") ||
|
|
504
|
+
importPath.includes("/utils") ||
|
|
505
|
+
importPath.includes("/hooks"))
|
|
485
506
|
continue;
|
|
486
507
|
// Extract base name from path
|
|
487
|
-
const pathSegments = importPath
|
|
508
|
+
const pathSegments = importPath
|
|
509
|
+
.split("/")
|
|
510
|
+
.filter((s) => s && s !== "." && s !== "..");
|
|
488
511
|
if (pathSegments.length === 0)
|
|
489
512
|
continue;
|
|
490
513
|
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
@@ -495,7 +518,10 @@ function scanSharedSubcomponents(sourceDir) {
|
|
|
495
518
|
continue;
|
|
496
519
|
seenInFile.add(key);
|
|
497
520
|
if (!importUsage.has(key)) {
|
|
498
|
-
importUsage.set(key, {
|
|
521
|
+
importUsage.set(key, {
|
|
522
|
+
usingComponents: new Set(),
|
|
523
|
+
rawImportPath: importPath,
|
|
524
|
+
});
|
|
499
525
|
}
|
|
500
526
|
importUsage.get(key).usingComponents.add(componentDir);
|
|
501
527
|
}
|
|
@@ -504,7 +530,7 @@ function scanSharedSubcomponents(sourceDir) {
|
|
|
504
530
|
const shared = [];
|
|
505
531
|
for (const [name, { usingComponents, rawImportPath }] of importUsage) {
|
|
506
532
|
// Don't flag the component itself (e.g., Navbar imports from ../Navbar/something)
|
|
507
|
-
const users = [...usingComponents].filter(c => c !== name);
|
|
533
|
+
const users = [...usingComponents].filter((c) => c !== name);
|
|
508
534
|
if (users.length >= 3) {
|
|
509
535
|
shared.push({ name, usedBy: users.sort(), importPaths: [rawImportPath] });
|
|
510
536
|
}
|
|
@@ -521,7 +547,7 @@ function toKebabCase(s) {
|
|
|
521
547
|
}
|
|
522
548
|
function classifyComplexity(comp, customDataMap) {
|
|
523
549
|
const props = comp.props || [];
|
|
524
|
-
const customCount = props.filter(p => p.type === "CUSTOM").length;
|
|
550
|
+
const customCount = props.filter((p) => p.type === "CUSTOM").length;
|
|
525
551
|
if (customCount === 0 && props.length < 10)
|
|
526
552
|
return "simple";
|
|
527
553
|
// Check for deeply nested CUSTOM (customData referencing another customData)
|
|
@@ -532,7 +558,9 @@ function classifyComplexity(comp, customDataMap) {
|
|
|
532
558
|
if (cd?.nestedData) {
|
|
533
559
|
const hasNested = (items) => {
|
|
534
560
|
for (const item of items) {
|
|
535
|
-
if (item.type === "DYNAMIC_LIST" ||
|
|
561
|
+
if (item.type === "DYNAMIC_LIST" ||
|
|
562
|
+
item.type === "STATIC_LIST" ||
|
|
563
|
+
item.customDataId)
|
|
536
564
|
return true;
|
|
537
565
|
if (item.nestedData && hasNested(item.nestedData))
|
|
538
566
|
return true;
|
|
@@ -564,7 +592,7 @@ function generateMigrationPlan(theme, projectName, oldSourceDir) {
|
|
|
564
592
|
parts.push(`# Theme Migration Plan — \`${projectName}\``);
|
|
565
593
|
parts.push("");
|
|
566
594
|
parts.push(`**Generated:** ${new Date().toISOString().slice(0, 10)}`);
|
|
567
|
-
parts.push(`**Source:** ${components.length} old components, ${customData.filter(cd => cd.isRoot).length} custom data types, ${(theme.pages || []).length} pages`);
|
|
595
|
+
parts.push(`**Source:** ${components.length} old components, ${customData.filter((cd) => cd.isRoot).length} custom data types, ${(theme.pages || []).length} pages`);
|
|
568
596
|
parts.push("");
|
|
569
597
|
parts.push(`> ## READ THIS FIRST`);
|
|
570
598
|
parts.push(`>`);
|
|
@@ -654,16 +682,22 @@ function generateMigrationPlan(theme, projectName, oldSourceDir) {
|
|
|
654
682
|
const cdType = cd.type || "?";
|
|
655
683
|
let shape = "";
|
|
656
684
|
if (cd.type === "ENUM") {
|
|
657
|
-
const opts = (cd.enumOptions || [])
|
|
685
|
+
const opts = (cd.enumOptions || [])
|
|
686
|
+
.map((o) => o.value || o.displayName)
|
|
687
|
+
.filter(Boolean);
|
|
658
688
|
shape = ` — shape: \`enum {${opts.slice(0, 6).join(", ")}${opts.length > 6 ? ", ..." : ""}}\``;
|
|
659
689
|
}
|
|
660
690
|
else if (cd.nestedData && cd.nestedData.length > 0) {
|
|
661
691
|
const first = cd.nestedData[0];
|
|
662
|
-
const fields = (first?.nestedData || cd.nestedData || [])
|
|
692
|
+
const fields = (first?.nestedData || cd.nestedData || [])
|
|
693
|
+
.map((f) => `${f.key || f.name || "?"}: ${f.type || "?"}`)
|
|
694
|
+
.slice(0, 8);
|
|
663
695
|
shape = ` — shape: \`{${fields.join(", ")}}\``;
|
|
664
696
|
}
|
|
665
697
|
const usedBy = cd.id ? usageByCustomDataId.get(cd.id) || [] : [];
|
|
666
|
-
const usedByStr = usedBy.length > 0
|
|
698
|
+
const usedByStr = usedBy.length > 0
|
|
699
|
+
? ` — used by: ${usedBy.slice(0, 6).join(", ")}${usedBy.length > 6 ? `, +${usedBy.length - 6} more` : ""}`
|
|
700
|
+
: ` — _not directly referenced by any section's props (may be nested inside another customData)_`;
|
|
667
701
|
parts.push(`- \`${cdName}\` (${cdType})${shape}${usedByStr}`);
|
|
668
702
|
}
|
|
669
703
|
parts.push("");
|
|
@@ -697,7 +731,11 @@ function generateMigrationPlan(theme, projectName, oldSourceDir) {
|
|
|
697
731
|
const oldName = comp.displayName || comp.dir || comp.id || "Unknown";
|
|
698
732
|
const kebabName = toKebabCase(comp.dir || comp.displayName || comp.id || "unknown");
|
|
699
733
|
const newId = `${projectName}-${kebabName}`;
|
|
700
|
-
const headerFooter = comp.isHeader
|
|
734
|
+
const headerFooter = comp.isHeader
|
|
735
|
+
? " **[HEADER]**"
|
|
736
|
+
: comp.isFooter
|
|
737
|
+
? " **[FOOTER]**"
|
|
738
|
+
: "";
|
|
701
739
|
const propCount = (comp.props || []).length;
|
|
702
740
|
// Detect children from CUSTOM DYNAMIC_LIST props
|
|
703
741
|
const children = [];
|
|
@@ -707,8 +745,13 @@ function generateMigrationPlan(theme, projectName, oldSourceDir) {
|
|
|
707
745
|
if (cd && (cd.type === "DYNAMIC_LIST" || cd.type === "STATIC_LIST")) {
|
|
708
746
|
const itemObj = cd.nestedData?.[0];
|
|
709
747
|
if (itemObj) {
|
|
710
|
-
const childName = itemObj.typescriptName ||
|
|
711
|
-
|
|
748
|
+
const childName = itemObj.typescriptName ||
|
|
749
|
+
(itemObj.name
|
|
750
|
+
? itemObj.name.replace(/[^a-zA-Z0-9]/g, "")
|
|
751
|
+
: `${oldName}Item`);
|
|
752
|
+
const fields = (itemObj.nestedData || [])
|
|
753
|
+
.map((f) => f.key || f.name || "?")
|
|
754
|
+
.slice(0, 8);
|
|
712
755
|
children.push({ propName: p.name || "?", childName, fields });
|
|
713
756
|
}
|
|
714
757
|
}
|
|
@@ -767,11 +810,25 @@ function generateMigrationPlan(theme, projectName, oldSourceDir) {
|
|
|
767
810
|
}
|
|
768
811
|
// Known libraries we detect in old themes and want to flag for replacement
|
|
769
812
|
const KNOWN_LIBRARIES = [
|
|
770
|
-
"swiper",
|
|
771
|
-
"react
|
|
772
|
-
"react
|
|
773
|
-
"
|
|
774
|
-
"
|
|
813
|
+
"swiper",
|
|
814
|
+
"@headlessui/react",
|
|
815
|
+
"@heroicons/react",
|
|
816
|
+
"recharts",
|
|
817
|
+
"react-player",
|
|
818
|
+
"react-simple-star-rating",
|
|
819
|
+
"react-slider",
|
|
820
|
+
"react-compound-slider",
|
|
821
|
+
"react-zoom-pan-pinch",
|
|
822
|
+
"react-hot-toast",
|
|
823
|
+
"react-fast-marquee",
|
|
824
|
+
"react-indiana-drag-scroll",
|
|
825
|
+
"react-simple-typewriter",
|
|
826
|
+
"react-timer-hook",
|
|
827
|
+
"date-fns",
|
|
828
|
+
"slugify",
|
|
829
|
+
"classnames",
|
|
830
|
+
"clsx",
|
|
831
|
+
"@react-pdf/renderer",
|
|
775
832
|
];
|
|
776
833
|
// Heuristic: member-access patterns on old storefront stores/singletons that likely need new-system equivalents
|
|
777
834
|
const OLD_STOREFRONT_CALL_REGEX = /\b(customerStore|cartStore|productStore|categoryStore|orderStore|searchStore|favoritesStore|i18nStore|Router|useStore)\.\w+/g;
|
|
@@ -790,7 +847,8 @@ function scanSectionSource(componentDir, propNames) {
|
|
|
790
847
|
// Collect all .tsx/.ts files in the component dir
|
|
791
848
|
try {
|
|
792
849
|
for (const entry of fs.readdirSync(componentDir, { withFileTypes: true })) {
|
|
793
|
-
if (entry.isFile() &&
|
|
850
|
+
if (entry.isFile() &&
|
|
851
|
+
(entry.name.endsWith(".tsx") || entry.name.endsWith(".ts"))) {
|
|
794
852
|
result.sourceFiles.push(path.join(componentDir, entry.name));
|
|
795
853
|
}
|
|
796
854
|
}
|
|
@@ -807,7 +865,18 @@ function scanSectionSource(componentDir, propNames) {
|
|
|
807
865
|
const subCompSet = new Map();
|
|
808
866
|
const callSet = new Set();
|
|
809
867
|
// Packages we treat as "framework" and don't flag for replacement (but do note in reactPackageUsage)
|
|
810
|
-
const REACT_PACKAGES = new Set([
|
|
868
|
+
const REACT_PACKAGES = new Set([
|
|
869
|
+
"react",
|
|
870
|
+
"react-dom",
|
|
871
|
+
"next",
|
|
872
|
+
"next/link",
|
|
873
|
+
"next/image",
|
|
874
|
+
"next/router",
|
|
875
|
+
"next/head",
|
|
876
|
+
"next/script",
|
|
877
|
+
"mobx-react-lite",
|
|
878
|
+
"mobx",
|
|
879
|
+
]);
|
|
811
880
|
for (const file of result.sourceFiles) {
|
|
812
881
|
let content;
|
|
813
882
|
try {
|
|
@@ -821,7 +890,7 @@ function scanSectionSource(componentDir, propNames) {
|
|
|
821
890
|
while ((m = importRegex.exec(content)) !== null) {
|
|
822
891
|
const p = m[1];
|
|
823
892
|
if (p.startsWith(".")) {
|
|
824
|
-
const segs = p.split("/").filter(s => s && s !== "." && s !== "..");
|
|
893
|
+
const segs = p.split("/").filter((s) => s && s !== "." && s !== "..");
|
|
825
894
|
const last = segs[segs.length - 1];
|
|
826
895
|
if (last && /^[A-Z]/.test(last) && !last.includes("__generated__")) {
|
|
827
896
|
subCompSet.set(last, p);
|
|
@@ -829,7 +898,9 @@ function scanSectionSource(componentDir, propNames) {
|
|
|
829
898
|
}
|
|
830
899
|
else if (!p.startsWith("@ikas/")) {
|
|
831
900
|
// Classify: known library, react-family, or unknown-external
|
|
832
|
-
const base = p.startsWith("@")
|
|
901
|
+
const base = p.startsWith("@")
|
|
902
|
+
? p.split("/").slice(0, 2).join("/")
|
|
903
|
+
: p.split("/")[0];
|
|
833
904
|
if (REACT_PACKAGES.has(p) || REACT_PACKAGES.has(base)) {
|
|
834
905
|
reactSet.add(base);
|
|
835
906
|
}
|
|
@@ -892,7 +963,10 @@ function scanSectionSource(componentDir, propNames) {
|
|
|
892
963
|
}
|
|
893
964
|
}
|
|
894
965
|
}
|
|
895
|
-
result.importedSubComponents = [...subCompSet.entries()].map(([name, p]) => ({
|
|
966
|
+
result.importedSubComponents = [...subCompSet.entries()].map(([name, p]) => ({
|
|
967
|
+
name,
|
|
968
|
+
path: p,
|
|
969
|
+
}));
|
|
896
970
|
result.importedLibraries = [...libSet].sort();
|
|
897
971
|
result.importedUnknownLibraries = [...unknownLibSet].sort();
|
|
898
972
|
result.reactPackageUsage = [...reactSet].sort();
|
|
@@ -908,27 +982,38 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
908
982
|
customDataMap.set(cd.id, cd);
|
|
909
983
|
}
|
|
910
984
|
// Find the component — try match by dir, displayName, id, or new-id
|
|
911
|
-
const target = components.find(c => {
|
|
985
|
+
const target = components.find((c) => {
|
|
912
986
|
if (!c)
|
|
913
987
|
return false;
|
|
914
|
-
if (c.dir === sectionName ||
|
|
988
|
+
if (c.dir === sectionName ||
|
|
989
|
+
c.displayName === sectionName ||
|
|
990
|
+
c.id === sectionName)
|
|
915
991
|
return true;
|
|
916
992
|
const kebab = toKebabCase(c.dir || c.displayName || c.id || "");
|
|
917
993
|
const newId = `${projectName}-${kebab}`;
|
|
918
994
|
return newId === sectionName;
|
|
919
995
|
});
|
|
920
996
|
if (!target) {
|
|
921
|
-
const available = components
|
|
997
|
+
const available = components
|
|
998
|
+
.map((c) => c.dir || c.displayName || c.id)
|
|
999
|
+
.filter(Boolean)
|
|
1000
|
+
.join(", ");
|
|
922
1001
|
return `Section "${sectionName}" not found in theme. Available: ${available}`;
|
|
923
1002
|
}
|
|
924
1003
|
const parts = [];
|
|
925
1004
|
const oldName = target.displayName || target.dir || target.id || "Unknown";
|
|
926
1005
|
const kebabName = toKebabCase(target.dir || target.displayName || target.id || "unknown");
|
|
927
1006
|
const sectionId = `${projectName}-${kebabName}`;
|
|
928
|
-
const sectionPascal = (target.dir || target.displayName || "").replace(/[^a-zA-Z0-9]/g, "") ||
|
|
1007
|
+
const sectionPascal = (target.dir || target.displayName || "").replace(/[^a-zA-Z0-9]/g, "") ||
|
|
1008
|
+
kebabName
|
|
1009
|
+
.split("-")
|
|
1010
|
+
.map((s) => s[0]?.toUpperCase() + s.slice(1))
|
|
1011
|
+
.join("");
|
|
929
1012
|
// Scan the old source for imports, libraries, field usage
|
|
930
|
-
const propNames = (target.props || [])
|
|
931
|
-
|
|
1013
|
+
const propNames = (target.props || [])
|
|
1014
|
+
.map((p) => p.name || "")
|
|
1015
|
+
.filter(Boolean);
|
|
1016
|
+
const sourceScan = oldSourceDir && target.dir
|
|
932
1017
|
? scanSectionSource(path.join(oldSourceDir, target.dir), propNames)
|
|
933
1018
|
: null;
|
|
934
1019
|
parts.push(`# Section Migration Plan: ${oldName}`);
|
|
@@ -974,7 +1059,7 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
974
1059
|
}
|
|
975
1060
|
if (sourceScan.reactPackageUsage.length > 0) {
|
|
976
1061
|
parts.push("");
|
|
977
|
-
parts.push(`**React/Next.js framework imports detected:** ${sourceScan.reactPackageUsage.map(p => `\`${p}\``).join(", ")}. These do NOT carry over — the new system is Preact. See \`get_migration_guide("react-to-preact")\` for conversion patterns (hooks, observer, event types, routing).`);
|
|
1062
|
+
parts.push(`**React/Next.js framework imports detected:** ${sourceScan.reactPackageUsage.map((p) => `\`${p}\``).join(", ")}. These do NOT carry over — the new system is Preact. See \`get_migration_guide("react-to-preact")\` for conversion patterns (hooks, observer, event types, routing).`);
|
|
978
1063
|
}
|
|
979
1064
|
if (sourceScan.oldStorefrontCalls.length > 0) {
|
|
980
1065
|
parts.push("");
|
|
@@ -1020,7 +1105,11 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1020
1105
|
if (oldType === "SLIDER") {
|
|
1021
1106
|
newType = "NUMBER";
|
|
1022
1107
|
notes = `Was SLIDER(min=${p.sliderData?.min}, max=${p.sliderData?.max}) — replace \`.value\` access with direct number`;
|
|
1023
|
-
const prop = {
|
|
1108
|
+
const prop = {
|
|
1109
|
+
name: newName,
|
|
1110
|
+
displayName: p.displayName || newName,
|
|
1111
|
+
type: "NUMBER",
|
|
1112
|
+
};
|
|
1024
1113
|
if (p.isRequired)
|
|
1025
1114
|
prop.required = true;
|
|
1026
1115
|
parentPropsJson.push(prop);
|
|
@@ -1028,7 +1117,11 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1028
1117
|
else if (oldType === "PRODUCT_DETAIL") {
|
|
1029
1118
|
newType = "PRODUCT";
|
|
1030
1119
|
notes = "Renamed — PRODUCT_DETAIL → PRODUCT";
|
|
1031
|
-
const prop = {
|
|
1120
|
+
const prop = {
|
|
1121
|
+
name: newName,
|
|
1122
|
+
displayName: p.displayName || newName,
|
|
1123
|
+
type: "PRODUCT",
|
|
1124
|
+
};
|
|
1032
1125
|
if (p.isRequired)
|
|
1033
1126
|
prop.required = true;
|
|
1034
1127
|
parentPropsJson.push(prop);
|
|
@@ -1039,7 +1132,10 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1039
1132
|
if (cd.type === "DYNAMIC_LIST" || cd.type === "STATIC_LIST") {
|
|
1040
1133
|
// Child component needed
|
|
1041
1134
|
const itemObj = cd.nestedData?.[0];
|
|
1042
|
-
const childName = itemObj?.typescriptName ||
|
|
1135
|
+
const childName = itemObj?.typescriptName ||
|
|
1136
|
+
(itemObj?.name
|
|
1137
|
+
? itemObj.name.replace(/[^a-zA-Z0-9]/g, "")
|
|
1138
|
+
: `${sectionPascal}Item`);
|
|
1043
1139
|
const childProps = [];
|
|
1044
1140
|
const nestedWarnings = [];
|
|
1045
1141
|
for (const f of (itemObj?.nestedData || [])) {
|
|
@@ -1050,11 +1146,18 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1050
1146
|
fType = "NUMBER";
|
|
1051
1147
|
else if (fType === "PRODUCT_DETAIL")
|
|
1052
1148
|
fType = "PRODUCT";
|
|
1053
|
-
else if (fType === "CUSTOM" ||
|
|
1149
|
+
else if (fType === "CUSTOM" ||
|
|
1150
|
+
fType === "DYNAMIC_LIST" ||
|
|
1151
|
+
fType === "STATIC_LIST" ||
|
|
1152
|
+
fType === "OBJECT") {
|
|
1054
1153
|
nestedWarnings.push(`\`${f.key}\` (${fType})`);
|
|
1055
1154
|
fType = "COMPONENT_LIST";
|
|
1056
1155
|
}
|
|
1057
|
-
const prop = {
|
|
1156
|
+
const prop = {
|
|
1157
|
+
name: f.key,
|
|
1158
|
+
displayName: f.name || f.key,
|
|
1159
|
+
type: fType,
|
|
1160
|
+
};
|
|
1058
1161
|
if (f.isRequired)
|
|
1059
1162
|
prop.required = true;
|
|
1060
1163
|
childProps.push(prop);
|
|
@@ -1066,10 +1169,14 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1066
1169
|
if (childProps.length === 0 && sourceScan?.propFieldUsage[oldName]) {
|
|
1067
1170
|
const inferred = sourceScan.propFieldUsage[oldName];
|
|
1068
1171
|
for (const fieldName of inferred) {
|
|
1069
|
-
childProps.push({
|
|
1172
|
+
childProps.push({
|
|
1173
|
+
name: fieldName,
|
|
1174
|
+
displayName: fieldName,
|
|
1175
|
+
type: "TEXT",
|
|
1176
|
+
});
|
|
1070
1177
|
}
|
|
1071
1178
|
if (inferred.length > 0) {
|
|
1072
|
-
notes = `Was CUSTOM → ${cd.type} with empty customData. **Inferred props from source usage:** ${inferred.map(f => `\`${f}\``).join(", ")}. Verify types and required flags — default inferred type is TEXT.`;
|
|
1179
|
+
notes = `Was CUSTOM → ${cd.type} with empty customData. **Inferred props from source usage:** ${inferred.map((f) => `\`${f}\``).join(", ")}. Verify types and required flags — default inferred type is TEXT.`;
|
|
1073
1180
|
}
|
|
1074
1181
|
}
|
|
1075
1182
|
children.push({
|
|
@@ -1098,7 +1205,11 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1098
1205
|
let fType = f.type;
|
|
1099
1206
|
if (fType === "SLIDER")
|
|
1100
1207
|
fType = "NUMBER";
|
|
1101
|
-
const prop = {
|
|
1208
|
+
const prop = {
|
|
1209
|
+
name: f.key,
|
|
1210
|
+
displayName: f.name || f.key,
|
|
1211
|
+
type: fType,
|
|
1212
|
+
};
|
|
1102
1213
|
if (f.isRequired)
|
|
1103
1214
|
prop.required = true;
|
|
1104
1215
|
parentPropsJson.push(prop);
|
|
@@ -1113,7 +1224,8 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1113
1224
|
}
|
|
1114
1225
|
else if (cd.type === "ENUM") {
|
|
1115
1226
|
newType = "ENUM";
|
|
1116
|
-
const enumName = cd.typescriptName ||
|
|
1227
|
+
const enumName = cd.typescriptName ||
|
|
1228
|
+
(cd.name ? cd.name.replace(/[^a-zA-Z0-9]/g, "") : "Enum");
|
|
1117
1229
|
const options = (cd.enumOptions || []).reduce((acc, o) => {
|
|
1118
1230
|
if (o.displayName && o.value)
|
|
1119
1231
|
acc[o.displayName] = o.value;
|
|
@@ -1121,7 +1233,12 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1121
1233
|
}, {});
|
|
1122
1234
|
enumsNeeded.push({ name: enumName, options });
|
|
1123
1235
|
notes = `Was CUSTOM (ENUM) — create enum \`${enumName}\` via \`config add-enum\` first, then reference its enumId here`;
|
|
1124
|
-
const prop = {
|
|
1236
|
+
const prop = {
|
|
1237
|
+
name: newName,
|
|
1238
|
+
displayName: p.displayName || newName,
|
|
1239
|
+
type: "ENUM",
|
|
1240
|
+
enumTypeId: `<ENUM_ID_FROM_add-enum_${enumName}>`,
|
|
1241
|
+
};
|
|
1125
1242
|
if (p.isRequired)
|
|
1126
1243
|
prop.required = true;
|
|
1127
1244
|
parentPropsJson.push(prop);
|
|
@@ -1130,7 +1247,11 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1130
1247
|
}
|
|
1131
1248
|
else {
|
|
1132
1249
|
// Direct mapping
|
|
1133
|
-
const prop = {
|
|
1250
|
+
const prop = {
|
|
1251
|
+
name: newName,
|
|
1252
|
+
displayName: p.displayName || newName,
|
|
1253
|
+
type: newType,
|
|
1254
|
+
};
|
|
1134
1255
|
if (p.isRequired)
|
|
1135
1256
|
prop.required = true;
|
|
1136
1257
|
parentPropsJson.push(prop);
|
|
@@ -1139,7 +1260,9 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1139
1260
|
}
|
|
1140
1261
|
parts.push("");
|
|
1141
1262
|
// Custom Data Decision Callouts — per prop referencing a customData type
|
|
1142
|
-
const customDataPropsForCallouts = (target.props || []).filter((p) => p.type === "CUSTOM" &&
|
|
1263
|
+
const customDataPropsForCallouts = (target.props || []).filter((p) => p.type === "CUSTOM" &&
|
|
1264
|
+
p.customDataId &&
|
|
1265
|
+
customDataMap.has(p.customDataId));
|
|
1143
1266
|
if (customDataPropsForCallouts.length > 0) {
|
|
1144
1267
|
parts.push(`## Custom Data Decisions to Make`);
|
|
1145
1268
|
parts.push("");
|
|
@@ -1154,7 +1277,9 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1154
1277
|
let shape = "";
|
|
1155
1278
|
let shapeKind = "unknown";
|
|
1156
1279
|
if (cd.type === "ENUM") {
|
|
1157
|
-
const opts = (cd.enumOptions || [])
|
|
1280
|
+
const opts = (cd.enumOptions || [])
|
|
1281
|
+
.map((o) => o.value || o.displayName)
|
|
1282
|
+
.filter(Boolean);
|
|
1158
1283
|
shape = `enum {${opts.slice(0, 6).join(", ")}${opts.length > 6 ? ", ..." : ""}}`;
|
|
1159
1284
|
shapeKind = "enum";
|
|
1160
1285
|
}
|
|
@@ -1187,7 +1312,8 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1187
1312
|
if (shapeKind === "enum") {
|
|
1188
1313
|
parts.push(`**Default: enum prop.** Flat scalar set; use \`config add-enum\`.`);
|
|
1189
1314
|
parts.push("");
|
|
1190
|
-
const enumName = cd.typescriptName ||
|
|
1315
|
+
const enumName = cd.typescriptName ||
|
|
1316
|
+
(cd.name ? cd.name.replace(/[^a-zA-Z0-9]/g, "") : "Enum");
|
|
1191
1317
|
const enumOptions = (cd.enumOptions || []).reduce((acc, o) => {
|
|
1192
1318
|
if (o.displayName && o.value)
|
|
1193
1319
|
acc[o.displayName] = o.value;
|
|
@@ -1222,7 +1348,10 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1222
1348
|
parts.push(`> See \`get_migration_guide("component-composition-decision-guide")\` for when \`COMPONENT_LIST\` is overkill.`);
|
|
1223
1349
|
parts.push("");
|
|
1224
1350
|
}
|
|
1225
|
-
const compName = cd.typescriptName ||
|
|
1351
|
+
const compName = cd.typescriptName ||
|
|
1352
|
+
(cd.name
|
|
1353
|
+
? cd.name.replace(/[^a-zA-Z0-9]/g, "")
|
|
1354
|
+
: `${sectionPascal}Item`);
|
|
1226
1355
|
const compPropsForCli = [];
|
|
1227
1356
|
for (const f of fieldSource) {
|
|
1228
1357
|
if (!f.key)
|
|
@@ -1232,7 +1361,11 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1232
1361
|
fType = "NUMBER";
|
|
1233
1362
|
else if (fType === "PRODUCT_DETAIL")
|
|
1234
1363
|
fType = "PRODUCT";
|
|
1235
|
-
compPropsForCli.push({
|
|
1364
|
+
compPropsForCli.push({
|
|
1365
|
+
name: f.key,
|
|
1366
|
+
displayName: f.name || f.key,
|
|
1367
|
+
type: fType,
|
|
1368
|
+
});
|
|
1236
1369
|
}
|
|
1237
1370
|
parts.push("```bash");
|
|
1238
1371
|
if (isMinimal) {
|
|
@@ -1271,7 +1404,10 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1271
1404
|
existing.usedByProps.push(ch.propName);
|
|
1272
1405
|
}
|
|
1273
1406
|
else {
|
|
1274
|
-
uniqueChildren.set(ch.childName, {
|
|
1407
|
+
uniqueChildren.set(ch.childName, {
|
|
1408
|
+
child: ch,
|
|
1409
|
+
usedByProps: [ch.propName],
|
|
1410
|
+
});
|
|
1275
1411
|
}
|
|
1276
1412
|
}
|
|
1277
1413
|
if (uniqueChildren.size > 0) {
|
|
@@ -1284,7 +1420,7 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1284
1420
|
for (const { child: ch, usedByProps } of uniqueChildren.values()) {
|
|
1285
1421
|
parts.push(`### \`${ch.childName}\``);
|
|
1286
1422
|
const propsLabel = usedByProps.length > 1
|
|
1287
|
-
? `Used by parent props: ${usedByProps.map(p => `\`${p}\``).join(", ")} (${usedByProps.length}×)`
|
|
1423
|
+
? `Used by parent props: ${usedByProps.map((p) => `\`${p}\``).join(", ")} (${usedByProps.length}×)`
|
|
1288
1424
|
: `For parent prop: \`${usedByProps[0]}\``;
|
|
1289
1425
|
parts.push(propsLabel);
|
|
1290
1426
|
parts.push(`Old customData: "${ch.customDataName}"`);
|
|
@@ -1330,12 +1466,15 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1330
1466
|
parts.push(`- **Every COMPONENT_LIST slot needs a child component to render individual items.** A product list needs a ProductCard child, a blog list needs a BlogCard child, etc. Check if the child already exists (run \`config list\` to see all components and their opaque ids; reuse the existing id in \`filteredComponentIds\`). If not, create it as a registered component and use the \`componentId\` from the CLI's response.`);
|
|
1331
1467
|
}
|
|
1332
1468
|
// Check if the section itself has data-driven list props (PRODUCT_LIST, BLOG_LIST, CATEGORY_LIST)
|
|
1333
|
-
const dataListProps = (target.props || []).filter(p => p.type === "PRODUCT_LIST" ||
|
|
1469
|
+
const dataListProps = (target.props || []).filter((p) => p.type === "PRODUCT_LIST" ||
|
|
1470
|
+
p.type === "BLOG_LIST" ||
|
|
1471
|
+
p.type === "CATEGORY_LIST" ||
|
|
1472
|
+
p.type === "BRAND_LIST");
|
|
1334
1473
|
if (dataListProps.length > 0) {
|
|
1335
1474
|
parts.push("");
|
|
1336
1475
|
parts.push(`### Data-Driven List Rendering`);
|
|
1337
1476
|
parts.push("");
|
|
1338
|
-
parts.push(`This section has data-driven list props: ${dataListProps.map(p => `\`${p.name}\` (${p.type})`).join(", ")}.`);
|
|
1477
|
+
parts.push(`This section has data-driven list props: ${dataListProps.map((p) => `\`${p.name}\` (${p.type})`).join(", ")}.`);
|
|
1339
1478
|
parts.push(`These are NOT COMPONENT_LIST — the data comes from dynamic queries (filters, categories, search), not hand-picked items. Render items **internally** by mapping over the data:`);
|
|
1340
1479
|
parts.push("");
|
|
1341
1480
|
parts.push("```tsx");
|
|
@@ -1362,9 +1501,22 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1362
1501
|
parts.push(`See \`get_migration_guide("custom-data-conversion")\` → "Two Ways to Render Lists" for the full pattern.`);
|
|
1363
1502
|
}
|
|
1364
1503
|
// Detect form-page sections (0 or few props, name suggests a form/auth page)
|
|
1365
|
-
const formKeywords = [
|
|
1504
|
+
const formKeywords = [
|
|
1505
|
+
"login",
|
|
1506
|
+
"register",
|
|
1507
|
+
"forgot",
|
|
1508
|
+
"recover",
|
|
1509
|
+
"password",
|
|
1510
|
+
"account",
|
|
1511
|
+
"email",
|
|
1512
|
+
"verification",
|
|
1513
|
+
"activate",
|
|
1514
|
+
"contact",
|
|
1515
|
+
"checkout",
|
|
1516
|
+
"address",
|
|
1517
|
+
];
|
|
1366
1518
|
const lowerDir = (target.dir || "").toLowerCase();
|
|
1367
|
-
const isLikelyFormPage = formKeywords.some(kw => lowerDir.includes(kw));
|
|
1519
|
+
const isLikelyFormPage = formKeywords.some((kw) => lowerDir.includes(kw));
|
|
1368
1520
|
if (isLikelyFormPage) {
|
|
1369
1521
|
parts.push("");
|
|
1370
1522
|
parts.push(`### Form Page Pattern`);
|
|
@@ -1393,7 +1545,9 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1393
1545
|
// Fallback heuristic only when source scan unavailable
|
|
1394
1546
|
const heuristicLibs = [];
|
|
1395
1547
|
const lowerName = oldName.toLowerCase();
|
|
1396
|
-
if (lowerName.includes("slider") ||
|
|
1548
|
+
if (lowerName.includes("slider") ||
|
|
1549
|
+
lowerName.includes("carousel") ||
|
|
1550
|
+
lowerName.includes("banner")) {
|
|
1397
1551
|
heuristicLibs.push("swiper");
|
|
1398
1552
|
}
|
|
1399
1553
|
if (lowerName.includes("marquee"))
|
|
@@ -1402,7 +1556,9 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1402
1556
|
heuristicLibs.push("react-player");
|
|
1403
1557
|
if (lowerName.includes("chart"))
|
|
1404
1558
|
heuristicLibs.push("recharts");
|
|
1405
|
-
if (lowerName.includes("star") ||
|
|
1559
|
+
if (lowerName.includes("star") ||
|
|
1560
|
+
lowerName.includes("rating") ||
|
|
1561
|
+
lowerName.includes("review"))
|
|
1406
1562
|
heuristicLibs.push("react-simple-star-rating");
|
|
1407
1563
|
if (heuristicLibs.length > 0) {
|
|
1408
1564
|
parts.push(`### Likely Library Replacements (heuristic — source not scanned)`);
|
|
@@ -1433,10 +1589,26 @@ function generateSectionMigrationPlan(theme, sectionName, projectName, oldSource
|
|
|
1433
1589
|
return parts.join("\n");
|
|
1434
1590
|
}
|
|
1435
1591
|
// --- Search helpers ---
|
|
1592
|
+
/**
|
|
1593
|
+
* Strip every non-alphanumeric character and lowercase, so the SAME identifier written in
|
|
1594
|
+
* different conventions collapses to one form: `PRODUCT_ATTRIBUTE`, `IkasProductAttributeDetail`
|
|
1595
|
+
* and the prose "product attribute detail" all become `productattribute…`. Without this a query
|
|
1596
|
+
* for a prop type (which is always SCREAMING_SNAKE) can never reach the function/type docs that
|
|
1597
|
+
* spell the same concept in camelCase or prose — `search_docs("PRODUCT_ATTRIBUTE")` used to miss
|
|
1598
|
+
* `getAttributeDetailValues` entirely.
|
|
1599
|
+
*/
|
|
1600
|
+
function squashIdentifier(text) {
|
|
1601
|
+
return text.replace(/[^a-z0-9]/gi, "").toLowerCase();
|
|
1602
|
+
}
|
|
1603
|
+
/** A query word worth matching separator-insensitively: an identifier, not prose. */
|
|
1604
|
+
function isIdentifierLike(word) {
|
|
1605
|
+
return (word.length > 3 &&
|
|
1606
|
+
(/[_\-.]/.test(word) || /[a-z][A-Z]/.test(word) || /^[A-Z0-9_]+$/.test(word)));
|
|
1607
|
+
}
|
|
1436
1608
|
function matchScore(text, query) {
|
|
1437
1609
|
const lower = text.toLowerCase();
|
|
1438
1610
|
const queryLower = query.toLowerCase();
|
|
1439
|
-
const words =
|
|
1611
|
+
const words = query.split(/\s+/).filter(Boolean);
|
|
1440
1612
|
let score = 0;
|
|
1441
1613
|
// Exact substring match
|
|
1442
1614
|
if (lower.includes(queryLower)) {
|
|
@@ -1444,9 +1616,18 @@ function matchScore(text, query) {
|
|
|
1444
1616
|
}
|
|
1445
1617
|
// Word matches
|
|
1446
1618
|
for (const word of words) {
|
|
1447
|
-
|
|
1619
|
+
const wordLower = word.toLowerCase();
|
|
1620
|
+
if (lower.includes(wordLower)) {
|
|
1448
1621
|
score += 3;
|
|
1449
1622
|
}
|
|
1623
|
+
else if (isIdentifierLike(word)) {
|
|
1624
|
+
// Same identifier, different convention (PRODUCT_ATTRIBUTE ↔ IkasProductAttributeDetail
|
|
1625
|
+
// ↔ "product attribute"). Scored below an exact word hit so literal matches still win.
|
|
1626
|
+
const squashed = squashIdentifier(word);
|
|
1627
|
+
if (squashed && squashIdentifier(text).includes(squashed)) {
|
|
1628
|
+
score += 2;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1450
1631
|
}
|
|
1451
1632
|
// Name exact match bonus
|
|
1452
1633
|
if (lower === queryLower) {
|
|
@@ -1474,8 +1655,7 @@ function levenshtein(a, b) {
|
|
|
1474
1655
|
const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
|
|
1475
1656
|
curr[j] = Math.min(curr[j - 1] + 1, // insertion
|
|
1476
1657
|
prev[j] + 1, // deletion
|
|
1477
|
-
prev[j - 1] + cost
|
|
1478
|
-
);
|
|
1658
|
+
prev[j - 1] + cost);
|
|
1479
1659
|
}
|
|
1480
1660
|
for (let j = 0; j <= n; j++)
|
|
1481
1661
|
prev[j] = curr[j];
|
|
@@ -1506,17 +1686,29 @@ function searchFunctions(query) {
|
|
|
1506
1686
|
const scored = storefrontData.functions
|
|
1507
1687
|
.map((fn) => {
|
|
1508
1688
|
const nameScore = matchScore(fn.name, query) * 3;
|
|
1509
|
-
const displayNameScore = fn.displayName
|
|
1689
|
+
const displayNameScore = fn.displayName
|
|
1690
|
+
? matchScore(fn.displayName, query) * 3
|
|
1691
|
+
: 0;
|
|
1510
1692
|
const descScore = matchScore(fn.description, query);
|
|
1511
|
-
const catScore = fn.categories.some((c) => matchScore(c, query) > 0)
|
|
1693
|
+
const catScore = fn.categories.some((c) => matchScore(c, query) > 0)
|
|
1694
|
+
? 5
|
|
1695
|
+
: 0;
|
|
1512
1696
|
const paramScore = fn.params.some((p) => matchScore(p.name, query) > 0 || matchScore(p.description, query) > 0)
|
|
1513
1697
|
? 2
|
|
1514
1698
|
: 0;
|
|
1515
1699
|
const sigScore = matchScore(fn.signature, query) * 2;
|
|
1516
|
-
const typeScore = fn.parameterTypes?.some((t) => matchScore(t, query) > 0)
|
|
1700
|
+
const typeScore = fn.parameterTypes?.some((t) => matchScore(t, query) > 0)
|
|
1701
|
+
? 8
|
|
1702
|
+
: 0;
|
|
1517
1703
|
return {
|
|
1518
1704
|
fn,
|
|
1519
|
-
score: nameScore +
|
|
1705
|
+
score: nameScore +
|
|
1706
|
+
displayNameScore +
|
|
1707
|
+
descScore +
|
|
1708
|
+
catScore +
|
|
1709
|
+
paramScore +
|
|
1710
|
+
sigScore +
|
|
1711
|
+
typeScore,
|
|
1520
1712
|
};
|
|
1521
1713
|
})
|
|
1522
1714
|
.filter((item) => item.score > 0)
|
|
@@ -1530,7 +1722,11 @@ function searchFrameworkTopics(query) {
|
|
|
1530
1722
|
const descScore = matchScore(topic.description, query) * 2;
|
|
1531
1723
|
const contentScore = matchScore(topic.content, query);
|
|
1532
1724
|
const tagScore = topic.tags.some((t) => matchScore(t, query) > 0) ? 5 : 0;
|
|
1533
|
-
return {
|
|
1725
|
+
return {
|
|
1726
|
+
key,
|
|
1727
|
+
topic,
|
|
1728
|
+
score: titleScore + descScore + contentScore + tagScore,
|
|
1729
|
+
};
|
|
1534
1730
|
})
|
|
1535
1731
|
.filter((item) => item.score > 0)
|
|
1536
1732
|
.sort((a, b) => b.score - a.score);
|
|
@@ -1545,14 +1741,34 @@ function searchTypes(query) {
|
|
|
1545
1741
|
const propScore = td.properties?.some((p) => matchScore(p.name, query) > 0 || matchScore(p.type, query) > 0)
|
|
1546
1742
|
? 4
|
|
1547
1743
|
: 0;
|
|
1548
|
-
const enumScore = td.enumValues?.some((v) => matchScore(v, query) > 0)
|
|
1549
|
-
|
|
1744
|
+
const enumScore = td.enumValues?.some((v) => matchScore(v, query) > 0)
|
|
1745
|
+
? 4
|
|
1746
|
+
: 0;
|
|
1747
|
+
const unionScore = td.unionValues?.some((v) => matchScore(v, query) > 0)
|
|
1748
|
+
? 4
|
|
1749
|
+
: 0;
|
|
1750
|
+
return {
|
|
1751
|
+
td,
|
|
1752
|
+
score: nameScore + domainScore + propScore + enumScore + unionScore,
|
|
1753
|
+
};
|
|
1550
1754
|
})
|
|
1551
1755
|
.filter((item) => item.score > 0)
|
|
1552
1756
|
.sort((a, b) => b.score - a.score);
|
|
1553
1757
|
return scored.map((item) => item.td);
|
|
1554
1758
|
}
|
|
1555
1759
|
// --- Format helpers ---
|
|
1760
|
+
/**
|
|
1761
|
+
* Wrap a code snippet in a fenced block — unless it already carries its own fence. JSDoc `@example`
|
|
1762
|
+
* bodies are indexed verbatim, so every one of them arrives fenced; wrapping them again produced a
|
|
1763
|
+
* double ```` ``` ```` opener, which makes the block unparseable for anything extracting code from
|
|
1764
|
+
* the doc. Bare snippets still get fenced as typescript.
|
|
1765
|
+
*/
|
|
1766
|
+
function asCodeBlock(snippet) {
|
|
1767
|
+
const trimmed = snippet.trim();
|
|
1768
|
+
return trimmed.startsWith("```")
|
|
1769
|
+
? trimmed
|
|
1770
|
+
: ["```typescript", trimmed, "```"].join("\n");
|
|
1771
|
+
}
|
|
1556
1772
|
function formatFunctionDoc(fn) {
|
|
1557
1773
|
const lines = [];
|
|
1558
1774
|
lines.push(`## ${fn.name}`);
|
|
@@ -1579,7 +1795,7 @@ function formatFunctionDoc(fn) {
|
|
|
1579
1795
|
lines.push("", `**Returns:** \`${fn.returnType}\`${fn.returns ? ` - ${fn.returns}` : ""}`);
|
|
1580
1796
|
}
|
|
1581
1797
|
if (fn.example) {
|
|
1582
|
-
lines.push("", "**Example:**",
|
|
1798
|
+
lines.push("", "**Example:**", asCodeBlock(fn.example));
|
|
1583
1799
|
}
|
|
1584
1800
|
if (fn.related.length > 0) {
|
|
1585
1801
|
lines.push("", `**Related:** ${fn.related.map((r) => `\`${r}\``).join(", ")}`);
|
|
@@ -1587,8 +1803,12 @@ function formatFunctionDoc(fn) {
|
|
|
1587
1803
|
return lines.join("\n");
|
|
1588
1804
|
}
|
|
1589
1805
|
function formatFunctionSummary(fn) {
|
|
1590
|
-
const desc = fn.description
|
|
1591
|
-
|
|
1806
|
+
const desc = fn.description
|
|
1807
|
+
? fn.description.split(".")[0] + "."
|
|
1808
|
+
: "No description.";
|
|
1809
|
+
const alias = fn.displayName && fn.displayName !== fn.name
|
|
1810
|
+
? ` (alias: ${fn.displayName})`
|
|
1811
|
+
: "";
|
|
1592
1812
|
return `- \`${fn.name}\`${alias} - ${desc}`;
|
|
1593
1813
|
}
|
|
1594
1814
|
function formatTypeDefinition(td, opts = {}) {
|
|
@@ -1596,7 +1816,12 @@ function formatTypeDefinition(td, opts = {}) {
|
|
|
1596
1816
|
const lines = [];
|
|
1597
1817
|
lines.push(`## ${td.name}`);
|
|
1598
1818
|
lines.push("", `**Kind:** ${td.kind} | **Domain:** ${td.domain}`);
|
|
1599
|
-
if (td.kind === "type") {
|
|
1819
|
+
if (td.kind === "type" && td.unionValues) {
|
|
1820
|
+
lines.push("", "```typescript");
|
|
1821
|
+
lines.push(`type ${td.name} = ${td.unionValues.map((v) => `"${v}"`).join(" | ")};`);
|
|
1822
|
+
lines.push("```");
|
|
1823
|
+
}
|
|
1824
|
+
else if (td.kind === "type") {
|
|
1600
1825
|
lines.push("", "```typescript");
|
|
1601
1826
|
const extendsStr = td.extends ? ` & ${td.extends.join(" & ")}` : "";
|
|
1602
1827
|
lines.push(`type ${td.name} = {`);
|
|
@@ -1629,7 +1854,9 @@ function formatTypeDefinition(td, opts = {}) {
|
|
|
1629
1854
|
const fn = storefrontData.functions.find((f) => f.name === fnName);
|
|
1630
1855
|
if (fn) {
|
|
1631
1856
|
const desc = fn.description ? fn.description.split(".")[0] + "." : "";
|
|
1632
|
-
const alias = fn.displayName && fn.displayName !== fn.name
|
|
1857
|
+
const alias = fn.displayName && fn.displayName !== fn.name
|
|
1858
|
+
? ` (alias: ${fn.displayName})`
|
|
1859
|
+
: "";
|
|
1633
1860
|
lines.push(`- **\`${fn.name}\`**${alias} — ${desc}`);
|
|
1634
1861
|
lines.push(` \`${fn.signature}\``);
|
|
1635
1862
|
}
|
|
@@ -1638,7 +1865,9 @@ function formatTypeDefinition(td, opts = {}) {
|
|
|
1638
1865
|
}
|
|
1639
1866
|
}
|
|
1640
1867
|
lines.push("");
|
|
1641
|
-
lines.push(
|
|
1868
|
+
lines.push('Use `get_functions_for_type("' +
|
|
1869
|
+
td.name +
|
|
1870
|
+
'")` for full documentation of these functions.');
|
|
1642
1871
|
}
|
|
1643
1872
|
return lines.join("\n");
|
|
1644
1873
|
}
|
|
@@ -1647,6 +1876,10 @@ function formatTypeSummary(td) {
|
|
|
1647
1876
|
const count = td.enumValues?.length ?? 0;
|
|
1648
1877
|
return `- \`${td.name}\` (enum, ${count} values) — domain: ${td.domain}`;
|
|
1649
1878
|
}
|
|
1879
|
+
if (td.unionValues) {
|
|
1880
|
+
const values = td.unionValues.map((v) => `"${v}"`).join(" | ");
|
|
1881
|
+
return `- \`${td.name}\` (union: ${values}) — domain: ${td.domain}`;
|
|
1882
|
+
}
|
|
1650
1883
|
const count = td.properties?.length ?? 0;
|
|
1651
1884
|
const ext = td.extends ? ` extends ${td.extends.join(", ")}` : "";
|
|
1652
1885
|
return `- \`${td.name}\` (${count} properties${ext}) — domain: ${td.domain}`;
|
|
@@ -1656,7 +1889,14 @@ const server = new McpServer({
|
|
|
1656
1889
|
name: "ikas-code-components",
|
|
1657
1890
|
version: "0.1.0",
|
|
1658
1891
|
}, {
|
|
1659
|
-
instructions: "Examples and section templates from this server are API reference only — reuse imports, function calls, and data-access patterns; create your own JSX structure, CSS class names, and visual design
|
|
1892
|
+
instructions: "Examples and section templates from this server are API reference only — reuse imports, function calls, and data-access patterns; create your own JSX structure, CSS class names, and visual design.\n\n" +
|
|
1893
|
+
"Live-editor actions (require `ikas-component dev` running with the editor connected): `list_editor_pages` → page ids; `list_imported_sections` → imported component ids; `import_section` → import a built component; `add_section_to_page` → place one section (`add_sections_to_page` places MANY at once and can set their props in the same call — fastest way to build a page); `list_page_sections` → the sections placed on a page (LEAN roster: per-placement `elementId`, `componentId`, `propCount`, which props are filled — NO schema/values, so it never truncates); `get_component_props` → a component's prop blueprint (types, ENUM valid `options`, COMPONENT_LIST `allowedComponentIds`) for any section OR child id; `get_section_values` → one section's current prop values (for read-modify-write); `get_page_by_type` → a theme page id by pageType (e.g. CATEGORY), to build PAGE links to entities (`create_page` adds that page if it does not exist yet, so you never guess a slug); `update_section_prop` → change a single prop value of a placed section (`update_page_sections` fills MANY sections/props of a page in ONE call — strongly prefer it to cut round-trips when filling content); `upload_image` → upload one image (file or URL) and get an image id (`upload_images` uploads many in one call — prefer it for several); `search_products` / `list_categories` / `list_brands` / `list_blogs` / `list_blog_categories` → find real entity ids for PRODUCT/CATEGORY/BRAND/BLOG/BLOG_CATEGORY prop values; `publish_theme` → publish the theme LIVE and get back the preview URL to review (guarded — needs `confirm:true`, and `confirm_production:true` for the main theme; only call it when the user explicitly asks to publish). For the full end-to-end process (placing a section and filling its content, with per-prop value shapes and COMPONENT_LIST rules), call `get_editor_workflow` first.\n\n" +
|
|
1894
|
+
"To CHANGE/EDIT a prop value (text, color, boolean, number, etc.) of a section that is already on a page, this IS supported: call `list_page_sections(page_id)` to get the placement `elementId` and the prop names/ids, then `update_section_prop(page_id, element_id, prop_name|prop_id, value)`. Do not assume prop editing is unavailable.\n\n" +
|
|
1895
|
+
"TWO DISTINCT JOBS — do not confuse them, and do not jump to writing code for the second one:\n" +
|
|
1896
|
+
"(A) DEFINING props / authoring a component = changing which props a component HAS. This edits the component source/config (types.ts via `ikas-component config add-prop`/`add-component`, JSX in index.tsx, etc.) and requires a rebuild. Use this ONLY when the needed prop does not exist yet, or the user explicitly asks to build/modify the component's code or prop schema.\n" +
|
|
1897
|
+
"(B) SETTING prop VALUES / filling content = giving values to props that ALREADY exist on a section placed on a page. This is pure data entry via `list_page_sections` + `update_section_prop` (and `upload_image` for images). It writes NO code and needs NO rebuild.\n" +
|
|
1898
|
+
"When the user says things like 'fill this section', 'set the heading/title/text/image/link', 'populate', 'change the content/value', or 'enter this data', that is JOB (B): use `update_section_prop`. First call `list_page_sections` and check the existing `props` — if the prop is already there (it usually is), just set its value. Only fall back to JOB (A) if the required prop genuinely does not exist in that section's `props`. Writing a new component or adding a prop to fill in a value the section already supports is the wrong move.\n\n" +
|
|
1899
|
+
"COMMON (GLOBAL) SECTIONS — HEADER & FOOTER: these render on EVERY page and their prop values are shared theme-wide, stored in ONE record on the INDEX (Home) page's placement. Reads and writes from any page are resolved to that record, and every response about such a section carries a `common` block (`isCommon`, `commonSectionType`, `canonicalPageId`, `canonicalElementId`, `valuesArePageSpecific: false`). Consequences: changing a header/footer prop from, say, a product-detail page changes it on ALL pages; and since the header/footer normally already holds the merchant's content, you must `get_section_values` first and change only what the user asked — never treat a prop as empty and never blind-fill 'missing' props, or you overwrite live content everywhere. If the INDEX page has no placement of the section there is no record at all: reads report nothing and writes fail until you add it to the INDEX page.",
|
|
1660
1900
|
});
|
|
1661
1901
|
// Tool: search_docs
|
|
1662
1902
|
server.tool("search_docs", "Search across all ikas storefront API docs, framework guides, and migration guides. Returns matching functions, framework topics, and migration topics ranked by relevance.", { query: z.string().describe("Search keyword or phrase") }, async ({ query }) => {
|
|
@@ -1697,13 +1937,20 @@ server.tool("search_docs", "Search across all ikas storefront API docs, framewor
|
|
|
1697
1937
|
parts.push("");
|
|
1698
1938
|
parts.push("Use `get_migration_guide(topic)` to get full content for any migration topic.");
|
|
1699
1939
|
}
|
|
1700
|
-
if (functions.length === 0 &&
|
|
1940
|
+
if (functions.length === 0 &&
|
|
1941
|
+
topics.length === 0 &&
|
|
1942
|
+
types.length === 0 &&
|
|
1943
|
+
migrationTopics.length === 0) {
|
|
1701
1944
|
parts.push(`No results found for "${query}". Try different keywords or use \`list_functions()\` to see all available functions.`);
|
|
1702
1945
|
}
|
|
1703
1946
|
return { content: [{ type: "text", text: parts.join("\n") }] };
|
|
1704
1947
|
});
|
|
1705
1948
|
// Tool: get_function_doc
|
|
1706
|
-
server.tool("get_function_doc", "Get full documentation for a specific storefront API function including signature, parameters, return type, and example.", {
|
|
1949
|
+
server.tool("get_function_doc", "Get full documentation for a specific storefront API function including signature, parameters, return type, and example.", {
|
|
1950
|
+
name: z
|
|
1951
|
+
.string()
|
|
1952
|
+
.describe("Function name (e.g. 'addItemToCart', 'Router.navigate')"),
|
|
1953
|
+
}, async ({ name }) => {
|
|
1707
1954
|
const nameLower = name.toLowerCase();
|
|
1708
1955
|
// Phase 1: canonical-name match wins. A real function name always outranks
|
|
1709
1956
|
// any displayName alias so aliases can never shadow the function they're
|
|
@@ -1711,7 +1958,9 @@ server.tool("get_function_doc", "Get full documentation for a specific storefron
|
|
|
1711
1958
|
// [BP-DISPLAY-NAME: hasCustomer] alias).
|
|
1712
1959
|
const byName = storefrontData.functions.find((f) => f.name.toLowerCase() === nameLower);
|
|
1713
1960
|
if (byName) {
|
|
1714
|
-
return {
|
|
1961
|
+
return {
|
|
1962
|
+
content: [{ type: "text", text: formatFunctionDoc(byName) }],
|
|
1963
|
+
};
|
|
1715
1964
|
}
|
|
1716
1965
|
// Phase 2: fall back to displayName aliases.
|
|
1717
1966
|
const byAlias = storefrontData.functions.filter((f) => f.displayName && f.displayName.toLowerCase() === nameLower);
|
|
@@ -1719,7 +1968,9 @@ server.tool("get_function_doc", "Get full documentation for a specific storefron
|
|
|
1719
1968
|
const fn = byAlias[0];
|
|
1720
1969
|
const note = `> Note: "${name}" is a display alias for \`${fn.name}\`.\n\n`;
|
|
1721
1970
|
return {
|
|
1722
|
-
content: [
|
|
1971
|
+
content: [
|
|
1972
|
+
{ type: "text", text: note + formatFunctionDoc(fn) },
|
|
1973
|
+
],
|
|
1723
1974
|
};
|
|
1724
1975
|
}
|
|
1725
1976
|
if (byAlias.length > 1) {
|
|
@@ -1737,7 +1988,9 @@ server.tool("get_function_doc", "Get full documentation for a specific storefron
|
|
|
1737
1988
|
(f.displayName && f.displayName.toLowerCase().includes(nameLower)));
|
|
1738
1989
|
if (matches.length > 0) {
|
|
1739
1990
|
const suggestions = matches.slice(0, 5).map((f) => {
|
|
1740
|
-
const alias = f.displayName && f.displayName !== f.name
|
|
1991
|
+
const alias = f.displayName && f.displayName !== f.name
|
|
1992
|
+
? ` (alias: ${f.displayName})`
|
|
1993
|
+
: "";
|
|
1741
1994
|
return ` - ${f.name}${alias}`;
|
|
1742
1995
|
});
|
|
1743
1996
|
return {
|
|
@@ -1750,7 +2003,12 @@ server.tool("get_function_doc", "Get full documentation for a specific storefron
|
|
|
1750
2003
|
};
|
|
1751
2004
|
}
|
|
1752
2005
|
return {
|
|
1753
|
-
content: [
|
|
2006
|
+
content: [
|
|
2007
|
+
{
|
|
2008
|
+
type: "text",
|
|
2009
|
+
text: `Function "${name}" not found. Use \`list_functions()\` to see all available functions.`,
|
|
2010
|
+
},
|
|
2011
|
+
],
|
|
1754
2012
|
};
|
|
1755
2013
|
});
|
|
1756
2014
|
// Tool: list_functions
|
|
@@ -1800,7 +2058,7 @@ server.tool("list_functions", "List storefront API functions. Without a `categor
|
|
|
1800
2058
|
if (uncategorized > 0) {
|
|
1801
2059
|
lines.push(`- \`Other\` (${uncategorized})`);
|
|
1802
2060
|
}
|
|
1803
|
-
lines.push("",
|
|
2061
|
+
lines.push("", 'Call `list_functions(category: "<name>")` to see one-line summaries for a category.');
|
|
1804
2062
|
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
1805
2063
|
}
|
|
1806
2064
|
const catLower = category.toLowerCase();
|
|
@@ -1832,7 +2090,11 @@ server.tool("list_functions", "List storefront API functions. Without a `categor
|
|
|
1832
2090
|
return { content: [{ type: "text", text: parts.join("\n") }] };
|
|
1833
2091
|
});
|
|
1834
2092
|
// Tool: get_code_example
|
|
1835
|
-
server.tool("get_code_example", "Get an API usage reference for a specific task. Shows correct function calls, imports, and data-handling patterns from a real production theme. The JSX layout and CSS are illustrative only — create your own original visual design. Call `list_examples()` to see available example IDs.", {
|
|
2093
|
+
server.tool("get_code_example", "Get an API usage reference for a specific task. Shows correct function calls, imports, and data-handling patterns from a real production theme. The JSX layout and CSS are illustrative only — create your own original visual design. Call `list_examples()` to see available example IDs.", {
|
|
2094
|
+
task: z
|
|
2095
|
+
.string()
|
|
2096
|
+
.describe("Task description or example ID (call `list_examples()` for the full list)"),
|
|
2097
|
+
}, async ({ task }) => {
|
|
1836
2098
|
const taskLower = task.toLowerCase();
|
|
1837
2099
|
// Try exact ID match first
|
|
1838
2100
|
let example = storefrontData.codeExamples.find((e) => e.id === taskLower);
|
|
@@ -1852,7 +2114,9 @@ server.tool("get_code_example", "Get an API usage reference for a specific task.
|
|
|
1852
2114
|
}
|
|
1853
2115
|
}
|
|
1854
2116
|
if (!example) {
|
|
1855
|
-
const available = storefrontData.codeExamples
|
|
2117
|
+
const available = storefrontData.codeExamples
|
|
2118
|
+
.map((e) => ` - \`${e.id}\` - ${e.title}`)
|
|
2119
|
+
.join("\n");
|
|
1856
2120
|
return {
|
|
1857
2121
|
content: [
|
|
1858
2122
|
{
|
|
@@ -1875,20 +2139,30 @@ server.tool("get_code_example", "Get an API usage reference for a specific task.
|
|
|
1875
2139
|
if (example.files && example.files.length > 0) {
|
|
1876
2140
|
for (const file of example.files) {
|
|
1877
2141
|
const ext = file.filename.split(".").pop() || "text";
|
|
1878
|
-
const lang = ext === "tsx" || ext === "ts"
|
|
2142
|
+
const lang = ext === "tsx" || ext === "ts"
|
|
2143
|
+
? "typescript"
|
|
2144
|
+
: ext === "css"
|
|
2145
|
+
? "css"
|
|
2146
|
+
: ext === "json"
|
|
2147
|
+
? "json"
|
|
2148
|
+
: "text";
|
|
1879
2149
|
// Add inline originality comments to CSS and TSX files
|
|
1880
2150
|
let content = file.content;
|
|
1881
2151
|
if (ext === "css") {
|
|
1882
|
-
content =
|
|
2152
|
+
content =
|
|
2153
|
+
"/* EXAMPLE STYLING — create your own original CSS with different class names and design */\n" +
|
|
2154
|
+
content;
|
|
1883
2155
|
}
|
|
1884
2156
|
else if (ext === "tsx") {
|
|
1885
|
-
content =
|
|
2157
|
+
content =
|
|
2158
|
+
"// EXAMPLE COMPONENT — use the API patterns but create your own JSX structure and layout\n" +
|
|
2159
|
+
content;
|
|
1886
2160
|
}
|
|
1887
2161
|
parts.push(`### ${file.filename}`, "", `\`\`\`${lang}`, content, "```", "");
|
|
1888
2162
|
}
|
|
1889
2163
|
}
|
|
1890
2164
|
else {
|
|
1891
|
-
parts.push(
|
|
2165
|
+
parts.push(asCodeBlock(example.code), "");
|
|
1892
2166
|
}
|
|
1893
2167
|
parts.push(`**Reminder:** Use the API patterns above (function calls, imports, type handling) but create your own original HTML structure and CSS.`);
|
|
1894
2168
|
parts.push("");
|
|
@@ -1896,63 +2170,88 @@ server.tool("get_code_example", "Get an API usage reference for a specific task.
|
|
|
1896
2170
|
return { content: [{ type: "text", text: parts.join("\n") }] };
|
|
1897
2171
|
});
|
|
1898
2172
|
// Tool: get_framework_guide
|
|
1899
|
-
server.tool("get_framework_guide", "Get a framework guide on a specific topic (e.g. 'ai-workflow', 'common-pitfalls', 'prop-types', 'css-scoping', 'form-handling'). Call `list_topics()` to see all available topic keys.", {
|
|
2173
|
+
server.tool("get_framework_guide", "Get a framework guide on a specific topic (e.g. 'ai-workflow', 'common-pitfalls', 'prop-types', 'css-scoping', 'form-handling'). Call `list_topics()` to see all available topic keys.", {
|
|
2174
|
+
topic: z
|
|
2175
|
+
.string()
|
|
2176
|
+
.describe("Topic key or keyword (call `list_topics()` for the full list)"),
|
|
2177
|
+
}, async ({ topic }) => {
|
|
1900
2178
|
const topicLower = topic.toLowerCase().replace(/\s+/g, "-");
|
|
1901
2179
|
// Alias mapping for common alternative topic names
|
|
1902
2180
|
const topicAliases = {
|
|
1903
2181
|
"form-handling": "form-patterns",
|
|
1904
|
-
|
|
2182
|
+
forms: "form-patterns",
|
|
1905
2183
|
"data-fetching": "async-data-patterns",
|
|
1906
|
-
|
|
1907
|
-
|
|
2184
|
+
async: "async-data-patterns",
|
|
2185
|
+
loading: "async-data-patterns",
|
|
1908
2186
|
"sub-components": "sub-component-patterns",
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
2187
|
+
subcomponents: "sub-component-patterns",
|
|
2188
|
+
routing: "navigation-patterns",
|
|
2189
|
+
router: "navigation-patterns",
|
|
2190
|
+
observer: "component-structure",
|
|
2191
|
+
reactivity: "component-structure",
|
|
2192
|
+
pitfalls: "common-pitfalls",
|
|
2193
|
+
gotchas: "common-pitfalls",
|
|
2194
|
+
mistakes: "common-pitfalls",
|
|
2195
|
+
header: "header-footer-patterns",
|
|
2196
|
+
footer: "header-footer-patterns",
|
|
2197
|
+
blog: "blog-patterns",
|
|
2198
|
+
cart: "cart-patterns",
|
|
2199
|
+
account: "account-patterns",
|
|
1922
2200
|
"product-detail": "product-detail-patterns",
|
|
1923
2201
|
"product-list": "product-list-patterns",
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
2202
|
+
filtering: "product-list-patterns",
|
|
2203
|
+
reviews: "review-patterns",
|
|
2204
|
+
slider: "slider-overlay-patterns",
|
|
2205
|
+
overlay: "slider-overlay-patterns",
|
|
2206
|
+
modal: "slider-overlay-patterns",
|
|
2207
|
+
architecture: "real-world-architecture",
|
|
2208
|
+
theme: "real-world-architecture",
|
|
1931
2209
|
"global-styles": "global-css",
|
|
1932
|
-
|
|
2210
|
+
global: "global-css",
|
|
1933
2211
|
"css-variables": "global-css",
|
|
1934
2212
|
"custom-properties": "global-css",
|
|
1935
2213
|
};
|
|
1936
2214
|
const resolvedTopic = topicAliases[topicLower] || topicLower;
|
|
1937
2215
|
// Topics that involve MobX store reads get a reminder about root reactivity
|
|
1938
2216
|
const storeTopics = new Set([
|
|
1939
|
-
"product-detail-patterns",
|
|
1940
|
-
"
|
|
1941
|
-
"
|
|
1942
|
-
"
|
|
2217
|
+
"product-detail-patterns",
|
|
2218
|
+
"product-list-patterns",
|
|
2219
|
+
"cart-patterns",
|
|
2220
|
+
"account-patterns",
|
|
2221
|
+
"header-footer-patterns",
|
|
2222
|
+
"review-patterns",
|
|
2223
|
+
"blog-patterns",
|
|
2224
|
+
"form-handling",
|
|
2225
|
+
"async-data-patterns",
|
|
2226
|
+
"component-structure",
|
|
2227
|
+
"imports",
|
|
1943
2228
|
]);
|
|
1944
2229
|
const observerReminder = "> **IMPORTANT: Do NOT use `observer()` on root component exports.** The ikas runtime wraps root renders in MobX `autorun()`, making them automatically reactive. All store reads (`cartStore`, `customerStore`, etc.) in root components are tracked automatically. Only use `observer()` on extracted sub-components.\n\n";
|
|
1945
2230
|
// Try exact key match (with alias resolution)
|
|
1946
2231
|
if (frameworkData.topics[resolvedTopic]) {
|
|
1947
2232
|
const t = frameworkData.topics[resolvedTopic];
|
|
1948
2233
|
const prefix = storeTopics.has(resolvedTopic) ? observerReminder : "";
|
|
1949
|
-
return {
|
|
2234
|
+
return {
|
|
2235
|
+
content: [
|
|
2236
|
+
{
|
|
2237
|
+
type: "text",
|
|
2238
|
+
text: `## ${t.title}\n\n${prefix}${t.content}`,
|
|
2239
|
+
},
|
|
2240
|
+
],
|
|
2241
|
+
};
|
|
1950
2242
|
}
|
|
1951
2243
|
// Try original topic key (without alias) in case it's a direct key
|
|
1952
2244
|
if (resolvedTopic !== topicLower && frameworkData.topics[topicLower]) {
|
|
1953
2245
|
const t = frameworkData.topics[topicLower];
|
|
1954
2246
|
const prefix = storeTopics.has(topicLower) ? observerReminder : "";
|
|
1955
|
-
return {
|
|
2247
|
+
return {
|
|
2248
|
+
content: [
|
|
2249
|
+
{
|
|
2250
|
+
type: "text",
|
|
2251
|
+
text: `## ${t.title}\n\n${prefix}${t.content}`,
|
|
2252
|
+
},
|
|
2253
|
+
],
|
|
2254
|
+
};
|
|
1956
2255
|
}
|
|
1957
2256
|
// Try keyword search
|
|
1958
2257
|
const matches = searchFrameworkTopics(topic);
|
|
@@ -1960,7 +2259,12 @@ server.tool("get_framework_guide", "Get a framework guide on a specific topic (e
|
|
|
1960
2259
|
const best = matches[0];
|
|
1961
2260
|
const prefix = storeTopics.has(best.key) ? observerReminder : "";
|
|
1962
2261
|
return {
|
|
1963
|
-
content: [
|
|
2262
|
+
content: [
|
|
2263
|
+
{
|
|
2264
|
+
type: "text",
|
|
2265
|
+
text: `## ${best.topic.title}\n\n${prefix}${best.topic.content}`,
|
|
2266
|
+
},
|
|
2267
|
+
],
|
|
1964
2268
|
};
|
|
1965
2269
|
}
|
|
1966
2270
|
const available = Object.entries(frameworkData.topics)
|
|
@@ -1976,16 +2280,27 @@ server.tool("get_framework_guide", "Get a framework guide on a specific topic (e
|
|
|
1976
2280
|
};
|
|
1977
2281
|
});
|
|
1978
2282
|
// Tool: get_type_definition
|
|
1979
|
-
server.tool("get_type_definition", "Get the full definition of a storefront type or enum by name (e.g. 'IkasProduct', 'IkasOrderStatus')
|
|
2283
|
+
server.tool("get_type_definition", "Get the full definition of a storefront type or enum by name. Shows all properties with types, extends, enum values, or string-union values. Covers runtime models (e.g. 'IkasProduct', 'IkasOrderStatus'), theme-globals tokens returned by the getters (e.g. 'ThemeSetting', 'DesignToken', 'TypographyToken', 'ColorSchemeToken', 'BreakpointToken', 'KeyframeToken'), and style-prop TYPE shapes used by ikas.config.json props (e.g. 'BorderRadiusStyleType', 'PaddingStyleType', 'GapStyleType', 'SizeStyleType' and their '*StyleUnitType' unions). If a type reports as not found, it may not be indexed yet — fall back to reading the package's `.d.ts` (e.g. `@ikas/bp-storefront-config`) rather than typing the value as `any`.", {
|
|
2284
|
+
name: z
|
|
2285
|
+
.string()
|
|
2286
|
+
.describe("Type or enum name (e.g. 'IkasProduct', 'IkasOrderStatus')"),
|
|
2287
|
+
}, async ({ name }) => {
|
|
1980
2288
|
if (!typesData) {
|
|
1981
2289
|
return {
|
|
1982
|
-
content: [
|
|
2290
|
+
content: [
|
|
2291
|
+
{
|
|
2292
|
+
type: "text",
|
|
2293
|
+
text: "Type data not available. Run 'npm run docs:generate' in storefront-docs first.",
|
|
2294
|
+
},
|
|
2295
|
+
],
|
|
1983
2296
|
};
|
|
1984
2297
|
}
|
|
1985
2298
|
const nameLower = name.toLowerCase();
|
|
1986
2299
|
const td = typesData.types.find((t) => t.name.toLowerCase() === nameLower);
|
|
1987
2300
|
if (td) {
|
|
1988
|
-
return {
|
|
2301
|
+
return {
|
|
2302
|
+
content: [{ type: "text", text: formatTypeDefinition(td) }],
|
|
2303
|
+
};
|
|
1989
2304
|
}
|
|
1990
2305
|
// Fuzzy match
|
|
1991
2306
|
const matches = typesData.types.filter((t) => t.name.toLowerCase().includes(nameLower));
|
|
@@ -2001,14 +2316,28 @@ server.tool("get_type_definition", "Get the full definition of a storefront type
|
|
|
2001
2316
|
};
|
|
2002
2317
|
}
|
|
2003
2318
|
return {
|
|
2004
|
-
content: [
|
|
2319
|
+
content: [
|
|
2320
|
+
{
|
|
2321
|
+
type: "text",
|
|
2322
|
+
text: `Type "${name}" not found. Use \`list_types()\` to see all available types.`,
|
|
2323
|
+
},
|
|
2324
|
+
],
|
|
2005
2325
|
};
|
|
2006
2326
|
});
|
|
2007
2327
|
// Tool: get_functions_for_type
|
|
2008
|
-
server.tool("get_functions_for_type", "Get full documentation for all utility functions that operate on a given storefront type. For example, get_functions_for_type('IkasImage') returns getSrc, getDefaultSrc, getThumbnailSrc, createMediaSrcset with full signatures, descriptions, and examples.", {
|
|
2328
|
+
server.tool("get_functions_for_type", "Get full documentation for all utility functions that operate on a given storefront type. For example, get_functions_for_type('IkasImage') returns getSrc, getDefaultSrc, getThumbnailSrc, createMediaSrcset with full signatures, descriptions, and examples.", {
|
|
2329
|
+
typeName: z
|
|
2330
|
+
.string()
|
|
2331
|
+
.describe("Type name (e.g. 'IkasImage', 'IkasProduct', 'IkasOrder')"),
|
|
2332
|
+
}, async ({ typeName }) => {
|
|
2009
2333
|
if (!typesData) {
|
|
2010
2334
|
return {
|
|
2011
|
-
content: [
|
|
2335
|
+
content: [
|
|
2336
|
+
{
|
|
2337
|
+
type: "text",
|
|
2338
|
+
text: "Type data not available. Run 'npm run docs:generate' in storefront-docs first.",
|
|
2339
|
+
},
|
|
2340
|
+
],
|
|
2012
2341
|
};
|
|
2013
2342
|
}
|
|
2014
2343
|
const nameLower = typeName.toLowerCase();
|
|
@@ -2028,7 +2357,12 @@ server.tool("get_functions_for_type", "Get full documentation for all utility fu
|
|
|
2028
2357
|
};
|
|
2029
2358
|
}
|
|
2030
2359
|
return {
|
|
2031
|
-
content: [
|
|
2360
|
+
content: [
|
|
2361
|
+
{
|
|
2362
|
+
type: "text",
|
|
2363
|
+
text: `Type "${typeName}" not found. Use \`list_types()\` to see all available types.`,
|
|
2364
|
+
},
|
|
2365
|
+
],
|
|
2032
2366
|
};
|
|
2033
2367
|
}
|
|
2034
2368
|
if (!td.relatedFunctions || td.relatedFunctions.length === 0) {
|
|
@@ -2059,7 +2393,10 @@ server.tool("get_functions_for_type", "Get full documentation for all utility fu
|
|
|
2059
2393
|
});
|
|
2060
2394
|
// Tool: get_model_guide
|
|
2061
2395
|
server.tool("get_model_guide", "Get an overview of a storefront model type. By default returns the type definition, related function names with one-line summaries, matching example titles/IDs, and related type summaries. Pass `mode: 'full'` to inline full function docs and example code.", {
|
|
2062
|
-
model: z
|
|
2396
|
+
model: z
|
|
2397
|
+
.string()
|
|
2398
|
+
.optional()
|
|
2399
|
+
.describe("Model type name (e.g. 'IkasImage', 'IkasProduct', 'IkasOrder')"),
|
|
2063
2400
|
name: z.string().optional().describe("Alias for 'model'"),
|
|
2064
2401
|
mode: z
|
|
2065
2402
|
.enum(["summary", "full"])
|
|
@@ -2070,12 +2407,22 @@ server.tool("get_model_guide", "Get an overview of a storefront model type. By d
|
|
|
2070
2407
|
const model = modelParam || nameParam;
|
|
2071
2408
|
if (!model) {
|
|
2072
2409
|
return {
|
|
2073
|
-
content: [
|
|
2410
|
+
content: [
|
|
2411
|
+
{
|
|
2412
|
+
type: "text",
|
|
2413
|
+
text: "Please provide a model name (e.g. 'IkasProduct', 'IkasOrder'). Use the 'model' or 'name' parameter.",
|
|
2414
|
+
},
|
|
2415
|
+
],
|
|
2074
2416
|
};
|
|
2075
2417
|
}
|
|
2076
2418
|
if (!typesData) {
|
|
2077
2419
|
return {
|
|
2078
|
-
content: [
|
|
2420
|
+
content: [
|
|
2421
|
+
{
|
|
2422
|
+
type: "text",
|
|
2423
|
+
text: "Type data not available. Run 'npm run docs:generate' in storefront-docs first.",
|
|
2424
|
+
},
|
|
2425
|
+
],
|
|
2079
2426
|
};
|
|
2080
2427
|
}
|
|
2081
2428
|
const modelLower = model.toLowerCase();
|
|
@@ -2097,7 +2444,12 @@ server.tool("get_model_guide", "Get an overview of a storefront model type. By d
|
|
|
2097
2444
|
};
|
|
2098
2445
|
}
|
|
2099
2446
|
return {
|
|
2100
|
-
content: [
|
|
2447
|
+
content: [
|
|
2448
|
+
{
|
|
2449
|
+
type: "text",
|
|
2450
|
+
text: `Model "${model}" not found. Use \`list_types()\` to see all available types.`,
|
|
2451
|
+
},
|
|
2452
|
+
],
|
|
2101
2453
|
};
|
|
2102
2454
|
}
|
|
2103
2455
|
const parts = [`# Model Guide: ${td.name}\n`];
|
|
@@ -2205,13 +2557,23 @@ server.tool("get_model_guide", "Get an overview of a storefront model type. By d
|
|
|
2205
2557
|
server.tool("search_types", "Search storefront types and enums by keyword (e.g. 'price', 'address', 'status'). Returns top matches ranked by relevance.", { query: z.string().describe("Search keyword or phrase") }, async ({ query }) => {
|
|
2206
2558
|
if (!typesData) {
|
|
2207
2559
|
return {
|
|
2208
|
-
content: [
|
|
2560
|
+
content: [
|
|
2561
|
+
{
|
|
2562
|
+
type: "text",
|
|
2563
|
+
text: "Type data not available. Run 'npm run docs:generate' in storefront-docs first.",
|
|
2564
|
+
},
|
|
2565
|
+
],
|
|
2209
2566
|
};
|
|
2210
2567
|
}
|
|
2211
2568
|
const results = searchTypes(query).slice(0, 15);
|
|
2212
2569
|
if (results.length === 0) {
|
|
2213
2570
|
return {
|
|
2214
|
-
content: [
|
|
2571
|
+
content: [
|
|
2572
|
+
{
|
|
2573
|
+
type: "text",
|
|
2574
|
+
text: `No types found matching "${query}". Use \`list_types()\` to see all available types.`,
|
|
2575
|
+
},
|
|
2576
|
+
],
|
|
2215
2577
|
};
|
|
2216
2578
|
}
|
|
2217
2579
|
const parts = [`## Type Search Results for "${query}"\n`];
|
|
@@ -2275,7 +2637,7 @@ server.tool("list_types", "List storefront types and enums. Use `domain` and/or
|
|
|
2275
2637
|
for (const [d, count] of sorted) {
|
|
2276
2638
|
lines.push(`- \`${d}\` (${count})`);
|
|
2277
2639
|
}
|
|
2278
|
-
lines.push("",
|
|
2640
|
+
lines.push("", 'Call `list_types(domain: "<name>")` to see summaries for a domain.');
|
|
2279
2641
|
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
2280
2642
|
}
|
|
2281
2643
|
const domainLower = domain.toLowerCase();
|
|
@@ -2314,15 +2676,25 @@ server.tool("list_types", "List storefront types and enums. Use `domain` and/or
|
|
|
2314
2676
|
return { content: [{ type: "text", text: parts.join("\n") }] };
|
|
2315
2677
|
});
|
|
2316
2678
|
// Tool: get_prop_types
|
|
2317
|
-
server.tool("get_prop_types",
|
|
2679
|
+
server.tool("get_prop_types", 'Get all available ikas.config.json prop types with descriptions, TypeScript types, and examples. NOTE: these are the TypeScript prop-definition types for authoring a component — they are NOT the runtime JSON value shapes you write via `update_section_prop` (e.g. a TEXT prop is typed `string` here but written as `{ "value": "..." }`, and an IMAGE is `IkasImage | null` here but written as `{ "id": "..." }`). For the value shapes to pass to `update_section_prop`, see that tool\'s description. Tip: Use `npx ikas-component config add-component --props \'[...]\'` to create a component with all props in one command, or `add-prop` to add props incrementally. NEVER manually edit types.ts — it is auto-generated by the CLI.', {}, async () => {
|
|
2318
2680
|
const propTypesTopic = frameworkData.topics["prop-types"];
|
|
2319
2681
|
if (propTypesTopic) {
|
|
2320
2682
|
return {
|
|
2321
|
-
content: [
|
|
2683
|
+
content: [
|
|
2684
|
+
{
|
|
2685
|
+
type: "text",
|
|
2686
|
+
text: `## ${propTypesTopic.title}\n\n${propTypesTopic.content}`,
|
|
2687
|
+
},
|
|
2688
|
+
],
|
|
2322
2689
|
};
|
|
2323
2690
|
}
|
|
2324
2691
|
return {
|
|
2325
|
-
content: [
|
|
2692
|
+
content: [
|
|
2693
|
+
{
|
|
2694
|
+
type: "text",
|
|
2695
|
+
text: "Prop types documentation not available.",
|
|
2696
|
+
},
|
|
2697
|
+
],
|
|
2326
2698
|
};
|
|
2327
2699
|
});
|
|
2328
2700
|
// Tool: get_section_template
|
|
@@ -2419,7 +2791,8 @@ server.tool("get_section_template", "Get the root files of a starter section tem
|
|
|
2419
2791
|
// the end of the response in the existing recipe-builder block.
|
|
2420
2792
|
{
|
|
2421
2793
|
const snippetStrForBanner = bundle.rootFiles["ikas-config-snippet.json"];
|
|
2422
|
-
if (snippetStrForBanner &&
|
|
2794
|
+
if (snippetStrForBanner &&
|
|
2795
|
+
/<id-of-[A-Za-z0-9_]+>/.test(snippetStrForBanner)) {
|
|
2423
2796
|
const childMatches = Array.from(snippetStrForBanner.matchAll(/<id-of-([A-Za-z0-9_]+)>/g));
|
|
2424
2797
|
const uniqueChildren = Array.from(new Set(childMatches.map((m) => m[1])));
|
|
2425
2798
|
parts.push(`> 🔧 **CONTAINER SECTION — required wiring.** This template hosts ${uniqueChildren.length} child component${uniqueChildren.length === 1 ? "" : "s"} (${uniqueChildren.map((n) => `\`${n}\``).join(", ")}) via a \`COMPONENT_LIST\` slot. Creating the parent alone produces an empty, unusable section. **You MUST follow the full Setup Recipe below**: create each child → capture its \`componentId\` → wire them into the parent's \`filteredComponentIds\` with \`config update-prop\`. Component ids are opaque random strings (e.g. \`7ojrigep-Eml9n5sN3i\`) — they cannot be derived from names, and the CLI rejects unknown ids.`, "");
|
|
@@ -2543,7 +2916,10 @@ server.tool("get_section_template", "Get the root files of a starter section tem
|
|
|
2543
2916
|
try {
|
|
2544
2917
|
const childSnippet = JSON.parse(fs.readFileSync(childSnippetPath, "utf-8"));
|
|
2545
2918
|
const childProps = (childSnippet.props || []).map((p) => {
|
|
2546
|
-
const out = {
|
|
2919
|
+
const out = {
|
|
2920
|
+
name: p.name,
|
|
2921
|
+
type: p.type,
|
|
2922
|
+
};
|
|
2547
2923
|
if (p.displayName)
|
|
2548
2924
|
out.displayName = p.displayName;
|
|
2549
2925
|
if (p.required)
|
|
@@ -2616,10 +2992,7 @@ server.tool("get_section_child", "Fetch one item's files from a section's childr
|
|
|
2616
2992
|
.string()
|
|
2617
2993
|
.optional()
|
|
2618
2994
|
.describe("The item name as listed in `get_section_template`'s response (Children/Components/Sub-components)"),
|
|
2619
|
-
child: z
|
|
2620
|
-
.string()
|
|
2621
|
-
.optional()
|
|
2622
|
-
.describe("Alias for `name`"),
|
|
2995
|
+
child: z.string().optional().describe("Alias for `name`"),
|
|
2623
2996
|
kind: z
|
|
2624
2997
|
.enum(["children", "components", "sub-components"])
|
|
2625
2998
|
.optional()
|
|
@@ -2782,7 +3155,11 @@ server.tool("list_section_types", "List all available `get_section_template` sec
|
|
|
2782
3155
|
});
|
|
2783
3156
|
// --- Migration tools ---
|
|
2784
3157
|
// Tool: analyze_old_theme
|
|
2785
|
-
server.tool("analyze_old_theme", "Analyze an old ikas storefront theme.json and produce a structured migration report. Shows all components, custom data definitions, prop type breakdown, and migration recommendations. Use this as the first step when converting an old theme.", {
|
|
3158
|
+
server.tool("analyze_old_theme", "Analyze an old ikas storefront theme.json and produce a structured migration report. Shows all components, custom data definitions, prop type breakdown, and migration recommendations. Use this as the first step when converting an old theme.", {
|
|
3159
|
+
theme_json: z
|
|
3160
|
+
.string()
|
|
3161
|
+
.describe("The raw JSON content of the old theme.json file"),
|
|
3162
|
+
}, async ({ theme_json }) => {
|
|
2786
3163
|
try {
|
|
2787
3164
|
const parsed = JSON.parse(theme_json);
|
|
2788
3165
|
const analysis = analyzeOldTheme(parsed);
|
|
@@ -2790,102 +3167,162 @@ server.tool("analyze_old_theme", "Analyze an old ikas storefront theme.json and
|
|
|
2790
3167
|
}
|
|
2791
3168
|
catch (err) {
|
|
2792
3169
|
return {
|
|
2793
|
-
content: [
|
|
3170
|
+
content: [
|
|
3171
|
+
{
|
|
3172
|
+
type: "text",
|
|
3173
|
+
text: `Error parsing theme.json: ${err instanceof Error ? err.message : String(err)}. Make sure you're passing valid JSON.`,
|
|
3174
|
+
},
|
|
3175
|
+
],
|
|
2794
3176
|
};
|
|
2795
3177
|
}
|
|
2796
3178
|
});
|
|
2797
3179
|
// Tool: get_migration_guide
|
|
2798
3180
|
const migrationTopicAliases = {
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
3181
|
+
overview: "migration-overview",
|
|
3182
|
+
migrate: "migration-overview",
|
|
3183
|
+
custom: "custom-data-conversion",
|
|
2802
3184
|
"custom-data": "custom-data-conversion",
|
|
2803
|
-
|
|
3185
|
+
customdata: "custom-data-conversion",
|
|
2804
3186
|
"dynamic-list": "custom-data-conversion",
|
|
2805
3187
|
"component-list": "custom-data-conversion",
|
|
2806
|
-
|
|
2807
|
-
|
|
3188
|
+
slider: "prop-type-mapping",
|
|
3189
|
+
props: "prop-type-mapping",
|
|
2808
3190
|
"prop-mapping": "prop-type-mapping",
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
3191
|
+
types: "prop-type-mapping",
|
|
3192
|
+
react: "react-to-preact",
|
|
3193
|
+
preact: "react-to-preact",
|
|
3194
|
+
observer: "react-to-preact",
|
|
3195
|
+
libraries: "library-replacements",
|
|
3196
|
+
swiper: "library-replacements",
|
|
3197
|
+
headlessui: "library-replacements",
|
|
3198
|
+
tailwind: "library-replacements",
|
|
3199
|
+
tailwindcss: "library-replacements",
|
|
3200
|
+
recharts: "library-replacements",
|
|
3201
|
+
marquee: "library-replacements",
|
|
3202
|
+
imports: "storefront-import-mapping",
|
|
3203
|
+
storefront: "storefront-import-mapping",
|
|
2822
3204
|
"bp-storefront": "storefront-import-mapping",
|
|
2823
3205
|
"theme-json": "theme-json-anatomy",
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
3206
|
+
anatomy: "theme-json-anatomy",
|
|
3207
|
+
decompose: "component-decomposition-strategy",
|
|
3208
|
+
decomposition: "component-decomposition-strategy",
|
|
3209
|
+
strategy: "component-decomposition-strategy",
|
|
3210
|
+
project: "complete-project-generation",
|
|
3211
|
+
generate: "complete-project-generation",
|
|
3212
|
+
generation: "complete-project-generation",
|
|
3213
|
+
settings: "settings-conversion",
|
|
3214
|
+
colors: "settings-conversion",
|
|
3215
|
+
fonts: "settings-conversion",
|
|
3216
|
+
find: "finding-new-system-equivalents",
|
|
3217
|
+
search: "finding-new-system-equivalents",
|
|
3218
|
+
discover: "finding-new-system-equivalents",
|
|
3219
|
+
equivalent: "finding-new-system-equivalents",
|
|
3220
|
+
equivalents: "finding-new-system-equivalents",
|
|
3221
|
+
replacement: "finding-new-system-equivalents",
|
|
2840
3222
|
};
|
|
2841
3223
|
const migrationTopicKeys = migrationData
|
|
2842
3224
|
? Object.keys(migrationData.topics)
|
|
2843
3225
|
: [];
|
|
2844
|
-
server.tool("get_migration_guide", `Get a migration guide for converting old ikas themes to the new code-component system. **Start with \`get_migration_guide("iterative-workflow")\` if you're new to this MCP** — it explains the MCP-vs-LLM responsibility split and the four phases.${migrationTopicKeys.length > 0 ? ` Available topics: ${migrationTopicKeys.join(", ")}. Also supports aliases like "custom", "slider", "react", "libraries", "imports", "settings".` : ""} Call with topic "list" to see all available topics.`, {
|
|
3226
|
+
server.tool("get_migration_guide", `Get a migration guide for converting old ikas themes to the new code-component system. **Start with \`get_migration_guide("iterative-workflow")\` if you're new to this MCP** — it explains the MCP-vs-LLM responsibility split and the four phases.${migrationTopicKeys.length > 0 ? ` Available topics: ${migrationTopicKeys.join(", ")}. Also supports aliases like "custom", "slider", "react", "libraries", "imports", "settings".` : ""} Call with topic "list" to see all available topics.`, {
|
|
3227
|
+
topic: z
|
|
3228
|
+
.string()
|
|
3229
|
+
.describe("Migration topic key, alias, or 'list' to see all topics"),
|
|
3230
|
+
}, async ({ topic }) => {
|
|
2845
3231
|
if (!migrationData) {
|
|
2846
|
-
return {
|
|
3232
|
+
return {
|
|
3233
|
+
content: [
|
|
3234
|
+
{
|
|
3235
|
+
type: "text",
|
|
3236
|
+
text: "Migration data not available. Ensure data/migration.json exists.",
|
|
3237
|
+
},
|
|
3238
|
+
],
|
|
3239
|
+
};
|
|
2847
3240
|
}
|
|
2848
3241
|
if (topic.toLowerCase() === "list") {
|
|
2849
3242
|
const available = Object.entries(migrationData.topics)
|
|
2850
3243
|
.map(([key, t]) => `- \`${key}\` — ${t.title}: ${t.description}`)
|
|
2851
3244
|
.join("\n");
|
|
2852
|
-
return {
|
|
3245
|
+
return {
|
|
3246
|
+
content: [
|
|
3247
|
+
{
|
|
3248
|
+
type: "text",
|
|
3249
|
+
text: `## Available Migration Topics\n\n${available}`,
|
|
3250
|
+
},
|
|
3251
|
+
],
|
|
3252
|
+
};
|
|
2853
3253
|
}
|
|
2854
3254
|
const topicLower = topic.toLowerCase().replace(/\s+/g, "-");
|
|
2855
3255
|
const resolvedTopic = migrationTopicAliases[topicLower] || topicLower;
|
|
2856
3256
|
if (migrationData.topics[resolvedTopic]) {
|
|
2857
3257
|
const t = migrationData.topics[resolvedTopic];
|
|
2858
|
-
return {
|
|
3258
|
+
return {
|
|
3259
|
+
content: [
|
|
3260
|
+
{ type: "text", text: `## ${t.title}\n\n${t.content}` },
|
|
3261
|
+
],
|
|
3262
|
+
};
|
|
2859
3263
|
}
|
|
2860
3264
|
// Try original key
|
|
2861
3265
|
if (resolvedTopic !== topicLower && migrationData.topics[topicLower]) {
|
|
2862
3266
|
const t = migrationData.topics[topicLower];
|
|
2863
|
-
return {
|
|
3267
|
+
return {
|
|
3268
|
+
content: [
|
|
3269
|
+
{ type: "text", text: `## ${t.title}\n\n${t.content}` },
|
|
3270
|
+
],
|
|
3271
|
+
};
|
|
2864
3272
|
}
|
|
2865
3273
|
// Keyword search
|
|
2866
3274
|
const matches = searchMigrationTopics(topic);
|
|
2867
3275
|
if (matches.length > 0) {
|
|
2868
3276
|
const best = matches[0];
|
|
2869
|
-
return {
|
|
3277
|
+
return {
|
|
3278
|
+
content: [
|
|
3279
|
+
{
|
|
3280
|
+
type: "text",
|
|
3281
|
+
text: `## ${best.topic.title}\n\n${best.topic.content}`,
|
|
3282
|
+
},
|
|
3283
|
+
],
|
|
3284
|
+
};
|
|
2870
3285
|
}
|
|
2871
3286
|
const available = Object.entries(migrationData.topics)
|
|
2872
3287
|
.map(([key, t]) => ` - \`${key}\` - ${t.title}`)
|
|
2873
3288
|
.join("\n");
|
|
2874
3289
|
return {
|
|
2875
|
-
content: [
|
|
3290
|
+
content: [
|
|
3291
|
+
{
|
|
3292
|
+
type: "text",
|
|
3293
|
+
text: `Migration topic "${topic}" not found. Available topics:\n${available}`,
|
|
3294
|
+
},
|
|
3295
|
+
],
|
|
2876
3296
|
};
|
|
2877
3297
|
});
|
|
2878
3298
|
// Tool: get_migration_example
|
|
2879
|
-
server.tool("get_migration_example", `Get a concrete before/after migration example showing how to convert an old theme component to the new code-component system.${migrationExampleNames.length > 0 ? ` Available examples: ${migrationExampleNames.join(", ")}.` : ""} Call with example "list" to see all examples.`, {
|
|
3299
|
+
server.tool("get_migration_example", `Get a concrete before/after migration example showing how to convert an old theme component to the new code-component system.${migrationExampleNames.length > 0 ? ` Available examples: ${migrationExampleNames.join(", ")}.` : ""} Call with example "list" to see all examples.`, {
|
|
3300
|
+
example: z.string().describe("Example name or 'list' to see all examples"),
|
|
3301
|
+
}, async ({ example }) => {
|
|
2880
3302
|
if (example.toLowerCase() === "list") {
|
|
2881
3303
|
if (migrationExampleNames.length === 0) {
|
|
2882
|
-
return {
|
|
3304
|
+
return {
|
|
3305
|
+
content: [
|
|
3306
|
+
{ type: "text", text: "No migration examples available." },
|
|
3307
|
+
],
|
|
3308
|
+
};
|
|
2883
3309
|
}
|
|
2884
|
-
const list = migrationExampleNames
|
|
3310
|
+
const list = migrationExampleNames
|
|
3311
|
+
.map((name) => {
|
|
2885
3312
|
const ex = loadMigrationExample(name);
|
|
2886
|
-
return ex
|
|
2887
|
-
|
|
2888
|
-
|
|
3313
|
+
return ex
|
|
3314
|
+
? `- \`${name}\` — ${ex.title}: ${ex.description}`
|
|
3315
|
+
: `- \`${name}\``;
|
|
3316
|
+
})
|
|
3317
|
+
.join("\n");
|
|
3318
|
+
return {
|
|
3319
|
+
content: [
|
|
3320
|
+
{
|
|
3321
|
+
type: "text",
|
|
3322
|
+
text: `## Available Migration Examples\n\n${list}`,
|
|
3323
|
+
},
|
|
3324
|
+
],
|
|
3325
|
+
};
|
|
2889
3326
|
}
|
|
2890
3327
|
const exampleLower = example.toLowerCase();
|
|
2891
3328
|
let exName = migrationExampleNames.find((n) => n === exampleLower);
|
|
@@ -2895,19 +3332,26 @@ server.tool("get_migration_example", `Get a concrete before/after migration exam
|
|
|
2895
3332
|
if (!exName) {
|
|
2896
3333
|
const available = migrationExampleNames.join(", ");
|
|
2897
3334
|
return {
|
|
2898
|
-
content: [
|
|
3335
|
+
content: [
|
|
3336
|
+
{
|
|
3337
|
+
type: "text",
|
|
3338
|
+
text: `Migration example "${example}" not found. Available: ${available}`,
|
|
3339
|
+
},
|
|
3340
|
+
],
|
|
2899
3341
|
};
|
|
2900
3342
|
}
|
|
2901
3343
|
const ex = loadMigrationExample(exName);
|
|
2902
3344
|
if (!ex) {
|
|
2903
|
-
return {
|
|
3345
|
+
return {
|
|
3346
|
+
content: [
|
|
3347
|
+
{
|
|
3348
|
+
type: "text",
|
|
3349
|
+
text: `Failed to load migration example "${exName}".`,
|
|
3350
|
+
},
|
|
3351
|
+
],
|
|
3352
|
+
};
|
|
2904
3353
|
}
|
|
2905
|
-
const parts = [
|
|
2906
|
-
`## ${ex.title}`,
|
|
2907
|
-
"",
|
|
2908
|
-
ex.description,
|
|
2909
|
-
"",
|
|
2910
|
-
];
|
|
3354
|
+
const parts = [`## ${ex.title}`, "", ex.description, ""];
|
|
2911
3355
|
for (const [filename, content] of Object.entries(ex.files)) {
|
|
2912
3356
|
const ext = filename.split(".").pop() || "text";
|
|
2913
3357
|
const lang = ext === "tsx" || ext === "ts"
|
|
@@ -2926,13 +3370,31 @@ server.tool("get_migration_example", `Get a concrete before/after migration exam
|
|
|
2926
3370
|
});
|
|
2927
3371
|
// Tool: plan_migration
|
|
2928
3372
|
server.tool("plan_migration", "Generate the **initial** migration plan and (when `project_root` is provided) write it to <project_root>/MIGRATION.md. **This is the only time the MCP writes that file.** From here, you own it: tick checkboxes as you finish work, log custom-data decisions, scan the old source for atomic components (Button, Input, Card, etc.) that theme.json doesn't see, and append them to MIGRATION.md yourself. theme.json is incomplete by design — the MCP can only describe what's listed there. Pass `theme_json_path` for large themes (raw `theme_json` string is supported for backward compat but fails on real-world sizes).", {
|
|
2929
|
-
theme_json: z
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
3373
|
+
theme_json: z
|
|
3374
|
+
.string()
|
|
3375
|
+
.optional()
|
|
3376
|
+
.describe("Raw JSON content of the old theme.json. EITHER this OR theme_json_path is required (not both). For real themes use theme_json_path — raw strings exceed tool/context limits at production sizes."),
|
|
3377
|
+
theme_json_path: z
|
|
3378
|
+
.string()
|
|
3379
|
+
.optional()
|
|
3380
|
+
.describe("Absolute path to the old theme.json file on disk. Preferred for any real-world theme."),
|
|
3381
|
+
project_name: z
|
|
3382
|
+
.string()
|
|
3383
|
+
.optional()
|
|
3384
|
+
.describe("Target new project name, used to prefix migration-tracking IDs (default: 'my-theme')"),
|
|
3385
|
+
old_source_dir: z
|
|
3386
|
+
.string()
|
|
3387
|
+
.optional()
|
|
3388
|
+
.describe("Absolute path to the old project's src/ directory. When provided, the tool scans .tsx files to detect shared sub-components used across 3+ components. This scan is partial — atomic components used by only 1-2 sections will be missed and must be added by the LLM."),
|
|
3389
|
+
project_root: z
|
|
3390
|
+
.string()
|
|
3391
|
+
.optional()
|
|
3392
|
+
.describe("Absolute path to the new project root. When provided, the MCP writes MIGRATION.md to <project_root>/MIGRATION.md and returns a short summary instead of the full markdown body."),
|
|
3393
|
+
overwrite: z
|
|
3394
|
+
.boolean()
|
|
3395
|
+
.optional()
|
|
3396
|
+
.describe("If MIGRATION.md already exists at <project_root>/MIGRATION.md and is non-empty, refuse the write unless this is true. Default: false."),
|
|
3397
|
+
}, async ({ theme_json, theme_json_path, project_name, old_source_dir, project_root, overwrite, }) => {
|
|
2936
3398
|
try {
|
|
2937
3399
|
const parsed = resolveThemeJson(theme_json, theme_json_path);
|
|
2938
3400
|
const projectName = project_name || "my-theme";
|
|
@@ -2993,18 +3455,37 @@ server.tool("plan_migration", "Generate the **initial** migration plan and (when
|
|
|
2993
3455
|
}
|
|
2994
3456
|
catch (err) {
|
|
2995
3457
|
return {
|
|
2996
|
-
content: [
|
|
3458
|
+
content: [
|
|
3459
|
+
{
|
|
3460
|
+
type: "text",
|
|
3461
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
3462
|
+
},
|
|
3463
|
+
],
|
|
2997
3464
|
};
|
|
2998
3465
|
}
|
|
2999
3466
|
});
|
|
3000
3467
|
// Tool: get_section_migration_plan
|
|
3001
3468
|
server.tool("get_section_migration_plan", "Returns concrete CLI commands and prop conversions for one section. For each prop that references a customData type, you'll see a 'Decide: enum or component?' callout — log your decision in MIGRATION.md under `## Custom Data Decisions`. Pass `theme_json_path` for large themes.", {
|
|
3002
|
-
theme_json: z
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3469
|
+
theme_json: z
|
|
3470
|
+
.string()
|
|
3471
|
+
.optional()
|
|
3472
|
+
.describe("Raw JSON content of the old theme.json. EITHER this OR theme_json_path is required (not both)."),
|
|
3473
|
+
theme_json_path: z
|
|
3474
|
+
.string()
|
|
3475
|
+
.optional()
|
|
3476
|
+
.describe("Absolute path to the old theme.json file on disk. Preferred for any real-world theme."),
|
|
3477
|
+
section_name: z
|
|
3478
|
+
.string()
|
|
3479
|
+
.describe("Old component name (e.g. 'Navbar', 'ProductGrid') or dir name, OR the new section ID (e.g. 'my-theme-navbar')"),
|
|
3480
|
+
project_name: z
|
|
3481
|
+
.string()
|
|
3482
|
+
.optional()
|
|
3483
|
+
.describe("Target new project name (must match what was used in plan_migration). Default: 'my-theme'"),
|
|
3484
|
+
old_source_dir: z
|
|
3485
|
+
.string()
|
|
3486
|
+
.optional()
|
|
3487
|
+
.describe("Absolute path to old src/ directory (used to output exact source file paths to read)"),
|
|
3488
|
+
}, async ({ theme_json, theme_json_path, section_name, project_name, old_source_dir, }) => {
|
|
3008
3489
|
try {
|
|
3009
3490
|
const parsed = resolveThemeJson(theme_json, theme_json_path);
|
|
3010
3491
|
const projectName = project_name || "my-theme";
|
|
@@ -3013,7 +3494,12 @@ server.tool("get_section_migration_plan", "Returns concrete CLI commands and pro
|
|
|
3013
3494
|
}
|
|
3014
3495
|
catch (err) {
|
|
3015
3496
|
return {
|
|
3016
|
-
content: [
|
|
3497
|
+
content: [
|
|
3498
|
+
{
|
|
3499
|
+
type: "text",
|
|
3500
|
+
text: `Error: ${err instanceof Error ? err.message : String(err)}`,
|
|
3501
|
+
},
|
|
3502
|
+
],
|
|
3017
3503
|
};
|
|
3018
3504
|
}
|
|
3019
3505
|
});
|
|
@@ -3043,13 +3529,22 @@ function resolveIkasComponentBinary(projectRoot) {
|
|
|
3043
3529
|
async function runIkasComponentCli(projectRoot, args) {
|
|
3044
3530
|
const bin = resolveIkasComponentBinary(projectRoot);
|
|
3045
3531
|
return new Promise((resolve) => {
|
|
3046
|
-
execFile(bin, args,
|
|
3532
|
+
execFile(bin, args,
|
|
3533
|
+
// Large editor responses (e.g. list_categories on a big store, or
|
|
3534
|
+
// add_sections_to_page echoing many sections) easily exceed Node's default
|
|
3535
|
+
// 1MB stdout buffer, which truncates output mid-JSON and yields a
|
|
3536
|
+
// "no parseable JSON" error. Give it generous headroom.
|
|
3537
|
+
{ cwd: projectRoot, windowsHide: true, maxBuffer: 64 * 1024 * 1024 }, (err, stdout, stderr) => {
|
|
3047
3538
|
const exitCode = err && typeof err.code === "number"
|
|
3048
3539
|
? err.code
|
|
3049
3540
|
: err
|
|
3050
3541
|
? 1
|
|
3051
3542
|
: 0;
|
|
3052
|
-
resolve({
|
|
3543
|
+
resolve({
|
|
3544
|
+
stdout: stdout?.toString() ?? "",
|
|
3545
|
+
stderr: stderr?.toString() ?? "",
|
|
3546
|
+
exitCode,
|
|
3547
|
+
});
|
|
3053
3548
|
});
|
|
3054
3549
|
});
|
|
3055
3550
|
}
|
|
@@ -3057,24 +3552,47 @@ function parseCliJson(stdout) {
|
|
|
3057
3552
|
const trimmed = stdout.trim();
|
|
3058
3553
|
if (!trimmed)
|
|
3059
3554
|
return null;
|
|
3060
|
-
// CLI prints exactly one JSON object on stdout
|
|
3061
|
-
// (e.g., warnings on stderr leaked), take the last non-empty line.
|
|
3062
|
-
const last = trimmed.split("\n").map(l => l.trim()).filter(Boolean).pop();
|
|
3063
|
-
if (!last)
|
|
3064
|
-
return null;
|
|
3555
|
+
// Fast path: the CLI prints exactly one JSON object on stdout.
|
|
3065
3556
|
try {
|
|
3066
|
-
return JSON.parse(
|
|
3557
|
+
return JSON.parse(trimmed);
|
|
3067
3558
|
}
|
|
3068
3559
|
catch {
|
|
3560
|
+
// Fallback: if anything leaked onto stdout before/after the JSON, scan the
|
|
3561
|
+
// lines and return the last one that parses as JSON.
|
|
3562
|
+
const lines = trimmed
|
|
3563
|
+
.split("\n")
|
|
3564
|
+
.map((l) => l.trim())
|
|
3565
|
+
.filter(Boolean);
|
|
3566
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
3567
|
+
try {
|
|
3568
|
+
return JSON.parse(lines[i]);
|
|
3569
|
+
}
|
|
3570
|
+
catch {
|
|
3571
|
+
// keep scanning
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3069
3574
|
return null;
|
|
3070
3575
|
}
|
|
3071
3576
|
}
|
|
3577
|
+
// Coerce a JSON-ARRAY argument (points / settings / colors) into the single JSON-array string the
|
|
3578
|
+
// CLI expects. Agents sometimes send these PRE-STRINGIFIED (a JSON string instead of a real array);
|
|
3579
|
+
// a blind JSON.stringify would then double-encode it ("[...]" -> "\"[...]\"") and the CLI rejects it
|
|
3580
|
+
// with "must be a JSON array". So pass a string through as-is (the CLI parses + validates it) and
|
|
3581
|
+
// only stringify real arrays/values. NOTE: only for array args — a scalar `value` arg must NOT use
|
|
3582
|
+
// this (a plain string there is a literal value, not stringified JSON).
|
|
3583
|
+
function toJsonArrayArg(value) {
|
|
3584
|
+
return typeof value === "string" ? value : JSON.stringify(value ?? []);
|
|
3585
|
+
}
|
|
3072
3586
|
async function callEditorAction(projectRoot, args) {
|
|
3073
3587
|
try {
|
|
3074
3588
|
const { stdout, stderr, exitCode } = await runIkasComponentCli(projectRoot, args);
|
|
3075
3589
|
const parsed = parseCliJson(stdout);
|
|
3076
3590
|
if (parsed) {
|
|
3077
|
-
return {
|
|
3591
|
+
return {
|
|
3592
|
+
content: [
|
|
3593
|
+
{ type: "text", text: JSON.stringify(parsed, null, 2) },
|
|
3594
|
+
],
|
|
3595
|
+
};
|
|
3078
3596
|
}
|
|
3079
3597
|
return {
|
|
3080
3598
|
content: [
|
|
@@ -3097,38 +3615,77 @@ async function callEditorAction(projectRoot, args) {
|
|
|
3097
3615
|
};
|
|
3098
3616
|
}
|
|
3099
3617
|
}
|
|
3618
|
+
//
|
|
3100
3619
|
// Tool: list_editor_pages
|
|
3101
3620
|
server.tool("list_editor_pages", "List pages in the connected editor's project. Returns id, name, pageType, slug for each page. Requires `ikas-component dev` to be running with the editor connected. Use the returned `id`s as the `pageId` argument to `add_section_to_page`.", {
|
|
3102
|
-
project_root: z
|
|
3103
|
-
|
|
3621
|
+
project_root: z
|
|
3622
|
+
.string()
|
|
3623
|
+
.describe("Absolute path to the code-component project (where `node_modules/.bin/ikas-component` lives)."),
|
|
3624
|
+
port: z
|
|
3625
|
+
.number()
|
|
3626
|
+
.optional()
|
|
3627
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
3104
3628
|
}, async ({ project_root, port }) => {
|
|
3105
3629
|
const args = ["list-pages", ...(port ? ["--port", String(port)] : [])];
|
|
3106
3630
|
return callEditorAction(project_root, args);
|
|
3107
3631
|
});
|
|
3108
3632
|
// Tool: list_imported_sections
|
|
3109
3633
|
server.tool("list_imported_sections", "List section-type code components already imported into the editor's project (theme.codeComponents, filtered to type=section). Use to confirm a component is ready to be placed on a page. The component must be built (`ikas-component build`/`dev`) and imported (`import_section`) before it can be added to a page. The returned `id` is the editor's id for the imported component — normally identical to the id in `ikas.config.json`, but it can differ if the dev component was deleted and re-scaffolded after a previous import. Always use the `id` from this tool, not from `ikas.config.json`, when calling `add_section_to_page`.", {
|
|
3110
|
-
project_root: z
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3634
|
+
project_root: z
|
|
3635
|
+
.string()
|
|
3636
|
+
.describe("Absolute path to the code-component project."),
|
|
3637
|
+
port: z
|
|
3638
|
+
.number()
|
|
3639
|
+
.optional()
|
|
3640
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
3641
|
+
}, async ({ project_root, port }) => {
|
|
3642
|
+
const args = [
|
|
3643
|
+
"list-imported",
|
|
3644
|
+
"--sections-only",
|
|
3645
|
+
...(port ? ["--port", String(port)] : []),
|
|
3646
|
+
];
|
|
3647
|
+
return callEditorAction(project_root, args);
|
|
3115
3648
|
});
|
|
3116
3649
|
// Tool: import_section
|
|
3117
3650
|
server.tool("import_section", "Import a built section-type code component into the editor's project. This copies the compiled JS/CSS/props into `theme.codeComponents` and auto-creates the wrapper section needed to place it on a page. Idempotent: re-running updates the existing entry in place. Required before `add_section_to_page`. The component must have been built (`ikas-component build`/`dev`).", {
|
|
3118
|
-
project_root: z
|
|
3119
|
-
|
|
3120
|
-
|
|
3651
|
+
project_root: z
|
|
3652
|
+
.string()
|
|
3653
|
+
.describe("Absolute path to the code-component project."),
|
|
3654
|
+
component_id: z
|
|
3655
|
+
.string()
|
|
3656
|
+
.describe("Component id from `ikas.config.json` (strict — no name resolution)."),
|
|
3657
|
+
port: z
|
|
3658
|
+
.number()
|
|
3659
|
+
.optional()
|
|
3660
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
3121
3661
|
}, async ({ project_root, component_id, port }) => {
|
|
3122
|
-
const args = [
|
|
3662
|
+
const args = [
|
|
3663
|
+
"import",
|
|
3664
|
+
"--id",
|
|
3665
|
+
component_id,
|
|
3666
|
+
...(port ? ["--port", String(port)] : []),
|
|
3667
|
+
];
|
|
3123
3668
|
return callEditorAction(project_root, args);
|
|
3124
3669
|
});
|
|
3125
3670
|
// Tool: add_section_to_page
|
|
3126
|
-
server.tool("add_section_to_page", "Place
|
|
3127
|
-
project_root: z
|
|
3128
|
-
|
|
3671
|
+
server.tool("add_section_to_page", "Place a SINGLE already-imported section-type code component on a page. Use this ONLY when adding exactly one section. If you are adding more than one section — or building/populating a page — call `add_sections_to_page` instead: it places them all AND fills their props in ONE call. Calling this tool repeatedly (one section per call) is the slow path and should be avoided. Equivalent to right-clicking the section in the dev-components panel and choosing \"Add to Page\". Errors if the component is not imported, is not section-type, or the page id is unknown. Use `list_editor_pages` to discover page ids and `list_imported_sections` to discover component ids. After placing, change the section's prop values with `update_section_prop` / `update_page_sections` (use `list_page_sections` to get the placement's `elementId` and prop names).", {
|
|
3672
|
+
project_root: z
|
|
3673
|
+
.string()
|
|
3674
|
+
.describe("Absolute path to the code-component project."),
|
|
3675
|
+
component_id: z
|
|
3676
|
+
.string()
|
|
3677
|
+
.describe("Imported code component id from `list_imported_sections` — NOT the id in `ikas.config.json` (the two are usually the same but can diverge after a rescaffold)."),
|
|
3129
3678
|
page_id: z.string().describe("Target page id (from `list_editor_pages`)."),
|
|
3130
|
-
index: z
|
|
3131
|
-
|
|
3679
|
+
index: z
|
|
3680
|
+
.number()
|
|
3681
|
+
.int()
|
|
3682
|
+
.nonnegative()
|
|
3683
|
+
.optional()
|
|
3684
|
+
.describe("Zero-based insertion index in the page; appends when omitted."),
|
|
3685
|
+
port: z
|
|
3686
|
+
.number()
|
|
3687
|
+
.optional()
|
|
3688
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
3132
3689
|
}, async ({ project_root, component_id, page_id, index, port }) => {
|
|
3133
3690
|
const args = [
|
|
3134
3691
|
"add-to-page",
|
|
@@ -3141,6 +3698,1139 @@ server.tool("add_section_to_page", "Place an already-imported section-type code
|
|
|
3141
3698
|
];
|
|
3142
3699
|
return callEditorAction(project_root, args);
|
|
3143
3700
|
});
|
|
3701
|
+
// Tool: add_sections_to_page
|
|
3702
|
+
server.tool("add_sections_to_page", "Place MANY sections on a page in a SINGLE call — and optionally set each section's prop values AT placement time, so you skip the separate fill step. The fastest way to build a page: one round-trip instead of one add (and one fill) per section. Pass `sections`, each `{ component_id, index?, updates?: [{ prop_name|prop_id, value }] }`; values use the same per-type shapes as update_section_prop / get_editor_workflow. Returns the new `elementId` for each placement (plus written prop results). Built-but-unimported section AND child code components are auto-imported. All update values are validated before anything is placed. Use `list_editor_pages` for page ids and `list_imported_sections` for component ids. Placing a COMMON (global) section — the theme's header/footer — is special: it has ONE shared set of prop values stored on the INDEX (Home) page's placement, so `updates` land there and change that section on every page (the result carries a `common` block), and placing it with `updates` on a non-INDEX page while the INDEX page does not have it is rejected — place and fill it on the INDEX page instead.", {
|
|
3703
|
+
project_root: z
|
|
3704
|
+
.string()
|
|
3705
|
+
.describe("Absolute path to the code-component project."),
|
|
3706
|
+
page_id: z.string().describe("Target page id (from `list_editor_pages`)."),
|
|
3707
|
+
sections: z
|
|
3708
|
+
.array(z.object({
|
|
3709
|
+
component_id: z
|
|
3710
|
+
.string()
|
|
3711
|
+
.describe("Imported (or built) section-type code component id."),
|
|
3712
|
+
index: z
|
|
3713
|
+
.number()
|
|
3714
|
+
.int()
|
|
3715
|
+
.nonnegative()
|
|
3716
|
+
.optional()
|
|
3717
|
+
.describe("Zero-based insertion index; appends when omitted."),
|
|
3718
|
+
updates: z
|
|
3719
|
+
.array(z.object({
|
|
3720
|
+
prop_id: z
|
|
3721
|
+
.string()
|
|
3722
|
+
.optional()
|
|
3723
|
+
.describe("Blueprint prop id (provide this or prop_name)."),
|
|
3724
|
+
prop_name: z
|
|
3725
|
+
.string()
|
|
3726
|
+
.optional()
|
|
3727
|
+
.describe("Blueprint prop name (alternative to prop_id)."),
|
|
3728
|
+
value: z
|
|
3729
|
+
.any()
|
|
3730
|
+
.describe("Prop value, same shape update_section_prop expects for that type."),
|
|
3731
|
+
}))
|
|
3732
|
+
.optional()
|
|
3733
|
+
.describe("Optional prop values to set on this section right after placing it."),
|
|
3734
|
+
}))
|
|
3735
|
+
.describe("Non-empty array of sections to place (in order), each with its componentId and optional prop updates."),
|
|
3736
|
+
port: z
|
|
3737
|
+
.number()
|
|
3738
|
+
.optional()
|
|
3739
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
3740
|
+
}, async ({ project_root, page_id, sections, port }) => {
|
|
3741
|
+
const normalized = (sections || []).map((s) => ({
|
|
3742
|
+
componentId: s.component_id,
|
|
3743
|
+
...(typeof s.index === "number" ? { index: s.index } : {}),
|
|
3744
|
+
...(s.updates
|
|
3745
|
+
? {
|
|
3746
|
+
updates: s.updates.map((u) => ({
|
|
3747
|
+
...(u.prop_id ? { propId: u.prop_id } : {}),
|
|
3748
|
+
...(u.prop_name ? { propName: u.prop_name } : {}),
|
|
3749
|
+
value: u.value,
|
|
3750
|
+
})),
|
|
3751
|
+
}
|
|
3752
|
+
: {}),
|
|
3753
|
+
}));
|
|
3754
|
+
const args = [
|
|
3755
|
+
"add-sections-to-page",
|
|
3756
|
+
"--page-id",
|
|
3757
|
+
page_id,
|
|
3758
|
+
"--sections",
|
|
3759
|
+
JSON.stringify(normalized),
|
|
3760
|
+
...(port ? ["--port", String(port)] : []),
|
|
3761
|
+
];
|
|
3762
|
+
return callEditorAction(project_root, args);
|
|
3763
|
+
});
|
|
3764
|
+
// Tool: list_page_sections
|
|
3765
|
+
server.tool("list_page_sections", "List the sections placed on a page — a LEAN ROSTER that never truncates: per-placement `elementId` (the identity of THIS placement — there can be multiple of the same section), `sectionId`, `componentId`, `name`, `propCount`, and `setPropNames` (which props already have a value). It deliberately omits the prop SCHEMA and the prop VALUES (both can be large — Header alone can have ~80 props). To get a section's prop schema (types, ENUM options, allowed children) call `get_component_props(componentId)`; to read its current values call `get_section_values(element_id)`. Use the returned `elementId` with `update_section_prop` / `update_page_sections`. Use `list_editor_pages` for page ids. COMMON (global) sections — the theme's header and footer — carry an extra `common` field (`isCommon`, `commonSectionType`, `canonicalPageId`/`canonicalElementId`, `valuesArePageSpecific: false`): their prop values are NOT page-specific, they are shared by every page and stored on the INDEX (Home) page's placement, so `setPropNames` for them reflects that one shared record and any write from any page changes the header/footer everywhere.", {
|
|
3766
|
+
project_root: z
|
|
3767
|
+
.string()
|
|
3768
|
+
.describe("Absolute path to the code-component project."),
|
|
3769
|
+
page_id: z.string().describe("Target page id (from `list_editor_pages`)."),
|
|
3770
|
+
port: z
|
|
3771
|
+
.number()
|
|
3772
|
+
.optional()
|
|
3773
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
3774
|
+
}, async ({ project_root, page_id, port }) => {
|
|
3775
|
+
const args = [
|
|
3776
|
+
"list-page-sections",
|
|
3777
|
+
"--page-id",
|
|
3778
|
+
page_id,
|
|
3779
|
+
...(port ? ["--port", String(port)] : []),
|
|
3780
|
+
];
|
|
3781
|
+
return callEditorAction(project_root, args);
|
|
3782
|
+
});
|
|
3783
|
+
// Tool: get_component_props
|
|
3784
|
+
server.tool("get_component_props", "Get prop blueprints straight from the editor (the source of truth) for one or MANY components in a single call — for any section OR child code component ids. Returns `{ components: [...] }`, each prop carrying its `id`, `name`, `type`, `required`, `default`, and crucially: a ready-to-use `writeExample` (the EXACT value shape to pass to update_section_prop / update_page_sections — e.g. PRODUCT_LIST, BLOG_LIST, COMPONENT_LIST, LINK) plus a `writeNote` for variants, so you do NOT have to guess or trial-write the JSON; for ENUM props the `options` (valid `value`s); and for COMPONENT/COMPONENT_LIST props the `allowedComponentIds` (which children the slot permits — when empty, an `allowedComponentsNote` says any imported code component is allowed). Use this (its `writeExample`/`options`/`allowedComponentIds`) instead of guessing or reading ikas.config.json. Pass ALL the section/child ids you need at once (batch). Child component ids come from a parent prop's `allowedComponentIds` (or get_section_template).", {
|
|
3785
|
+
project_root: z
|
|
3786
|
+
.string()
|
|
3787
|
+
.describe("Absolute path to the code-component project."),
|
|
3788
|
+
component_ids: z
|
|
3789
|
+
.array(z.string())
|
|
3790
|
+
.describe("Section/child code-component ids to resolve (batch). From list_imported_sections or a COMPONENT_LIST prop's allowedComponentIds."),
|
|
3791
|
+
port: z
|
|
3792
|
+
.number()
|
|
3793
|
+
.optional()
|
|
3794
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
3795
|
+
}, async ({ project_root, component_ids, port }) => {
|
|
3796
|
+
const args = [
|
|
3797
|
+
"get-component-props",
|
|
3798
|
+
"--component-ids",
|
|
3799
|
+
(component_ids || []).join(","),
|
|
3800
|
+
...(port ? ["--port", String(port)] : []),
|
|
3801
|
+
];
|
|
3802
|
+
return callEditorAction(project_root, args);
|
|
3803
|
+
});
|
|
3804
|
+
// Tool: get_section_values
|
|
3805
|
+
server.tool("get_section_values", "Get the CURRENT prop values of one or MANY placed sections (each with its full `propValues` plus blueprint `props` — every prop carrying a `writeExample`/`writeNote` for the exact value shape, plus ENUM `options` and COMPONENT_LIST `allowedComponentIds`). `list_page_sections` is lean and omits values to avoid truncation; use this to read sections' values — needed for read-modify-write of a COMPONENT_LIST, or to inspect the exact stored shape of an existing value. Returns `{ sections: [...] }`. Pass all the elementIds you need at once (batch). COMMON (global) sections — the theme's header and footer — keep ONE shared set of prop values for the whole theme, stored on the INDEX (Home) page's placement; for those this tool reads the values FROM that canonical placement (a non-INDEX placement stores nothing of its own) and returns a `common` block naming `canonicalPageId`/`canonicalElementId`. So the values you get for a header/footer are the live ones the page actually renders no matter which page_id you ask from — do NOT read defaults as \"empty\" and blind-fill them, and remember any write goes to that same shared record and changes all pages.", {
|
|
3806
|
+
project_root: z
|
|
3807
|
+
.string()
|
|
3808
|
+
.describe("Absolute path to the code-component project."),
|
|
3809
|
+
page_id: z.string().describe("Target page id (from `list_editor_pages`)."),
|
|
3810
|
+
element_ids: z
|
|
3811
|
+
.array(z.string())
|
|
3812
|
+
.describe("Placed-section elementIds to read (batch). From `list_page_sections`."),
|
|
3813
|
+
port: z
|
|
3814
|
+
.number()
|
|
3815
|
+
.optional()
|
|
3816
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
3817
|
+
}, async ({ project_root, page_id, element_ids, port }) => {
|
|
3818
|
+
const args = [
|
|
3819
|
+
"get-section-values",
|
|
3820
|
+
"--page-id",
|
|
3821
|
+
page_id,
|
|
3822
|
+
"--element-ids",
|
|
3823
|
+
(element_ids || []).join(","),
|
|
3824
|
+
...(port ? ["--port", String(port)] : []),
|
|
3825
|
+
];
|
|
3826
|
+
return callEditorAction(project_root, args);
|
|
3827
|
+
});
|
|
3828
|
+
// Tool: update_section_prop
|
|
3829
|
+
server.tool("update_section_prop", 'Change a single prop value of a section placed on a page. This is the tool for FILLING/SETTING content (heading, text, image, link, etc.) on an existing section — it is pure data entry: it writes NO component code and needs NO rebuild. Do not author a new prop or component to set a value the section already supports; first check the section\'s existing `props` via `list_page_sections`. Target the specific placement by its `element_id` (from `list_page_sections`) and the prop by `prop_id` or `prop_name` (also from `list_page_sections`). `value` is the prop value object as stored by the editor — for scalar props it is wrapped as `{ "value": <scalar> }` (e.g. `{ "value": "Hello" }` for TEXT, `{ "value": true }` for BOOLEAN, `{ "value": 12 }` for NUMBER, `{ "value": "#FF0000" }` for COLOR, `{ "value": "<enum-key>" }` for ENUM). A COLOR prop can ALSO bind to a global theme color instead of a literal hex — pass `{ "patternValueId": "<id>" }` (the color id from `list_theme_globals` → `colors[].id`) and the prop tracks that global color live (resolved to `var(--<id>)` at render); the id is validated and an unknown one is REJECTED. Richer object prop types use their own object shape and are NOT `{ "value": ... }`-wrapped (full catalog in `get_editor_workflow`): IMAGE = `{ "id": "<asset-id>", "altText"?: "<alt>", "isVideo"?: false }` (the `id` MUST reference an already-uploaded asset — call `upload_image` with a `file_path`/`image_url` to get one, or reuse an existing `id` from another section\'s `propValues`); IMAGE_LIST = `{ "images": [ <image>, ... ] }`; VIDEO = `{ "video": { "id": "<asset-id>" }, "thumbnailImage"?: { "id": "..." }, "autoplay"?: false, "controls"?: true, "loop"?: false, "muted"?: false }` (NOT a bare `{ "id": ... }`); SVG = `{ "value": "<svg markup>" }` (value-wrapped, like a scalar); SVG_LIST = `{ "svgs": [ "<svg>", ... ] }`; TYPE (style props such as BorderRadiusStyleType/PaddingStyleType/GapStyleType) = the type-shaped object ITSELF, e.g. `{ "value": 8, "unit": "px" }` — get the exact field structure from the prop\'s `writeExample`/`typeName` in `get_component_props` or `get_type_definition("<typeName>")`; unknown fields, wrong field types, and invalid union values (e.g. `"unit": "banana"`) are REJECTED; entity props PRODUCT/CATEGORY/BRAND/BLOG/BLOG_CATEGORY/RAFFLE = `{ "<entity>Id": "...", "usePageData"?: false }` (e.g. `{ "categoryId": "..." }`) — get real ids from `search_products` (PRODUCT), `list_categories`, `list_brands`, `list_blogs`, `list_blog_categories`; PRODUCT_ATTRIBUTE = `{ "productId": "...", "variantId": "...", "attributeId": "..." }` — `variantId` is REQUIRED alongside `productId` (without it the value resolves with `product: null` and the component renders nothing), or bind to the page product with `{ "attributeId": "...", "usePageData": true }` on a product detail page; PRODUCT_ATTRIBUTE_LIST = the same with `"attributeIds": [ "..." ]`, and note the component receives a SINGLE wrapper object, never an array (read both with `getAttributeDetailValues()` / `getAttributeListValues()` — see `get_framework_guide("prop-types")`); list/collection props are typed objects keyed by a `<entity>ListType` discriminator: PRODUCT_LIST = `{ "id": "<unique>", "productListType": "STATIC", "productIds": [ { "productId": "...", "variantId": "..." } ], "initialLimit"?: 12 }` — note productIds is an array of {productId, variantId} PAIRS (from search_products), not bare ids; productListType ∈ ALL|STATIC|DISCOUNTED|RECOMMENDED|CATEGORY|SEARCH|LAST_VIEWED|RELATED_PRODUCTS|VIEWED_TOGETHER|PURCHASED_TOGETHER, and for a dynamic type use e.g. `{ "id": "<unique>", "productListType": "CATEGORY", "category": "<id from list_categories>" }` (the field is `category`, NOT `categoryId` — `categoryId` is only the standalone CATEGORY entity prop; no productIds here) or `"ALL"` (no ids). Unknown sub-fields inside a PRODUCT_LIST (e.g. `categoryId`) are REJECTED, not silently stored. CATEGORY_LIST = `{ "categoryListType": "STATIC", "categoryIds": ["..."] }` or `{ "categoryListType": "ALL" }`. BRAND_LIST = `{ "brandListType": "STATIC", "brandIds": ["..."] }` or ALL. BLOG_LIST = `{ "blogListType": "STATIC", "blogIds": ["..."] }`, `{ "blogListType": "CATEGORY", "categoryId": "..." }`, or ALL. BLOG_CATEGORY_LIST = `{ "blogCategoryListType": "STATIC", "blogCategoryIds": ["..."] }` or ALL. (Get the entity ids from search_products / list_*; you can also read an existing value with `get_section_values` to copy its exact shape.) LINK = a single link object `{ "id": "<unique-short-id>", "linkType": "PAGE"|"EXTERNAL"|"FILE", "label": "...", "openInNewTab"?: false, "subLinks": [] }` plus the target for its type — for PAGE add `"pageId"` AND `"pageType"` (both from `list_editor_pages`, e.g. pageType "INDEX"; for dynamic page types like PRODUCT/CATEGORY/BLOG also add the target `"itemId"`), for EXTERNAL add `"externalLink": "https://..."`. Examples: PAGE → `{ "id": "k3p9x", "linkType": "PAGE", "label": "Home", "pageId": "<page-id>", "pageType": "INDEX", "openInNewTab": false, "subLinks": [] }`; EXTERNAL → `{ "id": "m7q2z", "linkType": "EXTERNAL", "label": "Docs", "externalLink": "https://example.com", "openInNewTab": true, "subLinks": [] }`. To link to an ENTITY (category/brand/blog/blog-category) do NOT guess a slug — get the entity id from `list_categories`/`list_brands`/`list_blogs`/`list_blog_categories` and the page id from `get_page_by_type("<TYPE>")`, then build `{ "id": "<unique>", "linkType": "PAGE", "label": "...", "pageId": <pageId>, "pageType": "<TYPE>", "itemId": <entityId>, "subLinks": [] }`. LIST_OF_LINK = `{ "links": [ <link>, ... ] }` (each item is a link object as above). PRODUCT = `{ "productId": "...", "variantId"?: "..." }`. This SAME unwrapped shape applies whether the prop sits at section level OR nested inside a COMPONENT_LIST entry\'s `propValues` — there is no section-vs-nested difference. IMPORTANT: pass `value` as the parsed JSON object/array itself, NEVER as a JSON string (a stringified value is double-encoded and stored as a useless string). Values are validated server-side (deeply, including nested COMPONENT_LIST children): wrong shapes AND wrong semantics are REJECTED with an explanatory error instead of being silently stored. This includes: a `{ "value": [...] }` wrapper for a COMPONENT_LIST; a `{ "value": ... }`-wrapped IMAGE; `props` instead of `propValues`; a missing/duplicate entry `id`; a child referenced by the wrong key (a code component MUST use `codeComponentId`, a theme component `componentId`) or by an id that does not exist (child ids are opaque — take them from `get_section_template` / `list_imported_sections`, never invent them); and any `propValues` key that is not a real prop of that child component (the error lists the valid prop names). Auto-import: a referenced child code component that has been BUILT but not yet imported into the theme is imported automatically before the value is set (the response lists any such ids under `autoImported`); only children that are not built at all fail with a "no imported code component" error — build them first (`ikas-component build`/`dev`). For any prop type you are unsure about, inspect the existing value with `get_section_values` and match its exact shape. The change is applied with undo support.\n\n' +
|
|
3830
|
+
"COMMON (global) sections — the theme's HEADER and FOOTER: these render on EVERY page and have ONE shared set of prop values, stored on the INDEX (Home) page's placement. Whichever page_id you write from, the value lands on that single record and changes the header/footer on ALL pages; the response carries a `common` block (`commonSectionType`, `canonicalPageId`, `canonicalElementId`) saying so, and the echoed `value` is read back from that canonical placement. Therefore: ALWAYS `get_section_values` first and change only the prop the user asked about — the props are already filled with the merchant's content even when you are on a page you have not inspected, so blind-filling \"empty-looking\" props overwrites the live header/footer everywhere. If the INDEX page has no placement of the section, there is no record to write to and the call fails telling you to add it to the INDEX page first.\n\n" +
|
|
3831
|
+
'BIND TO A GLOBAL VARIABLE (Theme Setting): instead of a static `value`, pass `bind_global` = the global\'s `name` (its `variableName`, the `_<id>` form) from `list_theme_globals`. The prop becomes a LIVE dynamic value that always reflects that global\'s current value — editing the global in Theme Settings updates every bound prop. Use this to wire content to a project-wide setting (e.g. a shared announcement text, brand color, or logo image) rather than duplicating a literal. Pick a global whose type matches the prop (TEXT↔TEXT/RICH_TEXT, NUMBER↔NUMBER, BOOLEAN↔BOOLEAN, IMAGE↔IMAGE, COLOR↔COLOR, …). Provide `value` OR `bind_global`, not both. To bind a prop of a COMPONENT_LIST CHILD, also pass `list_path` (the `{ propId, index }` steps down to the child) and set `prop_id` to the child\'s prop id. Works for every section type, including built-in / code-component sections that have no blueprint.\n\n' +
|
|
3832
|
+
'COMPONENT_LIST / COMPONENT props: the value is NOT wrapped in `{ "value": ... }`. A COMPONENT_LIST value is `{ "components": [ <entry>, ... ] }`; a single COMPONENT value is one `<entry>`. Each entry = `{ "id": "<unique-id>", "codeComponentId": "<child-id>" | "componentId": "<child-id>", "propValues": { "<childPropName>": <wrapped-value>, ... } }`. Rules: (1) `id` is a unique short alphanumeric string identifying THIS entry — generate a fresh one per new entry and NEVER reuse an existing entry\'s id. (2) Use `codeComponentId` for code components, `componentId` for built-in theme components. (3) `propValues` is keyed by the CHILD component\'s prop NAMES, each using the same scalar wrappers as above (nesting is recursive — a child may itself hold a COMPONENT_LIST). (4) `update_section_prop` REPLACES the whole prop value — there is NO partial/deep merge. ALWAYS send the COMPLETE, fully-nested value for the prop: every existing entry (with its id), every nested `propValues`, and every nested COMPONENT_LIST at every depth. To change anything (even one deeply-nested scalar, or to add/remove/reorder a child), READ-MODIFY-WRITE: take the current `{ "components": [...] }` from `get_section_values`, edit it in place (preserving all other entries, ids, and nested structures), then send the ENTIRE updated object back. Sending only the changed part — a single entry, or a child without its siblings — wipes everything you omitted. (5) You can only add child component types the prop permits — call `get_component_props(parentComponentId)` to read the COMPONENT_LIST prop\'s `allowedComponentIds`, then `get_component_props(childId)` to learn that child\'s props (names, types, ENUM `options`/valid values) instead of guessing or reading ikas.config.json. The allowed set is wired at build/config time per the `get_section_template` setup recipe (`config update-prop`), not here.\n\n' +
|
|
3833
|
+
'Example — a full COMPONENT_LIST `value` with two children, where the second child itself nests another COMPONENT_LIST (note: scalar leaves are `{ "value": ... }`-wrapped, COMPONENT_LIST values are `{ "components": [...] }` and are NOT wrapped, every entry has a unique `id`, and this is the COMPLETE value you would send even to change just one field): ' +
|
|
3834
|
+
`{ "components": [ { "id": "a1b2c", "codeComponentId": "7ojrigep-Eml9n5sN3i", "propValues": { "heading": { "value": "Featured" }, "visible": { "value": true } } }, { "id": "d3e4f", "codeComponentId": "x2plk9zq-Qw8rt", "propValues": { "title": { "value": "Sub group" }, "cards": { "components": [ { "id": "g5h6i", "codeComponentId": "card01ab-Zz12", "propValues": { "label": { "value": "Card 1" } } }, { "id": "j7k8l", "codeComponentId": "card01ab-Zz12", "propValues": { "label": { "value": "Card 2" } } } ] } } } ] }`, {
|
|
3835
|
+
project_root: z
|
|
3836
|
+
.string()
|
|
3837
|
+
.describe("Absolute path to the code-component project."),
|
|
3838
|
+
page_id: z.string().describe("Target page id (from `list_editor_pages`)."),
|
|
3839
|
+
element_id: z
|
|
3840
|
+
.string()
|
|
3841
|
+
.describe("Placed-section elementId identifying THIS placement on the page (from `list_page_sections`)."),
|
|
3842
|
+
prop_id: z
|
|
3843
|
+
.string()
|
|
3844
|
+
.optional()
|
|
3845
|
+
.describe("Blueprint prop id to update (from `list_page_sections`). Provide this or `prop_name`."),
|
|
3846
|
+
prop_name: z
|
|
3847
|
+
.string()
|
|
3848
|
+
.optional()
|
|
3849
|
+
.describe("Blueprint prop name to update (alternative to `prop_id`)."),
|
|
3850
|
+
value: z
|
|
3851
|
+
.any()
|
|
3852
|
+
.optional()
|
|
3853
|
+
.describe('The prop value object to store, e.g. `{ "value": "Hello" }`. Match the shape of the existing value from `get_section_values` for non-scalar prop types. Omit when using `bind_global`.'),
|
|
3854
|
+
bind_global: z
|
|
3855
|
+
.string()
|
|
3856
|
+
.optional()
|
|
3857
|
+
.describe("Bind this prop to a project GLOBAL variable (Theme Setting) as a LIVE dynamic value instead of writing a static `value` — the prop then always reflects that global's current value (edited in Theme Settings). Pass the global's `name` (its `variableName`, the `_<id>` form) from `list_theme_globals`. Provide `value` OR `bind_global`, not both. Bindable globals include TEXT / RICH_TEXT / NUMBER / BOOLEAN / IMAGE / COLOR / BORDER / SHADOW settings; pick a global whose type matches the prop. (This is the general theme-global binding; a COLOR prop can alternatively take an inline `{ \"patternValueId\" }` for theme colors.)"),
|
|
3858
|
+
list_path: z
|
|
3859
|
+
.array(z.object({ propId: z.string(), index: z.number() }))
|
|
3860
|
+
.optional()
|
|
3861
|
+
.describe("Only with `bind_global`: bind a prop of a COMPONENT_LIST child instead of a section-level prop. An array of `{ propId, index }` steps from the section down to the target child; `prop_id` is then the CHILD's prop id (from `get_component_props`)."),
|
|
3862
|
+
port: z
|
|
3863
|
+
.number()
|
|
3864
|
+
.optional()
|
|
3865
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
3866
|
+
}, async ({ project_root, page_id, element_id, prop_id, prop_name, value, bind_global, list_path, port, }) => {
|
|
3867
|
+
const args = [
|
|
3868
|
+
"update-section-prop",
|
|
3869
|
+
"--page-id",
|
|
3870
|
+
page_id,
|
|
3871
|
+
"--element-id",
|
|
3872
|
+
element_id,
|
|
3873
|
+
...(prop_id ? ["--prop-id", prop_id] : []),
|
|
3874
|
+
...(prop_name ? ["--prop-name", prop_name] : []),
|
|
3875
|
+
...(bind_global
|
|
3876
|
+
? ["--bind-global", bind_global, ...(list_path ? ["--list-path", JSON.stringify(list_path)] : [])]
|
|
3877
|
+
: [
|
|
3878
|
+
"--value",
|
|
3879
|
+
// The CLI JSON.parses --value. If `value` is already a JSON string, pass
|
|
3880
|
+
// it through verbatim — re-stringifying it would double-encode it and the
|
|
3881
|
+
// editor would store a string instead of the object/array.
|
|
3882
|
+
typeof value === "string" ? value : JSON.stringify(value),
|
|
3883
|
+
]),
|
|
3884
|
+
...(port ? ["--port", String(port)] : []),
|
|
3885
|
+
];
|
|
3886
|
+
return callEditorAction(project_root, args);
|
|
3887
|
+
});
|
|
3888
|
+
// Tool: upload_image
|
|
3889
|
+
server.tool("upload_image", 'Upload an image to the connected editor\'s project and get back its image `id`. Provide the image via `file_path` (a local path) OR `image_url`. This is the ONLY way to obtain a real image id — an id cannot be invented. Use the returned `id`: (1) as an IMAGE prop value for `update_section_prop` (e.g. `{ "id": "<returned-id>", "altText": "...", "isVideo": false }`), or (2) as an IMAGE theme global\'s value for `create_theme_global`/`update_theme_global` (e.g. `{ "id": "<returned-id>" }`). An id cannot be invented — an unreal one is stored as given and renders as a broken image, so always use a `upload_image` id or one already listed by `list_theme_globals`. Neither tool uploads; both only reference an existing image id. Supported types: png, jpg, jpeg, webp, gif; max 10MB. Requires the editor to be embedded in the ikas admin panel (the admin panel performs the actual upload; a standalone editor cannot upload and will error/time out).', {
|
|
3890
|
+
project_root: z
|
|
3891
|
+
.string()
|
|
3892
|
+
.describe("Absolute path to the code-component project."),
|
|
3893
|
+
file_path: z
|
|
3894
|
+
.string()
|
|
3895
|
+
.optional()
|
|
3896
|
+
.describe("Local image file path (.png, .jpg, .jpeg, .webp, .gif). Provide this or `image_url`."),
|
|
3897
|
+
image_url: z
|
|
3898
|
+
.string()
|
|
3899
|
+
.optional()
|
|
3900
|
+
.describe("Image URL to fetch and upload (alternative to `file_path`)."),
|
|
3901
|
+
alt_text: z
|
|
3902
|
+
.string()
|
|
3903
|
+
.optional()
|
|
3904
|
+
.describe("Alt text to store with the image."),
|
|
3905
|
+
port: z
|
|
3906
|
+
.number()
|
|
3907
|
+
.optional()
|
|
3908
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
3909
|
+
}, async ({ project_root, file_path, image_url, alt_text, port }) => {
|
|
3910
|
+
const args = [
|
|
3911
|
+
"upload-image",
|
|
3912
|
+
...(file_path ? ["--file", file_path] : []),
|
|
3913
|
+
...(image_url ? ["--url", image_url] : []),
|
|
3914
|
+
...(alt_text ? ["--alt", alt_text] : []),
|
|
3915
|
+
...(port ? ["--port", String(port)] : []),
|
|
3916
|
+
];
|
|
3917
|
+
return callEditorAction(project_root, args);
|
|
3918
|
+
});
|
|
3919
|
+
// Tool: update_page_sections
|
|
3920
|
+
server.tool("update_page_sections", "Fill MANY placed sections of a page in a SINGLE call — the fastest way to populate a whole page (one round-trip for the entire page instead of one call per section/prop). Takes `sections`, each `{ element_id, updates: [{ prop_name|prop_id, value }] }`; values use the same per-type shapes as update_section_prop / get_editor_workflow. All-or-nothing across the whole page: every value is resolved and deeply validated (and built-but-unimported child code components auto-imported) before anything is written — one invalid value rejects the entire page update. An update item may instead bind a prop to a project GLOBAL variable (Theme Setting) as a live dynamic value: use `{ prop_id|prop_name, bind_global }` where `bind_global` is the global's `name` (its `variableName`) from `list_theme_globals` — omit `value`. Add `list_path` (an array of `{ propId, index }` steps) to bind a prop of a COMPONENT_LIST child (then `prop_id` is the child's prop id). Static value writes are applied first, then bindings. Prefer this over many update_section_prop(s) calls. If any targeted section is a COMMON (global) one — the theme's header/footer — its values are shared by every page and stored on the INDEX (Home) page's placement: the write goes there and changes that section on ALL pages, the result's `common` block says so, and the echoed values are read back from that canonical placement. Read those sections with `get_section_values` first and only change what was asked; a header/footer missing from the INDEX page has no record to write to and rejects the whole call.", {
|
|
3921
|
+
project_root: z
|
|
3922
|
+
.string()
|
|
3923
|
+
.describe("Absolute path to the code-component project."),
|
|
3924
|
+
page_id: z.string().describe("Target page id (from list_editor_pages)."),
|
|
3925
|
+
sections: z
|
|
3926
|
+
.array(z.object({
|
|
3927
|
+
element_id: z
|
|
3928
|
+
.string()
|
|
3929
|
+
.describe("Placed-section elementId (from list_page_sections)."),
|
|
3930
|
+
updates: z
|
|
3931
|
+
.array(z.object({
|
|
3932
|
+
prop_id: z
|
|
3933
|
+
.string()
|
|
3934
|
+
.optional()
|
|
3935
|
+
.describe("Blueprint prop id (provide this or prop_name)."),
|
|
3936
|
+
prop_name: z
|
|
3937
|
+
.string()
|
|
3938
|
+
.optional()
|
|
3939
|
+
.describe("Blueprint prop name (alternative to prop_id)."),
|
|
3940
|
+
value: z
|
|
3941
|
+
.any()
|
|
3942
|
+
.optional()
|
|
3943
|
+
.describe("Prop value, same shape update_section_prop expects for that type. Omit when using bind_global."),
|
|
3944
|
+
bind_global: z
|
|
3945
|
+
.string()
|
|
3946
|
+
.optional()
|
|
3947
|
+
.describe("Bind this prop to a project GLOBAL variable (Theme Setting) as a live dynamic value instead of a static value. The global's `name` (variableName) from list_theme_globals. Provide value OR bind_global."),
|
|
3948
|
+
list_path: z
|
|
3949
|
+
.array(z.object({ propId: z.string(), index: z.number() }))
|
|
3950
|
+
.optional()
|
|
3951
|
+
.describe("Only with bind_global: `{ propId, index }` steps down to a COMPONENT_LIST child; prop_id is then the child's prop id."),
|
|
3952
|
+
}))
|
|
3953
|
+
.describe("Non-empty array of prop updates for this section."),
|
|
3954
|
+
}))
|
|
3955
|
+
.describe("Non-empty array of sections to fill, each with its elementId and prop updates."),
|
|
3956
|
+
port: z
|
|
3957
|
+
.number()
|
|
3958
|
+
.optional()
|
|
3959
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
3960
|
+
}, async ({ project_root, page_id, sections, port }) => {
|
|
3961
|
+
const normalized = (sections || []).map((s) => ({
|
|
3962
|
+
elementId: s.element_id,
|
|
3963
|
+
updates: (s.updates || []).map((u) => ({
|
|
3964
|
+
...(u.prop_id ? { propId: u.prop_id } : {}),
|
|
3965
|
+
...(u.prop_name ? { propName: u.prop_name } : {}),
|
|
3966
|
+
...(u.bind_global
|
|
3967
|
+
? { bindGlobal: u.bind_global, ...(u.list_path ? { listPath: u.list_path } : {}) }
|
|
3968
|
+
: { value: u.value }),
|
|
3969
|
+
})),
|
|
3970
|
+
}));
|
|
3971
|
+
const args = [
|
|
3972
|
+
"update-page-sections",
|
|
3973
|
+
"--page-id",
|
|
3974
|
+
page_id,
|
|
3975
|
+
"--sections",
|
|
3976
|
+
JSON.stringify(normalized),
|
|
3977
|
+
...(port ? ["--port", String(port)] : []),
|
|
3978
|
+
];
|
|
3979
|
+
return callEditorAction(project_root, args);
|
|
3980
|
+
});
|
|
3981
|
+
// Tool: upload_images
|
|
3982
|
+
server.tool("upload_images", "Upload MANY images in one call (batch upload_image) and get their ids back in order — the host uploads them all in a single round-trip. Pass `images`, each `{ file_path?, image_url?, alt_text? }`. Returns an array of { id, fileName, altText, isVideo } in the same order; use each id in an IMAGE prop value. Prefer this over multiple upload_image calls when a section/page needs several images. Supported: png/jpg/jpeg/webp/gif, max 10MB each. Requires the editor embedded in the ikas admin panel.", {
|
|
3983
|
+
project_root: z
|
|
3984
|
+
.string()
|
|
3985
|
+
.describe("Absolute path to the code-component project."),
|
|
3986
|
+
images: z
|
|
3987
|
+
.array(z.object({
|
|
3988
|
+
file_path: z
|
|
3989
|
+
.string()
|
|
3990
|
+
.optional()
|
|
3991
|
+
.describe("Local image file path (provide this or image_url)."),
|
|
3992
|
+
image_url: z
|
|
3993
|
+
.string()
|
|
3994
|
+
.optional()
|
|
3995
|
+
.describe("Image URL to fetch (alternative to file_path)."),
|
|
3996
|
+
alt_text: z.string().optional().describe("Alt text for this image."),
|
|
3997
|
+
}))
|
|
3998
|
+
.describe("Non-empty array of images to upload."),
|
|
3999
|
+
port: z
|
|
4000
|
+
.number()
|
|
4001
|
+
.optional()
|
|
4002
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4003
|
+
}, async ({ project_root, images, port }) => {
|
|
4004
|
+
const manifest = (images || []).map((im) => ({
|
|
4005
|
+
...(im.file_path ? { file: im.file_path } : {}),
|
|
4006
|
+
...(im.image_url ? { url: im.image_url } : {}),
|
|
4007
|
+
...(im.alt_text ? { alt: im.alt_text } : {}),
|
|
4008
|
+
}));
|
|
4009
|
+
const args = [
|
|
4010
|
+
"upload-images",
|
|
4011
|
+
"--manifest",
|
|
4012
|
+
JSON.stringify(manifest),
|
|
4013
|
+
...(port ? ["--port", String(port)] : []),
|
|
4014
|
+
];
|
|
4015
|
+
return callEditorAction(project_root, args);
|
|
4016
|
+
});
|
|
4017
|
+
// Tool: search_products
|
|
4018
|
+
server.tool("search_products", 'Search the connected store\'s products to obtain a real productId (and first variantId) for a PRODUCT prop value. Returns products with productId, variantId, name, slug, variantCount, and `imageSrc` (the full-resolution CDN URL of the product\'s main image). To use that product image in an IMAGE prop, you CANNOT reuse a product image id directly (it is not a theme asset) — pass the `imageSrc` URL to `upload_image(image_url: <imageSrc>)` (or `upload_images`), then use the returned id in the IMAGE value. This gives real product imagery instead of external/placeholder URLs. Use the result in update_section_prop as `{ "productId": "<productId>", "variantId": "<variantId>" }`. Pass `query` for free-text search, or `product_ids` to resolve specific ids. Requires the editor embedded in the ikas admin panel (the admin panel runs the search; a standalone editor cannot).', {
|
|
4019
|
+
project_root: z
|
|
4020
|
+
.string()
|
|
4021
|
+
.describe("Absolute path to the code-component project."),
|
|
4022
|
+
query: z
|
|
4023
|
+
.string()
|
|
4024
|
+
.optional()
|
|
4025
|
+
.describe("Free-text product search (name, sku, barcode)."),
|
|
4026
|
+
product_ids: z
|
|
4027
|
+
.array(z.string())
|
|
4028
|
+
.optional()
|
|
4029
|
+
.describe("Specific product ids to resolve directly (alternative to `query`)."),
|
|
4030
|
+
per_page: z.number().optional().describe("Results per page."),
|
|
4031
|
+
port: z
|
|
4032
|
+
.number()
|
|
4033
|
+
.optional()
|
|
4034
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4035
|
+
}, async ({ project_root, query, product_ids, per_page, port }) => {
|
|
4036
|
+
const args = [
|
|
4037
|
+
"search-products",
|
|
4038
|
+
...(query ? ["--query", query] : []),
|
|
4039
|
+
...(product_ids && product_ids.length
|
|
4040
|
+
? ["--ids", product_ids.join(",")]
|
|
4041
|
+
: []),
|
|
4042
|
+
...(typeof per_page === "number" ? ["--per-page", String(per_page)] : []),
|
|
4043
|
+
...(port ? ["--port", String(port)] : []),
|
|
4044
|
+
];
|
|
4045
|
+
return callEditorAction(project_root, args);
|
|
4046
|
+
});
|
|
4047
|
+
// Tool: list_categories
|
|
4048
|
+
server.tool("list_categories", 'List the store\'s product categories and their ids, to fill a CATEGORY prop value `{ "categoryId": "<id>" }`. Returns categoryId, name, slug, parentId for each. Returns all categories (no query). To link to a category from a LINK prop, also call `get_page_by_type("CATEGORY")` for the page id, then build `{ "linkType": "PAGE", "pageId": <pageId>, "pageType": "CATEGORY", "itemId": <categoryId>, "id": <unique>, "label": "..." }`. Requires the editor embedded in the ikas admin panel.', {
|
|
4049
|
+
project_root: z
|
|
4050
|
+
.string()
|
|
4051
|
+
.describe("Absolute path to the code-component project."),
|
|
4052
|
+
port: z
|
|
4053
|
+
.number()
|
|
4054
|
+
.optional()
|
|
4055
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4056
|
+
}, async ({ project_root, port }) => {
|
|
4057
|
+
const args = [
|
|
4058
|
+
"list-entities",
|
|
4059
|
+
"--kind",
|
|
4060
|
+
"category",
|
|
4061
|
+
...(port ? ["--port", String(port)] : []),
|
|
4062
|
+
];
|
|
4063
|
+
return callEditorAction(project_root, args);
|
|
4064
|
+
});
|
|
4065
|
+
// Tool: list_brands
|
|
4066
|
+
server.tool("list_brands", 'List the store\'s product brands and their ids, to fill a BRAND prop value `{ "brandId": "<id>" }`. Returns brandId, name, slug for each. Returns all brands (no query). To link to a brand from a LINK prop, also call `get_page_by_type("BRAND")` for the page id, then build `{ "linkType": "PAGE", "pageId": <pageId>, "pageType": "BRAND", "itemId": <brandId>, "id": <unique>, "label": "..." }`. Requires the editor embedded in the ikas admin panel.', {
|
|
4067
|
+
project_root: z
|
|
4068
|
+
.string()
|
|
4069
|
+
.describe("Absolute path to the code-component project."),
|
|
4070
|
+
port: z
|
|
4071
|
+
.number()
|
|
4072
|
+
.optional()
|
|
4073
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4074
|
+
}, async ({ project_root, port }) => {
|
|
4075
|
+
const args = [
|
|
4076
|
+
"list-entities",
|
|
4077
|
+
"--kind",
|
|
4078
|
+
"brand",
|
|
4079
|
+
...(port ? ["--port", String(port)] : []),
|
|
4080
|
+
];
|
|
4081
|
+
return callEditorAction(project_root, args);
|
|
4082
|
+
});
|
|
4083
|
+
// Tool: list_blogs
|
|
4084
|
+
server.tool("list_blogs", 'List the store\'s blogs and their ids, to fill a BLOG prop value `{ "blogId": "<id>" }`. Returns blogId, name, slug for each. Accepts an optional `query` for free-text search. To link to a blog from a LINK prop, also call `get_page_by_type("BLOG")` for the page id, then build `{ "linkType": "PAGE", "pageId": <pageId>, "pageType": "BLOG", "itemId": <blogId>, "id": <unique>, "label": "..." }`. Requires the editor embedded in the ikas admin panel.', {
|
|
4085
|
+
project_root: z
|
|
4086
|
+
.string()
|
|
4087
|
+
.describe("Absolute path to the code-component project."),
|
|
4088
|
+
query: z.string().optional().describe("Free-text blog search."),
|
|
4089
|
+
port: z
|
|
4090
|
+
.number()
|
|
4091
|
+
.optional()
|
|
4092
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4093
|
+
}, async ({ project_root, query, port }) => {
|
|
4094
|
+
const args = [
|
|
4095
|
+
"list-entities",
|
|
4096
|
+
"--kind",
|
|
4097
|
+
"blog",
|
|
4098
|
+
...(query ? ["--query", query] : []),
|
|
4099
|
+
...(port ? ["--port", String(port)] : []),
|
|
4100
|
+
];
|
|
4101
|
+
return callEditorAction(project_root, args);
|
|
4102
|
+
});
|
|
4103
|
+
// Tool: list_blog_categories
|
|
4104
|
+
server.tool("list_blog_categories", 'List the store\'s blog categories and their ids, to fill a BLOG_CATEGORY prop value `{ "blogCategoryId": "<id>" }`. Returns blogCategoryId, name, slug for each. Accepts an optional `query` for free-text search. To link to a blog category from a LINK prop, also call `get_page_by_type("BLOG_CATEGORY")` for the page id, then build `{ "linkType": "PAGE", "pageId": <pageId>, "pageType": "BLOG_CATEGORY", "itemId": <blogCategoryId>, "id": <unique>, "label": "..." }`. Requires the editor embedded in the ikas admin panel.', {
|
|
4105
|
+
project_root: z
|
|
4106
|
+
.string()
|
|
4107
|
+
.describe("Absolute path to the code-component project."),
|
|
4108
|
+
query: z.string().optional().describe("Free-text blog-category search."),
|
|
4109
|
+
port: z
|
|
4110
|
+
.number()
|
|
4111
|
+
.optional()
|
|
4112
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4113
|
+
}, async ({ project_root, query, port }) => {
|
|
4114
|
+
const args = [
|
|
4115
|
+
"list-entities",
|
|
4116
|
+
"--kind",
|
|
4117
|
+
"blog-category",
|
|
4118
|
+
...(query ? ["--query", query] : []),
|
|
4119
|
+
...(port ? ["--port", String(port)] : []),
|
|
4120
|
+
];
|
|
4121
|
+
return callEditorAction(project_root, args);
|
|
4122
|
+
});
|
|
4123
|
+
// Tool: get_page_by_type
|
|
4124
|
+
server.tool("get_page_by_type", 'Resolve a theme page\'s id from its pageType (CATEGORY, PRODUCT, BRAND, BLOG, BLOG_CATEGORY, INDEX, …). Use this to get the `pageId` needed to build a PAGE link to an entity: pair it with the entity id from list_categories/list_brands/list_blogs/list_blog_categories — `{ linkType:"PAGE", pageId:<this pageId>, pageType:<type>, itemId:<entityId>, id:<unique>, label:... }`. Returns `pageId: null` (with a note) if no page of that type exists yet — in that case call `create_page(page_type)` to add it, then use the returned pageId (do not guess a slug/EXTERNAL URL).', {
|
|
4125
|
+
project_root: z
|
|
4126
|
+
.string()
|
|
4127
|
+
.describe("Absolute path to the code-component project."),
|
|
4128
|
+
page_type: z
|
|
4129
|
+
.string()
|
|
4130
|
+
.describe("Page type to resolve, e.g. CATEGORY, PRODUCT, BRAND, BLOG, BLOG_CATEGORY, INDEX."),
|
|
4131
|
+
port: z
|
|
4132
|
+
.number()
|
|
4133
|
+
.optional()
|
|
4134
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4135
|
+
}, async ({ project_root, page_type, port }) => {
|
|
4136
|
+
const args = [
|
|
4137
|
+
"get-page-by-type",
|
|
4138
|
+
"--page-type",
|
|
4139
|
+
page_type,
|
|
4140
|
+
...(port ? ["--port", String(port)] : []),
|
|
4141
|
+
];
|
|
4142
|
+
return callEditorAction(project_root, args);
|
|
4143
|
+
});
|
|
4144
|
+
// Tool: create_page
|
|
4145
|
+
server.tool("create_page", 'Create a theme page of a given pageType in the connected editor. Use this when get_page_by_type returns `pageId: null` for a dynamic page (CATEGORY/PRODUCT/BRAND/BLOG/BLOG_CATEGORY) you need to link to: create the page, then build a PAGE link `{ linkType:"PAGE", pageId:<this pageId>, pageType:<type>, itemId:<entityId>, id:<unique>, label:... }` — do NOT guess a slug/EXTERNAL URL. Non-CUSTOM page types are unique per theme: if one already exists it is returned unchanged (`alreadyExisted: true`). CUSTOM pages require `name` and a unique `slug`. Account sub-pages (ADDRESSES/ORDERS/ORDER_DETAIL/FAVORITE_PRODUCTS/RAFFLE_ACCOUNT) need an ACCOUNT page first. Returns `{ pageType, pageId, name, slug }`. Requires `ikas-component dev` running with the editor connected.', {
|
|
4146
|
+
project_root: z
|
|
4147
|
+
.string()
|
|
4148
|
+
.describe("Absolute path to the code-component project."),
|
|
4149
|
+
page_type: z
|
|
4150
|
+
.string()
|
|
4151
|
+
.describe("Page type to create, e.g. CATEGORY, PRODUCT, BRAND, BLOG, BLOG_CATEGORY, INDEX, CUSTOM."),
|
|
4152
|
+
name: z
|
|
4153
|
+
.string()
|
|
4154
|
+
.optional()
|
|
4155
|
+
.describe("Page name. Required for CUSTOM pages; ignored otherwise."),
|
|
4156
|
+
slug: z
|
|
4157
|
+
.string()
|
|
4158
|
+
.optional()
|
|
4159
|
+
.describe("Page slug. Required (and unique) for CUSTOM pages; ignored otherwise."),
|
|
4160
|
+
port: z
|
|
4161
|
+
.number()
|
|
4162
|
+
.optional()
|
|
4163
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4164
|
+
}, async ({ project_root, page_type, name, slug, port }) => {
|
|
4165
|
+
const args = [
|
|
4166
|
+
"create-page",
|
|
4167
|
+
"--page-type",
|
|
4168
|
+
page_type,
|
|
4169
|
+
...(name ? ["--name", name] : []),
|
|
4170
|
+
...(slug ? ["--slug", slug] : []),
|
|
4171
|
+
...(port ? ["--port", String(port)] : []),
|
|
4172
|
+
];
|
|
4173
|
+
return callEditorAction(project_root, args);
|
|
4174
|
+
});
|
|
4175
|
+
// Tool: publish_theme
|
|
4176
|
+
server.tool("publish_theme", "Publish the current theme LIVE — the same action as the editor's Publish button (uploads the whole project to the storefront). This is REAL and customer-facing: the published site changes. SAFETY: it publishes nothing unless `confirm: true` is passed; if you omit it you get a dry-run with the `previewUrl` and a warning describing the impact. The MAIN/production theme additionally requires `confirm_production: true` (its URL is the live customer-facing domain). Use this when the user explicitly asks to publish/go live — do NOT publish on your own initiative. On success returns `{ published: true, previewUrl, isMainTheme }`; open `previewUrl` to review the result. Requires `ikas-component dev` running with the editor connected.", {
|
|
4177
|
+
project_root: z
|
|
4178
|
+
.string()
|
|
4179
|
+
.describe("Absolute path to the code-component project."),
|
|
4180
|
+
confirm: z
|
|
4181
|
+
.boolean()
|
|
4182
|
+
.optional()
|
|
4183
|
+
.describe("Set true to actually publish. Omitted/false = dry-run (returns previewUrl + warning, publishes nothing)."),
|
|
4184
|
+
confirm_production: z
|
|
4185
|
+
.boolean()
|
|
4186
|
+
.optional()
|
|
4187
|
+
.describe("Required IN ADDITION to confirm when the target is the MAIN/production theme (live customer-facing site)."),
|
|
4188
|
+
port: z
|
|
4189
|
+
.number()
|
|
4190
|
+
.optional()
|
|
4191
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4192
|
+
}, async ({ project_root, confirm, confirm_production, port }) => {
|
|
4193
|
+
const args = [
|
|
4194
|
+
"publish-theme",
|
|
4195
|
+
...(confirm ? ["--confirm"] : []),
|
|
4196
|
+
...(confirm_production ? ["--confirm-production"] : []),
|
|
4197
|
+
...(port ? ["--port", String(port)] : []),
|
|
4198
|
+
];
|
|
4199
|
+
return callEditorAction(project_root, args);
|
|
4200
|
+
});
|
|
4201
|
+
// Tool: get_editor_workflow
|
|
4202
|
+
const EDITOR_WORKFLOW_GUIDE = [
|
|
4203
|
+
"# Editor workflow: placing sections and filling their content on a page",
|
|
4204
|
+
"",
|
|
4205
|
+
"Use this when the user wants to add a section to a page and/or fill in its content (heading, text, image, link, slides, etc.) in the live editor. These are LIVE-EDITOR actions and require `ikas-component dev` running with the editor connected; image upload additionally requires the editor to be embedded in the ikas admin panel (the admin panel performs the upload — a standalone editor cannot upload).",
|
|
4206
|
+
"",
|
|
4207
|
+
"## Two distinct jobs — do not confuse them",
|
|
4208
|
+
"- (A) DEFINE props / author component code — changing WHICH props a component has. Edits component source/config (config add-prop/add-component, index.tsx) and needs a rebuild. Do this ONLY when a needed prop does not exist yet, or the user explicitly asks to build/modify the component.",
|
|
4209
|
+
"- (B) SET prop VALUES / fill content — giving values to props that ALREADY exist on a placed section. Pure data entry via list_page_sections + update_section_prop (+ upload_image). No code, no rebuild.",
|
|
4210
|
+
"When the user says 'fill this section', 'set the title/text/image/link', 'populate', 'change the content' → that is JOB (B). Do NOT write a component or add a prop to fill a value the section already supports.",
|
|
4211
|
+
"",
|
|
4212
|
+
"## Step-by-step (JOB B — fill content)",
|
|
4213
|
+
"1. list_editor_pages → choose the target page_id.",
|
|
4214
|
+
"2. list_page_sections(page_id) → for each placed section: its per-placement elementId, blueprint props (id, name, type), and setPropNames (which props already have a value). It is LEAN — no prop VALUES, so it never truncates. To read a section's current values (e.g. to read-modify-write a COMPONENT_LIST), call get_section_values(page_id, element_id). A section returned with a `common` field is the theme's header/footer — its values are theme-wide, not this page's; read the 'COMMON (global) sections' section below BEFORE touching it. (If the section is not on the page yet, see 'Placing a section' below.)",
|
|
4215
|
+
"3. To set props (fewest round-trips = fastest): update_page_sections(page_id, sections:[{element_id, updates:[{prop_name,value}]}]) fills the WHOLE page (or one section, or just one prop — it scales to all cases) in ONE call (best). update_section_prop sets a single prop, for quick one-offs. Pass each value as a parsed JSON object/array, NEVER a JSON string.",
|
|
4216
|
+
"4. For image props: upload_images(images:[{file_path|image_url, alt_text}]) uploads many in ONE call (preferred); upload_image for a single one. Use the returned id(s) in IMAGE values. Do uploads BEFORE the update call so you have the ids.",
|
|
4217
|
+
"Speed tip: each tool call is a round-trip — gather first (one list_page_sections), batch your uploads (upload_images) and your writes (update_page_sections), rather than calling per-prop/per-image.",
|
|
4218
|
+
"",
|
|
4219
|
+
"## COMMON (global) sections: the header and the footer",
|
|
4220
|
+
"The theme's header and footer are COMMON sections: they render on EVERY page and their prop values are SHARED by the whole theme — there is exactly ONE record, kept on the INDEX (Home) page's placement. A placement of the same section on any other page stores NOTHING of its own.",
|
|
4221
|
+
"- How to recognize one: list_page_sections / get_section_values / the write results return a `common` block for it — `isCommon: true`, `commonSectionType: \"header\"|\"footer\"`, `valuesArePageSpecific: false`, plus `canonicalPageId`/`canonicalElementId` (the INDEX placement that holds the values). A page containing one also gets a top-level `commonSectionsNote`.",
|
|
4222
|
+
"- READS are redirected for you: get_section_values / list_page_sections report a common section's values FROM the INDEX placement, whatever page_id you pass. So what you see is what the page actually renders — no need to re-read from the INDEX page.",
|
|
4223
|
+
"- WRITES are redirected too: update_section_prop / update_page_sections / add_sections_to_page store the value on that INDEX record, so the change applies to the header/footer on ALL pages. The echoed value is read back from the canonical placement, so it reflects what was really stored.",
|
|
4224
|
+
"- THE TRAP to avoid: a header/footer is normally already filled with the merchant's content. Never conclude a prop is empty and never blind-fill \"missing\" props — you would overwrite live content on every page, including pages you never opened. Always get_section_values first and change ONLY the prop the user asked about.",
|
|
4225
|
+
"- If the INDEX page has no placement of the section, there is no record: reads return nothing and writes are REJECTED (\"Index page does not have the common section!\"). Fix it by placing the section on the INDEX page (add_section_to_page with the INDEX page id — get it from list_editor_pages / get_page_by_type('INDEX')) and setting its props there; it then renders on the other pages too.",
|
|
4226
|
+
"",
|
|
4227
|
+
"## Building a whole page fast (placing + filling)",
|
|
4228
|
+
"- add_sections_to_page(page_id, sections:[{component_id, index?, updates:[{prop_name,value}]}]) places MANY sections AND sets their props in ONE call, returning each new elementId. This is the fastest path — prefer it over add_section_to_page per section followed by separate fills. Built-but-unimported section/child components are auto-imported.",
|
|
4229
|
+
"- For a single section: list_imported_sections (confirm imported; else import_section, after building) → add_section_to_page(component_id, page_id, index?) → then list_page_sections to get its elementId.",
|
|
4230
|
+
"",
|
|
4231
|
+
"## Value shapes by prop type (what to pass as `value`)",
|
|
4232
|
+
'- Scalars are WRAPPED: TEXT/RICH_TEXT { "value": "..." }, BOOLEAN { "value": true }, NUMBER { "value": 12 }, COLOR { "value": "#FF0000" }, ENUM { "value": "<key>" }, DATE { "value": ... }.',
|
|
4233
|
+
'- SVG is value-wrapped: { "value": "<svg markup>" }. NUMBER_RANGE: { "value": <number>, "unit": "px"|null }.',
|
|
4234
|
+
'- SVG naming: the editor shows each svg\'s `class` attribute as its display name in the list; add class="my-icon" to name it. SVG_LIST items with no class render as svg-1, svg-2, ….',
|
|
4235
|
+
'- Object props are NOT wrapped (no { "value": ... }):',
|
|
4236
|
+
' - IMAGE: { "id": "<asset-id>", "altText"?: "...", "isVideo"?: false } — get the id from upload_image. Same shape at section level AND nested in a component list. IMAGE_LIST: { "images": [ <image>, ... ] }.',
|
|
4237
|
+
' - VIDEO: { "video": { "id": "<asset-id>" }, "thumbnailImage"?: { "id": "..." }, "autoplay"?: false, "controls"?: true, "loop"?: false, "muted"?: false } — NOT a bare { "id": ... }. SVG_LIST: { "svgs": [ "<svg>", ... ] }.',
|
|
4238
|
+
' - LINK: { "id": "<unique>", "linkType": "PAGE"|"EXTERNAL"|"FILE", "label": "...", "subLinks": [] } plus target — for a static page: pageId + pageType (from list_editor_pages); for EXTERNAL: externalLink. To link to a CATEGORY/BRAND/BLOG/BLOG_CATEGORY entity, do NOT guess a slug — get the entity id from list_categories/list_brands/list_blogs/list_blog_categories and the page id from get_page_by_type(\'<TYPE>\'), then build { id, linkType:\'PAGE\', label, pageId:<pageId>, pageType:\'<TYPE>\', itemId:<entityId>, subLinks:[] }. LIST_OF_LINK = { "links": [ <link>, ... ] }.',
|
|
4239
|
+
' - Entity props PRODUCT/CATEGORY/BRAND/BLOG/BLOG_CATEGORY/RAFFLE: { "<entity>Id": "...", "usePageData"?: false } — e.g. { "productId": "...", "variantId"?: "..." }, { "categoryId": "..." }. Get real ids (never invent them) from: search_products (PRODUCT), list_categories (CATEGORY), list_brands (BRAND), list_blogs (BLOG), list_blog_categories (BLOG_CATEGORY). (RAFFLE has no lookup tool yet — read an existing value or ask the user.)',
|
|
4240
|
+
" - List/collection props (PRODUCT_LIST/CATEGORY_LIST/BRAND_LIST/BLOG_LIST/…): typed objects keyed by a <entity>ListType discriminator plus initialSort/initialLimit. The id field DEPENDS on the type — for PRODUCT_LIST: STATIC → productIds:[{productId,variantId}] (from search_products); CATEGORY → category:'<categoryId>' (from list_categories) — the field is `category`, NOT `categoryId` (categoryId is ONLY the standalone CATEGORY entity prop above); ALL/DISCOUNTED/RECOMMENDED/etc → no id field. Get the exact field set + writeNote from get_component_props, or read+edit an existing value via get_section_values. Unknown sub-fields (e.g. categoryId inside a PRODUCT_LIST) are REJECTED.",
|
|
4241
|
+
' - COMPONENT_LIST: { "components": [ { "id": "<unique>", "codeComponentId": "<child-id>", "propValues": { "<childProp>": <value>, ... } }, ... ] }. A single COMPONENT prop is one such entry. childProp values use these same per-type shapes, recursively.',
|
|
4242
|
+
"",
|
|
4243
|
+
"## COMPONENT_LIST rules (the part most often gotten wrong)",
|
|
4244
|
+
"- READ-MODIFY-WRITE: update_section_prop REPLACES the whole prop value. To add/edit/remove one child, take the CURRENT { components: [...] } from get_section_values, edit it, and resend the ENTIRE array (with all existing entries and their ids). Sending only your new entry wipes the rest.",
|
|
4245
|
+
"- Each entry needs a UNIQUE id (a short string you generate; it does not need to match anything). Do not reuse another entry's id.",
|
|
4246
|
+
'- Reference a code component with "codeComponentId" and a built-in theme component with "componentId" — not the other way around. Use "propValues" (not "props").',
|
|
4247
|
+
"- Child ids are opaque — take them from get_section_template / list_imported_sections; never invent them.",
|
|
4248
|
+
"- Auto-import: a referenced child that is BUILT but not yet imported is imported automatically (returned under autoImported). A child that is not built at all errors — build it first.",
|
|
4249
|
+
"",
|
|
4250
|
+
"## Reading prop schemas (avoid guessing)",
|
|
4251
|
+
"- get_component_props(componentId) → a component's props with types, required, default, ENUM `options` (the valid values to set), and COMPONENT_LIST `allowedComponentIds` (valid children). Works for any section OR child id. Use it BEFORE filling — to know prop names, enum values, and which children a slot allows — instead of guessing or reading ikas.config.json.",
|
|
4252
|
+
"- For a COMPONENT_LIST: get_component_props(parent) → its allowedComponentIds → get_component_props(child) → the child's props/enums. Then build the components array.",
|
|
4253
|
+
"- get_section_values(element_id) → one placed section's current values (read-modify-write of a COMPONENT_LIST, or to copy an existing value's exact shape).",
|
|
4254
|
+
"- Real entity ids/images: search_products returns productId + variantId + imageSrc (the product image URL). To use that image in an IMAGE prop, you can't reuse a product image id — upload it: upload_image(image_url: imageSrc) → use the returned id. list_categories/list_brands/list_blogs/list_blog_categories return the entity ids; to LINK to one, also call get_page_by_type('<TYPE>') for the page id and build a PAGE link { linkType:'PAGE', pageId, pageType, itemId:<entityId>, id, label }. IMPORTANT: if get_page_by_type returns pageId:null, that dynamic page does NOT exist in the theme yet — do NOT guess a slug/EXTERNAL URL. Call create_page('<TYPE>') to add it (non-CUSTOM types are unique and returned as-is if already present), then use the returned pageId to build the PAGE link. Always have a real pageId before building a PAGE link.",
|
|
4255
|
+
"",
|
|
4256
|
+
"## Validation",
|
|
4257
|
+
"Values are validated server-side (deeply, including nested children). Wrong shape or wrong semantics (double-encoded string, { value } wrapper on an object prop, props vs propValues, missing/duplicate id, wrong reference key, nonexistent component id, unknown prop name) are REJECTED with an explanatory error instead of being stored silently. Read the error and fix the value; if unsure of a shape, read it with get_section_values and match it.",
|
|
4258
|
+
].join("\n");
|
|
4259
|
+
server.tool("get_editor_workflow", "Read this FIRST when the user wants to place a section on a page or fill/edit a section's content (text, image, link, slides, component lists) in the live editor. Returns the complete step-by-step workflow for the live-editor tools (list_editor_pages, list_imported_sections, import_section, add_section_to_page, list_page_sections, update_section_prop, upload_image), the per-prop-type value shapes, the COMPONENT_LIST read-modify-write rules, how COMMON (global) header/footer sections keep one theme-wide set of values on the INDEX page (and how not to overwrite them), and how validation/auto-import behave. Use it to avoid the common mistake of writing component code to set a value a section already supports.", {}, async () => {
|
|
4260
|
+
return {
|
|
4261
|
+
content: [{ type: "text", text: EDITOR_WORKFLOW_GUIDE }],
|
|
4262
|
+
};
|
|
4263
|
+
});
|
|
4264
|
+
// Tool: list_theme_globals
|
|
4265
|
+
server.tool("list_theme_globals", "List the theme's global settings from the connected editor: global variables (Theme Settings) and design tokens (colors, typography, breakpoints, keyframes, color schemes). Call this BEFORE generating sections/components so you reuse the theme's existing variables and tokens (read them in component code via `getThemeSetting`/`getThemeColors`/... from `@ikas/bp-storefront`). Includes items created manually in the editor UI. Requires `ikas-component dev` running with the editor connected. Two shape gotchas when consuming the result at runtime: (1) color schemes — `colorSchemes.schemes` holds only `{id,name}` slot LABELS; the actual colors live in `colorSchemes.values[].colorsByScheme` keyed by slot id, so iterate `values[].colorsByScheme` (iterating `schemes` renders empty). (2) An IMAGE setting's `value` is an image REFERENCE like `{id:'theme-images/<uuid>'}` with no `.url` — resolve it via `getDefaultSrc`/`getSrc`. (3) Each keyframe now includes its animation `settings` (type-dependent { property, value } entries — duration/iteration/timing/etc. for keyframe, transition for transition) and each point's resolved `styles`, so you can read back the full animation config, not just the `ref`. (4) Each typography entry may include `supportedFontWeights` — the exact numeric weights that text style's font actually ships (e.g. `[400]` for Modak); when present, only set `font_weight` to a value in this list (via `update_text_style`/`create_theme_global`), otherwise the write is rejected. If the field is absent the font's weight set couldn't be determined — fall back to 400 or rely on the validation error. Each typography entry also carries `isDefault` (true for the theme's default/global text style — the editor's \"Make Default Style\"); toggle it via `update_text_style`'s `is_default`. (5) Token NAMES are NOT unique — a theme can contain two tokens with the SAME name (e.g. colors pulled from two different design assets), so NEVER match a token by its human name. ALWAYS identify a token by its `id` (globally unique). IN COMPONENT CODE: prefer embedding the token's id-derived STABLE ref directly — color → cssVar `var(--<id>)`, typography → `className` `_<id>`, keyframe (animation-name) → `ref` `_<id>` — so you don't look anything up at runtime. If you DO need to pick a token out of a `getThemeColors()` / `getThemeTypography()` / `getThemeKeyframes()` / `getThemeColorSchemes()` array, match on `.id` (e.g. `getThemeColors().find(c => c.id === \"<id>\")`), NEVER on `.name`. EXCEPTION — global variables/settings: `getThemeSetting(name)` takes the token's `name`, but here `name` is the unique runtime key (`variableName`, the `_<id>` form returned in this list), which IS safe; do NOT pass a setting's human `displayName`. The update/delete tools also identify a token ONLY by `id` (they do NOT look up by name — on those tools `name` means the NEW name when renaming). Always take the `id` (or, for settings, the `name`/variableName) from THIS list. (6) GROUPING convention: a \"/\" in a token's NAME organizes it into a group in the editor UI — the text before the first \"/\" is the group, the rest is the item label. This applies to COLORS (e.g. \"Brand/Primary\"), TEXT STYLES (e.g. \"Heading/H1\"), and COLOR-SCHEME SLOTS (e.g. \"PrimaryButton/Background\"). When you create globals (via `create_theme_global`/`update_theme_color_scheme`), use \"/\"-prefixed names to keep related tokens grouped and tidy; reuse an existing group's exact prefix so they nest together.", {
|
|
4266
|
+
project_root: z
|
|
4267
|
+
.string()
|
|
4268
|
+
.describe("Absolute path to the code-component project (where `node_modules/.bin/ikas-component` lives)."),
|
|
4269
|
+
port: z
|
|
4270
|
+
.number()
|
|
4271
|
+
.optional()
|
|
4272
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4273
|
+
}, async ({ project_root, port }) => {
|
|
4274
|
+
const args = [
|
|
4275
|
+
"list-theme-globals",
|
|
4276
|
+
...(port ? ["--port", String(port)] : []),
|
|
4277
|
+
];
|
|
4278
|
+
return callEditorAction(project_root, args);
|
|
4279
|
+
});
|
|
4280
|
+
// Shared text-style (typography) font-property schema — kept in lock-step with the editor's
|
|
4281
|
+
// "Update Text Style" modal fields (no color/text-align, since that modal doesn't expose them).
|
|
4282
|
+
// Each enum prop documents its accepted values so a bad value is caught with a clear error. Spread
|
|
4283
|
+
// into both create_theme_global (typography) and update_text_style so the two never drift apart.
|
|
4284
|
+
const textStyleFontParams = {
|
|
4285
|
+
font_family: z
|
|
4286
|
+
.string()
|
|
4287
|
+
.optional()
|
|
4288
|
+
.describe('A real font family the editor offers — a Google Fonts name with EXACT casing (e.g. "Inter", "Roboto", ' +
|
|
4289
|
+
'"Poppins"), or a font already used by an existing text style in list_theme_globals. An unknown font ' +
|
|
4290
|
+
"(or wrong casing) is rejected; do NOT invent a family name."),
|
|
4291
|
+
font_size: z.string().optional(),
|
|
4292
|
+
font_weight: z
|
|
4293
|
+
.string()
|
|
4294
|
+
.optional()
|
|
4295
|
+
.describe('font-weight as a number (e.g. "600"); append \'i\' for italic (e.g. "600i"). A PLAIN number with no \'i\' ' +
|
|
4296
|
+
'is upright and REMOVES italic if the text style was italic (italic is carried by the weight — re-send the ' +
|
|
4297
|
+
'weight without \'i\' to turn it off). Must be a weight the chosen ' +
|
|
4298
|
+
'font ships — if it isn\'t, the error lists the supported weights; when unsure use "400".'),
|
|
4299
|
+
line_height: z.string().optional(),
|
|
4300
|
+
letter_spacing: z.string().optional(),
|
|
4301
|
+
text_decoration: z
|
|
4302
|
+
.string()
|
|
4303
|
+
.optional()
|
|
4304
|
+
.describe("text-decoration: none | underline | line-through"),
|
|
4305
|
+
text_transform: z
|
|
4306
|
+
.string()
|
|
4307
|
+
.optional()
|
|
4308
|
+
.describe("text-transform: none | uppercase | lowercase | capitalize"),
|
|
4309
|
+
text_overflow: z
|
|
4310
|
+
.string()
|
|
4311
|
+
.optional()
|
|
4312
|
+
.describe("text-overflow: clip | ellipsis"),
|
|
4313
|
+
white_space: z
|
|
4314
|
+
.string()
|
|
4315
|
+
.optional()
|
|
4316
|
+
.describe("white-space: normal | pre | pre-wrap | pre-line | wrap | nowrap | collapse"),
|
|
4317
|
+
line_break: z
|
|
4318
|
+
.string()
|
|
4319
|
+
.optional()
|
|
4320
|
+
.describe("line-break: auto | loose | normal | strict | anywhere"),
|
|
4321
|
+
word_break: z
|
|
4322
|
+
.string()
|
|
4323
|
+
.optional()
|
|
4324
|
+
.describe("word-break: normal | break-all | keep-all"),
|
|
4325
|
+
text_wrap_style: z
|
|
4326
|
+
.string()
|
|
4327
|
+
.optional()
|
|
4328
|
+
.describe("text-wrap-style: auto | balance | pretty | stable"),
|
|
4329
|
+
};
|
|
4330
|
+
// Turn the supplied text-style font params into `ikas-component` CLI flags (omitted ones dropped).
|
|
4331
|
+
// The editor validates each value and rejects an unsupported one with the offending value + allowed set.
|
|
4332
|
+
function textStyleFontArgs(input) {
|
|
4333
|
+
const map = {
|
|
4334
|
+
"--font-family": input.font_family,
|
|
4335
|
+
"--font-size": input.font_size,
|
|
4336
|
+
"--font-weight": input.font_weight,
|
|
4337
|
+
"--line-height": input.line_height,
|
|
4338
|
+
"--letter-spacing": input.letter_spacing,
|
|
4339
|
+
"--text-decoration": input.text_decoration,
|
|
4340
|
+
"--text-transform": input.text_transform,
|
|
4341
|
+
"--text-overflow": input.text_overflow,
|
|
4342
|
+
"--white-space": input.white_space,
|
|
4343
|
+
"--line-break": input.line_break,
|
|
4344
|
+
"--word-break": input.word_break,
|
|
4345
|
+
"--text-wrap-style": input.text_wrap_style,
|
|
4346
|
+
};
|
|
4347
|
+
return Object.entries(map).flatMap(([flag, value]) => value ? [flag, value] : []);
|
|
4348
|
+
}
|
|
4349
|
+
// Tool: create_theme_global
|
|
4350
|
+
server.tool("create_theme_global", "Create a theme global setting in the connected editor. `kind` selects what to create:\n" +
|
|
4351
|
+
'- globalVariable: requires display_name + type (TEXT|RICH_TEXT|IMAGE|COLOR|NUMBER|BOOLEAN|BORDER|SHADOW); value optional. Pass `value` as a REAL JSON value, never a stringified JSON. Value shapes — TEXT/COLOR: string; RICH_TEXT: HTML string; NUMBER: number; BOOLEAN: real JSON boolean true/false (NOT the string "true"); IMAGE: an image REFERENCE object { id: "theme-images/<uuid>" } (NOT { url }) — the id MUST come from a REAL upload: call `upload_image` (file_path or image_url) and use the id it returns, or reuse an id already listed by `list_theme_globals`. NEVER invent an id — it is stored as given and renders as a broken image, so if you have no image, omit `value` and let the merchant set it from the "Theme Settings" panel; BORDER: { width: { value, unit }, style, color } (width.value must be a number); SHADOW: { x, y, blur, spread, color, position: "outside"|"inside" }. For object types (IMAGE/BORDER/SHADOW) pass an actual JSON object, not a JSON-encoded string. Every value is validated server-side and a wrong shape is REJECTED, not silently stored.\n' +
|
|
4352
|
+
'- color: requires name + value — a CONCRETE color (hex e.g. "#ff0000", rgb()/hsl() or a CSS color name). A color token cannot alias another color, so a "var(...)" reference is REJECTED here (to reuse another theme color, reference its cssVar in component code, or in a colorScheme slot). TIP: a "/" in the `name` GROUPS the color in the editor UI (e.g. "Brand/Primary", "Brand/Accent" appear under a "Brand" group); use this to organize related colors. To CHANGE an existing color later, use `update_theme_color` (edits in place, keeps the cssVar stable) — do NOT delete+recreate.\n' +
|
|
4353
|
+
'- typography: requires name + at least one text-style property. These are exactly the fields the editor\'s "Update Text Style" modal exposes — nothing else (in particular there is NO color or text-align on a text style). VALUE FORMATS (all validated; a bad value is rejected with the offending value and the allowed set): font_weight is one of 100,200,300,400,500,600,700,800,900 (append \'i\' for italic, e.g. "600i") AND must be a weight the chosen font actually ships (many fonts provide only a subset, e.g. "Modak" only ships 400) — if unavailable the call fails and lists the supported weights, so when unsure use 400; stored as a numeric weight + a font-style entry; font_size is a number WITH a unit (e.g. "16px", "1.2rem", "80%"); line_height is "normal", a unitless number (e.g. "1.5") or a length; letter_spacing is "normal" or a length (e.g. "0.02em", "0.5px"); font_family is a real font the editor offers (a Google Fonts name with EXACT casing, e.g. "Inter") — an unknown/invented family is rejected; text_decoration is none|underline|line-through; text_transform is none|uppercase|lowercase|capitalize; text_overflow is clip|ellipsis; white_space is normal|pre|pre-wrap|pre-line|wrap|nowrap|collapse; line_break is auto|loose|normal|strict|anywhere; word_break is normal|break-all|keep-all; text_wrap_style is auto|balance|pretty|stable. TIP: a "/" in the `name` GROUPS the text style in the editor UI (e.g. "Heading/H1", "Heading/H2" appear under a "Heading" group); use this to organize related styles. To CHANGE an existing text style later, use `update_text_style` (edits in place, keeps the `className` stable) — do NOT delete+recreate, which changes the id/className.\n' +
|
|
4354
|
+
"- breakpoint: requires name + width (a positive INTEGER, in px — no decimals). To CHANGE an existing breakpoint later, use `update_theme_breakpoint` (edits in place, keeps the id).\n" +
|
|
4355
|
+
"- keyframe: requires name + points (array of { point, styles? }) where each style is { property, value } using a CSS property name (opacity, transform, filter, background, color, …); keyframe_type defaults to \"keyframe\". Optional `settings` = animation-level config as { property, value } entries, TYPE-DEPENDENT: for keyframe — animation-duration, animation-iteration-count, animation-play-state, animation-delay, animation-timing-function, animation-direction, animation-fill-mode, animation-timeline, animation-range, transform-origin, backface-visibility; for transition — transition, backface-visibility. Setting these means the editor drives the animation timing (you don't have to hand-write `animation:` CSS). Use the keyframe's `ref` as the CSS animation-name. For a TRANSITION keyframe, put the target/hover-state styles on the 100% point (points[1].styles) — the 0% point is ignored (the start state is the element's own normal state). To CHANGE an existing keyframe later, use `update_theme_keyframe` (edits in place, keeps the `ref` stable) — do NOT delete+recreate, which changes the ref and breaks references.\n" +
|
|
4356
|
+
'- colorScheme: requires name + colors (array of { slotId? | newSlotName?, value }) — each color targets ONE color SLOT, EITHER by `slotId` (an EXISTING slot\'s id, from `list_theme_globals` → colorSchemes.schemes[].id or a `colorsByScheme` key — the id-keyed path) OR by `newSlotName` (a name to CREATE-or-reuse a slot; write-only, for the standard vocabulary and brand-new slots). Pass EXACTLY ONE of the two per entry. `value` is EITHER a literal color (hex/rgb/hsl or a CSS color name, e.g. "#0b1120") OR a REFERENCE to an existing theme color, passed as that color\'s cssVar from `list_theme_globals` (e.g. "var(--<colorId>)"). A `var(--id)` value is stored as a linked reference (editing the global color updates the scheme too and the dependency is tracked) — do NOT inline a hex you copied from a global color; pass its cssVar. SLOT IDENTITY: `colorSchemes.schemes` lists each slot as `{id, name}`. To set a color on an EXISTING slot, find it there by name and pass its `slotId` (names are NOT unique — two design assets can each have a "Background" — so when ambiguous disambiguate via the scheme\'s existing `colorsByScheme` keys); use `newSlotName` only to add a slot the scheme does not have yet. When creating slots use the theme\'s STANDARD slot names so components resolve them: "Background", "Heading", "Text", "Link", "HoverLink", "Border", and per button "PrimaryButton/Background", "PrimaryButton/Text", "PrimaryButton/Border", "PrimaryButton/HoverBackground", "PrimaryButton/HoverText", "PrimaryButton/HoverBorder" (and the same six under "SecondaryButton/"); a "/" groups the slot in the editor UI. A scheme should normally define EVERY slot it uses; omitted slots fall back to the default scheme\'s color. A mistaken slot can be removed with `delete_theme_global` kind `colorSchemeSlot` (by slot id), or renamed in place (id stays stable) with `rename_theme_color_scheme_slot`. To CHANGE an existing scheme later, use `update_theme_color_scheme` (edits in place, keeps the className stable; merges colors by slot, and can set/clear its default flag via `is_default`).\n' +
|
|
4357
|
+
"Read created items back with `list_theme_globals`. Requires `ikas-component dev` running with the editor connected.", {
|
|
4358
|
+
project_root: z
|
|
4359
|
+
.string()
|
|
4360
|
+
.describe("Absolute path to the code-component project."),
|
|
4361
|
+
kind: z
|
|
4362
|
+
.enum([
|
|
4363
|
+
"globalVariable",
|
|
4364
|
+
"color",
|
|
4365
|
+
"typography",
|
|
4366
|
+
"breakpoint",
|
|
4367
|
+
"keyframe",
|
|
4368
|
+
"colorScheme",
|
|
4369
|
+
])
|
|
4370
|
+
.describe("What to create."),
|
|
4371
|
+
name: z.string().optional().describe("Name (design tokens)."),
|
|
4372
|
+
display_name: z
|
|
4373
|
+
.string()
|
|
4374
|
+
.optional()
|
|
4375
|
+
.describe("Human label (globalVariable)."),
|
|
4376
|
+
type: z.string().optional().describe("globalVariable value type."),
|
|
4377
|
+
value: z
|
|
4378
|
+
.any()
|
|
4379
|
+
.optional()
|
|
4380
|
+
.describe("globalVariable default value (shape depends on type — see tool description), or color hex string."),
|
|
4381
|
+
...textStyleFontParams,
|
|
4382
|
+
width: z
|
|
4383
|
+
.number()
|
|
4384
|
+
.int()
|
|
4385
|
+
.optional()
|
|
4386
|
+
.describe("breakpoint width in px (positive integer, no decimals)."),
|
|
4387
|
+
keyframe_type: z.enum(["keyframe", "transition"]).optional(),
|
|
4388
|
+
points: z.any().optional().describe("keyframe points array."),
|
|
4389
|
+
settings: z
|
|
4390
|
+
.any()
|
|
4391
|
+
.optional()
|
|
4392
|
+
.describe("keyframe animation settings: array of { property, value } (type-dependent — see tool description)."),
|
|
4393
|
+
colors: z
|
|
4394
|
+
.any()
|
|
4395
|
+
.optional()
|
|
4396
|
+
.describe('colorScheme colors: array of { slotId? | newSlotName?, value } — target an EXISTING slot by `slotId` (its id from list_theme_globals → colorSchemes.schemes / colorsByScheme keys) OR create/reuse one by `newSlotName` (use the standard slot names, "/" to group, e.g. "PrimaryButton/Background"). Exactly one per entry. value = a literal color hex/rgb/hsl/name, OR an existing theme color\'s cssVar "var(--<colorId>)" to store a linked reference.'),
|
|
4397
|
+
port: z
|
|
4398
|
+
.number()
|
|
4399
|
+
.optional()
|
|
4400
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4401
|
+
}, async (input) => {
|
|
4402
|
+
const p = input.port ? ["--port", String(input.port)] : [];
|
|
4403
|
+
let args;
|
|
4404
|
+
switch (input.kind) {
|
|
4405
|
+
case "globalVariable":
|
|
4406
|
+
args = [
|
|
4407
|
+
"create-global-variable",
|
|
4408
|
+
"--display-name",
|
|
4409
|
+
String(input.display_name ?? ""),
|
|
4410
|
+
"--type",
|
|
4411
|
+
String(input.type ?? ""),
|
|
4412
|
+
...(input.value !== undefined
|
|
4413
|
+
? ["--value", JSON.stringify(input.value)]
|
|
4414
|
+
: []),
|
|
4415
|
+
...p,
|
|
4416
|
+
];
|
|
4417
|
+
break;
|
|
4418
|
+
case "color":
|
|
4419
|
+
args = [
|
|
4420
|
+
"create-color",
|
|
4421
|
+
"--name",
|
|
4422
|
+
String(input.name ?? ""),
|
|
4423
|
+
"--value",
|
|
4424
|
+
String(input.value ?? ""),
|
|
4425
|
+
...p,
|
|
4426
|
+
];
|
|
4427
|
+
break;
|
|
4428
|
+
case "typography":
|
|
4429
|
+
args = [
|
|
4430
|
+
"create-text-style",
|
|
4431
|
+
"--name",
|
|
4432
|
+
String(input.name ?? ""),
|
|
4433
|
+
...textStyleFontArgs(input),
|
|
4434
|
+
...p,
|
|
4435
|
+
];
|
|
4436
|
+
break;
|
|
4437
|
+
case "breakpoint":
|
|
4438
|
+
args = [
|
|
4439
|
+
"create-breakpoint",
|
|
4440
|
+
"--name",
|
|
4441
|
+
String(input.name ?? ""),
|
|
4442
|
+
"--width",
|
|
4443
|
+
String(input.width ?? ""),
|
|
4444
|
+
...p,
|
|
4445
|
+
];
|
|
4446
|
+
break;
|
|
4447
|
+
case "keyframe":
|
|
4448
|
+
args = [
|
|
4449
|
+
"create-keyframe",
|
|
4450
|
+
"--name",
|
|
4451
|
+
String(input.name ?? ""),
|
|
4452
|
+
...(input.keyframe_type ? ["--type", input.keyframe_type] : []),
|
|
4453
|
+
"--points",
|
|
4454
|
+
toJsonArrayArg(input.points),
|
|
4455
|
+
...(input.settings !== undefined
|
|
4456
|
+
? ["--settings", toJsonArrayArg(input.settings)]
|
|
4457
|
+
: []),
|
|
4458
|
+
...p,
|
|
4459
|
+
];
|
|
4460
|
+
break;
|
|
4461
|
+
case "colorScheme":
|
|
4462
|
+
args = [
|
|
4463
|
+
"create-color-scheme",
|
|
4464
|
+
"--name",
|
|
4465
|
+
String(input.name ?? ""),
|
|
4466
|
+
"--colors",
|
|
4467
|
+
toJsonArrayArg(input.colors),
|
|
4468
|
+
...p,
|
|
4469
|
+
];
|
|
4470
|
+
break;
|
|
4471
|
+
default:
|
|
4472
|
+
return {
|
|
4473
|
+
content: [
|
|
4474
|
+
{
|
|
4475
|
+
type: "text",
|
|
4476
|
+
text: `Error: unknown kind "${input.kind}"`,
|
|
4477
|
+
},
|
|
4478
|
+
],
|
|
4479
|
+
};
|
|
4480
|
+
}
|
|
4481
|
+
return callEditorAction(input.project_root, args);
|
|
4482
|
+
});
|
|
4483
|
+
// Tool: update_theme_global
|
|
4484
|
+
server.tool("update_theme_global", 'Update an existing global variable in the connected editor (e.g. fix its value or change its type). Identify it by `name` (the runtime key from `list_theme_globals`). Only the fields you pass are changed. Value shapes follow `create_theme_global` — pass `value` as REAL JSON (objects/booleans, never stringified); BOOLEAN is a real boolean, BORDER/SHADOW are real objects; IMAGE is an image REFERENCE object { id: "theme-images/<uuid>" } whose id MUST come from `upload_image` or an existing `list_theme_globals` entry — an invented id renders as a broken image. Values are validated server-side; a wrong shape is REJECTED, not silently stored.', {
|
|
4485
|
+
project_root: z
|
|
4486
|
+
.string()
|
|
4487
|
+
.describe("Absolute path to the code-component project."),
|
|
4488
|
+
name: z
|
|
4489
|
+
.string()
|
|
4490
|
+
.describe("The variable's runtime key (from `list_theme_globals`)."),
|
|
4491
|
+
display_name: z.string().optional().describe("New label."),
|
|
4492
|
+
type: z
|
|
4493
|
+
.string()
|
|
4494
|
+
.optional()
|
|
4495
|
+
.describe("New value type (TEXT|RICH_TEXT|IMAGE|COLOR|NUMBER|BOOLEAN|BORDER|SHADOW)."),
|
|
4496
|
+
value: z
|
|
4497
|
+
.any()
|
|
4498
|
+
.optional()
|
|
4499
|
+
.describe('New value as REAL JSON (shape depends on type; e.g. BOOLEAN: true/false, NUMBER: 12, IMAGE: { id: "theme-images/<uuid>" } from upload_image — see create_theme_global). An invented IMAGE id renders as a broken image.'),
|
|
4500
|
+
port: z
|
|
4501
|
+
.number()
|
|
4502
|
+
.optional()
|
|
4503
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4504
|
+
}, async ({ project_root, name, display_name, type, value, port }) => {
|
|
4505
|
+
const args = [
|
|
4506
|
+
"update-global-variable",
|
|
4507
|
+
"--name",
|
|
4508
|
+
name,
|
|
4509
|
+
...(display_name !== undefined ? ["--display-name", display_name] : []),
|
|
4510
|
+
...(type !== undefined ? ["--type", type] : []),
|
|
4511
|
+
...(value !== undefined ? ["--value", JSON.stringify(value)] : []),
|
|
4512
|
+
...(port ? ["--port", String(port)] : []),
|
|
4513
|
+
];
|
|
4514
|
+
return callEditorAction(project_root, args);
|
|
4515
|
+
});
|
|
4516
|
+
// Tool: update_theme_keyframe
|
|
4517
|
+
server.tool("update_theme_keyframe", "Update an existing theme keyframe IN PLACE in the connected editor. Prefer this over delete+recreate: " +
|
|
4518
|
+
"it keeps the keyframe's id, so its runtime `ref` (the CSS animation-name `_<id>`) stays STABLE and every " +
|
|
4519
|
+
"existing reference to it keeps working. Identify the keyframe by `id` (REQUIRED — globally unique, from " +
|
|
4520
|
+
"`list_theme_globals`); name-based lookup is intentionally NOT supported here because names can collide across " +
|
|
4521
|
+
"design assets. To rename, pass `name` (the new name) together with `id`. " +
|
|
4522
|
+
"`points` REPLACES the keyframe's points: an array of { point, styles? } where `point` is a CSS " +
|
|
4523
|
+
'keyframe offset (e.g. "0%", "50%", "100%") and each style is { property, value } using a CSS property ' +
|
|
4524
|
+
"name (opacity, transform, filter, background, color, …). Pass `points` as REAL JSON (not a stringified array). " +
|
|
4525
|
+
"For a TRANSITION keyframe, put the target/hover-state styles on the 100% point (points[1].styles) — the 0% " +
|
|
4526
|
+
"point is ignored (the start state is the element's own normal state). " +
|
|
4527
|
+
"Optional `settings` REPLACES the keyframe's animation settings (type-dependent { property, value } entries — " +
|
|
4528
|
+
"see `create_theme_global`); OMIT it to keep the existing settings, or pass [] to clear them. " +
|
|
4529
|
+
"Requires `ikas-component dev` running with the editor connected.", {
|
|
4530
|
+
project_root: z
|
|
4531
|
+
.string()
|
|
4532
|
+
.describe("Absolute path to the code-component project."),
|
|
4533
|
+
id: z
|
|
4534
|
+
.string()
|
|
4535
|
+
.describe("Keyframe id (REQUIRED) from `list_theme_globals`. The token is always identified by id."),
|
|
4536
|
+
name: z
|
|
4537
|
+
.string()
|
|
4538
|
+
.optional()
|
|
4539
|
+
.describe("Optional NEW name to rename the keyframe to. NOT used to find the token — lookup is always by id."),
|
|
4540
|
+
keyframe_type: z
|
|
4541
|
+
.enum(["keyframe", "transition"])
|
|
4542
|
+
.optional()
|
|
4543
|
+
.describe("Optional new keyframe type."),
|
|
4544
|
+
points: z
|
|
4545
|
+
.any()
|
|
4546
|
+
.describe("New keyframe points array of { point, styles? } — REPLACES the existing points."),
|
|
4547
|
+
settings: z
|
|
4548
|
+
.any()
|
|
4549
|
+
.optional()
|
|
4550
|
+
.describe("New animation settings { property, value } array (type-dependent — see create_theme_global). Omit to keep existing; [] to clear."),
|
|
4551
|
+
port: z
|
|
4552
|
+
.number()
|
|
4553
|
+
.optional()
|
|
4554
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4555
|
+
}, async ({ project_root, id, name, keyframe_type, points, settings, port }) => {
|
|
4556
|
+
const args = [
|
|
4557
|
+
"update-keyframe",
|
|
4558
|
+
"--id",
|
|
4559
|
+
id,
|
|
4560
|
+
...(name !== undefined ? ["--name", name] : []),
|
|
4561
|
+
...(keyframe_type ? ["--type", keyframe_type] : []),
|
|
4562
|
+
"--points",
|
|
4563
|
+
toJsonArrayArg(points),
|
|
4564
|
+
...(settings !== undefined
|
|
4565
|
+
? ["--settings", toJsonArrayArg(settings)]
|
|
4566
|
+
: []),
|
|
4567
|
+
...(port ? ["--port", String(port)] : []),
|
|
4568
|
+
];
|
|
4569
|
+
return callEditorAction(project_root, args);
|
|
4570
|
+
});
|
|
4571
|
+
// Tool: update_text_style
|
|
4572
|
+
server.tool("update_text_style", "Update an existing theme typography token (text style) IN PLACE in the connected editor. Prefer this over " +
|
|
4573
|
+
"delete+recreate: it keeps the text style's id, so its `className` (`_<id>`) — and every section bound to it — " +
|
|
4574
|
+
"stays STABLE. Identify the text style by `id` (REQUIRED — globally unique, from `list_theme_globals`); " +
|
|
4575
|
+
"name-based lookup is intentionally NOT supported here because names can collide across design assets. " +
|
|
4576
|
+
"To rename, pass `name` (the new name) together with `id`. Pass only the properties you want to change; omitted " +
|
|
4577
|
+
'ones keep their existing values. The settable properties are exactly the editor\'s "Update Text Style" modal ' +
|
|
4578
|
+
"fields — there is NO color or text-align on a text style. VALUE FORMATS (all validated; a bad value is rejected " +
|
|
4579
|
+
"with the offending value and the allowed set): font_weight is one of 100…900 (append 'i' for italic, e.g. " +
|
|
4580
|
+
'"600i") AND must be a weight the chosen font actually ships — many fonts only provide a subset (e.g. "Modak" ' +
|
|
4581
|
+
"only ships 400); if a weight isn't available the call fails and the error lists the supported weights, so when " +
|
|
4582
|
+
'unsure use 400; font_size is a number with a unit (e.g. "16px"); line_height is "normal", a unitless number ' +
|
|
4583
|
+
'or a length; letter_spacing is "normal" or a length (e.g. "0.02em"); font_family is a real font the editor ' +
|
|
4584
|
+
'offers (a Google Fonts name with EXACT casing, e.g. "Inter") — an unknown/invented family is rejected; ' +
|
|
4585
|
+
"text_decoration is none|underline|" +
|
|
4586
|
+
"line-through; text_transform is none|uppercase|lowercase|capitalize; text_overflow is clip|ellipsis; white_space " +
|
|
4587
|
+
"is normal|pre|pre-wrap|pre-line|wrap|nowrap|collapse; line_break is auto|loose|normal|strict|anywhere; word_break " +
|
|
4588
|
+
"is normal|break-all|keep-all; text_wrap_style is auto|balance|pretty|stable. Set `is_default: true` to make " +
|
|
4589
|
+
"this text style the theme's default/global style (the editor's right-click \"Make Default Style\" / \"Global " +
|
|
4590
|
+
"Stil Yap\") — any other default in the group is cleared; `is_default: false` removes the flag. A text style's " +
|
|
4591
|
+
"current default state is readable from `list_theme_globals` (each typography entry's `isDefault`). Requires " +
|
|
4592
|
+
"`ikas-component dev` running with the editor connected.", {
|
|
4593
|
+
project_root: z
|
|
4594
|
+
.string()
|
|
4595
|
+
.describe("Absolute path to the code-component project."),
|
|
4596
|
+
id: z
|
|
4597
|
+
.string()
|
|
4598
|
+
.describe("Text style id (REQUIRED) from `list_theme_globals`. The token is always identified by id."),
|
|
4599
|
+
name: z
|
|
4600
|
+
.string()
|
|
4601
|
+
.optional()
|
|
4602
|
+
.describe("Optional NEW name to rename the text style to. NOT used to find the token — lookup is always by id."),
|
|
4603
|
+
...textStyleFontParams,
|
|
4604
|
+
is_default: z
|
|
4605
|
+
.boolean()
|
|
4606
|
+
.optional()
|
|
4607
|
+
.describe("true → make this the theme's default/global text style (clears any other default); false → remove the " +
|
|
4608
|
+
"default flag. Omit to leave the default state unchanged."),
|
|
4609
|
+
port: z
|
|
4610
|
+
.number()
|
|
4611
|
+
.optional()
|
|
4612
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4613
|
+
}, async (input) => {
|
|
4614
|
+
const { project_root, id, name, is_default, port } = input;
|
|
4615
|
+
const args = [
|
|
4616
|
+
"update-text-style",
|
|
4617
|
+
"--id",
|
|
4618
|
+
id,
|
|
4619
|
+
...(name !== undefined ? ["--name", name] : []),
|
|
4620
|
+
...textStyleFontArgs(input),
|
|
4621
|
+
...(is_default === true ? ["--default"] : is_default === false ? ["--no-default"] : []),
|
|
4622
|
+
...(port ? ["--port", String(port)] : []),
|
|
4623
|
+
];
|
|
4624
|
+
return callEditorAction(project_root, args);
|
|
4625
|
+
});
|
|
4626
|
+
// Tool: update_theme_color
|
|
4627
|
+
server.tool("update_theme_color", "Update an existing theme color token IN PLACE in the connected editor. Prefer this over delete+recreate: " +
|
|
4628
|
+
"it keeps the color's id, so its cssVar (`var(--<id>)`) — and every element style bound to it — stays STABLE. " +
|
|
4629
|
+
"Identify it by `id` (REQUIRED — globally unique, from `list_theme_globals`); name-based lookup is intentionally " +
|
|
4630
|
+
"NOT supported here because a theme can have two colors with the same name (e.g. from two different design assets). " +
|
|
4631
|
+
"To rename, pass `name` (the new name) together with `id`. Pass `value` to change the color — a CONCRETE " +
|
|
4632
|
+
'color (hex/rgb/hsl or a CSS color name), NOT a "var(...)" reference (a color token can\'t alias another ' +
|
|
4633
|
+
"color); omit it to only rename. Requires `ikas-component " +
|
|
4634
|
+
"dev` running with the editor connected.", {
|
|
4635
|
+
project_root: z
|
|
4636
|
+
.string()
|
|
4637
|
+
.describe("Absolute path to the code-component project."),
|
|
4638
|
+
id: z
|
|
4639
|
+
.string()
|
|
4640
|
+
.describe("Color id (REQUIRED) from `list_theme_globals`. The token is always identified by id."),
|
|
4641
|
+
name: z
|
|
4642
|
+
.string()
|
|
4643
|
+
.optional()
|
|
4644
|
+
.describe("Optional NEW name to rename the color to. NOT used to find the token — lookup is always by id."),
|
|
4645
|
+
value: z
|
|
4646
|
+
.string()
|
|
4647
|
+
.optional()
|
|
4648
|
+
.describe('New color value — a concrete color (e.g. "#ff0000", rgb/hsl/name), not a "var(...)" reference. Omit to only rename.'),
|
|
4649
|
+
port: z
|
|
4650
|
+
.number()
|
|
4651
|
+
.optional()
|
|
4652
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4653
|
+
}, async ({ project_root, id, name, value, port }) => {
|
|
4654
|
+
const args = [
|
|
4655
|
+
"update-color",
|
|
4656
|
+
"--id",
|
|
4657
|
+
id,
|
|
4658
|
+
...(name !== undefined ? ["--name", name] : []),
|
|
4659
|
+
...(value !== undefined ? ["--value", value] : []),
|
|
4660
|
+
...(port ? ["--port", String(port)] : []),
|
|
4661
|
+
];
|
|
4662
|
+
return callEditorAction(project_root, args);
|
|
4663
|
+
});
|
|
4664
|
+
// Tool: update_theme_breakpoint
|
|
4665
|
+
server.tool("update_theme_breakpoint", "Update an existing theme breakpoint IN PLACE in the connected editor (keeps its id). Identify it by `id` " +
|
|
4666
|
+
"(REQUIRED — globally unique, from `list_theme_globals`); name-based lookup is intentionally NOT supported here " +
|
|
4667
|
+
"because names can collide across design assets. To rename, pass `name` (the new name) together with `id`. " +
|
|
4668
|
+
"Pass `width` (px) to change it; omit it to only rename. " +
|
|
4669
|
+
"Requires `ikas-component dev` running with the editor connected.", {
|
|
4670
|
+
project_root: z
|
|
4671
|
+
.string()
|
|
4672
|
+
.describe("Absolute path to the code-component project."),
|
|
4673
|
+
id: z
|
|
4674
|
+
.string()
|
|
4675
|
+
.describe("Breakpoint id (REQUIRED) from `list_theme_globals`. The token is always identified by id."),
|
|
4676
|
+
name: z
|
|
4677
|
+
.string()
|
|
4678
|
+
.optional()
|
|
4679
|
+
.describe("Optional NEW name to rename the breakpoint to. NOT used to find the token — lookup is always by id."),
|
|
4680
|
+
width: z
|
|
4681
|
+
.number()
|
|
4682
|
+
.int()
|
|
4683
|
+
.optional()
|
|
4684
|
+
.describe("New breakpoint width in px (positive integer, no decimals). Omit to only rename."),
|
|
4685
|
+
port: z
|
|
4686
|
+
.number()
|
|
4687
|
+
.optional()
|
|
4688
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4689
|
+
}, async ({ project_root, id, name, width, port }) => {
|
|
4690
|
+
const args = [
|
|
4691
|
+
"update-breakpoint",
|
|
4692
|
+
"--id",
|
|
4693
|
+
id,
|
|
4694
|
+
...(name !== undefined ? ["--name", name] : []),
|
|
4695
|
+
...(width !== undefined ? ["--width", String(width)] : []),
|
|
4696
|
+
...(port ? ["--port", String(port)] : []),
|
|
4697
|
+
];
|
|
4698
|
+
return callEditorAction(project_root, args);
|
|
4699
|
+
});
|
|
4700
|
+
// Tool: update_theme_color_scheme
|
|
4701
|
+
server.tool("update_theme_color_scheme", "Update an existing theme color scheme (palette) IN PLACE in the connected editor. Prefer this over " +
|
|
4702
|
+
"delete+recreate: it keeps the scheme's id, so its className (`_<id>`) stays STABLE. Identify it by `id` " +
|
|
4703
|
+
"(REQUIRED — globally unique, from `list_theme_globals`); name-based lookup is intentionally NOT supported here " +
|
|
4704
|
+
"because names can collide across design assets. To rename, pass `name` (the new name) together with `id`. " +
|
|
4705
|
+
"`colors` is an array of { slotId? | newSlotName?, value } — each entry targets ONE slot, EITHER by " +
|
|
4706
|
+
"`slotId` (an EXISTING slot's id, from list_theme_globals colorsByScheme keys / colorSchemes.schemes — the " +
|
|
4707
|
+
"id-keyed path; slot names ARE listed in colorSchemes.schemes but are not unique, so prefer the scheme's colorsByScheme keys to get the right id) OR by `newSlotName` (create/reuse " +
|
|
4708
|
+
'a slot by name; use the standard slot names, "/" to group, e.g. "PrimaryButton/Background"); value = a ' +
|
|
4709
|
+
'literal color hex/rgb/hsl/name, OR an existing theme color\'s cssVar "var(--<colorId>)" from ' +
|
|
4710
|
+
"list_theme_globals to store it as a LINKED reference — pass the cssVar, not a hex copied from a global color) " +
|
|
4711
|
+
"and MERGES by slot — only the slots you pass change. Pass `colors` as REAL " +
|
|
4712
|
+
"JSON (not a stringified array). Set `is_default: true` to make this the theme's DEFAULT scheme (the " +
|
|
4713
|
+
"fallback whose colors fill any slot a non-default scheme leaves unset); this is exclusive — the editor " +
|
|
4714
|
+
"automatically clears the default flag from any other scheme in the same group, so there is always exactly " +
|
|
4715
|
+
"one default. Set `is_default: false` to remove the default flag from this scheme. Omit all of name/colors/" +
|
|
4716
|
+
"is_default to no-op. Requires `ikas-component dev` running with the editor connected.", {
|
|
4717
|
+
project_root: z
|
|
4718
|
+
.string()
|
|
4719
|
+
.describe("Absolute path to the code-component project."),
|
|
4720
|
+
id: z
|
|
4721
|
+
.string()
|
|
4722
|
+
.describe("Color scheme id (REQUIRED) from `list_theme_globals`. The token is always identified by id."),
|
|
4723
|
+
name: z
|
|
4724
|
+
.string()
|
|
4725
|
+
.optional()
|
|
4726
|
+
.describe("Optional NEW name to rename the color scheme to. NOT used to find the token — lookup is always by id."),
|
|
4727
|
+
colors: z
|
|
4728
|
+
.any()
|
|
4729
|
+
.optional()
|
|
4730
|
+
.describe('Array of { slotId? | newSlotName?, value } to set — target an existing slot by `slotId` (from list_theme_globals colorsByScheme keys / colorSchemes.schemes) or create/reuse by `newSlotName`; value = a literal color hex/rgb/hsl/name, OR an existing theme color\'s cssVar "var(--<colorId>)" (linked reference). Merges by slot. Omit to only rename.'),
|
|
4731
|
+
is_default: z
|
|
4732
|
+
.boolean()
|
|
4733
|
+
.optional()
|
|
4734
|
+
.describe("true = make this the default scheme (exclusive — the editor clears the default flag from every other scheme in its group); false = remove the default flag. Omit to leave the default unchanged. The result echoes the persisted `isDefault`."),
|
|
4735
|
+
port: z
|
|
4736
|
+
.number()
|
|
4737
|
+
.optional()
|
|
4738
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4739
|
+
}, async ({ project_root, id, name, colors, is_default, port }) => {
|
|
4740
|
+
const args = [
|
|
4741
|
+
"update-color-scheme",
|
|
4742
|
+
"--id",
|
|
4743
|
+
id,
|
|
4744
|
+
...(name !== undefined ? ["--name", name] : []),
|
|
4745
|
+
...(colors !== undefined ? ["--colors", toJsonArrayArg(colors)] : []),
|
|
4746
|
+
...(is_default === true
|
|
4747
|
+
? ["--default"]
|
|
4748
|
+
: is_default === false
|
|
4749
|
+
? ["--no-default"]
|
|
4750
|
+
: []),
|
|
4751
|
+
...(port ? ["--port", String(port)] : []),
|
|
4752
|
+
];
|
|
4753
|
+
return callEditorAction(project_root, args);
|
|
4754
|
+
});
|
|
4755
|
+
// Tool: rename_theme_color_scheme_slot
|
|
4756
|
+
server.tool("rename_theme_color_scheme_slot", 'Rename a color scheme SLOT (a scheme key like "Background" or "PrimaryButton/Text") IN PLACE in the ' +
|
|
4757
|
+
"connected editor. A slot's id is STABLE, so renaming keeps every runtime reference intact " +
|
|
4758
|
+
"(`var(--<slotId>)` in CSS, `colorsByScheme[slotId]` in component code) — only the human display name " +
|
|
4759
|
+
"changes; nothing rebinds. Identify the slot by `id` (REQUIRED — the slot id from `list_theme_globals` → " +
|
|
4760
|
+
"colorSchemes.schemes[].id or a `colorsByScheme` key); name-based lookup is intentionally NOT supported " +
|
|
4761
|
+
'because slot names can collide across design assets. `name` is the NEW slot name (a "/" groups it in the ' +
|
|
4762
|
+
'editor UI, e.g. "PrimaryButton/Background"). Only non-design-asset (user/theme) slots can be renamed here. ' +
|
|
4763
|
+
"This renames the slot itself across ALL schemes that use it (a slot is shared) — it does NOT rename a single " +
|
|
4764
|
+
"scheme/palette (for that use `update_theme_color_scheme`). Requires `ikas-component dev` running with the " +
|
|
4765
|
+
"editor connected.", {
|
|
4766
|
+
project_root: z
|
|
4767
|
+
.string()
|
|
4768
|
+
.describe("Absolute path to the code-component project."),
|
|
4769
|
+
id: z
|
|
4770
|
+
.string()
|
|
4771
|
+
.min(1, "id is REQUIRED — the slot id from list_theme_globals (colorSchemes.schemes[].id / colorsByScheme keys).")
|
|
4772
|
+
.describe("Slot id (REQUIRED) from `list_theme_globals` → colorSchemes.schemes[].id / colorsByScheme keys. The slot is always identified by id."),
|
|
4773
|
+
name: z
|
|
4774
|
+
.string()
|
|
4775
|
+
.min(1, "name is REQUIRED — the new slot name (non-empty).")
|
|
4776
|
+
.describe('The NEW slot name (non-empty). A "/" groups it in the editor UI (e.g. "PrimaryButton/Background").'),
|
|
4777
|
+
port: z
|
|
4778
|
+
.number()
|
|
4779
|
+
.optional()
|
|
4780
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4781
|
+
}, async ({ project_root, id, name, port }) => {
|
|
4782
|
+
const args = [
|
|
4783
|
+
"rename-color-scheme-slot",
|
|
4784
|
+
"--id",
|
|
4785
|
+
id,
|
|
4786
|
+
"--name",
|
|
4787
|
+
name,
|
|
4788
|
+
...(port ? ["--port", String(port)] : []),
|
|
4789
|
+
];
|
|
4790
|
+
return callEditorAction(project_root, args);
|
|
4791
|
+
});
|
|
4792
|
+
// Tool: delete_theme_global
|
|
4793
|
+
server.tool("delete_theme_global", 'Delete a theme global setting from the connected editor. For `kind: globalVariable` pass `name` (the runtime key); for design-token kinds (color | typography | breakpoint | keyframe | colorScheme) pass the token `id`. For `kind: colorSchemeSlot` pass the color SLOT id (from `list_theme_globals` → colorSchemes.schemes[].id or a `colorsByScheme` key) — this deletes the slot itself across ALL schemes (use it to clean up a junk slot created by a typo); it CASCADES: the slot\'s color is removed from every scheme and any element/component style bound to that slot is cleared, so only delete a slot you are sure is unused. Only non-design-asset (user/theme) slots can be deleted here. Get names/ids from `list_theme_globals`. Deleting a non-existent id fails with a "not found" error (it does NOT report a false success), so a success result means the token really existed and was removed.', {
|
|
4794
|
+
project_root: z
|
|
4795
|
+
.string()
|
|
4796
|
+
.describe("Absolute path to the code-component project."),
|
|
4797
|
+
kind: z
|
|
4798
|
+
.enum([
|
|
4799
|
+
"globalVariable",
|
|
4800
|
+
"color",
|
|
4801
|
+
"typography",
|
|
4802
|
+
"breakpoint",
|
|
4803
|
+
"keyframe",
|
|
4804
|
+
"colorScheme",
|
|
4805
|
+
"colorSchemeSlot",
|
|
4806
|
+
])
|
|
4807
|
+
.describe("What to delete."),
|
|
4808
|
+
name: z
|
|
4809
|
+
.string()
|
|
4810
|
+
.optional()
|
|
4811
|
+
.describe("globalVariable runtime key (from `list_theme_globals`)."),
|
|
4812
|
+
id: z
|
|
4813
|
+
.string()
|
|
4814
|
+
.optional()
|
|
4815
|
+
.describe("design-token id, or for colorSchemeSlot the slot id from `list_theme_globals` → colorSchemes.schemes."),
|
|
4816
|
+
port: z
|
|
4817
|
+
.number()
|
|
4818
|
+
.optional()
|
|
4819
|
+
.describe("Dev server WebSocket port (default 5201)."),
|
|
4820
|
+
}, async ({ project_root, kind, name, id, port }) => {
|
|
4821
|
+
const p = port ? ["--port", String(port)] : [];
|
|
4822
|
+
const args = kind === "globalVariable"
|
|
4823
|
+
? ["delete-global-variable", "--name", String(name ?? ""), ...p]
|
|
4824
|
+
: [
|
|
4825
|
+
"delete-design-token",
|
|
4826
|
+
"--token-type",
|
|
4827
|
+
kind,
|
|
4828
|
+
"--id",
|
|
4829
|
+
String(id ?? ""),
|
|
4830
|
+
...p,
|
|
4831
|
+
];
|
|
4832
|
+
return callEditorAction(project_root, args);
|
|
4833
|
+
});
|
|
3144
4834
|
// --- Start server ---
|
|
3145
4835
|
async function main() {
|
|
3146
4836
|
const transport = new StdioServerTransport();
|