Check Python-JavaScript UI Bindings
Audit SD.Next UI integration points where Python uses Gradio _js=... bindings to call JavaScript. Verify each JavaScript callback is exposed on the global window object and included in ui/globals.d.ts.
When To Use
- The user changes or reviews Python UI code under
modules/, scripts/, or extensions/ with _js= callbacks.
- A UI integration bug involves Python-triggered JavaScript functions.
- You need to validate UI contract consistency for Gradio-bound JS methods.
- User adds or updates extension with JavaScript code in
extensions/*/javascript.
Guidance
- Consult
.github/instructions/core.instructions.md for relevant core runtime guidance before proceeding.
Primary Files
ui/globals.d.ts
wiki/Dev-UI.md
modules/** and scripts/** Python files that declare _js= values
extensions/*/javascript/** TypeScript/JavaScript source files
Secondary Files To Inspect
ui/**/*.ts
extensions-builtin/sdnext-modernui/src/**/*.ts
extensions-builtin/sdnext-kanvas/src/**/*.ts
extensions-builtin/sdnext-kanvas/javascript/kanvas.mjs
Audit Goals
For every Python _js usage, confirm:
- The referenced JS callback exists in code.
- The callback is assigned to
window.<name> or otherwise accessible as a global function.
- The callback name is declared in
ui/globals.d.ts.
- JavaScript-only methods called from Python are not implemented only as module-local exports.
For all extension JavaScript code under extensions/*/javascript, confirm:
- No missing JS callback registrations for Python-bound names.
- Global names are only used for Python bindings, not for code that should instead be imported.
ui/globals.d.ts remains the source of truth for Python-visible UI globals.
Procedure
1. Enumerate Python _js= Bindings
- Search
modules/, scripts/, and extensions/ for _js= occurrences.
- Capture the literal callback string values, including direct names and arrow-function expressions.
- For formatted strings, enumerate all possible callback names generated by the formatting pattern.
- Flag dynamic cases where the callback cannot be statically resolved.
This is the most complex part as _js can be assigned a direct string, a formatted string, or an inline function. Focus on extracting the intended callback name(s) for verification in the next steps.
Examples:
_js="send_to_kanvas"
_js=f"switch_to_{binding.tabname}"
_js=f'(x, y, i, j) => [x, y, ...selected_gallery_files("{tabname}")]'
_js='() => gallerySort("name")'
2. Enumerate any additional Extension JavaScript Sources
- Review
extensions/*/javascript, extensions-builtin/*/src, and the specific entry point extensions-builtin/sdnext-kanvas/javascript/kanvas.mjs for functions that attach to window.
- Confirm extension source files are the authoritative implementation, not generated build artifacts.
- Validate that any new JS entry points are registered by package build or extension initialization.
3. Verify JavaScript Exposure
- Search
ui/, extensions-builtin/sdnext-modernui/src/, extensions-builtin/sdnext-kanvas/src/, and extensions/*/javascript/ for each callback name.
- Confirm the callback is attached to
window as window.<name> = ... or equivalent.
- If the callback is an inline function string like
() => quickSaveStyle(), ensure the referenced helper exists and any helper used for Python integration is also globally available if needed.
4. Check TypeScript Declarations
- Open
ui/globals.d.ts and verify each Python-visible global callback name is declared.
- Confirm the declaration shape is compatible with its usage if type annotations are present.
- If an extension exposes its own additional global helpers, verify the declaration file is updated accordingly.
5. Propose Fixes for Any Issues Found
- For missing global registrations, add
window.<name> = <function> in the appropriate JavaScript source file.
- For missing
ui/globals.d.ts entries, add a declaration like declare global { function <name>(...args: any[]): any; } with appropriate types if possible.
6. Run UI Typecheck and Lint tests
- Run
pnpm eslint to ensure there are no linting errors.
- Run
pnpm tsc to ensure there are no type errors, which can catch missing or mismatched declarations.
- Run
pnpm build to ensure the extension builds correctly with the new or updated JavaScript code.
And fix any issues that arise from these checks.
Reporting Format
Report findings with:
- Python file and
_js reference
- JavaScript location and global registration status
ui/globals.d.ts declaration status
- Severity: missing global, missing declaration, stale declaration, or dynamic/ambiguous binding
If no issues are found, state that the Python/JS UI binding audit is clear and mention whether any dynamic _js strings remain unresolved.
Output Expectations
When this skill is used, return:
- Total
_js bindings inspected
- Total missing or invalid global registrations
- Total missing or stale
ui/globals.d.ts entries
- Summary of any ambiguous
_js cases that require manual review
- A short summary of whether the UI binding contract is intact
1---2name: check-ui3description: Audit Python-to-JavaScript UI bindings for Gradio _js calls, global window exposure, and ui/globals.d.ts registration.4---56# Check Python-JavaScript UI Bindings78Audit SD.Next UI integration points where Python uses Gradio `_js=...` bindings to call JavaScript. Verify each JavaScript callback is exposed on the global `window` object and included in `ui/globals.d.ts`.910## When To Use1112- The user changes or reviews Python UI code under `modules/`, `scripts/`, or `extensions/` with `_js=` callbacks.13- A UI integration bug involves Python-triggered JavaScript functions.14- You need to validate UI contract consistency for Gradio-bound JS methods.15- User adds or updates extension with JavaScript code in `extensions/*/javascript`.1617## Guidance1819- Consult `.github/instructions/core.instructions.md` for relevant core runtime guidance before proceeding.2021## Primary Files2223- `ui/globals.d.ts`24- `wiki/Dev-UI.md`25- `modules/**` and `scripts/**` Python files that declare `_js=` values26- `extensions/*/javascript/**` TypeScript/JavaScript source files2728## Secondary Files To Inspect2930- `ui/**/*.ts`31- `extensions-builtin/sdnext-modernui/src/**/*.ts`32- `extensions-builtin/sdnext-kanvas/src/**/*.ts`33- `extensions-builtin/sdnext-kanvas/javascript/kanvas.mjs`3435## Audit Goals3637For every Python `_js` usage, confirm:38391. The referenced JS callback exists in code.402. The callback is assigned to `window.<name>` or otherwise accessible as a global function.413. The callback name is declared in `ui/globals.d.ts`.424. JavaScript-only methods called from Python are not implemented only as module-local exports.4344For all extension JavaScript code under `extensions/*/javascript`, confirm:4546- No missing JS callback registrations for Python-bound names.47- Global names are only used for Python bindings, not for code that should instead be imported.48- `ui/globals.d.ts` remains the source of truth for Python-visible UI globals.4950## Procedure5152### 1. Enumerate Python `_js=` Bindings5354- Search `modules/`, `scripts/`, and `extensions/` for `_js=` occurrences.55- Capture the literal callback string values, including direct names and arrow-function expressions.56- For formatted strings, enumerate all possible callback names generated by the formatting pattern.57- Flag dynamic cases where the callback cannot be statically resolved.5859This is the most complex part as `_js` can be assigned a direct string, a formatted string, or an inline function. Focus on extracting the intended callback name(s) for verification in the next steps.6061Examples:6263```python64_js="send_to_kanvas"65_js=f"switch_to_{binding.tabname}"66_js=f'(x, y, i, j) => [x, y, ...selected_gallery_files("{tabname}")]'67_js='() => gallerySort("name")'68```6970### 2. Enumerate any additional Extension JavaScript Sources7172- Review `extensions/*/javascript`, `extensions-builtin/*/src`, and the specific entry point `extensions-builtin/sdnext-kanvas/javascript/kanvas.mjs` for functions that attach to `window`.73- Confirm extension source files are the authoritative implementation, not generated build artifacts.74- Validate that any new JS entry points are registered by package build or extension initialization.7576### 3. Verify JavaScript Exposure7778- Search `ui/`, `extensions-builtin/sdnext-modernui/src/`, `extensions-builtin/sdnext-kanvas/src/`, and `extensions/*/javascript/` for each callback name.79- Confirm the callback is attached to `window` as `window.<name> = ...` or equivalent.80- If the callback is an inline function string like `() => quickSaveStyle()`, ensure the referenced helper exists and any helper used for Python integration is also globally available if needed.8182### 4. Check TypeScript Declarations8384- Open `ui/globals.d.ts` and verify each Python-visible global callback name is declared.85- Confirm the declaration shape is compatible with its usage if type annotations are present.86- If an extension exposes its own additional global helpers, verify the declaration file is updated accordingly.8788### 5. Propose Fixes for Any Issues Found8990- For missing global registrations, add `window.<name> = <function>` in the appropriate JavaScript source file.91- For missing `ui/globals.d.ts` entries, add a declaration like `declare global { function <name>(...args: any[]): any; }` with appropriate types if possible.9293### 6. Run UI Typecheck and Lint tests9495- Run `pnpm eslint` to ensure there are no linting errors.96- Run `pnpm tsc` to ensure there are no type errors, which can catch missing or mismatched declarations.97- Run `pnpm build` to ensure the extension builds correctly with the new or updated JavaScript code.9899And fix any issues that arise from these checks.100101## Reporting Format102103Report findings with:104105- Python file and `_js` reference106- JavaScript location and global registration status107- `ui/globals.d.ts` declaration status108- Severity: missing global, missing declaration, stale declaration, or dynamic/ambiguous binding109110If no issues are found, state that the Python/JS UI binding audit is clear and mention whether any dynamic `_js` strings remain unresolved.111112## Output Expectations113114When this skill is used, return:115116- Total `_js` bindings inspected117- Total missing or invalid global registrations118- Total missing or stale `ui/globals.d.ts` entries119- Summary of any ambiguous `_js` cases that require manual review120- A short summary of whether the UI binding contract is intact