@contractspec/lib.knowledge 1.56.1 → 1.58.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.
Files changed (74) hide show
  1. package/dist/access/guard.d.ts +13 -17
  2. package/dist/access/guard.d.ts.map +1 -1
  3. package/dist/access/guard.js +60 -49
  4. package/dist/access/index.d.ts +2 -2
  5. package/dist/access/index.d.ts.map +1 -0
  6. package/dist/access/index.js +60 -2
  7. package/dist/index.d.ts +6 -12
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +455 -12
  10. package/dist/ingestion/document-processor.d.ts +18 -20
  11. package/dist/ingestion/document-processor.d.ts.map +1 -1
  12. package/dist/ingestion/document-processor.js +63 -53
  13. package/dist/ingestion/embedding-service.d.ts +7 -11
  14. package/dist/ingestion/embedding-service.d.ts.map +1 -1
  15. package/dist/ingestion/embedding-service.js +26 -25
  16. package/dist/ingestion/gmail-adapter.d.ts +13 -17
  17. package/dist/ingestion/gmail-adapter.d.ts.map +1 -1
  18. package/dist/ingestion/gmail-adapter.js +67 -46
  19. package/dist/ingestion/index.d.ts +6 -6
  20. package/dist/ingestion/index.d.ts.map +1 -0
  21. package/dist/ingestion/index.js +221 -6
  22. package/dist/ingestion/storage-adapter.d.ts +10 -14
  23. package/dist/ingestion/storage-adapter.d.ts.map +1 -1
  24. package/dist/ingestion/storage-adapter.js +31 -26
  25. package/dist/ingestion/vector-indexer.d.ts +11 -15
  26. package/dist/ingestion/vector-indexer.d.ts.map +1 -1
  27. package/dist/ingestion/vector-indexer.js +32 -32
  28. package/dist/node/access/guard.js +60 -0
  29. package/dist/node/access/index.js +60 -0
  30. package/dist/node/index.js +454 -0
  31. package/dist/node/ingestion/document-processor.js +64 -0
  32. package/dist/node/ingestion/embedding-service.js +26 -0
  33. package/dist/node/ingestion/gmail-adapter.js +72 -0
  34. package/dist/node/ingestion/index.js +221 -0
  35. package/dist/node/ingestion/storage-adapter.js +31 -0
  36. package/dist/node/ingestion/vector-indexer.js +32 -0
  37. package/dist/node/query/index.js +79 -0
  38. package/dist/node/query/service.js +79 -0
  39. package/dist/node/retriever/index.js +100 -0
  40. package/dist/node/retriever/interface.js +0 -0
  41. package/dist/node/retriever/static-retriever.js +43 -0
  42. package/dist/node/retriever/vector-retriever.js +58 -0
  43. package/dist/node/types.js +0 -0
  44. package/dist/query/index.d.ts +2 -2
  45. package/dist/query/index.d.ts.map +1 -0
  46. package/dist/query/index.js +79 -2
  47. package/dist/query/service.d.ts +20 -24
  48. package/dist/query/service.d.ts.map +1 -1
  49. package/dist/query/service.js +76 -62
  50. package/dist/retriever/index.d.ts +4 -4
  51. package/dist/retriever/index.d.ts.map +1 -0
  52. package/dist/retriever/index.js +100 -3
  53. package/dist/retriever/interface.d.ts +38 -43
  54. package/dist/retriever/interface.d.ts.map +1 -1
  55. package/dist/retriever/interface.js +1 -0
  56. package/dist/retriever/static-retriever.d.ts +13 -18
  57. package/dist/retriever/static-retriever.d.ts.map +1 -1
  58. package/dist/retriever/static-retriever.js +42 -46
  59. package/dist/retriever/vector-retriever.d.ts +23 -28
  60. package/dist/retriever/vector-retriever.d.ts.map +1 -1
  61. package/dist/retriever/vector-retriever.js +57 -59
  62. package/dist/types.d.ts +34 -39
  63. package/dist/types.d.ts.map +1 -1
  64. package/dist/types.js +1 -0
  65. package/package.json +152 -45
  66. package/dist/access/guard.js.map +0 -1
  67. package/dist/ingestion/document-processor.js.map +0 -1
  68. package/dist/ingestion/embedding-service.js.map +0 -1
  69. package/dist/ingestion/gmail-adapter.js.map +0 -1
  70. package/dist/ingestion/storage-adapter.js.map +0 -1
  71. package/dist/ingestion/vector-indexer.js.map +0 -1
  72. package/dist/query/service.js.map +0 -1
  73. package/dist/retriever/static-retriever.js.map +0 -1
  74. package/dist/retriever/vector-retriever.js.map +0 -1
