@jaypie/llm 1.2.19 → 1.2.20

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/esm/index.js CHANGED
@@ -4425,6 +4425,19 @@ class OperateLoop {
4425
4425
  status: jaypieError.status,
4426
4426
  title: ERROR$1.BAD_FUNCTION_CALL,
4427
4427
  });
4428
+ // Add error tool_result to history so the tool_use block is not orphaned.
4429
+ // Without this, the next turn's request would have a tool_use without a
4430
+ // matching tool_result, causing Anthropic API to reject with 400.
4431
+ const errorResult = {
4432
+ callId: toolCall.callId,
4433
+ output: JSON.stringify({
4434
+ error: error.message || "Tool execution failed",
4435
+ }),
4436
+ success: false,
4437
+ error: error.message,
4438
+ };
4439
+ const toolResultFormatted = this.adapter.formatToolResult(toolCall, errorResult);
4440
+ state.responseBuilder.appendToHistory(toolResultFormatted);
4428
4441
  log$1.error(`Error executing function call ${toolCall.name}`);
4429
4442
  log$1.var({ error });
4430
4443
  }
@@ -4905,6 +4918,18 @@ class StreamLoop {
4905
4918
  title: ERROR.BAD_FUNCTION_CALL,
4906
4919
  },
4907
4920
  };
4921
+ // Add error tool_result to history so the tool_use block is not orphaned.
4922
+ // Without this, the next turn's request would have a tool_use without a
4923
+ // matching tool_result, causing Anthropic API to reject with 400.
4924
+ const errorOutput = JSON.stringify({
4925
+ error: error.message || "Tool execution failed",
4926
+ });
4927
+ state.currentInput.push({
4928
+ type: LlmMessageType.FunctionCallOutput,
4929
+ output: errorOutput,
4930
+ call_id: toolCall.callId,
4931
+ name: toolCall.name,
4932
+ });
4908
4933
  log$1.error(`Error executing function call ${toolCall.name}`);
4909
4934
  log$1.var({ error });
4910
4935
  }