Skip to content

docs(comfy-router): narrow RunResult in the TypeScript snippets for SDK 0.3.0 - #1679

Open
mattmillerai wants to merge 2 commits into
mainfrom
matt/sdk-0.3.0-run-kind
Open

mattmillerai wants to merge 2 commits into
mainfrom
matt/sdk-0.3.0-run-kind

Conversation

@mattmillerai

Copy link
Copy Markdown
Contributor

ELI-5

@comfyorg/sdk@0.3.0 shipped today and changed the type models.run() returns. Every TypeScript snippet on the Comfy Router pages, plus the quickstart, is written in the old style, so copy-pasting one no longer compiles. This updates them.

Why they break

RunResult is now a discriminated union, because the run route's 200 has two documented shapes: an application/json document, and a */* binary body, which is how a partner whose generation is the response answers (the ElevenLabs audio models). Pulling data straight off the result no longer typechecks once a type argument is supplied:

error TS2339: Property 'result' does not exist on type
  'Uint8Array<ArrayBufferLike> | Result'.

Before / after:

// before
const { data } = await comfy.models.run<Result>("bfl/flux-kontext-pro", { ... });
console.log("image:", data.result.sample);

// after
const result = await comfy.models.run<Result>("bfl/flux-kontext-pro", { ... });
if (result.kind !== "json") throw new Error("expected a JSON result");

console.log("image:", result.data.result.sample);

What changed

  • .github/scripts/snippets/gen-code-pages.ts is the real change. typescriptSnippet assigns the result and narrows on kind before reading data. The 27 model code.mdx files in this PR are regenerated output, not hand edits.
  • development/comfy-router/quickstart.mdx is hand-written, so it is patched directly. Its install line also pinned @comfyorg/sdk@^0.1.9, which on a 0.x caret resolves below 0.2.0 and so never picked up either of the last two releases. Now ^0.3.0.

Untyped snippets (const { data } = await comfy.models.run(...) with no type argument) still compile, because data is unknown either way. They are left alone. The ja / zh / ko trees carry no typed snippets and are untouched; the i18n sync owns them regardless.

Verification

  • bun .github/scripts/snippets/gen-code-pages.ts --check --validate reports 204 code pages fresh (27 curated, 177 derived), so the committed output matches a clean generation.
  • Both patched shapes, verbatim, compiled against the 0.3.0 source: clean under tsc --noEmit. The same two shapes before the change produce the TS2339 above, which is how the break was confirmed rather than assumed.

Follow-up, not in this PR

The binary models have more to say now than they used to. elevenlabs/eleven_v3 and elevenlabs/eleven_sfx_v2 answer with audio bytes, which 0.3.0 can finally hand back, and their pages still print the result as though it were a document. Teaching the generator to emit a binary branch (result.kind === "binary" and write the bytes) for those models is worth its own pass.

Provenance

🤖 Generated with Claude Code

…DK 0.3.0

`@comfyorg/sdk@0.3.0` makes `RunResult` a discriminated union, because the
run route's `200` has two documented shapes: an `application/json` document
and a `*/*` binary body, which is how a partner whose generation IS the
response answers. Destructuring `data` straight off the result no longer
compiles when a type argument is supplied:

    error TS2339: Property 'result' does not exist on type
      'Uint8Array<ArrayBufferLike> | Result'.

Every TypeScript snippet on the Router model pages is written that way, as is
the quickstart, so each one is a copy-paste that fails to build against the
current SDK.

The generated pages are fixed at the source: `typescriptSnippet` in
`.github/scripts/snippets/gen-code-pages.ts` now assigns the result and
narrows on `kind` before reading `data`. The 27 affected pages are
regenerated output, not hand edits, and `--check --validate` reports all 204
fresh.

The quickstart is hand-written and is patched directly. Its install line also
pinned `@comfyorg/sdk@^0.1.9`, which on a `0.x` caret resolves below `0.2.0`
and so never picked up either of the last two releases; now `^0.3.0`.

