@jaypie/llm 1.2.18 → 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
@@ -2312,8 +2312,9 @@ class OpenAiAdapter extends BaseProviderAdapter {
2312
2312
  async executeRequest(client, request, signal) {
2313
2313
  const openai = client;
2314
2314
  try {
2315
+ return await openai.responses.create(
2315
2316
  // @ts-expect-error OpenAI SDK types don't match our request format exactly
2316
- return await openai.responses.create(request, signal ? { signal } : undefined);
2317
+ request, signal ? { signal } : undefined);
2317
2318
  }
2318
2319
  catch (error) {
2319
2320
  if (signal?.aborted)
@@ -4424,6 +4425,19 @@ class OperateLoop {
4424
4425
  status: jaypieError.status,
4425
4426
  title: ERROR$1.BAD_FUNCTION_CALL,
4426
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);
4427
4441
  log$1.error(`Error executing function call ${toolCall.name}`);
4428
4442
  log$1.var({ error });
4429
4443
  }
@@ -4904,6 +4918,18 @@ class StreamLoop {
4904
4918
  title: ERROR.BAD_FUNCTION_CALL,
4905
4919
  },
4906
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
+ });
4907
4933
  log$1.error(`Error executing function call ${toolCall.name}`);
4908
4934
  log$1.var({ error });
4909
4935
  }