@@ -1,48 +1,44 @@
1
- //#region src/retriever/static-retriever.ts
2
- /**
3
- * A simple in-memory retriever for static knowledge content.
4
- *
5
- * Useful for:
6
- * - Required knowledge that doesn't need semantic search
7
- * - Testing and development
8
- * - Small knowledge bases that fit in memory
9
- */
10
- var StaticRetriever = class {
11
- content;
12
- constructor(config) {
13
- this.content = config.content instanceof Map ? config.content : new Map(Object.entries(config.content));
14
- }
15
- async retrieve(query, options) {
16
- const content = this.content.get(options.spaceKey);
17
- if (!content) return [];
18
- const queryLower = query.toLowerCase();
19
- const lines = content.split("\n").filter((line) => line.trim());
20
- const results = [];
21
- for (const line of lines) if (line.toLowerCase().includes(queryLower)) results.push({
22
- content: line,
23
- source: options.spaceKey,
24
- score: 1,
25
- metadata: { type: "static" }
26
- });
27
- return results.slice(0, options.topK ?? 5);
28
- }
29
- async getStatic(spaceKey) {
30
- return this.content.get(spaceKey) ?? null;
31
- }
32
- supportsSpace(spaceKey) {
33
- return this.content.has(spaceKey);
34
- }
35
- listSpaces() {
36
- return [...this.content.keys()];
37
- }
38
- };
39
- /**
40
- * Create a static retriever from a content map.
41
- */
1
+ // @bun
2
+ // src/retriever/static-retriever.ts
3
+ class StaticRetriever {
4
+ content;
5
+ constructor(config) {
6
+ this.content = config.content instanceof Map ? config.content : new Map(Object.entries(config.content));
7
+ }
8
+ async retrieve(query, options) {
9
+ const content = this.content.get(options.spaceKey);
10
+ if (!content)
11
+ return [];
12
+ const queryLower = query.toLowerCase();
13
+ const lines = content.split(`
14
+ `).filter((line) => line.trim());
15
+ const results = [];
16
+ for (const line of lines) {
17
+ if (line.toLowerCase().includes(queryLower)) {
18
+ results.push({
19
+ content: line,
20
+ source: options.spaceKey,
21
+ score: 1,
22
+ metadata: { type: "static" }
23
+ });
24
+ }
25
+ }
26
+ return results.slice(0, options.topK ?? 5);
27
+ }
28
+ async getStatic(spaceKey) {
29
+ return this.content.get(spaceKey) ?? null;
30
+ }
31
+ supportsSpace(spaceKey) {
32
+ return this.content.has(spaceKey);
33
+ }
34
+ listSpaces() {
35
+ return [...this.content.keys()];
36
+ }
37
+ }
42
38
  function createStaticRetriever(content) {
43
- return new StaticRetriever({ content });
39
+ return new StaticRetriever({ content });
44
40
  }
45
-
46
- //#endregion
47
- export { StaticRetriever, createStaticRetriever };
48
- //# sourceMappingURL=static-retriever.js.map
41
+ export {
42
+ createStaticRetriever,
43
+ StaticRetriever
44
+ };
@@ -1,21 +1,18 @@
1
- import { RetrievalOptions, RetrievalResult } from "../types.js";
2
- import { KnowledgeRetriever, RetrieverConfig } from "./interface.js";
3
- import { EmbeddingProvider, VectorStoreProvider } from "@contractspec/lib.contracts";
4
-
5
- //#region src/retriever/vector-retriever.d.ts
6
-
1
+ import type { EmbeddingProvider, VectorStoreProvider } from '@contractspec/lib.contracts';
2
+ import type { RetrievalResult, RetrievalOptions } from '../types';
3
+ import type { KnowledgeRetriever, RetrieverConfig } from './interface';
7
4
  /**
8
5
  * Configuration for the vector retriever.
9
6
  */
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>;
7
+ export interface VectorRetrieverConfig extends RetrieverConfig {
8
+ /** Embedding provider for query vectorization */
9
+ embeddings: EmbeddingProvider;
10
+ /** Vector store provider for similarity search */
11
+ vectorStore: VectorStoreProvider;
12
+ /** Map of space key to collection name */
13
+ spaceCollections: Map<string, string> | Record<string, string>;
14
+ /** Optional static content for getStatic() calls */
15
+ staticContent?: Map<string, string> | Record<string, string>;
19
16
  }
