fix(custom-widgets): address review findings

This commit is contained in:
ajnart committed 2026-08-30 21:47:44 +02:00
1 parent 349f889464
commit 6cca2bafe6
12 files changed
+158 -21

No files matched your search

@@ -15,6 +15,15 @@ const userMessage = (text: string): UIMessage => ({
});
describe("Custom Widget authoring context", () => {
test("refunds a focused discovery claim when the tool call fails", () => {
const controller = createCustomWidgetDiscoveryPhaseController();
expect(controller.claim("customWidget_getComponents")).toBe(true);
expect(controller.claim("customWidget_getComponents")).toBe(false);
controller.observeFailure("customWidget_getComponents");
expect(controller.claim("customWidget_getComponents")).toBe(true);
});
test.each([
"Create a custom widget for these fixtures",
"Create custom widgets for these services",
@@ -42,7 +42,17 @@ export const createCustomWidgetDiscoveryPhaseController = (limit = maxFocusedCom
if (toolName === "customWidget_createFromPreview" && typeof result?.id === "string") reset();
},
observeFailure(toolName: string) {
if (toolName === "customWidget_validateTemplate" || toolName === "customWidget_previewCreate") reset();
if (toolName === "customWidget_validateTemplate" || toolName === "customWidget_previewCreate") {
reset();
return;
}
if (customWidgetContextToolBudgets[toolName] === undefined) return;
const used = calls.get(toolName) ?? 0;
if (used <= 1) {
calls.delete(toolName);
return;
}
calls.set(toolName, used - 1);
},
};
};