x
This commit is contained in:
1 parent
1a13b3624a
commit
4454b860c1
9 files changed
+381
-105
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import crypto from "crypto";
|
||||
import type { AxiosInstance } from "axios";
|
||||
import { PAGE_SECTION_TYPES } from "@homaroma/types";
|
||||
|
||||
@@ -116,9 +117,12 @@ const SECTION_TOOL_CONFIGS = [
|
||||
properties: {
|
||||
sectionId: { type: "number", description: "The numeric ID of the section to update" },
|
||||
title: { ...localizedStringSchema, description: `Localized section title, for example ${localizedStringExample}` },
|
||||
backgroundColor: { type: "string", description: "Plain string representing a valid CSS color for the background" },
|
||||
textColor: { type: "string", description: "Plain string representing a valid CSS color for text" },
|
||||
iconColor: { type: "string", description: "Plain string representing a valid CSS color for icons" },
|
||||
categories: {
|
||||
type: "array",
|
||||
description: "Accordion categories",
|
||||
description: "Accordion categories. IMPORTANT: Providing this will completely overwrite the existing categories array. Ensure you provide all categories.",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
@@ -141,7 +145,7 @@ const SECTION_TOOL_CONFIGS = [
|
||||
}
|
||||
}
|
||||
},
|
||||
required: ["sectionId", "categories"]
|
||||
required: ["sectionId"]
|
||||
},
|
||||
{
|
||||
name: "update_contact_info",
|
||||
@@ -298,6 +302,74 @@ export const SECTION_TOOL_DEFINITIONS = [
|
||||
required: config.required
|
||||
}
|
||||
})),
|
||||
{
|
||||
name: "add_accordion_category",
|
||||
description: "Add a category to an ACCORDION section.",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
sectionId: { type: "number", description: "The numeric ID of the section to update" },
|
||||
name: { ...localizedStringSchema, description: "Localized category name" },
|
||||
icon: { type: "string", description: "Optional plain string for icon/emoji" },
|
||||
questions: {
|
||||
type: "array",
|
||||
description: "Optional array of questions to add",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: {
|
||||
q: { ...localizedStringSchema, description: "Localized question text" },
|
||||
a: { ...localizedStringSchema, description: "Localized answer text" }
|
||||
},
|
||||
required: ["q", "a"]
|
||||
}
|
||||
}
|
||||
},
|
||||
required: ["sectionId", "name"]
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "update_accordion_category",
|
||||
description: "Update a category in an ACCORDION section.",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
sectionId: { type: "number", description: "The numeric ID of the section to update" },
|
||||
categoryId: { type: "string", description: "ID of the category to update" },
|
||||
name: { ...localizedStringSchema, description: "Optional localized category name" },
|
||||
icon: { type: "string", description: "Optional plain string for icon/emoji" }
|
||||
},
|
||||
required: ["sectionId", "categoryId"]
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "add_accordion_question",
|
||||
description: "Add a question to a category in an ACCORDION section.",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
sectionId: { type: "number", description: "The numeric ID of the section to update" },
|
||||
categoryId: { type: "string", description: "ID of the category" },
|
||||
question: { ...localizedStringSchema, description: "Localized question text" },
|
||||
answer: { ...localizedStringSchema, description: "Localized answer text" }
|
||||
},
|
||||
required: ["sectionId", "categoryId", "question", "answer"]
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "update_accordion_question",
|
||||
description: "Update a question in an ACCORDION section.",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
sectionId: { type: "number", description: "The numeric ID of the section to update" },
|
||||
categoryId: { type: "string", description: "ID of the category" },
|
||||
questionId: { type: "string", description: "ID of the question item to update" },
|
||||
question: { ...localizedStringSchema, description: "Optional localized question text" },
|
||||
answer: { ...localizedStringSchema, description: "Optional localized answer text" }
|
||||
},
|
||||
required: ["sectionId", "categoryIndex", "itemIndex"]
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "delete_page_section",
|
||||
description: "Delete a block section from a dynamic page layout",
|
||||
@@ -395,6 +467,65 @@ export async function handleSectionTool(api: AxiosInstance, name: string, params
|
||||
const res = await api.delete(`/pages/sections/${params.sectionId}`);
|
||||
return { content: [{ type: "text", text: JSON.stringify(res.data, null, 2) }] };
|
||||
}
|
||||
case "add_accordion_category":
|
||||
case "update_accordion_category":
|
||||
case "add_accordion_question":
|
||||
case "update_accordion_question": {
|
||||
const existingRes = await api.get(`/pages/sections/${params.sectionId}?lang=all`);
|
||||
const payload = existingRes.data?.payload || {};
|
||||
payload.categories = payload.categories || [];
|
||||
|
||||
if (name === "add_accordion_category") {
|
||||
const questions = params.questions?.map((q: any) => ({
|
||||
id: crypto.randomUUID(),
|
||||
q: q.q,
|
||||
a: q.a
|
||||
})) || [];
|
||||
payload.categories.push({
|
||||
id: crypto.randomUUID(),
|
||||
name: params.name,
|
||||
icon: params.icon,
|
||||
questions
|
||||
});
|
||||
} else if (name === "update_accordion_category") {
|
||||
const cat = payload.categories.find((c: any) => c.id === params.categoryId);
|
||||
if (!cat) throw new Error(`Category with id ${params.categoryId} not found`);
|
||||
if (params.name) {
|
||||
cat.name = typeof params.name === "object" && typeof cat.name === "object"
|
||||
? { ...cat.name, ...params.name }
|
||||
: params.name;
|
||||
}
|
||||
if (params.icon !== undefined) cat.icon = params.icon;
|
||||
} else if (name === "add_accordion_question") {
|
||||
const cat = payload.categories.find((c: any) => c.id === params.categoryId);
|
||||
if (!cat) throw new Error(`Category with id ${params.categoryId} not found`);
|
||||
cat.questions = cat.questions || [];
|
||||
cat.questions.push({ id: crypto.randomUUID(), q: params.question, a: params.answer });
|
||||
} else if (name === "update_accordion_question") {
|
||||
const cat = payload.categories.find((c: any) => c.id === params.categoryId);
|
||||
if (!cat) throw new Error(`Category with id ${params.categoryId} not found`);
|
||||
cat.questions = cat.questions || [];
|
||||
const item = cat.questions.find((q: any) => q.id === params.questionId);
|
||||
if (!item) throw new Error(`Question with id ${params.questionId} not found`);
|
||||
if (params.question) {
|
||||
item.q = typeof params.question === "object" && typeof item.q === "object"
|
||||
? { ...item.q, ...params.question }
|
||||
: params.question;
|
||||
}
|
||||
if (params.answer) {
|
||||
item.a = typeof params.answer === "object" && typeof item.a === "object"
|
||||
? { ...item.a, ...params.answer }
|
||||
: params.answer;
|
||||
}
|
||||
}
|
||||
|
||||
await api.put(`/pages/sections/${params.sectionId}`, {
|
||||
type: "ACCORDION",
|
||||
payload
|
||||
});
|
||||
|
||||
return { content: [{ type: "text", text: "Success message" }] };
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user