supermemory/apps/sdk-playground
Dhravya 4ad5f0beb1
feat(sdk-playground): reflect SDK-owned memory block in debug view (#1533)
## Stack Context

Part 3 (top) of a 3-PR stack moving memory deduplication into the SDKs. See `sdk-dedup/tools-ts` for full context.

## What?

Update the SDK playground so its debug view reflects the SDK-owned memory block.

- Displays the current deduplicated `<supermemory>` replacement block produced by the SDK middleware, instead of the old browser-side "seen facts" delta.
- Adds a `memory-dedupe` helper and ignores local `*.tsbuildinfo`.

## Why?

The previous debug cards were misleading — they showed an incremental browser-filtered delta while the middleware actually re-injected the full profile. Now the visualization matches what the SDK really sends.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Playground-only visualization and chat gating changes; no production SDK or API behavior.
>
> **Overview**
> The playground **debug trace** now shows the **deduplicated memory block** the SDK middleware would inject (static → dynamic → search, mode-aware), instead of a misleading browser-side “new facts” delta. A new **`memory-dedupe`** helper mirrors `@supermemory/tools` middleware behavior and is applied when fetching container context and building middleware memory debug entries; the context preview card is relabeled to reflect that each turn **replaces** the prior `<supermemory>` block.
>
> **Chat UX:** messaging is enabled when API keys are configured on the **server** (`hasSupermemoryKey` / `hasOpenAiKey` from `/api/chat`), not only when keys are typed in the panel. The message input stays editable while waiting for text; Send still requires non-empty input.
>
> Also ignores `*.tsbuildinfo` in `.gitignore`.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ed15364eb3. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2026-09-01 06:10:37 +00:00
..
python feat(sdk-playground): reflect SDK-owned memory block in debug view (#1533) 2026-09-01 06:10:37 +00:00
src feat(sdk-playground): reflect SDK-owned memory block in debug view (#1533) 2026-09-01 06:10:37 +00:00
.env.example feat(sdk-playground): interactive SDK chat playground (#1437) 2026-09-01 06:10:36 +00:00
.gitignore feat(sdk-playground): interactive SDK chat playground (#1437) 2026-09-01 06:10:36 +00:00
next.config.ts feat(sdk-playground): interactive SDK chat playground (#1437) 2026-09-01 06:10:36 +00:00
package.json feat(sdk-playground): interactive SDK chat playground (#1437) 2026-09-01 06:10:36 +00:00
postcss.config.mjs feat(sdk-playground): interactive SDK chat playground (#1437) 2026-09-01 06:10:36 +00:00
README.md feat(sdk-playground): interactive SDK chat playground (#1437) 2026-09-01 06:10:36 +00:00
tsconfig.json feat(sdk-playground): interactive SDK chat playground (#1437) 2026-09-01 06:10:36 +00:00

SDK Agent Playground

Chat with a real agent and switch which Supermemory SDK integration powers it.

Warning

This is a local, single-user development tool. It makes real API calls, stores browser-entered keys only in memory unless you opt into tab-scoped sessionStorage, and exposes tools that can permanently delete documents. Use disposable development credentials and a test container; do not deploy it or point it at production data.

Integrations

SDK Style What happens
AI SDK + middleware automatic withSupermemory injects context + saves chat
OpenAI + middleware automatic same, via OpenAI client wrapper
AI SDK + tools explicit model calls 7 memory tools via generateText
OpenAI + tools explicit OpenAI function-calling loop
@supermemory/ai-sdk explicit re-export of tools/ai-sdk
Python OpenAI middleware automatic with_supermemory
Python OpenAI tools explicit SupermemoryTools loop
Python supermemory direct manual profile() + OpenAI + add()

Setup

Prerequisites: Bun 1.3.6, Python 3.11+, and uv. Portless is required only for the HTTPS development hostname; the direct localhost commands below work without it.

From the repository root:

bun install --frozen-lockfile

cp apps/sdk-playground/.env.example apps/sdk-playground/.env.local
# Required:
# SUPERMEMORY_API_KEY=...
# OPENAI_API_KEY=...

The playground scripts build @supermemory/tools first and @supermemory/ai-sdk second before starting, type-checking, or building the Next.js app. Development mode also watches both workspace packages.

Run

bun run --cwd apps/sdk-playground dev

Opens:

To run without Portless, use two terminals:

bun run --cwd apps/sdk-playground dev:next
bun run --cwd apps/sdk-playground dev:python

For a production-mode local smoke check, build first and then start. start runs both the built Next.js app and the Python server, and remains intended for local use only.

bun run --cwd apps/sdk-playground build
bun run --cwd apps/sdk-playground start

Try:

  • "Remember that I prefer oat milk in coffee"
  • "What do you know about my drink preferences?"
  • "Forget that I like tea" (tools mode)

Env

Variable Required
SUPERMEMORY_API_KEY yes
OPENAI_API_KEY yes
SUPERMEMORY_BASE_URL optional
MODEL_NAME optional (default gpt-4o-mini)
SDK_PLAYGROUND_PYTHON_URL optional (default http://127.0.0.1:8792)
SDK_PLAYGROUND_PYTHON_PORT optional (default 8792)
SDK_PLAYGROUND_ALLOW_ENV_KEYS optional; set true only when a trusted non-local hostname must use server env keys

Server environment keys are exposed to the playground routes only on loopback hosts and sdk.dev.supermemory.ai by default. Browser-provided keys remain request-scoped and are never copied into process-global environment variables.