Skip to content

Conversation

@nicoalbanese
Copy link
Collaborator

@nicoalbanese nicoalbanese commented Nov 27, 2025

Background

When a user denies a tool execution approval (answers "n" to an approval prompt), the SDK creates a tool result with output: { type: 'execution-denied' }. The Gateway API doesn't recognize this type, returning GatewayInvalidRequestError: Invalid input at "prompt",3,"content",0,"output".

Other providers (OpenAI, Anthropic, Mistral, etc.) handle this by converting execution-denied to plain text in their message converters before sending to their APIs.

Summary

  • Renamed maybeEncodeFileParts()preparePrompt() to reflect its broader responsibility
  • Added conversion of execution-denied tool results to { type: 'text', value: reason } before sending to Gateway API
  • Added tests for the conversion

Manual Verification

  1. Run examples/ai-core/src/stream-text/openai-tool-approval.ts
  2. Change provider/model to use gateway
  3. Ask for weather somewhere, then reject the execution approval
  4. Verify no error is thrown and the model responds appropriately

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #10663

@nicoalbanese nicoalbanese marked this pull request as ready for review November 27, 2025 17:28
@nicoalbanese nicoalbanese marked this pull request as draft December 3, 2025 10:50
@nicoalbanese
Copy link
Collaborator Author

DO NOT MERGE

@shaper looking into gateway fix here.
cc @lgrammel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: tool execution approval not working with gateway

2 participants