@fortemi/core 2026.7.13 → 2026.7.15
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 +41 -2
- package/dist/aiwg-index-schema.d.ts +0 -1
- package/dist/aiwg-index-schema.js +49 -0
- package/dist/aiwg-index-schema.js.map +1 -1
- package/dist/{aiwg-index-shard-BhF8kKAU.d.ts → aiwg-index-shard-BCdaz0X1.d.ts} +26 -0
- package/dist/aiwg-index-shard.d.ts +1 -1
- package/dist/aiwg-index-shard.js +863 -28
- package/dist/aiwg-index-shard.js.map +1 -1
- package/dist/aiwg-index.d.ts +53 -28
- package/dist/aiwg-index.js +8 -8
- package/dist/aiwg-index.js.map +1 -1
- package/dist/index.d.ts +548 -577
- package/dist/index.js +1600 -1245
- package/dist/index.js.map +1 -1
- package/package.json +9 -3
package/dist/aiwg-index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
type AiwgFortemiRecordType = string;
|
|
2
2
|
type AiwgFortemiRecordSchemaVersion = 'aiwg.fortemi.index.record.v1' | 'aiwg.fortemi.index.record.v2';
|
|
3
3
|
type AiwgFortemiIndexExportSchemaVersion = 'aiwg.fortemi.index.export.v1' | 'aiwg.fortemi.index.export.v2';
|
|
4
|
-
type AiwgPrivacyClassification = 'private' | '
|
|
5
|
-
type AiwgProvenanceConfidence = '
|
|
6
|
-
type AiwgReviewAction = 'accept' | '
|
|
7
|
-
type AiwgFortemiRelationshipDirection = '
|
|
4
|
+
type AiwgPrivacyClassification = 'private' | 'public' | 'sanitized';
|
|
5
|
+
type AiwgProvenanceConfidence = 'candidate' | 'rejected' | 'reviewed' | 'source';
|
|
6
|
+
type AiwgReviewAction = 'accept' | 'defer' | 'reject';
|
|
7
|
+
type AiwgFortemiRelationshipDirection = 'downstream' | 'related' | 'upstream';
|
|
8
|
+
type AiwgOperationalStateClassification = 'contradicted' | 'fresh' | 'historical' | 'needs-source' | 'superseded';
|
|
9
|
+
type AiwgOperationalStateConfidence = 'candidate' | 'rejected' | 'reviewed' | 'source';
|
|
8
10
|
interface AiwgFortemiRecordSource {
|
|
9
11
|
path: string;
|
|
10
12
|
repo_relative_path: string;
|
|
@@ -96,18 +98,38 @@ interface AiwgFortemiRecordEmbedding {
|
|
|
96
98
|
interface AiwgFortemiAttachmentReference {
|
|
97
99
|
id: string;
|
|
98
100
|
path: string;
|
|
99
|
-
mime:
|
|
101
|
+
mime: null | string;
|
|
100
102
|
checksum: string;
|
|
101
103
|
bytes: number;
|
|
102
104
|
}
|
|
103
105
|
interface AiwgFortemiBinarySource {
|
|
104
|
-
extracted_text:
|
|
106
|
+
extracted_text: null | string;
|
|
105
107
|
created_at?: string;
|
|
106
|
-
deleted_at?:
|
|
107
|
-
extraction_status?: '
|
|
108
|
-
reason?:
|
|
108
|
+
deleted_at?: null | string;
|
|
109
|
+
extraction_status?: 'blocked' | 'deferred' | 'extracted' | 'failed' | 'pending';
|
|
110
|
+
reason?: 'extraction_pending' | 'extractor_failed' | 'large_binary' | 'no_extracted_text' | 'quarantined' | 'unsupported_mime' | null;
|
|
109
111
|
attachment: AiwgFortemiAttachmentReference;
|
|
110
112
|
}
|
|
113
|
+
interface AiwgOperationalState {
|
|
114
|
+
source_repo?: string;
|
|
115
|
+
source_kind?: string;
|
|
116
|
+
source_id?: string;
|
|
117
|
+
observed_state?: string;
|
|
118
|
+
observed_at?: string;
|
|
119
|
+
source_updated_at?: string;
|
|
120
|
+
evidence_url?: string;
|
|
121
|
+
evidence_path?: string;
|
|
122
|
+
observer?: string;
|
|
123
|
+
supersedes?: string[];
|
|
124
|
+
contradicts?: string[];
|
|
125
|
+
stale_after?: string;
|
|
126
|
+
classification: AiwgOperationalStateClassification;
|
|
127
|
+
confidence?: AiwgOperationalStateConfidence;
|
|
128
|
+
current_action_selector?: boolean;
|
|
129
|
+
}
|
|
130
|
+
interface AiwgStateTransfer {
|
|
131
|
+
deleted_at: null | string;
|
|
132
|
+
}
|
|
111
133
|
interface AiwgFortemiRecord {
|
|
112
134
|
schema_version: AiwgFortemiRecordSchemaVersion;
|
|
113
135
|
id: string;
|
|
@@ -131,10 +153,14 @@ interface AiwgFortemiRecord {
|
|
|
131
153
|
skos_relations?: AiwgFortemiSkosRelation[];
|
|
132
154
|
/** Optional W3C PROV-style activity chain for this record. */
|
|
133
155
|
provenance_events?: AiwgFortemiProvenanceEvent[];
|
|
156
|
+
/** Observed external state provenance. This is not a persistence tombstone. */
|
|
157
|
+
operational_state?: AiwgOperationalState;
|
|
158
|
+
/** Source-authored state projected into portable persistence semantics. */
|
|
159
|
+
state_transfer?: AiwgStateTransfer;
|
|
134
160
|
privacy: {
|
|
135
161
|
classification: AiwgPrivacyClassification;
|
|
136
|
-
pii: boolean;
|
|
137
162
|
locality?: string;
|
|
163
|
+
pii: boolean;
|
|
138
164
|
};
|
|
139
165
|
updated_at: string;
|
|
140
166
|
}
|
|
@@ -142,9 +168,9 @@ interface AiwgFortemiIndexExport {
|
|
|
142
168
|
schema_version: AiwgFortemiIndexExportSchemaVersion;
|
|
143
169
|
generated_at: string;
|
|
144
170
|
source: {
|
|
145
|
-
repo: string;
|
|
146
|
-
privacy: AiwgPrivacyClassification;
|
|
147
171
|
graph?: string;
|
|
172
|
+
privacy: AiwgPrivacyClassification;
|
|
173
|
+
repo: string;
|
|
148
174
|
};
|
|
149
175
|
items: AiwgFortemiRecord[];
|
|
150
176
|
compatibility?: {
|
|
@@ -158,8 +184,8 @@ interface AiwgFortemiChunkPartRef {
|
|
|
158
184
|
count: number;
|
|
159
185
|
}
|
|
160
186
|
declare const AIWG_SCAN_REQUIRED_FIELDS: Array<keyof AiwgFortemiRecord>;
|
|
161
|
-
type AiwgFortemiProjectedRecord = Pick<AiwgFortemiRecord, '
|
|
162
|
-
type AiwgDetailIdEncoding = '
|
|
187
|
+
type AiwgFortemiProjectedRecord = Pick<AiwgFortemiRecord, 'concepts' | 'facets' | 'id' | 'privacy' | 'schema_version' | 'tags' | 'text' | 'title' | 'type'> & Partial<AiwgFortemiRecord>;
|
|
188
|
+
type AiwgDetailIdEncoding = 'base64url' | 'uri';
|
|
163
189
|
interface AiwgFortemiChunkDetailRef {
|
|
164
190
|
href: string;
|
|
165
191
|
encoding?: AiwgDetailIdEncoding;
|
|
@@ -205,7 +231,7 @@ interface AiwgIndexQueryOptions {
|
|
|
205
231
|
snippetLength?: number;
|
|
206
232
|
weights?: Partial<AiwgIndexQueryWeights>;
|
|
207
233
|
includeMatches?: boolean;
|
|
208
|
-
searchProfile?: '
|
|
234
|
+
searchProfile?: 'aiwg-discovery' | 'default';
|
|
209
235
|
}
|
|
210
236
|
interface AiwgIndexQueryWeights {
|
|
211
237
|
title: number;
|
|
@@ -217,7 +243,7 @@ interface AiwgIndexQueryWeights {
|
|
|
217
243
|
source: number;
|
|
218
244
|
}
|
|
219
245
|
interface AiwgIndexQueryMatch {
|
|
220
|
-
field: '
|
|
246
|
+
field: 'concept' | 'facet' | 'id' | 'source' | 'tag' | 'text' | 'title';
|
|
221
247
|
value: string;
|
|
222
248
|
score?: number;
|
|
223
249
|
reason?: string;
|
|
@@ -276,8 +302,8 @@ interface AiwgIndexGraphOptions {
|
|
|
276
302
|
relationshipWeights?: Record<string, number>;
|
|
277
303
|
includeDanglingRelationships?: boolean;
|
|
278
304
|
}
|
|
279
|
-
type AiwgRelationshipDirection = '
|
|
280
|
-
type AiwgRelationshipSetOperation = '
|
|
305
|
+
type AiwgRelationshipDirection = 'both' | 'in' | 'out';
|
|
306
|
+
type AiwgRelationshipSetOperation = 'difference' | 'intersection' | 'union';
|
|
281
307
|
interface AiwgRelationshipTraversalOptions {
|
|
282
308
|
direction?: AiwgRelationshipDirection;
|
|
283
309
|
relationshipType?: string;
|
|
@@ -333,7 +359,7 @@ interface AiwgStaticEmbeddingSet {
|
|
|
333
359
|
model: string;
|
|
334
360
|
dimensions: number;
|
|
335
361
|
generated_at: string;
|
|
336
|
-
granularity: '
|
|
362
|
+
granularity: 'body' | 'chunked-body' | 'title-summary' | string;
|
|
337
363
|
metric?: 'cosine' | 'dot' | 'euclidean';
|
|
338
364
|
input_hash_algorithm?: string;
|
|
339
365
|
embeddings: AiwgStaticEmbeddingRecord[];
|
|
@@ -355,7 +381,7 @@ interface BuildAiwgStaticEmbeddingSetOptions {
|
|
|
355
381
|
id: string;
|
|
356
382
|
backend: AiwgHeadlessEmbeddingBackend;
|
|
357
383
|
records?: AiwgFortemiRecord[];
|
|
358
|
-
generatedAt?:
|
|
384
|
+
generatedAt?: Date | string;
|
|
359
385
|
granularity?: AiwgStaticEmbeddingSet['granularity'];
|
|
360
386
|
metric?: AiwgStaticEmbeddingSet['metric'];
|
|
361
387
|
textForRecord?: (record: AiwgFortemiRecord) => string;
|
|
@@ -389,8 +415,8 @@ interface AiwgReviewInput {
|
|
|
389
415
|
interface AiwgIndexControllerSnapshot {
|
|
390
416
|
index: AiwgFortemiIndexExport | null;
|
|
391
417
|
chunked: {
|
|
392
|
-
manifest: AiwgFortemiChunkManifest;
|
|
393
418
|
cachedParts: number;
|
|
419
|
+
manifest: AiwgFortemiChunkManifest;
|
|
394
420
|
maxCachedParts: number;
|
|
395
421
|
} | null;
|
|
396
422
|
data: AiwgIndexQueryResult | null;
|
|
@@ -449,8 +475,8 @@ interface AiwgChunkedIndexBuildResult {
|
|
|
449
475
|
part: AiwgFortemiChunkPart;
|
|
450
476
|
}>;
|
|
451
477
|
details: Array<{
|
|
452
|
-
id: string;
|
|
453
478
|
href: string;
|
|
479
|
+
id: string;
|
|
454
480
|
record: AiwgFortemiRecord;
|
|
455
481
|
}>;
|
|
456
482
|
}
|
|
@@ -467,19 +493,18 @@ declare function findAiwgStaticDuplicatePairs(index: AiwgFortemiIndexExport, emb
|
|
|
467
493
|
declare function createAiwgReviewDecisionExport(source: Pick<AiwgFortemiIndexExport, 'schema_version'>, decisions: AiwgReviewDecision[], generatedAt?: string): AiwgReviewDecisionExport;
|
|
468
494
|
declare function createAiwgIndexController(initialIndex?: AiwgFortemiIndexExport): AiwgIndexController;
|
|
469
495
|
declare function aiwgFortemiIndexToCommunityGraph(index: AiwgFortemiIndexExport, options?: AiwgIndexGraphOptions): {
|
|
470
|
-
|
|
496
|
+
communities: {
|
|
471
497
|
id: string;
|
|
498
|
+
nodes: string[];
|
|
472
499
|
}[];
|
|
473
500
|
edges: {
|
|
501
|
+
kind: string;
|
|
474
502
|
source: string;
|
|
475
503
|
target: string;
|
|
476
|
-
kind: string;
|
|
477
504
|
weight: number;
|
|
478
505
|
}[];
|
|
479
|
-
|
|
506
|
+
nodes: {
|
|
480
507
|
id: string;
|
|
481
|
-
nodes: string[];
|
|
482
508
|
}[];
|
|
483
509
|
};
|
|
484
|
-
|
|
485
|
-
export { AIWG_SCAN_REQUIRED_FIELDS, type AiwgChunkedIndexBuildOptions, type AiwgChunkedIndexBuildResult, type AiwgChunkedIndexDetailLoader, type AiwgChunkedIndexLoadOptions, type AiwgChunkedIndexLoader, type AiwgChunkedIndexProgress, type AiwgChunkedIndexProgressPhase, type AiwgChunkedIndexQueryOptions, type AiwgChunkedIndexQueryResult, type AiwgChunkedIndexValidationResult, type AiwgDetailIdEncoding, type AiwgFortemiAttachmentReference, type AiwgFortemiBinarySource, type AiwgFortemiChunk, type AiwgFortemiChunkDetailRef, type AiwgFortemiChunkManifest, type AiwgFortemiChunkPart, type AiwgFortemiChunkPartRef, type AiwgFortemiIndexExport, type AiwgFortemiIndexExportSchemaVersion, type AiwgFortemiProjectedRecord, type AiwgFortemiProvenance, type AiwgFortemiProvenanceEvent, type AiwgFortemiRecord, type AiwgFortemiRecordEmbedding, type AiwgFortemiRecordSchemaVersion, type AiwgFortemiRecordSource, type AiwgFortemiRecordType, type AiwgFortemiRelationship, type AiwgFortemiRelationshipDirection, type AiwgFortemiSearchProjection, type AiwgFortemiSkosConcept, type AiwgFortemiSkosRelation, type AiwgFortemiSkosRelationType, type AiwgHeadlessEmbeddingBackend, type AiwgIndexController, type AiwgIndexControllerListener, type AiwgIndexControllerSnapshot, type AiwgIndexGraphOptions, type AiwgIndexQueryMatch, type AiwgIndexQueryOptions, type AiwgIndexQueryRankedItem, type AiwgIndexQueryResult, type AiwgIndexQueryWeights, type AiwgIndexValidationResult, type AiwgPrivacyClassification, type AiwgPrivacyFilterOptions, type AiwgProvenanceConfidence, type AiwgRelationshipDirection, type AiwgRelationshipEdgeSummary, type AiwgRelationshipNodeSummary, type AiwgRelationshipQueryOptions, type AiwgRelationshipSetOperation, type AiwgRelationshipSetOptions, type AiwgRelationshipSetResult, type AiwgRelationshipTraversalOptions, type AiwgRelationshipTraversalResult, type AiwgReviewAction, type AiwgReviewDecision, type AiwgReviewDecisionExport, type AiwgReviewInput, type AiwgStaticDuplicatePair, type AiwgStaticEmbeddingRecord, type AiwgStaticEmbeddingSet, type AiwgStaticHybridQueryOptions, type AiwgStaticSemanticQueryOptions, type AiwgStaticSemanticResult, type BuildAiwgStaticEmbeddingSetOptions, DEFAULT_AIWG_DUPLICATE_SCAN_MAX_EMBEDDINGS, aiwgDetailHrefForId, aiwgFortemiIndexToCommunityGraph, assertAiwgFortemiChunkManifest, assertAiwgFortemiChunkPart, assertAiwgFortemiIndexExport, assertAiwgStaticEmbeddingSet, buildAiwgChunkedIndex, buildAiwgStaticEmbeddingSet, createAiwgFetchChunkLoader, createAiwgFetchDetailLoader, createAiwgIndexController, createAiwgReviewDecisionExport, encodeAiwgDetailId, filterAiwgRecordsByPrivacy, findAiwgStaticDuplicatePairs, getAiwgFortemiFacets, queryAiwgFortemiIndex, queryAiwgHybridIndex, queryAiwgSemanticIndex, resolveAiwgFetchUrl, validateAiwgFortemiChunkManifest, validateAiwgFortemiChunkPart, validateAiwgFortemiIndexExport, validateAiwgStaticEmbeddingSet };
|
|
510
|
+
export { AIWG_SCAN_REQUIRED_FIELDS, type AiwgChunkedIndexBuildOptions, type AiwgChunkedIndexBuildResult, type AiwgChunkedIndexDetailLoader, type AiwgChunkedIndexLoadOptions, type AiwgChunkedIndexLoader, type AiwgChunkedIndexProgress, type AiwgChunkedIndexProgressPhase, type AiwgChunkedIndexQueryOptions, type AiwgChunkedIndexQueryResult, type AiwgChunkedIndexValidationResult, type AiwgDetailIdEncoding, type AiwgFortemiAttachmentReference, type AiwgFortemiBinarySource, type AiwgFortemiChunk, type AiwgFortemiChunkDetailRef, type AiwgFortemiChunkManifest, type AiwgFortemiChunkPart, type AiwgFortemiChunkPartRef, type AiwgFortemiIndexExport, type AiwgFortemiIndexExportSchemaVersion, type AiwgFortemiProjectedRecord, type AiwgFortemiProvenance, type AiwgFortemiProvenanceEvent, type AiwgFortemiRecord, type AiwgFortemiRecordEmbedding, type AiwgFortemiRecordSchemaVersion, type AiwgFortemiRecordSource, type AiwgFortemiRecordType, type AiwgFortemiRelationship, type AiwgFortemiRelationshipDirection, type AiwgFortemiSearchProjection, type AiwgFortemiSkosConcept, type AiwgFortemiSkosRelation, type AiwgFortemiSkosRelationType, type AiwgHeadlessEmbeddingBackend, type AiwgIndexController, type AiwgIndexControllerListener, type AiwgIndexControllerSnapshot, type AiwgIndexGraphOptions, type AiwgIndexQueryMatch, type AiwgIndexQueryOptions, type AiwgIndexQueryRankedItem, type AiwgIndexQueryResult, type AiwgIndexQueryWeights, type AiwgIndexValidationResult, type AiwgOperationalState, type AiwgOperationalStateClassification, type AiwgOperationalStateConfidence, type AiwgPrivacyClassification, type AiwgPrivacyFilterOptions, type AiwgProvenanceConfidence, type AiwgRelationshipDirection, type AiwgRelationshipEdgeSummary, type AiwgRelationshipNodeSummary, type AiwgRelationshipQueryOptions, type AiwgRelationshipSetOperation, type AiwgRelationshipSetOptions, type AiwgRelationshipSetResult, type AiwgRelationshipTraversalOptions, type AiwgRelationshipTraversalResult, type AiwgReviewAction, type AiwgReviewDecision, type AiwgReviewDecisionExport, type AiwgReviewInput, type AiwgStateTransfer, type AiwgStaticDuplicatePair, type AiwgStaticEmbeddingRecord, type AiwgStaticEmbeddingSet, type AiwgStaticHybridQueryOptions, type AiwgStaticSemanticQueryOptions, type AiwgStaticSemanticResult, type BuildAiwgStaticEmbeddingSetOptions, DEFAULT_AIWG_DUPLICATE_SCAN_MAX_EMBEDDINGS, aiwgDetailHrefForId, aiwgFortemiIndexToCommunityGraph, assertAiwgFortemiChunkManifest, assertAiwgFortemiChunkPart, assertAiwgFortemiIndexExport, assertAiwgStaticEmbeddingSet, buildAiwgChunkedIndex, buildAiwgStaticEmbeddingSet, createAiwgFetchChunkLoader, createAiwgFetchDetailLoader, createAiwgIndexController, createAiwgReviewDecisionExport, encodeAiwgDetailId, filterAiwgRecordsByPrivacy, findAiwgStaticDuplicatePairs, getAiwgFortemiFacets, queryAiwgFortemiIndex, queryAiwgHybridIndex, queryAiwgSemanticIndex, resolveAiwgFetchUrl, validateAiwgFortemiChunkManifest, validateAiwgFortemiChunkPart, validateAiwgFortemiIndexExport, validateAiwgStaticEmbeddingSet };
|
package/dist/aiwg-index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var we=["schema_version","id","type","title","text","facets","tags","concepts","privacy"];function ye(e,t){let i=e.privacy;return !!(!i||!P(i.classification)||typeof i.pii!="boolean"||i.classification==="private"&&!t?.includePrivate||i.pii&&!t?.includePii)}function ie(e,t){return e.filter(i=>!ye(i,t))}var xe=["schema_version","id","type","source","facets","tags","concepts","relationships","provenance","privacy","updated_at"],K={title:4,tag:3,concept:2,text:1,facet:2,id:1,source:.25};function l(e){return typeof e=="string"&&e.length>0}function M(e,t,i){let r=e[t];r===void 0&&(r=Object.create(null),e[t]=r),r[i]=(r[i]??0)+1;}function C(e){return Number.isInteger(e)&&typeof e=="number"&&e>=0}function S(e){return Number.isInteger(e)&&typeof e=="number"&&e>0}function Ae(e){return !e||typeof e!="object"||Array.isArray(e)?false:Object.values(e).every(t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(i=>C(i)))}function h(e){return !!e&&typeof e=="object"&&!Array.isArray(e)}function L(e){return e===void 0||Array.isArray(e)&&e.every(t=>typeof t=="string")}function re(e){return e==="aiwg.fortemi.index.export.v1"||e==="aiwg.fortemi.index.export.v2"}function ne(e){return e==="aiwg.fortemi.index.record.v1"||e==="aiwg.fortemi.index.record.v2"}function be(e,t,i){if(e.skos_concepts!==void 0)if(!Array.isArray(e.skos_concepts))i.push("items["+t+"].skos_concepts must be an array when present");else for(let[r,n]of e.skos_concepts.entries()){if(!h(n)){i.push("items["+t+"].skos_concepts["+r+"] must be an object");continue}l(n.id)||i.push("items["+t+"].skos_concepts["+r+"].id is required"),l(n.prefLabel)||i.push("items["+t+"].skos_concepts["+r+"].prefLabel is required"),L(n.altLabels)||i.push("items["+t+"].skos_concepts["+r+"].altLabels must be a string array"),n.metadata!==void 0&&!h(n.metadata)&&i.push("items["+t+"].skos_concepts["+r+"].metadata must be an object");}if(e.skos_relations!==void 0)if(!Array.isArray(e.skos_relations))i.push("items["+t+"].skos_relations must be an array when present");else for(let[r,n]of e.skos_relations.entries()){if(!h(n)){i.push("items["+t+"].skos_relations["+r+"] must be an object");continue}l(n.type)||i.push("items["+t+"].skos_relations["+r+"].type is required"),l(n.source_id)||i.push("items["+t+"].skos_relations["+r+"].source_id is required"),l(n.target_id)||i.push("items["+t+"].skos_relations["+r+"].target_id is required"),n.metadata!==void 0&&!h(n.metadata)&&i.push("items["+t+"].skos_relations["+r+"].metadata must be an object");}if(e.provenance_events!==void 0)if(!Array.isArray(e.provenance_events))i.push("items["+t+"].provenance_events must be an array when present");else for(let[r,n]of e.provenance_events.entries()){if(!h(n)){i.push("items["+t+"].provenance_events["+r+"] must be an object");continue}l(n.activity)||i.push("items["+t+"].provenance_events["+r+"].activity is required"),n.attributes!==void 0&&!h(n.attributes)&&i.push("items["+t+"].provenance_events["+r+"].attributes must be an object");}if(Array.isArray(e.relationships))for(let[r,n]of e.relationships.entries()){if(!h(n)){i.push("items["+t+"].relationships["+r+"] must be an object");continue}n.metadata!==void 0&&!h(n.metadata)&&i.push("items["+t+"].relationships["+r+"].metadata must be an object"),n.direction!==void 0&&n.direction!=="upstream"&&n.direction!=="downstream"&&n.direction!=="related"&&i.push("items["+t+"].relationships["+r+"].direction must be upstream, downstream, or related"),n.target_path!==void 0&&typeof n.target_path!="string"&&i.push("items["+t+"].relationships["+r+"].target_path must be a string");}if(e.search!==void 0&&(h(e.search)?(L(e.search.triggers)||i.push("items["+t+"].search.triggers must be a string array"),L(e.search.aliases)||i.push("items["+t+"].search.aliases must be a string array"),L(e.search.tags)||i.push("items["+t+"].search.tags must be a string array"),e.search.frontmatter!==void 0&&!h(e.search.frontmatter)&&i.push("items["+t+"].search.frontmatter must be an object")):i.push("items["+t+"].search must be an object")),e.chunks!==void 0)if(!Array.isArray(e.chunks))i.push("items["+t+"].chunks must be an array when present");else for(let[r,n]of e.chunks.entries()){if(!h(n)){i.push("items["+t+"].chunks["+r+"] must be an object");continue}n.metadata!==void 0&&!h(n.metadata)&&i.push("items["+t+"].chunks["+r+"].metadata must be an object");}if(e.embeddings!==void 0)if(!Array.isArray(e.embeddings))i.push("items["+t+"].embeddings must be an array when present");else for(let[r,n]of e.embeddings.entries()){if(!h(n)){i.push("items["+t+"].embeddings["+r+"] must be an object");continue}let s=n.embedding??n.vector;s!==void 0&&(!Array.isArray(s)||!s.every(o=>typeof o=="number"))&&i.push("items["+t+"].embeddings["+r+"].embedding/vector must be a number array"),n.metadata!==void 0&&!h(n.metadata)&&i.push("items["+t+"].embeddings["+r+"].metadata must be an object");}e.compatibility!==void 0&&!h(e.compatibility)&&i.push("items["+t+"].compatibility must be an object");}function P(e){return e==="private"||e==="sanitized"||e==="public"}function se(e){return e==="source"||e==="candidate"||e==="reviewed"||e==="rejected"}function ve(e,t,i){if(Array.isArray(e.provenance))for(let[r,n]of e.provenance.entries()){let s="items["+t+"].provenance["+r+"]";if(!h(n)){i.push(s+" must be an object");continue}l(n.field)||i.push(s+".field is required"),l(n.source)||i.push(s+".source is required"),l(n.path)||i.push(s+".path is required"),se(n.confidence)||i.push(s+".confidence must be one of source, candidate, reviewed, rejected"),P(n.privacy)||i.push(s+".privacy must be one of private, sanitized, public");}}var Re=["search","chunks","embeddings","skos_concepts","skos_relations","provenance_events","compatibility"],ke=["origin","generated","checksum","updated_at"],_e=["target_path","direction","metadata"];function Ie(e,t,i){if(e.schema_version!=="aiwg.fortemi.index.record.v1")return;let r="items["+t+"]",n=e,s=" is a v2-only field and must be absent on a record.v1 record";for(let o of Re)n[o]!==void 0&&i.push(r+"."+o+s);if(h(e.source)){let o=e.source;for(let a of ke)o[a]!==void 0&&i.push(r+".source."+a+s);}if(h(e.privacy)&&e.privacy.locality!==void 0&&i.push(r+".privacy.locality"+s),Array.isArray(e.relationships))for(let[o,a]of e.relationships.entries()){if(!h(a))continue;let c=a;for(let g of _e)c[g]!==void 0&&i.push(r+".relationships["+o+"]."+g+s);}}function oe(e){let t=[],i=Object.create(null),r=h(e)?e:{};h(e)||t.push("index export must be an object"),re(r?.schema_version)||t.push("schema_version must be aiwg.fortemi.index.export.v1 or aiwg.fortemi.index.export.v2"),l(r?.generated_at)||t.push("generated_at is required"),l(r?.source?.repo)||t.push("source.repo is required"),l(r?.source?.privacy)?P(r?.source?.privacy)||t.push("source.privacy must be one of private, sanitized, public"):t.push("source.privacy is required"),Array.isArray(r?.items)||t.push("items must be an array"),r.compatibility!==void 0&&!h(r.compatibility)&&t.push("compatibility must be an object"),r?.schema_version==="aiwg.fortemi.index.export.v1"&&(h(r.source)&&r.source.graph!==void 0&&t.push("source.graph is a v2-only field and must be absent on an export.v1 export"),r.compatibility!==void 0&&t.push("compatibility is a v2-only field and must be absent on an export.v1 export"));let n=new Set,s="",o=Array.isArray(r.items)?r.items:[];for(let[a,c]of o.entries()){if(!h(c)){t.push("items["+a+"] must be an object");continue}for(let g of xe)g in c||t.push("items["+a+"]."+g+" is required");ne(c.schema_version)||t.push("items["+a+"].schema_version must be aiwg.fortemi.index.record.v1 or aiwg.fortemi.index.record.v2"),r.schema_version==="aiwg.fortemi.index.export.v1"&&c.schema_version==="aiwg.fortemi.index.record.v2"&&t.push("items["+a+"].schema_version must match aiwg.fortemi.index.export.v1"),l(c.id)||t.push("items["+a+"].id is required"),l(c.id)&&n.has(c.id)&&t.push("duplicate id: "+c.id),l(c.id)&&n.add(c.id),s&&l(c.id)&&s>c.id&&t.push("items must be sorted by id: "+s+" before "+c.id),l(c.id)&&(s=c.id),l(c.type)?i[c.type]=(i[c.type]??0)+1:t.push("items["+a+"].type must be a non-empty string"),l(c.source?.path)||t.push("items["+a+"].source.path is required"),l(c.source?.repo_relative_path)||t.push("items["+a+"].source.repo_relative_path is required"),l(c.source?.locator)||t.push("items["+a+"].source.locator is required"),typeof c.title!="string"&&typeof c.search?.title!="string"&&typeof c.search?.name!="string"&&t.push("items["+a+"].title or search.title/search.name is required"),typeof c.text!="string"&&typeof c.search?.body!="string"&&typeof c.search?.summary!="string"&&t.push("items["+a+"].text or search.body/search.summary is required"),Array.isArray(c.tags)||t.push("items["+a+"].tags must be an array"),Array.isArray(c.concepts)||t.push("items["+a+"].concepts must be an array"),Array.isArray(c.relationships)||t.push("items["+a+"].relationships must be an array"),(!Array.isArray(c.provenance)||c.provenance.length===0)&&t.push("items["+a+"].provenance must be a non-empty array"),be(c,a,t),ve(c,a,t),Ie(c,a,t),!c.privacy||typeof c.privacy.pii!="boolean"||!l(c.privacy.classification)?t.push("items["+a+"].privacy requires classification and pii"):P(c.privacy.classification)||t.push("items["+a+"].privacy.classification must be one of private, sanitized, public");}return {valid:t.length===0,errors:t,counts:i}}function q(e){let t=oe(e);if(!t.valid)throw new Error(`Invalid AIWG Fortemi index export:
|
|
1
|
+
var we=["schema_version","id","type","title","text","facets","tags","concepts","privacy"];function ye(e,t){let i=e.privacy;return !!(!i||!P(i.classification)||typeof i.pii!="boolean"||i.classification==="private"&&!t?.includePrivate||i.pii&&!t?.includePii)}function ie(e,t){return e.filter(i=>!ye(i,t))}var be=["schema_version","id","type","source","facets","tags","concepts","relationships","provenance","privacy","updated_at"],K={title:4,tag:3,concept:2,text:1,facet:2,id:1,source:.25};function l(e){return typeof e=="string"&&e.length>0}function M(e,t,i){let r=e[t];r===void 0&&(r=Object.create(null),e[t]=r),r[i]=(r[i]??0)+1;}function C(e){return Number.isInteger(e)&&typeof e=="number"&&e>=0}function S(e){return Number.isInteger(e)&&typeof e=="number"&&e>0}function Ae(e){return !e||typeof e!="object"||Array.isArray(e)?false:Object.values(e).every(t=>!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(i=>C(i)))}function h(e){return !!e&&typeof e=="object"&&!Array.isArray(e)}function j(e){return e===void 0||Array.isArray(e)&&e.every(t=>typeof t=="string")}function re(e){return e==="aiwg.fortemi.index.export.v1"||e==="aiwg.fortemi.index.export.v2"}function ne(e){return e==="aiwg.fortemi.index.record.v1"||e==="aiwg.fortemi.index.record.v2"}function xe(e,t,i){if(e.skos_concepts!==void 0)if(!Array.isArray(e.skos_concepts))i.push("items["+t+"].skos_concepts must be an array when present");else for(let[r,n]of e.skos_concepts.entries()){if(!h(n)){i.push("items["+t+"].skos_concepts["+r+"] must be an object");continue}l(n.id)||i.push("items["+t+"].skos_concepts["+r+"].id is required"),l(n.prefLabel)||i.push("items["+t+"].skos_concepts["+r+"].prefLabel is required"),j(n.altLabels)||i.push("items["+t+"].skos_concepts["+r+"].altLabels must be a string array"),n.metadata!==void 0&&!h(n.metadata)&&i.push("items["+t+"].skos_concepts["+r+"].metadata must be an object");}if(e.skos_relations!==void 0)if(!Array.isArray(e.skos_relations))i.push("items["+t+"].skos_relations must be an array when present");else for(let[r,n]of e.skos_relations.entries()){if(!h(n)){i.push("items["+t+"].skos_relations["+r+"] must be an object");continue}l(n.type)||i.push("items["+t+"].skos_relations["+r+"].type is required"),l(n.source_id)||i.push("items["+t+"].skos_relations["+r+"].source_id is required"),l(n.target_id)||i.push("items["+t+"].skos_relations["+r+"].target_id is required"),n.metadata!==void 0&&!h(n.metadata)&&i.push("items["+t+"].skos_relations["+r+"].metadata must be an object");}if(e.provenance_events!==void 0)if(!Array.isArray(e.provenance_events))i.push("items["+t+"].provenance_events must be an array when present");else for(let[r,n]of e.provenance_events.entries()){if(!h(n)){i.push("items["+t+"].provenance_events["+r+"] must be an object");continue}l(n.activity)||i.push("items["+t+"].provenance_events["+r+"].activity is required"),n.attributes!==void 0&&!h(n.attributes)&&i.push("items["+t+"].provenance_events["+r+"].attributes must be an object");}if(Array.isArray(e.relationships))for(let[r,n]of e.relationships.entries()){if(!h(n)){i.push("items["+t+"].relationships["+r+"] must be an object");continue}n.metadata!==void 0&&!h(n.metadata)&&i.push("items["+t+"].relationships["+r+"].metadata must be an object"),n.direction!==void 0&&n.direction!=="upstream"&&n.direction!=="downstream"&&n.direction!=="related"&&i.push("items["+t+"].relationships["+r+"].direction must be upstream, downstream, or related"),n.target_path!==void 0&&typeof n.target_path!="string"&&i.push("items["+t+"].relationships["+r+"].target_path must be a string");}if(e.search!==void 0&&(h(e.search)?(j(e.search.triggers)||i.push("items["+t+"].search.triggers must be a string array"),j(e.search.aliases)||i.push("items["+t+"].search.aliases must be a string array"),j(e.search.tags)||i.push("items["+t+"].search.tags must be a string array"),e.search.frontmatter!==void 0&&!h(e.search.frontmatter)&&i.push("items["+t+"].search.frontmatter must be an object")):i.push("items["+t+"].search must be an object")),e.chunks!==void 0)if(!Array.isArray(e.chunks))i.push("items["+t+"].chunks must be an array when present");else for(let[r,n]of e.chunks.entries()){if(!h(n)){i.push("items["+t+"].chunks["+r+"] must be an object");continue}n.metadata!==void 0&&!h(n.metadata)&&i.push("items["+t+"].chunks["+r+"].metadata must be an object");}if(e.embeddings!==void 0)if(!Array.isArray(e.embeddings))i.push("items["+t+"].embeddings must be an array when present");else for(let[r,n]of e.embeddings.entries()){if(!h(n)){i.push("items["+t+"].embeddings["+r+"] must be an object");continue}let s=n.embedding??n.vector;s!==void 0&&(!Array.isArray(s)||!s.every(a=>typeof a=="number"))&&i.push("items["+t+"].embeddings["+r+"].embedding/vector must be a number array"),n.metadata!==void 0&&!h(n.metadata)&&i.push("items["+t+"].embeddings["+r+"].metadata must be an object");}if(e.compatibility!==void 0&&!h(e.compatibility)&&i.push("items["+t+"].compatibility must be an object"),e.operational_state!==void 0){let r="items["+t+"].operational_state";if(!h(e.operational_state))i.push(r+" must be an object");else {let n=e.operational_state,s=new Set(["fresh","historical","superseded","contradicted","needs-source"]),a=new Set(["source","candidate","reviewed","rejected"]),o=["source_repo","source_kind","source_id","observed_state","observed_at","source_updated_at","evidence_url","evidence_path","observer","stale_after"],c=["supersedes","contradicts"],g=new Set([...o,...c,"classification","confidence","current_action_selector"]);s.has(String(n.classification))||i.push(r+".classification must be fresh, historical, superseded, contradicted, or needs-source");for(let d of o)n[d]!==void 0&&!l(n[d])&&i.push(r+"."+d+" must be a non-empty string");for(let d of ["observed_at","source_updated_at","stale_after"])n[d]!==void 0&&(typeof n[d]!="string"||Number.isNaN(Date.parse(n[d])))&&i.push(r+"."+d+" must be a date-time string");for(let d of c)j(n[d])||i.push(r+"."+d+" must be a string array");n.confidence!==void 0&&!a.has(String(n.confidence))&&i.push(r+".confidence must be source, candidate, reviewed, or rejected"),n.current_action_selector!==void 0&&typeof n.current_action_selector!="boolean"&&i.push(r+".current_action_selector must be a boolean"),Object.keys(n).some(d=>!g.has(d))&&i.push(r+" contains unsupported fields");}}if(e.state_transfer!==void 0){let r="items["+t+"].state_transfer";if(!h(e.state_transfer))i.push(r+" must be an object");else {let n=e.state_transfer,s=n.deleted_at;Object.hasOwn(n,"deleted_at")?s!==null&&(typeof s!="string"||Number.isNaN(Date.parse(s)))&&i.push(r+".deleted_at must be a date-time string or null"):i.push(r+".deleted_at is required"),Object.keys(n).some(a=>a!=="deleted_at")&&i.push(r+" contains unsupported fields");}}}function P(e){return e==="private"||e==="sanitized"||e==="public"}function se(e){return e==="source"||e==="candidate"||e==="reviewed"||e==="rejected"}function ve(e,t,i){if(Array.isArray(e.provenance))for(let[r,n]of e.provenance.entries()){let s="items["+t+"].provenance["+r+"]";if(!h(n)){i.push(s+" must be an object");continue}l(n.field)||i.push(s+".field is required"),l(n.source)||i.push(s+".source is required"),l(n.path)||i.push(s+".path is required"),se(n.confidence)||i.push(s+".confidence must be one of source, candidate, reviewed, rejected"),P(n.privacy)||i.push(s+".privacy must be one of private, sanitized, public");}}var _e=["search","chunks","embeddings","skos_concepts","skos_relations","provenance_events","compatibility","operational_state","state_transfer"],Re=["origin","generated","checksum","updated_at"],ke=["target_path","direction","metadata"];function Ie(e,t,i){if(e.schema_version!=="aiwg.fortemi.index.record.v1")return;let r="items["+t+"]",n=e,s=" is a v2-only field and must be absent on a record.v1 record";for(let a of _e)n[a]!==void 0&&i.push(r+"."+a+s);if(h(e.source)){let a=e.source;for(let o of Re)a[o]!==void 0&&i.push(r+".source."+o+s);}if(h(e.privacy)&&e.privacy.locality!==void 0&&i.push(r+".privacy.locality"+s),Array.isArray(e.relationships))for(let[a,o]of e.relationships.entries()){if(!h(o))continue;let c=o;for(let g of ke)c[g]!==void 0&&i.push(r+".relationships["+a+"]."+g+s);}}function ae(e){let t=[],i=Object.create(null),r=h(e)?e:{};h(e)||t.push("index export must be an object"),re(r?.schema_version)||t.push("schema_version must be aiwg.fortemi.index.export.v1 or aiwg.fortemi.index.export.v2"),l(r?.generated_at)||t.push("generated_at is required"),l(r?.source?.repo)||t.push("source.repo is required"),l(r?.source?.privacy)?P(r?.source?.privacy)||t.push("source.privacy must be one of private, sanitized, public"):t.push("source.privacy is required"),Array.isArray(r?.items)||t.push("items must be an array"),r.compatibility!==void 0&&!h(r.compatibility)&&t.push("compatibility must be an object"),r?.schema_version==="aiwg.fortemi.index.export.v1"&&(h(r.source)&&r.source.graph!==void 0&&t.push("source.graph is a v2-only field and must be absent on an export.v1 export"),r.compatibility!==void 0&&t.push("compatibility is a v2-only field and must be absent on an export.v1 export"));let n=new Set,s="",a=Array.isArray(r.items)?r.items:[];for(let[o,c]of a.entries()){if(!h(c)){t.push("items["+o+"] must be an object");continue}for(let g of be)g in c||t.push("items["+o+"]."+g+" is required");ne(c.schema_version)||t.push("items["+o+"].schema_version must be aiwg.fortemi.index.record.v1 or aiwg.fortemi.index.record.v2"),r.schema_version==="aiwg.fortemi.index.export.v1"&&c.schema_version==="aiwg.fortemi.index.record.v2"&&t.push("items["+o+"].schema_version must match aiwg.fortemi.index.export.v1"),l(c.id)||t.push("items["+o+"].id is required"),l(c.id)&&n.has(c.id)&&t.push("duplicate id: "+c.id),l(c.id)&&n.add(c.id),s&&l(c.id)&&s>c.id&&t.push("items must be sorted by id: "+s+" before "+c.id),l(c.id)&&(s=c.id),l(c.type)?i[c.type]=(i[c.type]??0)+1:t.push("items["+o+"].type must be a non-empty string"),l(c.source?.path)||t.push("items["+o+"].source.path is required"),l(c.source?.repo_relative_path)||t.push("items["+o+"].source.repo_relative_path is required"),l(c.source?.locator)||t.push("items["+o+"].source.locator is required"),typeof c.title!="string"&&typeof c.search?.title!="string"&&typeof c.search?.name!="string"&&t.push("items["+o+"].title or search.title/search.name is required"),typeof c.text!="string"&&typeof c.search?.body!="string"&&typeof c.search?.summary!="string"&&t.push("items["+o+"].text or search.body/search.summary is required"),Array.isArray(c.tags)||t.push("items["+o+"].tags must be an array"),Array.isArray(c.concepts)||t.push("items["+o+"].concepts must be an array"),Array.isArray(c.relationships)||t.push("items["+o+"].relationships must be an array"),(!Array.isArray(c.provenance)||c.provenance.length===0)&&t.push("items["+o+"].provenance must be a non-empty array"),xe(c,o,t),ve(c,o,t),Ie(c,o,t),!c.privacy||typeof c.privacy.pii!="boolean"||!l(c.privacy.classification)?t.push("items["+o+"].privacy requires classification and pii"):P(c.privacy.classification)||t.push("items["+o+"].privacy.classification must be one of private, sanitized, public");}return {valid:t.length===0,errors:t,counts:i}}function q(e){let t=ae(e);if(!t.valid)throw new Error(`Invalid AIWG Fortemi index export:
|
|
2
2
|
`+t.errors.join(`
|
|
3
|
-
`));return e}function Ce(e){let t=[],i=h(e)?e:{};if(h(e)||t.push("chunk manifest must be an object"),i?.schema_version!=="aiwg.fortemi.index.chunk-manifest.v1"&&t.push("schema_version must be aiwg.fortemi.index.chunk-manifest.v1"),l(i?.generated_at)||t.push("generated_at is required"),l(i?.source?.repo)||t.push("source.repo is required"),l(i?.source?.privacy)||t.push("source.privacy is required"),i?.source_export_schema_version!==void 0&&!re(i.source_export_schema_version)&&t.push("source_export_schema_version must be aiwg.fortemi.index.export.v1 or aiwg.fortemi.index.export.v2 when present"),C(i?.total)||t.push("total must be a non-negative integer"),S(i?.part_size)||t.push("part_size must be a positive integer"),i.facets!==void 0&&!Ae(i.facets)&&t.push("facets must be a nested string-to-number count object"),i.projection!==void 0)if(!Array.isArray(i.projection)||!i.projection.every(s=>typeof s=="string"))t.push("projection must be an array of field names");else {let s=new Set(i.projection);for(let
|
|
3
|
+
`));return e}function Ce(e){let t=[],i=h(e)?e:{};if(h(e)||t.push("chunk manifest must be an object"),i?.schema_version!=="aiwg.fortemi.index.chunk-manifest.v1"&&t.push("schema_version must be aiwg.fortemi.index.chunk-manifest.v1"),l(i?.generated_at)||t.push("generated_at is required"),l(i?.source?.repo)||t.push("source.repo is required"),l(i?.source?.privacy)||t.push("source.privacy is required"),i?.source_export_schema_version!==void 0&&!re(i.source_export_schema_version)&&t.push("source_export_schema_version must be aiwg.fortemi.index.export.v1 or aiwg.fortemi.index.export.v2 when present"),C(i?.total)||t.push("total must be a non-negative integer"),S(i?.part_size)||t.push("part_size must be a positive integer"),i.facets!==void 0&&!Ae(i.facets)&&t.push("facets must be a nested string-to-number count object"),i.projection!==void 0)if(!Array.isArray(i.projection)||!i.projection.every(s=>typeof s=="string"))t.push("projection must be an array of field names");else {let s=new Set(i.projection);for(let a of we)s.has(a)||t.push("projection must include scan-required field "+a);}i.detail!==void 0&&!h(i.detail)?t.push("detail must be an object"):i.detail!==void 0&&(l(i.detail.href)?i.detail.href.includes("{id}")||t.push("detail.href must contain the {id} placeholder"):t.push("detail.href is required"),i.detail.encoding!==void 0&&i.detail.encoding!=="uri"&&i.detail.encoding!=="base64url"&&t.push("detail.encoding must be 'uri' or 'base64url'")),Array.isArray(i?.parts)||t.push("parts must be an array");let r=0,n=Array.isArray(i?.parts)?i.parts:[];for(let[s,a]of n.entries()){if(!h(a)){t.push("parts["+s+"] must be an object");continue}l(a.href)||t.push("parts["+s+"].href is required"),C(a.offset)||t.push("parts["+s+"].offset must be a non-negative integer"),C(a.count)||t.push("parts["+s+"].count must be a non-negative integer"),C(a.offset)&&a.offset!==r&&t.push("parts["+s+"].offset must be "+r),C(a.count)&&(r+=a.count);}return C(i?.total)&&r!==i.total&&t.push("parts counts must add up to total"),{valid:t.length===0,errors:t}}function Fe(e){let t=Ce(e);if(!t.valid)throw new Error(`Invalid AIWG Fortemi chunk manifest:
|
|
4
4
|
`+t.errors.join(`
|
|
5
|
-
`));return e}function Se(e,t,i){let r="items["+t+"]";if(!e.privacy||!h(e.privacy)?i.push(r+"/privacy requires classification and pii"):(P(e.privacy.classification)||i.push(r+"/privacy/classification must be one of private, sanitized, public"),typeof e.privacy.pii!="boolean"&&i.push(r+"/privacy/pii must be boolean")),Array.isArray(e.provenance))for(let[n,s]of e.provenance.entries()){if(!h(s)){i.push(r+"/provenance/"+n+" must be an object");continue}se(s.confidence)||i.push(r+"/provenance/"+n+"/confidence must be one of source, candidate, reviewed, rejected"),P(s.privacy)||i.push(r+"/provenance/"+n+"/privacy must be one of private, sanitized, public");}}function Pe(e,t){let i=[],r=new Set,n="";for(let[s,
|
|
5
|
+
`));return e}function Se(e,t,i){let r="items["+t+"]";if(!e.privacy||!h(e.privacy)?i.push(r+"/privacy requires classification and pii"):(P(e.privacy.classification)||i.push(r+"/privacy/classification must be one of private, sanitized, public"),typeof e.privacy.pii!="boolean"&&i.push(r+"/privacy/pii must be boolean")),Array.isArray(e.provenance))for(let[n,s]of e.provenance.entries()){if(!h(s)){i.push(r+"/provenance/"+n+" must be an object");continue}se(s.confidence)||i.push(r+"/provenance/"+n+"/confidence must be one of source, candidate, reviewed, rejected"),P(s.privacy)||i.push(r+"/provenance/"+n+"/privacy must be one of private, sanitized, public");}}function Pe(e,t){let i=[],r=new Set,n="";for(let[s,a]of e.entries()){if(!h(a)){i.push("items["+s+"] must be an object");continue}Se(a,s,i);let o=t==="aiwg.fortemi.index.export.v2"?"aiwg.fortemi.index.record.v2":"aiwg.fortemi.index.record.v1";a.schema_version!==o&&i.push(`items[${s}].schema_version must match ${t}`),ne(a.schema_version)||i.push("items["+s+"].schema_version must be aiwg.fortemi.index.record.v1 or aiwg.fortemi.index.record.v2"),l(a.id)||i.push("items["+s+"].id is required"),l(a.id)&&r.has(a.id)&&i.push("duplicate id: "+a.id),l(a.id)&&r.add(a.id),n&&l(a.id)&&n>a.id&&i.push("items must be sorted by id: "+n+" before "+a.id),l(a.id)&&(n=a.id),l(a.type)||i.push("items["+s+"].type must be a non-empty string"),typeof a.title!="string"&&typeof a.search?.title!="string"&&typeof a.search?.name!="string"&&i.push("items["+s+"].title or search.title/search.name is required"),typeof a.text!="string"&&typeof a.search?.body!="string"&&typeof a.search?.summary!="string"&&i.push("items["+s+"].text or search.body/search.summary is required"),(!a.facets||typeof a.facets!="object"||Array.isArray(a.facets))&&i.push("items["+s+"].facets must be an object"),Array.isArray(a.tags)||i.push("items["+s+"].tags must be an array"),Array.isArray(a.concepts)||i.push("items["+s+"].concepts must be an array");}return i}function Ee(e,t,i){let r=[],n=h(e)?e:{};if(h(e)||r.push("chunk part must be an object"),n?.schema_version!=="aiwg.fortemi.index.chunk.v1"&&r.push("schema_version must be aiwg.fortemi.index.chunk.v1"),n?.manifest_schema_version!=="aiwg.fortemi.index.chunk-manifest.v1"&&r.push("manifest_schema_version must be aiwg.fortemi.index.chunk-manifest.v1"),C(n?.offset)||r.push("offset must be a non-negative integer"),Array.isArray(n?.items)||r.push("items must be an array"),t&&C(n?.offset)&&n.offset!==t.offset&&r.push("offset must match manifest part offset "+t.offset),t&&Array.isArray(n?.items)&&n.items.length!==t.count&&r.push("items length must match manifest part count "+t.count),Array.isArray(n?.items))if(i?.projection)r.push(...Pe(n.items,i.source_export_schema_version??"aiwg.fortemi.index.export.v1").map(s=>"items."+s));else {let s=ae({schema_version:i?.source_export_schema_version??"aiwg.fortemi.index.export.v1",generated_at:i?.generated_at??"1970-01-01T00:00:00.000Z",source:i?.source??{repo:"chunk",privacy:"public"},...(i?.source_export_schema_version??"aiwg.fortemi.index.export.v1")==="aiwg.fortemi.index.export.v2"?{compatibility:{previous_schema_version:"aiwg.fortemi.index.export.v1",strategy:"supported"}}:{},items:n.items});r.push(...s.errors.map(a=>"items."+a));}return {valid:r.length===0,errors:r}}function Oe(e,t,i){let r=Ee(e,t,i);if(!r.valid)throw new Error(`Invalid AIWG Fortemi chunk part:
|
|
6
6
|
`+r.errors.join(`
|
|
7
|
-
`));return e}var X=new Set(["http:","https:","blob:","data:"]);function Me(e){try{return new URL(e)}catch{return null}}function
|
|
7
|
+
`));return e}var X=new Set(["http:","https:","blob:","data:"]);function Me(e){try{return new URL(e)}catch{return null}}function oe(e,t){if(t===void 0){let n=Me(e);if(n&&!X.has(n.protocol))throw new Error("Refusing AIWG index fetch with disallowed scheme: "+n.protocol);return e}let i=new URL(t),r=new URL(e,i);if(!X.has(r.protocol))throw new Error("Refusing AIWG index fetch with disallowed scheme: "+r.protocol);if(r.origin!==i.origin)throw new Error("Refusing cross-origin AIWG index fetch: "+r.origin+" != "+i.origin);return r.toString()}function At(e){return async t=>{let i=oe(t.href,e),r=await fetch(i);if(!r.ok)throw new Error("Failed to fetch AIWG index chunk "+i+": "+r.status);return r.json()}}function je(e,t="base64url"){if(t==="uri")return encodeURIComponent(e);let i=new TextEncoder().encode(e),r="";for(let n of i)r+=String.fromCharCode(n);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function ce(e,t){return e.href.replace("{id}",je(t,e.encoding??"uri"))}function xt(e){return async(t,i)=>{if(!i.detail?.href)throw new Error("Manifest has no detail.href for record resolution");let r=ce(i.detail,t),n=oe(r,e),s=await fetch(n);if(!s.ok)throw new Error("Failed to fetch AIWG index detail "+n+": "+s.status);return s.json()}}function de(e){let t=Object.create(null);for(let i of e){M(t,"type",i.type),M(t,"privacy",i.privacy.classification);for(let r of i.tags)M(t,"tag",r);for(let r of i.concepts)M(t,"concept",r);for(let[r,n]of Object.entries(i.facets))for(let s of n)M(t,r,s);}return t}function E(e){return e.title??e.search?.title??e.search?.name??e.id}function D(e){let t=e.text??e.search?.body??e.search?.summary??e.chunks?.map(r=>r.text??r.body??r.summary??"").filter(Boolean).join(`
|
|
8
8
|
`)??"",i=ue(e);return [t,i].filter(Boolean).join(`
|
|
9
9
|
`)}function ue(e){return "binary_sources"in e?e.binary_sources?.map(t=>t.extracted_text).filter(Boolean).join(`
|
|
10
|
-
`)??"":""}function
|
|
10
|
+
`)??"":""}function De(e,t){let i=E(e),r=D(e);return t==="title-summary"?[i,e.search?.summary??"",ue(e)].filter(Boolean).join(`
|
|
11
11
|
`):[i,r].filter(Boolean).join(`
|
|
12
|
-
`)}function Le(e){return e instanceof Date?e.toISOString():e??new Date().toISOString()}var Qe=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function
|
|
13
|
-
`),y=e.search?.type??e.type,
|
|
12
|
+
`)}function Le(e){return e instanceof Date?e.toISOString():e??new Date().toISOString()}var Qe=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function k(e,t){return e>>>t|e<<32-t}function Te(e){let t=e.length*8,i=new Uint8Array(e.length+9+63>>6<<6);i.set(e),i[e.length]=128;let r=new DataView(i.buffer);r.setUint32(i.length-4,t>>>0),r.setUint32(i.length-8,Math.floor(t/4294967296));let n=1779033703,s=3144134277,a=1013904242,o=2773480762,c=1359893119,g=2600822924,d=528734635,f=1541459225,u=new Uint32Array(64);for(let p=0;p<i.length;p+=64){for(let w=0;w<16;w++)u[w]=r.getUint32(p+w*4);for(let w=16;w<64;w++){let m=k(u[w-15],7)^k(u[w-15],18)^u[w-15]>>>3,F=k(u[w-2],17)^k(u[w-2],19)^u[w-2]>>>10;u[w]=u[w-16]+m+u[w-7]+F>>>0;}let y=n,x=s,A=a,b=o,v=c,_=g,R=d,I=f;for(let w=0;w<64;w++){let m=k(v,6)^k(v,11)^k(v,25),F=v&_^~v&R,O=I+m+F+Qe[w]+u[w]>>>0,W=k(y,2)^k(y,13)^k(y,22),N=y&x^y&A^x&A,L=W+N>>>0;I=R,R=_,_=v,v=b+O>>>0,b=A,A=x,x=y,y=O+L>>>0;}n=n+y>>>0,s=s+x>>>0,a=a+A>>>0,o=o+b>>>0,c=c+v>>>0,g=g+_>>>0,d=d+R>>>0,f=f+I>>>0;}return [n,s,a,o,c,g,d,f].map(p=>p.toString(16).padStart(8,"0")).join("")}function qe(e){return `sha256:${Te(e)}`}async function vt(e,t){q(e);let i=t.granularity??"body",r=ie(t.records??e.items,t.privacy),n=[];for(let a of r){let o=t.textForRecord?.(a)??De(a,i),c=await t.backend.embed(o,a);if(c.length!==t.backend.dimensions)throw new Error(`Embedding for ${a.id} has ${c.length} dimensions; expected ${t.backend.dimensions}`);n.push({record_id:a.id,embedding:c,granularity:i,input_hash:qe(new TextEncoder().encode(o)),source_path:a.source.path});}let s={schema_version:"aiwg.fortemi.embedding.set.v1",id:t.id,model:t.backend.model,dimensions:t.backend.dimensions,generated_at:Le(t.generatedAt),granularity:i,...t.metric?{metric:t.metric}:{},input_hash_algorithm:"sha256",embeddings:n};return Y(s),s}function We(e){let t=e.search,i=[e.id,E(e),D(e),t?.title,t?.name,t?.summary,t?.body,t?.capability,t?.phase,t?.type,...t?.triggers??[],...t?.aliases??[],...t?.tags??[],...(e.chunks??[]).flatMap(r=>[r.text,r.body,r.summary,r.source_path])];if(t?.frontmatter)for(let r of Object.values(t.frontmatter))typeof r=="string"?i.push(r):Array.isArray(r)&&i.push(...r.filter(n=>typeof n=="string"));return i.filter(r=>typeof r=="string"&&r.length>0)}function _t(e,t={}){q(e);let i=S(t.partSize)?t.partSize:500,r=t.projection,n=t.idEncoding??"base64url",s=t.detailHref??"detail/{id}.json",a=ie(e.items,t.privacy),o=u=>String(u).padStart(4,"0"),c=u=>{if(!r)return u;let p={};for(let y of r)p[y]=u[y];return p},g=[],d=[];for(let u=0,p=0;u<a.length;u+=i,p+=1){let y=a.slice(u,u+i),x="part-"+o(p)+".json";g.push({href:x,part:{schema_version:"aiwg.fortemi.index.chunk.v1",manifest_schema_version:"aiwg.fortemi.index.chunk-manifest.v1",offset:u,items:y.map(c)}}),d.push({href:x,offset:u,count:y.length});}return {manifest:{schema_version:"aiwg.fortemi.index.chunk-manifest.v1",generated_at:t.generatedAt??e.generated_at,source:e.source,source_export_schema_version:e.schema_version,total:a.length,part_size:i,facets:de(a),parts:d,...r?{projection:r,detail:{href:s,encoding:n}}:{}},parts:g,details:r?a.map(u=>({id:u.id,href:ce({href:s,encoding:n},u.id),record:u})):[]}}function U(e,t){if(!t||t.length===0)return true;let i=new Set(e);return t.every(r=>i.has(r))}function Ne(e,t){return t?Object.entries(t).every(([i,r])=>U(e.facets[i]??[],r)):true}function Ge(e,t){if(!t)return [];let i=[],r=E(e),n=D(e);r.toLowerCase().includes(t)&&i.push({field:"title",value:r}),n.toLowerCase().includes(t)&&i.push({field:"text",value:n});for(let s of e.tags)s.toLowerCase().includes(t)&&i.push({field:"tag",value:s});for(let s of e.concepts)s.toLowerCase().includes(t)&&i.push({field:"concept",value:s});for(let s of We(e))s!==r&&s!==n&&s.toLowerCase().includes(t)&&i.push({field:"text",value:s,score:K.text});return i}var Ve=new Set(["the","a","an","and","or","of","for","to","in","on","with","into","from","is","are","be","i","we","my","it","you","me","us","your","our","this","that","these","those","there","here","some","any","all","also","please","about","how","what","which","where","when","who","why","find","give","show","need","want","looking","look","help","do","does","did","can","could","should","would","will","handle","handles","handling","aiwg","skill","skills","agent","agents","command","commands","rule","rules","flow","flows","workflow","workflows"]);function Q(e){return e.toLowerCase().replace(/[-_\s]+/g," ").trim()}function ze(e){return e.toLowerCase().split(/[^a-z0-9-]+/).filter(t=>t.length>1&&!Ve.has(t))}function V(e,t){return t.flatMap(i=>e.facets[i]??[])}function Z(e,t){e.some(i=>i.field===t.field&&i.value===t.value&&i.reason===t.reason)||e.push(t);}function Ue(e,t){if(e===t)return true;if(Math.abs(e.length-t.length)>1)return false;if(e.length===t.length){let o=-1,c=0;for(let g=0;g<e.length;g+=1)e[g]!==t[g]&&(o<0&&(o=g),c+=1);return c===1?true:c===2&&o+1<e.length&&e[o]===t[o+1]&&e[o+1]===t[o]}let i=e.length<t.length?e:t,r=e.length<t.length?t:e,n=0,s=0,a=0;for(;n<i.length&&s<r.length;)if(i[n]===r[s])n+=1,s+=1;else {if(a+=1,a>1)return false;s+=1;}return true}function Be(e,t){let i=Q(e).split(/\s+/).filter(Boolean),r=Q(t).split(/\s+/).filter(Boolean);return i.length!==r.length?false:i.every((n,s)=>{let a=r[s];return n===a?true:n.length<5||a.length<5?false:Ue(n,a)})}function $e(e){return e.map(t=>t.toLowerCase())}function He(e,t,i={}){if(!t)return [];let r=[],n=ze(t),s=n.length>0?n.join(" "):t.toLowerCase().trim(),a=t.toLowerCase().trim(),o=e.id.split(/[:/]/),c=[e.id,E(e),e.search?.name,e.search?.title,...e.search?.aliases??[],...o,...V(e,["name","canonical_name","command","skill","agent","rule"])].filter(m=>l(m)),g=[...V(e,["trigger","triggers","trigger_phrase","trigger_phrases"]),...e.search?.triggers??[]],d=[...V(e,["capability","capabilities","summary","description"]),e.search?.capability,e.search?.summary,e.search?.phase,e.search?.type,...e.search?.tags??[],...e.concepts,...e.tags].filter(m=>l(m)),f=[e.source?.path,e.source?.repo_relative_path,e.source?.locator].filter(m=>l(m)),u=E(e),p=[e.search?.summary,D(e)].filter(m=>l(m)).join(`
|
|
13
|
+
`),y=e.search?.type??e.type,x=[...e.search?.tags??[],...e.tags],A=n.length>1,b=A?i.relaxOverlap?1:Math.ceil(n.length/2):1,v=m=>A&&m>=b,_=m=>Z(r,{...m,score:0}),R=m=>{m>0&&Z(r,{field:"id",value:e.id,score:m,reason:"aiwg discovery score"});};for(let m of c){if(Q(t)===Q(m))return _({field:"id",value:m,reason:"exact canonical name"}),R(1.001),r;if(Be(t,m))return _({field:"id",value:m,reason:"near canonical name"}),R(.951),r}let I=0,w=(m,F,O,W,N,L,me=0)=>{let G=F.toLowerCase();if(G.includes(s))I+=W*L,G===s&&(I+=me),_({field:m,value:F,reason:O});else if(A){let J=n.filter(he=>G.includes(he)).length;v(J)&&(I+=N*L*(J/n.length),_({field:m,value:F,reason:O}));}};for(let m of $e(g))if(m===s||m===a)return _({field:"facet",value:m,reason:"trigger phrase"}),R(1.0008),r;for(let m of g)w("facet",m,"trigger phrase",.25,.06,4);for(let m of d)w("concept",m,"capability overlap",.2,.1,2);w("title",u,"title token overlap",.3,.08,3,.2);for(let m of x)w("tag",m,"tag token overlap",.2,.05,2);p&&w("text",p,"body token overlap",.15,.04,1);for(let m of f)w("source",m,"path overlap",.1,.03,1);return y.toLowerCase().includes(s)&&(I+=.1,_({field:"facet",value:y,reason:"type overlap"})),R(Math.min(I,1)),r}function Ke(e,t){return e.reduce((i,r)=>i+(r.score??t[r.field]),0)}function Ye(e,t,i){let r=Math.max(20,i);if(!e)return "";if(!t)return e.length>r?`${e.slice(0,r).trimEnd()}...`:e;let s=e.toLowerCase().indexOf(t);if(s<0)return e.length>r?`${e.slice(0,r).trimEnd()}...`:e;let a=Math.max(0,Math.floor((r-t.length)/2)),o=Math.max(0,s-a),c=Math.min(e.length,o+r),g=o>0?"...":"",d=c<e.length?"...":"";return `${g}${e.slice(o,c).trim()}${d}`}function Je(e,t,i,r){let n=t.find(o=>o.field==="text"),s=t.find(o=>o.field==="title"),a=n??s??t[0];return Ye(a?.value??D(e),i,r)}function B(e,t,i,r=0,n={}){let s={...K,...i.weights},a=i.searchProfile??"default";return e.map((o,c)=>({item:o,ordinal:r+c,matches:a==="aiwg-discovery"?He(o,t,n):Ge(o,t)})).filter(({item:o,matches:c})=>!(t&&c.length===0||i.types&&!i.types.includes(o.type)||i.privacy&&!i.privacy.includes(o.privacy.classification)||!U(o.tags,i.tags)||!U(o.concepts,i.concepts)||!Ne(o,i.facets)||i.relationshipTargetId&&!(o.relationships??[]).some(g=>g.target_id===i.relationshipTargetId))).map(({item:o,ordinal:c,matches:g})=>({item:o,ordinal:c,rank:Ke(g,s),matches:g}))}function Xe(e,t){return [...e].sort((i,r)=>t&&r.rank-i.rank||i.ordinal-r.ordinal)}function T(e,t,i){let r=Xe(e,i.rank),n=i.offset??0,s=i.limit??r.length,a=r.slice(n,n+s),o={items:a.map(c=>c.item),total:r.length,facets:de(r.map(c=>c.item))};if(i.rank||i.snippets||i.includeMatches){let c=i.snippetLength??160;o.rankedItems=a.map(g=>({item:g.item,rank:g.rank,...i.snippets?{snippet:Je(g.item,g.matches,t,c)}:{},...i.includeMatches?{matches:g.matches}:{}}));}return o}function ge(e,t="",i={}){let r=t.trim().toLowerCase(),n=B(e.items,r,i);return n.length===0&&r&&i.searchProfile==="aiwg-discovery"?T(B(e.items,r,i,0,{relaxOverlap:true}),r,i):T(n,r,i)}function fe(e,t){if(e.length!==t.length||e.length===0)return 0;let i=0,r=0,n=0;for(let s=0;s<e.length;s+=1){let a=e[s],o=t[s];i+=a*o,r+=a*a,n+=o*o;}return r===0||n===0?0:i/(Math.sqrt(r)*Math.sqrt(n))}function Ze(e){let t=[],i=h(e)?e:{};h(e)||t.push("embedding set must be an object"),i?.schema_version!=="aiwg.fortemi.embedding.set.v1"&&t.push("schema_version must be aiwg.fortemi.embedding.set.v1"),l(i?.id)||t.push("id is required"),l(i?.model)||t.push("model is required"),S(i?.dimensions)||t.push("dimensions must be a positive integer"),l(i?.generated_at)||t.push("generated_at is required"),l(i?.granularity)||t.push("granularity is required"),Array.isArray(i?.embeddings)||t.push("embeddings must be an array");let r=Array.isArray(i.embeddings)?i.embeddings:[];for(let[n,s]of r.entries()){if(!h(s)){t.push("embeddings["+n+"] must be an object");continue}l(s.record_id)||t.push("embeddings["+n+"].record_id is required"),l(s.input_hash)||t.push("embeddings["+n+"].input_hash is required"),Array.isArray(s.embedding)?S(i?.dimensions)&&s.embedding.length!==i.dimensions?t.push("embeddings["+n+"].embedding length must match dimensions"):s.embedding.every(a=>typeof a=="number"&&Number.isFinite(a))||t.push("embeddings["+n+"].embedding must contain finite numbers"):t.push("embeddings["+n+"].embedding must be an array");}return {valid:t.length===0,errors:t}}function Y(e){let t=Ze(e);if(!t.valid)throw new Error(`Invalid AIWG Fortemi embedding set:
|
|
14
14
|
`+t.errors.join(`
|
|
15
|
-
`));return e}function et(e,t,i,r={}){if(Y(t),i.length!==t.dimensions)throw new Error("query embedding length must match embedding set dimensions");let n=new Map(e.items.map(a=>[a.id,a])),s=r.offset??0,o=r.limit??20;return t.embeddings.map(a=>{let c=n.get(a.record_id);return c?{item:c,embedding:a,score:fe(i,a.embedding)}:null}).filter(a=>a!==null&&a.score>=(r.minScore??-1)).sort((a,c)=>c.score-a.score||a.item.id.localeCompare(c.item.id)).slice(s,s+o)}function kt(e,t,i,r,n={}){let s={...n};delete s.limit,delete s.offset;let o=ge(e,i,{...s,rank:true}),a=et(e,t,r,{limit:e.items.length}),c=n.lexicalWeight??.5,g=n.semanticWeight??.5,u=new Map(o.rankedItems?.map(x=>[x.item.id,x.rank])??[]),f=Math.max(1,...u.values()),d=new Map(a.flatMap(x=>x.embedding?[[x.item.id,x.embedding]]:[])),m=new Map(a.map(x=>[x.item.id,x.score])),y=new Set([...u.keys(),...m.keys()]),b=n.offset??0,A=n.limit??20;return [...y].map(x=>{let v=e.items.find(k=>k.id===x),R=d.get(x);return v?{item:v,...R?{embedding:R}:{},score:(u.get(x)??0)/f*c+(m.get(x)??0)*g}:null}).filter(x=>x!==null&&x.score>=(n.minScore??-1)).sort((x,v)=>v.score-x.score||x.item.id.localeCompare(v.item.id)).slice(b,b+A)}var tt=5e3;function _t(e,t,i=.9,r){Y(t);let n=r?.maxEmbeddings??tt;if(t.embeddings.length>n)throw new Error("Embedding set too large for duplicate scan: "+t.embeddings.length+" > "+n+" (raise options.maxEmbeddings to override for trusted input)");let s=new Map(e.items.map(a=>[a.id,a])),o=[];for(let a=0;a<t.embeddings.length;a+=1)for(let c=a+1;c<t.embeddings.length;c+=1){let g=t.embeddings[a],u=t.embeddings[c],f=s.get(g.record_id),d=s.get(u.record_id);if(!f||!d)continue;let m=fe(g.embedding,u.embedding);m>=i&&o.push({left:f,right:d,score:m});}return o.sort((a,c)=>c.score-a.score||a.left.id.localeCompare(c.left.id))}function it(e){return `${e.offset}:${e.href}`}function rt(e){return S(e)?e:3}function nt(e){return S(e)?e:32}function st(e){return S(e)?e:5e3}function ot(e,t){return JSON.stringify({q:e,types:t.types??null,facets:t.facets??null,tags:t.tags??null,concepts:t.concepts??null,privacy:t.privacy??null,rel:t.relationshipTargetId??null,searchProfile:t.searchProfile??"default",weights:{...K,...t.weights}})}function at(e,t,i){e.matchCache.delete(t),e.matchCache.set(t,i);let r=0;for(let n of e.matchCache.values())r+=n.length;for(;r>e.maxCachedMatches&&e.matchCache.size>1;){let n=e.matchCache.keys().next().value;if(n===void 0||n===t)break;r-=e.matchCache.get(n)?.length??0,e.matchCache.delete(n);}}function ct(e,t){return e.trim()===""&&!t.rank&&!t.snippets&&!t.includeMatches&&!t.types&&!t.facets&&!t.tags&&!t.concepts&&!t.privacy&&!t.relationshipTargetId}function dt(e,t,i){let r=t+i;return e.parts.filter(n=>n.count>0&&n.offset<r&&n.offset+n.count>t)}async function $(e,t){let i=it(t),r=e.partCache.get(i);if(r)return e.partCache.delete(i),e.partCache.set(i,r),{part:r,fetched:false};let n=Oe(await e.loader(t,e.manifest),t,e.manifest);for(e.partCache.set(i,n);e.partCache.size>e.maxCachedParts;){let s=e.partCache.keys().next().value;if(s===void 0)break;e.partCache.delete(s);}return {part:n,fetched:true}}async function le(e,t){let i=e.detailCache.get(t);if(i)return e.detailCache.delete(t),e.detailCache.set(t,i),i;if(!e.manifest.projection)for(let s of e.partCache.values()){let o=s.items.find(a=>a.id===t);if(o)return o}if(!e.detailLoader)throw new Error("No detailLoader configured to resolve record "+t);let r=await e.detailLoader(t,e.manifest),n=q({schema_version:"aiwg.fortemi.index.export.v1",generated_at:e.manifest.generated_at,source:e.manifest.source,items:[r]}).items[0];if(n.id!==t)throw new Error("Detail record id mismatch: expected "+t+", got "+n.id);for(e.detailCache.set(t,n);e.detailCache.size>e.maxCachedDetails;){let s=e.detailCache.keys().next().value;if(s===void 0)break;e.detailCache.delete(s);}return n}function ut(e){return e?.relationshipType??e?.type}function gt(e,t){return {source_id:e,target_id:t.target_id,type:t.type,...t.source_path?{source_path:t.source_path}:{},...t.target_path?{target_path:t.target_path}:{},...t.direction?{direction:t.direction}:{}}}function ft(e,t={}){let i=ut(t);return !(i&&e.type!==i||t.relationshipDirection&&e.direction!==t.relationshipDirection||t.sourceId&&e.source_id!==t.sourceId||t.targetId&&e.target_id!==t.targetId||t.endpointId&&e.source_id!==t.endpointId&&e.target_id!==t.endpointId)}function lt(e){if(e.direction==="out"&&!e.sourceId)throw new Error("relationship direction 'out' requires sourceId");if(e.direction==="in"&&!e.targetId)throw new Error("relationship direction 'in' requires targetId")}function mt(e){return {id:e.id,type:e.type,title:E(e)}}function ee(e,t){t&&e.set(t.id,mt(t));}function H(e,t={}){lt(t);let i=new Map(e.map(a=>[a.id,a])),r=[];for(let a of e)for(let c of a.relationships??[]){let g=gt(a.id,c);ft(g,t)&&r.push(g);}let n=r.sort((a,c)=>a.source_id.localeCompare(c.source_id)||a.target_id.localeCompare(c.target_id)||a.type.localeCompare(c.type)),s=t.limit?n.slice(0,t.limit):n,o=new Map;for(let a of s)ee(o,i.get(a.source_id)),ee(o,i.get(a.target_id));return {nodes:[...o.values()].sort((a,c)=>a.id.localeCompare(c.id)),edges:s,complete:true}}function pt(e,t={}){let i=t.direction??"both";return {...t,...i==="out"?{sourceId:e}:{},...i==="in"?{targetId:e}:{},...i==="both"?{endpointId:e}:{}}}function ht(e,t,i={}){let r=i.direction??"both",n=t.edges.filter(o=>r==="out"?o.source_id===e:r==="in"?o.target_id===e:o.source_id===e||o.target_id===e),s=new Set;for(let o of n)s.add(o.source_id),s.add(o.target_id);return {...t,edges:n,nodes:t.nodes.filter(o=>s.has(o.id))}}async function me(e,t){let i=0,r=0,n=[];for(let s of e.manifest.parts){let o=await $(e,s);o.fetched&&(r+=1),i+=1,t?.({phase:"part",done:i,total:e.manifest.parts.length,href:s.href});for(let a of o.part.items)n.push(a.relationships?a:await le(e,a.id));}return {records:n,scannedParts:i,fetchedParts:r}}async function te(e,t={}){let i=await me(e);return {...H(i.records,t),scannedParts:i.scannedParts,fetchedParts:i.fetchedParts}}async function wt(e,t="",i={}){let r=t.trim().toLowerCase(),n=0,s=0;if(ct(t,i)){let g=i.offset??0,u=i.limit??e.manifest.total,f=dt(e.manifest,g,u),d=[];for(let m of f){let y=await $(e,m);y.fetched&&(s+=1),n+=1,i.onProgress?.({phase:"part",done:n,total:f.length,href:m.href});let b=Math.max(0,g-m.offset),A=Math.min(y.part.items.length,g+u-m.offset);d.push(...y.part.items.slice(b,A));}return {items:d,total:e.manifest.total,facets:e.manifest.facets??{},manifestTotal:e.manifest.total,scannedParts:n,fetchedParts:s,complete:true}}let o=ot(r,i),a=e.matchCache.get(o);if(a)return e.matchCache.delete(o),e.matchCache.set(o,a),{...T(a,r,i),manifestTotal:e.manifest.total,scannedParts:0,fetchedParts:0,complete:true};let c=[];for(let g of e.manifest.parts){let u=await $(e,g);u.fetched&&(s+=1),n+=1,i.onProgress?.({phase:"part",done:n,total:e.manifest.parts.length,href:g.href}),c.push(...B(u.part.items,r,i,g.offset)),i.onProgress?.({phase:"query",done:n,total:e.manifest.parts.length,href:g.href});}return at(e,o,c),{...T(c,r,i),manifestTotal:e.manifest.total,scannedParts:n,fetchedParts:s,complete:true}}function yt(e,t,i=new Date().toISOString()){return {schema_version:"aiwg.fortemi.review-decisions.v1",generated_at:i,source_export_schema_version:e.schema_version,decisions:[...t].sort((r,n)=>r.item_id.localeCompare(n.item_id))}}function It(e){let t=e??null,i=null,r=null,n=null,s=[],o=new Set,a=()=>({index:t,chunked:i?{manifest:i.manifest,cachedParts:i.partCache.size,maxCachedParts:i.maxCachedParts}:null,data:r,error:n,reviewDecisions:[...s]}),c=()=>{let u=a();for(let f of o)f(u);},g=()=>{if(!t)throw new Error("No AIWG index export loaded");return t};return {loadIndex(u){try{let f=q(u);return t=f,i=null,r=null,s=[],n=null,c(),f}catch(f){throw n=f instanceof Error?f:new Error(String(f)),c(),n}},loadChunkedIndex(u,f,d={}){try{let m=Fe(u);return t=null,i={manifest:m,loader:f,maxCachedParts:rt(d.maxCachedParts),partCache:new Map,detailLoader:d.detailLoader,maxCachedDetails:nt(d.maxCachedDetails),detailCache:new Map,maxCachedMatches:st(d.maxCachedMatches),matchCache:new Map},r=null,s=[],n=null,c(),m}catch(m){throw n=m instanceof Error?m:new Error(String(m)),c(),n}},getIndex(){return t},getChunkedManifest(){return i?.manifest??null},getSnapshot(){return a()},query(u="",f){let d=ge(g(),u,f);return r=d,n=null,c(),d},async queryChunked(u="",f){if(!i)throw new Error("No AIWG chunked index manifest loaded");try{let d=await wt(i,u,f);return r=d,n=null,c(),d}catch(d){throw n=d instanceof Error?d:new Error(String(d)),c(),n}},async getRecord(u){if(i)try{return await le(i,u)}catch(d){throw n=d instanceof Error?d:new Error(String(d)),c(),n}let f=g().items.find(d=>d.id===u);if(!f)throw new Error("Record not found: "+u);return f},async neighbors(u,f){try{let d=pt(u,f),m=i?await te(i,d):H(g().items,d);return ht(u,m,f)}catch(d){throw n=d instanceof Error?d:new Error(String(d)),c(),n}},async relationshipQuery(u){try{return i?await te(i,u):H(g().items,u)}catch(f){throw n=f instanceof Error?f:new Error(String(f)),c(),n}},async relationshipSet(u){let[f,d]=await Promise.all([this.neighbors(u.a,u),this.neighbors(u.b,u)]),m=new Set(f.nodes.map(A=>A.id).filter(A=>A!==u.a)),y=new Set(d.nodes.map(A=>A.id).filter(A=>A!==u.b)),b;return u.op==="intersection"?b=[...m].filter(A=>y.has(A)):u.op==="difference"?b=[...m].filter(A=>!y.has(A)):b=[...new Set([...m,...y])],{op:u.op,ids:b.sort()}},clearChunkCache(){i?.partCache.clear(),i?.detailCache.clear(),i?.matchCache.clear(),n=null,c();},toCommunityGraph(u){return z(g(),u)},async toCommunityGraphChunked(u){if(!i)return z(g(),u);let f=await me(i,u?.onProgress);return z({generated_at:i.manifest.generated_at,source:i.manifest.source,items:f.records},u)},setReviewDecision(u){let f={...u,updated_at:new Date().toISOString()};return s=[...s.filter(d=>d.item_id!==f.item_id),f].sort((d,m)=>d.item_id.localeCompare(m.item_id)),n=null,c(),f},clearReviewDecision(u){s=s.filter(f=>f.item_id!==u),n=null,c();},createReviewDecisionExport(u){let f=t??(i?{schema_version:i.manifest.source_export_schema_version??"aiwg.fortemi.index.export.v1"}:null);if(!f)throw new Error("No AIWG index export or chunked manifest loaded");return yt(f,s,u)},subscribe(u){return o.add(u),()=>{o.delete(u);}}}}function z(e,t={}){let i=new Set(e.items.map(o=>o.id)),r=t.relationshipWeights??Object.create(null),n=new Map;for(let o of e.items)for(let a of o.relationships){if(!i.has(a.target_id)&&!t.includeDanglingRelationships)continue;let c=a.type,g=Object.prototype.hasOwnProperty.call(r,c)?r[c]:void 0,u=typeof g=="number"&&Number.isFinite(g)?g:1,f=`${o.id}\0${a.target_id}\0${c}`,d=n.get(f);d?d.weight+=u:n.set(f,{source:o.id,target:a.target_id,kind:c,weight:u});}let s=new Map;for(let o of e.items){let a=xt(o,t);for(let c of a){let g=s.get(c)??[];g.push(o.id),s.set(c,g);}}return {nodes:e.items.map(o=>({id:o.id})),edges:Array.from(n.values()).sort((o,a)=>o.source.localeCompare(a.source)||o.target.localeCompare(a.target)||o.kind.localeCompare(a.kind)),communities:Array.from(s.entries()).map(([o,a])=>({id:o,nodes:[...new Set(a)].sort()})).sort((o,a)=>o.id.localeCompare(a.id))}}function xt(e,t){if(t.communityFacet){let i=e.facets[t.communityFacet]??[];if(i.length>0)return i.map(r=>`${t.communityFacet}:${r}`)}if(t.communityTagPrefix){let i=t.communityTagPrefix,r=e.tags.filter(n=>n.startsWith(i));if(r.length>0)return r}return e.concepts.length>0?e.concepts.map(i=>`concept:${i}`):[`type:${e.type}`]}export{we as AIWG_SCAN_REQUIRED_FIELDS,tt as DEFAULT_AIWG_DUPLICATE_SCAN_MAX_EMBEDDINGS,ce as aiwgDetailHrefForId,z as aiwgFortemiIndexToCommunityGraph,Fe as assertAiwgFortemiChunkManifest,Oe as assertAiwgFortemiChunkPart,q as assertAiwgFortemiIndexExport,Y as assertAiwgStaticEmbeddingSet,Rt as buildAiwgChunkedIndex,vt as buildAiwgStaticEmbeddingSet,At as createAiwgFetchChunkLoader,bt as createAiwgFetchDetailLoader,It as createAiwgIndexController,yt as createAiwgReviewDecisionExport,De as encodeAiwgDetailId,ie as filterAiwgRecordsByPrivacy,_t as findAiwgStaticDuplicatePairs,de as getAiwgFortemiFacets,ge as queryAiwgFortemiIndex,kt as queryAiwgHybridIndex,et as queryAiwgSemanticIndex,ae as resolveAiwgFetchUrl,Ce as validateAiwgFortemiChunkManifest,Ee as validateAiwgFortemiChunkPart,oe as validateAiwgFortemiIndexExport,Ze as validateAiwgStaticEmbeddingSet};//# sourceMappingURL=aiwg-index.js.map
|
|
15
|
+
`));return e}function et(e,t,i,r={}){if(Y(t),i.length!==t.dimensions)throw new Error("query embedding length must match embedding set dimensions");let n=new Map(e.items.map(o=>[o.id,o])),s=r.offset??0,a=r.limit??20;return t.embeddings.map(o=>{let c=n.get(o.record_id);return c?{item:c,embedding:o,score:fe(i,o.embedding)}:null}).filter(o=>o!==null&&o.score>=(r.minScore??-1)).sort((o,c)=>c.score-o.score||o.item.id.localeCompare(c.item.id)).slice(s,s+a)}function Rt(e,t,i,r,n={}){let s={...n};delete s.limit,delete s.offset;let a=ge(e,i,{...s,rank:true}),o=et(e,t,r,{limit:e.items.length}),c=n.lexicalWeight??.5,g=n.semanticWeight??.5,d=new Map(a.rankedItems?.map(b=>[b.item.id,b.rank])??[]),f=Math.max(1,...d.values()),u=new Map(o.flatMap(b=>b.embedding?[[b.item.id,b.embedding]]:[])),p=new Map(o.map(b=>[b.item.id,b.score])),y=new Set([...d.keys(),...p.keys()]),x=n.offset??0,A=n.limit??20;return [...y].map(b=>{let v=e.items.find(R=>R.id===b),_=u.get(b);return v?{item:v,..._?{embedding:_}:{},score:(d.get(b)??0)/f*c+(p.get(b)??0)*g}:null}).filter(b=>b!==null&&b.score>=(n.minScore??-1)).sort((b,v)=>v.score-b.score||b.item.id.localeCompare(v.item.id)).slice(x,x+A)}var tt=5e3;function kt(e,t,i=.9,r){Y(t);let n=r?.maxEmbeddings??tt;if(t.embeddings.length>n)throw new Error("Embedding set too large for duplicate scan: "+t.embeddings.length+" > "+n+" (raise options.maxEmbeddings to override for trusted input)");let s=new Map(e.items.map(o=>[o.id,o])),a=[];for(let o=0;o<t.embeddings.length;o+=1)for(let c=o+1;c<t.embeddings.length;c+=1){let g=t.embeddings[o],d=t.embeddings[c],f=s.get(g.record_id),u=s.get(d.record_id);if(!f||!u)continue;let p=fe(g.embedding,d.embedding);p>=i&&a.push({left:f,right:u,score:p});}return a.sort((o,c)=>c.score-o.score||o.left.id.localeCompare(c.left.id))}function it(e){return `${e.offset}:${e.href}`}function rt(e){return S(e)?e:3}function nt(e){return S(e)?e:32}function st(e){return S(e)?e:5e3}function at(e,t){return JSON.stringify({q:e,types:t.types??null,facets:t.facets??null,tags:t.tags??null,concepts:t.concepts??null,privacy:t.privacy??null,rel:t.relationshipTargetId??null,searchProfile:t.searchProfile??"default",weights:{...K,...t.weights}})}function ot(e,t,i){e.matchCache.delete(t),e.matchCache.set(t,i);let r=0;for(let n of e.matchCache.values())r+=n.length;for(;r>e.maxCachedMatches&&e.matchCache.size>1;){let n=e.matchCache.keys().next().value;if(n===void 0||n===t)break;r-=e.matchCache.get(n)?.length??0,e.matchCache.delete(n);}}function ct(e,t){return e.trim()===""&&!t.rank&&!t.snippets&&!t.includeMatches&&!t.types&&!t.facets&&!t.tags&&!t.concepts&&!t.privacy&&!t.relationshipTargetId}function dt(e,t,i){let r=t+i;return e.parts.filter(n=>n.count>0&&n.offset<r&&n.offset+n.count>t)}async function $(e,t){let i=it(t),r=e.partCache.get(i);if(r)return e.partCache.delete(i),e.partCache.set(i,r),{part:r,fetched:false};let n=Oe(await e.loader(t,e.manifest),t,e.manifest);for(e.partCache.set(i,n);e.partCache.size>e.maxCachedParts;){let s=e.partCache.keys().next().value;if(s===void 0)break;e.partCache.delete(s);}return {part:n,fetched:true}}async function le(e,t){let i=e.detailCache.get(t);if(i)return e.detailCache.delete(t),e.detailCache.set(t,i),i;if(!e.manifest.projection)for(let s of e.partCache.values()){let a=s.items.find(o=>o.id===t);if(a)return a}if(!e.detailLoader)throw new Error("No detailLoader configured to resolve record "+t);let r=await e.detailLoader(t,e.manifest),n=q({schema_version:"aiwg.fortemi.index.export.v1",generated_at:e.manifest.generated_at,source:e.manifest.source,items:[r]}).items[0];if(n.id!==t)throw new Error("Detail record id mismatch: expected "+t+", got "+n.id);for(e.detailCache.set(t,n);e.detailCache.size>e.maxCachedDetails;){let s=e.detailCache.keys().next().value;if(s===void 0)break;e.detailCache.delete(s);}return n}function ut(e){return e?.relationshipType??e?.type}function gt(e,t){return {source_id:e,target_id:t.target_id,type:t.type,...t.source_path?{source_path:t.source_path}:{},...t.target_path?{target_path:t.target_path}:{},...t.direction?{direction:t.direction}:{}}}function ft(e,t={}){let i=ut(t);return !(i&&e.type!==i||t.relationshipDirection&&e.direction!==t.relationshipDirection||t.sourceId&&e.source_id!==t.sourceId||t.targetId&&e.target_id!==t.targetId||t.endpointId&&e.source_id!==t.endpointId&&e.target_id!==t.endpointId)}function lt(e){if(e.direction==="out"&&!e.sourceId)throw new Error("relationship direction 'out' requires sourceId");if(e.direction==="in"&&!e.targetId)throw new Error("relationship direction 'in' requires targetId")}function pt(e){return {id:e.id,type:e.type,title:E(e)}}function ee(e,t){t&&e.set(t.id,pt(t));}function H(e,t={}){lt(t);let i=new Map(e.map(o=>[o.id,o])),r=[];for(let o of e)for(let c of o.relationships??[]){let g=gt(o.id,c);ft(g,t)&&r.push(g);}let n=r.sort((o,c)=>o.source_id.localeCompare(c.source_id)||o.target_id.localeCompare(c.target_id)||o.type.localeCompare(c.type)),s=t.limit?n.slice(0,t.limit):n,a=new Map;for(let o of s)ee(a,i.get(o.source_id)),ee(a,i.get(o.target_id));return {nodes:[...a.values()].sort((o,c)=>o.id.localeCompare(c.id)),edges:s,complete:true}}function mt(e,t={}){let i=t.direction??"both";return {...t,...i==="out"?{sourceId:e}:{},...i==="in"?{targetId:e}:{},...i==="both"?{endpointId:e}:{}}}function ht(e,t,i={}){let r=i.direction??"both",n=t.edges.filter(a=>r==="out"?a.source_id===e:r==="in"?a.target_id===e:a.source_id===e||a.target_id===e),s=new Set;for(let a of n)s.add(a.source_id),s.add(a.target_id);return {...t,edges:n,nodes:t.nodes.filter(a=>s.has(a.id))}}async function pe(e,t){let i=0,r=0,n=[];for(let s of e.manifest.parts){let a=await $(e,s);a.fetched&&(r+=1),i+=1,t?.({phase:"part",done:i,total:e.manifest.parts.length,href:s.href});for(let o of a.part.items)n.push(o.relationships?o:await le(e,o.id));}return {records:n,scannedParts:i,fetchedParts:r}}async function te(e,t={}){let i=await pe(e);return {...H(i.records,t),scannedParts:i.scannedParts,fetchedParts:i.fetchedParts}}async function wt(e,t="",i={}){let r=t.trim().toLowerCase(),n=0,s=0;if(ct(t,i)){let g=i.offset??0,d=i.limit??e.manifest.total,f=dt(e.manifest,g,d),u=[];for(let p of f){let y=await $(e,p);y.fetched&&(s+=1),n+=1,i.onProgress?.({phase:"part",done:n,total:f.length,href:p.href});let x=Math.max(0,g-p.offset),A=Math.min(y.part.items.length,g+d-p.offset);u.push(...y.part.items.slice(x,A));}return {items:u,total:e.manifest.total,facets:e.manifest.facets??{},manifestTotal:e.manifest.total,scannedParts:n,fetchedParts:s,complete:true}}let a=at(r,i),o=e.matchCache.get(a);if(o)return e.matchCache.delete(a),e.matchCache.set(a,o),{...T(o,r,i),manifestTotal:e.manifest.total,scannedParts:0,fetchedParts:0,complete:true};let c=[];for(let g of e.manifest.parts){let d=await $(e,g);d.fetched&&(s+=1),n+=1,i.onProgress?.({phase:"part",done:n,total:e.manifest.parts.length,href:g.href}),c.push(...B(d.part.items,r,i,g.offset)),i.onProgress?.({phase:"query",done:n,total:e.manifest.parts.length,href:g.href});}return ot(e,a,c),{...T(c,r,i),manifestTotal:e.manifest.total,scannedParts:n,fetchedParts:s,complete:true}}function yt(e,t,i=new Date().toISOString()){return {schema_version:"aiwg.fortemi.review-decisions.v1",generated_at:i,source_export_schema_version:e.schema_version,decisions:[...t].sort((r,n)=>r.item_id.localeCompare(n.item_id))}}function It(e){let t=e??null,i=null,r=null,n=null,s=[],a=new Set,o=()=>({index:t,chunked:i?{manifest:i.manifest,cachedParts:i.partCache.size,maxCachedParts:i.maxCachedParts}:null,data:r,error:n,reviewDecisions:[...s]}),c=()=>{let d=o();for(let f of a)f(d);},g=()=>{if(!t)throw new Error("No AIWG index export loaded");return t};return {loadIndex(d){try{let f=q(d);return t=f,i=null,r=null,s=[],n=null,c(),f}catch(f){throw n=f instanceof Error?f:new Error(String(f)),c(),n}},loadChunkedIndex(d,f,u={}){try{let p=Fe(d);return t=null,i={manifest:p,loader:f,maxCachedParts:rt(u.maxCachedParts),partCache:new Map,detailLoader:u.detailLoader,maxCachedDetails:nt(u.maxCachedDetails),detailCache:new Map,maxCachedMatches:st(u.maxCachedMatches),matchCache:new Map},r=null,s=[],n=null,c(),p}catch(p){throw n=p instanceof Error?p:new Error(String(p)),c(),n}},getIndex(){return t},getChunkedManifest(){return i?.manifest??null},getSnapshot(){return o()},query(d="",f){let u=ge(g(),d,f);return r=u,n=null,c(),u},async queryChunked(d="",f){if(!i)throw new Error("No AIWG chunked index manifest loaded");try{let u=await wt(i,d,f);return r=u,n=null,c(),u}catch(u){throw n=u instanceof Error?u:new Error(String(u)),c(),n}},async getRecord(d){if(i)try{return await le(i,d)}catch(u){throw n=u instanceof Error?u:new Error(String(u)),c(),n}let f=g().items.find(u=>u.id===d);if(!f)throw new Error("Record not found: "+d);return f},async neighbors(d,f){try{let u=mt(d,f),p=i?await te(i,u):H(g().items,u);return ht(d,p,f)}catch(u){throw n=u instanceof Error?u:new Error(String(u)),c(),n}},async relationshipQuery(d){try{return i?await te(i,d):H(g().items,d)}catch(f){throw n=f instanceof Error?f:new Error(String(f)),c(),n}},async relationshipSet(d){let[f,u]=await Promise.all([this.neighbors(d.a,d),this.neighbors(d.b,d)]),p=new Set(f.nodes.map(A=>A.id).filter(A=>A!==d.a)),y=new Set(u.nodes.map(A=>A.id).filter(A=>A!==d.b)),x;return d.op==="intersection"?x=[...p].filter(A=>y.has(A)):d.op==="difference"?x=[...p].filter(A=>!y.has(A)):x=[...new Set([...p,...y])],{op:d.op,ids:x.sort()}},clearChunkCache(){i?.partCache.clear(),i?.detailCache.clear(),i?.matchCache.clear(),n=null,c();},toCommunityGraph(d){return z(g(),d)},async toCommunityGraphChunked(d){if(!i)return z(g(),d);let f=await pe(i,d?.onProgress);return z({generated_at:i.manifest.generated_at,source:i.manifest.source,items:f.records},d)},setReviewDecision(d){let f={...d,updated_at:new Date().toISOString()};return s=[...s.filter(u=>u.item_id!==f.item_id),f].sort((u,p)=>u.item_id.localeCompare(p.item_id)),n=null,c(),f},clearReviewDecision(d){s=s.filter(f=>f.item_id!==d),n=null,c();},createReviewDecisionExport(d){let f=t??(i?{schema_version:i.manifest.source_export_schema_version??"aiwg.fortemi.index.export.v1"}:null);if(!f)throw new Error("No AIWG index export or chunked manifest loaded");return yt(f,s,d)},subscribe(d){return a.add(d),()=>{a.delete(d);}}}}function z(e,t={}){let i=new Set(e.items.map(a=>a.id)),r=t.relationshipWeights??Object.create(null),n=new Map;for(let a of e.items)for(let o of a.relationships){if(!i.has(o.target_id)&&!t.includeDanglingRelationships)continue;let c=o.type,g=Object.prototype.hasOwnProperty.call(r,c)?r[c]:void 0,d=typeof g=="number"&&Number.isFinite(g)?g:1,f=`${a.id}\0${o.target_id}\0${c}`,u=n.get(f);u?u.weight+=d:n.set(f,{source:a.id,target:o.target_id,kind:c,weight:d});}let s=new Map;for(let a of e.items){let o=bt(a,t);for(let c of o){let g=s.get(c)??[];g.push(a.id),s.set(c,g);}}return {nodes:e.items.map(a=>({id:a.id})),edges:Array.from(n.values()).sort((a,o)=>a.source.localeCompare(o.source)||a.target.localeCompare(o.target)||a.kind.localeCompare(o.kind)),communities:Array.from(s.entries()).map(([a,o])=>({id:a,nodes:[...new Set(o)].sort()})).sort((a,o)=>a.id.localeCompare(o.id))}}function bt(e,t){if(t.communityFacet){let i=e.facets[t.communityFacet]??[];if(i.length>0)return i.map(r=>`${t.communityFacet}:${r}`)}if(t.communityTagPrefix){let i=t.communityTagPrefix,r=e.tags.filter(n=>n.startsWith(i));if(r.length>0)return r}return e.concepts.length>0?e.concepts.map(i=>`concept:${i}`):[`type:${e.type}`]}export{we as AIWG_SCAN_REQUIRED_FIELDS,tt as DEFAULT_AIWG_DUPLICATE_SCAN_MAX_EMBEDDINGS,ce as aiwgDetailHrefForId,z as aiwgFortemiIndexToCommunityGraph,Fe as assertAiwgFortemiChunkManifest,Oe as assertAiwgFortemiChunkPart,q as assertAiwgFortemiIndexExport,Y as assertAiwgStaticEmbeddingSet,_t as buildAiwgChunkedIndex,vt as buildAiwgStaticEmbeddingSet,At as createAiwgFetchChunkLoader,xt as createAiwgFetchDetailLoader,It as createAiwgIndexController,yt as createAiwgReviewDecisionExport,je as encodeAiwgDetailId,ie as filterAiwgRecordsByPrivacy,kt as findAiwgStaticDuplicatePairs,de as getAiwgFortemiFacets,ge as queryAiwgFortemiIndex,Rt as queryAiwgHybridIndex,et as queryAiwgSemanticIndex,oe as resolveAiwgFetchUrl,Ce as validateAiwgFortemiChunkManifest,Ee as validateAiwgFortemiChunkPart,ae as validateAiwgFortemiIndexExport,Ze as validateAiwgStaticEmbeddingSet};//# sourceMappingURL=aiwg-index.js.map
|
|
16
16
|
//# sourceMappingURL=aiwg-index.js.map
|