Logo di Realtime

Realtime

Organizzazione
butterbase-ai
realtime

Use when enabling WebSocket subscriptions for live database changes, presence/multiplayer state, or when debugging clients that connect but receive no events

Panoramica

Pubblicato dabutterbase-ai
Repositorybutterbase-skills
Nome della skillrealtime
Stelle
535
Fork
42
File inclusi
Solo istruzioni
LicenzaMIT
Link
  • Istruzioni in Markdown

    Un file SKILL.md che il modello carica quando serve, consumando token solo quando una richiesta è effettivamente pertinente.

  • Funziona con qualsiasi LLM

    Le skill IA sono in semplice Markdown, non in codice specifico di un fornitore, quindi funzionano con GPT, Claude, Gemini, Grok o un modello locale.

  • Tutto nelle istruzioni

    Tutto ciò che serve al modello è nelle istruzioni: nessun file aggiuntivo da sincronizzare.

  • Open source

    Pubblicata da butterbase-ai su GitHub. Leggi i sorgenti prima di installarla.

Installazione

Installa la skill IA Realtime in TypingMind per usarla con qualsiasi LLM, oppure copiala in un altro agente in grado di leggere SKILL.md.

1

Installa in TypingMind

TypingMind installa una skill direttamente dalla sua cartella GitHub: legge SKILL.md, raccoglie i file delle risorse e salva il risultato in locale.

  1. Apri l'app e vai su Plugin → Skill.
  2. Scegli "Installa da GitHub".
  3. Incolla l'URL della cartella della skill riportato qui sotto e conferma.
    https://github.com/butterbase-ai/butterbase-skills/tree/main/skills/realtime
  4. Attiva la skill in ogni chat in cui vuoi averla a disposizione.
Plugin → Skill → Aggiungi skill → Da URL GitHub, poi incolla l'URL della cartella e premi Continua.
2

Installa in un altro agente

Qualsiasi agente che legge il formato Agent Skills può usare questa skill: copia la cartella della skill nella directory delle skill di quell'agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/butterbase-ai/butterbase-skills.git /tmp/butterbase-skills
mkdir -p .claude/skills
cp -r /tmp/butterbase-skills/skills/realtime .claude/skills/realtime
Dopo la copia, riavvia Claude Code per caricare la nuova skill.

Usala in TypingMind

Attiva Realtime in qualsiasi chat di TypingMind e al resto pensa il modello. Il nome e la descrizione della skill sono nel prompt di sistema e, non appena arriva una richiesta pertinente, il modello carica da solo le istruzioni complete: non devi mai richiamarla manualmente e non consuma token finché non viene effettivamente usata.

Il modello carica automaticamente Realtime non appena riceve una richiesta pertinente.

Funziona con qualsiasi modello IA

Le skill IA sono semplici istruzioni in Markdown, non codice specifico di un fornitore, quindi Realtime non è vincolata al modello per cui è stata scritta. Installala una sola volta in TypingMind e usala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modello locale che esegui tu, sempre con le tue chiavi API.

  • Caricata solo quando serve

    Il prompt di sistema contiene solo il nome e la descrizione. Le istruzioni vengono recuperate alla prima richiesta pertinente, quindi una skill inutilizzata non costa nulla.

  • Cambia modello durante la chat

    Poiché la skill è composta da istruzioni e non da codice, continua a funzionare anche se cambi modello: il nuovo modello legge lo stesso file SKILL.md.

Istruzioni della skill

Questo è il contenuto di SKILL.md che il modello carica. Leggilo prima dell'installazione: una skill è un insieme di istruzioni che il tuo modello seguirà.

Butterbase Realtime

Live database change notifications over WebSocket, with per-row RLS enforcement. Once a table is enabled, INSERT/UPDATE/DELETE events stream to subscribed clients filtered by the same RLS policies that gate reads.

One tool: manage_realtime with two actions: configure and get.


1. The mental model

Postgres (data plane)              Control API                       Browser
─────────────────────              ────────────                      ────────
INSERT/UPDATE/DELETE  ──trigger──► realtime.changes  ──WAL listener─► WebSocket ──► client
                                          │
                                          └── RLS check per (role, user) ──► filter rows

When you configure a table:

  1. A Postgres trigger is installed → writes every change to realtime.changes.
  2. A LISTEN connection in RealtimeManager reads those changes.
  3. For each connected client, the change is RLS-checked as that user before broadcasting.
  4. Clients only receive events for rows they could read with a regular SELECT.

2. Prerequisites

