@elizaos/plugin-knowledge 1.2.2 → 1.5.10
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/.vite/manifest.json +1 -1
- package/dist/assets/{index-YT4-1nM5.js → index-C_sAxTPC.js} +38 -38
- package/dist/index.html +1 -1
- package/dist/index.js +42 -34
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
package/dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>Agent Plugin View</title>
|
|
8
|
-
<script type="module" crossorigin src="./assets/index-
|
|
8
|
+
<script type="module" crossorigin src="./assets/index-C_sAxTPC.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="./assets/index-B5VEkqpw.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
package/dist/index.js
CHANGED
|
@@ -810,11 +810,11 @@ async function generateAnthropicText(config, prompt, system, modelName, maxToken
|
|
|
810
810
|
prompt,
|
|
811
811
|
system,
|
|
812
812
|
temperature: 0.3,
|
|
813
|
-
maxTokens
|
|
813
|
+
maxOutputTokens: maxTokens
|
|
814
814
|
});
|
|
815
|
-
const totalTokens = result.usage.
|
|
815
|
+
const totalTokens = (result.usage.inputTokens || 0) + (result.usage.outputTokens || 0);
|
|
816
816
|
logger2.debug(
|
|
817
|
-
`[Document Processor] ${modelName}: ${totalTokens} tokens (${result.usage.
|
|
817
|
+
`[Document Processor] ${modelName}: ${totalTokens} tokens (${result.usage.inputTokens || 0}\u2192${result.usage.outputTokens || 0})`
|
|
818
818
|
);
|
|
819
819
|
return result;
|
|
820
820
|
} catch (error) {
|
|
@@ -843,11 +843,11 @@ async function generateOpenAIText(config, prompt, system, modelName, maxTokens)
|
|
|
843
843
|
prompt,
|
|
844
844
|
system,
|
|
845
845
|
temperature: 0.3,
|
|
846
|
-
maxTokens
|
|
846
|
+
maxOutputTokens: maxTokens
|
|
847
847
|
});
|
|
848
|
-
const totalTokens = result.usage.
|
|
848
|
+
const totalTokens = (result.usage.inputTokens || 0) + (result.usage.outputTokens || 0);
|
|
849
849
|
logger2.debug(
|
|
850
|
-
`[Document Processor] OpenAI ${modelName}: ${totalTokens} tokens (${result.usage.
|
|
850
|
+
`[Document Processor] OpenAI ${modelName}: ${totalTokens} tokens (${result.usage.inputTokens || 0}\u2192${result.usage.outputTokens || 0})`
|
|
851
851
|
);
|
|
852
852
|
return result;
|
|
853
853
|
}
|
|
@@ -862,15 +862,15 @@ async function generateGoogleText(prompt, system, modelName, maxTokens, config)
|
|
|
862
862
|
prompt,
|
|
863
863
|
system,
|
|
864
864
|
temperature: 0.3,
|
|
865
|
-
maxTokens
|
|
865
|
+
maxOutputTokens: maxTokens
|
|
866
866
|
});
|
|
867
|
-
const totalTokens = result.usage.
|
|
867
|
+
const totalTokens = (result.usage.inputTokens || 0) + (result.usage.outputTokens || 0);
|
|
868
868
|
logger2.debug(
|
|
869
|
-
`[Document Processor] Google ${modelName}: ${totalTokens} tokens (${result.usage.
|
|
869
|
+
`[Document Processor] Google ${modelName}: ${totalTokens} tokens (${result.usage.inputTokens || 0}\u2192${result.usage.outputTokens || 0})`
|
|
870
870
|
);
|
|
871
871
|
return result;
|
|
872
872
|
}
|
|
873
|
-
async function generateOpenRouterText(config, prompt, system, modelName, maxTokens, cacheDocument,
|
|
873
|
+
async function generateOpenRouterText(config, prompt, system, modelName, maxTokens, cacheDocument, _cacheOptions, autoCacheContextualRetrieval = true) {
|
|
874
874
|
const openrouter = createOpenRouter({
|
|
875
875
|
apiKey: config.OPENROUTER_API_KEY,
|
|
876
876
|
baseURL: config.OPENROUTER_BASE_URL
|
|
@@ -891,7 +891,6 @@ async function generateOpenRouterText(config, prompt, system, modelName, maxToke
|
|
|
891
891
|
}
|
|
892
892
|
}
|
|
893
893
|
if (documentForCaching && supportsCaching) {
|
|
894
|
-
const effectiveCacheOptions = cacheOptions || { type: "ephemeral" };
|
|
895
894
|
let promptText = prompt;
|
|
896
895
|
if (promptText.includes("<document>")) {
|
|
897
896
|
promptText = promptText.replace(/<document>[\s\S]*?<\/document>/, "").trim();
|
|
@@ -978,7 +977,7 @@ async function generateClaudeWithCaching(promptText, system, modelInstance, mode
|
|
|
978
977
|
model: modelInstance,
|
|
979
978
|
messages,
|
|
980
979
|
temperature: 0.3,
|
|
981
|
-
maxTokens,
|
|
980
|
+
maxOutputTokens: maxTokens,
|
|
982
981
|
providerOptions: {
|
|
983
982
|
openrouter: {
|
|
984
983
|
usage: {
|
|
@@ -988,9 +987,9 @@ async function generateClaudeWithCaching(promptText, system, modelInstance, mode
|
|
|
988
987
|
}
|
|
989
988
|
});
|
|
990
989
|
logCacheMetrics(result);
|
|
991
|
-
const totalTokens = result.usage.
|
|
990
|
+
const totalTokens = (result.usage.inputTokens || 0) + (result.usage.outputTokens || 0);
|
|
992
991
|
logger2.debug(
|
|
993
|
-
`[Document Processor] OpenRouter ${modelName}: ${totalTokens} tokens (${result.usage.
|
|
992
|
+
`[Document Processor] OpenRouter ${modelName}: ${totalTokens} tokens (${result.usage.inputTokens || 0}\u2192${result.usage.outputTokens || 0})`
|
|
994
993
|
);
|
|
995
994
|
return result;
|
|
996
995
|
}
|
|
@@ -1029,7 +1028,7 @@ ${promptText}`;
|
|
|
1029
1028
|
model: modelInstance,
|
|
1030
1029
|
prompt: geminiPrompt,
|
|
1031
1030
|
temperature: 0.3,
|
|
1032
|
-
maxTokens,
|
|
1031
|
+
maxOutputTokens: maxTokens,
|
|
1033
1032
|
providerOptions: {
|
|
1034
1033
|
openrouter: {
|
|
1035
1034
|
usage: {
|
|
@@ -1040,10 +1039,10 @@ ${promptText}`;
|
|
|
1040
1039
|
}
|
|
1041
1040
|
});
|
|
1042
1041
|
logCacheMetrics(result);
|
|
1043
|
-
const totalTokens = result.usage.
|
|
1042
|
+
const totalTokens = (result.usage.inputTokens || 0) + (result.usage.outputTokens || 0);
|
|
1044
1043
|
const cachingType = usingImplicitCaching ? "implicit" : "standard";
|
|
1045
1044
|
logger2.debug(
|
|
1046
|
-
`[Document Processor] OpenRouter ${modelName} (${cachingType} caching): ${totalTokens} tokens (${result.usage.
|
|
1045
|
+
`[Document Processor] OpenRouter ${modelName} (${cachingType} caching): ${totalTokens} tokens (${result.usage.inputTokens || 0}\u2192${result.usage.outputTokens || 0})`
|
|
1047
1046
|
);
|
|
1048
1047
|
return result;
|
|
1049
1048
|
}
|
|
@@ -1053,7 +1052,7 @@ async function generateStandardOpenRouterText(prompt, system, modelInstance, mod
|
|
|
1053
1052
|
prompt,
|
|
1054
1053
|
system,
|
|
1055
1054
|
temperature: 0.3,
|
|
1056
|
-
maxTokens,
|
|
1055
|
+
maxOutputTokens: maxTokens,
|
|
1057
1056
|
providerOptions: {
|
|
1058
1057
|
openrouter: {
|
|
1059
1058
|
usage: {
|
|
@@ -1063,9 +1062,9 @@ async function generateStandardOpenRouterText(prompt, system, modelInstance, mod
|
|
|
1063
1062
|
}
|
|
1064
1063
|
}
|
|
1065
1064
|
});
|
|
1066
|
-
const totalTokens = result.usage.
|
|
1065
|
+
const totalTokens = (result.usage.inputTokens || 0) + (result.usage.outputTokens || 0);
|
|
1067
1066
|
logger2.debug(
|
|
1068
|
-
`[Document Processor] OpenRouter ${modelName}: ${totalTokens} tokens (${result.usage.
|
|
1067
|
+
`[Document Processor] OpenRouter ${modelName}: ${totalTokens} tokens (${result.usage.inputTokens || 0}\u2192${result.usage.outputTokens || 0})`
|
|
1069
1068
|
);
|
|
1070
1069
|
return result;
|
|
1071
1070
|
}
|
|
@@ -2609,7 +2608,7 @@ var KnowledgeService = class _KnowledgeService extends Service {
|
|
|
2609
2608
|
return !!existingDocument;
|
|
2610
2609
|
}
|
|
2611
2610
|
async getKnowledge(message, scope) {
|
|
2612
|
-
logger6.debug(
|
|
2611
|
+
logger6.debug(`KnowledgeService: getKnowledge called for message id: ${message.id}`);
|
|
2613
2612
|
if (!message?.content?.text || message?.content?.text.trim().length === 0) {
|
|
2614
2613
|
logger6.warn("KnowledgeService: Invalid or empty message content for knowledge query.");
|
|
2615
2614
|
return [];
|
|
@@ -2900,7 +2899,7 @@ var KnowledgeService = class _KnowledgeService extends Service {
|
|
|
2900
2899
|
return chunks.map((chunk, index) => {
|
|
2901
2900
|
const fragmentIdContent = `${document.id}-fragment-${index}-${Date.now()}`;
|
|
2902
2901
|
const fragmentId = createUniqueUuid(
|
|
2903
|
-
this.runtime
|
|
2902
|
+
this.runtime,
|
|
2904
2903
|
fragmentIdContent
|
|
2905
2904
|
);
|
|
2906
2905
|
return {
|
|
@@ -4016,7 +4015,7 @@ var processKnowledgeAction = {
|
|
|
4016
4015
|
};
|
|
4017
4016
|
const result = await service.addKnowledge(knowledgeOptions);
|
|
4018
4017
|
response = {
|
|
4019
|
-
text: `I've successfully processed the document "${fileName}". It has been split into ${result
|
|
4018
|
+
text: `I've successfully processed the document "${fileName}". It has been split into ${result?.fragmentCount || 0} searchable fragments and added to my knowledge base.`
|
|
4020
4019
|
};
|
|
4021
4020
|
} else {
|
|
4022
4021
|
const knowledgeContent = text.replace(/^(add|store|remember|process|learn)\s+(this|that|the following)?:?\s*/i, "").trim();
|
|
@@ -4038,7 +4037,7 @@ var processKnowledgeAction = {
|
|
|
4038
4037
|
roomId: message.roomId,
|
|
4039
4038
|
entityId: message.entityId
|
|
4040
4039
|
};
|
|
4041
|
-
|
|
4040
|
+
await service.addKnowledge(knowledgeOptions);
|
|
4042
4041
|
response = {
|
|
4043
4042
|
text: `I've added that information to my knowledge base. It has been stored and indexed for future reference.`
|
|
4044
4043
|
};
|
|
@@ -4534,22 +4533,27 @@ async function getKnowledgeByIdHandler(req, res, runtime) {
|
|
|
4534
4533
|
async function knowledgePanelHandler(req, res, runtime) {
|
|
4535
4534
|
const agentId = runtime.agentId;
|
|
4536
4535
|
logger9.debug(`[Document Processor] \u{1F310} Serving knowledge panel for agent ${agentId}`);
|
|
4536
|
+
const requestPath = req.originalUrl || req.url || req.path;
|
|
4537
|
+
const pluginBasePath = requestPath.replace(/\/display.*$/, "");
|
|
4538
|
+
logger9.debug(`[Document Processor] \u{1F310} Plugin base path: ${pluginBasePath}`);
|
|
4537
4539
|
try {
|
|
4538
4540
|
const currentDir = path4.dirname(new URL(import.meta.url).pathname);
|
|
4539
4541
|
const frontendPath = path4.join(currentDir, "../dist/index.html");
|
|
4540
4542
|
logger9.debug(`[Document Processor] \u{1F310} Looking for frontend at: ${frontendPath}`);
|
|
4541
4543
|
if (fs4.existsSync(frontendPath)) {
|
|
4542
4544
|
const html = await fs4.promises.readFile(frontendPath, "utf8");
|
|
4543
|
-
|
|
4545
|
+
let injectedHtml = html.replace(
|
|
4544
4546
|
"<head>",
|
|
4545
4547
|
`<head>
|
|
4546
4548
|
<script>
|
|
4547
4549
|
window.ELIZA_CONFIG = {
|
|
4548
4550
|
agentId: '${agentId}',
|
|
4549
|
-
apiBase: '
|
|
4551
|
+
apiBase: '${pluginBasePath}'
|
|
4550
4552
|
};
|
|
4551
4553
|
</script>`
|
|
4552
4554
|
);
|
|
4555
|
+
injectedHtml = injectedHtml.replace(/src="\.\/assets\//g, `src="${pluginBasePath}/assets/`);
|
|
4556
|
+
injectedHtml = injectedHtml.replace(/href="\.\/assets\//g, `href="${pluginBasePath}/assets/`);
|
|
4553
4557
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
4554
4558
|
res.end(injectedHtml);
|
|
4555
4559
|
} else {
|
|
@@ -4585,10 +4589,10 @@ async function knowledgePanelHandler(req, res, runtime) {
|
|
|
4585
4589
|
<script>
|
|
4586
4590
|
window.ELIZA_CONFIG = {
|
|
4587
4591
|
agentId: '${agentId}',
|
|
4588
|
-
apiBase: '
|
|
4592
|
+
apiBase: '${pluginBasePath}'
|
|
4589
4593
|
};
|
|
4590
4594
|
</script>
|
|
4591
|
-
<link rel="stylesheet" href="
|
|
4595
|
+
<link rel="stylesheet" href="${pluginBasePath}/assets/${cssFile}">
|
|
4592
4596
|
<style>
|
|
4593
4597
|
body { font-family: system-ui, -apple-system, sans-serif; margin: 0; padding: 20px; }
|
|
4594
4598
|
.container { max-width: 1200px; margin: 0 auto; }
|
|
@@ -4601,7 +4605,7 @@ async function knowledgePanelHandler(req, res, runtime) {
|
|
|
4601
4605
|
<div class="loading">Loading Knowledge Library...</div>
|
|
4602
4606
|
</div>
|
|
4603
4607
|
</div>
|
|
4604
|
-
<script type="module" src="
|
|
4608
|
+
<script type="module" src="${pluginBasePath}/assets/${jsFile}"></script>
|
|
4605
4609
|
</body>
|
|
4606
4610
|
</html>`;
|
|
4607
4611
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
@@ -4614,21 +4618,25 @@ async function knowledgePanelHandler(req, res, runtime) {
|
|
|
4614
4618
|
}
|
|
4615
4619
|
async function frontendAssetHandler(req, res, runtime) {
|
|
4616
4620
|
try {
|
|
4617
|
-
|
|
4621
|
+
const fullPath = req.originalUrl || req.url || req.path;
|
|
4622
|
+
logger9.debug(`[Document Processor] \u{1F310} Asset request: ${fullPath}`);
|
|
4618
4623
|
const currentDir = path4.dirname(new URL(import.meta.url).pathname);
|
|
4619
|
-
const assetRequestPath = req.path;
|
|
4620
4624
|
const assetsMarker = "/assets/";
|
|
4621
|
-
const assetsStartIndex =
|
|
4625
|
+
const assetsStartIndex = fullPath.lastIndexOf(assetsMarker);
|
|
4622
4626
|
let assetName = null;
|
|
4623
4627
|
if (assetsStartIndex !== -1) {
|
|
4624
|
-
assetName =
|
|
4628
|
+
assetName = fullPath.substring(assetsStartIndex + assetsMarker.length);
|
|
4629
|
+
const queryIndex = assetName.indexOf("?");
|
|
4630
|
+
if (queryIndex !== -1) {
|
|
4631
|
+
assetName = assetName.substring(0, queryIndex);
|
|
4632
|
+
}
|
|
4625
4633
|
}
|
|
4626
4634
|
if (!assetName || assetName.includes("..")) {
|
|
4627
4635
|
return sendError(
|
|
4628
4636
|
res,
|
|
4629
4637
|
400,
|
|
4630
4638
|
"BAD_REQUEST",
|
|
4631
|
-
`Invalid asset name: '${assetName}' from path ${
|
|
4639
|
+
`Invalid asset name: '${assetName}' from path ${fullPath}`
|
|
4632
4640
|
);
|
|
4633
4641
|
}
|
|
4634
4642
|
const assetPath = path4.join(currentDir, "../dist/assets", assetName);
|