@nandansai08/personal-ai 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +62 -0
- package/LICENSE +21 -0
- package/README.md +431 -0
- package/bin/personal-ai.js +4 -0
- package/config/mcp.json +3 -0
- package/config/models.yaml +23 -0
- package/config/persona.yaml +24 -0
- package/config/profiles.yaml +61 -0
- package/config/providers.yaml +22 -0
- package/dist/bootstrap.js +41 -0
- package/dist/core/assistant.js +170 -0
- package/dist/core/context.js +35 -0
- package/dist/core/events.js +45 -0
- package/dist/core/logger.js +67 -0
- package/dist/core/model-manager.js +101 -0
- package/dist/index.js +98 -0
- package/dist/mcp/client.js +3 -0
- package/dist/mcp/loader.js +3 -0
- package/dist/memory/embeddings.js +53 -0
- package/dist/memory/intent.js +113 -0
- package/dist/memory/long-term.js +312 -0
- package/dist/memory/short-term.js +63 -0
- package/dist/memory/types.js +5 -0
- package/dist/memory/vector-store.js +57 -0
- package/dist/persona/loader.js +56 -0
- package/dist/persona/profiles.js +51 -0
- package/dist/persona/system-prompt.js +99 -0
- package/dist/persona/types.js +22 -0
- package/dist/plugins/interface.js +1 -0
- package/dist/plugins/loader.js +3 -0
- package/dist/providers/anthropic.js +112 -0
- package/dist/providers/factory.js +40 -0
- package/dist/providers/gemini.js +86 -0
- package/dist/providers/groq.js +14 -0
- package/dist/providers/interface.js +2 -0
- package/dist/providers/lmstudio.js +13 -0
- package/dist/providers/metadata.js +96 -0
- package/dist/providers/mistral.js +133 -0
- package/dist/providers/ollama.js +265 -0
- package/dist/providers/openai-compatible.js +110 -0
- package/dist/providers/openai.js +14 -0
- package/dist/providers/together.js +14 -0
- package/dist/providers/utils.js +57 -0
- package/dist/tools/calculator.js +44 -0
- package/dist/tools/file-reader.js +101 -0
- package/dist/tools/memory-tool.js +58 -0
- package/dist/tools/notes.js +121 -0
- package/dist/tools/parser.js +119 -0
- package/dist/tools/registry.js +88 -0
- package/dist/tools/tasks.js +134 -0
- package/dist/tools/types.js +3 -0
- package/dist/tools/web-search.js +108 -0
- package/dist/ui/cli-helpers.js +153 -0
- package/dist/ui/cli.js +647 -0
- package/dist/ui/setup.js +196 -0
- package/dist/ui/web/client/index.html +2081 -0
- package/dist/ui/web/server.js +310 -0
- package/dist/voice/stt.js +3 -0
- package/dist/voice/tts.js +3 -0
- package/dist/web.js +63 -0
- package/package.json +68 -0
package/.env.example
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# PersonalAI — copy to .env and fill in what you use.
|
|
2
|
+
# PROVIDER=ollama # ollama | anthropic | openai | groq | gemini | mistral | lmstudio | together
|
|
3
|
+
|
|
4
|
+
# ── Ollama (local, no key needed) ───────────────────────────────────
|
|
5
|
+
OLLAMA_BASE_URL=http://localhost:11434
|
|
6
|
+
OLLAMA_MODEL=qwen2.5:14b
|
|
7
|
+
OLLAMA_CODER_MODEL=qwen2.5-coder:7b
|
|
8
|
+
OLLAMA_CHAT_MODEL=gemma3:12b
|
|
9
|
+
OLLAMA_NUM_CTX=8192
|
|
10
|
+
OLLAMA_NUM_PREDICT=1024
|
|
11
|
+
OLLAMA_TEMPERATURE=0.7
|
|
12
|
+
|
|
13
|
+
# ── Logging ──────────────────────────────────────────────────────────
|
|
14
|
+
# LOG_LEVEL=info # debug | info | warn | error (default: info)
|
|
15
|
+
|
|
16
|
+
# ── Anthropic ────────────────────────────────────────────────────────
|
|
17
|
+
# ANTHROPIC_API_KEY=sk-ant-...
|
|
18
|
+
# ANTHROPIC_MODEL=claude-sonnet-4-6
|
|
19
|
+
# ANTHROPIC_MAX_TOKENS=1024
|
|
20
|
+
|
|
21
|
+
# ── OpenAI ───────────────────────────────────────────────────────────
|
|
22
|
+
# OPENAI_API_KEY=sk-...
|
|
23
|
+
# OPENAI_MODEL=gpt-4o-mini
|
|
24
|
+
# OPENAI_BASE_URL=https://api.openai.com/v1
|
|
25
|
+
|
|
26
|
+
# ── Groq (fast inference, free tier) ─────────────────────────────────
|
|
27
|
+
# GROQ_API_KEY=gsk_...
|
|
28
|
+
# GROQ_MODEL=llama-3.3-70b-versatile
|
|
29
|
+
|
|
30
|
+
# ── Google Gemini ─────────────────────────────────────────────────────
|
|
31
|
+
# GEMINI_API_KEY=AIza...
|
|
32
|
+
# GEMINI_MODEL=gemini-2.0-flash
|
|
33
|
+
|
|
34
|
+
# ── Mistral ──────────────────────────────────────────────────────────
|
|
35
|
+
# MISTRAL_API_KEY=...
|
|
36
|
+
# MISTRAL_MODEL=mistral-large-latest
|
|
37
|
+
# MISTRAL_BASE_URL=https://api.mistral.ai/v1
|
|
38
|
+
|
|
39
|
+
# ── LM Studio (local, no key) ────────────────────────────────────────
|
|
40
|
+
# LMSTUDIO_BASE_URL=http://localhost:1234/v1
|
|
41
|
+
# LMSTUDIO_MODEL=local-model
|
|
42
|
+
|
|
43
|
+
# ── Together.ai ──────────────────────────────────────────────────────
|
|
44
|
+
# TOGETHER_API_KEY=...
|
|
45
|
+
# TOGETHER_MODEL=meta-llama/Llama-3.3-70B-Instruct-Turbo
|
|
46
|
+
|
|
47
|
+
# ── Web Search ───────────────────────────────────────────────────────
|
|
48
|
+
# Priority: Serper → Brave → DuckDuckGo
|
|
49
|
+
SERPER_API_KEY= # free 2500 searches, no card — https://serper.dev
|
|
50
|
+
# BRAVE_SEARCH_API_KEY= # free 2000/month — https://api.search.brave.com
|
|
51
|
+
|
|
52
|
+
# ── File reader tool security ──────────────────────────────────────────
|
|
53
|
+
# Comma-separated roots the file_reader tool may read from.
|
|
54
|
+
# Default: home directory + current working directory.
|
|
55
|
+
# Credential files (.env, SSH keys, .pem/.key) are always denied.
|
|
56
|
+
# FILE_READER_ROOTS=C:\Users\you\Documents,D:\projects
|
|
57
|
+
|
|
58
|
+
# ── Semantic memory (optional) ────────────────────────────────────────
|
|
59
|
+
# Local embeddings via Ollama. Pull the model first:
|
|
60
|
+
# ollama pull nomic-embed-text
|
|
61
|
+
# Falls back to keyword search automatically when unavailable.
|
|
62
|
+
# EMBEDDINGS_MODEL=nomic-embed-text
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 PersonalAI Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
# PersonalAI
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Nandansai08/personal-ai/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](package.json)
|
|
6
|
+
|
|
7
|
+
**Local-first AI assistant. Any provider. Runs on your machine.**
|
|
8
|
+
|
|
9
|
+
<!-- demo.gif: record with `npm start` → ask a question → /model switch → web UI. Keep under 15s. -->
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
No cloud lock-in. Switch between Ollama, Anthropic, OpenAI, Groq, Gemini, Mistral, LM Studio, or Together with one env var. Auto-routes tasks to the right model — qwen2.5:14b for tools/reasoning, gemma3:12b for chat/long context.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Providers
|
|
17
|
+
|
|
18
|
+
| Provider | Free Tier | Local | Tool Use | Speed |
|
|
19
|
+
|---|---|---|---|---|
|
|
20
|
+
| **Ollama** | Unlimited | Yes | Native | Fast (GPU-dependent) |
|
|
21
|
+
| **Anthropic** | Paid only | No | Native | Fast |
|
|
22
|
+
| **OpenAI** | Paid only | No | Native | Fast |
|
|
23
|
+
| **Groq** | 14k req/day | No | Native | Very fast |
|
|
24
|
+
| **Gemini** | 1500 req/day | No | Native | Fast |
|
|
25
|
+
| **Mistral** | Paid only | No | Native | Fast |
|
|
26
|
+
| **LM Studio** | Unlimited | Yes | No | Fast (GPU-dependent) |
|
|
27
|
+
| **Together.ai** | $1 credit | No | No | Fast |
|
|
28
|
+
|
|
29
|
+
See [docs/PROVIDERS.md](docs/PROVIDERS.md) for API key links, recommended models, and free tier details.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- **8 providers** — Ollama, Anthropic, OpenAI, Groq, Gemini, Mistral, LM Studio, Together; swap with `PROVIDER=groq`
|
|
36
|
+
- **Auto model routing** — ModelManager detects task type per message and hot-switches models (qwen2.5:14b for tools, gemma3:12b for chat)
|
|
37
|
+
- **4 agent profiles** — `assistant`, `coder`, `researcher`, `tutor`; each overrides system prompt, model, and tool priority
|
|
38
|
+
- **Persistent memory** — SQLite-backed long-term memory; facts, preferences, context, and episodic entries survive restarts
|
|
39
|
+
- **6 built-in tools** — web search (Serper → Brave → DuckDuckGo), notes, tasks, calculator, file reader, memory save
|
|
40
|
+
- **Streaming output** — token-by-token display with animated spinner and tool call progress indicators
|
|
41
|
+
- **Hot-reload config** — edit `persona.yaml` or `profiles.yaml` while running; changes apply to the next message
|
|
42
|
+
- **Observability** — every action emits typed events; daily log files at `~/.personal-ai/logs/`
|
|
43
|
+
- **Provider-blind core** — `src/core/`, `src/memory/`, `src/tools/`, `src/ui/` never import provider SDKs
|
|
44
|
+
- **No cloud required** — works entirely offline with Ollama and local models
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
**Fastest** (once published to npm):
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npx @nandansai08/personal-ai
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Or install globally:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm i -g @nandansai08/personal-ai
|
|
60
|
+
personal-ai
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The first-run wizard walks you through provider + persona setup; config is
|
|
64
|
+
stored in `~/.personal-ai/`.
|
|
65
|
+
|
|
66
|
+
**From source:**
|
|
67
|
+
|
|
68
|
+
**1. Clone and install**
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
git clone https://github.com/Nandansai08/personal-ai.git
|
|
72
|
+
cd personal-ai
|
|
73
|
+
npm install
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**2. Set up Ollama** (skip if using an API provider)
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Install from https://ollama.ai
|
|
80
|
+
ollama pull qwen2.5:14b
|
|
81
|
+
ollama pull gemma3:12b
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**3. Configure `.env`**
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
cp .env.example .env
|
|
88
|
+
# Edit .env — set PROVIDER and any required API keys
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**4. (Optional) Add a search key for web search**
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
# Primary: Serper.dev — free 2500 queries/month, no card required
|
|
95
|
+
# https://serper.dev → get key → SERPER_API_KEY=your_key
|
|
96
|
+
# Optional fallback: Brave Search → BRAVE_SEARCH_API_KEY=your_key
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**5. Customize your persona** (optional)
|
|
100
|
+
|
|
101
|
+
Edit `config/persona.yaml` — set your name, tone, and expertise areas.
|
|
102
|
+
|
|
103
|
+
**6. Build**
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm run build
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**7. Start**
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npm start
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**8. Try it**
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
[qwen2.5:14b] > who won today's cricket match?
|
|
119
|
+
[qwen2.5:14b] > /profile coder
|
|
120
|
+
[qwen2.5-coder:7b|coder] > write a debounce function in TypeScript
|
|
121
|
+
[qwen2.5-coder:7b|coder] > /model gemma3:12b
|
|
122
|
+
[gemma3:12b|coder] > explain async generators
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Environment Variables
|
|
128
|
+
|
|
129
|
+
Copy `.env.example` to `.env`. Only configure what you use.
|
|
130
|
+
|
|
131
|
+
### Core
|
|
132
|
+
|
|
133
|
+
| Variable | Default | Description |
|
|
134
|
+
|---|---|---|
|
|
135
|
+
| `PROVIDER` | `ollama` | Active provider: `ollama` \| `anthropic` \| `openai` \| `groq` \| `gemini` \| `mistral` \| `lmstudio` \| `together` |
|
|
136
|
+
| `LOG_LEVEL` | `info` | `debug` \| `info` \| `warn` \| `error` |
|
|
137
|
+
|
|
138
|
+
### Ollama
|
|
139
|
+
|
|
140
|
+
| Variable | Default | Description |
|
|
141
|
+
|---|---|---|
|
|
142
|
+
| `OLLAMA_BASE_URL` | `http://localhost:11434` | Ollama server URL |
|
|
143
|
+
| `OLLAMA_MODEL` | `qwen2.5:14b` | Default model (tools, reasoning) |
|
|
144
|
+
| `OLLAMA_CODER_MODEL` | `qwen2.5:14b` | Model for coding tasks (falls back to default) |
|
|
145
|
+
| `OLLAMA_CHAT_MODEL` | `gemma3:12b` | Model for chat, quick, long-context |
|
|
146
|
+
| `OLLAMA_NUM_CTX` | `2048` | Context window size |
|
|
147
|
+
| `OLLAMA_NUM_PREDICT` | `1024` | Max tokens per response |
|
|
148
|
+
| `OLLAMA_TEMPERATURE` | `0.7` | Sampling temperature |
|
|
149
|
+
|
|
150
|
+
### API Providers
|
|
151
|
+
|
|
152
|
+
| Variable | Description |
|
|
153
|
+
|---|---|
|
|
154
|
+
| `ANTHROPIC_API_KEY` | [console.anthropic.com](https://console.anthropic.com) |
|
|
155
|
+
| `ANTHROPIC_MODEL` | Default: `claude-sonnet-4-6` |
|
|
156
|
+
| `OPENAI_API_KEY` | [platform.openai.com/api-keys](https://platform.openai.com/api-keys) |
|
|
157
|
+
| `OPENAI_MODEL` | Default: `gpt-4o-mini` |
|
|
158
|
+
| `GROQ_API_KEY` | [console.groq.com/keys](https://console.groq.com/keys) |
|
|
159
|
+
| `GROQ_MODEL` | Default: `llama-3.3-70b-versatile` |
|
|
160
|
+
| `GEMINI_API_KEY` | [aistudio.google.com/app/apikey](https://aistudio.google.com/app/apikey) |
|
|
161
|
+
| `GEMINI_MODEL` | Default: `gemini-2.0-flash` |
|
|
162
|
+
| `MISTRAL_API_KEY` | [console.mistral.ai/api-keys](https://console.mistral.ai/api-keys/) |
|
|
163
|
+
| `MISTRAL_MODEL` | Default: `mistral-large-latest` |
|
|
164
|
+
| `LMSTUDIO_BASE_URL` | Default: `http://localhost:1234/v1` |
|
|
165
|
+
| `LMSTUDIO_MODEL` | Default: `local-model` |
|
|
166
|
+
| `TOGETHER_API_KEY` | [api.together.xyz/settings/api-keys](https://api.together.xyz/settings/api-keys) |
|
|
167
|
+
| `TOGETHER_MODEL` | Default: `meta-llama/Llama-3.3-70B-Instruct-Turbo` |
|
|
168
|
+
|
|
169
|
+
### Search
|
|
170
|
+
|
|
171
|
+
| Variable | Description |
|
|
172
|
+
|---|---|
|
|
173
|
+
| `SERPER_API_KEY` | Primary — [serper.dev](https://serper.dev), free 2500/month |
|
|
174
|
+
| `BRAVE_SEARCH_API_KEY` | Fallback — [api.search.brave.com](https://api.search.brave.com), free 2000/month |
|
|
175
|
+
|
|
176
|
+
Search order is Serper first, then Brave Search, then DuckDuckGo Instant Answers as a last resort.
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Persona (`config/persona.yaml`)
|
|
181
|
+
|
|
182
|
+
Controls the assistant's name, tone, and response style.
|
|
183
|
+
|
|
184
|
+
```yaml
|
|
185
|
+
name: "Aria" # Assistant name
|
|
186
|
+
user_name: "Nanda" # Your name — used in memory and greetings
|
|
187
|
+
|
|
188
|
+
tone: "casual, direct, like a knowledgeable friend"
|
|
189
|
+
|
|
190
|
+
expertise: # Topic areas
|
|
191
|
+
- software development
|
|
192
|
+
- cricket and sports
|
|
193
|
+
|
|
194
|
+
avoid: # Phrases to never say
|
|
195
|
+
- "Certainly!"
|
|
196
|
+
- "Great question!"
|
|
197
|
+
|
|
198
|
+
custom_instructions: | # Appended verbatim to system prompt
|
|
199
|
+
Talk to Nanda like a friend, not a formal assistant.
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Changes hot-reload — no restart required.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Profiles (`config/profiles.yaml`)
|
|
207
|
+
|
|
208
|
+
Profiles override the system prompt, model, tool priority, and temperature.
|
|
209
|
+
|
|
210
|
+
| Profile | Command | Model | Best For |
|
|
211
|
+
|---|---|---|---|
|
|
212
|
+
| `assistant` | `/profile assistant` | auto-routed | General tasks, daily use |
|
|
213
|
+
| `coder` | `/coder` | qwen2.5:14b | Writing code, debugging, TypeScript |
|
|
214
|
+
| `researcher` | `/research` | gemma3:12b | Deep research, multi-angle analysis |
|
|
215
|
+
| `tutor` | `/tutor` | gemma3:12b | Step-by-step teaching, guided explanation |
|
|
216
|
+
|
|
217
|
+
Switch profile mid-session — takes effect on the next message.
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Slash Commands
|
|
222
|
+
|
|
223
|
+
| Command | Description |
|
|
224
|
+
|---|---|
|
|
225
|
+
| `/help` | Show all commands |
|
|
226
|
+
| `/exit` | Quit |
|
|
227
|
+
| `/clear` | Clear conversation history |
|
|
228
|
+
| **Model** | |
|
|
229
|
+
| `/models` | List models available from the current provider |
|
|
230
|
+
| `/model` | Show current model routing (mode + task mappings) |
|
|
231
|
+
| `/model <name>` | Pin to a specific model (e.g. `/model gemma3:4b`) |
|
|
232
|
+
| `/model auto` | Resume automatic task-based model routing |
|
|
233
|
+
| `/switch` | Show provider-switch instructions |
|
|
234
|
+
| `/switch <provider>` | Show required `.env` settings for a provider switch |
|
|
235
|
+
| **Profiles** | |
|
|
236
|
+
| `/profile` | Show active profile |
|
|
237
|
+
| `/profile list` | List all profiles |
|
|
238
|
+
| `/profile <name>` | Switch to a profile by name |
|
|
239
|
+
| `/coder` | Switch to coder profile |
|
|
240
|
+
| `/research` | Switch to researcher profile |
|
|
241
|
+
| `/tutor` | Switch to tutor profile |
|
|
242
|
+
| **Memory** | |
|
|
243
|
+
| `/memory` | Show memory stats |
|
|
244
|
+
| `/memory list` | List 10 most recent memories |
|
|
245
|
+
| `/memory search <q>` | Search memories by keyword |
|
|
246
|
+
| `/memory save <type> <content>` | Save a memory (`fact` \| `preference` \| `context` \| `episodic`) |
|
|
247
|
+
| **Tools** | |
|
|
248
|
+
| `/tools` | List registered tools |
|
|
249
|
+
| **Debug** | |
|
|
250
|
+
| `/health` | Check provider connectivity and latency |
|
|
251
|
+
| `/logs` | Show path to today's log file |
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Architecture
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
259
|
+
│ src/index.ts │
|
|
260
|
+
│ loads config · wires provider + engine + CLI + tools │
|
|
261
|
+
└────────────────────────────┬────────────────────────────────────┘
|
|
262
|
+
│
|
|
263
|
+
┌──────────────────┼──────────────────────┐
|
|
264
|
+
▼ ▼ ▼
|
|
265
|
+
┌─────────────────┐ ┌──────────────────┐ ┌───────────────────┐
|
|
266
|
+
│ src/ui/cli.ts │ │ src/core/ │ │ src/providers/ │
|
|
267
|
+
│ │ │ │ │ │
|
|
268
|
+
│ readline CLI │ │ assistant.ts │ │ interface.ts │
|
|
269
|
+
│ /commands │ │ context.ts │ │ factory.ts │
|
|
270
|
+
│ spinner │ │ model-manager │ │ ollama.ts │
|
|
271
|
+
│ tool display │ │ events.ts │ │ anthropic.ts │
|
|
272
|
+
└────────┬────────┘ │ logger.ts │ │ openai-compat.ts │
|
|
273
|
+
│ └──────┬───────────┘ │ openai.ts │
|
|
274
|
+
│ │ │ groq.ts │
|
|
275
|
+
│ ▼ │ gemini.ts │
|
|
276
|
+
│ ┌─────────────────┐ │ mistral.ts │
|
|
277
|
+
│ │ src/memory/ │ │ lmstudio.ts │
|
|
278
|
+
│ │ │ │ together.ts │
|
|
279
|
+
│ │ long-term.ts │ └───────────────────┘
|
|
280
|
+
│ │ short-term.ts │
|
|
281
|
+
│ │ types.ts │ ┌───────────────────┐
|
|
282
|
+
│ └─────────────────┘ │ src/persona/ │
|
|
283
|
+
│ │ │
|
|
284
|
+
│ ┌─────────────────┐ │ profiles.ts │
|
|
285
|
+
└───────▶│ src/tools/ │ │ system-prompt.ts │
|
|
286
|
+
│ │ │ loader.ts │
|
|
287
|
+
│ registry.ts │ └───────────────────┘
|
|
288
|
+
│ parser.ts │
|
|
289
|
+
│ web-search.ts │
|
|
290
|
+
│ notes.ts │
|
|
291
|
+
│ tasks.ts │
|
|
292
|
+
│ calculator.ts │
|
|
293
|
+
│ file-reader.ts │
|
|
294
|
+
│ memory-tool.ts │
|
|
295
|
+
└─────────────────┘
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
**Golden rule:** `src/core/`, `src/memory/`, `src/tools/`, `src/ui/` never import provider SDKs. All SDK imports live in `src/providers/*.ts`.
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## Adding a Custom Provider
|
|
303
|
+
|
|
304
|
+
**1. Create `src/providers/myprovider.ts`:**
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
// MIT License — personal-ai
|
|
308
|
+
import type { LLMProvider, ChatRequest, ChatChunk, ProviderHealth } from './interface.js'
|
|
309
|
+
import { eventBus } from '../core/events.js'
|
|
310
|
+
|
|
311
|
+
// fallow-ignore-next-line unused-export
|
|
312
|
+
export class MyProvider implements LLMProvider {
|
|
313
|
+
readonly name = 'myprovider'
|
|
314
|
+
readonly supportsToolUse = false
|
|
315
|
+
readonly supportsStreaming = true
|
|
316
|
+
readonly model: string
|
|
317
|
+
|
|
318
|
+
constructor() {
|
|
319
|
+
this.model = process.env['MY_MODEL'] ?? 'my-model-name'
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async *chat(request: ChatRequest): AsyncGenerator<ChatChunk> {
|
|
323
|
+
const startMs = Date.now()
|
|
324
|
+
// call your API, yield chunks
|
|
325
|
+
yield { type: 'text', delta: 'hello' }
|
|
326
|
+
yield { type: 'done', usage: { input: 10, output: 5 } }
|
|
327
|
+
eventBus.emit('provider_latency', {
|
|
328
|
+
provider: 'myprovider', model: this.model, latencyMs: Date.now() - startMs,
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async healthCheck(): Promise<ProviderHealth> {
|
|
333
|
+
return { ok: true, latencyMs: 0, model: this.model }
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
**2. Register in `src/providers/factory.ts`:**
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
// Add to ProviderName union:
|
|
342
|
+
type ProviderName = '...' | 'myprovider'
|
|
343
|
+
|
|
344
|
+
// Add to PROVIDER_INFO:
|
|
345
|
+
myprovider: { envKey: 'MY_API_KEY', signupUrl: 'https://myprovider.com/keys' },
|
|
346
|
+
|
|
347
|
+
// Add to loadProvider():
|
|
348
|
+
case 'myprovider': return new (await import('./myprovider.js')).MyProvider()
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
**3.** Set `PROVIDER=myprovider` in `.env`.
|
|
352
|
+
|
|
353
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for the full provider checklist.
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## Web UI
|
|
358
|
+
|
|
359
|
+
Multi-view browser interface served by the same Node.js process. Split theme: dark nav sidebar, light main content, dark live-events panel.
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
# Standalone (recommended):
|
|
363
|
+
npm run web
|
|
364
|
+
# → http://localhost:3000
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
**Views:**
|
|
368
|
+
|
|
369
|
+
| View | Description |
|
|
370
|
+
|---|---|
|
|
371
|
+
| **Chat** | Streaming chat with message avatars, tool call badges, model-switch pills |
|
|
372
|
+
| **Code Workspace** | Editor with line numbers, file tabs, AI assistant panel |
|
|
373
|
+
| **Research** | Web search integration, memory panel, Knowledge Graph SVG |
|
|
374
|
+
| **Memory / Vault** | Vault Index — browse, search, export memories; Vector Topology graph |
|
|
375
|
+
| **Settings** | Provider cards with status badges, Hardware Context, task routing table |
|
|
376
|
+
|
|
377
|
+
**Live Events panel (right sidebar):**
|
|
378
|
+
- Real-time event stream: `model_selected`, `tool_called`, `tool_result`, `done`, `error`
|
|
379
|
+
- `STREAMING` badge while response is in-flight
|
|
380
|
+
- GPU UTIL card — live VRAM usage from Ollama `/api/ps`
|
|
381
|
+
- Tokens/sec and context-window fill bars
|
|
382
|
+
|
|
383
|
+
**Hardware Context (Settings → Hardware):**
|
|
384
|
+
- RAM usage bar from Node.js `os` module — no external tools needed
|
|
385
|
+
- CPU load average, thermal status (NOMINAL / WARM / HIGH), swap latency estimate
|
|
386
|
+
- Auto-refreshes every 30 s
|
|
387
|
+
|
|
388
|
+
**Task routing table** shows active model per task type with fallback provider column. Populated live from `/api/stats`.
|
|
389
|
+
|
|
390
|
+
**Performance optimizations:**
|
|
391
|
+
- `keep_alive: -1` keeps Ollama models in VRAM between requests
|
|
392
|
+
- Both models warm-up on server start — first message latency ~2–5 s instead of 30–50 s
|
|
393
|
+
- `OLLAMA_NUM_CTX=8192` default — lower to 4096/2048 on RAM-tight machines
|
|
394
|
+
|
|
395
|
+
Set `PORT=8080` in `.env` to change the port. `autoPort: true` in `.claude/launch.json` for dev.
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## Roadmap
|
|
400
|
+
|
|
401
|
+
| Version | Status | Goal |
|
|
402
|
+
|---|---|---|
|
|
403
|
+
| v0.5 | Done | 8 providers, ModelManager auto-routing, 4 agent profiles |
|
|
404
|
+
| v0.6 | Done | Web UI — Express + WebSocket streaming chat in browser |
|
|
405
|
+
| v0.7 | Done | Setup wizard, `/cost` tracking, model-pin for all providers, friendly errors, session save |
|
|
406
|
+
| v0.8 | Done | Security hardening, semantic memory (local embeddings via Ollama), session save/load, npm packaging |
|
|
407
|
+
| v0.9 | Planned | MCP support — connect any MCP server over stdio |
|
|
408
|
+
| v1.0 | Planned | Plugin system — weather, GitHub, calendar plugins |
|
|
409
|
+
| v1.1 | Planned | Voice — STT + TTS + wake word |
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## Security
|
|
414
|
+
|
|
415
|
+
PersonalAI is local-first by design: the web UI binds to `127.0.0.1` only,
|
|
416
|
+
WebSocket connections are origin-checked, and the file-reader tool is
|
|
417
|
+
restricted to allowed roots with credential files always denied.
|
|
418
|
+
See [SECURITY.md](SECURITY.md) for the full security model and reporting policy.
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## Contributing
|
|
423
|
+
|
|
424
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) and [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
|
|
425
|
+
Changes are tracked in [CHANGELOG.md](CHANGELOG.md).
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
## License
|
|
430
|
+
|
|
431
|
+
MIT — see [LICENSE](LICENSE).
|
package/config/mcp.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Model routing table
|
|
2
|
+
routing:
|
|
3
|
+
tools: qwen2.5:14b
|
|
4
|
+
coding: qwen2.5-coder:7b
|
|
5
|
+
reasoning: qwen2.5:14b
|
|
6
|
+
chat: gemma3:12b
|
|
7
|
+
longcontext: gemma3:12b
|
|
8
|
+
quick: gemma3:12b
|
|
9
|
+
default: qwen2.5:14b
|
|
10
|
+
|
|
11
|
+
native_tool_prefixes:
|
|
12
|
+
- qwen2.5:
|
|
13
|
+
- qwen2.5-coder:
|
|
14
|
+
- llama3.1:
|
|
15
|
+
- llama3.2:
|
|
16
|
+
- mistral-nemo:
|
|
17
|
+
- mistral:
|
|
18
|
+
|
|
19
|
+
xml_fallback_prefixes:
|
|
20
|
+
- gemma3:
|
|
21
|
+
- gemma3n:
|
|
22
|
+
- phi4:
|
|
23
|
+
- phi3:
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: "Aria"
|
|
2
|
+
user_name: "Nandan Sai"
|
|
3
|
+
tone: "casual, direct, like a knowledgeable friend — not a customer support bot"
|
|
4
|
+
expertise:
|
|
5
|
+
- software development
|
|
6
|
+
- cricket and sports
|
|
7
|
+
- productivity
|
|
8
|
+
- general knowledge
|
|
9
|
+
avoid:
|
|
10
|
+
- "Certainly!"
|
|
11
|
+
- "Great question!"
|
|
12
|
+
- "If you want to..."
|
|
13
|
+
- "Feel free to..."
|
|
14
|
+
- "I hope this helps"
|
|
15
|
+
- "Keep an eye out for"
|
|
16
|
+
- excessive caveats
|
|
17
|
+
- formal sign-offs
|
|
18
|
+
custom_instructions: |
|
|
19
|
+
Talk to Nanda like a friend, not a formal assistant.
|
|
20
|
+
Be direct — skip the diplomatic padding.
|
|
21
|
+
When you don't know something exactly, say "not sure but probably X" and move on.
|
|
22
|
+
Don't suggest the user go look it up themselves — you already searched, give what you found.
|
|
23
|
+
Skip filler closings like "let me know if you need anything else".
|
|
24
|
+
Answers should feel like a WhatsApp reply, not an email.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
active: assistant
|
|
2
|
+
|
|
3
|
+
profiles:
|
|
4
|
+
assistant:
|
|
5
|
+
name: "Assistant"
|
|
6
|
+
description: "General purpose daily assistant"
|
|
7
|
+
system_addon: ""
|
|
8
|
+
preferred_model: ""
|
|
9
|
+
tools_priority:
|
|
10
|
+
- tasks
|
|
11
|
+
- notes
|
|
12
|
+
- web_search
|
|
13
|
+
- calculator
|
|
14
|
+
temperature: 0.7
|
|
15
|
+
|
|
16
|
+
coder:
|
|
17
|
+
name: "Coder"
|
|
18
|
+
description: "Software development specialist"
|
|
19
|
+
system_addon: |
|
|
20
|
+
You are in coding mode.
|
|
21
|
+
Always write complete, runnable code.
|
|
22
|
+
Include error handling and types.
|
|
23
|
+
Explain key decisions briefly.
|
|
24
|
+
Default language: TypeScript unless specified.
|
|
25
|
+
preferred_model: "qwen2.5:14b"
|
|
26
|
+
tools_priority:
|
|
27
|
+
- file_reader
|
|
28
|
+
- web_search
|
|
29
|
+
- calculator
|
|
30
|
+
temperature: 0.3
|
|
31
|
+
|
|
32
|
+
researcher:
|
|
33
|
+
name: "Researcher"
|
|
34
|
+
description: "Deep research and analysis"
|
|
35
|
+
system_addon: |
|
|
36
|
+
You are in research mode.
|
|
37
|
+
Search multiple angles before concluding.
|
|
38
|
+
Cite sources when available.
|
|
39
|
+
Structure findings clearly with headers.
|
|
40
|
+
Acknowledge uncertainty explicitly.
|
|
41
|
+
preferred_model: "gemma3:12b"
|
|
42
|
+
tools_priority:
|
|
43
|
+
- web_search
|
|
44
|
+
- file_reader
|
|
45
|
+
- notes
|
|
46
|
+
temperature: 0.5
|
|
47
|
+
|
|
48
|
+
tutor:
|
|
49
|
+
name: "Tutor"
|
|
50
|
+
description: "Teaching and explanation mode"
|
|
51
|
+
system_addon: |
|
|
52
|
+
You are in tutor mode.
|
|
53
|
+
Explain step by step.
|
|
54
|
+
Use analogies and examples.
|
|
55
|
+
Check understanding after complex points.
|
|
56
|
+
Never give the full answer immediately — guide toward it.
|
|
57
|
+
preferred_model: "gemma3:12b"
|
|
58
|
+
tools_priority:
|
|
59
|
+
- calculator
|
|
60
|
+
- web_search
|
|
61
|
+
temperature: 0.8
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Provider configuration
|
|
2
|
+
default_provider: ollama
|
|
3
|
+
|
|
4
|
+
providers:
|
|
5
|
+
ollama:
|
|
6
|
+
base_url: "${OLLAMA_BASE_URL:-http://localhost:11434}"
|
|
7
|
+
model: "${OLLAMA_MODEL:-qwen2.5:14b}"
|
|
8
|
+
num_ctx: 8192
|
|
9
|
+
temperature: 0.7
|
|
10
|
+
|
|
11
|
+
anthropic:
|
|
12
|
+
api_key: "${ANTHROPIC_API_KEY}"
|
|
13
|
+
default_model: claude-sonnet-4-6
|
|
14
|
+
|
|
15
|
+
openai:
|
|
16
|
+
api_key: "${OPENAI_API_KEY}"
|
|
17
|
+
base_url: "${OPENAI_BASE_URL:-https://api.openai.com/v1}"
|
|
18
|
+
default_model: gpt-4o-mini
|
|
19
|
+
|
|
20
|
+
groq:
|
|
21
|
+
api_key: "${GROQ_API_KEY}"
|
|
22
|
+
default_model: llama-3.1-8b-instant
|