@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
@@ -0,0 +1,58 @@
1
+ // src/retriever/vector-retriever.ts
2
+ class VectorRetriever {
3
+ config;
4
+ spaceCollections;
5
+ staticContent;
6
+ constructor(config) {
7
+ this.config = config;
8
+ this.spaceCollections = config.spaceCollections instanceof Map ? config.spaceCollections : new Map(Object.entries(config.spaceCollections));
9
+ this.staticContent = config.staticContent ? config.staticContent instanceof Map ? config.staticContent : new Map(Object.entries(config.staticContent)) : new Map;
10
+ }
11
+ async retrieve(query, options) {
12
+ const collection = this.spaceCollections.get(options.spaceKey);
13
+ if (!collection) {
14
+ return [];
15
+ }
16
+ const embedding = await this.config.embeddings.embedQuery(query);
17
+ const results = await this.config.vectorStore.search({
18
+ collection,
19
+ vector: embedding.vector,
20
+ topK: options.topK ?? this.config.defaultTopK ?? 5,
21
+ namespace: options.tenantId,
22
+ filter: options.filter
23
+ });
24
+ const minScore = options.minScore ?? this.config.defaultMinScore ?? 0;
25
+ const filtered = results.filter((r) => r.score >= minScore);
26
+ return filtered.map((result) => ({
27
+ content: this.extractContent(result.payload),
28
+ source: result.id,
29
+ score: result.score,
30
+ metadata: result.payload
31
+ }));
32
+ }
33
+ async getStatic(spaceKey) {
34
+ return this.staticContent.get(spaceKey) ?? null;
35
+ }
36
+ supportsSpace(spaceKey) {
37
+ return this.spaceCollections.has(spaceKey);
38
+ }
39
+ listSpaces() {
40
+ return [...this.spaceCollections.keys()];
41
+ }
42
+ extractContent(payload) {
43
+ if (!payload)
44
+ return "";
45
+ if (typeof payload.text === "string")
46
+ return payload.text;
47
+ if (typeof payload.content === "string")
48
+ return payload.content;
49
+ return JSON.stringify(payload);
50
+ }
51
+ }
52
+ function createVectorRetriever(config) {
53
+ return new VectorRetriever(config);
54
+ }
55
+ export {
56
+ createVectorRetriever,
57
+ VectorRetriever
58
+ };
File without changes
@@ -1,2 +1,2 @@
1
- import { KnowledgeAnswer, KnowledgeQueryConfig, KnowledgeQueryService } from "./service.js";
2
- export { KnowledgeAnswer, KnowledgeQueryConfig, KnowledgeQueryService };
1
+ export * from './service';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/query/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -1,3 +1,80 @@
1
- import { KnowledgeQueryService } from "./service.js";
1
+ // @bun
2
+ // src/query/service.ts
3
+ class KnowledgeQueryService {
4
+ embeddings;
5
+ vectorStore;
6
+ llm;
7
+ config;
8
+ constructor(embeddings, vectorStore, llm, config) {
9
+ this.embeddings = embeddings;
10
+ this.vectorStore = vectorStore;
11
+ this.llm = llm;
12
+ this.config = config;
13
+ }
14
+ async query(question) {
15
+ const embedding = await this.embeddings.embedQuery(question);
16
+ const results = await this.vectorStore.search({
17
+ collection: this.config.collection,
18
+ vector: embedding.vector,
19
+ topK: this.config.topK ?? 5,
20
+ namespace: this.config.namespace,
21
+ filter: undefined
22
+ });
23
+ const context = buildContext(results);
24
+ const messages = this.buildMessages(question, context);
25
+ const response = await this.llm.chat(messages);
26
+ return {
27
+ answer: response.message.content.map((part) => ("text" in part) ? part.text : "").join(""),
28
+ references: results.map((result) => ({
29
+ ...result,
30
+ text: extractText(result)
31
+ })),
32
+ usage: response.usage
33
+ };
34
+ }
35
+ buildMessages(question, context) {
36
+ const systemPrompt = this.config.systemPrompt ?? "You are a knowledge assistant that answers questions using the provided context. Cite relevant sources if possible.";
37
+ return [
38
+ {
39
+ role: "system",
40
+ content: [{ type: "text", text: systemPrompt }]
41
+ },
42
+ {
43
+ role: "user",
44
+ content: [
45
+ {
46
+ type: "text",
47
+ text: `Question:
48
+ ${question}
2
49
 
3
- export { KnowledgeQueryService };
50
+ Context:
51
+ ${context}`
52
+ }
53
+ ]
54
+ }
55
+ ];
56
+ }
57
+ }
58
+ function buildContext(results) {
59
+ if (results.length === 0) {
60
+ return "No relevant documents found.";
61
+ }
62
+ return results.map((result, index) => {
63
+ const text = extractText(result);
64
+ return `Source ${index + 1} (score: ${result.score.toFixed(3)}):
65
+ ${text}`;
66
+ }).join(`
67
+
68
+ `);
69
+ }
70
+ function extractText(result) {
71
+ const payload = result.payload ?? {};
72
+ if (typeof payload.text === "string")
73
+ return payload.text;
74
+ if (typeof payload.content === "string")
75
+ return payload.content;
76
+ return JSON.stringify(payload);
77
+ }
78
+ export {
79
+ KnowledgeQueryService
80
+ };
@@ -1,28 +1,24 @@
1
- import { EmbeddingProvider, LLMProvider, LLMResponse, VectorSearchResult, VectorStoreProvider } from "@contractspec/lib.contracts";
2
-
3
- //#region src/query/service.d.ts
4
- interface KnowledgeQueryConfig {
5
- collection: string;
6
- namespace?: string;
7
- topK?: number;
8
- systemPrompt?: string;
1
+ import type { EmbeddingProvider, VectorStoreProvider, VectorSearchResult, LLMProvider, LLMResponse } from '@contractspec/lib.contracts';
2
+ export interface KnowledgeQueryConfig {
3
+ collection: string;
4
+ namespace?: string;
5
+ topK?: number;
6
+ systemPrompt?: string;
9
7
  }
10
- interface KnowledgeAnswer {
11
- answer: string;
12
- references: (VectorSearchResult & {
13
- text?: string;
14
- })[];
15
- usage?: LLMResponse['usage'];
8
+ export interface KnowledgeAnswer {
9
+ answer: string;
10
+ references: (VectorSearchResult & {
11
+ text?: string;
12
+ })[];
13
+ usage?: LLMResponse['usage'];
16
14
  }
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;
15
+ export declare class KnowledgeQueryService {
16
+ private readonly embeddings;
17
+ private readonly vectorStore;
18
+ private readonly llm;
19
+ private readonly config;
20
+ constructor(embeddings: EmbeddingProvider, vectorStore: VectorStoreProvider, llm: LLMProvider, config: KnowledgeQueryConfig);
21
+ query(question: string): Promise<KnowledgeAnswer>;
22
+ private buildMessages;
25
23
  }
26
- //#endregion
27
- export { KnowledgeAnswer, KnowledgeQueryConfig, KnowledgeQueryService };
28
24
  //# sourceMappingURL=service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","names":[],"sources":["../../src/query/service.ts"],"sourcesContent":[],"mappings":";;;UASiB,oBAAA;;EAAA,SAAA,CAAA,EAAA,MAAA;EAOA,IAAA,CAAA,EAAA,MAAA;EAQJ,YAAA,CAAA,EAAA,MAAA;;AAQI,UAhBA,eAAA,CAgBA;EACR,MAAA,EAAA,MAAA;EACG,UAAA,EAAA,CAhBG,kBAgBH,GAAA;IAQ6B,IAAA,CAAA,EAAA,MAAA;EAAR,CAAA,CAAA,EAAA;EAAO,KAAA,CAAA,EArB9B,WAqB8B,CAAA,OAAA,CAAA;;cAlB3B,qBAAA;;;;;0BAOG,gCACC,0BACR,qBACG;2BAQqB,QAAQ"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/query/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EAEX,WAAW,EACZ,MAAM,6BAA6B,CAAC;AAErC,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,CAAC,kBAAkB,GAAG;QAChC,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC,EAAE,CAAC;IACL,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CAC9B;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsB;IAClD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAc;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;gBAG5C,UAAU,EAAE,iBAAiB,EAC7B,WAAW,EAAE,mBAAmB,EAChC,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,oBAAoB;IAQxB,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAwBvD,OAAO,CAAC,aAAa;CAoBtB"}
@@ -1,66 +1,80 @@
1
- //#region src/query/service.ts
2
- var KnowledgeQueryService = class {
3
- embeddings;
4
- vectorStore;
5
- llm;
6
- config;
7
- constructor(embeddings, vectorStore, llm, config) {
8
- this.embeddings = embeddings;
9
- this.vectorStore = vectorStore;
10
- this.llm = llm;
11
- this.config = config;
12
- }
13
- async query(question) {
14
- const embedding = await this.embeddings.embedQuery(question);
15
- const results = await this.vectorStore.search({
16
- collection: this.config.collection,
17
- vector: embedding.vector,
18
- topK: this.config.topK ?? 5,
19
- namespace: this.config.namespace,
20
- filter: void 0
21
- });
22
- const context = buildContext(results);
23
- const messages = this.buildMessages(question, context);
24
- const response = await this.llm.chat(messages);
25
- return {
26
- answer: response.message.content.map((part) => "text" in part ? part.text : "").join(""),
27
- references: results.map((result) => ({
28
- ...result,
29
- text: extractText(result)
30
- })),
31
- usage: response.usage
32
- };
33
- }
34
- buildMessages(question, context) {
35
- return [{
36
- role: "system",
37
- content: [{
38
- type: "text",
39
- text: this.config.systemPrompt ?? "You are a knowledge assistant that answers questions using the provided context. Cite relevant sources if possible."
40
- }]
41
- }, {
42
- role: "user",
43
- content: [{
44
- type: "text",
45
- text: `Question:\n${question}\n\nContext:\n${context}`
46
- }]
47
- }];
48
- }
49
- };
1
+ // @bun
2
+ // src/query/service.ts
3
+ class KnowledgeQueryService {
4
+ embeddings;
5
+ vectorStore;
6
+ llm;
7
+ config;
8
+ constructor(embeddings, vectorStore, llm, config) {
9
+ this.embeddings = embeddings;
10
+ this.vectorStore = vectorStore;
11
+ this.llm = llm;
12
+ this.config = config;
13
+ }
14
+ async query(question) {
15
+ const embedding = await this.embeddings.embedQuery(question);
16
+ const results = await this.vectorStore.search({
17
+ collection: this.config.collection,
18
+ vector: embedding.vector,
19
+ topK: this.config.topK ?? 5,
20
+ namespace: this.config.namespace,
21
+ filter: undefined
22
+ });
23
+ const context = buildContext(results);
24
+ const messages = this.buildMessages(question, context);
25
+ const response = await this.llm.chat(messages);
26
+ return {
27
+ answer: response.message.content.map((part) => ("text" in part) ? part.text : "").join(""),
28
+ references: results.map((result) => ({
29
+ ...result,
30
+ text: extractText(result)
31
+ })),
32
+ usage: response.usage
33
+ };
34
+ }
35
+ buildMessages(question, context) {
36
+ const systemPrompt = this.config.systemPrompt ?? "You are a knowledge assistant that answers questions using the provided context. Cite relevant sources if possible.";
37
+ return [
38
+ {
39
+ role: "system",
40
+ content: [{ type: "text", text: systemPrompt }]
41
+ },
42
+ {
43
+ role: "user",
44
+ content: [
45
+ {
46
+ type: "text",
47
+ text: `Question:
48
+ ${question}
49
+
50
+ Context:
51
+ ${context}`
52
+ }
53
+ ]
54
+ }
55
+ ];
56
+ }
57
+ }
50
58
  function buildContext(results) {
51
- if (results.length === 0) return "No relevant documents found.";
52
- return results.map((result, index) => {
53
- const text = extractText(result);
54
- return `Source ${index + 1} (score: ${result.score.toFixed(3)}):\n${text}`;
55
- }).join("\n\n");
59
+ if (results.length === 0) {
60
+ return "No relevant documents found.";
61
+ }
62
+ return results.map((result, index) => {
63
+ const text = extractText(result);
64
+ return `Source ${index + 1} (score: ${result.score.toFixed(3)}):
65
+ ${text}`;
66
+ }).join(`
67
+
68
+ `);
56
69
  }
57
70
  function extractText(result) {
58
- const payload = result.payload ?? {};
59
- if (typeof payload.text === "string") return payload.text;
60
- if (typeof payload.content === "string") return payload.content;
61
- return JSON.stringify(payload);
71
+ const payload = result.payload ?? {};
72
+ if (typeof payload.text === "string")
73
+ return payload.text;
74
+ if (typeof payload.content === "string")
75
+ return payload.content;
76
+ return JSON.stringify(payload);
62
77
  }
63
-
64
- //#endregion
65
- export { KnowledgeQueryService };
66
- //# sourceMappingURL=service.js.map
78
+ export {
79
+ KnowledgeQueryService
80
+ };
@@ -1,4 +1,4 @@
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
+ export * from './interface';
2
+ export * from './static-retriever';
3
+ export * from './vector-retriever';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/retriever/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
@@ -1,4 +1,101 @@
1
- import { StaticRetriever, createStaticRetriever } from "./static-retriever.js";
2
- import { VectorRetriever, createVectorRetriever } from "./vector-retriever.js";
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
+ }
38
+ function createStaticRetriever(content) {
39
+ return new StaticRetriever({ content });
40
+ }
3
41
 
4
- export { StaticRetriever, VectorRetriever, createStaticRetriever, createVectorRetriever };
42
+ // src/retriever/vector-retriever.ts
43
+ class VectorRetriever {
44
+ config;
45
+ spaceCollections;
46
+ staticContent;
47
+ constructor(config) {
48
+ this.config = config;
49
+ this.spaceCollections = config.spaceCollections instanceof Map ? config.spaceCollections : new Map(Object.entries(config.spaceCollections));
50
+ this.staticContent = config.staticContent ? config.staticContent instanceof Map ? config.staticContent : new Map(Object.entries(config.staticContent)) : new Map;
51
+ }
52
+ async retrieve(query, options) {
53
+ const collection = this.spaceCollections.get(options.spaceKey);
54
+ if (!collection) {
55
+ return [];
56
+ }
57
+ const embedding = await this.config.embeddings.embedQuery(query);
58
+ const results = await this.config.vectorStore.search({
59
+ collection,
60
+ vector: embedding.vector,
61
+ topK: options.topK ?? this.config.defaultTopK ?? 5,
62
+ namespace: options.tenantId,
63
+ filter: options.filter
64
+ });
65
+ const minScore = options.minScore ?? this.config.defaultMinScore ?? 0;
66
+ const filtered = results.filter((r) => r.score >= minScore);
67
+ return filtered.map((result) => ({
68
+ content: this.extractContent(result.payload),
69
+ source: result.id,
70
+ score: result.score,
71
+ metadata: result.payload
72
+ }));
73
+ }
74
+ async getStatic(spaceKey) {
75
+ return this.staticContent.get(spaceKey) ?? null;
76
+ }
77
+ supportsSpace(spaceKey) {
78
+ return this.spaceCollections.has(spaceKey);
79
+ }
80
+ listSpaces() {
81
+ return [...this.spaceCollections.keys()];
82
+ }
83
+ extractContent(payload) {
84
+ if (!payload)
85
+ return "";
86
+ if (typeof payload.text === "string")
87
+ return payload.text;
88
+ if (typeof payload.content === "string")
89
+ return payload.content;
90
+ return JSON.stringify(payload);
91
+ }
92
+ }
93
+ function createVectorRetriever(config) {
94
+ return new VectorRetriever(config);
95
+ }
96
+ export {
97
+ createVectorRetriever,
98
+ createStaticRetriever,
99
+ VectorRetriever,
100
+ StaticRetriever
101
+ };
@@ -1,7 +1,4 @@
1
- import { RetrievalOptions, RetrievalResult } from "../types.js";
2
-
3
- //#region src/retriever/interface.d.ts
4
-
1
+ import type { RetrievalResult, RetrievalOptions } from '../types';
5
2
  /**
6
3
  * Unified interface for knowledge retrieval.
7
4
  *
@@ -9,48 +6,46 @@ import { RetrievalOptions, RetrievalResult } from "../types.js";
9
6
  * This interface is consumed by @contractspec/lib.ai-agent for both static injection
10
7
  * and dynamic RAG tool queries.
11
8
  */
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[];
9
+ export interface KnowledgeRetriever {
10
+ /**
11
+ * Retrieve relevant content for a query using semantic search.
12
+ *
13
+ * @param query - The search query or question
14
+ * @param options - Retrieval options including space key and filters
15
+ * @returns Array of retrieval results sorted by relevance
16
+ */
17
+ retrieve(query: string, options: RetrievalOptions): Promise<RetrievalResult[]>;
18
+ /**
19
+ * Get static content by space key (for required knowledge injection).
20
+ *
21
+ * Used for injecting required knowledge into agent system prompts
22
+ * without performing semantic search.
23
+ *
24
+ * @param spaceKey - The knowledge space key
25
+ * @returns The static content or null if not available
26
+ */
27
+ getStatic(spaceKey: string): Promise<string | null>;
28
+ /**
29
+ * Check if this retriever supports a given knowledge space.
30
+ *
31
+ * @param spaceKey - The knowledge space key to check
32
+ * @returns True if the space is supported
33
+ */
34
+ supportsSpace(spaceKey: string): boolean;
35
+ /**
36
+ * List all supported knowledge space keys.
37
+ *
38
+ * @returns Array of supported space keys
39
+ */
40
+ listSpaces(): string[];
44
41
  }
45
42
  /**
46
43
  * Configuration for creating a retriever.
47
44
  */
48
- interface RetrieverConfig {
49
- /** Default number of results to return */
50
- defaultTopK?: number;
51
- /** Default minimum score threshold */
52
- defaultMinScore?: number;
45
+ export interface RetrieverConfig {
46
+ /** Default number of results to return */
47
+ defaultTopK?: number;
48
+ /** Default minimum score threshold */
49
+ defaultMinScore?: number;
53
50
  }
54
- //#endregion
55
- export { KnowledgeRetriever, RetrieverConfig };
56
51
  //# sourceMappingURL=interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.ts","names":[],"sources":["../../src/retriever/interface.ts"],"sourcesContent":[],"mappings":";;;;;;AASA;;;;;AAsBsC,UAtBrB,kBAAA,CAsBqB;EAqBrB;;;;;;;mCAjCJ,mBACR,QAAQ;;;;;;;;;;+BAWkB;;;;;;;;;;;;;;;;;;UAqBd,eAAA"}
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/retriever/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAElE;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;OAMG;IACH,QAAQ,CACN,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAE9B;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAEpD;;;;;OAKG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAEzC;;;;OAIG;IACH,UAAU,IAAI,MAAM,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B"}
@@ -0,0 +1 @@
1
+ // @bun
@@ -1,14 +1,11 @@
1
- import { RetrievalOptions, RetrievalResult } from "../types.js";
2
- import { KnowledgeRetriever, RetrieverConfig } from "./interface.js";
3
-
4
- //#region src/retriever/static-retriever.d.ts
5
-
1
+ import type { RetrievalResult, RetrievalOptions } from '../types';
2
+ import type { KnowledgeRetriever, RetrieverConfig } from './interface';
6
3
  /**
7
4
  * Configuration for the static retriever.
8
5
  */
9
- interface StaticRetrieverConfig extends RetrieverConfig {
10
- /** Map of space key to static content */
11
- content: Map<string, string> | Record<string, string>;
6
+ export interface StaticRetrieverConfig extends RetrieverConfig {
7
+ /** Map of space key to static content */
8
+ content: Map<string, string> | Record<string, string>;
12
9
  }
13
10
  /**
14
11
  * A simple in-memory retriever for static knowledge content.
@@ -18,18 +15,16 @@ interface StaticRetrieverConfig extends RetrieverConfig {
18
15
  * - Testing and development
19
16
  * - Small knowledge bases that fit in memory
20
17
  */
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[];
18
+ export declare class StaticRetriever implements KnowledgeRetriever {
19
+ private readonly content;
20
+ constructor(config: StaticRetrieverConfig);
21
+ retrieve(query: string, options: RetrievalOptions): Promise<RetrievalResult[]>;
22
+ getStatic(spaceKey: string): Promise<string | null>;
23
+ supportsSpace(spaceKey: string): boolean;
24
+ listSpaces(): string[];
28
25
  }
29
26
  /**
30
27
  * Create a static retriever from a content map.
31
28
  */
32
- declare function createStaticRetriever(content: Record<string, string> | Map<string, string>): StaticRetriever;
33
- //#endregion
34
- export { StaticRetriever, StaticRetrieverConfig, createStaticRetriever };
29
+ export declare function createStaticRetriever(content: Record<string, string> | Map<string, string>): StaticRetriever;
35
30
  //# sourceMappingURL=static-retriever.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"static-retriever.d.ts","names":[],"sources":["../../src/retriever/static-retriever.ts"],"sourcesContent":[],"mappings":";;;;;;;AAMA;AAEW,UAFM,qBAAA,SAA8B,eAEpC,CAAA;EAAsB;EAFc,OAAA,EAEpC,GAFoC,CAAA,MAAA,EAAA,MAAA,CAAA,GAEd,MAFc,CAAA,MAAA,EAAA,MAAA,CAAA;;AAa/C;;;;;;;;AAoDgB,cApDH,eAAA,YAA2B,kBAoDH,CAAA;EAC1B,iBAAA,OAAA;EAAyB,WAAA,CAAA,MAAA,EAlDd,qBAkDc;EACjC,QAAA,CAAA,KAAA,EAAA,MAAA,EAAA,OAAA,EA1CU,gBA0CV,CAAA,EAzCE,OAyCF,CAzCU,eAyCV,EAAA,CAAA;EAAe,SAAA,CAAA,QAAA,EAAA,MAAA,CAAA,EAlBmB,OAkBnB,CAAA,MAAA,GAAA,IAAA,CAAA;;;;;;;iBAFF,qBAAA,UACL,yBAAyB,sBACjC"}
1
+ {"version":3,"file":"static-retriever.d.ts","sourceRoot":"","sources":["../../src/retriever/static-retriever.ts"],"names":[],"mappings":"AAAA,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,yCAAyC;IACzC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvD;AAED;;;;;;;GAOG;AACH,qBAAa,eAAgB,YAAW,kBAAkB;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;gBAElC,MAAM,EAAE,qBAAqB;IAOnC,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,EAAE,CAAC;IAuBvB,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;CAGvB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACpD,eAAe,CAEjB"}