The untyped snippets (`const { data } = await comfy.models.run(...)` with no
type argument) still compile, since `data` is `unknown` either way, and are
left alone.

Not in this change: the binary models have more to say now than they used to.
`elevenlabs/eleven_v3` and `elevenlabs/eleven_sfx_v2` answer with audio bytes,
which 0.3.0 can finally return, and their pages still print the result as if
it were a document. Teaching the generator to emit a binary branch for those
models is worth its own pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@mintlify

mintlify Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
comfy 🟢 Ready View Preview Sep 15, 2026, 11:24 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@github-actions

Copy link
Copy Markdown

🌐 i18n translation sync reminder

@comfyui-wiki English documentation was updated in this PR. Please complete or schedule translation updates for the following files:

Japanese (ja)

  • ja/development/comfy-router/models/black-forest-labs/flux-1-1-pro-ultra-image/code.mdx
  • ja/development/comfy-router/models/black-forest-labs/flux-1-kontext/code.mdx
  • ja/development/comfy-router/models/black-forest-labs/flux-3-video/code.mdx
  • ja/development/comfy-router/models/black-forest-labs/flux-video-upscale/code.mdx
  • ja/development/comfy-router/models/google/gemini/code.mdx
  • ja/development/comfy-router/models/google/nano-banana-2-lite/code.mdx
  • ja/development/comfy-router/models/google/nano-banana-2/code.mdx
  • ja/development/comfy-router/models/google/nano-banana-pro/code.mdx
  • ja/development/comfy-router/models/ideogram/ideogram-v4/code.mdx
  • ja/development/comfy-router/models/wan/happyhorse-1-0-i2v/code.mdx
  • ja/development/comfy-router/models/wan/happyhorse-1-0-r2v/code.mdx
  • ja/development/comfy-router/models/wan/happyhorse-1-0-t2v/code.mdx
  • ja/development/comfy-router/models/wan/happyhorse-1-0-video-edit/code.mdx
  • ja/development/comfy-router/models/wan/happyhorse-1-1-i2v/code.mdx
  • ja/development/comfy-router/models/wan/happyhorse-1-1-r2v/code.mdx
  • ja/development/comfy-router/models/wan/happyhorse-1-1-t2v/code.mdx
  • ja/development/comfy-router/models/wan/wan2-5-i2v-preview/code.mdx
  • ja/development/comfy-router/models/wan/wan2-5-t2v-preview/code.mdx
  • ja/development/comfy-router/models/wan/wan2-6-i2v/code.mdx
  • ja/development/comfy-router/models/wan/wan2-6-r2v/code.mdx
  • ja/development/comfy-router/models/wan/wan2-6-t2v/code.mdx
  • ja/development/comfy-router/models/wan/wan2-7-i2v/code.mdx
  • ja/development/comfy-router/models/wan/wan2-7-r2v/code.mdx
  • ja/development/comfy-router/models/wan/wan2-7-t2v/code.mdx
  • ja/development/comfy-router/models/wan/wan2-7-videoedit/code.mdx
  • ja/development/comfy-router/models/wan/wan3-0-video-prime/code.mdx
  • ja/development/comfy-router/models/wan/wan3-0-video/code.mdx
  • ja/development/comfy-router/quickstart.mdx

