handleToolCall method
Implementation
Future<dynamic> handleToolCall(ToolCall call) async {
final sessionHandlers = _sessions[call.sessionId];
if (sessionHandlers == null) {
throw AppleFoundationException(
'Session not found: ${call.sessionId}',
code: 'SESSION_NOT_FOUND',
);
}
if (!sessionHandlers.isActive) {
throw AppleFoundationException(
'Session is inactive: ${call.sessionId}',
code: 'SESSION_INACTIVE',
);
}
final handler = sessionHandlers.handlers[call.toolName];
if (handler == null) {
throw AppleFoundationException(
'No handler registered for tool: ${call.toolName}',
code: 'TOOL_HANDLER_NOT_FOUND',
details: {
'toolName': call.toolName,
'sessionId': call.sessionId,
'availableTools': sessionHandlers.handlers.keys.toList(),
},
);
}
return await _executeWithTimeout(
handler: handler,
call: call,
timeout: sessionHandlers.timeout,
);
}