fix(sdk): surface clarifying questions from generative tools as CLARIFICATION_REQUIRED - #380
Merged
Merged
Conversation
…FICATION_REQUIRED
generate_screen_from_text (and edit_screens, generate_variants,
apply_design_system) can answer with outputComponents[].text (a question)
and outputComponents[].suggestion (proposed replies) but no design.screens.
Generated methods threw a non-recoverable UNKNOWN_ERROR 'no screens in
response' and dropped the question.
- New recoverable StitchErrorCode CLARIFICATION_REQUIRED with
StitchError.clarification { question, suggestions } (type exported).
- emptyGenerationError(toolName, raw) in src/generation.ts decides between
CLARIFICATION_REQUIRED and the existing UNKNOWN_ERROR; the generator emits
a call to it, so Generation stays non-empty.
- Regenerated project/screen/designsystem; golden snapshot and fixture
StitchError stub updated for the new emit.
- README + stitch-sdk-usage skill document answering the question.
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.
Overview
Stitch's agent sometimes replies to a generate or edit call with a question instead of a design. The response contains
outputComponents[].text(the question) andoutputComponents[].suggestion(suggested replies), but nodesign.screens. Until now the SDK reported this asUNKNOWN_ERROR("Incomplete API response … no screens in response",recoverable: false). The question was lost, and callers such as the Stitch CLI and agents couldn't tell a normal clarifying question from a broken response.With this change those responses throw a recoverable
CLARIFICATION_REQUIREDerror that carries the question and the suggestions. Callers can show the question to the user and call the method again with a prompt that answers it. A response with neither screens nor text still throwsUNKNOWN_ERROR.Changes
packages/sdk/src/spec/errors.ts:CLARIFICATION_REQUIREDcode toStitchErrorCode.StitchClarificationtype (question,suggestions).clarificationfield toStitchErrorDataandStitchError.packages/sdk/src/generation.ts: addsemptyGenerationError(toolName, raw).CLARIFICATION_REQUIRED(recoverable: true). Thesuggestiontells the caller to call again, using the first suggested reply as the example.UNKNOWN_ERROR, as before.scripts/generate-sdk.ts: generated generation methods now throwemptyGenerationError(...)instead of an inlineUNKNOWN_ERROR.generated/src/{project,screen,designsystem}.ts,stitch-sdk.lockand the codegen snapshot.packages/sdk/src/index.ts: exports theStitchClarificationtype.README.md,packages/sdk/README.mdand thestitch-sdk-usageskill explain how to handleCLARIFICATION_REQUIRED.packages/sdk/test/unit/sdk.test.ts, and an updated assertion inscripts/test/codegen-snapshot.test.ts.Testing
cd packages/sdk && npx vitest run: 42 files, 362 tests passedbun run test:scripts: 119 passed, 0 failedbun run typecheck: passedbun run validate:generated: passedbun run check:skills: passednpx prettier --checkon the changed source files: passed