Before calling configure, the table must:

  1. Exist. Run manage_schema (action: "apply") first. Realtime won't auto-create it.
  2. Have RLS configured (if you care about isolation). Realtime respects whatever policies exist via manage_rls. No policies = all events flow to all users of that role. This is the #1 silent leak.
  3. Have a primary key. RLS checks query by PK. Tables without one can't be realtime-enabled cleanly.

3. Configure tables

js
manage_realtime({
  app_id: "app_abc123",
  action: "configure",
  tables: ["messages", "presence", "documents"]
})
// → [{ table: "messages", status: "enabled" }, ...]
  • Idempotent — already-enabled tables are skipped.
  • All three events (INSERT / UPDATE / DELETE) are enabled together; per-event filtering happens client-side via subscription filter.
  • Validation: every named table must exist or you get VALIDATION_TABLE_NOT_FOUND.

Inspect current state

js
manage_realtime({ app_id: "app_abc123", action: "get" })
// → {
//     tables: [{ table_name, enabled, trigger_installed, drift, created_at, updated_at }, ...],
//     active_connection: true,
//     websocket_url: "wss://api.butterbase.dev/v1/app_abc123/realtime"
//   }

drift: true means the control-plane config says enabled but the data-plane trigger is missing — typically after a schema migration that dropped/recreated the table. Re-run configure to repair.


4. Connect from a client

wss://api.butterbase.dev/v1/{app_id}/realtime?token={JWT_or_API_KEY}

Browsers can't set custom headers on WebSocket upgrade, so the JWT goes in the query string. Server clients can use Authorization: Bearer ... instead.

js
const ws = new WebSocket(
  `wss://api.butterbase.dev/v1/${appId}/realtime?token=${userJwt}`
);

ws.onopen = () => {
  ws.send(JSON.stringify({ type: "subscribe", table: "messages" }));
};

ws.onmessage = (e) => {
  const msg = JSON.parse(e.data);
  if (msg.type === "change") handleChange(msg);  // { type, table, op, record, old_record, timestamp }
};

The Butterbase SDK wraps this:

ts
const realtime = client.realtime(appId, userJwt);
realtime.subscribe("messages", (change) => console.log(change.op, change.record));

Welcome and protocol

On connect, the server sends:

json
{ "type": "connected", "app_id": "app_abc123", "role": "butterbase_user" }

Then a heartbeat every 30s:

json
{ "type": "heartbeat", "timestamp": "..." }

Client → server messages

TypeBodyPurpose
subscribe{ table, filter? }Subscribe to changes; optional client-side filter { col: value }
unsubscribe{ table }Stop receiving
presence_track{ metadata }Announce yourself with arbitrary metadata (cursor, status)
event{ event, payload }Trigger a function with trigger: { type: "websocket", config: { event } }

Server → client messages

TypeBody
change{ table, op: "INSERT"|"UPDATE"|"DELETE", record, old_record, timestamp }
presence_state{ clients: [{ client_id, user_id, metadata }] }
heartbeat{ timestamp }

5. RLS enforcement (the critical pitfall)

For each broadcast, the server runs (roughly):

sql
SET LOCAL ROLE butterbase_user;
SET LOCAL request.jwt.claim.sub = '{user_id}';
SELECT 1 FROM "{table}" WHERE "{pk}" = {record_pk} LIMIT 1;

If the row is not visible under RLS, the change is silently dropped for that client. There is no error.

Common consequences:

  • Client connects, sees connected, subscribes — but receives no events. → RLS too restrictive (or no policies at all + access mode authenticated).
  • Client receives some events but not others. → RLS works for those rows; others are filtered out (often correct).
  • Service key clients see everything. → Service bypasses RLS. Don't use this to "verify realtime works" if testing user-scoped behaviour.

Always test with a real end-user JWT, not the service key.

Anonymous clients

If manage_app access mode is authenticated, anonymous WebSocket connections are rejected with close code 1008 (Policy Violation). To allow anon, the app must be in public mode AND the table must have a permissive policy for butterbase_anon.


6. Connection lifecycle

Close codeMeaning
1008App requires authentication, no token provided
1013 (try again later)Plan limit hit (maxRealtimeListenersPerApp) — upgrade
1013 ("Realtime disabled by plan")Free / starter tiers may have realtime off entirely
Normal closeHeartbeat missed, client disconnected, or server eviction

The server caches table primary keys for 60s and batches RLS checks per (role, user) group, so connection cost is amortised.


7. Common patterns

Live chat

  1. manage_schema apply with a messages table (id, room_id, user_id, body, created_at).
  2. manage_rls create_user_isolation with user_column: "user_id" plus a custom policy that allows reading messages where room_id IN (SELECT room_id FROM members WHERE user_id = current_user_id()).
  3. manage_realtime configure with tables: ["messages"].
  4. Client connects, subscribes to messages, optionally filters { room_id: "..." }.

