fix: add find projection step to IR for resilient outputComponents extraction#146
Closed
sushil-kamble wants to merge 1 commit intogoogle-labs-code:mainfrom
Closed
Conversation
…traction
The Stitch API returns outputComponents as a mixed, polymorphic array
(designSystem, design, text, suggestion) with no guaranteed ordering.
The SDK's generated generate() and edit() methods previously hardcoded
index 0 to locate the design component, causing a TypeError when the
API began returning a designSystem component at index 0.
This commit introduces a `find` step type to the ProjectionStep IR that
emits `.find((c: any) => c.<property>)` instead of a hardcoded array
index — making the extraction resilient to future API response ordering
changes.
Changes:
- scripts/ir-schema.ts: add `find: string` to ProjectionStep schema;
update refine() to forbid combining find with index or each
- scripts/generate-sdk.ts: emit .find((c: any) => c.X) in
emitProjection(); treat find like index in validateProjection()
for schema unwrapping
- domain-map.json: change outputComponents step in generate_screen_from_text
and edit_screens bindings from { index: 0 } to { find: "design" }
- Regenerate generated/src/{project,screen,stitch,index,tool-definitions}.ts
and stitch-sdk.lock via `bun run generate`
- Add IR schema tests for find acceptance and mutual-exclusion rules
- Add emitProjection test asserting correct find expression output
- Update sdk.test.ts mocks to reflect actual API shape (designSystem at
index 0, design at index 1) for generate and edit
Fixes google-labs-code#143
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
Removing it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #143
Problem
Project.generate()andScreen.edit()crash with:The root cause is that both methods hardcode
outputComponents[0]to locate the design component, but the Stitch API now returns adesignSystemcomponent at index 0 and the actual design component at index 1:SessionOutputComponentis a polymorphic union type with no ordering guarantee — hardcoding any index is fragile.Solution
This PR takes the approach suggested in #143 (comment): instead of patching the index from
0to1(as in PR #145), it adds properfindsemantics to theProjectionStepIR so the code generator emits.find((c: any) => c.design)— making extraction resilient to future API response ordering changes.Changes
scripts/ir-schema.tsfind: z.string().optional()toProjectionSteprefine()to forbid combiningfindwithindexoreachscripts/generate-sdk.tsemitProjection(): emits.find((c: any) => c.X)forfindstepsvalidateProjection(): treatsfindlikeindexwhen unwrapping array item schemaspackages/sdk/generated/domain-map.jsonoutputComponentsprojection step ingenerate_screen_from_textandedit_screensfrom{ "index": 0 }to{ "find": "design" }Generated files
bun run generate—project.tsnow emits:Tests
scripts/test/ir-schema.test.ts: 3 new tests (acceptsfind, rejectsfind+index, rejectsfind+each)scripts/test/generate-sdk.test.ts: asserts correct.find(...)expression outputpackages/sdk/test/unit/sdk.test.ts: updates mocks to reflect the real API shape (designSystem at [0], design at [1]) forgenerateandeditTest plan
npm run test)npm run test:scripts)npm run test:smoke)npx prettier --write .)bun run generateproduces clean output with correct.find(...)expressionWhy find over index: 1
PR #145 changes
index: 0→index: 1, which fixes the immediate crash but remains fragile — the next time the API adds or reorders a component, the index breaks again. Thefindapproach queries by presence of a property, which is semantically stable regardless of array ordering.🤖 Generated with Claude Code