fix(docs): correct stale @supermemory/memory-graph API references - #1414
fix(docs): correct stale @supermemory/memory-graph API references#1414thegoodengineer wants to merge 1 commit into
Conversation
9869bf4 to
f602a6a
Compare
| memories: doc.memoryEntries.map((mem): GraphApiMemory => ({ | ||
| id: mem.id, | ||
| memory: mem.memory ?? mem.content ?? '', | ||
| isStatic: mem.isStatic ?? false, | ||
| spaceId: mem.spaceId ?? '', | ||
| isLatest: mem.isLatest ?? true, | ||
| isForgotten: mem.isForgotten ?? false, | ||
| forgetAfter: mem.forgetAfter ?? null, | ||
| forgetReason: mem.forgetReason ?? null, | ||
| version: mem.version ?? 1, | ||
| parentMemoryId: mem.parentMemoryId ?? null, | ||
| rootMemoryId: mem.rootMemoryId ?? null, | ||
| createdAt: mem.createdAt, | ||
| updatedAt: mem.updatedAt, | ||
| relation: mem.relation ?? null, | ||
| updatesMemoryId: mem.updatesMemoryId ?? null, | ||
| nextVersionId: mem.nextVersionId ?? null, | ||
| memoryRelations: mem.memoryRelations ?? null, | ||
| spaceContainerTag: mem.spaceContainerTag ?? null, | ||
| })), |
There was a problem hiding this comment.
The toGraphDocument function drops the content field from RawMemoryEntry when mapping to GraphApiMemory. According to the GraphApiMemory interface defined at lines 389-408, content?: string | null; is a valid optional field, but it's never set in the mapping.
This causes data loss when mem.content exists and is different from mem.memory. The fix is to add the content field to the mapped object:
memories: doc.memoryEntries.map((mem): GraphApiMemory => ({
id: mem.id,
memory: mem.memory ?? mem.content ?? '',
content: mem.content ?? null, // Add this line
isStatic: mem.isStatic ?? false,
// ... rest of fields
}))Without this, any distinct content in the raw API response will be silently dropped when consumed by components expecting GraphApiDocument[].
| memories: doc.memoryEntries.map((mem): GraphApiMemory => ({ | |
| id: mem.id, | |
| memory: mem.memory ?? mem.content ?? '', | |
| isStatic: mem.isStatic ?? false, | |
| spaceId: mem.spaceId ?? '', | |
| isLatest: mem.isLatest ?? true, | |
| isForgotten: mem.isForgotten ?? false, | |
| forgetAfter: mem.forgetAfter ?? null, | |
| forgetReason: mem.forgetReason ?? null, | |
| version: mem.version ?? 1, | |
| parentMemoryId: mem.parentMemoryId ?? null, | |
| rootMemoryId: mem.rootMemoryId ?? null, | |
| createdAt: mem.createdAt, | |
| updatedAt: mem.updatedAt, | |
| relation: mem.relation ?? null, | |
| updatesMemoryId: mem.updatesMemoryId ?? null, | |
| nextVersionId: mem.nextVersionId ?? null, | |
| memoryRelations: mem.memoryRelations ?? null, | |
| spaceContainerTag: mem.spaceContainerTag ?? null, | |
| })), | |
| memories: doc.memoryEntries.map((mem): GraphApiMemory => ({ | |
| id: mem.id, | |
| memory: mem.memory ?? mem.content ?? '', | |
| content: mem.content ?? null, | |
| isStatic: mem.isStatic ?? false, | |
| spaceId: mem.spaceId ?? '', | |
| isLatest: mem.isLatest ?? true, | |
| isForgotten: mem.isForgotten ?? false, | |
| forgetAfter: mem.forgetAfter ?? null, | |
| forgetReason: mem.forgetReason ?? null, | |
| version: mem.version ?? 1, | |
| parentMemoryId: mem.parentMemoryId ?? null, | |
| rootMemoryId: mem.rootMemoryId ?? null, | |
| createdAt: mem.createdAt, | |
| updatedAt: mem.updatedAt, | |
| relation: mem.relation ?? null, | |
| updatesMemoryId: mem.updatesMemoryId ?? null, | |
| nextVersionId: mem.nextVersionId ?? null, | |
| memoryRelations: mem.memoryRelations ?? null, | |
| spaceContainerTag: mem.spaceContainerTag ?? null, | |
| })), | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
9209f94 to
2897daa
Compare
| documents: (data.documents as RawDocument[]).map(toGraphDocument), | ||
| pagination: data.pagination, |
There was a problem hiding this comment.
The code uses a type assertion (as RawDocument[]) on data.documents instead of a type annotation. According to the style guide rule 'Use type annotations instead of assertions for object literals' and 'Avoid unnecessary type assertions', you should avoid as casts where possible. Instead, type data properly (e.g., const data: { documents: RawDocument[]; pagination: unknown } = await response.json();) so that data.documents is already typed as RawDocument[] without needing a cast.
| documents: (data.documents as RawDocument[]).map(toGraphDocument), | |
| pagination: data.pagination, | |
| documents: data.documents.map(toGraphDocument), | |
| pagination: data.pagination, | |
Spotted by Graphite (based on custom rule: TypeScript style guide (Google))
Is this helpful? React 👍 or 👎 to let us know.
apps/docs/integrations/memory-graph.mdx and apps/memory-graph-playground/README.md
documented an older version of the @supermemory/memory-graph public API. Following
the Quick Start, Props Reference, or Exports section as written produced code that
either fails to type-check or silently drops props the component no longer has.
Verified against packages/memory-graph/src/{index.tsx,types.ts,api-types.ts,mock-data.ts,
constants.ts} and cross-checked the API normalization logic against two independent
real call sites: apps/web/components/memory-graph/hooks/use-graph-api.ts and
apps/memory-graph-playground/src/app/page.tsx.
- Exports section listed Legend, NodeDetailPanel, SpacesDropdown, useGraphInteractions,
colors, LAYOUT_CONSTANTS - none of these are actually exported. Corrected to the
real exports and added the previously-undocumented ./mock-data subpath.
- All examples used loadMoreDocuments/totalLoaded/selectedSpace/onSpaceChange/
showSpacesSelector, none of which exist on MemoryGraphProps. Corrected to
onLoadMore/totalCount and removed the Controlled Space Selection example
(that feature no longer exists on the component).
- documents was typed as DocumentWithMemories[] with a fabricated shape; the real
prop type is GraphApiDocument[]. Added a toGraphDocument mapping example grounded
in the real production code that talks to /v3/documents/documents.
- Rewrote Props Reference and Data Types to match the real MemoryGraphProps and
GraphApiDocument/GraphApiMemory interfaces field-for-field, including several
real props that weren't documented at all before.
- Removed the false 'space selector visible/hidden' claim from the Variants section
(no such component exists anywhere in packages/memory-graph/src); kept the 0.8x/0.5x
zoom figures, which checked out against constants.ts.
- Made the Pages Router and Express tabs in Backend API Route self-contained (each
defines its own toGraphDocument mapping) instead of depending on code shown only
in the App Router tab, since CodeGroup tabs are alternatives a reader copies
individually.
- Applied the identical corrections to apps/memory-graph-playground/README.md,
which had the same drift independently.
Address Graphite automated review feedback:
- Set the content field in all three toGraphDocument mappings (was a valid but
unpopulated field on GraphApiMemory). Confirmed via use-graph-data.ts that it's
inert for rendering (always overwritten with mem.memory before draw), so this
wasn't visible data loss, but it's a free fix that matches the type exactly.
- Replaced the (data.documents as RawDocument[]) cast with a proper
RawDocumentsResponse type annotation on data in the App Router and Pages Router
tabs, per the custom TypeScript style rule Graphite flagged. Implemented what
the comment's prose described rather than its literal suggested diff, which
would have just deleted the cast and left data as any.
Docs-only change, no .ts/.tsx files touched. This repo's biome.json has no
Markdown/MDX support configured, so format-lint doesn't apply here; checked
fence and MDX-component balance by hand instead (34 fence lines, all CodeGroup/
Note/Warning/Card tags balanced 1:1).
2897daa to
8d3f7ac
Compare
Summary
apps/docs/integrations/memory-graph.mdx(and, independently,apps/memory-graph-playground/README.md) document an older version of the@supermemory/memory-graphpublic API. Following the Quick Start, Props Reference, or Exports section as written today produces code that either fails to type-check or silently drops props the component doesn't recognize.What's wrong (verified against
packages/memory-graph/src)Legend,NodeDetailPanel,SpacesDropdown,useGraphInteractions,colors,LAYOUT_CONSTANTS. None of these are exported frompackages/memory-graph/src/index.tsx. The real exports areMemoryGraph,GraphCanvas,useGraphData,useGraphTheme, four engine classes, andDEFAULT_COLORS/GRAPH_SETTINGS/ etc.loadMoreDocuments,totalLoaded,selectedSpace,onSpaceChange,showSpacesSelector. None of these exist onMemoryGraphProps(packages/memory-graph/src/types.ts). The real props areonLoadMore/totalCount; the space-selector props don't exist on the component at all anymore.documentswas typed asDocumentWithMemories[]with a fabricated shape (status,metadata,customId, ...), butMemoryGraphProps.documentsis actuallyGraphApiDocument[](documentType/memories), a different, incompatible shape. Code copied straight from the docs doesn't compile.apps/memory-graph-playground/README.md, confirming this isn't a one-off typo but the package's real API having moved on without the docs.What changed
packages/memory-graph/src/index.tsxexactly, and documented the previously-undocumented./mock-datasubpath export (generateMockGraphData, already used internally by the playground app).GraphApiDocument[],onLoadMore,totalCount, and added atoGraphDocumentmapping function, grounded inapps/web/components/memory-graph/hooks/use-graph-api.ts(the actual production code that calls/v3/documents/documents), showing how to normalize the API'stype/memoryEntriesfields into thedocumentType/memoriesshape the component needs.selectedSpace/onSpaceChange/showSpacesSelectoraren't props on the component anymore.MemoryGraphPropsfield-for-field, including several real props that weren't documented before (containerTags,documentIds,maxNodes,showFps,labels,layering, slideshow props,onOpenDocument).GraphApiDocument/GraphApiMemory(whatdocumentsactually takes) alongside the realDocumentWithMemories/MemoryEntry(the backward-compat exports), instead of a fabricated shape.constants.ts.toGraphDocumentmapping) instead of referencing the App Router tab's helper, sinceCodeGrouptabs are alternatives a reader copies individually.apps/memory-graph-playground/README.md.Not changed
Installation, Performance, and Browser Support sections, and the Variants zoom figures (0.8x / 0.5x). I found no evidence these are inaccurate, so I left them alone to keep the diff scoped to verified errors.
Addressed automated review feedback
Graphite's review left two comments; both are fixed:
toGraphDocument(and the Express equivalent) never setGraphApiMemory.content, even though it's a valid field on the type. Addedcontent: mem.content ?? nullin all three mapping functions. Worth noting for context: I checked, and this field is provably unused for rendering (packages/memory-graph/src/hooks/use-graph-data.tsalways overwrites it withmem.memorybefore a memory node is drawn), so this wasn't causing the visible "data loss" the comment described, just an unpopulated optional field. Fixed anyway since it's free and makes the mapping match the type exactly.(data.documents as RawDocument[])cast was flagged against a custom "avoid type assertions" style rule. Rather than apply the bot's literal suggested diff (which just deletes the cast and leavesdataasany, i.e. less type-safe than before), I implemented what its own description asked for: aRawDocumentsResponseinterface and a type annotation ondata, sodata.documentsisRawDocument[]without any cast, in both the App Router and Pages Router tabs.Verification
packages/memory-graph/src/{index.tsx,types.ts,api-types.ts,mock-data.ts}andpackages/memory-graph/package.json'sexportsmap.apps/web/components/memory-graph/hooks/use-graph-api.tsandapps/memory-graph-playground/src/app/page.tsx. Both convert the sametype/memoryEntriestodocumentType/memoriesshape, giving two independent confirmations of the real wire format rather than a guess.Console/Consumerzoom claim in the Variants section againstpackages/memory-graph/src/constants.ts(0.8x / 0.5x initial zoom, confirmed accurate) and removed the section's "space selector visible/hidden" claim, which isn't: there's no space-selector component anywhere inpackages/memory-graph/src(only six components total, none of them a dropdown/selector).CodeGrouptab in the Backend API Route section standalone (each defines its owntoGraphDocumentmapping) instead of one tab silently depending on code shown only in another tab.biome.jsonhas no Markdown/MDX support configured in this repo, sobun run format-lintdoesn't apply to either changed file (confirmed:bunx biome checkexplicitly reports both as ignored, 0 files processed). Checked fence and MDX-component balance by hand instead: 34 code-fence lines (17 balanced pairs), and<CodeGroup>/<Note>/<Warning>/<Card>each open/close 1:1..ts/.tsxfiles touched.apps/docshas nocheck-typesorbuildscript (seeapps/docs/package.json), so this change is a structural no-op for those turbo tasks.