@eko-ai/eko 4.0.9 → 4.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"eko.d.ts","sourceRoot":"","sources":["../../src/agent/eko.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGjC,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EACL,SAAS,EACT,SAAS,EACT,QAAQ,EACR,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAI9B,qBAAa,GAAG;IACd,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC;gBAEhB,MAAM,EAAE,SAAS,EAAE,MAAM,GAAE,MAAiB;IAK3C,QAAQ,CACnB,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,MAAiB,EACzB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnC,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,QAAQ,CAAC;IA8BP,MAAM,CACjB,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,QAAQ,CAAC;IAcP,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IA+B3C,GAAG,CACd,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,MAAiB,EACzB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAClC,OAAO,CAAC,SAAS,CAAC;IAKR,WAAW,CACtB,QAAQ,EAAE,QAAQ,EAClB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAClC,OAAO,CAAC,WAAW,CAAC;YA0BT,aAAa;cAiHX,QAAQ,CACt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ool[];
7
7
  protected chatContext: ChatContext;
8
+ protected maxReactLoopNum: number;
8
9
  constructor(config: EkoDialogueConfig, chatId?: string, memory?: EkoMemory, tools?: DialogueTool[]);
9
10
  chat(params: DialogueParams): Promise<string>;
10
11
  private doChat;
11
12
  initMessages(): Promise<void>;
12
13
  protected buildSystemPrompt(params: DialogueParams, chatTools: DialogueTool[]): Promise<void>;
13
- protected addUserMessage(messageId: string, user: string | EkoMessageUserPart[]): Promise<EkoMessage>;
14
+ protected addUserMessage(messageId: string, user: EkoMessageUserPart[]): Promise<EkoMessage>;
14
15
  protected addMessages(messages: EkoMessage[], storage?: boolean): Promise<void>;
15
16
  protected buildInnerTools(params: DialogueParams): DialogueTool[];
16
17
  getMemory(): EkoMemory;
@@ -1 +1 @@
1
- {"version":3,"file":"chat-agent.d.ts","sourceRoot":"","sources":["../../src/chat/chat-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAEV,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,2BAA2B,EAE5B,MAAM,UAAU,CAAC;AASlB,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAS7C,qBAAa,SAAS;IACpB,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC;IAC5B,SAAS,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC;IAChC,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC;gBAGjC,MAAM,EAAE,iBAAiB,EACzB,MAAM,GAAE,MAAiB,EACzB,MAAM,CAAC,EAAE,SAAS,EAClB,KAAK,CAAC,EAAE,YAAY,EAAE;IAQX,IAAI,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;YAI5C,MAAM;IAyEP,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;cAe1B,iBAAiB,CAC/B,MAAM,EAA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M,CAAC,EAAE,SAAS,EAClB,KAAK,CAAC,EAAE,YAAY,EAAE;IAQX,IAAI,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;YAI5C,MAAM;IAyEP,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;cAe1B,iBAAiB,CAC/B,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,YAAY,EAAE,GACxB,OAAO,CAAC,IAAI,CAAC;cAsCA,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,kBAAkB,EAAE,GACzB,OAAO,CAAC,UAAU,CAAC;cAWN,WAAW,CACzB,QAAQ,EAAE,UAAU,EAAE,EACtB,OAAO,GAAE,OAAc,GACtB,OAAO,CAAC,IAAI,CAAC;IAUhB,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY,EAAE;IAc1D,SAAS,IAAI,SAAS;IAItB,QAAQ,IAAI,YAAY,EAAE;IAI1B,cAAc,IAAI,WAAW;cAIpB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,YAAY,EAAE,EACzB,OAAO,EAAE,KAAK,CAAC,uBAAuB,GAAG,2BAA2B,CAAC,EACrE,kBAAkB,CAAC,EAAE,kBAAkB,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAyE1B"}
@@ -2,7 +2,8 @@ import { ChatAgent } from "./chat-agent";
2
2
  import { ChatContext } from "./chat-context";
3
3
  import { WebSearchTool } from "./tools/web-search";
4
4
  import { WebpageQaTool } from "./tools/webpage-qa";
5
+ import AgentWrapTool from "./tools/agent-wrap-tool";
5
6
  import { DeepActionTool } from "./tools/deep-action";
6
7
  import { TaskVariableStorageTool } from "./tools/variable-storage";
7
- export { ChatAgent, ChatContext, WebSearchTool, WebpageQaTool, DeepActionTool, TaskVariableStorageTool, };
8
+ export { ChatAgent, ChatContext, AgentWrapTool, WebSearchTool, WebpageQaTool, DeepActionTool, TaskVariableStorageTool, };
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/chat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EACL,SAAS,EACT,WAAW,EACX,aAAa,EACb,aAAa,EACb,cAAc,EACd,uBAAuB,GACxB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/chat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,aAAa,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EACL,SAAS,EACT,WAAW,EACX,aAAa,EACb,aAAa,EACb,aAAa,EACb,cAAc,EACd,uBAAuB,GACxB,CAAC"}
@@ -38420,7 +38420,7 @@ const global = {
38420
38420
  prompts: new Map(),
38421
38421
  };
38422
38422
 
38423
- var GlobalPromptKey;
38423
+ exports.GlobalPromptKey = void 0;
38424
38424
  (function (GlobalPromptKey) {
38425
38425
  GlobalPromptKey["planner_system"] = "planner_system";
38426
38426
  GlobalPromptKey["planner_example"] = "planner_example";
@@ -38430,7 +38430,7 @@ var GlobalPromptKey;
38430
38430
  GlobalPromptKey["webpage_qa_prompt"] = "webpage_qa_prompt";
38431
38431
  GlobalPromptKey["deep_action_description"] = "deep_action_description";
38432
38432
  GlobalPromptKey["deep_action_param_task_description"] = "deep_action_param_task_description";
38433
- })(GlobalPromptKey || (GlobalPromptKey = {}));
38433
+ })(exports.GlobalPromptKey || (exports.GlobalPromptKey = {}));
38434
38434
 
38435
38435
  class PromptTemplate {
38436
38436
  /**
@@ -38750,8 +38750,8 @@ Attachments:
38750
38750
  `;
38751
38751
  async function getPlanSystemPrompt(context) {
38752
38752
  const agents_prompt = await buildAgentsPrompt(context.agents, context);
38753
- const planSysPrompt = global.prompts.get(GlobalPromptKey.planner_system) || PLAN_SYSTEM_TEMPLATE;
38754
- const planExamplePrompt = global.prompts.get(GlobalPromptKey.planner_example) || EXAMPLE_TEMPLATE;
38753
+ const planSysPrompt = global.prompts.get(exports.GlobalPromptKey.planner_system) || PLAN_SYSTEM_TEMPLATE;
38754
+ const planExamplePrompt = global.prompts.get(exports.GlobalPromptKey.planner_example) || EXAMPLE_TEMPLATE;
38755
38755
  return PromptTemplate.render(planSysPrompt, {
38756
38756
  name: config$1.name,
38757
38757
  agents: agents_prompt.trim(),
@@ -38759,7 +38759,7 @@ async function getPlanSystemPrompt(context) {
38759
38759
  }).trim();
38760
38760
  }
38761
38761
  function getPlanUserPrompt(context, taskPrompt) {
38762
- const planUserPrompt = global.prompts.get(GlobalPromptKey.planner_user) || PLAN_USER_TEMPLATE;
38762
+ const planUserPrompt = global.prompts.get(exports.GlobalPromptKey.planner_user) || PLAN_USER_TEMPLATE;
38763
38763
  return PromptTemplate.render(planUserPrompt, {
38764
38764
  taskPrompt: taskPrompt,
38765
38765
  platform: config$1.platform,
@@ -40392,7 +40392,7 @@ function getAgentSystemPrompt(agent, agentNode, context, tools, extSysPrompt) {
40392
40392
  mainTask = context.chain.taskPrompt.trim();
40393
40393
  preTaskResult = buildPreTaskResult(context);
40394
40394
  }
40395
- const agentSysPrompt = global.prompts.get(GlobalPromptKey.agent_system) || AGENT_SYSTEM_TEMPLATE;
40395
+ const agentSysPrompt = global.prompts.get(exports.GlobalPromptKey.agent_system) || AGENT_SYSTEM_TEMPLATE;
40396
40396
  return PromptTemplate.render(agentSysPrompt, {
40397
40397
  name: config$1.name,
40398
40398
  agent: agent.Name,
@@ -43217,7 +43217,7 @@ class EkoMemory {
43217
43217
  this.memoryConfig = memoryConfig;
43218
43218
  }
43219
43219
  genMessageId() {
43220
- return uuidv4();
43220
+ return "msg-" + uuidv4();
43221
43221
  }
43222
43222
  async import(data) {
43223
43223
  this.messages = [...data.messages];
@@ -44097,7 +44097,7 @@ class WebpageQaTool {
44097
44097
  const tabs = await global.browserService.extractPageContents(this.chatContext.getChatId(), tabIds);
44098
44098
  const chatConfig = this.chatContext.getConfig();
44099
44099
  const rlm = new RetryLanguageModel(chatConfig.llms, chatConfig.chatLlms);
44100
- const prompt = PromptTemplate.render(global.prompts.get(GlobalPromptKey.webpage_qa_prompt) ||
44100
+ const prompt = PromptTemplate.render(global.prompts.get(exports.GlobalPromptKey.webpage_qa_prompt) ||
44101
44101
  WEBPAGE_QA_PROMPT, {
44102
44102
  language: language,
44103
44103
  userPrompt: this.params.user
@@ -44259,9 +44259,9 @@ class DeepActionTool {
44259
44259
  this.chatContext = chatContext;
44260
44260
  const agents = this.chatContext.getConfig().agents || [];
44261
44261
  const agentNames = agents.map((agent) => agent.Name).join(", ");
44262
- const description = global.prompts.get(GlobalPromptKey.deep_action_description) ||
44262
+ const description = global.prompts.get(exports.GlobalPromptKey.deep_action_description) ||
44263
44263
  deep_action_description;
44264
- const paramTaskDescription = global.prompts.get(GlobalPromptKey.deep_action_param_task_description) ||
44264
+ const paramTaskDescription = global.prompts.get(exports.GlobalPromptKey.deep_action_param_task_description) ||
44265
44265
  deep_action_param_task_description;
44266
44266
  this.description = description.replace("{agentNames}", agentNames).trim();
44267
44267
  this.parameters = {
@@ -44513,7 +44513,7 @@ Current datetime: {{datetime}}
44513
44513
  The output language should match the user's conversation language.
44514
44514
  `;
44515
44515
  function getChatSystemPrompt(tools, datetime, memory, tabs) {
44516
- const systemPrompt = global.prompts.get(GlobalPromptKey.chat_system) || CHAT_SYSTEM_TEMPLATE;
44516
+ const systemPrompt = global.prompts.get(exports.GlobalPromptKey.chat_system) || CHAT_SYSTEM_TEMPLATE;
44517
44517
  const toolVars = {};
44518
44518
  for (let i = 0; i < tools.length; i++) {
44519
44519
  toolVars[tools[i].name + "Tool"] = true;
@@ -44542,7 +44542,8 @@ function getTabsInfo(tabs) {
44542
44542
  }
44543
44543
 
44544
44544
  class ChatAgent {
44545
- constructor(config, chatId = uuidv4(), memory, tools) {
44545
+ constructor(config, chatId = "chat-" + uuidv4(), memory, tools) {
44546
+ this.maxReactLoopNum = 15;
44546
44547
  this.tools = tools ?? [];
44547
44548
  this.memory = memory ?? new EkoMemory();
44548
44549
  this.chatContext = new ChatContext(chatId, config);
@@ -44569,7 +44570,7 @@ class ChatAgent {
44569
44570
  await this.addUserMessage(params.messageId, params.user);
44570
44571
  const config = this.chatContext.getConfig();
44571
44572
  const rlm = new RetryLanguageModel(config.llms, config.chatLlms);
44572
- for (; reactLoopNum < 15; reactLoopNum++) {
44573
+ for (; reactLoopNum < this.maxReactLoopNum; reactLoopNum++) {
44573
44574
  const messages = this.memory.buildMessages();
44574
44575
  const results = await callChatLLM(this.chatContext.getChatId(), params.messageId, rlm, messages, convertTools(chatTools), undefined, params.callback, params.signal);
44575
44576
  const finalResult = await this.handleCallResult(params.messageId, chatTools, results, params.callback);
@@ -44764,9 +44765,174 @@ class ChatAgent {
44764
44765
  }
44765
44766
  }
44766
44767
 
44768
+ class AgentWrapTool {
44769
+ constructor(chatContext, params, agent, extra) {
44770
+ this.agent = agent;
44771
+ this.params = params;
44772
+ this.chatContext = chatContext;
44773
+ this.name =
44774
+ extra?.name ||
44775
+ agent.Name.substring(0, 1).toLowerCase() + agent.Name.substring(1);
44776
+ this.description =
44777
+ extra?.description ||
44778
+ agent.PlanDescription ||
44779
+ sub(agent.Description, 600, true, false);
44780
+ this.parameters = extra?.parameters || {
44781
+ type: "object",
44782
+ properties: {
44783
+ language: {
44784
+ type: "string",
44785
+ description: "User language used, eg: English",
44786
+ },
44787
+ taskDescription: {
44788
+ type: "string",
44789
+ description: "Task description, please do not omit any information from the user's instructions, and use the same language as the user's question.",
44790
+ },
44791
+ tabIds: {
44792
+ type: "array",
44793
+ description: "Browser Tab IDs associated with this task, When user says 'left side' or 'current', it means current active tab",
44794
+ items: { type: "integer" },
44795
+ },
44796
+ dependentVariables: {
44797
+ type: "array",
44798
+ description: "The current task relies on variable data from prerequisite execution outputs. Provide the name of the dependent variable.",
44799
+ items: {
44800
+ type: "string",
44801
+ },
44802
+ },
44803
+ },
44804
+ required: ["language", "taskDescription"],
44805
+ };
44806
+ }
44807
+ async execute(args, toolCall, messageId) {
44808
+ const chatId = this.chatContext.getChatId();
44809
+ const language = args.language;
44810
+ const taskDescription = args.taskDescription;
44811
+ const tabIds = args.tabIds;
44812
+ const dependentVariables = args.dependentVariables;
44813
+ const globalVariables = this.chatContext.getGlobalVariables();
44814
+ const attachments = this.params.user
44815
+ .filter((part) => part.type === "file")
44816
+ .filter((part) => part.data && part.data.length < 500)
44817
+ .map((part) => {
44818
+ return {
44819
+ file_name: part.filename,
44820
+ file_path: part.filePath,
44821
+ file_url: part.data,
44822
+ };
44823
+ });
44824
+ const taskWebsite = await this.getTaskWebsite(tabIds);
44825
+ const config = this.chatContext.getConfig();
44826
+ const contextParams = {
44827
+ ...(this.params.extra || {}),
44828
+ ...globalVariables,
44829
+ tabIds: tabIds,
44830
+ language: language,
44831
+ attachments: attachments,
44832
+ taskWebsite: taskWebsite,
44833
+ dependentVariables: dependentVariables,
44834
+ datetime: this.params.datetime || new Date().toLocaleString(),
44835
+ };
44836
+ const agents = [this.agent];
44837
+ const chain = new Chain(taskDescription);
44838
+ const taskId = messageId;
44839
+ const context = new TaskContext(chatId, taskId, {
44840
+ ...config,
44841
+ callback: this.params.callback?.taskCallback,
44842
+ }, agents, chain);
44843
+ if (contextParams) {
44844
+ Object.keys(contextParams).forEach((key) => context.variables.set(key, contextParams[key]));
44845
+ }
44846
+ context.workflow = buildSimpleAgentWorkflow({
44847
+ taskId,
44848
+ name: "Task",
44849
+ agentName: this.agent.Name,
44850
+ task: taskDescription,
44851
+ });
44852
+ try {
44853
+ global.taskMap.set(taskId, context);
44854
+ const agentNode = context.workflow.agents[0];
44855
+ const resultText = await this.runAgent(context, this.agent, {
44856
+ type: "normal",
44857
+ agent: agentNode,
44858
+ }, new AgentChain(agentNode));
44859
+ return {
44860
+ content: [
44861
+ {
44862
+ type: "text",
44863
+ text: resultText || "",
44864
+ },
44865
+ ],
44866
+ };
44867
+ }
44868
+ finally {
44869
+ global.taskMap.delete(taskId);
44870
+ }
44871
+ }
44872
+ async runAgent(context, agent, agentNode, agentChain) {
44873
+ const callback = this.params.callback?.taskCallback;
44874
+ try {
44875
+ agentNode.agent.status = "running";
44876
+ callback &&
44877
+ (await callback.onMessage({
44878
+ streamType: "agent",
44879
+ chatId: context.chatId,
44880
+ taskId: context.taskId,
44881
+ agentName: agentNode.agent.name,
44882
+ nodeId: agentNode.agent.id,
44883
+ type: "agent_start",
44884
+ agentNode: agentNode.agent,
44885
+ }, agent.AgentContext));
44886
+ agentNode.result = await agent.run(context, agentChain);
44887
+ agentNode.agent.status = "done";
44888
+ callback &&
44889
+ (await callback.onMessage({
44890
+ streamType: "agent",
44891
+ chatId: context.chatId,
44892
+ taskId: context.taskId,
44893
+ agentName: agentNode.agent.name,
44894
+ nodeId: agentNode.agent.id,
44895
+ type: "agent_result",
44896
+ agentNode: agentNode.agent,
44897
+ result: agentNode.result,
44898
+ }, agent.AgentContext));
44899
+ return agentNode.result;
44900
+ }
44901
+ catch (e) {
44902
+ agentNode.agent.status = "error";
44903
+ callback &&
44904
+ (await callback.onMessage({
44905
+ streamType: "agent",
44906
+ chatId: context.chatId,
44907
+ taskId: context.taskId,
44908
+ agentName: agentNode.agent.name,
44909
+ nodeId: agentNode.agent.id,
44910
+ type: "agent_result",
44911
+ agentNode: agentNode.agent,
44912
+ error: e,
44913
+ }, agent.AgentContext));
44914
+ throw e;
44915
+ }
44916
+ }
44917
+ async getTaskWebsite(tabIds) {
44918
+ if (!global.browserService) {
44919
+ return [];
44920
+ }
44921
+ const tabs = await global.browserService.loadTabs(this.chatContext.getChatId(), tabIds);
44922
+ return tabs.map((tab) => {
44923
+ return {
44924
+ tabId: tab.tabId,
44925
+ title: tab.title,
44926
+ url: sub(tab.url, 300),
44927
+ };
44928
+ });
44929
+ }
44930
+ }
44931
+
44767
44932
  exports.Agent = Agent;
44768
44933
  exports.AgentChain = AgentChain;
44769
44934
  exports.AgentContext = AgentContext;
44935
+ exports.AgentWrapTool = AgentWrapTool;
44770
44936
  exports.BaseBrowserAgent = BaseBrowserAgent;
44771
44937
  exports.BaseBrowserLabelsAgent = BaseBrowserLabelsAgent;
44772
44938
  exports.BaseBrowserScreenAgent = BaseBrowserScreenAgent;
@@ -44810,4 +44976,4 @@ exports.sub = sub;
44810
44976
  exports.toFile = toFile;
44811
44977
  exports.toImage = toImage;
44812
44978
  exports.uuidv4 = uuidv4;
44813
- //# sourceMappingURL=index.cjs.js.map
44979
+ //# sourceMappingURL=index.cjs.map