@fortemi/core 2026.7.4 → 2026.7.5

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.
@@ -0,0 +1,724 @@
1
+ import Ajv2020 from 'ajv/dist/2020.js';
2
+
3
+ // src/aiwg-index-schema.ts
4
+
5
+ // schemas/aiwg-fortemi-index-export.schema.json
6
+ var aiwg_fortemi_index_export_schema_default = {
7
+ $schema: "https://json-schema.org/draft/2020-12/schema",
8
+ $id: "https://aiwg.io/schemas/aiwg-fortemi-index-export.json",
9
+ title: "AIWG Fortemi Index Export",
10
+ type: "object",
11
+ additionalProperties: false,
12
+ required: ["schema_version", "generated_at", "source", "items"],
13
+ properties: {
14
+ schema_version: {
15
+ enum: ["aiwg.fortemi.index.export.v1", "aiwg.fortemi.index.export.v2"]
16
+ },
17
+ generated_at: {
18
+ type: "string",
19
+ format: "date-time"
20
+ },
21
+ source: {
22
+ type: "object",
23
+ additionalProperties: false,
24
+ required: ["repo", "privacy"],
25
+ properties: {
26
+ repo: {
27
+ type: "string",
28
+ minLength: 1
29
+ },
30
+ privacy: {
31
+ $ref: "#/$defs/privacy"
32
+ },
33
+ graph: {
34
+ type: "string",
35
+ minLength: 1
36
+ }
37
+ }
38
+ },
39
+ compatibility: {
40
+ type: "object",
41
+ additionalProperties: false,
42
+ required: ["previous_schema_version", "strategy"],
43
+ properties: {
44
+ previous_schema_version: {
45
+ const: "aiwg.fortemi.index.export.v1"
46
+ },
47
+ strategy: {
48
+ const: "supported"
49
+ }
50
+ }
51
+ },
52
+ items: {
53
+ type: "array",
54
+ items: {
55
+ $ref: "#/$defs/record"
56
+ }
57
+ }
58
+ },
59
+ allOf: [
60
+ {
61
+ if: {
62
+ properties: {
63
+ schema_version: {
64
+ const: "aiwg.fortemi.index.export.v1"
65
+ }
66
+ }
67
+ },
68
+ then: {
69
+ not: {
70
+ required: ["compatibility"]
71
+ },
72
+ properties: {
73
+ source: {
74
+ not: {
75
+ required: ["graph"]
76
+ }
77
+ },
78
+ items: {
79
+ items: {
80
+ allOf: [
81
+ {
82
+ properties: {
83
+ schema_version: {
84
+ const: "aiwg.fortemi.index.record.v1"
85
+ }
86
+ }
87
+ },
88
+ {
89
+ $ref: "#/$defs/v1RecordCompatibility"
90
+ }
91
+ ]
92
+ }
93
+ }
94
+ }
95
+ }
96
+ },
97
+ {
98
+ if: {
99
+ properties: {
100
+ schema_version: {
101
+ const: "aiwg.fortemi.index.export.v2"
102
+ }
103
+ }
104
+ },
105
+ then: {
106
+ required: ["compatibility"],
107
+ properties: {
108
+ source: {
109
+ required: ["graph"]
110
+ },
111
+ items: {
112
+ items: {
113
+ properties: {
114
+ schema_version: {
115
+ const: "aiwg.fortemi.index.record.v2"
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ ],
124
+ $defs: {
125
+ privacy: {
126
+ enum: ["private", "sanitized", "public"]
127
+ },
128
+ recordType: {
129
+ type: "string",
130
+ minLength: 1
131
+ },
132
+ stringArray: {
133
+ type: "array",
134
+ items: {
135
+ type: "string"
136
+ }
137
+ },
138
+ numberArray: {
139
+ type: "array",
140
+ items: {
141
+ type: "number"
142
+ }
143
+ },
144
+ v1RecordCompatibility: {
145
+ type: "object",
146
+ not: {
147
+ anyOf: [
148
+ {
149
+ required: ["name"]
150
+ },
151
+ {
152
+ required: ["summary"]
153
+ },
154
+ {
155
+ required: ["search"]
156
+ },
157
+ {
158
+ required: ["chunks"]
159
+ },
160
+ {
161
+ required: ["embeddings"]
162
+ },
163
+ {
164
+ required: ["compatibility"]
165
+ },
166
+ {
167
+ required: ["skos_concepts"]
168
+ },
169
+ {
170
+ required: ["skos_relations"]
171
+ },
172
+ {
173
+ required: ["provenance_events"]
174
+ }
175
+ ]
176
+ },
177
+ properties: {
178
+ source: {
179
+ not: {
180
+ anyOf: [
181
+ {
182
+ required: ["origin"]
183
+ },
184
+ {
185
+ required: ["generated"]
186
+ },
187
+ {
188
+ required: ["checksum"]
189
+ },
190
+ {
191
+ required: ["updated_at"]
192
+ }
193
+ ]
194
+ }
195
+ },
196
+ relationships: {
197
+ items: {
198
+ not: {
199
+ anyOf: [
200
+ {
201
+ required: ["target_path"]
202
+ },
203
+ {
204
+ required: ["direction"]
205
+ },
206
+ {
207
+ required: ["label"]
208
+ },
209
+ {
210
+ required: ["confidence"]
211
+ },
212
+ {
213
+ required: ["privacy"]
214
+ },
215
+ {
216
+ required: ["metadata"]
217
+ }
218
+ ]
219
+ }
220
+ }
221
+ },
222
+ privacy: {
223
+ not: {
224
+ required: ["locality"]
225
+ }
226
+ }
227
+ }
228
+ },
229
+ record: {
230
+ type: "object",
231
+ additionalProperties: false,
232
+ required: [
233
+ "schema_version",
234
+ "id",
235
+ "type",
236
+ "source",
237
+ "title",
238
+ "text",
239
+ "facets",
240
+ "tags",
241
+ "concepts",
242
+ "relationships",
243
+ "provenance",
244
+ "privacy",
245
+ "updated_at"
246
+ ],
247
+ properties: {
248
+ schema_version: {
249
+ enum: [
250
+ "aiwg.fortemi.index.record.v1",
251
+ "aiwg.fortemi.index.record.v2"
252
+ ]
253
+ },
254
+ id: {
255
+ type: "string",
256
+ minLength: 1
257
+ },
258
+ type: {
259
+ $ref: "#/$defs/recordType"
260
+ },
261
+ source: {
262
+ type: "object",
263
+ additionalProperties: false,
264
+ required: ["path", "repo_relative_path", "locator"],
265
+ properties: {
266
+ path: {
267
+ type: "string",
268
+ minLength: 1
269
+ },
270
+ repo_relative_path: {
271
+ type: "string",
272
+ minLength: 1
273
+ },
274
+ locator: {
275
+ type: "string",
276
+ minLength: 1
277
+ },
278
+ origin: {
279
+ type: "string",
280
+ minLength: 1
281
+ },
282
+ generated: {
283
+ type: "boolean"
284
+ },
285
+ checksum: {
286
+ type: "string"
287
+ },
288
+ updated_at: {
289
+ type: "string",
290
+ format: "date-time"
291
+ }
292
+ }
293
+ },
294
+ title: {
295
+ type: "string"
296
+ },
297
+ name: {
298
+ type: "string"
299
+ },
300
+ summary: {
301
+ type: "string"
302
+ },
303
+ text: {
304
+ type: "string"
305
+ },
306
+ search: {
307
+ type: "object",
308
+ additionalProperties: false,
309
+ required: [
310
+ "title",
311
+ "body",
312
+ "triggers",
313
+ "aliases",
314
+ "tags",
315
+ "frontmatter"
316
+ ],
317
+ properties: {
318
+ title: {
319
+ type: "string"
320
+ },
321
+ name: {
322
+ type: "string"
323
+ },
324
+ summary: {
325
+ type: "string"
326
+ },
327
+ body: {
328
+ type: "string"
329
+ },
330
+ triggers: {
331
+ $ref: "#/$defs/stringArray"
332
+ },
333
+ aliases: {
334
+ $ref: "#/$defs/stringArray"
335
+ },
336
+ capability: {
337
+ type: "string"
338
+ },
339
+ tags: {
340
+ $ref: "#/$defs/stringArray"
341
+ },
342
+ phase: {
343
+ type: "string"
344
+ },
345
+ type: {
346
+ type: "string"
347
+ },
348
+ frontmatter: {
349
+ type: "object"
350
+ }
351
+ }
352
+ },
353
+ facets: {
354
+ type: "object",
355
+ additionalProperties: {
356
+ $ref: "#/$defs/stringArray"
357
+ }
358
+ },
359
+ tags: {
360
+ $ref: "#/$defs/stringArray"
361
+ },
362
+ concepts: {
363
+ $ref: "#/$defs/stringArray"
364
+ },
365
+ relationships: {
366
+ type: "array",
367
+ items: {
368
+ type: "object",
369
+ additionalProperties: false,
370
+ required: ["type", "target_id"],
371
+ properties: {
372
+ type: {
373
+ type: "string",
374
+ minLength: 1
375
+ },
376
+ target_id: {
377
+ type: "string",
378
+ minLength: 1
379
+ },
380
+ source_path: {
381
+ type: "string"
382
+ },
383
+ target_path: {
384
+ type: "string"
385
+ },
386
+ direction: {
387
+ enum: ["upstream", "downstream", "related"]
388
+ },
389
+ label: {
390
+ type: "string"
391
+ },
392
+ confidence: {
393
+ type: "number"
394
+ },
395
+ privacy: {
396
+ $ref: "#/$defs/privacy"
397
+ },
398
+ metadata: {
399
+ type: "object"
400
+ }
401
+ }
402
+ }
403
+ },
404
+ provenance: {
405
+ type: "array",
406
+ minItems: 1,
407
+ items: {
408
+ type: "object",
409
+ additionalProperties: false,
410
+ required: ["field", "source", "path", "confidence", "privacy"],
411
+ properties: {
412
+ field: {
413
+ type: "string",
414
+ minLength: 1
415
+ },
416
+ source: {
417
+ type: "string",
418
+ minLength: 1
419
+ },
420
+ path: {
421
+ type: "string",
422
+ minLength: 1
423
+ },
424
+ confidence: {
425
+ enum: ["source", "candidate", "reviewed", "rejected"]
426
+ },
427
+ privacy: {
428
+ $ref: "#/$defs/privacy"
429
+ }
430
+ }
431
+ }
432
+ },
433
+ privacy: {
434
+ type: "object",
435
+ additionalProperties: false,
436
+ required: ["classification", "pii"],
437
+ properties: {
438
+ classification: {
439
+ $ref: "#/$defs/privacy"
440
+ },
441
+ pii: {
442
+ type: "boolean"
443
+ },
444
+ locality: {
445
+ enum: ["project", "framework", "external"]
446
+ }
447
+ }
448
+ },
449
+ chunks: {
450
+ type: "array",
451
+ items: {
452
+ type: "object",
453
+ additionalProperties: false,
454
+ properties: {
455
+ id: {
456
+ type: "string",
457
+ minLength: 1
458
+ },
459
+ text: {
460
+ type: "string"
461
+ },
462
+ body: {
463
+ type: "string"
464
+ },
465
+ summary: {
466
+ type: "string"
467
+ },
468
+ source_path: {
469
+ type: "string"
470
+ },
471
+ metadata: {
472
+ type: "object"
473
+ },
474
+ checksum: {
475
+ type: "string"
476
+ }
477
+ }
478
+ }
479
+ },
480
+ embeddings: {
481
+ type: "array",
482
+ items: {
483
+ type: "object",
484
+ additionalProperties: false,
485
+ properties: {
486
+ id: {
487
+ type: "string"
488
+ },
489
+ model: {
490
+ type: "string"
491
+ },
492
+ embedding: {
493
+ $ref: "#/$defs/numberArray"
494
+ },
495
+ vector: {
496
+ $ref: "#/$defs/numberArray"
497
+ },
498
+ granularity: {
499
+ type: "string"
500
+ },
501
+ source_path: {
502
+ type: "string"
503
+ },
504
+ metadata: {
505
+ type: "object"
506
+ },
507
+ chunk_id: {
508
+ type: "string"
509
+ },
510
+ vector_ref: {
511
+ type: "string"
512
+ },
513
+ input_hash: {
514
+ type: "string"
515
+ }
516
+ }
517
+ }
518
+ },
519
+ compatibility: {
520
+ type: "object"
521
+ },
522
+ skos_concepts: {
523
+ type: "array",
524
+ items: {
525
+ type: "object",
526
+ additionalProperties: false,
527
+ required: ["id", "prefLabel"],
528
+ properties: {
529
+ id: {
530
+ type: "string",
531
+ minLength: 1
532
+ },
533
+ prefLabel: {
534
+ type: "string",
535
+ minLength: 1
536
+ },
537
+ definition: {
538
+ type: "string"
539
+ },
540
+ scheme: {
541
+ type: "string"
542
+ },
543
+ notation: {
544
+ type: "string"
545
+ },
546
+ uri: {
547
+ type: "string"
548
+ },
549
+ altLabels: {
550
+ $ref: "#/$defs/stringArray"
551
+ },
552
+ metadata: {
553
+ type: "object"
554
+ }
555
+ }
556
+ }
557
+ },
558
+ skos_relations: {
559
+ type: "array",
560
+ items: {
561
+ type: "object",
562
+ additionalProperties: false,
563
+ required: ["type", "source_id", "target_id"],
564
+ properties: {
565
+ type: {
566
+ type: "string",
567
+ minLength: 1
568
+ },
569
+ source_id: {
570
+ type: "string",
571
+ minLength: 1
572
+ },
573
+ target_id: {
574
+ type: "string",
575
+ minLength: 1
576
+ },
577
+ source_path: {
578
+ type: "string"
579
+ },
580
+ metadata: {
581
+ type: "object"
582
+ }
583
+ }
584
+ }
585
+ },
586
+ provenance_events: {
587
+ type: "array",
588
+ items: {
589
+ type: "object",
590
+ additionalProperties: false,
591
+ required: ["activity"],
592
+ properties: {
593
+ id: {
594
+ type: "string"
595
+ },
596
+ activity: {
597
+ type: "string",
598
+ minLength: 1
599
+ },
600
+ agent: {
601
+ type: "string"
602
+ },
603
+ started_at: {
604
+ type: "string",
605
+ format: "date-time"
606
+ },
607
+ ended_at: {
608
+ type: "string",
609
+ format: "date-time"
610
+ },
611
+ source: {
612
+ type: "string"
613
+ },
614
+ path: {
615
+ type: "string"
616
+ },
617
+ confidence: {
618
+ enum: ["source", "candidate", "reviewed", "rejected"]
619
+ },
620
+ privacy: {
621
+ $ref: "#/$defs/privacy"
622
+ },
623
+ attributes: {
624
+ type: "object"
625
+ }
626
+ }
627
+ }
628
+ },
629
+ updated_at: {
630
+ type: "string",
631
+ format: "date-time"
632
+ }
633
+ }
634
+ }
635
+ }
636
+ };
637
+
638
+ // src/aiwg-index-schema.ts
639
+ var PROJECTED_FIELDS = [
640
+ "schema_version",
641
+ "id",
642
+ "type",
643
+ "title",
644
+ "text",
645
+ "facets",
646
+ "tags",
647
+ "concepts",
648
+ "privacy"
649
+ ];
650
+ var ajvInstance;
651
+ var exportValidator;
652
+ var projectedRecordValidator;
653
+ function getAiwgFortemiIndexExportSchema() {
654
+ return aiwg_fortemi_index_export_schema_default;
655
+ }
656
+ function getAjv() {
657
+ if (!ajvInstance) {
658
+ ajvInstance = new Ajv2020({
659
+ allErrors: true,
660
+ strict: false,
661
+ validateFormats: false
662
+ });
663
+ ajvInstance.addSchema(aiwg_fortemi_index_export_schema_default);
664
+ }
665
+ return ajvInstance;
666
+ }
667
+ function formatErrors(errors) {
668
+ return (errors ?? []).map((error) => {
669
+ const path = error.instancePath || "(root)";
670
+ return `${path} ${error.message ?? "is invalid"}`;
671
+ });
672
+ }
673
+ function getExportValidator() {
674
+ exportValidator ??= getAjv().getSchema(aiwg_fortemi_index_export_schema_default.$id) ?? getAjv().compile(aiwg_fortemi_index_export_schema_default);
675
+ return exportValidator;
676
+ }
677
+ function getProjectedRecordValidator() {
678
+ if (!projectedRecordValidator) {
679
+ const properties = Object.fromEntries(Object.keys(aiwg_fortemi_index_export_schema_default.$defs.record.properties).map((field) => [
680
+ field,
681
+ { $ref: `${aiwg_fortemi_index_export_schema_default.$id}#/$defs/record/properties/${field}` }
682
+ ]));
683
+ projectedRecordValidator = getAjv().compile({
684
+ type: "object",
685
+ required: PROJECTED_FIELDS,
686
+ properties,
687
+ additionalProperties: true,
688
+ allOf: [
689
+ {
690
+ if: {
691
+ properties: {
692
+ schema_version: { const: "aiwg.fortemi.index.record.v1" }
693
+ }
694
+ },
695
+ then: { $ref: `${aiwg_fortemi_index_export_schema_default.$id}#/$defs/v1RecordCompatibility` }
696
+ }
697
+ ]
698
+ });
699
+ }
700
+ return projectedRecordValidator;
701
+ }
702
+ function validateAiwgFortemiIndexExportSchema(value) {
703
+ const validate = getExportValidator();
704
+ const schemaValue = value && typeof value === "object" && Array.isArray(value.items) ? {
705
+ ...value,
706
+ items: value.items.map((item) => {
707
+ if (!item || typeof item !== "object" || Array.isArray(item)) return item;
708
+ const schemaRecord = { ...item };
709
+ Reflect.deleteProperty(schemaRecord, "binary_sources");
710
+ return schemaRecord;
711
+ })
712
+ } : value;
713
+ const valid = validate(schemaValue);
714
+ return { valid, errors: formatErrors(validate.errors) };
715
+ }
716
+ function validateAiwgFortemiProjectedRecordSchema(value) {
717
+ const validate = getProjectedRecordValidator();
718
+ const valid = validate(value);
719
+ return { valid, errors: formatErrors(validate.errors) };
720
+ }
721
+
722
+ export { getAiwgFortemiIndexExportSchema, validateAiwgFortemiIndexExportSchema, validateAiwgFortemiProjectedRecordSchema };
723
+ //# sourceMappingURL=aiwg-index-schema.js.map
724
+ //# sourceMappingURL=aiwg-index-schema.js.map