@telvok/librarian-mcp 1.5.2 → 1.5.4
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.
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { ParseResult } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Parse a JSONL file
|
|
3
|
+
* Parse a JSONL file. Supports multiple formats:
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* {"type":"entity","name":"
|
|
7
|
-
*
|
|
5
|
+
* mcp-knowledge-graph:
|
|
6
|
+
* {"type":"entity","name":"Topic","observations":["fact 1","fact 2"]}
|
|
7
|
+
*
|
|
8
|
+
* Generic memory formats:
|
|
9
|
+
* {"title":"Topic","content":"..."}
|
|
10
|
+
* {"content":"...","timestamp":"..."}
|
|
11
|
+
* {"text":"...","metadata":{}}
|
|
12
|
+
* {"memory":"...","created_at":"..."}
|
|
8
13
|
*/
|
|
9
14
|
export declare function parseJSONL(filePath: string): Promise<ParseResult>;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import * as fs from 'fs/promises';
|
|
2
2
|
/**
|
|
3
|
-
* Parse a JSONL file
|
|
3
|
+
* Parse a JSONL file. Supports multiple formats:
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* {"type":"entity","name":"
|
|
7
|
-
*
|
|
5
|
+
* mcp-knowledge-graph:
|
|
6
|
+
* {"type":"entity","name":"Topic","observations":["fact 1","fact 2"]}
|
|
7
|
+
*
|
|
8
|
+
* Generic memory formats:
|
|
9
|
+
* {"title":"Topic","content":"..."}
|
|
10
|
+
* {"content":"...","timestamp":"..."}
|
|
11
|
+
* {"text":"...","metadata":{}}
|
|
12
|
+
* {"memory":"...","created_at":"..."}
|
|
8
13
|
*/
|
|
9
14
|
export async function parseJSONL(filePath) {
|
|
10
15
|
const entries = [];
|
|
@@ -17,28 +22,55 @@ export async function parseJSONL(filePath) {
|
|
|
17
22
|
const line = lines[i];
|
|
18
23
|
try {
|
|
19
24
|
const item = JSON.parse(line);
|
|
20
|
-
// Skip
|
|
25
|
+
// Skip internal markers and relations
|
|
21
26
|
if (item.type === '_aim' || item.type === 'relation') {
|
|
22
27
|
skipped++;
|
|
23
28
|
continue;
|
|
24
29
|
}
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
// Extract title (try multiple fields)
|
|
31
|
+
const title = item.name || item.title || item.key || `Entry ${i + 1}`;
|
|
32
|
+
// Extract content (try multiple fields)
|
|
33
|
+
let entryContent;
|
|
34
|
+
// Check observations array first (mcp-knowledge-graph)
|
|
35
|
+
if (item.observations && Array.isArray(item.observations) && item.observations.length > 0) {
|
|
36
|
+
entryContent = item.observations.join('\n\n');
|
|
37
|
+
}
|
|
38
|
+
// Fall back to common content fields
|
|
39
|
+
if (!entryContent) {
|
|
40
|
+
entryContent = item.content || item.text || item.description ||
|
|
41
|
+
item.value || item.memory || item.observation || item.body;
|
|
42
|
+
}
|
|
43
|
+
// Skip if no content found
|
|
44
|
+
if (!entryContent) {
|
|
40
45
|
skipped++;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
// Extract context
|
|
49
|
+
let context;
|
|
50
|
+
if (item.entityType) {
|
|
51
|
+
context = item.entityType;
|
|
52
|
+
}
|
|
53
|
+
else if (item.context) {
|
|
54
|
+
context = item.context;
|
|
55
|
+
}
|
|
56
|
+
else if (item.category) {
|
|
57
|
+
context = item.category;
|
|
58
|
+
}
|
|
59
|
+
else if (item.type && item.type !== 'entity' && item.type !== 'memory') {
|
|
60
|
+
context = item.type;
|
|
61
|
+
}
|
|
62
|
+
else if (item.tags && Array.isArray(item.tags)) {
|
|
63
|
+
context = item.tags.join(', ');
|
|
41
64
|
}
|
|
65
|
+
entries.push({
|
|
66
|
+
title: String(title),
|
|
67
|
+
content: String(entryContent),
|
|
68
|
+
context,
|
|
69
|
+
intent: item.intent ? String(item.intent) : undefined,
|
|
70
|
+
reasoning: item.reasoning ? String(item.reasoning) : undefined,
|
|
71
|
+
example: item.example ? String(item.example) : undefined,
|
|
72
|
+
source: 'jsonl',
|
|
73
|
+
});
|
|
42
74
|
}
|
|
43
75
|
catch (parseError) {
|
|
44
76
|
errors.push(`Line ${i + 1}: Invalid JSON - ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|