@lssm/lib.knowledge 0.0.0-canary-20251207013726 → 0.0.0-canary-20251207043720

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 CHANGED
@@ -63,3 +63,4 @@ MIT
63
63
 
64
64
 
65
65
 
66
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lssm/lib.knowledge",
3
- "version": "0.0.0-canary-20251207013726",
3
+ "version": "0.0.0-canary-20251207043720",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -31,25 +31,44 @@
31
31
  "typescript": "^5.9.3"
32
32
  },
33
33
  "exports": {
34
- ".": "./dist/index.js",
35
- "./access": "./dist/access/index.js",
36
- "./access/guard": "./dist/access/guard.js",
37
- "./ingestion": "./dist/ingestion/index.js",
38
- "./ingestion/document-processor": "./dist/ingestion/document-processor.js",
39
- "./ingestion/embedding-service": "./dist/ingestion/embedding-service.js",
40
- "./ingestion/gmail-adapter": "./dist/ingestion/gmail-adapter.js",
41
- "./ingestion/storage-adapter": "./dist/ingestion/storage-adapter.js",
42
- "./ingestion/vector-indexer": "./dist/ingestion/vector-indexer.js",
43
- "./query": "./dist/query/index.js",
44
- "./query/service": "./dist/query/service.js",
45
- "./retriever": "./dist/retriever/index.js",
46
- "./retriever/interface": "./dist/retriever/interface.js",
47
- "./retriever/static-retriever": "./dist/retriever/static-retriever.js",
48
- "./retriever/vector-retriever": "./dist/retriever/vector-retriever.js",
49
- "./types": "./dist/types.js",
34
+ ".": "./src/index.ts",
35
+ "./access": "./src/access/index.ts",
36
+ "./access/guard": "./src/access/guard.ts",
37
+ "./ingestion": "./src/ingestion/index.ts",
38
+ "./ingestion/document-processor": "./src/ingestion/document-processor.ts",
39
+ "./ingestion/embedding-service": "./src/ingestion/embedding-service.ts",
40
+ "./ingestion/gmail-adapter": "./src/ingestion/gmail-adapter.ts",
41
+ "./ingestion/storage-adapter": "./src/ingestion/storage-adapter.ts",
42
+ "./ingestion/vector-indexer": "./src/ingestion/vector-indexer.ts",
43
+ "./query": "./src/query/index.ts",
44
+ "./query/service": "./src/query/service.ts",
45
+ "./retriever": "./src/retriever/index.ts",
46
+ "./retriever/interface": "./src/retriever/interface.ts",
47
+ "./retriever/static-retriever": "./src/retriever/static-retriever.ts",
48
+ "./retriever/vector-retriever": "./src/retriever/vector-retriever.ts",
49
+ "./types": "./src/types.ts",
50
50
  "./*": "./*"
51
51
  },
52
52
  "publishConfig": {
53
- "access": "public"
53
+ "access": "public",
54
+ "exports": {
55
+ ".": "./dist/index.js",
56
+ "./access": "./dist/access/index.js",
57
+ "./access/guard": "./dist/access/guard.js",
58
+ "./ingestion": "./dist/ingestion/index.js",
59
+ "./ingestion/document-processor": "./dist/ingestion/document-processor.js",
60
+ "./ingestion/embedding-service": "./dist/ingestion/embedding-service.js",
61
+ "./ingestion/gmail-adapter": "./dist/ingestion/gmail-adapter.js",
62
+ "./ingestion/storage-adapter": "./dist/ingestion/storage-adapter.js",
63
+ "./ingestion/vector-indexer": "./dist/ingestion/vector-indexer.js",
64
+ "./query": "./dist/query/index.js",
65
+ "./query/service": "./dist/query/service.js",
66
+ "./retriever": "./dist/retriever/index.js",
67
+ "./retriever/interface": "./dist/retriever/interface.js",
68
+ "./retriever/static-retriever": "./dist/retriever/static-retriever.js",
69
+ "./retriever/vector-retriever": "./dist/retriever/vector-retriever.js",
70
+ "./types": "./dist/types.js",
71
+ "./*": "./*"
72
+ }
54
73
  }
55
74
  }