20
17
  /**
21
18
  * A retriever that uses vector similarity search.
@@ -23,21 +20,19 @@ interface VectorRetrieverConfig extends RetrieverConfig {
23
20
  * Uses embedding provider to vectorize queries and vector store
24
21
  * provider to perform similarity search.
25
22
  */
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;
23
+ export declare class VectorRetriever implements KnowledgeRetriever {
24
+ private readonly config;
25
+ private readonly spaceCollections;
26
+ private readonly staticContent;
27
+ constructor(config: VectorRetrieverConfig);
28
+ retrieve(query: string, options: RetrievalOptions): Promise<RetrievalResult[]>;
29
+ getStatic(spaceKey: string): Promise<string | null>;
30
+ supportsSpace(spaceKey: string): boolean;
31
+ listSpaces(): string[];
32
+ private extractContent;
36
33
  }
37
34
  /**
38
35
  * Create a vector retriever from configuration.
39
36
  */
40
- declare function createVectorRetriever(config: VectorRetrieverConfig): VectorRetriever;
41
- //#endregion
42
- export { VectorRetriever, VectorRetrieverConfig, createVectorRetriever };
37
+ export declare function createVectorRetriever(config: VectorRetrieverConfig): VectorRetriever;
43
38
  //# sourceMappingURL=vector-retriever.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vector-retriever.d.ts","names":[],"sources":["../../src/retriever/vector-retriever.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAUA;AAEc,UAFG,qBAAA,SAA8B,eAEjC,CAAA;EAEC;EAEK,UAAA,EAJN,iBAIM;EAAsB;EAExB,WAAA,EAJH,mBAIG;EAAsB;EARO,gBAAA,EAM3B,GAN2B,CAAA,MAAA,EAAA,MAAA,CAAA,GAML,MANK,CAAA,MAAA,EAAA,MAAA,CAAA;EAAe;EAiBjD,aAAA,CAAA,EATK,GASW,CAAA,MAAA,EAAA,MAAA,CAAA,GATW,MASX,CAAA,MAAA,EAAA,MAAA,CAAA;;;;;;;;AA2Eb,cA3EH,eAAA,YAA2B,kBA6ErC,CAAA;;;;sBAxEmB;mCAeT,mBACR,QAAQ;+BA+BwB;;;;;;;;iBAuBrB,qBAAA,SACN,wBACP"}
