@t2000/engine 1.25.1 → 1.25.2

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.js CHANGED
@@ -7668,7 +7668,7 @@ var QueryEngine = class {
7668
7668
  })),
7669
7669
  ...writeResultBlocks
7670
7670
  ];
7671
- const canonicalRouteText = response.approved ? buildCanonicalRouteText(action) : null;
7671
+ const canonicalRouteText = response.approved ? buildCanonicalRouteText(action, response) : null;
7672
7672
  if (canonicalRouteText) {
7673
7673
  allResults.push({ type: "text", text: canonicalRouteText });
7674
7674
  }
@@ -9028,16 +9028,33 @@ ${recipeCtx}`;
9028
9028
  }
9029
9029
  }
9030
9030
  };
9031
- function buildCanonicalRouteText(action) {
9031
+ function buildCanonicalRouteText(action, response) {
9032
+ const failedToolUseIds = /* @__PURE__ */ new Set();
9033
+ if (Array.isArray(action.steps) && action.steps.length > 0) {
9034
+ const stepResultByToolUseId = new Map(
9035
+ (response.stepResults ?? []).map((sr) => [sr.toolUseId, sr])
9036
+ );
9037
+ for (const step of action.steps) {
9038
+ const sr = stepResultByToolUseId.get(step.toolUseId);
9039
+ if (!sr || sr.isError === true) {
9040
+ failedToolUseIds.add(step.toolUseId);
9041
+ }
9042
+ }
9043
+ } else if (isExecutionResultFailure(response.executionResult)) {
9044
+ failedToolUseIds.add(action.toolUseId);
9045
+ }
9032
9046
  const swaps = [];
9033
9047
  if (Array.isArray(action.steps) && action.steps.length > 0) {
9034
9048
  for (const step of action.steps) {
9035
9049
  if (step.toolName === "swap_execute" && step.cetusRoute) {
9050
+ if (failedToolUseIds.has(step.toolUseId)) continue;
9036
9051
  swaps.push({ input: step.input, cetusRoute: step.cetusRoute });
9037
9052
  }
9038
9053
  }
9039
9054
  } else if (action.toolName === "swap_execute" && action.cetusRoute) {
9040
- swaps.push({ input: action.input, cetusRoute: action.cetusRoute });
9055
+ if (!failedToolUseIds.has(action.toolUseId)) {
9056
+ swaps.push({ input: action.input, cetusRoute: action.cetusRoute });
9057
+ }
9041
9058
  }
9042
9059
  if (swaps.length === 0) return null;
9043
9060
  const blocks = swaps.map(({ input, cetusRoute }) => {
@@ -9057,6 +9074,24 @@ function buildCanonicalRouteText(action) {
9057
9074
  });
9058
9075
  return blocks.join("\n\n");
9059
9076
  }
9077
+ function isExecutionResultFailure(executionResult) {
9078
+ if (executionResult === null || executionResult === void 0) return false;
9079
+ if (typeof executionResult !== "object") return false;
9080
+ const er = executionResult;
9081
+ if (er.success === false) return true;
9082
+ if (typeof er.error === "string" && er.error.length > 0) return true;
9083
+ if (er._bundleReverted === true) return true;
9084
+ if (er._sessionExpired === true) return true;
9085
+ if (er._txReverted === true) return true;
9086
+ if (er.data && typeof er.data === "object") {
9087
+ const d = er.data;
9088
+ if (typeof d.error === "string" && d.error.length > 0) return true;
9089
+ if (d._bundleReverted === true) return true;
9090
+ if (d._sessionExpired === true) return true;
9091
+ if (d._txReverted === true) return true;
9092
+ }
9093
+ return false;
9094
+ }
9060
9095
  function isCorruptHistoryError(err) {
9061
9096
  const msg = err instanceof Error ? err.message : String(err);
9062
9097
  return msg.includes("tool_use") && msg.includes("tool_result") || msg.includes("roles must alternate") || msg.includes("400") && msg.includes("invalid_request_error");