@eko-ai/eko 4.0.8 → 4.0.9
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/agent/base.d.ts.map +1 -1
- package/dist/chat/chat-agent.d.ts.map +1 -1
- package/dist/chat/tools/agent-wrap-tool.d.ts +24 -0
- package/dist/chat/tools/agent-wrap-tool.d.ts.map +1 -0
- package/dist/chat/tools/deep-action.d.ts +1 -1
- package/dist/common/xml.d.ts.map +1 -1
- package/dist/index.cjs.js +84 -54
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +84 -54
- package/dist/index.esm.js.map +1 -1
- package/dist/llm/react.d.ts +2 -1
- package/dist/llm/react.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/llm.types.d.ts +5 -1
- package/dist/types/llm.types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -36671,7 +36671,7 @@ function parseWorkflow(taskId, xml, done, thinking) {
|
|
|
36671
36671
|
}
|
|
36672
36672
|
const parser = new libExports.DOMParser();
|
|
36673
36673
|
const doc = parser.parseFromString(xml, "text/xml");
|
|
36674
|
-
|
|
36674
|
+
const root = doc.documentElement;
|
|
36675
36675
|
if (root.tagName !== "root") {
|
|
36676
36676
|
return _workflow;
|
|
36677
36677
|
}
|
|
@@ -36684,11 +36684,11 @@ function parseWorkflow(taskId, xml, done, thinking) {
|
|
|
36684
36684
|
agents: agents,
|
|
36685
36685
|
xml: xml,
|
|
36686
36686
|
};
|
|
36687
|
-
|
|
36688
|
-
|
|
36687
|
+
const agentsNode = root.getElementsByTagName("agents");
|
|
36688
|
+
const agentsNodes = agentsNode.length > 0 ? agentsNode[0].getElementsByTagName("agent") : [];
|
|
36689
36689
|
for (let i = 0; i < agentsNodes.length; i++) {
|
|
36690
|
-
|
|
36691
|
-
|
|
36690
|
+
const agentNode = agentsNodes[i];
|
|
36691
|
+
const name = agentNode.getAttribute("name");
|
|
36692
36692
|
if (!name) {
|
|
36693
36693
|
break;
|
|
36694
36694
|
}
|
|
@@ -36698,12 +36698,15 @@ function parseWorkflow(taskId, xml, done, thinking) {
|
|
|
36698
36698
|
let agent = {
|
|
36699
36699
|
name: name,
|
|
36700
36700
|
id: getAgentId(taskId, index),
|
|
36701
|
-
dependsOn: dependsOn
|
|
36701
|
+
dependsOn: dependsOn
|
|
36702
|
+
.split(",")
|
|
36703
|
+
.filter((idx) => idx.trim() != "")
|
|
36704
|
+
.map((idx) => getAgentId(taskId, idx)),
|
|
36702
36705
|
task: agentNode.getElementsByTagName("task")[0]?.textContent || "",
|
|
36703
36706
|
nodes: nodes,
|
|
36704
36707
|
status: "init",
|
|
36705
36708
|
parallel: undefined,
|
|
36706
|
-
xml: agentNode.toString(),
|
|
36709
|
+
xml: " " + agentNode.toString(),
|
|
36707
36710
|
};
|
|
36708
36711
|
let xmlNodes = agentNode.getElementsByTagName("nodes");
|
|
36709
36712
|
if (xmlNodes.length > 0) {
|
|
@@ -36749,7 +36752,7 @@ function parseWorkflowNodes(nodes, xmlNodes) {
|
|
|
36749
36752
|
if (xmlNodes[i].nodeType !== 1) {
|
|
36750
36753
|
continue;
|
|
36751
36754
|
}
|
|
36752
|
-
|
|
36755
|
+
const xmlNode = xmlNodes[i];
|
|
36753
36756
|
switch (xmlNode.tagName) {
|
|
36754
36757
|
case "node": {
|
|
36755
36758
|
let node = {
|
|
@@ -36797,10 +36800,10 @@ function parseWorkflowNodes(nodes, xmlNodes) {
|
|
|
36797
36800
|
function buildAgentRootXml(agentXml, mainTaskPrompt, nodeCallback) {
|
|
36798
36801
|
const parser = new libExports.DOMParser();
|
|
36799
36802
|
const doc = parser.parseFromString(agentXml, "text/xml");
|
|
36800
|
-
|
|
36801
|
-
|
|
36803
|
+
const agentNode = doc.getElementsByTagName("agent");
|
|
36804
|
+
const nodesNode = doc.getElementsByTagName("nodes");
|
|
36802
36805
|
if (nodesNode.length > 0) {
|
|
36803
|
-
|
|
36806
|
+
const nodes = nodesNode[0].childNodes;
|
|
36804
36807
|
let nodeId = 0;
|
|
36805
36808
|
for (let i = 0; i < nodes.length; i++) {
|
|
36806
36809
|
let node = nodes[i];
|
|
@@ -36811,21 +36814,27 @@ function buildAgentRootXml(agentXml, mainTaskPrompt, nodeCallback) {
|
|
|
36811
36814
|
}
|
|
36812
36815
|
}
|
|
36813
36816
|
}
|
|
36814
|
-
// <root><mainTask></mainTask><currentTask></currentTask><nodes><node id="0"></node></nodes></root>
|
|
36815
36817
|
let agentInnerHTML = getInnerXML(agentNode[0]);
|
|
36816
|
-
|
|
36818
|
+
const prefix = agentInnerHTML.substring(0, agentInnerHTML.indexOf("<task>"));
|
|
36817
36819
|
agentInnerHTML = agentInnerHTML
|
|
36818
36820
|
.replace("<task>", "<currentTask>")
|
|
36819
36821
|
.replace("</task>", "</currentTask>");
|
|
36820
|
-
|
|
36822
|
+
let xmlPrompt;
|
|
36823
|
+
if (agentInnerHTML.indexOf(`<currentTask>${mainTaskPrompt}</currentTask>`) > -1) {
|
|
36824
|
+
xmlPrompt = `<root>${agentInnerHTML}</root>`;
|
|
36825
|
+
}
|
|
36826
|
+
else {
|
|
36827
|
+
// <root><mainTask></mainTask><currentTask></currentTask><nodes><node id="0"></node></nodes></root>
|
|
36828
|
+
xmlPrompt = `<root>${prefix}<mainTask>${mainTaskPrompt}</mainTask>${agentInnerHTML}</root>`;
|
|
36829
|
+
}
|
|
36821
36830
|
return xmlPrompt.replace(/ /g, " ").replace(" </root>", "</root>");
|
|
36822
36831
|
}
|
|
36823
36832
|
function extractAgentXmlNode(agentXml, nodeId) {
|
|
36824
36833
|
const parser = new libExports.DOMParser();
|
|
36825
36834
|
const doc = parser.parseFromString(agentXml, "text/xml");
|
|
36826
|
-
|
|
36835
|
+
const nodesNode = doc.getElementsByTagName("nodes");
|
|
36827
36836
|
if (nodesNode.length > 0) {
|
|
36828
|
-
|
|
36837
|
+
const nodes = nodesNode[0].childNodes;
|
|
36829
36838
|
let _nodeId = 0;
|
|
36830
36839
|
for (let i = 0; i < nodes.length; i++) {
|
|
36831
36840
|
let node = nodes[i];
|
|
@@ -36851,8 +36860,8 @@ function getInnerXML(node) {
|
|
|
36851
36860
|
return result;
|
|
36852
36861
|
}
|
|
36853
36862
|
function buildSimpleAgentWorkflow({ taskId, name, agentName, task, taskNodes, }) {
|
|
36854
|
-
if (!taskNodes
|
|
36855
|
-
taskNodes = [
|
|
36863
|
+
if (!taskNodes) {
|
|
36864
|
+
taskNodes = [];
|
|
36856
36865
|
}
|
|
36857
36866
|
const workflow = {
|
|
36858
36867
|
taskId: taskId,
|
|
@@ -36885,7 +36894,9 @@ function resetWorkflowXml(workflow) {
|
|
|
36885
36894
|
const agents = [];
|
|
36886
36895
|
for (let i = 0; i < workflow.agents.length; i++) {
|
|
36887
36896
|
const agent = workflow.agents[i];
|
|
36888
|
-
const agentDependsAttr = ` id="${i}" dependsOn="${(agent.dependsOn || [])
|
|
36897
|
+
const agentDependsAttr = ` id="${i}" dependsOn="${(agent.dependsOn || [])
|
|
36898
|
+
.filter((s) => parseInt(s.split("-")[s.split("-").length - 1]))
|
|
36899
|
+
.join(",")}"`;
|
|
36889
36900
|
const nodes = agent.nodes
|
|
36890
36901
|
.map((node) => {
|
|
36891
36902
|
if (node.type == "forEach") {
|
|
@@ -36896,9 +36907,8 @@ function resetWorkflowXml(workflow) {
|
|
|
36896
36907
|
const output = _node.output ? ` output="${_node.output}"` : "";
|
|
36897
36908
|
forEachNodes.push(` <node${input}${output}>${_node.text}</node>`);
|
|
36898
36909
|
}
|
|
36899
|
-
|
|
36900
|
-
${forEachNodes.join("\n")}
|
|
36901
|
-
</forEach>`;
|
|
36910
|
+
const items = node.items || "";
|
|
36911
|
+
return ` <forEach items="${items}">\n${forEachNodes.join("\n")}\n </forEach>`;
|
|
36902
36912
|
}
|
|
36903
36913
|
else if (node.type == "watch") {
|
|
36904
36914
|
const watchNodes = [];
|
|
@@ -36908,12 +36918,9 @@ ${forEachNodes.join("\n")}
|
|
|
36908
36918
|
const output = _node.output ? ` output="${_node.output}"` : "";
|
|
36909
36919
|
watchNodes.push(` <node${input}${output}>${_node.text}</node>`);
|
|
36910
36920
|
}
|
|
36911
|
-
|
|
36912
|
-
|
|
36913
|
-
<trigger
|
|
36914
|
-
${watchNodes.join("\n")}
|
|
36915
|
-
</trigger>
|
|
36916
|
-
</watch>`;
|
|
36921
|
+
const event = node.event || "dom";
|
|
36922
|
+
const loop = node.loop ? "true" : "false";
|
|
36923
|
+
return ` <watch event="${event}" loop="${loop}">\n <description>${node.description}</description>\n <trigger>\n${watchNodes.join("\n")}\n </trigger>\n </watch>`;
|
|
36917
36924
|
}
|
|
36918
36925
|
else {
|
|
36919
36926
|
const input = node.input ? ` input="${node.input}"` : "";
|
|
@@ -36922,22 +36929,17 @@ ${watchNodes.join("\n")}
|
|
|
36922
36929
|
}
|
|
36923
36930
|
})
|
|
36924
36931
|
.join("\n");
|
|
36925
|
-
|
|
36926
|
-
|
|
36927
|
-
<nodes
|
|
36928
|
-
|
|
36929
|
-
|
|
36930
|
-
</agent>`;
|
|
36932
|
+
let agentXml;
|
|
36933
|
+
if (nodes.trim()) {
|
|
36934
|
+
agentXml = ` <agent name="${agent.name}"${agentDependsAttr}>\n <task>${agent.task}</task>\n <nodes>\n${nodes}\n </nodes>\n </agent>`;
|
|
36935
|
+
}
|
|
36936
|
+
else {
|
|
36937
|
+
agentXml = ` <agent name="${agent.name}"${agentDependsAttr}>\n <task>${agent.task}</task>\n </agent>`;
|
|
36938
|
+
}
|
|
36931
36939
|
agent.xml = agentXml;
|
|
36932
36940
|
agents.push(agentXml);
|
|
36933
36941
|
}
|
|
36934
|
-
const xml = `<root
|
|
36935
|
-
<name>${workflow.name}</name>
|
|
36936
|
-
<thought>${workflow.thought}</thought>
|
|
36937
|
-
<agents>
|
|
36938
|
-
${agents.join("\n")}
|
|
36939
|
-
</agents>
|
|
36940
|
-
</root>`;
|
|
36942
|
+
const xml = `<root>\n <name>${workflow.name}</name>\n <thought>${workflow.thought}</thought>\n <agents>\n${agents.join("\n")}\n </agents>\n</root>`;
|
|
36941
36943
|
workflow.xml = xml;
|
|
36942
36944
|
}
|
|
36943
36945
|
|
|
@@ -38012,7 +38014,9 @@ async function callWithReAct(rlm, request, toolCallsOrCallback, streamCallback,
|
|
|
38012
38014
|
};
|
|
38013
38015
|
}
|
|
38014
38016
|
if (typeof toolCallsOrCallback !== "function") {
|
|
38015
|
-
request.tools =
|
|
38017
|
+
request.tools = (Array.isArray(toolCallsOrCallback)
|
|
38018
|
+
? toolCallsOrCallback
|
|
38019
|
+
: toolCallsOrCallback.tools).map((tool) => ({
|
|
38016
38020
|
type: "function",
|
|
38017
38021
|
name: tool.name,
|
|
38018
38022
|
description: tool.description,
|
|
@@ -38050,16 +38054,33 @@ async function callWithReAct(rlm, request, toolCallsOrCallback, streamCallback,
|
|
|
38050
38054
|
toolResults = await toolCallsOrCallback(request, toolUses);
|
|
38051
38055
|
}
|
|
38052
38056
|
else {
|
|
38053
|
-
|
|
38054
|
-
|
|
38055
|
-
|
|
38056
|
-
|
|
38057
|
-
|
|
38058
|
-
|
|
38059
|
-
|
|
38060
|
-
|
|
38061
|
-
|
|
38062
|
-
|
|
38057
|
+
const tools = Array.isArray(toolCallsOrCallback)
|
|
38058
|
+
? toolCallsOrCallback
|
|
38059
|
+
: toolCallsOrCallback.tools;
|
|
38060
|
+
if (!Array.isArray(toolCallsOrCallback) && toolCallsOrCallback.callback) {
|
|
38061
|
+
toolResults = await toolCallsOrCallback.callback(request, toolUses, tools);
|
|
38062
|
+
}
|
|
38063
|
+
else {
|
|
38064
|
+
toolResults = await Promise.all(toolUses.map(async (toolUse) => {
|
|
38065
|
+
const tool = tools.find((t) => t.name === toolUse.toolName);
|
|
38066
|
+
if (!tool) {
|
|
38067
|
+
throw new Error(`Tool ${toolUse.toolName} not found`);
|
|
38068
|
+
}
|
|
38069
|
+
const args = typeof toolUse.input === "string"
|
|
38070
|
+
? JSON.parse(toolUse.input || "{}")
|
|
38071
|
+
: toolUse.input || {};
|
|
38072
|
+
try {
|
|
38073
|
+
return tool.execute(args, toolUse);
|
|
38074
|
+
}
|
|
38075
|
+
catch (e) {
|
|
38076
|
+
Log.error("tool call error: ", toolUse.toolName, toolUse.input, e);
|
|
38077
|
+
return {
|
|
38078
|
+
type: "error-text",
|
|
38079
|
+
value: "Error: " + (e + "") || "Unknown error",
|
|
38080
|
+
};
|
|
38081
|
+
}
|
|
38082
|
+
}));
|
|
38083
|
+
}
|
|
38063
38084
|
}
|
|
38064
38085
|
if (toolResults.length > 0) {
|
|
38065
38086
|
request.messages.push({
|
|
@@ -40566,6 +40587,12 @@ class Agent {
|
|
|
40566
40587
|
if (hasVariable) {
|
|
40567
40588
|
tools.push(new VariableStorageTool());
|
|
40568
40589
|
}
|
|
40590
|
+
else {
|
|
40591
|
+
const dependentVariables = agentContext.context.variables.get("dependentVariables");
|
|
40592
|
+
if (dependentVariables && dependentVariables.length > 0) {
|
|
40593
|
+
tools.push(new VariableStorageTool());
|
|
40594
|
+
}
|
|
40595
|
+
}
|
|
40569
40596
|
const hasForeach = agentNodeXml.indexOf("</forEach>") > -1;
|
|
40570
40597
|
if (hasForeach) {
|
|
40571
40598
|
tools.push(new ForeachTaskTool());
|
|
@@ -44263,7 +44290,7 @@ class DeepActionTool {
|
|
|
44263
44290
|
file_url: part.data,
|
|
44264
44291
|
};
|
|
44265
44292
|
});
|
|
44266
|
-
const taskWebsite = await this.
|
|
44293
|
+
const taskWebsite = await this.getTaskWebsite(tabIds);
|
|
44267
44294
|
const workflow = await eko.generate(taskDescription, messageId, {
|
|
44268
44295
|
...(this.params.extra || {}),
|
|
44269
44296
|
...globalVariables,
|
|
@@ -44312,7 +44339,7 @@ class DeepActionTool {
|
|
|
44312
44339
|
],
|
|
44313
44340
|
};
|
|
44314
44341
|
}
|
|
44315
|
-
async
|
|
44342
|
+
async getTaskWebsite(tabIds) {
|
|
44316
44343
|
if (!global.browserService) {
|
|
44317
44344
|
return [];
|
|
44318
44345
|
}
|
|
@@ -44612,6 +44639,9 @@ class ChatAgent {
|
|
|
44612
44639
|
}
|
|
44613
44640
|
tools.push(new WebSearchTool(this.chatContext, params));
|
|
44614
44641
|
tools.push(new TaskVariableStorageTool(this.chatContext, params));
|
|
44642
|
+
// this.chatContext.getConfig().agents?.forEach((agent) => {
|
|
44643
|
+
// tools.push(new AgentWrapTool(this.chatContext, params, agent));
|
|
44644
|
+
// });
|
|
44615
44645
|
return tools;
|
|
44616
44646
|
}
|
|
44617
44647
|
getMemory() {
|