Skip to content

fix(sdk): surface clarifying questions from generative tools as CLARIFICATION_REQUIRED - #380

Merged
davideast merged 1 commit into
mainfrom
fix/generation-clarification
Oct 1, 2026
Merged

davideast merged 1 commit into
mainfrom
fix/generation-clarification

Conversation

@davideast

Copy link
Copy Markdown
Collaborator

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) and outputComponents[].suggestion (suggested replies), but no design.screens. Until now the SDK reported this as UNKNOWN_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_REQUIRED error 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 throws UNKNOWN_ERROR.

Changes

  • packages/sdk/src/spec/errors.ts:
    • Adds the CLARIFICATION_REQUIRED code to StitchErrorCode.
    • Adds the StitchClarification type (question, suggestions).
    • Adds an optional clarification field to StitchErrorData and StitchError.
  • packages/sdk/src/generation.ts: adds emptyGenerationError(toolName, raw).
    • If the response has text, it throws CLARIFICATION_REQUIRED (recoverable: true). The suggestion tells the caller to call again, using the first suggested reply as the example.
    • Otherwise it throws UNKNOWN_ERROR, as before.
  • scripts/generate-sdk.ts: generated generation methods now throw emptyGenerationError(...) instead of an inline UNKNOWN_ERROR.
  • Regenerated generated/src/{project,screen,designsystem}.ts, stitch-sdk.lock and the codegen snapshot.
  • packages/sdk/src/index.ts: exports the StitchClarification type.
  • Docs: README.md, packages/sdk/README.md and the stitch-sdk-usage skill explain how to handle CLARIFICATION_REQUIRED.
  • Tests: new unit cases in packages/sdk/test/unit/sdk.test.ts, and an updated assertion in scripts/test/codegen-snapshot.test.ts.

Testing

  • cd packages/sdk && npx vitest run: 42 files, 362 tests passed
  • bun run test:scripts: 119 passed, 0 failed
  • bun run typecheck: passed
  • bun run validate:generated: passed
  • bun run check:skills: passed
  • npx prettier --check on the changed source files: passed

…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.
@davideast
davideast merged commit e3f8ece into main Oct 1, 2026
12 checks passed
@davideast
davideast deleted the fix/generation-clarification branch October 1, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant