@pellux/goodvibes-sdk 0.33.30 → 0.33.32
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/browser-agent.d.ts +6 -0
- package/dist/browser-agent.d.ts.map +1 -0
- package/dist/browser-agent.js +74 -0
- package/dist/browser-knowledge.d.ts +4 -3
- package/dist/browser-knowledge.d.ts.map +1 -1
- package/dist/browser-knowledge.js +6 -3
- package/dist/contracts/artifacts/operator-contract.json +1 -1
- package/dist/platform/daemon/facade-composition.d.ts.map +1 -1
- package/dist/platform/daemon/facade-composition.js +49 -3
- package/dist/platform/daemon/facade-types.d.ts +1 -0
- package/dist/platform/daemon/facade-types.d.ts.map +1 -1
- package/dist/platform/daemon/http/router.d.ts +3 -1
- package/dist/platform/daemon/http/router.d.ts.map +1 -1
- package/dist/platform/daemon/http/router.js +35 -2
- package/dist/platform/daemon/types.d.ts +1 -0
- package/dist/platform/daemon/types.d.ts.map +1 -1
- package/dist/platform/knowledge/index.d.ts +2 -1
- package/dist/platform/knowledge/index.d.ts.map +1 -1
- package/dist/platform/knowledge/index.js +2 -1
- package/dist/platform/knowledge/map-filters.d.ts.map +1 -1
- package/dist/platform/knowledge/map-filters.js +2 -3
- package/dist/platform/knowledge/packet.d.ts +1 -1
- package/dist/platform/knowledge/packet.d.ts.map +1 -1
- package/dist/platform/knowledge/packet.js +4 -5
- package/dist/platform/knowledge/projections.d.ts.map +1 -1
- package/dist/platform/knowledge/projections.js +19 -14
- package/dist/platform/knowledge/scope-records.d.ts.map +1 -1
- package/dist/platform/knowledge/scope-records.js +165 -4
- package/dist/platform/knowledge/semantic/answer-evidence.d.ts.map +1 -1
- package/dist/platform/knowledge/semantic/answer-evidence.js +17 -2
- package/dist/platform/knowledge/semantic/answer-gaps.d.ts.map +1 -1
- package/dist/platform/knowledge/semantic/answer-gaps.js +3 -0
- package/dist/platform/knowledge/semantic/enrichment.d.ts.map +1 -1
- package/dist/platform/knowledge/semantic/enrichment.js +44 -13
- package/dist/platform/knowledge/semantic/gap-repair.js +14 -1
- package/dist/platform/knowledge/semantic/graph-index.d.ts.map +1 -1
- package/dist/platform/knowledge/semantic/graph-index.js +11 -4
- package/dist/platform/knowledge/semantic/self-improvement-gap-context.d.ts.map +1 -1
- package/dist/platform/knowledge/semantic/self-improvement-gap-context.js +10 -0
- package/dist/platform/knowledge/service.d.ts.map +1 -1
- package/dist/platform/knowledge/service.js +12 -7
- package/dist/platform/knowledge/spaces.d.ts +4 -0
- package/dist/platform/knowledge/spaces.d.ts.map +1 -1
- package/dist/platform/knowledge/spaces.js +11 -0
- package/dist/platform/knowledge/store-config.d.ts +1 -0
- package/dist/platform/knowledge/store-config.d.ts.map +1 -1
- package/dist/platform/knowledge/store-config.js +1 -0
- package/dist/platform/runtime/services.d.ts +1 -0
- package/dist/platform/runtime/services.d.ts.map +1 -1
- package/dist/platform/runtime/services.js +20 -1
- package/dist/platform/version.js +1 -1
- package/package.json +13 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packet.d.ts","sourceRoot":"","sources":["../../../src/platform/knowledge/packet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,
|
|
1
|
+
{"version":3,"file":"packet.d.ts","sourceRoot":"","sources":["../../../src/platform/knowledge/packet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAM5D,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EAErB,qBAAqB,EAGrB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAalE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,UAAU,E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CAE1B;AAED,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,sBAAsB,EAC/B,IAAI,EAAE,MAAM,EACZ,UAAU,GAAE,SAAS,MAAM,EAAO,EAClC,KAAK,SAAuB,EAC5B,OAAO,GAAE;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,wBAA6B,GAClH,eAAe,GAAG,IAAI,CAExB;AAED,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,sBAAsB,EAC/B,IAAI,EAAE,MAAM,EACZ,UAAU,GAAE,SAAS,MAAM,EAAO,EAClC,KAAK,SAAuB,EAC5B,OAAO,GAAE;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,wBAA6B,GAClH,MAAM,GAAG,IAAI,CAGf;AAED,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,sBAAsB,EAC/B,IAAI,EAAE,MAAM,EACZ,UAAU,GAAE,SAAS,MAAM,EAAO,EAClC,KAAK,SAAuB,EAC5B,OAAO,GAAE;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,wBAA6B,GAClH,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGxB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { knowledgeNodeMatchesScope, } from './scope-records.js';
|
|
1
|
+
import { knowledgeNodeMatchesScope, knowledgeSourceMatchesScope, } from './scope-records.js';
|
|
3
2
|
import { emitKnowledgePacketBuilt } from '../runtime/emitters/index.js';
|
|
4
3
|
import { DEFAULT_PACKET_BUDGET, DEFAULT_PACKET_LIMIT, estimateTokens, isSourcePastRefreshWindow, renderPacket, scoreHaystack, summarizeCompact, tokenize, trimForDetail, } from './shared.js';
|
|
5
4
|
export function searchKnowledge(context, query, limit = 10, scope = {}) {
|
|
@@ -7,7 +6,7 @@ export function searchKnowledge(context, query, limit = 10, scope = {}) {
|
|
|
7
6
|
if (taskTokens.length === 0)
|
|
8
7
|
return [];
|
|
9
8
|
const scopeLookup = knowledgeScopeLookup(context);
|
|
10
|
-
const sourceResults = context.store.listSources(Number.MAX_SAFE_INTEGER).filter((source) =>
|
|
9
|
+
const sourceResults = context.store.listSources(Number.MAX_SAFE_INTEGER).filter((source) => knowledgeSourceMatchesScope(source, scope)).map((source) => {
|
|
11
10
|
const extraction = context.store.getExtractionBySourceId(source.id);
|
|
12
11
|
const haystack = [
|
|
13
12
|
source.title ?? '',
|
|
@@ -84,7 +83,7 @@ function buildKnowledgePacketFromCurrentState(context, task, writeScope, limit,
|
|
|
84
83
|
const usageStats = buildUsageStats(context);
|
|
85
84
|
const candidates = [];
|
|
86
85
|
for (const source of context.store.listSources(Number.MAX_SAFE_INTEGER)) {
|
|
87
|
-
if (!
|
|
86
|
+
if (!knowledgeSourceMatchesScope(source, options))
|
|
88
87
|
continue;
|
|
89
88
|
const extraction = context.store.getExtractionBySourceId(source.id);
|
|
90
89
|
const haystack = [
|
|
@@ -224,7 +223,7 @@ function collectRelatedLabels(context, kind, id, scope) {
|
|
|
224
223
|
}
|
|
225
224
|
else if (otherKind === 'source') {
|
|
226
225
|
const source = context.store.getSource(otherId);
|
|
227
|
-
if (source &&
|
|
226
|
+
if (source && knowledgeSourceMatchesScope(source, scope))
|
|
228
227
|
labels.push(source.title ?? source.canonicalUri ?? source.id);
|
|
229
228
|
}
|
|
230
229
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projections.d.ts","sourceRoot":"","sources":["../../../src/platform/knowledge/projections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAO3D,OAAO,EAGL,KAAK,wBA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C,WAAW;IAInB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,cAAc;CAOvB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { generatedKnowledgeCanonicalUri, generatedKnowledgeSourceId, isGeneratedKnowledgeSource, materializeGeneratedKnowledgeProjection, } from './generated-projections.js';
|
|
2
2
|
import { isInKnowledgeSpaceScope, resolveKnowledgeSpaceScope, } from './spaces.js';
|
|
3
|
-
import { knowledgeIssueMatchesScope, knowledgeNodeMatchesScope, } from './scope-records.js';
|
|
3
|
+
import { knowledgeIssueMatchesScope, knowledgeNodeMatchesScope, knowledgeSourceMatchesScope, } from './scope-records.js';
|
|
4
4
|
import { buildBulletList, dedupe, formatDateTime, joinSections, materializedTargetReference, quote, slugify, sortByTitle, } from './projection-utils.js';
|
|
5
5
|
export class KnowledgeProjectionService {
|
|
6
6
|
store;
|
|
@@ -109,7 +109,7 @@ export class KnowledgeProjectionService {
|
|
|
109
109
|
return null;
|
|
110
110
|
if (kind === 'source') {
|
|
111
111
|
const source = this.store.getSource(id);
|
|
112
|
-
return source &&
|
|
112
|
+
return source && knowledgeSourceMatchesScope(source, scope) ? this.createSourceTarget(source) : null;
|
|
113
113
|
}
|
|
114
114
|
if (kind === 'node') {
|
|
115
115
|
const node = this.store.getNode(id);
|
|
@@ -351,7 +351,7 @@ export class KnowledgeProjectionService {
|
|
|
351
351
|
buildBulletList(entry.incoming.map((edge) => {
|
|
352
352
|
if (edge.fromKind === 'source') {
|
|
353
353
|
const linked = this.store.getSource(edge.fromId);
|
|
354
|
-
return linked &&
|
|
354
|
+
return linked && knowledgeSourceMatchesScope(linked, scope) ? `${this.linkToTarget(this.createSourceTarget(linked))} via \`${edge.relation}\`` : `source:${edge.fromId}`;
|
|
355
355
|
}
|
|
356
356
|
if (edge.fromKind === 'node') {
|
|
357
357
|
const node = this.store.getNode(edge.fromId);
|
|
@@ -407,7 +407,7 @@ export class KnowledgeProjectionService {
|
|
|
407
407
|
}
|
|
408
408
|
renderSourcePage(id, scope) {
|
|
409
409
|
const source = this.store.getSource(id);
|
|
410
|
-
if (!source || !
|
|
410
|
+
if (!source || !knowledgeSourceMatchesScope(source, scope))
|
|
411
411
|
throw new Error(`Unknown knowledge source: ${id}`);
|
|
412
412
|
const extraction = this.store.getExtractionBySourceId(id);
|
|
413
413
|
const view = this.store.getItem(id);
|
|
@@ -442,7 +442,7 @@ export class KnowledgeProjectionService {
|
|
|
442
442
|
buildBulletList(relatedNodes.filter((node) => this.nodeInScope(node, scope)).map((node) => this.linkToTarget(this.createNodeTarget(node), `${node.title} (${node.kind})`))),
|
|
443
443
|
].join('\n'), [
|
|
444
444
|
'## Related Sources',
|
|
445
|
-
buildBulletList(relatedSources.filter((entry) =>
|
|
445
|
+
buildBulletList(relatedSources.filter((entry) => knowledgeSourceMatchesScope(entry, scope)).map((entry) => this.linkToTarget(this.createSourceTarget(entry)))),
|
|
446
446
|
].join('\n'), [
|
|
447
447
|
'## Backlinks',
|
|
448
448
|
buildBulletList(incoming.map((edge) => `${edge.fromKind}:${edge.fromId} via \`${edge.relation}\``)),
|
|
@@ -483,11 +483,11 @@ export class KnowledgeProjectionService {
|
|
|
483
483
|
'## Linked Sources',
|
|
484
484
|
buildBulletList((view?.linkedSources ?? [])
|
|
485
485
|
.filter((source) => !isGeneratedKnowledgeSource(source))
|
|
486
|
-
.filter((source) =>
|
|
486
|
+
.filter((source) => knowledgeSourceMatchesScope(source, scope))
|
|
487
487
|
.map((source) => this.linkToTarget(this.createSourceTarget(source)))),
|
|
488
488
|
].join('\n'), [
|
|
489
489
|
'## Linked Nodes',
|
|
490
|
-
buildBulletList((view?.linkedNodes ?? []).filter((entry) => entry.id !== node.id &&
|
|
490
|
+
buildBulletList((view?.linkedNodes ?? []).filter((entry) => entry.id !== node.id && this.nodeInScope(entry, scope)).map((entry) => this.linkToTarget(this.createNodeTarget(entry), `${entry.title} (${entry.kind})`))),
|
|
491
491
|
].join('\n'), [
|
|
492
492
|
'## Backlinks',
|
|
493
493
|
buildBulletList(incoming
|
|
@@ -518,8 +518,8 @@ export class KnowledgeProjectionService {
|
|
|
518
518
|
const target = this.createIssueTarget(issue);
|
|
519
519
|
const linkedSource = issue.sourceId ? this.store.getSource(issue.sourceId) : null;
|
|
520
520
|
const linkedNode = issue.nodeId ? this.store.getNode(issue.nodeId) : null;
|
|
521
|
-
const source = linkedSource &&
|
|
522
|
-
const node = linkedNode &&
|
|
521
|
+
const source = linkedSource && knowledgeSourceMatchesScope(linkedSource, scope) ? linkedSource : null;
|
|
522
|
+
const node = linkedNode && this.nodeInScope(linkedNode, scope) ? linkedNode : null;
|
|
523
523
|
const content = joinSections(`# ${target.title}`, [
|
|
524
524
|
'## Metadata',
|
|
525
525
|
`- id: \`${issue.id}\``,
|
|
@@ -569,7 +569,8 @@ export class KnowledgeProjectionService {
|
|
|
569
569
|
return this.store.getSource(edge.toId);
|
|
570
570
|
return null;
|
|
571
571
|
})
|
|
572
|
-
.filter((source) => Boolean(source)
|
|
572
|
+
.filter((source) => Boolean(source))
|
|
573
|
+
.filter((source) => knowledgeSourceMatchesScope(source, scope));
|
|
573
574
|
const linkedNodes = edges
|
|
574
575
|
.map((edge) => {
|
|
575
576
|
if (edge.fromKind === 'node' && edge.fromId !== node.id)
|
|
@@ -578,7 +579,8 @@ export class KnowledgeProjectionService {
|
|
|
578
579
|
return this.store.getNode(edge.toId);
|
|
579
580
|
return null;
|
|
580
581
|
})
|
|
581
|
-
.filter((entry) => Boolean(entry)
|
|
582
|
+
.filter((entry) => Boolean(entry))
|
|
583
|
+
.filter((entry) => this.nodeInScope(entry, scope));
|
|
582
584
|
const content = joinSections(`# ${target.title}`, node.summary, [
|
|
583
585
|
'## Included Sources',
|
|
584
586
|
buildBulletList(sortByTitle(dedupe(sources, (source) => source.id)).map((source) => this.linkToTarget(this.createSourceTarget(source)))),
|
|
@@ -675,7 +677,7 @@ export class KnowledgeProjectionService {
|
|
|
675
677
|
recordReferenceInScope(kind, id, scope) {
|
|
676
678
|
if (kind === 'source') {
|
|
677
679
|
const source = this.store.getSource(id);
|
|
678
|
-
return Boolean(source &&
|
|
680
|
+
return Boolean(source && knowledgeSourceMatchesScope(source, scope));
|
|
679
681
|
}
|
|
680
682
|
if (kind === 'node') {
|
|
681
683
|
const node = this.store.getNode(id);
|
|
@@ -689,7 +691,7 @@ export class KnowledgeProjectionService {
|
|
|
689
691
|
}
|
|
690
692
|
scopedSources(scope, limit = Number.MAX_SAFE_INTEGER) {
|
|
691
693
|
return this.store.listSources(Number.MAX_SAFE_INTEGER)
|
|
692
|
-
.filter((source) =>
|
|
694
|
+
.filter((source) => knowledgeSourceMatchesScope(source, scope))
|
|
693
695
|
.slice(0, Math.max(1, limit));
|
|
694
696
|
}
|
|
695
697
|
scopedNodes(scope, limit = Number.MAX_SAFE_INTEGER) {
|
|
@@ -706,7 +708,10 @@ export class KnowledgeProjectionService {
|
|
|
706
708
|
}
|
|
707
709
|
scopedExtractions(scope, limit = Number.MAX_SAFE_INTEGER) {
|
|
708
710
|
return this.store.listExtractions(Number.MAX_SAFE_INTEGER)
|
|
709
|
-
.filter((extraction) =>
|
|
711
|
+
.filter((extraction) => {
|
|
712
|
+
const source = this.store.getSource(extraction.sourceId);
|
|
713
|
+
return source ? knowledgeSourceMatchesScope(source, scope) : isInKnowledgeSpaceScope(extraction, scope);
|
|
714
|
+
})
|
|
710
715
|
.slice(0, Math.max(1, limit));
|
|
711
716
|
}
|
|
712
717
|
nodeInScope(node, scope) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope-records.d.ts","sourceRoot":"","sources":["../../../src/platform/knowledge/scope-records.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,wBAAwB,EAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,SA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C1E,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,mBAAmB,CAAC,GAAG,SAAS,CAAC;IACtE,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,mBAAmB,EAAE,GAAG,SAAS,CAAC;CAC7D;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,qBAAqB,EAC7B,KAAK,GAAE,wBAA6B,GACnC,OAAO,CAKT;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,mBAAmB,EACzB,KAAK,GAAE,wBAA6B,EACpC,MAAM,GAAE,oBAAyB,GAChC,OAAO,CAaT;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,oBAAoB,EAC3B,KAAK,GAAE,wBAA6B,EACpC,MAAM,GAAE,oBAAyB,GAChC,OAAO,CAYT"}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { DEFAULT_KNOWLEDGE_SPACE_ID, getExplicitKnowledgeSpaceId, getKnowledgeSpaceId, isInKnowledgeSpaceScope, resolveKnowledgeSpaceScope, } from './spaces.js';
|
|
2
2
|
export function knowledgeSourceMatchesScope(source, scope = {}) {
|
|
3
|
+
const scopedSpaceId = resolveKnowledgeSpaceScope(scope);
|
|
4
|
+
if (isDefaultExtensionContaminatedSource(source))
|
|
5
|
+
return false;
|
|
6
|
+
if (scopedSpaceId === null)
|
|
7
|
+
return true;
|
|
3
8
|
return isInKnowledgeSpaceScope(source, scope);
|
|
4
9
|
}
|
|
5
10
|
export function knowledgeNodeMatchesScope(node, scope = {}, lookup = {}) {
|
|
6
11
|
const scopedSpaceId = resolveKnowledgeSpaceScope(scope);
|
|
7
|
-
if (scopedSpaceId === null)
|
|
8
|
-
return true;
|
|
9
12
|
const relatedSpaces = relatedNodeSpaceIds(node, lookup);
|
|
10
13
|
const ownSpace = getKnowledgeSpaceId(node);
|
|
14
|
+
if (isDefaultExtensionContaminatedNode(node, lookup))
|
|
15
|
+
return false;
|
|
16
|
+
if (scopedSpaceId === null)
|
|
17
|
+
return true;
|
|
11
18
|
if (scopedSpaceId === DEFAULT_KNOWLEDGE_SPACE_ID
|
|
12
19
|
&& relatedSpaces.length === 0
|
|
13
20
|
&& (isUngroundedSemanticAnswerGapNode(node) || isUngroundedCatalogDerivedNode(node)))
|
|
@@ -19,10 +26,12 @@ export function knowledgeNodeMatchesScope(node, scope = {}, lookup = {}) {
|
|
|
19
26
|
}
|
|
20
27
|
export function knowledgeIssueMatchesScope(issue, scope = {}, lookup = {}) {
|
|
21
28
|
const scopedSpaceId = resolveKnowledgeSpaceScope(scope);
|
|
22
|
-
if (scopedSpaceId === null)
|
|
23
|
-
return true;
|
|
24
29
|
const relatedSpaces = relatedIssueSpaceIds(issue, lookup);
|
|
25
30
|
const ownSpace = getKnowledgeSpaceId(issue);
|
|
31
|
+
if (isDefaultExtensionContaminatedIssue(issue, lookup))
|
|
32
|
+
return false;
|
|
33
|
+
if (scopedSpaceId === null)
|
|
34
|
+
return true;
|
|
26
35
|
if (scopedSpaceId === DEFAULT_KNOWLEDGE_SPACE_ID
|
|
27
36
|
&& (isUngroundedSemanticAnswerGapIssue(issue, lookup) || isIssueLinkedOnlyToUngroundedAnswerGap(issue, lookup)))
|
|
28
37
|
return false;
|
|
@@ -135,6 +144,121 @@ function isUngroundedSemanticAnswerGapNode(node) {
|
|
|
135
144
|
...readStringArray(node.metadata.subjectIds),
|
|
136
145
|
]).length === 0;
|
|
137
146
|
}
|
|
147
|
+
function isDefaultExtensionContaminatedSource(source) {
|
|
148
|
+
if (getKnowledgeSpaceId(source) !== DEFAULT_KNOWLEDGE_SPACE_ID)
|
|
149
|
+
return false;
|
|
150
|
+
const text = [
|
|
151
|
+
source.id,
|
|
152
|
+
source.connectorId,
|
|
153
|
+
source.sourceType,
|
|
154
|
+
source.title,
|
|
155
|
+
source.summary,
|
|
156
|
+
source.description,
|
|
157
|
+
source.sourceUri,
|
|
158
|
+
source.canonicalUri,
|
|
159
|
+
source.url,
|
|
160
|
+
source.tags.join(' '),
|
|
161
|
+
metadataSearchText(source.metadata),
|
|
162
|
+
].join(' ');
|
|
163
|
+
return hasLegacyDefaultAgentWikiMarker(text) || hasExtensionOnlyKnowledgeMarker(text);
|
|
164
|
+
}
|
|
165
|
+
function isDefaultExtensionContaminatedNode(node, lookup) {
|
|
166
|
+
if (getKnowledgeSpaceId(node) !== DEFAULT_KNOWLEDGE_SPACE_ID)
|
|
167
|
+
return false;
|
|
168
|
+
if (isDefaultAnswerGapNode(node))
|
|
169
|
+
return true;
|
|
170
|
+
if (/^ha[_:-]/i.test(node.kind))
|
|
171
|
+
return true;
|
|
172
|
+
if (nodeReferencesDefaultExtensionSource(node, lookup))
|
|
173
|
+
return true;
|
|
174
|
+
if (nodeReferencesExtensionObject(node, lookup))
|
|
175
|
+
return true;
|
|
176
|
+
const text = [
|
|
177
|
+
node.id,
|
|
178
|
+
node.kind,
|
|
179
|
+
node.slug,
|
|
180
|
+
node.title,
|
|
181
|
+
node.summary,
|
|
182
|
+
node.aliases.join(' '),
|
|
183
|
+
metadataSearchText(node.metadata),
|
|
184
|
+
].join(' ');
|
|
185
|
+
return hasLegacyDefaultAgentWikiMarker(text) || hasExtensionOnlyKnowledgeMarker(text);
|
|
186
|
+
}
|
|
187
|
+
function nodeReferencesExtensionObject(node, lookup) {
|
|
188
|
+
for (const nodeId of uniqueStrings([
|
|
189
|
+
...readStringArray(node.metadata.linkedObjectIds),
|
|
190
|
+
...readStringArray(node.metadata.subjectIds),
|
|
191
|
+
])) {
|
|
192
|
+
const linked = lookupNode(lookup, nodeId);
|
|
193
|
+
if (!linked)
|
|
194
|
+
continue;
|
|
195
|
+
if (/^ha[_:-]/i.test(linked.kind))
|
|
196
|
+
return true;
|
|
197
|
+
if (hasExtensionOnlyKnowledgeMarker(`${linked.kind} ${linked.title} ${metadataSearchText(linked.metadata)}`))
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
function isDefaultExtensionContaminatedIssue(issue, lookup) {
|
|
203
|
+
if (getKnowledgeSpaceId(issue) !== DEFAULT_KNOWLEDGE_SPACE_ID)
|
|
204
|
+
return false;
|
|
205
|
+
if (issue.code === 'knowledge.answer_gap')
|
|
206
|
+
return true;
|
|
207
|
+
if (issueReferencesDefaultExtensionSource(issue, lookup))
|
|
208
|
+
return true;
|
|
209
|
+
for (const nodeId of issueNodeIds(issue)) {
|
|
210
|
+
const node = lookupNode(lookup, nodeId);
|
|
211
|
+
if (node && isDefaultExtensionContaminatedNode(node, lookup))
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
const text = [
|
|
215
|
+
issue.id,
|
|
216
|
+
issue.code,
|
|
217
|
+
issue.message,
|
|
218
|
+
issue.sourceId,
|
|
219
|
+
issue.nodeId,
|
|
220
|
+
metadataSearchText(issue.metadata),
|
|
221
|
+
].join(' ');
|
|
222
|
+
return hasLegacyDefaultAgentWikiMarker(text) || hasExtensionOnlyKnowledgeMarker(text);
|
|
223
|
+
}
|
|
224
|
+
function isDefaultAnswerGapNode(node) {
|
|
225
|
+
return node.kind === 'knowledge_gap'
|
|
226
|
+
&& readString(node.metadata.semanticKind) === 'gap'
|
|
227
|
+
&& readString(node.metadata.gapKind) === 'answer'
|
|
228
|
+
&& readString(node.metadata.visibility) === 'refinement';
|
|
229
|
+
}
|
|
230
|
+
function nodeReferencesDefaultExtensionSource(node, lookup) {
|
|
231
|
+
for (const sourceId of uniqueStrings([
|
|
232
|
+
node.sourceId,
|
|
233
|
+
readString(node.metadata.sourceId),
|
|
234
|
+
...readStringArray(node.metadata.sourceIds),
|
|
235
|
+
])) {
|
|
236
|
+
const source = lookupSource(lookup, sourceId);
|
|
237
|
+
if (source && isDefaultExtensionContaminatedSource(source))
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
for (const edge of lookup.edges ?? []) {
|
|
241
|
+
if (!edgeTouchesRecord(edge, 'node', node.id))
|
|
242
|
+
continue;
|
|
243
|
+
const sourceId = edge.fromKind === 'source' ? edge.fromId : edge.toKind === 'source' ? edge.toId : undefined;
|
|
244
|
+
const source = lookupSource(lookup, sourceId);
|
|
245
|
+
if (source && isDefaultExtensionContaminatedSource(source))
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
function issueReferencesDefaultExtensionSource(issue, lookup) {
|
|
251
|
+
for (const sourceId of uniqueStrings([
|
|
252
|
+
issue.sourceId,
|
|
253
|
+
readString(issue.metadata.sourceId),
|
|
254
|
+
...readStringArray(issue.metadata.sourceIds),
|
|
255
|
+
])) {
|
|
256
|
+
const source = lookupSource(lookup, sourceId);
|
|
257
|
+
if (source && isDefaultExtensionContaminatedSource(source))
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
138
262
|
function isUngroundedSemanticAnswerGapIssue(issue, lookup) {
|
|
139
263
|
return issue.code === 'knowledge.answer_gap'
|
|
140
264
|
&& (issue.metadata.semantic === true || readString(issue.metadata.semantic) === 'true')
|
|
@@ -207,3 +331,40 @@ function uniqueStrings(values) {
|
|
|
207
331
|
function readOnlyMetadataKeys(metadata) {
|
|
208
332
|
return Object.keys(metadata).filter((key) => !['knowledgeSpaceId', 'namespace'].includes(key));
|
|
209
333
|
}
|
|
334
|
+
function metadataSearchText(metadata) {
|
|
335
|
+
return Object.entries(metadata)
|
|
336
|
+
.filter(([key]) => !['content', 'raw', 'html'].includes(key))
|
|
337
|
+
.flatMap(([, value]) => flattenMetadataText(value))
|
|
338
|
+
.join(' ');
|
|
339
|
+
}
|
|
340
|
+
function flattenMetadataText(value) {
|
|
341
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
|
|
342
|
+
return [String(value)];
|
|
343
|
+
if (Array.isArray(value))
|
|
344
|
+
return value.flatMap(flattenMetadataText);
|
|
345
|
+
if (!value || typeof value !== 'object')
|
|
346
|
+
return [];
|
|
347
|
+
return Object.values(value).flatMap(flattenMetadataText);
|
|
348
|
+
}
|
|
349
|
+
function hasExtensionOnlyKnowledgeMarker(value) {
|
|
350
|
+
const lower = value.toLowerCase();
|
|
351
|
+
return /\bhome\s*assistant\b/.test(lower)
|
|
352
|
+
|| /\bhome[-_]?assistant\b/.test(lower)
|
|
353
|
+
|| /\bhome\s*graph\b/.test(lower)
|
|
354
|
+
|| /\bhome[-_]?graph\b/.test(lower)
|
|
355
|
+
|| /\bhomegraph\b/.test(lower)
|
|
356
|
+
|| /\bgoodvibes[-_]?homeassistant\b/.test(lower)
|
|
357
|
+
|| /\bha_(?:device|entity|area|integration|device_passport|room)\b/.test(lower)
|
|
358
|
+
|| /\bhomeassistant:/.test(lower);
|
|
359
|
+
}
|
|
360
|
+
function hasLegacyDefaultAgentWikiMarker(value) {
|
|
361
|
+
const lower = value.toLowerCase();
|
|
362
|
+
const mentionsGoodVibesAgent = /\bgoodvibes\s+agents?\b/.test(lower)
|
|
363
|
+
|| /\bgoodvibes[-_]?agents?\b/.test(lower);
|
|
364
|
+
if (!mentionsGoodVibesAgent)
|
|
365
|
+
return false;
|
|
366
|
+
return /\bdefault[-_]?specification\b/.test(lower)
|
|
367
|
+
|| /\byaml\s+frontmatter\b/.test(lower)
|
|
368
|
+
|| /\bfrontmatter\b/.test(lower)
|
|
369
|
+
|| /\bgoodvibes:\/\/wiki\/default\b/.test(lower);
|
|
370
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"answer-evidence.d.ts","sourceRoot":"","sources":["../../../../src/platform/knowledge/semantic/answer-evidence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"answer-evidence.d.ts","sourceRoot":"","sources":["../../../../src/platform/knowledge/semantic/answer-evidence.ts"],"names":[],"mappings":"AAAA,OA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,EACb,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,aAAa,EAAE,SAAS,mBAAmB,EAAE,EAC7C,KAAK,EAAE,MAAM,GACZ,YAAY,EAAE,CAwChB;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,qBAAqB,CASxE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,mBAAmB,EAAE,GAAG,mBAAmB,EAAE,CASxF;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,qBAAqB,GAAG,qBAAqB,CAM5F"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getExplicitKnowledgeSpaceId, isHomeAssistantKnowledgeSpace, normalizeKnowledgeSpaceId, } from '../spaces.js';
|
|
2
|
+
import { knowledgeNodeMatchesScope, knowledgeSourceMatchesScope, } from '../scope-records.js';
|
|
2
3
|
import { isActiveKnowledgeEdge } from '../projection-utils.js';
|
|
3
4
|
import { clampText, normalizeWhitespace, readRecord, readString, readStringArray, scoreSemanticText, sourceSemanticText, splitSentences, tokenizeSemanticQuery, uniqueStrings, } from './utils.js';
|
|
4
5
|
import { isLowValueFeatureOrSpecText, isSemanticAnswerLinkedObject, } from './fact-quality.js';
|
|
@@ -267,13 +268,27 @@ function listAnswerSources(store, spaceId) {
|
|
|
267
268
|
const sources = isBroadKnowledgeSpaceAlias(spaceId)
|
|
268
269
|
? store.listSources(Number.MAX_SAFE_INTEGER)
|
|
269
270
|
: store.listSourcesInSpace(spaceId);
|
|
270
|
-
return sources
|
|
271
|
+
return sources
|
|
272
|
+
.filter((source) => source.status !== 'stale')
|
|
273
|
+
.filter((source) => knowledgeSourceMatchesScope(source, answerEvidenceScope(spaceId)));
|
|
271
274
|
}
|
|
272
275
|
function listAnswerNodes(store, spaceId) {
|
|
273
276
|
const nodes = isBroadKnowledgeSpaceAlias(spaceId)
|
|
274
277
|
? store.listNodes(Number.MAX_SAFE_INTEGER)
|
|
275
278
|
: store.listNodesInSpace(spaceId);
|
|
276
|
-
|
|
279
|
+
const lookup = {
|
|
280
|
+
getSource: (id) => store.getSource(id),
|
|
281
|
+
getNode: (id) => store.getNode(id),
|
|
282
|
+
edges: store.listEdges(),
|
|
283
|
+
};
|
|
284
|
+
return nodes
|
|
285
|
+
.filter((node) => node.status !== 'stale')
|
|
286
|
+
.filter((node) => knowledgeNodeMatchesScope(node, answerEvidenceScope(spaceId), lookup));
|
|
287
|
+
}
|
|
288
|
+
function answerEvidenceScope(spaceId) {
|
|
289
|
+
if (isBroadKnowledgeSpaceAlias(spaceId))
|
|
290
|
+
return { includeAllSpaces: true };
|
|
291
|
+
return { knowledgeSpaceId: normalizeKnowledgeSpaceId(spaceId) };
|
|
277
292
|
}
|
|
278
293
|
function sourceIdsLinkedToNodes(store, nodeIds, spaceId) {
|
|
279
294
|
const sourceIds = new Set();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"answer-gaps.d.ts","sourceRoot":"","sources":["../../../../src/platform/knowledge/semantic/answer-gaps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"answer-gaps.d.ts","sourceRoot":"","sources":["../../../../src/platform/knowledge/semantic/answer-gaps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAK9E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAgB5D,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,SAAS,mBAAmB,EAAE,GAC5C,OAAO,CAMT;AAED,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IACP,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,qBAAqB,EAAE,GAAG,SAAS,CAAC;IAChE,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,mBAAmB,EAAE,GAAG,SAAS,CAAC;CAChE,GACL,OAAO,CAAC,mBAAmB,CAAC,CA6E9B;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,SAAS,yBAAyB,EAAE,EAC1C,OAAO,GAAE;IACP,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,qBAAqB,EAAE,GAAG,SAAS,CAAC;IAChE,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,mBAAmB,EAAE,GAAG,SAAS,CAAC;CAChE,GACL,OAAO,CAAC,SAAS,mBAAmB,EAAE,CAAC,CAUzC;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAKtE"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { DEFAULT_KNOWLEDGE_SPACE_ID, normalizeKnowledgeSpaceId, } from '../spaces.js';
|
|
1
2
|
import { normalizeWhitespace, readString, readStringArray, semanticHash, semanticMetadata, tokenizeSemanticQuery, uniqueStrings, } from './utils.js';
|
|
2
3
|
import { GENERIC_ANSWER_INTENT_TOKENS, isBroadKnowledgeSpaceAlias, } from './answer-common.js';
|
|
3
4
|
import { hasAny } from './answer-fact-selection.js';
|
|
4
5
|
export function shouldPersistNoMatchGap(spaceId, query, linkedObjects) {
|
|
5
6
|
if (linkedObjects.length > 0)
|
|
6
7
|
return true;
|
|
8
|
+
if (normalizeKnowledgeSpaceId(spaceId) === DEFAULT_KNOWLEDGE_SPACE_ID)
|
|
9
|
+
return false;
|
|
7
10
|
if (!isBroadKnowledgeSpaceAlias(spaceId))
|
|
8
11
|
return true;
|
|
9
12
|
const subjectTokens = tokenizeSemanticQuery(query).filter((token) => !GENERIC_ANSWER_INTENT_TOKENS.has(token));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enrichment.d.ts","sourceRoot":"","sources":["../../../../src/platform/knowledge/semantic/enrichment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"enrichment.d.ts","sourceRoot":"","sources":["../../../../src/platform/knowledge/semantic/enrichment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,KAAK,EAGV,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAKV,oBAAoB,EAErB,MAAM,YAAY,CAAC;AAwBpB,MAAM,WAAW,kCAAkC;IACjD,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,GAAG,CAAC,EAAE,oBAAoB,GAAG,IAAI,GAAG,SAAS,CAAC;CACxD;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChD;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,eAAe,GAAG,SAAS,CAAC;IACzD,QAAQ,CAAC,KAAK,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAC/C,QAAQ,CAAC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAClD,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACpD,QAAQ,CAAC,IAAI,EAAE,SAAS,mBAAmB,EAAE,CAAC;CAC/C;AAED,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,kCAAkC,EAC3C,MAAM,EAAE,qBAAqB,EAC7B,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,2BAA2B,CAAC,CAqCtC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getKnowledgeSpaceId } from '../spaces.js';
|
|
2
|
+
import { knowledgeSourceMatchesScope } from '../scope-records.js';
|
|
2
3
|
import { isActiveKnowledgeEdge } from '../projection-utils.js';
|
|
3
4
|
import { MAX_SEMANTIC_SOURCE_CHARS, applySourceMetadata, clampText, normalizeWhitespace, readRecord, readString, readStringArray, semanticFactId, semanticHash, semanticMetadata, semanticSlug, sourceKnowledgeSpace, sourceSemanticHash, sourceSemanticText, splitSentences, uniqueStrings, } from './utils.js';
|
|
4
5
|
import { canonicalRepairSubjectNodes } from './repair-subjects.js';
|
|
@@ -12,6 +13,12 @@ export async function enrichKnowledgeSource(context, source, options = {}) {
|
|
|
12
13
|
const existingSemantic = readRecord(source.metadata.semanticEnrichment);
|
|
13
14
|
const currentExtractor = readString(existingSemantic.extractor);
|
|
14
15
|
const shouldUpgradeDeterministic = Boolean(context.llm && existingSemantic.textHash === textHash && currentExtractor !== 'llm');
|
|
16
|
+
if (!knowledgeSourceMatchesScope(source, { includeAllSpaces: true })) {
|
|
17
|
+
await markSourceSemanticState(context.store, source, textHash, {
|
|
18
|
+
skippedReason: 'source is outside active knowledge scope',
|
|
19
|
+
});
|
|
20
|
+
return emptyResult(source, true, 'source is outside active knowledge scope');
|
|
21
|
+
}
|
|
15
22
|
if (!options.force && existingSemantic.textHash === textHash && !shouldUpgradeDeterministic) {
|
|
16
23
|
return emptyResult(source, true, 'semantic enrichment is current');
|
|
17
24
|
}
|
|
@@ -111,19 +118,21 @@ function normalizeSemanticExtraction(value) {
|
|
|
111
118
|
function deterministicSemanticExtraction(source, extraction, text) {
|
|
112
119
|
const factText = cleanDeterministicSourceText(deterministicFactSourceText(extraction) || text);
|
|
113
120
|
const sentences = splitSentences(factText);
|
|
114
|
-
const profileFacts =
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
const profileFacts = shouldDeriveDeterministicProfileFacts(source, factText)
|
|
122
|
+
? deriveRepairProfileFacts({
|
|
123
|
+
query: 'complete features specifications capabilities',
|
|
124
|
+
source,
|
|
125
|
+
text: factText,
|
|
126
|
+
}).map((fact) => ({
|
|
127
|
+
kind: fact.kind,
|
|
128
|
+
title: fact.title,
|
|
129
|
+
value: fact.value,
|
|
130
|
+
summary: fact.summary,
|
|
131
|
+
evidence: fact.evidence,
|
|
132
|
+
confidence: 72,
|
|
133
|
+
labels: fact.labels,
|
|
134
|
+
}))
|
|
135
|
+
: [];
|
|
127
136
|
const facts = [
|
|
128
137
|
...profileFacts,
|
|
129
138
|
...sentences
|
|
@@ -155,6 +164,28 @@ function deterministicSemanticExtraction(source, extraction, text) {
|
|
|
155
164
|
extractor: 'deterministic',
|
|
156
165
|
};
|
|
157
166
|
}
|
|
167
|
+
function shouldDeriveDeterministicProfileFacts(source, text) {
|
|
168
|
+
const discovery = readRecord(source.metadata.sourceDiscovery);
|
|
169
|
+
if (readStringArray(discovery.linkedObjectIds).length > 0)
|
|
170
|
+
return true;
|
|
171
|
+
if (/\bmodel:[a-z0-9][a-z0-9._-]{2,}\b/i.test(readString(discovery.trustReason) ?? ''))
|
|
172
|
+
return true;
|
|
173
|
+
const sourceIdentity = [
|
|
174
|
+
source.title,
|
|
175
|
+
source.summary,
|
|
176
|
+
source.sourceUri,
|
|
177
|
+
source.canonicalUri,
|
|
178
|
+
source.url,
|
|
179
|
+
source.tags.join(' '),
|
|
180
|
+
].filter(Boolean).join(' ');
|
|
181
|
+
const hasModelIdentity = /\b[A-Z]{2,}[-_ ]?[0-9][A-Z0-9._-]{2,}\b/.test(sourceIdentity);
|
|
182
|
+
if (!hasModelIdentity)
|
|
183
|
+
return false;
|
|
184
|
+
const sourceLooksLikeSpecProfile = /\b(specifications?|specs?|product|manual|datasheet|support|features?)\b/i.test(sourceIdentity);
|
|
185
|
+
const textLooksLikeSpecProfile = /\b(?:hdmi|hdr10|dolby vision|refresh rate|bluetooth|wi-?fi|speaker|usb|ethernet|optical|rf antenna|rs-?232|webos|airplay|homekit)\b/i.test(text)
|
|
186
|
+
&& /\b(?:\d{2,3}(?:\.0)?\s*(?:inch|inches|in\.|")|4k|uhd|3840\s*(?:x|×)\s*2160|[A-Z]{2,}[-_ ]?[0-9][A-Z0-9._-]{2,})\b/i.test(text);
|
|
187
|
+
return sourceLooksLikeSpecProfile || textLooksLikeSpecProfile;
|
|
188
|
+
}
|
|
158
189
|
function deterministicFactSourceText(extraction) {
|
|
159
190
|
const structure = readRecord(extraction?.structure);
|
|
160
191
|
const nestedStructure = readRecord(structure.structure);
|
|
@@ -484,7 +484,8 @@ function domainManufacturerHints(value) {
|
|
|
484
484
|
const hints = [];
|
|
485
485
|
for (const match of value.toLowerCase().matchAll(/\b(?:https?:\/\/)?(?:www\.|support\.|docs\.|developer\.)?([a-z0-9-]+)\.(?:com|net|org|io|dev|tv|ca|co\.uk)\b/g)) {
|
|
486
486
|
const label = match[1]?.replace(/-/g, ' ').trim();
|
|
487
|
-
|
|
487
|
+
const slug = manufacturerDomainSlug(label ?? '');
|
|
488
|
+
if (label && !isGenericManufacturerSlug(slug) && !isGenericDomainManufacturerSlug(slug))
|
|
488
489
|
hints.push(label);
|
|
489
490
|
}
|
|
490
491
|
return hints;
|
|
@@ -517,6 +518,18 @@ function isGenericManufacturerSlug(slug) {
|
|
|
517
518
|
'assistant',
|
|
518
519
|
].includes(slug);
|
|
519
520
|
}
|
|
521
|
+
function isGenericDomainManufacturerSlug(slug) {
|
|
522
|
+
return [
|
|
523
|
+
'github',
|
|
524
|
+
'gitlab',
|
|
525
|
+
'bitbucket',
|
|
526
|
+
'sourceforge',
|
|
527
|
+
'readthedocs',
|
|
528
|
+
'githubio',
|
|
529
|
+
'pages',
|
|
530
|
+
'docs',
|
|
531
|
+
].includes(slug);
|
|
532
|
+
}
|
|
520
533
|
function escapeRegExp(value) {
|
|
521
534
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
522
535
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-index.d.ts","sourceRoot":"","sources":["../../../../src/platform/knowledge/semantic/graph-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"graph-index.d.ts","sourceRoot":"","sources":["../../../../src/platform/knowledge/semantic/graph-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,KAAK,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAC/C,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC7D,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;CAClE;AAED,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,MAAM,GACd,2BAA2B,CAuB7B"}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { isActiveKnowledgeEdge } from '../projection-utils.js';
|
|
2
|
+
import { knowledgeNodeMatchesScope, knowledgeSourceMatchesScope, } from '../scope-records.js';
|
|
2
3
|
export function buildKnowledgeSemanticGraphIndex(store, spaceId) {
|
|
3
|
-
const
|
|
4
|
-
const
|
|
4
|
+
const scope = { knowledgeSpaceId: spaceId };
|
|
5
|
+
const rawSources = store.listSourcesInSpace(spaceId).filter((source) => source.status !== 'stale');
|
|
6
|
+
const sourceMap = new Map(rawSources.map((source) => [source.id, source]));
|
|
7
|
+
const rawNodes = store.listNodesInSpace(spaceId).filter((node) => node.status !== 'stale');
|
|
8
|
+
const edgeCandidates = store.listEdges().filter(isActiveKnowledgeEdge);
|
|
9
|
+
const rawNodeMap = new Map(rawNodes.map((node) => [node.id, node]));
|
|
10
|
+
const lookup = { sources: sourceMap, nodes: rawNodeMap, edges: edgeCandidates };
|
|
11
|
+
const sources = rawSources.filter((source) => knowledgeSourceMatchesScope(source, scope));
|
|
12
|
+
const nodes = rawNodes.filter((node) => knowledgeNodeMatchesScope(node, scope, lookup));
|
|
5
13
|
const nodeIds = new Set(nodes.map((node) => node.id));
|
|
6
14
|
const sourceIds = new Set(sources.map((source) => source.id));
|
|
7
|
-
const edges =
|
|
8
|
-
&& (edge.fromKind !== 'node' || nodeIds.has(edge.fromId))
|
|
15
|
+
const edges = edgeCandidates.filter((edge) => ((edge.fromKind !== 'node' || nodeIds.has(edge.fromId))
|
|
9
16
|
&& (edge.toKind !== 'node' || nodeIds.has(edge.toId))
|
|
10
17
|
&& (edge.fromKind !== 'source' || sourceIds.has(edge.fromId))
|
|
11
18
|
&& (edge.toKind !== 'source' || sourceIds.has(edge.toId))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"self-improvement-gap-context.d.ts","sourceRoot":"","sources":["../../../../src/platform/knowledge/semantic/self-improvement-gap-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"self-improvement-gap-context.d.ts","sourceRoot":"","sources":["../../../../src/platform/knowledge/semantic/self-improvement-gap-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAKrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAEV,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAgBrB,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,mBAAmB,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,qBAAqB,EAAE,CAAC;IACnD,QAAQ,CAAC,aAAa,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACvD,QAAQ,CAAC,KAAK,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAC/C,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IAChD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC5C;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,EAC1C,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,GACtC,mBAAmB,EAAE,CAQvB;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,M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