title: "Library Hub API: rules for coding agents"
built: 2026-10-30
source: api/AGENTS.md
html: https://insurgently.com/projects/library-hub/technical/agents/AGENTSIndex of these files: llms.txt
You're in a plugin that calls Library Hub through @insurgently/library-hub-api. The contract is dist/index.d.ts in this package. Follow these rules:
- Use the getter. Reach Library Hub with
getLibraryHub(app, wanted, { by })oronLibraryHubReady(app, plugin, wanted, cb). Neverapp.plugins.getPlugin('library-hub')yourself. - Gate on the lowest minor you need.
wantedis a version like'0.8.0'. Don't raise it just because the types are newer. - Feature-detect anything newer than the gate. A method tagged
@sincea later minor than your gate may be missing:if (hasMethod(api, 'bookText')). - Re-register on the ready event. Library Hub can be turned off and on.
onLibraryHubReadycalls you again with the new API object; drop the old one. - Treat the error
codeas the contract. Branch one.code(server-off,book-missing,needs-conversion…), never on the message. Show the message to the user as it is. - Never import plugin source. Only this package. Its runtime part is a few helpers with no dependencies.
Also: a BookRef can be a number, a string or { isbn: … }; pass what you have. bookText only converts an AZW3 or MOBI with { convert: true }, and the user is asked first. A chapter's location goes to openBook unchanged.