Smart Chat (Obsidian Plugin)

Talk to your notes inside Obsidian

> [!QUESTION] **Need conversational access to your vault?**

> Smart Chat lets you interact with an AI that understands your notes while staying fully local.

**Install Smart Chat now →**

Smart Chat adds a powerful chat interface to Obsidian using the [Smart Environment](https://github.com/brianpetro/jsbrains/tree/main/smart-environment) architecture. It allows you to chat with an AI model while dynamically pulling context from your Obsidian vault, creating new chat threads, injecting context or system prompts, and more.

How It Works

Smart Chat uses several underlying modules that work together:

The main runtime harness. It initializes modules, loads settings, and provides the app-wide `env` (environment).

A flexible data-layer for storing items (like threads and completions). It handles loading/saving, item relationships, and queue-based file operations.

A module that represents each AI request (prompt) and AI response as a 'SmartCompletion' item. Adapters automatically transform data before sending it to the AI (for example, inserting context or system messages).

A multi-adapter approach for hooking up to different AI chat providers (e.g., OpenAI, Anthropic, etc.). You choose which service to use via plugin settings.

Additional modules that handle tool calls (actions), context retrieval, and knowledge sources, respectively.

Technical Flow


sequenceDiagram
		participant U as User
		participant V as Smart Chat View
		participant A as Adapters
		participant M as Chat Model
		U->>V: type message
		V->>A: build completion
		A->>M: send request
		M-->>A: respond
		A-->>V: update thread
		V-->>U: render reply

Plugin Architecture

When you enable Smart Chat in Obsidian:

1. **`main.js`**

2. **`build_smart_env_config.js`**

3. **`src/collections/chats_threads.js`**

4. **`src/items/smart_chat_thread.js`**

5. **`src/components/`**

6. **`smart_chat.obsidian.js`**

Data Flow

1. **User types a new message** in the input box.

2. **A SmartCompletion** is created or updated for the conversation:

3. **The UI** updates to show the new messages and any context selection overlays.

Files You May Want to Explore

Entry point for the plugin. Registers the chat view and merges environment configs.

A static HTML reference for testing the chat UI in a browser environment without Obsidian.

Each sub-component for the chat UI: user messages, assistant replies, context selection, etc.

Data classes representing key objects in the plugin: `SmartChatThread` and `SmartAction`.

An example "action" that the AI can call to retrieve relevant notes from your vault.

Building and Installing

1. **Install Dependencies**

Run `npm install` in the `smart-chat-obsidian` directory. This plugin references local dependencies like `smart-collections` and `smart-completions`, so ensure they are linked or otherwise accessible.

2. **Build**

Run `npm run build`. This does two steps:

3. **Copy to Your Obsidian Vault's Plugins**

Copy the resulting `main.js`, `manifest.json`, and `styles.css` into a folder under `.obsidian/plugins/smart-chat/` in your vault.

4. **Enable**

In Obsidian settings, go to 'Community plugins' and enable 'Smart Chat'.

Usage

Settings

Adapters at a Glance

Injects your 'system_message' into the request.

Adds the user's message into the request.

Pulls in text from 'smart_contexts' if 'context_key' is set.

Gathers previous messages in the thread so the model sees the entire conversation.

If the model calls a function (tool call), it routes that to a 'SmartAction' in your environment.

Development Tips