@yesvara/svara 0.1.0 → 0.1.2
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/CONTRIBUTING.md +233 -0
- package/README.md +211 -23
- package/SvaraJS.png +0 -0
- package/dist/{chunk-FEA5KIJN.mjs → chunk-CCNWHBEI.mjs} +108 -27
- package/dist/chunk-GA7LHPOF.mjs +257 -0
- package/dist/cli/index.js +490 -4
- package/dist/cli/index.mjs +35 -3
- package/dist/db-PEMUBXAR.mjs +190 -0
- package/dist/index.d.mts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +454 -269
- package/dist/index.mjs +83 -239
- package/dist/{retriever-4QY667XF.mjs → retriever-JYOGHA4F.mjs} +2 -1
- package/package.json +27 -15
- package/src/cli/commands/db.ts +267 -0
- package/src/cli/index.ts +74 -4
- package/src/core/agent.ts +89 -8
- package/src/core/types.ts +14 -1
- package/src/database/schema.ts +31 -6
- package/src/rag/chunker.ts +1 -0
- package/src/rag/retriever.ts +146 -33
- package/svara@1.0.0 +0 -0
- package/test-rag.ts +20 -0
- package/tsx +0 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# Contributing to SvaraJS
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in contributing! We welcome all contributions—bug reports, feature requests, documentation improvements, and pull requests.
|
|
4
|
+
|
|
5
|
+
## Code of Conduct
|
|
6
|
+
|
|
7
|
+
Be respectful and constructive. We're building a framework for developers, so let's keep the community welcoming.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Getting Started
|
|
12
|
+
|
|
13
|
+
### 1. Clone & Setup
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/yogiswara92/svarajs.git
|
|
17
|
+
cd svara
|
|
18
|
+
nvm use 20 # or 22
|
|
19
|
+
npm install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. Development
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm run dev # Watch mode for TypeScript
|
|
26
|
+
npm run build # Build for production
|
|
27
|
+
npm run typecheck # Type checking
|
|
28
|
+
npm test # Run tests
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 3. Project Structure
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
src/
|
|
35
|
+
├── core/ # Agent, LLM, types
|
|
36
|
+
├── app/ # SvaraApp HTTP wrapper
|
|
37
|
+
├── channels/ # Web, Telegram, WhatsApp
|
|
38
|
+
├── rag/ # Document loading, chunking, retrieval
|
|
39
|
+
├── memory/ # Conversation history
|
|
40
|
+
├── tools/ # Tool definition & registry
|
|
41
|
+
├── database/ # SQLite wrapper
|
|
42
|
+
├── cli/ # CLI commands
|
|
43
|
+
└── types.ts # Public API types
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Reporting Issues
|
|
49
|
+
|
|
50
|
+
**Before opening an issue:**
|
|
51
|
+
- Check [existing issues](https://github.com/yogiswara92/svarajs/issues)
|
|
52
|
+
- Try the latest dev version: `npm run dev`
|
|
53
|
+
|
|
54
|
+
**When reporting, include:**
|
|
55
|
+
- Clear title + description
|
|
56
|
+
- Steps to reproduce
|
|
57
|
+
- Expected vs actual behavior
|
|
58
|
+
- Node version, OS, environment
|
|
59
|
+
- Code snippet (if applicable)
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Submitting PRs
|
|
64
|
+
|
|
65
|
+
### Before You Start
|
|
66
|
+
|
|
67
|
+
1. **Check existing PRs** to avoid duplicates
|
|
68
|
+
2. **Open an issue first** for major changes (discuss approach)
|
|
69
|
+
3. **Fork & create a branch:**
|
|
70
|
+
```bash
|
|
71
|
+
git checkout -b feature/your-feature-name
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### While Developing
|
|
75
|
+
|
|
76
|
+
- Follow **existing code style** (no strict linter, but be consistent)
|
|
77
|
+
- Keep changes **focused & minimal**
|
|
78
|
+
- Write clear commit messages (see below)
|
|
79
|
+
- Test locally: `npm run build && npm run typecheck`
|
|
80
|
+
|
|
81
|
+
### Before Submitting PR
|
|
82
|
+
|
|
83
|
+
1. **Run tests:**
|
|
84
|
+
```bash
|
|
85
|
+
npm test
|
|
86
|
+
npm run typecheck
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
2. **Update docs** if adding/changing public APIs
|
|
90
|
+
|
|
91
|
+
3. **Commit with clear messages:**
|
|
92
|
+
```bash
|
|
93
|
+
git commit -m "feat: add support for custom embeddings provider"
|
|
94
|
+
git commit -m "fix: resolve memory leak in vector store"
|
|
95
|
+
git commit -m "docs: improve RAG examples in README"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
4. **Push & open PR:**
|
|
99
|
+
```bash
|
|
100
|
+
git push origin feature/your-feature-name
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### PR Guidelines
|
|
104
|
+
|
|
105
|
+
- **Title:** Start with `feat:`, `fix:`, `docs:`, `refactor:`, etc.
|
|
106
|
+
- **Description:** What changed and why
|
|
107
|
+
- **Link issues:** "Closes #123" in description
|
|
108
|
+
- **Keep it focused:** One feature/fix per PR
|
|
109
|
+
- **Minimal dependencies:** Discuss before adding packages
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Code Style
|
|
114
|
+
|
|
115
|
+
We follow these patterns (not strict, but consistent):
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
// Imports
|
|
119
|
+
import { SvaraAgent } from '../core/agent.js';
|
|
120
|
+
import type { Tool } from '../types.js';
|
|
121
|
+
|
|
122
|
+
// Exports
|
|
123
|
+
export class MyClass { }
|
|
124
|
+
export type { MyType };
|
|
125
|
+
|
|
126
|
+
// Naming
|
|
127
|
+
const myVariable = 'value'; // camelCase
|
|
128
|
+
const MY_CONSTANT = 'VALUE'; // UPPER_SNAKE_CASE (rarely used)
|
|
129
|
+
class MyClass { } // PascalCase
|
|
130
|
+
|
|
131
|
+
// Comments
|
|
132
|
+
// Single line for brief explanation
|
|
133
|
+
/**
|
|
134
|
+
* Multi-line for public API documentation.
|
|
135
|
+
* Explain what it does, not how.
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
// Error handling
|
|
139
|
+
throw new Error('[@yesvara/svara] Clear error message');
|
|
140
|
+
|
|
141
|
+
// Async/await
|
|
142
|
+
async function load() {
|
|
143
|
+
try {
|
|
144
|
+
return await operation();
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error('[SvaraJS] Error message:', error);
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Testing
|
|
155
|
+
|
|
156
|
+
Currently minimal test suite. Before submitting:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npm run typecheck
|
|
160
|
+
npm run build
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
If adding features:
|
|
164
|
+
- Test locally with `npm run dev`
|
|
165
|
+
- Consider adding tests in `src/__tests__/`
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Commit Message Format
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
<type>: <subject>
|
|
173
|
+
|
|
174
|
+
<body (optional)>
|
|
175
|
+
|
|
176
|
+
<footer (optional)>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Types:**
|
|
180
|
+
- `feat:` - New feature
|
|
181
|
+
- `fix:` - Bug fix
|
|
182
|
+
- `docs:` - Documentation
|
|
183
|
+
- `refactor:` - Code restructuring (no behavior change)
|
|
184
|
+
- `perf:` - Performance improvement
|
|
185
|
+
- `test:` - Test-related
|
|
186
|
+
- `chore:` - Dependency updates, build config, etc.
|
|
187
|
+
|
|
188
|
+
**Examples:**
|
|
189
|
+
```
|
|
190
|
+
feat: add support for Groq API provider
|
|
191
|
+
|
|
192
|
+
- Auto-detect model from "groq-" prefix
|
|
193
|
+
- Support streaming responses
|
|
194
|
+
- Add tests for Groq integration
|
|
195
|
+
|
|
196
|
+
Closes #45
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
fix: resolve memory leak in vector store
|
|
201
|
+
|
|
202
|
+
The InMemoryVectorStore was not clearing old entries.
|
|
203
|
+
Now properly clears when adding > 10k entries.
|
|
204
|
+
|
|
205
|
+
Fixes #123
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Release Process
|
|
211
|
+
|
|
212
|
+
Maintainers only:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
npm version minor # or patch, major
|
|
216
|
+
npm publish
|
|
217
|
+
git push origin main --tags
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Questions?
|
|
223
|
+
|
|
224
|
+
- **Issues:** [GitHub Issues](https://github.com/yogiswara92/svarajs/issues)
|
|
225
|
+
- **Discussions:** [GitHub Discussions](https://github.com/yogiswara92/svarajs/discussions)
|
|
226
|
+
- **Email:** yogiswaragheartha@gmail.com / admin@yesvara.com
|
|
227
|
+
- **Website:** https://yesvara.com
|
|
228
|
+
- **Whatsapp:** [+6285171010456](https://wa.me/6285171010456)
|
|
229
|
+
- **LinkedIn:** [Yogiswara Gheartha](https://www.linkedin.com/in/igb-yogiswara-gheartha-st-mmt-969b6b117/)
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
Thanks for contributing to SvaraJS!
|
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
+
<img src="SvaraJS.png" alt="SvaraJS" width="400">
|
|
2
3
|
|
|
3
|
-
# @yesvara/svara
|
|
4
|
+
<!-- # @yesvara/svara -->
|
|
4
5
|
|
|
5
6
|
**Build AI agents in 15 lines. Ship to production.**
|
|
6
7
|
|
|
7
|
-
A batteries-included Node.js framework for building agentic AI backends
|
|
8
|
-
|
|
8
|
+
A batteries-included Node.js framework for building agentic AI backends.
|
|
9
|
+
Multi-channel, RAG-ready, and designed for developers who value simplicity.
|
|
9
10
|
|
|
10
11
|
[](https://www.npmjs.com/package/@yesvara/svara)
|
|
11
12
|
[](./LICENSE)
|
|
@@ -37,7 +38,7 @@ app.listen(3000);
|
|
|
37
38
|
```
|
|
38
39
|
|
|
39
40
|
That's it. No pipeline setup. No embedding boilerplate. No webhook configuration.
|
|
40
|
-
**Convention over configuration
|
|
41
|
+
**Convention over configuration (like Express, but for AI).**
|
|
41
42
|
|
|
42
43
|
---
|
|
43
44
|
|
|
@@ -45,13 +46,16 @@ That's it. No pipeline setup. No embedding boilerplate. No webhook configuration
|
|
|
45
46
|
|
|
46
47
|
| | |
|
|
47
48
|
|---|---|
|
|
48
|
-
| **Zero-config LLM** | Pass a model name
|
|
49
|
+
| **Zero-config LLM** | Pass a model name, provider is auto-detected |
|
|
49
50
|
| **Instant RAG** | Point to a folder, documents are indexed automatically |
|
|
50
51
|
| **Multi-channel** | WhatsApp, Telegram, and Web from one agent |
|
|
51
52
|
| **Tool calling** | Declarative tools with full TypeScript types |
|
|
52
53
|
| **Conversation memory** | Automatic per-session history, configurable window |
|
|
53
54
|
| **Express-compatible** | `agent.handler()` drops into any existing app |
|
|
54
|
-
| **Built-in database** |
|
|
55
|
+
| **Built-in database** | Persistent SQLite for users, sessions, RAG chunks, and state |
|
|
56
|
+
| **RAG per agent** | Each agent has isolated knowledge base, no cross-contamination |
|
|
57
|
+
| **RAG persistence** | Vector embeddings stored in SQLite, auto-dedup |
|
|
58
|
+
| **User tracking** | Auto-tracks users and sessions with timestamps |
|
|
55
59
|
| **CLI included** | `svara new`, `svara dev`, `svara build` |
|
|
56
60
|
|
|
57
61
|
---
|
|
@@ -101,17 +105,23 @@ npx tsx src/index.ts
|
|
|
101
105
|
```bash
|
|
102
106
|
curl -X POST http://localhost:3000/chat \
|
|
103
107
|
-H "Content-Type: application/json" \
|
|
104
|
-
-d '{
|
|
108
|
+
-d '{
|
|
109
|
+
"message": "Hello! What can you do?",
|
|
110
|
+
"userId": "user-1",
|
|
111
|
+
"sessionId": "user-1-session-1"
|
|
112
|
+
}'
|
|
105
113
|
```
|
|
106
114
|
|
|
107
115
|
```json
|
|
108
116
|
{
|
|
109
117
|
"response": "Hi! I'm Aria, your AI assistant...",
|
|
110
|
-
"sessionId": "user-1",
|
|
118
|
+
"sessionId": "user-1-session-1",
|
|
111
119
|
"usage": { "totalTokens": 142 }
|
|
112
120
|
}
|
|
113
121
|
```
|
|
114
122
|
|
|
123
|
+
The agent automatically tracks users and sessions in the SQLite database.
|
|
124
|
+
|
|
115
125
|
---
|
|
116
126
|
|
|
117
127
|
## Supported Models
|
|
@@ -143,13 +153,13 @@ The central class. Configure once, use everywhere.
|
|
|
143
153
|
```ts
|
|
144
154
|
const agent = new SvaraAgent({
|
|
145
155
|
name: 'Support Bot', // Display name (used in logs & system prompt)
|
|
146
|
-
model: 'gpt-4o-mini', // LLM model
|
|
147
|
-
systemPrompt: 'You are...', // Optional
|
|
148
|
-
knowledge: './docs', // Optional
|
|
149
|
-
memory: { window: 20 }, // Optional
|
|
150
|
-
tools: [myTool], // Optional
|
|
151
|
-
temperature: 0.7, // Optional
|
|
152
|
-
verbose: true, // Optional
|
|
156
|
+
model: 'gpt-4o-mini', // LLM model - provider auto-detected
|
|
157
|
+
systemPrompt: 'You are...', // Optional - sensible default based on name
|
|
158
|
+
knowledge: './docs', // Optional - folder/glob for RAG
|
|
159
|
+
memory: { window: 20 }, // Optional - conversation history window
|
|
160
|
+
tools: [myTool], // Optional - functions the agent can call
|
|
161
|
+
temperature: 0.7, // Optional - creativity (0–2)
|
|
162
|
+
verbose: true, // Optional - detailed logs
|
|
153
163
|
});
|
|
154
164
|
```
|
|
155
165
|
|
|
@@ -219,6 +229,122 @@ await agent.addKnowledge('./new-policy-2024.pdf');
|
|
|
219
229
|
|
|
220
230
|
Supported formats: **PDF, Markdown, TXT, DOCX, HTML, JSON**
|
|
221
231
|
|
|
232
|
+
**RAG Persistence & Per-Agent Isolation:**
|
|
233
|
+
|
|
234
|
+
Vector embeddings are automatically persisted to SQLite. Each agent has its own isolated knowledge base:
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
const supportBot = new SvaraAgent({
|
|
238
|
+
name: 'SupportBot',
|
|
239
|
+
model: 'gpt-4o-mini',
|
|
240
|
+
knowledge: './docs/support', // Knowledge base 1
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
const salesBot = new SvaraAgent({
|
|
244
|
+
name: 'SalesBot',
|
|
245
|
+
model: 'gpt-4o-mini',
|
|
246
|
+
knowledge: './docs/sales', // Knowledge base 2
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
await supportBot.start();
|
|
250
|
+
await salesBot.start();
|
|
251
|
+
|
|
252
|
+
// Both agents run simultaneously with isolated RAG:
|
|
253
|
+
// - SupportBot only searches in support docs
|
|
254
|
+
// - SalesBot only searches in sales docs
|
|
255
|
+
// - No cross-contamination, efficient storage
|
|
256
|
+
// - Embeddings persist across restarts
|
|
257
|
+
// - Duplicate content skipped per agent
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**How it works:**
|
|
261
|
+
- Documents are embedded and stored in SQLite with agent name
|
|
262
|
+
- Each agent queries only its own chunks
|
|
263
|
+
- Deduplication happens per agent (same content in different agents is OK)
|
|
264
|
+
- Perfect for multi-agent systems with different domains
|
|
265
|
+
|
|
266
|
+
**Accessing Retrieved Documents:**
|
|
267
|
+
|
|
268
|
+
The `/chat` endpoint returns `retrievedDocuments` showing which knowledge was used:
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
const response = await fetch('http://localhost:3000/chat', {
|
|
272
|
+
method: 'POST',
|
|
273
|
+
headers: { 'Content-Type': 'application/json' },
|
|
274
|
+
body: JSON.stringify({
|
|
275
|
+
message: 'What is the pricing?',
|
|
276
|
+
sessionId: 'user-123'
|
|
277
|
+
})
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
const result = await response.json();
|
|
281
|
+
// {
|
|
282
|
+
// response: "Our pricing starts at...",
|
|
283
|
+
// retrievedDocuments: [
|
|
284
|
+
// {
|
|
285
|
+
// source: "./docs/pricing.md",
|
|
286
|
+
// score: 0.89, // relevance (0-1)
|
|
287
|
+
// excerpt: "# Pricing\n\nOur plans start at..."
|
|
288
|
+
// },
|
|
289
|
+
// {
|
|
290
|
+
// source: "./docs/faq.md",
|
|
291
|
+
// score: 0.76,
|
|
292
|
+
// excerpt: "## Is there a free trial?\n\nYes, 14 days..."
|
|
293
|
+
// }
|
|
294
|
+
// ]
|
|
295
|
+
// }
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
The `retrievedDocuments` field shows:
|
|
299
|
+
- **source**: File path of the matching document
|
|
300
|
+
- **score**: Cosine similarity (0-1, higher = more relevant)
|
|
301
|
+
- **excerpt**: First 150 characters of the matched chunk
|
|
302
|
+
|
|
303
|
+
### User & Session Tracking
|
|
304
|
+
|
|
305
|
+
Every message automatically tracks the user and their session.
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
// Send message with userId and sessionId
|
|
309
|
+
const result = await agent.process('Help me with my order', {
|
|
310
|
+
userId: 'user-123',
|
|
311
|
+
sessionId: 'user-123-conversation-1'
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// Database tracks:
|
|
315
|
+
// - svara_users: user-123 (first_seen, last_seen, metadata)
|
|
316
|
+
// - svara_sessions: session details, linked to user-123
|
|
317
|
+
// - svara_messages: conversation history for this session
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Query user data:
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
import { SvaraDB } from '@yesvara/svara';
|
|
324
|
+
|
|
325
|
+
const db = new SvaraDB('./data/svara.db');
|
|
326
|
+
|
|
327
|
+
// Get all users
|
|
328
|
+
const users = db.query('SELECT * FROM svara_users');
|
|
329
|
+
|
|
330
|
+
// Get sessions for a user
|
|
331
|
+
const sessions = db.query(
|
|
332
|
+
'SELECT * FROM svara_sessions WHERE user_id = ?',
|
|
333
|
+
['user-123']
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
// Get chat history for a session
|
|
337
|
+
const messages = db.query(
|
|
338
|
+
'SELECT * FROM svara_messages WHERE session_id = ? ORDER BY created_at',
|
|
339
|
+
['user-123-conversation-1']
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
// Check RAG chunks (with dedup tracking)
|
|
343
|
+
const chunks = db.query(
|
|
344
|
+
'SELECT id, content, content_hash FROM svara_chunks LIMIT 10'
|
|
345
|
+
);
|
|
346
|
+
```
|
|
347
|
+
|
|
222
348
|
### Channels
|
|
223
349
|
|
|
224
350
|
One agent, multiple platforms.
|
|
@@ -372,15 +498,30 @@ $ svara new my-app
|
|
|
372
498
|
|
|
373
499
|
## Built-in Database
|
|
374
500
|
|
|
375
|
-
|
|
501
|
+
Persistent SQLite for users, sessions, conversation history, and RAG vectors.
|
|
376
502
|
|
|
377
503
|
```ts
|
|
378
504
|
import { SvaraDB } from '@yesvara/svara';
|
|
379
505
|
|
|
380
|
-
const db = new SvaraDB('./data/
|
|
506
|
+
const db = new SvaraDB('./data/svara.db');
|
|
381
507
|
|
|
382
|
-
//
|
|
383
|
-
|
|
508
|
+
// Built-in tables (auto-created):
|
|
509
|
+
// - svara_users: user registry with timestamps
|
|
510
|
+
// - svara_sessions: conversation sessions linked to users
|
|
511
|
+
// - svara_messages: conversation history
|
|
512
|
+
// - svara_chunks: RAG vectors with deduplication
|
|
513
|
+
// - svara_kv: key-value store for app state
|
|
514
|
+
|
|
515
|
+
// Query users
|
|
516
|
+
const activeUsers = db.query(
|
|
517
|
+
'SELECT id, display_name, last_seen FROM svara_users WHERE last_seen > unixepoch() - 86400'
|
|
518
|
+
);
|
|
519
|
+
|
|
520
|
+
// Get conversation history
|
|
521
|
+
const history = db.query(
|
|
522
|
+
'SELECT role, content FROM svara_messages WHERE session_id = ? ORDER BY created_at',
|
|
523
|
+
['session-id']
|
|
524
|
+
);
|
|
384
525
|
|
|
385
526
|
// Key-value store
|
|
386
527
|
db.kv.set('feature:rag', true);
|
|
@@ -446,8 +587,8 @@ Request:
|
|
|
446
587
|
```json
|
|
447
588
|
{
|
|
448
589
|
"message": "What is the refund policy?",
|
|
449
|
-
"
|
|
450
|
-
"
|
|
590
|
+
"userId": "alice@example.com",
|
|
591
|
+
"sessionId": "alice-session-1"
|
|
451
592
|
}
|
|
452
593
|
```
|
|
453
594
|
|
|
@@ -455,7 +596,7 @@ Response:
|
|
|
455
596
|
```json
|
|
456
597
|
{
|
|
457
598
|
"response": "Our refund policy allows returns within 30 days...",
|
|
458
|
-
"sessionId": "
|
|
599
|
+
"sessionId": "alice-session-1",
|
|
459
600
|
"usage": {
|
|
460
601
|
"promptTokens": 312,
|
|
461
602
|
"completionTokens": 89,
|
|
@@ -465,16 +606,63 @@ Response:
|
|
|
465
606
|
}
|
|
466
607
|
```
|
|
467
608
|
|
|
609
|
+
**Note:** `userId` and `sessionId` are automatically tracked in the SQLite database for user management and conversation history.
|
|
610
|
+
|
|
468
611
|
**`GET /health`** — always returns `{ "status": "ok" }`
|
|
469
612
|
|
|
470
613
|
---
|
|
471
614
|
|
|
615
|
+
## Database Schema
|
|
616
|
+
|
|
617
|
+
SvaraJS automatically creates and manages these SQLite tables:
|
|
618
|
+
|
|
619
|
+
| Table | Purpose | Auto-Managed |
|
|
620
|
+
|-------|---------|--------------|
|
|
621
|
+
| `svara_users` | User registry (first_seen, last_seen, metadata) | ✅ Yes |
|
|
622
|
+
| `svara_sessions` | Conversation sessions linked to users | ✅ Yes |
|
|
623
|
+
| `svara_messages` | Full conversation history per session | ✅ Yes |
|
|
624
|
+
| `svara_chunks` | RAG vectors **isolated per agent** with deduplication | ✅ Yes |
|
|
625
|
+
| `svara_documents` | Document registry and metadata | ✅ Yes |
|
|
626
|
+
| `svara_kv` | Key-value store for app state | ✅ Yes |
|
|
627
|
+
| `svara_meta` | Framework metadata and versions | ✅ Yes |
|
|
628
|
+
|
|
629
|
+
**RAG Isolation:**
|
|
630
|
+
|
|
631
|
+
Each agent's RAG data is stored separately using the `agent_name` column:
|
|
632
|
+
|
|
633
|
+
```ts
|
|
634
|
+
// Query RAG chunks for specific agent
|
|
635
|
+
const supportChunks = db.query(
|
|
636
|
+
'SELECT COUNT(*) as count FROM svara_chunks WHERE agent_name = ?',
|
|
637
|
+
['SupportBot']
|
|
638
|
+
);
|
|
639
|
+
|
|
640
|
+
const salesChunks = db.query(
|
|
641
|
+
'SELECT COUNT(*) as count FROM svara_chunks WHERE agent_name = ?',
|
|
642
|
+
['SalesBot']
|
|
643
|
+
);
|
|
644
|
+
|
|
645
|
+
// Export conversation analytics
|
|
646
|
+
db.query(`
|
|
647
|
+
SELECT u.id, u.display_name, COUNT(m.id) as message_count
|
|
648
|
+
FROM svara_users u
|
|
649
|
+
LEFT JOIN svara_messages m ON u.id = (
|
|
650
|
+
SELECT user_id FROM svara_sessions WHERE id = m.session_id
|
|
651
|
+
)
|
|
652
|
+
WHERE u.last_seen > unixepoch() - 86400
|
|
653
|
+
GROUP BY u.id
|
|
654
|
+
ORDER BY message_count DESC
|
|
655
|
+
`);
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
---
|
|
659
|
+
|
|
472
660
|
## Contributing
|
|
473
661
|
|
|
474
662
|
Contributions are welcome! Please read [CONTRIBUTING.md](./CONTRIBUTING.md) first.
|
|
475
663
|
|
|
476
664
|
```bash
|
|
477
|
-
git clone https://github.com/
|
|
665
|
+
git clone https://github.com/yogiswara92/svarajs
|
|
478
666
|
cd svara
|
|
479
667
|
npm install
|
|
480
668
|
npm run dev
|
package/SvaraJS.png
ADDED
|
Binary file
|