1
+ {"version":3,"file":"vector-retriever.d.ts","sourceRoot":"","sources":["../../src/retriever/vector-retriever.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,iDAAiD;IACjD,UAAU,EAAE,iBAAiB,CAAC;IAC9B,kDAAkD;IAClD,WAAW,EAAE,mBAAmB,CAAC;IACjC,0CAA0C;IAC1C,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/D,oDAAoD;IACpD,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9D;AAED;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,kBAAkB;IACxD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;IAC/C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAsB;IACvD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsB;gBAExC,MAAM,EAAE,qBAAqB;IAanC,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,EAAE,CAAC;IA+BvB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIzD,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIxC,UAAU,IAAI,MAAM,EAAE;IAItB,OAAO,CAAC,cAAc;CAMvB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,qBAAqB,GAC5B,eAAe,CAEjB"}
@@ -1,61 +1,59 @@
1
- //#region src/retriever/vector-retriever.ts
2
- /**
3
- * A retriever that uses vector similarity search.
4
- *
5
- * Uses embedding provider to vectorize queries and vector store
6
- * provider to perform similarity search.
7
- */
8
- var VectorRetriever = class {
9
- config;
10
- spaceCollections;
11
- staticContent;
12
- constructor(config) {
13
- this.config = config;
14
- this.spaceCollections = config.spaceCollections instanceof Map ? config.spaceCollections : new Map(Object.entries(config.spaceCollections));
15
- this.staticContent = config.staticContent ? config.staticContent instanceof Map ? config.staticContent : new Map(Object.entries(config.staticContent)) : /* @__PURE__ */ new Map();
16
- }
17
- async retrieve(query, options) {
18
- const collection = this.spaceCollections.get(options.spaceKey);
19
- if (!collection) return [];
20
- const embedding = await this.config.embeddings.embedQuery(query);
21
- const results = await this.config.vectorStore.search({
22
- collection,
23
- vector: embedding.vector,
24
- topK: options.topK ?? this.config.defaultTopK ?? 5,
25
- namespace: options.tenantId,
26
- filter: options.filter
27
- });
28
- const minScore = options.minScore ?? this.config.defaultMinScore ?? 0;
29
- return results.filter((r) => r.score >= minScore).map((result) => ({
30
- content: this.extractContent(result.payload),
31
- source: result.id,
32
- score: result.score,
33
- metadata: result.payload
34
- }));
35
- }
36
- async getStatic(spaceKey) {
37
- return this.staticContent.get(spaceKey) ?? null;
38
- }
39
- supportsSpace(spaceKey) {
40
- return this.spaceCollections.has(spaceKey);
41
- }
42
- listSpaces() {
43
- return [...this.spaceCollections.keys()];
44
- }
45
- extractContent(payload) {
46
- if (!payload) return "";
47
- if (typeof payload.text === "string") return payload.text;
48
- if (typeof payload.content === "string") return payload.content;
49
- return JSON.stringify(payload);
50
- }
51
- };
52
- /**
53
- * Create a vector retriever from configuration.
54
- */
1
+ // @bun
2
+ // src/retriever/vector-retriever.ts
3
+ class VectorRetriever {
4
+ config;
5
+ spaceCollections;
6
+ staticContent;
7
+ constructor(config) {
8
+ this.config = config;
9
+ this.spaceCollections = config.spaceCollections instanceof Map ? config.spaceCollections : new Map(Object.entries(config.spaceCollections));
10
+ this.staticContent = config.staticContent ? config.staticContent instanceof Map ? config.staticContent : new Map(Object.entries(config.staticContent)) : new Map;
11
+ }
12
+ async retrieve(query, options) {
13
+ const collection = this.spaceCollections.get(options.spaceKey);
14
+ if (!collection) {
15
+ return [];
16
+ }
17
+ const embedding = await this.config.embeddings.embedQuery(query);
18
+ const results = await this.config.vectorStore.search({
19
+ collection,
20
+ vector: embedding.vector,
21
+ topK: options.topK ?? this.config.defaultTopK ?? 5,
22
+ namespace: options.tenantId,
23
+ filter: options.filter
24
+ });
25
+ const minScore = options.minScore ?? this.config.defaultMinScore ?? 0;
26
+ const filtered = results.filter((r) => r.score >= minScore);
27
+ return filtered.map((result) => ({
28
+ content: this.extractContent(result.payload),
29
+ source: result.id,
30
+ score: result.score,
31
+ metadata: result.payload
32
+ }));
33
+ }
34
+ async getStatic(spaceKey) {
35
+ return this.staticContent.get(spaceKey) ?? null;
36
+ }
37
+ supportsSpace(spaceKey) {
38
+ return this.spaceCollections.has(spaceKey);
39
+ }
40
+ listSpaces() {
41
+ return [...this.spaceCollections.keys()];
42
+ }
43
+ extractContent(payload) {
44
+ if (!payload)
45
+ return "";
46
+ if (typeof payload.text === "string")
47
+ return payload.text;
48
+ if (typeof payload.content === "string")
49
+ return payload.content;
50
+ return JSON.stringify(payload);
51
+ }
52
+ }
55
53
  function createVectorRetriever(config) {
56
- return new VectorRetriever(config);
54
+ return new VectorRetriever(config);
57
55
  }
58
-
59
- //#endregion
60
- export { VectorRetriever, createVectorRetriever };
61
- //# sourceMappingURL=vector-retriever.js.map
56
+ export {
57
+ createVectorRetriever,
58
+ VectorRetriever
59
+ };
package/dist/types.d.ts CHANGED
@@ -1,56 +1,51 @@
1
- import { KnowledgeCategory } from "@contractspec/lib.contracts";
2
-
3
- //#region src/types.d.ts
4
-
1
+ import type { KnowledgeCategory } from '@contractspec/lib.contracts';
5
2
  /**
6
3
  * Result from a knowledge retrieval operation.
7
4
  */
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>;
5
+ export interface RetrievalResult {
6
+ /** The retrieved content/text */
7
+ content: string;
8
+ /** Source identifier (document ID, URL, etc.) */
9
+ source: string;
10
+ /** Relevance score (0-1, higher is more relevant) */
11
+ score: number;
12
+ /** Additional metadata about the result */
13
+ metadata?: Record<string, unknown>;
17
14
  }
18
15
  /**
19
16
  * Options for knowledge retrieval.
20
17
  */
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>;
18
+ export interface RetrievalOptions {
19
+ /** Knowledge space key to query */
20
+ spaceKey: string;
21
+ /** Maximum number of results to return */
22
+ topK?: number;
23
+ /** Minimum relevance score threshold */
24
+ minScore?: number;
25
+ /** Filter by knowledge category */
26
+ category?: KnowledgeCategory;
27
+ /** Tenant-scoped retrieval */
28
+ tenantId?: string;
29
+ /** Additional filter criteria */
30
+ filter?: Record<string, unknown>;
34
31
  }
35
32
  /**
36
33
  * Context for knowledge access operations.
37
34
  */
38
- interface KnowledgeAccessContext {
39
- tenantId: string;
40
- appId: string;
41
- environment?: string;
42
- workflowName?: string;
43
- agentName?: string;
44
- operation: 'read' | 'write' | 'search';
35
+ export interface KnowledgeAccessContext {
36
+ tenantId: string;
37
+ appId: string;
38
+ environment?: string;
39
+ workflowName?: string;
40
+ agentName?: string;
41
+ operation: 'read' | 'write' | 'search';
45
42
  }
46
43
  /**
47
44
  * Result of an access check.
48
45
  */
49
- interface KnowledgeAccessResult {
50
- allowed: boolean;
51
- reason?: string;
52
- severity?: 'error' | 'warning';
46
+ export interface KnowledgeAccessResult {
47
+ allowed: boolean;
48
+ reason?: string;
49
+ severity?: 'error' | 'warning';
53
50
  }
54
- //#endregion
55
- export { KnowledgeAccessContext, KnowledgeAccessResult, RetrievalOptions, RetrievalResult };
56
51
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAciB,UAdA,eAAA,CAcgB;EAkBhB;EAYA,OAAA,EAAA,MAAA;;;;;;aApCJ;;;;;UAMI,gBAAA;;;;;;;;aAQJ;;;;WAIF;;;;;UAMM,sBAAA;;;;;;;;;;;UAYA,qBAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC"}
package/dist/types.js CHANGED
@@ -0,0 +1 @@
1
+ // @bun
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractspec/lib.knowledge",
3
- "version": "1.56.1",
3
+ "version": "1.58.0",
4
4
  "description": "RAG and knowledge base primitives",
5
5
  "keywords": [
6
6
  "contractspec",
@@ -18,64 +18,171 @@
18
18
  "scripts": {
19
19
  "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
20
20
  "publish:pkg:canary": "bun publish:pkg --tag canary",
21
- "build": "bun build:types && bun build:bundle",
22
- "build:bundle": "tsdown",
23
- "build:types": "tsc --noEmit",
24
- "dev": "bun build:bundle --watch",
21
+ "build": "bun run prebuild && bun run build:bundle && bun run build:types",
22
+ "build:bundle": "contractspec-bun-build transpile",
23
+ "build:types": "contractspec-bun-build types",
24
+ "dev": "contractspec-bun-build dev",
25
25
  "clean": "rimraf dist .turbo",
26
26
  "lint": "bun lint:fix",
27
27
  "lint:fix": "eslint src --fix",
28
28
  "lint:check": "eslint src",
29
- "test": "bun test"
29
+ "test": "bun test",
30
+ "prebuild": "contractspec-bun-build prebuild",
31
+ "typecheck": "tsc --noEmit"
30
32
  },
31
33
  "dependencies": {
32
- "@contractspec/lib.contracts": "1.56.1"
34
+ "@contractspec/lib.contracts": "1.58.0"
33
35
  },
34
36
  "devDependencies": {
35
- "@contractspec/tool.tsdown": "1.56.1",
36
- "@contractspec/tool.typescript": "1.56.1",
37
- "tsdown": "^0.19.0",
38
- "typescript": "^5.9.3"
37
+ "@contractspec/tool.typescript": "1.58.0",
38
+ "typescript": "^5.9.3",
39
+ "@contractspec/tool.bun": "1.57.0"
39
40
  },
40
41
  "exports": {
41
- ".": "./dist/index.js",
42
- "./access": "./dist/access/index.js",
43
- "./access/guard": "./dist/access/guard.js",
44
- "./ingestion": "./dist/ingestion/index.js",
45
- "./ingestion/document-processor": "./dist/ingestion/document-processor.js",
46
- "./ingestion/embedding-service": "./dist/ingestion/embedding-service.js",
47
- "./ingestion/gmail-adapter": "./dist/ingestion/gmail-adapter.js",
48
- "./ingestion/storage-adapter": "./dist/ingestion/storage-adapter.js",
49
- "./ingestion/vector-indexer": "./dist/ingestion/vector-indexer.js",
50
- "./query": "./dist/query/index.js",
51
- "./query/service": "./dist/query/service.js",
52
- "./retriever": "./dist/retriever/index.js",
53
- "./retriever/interface": "./dist/retriever/interface.js",
54
- "./retriever/static-retriever": "./dist/retriever/static-retriever.js",
55
- "./retriever/vector-retriever": "./dist/retriever/vector-retriever.js",
56
- "./types": "./dist/types.js",
57
- "./*": "./*"
42
+ ".": "./src/index.ts",
43
+ "./access": "./src/access/index.ts",
44
+ "./access/guard": "./src/access/guard.ts",
45
+ "./access/index": "./src/access/index.ts",
46
+ "./ingestion": "./src/ingestion/index.ts",
47
+ "./ingestion/document-processor": "./src/ingestion/document-processor.ts",
48
+ "./ingestion/embedding-service": "./src/ingestion/embedding-service.ts",
49
+ "./ingestion/gmail-adapter": "./src/ingestion/gmail-adapter.ts",
50
+ "./ingestion/index": "./src/ingestion/index.ts",
51
+ "./ingestion/storage-adapter": "./src/ingestion/storage-adapter.ts",
52
+ "./ingestion/vector-indexer": "./src/ingestion/vector-indexer.ts",
53
+ "./query": "./src/query/index.ts",
54
+ "./query/index": "./src/query/index.ts",
55
+ "./query/service": "./src/query/service.ts",
56
+ "./retriever": "./src/retriever/index.ts",
57
+ "./retriever/index": "./src/retriever/index.ts",
58
+ "./retriever/interface": "./src/retriever/interface.ts",
59
+ "./retriever/static-retriever": "./src/retriever/static-retriever.ts",
60
+ "./retriever/vector-retriever": "./src/retriever/vector-retriever.ts",
61
+ "./types": "./src/types.ts"
58
62
  },
59
63
  "publishConfig": {
60
64
  "access": "public",
61
65
  "exports": {
62
- ".": "./dist/index.js",
63
- "./access": "./dist/access/index.js",
64
- "./access/guard": "./dist/access/guard.js",
65
- "./ingestion": "./dist/ingestion/index.js",
66
- "./ingestion/document-processor": "./dist/ingestion/document-processor.js",
67
- "./ingestion/embedding-service": "./dist/ingestion/embedding-service.js",
68
- "./ingestion/gmail-adapter": "./dist/ingestion/gmail-adapter.js",
69
- "./ingestion/storage-adapter": "./dist/ingestion/storage-adapter.js",
70
- "./ingestion/vector-indexer": "./dist/ingestion/vector-indexer.js",
71
- "./query": "./dist/query/index.js",
72
- "./query/service": "./dist/query/service.js",
73
- "./retriever": "./dist/retriever/index.js",
74
- "./retriever/interface": "./dist/retriever/interface.js",
75
- "./retriever/static-retriever": "./dist/retriever/static-retriever.js",
76
- "./retriever/vector-retriever": "./dist/retriever/vector-retriever.js",
77
- "./types": "./dist/types.js",
78
- "./*": "./*"
66
+ ".": {
67
+ "types": "./dist/index.d.ts",
68
+ "bun": "./dist/index.js",
69
+ "node": "./dist/node/index.mjs",
70
+ "default": "./dist/index.js"
71
+ },
72
+ "./access": {
73
+ "types": "./dist/access/index.d.ts",
74
+ "bun": "./dist/access/index.js",
75
+ "node": "./dist/node/access/index.mjs",
76
+ "default": "./dist/access/index.js"
77
+ },
78
+ "./access/guard": {
79
+ "types": "./dist/access/guard.d.ts",
80
+ "bun": "./dist/access/guard.js",
81
+ "node": "./dist/node/access/guard.mjs",
82
+ "default": "./dist/access/guard.js"
83
+ },
84
+ "./access/index": {
85
+ "types": "./dist/access/index.d.ts",
86
+ "bun": "./dist/access/index.js",
87
+ "node": "./dist/node/access/index.mjs",
88
+ "default": "./dist/access/index.js"
89
+ },
90
+ "./ingestion": {
91
+ "types": "./dist/ingestion/index.d.ts",
92
+ "bun": "./dist/ingestion/index.js",
93
+ "node": "./dist/node/ingestion/index.mjs",
94
+ "default": "./dist/ingestion/index.js"
95
+ },
96
+ "./ingestion/document-processor": {
97
+ "types": "./dist/ingestion/document-processor.d.ts",
98
+ "bun": "./dist/ingestion/document-processor.js",
99
+ "node": "./dist/node/ingestion/document-processor.mjs",
100
+ "default": "./dist/ingestion/document-processor.js"
101
+ },
102
+ "./ingestion/embedding-service": {
103
+ "types": "./dist/ingestion/embedding-service.d.ts",
104
+ "bun": "./dist/ingestion/embedding-service.js",
105
+ "node": "./dist/node/ingestion/embedding-service.mjs",
106
+ "default": "./dist/ingestion/embedding-service.js"
107
+ },
108
+ "./ingestion/gmail-adapter": {
109
+ "types": "./dist/ingestion/gmail-adapter.d.ts",
110
+ "bun": "./dist/ingestion/gmail-adapter.js",
111
+ "node": "./dist/node/ingestion/gmail-adapter.mjs",
112
+ "default": "./dist/ingestion/gmail-adapter.js"
113
+ },
114
+ "./ingestion/index": {
115
+ "types": "./dist/ingestion/index.d.ts",
116
+ "bun": "./dist/ingestion/index.js",
117
+ "node": "./dist/node/ingestion/index.mjs",
118
+ "default": "./dist/ingestion/index.js"
119
+ },
120
+ "./ingestion/storage-adapter": {
121
+ "types": "./dist/ingestion/storage-adapter.d.ts",
122
+ "bun": "./dist/ingestion/storage-adapter.js",
123
+ "node": "./dist/node/ingestion/storage-adapter.mjs",
124
+ "default": "./dist/ingestion/storage-adapter.js"
125
+ },
126
+ "./ingestion/vector-indexer": {
127
+ "types": "./dist/ingestion/vector-indexer.d.ts",
128
+ "bun": "./dist/ingestion/vector-indexer.js",
129
+ "node": "./dist/node/ingestion/vector-indexer.mjs",
130
+ "default": "./dist/ingestion/vector-indexer.js"
131
+ },
132
+ "./query": {
133
+ "types": "./dist/query/index.d.ts",
134
+ "bun": "./dist/query/index.js",
135
+ "node": "./dist/node/query/index.mjs",
136
+ "default": "./dist/query/index.js"
137
+ },
138
+ "./query/index": {
139
+ "types": "./dist/query/index.d.ts",
140
+ "bun": "./dist/query/index.js",
141
+ "node": "./dist/node/query/index.mjs",
142
+ "default": "./dist/query/index.js"
143
+ },
144
+ "./query/service": {
145
+ "types": "./dist/query/service.d.ts",
146
+ "bun": "./dist/query/service.js",
147
+ "node": "./dist/node/query/service.mjs",
148
+ "default": "./dist/query/service.js"
149
+ },
150
+ "./retriever": {
151
+ "types": "./dist/retriever/index.d.ts",
152
+ "bun": "./dist/retriever/index.js",
153
+ "node": "./dist/node/retriever/index.mjs",
154
+ "default": "./dist/retriever/index.js"
155
+ },
156
+ "./retriever/index": {
157
+ "types": "./dist/retriever/index.d.ts",
158
+ "bun": "./dist/retriever/index.js",
159
+ "node": "./dist/node/retriever/index.mjs",
160
+ "default": "./dist/retriever/index.js"
161
+ },
162
+ "./retriever/interface": {
163
+ "types": "./dist/retriever/interface.d.ts",
164
+ "bun": "./dist/retriever/interface.js",
165
+ "node": "./dist/node/retriever/interface.mjs",
166
+ "default": "./dist/retriever/interface.js"
167
+ },
168
+ "./retriever/static-retriever": {
169
+ "types": "./dist/retriever/static-retriever.d.ts",
170
+ "bun": "./dist/retriever/static-retriever.js",
171
+ "node": "./dist/node/retriever/static-retriever.mjs",
172
+ "default": "./dist/retriever/static-retriever.js"
173
+ },
174
+ "./retriever/vector-retriever": {
175
+ "types": "./dist/retriever/vector-retriever.d.ts",
176
+ "bun": "./dist/retriever/vector-retriever.js",
177
+ "node": "./dist/node/retriever/vector-retriever.mjs",
178
+ "default": "./dist/retriever/vector-retriever.js"
179
+ },
180
+ "./types": {
181
+ "types": "./dist/types.d.ts",
182
+ "bun": "./dist/types.js",
183
+ "node": "./dist/node/types.mjs",
184
+ "default": "./dist/types.js"
185
+ }
79
186
  },
80
187
  "registry": "https://registry.npmjs.org/"
81
188
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"guard.js","names":[],"sources":["../../src/access/guard.ts"],"sourcesContent":["import type {\n ResolvedAppConfig,\n ResolvedKnowledge,\n KnowledgeCategory,\n} from '@contractspec/lib.contracts';\nimport type { KnowledgeAccessContext, KnowledgeAccessResult } from '../types';\n\nexport interface KnowledgeAccessGuardOptions {\n disallowWriteCategories?: KnowledgeCategory[];\n requireWorkflowBinding?: boolean;\n requireAgentBinding?: boolean;\n}\n\nconst DEFAULT_DISALLOWED_WRITE: KnowledgeCategory[] = ['external', 'ephemeral'];\n\nexport class KnowledgeAccessGuard {\n private readonly disallowedWrite: Set<KnowledgeCategory>;\n private readonly requireWorkflowBinding: boolean;\n private readonly requireAgentBinding: boolean;\n\n constructor(options: KnowledgeAccessGuardOptions = {}) {\n this.disallowedWrite = new Set(\n options.disallowWriteCategories ?? DEFAULT_DISALLOWED_WRITE\n );\n this.requireWorkflowBinding = options.requireWorkflowBinding ?? true;\n this.requireAgentBinding = options.requireAgentBinding ?? false;\n }\n\n checkAccess(\n spaceBinding: ResolvedKnowledge,\n context: KnowledgeAccessContext,\n appConfig: ResolvedAppConfig\n ): KnowledgeAccessResult {\n const { binding, space } = spaceBinding;\n\n if (\n binding.required !== false &&\n !this.isSpaceBound(spaceBinding, appConfig)\n ) {\n return {\n allowed: false,\n reason: `Knowledge space \"${space.meta.key}\" is not bound in the resolved app config.`,\n };\n }\n\n if (\n context.operation === 'write' &&\n this.disallowedWrite.has(space.meta.category)\n ) {\n return {\n allowed: false,\n reason: `Knowledge space \"${space.meta.key}\" is category \"${space.meta.category}\" and is read-only.`,\n };\n }\n\n if (this.requireWorkflowBinding && context.workflowName) {\n const allowedWorkflows = binding.scope?.workflows;\n if (\n allowedWorkflows &&\n !allowedWorkflows.includes(context.workflowName)\n ) {\n return {\n allowed: false,\n reason: `Workflow \"${context.workflowName}\" is not authorized to access knowledge space \"${space.meta.key}\".`,\n };\n }\n }\n\n if (this.requireAgentBinding && context.agentName) {\n const allowedAgents = binding.scope?.agents;\n if (allowedAgents && !allowedAgents.includes(context.agentName)) {\n return {\n allowed: false,\n reason: `Agent \"${context.agentName}\" is not authorized to access knowledge space \"${space.meta.key}\".`,\n };\n }\n }\n\n if (space.meta.category === 'ephemeral') {\n return {\n allowed: true,\n severity: 'warning',\n reason: `Knowledge space \"${space.meta.key}\" is ephemeral; results may be transient.`,\n };\n }\n\n return { allowed: true };\n }\n\n private isSpaceBound(\n resolved: ResolvedKnowledge,\n appConfig: ResolvedAppConfig\n ): boolean {\n return appConfig.knowledge.some(\n (entry) =>\n entry.space.meta.key === resolved.space.meta.key &&\n (resolved.space.meta.version == null ||\n entry.space.meta.version === resolved.space.meta.version)\n );\n }\n}\n"],"mappings":";AAaA,MAAM,2BAAgD,CAAC,YAAY,YAAY;AAE/E,IAAa,uBAAb,MAAkC;CAChC,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,YAAY,UAAuC,EAAE,EAAE;AACrD,OAAK,kBAAkB,IAAI,IACzB,QAAQ,2BAA2B,yBACpC;AACD,OAAK,yBAAyB,QAAQ,0BAA0B;AAChE,OAAK,sBAAsB,QAAQ,uBAAuB;;CAG5D,YACE,cACA,SACA,WACuB;EACvB,MAAM,EAAE,SAAS,UAAU;AAE3B,MACE,QAAQ,aAAa,SACrB,CAAC,KAAK,aAAa,cAAc,UAAU,CAE3C,QAAO;GACL,SAAS;GACT,QAAQ,oBAAoB,MAAM,KAAK,IAAI;GAC5C;AAGH,MACE,QAAQ,cAAc,WACtB,KAAK,gBAAgB,IAAI,MAAM,KAAK,SAAS,CAE7C,QAAO;GACL,SAAS;GACT,QAAQ,oBAAoB,MAAM,KAAK,IAAI,iBAAiB,MAAM,KAAK,SAAS;GACjF;AAGH,MAAI,KAAK,0BAA0B,QAAQ,cAAc;GACvD,MAAM,mBAAmB,QAAQ,OAAO;AACxC,OACE,oBACA,CAAC,iBAAiB,SAAS,QAAQ,aAAa,CAEhD,QAAO;IACL,SAAS;IACT,QAAQ,aAAa,QAAQ,aAAa,iDAAiD,MAAM,KAAK,IAAI;IAC3G;;AAIL,MAAI,KAAK,uBAAuB,QAAQ,WAAW;GACjD,MAAM,gBAAgB,QAAQ,OAAO;AACrC,OAAI,iBAAiB,CAAC,cAAc,SAAS,QAAQ,UAAU,CAC7D,QAAO;IACL,SAAS;IACT,QAAQ,UAAU,QAAQ,UAAU,iDAAiD,MAAM,KAAK,IAAI;IACrG;;AAIL,MAAI,MAAM,KAAK,aAAa,YAC1B,QAAO;GACL,SAAS;GACT,UAAU;GACV,QAAQ,oBAAoB,MAAM,KAAK,IAAI;GAC5C;AAGH,SAAO,EAAE,SAAS,MAAM;;CAG1B,AAAQ,aACN,UACA,WACS;AACT,SAAO,UAAU,UAAU,MACxB,UACC,MAAM,MAAM,KAAK,QAAQ,SAAS,MAAM,KAAK,QAC5C,SAAS,MAAM,KAAK,WAAW,QAC9B,MAAM,MAAM,KAAK,YAAY,SAAS,MAAM,KAAK,SACtD"}