@eko-ai/eko 3.0.7 → 3.0.8-alpha.1
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/llm.d.ts +4 -2
- package/dist/agent/llm.d.ts.map +1 -1
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/index.cjs.js +114 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +114 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/mcp/http.d.ts.map +1 -1
- package/dist/mcp/sse.d.ts.map +1 -1
- package/dist/prompt/agent.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/agent/llm.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { RetryLanguageModel } from "../llm";
|
|
2
2
|
import { AgentContext } from "../core/context";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Tool, LLMRequest, ToolResult, DialogueTool, HumanCallback, StreamCallback } from "../types";
|
|
4
|
+
import { LanguageModelV2Prompt, LanguageModelV2TextPart, SharedV2ProviderOptions, LanguageModelV2ToolChoice, LanguageModelV2ToolCallPart, LanguageModelV2FunctionTool, LanguageModelV2ToolResultPart } from "@ai-sdk/provider";
|
|
5
5
|
export declare function defaultLLMProviderOptions(): SharedV2ProviderOptions;
|
|
6
6
|
export declare function defaultMessageProviderOptions(): SharedV2ProviderOptions;
|
|
7
7
|
export declare function convertTools(tools: Tool[] | DialogueTool[]): LanguageModelV2FunctionTool[];
|
|
8
8
|
export declare function getTool<T extends Tool | DialogueTool>(tools: T[], name: string): T | null;
|
|
9
9
|
export declare function convertToolResult(toolUse: LanguageModelV2ToolCallPart, toolResult: ToolResult, user_messages: LanguageModelV2Prompt): LanguageModelV2ToolResultPart;
|
|
10
10
|
export declare function callAgentLLM(agentContext: AgentContext, rlm: RetryLanguageModel, messages: LanguageModelV2Prompt, tools: LanguageModelV2FunctionTool[], noCompress?: boolean, toolChoice?: LanguageModelV2ToolChoice, retryNum?: number, callback?: StreamCallback & HumanCallback, requestHandler?: (request: LLMRequest) => void): Promise<Array<LanguageModelV2TextPart | LanguageModelV2ToolCallPart>>;
|
|
11
|
+
export declare function estimatePromptTokens(messages: LanguageModelV2Prompt, tools?: LanguageModelV2FunctionTool[]): number;
|
|
12
|
+
export declare function estimateTokens(text: string): number;
|
|
11
13
|
//# sourceMappingURL=llm.d.ts.map
|
package/dist/agent/llm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../src/agent/llm.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../src/agent/llm.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EACL,IAAI,EACJ,UAAU,EACV,UAAU,EACV,YAAY,EAEZ,aAAa,EACb,cAAc,EAEf,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EACvB,yBAAyB,EAEzB,2BAA2B,EAC3B,2BAA2B,EAC3B,6BAA6B,EAE9B,MAAM,kBAAkB,CAAC;AAE1B,wBAAgB,yBAAyB,IAAI,uBAAuB,CAanE;AAED,wBAAgB,6BAA6B,IAAI,uBAAuB,CAYvE;AAED,wBAAgB,YAAY,CAC1B,KAAK,EAAE,IAAI,EAAE,GAAG,YAAY,EAAE,GAC7B,2BAA2B,EAAE,CAQ/B;AAED,wBAAgB,OAAO,CAAC,CAAC,SAAS,IAAI,GAAG,YAAY,EACnD,KAAK,EAAE,CAAC,EAAE,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CAAC;IAC9B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,qBAAqB,EAAE,MAAM,CAAC;CAC/B,CAAA;AAED,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,uBAAuB,EAAE,MAAM,CAAC;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,OAAO,CAAC;IAC9B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,qBAAqB,EAAE,MAAM,CAAC;CAC/B,CAAA;AAED,QAAA,MAAM,MAAM,EAAE,YAgBb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -12,6 +12,7 @@ const config$1 = {
|
|
|
12
12
|
maxRetryNum: 3,
|
|
13
13
|
agentParallel: false,
|
|
14
14
|
compressThreshold: 80,
|
|
15
|
+
compressTokensThreshold: 100000,
|
|
15
16
|
largeTextLength: 5000,
|
|
16
17
|
fileTextMaxLength: 20000,
|
|
17
18
|
maxDialogueImgFileNum: 1,
|
|
@@ -31604,7 +31605,8 @@ function convertToolResult(toolUse, toolResult, user_messages) {
|
|
|
31604
31605
|
value: "Error",
|
|
31605
31606
|
};
|
|
31606
31607
|
}
|
|
31607
|
-
else if (toolResult.content.length == 1 &&
|
|
31608
|
+
else if (toolResult.content.length == 1 &&
|
|
31609
|
+
toolResult.content[0].type == "text") {
|
|
31608
31610
|
let text = toolResult.content[0].text;
|
|
31609
31611
|
result = {
|
|
31610
31612
|
type: "text",
|
|
@@ -31694,7 +31696,9 @@ function convertToolResult(toolUse, toolResult, user_messages) {
|
|
|
31694
31696
|
}
|
|
31695
31697
|
async function callAgentLLM(agentContext, rlm, messages, tools, noCompress, toolChoice, retryNum = 0, callback, requestHandler) {
|
|
31696
31698
|
await agentContext.context.checkAborted();
|
|
31697
|
-
if (
|
|
31699
|
+
if (!noCompress &&
|
|
31700
|
+
(messages.length >= config$1.compressThreshold || (messages.length >= 10 && estimatePromptTokens(messages, tools) >= config$1.compressTokensThreshold))) {
|
|
31701
|
+
// Compress messages
|
|
31698
31702
|
await compressAgentMessages(agentContext, rlm, messages, tools);
|
|
31699
31703
|
}
|
|
31700
31704
|
if (!toolChoice) {
|
|
@@ -31964,6 +31968,9 @@ async function callAgentLLM(agentContext, rlm, messages, tools, noCompress, tool
|
|
|
31964
31968
|
await context.checkAborted();
|
|
31965
31969
|
if (retryNum < config$1.maxRetryNum) {
|
|
31966
31970
|
await sleep(300 * (retryNum + 1) * (retryNum + 1));
|
|
31971
|
+
if ((e + "").indexOf("is too long") > -1) {
|
|
31972
|
+
await compressAgentMessages(agentContext, rlm, messages, tools);
|
|
31973
|
+
}
|
|
31967
31974
|
return callAgentLLM(agentContext, rlm, messages, tools, noCompress, toolChoice, ++retryNum, streamCallback);
|
|
31968
31975
|
}
|
|
31969
31976
|
throw e;
|
|
@@ -31980,6 +31987,100 @@ async function callAgentLLM(agentContext, rlm, messages, tools, noCompress, tool
|
|
|
31980
31987
|
]
|
|
31981
31988
|
: toolParts;
|
|
31982
31989
|
}
|
|
31990
|
+
function estimatePromptTokens(messages, tools) {
|
|
31991
|
+
let tokens = messages.reduce((total, message) => {
|
|
31992
|
+
if (message.role == "system") {
|
|
31993
|
+
return total + estimateTokens(message.content);
|
|
31994
|
+
}
|
|
31995
|
+
else if (message.role == "user") {
|
|
31996
|
+
return (total +
|
|
31997
|
+
estimateTokens(message.content
|
|
31998
|
+
.filter((part) => part.type == "text")
|
|
31999
|
+
.map((part) => part.text)
|
|
32000
|
+
.join("\n")));
|
|
32001
|
+
}
|
|
32002
|
+
else if (message.role == "assistant") {
|
|
32003
|
+
return (total +
|
|
32004
|
+
estimateTokens(message.content
|
|
32005
|
+
.map((part) => {
|
|
32006
|
+
if (part.type == "text") {
|
|
32007
|
+
return part.text;
|
|
32008
|
+
}
|
|
32009
|
+
else if (part.type == "reasoning") {
|
|
32010
|
+
return part.text;
|
|
32011
|
+
}
|
|
32012
|
+
else if (part.type == "tool-call") {
|
|
32013
|
+
return part.toolName + JSON.stringify(part.input || {});
|
|
32014
|
+
}
|
|
32015
|
+
else if (part.type == "tool-result") {
|
|
32016
|
+
return part.toolName + JSON.stringify(part.output || {});
|
|
32017
|
+
}
|
|
32018
|
+
return "";
|
|
32019
|
+
})
|
|
32020
|
+
.join("")));
|
|
32021
|
+
}
|
|
32022
|
+
else if (message.role == "tool") {
|
|
32023
|
+
return (total +
|
|
32024
|
+
estimateTokens(message.content
|
|
32025
|
+
.map((part) => part.toolName + JSON.stringify(part.output || {}))
|
|
32026
|
+
.join("")));
|
|
32027
|
+
}
|
|
32028
|
+
return total;
|
|
32029
|
+
}, 0);
|
|
32030
|
+
if (tools) {
|
|
32031
|
+
tokens += tools.reduce((total, tool) => {
|
|
32032
|
+
return total + estimateTokens(JSON.stringify(tool));
|
|
32033
|
+
}, 0);
|
|
32034
|
+
}
|
|
32035
|
+
return tokens;
|
|
32036
|
+
}
|
|
32037
|
+
function estimateTokens(text) {
|
|
32038
|
+
if (!text) {
|
|
32039
|
+
return 0;
|
|
32040
|
+
}
|
|
32041
|
+
let tokenCount = 0;
|
|
32042
|
+
for (let i = 0; i < text.length; i++) {
|
|
32043
|
+
const char = text[i];
|
|
32044
|
+
const code = char.charCodeAt(0);
|
|
32045
|
+
if ((code >= 0x4e00 && code <= 0x9fff) ||
|
|
32046
|
+
(code >= 0x3400 && code <= 0x4dbf) ||
|
|
32047
|
+
(code >= 0x3040 && code <= 0x309f) ||
|
|
32048
|
+
(code >= 0x30a0 && code <= 0x30ff) ||
|
|
32049
|
+
(code >= 0xac00 && code <= 0xd7af)) {
|
|
32050
|
+
tokenCount += 2;
|
|
32051
|
+
}
|
|
32052
|
+
else if (/\s/.test(char)) {
|
|
32053
|
+
continue;
|
|
32054
|
+
}
|
|
32055
|
+
else if (/[a-zA-Z]/.test(char)) {
|
|
32056
|
+
let word = "";
|
|
32057
|
+
while (i < text.length && /[a-zA-Z]/.test(text[i])) {
|
|
32058
|
+
word += text[i];
|
|
32059
|
+
i++;
|
|
32060
|
+
}
|
|
32061
|
+
i--;
|
|
32062
|
+
if (word.length <= 4) {
|
|
32063
|
+
tokenCount += 1;
|
|
32064
|
+
}
|
|
32065
|
+
else {
|
|
32066
|
+
tokenCount += Math.ceil(word.length / 4);
|
|
32067
|
+
}
|
|
32068
|
+
}
|
|
32069
|
+
else if (/\d/.test(char)) {
|
|
32070
|
+
let number = "";
|
|
32071
|
+
while (i < text.length && /\d/.test(text[i])) {
|
|
32072
|
+
number += text[i];
|
|
32073
|
+
i++;
|
|
32074
|
+
}
|
|
32075
|
+
i--;
|
|
32076
|
+
tokenCount += Math.max(1, Math.ceil(number.length / 3));
|
|
32077
|
+
}
|
|
32078
|
+
else {
|
|
32079
|
+
tokenCount += 1;
|
|
32080
|
+
}
|
|
32081
|
+
}
|
|
32082
|
+
return Math.max(1, tokenCount);
|
|
32083
|
+
}
|
|
31983
32084
|
function appendUserConversation(agentContext, messages) {
|
|
31984
32085
|
const userPrompts = agentContext.context.conversation
|
|
31985
32086
|
.splice(0, agentContext.context.conversation.length)
|
|
@@ -34160,7 +34261,10 @@ class SimpleSseMcpClient {
|
|
|
34160
34261
|
version: "1.0.0",
|
|
34161
34262
|
},
|
|
34162
34263
|
});
|
|
34163
|
-
|
|
34264
|
+
try {
|
|
34265
|
+
await this.request("notifications/initialized", {});
|
|
34266
|
+
}
|
|
34267
|
+
catch (ignored) { }
|
|
34164
34268
|
}
|
|
34165
34269
|
ping() {
|
|
34166
34270
|
this.request("ping", {});
|
|
@@ -34357,6 +34461,12 @@ class SimpleHttpMcpClient {
|
|
|
34357
34461
|
version: "1.0.0",
|
|
34358
34462
|
},
|
|
34359
34463
|
}, signal);
|
|
34464
|
+
if (this.mcpSessionId) {
|
|
34465
|
+
try {
|
|
34466
|
+
await this.request("notifications/initialized", {});
|
|
34467
|
+
}
|
|
34468
|
+
catch (ignored) { }
|
|
34469
|
+
}
|
|
34360
34470
|
this.connected = true;
|
|
34361
34471
|
}
|
|
34362
34472
|
async listTools(param, signal) {
|
|
@@ -35332,6 +35442,7 @@ During the task execution process, you can use the \`${TOOL_NAME$5}\` tool to in
|
|
|
35332
35442
|
- When performing dangerous operations such as deleting files, confirmation from humans is required.
|
|
35333
35443
|
- When encountering obstacles while accessing websites, such as requiring user login, captcha verification, QR code scanning, or human verification, you need to request manual assistance.
|
|
35334
35444
|
- Please do not use the \`${TOOL_NAME$5}\` tool frequently.
|
|
35445
|
+
- The \`${TOOL_NAME$5}\` tool does not support parallel calls.
|
|
35335
35446
|
`;
|
|
35336
35447
|
const VARIABLE_PROMPT = `
|
|
35337
35448
|
* VARIABLE STORAGE
|