@mubit-ai/ai-sdk
v0.1.0
Published
Vercel AI SDK middleware backed by MuBit memory engine
Downloads
33
Readme
@mubit-ai/ai-sdk
Vercel AI SDK middleware backed by MuBit memory engine.
Wraps any AI SDK model with automatic memory injection and interaction capture.
Install
npm install @mubit-ai/ai-sdkUsage
import { wrapLanguageModel } from "ai";
import { mubitMemoryMiddleware } from "@mubit-ai/ai-sdk";
const model = wrapLanguageModel({
model: openai("gpt-4o"),
middleware: mubitMemoryMiddleware({
apiKey: "mbt_...",
sessionId: "session-1",
}),
});
// All generateText/streamText calls through this model
// automatically get lessons injected + interactions captured
const { text } = await generateText({ model, prompt: "Hello" });How it works
The middleware has two hooks:
transformParams— Before each LLM call, fetches relevant lessons from MuBit and injects them into the system promptwrapGenerate— After each LLM call, captures the interaction and ingests it to MuBit (fire-and-forget)
Options
| Option | Default | Description |
| --- | --- | --- |
| apiKey | MUBIT_API_KEY | MuBit API key |
| endpoint | MUBIT_ENDPOINT / http://127.0.0.1:3000 | MuBit endpoint URL |
| sessionId | "default" | Session/run ID for scoping memory |
| userId | "" | User ID for scoping memory |
| agentId | "ai-sdk" | Agent ID for attribution |
| maxTokenBudget | 2048 | Token budget for context retrieval |
| entryTypes | server default | Memory entry types to retrieve |
| sections | server default | Context sections to include |
| injectLessons | true | Whether to inject lessons before calls |
| captureInteractions | true | Whether to capture interactions after calls |
| failOpen | true | Proceed without lessons on error |
| mubitClient | auto-created | Pre-configured MuBit client |
Features
- TTL-bounded in-memory cache (30s, 100 entries) for context retrieval
- Fail-open by default — LLM calls proceed even if MuBit is unreachable
- Fire-and-forget ingestion — doesn't block on capture
- Compatible with
generateText,streamText, and any AI SDK model
Development
node --test test/**/*.test.jsLicense
Apache-2.0
