api.book
Interface: IBookApi
Implementation tier: T1 (reads) / T2 (provider, iterate)
Read book sections, list book modules and their table of contents, iterate sections, and register custom book providers.
Permissions
book:readbook:provide (for registerProvider)
Methods
listModules
listModules(): Promise<BookModuleInfoDto[]>
Returns: Promise<BookModuleInfoDto[]>
getSection
getSection(moduleId: string, sectionId: string): Promise<BookSectionDto | null>
Get a single section by id.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
moduleId | string | Yes | |
sectionId | string | Yes |
Returns: Promise<BookSectionDto | null>
listSections
listSections(
moduleId: string,
parentId?: string,
): Promise<BookSectionSummaryDto[]>
Get the table of contents (or a subtree) for a book module.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
moduleId | string | Yes | |
parentId | string | No |
Returns: Promise<BookSectionSummaryDto[]>
iterateSections
iterateSections(opts: IterateBookOpts): Promise<BookIterationResult>
Cursor-based iteration over all sections (depth-first).
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
opts | IterateBookOpts | Yes |
Returns: Promise<BookIterationResult>
registerProvider
registerProvider(provider: BookProviderDescriptor): Promise<DisposableHandle>
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
provider | BookProviderDescriptor | Yes |
Returns: Promise<DisposableHandle>
Events
onDidChangeActiveBook
onDidChangeActiveBook: IEventApi<{ moduleId: string } | null>
Payload type: { moduleId: string } | null
Subscribe to this event:
const handle = await api.book.onDidChangeActiveBook.subscribe((payload) => {
// Handle event
});
// Later, to unsubscribe:
await handle.dispose();