Simplified Chinese (zh)

  • zh/development/comfy-router/models/black-forest-labs/flux-1-1-pro-ultra-image/code.mdx
  • zh/development/comfy-router/models/black-forest-labs/flux-1-kontext/code.mdx
  • zh/development/comfy-router/models/black-forest-labs/flux-3-video/code.mdx
  • zh/development/comfy-router/models/black-forest-labs/flux-video-upscale/code.mdx
  • zh/development/comfy-router/models/google/gemini/code.mdx
  • zh/development/comfy-router/models/google/nano-banana-2-lite/code.mdx
  • zh/development/comfy-router/models/google/nano-banana-2/code.mdx
  • zh/development/comfy-router/models/google/nano-banana-pro/code.mdx
  • zh/development/comfy-router/models/ideogram/ideogram-v4/code.mdx
  • zh/development/comfy-router/models/wan/happyhorse-1-0-i2v/code.mdx
  • zh/development/comfy-router/models/wan/happyhorse-1-0-r2v/code.mdx
  • zh/development/comfy-router/models/wan/happyhorse-1-0-t2v/code.mdx
  • zh/development/comfy-router/models/wan/happyhorse-1-0-video-edit/code.mdx
  • zh/development/comfy-router/models/wan/happyhorse-1-1-i2v/code.mdx
  • zh/development/comfy-router/models/wan/happyhorse-1-1-r2v/code.mdx
  • zh/development/comfy-router/models/wan/happyhorse-1-1-t2v/code.mdx
  • zh/development/comfy-router/models/wan/wan2-5-i2v-preview/code.mdx
  • zh/development/comfy-router/models/wan/wan2-5-t2v-preview/code.mdx
  • zh/development/comfy-router/models/wan/wan2-6-i2v/code.mdx
  • zh/development/comfy-router/models/wan/wan2-6-r2v/code.mdx
  • zh/development/comfy-router/models/wan/wan2-6-t2v/code.mdx
  • zh/development/comfy-router/models/wan/wan2-7-i2v/code.mdx
  • zh/development/comfy-router/models/wan/wan2-7-r2v/code.mdx
  • zh/development/comfy-router/models/wan/wan2-7-t2v/code.mdx
  • zh/development/comfy-router/models/wan/wan2-7-videoedit/code.mdx
  • zh/development/comfy-router/models/wan/wan3-0-video-prime/code.mdx
  • zh/development/comfy-router/models/wan/wan3-0-video/code.mdx
  • zh/development/comfy-router/quickstart.mdx

Korean (ko)

  • ko/development/comfy-router/models/black-forest-labs/flux-1-1-pro-ultra-image/code.mdx
  • ko/development/comfy-router/models/black-forest-labs/flux-1-kontext/code.mdx
  • ko/development/comfy-router/models/black-forest-labs/flux-3-video/code.mdx
  • ko/development/comfy-router/models/black-forest-labs/flux-video-upscale/code.mdx
  • ko/development/comfy-router/models/google/gemini/code.mdx
  • ko/development/comfy-router/models/google/nano-banana-2-lite/code.mdx
  • ko/development/comfy-router/models/google/nano-banana-2/code.mdx
  • ko/development/comfy-router/models/google/nano-banana-pro/code.mdx
  • ko/development/comfy-router/models/ideogram/ideogram-v4/code.mdx
  • ko/development/comfy-router/models/wan/happyhorse-1-0-i2v/code.mdx
  • ko/development/comfy-router/models/wan/happyhorse-1-0-r2v/code.mdx
  • ko/development/comfy-router/models/wan/happyhorse-1-0-t2v/code.mdx
  • ko/development/comfy-router/models/wan/happyhorse-1-0-video-edit/code.mdx
  • ko/development/comfy-router/models/wan/happyhorse-1-1-i2v/code.mdx
  • ko/development/comfy-router/models/wan/happyhorse-1-1-r2v/code.mdx
  • ko/development/comfy-router/models/wan/happyhorse-1-1-t2v/code.mdx
  • ko/development/comfy-router/models/wan/wan2-5-i2v-preview/code.mdx
  • ko/development/comfy-router/models/wan/wan2-5-t2v-preview/code.mdx
  • ko/development/comfy-router/models/wan/wan2-6-i2v/code.mdx
  • ko/development/comfy-router/models/wan/wan2-6-r2v/code.mdx
  • ko/development/comfy-router/models/wan/wan2-6-t2v/code.mdx
  • ko/development/comfy-router/models/wan/wan2-7-i2v/code.mdx
  • ko/development/comfy-router/models/wan/wan2-7-r2v/code.mdx
  • ko/development/comfy-router/models/wan/wan2-7-t2v/code.mdx
  • ko/development/comfy-router/models/wan/wan2-7-videoedit/code.mdx
  • ko/development/comfy-router/models/wan/wan3-0-video-prime/code.mdx
  • ko/development/comfy-router/models/wan/wan3-0-video/code.mdx
  • ko/development/comfy-router/quickstart.mdx

