@fortemi/core 2026.5.4 → 2026.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -52,6 +52,13 @@ interface EventMap {
52
52
  name: string;
53
53
  progress?: number;
54
54
  };
55
+ 'capability.required': {
56
+ name: string;
57
+ jobId: string;
58
+ noteId: string;
59
+ type: string;
60
+ message: string;
61
+ };
55
62
  'job.completed': {
56
63
  id: string;
57
64
  noteId: string;
@@ -63,6 +70,13 @@ interface EventMap {
63
70
  type: string;
64
71
  error: string;
65
72
  };
73
+ 'job.blocked': {
74
+ id: string;
75
+ noteId: string;
76
+ type: string;
77
+ capability: string;
78
+ message: string;
79
+ };
66
80
  'archive.switched': {
67
81
  name: string;
68
82
  };
@@ -1177,6 +1191,7 @@ declare class JobQueueWorker {
1177
1191
  processOnce(): Promise<number>;
1178
1192
  private poll;
1179
1193
  private processPendingJobs;
1194
+ private blockForCapability;
1180
1195
  getBackoffDelay(retryCount: number): number;
1181
1196
  }
1182
1197
  /** Title generation: LLM first, fallback to first-line extraction */
@@ -2808,6 +2823,92 @@ declare function exportShard(db: DatabaseClient, options?: ExportOptions): Promi
2808
2823
  */
2809
2824
  declare function importShard(db: DatabaseClient, data: Uint8Array | ArrayBuffer, options?: ImportOptions): Promise<ImportResult>;
2810
2825
 
2811
- declare const VERSION = "2026.5.4";
2826
+ type AiwgFortemiRecordType = 'crm.contact' | 'crm.organization' | 'crm.event' | 'crm.interaction' | 'aiwg.artifact';
2827
+ type AiwgPrivacyClassification = 'private' | 'sanitized' | 'public';
2828
+ type AiwgProvenanceConfidence = 'source' | 'candidate' | 'reviewed' | 'rejected';
2829
+ type AiwgReviewAction = 'accept' | 'reject' | 'defer';
2830
+ interface AiwgFortemiRecordSource {
2831
+ path: string;
2832
+ repo_relative_path: string;
2833
+ locator: string;
2834
+ }
2835
+ interface AiwgFortemiRelationship {
2836
+ type: string;
2837
+ target_id: string;
2838
+ source_path?: string;
2839
+ }
2840
+ interface AiwgFortemiProvenance {
2841
+ field: string;
2842
+ source: string;
2843
+ path: string;
2844
+ confidence: AiwgProvenanceConfidence;
2845
+ privacy: AiwgPrivacyClassification;
2846
+ }
2847
+ interface AiwgFortemiRecord {
2848
+ schema_version: 'aiwg.fortemi.index.record.v1';
2849
+ id: string;
2850
+ type: AiwgFortemiRecordType;
2851
+ source: AiwgFortemiRecordSource;
2852
+ title: string;
2853
+ text: string;
2854
+ facets: Record<string, string[]>;
2855
+ tags: string[];
2856
+ concepts: string[];
2857
+ relationships: AiwgFortemiRelationship[];
2858
+ provenance: AiwgFortemiProvenance[];
2859
+ privacy: {
2860
+ classification: AiwgPrivacyClassification;
2861
+ pii: boolean;
2862
+ };
2863
+ updated_at: string;
2864
+ }
2865
+ interface AiwgFortemiIndexExport {
2866
+ schema_version: 'aiwg.fortemi.index.export.v1';
2867
+ generated_at: string;
2868
+ source: {
2869
+ repo: string;
2870
+ privacy: AiwgPrivacyClassification;
2871
+ };
2872
+ items: AiwgFortemiRecord[];
2873
+ }
2874
+ interface AiwgIndexValidationResult {
2875
+ valid: boolean;
2876
+ errors: string[];
2877
+ counts: Partial<Record<AiwgFortemiRecordType, number>>;
2878
+ }
2879
+ interface AiwgIndexQueryOptions {
2880
+ types?: AiwgFortemiRecordType[];
2881
+ facets?: Record<string, string[]>;
2882
+ tags?: string[];
2883
+ concepts?: string[];
2884
+ privacy?: AiwgPrivacyClassification[];
2885
+ relationshipTargetId?: string;
2886
+ limit?: number;
2887
+ offset?: number;
2888
+ }
2889
+ interface AiwgIndexQueryResult {
2890
+ items: AiwgFortemiRecord[];
2891
+ total: number;
2892
+ facets: Record<string, Record<string, number>>;
2893
+ }
2894
+ interface AiwgReviewDecision {
2895
+ item_id: string;
2896
+ action: AiwgReviewAction;
2897
+ reason?: string;
2898
+ updated_at: string;
2899
+ }
2900
+ interface AiwgReviewDecisionExport {
2901
+ schema_version: 'aiwg.fortemi.review-decisions.v1';
2902
+ generated_at: string;
2903
+ source_export_schema_version: string;
2904
+ decisions: AiwgReviewDecision[];
2905
+ }
2906
+ declare function validateAiwgFortemiIndexExport(value: unknown): AiwgIndexValidationResult;
2907
+ declare function assertAiwgFortemiIndexExport(value: unknown): AiwgFortemiIndexExport;
2908
+ declare function getAiwgFortemiFacets(items: AiwgFortemiRecord[]): Record<string, Record<string, number>>;
2909
+ declare function queryAiwgFortemiIndex(index: AiwgFortemiIndexExport, query?: string, options?: AiwgIndexQueryOptions): AiwgIndexQueryResult;
2910
+ declare function createAiwgReviewDecisionExport(source: AiwgFortemiIndexExport, decisions: AiwgReviewDecision[], generatedAt?: string): AiwgReviewDecisionExport;
2911
+
2912
+ declare const VERSION = "2026.6.0";
2812
2913
 
2813
- export { type ArchiveInfo, ArchiveManager, type AttachInput, type AttachmentBlobRow, type AttachmentRow, AttachmentsRepository, type BlobStore, type BridgeCapability, type BrowserNoteExport, CURRENT_SHARD_VERSION, type CapabilityInfo, CapabilityManager, type CapabilityName, type CapabilityState, type CaptureKnowledgeInput, CaptureKnowledgeInputSchema, type CaptureKnowledgeResult, type CollectionCreateInput, type CollectionRow, CollectionsRepository, CommunitiesRepository, type CommunityAssignmentView, type CommunityCreateInput, type CommunityFilterDefinition, type CommunityGraph, type CommunityOptions, type CommunitySourceDescriptor, type CommunitySourceType, type CommunitySummary, type CompletionRequest, type CompletionResponse, type ConditionResult, type ConflictStrategy, type CooldownConfig, type CooldownEvent, type CspDirectiveName, type CspDirectives, type CspViolationReport, type DatabaseClient, type DiscoveredProvider, type DiscoveryOptions, type EmbedFunction, type EmbedRequest, type EmbedResponse, type EmbeddingCompatibilityPolicy, type EmbeddingSetCreateInput, type EmbeddingSetCriteria, type EmbeddingSetDescriptor, type EmbeddingSetEmbeddingInput, type EmbeddingSetFreshness, type EmbeddingSetKind, type EmbeddingSetMode, type EmbeddingSetRow, type EmbeddingSetSelector, EmbeddingSetsRepository, type EnqueueJobInput, type ErrorCategory, type EventMap, type ExportOptions, type FallbackEvent, FallbackRouter, type FallbackRouterConfig, type FortemiConfig, type FortemiCore, type FortemiToolDefinition, FortemiToolManifest, type GetNoteInput, GetNoteInputSchema, type GpuCapabilities, type GraphCommunity, type GraphEdge, type GraphNode, GraphRepository, type IDisposable, type ImportCounts, type ImportOptions, type ImportResult, type InferenceCapabilities, type InferenceProvider, JOB_CAPABILITIES, JOB_PRIORITIES, type JobQueueOptions, JobQueueWorker, type JobStatus, type JobType, LOCAL_ENDPOINTS, type LinkRow, LinksRepository, type ListNotesInput, ListNotesInputSchema, type LlmCapabilityOptions, type LlmCompleteFn, type LoadedPluginScript, type LocalEndpoint, type ManageArchiveInput, ManageArchiveInputSchema, type ManageArchiveResult, type ManageAttachmentsInput, ManageAttachmentsInputSchema, type ManageAttachmentsResult, type ManageCapabilitiesInput, ManageCapabilitiesInputSchema, type ManageCapabilitiesResult, type ManageCollectionsInput, ManageCollectionsInputSchema, type ManageCollectionsResult, type ManageLinksInput, ManageLinksInputSchema, type ManageLinksResult, type ManageNoteInput, ManageNoteInputSchema, type ManageNoteResult, type ManageTagsInput, ManageTagsInputSchema, type ManageTagsResult, MemoryBlobStore, type Migration, MigrationRunner, type ModelCategory, type ModelFitResult, type ModelInfo, type NoteCreateInput, type NoteFull, type NoteListOptions, type NoteRevision, type NoteSummary, type NoteUpdateInput, NotesRepository, OpenAICompatibleProvider, type OpenAIProviderConfig, PGliteStorageBackend, PGliteStorageBackendFactory, PGliteWorkerClient, type PaginatedResult, type PersistenceMode, type PluginCspOptions, type PluginScriptDescriptor, type PluginScriptPolicy, type ProbeResult, type ProbeStatus, type ProviderCapabilities, ProviderRegistry, type ProviderTier, type QueryExecutor, type QueryResult, type RecommendedTier, type ResolvedEmbeddingRow, type ResolvedEmbeddingSet, type RouteHandler, SHARD_FORMAT, type SWRegistrationResult, type SearchFacets, type SearchInput, SearchInputSchema, type SearchOptions, SearchRepository, type SearchResponse, type SearchResult, type ShardCollection, type ShardComponent, type ShardEmbedding, type ShardEmbeddingSet, type ShardEmbeddingSetMember, type ShardLink, type ShardManifest, type ShardNote, type ShardNoteSkosTag, type ShardProvenanceEdge, type ShardSkosConcept, type ShardSkosRelation, type ShardSkosScheme, type ShardTag, type SimilarityGraphCacheKey, type SimilarityGraphOptions, type SimilarityGraphRequest, type SimilarityGraphResult, type SkosConcept, type SkosRelation, SkosRepository, type SkosScheme, type StorageBackend, type StorageBackendFactory, type StorageOpenRequest, type StorageTopology, type StreamChunk, TagsRepository, TransactionProxy, TypedEventBus, VERSION, type VirtualEmbeddingSetDefinition, type VirtualEmbeddingSetSource, type VirtualEmbeddingSetValidationError, type VirtualMaterializationPolicy, type VramTier, type WorkerRequest, type WorkerResponse, aiRevisionHandler, allMigrations, appendPluginScript, buildNoteConditions, buildPluginCsp, captureKnowledge, chunkText, classifyError, classifyModel, collectionFromShard, collectionToShard, computeHash, computeSri, conceptTaggingHandler, cosineSimilarity, createBlobStore, createCspReportHandler, createFortemi, createLegacyProvider, createPGliteInstance, createRoutes, defaultStorageBackendFactory, detectCommunities, detectGpuCapabilities, detectInferenceCapabilities, discoverLocalProviders, embeddingFromShard, embeddingGenerationHandler, embeddingSetFromShard, embeddingSetMemberToShard, embeddingSetToShard, embeddingToShard, enqueueFullWorkflow, enqueueJob, enqueueNoteCreationJobs, estimateModelFit, estimateVramMB, estimateVramTier, exportShard, fetchPluginScript, fortemiManifest, generateId, getEmbedFunction, getJobQueueStatus, getLlmFunction, getNote, importShard, isPluginScriptAllowed, linkFromShard, linkToShard, linkingHandler, listNotes, manageArchive, manageAttachments, manageCapabilities, manageCollections, manageLinks, manageNote, manageTags, matchRoute, noteFromShard, noteSkosTagToShard, noteToShard, packTarGz, parseCspReport, provenanceEdgeToShard, registerLlmCapability, registerSemanticCapability, registerServiceWorker, searchTool, selectLlmModel, setEmbedFunction, setLlmFunction, sha256Hex, skosConceptToShard, skosRelationToShard, skosSchemeToShard, suggestTags, tagsFromShard, tagsToShard, titleGenerationHandler, unpackTarGz, unregisterLlmCapability, unregisterSemanticCapability, validateChecksums, verifySri };
2914
+ export { type AiwgFortemiIndexExport, type AiwgFortemiProvenance, type AiwgFortemiRecord, type AiwgFortemiRecordSource, type AiwgFortemiRecordType, type AiwgFortemiRelationship, type AiwgIndexQueryOptions, type AiwgIndexQueryResult, type AiwgIndexValidationResult, type AiwgPrivacyClassification, type AiwgProvenanceConfidence, type AiwgReviewAction, type AiwgReviewDecision, type AiwgReviewDecisionExport, type ArchiveInfo, ArchiveManager, type AttachInput, type AttachmentBlobRow, type AttachmentRow, AttachmentsRepository, type BlobStore, type BridgeCapability, type BrowserNoteExport, CURRENT_SHARD_VERSION, type CapabilityInfo, CapabilityManager, type CapabilityName, type CapabilityState, type CaptureKnowledgeInput, CaptureKnowledgeInputSchema, type CaptureKnowledgeResult, type CollectionCreateInput, type CollectionRow, CollectionsRepository, CommunitiesRepository, type CommunityAssignmentView, type CommunityCreateInput, type CommunityFilterDefinition, type CommunityGraph, type CommunityOptions, type CommunitySourceDescriptor, type CommunitySourceType, type CommunitySummary, type CompletionRequest, type CompletionResponse, type ConditionResult, type ConflictStrategy, type CooldownConfig, type CooldownEvent, type CspDirectiveName, type CspDirectives, type CspViolationReport, type DatabaseClient, type DiscoveredProvider, type DiscoveryOptions, type EmbedFunction, type EmbedRequest, type EmbedResponse, type EmbeddingCompatibilityPolicy, type EmbeddingSetCreateInput, type EmbeddingSetCriteria, type EmbeddingSetDescriptor, type EmbeddingSetEmbeddingInput, type EmbeddingSetFreshness, type EmbeddingSetKind, type EmbeddingSetMode, type EmbeddingSetRow, type EmbeddingSetSelector, EmbeddingSetsRepository, type EnqueueJobInput, type ErrorCategory, type EventMap, type ExportOptions, type FallbackEvent, FallbackRouter, type FallbackRouterConfig, type FortemiConfig, type FortemiCore, type FortemiToolDefinition, FortemiToolManifest, type GetNoteInput, GetNoteInputSchema, type GpuCapabilities, type GraphCommunity, type GraphEdge, type GraphNode, GraphRepository, type IDisposable, type ImportCounts, type ImportOptions, type ImportResult, type InferenceCapabilities, type InferenceProvider, JOB_CAPABILITIES, JOB_PRIORITIES, type JobQueueOptions, JobQueueWorker, type JobStatus, type JobType, LOCAL_ENDPOINTS, type LinkRow, LinksRepository, type ListNotesInput, ListNotesInputSchema, type LlmCapabilityOptions, type LlmCompleteFn, type LoadedPluginScript, type LocalEndpoint, type ManageArchiveInput, ManageArchiveInputSchema, type ManageArchiveResult, type ManageAttachmentsInput, ManageAttachmentsInputSchema, type ManageAttachmentsResult, type ManageCapabilitiesInput, ManageCapabilitiesInputSchema, type ManageCapabilitiesResult, type ManageCollectionsInput, ManageCollectionsInputSchema, type ManageCollectionsResult, type ManageLinksInput, ManageLinksInputSchema, type ManageLinksResult, type ManageNoteInput, ManageNoteInputSchema, type ManageNoteResult, type ManageTagsInput, ManageTagsInputSchema, type ManageTagsResult, MemoryBlobStore, type Migration, MigrationRunner, type ModelCategory, type ModelFitResult, type ModelInfo, type NoteCreateInput, type NoteFull, type NoteListOptions, type NoteRevision, type NoteSummary, type NoteUpdateInput, NotesRepository, OpenAICompatibleProvider, type OpenAIProviderConfig, PGliteStorageBackend, PGliteStorageBackendFactory, PGliteWorkerClient, type PaginatedResult, type PersistenceMode, type PluginCspOptions, type PluginScriptDescriptor, type PluginScriptPolicy, type ProbeResult, type ProbeStatus, type ProviderCapabilities, ProviderRegistry, type ProviderTier, type QueryExecutor, type QueryResult, type RecommendedTier, type ResolvedEmbeddingRow, type ResolvedEmbeddingSet, type RouteHandler, SHARD_FORMAT, type SWRegistrationResult, type SearchFacets, type SearchInput, SearchInputSchema, type SearchOptions, SearchRepository, type SearchResponse, type SearchResult, type ShardCollection, type ShardComponent, type ShardEmbedding, type ShardEmbeddingSet, type ShardEmbeddingSetMember, type ShardLink, type ShardManifest, type ShardNote, type ShardNoteSkosTag, type ShardProvenanceEdge, type ShardSkosConcept, type ShardSkosRelation, type ShardSkosScheme, type ShardTag, type SimilarityGraphCacheKey, type SimilarityGraphOptions, type SimilarityGraphRequest, type SimilarityGraphResult, type SkosConcept, type SkosRelation, SkosRepository, type SkosScheme, type StorageBackend, type StorageBackendFactory, type StorageOpenRequest, type StorageTopology, type StreamChunk, TagsRepository, TransactionProxy, TypedEventBus, VERSION, type VirtualEmbeddingSetDefinition, type VirtualEmbeddingSetSource, type VirtualEmbeddingSetValidationError, type VirtualMaterializationPolicy, type VramTier, type WorkerRequest, type WorkerResponse, aiRevisionHandler, allMigrations, appendPluginScript, assertAiwgFortemiIndexExport, buildNoteConditions, buildPluginCsp, captureKnowledge, chunkText, classifyError, classifyModel, collectionFromShard, collectionToShard, computeHash, computeSri, conceptTaggingHandler, cosineSimilarity, createAiwgReviewDecisionExport, createBlobStore, createCspReportHandler, createFortemi, createLegacyProvider, createPGliteInstance, createRoutes, defaultStorageBackendFactory, detectCommunities, detectGpuCapabilities, detectInferenceCapabilities, discoverLocalProviders, embeddingFromShard, embeddingGenerationHandler, embeddingSetFromShard, embeddingSetMemberToShard, embeddingSetToShard, embeddingToShard, enqueueFullWorkflow, enqueueJob, enqueueNoteCreationJobs, estimateModelFit, estimateVramMB, estimateVramTier, exportShard, fetchPluginScript, fortemiManifest, generateId, getAiwgFortemiFacets, getEmbedFunction, getJobQueueStatus, getLlmFunction, getNote, importShard, isPluginScriptAllowed, linkFromShard, linkToShard, linkingHandler, listNotes, manageArchive, manageAttachments, manageCapabilities, manageCollections, manageLinks, manageNote, manageTags, matchRoute, noteFromShard, noteSkosTagToShard, noteToShard, packTarGz, parseCspReport, provenanceEdgeToShard, queryAiwgFortemiIndex, registerLlmCapability, registerSemanticCapability, registerServiceWorker, searchTool, selectLlmModel, setEmbedFunction, setLlmFunction, sha256Hex, skosConceptToShard, skosRelationToShard, skosSchemeToShard, suggestTags, tagsFromShard, tagsToShard, titleGenerationHandler, unpackTarGz, unregisterLlmCapability, unregisterSemanticCapability, validateAiwgFortemiIndexExport, validateChecksums, verifySri };
package/dist/index.js CHANGED
@@ -2953,12 +2953,12 @@ var JobQueueWorker = class {
2953
2953
  if (job.required_capability) {
2954
2954
  const capName = job.required_capability;
2955
2955
  if (!this.capabilityManager?.isReady(capName)) {
2956
- console.log(`[JobQueue] Skipping ${job.job_type} \u2014 capability '${capName}' not ready`);
2956
+ await this.blockForCapability(job, capName);
2957
2957
  continue;
2958
2958
  }
2959
2959
  }
2960
2960
  await this.db.query(
2961
- `UPDATE job_queue SET status = 'processing', updated_at = now() WHERE id = $1`,
2961
+ `UPDATE job_queue SET status = 'processing', error = NULL, updated_at = now() WHERE id = $1`,
2962
2962
  [job.id]
2963
2963
  );
2964
2964
  try {
@@ -2966,7 +2966,7 @@ var JobQueueWorker = class {
2966
2966
  const jobResult = await handler(job, this.db);
2967
2967
  console.log(`[JobQueue] Completed ${job.job_type}:`, jobResult);
2968
2968
  await this.db.query(
2969
- `UPDATE job_queue SET status = 'completed', result = $1, updated_at = now() WHERE id = $2`,
2969
+ `UPDATE job_queue SET status = 'completed', error = NULL, result = $1, updated_at = now() WHERE id = $2`,
2970
2970
  [JSON.stringify(jobResult ?? null), job.id]
2971
2971
  );
2972
2972
  this.events?.emit("job.completed", {
@@ -3000,6 +3000,30 @@ var JobQueueWorker = class {
3000
3000
  }
3001
3001
  return processed;
3002
3002
  }
3003
+ async blockForCapability(job, capability) {
3004
+ const message = `requires capability '${capability}' \u2014 not ready`;
3005
+ console.log(`[JobQueue] Deferring ${job.job_type} \u2014 ${message}`);
3006
+ await this.db.query(
3007
+ `UPDATE job_queue
3008
+ SET status = 'pending', error = $1, updated_at = now()
3009
+ WHERE id = $2 AND error IS DISTINCT FROM $1`,
3010
+ [message, job.id]
3011
+ );
3012
+ this.events?.emit("job.blocked", {
3013
+ id: job.id,
3014
+ noteId: job.note_id,
3015
+ type: job.job_type,
3016
+ capability,
3017
+ message
3018
+ });
3019
+ this.events?.emit("capability.required", {
3020
+ name: capability,
3021
+ jobId: job.id,
3022
+ noteId: job.note_id,
3023
+ type: job.job_type,
3024
+ message
3025
+ });
3026
+ }
3003
3027
  getBackoffDelay(retryCount) {
3004
3028
  const delay = this.options.backoffBaseMs * Math.pow(2, retryCount);
3005
3029
  return Math.min(delay, this.options.backoffMaxMs);
@@ -6388,9 +6412,144 @@ function parseJsonArray(data) {
6388
6412
  return JSON.parse(decoder.decode(data));
6389
6413
  }
6390
6414
 
6415
+ // src/aiwg-index.ts
6416
+ var REQUIRED_RECORD_FIELDS = [
6417
+ "schema_version",
6418
+ "id",
6419
+ "type",
6420
+ "source",
6421
+ "title",
6422
+ "text",
6423
+ "facets",
6424
+ "tags",
6425
+ "concepts",
6426
+ "relationships",
6427
+ "provenance",
6428
+ "privacy",
6429
+ "updated_at"
6430
+ ];
6431
+ var VALID_TYPES = /* @__PURE__ */ new Set([
6432
+ "crm.contact",
6433
+ "crm.organization",
6434
+ "crm.event",
6435
+ "crm.interaction",
6436
+ "aiwg.artifact"
6437
+ ]);
6438
+ function hasString(value) {
6439
+ return typeof value === "string" && value.length > 0;
6440
+ }
6441
+ function pushFacet(counts, name, value) {
6442
+ counts[name] ??= {};
6443
+ counts[name][value] = (counts[name][value] ?? 0) + 1;
6444
+ }
6445
+ function validateAiwgFortemiIndexExport(value) {
6446
+ const errors = [];
6447
+ const counts = {};
6448
+ const data = value;
6449
+ if (data?.schema_version !== "aiwg.fortemi.index.export.v1") {
6450
+ errors.push("schema_version must be aiwg.fortemi.index.export.v1");
6451
+ }
6452
+ if (!hasString(data?.generated_at)) errors.push("generated_at is required");
6453
+ if (!hasString(data?.source?.repo)) errors.push("source.repo is required");
6454
+ if (!hasString(data?.source?.privacy)) errors.push("source.privacy is required");
6455
+ if (!Array.isArray(data?.items)) errors.push("items must be an array");
6456
+ const ids = /* @__PURE__ */ new Set();
6457
+ let previousId = "";
6458
+ for (const [index, item] of (data.items ?? []).entries()) {
6459
+ for (const field of REQUIRED_RECORD_FIELDS) {
6460
+ if (!(field in item)) errors.push("items[" + index + "]." + field + " is required");
6461
+ }
6462
+ if (item.schema_version !== "aiwg.fortemi.index.record.v1") {
6463
+ errors.push("items[" + index + "].schema_version must be aiwg.fortemi.index.record.v1");
6464
+ }
6465
+ if (!hasString(item.id)) errors.push("items[" + index + "].id is required");
6466
+ if (hasString(item.id) && ids.has(item.id)) errors.push("duplicate id: " + item.id);
6467
+ if (hasString(item.id)) ids.add(item.id);
6468
+ if (previousId && hasString(item.id) && previousId.localeCompare(item.id) > 0) {
6469
+ errors.push("items must be sorted by id: " + previousId + " before " + item.id);
6470
+ }
6471
+ if (hasString(item.id)) previousId = item.id;
6472
+ if (!VALID_TYPES.has(item.type)) errors.push("items[" + index + "].type is invalid");
6473
+ else counts[item.type] = (counts[item.type] ?? 0) + 1;
6474
+ if (!hasString(item.source?.path)) errors.push("items[" + index + "].source.path is required");
6475
+ if (!hasString(item.source?.repo_relative_path)) errors.push("items[" + index + "].source.repo_relative_path is required");
6476
+ if (!hasString(item.source?.locator)) errors.push("items[" + index + "].source.locator is required");
6477
+ if (!Array.isArray(item.tags)) errors.push("items[" + index + "].tags must be an array");
6478
+ if (!Array.isArray(item.concepts)) errors.push("items[" + index + "].concepts must be an array");
6479
+ if (!Array.isArray(item.relationships)) errors.push("items[" + index + "].relationships must be an array");
6480
+ if (!Array.isArray(item.provenance) || item.provenance.length === 0) {
6481
+ errors.push("items[" + index + "].provenance must be a non-empty array");
6482
+ }
6483
+ if (!item.privacy || typeof item.privacy.pii !== "boolean" || !hasString(item.privacy.classification)) {
6484
+ errors.push("items[" + index + "].privacy requires classification and pii");
6485
+ }
6486
+ }
6487
+ return { valid: errors.length === 0, errors, counts };
6488
+ }
6489
+ function assertAiwgFortemiIndexExport(value) {
6490
+ const result = validateAiwgFortemiIndexExport(value);
6491
+ if (!result.valid) {
6492
+ throw new Error("Invalid AIWG Fortemi index export:\n" + result.errors.join("\n"));
6493
+ }
6494
+ return value;
6495
+ }
6496
+ function getAiwgFortemiFacets(items) {
6497
+ const result = {};
6498
+ for (const item of items) {
6499
+ pushFacet(result, "type", item.type);
6500
+ pushFacet(result, "privacy", item.privacy.classification);
6501
+ for (const tag of item.tags) pushFacet(result, "tag", tag);
6502
+ for (const concept of item.concepts) pushFacet(result, "concept", concept);
6503
+ for (const [name, values] of Object.entries(item.facets)) {
6504
+ for (const value of values) pushFacet(result, name, value);
6505
+ }
6506
+ }
6507
+ return result;
6508
+ }
6509
+ function includesAll(actual, expected) {
6510
+ if (!expected || expected.length === 0) return true;
6511
+ const actualSet = new Set(actual);
6512
+ return expected.every((value) => actualSet.has(value));
6513
+ }
6514
+ function matchesFacetFilters(item, filters) {
6515
+ if (!filters) return true;
6516
+ return Object.entries(filters).every(([name, expected]) => includesAll(item.facets[name] ?? [], expected));
6517
+ }
6518
+ function queryAiwgFortemiIndex(index, query = "", options = {}) {
6519
+ const q = query.trim().toLowerCase();
6520
+ const filtered = index.items.filter((item) => {
6521
+ if (q) {
6522
+ const haystack = [item.title, item.text, ...item.tags, ...item.concepts].join("\n").toLowerCase();
6523
+ if (!haystack.includes(q)) return false;
6524
+ }
6525
+ if (options.types && !options.types.includes(item.type)) return false;
6526
+ if (options.privacy && !options.privacy.includes(item.privacy.classification)) return false;
6527
+ if (!includesAll(item.tags, options.tags)) return false;
6528
+ if (!includesAll(item.concepts, options.concepts)) return false;
6529
+ if (!matchesFacetFilters(item, options.facets)) return false;
6530
+ if (options.relationshipTargetId && !item.relationships.some((rel) => rel.target_id === options.relationshipTargetId)) return false;
6531
+ return true;
6532
+ });
6533
+ const offset = options.offset ?? 0;
6534
+ const limit = options.limit ?? filtered.length;
6535
+ return {
6536
+ items: filtered.slice(offset, offset + limit),
6537
+ total: filtered.length,
6538
+ facets: getAiwgFortemiFacets(filtered)
6539
+ };
6540
+ }
6541
+ function createAiwgReviewDecisionExport(source, decisions, generatedAt = (/* @__PURE__ */ new Date()).toISOString()) {
6542
+ return {
6543
+ schema_version: "aiwg.fortemi.review-decisions.v1",
6544
+ generated_at: generatedAt,
6545
+ source_export_schema_version: source.schema_version,
6546
+ decisions: [...decisions].sort((left, right) => left.item_id.localeCompare(right.item_id))
6547
+ };
6548
+ }
6549
+
6391
6550
  // src/index.ts
6392
- var VERSION = "2026.5.4";
6551
+ var VERSION = "2026.6.0";
6393
6552
 
6394
- export { ArchiveManager, AttachmentsRepository, CURRENT_SHARD_VERSION, CapabilityManager, CaptureKnowledgeInputSchema, CollectionsRepository, CommunitiesRepository, EmbeddingSetsRepository, FallbackRouter, FortemiToolManifest, GetNoteInputSchema, GraphRepository, JOB_CAPABILITIES, JOB_PRIORITIES, JobQueueWorker, LOCAL_ENDPOINTS, LinksRepository, ListNotesInputSchema, ManageArchiveInputSchema, ManageAttachmentsInputSchema, ManageCapabilitiesInputSchema, ManageCollectionsInputSchema, ManageLinksInputSchema, ManageNoteInputSchema, ManageTagsInputSchema, MemoryBlobStore, MigrationRunner, NotesRepository, OpenAICompatibleProvider, PGliteStorageBackend, PGliteStorageBackendFactory, PGliteWorkerClient, ProviderRegistry, SHARD_FORMAT, SearchInputSchema, SearchRepository, SkosRepository, TagsRepository, TransactionProxy, TypedEventBus, VERSION, aiRevisionHandler, allMigrations, appendPluginScript, buildNoteConditions, buildPluginCsp, captureKnowledge, chunkText, classifyError, classifyModel, collectionFromShard, collectionToShard, computeHash, computeSri, conceptTaggingHandler, cosineSimilarity, createBlobStore, createCspReportHandler, createFortemi, createLegacyProvider, createPGliteInstance, createRoutes, defaultStorageBackendFactory, detectCommunities, detectGpuCapabilities, detectInferenceCapabilities, discoverLocalProviders, embeddingFromShard, embeddingGenerationHandler, embeddingSetFromShard, embeddingSetMemberToShard, embeddingSetToShard, embeddingToShard, enqueueFullWorkflow, enqueueJob, enqueueNoteCreationJobs, estimateModelFit, estimateVramMB, estimateVramTier, exportShard, fetchPluginScript, fortemiManifest, generateId, getEmbedFunction, getJobQueueStatus, getLlmFunction, getNote, importShard, isPluginScriptAllowed, linkFromShard, linkToShard, linkingHandler, listNotes, manageArchive, manageAttachments, manageCapabilities, manageCollections, manageLinks, manageNote, manageTags, matchRoute, noteFromShard, noteSkosTagToShard, noteToShard, packTarGz, parseCspReport, provenanceEdgeToShard, registerLlmCapability, registerSemanticCapability, registerServiceWorker, searchTool, selectLlmModel, setEmbedFunction, setLlmFunction, sha256Hex, skosConceptToShard, skosRelationToShard, skosSchemeToShard, suggestTags, tagsFromShard, tagsToShard, titleGenerationHandler, unpackTarGz, unregisterLlmCapability, unregisterSemanticCapability, validateChecksums, verifySri };
6553
+ export { ArchiveManager, AttachmentsRepository, CURRENT_SHARD_VERSION, CapabilityManager, CaptureKnowledgeInputSchema, CollectionsRepository, CommunitiesRepository, EmbeddingSetsRepository, FallbackRouter, FortemiToolManifest, GetNoteInputSchema, GraphRepository, JOB_CAPABILITIES, JOB_PRIORITIES, JobQueueWorker, LOCAL_ENDPOINTS, LinksRepository, ListNotesInputSchema, ManageArchiveInputSchema, ManageAttachmentsInputSchema, ManageCapabilitiesInputSchema, ManageCollectionsInputSchema, ManageLinksInputSchema, ManageNoteInputSchema, ManageTagsInputSchema, MemoryBlobStore, MigrationRunner, NotesRepository, OpenAICompatibleProvider, PGliteStorageBackend, PGliteStorageBackendFactory, PGliteWorkerClient, ProviderRegistry, SHARD_FORMAT, SearchInputSchema, SearchRepository, SkosRepository, TagsRepository, TransactionProxy, TypedEventBus, VERSION, aiRevisionHandler, allMigrations, appendPluginScript, assertAiwgFortemiIndexExport, buildNoteConditions, buildPluginCsp, captureKnowledge, chunkText, classifyError, classifyModel, collectionFromShard, collectionToShard, computeHash, computeSri, conceptTaggingHandler, cosineSimilarity, createAiwgReviewDecisionExport, createBlobStore, createCspReportHandler, createFortemi, createLegacyProvider, createPGliteInstance, createRoutes, defaultStorageBackendFactory, detectCommunities, detectGpuCapabilities, detectInferenceCapabilities, discoverLocalProviders, embeddingFromShard, embeddingGenerationHandler, embeddingSetFromShard, embeddingSetMemberToShard, embeddingSetToShard, embeddingToShard, enqueueFullWorkflow, enqueueJob, enqueueNoteCreationJobs, estimateModelFit, estimateVramMB, estimateVramTier, exportShard, fetchPluginScript, fortemiManifest, generateId, getAiwgFortemiFacets, getEmbedFunction, getJobQueueStatus, getLlmFunction, getNote, importShard, isPluginScriptAllowed, linkFromShard, linkToShard, linkingHandler, listNotes, manageArchive, manageAttachments, manageCapabilities, manageCollections, manageLinks, manageNote, manageTags, matchRoute, noteFromShard, noteSkosTagToShard, noteToShard, packTarGz, parseCspReport, provenanceEdgeToShard, queryAiwgFortemiIndex, registerLlmCapability, registerSemanticCapability, registerServiceWorker, searchTool, selectLlmModel, setEmbedFunction, setLlmFunction, sha256Hex, skosConceptToShard, skosRelationToShard, skosSchemeToShard, suggestTags, tagsFromShard, tagsToShard, titleGenerationHandler, unpackTarGz, unregisterLlmCapability, unregisterSemanticCapability, validateAiwgFortemiIndexExport, validateChecksums, verifySri };
6395
6554
  //# sourceMappingURL=index.js.map
6396
6555
  //# sourceMappingURL=index.js.map