@j0hanz/memdb 1.1.5 → 1.2.1
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/dist/config.d.ts +3 -1
- package/dist/config.js +27 -3
- package/dist/core/db.d.ts +1 -1
- package/dist/core/db.js +11 -0
- package/dist/core/memory-read.js +18 -16
- package/dist/core/memory-write.d.ts +5 -1
- package/dist/core/memory-write.js +33 -22
- package/dist/core/relationships.d.ts +15 -0
- package/dist/core/relationships.js +93 -0
- package/dist/core/search.d.ts +5 -1
- package/dist/core/search.js +93 -7
- package/dist/index.js +8 -4
- package/dist/protocol-version-guard.js +16 -0
- package/dist/schemas.d.ts +44 -0
- package/dist/schemas.js +58 -0
- package/dist/stdio-transport.d.ts +29 -0
- package/dist/stdio-transport.js +250 -0
- package/dist/tools.d.ts +11 -2
- package/dist/tools.js +101 -3
- package/dist/types.d.ts +29 -5
- package/dist/types.js +10 -1
- package/package.json +3 -3
- package/dist/core/database-schema.d.ts +0 -2
- package/dist/core/database-schema.d.ts.map +0 -1
- package/dist/core/database-schema.js +0 -64
- package/dist/core/database-schema.js.map +0 -1
- package/dist/core/database.d.ts +0 -3
- package/dist/core/database.d.ts.map +0 -1
- package/dist/core/database.js +0 -43
- package/dist/core/database.js.map +0 -1
- package/dist/core/memory-create.d.ts +0 -7
- package/dist/core/memory-create.d.ts.map +0 -1
- package/dist/core/memory-create.js +0 -40
- package/dist/core/memory-create.js.map +0 -1
- package/dist/core/memory-db.d.ts +0 -2
- package/dist/core/memory-db.d.ts.map +0 -1
- package/dist/core/memory-db.js +0 -31
- package/dist/core/memory-db.js.map +0 -1
- package/dist/core/memory-read.d.ts.map +0 -1
- package/dist/core/memory-read.js.map +0 -1
- package/dist/core/memory-relations.d.ts +0 -10
- package/dist/core/memory-relations.d.ts.map +0 -1
- package/dist/core/memory-relations.js +0 -57
- package/dist/core/memory-relations.js.map +0 -1
- package/dist/core/memory-search.d.ts +0 -10
- package/dist/core/memory-search.d.ts.map +0 -1
- package/dist/core/memory-search.js +0 -23
- package/dist/core/memory-search.js.map +0 -1
- package/dist/core/memory-stats.d.ts +0 -2
- package/dist/core/memory-stats.d.ts.map +0 -1
- package/dist/core/memory-stats.js +0 -51
- package/dist/core/memory-stats.js.map +0 -1
- package/dist/core/memory-updates.d.ts +0 -10
- package/dist/core/memory-updates.d.ts.map +0 -1
- package/dist/core/memory-updates.js +0 -115
- package/dist/core/memory-updates.js.map +0 -1
- package/dist/core/relation-queries.d.ts +0 -7
- package/dist/core/relation-queries.d.ts.map +0 -1
- package/dist/core/relation-queries.js +0 -125
- package/dist/core/relation-queries.js.map +0 -1
- package/dist/core/relations.d.ts +0 -10
- package/dist/core/relations.js +0 -177
- package/dist/core/row-mappers.d.ts +0 -6
- package/dist/core/row-mappers.d.ts.map +0 -1
- package/dist/core/row-mappers.js +0 -52
- package/dist/core/row-mappers.js.map +0 -1
- package/dist/core/search-errors.d.ts +0 -1
- package/dist/core/search-errors.d.ts.map +0 -1
- package/dist/core/search-errors.js +0 -30
- package/dist/core/search-errors.js.map +0 -1
- package/dist/core/search.d.ts.map +0 -1
- package/dist/core/search.js.map +0 -1
- package/dist/core/sqlite.d.ts +0 -10
- package/dist/core/sqlite.d.ts.map +0 -1
- package/dist/core/sqlite.js +0 -71
- package/dist/core/sqlite.js.map +0 -1
- package/dist/core/tags.d.ts +0 -1
- package/dist/core/tags.d.ts.map +0 -1
- package/dist/core/tags.js +0 -27
- package/dist/core/tags.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/errors.d.ts +0 -19
- package/dist/lib/errors.d.ts.map +0 -1
- package/dist/lib/errors.js +0 -22
- package/dist/lib/errors.js.map +0 -1
- package/dist/schemas/inputs.d.ts +0 -44
- package/dist/schemas/inputs.d.ts.map +0 -1
- package/dist/schemas/inputs.js +0 -97
- package/dist/schemas/inputs.js.map +0 -1
- package/dist/schemas/outputs.d.ts +0 -9
- package/dist/schemas/outputs.d.ts.map +0 -1
- package/dist/schemas/outputs.js +0 -28
- package/dist/schemas/outputs.js.map +0 -1
- package/dist/tools/definitions/memory-core.d.ts +0 -2
- package/dist/tools/definitions/memory-core.d.ts.map +0 -1
- package/dist/tools/definitions/memory-core.js +0 -79
- package/dist/tools/definitions/memory-core.js.map +0 -1
- package/dist/tools/definitions/memory-relations.d.ts +0 -2
- package/dist/tools/definitions/memory-relations.d.ts.map +0 -1
- package/dist/tools/definitions/memory-relations.js +0 -43
- package/dist/tools/definitions/memory-relations.js.map +0 -1
- package/dist/tools/definitions/memory-search.d.ts +0 -2
- package/dist/tools/definitions/memory-search.d.ts.map +0 -1
- package/dist/tools/definitions/memory-search.js +0 -20
- package/dist/tools/definitions/memory-search.js.map +0 -1
- package/dist/tools/definitions/memory-stats.d.ts +0 -2
- package/dist/tools/definitions/memory-stats.d.ts.map +0 -1
- package/dist/tools/definitions/memory-stats.js +0 -20
- package/dist/tools/definitions/memory-stats.js.map +0 -1
- package/dist/tools/index.d.ts +0 -2
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -15
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/tool-handlers.d.ts +0 -3
- package/dist/tools/tool-handlers.d.ts.map +0 -1
- package/dist/tools/tool-handlers.js +0 -19
- package/dist/tools/tool-handlers.js.map +0 -1
- package/dist/tools/tool-types.d.ts +0 -14
- package/dist/tools/tool-types.d.ts.map +0 -1
- package/dist/tools/tool-types.js +0 -1
- package/dist/tools/tool-types.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/index.d.ts +0 -37
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/utils/config.d.ts +0 -6
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -99
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -5
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -20
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils.d.ts +0 -11
- package/dist/utils.js +0 -118
- package/dist/worker/db-worker-client.d.ts +0 -9
- package/dist/worker/db-worker-client.js +0 -93
- package/dist/worker/db-worker.d.ts +0 -1
- package/dist/worker/db-worker.js +0 -174
- package/dist/worker/protocol.d.ts +0 -9
- package/dist/worker/protocol.js +0 -14
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { mapRowToRelatedMemory } from './row-mappers.js';
|
|
2
|
-
import { executeAll, prepareCached } from './sqlite.js';
|
|
3
|
-
const directConfig = {
|
|
4
|
-
outgoing: { joinColumn: 'to_memory_id', whereColumn: 'from_memory_id' },
|
|
5
|
-
incoming: { joinColumn: 'from_memory_id', whereColumn: 'to_memory_id' },
|
|
6
|
-
};
|
|
7
|
-
const recursiveConfig = {
|
|
8
|
-
outgoing: {
|
|
9
|
-
baseColumn: 'from_memory_id',
|
|
10
|
-
joinColumn: 'from_memory_id',
|
|
11
|
-
relsJoinColumn: 'to_id',
|
|
12
|
-
memoryJoinColumn: 'to_id',
|
|
13
|
-
},
|
|
14
|
-
incoming: {
|
|
15
|
-
baseColumn: 'to_memory_id',
|
|
16
|
-
joinColumn: 'to_memory_id',
|
|
17
|
-
relsJoinColumn: 'from_id',
|
|
18
|
-
memoryJoinColumn: 'from_id',
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
const typeFilter = (relationType) => relationType
|
|
22
|
-
? { clause: ' AND r.relation_type = ?', params: [relationType] }
|
|
23
|
-
: { clause: '', params: [] };
|
|
24
|
-
const run = (sql, params) => executeAll(prepareCached(sql), ...params).map((row) => mapRowToRelatedMemory(row));
|
|
25
|
-
const buildDirectSql = (input) => {
|
|
26
|
-
const config = directConfig[input.direction];
|
|
27
|
-
const limitClause = input.includeLimit === false ? '' : '\n LIMIT 1000';
|
|
28
|
-
return `
|
|
29
|
-
SELECT m.*, r.relation_type as relation_type, 1 as depth
|
|
30
|
-
FROM memories m
|
|
31
|
-
JOIN relationships r ON m.id = r.${config.joinColumn}
|
|
32
|
-
WHERE r.${config.whereColumn} = ?${input.clause}${limitClause}
|
|
33
|
-
`;
|
|
34
|
-
};
|
|
35
|
-
const buildRecursiveSql = (input) => {
|
|
36
|
-
const config = recursiveConfig[input.direction];
|
|
37
|
-
return `
|
|
38
|
-
WITH RECURSIVE rels(depth, from_id, to_id, relation_type) AS (
|
|
39
|
-
SELECT 1, r.from_memory_id, r.to_memory_id, r.relation_type
|
|
40
|
-
FROM relationships r
|
|
41
|
-
WHERE r.${config.baseColumn} = ?${input.clause}
|
|
42
|
-
UNION ALL
|
|
43
|
-
SELECT rels.depth + 1, r.from_memory_id, r.to_memory_id, r.relation_type
|
|
44
|
-
FROM relationships r
|
|
45
|
-
JOIN rels ON r.${config.joinColumn} = rels.${config.relsJoinColumn}
|
|
46
|
-
WHERE rels.depth < ?${input.clause}
|
|
47
|
-
)
|
|
48
|
-
SELECT m.*, rels.relation_type as relation_type, MIN(rels.depth) as depth
|
|
49
|
-
FROM rels
|
|
50
|
-
JOIN memories m ON m.id = rels.${config.memoryJoinColumn}
|
|
51
|
-
GROUP BY m.id, rels.relation_type
|
|
52
|
-
ORDER BY depth, m.id
|
|
53
|
-
LIMIT 1000
|
|
54
|
-
`;
|
|
55
|
-
};
|
|
56
|
-
const buildRecursiveParams = (input) => {
|
|
57
|
-
if (!input.relationType) {
|
|
58
|
-
return [input.memoryId, input.maxDepth];
|
|
59
|
-
}
|
|
60
|
-
return [input.memoryId, ...input.params, input.maxDepth, ...input.params];
|
|
61
|
-
};
|
|
62
|
-
export const queryOutgoingDirect = (memoryId, relationType) => {
|
|
63
|
-
const { clause, params } = typeFilter(relationType);
|
|
64
|
-
const sql = buildDirectSql({ direction: 'outgoing', clause });
|
|
65
|
-
return run(sql, [memoryId, ...params]);
|
|
66
|
-
};
|
|
67
|
-
export const queryIncomingDirect = (memoryId, relationType) => {
|
|
68
|
-
const { clause, params } = typeFilter(relationType);
|
|
69
|
-
const sql = buildDirectSql({ direction: 'incoming', clause });
|
|
70
|
-
return run(sql, [memoryId, ...params]);
|
|
71
|
-
};
|
|
72
|
-
export const queryBothDirect = (memoryId, relationType) => {
|
|
73
|
-
const { clause, params } = typeFilter(relationType);
|
|
74
|
-
const outgoingSql = buildDirectSql({
|
|
75
|
-
direction: 'outgoing',
|
|
76
|
-
clause,
|
|
77
|
-
includeLimit: false,
|
|
78
|
-
});
|
|
79
|
-
const incomingSql = buildDirectSql({
|
|
80
|
-
direction: 'incoming',
|
|
81
|
-
clause,
|
|
82
|
-
includeLimit: false,
|
|
83
|
-
});
|
|
84
|
-
const sql = `
|
|
85
|
-
${outgoingSql}
|
|
86
|
-
UNION
|
|
87
|
-
${incomingSql}
|
|
88
|
-
LIMIT 1000
|
|
89
|
-
`;
|
|
90
|
-
return run(sql, [memoryId, ...params, memoryId, ...params]);
|
|
91
|
-
};
|
|
92
|
-
export const queryOutgoingRecursive = (memoryId, relationType, maxDepth) => {
|
|
93
|
-
const { clause, params } = typeFilter(relationType);
|
|
94
|
-
const sql = buildRecursiveSql({ direction: 'outgoing', clause });
|
|
95
|
-
const sqlParams = buildRecursiveParams({
|
|
96
|
-
memoryId,
|
|
97
|
-
relationType,
|
|
98
|
-
maxDepth,
|
|
99
|
-
params,
|
|
100
|
-
});
|
|
101
|
-
return run(sql, sqlParams);
|
|
102
|
-
};
|
|
103
|
-
export const queryIncomingRecursive = (memoryId, relationType, maxDepth) => {
|
|
104
|
-
const { clause, params } = typeFilter(relationType);
|
|
105
|
-
const sql = buildRecursiveSql({ direction: 'incoming', clause });
|
|
106
|
-
const sqlParams = buildRecursiveParams({
|
|
107
|
-
memoryId,
|
|
108
|
-
relationType,
|
|
109
|
-
maxDepth,
|
|
110
|
-
params,
|
|
111
|
-
});
|
|
112
|
-
return run(sql, sqlParams);
|
|
113
|
-
};
|
|
114
|
-
export const deduplicateByHash = (memories) => {
|
|
115
|
-
const seen = new Map();
|
|
116
|
-
for (const mem of memories) {
|
|
117
|
-
const existing = seen.get(mem.hash);
|
|
118
|
-
if (!existing || mem.depth < existing.depth) {
|
|
119
|
-
seen.set(mem.hash, mem);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return [...seen.values()]
|
|
123
|
-
.sort((a, b) => a.depth - b.depth || a.id - b.id)
|
|
124
|
-
.slice(0, 1000);
|
|
125
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relation-queries.js","sourceRoot":"","sources":["../../src/core/relation-queries.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAiB,MAAM,aAAa,CAAC;AAIvE,MAAM,YAAY,GAGd;IACF,QAAQ,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,gBAAgB,EAAE;IACvE,QAAQ,EAAE,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAE;CACxE,CAAC;AAEF,MAAM,eAAe,GAQjB;IACF,QAAQ,EAAE;QACR,UAAU,EAAE,gBAAgB;QAC5B,UAAU,EAAE,gBAAgB;QAC5B,cAAc,EAAE,OAAO;QACvB,gBAAgB,EAAE,OAAO;KAC1B;IACD,QAAQ,EAAE;QACR,UAAU,EAAE,cAAc;QAC1B,UAAU,EAAE,cAAc;QAC1B,cAAc,EAAE,SAAS;QACzB,gBAAgB,EAAE,SAAS;KAC5B;CACF,CAAC;AAEF,MAAM,UAAU,GAAG,CACjB,YAAqB,EACiB,EAAE,CACxC,YAAY;IACV,CAAC,CAAC,EAAE,MAAM,EAAE,0BAA0B,EAAE,MAAM,EAAE,CAAC,YAAY,CAAC,EAAE;IAChE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAEjC,MAAM,GAAG,GAAG,CAAC,GAAW,EAAE,MAAkB,EAAmB,EAAE,CAC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G,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;SACtB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;SAChD,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AACpB,CAAC,CAAC"}
|
package/dist/core/relations.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { RelatedMemory, StatementResult } from '../types.js';
|
|
2
|
-
type RelationDirection = 'outgoing' | 'incoming' | 'both';
|
|
3
|
-
export declare const linkMemories: (fromHash: string, toHash: string, relationType: string) => StatementResult;
|
|
4
|
-
export declare const getRelated: (input: {
|
|
5
|
-
hash: string;
|
|
6
|
-
relationType?: string;
|
|
7
|
-
depth?: number;
|
|
8
|
-
direction?: RelationDirection;
|
|
9
|
-
}) => RelatedMemory[];
|
|
10
|
-
export {};
|
package/dist/core/relations.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { db, executeAll, executeRun, mapRowToRelatedMemory, prepareCached, toSafeInteger, } from './db.js';
|
|
2
|
-
import { findMemoryIdByHash } from './memory-write.js';
|
|
3
|
-
const stmtInsertRelation = db.prepare('INSERT OR IGNORE INTO relationships (from_memory_id, to_memory_id, ' +
|
|
4
|
-
'relation_type) VALUES (?, ?, ?)');
|
|
5
|
-
const directConfig = {
|
|
6
|
-
outgoing: { joinColumn: 'to_memory_id', whereColumn: 'from_memory_id' },
|
|
7
|
-
incoming: { joinColumn: 'from_memory_id', whereColumn: 'to_memory_id' },
|
|
8
|
-
};
|
|
9
|
-
const recursiveConfig = {
|
|
10
|
-
outgoing: {
|
|
11
|
-
baseColumn: 'from_memory_id',
|
|
12
|
-
joinColumn: 'from_memory_id',
|
|
13
|
-
relsJoinColumn: 'to_id',
|
|
14
|
-
memoryJoinColumn: 'to_id',
|
|
15
|
-
},
|
|
16
|
-
incoming: {
|
|
17
|
-
baseColumn: 'to_memory_id',
|
|
18
|
-
joinColumn: 'to_memory_id',
|
|
19
|
-
relsJoinColumn: 'from_id',
|
|
20
|
-
memoryJoinColumn: 'from_id',
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
const typeFilter = (relationType) => relationType
|
|
24
|
-
? { clause: ' AND r.relation_type = ?', params: [relationType] }
|
|
25
|
-
: { clause: '', params: [] };
|
|
26
|
-
const run = (sql, params) => executeAll(prepareCached(sql), ...params).map((row) => mapRowToRelatedMemory(row));
|
|
27
|
-
const buildDirectSql = (input) => {
|
|
28
|
-
const config = directConfig[input.direction];
|
|
29
|
-
const limitClause = input.includeLimit === false ? '' : '\n LIMIT 1000';
|
|
30
|
-
return `
|
|
31
|
-
SELECT m.*, r.relation_type as relation_type, 1 as depth
|
|
32
|
-
FROM memories m
|
|
33
|
-
JOIN relationships r ON m.id = r.${config.joinColumn}
|
|
34
|
-
WHERE r.${config.whereColumn} = ?${input.clause}${limitClause}
|
|
35
|
-
`;
|
|
36
|
-
};
|
|
37
|
-
const buildRecursiveSql = (input) => {
|
|
38
|
-
const config = recursiveConfig[input.direction];
|
|
39
|
-
return `
|
|
40
|
-
WITH RECURSIVE rels(depth, from_id, to_id, relation_type) AS (
|
|
41
|
-
SELECT 1, r.from_memory_id, r.to_memory_id, r.relation_type
|
|
42
|
-
FROM relationships r
|
|
43
|
-
WHERE r.${config.baseColumn} = ?${input.clause}
|
|
44
|
-
UNION ALL
|
|
45
|
-
SELECT rels.depth + 1, r.from_memory_id, r.to_memory_id, r.relation_type
|
|
46
|
-
FROM relationships r
|
|
47
|
-
JOIN rels ON r.${config.joinColumn} = rels.${config.relsJoinColumn}
|
|
48
|
-
WHERE rels.depth < ?${input.clause}
|
|
49
|
-
)
|
|
50
|
-
SELECT m.*, rels.relation_type as relation_type, MIN(rels.depth) as depth
|
|
51
|
-
FROM rels
|
|
52
|
-
JOIN memories m ON m.id = rels.${config.memoryJoinColumn}
|
|
53
|
-
GROUP BY m.id, rels.relation_type
|
|
54
|
-
ORDER BY depth, m.id
|
|
55
|
-
LIMIT 1000
|
|
56
|
-
`;
|
|
57
|
-
};
|
|
58
|
-
const buildRecursiveParams = (input) => {
|
|
59
|
-
if (!input.relationType) {
|
|
60
|
-
return [input.memoryId, input.maxDepth];
|
|
61
|
-
}
|
|
62
|
-
return [input.memoryId, ...input.params, input.maxDepth, ...input.params];
|
|
63
|
-
};
|
|
64
|
-
const queryOutgoingDirect = (memoryId, relationType) => {
|
|
65
|
-
const { clause, params } = typeFilter(relationType);
|
|
66
|
-
const sql = buildDirectSql({ direction: 'outgoing', clause });
|
|
67
|
-
return run(sql, [memoryId, ...params]);
|
|
68
|
-
};
|
|
69
|
-
const queryIncomingDirect = (memoryId, relationType) => {
|
|
70
|
-
const { clause, params } = typeFilter(relationType);
|
|
71
|
-
const sql = buildDirectSql({ direction: 'incoming', clause });
|
|
72
|
-
return run(sql, [memoryId, ...params]);
|
|
73
|
-
};
|
|
74
|
-
const queryBothDirect = (memoryId, relationType) => {
|
|
75
|
-
const { clause, params } = typeFilter(relationType);
|
|
76
|
-
const outgoingSql = buildDirectSql({
|
|
77
|
-
direction: 'outgoing',
|
|
78
|
-
clause,
|
|
79
|
-
includeLimit: false,
|
|
80
|
-
});
|
|
81
|
-
const incomingSql = buildDirectSql({
|
|
82
|
-
direction: 'incoming',
|
|
83
|
-
clause,
|
|
84
|
-
includeLimit: false,
|
|
85
|
-
});
|
|
86
|
-
const sql = `
|
|
87
|
-
${outgoingSql}
|
|
88
|
-
UNION
|
|
89
|
-
${incomingSql}
|
|
90
|
-
LIMIT 1000
|
|
91
|
-
`;
|
|
92
|
-
return run(sql, [memoryId, ...params, memoryId, ...params]);
|
|
93
|
-
};
|
|
94
|
-
const queryOutgoingRecursive = (memoryId, relationType, maxDepth) => {
|
|
95
|
-
const { clause, params } = typeFilter(relationType);
|
|
96
|
-
const sql = buildRecursiveSql({ direction: 'outgoing', clause });
|
|
97
|
-
const sqlParams = buildRecursiveParams({
|
|
98
|
-
memoryId,
|
|
99
|
-
relationType,
|
|
100
|
-
maxDepth,
|
|
101
|
-
params,
|
|
102
|
-
});
|
|
103
|
-
return run(sql, sqlParams);
|
|
104
|
-
};
|
|
105
|
-
const queryIncomingRecursive = (memoryId, relationType, maxDepth) => {
|
|
106
|
-
const { clause, params } = typeFilter(relationType);
|
|
107
|
-
const sql = buildRecursiveSql({ direction: 'incoming', clause });
|
|
108
|
-
const sqlParams = buildRecursiveParams({
|
|
109
|
-
memoryId,
|
|
110
|
-
relationType,
|
|
111
|
-
maxDepth,
|
|
112
|
-
params,
|
|
113
|
-
});
|
|
114
|
-
return run(sql, sqlParams);
|
|
115
|
-
};
|
|
116
|
-
const deduplicateByHash = (memories) => {
|
|
117
|
-
const seen = new Map();
|
|
118
|
-
for (const mem of memories) {
|
|
119
|
-
const existing = seen.get(mem.hash);
|
|
120
|
-
if (!existing || mem.depth < existing.depth) {
|
|
121
|
-
seen.set(mem.hash, mem);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return [...seen.values()]
|
|
125
|
-
.sort((a, b) => a.depth - b.depth || a.id - b.id)
|
|
126
|
-
.slice(0, 1000);
|
|
127
|
-
};
|
|
128
|
-
const resolveMaxDepth = (depth, direction) => {
|
|
129
|
-
if (direction === 'both') {
|
|
130
|
-
return Math.min(depth, 2);
|
|
131
|
-
}
|
|
132
|
-
return Math.max(1, depth);
|
|
133
|
-
};
|
|
134
|
-
export const linkMemories = (fromHash, toHash, relationType) => {
|
|
135
|
-
const fromId = findMemoryIdByHash(fromHash);
|
|
136
|
-
const toId = findMemoryIdByHash(toHash);
|
|
137
|
-
if (fromId === undefined || toId === undefined) {
|
|
138
|
-
throw new Error('One or both memories not found');
|
|
139
|
-
}
|
|
140
|
-
const result = executeRun(stmtInsertRelation, fromId, toId, relationType);
|
|
141
|
-
return { changes: toSafeInteger(result.changes, 'changes') };
|
|
142
|
-
};
|
|
143
|
-
export const getRelated = (input) => {
|
|
144
|
-
const { hash, relationType, depth = 1, direction = 'outgoing' } = input;
|
|
145
|
-
const memoryId = findMemoryIdByHash(hash);
|
|
146
|
-
if (memoryId === undefined)
|
|
147
|
-
return [];
|
|
148
|
-
const maxDepth = resolveMaxDepth(depth, direction);
|
|
149
|
-
if (maxDepth === 1) {
|
|
150
|
-
return getRelatedDirect(memoryId, relationType, direction);
|
|
151
|
-
}
|
|
152
|
-
return getRelatedRecursive({
|
|
153
|
-
memoryId,
|
|
154
|
-
relationType,
|
|
155
|
-
maxDepth,
|
|
156
|
-
direction,
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
const getRelatedDirect = (memoryId, relationType, direction = 'outgoing') => {
|
|
160
|
-
if (direction === 'outgoing')
|
|
161
|
-
return queryOutgoingDirect(memoryId, relationType);
|
|
162
|
-
if (direction === 'incoming')
|
|
163
|
-
return queryIncomingDirect(memoryId, relationType);
|
|
164
|
-
return queryBothDirect(memoryId, relationType);
|
|
165
|
-
};
|
|
166
|
-
const getRelatedRecursive = (input) => {
|
|
167
|
-
const { memoryId, relationType, maxDepth, direction } = input;
|
|
168
|
-
if (direction === 'outgoing') {
|
|
169
|
-
return queryOutgoingRecursive(memoryId, relationType, maxDepth);
|
|
170
|
-
}
|
|
171
|
-
if (direction === 'incoming') {
|
|
172
|
-
return queryIncomingRecursive(memoryId, relationType, maxDepth);
|
|
173
|
-
}
|
|
174
|
-
const outgoing = queryOutgoingRecursive(memoryId, relationType, maxDepth);
|
|
175
|
-
const incoming = queryIncomingRecursive(memoryId, relationType, maxDepth);
|
|
176
|
-
return deduplicateByHash([...outgoing, ...incoming]);
|
|
177
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Memory, RelatedMemory, SearchResult } from '../types/index.js';
|
|
2
|
-
export type DbRow = Record<string, unknown>;
|
|
3
|
-
export declare const toSafeInteger: (value: unknown, field: string) => number;
|
|
4
|
-
export declare const mapRowToMemory: (row: DbRow) => Memory;
|
|
5
|
-
export declare const mapRowToSearchResult: (row: DbRow) => SearchResult;
|
|
6
|
-
export declare const mapRowToRelatedMemory: (row: DbRow) => RelatedMemory;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"row-mappers.d.ts","sourceRoot":"","sources":["../../src/core/row-mappers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE7E,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAc5C,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,MAM7D,CAAC;AAuBF,eAAO,MAAM,cAAc,GAAI,KAAK,KAAK,KAAG,MAS1C,CAAC;AAEH,eAAO,MAAM,oBAAoB,GAAI,KAAK,KAAK,KAAG,YAGhD,CAAC;AAEH,eAAO,MAAM,qBAAqB,GAAI,KAAK,KAAK,KAAG,aAIjD,CAAC"}
|
package/dist/core/row-mappers.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const createFieldError = (field) => new Error(`Invalid ${field}`);
|
|
2
|
-
const toNumber = (value, field) => {
|
|
3
|
-
if (typeof value === 'number' && Number.isFinite(value))
|
|
4
|
-
return value;
|
|
5
|
-
if (typeof value === 'bigint') {
|
|
6
|
-
const numeric = Number(value);
|
|
7
|
-
if (Number.isFinite(numeric))
|
|
8
|
-
return numeric;
|
|
9
|
-
}
|
|
10
|
-
throw createFieldError(field);
|
|
11
|
-
};
|
|
12
|
-
export const toSafeInteger = (value, field) => {
|
|
13
|
-
const numeric = toNumber(value, field);
|
|
14
|
-
if (!Number.isSafeInteger(numeric)) {
|
|
15
|
-
throw createFieldError(field);
|
|
16
|
-
}
|
|
17
|
-
return numeric;
|
|
18
|
-
};
|
|
19
|
-
const toString = (value, field) => {
|
|
20
|
-
if (typeof value === 'string')
|
|
21
|
-
return value;
|
|
22
|
-
throw createFieldError(field);
|
|
23
|
-
};
|
|
24
|
-
const toOptionalString = (value, field) => {
|
|
25
|
-
if (value === null || value === undefined)
|
|
26
|
-
return undefined;
|
|
27
|
-
return toString(value, field);
|
|
28
|
-
};
|
|
29
|
-
const toOptionalNumber = (value, field) => {
|
|
30
|
-
if (value === null || value === undefined)
|
|
31
|
-
return undefined;
|
|
32
|
-
return toNumber(value, field);
|
|
33
|
-
};
|
|
34
|
-
export const mapRowToMemory = (row) => ({
|
|
35
|
-
id: toSafeInteger(row.id, 'id'),
|
|
36
|
-
content: toString(row.content, 'content'),
|
|
37
|
-
summary: toOptionalString(row.summary, 'summary'),
|
|
38
|
-
importance: toSafeInteger(row.importance, 'importance'),
|
|
39
|
-
memory_type: toString(row.memory_type, 'memory_type'),
|
|
40
|
-
created_at: toString(row.created_at, 'created_at'),
|
|
41
|
-
accessed_at: toString(row.accessed_at, 'accessed_at'),
|
|
42
|
-
hash: toString(row.hash, 'hash'),
|
|
43
|
-
});
|
|
44
|
-
export const mapRowToSearchResult = (row) => ({
|
|
45
|
-
...mapRowToMemory(row),
|
|
46
|
-
relevance: toOptionalNumber(row.relevance, 'relevance') ?? 0,
|
|
47
|
-
});
|
|
48
|
-
export const mapRowToRelatedMemory = (row) => ({
|
|
49
|
-
...mapRowToMemory(row),
|
|
50
|
-
relation_type: toString(row.relation_type, 'relation_type'),
|
|
51
|
-
depth: toSafeInteger(row.depth, 'depth'),
|
|
52
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"row-mappers.js","sourceRoot":"","sources":["../../src/core/row-mappers.ts"],"names":[],"mappings":"AAIA,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAS,EAAE,CAChD,IAAI,KAAK,CAAC,WAAW,KAAK,EAAE,CAAC,CAAC;AAEhC,MAAM,QAAQ,GAAG,CAAC,KAAc,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Error | undefined;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search-errors.d.ts","sourceRoot":"","sources":["../../src/core/search-errors.ts"],"names":[],"mappings":"AAsCA,eAAO,MAAM,aAAa,GAAI,KAAK,OAAO,KAAG,KAAK,GAAG,SAQpD,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const INDEX_MISSING_TOKENS = [
|
|
2
|
-
'no such module: fts5',
|
|
3
|
-
'no such table: memories_fts',
|
|
4
|
-
];
|
|
5
|
-
const QUERY_INVALID_TOKENS = ['fts5', 'syntax error'];
|
|
6
|
-
const isSearchIndexMissing = (message) => INDEX_MISSING_TOKENS.some((token) => message.includes(token));
|
|
7
|
-
const isSearchQueryInvalid = (message) => QUERY_INVALID_TOKENS.some((token) => message.includes(token));
|
|
8
|
-
const getErrorMessage = (err) => err instanceof Error ? err.message : String(err);
|
|
9
|
-
const SEARCH_ERROR_MAP = [
|
|
10
|
-
{
|
|
11
|
-
matches: isSearchIndexMissing,
|
|
12
|
-
build: () => new Error('Search index unavailable. Ensure FTS5 is enabled and the index is ' +
|
|
13
|
-
'initialized.'),
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
matches: isSearchQueryInvalid,
|
|
17
|
-
build: (message) => new Error('Invalid search query syntax. Check for unbalanced quotes or special ' +
|
|
18
|
-
'characters. ' +
|
|
19
|
-
`Details: ${message}`),
|
|
20
|
-
},
|
|
21
|
-
];
|
|
22
|
-
export const toSearchError = (err) => {
|
|
23
|
-
const message = getErrorMessage(err);
|
|
24
|
-
for (const mapping of SEARCH_ERROR_MAP) {
|
|
25
|
-
if (mapping.matches(message)) {
|
|
26
|
-
return mapping.build(message);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return undefined;
|
|
30
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search-errors.js","sourceRoot":"","sources":["../../src/core/search-errors.ts"],"names":[],"mappings":"AAAA,MAAM,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AS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/core/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AA4E9C,eAAO,MAAM,gBAAgB,GAAI,OAAO;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,KAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;CAkB7C,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,KAAK,MAAM,EACX,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAC1B,KAAK,EAWP,CAAC"}
|
package/dist/core/search.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/core/search.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B,MAAM,aAAa,GAAG,CAAC,KAAa,EAAU,EAAE;IAC9C,MAAM,KAAK,GAAG,KAAK;SAChB,IAAI,EAAE;SACN,KAAK,CAAC,KAAK,CAAC;SACZ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,KAAK,CAAC,MAAM,GAAG,gBAAgB,EA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CAAC,EAAE,GAAG,aAAa,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;IACrE,OAAO,gBAAgB,CAAC,cAAc,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,GAAW,EACX,MAA2B,EAClB,EAAE;IACX,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,UAAU,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,WAAW,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,WAAW,EAAE,CAAC;YAChB,MAAM,WAAW,CAAC;QACpB,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
package/dist/core/sqlite.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { StatementSync } from 'node:sqlite';
|
|
2
|
-
import type { DbRow } from './row-mappers.js';
|
|
3
|
-
export type SqlParam = string | number | bigint | null | Uint8Array;
|
|
4
|
-
export declare const prepareCached: (sql: string) => StatementSync;
|
|
5
|
-
export declare const executeAll: (stmt: StatementSync, ...params: SqlParam[]) => DbRow[];
|
|
6
|
-
export declare const executeGet: (stmt: StatementSync, ...params: SqlParam[]) => DbRow | undefined;
|
|
7
|
-
export declare const executeRun: (stmt: StatementSync, ...params: SqlParam[]) => {
|
|
8
|
-
changes: number | bigint;
|
|
9
|
-
};
|
|
10
|
-
export declare const withImmediateTransaction: <T>(operation: () => T) => T;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/core/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,UAAU,CAAC;AAqDpE,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,KAAG,aAW3C,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,MAAM,aAAa,EACnB,GAAG,QAAQ,QAAQ,EAAE,KACpB,KAAK,EAAuC,CAAC;AAEhD,eAAO,MAAM,UAAU,GACrB,MAAM,aAAa,EACnB,GAAG,QAAQ,QAAQ,EAAE,KACpB,KAAK,GAAG,SAAoD,CAAC;AAEhE,eAAO,MAAM,UAAU,GACrB,MAAM,aAAa,EACnB,GAAG,QAAQ,QAAQ,EAAE,KACpB;IAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;CAAsC,CAAC;AAEpE,eAAO,MAAM,wBAAwB,GAAI,CAAC,EAAE,WAAW,MAAM,CAAC,KAAG,CAUhE,CAAC"}
|
package/dist/core/sqlite.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { db } from './database.js';
|
|
2
|
-
const MAX_CACHED_STATEMENTS = 200;
|
|
3
|
-
const statementCache = new Map();
|
|
4
|
-
const statementCacheOrder = [];
|
|
5
|
-
const enforceStatementCacheLimit = () => {
|
|
6
|
-
if (statementCacheOrder.length <= MAX_CACHED_STATEMENTS)
|
|
7
|
-
return;
|
|
8
|
-
const oldestSql = statementCacheOrder.shift();
|
|
9
|
-
if (!oldestSql)
|
|
10
|
-
return;
|
|
11
|
-
statementCache.delete(oldestSql);
|
|
12
|
-
};
|
|
13
|
-
const isDbRow = (value) => {
|
|
14
|
-
return typeof value === 'object' && value !== null;
|
|
15
|
-
};
|
|
16
|
-
const toDbRowArray = (value) => {
|
|
17
|
-
if (!Array.isArray(value)) {
|
|
18
|
-
throw new Error('Expected rows array');
|
|
19
|
-
}
|
|
20
|
-
const rows = [];
|
|
21
|
-
for (const row of value) {
|
|
22
|
-
if (!isDbRow(row)) {
|
|
23
|
-
throw new Error('Invalid row');
|
|
24
|
-
}
|
|
25
|
-
rows.push(row);
|
|
26
|
-
}
|
|
27
|
-
return rows;
|
|
28
|
-
};
|
|
29
|
-
const toDbRowOrUndefined = (value) => {
|
|
30
|
-
if (value === undefined)
|
|
31
|
-
return undefined;
|
|
32
|
-
if (!isDbRow(value)) {
|
|
33
|
-
throw new Error('Invalid row');
|
|
34
|
-
}
|
|
35
|
-
return value;
|
|
36
|
-
};
|
|
37
|
-
const toRunResult = (value) => {
|
|
38
|
-
if (typeof value !== 'object' || value === null) {
|
|
39
|
-
throw new Error('Invalid run result');
|
|
40
|
-
}
|
|
41
|
-
const changes = Reflect.get(value, 'changes');
|
|
42
|
-
if (typeof changes !== 'number' && typeof changes !== 'bigint') {
|
|
43
|
-
throw new Error('Invalid run result');
|
|
44
|
-
}
|
|
45
|
-
return { changes };
|
|
46
|
-
};
|
|
47
|
-
export const prepareCached = (sql) => {
|
|
48
|
-
const cached = statementCache.get(sql);
|
|
49
|
-
if (cached)
|
|
50
|
-
return cached;
|
|
51
|
-
const stmt = db.prepare(sql);
|
|
52
|
-
statementCache.set(sql, stmt);
|
|
53
|
-
statementCacheOrder.push(sql);
|
|
54
|
-
enforceStatementCacheLimit();
|
|
55
|
-
return stmt;
|
|
56
|
-
};
|
|
57
|
-
export const executeAll = (stmt, ...params) => toDbRowArray(stmt.all(...params));
|
|
58
|
-
export const executeGet = (stmt, ...params) => toDbRowOrUndefined(stmt.get(...params));
|
|
59
|
-
export const executeRun = (stmt, ...params) => toRunResult(stmt.run(...params));
|
|
60
|
-
export const withImmediateTransaction = (operation) => {
|
|
61
|
-
db.exec('BEGIN IMMEDIATE');
|
|
62
|
-
try {
|
|
63
|
-
const result = operation();
|
|
64
|
-
db.exec('COMMIT');
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
catch (err) {
|
|
68
|
-
db.exec('ROLLBACK');
|
|
69
|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,MAAM,UAAU,GAAG,CACxB,IAAmB,EACnB,GAAG,MAAkB,EACZ,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AAEhD,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAmB,EACnB,GAAG,MAAkB,EACF,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AAEhE,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAmB,EACnB,GAAG,MAAkB,EACS,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AAEpE,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAI,SAAkB,EAAK,EAAE;IACnE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC3B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClB,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACpB,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
package/dist/core/tags.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const normalizeTags: (tags: readonly string[], maxTags: number) => string[];
|
package/dist/core/tags.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../../src/core/tags.ts"],"names":[],"mappings":"AAwBA,eAAO,MAAM,aAAa,GACxB,MAAM,SAAS,MAAM,EAAE,EACvB,SAAS,MAAM,KACd,MAAM,EAIR,CAAC"}
|
package/dist/core/tags.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const validateTag = (tag) => {
|
|
2
|
-
if (tag.length === 0) {
|
|
3
|
-
throw new Error('Tag must be at least 1 character');
|
|
4
|
-
}
|
|
5
|
-
if (tag.length > 50) {
|
|
6
|
-
throw new Error('Tag exceeds 50 characters');
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
const validateTagCount = (tags, maxTags) => {
|
|
10
|
-
if (tags.length > maxTags) {
|
|
11
|
-
throw new Error(`Too many tags (max ${maxTags})`);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
const dedupeTags = (tags) => {
|
|
15
|
-
const seen = new Set();
|
|
16
|
-
for (const tag of tags) {
|
|
17
|
-
validateTag(tag);
|
|
18
|
-
seen.add(tag);
|
|
19
|
-
}
|
|
20
|
-
return [...seen];
|
|
21
|
-
};
|
|
22
|
-
export const normalizeTags = (tags, maxTags) => {
|
|
23
|
-
if (tags.length === 0)
|
|
24
|
-
return [];
|
|
25
|
-
validateTagCount(tags, maxTags);
|
|
26
|
-
return dedupeTags(tags);
|
|
27
|
-
};
|
package/dist/core/tags.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../../src/core/tags.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,CAAC,GAAW,EAAQ,EAAE;IACxC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,IAAuB,EAAE,OAAe,EAAQ,EAAE;IAC1E,IAAI,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;IACjE,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,IAAuB,EAAY,EAAE;IACvD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,WAAW,CAAC,GAAG,CAAC,CAAC;QACjB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,IAAuB,EACvB,OAAe,EACL,EAAE;IACZ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,MAAM,E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CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,KAAK,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;AAExD,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;IAC9C,MAAM,CAAC,KAAK,CAAC,uBAAuB,MAAM,IAAI,EAAE,GAAG,CAAC,CAAC;IACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,EAAE;IAC1C,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;IAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/lib/errors.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
type ErrorResponse = CallToolResult & {
|
|
3
|
-
content: {
|
|
4
|
-
type: 'text';
|
|
5
|
-
text: string;
|
|
6
|
-
}[];
|
|
7
|
-
structuredContent: {
|
|
8
|
-
ok: false;
|
|
9
|
-
error: {
|
|
10
|
-
code: string;
|
|
11
|
-
message: string;
|
|
12
|
-
};
|
|
13
|
-
result?: unknown;
|
|
14
|
-
};
|
|
15
|
-
isError: true;
|
|
16
|
-
};
|
|
17
|
-
export declare function getErrorMessage(error: unknown): string;
|
|
18
|
-
export declare function createErrorResponse(code: string, message: string, result?: unknown): ErrorResponse;
|
|
19
|
-
export {};
|
package/dist/lib/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,KAAK,aAAa,GAAG,cAAc,GAAG;IACpC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C,iBAAiB,EAAE;QACjB,EAAE,EAAE,KAAK,CAAC;QACV,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;QACzC,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,OAAO,EAAE,IAAI,CAAC;CACf,CAAC;AAOF,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGtD;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,OAAO,GACf,aAAa,CAWf"}
|
package/dist/lib/errors.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const toNonEmptyString = (value) => {
|
|
2
|
-
if (typeof value === 'string' && value.length > 0)
|
|
3
|
-
return value;
|
|
4
|
-
return undefined;
|
|
5
|
-
};
|
|
6
|
-
export function getErrorMessage(error) {
|
|
7
|
-
if (error instanceof Error)
|
|
8
|
-
return error.message;
|
|
9
|
-
return toNonEmptyString(error) ?? 'Unknown error';
|
|
10
|
-
}
|
|
11
|
-
export function createErrorResponse(code, message, result) {
|
|
12
|
-
const structured = {
|
|
13
|
-
ok: false,
|
|
14
|
-
error: { code, message },
|
|
15
|
-
...(result !== undefined ? { result } : {}),
|
|
16
|
-
};
|
|
17
|
-
return {
|
|
18
|
-
content: [{ type: 'text', text: JSON.stringify(structured) }],
|
|
19
|
-
structuredContent: structured,
|
|
20
|
-
isError: true,
|
|
21
|
-
};
|
|
22
|
-
}
|
package/dist/lib/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAYA,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAsB,EAAE;IAC9D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAChE,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjD,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,eAAe,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,OAAe,EACf,MAAgB;IAEhB,MAAM,UAAU,GAAuC;QACrD,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;QACxB,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5C,CAAC;IACF,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7D,iBAAiB,EAAE,UAAU;QAC7B,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|