Live dashboard / activity feed

  1. Add a notifications table with user_id.
  2. RLS create_user_isolation so each user only sees their own.
  3. Realtime configure → notifications stream straight to the right user, no extra filtering needed.

Multiplayer cursor sharing

Use presence, not table changes:

js
ws.send(JSON.stringify({
  type: "presence_track",
  metadata: { cursor: { x: 100, y: 50 }, color: "#f00" }
}));

Other clients receive presence_state updates with everyone's metadata. No DB writes.

Debugging "client connects but no events"

  1. Confirm trigger installed: manage_realtime get → trigger_installed: true, drift: false.
  2. Confirm RLS allows the user to SELECT the row: select_rows with as_role: "user", as_user: "<id>" → does the row appear?
  3. If yes to both and still no events: check for plan limits in close codes; check that the change actually happened in Postgres (look at realtime.changes).

8. Anti-patterns

Don'tDo
Enable realtime before configuring RLSSet up policies first; otherwise events leak across users
Use a service key from the frontend "to make it work"Service bypasses RLS — ship-stopping leak. Use end-user JWTs.
Trust client-side filter for securityfilter is just a convenience to reduce client-side work; RLS is the security boundary
Hold thousands of subscriptions per clientOne connection, one or two subscribed tables — the server handles fan-out
Re-call configure in a loop on every page loadIt's idempotent but each call still touches the DB. Configure once during app setup.
Send custom auth headers from the browserWebSocket API can't set them — pass the JWT as ?token= query param

If a docs/butterbase/00-state.md exists in the working directory, prefer invoking via /butterbase-skills:journey-realtime so the journey orchestrator stays in sync.

Domande frequenti

Cosa fa la skill IA Realtime?

Use when enabling WebSocket subscriptions for live database changes, presence/multiplayer state, or when debugging clients that connect but receive no events

Perché usare Realtime su TypingMind?

Perché la installi una volta e la usi con qualsiasi modello. Realtime è scritta in semplice Markdown anziché in codice specifico di un fornitore, quindi la stessa skill funziona con GPT-5, Claude, Gemini, Grok o un modello locale, e puoi cambiare modello durante la chat senza che la skill smetta di funzionare. TypingMind usa le tue chiavi API, quindi paghi direttamente i fornitori anziché un abbonamento per posto utente, e le tue skill e chat restano nel tuo spazio di archiviazione.

Come installo Realtime in TypingMind?

Apri Plugin → Skill → Installa da GitHub in TypingMind e incolla https://github.com/butterbase-ai/butterbase-skills/tree/main/skills/realtime. TypingMind legge il file SKILL.md e installa la skill, che puoi abilitare per ogni singola chat.

Quali modelli IA possono usare Realtime?

Qualsiasi modello che colleghi a TypingMind. Le skill IA sono semplici istruzioni in Markdown anziché codice specifico di un fornitore, quindi GPT, Claude, Gemini, Grok e i modelli locali possono tutti caricare questa skill quando una richiesta corrisponde al suo scopo.

Quanti modelli IA posso usare con Realtime?

Quanti ne vuoi. Se un modello supporta le skill, puoi usarlo con Realtime: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e molti altri, tutti su TypingMind con le tue chiavi API.

La skill IA Realtime è gratuita?

Sì. È pubblicata su GitHub da butterbase-ai con licenza MIT. Paghi solo il tuo fornitore IA per i token che usi.

Cosa sono le skill IA?

Una skill IA è un pacchetto di istruzioni riutilizzabili che insegna a un modello IA come svolgere un'attività specifica. Segue il formato aperto Agent Skills: un file SKILL.md con un nome e una descrizione, più eventuali script, template o file di riferimento di cui il modello potrebbe aver bisogno. Il modello legge le istruzioni solo quando la tua richiesta corrisponde alla skill, quindi una skill installata non comporta costi finché non viene usata.

In cosa si differenziano le skill IA dai plugin o dai server MCP?

Un plugin o un server MCP fornisce a un modello nuovi strumenti da richiamare: codice che viene eseguito da qualche parte e restituisce un risultato. Una skill IA, invece, fornisce al modello conoscenze e procedure: come affrontare un'attività, quali passaggi seguire e quali caratteristiche deve avere un buon output. Le skill sono semplici istruzioni in Markdown, quindi non richiedono server, chiavi API né ambienti di esecuzione e funzionano con qualsiasi modello.

Elenco completo

Crea subito il tuo spazio di lavoro AI

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