Files
homarr/apps/nextjs/src/app/api/assistant/chat/assistant-tool-schema.ts
T
Thomas 5e23659d99 feat(assistant): optimize MCP and custom widget authoring (#6743)
* feat(assistant): optimize MCP and custom widget authoring

* fix(assistant): isolate server-safe JSX analyzer

* refactor(assistant): generate MCP tool staging

* fix(assistant): preserve widget placement follow-up

* fix(ci): allow fast gate to finish

* fix(custom-widgets): address review findings

* fix(custom-widgets): split preview evidence module

* style: format assistant custom widget files

* fix(custom-widgets): sync formatted skill schema
2026-08-30 23:43:29 +02:00

23 lines
1.1 KiB
TypeScript

const compactTemplateToolNames = new Set(["customWidget_validateTemplate", "customWidget_previewReviseTemplate"]);
const asRecord = (value: unknown): Record<string, unknown> | null =>
typeof value === "object" && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : null;
export const getAssistantToolInputSchema = (toolName: string, inputSchema: Record<string, unknown>) => {
if (!compactTemplateToolNames.has(toolName)) return inputSchema;
const properties = asRecord(inputSchema.properties);
if (!properties?.templateLines) return inputSchema;
const omittedProperties = new Set(["template"]);
if (toolName === "customWidget_previewReviseTemplate") omittedProperties.add("expectedRevision");
const required = Array.isArray(inputSchema.required)
? inputSchema.required.filter((name): name is string => typeof name === "string" && !omittedProperties.has(name))
: [];
return {
...inputSchema,
properties: Object.fromEntries(Object.entries(properties).filter(([name]) => !omittedProperties.has(name))),
required: [...new Set([...required, "templateLines"])],
};
};