Pick where you build. Copy the prompt. Paste it into your AI builder's chat. It edits the code for you. No terminal needed (if you have one, there's a faster path further down).
The prompt defaults to standard mode: full prompts, completions, tool args, and reasoning text — with emails, phone numbers, SSNs, card-shaped numbers, JWTs, and provider API keys regex-scrubbed before egress, then scrubbed again server-side. Need zero text off-machine? Flip to redact: "metadata-only". Full data-handling story: /privacy.
Open your Lovable project, click the chat with the AI, paste the prompt below.
I'd like to add lightweight observability to a side-project AI app I'm working on. Heads-up before you start: the package is brand-new and low-adoption — first published 2026-05-01 — so this is for a non-critical project, not anything in production. If my code doesn't actually have an AI SDK call to instrument yet, please tell me and skip the install.
Important framework note: this project runs on **TanStack Start (React 19 + Vite)**, not Next.js. The streamText / generateText call is in a TanStack server file route (typically `src/routes/api/chat.ts` or similar), not `app/api/chat/route.ts`. Find the actual file by searching the repo for `streamText` or `generateText` — that's where the wrap goes. The @pisama/sdk `observe()` helper works identically on TanStack Start since it operates on the Vercel AI SDK's model object, which is framework-agnostic.
The package is @pisama/sdk. It's a Vercel AI SDK middleware that streams trace metadata about my agent's calls to a dashboard so I can see when the agent loops, hallucinates, or burns through tokens. Public refs:
- npm: https://www.npmjs.com/package/@pisama/sdk
- repo: https://github.com/tn-pisama/whoopsie
- privacy / data handling: https://whoopsie.dev/privacy
- license: MIT
For first install I want full traces with PII scrubbed — `standard` mode. The SDK ships my prompt, the model's completion, tool args/results, and reasoning text (when the model emits it: o1, Claude extended thinking, Gemini thinking). Before any of that leaves my app, the SDK replaces common PII patterns — emails, phone numbers, SSNs, card-shaped numbers, JWTs, and OpenAI/Anthropic/AWS/GitHub/Slack-shaped API keys — with placeholders like `[email]`. The server then re-runs the same scrub before persisting. Token counts, model name, finish reason, timing, and detector verdicts also come along. If my prompts may contain anything that can't leave the box at all, I'll switch to `redact: "metadata-only"` instead — that ships token counts and detector verdicts and nothing else.
**Use the `observe()` helper. It's a single function call — do not write your own `wrapLanguageModel` pattern.** This matters because past installs failed silently when AI agents reconstructed the wrap incorrectly. The correct usage is exactly:
```ts
import { observe } from "@pisama/sdk";
// before:
// model: openai("gpt-4o"),
// after — wrap whatever model is currently there:
const model = observe(openai("gpt-4o"), { redact: "standard" });
```
That's it. Do not import `wrapLanguageModel` from "ai". Do not call `whoopsieMiddleware(...)` directly. Do not pass the middleware as an option — `observe(model, opts)` returns the wrapped model.
**Vercel AI SDK v6 gotchas (very common ai@5 → ai@6 mistakes):**
- The chat route must end with `return result.toUIMessageStreamResponse()` — `toDataStreamResponse()` was removed in v6.
- `convertToModelMessages` is **async** in `ai@6.0.x` — it returns `Promise<ModelMessage[]>`, not `ModelMessage[]`. Await it before passing into `streamText`:
```ts
const modelMessages = await convertToModelMessages(messages);
const result = streamText({ model, messages: modelMessages });
```
If you skip the `await`, TypeScript errors with `Type 'Promise<ModelMessage[]>' is missing the following properties from type 'ModelMessage[]'`. The React `useChat` hook posts UIMessages with `parts` arrays; `streamText` only accepts ModelMessages, so the conversion is required.
- `@pisama/sdk` ≥ 0.5 wraps a `LanguageModelV3` (the spec shipped by `ai@6`). If your project still has `@ai-sdk/openai@^2` (or any provider on the V2 spec), `next build` errors with `Type '"v2"' is not assignable to type '"v3"'` on the `observe()` call site. Fix by upgrading the provider: `pnpm add @ai-sdk/openai@^3` (or the equivalent for npm/yarn/bun, and the matching v3 release for `@ai-sdk/anthropic`, `@ai-sdk/google`, etc.). Verified 2026-05-12 against a fresh Next.js 16 + ai@6.0.180 + @ai-sdk/openai@3.0.63 install.
- On the React side, `useChat` no longer returns `{ input, handleInputChange, handleSubmit }`. Use `{ messages, sendMessage, status } = useChat()` and manage the input string yourself with `useState`. Call `sendMessage({ text: input })` on submit.
- The eager-flush serverless mode auto-detects Vercel (`VERCEL=1`), AWS Lambda, Netlify, Cloud Run, Cloudflare Workers, and Vercel Edge. You do not need to configure it; just confirm the install logs print `[whoopsie] enabled · project=ws_…` on first request.
Could you:
1. First: **find the existing `streamText` or `generateText` call by searching the repo for those exact strings**. Don't guess at file paths. If you don't find one, tell me and skip the install — there's nothing to instrument.
2. Edit `observe(<existing-model-expression>, { redact: "standard" })` **directly at the line where the model is passed to streamText/generateText**. Do not create a new file. Do not put the wrap in a separate `observability.ts` or `lib/` module. The wrap must be on the model expression that the actual streamText call uses, or it does nothing.
3. If the route or client is still on the ai@5 API (any of: `toDataStreamResponse()`, no `convertToModelMessages` call on the messages, `handleInputChange`/`handleSubmit` from `useChat`), migrate it to ai@6 per the gotchas above as part of the same change.
4. Tell me which file you changed and the exact line you changed.
I'll separately set two env vars in Lovable's Cloud tab → Secrets (click + next to Preview in the editor): `WHOOPSIE_PROJECT_ID=ws_N8rfa8oWc1V8ZFzR` (which dashboard your traces land on) and `WHOOPSIE_PLATFORM=lovable` (lets whoopsie tag this install as coming from lovable so we can spot when their AI builder's behavior changes and the install starts silently breaking — the slug is non-sensitive metadata, same level as the model name, and is disclosed on /privacy). The dashboard lives at https://whoopsie.dev/live/ws_N8rfa8oWc1V8ZFzR.
To verify the install is wired correctly (independent of whether your AI call actually fires yet), tell me to run `npx @pisama/cli verify` in a terminal. It posts a synthetic trace and confirms the round-trip — if it passes but real chats don't produce traces, the gap is in the code wrap. If it fails, the gap is in env vars or network egress. Either way it tells me where to look.
If you'd rather wait until the package has more adoption, suggest a more established alternative (Langfuse, Helicone, Sentry AI, OpenTelemetry) and I'll consider it.
Open this in another tab. Once Lovable confirms whoopsie is wired up and you hit your chat, the first event lands here.
project id: ws_N8rfa8oWc1V8ZFzR
After install, verify a trace lands
AI builders sometimes accept the install prompt confidently and then write the wrap incorrectly — silently. The cure is one quick check: send one chat messagein your running app and confirm a trace appears on your live dashboard within ~2 seconds. If nothing lands, the AI rewrote the wrap into something that doesn't invoke whoopsie's middleware. Re-paste the prompt and ask it to use the observe() helper exactly as written.
Lovable is a special case: it builds on TanStack Start (React 19 + Vite), not Next.js. The integration code path is different, and our tests have shown it's the most likely platform to silently no-op. Verify carefully there.
Or: skip the AI builder, install via terminal
If your AI builder refuses (some defended ones will, see above) or you just want to wire it yourself, the npm path works the same:
# in your Next.js + AI SDK project
npx -y @pisama/cli init
# or manually:
pnpm add @pisama/sdk
# then wrap your model in one call:
# import { observe } from "@pisama/sdk";
# const model = observe(openai("gpt-4o"), { redact: "metadata-only" });
Set WHOOPSIE_PROJECT_ID=ws_N8rfa8oWc1V8ZFzR in your .env.local.
Why this works (when it works)
Lovable, Replit, Bolt, and v0 all let you talk to an AI that edits your code. The prompt above tells that AI exactly what to do: install the SDK, find the model call, wrap it. The wrap is one line of TypeScript that catches loops, hallucinations, and cost spikes and streams them to your dashboard.
Some AI builders (Lovable in particular) defend against installing new packages with low adoption — that's a feature, not a bug. If yours refuses, the terminal path above still works.