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
This commit is contained in:
Thomas authored and GitHub committed 2026-08-30 23:43:29 +02:00
1 parent 38f4b0e1f8
commit 5e23659d99
95 files changed
+6799 -1778

No files matched your search

@@ -0,0 +1,83 @@
export const isCustomWidgetToolName = (toolName: string) => toolName.startsWith("customWidget_");
const parallelSafeCustomWidgetToolNames = new Set([
"customWidget_getSkill",
"customWidget_schema",
"customWidget_getReference",
"customWidget_getComponentCatalog",
"customWidget_findComponents",
"customWidget_getComponent",
"customWidget_getComponents",
"customWidget_getSharedProps",
"customWidget_getExample",
]);
const isExclusiveCustomWidgetToolName = (toolName: string) =>
isCustomWidgetToolName(toolName) && !parallelSafeCustomWidgetToolNames.has(toolName);
export const appendActiveCustomWidgetToolInstruction = (instructions: string, activeToolNames: readonly string[]) =>
`${instructions}\n\nCurrent authoring step (authoritative), active tools: [${activeToolNames.join(", ")}]. Independent read-only discovery/reference tools may run together. A lifecycle tool (validation, preview, evidence, revision, or persistence) must be the only call in its step; every unlisted tool fails.`;
export const createCustomWidgetToolStepGate = () => {
let currentStep: number | null = null;
let exclusiveToolClaimed = false;
let parallelSafeToolClaimed = false;
let componentRepairClaimed = false;
return {
begin(stepNumber: number) {
if (currentStep === stepNumber) return;
currentStep = stepNumber;
exclusiveToolClaimed = false;
parallelSafeToolClaimed = false;
componentRepairClaimed = false;
},
claim(toolName: string) {
if (isExclusiveCustomWidgetToolName(toolName)) {
if (exclusiveToolClaimed || parallelSafeToolClaimed) return false;
exclusiveToolClaimed = true;
return true;
}
if (exclusiveToolClaimed) return false;
if (toolName === "customWidget_getComponent") {
if (componentRepairClaimed) return false;
componentRepairClaimed = true;
}
parallelSafeToolClaimed = true;
return true;
},
};
};
export function selectSequentialCustomWidgetToolCalls<T extends { function: { name: string } }>(
toolCalls: readonly T[],
) {
let exclusiveToolSelected = false;
let parallelSafeToolSelected = false;
let componentRepairSelected = false;
const selected: T[] = [];
const rejected: T[] = [];
for (const toolCall of toolCalls) {
if (toolCall.function.name === "customWidget_getComponent") {
if (componentRepairSelected) {
rejected.push(toolCall);
continue;
}
componentRepairSelected = true;
}
if (!isExclusiveCustomWidgetToolName(toolCall.function.name) && !exclusiveToolSelected) {
parallelSafeToolSelected = true;
selected.push(toolCall);
continue;
}
if (!isExclusiveCustomWidgetToolName(toolCall.function.name) || exclusiveToolSelected || parallelSafeToolSelected) {
rejected.push(toolCall);
continue;
}
exclusiveToolSelected = true;
selected.push(toolCall);
}
return { selected, rejected };
}