lemura 1.0.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/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +143 -0
- package/dist/adapters/index.d.mts +45 -0
- package/dist/adapters/index.d.ts +45 -0
- package/dist/adapters/index.js +371 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +369 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/adapters-BSkhv5ac.d.ts +208 -0
- package/dist/adapters-BnG0LEYD.d.mts +208 -0
- package/dist/context/index.d.mts +143 -0
- package/dist/context/index.d.ts +143 -0
- package/dist/context/index.js +321 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +314 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/index.d.mts +91 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +1375 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1348 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger/index.d.mts +19 -0
- package/dist/logger/index.d.ts +19 -0
- package/dist/logger/index.js +67 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/index.mjs +65 -0
- package/dist/logger/index.mjs.map +1 -0
- package/dist/logger-DxvKliuk.d.mts +37 -0
- package/dist/logger-DxvKliuk.d.ts +37 -0
- package/dist/rag/index.d.mts +10 -0
- package/dist/rag/index.d.ts +10 -0
- package/dist/rag/index.js +43 -0
- package/dist/rag/index.js.map +1 -0
- package/dist/rag/index.mjs +41 -0
- package/dist/rag/index.mjs.map +1 -0
- package/dist/rag-La_Bo-J8.d.mts +45 -0
- package/dist/rag-La_Bo-J8.d.ts +45 -0
- package/dist/skills/index.d.mts +15 -0
- package/dist/skills/index.d.ts +15 -0
- package/dist/skills/index.js +40 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/index.mjs +38 -0
- package/dist/skills/index.mjs.map +1 -0
- package/dist/skills-wc8S-OvC.d.mts +14 -0
- package/dist/skills-wc8S-OvC.d.ts +14 -0
- package/dist/storage-BGu4Loao.d.ts +121 -0
- package/dist/storage-DMcliVVj.d.mts +121 -0
- package/dist/tools/index.d.mts +17 -0
- package/dist/tools/index.d.ts +17 -0
- package/dist/tools/index.js +72 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/index.mjs +70 -0
- package/dist/tools/index.mjs.map +1 -0
- package/dist/types/index.d.mts +118 -0
- package/dist/types/index.d.ts +118 -0
- package/dist/types/index.js +84 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +74 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/rag/InMemoryRAGAdapter.ts
|
|
2
|
+
var InMemoryRAGAdapter = class {
|
|
3
|
+
documents = /* @__PURE__ */ new Map();
|
|
4
|
+
async ingest(request) {
|
|
5
|
+
for (const doc of request.documents) {
|
|
6
|
+
this.documents.set(doc.id, doc);
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
ingestedCount: request.documents.length,
|
|
10
|
+
failedCount: 0
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async query(request) {
|
|
14
|
+
const queryStr = request.query.toLowerCase();
|
|
15
|
+
const results = [];
|
|
16
|
+
for (const doc of this.documents.values()) {
|
|
17
|
+
const content = doc.content.toLowerCase();
|
|
18
|
+
let score = 0;
|
|
19
|
+
if (content.includes(queryStr)) score += 0.8;
|
|
20
|
+
const words = queryStr.split(" ");
|
|
21
|
+
for (const word of words) {
|
|
22
|
+
if (content.includes(word)) score += 0.1;
|
|
23
|
+
}
|
|
24
|
+
if (score > 0 && score >= (request.minScore || 0)) {
|
|
25
|
+
results.push({ document: doc, score: Math.min(score, 1) });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
results.sort((a, b) => b.score - a.score);
|
|
29
|
+
const topK = request.topK || 5;
|
|
30
|
+
return {
|
|
31
|
+
results: results.slice(0, topK)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async healthCheck() {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { InMemoryRAGAdapter };
|
|
40
|
+
//# sourceMappingURL=index.mjs.map
|
|
41
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/rag/InMemoryRAGAdapter.ts"],"names":[],"mappings":";AAEO,IAAM,qBAAN,MAAgD;AAAA,EAC3C,SAAA,uBAA0C,GAAA,EAAI;AAAA,EAEtD,MAAM,OAAO,OAAA,EAAuD;AAChE,IAAA,KAAA,MAAW,GAAA,IAAO,QAAQ,SAAA,EAAW;AACjC,MAAA,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,GAAA,CAAI,EAAA,EAAI,GAAG,CAAA;AAAA,IAClC;AACA,IAAA,OAAO;AAAA,MACH,aAAA,EAAe,QAAQ,SAAA,CAAU,MAAA;AAAA,MACjC,WAAA,EAAa;AAAA,KACjB;AAAA,EACJ;AAAA,EAEA,MAAM,MAAM,OAAA,EAAqD;AAC7D,IAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,KAAA,CAAM,WAAA,EAAY;AAC3C,IAAA,MAAM,UAAU,EAAC;AAGjB,IAAA,KAAA,MAAW,GAAA,IAAO,IAAA,CAAK,SAAA,CAAU,MAAA,EAAO,EAAG;AACvC,MAAA,MAAM,OAAA,GAAU,GAAA,CAAI,OAAA,CAAQ,WAAA,EAAY;AACxC,MAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,MAAA,IAAI,OAAA,CAAQ,QAAA,CAAS,QAAQ,CAAA,EAAG,KAAA,IAAS,GAAA;AAEzC,MAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,KAAA,CAAM,GAAG,CAAA;AAChC,MAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACtB,QAAA,IAAI,OAAA,CAAQ,QAAA,CAAS,IAAI,CAAA,EAAG,KAAA,IAAS,GAAA;AAAA,MACzC;AAEA,MAAA,IAAI,KAAA,GAAQ,CAAA,IAAK,KAAA,KAAU,OAAA,CAAQ,YAAY,CAAA,CAAA,EAAI;AAC/C,QAAA,OAAA,CAAQ,IAAA,CAAK,EAAE,QAAA,EAAU,GAAA,EAAK,KAAA,EAAO,KAAK,GAAA,CAAI,KAAA,EAAO,CAAC,CAAA,EAAG,CAAA;AAAA,MAC7D;AAAA,IACJ;AAEA,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA,EAAG,MAAM,CAAA,CAAE,KAAA,GAAQ,EAAE,KAAK,CAAA;AACxC,IAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,IAAQ,CAAA;AAE7B,IAAA,OAAO;AAAA,MACH,OAAA,EAAS,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,IAAI;AAAA,KAClC;AAAA,EACJ;AAAA,EAEA,MAAM,WAAA,GAAgC;AAClC,IAAA,OAAO,IAAA;AAAA,EACX;AACJ","file":"index.mjs","sourcesContent":["import { IRAGAdapter, RAGDocument, RAGIngestRequest, RAGIngestResponse, RAGQueryRequest, RAGQueryResponse } from '../types/index.js';\n\nexport class InMemoryRAGAdapter implements IRAGAdapter {\n private documents: Map<string, RAGDocument> = new Map();\n\n async ingest(request: RAGIngestRequest): Promise<RAGIngestResponse> {\n for (const doc of request.documents) {\n this.documents.set(doc.id, doc);\n }\n return {\n ingestedCount: request.documents.length,\n failedCount: 0\n };\n }\n\n async query(request: RAGQueryRequest): Promise<RAGQueryResponse> {\n const queryStr = request.query.toLowerCase();\n const results = [];\n\n // Very basic keyword matching for testing\n for (const doc of this.documents.values()) {\n const content = doc.content.toLowerCase();\n let score = 0;\n if (content.includes(queryStr)) score += 0.8;\n\n const words = queryStr.split(' ');\n for (const word of words) {\n if (content.includes(word)) score += 0.1;\n }\n\n if (score > 0 && score >= (request.minScore || 0)) {\n results.push({ document: doc, score: Math.min(score, 1) });\n }\n }\n\n results.sort((a, b) => b.score - a.score);\n const topK = request.topK || 5;\n\n return {\n results: results.slice(0, topK)\n };\n }\n\n async healthCheck(): Promise<boolean> {\n return true;\n }\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
interface RAGDocument {
|
|
2
|
+
id: string;
|
|
3
|
+
content: string;
|
|
4
|
+
metadata?: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
interface RAGIngestOptions {
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface RAGIngestRequest {
|
|
10
|
+
documents: RAGDocument[];
|
|
11
|
+
collectionId?: string;
|
|
12
|
+
options?: RAGIngestOptions;
|
|
13
|
+
}
|
|
14
|
+
interface RAGIngestResponse {
|
|
15
|
+
ingestedCount: number;
|
|
16
|
+
failedCount: number;
|
|
17
|
+
failures?: Array<{
|
|
18
|
+
id: string;
|
|
19
|
+
reason: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
interface RAGQueryRequest {
|
|
23
|
+
query: string;
|
|
24
|
+
topK?: number;
|
|
25
|
+
collectionId?: string;
|
|
26
|
+
filter?: Record<string, unknown>;
|
|
27
|
+
minScore?: number;
|
|
28
|
+
}
|
|
29
|
+
interface RAGResult {
|
|
30
|
+
document: RAGDocument;
|
|
31
|
+
score: number;
|
|
32
|
+
chunkIndex?: number;
|
|
33
|
+
}
|
|
34
|
+
interface RAGQueryResponse {
|
|
35
|
+
results: RAGResult[];
|
|
36
|
+
queryEmbedding?: number[];
|
|
37
|
+
}
|
|
38
|
+
interface IRAGAdapter {
|
|
39
|
+
ingest(request: RAGIngestRequest): Promise<RAGIngestResponse>;
|
|
40
|
+
query(request: RAGQueryRequest): Promise<RAGQueryResponse>;
|
|
41
|
+
delete?(ids: string[]): Promise<void>;
|
|
42
|
+
healthCheck?(): Promise<boolean>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type { IRAGAdapter as I, RAGDocument as R, RAGIngestOptions as a, RAGIngestRequest as b, RAGIngestResponse as c, RAGQueryRequest as d, RAGQueryResponse as e, RAGResult as f };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
interface RAGDocument {
|
|
2
|
+
id: string;
|
|
3
|
+
content: string;
|
|
4
|
+
metadata?: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
interface RAGIngestOptions {
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface RAGIngestRequest {
|
|
10
|
+
documents: RAGDocument[];
|
|
11
|
+
collectionId?: string;
|
|
12
|
+
options?: RAGIngestOptions;
|
|
13
|
+
}
|
|
14
|
+
interface RAGIngestResponse {
|
|
15
|
+
ingestedCount: number;
|
|
16
|
+
failedCount: number;
|
|
17
|
+
failures?: Array<{
|
|
18
|
+
id: string;
|
|
19
|
+
reason: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
interface RAGQueryRequest {
|
|
23
|
+
query: string;
|
|
24
|
+
topK?: number;
|
|
25
|
+
collectionId?: string;
|
|
26
|
+
filter?: Record<string, unknown>;
|
|
27
|
+
minScore?: number;
|
|
28
|
+
}
|
|
29
|
+
interface RAGResult {
|
|
30
|
+
document: RAGDocument;
|
|
31
|
+
score: number;
|
|
32
|
+
chunkIndex?: number;
|
|
33
|
+
}
|
|
34
|
+
interface RAGQueryResponse {
|
|
35
|
+
results: RAGResult[];
|
|
36
|
+
queryEmbedding?: number[];
|
|
37
|
+
}
|
|
38
|
+
interface IRAGAdapter {
|
|
39
|
+
ingest(request: RAGIngestRequest): Promise<RAGIngestResponse>;
|
|
40
|
+
query(request: RAGQueryRequest): Promise<RAGQueryResponse>;
|
|
41
|
+
delete?(ids: string[]): Promise<void>;
|
|
42
|
+
healthCheck?(): Promise<boolean>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type { IRAGAdapter as I, RAGDocument as R, RAGIngestOptions as a, RAGIngestRequest as b, RAGIngestResponse as c, RAGQueryRequest as d, RAGQueryResponse as e, RAGResult as f };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { I as ISkill } from '../skills-wc8S-OvC.mjs';
|
|
2
|
+
|
|
3
|
+
declare class SkillInjector {
|
|
4
|
+
private skills;
|
|
5
|
+
constructor(skills?: ISkill[]);
|
|
6
|
+
register(skill: ISkill): void;
|
|
7
|
+
private sortSkills;
|
|
8
|
+
getSkillsForInjection(position: ISkill['inject']): ISkill[];
|
|
9
|
+
/**
|
|
10
|
+
* Generates a combined prompt block for all skills targeting a specific injection position.
|
|
11
|
+
*/
|
|
12
|
+
buildInjectionBlock(position: ISkill['inject']): string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { SkillInjector };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { I as ISkill } from '../skills-wc8S-OvC.js';
|
|
2
|
+
|
|
3
|
+
declare class SkillInjector {
|
|
4
|
+
private skills;
|
|
5
|
+
constructor(skills?: ISkill[]);
|
|
6
|
+
register(skill: ISkill): void;
|
|
7
|
+
private sortSkills;
|
|
8
|
+
getSkillsForInjection(position: ISkill['inject']): ISkill[];
|
|
9
|
+
/**
|
|
10
|
+
* Generates a combined prompt block for all skills targeting a specific injection position.
|
|
11
|
+
*/
|
|
12
|
+
buildInjectionBlock(position: ISkill['inject']): string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { SkillInjector };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/skills/SkillInjector.ts
|
|
4
|
+
var SkillInjector = class {
|
|
5
|
+
skills = [];
|
|
6
|
+
constructor(skills = []) {
|
|
7
|
+
this.skills = [...skills];
|
|
8
|
+
this.sortSkills();
|
|
9
|
+
}
|
|
10
|
+
register(skill) {
|
|
11
|
+
this.skills.push(skill);
|
|
12
|
+
this.sortSkills();
|
|
13
|
+
}
|
|
14
|
+
sortSkills() {
|
|
15
|
+
this.skills.sort((a, b) => a.priority - b.priority);
|
|
16
|
+
}
|
|
17
|
+
getSkillsForInjection(position) {
|
|
18
|
+
return this.skills.filter((s) => s.inject === position);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generates a combined prompt block for all skills targeting a specific injection position.
|
|
22
|
+
*/
|
|
23
|
+
buildInjectionBlock(position) {
|
|
24
|
+
const relevantSkills = this.getSkillsForInjection(position);
|
|
25
|
+
if (relevantSkills.length === 0) return "";
|
|
26
|
+
let block = "";
|
|
27
|
+
for (const skill of relevantSkills) {
|
|
28
|
+
const content = skill.standard || skill.micro || skill.nano || skill.description;
|
|
29
|
+
block += `
|
|
30
|
+
[Skill: ${skill.name} (Tier: ${skill.tier})]
|
|
31
|
+
${content}
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
return block.trim();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.SkillInjector = SkillInjector;
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/skills/SkillInjector.ts"],"names":[],"mappings":";;;AAEO,IAAM,gBAAN,MAAoB;AAAA,EACf,SAAmB,EAAC;AAAA,EAE5B,WAAA,CAAY,MAAA,GAAmB,EAAC,EAAG;AAC/B,IAAA,IAAA,CAAK,MAAA,GAAS,CAAC,GAAG,MAAM,CAAA;AACxB,IAAA,IAAA,CAAK,UAAA,EAAW;AAAA,EACpB;AAAA,EAEA,SAAS,KAAA,EAAe;AACpB,IAAA,IAAA,CAAK,MAAA,CAAO,KAAK,KAAK,CAAA;AACtB,IAAA,IAAA,CAAK,UAAA,EAAW;AAAA,EACpB;AAAA,EAEQ,UAAA,GAAa;AACjB,IAAA,IAAA,CAAK,MAAA,CAAO,KAAK,CAAC,CAAA,EAAG,MAAM,CAAA,CAAE,QAAA,GAAW,EAAE,QAAQ,CAAA;AAAA,EACtD;AAAA,EAEA,sBAAsB,QAAA,EAAsC;AACxD,IAAA,OAAO,KAAK,MAAA,CAAO,MAAA,CAAO,CAAA,CAAA,KAAK,CAAA,CAAE,WAAW,QAAQ,CAAA;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKA,oBAAoB,QAAA,EAAoC;AACpD,IAAA,MAAM,cAAA,GAAiB,IAAA,CAAK,qBAAA,CAAsB,QAAQ,CAAA;AAC1D,IAAA,IAAI,cAAA,CAAe,MAAA,KAAW,CAAA,EAAG,OAAO,EAAA;AAExC,IAAA,IAAI,KAAA,GAAQ,EAAA;AACZ,IAAA,KAAA,MAAW,SAAS,cAAA,EAAgB;AAEhC,MAAA,MAAM,UAAU,KAAA,CAAM,QAAA,IAAY,MAAM,KAAA,IAAS,KAAA,CAAM,QAAQ,KAAA,CAAM,WAAA;AACrE,MAAA,KAAA,IAAS;AAAA,QAAA,EAAa,KAAA,CAAM,IAAI,CAAA,QAAA,EAAW,KAAA,CAAM,IAAI,CAAA;AAAA,EAAO,OAAO;AAAA,CAAA;AAAA,IACvE;AAEA,IAAA,OAAO,MAAM,IAAA,EAAK;AAAA,EACtB;AACJ","file":"index.js","sourcesContent":["import { ISkill } from '../types/index.js';\n\nexport class SkillInjector {\n private skills: ISkill[] = [];\n\n constructor(skills: ISkill[] = []) {\n this.skills = [...skills];\n this.sortSkills();\n }\n\n register(skill: ISkill) {\n this.skills.push(skill);\n this.sortSkills();\n }\n\n private sortSkills() {\n this.skills.sort((a, b) => a.priority - b.priority);\n }\n\n getSkillsForInjection(position: ISkill['inject']): ISkill[] {\n return this.skills.filter(s => s.inject === position);\n }\n\n /**\n * Generates a combined prompt block for all skills targeting a specific injection position.\n */\n buildInjectionBlock(position: ISkill['inject']): string {\n const relevantSkills = this.getSkillsForInjection(position);\n if (relevantSkills.length === 0) return '';\n\n let block = '';\n for (const skill of relevantSkills) {\n // Very basic tier logic, full compression handling would be tied to budgets\n const content = skill.standard || skill.micro || skill.nano || skill.description;\n block += `\\n[Skill: ${skill.name} (Tier: ${skill.tier})]\\n${content}\\n`;\n }\n\n return block.trim();\n }\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/skills/SkillInjector.ts
|
|
2
|
+
var SkillInjector = class {
|
|
3
|
+
skills = [];
|
|
4
|
+
constructor(skills = []) {
|
|
5
|
+
this.skills = [...skills];
|
|
6
|
+
this.sortSkills();
|
|
7
|
+
}
|
|
8
|
+
register(skill) {
|
|
9
|
+
this.skills.push(skill);
|
|
10
|
+
this.sortSkills();
|
|
11
|
+
}
|
|
12
|
+
sortSkills() {
|
|
13
|
+
this.skills.sort((a, b) => a.priority - b.priority);
|
|
14
|
+
}
|
|
15
|
+
getSkillsForInjection(position) {
|
|
16
|
+
return this.skills.filter((s) => s.inject === position);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generates a combined prompt block for all skills targeting a specific injection position.
|
|
20
|
+
*/
|
|
21
|
+
buildInjectionBlock(position) {
|
|
22
|
+
const relevantSkills = this.getSkillsForInjection(position);
|
|
23
|
+
if (relevantSkills.length === 0) return "";
|
|
24
|
+
let block = "";
|
|
25
|
+
for (const skill of relevantSkills) {
|
|
26
|
+
const content = skill.standard || skill.micro || skill.nano || skill.description;
|
|
27
|
+
block += `
|
|
28
|
+
[Skill: ${skill.name} (Tier: ${skill.tier})]
|
|
29
|
+
${content}
|
|
30
|
+
`;
|
|
31
|
+
}
|
|
32
|
+
return block.trim();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { SkillInjector };
|
|
37
|
+
//# sourceMappingURL=index.mjs.map
|
|
38
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/skills/SkillInjector.ts"],"names":[],"mappings":";AAEO,IAAM,gBAAN,MAAoB;AAAA,EACf,SAAmB,EAAC;AAAA,EAE5B,WAAA,CAAY,MAAA,GAAmB,EAAC,EAAG;AAC/B,IAAA,IAAA,CAAK,MAAA,GAAS,CAAC,GAAG,MAAM,CAAA;AACxB,IAAA,IAAA,CAAK,UAAA,EAAW;AAAA,EACpB;AAAA,EAEA,SAAS,KAAA,EAAe;AACpB,IAAA,IAAA,CAAK,MAAA,CAAO,KAAK,KAAK,CAAA;AACtB,IAAA,IAAA,CAAK,UAAA,EAAW;AAAA,EACpB;AAAA,EAEQ,UAAA,GAAa;AACjB,IAAA,IAAA,CAAK,MAAA,CAAO,KAAK,CAAC,CAAA,EAAG,MAAM,CAAA,CAAE,QAAA,GAAW,EAAE,QAAQ,CAAA;AAAA,EACtD;AAAA,EAEA,sBAAsB,QAAA,EAAsC;AACxD,IAAA,OAAO,KAAK,MAAA,CAAO,MAAA,CAAO,CAAA,CAAA,KAAK,CAAA,CAAE,WAAW,QAAQ,CAAA;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKA,oBAAoB,QAAA,EAAoC;AACpD,IAAA,MAAM,cAAA,GAAiB,IAAA,CAAK,qBAAA,CAAsB,QAAQ,CAAA;AAC1D,IAAA,IAAI,cAAA,CAAe,MAAA,KAAW,CAAA,EAAG,OAAO,EAAA;AAExC,IAAA,IAAI,KAAA,GAAQ,EAAA;AACZ,IAAA,KAAA,MAAW,SAAS,cAAA,EAAgB;AAEhC,MAAA,MAAM,UAAU,KAAA,CAAM,QAAA,IAAY,MAAM,KAAA,IAAS,KAAA,CAAM,QAAQ,KAAA,CAAM,WAAA;AACrE,MAAA,KAAA,IAAS;AAAA,QAAA,EAAa,KAAA,CAAM,IAAI,CAAA,QAAA,EAAW,KAAA,CAAM,IAAI,CAAA;AAAA,EAAO,OAAO;AAAA,CAAA;AAAA,IACvE;AAEA,IAAA,OAAO,MAAM,IAAA,EAAK;AAAA,EACtB;AACJ","file":"index.mjs","sourcesContent":["import { ISkill } from '../types/index.js';\n\nexport class SkillInjector {\n private skills: ISkill[] = [];\n\n constructor(skills: ISkill[] = []) {\n this.skills = [...skills];\n this.sortSkills();\n }\n\n register(skill: ISkill) {\n this.skills.push(skill);\n this.sortSkills();\n }\n\n private sortSkills() {\n this.skills.sort((a, b) => a.priority - b.priority);\n }\n\n getSkillsForInjection(position: ISkill['inject']): ISkill[] {\n return this.skills.filter(s => s.inject === position);\n }\n\n /**\n * Generates a combined prompt block for all skills targeting a specific injection position.\n */\n buildInjectionBlock(position: ISkill['inject']): string {\n const relevantSkills = this.getSkillsForInjection(position);\n if (relevantSkills.length === 0) return '';\n\n let block = '';\n for (const skill of relevantSkills) {\n // Very basic tier logic, full compression handling would be tied to budgets\n const content = skill.standard || skill.micro || skill.nano || skill.description;\n block += `\\n[Skill: ${skill.name} (Tier: ${skill.tier})]\\n${content}\\n`;\n }\n\n return block.trim();\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface ISkill {
|
|
2
|
+
name: string;
|
|
3
|
+
version: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inject: 'system_prompt' | 'pre_turn' | 'post_history';
|
|
6
|
+
priority: number;
|
|
7
|
+
tier: 'nano' | 'micro' | 'standard' | 'extended';
|
|
8
|
+
nano?: string;
|
|
9
|
+
micro?: string;
|
|
10
|
+
standard?: string;
|
|
11
|
+
extended?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type { ISkill as I };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface ISkill {
|
|
2
|
+
name: string;
|
|
3
|
+
version: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inject: 'system_prompt' | 'pre_turn' | 'post_history';
|
|
6
|
+
priority: number;
|
|
7
|
+
tier: 'nano' | 'micro' | 'standard' | 'extended';
|
|
8
|
+
nano?: string;
|
|
9
|
+
micro?: string;
|
|
10
|
+
standard?: string;
|
|
11
|
+
extended?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type { ISkill as I };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { I as IRAGAdapter } from './rag-La_Bo-J8.js';
|
|
2
|
+
import { I as ILogger } from './logger-DxvKliuk.js';
|
|
3
|
+
|
|
4
|
+
interface STMRegistryConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The storage backend to use for Short Term Memory items.
|
|
7
|
+
*/
|
|
8
|
+
storage: IStorageAdapter;
|
|
9
|
+
/**
|
|
10
|
+
* The maximum number of tokens allowed for a 'text' type STM item.
|
|
11
|
+
* If an item exceeds this, it may be rejected or truncated.
|
|
12
|
+
* Default: 100000
|
|
13
|
+
*/
|
|
14
|
+
maxTextTokens?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Registry for Short Term Memory (STM).
|
|
18
|
+
* Manages the storage and retrieval of large context variables like long texts or blobs.
|
|
19
|
+
* Generates '[STM:uuid]' references to be used within the ReAct agent context.
|
|
20
|
+
*/
|
|
21
|
+
declare class ShortTermMemoryRegistry {
|
|
22
|
+
private storage;
|
|
23
|
+
private maxTextTokens;
|
|
24
|
+
constructor(config: STMRegistryConfig);
|
|
25
|
+
/**
|
|
26
|
+
* Registers a new memory item and returns its reference string.
|
|
27
|
+
*
|
|
28
|
+
* @param content - The raw content to store
|
|
29
|
+
* @param type - The type of content ('text' or 'blob')
|
|
30
|
+
* @param metadata - Optional metadata (e.g. sandwich layers, original filename)
|
|
31
|
+
* @param estimateTokens - Optional function to estimate token count for 'text' type
|
|
32
|
+
* @returns A reference string formatted as '[STM:uuid]'
|
|
33
|
+
* @throws {Error} if a text item exceeds the maxTextTokens limit
|
|
34
|
+
*/
|
|
35
|
+
register(content: any, type: 'text' | 'blob', metadata?: Record<string, unknown>, estimateTokens?: (text: string) => number): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Updates an existing STM item's content or metadata.
|
|
38
|
+
*
|
|
39
|
+
* @param id - The UUID of the item to update
|
|
40
|
+
* @param updates - Partial updates to apply (content or metadata)
|
|
41
|
+
*/
|
|
42
|
+
update(id: string, updates: {
|
|
43
|
+
content?: any;
|
|
44
|
+
metadata?: Record<string, unknown>;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves an STM item by its full reference string (e.g., '[STM:uuid]').
|
|
48
|
+
*
|
|
49
|
+
* @param ref - The full reference string
|
|
50
|
+
* @returns The STMItem or undefined if not found
|
|
51
|
+
*/
|
|
52
|
+
getByRef(ref: string): Promise<STMItem | undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* Deletes an STM item by its ID.
|
|
55
|
+
*
|
|
56
|
+
* @param id - The UUID of the item to delete
|
|
57
|
+
*/
|
|
58
|
+
delete(id: string): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface ToolContext {
|
|
62
|
+
sessionId: string;
|
|
63
|
+
turnIndex: number;
|
|
64
|
+
logger: ILogger;
|
|
65
|
+
ragAdapter?: IRAGAdapter;
|
|
66
|
+
stmRegistry?: ShortTermMemoryRegistry;
|
|
67
|
+
scratchpad?: string;
|
|
68
|
+
}
|
|
69
|
+
interface IToolDefinition {
|
|
70
|
+
name: string;
|
|
71
|
+
description: string;
|
|
72
|
+
parameters: Record<string, unknown>;
|
|
73
|
+
execute(params: unknown, context: ToolContext): Promise<unknown>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Interface for Short Term Memory storage adapters.
|
|
78
|
+
* Implementations handle the persistence of STM variables.
|
|
79
|
+
*/
|
|
80
|
+
interface IStorageAdapter {
|
|
81
|
+
/**
|
|
82
|
+
* Retrieves content by its unique ID.
|
|
83
|
+
*
|
|
84
|
+
* @param id - The unique identifier of the stored content
|
|
85
|
+
* @returns The content or undefined if it does not exist
|
|
86
|
+
*/
|
|
87
|
+
get(id: string): Promise<any | undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* Saves content returning a stable ID if none was provided, or using the given ID.
|
|
90
|
+
*
|
|
91
|
+
* @param id - An optional unique identifier. If not provided, one should be generated.
|
|
92
|
+
* @param content - The content to be stored
|
|
93
|
+
* @param metadata - Optional metadata about the content (e.g. type, size)
|
|
94
|
+
* @returns A promise that resolves to the ID under which it was saved
|
|
95
|
+
*/
|
|
96
|
+
set(id: string | undefined, content: any, metadata?: Record<string, unknown>): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Deletes content by its unique ID.
|
|
99
|
+
*
|
|
100
|
+
* @param id - The unique identifier of the content to delete
|
|
101
|
+
* @returns Resolves when deletion is complete
|
|
102
|
+
*/
|
|
103
|
+
delete(id: string): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Optional health check for remote storage adapters.
|
|
106
|
+
*
|
|
107
|
+
* @returns true if storage is accessible, false otherwise
|
|
108
|
+
*/
|
|
109
|
+
healthCheck?(): Promise<boolean>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Represents an item stored in Short Term Memory.
|
|
113
|
+
*/
|
|
114
|
+
interface STMItem {
|
|
115
|
+
id: string;
|
|
116
|
+
content: any;
|
|
117
|
+
type: 'text' | 'blob';
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { type IToolDefinition as I, type STMItem as S, type ToolContext as T, type IStorageAdapter as a, type STMRegistryConfig as b, ShortTermMemoryRegistry as c };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { I as IRAGAdapter } from './rag-La_Bo-J8.mjs';
|
|
2
|
+
import { I as ILogger } from './logger-DxvKliuk.mjs';
|
|
3
|
+
|
|
4
|
+
interface STMRegistryConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The storage backend to use for Short Term Memory items.
|
|
7
|
+
*/
|
|
8
|
+
storage: IStorageAdapter;
|
|
9
|
+
/**
|
|
10
|
+
* The maximum number of tokens allowed for a 'text' type STM item.
|
|
11
|
+
* If an item exceeds this, it may be rejected or truncated.
|
|
12
|
+
* Default: 100000
|
|
13
|
+
*/
|
|
14
|
+
maxTextTokens?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Registry for Short Term Memory (STM).
|
|
18
|
+
* Manages the storage and retrieval of large context variables like long texts or blobs.
|
|
19
|
+
* Generates '[STM:uuid]' references to be used within the ReAct agent context.
|
|
20
|
+
*/
|
|
21
|
+
declare class ShortTermMemoryRegistry {
|
|
22
|
+
private storage;
|
|
23
|
+
private maxTextTokens;
|
|
24
|
+
constructor(config: STMRegistryConfig);
|
|
25
|
+
/**
|
|
26
|
+
* Registers a new memory item and returns its reference string.
|
|
27
|
+
*
|
|
28
|
+
* @param content - The raw content to store
|
|
29
|
+
* @param type - The type of content ('text' or 'blob')
|
|
30
|
+
* @param metadata - Optional metadata (e.g. sandwich layers, original filename)
|
|
31
|
+
* @param estimateTokens - Optional function to estimate token count for 'text' type
|
|
32
|
+
* @returns A reference string formatted as '[STM:uuid]'
|
|
33
|
+
* @throws {Error} if a text item exceeds the maxTextTokens limit
|
|
34
|
+
*/
|
|
35
|
+
register(content: any, type: 'text' | 'blob', metadata?: Record<string, unknown>, estimateTokens?: (text: string) => number): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Updates an existing STM item's content or metadata.
|
|
38
|
+
*
|
|
39
|
+
* @param id - The UUID of the item to update
|
|
40
|
+
* @param updates - Partial updates to apply (content or metadata)
|
|
41
|
+
*/
|
|
42
|
+
update(id: string, updates: {
|
|
43
|
+
content?: any;
|
|
44
|
+
metadata?: Record<string, unknown>;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves an STM item by its full reference string (e.g., '[STM:uuid]').
|
|
48
|
+
*
|
|
49
|
+
* @param ref - The full reference string
|
|
50
|
+
* @returns The STMItem or undefined if not found
|
|
51
|
+
*/
|
|
52
|
+
getByRef(ref: string): Promise<STMItem | undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* Deletes an STM item by its ID.
|
|
55
|
+
*
|
|
56
|
+
* @param id - The UUID of the item to delete
|
|
57
|
+
*/
|
|
58
|
+
delete(id: string): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface ToolContext {
|
|
62
|
+
sessionId: string;
|
|
63
|
+
turnIndex: number;
|
|
64
|
+
logger: ILogger;
|
|
65
|
+
ragAdapter?: IRAGAdapter;
|
|
66
|
+
stmRegistry?: ShortTermMemoryRegistry;
|
|
67
|
+
scratchpad?: string;
|
|
68
|
+
}
|
|
69
|
+
interface IToolDefinition {
|
|
70
|
+
name: string;
|
|
71
|
+
description: string;
|
|
72
|
+
parameters: Record<string, unknown>;
|
|
73
|
+
execute(params: unknown, context: ToolContext): Promise<unknown>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Interface for Short Term Memory storage adapters.
|
|
78
|
+
* Implementations handle the persistence of STM variables.
|
|
79
|
+
*/
|
|
80
|
+
interface IStorageAdapter {
|
|
81
|
+
/**
|
|
82
|
+
* Retrieves content by its unique ID.
|
|
83
|
+
*
|
|
84
|
+
* @param id - The unique identifier of the stored content
|
|
85
|
+
* @returns The content or undefined if it does not exist
|
|
86
|
+
*/
|
|
87
|
+
get(id: string): Promise<any | undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* Saves content returning a stable ID if none was provided, or using the given ID.
|
|
90
|
+
*
|
|
91
|
+
* @param id - An optional unique identifier. If not provided, one should be generated.
|
|
92
|
+
* @param content - The content to be stored
|
|
93
|
+
* @param metadata - Optional metadata about the content (e.g. type, size)
|
|
94
|
+
* @returns A promise that resolves to the ID under which it was saved
|
|
95
|
+
*/
|
|
96
|
+
set(id: string | undefined, content: any, metadata?: Record<string, unknown>): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Deletes content by its unique ID.
|
|
99
|
+
*
|
|
100
|
+
* @param id - The unique identifier of the content to delete
|
|
101
|
+
* @returns Resolves when deletion is complete
|
|
102
|
+
*/
|
|
103
|
+
delete(id: string): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Optional health check for remote storage adapters.
|
|
106
|
+
*
|
|
107
|
+
* @returns true if storage is accessible, false otherwise
|
|
108
|
+
*/
|
|
109
|
+
healthCheck?(): Promise<boolean>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Represents an item stored in Short Term Memory.
|
|
113
|
+
*/
|
|
114
|
+
interface STMItem {
|
|
115
|
+
id: string;
|
|
116
|
+
content: any;
|
|
117
|
+
type: 'text' | 'blob';
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { type IToolDefinition as I, type STMItem as S, type ToolContext as T, type IStorageAdapter as a, type STMRegistryConfig as b, ShortTermMemoryRegistry as c };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { I as IToolDefinition, T as ToolContext } from '../storage-DMcliVVj.mjs';
|
|
2
|
+
import '../rag-La_Bo-J8.mjs';
|
|
3
|
+
import '../logger-DxvKliuk.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Manages registered tools and their execution
|
|
7
|
+
*/
|
|
8
|
+
declare class ToolRegistry {
|
|
9
|
+
private tools;
|
|
10
|
+
constructor(initialTools?: IToolDefinition[]);
|
|
11
|
+
register(tool: IToolDefinition): void;
|
|
12
|
+
get(name: string): IToolDefinition | undefined;
|
|
13
|
+
getAll(): IToolDefinition[];
|
|
14
|
+
execute(name: string, params: unknown, context: ToolContext): Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { ToolRegistry };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { I as IToolDefinition, T as ToolContext } from '../storage-BGu4Loao.js';
|
|
2
|
+
import '../rag-La_Bo-J8.js';
|
|
3
|
+
import '../logger-DxvKliuk.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Manages registered tools and their execution
|
|
7
|
+
*/
|
|
8
|
+
declare class ToolRegistry {
|
|
9
|
+
private tools;
|
|
10
|
+
constructor(initialTools?: IToolDefinition[]);
|
|
11
|
+
register(tool: IToolDefinition): void;
|
|
12
|
+
get(name: string): IToolDefinition | undefined;
|
|
13
|
+
getAll(): IToolDefinition[];
|
|
14
|
+
execute(name: string, params: unknown, context: ToolContext): Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { ToolRegistry };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/types/errors.ts
|
|
4
|
+
var LemuraError = class extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* @param message - The error message
|
|
7
|
+
* @param code - The error code for programmatic handling
|
|
8
|
+
* @param problem - A clear description of the problem for the end user
|
|
9
|
+
* @param hints - A list of suggestions to resolve the issue
|
|
10
|
+
*/
|
|
11
|
+
constructor(message, code, problem, hints = []) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.problem = problem;
|
|
15
|
+
this.hints = hints;
|
|
16
|
+
this.name = "LemuraError";
|
|
17
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var LemuraToolNotFoundError = class extends LemuraError {
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(message, "TOOL_NOT_FOUND");
|
|
23
|
+
this.name = "LemuraToolNotFoundError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var LemuraToolValidationError = class extends LemuraError {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(message, "TOOL_VALIDATION_FAILED");
|
|
29
|
+
this.name = "LemuraToolValidationError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/tools/ToolRegistry.ts
|
|
34
|
+
var ToolRegistry = class {
|
|
35
|
+
tools = /* @__PURE__ */ new Map();
|
|
36
|
+
constructor(initialTools = []) {
|
|
37
|
+
for (const tool of initialTools) {
|
|
38
|
+
this.register(tool);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
register(tool) {
|
|
42
|
+
if (this.tools.has(tool.name)) {
|
|
43
|
+
throw new Error(`Tool ${tool.name} is already registered.`);
|
|
44
|
+
}
|
|
45
|
+
this.tools.set(tool.name, tool);
|
|
46
|
+
}
|
|
47
|
+
get(name) {
|
|
48
|
+
return this.tools.get(name);
|
|
49
|
+
}
|
|
50
|
+
getAll() {
|
|
51
|
+
return Array.from(this.tools.values());
|
|
52
|
+
}
|
|
53
|
+
async execute(name, params, context) {
|
|
54
|
+
const tool = this.tools.get(name);
|
|
55
|
+
if (!tool) {
|
|
56
|
+
throw new LemuraToolNotFoundError(`Tool '${name}' not found.`);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const result = await tool.execute(params, context);
|
|
60
|
+
return result;
|
|
61
|
+
} catch (err) {
|
|
62
|
+
if (err instanceof LemuraToolValidationError) {
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`Tool execution failed for '${name}': ${err.message}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.ToolRegistry = ToolRegistry;
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/errors.ts","../../src/tools/ToolRegistry.ts"],"names":[],"mappings":";;;AAMO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOnC,YACI,OAAA,EACgB,IAAA,EACA,OAAA,EACA,KAAA,GAAkB,EAAC,EACrC;AACE,IAAA,KAAA,CAAM,OAAO,CAAA;AAJG,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AACA,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA;AAAA,EACpD;AACJ,CAAA;AAWO,IAAM,uBAAA,GAAN,cAAsC,WAAA,CAAY;AAAA,EACrD,YAAY,OAAA,EAAiB;AACzB,IAAA,KAAA,CAAM,SAAS,gBAAgB,CAAA;AAC/B,IAAA,IAAA,CAAK,IAAA,GAAO,yBAAA;AAAA,EAChB;AACJ,CAAA;AAiCO,IAAM,yBAAA,GAAN,cAAwC,WAAA,CAAY;AAAA,EACvD,YAAY,OAAA,EAAiB;AACzB,IAAA,KAAA,CAAM,SAAS,wBAAwB,CAAA;AACvC,IAAA,IAAA,CAAK,IAAA,GAAO,2BAAA;AAAA,EAChB;AACJ,CAAA;;;ACxEO,IAAM,eAAN,MAAmB;AAAA,EACd,KAAA,uBAA0C,GAAA,EAAI;AAAA,EAEtD,WAAA,CAAY,YAAA,GAAkC,EAAC,EAAG;AAC9C,IAAA,KAAA,MAAW,QAAQ,YAAA,EAAc;AAC7B,MAAA,IAAA,CAAK,SAAS,IAAI,CAAA;AAAA,IACtB;AAAA,EACJ;AAAA,EAEA,SAAS,IAAA,EAA6B;AAClC,IAAA,IAAI,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,IAAA,CAAK,IAAI,CAAA,EAAG;AAC3B,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,KAAA,EAAQ,IAAA,CAAK,IAAI,CAAA,uBAAA,CAAyB,CAAA;AAAA,IAC9D;AACA,IAAA,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,IAAA,CAAK,IAAA,EAAM,IAAI,CAAA;AAAA,EAClC;AAAA,EAEA,IAAI,IAAA,EAA2C;AAC3C,IAAA,OAAO,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,IAAI,CAAA;AAAA,EAC9B;AAAA,EAEA,MAAA,GAA4B;AACxB,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,KAAA,CAAM,QAAQ,CAAA;AAAA,EACzC;AAAA,EAEA,MAAM,OAAA,CAAQ,IAAA,EAAc,MAAA,EAAiB,OAAA,EAAwC;AACjF,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,IAAI,CAAA;AAChC,IAAA,IAAI,CAAC,IAAA,EAAM;AACP,MAAA,MAAM,IAAI,uBAAA,CAAwB,CAAA,MAAA,EAAS,IAAI,CAAA,YAAA,CAAc,CAAA;AAAA,IACjE;AAEA,IAAA,IAAI;AAGA,MAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,OAAA,CAAQ,QAAQ,OAAO,CAAA;AACjD,MAAA,OAAO,MAAA;AAAA,IACX,SAAS,GAAA,EAAU;AACf,MAAA,IAAI,eAAe,yBAAA,EAA2B;AAC1C,QAAA,MAAM,GAAA;AAAA,MACV;AACA,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,2BAAA,EAA8B,IAAI,CAAA,GAAA,EAAM,GAAA,CAAI,OAAO,CAAA,CAAE,CAAA;AAAA,IACzE;AAAA,EACJ;AACJ","file":"index.js","sourcesContent":["/**\n * Base class for all custom errors thrown by lemura.\n *\n * @example\n * throw new LemuraError('Something went wrong', 'UNKNOWN_ERROR');\n */\nexport class LemuraError extends Error {\n /**\n * @param message - The error message\n * @param code - The error code for programmatic handling\n * @param problem - A clear description of the problem for the end user\n * @param hints - A list of suggestions to resolve the issue\n */\n constructor(\n message: string,\n public readonly code: string,\n public readonly problem?: string,\n public readonly hints: string[] = []\n ) {\n super(message);\n this.name = 'LemuraError';\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Error thrown when context exceeds max tokens and cannot be compressed further */\nexport class LemuraContextOverflowError extends LemuraError {\n constructor(message: string) {\n super(message, 'CONTEXT_OVERFLOW');\n this.name = 'LemuraContextOverflowError';\n }\n}\n\n/** Error thrown when a requested tool is not found in the registry */\nexport class LemuraToolNotFoundError extends LemuraError {\n constructor(message: string) {\n super(message, 'TOOL_NOT_FOUND');\n this.name = 'LemuraToolNotFoundError';\n }\n}\n\n/** Error thrown when an adapter encounters an API or formatting issue */\nexport class LemuraAdapterError extends LemuraError {\n constructor(\n message: string,\n code = 'ADAPTER_ERROR',\n public cause?: any,\n problem?: string,\n hints: string[] = []\n ) {\n super(message, code, problem, hints);\n this.name = 'LemuraAdapterError';\n }\n}\n\n/** Error thrown when a skill cannot be parsed or injected */\nexport class LemuraSkillInjectionError extends LemuraError {\n constructor(message: string) {\n super(message, 'SKILL_INJECTION_FAILED');\n this.name = 'LemuraSkillInjectionError';\n }\n}\n\n/** Error thrown when the ReAct loop exceeds the configured max iterations */\nexport class LemuraMaxIterationsError extends LemuraError {\n constructor(message: string) {\n super(message, 'MAX_ITERATIONS_EXCEEDED');\n this.name = 'LemuraMaxIterationsError';\n }\n}\n\n/** Error thrown when tool parameters fail JSON schema validation */\nexport class LemuraToolValidationError extends LemuraError {\n constructor(message: string) {\n super(message, 'TOOL_VALIDATION_FAILED');\n this.name = 'LemuraToolValidationError';\n }\n}\n\n/** Error thrown when a tool execute function exceeds its timeout */\nexport class LemuraToolTimeoutError extends LemuraError {\n constructor(message: string) {\n super(message, 'TOOL_TIMEOUT');\n this.name = 'LemuraToolTimeoutError';\n }\n}\n","import { IToolDefinition, LemuraToolNotFoundError, LemuraToolValidationError, ToolContext } from '../types/index.js';\n\n/**\n * Manages registered tools and their execution\n */\nexport class ToolRegistry {\n private tools: Map<string, IToolDefinition> = new Map();\n\n constructor(initialTools: IToolDefinition[] = []) {\n for (const tool of initialTools) {\n this.register(tool);\n }\n }\n\n register(tool: IToolDefinition): void {\n if (this.tools.has(tool.name)) {\n throw new Error(`Tool ${tool.name} is already registered.`);\n }\n this.tools.set(tool.name, tool);\n }\n\n get(name: string): IToolDefinition | undefined {\n return this.tools.get(name);\n }\n\n getAll(): IToolDefinition[] {\n return Array.from(this.tools.values());\n }\n\n async execute(name: string, params: unknown, context: ToolContext): Promise<unknown> {\n const tool = this.tools.get(name);\n if (!tool) {\n throw new LemuraToolNotFoundError(`Tool '${name}' not found.`);\n }\n\n try {\n // Basic JSON schema validation logic goes here\n // Real implementation would use Ajv or similar to validate `params` against `tool.parameters`\n const result = await tool.execute(params, context);\n return result;\n } catch (err: any) {\n if (err instanceof LemuraToolValidationError) {\n throw err;\n }\n throw new Error(`Tool execution failed for '${name}': ${err.message}`);\n }\n }\n}\n"]}
|