UNPKG

@xynehq/jaf

Version:

Juspay Agent Framework - A purely functional agent framework with immutable state and composable tools

138 lines 6.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MockModelProvider = void 0; class MockModelProvider { async getCompletion(state, agent, config) { const lastMessage = state.messages[state.messages.length - 1]; if (agent.name === 'TriageAgent') { const userMessage = state.messages.find(m => m.role === 'user')?.content || ''; let targetAgent = 'MathTutor'; let reasoning = 'Default to math tutor'; if (userMessage.toLowerCase().includes('file') || userMessage.toLowerCase().includes('read') || userMessage.toLowerCase().includes('write')) { targetAgent = 'FileManager'; reasoning = 'Request involves file operations'; } else if (userMessage.toLowerCase().includes('search') || userMessage.toLowerCase().includes('research') || userMessage.toLowerCase().includes('web')) { targetAgent = 'WebResearcher'; reasoning = 'Request involves web search or research'; } else if (userMessage.match(/\d+.*[+\-*/].*\d+|math|calculate|equation|solve/i)) { targetAgent = 'MathTutor'; reasoning = 'Request involves mathematical calculations'; } return { message: { content: JSON.stringify({ agentName: targetAgent, reasoning: reasoning }), tool_calls: [{ id: 'handoff_1', type: 'function', function: { name: 'handoff_to_agent', arguments: JSON.stringify({ agentName: targetAgent, reason: reasoning }) } }] } }; } if (agent.name === 'MathTutor') { const userMessage = state.messages.find(m => m.role === 'user')?.content || ''; const mathMatch = userMessage.match(/(\d+.*[+\-*/].*\d+|sqrt\(\d+\))/); if (mathMatch) { return { message: { content: `I'll solve that math problem for you!`, tool_calls: [{ id: 'calc_1', type: 'function', function: { name: 'calculate', arguments: JSON.stringify({ expression: mathMatch[0] }) } }] } }; } return { message: { content: `I'm a math tutor! I can help you with mathematical calculations, equations, and explain math concepts. What would you like me to help you with?` } }; } if (agent.name === 'FileManager') { const userMessage = state.messages.find(m => m.role === 'user')?.content || ''; if (userMessage.toLowerCase().includes('read')) { const pathMatch = userMessage.match(/read\s+([^\s]+)/i); const path = pathMatch ? pathMatch[1] : '/shared/example.txt'; return { message: { content: `I'll read that file for you.`, tool_calls: [{ id: 'read_1', type: 'function', function: { name: 'read_file', arguments: JSON.stringify({ path: path }) } }] } }; } if (userMessage.toLowerCase().includes('write')) { return { message: { content: `I can help you write files, but you need admin permissions for write operations. What would you like me to write?` } }; } return { message: { content: `I'm a file manager! I can help you read files and manage your workspace. What file operation would you like to perform?` } }; } if (agent.name === 'WebResearcher') { const userMessage = state.messages.find(m => m.role === 'user')?.content || ''; const searchMatch = userMessage.match(/search\s+(?:for\s+)?(.+)/i); if (searchMatch) { return { message: { content: `I'll search for information about that topic.`, tool_calls: [{ id: 'search_1', type: 'function', function: { name: 'search_web', arguments: JSON.stringify({ query: searchMatch[1].trim(), maxResults: 3 }) } }] } }; } return { message: { content: `I'm a web researcher! I can search the web for information and help with research tasks. What would you like me to research?` } }; } return { message: { content: `I'm ${agent.name}. How can I help you today?` } }; } } exports.MockModelProvider = MockModelProvider; //# sourceMappingURL=mock-provider.js.map