Skip to content

generate() and edit() crash: outputComponents[0] is now designSystem, not screen data #143

@icebear0828

Description

@icebear0828

Bug

Project.generate() and Screen.edit() crash with:

TypeError: Cannot read properties of undefined (reading 'screens')

Cause

The SDK hardcodes outputComponents[0].design.screens[0] to extract screen data from the API response. The Stitch API now returns designSystem at outputComponents[0] and the actual screen data at outputComponents[1]:

outputComponents[0] → { designSystem: { ... } }      // no .design property
outputComponents[1] → { design: { screens: [...] } }  // actual screen
outputComponents[2] → { text: "..." }
outputComponents[3..] → { suggestion: "..." }

This affects both generate_screen_from_text and edit_screens response handling.

Affected code

  • domain-map.json: projection { "prop": "outputComponents", "index": 0 }
  • Generated project.ts line 40: raw.outputComponents[0].design.screens[0]
  • Generated screen.ts line 41: raw.outputComponents[0].design.screens[0]

Proposed fix

Replace the brittle index-based lookup with property-based lookup:

  • Add find to ProjectionStep IR schema
  • Emit .find((c) => c.design) instead of [0]

This makes the projection resilient to API response ordering changes.

Reproduction

const project = stitch.project("any-project-id");
const screen = await project.generate("A simple card");
// → TypeError: Cannot read properties of undefined (reading 'screens')

Metadata

Metadata

Assignees

No one assigned

    Labels

    fleetFleet-managed issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions