Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Notebook Worker Package

Status: Implemented for the current package boundary. packages/notebook/worker owns generic notebook worker transport contracts and host request promise plumbing consumed by the notebook product plugin.

Purpose

@lapis-notes/notebook-worker separates worker transport message contracts, host-neutral worker-side request plumbing, main-thread command promise plumbing, main-thread host response wrapping, worker-side shell dispatch, and pure worker eligibility policy from the product plugin. The package owns protocol shapes, request id/promise settlement for both main-thread commands and worker-to-host calls, generic host response envelopes and transfer-list selection, generic worker-side command/response dispatch, and the reusable decision for whether a runtime feature set may use a worker; concrete worker startup, worker URL imports, request semantics, response application, host adapters, feature analysis, fallback execution, and execution remain in @lapis-notes/notebook.

Current Scope

  • stable notebook worker channel names
  • generic execute command request and response messages
  • generic progress messages
  • host request and host response messages
  • generic incoming/outgoing worker message unions
  • NotebookWorkerCommandBroker for creating command ids, creating command messages, tracking pending command promises, looking up command context for progress events, and rejecting outstanding commands when a worker stops
  • NotebookWorkerShell for dispatching incoming worker messages, settling host responses, wrapping execute command results/errors as command responses, and posting progress messages with the active command id
  • NotebookWorkerHostRequestBroker for posting host requests, tracking pending request promises, settling host responses, and rejecting outstanding requests when a worker shell tears down
  • NotebookWorkerHostRequestResponder for resolving main-thread host requests through product-provided callbacks, wrapping success/error host responses, and selecting transfer lists for transferable response values
  • shouldUseNotebookWorkerRuntime(input) for deciding whether a runtime feature set can use a worker, based on worker availability, DuckDB usage, live browser DOM requirements, injected dependency loaders, host-only providers, and unsupported dependency resolver kinds
  • hasUnsupportedNotebookWorkerRuntimeDependency(dependencies) for checking whether dependency descriptors require main-thread execution because they are not remote ESM descriptors

Boundary Rules

This package must stay host-neutral. It must not import @lapis-notes/api, Svelte, notebook product-plugin models, worker entrypoints, DuckDB, TypeScript, DOM runtime packages, or app host adapters. Product runtimes bind protocol generics to their document/result/progress types, decide what each command and host request means, provide the execute implementation used by NotebookWorkerShell, provide host request resolver callbacks used by NotebookWorkerHostRequestResponder, apply command responses to local state, and supply runtime feature facts to the worker policy helper.

Consumers

@lapis-notes/notebook consumes this package through a product-plugin alias layer that binds the generic protocol contracts to current notebook document, execution result, persisted cell-state, and progress-event types. Its concrete worker entrypoint uses NotebookWorkerShell plus NotebookWorkerHostRequestBroker for app-table and vault-file host calls, and its worker client uses NotebookWorkerCommandBroker, NotebookWorkerHostRequestResponder, and the shared policy helper after product-plugin feature analysis.