React hooks
Import the hooks from @equationalapplications/react-llm-wiki on the web, or from
@equationalapplications/expo-llm-wiki in Expo. They’re the same hooks.
<WikiProvider wiki={wiki}> <App /></WikiProvider>useWiki() returns the WikiMemory instance. It throws outside a provider. Use it for any
method that has no hook, such as listDrafts, lint, or getInstructions.
Conventions
Section titled “Conventions”Mutation hooks share one shape:
{ execute: (...args) => Promise<TResult>; lastResult: TResult | null; // last successful result; null before the first call or after an error isPending: boolean; error: Error | null; // cleared on the next execute()}Writes don’t refresh reads. After a mutation, call refetch() on any useMemoryRead,
useOntologyManifest, or useWikiTraversal that should update.
Read hooks
Section titled “Read hooks”useMemoryRead
Section titled “useMemoryRead”const { data, isPending, error, refetch } = useMemoryRead(entityId, query, options?);// data: MemoryBundle | nullIt fetches on mount, and again when entityId, query, wiki, or relevant options change
(maxResults, preFilterLimit, hybridWeight, tierWeights, includeZeroWeightEntities,
excludeDrafts). Changing tierFloors, asOf or tokenBudget alone does not refetch; call
refetch(). entityId may be an array. An
in-flight result always lands before a queued refetch starts.
- A
tierWeightsentry of1.0counts the same as leaving it out, so it doesn’t trigger a refetch. includeZeroWeightEntities: falseandundefinedbehave the same. Only switching totruerefetches.- For multi-entity reads,
data.metadatais also filled in.data.factScoresis conditional: it appears only when the query is non-empty and scored results were captured.
useWikiTraversal
Section titled “useWikiTraversal”const { nodes, edges, isPending, error, refetch } = useWikiTraversal(entityId, { sourceId, maxDepth: 2 });Accepts the same options as traverseGraph().
maxDepth is clamped to 1–3. edgeTypes: [] matches nothing, while leaving it out matches every
edge type. Pass the result to formatGraphContext({ nodes, edges }) for a prompt-ready block.
useOntologyManifest
Section titled “useOntologyManifest”const { manifest, mode, isPending, error, refetch } = useOntologyManifest(entityId);manifest and mode are null when the entity has no persisted or seeded manifest.
useEntityStatus
Section titled “useEntityStatus”const { ingesting, librarian, heal } = useEntityStatus(entityId);It’s push-based, with no polling, and updates on every job transition.
Mutation hooks
Section titled “Mutation hooks”| Hook | execute(...) |
lastResult |
|---|---|---|
useWikiWrite() |
(entityId, event) |
— |
useWikiIngest() |
(entityId, params) |
IngestResult |
useWikiForget() |
(entityId, params) |
{ deleted: { entries, tasks, events? }, metadataReset? } |
useWikiHasChanged() |
(entityId, sourceRef, sourceHash) |
boolean |
useWikiExport() |
(entityIds) |
MemoryDump |
useSetOntologyManifest() |
(entityId, manifest, { mode? }) |
— |
useWikiMaintenance
Section titled “useWikiMaintenance”const { runLibrarian, runHeal, runReembed, runPrune, isPending, lastResult, error } = useWikiMaintenance();isPendingis shared, so it’struewhile any of the operations is running.lastResultis a discriminated union:{ operation: 'librarian' | 'heal' | 'prune', result }. Narrow it by checkingoperation.runReembeddeliberately leaveslastResultasnull. Use its returned promise instead.
import type { MaintenanceResult } from '@equationalapplications/react-llm-wiki';
if (lastResult?.operation === 'prune') console.log(lastResult.result.entries);