@@ -1,20 +0,0 @@
1
- import { KnowledgeAccessContext, KnowledgeAccessResult } from "../types.js";
2
- import { ResolvedAppConfig, ResolvedKnowledge } from "@lssm/lib.contracts/app-config";
3
- import { KnowledgeCategory } from "@lssm/lib.contracts/knowledge";
4
-
5
- //#region src/access/guard.d.ts
6
- interface KnowledgeAccessGuardOptions {
7
- disallowWriteCategories?: KnowledgeCategory[];
8
- requireWorkflowBinding?: boolean;
9
- requireAgentBinding?: boolean;
10
- }
11
- declare class KnowledgeAccessGuard {
12
- private readonly disallowedWrite;
13
- private readonly requireWorkflowBinding;
14
- private readonly requireAgentBinding;
15
- constructor(options?: KnowledgeAccessGuardOptions);
16
- checkAccess(spaceBinding: ResolvedKnowledge, context: KnowledgeAccessContext, appConfig: ResolvedAppConfig): KnowledgeAccessResult;
17
- private isSpaceBound;
18
- }
19
- //#endregion
20
- export { KnowledgeAccessGuard, KnowledgeAccessGuardOptions };
@@ -1,2 +0,0 @@
1
- import { KnowledgeAccessGuard, KnowledgeAccessGuardOptions } from "./guard.js";
2
- export { KnowledgeAccessGuard, KnowledgeAccessGuardOptions };
package/dist/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { KnowledgeAccessContext, KnowledgeAccessResult, RetrievalOptions, RetrievalResult } from "./types.js";
2
- import { KnowledgeAccessGuard, KnowledgeAccessGuardOptions } from "./access/guard.js";
3
- import { KnowledgeRetriever, RetrieverConfig } from "./retriever/interface.js";
4
- import { StaticRetriever, StaticRetrieverConfig, createStaticRetriever } from "./retriever/static-retriever.js";
5
- import { VectorRetriever, VectorRetrieverConfig, createVectorRetriever } from "./retriever/vector-retriever.js";
6
- import { KnowledgeAnswer, KnowledgeQueryConfig, KnowledgeQueryService } from "./query/service.js";
7
- import { DocumentFragment, DocumentProcessor, RawDocument } from "./ingestion/document-processor.js";
8
- import { EmbeddingService } from "./ingestion/embedding-service.js";
9
- import { VectorIndexConfig, VectorIndexer } from "./ingestion/vector-indexer.js";
10
- import { GmailIngestionAdapter } from "./ingestion/gmail-adapter.js";
11
- import { StorageIngestionAdapter } from "./ingestion/storage-adapter.js";
12
- export { DocumentFragment, DocumentProcessor, EmbeddingService, GmailIngestionAdapter, KnowledgeAccessContext, KnowledgeAccessGuard, KnowledgeAccessGuardOptions, KnowledgeAccessResult, KnowledgeAnswer, KnowledgeQueryConfig, KnowledgeQueryService, KnowledgeRetriever, RawDocument, RetrievalOptions, RetrievalResult, RetrieverConfig, StaticRetriever, StaticRetrieverConfig, StorageIngestionAdapter, VectorIndexConfig, VectorIndexer, VectorRetriever, VectorRetrieverConfig, createStaticRetriever, createVectorRetriever };
@@ -1,24 +0,0 @@
1
- //#region src/ingestion/document-processor.d.ts
2
- interface RawDocument {
3
- id: string;
4
- mimeType: string;
5
- data: Uint8Array;
6
- metadata?: Record<string, string>;
7
- }
8
- interface DocumentFragment {
9
- id: string;
10
- documentId: string;
11
- text: string;
12
- metadata?: Record<string, string>;
13
- }
14
- type Extractor = (input: RawDocument) => Promise<DocumentFragment[]>;
15
- declare class DocumentProcessor {
16
- private readonly extractors;
17
- constructor();
18
- registerExtractor(mimeType: string, extractor: Extractor): void;
19
- process(document: RawDocument): Promise<DocumentFragment[]>;
20
- private extractText;
21
- private extractJson;
22
- }
23
- //#endregion
24
- export { DocumentFragment, DocumentProcessor, RawDocument };
@@ -1,12 +0,0 @@
1
- import { DocumentFragment } from "./document-processor.js";
2
- import { EmbeddingProvider, EmbeddingResult } from "@lssm/lib.contracts/integrations/providers";
3
-
4
- //#region src/ingestion/embedding-service.d.ts
5
- declare class EmbeddingService {
6
- private readonly provider;
7
- private readonly batchSize;
8
- constructor(provider: EmbeddingProvider, batchSize?: number);
9
- embedFragments(fragments: DocumentFragment[]): Promise<EmbeddingResult[]>;
10
- }
11
- //#endregion
12
- export { EmbeddingService };
@@ -1,18 +0,0 @@
1
- import { DocumentProcessor } from "./document-processor.js";
2
- import { EmbeddingService } from "./embedding-service.js";
3
- import { VectorIndexer } from "./vector-indexer.js";
4
- import { EmailInboundProvider, EmailThread } from "@lssm/lib.contracts/integrations/providers";
5
-
6
- //#region src/ingestion/gmail-adapter.d.ts
7
- declare class GmailIngestionAdapter {
8
- private readonly gmail;
9
- private readonly processor;
10
- private readonly embeddings;
11
- private readonly indexer;
12
- constructor(gmail: EmailInboundProvider, processor: DocumentProcessor, embeddings: EmbeddingService, indexer: VectorIndexer);
13
- syncThreads(query?: Parameters<EmailInboundProvider['listThreads']>[0]): Promise<void>;
14
- ingestThread(thread: EmailThread): Promise<void>;
15
- private toRawDocument;
16
- }
17
- //#endregion
18
- export { GmailIngestionAdapter };
@@ -1,6 +0,0 @@
1
- import { DocumentFragment, DocumentProcessor, RawDocument } from "./document-processor.js";
2
- import { EmbeddingService } from "./embedding-service.js";
3
- import { VectorIndexConfig, VectorIndexer } from "./vector-indexer.js";
4
- import { GmailIngestionAdapter } from "./gmail-adapter.js";
5
- import { StorageIngestionAdapter } from "./storage-adapter.js";
6
- export { DocumentFragment, DocumentProcessor, EmbeddingService, GmailIngestionAdapter, RawDocument, StorageIngestionAdapter, VectorIndexConfig, VectorIndexer };
@@ -1,15 +0,0 @@
1
- import { DocumentProcessor } from "./document-processor.js";
2
- import { EmbeddingService } from "./embedding-service.js";
3
- import { VectorIndexer } from "./vector-indexer.js";
4
- import { GetObjectResult } from "@lssm/lib.contracts/integrations/providers";
5
-
6
- //#region src/ingestion/storage-adapter.d.ts
7
- declare class StorageIngestionAdapter {
8
- private readonly processor;
9
- private readonly embeddings;
10
- private readonly indexer;
11
- constructor(processor: DocumentProcessor, embeddings: EmbeddingService, indexer: VectorIndexer);
12
- ingestObject(object: GetObjectResult): Promise<void>;
13
- }
14
- //#endregion
15
- export { StorageIngestionAdapter };
@@ -1,17 +0,0 @@
1
- import { DocumentFragment } from "./document-processor.js";
2
- import { EmbeddingResult, VectorStoreProvider } from "@lssm/lib.contracts/integrations/providers";
3
-
4
- //#region src/ingestion/vector-indexer.d.ts
5
- interface VectorIndexConfig {
6
- collection: string;
7
- namespace?: string;
8
- metadata?: Record<string, string>;
9
- }
10
- declare class VectorIndexer {
11
- private readonly provider;
12
- private readonly config;
13
- constructor(provider: VectorStoreProvider, config: VectorIndexConfig);
14
- upsert(fragments: DocumentFragment[], embeddings: EmbeddingResult[]): Promise<void>;
15
- }
16
- //#endregion
17
- export { VectorIndexConfig, VectorIndexer };
@@ -1,2 +0,0 @@
1
- import { KnowledgeAnswer, KnowledgeQueryConfig, KnowledgeQueryService } from "./service.js";
2
- export { KnowledgeAnswer, KnowledgeQueryConfig, KnowledgeQueryService };
@@ -1,27 +0,0 @@
1
- import { EmbeddingProvider, LLMProvider, LLMResponse, VectorSearchResult, VectorStoreProvider } from "@lssm/lib.contracts/integrations/providers";
2
-
3
- //#region src/query/service.d.ts
4
- interface KnowledgeQueryConfig {
5
- collection: string;
6
- namespace?: string;
7
- topK?: number;
8
- systemPrompt?: string;
9
- }
10
- interface KnowledgeAnswer {
11
- answer: string;
12
- references: (VectorSearchResult & {
13
- text?: string;
14
- })[];
15
- usage?: LLMResponse['usage'];
16
- }
17
- declare class KnowledgeQueryService {
18
- private readonly embeddings;
19
- private readonly vectorStore;
20
- private readonly llm;
21
- private readonly config;
22
- constructor(embeddings: EmbeddingProvider, vectorStore: VectorStoreProvider, llm: LLMProvider, config: KnowledgeQueryConfig);
23
- query(question: string): Promise<KnowledgeAnswer>;
24
- private buildMessages;
25
- }
26
- //#endregion
27
- export { KnowledgeAnswer, KnowledgeQueryConfig, KnowledgeQueryService };
@@ -1,4 +0,0 @@
1
- import { KnowledgeRetriever, RetrieverConfig } from "./interface.js";
2
- import { StaticRetriever, StaticRetrieverConfig, createStaticRetriever } from "./static-retriever.js";
3
- import { VectorRetriever, VectorRetrieverConfig, createVectorRetriever } from "./vector-retriever.js";
4
- export { KnowledgeRetriever, RetrieverConfig, StaticRetriever, StaticRetrieverConfig, VectorRetriever, VectorRetrieverConfig, createStaticRetriever, createVectorRetriever };
@@ -1,55 +0,0 @@
1
- import { RetrievalOptions, RetrievalResult } from "../types.js";
2
-
3
- //#region src/retriever/interface.d.ts
4
-
5
- /**
6
- * Unified interface for knowledge retrieval.
7
- *
8
- * Implementations can use vector stores, static content, or hybrid approaches.
9
- * This interface is consumed by @lssm/lib.ai-agent for both static injection
10
- * and dynamic RAG tool queries.
11
- */
12
- interface KnowledgeRetriever {
13
- /**
14
- * Retrieve relevant content for a query using semantic search.
15
- *
16
- * @param query - The search query or question
17
- * @param options - Retrieval options including space key and filters
18
- * @returns Array of retrieval results sorted by relevance
19
- */
20
- retrieve(query: string, options: RetrievalOptions): Promise<RetrievalResult[]>;
21
- /**
22
- * Get static content by space key (for required knowledge injection).
23
- *
24
- * Used for injecting required knowledge into agent system prompts
25
- * without performing semantic search.
26
- *
27
- * @param spaceKey - The knowledge space key
28
- * @returns The static content or null if not available
29
- */
30
- getStatic(spaceKey: string): Promise<string | null>;
31
- /**
32
- * Check if this retriever supports a given knowledge space.
33
- *
34
- * @param spaceKey - The knowledge space key to check
35
- * @returns True if the space is supported
36
- */
37
- supportsSpace(spaceKey: string): boolean;
38
- /**
39
- * List all supported knowledge space keys.
40
- *
41
- * @returns Array of supported space keys
42
- */
43
- listSpaces(): string[];
44
- }
45
- /**
46
- * Configuration for creating a retriever.
47
- */
48
- interface RetrieverConfig {
49
- /** Default number of results to return */
50
- defaultTopK?: number;
51
- /** Default minimum score threshold */
52
- defaultMinScore?: number;
53
- }
54
- //#endregion
55
- export { KnowledgeRetriever, RetrieverConfig };
@@ -1,34 +0,0 @@
1
- import { RetrievalOptions, RetrievalResult } from "../types.js";
2
- import { KnowledgeRetriever, RetrieverConfig } from "./interface.js";
3
-
4
- //#region src/retriever/static-retriever.d.ts
5
-
6
- /**
7
- * Configuration for the static retriever.
8
- */
9
- interface StaticRetrieverConfig extends RetrieverConfig {
10
- /** Map of space key to static content */
11
- content: Map<string, string> | Record<string, string>;
12
- }
13
- /**
14
- * A simple in-memory retriever for static knowledge content.
15
- *
16
- * Useful for:
17
- * - Required knowledge that doesn't need semantic search
18
- * - Testing and development
19
- * - Small knowledge bases that fit in memory
20
- */
21
- declare class StaticRetriever implements KnowledgeRetriever {
22
- private readonly content;
23
- constructor(config: StaticRetrieverConfig);
24
- retrieve(query: string, options: RetrievalOptions): Promise<RetrievalResult[]>;
25
- getStatic(spaceKey: string): Promise<string | null>;
26
- supportsSpace(spaceKey: string): boolean;
27
- listSpaces(): string[];
28
- }
29
- /**
30
- * Create a static retriever from a content map.
31
- */
32
- declare function createStaticRetriever(content: Record<string, string> | Map<string, string>): StaticRetriever;
33
- //#endregion
34
- export { StaticRetriever, StaticRetrieverConfig, createStaticRetriever };
@@ -1,42 +0,0 @@
1
- import { RetrievalOptions, RetrievalResult } from "../types.js";
2
- import { KnowledgeRetriever, RetrieverConfig } from "./interface.js";
3
- import { EmbeddingProvider, VectorStoreProvider } from "@lssm/lib.contracts/integrations/providers";
4
-
5
- //#region src/retriever/vector-retriever.d.ts
6
-
7
- /**
8
- * Configuration for the vector retriever.
9
- */
10
- interface VectorRetrieverConfig extends RetrieverConfig {
11
- /** Embedding provider for query vectorization */
12
- embeddings: EmbeddingProvider;
13
- /** Vector store provider for similarity search */
14
- vectorStore: VectorStoreProvider;
15
- /** Map of space key to collection name */
16
- spaceCollections: Map<string, string> | Record<string, string>;
17
- /** Optional static content for getStatic() calls */
18
- staticContent?: Map<string, string> | Record<string, string>;
19
- }
20
- /**
21
- * A retriever that uses vector similarity search.
22
- *
23
- * Uses embedding provider to vectorize queries and vector store
24
- * provider to perform similarity search.
25
- */
26
- declare class VectorRetriever implements KnowledgeRetriever {
27
- private readonly config;
28
- private readonly spaceCollections;
29
- private readonly staticContent;
30
- constructor(config: VectorRetrieverConfig);
31
- retrieve(query: string, options: RetrievalOptions): Promise<RetrievalResult[]>;
32
- getStatic(spaceKey: string): Promise<string | null>;
33
- supportsSpace(spaceKey: string): boolean;
34
- listSpaces(): string[];
35
- private extractContent;
36
- }
37
- /**
38
- * Create a vector retriever from configuration.
39
- */
40
- declare function createVectorRetriever(config: VectorRetrieverConfig): VectorRetriever;
41
- //#endregion
42
- export { VectorRetriever, VectorRetrieverConfig, createVectorRetriever };
package/dist/types.d.ts DELETED
@@ -1,55 +0,0 @@
1
- import { KnowledgeCategory } from "@lssm/lib.contracts/knowledge";
2
-
3
- //#region src/types.d.ts
4
-
5
- /**
6
- * Result from a knowledge retrieval operation.
7
- */
8
- interface RetrievalResult {
9
- /** The retrieved content/text */
10
- content: string;
11
- /** Source identifier (document ID, URL, etc.) */
12
- source: string;
13
- /** Relevance score (0-1, higher is more relevant) */
14
- score: number;
15
- /** Additional metadata about the result */
16
- metadata?: Record<string, unknown>;
17
- }
18
- /**
19
- * Options for knowledge retrieval.
20
- */
21
- interface RetrievalOptions {
22
- /** Knowledge space key to query */
23
- spaceKey: string;
24
- /** Maximum number of results to return */
25
- topK?: number;
26
- /** Minimum relevance score threshold */
27
- minScore?: number;
28
- /** Filter by knowledge category */
29
- category?: KnowledgeCategory;
30
- /** Tenant-scoped retrieval */
31
- tenantId?: string;
32
- /** Additional filter criteria */
33
- filter?: Record<string, unknown>;
34
- }
35
- /**
36
- * Context for knowledge access operations.
37
- */
38
- interface KnowledgeAccessContext {
39
- tenantId: string;
40
- appId: string;
41
- environment?: string;
42
- workflowName?: string;
43
- agentName?: string;
44
- operation: 'read' | 'write' | 'search';
45
- }
46
- /**
47
- * Result of an access check.
48
- */
49
- interface KnowledgeAccessResult {
50
- allowed: boolean;
51
- reason?: string;
52
- severity?: 'error' | 'warning';
53
- }
54
- //#endregion
55
- export { KnowledgeAccessContext, KnowledgeAccessResult, RetrievalOptions, RetrievalResult };