Skip to content

Fix: generator reads new layout format — live, factory, logs get correct widgets - #598

Merged
joelteply merged 1 commit into
mainfrom
fix/generator-widget-format
Mar 30, 2026
Merged

joelteply merged 1 commit into
mainfrom
fix/generator-widget-format

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Root Cause Found

The content type generator only read layout.main[] (old format). Recipes using layout.widgets[] (new format) — live, factory, canvas, logs — all mapped to chat-widget in the generated config. This is why live mode showed general chat.

Combined with the race condition fix in #597, this fully resolves content routing for all content types.

Fix

getMainWidget() helper reads both formats: new widgets[] array (finds center-position widget) and old main[] array.

Verified

live: live-widget ✓ (was: chat-widget)
factory: factory-widget ✓ (was: chat-widget)  
logs: log-viewer-widget ✓ (was: chat-widget)
grid-overview: grid-overview-widget ✓

Test

  • npm run build:ts passes
  • Generated ContentTypes.ts shows correct widget mappings
  • Deploy and verify live mode opens live-widget

…s all get correct widget

Generator only read layout.main (old format). Recipes using layout.widgets
array (live, factory, canvas, logs) all mapped to chat-widget. Now extracts
center-position widget from new format, falls back to old format.
Copilot AI review requested due to automatic review settings March 30, 2026 02:35
@joelteply
joelteply merged commit 04dd96b into main Mar 30, 2026
4 of 6 checks passed
@joelteply
joelteply deleted the fix/generator-widget-format branch March 30, 2026 02:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the content type generator so generated ContentTypes widget mappings correctly reflect recipes using the newer layout.widgets[] schema (instead of always falling back to chat-widget).

Changes:

  • Extend RecipeFile.layout typing to include the new widgets[] layout format.
  • Add getMainWidget() helper to extract the primary/center widget from either layout format.
  • Use getMainWidget() when generating ContentTypeConfig.widget.
Comments suppressed due to low confidence (1)

src/generator/generate-content-types.ts:101

  • hasRightPanel is still derived from layout.right, which is undefined for recipes using the new layout.widgets[] format. This will incorrectly mark right panels as absent for new-format recipes that include a right-position widget (e.g. canvas/logs/settings/theme), and getRightPanelConfig() will return null instead of the default help panel when the recipe service isn't loaded. Update the generator to detect right-panel intent from layout.widgets (and layout.panels?.right?.visible === false when present), while keeping the old layout.right handling.
        const widget = getMainWidget(r);
        const displayName = r.displayName || r.name || r.uniqueId;
        const icon = ICON_MAP[r.uniqueId] || '📄';
        const hasRightPanel = r.layout?.right !== null && r.layout?.right !== undefined;
        const entityType = r.entityType || null;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +31 to 33
// New format: widgets array with position
widgets?: Array<{ widget: string; position: string; order: number }>;
};

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For layout.widgets, position is typed as string, but elsewhere in the codebase it's treated as a fixed set ('left' | 'center' | 'right'). Narrowing this type (or reusing the existing WidgetPosition type) would prevent silent mis-generation if a recipe typo slips in.

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +48
const center = layout.widgets.find(w => w.position === 'center');
if (center) return center.widget;
// Fall back to first widget if no center specified
if (layout.widgets.length > 0) return layout.widgets[0].widget;

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the new layout format, this selects the first position === 'center' widget based on array order, but runtime selection sorts by order and takes the first (see RecipeLayoutService.getWidget()). To keep generated config consistent with runtime behavior, filter to center widgets, sort by order, then pick the first; also consider dropping the fallback to layout.widgets[0] (it could be a left/right widget).

Suggested change
const center = layout.widgets.find(w => w.position === 'center');
if (center) return center.widget;
// Fall back to first widget if no center specified
if (layout.widgets.length > 0) return layout.widgets[0].widget;
const centerWidgets = layout.widgets
.filter(w => w.position === 'center')
.slice()
.sort((a, b) => a.order - b.order);
if (centerWidgets.length > 0) {
return centerWidgets[0].widget;
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants