feat(sdk/typescript): Vercel AI SDK chat-persistence adapter (closes #37) - #57
Merged
Conversation
) The last of the three framework adapters (after the Python LangGraph + CrewAI ones). The AI SDK persists a chat as its full UIMessage[], loaded by id and re-saved after each turn; this maps that convention onto the kv block — one key per chat holding the JSON message array. - New subpath export `@memsidecar/client/ai` (src/ext/vercel.ts): createChatStore → loadChat(id) / saveChat({chatId, messages}) matching the AI SDK's persistence points, plus createChat / deleteChat / listChats. Typed to `ai`'s UIMessage via a type-only import; `ai` is an optional peer dependency, so importing the base client never pulls it in. - Client is typed against a structural `{ kv }` subset (a full MemSidecar satisfies it) so the store unit-tests with a fake and stays decoupled. - package.json: `./ai` export, optional peer dep `ai` (>=5), dev deps `ai` + @types/node; README documents the toUIMessageStreamResponse onFinish wiring. - Offline tests (mock kv) cover round-trip, empty/unknown chat, list/delete, and namespace isolation. Verified: tsc typecheck + build clean, `dist/ext/vercel.{js,d.ts}` ship in the package, and all offline tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The last of the three framework adapters in #37 — after the Python LangGraph (#46) and CrewAI (#47) ones, this is the TypeScript Vercel AI SDK adapter. Unblocked now that the TS SDK (#44) is merged.
What it does
The AI SDK persists a chat as its full
UIMessage[], loaded by id at the start of a request and re-saved after each turn. This maps that convention onto the kv block — one key per chat holding the JSON message array.@memsidecar/client/ai(src/ext/vercel.ts):createChatStore→loadChat(id)/saveChat({chatId, messages})(matching the AI SDK's persistence points) pluscreateChat/deleteChat/listChats.ai'sUIMessagevia a type-only import;aiis an optional peer dependency, so importing the base client never pulls it in (mirrors the Pythonmemsidecar[langgraph]extra pattern).{ kv }subset (a fullMemSidecarsatisfies it), so the store unit-tests with a fake and stays decoupled.Verification
tsctypecheck + build clean;dist/ext/vercel.{js,d.ts}ship innpm pack; offline tests (mock kv) cover round-trip, empty/unknown chat, list/delete, and namespace isolation — all pass. (The TS SDK isn't gated by the repo's Go/buf CI, so this was verified locally.)Closes #37. README documents the
toUIMessageStreamResponsewiring.