import { describe, expect, it } from 'vitest'; import { Tool, apiPrompt, toolPrompt, toolsPrompts } from './tools'; describe('Prompt Generation Utils', () => { // 测试 apiPrompt 函数 describe('apiPrompt', () => { it('should generate correct api prompt', () => { const api = { name: 'testApi', desc: 'Test API Description', }; expect(apiPrompt(api)).toBe(`Test API Description`); }); }); // 测试 toolPrompt 函数 describe('toolPrompt', () => { it('should generate tool prompt with system role', () => { const tool: Tool = { name: 'testTool', identifier: 'test-id', systemRole: 'Test System Role', apis: [ { name: 'api1', desc: 'API 1 Description', }, ], }; const expected = ` Test System Role API 1 Description `; expect(toolPrompt(tool)).toBe(expected); }); it('should generate tool prompt without system role', () => { const tool: Tool = { name: 'testTool', identifier: 'test-id', apis: [ { name: 'api1', desc: 'API 1 Description', }, ], }; const expected = ` API 1 Description `; expect(toolPrompt(tool)).toBe(expected); }); }); // 测试 toolsPrompts 函数 describe('toolsPrompts', () => { it('should generate tools prompts with multiple tools', () => { const tools: Tool[] = [ { name: 'tool1', identifier: 'id1', apis: [ { name: 'api1', desc: 'API 1', }, ], }, { name: 'tool2', identifier: 'id2', apis: [ { name: 'api2', desc: 'API 2', }, ], }, ]; const expected = ` API 1 API 2 `; expect(toolsPrompts(tools)).toBe(expected); }); it('should generate tools prompts with empty tools array', () => { const tools: Tool[] = []; expect(toolsPrompts(tools)).toBe(''); }); }); });