@eko-ai/eko 4.0.7-alpha.1 → 4.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/index.cjs.js CHANGED
@@ -38047,7 +38047,9 @@ async function callWithReAct(rlm, request, toolCallsOrCallback, streamCallback,
38047
38047
  };
38048
38048
  }
38049
38049
  if (typeof toolCallsOrCallback !== "function") {
38050
- request.tools = toolCallsOrCallback.map((tool) => ({
38050
+ request.tools = (Array.isArray(toolCallsOrCallback)
38051
+ ? toolCallsOrCallback
38052
+ : toolCallsOrCallback.tools).map((tool) => ({
38051
38053
  type: "function",
38052
38054
  name: tool.name,
38053
38055
  description: tool.description,
@@ -38057,6 +38059,11 @@ async function callWithReAct(rlm, request, toolCallsOrCallback, streamCallback,
38057
38059
  let loopNum = 0;
38058
38060
  let assistantParts = null;
38059
38061
  while (true) {
38062
+ await streamCallback?.({
38063
+ type: "loop_start",
38064
+ request,
38065
+ loopNum,
38066
+ });
38060
38067
  assistantParts = await callLLM(rlm, request, streamCallback, errorHandler, finishHandler);
38061
38068
  if (assistantParts.length > 0) {
38062
38069
  request.messages.push({
@@ -38066,6 +38073,12 @@ async function callWithReAct(rlm, request, toolCallsOrCallback, streamCallback,
38066
38073
  }
38067
38074
  const continueLoop = await loopControl(request, assistantParts, loopNum);
38068
38075
  if (!continueLoop) {
38076
+ await streamCallback?.({
38077
+ type: "loop_end",
38078
+ request,
38079
+ loopNum,
38080
+ continueLoop,
38081
+ });
38069
38082
  break;
38070
38083
  }
38071
38084
  const toolUses = assistantParts.filter((s) => s.type == "tool-call");
@@ -38074,16 +38087,33 @@ async function callWithReAct(rlm, request, toolCallsOrCallback, streamCallback,
38074
38087
  toolResults = await toolCallsOrCallback(request, toolUses);
38075
38088
  }
38076
38089
  else {
38077
- toolResults = await Promise.all(toolUses.map(async (toolUse) => {
38078
- const tool = toolCallsOrCallback.find((t) => t.name === toolUse.toolName);
38079
- if (!tool) {
38080
- throw new Error(`Tool ${toolUse.toolName} not found`);
38081
- }
38082
- const args = typeof toolUse.input === "string"
38083
- ? JSON.parse(toolUse.input || "{}")
38084
- : toolUse.input || {};
38085
- return await tool.execute(args, toolUse);
38086
- }));
38090
+ const tools = Array.isArray(toolCallsOrCallback)
38091
+ ? toolCallsOrCallback
38092
+ : toolCallsOrCallback.tools;
38093
+ if (!Array.isArray(toolCallsOrCallback) && toolCallsOrCallback.callback) {
38094
+ toolResults = await toolCallsOrCallback.callback(request, toolUses, tools);
38095
+ }
38096
+ else {
38097
+ toolResults = await Promise.all(toolUses.map(async (toolUse) => {
38098
+ const tool = tools.find((t) => t.name === toolUse.toolName);
38099
+ if (!tool) {
38100
+ throw new Error(`Tool ${toolUse.toolName} not found`);
38101
+ }
38102
+ const args = typeof toolUse.input === "string"
38103
+ ? JSON.parse(toolUse.input || "{}")
38104
+ : toolUse.input || {};
38105
+ try {
38106
+ return await tool.execute(args, toolUse);
38107
+ }
38108
+ catch (e) {
38109
+ Log.error("tool call error: ", toolUse.toolName, toolUse.input, e);
38110
+ return {
38111
+ type: "error-text",
38112
+ value: "Error: " + (e + "") || "Unknown error",
38113
+ };
38114
+ }
38115
+ }));
38116
+ }
38087
38117
  }
38088
38118
  if (toolResults.length > 0) {
38089
38119
  request.messages.push({
@@ -38096,6 +38126,12 @@ async function callWithReAct(rlm, request, toolCallsOrCallback, streamCallback,
38096
38126
  })),
38097
38127
  });
38098
38128
  }
38129
+ await streamCallback?.({
38130
+ type: "loop_end",
38131
+ request,
38132
+ loopNum,
38133
+ continueLoop,
38134
+ });
38099
38135
  loopNum++;
38100
38136
  }
38101
38137
  return assistantParts;