mirror of
https://github.com/Comfy-Org/comfy-typescript-sdk.git
synced 2026-11-04 23:47:27 +00:00
[PR #120] feat(sdk): make the SDK loadable in a browser #124
Labels
No labels
audit:ai-readiness
audit:community
audit:github
audit:health-scoring
audit:policy
audit:release
audit:supply-chain
bug
cursor-review-pin
effort:medium
effort:small
effort:trivial
priority:nice-to-have
priority:recommended
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-typescript-sdk#124
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/comfy-typescript-sdk/pull/120
Author: @benjcooley
Created: 9/3/2026
Status: 🔄 Open
Base:
main← Head:ben/sdk-browser-safe📝 Commits (1)
add6c32feat(sdk): make the SDK loadable in a browser📊 Changes
7 files changed (+109 additions, -16 deletions)
View changed files
➕
src/browser-safety.test.ts(+50 -0)📝
src/sdk/assets.test.ts(+11 -1)📝
src/sdk/assets.ts(+24 -2)📝
src/sdk/core.ts(+1 -3)📝
src/sdk/hashing.ts(+8 -3)📝
src/sdk/outputs.ts(+8 -4)📝
src/sdk/workflows.ts(+7 -3)📄 Description
Summary
I'm making the SDK compatible with running in a web page. It previously only ran in Node.js. We need this because our Workshop pages call Router endpoints, and the page should use the same library the code snippet next to it teaches.
Five files imported Node-only tools at the top of the file. A browser build tool reads every import up front, before it knows which functions will actually run, so those got pulled in even when nothing called them. Browsers have no file system, so the build breaks — on
mainit fails with"randomUUID" is not exported by "__vite-browser-external:node:crypto".Two of them didn't need Node at all. One generates a random ID, which browsers and Node both do natively. The other splits filenames apart, which is a few lines of string handling, now written inline.
Those inlined helpers match what
node:pathactually does rather than picking one set of rules.node:pathdispatches on platform: on Windows a backslash is a path separator, on Linux and macOS it's an ordinary filename character. So a POSIX file genuinely nameda\b.txtkeeps its backslash exactly as before. A browser has no filesystem paths, so it takes the POSIX rules.The other three really do read and write files. They behave the same, but now ask for their Node tools inside the function instead of at the top, so that only happens if you call them. A bundler puts those in separate chunks a browser never fetches.
assets.tsalready worked this way foropenAsBlob; this extends it to the rest.Provenance
Authored by: Claude Code, directed by @benjcooley
Verified:
pnpm typecheck,pnpm test(409 passed, 24 files),pnpm lint,pnpm format:check,pnpm build. Also built a real Vite browser bundle against this branch and againstmain— see the test plan.Deviations: none
Reviewer context
Type: compatibility fix. No behaviour change for Node callers, no API change.
Not in scope:
models.list(). The router surface is hand-written rather than generated, so adding a catalog listing is a separate change with its own pagination design.Test plan
mainit fails on thenode:cryptoimport; against this branch it builds clean, 115 modules, and the main entry chunk contains nonode:references. The four Node modules appear only as separate lazy chunks that are never fetchedbrowser-safety.test.tswalks the shipped source and fails on any top-of-file Node import, naming file and line. Checked against a negative control: reintroducingimport { randomUUID } from "node:crypto"makes it fail with that exact location, and it passes again once revertedassets.test.tsasserts the inlined helpers agree withnode:pathon this platform, including the backslash case that differs between win32 and posixSummary by CodeRabbit
Bug Fixes
Documentation
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.