Local sync: npm run translate (see README — Automated translation)

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 677ae0f5-0bd4-496f-a9f1-8c7b65dbed4d

📥 Commits

Reviewing files that changed from the base of the PR and between 5a81051 and d5e1c70.

📒 Files selected for processing (29)
  • .github/scripts/snippets/gen-code-pages.ts
  • development/comfy-router/models/black-forest-labs/flux-1-1-pro-ultra-image/code.mdx
  • development/comfy-router/models/black-forest-labs/flux-1-kontext/code.mdx
  • development/comfy-router/models/black-forest-labs/flux-3-video/code.mdx
  • development/comfy-router/models/black-forest-labs/flux-video-upscale/code.mdx
  • development/comfy-router/models/google/gemini/code.mdx
  • development/comfy-router/models/google/nano-banana-2-lite/code.mdx
  • development/comfy-router/models/google/nano-banana-2/code.mdx
  • development/comfy-router/models/google/nano-banana-pro/code.mdx
  • development/comfy-router/models/ideogram/ideogram-v4/code.mdx
  • development/comfy-router/models/wan/happyhorse-1-0-i2v/code.mdx
  • development/comfy-router/models/wan/happyhorse-1-0-r2v/code.mdx
  • development/comfy-router/models/wan/happyhorse-1-0-t2v/code.mdx
  • development/comfy-router/models/wan/happyhorse-1-0-video-edit/code.mdx
  • development/comfy-router/models/wan/happyhorse-1-1-i2v/code.mdx
  • development/comfy-router/models/wan/happyhorse-1-1-r2v/code.mdx
  • development/comfy-router/models/wan/happyhorse-1-1-t2v/code.mdx
  • development/comfy-router/models/wan/wan2-5-i2v-preview/code.mdx
  • development/comfy-router/models/wan/wan2-5-t2v-preview/code.mdx
  • development/comfy-router/models/wan/wan2-6-i2v/code.mdx
  • development/comfy-router/models/wan/wan2-6-r2v/code.mdx
  • development/comfy-router/models/wan/wan2-6-t2v/code.mdx
  • development/comfy-router/models/wan/wan2-7-i2v/code.mdx
  • development/comfy-router/models/wan/wan2-7-r2v/code.mdx
  • development/comfy-router/models/wan/wan2-7-t2v/code.mdx
  • development/comfy-router/models/wan/wan2-7-videoedit/code.mdx
  • development/comfy-router/models/wan/wan3-0-video-prime/code.mdx
  • development/comfy-router/models/wan/wan3-0-video/code.mdx
  • development/comfy-router/quickstart.mdx

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

TypeScript snippets and quick-start examples now retain the SDK result wrapper, reject non-JSON results, and read payloads through result.data. The quick-start updates the SDK version to ^0.3.0.

Changes

SDK result envelope updates

Layer / File(s) Summary
Generated snippet and quick-start pattern
.github/scripts/snippets/gen-code-pages.ts, development/comfy-router/quickstart.mdx
Generated snippets and the quick-start now validate result.kind === "json" and read payloads through result.data. The quick-start updates @comfyorg/sdk to ^0.3.0.
Image and text examples
development/comfy-router/models/black-forest-labs/*, development/comfy-router/models/google/*, development/comfy-router/models/ideogram/*
FLUX, Gemini, Nano Banana, and Ideogram examples now reject non-JSON results and read image or text payloads through result.data.
Video examples
development/comfy-router/models/black-forest-labs/flux-3-video/*, development/comfy-router/models/black-forest-labs/flux-video-upscale/*, development/comfy-router/models/wan/*
Video examples now reject non-JSON results and read video payloads through result.data, including nested output fields where applicable.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to d5e1c

No actionable correctness, availability, or documentation-contract issue remains from the reviewed changes.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch matt/sdk-0.3.0-run-kind
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch matt/sdk-0.3.0-run-kind

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cursor-review Trigger Cursor automated review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants