@eko-ai/eko 2.1.4 → 2.1.5
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/core/context.d.ts +1 -0
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/index.cjs.js +63 -13
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +63 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/types/llm.types.d.ts +2 -2
- package/dist/types/llm.types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -371,6 +371,7 @@ function fixXmlTag(code) {
|
|
|
371
371
|
class Context {
|
|
372
372
|
constructor(taskId, config, agents, chain) {
|
|
373
373
|
this.paused = false;
|
|
374
|
+
this.conversation = [];
|
|
374
375
|
this.taskId = taskId;
|
|
375
376
|
this.config = config;
|
|
376
377
|
this.agents = agents;
|
|
@@ -14729,7 +14730,7 @@ class RetryLanguageModel {
|
|
|
14729
14730
|
const names = [...this.names, ...this.names];
|
|
14730
14731
|
for (let i = 0; i < names.length; i++) {
|
|
14731
14732
|
const name = names[i];
|
|
14732
|
-
const llm = this.getLLM(name);
|
|
14733
|
+
const llm = await this.getLLM(name);
|
|
14733
14734
|
if (!llm) {
|
|
14734
14735
|
continue;
|
|
14735
14736
|
}
|
|
@@ -14781,7 +14782,7 @@ class RetryLanguageModel {
|
|
|
14781
14782
|
const names = [...this.names, ...this.names];
|
|
14782
14783
|
for (let i = 0; i < names.length; i++) {
|
|
14783
14784
|
const name = names[i];
|
|
14784
|
-
const llm = this.getLLM(name);
|
|
14785
|
+
const llm = await this.getLLM(name);
|
|
14785
14786
|
if (!llm) {
|
|
14786
14787
|
continue;
|
|
14787
14788
|
}
|
|
@@ -14836,42 +14837,58 @@ class RetryLanguageModel {
|
|
|
14836
14837
|
}
|
|
14837
14838
|
return Promise.reject(new Error("No LLM available"));
|
|
14838
14839
|
}
|
|
14839
|
-
getLLM(name) {
|
|
14840
|
+
async getLLM(name) {
|
|
14840
14841
|
const llm = this.llms[name];
|
|
14841
14842
|
if (!llm) {
|
|
14842
14843
|
return null;
|
|
14843
14844
|
}
|
|
14845
|
+
let apiKey;
|
|
14846
|
+
if (typeof llm.apiKey === "string") {
|
|
14847
|
+
apiKey = llm.apiKey;
|
|
14848
|
+
}
|
|
14849
|
+
else {
|
|
14850
|
+
apiKey = await llm.apiKey();
|
|
14851
|
+
}
|
|
14852
|
+
let baseURL = undefined;
|
|
14853
|
+
if (llm.config?.baseURL) {
|
|
14854
|
+
if (typeof llm.config.baseURL === "string") {
|
|
14855
|
+
baseURL = llm.config.baseURL;
|
|
14856
|
+
}
|
|
14857
|
+
else {
|
|
14858
|
+
baseURL = await llm.config.baseURL();
|
|
14859
|
+
}
|
|
14860
|
+
}
|
|
14844
14861
|
if (llm.provider == "openai") {
|
|
14845
14862
|
return createOpenAI({
|
|
14846
|
-
apiKey:
|
|
14847
|
-
baseURL:
|
|
14863
|
+
apiKey: apiKey,
|
|
14864
|
+
baseURL: baseURL,
|
|
14848
14865
|
}).languageModel(llm.model);
|
|
14849
14866
|
}
|
|
14850
14867
|
else if (llm.provider == "anthropic") {
|
|
14851
14868
|
return createAnthropic({
|
|
14852
|
-
apiKey:
|
|
14853
|
-
baseURL:
|
|
14869
|
+
apiKey: apiKey,
|
|
14870
|
+
baseURL: baseURL,
|
|
14854
14871
|
}).languageModel(llm.model);
|
|
14855
14872
|
}
|
|
14856
14873
|
else if (llm.provider == "google") {
|
|
14857
14874
|
return createGoogleGenerativeAI({
|
|
14858
|
-
apiKey:
|
|
14859
|
-
baseURL:
|
|
14875
|
+
apiKey: apiKey,
|
|
14876
|
+
baseURL: baseURL,
|
|
14860
14877
|
}).languageModel(llm.model);
|
|
14861
14878
|
}
|
|
14862
14879
|
else if (llm.provider == "aws") {
|
|
14863
|
-
let keys =
|
|
14880
|
+
let keys = apiKey.split("=");
|
|
14864
14881
|
return createAmazonBedrock({
|
|
14865
14882
|
accessKeyId: keys[0],
|
|
14866
14883
|
secretAccessKey: keys[1],
|
|
14867
|
-
baseURL:
|
|
14884
|
+
baseURL: baseURL,
|
|
14868
14885
|
region: llm.config?.region || "us-west-1",
|
|
14869
14886
|
}).languageModel(llm.model);
|
|
14870
14887
|
}
|
|
14871
14888
|
else if (llm.provider == "openrouter") {
|
|
14872
14889
|
return createOpenRouter({
|
|
14873
|
-
apiKey:
|
|
14874
|
-
baseURL:
|
|
14890
|
+
apiKey: apiKey,
|
|
14891
|
+
baseURL: baseURL,
|
|
14875
14892
|
}).languageModel(llm.model);
|
|
14876
14893
|
}
|
|
14877
14894
|
else {
|
|
@@ -18790,6 +18807,29 @@ class Agent {
|
|
|
18790
18807
|
async handleMessages(agentContext, messages, tools) {
|
|
18791
18808
|
// Only keep the last image / file, large tool-text-result
|
|
18792
18809
|
handleLargeContextMessages(messages);
|
|
18810
|
+
// User dialogue
|
|
18811
|
+
const userPrompts = agentContext.context.conversation
|
|
18812
|
+
.splice(0, agentContext.context.conversation.length)
|
|
18813
|
+
.filter((s) => !!s);
|
|
18814
|
+
if (userPrompts.length > 0) {
|
|
18815
|
+
const lastMessage = messages[messages.length - 1];
|
|
18816
|
+
if (lastMessage.role == "user") {
|
|
18817
|
+
for (let i = 0; i < userPrompts.length; i++) {
|
|
18818
|
+
lastMessage.content.push({
|
|
18819
|
+
type: "text",
|
|
18820
|
+
text: userPrompts[i],
|
|
18821
|
+
});
|
|
18822
|
+
}
|
|
18823
|
+
}
|
|
18824
|
+
else {
|
|
18825
|
+
messages.push({
|
|
18826
|
+
role: "user",
|
|
18827
|
+
content: userPrompts.map((s) => {
|
|
18828
|
+
return { type: "text", text: s };
|
|
18829
|
+
}),
|
|
18830
|
+
});
|
|
18831
|
+
}
|
|
18832
|
+
}
|
|
18793
18833
|
}
|
|
18794
18834
|
async callInnerTool(fun) {
|
|
18795
18835
|
let result = await fun();
|
|
@@ -19392,6 +19432,7 @@ class Eko {
|
|
|
19392
19432
|
if (context.paused) {
|
|
19393
19433
|
context.paused = false;
|
|
19394
19434
|
}
|
|
19435
|
+
context.conversation = [];
|
|
19395
19436
|
if (context.controller.signal.aborted) {
|
|
19396
19437
|
context.controller = new AbortController();
|
|
19397
19438
|
}
|
|
@@ -19466,11 +19507,13 @@ class Eko {
|
|
|
19466
19507
|
return [...this.taskMap.keys()];
|
|
19467
19508
|
}
|
|
19468
19509
|
deleteTask(taskId) {
|
|
19510
|
+
this.abortTask(taskId);
|
|
19469
19511
|
return this.taskMap.delete(taskId);
|
|
19470
19512
|
}
|
|
19471
19513
|
abortTask(taskId) {
|
|
19472
19514
|
let context = this.taskMap.get(taskId);
|
|
19473
19515
|
if (context) {
|
|
19516
|
+
context.paused = false;
|
|
19474
19517
|
context.controller.abort();
|
|
19475
19518
|
return true;
|
|
19476
19519
|
}
|
|
@@ -19488,6 +19531,13 @@ class Eko {
|
|
|
19488
19531
|
return false;
|
|
19489
19532
|
}
|
|
19490
19533
|
}
|
|
19534
|
+
chatTask(taskId, userPrompt) {
|
|
19535
|
+
let context = this.taskMap.get(taskId);
|
|
19536
|
+
if (context) {
|
|
19537
|
+
context.conversation.push(userPrompt);
|
|
19538
|
+
return context.conversation;
|
|
19539
|
+
}
|
|
19540
|
+
}
|
|
19491
19541
|
addAgent(agent) {
|
|
19492
19542
|
this.config.agents = this.config.agents || [];
|
|
19493
19543
|
this.config.agents.push(agent);
|