@squadrules/mcp 5.0.0-beta.1 → 5.0.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/README.md +23 -20
- package/dist/.tsbuildinfo +1 -1
- package/dist/config/embedding-fastembed.d.ts +9 -0
- package/dist/config/embedding-fastembed.d.ts.map +1 -0
- package/dist/config/embedding-fastembed.js +20 -0
- package/dist/config/embedding-fastembed.js.map +1 -0
- package/dist/config.d.ts +8 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -4
- package/dist/config.js.map +1 -1
- package/dist/embed-docs/mem/adapter-migration.md +1 -1
- package/dist/embed-docs/mem/bulk-insert-adapters-via-cli.md +1 -1
- package/dist/embed-docs/mem/challenge-type-guide.md +1 -1
- package/dist/embed-docs/mem/create-new-protocol.md +1 -1
- package/dist/embed-docs/mem/phase-critic-guide.md +1 -1
- package/dist/embed-docs/mem/phase-critic.md +1 -1
- package/dist/embed-docs/mem/protocol-linking-guide.md +1 -1
- package/dist/embed-docs/mem/refine-search.md +1 -1
- package/dist/embed-docs/mem/skill-format-guide.md +1 -1
- package/dist/http/http-api-snapshot.d.ts.map +1 -1
- package/dist/http/http-api-snapshot.js +13 -1
- package/dist/http/http-api-snapshot.js.map +1 -1
- package/dist/http/http-health-routes.d.ts.map +1 -1
- package/dist/http/http-health-routes.js +6 -3
- package/dist/http/http-health-routes.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -5
- package/dist/index.js.map +1 -1
- package/dist/resources/embedded-mcp-resources.js +9 -9
- package/dist/resources/embedded-mcp-resources.js.map +1 -1
- package/dist/resources/mem-resources-boot.d.ts.map +1 -1
- package/dist/resources/mem-resources-boot.js +2 -28
- package/dist/resources/mem-resources-boot.js.map +1 -1
- package/dist/resources/mem-uuid-mapper.d.ts.map +1 -1
- package/dist/resources/mem-uuid-mapper.js +8 -23
- package/dist/resources/mem-uuid-mapper.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +9 -7
- package/dist/server.js.map +1 -1
- package/dist/services/embedding/fastembed-provider.d.ts +2 -0
- package/dist/services/embedding/fastembed-provider.d.ts.map +1 -0
- package/dist/services/embedding/fastembed-provider.js +78 -0
- package/dist/services/embedding/fastembed-provider.js.map +1 -0
- package/dist/services/embedding/health.d.ts.map +1 -1
- package/dist/services/embedding/health.js +99 -96
- package/dist/services/embedding/health.js.map +1 -1
- package/dist/services/embedding/provider-audit.d.ts +15 -0
- package/dist/services/embedding/provider-audit.d.ts.map +1 -0
- package/dist/services/embedding/provider-audit.js +28 -0
- package/dist/services/embedding/provider-audit.js.map +1 -0
- package/dist/services/embedding/providers.d.ts +2 -1
- package/dist/services/embedding/providers.d.ts.map +1 -1
- package/dist/services/embedding/providers.js +21 -23
- package/dist/services/embedding/providers.js.map +1 -1
- package/dist/services/embedding/service.d.ts +2 -2
- package/dist/services/embedding/service.d.ts.map +1 -1
- package/dist/services/embedding/service.js +13 -16
- package/dist/services/embedding/service.js.map +1 -1
- package/dist/services/execution-trace-store.d.ts +5 -29
- package/dist/services/execution-trace-store.d.ts.map +1 -1
- package/dist/services/execution-trace-store.js +10 -2
- package/dist/services/execution-trace-store.js.map +1 -1
- package/dist/services/memory/store.d.ts +23 -0
- package/dist/services/memory/store.d.ts.map +1 -1
- package/dist/services/memory/store.js +110 -3
- package/dist/services/memory/store.js.map +1 -1
- package/dist/services/memory-store.d.ts +5 -0
- package/dist/services/memory-store.d.ts.map +1 -1
- package/dist/services/memory-store.js +5 -0
- package/dist/services/memory-store.js.map +1 -1
- package/dist/services/qdrant/service.d.ts.map +1 -1
- package/dist/services/qdrant/service.js +11 -2
- package/dist/services/qdrant/service.js.map +1 -1
- package/dist/services/vector-store/IExecutionTraceStore.d.ts +25 -0
- package/dist/services/vector-store/IExecutionTraceStore.d.ts.map +1 -0
- package/dist/services/vector-store/IExecutionTraceStore.js +2 -0
- package/dist/services/vector-store/IExecutionTraceStore.js.map +1 -0
- package/dist/services/vector-store/IVectorRecordStore.d.ts +58 -0
- package/dist/services/vector-store/IVectorRecordStore.d.ts.map +1 -0
- package/dist/services/vector-store/IVectorRecordStore.js +2 -0
- package/dist/services/vector-store/IVectorRecordStore.js.map +1 -0
- package/dist/services/vector-store/commit-retry.d.ts +21 -0
- package/dist/services/vector-store/commit-retry.d.ts.map +1 -0
- package/dist/services/vector-store/commit-retry.js +58 -0
- package/dist/services/vector-store/commit-retry.js.map +1 -0
- package/dist/services/vector-store/embedded-store-singleton.d.ts +12 -0
- package/dist/services/vector-store/embedded-store-singleton.d.ts.map +1 -0
- package/dist/services/vector-store/embedded-store-singleton.js +17 -0
- package/dist/services/vector-store/embedded-store-singleton.js.map +1 -0
- package/dist/services/vector-store/lancedb/LanceExecutionTraceStore.d.ts +28 -0
- package/dist/services/vector-store/lancedb/LanceExecutionTraceStore.d.ts.map +1 -0
- package/dist/services/vector-store/lancedb/LanceExecutionTraceStore.js +222 -0
- package/dist/services/vector-store/lancedb/LanceExecutionTraceStore.js.map +1 -0
- package/dist/services/vector-store/lancedb/LanceVectorRecordStore.d.ts +77 -0
- package/dist/services/vector-store/lancedb/LanceVectorRecordStore.d.ts.map +1 -0
- package/dist/services/vector-store/lancedb/LanceVectorRecordStore.js +136 -0
- package/dist/services/vector-store/lancedb/LanceVectorRecordStore.js.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-engine.d.ts +41 -0
- package/dist/services/vector-store/lancedb/lance-records-engine.d.ts.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-engine.js +102 -0
- package/dist/services/vector-store/lancedb/lance-records-engine.js.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-mutations.d.ts +22 -0
- package/dist/services/vector-store/lancedb/lance-records-mutations.d.ts.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-mutations.js +211 -0
- package/dist/services/vector-store/lancedb/lance-records-mutations.js.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-reads.d.ts +64 -0
- package/dist/services/vector-store/lancedb/lance-records-reads.d.ts.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-reads.js +237 -0
- package/dist/services/vector-store/lancedb/lance-records-reads.js.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-schema.d.ts +48 -0
- package/dist/services/vector-store/lancedb/lance-records-schema.d.ts.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-schema.js +159 -0
- package/dist/services/vector-store/lancedb/lance-records-schema.js.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-search.d.ts +30 -0
- package/dist/services/vector-store/lancedb/lance-records-search.d.ts.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-search.js +112 -0
- package/dist/services/vector-store/lancedb/lance-records-search.js.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-write-artifact.d.ts +11 -0
- package/dist/services/vector-store/lancedb/lance-records-write-artifact.d.ts.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-write-artifact.js +121 -0
- package/dist/services/vector-store/lancedb/lance-records-write-artifact.js.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-write-helpers.d.ts +52 -0
- package/dist/services/vector-store/lancedb/lance-records-write-helpers.d.ts.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-write-helpers.js +216 -0
- package/dist/services/vector-store/lancedb/lance-records-write-helpers.js.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-writes.d.ts +21 -0
- package/dist/services/vector-store/lancedb/lance-records-writes.d.ts.map +1 -0
- package/dist/services/vector-store/lancedb/lance-records-writes.js +294 -0
- package/dist/services/vector-store/lancedb/lance-records-writes.js.map +1 -0
- package/dist/services/vector-store/lancedb-connection.d.ts +12 -0
- package/dist/services/vector-store/lancedb-connection.d.ts.map +1 -0
- package/dist/services/vector-store/lancedb-connection.js +28 -0
- package/dist/services/vector-store/lancedb-connection.js.map +1 -0
- package/dist/services/vector-store/types.d.ts +85 -0
- package/dist/services/vector-store/types.d.ts.map +1 -0
- package/dist/services/vector-store/types.js +2 -0
- package/dist/services/vector-store/types.js.map +1 -0
- package/dist/tools/artifact-catalog.d.ts.map +1 -1
- package/dist/tools/artifact-catalog.js +6 -33
- package/dist/tools/artifact-catalog.js.map +1 -1
- package/dist/tools/search.d.ts.map +1 -1
- package/dist/tools/search.js +6 -20
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/search_schema.d.ts +1 -1
- package/dist/tools/skill-export/enumerate-space-adapters.d.ts +1 -1
- package/dist/tools/skill-export/enumerate-space-adapters.d.ts.map +1 -1
- package/dist/tools/skill-export/enumerate-space-adapters.js +11 -27
- package/dist/tools/skill-export/enumerate-space-adapters.js.map +1 -1
- package/dist/tools/spaces.d.ts.map +1 -1
- package/dist/tools/spaces.js +2 -15
- package/dist/tools/spaces.js.map +1 -1
- package/dist/ui/assets/{AccountPage-B0ali9jz.js → AccountPage-BJm56sur.js} +1 -1
- package/dist/ui/assets/{ProtocolEditPage-DIySo-F_.js → ProtocolEditPage-mChBe3JY.js} +1 -1
- package/dist/ui/assets/{RichTextEditor-uun0UIVc.js → RichTextEditor-Bj6JxHM5.js} +1 -1
- package/dist/ui/assets/{SkillBundlePage-DtOlpupj.js → SkillBundlePage-D1OPKJzA.js} +1 -1
- package/dist/ui/assets/{index-BlCipoHI.js → index-PouLvU1c.js} +2 -2
- package/dist/ui/index.html +1 -1
- package/dist/utils/squadrules-user-dirs.d.ts +10 -0
- package/dist/utils/squadrules-user-dirs.d.ts.map +1 -1
- package/dist/utils/squadrules-user-dirs.js +12 -0
- package/dist/utils/squadrules-user-dirs.js.map +1 -1
- package/package.json +18 -11
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { embeddingService } from '../../embedding/service.js';
|
|
2
|
+
import { getSearchSpaceIds } from '../../../utils/tenant-context.js';
|
|
3
|
+
import { buildSpaceFilter } from '../../../utils/space-filter.js';
|
|
4
|
+
import { SQUADRULES_CREATION_PROTOCOL_SLUG, SQUADRULES_REFINING_PROTOCOL_SLUG, memoryIsBuiltinSearchFooterProtocol } from '../../../constants/builtin-search-meta.js';
|
|
5
|
+
import { getActivationPatternVectorName, getAdapterTitleVectorName, getPrimaryVectorName } from '../../../utils/qdrant-vector-types.js';
|
|
6
|
+
import { pointToMemory } from '../../memory/qdrant-point-to-memory.js';
|
|
7
|
+
import { toNumberArray } from './lance-records-schema.js';
|
|
8
|
+
const TITLE_MATCH_BOOST = 0.45;
|
|
9
|
+
const ACTIVATION_PATTERN_MATCH_BOOST = 0.35;
|
|
10
|
+
const LABEL_MATCH_BOOST = 0.15;
|
|
11
|
+
const TAG_MATCH_BOOST = 0.05;
|
|
12
|
+
function payloadOf(row) {
|
|
13
|
+
return JSON.parse(row.payload);
|
|
14
|
+
}
|
|
15
|
+
function cosine(a, b) {
|
|
16
|
+
if (!a || !b || a.length === 0 || a.length !== b.length)
|
|
17
|
+
return 0;
|
|
18
|
+
let dot = 0;
|
|
19
|
+
let na = 0;
|
|
20
|
+
let nb = 0;
|
|
21
|
+
for (let i = 0; i < a.length; i++) {
|
|
22
|
+
const x = a[i];
|
|
23
|
+
const y = b[i];
|
|
24
|
+
dot += x * y;
|
|
25
|
+
na += x * x;
|
|
26
|
+
nb += y * y;
|
|
27
|
+
}
|
|
28
|
+
if (na === 0 || nb === 0)
|
|
29
|
+
return 0;
|
|
30
|
+
return dot / (Math.sqrt(na) * Math.sqrt(nb));
|
|
31
|
+
}
|
|
32
|
+
function tokenize(text) {
|
|
33
|
+
return new Set((text || '').toLowerCase().split(/[^a-z0-9]+/).filter(Boolean));
|
|
34
|
+
}
|
|
35
|
+
/** Fraction of the query tokens present in the field text, capped to [0,1]. */
|
|
36
|
+
function textMatch(queryTokens, fieldText) {
|
|
37
|
+
if (queryTokens.size === 0)
|
|
38
|
+
return 0;
|
|
39
|
+
const field = tokenize(fieldText);
|
|
40
|
+
let hits = 0;
|
|
41
|
+
for (const token of queryTokens)
|
|
42
|
+
if (field.has(token))
|
|
43
|
+
hits++;
|
|
44
|
+
return Math.min(hits / queryTokens.size, 1);
|
|
45
|
+
}
|
|
46
|
+
function headFilter() {
|
|
47
|
+
const base = buildSpaceFilter(getSearchSpaceIds(), {
|
|
48
|
+
must: [{ key: 'adapter.layer_index', match: { value: 1 } }]
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
...base,
|
|
52
|
+
must_not: [{ key: 'slug', match: { any: [SQUADRULES_REFINING_PROTOCOL_SLUG, SQUADRULES_CREATION_PROTOCOL_SLUG] } }]
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function finalize(scored, limit, fallbackScore) {
|
|
56
|
+
let filtered = scored
|
|
57
|
+
.filter((e) => e.score > 0 && !memoryIsBuiltinSearchFooterProtocol(e.memory))
|
|
58
|
+
.sort((a, b) => (b.score !== a.score ? b.score - a.score : (a.memory.memory_uuid ?? '').localeCompare(b.memory.memory_uuid ?? '')))
|
|
59
|
+
.slice(0, limit);
|
|
60
|
+
if (filtered.length === 0 && scored.length > 0 && fallbackScore !== null) {
|
|
61
|
+
filtered = scored
|
|
62
|
+
.filter((e) => !memoryIsBuiltinSearchFooterProtocol(e.memory))
|
|
63
|
+
.slice(0, limit)
|
|
64
|
+
.map((e) => ({ memory: e.memory, score: fallbackScore }));
|
|
65
|
+
}
|
|
66
|
+
return { memories: filtered.map((e) => e.memory), scores: filtered.map((e) => e.score) };
|
|
67
|
+
}
|
|
68
|
+
export class LanceRecordSearch {
|
|
69
|
+
engine;
|
|
70
|
+
constructor(engine) {
|
|
71
|
+
this.engine = engine;
|
|
72
|
+
}
|
|
73
|
+
/** Full hybrid-style ranking over the three dense legs + text boosts. */
|
|
74
|
+
async searchMemories(query, limit) {
|
|
75
|
+
const queryKey = (query || '').trim();
|
|
76
|
+
if (!queryKey)
|
|
77
|
+
return { memories: [], scores: [] };
|
|
78
|
+
const { embedding: queryVector } = await embeddingService.generateEmbedding(queryKey);
|
|
79
|
+
const primaryName = getPrimaryVectorName(queryVector.length);
|
|
80
|
+
const titleName = getAdapterTitleVectorName(queryVector.length);
|
|
81
|
+
const activationName = getActivationPatternVectorName(queryVector.length);
|
|
82
|
+
const queryTokens = tokenize(queryKey);
|
|
83
|
+
const rows = await this.engine.scroll(headFilter());
|
|
84
|
+
const scored = rows.map((row) => {
|
|
85
|
+
const payload = payloadOf(row);
|
|
86
|
+
const memory = pointToMemory({ id: row.id, payload });
|
|
87
|
+
const score = cosine(queryVector, toNumberArray(row[primaryName])) +
|
|
88
|
+
TITLE_MATCH_BOOST * cosine(queryVector, toNumberArray(row[titleName])) +
|
|
89
|
+
ACTIVATION_PATTERN_MATCH_BOOST * cosine(queryVector, toNumberArray(row[activationName])) +
|
|
90
|
+
LABEL_MATCH_BOOST * textMatch(queryTokens, typeof payload.label_text === 'string' ? payload.label_text : payload.label || '') +
|
|
91
|
+
TAG_MATCH_BOOST * textMatch(queryTokens, typeof payload.tags_text === 'string' ? payload.tags_text : (payload.tags || []).join(' ')) +
|
|
92
|
+
(typeof payload.attest_boost === 'number' ? payload.attest_boost : 0);
|
|
93
|
+
return { memory, score };
|
|
94
|
+
});
|
|
95
|
+
return finalize(scored, limit, 0.5);
|
|
96
|
+
}
|
|
97
|
+
/** Adapter-title similarity gate (mirrors `searchAdapterTitlesBySimilarity`). */
|
|
98
|
+
async searchAdapterTitlesBySimilarity(query, limit) {
|
|
99
|
+
const queryKey = (query || '').trim();
|
|
100
|
+
if (!queryKey)
|
|
101
|
+
return { memories: [], scores: [] };
|
|
102
|
+
const { embedding: queryVector } = await embeddingService.generateEmbedding(queryKey);
|
|
103
|
+
const titleName = getAdapterTitleVectorName(queryVector.length);
|
|
104
|
+
const rows = await this.engine.scroll(headFilter());
|
|
105
|
+
const scored = rows.map((row) => ({
|
|
106
|
+
memory: pointToMemory({ id: row.id, payload: payloadOf(row) }),
|
|
107
|
+
score: cosine(queryVector, toNumberArray(row[titleName]))
|
|
108
|
+
}));
|
|
109
|
+
return finalize(scored, limit, null);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=lance-records-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lance-records-search.js","sourceRoot":"","sources":["../../../../src/services/vector-store/lancedb/lance-records-search.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EACL,iCAAiC,EACjC,iCAAiC,EACjC,mCAAmC,EACpC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,8BAA8B,EAC9B,yBAAyB,EACzB,oBAAoB,EACrB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAEvE,OAAO,EAAE,aAAa,EAAuB,MAAM,2BAA2B,CAAC;AAE/E,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAC/B,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAC5C,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAC/B,MAAM,eAAe,GAAG,IAAI,CAAC;AAI7B,SAAS,SAAS,CAAC,GAAmB;IACpC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAA4B,CAAC;AAC5D,CAAC;AAED,SAAS,MAAM,CAAC,CAAkB,EAAE,CAAkB;IACpD,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,CAAC,CAAC;IAClE,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,MAAM,CAAC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nD,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,MAAM,gBAAgB,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QACtF,MAAM,SAAS,GAAG,yBAAyB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAChE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QACpD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAChC,MAAM,EAAE,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9D,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;SAC1D,CAAC,CAAC,CAAC;QACJ,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Memory } from '../../../types/memory.js';
|
|
2
|
+
import type { StoreArtifactOptions } from '../../memory/store-adapter.js';
|
|
3
|
+
import type { LanceRecordEngine } from './lance-records-engine.js';
|
|
4
|
+
import type { LanceWriteRepo } from './lance-records-write-helpers.js';
|
|
5
|
+
export declare class LanceArtifactWriter {
|
|
6
|
+
private readonly engine;
|
|
7
|
+
private readonly repo;
|
|
8
|
+
constructor(engine: LanceRecordEngine, repo: LanceWriteRepo);
|
|
9
|
+
storeArtifact(content: string, options: StoreArtifactOptions): Promise<Memory[]>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=lance-records-write-artifact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lance-records-write-artifact.d.ts","sourceRoot":"","sources":["../../../../src/services/vector-store/lancedb/lance-records-write-artifact.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAavD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAGvE,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAqB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAhD,MAAM,EAAE,iBAAiB,EAAmB,IAAI,EAAE,cAAc;IAEvF,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAoGvF"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lance artifact write path.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors `store-artifact.ts` exactly — chain-id normalization, artifact
|
|
5
|
+
* metadata + sha256, duplicate detection by slug/name, created-at/by preservation
|
|
6
|
+
* on force-update, and the zero-vector dense columns (artifacts carry no learned
|
|
7
|
+
* embeddings) — but persists through the Lance engine and resolves adapter anchors
|
|
8
|
+
* via `LanceWriteRepo`. Keeping the returned `Memory` shape identical means artifact
|
|
9
|
+
* export/search behaves the same as on Qdrant.
|
|
10
|
+
*/
|
|
11
|
+
import crypto from 'node:crypto';
|
|
12
|
+
import { logger } from '../../../utils/structured-logger.js';
|
|
13
|
+
import { getEmbeddingDimension } from '../../embedding/config.js';
|
|
14
|
+
import { bm25Tokenizer } from '../../embedding/bm25-tokenizer.js';
|
|
15
|
+
import { getActivationPatternVectorName, getAdapterTitleVectorName, getPrimaryVectorName } from '../../../utils/qdrant-vector-types.js';
|
|
16
|
+
import { getSpaceContext } from '../../../utils/tenant-context.js';
|
|
17
|
+
import { redisCacheService } from '../../redis-cache.js';
|
|
18
|
+
import { parseSquadrulesUri } from '../../../tools/squadrules-uri.js';
|
|
19
|
+
import { extractArtifactMetadata } from '../../memory/artifact-metadata.js';
|
|
20
|
+
export class LanceArtifactWriter {
|
|
21
|
+
engine;
|
|
22
|
+
repo;
|
|
23
|
+
constructor(engine, repo) {
|
|
24
|
+
this.engine = engine;
|
|
25
|
+
this.repo = repo;
|
|
26
|
+
}
|
|
27
|
+
async storeArtifact(content, options) {
|
|
28
|
+
const parsed = parseSquadrulesUri(options.adapterUri);
|
|
29
|
+
if (parsed.kind !== 'adapter') {
|
|
30
|
+
throw new Error('adapterUri must be a squadrules://adapter/{slug|uuid} URI');
|
|
31
|
+
}
|
|
32
|
+
const { adapterId, adapterName } = await this.repo.resolveChainAdapterIdForArtifacts(parsed);
|
|
33
|
+
const slugSourceInput = typeof options.relativePath === 'string' && options.relativePath.trim().length > 0 ? options.relativePath.trim() : options.name;
|
|
34
|
+
const artifact = extractArtifactMetadata(content, slugSourceInput);
|
|
35
|
+
const sha256 = crypto.createHash('sha256').update(content, 'utf8').digest('hex');
|
|
36
|
+
const vectorSize = getEmbeddingDimension();
|
|
37
|
+
const zeroVector = Array.from({ length: vectorSize }, () => 0);
|
|
38
|
+
const context = getSpaceContext();
|
|
39
|
+
const spaceId = context.defaultWriteSpaceId;
|
|
40
|
+
const actorId = context.userId || 'system';
|
|
41
|
+
const now = new Date().toISOString();
|
|
42
|
+
const normalizedArtifactName = options.name.trim().toLowerCase();
|
|
43
|
+
const existingPoints = await this.repo.listExistingArtifactPoints(spaceId, adapterId);
|
|
44
|
+
const matchingPoints = existingPoints.filter((point) => {
|
|
45
|
+
const artifactPayload = (point.payload['artifact'] ?? {});
|
|
46
|
+
const existingSlug = typeof artifactPayload['slug'] === 'string' ? artifactPayload['slug'].trim().toLowerCase() : '';
|
|
47
|
+
const existingName = typeof artifactPayload['name'] === 'string' ? artifactPayload['name'].trim().toLowerCase() : '';
|
|
48
|
+
if (artifact.slug_source === 'header')
|
|
49
|
+
return existingSlug === artifact.slug.toLowerCase();
|
|
50
|
+
return existingName === normalizedArtifactName || existingSlug === artifact.slug.toLowerCase();
|
|
51
|
+
});
|
|
52
|
+
matchingPoints.sort((a, b) => a.id.localeCompare(b.id));
|
|
53
|
+
if (matchingPoints.length > 0 && !options.forceUpdate) {
|
|
54
|
+
throw new Error(`Artifact "${options.name}" already exists on this adapter`);
|
|
55
|
+
}
|
|
56
|
+
const existingPoint = options.forceUpdate ? matchingPoints[0] : undefined;
|
|
57
|
+
const existingCreatedAt = typeof existingPoint?.payload['created_at'] === 'string' && existingPoint.payload['created_at'].trim().length > 0
|
|
58
|
+
? existingPoint.payload['created_at'].trim()
|
|
59
|
+
: now;
|
|
60
|
+
const existingCreatedBy = typeof existingPoint?.payload['created_by'] === 'string' && existingPoint.payload['created_by'].trim().length > 0
|
|
61
|
+
? existingPoint.payload['created_by'].trim()
|
|
62
|
+
: actorId;
|
|
63
|
+
const memoryUuid = existingPoint?.id ?? crypto.randomUUID();
|
|
64
|
+
const tags = ['artifact', options.mime.replace('text/', ''), `artifact:${artifact.slug}`];
|
|
65
|
+
const sparseText = `${options.name}\n${artifact.slug}\n${content.slice(0, 4096)}`;
|
|
66
|
+
const bm25 = bm25Tokenizer.tokenize(sparseText);
|
|
67
|
+
const point = {
|
|
68
|
+
id: memoryUuid,
|
|
69
|
+
vector: {
|
|
70
|
+
[getPrimaryVectorName(vectorSize)]: zeroVector,
|
|
71
|
+
[getAdapterTitleVectorName(vectorSize)]: zeroVector,
|
|
72
|
+
[getActivationPatternVectorName(vectorSize)]: zeroVector,
|
|
73
|
+
bm25: { indices: bm25.indices, values: bm25.values }
|
|
74
|
+
},
|
|
75
|
+
payload: {
|
|
76
|
+
space_id: spaceId,
|
|
77
|
+
label: options.name,
|
|
78
|
+
tags,
|
|
79
|
+
text: content,
|
|
80
|
+
llm_model_id: options.llmModelId,
|
|
81
|
+
created_at: existingCreatedAt,
|
|
82
|
+
created_by: existingCreatedBy,
|
|
83
|
+
modified_at: now,
|
|
84
|
+
modified_by: actorId,
|
|
85
|
+
content_type: options.mime,
|
|
86
|
+
artifact: {
|
|
87
|
+
slug: artifact.slug,
|
|
88
|
+
version: artifact.version,
|
|
89
|
+
name: options.name,
|
|
90
|
+
sha256,
|
|
91
|
+
...(typeof options.relativePath === 'string' && options.relativePath.trim().length > 0 ? { relative_path: options.relativePath.trim() } : {})
|
|
92
|
+
},
|
|
93
|
+
adapter: { id: adapterId, name: adapterName ?? options.name }
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
await this.engine.putPoints([point]);
|
|
97
|
+
logger.tool('lance-store', 'upsert', `artifact adapter=${adapterId} slug=${artifact.slug}`);
|
|
98
|
+
await redisCacheService.invalidateAfterUpdate();
|
|
99
|
+
return [
|
|
100
|
+
{
|
|
101
|
+
memory_uuid: memoryUuid,
|
|
102
|
+
space_id: spaceId,
|
|
103
|
+
label: options.name,
|
|
104
|
+
tags,
|
|
105
|
+
text: content,
|
|
106
|
+
llm_model_id: options.llmModelId,
|
|
107
|
+
created_at: now,
|
|
108
|
+
content_type: options.mime,
|
|
109
|
+
artifact: {
|
|
110
|
+
slug: artifact.slug,
|
|
111
|
+
version: artifact.version,
|
|
112
|
+
name: options.name,
|
|
113
|
+
sha256,
|
|
114
|
+
...(typeof options.relativePath === 'string' && options.relativePath.trim().length > 0 ? { relative_path: options.relativePath.trim() } : {})
|
|
115
|
+
},
|
|
116
|
+
adapter: { id: adapterId, name: adapterName ?? options.name, layer_index: 0, layer_count: 0 }
|
|
117
|
+
}
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=lance-records-write-artifact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lance-records-write-artifact.js","sourceRoot":"","sources":["../../../../src/services/vector-store/lancedb/lance-records-write-artifact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,MAA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EAAE,WAAW,IAAI,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE;aAC9F;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type AdapterSlugMintInput } from '../../memory/store-adapter-helpers.js';
|
|
2
|
+
import type { LanceRecordEngine } from './lance-records-engine.js';
|
|
3
|
+
import type { LanceRecordSearch } from './lance-records-search.js';
|
|
4
|
+
export declare class LanceWriteRepo {
|
|
5
|
+
private readonly engine;
|
|
6
|
+
private readonly search;
|
|
7
|
+
constructor(engine: LanceRecordEngine, search: LanceRecordSearch);
|
|
8
|
+
/** Points already stored under this adapter id (duplicate check). */
|
|
9
|
+
checkDuplicateAdapter(adapterUuid: string): Promise<{
|
|
10
|
+
points: Array<{
|
|
11
|
+
id: string;
|
|
12
|
+
payload: any;
|
|
13
|
+
}>;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Replace-or-reject an existing adapter. Mirrors `handleDuplicateAdapter`: throw
|
|
17
|
+
* DUPLICATE_ADAPTER unless force_update, block writes into protected spaces, then
|
|
18
|
+
* delete the old adapter rows so the mint re-creates a clean chain.
|
|
19
|
+
*/
|
|
20
|
+
handleDuplicateAdapter(adapterUuid: string, forceUpdate: boolean): Promise<void>;
|
|
21
|
+
/** Slug collision scan within allowed spaces. */
|
|
22
|
+
scrollPointsWithSlug(slug: string): Promise<Array<{
|
|
23
|
+
id: string;
|
|
24
|
+
payload: any;
|
|
25
|
+
}>>;
|
|
26
|
+
/** Allocate a non-colliding slug (author exact-collision rejects; auto appends -2, -3…). */
|
|
27
|
+
allocateAdapterSlugForMint(input: AdapterSlugMintInput, newAdapterUuid: string): Promise<string>;
|
|
28
|
+
/** Title-similarity guard before mint (throws SIMILAR_MEMORY_FOUND above threshold). */
|
|
29
|
+
checkSimilarAdapterByTitle(adapterTitle: string, forceUpdate: boolean): Promise<void>;
|
|
30
|
+
/** Resolve an adapter head point id by slug (lowest id wins). */
|
|
31
|
+
resolveAdapterAnchorPointId(slug: string): Promise<string | null>;
|
|
32
|
+
resolveAdapterNameByAdapterId(adapterId: string): Promise<string | null>;
|
|
33
|
+
/** Normalize a slug / layer-id / chain-id adapter reference to its chain id + name. */
|
|
34
|
+
resolveChainAdapterIdForArtifacts(parsed: {
|
|
35
|
+
id: string;
|
|
36
|
+
idKind?: string;
|
|
37
|
+
}): Promise<{
|
|
38
|
+
adapterId: string;
|
|
39
|
+
adapterName: string | null;
|
|
40
|
+
}>;
|
|
41
|
+
/** Existing artifact points for an adapter+space (for duplicate detection). */
|
|
42
|
+
listExistingArtifactPoints(spaceId: string, adapterId: string): Promise<Array<{
|
|
43
|
+
id: string;
|
|
44
|
+
payload: any;
|
|
45
|
+
}>>;
|
|
46
|
+
/** Re-export domain/task/type for the writer's per-memory metric loop. */
|
|
47
|
+
deriveDomainTaskType(label: string, text: string, tags: string[]): {
|
|
48
|
+
task: string;
|
|
49
|
+
type: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=lance-records-write-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lance-records-write-helpers.d.ts","sourceRoot":"","sources":["../../../../src/services/vector-store/lancedb/lance-records-write-helpers.ts"],"names":[],"mappings":"AAqBA,OAAO,EAA2D,KAAK,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC3I,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAYnE,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAqB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAlD,MAAM,EAAE,iBAAiB,EAAmB,MAAM,EAAE,iBAAiB;IAElG,qEAAqE;IAC/D,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,OA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AC1E,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;CAGlG"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lance write-path primitives.
|
|
3
|
+
*
|
|
4
|
+
* The Qdrant store/adapter handlers reach the index through three client calls —
|
|
5
|
+
* `scroll` (duplicate + slug collision), `delete` (force-update replace) and the
|
|
6
|
+
* title-similarity search — plus a handful of artifact anchor lookups. This module
|
|
7
|
+
* reimplements exactly those over the Lance engine and the JS-cosine searcher, so
|
|
8
|
+
* the higher-level writer can reuse the backend-neutral parsing/build helpers
|
|
9
|
+
* (`resolveProtocolSlugCandidate`, `deriveDomainTaskType`, `buildHeaderMemoryAdapter`,
|
|
10
|
+
* embeddings) unchanged and produce a store that reads/searches with the same
|
|
11
|
+
* contract as Qdrant. Payload semantics (protected-space guard, duplicate/slug error
|
|
12
|
+
* codes, similarity threshold, artifact anchor resolution) are mirrored verbatim.
|
|
13
|
+
*/
|
|
14
|
+
import { SIMILAR_MEMORY_THRESHOLD } from '../../../config.js';
|
|
15
|
+
import { getSpaceContext, getSearchSpaceIds } from '../../../utils/tenant-context.js';
|
|
16
|
+
import { buildSpaceFilter } from '../../../utils/space-filter.js';
|
|
17
|
+
import { isProtectedWriteSpace, protectedWriteErrorMessage } from '../../../utils/protected-space-write-guard.js';
|
|
18
|
+
import { SquadrulesError } from '../../../types/index.js';
|
|
19
|
+
import { buildAdapterUri, buildLayerUri } from '../../../tools/squadrules-uri.js';
|
|
20
|
+
import { MAX_AUTO_SUFFIX_ATTEMPTS, nextAutoSlugCandidate } from '../../../utils/protocol-slug.js';
|
|
21
|
+
import { ALLOWED_ARTIFACT_MIMES } from '../../../tools/artifact-mime.js';
|
|
22
|
+
import { deriveDomainTaskType, buildAdapterSimilaritySearchQuery } from '../../memory/store-adapter-helpers.js';
|
|
23
|
+
function payloadOf(row) {
|
|
24
|
+
return JSON.parse(row.payload);
|
|
25
|
+
}
|
|
26
|
+
function adapterIdOf(payload) {
|
|
27
|
+
const id = payload?.adapter?.id;
|
|
28
|
+
return typeof id === 'string' && id.length > 0 ? id : undefined;
|
|
29
|
+
}
|
|
30
|
+
export class LanceWriteRepo {
|
|
31
|
+
engine;
|
|
32
|
+
search;
|
|
33
|
+
constructor(engine, search) {
|
|
34
|
+
this.engine = engine;
|
|
35
|
+
this.search = search;
|
|
36
|
+
}
|
|
37
|
+
/** Points already stored under this adapter id (duplicate check). */
|
|
38
|
+
async checkDuplicateAdapter(adapterUuid) {
|
|
39
|
+
const filter = buildSpaceFilter(getSpaceContext().allowedSpaceIds, {
|
|
40
|
+
must: [{ key: 'adapter.id', match: { value: adapterUuid } }]
|
|
41
|
+
});
|
|
42
|
+
const rows = await this.engine.scroll(filter, 256);
|
|
43
|
+
return { points: rows.map((r) => ({ id: r.id, payload: payloadOf(r) })) };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Replace-or-reject an existing adapter. Mirrors `handleDuplicateAdapter`: throw
|
|
47
|
+
* DUPLICATE_ADAPTER unless force_update, block writes into protected spaces, then
|
|
48
|
+
* delete the old adapter rows so the mint re-creates a clean chain.
|
|
49
|
+
*/
|
|
50
|
+
async handleDuplicateAdapter(adapterUuid, forceUpdate) {
|
|
51
|
+
const dup = await this.checkDuplicateAdapter(adapterUuid);
|
|
52
|
+
if (dup.points.length === 0)
|
|
53
|
+
return;
|
|
54
|
+
if (!forceUpdate) {
|
|
55
|
+
const items = dup.points.map((p) => ({ label: p.payload?.label || 'Memory', uri: buildLayerUri(p.id) }));
|
|
56
|
+
throw new SquadrulesError('Duplicate adapter', 'DUPLICATE_ADAPTER', 409, { adapter_id: adapterUuid, items });
|
|
57
|
+
}
|
|
58
|
+
const protectedEntries = dup.points.filter((p) => isProtectedWriteSpace(typeof p.payload?.space_id === 'string' ? p.payload.space_id : ''));
|
|
59
|
+
if (protectedEntries.length > 0) {
|
|
60
|
+
const items = protectedEntries.map((p) => ({
|
|
61
|
+
label: p.payload?.label || 'Memory',
|
|
62
|
+
uri: buildLayerUri(p.id),
|
|
63
|
+
space_id: typeof p.payload?.space_id === 'string' ? p.payload.space_id : undefined
|
|
64
|
+
}));
|
|
65
|
+
const firstSpaceId = typeof protectedEntries[0]?.payload?.space_id === 'string' ? protectedEntries[0].payload.space_id : undefined;
|
|
66
|
+
throw new SquadrulesError(protectedWriteErrorMessage(firstSpaceId), 'PROTECTED_SPACE_WRITE_FORBIDDEN', 403, { adapter_id: adapterUuid, items });
|
|
67
|
+
}
|
|
68
|
+
const filter = buildSpaceFilter(getSpaceContext().allowedSpaceIds, {
|
|
69
|
+
must: [{ key: 'adapter.id', match: { value: adapterUuid } }]
|
|
70
|
+
});
|
|
71
|
+
await this.engine.deleteByFilter(filter);
|
|
72
|
+
}
|
|
73
|
+
/** Slug collision scan within allowed spaces. */
|
|
74
|
+
async scrollPointsWithSlug(slug) {
|
|
75
|
+
const filter = buildSpaceFilter(getSpaceContext().allowedSpaceIds, { must: [{ key: 'slug', match: { value: slug } }] });
|
|
76
|
+
const rows = await this.engine.scroll(filter, 24);
|
|
77
|
+
return rows.map((r) => ({ id: r.id, payload: payloadOf(r) }));
|
|
78
|
+
}
|
|
79
|
+
/** Allocate a non-colliding slug (author exact-collision rejects; auto appends -2, -3…). */
|
|
80
|
+
async allocateAdapterSlugForMint(input, newAdapterUuid) {
|
|
81
|
+
const { slug: baseSlug, authorSupplied } = input;
|
|
82
|
+
const usedByOtherAdapter = async (candidate) => {
|
|
83
|
+
const hits = await this.scrollPointsWithSlug(candidate);
|
|
84
|
+
for (const h of hits) {
|
|
85
|
+
const adapterId = adapterIdOf(h.payload);
|
|
86
|
+
if (adapterId && adapterId !== newAdapterUuid) {
|
|
87
|
+
return { otherAdapterId: adapterId, sample_uri: buildLayerUri(h.id) };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
};
|
|
92
|
+
if (authorSupplied) {
|
|
93
|
+
const clash = await usedByOtherAdapter(baseSlug);
|
|
94
|
+
if (clash) {
|
|
95
|
+
throw new SquadrulesError(`Slug "${baseSlug}" is already used by another protocol in this space.`, 'DUPLICATE_SLUG', 409, { slug: baseSlug, adapter_id: clash.otherAdapterId, sample_uri: clash.sample_uri });
|
|
96
|
+
}
|
|
97
|
+
return baseSlug;
|
|
98
|
+
}
|
|
99
|
+
for (let attempt = 1; attempt <= MAX_AUTO_SUFFIX_ATTEMPTS; attempt++) {
|
|
100
|
+
const candidate = nextAutoSlugCandidate(baseSlug, attempt);
|
|
101
|
+
const clash = await usedByOtherAdapter(candidate);
|
|
102
|
+
if (!clash)
|
|
103
|
+
return candidate;
|
|
104
|
+
}
|
|
105
|
+
throw new SquadrulesError(`Could not allocate a unique slug from "${baseSlug}" after ${MAX_AUTO_SUFFIX_ATTEMPTS} attempts.`, 'SLUG_ALLOCATION_EXHAUSTED', 409, { base_slug: baseSlug });
|
|
106
|
+
}
|
|
107
|
+
/** Title-similarity guard before mint (throws SIMILAR_MEMORY_FOUND above threshold). */
|
|
108
|
+
async checkSimilarAdapterByTitle(adapterTitle, forceUpdate) {
|
|
109
|
+
if (forceUpdate)
|
|
110
|
+
return;
|
|
111
|
+
const label = buildAdapterSimilaritySearchQuery(adapterTitle);
|
|
112
|
+
const { memories, scores } = await this.search.searchAdapterTitlesBySimilarity(label, 10);
|
|
113
|
+
if (memories.length === 0 || scores.length === 0)
|
|
114
|
+
return;
|
|
115
|
+
let bestMatch = memories[0];
|
|
116
|
+
let bestScore = scores[0] ?? 0;
|
|
117
|
+
for (let i = 1; i < memories.length; i++) {
|
|
118
|
+
const score = scores[i] ?? 0;
|
|
119
|
+
if (score > bestScore) {
|
|
120
|
+
bestScore = score;
|
|
121
|
+
bestMatch = memories[i];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (bestScore < SIMILAR_MEMORY_THRESHOLD)
|
|
125
|
+
return;
|
|
126
|
+
const adapterUri = bestMatch.adapter?.id ? buildAdapterUri(bestMatch.adapter.id) : buildLayerUri(bestMatch.memory_uuid ?? '');
|
|
127
|
+
const existingMemory = {
|
|
128
|
+
uri: buildLayerUri(bestMatch.memory_uuid ?? ''),
|
|
129
|
+
memory_uuid: bestMatch.memory_uuid,
|
|
130
|
+
label: bestMatch.label,
|
|
131
|
+
adapter_name: bestMatch.adapter?.name ?? null,
|
|
132
|
+
score: bestScore,
|
|
133
|
+
layer_count: bestMatch.adapter?.layer_count ?? 1
|
|
134
|
+
};
|
|
135
|
+
const next_action = `call export with ${adapterUri} and format "markdown" for flat Markdown to inspect the similar adapter. If your markdown uses the same adapter id, call train with force_update: true to replace that adapter; otherwise pick a distinct adapter title (H1)`;
|
|
136
|
+
const content_preview = [bestMatch.label, bestMatch.text].filter(Boolean).join('\n').slice(0, 300);
|
|
137
|
+
const matchedAdapterName = bestMatch.adapter?.name ?? bestMatch.label;
|
|
138
|
+
throw new SquadrulesError('Similar memory found by title', 'SIMILAR_MEMORY_FOUND', 409, {
|
|
139
|
+
existing_memory: existingMemory,
|
|
140
|
+
similarity_score: bestScore,
|
|
141
|
+
message: `Adapter title similar to existing "${matchedAdapterName}" (${Math.round(bestScore * 100)}% match). Verify or use force_update: true with the same adapter id to replace.`,
|
|
142
|
+
must_obey: true,
|
|
143
|
+
next_action,
|
|
144
|
+
content_preview
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** Resolve an adapter head point id by slug (lowest id wins). */
|
|
148
|
+
async resolveAdapterAnchorPointId(slug) {
|
|
149
|
+
const normalized = (slug || '').trim().toLowerCase();
|
|
150
|
+
if (!normalized)
|
|
151
|
+
return null;
|
|
152
|
+
const filter = buildSpaceFilter(getSearchSpaceIds(), {
|
|
153
|
+
must: [{ key: 'slug', match: { value: normalized } }, { key: 'adapter.layer_index', match: { value: 1 } }]
|
|
154
|
+
});
|
|
155
|
+
const rows = await this.engine.scroll(filter);
|
|
156
|
+
if (rows.length === 0)
|
|
157
|
+
return null;
|
|
158
|
+
const ids = rows.map((r) => r.id).sort((a, b) => a.localeCompare(b));
|
|
159
|
+
return ids[0] ?? null;
|
|
160
|
+
}
|
|
161
|
+
async resolveAdapterNameByAdapterId(adapterId) {
|
|
162
|
+
const filter = buildSpaceFilter(getSearchSpaceIds(), {
|
|
163
|
+
must: [{ key: 'adapter.id', match: { value: adapterId } }, { key: 'adapter.layer_index', match: { value: 1 } }]
|
|
164
|
+
});
|
|
165
|
+
const rows = await this.engine.scroll(filter, 1);
|
|
166
|
+
const payload = rows[0] ? payloadOf(rows[0]) : {};
|
|
167
|
+
const name = payload?.adapter?.name;
|
|
168
|
+
if (typeof name === 'string' && name.trim().length > 0)
|
|
169
|
+
return name.trim();
|
|
170
|
+
if (typeof payload?.label === 'string' && payload.label.trim().length > 0)
|
|
171
|
+
return payload.label.trim();
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
/** Normalize a slug / layer-id / chain-id adapter reference to its chain id + name. */
|
|
175
|
+
async resolveChainAdapterIdForArtifacts(parsed) {
|
|
176
|
+
if (parsed.idKind === 'slug') {
|
|
177
|
+
const headPointId = await this.resolveAdapterAnchorPointId(parsed.id);
|
|
178
|
+
if (!headPointId)
|
|
179
|
+
throw new Error(`Adapter slug "${parsed.id}" was not found for artifact attachment`);
|
|
180
|
+
const row = await this.engine.retrieveRaw(headPointId);
|
|
181
|
+
const payload = row ? payloadOf(row) : {};
|
|
182
|
+
const adapterId = typeof payload?.adapter?.id === 'string' && payload.adapter.id.length > 0 ? payload.adapter.id : headPointId;
|
|
183
|
+
const adapterName = typeof payload?.adapter?.name === 'string' && payload.adapter.name.trim().length > 0
|
|
184
|
+
? payload.adapter.name.trim()
|
|
185
|
+
: await this.resolveAdapterNameByAdapterId(adapterId);
|
|
186
|
+
return { adapterId, adapterName };
|
|
187
|
+
}
|
|
188
|
+
const row = await this.engine.retrieveRaw(parsed.id);
|
|
189
|
+
const payload = row ? payloadOf(row) : {};
|
|
190
|
+
const nameFromRow = typeof payload?.adapter?.name === 'string' && payload.adapter.name.trim().length > 0 ? payload.adapter.name.trim() : null;
|
|
191
|
+
const idFromRow = typeof payload?.adapter?.id === 'string' && payload.adapter.id.length > 0 ? payload.adapter.id : null;
|
|
192
|
+
if (idFromRow) {
|
|
193
|
+
const adapterName = nameFromRow ?? (await this.resolveAdapterNameByAdapterId(idFromRow));
|
|
194
|
+
return { adapterId: idFromRow, adapterName };
|
|
195
|
+
}
|
|
196
|
+
const adapterName = nameFromRow ?? (await this.resolveAdapterNameByAdapterId(parsed.id));
|
|
197
|
+
return { adapterId: parsed.id, adapterName };
|
|
198
|
+
}
|
|
199
|
+
/** Existing artifact points for an adapter+space (for duplicate detection). */
|
|
200
|
+
async listExistingArtifactPoints(spaceId, adapterId) {
|
|
201
|
+
const filter = buildSpaceFilter(getSearchSpaceIds(), {
|
|
202
|
+
must: [
|
|
203
|
+
{ key: 'space_id', match: { value: spaceId } },
|
|
204
|
+
{ key: 'adapter.id', match: { value: adapterId } },
|
|
205
|
+
{ key: 'content_type', match: { any: [...ALLOWED_ARTIFACT_MIMES] } }
|
|
206
|
+
]
|
|
207
|
+
});
|
|
208
|
+
const rows = await this.engine.scroll(filter);
|
|
209
|
+
return rows.map((r) => ({ id: r.id, payload: payloadOf(r) }));
|
|
210
|
+
}
|
|
211
|
+
/** Re-export domain/task/type for the writer's per-memory metric loop. */
|
|
212
|
+
deriveDomainTaskType(label, text, tags) {
|
|
213
|
+
return deriveDomainTaskType(label, text, tags);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=lance-records-write-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lance-records-write-helpers.js","sourceRoot":"","sources":["../../../../src/services/vector-store/lancedb/lance-records-write-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE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.js';
|
|
2
|
+
import type { StoreAdapterOptions, StoreArtifactOptions } from '../../memory/store-adapter.js';
|
|
3
|
+
import type { LanceRecordEngine } from './lance-records-engine.js';
|
|
4
|
+
import type { LanceRecordSearch } from './lance-records-search.js';
|
|
5
|
+
export declare class LanceRecordWriter {
|
|
6
|
+
private readonly engine;
|
|
7
|
+
private readonly repo;
|
|
8
|
+
private readonly codeBlockProcessor;
|
|
9
|
+
private readonly artifactWriter;
|
|
10
|
+
constructor(engine: LanceRecordEngine, search: LanceRecordSearch);
|
|
11
|
+
storeArtifact(content: string, options: StoreArtifactOptions): Promise<Memory[]>;
|
|
12
|
+
storeAdapter(docs: string[], llmModelId: string, options?: StoreAdapterOptions): Promise<Memory[]>;
|
|
13
|
+
private resolveAdapterTitle;
|
|
14
|
+
private embedActivation;
|
|
15
|
+
private vectorNames;
|
|
16
|
+
private storeHeaderBasedAdapter;
|
|
17
|
+
private storeDefaultAdapter;
|
|
18
|
+
private enginePut;
|
|
19
|
+
private recordContributions;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=lance-records-writes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lance-records-writes.d.ts","sourceRoot":"","sources":["../../../../src/services/vector-store/lancedb/lance-records-writes.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAkBvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAOnE,qBAAa,iBAAiB;IAM1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IACtC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA4B;IAC/D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAsB;gBAGlC,MAAM,EAAE,iBAAiB,EAC1C,MAAM,EAAE,iBAAiB;IAM3B,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAI1E,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA0D5G,OAAO,CAAC,mBAAmB;YAOb,eAAe;IA0B7B,OAAO,CAAC,WAAW;YAKL,uBAAuB;YAwEvB,mBAAmB;YAqGnB,SAAS;YAMT,mBAAmB;CAclC"}
|