import { describe, expect, test } from 'bun:test' import { anthropicToolsToOpenAI, anthropicToolChoiceToOpenAI } from '../convertTools.js' describe('anthropicToolsToOpenAI', () => { test('converts basic tool', () => { const tools = [ { type: 'custom', name: 'bash', description: 'Run a bash command', input_schema: { type: 'object', properties: { command: { type: 'string' } }, required: ['command'], }, }, ] const result = anthropicToolsToOpenAI(tools as any) expect(result).toEqual([{ type: 'function', function: { name: 'bash', description: 'Run a bash command', parameters: { type: 'object', properties: { command: { type: 'string' } }, required: ['command'], }, }, }]) }) test('uses empty schema when input_schema missing', () => { const tools = [{ type: 'custom', name: 'noop', description: 'no-op' }] const result = anthropicToolsToOpenAI(tools as any) expect(result[0].function.parameters).toEqual({ type: 'object', properties: {} }) }) test('strips Anthropic-specific fields', () => { const tools = [ { type: 'custom', name: 'bash', description: 'Run bash', input_schema: { type: 'object', properties: {} }, cache_control: { type: 'ephemeral' }, defer_loading: true, }, ] const result = anthropicToolsToOpenAI(tools as any) expect((result[0] as any).cache_control).toBeUndefined() expect((result[0] as any).defer_loading).toBeUndefined() }) test('handles empty tools array', () => { expect(anthropicToolsToOpenAI([])).toEqual([]) }) }) describe('anthropicToolChoiceToOpenAI', () => { test('maps auto', () => { expect(anthropicToolChoiceToOpenAI({ type: 'auto' })).toBe('auto') }) test('maps any to required', () => { expect(anthropicToolChoiceToOpenAI({ type: 'any' })).toBe('required') }) test('maps tool to function', () => { const result = anthropicToolChoiceToOpenAI({ type: 'tool', name: 'bash' }) expect(result).toEqual({ type: 'function', function: { name: 'bash' } }) }) test('returns undefined for undefined input', () => { expect(anthropicToolChoiceToOpenAI(undefined)).toBeUndefined() }) test('returns undefined for unknown type', () => { expect(anthropicToolChoiceToOpenAI({ type: 'unknown' })).toBeUndefined() }) })