Skip to content

feat(sdk/typescript): Vercel AI SDK chat-persistence adapter (closes #37) - #57

Merged
mkorbi merged 1 commit into
mainfrom
feat/vercel-ai-adapter
Jul 24, 2026
Merged

feat(sdk/typescript): Vercel AI SDK chat-persistence adapter (closes #37)#57
mkorbi merged 1 commit into
mainfrom
feat/vercel-ai-adapter

Conversation

@mkorbi

@mkorbi mkorbi commented Jul 20, 2026

Copy link
Copy Markdown
Member

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.

  • New subpath export @memsidecar/client/ai (src/ext/vercel.ts): createChatStoreloadChat(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 (mirrors the Python memsidecar[langgraph] extra pattern).
  • The client is typed against a structural { kv } subset (a full MemSidecar satisfies it), so the store unit-tests with a fake and stays decoupled.
import { MemSidecar } from "@memsidecar/client";
import { createChatStore } from "@memsidecar/client/ai";

const store = createChatStore(new MemSidecar(addr, { token }));
const chatId = await store.createChat();
const messages = await store.loadChat(chatId);
// ...stream a turn, then:
result.toUIMessageStreamResponse({ originalMessages: messages,
  onFinish: ({ messages }) => store.saveChat({ chatId, messages }) });

Verification

tsc typecheck + build clean; dist/ext/vercel.{js,d.ts} ship in npm 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 toUIMessageStreamResponse wiring.

Note: touches sdk/typescript/package.json + package-lock.json, which #55 (publish workflows) also edits — trivial rebase for whichever lands second.

)

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>
@mkorbi
mkorbi merged commit fce4785 into main Jul 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: framework memory/checkpointer adapters (LangGraph, CrewAI, Vercel AI SDK)

1 participant