Principle:AFK surf Open agent Provider Pattern
| Knowledge Sources | |
|---|---|
| Domains | Extensions, Plugin_System, BlockSuite |
| Last Updated | 2026-10-25 00:00 GMT |
Overview
Pattern of authoring an editor extension as a provider subclass with a zod-validated options schema and a setup hook that registers extensions into a DI container.
Description
The ext-loader system decouples extension authoring from the core. A provider is a class subclassing StoreExtensionProvider<T> or ViewExtensionProvider<T> with: a unique name (the key used with manager.configure), a zod schema validating the options object, and a setup(context, options?) hook that calls super.setup then context.register([...]) with the ExtensionType objects to install. The generic T is the options type inferred from the zod schema. Store providers are scope-agnostic ('scope: store'); view providers branch on a per-scope value. The schema rejects invalid configuration early, at configure time.
Usage
Apply this principle whenever you want to add custom blocks, services, providers, or UI to the editor without forking the core — a new block flavor, a custom notification service, a scoped toolbar. Subclass the appropriate base, declare the schema, implement setup.
Theoretical Basis
A provider is a typed plugin descriptor: Provider = (name, schema, setup). The schema is a runtime contract (zod) on the options; setup is a side-effectful registration against a per-scope DI container. The manager instantiates providers and resolves the extension list per scope.
Pseudo-code:
class MyStoreProvider extends StoreExtensionProvider<{ cacheSize: number }> {
override name = 'MyStoreProvider';
override schema = z.object({ cacheSize: z.number().min(0) });
override setup(context, options?) {
super.setup(context, options);
context.register([Ext1, Ext2]);
}
}