@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.
- package/dist/access/guard.d.ts +13 -17
- package/dist/access/guard.d.ts.map +1 -1
- package/dist/access/guard.js +60 -49
- package/dist/access/index.d.ts +2 -2
- package/dist/access/index.d.ts.map +1 -0
- package/dist/access/index.js +60 -2
- package/dist/index.d.ts +6 -12
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +455 -12
- package/dist/ingestion/document-processor.d.ts +18 -20
- package/dist/ingestion/document-processor.d.ts.map +1 -1
- package/dist/ingestion/document-processor.js +63 -53
- package/dist/ingestion/embedding-service.d.ts +7 -11
- package/dist/ingestion/embedding-service.d.ts.map +1 -1
- package/dist/ingestion/embedding-service.js +26 -25
- package/dist/ingestion/gmail-adapter.d.ts +13 -17
- package/dist/ingestion/gmail-adapter.d.ts.map +1 -1
- package/dist/ingestion/gmail-adapter.js +67 -46
- package/dist/ingestion/index.d.ts +6 -6
- package/dist/ingestion/index.d.ts.map +1 -0
- package/dist/ingestion/index.js +221 -6
- package/dist/ingestion/storage-adapter.d.ts +10 -14
- package/dist/ingestion/storage-adapter.d.ts.map +1 -1
- package/dist/ingestion/storage-adapter.js +31 -26
- package/dist/ingestion/vector-indexer.d.ts +11 -15
- package/dist/ingestion/vector-indexer.d.ts.map +1 -1
- package/dist/ingestion/vector-indexer.js +32 -32
- package/dist/node/access/guard.js +60 -0
- package/dist/node/access/index.js +60 -0
- package/dist/node/index.js +454 -0
- package/dist/node/ingestion/document-processor.js +64 -0
- package/dist/node/ingestion/embedding-service.js +26 -0
- package/dist/node/ingestion/gmail-adapter.js +72 -0
- package/dist/node/ingestion/index.js +221 -0
- package/dist/node/ingestion/storage-adapter.js +31 -0
- package/dist/node/ingestion/vector-indexer.js +32 -0
- package/dist/node/query/index.js +79 -0
- package/dist/node/query/service.js +79 -0
- package/dist/node/retriever/index.js +100 -0
- package/dist/node/retriever/interface.js +0 -0
- package/dist/node/retriever/static-retriever.js +43 -0
- package/dist/node/retriever/vector-retriever.js +58 -0
- package/dist/node/types.js +0 -0
- package/dist/query/index.d.ts +2 -2
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +79 -2
- package/dist/query/service.d.ts +20 -24
- package/dist/query/service.d.ts.map +1 -1
- package/dist/query/service.js +76 -62
- package/dist/retriever/index.d.ts +4 -4
- package/dist/retriever/index.d.ts.map +1 -0
- package/dist/retriever/index.js +100 -3
- package/dist/retriever/interface.d.ts +38 -43
- package/dist/retriever/interface.d.ts.map +1 -1
- package/dist/retriever/interface.js +1 -0
- package/dist/retriever/static-retriever.d.ts +13 -18
- package/dist/retriever/static-retriever.d.ts.map +1 -1
- package/dist/retriever/static-retriever.js +42 -46
- package/dist/retriever/vector-retriever.d.ts +23 -28
- package/dist/retriever/vector-retriever.d.ts.map +1 -1
- package/dist/retriever/vector-retriever.js +57 -59
- package/dist/types.d.ts +34 -39
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +152 -45
- package/dist/access/guard.js.map +0 -1
- package/dist/ingestion/document-processor.js.map +0 -1
- package/dist/ingestion/embedding-service.js.map +0 -1
- package/dist/ingestion/gmail-adapter.js.map +0 -1
- package/dist/ingestion/storage-adapter.js.map +0 -1
- package/dist/ingestion/vector-indexer.js.map +0 -1
- package/dist/query/service.js.map +0 -1
- package/dist/retriever/static-retriever.js.map +0 -1
- package/dist/retriever/vector-retriever.js.map +0 -1
|
@@ -1,48 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
39
|
+
return new StaticRetriever({ content });
|
|
44
40
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
export {
|
|
42
|
+
createStaticRetriever,
|
|
43
|
+
StaticRetriever
|
|
44
|
+
};
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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","
|
|
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,EA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39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
54
|
+
return new VectorRetriever(config);
|
|
57
55
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
export {
|
|
57
|
+
createVectorRetriever,
|
|
58
|
+
VectorRetriever
|
|
59
|
+
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,56 +1,51 @@
|
|
|
1
|
-
import { KnowledgeCategory } from
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","
|
|
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.
|
|
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:
|
|
22
|
-
"build:bundle": "
|
|
23
|
-
"build:types": "
|
|
24
|
-
"dev": "bun
|
|
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.
|
|
34
|
+
"@contractspec/lib.contracts": "1.58.0"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
35
|
-
"@contractspec/tool.
|
|
36
|
-
"
|
|
37
|
-
"
|
|
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
|
-
".": "./
|
|
42
|
-
"./access": "./
|
|
43
|
-
"./access/guard": "./
|
|
44
|
-
"./
|
|
45
|
-
"./ingestion
|
|
46
|
-
"./ingestion/
|
|
47
|
-
"./ingestion/
|
|
48
|
-
"./ingestion/
|
|
49
|
-
"./ingestion/
|
|
50
|
-
"./
|
|
51
|
-
"./
|
|
52
|
-
"./
|
|
53
|
-
"./
|
|
54
|
-
"./
|
|
55
|
-
"./retriever
|
|
56
|
-
"./
|
|
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
|
-
".":
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"./
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"./
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
},
|
package/dist/access/guard.js.map
DELETED
|
@@ -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,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