Add startup extensions for JavaScript kernels#29
Conversation
49923fa to
0f5c610
Compare
|
@jtpio what do you think? |
…ss implementation
|
Thanks for working on this! I haven't looked into the details of the changes yet. But if you both are fine with the current state please feel free to move forward with this. Otherwise I'll take a look soon. Also we can aim for a 0.4.0 final release of this kernel in the coming days. |
There was a problem hiding this comment.
Pull request overview
This PR introduces a first-class “kernel startup extensions” mechanism for @jupyterlite/javascript-kernel, enabling frontend integrations to preload runtime modules and register/unregister comm targets automatically as kernels start (and for already-running kernels), reducing the need for frontend requestExecute bootstrap payloads.
Changes:
- Adds a startup-extension registry service (
IJavaScriptKernelStartup) and wires it into the JavaScript kernel extension so registrations apply to new and active kernels. - Extends the runtime protocol/backend APIs to support module preloads and comm target registration/unregistration via the remote evaluator.
- Updates kernel initialization to apply startup extensions before user code runs, and updates docs/dependencies accordingly.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Adds lockfile entries for the new @lumino/disposable dependency. |
| README.md | Documents the new kernel startup extension API and usage example. |
| packages/javascript-kernel/src/startup.ts | Introduces the startup extension registry interface and token. |
| packages/javascript-kernel/src/runtime_remote.ts | Exposes preload/comm-target APIs over the Comlink remote runtime API. |
| packages/javascript-kernel/src/runtime_protocol.ts | Extends the remote runtime protocol interface with preload/comm-target methods. |
| packages/javascript-kernel/src/runtime_evaluator.ts | Implements module preload and comm target registration/unregistration in the evaluator. |
| packages/javascript-kernel/src/runtime_backends.ts | Plumbs new remote APIs through iframe/worker backend readiness contexts. |
| packages/javascript-kernel/src/kernel.ts | Applies/removes startup extensions during runtime readiness and kernel lifetime. |
| packages/javascript-kernel/src/index.ts | Exports the new startup API surface. |
| packages/javascript-kernel/src/executor.ts | Adds an executor-level importModule helper for resolved dynamic imports. |
| packages/javascript-kernel/src/comm/manager.ts | Adds comm target presence checks and unregister support. |
| packages/javascript-kernel/package.json | Declares @lumino/disposable dependency for the kernel package. |
| packages/javascript-kernel-extension/src/index.ts | Adds an in-memory startup extension registry and wires it into kernel creation. |
| packages/javascript-kernel-extension/package.json | Adds @lumino/disposable dependency and marks the kernel package as a singleton shared package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| trackKernel(kernel: JavaScriptKernel): void { | ||
| this._kernels.add(kernel); | ||
| const untrackKernel = (sender: JavaScriptKernel): void => { | ||
| this._kernels.delete(sender); | ||
| sender.disposed.disconnect(untrackKernel); | ||
| }; | ||
| kernel.disposed.connect(untrackKernel); | ||
| } |
| } catch (error) { | ||
| for (const target of registeredTargets.reverse()) { | ||
| await context.unregisterCommTarget(target.targetName); | ||
| } | ||
| throw error; | ||
| } |
Closes #28
This PR adds a first-class startup extension path for JavaScript kernels, allowing integrations to preload modules and register comm targets when kernels start. It also exposes a registration service for extensions and applies startup hooks to new and active kernels.