@mutagent/vercel-ai
v0.1.2
Published
MutagenT integration for Vercel AI SDK - middleware for tracing AI streams
Maintainers
Readme
MutagenT Vercel AI
╔════════════════════════════════════════════════════════════════════════════════════════════╗
║ ║
║ ███╗ ███╗██╗ ██╗████████╗ █████╗ ██████╗ ███████╗███╗ ██╗████████╗ ║
║ ████╗ ████║██║ ██║╚══██╔══╝██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝ ║
║ ██╔████╔██║██║ ██║ ██║ ███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║ ║
║ ██║╚██╔╝██║██║ ██║ ██║ ██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║ ║
║ ██║ ╚═╝ ██║╚██████╔╝ ██║ ██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║ ║
║ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ║
║ ║
║ ██╗ ██╗███████╗██████╗ ██████╗███████╗██╗ █████╗ ██╗ ║
║ ██║ ██║██╔════╝██╔══██╗██╔════╝██╔════╝██║ ██╔══██╗██║ ║
║ ██║ ██║█████╗ ██████╔╝██║ █████╗ ██║ ███████║██║ ║
║ ╚██╗ ██╔╝██╔══╝ ██╔══██╗██║ ██╔══╝ ██║ ██╔══██║██║ ║
║ ╚████╔╝ ███████╗██║ ██║╚██████╗███████╗███████╗ ██║ ██║██║ ║
║ ╚═══╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝╚══════╝╚══════╝ ╚═╝ ╚═╝╚═╝ ║
║ ║
║ Vercel AI SDK Integration for AI-Native Observability. ║
║ ║
╚════════════════════════════════════════════════════════════════════════════════════════════╝Vercel AI SDK middleware for tracing AI generation and streaming to MutagenT.
Installation
npm install @mutagent/vercel-ai @mutagent/sdkPeer Dependencies
| Package | Version |
|---------|---------|
| ai | >=3.0.0 |
| @mutagent/sdk | ^0.1.0 |
Quick Start
import { createMutagentMiddleware } from '@mutagent/vercel-ai';
import { initTracing } from '@mutagent/sdk/tracing';
import { generateText, streamText, wrapLanguageModel } from 'ai';
import { openai } from '@ai-sdk/openai';
// Initialize tracing once at app startup
initTracing({ apiKey: process.env.MUTAGENT_API_KEY! });
// Wrap your model with the tracing middleware
const model = wrapLanguageModel({
model: openai('gpt-4'),
middleware: createMutagentMiddleware(),
});
// Non-streaming
const result = await generateText({ model, prompt: 'Hello!' });
// Streaming
const stream = await streamText({ model, prompt: 'Hello!' });
for await (const chunk of stream.textStream) {
process.stdout.write(chunk);
}API Reference
createMutagentMiddleware()
Returns a Vercel AI SDK middleware object with two hooks:
wrapGenerate-- Traces non-streaminggenerateTextcalls. Captures input params, output text, and token usage metrics.wrapStream-- Traces streamingstreamTextcalls. Accumulates text deltas and tool calls from the stream, then records the complete span on stream completion.
MutagentMiddleware
TypeScript type for the return value of createMutagentMiddleware().
License
MIT
