fix(proxy): stringify tool_result images for OpenAI upstreams

This commit is contained in:
seilk committed 2026-04-30 00:55:45 +09:00
1 parent b33277bf93
commit f6bb31c956
2 files changed
+45 -22

No files matched your search

@@ -189,27 +189,39 @@ describe('ProxyRequestTransformer regressions', () => {
).toThrow('must start with tool_result blocks for pending tool_use ids');
});
it('rejects tool_result content that cannot be represented as OpenAI tool text', () => {
expect(() =>
new ProxyRequestTransformer().transform({
messages: [
{
role: 'assistant',
content: [{ type: 'tool_use', id: 'toolu_1', name: 'vision', input: { detail: 'high' } }],
},
{
role: 'user',
content: [
{
type: 'tool_result',
tool_use_id: 'toolu_1',
content: [{ type: 'image', source: { type: 'url', url: 'https://example.com/error.png' } }],
},
],
},
],
})
).toThrow('type "image" is not supported in tool_result content');
it('converts tool_result image blocks to text placeholders for OpenAI-compatible tool messages', () => {
const result = new ProxyRequestTransformer().transform({
messages: [
{
role: 'assistant',
content: [{ type: 'tool_use', id: 'toolu_1', name: 'vision', input: { detail: 'high' } }],
},
{
role: 'user',
content: [
{
type: 'tool_result',
tool_use_id: 'toolu_1',
content: [
{ type: 'text', text: 'screenshot captured' },
{ type: 'image', source: { type: 'url', url: 'https://example.com/error.png' } },
{
type: 'image',
source: { type: 'base64', media_type: 'image/png', data: 'ZmFrZQ==' },
},
],
},
],
},
],
});
expect(result.messages[1]).toEqual({
role: 'tool',
tool_call_id: 'toolu_1',
content:
'screenshot captured\n[tool_result image omitted: https://example.com/error.png]\n[tool_result image omitted: image/png base64 payload]',
});
});
it('rejects unsupported assistant blocks instead of silently dropping them', () => {