@yesvara/svara 0.1.1 → 0.1.3
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 +1 -1
- package/README.md +223 -15
- package/SvaraJS.png +0 -0
- package/dist/{chunk-WA3BIA3S.mjs → chunk-CCNWHBEI.mjs} +3 -251
- 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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +10 -0
- package/dist/index.mjs +15 -3
- package/dist/{retriever-OTPBECGO.mjs → retriever-JYOGHA4F.mjs} +2 -1
- package/examples/03-rag-knowledge/index.ts +2 -4
- package/package.json +2 -2
- package/src/cli/commands/db.ts +267 -0
- package/src/cli/index.ts +74 -4
- package/src/core/agent.ts +12 -0
- package/svara@1.0.0 +0 -0
- package/test-rag.ts +0 -20
- package/tsx +0 -0
package/src/core/agent.ts
CHANGED
|
@@ -173,6 +173,7 @@ export class SvaraAgent extends EventEmitter {
|
|
|
173
173
|
private retriever: any = null; // Store VectorRetriever for retrieveChunks access
|
|
174
174
|
private knowledgePaths: string[] = [];
|
|
175
175
|
private isStarted = false;
|
|
176
|
+
private isKnowledgeInitialized = false;
|
|
176
177
|
private db: SvaraDB;
|
|
177
178
|
|
|
178
179
|
constructor(config: AgentConfig) {
|
|
@@ -303,6 +304,17 @@ export class SvaraAgent extends EventEmitter {
|
|
|
303
304
|
*/
|
|
304
305
|
handler(): RequestHandler {
|
|
305
306
|
return async (req, res) => {
|
|
307
|
+
// Auto-initialize knowledge on first request (lazy loading)
|
|
308
|
+
if (this.knowledgePaths.length > 0 && !this.isKnowledgeInitialized) {
|
|
309
|
+
try {
|
|
310
|
+
await this.initKnowledge(this.knowledgePaths);
|
|
311
|
+
this.isKnowledgeInitialized = true;
|
|
312
|
+
} catch (err) {
|
|
313
|
+
const error = err as Error;
|
|
314
|
+
this.log('error', `Failed to initialize knowledge: ${error.message}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
306
318
|
const { message, sessionId, userId } = req.body as {
|
|
307
319
|
message?: string;
|
|
308
320
|
sessionId?: string;
|
package/svara@1.0.0
DELETED
|
File without changes
|
package/test-rag.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
2
|
-
import { SvaraApp, SvaraAgent } from './src/index.js';
|
|
3
|
-
|
|
4
|
-
async function main() {
|
|
5
|
-
const app = new SvaraApp({ cors: true });
|
|
6
|
-
|
|
7
|
-
const agent = new SvaraAgent({
|
|
8
|
-
name: 'TestAgent',
|
|
9
|
-
model: 'gpt-4o-mini',
|
|
10
|
-
knowledge: '/Users/920078/Documents/svara/contoh_folder_knowledge/**/*',
|
|
11
|
-
verbose: true,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
await agent.start();
|
|
15
|
-
app.route('/chat', agent.handler());
|
|
16
|
-
app.listen(3000);
|
|
17
|
-
console.log('✓ Test server on port 3000');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
main().catch(console.error);
|
package/tsx
DELETED
|
File without changes
|