fleet-memory/hindsight-integrations/chat
Derek Bouius 3b9d2db091
security: bump vite across integrations (high CVE fix) (#913)
* security: bump vite across integrations to patched versions

Fixes Dependabot alerts for vite transitive dev dependency:
- GHSA-v2wj-q39q-566r (high): server.fs.deny bypass with queries
- GHSA-p9ff-h696-f583 (high): related vite server vulnerability

Adds a `vite` entry to the npm `overrides` in each integration's
package.json to force the patched version (>=8.0.5). To make this
possible in ai-sdk, chat, and openclaw — which pinned vitest ^4.0.18
whose vite peer is `^6.0.0 || ^7.0.0` — the minor-compatible bump
vitest ^4.0.18 -> ^4.1.2 is also included. vitest 4.1.x supports
vite 8.x (peer: ^6 || ^7 || ^8), so all six integrations converge on
vite 8.x consistently.

paperclip had no overrides block; one was added.

Verified locally: `npm ci && npx vitest run` passes in all six
integrations (ai-sdk 23, chat 28, openclaw 66, opencode 89, paperclip 27,
nemoclaw 36 tests).

* chore: regenerate hindsight-docs skill

Picks up FAQ and best-practice sections added in #905 that were not
regenerated at merge time, so that `verify-generated-files` passes
for this branch.
2026-04-08 09:11:21 +02:00
..
src feat: add Chat SDK integration for persistent chat bot memory (#442) 2026-02-26 17:07:47 +01:00
.gitignore feat: add Chat SDK integration for persistent chat bot memory (#442) 2026-02-26 17:07:47 +01:00
package-lock.json security: bump vite across integrations (high CVE fix) (#913) 2026-04-08 09:11:21 +02:00
package.json security: bump vite across integrations (high CVE fix) (#913) 2026-04-08 09:11:21 +02:00
README.md feat: add Chat SDK integration for persistent chat bot memory (#442) 2026-02-26 17:07:47 +01:00
tsconfig.json feat: add Chat SDK integration for persistent chat bot memory (#442) 2026-02-26 17:07:47 +01:00
tsup.config.ts feat(typescript-client): Deno compatibility (#607) 2026-03-18 14:25:35 +01:00
vitest.config.ts feat: add Chat SDK integration for persistent chat bot memory (#442) 2026-02-26 17:07:47 +01:00

@vectorize-io/hindsight-chat

Give your Vercel Chat SDK bots persistent, per-user memory with a single handler wrapper. Works with Slack, Discord, Teams, Google Chat, GitHub, and Linear.

Quick Start

npm install @vectorize-io/hindsight-chat
import { Chat } from 'chat';
import { HindsightClient } from '@vectorize-io/hindsight-client';
import { withHindsightChat } from '@vectorize-io/hindsight-chat';
import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';

const chat = new Chat({ connectors: [/* your connectors */] });
const hindsight = new HindsightClient({ apiKey: process.env.HINDSIGHT_API_KEY });

chat.onNewMention(
  withHindsightChat(
    {
      client: hindsight,
      bankId: (msg) => msg.author.userId, // per-user memory
    },
    async (thread, message, ctx) => {
      await thread.subscribe();

      const result = await streamText({
        model: openai('gpt-4o'),
        system: ctx.memoriesAsSystemPrompt(),
        messages: [{ role: 'user', content: message.text }],
      });

      // Stream the response
      const chunks: string[] = [];
      for await (const chunk of result.textStream) {
        chunks.push(chunk);
      }
      const fullResponse = chunks.join('');
      await thread.post(fullResponse);

      // Store the conversation in memory
      await ctx.retain(
        `User: ${message.text}\nAssistant: ${fullResponse}`
      );
    }
  )
);

Configuration

withHindsightChat(options, handler)

Returns a standard Chat SDK handler (thread, message) => Promise<void>.

Options

Option Type Default Description
client HindsightClient required Hindsight client instance
bankId string | (msg) => string required Memory bank ID or resolver function
recall.enabled boolean true Auto-recall memories before handler
recall.budget 'low' | 'mid' | 'high' 'mid' Processing budget for recall
recall.maxTokens number API default Max tokens for recall results
recall.types FactType[] all Filter to specific fact types
recall.includeEntities boolean true Include entity observations
retain.enabled boolean false Auto-retain inbound messages
retain.async boolean true Fire-and-forget retain
retain.tags string[] Tags for retained memories
retain.metadata Record<string, string> Metadata for retained memories

Context (ctx)

The third argument passed to your handler:

Property/Method Description
ctx.bankId Resolved bank ID
ctx.memories Array of recalled memories
ctx.entities Entity observations (or null)
ctx.memoriesAsSystemPrompt(options?) Format memories for LLM system prompt
ctx.retain(content, options?) Store content in memory
ctx.recall(query, options?) Search memories
ctx.reflect(query, options?) Reason over memories

Examples

Subscribed Message Handler

chat.onSubscribedMessage(
  withHindsightChat(
    {
      client: hindsight,
      bankId: (msg) => msg.author.userId,
      recall: { budget: 'high', maxTokens: 1000 },
    },
    async (thread, message, ctx) => {
      const result = await generateText({
        model: openai('gpt-4o'),
        system: ctx.memoriesAsSystemPrompt(),
        messages: [{ role: 'user', content: message.text }],
      });
      await thread.post(result.text);
    }
  )
);

Auto-Retain Inbound Messages

chat.onNewMention(
  withHindsightChat(
    {
      client: hindsight,
      bankId: (msg) => msg.author.userId,
      retain: { enabled: true, tags: ['slack', 'inbound'] },
    },
    async (thread, message, ctx) => {
      // Inbound message is already being retained automatically
      const result = await generateText({
        model: openai('gpt-4o'),
        system: ctx.memoriesAsSystemPrompt(),
        messages: [{ role: 'user', content: message.text }],
      });
      await thread.post(result.text);

      // Retain the assistant response separately
      await ctx.retain(`Assistant: ${result.text}`, {
        tags: ['slack', 'outbound'],
      });
    }
  )
);

Static Bank ID (Shared Memory)

// All users share the same memory bank
chat.onNewMention(
  withHindsightChat(
    { client: hindsight, bankId: 'shared-team-memory' },
    async (thread, message, ctx) => {
      // ...
    }
  )
);

Error Handling

Memory failures never break your bot. Auto-recall and auto-retain errors are logged as warnings and the handler continues with empty memories. Manual ctx.retain(), ctx.recall(), and ctx.reflect() calls propagate errors normally so you can handle them as needed.

License

MIT